@loaders.gl/schema 4.0.0-alpha.24 → 4.0.0-alpha.25

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 (40) hide show
  1. package/dist/dist.min.js +26 -7
  2. package/dist/es5/index.js.map +1 -1
  3. package/dist/es5/lib/table/arrow-api/arrow-like-table.js +1 -1
  4. package/dist/es5/lib/table/arrow-api/arrow-like-table.js.map +1 -1
  5. package/dist/es5/lib/table/batches/row-table-batch-aggregator.js.map +1 -1
  6. package/dist/es5/lib/table/simple-table/table-accessors.js +52 -31
  7. package/dist/es5/lib/table/simple-table/table-accessors.js.map +1 -1
  8. package/dist/es5/types/batch.js +2 -0
  9. package/dist/es5/types/batch.js.map +1 -0
  10. package/dist/es5/types/category-table.js.map +1 -1
  11. package/dist/es5/types/schema.js.map +1 -1
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/lib/table/arrow-api/arrow-like-table.js +1 -1
  14. package/dist/esm/lib/table/arrow-api/arrow-like-table.js.map +1 -1
  15. package/dist/esm/lib/table/batches/row-table-batch-aggregator.js.map +1 -1
  16. package/dist/esm/lib/table/simple-table/table-accessors.js +32 -11
  17. package/dist/esm/lib/table/simple-table/table-accessors.js.map +1 -1
  18. package/dist/esm/types/batch.js +2 -0
  19. package/dist/esm/types/batch.js.map +1 -0
  20. package/dist/esm/types/category-table.js.map +1 -1
  21. package/dist/esm/types/schema.js.map +1 -1
  22. package/dist/index.d.ts +4 -3
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +3 -3
  25. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +1 -1
  26. package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -1
  27. package/dist/types/batch.d.ts +34 -0
  28. package/dist/types/batch.d.ts.map +1 -0
  29. package/dist/types/category-table.d.ts +21 -13
  30. package/dist/types/category-table.d.ts.map +1 -1
  31. package/dist/types/schema.d.ts +0 -15
  32. package/dist/types/schema.d.ts.map +1 -1
  33. package/package.json +2 -2
  34. package/src/index.ts +5 -3
  35. package/src/lib/table/arrow-api/arrow-like-table.ts +1 -1
  36. package/src/lib/table/batches/row-table-batch-aggregator.ts +2 -2
  37. package/src/lib/table/simple-table/table-accessors.ts +41 -13
  38. package/src/types/batch.ts +41 -0
  39. package/src/types/category-table.ts +22 -13
  40. package/src/types/schema.ts +0 -17
@@ -13,8 +13,8 @@ export class RowTableBatchAggregator implements TableBatchAggregator {
13
13
  options: TableBatchOptions;
14
14
 
15
15
  length: number = 0;
16
- objectRows: {[columnName: string]: any} | null = null;
17
- arrayRows: any[] | null = null;
16
+ objectRows: {[columnName: string]: unknown}[] | null = null;
17
+ arrayRows: unknown[][] | null = null;
18
18
  cursor: number = 0;
19
19
  private _headers: string[] = [];
20
20
 
@@ -11,9 +11,11 @@ export function getTableLength(table: Table): number {
11
11
  switch (table.shape) {
12
12
  case 'array-row-table':
13
13
  case 'object-row-table':
14
- case 'geojson-row-table':
15
14
  return table.data.length;
16
15
 
16
+ case 'geojson-table':
17
+ return table.features.length;
18
+
17
19
  case 'arrow-table':
18
20
  return table.data.numRows;
19
21
 
@@ -42,12 +44,11 @@ export function getTableNumCols(table: Table): number {
42
44
  case 'array-row-table':
43
45
  return table.data[0].length;
44
46
  case 'object-row-table':
45
- case 'geojson-row-table':
46
47
  return Object.keys(table.data[0]).length;
47
-
48
+ case 'geojson-table':
49
+ return Object.keys(table.features[0]).length;
48
50
  case 'columnar-table':
49
51
  return Object.keys(table.data).length;
50
-
51
52
  case 'arrow-table':
52
53
  return table.data.numCols;
53
54
  default:
@@ -63,9 +64,11 @@ export function getTableCell(table: Table, rowIndex: number, columnName: string)
63
64
  return table.data[rowIndex][columnIndex];
64
65
 
65
66
  case 'object-row-table':
66
- case 'geojson-row-table':
67
67
  return table.data[rowIndex][columnName];
68
68
 
69
+ case 'geojson-table':
70
+ return table.features[rowIndex][columnName];
71
+
69
72
  case 'columnar-table':
70
73
  const column = table.data[columnName];
71
74
  return column[rowIndex];
@@ -88,13 +91,16 @@ export function getTableCellAt(table: Table, rowIndex: number, columnIndex: numb
88
91
  return table.data[rowIndex][columnIndex];
89
92
 
90
93
  case 'object-row-table':
91
- case 'geojson-row-table':
92
- let columnName = getTableColumnName(table, columnIndex);
93
- return table.data[rowIndex][columnName];
94
+ const columnName1 = getTableColumnName(table, columnIndex);
95
+ return table.data[rowIndex][columnName1];
96
+
97
+ case 'geojson-table':
98
+ const columnName2 = getTableColumnName(table, columnIndex);
99
+ return table.features[rowIndex][columnName2];
94
100
 
95
101
  case 'columnar-table':
96
- columnName = getTableColumnName(table, columnIndex);
97
- const column = table.data[columnName];
102
+ const columnName3 = getTableColumnName(table, columnIndex);
103
+ const column = table.data[columnName3];
98
104
  return column[rowIndex];
99
105
 
100
106
  case 'arrow-table':
@@ -112,7 +118,8 @@ export function getTableRowShape(table: Table): 'array-row-table' | 'object-row-
112
118
  case 'object-row-table':
113
119
  return table.shape;
114
120
 
115
- case 'geojson-row-table':
121
+ case 'geojson-table':
122
+ // TODO - this is not correct, geojson-table is not a row table
116
123
  return 'object-row-table';
117
124
 
118
125
  case 'columnar-table':
@@ -156,7 +163,6 @@ export function getTableRowAsObject(
156
163
  return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
157
164
 
158
165
  case 'array-row-table':
159
- case 'geojson-row-table':
160
166
  if (table.schema) {
161
167
  const objectRow: {[columnName: string]: unknown} = target || {};
162
168
  for (let i = 0; i < table.schema.fields.length; i++) {
@@ -166,6 +172,17 @@ export function getTableRowAsObject(
166
172
  }
167
173
  throw new Error('no schema');
168
174
 
175
+ case 'geojson-table':
176
+ if (table.schema) {
177
+ const objectRow: {[columnName: string]: unknown} = target || {};
178
+ // TODO - should lift properties to top level
179
+ for (let i = 0; i < table.schema.fields.length; i++) {
180
+ objectRow[table.schema.fields[i].name] = table.features[rowIndex][i];
181
+ }
182
+ return objectRow;
183
+ }
184
+ throw new Error('no schema');
185
+
169
186
  case 'columnar-table':
170
187
  if (table.schema) {
171
188
  const objectRow: {[columnName: string]: unknown} = target || {};
@@ -214,7 +231,6 @@ export function getTableRowAsArray(
214
231
  return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
215
232
 
216
233
  case 'object-row-table':
217
- case 'geojson-row-table':
218
234
  if (table.schema) {
219
235
  const arrayRow: unknown[] = target || [];
220
236
  for (let i = 0; i < table.schema.fields.length; i++) {
@@ -225,6 +241,18 @@ export function getTableRowAsArray(
225
241
  // Warning: just slap on the values, this risks mismatches between rows
226
242
  return Object.values(table.data[rowIndex]);
227
243
 
244
+ case 'geojson-table':
245
+ if (table.schema) {
246
+ const arrayRow: unknown[] = target || [];
247
+ // TODO - should lift properties to top level
248
+ for (let i = 0; i < table.schema.fields.length; i++) {
249
+ arrayRow[i] = table.features[rowIndex][table.schema.fields[i].name];
250
+ }
251
+ return arrayRow;
252
+ }
253
+ // Warning: just slap on the values, this risks mismatches between rows
254
+ return Object.values(table.features[rowIndex]);
255
+
228
256
  case 'columnar-table':
229
257
  if (table.schema) {
230
258
  const arrayRow: unknown[] = target || [];
@@ -0,0 +1,41 @@
1
+ // loaders.gl, MIT license
2
+
3
+ import {Schema} from './schema';
4
+ import type {RecordBatch} from 'apache-arrow';
5
+
6
+ /**
7
+ * A batch of data (or metadata/schema), from a streaming loader
8
+ * @see parseInBatches()
9
+ * @see loadInBatches()
10
+ */
11
+ export type Batch = {
12
+ /** A batch can contain metadata, data, or in case of unstructured data (JSON) */
13
+ batchType: 'data' | 'metadata' | 'partial-result' | 'final-result';
14
+ /** A string identifying the shape of data in this batch (table, etc) */
15
+ shape: string;
16
+ /** Schema of the data in this batch */
17
+ schema?: Schema;
18
+ /** Data in this batch */
19
+ data: unknown;
20
+ /** If this is an arrow table. @deprecated Use `data` */
21
+ recordBatch?: RecordBatch;
22
+ /** Length of data in this batch */
23
+ length: number;
24
+
25
+ /** A count of batches received */
26
+ batch?: number;
27
+
28
+ /** A count of batches received */
29
+ count?: number;
30
+
31
+ /** Bytes used so far */
32
+ bytesUsed?: number;
33
+ /** cursor is the */
34
+ cursor?: number;
35
+
36
+ /** MIME type of the data generating this batch */
37
+ mimeType?: string;
38
+
39
+ /** Any other data */
40
+ [key: string]: unknown;
41
+ };
@@ -1,7 +1,8 @@
1
1
  // loaders.gl, MIT license
2
2
 
3
- import type {Table as ApacheArrowTable, RecordBatch} from 'apache-arrow';
4
- import type {Batch, Schema} from './schema';
3
+ import type {Table as ApacheArrowTable} from 'apache-arrow';
4
+ import type {Schema} from './schema';
5
+ import type {Batch} from './batch';
5
6
  import type {Feature} from './category-gis';
6
7
 
7
8
  // Idea was to just import types, but it seems
@@ -15,12 +16,12 @@ export type Table =
15
16
  | RowTable
16
17
  | ArrayRowTable
17
18
  | ObjectRowTable
18
- | GeoJSONRowTable
19
+ | GeoJSONTable
19
20
  | ColumnarTable
20
21
  | ArrowTable;
21
22
 
22
23
  /** A table organized as an array of rows */
23
- export type RowTable = ArrayRowTable | ObjectRowTable | GeoJSONRowTable;
24
+ export type RowTable = ArrayRowTable | ObjectRowTable | GeoJSONTable;
24
25
 
25
26
  /** A table organized as an array of rows, each row is an array of values */
26
27
  export type ArrayRowTable = {
@@ -36,11 +37,17 @@ export type ObjectRowTable = {
36
37
  data: {[columnName: string]: any}[];
37
38
  };
38
39
 
39
- /** A table organized as an array of rows, each row is a GeoJSON Feature */
40
- export type GeoJSONRowTable = {
41
- shape: 'geojson-row-table';
40
+ /**
41
+ * A table organized as an array of rows, each row is a GeoJSON Feature
42
+ * @note For compatibility with GeoJSON, rows are stored in `table.features` instead of `table.data`
43
+ */
44
+ export type GeoJSONTable = {
45
+ shape: 'geojson-table';
42
46
  schema?: Schema;
43
- data: Feature[];
47
+ /** For compatibility with GeoJSON, the type field must always be set to `FeatureCollection` */
48
+ type: 'FeatureCollection';
49
+ /** For compatibility with GeoJSON, rows are stored in `table.features` instead of `table.data` */
50
+ features: Feature[];
44
51
  };
45
52
 
46
53
  /** A table organized as a map of columns, each column is an array of value */
@@ -69,7 +76,7 @@ export type Tables<TableType = Table> = {
69
76
  export type TableBatch =
70
77
  | ArrayRowTableBatch
71
78
  | ObjectRowTableBatch
72
- | GeoJSONRowTableBatch
79
+ | GeoJSONTableBatch
73
80
  | ColumnarTableBatch
74
81
  | ArrowTableBatch;
75
82
 
@@ -92,11 +99,12 @@ export type ObjectRowTableBatch = Batch & {
92
99
  };
93
100
 
94
101
  /** Batch for a table organized as an array of rows, each row is an array of values */
95
- export type GeoJSONRowTableBatch = Batch & {
96
- shape: 'geojson-row-table';
102
+ export type GeoJSONTableBatch = Batch & {
103
+ shape: 'geojson-table';
97
104
  schema?: Schema;
98
105
  schemaType?: 'explicit' | 'deduced';
99
- data: Feature[];
106
+ type: 'FeatureCollection';
107
+ features: Feature[];
100
108
  length: number;
101
109
  };
102
110
 
@@ -114,6 +122,7 @@ export type ArrowTableBatch = Batch & {
114
122
  shape: 'arrow-table';
115
123
  schemaType?: 'explicit' | 'deduced';
116
124
  schema?: Schema;
117
- data: RecordBatch;
125
+ data: ApacheArrowTable;
126
+ // recordBatch: RecordBatch;
118
127
  length: number;
119
128
  };
@@ -1,7 +1,5 @@
1
1
  // loaders.gl, MIT license
2
2
 
3
- import type {RecordBatch} from 'apache-arrow';
4
-
5
3
  /** For dictionary type */
6
4
  export type KeyType = 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' | 'uint32';
7
5
 
@@ -80,18 +78,3 @@ export type Schema = {
80
78
  fields: Field[];
81
79
  metadata: SchemaMetadata;
82
80
  };
83
-
84
- export type Batch = {
85
- batchType: 'data' | 'metadata' | 'partial-result' | 'final-result';
86
- batch?: number;
87
- mimeType?: string;
88
- shape: string;
89
- data: any;
90
- recordBatch?: RecordBatch;
91
- length: number;
92
- schema?: Schema;
93
- bytesUsed?: number;
94
- count?: number;
95
- cursor?: number;
96
- [key: string]: any;
97
- };