@loaders.gl/json 3.3.0-alpha.4 → 3.3.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.
- package/dist/dist.min.js +16 -10
- package/dist/es5/bundle.js +0 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/geojson-loader.js +34 -82
- package/dist/es5/geojson-loader.js.map +1 -1
- package/dist/es5/index.js +6 -13
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/json-loader.js +4 -18
- package/dist/es5/json-loader.js.map +1 -1
- package/dist/es5/lib/clarinet/clarinet.js +19 -91
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
- package/dist/es5/lib/jsonpath/jsonpath.js +8 -28
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
- package/dist/es5/lib/parse-json-in-batches.js +59 -126
- package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-json.js +0 -10
- package/dist/es5/lib/parse-json.js.map +1 -1
- package/dist/es5/lib/parse-ndjson-in-batches.js +41 -83
- package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-ndjson.js +0 -1
- package/dist/es5/lib/parse-ndjson.js.map +1 -1
- package/dist/es5/lib/parser/json-parser.js +8 -24
- package/dist/es5/lib/parser/json-parser.js.map +1 -1
- package/dist/es5/lib/parser/streaming-json-parser.js +10 -37
- package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/es5/ndjgeoson-loader.js +3 -11
- package/dist/es5/ndjgeoson-loader.js.map +1 -1
- package/dist/es5/ndjson-loader.js +3 -11
- package/dist/es5/ndjson-loader.js.map +1 -1
- package/dist/es5/workers/geojson-worker.js +0 -2
- package/dist/es5/workers/geojson-worker.js.map +1 -1
- package/dist/esm/bundle.js +1 -1
- package/dist/esm/bundle.js.map +1 -1
- package/dist/esm/geojson-loader.js +13 -14
- package/dist/esm/geojson-loader.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/json-loader.js +12 -8
- package/dist/esm/json-loader.js.map +1 -1
- package/dist/esm/lib/clarinet/clarinet.js +19 -108
- package/dist/esm/lib/clarinet/clarinet.js.map +1 -1
- package/dist/esm/lib/jsonpath/jsonpath.js +2 -18
- package/dist/esm/lib/jsonpath/jsonpath.js.map +1 -1
- package/dist/esm/lib/parse-json-in-batches.js +5 -10
- package/dist/esm/lib/parse-json-in-batches.js.map +1 -1
- package/dist/esm/lib/parse-json.js +0 -7
- package/dist/esm/lib/parse-json.js.map +1 -1
- package/dist/esm/lib/parse-ndjson-in-batches.js +2 -5
- package/dist/esm/lib/parse-ndjson-in-batches.js.map +1 -1
- package/dist/esm/lib/parse-ndjson.js.map +1 -1
- package/dist/esm/lib/parser/json-parser.js +6 -21
- package/dist/esm/lib/parser/json-parser.js.map +1 -1
- package/dist/esm/lib/parser/streaming-json-parser.js +3 -19
- package/dist/esm/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/esm/ndjgeoson-loader.js +4 -2
- package/dist/esm/ndjgeoson-loader.js.map +1 -1
- package/dist/esm/ndjson-loader.js +4 -2
- package/dist/esm/ndjson-loader.js.map +1 -1
- package/dist/esm/workers/geojson-worker.js.map +1 -1
- package/dist/geojson-worker.js +10 -11
- package/package.json +5 -5
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
export default class JSONPath {
|
|
3
|
-
constructor(
|
|
3
|
+
constructor() {
|
|
4
|
+
let path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
4
5
|
_defineProperty(this, "path", void 0);
|
|
5
|
-
|
|
6
6
|
this.path = ['$'];
|
|
7
|
-
|
|
8
7
|
if (path instanceof JSONPath) {
|
|
9
8
|
this.path = [...path.path];
|
|
10
9
|
return;
|
|
11
10
|
}
|
|
12
|
-
|
|
13
11
|
if (Array.isArray(path)) {
|
|
14
12
|
this.path.push(...path);
|
|
15
13
|
return;
|
|
@@ -17,44 +15,35 @@ export default class JSONPath {
|
|
|
17
15
|
|
|
18
16
|
if (typeof path === 'string') {
|
|
19
17
|
this.path = path.split('.');
|
|
20
|
-
|
|
21
18
|
if (this.path[0] !== '$') {
|
|
22
19
|
throw new Error('JSONPaths must start with $');
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
|
-
|
|
27
23
|
clone() {
|
|
28
24
|
return new JSONPath(this);
|
|
29
25
|
}
|
|
30
|
-
|
|
31
26
|
toString() {
|
|
32
27
|
return this.path.join('.');
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
push(name) {
|
|
36
30
|
this.path.push(name);
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
pop() {
|
|
40
33
|
return this.path.pop();
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
set(name) {
|
|
44
36
|
this.path[this.path.length - 1] = name;
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
equals(other) {
|
|
48
39
|
if (!this || !other || this.path.length !== other.path.length) {
|
|
49
40
|
return false;
|
|
50
41
|
}
|
|
51
|
-
|
|
52
42
|
for (let i = 0; i < this.path.length; ++i) {
|
|
53
43
|
if (this.path[i] !== other.path[i]) {
|
|
54
44
|
return false;
|
|
55
45
|
}
|
|
56
46
|
}
|
|
57
|
-
|
|
58
47
|
return true;
|
|
59
48
|
}
|
|
60
49
|
|
|
@@ -62,11 +51,9 @@ export default class JSONPath {
|
|
|
62
51
|
const path = [...this.path];
|
|
63
52
|
path.shift();
|
|
64
53
|
const field = path.pop();
|
|
65
|
-
|
|
66
54
|
for (const component of path) {
|
|
67
55
|
object = object[component];
|
|
68
56
|
}
|
|
69
|
-
|
|
70
57
|
object[field] = value;
|
|
71
58
|
}
|
|
72
59
|
|
|
@@ -74,13 +61,10 @@ export default class JSONPath {
|
|
|
74
61
|
const path = [...this.path];
|
|
75
62
|
path.shift();
|
|
76
63
|
const field = path.pop();
|
|
77
|
-
|
|
78
64
|
for (const component of path) {
|
|
79
65
|
object = object[component];
|
|
80
66
|
}
|
|
81
|
-
|
|
82
67
|
return object[field];
|
|
83
68
|
}
|
|
84
|
-
|
|
85
69
|
}
|
|
86
70
|
//# sourceMappingURL=jsonpath.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"jsonpath.js","names":["JSONPath","constructor","path","Array","isArray","push","split","Error","clone","toString","join","name","pop","set","length","equals","other","i","setFieldAtPath","object","value","shift","field","component","getFieldAtPath"],"sources":["../../../../src/lib/jsonpath/jsonpath.ts"],"sourcesContent":["/**\n * A parser for a minimal subset of the jsonpath standard\n * Full JSON path parsers for JS exist but are quite large (bundle size)\n *\n * Supports\n *\n * `$.component.component.component`\n */\nexport default class JSONPath {\n path: string[];\n\n constructor(path: JSONPath | string[] | string | null = null) {\n this.path = ['$'];\n\n if (path instanceof JSONPath) {\n // @ts-ignore\n this.path = [...path.path];\n return;\n }\n\n if (Array.isArray(path)) {\n this.path.push(...path);\n return;\n }\n\n // Parse a string as a JSONPath\n if (typeof path === 'string') {\n this.path = path.split('.');\n if (this.path[0] !== '$') {\n throw new Error('JSONPaths must start with $');\n }\n }\n }\n\n clone(): JSONPath {\n return new JSONPath(this);\n }\n\n toString(): string {\n return this.path.join('.');\n }\n\n push(name: string): void {\n this.path.push(name);\n }\n\n pop() {\n return this.path.pop();\n }\n\n set(name: string): void {\n this.path[this.path.length - 1] = name;\n }\n\n equals(other: JSONPath): boolean {\n if (!this || !other || this.path.length !== other.path.length) {\n return false;\n }\n\n for (let i = 0; i < this.path.length; ++i) {\n if (this.path[i] !== other.path[i]) {\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Sets the value pointed at by path\n * TODO - handle root path\n * @param object\n * @param value\n */\n setFieldAtPath(object, value) {\n const path = [...this.path];\n path.shift();\n const field = path.pop();\n for (const component of path) {\n object = object[component];\n }\n // @ts-ignore\n object[field] = value;\n }\n\n /**\n * Gets the value pointed at by path\n * TODO - handle root path\n * @param object\n */\n getFieldAtPath(object) {\n const path = [...this.path];\n path.shift();\n const field = path.pop();\n for (const component of path) {\n object = object[component];\n }\n // @ts-ignore\n return object[field];\n }\n}\n"],"mappings":";AAQA,eAAe,MAAMA,QAAQ,CAAC;EAG5BC,WAAW,GAAmD;IAAA,IAAlDC,IAAyC,uEAAG,IAAI;IAAA;IAC1D,IAAI,CAACA,IAAI,GAAG,CAAC,GAAG,CAAC;IAEjB,IAAIA,IAAI,YAAYF,QAAQ,EAAE;MAE5B,IAAI,CAACE,IAAI,GAAG,CAAC,GAAGA,IAAI,CAACA,IAAI,CAAC;MAC1B;IACF;IAEA,IAAIC,KAAK,CAACC,OAAO,CAACF,IAAI,CAAC,EAAE;MACvB,IAAI,CAACA,IAAI,CAACG,IAAI,CAAC,GAAGH,IAAI,CAAC;MACvB;IACF;;IAGA,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;MAC5B,IAAI,CAACA,IAAI,GAAGA,IAAI,CAACI,KAAK,CAAC,GAAG,CAAC;MAC3B,IAAI,IAAI,CAACJ,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QACxB,MAAM,IAAIK,KAAK,CAAC,6BAA6B,CAAC;MAChD;IACF;EACF;EAEAC,KAAK,GAAa;IAChB,OAAO,IAAIR,QAAQ,CAAC,IAAI,CAAC;EAC3B;EAEAS,QAAQ,GAAW;IACjB,OAAO,IAAI,CAACP,IAAI,CAACQ,IAAI,CAAC,GAAG,CAAC;EAC5B;EAEAL,IAAI,CAACM,IAAY,EAAQ;IACvB,IAAI,CAACT,IAAI,CAACG,IAAI,CAACM,IAAI,CAAC;EACtB;EAEAC,GAAG,GAAG;IACJ,OAAO,IAAI,CAACV,IAAI,CAACU,GAAG,EAAE;EACxB;EAEAC,GAAG,CAACF,IAAY,EAAQ;IACtB,IAAI,CAACT,IAAI,CAAC,IAAI,CAACA,IAAI,CAACY,MAAM,GA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DecoderIterator } from '@loaders.gl/loader-utils';
|
|
3
3
|
import StreamingJSONParser from './parser/streaming-json-parser';
|
|
4
4
|
import JSONPath from './jsonpath/jsonpath';
|
|
5
|
+
|
|
5
6
|
export default async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
6
7
|
var _options$json;
|
|
7
|
-
|
|
8
8
|
const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
|
|
9
9
|
const {
|
|
10
10
|
metadata
|
|
@@ -13,19 +13,19 @@ export default async function* parseJSONInBatches(binaryAsyncIterator, options)
|
|
|
13
13
|
jsonpaths
|
|
14
14
|
} = options.json || {};
|
|
15
15
|
let isFirstChunk = true;
|
|
16
|
+
|
|
16
17
|
const schema = null;
|
|
17
18
|
const shape = (options === null || options === void 0 ? void 0 : (_options$json = options.json) === null || _options$json === void 0 ? void 0 : _options$json.shape) || 'row-table';
|
|
18
|
-
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
19
|
+
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
20
|
+
...options,
|
|
19
21
|
shape
|
|
20
22
|
});
|
|
21
23
|
const parser = new StreamingJSONParser({
|
|
22
24
|
jsonpaths
|
|
23
25
|
});
|
|
24
|
-
|
|
25
26
|
for await (const chunk of asyncIterator) {
|
|
26
27
|
const rows = parser.write(chunk);
|
|
27
28
|
const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
|
|
28
|
-
|
|
29
29
|
if (rows.length > 0 && isFirstChunk) {
|
|
30
30
|
if (metadata) {
|
|
31
31
|
const initialBatch = {
|
|
@@ -39,7 +39,6 @@ export default async function* parseJSONInBatches(binaryAsyncIterator, options)
|
|
|
39
39
|
};
|
|
40
40
|
yield initialBatch;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
42
|
isFirstChunk = false;
|
|
44
43
|
}
|
|
45
44
|
|
|
@@ -48,17 +47,14 @@ export default async function* parseJSONInBatches(binaryAsyncIterator, options)
|
|
|
48
47
|
const batch = tableBatchBuilder.getFullBatch({
|
|
49
48
|
jsonpath
|
|
50
49
|
});
|
|
51
|
-
|
|
52
50
|
if (batch) {
|
|
53
51
|
yield batch;
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
|
|
57
54
|
tableBatchBuilder.chunkComplete(chunk);
|
|
58
55
|
const batch = tableBatchBuilder.getFullBatch({
|
|
59
56
|
jsonpath
|
|
60
57
|
});
|
|
61
|
-
|
|
62
58
|
if (batch) {
|
|
63
59
|
yield batch;
|
|
64
60
|
}
|
|
@@ -68,11 +64,9 @@ export default async function* parseJSONInBatches(binaryAsyncIterator, options)
|
|
|
68
64
|
const batch = tableBatchBuilder.getFinalBatch({
|
|
69
65
|
jsonpath
|
|
70
66
|
});
|
|
71
|
-
|
|
72
67
|
if (batch) {
|
|
73
68
|
yield batch;
|
|
74
69
|
}
|
|
75
|
-
|
|
76
70
|
if (metadata) {
|
|
77
71
|
const finalBatch = {
|
|
78
72
|
shape,
|
|
@@ -82,6 +76,7 @@ export default async function* parseJSONInBatches(binaryAsyncIterator, options)
|
|
|
82
76
|
data: [],
|
|
83
77
|
length: 0
|
|
84
78
|
};
|
|
79
|
+
|
|
85
80
|
yield finalBatch;
|
|
86
81
|
}
|
|
87
82
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parse-json-in-batches.js","names":["TableBatchBuilder","assert","makeTextDecoderIterator","StreamingJSONParser","JSONPath","parseJSONInBatches","binaryAsyncIterator","options","asyncIterator","metadata","jsonpaths","json","isFirstChunk","schema","shape","tableBatchBuilder","parser","chunk","rows","write","jsonpath","length","getStreamingJsonPathAsString","initialBatch","batchType","data","bytesUsed","container","getPartialResult","row","addRow","batch","getFullBatch","chunkComplete","getFinalBatch","finalBatch","rebuildJsonObject","topLevelObject","streamingPath","setFieldAtPath"],"sources":["../../../src/lib/parse-json-in-batches.ts"],"sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport type {JSONLoaderOptions} from '../json-loader';\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {assert, makeTextDecoderIterator} from '@loaders.gl/loader-utils';\nimport StreamingJSONParser from './parser/streaming-json-parser';\nimport JSONPath from './jsonpath/jsonpath';\n\n// TODO - support batch size 0 = no batching/single batch?\n// eslint-disable-next-line max-statements, complexity\nexport default async function* parseJSONInBatches(\n binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options: JSONLoaderOptions\n): AsyncIterable<Batch> {\n const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);\n\n const {metadata} = options;\n const {jsonpaths} = options.json || {};\n\n let isFirstChunk: boolean = true;\n\n // TODO fix Schema deduction\n const schema = null; // new Schema([]);\n const shape = options?.json?.shape || 'row-table';\n // @ts-ignore\n const tableBatchBuilder = new TableBatchBuilder(schema, {\n ...options,\n shape\n });\n\n const parser = new StreamingJSONParser({jsonpaths});\n\n for await (const chunk of asyncIterator) {\n const rows = parser.write(chunk);\n\n const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();\n\n if (rows.length > 0 && isFirstChunk) {\n if (metadata) {\n const initialBatch: Batch = {\n // Common fields\n shape,\n batchType: 'partial-result',\n data: [],\n length: 0,\n bytesUsed: 0,\n // JSON additions\n container: parser.getPartialResult(),\n jsonpath\n };\n yield initialBatch;\n }\n isFirstChunk = false;\n // schema = deduceSchema(rows);\n }\n\n // Add the row\n for (const row of rows) {\n tableBatchBuilder.addRow(row);\n // If a batch has been completed, emit it\n const batch = tableBatchBuilder.getFullBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n }\n\n tableBatchBuilder.chunkComplete(chunk);\n const batch = tableBatchBuilder.getFullBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n }\n\n // yield final batch\n const jsonpath = parser.getStreamingJsonPathAsString();\n const batch = tableBatchBuilder.getFinalBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n\n if (metadata) {\n const finalBatch: Batch = {\n shape,\n batchType: 'final-result',\n container: parser.getPartialResult(),\n jsonpath: parser.getStreamingJsonPathAsString(),\n data: [],\n length: 0\n // schema: null\n };\n yield finalBatch;\n }\n}\n\nexport function rebuildJsonObject(batch, data) {\n // Last batch will have this special type and will provide all the root object of the parsed file\n assert(batch.batchType === 'final-result');\n\n // The streamed JSON data is a top level array (jsonpath = '$'), just return the array of row objects\n if (batch.jsonpath === '$') {\n return data;\n }\n\n // (jsonpath !== '$') The streamed data is not a top level array, so stitch it back in to the top-level object\n if (batch.jsonpath && batch.jsonpath.length > 1) {\n const topLevelObject = batch.container;\n const streamingPath = new JSONPath(batch.jsonpath);\n streamingPath.setFieldAtPath(topLevelObject, data);\n return topLevelObject;\n }\n\n // No jsonpath, in this case nothing was streamed.\n return batch.container;\n}\n"],"mappings":"AAEA,SAAQA,iBAAiB,QAAO,oBAAoB;AACpD,SAAQC,MAAM,EAAEC,uBAAuB,QAAO,0BAA0B;AACxE,OAAOC,mBAAmB,MAAM,gCAAgC;AAChE,OAAOC,QAAQ,MAAM,qBAAqB;;AAI1C,eAAe,gBAAgBC,kBAAkB,CAC/CC,mBAAuE,EACvEC,OAA0B,EACJ;EAAA;EACtB,MAAMC,aAAa,GAAGN,uBAAuB,CAACI,mBAAmB,CAAC;EAElE,MAAM;IAACG;EAAQ,CAAC,GAAGF,OAAO;EAC1B,MAAM;IAACG;EAAS,CAAC,GAAGH,OAAO,CAACI,IAAI,IAAI,CAAC,CAAC;EAEtC,IAAIC,YAAqB,GAAG,IAAI;;EAGhC,MAAMC,MAAM,GAAG,IAAI;EACnB,MAAMC,KAAK,GAAG,CAAAP,OAAO,aAAPA,OAAO,wCAAPA,OAAO,CAAEI,IAAI,kDAAb,cAAeG,KAAK,KAAI,WAAW;EAEjD,MAAMC,iBAAiB,GAAG,IAAIf,iBAAiB,CAACa,MAAM,EAAE;IACtD,GAAGN,OAAO;IACVO;EACF,CAAC,CAAC;EAEF,MAAME,MAAM,GAAG,IAAIb,mBAAmB,CAAC;IAACO;EAAS,CAAC,CAA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AS,EAAE,cAAc;MACzBG,SAAS,EAAEX,MAAM,CAACY,gBAAgB,EAAE;MACpCR,QAAQ,EAAEJ,MAAM,CAACM,4BAA4B,EAAE;MAC/CG,IAAI,EAAE,EAAE;MACRJ,MAAM,EAAE;IAEV,CAAC;;IACD,MAAMc,UAAU;EAClB;AACF;AAEA,OAAO,SAASC,iBAAiB,CAACL,KAAK,EAAEN,IAAI,EAAE;EAE7CxB,MAAM,CAAC8B,KAAK,CAACP,SAAS,KAAK,cAAc,CAAC;;EAG1C,IAAIO,KAAK,CAACX,QAAQ,KAAK,GAAG,EAAE;IAC1B,OAAOK,IAAI;EACb;;EAGA,IAAIM,KAAK,CAACX,QAAQ,IAAIW,KAAK,CAACX,QAAQ,CAACC,MAAM,GAAG,CAAC,EAAE;IAC/C,MAAMgB,cAAc,GAAGN,KAAK,CAACJ,SAAS;IACtC,MAAMW,aAAa,GAAG,IAAIlC,QAAQ,CAAC2B,KAAK,CAACX,QAAQ,CAAC;IAClDkB,aAAa,CAACC,cAAc,CAACF,cAAc,EAAEZ,IAAI,CAAC;IAClD,OAAOY,cAAc;EACvB;;EAGA,OAAON,KAAK,CAACJ,SAAS;AACxB"}
|
|
@@ -1,34 +1,27 @@
|
|
|
1
1
|
export default function parseJSONSync(jsonText, options) {
|
|
2
2
|
try {
|
|
3
3
|
var _options$json;
|
|
4
|
-
|
|
5
4
|
const json = JSON.parse(jsonText);
|
|
6
|
-
|
|
7
5
|
if ((_options$json = options.json) !== null && _options$json !== void 0 && _options$json.table) {
|
|
8
6
|
return getFirstArray(json) || json;
|
|
9
7
|
}
|
|
10
|
-
|
|
11
8
|
return json;
|
|
12
9
|
} catch (error) {
|
|
13
10
|
throw new Error('JSONLoader: failed to parse JSON');
|
|
14
11
|
}
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
function getFirstArray(json) {
|
|
18
14
|
if (Array.isArray(json)) {
|
|
19
15
|
return json;
|
|
20
16
|
}
|
|
21
|
-
|
|
22
17
|
if (json && typeof json === 'object') {
|
|
23
18
|
for (const value of Object.values(json)) {
|
|
24
19
|
const array = getFirstArray(value);
|
|
25
|
-
|
|
26
20
|
if (array) {
|
|
27
21
|
return array;
|
|
28
22
|
}
|
|
29
23
|
}
|
|
30
24
|
}
|
|
31
|
-
|
|
32
25
|
return null;
|
|
33
26
|
}
|
|
34
27
|
//# sourceMappingURL=parse-json.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parse-json.js","names":["parseJSONSync","jsonText","options","json","JSON","parse","table","getFirstArray","error","Error","Array","isArray","value","Object","values","array"],"sources":["../../../src/lib/parse-json.ts"],"sourcesContent":["import type {JSONLoaderOptions} from '../json-loader';\n\nexport default function parseJSONSync(jsonText: string, options: JSONLoaderOptions) {\n try {\n const json = JSON.parse(jsonText);\n if (options.json?.table) {\n return getFirstArray(json) || json;\n }\n return json;\n } catch (error) {\n throw new Error('JSONLoader: failed to parse JSON');\n }\n}\n\nfunction getFirstArray(json) {\n if (Array.isArray(json)) {\n return json;\n }\n if (json && typeof json === 'object') {\n for (const value of Object.values(json)) {\n const array = getFirstArray(value);\n if (array) {\n return array;\n }\n }\n }\n return null;\n}\n"],"mappings":"AAEA,eAAe,SAASA,aAAa,CAACC,QAAgB,EAAEC,OAA0B,EAAE;EAClF,IAAI;IAAA;IACF,MAAMC,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACJ,QAAQ,CAAC;IACjC,qBAAIC,OAAO,CAACC,IAAI,0CAAZ,cAAcG,KAAK,EAAE;MACvB,OAAOC,aAAa,CAACJ,IAAI,CAAC,IAAIA,IAAI;IACpC;IACA,OAAOA,IAAI;EACb,CAAC,CAAC,OAAOK,KAAK,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,kCAAkC,CAAC;EACrD;AACF;AAEA,SAASF,aAAa,CAACJ,IAAI,EAAE;EAC3B,IAAIO,KAAK,CAACC,OAAO,CAACR,IAAI,CAAC,EAAE;IACvB,OAAOA,IAAI;EACb;EACA,IAAIA,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACpC,KAAK,MAAMS,KAAK,IAAIC,MAAM,CAACC,MAAM,CAACX,IAAI,CAAC,EAAE;MACvC,MAAMY,KAAK,GAAGR,aAAa,CAACK,KAAK,CAAC;MAClC,IAAIG,KAAK,EAAE;QACT,OAAOA,KAAK;MACd;IACF;EACF;EACA,OAAO,IAAI;AACb"}
|
|
@@ -6,10 +6,10 @@ export default async function* parseNDJSONInBatches(binaryAsyncIterator, options
|
|
|
6
6
|
const numberedLineIterator = makeNumberedLineIterator(lineIterator);
|
|
7
7
|
const schema = null;
|
|
8
8
|
const shape = 'row-table';
|
|
9
|
-
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
9
|
+
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
10
|
+
...options,
|
|
10
11
|
shape
|
|
11
12
|
});
|
|
12
|
-
|
|
13
13
|
for await (const {
|
|
14
14
|
counter,
|
|
15
15
|
line
|
|
@@ -19,7 +19,6 @@ export default async function* parseNDJSONInBatches(binaryAsyncIterator, options
|
|
|
19
19
|
tableBatchBuilder.addRow(row);
|
|
20
20
|
tableBatchBuilder.chunkComplete(line);
|
|
21
21
|
const batch = tableBatchBuilder.getFullBatch();
|
|
22
|
-
|
|
23
22
|
if (batch) {
|
|
24
23
|
yield batch;
|
|
25
24
|
}
|
|
@@ -27,9 +26,7 @@ export default async function* parseNDJSONInBatches(binaryAsyncIterator, options
|
|
|
27
26
|
throw new Error("NDJSONLoader: failed to parse JSON on line ".concat(counter));
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
|
-
|
|
31
29
|
const batch = tableBatchBuilder.getFinalBatch();
|
|
32
|
-
|
|
33
30
|
if (batch) {
|
|
34
31
|
yield batch;
|
|
35
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parse-ndjson-in-batches.js","names":["TableBatchBuilder","makeLineIterator","makeNumberedLineIterator","makeTextDecoderIterator","parseNDJSONInBatches","binaryAsyncIterator","options","textIterator","lineIterator","numberedLineIterator","schema","shape","tableBatchBuilder","counter","line","row","JSON","parse","addRow","chunkComplete","batch","getFullBatch","error","Error","getFinalBatch"],"sources":["../../../src/lib/parse-ndjson-in-batches.ts"],"sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {\n LoaderOptions,\n makeLineIterator,\n makeNumberedLineIterator,\n makeTextDecoderIterator\n} from '@loaders.gl/loader-utils';\n\nexport default async function* parseNDJSONInBatches(\n binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: LoaderOptions\n): AsyncIterable<Batch> {\n const textIterator = makeTextDecoderIterator(binaryAsyncIterator);\n const lineIterator = makeLineIterator(textIterator);\n const numberedLineIterator = makeNumberedLineIterator(lineIterator);\n\n const schema = null;\n const shape = 'row-table';\n // @ts-ignore\n const tableBatchBuilder = new TableBatchBuilder(schema, {\n ...options,\n shape\n });\n\n for await (const {counter, line} of numberedLineIterator) {\n try {\n const row = JSON.parse(line);\n tableBatchBuilder.addRow(row);\n tableBatchBuilder.chunkComplete(line);\n const batch = tableBatchBuilder.getFullBatch();\n if (batch) {\n yield batch;\n }\n } catch (error) {\n throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);\n }\n }\n\n const batch = tableBatchBuilder.getFinalBatch();\n if (batch) {\n yield batch;\n }\n}\n"],"mappings":"AACA,SAAQA,iBAAiB,QAAO,oBAAoB;AACpD,SAEEC,gBAAgB,EAChBC,wBAAwB,EACxBC,uBAAuB,QAClB,0BAA0B;AAEjC,eAAe,gBAAgBC,oBAAoB,CACjDC,mBAAuE,EACvEC,OAAuB,EACD;EACtB,MAAMC,YAAY,GAAGJ,uBAAuB,CAACE,mBAAmB,CAAC;EACjE,MAAMG,YAAY,GAAGP,gBAAgB,CAACM,YAAY,CAAC;EACnD,MAAME,oBAAoB,GAAGP,wBAAwB,CAACM,YAAY,CAAC;EAEnE,MAAME,MAAM,GAAG,IAAI;EACnB,MAAMC,KAAK,GAAG,WAAW;EAEzB,MAAMC,iBAAiB,GAAG,IAAIZ,iBAAiB,CAACU,MAAM,EAAE;IACtD,GAAGJ,OAAO;IACVK;EACF,CAAC,CAAC;EAEF,WAAW,MAAM;IAACE,OAAO;IAAEC;EAAI,CAAC,IAAIL,oBAAoB,EAAE;IACxD,IAAI;MACF,MAAMM,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;MAC5BF,iBAAiB,CAACM,MAAM,CAACH,GAAG,CAAC;MAC7BH,iBAAiB,CAACO,aAAa,CAACL,IAAI,CAAC;MACrC,MAAMM,KAAK,GAAGR,iBAAiB,CAACS,YAAY,EAAE;MAC9C,IAAID,KAAK,EAAE;QACT,MAAMA,KAAK;MACb;IACF,CAAC,CAAC,OAAOE,KAAK,EAAE;MACd,MAAM,IAAIC,KAAK,sDAA+CV,OAAO,EAAG;IAC1E;EACF;EAEA,MAAMO,KAAK,GAAGR,iBAAiB,CAACY,aAAa,EAAE;EAC/C,IAAIJ,KAAK,EAAE;IACT,MAAMA,KAAK;EACb;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"parse-ndjson.js","names":["parseNDJSONSync","ndjsonText","lines","trim","split","map","line","counter","JSON","parse","error","Error"],"sources":["../../../src/lib/parse-ndjson.ts"],"sourcesContent":["export default function parseNDJSONSync(ndjsonText: string) {\n const lines = ndjsonText.trim().split('\\n');\n return lines.map((line, counter) => {\n try {\n return JSON.parse(line);\n } catch (error) {\n throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);\n }\n });\n}\n"],"mappings":"AAAA,eAAe,SAASA,eAAe,CAACC,UAAkB,EAAE;EAC1D,MAAMC,KAAK,GAAGD,UAAU,CAACE,IAAI,EAAE,CAACC,KAAK,CAAC,IAAI,CAAC;EAC3C,OAAOF,KAAK,CAACG,GAAG,CAAC,CAACC,IAAI,EAAEC,OAAO,KAAK;IAClC,IAAI;MACF,OAAOC,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;IACzB,CAAC,CAAC,OAAOI,KAAK,EAAE;MACd,MAAM,IAAIC,KAAK,sDAA+CJ,OAAO,GAAG,CAAC,EAAG;IAC9E;EACF,CAAC,CAAC;AACJ"}
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
|
|
2
3
|
import ClarinetParser from '../clarinet/clarinet';
|
|
3
4
|
import JSONPath from '../jsonpath/jsonpath';
|
|
5
|
+
|
|
4
6
|
export default class JSONParser {
|
|
5
7
|
constructor(options) {
|
|
6
8
|
_defineProperty(this, "parser", void 0);
|
|
7
|
-
|
|
8
9
|
_defineProperty(this, "result", undefined);
|
|
9
|
-
|
|
10
10
|
_defineProperty(this, "previousStates", []);
|
|
11
|
-
|
|
12
11
|
_defineProperty(this, "currentState", Object.freeze({
|
|
13
12
|
container: [],
|
|
14
13
|
key: null
|
|
15
14
|
}));
|
|
16
|
-
|
|
17
15
|
_defineProperty(this, "jsonpath", new JSONPath());
|
|
18
|
-
|
|
19
16
|
this.reset();
|
|
20
17
|
this.parser = new ClarinetParser({
|
|
21
18
|
onready: () => {
|
|
@@ -25,7 +22,6 @@ export default class JSONParser {
|
|
|
25
22
|
},
|
|
26
23
|
onopenobject: name => {
|
|
27
24
|
this._openObject({});
|
|
28
|
-
|
|
29
25
|
if (typeof name !== 'undefined') {
|
|
30
26
|
this.parser.emit('onkey', name);
|
|
31
27
|
}
|
|
@@ -55,7 +51,6 @@ export default class JSONParser {
|
|
|
55
51
|
...options
|
|
56
52
|
});
|
|
57
53
|
}
|
|
58
|
-
|
|
59
54
|
reset() {
|
|
60
55
|
this.result = undefined;
|
|
61
56
|
this.previousStates = [];
|
|
@@ -65,11 +60,9 @@ export default class JSONParser {
|
|
|
65
60
|
});
|
|
66
61
|
this.jsonpath = new JSONPath();
|
|
67
62
|
}
|
|
68
|
-
|
|
69
63
|
write(chunk) {
|
|
70
64
|
this.parser.write(chunk);
|
|
71
65
|
}
|
|
72
|
-
|
|
73
66
|
close() {
|
|
74
67
|
this.parser.close();
|
|
75
68
|
}
|
|
@@ -79,7 +72,6 @@ export default class JSONParser {
|
|
|
79
72
|
container,
|
|
80
73
|
key
|
|
81
74
|
} = this.currentState;
|
|
82
|
-
|
|
83
75
|
if (key !== null) {
|
|
84
76
|
container[key] = value;
|
|
85
77
|
this.currentState.key = null;
|
|
@@ -87,12 +79,10 @@ export default class JSONParser {
|
|
|
87
79
|
container.push(value);
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
_openArray() {
|
|
83
|
+
let newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
92
84
|
this.jsonpath.push(null);
|
|
93
|
-
|
|
94
85
|
this._pushOrSet(newContainer);
|
|
95
|
-
|
|
96
86
|
this.previousStates.push(this.currentState);
|
|
97
87
|
this.currentState = {
|
|
98
88
|
container: newContainer,
|
|
@@ -100,17 +90,14 @@ export default class JSONParser {
|
|
|
100
90
|
key: null
|
|
101
91
|
};
|
|
102
92
|
}
|
|
103
|
-
|
|
104
93
|
_closeArray() {
|
|
105
94
|
this.jsonpath.pop();
|
|
106
95
|
this.currentState = this.previousStates.pop();
|
|
107
96
|
}
|
|
108
|
-
|
|
109
|
-
|
|
97
|
+
_openObject() {
|
|
98
|
+
let newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
110
99
|
this.jsonpath.push(null);
|
|
111
|
-
|
|
112
100
|
this._pushOrSet(newContainer);
|
|
113
|
-
|
|
114
101
|
this.previousStates.push(this.currentState);
|
|
115
102
|
this.currentState = {
|
|
116
103
|
container: newContainer,
|
|
@@ -118,11 +105,9 @@ export default class JSONParser {
|
|
|
118
105
|
key: null
|
|
119
106
|
};
|
|
120
107
|
}
|
|
121
|
-
|
|
122
108
|
_closeObject() {
|
|
123
109
|
this.jsonpath.pop();
|
|
124
110
|
this.currentState = this.previousStates.pop();
|
|
125
111
|
}
|
|
126
|
-
|
|
127
112
|
}
|
|
128
113
|
//# sourceMappingURL=json-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"json-parser.js","names":["ClarinetParser","JSONPath","JSONParser","constructor","options","undefined","Object","freeze","container","key","reset","parser","onready","jsonpath","previousStates","length","currentState","onopenobject","name","_openObject","emit","onkey","set","oncloseobject","_closeObject","onopenarray","_openArray","onclosearray","_closeArray","onvalue","value","_pushOrSet","onerror","error","onend","result","pop","write","chunk","close","push","newContainer","isArray"],"sources":["../../../../src/lib/parser/json-parser.ts"],"sourcesContent":["// @ts-nocheck\n\nimport ClarinetParser, {ClarinetParserOptions} from '../clarinet/clarinet';\nimport JSONPath from '../jsonpath/jsonpath';\n\n// JSONParser builds a JSON object using the events emitted by the Clarinet parser\n\nexport default class JSONParser {\n readonly parser: ClarinetParser;\n result = undefined;\n previousStates = [];\n currentState = Object.freeze({container: [], key: null});\n jsonpath: JSONPath = new JSONPath();\n\n constructor(options: ClarinetParserOptions) {\n this.reset();\n this.parser = new ClarinetParser({\n onready: () => {\n this.jsonpath = new JSONPath();\n this.previousStates.length = 0;\n this.currentState.container.length = 0;\n },\n\n onopenobject: (name) => {\n this._openObject({});\n if (typeof name !== 'undefined') {\n this.parser.emit('onkey', name);\n }\n },\n\n onkey: (name) => {\n this.jsonpath.set(name);\n this.currentState.key = name;\n },\n\n oncloseobject: () => {\n this._closeObject();\n },\n\n onopenarray: () => {\n this._openArray();\n },\n\n onclosearray: () => {\n this._closeArray();\n },\n\n onvalue: (value) => {\n this._pushOrSet(value);\n },\n\n onerror: (error) => {\n throw error;\n },\n\n onend: () => {\n this.result = this.currentState.container.pop();\n },\n\n ...options\n });\n }\n\n reset(): void {\n this.result = undefined;\n this.previousStates = [];\n this.currentState = Object.freeze({container: [], key: null});\n this.jsonpath = new JSONPath();\n }\n\n write(chunk): void {\n this.parser.write(chunk);\n }\n\n close(): void {\n this.parser.close();\n }\n\n // PRIVATE METHODS\n\n _pushOrSet(value): void {\n const {container, key} = this.currentState;\n if (key !== null) {\n container[key] = value;\n this.currentState.key = null;\n } else {\n container.push(value);\n }\n }\n\n _openArray(newContainer = []): void {\n this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: true, key: null};\n }\n\n _closeArray(): void {\n this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _openObject(newContainer = {}): void {\n this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: false, key: null};\n }\n\n _closeObject(): void {\n this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n}\n"],"mappings":";;AAEA,OAAOA,cAAc,MAA+B,sBAAsB;AAC1E,OAAOC,QAAQ,MAAM,sBAAsB;;AAI3C,eAAe,MAAMC,UAAU,CAAC;EAO9BC,WAAW,CAACC,OAA8B,EAAE;IAAA;IAAA,gCALnCC,SAAS;IAAA,wCACD,EAAE;IAAA,sCACJC,MAAM,CAACC,MAAM,CAAC;MAACC,SAAS,EAAE,EAAE;MAAEC,GAAG,EAAE;IAAI,CAAC,CAAC;IAAA,kCACnC,IAAIR,QAAQ,EAAE;IAGjC,IAAI,CAACS,KAAK,EAAE;IACZ,IAAI,CAACC,MAAM,GAAG,IAAIX,cAAc,CAAC;MAC/BY,OAAO,EAAE,MAAM;QACb,IAAI,CAACC,QAAQ,GAAG,IAAIZ,QAAQ,EAAE;QAC9B,IAAI,CAACa,cAAc,CAACC,MAAM,GAAG,CAAC;QAC9B,IAAI,CAACC,YAAY,CAACR,SAAS,CAACO,MAAM,GAAG,CAAC;MACxC,CAAC;MAEDE,YAAY,EAAGC,IAAI,IAAK;QACtB,IAAI,CA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QAAQ,CAACuB,GAAG,EAAE;IACnB,IAAI,CAACpB,YAAY,GAAG,IAAI,CAACF,cAAc,CAACsB,GAAG,EAAE;EAC/C;AACF"}
|
|
@@ -1,46 +1,38 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
2
|
import { default as JSONParser } from './json-parser';
|
|
3
3
|
import JSONPath from '../jsonpath/jsonpath';
|
|
4
|
+
|
|
4
5
|
export default class StreamingJSONParser extends JSONParser {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor() {
|
|
7
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
8
|
super({
|
|
7
9
|
onopenarray: () => {
|
|
8
10
|
if (!this.streamingArray) {
|
|
9
11
|
if (this._matchJSONPath()) {
|
|
10
12
|
this.streamingJsonPath = this.getJsonPath().clone();
|
|
11
13
|
this.streamingArray = [];
|
|
12
|
-
|
|
13
14
|
this._openArray(this.streamingArray);
|
|
14
|
-
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
-
|
|
19
18
|
this._openArray();
|
|
20
19
|
},
|
|
21
20
|
onopenobject: name => {
|
|
22
21
|
if (!this.topLevelObject) {
|
|
23
22
|
this.topLevelObject = {};
|
|
24
|
-
|
|
25
23
|
this._openObject(this.topLevelObject);
|
|
26
24
|
} else {
|
|
27
25
|
this._openObject({});
|
|
28
26
|
}
|
|
29
|
-
|
|
30
27
|
if (typeof name !== 'undefined') {
|
|
31
28
|
this.parser.emit('onkey', name);
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
31
|
});
|
|
35
|
-
|
|
36
32
|
_defineProperty(this, "jsonPaths", void 0);
|
|
37
|
-
|
|
38
33
|
_defineProperty(this, "streamingJsonPath", null);
|
|
39
|
-
|
|
40
34
|
_defineProperty(this, "streamingArray", null);
|
|
41
|
-
|
|
42
35
|
_defineProperty(this, "topLevelObject", null);
|
|
43
|
-
|
|
44
36
|
const jsonpaths = options.jsonpaths || [];
|
|
45
37
|
this.jsonPaths = jsonpaths.map(jsonpath => new JSONPath(jsonpath));
|
|
46
38
|
}
|
|
@@ -48,27 +40,22 @@ export default class StreamingJSONParser extends JSONParser {
|
|
|
48
40
|
write(chunk) {
|
|
49
41
|
super.write(chunk);
|
|
50
42
|
let array = [];
|
|
51
|
-
|
|
52
43
|
if (this.streamingArray) {
|
|
53
44
|
array = [...this.streamingArray];
|
|
54
45
|
this.streamingArray.length = 0;
|
|
55
46
|
}
|
|
56
|
-
|
|
57
47
|
return array;
|
|
58
48
|
}
|
|
59
49
|
|
|
60
50
|
getPartialResult() {
|
|
61
51
|
return this.topLevelObject;
|
|
62
52
|
}
|
|
63
|
-
|
|
64
53
|
getStreamingJsonPath() {
|
|
65
54
|
return this.streamingJsonPath;
|
|
66
55
|
}
|
|
67
|
-
|
|
68
56
|
getStreamingJsonPathAsString() {
|
|
69
57
|
return this.streamingJsonPath && this.streamingJsonPath.toString();
|
|
70
58
|
}
|
|
71
|
-
|
|
72
59
|
getJsonPath() {
|
|
73
60
|
return this.jsonpath;
|
|
74
61
|
}
|
|
@@ -79,15 +66,12 @@ export default class StreamingJSONParser extends JSONParser {
|
|
|
79
66
|
if (this.jsonPaths.length === 0) {
|
|
80
67
|
return true;
|
|
81
68
|
}
|
|
82
|
-
|
|
83
69
|
for (const jsonPath of this.jsonPaths) {
|
|
84
70
|
if (jsonPath.equals(currentPath)) {
|
|
85
71
|
return true;
|
|
86
72
|
}
|
|
87
73
|
}
|
|
88
|
-
|
|
89
74
|
return false;
|
|
90
75
|
}
|
|
91
|
-
|
|
92
76
|
}
|
|
93
77
|
//# sourceMappingURL=streaming-json-parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"streaming-json-parser.js","names":["default","JSONParser","JSONPath","StreamingJSONParser","constructor","options","onopenarray","streamingArray","_matchJSONPath","streamingJsonPath","getJsonPath","clone","_openArray","onopenobject","name","topLevelObject","_openObject","parser","emit","jsonpaths","jsonPaths","map","jsonpath","write","chunk","array","length","getPartialResult","getStreamingJsonPath","getStreamingJsonPathAsString","toString","currentPath","jsonPath","equals"],"sources":["../../../../src/lib/parser/streaming-json-parser.ts"],"sourcesContent":["import {default as JSONParser} from './json-parser';\nimport JSONPath from '../jsonpath/jsonpath';\n\n/**\n * The `StreamingJSONParser` looks for the first array in the JSON structure.\n * and emits an array of chunks\n */\nexport default class StreamingJSONParser extends JSONParser {\n private jsonPaths: JSONPath[];\n private streamingJsonPath: JSONPath | null = null;\n private streamingArray: any[] | null = null;\n private topLevelObject: object | null = null;\n\n constructor(options: {[key: string]: any} = {}) {\n super({\n onopenarray: () => {\n if (!this.streamingArray) {\n if (this._matchJSONPath()) {\n // @ts-ignore\n this.streamingJsonPath = this.getJsonPath().clone();\n this.streamingArray = [];\n this._openArray(this.streamingArray as []);\n return;\n }\n }\n\n this._openArray();\n },\n\n // Redefine onopenarray to inject value for top-level object\n onopenobject: (name) => {\n if (!this.topLevelObject) {\n this.topLevelObject = {};\n this._openObject(this.topLevelObject);\n } else {\n this._openObject({});\n }\n if (typeof name !== 'undefined') {\n this.parser.emit('onkey', name);\n }\n }\n });\n const jsonpaths = options.jsonpaths || [];\n this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));\n }\n\n /**\n * write REDEFINITION\n * - super.write() chunk to parser\n * - get the contents (so far) of \"topmost-level\" array as batch of rows\n * - clear top-level array\n * - return the batch of rows\\\n */\n write(chunk) {\n super.write(chunk);\n let array: any[] = [];\n if (this.streamingArray) {\n array = [...this.streamingArray];\n this.streamingArray.length = 0;\n }\n return array;\n }\n\n /**\n * Returns a partially formed result object\n * Useful for returning the \"wrapper\" object when array is not top level\n * e.g. GeoJSON\n */\n getPartialResult() {\n return this.topLevelObject;\n }\n\n getStreamingJsonPath() {\n return this.streamingJsonPath;\n }\n\n getStreamingJsonPathAsString() {\n return this.streamingJsonPath && this.streamingJsonPath.toString();\n }\n\n getJsonPath() {\n return this.jsonpath;\n }\n\n // PRIVATE METHODS\n\n /**\n * Checks is this.getJsonPath matches the jsonpaths provided in options\n */\n _matchJSONPath() {\n const currentPath = this.getJsonPath();\n // console.debug(`Testing JSONPath`, currentPath);\n\n // Backwards compatibility, match any array\n // TODO implement using wildcard once that is supported\n if (this.jsonPaths.length === 0) {\n return true;\n }\n\n for (const jsonPath of this.jsonPaths) {\n if (jsonPath.equals(currentPath)) {\n return true;\n }\n }\n\n return false;\n }\n}\n"],"mappings":";AAAA,SAAQA,OAAO,IAAIC,UAAU,QAAO,eAAe;AACnD,OAAOC,QAAQ,MAAM,sBAAsB;;AAM3C,eAAe,MAAMC,mBAAmB,SAASF,UAAU,CAAC;EAM1DG,WAAW,GAAqC;IAAA,IAApCC,OAA6B,uEAAG,CAAC,CAAC;IAC5C,KAAK,CAAC;MACJC,WAAW,EAAE,MAAM;QACjB,IAAI,CAAC,IAAI,CAACC,cAAc,EAAE;UACxB,IAAI,IAAI,CAACC,cAAc,EAAE,EAAE;YAEzB,IAAI,CAACC,iBAAiB,GAAG,IAAI,CAACC,WAAW,EAAE,CAACC,KAAK,EAAE;YACnD,IAAI,CAACJ,cAAc,GAAG,EAAE;YACxB,IAAI,CAACK,UAAU,CAAC,IAAI,CAACL,cAAc,CAAO;YAC1C;UACF;QACF;QAEA,IAAI,CAACK,UAAU,EAAE;MACnB,CAAC;MAGDC,YAAY,EAAGC,IAAI,IAAK;QACtB,IAAI,CAAC,IAAI,CAACC,cAAc,EAAE;UACxB,IAAI,CAACA,cAAc,GAAG,CAAC,CAAC;UACxB,IAAI,CAACC,WAAW,CAAC,IAAI,CAACD,cAAc,CAAC;QACvC,CAAC,MAAM;UACL,IAAI,CAACC,WAAW,CAAC,CAAC,CAAC,CAAC;QACtB;QACA,IAAI,OAAOF,IAAI,KAAK,WAAW,EAAE;UAC/B,IAAI,CAACG,MAAM,CAACC,IAAI,CAAC,OAAO,EAAEJ,IAAI,CAAC;QACjC;MACF;IACF,CA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DJSONInBatches from './lib/parse-ndjson-in-batches';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
const VERSION = typeof "3.3.0-alpha.6" !== 'undefined' ? "3.3.0-alpha.6" : 'latest';
|
|
4
5
|
const DEFAULT_NDGEOJSON_LOADER_OPTIONS = {
|
|
5
6
|
geojson: {
|
|
6
7
|
shape: 'object-row-table'
|
|
@@ -15,7 +16,8 @@ export const NDJSONLoader = {
|
|
|
15
16
|
module: 'json',
|
|
16
17
|
version: VERSION,
|
|
17
18
|
extensions: ['ndjson', 'ndgeojson'],
|
|
18
|
-
mimeTypes: ['application/geo+x-ndjson', 'application/geo+x-ldjson', 'application/jsonlines',
|
|
19
|
+
mimeTypes: ['application/geo+x-ndjson', 'application/geo+x-ldjson', 'application/jsonlines',
|
|
20
|
+
'application/geo+json-seq', 'application/x-ndjson'],
|
|
19
21
|
category: 'table',
|
|
20
22
|
text: true,
|
|
21
23
|
parse: async arrayBuffer => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ndjgeoson-loader.js","names":["parseNDJSONSync","parseNDJSONInBatches","VERSION","DEFAULT_NDGEOJSON_LOADER_OPTIONS","geojson","shape","gis","format","NDJSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parse","arrayBuffer","TextDecoder","decode","parseTextSync","parseInBatches","options","_typecheckNDJSONLoader"],"sources":["../../src/ndjgeoson-loader.ts"],"sourcesContent":["import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport parseNDJSONSync from './lib/parse-ndjson';\nimport parseNDJSONInBatches from './lib/parse-ndjson-in-batches';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type NDGeoJSONLoaderOptions = LoaderOptions & {\n geojson?: {\n shape?: 'object-row-table';\n };\n gis?: {\n format: 'geojson';\n };\n};\n\nconst DEFAULT_NDGEOJSON_LOADER_OPTIONS = {\n geojson: {\n shape: 'object-row-table'\n },\n gis: {\n format: 'geojson'\n }\n};\n\nexport const NDJSONLoader = {\n name: 'NDJSON',\n id: 'ndjson',\n module: 'json',\n version: VERSION,\n extensions: ['ndjson', 'ndgeojson'],\n mimeTypes: [\n 'application/geo+x-ndjson',\n 'application/geo+x-ldjson',\n 'application/jsonlines', // https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#cm-batch\n 'application/geo+json-seq',\n 'application/x-ndjson'\n ],\n category: 'table',\n text: true,\n parse: async (arrayBuffer: ArrayBuffer) => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),\n parseTextSync: parseNDJSONSync,\n parseInBatches: parseNDJSONInBatches,\n options: DEFAULT_NDGEOJSON_LOADER_OPTIONS\n};\n\nexport const _typecheckNDJSONLoader: LoaderWithParser = NDJSONLoader;\n"],"mappings":"AACA,OAAOA,eAAe,MAAM,oBAAoB;AAChD,OAAOC,oBAAoB,MAAM,+BAA+B;;AAIhE,MAAMC,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAW3E,MAAMC,gCAAgC,GAAG;EACvCC,OAAO,EAAE;IACPC,KAAK,EAAE;EACT,CAAC;EACDC,GAAG,EAAE;IACHC,MAAM,EAAE;EACV;AACF,CAAC;AAED,OAAO,MAAMC,YAAY,GAAG;EAC1BC,IAAI,EAAE,QAAQ;EACdC,EAAE,EAAE,QAAQ;EACZC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEV,OAAO;EAChBW,UAAU,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;EACnCC,SAAS,EAAE,CACT,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB;EACvB,0BAA0B,EAC1B,sBAAsB,CACvB;EACDC,QAAQ,EAAE,OAAO;EACjBC,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE,MAAOC,WAAwB,IAAKlB,eAAe,CAAC,IAAImB,WAAW,EAAE,CAACC,MAAM,CAACF,WAAW,CAAC,CAAC;EACjGG,aAAa,EAAErB,eAAe;EAC9BsB,cAAc,EAAErB,oBAAoB;EACpCsB,OAAO,EAAEpB;AACX,CAAC;AAED,OAAO,MAAMqB,sBAAwC,GAAGhB,YAAY"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import parseNDJSONSync from './lib/parse-ndjson';
|
|
2
2
|
import parseNDJSONInBatches from './lib/parse-ndjson-in-batches';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
const VERSION = typeof "3.3.0-alpha.6" !== 'undefined' ? "3.3.0-alpha.6" : 'latest';
|
|
4
5
|
export const NDJSONLoader = {
|
|
5
6
|
name: 'NDJSON',
|
|
6
7
|
id: 'ndjson',
|
|
7
8
|
module: 'json',
|
|
8
9
|
version: VERSION,
|
|
9
10
|
extensions: ['ndjson', 'jsonl'],
|
|
10
|
-
mimeTypes: ['application/x-ndjson', 'application/jsonlines',
|
|
11
|
+
mimeTypes: ['application/x-ndjson', 'application/jsonlines',
|
|
12
|
+
'application/json-seq'],
|
|
11
13
|
category: 'table',
|
|
12
14
|
text: true,
|
|
13
15
|
parse: async arrayBuffer => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),
|