@loaders.gl/schema 4.2.0-alpha.4 → 4.2.0-alpha.6

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 (136) hide show
  1. package/dist/dist.dev.js +216 -147
  2. package/dist/dist.min.js +9 -0
  3. package/dist/index.cjs +128 -97
  4. package/dist/index.cjs.map +7 -0
  5. package/dist/index.d.ts +30 -30
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +9 -1
  8. package/dist/lib/mesh/convert-mesh.d.ts +2 -2
  9. package/dist/lib/mesh/convert-mesh.d.ts.map +1 -1
  10. package/dist/lib/mesh/convert-mesh.js +33 -18
  11. package/dist/lib/mesh/deduce-mesh-schema.d.ts +2 -2
  12. package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -1
  13. package/dist/lib/mesh/deduce-mesh-schema.js +54 -40
  14. package/dist/lib/mesh/mesh-to-arrow-table.js +46 -1
  15. package/dist/lib/mesh/mesh-utils.d.ts +2 -2
  16. package/dist/lib/mesh/mesh-utils.d.ts.map +1 -1
  17. package/dist/lib/mesh/mesh-utils.js +41 -28
  18. package/dist/lib/table/arrow-api/arrow-like-field.d.ts +1 -1
  19. package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +1 -1
  20. package/dist/lib/table/arrow-api/arrow-like-field.js +34 -25
  21. package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +2 -2
  22. package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +1 -1
  23. package/dist/lib/table/arrow-api/arrow-like-schema.js +71 -56
  24. package/dist/lib/table/arrow-api/arrow-like-table.d.ts +2 -2
  25. package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -1
  26. package/dist/lib/table/arrow-api/arrow-like-table.js +57 -45
  27. package/dist/lib/table/arrow-api/arrow-like-type.d.ts +3 -3
  28. package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +1 -1
  29. package/dist/lib/table/arrow-api/arrow-like-type.js +371 -321
  30. package/dist/lib/table/arrow-api/enum.js +97 -48
  31. package/dist/lib/table/arrow-api/get-type-info.d.ts +1 -1
  32. package/dist/lib/table/arrow-api/get-type-info.d.ts.map +1 -1
  33. package/dist/lib/table/arrow-api/get-type-info.js +20 -14
  34. package/dist/lib/table/arrow-api/index.d.ts +4 -4
  35. package/dist/lib/table/arrow-api/index.d.ts.map +1 -1
  36. package/dist/lib/table/arrow-api/index.js +3 -1
  37. package/dist/lib/table/batches/base-table-batch-aggregator.d.ts +3 -3
  38. package/dist/lib/table/batches/base-table-batch-aggregator.d.ts.map +1 -1
  39. package/dist/lib/table/batches/base-table-batch-aggregator.js +56 -52
  40. package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts +3 -3
  41. package/dist/lib/table/batches/columnar-table-batch-aggregator.d.ts.map +1 -1
  42. package/dist/lib/table/batches/columnar-table-batch-aggregator.js +82 -67
  43. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts +3 -3
  44. package/dist/lib/table/batches/row-table-batch-aggregator.d.ts.map +1 -1
  45. package/dist/lib/table/batches/row-table-batch-aggregator.js +76 -67
  46. package/dist/lib/table/batches/table-batch-aggregator.d.ts +2 -2
  47. package/dist/lib/table/batches/table-batch-aggregator.d.ts.map +1 -1
  48. package/dist/lib/table/batches/table-batch-aggregator.js +3 -1
  49. package/dist/lib/table/batches/table-batch-builder.d.ts +3 -3
  50. package/dist/lib/table/batches/table-batch-builder.d.ts.map +1 -1
  51. package/dist/lib/table/batches/table-batch-builder.js +131 -116
  52. package/dist/lib/table/simple-table/convert-table.d.ts +1 -1
  53. package/dist/lib/table/simple-table/convert-table.d.ts.map +1 -1
  54. package/dist/lib/table/simple-table/convert-table.js +97 -62
  55. package/dist/lib/table/simple-table/data-type.d.ts +2 -2
  56. package/dist/lib/table/simple-table/data-type.d.ts.map +1 -1
  57. package/dist/lib/table/simple-table/data-type.js +79 -76
  58. package/dist/lib/table/simple-table/make-table-from-batches.js +70 -67
  59. package/dist/lib/table/simple-table/make-table.d.ts +1 -1
  60. package/dist/lib/table/simple-table/make-table.d.ts.map +1 -1
  61. package/dist/lib/table/simple-table/make-table.js +85 -41
  62. package/dist/lib/table/simple-table/row-utils.js +38 -31
  63. package/dist/lib/table/simple-table/table-accessors.d.ts +1 -1
  64. package/dist/lib/table/simple-table/table-accessors.d.ts.map +1 -1
  65. package/dist/lib/table/simple-table/table-accessors.js +314 -270
  66. package/dist/lib/table/simple-table/table-column.d.ts +1 -1
  67. package/dist/lib/table/simple-table/table-column.d.ts.map +1 -1
  68. package/dist/lib/table/simple-table/table-column.js +36 -3
  69. package/dist/lib/table/simple-table/table-schema.d.ts +2 -2
  70. package/dist/lib/table/simple-table/table-schema.d.ts.map +1 -1
  71. package/dist/lib/table/simple-table/table-schema.js +69 -56
  72. package/dist/lib/utils/assert.js +6 -4
  73. package/dist/lib/utils/async-queue.js +79 -82
  74. package/dist/types/batch.d.ts +1 -1
  75. package/dist/types/batch.d.ts.map +1 -1
  76. package/dist/types/batch.js +3 -1
  77. package/dist/types/binary-geometries.d.ts +1 -1
  78. package/dist/types/binary-geometries.d.ts.map +1 -1
  79. package/dist/types/binary-geometries.js +3 -1
  80. package/dist/types/category-gis.d.ts +2 -2
  81. package/dist/types/category-gis.d.ts.map +1 -1
  82. package/dist/types/category-gis.js +3 -1
  83. package/dist/types/category-image.js +3 -1
  84. package/dist/types/category-mesh.d.ts +3 -3
  85. package/dist/types/category-mesh.d.ts.map +1 -1
  86. package/dist/types/category-mesh.js +3 -1
  87. package/dist/types/category-table.d.ts +3 -3
  88. package/dist/types/category-table.d.ts.map +1 -1
  89. package/dist/types/category-table.js +3 -1
  90. package/dist/types/category-texture.d.ts +1 -1
  91. package/dist/types/category-texture.d.ts.map +1 -1
  92. package/dist/types/category-texture.js +3 -1
  93. package/dist/types/flat-geometries.js +3 -1
  94. package/dist/types/schema.js +3 -1
  95. package/dist/types/types.js +3 -1
  96. package/package.json +8 -4
  97. package/src/index.ts +1 -1
  98. package/src/lib/table/arrow-api/arrow-like-field.ts +2 -2
  99. package/src/lib/table/arrow-api/arrow-like-type.ts +4 -2
  100. package/dist/index.js.map +0 -1
  101. package/dist/lib/mesh/convert-mesh.js.map +0 -1
  102. package/dist/lib/mesh/deduce-mesh-schema.js.map +0 -1
  103. package/dist/lib/mesh/mesh-to-arrow-table.js.map +0 -1
  104. package/dist/lib/mesh/mesh-utils.js.map +0 -1
  105. package/dist/lib/table/arrow-api/arrow-like-field.js.map +0 -1
  106. package/dist/lib/table/arrow-api/arrow-like-schema.js.map +0 -1
  107. package/dist/lib/table/arrow-api/arrow-like-table.js.map +0 -1
  108. package/dist/lib/table/arrow-api/arrow-like-type.js.map +0 -1
  109. package/dist/lib/table/arrow-api/enum.js.map +0 -1
  110. package/dist/lib/table/arrow-api/get-type-info.js.map +0 -1
  111. package/dist/lib/table/arrow-api/index.js.map +0 -1
  112. package/dist/lib/table/batches/base-table-batch-aggregator.js.map +0 -1
  113. package/dist/lib/table/batches/columnar-table-batch-aggregator.js.map +0 -1
  114. package/dist/lib/table/batches/row-table-batch-aggregator.js.map +0 -1
  115. package/dist/lib/table/batches/table-batch-aggregator.js.map +0 -1
  116. package/dist/lib/table/batches/table-batch-builder.js.map +0 -1
  117. package/dist/lib/table/simple-table/convert-table.js.map +0 -1
  118. package/dist/lib/table/simple-table/data-type.js.map +0 -1
  119. package/dist/lib/table/simple-table/make-table-from-batches.js.map +0 -1
  120. package/dist/lib/table/simple-table/make-table.js.map +0 -1
  121. package/dist/lib/table/simple-table/row-utils.js.map +0 -1
  122. package/dist/lib/table/simple-table/table-accessors.js.map +0 -1
  123. package/dist/lib/table/simple-table/table-column.js.map +0 -1
  124. package/dist/lib/table/simple-table/table-schema.js.map +0 -1
  125. package/dist/lib/utils/assert.js.map +0 -1
  126. package/dist/lib/utils/async-queue.js.map +0 -1
  127. package/dist/types/batch.js.map +0 -1
  128. package/dist/types/binary-geometries.js.map +0 -1
  129. package/dist/types/category-gis.js.map +0 -1
  130. package/dist/types/category-image.js.map +0 -1
  131. package/dist/types/category-mesh.js.map +0 -1
  132. package/dist/types/category-table.js.map +0 -1
  133. package/dist/types/category-texture.js.map +0 -1
  134. package/dist/types/flat-geometries.js.map +0 -1
  135. package/dist/types/schema.js.map +0 -1
  136. package/dist/types/types.js.map +0 -1
@@ -1,306 +1,350 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
1
4
  export function isTable(table) {
2
- var _table$data;
3
- const shape = typeof table === 'object' && (table === null || table === void 0 ? void 0 : table.shape);
4
- switch (shape) {
5
- case 'array-row-table':
6
- case 'object-row-table':
7
- return Array.isArray(table.data);
8
- case 'geojson-table':
9
- return Array.isArray(table.features);
10
- case 'columnar-table':
11
- return table.data && typeof table.data === 'object';
12
- case 'arrow-table':
13
- return Boolean((table === null || table === void 0 ? void 0 : (_table$data = table.data) === null || _table$data === void 0 ? void 0 : _table$data.numRows) !== undefined);
14
- default:
15
- return false;
16
- }
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
+ }
17
19
  }
20
+ /**
21
+ * Returns the length of the table (i.e. the number of rows)
22
+ */
18
23
  export function getTableLength(table) {
19
- switch (table.shape) {
20
- case 'array-row-table':
21
- case 'object-row-table':
22
- return table.data.length;
23
- case 'geojson-table':
24
- return table.features.length;
25
- case 'arrow-table':
26
- const arrowTable = table.data;
27
- return arrowTable.numRows;
28
- case 'columnar-table':
29
- for (const column of Object.values(table.data)) {
30
- return column.length || 0;
31
- }
32
- return 0;
33
- default:
34
- throw new Error('table');
35
- }
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
+ }
36
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
+ */
37
46
  export function getTableNumCols(table) {
38
- if (table.schema) {
39
- return table.schema.fields.length;
40
- }
41
- if (getTableLength(table) === 0) {
42
- throw new Error('empty table');
43
- }
44
- switch (table.shape) {
45
- case 'array-row-table':
46
- return table.data[0].length;
47
- case 'object-row-table':
48
- return Object.keys(table.data[0]).length;
49
- case 'geojson-table':
50
- return Object.keys(table.features[0]).length;
51
- case 'columnar-table':
52
- return Object.keys(table.data).length;
53
- case 'arrow-table':
54
- const arrowTable = table.data;
55
- return arrowTable.numCols;
56
- default:
57
- throw new Error('table');
58
- }
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
+ }
59
68
  }
69
+ /** Get a table cell value at row index and column name */
60
70
  export function getTableCell(table, rowIndex, columnName) {
61
- var _arrowTable$getChildA;
62
- switch (table.shape) {
63
- case 'array-row-table':
64
- const columnIndex = getTableColumnIndex(table, columnName);
65
- return table.data[rowIndex][columnIndex];
66
- case 'object-row-table':
67
- return table.data[rowIndex][columnName];
68
- case 'geojson-table':
69
- return table.features[rowIndex][columnName];
70
- case 'columnar-table':
71
- const column = table.data[columnName];
72
- return column[rowIndex];
73
- case 'arrow-table':
74
- const arrowTable = table.data;
75
- const arrowColumnIndex = arrowTable.schema.fields.findIndex(field => field.name === columnName);
76
- return (_arrowTable$getChildA = arrowTable.getChildAt(arrowColumnIndex)) === null || _arrowTable$getChildA === void 0 ? void 0 : _arrowTable$getChildA.get(rowIndex);
77
- default:
78
- throw new Error('todo');
79
- }
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
+ }
80
89
  }
90
+ /** Get a table cell value at row index and column name */
81
91
  export function getTableCellAt(table, rowIndex, columnIndex) {
82
- var _arrowTable$getChildA2;
83
- switch (table.shape) {
84
- case 'array-row-table':
85
- return table.data[rowIndex][columnIndex];
86
- case 'object-row-table':
87
- const columnName1 = getTableColumnName(table, columnIndex);
88
- return table.data[rowIndex][columnName1];
89
- case 'geojson-table':
90
- const columnName2 = getTableColumnName(table, columnIndex);
91
- return table.features[rowIndex][columnName2];
92
- case 'columnar-table':
93
- const columnName3 = getTableColumnName(table, columnIndex);
94
- const column = table.data[columnName3];
95
- return column[rowIndex];
96
- case 'arrow-table':
97
- const arrowTable = table.data;
98
- return (_arrowTable$getChildA2 = arrowTable.getChildAt(columnIndex)) === null || _arrowTable$getChildA2 === void 0 ? void 0 : _arrowTable$getChildA2.get(rowIndex);
99
- default:
100
- throw new Error('todo');
101
- }
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
+ }
102
111
  }
112
+ /** Deduce the table row shape */
103
113
  export function getTableRowShape(table) {
104
- switch (table.shape) {
105
- case 'array-row-table':
106
- case 'object-row-table':
107
- return table.shape;
108
- case 'geojson-table':
109
- return 'object-row-table';
110
- case 'columnar-table':
111
- default:
112
- throw new Error('Not a row table');
113
- }
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
+ }
114
125
  }
126
+ /** Get the index of a named table column. Requires the table to have a schema */
115
127
  export function getTableColumnIndex(table, columnName) {
116
- var _table$schema;
117
- const columnIndex = (_table$schema = table.schema) === null || _table$schema === void 0 ? void 0 : _table$schema.fields.findIndex(field => field.name === columnName);
118
- if (columnIndex === undefined) {
119
- throw new Error(columnName);
120
- }
121
- return columnIndex;
128
+ const columnIndex = table.schema?.fields.findIndex((field) => field.name === columnName);
129
+ if (columnIndex === undefined) {
130
+ throw new Error(columnName);
131
+ }
132
+ return columnIndex;
122
133
  }
134
+ /** Get the name of a table column by index. Requires the table to have a schema */
123
135
  export function getTableColumnName(table, columnIndex) {
124
- var _table$schema2, _table$schema2$fields;
125
- const columnName = (_table$schema2 = table.schema) === null || _table$schema2 === void 0 ? void 0 : (_table$schema2$fields = _table$schema2.fields[columnIndex]) === null || _table$schema2$fields === void 0 ? void 0 : _table$schema2$fields.name;
126
- if (!columnName) {
127
- throw new Error(`${columnIndex}`);
128
- }
129
- return columnName;
136
+ const columnName = table.schema?.fields[columnIndex]?.name;
137
+ if (!columnName) {
138
+ throw new Error(`${columnIndex}`);
139
+ }
140
+ return columnName;
130
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
131
148
  export function getTableRowAsObject(table, rowIndex, target, copy) {
132
- switch (table.shape) {
133
- case 'object-row-table':
134
- return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
135
- case 'array-row-table':
136
- if (table.schema) {
137
- const objectRow = target || {};
138
- for (let i = 0; i < table.schema.fields.length; i++) {
139
- objectRow[table.schema.fields[i].name] = table.data[rowIndex][i];
140
- }
141
- return objectRow;
142
- }
143
- throw new Error('no schema');
144
- case 'geojson-table':
145
- if (table.schema) {
146
- const objectRow = target || {};
147
- for (let i = 0; i < table.schema.fields.length; i++) {
148
- objectRow[table.schema.fields[i].name] = table.features[rowIndex][i];
149
- }
150
- return objectRow;
151
- }
152
- throw new Error('no schema');
153
- case 'columnar-table':
154
- if (table.schema) {
155
- const objectRow = target || {};
156
- for (let i = 0; i < table.schema.fields.length; i++) {
157
- objectRow[table.schema.fields[i].name] = table.data[table.schema.fields[i].name][rowIndex];
158
- }
159
- return objectRow;
160
- } else {
161
- const objectRow = target || {};
162
- for (const [name, column] of Object.entries(table.data)) {
163
- objectRow[name] = column[rowIndex];
164
- }
165
- return objectRow;
166
- }
167
- case 'arrow-table':
168
- const arrowTable = table.data;
169
- const objectRow = target || {};
170
- const row = arrowTable.get(rowIndex);
171
- const schema = arrowTable.schema;
172
- for (let i = 0; i < schema.fields.length; i++) {
173
- objectRow[schema.fields[i].name] = row === null || row === void 0 ? void 0 : row[schema.fields[i].name];
174
- }
175
- return objectRow;
176
- default:
177
- throw new Error('shape');
178
- }
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
+ }
179
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
180
207
  export function getTableRowAsArray(table, rowIndex, target, copy) {
181
- switch (table.shape) {
182
- case 'array-row-table':
183
- return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
184
- case 'object-row-table':
185
- if (table.schema) {
186
- const arrayRow = target || [];
187
- for (let i = 0; i < table.schema.fields.length; i++) {
188
- arrayRow[i] = table.data[rowIndex][table.schema.fields[i].name];
189
- }
190
- return arrayRow;
191
- }
192
- return Object.values(table.data[rowIndex]);
193
- case 'geojson-table':
194
- if (table.schema) {
195
- const arrayRow = target || [];
196
- for (let i = 0; i < table.schema.fields.length; i++) {
197
- arrayRow[i] = table.features[rowIndex][table.schema.fields[i].name];
198
- }
199
- return arrayRow;
200
- }
201
- return Object.values(table.features[rowIndex]);
202
- case 'columnar-table':
203
- if (table.schema) {
204
- const arrayRow = target || [];
205
- for (let i = 0; i < table.schema.fields.length; i++) {
206
- arrayRow[i] = table.data[table.schema.fields[i].name][rowIndex];
207
- }
208
- return arrayRow;
209
- } else {
210
- const arrayRow = target || [];
211
- let i = 0;
212
- for (const column of Object.values(table.data)) {
213
- arrayRow[i] = column[rowIndex];
214
- i++;
215
- }
216
- return arrayRow;
217
- }
218
- case 'arrow-table':
219
- const arrowTable = table.data;
220
- const arrayRow = target || [];
221
- const row = arrowTable.get(rowIndex);
222
- const schema = arrowTable.schema;
223
- for (let i = 0; i < schema.fields.length; i++) {
224
- arrayRow[i] = row === null || row === void 0 ? void 0 : row[schema.fields[i].name];
225
- }
226
- return arrayRow;
227
- default:
228
- throw new Error('shape');
229
- }
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
+ }
230
262
  }
263
+ /** Convert any table into array row format */
231
264
  export function makeArrayRowTable(table) {
232
- if (table.shape === 'array-row-table') {
233
- return table;
234
- }
235
- const length = getTableLength(table);
236
- const data = new Array(length);
237
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
238
- data[rowIndex] = getTableRowAsArray(table, rowIndex);
239
- }
240
- return {
241
- shape: 'array-row-table',
242
- schema: table.schema,
243
- data
244
- };
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
+ };
245
278
  }
279
+ /** Convert any table into object row format */
246
280
  export function makeObjectRowTable(table) {
247
- if (table.shape === 'object-row-table') {
248
- return table;
249
- }
250
- const length = getTableLength(table);
251
- const data = new Array(length);
252
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
253
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
254
- }
255
- return {
256
- shape: 'object-row-table',
257
- schema: table.schema,
258
- data
259
- };
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
+ };
260
294
  }
295
+ /** Convert any table into object row format */
261
296
  export function makeColumnarTable(table) {
262
- if (table.shape === 'object-row-table') {
263
- return table;
264
- }
265
- const length = getTableLength(table);
266
- const data = new Array(length);
267
- for (let rowIndex = 0; rowIndex < length; rowIndex++) {
268
- data[rowIndex] = getTableRowAsObject(table, rowIndex);
269
- }
270
- return {
271
- shape: 'object-row-table',
272
- schema: table.schema,
273
- data
274
- };
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
+ };
275
310
  }
311
+ // Row Iterators
312
+ /**
313
+ * Iterate over table rows
314
+ * @param table
315
+ * @param shape
316
+ */
276
317
  export function* makeRowIterator(table, shape) {
277
- switch (shape) {
278
- case 'array-row-table':
279
- yield* makeArrayRowIterator(table);
280
- break;
281
- case 'object-row-table':
282
- yield* makeObjectRowIterator(table);
283
- break;
284
- default:
285
- throw new Error(`Unknown row type ${shape}`);
286
- }
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
+ }
287
328
  }
288
- export function makeArrayRowIterator(table) {
289
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
290
- return function* () {
329
+ /**
330
+ * Streaming processing: Iterate over table, yielding array rows
331
+ * @param table
332
+ * @param shape
333
+ */
334
+ export function* makeArrayRowIterator(table, target = []) {
291
335
  const length = getTableLength(table);
292
336
  for (let rowIndex = 0; rowIndex < length; rowIndex++) {
293
- yield getTableRowAsArray(table, rowIndex, target);
337
+ yield getTableRowAsArray(table, rowIndex, target);
294
338
  }
295
- }();
296
339
  }
297
- export function makeObjectRowIterator(table) {
298
- let target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
299
- return function* () {
340
+ /**
341
+ * Streaming processing: Iterate over table, yielding object rows
342
+ * @param table
343
+ * @param shape
344
+ */
345
+ export function* makeObjectRowIterator(table, target = {}) {
300
346
  const length = getTableLength(table);
301
347
  for (let rowIndex = 0; rowIndex < length; rowIndex++) {
302
- yield getTableRowAsObject(table, rowIndex, target);
348
+ yield getTableRowAsObject(table, rowIndex, target);
303
349
  }
304
- }();
305
350
  }
306
- //# sourceMappingURL=table-accessors.js.map
@@ -1,4 +1,4 @@
1
- import { Field } from '../../../types/schema';
1
+ import { Field } from "../../../types/schema.js";
2
2
  export interface ArrayType<T = unknown> {
3
3
  readonly length: number;
4
4
  [n: number]: T;
@@ -1 +1 @@
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,MAAM,uBAAuB,CAAC;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
+ {"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"}