@loaders.gl/json 3.1.0-alpha.4 → 4.0.0-alpha.1
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/{esm/bundle.js → bundle.js} +0 -0
- package/dist/bundle.js.map +1 -0
- package/dist/{esm/geojson-loader.js → geojson-loader.js} +1 -1
- package/dist/geojson-loader.js.map +1 -0
- package/dist/geojson-worker.js +1702 -2
- package/dist/{esm/index.js → index.js} +0 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/json-loader.js → json-loader.js} +1 -1
- package/dist/json-loader.js.map +1 -0
- package/dist/{esm/jsonl-loader.js → jsonl-loader.js} +0 -0
- package/dist/{es5/jsonl-loader.js.map → jsonl-loader.js.map} +0 -0
- package/dist/{es5/lib → lib}/clarinet/LICENSE +0 -0
- package/dist/lib/clarinet/clarinet.js +518 -0
- package/dist/lib/clarinet/clarinet.js.map +1 -0
- package/dist/{esm/lib → lib}/jsonpath/jsonpath.js +0 -0
- package/dist/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/{esm/lib → lib}/parse-json-in-batches.js +0 -0
- package/dist/lib/parse-json-in-batches.js.map +1 -0
- package/dist/{esm/lib → lib}/parse-json.js +0 -0
- package/dist/lib/parse-json.js.map +1 -0
- package/dist/{esm/lib → lib}/parse-ndjson-in-batches.js +1 -1
- package/dist/lib/parse-ndjson-in-batches.js.map +1 -0
- package/dist/{esm/lib → lib}/parse-ndjson.js +1 -1
- package/dist/lib/parse-ndjson.js.map +1 -0
- package/dist/{esm/lib → lib}/parser/json-parser.js +48 -47
- package/dist/lib/parser/json-parser.js.map +1 -0
- package/dist/{esm/lib → lib}/parser/streaming-json-parser.js +29 -34
- package/dist/lib/parser/streaming-json-parser.js.map +1 -0
- package/dist/{esm/ndjson-loader.js → ndjson-loader.js} +3 -1
- package/dist/ndjson-loader.js.map +1 -0
- package/dist/{esm/workers → workers}/geojson-worker.js +0 -0
- package/dist/workers/geojson-worker.js.map +1 -0
- package/package.json +9 -9
- package/src/lib/clarinet/clarinet.ts +539 -0
- package/src/lib/parser/json-parser.ts +52 -55
- package/src/lib/parser/streaming-json-parser.ts +28 -32
- package/src/ndjson-loader.ts +3 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/es5/bundle.js +0 -7
- package/dist/es5/bundle.js.map +0 -1
- package/dist/es5/geojson-loader.js +0 -209
- package/dist/es5/geojson-loader.js.map +0 -1
- package/dist/es5/index.js +0 -54
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/json-loader.js +0 -85
- package/dist/es5/json-loader.js.map +0 -1
- package/dist/es5/jsonl-loader.js +0 -2
- package/dist/es5/lib/clarinet/clarinet.js +0 -586
- package/dist/es5/lib/clarinet/clarinet.js.map +0 -1
- package/dist/es5/lib/jsonpath/jsonpath.js +0 -144
- package/dist/es5/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/es5/lib/parse-json-in-batches.js +0 -258
- package/dist/es5/lib/parse-json-in-batches.js.map +0 -1
- package/dist/es5/lib/parse-json.js +0 -46
- package/dist/es5/lib/parse-json.js.map +0 -1
- package/dist/es5/lib/parse-ndjson-in-batches.js +0 -158
- package/dist/es5/lib/parse-ndjson-in-batches.js.map +0 -1
- package/dist/es5/lib/parse-ndjson.js +0 -18
- package/dist/es5/lib/parse-ndjson.js.map +0 -1
- package/dist/es5/lib/parser/json-parser.js +0 -160
- package/dist/es5/lib/parser/json-parser.js.map +0 -1
- package/dist/es5/lib/parser/streaming-json-parser.js +0 -167
- package/dist/es5/lib/parser/streaming-json-parser.js.map +0 -1
- package/dist/es5/ndjson-loader.js +0 -64
- package/dist/es5/ndjson-loader.js.map +0 -1
- package/dist/es5/workers/geojson-worker.js +0 -8
- package/dist/es5/workers/geojson-worker.js.map +0 -1
- package/dist/esm/bundle.js.map +0 -1
- package/dist/esm/geojson-loader.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-loader.js.map +0 -1
- package/dist/esm/jsonl-loader.js.map +0 -1
- package/dist/esm/lib/clarinet/LICENSE +0 -28
- package/dist/esm/lib/clarinet/clarinet.js +0 -556
- package/dist/esm/lib/clarinet/clarinet.js.map +0 -1
- package/dist/esm/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/esm/lib/parse-json-in-batches.js.map +0 -1
- package/dist/esm/lib/parse-json.js.map +0 -1
- package/dist/esm/lib/parse-ndjson-in-batches.js.map +0 -1
- package/dist/esm/lib/parse-ndjson.js.map +0 -1
- package/dist/esm/lib/parser/json-parser.js.map +0 -1
- package/dist/esm/lib/parser/streaming-json-parser.js.map +0 -1
- package/dist/esm/ndjson-loader.js.map +0 -1
- package/dist/esm/workers/geojson-worker.js.map +0 -1
- package/dist/geojson-worker.js.map +0 -1
- package/src/lib/clarinet/clarinet.js +0 -578
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/parse-json.ts"],"names":["parseJSONSync","jsonText","options","json","JSON","parse","table","getFirstArray","error","Error","Array","isArray","value","Object","values","array"],"mappings":"AAEA,eAAe,SAASA,aAAT,CAAuBC,QAAvB,EAAyCC,OAAzC,EAAqE;AAClF,MAAI;AAAA;;AACF,UAAMC,IAAI,GAAGC,IAAI,CAACC,KAAL,CAAWJ,QAAX,CAAb;;AACA,yBAAIC,OAAO,CAACC,IAAZ,0CAAI,cAAcG,KAAlB,EAAyB;AACvB,aAAOC,aAAa,CAACJ,IAAD,CAAb,IAAuBA,IAA9B;AACD;;AACD,WAAOA,IAAP;AACD,GAND,CAME,OAAOK,KAAP,EAAc;AACd,UAAM,IAAIC,KAAJ,CAAU,kCAAV,CAAN;AACD;AACF;;AAED,SAASF,aAAT,CAAuBJ,IAAvB,EAA6B;AAC3B,MAAIO,KAAK,CAACC,OAAN,CAAcR,IAAd,CAAJ,EAAyB;AACvB,WAAOA,IAAP;AACD;;AACD,MAAIA,IAAI,IAAI,OAAOA,IAAP,KAAgB,QAA5B,EAAsC;AACpC,SAAK,MAAMS,KAAX,IAAoBC,MAAM,CAACC,MAAP,CAAcX,IAAd,CAApB,EAAyC;AACvC,YAAMY,KAAK,GAAGR,aAAa,CAACK,KAAD,CAA3B;;AACA,UAAIG,KAAJ,EAAW;AACT,eAAOA,KAAP;AACD;AACF;AACF;;AACD,SAAO,IAAP;AACD","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"],"file":"parse-json.js"}
|
|
@@ -24,7 +24,7 @@ export default async function* parseNDJSONInBatches(binaryAsyncIterator, options
|
|
|
24
24
|
yield batch;
|
|
25
25
|
}
|
|
26
26
|
} catch (error) {
|
|
27
|
-
throw new Error(
|
|
27
|
+
throw new Error("NDJSONLoader: failed to parse JSON on line ".concat(counter));
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/parse-ndjson-in-batches.ts"],"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"],"mappings":"AACA,SAAQA,iBAAR,QAAgC,oBAAhC;AACA,SAEEC,gBAFF,EAGEC,wBAHF,EAIEC,uBAJF,QAKO,0BALP;AAOA,eAAe,gBAAgBC,oBAAhB,CACbC,mBADa,EAEbC,OAFa,EAGS;AACtB,QAAMC,YAAY,GAAGJ,uBAAuB,CAACE,mBAAD,CAA5C;AACA,QAAMG,YAAY,GAAGP,gBAAgB,CAACM,YAAD,CAArC;AACA,QAAME,oBAAoB,GAAGP,wBAAwB,CAACM,YAAD,CAArD;AAEA,QAAME,MAAM,GAAG,IAAf;AACA,QAAMC,KAAK,GAAG,WAAd;AAEA,QAAMC,iBAAiB,GAAG,IAAIZ,iBAAJ,CAAsBU,MAAtB,EAA8B,EACtD,GAAGJ,OADmD;AAEtDK,IAAAA;AAFsD,GAA9B,CAA1B;;AAKA,aAAW,MAAM;AAACE,IAAAA,OAAD;AAAUC,IAAAA;AAAV,GAAjB,IAAoCL,oBAApC,EAA0D;AACxD,QAAI;AACF,YAAMM,GAAG,GAAGC,IAAI,CAACC,KAAL,CAAWH,IAAX,CAAZ;AACAF,MAAAA,iBAAiB,CAACM,MAAlB,CAAyBH,GAAzB;AACAH,MAAAA,iBAAiB,CAACO,aAAlB,CAAgCL,IAAhC;AACA,YAAMM,KAAK,GAAGR,iBAAiB,CAACS,YAAlB,EAAd;;AACA,UAAID,KAAJ,EAAW;AACT,cAAMA,KAAN;AACD;AACF,KARD,CAQE,OAAOE,KAAP,EAAc;AACd,YAAM,IAAIC,KAAJ,sDAAwDV,OAAxD,EAAN;AACD;AACF;;AAED,QAAMO,KAAK,GAAGR,iBAAiB,CAACY,aAAlB,EAAd;;AACA,MAAIJ,KAAJ,EAAW;AACT,UAAMA,KAAN;AACD;AACF","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"],"file":"parse-ndjson-in-batches.js"}
|
|
@@ -4,7 +4,7 @@ export default function parseNDJSONSync(ndjsonText) {
|
|
|
4
4
|
try {
|
|
5
5
|
return JSON.parse(line);
|
|
6
6
|
} catch (error) {
|
|
7
|
-
throw new Error(
|
|
7
|
+
throw new Error("NDJSONLoader: failed to parse JSON on line ".concat(counter + 1));
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
10
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/lib/parse-ndjson.ts"],"names":["parseNDJSONSync","ndjsonText","lines","trim","split","map","line","counter","JSON","parse","error","Error"],"mappings":"AAAA,eAAe,SAASA,eAAT,CAAyBC,UAAzB,EAA6C;AAC1D,QAAMC,KAAK,GAAGD,UAAU,CAACE,IAAX,GAAkBC,KAAlB,CAAwB,IAAxB,CAAd;AACA,SAAOF,KAAK,CAACG,GAAN,CAAU,CAACC,IAAD,EAAOC,OAAP,KAAmB;AAClC,QAAI;AACF,aAAOC,IAAI,CAACC,KAAL,CAAWH,IAAX,CAAP;AACD,KAFD,CAEE,OAAOI,KAAP,EAAc;AACd,YAAM,IAAIC,KAAJ,sDAAwDJ,OAAO,GAAG,CAAlE,EAAN;AACD;AACF,GANM,CAAP;AAOD","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"],"file":"parse-ndjson.js"}
|
|
@@ -2,14 +2,58 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
2
2
|
import ClarinetParser from '../clarinet/clarinet';
|
|
3
3
|
import JSONPath from '../jsonpath/jsonpath';
|
|
4
4
|
export default class JSONParser {
|
|
5
|
-
constructor() {
|
|
6
|
-
_defineProperty(this, "
|
|
5
|
+
constructor(options) {
|
|
6
|
+
_defineProperty(this, "parser", void 0);
|
|
7
7
|
|
|
8
|
-
_defineProperty(this, "
|
|
8
|
+
_defineProperty(this, "result", undefined);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "previousStates", []);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "currentState", Object.freeze({
|
|
13
|
+
container: [],
|
|
14
|
+
key: null
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
_defineProperty(this, "jsonpath", new JSONPath());
|
|
9
18
|
|
|
10
19
|
this.reset();
|
|
20
|
+
this.parser = new ClarinetParser({
|
|
21
|
+
onready: () => {
|
|
22
|
+
this.jsonpath = new JSONPath();
|
|
23
|
+
this.previousStates.length = 0;
|
|
24
|
+
this.currentState.container.length = 0;
|
|
25
|
+
},
|
|
26
|
+
onopenobject: name => {
|
|
27
|
+
this._openObject({});
|
|
11
28
|
|
|
12
|
-
|
|
29
|
+
if (typeof name !== 'undefined') {
|
|
30
|
+
this.parser.emit('onkey', name);
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
onkey: name => {
|
|
34
|
+
this.jsonpath.set(name);
|
|
35
|
+
this.currentState.key = name;
|
|
36
|
+
},
|
|
37
|
+
oncloseobject: () => {
|
|
38
|
+
this._closeObject();
|
|
39
|
+
},
|
|
40
|
+
onopenarray: () => {
|
|
41
|
+
this._openArray();
|
|
42
|
+
},
|
|
43
|
+
onclosearray: () => {
|
|
44
|
+
this._closeArray();
|
|
45
|
+
},
|
|
46
|
+
onvalue: value => {
|
|
47
|
+
this._pushOrSet(value);
|
|
48
|
+
},
|
|
49
|
+
onerror: error => {
|
|
50
|
+
throw error;
|
|
51
|
+
},
|
|
52
|
+
onend: () => {
|
|
53
|
+
this.result = this.currentState.container.pop();
|
|
54
|
+
},
|
|
55
|
+
...options
|
|
56
|
+
});
|
|
13
57
|
}
|
|
14
58
|
|
|
15
59
|
reset() {
|
|
@@ -80,48 +124,5 @@ export default class JSONParser {
|
|
|
80
124
|
this.currentState = this.previousStates.pop();
|
|
81
125
|
}
|
|
82
126
|
|
|
83
|
-
_initializeParser() {
|
|
84
|
-
this._parser = new ClarinetParser({
|
|
85
|
-
onready: () => {
|
|
86
|
-
this.jsonpath = new JSONPath();
|
|
87
|
-
this.previousStates.length = 0;
|
|
88
|
-
this.currentState.container.length = 0;
|
|
89
|
-
},
|
|
90
|
-
onopenobject: name => {
|
|
91
|
-
this._openObject({});
|
|
92
|
-
|
|
93
|
-
if (typeof name !== 'undefined') {
|
|
94
|
-
this.parser.onkey(name);
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
onkey: name => {
|
|
98
|
-
this.jsonpath.set(name);
|
|
99
|
-
this.currentState.key = name;
|
|
100
|
-
},
|
|
101
|
-
oncloseobject: () => {
|
|
102
|
-
this._closeObject();
|
|
103
|
-
},
|
|
104
|
-
onopenarray: () => {
|
|
105
|
-
this._openArray();
|
|
106
|
-
},
|
|
107
|
-
onclosearray: () => {
|
|
108
|
-
this._closeArray();
|
|
109
|
-
},
|
|
110
|
-
onvalue: value => {
|
|
111
|
-
this._pushOrSet(value);
|
|
112
|
-
},
|
|
113
|
-
onerror: error => {
|
|
114
|
-
throw error;
|
|
115
|
-
},
|
|
116
|
-
onend: () => {
|
|
117
|
-
this.result = this.currentState.container.pop();
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
get parser() {
|
|
123
|
-
return this._parser;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
127
|
}
|
|
127
128
|
//# sourceMappingURL=json-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/parser/json-parser.ts"],"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"],"mappings":";AAEA,OAAOA,cAAP,MAAoD,sBAApD;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAIA,eAAe,MAAMC,UAAN,CAAiB;AAO9BC,EAAAA,WAAW,CAACC,OAAD,EAAiC;AAAA;;AAAA,oCALnCC,SAKmC;;AAAA,4CAJ3B,EAI2B;;AAAA,0CAH7BC,MAAM,CAACC,MAAP,CAAc;AAACC,MAAAA,SAAS,EAAE,EAAZ;AAAgBC,MAAAA,GAAG,EAAE;AAArB,KAAd,CAG6B;;AAAA,sCAFvB,IAAIR,QAAJ,EAEuB;;AAC1C,SAAKS,KAAL;AACA,SAAKC,MAAL,GAAc,IAAIX,cAAJ,CAAmB;AAC/BY,MAAAA,OAAO,EAAE,MAAM;AACb,aAAKC,QAAL,GAAgB,IAAIZ,QAAJ,EAAhB;AACA,aAAKa,cAAL,CAAoBC,MAApB,GAA6B,CAA7B;AACA,aAAKC,YAAL,CAAkBR,SAAlB,CAA4BO,MAA5B,GAAqC,CAArC;AACD,OAL8B;AAO/BE,MAAAA,YAAY,EAAGC,IAAD,IAAU;AACtB,aAAKC,WAAL,CAAiB,EAAjB;;AACA,YAAI,OAAOD,IAAP,KAAgB,WAApB,EAAiC;AAC/B,eAAKP,MAAL,CAAYS,IAAZ,CAAiB,OAAjB,EAA0BF,IAA1B;AACD;AACF,OAZ8B;AAc/BG,MA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';\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"],"file":"json-parser.js"}
|
|
@@ -3,7 +3,35 @@ import { default as JSONParser } from './json-parser';
|
|
|
3
3
|
import JSONPath from '../jsonpath/jsonpath';
|
|
4
4
|
export default class StreamingJSONParser extends JSONParser {
|
|
5
5
|
constructor(options = {}) {
|
|
6
|
-
super(
|
|
6
|
+
super({
|
|
7
|
+
onopenarray: () => {
|
|
8
|
+
if (!this.streamingArray) {
|
|
9
|
+
if (this._matchJSONPath()) {
|
|
10
|
+
this.streamingJsonPath = this.getJsonPath().clone();
|
|
11
|
+
this.streamingArray = [];
|
|
12
|
+
|
|
13
|
+
this._openArray(this.streamingArray);
|
|
14
|
+
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this._openArray();
|
|
20
|
+
},
|
|
21
|
+
onopenobject: name => {
|
|
22
|
+
if (!this.topLevelObject) {
|
|
23
|
+
this.topLevelObject = {};
|
|
24
|
+
|
|
25
|
+
this._openObject(this.topLevelObject);
|
|
26
|
+
} else {
|
|
27
|
+
this._openObject({});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (typeof name !== 'undefined') {
|
|
31
|
+
this.parser.emit('onkey', name);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
7
35
|
|
|
8
36
|
_defineProperty(this, "jsonPaths", void 0);
|
|
9
37
|
|
|
@@ -15,8 +43,6 @@ export default class StreamingJSONParser extends JSONParser {
|
|
|
15
43
|
|
|
16
44
|
const jsonpaths = options.jsonpaths || [];
|
|
17
45
|
this.jsonPaths = jsonpaths.map(jsonpath => new JSONPath(jsonpath));
|
|
18
|
-
|
|
19
|
-
this._extendParser();
|
|
20
46
|
}
|
|
21
47
|
|
|
22
48
|
write(chunk) {
|
|
@@ -63,36 +89,5 @@ export default class StreamingJSONParser extends JSONParser {
|
|
|
63
89
|
return false;
|
|
64
90
|
}
|
|
65
91
|
|
|
66
|
-
_extendParser() {
|
|
67
|
-
this.parser.onopenarray = () => {
|
|
68
|
-
if (!this.streamingArray) {
|
|
69
|
-
if (this._matchJSONPath()) {
|
|
70
|
-
this.streamingJsonPath = this.getJsonPath().clone();
|
|
71
|
-
this.streamingArray = [];
|
|
72
|
-
|
|
73
|
-
this._openArray(this.streamingArray);
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this._openArray();
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
this.parser.onopenobject = name => {
|
|
83
|
-
if (!this.topLevelObject) {
|
|
84
|
-
this.topLevelObject = {};
|
|
85
|
-
|
|
86
|
-
this._openObject(this.topLevelObject);
|
|
87
|
-
} else {
|
|
88
|
-
this._openObject({});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (typeof name !== 'undefined') {
|
|
92
|
-
this.parser.onkey(name);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
92
|
}
|
|
98
93
|
//# sourceMappingURL=streaming-json-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/parser/streaming-json-parser.ts"],"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"],"mappings":";AAAA,SAAQA,OAAO,IAAIC,UAAnB,QAAoC,eAApC;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAMA,eAAe,MAAMC,mBAAN,SAAkCF,UAAlC,CAA6C;AAM1DG,EAAAA,WAAW,CAACC,OAA6B,GAAG,EAAjC,EAAqC;AAC9C,UAAM;AACJC,MAAAA,WAAW,EAAE,MAAM;AACjB,YAAI,CAAC,KAAKC,cAAV,EAA0B;AAC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BAA4B,GAAG;AAC7B,WAAO,KAAKpB,iBAAL,IAA0B,KAAKA,iBAAL,CAAuBqB,QAAvB,EAAjC;AACD;;AAEDpB,EAAAA,WAAW,GAAG;AACZ,WAAO,KAAKY,QAAZ;AACD;;AAODd,EAAAA,cAAc,GAAG;AACf,UAAMuB,WAAW,GAAG,KAAKrB,WAAL,EAApB;;AAKA,QAAI,KAAKU,SAAL,CAAeM,MAAf,KAA0B,CAA9B,EAAiC;AAC/B,aAAO,IAAP;AACD;;AAED,SAAK,MAAMM,QAAX,IAAuB,KAAKZ,SAA5B,EAAuC;AACrC,UAAIY,QAAQ,CAACC,MAAT,CAAgBF,WAAhB,CAAJ,EAAkC;AAChC,eAAO,IAAP;AACD;AACF;;AAED,WAAO,KAAP;AACD;;AAnGyD","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"],"file":"streaming-json-parser.js"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import parseNDJSONSync from './lib/parse-ndjson';
|
|
2
2
|
import parseNDJSONInBatches from './lib/parse-ndjson-in-batches';
|
|
3
|
-
const VERSION = typeof "
|
|
3
|
+
const VERSION = typeof "4.0.0-alpha.1" !== 'undefined' ? "4.0.0-alpha.1" : 'latest';
|
|
4
4
|
export const NDJSONLoader = {
|
|
5
5
|
name: 'NDJSON',
|
|
6
6
|
id: 'ndjson',
|
|
@@ -27,4 +27,6 @@ function parseTextSync(text) {
|
|
|
27
27
|
function parseInBatches(asyncIterator, options) {
|
|
28
28
|
return parseNDJSONInBatches(asyncIterator, options);
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
export const _typecheckNDJSONLoader = NDJSONLoader;
|
|
30
32
|
//# sourceMappingURL=ndjson-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ndjson-loader.ts"],"names":["parseNDJSONSync","parseNDJSONInBatches","VERSION","NDJSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parse","parseTextSync","parseInBatches","options","arrayBuffer","TextDecoder","decode","asyncIterator","_typecheckNDJSONLoader"],"mappings":"AAEA,OAAOA,eAAP,MAA4B,oBAA5B;AACA,OAAOC,oBAAP,MAAiC,+BAAjC;AAIA,MAAMC,OAAO,GAAG,2BAAuB,WAAvB,qBAAmD,QAAnE;AAEA,OAAO,MAAMC,YAAY,GAAG;AAC1BC,EAAAA,IAAI,EAAE,QADoB;AAE1BC,EAAAA,EAAE,EAAE,QAFsB;AAG1BC,EAAAA,MAAM,EAAE,MAHkB;AAI1BC,EAAAA,OAAO,EAAEL,OAJiB;AAK1BM,EAAAA,UAAU,EAAE,CAAC,QAAD,CALc;AAM1BC,EAAAA,SAAS,EAAE,CAAC,sBAAD,CANe;AAO1BC,EAAAA,QAAQ,EAAE,OAPgB;AAQ1BC,EAAAA,IAAI,EAAE,IARoB;AAS1BC,EAAAA,KAT0B;AAU1BC,EAAAA,aAV0B;AAW1BC,EAAAA,cAX0B;AAY1BC,EAAAA,OAAO,EAAE;AAZiB,CAArB;;AAeP,eAAeH,KAAf,CAAqBI,WAArB,EAA+C;AAC7C,SAAOH,aAAa,CAAC,IAAII,WAAJ,GAAkBC,MAAlB,CAAyBF,WAAzB,CAAD,CAApB;AACD;;AAED,SAASH,aAAT,CAAuBF,IAAvB,EAAqC;AACnC,SAAOX,eAAe,CAACW,IAAD,CAAtB;AACD;;AAED,SAASG,cAAT,CACEK,aADF,EAEEJ,OAFF,EAGwB;AACtB,SAAOd,oBAAoB,CAACkB,aAAD,EAAgBJ,OAAhB,CAA3B;AACD;;AAED,OAAO,MAAMK,sBAAwC,GAAGjB,YAAjD","sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport 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 const NDJSONLoader = {\n name: 'NDJSON',\n id: 'ndjson',\n module: 'json',\n version: VERSION,\n extensions: ['ndjson'],\n mimeTypes: ['application/x-ndjson'],\n category: 'table',\n text: true,\n parse,\n parseTextSync,\n parseInBatches,\n options: {}\n};\n\nasync function parse(arrayBuffer: ArrayBuffer) {\n return parseTextSync(new TextDecoder().decode(arrayBuffer));\n}\n\nfunction parseTextSync(text: string) {\n return parseNDJSONSync(text);\n}\n\nfunction parseInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: LoaderOptions\n): AsyncIterable<Batch> {\n return parseNDJSONInBatches(asyncIterator, options);\n}\n\nexport const _typecheckNDJSONLoader: LoaderWithParser = NDJSONLoader;\n"],"file":"ndjson-loader.js"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/workers/geojson-worker.ts"],"names":["createLoaderWorker","GeoJSONLoader"],"mappings":"AAAA,SAAQA,kBAAR,QAAiC,0BAAjC;AACA,SAAQC,aAAR,QAA4B,mBAA5B;AAEAD,kBAAkB,CAACC,aAAD,CAAlB","sourcesContent":["import {createLoaderWorker} from '@loaders.gl/loader-utils';\nimport {GeoJSONLoader} from '../geojson-loader';\n\ncreateLoaderWorker(GeoJSONLoader);\n"],"file":"geojson-worker.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/json",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.1",
|
|
4
4
|
"description": "Framework-independent loader for JSON and streaming JSON formats",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"JSON async iterator"
|
|
22
22
|
],
|
|
23
23
|
"types": "src/index.ts",
|
|
24
|
-
"main": "dist/
|
|
25
|
-
"module": "dist/
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"module": "dist/index.js",
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"files": [
|
|
28
28
|
"src",
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"pre-build": "npm run build-bundle && npm run build-worker",
|
|
34
|
-
"build-bundle": "
|
|
35
|
-
"build-worker": "
|
|
34
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/bundle.js",
|
|
35
|
+
"build-worker": "esbuild src/workers/geojson-worker.ts --bundle --outfile=dist/geojson-worker.js"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@loaders.gl/gis": "
|
|
39
|
-
"@loaders.gl/loader-utils": "
|
|
40
|
-
"@loaders.gl/schema": "
|
|
38
|
+
"@loaders.gl/gis": "4.0.0-alpha.1",
|
|
39
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.1",
|
|
40
|
+
"@loaders.gl/schema": "4.0.0-alpha.1"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "e48f5534fe7188c810f23f965a440c144b3cf6d0"
|
|
43
43
|
}
|