@loaders.gl/schema 4.3.2 → 4.4.0-alpha.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 (163) hide show
  1. package/dist/categories/category-gis.d.ts +6 -0
  2. package/dist/categories/category-gis.d.ts.map +1 -0
  3. package/dist/categories/category-image.d.ts.map +1 -0
  4. package/dist/{types → categories}/category-mesh.d.ts +2 -2
  5. package/dist/categories/category-mesh.d.ts.map +1 -0
  6. package/dist/{types → categories}/category-table.d.ts +14 -14
  7. package/dist/categories/category-table.d.ts.map +1 -0
  8. package/dist/categories/category-texture.d.ts.map +1 -0
  9. package/dist/{lib/mesh → deprecated}/mesh-utils.d.ts +4 -2
  10. package/dist/deprecated/mesh-utils.d.ts.map +1 -0
  11. package/dist/{lib/mesh → deprecated}/mesh-utils.js +2 -0
  12. package/dist/dist.dev.js +0 -1836
  13. package/dist/dist.min.js +1 -1
  14. package/dist/geometry/binary-features.d.ts +30 -0
  15. package/dist/geometry/binary-features.d.ts.map +1 -0
  16. package/dist/geometry/binary-geometries.d.ts +33 -0
  17. package/dist/geometry/binary-geometries.d.ts.map +1 -0
  18. package/dist/geometry/flat-geometries.d.ts +61 -0
  19. package/dist/geometry/flat-geometries.d.ts.map +1 -0
  20. package/dist/index.cjs +2 -1792
  21. package/dist/index.cjs.map +4 -4
  22. package/dist/index.d.ts +10 -28
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +3 -23
  25. package/dist/types/batch.d.ts +3 -1
  26. package/dist/types/batch.d.ts.map +1 -1
  27. package/package.json +5 -4
  28. package/src/{types → categories}/category-gis.ts +7 -18
  29. package/src/{types → categories}/category-mesh.ts +2 -2
  30. package/src/{types → categories}/category-table.ts +14 -17
  31. package/src/{lib/mesh → deprecated}/mesh-utils.ts +4 -2
  32. package/src/geometry/binary-features.ts +43 -0
  33. package/src/geometry/binary-geometries.ts +45 -0
  34. package/src/{types → geometry}/flat-geometries.ts +44 -14
  35. package/src/index.ts +15 -101
  36. package/src/types/batch.ts +3 -1
  37. package/dist/lib/mesh/convert-mesh.d.ts +0 -15
  38. package/dist/lib/mesh/convert-mesh.d.ts.map +0 -1
  39. package/dist/lib/mesh/convert-mesh.js +0 -37
  40. package/dist/lib/mesh/deduce-mesh-schema.d.ts +0 -24
  41. package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +0 -1
  42. package/dist/lib/mesh/deduce-mesh-schema.js +0 -62
  43. package/dist/lib/mesh/mesh-to-arrow-table.d.ts +0 -1
  44. package/dist/lib/mesh/mesh-to-arrow-table.d.ts.map +0 -1
  45. package/dist/lib/mesh/mesh-to-arrow-table.js +0 -47
  46. package/dist/lib/mesh/mesh-utils.d.ts.map +0 -1
  47. package/dist/lib/table/arrow-api/arrow-like-field.d.ts +0 -19
  48. package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +0 -1
  49. package/dist/lib/table/arrow-api/arrow-like-field.js +0 -36
  50. package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +0 -43
  51. package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +0 -1
  52. package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +0 -12
  53. package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +0 -1
  54. package/dist/lib/table/arrow-api/arrow-like-schema.js +0 -81
  55. package/dist/lib/table/arrow-api/arrow-like-table.d.ts +0 -24
  56. package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +0 -1
  57. package/dist/lib/table/arrow-api/arrow-like-table.js +0 -63
  58. package/dist/lib/table/arrow-api/arrow-like-type.d.ts +0 -177
  59. package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +0 -1
  60. package/dist/lib/table/arrow-api/arrow-like-type.js +0 -442
  61. package/dist/lib/table/arrow-api/enum.d.ts +0 -92
  62. package/dist/lib/table/arrow-api/enum.d.ts.map +0 -1
  63. package/dist/lib/table/arrow-api/enum.js +0 -97
  64. package/dist/lib/table/arrow-api/get-type-info.d.ts +0 -13
  65. package/dist/lib/table/arrow-api/get-type-info.d.ts.map +0 -1
  66. package/dist/lib/table/arrow-api/get-type-info.js +0 -27
  67. package/dist/lib/table/arrow-api/index.d.ts +0 -5
  68. package/dist/lib/table/arrow-api/index.d.ts.map +0 -1
  69. package/dist/lib/table/arrow-api/index.js +0 -7
  70. package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +0 -20
  71. package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +0 -1
  72. package/dist/lib/table/batches/base-table-batch-aggregator.js +0 -63
  73. package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts +0 -23
  74. package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +0 -1
  75. package/dist/lib/table/batches/columnar-table-batch-aggregator.js +0 -91
  76. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +0 -22
  77. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +0 -1
  78. package/dist/lib/table/batches/row-table-batch-aggregator.js +0 -85
  79. package/dist/lib/table/batches/table-batch-aggregator.d.ts +0 -25
  80. package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +0 -1
  81. package/dist/lib/table/batches/table-batch-aggregator.js +0 -4
  82. package/dist/lib/table/batches/table-batch-builder.d.ts +0 -53
  83. package/dist/lib/table/batches/table-batch-builder.d.ts.map +0 -1
  84. package/dist/lib/table/batches/table-batch-builder.js +0 -151
  85. package/dist/lib/table/simple-table/convert-table.d.ts +0 -43
  86. package/dist/lib/table/simple-table/convert-table.d.ts.map +0 -1
  87. package/dist/lib/table/simple-table/convert-table.js +0 -118
  88. package/dist/lib/table/simple-table/data-type.d.ts +0 -17
  89. package/dist/lib/table/simple-table/data-type.d.ts.map +0 -1
  90. package/dist/lib/table/simple-table/data-type.js +0 -88
  91. package/dist/lib/table/simple-table/make-table-from-batches.d.ts +0 -22
  92. package/dist/lib/table/simple-table/make-table-from-batches.d.ts.map +0 -1
  93. package/dist/lib/table/simple-table/make-table-from-batches.js +0 -79
  94. package/dist/lib/table/simple-table/make-table.d.ts +0 -65
  95. package/dist/lib/table/simple-table/make-table.d.ts.map +0 -1
  96. package/dist/lib/table/simple-table/make-table.js +0 -94
  97. package/dist/lib/table/simple-table/row-utils.d.ts +0 -15
  98. package/dist/lib/table/simple-table/row-utils.d.ts.map +0 -1
  99. package/dist/lib/table/simple-table/row-utils.js +0 -49
  100. package/dist/lib/table/simple-table/table-accessors.d.ts +0 -68
  101. package/dist/lib/table/simple-table/table-accessors.d.ts.map +0 -1
  102. package/dist/lib/table/simple-table/table-accessors.js +0 -350
  103. package/dist/lib/table/simple-table/table-column.d.ts +0 -7
  104. package/dist/lib/table/simple-table/table-column.d.ts.map +0 -1
  105. package/dist/lib/table/simple-table/table-column.js +0 -39
  106. package/dist/lib/table/simple-table/table-schema.d.ts +0 -15
  107. package/dist/lib/table/simple-table/table-schema.d.ts.map +0 -1
  108. package/dist/lib/table/simple-table/table-schema.js +0 -100
  109. package/dist/lib/utils/assert.d.ts +0 -2
  110. package/dist/lib/utils/assert.d.ts.map +0 -1
  111. package/dist/lib/utils/assert.js +0 -8
  112. package/dist/lib/utils/async-queue.d.ts +0 -18
  113. package/dist/lib/utils/async-queue.d.ts.map +0 -1
  114. package/dist/lib/utils/async-queue.js +0 -90
  115. package/dist/types/binary-geometries.d.ts +0 -57
  116. package/dist/types/binary-geometries.d.ts.map +0 -1
  117. package/dist/types/category-gis.d.ts +0 -18
  118. package/dist/types/category-gis.d.ts.map +0 -1
  119. package/dist/types/category-image.d.ts.map +0 -1
  120. package/dist/types/category-mesh.d.ts.map +0 -1
  121. package/dist/types/category-table.d.ts.map +0 -1
  122. package/dist/types/category-texture.d.ts.map +0 -1
  123. package/dist/types/flat-geometries.d.ts +0 -30
  124. package/dist/types/flat-geometries.d.ts.map +0 -1
  125. package/src/lib/mesh/convert-mesh.ts +0 -51
  126. package/src/lib/mesh/deduce-mesh-schema.ts +0 -76
  127. package/src/lib/mesh/mesh-to-arrow-table.ts +0 -47
  128. package/src/lib/table/arrow-api/arrow-like-field.ts +0 -53
  129. package/src/lib/table/arrow-api/arrow-like-interface.ts +0 -84
  130. package/src/lib/table/arrow-api/arrow-like-schema.ts +0 -101
  131. package/src/lib/table/arrow-api/arrow-like-table.ts +0 -86
  132. package/src/lib/table/arrow-api/arrow-like-type.ts +0 -502
  133. package/src/lib/table/arrow-api/enum.ts +0 -99
  134. package/src/lib/table/arrow-api/get-type-info.ts +0 -38
  135. package/src/lib/table/arrow-api/index.ts +0 -8
  136. package/src/lib/table/batches/base-table-batch-aggregator.ts +0 -83
  137. package/src/lib/table/batches/columnar-table-batch-aggregator.ts +0 -112
  138. package/src/lib/table/batches/row-table-batch-aggregator.ts +0 -109
  139. package/src/lib/table/batches/table-batch-aggregator.ts +0 -29
  140. package/src/lib/table/batches/table-batch-builder.ts +0 -190
  141. package/src/lib/table/simple-table/convert-table.ts +0 -149
  142. package/src/lib/table/simple-table/data-type.ts +0 -104
  143. package/src/lib/table/simple-table/make-table-from-batches.ts +0 -98
  144. package/src/lib/table/simple-table/make-table.ts +0 -111
  145. package/src/lib/table/simple-table/row-utils.ts +0 -59
  146. package/src/lib/table/simple-table/table-accessors.ts +0 -417
  147. package/src/lib/table/simple-table/table-column.ts +0 -49
  148. package/src/lib/table/simple-table/table-schema.ts +0 -121
  149. package/src/lib/utils/assert.ts +0 -8
  150. package/src/lib/utils/async-queue.ts +0 -104
  151. package/src/types/binary-geometries.ts +0 -67
  152. /package/dist/{types → categories}/category-gis.js +0 -0
  153. /package/dist/{types → categories}/category-image.d.ts +0 -0
  154. /package/dist/{types → categories}/category-image.js +0 -0
  155. /package/dist/{types → categories}/category-mesh.js +0 -0
  156. /package/dist/{types → categories}/category-table.js +0 -0
  157. /package/dist/{types → categories}/category-texture.d.ts +0 -0
  158. /package/dist/{types → categories}/category-texture.js +0 -0
  159. /package/dist/{lib/table/arrow-api/arrow-like-interface.js → geometry/binary-features.js} +0 -0
  160. /package/dist/{types → geometry}/binary-geometries.js +0 -0
  161. /package/dist/{types → geometry}/flat-geometries.js +0 -0
  162. /package/src/{types → categories}/category-image.ts +0 -0
  163. /package/src/{types → categories}/category-texture.ts +0 -0
package/dist/index.cjs CHANGED
@@ -3,7 +3,6 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
6
  var __export = (target, all) => {
8
7
  for (var name in all)
9
8
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -17,1205 +16,16 @@ var __copyProps = (to, from, except, desc) => {
17
16
  return to;
18
17
  };
19
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
- var __publicField = (obj, key, value) => {
21
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
- return value;
23
- };
24
19
 
25
20
  // dist/index.js
26
21
  var dist_exports = {};
27
22
  __export(dist_exports, {
28
- ArrowLikeDataType: () => DataType,
29
- ArrowLikeField: () => ArrowLikeField,
30
- ArrowLikeSchema: () => ArrowLikeSchema,
31
- ArrowLikeTable: () => ArrowLikeTable,
32
- AsyncQueue: () => AsyncQueue,
33
- Binary: () => Binary,
34
- Bool: () => Bool,
35
- ColumnarTableBatchAggregator: () => ColumnarTableBatchAggregator,
36
- Date: () => Date2,
37
- DateDay: () => DateDay,
38
- DateMillisecond: () => DateMillisecond,
39
- FixedSizeList: () => FixedSizeList,
40
- Float: () => Float,
41
- Float16: () => Float16,
42
- Float32: () => Float32,
43
- Float64: () => Float64,
44
- Int: () => Int,
45
- Int16: () => Int16,
46
- Int32: () => Int32,
47
- Int64: () => Int64,
48
- Int8: () => Int8,
49
- Interval: () => Interval,
50
- IntervalDayTime: () => IntervalDayTime,
51
- IntervalYearMonth: () => IntervalYearMonth,
52
- Null: () => Null,
53
- RowTableBatchAggregator: () => RowTableBatchAggregator,
54
- Struct: () => Struct,
55
- TableBatchBuilder: () => TableBatchBuilder,
56
- Time: () => Time,
57
- TimeMillisecond: () => TimeMillisecond,
58
- TimeSecond: () => TimeSecond,
59
- Timestamp: () => Timestamp,
60
- TimestampMicrosecond: () => TimestampMicrosecond,
61
- TimestampMillisecond: () => TimestampMillisecond,
62
- TimestampNanosecond: () => TimestampNanosecond,
63
- TimestampSecond: () => TimestampSecond,
64
- Uint16: () => Uint16,
65
- Uint32: () => Uint32,
66
- Uint64: () => Uint64,
67
- Uint8: () => Uint8,
68
- Utf8: () => Utf8,
69
- convertTable: () => convertTable,
70
- convertToArrayRow: () => convertToArrayRow,
71
- convertToObjectRow: () => convertToObjectRow,
72
- deduceMeshField: () => deduceMeshField,
73
- deduceMeshSchema: () => deduceMeshSchema,
74
- deduceTableSchema: () => deduceTableSchema,
75
- getArrayTypeFromDataType: () => getArrayTypeFromDataType,
76
- getDataTypeFromArray: () => getDataTypeFromArray,
77
23
  getMeshBoundingBox: () => getMeshBoundingBox,
78
- getMeshSize: () => getMeshSize,
79
- getTableCell: () => getTableCell,
80
- getTableCellAt: () => getTableCellAt,
81
- getTableColumnIndex: () => getTableColumnIndex,
82
- getTableColumnName: () => getTableColumnName,
83
- getTableLength: () => getTableLength,
84
- getTableNumCols: () => getTableNumCols,
85
- getTableRowAsArray: () => getTableRowAsArray,
86
- getTableRowAsObject: () => getTableRowAsObject,
87
- getTableRowShape: () => getTableRowShape,
88
- getTypeInfo: () => getTypeInfo,
89
- isTable: () => isTable,
90
- makeArrayRowIterator: () => makeArrayRowIterator,
91
- makeBatchFromTable: () => makeBatchFromTable,
92
- makeMeshAttributeMetadata: () => makeMeshAttributeMetadata,
93
- makeObjectRowIterator: () => makeObjectRowIterator,
94
- makeRowIterator: () => makeRowIterator,
95
- makeTableFromBatches: () => makeTableFromBatches,
96
- makeTableFromData: () => makeTableFromData
24
+ getMeshSize: () => getMeshSize
97
25
  });
98
26
  module.exports = __toCommonJS(dist_exports);
99
27
 
100
- // dist/lib/table/simple-table/data-type.js
101
- function getDataTypeFromValue(value, defaultNumberType = "float32") {
102
- if (value instanceof Date) {
103
- return "date-millisecond";
104
- }
105
- if (value instanceof Number) {
106
- return defaultNumberType;
107
- }
108
- if (typeof value === "string") {
109
- return "utf8";
110
- }
111
- if (value === null || value === "undefined") {
112
- return "null";
113
- }
114
- return "null";
115
- }
116
- function getDataTypeFromArray(array) {
117
- let type = getDataTypeFromTypedArray(array);
118
- if (type !== "null") {
119
- return { type, nullable: false };
120
- }
121
- if (array.length > 0) {
122
- type = getDataTypeFromValue(array[0]);
123
- return { type, nullable: true };
124
- }
125
- return { type: "null", nullable: true };
126
- }
127
- function getDataTypeFromTypedArray(array) {
128
- switch (array.constructor) {
129
- case Int8Array:
130
- return "int8";
131
- case Uint8Array:
132
- case Uint8ClampedArray:
133
- return "uint8";
134
- case Int16Array:
135
- return "int16";
136
- case Uint16Array:
137
- return "uint16";
138
- case Int32Array:
139
- return "int32";
140
- case Uint32Array:
141
- return "uint32";
142
- case Float32Array:
143
- return "float32";
144
- case Float64Array:
145
- return "float64";
146
- default:
147
- return "null";
148
- }
149
- }
150
- function getArrayTypeFromDataType(type, nullable) {
151
- if (!nullable) {
152
- switch (type) {
153
- case "int8":
154
- return Int8Array;
155
- case "uint8":
156
- return Uint8Array;
157
- case "int16":
158
- return Int16Array;
159
- case "uint16":
160
- return Uint16Array;
161
- case "int32":
162
- return Int32Array;
163
- case "uint32":
164
- return Uint32Array;
165
- case "float32":
166
- return Float32Array;
167
- case "float64":
168
- return Float64Array;
169
- default:
170
- break;
171
- }
172
- }
173
- return Array;
174
- }
175
-
176
- // dist/lib/table/batches/base-table-batch-aggregator.js
177
- var DEFAULT_ROW_COUNT = 100;
178
- var BaseTableBatchAggregator = class {
179
- schema;
180
- options;
181
- shape;
182
- length = 0;
183
- rows = null;
184
- cursor = 0;
185
- _headers = [];
186
- constructor(schema, options) {
187
- this.options = options;
188
- this.schema = schema;
189
- if (!Array.isArray(schema)) {
190
- this._headers = [];
191
- for (const key in schema) {
192
- this._headers[schema[key].index] = schema[key].name;
193
- }
194
- }
195
- }
196
- rowCount() {
197
- return this.length;
198
- }
199
- addArrayRow(row, cursor) {
200
- if (Number.isFinite(cursor)) {
201
- this.cursor = cursor;
202
- }
203
- this.shape = "array-row-table";
204
- this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
205
- this.rows[this.length] = row;
206
- this.length++;
207
- }
208
- addObjectRow(row, cursor) {
209
- if (Number.isFinite(cursor)) {
210
- this.cursor = cursor;
211
- }
212
- this.shape = "object-row-table";
213
- this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
214
- this.rows[this.length] = row;
215
- this.length++;
216
- }
217
- getBatch() {
218
- let rows = this.rows;
219
- if (!rows) {
220
- return null;
221
- }
222
- rows = rows.slice(0, this.length);
223
- this.rows = null;
224
- const batch = {
225
- shape: this.shape || "array-row-table",
226
- batchType: "data",
227
- data: rows,
228
- length: this.length,
229
- schema: this.schema,
230
- cursor: this.cursor
231
- };
232
- return batch;
233
- }
234
- };
235
-
236
- // dist/lib/table/simple-table/row-utils.js
237
- function convertToObjectRow(arrayRow, headers) {
238
- if (!arrayRow) {
239
- throw new Error("null row");
240
- }
241
- const objectRow = {};
242
- if (headers) {
243
- for (let i = 0; i < headers.length; i++) {
244
- objectRow[headers[i]] = arrayRow[i];
245
- }
246
- } else {
247
- for (let i = 0; i < arrayRow.length; i++) {
248
- const columnName = `column-${i}`;
249
- objectRow[columnName] = arrayRow[i];
250
- }
251
- }
252
- return objectRow;
253
- }
254
- function convertToArrayRow(objectRow, headers) {
255
- if (!objectRow) {
256
- throw new Error("null row");
257
- }
258
- if (headers) {
259
- const arrayRow = new Array(headers.length);
260
- for (let i = 0; i < headers.length; i++) {
261
- arrayRow[i] = objectRow[headers[i]];
262
- }
263
- return arrayRow;
264
- }
265
- return Object.values(objectRow);
266
- }
267
- function inferHeadersFromArrayRow(arrayRow) {
268
- const headers = [];
269
- for (let i = 0; i < arrayRow.length; i++) {
270
- const columnName = `column-${i}`;
271
- headers.push(columnName);
272
- }
273
- return headers;
274
- }
275
- function inferHeadersFromObjectRow(row) {
276
- return Object.keys(row);
277
- }
278
-
279
- // dist/lib/table/batches/row-table-batch-aggregator.js
280
- var DEFAULT_ROW_COUNT2 = 100;
281
- var RowTableBatchAggregator = class {
282
- schema;
283
- options;
284
- length = 0;
285
- objectRows = null;
286
- arrayRows = null;
287
- cursor = 0;
288
- _headers = null;
289
- constructor(schema, options) {
290
- this.options = options;
291
- this.schema = schema;
292
- if (schema) {
293
- this._headers = [];
294
- for (const key in schema) {
295
- this._headers[schema[key].index] = schema[key].name;
296
- }
297
- }
298
- }
299
- rowCount() {
300
- return this.length;
301
- }
302
- addArrayRow(row, cursor) {
303
- if (Number.isFinite(cursor)) {
304
- this.cursor = cursor;
305
- }
306
- this._headers ||= inferHeadersFromArrayRow(row);
307
- switch (this.options.shape) {
308
- case "object-row-table":
309
- const rowObject = convertToObjectRow(row, this._headers);
310
- this.addObjectRow(rowObject, cursor);
311
- break;
312
- case "array-row-table":
313
- this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT2);
314
- this.arrayRows[this.length] = row;
315
- this.length++;
316
- break;
317
- }
318
- }
319
- addObjectRow(row, cursor) {
320
- if (Number.isFinite(cursor)) {
321
- this.cursor = cursor;
322
- }
323
- this._headers ||= inferHeadersFromObjectRow(row);
324
- switch (this.options.shape) {
325
- case "array-row-table":
326
- const rowArray = convertToArrayRow(row, this._headers);
327
- this.addArrayRow(rowArray, cursor);
328
- break;
329
- case "object-row-table":
330
- this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT2);
331
- this.objectRows[this.length] = row;
332
- this.length++;
333
- break;
334
- }
335
- }
336
- getBatch() {
337
- let rows = this.arrayRows || this.objectRows;
338
- if (!rows) {
339
- return null;
340
- }
341
- rows = rows.slice(0, this.length);
342
- this.arrayRows = null;
343
- this.objectRows = null;
344
- return {
345
- shape: this.options.shape,
346
- batchType: "data",
347
- data: rows,
348
- length: this.length,
349
- // @ts-expect-error we should infer a schema
350
- schema: this.schema,
351
- cursor: this.cursor
352
- };
353
- }
354
- };
355
-
356
- // dist/lib/table/batches/columnar-table-batch-aggregator.js
357
- var DEFAULT_ROW_COUNT3 = 100;
358
- var ColumnarTableBatchAggregator = class {
359
- schema;
360
- length = 0;
361
- allocated = 0;
362
- columns = {};
363
- constructor(schema, options) {
364
- this.schema = schema;
365
- this._reallocateColumns();
366
- }
367
- rowCount() {
368
- return this.length;
369
- }
370
- addArrayRow(row) {
371
- this._reallocateColumns();
372
- let i = 0;
373
- for (const fieldName in this.columns) {
374
- this.columns[fieldName][this.length] = row[i++];
375
- }
376
- this.length++;
377
- }
378
- addObjectRow(row) {
379
- this._reallocateColumns();
380
- for (const fieldName in row) {
381
- this.columns[fieldName][this.length] = row[fieldName];
382
- }
383
- this.length++;
384
- }
385
- getBatch() {
386
- this._pruneColumns();
387
- const columns = Array.isArray(this.schema) ? this.columns : {};
388
- if (!Array.isArray(this.schema)) {
389
- for (const fieldName in this.schema) {
390
- const field = this.schema[fieldName];
391
- columns[field.name] = this.columns[field.index];
392
- }
393
- }
394
- this.columns = {};
395
- const batch = {
396
- shape: "columnar-table",
397
- batchType: "data",
398
- data: columns,
399
- schema: this.schema,
400
- length: this.length
401
- };
402
- return batch;
403
- }
404
- // HELPERS
405
- _reallocateColumns() {
406
- if (this.length < this.allocated) {
407
- return;
408
- }
409
- this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT3;
410
- this.columns = {};
411
- for (const fieldName in this.schema) {
412
- const field = this.schema[fieldName];
413
- const ArrayType = field.type || Float32Array;
414
- const oldColumn = this.columns[field.index];
415
- if (oldColumn && ArrayBuffer.isView(oldColumn)) {
416
- const typedArray = new ArrayType(this.allocated);
417
- typedArray.set(oldColumn);
418
- this.columns[field.index] = typedArray;
419
- } else if (oldColumn) {
420
- oldColumn.length = this.allocated;
421
- this.columns[field.index] = oldColumn;
422
- } else {
423
- this.columns[field.index] = new ArrayType(this.allocated);
424
- }
425
- }
426
- }
427
- _pruneColumns() {
428
- for (const [columnName, column] of Object.entries(this.columns)) {
429
- this.columns[columnName] = column.slice(0, this.length);
430
- }
431
- }
432
- };
433
-
434
- // dist/lib/table/batches/table-batch-builder.js
435
- var DEFAULT_OPTIONS = {
436
- shape: void 0,
437
- batchSize: "auto",
438
- batchDebounceMs: 0,
439
- limit: 0,
440
- _limitMB: 0
441
- };
442
- var ERR_MESSAGE = "TableBatchBuilder";
443
- var _TableBatchBuilder = class {
444
- schema;
445
- options;
446
- aggregator = null;
447
- batchCount = 0;
448
- bytesUsed = 0;
449
- isChunkComplete = false;
450
- lastBatchEmittedMs = Date.now();
451
- totalLength = 0;
452
- totalBytes = 0;
453
- rowBytes = 0;
454
- constructor(schema, options) {
455
- this.schema = schema;
456
- this.options = { ...DEFAULT_OPTIONS, ...options };
457
- }
458
- limitReached() {
459
- var _a, _b;
460
- if (Boolean((_a = this.options) == null ? void 0 : _a.limit) && this.totalLength >= this.options.limit) {
461
- return true;
462
- }
463
- if (Boolean((_b = this.options) == null ? void 0 : _b._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
464
- return true;
465
- }
466
- return false;
467
- }
468
- /** @deprecated Use addArrayRow or addObjectRow */
469
- addRow(row) {
470
- if (this.limitReached()) {
471
- return;
472
- }
473
- this.totalLength++;
474
- this.rowBytes = this.rowBytes || this._estimateRowMB(row);
475
- this.totalBytes += this.rowBytes;
476
- if (Array.isArray(row)) {
477
- this.addArrayRow(row);
478
- } else {
479
- this.addObjectRow(row);
480
- }
481
- }
482
- /** Add one row to the batch */
483
- addArrayRow(row) {
484
- if (!this.aggregator) {
485
- const TableBatchType = this._getTableBatchType();
486
- this.aggregator = new TableBatchType(this.schema, this.options);
487
- }
488
- this.aggregator.addArrayRow(row);
489
- }
490
- /** Add one row to the batch */
491
- addObjectRow(row) {
492
- if (!this.aggregator) {
493
- const TableBatchType = this._getTableBatchType();
494
- this.aggregator = new TableBatchType(this.schema, this.options);
495
- }
496
- this.aggregator.addObjectRow(row);
497
- }
498
- /** Mark an incoming raw memory chunk has completed */
499
- chunkComplete(chunk) {
500
- if (chunk instanceof ArrayBuffer) {
501
- this.bytesUsed += chunk.byteLength;
502
- }
503
- if (typeof chunk === "string") {
504
- this.bytesUsed += chunk.length;
505
- }
506
- this.isChunkComplete = true;
507
- }
508
- getFullBatch(options) {
509
- return this._isFull() ? this._getBatch(options) : null;
510
- }
511
- getFinalBatch(options) {
512
- return this._getBatch(options);
513
- }
514
- // INTERNAL
515
- _estimateRowMB(row) {
516
- return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
517
- }
518
- _isFull() {
519
- if (!this.aggregator || this.aggregator.rowCount() === 0) {
520
- return false;
521
- }
522
- if (this.options.batchSize === "auto") {
523
- if (!this.isChunkComplete) {
524
- return false;
525
- }
526
- } else if (this.options.batchSize > this.aggregator.rowCount()) {
527
- return false;
528
- }
529
- if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
530
- return false;
531
- }
532
- this.isChunkComplete = false;
533
- this.lastBatchEmittedMs = Date.now();
534
- return true;
535
- }
536
- /**
537
- * bytesUsed can be set via chunkComplete or via getBatch*
538
- */
539
- _getBatch(options) {
540
- if (!this.aggregator) {
541
- return null;
542
- }
543
- if (options == null ? void 0 : options.bytesUsed) {
544
- this.bytesUsed = options.bytesUsed;
545
- }
546
- const normalizedBatch = this.aggregator.getBatch();
547
- normalizedBatch.count = this.batchCount;
548
- normalizedBatch.bytesUsed = this.bytesUsed;
549
- Object.assign(normalizedBatch, options);
550
- this.batchCount++;
551
- this.aggregator = null;
552
- return normalizedBatch;
553
- }
554
- _getTableBatchType() {
555
- switch (this.options.shape) {
556
- case "array-row-table":
557
- case "object-row-table":
558
- return RowTableBatchAggregator;
559
- case "columnar-table":
560
- return ColumnarTableBatchAggregator;
561
- case "arrow-table":
562
- if (!_TableBatchBuilder.ArrowBatch) {
563
- throw new Error(ERR_MESSAGE);
564
- }
565
- return _TableBatchBuilder.ArrowBatch;
566
- default:
567
- return BaseTableBatchAggregator;
568
- }
569
- }
570
- };
571
- var TableBatchBuilder = _TableBatchBuilder;
572
- __publicField(TableBatchBuilder, "ArrowBatch");
573
-
574
- // dist/lib/table/simple-table/table-accessors.js
575
- function isTable(table) {
576
- var _a;
577
- const shape = typeof table === "object" && (table == null ? void 0 : table.shape);
578
- switch (shape) {
579
- case "array-row-table":
580
- case "object-row-table":
581
- return Array.isArray(table.data);
582
- case "geojson-table":
583
- return Array.isArray(table.features);
584
- case "columnar-table":
585
- return table.data && typeof table.data === "object";
586
- case "arrow-table":
587
- return Boolean(((_a = table == null ? void 0 : table.data) == null ? void 0 : _a.numRows) !== void 0);
588
- default:
589
- return false;
590
- }
591
- }
592
- function getTableLength(table) {
593
- switch (table.shape) {
594
- case "array-row-table":
595
- case "object-row-table":
596
- return table.data.length;
597
- case "geojson-table":
598
- return table.features.length;
599
- case "arrow-table":
600
- const arrowTable = table.data;
601
- return arrowTable.numRows;
602
- case "columnar-table":
603
- for (const column of Object.values(table.data)) {
604
- return column.length || 0;
605
- }
606
- return 0;
607
- default:
608
- throw new Error("table");
609
- }
610
- }
611
- function getTableNumCols(table) {
612
- if (table.schema) {
613
- return table.schema.fields.length;
614
- }
615
- if (getTableLength(table) === 0) {
616
- throw new Error("empty table");
617
- }
618
- switch (table.shape) {
619
- case "array-row-table":
620
- return table.data[0].length;
621
- case "object-row-table":
622
- return Object.keys(table.data[0]).length;
623
- case "geojson-table":
624
- return Object.keys(table.features[0]).length;
625
- case "columnar-table":
626
- return Object.keys(table.data).length;
627
- case "arrow-table":
628
- const arrowTable = table.data;
629
- return arrowTable.numCols;
630
- default:
631
- throw new Error("table");
632
- }
633
- }
634
- function getTableCell(table, rowIndex, columnName) {
635
- var _a;
636
- switch (table.shape) {
637
- case "array-row-table":
638
- const columnIndex = getTableColumnIndex(table, columnName);
639
- return table.data[rowIndex][columnIndex];
640
- case "object-row-table":
641
- return table.data[rowIndex][columnName];
642
- case "geojson-table":
643
- return table.features[rowIndex][columnName];
644
- case "columnar-table":
645
- const column = table.data[columnName];
646
- return column[rowIndex];
647
- case "arrow-table":
648
- const arrowTable = table.data;
649
- const arrowColumnIndex = arrowTable.schema.fields.findIndex((field) => field.name === columnName);
650
- return (_a = arrowTable.getChildAt(arrowColumnIndex)) == null ? void 0 : _a.get(rowIndex);
651
- default:
652
- throw new Error("todo");
653
- }
654
- }
655
- function getTableCellAt(table, rowIndex, columnIndex) {
656
- var _a;
657
- switch (table.shape) {
658
- case "array-row-table":
659
- return table.data[rowIndex][columnIndex];
660
- case "object-row-table":
661
- const columnName1 = getTableColumnName(table, columnIndex);
662
- return table.data[rowIndex][columnName1];
663
- case "geojson-table":
664
- const columnName2 = getTableColumnName(table, columnIndex);
665
- return table.features[rowIndex][columnName2];
666
- case "columnar-table":
667
- const columnName3 = getTableColumnName(table, columnIndex);
668
- const column = table.data[columnName3];
669
- return column[rowIndex];
670
- case "arrow-table":
671
- const arrowTable = table.data;
672
- return (_a = arrowTable.getChildAt(columnIndex)) == null ? void 0 : _a.get(rowIndex);
673
- default:
674
- throw new Error("todo");
675
- }
676
- }
677
- function getTableRowShape(table) {
678
- switch (table.shape) {
679
- case "array-row-table":
680
- case "object-row-table":
681
- return table.shape;
682
- case "geojson-table":
683
- return "object-row-table";
684
- case "columnar-table":
685
- default:
686
- throw new Error("Not a row table");
687
- }
688
- }
689
- function getTableColumnIndex(table, columnName) {
690
- var _a;
691
- const columnIndex = (_a = table.schema) == null ? void 0 : _a.fields.findIndex((field) => field.name === columnName);
692
- if (columnIndex === void 0) {
693
- throw new Error(columnName);
694
- }
695
- return columnIndex;
696
- }
697
- function getTableColumnName(table, columnIndex) {
698
- var _a, _b;
699
- const columnName = (_b = (_a = table.schema) == null ? void 0 : _a.fields[columnIndex]) == null ? void 0 : _b.name;
700
- if (!columnName) {
701
- throw new Error(`${columnIndex}`);
702
- }
703
- return columnName;
704
- }
705
- function getTableRowAsObject(table, rowIndex, target, copy) {
706
- switch (table.shape) {
707
- case "object-row-table":
708
- return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
709
- case "array-row-table":
710
- if (table.schema) {
711
- const objectRow2 = target || {};
712
- for (let i = 0; i < table.schema.fields.length; i++) {
713
- objectRow2[table.schema.fields[i].name] = table.data[rowIndex][i];
714
- }
715
- return objectRow2;
716
- }
717
- throw new Error("no schema");
718
- case "geojson-table":
719
- if (table.schema) {
720
- const objectRow2 = target || {};
721
- for (let i = 0; i < table.schema.fields.length; i++) {
722
- objectRow2[table.schema.fields[i].name] = table.features[rowIndex][i];
723
- }
724
- return objectRow2;
725
- }
726
- throw new Error("no schema");
727
- case "columnar-table":
728
- if (table.schema) {
729
- const objectRow2 = target || {};
730
- for (let i = 0; i < table.schema.fields.length; i++) {
731
- objectRow2[table.schema.fields[i].name] = table.data[table.schema.fields[i].name][rowIndex];
732
- }
733
- return objectRow2;
734
- } else {
735
- const objectRow2 = target || {};
736
- for (const [name, column] of Object.entries(table.data)) {
737
- objectRow2[name] = column[rowIndex];
738
- }
739
- return objectRow2;
740
- }
741
- case "arrow-table":
742
- const arrowTable = table.data;
743
- const objectRow = target || {};
744
- const row = arrowTable.get(rowIndex);
745
- const schema = arrowTable.schema;
746
- for (let i = 0; i < schema.fields.length; i++) {
747
- objectRow[schema.fields[i].name] = row == null ? void 0 : row[schema.fields[i].name];
748
- }
749
- return objectRow;
750
- default:
751
- throw new Error("shape");
752
- }
753
- }
754
- function getTableRowAsArray(table, rowIndex, target, copy) {
755
- switch (table.shape) {
756
- case "array-row-table":
757
- return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
758
- case "object-row-table":
759
- if (table.schema) {
760
- const arrayRow2 = target || [];
761
- for (let i = 0; i < table.schema.fields.length; i++) {
762
- arrayRow2[i] = table.data[rowIndex][table.schema.fields[i].name];
763
- }
764
- return arrayRow2;
765
- }
766
- return Object.values(table.data[rowIndex]);
767
- case "geojson-table":
768
- if (table.schema) {
769
- const arrayRow2 = target || [];
770
- for (let i = 0; i < table.schema.fields.length; i++) {
771
- arrayRow2[i] = table.features[rowIndex][table.schema.fields[i].name];
772
- }
773
- return arrayRow2;
774
- }
775
- return Object.values(table.features[rowIndex]);
776
- case "columnar-table":
777
- if (table.schema) {
778
- const arrayRow2 = target || [];
779
- for (let i = 0; i < table.schema.fields.length; i++) {
780
- arrayRow2[i] = table.data[table.schema.fields[i].name][rowIndex];
781
- }
782
- return arrayRow2;
783
- } else {
784
- const arrayRow2 = target || [];
785
- let i = 0;
786
- for (const column of Object.values(table.data)) {
787
- arrayRow2[i] = column[rowIndex];
788
- i++;
789
- }
790
- return arrayRow2;
791
- }
792
- case "arrow-table":
793
- const arrowTable = table.data;
794
- const arrayRow = target || [];
795
- const row = arrowTable.get(rowIndex);
796
- const schema = arrowTable.schema;
797
- for (let i = 0; i < schema.fields.length; i++) {
798
- arrayRow[i] = row == null ? void 0 : row[schema.fields[i].name];
799
- }
800
- return arrayRow;
801
- default:
802
- throw new Error("shape");
803
- }
804
- }
805
- function* makeRowIterator(table, shape) {
806
- switch (shape) {
807
- case "array-row-table":
808
- yield* makeArrayRowIterator(table);
809
- break;
810
- case "object-row-table":
811
- yield* makeObjectRowIterator(table);
812
- break;
813
- default:
814
- throw new Error(`Unknown row type ${shape}`);
815
- }
816
- }
817
- function* makeArrayRowIterator(table, target = []) {
818
- const length = getTableLength(table);
819
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
820
- yield getTableRowAsArray(table, rowIndex, target);
821
- }
822
- }
823
- function* makeObjectRowIterator(table, target = {}) {
824
- const length = getTableLength(table);
825
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
826
- yield getTableRowAsObject(table, rowIndex, target);
827
- }
828
- }
829
-
830
- // dist/lib/table/arrow-api/arrow-like-field.js
831
- var ArrowLikeField = class {
832
- name;
833
- type;
834
- nullable;
835
- metadata;
836
- constructor(name, type, nullable = false, metadata = /* @__PURE__ */ new Map()) {
837
- this.name = name;
838
- this.type = type;
839
- this.nullable = nullable;
840
- this.metadata = metadata;
841
- }
842
- get typeId() {
843
- return this.type && this.type.typeId;
844
- }
845
- clone() {
846
- return new ArrowLikeField(this.name, this.type, this.nullable, this.metadata);
847
- }
848
- compareTo(other) {
849
- return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
850
- }
851
- toString() {
852
- return `${JSON.stringify(this.type)}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${JSON.stringify(this.metadata)}` : ""}`;
853
- }
854
- };
855
-
856
- // dist/lib/table/arrow-api/arrow-like-schema.js
857
- var ArrowLikeSchema = class {
858
- fields;
859
- metadata;
860
- constructor(fields, metadata = /* @__PURE__ */ new Map()) {
861
- this.fields = fields.map((field) => new ArrowLikeField(field.name, field.type, field.nullable, field.metadata));
862
- this.metadata = metadata instanceof Map ? metadata : new Map(Object.entries(metadata));
863
- }
864
- // TODO - arrow only seems to compare fields, not metadata
865
- compareTo(other) {
866
- if (this.metadata !== other.metadata) {
867
- return false;
868
- }
869
- if (this.fields.length !== other.fields.length) {
870
- return false;
871
- }
872
- for (let i = 0; i < this.fields.length; ++i) {
873
- if (!this.fields[i].compareTo(other.fields[i])) {
874
- return false;
875
- }
876
- }
877
- return true;
878
- }
879
- select(...columnNames) {
880
- const nameMap = /* @__PURE__ */ Object.create(null);
881
- for (const name of columnNames) {
882
- nameMap[name] = true;
883
- }
884
- const selectedFields = this.fields.filter((field) => nameMap[field.name]);
885
- return new ArrowLikeSchema(selectedFields, this.metadata);
886
- }
887
- selectAt(...columnIndices) {
888
- const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
889
- return new ArrowLikeSchema(selectedFields, this.metadata);
890
- }
891
- assign(schemaOrFields) {
892
- let fields;
893
- let metadata = this.metadata;
894
- if (schemaOrFields instanceof ArrowLikeSchema) {
895
- const otherArrowLikeSchema = schemaOrFields;
896
- fields = otherArrowLikeSchema.fields;
897
- metadata = mergeMaps(mergeMaps(/* @__PURE__ */ new Map(), this.metadata), otherArrowLikeSchema.metadata);
898
- } else {
899
- fields = schemaOrFields;
900
- }
901
- const fieldMap = /* @__PURE__ */ Object.create(null);
902
- for (const field of this.fields) {
903
- fieldMap[field.name] = field;
904
- }
905
- for (const field of fields) {
906
- fieldMap[field.name] = field;
907
- }
908
- const mergedFields = Object.values(fieldMap);
909
- return new ArrowLikeSchema(mergedFields, metadata);
910
- }
911
- };
912
- function mergeMaps(m1, m2) {
913
- return new Map([...m1 || /* @__PURE__ */ new Map(), ...m2 || /* @__PURE__ */ new Map()]);
914
- }
915
-
916
- // dist/lib/table/simple-table/table-schema.js
917
- function deduceTableSchema(table) {
918
- switch (table.shape) {
919
- case "array-row-table":
920
- case "object-row-table":
921
- return deduceSchemaFromRows(table.data);
922
- case "geojson-table":
923
- return deduceSchemaFromGeoJSON(table.features);
924
- case "columnar-table":
925
- return deduceSchemaFromColumns(table.data);
926
- case "arrow-table":
927
- default:
928
- throw new Error("Deduce schema");
929
- }
930
- }
931
- function deduceSchemaFromColumns(columnarTable) {
932
- const fields = [];
933
- for (const [columnName, column] of Object.entries(columnarTable)) {
934
- const field = deduceFieldFromColumn(column, columnName);
935
- fields.push(field);
936
- }
937
- return { fields, metadata: {} };
938
- }
939
- function deduceSchemaFromRows(rowTable) {
940
- if (!rowTable.length) {
941
- throw new Error("deduce from empty table");
942
- }
943
- const fields = [];
944
- const row0 = rowTable[0];
945
- for (const [columnName, value] of Object.entries(row0)) {
946
- fields.push(deduceFieldFromValue(value, columnName));
947
- }
948
- return { fields, metadata: {} };
949
- }
950
- function deduceSchemaFromGeoJSON(features) {
951
- if (!features.length) {
952
- throw new Error("deduce from empty table");
953
- }
954
- const fields = [];
955
- const row0 = features[0].properties || {};
956
- for (const [columnName, value] of Object.entries(row0)) {
957
- fields.push(deduceFieldFromValue(value, columnName));
958
- }
959
- return { fields, metadata: {} };
960
- }
961
- function deduceFieldFromColumn(column, name) {
962
- if (ArrayBuffer.isView(column)) {
963
- const type = getDataTypeFromArray(column);
964
- return {
965
- name,
966
- type: type.type || "null",
967
- nullable: type.nullable
968
- // metadata: {}
969
- };
970
- }
971
- if (Array.isArray(column) && column.length > 0) {
972
- const value = column[0];
973
- const type = getDataTypeFromValue(value);
974
- return {
975
- name,
976
- type,
977
- nullable: true
978
- // metadata: {},
979
- };
980
- }
981
- throw new Error("empty table");
982
- }
983
- function deduceFieldFromValue(value, name) {
984
- const type = getDataTypeFromValue(value);
985
- return {
986
- name,
987
- type,
988
- nullable: true
989
- // metadata: {}
990
- };
991
- }
992
-
993
- // dist/lib/table/arrow-api/arrow-like-table.js
994
- var ArrowLikeVector = class {
995
- table;
996
- columnName;
997
- constructor(table, columnName) {
998
- this.table = table;
999
- this.columnName = columnName;
1000
- }
1001
- get(rowIndex) {
1002
- return getTableCell(this.table, rowIndex, this.columnName);
1003
- }
1004
- toArray() {
1005
- var _a;
1006
- switch (this.table.shape) {
1007
- case "arrow-table":
1008
- const arrowTable = this.table.data;
1009
- return (_a = arrowTable.getChild(this.columnName)) == null ? void 0 : _a.toArray();
1010
- case "columnar-table":
1011
- return this.table.data[this.columnName];
1012
- default:
1013
- throw new Error(this.table.shape);
1014
- }
1015
- }
1016
- };
1017
- var ArrowLikeTable = class {
1018
- schema;
1019
- table;
1020
- constructor(table) {
1021
- const schema = table.schema || deduceTableSchema(table);
1022
- this.schema = new ArrowLikeSchema(schema.fields, schema.metadata);
1023
- this.table = { ...table, schema };
1024
- }
1025
- // get schema() {
1026
- // return this.table.schema;
1027
- // }
1028
- get data() {
1029
- return this.table.shape === "geojson-table" ? this.table.features : this.table.data;
1030
- }
1031
- get numCols() {
1032
- return getTableNumCols(this.table);
1033
- }
1034
- get length() {
1035
- return getTableLength(this.table);
1036
- }
1037
- getChild(columnName) {
1038
- return new ArrowLikeVector(this.table, columnName);
1039
- }
1040
- };
1041
-
1042
- // dist/lib/table/simple-table/make-table.js
1043
- function makeTableFromData(data) {
1044
- let table;
1045
- switch (getTableShapeFromData(data)) {
1046
- case "array-row-table":
1047
- table = { shape: "array-row-table", data };
1048
- break;
1049
- case "object-row-table":
1050
- table = { shape: "object-row-table", data };
1051
- break;
1052
- case "columnar-table":
1053
- table = { shape: "columnar-table", data };
1054
- break;
1055
- default:
1056
- throw new Error("table");
1057
- }
1058
- const schema = deduceTableSchema(table);
1059
- return { ...table, schema };
1060
- }
1061
- function getTableShapeFromData(data) {
1062
- if (Array.isArray(data)) {
1063
- if (data.length === 0) {
1064
- throw new Error("cannot deduce type of empty table");
1065
- }
1066
- const firstRow = data[0];
1067
- if (Array.isArray(firstRow)) {
1068
- return "array-row-table";
1069
- }
1070
- if (firstRow && typeof firstRow === "object") {
1071
- return "object-row-table";
1072
- }
1073
- }
1074
- if (data && typeof data === "object") {
1075
- return "columnar-table";
1076
- }
1077
- throw new Error("invalid table");
1078
- }
1079
-
1080
- // dist/lib/table/simple-table/make-table-from-batches.js
1081
- function makeBatchFromTable(table) {
1082
- return { ...table, length: getTableLength(table), batchType: "data" };
1083
- }
1084
- async function makeTableFromBatches(batchIterator) {
1085
- let arrayRows;
1086
- let objectRows;
1087
- let features;
1088
- let shape = null;
1089
- let schema;
1090
- for await (const batch of batchIterator) {
1091
- shape = shape || batch.shape;
1092
- schema = schema || batch.schema;
1093
- switch (batch.shape) {
1094
- case "array-row-table":
1095
- arrayRows = arrayRows || [];
1096
- for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
1097
- const row = batch.data[rowIndex];
1098
- arrayRows.push(row);
1099
- }
1100
- break;
1101
- case "object-row-table":
1102
- objectRows = objectRows || [];
1103
- for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
1104
- const row = batch.data[rowIndex];
1105
- objectRows.push(row);
1106
- }
1107
- break;
1108
- case "geojson-table":
1109
- features = features || [];
1110
- for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
1111
- const row = batch.features[rowIndex];
1112
- features.push(row);
1113
- }
1114
- break;
1115
- case "columnar-table":
1116
- case "arrow-table":
1117
- default:
1118
- throw new Error("shape");
1119
- }
1120
- }
1121
- if (!shape) {
1122
- return null;
1123
- }
1124
- switch (shape) {
1125
- case "array-row-table":
1126
- return { shape: "array-row-table", data: arrayRows, schema };
1127
- case "object-row-table":
1128
- return { shape: "object-row-table", data: objectRows, schema };
1129
- case "geojson-table":
1130
- return { shape: "geojson-table", type: "FeatureCollection", features, schema };
1131
- default:
1132
- return null;
1133
- }
1134
- }
1135
-
1136
- // dist/lib/table/simple-table/table-column.js
1137
- function makeColumnFromField(field, length) {
1138
- const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
1139
- return new ArrayType(length);
1140
- }
1141
-
1142
- // dist/lib/table/simple-table/convert-table.js
1143
- function convertTable(table, shape) {
1144
- switch (shape) {
1145
- case "object-row-table":
1146
- return makeObjectRowTable(table);
1147
- case "array-row-table":
1148
- return makeArrayRowTable(table);
1149
- case "columnar-table":
1150
- return makeColumnarTable(table);
1151
- case "arrow-table":
1152
- return makeArrowTable(table);
1153
- default:
1154
- throw new Error(shape);
1155
- }
1156
- }
1157
- function makeArrowTable(table) {
1158
- var _a;
1159
- const _makeArrowTable = (_a = globalThis.__loaders) == null ? void 0 : _a._makeArrowTable;
1160
- if (!_makeArrowTable) {
1161
- throw new Error("");
1162
- }
1163
- return _makeArrowTable(table);
1164
- }
1165
- function makeColumnarTable(table) {
1166
- var _a;
1167
- const schema = table.schema || deduceTableSchema(table);
1168
- const fields = ((_a = table.schema) == null ? void 0 : _a.fields) || [];
1169
- if (table.shape === "columnar-table") {
1170
- return { ...table, schema };
1171
- }
1172
- const length = getTableLength(table);
1173
- const columns = {};
1174
- for (const field of fields) {
1175
- const column = makeColumnFromField(field, length);
1176
- columns[field.name] = column;
1177
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
1178
- column[rowIndex] = getTableCell(table, rowIndex, field.name);
1179
- }
1180
- }
1181
- return {
1182
- shape: "columnar-table",
1183
- schema,
1184
- data: columns
1185
- };
1186
- }
1187
- function makeArrayRowTable(table) {
1188
- if (table.shape === "array-row-table") {
1189
- return table;
1190
- }
1191
- const length = getTableLength(table);
1192
- const data = new Array(length);
1193
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
1194
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
1195
- }
1196
- return {
1197
- shape: "array-row-table",
1198
- schema: table.schema,
1199
- data
1200
- };
1201
- }
1202
- function makeObjectRowTable(table) {
1203
- if (table.shape === "object-row-table") {
1204
- return table;
1205
- }
1206
- const length = getTableLength(table);
1207
- const data = new Array(length);
1208
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
1209
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
1210
- }
1211
- return {
1212
- shape: "object-row-table",
1213
- schema: table.schema,
1214
- data
1215
- };
1216
- }
1217
-
1218
- // dist/lib/mesh/mesh-utils.js
28
+ // dist/deprecated/mesh-utils.js
1219
29
  function getMeshSize(attributes) {
1220
30
  let size = 0;
1221
31
  for (const attributeName in attributes) {
@@ -1251,604 +61,4 @@ function getMeshBoundingBox(attributes) {
1251
61
  [maxX, maxY, maxZ]
1252
62
  ];
1253
63
  }
1254
-
1255
- // dist/lib/mesh/deduce-mesh-schema.js
1256
- function deduceMeshSchema(attributes, metadata = {}) {
1257
- const fields = deduceMeshFields(attributes);
1258
- return { fields, metadata };
1259
- }
1260
- function deduceMeshField(name, attribute, optionalMetadata) {
1261
- const type = getDataTypeFromTypedArray(attribute.value);
1262
- const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
1263
- return {
1264
- name,
1265
- type: { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "value", type }] },
1266
- nullable: false,
1267
- metadata
1268
- };
1269
- }
1270
- function deduceMeshFields(attributes) {
1271
- const fields = [];
1272
- for (const attributeName in attributes) {
1273
- const attribute = attributes[attributeName];
1274
- fields.push(deduceMeshField(attributeName, attribute));
1275
- }
1276
- return fields;
1277
- }
1278
- function makeMeshAttributeMetadata(attribute) {
1279
- const result = {};
1280
- if ("byteOffset" in attribute) {
1281
- result.byteOffset = attribute.byteOffset.toString(10);
1282
- }
1283
- if ("byteStride" in attribute) {
1284
- result.byteStride = attribute.byteStride.toString(10);
1285
- }
1286
- if ("normalized" in attribute) {
1287
- result.normalized = attribute.normalized.toString();
1288
- }
1289
- return result;
1290
- }
1291
-
1292
- // dist/lib/table/arrow-api/enum.js
1293
- var Type;
1294
- (function(Type2) {
1295
- Type2[Type2["NONE"] = 0] = "NONE";
1296
- Type2[Type2["Null"] = 1] = "Null";
1297
- Type2[Type2["Int"] = 2] = "Int";
1298
- Type2[Type2["Float"] = 3] = "Float";
1299
- Type2[Type2["Binary"] = 4] = "Binary";
1300
- Type2[Type2["Utf8"] = 5] = "Utf8";
1301
- Type2[Type2["Bool"] = 6] = "Bool";
1302
- Type2[Type2["Decimal"] = 7] = "Decimal";
1303
- Type2[Type2["Date"] = 8] = "Date";
1304
- Type2[Type2["Time"] = 9] = "Time";
1305
- Type2[Type2["Timestamp"] = 10] = "Timestamp";
1306
- Type2[Type2["Interval"] = 11] = "Interval";
1307
- Type2[Type2["List"] = 12] = "List";
1308
- Type2[Type2["Struct"] = 13] = "Struct";
1309
- Type2[Type2["Union"] = 14] = "Union";
1310
- Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
1311
- Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
1312
- Type2[Type2["Map"] = 17] = "Map";
1313
- Type2[Type2["Dictionary"] = -1] = "Dictionary";
1314
- Type2[Type2["Int8"] = -2] = "Int8";
1315
- Type2[Type2["Int16"] = -3] = "Int16";
1316
- Type2[Type2["Int32"] = -4] = "Int32";
1317
- Type2[Type2["Int64"] = -5] = "Int64";
1318
- Type2[Type2["Uint8"] = -6] = "Uint8";
1319
- Type2[Type2["Uint16"] = -7] = "Uint16";
1320
- Type2[Type2["Uint32"] = -8] = "Uint32";
1321
- Type2[Type2["Uint64"] = -9] = "Uint64";
1322
- Type2[Type2["Float16"] = -10] = "Float16";
1323
- Type2[Type2["Float32"] = -11] = "Float32";
1324
- Type2[Type2["Float64"] = -12] = "Float64";
1325
- Type2[Type2["DateDay"] = -13] = "DateDay";
1326
- Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
1327
- Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
1328
- Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
1329
- Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
1330
- Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
1331
- Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
1332
- Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
1333
- Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
1334
- Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
1335
- Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
1336
- Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
1337
- Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
1338
- Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
1339
- })(Type || (Type = {}));
1340
-
1341
- // dist/lib/table/arrow-api/arrow-like-type.js
1342
- var DataType = class {
1343
- static isNull(x) {
1344
- return x && x.typeId === Type.Null;
1345
- }
1346
- static isInt(x) {
1347
- return x && x.typeId === Type.Int;
1348
- }
1349
- static isFloat(x) {
1350
- return x && x.typeId === Type.Float;
1351
- }
1352
- static isBinary(x) {
1353
- return x && x.typeId === Type.Binary;
1354
- }
1355
- static isUtf8(x) {
1356
- return x && x.typeId === Type.Utf8;
1357
- }
1358
- static isBool(x) {
1359
- return x && x.typeId === Type.Bool;
1360
- }
1361
- static isDecimal(x) {
1362
- return x && x.typeId === Type.Decimal;
1363
- }
1364
- static isDate(x) {
1365
- return x && x.typeId === Type.Date;
1366
- }
1367
- static isTime(x) {
1368
- return x && x.typeId === Type.Time;
1369
- }
1370
- static isTimestamp(x) {
1371
- return x && x.typeId === Type.Timestamp;
1372
- }
1373
- static isInterval(x) {
1374
- return x && x.typeId === Type.Interval;
1375
- }
1376
- static isList(x) {
1377
- return x && x.typeId === Type.List;
1378
- }
1379
- static isStruct(x) {
1380
- return x && x.typeId === Type.Struct;
1381
- }
1382
- static isUnion(x) {
1383
- return x && x.typeId === Type.Union;
1384
- }
1385
- static isFixedSizeBinary(x) {
1386
- return x && x.typeId === Type.FixedSizeBinary;
1387
- }
1388
- static isFixedSizeList(x) {
1389
- return x && x.typeId === Type.FixedSizeList;
1390
- }
1391
- static isMap(x) {
1392
- return x && x.typeId === Type.Map;
1393
- }
1394
- static isDictionary(x) {
1395
- return x && x.typeId === Type.Dictionary;
1396
- }
1397
- get typeId() {
1398
- return Type.NONE;
1399
- }
1400
- // get ArrayType(): AnyArrayType {
1401
- // return Int8Array;
1402
- // }
1403
- // get ArrayType() { return Array; }
1404
- compareTo(other) {
1405
- return this === other;
1406
- }
1407
- };
1408
- var Null = class extends DataType {
1409
- get typeId() {
1410
- return Type.Null;
1411
- }
1412
- get [Symbol.toStringTag]() {
1413
- return "Null";
1414
- }
1415
- toString() {
1416
- return "Null";
1417
- }
1418
- };
1419
- var Bool = class extends DataType {
1420
- get typeId() {
1421
- return Type.Bool;
1422
- }
1423
- // get ArrayType() {
1424
- // return Uint8Array;
1425
- // }
1426
- get [Symbol.toStringTag]() {
1427
- return "Bool";
1428
- }
1429
- toString() {
1430
- return "Bool";
1431
- }
1432
- };
1433
- var Int = class extends DataType {
1434
- isSigned;
1435
- bitWidth;
1436
- constructor(isSigned, bitWidth) {
1437
- super();
1438
- this.isSigned = isSigned;
1439
- this.bitWidth = bitWidth;
1440
- }
1441
- get typeId() {
1442
- return Type.Int;
1443
- }
1444
- // get ArrayType() {
1445
- // switch (this.bitWidth) {
1446
- // case 8:
1447
- // return this.isSigned ? Int8Array : Uint8Array;
1448
- // case 16:
1449
- // return this.isSigned ? Int16Array : Uint16Array;
1450
- // case 32:
1451
- // return this.isSigned ? Int32Array : Uint32Array;
1452
- // case 64:
1453
- // return this.isSigned ? Int32Array : Uint32Array;
1454
- // default:
1455
- // throw new Error(`Unrecognized ${this[Symbol.toStringTag]} type`);
1456
- // }
1457
- // }
1458
- get [Symbol.toStringTag]() {
1459
- return "Int";
1460
- }
1461
- toString() {
1462
- return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
1463
- }
1464
- };
1465
- var Int8 = class extends Int {
1466
- constructor() {
1467
- super(true, 8);
1468
- }
1469
- };
1470
- var Int16 = class extends Int {
1471
- constructor() {
1472
- super(true, 16);
1473
- }
1474
- };
1475
- var Int32 = class extends Int {
1476
- constructor() {
1477
- super(true, 32);
1478
- }
1479
- };
1480
- var Int64 = class extends Int {
1481
- constructor() {
1482
- super(true, 64);
1483
- }
1484
- };
1485
- var Uint8 = class extends Int {
1486
- constructor() {
1487
- super(false, 8);
1488
- }
1489
- };
1490
- var Uint16 = class extends Int {
1491
- constructor() {
1492
- super(false, 16);
1493
- }
1494
- };
1495
- var Uint32 = class extends Int {
1496
- constructor() {
1497
- super(false, 32);
1498
- }
1499
- };
1500
- var Uint64 = class extends Int {
1501
- constructor() {
1502
- super(false, 64);
1503
- }
1504
- };
1505
- var Precision = {
1506
- HALF: 16,
1507
- SINGLE: 32,
1508
- DOUBLE: 64
1509
- };
1510
- var Float = class extends DataType {
1511
- precision;
1512
- constructor(precision) {
1513
- super();
1514
- this.precision = precision;
1515
- }
1516
- get typeId() {
1517
- return Type.Float;
1518
- }
1519
- // get ArrayType() {
1520
- // switch (this.precision) {
1521
- // case Precision.HALF:
1522
- // return Uint16Array;
1523
- // case Precision.SINGLE:
1524
- // return Float32Array;
1525
- // case Precision.DOUBLE:
1526
- // return Float64Array;
1527
- // default:
1528
- // throw new Error(`Unrecognized ${this[Symbol.toStringTag]} type`);
1529
- // }
1530
- // }
1531
- get [Symbol.toStringTag]() {
1532
- return "Float";
1533
- }
1534
- toString() {
1535
- return `Float${this.precision}`;
1536
- }
1537
- };
1538
- var Float16 = class extends Float {
1539
- constructor() {
1540
- super(Precision.HALF);
1541
- }
1542
- };
1543
- var Float32 = class extends Float {
1544
- constructor() {
1545
- super(Precision.SINGLE);
1546
- }
1547
- };
1548
- var Float64 = class extends Float {
1549
- constructor() {
1550
- super(Precision.DOUBLE);
1551
- }
1552
- };
1553
- var Binary = class extends DataType {
1554
- constructor() {
1555
- super();
1556
- }
1557
- get typeId() {
1558
- return Type.Binary;
1559
- }
1560
- toString() {
1561
- return "Binary";
1562
- }
1563
- get [Symbol.toStringTag]() {
1564
- return "Binary";
1565
- }
1566
- };
1567
- var Utf8 = class extends DataType {
1568
- get typeId() {
1569
- return Type.Utf8;
1570
- }
1571
- // get ArrayType() {
1572
- // return Uint8Array;
1573
- // }
1574
- get [Symbol.toStringTag]() {
1575
- return "Utf8";
1576
- }
1577
- toString() {
1578
- return "Utf8";
1579
- }
1580
- };
1581
- var DateUnit = {
1582
- DAY: 0,
1583
- MILLISECOND: 1
1584
- };
1585
- var Date2 = class extends DataType {
1586
- unit;
1587
- constructor(unit) {
1588
- super();
1589
- this.unit = unit;
1590
- }
1591
- get typeId() {
1592
- return Type.Date;
1593
- }
1594
- // get ArrayType() {
1595
- // return Int32Array;
1596
- // }
1597
- get [Symbol.toStringTag]() {
1598
- return "Date";
1599
- }
1600
- toString() {
1601
- return `Date${(this.unit + 1) * 32}<${DateUnit[this.unit]}>`;
1602
- }
1603
- };
1604
- var DateDay = class extends Date2 {
1605
- constructor() {
1606
- super(DateUnit.DAY);
1607
- }
1608
- };
1609
- var DateMillisecond = class extends Date2 {
1610
- constructor() {
1611
- super(DateUnit.MILLISECOND);
1612
- }
1613
- };
1614
- var TimeUnit = {
1615
- SECOND: 1,
1616
- MILLISECOND: 1e3,
1617
- MICROSECOND: 1e6,
1618
- NANOSECOND: 1e9
1619
- };
1620
- var Time = class extends DataType {
1621
- unit;
1622
- bitWidth;
1623
- constructor(unit, bitWidth) {
1624
- super();
1625
- this.unit = unit;
1626
- this.bitWidth = bitWidth;
1627
- }
1628
- get typeId() {
1629
- return Type.Time;
1630
- }
1631
- toString() {
1632
- return `Time${this.bitWidth}<${TimeUnit[this.unit]}>`;
1633
- }
1634
- get [Symbol.toStringTag]() {
1635
- return "Time";
1636
- }
1637
- };
1638
- var TimeSecond = class extends Time {
1639
- constructor() {
1640
- super(TimeUnit.SECOND, 32);
1641
- }
1642
- };
1643
- var TimeMillisecond = class extends Time {
1644
- constructor() {
1645
- super(TimeUnit.MILLISECOND, 32);
1646
- }
1647
- };
1648
- var Timestamp = class extends DataType {
1649
- unit;
1650
- timezone;
1651
- constructor(unit, timezone = null) {
1652
- super();
1653
- this.unit = unit;
1654
- this.timezone = timezone;
1655
- }
1656
- get typeId() {
1657
- return Type.Timestamp;
1658
- }
1659
- // get ArrayType() {
1660
- // return Int32Array;
1661
- // }
1662
- get [Symbol.toStringTag]() {
1663
- return "Timestamp";
1664
- }
1665
- toString() {
1666
- return `Timestamp<${TimeUnit[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
1667
- }
1668
- };
1669
- var TimestampSecond = class extends Timestamp {
1670
- constructor(timezone = null) {
1671
- super(TimeUnit.SECOND, timezone);
1672
- }
1673
- };
1674
- var TimestampMillisecond = class extends Timestamp {
1675
- constructor(timezone = null) {
1676
- super(TimeUnit.MILLISECOND, timezone);
1677
- }
1678
- };
1679
- var TimestampMicrosecond = class extends Timestamp {
1680
- constructor(timezone = null) {
1681
- super(TimeUnit.MICROSECOND, timezone);
1682
- }
1683
- };
1684
- var TimestampNanosecond = class extends Timestamp {
1685
- constructor(timezone = null) {
1686
- super(TimeUnit.NANOSECOND, timezone);
1687
- }
1688
- };
1689
- var IntervalUnit = {
1690
- DAY_TIME: 0,
1691
- YEAR_MONTH: 1
1692
- };
1693
- var Interval = class extends DataType {
1694
- unit;
1695
- constructor(unit) {
1696
- super();
1697
- this.unit = unit;
1698
- }
1699
- get typeId() {
1700
- return Type.Interval;
1701
- }
1702
- // get ArrayType() {
1703
- // return Int32Array;
1704
- // }
1705
- get [Symbol.toStringTag]() {
1706
- return "Interval";
1707
- }
1708
- toString() {
1709
- return `Interval<${IntervalUnit[this.unit]}>`;
1710
- }
1711
- };
1712
- var IntervalDayTime = class extends Interval {
1713
- constructor() {
1714
- super(IntervalUnit.DAY_TIME);
1715
- }
1716
- };
1717
- var IntervalYearMonth = class extends Interval {
1718
- constructor() {
1719
- super(IntervalUnit.YEAR_MONTH);
1720
- }
1721
- };
1722
- var FixedSizeList = class extends DataType {
1723
- listSize;
1724
- children;
1725
- constructor(listSize, child) {
1726
- super();
1727
- this.listSize = listSize;
1728
- this.children = [child];
1729
- }
1730
- get typeId() {
1731
- return Type.FixedSizeList;
1732
- }
1733
- get valueType() {
1734
- return this.children[0].type;
1735
- }
1736
- get valueField() {
1737
- return this.children[0];
1738
- }
1739
- // get ArrayType() {
1740
- // return this.valueType.ArrayType;
1741
- // }
1742
- get [Symbol.toStringTag]() {
1743
- return "FixedSizeList";
1744
- }
1745
- toString() {
1746
- return `FixedSizeList[${this.listSize}]<${JSON.stringify(this.valueType)}>`;
1747
- }
1748
- };
1749
- var Struct = class extends DataType {
1750
- children;
1751
- constructor(children) {
1752
- super();
1753
- this.children = children;
1754
- }
1755
- get typeId() {
1756
- return Type.Struct;
1757
- }
1758
- toString() {
1759
- return `Struct<{${this.children.map((f) => `${f.name}:${JSON.stringify(f.type)}`).join(", ")}}>`;
1760
- }
1761
- get [Symbol.toStringTag]() {
1762
- return "Struct";
1763
- }
1764
- };
1765
-
1766
- // dist/lib/table/arrow-api/get-type-info.js
1767
- function getTypeInfo(arrowTypeLike) {
1768
- return {
1769
- typeId: arrowTypeLike.typeId,
1770
- ArrayType: arrowTypeLike.ArrayType,
1771
- typeName: arrowTypeLike.toString(),
1772
- typeEnumName: getTypeKey(arrowTypeLike.typeId),
1773
- precision: arrowTypeLike.precision
1774
- };
1775
- }
1776
- var ReverseType = null;
1777
- function getTypeKey(typeKey) {
1778
- if (!ReverseType) {
1779
- ReverseType = {};
1780
- for (const key in Type) {
1781
- ReverseType[Type[key]] = key;
1782
- }
1783
- }
1784
- return ReverseType[typeKey];
1785
- }
1786
-
1787
- // dist/lib/utils/async-queue.js
1788
- var ArrayQueue = class extends Array {
1789
- enqueue(value) {
1790
- return this.push(value);
1791
- }
1792
- dequeue() {
1793
- return this.shift();
1794
- }
1795
- };
1796
- var AsyncQueue = class {
1797
- _values;
1798
- _settlers;
1799
- _closed;
1800
- constructor() {
1801
- this._values = new ArrayQueue();
1802
- this._settlers = new ArrayQueue();
1803
- this._closed = false;
1804
- }
1805
- close() {
1806
- while (this._settlers.length > 0) {
1807
- this._settlers.dequeue().resolve({ done: true });
1808
- }
1809
- this._closed = true;
1810
- }
1811
- [Symbol.asyncIterator]() {
1812
- return this;
1813
- }
1814
- enqueue(value) {
1815
- if (this._closed) {
1816
- throw new Error("Closed");
1817
- }
1818
- if (this._settlers.length > 0) {
1819
- if (this._values.length > 0) {
1820
- throw new Error("Illegal internal state");
1821
- }
1822
- const settler = this._settlers.dequeue();
1823
- if (value instanceof Error) {
1824
- settler.reject(value);
1825
- } else {
1826
- settler.resolve({ value });
1827
- }
1828
- } else {
1829
- this._values.enqueue(value);
1830
- }
1831
- }
1832
- /**
1833
- * @returns a Promise for an IteratorResult
1834
- */
1835
- next() {
1836
- if (this._values.length > 0) {
1837
- const value = this._values.dequeue();
1838
- if (value instanceof Error) {
1839
- return Promise.reject(value);
1840
- }
1841
- return Promise.resolve({ value });
1842
- }
1843
- if (this._closed) {
1844
- if (this._settlers.length > 0) {
1845
- throw new Error("Illegal internal state");
1846
- }
1847
- return Promise.resolve({ done: true });
1848
- }
1849
- return new Promise((resolve, reject) => {
1850
- this._settlers.enqueue({ resolve, reject });
1851
- });
1852
- }
1853
- };
1854
64
  //# sourceMappingURL=index.cjs.map