@loaders.gl/schema 4.0.0-alpha.9 → 4.0.0-beta.1

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 (112) hide show
  1. package/dist/dist.min.js +558 -943
  2. package/dist/es5/index.js +7 -0
  3. package/dist/es5/index.js.map +1 -1
  4. package/dist/es5/lib/table/arrow-api/arrow-like-table.js +4 -3
  5. package/dist/es5/lib/table/arrow-api/arrow-like-table.js.map +1 -1
  6. package/dist/es5/lib/table/batches/row-table-batch-aggregator.js.map +1 -1
  7. package/dist/es5/lib/table/simple-table/convert-table.js +24 -0
  8. package/dist/es5/lib/table/simple-table/convert-table.js.map +1 -1
  9. package/dist/es5/lib/table/simple-table/table-accessors.js +69 -42
  10. package/dist/es5/lib/table/simple-table/table-accessors.js.map +1 -1
  11. package/dist/es5/types/batch.js +2 -0
  12. package/dist/es5/types/batch.js.map +1 -0
  13. package/dist/es5/types/binary-geometries.js +2 -0
  14. package/dist/es5/types/binary-geometries.js.map +1 -0
  15. package/dist/es5/types/category-gis.js.map +1 -1
  16. package/dist/es5/types/category-image.js.map +1 -1
  17. package/dist/es5/types/category-table.js.map +1 -1
  18. package/dist/es5/types/flat-geometries.js +2 -0
  19. package/dist/es5/types/flat-geometries.js.map +1 -0
  20. package/dist/es5/types/schema.js.map +1 -1
  21. package/dist/esm/index.js +1 -0
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/lib/table/arrow-api/arrow-like-table.js +4 -3
  24. package/dist/esm/lib/table/arrow-api/arrow-like-table.js.map +1 -1
  25. package/dist/esm/lib/table/batches/row-table-batch-aggregator.js.map +1 -1
  26. package/dist/esm/lib/table/simple-table/convert-table.js +22 -0
  27. package/dist/esm/lib/table/simple-table/convert-table.js.map +1 -1
  28. package/dist/esm/lib/table/simple-table/table-accessors.js +49 -22
  29. package/dist/esm/lib/table/simple-table/table-accessors.js.map +1 -1
  30. package/dist/esm/types/batch.js +2 -0
  31. package/dist/esm/types/batch.js.map +1 -0
  32. package/dist/esm/types/binary-geometries.js +2 -0
  33. package/dist/esm/types/binary-geometries.js.map +1 -0
  34. package/dist/esm/types/category-gis.js.map +1 -1
  35. package/dist/esm/types/category-image.js.map +1 -1
  36. package/dist/esm/types/category-table.js.map +1 -1
  37. package/dist/esm/types/flat-geometries.js +2 -0
  38. package/dist/esm/types/flat-geometries.js.map +1 -0
  39. package/dist/esm/types/schema.js.map +1 -1
  40. package/dist/index.d.ts +7 -5
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/lib/table/arrow-api/arrow-like-table.d.ts +1 -5
  43. package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -1
  44. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +3 -3
  45. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +1 -1
  46. package/dist/lib/table/simple-table/convert-table.d.ts +34 -1
  47. package/dist/lib/table/simple-table/convert-table.d.ts.map +1 -1
  48. package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -1
  49. package/dist/types/batch.d.ts +34 -0
  50. package/dist/types/batch.d.ts.map +1 -0
  51. package/dist/types/binary-geometries.d.ts +56 -0
  52. package/dist/types/binary-geometries.d.ts.map +1 -0
  53. package/dist/types/category-gis.d.ts +3 -84
  54. package/dist/types/category-gis.d.ts.map +1 -1
  55. package/dist/types/category-image.d.ts +1 -1
  56. package/dist/types/category-image.d.ts.map +1 -1
  57. package/dist/types/category-table.d.ts +42 -22
  58. package/dist/types/category-table.d.ts.map +1 -1
  59. package/dist/types/flat-geometries.d.ts +30 -0
  60. package/dist/types/flat-geometries.d.ts.map +1 -0
  61. package/dist/types/schema.d.ts +0 -15
  62. package/dist/types/schema.d.ts.map +1 -1
  63. package/package.json +2 -2
  64. package/src/index.ts +13 -7
  65. package/src/lib/table/arrow-api/arrow-like-table.ts +3 -2
  66. package/src/lib/table/batches/row-table-batch-aggregator.ts +2 -2
  67. package/src/lib/table/simple-table/convert-table.ts +73 -1
  68. package/src/lib/table/simple-table/table-accessors.ts +56 -22
  69. package/src/types/batch.ts +41 -0
  70. package/src/types/binary-geometries.ts +62 -0
  71. package/src/types/category-gis.ts +30 -104
  72. package/src/types/category-image.ts +1 -1
  73. package/src/types/category-table.ts +49 -27
  74. package/src/types/flat-geometries.ts +40 -0
  75. package/src/types/schema.ts +0 -17
  76. package/dist/bundle.js +0 -5
  77. package/dist/index.js +0 -92
  78. package/dist/lib/mesh/convert-mesh.js +0 -40
  79. package/dist/lib/mesh/deduce-mesh-schema.js +0 -66
  80. package/dist/lib/mesh/mesh-to-arrow-table.js +0 -44
  81. package/dist/lib/mesh/mesh-utils.js +0 -51
  82. package/dist/lib/table/arrow/arrow-type-utils.js +0 -53
  83. package/dist/lib/table/arrow/convert-schema-arrow.js +0 -187
  84. package/dist/lib/table/arrow/convert-table-to-arrow.js +0 -57
  85. package/dist/lib/table/arrow-api/arrow-like-field.js +0 -34
  86. package/dist/lib/table/arrow-api/arrow-like-schema.js +0 -81
  87. package/dist/lib/table/arrow-api/arrow-like-table.js +0 -53
  88. package/dist/lib/table/arrow-api/arrow-like-type.js +0 -463
  89. package/dist/lib/table/arrow-api/enum.js +0 -97
  90. package/dist/lib/table/arrow-api/get-type-info.js +0 -29
  91. package/dist/lib/table/arrow-api/index.js +0 -25
  92. package/dist/lib/table/batches/base-table-batch-aggregator.js +0 -60
  93. package/dist/lib/table/batches/columnar-table-batch-aggregator.js +0 -92
  94. package/dist/lib/table/batches/row-table-batch-aggregator.js +0 -81
  95. package/dist/lib/table/batches/table-batch-aggregator.js +0 -3
  96. package/dist/lib/table/batches/table-batch-builder.js +0 -152
  97. package/dist/lib/table/simple-table/convert-table.js +0 -65
  98. package/dist/lib/table/simple-table/data-type.js +0 -93
  99. package/dist/lib/table/simple-table/make-table.js +0 -95
  100. package/dist/lib/table/simple-table/row-utils.js +0 -33
  101. package/dist/lib/table/simple-table/table-accessors.js +0 -319
  102. package/dist/lib/table/simple-table/table-column.js +0 -41
  103. package/dist/lib/table/simple-table/table-schema.js +0 -85
  104. package/dist/lib/utils/assert.js +0 -12
  105. package/dist/lib/utils/async-queue.js +0 -92
  106. package/dist/types/category-gis.js +0 -2
  107. package/dist/types/category-image.js +0 -2
  108. package/dist/types/category-mesh.js +0 -3
  109. package/dist/types/category-table.js +0 -3
  110. package/dist/types/category-texture.js +0 -3
  111. package/dist/types/schema.js +0 -3
  112. package/dist/types/types.js +0 -2
@@ -1,319 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.makeObjectRowIterator = exports.makeArrayRowIterator = exports.makeRowIterator = exports.makeColumnarTable = exports.makeObjectRowTable = exports.makeArrayRowTable = exports.getTableRowAsArray = exports.getTableRowAsObject = exports.getTableColumnName = exports.getTableColumnIndex = exports.getTableRowShape = exports.getTableCellAt = exports.getTableCell = exports.getTableNumCols = exports.getTableLength = void 0;
5
- /**
6
- * Returns the length of the table (i.e. the number of rows)
7
- */
8
- function getTableLength(table) {
9
- switch (table.shape) {
10
- case 'array-row-table':
11
- case 'object-row-table':
12
- case 'geojson-row-table':
13
- return table.data.length;
14
- case 'arrow-table':
15
- return table.data.numRows;
16
- case 'columnar-table':
17
- for (const column of Object.values(table.data)) {
18
- return column.length || 0;
19
- }
20
- return 0;
21
- default:
22
- throw new Error('table');
23
- }
24
- }
25
- exports.getTableLength = getTableLength;
26
- /**
27
- * Returns the number of columns in the table
28
- * @throws Fails to deduce number of columns if the table has no schema and is empty
29
- */
30
- function getTableNumCols(table) {
31
- if (table.schema) {
32
- return table.schema.fields.length;
33
- }
34
- if (getTableLength(table) === 0) {
35
- throw new Error('empty table');
36
- }
37
- switch (table.shape) {
38
- case 'array-row-table':
39
- return table.data[0].length;
40
- case 'object-row-table':
41
- case 'geojson-row-table':
42
- return Object.keys(table.data[0]).length;
43
- case 'columnar-table':
44
- return Object.keys(table.data).length;
45
- case 'arrow-table':
46
- return table.data.numCols;
47
- default:
48
- throw new Error('table');
49
- }
50
- }
51
- exports.getTableNumCols = getTableNumCols;
52
- /** Get a table cell value at row index and column name */
53
- function getTableCell(table, rowIndex, columnName) {
54
- switch (table.shape) {
55
- case 'array-row-table':
56
- const columnIndex = getTableColumnIndex(table, columnName);
57
- return table.data[rowIndex][columnIndex];
58
- case 'object-row-table':
59
- case 'geojson-row-table':
60
- return table.data[rowIndex][columnName];
61
- case 'columnar-table':
62
- const column = table.data[columnName];
63
- return column[rowIndex];
64
- case 'arrow-table':
65
- const arrowColumnIndex = table.data.schema.fields.findIndex((field) => field.name === columnName);
66
- return table.data.getChildAt(arrowColumnIndex)?.get(rowIndex);
67
- default:
68
- throw new Error('todo');
69
- }
70
- }
71
- exports.getTableCell = getTableCell;
72
- /** Get a table cell value at row index and column name */
73
- function getTableCellAt(table, rowIndex, columnIndex) {
74
- switch (table.shape) {
75
- case 'array-row-table':
76
- return table.data[rowIndex][columnIndex];
77
- case 'object-row-table':
78
- case 'geojson-row-table':
79
- let columnName = getTableColumnName(table, columnIndex);
80
- return table.data[rowIndex][columnName];
81
- case 'columnar-table':
82
- columnName = getTableColumnName(table, columnIndex);
83
- const column = table.data[columnName];
84
- return column[rowIndex];
85
- case 'arrow-table':
86
- return table.data.getChildAt(columnIndex)?.get(rowIndex);
87
- default:
88
- throw new Error('todo');
89
- }
90
- }
91
- exports.getTableCellAt = getTableCellAt;
92
- /** Deduce the table row shape */
93
- function getTableRowShape(table) {
94
- switch (table.shape) {
95
- case 'array-row-table':
96
- case 'object-row-table':
97
- return table.shape;
98
- case 'geojson-row-table':
99
- return 'object-row-table';
100
- case 'columnar-table':
101
- default:
102
- throw new Error('Not a row table');
103
- }
104
- }
105
- exports.getTableRowShape = getTableRowShape;
106
- /** Get the index of a named table column. Requires the table to have a schema */
107
- function getTableColumnIndex(table, columnName) {
108
- const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
109
- if (columnIndex === undefined) {
110
- throw new Error(columnName);
111
- }
112
- return columnIndex;
113
- }
114
- exports.getTableColumnIndex = getTableColumnIndex;
115
- /** Get the name of a table column by index. Requires the table to have a schema */
116
- function getTableColumnName(table, columnIndex) {
117
- const columnName = table.schema?.fields[columnIndex]?.name;
118
- if (!columnName) {
119
- throw new Error(`${columnIndex}`);
120
- }
121
- return columnName;
122
- }
123
- exports.getTableColumnName = getTableColumnName;
124
- /**
125
- * Returns one row of the table in object format.
126
- * @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance
127
- * @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
128
- */
129
- // eslint-disable-next-line complexity
130
- function getTableRowAsObject(table, rowIndex, target, copy) {
131
- switch (table.shape) {
132
- case 'object-row-table':
133
- return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
134
- case 'array-row-table':
135
- case 'geojson-row-table':
136
- if (table.schema) {
137
- const objectRow = target || {};
138
- for (let i = 0; i < table.schema.fields.length; i++) {
139
- objectRow[table.schema.fields[i].name] = table.data[rowIndex][i];
140
- }
141
- return objectRow;
142
- }
143
- throw new Error('no schema');
144
- case 'columnar-table':
145
- if (table.schema) {
146
- const objectRow = target || {};
147
- for (let i = 0; i < table.schema.fields.length; i++) {
148
- objectRow[table.schema.fields[i].name] =
149
- table.data[table.schema.fields[i].name][rowIndex];
150
- }
151
- return objectRow;
152
- }
153
- else {
154
- // eslint-disable-line no-else-return
155
- const objectRow = target || {};
156
- for (const [name, column] of Object.entries(table.data)) {
157
- objectRow[name] = column[rowIndex];
158
- }
159
- return objectRow;
160
- }
161
- case 'arrow-table':
162
- const objectRow = target || {};
163
- const row = table.data.get(rowIndex);
164
- const schema = table.data.schema;
165
- for (let i = 0; i < schema.fields.length; i++) {
166
- objectRow[schema.fields[i].name] = row?.[schema.fields[i].name];
167
- }
168
- return objectRow;
169
- default:
170
- throw new Error('shape');
171
- }
172
- }
173
- exports.getTableRowAsObject = getTableRowAsObject;
174
- /**
175
- * Returns one row of the table in array format.
176
- * @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance.
177
- * @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
178
- */
179
- // eslint-disable-next-line complexity
180
- function getTableRowAsArray(table, rowIndex, target, copy) {
181
- switch (table.shape) {
182
- case 'array-row-table':
183
- return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
184
- case 'object-row-table':
185
- case 'geojson-row-table':
186
- if (table.schema) {
187
- const arrayRow = target || [];
188
- for (let i = 0; i < table.schema.fields.length; i++) {
189
- arrayRow[i] = table.data[rowIndex][table.schema.fields[i].name];
190
- }
191
- return arrayRow;
192
- }
193
- // Warning: just slap on the values, this risks mismatches between rows
194
- return Object.values(table.data[rowIndex]);
195
- case 'columnar-table':
196
- if (table.schema) {
197
- const arrayRow = target || [];
198
- for (let i = 0; i < table.schema.fields.length; i++) {
199
- arrayRow[i] = table.data[table.schema.fields[i].name][rowIndex];
200
- }
201
- return arrayRow;
202
- }
203
- else {
204
- // eslint-disable-line no-else-return
205
- const arrayRow = target || [];
206
- let i = 0;
207
- for (const column of Object.values(table.data)) {
208
- arrayRow[i] = column[rowIndex];
209
- i++;
210
- }
211
- return arrayRow;
212
- }
213
- case 'arrow-table':
214
- const arrayRow = target || [];
215
- const row = table.data.get(rowIndex);
216
- const schema = table.data.schema;
217
- for (let i = 0; i < schema.fields.length; i++) {
218
- arrayRow[i] = row?.[schema.fields[i].name];
219
- }
220
- return arrayRow;
221
- default:
222
- throw new Error('shape');
223
- }
224
- }
225
- exports.getTableRowAsArray = getTableRowAsArray;
226
- /** Convert any table into array row format */
227
- function makeArrayRowTable(table) {
228
- if (table.shape === 'array-row-table') {
229
- return table;
230
- }
231
- const length = getTableLength(table);
232
- const data = new Array(length);
233
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
234
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
235
- }
236
- return {
237
- shape: 'array-row-table',
238
- schema: table.schema,
239
- data
240
- };
241
- }
242
- exports.makeArrayRowTable = makeArrayRowTable;
243
- /** Convert any table into object row format */
244
- function makeObjectRowTable(table) {
245
- if (table.shape === 'object-row-table') {
246
- return table;
247
- }
248
- const length = getTableLength(table);
249
- const data = new Array(length);
250
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
251
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
252
- }
253
- return {
254
- shape: 'object-row-table',
255
- schema: table.schema,
256
- data
257
- };
258
- }
259
- exports.makeObjectRowTable = makeObjectRowTable;
260
- /** Convert any table into object row format */
261
- function makeColumnarTable(table) {
262
- if (table.shape === 'object-row-table') {
263
- return table;
264
- }
265
- const length = getTableLength(table);
266
- const data = new Array(length);
267
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
268
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
269
- }
270
- return {
271
- shape: 'object-row-table',
272
- schema: table.schema,
273
- data
274
- };
275
- }
276
- exports.makeColumnarTable = makeColumnarTable;
277
- // Row Iterators
278
- /**
279
- * Iterate over table rows
280
- * @param table
281
- * @param shape
282
- */
283
- function* makeRowIterator(table, shape) {
284
- switch (shape) {
285
- case 'array-row-table':
286
- yield* makeArrayRowIterator(table);
287
- break;
288
- case 'object-row-table':
289
- yield* makeObjectRowIterator(table);
290
- break;
291
- default:
292
- throw new Error(`Unknown row type ${shape}`);
293
- }
294
- }
295
- exports.makeRowIterator = makeRowIterator;
296
- /**
297
- * Streaming processing: Iterate over table, yielding array rows
298
- * @param table
299
- * @param shape
300
- */
301
- function* makeArrayRowIterator(table, target = []) {
302
- const length = getTableLength(table);
303
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
304
- yield getTableRowAsArray(table, rowIndex, target);
305
- }
306
- }
307
- exports.makeArrayRowIterator = makeArrayRowIterator;
308
- /**
309
- * Streaming processing: Iterate over table, yielding object rows
310
- * @param table
311
- * @param shape
312
- */
313
- function* makeObjectRowIterator(table, target = {}) {
314
- const length = getTableLength(table);
315
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
316
- yield getTableRowAsObject(table, rowIndex, target);
317
- }
318
- }
319
- exports.makeObjectRowIterator = makeObjectRowIterator;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.makeColumnFromField = void 0;
5
- const data_type_1 = require("./data-type");
6
- function makeColumnFromField(field, length) {
7
- const ArrayType = (0, data_type_1.getArrayTypeFromDataType)(field.type, field.nullable);
8
- return new ArrayType(length);
9
- }
10
- exports.makeColumnFromField = makeColumnFromField;
11
- /*
12
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
13
- function deduceSchema(rows) {
14
- const row = rows[0];
15
-
16
- const schema = {};
17
- let i = 0;
18
- for (const columnName in row) {
19
- const value = row[columnName];
20
- switch (typeof value) {
21
- case 'number':
22
- case 'boolean':
23
- // TODO - booleans could be handled differently...
24
- schema[columnName] = {name: String(columnName), index: i, type: Float32Array};
25
- break;
26
-
27
- case 'object':
28
- schema[columnName] = {name: String(columnName), index: i, type: Array};
29
- break;
30
-
31
- case 'string':
32
- default:
33
- schema[columnName] = {name: String(columnName), index: i, type: Array};
34
- // We currently only handle numeric rows
35
- // TODO we could offer a function to map strings to numbers?
36
- }
37
- i++;
38
- }
39
- return schema;
40
- }
41
- */
@@ -1,85 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deduceSchema = exports.deduceTableSchema = void 0;
4
- const data_type_1 = require("./data-type");
5
- /**
6
- * SCHEMA SUPPORT - AUTODEDUCTION
7
- * @param {*} table
8
- * @param {*} schema
9
- * @returns
10
- */
11
- function deduceTableSchema(table) {
12
- switch (table.shape) {
13
- case 'array-row-table':
14
- case 'object-row-table':
15
- return deduceSchemaFromRows(table.data);
16
- case 'columnar-table':
17
- return deduceSchemaFromColumns(table.data);
18
- case 'arrow-table':
19
- default:
20
- throw new Error('Deduce schema');
21
- }
22
- }
23
- exports.deduceTableSchema = deduceTableSchema;
24
- function deduceSchema(data) {
25
- return Array.isArray(data) ? deduceSchemaFromRows(data) : deduceSchemaFromColumns(data);
26
- }
27
- exports.deduceSchema = deduceSchema;
28
- /** Given an object with columnar arrays, try to deduce a schema */
29
- function deduceSchemaFromColumns(columnarTable) {
30
- const fields = [];
31
- for (const [columnName, column] of Object.entries(columnarTable)) {
32
- const field = deduceFieldFromColumn(column, columnName);
33
- fields.push(field);
34
- }
35
- return { fields, metadata: {} };
36
- }
37
- /** Given an array of rows, try to deduce a schema */
38
- function deduceSchemaFromRows(rowTable) {
39
- if (!rowTable.length) {
40
- throw new Error('deduce from empty table');
41
- }
42
- const fields = [];
43
- const row0 = rowTable[0];
44
- // TODO - fields can be nullable, false detection...
45
- // Could look at additional rows if nulls in first row
46
- // TODO - if array, column names will be numbers
47
- for (const [columnName, value] of Object.entries(row0)) {
48
- fields.push(deduceFieldFromValue(value, columnName));
49
- }
50
- return { fields, metadata: {} };
51
- }
52
- /** Given a column (i.e. array), attempt to deduce an appropriate `Field` */
53
- function deduceFieldFromColumn(column, name) {
54
- if (ArrayBuffer.isView(column)) {
55
- const type = (0, data_type_1.getDataTypeFromArray)(column);
56
- return {
57
- name,
58
- type: type.type || 'null',
59
- nullable: type.nullable
60
- // metadata: {}
61
- };
62
- }
63
- if (Array.isArray(column) && column.length > 0) {
64
- const value = column[0];
65
- const type = (0, data_type_1.getDataTypeFromValue)(value);
66
- // TODO - support nested schemas?
67
- return {
68
- name,
69
- type,
70
- nullable: true
71
- // metadata: {},
72
- };
73
- }
74
- throw new Error('empty table');
75
- }
76
- /** Given a value, attempt to deduce an appropriate `Field` */
77
- function deduceFieldFromValue(value, name) {
78
- const type = (0, data_type_1.getDataTypeFromValue)(value);
79
- return {
80
- name,
81
- type,
82
- nullable: true
83
- // metadata: {}
84
- };
85
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assert = void 0;
4
- // Replacement for the external assert method to reduce bundle size
5
- // Note: We don't use the second "message" argument in calling code,
6
- // so no need to support it here
7
- function assert(condition, message) {
8
- if (!condition) {
9
- throw new Error(message || 'loader assertion failed.');
10
- }
11
- }
12
- exports.assert = assert;
@@ -1,92 +0,0 @@
1
- "use strict";
2
- // From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license
3
- // http://2ality.com/2016/10/asynchronous-iteration.html
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.takeAsync = void 0;
6
- class ArrayQueue extends Array {
7
- enqueue(value) {
8
- // Add at the end
9
- return this.push(value);
10
- }
11
- dequeue() {
12
- // Remove first element
13
- return this.shift();
14
- }
15
- }
16
- class AsyncQueue {
17
- constructor() {
18
- // enqueues > dequeues
19
- this._values = new ArrayQueue();
20
- // dequeues > enqueues
21
- this._settlers = new ArrayQueue();
22
- this._closed = false;
23
- }
24
- close() {
25
- while (this._settlers.length > 0) {
26
- this._settlers.dequeue().resolve({ done: true });
27
- }
28
- this._closed = true;
29
- }
30
- [Symbol.asyncIterator]() {
31
- return this;
32
- }
33
- enqueue(value) {
34
- if (this._closed) {
35
- throw new Error('Closed');
36
- }
37
- if (this._settlers.length > 0) {
38
- if (this._values.length > 0) {
39
- throw new Error('Illegal internal state');
40
- }
41
- const settler = this._settlers.dequeue();
42
- if (value instanceof Error) {
43
- settler.reject(value);
44
- }
45
- else {
46
- settler.resolve({ value });
47
- }
48
- }
49
- else {
50
- this._values.enqueue(value);
51
- }
52
- }
53
- /**
54
- * @returns a Promise for an IteratorResult
55
- */
56
- next() {
57
- if (this._values.length > 0) {
58
- const value = this._values.dequeue();
59
- if (value instanceof Error) {
60
- return Promise.reject(value);
61
- }
62
- return Promise.resolve({ value });
63
- }
64
- if (this._closed) {
65
- if (this._settlers.length > 0) {
66
- throw new Error('Illegal internal state');
67
- }
68
- return Promise.resolve({ done: true });
69
- }
70
- // Wait for new values to be enqueued
71
- return new Promise((resolve, reject) => {
72
- this._settlers.enqueue({ resolve, reject });
73
- });
74
- }
75
- }
76
- exports.default = AsyncQueue;
77
- /**
78
- * @returns a Promise for an Array with the elements in `asyncIterable`
79
- */
80
- async function takeAsync(asyncIterable, count = Infinity) {
81
- const result = [];
82
- const iterator = asyncIterable[Symbol.asyncIterator]();
83
- while (result.length < count) {
84
- const { value, done } = await iterator.next();
85
- if (done) {
86
- break;
87
- }
88
- result.push(value);
89
- }
90
- return result;
91
- }
92
- exports.takeAsync = takeAsync;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,3 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });