Skip to content

Commit 944955d

Browse files
committed
Update ESQL helper types
The ESQL helper needs to reflect the types added to the spec in elastic/elasticsearch-specification#4189
1 parent 1ab0890 commit 944955d

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/helpers.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,6 @@ export interface EsqlColumn {
132132
type: string
133133
}
134134

135-
export type EsqlValue = any[]
136-
137-
export type EsqlRow = EsqlValue[]
138-
139-
export interface EsqlResponse {
140-
columns: EsqlColumn[]
141-
values: EsqlRow[]
142-
}
143-
144135
export interface EsqlHelper {
145136
toRecords: <TDocument>() => Promise<EsqlToRecords<TDocument>>
146137
toArrowTable: () => Promise<Table<TypeMap>>
@@ -963,7 +954,7 @@ export default class Helpers {
963954
esql (params: T.EsqlQueryRequest, reqOptions: TransportRequestOptions = {}): EsqlHelper {
964955
const client = this[kClient]
965956

966-
function toRecords<TDocument> (response: EsqlResponse): TDocument[] {
957+
function toRecords<TDocument> (response: T.EsqlEsqlResult): TDocument[] {
967958
const { columns, values } = response
968959
return values.map(row => {
969960
const doc: Partial<TDocument> = {}
@@ -990,8 +981,7 @@ export default class Helpers {
990981

991982
params.format = 'json'
992983
params.columnar = false
993-
// @ts-expect-error it's typed as ArrayBuffer but we know it will be JSON
994-
const response: EsqlResponse = await client.esql.query(params, reqOptions)
984+
const response = await client.esql.query(params, reqOptions)
995985
const records: TDocument[] = toRecords(response)
996986
const { columns } = response
997987
return { records, columns }
@@ -1005,7 +995,8 @@ export default class Helpers {
1005995

1006996
params.format = 'arrow'
1007997

1008-
const response = await client.esql.query(params, reqOptions)
998+
// @ts-expect-error the return type will be ArrayBuffer when the format is set to 'arrow'
999+
const response: ArrayBuffer = await client.esql.query(params, reqOptions)
10091000
return tableFromIPC(response)
10101001
},
10111002

@@ -1018,7 +1009,8 @@ export default class Helpers {
10181009

10191010
params.format = 'arrow'
10201011

1021-
const response = await client.esql.query(params, reqOptions)
1012+
// @ts-expect-error the return type will be ArrayBuffer when the format is set to 'arrow'
1013+
const response: ArrayBuffer = await client.esql.query(params, reqOptions)
10221014
return RecordBatchStreamReader.from(response)
10231015
}
10241016
}

0 commit comments

Comments
 (0)