@loaders.gl/json 4.0.0-alpha.5 → 4.0.0-alpha.7

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 (193) hide show
  1. package/dist/bundle.js +2 -2
  2. package/dist/dist.min.js +643 -92
  3. package/dist/es5/bundle.js +6 -0
  4. package/dist/es5/bundle.js.map +1 -0
  5. package/dist/es5/geojson-loader.js +157 -0
  6. package/dist/es5/geojson-loader.js.map +1 -0
  7. package/dist/es5/geojson-writer.js +27 -0
  8. package/dist/es5/geojson-writer.js.map +1 -0
  9. package/dist/es5/index.js +69 -0
  10. package/dist/es5/index.js.map +1 -0
  11. package/dist/es5/json-loader.js +67 -0
  12. package/dist/es5/json-loader.js.map +1 -0
  13. package/dist/es5/json-writer.js +42 -0
  14. package/dist/es5/json-writer.js.map +1 -0
  15. package/dist/es5/lib/clarinet/clarinet.js +446 -0
  16. package/dist/es5/lib/clarinet/clarinet.js.map +1 -0
  17. package/dist/es5/lib/encoders/encode-utils.js +42 -0
  18. package/dist/es5/lib/encoders/encode-utils.js.map +1 -0
  19. package/dist/es5/lib/encoders/geojson-encoder.js +178 -0
  20. package/dist/es5/lib/encoders/geojson-encoder.js.map +1 -0
  21. package/dist/es5/lib/encoders/json-encoder.js +30 -0
  22. package/dist/es5/lib/encoders/json-encoder.js.map +1 -0
  23. package/dist/es5/lib/encoders/utf8-encoder.js +54 -0
  24. package/dist/es5/lib/encoders/utf8-encoder.js.map +1 -0
  25. package/dist/es5/lib/json-parser/json-parser.js +140 -0
  26. package/dist/es5/lib/json-parser/json-parser.js.map +1 -0
  27. package/dist/es5/lib/json-parser/streaming-json-parser.js +123 -0
  28. package/dist/es5/lib/json-parser/streaming-json-parser.js.map +1 -0
  29. package/dist/es5/lib/jsonpath/jsonpath.js +119 -0
  30. package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -0
  31. package/dist/es5/lib/parsers/parse-json-in-batches.js +206 -0
  32. package/dist/es5/lib/parsers/parse-json-in-batches.js.map +1 -0
  33. package/dist/es5/lib/parsers/parse-json.js +38 -0
  34. package/dist/es5/lib/parsers/parse-json.js.map +1 -0
  35. package/dist/es5/lib/parsers/parse-ndjson-in-batches.js +114 -0
  36. package/dist/es5/lib/parsers/parse-ndjson-in-batches.js.map +1 -0
  37. package/dist/es5/lib/parsers/parse-ndjson.js +19 -0
  38. package/dist/es5/lib/parsers/parse-ndjson.js.map +1 -0
  39. package/dist/es5/ndgeoson-loader.js +54 -0
  40. package/dist/es5/ndgeoson-loader.js.map +1 -0
  41. package/dist/es5/ndjson-loader.js +44 -0
  42. package/dist/es5/ndjson-loader.js.map +1 -0
  43. package/dist/es5/workers/geojson-worker.js +6 -0
  44. package/dist/es5/workers/geojson-worker.js.map +1 -0
  45. package/dist/esm/bundle.js +4 -0
  46. package/dist/esm/bundle.js.map +1 -0
  47. package/dist/esm/geojson-loader.js +79 -0
  48. package/dist/esm/geojson-loader.js.map +1 -0
  49. package/dist/esm/geojson-writer.js +18 -0
  50. package/dist/esm/geojson-writer.js.map +1 -0
  51. package/dist/esm/index.js +9 -0
  52. package/dist/esm/index.js.map +1 -0
  53. package/dist/esm/json-loader.js +48 -0
  54. package/dist/esm/json-loader.js.map +1 -0
  55. package/dist/esm/json-writer.js +14 -0
  56. package/dist/esm/json-writer.js.map +1 -0
  57. package/dist/esm/lib/clarinet/LICENSE +28 -0
  58. package/dist/esm/lib/clarinet/clarinet.js +415 -0
  59. package/dist/esm/lib/clarinet/clarinet.js.map +1 -0
  60. package/dist/esm/lib/encoders/encode-utils.js +31 -0
  61. package/dist/esm/lib/encoders/encode-utils.js.map +1 -0
  62. package/dist/esm/lib/encoders/geojson-encoder.js +98 -0
  63. package/dist/esm/lib/encoders/geojson-encoder.js.map +1 -0
  64. package/dist/esm/lib/encoders/json-encoder.js +12 -0
  65. package/dist/esm/lib/encoders/json-encoder.js.map +1 -0
  66. package/dist/esm/lib/encoders/utf8-encoder.js +32 -0
  67. package/dist/esm/lib/encoders/utf8-encoder.js.map +1 -0
  68. package/dist/{lib/parser → esm/lib/json-parser}/json-parser.js +4 -22
  69. package/dist/esm/lib/json-parser/json-parser.js.map +1 -0
  70. package/dist/{lib/parser → esm/lib/json-parser}/streaming-json-parser.js +2 -23
  71. package/dist/esm/lib/json-parser/streaming-json-parser.js.map +1 -0
  72. package/dist/esm/lib/jsonpath/jsonpath.js +67 -0
  73. package/dist/esm/lib/jsonpath/jsonpath.js.map +1 -0
  74. package/dist/{lib → esm/lib/parsers}/parse-json-in-batches.js +5 -18
  75. package/dist/esm/lib/parsers/parse-json-in-batches.js.map +1 -0
  76. package/dist/{lib → esm/lib/parsers}/parse-json.js +4 -9
  77. package/dist/esm/lib/parsers/parse-json.js.map +1 -0
  78. package/dist/{lib → esm/lib/parsers}/parse-ndjson-in-batches.js +3 -6
  79. package/dist/esm/lib/parsers/parse-ndjson-in-batches.js.map +1 -0
  80. package/dist/esm/lib/parsers/parse-ndjson.js +13 -0
  81. package/dist/esm/lib/parsers/parse-ndjson.js.map +1 -0
  82. package/dist/esm/ndgeoson-loader.js +27 -0
  83. package/dist/esm/ndgeoson-loader.js.map +1 -0
  84. package/dist/esm/ndjson-loader.js +18 -0
  85. package/dist/esm/ndjson-loader.js.map +1 -0
  86. package/dist/esm/workers/geojson-worker.js +4 -0
  87. package/dist/esm/workers/geojson-worker.js.map +1 -0
  88. package/dist/geojson-loader.d.ts +2 -2
  89. package/dist/geojson-loader.d.ts.map +1 -1
  90. package/dist/geojson-loader.js +65 -69
  91. package/dist/geojson-worker.js +251 -68
  92. package/dist/geojson-writer.d.ts +6 -0
  93. package/dist/geojson-writer.d.ts.map +1 -0
  94. package/dist/geojson-writer.js +22 -0
  95. package/dist/index.d.ts +5 -1
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +24 -7
  98. package/dist/json-loader.d.ts +10 -7
  99. package/dist/json-loader.d.ts.map +1 -1
  100. package/dist/json-loader.js +33 -38
  101. package/dist/json-writer.d.ts +6 -0
  102. package/dist/json-writer.d.ts.map +1 -0
  103. package/dist/json-writer.js +18 -0
  104. package/dist/lib/clarinet/clarinet.d.ts +3 -3
  105. package/dist/lib/clarinet/clarinet.d.ts.map +1 -1
  106. package/dist/lib/clarinet/clarinet.js +510 -493
  107. package/dist/lib/encoders/encode-utils.d.ts +19 -0
  108. package/dist/lib/encoders/encode-utils.d.ts.map +1 -0
  109. package/dist/lib/encoders/encode-utils.js +47 -0
  110. package/dist/lib/encoders/geojson-encoder.d.ts +14 -0
  111. package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -0
  112. package/dist/lib/encoders/geojson-encoder.js +104 -0
  113. package/dist/lib/encoders/json-encoder.d.ts +16 -0
  114. package/dist/lib/encoders/json-encoder.d.ts.map +1 -0
  115. package/dist/lib/encoders/json-encoder.js +22 -0
  116. package/dist/lib/encoders/utf8-encoder.d.ts +12 -0
  117. package/dist/lib/encoders/utf8-encoder.d.ts.map +1 -0
  118. package/dist/lib/encoders/utf8-encoder.js +32 -0
  119. package/dist/lib/json-parser/json-parser.d.ts.map +1 -0
  120. package/dist/lib/json-parser/json-parser.js +98 -0
  121. package/dist/lib/json-parser/streaming-json-parser.d.ts.map +1 -0
  122. package/dist/lib/json-parser/streaming-json-parser.js +100 -0
  123. package/dist/lib/jsonpath/jsonpath.js +81 -78
  124. package/dist/lib/parsers/parse-json-in-batches.d.ts +5 -0
  125. package/dist/lib/parsers/parse-json-in-batches.d.ts.map +1 -0
  126. package/dist/lib/parsers/parse-json-in-batches.js +100 -0
  127. package/dist/lib/parsers/parse-json.d.ts +4 -0
  128. package/dist/lib/parsers/parse-json.d.ts.map +1 -0
  129. package/dist/lib/parsers/parse-json.js +32 -0
  130. package/dist/lib/{parse-ndjson-in-batches.d.ts → parsers/parse-ndjson-in-batches.d.ts} +1 -1
  131. package/dist/lib/parsers/parse-ndjson-in-batches.d.ts.map +1 -0
  132. package/dist/lib/parsers/parse-ndjson-in-batches.js +36 -0
  133. package/dist/lib/parsers/parse-ndjson.d.ts +3 -0
  134. package/dist/lib/parsers/parse-ndjson.d.ts.map +1 -0
  135. package/dist/lib/parsers/parse-ndjson.js +17 -0
  136. package/dist/ndgeoson-loader.d.ts +34 -0
  137. package/dist/ndgeoson-loader.d.ts.map +1 -0
  138. package/dist/ndgeoson-loader.js +37 -0
  139. package/dist/ndjson-loader.d.ts +3 -21
  140. package/dist/ndjson-loader.d.ts.map +1 -1
  141. package/dist/ndjson-loader.js +26 -31
  142. package/dist/workers/geojson-worker.js +5 -4
  143. package/package.json +7 -7
  144. package/src/geojson-loader.ts +10 -6
  145. package/src/geojson-writer.ts +27 -0
  146. package/src/index.ts +9 -1
  147. package/src/json-loader.ts +15 -24
  148. package/src/json-writer.ts +24 -0
  149. package/src/lib/encoders/encode-utils.ts +54 -0
  150. package/src/lib/encoders/geojson-encoder.ts +139 -0
  151. package/src/lib/encoders/json-encoder.ts +30 -0
  152. package/src/lib/encoders/utf8-encoder.ts +35 -0
  153. package/src/lib/{parse-json-in-batches.ts → parsers/parse-json-in-batches.ts} +8 -8
  154. package/src/lib/{parse-json.ts → parsers/parse-json.ts} +7 -3
  155. package/src/lib/{parse-ndjson-in-batches.ts → parsers/parse-ndjson-in-batches.ts} +1 -1
  156. package/src/lib/parsers/parse-ndjson.ts +15 -0
  157. package/src/ndgeoson-loader.ts +48 -0
  158. package/src/ndjson-loader.ts +20 -27
  159. package/dist/bundle.js.map +0 -1
  160. package/dist/geojson-loader.js.map +0 -1
  161. package/dist/index.js.map +0 -1
  162. package/dist/json-loader.js.map +0 -1
  163. package/dist/jsonl-loader.d.ts +0 -1
  164. package/dist/jsonl-loader.d.ts.map +0 -1
  165. package/dist/jsonl-loader.js +0 -2
  166. package/dist/jsonl-loader.js.map +0 -1
  167. package/dist/lib/clarinet/clarinet.js.map +0 -1
  168. package/dist/lib/jsonpath/jsonpath.js.map +0 -1
  169. package/dist/lib/parse-json-in-batches.d.ts +0 -5
  170. package/dist/lib/parse-json-in-batches.d.ts.map +0 -1
  171. package/dist/lib/parse-json-in-batches.js.map +0 -1
  172. package/dist/lib/parse-json.d.ts +0 -3
  173. package/dist/lib/parse-json.d.ts.map +0 -1
  174. package/dist/lib/parse-json.js.map +0 -1
  175. package/dist/lib/parse-ndjson-in-batches.d.ts.map +0 -1
  176. package/dist/lib/parse-ndjson-in-batches.js.map +0 -1
  177. package/dist/lib/parse-ndjson.d.ts +0 -2
  178. package/dist/lib/parse-ndjson.d.ts.map +0 -1
  179. package/dist/lib/parse-ndjson.js +0 -11
  180. package/dist/lib/parse-ndjson.js.map +0 -1
  181. package/dist/lib/parser/json-parser.d.ts.map +0 -1
  182. package/dist/lib/parser/json-parser.js.map +0 -1
  183. package/dist/lib/parser/streaming-json-parser.d.ts.map +0 -1
  184. package/dist/lib/parser/streaming-json-parser.js.map +0 -1
  185. package/dist/ndjson-loader.js.map +0 -1
  186. package/dist/workers/geojson-worker.js.map +0 -1
  187. package/src/jsonl-loader.ts +0 -53
  188. package/src/lib/parse-ndjson.ts +0 -10
  189. /package/dist/{lib → es5/lib}/clarinet/LICENSE +0 -0
  190. /package/dist/lib/{parser → json-parser}/json-parser.d.ts +0 -0
  191. /package/dist/lib/{parser → json-parser}/streaming-json-parser.d.ts +0 -0
  192. /package/src/lib/{parser → json-parser}/json-parser.ts +0 -0
  193. /package/src/lib/{parser → json-parser}/streaming-json-parser.ts +0 -0
@@ -0,0 +1,19 @@
1
+ import { Table } from '@loaders.gl/schema';
2
+ type Row = {
3
+ [key: string]: unknown;
4
+ };
5
+ /**
6
+ * Attempts to identify which column contains geometry
7
+ * Currently just returns name (key) of first object-valued column
8
+ * @todo look for hints in schema metadata
9
+ * @todo look for WKB
10
+ */
11
+ export declare function detectGeometryColumnIndex(table: Table): number;
12
+ /**
13
+ * Return a row as a property (key/value) object, excluding selected columns
14
+ */
15
+ export declare function getRowPropertyObject(table: Table, row: Row, excludeColumnIndices?: number[]): {
16
+ [columnName: string]: unknown;
17
+ };
18
+ export {};
19
+ //# sourceMappingURL=encode-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/encode-utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,EAAsD,MAAM,oBAAoB,CAAC;AAE9F,KAAK,GAAG,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAsB9D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,GAAG,EACR,oBAAoB,GAAE,MAAM,EAAO,GAClC;IAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CASjC"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Copyright 2022 Foursquare Labs, Inc.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.getRowPropertyObject = exports.detectGeometryColumnIndex = void 0;
6
+ const schema_1 = require("@loaders.gl/schema");
7
+ /**
8
+ * Attempts to identify which column contains geometry
9
+ * Currently just returns name (key) of first object-valued column
10
+ * @todo look for hints in schema metadata
11
+ * @todo look for WKB
12
+ */
13
+ function detectGeometryColumnIndex(table) {
14
+ // TODO - look for hints in schema metadata
15
+ // look for a column named geometry
16
+ const geometryIndex = table.schema?.fields.findIndex((field) => field.name === 'geometry') ?? -1;
17
+ if (geometryIndex > -1) {
18
+ return geometryIndex;
19
+ }
20
+ // look at the data
21
+ // TODO - this drags in the indices
22
+ if ((0, schema_1.getTableLength)(table) > 0) {
23
+ const row = (0, schema_1.getTableRowAsArray)(table, 0);
24
+ for (let columnIndex = 0; columnIndex < (0, schema_1.getTableNumCols)(table); columnIndex++) {
25
+ const value = row?.[columnIndex];
26
+ if (value && typeof value === 'object') {
27
+ return columnIndex;
28
+ }
29
+ }
30
+ }
31
+ throw new Error('Failed to detect geometry column');
32
+ }
33
+ exports.detectGeometryColumnIndex = detectGeometryColumnIndex;
34
+ /**
35
+ * Return a row as a property (key/value) object, excluding selected columns
36
+ */
37
+ function getRowPropertyObject(table, row, excludeColumnIndices = []) {
38
+ const properties = {};
39
+ for (let columnIndex = 0; columnIndex < (0, schema_1.getTableNumCols)(table); ++columnIndex) {
40
+ const columnName = table.schema?.fields[columnIndex].name;
41
+ if (columnName && !excludeColumnIndices.includes(columnIndex)) {
42
+ properties[columnName] = row[columnName];
43
+ }
44
+ }
45
+ return properties;
46
+ }
47
+ exports.getRowPropertyObject = getRowPropertyObject;
@@ -0,0 +1,14 @@
1
+ import { TableBatch } from '@loaders.gl/schema';
2
+ export type GeoJSONWriterOptions = {
3
+ geojson?: {
4
+ featureArray?: boolean;
5
+ geometryColumn?: number | null;
6
+ };
7
+ chunkSize?: number;
8
+ };
9
+ /**
10
+ * Encode a table as GeoJSON
11
+ */
12
+ export declare function encodeTableAsGeojsonInBatches(batchIterator: AsyncIterable<TableBatch>, // | Iterable<TableBatch>,
13
+ inputOpts?: GeoJSONWriterOptions): AsyncIterable<ArrayBuffer>;
14
+ //# sourceMappingURL=geojson-encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geojson-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/geojson-encoder.ts"],"names":[],"mappings":"AAIA,OAAO,EAAQ,UAAU,EAAsB,MAAM,oBAAoB,CAAC;AAM1E,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAChC,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;GAEG;AAEH,wBAAuB,6BAA6B,CAClD,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,EAAE,0BAA0B;AACpE,SAAS,GAAE,oBAAyB,GACnC,aAAa,CAAC,WAAW,CAAC,CAqD5B"}
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Copyright 2022 Foursquare Labs, Inc.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.encodeTableAsGeojsonInBatches = void 0;
6
+ const schema_1 = require("@loaders.gl/schema");
7
+ const schema_2 = require("@loaders.gl/schema");
8
+ const encode_utils_1 = require("./encode-utils");
9
+ const utf8_encoder_1 = require("./utf8-encoder");
10
+ /**
11
+ * Encode a table as GeoJSON
12
+ */
13
+ // eslint-disable-next-line max-statements
14
+ async function* encodeTableAsGeojsonInBatches(batchIterator, // | Iterable<TableBatch>,
15
+ inputOpts = {}) {
16
+ const options = { geojson: {}, chunkSize: 10000, ...inputOpts };
17
+ const utf8Encoder = new utf8_encoder_1.Utf8ArrayBufferEncoder(options.chunkSize);
18
+ if (!options.geojson.featureArray) {
19
+ utf8Encoder.push('{\n', '"type": "FeatureCollection",\n', '"features":\n');
20
+ }
21
+ utf8Encoder.push('['); // Note no newline
22
+ let geometryColumn = options.geojson.geometryColumn;
23
+ let isFirstLine = true;
24
+ for await (const batch of batchIterator) {
25
+ const { table, start, end = (0, schema_1.getTableLength)(batch.table) - start } = batch;
26
+ // Deduce geometry column if not already done
27
+ if (!geometryColumn) {
28
+ geometryColumn = geometryColumn || (0, encode_utils_1.detectGeometryColumnIndex)(table);
29
+ }
30
+ for (let rowIndex = start; rowIndex < end; ++rowIndex) {
31
+ // Add a comma except on final feature
32
+ if (!isFirstLine) {
33
+ utf8Encoder.push(',');
34
+ }
35
+ utf8Encoder.push('\n');
36
+ isFirstLine = false;
37
+ encodeRow(table, rowIndex, geometryColumn, utf8Encoder);
38
+ // eslint-disable-next-line max-depth
39
+ if (utf8Encoder.isFull()) {
40
+ yield utf8Encoder.getArrayBufferBatch();
41
+ }
42
+ }
43
+ const arrayBufferBatch = utf8Encoder.getArrayBufferBatch();
44
+ if (arrayBufferBatch.byteLength > 0) {
45
+ yield arrayBufferBatch;
46
+ }
47
+ }
48
+ utf8Encoder.push('\n');
49
+ // Add completing rows and emit final batch
50
+ utf8Encoder.push(']\n');
51
+ if (!options.geojson.featureArray) {
52
+ utf8Encoder.push('}');
53
+ }
54
+ // Note: Since we pushed a few final lines, the last batch will always exist, no need to check first
55
+ yield utf8Encoder.getArrayBufferBatch();
56
+ }
57
+ exports.encodeTableAsGeojsonInBatches = encodeTableAsGeojsonInBatches;
58
+ // Helpers
59
+ /**
60
+ * Encode a row. Currently this ignores properties in the geometry column.
61
+ */
62
+ function encodeRow(table, rowIndex, geometryColumnIndex, utf8Encoder) {
63
+ const row = (0, schema_2.getTableRowAsObject)(table, rowIndex);
64
+ if (!row)
65
+ return;
66
+ const featureWithProperties = getFeatureFromRow(table, row, geometryColumnIndex);
67
+ const featureString = JSON.stringify(featureWithProperties);
68
+ utf8Encoder.push(featureString);
69
+ }
70
+ /**
71
+ * Encode a row as a Feature. Currently this ignores properties objects in the geometry column.
72
+ */
73
+ function getFeatureFromRow(table, row, geometryColumnIndex) {
74
+ // Extract non-feature/geometry properties
75
+ const properties = (0, encode_utils_1.getRowPropertyObject)(table, row, [geometryColumnIndex]);
76
+ // Extract geometry feature
77
+ const columnName = table.schema?.fields[geometryColumnIndex].name;
78
+ let featureOrGeometry = columnName && row[columnName];
79
+ // GeoJSON support null geometries
80
+ if (!featureOrGeometry) {
81
+ // @ts-ignore Feature type does not support null geometries
82
+ return { type: 'Feature', geometry: null, properties };
83
+ }
84
+ // Support string geometries?
85
+ // TODO: This assumes GeoJSON strings, which may not be the correct format
86
+ // (could be WKT, encoded WKB...)
87
+ if (typeof featureOrGeometry === 'string') {
88
+ try {
89
+ featureOrGeometry = JSON.parse(featureOrGeometry);
90
+ }
91
+ catch (err) {
92
+ throw new Error('Invalid string geometry');
93
+ }
94
+ }
95
+ if (typeof featureOrGeometry !== 'object' || typeof featureOrGeometry?.type !== 'string') {
96
+ throw new Error('invalid geometry column value');
97
+ }
98
+ if (featureOrGeometry?.type === 'Feature') {
99
+ // @ts-ignore Feature type does not support null geometries
100
+ return { ...featureOrGeometry, properties };
101
+ }
102
+ // @ts-ignore Feature type does not support null geometries
103
+ return { type: 'Feature', geometry: featureOrGeometry, properties };
104
+ }
@@ -0,0 +1,16 @@
1
+ import { Table } from '@loaders.gl/schema';
2
+ type RowArray = unknown[];
3
+ type RowObject = {
4
+ [key: string]: unknown;
5
+ };
6
+ type TableJSON = RowArray[] | RowObject[];
7
+ export type JSONWriterOptions = {
8
+ shape?: 'object-row-table' | 'array-row-table';
9
+ wrapper?: (table: TableJSON) => unknown;
10
+ };
11
+ /**
12
+ * Encode a table as a JSON string
13
+ */
14
+ export declare function encodeTableAsJSON(table: Table, options?: JSONWriterOptions): string;
15
+ export {};
16
+ //# sourceMappingURL=json-encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/json-encoder.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,KAAK,EAAkB,MAAM,oBAAoB,CAAC;AAE1D,KAAK,QAAQ,GAAG,OAAO,EAAE,CAAC;AAC1B,KAAK,SAAS,GAAG;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,CAAC;AAC1C,KAAK,SAAS,GAAG,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAC;AAE1C,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,CAAC,EAAE,kBAAkB,GAAG,iBAAiB,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,OAAO,CAAC;CACzC,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAYvF"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ // loaders.gl, MIT license
3
+ // Copyright 2022 Foursquare Labs, Inc.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.encodeTableAsJSON = void 0;
6
+ const schema_1 = require("@loaders.gl/schema");
7
+ /**
8
+ * Encode a table as a JSON string
9
+ */
10
+ function encodeTableAsJSON(table, options = {}) {
11
+ const shape = options.shape || 'object-row-table';
12
+ const strings = [];
13
+ const rowIterator = (0, schema_1.makeRowIterator)(table, shape);
14
+ for (const row of rowIterator) {
15
+ // Round elements etc
16
+ // processRow(wrappedRow, table.schema);
17
+ // const wrappedRow = options.wrapper ? options.wrapper(row) : row;
18
+ strings.push(JSON.stringify(row));
19
+ }
20
+ return `[${strings.join(',')}]`;
21
+ }
22
+ exports.encodeTableAsJSON = encodeTableAsJSON;
@@ -0,0 +1,12 @@
1
+ export declare class Utf8ArrayBufferEncoder {
2
+ private readonly chunkSize;
3
+ private strings;
4
+ private totalLength;
5
+ private textEncoder;
6
+ constructor(chunkSize: number);
7
+ push(...strings: string[]): void;
8
+ isFull(): boolean;
9
+ getArrayBufferBatch(): ArrayBufferLike;
10
+ getStringBatch(): string;
11
+ }
12
+ //# sourceMappingURL=utf8-encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utf8-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/utf8-encoder.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,WAAW,CAAkC;gBAEzC,SAAS,EAAE,MAAM;IAI7B,IAAI,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAOhC,MAAM,IAAI,OAAO;IAIjB,mBAAmB,IAAI,eAAe;IAItC,cAAc,IAAI,MAAM;CAMzB"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // loaders.gl, MIT License
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Utf8ArrayBufferEncoder = void 0;
5
+ /* global TextEncoder */
6
+ class Utf8ArrayBufferEncoder {
7
+ constructor(chunkSize) {
8
+ this.strings = [];
9
+ this.totalLength = 0;
10
+ this.textEncoder = new TextEncoder();
11
+ this.chunkSize = chunkSize;
12
+ }
13
+ push(...strings) {
14
+ for (const string of strings) {
15
+ this.strings.push(string);
16
+ this.totalLength += string.length;
17
+ }
18
+ }
19
+ isFull() {
20
+ return this.totalLength >= this.chunkSize;
21
+ }
22
+ getArrayBufferBatch() {
23
+ return this.textEncoder.encode(this.getStringBatch()).buffer;
24
+ }
25
+ getStringBatch() {
26
+ const stringChunk = this.strings.join('');
27
+ this.strings = [];
28
+ this.totalLength = 0;
29
+ return stringChunk;
30
+ }
31
+ }
32
+ exports.Utf8ArrayBufferEncoder = Utf8ArrayBufferEncoder;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"json-parser.d.ts","sourceRoot":"","sources":["../../../src/lib/json-parser/json-parser.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,EAAE,EAAC,qBAAqB,EAAC,MAAM,sBAAsB,CAAC;AAC3E,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAI5C,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,MAAM,YAAa;IACnB,cAAc,UAAM;IACpB,YAAY;;;OAA6C;IACzD,QAAQ,EAAE,QAAQ,CAAkB;gBAExB,OAAO,EAAE,qBAAqB;IAiD1C,KAAK,IAAI,IAAI;IAOb,KAAK,CAAC,KAAK,KAAA,GAAG,IAAI;IAIlB,KAAK,IAAI,IAAI;IAMb,UAAU,CAAC,KAAK,KAAA,GAAG,IAAI;IAUvB,UAAU,CAAC,YAAY,UAAK,GAAG,IAAI;IAOnC,WAAW,IAAI,IAAI;IAKnB,WAAW,CAAC,YAAY,KAAK,GAAG,IAAI;IAOpC,YAAY,IAAI,IAAI;CAIrB"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ // @ts-nocheck
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const clarinet_1 = __importDefault(require("../clarinet/clarinet"));
8
+ const jsonpath_1 = __importDefault(require("../jsonpath/jsonpath"));
9
+ // JSONParser builds a JSON object using the events emitted by the Clarinet parser
10
+ class JSONParser {
11
+ constructor(options) {
12
+ this.result = undefined;
13
+ this.previousStates = [];
14
+ this.currentState = Object.freeze({ container: [], key: null });
15
+ this.jsonpath = new jsonpath_1.default();
16
+ this.reset();
17
+ this.parser = new clarinet_1.default({
18
+ onready: () => {
19
+ this.jsonpath = new jsonpath_1.default();
20
+ this.previousStates.length = 0;
21
+ this.currentState.container.length = 0;
22
+ },
23
+ onopenobject: (name) => {
24
+ this._openObject({});
25
+ if (typeof name !== 'undefined') {
26
+ this.parser.emit('onkey', name);
27
+ }
28
+ },
29
+ onkey: (name) => {
30
+ this.jsonpath.set(name);
31
+ this.currentState.key = name;
32
+ },
33
+ oncloseobject: () => {
34
+ this._closeObject();
35
+ },
36
+ onopenarray: () => {
37
+ this._openArray();
38
+ },
39
+ onclosearray: () => {
40
+ this._closeArray();
41
+ },
42
+ onvalue: (value) => {
43
+ this._pushOrSet(value);
44
+ },
45
+ onerror: (error) => {
46
+ throw error;
47
+ },
48
+ onend: () => {
49
+ this.result = this.currentState.container.pop();
50
+ },
51
+ ...options
52
+ });
53
+ }
54
+ reset() {
55
+ this.result = undefined;
56
+ this.previousStates = [];
57
+ this.currentState = Object.freeze({ container: [], key: null });
58
+ this.jsonpath = new jsonpath_1.default();
59
+ }
60
+ write(chunk) {
61
+ this.parser.write(chunk);
62
+ }
63
+ close() {
64
+ this.parser.close();
65
+ }
66
+ // PRIVATE METHODS
67
+ _pushOrSet(value) {
68
+ const { container, key } = this.currentState;
69
+ if (key !== null) {
70
+ container[key] = value;
71
+ this.currentState.key = null;
72
+ }
73
+ else {
74
+ container.push(value);
75
+ }
76
+ }
77
+ _openArray(newContainer = []) {
78
+ this.jsonpath.push(null);
79
+ this._pushOrSet(newContainer);
80
+ this.previousStates.push(this.currentState);
81
+ this.currentState = { container: newContainer, isArray: true, key: null };
82
+ }
83
+ _closeArray() {
84
+ this.jsonpath.pop();
85
+ this.currentState = this.previousStates.pop();
86
+ }
87
+ _openObject(newContainer = {}) {
88
+ this.jsonpath.push(null);
89
+ this._pushOrSet(newContainer);
90
+ this.previousStates.push(this.currentState);
91
+ this.currentState = { container: newContainer, isArray: false, key: null };
92
+ }
93
+ _closeObject() {
94
+ this.jsonpath.pop();
95
+ this.currentState = this.previousStates.pop();
96
+ }
97
+ }
98
+ exports.default = JSONParser;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streaming-json-parser.d.ts","sourceRoot":"","sources":["../../../src/lib/json-parser/streaming-json-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,eAAe,CAAC;AACpD,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAU;IACzD,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,iBAAiB,CAAyB;IAClD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,cAAc,CAAuB;gBAEjC,OAAO,GAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAM;IAiC9C;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,KAAA;IAUX;;;;OAIG;IACH,gBAAgB;IAIhB,oBAAoB;IAIpB,4BAA4B;IAI5B,WAAW;IAMX;;OAEG;IACH,cAAc;CAkBf"}
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const json_parser_1 = __importDefault(require("./json-parser"));
7
+ const jsonpath_1 = __importDefault(require("../jsonpath/jsonpath"));
8
+ /**
9
+ * The `StreamingJSONParser` looks for the first array in the JSON structure.
10
+ * and emits an array of chunks
11
+ */
12
+ class StreamingJSONParser extends json_parser_1.default {
13
+ constructor(options = {}) {
14
+ super({
15
+ onopenarray: () => {
16
+ if (!this.streamingArray) {
17
+ if (this._matchJSONPath()) {
18
+ // @ts-ignore
19
+ this.streamingJsonPath = this.getJsonPath().clone();
20
+ this.streamingArray = [];
21
+ this._openArray(this.streamingArray);
22
+ return;
23
+ }
24
+ }
25
+ this._openArray();
26
+ },
27
+ // Redefine onopenarray to inject value for top-level object
28
+ onopenobject: (name) => {
29
+ if (!this.topLevelObject) {
30
+ this.topLevelObject = {};
31
+ this._openObject(this.topLevelObject);
32
+ }
33
+ else {
34
+ this._openObject({});
35
+ }
36
+ if (typeof name !== 'undefined') {
37
+ this.parser.emit('onkey', name);
38
+ }
39
+ }
40
+ });
41
+ this.streamingJsonPath = null;
42
+ this.streamingArray = null;
43
+ this.topLevelObject = null;
44
+ const jsonpaths = options.jsonpaths || [];
45
+ this.jsonPaths = jsonpaths.map((jsonpath) => new jsonpath_1.default(jsonpath));
46
+ }
47
+ /**
48
+ * write REDEFINITION
49
+ * - super.write() chunk to parser
50
+ * - get the contents (so far) of "topmost-level" array as batch of rows
51
+ * - clear top-level array
52
+ * - return the batch of rows\
53
+ */
54
+ write(chunk) {
55
+ super.write(chunk);
56
+ let array = [];
57
+ if (this.streamingArray) {
58
+ array = [...this.streamingArray];
59
+ this.streamingArray.length = 0;
60
+ }
61
+ return array;
62
+ }
63
+ /**
64
+ * Returns a partially formed result object
65
+ * Useful for returning the "wrapper" object when array is not top level
66
+ * e.g. GeoJSON
67
+ */
68
+ getPartialResult() {
69
+ return this.topLevelObject;
70
+ }
71
+ getStreamingJsonPath() {
72
+ return this.streamingJsonPath;
73
+ }
74
+ getStreamingJsonPathAsString() {
75
+ return this.streamingJsonPath && this.streamingJsonPath.toString();
76
+ }
77
+ getJsonPath() {
78
+ return this.jsonpath;
79
+ }
80
+ // PRIVATE METHODS
81
+ /**
82
+ * Checks is this.getJsonPath matches the jsonpaths provided in options
83
+ */
84
+ _matchJSONPath() {
85
+ const currentPath = this.getJsonPath();
86
+ // console.debug(`Testing JSONPath`, currentPath);
87
+ // Backwards compatibility, match any array
88
+ // TODO implement using wildcard once that is supported
89
+ if (this.jsonPaths.length === 0) {
90
+ return true;
91
+ }
92
+ for (const jsonPath of this.jsonPaths) {
93
+ if (jsonPath.equals(currentPath)) {
94
+ return true;
95
+ }
96
+ }
97
+ return false;
98
+ }
99
+ }
100
+ exports.default = StreamingJSONParser;
@@ -1,86 +1,89 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- export default class JSONPath {
3
- constructor(path = null) {
4
- _defineProperty(this, "path", void 0);
5
-
6
- this.path = ['$'];
7
-
8
- if (path instanceof JSONPath) {
9
- this.path = [...path.path];
10
- return;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * A parser for a minimal subset of the jsonpath standard
5
+ * Full JSON path parsers for JS exist but are quite large (bundle size)
6
+ *
7
+ * Supports
8
+ *
9
+ * `$.component.component.component`
10
+ */
11
+ class JSONPath {
12
+ constructor(path = null) {
13
+ this.path = ['$'];
14
+ if (path instanceof JSONPath) {
15
+ // @ts-ignore
16
+ this.path = [...path.path];
17
+ return;
18
+ }
19
+ if (Array.isArray(path)) {
20
+ this.path.push(...path);
21
+ return;
22
+ }
23
+ // Parse a string as a JSONPath
24
+ if (typeof path === 'string') {
25
+ this.path = path.split('.');
26
+ if (this.path[0] !== '$') {
27
+ throw new Error('JSONPaths must start with $');
28
+ }
29
+ }
11
30
  }
12
-
13
- if (Array.isArray(path)) {
14
- this.path.push(...path);
15
- return;
31
+ clone() {
32
+ return new JSONPath(this);
16
33
  }
17
-
18
- if (typeof path === 'string') {
19
- this.path = path.split('.');
20
-
21
- if (this.path[0] !== '$') {
22
- throw new Error('JSONPaths must start with $');
23
- }
34
+ toString() {
35
+ return this.path.join('.');
24
36
  }
25
- }
26
-
27
- clone() {
28
- return new JSONPath(this);
29
- }
30
-
31
- toString() {
32
- return this.path.join('.');
33
- }
34
-
35
- push(name) {
36
- this.path.push(name);
37
- }
38
-
39
- pop() {
40
- return this.path.pop();
41
- }
42
-
43
- set(name) {
44
- this.path[this.path.length - 1] = name;
45
- }
46
-
47
- equals(other) {
48
- if (!this || !other || this.path.length !== other.path.length) {
49
- return false;
37
+ push(name) {
38
+ this.path.push(name);
50
39
  }
51
-
52
- for (let i = 0; i < this.path.length; ++i) {
53
- if (this.path[i] !== other.path[i]) {
54
- return false;
55
- }
40
+ pop() {
41
+ return this.path.pop();
56
42
  }
57
-
58
- return true;
59
- }
60
-
61
- setFieldAtPath(object, value) {
62
- const path = [...this.path];
63
- path.shift();
64
- const field = path.pop();
65
-
66
- for (const component of path) {
67
- object = object[component];
43
+ set(name) {
44
+ this.path[this.path.length - 1] = name;
68
45
  }
69
-
70
- object[field] = value;
71
- }
72
-
73
- getFieldAtPath(object) {
74
- const path = [...this.path];
75
- path.shift();
76
- const field = path.pop();
77
-
78
- for (const component of path) {
79
- object = object[component];
46
+ equals(other) {
47
+ if (!this || !other || this.path.length !== other.path.length) {
48
+ return false;
49
+ }
50
+ for (let i = 0; i < this.path.length; ++i) {
51
+ if (this.path[i] !== other.path[i]) {
52
+ return false;
53
+ }
54
+ }
55
+ return true;
56
+ }
57
+ /**
58
+ * Sets the value pointed at by path
59
+ * TODO - handle root path
60
+ * @param object
61
+ * @param value
62
+ */
63
+ setFieldAtPath(object, value) {
64
+ const path = [...this.path];
65
+ path.shift();
66
+ const field = path.pop();
67
+ for (const component of path) {
68
+ object = object[component];
69
+ }
70
+ // @ts-ignore
71
+ object[field] = value;
72
+ }
73
+ /**
74
+ * Gets the value pointed at by path
75
+ * TODO - handle root path
76
+ * @param object
77
+ */
78
+ getFieldAtPath(object) {
79
+ const path = [...this.path];
80
+ path.shift();
81
+ const field = path.pop();
82
+ for (const component of path) {
83
+ object = object[component];
84
+ }
85
+ // @ts-ignore
86
+ return object[field];
80
87
  }
81
-
82
- return object[field];
83
- }
84
-
85
88
  }
86
- //# sourceMappingURL=jsonpath.js.map
89
+ exports.default = JSONPath;
@@ -0,0 +1,5 @@
1
+ import type { TableBatch } from '@loaders.gl/schema';
2
+ import type { JSONLoaderOptions } from '../../json-loader';
3
+ export declare function parseJSONInBatches(binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options: JSONLoaderOptions): AsyncIterable<TableBatch>;
4
+ export declare function rebuildJsonObject(batch: any, data: any): any;
5
+ //# sourceMappingURL=parse-json-in-batches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-json-in-batches.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-json-in-batches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAQzD,wBAAuB,kBAAkB,CACvC,mBAAmB,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACvE,OAAO,EAAE,iBAAiB,GACzB,aAAa,CAAC,UAAU,CAAC,CA+E3B;AAED,wBAAgB,iBAAiB,CAAC,KAAK,KAAA,EAAE,IAAI,KAAA,OAmB5C"}