@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.
- package/dist/categories/category-gis.d.ts +6 -0
- package/dist/categories/category-gis.d.ts.map +1 -0
- package/dist/categories/category-image.d.ts.map +1 -0
- package/dist/{types → categories}/category-mesh.d.ts +2 -2
- package/dist/categories/category-mesh.d.ts.map +1 -0
- package/dist/{types → categories}/category-table.d.ts +14 -14
- package/dist/categories/category-table.d.ts.map +1 -0
- package/dist/categories/category-texture.d.ts.map +1 -0
- package/dist/{lib/mesh → deprecated}/mesh-utils.d.ts +4 -2
- package/dist/deprecated/mesh-utils.d.ts.map +1 -0
- package/dist/{lib/mesh → deprecated}/mesh-utils.js +2 -0
- package/dist/dist.dev.js +0 -1836
- package/dist/dist.min.js +1 -1
- package/dist/geometry/binary-features.d.ts +30 -0
- package/dist/geometry/binary-features.d.ts.map +1 -0
- package/dist/geometry/binary-geometries.d.ts +33 -0
- package/dist/geometry/binary-geometries.d.ts.map +1 -0
- package/dist/geometry/flat-geometries.d.ts +61 -0
- package/dist/geometry/flat-geometries.d.ts.map +1 -0
- package/dist/index.cjs +2 -1792
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +10 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -23
- package/dist/types/batch.d.ts +3 -1
- package/dist/types/batch.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/{types → categories}/category-gis.ts +7 -18
- package/src/{types → categories}/category-mesh.ts +2 -2
- package/src/{types → categories}/category-table.ts +14 -17
- package/src/{lib/mesh → deprecated}/mesh-utils.ts +4 -2
- package/src/geometry/binary-features.ts +43 -0
- package/src/geometry/binary-geometries.ts +45 -0
- package/src/{types → geometry}/flat-geometries.ts +44 -14
- package/src/index.ts +15 -101
- package/src/types/batch.ts +3 -1
- package/dist/lib/mesh/convert-mesh.d.ts +0 -15
- package/dist/lib/mesh/convert-mesh.d.ts.map +0 -1
- package/dist/lib/mesh/convert-mesh.js +0 -37
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +0 -24
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +0 -1
- package/dist/lib/mesh/deduce-mesh-schema.js +0 -62
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts +0 -1
- package/dist/lib/mesh/mesh-to-arrow-table.d.ts.map +0 -1
- package/dist/lib/mesh/mesh-to-arrow-table.js +0 -47
- package/dist/lib/mesh/mesh-utils.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +0 -19
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-field.js +0 -36
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +0 -43
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +0 -12
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-schema.js +0 -81
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +0 -24
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-table.js +0 -63
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +0 -177
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/arrow-like-type.js +0 -442
- package/dist/lib/table/arrow-api/enum.d.ts +0 -92
- package/dist/lib/table/arrow-api/enum.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/enum.js +0 -97
- package/dist/lib/table/arrow-api/get-type-info.d.ts +0 -13
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/get-type-info.js +0 -27
- package/dist/lib/table/arrow-api/index.d.ts +0 -5
- package/dist/lib/table/arrow-api/index.d.ts.map +0 -1
- package/dist/lib/table/arrow-api/index.js +0 -7
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +0 -20
- package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/base-table-batch-aggregator.js +0 -63
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts +0 -23
- package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/columnar-table-batch-aggregator.js +0 -91
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +0 -22
- package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/row-table-batch-aggregator.js +0 -85
- package/dist/lib/table/batches/table-batch-aggregator.d.ts +0 -25
- package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +0 -1
- package/dist/lib/table/batches/table-batch-aggregator.js +0 -4
- package/dist/lib/table/batches/table-batch-builder.d.ts +0 -53
- package/dist/lib/table/batches/table-batch-builder.d.ts.map +0 -1
- package/dist/lib/table/batches/table-batch-builder.js +0 -151
- package/dist/lib/table/simple-table/convert-table.d.ts +0 -43
- package/dist/lib/table/simple-table/convert-table.d.ts.map +0 -1
- package/dist/lib/table/simple-table/convert-table.js +0 -118
- package/dist/lib/table/simple-table/data-type.d.ts +0 -17
- package/dist/lib/table/simple-table/data-type.d.ts.map +0 -1
- package/dist/lib/table/simple-table/data-type.js +0 -88
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts +0 -22
- package/dist/lib/table/simple-table/make-table-from-batches.d.ts.map +0 -1
- package/dist/lib/table/simple-table/make-table-from-batches.js +0 -79
- package/dist/lib/table/simple-table/make-table.d.ts +0 -65
- package/dist/lib/table/simple-table/make-table.d.ts.map +0 -1
- package/dist/lib/table/simple-table/make-table.js +0 -94
- package/dist/lib/table/simple-table/row-utils.d.ts +0 -15
- package/dist/lib/table/simple-table/row-utils.d.ts.map +0 -1
- package/dist/lib/table/simple-table/row-utils.js +0 -49
- package/dist/lib/table/simple-table/table-accessors.d.ts +0 -68
- package/dist/lib/table/simple-table/table-accessors.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-accessors.js +0 -350
- package/dist/lib/table/simple-table/table-column.d.ts +0 -7
- package/dist/lib/table/simple-table/table-column.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-column.js +0 -39
- package/dist/lib/table/simple-table/table-schema.d.ts +0 -15
- package/dist/lib/table/simple-table/table-schema.d.ts.map +0 -1
- package/dist/lib/table/simple-table/table-schema.js +0 -100
- package/dist/lib/utils/assert.d.ts +0 -2
- package/dist/lib/utils/assert.d.ts.map +0 -1
- package/dist/lib/utils/assert.js +0 -8
- package/dist/lib/utils/async-queue.d.ts +0 -18
- package/dist/lib/utils/async-queue.d.ts.map +0 -1
- package/dist/lib/utils/async-queue.js +0 -90
- package/dist/types/binary-geometries.d.ts +0 -57
- package/dist/types/binary-geometries.d.ts.map +0 -1
- package/dist/types/category-gis.d.ts +0 -18
- package/dist/types/category-gis.d.ts.map +0 -1
- package/dist/types/category-image.d.ts.map +0 -1
- package/dist/types/category-mesh.d.ts.map +0 -1
- package/dist/types/category-table.d.ts.map +0 -1
- package/dist/types/category-texture.d.ts.map +0 -1
- package/dist/types/flat-geometries.d.ts +0 -30
- package/dist/types/flat-geometries.d.ts.map +0 -1
- package/src/lib/mesh/convert-mesh.ts +0 -51
- package/src/lib/mesh/deduce-mesh-schema.ts +0 -76
- package/src/lib/mesh/mesh-to-arrow-table.ts +0 -47
- package/src/lib/table/arrow-api/arrow-like-field.ts +0 -53
- package/src/lib/table/arrow-api/arrow-like-interface.ts +0 -84
- package/src/lib/table/arrow-api/arrow-like-schema.ts +0 -101
- package/src/lib/table/arrow-api/arrow-like-table.ts +0 -86
- package/src/lib/table/arrow-api/arrow-like-type.ts +0 -502
- package/src/lib/table/arrow-api/enum.ts +0 -99
- package/src/lib/table/arrow-api/get-type-info.ts +0 -38
- package/src/lib/table/arrow-api/index.ts +0 -8
- package/src/lib/table/batches/base-table-batch-aggregator.ts +0 -83
- package/src/lib/table/batches/columnar-table-batch-aggregator.ts +0 -112
- package/src/lib/table/batches/row-table-batch-aggregator.ts +0 -109
- package/src/lib/table/batches/table-batch-aggregator.ts +0 -29
- package/src/lib/table/batches/table-batch-builder.ts +0 -190
- package/src/lib/table/simple-table/convert-table.ts +0 -149
- package/src/lib/table/simple-table/data-type.ts +0 -104
- package/src/lib/table/simple-table/make-table-from-batches.ts +0 -98
- package/src/lib/table/simple-table/make-table.ts +0 -111
- package/src/lib/table/simple-table/row-utils.ts +0 -59
- package/src/lib/table/simple-table/table-accessors.ts +0 -417
- package/src/lib/table/simple-table/table-column.ts +0 -49
- package/src/lib/table/simple-table/table-schema.ts +0 -121
- package/src/lib/utils/assert.ts +0 -8
- package/src/lib/utils/async-queue.ts +0 -104
- package/src/types/binary-geometries.ts +0 -67
- /package/dist/{types → categories}/category-gis.js +0 -0
- /package/dist/{types → categories}/category-image.d.ts +0 -0
- /package/dist/{types → categories}/category-image.js +0 -0
- /package/dist/{types → categories}/category-mesh.js +0 -0
- /package/dist/{types → categories}/category-table.js +0 -0
- /package/dist/{types → categories}/category-texture.d.ts +0 -0
- /package/dist/{types → categories}/category-texture.js +0 -0
- /package/dist/{lib/table/arrow-api/arrow-like-interface.js → geometry/binary-features.js} +0 -0
- /package/dist/{types → geometry}/binary-geometries.js +0 -0
- /package/dist/{types → geometry}/flat-geometries.js +0 -0
- /package/src/{types → categories}/category-image.ts +0 -0
- /package/src/{types → categories}/category-texture.ts +0 -0
|
@@ -1,417 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
/* eslint-disable no-else-return */
|
|
6
|
-
|
|
7
|
-
import {Table, ArrayRowTable, ObjectRowTable} from '../../../types/category-table';
|
|
8
|
-
|
|
9
|
-
export function isTable(table: any): table is Table {
|
|
10
|
-
const shape = typeof table === 'object' && table?.shape;
|
|
11
|
-
switch (shape) {
|
|
12
|
-
case 'array-row-table':
|
|
13
|
-
case 'object-row-table':
|
|
14
|
-
return Array.isArray(table.data);
|
|
15
|
-
|
|
16
|
-
case 'geojson-table':
|
|
17
|
-
return Array.isArray(table.features);
|
|
18
|
-
|
|
19
|
-
case 'columnar-table':
|
|
20
|
-
return table.data && typeof table.data === 'object';
|
|
21
|
-
|
|
22
|
-
case 'arrow-table':
|
|
23
|
-
return Boolean(table?.data?.numRows !== undefined);
|
|
24
|
-
|
|
25
|
-
default:
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Returns the length of the table (i.e. the number of rows)
|
|
32
|
-
*/
|
|
33
|
-
export function getTableLength(table: Table): number {
|
|
34
|
-
switch (table.shape) {
|
|
35
|
-
case 'array-row-table':
|
|
36
|
-
case 'object-row-table':
|
|
37
|
-
return table.data.length;
|
|
38
|
-
|
|
39
|
-
case 'geojson-table':
|
|
40
|
-
return table.features.length;
|
|
41
|
-
|
|
42
|
-
case 'arrow-table':
|
|
43
|
-
const arrowTable = table.data as any;
|
|
44
|
-
return arrowTable.numRows;
|
|
45
|
-
|
|
46
|
-
case 'columnar-table':
|
|
47
|
-
for (const column of Object.values(table.data)) {
|
|
48
|
-
return column.length || 0;
|
|
49
|
-
}
|
|
50
|
-
return 0;
|
|
51
|
-
default:
|
|
52
|
-
throw new Error('table');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Returns the number of columns in the table
|
|
58
|
-
* @throws Fails to deduce number of columns if the table has no schema and is empty
|
|
59
|
-
*/
|
|
60
|
-
export function getTableNumCols(table: Table): number {
|
|
61
|
-
if (table.schema) {
|
|
62
|
-
return table.schema.fields.length;
|
|
63
|
-
}
|
|
64
|
-
if (getTableLength(table) === 0) {
|
|
65
|
-
throw new Error('empty table');
|
|
66
|
-
}
|
|
67
|
-
switch (table.shape) {
|
|
68
|
-
case 'array-row-table':
|
|
69
|
-
return table.data[0].length;
|
|
70
|
-
case 'object-row-table':
|
|
71
|
-
return Object.keys(table.data[0]).length;
|
|
72
|
-
case 'geojson-table':
|
|
73
|
-
return Object.keys(table.features[0]).length;
|
|
74
|
-
case 'columnar-table':
|
|
75
|
-
return Object.keys(table.data).length;
|
|
76
|
-
case 'arrow-table':
|
|
77
|
-
const arrowTable = table.data as any;
|
|
78
|
-
return arrowTable.numCols;
|
|
79
|
-
default:
|
|
80
|
-
throw new Error('table');
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** Get a table cell value at row index and column name */
|
|
85
|
-
export function getTableCell(table: Table, rowIndex: number, columnName: string): unknown {
|
|
86
|
-
switch (table.shape) {
|
|
87
|
-
case 'array-row-table':
|
|
88
|
-
const columnIndex = getTableColumnIndex(table, columnName);
|
|
89
|
-
return table.data[rowIndex][columnIndex];
|
|
90
|
-
|
|
91
|
-
case 'object-row-table':
|
|
92
|
-
return table.data[rowIndex][columnName];
|
|
93
|
-
|
|
94
|
-
case 'geojson-table':
|
|
95
|
-
return table.features[rowIndex][columnName];
|
|
96
|
-
|
|
97
|
-
case 'columnar-table':
|
|
98
|
-
const column = table.data[columnName];
|
|
99
|
-
return column[rowIndex];
|
|
100
|
-
|
|
101
|
-
case 'arrow-table':
|
|
102
|
-
const arrowTable = table.data as any;
|
|
103
|
-
const arrowColumnIndex = arrowTable.schema.fields.findIndex(
|
|
104
|
-
(field) => field.name === columnName
|
|
105
|
-
);
|
|
106
|
-
return arrowTable.getChildAt(arrowColumnIndex)?.get(rowIndex);
|
|
107
|
-
|
|
108
|
-
default:
|
|
109
|
-
throw new Error('todo');
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** Get a table cell value at row index and column name */
|
|
114
|
-
export function getTableCellAt(table: Table, rowIndex: number, columnIndex: number): unknown {
|
|
115
|
-
switch (table.shape) {
|
|
116
|
-
case 'array-row-table':
|
|
117
|
-
return table.data[rowIndex][columnIndex];
|
|
118
|
-
|
|
119
|
-
case 'object-row-table':
|
|
120
|
-
const columnName1 = getTableColumnName(table, columnIndex);
|
|
121
|
-
return table.data[rowIndex][columnName1];
|
|
122
|
-
|
|
123
|
-
case 'geojson-table':
|
|
124
|
-
const columnName2 = getTableColumnName(table, columnIndex);
|
|
125
|
-
return table.features[rowIndex][columnName2];
|
|
126
|
-
|
|
127
|
-
case 'columnar-table':
|
|
128
|
-
const columnName3 = getTableColumnName(table, columnIndex);
|
|
129
|
-
const column = table.data[columnName3];
|
|
130
|
-
return column[rowIndex];
|
|
131
|
-
|
|
132
|
-
case 'arrow-table':
|
|
133
|
-
const arrowTable = table.data as any;
|
|
134
|
-
return arrowTable.getChildAt(columnIndex)?.get(rowIndex);
|
|
135
|
-
|
|
136
|
-
default:
|
|
137
|
-
throw new Error('todo');
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/** Deduce the table row shape */
|
|
142
|
-
export function getTableRowShape(table: Table): 'array-row-table' | 'object-row-table' {
|
|
143
|
-
switch (table.shape) {
|
|
144
|
-
case 'array-row-table':
|
|
145
|
-
case 'object-row-table':
|
|
146
|
-
return table.shape;
|
|
147
|
-
|
|
148
|
-
case 'geojson-table':
|
|
149
|
-
// TODO - this is not correct, geojson-table is not a row table
|
|
150
|
-
return 'object-row-table';
|
|
151
|
-
|
|
152
|
-
case 'columnar-table':
|
|
153
|
-
default:
|
|
154
|
-
throw new Error('Not a row table');
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/** Get the index of a named table column. Requires the table to have a schema */
|
|
159
|
-
export function getTableColumnIndex(table: Table, columnName: string): number {
|
|
160
|
-
const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
|
|
161
|
-
if (columnIndex === undefined) {
|
|
162
|
-
throw new Error(columnName);
|
|
163
|
-
}
|
|
164
|
-
return columnIndex;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/** Get the name of a table column by index. Requires the table to have a schema */
|
|
168
|
-
export function getTableColumnName(table: Table, columnIndex: number): string {
|
|
169
|
-
const columnName = table.schema?.fields[columnIndex]?.name;
|
|
170
|
-
if (!columnName) {
|
|
171
|
-
throw new Error(`${columnIndex}`);
|
|
172
|
-
}
|
|
173
|
-
return columnName;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Returns one row of the table in object format.
|
|
178
|
-
* @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance
|
|
179
|
-
* @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
|
|
180
|
-
*/
|
|
181
|
-
// eslint-disable-next-line complexity
|
|
182
|
-
export function getTableRowAsObject(
|
|
183
|
-
table: Table,
|
|
184
|
-
rowIndex: number,
|
|
185
|
-
target?: {[columnName: string]: unknown},
|
|
186
|
-
copy?: 'copy'
|
|
187
|
-
): {[columnName: string]: unknown} {
|
|
188
|
-
switch (table.shape) {
|
|
189
|
-
case 'object-row-table':
|
|
190
|
-
return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
|
|
191
|
-
|
|
192
|
-
case 'array-row-table':
|
|
193
|
-
if (table.schema) {
|
|
194
|
-
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
195
|
-
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
196
|
-
objectRow[table.schema.fields[i].name] = table.data[rowIndex][i];
|
|
197
|
-
}
|
|
198
|
-
return objectRow;
|
|
199
|
-
}
|
|
200
|
-
throw new Error('no schema');
|
|
201
|
-
|
|
202
|
-
case 'geojson-table':
|
|
203
|
-
if (table.schema) {
|
|
204
|
-
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
205
|
-
// TODO - should lift properties to top level
|
|
206
|
-
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
207
|
-
objectRow[table.schema.fields[i].name] = table.features[rowIndex][i];
|
|
208
|
-
}
|
|
209
|
-
return objectRow;
|
|
210
|
-
}
|
|
211
|
-
throw new Error('no schema');
|
|
212
|
-
|
|
213
|
-
case 'columnar-table':
|
|
214
|
-
if (table.schema) {
|
|
215
|
-
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
216
|
-
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
217
|
-
objectRow[table.schema.fields[i].name] =
|
|
218
|
-
table.data[table.schema.fields[i].name][rowIndex];
|
|
219
|
-
}
|
|
220
|
-
return objectRow;
|
|
221
|
-
} else {
|
|
222
|
-
// eslint-disable-line no-else-return
|
|
223
|
-
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
224
|
-
for (const [name, column] of Object.entries(table.data)) {
|
|
225
|
-
objectRow[name] = column[rowIndex];
|
|
226
|
-
}
|
|
227
|
-
return objectRow;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
case 'arrow-table':
|
|
231
|
-
const arrowTable = table.data as any;
|
|
232
|
-
const objectRow: {[columnName: string]: unknown} = target || {};
|
|
233
|
-
const row = arrowTable.get(rowIndex);
|
|
234
|
-
const schema = arrowTable.schema;
|
|
235
|
-
for (let i = 0; i < schema.fields.length; i++) {
|
|
236
|
-
objectRow[schema.fields[i].name] = row?.[schema.fields[i].name];
|
|
237
|
-
}
|
|
238
|
-
return objectRow;
|
|
239
|
-
|
|
240
|
-
default:
|
|
241
|
-
throw new Error('shape');
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Returns one row of the table in array format.
|
|
247
|
-
* @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance.
|
|
248
|
-
* @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
|
|
249
|
-
*/
|
|
250
|
-
// eslint-disable-next-line complexity
|
|
251
|
-
export function getTableRowAsArray(
|
|
252
|
-
table: Table,
|
|
253
|
-
rowIndex: number,
|
|
254
|
-
target?: unknown[],
|
|
255
|
-
copy?: 'copy'
|
|
256
|
-
): unknown[] {
|
|
257
|
-
switch (table.shape) {
|
|
258
|
-
case 'array-row-table':
|
|
259
|
-
return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
|
|
260
|
-
|
|
261
|
-
case 'object-row-table':
|
|
262
|
-
if (table.schema) {
|
|
263
|
-
const arrayRow: unknown[] = target || [];
|
|
264
|
-
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
265
|
-
arrayRow[i] = table.data[rowIndex][table.schema.fields[i].name];
|
|
266
|
-
}
|
|
267
|
-
return arrayRow;
|
|
268
|
-
}
|
|
269
|
-
// Warning: just slap on the values, this risks mismatches between rows
|
|
270
|
-
return Object.values(table.data[rowIndex]);
|
|
271
|
-
|
|
272
|
-
case 'geojson-table':
|
|
273
|
-
if (table.schema) {
|
|
274
|
-
const arrayRow: unknown[] = target || [];
|
|
275
|
-
// TODO - should lift properties to top level
|
|
276
|
-
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
277
|
-
arrayRow[i] = table.features[rowIndex][table.schema.fields[i].name];
|
|
278
|
-
}
|
|
279
|
-
return arrayRow;
|
|
280
|
-
}
|
|
281
|
-
// Warning: just slap on the values, this risks mismatches between rows
|
|
282
|
-
return Object.values(table.features[rowIndex]);
|
|
283
|
-
|
|
284
|
-
case 'columnar-table':
|
|
285
|
-
if (table.schema) {
|
|
286
|
-
const arrayRow: unknown[] = target || [];
|
|
287
|
-
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
288
|
-
arrayRow[i] = table.data[table.schema.fields[i].name][rowIndex];
|
|
289
|
-
}
|
|
290
|
-
return arrayRow;
|
|
291
|
-
} else {
|
|
292
|
-
// eslint-disable-line no-else-return
|
|
293
|
-
const arrayRow: unknown[] = target || [];
|
|
294
|
-
let i = 0;
|
|
295
|
-
for (const column of Object.values(table.data)) {
|
|
296
|
-
arrayRow[i] = column[rowIndex];
|
|
297
|
-
i++;
|
|
298
|
-
}
|
|
299
|
-
return arrayRow;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
case 'arrow-table':
|
|
303
|
-
const arrowTable = table.data as any;
|
|
304
|
-
const arrayRow: unknown[] = target || [];
|
|
305
|
-
const row = arrowTable.get(rowIndex);
|
|
306
|
-
const schema = arrowTable.schema;
|
|
307
|
-
for (let i = 0; i < schema.fields.length; i++) {
|
|
308
|
-
arrayRow[i] = row?.[schema.fields[i].name];
|
|
309
|
-
}
|
|
310
|
-
return arrayRow;
|
|
311
|
-
|
|
312
|
-
default:
|
|
313
|
-
throw new Error('shape');
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/** Convert any table into array row format */
|
|
318
|
-
export function makeArrayRowTable(table: Table): ArrayRowTable {
|
|
319
|
-
if (table.shape === 'array-row-table') {
|
|
320
|
-
return table;
|
|
321
|
-
}
|
|
322
|
-
const length = getTableLength(table);
|
|
323
|
-
const data = new Array<unknown[]>(length);
|
|
324
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
325
|
-
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
326
|
-
}
|
|
327
|
-
return {
|
|
328
|
-
shape: 'array-row-table',
|
|
329
|
-
schema: table.schema,
|
|
330
|
-
data
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/** Convert any table into object row format */
|
|
335
|
-
export function makeObjectRowTable(table: Table): ObjectRowTable {
|
|
336
|
-
if (table.shape === 'object-row-table') {
|
|
337
|
-
return table;
|
|
338
|
-
}
|
|
339
|
-
const length = getTableLength(table);
|
|
340
|
-
const data = new Array<{[key: string]: unknown}>(length);
|
|
341
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
342
|
-
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
343
|
-
}
|
|
344
|
-
return {
|
|
345
|
-
shape: 'object-row-table',
|
|
346
|
-
schema: table.schema,
|
|
347
|
-
data
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/** Convert any table into object row format */
|
|
352
|
-
export function makeColumnarTable(table: Table): ObjectRowTable {
|
|
353
|
-
if (table.shape === 'object-row-table') {
|
|
354
|
-
return table;
|
|
355
|
-
}
|
|
356
|
-
const length = getTableLength(table);
|
|
357
|
-
const data = new Array<{[key: string]: unknown}>(length);
|
|
358
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
359
|
-
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
360
|
-
}
|
|
361
|
-
return {
|
|
362
|
-
shape: 'object-row-table',
|
|
363
|
-
schema: table.schema,
|
|
364
|
-
data
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// Row Iterators
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Iterate over table rows
|
|
372
|
-
* @param table
|
|
373
|
-
* @param shape
|
|
374
|
-
*/
|
|
375
|
-
export function* makeRowIterator(
|
|
376
|
-
table: Table,
|
|
377
|
-
shape: 'object-row-table' | 'array-row-table'
|
|
378
|
-
): Iterable<unknown[] | {[key: string]: unknown}> {
|
|
379
|
-
switch (shape) {
|
|
380
|
-
case 'array-row-table':
|
|
381
|
-
yield* makeArrayRowIterator(table);
|
|
382
|
-
break;
|
|
383
|
-
case 'object-row-table':
|
|
384
|
-
yield* makeObjectRowIterator(table);
|
|
385
|
-
break;
|
|
386
|
-
|
|
387
|
-
default:
|
|
388
|
-
throw new Error(`Unknown row type ${shape}`);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Streaming processing: Iterate over table, yielding array rows
|
|
394
|
-
* @param table
|
|
395
|
-
* @param shape
|
|
396
|
-
*/
|
|
397
|
-
export function* makeArrayRowIterator(table: Table, target: unknown[] = []): Iterable<unknown[]> {
|
|
398
|
-
const length = getTableLength(table);
|
|
399
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
400
|
-
yield getTableRowAsArray(table, rowIndex, target);
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Streaming processing: Iterate over table, yielding object rows
|
|
406
|
-
* @param table
|
|
407
|
-
* @param shape
|
|
408
|
-
*/
|
|
409
|
-
export function* makeObjectRowIterator(
|
|
410
|
-
table: Table,
|
|
411
|
-
target: {[key: string]: unknown} = {}
|
|
412
|
-
): Iterable<{[key: string]: unknown}> {
|
|
413
|
-
const length = getTableLength(table);
|
|
414
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
415
|
-
yield getTableRowAsObject(table, rowIndex, target);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
// import type {TypedArray,} from '../../../types/types';
|
|
6
|
-
import {Field} from '../../../types/schema';
|
|
7
|
-
import {getArrayTypeFromDataType} from './data-type';
|
|
8
|
-
|
|
9
|
-
export interface ArrayType<T = unknown> {
|
|
10
|
-
readonly length: number;
|
|
11
|
-
[n: number]: T;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function makeColumnFromField(field: Field, length: number): ArrayType {
|
|
15
|
-
const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
|
|
16
|
-
return new ArrayType(length);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
21
|
-
function deduceSchema(rows) {
|
|
22
|
-
const row = rows[0];
|
|
23
|
-
|
|
24
|
-
const schema = {};
|
|
25
|
-
let i = 0;
|
|
26
|
-
for (const columnName in row) {
|
|
27
|
-
const value = row[columnName];
|
|
28
|
-
switch (typeof value) {
|
|
29
|
-
case 'number':
|
|
30
|
-
case 'boolean':
|
|
31
|
-
// TODO - booleans could be handled differently...
|
|
32
|
-
schema[columnName] = {name: String(columnName), index: i, type: Float32Array};
|
|
33
|
-
break;
|
|
34
|
-
|
|
35
|
-
case 'object':
|
|
36
|
-
schema[columnName] = {name: String(columnName), index: i, type: Array};
|
|
37
|
-
break;
|
|
38
|
-
|
|
39
|
-
case 'string':
|
|
40
|
-
default:
|
|
41
|
-
schema[columnName] = {name: String(columnName), index: i, type: Array};
|
|
42
|
-
// We currently only handle numeric rows
|
|
43
|
-
// TODO we could offer a function to map strings to numbers?
|
|
44
|
-
}
|
|
45
|
-
i++;
|
|
46
|
-
}
|
|
47
|
-
return schema;
|
|
48
|
-
}
|
|
49
|
-
*/
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
// Type deduction
|
|
6
|
-
import {Schema, Field} from '../../../types/schema';
|
|
7
|
-
import {ArrayType} from '../../../types/types';
|
|
8
|
-
import {Table} from '../../../types/category-table';
|
|
9
|
-
import {getDataTypeFromArray, getDataTypeFromValue} from './data-type';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* SCHEMA SUPPORT - AUTODEDUCTION
|
|
13
|
-
* @param {*} table
|
|
14
|
-
* @param {*} schema
|
|
15
|
-
* @returns
|
|
16
|
-
*/
|
|
17
|
-
export function deduceTableSchema(table: Table): Schema {
|
|
18
|
-
switch (table.shape) {
|
|
19
|
-
case 'array-row-table':
|
|
20
|
-
case 'object-row-table':
|
|
21
|
-
return deduceSchemaFromRows(table.data);
|
|
22
|
-
|
|
23
|
-
case 'geojson-table':
|
|
24
|
-
return deduceSchemaFromGeoJSON(table.features);
|
|
25
|
-
|
|
26
|
-
case 'columnar-table':
|
|
27
|
-
return deduceSchemaFromColumns(table.data);
|
|
28
|
-
|
|
29
|
-
case 'arrow-table':
|
|
30
|
-
default:
|
|
31
|
-
throw new Error('Deduce schema');
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function deduceSchema(
|
|
36
|
-
data: unknown[][] | {[key: string]: unknown}[] | {[key: string]: unknown[]}
|
|
37
|
-
): Schema {
|
|
38
|
-
return Array.isArray(data) ? deduceSchemaFromRows(data) : deduceSchemaFromColumns(data);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/** Given an object with columnar arrays, try to deduce a schema */
|
|
42
|
-
function deduceSchemaFromColumns(columnarTable: {[key: string]: ArrayType}): Schema {
|
|
43
|
-
const fields: Field[] = [];
|
|
44
|
-
for (const [columnName, column] of Object.entries(columnarTable)) {
|
|
45
|
-
const field = deduceFieldFromColumn(column, columnName);
|
|
46
|
-
fields.push(field);
|
|
47
|
-
}
|
|
48
|
-
return {fields, metadata: {}};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Given an array of rows, try to deduce a schema */
|
|
52
|
-
function deduceSchemaFromRows(rowTable: unknown[][] | {[key: string]: unknown}[]): Schema {
|
|
53
|
-
if (!rowTable.length) {
|
|
54
|
-
throw new Error('deduce from empty table');
|
|
55
|
-
}
|
|
56
|
-
const fields: Field[] = [];
|
|
57
|
-
const row0 = rowTable[0];
|
|
58
|
-
// TODO - fields can be nullable, false detection...
|
|
59
|
-
// Could look at additional rows if nulls in first row
|
|
60
|
-
// TODO - if array, column names will be numbers
|
|
61
|
-
for (const [columnName, value] of Object.entries(row0)) {
|
|
62
|
-
fields.push(deduceFieldFromValue(value, columnName));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {fields, metadata: {}};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/** Given a GeoJSON, try to deduce a schema */
|
|
69
|
-
function deduceSchemaFromGeoJSON(features: {properties: Record<string, number> | null}[]): Schema {
|
|
70
|
-
if (!features.length) {
|
|
71
|
-
throw new Error('deduce from empty table');
|
|
72
|
-
}
|
|
73
|
-
const fields: Field[] = [];
|
|
74
|
-
const row0 = features[0].properties || {};
|
|
75
|
-
// TODO - fields can be nullable, false detection...
|
|
76
|
-
// Could look at additional rows if nulls in first row
|
|
77
|
-
// TODO - if array, column names will be numbers
|
|
78
|
-
for (const [columnName, value] of Object.entries(row0)) {
|
|
79
|
-
fields.push(deduceFieldFromValue(value, columnName));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return {fields, metadata: {}};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/** Given a column (i.e. array), attempt to deduce an appropriate `Field` */
|
|
86
|
-
function deduceFieldFromColumn(column: ArrayType, name: string): Field {
|
|
87
|
-
if (ArrayBuffer.isView(column)) {
|
|
88
|
-
const type = getDataTypeFromArray(column);
|
|
89
|
-
return {
|
|
90
|
-
name,
|
|
91
|
-
type: type.type || 'null',
|
|
92
|
-
nullable: type.nullable
|
|
93
|
-
// metadata: {}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (Array.isArray(column) && column.length > 0) {
|
|
98
|
-
const value = column[0];
|
|
99
|
-
const type = getDataTypeFromValue(value);
|
|
100
|
-
// TODO - support nested schemas?
|
|
101
|
-
return {
|
|
102
|
-
name,
|
|
103
|
-
type,
|
|
104
|
-
nullable: true
|
|
105
|
-
// metadata: {},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
throw new Error('empty table');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/** Given a value, attempt to deduce an appropriate `Field` */
|
|
113
|
-
function deduceFieldFromValue(value: unknown, name: string): Field {
|
|
114
|
-
const type = getDataTypeFromValue(value);
|
|
115
|
-
return {
|
|
116
|
-
name,
|
|
117
|
-
type,
|
|
118
|
-
nullable: true
|
|
119
|
-
// metadata: {}
|
|
120
|
-
};
|
|
121
|
-
}
|
package/src/lib/utils/assert.ts
DELETED
|
@@ -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: boolean, message?: string) {
|
|
5
|
-
if (!condition) {
|
|
6
|
-
throw new Error(message || 'loader assertion failed.');
|
|
7
|
-
}
|
|
8
|
-
}
|
|
@@ -1,104 +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
|
-
|
|
4
|
-
class ArrayQueue<T> extends Array<T> {
|
|
5
|
-
enqueue(value: T) {
|
|
6
|
-
// Add at the end
|
|
7
|
-
return this.push(value);
|
|
8
|
-
}
|
|
9
|
-
dequeue(): T {
|
|
10
|
-
// Remove first element
|
|
11
|
-
return this.shift() as T;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default class AsyncQueue<T> {
|
|
16
|
-
private _values: ArrayQueue<T | Error>;
|
|
17
|
-
private _settlers: ArrayQueue<{resolve: (value: any) => void; reject: (reason?: any) => void}>;
|
|
18
|
-
private _closed: boolean;
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
// enqueues > dequeues
|
|
22
|
-
this._values = new ArrayQueue<T>();
|
|
23
|
-
// dequeues > enqueues
|
|
24
|
-
this._settlers = new ArrayQueue<{
|
|
25
|
-
resolve: (value: any) => void;
|
|
26
|
-
reject: (reason?: any) => void;
|
|
27
|
-
}>();
|
|
28
|
-
this._closed = false;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
close(): void {
|
|
32
|
-
while (this._settlers.length > 0) {
|
|
33
|
-
this._settlers.dequeue().resolve({done: true});
|
|
34
|
-
}
|
|
35
|
-
this._closed = true;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
[Symbol.asyncIterator](): AsyncIterator<T> {
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
enqueue(value: T | Error): void {
|
|
43
|
-
if (this._closed) {
|
|
44
|
-
throw new Error('Closed');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (this._settlers.length > 0) {
|
|
48
|
-
if (this._values.length > 0) {
|
|
49
|
-
throw new Error('Illegal internal state');
|
|
50
|
-
}
|
|
51
|
-
const settler = this._settlers.dequeue();
|
|
52
|
-
if (value instanceof Error) {
|
|
53
|
-
settler.reject(value);
|
|
54
|
-
} else {
|
|
55
|
-
settler.resolve({value});
|
|
56
|
-
}
|
|
57
|
-
} else {
|
|
58
|
-
this._values.enqueue(value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @returns a Promise for an IteratorResult
|
|
64
|
-
*/
|
|
65
|
-
next(): Promise<any> {
|
|
66
|
-
if (this._values.length > 0) {
|
|
67
|
-
const value = this._values.dequeue();
|
|
68
|
-
if (value instanceof Error) {
|
|
69
|
-
return Promise.reject(value);
|
|
70
|
-
}
|
|
71
|
-
return Promise.resolve({value});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (this._closed) {
|
|
75
|
-
if (this._settlers.length > 0) {
|
|
76
|
-
throw new Error('Illegal internal state');
|
|
77
|
-
}
|
|
78
|
-
return Promise.resolve({done: true});
|
|
79
|
-
}
|
|
80
|
-
// Wait for new values to be enqueued
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
this._settlers.enqueue({resolve, reject});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @returns a Promise for an Array with the elements in `asyncIterable`
|
|
89
|
-
*/
|
|
90
|
-
export async function takeAsync(
|
|
91
|
-
asyncIterable: AsyncIterable<any>,
|
|
92
|
-
count = Infinity
|
|
93
|
-
): Promise<any[]> {
|
|
94
|
-
const result: Array<any> = [];
|
|
95
|
-
const iterator = asyncIterable[Symbol.asyncIterator]();
|
|
96
|
-
while (result.length < count) {
|
|
97
|
-
const {value, done} = await iterator.next();
|
|
98
|
-
if (done) {
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
result.push(value);
|
|
102
|
-
}
|
|
103
|
-
return result;
|
|
104
|
-
}
|