@loaders.gl/schema 4.3.1 → 4.4.0-alpha.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 (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
@@ -1,350 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- export function isTable(table) {
5
- const shape = typeof table === 'object' && table?.shape;
6
- switch (shape) {
7
- case 'array-row-table':
8
- case 'object-row-table':
9
- return Array.isArray(table.data);
10
- case 'geojson-table':
11
- return Array.isArray(table.features);
12
- case 'columnar-table':
13
- return table.data && typeof table.data === 'object';
14
- case 'arrow-table':
15
- return Boolean(table?.data?.numRows !== undefined);
16
- default:
17
- return false;
18
- }
19
- }
20
- /**
21
- * Returns the length of the table (i.e. the number of rows)
22
- */
23
- export function getTableLength(table) {
24
- switch (table.shape) {
25
- case 'array-row-table':
26
- case 'object-row-table':
27
- return table.data.length;
28
- case 'geojson-table':
29
- return table.features.length;
30
- case 'arrow-table':
31
- const arrowTable = table.data;
32
- return arrowTable.numRows;
33
- case 'columnar-table':
34
- for (const column of Object.values(table.data)) {
35
- return column.length || 0;
36
- }
37
- return 0;
38
- default:
39
- throw new Error('table');
40
- }
41
- }
42
- /**
43
- * Returns the number of columns in the table
44
- * @throws Fails to deduce number of columns if the table has no schema and is empty
45
- */
46
- export function getTableNumCols(table) {
47
- if (table.schema) {
48
- return table.schema.fields.length;
49
- }
50
- if (getTableLength(table) === 0) {
51
- throw new Error('empty table');
52
- }
53
- switch (table.shape) {
54
- case 'array-row-table':
55
- return table.data[0].length;
56
- case 'object-row-table':
57
- return Object.keys(table.data[0]).length;
58
- case 'geojson-table':
59
- return Object.keys(table.features[0]).length;
60
- case 'columnar-table':
61
- return Object.keys(table.data).length;
62
- case 'arrow-table':
63
- const arrowTable = table.data;
64
- return arrowTable.numCols;
65
- default:
66
- throw new Error('table');
67
- }
68
- }
69
- /** Get a table cell value at row index and column name */
70
- export function getTableCell(table, rowIndex, columnName) {
71
- switch (table.shape) {
72
- case 'array-row-table':
73
- const columnIndex = getTableColumnIndex(table, columnName);
74
- return table.data[rowIndex][columnIndex];
75
- case 'object-row-table':
76
- return table.data[rowIndex][columnName];
77
- case 'geojson-table':
78
- return table.features[rowIndex][columnName];
79
- case 'columnar-table':
80
- const column = table.data[columnName];
81
- return column[rowIndex];
82
- case 'arrow-table':
83
- const arrowTable = table.data;
84
- const arrowColumnIndex = arrowTable.schema.fields.findIndex((field) => field.name === columnName);
85
- return arrowTable.getChildAt(arrowColumnIndex)?.get(rowIndex);
86
- default:
87
- throw new Error('todo');
88
- }
89
- }
90
- /** Get a table cell value at row index and column name */
91
- export function getTableCellAt(table, rowIndex, columnIndex) {
92
- switch (table.shape) {
93
- case 'array-row-table':
94
- return table.data[rowIndex][columnIndex];
95
- case 'object-row-table':
96
- const columnName1 = getTableColumnName(table, columnIndex);
97
- return table.data[rowIndex][columnName1];
98
- case 'geojson-table':
99
- const columnName2 = getTableColumnName(table, columnIndex);
100
- return table.features[rowIndex][columnName2];
101
- case 'columnar-table':
102
- const columnName3 = getTableColumnName(table, columnIndex);
103
- const column = table.data[columnName3];
104
- return column[rowIndex];
105
- case 'arrow-table':
106
- const arrowTable = table.data;
107
- return arrowTable.getChildAt(columnIndex)?.get(rowIndex);
108
- default:
109
- throw new Error('todo');
110
- }
111
- }
112
- /** Deduce the table row shape */
113
- export function getTableRowShape(table) {
114
- switch (table.shape) {
115
- case 'array-row-table':
116
- case 'object-row-table':
117
- return table.shape;
118
- case 'geojson-table':
119
- // TODO - this is not correct, geojson-table is not a row table
120
- return 'object-row-table';
121
- case 'columnar-table':
122
- default:
123
- throw new Error('Not a row table');
124
- }
125
- }
126
- /** Get the index of a named table column. Requires the table to have a schema */
127
- export function getTableColumnIndex(table, columnName) {
128
- const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
129
- if (columnIndex === undefined) {
130
- throw new Error(columnName);
131
- }
132
- return columnIndex;
133
- }
134
- /** Get the name of a table column by index. Requires the table to have a schema */
135
- export function getTableColumnName(table, columnIndex) {
136
- const columnName = table.schema?.fields[columnIndex]?.name;
137
- if (!columnName) {
138
- throw new Error(`${columnIndex}`);
139
- }
140
- return columnName;
141
- }
142
- /**
143
- * Returns one row of the table in object format.
144
- * @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance
145
- * @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
146
- */
147
- // eslint-disable-next-line complexity
148
- export function getTableRowAsObject(table, rowIndex, target, copy) {
149
- switch (table.shape) {
150
- case 'object-row-table':
151
- return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
152
- case 'array-row-table':
153
- if (table.schema) {
154
- const objectRow = target || {};
155
- for (let i = 0; i < table.schema.fields.length; i++) {
156
- objectRow[table.schema.fields[i].name] = table.data[rowIndex][i];
157
- }
158
- return objectRow;
159
- }
160
- throw new Error('no schema');
161
- case 'geojson-table':
162
- if (table.schema) {
163
- const objectRow = target || {};
164
- // TODO - should lift properties to top level
165
- for (let i = 0; i < table.schema.fields.length; i++) {
166
- objectRow[table.schema.fields[i].name] = table.features[rowIndex][i];
167
- }
168
- return objectRow;
169
- }
170
- throw new Error('no schema');
171
- case 'columnar-table':
172
- if (table.schema) {
173
- const objectRow = target || {};
174
- for (let i = 0; i < table.schema.fields.length; i++) {
175
- objectRow[table.schema.fields[i].name] =
176
- table.data[table.schema.fields[i].name][rowIndex];
177
- }
178
- return objectRow;
179
- }
180
- else {
181
- // eslint-disable-line no-else-return
182
- const objectRow = target || {};
183
- for (const [name, column] of Object.entries(table.data)) {
184
- objectRow[name] = column[rowIndex];
185
- }
186
- return objectRow;
187
- }
188
- case 'arrow-table':
189
- const arrowTable = table.data;
190
- const objectRow = target || {};
191
- const row = arrowTable.get(rowIndex);
192
- const schema = arrowTable.schema;
193
- for (let i = 0; i < schema.fields.length; i++) {
194
- objectRow[schema.fields[i].name] = row?.[schema.fields[i].name];
195
- }
196
- return objectRow;
197
- default:
198
- throw new Error('shape');
199
- }
200
- }
201
- /**
202
- * Returns one row of the table in array format.
203
- * @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance.
204
- * @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
205
- */
206
- // eslint-disable-next-line complexity
207
- export function getTableRowAsArray(table, rowIndex, target, copy) {
208
- switch (table.shape) {
209
- case 'array-row-table':
210
- return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
211
- case 'object-row-table':
212
- if (table.schema) {
213
- const arrayRow = target || [];
214
- for (let i = 0; i < table.schema.fields.length; i++) {
215
- arrayRow[i] = table.data[rowIndex][table.schema.fields[i].name];
216
- }
217
- return arrayRow;
218
- }
219
- // Warning: just slap on the values, this risks mismatches between rows
220
- return Object.values(table.data[rowIndex]);
221
- case 'geojson-table':
222
- if (table.schema) {
223
- const arrayRow = target || [];
224
- // TODO - should lift properties to top level
225
- for (let i = 0; i < table.schema.fields.length; i++) {
226
- arrayRow[i] = table.features[rowIndex][table.schema.fields[i].name];
227
- }
228
- return arrayRow;
229
- }
230
- // Warning: just slap on the values, this risks mismatches between rows
231
- return Object.values(table.features[rowIndex]);
232
- case 'columnar-table':
233
- if (table.schema) {
234
- const arrayRow = target || [];
235
- for (let i = 0; i < table.schema.fields.length; i++) {
236
- arrayRow[i] = table.data[table.schema.fields[i].name][rowIndex];
237
- }
238
- return arrayRow;
239
- }
240
- else {
241
- // eslint-disable-line no-else-return
242
- const arrayRow = target || [];
243
- let i = 0;
244
- for (const column of Object.values(table.data)) {
245
- arrayRow[i] = column[rowIndex];
246
- i++;
247
- }
248
- return arrayRow;
249
- }
250
- case 'arrow-table':
251
- const arrowTable = table.data;
252
- const arrayRow = target || [];
253
- const row = arrowTable.get(rowIndex);
254
- const schema = arrowTable.schema;
255
- for (let i = 0; i < schema.fields.length; i++) {
256
- arrayRow[i] = row?.[schema.fields[i].name];
257
- }
258
- return arrayRow;
259
- default:
260
- throw new Error('shape');
261
- }
262
- }
263
- /** Convert any table into array row format */
264
- export function makeArrayRowTable(table) {
265
- if (table.shape === 'array-row-table') {
266
- return table;
267
- }
268
- const length = getTableLength(table);
269
- const data = new Array(length);
270
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
271
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
272
- }
273
- return {
274
- shape: 'array-row-table',
275
- schema: table.schema,
276
- data
277
- };
278
- }
279
- /** Convert any table into object row format */
280
- export function makeObjectRowTable(table) {
281
- if (table.shape === 'object-row-table') {
282
- return table;
283
- }
284
- const length = getTableLength(table);
285
- const data = new Array(length);
286
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
287
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
288
- }
289
- return {
290
- shape: 'object-row-table',
291
- schema: table.schema,
292
- data
293
- };
294
- }
295
- /** Convert any table into object row format */
296
- export function makeColumnarTable(table) {
297
- if (table.shape === 'object-row-table') {
298
- return table;
299
- }
300
- const length = getTableLength(table);
301
- const data = new Array(length);
302
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
303
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
304
- }
305
- return {
306
- shape: 'object-row-table',
307
- schema: table.schema,
308
- data
309
- };
310
- }
311
- // Row Iterators
312
- /**
313
- * Iterate over table rows
314
- * @param table
315
- * @param shape
316
- */
317
- export function* makeRowIterator(table, shape) {
318
- switch (shape) {
319
- case 'array-row-table':
320
- yield* makeArrayRowIterator(table);
321
- break;
322
- case 'object-row-table':
323
- yield* makeObjectRowIterator(table);
324
- break;
325
- default:
326
- throw new Error(`Unknown row type ${shape}`);
327
- }
328
- }
329
- /**
330
- * Streaming processing: Iterate over table, yielding array rows
331
- * @param table
332
- * @param shape
333
- */
334
- export function* makeArrayRowIterator(table, target = []) {
335
- const length = getTableLength(table);
336
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
337
- yield getTableRowAsArray(table, rowIndex, target);
338
- }
339
- }
340
- /**
341
- * Streaming processing: Iterate over table, yielding object rows
342
- * @param table
343
- * @param shape
344
- */
345
- export function* makeObjectRowIterator(table, target = {}) {
346
- const length = getTableLength(table);
347
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
348
- yield getTableRowAsObject(table, rowIndex, target);
349
- }
350
- }
@@ -1,7 +0,0 @@
1
- import { Field } from "../../../types/schema.js";
2
- export interface ArrayType<T = unknown> {
3
- readonly length: number;
4
- [n: number]: T;
5
- }
6
- export declare function makeColumnFromField(field: Field, length: number): ArrayType;
7
- //# sourceMappingURL=table-column.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"table-column.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/table-column.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,EAAC,iCAA8B;AAG5C,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC;CAChB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,CAG3E"}
@@ -1,39 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { getArrayTypeFromDataType } from "./data-type.js";
5
- export function makeColumnFromField(field, length) {
6
- const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
7
- return new ArrayType(length);
8
- }
9
- /*
10
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
11
- function deduceSchema(rows) {
12
- const row = rows[0];
13
-
14
- const schema = {};
15
- let i = 0;
16
- for (const columnName in row) {
17
- const value = row[columnName];
18
- switch (typeof value) {
19
- case 'number':
20
- case 'boolean':
21
- // TODO - booleans could be handled differently...
22
- schema[columnName] = {name: String(columnName), index: i, type: Float32Array};
23
- break;
24
-
25
- case 'object':
26
- schema[columnName] = {name: String(columnName), index: i, type: Array};
27
- break;
28
-
29
- case 'string':
30
- default:
31
- schema[columnName] = {name: String(columnName), index: i, type: Array};
32
- // We currently only handle numeric rows
33
- // TODO we could offer a function to map strings to numbers?
34
- }
35
- i++;
36
- }
37
- return schema;
38
- }
39
- */
@@ -1,15 +0,0 @@
1
- import { Schema } from "../../../types/schema.js";
2
- import { Table } from "../../../types/category-table.js";
3
- /**
4
- * SCHEMA SUPPORT - AUTODEDUCTION
5
- * @param {*} table
6
- * @param {*} schema
7
- * @returns
8
- */
9
- export declare function deduceTableSchema(table: Table): Schema;
10
- export declare function deduceSchema(data: unknown[][] | {
11
- [key: string]: unknown;
12
- }[] | {
13
- [key: string]: unknown[];
14
- }): Schema;
15
- //# sourceMappingURL=table-schema.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"table-schema.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/table-schema.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,MAAM,EAAQ,iCAA8B;AAEpD,OAAO,EAAC,KAAK,EAAC,yCAAsC;AAGpD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAgBtD;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EAAE,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,EAAE,CAAA;CAAC,GAC1E,MAAM,CAER"}
@@ -1,100 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { getDataTypeFromArray, getDataTypeFromValue } from "./data-type.js";
5
- /**
6
- * SCHEMA SUPPORT - AUTODEDUCTION
7
- * @param {*} table
8
- * @param {*} schema
9
- * @returns
10
- */
11
- export function deduceTableSchema(table) {
12
- switch (table.shape) {
13
- case 'array-row-table':
14
- case 'object-row-table':
15
- return deduceSchemaFromRows(table.data);
16
- case 'geojson-table':
17
- return deduceSchemaFromGeoJSON(table.features);
18
- case 'columnar-table':
19
- return deduceSchemaFromColumns(table.data);
20
- case 'arrow-table':
21
- default:
22
- throw new Error('Deduce schema');
23
- }
24
- }
25
- export function deduceSchema(data) {
26
- return Array.isArray(data) ? deduceSchemaFromRows(data) : deduceSchemaFromColumns(data);
27
- }
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 GeoJSON, try to deduce a schema */
53
- function deduceSchemaFromGeoJSON(features) {
54
- if (!features.length) {
55
- throw new Error('deduce from empty table');
56
- }
57
- const fields = [];
58
- const row0 = features[0].properties || {};
59
- // TODO - fields can be nullable, false detection...
60
- // Could look at additional rows if nulls in first row
61
- // TODO - if array, column names will be numbers
62
- for (const [columnName, value] of Object.entries(row0)) {
63
- fields.push(deduceFieldFromValue(value, columnName));
64
- }
65
- return { fields, metadata: {} };
66
- }
67
- /** Given a column (i.e. array), attempt to deduce an appropriate `Field` */
68
- function deduceFieldFromColumn(column, name) {
69
- if (ArrayBuffer.isView(column)) {
70
- const type = getDataTypeFromArray(column);
71
- return {
72
- name,
73
- type: type.type || 'null',
74
- nullable: type.nullable
75
- // metadata: {}
76
- };
77
- }
78
- if (Array.isArray(column) && column.length > 0) {
79
- const value = column[0];
80
- const type = getDataTypeFromValue(value);
81
- // TODO - support nested schemas?
82
- return {
83
- name,
84
- type,
85
- nullable: true
86
- // metadata: {},
87
- };
88
- }
89
- throw new Error('empty table');
90
- }
91
- /** Given a value, attempt to deduce an appropriate `Field` */
92
- function deduceFieldFromValue(value, name) {
93
- const type = getDataTypeFromValue(value);
94
- return {
95
- name,
96
- type,
97
- nullable: true
98
- // metadata: {}
99
- };
100
- }
@@ -1,2 +0,0 @@
1
- export declare function assert(condition: boolean, message?: string): void;
2
- //# sourceMappingURL=assert.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/assert.ts"],"names":[],"mappings":"AAGA,wBAAgB,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,QAI1D"}
@@ -1,8 +0,0 @@
1
- // Replacement for the external assert method to reduce bundle size
2
- // Note: We don't use the second "message" argument in calling code,
3
- // so no need to support it here
4
- export function assert(condition, message) {
5
- if (!condition) {
6
- throw new Error(message || 'loader assertion failed.');
7
- }
8
- }
@@ -1,18 +0,0 @@
1
- export default class AsyncQueue<T> {
2
- private _values;
3
- private _settlers;
4
- private _closed;
5
- constructor();
6
- close(): void;
7
- [Symbol.asyncIterator](): AsyncIterator<T>;
8
- enqueue(value: T | Error): void;
9
- /**
10
- * @returns a Promise for an IteratorResult
11
- */
12
- next(): Promise<any>;
13
- }
14
- /**
15
- * @returns a Promise for an Array with the elements in `asyncIterable`
16
- */
17
- export declare function takeAsync(asyncIterable: AsyncIterable<any>, count?: number): Promise<any[]>;
18
- //# sourceMappingURL=async-queue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-queue.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/async-queue.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC;IAC/B,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,SAAS,CAA8E;IAC/F,OAAO,CAAC,OAAO,CAAU;;IAazB,KAAK,IAAI,IAAI;IAOb,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;IAI1C,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK,GAAG,IAAI;IAoB/B;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;CAoBrB;AAED;;GAEG;AACH,wBAAsB,SAAS,CAC7B,aAAa,EAAE,aAAa,CAAC,GAAG,CAAC,EACjC,KAAK,SAAW,GACf,OAAO,CAAC,GAAG,EAAE,CAAC,CAWhB"}
@@ -1,90 +0,0 @@
1
- // From https://github.com/rauschma/async-iter-demo/tree/master/src under MIT license
2
- // http://2ality.com/2016/10/asynchronous-iteration.html
3
- class ArrayQueue extends Array {
4
- enqueue(value) {
5
- // Add at the end
6
- return this.push(value);
7
- }
8
- dequeue() {
9
- // Remove first element
10
- return this.shift();
11
- }
12
- }
13
- export default class AsyncQueue {
14
- _values;
15
- _settlers;
16
- _closed;
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
- /**
77
- * @returns a Promise for an Array with the elements in `asyncIterable`
78
- */
79
- export async function takeAsync(asyncIterable, count = Infinity) {
80
- const result = [];
81
- const iterator = asyncIterable[Symbol.asyncIterator]();
82
- while (result.length < count) {
83
- const { value, done } = await iterator.next();
84
- if (done) {
85
- break;
86
- }
87
- result.push(value);
88
- }
89
- return result;
90
- }