@useairfoil/flight 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/proto/any.ts CHANGED
@@ -242,17 +242,24 @@ function base64FromBytes(arr: Uint8Array): string {
242
242
 
243
243
  type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
244
244
 
245
- export type DeepPartial<T> = T extends Builtin ? T
246
- : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
247
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
248
- : T extends { readonly $case: string }
249
- ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { readonly $case: T["$case"] }
250
- : T extends {} ? { [K in Exclude<keyof T, "$type">]?: DeepPartial<T[K]> }
251
- : Partial<T>;
245
+ export type DeepPartial<T> = T extends Builtin
246
+ ? T
247
+ : T extends globalThis.Array<infer U>
248
+ ? globalThis.Array<DeepPartial<U>>
249
+ : T extends ReadonlyArray<infer U>
250
+ ? ReadonlyArray<DeepPartial<U>>
251
+ : T extends { readonly $case: string }
252
+ ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { readonly $case: T["$case"] }
253
+ : T extends {}
254
+ ? { [K in Exclude<keyof T, "$type">]?: DeepPartial<T[K]> }
255
+ : Partial<T>;
252
256
 
253
257
  type KeysOfUnion<T> = T extends T ? keyof T : never;
254
- export type Exact<P, I extends P> = P extends Builtin ? P
255
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> | "$type">]: never };
258
+ export type Exact<P, I extends P> = P extends Builtin
259
+ ? P
260
+ : P & { [K in keyof P]: Exact<P[K], I[K]> } & {
261
+ [K in Exclude<keyof I, KeysOfUnion<P> | "$type">]: never;
262
+ };
256
263
 
257
264
  function isSet(value: any): boolean {
258
265
  return value !== null && value !== undefined;
@@ -128,7 +128,9 @@ export const Timestamp: MessageFns<Timestamp, "google.protobuf.Timestamp"> = {
128
128
  encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
129
129
  if (message.seconds !== 0n) {
130
130
  if (BigInt.asIntN(64, message.seconds) !== message.seconds) {
131
- throw new globalThis.Error("value provided for field message.seconds of type int64 too large");
131
+ throw new globalThis.Error(
132
+ "value provided for field message.seconds of type int64 too large",
133
+ );
132
134
  }
133
135
  writer.uint32(8).int64(message.seconds);
134
136
  }
@@ -204,17 +206,24 @@ messageTypeRegistry.set(Timestamp.$type, Timestamp);
204
206
 
205
207
  type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
206
208
 
207
- export type DeepPartial<T> = T extends Builtin ? T
208
- : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
209
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
210
- : T extends { readonly $case: string }
211
- ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { readonly $case: T["$case"] }
212
- : T extends {} ? { [K in Exclude<keyof T, "$type">]?: DeepPartial<T[K]> }
213
- : Partial<T>;
209
+ export type DeepPartial<T> = T extends Builtin
210
+ ? T
211
+ : T extends globalThis.Array<infer U>
212
+ ? globalThis.Array<DeepPartial<U>>
213
+ : T extends ReadonlyArray<infer U>
214
+ ? ReadonlyArray<DeepPartial<U>>
215
+ : T extends { readonly $case: string }
216
+ ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { readonly $case: T["$case"] }
217
+ : T extends {}
218
+ ? { [K in Exclude<keyof T, "$type">]?: DeepPartial<T[K]> }
219
+ : Partial<T>;
214
220
 
215
221
  type KeysOfUnion<T> = T extends T ? keyof T : never;
216
- export type Exact<P, I extends P> = P extends Builtin ? P
217
- : P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P> | "$type">]: never };
222
+ export type Exact<P, I extends P> = P extends Builtin
223
+ ? P
224
+ : P & { [K in keyof P]: Exact<P[K], I[K]> } & {
225
+ [K in Exclude<keyof I, KeysOfUnion<P> | "$type">]: never;
226
+ };
218
227
 
219
228
  function isSet(value: any): boolean {
220
229
  return value !== null && value !== undefined;
@@ -20,10 +20,14 @@ export type UnknownMessage = { $type: string };
20
20
  export const messageTypeRegistry = new Map<string, MessageType>();
21
21
 
22
22
  type Builtin = Date | Function | Uint8Array | string | number | boolean | bigint | undefined;
23
- export type DeepPartial<T> = T extends Builtin ? T
24
- : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
25
- : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
26
- : T extends { readonly $case: string }
27
- ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { readonly $case: T["$case"] }
28
- : T extends {} ? { [K in Exclude<keyof T, "$type">]?: DeepPartial<T[K]> }
29
- : Partial<T>;
23
+ export type DeepPartial<T> = T extends Builtin
24
+ ? T
25
+ : T extends globalThis.Array<infer U>
26
+ ? globalThis.Array<DeepPartial<U>>
27
+ : T extends ReadonlyArray<infer U>
28
+ ? ReadonlyArray<DeepPartial<U>>
29
+ : T extends { readonly $case: string }
30
+ ? { [K in keyof Omit<T, "$case">]?: DeepPartial<T[K]> } & { readonly $case: T["$case"] }
31
+ : T extends {}
32
+ ? { [K in Exclude<keyof T, "$type">]?: DeepPartial<T[K]> }
33
+ : Partial<T>;
@@ -28,11 +28,7 @@ export type HostOrChannel =
28
28
 
29
29
  export function createChannelFromConfig(config: HostOrChannel): Channel {
30
30
  if (config.host !== undefined) {
31
- return createChannel(
32
- config.host,
33
- config.credentials,
34
- config.channelOptions,
35
- );
31
+ return createChannel(config.host, config.credentials, config.channelOptions);
36
32
  }
37
33
 
38
34
  return config.channel;
@@ -45,11 +45,9 @@ import {
45
45
  import * as metadata from "apache-arrow/ipc/metadata/message";
46
46
  import { _InternalEmptyPlaceholderRecordBatch } from "apache-arrow/recordbatch";
47
47
  import { bigIntToNumber } from "apache-arrow/util/bigint";
48
- import {
49
- CompressedVectorLoader,
50
- VectorLoader,
51
- } from "apache-arrow/visitor/vectorloader";
48
+ import { CompressedVectorLoader, VectorLoader } from "apache-arrow/visitor/vectorloader";
52
49
  import * as flatbuffers from "flatbuffers";
50
+
53
51
  import type { FlightData } from "./proto/Flight";
54
52
 
55
53
  const invalidMessageType = (type: MessageHeader) =>
@@ -61,10 +59,8 @@ const invalidMessageType = (type: MessageHeader) =>
61
59
  // const invalidMessageBodyLength = (expected: number, actual: number) =>
62
60
  // `Expected to read ${expected} bytes for message body, but only read ${actual}.`;
63
61
 
64
- abstract class RecordBatchReaderImpl<T extends TypeMap = any>
65
- implements RecordBatchReaderImpl<T>
66
- {
67
- public declare schema: Schema<T>;
62
+ abstract class RecordBatchReaderImpl<T extends TypeMap = any> implements RecordBatchReaderImpl<T> {
63
+ declare public schema: Schema<T>;
68
64
  public closed = false;
69
65
  public autoDestroy = true;
70
66
  public dictionaries: Map<number, Vector>;
@@ -105,10 +101,7 @@ abstract class RecordBatchReaderImpl<T extends TypeMap = any>
105
101
  return this;
106
102
  }
107
103
 
108
- protected _loadRecordBatch(
109
- header: metadata.RecordBatch,
110
- body: Uint8Array,
111
- ): RecordBatch<T> {
104
+ protected _loadRecordBatch(header: metadata.RecordBatch, body: Uint8Array): RecordBatch<T> {
112
105
  // Ensure the body buffer is properly aligned for Apache Arrow
113
106
  // Apache Arrow requires 8-byte aligned buffers for typed arrays
114
107
  const alignedBody = this._ensureAlignedBuffer(body);
@@ -117,22 +110,9 @@ abstract class RecordBatchReaderImpl<T extends TypeMap = any>
117
110
  if (header.compression != null) {
118
111
  const codec = compressionRegistry.get(header.compression.type);
119
112
  if (codec?.decode && typeof codec.decode === "function") {
120
- const { decommpressedBody, buffers } = this._decompressBuffers(
121
- header,
122
- alignedBody,
123
- codec,
124
- );
125
- children = this._loadCompressedVectors(
126
- header,
127
- decommpressedBody,
128
- this.schema.fields,
129
- );
130
- header = new metadata.RecordBatch(
131
- header.length,
132
- header.nodes,
133
- buffers,
134
- null,
135
- );
113
+ const { decommpressedBody, buffers } = this._decompressBuffers(header, alignedBody, codec);
114
+ children = this._loadCompressedVectors(header, decommpressedBody, this.schema.fields);
115
+ header = new metadata.RecordBatch(header.length, header.nodes, buffers, null);
136
116
  } else {
137
117
  throw new Error("Record batch is compressed but codec not found");
138
118
  }
@@ -164,10 +144,7 @@ abstract class RecordBatchReaderImpl<T extends TypeMap = any>
164
144
  return alignedBuffer;
165
145
  }
166
146
 
167
- protected _loadDictionaryBatch(
168
- header: metadata.DictionaryBatch,
169
- body: Uint8Array,
170
- ) {
147
+ protected _loadDictionaryBatch(header: metadata.DictionaryBatch, body: Uint8Array) {
171
148
  const { id, isDelta } = header;
172
149
  const { dictionaries, schema } = this;
173
150
  const dictionary = dictionaries.get(id);
@@ -176,21 +153,10 @@ abstract class RecordBatchReaderImpl<T extends TypeMap = any>
176
153
  if (header.data.compression != null) {
177
154
  const codec = compressionRegistry.get(header.data.compression.type);
178
155
  if (codec?.decode && typeof codec.decode === "function") {
179
- const { decommpressedBody, buffers } = this._decompressBuffers(
180
- header.data,
181
- body,
182
- codec,
183
- );
184
- data = this._loadCompressedVectors(header.data, decommpressedBody, [
185
- type,
186
- ]);
156
+ const { decommpressedBody, buffers } = this._decompressBuffers(header.data, body, codec);
157
+ data = this._loadCompressedVectors(header.data, decommpressedBody, [type]);
187
158
  header = new metadata.DictionaryBatch(
188
- new metadata.RecordBatch(
189
- header.data.length,
190
- header.data.nodes,
191
- buffers,
192
- null,
193
- ),
159
+ new metadata.RecordBatch(header.data.length, header.data.nodes, buffers, null),
194
160
  id,
195
161
  isDelta,
196
162
  );
@@ -202,9 +168,7 @@ abstract class RecordBatchReaderImpl<T extends TypeMap = any>
202
168
  }
203
169
  // const data = this._loadVectors(header.data, body, [type]);
204
170
  return (
205
- dictionary && isDelta
206
- ? dictionary.concat(new Vector(data))
207
- : new Vector(data)
171
+ dictionary && isDelta ? dictionary.concat(new Vector(data)) : new Vector(data)
208
172
  ).memoize() as Vector;
209
173
  }
210
174
 
@@ -251,25 +215,19 @@ abstract class RecordBatchReaderImpl<T extends TypeMap = any>
251
215
  newBufferRegions.push(new metadata.BufferRegion(currentOffset, 0));
252
216
  continue;
253
217
  }
254
- const byteBuf = new flatbuffers.ByteBuffer(
255
- body.subarray(offset, offset + length),
256
- );
218
+ const byteBuf = new flatbuffers.ByteBuffer(body.subarray(offset, offset + length));
257
219
  const uncompressedLenth = bigIntToNumber(byteBuf.readInt64(0));
258
220
 
259
221
  const bytes = byteBuf.bytes().subarray(COMPRESS_LENGTH_PREFIX);
260
222
 
261
223
  const decompressed =
262
- uncompressedLenth === LENGTH_NO_COMPRESSED_DATA
263
- ? bytes
264
- : codec.decode!(bytes);
224
+ uncompressedLenth === LENGTH_NO_COMPRESSED_DATA ? bytes : codec.decode!(bytes);
265
225
 
266
226
  decompressedBuffers.push(decompressed);
267
227
 
268
228
  const padding = ((currentOffset + 7) & ~7) - currentOffset;
269
229
  currentOffset += padding;
270
- newBufferRegions.push(
271
- new metadata.BufferRegion(currentOffset, decompressed.length),
272
- );
230
+ newBufferRegions.push(new metadata.BufferRegion(currentOffset, decompressed.length));
273
231
  currentOffset += decompressed.length;
274
232
  }
275
233
 
@@ -383,9 +341,7 @@ export class RecordBatchStreamReaderFromFlightData<T extends TypeMap = any>
383
341
  return ITERATOR_DONE;
384
342
  }
385
343
 
386
- protected async _readNextMessageAndValidate<T extends MessageHeader>(
387
- type?: T | null,
388
- ) {
344
+ protected async _readNextMessageAndValidate<T extends MessageHeader>(type?: T | null) {
389
345
  const { done, value } = await this._reader.next();
390
346
  if (done) {
391
347
  return null;