@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,118 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { getTableCell, getTableLength, getTableRowAsArray, getTableRowAsObject } from "./table-accessors.js";
5
- import { deduceTableSchema } from "./table-schema.js";
6
- import { makeColumnFromField } from "./table-column.js";
7
- /**
8
- * Convert a table to a different shape
9
- * @param table
10
- * @param shape
11
- * @returns
12
- */
13
- export function convertTable(table, shape) {
14
- switch (shape) {
15
- case 'object-row-table':
16
- return makeObjectRowTable(table);
17
- case 'array-row-table':
18
- return makeArrayRowTable(table);
19
- case 'columnar-table':
20
- return makeColumnarTable(table);
21
- case 'arrow-table':
22
- return makeArrowTable(table);
23
- default:
24
- throw new Error(shape);
25
- }
26
- }
27
- /**
28
- * Convert a table to apache arrow format
29
- * @note this depends on the `@loaders.gl/arrow module being imported
30
- */
31
- export function makeArrowTable(table) {
32
- const _makeArrowTable = globalThis.__loaders?._makeArrowTable;
33
- if (!_makeArrowTable) {
34
- throw new Error('');
35
- }
36
- return _makeArrowTable(table);
37
- }
38
- /** Convert any simple table into columnar format */
39
- export function makeColumnarTable(table) {
40
- // TODO - should schema really be optional?
41
- const schema = table.schema || deduceTableSchema(table);
42
- const fields = table.schema?.fields || [];
43
- if (table.shape === 'columnar-table') {
44
- return { ...table, schema };
45
- }
46
- const length = getTableLength(table);
47
- const columns = {};
48
- for (const field of fields) {
49
- const column = makeColumnFromField(field, length);
50
- columns[field.name] = column;
51
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
52
- column[rowIndex] = getTableCell(table, rowIndex, field.name);
53
- }
54
- }
55
- return {
56
- shape: 'columnar-table',
57
- schema,
58
- data: columns
59
- };
60
- }
61
- /** Convert any table into array row format */
62
- export function makeArrayRowTable(table) {
63
- if (table.shape === 'array-row-table') {
64
- return table;
65
- }
66
- const length = getTableLength(table);
67
- const data = new Array(length);
68
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
69
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
70
- }
71
- return {
72
- shape: 'array-row-table',
73
- schema: table.schema,
74
- data
75
- };
76
- }
77
- /** Convert any table into object row format */
78
- export function makeObjectRowTable(table) {
79
- if (table.shape === 'object-row-table') {
80
- return table;
81
- }
82
- const length = getTableLength(table);
83
- const data = new Array(length);
84
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
85
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
86
- }
87
- return {
88
- shape: 'object-row-table',
89
- schema: table.schema,
90
- data
91
- };
92
- }
93
- /**
94
- *
95
- * @note - should be part of schema module
96
- *
97
- export function convertColumnarToRowFormatTable(columnarTable: ColumnarTable): ObjectRowTable {
98
- const tableKeys = Object.keys(columnarTable);
99
- const tableRowsCount = columnarTable[tableKeys[0]].length;
100
-
101
- const rowFormatTable: {}[] = [];
102
-
103
- for (let index = 0; index < tableRowsCount; index++) {
104
- const tableItem = {};
105
- for (let keyIndex = 0; keyIndex < tableKeys.length; keyIndex++) {
106
- const fieldName = tableKeys[keyIndex];
107
- tableItem[fieldName] = columnarTable[fieldName][index];
108
- }
109
- rowFormatTable.push(tableItem);
110
- }
111
-
112
- return {
113
- shape: 'object-row-table',
114
- schema: columnarTable.schema,
115
- data: rowFormatTable
116
- };
117
- }
118
- */
@@ -1,17 +0,0 @@
1
- import { DataType } from "../../../types/schema.js";
2
- import { TypedArray, TypedArrayConstructor, ArrayType } from "../../../types/types.js";
3
- /** Deduce column types from values */
4
- export declare function getDataTypeFromValue(value: unknown, defaultNumberType?: 'float32'): DataType;
5
- /**
6
- * Deduces a simple data type "descriptor from a typed array instance
7
- */
8
- export declare function getDataTypeFromArray(array: ArrayType): {
9
- type: DataType;
10
- nullable: boolean;
11
- };
12
- /**
13
- * Deduces a simple data type "descriptor from a typed array instance
14
- */
15
- export declare function getDataTypeFromTypedArray(array: TypedArray): DataType;
16
- export declare function getArrayTypeFromDataType(type: DataType, nullable: boolean | undefined): TypedArrayConstructor | ArrayConstructor;
17
- //# sourceMappingURL=data-type.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"data-type.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/data-type.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,QAAQ,EAAC,iCAA8B;AAC/C,OAAO,EAAC,UAAU,EAAE,qBAAqB,EAAE,SAAS,EAAC,gCAA6B;AAElF,sCAAsC;AACtC,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,iBAAiB,GAAE,SAAqB,GACvC,QAAQ,CAcV;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,GAAG;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,OAAO,CAAA;CAAC,CAW1F;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAsBrE;AAED,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,QAAQ,EACd,QAAQ,EAAE,OAAO,GAAG,SAAS,GAC5B,qBAAqB,GAAG,gBAAgB,CA8B1C"}
@@ -1,88 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- /** Deduce column types from values */
5
- export function getDataTypeFromValue(value, defaultNumberType = 'float32') {
6
- if (value instanceof Date) {
7
- return 'date-millisecond';
8
- }
9
- if (value instanceof Number) {
10
- return defaultNumberType;
11
- }
12
- if (typeof value === 'string') {
13
- return 'utf8';
14
- }
15
- if (value === null || value === 'undefined') {
16
- return 'null';
17
- }
18
- return 'null';
19
- }
20
- /**
21
- * Deduces a simple data type "descriptor from a typed array instance
22
- */
23
- export function getDataTypeFromArray(array) {
24
- let type = getDataTypeFromTypedArray(array);
25
- if (type !== 'null') {
26
- return { type, nullable: false };
27
- }
28
- if (array.length > 0) {
29
- type = getDataTypeFromValue(array[0]);
30
- return { type, nullable: true };
31
- }
32
- return { type: 'null', nullable: true };
33
- }
34
- /**
35
- * Deduces a simple data type "descriptor from a typed array instance
36
- */
37
- export function getDataTypeFromTypedArray(array) {
38
- switch (array.constructor) {
39
- case Int8Array:
40
- return 'int8';
41
- case Uint8Array:
42
- case Uint8ClampedArray:
43
- return 'uint8';
44
- case Int16Array:
45
- return 'int16';
46
- case Uint16Array:
47
- return 'uint16';
48
- case Int32Array:
49
- return 'int32';
50
- case Uint32Array:
51
- return 'uint32';
52
- case Float32Array:
53
- return 'float32';
54
- case Float64Array:
55
- return 'float64';
56
- default:
57
- return 'null';
58
- }
59
- }
60
- export function getArrayTypeFromDataType(type, nullable) {
61
- if (!nullable) {
62
- switch (type) {
63
- case 'int8':
64
- return Int8Array;
65
- case 'uint8':
66
- return Uint8Array;
67
- case 'int16':
68
- return Int16Array;
69
- case 'uint16':
70
- return Uint16Array;
71
- case 'int32':
72
- return Int32Array;
73
- case 'uint32':
74
- return Uint32Array;
75
- case 'float32':
76
- return Float32Array;
77
- case 'float64':
78
- return Float64Array;
79
- default:
80
- break;
81
- }
82
- }
83
- // if (typeof BigInt64Array !== 'undefined') {
84
- // TYPED_ARRAY_TO_TYPE.BigInt64Array = new Int64();
85
- // TYPED_ARRAY_TO_TYPE.BigUint64Array = new Uint64();
86
- // }
87
- return Array;
88
- }
@@ -1,22 +0,0 @@
1
- import type { TableBatch, Table } from "../../../types/category-table.js";
2
- /**
3
- * Returns an iterator that yields a single table as a sequence of batches.
4
- * @note Currently only a single batch is yielded.
5
- * @note All batches will have the same shape and schema as the original table.
6
- * @returns
7
- */
8
- export declare function makeBatchesFromTable(table: Table): IterableIterator<TableBatch>;
9
- /**
10
- * Returns a table packaged as a single table batch
11
- * @note The batch will have the same shape and schema as the original table.
12
- * @returns `null` if no batches are yielded by the async iterator
13
- */
14
- export declare function makeBatchFromTable(table: Table): TableBatch;
15
- /**
16
- * Assembles all batches from an async iterator into a single table.
17
- * @note All batches must have the same shape and schema
18
- * @param batchIterator
19
- * @returns `null` if no batches are yielded by the async iterator
20
- */
21
- export declare function makeTableFromBatches(batchIterator: AsyncIterable<TableBatch> | Iterable<TableBatch>): Promise<Table | null>;
22
- //# sourceMappingURL=make-table-from-batches.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"make-table-from-batches.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/make-table-from-batches.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,UAAU,EAAE,KAAK,EAAgC,yCAAsC;AAIpG;;;;;GAKG;AACH,wBAAiB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAEhF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAE3D;AAED;;;;;GAKG;AAEH,wBAAsB,oBAAoB,CACxC,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,GAC9D,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CA4DvB"}
@@ -1,79 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { getTableLength } from "./table-accessors.js";
5
- /**
6
- * Returns an iterator that yields a single table as a sequence of batches.
7
- * @note Currently only a single batch is yielded.
8
- * @note All batches will have the same shape and schema as the original table.
9
- * @returns
10
- */
11
- export function* makeBatchesFromTable(table) {
12
- yield makeBatchFromTable(table);
13
- }
14
- /**
15
- * Returns a table packaged as a single table batch
16
- * @note The batch will have the same shape and schema as the original table.
17
- * @returns `null` if no batches are yielded by the async iterator
18
- */
19
- export function makeBatchFromTable(table) {
20
- return { ...table, length: getTableLength(table), batchType: 'data' };
21
- }
22
- /**
23
- * Assembles all batches from an async iterator into a single table.
24
- * @note All batches must have the same shape and schema
25
- * @param batchIterator
26
- * @returns `null` if no batches are yielded by the async iterator
27
- */
28
- // eslint-disable-next-line complexity
29
- export async function makeTableFromBatches(batchIterator) {
30
- let arrayRows;
31
- let objectRows;
32
- let features;
33
- let shape = null;
34
- let schema;
35
- for await (const batch of batchIterator) {
36
- shape = shape || batch.shape;
37
- schema = schema || batch.schema;
38
- switch (batch.shape) {
39
- case 'array-row-table':
40
- arrayRows = arrayRows || [];
41
- for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
42
- const row = batch.data[rowIndex];
43
- arrayRows.push(row);
44
- }
45
- break;
46
- case 'object-row-table':
47
- objectRows = objectRows || [];
48
- for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
49
- const row = batch.data[rowIndex];
50
- objectRows.push(row);
51
- }
52
- break;
53
- case 'geojson-table':
54
- features = features || [];
55
- for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
56
- const row = batch.features[rowIndex];
57
- features.push(row);
58
- }
59
- break;
60
- case 'columnar-table':
61
- case 'arrow-table':
62
- default:
63
- throw new Error('shape');
64
- }
65
- }
66
- if (!shape) {
67
- return null;
68
- }
69
- switch (shape) {
70
- case 'array-row-table':
71
- return { shape: 'array-row-table', data: arrayRows, schema };
72
- case 'object-row-table':
73
- return { shape: 'object-row-table', data: objectRows, schema };
74
- case 'geojson-table':
75
- return { shape: 'geojson-table', type: 'FeatureCollection', features: features, schema };
76
- default:
77
- return null;
78
- }
79
- }
@@ -1,65 +0,0 @@
1
- import { ArrayRowTable, ObjectRowTable, ColumnarTable } from "../../../types/category-table.js";
2
- /**
3
- * Makes a typed table from data.
4
- * @throws Row tables must contain at least one row. Columnar tables must contain empty arrays
5
- */
6
- export declare function makeTableFromData(data: unknown[][]): ArrayRowTable;
7
- export declare function makeTableFromData(data: {
8
- [column: string]: unknown;
9
- }[]): ObjectRowTable;
10
- export declare function makeTableFromData(data: {
11
- [column: string]: ArrayLike<unknown>;
12
- }): ColumnarTable;
13
- /** Convert any table into object row format *
14
- export function makeColumnarTable(table: Table): ColumnarTable {
15
- if (table.shape === 'columnar-table') {
16
- return table;
17
- }
18
- const length = getTableLength(table);
19
- const data = new Array<{[key: string]: unknown}>(length);
20
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
21
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
22
- }
23
- return {
24
- shape: 'columnar-table',
25
- schema: table.schema,
26
- data
27
- };
28
- }
29
-
30
-
31
- /** Convert any table into array row format *
32
- export function makeArrayRowTable(table: TableLike): ArrayRowTable {
33
- if (table.shape === 'array-row-table') {
34
- return table;
35
- }
36
- const length = getTableLength(table);
37
- const data = new Array<unknown[]>(length);
38
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
39
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
40
- }
41
- return {
42
- shape: 'array-row-table',
43
- schema: table.schema,
44
- data
45
- };
46
- }
47
-
48
- /** Convert any table into object row format *
49
- export function makeObjectRowTable(table: Table): ObjectRowTable {
50
- if (table.shape === 'object-row-table') {
51
- return table;
52
- }
53
- const length = getTableLength(table);
54
- const data = new Array<{[key: string]: unknown}>(length);
55
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
56
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
57
- }
58
- return {
59
- shape: 'object-row-table',
60
- schema: table.schema,
61
- data
62
- };
63
- }
64
- */
65
- //# sourceMappingURL=make-table.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"make-table.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/make-table.ts"],"names":[],"mappings":"AAIA,OAAO,EAAQ,aAAa,EAAE,cAAc,EAAE,aAAa,EAAC,yCAAsC;AAGlG;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,GAAG,aAAa,CAAC;AACpE,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IAAC,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EAAE,GAAG,cAAc,CAAC;AACvF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IAAC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,CAAA;CAAC,GAAG,aAAa,CAAC;AA8C/F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmDE"}
@@ -1,94 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- import { deduceTableSchema } from "./table-schema.js";
5
- export function makeTableFromData(data) {
6
- let table;
7
- switch (getTableShapeFromData(data)) {
8
- case 'array-row-table':
9
- table = { shape: 'array-row-table', data: data };
10
- break;
11
- case 'object-row-table':
12
- table = { shape: 'object-row-table', data: data };
13
- break;
14
- case 'columnar-table':
15
- table = { shape: 'columnar-table', data: data };
16
- break;
17
- default:
18
- throw new Error('table');
19
- }
20
- const schema = deduceTableSchema(table);
21
- return { ...table, schema };
22
- }
23
- /** Helper function to get shape of data */
24
- function getTableShapeFromData(data) {
25
- if (Array.isArray(data)) {
26
- if (data.length === 0) {
27
- throw new Error('cannot deduce type of empty table');
28
- }
29
- // Deduce the table shape from the first row
30
- const firstRow = data[0];
31
- if (Array.isArray(firstRow)) {
32
- return 'array-row-table';
33
- }
34
- if (firstRow && typeof firstRow === 'object') {
35
- return 'object-row-table';
36
- }
37
- }
38
- if (data && typeof data === 'object') {
39
- return 'columnar-table';
40
- }
41
- throw new Error('invalid table');
42
- }
43
- /** Convert any table into object row format *
44
- export function makeColumnarTable(table: Table): ColumnarTable {
45
- if (table.shape === 'columnar-table') {
46
- return table;
47
- }
48
- const length = getTableLength(table);
49
- const data = new Array<{[key: string]: unknown}>(length);
50
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
51
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
52
- }
53
- return {
54
- shape: 'columnar-table',
55
- schema: table.schema,
56
- data
57
- };
58
- }
59
-
60
-
61
- /** Convert any table into array row format *
62
- export function makeArrayRowTable(table: TableLike): ArrayRowTable {
63
- if (table.shape === 'array-row-table') {
64
- return table;
65
- }
66
- const length = getTableLength(table);
67
- const data = new Array<unknown[]>(length);
68
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
69
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
70
- }
71
- return {
72
- shape: 'array-row-table',
73
- schema: table.schema,
74
- data
75
- };
76
- }
77
-
78
- /** Convert any table into object row format *
79
- export function makeObjectRowTable(table: Table): ObjectRowTable {
80
- if (table.shape === 'object-row-table') {
81
- return table;
82
- }
83
- const length = getTableLength(table);
84
- const data = new Array<{[key: string]: unknown}>(length);
85
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
86
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
87
- }
88
- return {
89
- shape: 'object-row-table',
90
- schema: table.schema,
91
- data
92
- };
93
- }
94
- */
@@ -1,15 +0,0 @@
1
- /** Convert an object row to an array row */
2
- export declare function convertToObjectRow(arrayRow: unknown[], headers: string[] | null): {
3
- [columnName: string]: unknown;
4
- };
5
- /** Convert an object row to an array row */
6
- export declare function convertToArrayRow(objectRow: {
7
- [columnName: string]: unknown;
8
- }, headers: string[] | null): unknown[];
9
- /** Get headers from a sample array row */
10
- export declare function inferHeadersFromArrayRow(arrayRow: unknown[]): string[];
11
- /** Get headers from a smaple object row */
12
- export declare function inferHeadersFromObjectRow(row: {
13
- [columnName: string]: unknown;
14
- }): string[];
15
- //# sourceMappingURL=row-utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"row-utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/row-utils.ts"],"names":[],"mappings":"AAIA,4CAA4C;AAC5C,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,OAAO,EAAE,EACnB,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,GACvB;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAgBjC;AAED,4CAA4C;AAC5C,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EAC1C,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,GACvB,OAAO,EAAE,CAaX;AAED,0CAA0C;AAC1C,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAO3D;AAED,2CAA2C;AAC3C,wBAAgB,yBAAyB,CAAC,GAAG,EAAE;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,YAE7E"}
@@ -1,49 +0,0 @@
1
- // loaders.gl
2
- // SPDX-License-Identifier: MIT
3
- // Copyright (c) vis.gl contributors
4
- /** Convert an object row to an array row */
5
- export function convertToObjectRow(arrayRow, headers) {
6
- if (!arrayRow) {
7
- throw new Error('null row');
8
- }
9
- const objectRow = {};
10
- if (headers) {
11
- for (let i = 0; i < headers.length; i++) {
12
- objectRow[headers[i]] = arrayRow[i];
13
- }
14
- }
15
- else {
16
- for (let i = 0; i < arrayRow.length; i++) {
17
- const columnName = `column-${i}`;
18
- objectRow[columnName] = arrayRow[i];
19
- }
20
- }
21
- return objectRow;
22
- }
23
- /** Convert an object row to an array row */
24
- export function convertToArrayRow(objectRow, headers) {
25
- if (!objectRow) {
26
- throw new Error('null row');
27
- }
28
- if (headers) {
29
- const arrayRow = new Array(headers.length);
30
- for (let i = 0; i < headers.length; i++) {
31
- arrayRow[i] = objectRow[headers[i]];
32
- }
33
- return arrayRow;
34
- }
35
- return Object.values(objectRow);
36
- }
37
- /** Get headers from a sample array row */
38
- export function inferHeadersFromArrayRow(arrayRow) {
39
- const headers = [];
40
- for (let i = 0; i < arrayRow.length; i++) {
41
- const columnName = `column-${i}`;
42
- headers.push(columnName);
43
- }
44
- return headers;
45
- }
46
- /** Get headers from a smaple object row */
47
- export function inferHeadersFromObjectRow(row) {
48
- return Object.keys(row);
49
- }
@@ -1,68 +0,0 @@
1
- import { Table, ArrayRowTable, ObjectRowTable } from "../../../types/category-table.js";
2
- export declare function isTable(table: any): table is Table;
3
- /**
4
- * Returns the length of the table (i.e. the number of rows)
5
- */
6
- export declare function getTableLength(table: Table): number;
7
- /**
8
- * Returns the number of columns in the table
9
- * @throws Fails to deduce number of columns if the table has no schema and is empty
10
- */
11
- export declare function getTableNumCols(table: Table): number;
12
- /** Get a table cell value at row index and column name */
13
- export declare function getTableCell(table: Table, rowIndex: number, columnName: string): unknown;
14
- /** Get a table cell value at row index and column name */
15
- export declare function getTableCellAt(table: Table, rowIndex: number, columnIndex: number): unknown;
16
- /** Deduce the table row shape */
17
- export declare function getTableRowShape(table: Table): 'array-row-table' | 'object-row-table';
18
- /** Get the index of a named table column. Requires the table to have a schema */
19
- export declare function getTableColumnIndex(table: Table, columnName: string): number;
20
- /** Get the name of a table column by index. Requires the table to have a schema */
21
- export declare function getTableColumnName(table: Table, columnIndex: number): string;
22
- /**
23
- * Returns one row of the table in object format.
24
- * @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance
25
- * @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
26
- */
27
- export declare function getTableRowAsObject(table: Table, rowIndex: number, target?: {
28
- [columnName: string]: unknown;
29
- }, copy?: 'copy'): {
30
- [columnName: string]: unknown;
31
- };
32
- /**
33
- * Returns one row of the table in array format.
34
- * @param target Optional parameter will be used if needed to store the row. Can be reused between calls to improve performance.
35
- * @returns an array representing the row. May be the original array in the row, a new object, or the target parameter
36
- */
37
- export declare function getTableRowAsArray(table: Table, rowIndex: number, target?: unknown[], copy?: 'copy'): unknown[];
38
- /** Convert any table into array row format */
39
- export declare function makeArrayRowTable(table: Table): ArrayRowTable;
40
- /** Convert any table into object row format */
41
- export declare function makeObjectRowTable(table: Table): ObjectRowTable;
42
- /** Convert any table into object row format */
43
- export declare function makeColumnarTable(table: Table): ObjectRowTable;
44
- /**
45
- * Iterate over table rows
46
- * @param table
47
- * @param shape
48
- */
49
- export declare function makeRowIterator(table: Table, shape: 'object-row-table' | 'array-row-table'): Iterable<unknown[] | {
50
- [key: string]: unknown;
51
- }>;
52
- /**
53
- * Streaming processing: Iterate over table, yielding array rows
54
- * @param table
55
- * @param shape
56
- */
57
- export declare function makeArrayRowIterator(table: Table, target?: unknown[]): Iterable<unknown[]>;
58
- /**
59
- * Streaming processing: Iterate over table, yielding object rows
60
- * @param table
61
- * @param shape
62
- */
63
- export declare function makeObjectRowIterator(table: Table, target?: {
64
- [key: string]: unknown;
65
- }): Iterable<{
66
- [key: string]: unknown;
67
- }>;
68
- //# sourceMappingURL=table-accessors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"table-accessors.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/simple-table/table-accessors.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAE,aAAa,EAAE,cAAc,EAAC,yCAAsC;AAEnF,wBAAgB,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,KAAK,IAAI,KAAK,CAmBlD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAqBnD;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAsBpD;AAED,0DAA0D;AAC1D,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CA0BxF;AAED,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAyB3F;AAED,iCAAiC;AACjC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,iBAAiB,GAAG,kBAAkB,CAcrF;AAED,iFAAiF;AACjF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAM5E;AAED,mFAAmF;AACnF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAM5E;AAED;;;;GAIG;AAEH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EACxC,IAAI,CAAC,EAAE,MAAM,GACZ;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAwDjC;AAED;;;;GAIG;AAEH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,OAAO,EAAE,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,EAAE,CA2DX;AAED,8CAA8C;AAC9C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAc7D;AAED,+CAA+C;AAC/C,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,CAc/D;AAED,+CAA+C;AAC/C,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,CAc9D;AAID;;;;GAIG;AACH,wBAAiB,eAAe,CAC9B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,kBAAkB,GAAG,iBAAiB,GAC5C,QAAQ,CAAC,OAAO,EAAE,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC,CAYhD;AAED;;;;GAIG;AACH,wBAAiB,oBAAoB,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,GAAE,OAAO,EAAO,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,CAK/F;AAED;;;;GAIG;AACH,wBAAiB,qBAAqB,CACpC,KAAK,EAAE,KAAK,EACZ,MAAM,GAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAM,GACpC,QAAQ,CAAC;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC,CAKpC"}