@loaders.gl/arrow 4.3.0-alpha.8 → 4.3.0-beta.2

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.
Files changed (132) hide show
  1. package/dist/arrow-loader.d.ts +6 -38
  2. package/dist/arrow-loader.d.ts.map +1 -1
  3. package/dist/arrow-loader.js +2 -29
  4. package/dist/arrow-worker.js +2654 -1710
  5. package/dist/arrow-writer.d.ts +1 -1
  6. package/dist/arrow-writer.d.ts.map +1 -1
  7. package/dist/arrow-writer.js +2 -2
  8. package/dist/dist.dev.js +1863 -1768
  9. package/dist/dist.min.js +5 -5
  10. package/dist/exports/arrow-loader.d.ts +34 -0
  11. package/dist/exports/arrow-loader.d.ts.map +1 -0
  12. package/dist/exports/arrow-loader.js +30 -0
  13. package/dist/exports/geoarrow-loader.d.ts +27 -0
  14. package/dist/exports/geoarrow-loader.d.ts.map +1 -0
  15. package/dist/exports/geoarrow-loader.js +13 -0
  16. package/dist/geoarrow-loader.d.ts +3 -27
  17. package/dist/geoarrow-loader.d.ts.map +1 -1
  18. package/dist/geoarrow-loader.js +2 -12
  19. package/dist/geoarrow-writer.d.ts +2 -2
  20. package/dist/geoarrow-writer.d.ts.map +1 -1
  21. package/dist/geoarrow-writer.js +2 -2
  22. package/dist/index.cjs +426 -387
  23. package/dist/index.cjs.map +4 -4
  24. package/dist/index.d.ts +14 -13
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +16 -12
  27. package/dist/lib/encoders/encode-arrow.d.ts.map +1 -0
  28. package/dist/lib/encoders/encode-geoarrow.d.ts.map +1 -0
  29. package/dist/lib/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -0
  30. package/dist/lib/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +1 -0
  31. package/dist/lib/geoarrow/get-arrow-bounds.d.ts.map +1 -0
  32. package/dist/lib/parsers/parse-arrow.d.ts +9 -0
  33. package/dist/lib/parsers/parse-arrow.d.ts.map +1 -0
  34. package/dist/{parsers/parse-arrow-in-batches.js → lib/parsers/parse-arrow.js} +7 -3
  35. package/dist/lib/parsers/parse-geoarrow.d.ts +9 -0
  36. package/dist/lib/parsers/parse-geoarrow.d.ts.map +1 -0
  37. package/dist/{parsers/parse-geoarrow-sync.js → lib/parsers/parse-geoarrow.js} +9 -3
  38. package/dist/{schema → lib/tables}/convert-arrow-schema.d.ts +4 -0
  39. package/dist/lib/tables/convert-arrow-schema.d.ts.map +1 -0
  40. package/dist/{schema → lib/tables}/convert-arrow-schema.js +8 -0
  41. package/dist/lib/tables/convert-arrow-to-table.d.ts +15 -0
  42. package/dist/lib/tables/convert-arrow-to-table.d.ts.map +1 -0
  43. package/dist/lib/tables/convert-arrow-to-table.js +104 -0
  44. package/dist/lib/tables/convert-table-to-arrow.d.ts +16 -0
  45. package/dist/lib/tables/convert-table-to-arrow.d.ts.map +1 -0
  46. package/dist/lib/tables/convert-table-to-arrow.js +56 -0
  47. package/dist/lib/types.d.ts.map +1 -0
  48. package/dist/{lib → schema}/arrow-table-batch.d.ts +2 -1
  49. package/dist/schema/arrow-table-batch.d.ts.map +1 -0
  50. package/dist/{lib → schema}/arrow-table-batch.js +1 -0
  51. package/dist/{lib/arrow-table.d.ts → schema/arrow-table-type.d.ts} +3 -1
  52. package/dist/schema/arrow-table-type.d.ts.map +1 -0
  53. package/dist/triangulate-on-worker.js +1 -1
  54. package/dist/triangulation-worker.js +13 -5
  55. package/dist/workers/triangulation-worker.js +1 -1
  56. package/package.json +11 -7
  57. package/src/arrow-loader.ts +6 -57
  58. package/src/arrow-writer.ts +1 -2
  59. package/src/exports/arrow-loader.ts +49 -0
  60. package/src/exports/geoarrow-loader.ts +24 -0
  61. package/src/geoarrow-loader.ts +6 -22
  62. package/src/geoarrow-writer.ts +1 -1
  63. package/src/index.ts +23 -23
  64. package/src/{parsers/parse-arrow-in-batches.ts → lib/parsers/parse-arrow.ts} +11 -5
  65. package/src/lib/parsers/parse-geoarrow.ts +32 -0
  66. package/src/{schema → lib/tables}/convert-arrow-schema.ts +10 -0
  67. package/src/lib/tables/convert-arrow-to-table.ts +144 -0
  68. package/src/lib/tables/convert-table-to-arrow.ts +72 -0
  69. package/src/{lib → schema}/arrow-table-batch.ts +2 -1
  70. package/src/{lib/arrow-table.ts → schema/arrow-table-type.ts} +2 -0
  71. package/src/workers/triangulation-worker.ts +1 -1
  72. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +0 -1
  73. package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +0 -1
  74. package/dist/geoarrow/get-arrow-bounds.d.ts.map +0 -1
  75. package/dist/lib/arrow-table-batch.d.ts.map +0 -1
  76. package/dist/lib/arrow-table.d.ts.map +0 -1
  77. package/dist/lib/encode-arrow.d.ts.map +0 -1
  78. package/dist/lib/encode-geoarrow.d.ts.map +0 -1
  79. package/dist/parsers/parse-arrow-in-batches.d.ts +0 -6
  80. package/dist/parsers/parse-arrow-in-batches.d.ts.map +0 -1
  81. package/dist/parsers/parse-arrow-sync.d.ts +0 -6
  82. package/dist/parsers/parse-arrow-sync.d.ts.map +0 -1
  83. package/dist/parsers/parse-arrow-sync.js +0 -32
  84. package/dist/parsers/parse-geoarrow-in-batches.d.ts +0 -6
  85. package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +0 -1
  86. package/dist/parsers/parse-geoarrow-in-batches.js +0 -10
  87. package/dist/parsers/parse-geoarrow-sync.d.ts +0 -6
  88. package/dist/parsers/parse-geoarrow-sync.d.ts.map +0 -1
  89. package/dist/schema/arrow-type-utils.d.ts +0 -5
  90. package/dist/schema/arrow-type-utils.d.ts.map +0 -1
  91. package/dist/schema/arrow-type-utils.js +0 -51
  92. package/dist/schema/convert-arrow-schema.d.ts.map +0 -1
  93. package/dist/tables/convert-arrow-to-columnar-table.d.ts +0 -8
  94. package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +0 -1
  95. package/dist/tables/convert-arrow-to-columnar-table.js +0 -24
  96. package/dist/tables/convert-arrow-to-geojson-table.d.ts +0 -16
  97. package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +0 -1
  98. package/dist/tables/convert-arrow-to-geojson-table.js +0 -54
  99. package/dist/tables/convert-columnar-to-row-table.d.ts +0 -7
  100. package/dist/tables/convert-columnar-to-row-table.d.ts.map +0 -1
  101. package/dist/tables/convert-columnar-to-row-table.js +0 -25
  102. package/dist/tables/convert-table-to-arrow.d.ts +0 -42
  103. package/dist/tables/convert-table-to-arrow.d.ts.map +0 -1
  104. package/dist/tables/convert-table-to-arrow.js +0 -59
  105. package/dist/types.d.ts.map +0 -1
  106. package/src/parsers/parse-arrow-sync.ts +0 -44
  107. package/src/parsers/parse-geoarrow-in-batches.ts +0 -16
  108. package/src/parsers/parse-geoarrow-sync.ts +0 -23
  109. package/src/schema/arrow-type-utils.ts +0 -55
  110. package/src/tables/convert-arrow-to-columnar-table.ts +0 -31
  111. package/src/tables/convert-arrow-to-geojson-table.ts +0 -66
  112. package/src/tables/convert-columnar-to-row-table.ts +0 -31
  113. package/src/tables/convert-table-to-arrow.ts +0 -61
  114. /package/dist/lib/{encode-arrow.d.ts → encoders/encode-arrow.d.ts} +0 -0
  115. /package/dist/lib/{encode-arrow.js → encoders/encode-arrow.js} +0 -0
  116. /package/dist/lib/{encode-geoarrow.d.ts → encoders/encode-geoarrow.d.ts} +0 -0
  117. /package/dist/lib/{encode-geoarrow.js → encoders/encode-geoarrow.js} +0 -0
  118. /package/dist/{geoarrow → lib/geoarrow}/convert-geoarrow-to-binary-geometry.d.ts +0 -0
  119. /package/dist/{geoarrow → lib/geoarrow}/convert-geoarrow-to-binary-geometry.js +0 -0
  120. /package/dist/{geoarrow → lib/geoarrow}/convert-geoarrow-to-geojson-geometry.d.ts +0 -0
  121. /package/dist/{geoarrow → lib/geoarrow}/convert-geoarrow-to-geojson-geometry.js +0 -0
  122. /package/dist/{geoarrow → lib/geoarrow}/get-arrow-bounds.d.ts +0 -0
  123. /package/dist/{geoarrow → lib/geoarrow}/get-arrow-bounds.js +0 -0
  124. /package/dist/{types.d.ts → lib/types.d.ts} +0 -0
  125. /package/dist/{types.js → lib/types.js} +0 -0
  126. /package/dist/{lib/arrow-table.js → schema/arrow-table-type.js} +0 -0
  127. /package/src/lib/{encode-arrow.ts → encoders/encode-arrow.ts} +0 -0
  128. /package/src/lib/{encode-geoarrow.ts → encoders/encode-geoarrow.ts} +0 -0
  129. /package/src/{geoarrow → lib/geoarrow}/convert-geoarrow-to-binary-geometry.ts +0 -0
  130. /package/src/{geoarrow → lib/geoarrow}/convert-geoarrow-to-geojson-geometry.ts +0 -0
  131. /package/src/{geoarrow → lib/geoarrow}/get-arrow-bounds.ts +0 -0
  132. /package/src/{types.ts → lib/types.ts} +0 -0
@@ -205,954 +205,579 @@
205
205
  return await parser(data, { ...options }, context, loader);
206
206
  }
207
207
 
208
- // ../schema/src/lib/table/simple-table/data-type.ts
209
- function getDataTypeFromValue(value, defaultNumberType = "float32") {
210
- if (value instanceof Date) {
211
- return "date-millisecond";
208
+ // ../../node_modules/tslib/tslib.es6.mjs
209
+ function __rest(s, e) {
210
+ var t = {};
211
+ for (var p in s)
212
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
213
+ t[p] = s[p];
214
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
215
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
216
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
217
+ t[p[i]] = s[p[i]];
218
+ }
219
+ return t;
220
+ }
221
+ function __awaiter(thisArg, _arguments, P, generator) {
222
+ function adopt(value) {
223
+ return value instanceof P ? value : new P(function(resolve) {
224
+ resolve(value);
225
+ });
212
226
  }
213
- if (value instanceof Number) {
214
- return defaultNumberType;
227
+ return new (P || (P = Promise))(function(resolve, reject) {
228
+ function fulfilled(value) {
229
+ try {
230
+ step(generator.next(value));
231
+ } catch (e) {
232
+ reject(e);
233
+ }
234
+ }
235
+ function rejected(value) {
236
+ try {
237
+ step(generator["throw"](value));
238
+ } catch (e) {
239
+ reject(e);
240
+ }
241
+ }
242
+ function step(result) {
243
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
244
+ }
245
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
246
+ });
247
+ }
248
+ function __values(o) {
249
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
250
+ if (m)
251
+ return m.call(o);
252
+ if (o && typeof o.length === "number")
253
+ return {
254
+ next: function() {
255
+ if (o && i >= o.length)
256
+ o = void 0;
257
+ return { value: o && o[i++], done: !o };
258
+ }
259
+ };
260
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
261
+ }
262
+ function __await(v) {
263
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
264
+ }
265
+ function __asyncGenerator(thisArg, _arguments, generator) {
266
+ if (!Symbol.asyncIterator)
267
+ throw new TypeError("Symbol.asyncIterator is not defined.");
268
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
269
+ return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function() {
270
+ return this;
271
+ }, i;
272
+ function awaitReturn(f) {
273
+ return function(v) {
274
+ return Promise.resolve(v).then(f, reject);
275
+ };
215
276
  }
216
- if (typeof value === "string") {
217
- return "utf8";
277
+ function verb(n, f) {
278
+ if (g[n]) {
279
+ i[n] = function(v) {
280
+ return new Promise(function(a, b) {
281
+ q.push([n, v, a, b]) > 1 || resume(n, v);
282
+ });
283
+ };
284
+ if (f)
285
+ i[n] = f(i[n]);
286
+ }
218
287
  }
219
- if (value === null || value === "undefined") {
220
- return "null";
288
+ function resume(n, v) {
289
+ try {
290
+ step(g[n](v));
291
+ } catch (e) {
292
+ settle(q[0][3], e);
293
+ }
221
294
  }
222
- return "null";
223
- }
224
- function getDataTypeFromArray(array) {
225
- let type = getDataTypeFromTypedArray(array);
226
- if (type !== "null") {
227
- return { type, nullable: false };
295
+ function step(r) {
296
+ r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
228
297
  }
229
- if (array.length > 0) {
230
- type = getDataTypeFromValue(array[0]);
231
- return { type, nullable: true };
298
+ function fulfill(value) {
299
+ resume("next", value);
232
300
  }
233
- return { type: "null", nullable: true };
234
- }
235
- function getDataTypeFromTypedArray(array) {
236
- switch (array.constructor) {
237
- case Int8Array:
238
- return "int8";
239
- case Uint8Array:
240
- case Uint8ClampedArray:
241
- return "uint8";
242
- case Int16Array:
243
- return "int16";
244
- case Uint16Array:
245
- return "uint16";
246
- case Int32Array:
247
- return "int32";
248
- case Uint32Array:
249
- return "uint32";
250
- case Float32Array:
251
- return "float32";
252
- case Float64Array:
253
- return "float64";
254
- default:
255
- return "null";
301
+ function reject(value) {
302
+ resume("throw", value);
256
303
  }
257
- }
258
- function getArrayTypeFromDataType(type, nullable) {
259
- if (!nullable) {
260
- switch (type) {
261
- case "int8":
262
- return Int8Array;
263
- case "uint8":
264
- return Uint8Array;
265
- case "int16":
266
- return Int16Array;
267
- case "uint16":
268
- return Uint16Array;
269
- case "int32":
270
- return Int32Array;
271
- case "uint32":
272
- return Uint32Array;
273
- case "float32":
274
- return Float32Array;
275
- case "float64":
276
- return Float64Array;
277
- default:
278
- break;
279
- }
304
+ function settle(f, v) {
305
+ if (f(v), q.shift(), q.length)
306
+ resume(q[0][0], q[0][1]);
280
307
  }
281
- return Array;
282
308
  }
283
-
284
- // ../schema/src/lib/table/simple-table/table-accessors.ts
285
- function getTableLength(table) {
286
- switch (table.shape) {
287
- case "array-row-table":
288
- case "object-row-table":
289
- return table.data.length;
290
- case "geojson-table":
291
- return table.features.length;
292
- case "arrow-table":
293
- const arrowTable = table.data;
294
- return arrowTable.numRows;
295
- case "columnar-table":
296
- for (const column of Object.values(table.data)) {
297
- return column.length || 0;
298
- }
299
- return 0;
300
- default:
301
- throw new Error("table");
309
+ function __asyncDelegator(o) {
310
+ var i, p;
311
+ return i = {}, verb("next"), verb("throw", function(e) {
312
+ throw e;
313
+ }), verb("return"), i[Symbol.iterator] = function() {
314
+ return this;
315
+ }, i;
316
+ function verb(n, f) {
317
+ i[n] = o[n] ? function(v) {
318
+ return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v;
319
+ } : f;
302
320
  }
303
321
  }
304
- function getTableCell(table, rowIndex, columnName) {
305
- switch (table.shape) {
306
- case "array-row-table":
307
- const columnIndex = getTableColumnIndex(table, columnName);
308
- return table.data[rowIndex][columnIndex];
309
- case "object-row-table":
310
- return table.data[rowIndex][columnName];
311
- case "geojson-table":
312
- return table.features[rowIndex][columnName];
313
- case "columnar-table":
314
- const column = table.data[columnName];
315
- return column[rowIndex];
316
- case "arrow-table":
317
- const arrowTable = table.data;
318
- const arrowColumnIndex = arrowTable.schema.fields.findIndex(
319
- (field) => field.name === columnName
320
- );
321
- return arrowTable.getChildAt(arrowColumnIndex)?.get(rowIndex);
322
- default:
323
- throw new Error("todo");
322
+ function __asyncValues(o) {
323
+ if (!Symbol.asyncIterator)
324
+ throw new TypeError("Symbol.asyncIterator is not defined.");
325
+ var m = o[Symbol.asyncIterator], i;
326
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
327
+ return this;
328
+ }, i);
329
+ function verb(n) {
330
+ i[n] = o[n] && function(v) {
331
+ return new Promise(function(resolve, reject) {
332
+ v = o[n](v), settle(resolve, reject, v.done, v.value);
333
+ });
334
+ };
324
335
  }
325
- }
326
- function getTableColumnIndex(table, columnName) {
327
- const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
328
- if (columnIndex === void 0) {
329
- throw new Error(columnName);
336
+ function settle(resolve, reject, d, v) {
337
+ Promise.resolve(v).then(function(v2) {
338
+ resolve({ value: v2, done: d });
339
+ }, reject);
330
340
  }
331
- return columnIndex;
332
341
  }
333
- function getTableRowAsObject(table, rowIndex, target, copy) {
334
- switch (table.shape) {
335
- case "object-row-table":
336
- return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
337
- case "array-row-table":
338
- if (table.schema) {
339
- const objectRow2 = target || {};
340
- for (let i = 0; i < table.schema.fields.length; i++) {
341
- objectRow2[table.schema.fields[i].name] = table.data[rowIndex][i];
342
- }
343
- return objectRow2;
344
- }
345
- throw new Error("no schema");
346
- case "geojson-table":
347
- if (table.schema) {
348
- const objectRow2 = target || {};
349
- for (let i = 0; i < table.schema.fields.length; i++) {
350
- objectRow2[table.schema.fields[i].name] = table.features[rowIndex][i];
351
- }
352
- return objectRow2;
353
- }
354
- throw new Error("no schema");
355
- case "columnar-table":
356
- if (table.schema) {
357
- const objectRow2 = target || {};
358
- for (let i = 0; i < table.schema.fields.length; i++) {
359
- objectRow2[table.schema.fields[i].name] = table.data[table.schema.fields[i].name][rowIndex];
360
- }
361
- return objectRow2;
362
- } else {
363
- const objectRow2 = target || {};
364
- for (const [name, column] of Object.entries(table.data)) {
365
- objectRow2[name] = column[rowIndex];
366
- }
367
- return objectRow2;
368
- }
369
- case "arrow-table":
370
- const arrowTable = table.data;
371
- const objectRow = target || {};
372
- const row = arrowTable.get(rowIndex);
373
- const schema = arrowTable.schema;
374
- for (let i = 0; i < schema.fields.length; i++) {
375
- objectRow[schema.fields[i].name] = row?.[schema.fields[i].name];
376
- }
377
- return objectRow;
378
- default:
379
- throw new Error("shape");
342
+
343
+ // ../../node_modules/apache-arrow/util/buffer.mjs
344
+ var buffer_exports = {};
345
+ __export(buffer_exports, {
346
+ compareArrayLike: () => compareArrayLike,
347
+ joinUint8Arrays: () => joinUint8Arrays,
348
+ memcpy: () => memcpy,
349
+ rebaseValueOffsets: () => rebaseValueOffsets,
350
+ toArrayBufferView: () => toArrayBufferView,
351
+ toArrayBufferViewAsyncIterator: () => toArrayBufferViewAsyncIterator,
352
+ toArrayBufferViewIterator: () => toArrayBufferViewIterator,
353
+ toBigInt64Array: () => toBigInt64Array,
354
+ toBigUint64Array: () => toBigUint64Array,
355
+ toFloat32Array: () => toFloat32Array,
356
+ toFloat32ArrayAsyncIterator: () => toFloat32ArrayAsyncIterator,
357
+ toFloat32ArrayIterator: () => toFloat32ArrayIterator,
358
+ toFloat64Array: () => toFloat64Array,
359
+ toFloat64ArrayAsyncIterator: () => toFloat64ArrayAsyncIterator,
360
+ toFloat64ArrayIterator: () => toFloat64ArrayIterator,
361
+ toInt16Array: () => toInt16Array,
362
+ toInt16ArrayAsyncIterator: () => toInt16ArrayAsyncIterator,
363
+ toInt16ArrayIterator: () => toInt16ArrayIterator,
364
+ toInt32Array: () => toInt32Array,
365
+ toInt32ArrayAsyncIterator: () => toInt32ArrayAsyncIterator,
366
+ toInt32ArrayIterator: () => toInt32ArrayIterator,
367
+ toInt8Array: () => toInt8Array,
368
+ toInt8ArrayAsyncIterator: () => toInt8ArrayAsyncIterator,
369
+ toInt8ArrayIterator: () => toInt8ArrayIterator,
370
+ toUint16Array: () => toUint16Array,
371
+ toUint16ArrayAsyncIterator: () => toUint16ArrayAsyncIterator,
372
+ toUint16ArrayIterator: () => toUint16ArrayIterator,
373
+ toUint32Array: () => toUint32Array,
374
+ toUint32ArrayAsyncIterator: () => toUint32ArrayAsyncIterator,
375
+ toUint32ArrayIterator: () => toUint32ArrayIterator,
376
+ toUint8Array: () => toUint8Array,
377
+ toUint8ArrayAsyncIterator: () => toUint8ArrayAsyncIterator,
378
+ toUint8ArrayIterator: () => toUint8ArrayIterator,
379
+ toUint8ClampedArray: () => toUint8ClampedArray,
380
+ toUint8ClampedArrayAsyncIterator: () => toUint8ClampedArrayAsyncIterator,
381
+ toUint8ClampedArrayIterator: () => toUint8ClampedArrayIterator
382
+ });
383
+
384
+ // ../../node_modules/apache-arrow/util/utf8.mjs
385
+ var decoder = new TextDecoder("utf-8");
386
+ var decodeUtf8 = (buffer) => decoder.decode(buffer);
387
+ var encoder = new TextEncoder();
388
+ var encodeUtf8 = (value) => encoder.encode(value);
389
+
390
+ // ../../node_modules/apache-arrow/util/compat.mjs
391
+ var isNumber = (x) => typeof x === "number";
392
+ var isBoolean = (x) => typeof x === "boolean";
393
+ var isFunction = (x) => typeof x === "function";
394
+ var isObject = (x) => x != null && Object(x) === x;
395
+ var isPromise = (x) => {
396
+ return isObject(x) && isFunction(x.then);
397
+ };
398
+ var isIterable = (x) => {
399
+ return isObject(x) && isFunction(x[Symbol.iterator]);
400
+ };
401
+ var isAsyncIterable = (x) => {
402
+ return isObject(x) && isFunction(x[Symbol.asyncIterator]);
403
+ };
404
+ var isArrowJSON = (x) => {
405
+ return isObject(x) && isObject(x["schema"]);
406
+ };
407
+ var isIteratorResult = (x) => {
408
+ return isObject(x) && "done" in x && "value" in x;
409
+ };
410
+ var isFileHandle = (x) => {
411
+ return isObject(x) && isFunction(x["stat"]) && isNumber(x["fd"]);
412
+ };
413
+ var isFetchResponse = (x) => {
414
+ return isObject(x) && isReadableDOMStream(x["body"]);
415
+ };
416
+ var isReadableInterop = (x) => "_getDOMStream" in x && "_getNodeStream" in x;
417
+ var isWritableDOMStream = (x) => {
418
+ return isObject(x) && isFunction(x["abort"]) && isFunction(x["getWriter"]) && !isReadableInterop(x);
419
+ };
420
+ var isReadableDOMStream = (x) => {
421
+ return isObject(x) && isFunction(x["cancel"]) && isFunction(x["getReader"]) && !isReadableInterop(x);
422
+ };
423
+ var isWritableNodeStream = (x) => {
424
+ return isObject(x) && isFunction(x["end"]) && isFunction(x["write"]) && isBoolean(x["writable"]) && !isReadableInterop(x);
425
+ };
426
+ var isReadableNodeStream = (x) => {
427
+ return isObject(x) && isFunction(x["read"]) && isFunction(x["pipe"]) && isBoolean(x["readable"]) && !isReadableInterop(x);
428
+ };
429
+ var isFlatbuffersByteBuffer = (x) => {
430
+ return isObject(x) && isFunction(x["clear"]) && isFunction(x["bytes"]) && isFunction(x["position"]) && isFunction(x["setPosition"]) && isFunction(x["capacity"]) && isFunction(x["getBufferIdentifier"]) && isFunction(x["createLong"]);
431
+ };
432
+
433
+ // ../../node_modules/apache-arrow/util/buffer.mjs
434
+ var SharedArrayBuf = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : ArrayBuffer;
435
+ function collapseContiguousByteRanges(chunks) {
436
+ const result = chunks[0] ? [chunks[0]] : [];
437
+ let xOffset, yOffset, xLen, yLen;
438
+ for (let x, y, i = 0, j = 0, n = chunks.length; ++i < n; ) {
439
+ x = result[j];
440
+ y = chunks[i];
441
+ if (!x || !y || x.buffer !== y.buffer || y.byteOffset < x.byteOffset) {
442
+ y && (result[++j] = y);
443
+ continue;
444
+ }
445
+ ({ byteOffset: xOffset, byteLength: xLen } = x);
446
+ ({ byteOffset: yOffset, byteLength: yLen } = y);
447
+ if (xOffset + xLen < yOffset || yOffset + yLen < xOffset) {
448
+ y && (result[++j] = y);
449
+ continue;
450
+ }
451
+ result[j] = new Uint8Array(x.buffer, xOffset, yOffset - xOffset + yLen);
380
452
  }
453
+ return result;
381
454
  }
382
- function getTableRowAsArray(table, rowIndex, target, copy) {
383
- switch (table.shape) {
384
- case "array-row-table":
385
- return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
386
- case "object-row-table":
387
- if (table.schema) {
388
- const arrayRow2 = target || [];
389
- for (let i = 0; i < table.schema.fields.length; i++) {
390
- arrayRow2[i] = table.data[rowIndex][table.schema.fields[i].name];
391
- }
392
- return arrayRow2;
393
- }
394
- return Object.values(table.data[rowIndex]);
395
- case "geojson-table":
396
- if (table.schema) {
397
- const arrayRow2 = target || [];
398
- for (let i = 0; i < table.schema.fields.length; i++) {
399
- arrayRow2[i] = table.features[rowIndex][table.schema.fields[i].name];
400
- }
401
- return arrayRow2;
402
- }
403
- return Object.values(table.features[rowIndex]);
404
- case "columnar-table":
405
- if (table.schema) {
406
- const arrayRow2 = target || [];
407
- for (let i = 0; i < table.schema.fields.length; i++) {
408
- arrayRow2[i] = table.data[table.schema.fields[i].name][rowIndex];
409
- }
410
- return arrayRow2;
411
- } else {
412
- const arrayRow2 = target || [];
413
- let i = 0;
414
- for (const column of Object.values(table.data)) {
415
- arrayRow2[i] = column[rowIndex];
416
- i++;
417
- }
418
- return arrayRow2;
419
- }
420
- case "arrow-table":
421
- const arrowTable = table.data;
422
- const arrayRow = target || [];
423
- const row = arrowTable.get(rowIndex);
424
- const schema = arrowTable.schema;
425
- for (let i = 0; i < schema.fields.length; i++) {
426
- arrayRow[i] = row?.[schema.fields[i].name];
455
+ function memcpy(target, source, targetByteOffset = 0, sourceByteLength = source.byteLength) {
456
+ const targetByteLength = target.byteLength;
457
+ const dst = new Uint8Array(target.buffer, target.byteOffset, targetByteLength);
458
+ const src = new Uint8Array(source.buffer, source.byteOffset, Math.min(sourceByteLength, targetByteLength));
459
+ dst.set(src, targetByteOffset);
460
+ return target;
461
+ }
462
+ function joinUint8Arrays(chunks, size) {
463
+ const result = collapseContiguousByteRanges(chunks);
464
+ const byteLength = result.reduce((x, b) => x + b.byteLength, 0);
465
+ let source, sliced, buffer;
466
+ let offset = 0, index = -1;
467
+ const length = Math.min(size || Number.POSITIVE_INFINITY, byteLength);
468
+ for (const n = result.length; ++index < n; ) {
469
+ source = result[index];
470
+ sliced = source.subarray(0, Math.min(source.length, length - offset));
471
+ if (length <= offset + sliced.length) {
472
+ if (sliced.length < source.length) {
473
+ result[index] = source.subarray(sliced.length);
474
+ } else if (sliced.length === source.length) {
475
+ index++;
427
476
  }
428
- return arrayRow;
429
- default:
430
- throw new Error("shape");
477
+ buffer ? memcpy(buffer, sliced, offset) : buffer = sliced;
478
+ break;
479
+ }
480
+ memcpy(buffer || (buffer = new Uint8Array(length)), sliced, offset);
481
+ offset += sliced.length;
431
482
  }
483
+ return [buffer || new Uint8Array(0), result.slice(index), byteLength - (buffer ? buffer.byteLength : 0)];
432
484
  }
433
-
434
- // ../schema/src/lib/table/simple-table/table-schema.ts
435
- function deduceTableSchema(table) {
436
- switch (table.shape) {
437
- case "array-row-table":
438
- case "object-row-table":
439
- return deduceSchemaFromRows(table.data);
440
- case "geojson-table":
441
- return deduceSchemaFromGeoJSON(table.features);
442
- case "columnar-table":
443
- return deduceSchemaFromColumns(table.data);
444
- case "arrow-table":
445
- default:
446
- throw new Error("Deduce schema");
485
+ function toArrayBufferView(ArrayBufferViewCtor, input) {
486
+ let value = isIteratorResult(input) ? input.value : input;
487
+ if (value instanceof ArrayBufferViewCtor) {
488
+ if (ArrayBufferViewCtor === Uint8Array) {
489
+ return new ArrayBufferViewCtor(value.buffer, value.byteOffset, value.byteLength);
490
+ }
491
+ return value;
447
492
  }
448
- }
449
- function deduceSchemaFromColumns(columnarTable) {
450
- const fields = [];
451
- for (const [columnName, column] of Object.entries(columnarTable)) {
452
- const field = deduceFieldFromColumn(column, columnName);
453
- fields.push(field);
493
+ if (!value) {
494
+ return new ArrayBufferViewCtor(0);
454
495
  }
455
- return { fields, metadata: {} };
456
- }
457
- function deduceSchemaFromRows(rowTable) {
458
- if (!rowTable.length) {
459
- throw new Error("deduce from empty table");
496
+ if (typeof value === "string") {
497
+ value = encodeUtf8(value);
460
498
  }
461
- const fields = [];
462
- const row0 = rowTable[0];
463
- for (const [columnName, value] of Object.entries(row0)) {
464
- fields.push(deduceFieldFromValue(value, columnName));
499
+ if (value instanceof ArrayBuffer) {
500
+ return new ArrayBufferViewCtor(value);
465
501
  }
466
- return { fields, metadata: {} };
467
- }
468
- function deduceSchemaFromGeoJSON(features) {
469
- if (!features.length) {
470
- throw new Error("deduce from empty table");
502
+ if (value instanceof SharedArrayBuf) {
503
+ return new ArrayBufferViewCtor(value);
471
504
  }
472
- const fields = [];
473
- const row0 = features[0].properties || {};
474
- for (const [columnName, value] of Object.entries(row0)) {
475
- fields.push(deduceFieldFromValue(value, columnName));
505
+ if (isFlatbuffersByteBuffer(value)) {
506
+ return toArrayBufferView(ArrayBufferViewCtor, value.bytes());
476
507
  }
477
- return { fields, metadata: {} };
478
- }
479
- function deduceFieldFromColumn(column, name) {
480
- if (ArrayBuffer.isView(column)) {
481
- const type = getDataTypeFromArray(column);
482
- return {
483
- name,
484
- type: type.type || "null",
485
- nullable: type.nullable
486
- // metadata: {}
487
- };
488
- }
489
- if (Array.isArray(column) && column.length > 0) {
490
- const value = column[0];
491
- const type = getDataTypeFromValue(value);
492
- return {
493
- name,
494
- type,
495
- nullable: true
496
- // metadata: {},
497
- };
498
- }
499
- throw new Error("empty table");
508
+ return !ArrayBuffer.isView(value) ? ArrayBufferViewCtor.from(value) : value.byteLength <= 0 ? new ArrayBufferViewCtor(0) : new ArrayBufferViewCtor(value.buffer, value.byteOffset, value.byteLength / ArrayBufferViewCtor.BYTES_PER_ELEMENT);
500
509
  }
501
- function deduceFieldFromValue(value, name) {
502
- const type = getDataTypeFromValue(value);
503
- return {
504
- name,
505
- type,
506
- nullable: true
507
- // metadata: {}
510
+ var toInt8Array = (input) => toArrayBufferView(Int8Array, input);
511
+ var toInt16Array = (input) => toArrayBufferView(Int16Array, input);
512
+ var toInt32Array = (input) => toArrayBufferView(Int32Array, input);
513
+ var toBigInt64Array = (input) => toArrayBufferView(BigInt64Array, input);
514
+ var toUint8Array = (input) => toArrayBufferView(Uint8Array, input);
515
+ var toUint16Array = (input) => toArrayBufferView(Uint16Array, input);
516
+ var toUint32Array = (input) => toArrayBufferView(Uint32Array, input);
517
+ var toBigUint64Array = (input) => toArrayBufferView(BigUint64Array, input);
518
+ var toFloat32Array = (input) => toArrayBufferView(Float32Array, input);
519
+ var toFloat64Array = (input) => toArrayBufferView(Float64Array, input);
520
+ var toUint8ClampedArray = (input) => toArrayBufferView(Uint8ClampedArray, input);
521
+ var pump = (iterator) => {
522
+ iterator.next();
523
+ return iterator;
524
+ };
525
+ function* toArrayBufferViewIterator(ArrayCtor, source) {
526
+ const wrap = function* (x) {
527
+ yield x;
508
528
  };
529
+ const buffers = typeof source === "string" ? wrap(source) : ArrayBuffer.isView(source) ? wrap(source) : source instanceof ArrayBuffer ? wrap(source) : source instanceof SharedArrayBuf ? wrap(source) : !isIterable(source) ? wrap(source) : source;
530
+ yield* pump(function* (it) {
531
+ let r = null;
532
+ do {
533
+ r = it.next(yield toArrayBufferView(ArrayCtor, r));
534
+ } while (!r.done);
535
+ }(buffers[Symbol.iterator]()));
536
+ return new ArrayCtor();
509
537
  }
510
-
511
- // ../schema/src/lib/table/simple-table/table-column.ts
512
- function makeColumnFromField(field, length) {
513
- const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
514
- return new ArrayType(length);
515
- }
516
-
517
- // ../schema/src/lib/table/simple-table/convert-table.ts
518
- function convertTable(table, shape) {
519
- switch (shape) {
520
- case "object-row-table":
521
- return makeObjectRowTable(table);
522
- case "array-row-table":
523
- return makeArrayRowTable(table);
524
- case "columnar-table":
525
- return makeColumnarTable(table);
526
- case "arrow-table":
527
- return makeArrowTable(table);
528
- default:
529
- throw new Error(shape);
530
- }
531
- }
532
- function makeArrowTable(table) {
533
- const _makeArrowTable = globalThis.__loaders?._makeArrowTable;
534
- if (!_makeArrowTable) {
535
- throw new Error("");
536
- }
537
- return _makeArrowTable(table);
538
- }
539
- function makeColumnarTable(table) {
540
- const schema = table.schema || deduceTableSchema(table);
541
- const fields = table.schema?.fields || [];
542
- if (table.shape === "columnar-table") {
543
- return { ...table, schema };
544
- }
545
- const length = getTableLength(table);
546
- const columns = {};
547
- for (const field of fields) {
548
- const column = makeColumnFromField(field, length);
549
- columns[field.name] = column;
550
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
551
- column[rowIndex] = getTableCell(table, rowIndex, field.name);
538
+ var toInt8ArrayIterator = (input) => toArrayBufferViewIterator(Int8Array, input);
539
+ var toInt16ArrayIterator = (input) => toArrayBufferViewIterator(Int16Array, input);
540
+ var toInt32ArrayIterator = (input) => toArrayBufferViewIterator(Int32Array, input);
541
+ var toUint8ArrayIterator = (input) => toArrayBufferViewIterator(Uint8Array, input);
542
+ var toUint16ArrayIterator = (input) => toArrayBufferViewIterator(Uint16Array, input);
543
+ var toUint32ArrayIterator = (input) => toArrayBufferViewIterator(Uint32Array, input);
544
+ var toFloat32ArrayIterator = (input) => toArrayBufferViewIterator(Float32Array, input);
545
+ var toFloat64ArrayIterator = (input) => toArrayBufferViewIterator(Float64Array, input);
546
+ var toUint8ClampedArrayIterator = (input) => toArrayBufferViewIterator(Uint8ClampedArray, input);
547
+ function toArrayBufferViewAsyncIterator(ArrayCtor, source) {
548
+ return __asyncGenerator(this, arguments, function* toArrayBufferViewAsyncIterator_1() {
549
+ if (isPromise(source)) {
550
+ return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(toArrayBufferViewAsyncIterator(ArrayCtor, yield __await(source))))));
552
551
  }
553
- }
554
- return {
555
- shape: "columnar-table",
556
- schema,
557
- data: columns
558
- };
552
+ const wrap = function(x) {
553
+ return __asyncGenerator(this, arguments, function* () {
554
+ yield yield __await(yield __await(x));
555
+ });
556
+ };
557
+ const emit = function(source2) {
558
+ return __asyncGenerator(this, arguments, function* () {
559
+ yield __await(yield* __asyncDelegator(__asyncValues(pump(function* (it) {
560
+ let r = null;
561
+ do {
562
+ r = it.next(yield r === null || r === void 0 ? void 0 : r.value);
563
+ } while (!r.done);
564
+ }(source2[Symbol.iterator]())))));
565
+ });
566
+ };
567
+ const buffers = typeof source === "string" ? wrap(source) : ArrayBuffer.isView(source) ? wrap(source) : source instanceof ArrayBuffer ? wrap(source) : source instanceof SharedArrayBuf ? wrap(source) : isIterable(source) ? emit(source) : !isAsyncIterable(source) ? wrap(source) : source;
568
+ yield __await(
569
+ // otherwise if AsyncIterable, use it
570
+ yield* __asyncDelegator(__asyncValues(pump(function(it) {
571
+ return __asyncGenerator(this, arguments, function* () {
572
+ let r = null;
573
+ do {
574
+ r = yield __await(it.next(yield yield __await(toArrayBufferView(ArrayCtor, r))));
575
+ } while (!r.done);
576
+ });
577
+ }(buffers[Symbol.asyncIterator]()))))
578
+ );
579
+ return yield __await(new ArrayCtor());
580
+ });
559
581
  }
560
- function makeArrayRowTable(table) {
561
- if (table.shape === "array-row-table") {
562
- return table;
563
- }
564
- const length = getTableLength(table);
565
- const data = new Array(length);
566
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
567
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
582
+ var toInt8ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int8Array, input);
583
+ var toInt16ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int16Array, input);
584
+ var toInt32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int32Array, input);
585
+ var toUint8ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint8Array, input);
586
+ var toUint16ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint16Array, input);
587
+ var toUint32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint32Array, input);
588
+ var toFloat32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Float32Array, input);
589
+ var toFloat64ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Float64Array, input);
590
+ var toUint8ClampedArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint8ClampedArray, input);
591
+ function rebaseValueOffsets(offset, length, valueOffsets) {
592
+ if (offset !== 0) {
593
+ valueOffsets = valueOffsets.slice(0, length);
594
+ for (let i = -1, n = valueOffsets.length; ++i < n; ) {
595
+ valueOffsets[i] += offset;
596
+ }
568
597
  }
569
- return {
570
- shape: "array-row-table",
571
- schema: table.schema,
572
- data
573
- };
598
+ return valueOffsets.subarray(0, length);
574
599
  }
575
- function makeObjectRowTable(table) {
576
- if (table.shape === "object-row-table") {
577
- return table;
600
+ function compareArrayLike(a, b) {
601
+ let i = 0;
602
+ const n = a.length;
603
+ if (n !== b.length) {
604
+ return false;
578
605
  }
579
- const length = getTableLength(table);
580
- const data = new Array(length);
581
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
582
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
606
+ if (n > 0) {
607
+ do {
608
+ if (a[i] !== b[i]) {
609
+ return false;
610
+ }
611
+ } while (++i < n);
583
612
  }
584
- return {
585
- shape: "object-row-table",
586
- schema: table.schema,
587
- data
588
- };
613
+ return true;
589
614
  }
590
615
 
591
- // ../../node_modules/tslib/tslib.es6.mjs
592
- function __rest(s, e) {
593
- var t = {};
594
- for (var p in s)
595
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
596
- t[p] = s[p];
597
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
598
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
599
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
600
- t[p[i]] = s[p[i]];
616
+ // ../../node_modules/apache-arrow/io/adapters.mjs
617
+ var adapters_default = {
618
+ fromIterable(source) {
619
+ return pump2(fromIterable(source));
620
+ },
621
+ fromAsyncIterable(source) {
622
+ return pump2(fromAsyncIterable(source));
623
+ },
624
+ fromDOMStream(source) {
625
+ return pump2(fromDOMStream(source));
626
+ },
627
+ fromNodeStream(stream) {
628
+ return pump2(fromNodeStream(stream));
629
+ },
630
+ // @ts-ignore
631
+ toDOMStream(source, options) {
632
+ throw new Error(`"toDOMStream" not available in this environment`);
633
+ },
634
+ // @ts-ignore
635
+ toNodeStream(source, options) {
636
+ throw new Error(`"toNodeStream" not available in this environment`);
637
+ }
638
+ };
639
+ var pump2 = (iterator) => {
640
+ iterator.next();
641
+ return iterator;
642
+ };
643
+ function* fromIterable(source) {
644
+ let done, threw = false;
645
+ let buffers = [], buffer;
646
+ let cmd, size, bufferLength = 0;
647
+ function byteRange() {
648
+ if (cmd === "peek") {
649
+ return joinUint8Arrays(buffers, size)[0];
601
650
  }
602
- return t;
603
- }
604
- function __awaiter(thisArg, _arguments, P, generator) {
605
- function adopt(value) {
606
- return value instanceof P ? value : new P(function(resolve) {
607
- resolve(value);
608
- });
651
+ [buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
652
+ return buffer;
609
653
  }
610
- return new (P || (P = Promise))(function(resolve, reject) {
611
- function fulfilled(value) {
612
- try {
613
- step(generator.next(value));
614
- } catch (e) {
615
- reject(e);
654
+ ({ cmd, size } = (yield (() => null)()) || { cmd: "read", size: 0 });
655
+ const it = toUint8ArrayIterator(source)[Symbol.iterator]();
656
+ try {
657
+ do {
658
+ ({ done, value: buffer } = Number.isNaN(size - bufferLength) ? it.next() : it.next(size - bufferLength));
659
+ if (!done && buffer.byteLength > 0) {
660
+ buffers.push(buffer);
661
+ bufferLength += buffer.byteLength;
616
662
  }
617
- }
618
- function rejected(value) {
619
- try {
620
- step(generator["throw"](value));
621
- } catch (e) {
622
- reject(e);
663
+ if (done || size <= bufferLength) {
664
+ do {
665
+ ({ cmd, size } = yield byteRange());
666
+ } while (size < bufferLength);
667
+ }
668
+ } while (!done);
669
+ } catch (e) {
670
+ (threw = true) && typeof it.throw === "function" && it.throw(e);
671
+ } finally {
672
+ threw === false && typeof it.return === "function" && it.return(null);
673
+ }
674
+ return null;
675
+ }
676
+ function fromAsyncIterable(source) {
677
+ return __asyncGenerator(this, arguments, function* fromAsyncIterable_1() {
678
+ let done, threw = false;
679
+ let buffers = [], buffer;
680
+ let cmd, size, bufferLength = 0;
681
+ function byteRange() {
682
+ if (cmd === "peek") {
683
+ return joinUint8Arrays(buffers, size)[0];
623
684
  }
685
+ [buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
686
+ return buffer;
624
687
  }
625
- function step(result) {
626
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
688
+ ({ cmd, size } = (yield yield __await((() => null)())) || { cmd: "read", size: 0 });
689
+ const it = toUint8ArrayAsyncIterator(source)[Symbol.asyncIterator]();
690
+ try {
691
+ do {
692
+ ({ done, value: buffer } = Number.isNaN(size - bufferLength) ? yield __await(it.next()) : yield __await(it.next(size - bufferLength)));
693
+ if (!done && buffer.byteLength > 0) {
694
+ buffers.push(buffer);
695
+ bufferLength += buffer.byteLength;
696
+ }
697
+ if (done || size <= bufferLength) {
698
+ do {
699
+ ({ cmd, size } = yield yield __await(byteRange()));
700
+ } while (size < bufferLength);
701
+ }
702
+ } while (!done);
703
+ } catch (e) {
704
+ (threw = true) && typeof it.throw === "function" && (yield __await(it.throw(e)));
705
+ } finally {
706
+ threw === false && typeof it.return === "function" && (yield __await(it.return(new Uint8Array(0))));
627
707
  }
628
- step((generator = generator.apply(thisArg, _arguments || [])).next());
708
+ return yield __await(null);
629
709
  });
630
710
  }
631
- function __values(o) {
632
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
633
- if (m)
634
- return m.call(o);
635
- if (o && typeof o.length === "number")
636
- return {
637
- next: function() {
638
- if (o && i >= o.length)
639
- o = void 0;
640
- return { value: o && o[i++], done: !o };
711
+ function fromDOMStream(source) {
712
+ return __asyncGenerator(this, arguments, function* fromDOMStream_1() {
713
+ let done = false, threw = false;
714
+ let buffers = [], buffer;
715
+ let cmd, size, bufferLength = 0;
716
+ function byteRange() {
717
+ if (cmd === "peek") {
718
+ return joinUint8Arrays(buffers, size)[0];
641
719
  }
642
- };
643
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
644
- }
645
- function __await(v) {
646
- return this instanceof __await ? (this.v = v, this) : new __await(v);
647
- }
648
- function __asyncGenerator(thisArg, _arguments, generator) {
649
- if (!Symbol.asyncIterator)
650
- throw new TypeError("Symbol.asyncIterator is not defined.");
651
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
652
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
653
- return this;
654
- }, i;
655
- function verb(n) {
656
- if (g[n])
657
- i[n] = function(v) {
658
- return new Promise(function(a, b) {
659
- q.push([n, v, a, b]) > 1 || resume(n, v);
660
- });
661
- };
662
- }
663
- function resume(n, v) {
720
+ [buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
721
+ return buffer;
722
+ }
723
+ ({ cmd, size } = (yield yield __await((() => null)())) || { cmd: "read", size: 0 });
724
+ const it = new AdaptiveByteReader(source);
664
725
  try {
665
- step(g[n](v));
726
+ do {
727
+ ({ done, value: buffer } = Number.isNaN(size - bufferLength) ? yield __await(it["read"]()) : yield __await(it["read"](size - bufferLength)));
728
+ if (!done && buffer.byteLength > 0) {
729
+ buffers.push(toUint8Array(buffer));
730
+ bufferLength += buffer.byteLength;
731
+ }
732
+ if (done || size <= bufferLength) {
733
+ do {
734
+ ({ cmd, size } = yield yield __await(byteRange()));
735
+ } while (size < bufferLength);
736
+ }
737
+ } while (!done);
666
738
  } catch (e) {
667
- settle(q[0][3], e);
739
+ (threw = true) && (yield __await(it["cancel"](e)));
740
+ } finally {
741
+ threw === false ? yield __await(it["cancel"]()) : source["locked"] && it.releaseLock();
668
742
  }
743
+ return yield __await(null);
744
+ });
745
+ }
746
+ var AdaptiveByteReader = class {
747
+ constructor(source) {
748
+ this.source = source;
749
+ this.reader = null;
750
+ this.reader = this.source["getReader"]();
751
+ this.reader["closed"].catch(() => {
752
+ });
669
753
  }
670
- function step(r) {
671
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
672
- }
673
- function fulfill(value) {
674
- resume("next", value);
675
- }
676
- function reject(value) {
677
- resume("throw", value);
678
- }
679
- function settle(f, v) {
680
- if (f(v), q.shift(), q.length)
681
- resume(q[0][0], q[0][1]);
754
+ get closed() {
755
+ return this.reader ? this.reader["closed"].catch(() => {
756
+ }) : Promise.resolve();
682
757
  }
683
- }
684
- function __asyncDelegator(o) {
685
- var i, p;
686
- return i = {}, verb("next"), verb("throw", function(e) {
687
- throw e;
688
- }), verb("return"), i[Symbol.iterator] = function() {
689
- return this;
690
- }, i;
691
- function verb(n, f) {
692
- i[n] = o[n] ? function(v) {
693
- return (p = !p) ? { value: __await(o[n](v)), done: false } : f ? f(v) : v;
694
- } : f;
758
+ releaseLock() {
759
+ if (this.reader) {
760
+ this.reader.releaseLock();
761
+ }
762
+ this.reader = null;
695
763
  }
696
- }
697
- function __asyncValues(o) {
698
- if (!Symbol.asyncIterator)
699
- throw new TypeError("Symbol.asyncIterator is not defined.");
700
- var m = o[Symbol.asyncIterator], i;
701
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
702
- return this;
703
- }, i);
704
- function verb(n) {
705
- i[n] = o[n] && function(v) {
706
- return new Promise(function(resolve, reject) {
707
- v = o[n](v), settle(resolve, reject, v.done, v.value);
708
- });
709
- };
764
+ cancel(reason) {
765
+ return __awaiter(this, void 0, void 0, function* () {
766
+ const { reader, source } = this;
767
+ reader && (yield reader["cancel"](reason).catch(() => {
768
+ }));
769
+ source && (source["locked"] && this.releaseLock());
770
+ });
710
771
  }
711
- function settle(resolve, reject, d, v) {
712
- Promise.resolve(v).then(function(v2) {
713
- resolve({ value: v2, done: d });
714
- }, reject);
715
- }
716
- }
717
-
718
- // ../../node_modules/apache-arrow/util/buffer.mjs
719
- var buffer_exports = {};
720
- __export(buffer_exports, {
721
- compareArrayLike: () => compareArrayLike,
722
- joinUint8Arrays: () => joinUint8Arrays,
723
- memcpy: () => memcpy,
724
- rebaseValueOffsets: () => rebaseValueOffsets,
725
- toArrayBufferView: () => toArrayBufferView,
726
- toArrayBufferViewAsyncIterator: () => toArrayBufferViewAsyncIterator,
727
- toArrayBufferViewIterator: () => toArrayBufferViewIterator,
728
- toBigInt64Array: () => toBigInt64Array,
729
- toBigUint64Array: () => toBigUint64Array,
730
- toFloat32Array: () => toFloat32Array,
731
- toFloat32ArrayAsyncIterator: () => toFloat32ArrayAsyncIterator,
732
- toFloat32ArrayIterator: () => toFloat32ArrayIterator,
733
- toFloat64Array: () => toFloat64Array,
734
- toFloat64ArrayAsyncIterator: () => toFloat64ArrayAsyncIterator,
735
- toFloat64ArrayIterator: () => toFloat64ArrayIterator,
736
- toInt16Array: () => toInt16Array,
737
- toInt16ArrayAsyncIterator: () => toInt16ArrayAsyncIterator,
738
- toInt16ArrayIterator: () => toInt16ArrayIterator,
739
- toInt32Array: () => toInt32Array,
740
- toInt32ArrayAsyncIterator: () => toInt32ArrayAsyncIterator,
741
- toInt32ArrayIterator: () => toInt32ArrayIterator,
742
- toInt8Array: () => toInt8Array,
743
- toInt8ArrayAsyncIterator: () => toInt8ArrayAsyncIterator,
744
- toInt8ArrayIterator: () => toInt8ArrayIterator,
745
- toUint16Array: () => toUint16Array,
746
- toUint16ArrayAsyncIterator: () => toUint16ArrayAsyncIterator,
747
- toUint16ArrayIterator: () => toUint16ArrayIterator,
748
- toUint32Array: () => toUint32Array,
749
- toUint32ArrayAsyncIterator: () => toUint32ArrayAsyncIterator,
750
- toUint32ArrayIterator: () => toUint32ArrayIterator,
751
- toUint8Array: () => toUint8Array,
752
- toUint8ArrayAsyncIterator: () => toUint8ArrayAsyncIterator,
753
- toUint8ArrayIterator: () => toUint8ArrayIterator,
754
- toUint8ClampedArray: () => toUint8ClampedArray,
755
- toUint8ClampedArrayAsyncIterator: () => toUint8ClampedArrayAsyncIterator,
756
- toUint8ClampedArrayIterator: () => toUint8ClampedArrayIterator
757
- });
758
-
759
- // ../../node_modules/apache-arrow/util/utf8.mjs
760
- var decoder = new TextDecoder("utf-8");
761
- var decodeUtf8 = (buffer) => decoder.decode(buffer);
762
- var encoder = new TextEncoder();
763
- var encodeUtf8 = (value) => encoder.encode(value);
764
-
765
- // ../../node_modules/apache-arrow/util/compat.mjs
766
- var isNumber = (x) => typeof x === "number";
767
- var isBoolean = (x) => typeof x === "boolean";
768
- var isFunction = (x) => typeof x === "function";
769
- var isObject = (x) => x != null && Object(x) === x;
770
- var isPromise = (x) => {
771
- return isObject(x) && isFunction(x.then);
772
- };
773
- var isIterable = (x) => {
774
- return isObject(x) && isFunction(x[Symbol.iterator]);
775
- };
776
- var isAsyncIterable = (x) => {
777
- return isObject(x) && isFunction(x[Symbol.asyncIterator]);
778
- };
779
- var isArrowJSON = (x) => {
780
- return isObject(x) && isObject(x["schema"]);
781
- };
782
- var isIteratorResult = (x) => {
783
- return isObject(x) && "done" in x && "value" in x;
784
- };
785
- var isFileHandle = (x) => {
786
- return isObject(x) && isFunction(x["stat"]) && isNumber(x["fd"]);
787
- };
788
- var isFetchResponse = (x) => {
789
- return isObject(x) && isReadableDOMStream(x["body"]);
790
- };
791
- var isReadableInterop = (x) => "_getDOMStream" in x && "_getNodeStream" in x;
792
- var isWritableDOMStream = (x) => {
793
- return isObject(x) && isFunction(x["abort"]) && isFunction(x["getWriter"]) && !isReadableInterop(x);
794
- };
795
- var isReadableDOMStream = (x) => {
796
- return isObject(x) && isFunction(x["cancel"]) && isFunction(x["getReader"]) && !isReadableInterop(x);
797
- };
798
- var isWritableNodeStream = (x) => {
799
- return isObject(x) && isFunction(x["end"]) && isFunction(x["write"]) && isBoolean(x["writable"]) && !isReadableInterop(x);
800
- };
801
- var isReadableNodeStream = (x) => {
802
- return isObject(x) && isFunction(x["read"]) && isFunction(x["pipe"]) && isBoolean(x["readable"]) && !isReadableInterop(x);
803
- };
804
- var isFlatbuffersByteBuffer = (x) => {
805
- return isObject(x) && isFunction(x["clear"]) && isFunction(x["bytes"]) && isFunction(x["position"]) && isFunction(x["setPosition"]) && isFunction(x["capacity"]) && isFunction(x["getBufferIdentifier"]) && isFunction(x["createLong"]);
806
- };
807
-
808
- // ../../node_modules/apache-arrow/util/buffer.mjs
809
- var SharedArrayBuf = typeof SharedArrayBuffer !== "undefined" ? SharedArrayBuffer : ArrayBuffer;
810
- function collapseContiguousByteRanges(chunks) {
811
- const result = chunks[0] ? [chunks[0]] : [];
812
- let xOffset, yOffset, xLen, yLen;
813
- for (let x, y, i = 0, j = 0, n = chunks.length; ++i < n; ) {
814
- x = result[j];
815
- y = chunks[i];
816
- if (!x || !y || x.buffer !== y.buffer || y.byteOffset < x.byteOffset) {
817
- y && (result[++j] = y);
818
- continue;
819
- }
820
- ({ byteOffset: xOffset, byteLength: xLen } = x);
821
- ({ byteOffset: yOffset, byteLength: yLen } = y);
822
- if (xOffset + xLen < yOffset || yOffset + yLen < xOffset) {
823
- y && (result[++j] = y);
824
- continue;
825
- }
826
- result[j] = new Uint8Array(x.buffer, xOffset, yOffset - xOffset + yLen);
827
- }
828
- return result;
829
- }
830
- function memcpy(target, source, targetByteOffset = 0, sourceByteLength = source.byteLength) {
831
- const targetByteLength = target.byteLength;
832
- const dst = new Uint8Array(target.buffer, target.byteOffset, targetByteLength);
833
- const src = new Uint8Array(source.buffer, source.byteOffset, Math.min(sourceByteLength, targetByteLength));
834
- dst.set(src, targetByteOffset);
835
- return target;
836
- }
837
- function joinUint8Arrays(chunks, size) {
838
- const result = collapseContiguousByteRanges(chunks);
839
- const byteLength = result.reduce((x, b) => x + b.byteLength, 0);
840
- let source, sliced, buffer;
841
- let offset = 0, index = -1;
842
- const length = Math.min(size || Number.POSITIVE_INFINITY, byteLength);
843
- for (const n = result.length; ++index < n; ) {
844
- source = result[index];
845
- sliced = source.subarray(0, Math.min(source.length, length - offset));
846
- if (length <= offset + sliced.length) {
847
- if (sliced.length < source.length) {
848
- result[index] = source.subarray(sliced.length);
849
- } else if (sliced.length === source.length) {
850
- index++;
851
- }
852
- buffer ? memcpy(buffer, sliced, offset) : buffer = sliced;
853
- break;
854
- }
855
- memcpy(buffer || (buffer = new Uint8Array(length)), sliced, offset);
856
- offset += sliced.length;
857
- }
858
- return [buffer || new Uint8Array(0), result.slice(index), byteLength - (buffer ? buffer.byteLength : 0)];
859
- }
860
- function toArrayBufferView(ArrayBufferViewCtor, input) {
861
- let value = isIteratorResult(input) ? input.value : input;
862
- if (value instanceof ArrayBufferViewCtor) {
863
- if (ArrayBufferViewCtor === Uint8Array) {
864
- return new ArrayBufferViewCtor(value.buffer, value.byteOffset, value.byteLength);
865
- }
866
- return value;
867
- }
868
- if (!value) {
869
- return new ArrayBufferViewCtor(0);
870
- }
871
- if (typeof value === "string") {
872
- value = encodeUtf8(value);
873
- }
874
- if (value instanceof ArrayBuffer) {
875
- return new ArrayBufferViewCtor(value);
876
- }
877
- if (value instanceof SharedArrayBuf) {
878
- return new ArrayBufferViewCtor(value);
879
- }
880
- if (isFlatbuffersByteBuffer(value)) {
881
- return toArrayBufferView(ArrayBufferViewCtor, value.bytes());
882
- }
883
- return !ArrayBuffer.isView(value) ? ArrayBufferViewCtor.from(value) : value.byteLength <= 0 ? new ArrayBufferViewCtor(0) : new ArrayBufferViewCtor(value.buffer, value.byteOffset, value.byteLength / ArrayBufferViewCtor.BYTES_PER_ELEMENT);
884
- }
885
- var toInt8Array = (input) => toArrayBufferView(Int8Array, input);
886
- var toInt16Array = (input) => toArrayBufferView(Int16Array, input);
887
- var toInt32Array = (input) => toArrayBufferView(Int32Array, input);
888
- var toBigInt64Array = (input) => toArrayBufferView(BigInt64Array, input);
889
- var toUint8Array = (input) => toArrayBufferView(Uint8Array, input);
890
- var toUint16Array = (input) => toArrayBufferView(Uint16Array, input);
891
- var toUint32Array = (input) => toArrayBufferView(Uint32Array, input);
892
- var toBigUint64Array = (input) => toArrayBufferView(BigUint64Array, input);
893
- var toFloat32Array = (input) => toArrayBufferView(Float32Array, input);
894
- var toFloat64Array = (input) => toArrayBufferView(Float64Array, input);
895
- var toUint8ClampedArray = (input) => toArrayBufferView(Uint8ClampedArray, input);
896
- var pump = (iterator) => {
897
- iterator.next();
898
- return iterator;
899
- };
900
- function* toArrayBufferViewIterator(ArrayCtor, source) {
901
- const wrap = function* (x) {
902
- yield x;
903
- };
904
- const buffers = typeof source === "string" ? wrap(source) : ArrayBuffer.isView(source) ? wrap(source) : source instanceof ArrayBuffer ? wrap(source) : source instanceof SharedArrayBuf ? wrap(source) : !isIterable(source) ? wrap(source) : source;
905
- yield* pump(function* (it) {
906
- let r = null;
907
- do {
908
- r = it.next(yield toArrayBufferView(ArrayCtor, r));
909
- } while (!r.done);
910
- }(buffers[Symbol.iterator]()));
911
- return new ArrayCtor();
912
- }
913
- var toInt8ArrayIterator = (input) => toArrayBufferViewIterator(Int8Array, input);
914
- var toInt16ArrayIterator = (input) => toArrayBufferViewIterator(Int16Array, input);
915
- var toInt32ArrayIterator = (input) => toArrayBufferViewIterator(Int32Array, input);
916
- var toUint8ArrayIterator = (input) => toArrayBufferViewIterator(Uint8Array, input);
917
- var toUint16ArrayIterator = (input) => toArrayBufferViewIterator(Uint16Array, input);
918
- var toUint32ArrayIterator = (input) => toArrayBufferViewIterator(Uint32Array, input);
919
- var toFloat32ArrayIterator = (input) => toArrayBufferViewIterator(Float32Array, input);
920
- var toFloat64ArrayIterator = (input) => toArrayBufferViewIterator(Float64Array, input);
921
- var toUint8ClampedArrayIterator = (input) => toArrayBufferViewIterator(Uint8ClampedArray, input);
922
- function toArrayBufferViewAsyncIterator(ArrayCtor, source) {
923
- return __asyncGenerator(this, arguments, function* toArrayBufferViewAsyncIterator_1() {
924
- if (isPromise(source)) {
925
- return yield __await(yield __await(yield* __asyncDelegator(__asyncValues(toArrayBufferViewAsyncIterator(ArrayCtor, yield __await(source))))));
926
- }
927
- const wrap = function(x) {
928
- return __asyncGenerator(this, arguments, function* () {
929
- yield yield __await(yield __await(x));
930
- });
931
- };
932
- const emit = function(source2) {
933
- return __asyncGenerator(this, arguments, function* () {
934
- yield __await(yield* __asyncDelegator(__asyncValues(pump(function* (it) {
935
- let r = null;
936
- do {
937
- r = it.next(yield r === null || r === void 0 ? void 0 : r.value);
938
- } while (!r.done);
939
- }(source2[Symbol.iterator]())))));
940
- });
941
- };
942
- const buffers = typeof source === "string" ? wrap(source) : ArrayBuffer.isView(source) ? wrap(source) : source instanceof ArrayBuffer ? wrap(source) : source instanceof SharedArrayBuf ? wrap(source) : isIterable(source) ? emit(source) : !isAsyncIterable(source) ? wrap(source) : source;
943
- yield __await(
944
- // otherwise if AsyncIterable, use it
945
- yield* __asyncDelegator(__asyncValues(pump(function(it) {
946
- return __asyncGenerator(this, arguments, function* () {
947
- let r = null;
948
- do {
949
- r = yield __await(it.next(yield yield __await(toArrayBufferView(ArrayCtor, r))));
950
- } while (!r.done);
951
- });
952
- }(buffers[Symbol.asyncIterator]()))))
953
- );
954
- return yield __await(new ArrayCtor());
955
- });
956
- }
957
- var toInt8ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int8Array, input);
958
- var toInt16ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int16Array, input);
959
- var toInt32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Int32Array, input);
960
- var toUint8ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint8Array, input);
961
- var toUint16ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint16Array, input);
962
- var toUint32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint32Array, input);
963
- var toFloat32ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Float32Array, input);
964
- var toFloat64ArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Float64Array, input);
965
- var toUint8ClampedArrayAsyncIterator = (input) => toArrayBufferViewAsyncIterator(Uint8ClampedArray, input);
966
- function rebaseValueOffsets(offset, length, valueOffsets) {
967
- if (offset !== 0) {
968
- valueOffsets = valueOffsets.slice(0, length);
969
- for (let i = -1, n = valueOffsets.length; ++i < n; ) {
970
- valueOffsets[i] += offset;
971
- }
972
- }
973
- return valueOffsets.subarray(0, length);
974
- }
975
- function compareArrayLike(a, b) {
976
- let i = 0;
977
- const n = a.length;
978
- if (n !== b.length) {
979
- return false;
980
- }
981
- if (n > 0) {
982
- do {
983
- if (a[i] !== b[i]) {
984
- return false;
985
- }
986
- } while (++i < n);
987
- }
988
- return true;
989
- }
990
-
991
- // ../../node_modules/apache-arrow/io/adapters.mjs
992
- var adapters_default = {
993
- fromIterable(source) {
994
- return pump2(fromIterable(source));
995
- },
996
- fromAsyncIterable(source) {
997
- return pump2(fromAsyncIterable(source));
998
- },
999
- fromDOMStream(source) {
1000
- return pump2(fromDOMStream(source));
1001
- },
1002
- fromNodeStream(stream) {
1003
- return pump2(fromNodeStream(stream));
1004
- },
1005
- // @ts-ignore
1006
- toDOMStream(source, options) {
1007
- throw new Error(`"toDOMStream" not available in this environment`);
1008
- },
1009
- // @ts-ignore
1010
- toNodeStream(source, options) {
1011
- throw new Error(`"toNodeStream" not available in this environment`);
1012
- }
1013
- };
1014
- var pump2 = (iterator) => {
1015
- iterator.next();
1016
- return iterator;
1017
- };
1018
- function* fromIterable(source) {
1019
- let done, threw = false;
1020
- let buffers = [], buffer;
1021
- let cmd, size, bufferLength = 0;
1022
- function byteRange() {
1023
- if (cmd === "peek") {
1024
- return joinUint8Arrays(buffers, size)[0];
1025
- }
1026
- [buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
1027
- return buffer;
1028
- }
1029
- ({ cmd, size } = (yield (() => null)()) || { cmd: "read", size: 0 });
1030
- const it = toUint8ArrayIterator(source)[Symbol.iterator]();
1031
- try {
1032
- do {
1033
- ({ done, value: buffer } = Number.isNaN(size - bufferLength) ? it.next() : it.next(size - bufferLength));
1034
- if (!done && buffer.byteLength > 0) {
1035
- buffers.push(buffer);
1036
- bufferLength += buffer.byteLength;
1037
- }
1038
- if (done || size <= bufferLength) {
1039
- do {
1040
- ({ cmd, size } = yield byteRange());
1041
- } while (size < bufferLength);
1042
- }
1043
- } while (!done);
1044
- } catch (e) {
1045
- (threw = true) && typeof it.throw === "function" && it.throw(e);
1046
- } finally {
1047
- threw === false && typeof it.return === "function" && it.return(null);
1048
- }
1049
- return null;
1050
- }
1051
- function fromAsyncIterable(source) {
1052
- return __asyncGenerator(this, arguments, function* fromAsyncIterable_1() {
1053
- let done, threw = false;
1054
- let buffers = [], buffer;
1055
- let cmd, size, bufferLength = 0;
1056
- function byteRange() {
1057
- if (cmd === "peek") {
1058
- return joinUint8Arrays(buffers, size)[0];
1059
- }
1060
- [buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
1061
- return buffer;
1062
- }
1063
- ({ cmd, size } = (yield yield __await((() => null)())) || { cmd: "read", size: 0 });
1064
- const it = toUint8ArrayAsyncIterator(source)[Symbol.asyncIterator]();
1065
- try {
1066
- do {
1067
- ({ done, value: buffer } = Number.isNaN(size - bufferLength) ? yield __await(it.next()) : yield __await(it.next(size - bufferLength)));
1068
- if (!done && buffer.byteLength > 0) {
1069
- buffers.push(buffer);
1070
- bufferLength += buffer.byteLength;
1071
- }
1072
- if (done || size <= bufferLength) {
1073
- do {
1074
- ({ cmd, size } = yield yield __await(byteRange()));
1075
- } while (size < bufferLength);
1076
- }
1077
- } while (!done);
1078
- } catch (e) {
1079
- (threw = true) && typeof it.throw === "function" && (yield __await(it.throw(e)));
1080
- } finally {
1081
- threw === false && typeof it.return === "function" && (yield __await(it.return(new Uint8Array(0))));
1082
- }
1083
- return yield __await(null);
1084
- });
1085
- }
1086
- function fromDOMStream(source) {
1087
- return __asyncGenerator(this, arguments, function* fromDOMStream_1() {
1088
- let done = false, threw = false;
1089
- let buffers = [], buffer;
1090
- let cmd, size, bufferLength = 0;
1091
- function byteRange() {
1092
- if (cmd === "peek") {
1093
- return joinUint8Arrays(buffers, size)[0];
1094
- }
1095
- [buffer, buffers, bufferLength] = joinUint8Arrays(buffers, size);
1096
- return buffer;
1097
- }
1098
- ({ cmd, size } = (yield yield __await((() => null)())) || { cmd: "read", size: 0 });
1099
- const it = new AdaptiveByteReader(source);
1100
- try {
1101
- do {
1102
- ({ done, value: buffer } = Number.isNaN(size - bufferLength) ? yield __await(it["read"]()) : yield __await(it["read"](size - bufferLength)));
1103
- if (!done && buffer.byteLength > 0) {
1104
- buffers.push(toUint8Array(buffer));
1105
- bufferLength += buffer.byteLength;
1106
- }
1107
- if (done || size <= bufferLength) {
1108
- do {
1109
- ({ cmd, size } = yield yield __await(byteRange()));
1110
- } while (size < bufferLength);
1111
- }
1112
- } while (!done);
1113
- } catch (e) {
1114
- (threw = true) && (yield __await(it["cancel"](e)));
1115
- } finally {
1116
- threw === false ? yield __await(it["cancel"]()) : source["locked"] && it.releaseLock();
1117
- }
1118
- return yield __await(null);
1119
- });
1120
- }
1121
- var AdaptiveByteReader = class {
1122
- constructor(source) {
1123
- this.source = source;
1124
- this.reader = null;
1125
- this.reader = this.source["getReader"]();
1126
- this.reader["closed"].catch(() => {
1127
- });
1128
- }
1129
- get closed() {
1130
- return this.reader ? this.reader["closed"].catch(() => {
1131
- }) : Promise.resolve();
1132
- }
1133
- releaseLock() {
1134
- if (this.reader) {
1135
- this.reader.releaseLock();
1136
- }
1137
- this.reader = null;
1138
- }
1139
- cancel(reason) {
1140
- return __awaiter(this, void 0, void 0, function* () {
1141
- const { reader, source } = this;
1142
- reader && (yield reader["cancel"](reason).catch(() => {
1143
- }));
1144
- source && (source["locked"] && this.releaseLock());
1145
- });
1146
- }
1147
- read(size) {
1148
- return __awaiter(this, void 0, void 0, function* () {
1149
- if (size === 0) {
1150
- return { done: this.reader == null, value: new Uint8Array(0) };
1151
- }
1152
- const result = yield this.reader.read();
1153
- !result.done && (result.value = toUint8Array(result));
1154
- return result;
1155
- });
772
+ read(size) {
773
+ return __awaiter(this, void 0, void 0, function* () {
774
+ if (size === 0) {
775
+ return { done: this.reader == null, value: new Uint8Array(0) };
776
+ }
777
+ const result = yield this.reader.read();
778
+ !result.done && (result.value = toUint8Array(result));
779
+ return result;
780
+ });
1156
781
  }
1157
782
  };
1158
783
  var onEvent = (stream, event) => {
@@ -11395,905 +11020,1409 @@ return true;`);
11395
11020
  }
11396
11021
  }
11397
11022
  }
11398
- _readFooter() {
11399
- const { _handle } = this;
11400
- const offset = _handle.size - magicAndPadding;
11401
- const length = _handle.readInt32(offset);
11402
- const buffer = _handle.readAt(offset - length, length);
11403
- return Footer_.decode(buffer);
11023
+ _readFooter() {
11024
+ const { _handle } = this;
11025
+ const offset = _handle.size - magicAndPadding;
11026
+ const length = _handle.readInt32(offset);
11027
+ const buffer = _handle.readAt(offset - length, length);
11028
+ return Footer_.decode(buffer);
11029
+ }
11030
+ _readNextMessageAndValidate(type) {
11031
+ var _a5;
11032
+ if (!this._footer) {
11033
+ this.open();
11034
+ }
11035
+ if (this._footer && this._recordBatchIndex < this.numRecordBatches) {
11036
+ const block = (_a5 = this._footer) === null || _a5 === void 0 ? void 0 : _a5.getRecordBatch(this._recordBatchIndex);
11037
+ if (block && this._handle.seek(block.offset)) {
11038
+ return this._reader.readMessage(type);
11039
+ }
11040
+ }
11041
+ return null;
11042
+ }
11043
+ };
11044
+ var AsyncRecordBatchFileReaderImpl = class extends AsyncRecordBatchStreamReaderImpl {
11045
+ get footer() {
11046
+ return this._footer;
11047
+ }
11048
+ get numDictionaries() {
11049
+ return this._footer ? this._footer.numDictionaries : 0;
11050
+ }
11051
+ get numRecordBatches() {
11052
+ return this._footer ? this._footer.numRecordBatches : 0;
11053
+ }
11054
+ constructor(source, ...rest) {
11055
+ const byteLength = typeof rest[0] !== "number" ? rest.shift() : void 0;
11056
+ const dictionaries = rest[0] instanceof Map ? rest.shift() : void 0;
11057
+ super(source instanceof AsyncRandomAccessFile ? source : new AsyncRandomAccessFile(source, byteLength), dictionaries);
11058
+ }
11059
+ isFile() {
11060
+ return true;
11061
+ }
11062
+ isAsync() {
11063
+ return true;
11064
+ }
11065
+ open(options) {
11066
+ const _super = Object.create(null, {
11067
+ open: { get: () => super.open }
11068
+ });
11069
+ return __awaiter(this, void 0, void 0, function* () {
11070
+ if (!this.closed && !this._footer) {
11071
+ this.schema = (this._footer = yield this._readFooter()).schema;
11072
+ for (const block of this._footer.dictionaryBatches()) {
11073
+ block && (yield this._readDictionaryBatch(this._dictionaryIndex++));
11074
+ }
11075
+ }
11076
+ return yield _super.open.call(this, options);
11077
+ });
11078
+ }
11079
+ readRecordBatch(index) {
11080
+ var _a5;
11081
+ return __awaiter(this, void 0, void 0, function* () {
11082
+ if (this.closed) {
11083
+ return null;
11084
+ }
11085
+ if (!this._footer) {
11086
+ yield this.open();
11087
+ }
11088
+ const block = (_a5 = this._footer) === null || _a5 === void 0 ? void 0 : _a5.getRecordBatch(index);
11089
+ if (block && (yield this._handle.seek(block.offset))) {
11090
+ const message = yield this._reader.readMessage(MessageHeader.RecordBatch);
11091
+ if (message === null || message === void 0 ? void 0 : message.isRecordBatch()) {
11092
+ const header = message.header();
11093
+ const buffer = yield this._reader.readMessageBody(message.bodyLength);
11094
+ const recordBatch = this._loadRecordBatch(header, buffer);
11095
+ return recordBatch;
11096
+ }
11097
+ }
11098
+ return null;
11099
+ });
11100
+ }
11101
+ _readDictionaryBatch(index) {
11102
+ var _a5;
11103
+ return __awaiter(this, void 0, void 0, function* () {
11104
+ const block = (_a5 = this._footer) === null || _a5 === void 0 ? void 0 : _a5.getDictionaryBatch(index);
11105
+ if (block && (yield this._handle.seek(block.offset))) {
11106
+ const message = yield this._reader.readMessage(MessageHeader.DictionaryBatch);
11107
+ if (message === null || message === void 0 ? void 0 : message.isDictionaryBatch()) {
11108
+ const header = message.header();
11109
+ const buffer = yield this._reader.readMessageBody(message.bodyLength);
11110
+ const vector = this._loadDictionaryBatch(header, buffer);
11111
+ this.dictionaries.set(header.id, vector);
11112
+ }
11113
+ }
11114
+ });
11115
+ }
11116
+ _readFooter() {
11117
+ return __awaiter(this, void 0, void 0, function* () {
11118
+ const { _handle } = this;
11119
+ _handle._pending && (yield _handle._pending);
11120
+ const offset = _handle.size - magicAndPadding;
11121
+ const length = yield _handle.readInt32(offset);
11122
+ const buffer = yield _handle.readAt(offset - length, length);
11123
+ return Footer_.decode(buffer);
11124
+ });
11125
+ }
11126
+ _readNextMessageAndValidate(type) {
11127
+ return __awaiter(this, void 0, void 0, function* () {
11128
+ if (!this._footer) {
11129
+ yield this.open();
11130
+ }
11131
+ if (this._footer && this._recordBatchIndex < this.numRecordBatches) {
11132
+ const block = this._footer.getRecordBatch(this._recordBatchIndex);
11133
+ if (block && (yield this._handle.seek(block.offset))) {
11134
+ return yield this._reader.readMessage(type);
11135
+ }
11136
+ }
11137
+ return null;
11138
+ });
11139
+ }
11140
+ };
11141
+ var RecordBatchJSONReaderImpl = class extends RecordBatchStreamReaderImpl {
11142
+ constructor(source, dictionaries) {
11143
+ super(source, dictionaries);
11144
+ }
11145
+ _loadVectors(header, body, types) {
11146
+ return new JSONVectorLoader(body, header.nodes, header.buffers, this.dictionaries, this.schema.metadataVersion).visitMany(types);
11147
+ }
11148
+ };
11149
+ function shouldAutoDestroy(self2, options) {
11150
+ return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self2["autoDestroy"];
11151
+ }
11152
+ function* readAllSync(source) {
11153
+ const reader = RecordBatchReader.from(source);
11154
+ try {
11155
+ if (!reader.open({ autoDestroy: false }).closed) {
11156
+ do {
11157
+ yield reader;
11158
+ } while (!reader.reset().open().closed);
11159
+ }
11160
+ } finally {
11161
+ reader.cancel();
11162
+ }
11163
+ }
11164
+ function readAllAsync(source) {
11165
+ return __asyncGenerator(this, arguments, function* readAllAsync_1() {
11166
+ const reader = yield __await(RecordBatchReader.from(source));
11167
+ try {
11168
+ if (!(yield __await(reader.open({ autoDestroy: false }))).closed) {
11169
+ do {
11170
+ yield yield __await(reader);
11171
+ } while (!(yield __await(reader.reset().open())).closed);
11172
+ }
11173
+ } finally {
11174
+ yield __await(reader.cancel());
11175
+ }
11176
+ });
11177
+ }
11178
+ function fromArrowJSON(source) {
11179
+ return new RecordBatchStreamReader(new RecordBatchJSONReaderImpl(source));
11180
+ }
11181
+ function fromByteStream(source) {
11182
+ const bytes = source.peek(magicLength + 7 & ~7);
11183
+ return bytes && bytes.byteLength >= 4 ? !checkForMagicArrowString(bytes) ? new RecordBatchStreamReader(new RecordBatchStreamReaderImpl(source)) : new RecordBatchFileReader(new RecordBatchFileReaderImpl(source.read())) : new RecordBatchStreamReader(new RecordBatchStreamReaderImpl(function* () {
11184
+ }()));
11185
+ }
11186
+ function fromAsyncByteStream(source) {
11187
+ return __awaiter(this, void 0, void 0, function* () {
11188
+ const bytes = yield source.peek(magicLength + 7 & ~7);
11189
+ return bytes && bytes.byteLength >= 4 ? !checkForMagicArrowString(bytes) ? new AsyncRecordBatchStreamReader(new AsyncRecordBatchStreamReaderImpl(source)) : new RecordBatchFileReader(new RecordBatchFileReaderImpl(yield source.read())) : new AsyncRecordBatchStreamReader(new AsyncRecordBatchStreamReaderImpl(function() {
11190
+ return __asyncGenerator(this, arguments, function* () {
11191
+ });
11192
+ }()));
11193
+ });
11194
+ }
11195
+ function fromFileHandle(source) {
11196
+ return __awaiter(this, void 0, void 0, function* () {
11197
+ const { size } = yield source.stat();
11198
+ const file = new AsyncRandomAccessFile(source, size);
11199
+ if (size >= magicX2AndPadding && checkForMagicArrowString(yield file.readAt(0, magicLength + 7 & ~7))) {
11200
+ return new AsyncRecordBatchFileReader(new AsyncRecordBatchFileReaderImpl(file));
11201
+ }
11202
+ return new AsyncRecordBatchStreamReader(new AsyncRecordBatchStreamReaderImpl(file));
11203
+ });
11204
+ }
11205
+
11206
+ // ../../node_modules/apache-arrow/visitor/vectorassembler.mjs
11207
+ var VectorAssembler = class extends Visitor {
11208
+ /** @nocollapse */
11209
+ static assemble(...args) {
11210
+ const unwrap = (nodes) => nodes.flatMap((node) => Array.isArray(node) ? unwrap(node) : node instanceof RecordBatch2 ? node.data.children : node.data);
11211
+ const assembler = new VectorAssembler();
11212
+ assembler.visitMany(unwrap(args));
11213
+ return assembler;
11214
+ }
11215
+ constructor() {
11216
+ super();
11217
+ this._byteLength = 0;
11218
+ this._nodes = [];
11219
+ this._buffers = [];
11220
+ this._bufferRegions = [];
11404
11221
  }
11405
- _readNextMessageAndValidate(type) {
11406
- var _a5;
11407
- if (!this._footer) {
11408
- this.open();
11222
+ visit(data) {
11223
+ if (data instanceof Vector) {
11224
+ this.visitMany(data.data);
11225
+ return this;
11409
11226
  }
11410
- if (this._footer && this._recordBatchIndex < this.numRecordBatches) {
11411
- const block = (_a5 = this._footer) === null || _a5 === void 0 ? void 0 : _a5.getRecordBatch(this._recordBatchIndex);
11412
- if (block && this._handle.seek(block.offset)) {
11413
- return this._reader.readMessage(type);
11227
+ const { type } = data;
11228
+ if (!DataType.isDictionary(type)) {
11229
+ const { length } = data;
11230
+ if (length > 2147483647) {
11231
+ throw new RangeError("Cannot write arrays larger than 2^31 - 1 in length");
11232
+ }
11233
+ if (DataType.isUnion(type)) {
11234
+ this.nodes.push(new FieldNode2(length, 0));
11235
+ } else {
11236
+ const { nullCount } = data;
11237
+ if (!DataType.isNull(type)) {
11238
+ addBuffer.call(this, nullCount <= 0 ? new Uint8Array(0) : truncateBitmap(data.offset, length, data.nullBitmap));
11239
+ }
11240
+ this.nodes.push(new FieldNode2(length, nullCount));
11414
11241
  }
11415
11242
  }
11416
- return null;
11243
+ return super.visit(data);
11417
11244
  }
11418
- };
11419
- var AsyncRecordBatchFileReaderImpl = class extends AsyncRecordBatchStreamReaderImpl {
11420
- get footer() {
11421
- return this._footer;
11245
+ visitNull(_null) {
11246
+ return this;
11422
11247
  }
11423
- get numDictionaries() {
11424
- return this._footer ? this._footer.numDictionaries : 0;
11248
+ visitDictionary(data) {
11249
+ return this.visit(data.clone(data.type.indices));
11425
11250
  }
11426
- get numRecordBatches() {
11427
- return this._footer ? this._footer.numRecordBatches : 0;
11251
+ get nodes() {
11252
+ return this._nodes;
11428
11253
  }
11429
- constructor(source, ...rest) {
11430
- const byteLength = typeof rest[0] !== "number" ? rest.shift() : void 0;
11431
- const dictionaries = rest[0] instanceof Map ? rest.shift() : void 0;
11432
- super(source instanceof AsyncRandomAccessFile ? source : new AsyncRandomAccessFile(source, byteLength), dictionaries);
11254
+ get buffers() {
11255
+ return this._buffers;
11433
11256
  }
11434
- isFile() {
11435
- return true;
11257
+ get byteLength() {
11258
+ return this._byteLength;
11436
11259
  }
11437
- isAsync() {
11438
- return true;
11260
+ get bufferRegions() {
11261
+ return this._bufferRegions;
11439
11262
  }
11440
- open(options) {
11441
- const _super = Object.create(null, {
11442
- open: { get: () => super.open }
11443
- });
11444
- return __awaiter(this, void 0, void 0, function* () {
11445
- if (!this.closed && !this._footer) {
11446
- this.schema = (this._footer = yield this._readFooter()).schema;
11447
- for (const block of this._footer.dictionaryBatches()) {
11448
- block && (yield this._readDictionaryBatch(this._dictionaryIndex++));
11263
+ };
11264
+ function addBuffer(values) {
11265
+ const byteLength = values.byteLength + 7 & ~7;
11266
+ this.buffers.push(values);
11267
+ this.bufferRegions.push(new BufferRegion(this._byteLength, byteLength));
11268
+ this._byteLength += byteLength;
11269
+ return this;
11270
+ }
11271
+ function assembleUnion(data) {
11272
+ var _a5;
11273
+ const { type, length, typeIds, valueOffsets } = data;
11274
+ addBuffer.call(this, typeIds);
11275
+ if (type.mode === UnionMode.Sparse) {
11276
+ return assembleNestedVector.call(this, data);
11277
+ } else if (type.mode === UnionMode.Dense) {
11278
+ if (data.offset <= 0) {
11279
+ addBuffer.call(this, valueOffsets);
11280
+ return assembleNestedVector.call(this, data);
11281
+ } else {
11282
+ const shiftedOffsets = new Int32Array(length);
11283
+ const childOffsets = /* @__PURE__ */ Object.create(null);
11284
+ const childLengths = /* @__PURE__ */ Object.create(null);
11285
+ for (let typeId, shift, index = -1; ++index < length; ) {
11286
+ if ((typeId = typeIds[index]) === void 0) {
11287
+ continue;
11449
11288
  }
11450
- }
11451
- return yield _super.open.call(this, options);
11452
- });
11453
- }
11454
- readRecordBatch(index) {
11455
- var _a5;
11456
- return __awaiter(this, void 0, void 0, function* () {
11457
- if (this.closed) {
11458
- return null;
11459
- }
11460
- if (!this._footer) {
11461
- yield this.open();
11462
- }
11463
- const block = (_a5 = this._footer) === null || _a5 === void 0 ? void 0 : _a5.getRecordBatch(index);
11464
- if (block && (yield this._handle.seek(block.offset))) {
11465
- const message = yield this._reader.readMessage(MessageHeader.RecordBatch);
11466
- if (message === null || message === void 0 ? void 0 : message.isRecordBatch()) {
11467
- const header = message.header();
11468
- const buffer = yield this._reader.readMessageBody(message.bodyLength);
11469
- const recordBatch = this._loadRecordBatch(header, buffer);
11470
- return recordBatch;
11289
+ if ((shift = childOffsets[typeId]) === void 0) {
11290
+ shift = childOffsets[typeId] = valueOffsets[index];
11471
11291
  }
11292
+ shiftedOffsets[index] = valueOffsets[index] - shift;
11293
+ childLengths[typeId] = ((_a5 = childLengths[typeId]) !== null && _a5 !== void 0 ? _a5 : 0) + 1;
11472
11294
  }
11473
- return null;
11474
- });
11295
+ addBuffer.call(this, shiftedOffsets);
11296
+ this.visitMany(data.children.map((child, childIndex) => {
11297
+ const typeId = type.typeIds[childIndex];
11298
+ const childOffset = childOffsets[typeId];
11299
+ const childLength = childLengths[typeId];
11300
+ return child.slice(childOffset, Math.min(length, childLength));
11301
+ }));
11302
+ }
11303
+ }
11304
+ return this;
11305
+ }
11306
+ function assembleBoolVector(data) {
11307
+ let values;
11308
+ if (data.nullCount >= data.length) {
11309
+ return addBuffer.call(this, new Uint8Array(0));
11310
+ } else if ((values = data.values) instanceof Uint8Array) {
11311
+ return addBuffer.call(this, truncateBitmap(data.offset, data.length, values));
11312
+ }
11313
+ return addBuffer.call(this, packBools(data.values));
11314
+ }
11315
+ function assembleFlatVector(data) {
11316
+ return addBuffer.call(this, data.values.subarray(0, data.length * data.stride));
11317
+ }
11318
+ function assembleFlatListVector(data) {
11319
+ const { length, values, valueOffsets } = data;
11320
+ const begin = bigIntToNumber(valueOffsets[0]);
11321
+ const end = bigIntToNumber(valueOffsets[length]);
11322
+ const byteLength = Math.min(end - begin, values.byteLength - begin);
11323
+ addBuffer.call(this, rebaseValueOffsets(-begin, length + 1, valueOffsets));
11324
+ addBuffer.call(this, values.subarray(begin, begin + byteLength));
11325
+ return this;
11326
+ }
11327
+ function assembleListVector(data) {
11328
+ const { length, valueOffsets } = data;
11329
+ if (valueOffsets) {
11330
+ const { [0]: begin, [length]: end } = valueOffsets;
11331
+ addBuffer.call(this, rebaseValueOffsets(-begin, length + 1, valueOffsets));
11332
+ return this.visit(data.children[0].slice(begin, end - begin));
11333
+ }
11334
+ return this.visit(data.children[0]);
11335
+ }
11336
+ function assembleNestedVector(data) {
11337
+ return this.visitMany(data.type.children.map((_, i) => data.children[i]).filter(Boolean))[0];
11338
+ }
11339
+ VectorAssembler.prototype.visitBool = assembleBoolVector;
11340
+ VectorAssembler.prototype.visitInt = assembleFlatVector;
11341
+ VectorAssembler.prototype.visitFloat = assembleFlatVector;
11342
+ VectorAssembler.prototype.visitUtf8 = assembleFlatListVector;
11343
+ VectorAssembler.prototype.visitLargeUtf8 = assembleFlatListVector;
11344
+ VectorAssembler.prototype.visitBinary = assembleFlatListVector;
11345
+ VectorAssembler.prototype.visitLargeBinary = assembleFlatListVector;
11346
+ VectorAssembler.prototype.visitFixedSizeBinary = assembleFlatVector;
11347
+ VectorAssembler.prototype.visitDate = assembleFlatVector;
11348
+ VectorAssembler.prototype.visitTimestamp = assembleFlatVector;
11349
+ VectorAssembler.prototype.visitTime = assembleFlatVector;
11350
+ VectorAssembler.prototype.visitDecimal = assembleFlatVector;
11351
+ VectorAssembler.prototype.visitList = assembleListVector;
11352
+ VectorAssembler.prototype.visitStruct = assembleNestedVector;
11353
+ VectorAssembler.prototype.visitUnion = assembleUnion;
11354
+ VectorAssembler.prototype.visitInterval = assembleFlatVector;
11355
+ VectorAssembler.prototype.visitDuration = assembleFlatVector;
11356
+ VectorAssembler.prototype.visitFixedSizeList = assembleListVector;
11357
+ VectorAssembler.prototype.visitMap = assembleListVector;
11358
+
11359
+ // ../../node_modules/apache-arrow/ipc/writer.mjs
11360
+ var RecordBatchWriter = class extends ReadableInterop {
11361
+ /** @nocollapse */
11362
+ // @ts-ignore
11363
+ static throughNode(options) {
11364
+ throw new Error(`"throughNode" not available in this environment`);
11365
+ }
11366
+ /** @nocollapse */
11367
+ static throughDOM(writableStrategy, readableStrategy) {
11368
+ throw new Error(`"throughDOM" not available in this environment`);
11369
+ }
11370
+ constructor(options) {
11371
+ super();
11372
+ this._position = 0;
11373
+ this._started = false;
11374
+ this._sink = new AsyncByteQueue();
11375
+ this._schema = null;
11376
+ this._dictionaryBlocks = [];
11377
+ this._recordBatchBlocks = [];
11378
+ this._dictionaryDeltaOffsets = /* @__PURE__ */ new Map();
11379
+ isObject(options) || (options = { autoDestroy: true, writeLegacyIpcFormat: false });
11380
+ this._autoDestroy = typeof options.autoDestroy === "boolean" ? options.autoDestroy : true;
11381
+ this._writeLegacyIpcFormat = typeof options.writeLegacyIpcFormat === "boolean" ? options.writeLegacyIpcFormat : false;
11382
+ }
11383
+ toString(sync = false) {
11384
+ return this._sink.toString(sync);
11385
+ }
11386
+ toUint8Array(sync = false) {
11387
+ return this._sink.toUint8Array(sync);
11475
11388
  }
11476
- _readDictionaryBatch(index) {
11477
- var _a5;
11478
- return __awaiter(this, void 0, void 0, function* () {
11479
- const block = (_a5 = this._footer) === null || _a5 === void 0 ? void 0 : _a5.getDictionaryBatch(index);
11480
- if (block && (yield this._handle.seek(block.offset))) {
11481
- const message = yield this._reader.readMessage(MessageHeader.DictionaryBatch);
11482
- if (message === null || message === void 0 ? void 0 : message.isDictionaryBatch()) {
11483
- const header = message.header();
11484
- const buffer = yield this._reader.readMessageBody(message.bodyLength);
11485
- const vector = this._loadDictionaryBatch(header, buffer);
11486
- this.dictionaries.set(header.id, vector);
11487
- }
11488
- }
11489
- });
11389
+ writeAll(input) {
11390
+ if (isPromise(input)) {
11391
+ return input.then((x) => this.writeAll(x));
11392
+ } else if (isAsyncIterable(input)) {
11393
+ return writeAllAsync(this, input);
11394
+ }
11395
+ return writeAll(this, input);
11490
11396
  }
11491
- _readFooter() {
11492
- return __awaiter(this, void 0, void 0, function* () {
11493
- const { _handle } = this;
11494
- _handle._pending && (yield _handle._pending);
11495
- const offset = _handle.size - magicAndPadding;
11496
- const length = yield _handle.readInt32(offset);
11497
- const buffer = yield _handle.readAt(offset - length, length);
11498
- return Footer_.decode(buffer);
11499
- });
11397
+ get closed() {
11398
+ return this._sink.closed;
11500
11399
  }
11501
- _readNextMessageAndValidate(type) {
11502
- return __awaiter(this, void 0, void 0, function* () {
11503
- if (!this._footer) {
11504
- yield this.open();
11505
- }
11506
- if (this._footer && this._recordBatchIndex < this.numRecordBatches) {
11507
- const block = this._footer.getRecordBatch(this._recordBatchIndex);
11508
- if (block && (yield this._handle.seek(block.offset))) {
11509
- return yield this._reader.readMessage(type);
11510
- }
11511
- }
11512
- return null;
11513
- });
11400
+ [Symbol.asyncIterator]() {
11401
+ return this._sink[Symbol.asyncIterator]();
11514
11402
  }
11515
- };
11516
- var RecordBatchJSONReaderImpl = class extends RecordBatchStreamReaderImpl {
11517
- constructor(source, dictionaries) {
11518
- super(source, dictionaries);
11403
+ toDOMStream(options) {
11404
+ return this._sink.toDOMStream(options);
11519
11405
  }
11520
- _loadVectors(header, body, types) {
11521
- return new JSONVectorLoader(body, header.nodes, header.buffers, this.dictionaries, this.schema.metadataVersion).visitMany(types);
11406
+ toNodeStream(options) {
11407
+ return this._sink.toNodeStream(options);
11522
11408
  }
11523
- };
11524
- function shouldAutoDestroy(self2, options) {
11525
- return options && typeof options["autoDestroy"] === "boolean" ? options["autoDestroy"] : self2["autoDestroy"];
11526
- }
11527
- function* readAllSync(source) {
11528
- const reader = RecordBatchReader.from(source);
11529
- try {
11530
- if (!reader.open({ autoDestroy: false }).closed) {
11531
- do {
11532
- yield reader;
11533
- } while (!reader.reset().open().closed);
11534
- }
11535
- } finally {
11536
- reader.cancel();
11409
+ close() {
11410
+ return this.reset()._sink.close();
11537
11411
  }
11538
- }
11539
- function readAllAsync(source) {
11540
- return __asyncGenerator(this, arguments, function* readAllAsync_1() {
11541
- const reader = yield __await(RecordBatchReader.from(source));
11542
- try {
11543
- if (!(yield __await(reader.open({ autoDestroy: false }))).closed) {
11544
- do {
11545
- yield yield __await(reader);
11546
- } while (!(yield __await(reader.reset().open())).closed);
11412
+ abort(reason) {
11413
+ return this.reset()._sink.abort(reason);
11414
+ }
11415
+ finish() {
11416
+ this._autoDestroy ? this.close() : this.reset(this._sink, this._schema);
11417
+ return this;
11418
+ }
11419
+ reset(sink = this._sink, schema = null) {
11420
+ if (sink === this._sink || sink instanceof AsyncByteQueue) {
11421
+ this._sink = sink;
11422
+ } else {
11423
+ this._sink = new AsyncByteQueue();
11424
+ if (sink && isWritableDOMStream(sink)) {
11425
+ this.toDOMStream({ type: "bytes" }).pipeTo(sink);
11426
+ } else if (sink && isWritableNodeStream(sink)) {
11427
+ this.toNodeStream({ objectMode: false }).pipe(sink);
11547
11428
  }
11548
- } finally {
11549
- yield __await(reader.cancel());
11550
11429
  }
11551
- });
11552
- }
11553
- function fromArrowJSON(source) {
11554
- return new RecordBatchStreamReader(new RecordBatchJSONReaderImpl(source));
11555
- }
11556
- function fromByteStream(source) {
11557
- const bytes = source.peek(magicLength + 7 & ~7);
11558
- return bytes && bytes.byteLength >= 4 ? !checkForMagicArrowString(bytes) ? new RecordBatchStreamReader(new RecordBatchStreamReaderImpl(source)) : new RecordBatchFileReader(new RecordBatchFileReaderImpl(source.read())) : new RecordBatchStreamReader(new RecordBatchStreamReaderImpl(function* () {
11559
- }()));
11560
- }
11561
- function fromAsyncByteStream(source) {
11562
- return __awaiter(this, void 0, void 0, function* () {
11563
- const bytes = yield source.peek(magicLength + 7 & ~7);
11564
- return bytes && bytes.byteLength >= 4 ? !checkForMagicArrowString(bytes) ? new AsyncRecordBatchStreamReader(new AsyncRecordBatchStreamReaderImpl(source)) : new RecordBatchFileReader(new RecordBatchFileReaderImpl(yield source.read())) : new AsyncRecordBatchStreamReader(new AsyncRecordBatchStreamReaderImpl(function() {
11565
- return __asyncGenerator(this, arguments, function* () {
11566
- });
11567
- }()));
11568
- });
11569
- }
11570
- function fromFileHandle(source) {
11571
- return __awaiter(this, void 0, void 0, function* () {
11572
- const { size } = yield source.stat();
11573
- const file = new AsyncRandomAccessFile(source, size);
11574
- if (size >= magicX2AndPadding && checkForMagicArrowString(yield file.readAt(0, magicLength + 7 & ~7))) {
11575
- return new AsyncRecordBatchFileReader(new AsyncRecordBatchFileReaderImpl(file));
11430
+ if (this._started && this._schema) {
11431
+ this._writeFooter(this._schema);
11576
11432
  }
11577
- return new AsyncRecordBatchStreamReader(new AsyncRecordBatchStreamReaderImpl(file));
11578
- });
11579
- }
11580
-
11581
- // ../../node_modules/apache-arrow/visitor/vectorassembler.mjs
11582
- var VectorAssembler = class extends Visitor {
11583
- /** @nocollapse */
11584
- static assemble(...args) {
11585
- const unwrap = (nodes) => nodes.flatMap((node) => Array.isArray(node) ? unwrap(node) : node instanceof RecordBatch2 ? node.data.children : node.data);
11586
- const assembler = new VectorAssembler();
11587
- assembler.visitMany(unwrap(args));
11588
- return assembler;
11433
+ this._started = false;
11434
+ this._dictionaryBlocks = [];
11435
+ this._recordBatchBlocks = [];
11436
+ this._dictionaryDeltaOffsets = /* @__PURE__ */ new Map();
11437
+ if (!schema || !compareSchemas(schema, this._schema)) {
11438
+ if (schema == null) {
11439
+ this._position = 0;
11440
+ this._schema = null;
11441
+ } else {
11442
+ this._started = true;
11443
+ this._schema = schema;
11444
+ this._writeSchema(schema);
11445
+ }
11446
+ }
11447
+ return this;
11589
11448
  }
11590
- constructor() {
11591
- super();
11592
- this._byteLength = 0;
11593
- this._nodes = [];
11594
- this._buffers = [];
11595
- this._bufferRegions = [];
11449
+ write(payload) {
11450
+ let schema = null;
11451
+ if (!this._sink) {
11452
+ throw new Error(`RecordBatchWriter is closed`);
11453
+ } else if (payload == null) {
11454
+ return this.finish() && void 0;
11455
+ } else if (payload instanceof Table && !(schema = payload.schema)) {
11456
+ return this.finish() && void 0;
11457
+ } else if (payload instanceof RecordBatch2 && !(schema = payload.schema)) {
11458
+ return this.finish() && void 0;
11459
+ }
11460
+ if (schema && !compareSchemas(schema, this._schema)) {
11461
+ if (this._started && this._autoDestroy) {
11462
+ return this.close();
11463
+ }
11464
+ this.reset(this._sink, schema);
11465
+ }
11466
+ if (payload instanceof RecordBatch2) {
11467
+ if (!(payload instanceof _InternalEmptyPlaceholderRecordBatch)) {
11468
+ this._writeRecordBatch(payload);
11469
+ }
11470
+ } else if (payload instanceof Table) {
11471
+ this.writeAll(payload.batches);
11472
+ } else if (isIterable(payload)) {
11473
+ this.writeAll(payload);
11474
+ }
11596
11475
  }
11597
- visit(data) {
11598
- if (data instanceof Vector) {
11599
- this.visitMany(data.data);
11600
- return this;
11476
+ _writeMessage(message, alignment = 8) {
11477
+ const a = alignment - 1;
11478
+ const buffer = Message2.encode(message);
11479
+ const flatbufferSize = buffer.byteLength;
11480
+ const prefixSize = !this._writeLegacyIpcFormat ? 8 : 4;
11481
+ const alignedSize = flatbufferSize + prefixSize + a & ~a;
11482
+ const nPaddingBytes = alignedSize - flatbufferSize - prefixSize;
11483
+ if (message.headerType === MessageHeader.RecordBatch) {
11484
+ this._recordBatchBlocks.push(new FileBlock(alignedSize, message.bodyLength, this._position));
11485
+ } else if (message.headerType === MessageHeader.DictionaryBatch) {
11486
+ this._dictionaryBlocks.push(new FileBlock(alignedSize, message.bodyLength, this._position));
11601
11487
  }
11602
- const { type } = data;
11603
- if (!DataType.isDictionary(type)) {
11604
- const { length } = data;
11605
- if (length > 2147483647) {
11606
- throw new RangeError("Cannot write arrays larger than 2^31 - 1 in length");
11488
+ if (!this._writeLegacyIpcFormat) {
11489
+ this._write(Int32Array.of(-1));
11490
+ }
11491
+ this._write(Int32Array.of(alignedSize - prefixSize));
11492
+ if (flatbufferSize > 0) {
11493
+ this._write(buffer);
11494
+ }
11495
+ return this._writePadding(nPaddingBytes);
11496
+ }
11497
+ _write(chunk) {
11498
+ if (this._started) {
11499
+ const buffer = toUint8Array(chunk);
11500
+ if (buffer && buffer.byteLength > 0) {
11501
+ this._sink.write(buffer);
11502
+ this._position += buffer.byteLength;
11607
11503
  }
11608
- if (DataType.isUnion(type)) {
11609
- this.nodes.push(new FieldNode2(length, 0));
11610
- } else {
11611
- const { nullCount } = data;
11612
- if (!DataType.isNull(type)) {
11613
- addBuffer.call(this, nullCount <= 0 ? new Uint8Array(0) : truncateBitmap(data.offset, length, data.nullBitmap));
11504
+ }
11505
+ return this;
11506
+ }
11507
+ _writeSchema(schema) {
11508
+ return this._writeMessage(Message2.from(schema));
11509
+ }
11510
+ // @ts-ignore
11511
+ _writeFooter(schema) {
11512
+ return this._writeLegacyIpcFormat ? this._write(Int32Array.of(0)) : this._write(Int32Array.of(-1, 0));
11513
+ }
11514
+ _writeMagic() {
11515
+ return this._write(MAGIC);
11516
+ }
11517
+ _writePadding(nBytes) {
11518
+ return nBytes > 0 ? this._write(new Uint8Array(nBytes)) : this;
11519
+ }
11520
+ _writeRecordBatch(batch) {
11521
+ const { byteLength, nodes, bufferRegions, buffers } = VectorAssembler.assemble(batch);
11522
+ const recordBatch = new RecordBatch3(batch.numRows, nodes, bufferRegions);
11523
+ const message = Message2.from(recordBatch, byteLength);
11524
+ return this._writeDictionaries(batch)._writeMessage(message)._writeBodyBuffers(buffers);
11525
+ }
11526
+ _writeDictionaryBatch(dictionary, id, isDelta = false) {
11527
+ this._dictionaryDeltaOffsets.set(id, dictionary.length + (this._dictionaryDeltaOffsets.get(id) || 0));
11528
+ const { byteLength, nodes, bufferRegions, buffers } = VectorAssembler.assemble(new Vector([dictionary]));
11529
+ const recordBatch = new RecordBatch3(dictionary.length, nodes, bufferRegions);
11530
+ const dictionaryBatch = new DictionaryBatch2(recordBatch, id, isDelta);
11531
+ const message = Message2.from(dictionaryBatch, byteLength);
11532
+ return this._writeMessage(message)._writeBodyBuffers(buffers);
11533
+ }
11534
+ _writeBodyBuffers(buffers) {
11535
+ let buffer;
11536
+ let size, padding;
11537
+ for (let i = -1, n = buffers.length; ++i < n; ) {
11538
+ if ((buffer = buffers[i]) && (size = buffer.byteLength) > 0) {
11539
+ this._write(buffer);
11540
+ if ((padding = (size + 7 & ~7) - size) > 0) {
11541
+ this._writePadding(padding);
11614
11542
  }
11615
- this.nodes.push(new FieldNode2(length, nullCount));
11616
11543
  }
11617
11544
  }
11618
- return super.visit(data);
11545
+ return this;
11619
11546
  }
11620
- visitNull(_null) {
11547
+ _writeDictionaries(batch) {
11548
+ for (let [id, dictionary] of batch.dictionaries) {
11549
+ let offset = this._dictionaryDeltaOffsets.get(id) || 0;
11550
+ if (offset === 0 || (dictionary = dictionary === null || dictionary === void 0 ? void 0 : dictionary.slice(offset)).length > 0) {
11551
+ for (const data of dictionary.data) {
11552
+ this._writeDictionaryBatch(data, id, offset > 0);
11553
+ offset += data.length;
11554
+ }
11555
+ }
11556
+ }
11621
11557
  return this;
11622
11558
  }
11623
- visitDictionary(data) {
11624
- return this.visit(data.clone(data.type.indices));
11559
+ };
11560
+ var RecordBatchStreamWriter = class extends RecordBatchWriter {
11561
+ /** @nocollapse */
11562
+ static writeAll(input, options) {
11563
+ const writer = new RecordBatchStreamWriter(options);
11564
+ if (isPromise(input)) {
11565
+ return input.then((x) => writer.writeAll(x));
11566
+ } else if (isAsyncIterable(input)) {
11567
+ return writeAllAsync(writer, input);
11568
+ }
11569
+ return writeAll(writer, input);
11625
11570
  }
11626
- get nodes() {
11627
- return this._nodes;
11571
+ };
11572
+ var RecordBatchFileWriter = class extends RecordBatchWriter {
11573
+ /** @nocollapse */
11574
+ static writeAll(input) {
11575
+ const writer = new RecordBatchFileWriter();
11576
+ if (isPromise(input)) {
11577
+ return input.then((x) => writer.writeAll(x));
11578
+ } else if (isAsyncIterable(input)) {
11579
+ return writeAllAsync(writer, input);
11580
+ }
11581
+ return writeAll(writer, input);
11628
11582
  }
11629
- get buffers() {
11630
- return this._buffers;
11583
+ constructor() {
11584
+ super();
11585
+ this._autoDestroy = true;
11631
11586
  }
11632
- get byteLength() {
11633
- return this._byteLength;
11587
+ // @ts-ignore
11588
+ _writeSchema(schema) {
11589
+ return this._writeMagic()._writePadding(2);
11634
11590
  }
11635
- get bufferRegions() {
11636
- return this._bufferRegions;
11591
+ _writeFooter(schema) {
11592
+ const buffer = Footer_.encode(new Footer_(schema, MetadataVersion.V5, this._recordBatchBlocks, this._dictionaryBlocks));
11593
+ return super._writeFooter(schema)._write(buffer)._write(Int32Array.of(buffer.byteLength))._writeMagic();
11637
11594
  }
11638
11595
  };
11639
- function addBuffer(values) {
11640
- const byteLength = values.byteLength + 7 & ~7;
11641
- this.buffers.push(values);
11642
- this.bufferRegions.push(new BufferRegion(this._byteLength, byteLength));
11643
- this._byteLength += byteLength;
11644
- return this;
11596
+ function writeAll(writer, input) {
11597
+ let chunks = input;
11598
+ if (input instanceof Table) {
11599
+ chunks = input.batches;
11600
+ writer.reset(void 0, input.schema);
11601
+ }
11602
+ for (const batch of chunks) {
11603
+ writer.write(batch);
11604
+ }
11605
+ return writer.finish();
11645
11606
  }
11646
- function assembleUnion(data) {
11647
- var _a5;
11648
- const { type, length, typeIds, valueOffsets } = data;
11649
- addBuffer.call(this, typeIds);
11650
- if (type.mode === UnionMode.Sparse) {
11651
- return assembleNestedVector.call(this, data);
11652
- } else if (type.mode === UnionMode.Dense) {
11653
- if (data.offset <= 0) {
11654
- addBuffer.call(this, valueOffsets);
11655
- return assembleNestedVector.call(this, data);
11656
- } else {
11657
- const shiftedOffsets = new Int32Array(length);
11658
- const childOffsets = /* @__PURE__ */ Object.create(null);
11659
- const childLengths = /* @__PURE__ */ Object.create(null);
11660
- for (let typeId, shift, index = -1; ++index < length; ) {
11661
- if ((typeId = typeIds[index]) === void 0) {
11662
- continue;
11663
- }
11664
- if ((shift = childOffsets[typeId]) === void 0) {
11665
- shift = childOffsets[typeId] = valueOffsets[index];
11666
- }
11667
- shiftedOffsets[index] = valueOffsets[index] - shift;
11668
- childLengths[typeId] = ((_a5 = childLengths[typeId]) !== null && _a5 !== void 0 ? _a5 : 0) + 1;
11607
+ function writeAllAsync(writer, batches) {
11608
+ var _a5, batches_1, batches_1_1;
11609
+ var _b2, e_1, _c2, _d2;
11610
+ return __awaiter(this, void 0, void 0, function* () {
11611
+ try {
11612
+ for (_a5 = true, batches_1 = __asyncValues(batches); batches_1_1 = yield batches_1.next(), _b2 = batches_1_1.done, !_b2; _a5 = true) {
11613
+ _d2 = batches_1_1.value;
11614
+ _a5 = false;
11615
+ const batch = _d2;
11616
+ writer.write(batch);
11617
+ }
11618
+ } catch (e_1_1) {
11619
+ e_1 = { error: e_1_1 };
11620
+ } finally {
11621
+ try {
11622
+ if (!_a5 && !_b2 && (_c2 = batches_1.return))
11623
+ yield _c2.call(batches_1);
11624
+ } finally {
11625
+ if (e_1)
11626
+ throw e_1.error;
11669
11627
  }
11670
- addBuffer.call(this, shiftedOffsets);
11671
- this.visitMany(data.children.map((child, childIndex) => {
11672
- const typeId = type.typeIds[childIndex];
11673
- const childOffset = childOffsets[typeId];
11674
- const childLength = childLengths[typeId];
11675
- return child.slice(childOffset, Math.min(length, childLength));
11676
- }));
11677
11628
  }
11678
- }
11679
- return this;
11629
+ return writer.finish();
11630
+ });
11680
11631
  }
11681
- function assembleBoolVector(data) {
11682
- let values;
11683
- if (data.nullCount >= data.length) {
11684
- return addBuffer.call(this, new Uint8Array(0));
11685
- } else if ((values = data.values) instanceof Uint8Array) {
11686
- return addBuffer.call(this, truncateBitmap(data.offset, data.length, values));
11632
+
11633
+ // ../../node_modules/apache-arrow/io/whatwg/iterable.mjs
11634
+ function toDOMStream(source, options) {
11635
+ if (isAsyncIterable(source)) {
11636
+ return asyncIterableAsReadableDOMStream(source, options);
11687
11637
  }
11688
- return addBuffer.call(this, packBools(data.values));
11689
- }
11690
- function assembleFlatVector(data) {
11691
- return addBuffer.call(this, data.values.subarray(0, data.length * data.stride));
11692
- }
11693
- function assembleFlatListVector(data) {
11694
- const { length, values, valueOffsets } = data;
11695
- const begin = bigIntToNumber(valueOffsets[0]);
11696
- const end = bigIntToNumber(valueOffsets[length]);
11697
- const byteLength = Math.min(end - begin, values.byteLength - begin);
11698
- addBuffer.call(this, rebaseValueOffsets(-begin, length + 1, valueOffsets));
11699
- addBuffer.call(this, values.subarray(begin, begin + byteLength));
11700
- return this;
11701
- }
11702
- function assembleListVector(data) {
11703
- const { length, valueOffsets } = data;
11704
- if (valueOffsets) {
11705
- const { [0]: begin, [length]: end } = valueOffsets;
11706
- addBuffer.call(this, rebaseValueOffsets(-begin, length + 1, valueOffsets));
11707
- return this.visit(data.children[0].slice(begin, end - begin));
11638
+ if (isIterable(source)) {
11639
+ return iterableAsReadableDOMStream(source, options);
11708
11640
  }
11709
- return this.visit(data.children[0]);
11710
- }
11711
- function assembleNestedVector(data) {
11712
- return this.visitMany(data.type.children.map((_, i) => data.children[i]).filter(Boolean))[0];
11641
+ throw new Error(`toDOMStream() must be called with an Iterable or AsyncIterable`);
11713
11642
  }
11714
- VectorAssembler.prototype.visitBool = assembleBoolVector;
11715
- VectorAssembler.prototype.visitInt = assembleFlatVector;
11716
- VectorAssembler.prototype.visitFloat = assembleFlatVector;
11717
- VectorAssembler.prototype.visitUtf8 = assembleFlatListVector;
11718
- VectorAssembler.prototype.visitLargeUtf8 = assembleFlatListVector;
11719
- VectorAssembler.prototype.visitBinary = assembleFlatListVector;
11720
- VectorAssembler.prototype.visitLargeBinary = assembleFlatListVector;
11721
- VectorAssembler.prototype.visitFixedSizeBinary = assembleFlatVector;
11722
- VectorAssembler.prototype.visitDate = assembleFlatVector;
11723
- VectorAssembler.prototype.visitTimestamp = assembleFlatVector;
11724
- VectorAssembler.prototype.visitTime = assembleFlatVector;
11725
- VectorAssembler.prototype.visitDecimal = assembleFlatVector;
11726
- VectorAssembler.prototype.visitList = assembleListVector;
11727
- VectorAssembler.prototype.visitStruct = assembleNestedVector;
11728
- VectorAssembler.prototype.visitUnion = assembleUnion;
11729
- VectorAssembler.prototype.visitInterval = assembleFlatVector;
11730
- VectorAssembler.prototype.visitDuration = assembleFlatVector;
11731
- VectorAssembler.prototype.visitFixedSizeList = assembleListVector;
11732
- VectorAssembler.prototype.visitMap = assembleListVector;
11733
-
11734
- // ../../node_modules/apache-arrow/ipc/writer.mjs
11735
- var RecordBatchWriter = class extends ReadableInterop {
11736
- /** @nocollapse */
11737
- // @ts-ignore
11738
- static throughNode(options) {
11739
- throw new Error(`"throughNode" not available in this environment`);
11643
+ function iterableAsReadableDOMStream(source, options) {
11644
+ let it = null;
11645
+ const bm = (options === null || options === void 0 ? void 0 : options.type) === "bytes" || false;
11646
+ const hwm = (options === null || options === void 0 ? void 0 : options.highWaterMark) || Math.pow(2, 24);
11647
+ return new ReadableStream(Object.assign(Object.assign({}, options), {
11648
+ start(controller) {
11649
+ next(controller, it || (it = source[Symbol.iterator]()));
11650
+ },
11651
+ pull(controller) {
11652
+ it ? next(controller, it) : controller.close();
11653
+ },
11654
+ cancel() {
11655
+ ((it === null || it === void 0 ? void 0 : it.return) && it.return() || true) && (it = null);
11656
+ }
11657
+ }), Object.assign({ highWaterMark: bm ? hwm : void 0 }, options));
11658
+ function next(controller, it2) {
11659
+ let buf;
11660
+ let r = null;
11661
+ let size = controller.desiredSize || null;
11662
+ while (!(r = it2.next(bm ? size : null)).done) {
11663
+ if (ArrayBuffer.isView(r.value) && (buf = toUint8Array(r.value))) {
11664
+ size != null && bm && (size = size - buf.byteLength + 1);
11665
+ r.value = buf;
11666
+ }
11667
+ controller.enqueue(r.value);
11668
+ if (size != null && --size <= 0) {
11669
+ return;
11670
+ }
11671
+ }
11672
+ controller.close();
11740
11673
  }
11741
- /** @nocollapse */
11742
- static throughDOM(writableStrategy, readableStrategy) {
11743
- throw new Error(`"throughDOM" not available in this environment`);
11674
+ }
11675
+ function asyncIterableAsReadableDOMStream(source, options) {
11676
+ let it = null;
11677
+ const bm = (options === null || options === void 0 ? void 0 : options.type) === "bytes" || false;
11678
+ const hwm = (options === null || options === void 0 ? void 0 : options.highWaterMark) || Math.pow(2, 24);
11679
+ return new ReadableStream(Object.assign(Object.assign({}, options), {
11680
+ start(controller) {
11681
+ return __awaiter(this, void 0, void 0, function* () {
11682
+ yield next(controller, it || (it = source[Symbol.asyncIterator]()));
11683
+ });
11684
+ },
11685
+ pull(controller) {
11686
+ return __awaiter(this, void 0, void 0, function* () {
11687
+ it ? yield next(controller, it) : controller.close();
11688
+ });
11689
+ },
11690
+ cancel() {
11691
+ return __awaiter(this, void 0, void 0, function* () {
11692
+ ((it === null || it === void 0 ? void 0 : it.return) && (yield it.return()) || true) && (it = null);
11693
+ });
11694
+ }
11695
+ }), Object.assign({ highWaterMark: bm ? hwm : void 0 }, options));
11696
+ function next(controller, it2) {
11697
+ return __awaiter(this, void 0, void 0, function* () {
11698
+ let buf;
11699
+ let r = null;
11700
+ let size = controller.desiredSize || null;
11701
+ while (!(r = yield it2.next(bm ? size : null)).done) {
11702
+ if (ArrayBuffer.isView(r.value) && (buf = toUint8Array(r.value))) {
11703
+ size != null && bm && (size = size - buf.byteLength + 1);
11704
+ r.value = buf;
11705
+ }
11706
+ controller.enqueue(r.value);
11707
+ if (size != null && --size <= 0) {
11708
+ return;
11709
+ }
11710
+ }
11711
+ controller.close();
11712
+ });
11744
11713
  }
11714
+ }
11715
+
11716
+ // ../../node_modules/apache-arrow/io/whatwg/builder.mjs
11717
+ function builderThroughDOMStream(options) {
11718
+ return new BuilderTransform(options);
11719
+ }
11720
+ var BuilderTransform = class {
11745
11721
  constructor(options) {
11746
- super();
11747
- this._position = 0;
11748
- this._started = false;
11749
- this._sink = new AsyncByteQueue();
11750
- this._schema = null;
11751
- this._dictionaryBlocks = [];
11752
- this._recordBatchBlocks = [];
11753
- this._dictionaryDeltaOffsets = /* @__PURE__ */ new Map();
11754
- isObject(options) || (options = { autoDestroy: true, writeLegacyIpcFormat: false });
11755
- this._autoDestroy = typeof options.autoDestroy === "boolean" ? options.autoDestroy : true;
11756
- this._writeLegacyIpcFormat = typeof options.writeLegacyIpcFormat === "boolean" ? options.writeLegacyIpcFormat : false;
11757
- }
11758
- toString(sync = false) {
11759
- return this._sink.toString(sync);
11722
+ this._numChunks = 0;
11723
+ this._finished = false;
11724
+ this._bufferedSize = 0;
11725
+ const { ["readableStrategy"]: readableStrategy, ["writableStrategy"]: writableStrategy, ["queueingStrategy"]: queueingStrategy = "count" } = options, builderOptions = __rest(options, ["readableStrategy", "writableStrategy", "queueingStrategy"]);
11726
+ this._controller = null;
11727
+ this._builder = makeBuilder(builderOptions);
11728
+ this._getSize = queueingStrategy !== "bytes" ? chunkLength : chunkByteLength;
11729
+ const { ["highWaterMark"]: readableHighWaterMark = queueingStrategy === "bytes" ? Math.pow(2, 14) : 1e3 } = Object.assign({}, readableStrategy);
11730
+ const { ["highWaterMark"]: writableHighWaterMark = queueingStrategy === "bytes" ? Math.pow(2, 14) : 1e3 } = Object.assign({}, writableStrategy);
11731
+ this["readable"] = new ReadableStream({
11732
+ ["cancel"]: () => {
11733
+ this._builder.clear();
11734
+ },
11735
+ ["pull"]: (c) => {
11736
+ this._maybeFlush(this._builder, this._controller = c);
11737
+ },
11738
+ ["start"]: (c) => {
11739
+ this._maybeFlush(this._builder, this._controller = c);
11740
+ }
11741
+ }, {
11742
+ "highWaterMark": readableHighWaterMark,
11743
+ "size": queueingStrategy !== "bytes" ? chunkLength : chunkByteLength
11744
+ });
11745
+ this["writable"] = new WritableStream({
11746
+ ["abort"]: () => {
11747
+ this._builder.clear();
11748
+ },
11749
+ ["write"]: () => {
11750
+ this._maybeFlush(this._builder, this._controller);
11751
+ },
11752
+ ["close"]: () => {
11753
+ this._maybeFlush(this._builder.finish(), this._controller);
11754
+ }
11755
+ }, {
11756
+ "highWaterMark": writableHighWaterMark,
11757
+ "size": (value) => this._writeValueAndReturnChunkSize(value)
11758
+ });
11760
11759
  }
11761
- toUint8Array(sync = false) {
11762
- return this._sink.toUint8Array(sync);
11760
+ _writeValueAndReturnChunkSize(value) {
11761
+ const bufferedSize = this._bufferedSize;
11762
+ this._bufferedSize = this._getSize(this._builder.append(value));
11763
+ return this._bufferedSize - bufferedSize;
11763
11764
  }
11764
- writeAll(input) {
11765
- if (isPromise(input)) {
11766
- return input.then((x) => this.writeAll(x));
11767
- } else if (isAsyncIterable(input)) {
11768
- return writeAllAsync(this, input);
11765
+ _maybeFlush(builder, controller) {
11766
+ if (controller == null) {
11767
+ return;
11768
+ }
11769
+ if (this._bufferedSize >= controller.desiredSize) {
11770
+ ++this._numChunks && this._enqueue(controller, builder.toVector());
11771
+ }
11772
+ if (builder.finished) {
11773
+ if (builder.length > 0 || this._numChunks === 0) {
11774
+ ++this._numChunks && this._enqueue(controller, builder.toVector());
11775
+ }
11776
+ if (!this._finished && (this._finished = true)) {
11777
+ this._enqueue(controller, null);
11778
+ }
11769
11779
  }
11770
- return writeAll(this, input);
11771
- }
11772
- get closed() {
11773
- return this._sink.closed;
11774
11780
  }
11775
- [Symbol.asyncIterator]() {
11776
- return this._sink[Symbol.asyncIterator]();
11781
+ _enqueue(controller, chunk) {
11782
+ this._bufferedSize = 0;
11783
+ this._controller = null;
11784
+ chunk == null ? controller.close() : controller.enqueue(chunk);
11777
11785
  }
11778
- toDOMStream(options) {
11779
- return this._sink.toDOMStream(options);
11786
+ };
11787
+ var chunkLength = (chunk) => {
11788
+ var _a5;
11789
+ return (_a5 = chunk === null || chunk === void 0 ? void 0 : chunk.length) !== null && _a5 !== void 0 ? _a5 : 0;
11790
+ };
11791
+ var chunkByteLength = (chunk) => {
11792
+ var _a5;
11793
+ return (_a5 = chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) !== null && _a5 !== void 0 ? _a5 : 0;
11794
+ };
11795
+
11796
+ // ../../node_modules/apache-arrow/io/whatwg/reader.mjs
11797
+ function recordBatchReaderThroughDOMStream(writableStrategy, readableStrategy) {
11798
+ const queue = new AsyncByteQueue();
11799
+ let reader = null;
11800
+ const readable = new ReadableStream({
11801
+ cancel() {
11802
+ return __awaiter(this, void 0, void 0, function* () {
11803
+ yield queue.close();
11804
+ });
11805
+ },
11806
+ start(controller) {
11807
+ return __awaiter(this, void 0, void 0, function* () {
11808
+ yield next(controller, reader || (reader = yield open()));
11809
+ });
11810
+ },
11811
+ pull(controller) {
11812
+ return __awaiter(this, void 0, void 0, function* () {
11813
+ reader ? yield next(controller, reader) : controller.close();
11814
+ });
11815
+ }
11816
+ });
11817
+ return { writable: new WritableStream(queue, Object.assign({ "highWaterMark": Math.pow(2, 14) }, writableStrategy)), readable };
11818
+ function open() {
11819
+ return __awaiter(this, void 0, void 0, function* () {
11820
+ return yield (yield RecordBatchReader.from(queue)).open(readableStrategy);
11821
+ });
11780
11822
  }
11781
- toNodeStream(options) {
11782
- return this._sink.toNodeStream(options);
11823
+ function next(controller, reader2) {
11824
+ return __awaiter(this, void 0, void 0, function* () {
11825
+ let size = controller.desiredSize;
11826
+ let r = null;
11827
+ while (!(r = yield reader2.next()).done) {
11828
+ controller.enqueue(r.value);
11829
+ if (size != null && --size <= 0) {
11830
+ return;
11831
+ }
11832
+ }
11833
+ controller.close();
11834
+ });
11783
11835
  }
11784
- close() {
11785
- return this.reset()._sink.close();
11836
+ }
11837
+
11838
+ // ../../node_modules/apache-arrow/io/whatwg/writer.mjs
11839
+ function recordBatchWriterThroughDOMStream(writableStrategy, readableStrategy) {
11840
+ const writer = new this(writableStrategy);
11841
+ const reader = new AsyncByteStream(writer);
11842
+ const readable = new ReadableStream({
11843
+ // type: 'bytes',
11844
+ cancel() {
11845
+ return __awaiter(this, void 0, void 0, function* () {
11846
+ yield reader.cancel();
11847
+ });
11848
+ },
11849
+ pull(controller) {
11850
+ return __awaiter(this, void 0, void 0, function* () {
11851
+ yield next(controller);
11852
+ });
11853
+ },
11854
+ start(controller) {
11855
+ return __awaiter(this, void 0, void 0, function* () {
11856
+ yield next(controller);
11857
+ });
11858
+ }
11859
+ }, Object.assign({ "highWaterMark": Math.pow(2, 14) }, readableStrategy));
11860
+ return { writable: new WritableStream(writer, writableStrategy), readable };
11861
+ function next(controller) {
11862
+ return __awaiter(this, void 0, void 0, function* () {
11863
+ let buf = null;
11864
+ let size = controller.desiredSize;
11865
+ while (buf = yield reader.read(size || null)) {
11866
+ controller.enqueue(buf);
11867
+ if (size != null && (size -= buf.byteLength) <= 0) {
11868
+ return;
11869
+ }
11870
+ }
11871
+ controller.close();
11872
+ });
11786
11873
  }
11787
- abort(reason) {
11788
- return this.reset()._sink.abort(reason);
11874
+ }
11875
+
11876
+ // ../../node_modules/apache-arrow/ipc/serialization.mjs
11877
+ function tableFromIPC(input) {
11878
+ const reader = RecordBatchReader.from(input);
11879
+ if (isPromise(reader)) {
11880
+ return reader.then((reader2) => tableFromIPC(reader2));
11789
11881
  }
11790
- finish() {
11791
- this._autoDestroy ? this.close() : this.reset(this._sink, this._schema);
11792
- return this;
11882
+ if (reader.isAsync()) {
11883
+ return reader.readAll().then((xs) => new Table(xs));
11793
11884
  }
11794
- reset(sink = this._sink, schema = null) {
11795
- if (sink === this._sink || sink instanceof AsyncByteQueue) {
11796
- this._sink = sink;
11797
- } else {
11798
- this._sink = new AsyncByteQueue();
11799
- if (sink && isWritableDOMStream(sink)) {
11800
- this.toDOMStream({ type: "bytes" }).pipeTo(sink);
11801
- } else if (sink && isWritableNodeStream(sink)) {
11802
- this.toNodeStream({ objectMode: false }).pipe(sink);
11803
- }
11804
- }
11805
- if (this._started && this._schema) {
11806
- this._writeFooter(this._schema);
11807
- }
11808
- this._started = false;
11809
- this._dictionaryBlocks = [];
11810
- this._recordBatchBlocks = [];
11811
- this._dictionaryDeltaOffsets = /* @__PURE__ */ new Map();
11812
- if (!schema || !compareSchemas(schema, this._schema)) {
11813
- if (schema == null) {
11814
- this._position = 0;
11815
- this._schema = null;
11816
- } else {
11817
- this._started = true;
11818
- this._schema = schema;
11819
- this._writeSchema(schema);
11820
- }
11821
- }
11822
- return this;
11885
+ return new Table(reader.readAll());
11886
+ }
11887
+
11888
+ // ../../node_modules/apache-arrow/Arrow.mjs
11889
+ var util = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, bn_exports), int_exports), bit_exports), math_exports), buffer_exports), vector_exports), pretty_exports), {
11890
+ compareSchemas,
11891
+ compareFields,
11892
+ compareTypes
11893
+ });
11894
+
11895
+ // ../../node_modules/apache-arrow/Arrow.dom.mjs
11896
+ adapters_default.toDOMStream = toDOMStream;
11897
+ Builder2["throughDOM"] = builderThroughDOMStream;
11898
+ RecordBatchReader["throughDOM"] = recordBatchReaderThroughDOMStream;
11899
+ RecordBatchFileReader["throughDOM"] = recordBatchReaderThroughDOMStream;
11900
+ RecordBatchStreamReader["throughDOM"] = recordBatchReaderThroughDOMStream;
11901
+ RecordBatchWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
11902
+ RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
11903
+ RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
11904
+
11905
+ // ../schema/src/lib/table/simple-table/data-type.ts
11906
+ function getDataTypeFromValue(value, defaultNumberType = "float32") {
11907
+ if (value instanceof Date) {
11908
+ return "date-millisecond";
11823
11909
  }
11824
- write(payload) {
11825
- let schema = null;
11826
- if (!this._sink) {
11827
- throw new Error(`RecordBatchWriter is closed`);
11828
- } else if (payload == null) {
11829
- return this.finish() && void 0;
11830
- } else if (payload instanceof Table && !(schema = payload.schema)) {
11831
- return this.finish() && void 0;
11832
- } else if (payload instanceof RecordBatch2 && !(schema = payload.schema)) {
11833
- return this.finish() && void 0;
11834
- }
11835
- if (schema && !compareSchemas(schema, this._schema)) {
11836
- if (this._started && this._autoDestroy) {
11837
- return this.close();
11838
- }
11839
- this.reset(this._sink, schema);
11840
- }
11841
- if (payload instanceof RecordBatch2) {
11842
- if (!(payload instanceof _InternalEmptyPlaceholderRecordBatch)) {
11843
- this._writeRecordBatch(payload);
11844
- }
11845
- } else if (payload instanceof Table) {
11846
- this.writeAll(payload.batches);
11847
- } else if (isIterable(payload)) {
11848
- this.writeAll(payload);
11849
- }
11910
+ if (value instanceof Number) {
11911
+ return defaultNumberType;
11850
11912
  }
11851
- _writeMessage(message, alignment = 8) {
11852
- const a = alignment - 1;
11853
- const buffer = Message2.encode(message);
11854
- const flatbufferSize = buffer.byteLength;
11855
- const prefixSize = !this._writeLegacyIpcFormat ? 8 : 4;
11856
- const alignedSize = flatbufferSize + prefixSize + a & ~a;
11857
- const nPaddingBytes = alignedSize - flatbufferSize - prefixSize;
11858
- if (message.headerType === MessageHeader.RecordBatch) {
11859
- this._recordBatchBlocks.push(new FileBlock(alignedSize, message.bodyLength, this._position));
11860
- } else if (message.headerType === MessageHeader.DictionaryBatch) {
11861
- this._dictionaryBlocks.push(new FileBlock(alignedSize, message.bodyLength, this._position));
11862
- }
11863
- if (!this._writeLegacyIpcFormat) {
11864
- this._write(Int32Array.of(-1));
11865
- }
11866
- this._write(Int32Array.of(alignedSize - prefixSize));
11867
- if (flatbufferSize > 0) {
11868
- this._write(buffer);
11869
- }
11870
- return this._writePadding(nPaddingBytes);
11913
+ if (typeof value === "string") {
11914
+ return "utf8";
11871
11915
  }
11872
- _write(chunk) {
11873
- if (this._started) {
11874
- const buffer = toUint8Array(chunk);
11875
- if (buffer && buffer.byteLength > 0) {
11876
- this._sink.write(buffer);
11877
- this._position += buffer.byteLength;
11878
- }
11879
- }
11880
- return this;
11916
+ if (value === null || value === "undefined") {
11917
+ return "null";
11881
11918
  }
11882
- _writeSchema(schema) {
11883
- return this._writeMessage(Message2.from(schema));
11919
+ return "null";
11920
+ }
11921
+ function getDataTypeFromArray(array) {
11922
+ let type = getDataTypeFromTypedArray(array);
11923
+ if (type !== "null") {
11924
+ return { type, nullable: false };
11884
11925
  }
11885
- // @ts-ignore
11886
- _writeFooter(schema) {
11887
- return this._writeLegacyIpcFormat ? this._write(Int32Array.of(0)) : this._write(Int32Array.of(-1, 0));
11926
+ if (array.length > 0) {
11927
+ type = getDataTypeFromValue(array[0]);
11928
+ return { type, nullable: true };
11888
11929
  }
11889
- _writeMagic() {
11890
- return this._write(MAGIC);
11930
+ return { type: "null", nullable: true };
11931
+ }
11932
+ function getDataTypeFromTypedArray(array) {
11933
+ switch (array.constructor) {
11934
+ case Int8Array:
11935
+ return "int8";
11936
+ case Uint8Array:
11937
+ case Uint8ClampedArray:
11938
+ return "uint8";
11939
+ case Int16Array:
11940
+ return "int16";
11941
+ case Uint16Array:
11942
+ return "uint16";
11943
+ case Int32Array:
11944
+ return "int32";
11945
+ case Uint32Array:
11946
+ return "uint32";
11947
+ case Float32Array:
11948
+ return "float32";
11949
+ case Float64Array:
11950
+ return "float64";
11951
+ default:
11952
+ return "null";
11891
11953
  }
11892
- _writePadding(nBytes) {
11893
- return nBytes > 0 ? this._write(new Uint8Array(nBytes)) : this;
11954
+ }
11955
+ function getArrayTypeFromDataType(type, nullable) {
11956
+ if (!nullable) {
11957
+ switch (type) {
11958
+ case "int8":
11959
+ return Int8Array;
11960
+ case "uint8":
11961
+ return Uint8Array;
11962
+ case "int16":
11963
+ return Int16Array;
11964
+ case "uint16":
11965
+ return Uint16Array;
11966
+ case "int32":
11967
+ return Int32Array;
11968
+ case "uint32":
11969
+ return Uint32Array;
11970
+ case "float32":
11971
+ return Float32Array;
11972
+ case "float64":
11973
+ return Float64Array;
11974
+ default:
11975
+ break;
11976
+ }
11894
11977
  }
11895
- _writeRecordBatch(batch) {
11896
- const { byteLength, nodes, bufferRegions, buffers } = VectorAssembler.assemble(batch);
11897
- const recordBatch = new RecordBatch3(batch.numRows, nodes, bufferRegions);
11898
- const message = Message2.from(recordBatch, byteLength);
11899
- return this._writeDictionaries(batch)._writeMessage(message)._writeBodyBuffers(buffers);
11978
+ return Array;
11979
+ }
11980
+
11981
+ // ../schema/src/lib/table/simple-table/table-accessors.ts
11982
+ function getTableLength(table) {
11983
+ switch (table.shape) {
11984
+ case "array-row-table":
11985
+ case "object-row-table":
11986
+ return table.data.length;
11987
+ case "geojson-table":
11988
+ return table.features.length;
11989
+ case "arrow-table":
11990
+ const arrowTable = table.data;
11991
+ return arrowTable.numRows;
11992
+ case "columnar-table":
11993
+ for (const column of Object.values(table.data)) {
11994
+ return column.length || 0;
11995
+ }
11996
+ return 0;
11997
+ default:
11998
+ throw new Error("table");
11900
11999
  }
11901
- _writeDictionaryBatch(dictionary, id, isDelta = false) {
11902
- this._dictionaryDeltaOffsets.set(id, dictionary.length + (this._dictionaryDeltaOffsets.get(id) || 0));
11903
- const { byteLength, nodes, bufferRegions, buffers } = VectorAssembler.assemble(new Vector([dictionary]));
11904
- const recordBatch = new RecordBatch3(dictionary.length, nodes, bufferRegions);
11905
- const dictionaryBatch = new DictionaryBatch2(recordBatch, id, isDelta);
11906
- const message = Message2.from(dictionaryBatch, byteLength);
11907
- return this._writeMessage(message)._writeBodyBuffers(buffers);
12000
+ }
12001
+ function getTableCell(table, rowIndex, columnName) {
12002
+ switch (table.shape) {
12003
+ case "array-row-table":
12004
+ const columnIndex = getTableColumnIndex(table, columnName);
12005
+ return table.data[rowIndex][columnIndex];
12006
+ case "object-row-table":
12007
+ return table.data[rowIndex][columnName];
12008
+ case "geojson-table":
12009
+ return table.features[rowIndex][columnName];
12010
+ case "columnar-table":
12011
+ const column = table.data[columnName];
12012
+ return column[rowIndex];
12013
+ case "arrow-table":
12014
+ const arrowTable = table.data;
12015
+ const arrowColumnIndex = arrowTable.schema.fields.findIndex(
12016
+ (field) => field.name === columnName
12017
+ );
12018
+ return arrowTable.getChildAt(arrowColumnIndex)?.get(rowIndex);
12019
+ default:
12020
+ throw new Error("todo");
11908
12021
  }
11909
- _writeBodyBuffers(buffers) {
11910
- let buffer;
11911
- let size, padding;
11912
- for (let i = -1, n = buffers.length; ++i < n; ) {
11913
- if ((buffer = buffers[i]) && (size = buffer.byteLength) > 0) {
11914
- this._write(buffer);
11915
- if ((padding = (size + 7 & ~7) - size) > 0) {
11916
- this._writePadding(padding);
12022
+ }
12023
+ function getTableColumnIndex(table, columnName) {
12024
+ const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
12025
+ if (columnIndex === void 0) {
12026
+ throw new Error(columnName);
12027
+ }
12028
+ return columnIndex;
12029
+ }
12030
+ function getTableRowAsObject(table, rowIndex, target, copy) {
12031
+ switch (table.shape) {
12032
+ case "object-row-table":
12033
+ return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
12034
+ case "array-row-table":
12035
+ if (table.schema) {
12036
+ const objectRow2 = target || {};
12037
+ for (let i = 0; i < table.schema.fields.length; i++) {
12038
+ objectRow2[table.schema.fields[i].name] = table.data[rowIndex][i];
12039
+ }
12040
+ return objectRow2;
12041
+ }
12042
+ throw new Error("no schema");
12043
+ case "geojson-table":
12044
+ if (table.schema) {
12045
+ const objectRow2 = target || {};
12046
+ for (let i = 0; i < table.schema.fields.length; i++) {
12047
+ objectRow2[table.schema.fields[i].name] = table.features[rowIndex][i];
12048
+ }
12049
+ return objectRow2;
12050
+ }
12051
+ throw new Error("no schema");
12052
+ case "columnar-table":
12053
+ if (table.schema) {
12054
+ const objectRow2 = target || {};
12055
+ for (let i = 0; i < table.schema.fields.length; i++) {
12056
+ objectRow2[table.schema.fields[i].name] = table.data[table.schema.fields[i].name][rowIndex];
12057
+ }
12058
+ return objectRow2;
12059
+ } else {
12060
+ const objectRow2 = target || {};
12061
+ for (const [name, column] of Object.entries(table.data)) {
12062
+ objectRow2[name] = column[rowIndex];
12063
+ }
12064
+ return objectRow2;
12065
+ }
12066
+ case "arrow-table":
12067
+ const arrowTable = table.data;
12068
+ const objectRow = target || {};
12069
+ const row = arrowTable.get(rowIndex);
12070
+ const schema = arrowTable.schema;
12071
+ for (let i = 0; i < schema.fields.length; i++) {
12072
+ objectRow[schema.fields[i].name] = row?.[schema.fields[i].name];
12073
+ }
12074
+ return objectRow;
12075
+ default:
12076
+ throw new Error("shape");
12077
+ }
12078
+ }
12079
+ function getTableRowAsArray(table, rowIndex, target, copy) {
12080
+ switch (table.shape) {
12081
+ case "array-row-table":
12082
+ return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
12083
+ case "object-row-table":
12084
+ if (table.schema) {
12085
+ const arrayRow2 = target || [];
12086
+ for (let i = 0; i < table.schema.fields.length; i++) {
12087
+ arrayRow2[i] = table.data[rowIndex][table.schema.fields[i].name];
11917
12088
  }
12089
+ return arrayRow2;
11918
12090
  }
11919
- }
11920
- return this;
11921
- }
11922
- _writeDictionaries(batch) {
11923
- for (let [id, dictionary] of batch.dictionaries) {
11924
- let offset = this._dictionaryDeltaOffsets.get(id) || 0;
11925
- if (offset === 0 || (dictionary = dictionary === null || dictionary === void 0 ? void 0 : dictionary.slice(offset)).length > 0) {
11926
- for (const data of dictionary.data) {
11927
- this._writeDictionaryBatch(data, id, offset > 0);
11928
- offset += data.length;
12091
+ return Object.values(table.data[rowIndex]);
12092
+ case "geojson-table":
12093
+ if (table.schema) {
12094
+ const arrayRow2 = target || [];
12095
+ for (let i = 0; i < table.schema.fields.length; i++) {
12096
+ arrayRow2[i] = table.features[rowIndex][table.schema.fields[i].name];
11929
12097
  }
12098
+ return arrayRow2;
11930
12099
  }
11931
- }
11932
- return this;
11933
- }
11934
- };
11935
- var RecordBatchStreamWriter = class extends RecordBatchWriter {
11936
- /** @nocollapse */
11937
- static writeAll(input, options) {
11938
- const writer = new RecordBatchStreamWriter(options);
11939
- if (isPromise(input)) {
11940
- return input.then((x) => writer.writeAll(x));
11941
- } else if (isAsyncIterable(input)) {
11942
- return writeAllAsync(writer, input);
11943
- }
11944
- return writeAll(writer, input);
11945
- }
11946
- };
11947
- var RecordBatchFileWriter = class extends RecordBatchWriter {
11948
- /** @nocollapse */
11949
- static writeAll(input) {
11950
- const writer = new RecordBatchFileWriter();
11951
- if (isPromise(input)) {
11952
- return input.then((x) => writer.writeAll(x));
11953
- } else if (isAsyncIterable(input)) {
11954
- return writeAllAsync(writer, input);
11955
- }
11956
- return writeAll(writer, input);
11957
- }
11958
- constructor() {
11959
- super();
11960
- this._autoDestroy = true;
12100
+ return Object.values(table.features[rowIndex]);
12101
+ case "columnar-table":
12102
+ if (table.schema) {
12103
+ const arrayRow2 = target || [];
12104
+ for (let i = 0; i < table.schema.fields.length; i++) {
12105
+ arrayRow2[i] = table.data[table.schema.fields[i].name][rowIndex];
12106
+ }
12107
+ return arrayRow2;
12108
+ } else {
12109
+ const arrayRow2 = target || [];
12110
+ let i = 0;
12111
+ for (const column of Object.values(table.data)) {
12112
+ arrayRow2[i] = column[rowIndex];
12113
+ i++;
12114
+ }
12115
+ return arrayRow2;
12116
+ }
12117
+ case "arrow-table":
12118
+ const arrowTable = table.data;
12119
+ const arrayRow = target || [];
12120
+ const row = arrowTable.get(rowIndex);
12121
+ const schema = arrowTable.schema;
12122
+ for (let i = 0; i < schema.fields.length; i++) {
12123
+ arrayRow[i] = row?.[schema.fields[i].name];
12124
+ }
12125
+ return arrayRow;
12126
+ default:
12127
+ throw new Error("shape");
11961
12128
  }
11962
- // @ts-ignore
11963
- _writeSchema(schema) {
11964
- return this._writeMagic()._writePadding(2);
12129
+ }
12130
+
12131
+ // ../schema/src/lib/table/simple-table/table-schema.ts
12132
+ function deduceTableSchema(table) {
12133
+ switch (table.shape) {
12134
+ case "array-row-table":
12135
+ case "object-row-table":
12136
+ return deduceSchemaFromRows(table.data);
12137
+ case "geojson-table":
12138
+ return deduceSchemaFromGeoJSON(table.features);
12139
+ case "columnar-table":
12140
+ return deduceSchemaFromColumns(table.data);
12141
+ case "arrow-table":
12142
+ default:
12143
+ throw new Error("Deduce schema");
11965
12144
  }
11966
- _writeFooter(schema) {
11967
- const buffer = Footer_.encode(new Footer_(schema, MetadataVersion.V5, this._recordBatchBlocks, this._dictionaryBlocks));
11968
- return super._writeFooter(schema)._write(buffer)._write(Int32Array.of(buffer.byteLength))._writeMagic();
12145
+ }
12146
+ function deduceSchemaFromColumns(columnarTable) {
12147
+ const fields = [];
12148
+ for (const [columnName, column] of Object.entries(columnarTable)) {
12149
+ const field = deduceFieldFromColumn(column, columnName);
12150
+ fields.push(field);
11969
12151
  }
11970
- };
11971
- function writeAll(writer, input) {
11972
- let chunks = input;
11973
- if (input instanceof Table) {
11974
- chunks = input.batches;
11975
- writer.reset(void 0, input.schema);
12152
+ return { fields, metadata: {} };
12153
+ }
12154
+ function deduceSchemaFromRows(rowTable) {
12155
+ if (!rowTable.length) {
12156
+ throw new Error("deduce from empty table");
11976
12157
  }
11977
- for (const batch of chunks) {
11978
- writer.write(batch);
12158
+ const fields = [];
12159
+ const row0 = rowTable[0];
12160
+ for (const [columnName, value] of Object.entries(row0)) {
12161
+ fields.push(deduceFieldFromValue(value, columnName));
11979
12162
  }
11980
- return writer.finish();
11981
- }
11982
- function writeAllAsync(writer, batches) {
11983
- var _a5, batches_1, batches_1_1;
11984
- var _b2, e_1, _c2, _d2;
11985
- return __awaiter(this, void 0, void 0, function* () {
11986
- try {
11987
- for (_a5 = true, batches_1 = __asyncValues(batches); batches_1_1 = yield batches_1.next(), _b2 = batches_1_1.done, !_b2; _a5 = true) {
11988
- _d2 = batches_1_1.value;
11989
- _a5 = false;
11990
- const batch = _d2;
11991
- writer.write(batch);
11992
- }
11993
- } catch (e_1_1) {
11994
- e_1 = { error: e_1_1 };
11995
- } finally {
11996
- try {
11997
- if (!_a5 && !_b2 && (_c2 = batches_1.return))
11998
- yield _c2.call(batches_1);
11999
- } finally {
12000
- if (e_1)
12001
- throw e_1.error;
12002
- }
12003
- }
12004
- return writer.finish();
12005
- });
12163
+ return { fields, metadata: {} };
12006
12164
  }
12007
-
12008
- // ../../node_modules/apache-arrow/io/whatwg/iterable.mjs
12009
- function toDOMStream(source, options) {
12010
- if (isAsyncIterable(source)) {
12011
- return asyncIterableAsReadableDOMStream(source, options);
12165
+ function deduceSchemaFromGeoJSON(features) {
12166
+ if (!features.length) {
12167
+ throw new Error("deduce from empty table");
12012
12168
  }
12013
- if (isIterable(source)) {
12014
- return iterableAsReadableDOMStream(source, options);
12169
+ const fields = [];
12170
+ const row0 = features[0].properties || {};
12171
+ for (const [columnName, value] of Object.entries(row0)) {
12172
+ fields.push(deduceFieldFromValue(value, columnName));
12015
12173
  }
12016
- throw new Error(`toDOMStream() must be called with an Iterable or AsyncIterable`);
12174
+ return { fields, metadata: {} };
12017
12175
  }
12018
- function iterableAsReadableDOMStream(source, options) {
12019
- let it = null;
12020
- const bm = (options === null || options === void 0 ? void 0 : options.type) === "bytes" || false;
12021
- const hwm = (options === null || options === void 0 ? void 0 : options.highWaterMark) || Math.pow(2, 24);
12022
- return new ReadableStream(Object.assign(Object.assign({}, options), {
12023
- start(controller) {
12024
- next(controller, it || (it = source[Symbol.iterator]()));
12025
- },
12026
- pull(controller) {
12027
- it ? next(controller, it) : controller.close();
12028
- },
12029
- cancel() {
12030
- ((it === null || it === void 0 ? void 0 : it.return) && it.return() || true) && (it = null);
12031
- }
12032
- }), Object.assign({ highWaterMark: bm ? hwm : void 0 }, options));
12033
- function next(controller, it2) {
12034
- let buf;
12035
- let r = null;
12036
- let size = controller.desiredSize || null;
12037
- while (!(r = it2.next(bm ? size : null)).done) {
12038
- if (ArrayBuffer.isView(r.value) && (buf = toUint8Array(r.value))) {
12039
- size != null && bm && (size = size - buf.byteLength + 1);
12040
- r.value = buf;
12041
- }
12042
- controller.enqueue(r.value);
12043
- if (size != null && --size <= 0) {
12044
- return;
12045
- }
12046
- }
12047
- controller.close();
12176
+ function deduceFieldFromColumn(column, name) {
12177
+ if (ArrayBuffer.isView(column)) {
12178
+ const type = getDataTypeFromArray(column);
12179
+ return {
12180
+ name,
12181
+ type: type.type || "null",
12182
+ nullable: type.nullable
12183
+ // metadata: {}
12184
+ };
12048
12185
  }
12049
- }
12050
- function asyncIterableAsReadableDOMStream(source, options) {
12051
- let it = null;
12052
- const bm = (options === null || options === void 0 ? void 0 : options.type) === "bytes" || false;
12053
- const hwm = (options === null || options === void 0 ? void 0 : options.highWaterMark) || Math.pow(2, 24);
12054
- return new ReadableStream(Object.assign(Object.assign({}, options), {
12055
- start(controller) {
12056
- return __awaiter(this, void 0, void 0, function* () {
12057
- yield next(controller, it || (it = source[Symbol.asyncIterator]()));
12058
- });
12059
- },
12060
- pull(controller) {
12061
- return __awaiter(this, void 0, void 0, function* () {
12062
- it ? yield next(controller, it) : controller.close();
12063
- });
12064
- },
12065
- cancel() {
12066
- return __awaiter(this, void 0, void 0, function* () {
12067
- ((it === null || it === void 0 ? void 0 : it.return) && (yield it.return()) || true) && (it = null);
12068
- });
12069
- }
12070
- }), Object.assign({ highWaterMark: bm ? hwm : void 0 }, options));
12071
- function next(controller, it2) {
12072
- return __awaiter(this, void 0, void 0, function* () {
12073
- let buf;
12074
- let r = null;
12075
- let size = controller.desiredSize || null;
12076
- while (!(r = yield it2.next(bm ? size : null)).done) {
12077
- if (ArrayBuffer.isView(r.value) && (buf = toUint8Array(r.value))) {
12078
- size != null && bm && (size = size - buf.byteLength + 1);
12079
- r.value = buf;
12080
- }
12081
- controller.enqueue(r.value);
12082
- if (size != null && --size <= 0) {
12083
- return;
12084
- }
12085
- }
12086
- controller.close();
12087
- });
12186
+ if (Array.isArray(column) && column.length > 0) {
12187
+ const value = column[0];
12188
+ const type = getDataTypeFromValue(value);
12189
+ return {
12190
+ name,
12191
+ type,
12192
+ nullable: true
12193
+ // metadata: {},
12194
+ };
12088
12195
  }
12196
+ throw new Error("empty table");
12197
+ }
12198
+ function deduceFieldFromValue(value, name) {
12199
+ const type = getDataTypeFromValue(value);
12200
+ return {
12201
+ name,
12202
+ type,
12203
+ nullable: true
12204
+ // metadata: {}
12205
+ };
12089
12206
  }
12090
12207
 
12091
- // ../../node_modules/apache-arrow/io/whatwg/builder.mjs
12092
- function builderThroughDOMStream(options) {
12093
- return new BuilderTransform(options);
12208
+ // ../schema/src/lib/table/simple-table/table-column.ts
12209
+ function makeColumnFromField(field, length) {
12210
+ const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
12211
+ return new ArrayType(length);
12094
12212
  }
12095
- var BuilderTransform = class {
12096
- constructor(options) {
12097
- this._numChunks = 0;
12098
- this._finished = false;
12099
- this._bufferedSize = 0;
12100
- const { ["readableStrategy"]: readableStrategy, ["writableStrategy"]: writableStrategy, ["queueingStrategy"]: queueingStrategy = "count" } = options, builderOptions = __rest(options, ["readableStrategy", "writableStrategy", "queueingStrategy"]);
12101
- this._controller = null;
12102
- this._builder = makeBuilder(builderOptions);
12103
- this._getSize = queueingStrategy !== "bytes" ? chunkLength : chunkByteLength;
12104
- const { ["highWaterMark"]: readableHighWaterMark = queueingStrategy === "bytes" ? Math.pow(2, 14) : 1e3 } = Object.assign({}, readableStrategy);
12105
- const { ["highWaterMark"]: writableHighWaterMark = queueingStrategy === "bytes" ? Math.pow(2, 14) : 1e3 } = Object.assign({}, writableStrategy);
12106
- this["readable"] = new ReadableStream({
12107
- ["cancel"]: () => {
12108
- this._builder.clear();
12109
- },
12110
- ["pull"]: (c) => {
12111
- this._maybeFlush(this._builder, this._controller = c);
12112
- },
12113
- ["start"]: (c) => {
12114
- this._maybeFlush(this._builder, this._controller = c);
12115
- }
12116
- }, {
12117
- "highWaterMark": readableHighWaterMark,
12118
- "size": queueingStrategy !== "bytes" ? chunkLength : chunkByteLength
12119
- });
12120
- this["writable"] = new WritableStream({
12121
- ["abort"]: () => {
12122
- this._builder.clear();
12123
- },
12124
- ["write"]: () => {
12125
- this._maybeFlush(this._builder, this._controller);
12126
- },
12127
- ["close"]: () => {
12128
- this._maybeFlush(this._builder.finish(), this._controller);
12129
- }
12130
- }, {
12131
- "highWaterMark": writableHighWaterMark,
12132
- "size": (value) => this._writeValueAndReturnChunkSize(value)
12133
- });
12134
- }
12135
- _writeValueAndReturnChunkSize(value) {
12136
- const bufferedSize = this._bufferedSize;
12137
- this._bufferedSize = this._getSize(this._builder.append(value));
12138
- return this._bufferedSize - bufferedSize;
12213
+
12214
+ // ../schema/src/lib/table/simple-table/convert-table.ts
12215
+ function convertTable(table, shape) {
12216
+ switch (shape) {
12217
+ case "object-row-table":
12218
+ return makeObjectRowTable(table);
12219
+ case "array-row-table":
12220
+ return makeArrayRowTable(table);
12221
+ case "columnar-table":
12222
+ return makeColumnarTable(table);
12223
+ case "arrow-table":
12224
+ return makeArrowTable(table);
12225
+ default:
12226
+ throw new Error(shape);
12139
12227
  }
12140
- _maybeFlush(builder, controller) {
12141
- if (controller == null) {
12142
- return;
12143
- }
12144
- if (this._bufferedSize >= controller.desiredSize) {
12145
- ++this._numChunks && this._enqueue(controller, builder.toVector());
12146
- }
12147
- if (builder.finished) {
12148
- if (builder.length > 0 || this._numChunks === 0) {
12149
- ++this._numChunks && this._enqueue(controller, builder.toVector());
12150
- }
12151
- if (!this._finished && (this._finished = true)) {
12152
- this._enqueue(controller, null);
12153
- }
12154
- }
12228
+ }
12229
+ function makeArrowTable(table) {
12230
+ const _makeArrowTable = globalThis.__loaders?._makeArrowTable;
12231
+ if (!_makeArrowTable) {
12232
+ throw new Error("");
12155
12233
  }
12156
- _enqueue(controller, chunk) {
12157
- this._bufferedSize = 0;
12158
- this._controller = null;
12159
- chunk == null ? controller.close() : controller.enqueue(chunk);
12234
+ return _makeArrowTable(table);
12235
+ }
12236
+ function makeColumnarTable(table) {
12237
+ const schema = table.schema || deduceTableSchema(table);
12238
+ const fields = table.schema?.fields || [];
12239
+ if (table.shape === "columnar-table") {
12240
+ return { ...table, schema };
12160
12241
  }
12161
- };
12162
- var chunkLength = (chunk) => {
12163
- var _a5;
12164
- return (_a5 = chunk === null || chunk === void 0 ? void 0 : chunk.length) !== null && _a5 !== void 0 ? _a5 : 0;
12165
- };
12166
- var chunkByteLength = (chunk) => {
12167
- var _a5;
12168
- return (_a5 = chunk === null || chunk === void 0 ? void 0 : chunk.byteLength) !== null && _a5 !== void 0 ? _a5 : 0;
12169
- };
12170
-
12171
- // ../../node_modules/apache-arrow/io/whatwg/reader.mjs
12172
- function recordBatchReaderThroughDOMStream(writableStrategy, readableStrategy) {
12173
- const queue = new AsyncByteQueue();
12174
- let reader = null;
12175
- const readable = new ReadableStream({
12176
- cancel() {
12177
- return __awaiter(this, void 0, void 0, function* () {
12178
- yield queue.close();
12179
- });
12180
- },
12181
- start(controller) {
12182
- return __awaiter(this, void 0, void 0, function* () {
12183
- yield next(controller, reader || (reader = yield open()));
12184
- });
12185
- },
12186
- pull(controller) {
12187
- return __awaiter(this, void 0, void 0, function* () {
12188
- reader ? yield next(controller, reader) : controller.close();
12189
- });
12242
+ const length = getTableLength(table);
12243
+ const columns = {};
12244
+ for (const field of fields) {
12245
+ const column = makeColumnFromField(field, length);
12246
+ columns[field.name] = column;
12247
+ for (let rowIndex = 0; rowIndex < length; rowIndex++) {
12248
+ column[rowIndex] = getTableCell(table, rowIndex, field.name);
12190
12249
  }
12191
- });
12192
- return { writable: new WritableStream(queue, Object.assign({ "highWaterMark": Math.pow(2, 14) }, writableStrategy)), readable };
12193
- function open() {
12194
- return __awaiter(this, void 0, void 0, function* () {
12195
- return yield (yield RecordBatchReader.from(queue)).open(readableStrategy);
12196
- });
12197
- }
12198
- function next(controller, reader2) {
12199
- return __awaiter(this, void 0, void 0, function* () {
12200
- let size = controller.desiredSize;
12201
- let r = null;
12202
- while (!(r = yield reader2.next()).done) {
12203
- controller.enqueue(r.value);
12204
- if (size != null && --size <= 0) {
12205
- return;
12206
- }
12207
- }
12208
- controller.close();
12209
- });
12210
12250
  }
12251
+ return {
12252
+ shape: "columnar-table",
12253
+ schema,
12254
+ data: columns
12255
+ };
12211
12256
  }
12212
-
12213
- // ../../node_modules/apache-arrow/io/whatwg/writer.mjs
12214
- function recordBatchWriterThroughDOMStream(writableStrategy, readableStrategy) {
12215
- const writer = new this(writableStrategy);
12216
- const reader = new AsyncByteStream(writer);
12217
- const readable = new ReadableStream({
12218
- // type: 'bytes',
12219
- cancel() {
12220
- return __awaiter(this, void 0, void 0, function* () {
12221
- yield reader.cancel();
12222
- });
12223
- },
12224
- pull(controller) {
12225
- return __awaiter(this, void 0, void 0, function* () {
12226
- yield next(controller);
12227
- });
12228
- },
12229
- start(controller) {
12230
- return __awaiter(this, void 0, void 0, function* () {
12231
- yield next(controller);
12232
- });
12233
- }
12234
- }, Object.assign({ "highWaterMark": Math.pow(2, 14) }, readableStrategy));
12235
- return { writable: new WritableStream(writer, writableStrategy), readable };
12236
- function next(controller) {
12237
- return __awaiter(this, void 0, void 0, function* () {
12238
- let buf = null;
12239
- let size = controller.desiredSize;
12240
- while (buf = yield reader.read(size || null)) {
12241
- controller.enqueue(buf);
12242
- if (size != null && (size -= buf.byteLength) <= 0) {
12243
- return;
12244
- }
12245
- }
12246
- controller.close();
12247
- });
12257
+ function makeArrayRowTable(table) {
12258
+ if (table.shape === "array-row-table") {
12259
+ return table;
12260
+ }
12261
+ const length = getTableLength(table);
12262
+ const data = new Array(length);
12263
+ for (let rowIndex = 0; rowIndex < length; rowIndex++) {
12264
+ data[rowIndex] = getTableRowAsArray(table, rowIndex);
12248
12265
  }
12266
+ return {
12267
+ shape: "array-row-table",
12268
+ schema: table.schema,
12269
+ data
12270
+ };
12249
12271
  }
12250
-
12251
- // ../../node_modules/apache-arrow/ipc/serialization.mjs
12252
- function tableFromIPC(input) {
12253
- const reader = RecordBatchReader.from(input);
12254
- if (isPromise(reader)) {
12255
- return reader.then((reader2) => tableFromIPC(reader2));
12272
+ function makeObjectRowTable(table) {
12273
+ if (table.shape === "object-row-table") {
12274
+ return table;
12256
12275
  }
12257
- if (reader.isAsync()) {
12258
- return reader.readAll().then((xs) => new Table(xs));
12276
+ const length = getTableLength(table);
12277
+ const data = new Array(length);
12278
+ for (let rowIndex = 0; rowIndex < length; rowIndex++) {
12279
+ data[rowIndex] = getTableRowAsObject(table, rowIndex);
12259
12280
  }
12260
- return new Table(reader.readAll());
12281
+ return {
12282
+ shape: "object-row-table",
12283
+ schema: table.schema,
12284
+ data
12285
+ };
12261
12286
  }
12262
12287
 
12263
- // ../../node_modules/apache-arrow/Arrow.mjs
12264
- var util = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, bn_exports), int_exports), bit_exports), math_exports), buffer_exports), vector_exports), pretty_exports), {
12265
- compareSchemas,
12266
- compareFields,
12267
- compareTypes
12268
- });
12269
-
12270
- // ../../node_modules/apache-arrow/Arrow.dom.mjs
12271
- adapters_default.toDOMStream = toDOMStream;
12272
- Builder2["throughDOM"] = builderThroughDOMStream;
12273
- RecordBatchReader["throughDOM"] = recordBatchReaderThroughDOMStream;
12274
- RecordBatchFileReader["throughDOM"] = recordBatchReaderThroughDOMStream;
12275
- RecordBatchStreamReader["throughDOM"] = recordBatchReaderThroughDOMStream;
12276
- RecordBatchWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12277
- RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12278
- RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12288
+ // ../gis/src/lib/geo/geoarrow-metadata.ts
12289
+ var GEOARROW_ENCODINGS = [
12290
+ "geoarrow.multipolygon",
12291
+ "geoarrow.polygon",
12292
+ "geoarrow.multilinestring",
12293
+ "geoarrow.linestring",
12294
+ "geoarrow.multipoint",
12295
+ "geoarrow.point",
12296
+ "geoarrow.wkb",
12297
+ "geoarrow.wkt"
12298
+ ];
12299
+ var GEOARROW_COLUMN_METADATA_ENCODING = "ARROW:extension:name";
12300
+ var GEOARROW_COLUMN_METADATA_METADATA = "ARROW:extension:metadata";
12301
+ function getGeometryColumnsFromSchema(schema) {
12302
+ const geometryColumns = {};
12303
+ for (const field of schema.fields) {
12304
+ const metadata = getGeometryMetadataForField(field);
12305
+ if (metadata) {
12306
+ geometryColumns[field.name] = metadata;
12307
+ }
12308
+ }
12309
+ return geometryColumns;
12310
+ }
12311
+ function getGeometryMetadataForField(field) {
12312
+ let metadata = null;
12313
+ let geoEncoding = field.metadata?.[GEOARROW_COLUMN_METADATA_ENCODING];
12314
+ if (geoEncoding) {
12315
+ geoEncoding = geoEncoding.toLowerCase();
12316
+ if (geoEncoding === "wkb") {
12317
+ geoEncoding = "geoarrow.wkb";
12318
+ }
12319
+ if (geoEncoding === "wkt") {
12320
+ geoEncoding = "geoarrow.wkt";
12321
+ }
12322
+ if (!GEOARROW_ENCODINGS.includes(geoEncoding)) {
12323
+ console.warn(`Invalid GeoArrow encoding: ${geoEncoding}`);
12324
+ } else {
12325
+ metadata = metadata || {};
12326
+ metadata.encoding = geoEncoding;
12327
+ }
12328
+ }
12329
+ const columnMetadata = field.metadata?.[GEOARROW_COLUMN_METADATA_METADATA];
12330
+ if (columnMetadata) {
12331
+ try {
12332
+ metadata = JSON.parse(columnMetadata);
12333
+ } catch (error) {
12334
+ console.warn("Failed to parse GeoArrow metadata", error);
12335
+ }
12336
+ }
12337
+ return metadata || null;
12338
+ }
12279
12339
 
12280
- // src/tables/convert-arrow-to-columnar-table.ts
12281
- function convertArrowToColumnarTable(table) {
12282
- const arrowTable = table.data;
12283
- const columnarTable = {};
12284
- for (const field of arrowTable.schema.fields) {
12285
- const arrowColumn = arrowTable.getChild(field.name);
12286
- const values = arrowColumn?.toArray();
12287
- columnarTable[field.name] = values;
12340
+ // ../gis/src/lib/binary-features/binary-to-geojson.ts
12341
+ function binaryToGeometry(data, startIndex, endIndex) {
12342
+ switch (data.type) {
12343
+ case "Point":
12344
+ return pointToGeoJson(data, startIndex, endIndex);
12345
+ case "LineString":
12346
+ return lineStringToGeoJson(data, startIndex, endIndex);
12347
+ case "Polygon":
12348
+ return polygonToGeoJson(data, startIndex, endIndex);
12349
+ default:
12350
+ const unexpectedInput = data;
12351
+ throw new Error(`Unsupported geometry type: ${unexpectedInput?.type}`);
12288
12352
  }
12289
- return {
12290
- shape: "columnar-table",
12291
- schema: table.schema,
12292
- data: columnarTable
12293
- };
12353
+ }
12354
+ function polygonToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
12355
+ const { positions } = data;
12356
+ const polygonIndices = data.polygonIndices.value.filter((x) => x >= startIndex && x <= endIndex);
12357
+ const primitivePolygonIndices = data.primitivePolygonIndices.value.filter(
12358
+ (x) => x >= startIndex && x <= endIndex
12359
+ );
12360
+ const multi = polygonIndices.length > 2;
12361
+ if (!multi) {
12362
+ const coordinates2 = [];
12363
+ for (let i = 0; i < primitivePolygonIndices.length - 1; i++) {
12364
+ const startRingIndex = primitivePolygonIndices[i];
12365
+ const endRingIndex = primitivePolygonIndices[i + 1];
12366
+ const ringCoordinates = ringToGeoJson(positions, startRingIndex, endRingIndex);
12367
+ coordinates2.push(ringCoordinates);
12368
+ }
12369
+ return { type: "Polygon", coordinates: coordinates2 };
12370
+ }
12371
+ const coordinates = [];
12372
+ for (let i = 0; i < polygonIndices.length - 1; i++) {
12373
+ const startPolygonIndex = polygonIndices[i];
12374
+ const endPolygonIndex = polygonIndices[i + 1];
12375
+ const polygonCoordinates = polygonToGeoJson(
12376
+ data,
12377
+ startPolygonIndex,
12378
+ endPolygonIndex
12379
+ ).coordinates;
12380
+ coordinates.push(polygonCoordinates);
12381
+ }
12382
+ return { type: "MultiPolygon", coordinates };
12383
+ }
12384
+ function lineStringToGeoJson(data, startIndex = -Infinity, endIndex = Infinity) {
12385
+ const { positions } = data;
12386
+ const pathIndices = data.pathIndices.value.filter((x) => x >= startIndex && x <= endIndex);
12387
+ const multi = pathIndices.length > 2;
12388
+ if (!multi) {
12389
+ const coordinates2 = ringToGeoJson(positions, pathIndices[0], pathIndices[1]);
12390
+ return { type: "LineString", coordinates: coordinates2 };
12391
+ }
12392
+ const coordinates = [];
12393
+ for (let i = 0; i < pathIndices.length - 1; i++) {
12394
+ const ringCoordinates = ringToGeoJson(positions, pathIndices[i], pathIndices[i + 1]);
12395
+ coordinates.push(ringCoordinates);
12396
+ }
12397
+ return { type: "MultiLineString", coordinates };
12398
+ }
12399
+ function pointToGeoJson(data, startIndex, endIndex) {
12400
+ const { positions } = data;
12401
+ const coordinates = ringToGeoJson(positions, startIndex, endIndex);
12402
+ const multi = coordinates.length > 1;
12403
+ if (multi) {
12404
+ return { type: "MultiPoint", coordinates };
12405
+ }
12406
+ return { type: "Point", coordinates: coordinates[0] };
12407
+ }
12408
+ function ringToGeoJson(positions, startIndex, endIndex) {
12409
+ startIndex = startIndex || 0;
12410
+ endIndex = endIndex || positions.value.length / positions.size;
12411
+ const ringCoordinates = [];
12412
+ for (let j = startIndex; j < endIndex; j++) {
12413
+ const coord = Array();
12414
+ for (let k = j * positions.size; k < (j + 1) * positions.size; k++) {
12415
+ coord.push(Number(positions.value[k]));
12416
+ }
12417
+ ringCoordinates.push(coord);
12418
+ }
12419
+ return ringCoordinates;
12294
12420
  }
12295
12421
 
12296
- // src/schema/convert-arrow-schema.ts
12422
+ // src/lib/tables/convert-arrow-schema.ts
12423
+ function convertArrowToSchema(arrowSchema) {
12424
+ return serializeArrowSchema(arrowSchema);
12425
+ }
12297
12426
  function serializeArrowSchema(arrowSchema) {
12298
12427
  return {
12299
12428
  fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
@@ -12463,32 +12592,845 @@ return true;`);
12463
12592
  }
12464
12593
  }
12465
12594
 
12466
- // src/parsers/parse-arrow-sync.ts
12467
- function parseArrowSync(arrayBuffer, options) {
12468
- const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
12469
- const arrowTable = {
12470
- shape: "arrow-table",
12471
- schema: serializeArrowSchema(apacheArrowTable.schema),
12472
- data: apacheArrowTable
12595
+ // ../wkt/src/lib/utils/version.ts
12596
+ var VERSION = true ? "4.3.0-beta.1" : "latest";
12597
+
12598
+ // ../wkt/src/lib/parse-wkt.ts
12599
+ var numberRegexp = /[-+]?([0-9]*\.[0-9]+|[0-9]+)([eE][-+]?[0-9]+)?/;
12600
+ var tuples = new RegExp("^" + numberRegexp.source + "(\\s" + numberRegexp.source + "){1,}");
12601
+ var WKT_MAGIC_STRINGS = [
12602
+ "POINT(",
12603
+ "LINESTRING(",
12604
+ "POLYGON(",
12605
+ "MULTIPOINT(",
12606
+ "MULTILINESTRING(",
12607
+ "MULTIPOLYGON(",
12608
+ "GEOMETRYCOLLECTION("
12609
+ // We only support this "geojson" subset of the OGC simple features standard
12610
+ ];
12611
+ function isWKT(input) {
12612
+ return WKT_MAGIC_STRINGS.some((magicString) => input.startsWith(magicString));
12613
+ }
12614
+ function parseWKT(input, options) {
12615
+ return parseWKTToGeometry(input, options);
12616
+ }
12617
+ function parseWKTToGeometry(input, options) {
12618
+ const parts = input.split(";");
12619
+ let _ = parts.pop();
12620
+ const srid = (parts.shift() || "").split("=").pop();
12621
+ const state = { parts, _, i: 0 };
12622
+ const geometry = parseGeometry(state);
12623
+ return options?.wkt?.crs ? addCRS(geometry, srid) : geometry;
12624
+ }
12625
+ function parseGeometry(state) {
12626
+ return parsePoint(state) || parseLineString(state) || parsePolygon(state) || parseMultiPoint(state) || parseMultiLineString(state) || parseMultiPolygon(state) || parseGeometryCollection(state);
12627
+ }
12628
+ function addCRS(obj, srid) {
12629
+ if (obj && srid?.match(/\d+/)) {
12630
+ const crs = {
12631
+ type: "name",
12632
+ properties: {
12633
+ name: "urn:ogc:def:crs:EPSG::" + srid
12634
+ }
12635
+ };
12636
+ obj.crs = crs;
12637
+ }
12638
+ return obj;
12639
+ }
12640
+ function parsePoint(state) {
12641
+ if (!$(/^(POINT(\sz)?)/i, state)) {
12642
+ return null;
12643
+ }
12644
+ white(state);
12645
+ if (!$(/^(\()/, state)) {
12646
+ return null;
12647
+ }
12648
+ const c = coords(state);
12649
+ if (!c) {
12650
+ return null;
12651
+ }
12652
+ white(state);
12653
+ if (!$(/^(\))/, state)) {
12654
+ return null;
12655
+ }
12656
+ return {
12657
+ type: "Point",
12658
+ coordinates: c[0]
12473
12659
  };
12474
- const shape = options?.shape || "arrow-table";
12660
+ }
12661
+ function parseMultiPoint(state) {
12662
+ if (!$(/^(MULTIPOINT)/i, state)) {
12663
+ return null;
12664
+ }
12665
+ white(state);
12666
+ const newCoordsFormat = state._?.substring(state._?.indexOf("(") + 1, state._.length - 1).replace(/\(/g, "").replace(/\)/g, "");
12667
+ state._ = "MULTIPOINT (" + newCoordsFormat + ")";
12668
+ const c = multicoords(state);
12669
+ if (!c) {
12670
+ return null;
12671
+ }
12672
+ white(state);
12673
+ return {
12674
+ type: "MultiPoint",
12675
+ coordinates: c
12676
+ };
12677
+ }
12678
+ function parseLineString(state) {
12679
+ if (!$(/^(LINESTRING(\sz)?)/i, state)) {
12680
+ return null;
12681
+ }
12682
+ white(state);
12683
+ if (!$(/^(\()/, state)) {
12684
+ return null;
12685
+ }
12686
+ const c = coords(state);
12687
+ if (!c) {
12688
+ return null;
12689
+ }
12690
+ if (!$(/^(\))/, state)) {
12691
+ return null;
12692
+ }
12693
+ return {
12694
+ type: "LineString",
12695
+ coordinates: c
12696
+ };
12697
+ }
12698
+ function parseMultiLineString(state) {
12699
+ if (!$(/^(MULTILINESTRING)/i, state))
12700
+ return null;
12701
+ white(state);
12702
+ const c = multicoords(state);
12703
+ if (!c) {
12704
+ return null;
12705
+ }
12706
+ white(state);
12707
+ return {
12708
+ // @ts-ignore
12709
+ type: "MultiLineString",
12710
+ // @ts-expect-error
12711
+ coordinates: c
12712
+ };
12713
+ }
12714
+ function parsePolygon(state) {
12715
+ if (!$(/^(POLYGON(\sz)?)/i, state)) {
12716
+ return null;
12717
+ }
12718
+ white(state);
12719
+ const c = multicoords(state);
12720
+ if (!c) {
12721
+ return null;
12722
+ }
12723
+ return {
12724
+ // @ts-ignore
12725
+ type: "Polygon",
12726
+ // @ts-expect-error
12727
+ coordinates: c
12728
+ };
12729
+ }
12730
+ function parseMultiPolygon(state) {
12731
+ if (!$(/^(MULTIPOLYGON)/i, state)) {
12732
+ return null;
12733
+ }
12734
+ white(state);
12735
+ const c = multicoords(state);
12736
+ if (!c) {
12737
+ return null;
12738
+ }
12739
+ return {
12740
+ type: "MultiPolygon",
12741
+ // @ts-expect-error
12742
+ coordinates: c
12743
+ };
12744
+ }
12745
+ function parseGeometryCollection(state) {
12746
+ const geometries = [];
12747
+ let geometry;
12748
+ if (!$(/^(GEOMETRYCOLLECTION)/i, state)) {
12749
+ return null;
12750
+ }
12751
+ white(state);
12752
+ if (!$(/^(\()/, state)) {
12753
+ return null;
12754
+ }
12755
+ while (geometry = parseGeometry(state)) {
12756
+ geometries.push(geometry);
12757
+ white(state);
12758
+ $(/^(,)/, state);
12759
+ white(state);
12760
+ }
12761
+ if (!$(/^(\))/, state)) {
12762
+ return null;
12763
+ }
12764
+ return {
12765
+ type: "GeometryCollection",
12766
+ geometries
12767
+ };
12768
+ }
12769
+ function multicoords(state) {
12770
+ white(state);
12771
+ let depth = 0;
12772
+ const rings = [];
12773
+ const stack = [rings];
12774
+ let pointer = rings;
12775
+ let elem;
12776
+ while (elem = $(/^(\()/, state) || $(/^(\))/, state) || $(/^(,)/, state) || $(tuples, state)) {
12777
+ if (elem === "(") {
12778
+ stack.push(pointer);
12779
+ pointer = [];
12780
+ stack[stack.length - 1].push(pointer);
12781
+ depth++;
12782
+ } else if (elem === ")") {
12783
+ if (pointer.length === 0)
12784
+ return null;
12785
+ pointer = stack.pop();
12786
+ if (!pointer)
12787
+ return null;
12788
+ depth--;
12789
+ if (depth === 0)
12790
+ break;
12791
+ } else if (elem === ",") {
12792
+ pointer = [];
12793
+ stack[stack.length - 1].push(pointer);
12794
+ } else if (!elem.split(/\s/g).some(isNaN)) {
12795
+ Array.prototype.push.apply(pointer, elem.split(/\s/g).map(parseFloat));
12796
+ } else {
12797
+ return null;
12798
+ }
12799
+ white(state);
12800
+ }
12801
+ if (depth !== 0)
12802
+ return null;
12803
+ return rings;
12804
+ }
12805
+ function coords(state) {
12806
+ const list = [];
12807
+ let item;
12808
+ let pt;
12809
+ while (pt = $(tuples, state) || $(/^(,)/, state)) {
12810
+ if (pt === ",") {
12811
+ list.push(item);
12812
+ item = [];
12813
+ } else if (!pt.split(/\s/g).some(isNaN)) {
12814
+ if (!item)
12815
+ item = [];
12816
+ Array.prototype.push.apply(item, pt.split(/\s/g).map(parseFloat));
12817
+ }
12818
+ white(state);
12819
+ }
12820
+ if (item)
12821
+ list.push(item);
12822
+ else
12823
+ return null;
12824
+ return list.length ? list : null;
12825
+ }
12826
+ function $(regexp, state) {
12827
+ const match = state._?.substring(state.i).match(regexp);
12828
+ if (!match)
12829
+ return null;
12830
+ else {
12831
+ state.i += match[0].length;
12832
+ return match[0];
12833
+ }
12834
+ }
12835
+ function white(state) {
12836
+ $(/^\s*/, state);
12837
+ }
12838
+
12839
+ // ../wkt/src/wkt-loader.ts
12840
+ var WKTWorkerLoader = {
12841
+ dataType: null,
12842
+ batchType: null,
12843
+ name: "WKT (Well-Known Text)",
12844
+ id: "wkt",
12845
+ module: "wkt",
12846
+ version: VERSION,
12847
+ worker: true,
12848
+ extensions: ["wkt"],
12849
+ mimeTypes: ["text/plain"],
12850
+ category: "geometry",
12851
+ text: true,
12852
+ tests: WKT_MAGIC_STRINGS,
12853
+ testText: isWKT,
12854
+ options: {
12855
+ wkt: {
12856
+ shape: "geojson-geometry",
12857
+ crs: true
12858
+ }
12859
+ }
12860
+ };
12861
+ var WKTLoader = {
12862
+ ...WKTWorkerLoader,
12863
+ parse: async (arrayBuffer, options) => parseWKT(new TextDecoder().decode(arrayBuffer), options),
12864
+ parseTextSync: (string, options) => parseWKT(string, options)
12865
+ };
12866
+
12867
+ // ../wkt/src/lib/parse-wkb-header.ts
12868
+ var EWKB_FLAG_Z = 2147483648;
12869
+ var EWKB_FLAG_M = 1073741824;
12870
+ var EWKB_FLAG_SRID = 536870912;
12871
+ var MAX_SRID = 1e4;
12872
+ function isWKB(arrayBuffer) {
12873
+ const dataView = new DataView(arrayBuffer);
12874
+ let byteOffset = 0;
12875
+ const endianness = dataView.getUint8(byteOffset);
12876
+ byteOffset += 1;
12877
+ if (endianness > 1) {
12878
+ return false;
12879
+ }
12880
+ const littleEndian = endianness === 1;
12881
+ const geometry = dataView.getUint32(byteOffset, littleEndian);
12882
+ byteOffset += 4;
12883
+ const geometryType = geometry & 7;
12884
+ if (geometryType === 0 || geometryType > 7) {
12885
+ return false;
12886
+ }
12887
+ const geometryFlags = geometry - geometryType;
12888
+ if (geometryFlags === 0 || geometryFlags === 1e3 || geometryFlags === 2e3 || geometryFlags === 3e3) {
12889
+ return true;
12890
+ }
12891
+ if ((geometryFlags & ~(EWKB_FLAG_Z | EWKB_FLAG_M | EWKB_FLAG_SRID)) !== 0) {
12892
+ return false;
12893
+ }
12894
+ if (geometryFlags & EWKB_FLAG_SRID) {
12895
+ const srid = dataView.getUint32(byteOffset, littleEndian);
12896
+ byteOffset += 4;
12897
+ if (srid > MAX_SRID) {
12898
+ return false;
12899
+ }
12900
+ }
12901
+ return true;
12902
+ }
12903
+ function parseWKBHeader(dataView, target) {
12904
+ const wkbHeader = Object.assign(target || {}, {
12905
+ type: "wkb",
12906
+ geometryType: 1,
12907
+ dimensions: 2,
12908
+ coordinates: "xy",
12909
+ littleEndian: true,
12910
+ byteOffset: 0
12911
+ });
12912
+ wkbHeader.littleEndian = dataView.getUint8(wkbHeader.byteOffset) === 1;
12913
+ wkbHeader.byteOffset++;
12914
+ const geometryCode = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
12915
+ wkbHeader.byteOffset += 4;
12916
+ wkbHeader.geometryType = geometryCode & 7;
12917
+ const isoType = (geometryCode - wkbHeader.geometryType) / 1e3;
12918
+ switch (isoType) {
12919
+ case 0:
12920
+ break;
12921
+ case 1:
12922
+ wkbHeader.type = "iso-wkb";
12923
+ wkbHeader.dimensions = 3;
12924
+ wkbHeader.coordinates = "xyz";
12925
+ break;
12926
+ case 2:
12927
+ wkbHeader.type = "iso-wkb";
12928
+ wkbHeader.dimensions = 3;
12929
+ wkbHeader.coordinates = "xym";
12930
+ break;
12931
+ case 3:
12932
+ wkbHeader.type = "iso-wkb";
12933
+ wkbHeader.dimensions = 4;
12934
+ wkbHeader.coordinates = "xyzm";
12935
+ break;
12936
+ default:
12937
+ throw new Error(`WKB: Unsupported iso-wkb type: ${isoType}`);
12938
+ }
12939
+ const ewkbZ = geometryCode & EWKB_FLAG_Z;
12940
+ const ewkbM = geometryCode & EWKB_FLAG_M;
12941
+ const ewkbSRID = geometryCode & EWKB_FLAG_SRID;
12942
+ if (ewkbZ && ewkbM) {
12943
+ wkbHeader.type = "ewkb";
12944
+ wkbHeader.dimensions = 4;
12945
+ wkbHeader.coordinates = "xyzm";
12946
+ } else if (ewkbZ) {
12947
+ wkbHeader.type = "ewkb";
12948
+ wkbHeader.dimensions = 3;
12949
+ wkbHeader.coordinates = "xyz";
12950
+ } else if (ewkbM) {
12951
+ wkbHeader.type = "ewkb";
12952
+ wkbHeader.dimensions = 3;
12953
+ wkbHeader.coordinates = "xym";
12954
+ }
12955
+ if (ewkbSRID) {
12956
+ wkbHeader.type = "ewkb";
12957
+ wkbHeader.srid = dataView.getUint32(wkbHeader.byteOffset, wkbHeader.littleEndian);
12958
+ wkbHeader.byteOffset += 4;
12959
+ }
12960
+ return wkbHeader;
12961
+ }
12962
+
12963
+ // ../wkt/src/lib/parse-wkb.ts
12964
+ function parseWKB(arrayBuffer, options) {
12965
+ const binaryGeometry = parseWKBToBinary(arrayBuffer, options);
12966
+ const shape = options?.wkb?.shape || "binary-geometry";
12967
+ switch (shape) {
12968
+ case "binary-geometry":
12969
+ return binaryGeometry;
12970
+ case "geojson-geometry":
12971
+ return binaryToGeometry(binaryGeometry);
12972
+ case "geometry":
12973
+ console.error('WKBLoader: "geometry" shape is deprecated, use "binary-geometry" instead');
12974
+ return binaryToGeometry(binaryGeometry);
12975
+ default:
12976
+ throw new Error(shape);
12977
+ }
12978
+ }
12979
+ function parseWKBToBinary(arrayBuffer, options) {
12980
+ const dataView = new DataView(arrayBuffer);
12981
+ const wkbHeader = parseWKBHeader(dataView);
12982
+ const { geometryType, dimensions, littleEndian } = wkbHeader;
12983
+ const offset = wkbHeader.byteOffset;
12984
+ switch (geometryType) {
12985
+ case 1 /* Point */:
12986
+ const point = parsePoint2(dataView, offset, dimensions, littleEndian);
12987
+ return point.geometry;
12988
+ case 2 /* LineString */:
12989
+ const line = parseLineString2(dataView, offset, dimensions, littleEndian);
12990
+ return line.geometry;
12991
+ case 3 /* Polygon */:
12992
+ const polygon = parsePolygon2(dataView, offset, dimensions, littleEndian);
12993
+ return polygon.geometry;
12994
+ case 4 /* MultiPoint */:
12995
+ const multiPoint = parseMultiPoint2(dataView, offset, dimensions, littleEndian);
12996
+ multiPoint.type = "Point";
12997
+ return multiPoint;
12998
+ case 5 /* MultiLineString */:
12999
+ const multiLine = parseMultiLineString2(dataView, offset, dimensions, littleEndian);
13000
+ multiLine.type = "LineString";
13001
+ return multiLine;
13002
+ case 6 /* MultiPolygon */:
13003
+ const multiPolygon = parseMultiPolygon2(dataView, offset, dimensions, littleEndian);
13004
+ multiPolygon.type = "Polygon";
13005
+ return multiPolygon;
13006
+ default:
13007
+ throw new Error(`WKB: Unsupported geometry type: ${geometryType}`);
13008
+ }
13009
+ }
13010
+ function parsePoint2(dataView, offset, dimension, littleEndian) {
13011
+ const positions = new Float64Array(dimension);
13012
+ for (let i = 0; i < dimension; i++) {
13013
+ positions[i] = dataView.getFloat64(offset, littleEndian);
13014
+ offset += 8;
13015
+ }
13016
+ return {
13017
+ geometry: { type: "Point", positions: { value: positions, size: dimension } },
13018
+ offset
13019
+ };
13020
+ }
13021
+ function parseLineString2(dataView, offset, dimension, littleEndian) {
13022
+ const nPoints = dataView.getUint32(offset, littleEndian);
13023
+ offset += 4;
13024
+ const positions = new Float64Array(nPoints * dimension);
13025
+ for (let i = 0; i < nPoints * dimension; i++) {
13026
+ positions[i] = dataView.getFloat64(offset, littleEndian);
13027
+ offset += 8;
13028
+ }
13029
+ const pathIndices = [0];
13030
+ if (nPoints > 0) {
13031
+ pathIndices.push(nPoints);
13032
+ }
13033
+ return {
13034
+ geometry: {
13035
+ type: "LineString",
13036
+ positions: { value: positions, size: dimension },
13037
+ pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
13038
+ },
13039
+ offset
13040
+ };
13041
+ }
13042
+ var cumulativeSum = (sum) => (value) => sum += value;
13043
+ function parsePolygon2(dataView, offset, dimension, littleEndian) {
13044
+ const nRings = dataView.getUint32(offset, littleEndian);
13045
+ offset += 4;
13046
+ const rings = [];
13047
+ for (let i = 0; i < nRings; i++) {
13048
+ const parsed = parseLineString2(dataView, offset, dimension, littleEndian);
13049
+ const { positions } = parsed.geometry;
13050
+ offset = parsed.offset;
13051
+ rings.push(positions.value);
13052
+ }
13053
+ const concatenatedPositions = new Float64Array(concatTypedArrays(rings).buffer);
13054
+ const polygonIndices = [0];
13055
+ if (concatenatedPositions.length > 0) {
13056
+ polygonIndices.push(concatenatedPositions.length / dimension);
13057
+ }
13058
+ const primitivePolygonIndices = rings.map((l) => l.length / dimension).map(cumulativeSum(0));
13059
+ primitivePolygonIndices.unshift(0);
13060
+ return {
13061
+ geometry: {
13062
+ type: "Polygon",
13063
+ positions: { value: concatenatedPositions, size: dimension },
13064
+ polygonIndices: {
13065
+ value: new Uint32Array(polygonIndices),
13066
+ size: 1
13067
+ },
13068
+ primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
13069
+ },
13070
+ offset
13071
+ };
13072
+ }
13073
+ function parseMultiPoint2(dataView, offset, dimension, littleEndian) {
13074
+ const nPoints = dataView.getUint32(offset, littleEndian);
13075
+ offset += 4;
13076
+ const binaryPointGeometries = [];
13077
+ for (let i = 0; i < nPoints; i++) {
13078
+ const littleEndianPoint = dataView.getUint8(offset) === 1;
13079
+ offset++;
13080
+ if (dataView.getUint32(offset, littleEndianPoint) % 1e3 !== 1) {
13081
+ throw new Error("WKB: Inner geometries of MultiPoint not of type Point");
13082
+ }
13083
+ offset += 4;
13084
+ const parsed = parsePoint2(dataView, offset, dimension, littleEndianPoint);
13085
+ offset = parsed.offset;
13086
+ binaryPointGeometries.push(parsed.geometry);
13087
+ }
13088
+ return concatenateBinaryPointGeometries(binaryPointGeometries, dimension);
13089
+ }
13090
+ function parseMultiLineString2(dataView, offset, dimension, littleEndian) {
13091
+ const nLines = dataView.getUint32(offset, littleEndian);
13092
+ offset += 4;
13093
+ const binaryLineGeometries = [];
13094
+ for (let i = 0; i < nLines; i++) {
13095
+ const littleEndianLine = dataView.getUint8(offset) === 1;
13096
+ offset++;
13097
+ if (dataView.getUint32(offset, littleEndianLine) % 1e3 !== 2) {
13098
+ throw new Error("WKB: Inner geometries of MultiLineString not of type LineString");
13099
+ }
13100
+ offset += 4;
13101
+ const parsed = parseLineString2(dataView, offset, dimension, littleEndianLine);
13102
+ offset = parsed.offset;
13103
+ binaryLineGeometries.push(parsed.geometry);
13104
+ }
13105
+ return concatenateBinaryLineGeometries(binaryLineGeometries, dimension);
13106
+ }
13107
+ function parseMultiPolygon2(dataView, offset, dimension, littleEndian) {
13108
+ const nPolygons = dataView.getUint32(offset, littleEndian);
13109
+ offset += 4;
13110
+ const binaryPolygonGeometries = [];
13111
+ for (let i = 0; i < nPolygons; i++) {
13112
+ const littleEndianPolygon = dataView.getUint8(offset) === 1;
13113
+ offset++;
13114
+ if (dataView.getUint32(offset, littleEndianPolygon) % 1e3 !== 3) {
13115
+ throw new Error("WKB: Inner geometries of MultiPolygon not of type Polygon");
13116
+ }
13117
+ offset += 4;
13118
+ const parsed = parsePolygon2(dataView, offset, dimension, littleEndianPolygon);
13119
+ offset = parsed.offset;
13120
+ binaryPolygonGeometries.push(parsed.geometry);
13121
+ }
13122
+ return concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension);
13123
+ }
13124
+ function concatenateBinaryPointGeometries(binaryPointGeometries, dimension) {
13125
+ const positions = binaryPointGeometries.map((geometry) => geometry.positions.value);
13126
+ const concatenatedPositions = new Float64Array(concatTypedArrays(positions).buffer);
13127
+ return {
13128
+ type: "Point",
13129
+ positions: { value: concatenatedPositions, size: dimension }
13130
+ };
13131
+ }
13132
+ function concatenateBinaryLineGeometries(binaryLineGeometries, dimension) {
13133
+ const lines = binaryLineGeometries.map((geometry) => geometry.positions.value);
13134
+ const concatenatedPositions = new Float64Array(concatTypedArrays(lines).buffer);
13135
+ const pathIndices = lines.map((line) => line.length / dimension).map(cumulativeSum(0));
13136
+ pathIndices.unshift(0);
13137
+ return {
13138
+ type: "LineString",
13139
+ positions: { value: concatenatedPositions, size: dimension },
13140
+ pathIndices: { value: new Uint32Array(pathIndices), size: 1 }
13141
+ };
13142
+ }
13143
+ function concatenateBinaryPolygonGeometries(binaryPolygonGeometries, dimension) {
13144
+ const polygons = [];
13145
+ const primitivePolygons = [];
13146
+ for (const binaryPolygon of binaryPolygonGeometries) {
13147
+ const { positions, primitivePolygonIndices: primitivePolygonIndices2 } = binaryPolygon;
13148
+ polygons.push(positions.value);
13149
+ primitivePolygons.push(primitivePolygonIndices2.value);
13150
+ }
13151
+ const concatenatedPositions = new Float64Array(concatTypedArrays(polygons).buffer);
13152
+ const polygonIndices = polygons.map((p) => p.length / dimension).map(cumulativeSum(0));
13153
+ polygonIndices.unshift(0);
13154
+ const primitivePolygonIndices = [0];
13155
+ for (const primitivePolygon of primitivePolygons) {
13156
+ primitivePolygonIndices.push(
13157
+ ...primitivePolygon.filter((x) => x > 0).map((x) => x + primitivePolygonIndices[primitivePolygonIndices.length - 1])
13158
+ );
13159
+ }
13160
+ return {
13161
+ type: "Polygon",
13162
+ positions: { value: concatenatedPositions, size: dimension },
13163
+ polygonIndices: { value: new Uint32Array(polygonIndices), size: 1 },
13164
+ primitivePolygonIndices: { value: new Uint32Array(primitivePolygonIndices), size: 1 }
13165
+ };
13166
+ }
13167
+ function concatTypedArrays(arrays) {
13168
+ let byteLength = 0;
13169
+ for (let i = 0; i < arrays.length; ++i) {
13170
+ byteLength += arrays[i].byteLength;
13171
+ }
13172
+ const buffer = new Uint8Array(byteLength);
13173
+ let byteOffset = 0;
13174
+ for (let i = 0; i < arrays.length; ++i) {
13175
+ const data = new Uint8Array(arrays[i].buffer);
13176
+ byteLength = data.length;
13177
+ for (let j = 0; j < byteLength; ++j) {
13178
+ buffer[byteOffset++] = data[j];
13179
+ }
13180
+ }
13181
+ return buffer;
13182
+ }
13183
+
13184
+ // ../wkt/src/wkb-loader.ts
13185
+ var WKBWorkerLoader = {
13186
+ dataType: null,
13187
+ batchType: null,
13188
+ name: "WKB",
13189
+ id: "wkb",
13190
+ module: "wkt",
13191
+ version: VERSION,
13192
+ worker: true,
13193
+ category: "geometry",
13194
+ extensions: ["wkb"],
13195
+ mimeTypes: [],
13196
+ // TODO can we define static, serializable tests, eg. some binary strings?
13197
+ tests: [isWKB],
13198
+ options: {
13199
+ wkb: {
13200
+ shape: "binary-geometry"
13201
+ // 'geojson-geometry'
13202
+ }
13203
+ }
13204
+ };
13205
+ var WKBLoader = {
13206
+ ...WKBWorkerLoader,
13207
+ parse: async (arrayBuffer) => parseWKB(arrayBuffer),
13208
+ parseSync: parseWKB
13209
+ };
13210
+
13211
+ // src/lib/geoarrow/convert-geoarrow-to-geojson-geometry.ts
13212
+ function parseGeometryFromArrow(arrowCellValue, encoding) {
13213
+ encoding = encoding?.toLowerCase();
13214
+ if (!encoding || !arrowCellValue) {
13215
+ return null;
13216
+ }
13217
+ let geometry;
13218
+ switch (encoding) {
13219
+ case "geoarrow.multipolygon":
13220
+ geometry = arrowMultiPolygonToFeature(arrowCellValue);
13221
+ break;
13222
+ case "geoarrow.polygon":
13223
+ geometry = arrowPolygonToFeature(arrowCellValue);
13224
+ break;
13225
+ case "geoarrow.multipoint":
13226
+ geometry = arrowMultiPointToFeature(arrowCellValue);
13227
+ break;
13228
+ case "geoarrow.point":
13229
+ geometry = arrowPointToFeature(arrowCellValue);
13230
+ break;
13231
+ case "geoarrow.multilinestring":
13232
+ geometry = arrowMultiLineStringToFeature(arrowCellValue);
13233
+ break;
13234
+ case "geoarrow.linestring":
13235
+ geometry = arrowLineStringToFeature(arrowCellValue);
13236
+ break;
13237
+ case "geoarrow.wkb":
13238
+ geometry = arrowWKBToFeature(arrowCellValue);
13239
+ break;
13240
+ case "geoarrow.wkt":
13241
+ geometry = arrowWKTToFeature(arrowCellValue);
13242
+ break;
13243
+ default: {
13244
+ throw Error(`GeoArrow encoding not supported ${encoding}`);
13245
+ }
13246
+ }
13247
+ return geometry;
13248
+ }
13249
+ function arrowWKBToFeature(arrowCellValue) {
13250
+ const arrayBuffer = arrowCellValue.buffer.slice(
13251
+ arrowCellValue.byteOffset,
13252
+ arrowCellValue.byteOffset + arrowCellValue.byteLength
13253
+ );
13254
+ const binaryGeometry = WKBLoader.parseSync?.(arrayBuffer);
13255
+ const geometry = binaryToGeometry(binaryGeometry);
13256
+ return geometry;
13257
+ }
13258
+ function arrowWKTToFeature(arrowCellValue) {
13259
+ const string = arrowCellValue;
13260
+ return WKTLoader.parseTextSync?.(string);
13261
+ }
13262
+ function arrowMultiPolygonToFeature(arrowMultiPolygon) {
13263
+ const multiPolygon = [];
13264
+ for (let m = 0; m < arrowMultiPolygon.length; m++) {
13265
+ const arrowPolygon = arrowMultiPolygon.get(m);
13266
+ const polygon = [];
13267
+ for (let i = 0; arrowPolygon && i < arrowPolygon?.length; i++) {
13268
+ const arrowRing = arrowPolygon?.get(i);
13269
+ const ring = [];
13270
+ for (let j = 0; arrowRing && j < arrowRing.length; j++) {
13271
+ const arrowCoord = arrowRing.get(j);
13272
+ const coord = Array.from(arrowCoord);
13273
+ ring.push(coord);
13274
+ }
13275
+ polygon.push(ring);
13276
+ }
13277
+ multiPolygon.push(polygon);
13278
+ }
13279
+ const geometry = {
13280
+ type: "MultiPolygon",
13281
+ coordinates: multiPolygon
13282
+ };
13283
+ return geometry;
13284
+ }
13285
+ function arrowPolygonToFeature(arrowPolygon) {
13286
+ const polygon = [];
13287
+ for (let i = 0; arrowPolygon && i < arrowPolygon.length; i++) {
13288
+ const arrowRing = arrowPolygon.get(i);
13289
+ const ring = [];
13290
+ for (let j = 0; arrowRing && j < arrowRing.length; j++) {
13291
+ const arrowCoord = arrowRing.get(j);
13292
+ const coords2 = Array.from(arrowCoord);
13293
+ ring.push(coords2);
13294
+ }
13295
+ polygon.push(ring);
13296
+ }
13297
+ const geometry = {
13298
+ type: "Polygon",
13299
+ coordinates: polygon
13300
+ };
13301
+ return geometry;
13302
+ }
13303
+ function arrowMultiPointToFeature(arrowMultiPoint) {
13304
+ const multiPoint = [];
13305
+ for (let i = 0; arrowMultiPoint && i < arrowMultiPoint.length; i++) {
13306
+ const arrowPoint = arrowMultiPoint.get(i);
13307
+ if (arrowPoint) {
13308
+ const coord = Array.from(arrowPoint);
13309
+ multiPoint.push(coord);
13310
+ }
13311
+ }
13312
+ return {
13313
+ type: "MultiPoint",
13314
+ coordinates: multiPoint
13315
+ };
13316
+ }
13317
+ function arrowPointToFeature(arrowPoint) {
13318
+ const point = Array.from(arrowPoint);
13319
+ return {
13320
+ type: "Point",
13321
+ coordinates: point
13322
+ };
13323
+ }
13324
+ function arrowMultiLineStringToFeature(arrowMultiLineString) {
13325
+ const multiLineString = [];
13326
+ for (let i = 0; arrowMultiLineString && i < arrowMultiLineString.length; i++) {
13327
+ const arrowLineString = arrowMultiLineString.get(i);
13328
+ const lineString = [];
13329
+ for (let j = 0; arrowLineString && j < arrowLineString.length; j++) {
13330
+ const arrowCoord = arrowLineString.get(j);
13331
+ if (arrowCoord) {
13332
+ const coords2 = Array.from(arrowCoord);
13333
+ lineString.push(coords2);
13334
+ }
13335
+ }
13336
+ multiLineString.push(lineString);
13337
+ }
13338
+ return {
13339
+ type: "MultiLineString",
13340
+ coordinates: multiLineString
13341
+ };
13342
+ }
13343
+ function arrowLineStringToFeature(arrowLineString) {
13344
+ const lineString = [];
13345
+ for (let i = 0; arrowLineString && i < arrowLineString.length; i++) {
13346
+ const arrowCoord = arrowLineString.get(i);
13347
+ if (arrowCoord) {
13348
+ const coords2 = Array.from(arrowCoord);
13349
+ lineString.push(coords2);
13350
+ }
13351
+ }
13352
+ return {
13353
+ type: "LineString",
13354
+ coordinates: lineString
13355
+ };
13356
+ }
13357
+
13358
+ // src/lib/tables/convert-arrow-to-table.ts
13359
+ function convertArrowToTable(arrowTable, shape) {
12475
13360
  switch (shape) {
12476
13361
  case "arrow-table":
12477
- return arrowTable;
13362
+ return convertArrowToArrowTable(arrowTable);
13363
+ case "array-row-table":
13364
+ return convertArrowToArrayRowTable(arrowTable);
13365
+ case "object-row-table":
13366
+ return convertArrowToObjectRowTable(arrowTable);
12478
13367
  case "columnar-table":
12479
13368
  return convertArrowToColumnarTable(arrowTable);
12480
- case "object-row-table":
12481
- let columnarTable = convertArrowToColumnarTable(arrowTable);
12482
- return convertTable(columnarTable, "object-row-table");
12483
- case "array-row-table":
12484
- columnarTable = convertArrowToColumnarTable(arrowTable);
12485
- return convertTable(columnarTable, "array-row-table");
13369
+ case "geojson-table":
13370
+ return convertArrowToGeoJSONTable(arrowTable);
12486
13371
  default:
12487
13372
  throw new Error(shape);
12488
13373
  }
12489
13374
  }
13375
+ function convertArrowToArrowTable(arrowTable) {
13376
+ return {
13377
+ shape: "arrow-table",
13378
+ schema: convertArrowToSchema(arrowTable.schema),
13379
+ data: arrowTable
13380
+ };
13381
+ }
13382
+ function convertArrowToArrayRowTable(arrowTable) {
13383
+ const columnarTable = convertArrowToColumnarTable(arrowTable);
13384
+ return convertTable(columnarTable, "array-row-table");
13385
+ }
13386
+ function convertArrowToObjectRowTable(arrowTable) {
13387
+ const columnarTable = convertArrowToColumnarTable(arrowTable);
13388
+ return convertTable(columnarTable, "object-row-table");
13389
+ }
13390
+ function convertArrowToColumnarTable(arrowTable) {
13391
+ const columns = {};
13392
+ for (const field of arrowTable.schema.fields) {
13393
+ const arrowColumn = arrowTable.getChild(field.name);
13394
+ const values = arrowColumn?.toArray();
13395
+ columns[field.name] = values;
13396
+ }
13397
+ const schema = convertArrowToSchema(arrowTable.schema);
13398
+ return {
13399
+ shape: "columnar-table",
13400
+ schema,
13401
+ data: columns
13402
+ };
13403
+ }
13404
+ function convertArrowToGeoJSONTable(arrowTable) {
13405
+ const schema = convertArrowToSchema(arrowTable.schema);
13406
+ const geometryColumns = getGeometryColumnsFromSchema(schema);
13407
+ const encoding = geometryColumns.geometry.encoding;
13408
+ const features = [];
13409
+ const propertyColumnNames = arrowTable.schema.fields.map((field) => field.name).filter((name) => !(name in geometryColumns));
13410
+ const propertiesTable = arrowTable.select(propertyColumnNames);
13411
+ const arrowGeometryColumn = arrowTable.getChild("geometry");
13412
+ for (let row = 0; row < arrowTable.numRows; row++) {
13413
+ const arrowGeometry = arrowGeometryColumn?.get(row);
13414
+ const feature = parseGeometryFromArrow(arrowGeometry, encoding);
13415
+ if (feature) {
13416
+ const properties = propertiesTable.get(row)?.toJSON() || {};
13417
+ features.push({ type: "Feature", geometry: feature, properties });
13418
+ }
13419
+ }
13420
+ return {
13421
+ shape: "geojson-table",
13422
+ type: "FeatureCollection",
13423
+ schema,
13424
+ features
13425
+ };
13426
+ }
12490
13427
 
12491
- // src/parsers/parse-arrow-in-batches.ts
13428
+ // src/lib/parsers/parse-arrow.ts
13429
+ function parseArrowSync(arrayBuffer, options) {
13430
+ const shape = options?.shape || "arrow-table";
13431
+ const arrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
13432
+ return convertArrowToTable(arrowTable, shape);
13433
+ }
12492
13434
  function parseArrowInBatches(asyncIterator, options) {
12493
13435
  async function* makeArrowAsyncIterator() {
12494
13436
  const readers = RecordBatchReader.readAll(asyncIterator);
@@ -12511,15 +13453,15 @@ return true;`);
12511
13453
  return makeArrowAsyncIterator();
12512
13454
  }
12513
13455
 
12514
- // src/arrow-loader.ts
12515
- var VERSION = true ? "4.3.0-alpha.7" : "latest";
13456
+ // src/exports/arrow-loader.ts
13457
+ var VERSION2 = true ? "4.3.0-beta.1" : "latest";
12516
13458
  var ArrowWorkerLoader = {
12517
13459
  dataType: null,
12518
13460
  batchType: null,
12519
13461
  name: "Apache Arrow",
12520
13462
  id: "arrow",
12521
13463
  module: "arrow",
12522
- version: VERSION,
13464
+ version: VERSION2,
12523
13465
  // worker: true,
12524
13466
  category: "table",
12525
13467
  extensions: ["arrow", "feather"],
@@ -12536,6 +13478,8 @@ return true;`);
12536
13478
  }
12537
13479
  }
12538
13480
  };
13481
+
13482
+ // src/arrow-loader.ts
12539
13483
  var ArrowLoader = {
12540
13484
  ...ArrowWorkerLoader,
12541
13485
  parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),