@loaders.gl/json 4.0.0-alpha.4 → 4.0.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/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/dist.min.js +2543 -0
- package/dist/geojson-loader.d.ts +16 -0
- package/dist/geojson-loader.d.ts.map +1 -0
- package/dist/geojson-loader.js +1 -1
- package/dist/geojson-worker.js +782 -181
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/json-loader.d.ts +14 -0
- package/dist/json-loader.d.ts.map +1 -0
- package/dist/json-loader.js +1 -1
- package/dist/jsonl-loader.d.ts +1 -0
- package/dist/jsonl-loader.d.ts.map +1 -0
- package/dist/lib/clarinet/clarinet.d.ts +74 -0
- package/dist/lib/clarinet/clarinet.d.ts.map +1 -0
- package/dist/lib/jsonpath/jsonpath.d.ts +32 -0
- package/dist/lib/jsonpath/jsonpath.d.ts.map +1 -0
- package/dist/lib/parse-json-in-batches.d.ts +5 -0
- package/dist/lib/parse-json-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-json-in-batches.js +18 -1
- package/dist/lib/parse-json-in-batches.js.map +1 -1
- package/dist/lib/parse-json.d.ts +3 -0
- package/dist/lib/parse-json.d.ts.map +1 -0
- package/dist/lib/parse-ndjson-in-batches.d.ts +4 -0
- package/dist/lib/parse-ndjson-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-ndjson.d.ts +2 -0
- package/dist/lib/parse-ndjson.d.ts.map +1 -0
- package/dist/lib/parser/json-parser.d.ts +22 -0
- package/dist/lib/parser/json-parser.d.ts.map +1 -0
- package/dist/lib/parser/streaming-json-parser.d.ts +37 -0
- package/dist/lib/parser/streaming-json-parser.d.ts.map +1 -0
- package/dist/ndjson-loader.d.ts +22 -0
- package/dist/ndjson-loader.d.ts.map +1 -0
- package/dist/ndjson-loader.js +1 -1
- package/dist/workers/geojson-worker.d.ts +2 -0
- package/dist/workers/geojson-worker.d.ts.map +1 -0
- package/package.json +8 -8
- package/src/index.ts +2 -0
- package/src/lib/parse-json-in-batches.ts +23 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { JSONLoaderOptions } from './json-loader';
|
|
2
|
+
export { JSONLoader } from './json-loader';
|
|
3
|
+
export { NDJSONLoader } from './ndjson-loader';
|
|
4
|
+
export type { GeoJSONLoaderOptions as _GeoJSONLoaderOptions } from './geojson-loader';
|
|
5
|
+
export { GeoJSONLoader as _GeoJSONLoader, GeoJSONWorkerLoader as _GeoJSONWorkerLoader } from './geojson-loader';
|
|
6
|
+
export { default as _JSONPath } from './lib/jsonpath/jsonpath';
|
|
7
|
+
export { default as _ClarinetParser } from './lib/clarinet/clarinet';
|
|
8
|
+
export { rebuildJsonObject as _rebuildJsonObject } from './lib/parse-json-in-batches';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC;AACzC,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAG7C,YAAY,EAAC,oBAAoB,IAAI,qBAAqB,EAAC,MAAM,kBAAkB,CAAC;AACpF,OAAO,EACL,aAAa,IAAI,cAAc,EAC/B,mBAAmB,IAAI,oBAAoB,EAC5C,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAEnE,OAAO,EAAC,iBAAiB,IAAI,kBAAkB,EAAC,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,4 +3,5 @@ export { NDJSONLoader } from './ndjson-loader';
|
|
|
3
3
|
export { GeoJSONLoader as _GeoJSONLoader, GeoJSONWorkerLoader as _GeoJSONWorkerLoader } from './geojson-loader';
|
|
4
4
|
export { default as _JSONPath } from './lib/jsonpath/jsonpath';
|
|
5
5
|
export { default as _ClarinetParser } from './lib/clarinet/clarinet';
|
|
6
|
+
export { rebuildJsonObject as _rebuildJsonObject } from './lib/parse-json-in-batches';
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["JSONLoader","NDJSONLoader","GeoJSONLoader","_GeoJSONLoader","GeoJSONWorkerLoader","_GeoJSONWorkerLoader","default","_JSONPath","_ClarinetParser"],"mappings":"AACA,SAAQA,UAAR,QAAyB,eAAzB;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AAIA,SACEC,aAAa,IAAIC,cADnB,EAEEC,mBAAmB,IAAIC,oBAFzB,QAGO,kBAHP;AAKA,SAAQC,OAAO,IAAIC,SAAnB,QAAmC,yBAAnC;AACA,SAAQD,OAAO,IAAIE,eAAnB,QAAyC,yBAAzC","sourcesContent":["export type {JSONLoaderOptions} from './json-loader';\nexport {JSONLoader} from './json-loader';\nexport {NDJSONLoader} from './ndjson-loader';\n\n// EXPERIMENTAL EXPORTS - WARNING: MAY BE REMOVED WIHTOUT NOTICE IN FUTURE RELEASES\nexport type {GeoJSONLoaderOptions as _GeoJSONLoaderOptions} from './geojson-loader';\nexport {\n GeoJSONLoader as _GeoJSONLoader,\n GeoJSONWorkerLoader as _GeoJSONWorkerLoader\n} from './geojson-loader';\n\nexport {default as _JSONPath} from './lib/jsonpath/jsonpath';\nexport {default as _ClarinetParser} from './lib/clarinet/clarinet';\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["JSONLoader","NDJSONLoader","GeoJSONLoader","_GeoJSONLoader","GeoJSONWorkerLoader","_GeoJSONWorkerLoader","default","_JSONPath","_ClarinetParser","rebuildJsonObject","_rebuildJsonObject"],"mappings":"AACA,SAAQA,UAAR,QAAyB,eAAzB;AACA,SAAQC,YAAR,QAA2B,iBAA3B;AAIA,SACEC,aAAa,IAAIC,cADnB,EAEEC,mBAAmB,IAAIC,oBAFzB,QAGO,kBAHP;AAKA,SAAQC,OAAO,IAAIC,SAAnB,QAAmC,yBAAnC;AACA,SAAQD,OAAO,IAAIE,eAAnB,QAAyC,yBAAzC;AAEA,SAAQC,iBAAiB,IAAIC,kBAA7B,QAAsD,6BAAtD","sourcesContent":["export type {JSONLoaderOptions} from './json-loader';\nexport {JSONLoader} from './json-loader';\nexport {NDJSONLoader} from './ndjson-loader';\n\n// EXPERIMENTAL EXPORTS - WARNING: MAY BE REMOVED WIHTOUT NOTICE IN FUTURE RELEASES\nexport type {GeoJSONLoaderOptions as _GeoJSONLoaderOptions} from './geojson-loader';\nexport {\n GeoJSONLoader as _GeoJSONLoader,\n GeoJSONWorkerLoader as _GeoJSONWorkerLoader\n} from './geojson-loader';\n\nexport {default as _JSONPath} from './lib/jsonpath/jsonpath';\nexport {default as _ClarinetParser} from './lib/clarinet/clarinet';\n\nexport {rebuildJsonObject as _rebuildJsonObject} from './lib/parse-json-in-batches';\n"],"file":"index.js"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
/**
|
|
3
|
+
* @param table -
|
|
4
|
+
* @param jsonpaths -
|
|
5
|
+
*/
|
|
6
|
+
export declare type JSONLoaderOptions = LoaderOptions & {
|
|
7
|
+
json?: {
|
|
8
|
+
shape?: 'row-table';
|
|
9
|
+
table?: false;
|
|
10
|
+
jsonpaths?: string[];
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const JSONLoader: LoaderWithParser;
|
|
14
|
+
//# sourceMappingURL=json-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-loader.d.ts","sourceRoot":"","sources":["../src/json-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAQ9E;;;GAGG;AACH,oBAAY,iBAAiB,GAAG,aAAa,GAAG;IAC9C,IAAI,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,WAAW,CAAC;QACpB,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;KACtB,CAAC;CACH,CAAC;AAWF,eAAO,MAAM,UAAU,EAAE,gBA0BxB,CAAC"}
|
package/dist/json-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import parseJSONSync from './lib/parse-json';
|
|
2
2
|
import parseJSONInBatches from './lib/parse-json-in-batches';
|
|
3
|
-
const VERSION = typeof "4.0.0-alpha.
|
|
3
|
+
const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
|
|
4
4
|
const DEFAULT_JSON_LOADER_OPTIONS = {
|
|
5
5
|
json: {
|
|
6
6
|
shape: 'row-table',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=jsonl-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonl-loader.d.ts","sourceRoot":"","sources":["../src/jsonl-loader.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export declare type ClarinetEvent = 'onvalue' | 'onstring' | 'onkey' | 'onopenobject' | 'oncloseobject' | 'onopenarray' | 'onclosearray' | 'onerror' | 'onend' | 'onready';
|
|
2
|
+
declare enum STATE {
|
|
3
|
+
BEGIN = 0,
|
|
4
|
+
VALUE = 1,
|
|
5
|
+
OPEN_OBJECT = 2,
|
|
6
|
+
CLOSE_OBJECT = 3,
|
|
7
|
+
OPEN_ARRAY = 4,
|
|
8
|
+
CLOSE_ARRAY = 5,
|
|
9
|
+
TEXT_ESCAPE = 6,
|
|
10
|
+
STRING = 7,
|
|
11
|
+
BACKSLASH = 8,
|
|
12
|
+
END = 9,
|
|
13
|
+
OPEN_KEY = 10,
|
|
14
|
+
CLOSE_KEY = 11,
|
|
15
|
+
TRUE = 12,
|
|
16
|
+
TRUE2 = 13,
|
|
17
|
+
TRUE3 = 14,
|
|
18
|
+
FALSE = 15,
|
|
19
|
+
FALSE2 = 16,
|
|
20
|
+
FALSE3 = 17,
|
|
21
|
+
FALSE4 = 18,
|
|
22
|
+
NULL = 19,
|
|
23
|
+
NULL2 = 20,
|
|
24
|
+
NULL3 = 21,
|
|
25
|
+
NUMBER_DECIMAL_POINT = 22,
|
|
26
|
+
NUMBER_DIGIT = 23
|
|
27
|
+
}
|
|
28
|
+
declare type ParserEvent = (parser: ClarinetParser, event: string, data?: any) => void;
|
|
29
|
+
export declare type ClarinetParserOptions = {
|
|
30
|
+
onready?: ParserEvent;
|
|
31
|
+
onopenobject?: ParserEvent;
|
|
32
|
+
onkey?: ParserEvent;
|
|
33
|
+
oncloseobject?: ParserEvent;
|
|
34
|
+
onopenarray?: ParserEvent;
|
|
35
|
+
onclosearray?: ParserEvent;
|
|
36
|
+
onvalue?: ParserEvent;
|
|
37
|
+
onerror?: ParserEvent;
|
|
38
|
+
onend?: ParserEvent;
|
|
39
|
+
onchunkparsed?: ParserEvent;
|
|
40
|
+
};
|
|
41
|
+
export default class ClarinetParser {
|
|
42
|
+
protected options: Required<ClarinetParserOptions>;
|
|
43
|
+
bufferCheckPosition: number;
|
|
44
|
+
q: string;
|
|
45
|
+
c: string;
|
|
46
|
+
p: string;
|
|
47
|
+
closed: boolean;
|
|
48
|
+
closedRoot: boolean;
|
|
49
|
+
sawRoot: boolean;
|
|
50
|
+
error: Error | null;
|
|
51
|
+
state: STATE;
|
|
52
|
+
stack: STATE[];
|
|
53
|
+
position: number;
|
|
54
|
+
column: number;
|
|
55
|
+
line: number;
|
|
56
|
+
slashed: boolean;
|
|
57
|
+
unicodeI: number;
|
|
58
|
+
unicodeS: string | null;
|
|
59
|
+
depth: number;
|
|
60
|
+
textNode: any;
|
|
61
|
+
numberNode: any;
|
|
62
|
+
constructor(options?: ClarinetParserOptions);
|
|
63
|
+
end(): this;
|
|
64
|
+
resume(): this;
|
|
65
|
+
close(): void | this;
|
|
66
|
+
emit(event: string, data?: any): void;
|
|
67
|
+
emitNode(event: string, data?: any): void;
|
|
68
|
+
write(chunk: any): void | this;
|
|
69
|
+
_closeValue(event?: string): void;
|
|
70
|
+
_closeNumber(): void;
|
|
71
|
+
_error(message?: string): void;
|
|
72
|
+
}
|
|
73
|
+
export {};
|
|
74
|
+
//# sourceMappingURL=clarinet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clarinet.d.ts","sourceRoot":"","sources":["../../../src/lib/clarinet/clarinet.ts"],"names":[],"mappings":"AAKA,oBAAY,aAAa,GACrB,SAAS,GACT,UAAU,GACV,OAAO,GACP,cAAc,GACd,eAAe,GACf,aAAa,GACb,cAAc,GACd,SAAS,GACT,OAAO,GACP,SAAS,CAAC;AAMd,aAAK,KAAK;IACR,KAAK,IAAI;IACT,KAAK,IAAA;IACL,WAAW,IAAA;IACX,YAAY,IAAA;IACZ,UAAU,IAAA;IACV,WAAW,IAAA;IACX,WAAW,IAAA;IACX,MAAM,IAAA;IACN,SAAS,IAAA;IACT,GAAG,IAAA;IACH,QAAQ,KAAA;IACR,SAAS,KAAA;IACT,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,KAAK,KAAA;IACL,KAAK,KAAA;IACL,MAAM,KAAA;IACN,MAAM,KAAA;IACN,MAAM,KAAA;IACN,IAAI,KAAA;IACJ,KAAK,KAAA;IACL,KAAK,KAAA;IACL,oBAAoB,KAAA;IACpB,YAAY,KAAA;CACb;AA0CD,aAAK,WAAW,GAAG,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;AAE/E,oBAAY,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,aAAa,CAAC,EAAE,WAAW,CAAC;CAC7B,CAAC;AAcF,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,SAAS,CAAC,OAAO,EAAE,QAAQ,CAAC,qBAAqB,CAAC,CAAmB;IAErE,mBAAmB,SAAqB;IACxC,CAAC,SAAM;IACP,CAAC,SAAM;IACP,CAAC,SAAM;IACP,MAAM,UAAS;IACf,UAAU,UAAS;IACnB,OAAO,UAAS;IAEhB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAQ;IAC3B,KAAK,QAAe;IACpB,KAAK,EAAE,KAAK,EAAE,CAAM;IAEpB,QAAQ,EAAE,MAAM,CAAK;IACrB,MAAM,EAAE,MAAM,CAAK;IACnB,IAAI,EAAE,MAAM,CAAK;IACjB,OAAO,EAAE,OAAO,CAAS;IACzB,QAAQ,EAAE,MAAM,CAAK;IACrB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC/B,KAAK,EAAE,MAAM,CAAK;IAElB,QAAQ,MAAC;IACT,UAAU,MAAC;gBAEC,OAAO,GAAE,qBAA0B;IAO/C,GAAG;IAUH,MAAM;IAKN,KAAK;IAML,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAKrC,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,IAAI;IAOzC,KAAK,CAAC,KAAK,KAAA;IAwTX,WAAW,CAAC,KAAK,GAAE,MAAkB,GAAG,IAAI;IAO5C,YAAY,IAAI,IAAI;IAKpB,MAAM,CAAC,OAAO,GAAE,MAAW,GAAG,IAAI;CAOnC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A parser for a minimal subset of the jsonpath standard
|
|
3
|
+
* Full JSON path parsers for JS exist but are quite large (bundle size)
|
|
4
|
+
*
|
|
5
|
+
* Supports
|
|
6
|
+
*
|
|
7
|
+
* `$.component.component.component`
|
|
8
|
+
*/
|
|
9
|
+
export default class JSONPath {
|
|
10
|
+
path: string[];
|
|
11
|
+
constructor(path?: JSONPath | string[] | string | null);
|
|
12
|
+
clone(): JSONPath;
|
|
13
|
+
toString(): string;
|
|
14
|
+
push(name: string): void;
|
|
15
|
+
pop(): string | undefined;
|
|
16
|
+
set(name: string): void;
|
|
17
|
+
equals(other: JSONPath): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the value pointed at by path
|
|
20
|
+
* TODO - handle root path
|
|
21
|
+
* @param object
|
|
22
|
+
* @param value
|
|
23
|
+
*/
|
|
24
|
+
setFieldAtPath(object: any, value: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* Gets the value pointed at by path
|
|
27
|
+
* TODO - handle root path
|
|
28
|
+
* @param object
|
|
29
|
+
*/
|
|
30
|
+
getFieldAtPath(object: any): any;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=jsonpath.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonpath.d.ts","sourceRoot":"","sources":["../../../src/lib/jsonpath/jsonpath.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,IAAI,EAAE,MAAM,EAAE,CAAC;gBAEH,IAAI,GAAE,QAAQ,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,IAAW;IAuB5D,KAAK,IAAI,QAAQ;IAIjB,QAAQ,IAAI,MAAM;IAIlB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIxB,GAAG;IAIH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAIvB,MAAM,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO;IAchC;;;;;OAKG;IACH,cAAc,CAAC,MAAM,KAAA,EAAE,KAAK,KAAA;IAW5B;;;;OAIG;IACH,cAAc,CAAC,MAAM,KAAA;CAUtB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Batch } from '@loaders.gl/schema';
|
|
2
|
+
import type { JSONLoaderOptions } from '../json-loader';
|
|
3
|
+
export default function parseJSONInBatches(binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options: JSONLoaderOptions): AsyncIterable<Batch>;
|
|
4
|
+
export declare function rebuildJsonObject(batch: any, data: any): any;
|
|
5
|
+
//# sourceMappingURL=parse-json-in-batches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-json-in-batches.d.ts","sourceRoot":"","sources":["../../src/lib/parse-json-in-batches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAQtD,wBAA+B,kBAAkB,CAC/C,mBAAmB,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACvE,OAAO,EAAE,iBAAiB,GACzB,aAAa,CAAC,KAAK,CAAC,CA+EtB;AAED,wBAAgB,iBAAiB,CAAC,KAAK,KAAA,EAAE,IAAI,KAAA,OAmB5C"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { TableBatchBuilder } from '@loaders.gl/schema';
|
|
2
|
-
import { makeTextDecoderIterator } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { assert, makeTextDecoderIterator } from '@loaders.gl/loader-utils';
|
|
3
3
|
import StreamingJSONParser from './parser/streaming-json-parser';
|
|
4
|
+
import JSONPath from './jsonpath/jsonpath';
|
|
4
5
|
export default async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
5
6
|
var _options$json;
|
|
6
7
|
|
|
@@ -84,4 +85,20 @@ export default async function* parseJSONInBatches(binaryAsyncIterator, options)
|
|
|
84
85
|
yield finalBatch;
|
|
85
86
|
}
|
|
86
87
|
}
|
|
88
|
+
export function rebuildJsonObject(batch, data) {
|
|
89
|
+
assert(batch.batchType === 'final-result');
|
|
90
|
+
|
|
91
|
+
if (batch.jsonpath === '$') {
|
|
92
|
+
return data;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (batch.jsonpath && batch.jsonpath.length > 1) {
|
|
96
|
+
const topLevelObject = batch.container;
|
|
97
|
+
const streamingPath = new JSONPath(batch.jsonpath);
|
|
98
|
+
streamingPath.setFieldAtPath(topLevelObject, data);
|
|
99
|
+
return topLevelObject;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return batch.container;
|
|
103
|
+
}
|
|
87
104
|
//# sourceMappingURL=parse-json-in-batches.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/lib/parse-json-in-batches.ts"],"names":["TableBatchBuilder","makeTextDecoderIterator","StreamingJSONParser","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"],"mappings":"AAEA,SAAQA,iBAAR,QAAgC,oBAAhC;AACA,SAAQC,
|
|
1
|
+
{"version":3,"sources":["../../src/lib/parse-json-in-batches.ts"],"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"],"mappings":"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","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"],"file":"parse-json-in-batches.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-json.d.ts","sourceRoot":"","sources":["../../src/lib/parse-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAEtD,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,OAUjF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Batch } from '@loaders.gl/schema';
|
|
2
|
+
import { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
|
+
export default function parseNDJSONInBatches(binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: LoaderOptions): AsyncIterable<Batch>;
|
|
4
|
+
//# sourceMappingURL=parse-ndjson-in-batches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-ndjson-in-batches.d.ts","sourceRoot":"","sources":["../../src/lib/parse-ndjson-in-batches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAE9C,OAAO,EACL,aAAa,EAId,MAAM,0BAA0B,CAAC;AAElC,wBAA+B,oBAAoB,CACjD,mBAAmB,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACvE,OAAO,CAAC,EAAE,aAAa,GACtB,aAAa,CAAC,KAAK,CAAC,CA+BtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-ndjson.d.ts","sourceRoot":"","sources":["../../src/lib/parse-ndjson.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,UAAU,EAAE,MAAM,SASzD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import ClarinetParser, { ClarinetParserOptions } from '../clarinet/clarinet';
|
|
2
|
+
import JSONPath from '../jsonpath/jsonpath';
|
|
3
|
+
export default class JSONParser {
|
|
4
|
+
readonly parser: ClarinetParser;
|
|
5
|
+
result: undefined;
|
|
6
|
+
previousStates: never[];
|
|
7
|
+
currentState: Readonly<{
|
|
8
|
+
container: never[];
|
|
9
|
+
key: null;
|
|
10
|
+
}>;
|
|
11
|
+
jsonpath: JSONPath;
|
|
12
|
+
constructor(options: ClarinetParserOptions);
|
|
13
|
+
reset(): void;
|
|
14
|
+
write(chunk: any): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
_pushOrSet(value: any): void;
|
|
17
|
+
_openArray(newContainer?: never[]): void;
|
|
18
|
+
_closeArray(): void;
|
|
19
|
+
_openObject(newContainer?: {}): void;
|
|
20
|
+
_closeObject(): void;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=json-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json-parser.d.ts","sourceRoot":"","sources":["../../../src/lib/parser/json-parser.ts"],"names":[],"mappings":"AAEA,OAAO,cAAc,EAAE,EAAC,qBAAqB,EAAC,MAAM,sBAAsB,CAAC;AAC3E,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAI5C,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC;IAChC,MAAM,YAAa;IACnB,cAAc,UAAM;IACpB,YAAY;;;OAA6C;IACzD,QAAQ,EAAE,QAAQ,CAAkB;gBAExB,OAAO,EAAE,qBAAqB;IAiD1C,KAAK,IAAI,IAAI;IAOb,KAAK,CAAC,KAAK,KAAA,GAAG,IAAI;IAIlB,KAAK,IAAI,IAAI;IAMb,UAAU,CAAC,KAAK,KAAA,GAAG,IAAI;IAUvB,UAAU,CAAC,YAAY,UAAK,GAAG,IAAI;IAOnC,WAAW,IAAI,IAAI;IAKnB,WAAW,CAAC,YAAY,KAAK,GAAG,IAAI;IAOpC,YAAY,IAAI,IAAI;CAIrB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { default as JSONParser } from './json-parser';
|
|
2
|
+
import JSONPath from '../jsonpath/jsonpath';
|
|
3
|
+
/**
|
|
4
|
+
* The `StreamingJSONParser` looks for the first array in the JSON structure.
|
|
5
|
+
* and emits an array of chunks
|
|
6
|
+
*/
|
|
7
|
+
export default class StreamingJSONParser extends JSONParser {
|
|
8
|
+
private jsonPaths;
|
|
9
|
+
private streamingJsonPath;
|
|
10
|
+
private streamingArray;
|
|
11
|
+
private topLevelObject;
|
|
12
|
+
constructor(options?: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* write REDEFINITION
|
|
17
|
+
* - super.write() chunk to parser
|
|
18
|
+
* - get the contents (so far) of "topmost-level" array as batch of rows
|
|
19
|
+
* - clear top-level array
|
|
20
|
+
* - return the batch of rows\
|
|
21
|
+
*/
|
|
22
|
+
write(chunk: any): any[];
|
|
23
|
+
/**
|
|
24
|
+
* Returns a partially formed result object
|
|
25
|
+
* Useful for returning the "wrapper" object when array is not top level
|
|
26
|
+
* e.g. GeoJSON
|
|
27
|
+
*/
|
|
28
|
+
getPartialResult(): object | null;
|
|
29
|
+
getStreamingJsonPath(): JSONPath | null;
|
|
30
|
+
getStreamingJsonPathAsString(): string | null;
|
|
31
|
+
getJsonPath(): JSONPath;
|
|
32
|
+
/**
|
|
33
|
+
* Checks is this.getJsonPath matches the jsonpaths provided in options
|
|
34
|
+
*/
|
|
35
|
+
_matchJSONPath(): boolean;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=streaming-json-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streaming-json-parser.d.ts","sourceRoot":"","sources":["../../../src/lib/parser/streaming-json-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,UAAU,EAAC,MAAM,eAAe,CAAC;AACpD,OAAO,QAAQ,MAAM,sBAAsB,CAAC;AAE5C;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,UAAU;IACzD,OAAO,CAAC,SAAS,CAAa;IAC9B,OAAO,CAAC,iBAAiB,CAAyB;IAClD,OAAO,CAAC,cAAc,CAAsB;IAC5C,OAAO,CAAC,cAAc,CAAuB;gBAEjC,OAAO,GAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAM;IAiC9C;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,KAAA;IAUX;;;;OAIG;IACH,gBAAgB;IAIhB,oBAAoB;IAIpB,4BAA4B;IAI5B,WAAW;IAMX;;OAEG;IACH,cAAc;CAkBf"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Batch } from '@loaders.gl/schema';
|
|
2
|
+
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
|
+
export declare const NDJSONLoader: {
|
|
4
|
+
name: string;
|
|
5
|
+
id: string;
|
|
6
|
+
module: string;
|
|
7
|
+
version: any;
|
|
8
|
+
extensions: string[];
|
|
9
|
+
mimeTypes: string[];
|
|
10
|
+
category: string;
|
|
11
|
+
text: boolean;
|
|
12
|
+
parse: typeof parse;
|
|
13
|
+
parseTextSync: typeof parseTextSync;
|
|
14
|
+
parseInBatches: typeof parseInBatches;
|
|
15
|
+
options: {};
|
|
16
|
+
};
|
|
17
|
+
declare function parse(arrayBuffer: ArrayBuffer): Promise<any[]>;
|
|
18
|
+
declare function parseTextSync(text: string): any[];
|
|
19
|
+
declare function parseInBatches(asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: LoaderOptions): AsyncIterable<Batch>;
|
|
20
|
+
export declare const _typecheckNDJSONLoader: LoaderWithParser;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=ndjson-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ndjson-loader.d.ts","sourceRoot":"","sources":["../src/ndjson-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAQ9E,eAAO,MAAM,YAAY;;;;;;;;;;;;;CAaxB,CAAC;AAEF,iBAAe,KAAK,CAAC,WAAW,EAAE,WAAW,kBAE5C;AAED,iBAAS,aAAa,CAAC,IAAI,EAAE,MAAM,SAElC;AAED,iBAAS,cAAc,CACrB,aAAa,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACjE,OAAO,CAAC,EAAE,aAAa,GACtB,aAAa,CAAC,KAAK,CAAC,CAEtB;AAED,eAAO,MAAM,sBAAsB,EAAE,gBAA+B,CAAC"}
|
package/dist/ndjson-loader.js
CHANGED
|
@@ -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 "4.0.0-alpha.
|
|
3
|
+
const VERSION = typeof "4.0.0-alpha.5" !== 'undefined' ? "4.0.0-alpha.5" : 'latest';
|
|
4
4
|
export const NDJSONLoader = {
|
|
5
5
|
name: 'NDJSON',
|
|
6
6
|
id: 'ndjson',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geojson-worker.d.ts","sourceRoot":"","sources":["../../src/workers/geojson-worker.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/json",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.5",
|
|
4
4
|
"description": "Framework-independent loader for JSON and streaming JSON formats",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"JSON stream",
|
|
21
21
|
"JSON async iterator"
|
|
22
22
|
],
|
|
23
|
-
"types": "
|
|
23
|
+
"types": "dist/index.d.ts",
|
|
24
24
|
"main": "dist/index.js",
|
|
25
25
|
"module": "dist/index.js",
|
|
26
26
|
"sideEffects": false,
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
33
|
"pre-build": "npm run build-bundle && npm run build-worker",
|
|
34
|
-
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/
|
|
35
|
-
"build-worker": "esbuild src/workers/geojson-worker.ts --bundle --outfile=dist/geojson-worker.js"
|
|
34
|
+
"build-bundle": "esbuild src/bundle.ts --bundle --outfile=dist/dist.min.js",
|
|
35
|
+
"build-worker": "esbuild src/workers/geojson-worker.ts --bundle --outfile=dist/geojson-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@loaders.gl/gis": "4.0.0-alpha.
|
|
39
|
-
"@loaders.gl/loader-utils": "4.0.0-alpha.
|
|
40
|
-
"@loaders.gl/schema": "4.0.0-alpha.
|
|
38
|
+
"@loaders.gl/gis": "4.0.0-alpha.5",
|
|
39
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.5",
|
|
40
|
+
"@loaders.gl/schema": "4.0.0-alpha.5"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "7a71a54bdf1ddf985cc3af3db90b82e7fa97d025"
|
|
43
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type {Batch} from '@loaders.gl/schema';
|
|
2
2
|
import type {JSONLoaderOptions} from '../json-loader';
|
|
3
3
|
import {TableBatchBuilder} from '@loaders.gl/schema';
|
|
4
|
-
import {makeTextDecoderIterator} from '@loaders.gl/loader-utils';
|
|
4
|
+
import {assert, makeTextDecoderIterator} from '@loaders.gl/loader-utils';
|
|
5
5
|
import StreamingJSONParser from './parser/streaming-json-parser';
|
|
6
|
+
import JSONPath from './jsonpath/jsonpath';
|
|
6
7
|
|
|
7
8
|
// TODO - support batch size 0 = no batching/single batch?
|
|
8
9
|
// eslint-disable-next-line max-statements, complexity
|
|
@@ -89,3 +90,24 @@ export default async function* parseJSONInBatches(
|
|
|
89
90
|
yield finalBatch;
|
|
90
91
|
}
|
|
91
92
|
}
|
|
93
|
+
|
|
94
|
+
export function rebuildJsonObject(batch, data) {
|
|
95
|
+
// Last batch will have this special type and will provide all the root object of the parsed file
|
|
96
|
+
assert(batch.batchType === 'final-result');
|
|
97
|
+
|
|
98
|
+
// The streamed JSON data is a top level array (jsonpath = '$'), just return the array of row objects
|
|
99
|
+
if (batch.jsonpath === '$') {
|
|
100
|
+
return data;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// (jsonpath !== '$') The streamed data is not a top level array, so stitch it back in to the top-level object
|
|
104
|
+
if (batch.jsonpath && batch.jsonpath.length > 1) {
|
|
105
|
+
const topLevelObject = batch.container;
|
|
106
|
+
const streamingPath = new JSONPath(batch.jsonpath);
|
|
107
|
+
streamingPath.setFieldAtPath(topLevelObject, data);
|
|
108
|
+
return topLevelObject;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// No jsonpath, in this case nothing was streamed.
|
|
112
|
+
return batch.container;
|
|
113
|
+
}
|