@loaders.gl/json 4.2.0-alpha.3 → 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.
- package/dist/dist.dev.js +341 -409
- package/dist/dist.min.js +21 -0
- package/dist/geojson-loader.d.ts +1 -1
- package/dist/geojson-loader.d.ts.map +1 -1
- package/dist/geojson-loader.js +75 -73
- package/dist/geojson-worker.js +1 -1
- package/dist/geojson-writer.js +23 -20
- package/dist/index.cjs +120 -94
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/json-loader.js +30 -37
- package/dist/json-writer.js +14 -11
- package/dist/lib/clarinet/clarinet.js +511 -391
- package/dist/lib/encoder-utils/encode-table-row.d.ts +1 -1
- package/dist/lib/encoder-utils/encode-table-row.d.ts.map +1 -1
- package/dist/lib/encoder-utils/encode-table-row.js +46 -37
- package/dist/lib/encoder-utils/encode-utils.js +38 -25
- package/dist/lib/encoder-utils/utf8-encoder.js +25 -27
- package/dist/lib/encoders/geojson-encoder.d.ts +1 -1
- package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/geojson-encoder.js +43 -40
- package/dist/lib/encoders/json-encoder.d.ts +1 -1
- package/dist/lib/encoders/json-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/json-encoder.js +17 -9
- package/dist/lib/json-parser/json-parser.d.ts +2 -2
- package/dist/lib/json-parser/json-parser.d.ts.map +1 -1
- package/dist/lib/json-parser/json-parser.js +85 -102
- package/dist/lib/json-parser/streaming-json-parser.d.ts +2 -2
- package/dist/lib/json-parser/streaming-json-parser.d.ts.map +1 -1
- package/dist/lib/json-parser/streaming-json-parser.js +86 -63
- package/dist/lib/jsonpath/jsonpath.js +77 -57
- package/dist/lib/parsers/parse-json-in-batches.d.ts +1 -1
- package/dist/lib/parsers/parse-json-in-batches.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json-in-batches.js +76 -75
- package/dist/lib/parsers/parse-json.d.ts +1 -1
- package/dist/lib/parsers/parse-json.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json.js +21 -22
- package/dist/lib/parsers/parse-ndjson-in-batches.js +26 -28
- package/dist/lib/parsers/parse-ndjson.js +10 -10
- package/dist/ndgeoson-loader.js +28 -20
- package/dist/ndjson-loader.js +22 -14
- package/dist/workers/geojson-worker.js +0 -1
- package/package.json +11 -7
- package/dist/geojson-loader.js.map +0 -1
- package/dist/geojson-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/json-writer.js.map +0 -1
- package/dist/lib/clarinet/LICENSE +0 -28
- package/dist/lib/clarinet/clarinet.js.map +0 -1
- package/dist/lib/encoder-utils/encode-table-row.js.map +0 -1
- package/dist/lib/encoder-utils/encode-utils.js.map +0 -1
- package/dist/lib/encoder-utils/utf8-encoder.js.map +0 -1
- package/dist/lib/encoders/geojson-encoder.js.map +0 -1
- package/dist/lib/encoders/json-encoder.js.map +0 -1
- package/dist/lib/json-parser/json-parser.js.map +0 -1
- package/dist/lib/json-parser/streaming-json-parser.js.map +0 -1
- package/dist/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/lib/parsers/parse-json-in-batches.js.map +0 -1
- package/dist/lib/parsers/parse-json.js.map +0 -1
- package/dist/lib/parsers/parse-ndjson-in-batches.js.map +0 -1
- package/dist/lib/parsers/parse-ndjson.js.map +0 -1
- package/dist/ndgeoson-loader.js.map +0 -1
- package/dist/ndjson-loader.js.map +0 -1
- package/dist/workers/geojson-worker.js.map +0 -1
|
@@ -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,
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
type
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 +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,
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
29
|
+
geometryColumn = geometryColumn || detectGeometryColumnIndex(tableBatch);
|
|
26
30
|
}
|
|
27
31
|
for (let rowIndex = start; rowIndex < end; ++rowIndex) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
47
|
+
yield arrayBufferBatch;
|
|
42
48
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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 +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,
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
2
|
-
import JSONPath from
|
|
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,
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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.
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.
|
|
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
|
|
2
|
-
import JSONPath from
|
|
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,
|
|
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"}
|