@loaders.gl/json 4.2.0-alpha.4 → 4.2.0-alpha.5

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 (66) hide show
  1. package/dist/dist.dev.js +341 -409
  2. package/dist/dist.min.js +21 -0
  3. package/dist/geojson-loader.d.ts +1 -1
  4. package/dist/geojson-loader.d.ts.map +1 -1
  5. package/dist/geojson-loader.js +74 -72
  6. package/dist/geojson-writer.js +23 -20
  7. package/dist/index.cjs +120 -94
  8. package/dist/index.cjs.map +7 -0
  9. package/dist/index.d.ts +12 -12
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +3 -1
  12. package/dist/json-loader.js +29 -36
  13. package/dist/json-writer.js +14 -11
  14. package/dist/lib/clarinet/clarinet.js +511 -391
  15. package/dist/lib/encoder-utils/encode-table-row.d.ts +1 -1
  16. package/dist/lib/encoder-utils/encode-table-row.d.ts.map +1 -1
  17. package/dist/lib/encoder-utils/encode-table-row.js +46 -37
  18. package/dist/lib/encoder-utils/encode-utils.js +38 -25
  19. package/dist/lib/encoder-utils/utf8-encoder.js +25 -27
  20. package/dist/lib/encoders/geojson-encoder.d.ts +1 -1
  21. package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -1
  22. package/dist/lib/encoders/geojson-encoder.js +43 -40
  23. package/dist/lib/encoders/json-encoder.d.ts +1 -1
  24. package/dist/lib/encoders/json-encoder.d.ts.map +1 -1
  25. package/dist/lib/encoders/json-encoder.js +17 -9
  26. package/dist/lib/json-parser/json-parser.d.ts +2 -2
  27. package/dist/lib/json-parser/json-parser.d.ts.map +1 -1
  28. package/dist/lib/json-parser/json-parser.js +85 -102
  29. package/dist/lib/json-parser/streaming-json-parser.d.ts +2 -2
  30. package/dist/lib/json-parser/streaming-json-parser.d.ts.map +1 -1
  31. package/dist/lib/json-parser/streaming-json-parser.js +86 -63
  32. package/dist/lib/jsonpath/jsonpath.js +77 -57
  33. package/dist/lib/parsers/parse-json-in-batches.d.ts +1 -1
  34. package/dist/lib/parsers/parse-json-in-batches.d.ts.map +1 -1
  35. package/dist/lib/parsers/parse-json-in-batches.js +76 -75
  36. package/dist/lib/parsers/parse-json.d.ts +1 -1
  37. package/dist/lib/parsers/parse-json.d.ts.map +1 -1
  38. package/dist/lib/parsers/parse-json.js +21 -22
  39. package/dist/lib/parsers/parse-ndjson-in-batches.js +26 -28
  40. package/dist/lib/parsers/parse-ndjson.js +10 -10
  41. package/dist/ndgeoson-loader.js +27 -19
  42. package/dist/ndjson-loader.js +21 -13
  43. package/dist/workers/geojson-worker.js +0 -1
  44. package/package.json +11 -7
  45. package/dist/geojson-loader.js.map +0 -1
  46. package/dist/geojson-writer.js.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/json-loader.js.map +0 -1
  49. package/dist/json-writer.js.map +0 -1
  50. package/dist/lib/clarinet/LICENSE +0 -28
  51. package/dist/lib/clarinet/clarinet.js.map +0 -1
  52. package/dist/lib/encoder-utils/encode-table-row.js.map +0 -1
  53. package/dist/lib/encoder-utils/encode-utils.js.map +0 -1
  54. package/dist/lib/encoder-utils/utf8-encoder.js.map +0 -1
  55. package/dist/lib/encoders/geojson-encoder.js.map +0 -1
  56. package/dist/lib/encoders/json-encoder.js.map +0 -1
  57. package/dist/lib/json-parser/json-parser.js.map +0 -1
  58. package/dist/lib/json-parser/streaming-json-parser.js.map +0 -1
  59. package/dist/lib/jsonpath/jsonpath.js.map +0 -1
  60. package/dist/lib/parsers/parse-json-in-batches.js.map +0 -1
  61. package/dist/lib/parsers/parse-json.js.map +0 -1
  62. package/dist/lib/parsers/parse-ndjson-in-batches.js.map +0 -1
  63. package/dist/lib/parsers/parse-ndjson.js.map +0 -1
  64. package/dist/ndgeoson-loader.js.map +0 -1
  65. package/dist/ndjson-loader.js.map +0 -1
  66. package/dist/workers/geojson-worker.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { Table } from '@loaders.gl/schema';
2
- import { Utf8ArrayBufferEncoder } from './utf8-encoder';
2
+ import { Utf8ArrayBufferEncoder } from "./utf8-encoder.js";
3
3
  /**
4
4
  * Encode a row. Currently this ignores properties in the geometry column.
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"encode-table-row.d.ts","sourceRoot":"","sources":["../../../src/lib/encoder-utils/encode-table-row.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAC,sBAAsB,EAAC,MAAM,gBAAgB,CAAC;AAMtD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,WAAW,EAAE,sBAAsB,GAClC,IAAI,CAMN"}
1
+ {"version":3,"file":"encode-table-row.d.ts","sourceRoot":"","sources":["../../../src/lib/encoder-utils/encode-table-row.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,KAAK,EAAsB,MAAM,oBAAoB,CAAC;AAE9D,OAAO,EAAC,sBAAsB,EAAC,0BAAuB;AAMtD;;GAEG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,WAAW,EAAE,sBAAsB,GAClC,IAAI,CAMN"}
@@ -1,44 +1,53 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Copyright 2022 Foursquare Labs, Inc.
1
5
  import { getTableRowAsObject } from '@loaders.gl/schema';
2
6
  import { getRowPropertyObject } from "./encode-utils.js";
7
+ // Helpers
8
+ /**
9
+ * Encode a row. Currently this ignores properties in the geometry column.
10
+ */
3
11
  export function encodeTableRow(table, rowIndex, geometryColumnIndex, utf8Encoder) {
4
- const row = getTableRowAsObject(table, rowIndex);
5
- if (!row) return;
6
- const featureWithProperties = getFeatureFromRow(table, row, geometryColumnIndex);
7
- const featureString = JSON.stringify(featureWithProperties);
8
- utf8Encoder.push(featureString);
12
+ const row = getTableRowAsObject(table, rowIndex);
13
+ if (!row)
14
+ return;
15
+ const featureWithProperties = getFeatureFromRow(table, row, geometryColumnIndex);
16
+ const featureString = JSON.stringify(featureWithProperties);
17
+ utf8Encoder.push(featureString);
9
18
  }
19
+ /**
20
+ * Encode a row as a Feature. Currently this ignores properties objects in the geometry column.
21
+ */
10
22
  function getFeatureFromRow(table, row, geometryColumnIndex) {
11
- var _table$schema, _featureOrGeometry, _featureOrGeometry2;
12
- const properties = getRowPropertyObject(table, row, [geometryColumnIndex]);
13
- const columnName = (_table$schema = table.schema) === null || _table$schema === void 0 ? void 0 : _table$schema.fields[geometryColumnIndex].name;
14
- let featureOrGeometry = columnName && row[columnName];
15
- if (!featureOrGeometry) {
16
- return {
17
- type: 'Feature',
18
- geometry: null,
19
- properties
20
- };
21
- }
22
- if (typeof featureOrGeometry === 'string') {
23
- try {
24
- featureOrGeometry = JSON.parse(featureOrGeometry);
25
- } catch (err) {
26
- throw new Error('Invalid string geometry');
23
+ // Extract non-feature/geometry properties
24
+ const properties = getRowPropertyObject(table, row, [geometryColumnIndex]);
25
+ // Extract geometry feature
26
+ const columnName = table.schema?.fields[geometryColumnIndex].name;
27
+ let featureOrGeometry = columnName && row[columnName];
28
+ // GeoJSON support null geometries
29
+ if (!featureOrGeometry) {
30
+ // @ts-ignore Feature type does not support null geometries
31
+ return { type: 'Feature', geometry: null, properties };
27
32
  }
28
- }
29
- if (typeof featureOrGeometry !== 'object' || typeof ((_featureOrGeometry = featureOrGeometry) === null || _featureOrGeometry === void 0 ? void 0 : _featureOrGeometry.type) !== 'string') {
30
- throw new Error('invalid geometry column value');
31
- }
32
- if (((_featureOrGeometry2 = featureOrGeometry) === null || _featureOrGeometry2 === void 0 ? void 0 : _featureOrGeometry2.type) === 'Feature') {
33
- return {
34
- ...featureOrGeometry,
35
- properties
36
- };
37
- }
38
- return {
39
- type: 'Feature',
40
- geometry: featureOrGeometry,
41
- properties
42
- };
33
+ // Support string geometries?
34
+ // TODO: This assumes GeoJSON strings, which may not be the correct format
35
+ // (could be WKT, encoded WKB...)
36
+ if (typeof featureOrGeometry === 'string') {
37
+ try {
38
+ featureOrGeometry = JSON.parse(featureOrGeometry);
39
+ }
40
+ catch (err) {
41
+ throw new Error('Invalid string geometry');
42
+ }
43
+ }
44
+ if (typeof featureOrGeometry !== 'object' || typeof featureOrGeometry?.type !== 'string') {
45
+ throw new Error('invalid geometry column value');
46
+ }
47
+ if (featureOrGeometry?.type === 'Feature') {
48
+ // @ts-ignore Feature type does not support null geometries
49
+ return { ...featureOrGeometry, properties };
50
+ }
51
+ // @ts-ignore Feature type does not support null geometries
52
+ return { type: 'Feature', geometry: featureOrGeometry, properties };
43
53
  }
44
- //# sourceMappingURL=encode-table-row.js.map
@@ -1,31 +1,44 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Copyright 2022 Foursquare Labs, Inc.
1
5
  import { getTableLength, getTableNumCols, getTableRowAsArray } from '@loaders.gl/schema';
6
+ /**
7
+ * Attempts to identify which column contains geometry
8
+ * Currently just returns name (key) of first object-valued column
9
+ * @todo look for hints in schema metadata
10
+ * @todo look for WKB
11
+ */
2
12
  export function detectGeometryColumnIndex(table) {
3
- var _table$schema$fields$, _table$schema;
4
- const geometryIndex = (_table$schema$fields$ = (_table$schema = table.schema) === null || _table$schema === void 0 ? void 0 : _table$schema.fields.findIndex(field => field.name === 'geometry')) !== null && _table$schema$fields$ !== void 0 ? _table$schema$fields$ : -1;
5
- if (geometryIndex > -1) {
6
- return geometryIndex;
7
- }
8
- if (getTableLength(table) > 0) {
9
- const row = getTableRowAsArray(table, 0);
10
- for (let columnIndex = 0; columnIndex < getTableNumCols(table); columnIndex++) {
11
- const value = row === null || row === void 0 ? void 0 : row[columnIndex];
12
- if (value && typeof value === 'object') {
13
- return columnIndex;
14
- }
13
+ // TODO - look for hints in schema metadata
14
+ // look for a column named geometry
15
+ const geometryIndex = table.schema?.fields.findIndex((field) => field.name === 'geometry') ?? -1;
16
+ if (geometryIndex > -1) {
17
+ return geometryIndex;
15
18
  }
16
- }
17
- throw new Error('Failed to detect geometry column');
19
+ // look at the data
20
+ // TODO - this drags in the indices
21
+ if (getTableLength(table) > 0) {
22
+ const row = getTableRowAsArray(table, 0);
23
+ for (let columnIndex = 0; columnIndex < getTableNumCols(table); columnIndex++) {
24
+ const value = row?.[columnIndex];
25
+ if (value && typeof value === 'object') {
26
+ return columnIndex;
27
+ }
28
+ }
29
+ }
30
+ throw new Error('Failed to detect geometry column');
18
31
  }
19
- export function getRowPropertyObject(table, row) {
20
- let excludeColumnIndices = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
21
- const properties = {};
22
- for (let columnIndex = 0; columnIndex < getTableNumCols(table); ++columnIndex) {
23
- var _table$schema2;
24
- const columnName = (_table$schema2 = table.schema) === null || _table$schema2 === void 0 ? void 0 : _table$schema2.fields[columnIndex].name;
25
- if (columnName && !excludeColumnIndices.includes(columnIndex)) {
26
- properties[columnName] = row[columnName];
32
+ /**
33
+ * Return a row as a property (key/value) object, excluding selected columns
34
+ */
35
+ export function getRowPropertyObject(table, row, excludeColumnIndices = []) {
36
+ const properties = {};
37
+ for (let columnIndex = 0; columnIndex < getTableNumCols(table); ++columnIndex) {
38
+ const columnName = table.schema?.fields[columnIndex].name;
39
+ if (columnName && !excludeColumnIndices.includes(columnIndex)) {
40
+ properties[columnName] = row[columnName];
41
+ }
27
42
  }
28
- }
29
- return properties;
43
+ return properties;
30
44
  }
31
- //# sourceMappingURL=encode-utils.js.map
@@ -1,31 +1,29 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ /* global TextEncoder */
1
4
  export class Utf8ArrayBufferEncoder {
2
- constructor(chunkSize) {
3
- this.chunkSize = void 0;
4
- this.strings = [];
5
- this.totalLength = 0;
6
- this.textEncoder = new TextEncoder();
7
- this.chunkSize = chunkSize;
8
- }
9
- push() {
10
- for (var _len = arguments.length, strings = new Array(_len), _key = 0; _key < _len; _key++) {
11
- strings[_key] = arguments[_key];
5
+ constructor(chunkSize) {
6
+ this.strings = [];
7
+ this.totalLength = 0;
8
+ this.textEncoder = new TextEncoder();
9
+ this.chunkSize = chunkSize;
12
10
  }
13
- for (const string of strings) {
14
- this.strings.push(string);
15
- this.totalLength += string.length;
11
+ push(...strings) {
12
+ for (const string of strings) {
13
+ this.strings.push(string);
14
+ this.totalLength += string.length;
15
+ }
16
+ }
17
+ isFull() {
18
+ return this.totalLength >= this.chunkSize;
19
+ }
20
+ getArrayBufferBatch() {
21
+ return this.textEncoder.encode(this.getStringBatch()).buffer;
22
+ }
23
+ getStringBatch() {
24
+ const stringChunk = this.strings.join('');
25
+ this.strings = [];
26
+ this.totalLength = 0;
27
+ return stringChunk;
16
28
  }
17
- }
18
- isFull() {
19
- return this.totalLength >= this.chunkSize;
20
- }
21
- getArrayBufferBatch() {
22
- return this.textEncoder.encode(this.getStringBatch()).buffer;
23
- }
24
- getStringBatch() {
25
- const stringChunk = this.strings.join('');
26
- this.strings = [];
27
- this.totalLength = 0;
28
- return stringChunk;
29
- }
30
29
  }
31
- //# sourceMappingURL=utf8-encoder.js.map
@@ -1,5 +1,5 @@
1
1
  import type { TableBatch } from '@loaders.gl/schema';
2
- import type { GeoJSONWriterOptions } from '../../geojson-writer';
2
+ import type { GeoJSONWriterOptions } from "../../geojson-writer.js";
3
3
  /**
4
4
  * Encode a table as GeoJSON
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"geojson-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/geojson-encoder.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAKnD,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,sBAAsB,CAAC;AAE/D;;GAEG;AAEH,wBAAuB,6BAA6B,CAClD,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,EAAE,0BAA0B;AAC3F,SAAS,GAAE,oBAAyB,GACnC,aAAa,CAAC,WAAW,CAAC,CA0D5B"}
1
+ {"version":3,"file":"geojson-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/geojson-encoder.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAKnD,OAAO,KAAK,EAAC,oBAAoB,EAAC,gCAA6B;AAE/D;;GAEG;AAEH,wBAAuB,6BAA6B,CAClD,aAAa,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,EAAE,0BAA0B;AAC3F,SAAS,GAAE,oBAAyB,GACnC,aAAa,CAAC,WAAW,CAAC,CA0D5B"}
@@ -1,55 +1,58 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Copyright 2022 Foursquare Labs, Inc.
1
5
  import { getTableLength } from '@loaders.gl/schema';
2
6
  import { detectGeometryColumnIndex } from "../encoder-utils/encode-utils.js";
3
7
  import { encodeTableRow } from "../encoder-utils/encode-table-row.js";
4
8
  import { Utf8ArrayBufferEncoder } from "../encoder-utils/utf8-encoder.js";
5
- export function encodeTableAsGeojsonInBatches(batchIterator) {
6
- try {
7
- let inputOpts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
8
- return async function* () {
9
- const options = {
10
- geojson: {},
11
- chunkSize: 10000,
12
- ...inputOpts
13
- };
14
- const utf8Encoder = new Utf8ArrayBufferEncoder(options.chunkSize);
15
- if (!options.geojson.featureArray) {
9
+ /**
10
+ * Encode a table as GeoJSON
11
+ */
12
+ // eslint-disable-next-line max-statements
13
+ export async function* encodeTableAsGeojsonInBatches(batchIterator, // | Iterable<TableBatch>,
14
+ inputOpts = {}) {
15
+ // @ts-expect-error
16
+ const options = { geojson: {}, chunkSize: 10000, ...inputOpts };
17
+ const utf8Encoder = new Utf8ArrayBufferEncoder(options.chunkSize);
18
+ if (!options.geojson.featureArray) {
16
19
  utf8Encoder.push('{\n', '"type": "FeatureCollection",\n', '"features":\n');
17
- }
18
- utf8Encoder.push('[');
19
- let geometryColumn = options.geojson.geometryColumn;
20
- let isFirstLine = true;
21
- let start = 0;
22
- for await (const tableBatch of batchIterator) {
20
+ }
21
+ utf8Encoder.push('['); // Note no newline
22
+ let geometryColumn = options.geojson.geometryColumn;
23
+ let isFirstLine = true;
24
+ let start = 0;
25
+ for await (const tableBatch of batchIterator) {
23
26
  const end = start + getTableLength(tableBatch);
27
+ // Deduce geometry column if not already done
24
28
  if (!geometryColumn) {
25
- geometryColumn = geometryColumn || detectGeometryColumnIndex(tableBatch);
29
+ geometryColumn = geometryColumn || detectGeometryColumnIndex(tableBatch);
26
30
  }
27
31
  for (let rowIndex = start; rowIndex < end; ++rowIndex) {
28
- if (!isFirstLine) {
29
- utf8Encoder.push(',');
30
- }
31
- utf8Encoder.push('\n');
32
- isFirstLine = false;
33
- encodeTableRow(tableBatch, rowIndex, geometryColumn, utf8Encoder);
34
- if (utf8Encoder.isFull()) {
35
- yield utf8Encoder.getArrayBufferBatch();
36
- }
37
- start = end;
32
+ // Add a comma except on final feature
33
+ if (!isFirstLine) {
34
+ utf8Encoder.push(',');
35
+ }
36
+ utf8Encoder.push('\n');
37
+ isFirstLine = false;
38
+ encodeTableRow(tableBatch, rowIndex, geometryColumn, utf8Encoder);
39
+ // eslint-disable-next-line max-depth
40
+ if (utf8Encoder.isFull()) {
41
+ yield utf8Encoder.getArrayBufferBatch();
42
+ }
43
+ start = end;
38
44
  }
39
45
  const arrayBufferBatch = utf8Encoder.getArrayBufferBatch();
40
46
  if (arrayBufferBatch.byteLength > 0) {
41
- yield arrayBufferBatch;
47
+ yield arrayBufferBatch;
42
48
  }
43
- }
44
- utf8Encoder.push('\n');
45
- utf8Encoder.push(']\n');
46
- if (!options.geojson.featureArray) {
49
+ }
50
+ utf8Encoder.push('\n');
51
+ // Add completing rows and emit final batch
52
+ utf8Encoder.push(']\n');
53
+ if (!options.geojson.featureArray) {
47
54
  utf8Encoder.push('}');
48
- }
49
- yield utf8Encoder.getArrayBufferBatch();
50
- }();
51
- } catch (e) {
52
- return Promise.reject(e);
53
- }
55
+ }
56
+ // Note: Since we pushed a few final lines, the last batch will always exist, no need to check first
57
+ yield utf8Encoder.getArrayBufferBatch();
54
58
  }
55
- //# sourceMappingURL=geojson-encoder.js.map
@@ -1,5 +1,5 @@
1
1
  import { Table } from '@loaders.gl/schema';
2
- import type { JSONWriterOptions } from '../../json-writer';
2
+ import type { JSONWriterOptions } from "../../json-writer.js";
3
3
  /**
4
4
  * Encode a table as a JSON string
5
5
  */
@@ -1 +1 @@
1
- {"version":3,"file":"json-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/json-encoder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,EAAkB,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEzD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAYnF"}
1
+ {"version":3,"file":"json-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/json-encoder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,KAAK,EAAkB,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAC,iBAAiB,EAAC,6BAA0B;AAEzD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,MAAM,CAYnF"}
@@ -1,12 +1,20 @@
1
+ // loaders.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // Copyright (c) vis.gl contributors
4
+ // Copyright 2022 Foursquare Labs, Inc.
1
5
  import { makeRowIterator } from '@loaders.gl/schema';
6
+ /**
7
+ * Encode a table as a JSON string
8
+ */
2
9
  export function encodeTableAsJSON(table, options) {
3
- var _options$json;
4
- const shape = (options === null || options === void 0 ? void 0 : (_options$json = options.json) === null || _options$json === void 0 ? void 0 : _options$json.shape) || 'object-row-table';
5
- const strings = [];
6
- const rowIterator = makeRowIterator(table, shape);
7
- for (const row of rowIterator) {
8
- strings.push(JSON.stringify(row));
9
- }
10
- return `[${strings.join(',')}]`;
10
+ const shape = options?.json?.shape || 'object-row-table';
11
+ const strings = [];
12
+ const rowIterator = makeRowIterator(table, shape);
13
+ for (const row of rowIterator) {
14
+ // Round elements etc
15
+ // processRow(wrappedRow, table.schema);
16
+ // const wrappedRow = options.wrapper ? options.wrapper(row) : row;
17
+ strings.push(JSON.stringify(row));
18
+ }
19
+ return `[${strings.join(',')}]`;
11
20
  }
12
- //# sourceMappingURL=json-encoder.js.map
@@ -1,5 +1,5 @@
1
- import ClarinetParser, { ClarinetParserOptions } from '../clarinet/clarinet';
2
- import JSONPath from '../jsonpath/jsonpath';
1
+ import ClarinetParser, { ClarinetParserOptions } from "../clarinet/clarinet.js";
2
+ import JSONPath from "../jsonpath/jsonpath.js";
3
3
  export default class JSONParser {
4
4
  readonly parser: ClarinetParser;
5
5
  result: undefined;
@@ -1 +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"}
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,gCAA6B;AAC3E,OAAO,QAAQ,gCAA6B;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"}
@@ -1,109 +1,92 @@
1
+ // @ts-nocheck
1
2
  import ClarinetParser from "../clarinet/clarinet.js";
2
3
  import JSONPath from "../jsonpath/jsonpath.js";
4
+ // JSONParser builds a JSON object using the events emitted by the Clarinet parser
3
5
  export default class JSONParser {
4
- constructor(options) {
5
- this.parser = void 0;
6
- this.result = undefined;
7
- this.previousStates = [];
8
- this.currentState = Object.freeze({
9
- container: [],
10
- key: null
11
- });
12
- this.jsonpath = new JSONPath();
13
- this.reset();
14
- this.parser = new ClarinetParser({
15
- onready: () => {
6
+ constructor(options) {
7
+ this.result = undefined;
8
+ this.previousStates = [];
9
+ this.currentState = Object.freeze({ container: [], key: null });
16
10
  this.jsonpath = new JSONPath();
17
- this.previousStates.length = 0;
18
- this.currentState.container.length = 0;
19
- },
20
- onopenobject: name => {
21
- this._openObject({});
22
- if (typeof name !== 'undefined') {
23
- this.parser.emit('onkey', name);
11
+ this.reset();
12
+ this.parser = new ClarinetParser({
13
+ onready: () => {
14
+ this.jsonpath = new JSONPath();
15
+ this.previousStates.length = 0;
16
+ this.currentState.container.length = 0;
17
+ },
18
+ onopenobject: (name) => {
19
+ this._openObject({});
20
+ if (typeof name !== 'undefined') {
21
+ this.parser.emit('onkey', name);
22
+ }
23
+ },
24
+ onkey: (name) => {
25
+ this.jsonpath.set(name);
26
+ this.currentState.key = name;
27
+ },
28
+ oncloseobject: () => {
29
+ this._closeObject();
30
+ },
31
+ onopenarray: () => {
32
+ this._openArray();
33
+ },
34
+ onclosearray: () => {
35
+ this._closeArray();
36
+ },
37
+ onvalue: (value) => {
38
+ this._pushOrSet(value);
39
+ },
40
+ onerror: (error) => {
41
+ throw error;
42
+ },
43
+ onend: () => {
44
+ this.result = this.currentState.container.pop();
45
+ },
46
+ ...options
47
+ });
48
+ }
49
+ reset() {
50
+ this.result = undefined;
51
+ this.previousStates = [];
52
+ this.currentState = Object.freeze({ container: [], key: null });
53
+ this.jsonpath = new JSONPath();
54
+ }
55
+ write(chunk) {
56
+ this.parser.write(chunk);
57
+ }
58
+ close() {
59
+ this.parser.close();
60
+ }
61
+ // PRIVATE METHODS
62
+ _pushOrSet(value) {
63
+ const { container, key } = this.currentState;
64
+ if (key !== null) {
65
+ container[key] = value;
66
+ this.currentState.key = null;
24
67
  }
25
- },
26
- onkey: name => {
27
- this.jsonpath.set(name);
28
- this.currentState.key = name;
29
- },
30
- oncloseobject: () => {
31
- this._closeObject();
32
- },
33
- onopenarray: () => {
34
- this._openArray();
35
- },
36
- onclosearray: () => {
37
- this._closeArray();
38
- },
39
- onvalue: value => {
40
- this._pushOrSet(value);
41
- },
42
- onerror: error => {
43
- throw error;
44
- },
45
- onend: () => {
46
- this.result = this.currentState.container.pop();
47
- },
48
- ...options
49
- });
50
- }
51
- reset() {
52
- this.result = undefined;
53
- this.previousStates = [];
54
- this.currentState = Object.freeze({
55
- container: [],
56
- key: null
57
- });
58
- this.jsonpath = new JSONPath();
59
- }
60
- write(chunk) {
61
- this.parser.write(chunk);
62
- }
63
- close() {
64
- this.parser.close();
65
- }
66
- _pushOrSet(value) {
67
- const {
68
- container,
69
- key
70
- } = this.currentState;
71
- if (key !== null) {
72
- container[key] = value;
73
- this.currentState.key = null;
74
- } else {
75
- container.push(value);
68
+ else {
69
+ container.push(value);
70
+ }
71
+ }
72
+ _openArray(newContainer = []) {
73
+ this.jsonpath.push(null);
74
+ this._pushOrSet(newContainer);
75
+ this.previousStates.push(this.currentState);
76
+ this.currentState = { container: newContainer, isArray: true, key: null };
77
+ }
78
+ _closeArray() {
79
+ this.jsonpath.pop();
80
+ this.currentState = this.previousStates.pop();
81
+ }
82
+ _openObject(newContainer = {}) {
83
+ this.jsonpath.push(null);
84
+ this._pushOrSet(newContainer);
85
+ this.previousStates.push(this.currentState);
86
+ this.currentState = { container: newContainer, isArray: false, key: null };
87
+ }
88
+ _closeObject() {
89
+ this.jsonpath.pop();
90
+ this.currentState = this.previousStates.pop();
76
91
  }
77
- }
78
- _openArray() {
79
- let newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
80
- this.jsonpath.push(null);
81
- this._pushOrSet(newContainer);
82
- this.previousStates.push(this.currentState);
83
- this.currentState = {
84
- container: newContainer,
85
- isArray: true,
86
- key: null
87
- };
88
- }
89
- _closeArray() {
90
- this.jsonpath.pop();
91
- this.currentState = this.previousStates.pop();
92
- }
93
- _openObject() {
94
- let newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
95
- this.jsonpath.push(null);
96
- this._pushOrSet(newContainer);
97
- this.previousStates.push(this.currentState);
98
- this.currentState = {
99
- container: newContainer,
100
- isArray: false,
101
- key: null
102
- };
103
- }
104
- _closeObject() {
105
- this.jsonpath.pop();
106
- this.currentState = this.previousStates.pop();
107
- }
108
92
  }
109
- //# sourceMappingURL=json-parser.js.map
@@ -1,5 +1,5 @@
1
- import { default as JSONParser } from './json-parser';
2
- import JSONPath from '../jsonpath/jsonpath';
1
+ import { default as JSONParser } from "./json-parser.js";
2
+ import JSONPath from "../jsonpath/jsonpath.js";
3
3
  /**
4
4
  * The `StreamingJSONParser` looks for the first array in the JSON structure.
5
5
  * and emits an array of chunks
@@ -1 +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"}
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,yBAAsB;AACpD,OAAO,QAAQ,gCAA6B;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"}