@loaders.gl/json 3.1.0-alpha.3 → 3.1.0-beta.2
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/bundle.js +1838 -4
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/geojson-loader.js +95 -0
- package/dist/es5/geojson-loader.js.map +1 -0
- package/dist/es5/index.js +54 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +59 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/jsonl-loader.js +2 -0
- package/dist/{jsonl-loader.js.map → es5/jsonl-loader.js.map} +0 -0
- package/dist/{lib → es5/lib}/clarinet/LICENSE +0 -0
- package/dist/es5/lib/clarinet/clarinet.js +511 -0
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -0
- package/dist/es5/lib/jsonpath/jsonpath.js +97 -0
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/es5/lib/parse-json-in-batches.js +99 -0
- package/dist/es5/lib/parse-json-in-batches.js.map +1 -0
- package/dist/es5/lib/parse-json.js +41 -0
- package/dist/es5/lib/parse-json.js.map +1 -0
- package/dist/es5/lib/parse-ndjson-in-batches.js +46 -0
- package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -0
- package/dist/es5/lib/parse-ndjson.js +18 -0
- package/dist/es5/lib/parse-ndjson.js.map +1 -0
- package/dist/es5/lib/parser/json-parser.js +137 -0
- package/dist/es5/lib/parser/json-parser.js.map +1 -0
- package/dist/es5/lib/parser/streaming-json-parser.js +102 -0
- package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -0
- package/dist/es5/ndjson-loader.js +45 -0
- package/dist/es5/ndjson-loader.js.map +1 -0
- package/dist/es5/workers/geojson-worker.js +8 -0
- package/dist/es5/workers/geojson-worker.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/geojson-loader.js +81 -0
- package/dist/esm/geojson-loader.js.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-loader.js +47 -0
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/esm/jsonl-loader.js +2 -0
- package/dist/esm/jsonl-loader.js.map +1 -0
- package/dist/esm/lib/clarinet/LICENSE +28 -0
- package/dist/esm/lib/clarinet/clarinet.js +518 -0
- package/dist/esm/lib/clarinet/clarinet.js.map +1 -0
- package/dist/esm/lib/jsonpath/jsonpath.js +86 -0
- package/dist/esm/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/esm/lib/parse-json-in-batches.js +87 -0
- package/dist/esm/lib/parse-json-in-batches.js.map +1 -0
- package/dist/esm/lib/parse-json.js +34 -0
- package/dist/esm/lib/parse-json.js.map +1 -0
- package/dist/esm/lib/parse-ndjson-in-batches.js +37 -0
- package/dist/esm/lib/parse-ndjson-in-batches.js.map +1 -0
- package/dist/esm/lib/parse-ndjson.js +11 -0
- package/dist/esm/lib/parse-ndjson.js.map +1 -0
- package/dist/esm/lib/parser/json-parser.js +128 -0
- package/dist/esm/lib/parser/json-parser.js.map +1 -0
- package/dist/esm/lib/parser/streaming-json-parser.js +93 -0
- package/dist/esm/lib/parser/streaming-json-parser.js.map +1 -0
- package/dist/esm/ndjson-loader.js +32 -0
- package/dist/esm/ndjson-loader.js.map +1 -0
- package/dist/esm/workers/geojson-worker.js +4 -0
- package/dist/esm/workers/geojson-worker.js.map +1 -0
- package/dist/geojson-loader.d.ts +16 -0
- package/dist/geojson-loader.d.ts.map +1 -0
- package/dist/geojson-loader.js +66 -69
- package/dist/geojson-worker.js +1702 -2
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -6
- package/dist/json-loader.d.ts +14 -0
- package/dist/json-loader.d.ts.map +1 -0
- package/dist/json-loader.js +48 -38
- package/dist/jsonl-loader.d.ts +1 -0
- package/dist/jsonl-loader.d.ts.map +1 -0
- package/dist/jsonl-loader.js +53 -1
- package/dist/lib/clarinet/clarinet.d.ts +74 -0
- package/dist/lib/clarinet/clarinet.d.ts.map +1 -0
- package/dist/lib/clarinet/clarinet.js +517 -538
- package/dist/lib/jsonpath/jsonpath.d.ts +32 -0
- package/dist/lib/jsonpath/jsonpath.d.ts.map +1 -0
- package/dist/lib/jsonpath/jsonpath.js +81 -78
- package/dist/lib/parse-json-in-batches.d.ts +4 -0
- package/dist/lib/parse-json-in-batches.d.ts.map +1 -0
- package/dist/lib/parse-json-in-batches.js +75 -82
- package/dist/lib/parse-json.d.ts +3 -0
- package/dist/lib/parse-json.d.ts.map +1 -0
- package/dist/lib/parse-json.js +24 -29
- 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-in-batches.js +32 -34
- package/dist/lib/parse-ndjson.d.ts +2 -0
- package/dist/lib/parse-ndjson.d.ts.map +1 -0
- package/dist/lib/parse-ndjson.js +13 -10
- 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/json-parser.js +95 -124
- 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/lib/parser/streaming-json-parser.js +95 -93
- package/dist/ndjson-loader.d.ts +22 -0
- package/dist/ndjson-loader.d.ts.map +1 -0
- package/dist/ndjson-loader.js +28 -23
- package/dist/workers/geojson-worker.d.ts +2 -0
- package/dist/workers/geojson-worker.d.ts.map +1 -0
- package/dist/workers/geojson-worker.js +5 -4
- package/package.json +10 -10
- 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/bundle.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/geojson-loader.js.map +0 -1
- package/dist/geojson-worker.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/lib/clarinet/clarinet.js.map +0 -1
- package/dist/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/lib/parse-json-in-batches.js.map +0 -1
- package/dist/lib/parse-json.js.map +0 -1
- package/dist/lib/parse-ndjson-in-batches.js.map +0 -1
- package/dist/lib/parse-ndjson.js.map +0 -1
- package/dist/lib/parser/json-parser.js.map +0 -1
- package/dist/lib/parser/streaming-json-parser.js.map +0 -1
- package/dist/ndjson-loader.js.map +0 -1
- package/dist/workers/geojson-worker.js.map +0 -1
- package/src/lib/clarinet/clarinet.js +0 -578
|
@@ -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"}
|
|
@@ -1,86 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* A parser for a minimal subset of the jsonpath standard
|
|
5
|
+
* Full JSON path parsers for JS exist but are quite large (bundle size)
|
|
6
|
+
*
|
|
7
|
+
* Supports
|
|
8
|
+
*
|
|
9
|
+
* `$.component.component.component`
|
|
10
|
+
*/
|
|
11
|
+
class JSONPath {
|
|
12
|
+
constructor(path = null) {
|
|
13
|
+
this.path = ['$'];
|
|
14
|
+
if (path instanceof JSONPath) {
|
|
15
|
+
// @ts-ignore
|
|
16
|
+
this.path = [...path.path];
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
if (Array.isArray(path)) {
|
|
20
|
+
this.path.push(...path);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
// Parse a string as a JSONPath
|
|
24
|
+
if (typeof path === 'string') {
|
|
25
|
+
this.path = path.split('.');
|
|
26
|
+
if (this.path[0] !== '$') {
|
|
27
|
+
throw new Error('JSONPaths must start with $');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
11
30
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.path.push(...path);
|
|
15
|
-
return;
|
|
31
|
+
clone() {
|
|
32
|
+
return new JSONPath(this);
|
|
16
33
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.path = path.split('.');
|
|
20
|
-
|
|
21
|
-
if (this.path[0] !== '$') {
|
|
22
|
-
throw new Error('JSONPaths must start with $');
|
|
23
|
-
}
|
|
34
|
+
toString() {
|
|
35
|
+
return this.path.join('.');
|
|
24
36
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
clone() {
|
|
28
|
-
return new JSONPath(this);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
toString() {
|
|
32
|
-
return this.path.join('.');
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
push(name) {
|
|
36
|
-
this.path.push(name);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
pop() {
|
|
40
|
-
return this.path.pop();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
set(name) {
|
|
44
|
-
this.path[this.path.length - 1] = name;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
equals(other) {
|
|
48
|
-
if (!this || !other || this.path.length !== other.path.length) {
|
|
49
|
-
return false;
|
|
37
|
+
push(name) {
|
|
38
|
+
this.path.push(name);
|
|
50
39
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if (this.path[i] !== other.path[i]) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
40
|
+
pop() {
|
|
41
|
+
return this.path.pop();
|
|
56
42
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
setFieldAtPath(object, value) {
|
|
62
|
-
const path = [...this.path];
|
|
63
|
-
path.shift();
|
|
64
|
-
const field = path.pop();
|
|
65
|
-
|
|
66
|
-
for (const component of path) {
|
|
67
|
-
object = object[component];
|
|
43
|
+
set(name) {
|
|
44
|
+
this.path[this.path.length - 1] = name;
|
|
68
45
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
46
|
+
equals(other) {
|
|
47
|
+
if (!this || !other || this.path.length !== other.path.length) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
for (let i = 0; i < this.path.length; ++i) {
|
|
51
|
+
if (this.path[i] !== other.path[i]) {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Sets the value pointed at by path
|
|
59
|
+
* TODO - handle root path
|
|
60
|
+
* @param object
|
|
61
|
+
* @param value
|
|
62
|
+
*/
|
|
63
|
+
setFieldAtPath(object, value) {
|
|
64
|
+
const path = [...this.path];
|
|
65
|
+
path.shift();
|
|
66
|
+
const field = path.pop();
|
|
67
|
+
for (const component of path) {
|
|
68
|
+
object = object[component];
|
|
69
|
+
}
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
object[field] = value;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Gets the value pointed at by path
|
|
75
|
+
* TODO - handle root path
|
|
76
|
+
* @param object
|
|
77
|
+
*/
|
|
78
|
+
getFieldAtPath(object) {
|
|
79
|
+
const path = [...this.path];
|
|
80
|
+
path.shift();
|
|
81
|
+
const field = path.pop();
|
|
82
|
+
for (const component of path) {
|
|
83
|
+
object = object[component];
|
|
84
|
+
}
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
return object[field];
|
|
80
87
|
}
|
|
81
|
-
|
|
82
|
-
return object[field];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
88
|
}
|
|
86
|
-
|
|
89
|
+
exports.default = JSONPath;
|
|
@@ -0,0 +1,4 @@
|
|
|
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
|
+
//# 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;AAOtD,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"}
|
|
@@ -1,87 +1,80 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
shape
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const schema_1 = require("@loaders.gl/schema");
|
|
7
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
8
|
+
const streaming_json_parser_1 = __importDefault(require("./parser/streaming-json-parser"));
|
|
9
|
+
// TODO - support batch size 0 = no batching/single batch?
|
|
10
|
+
// eslint-disable-next-line max-statements, complexity
|
|
11
|
+
async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
12
|
+
const asyncIterator = (0, loader_utils_1.makeTextDecoderIterator)(binaryAsyncIterator);
|
|
13
|
+
const { metadata } = options;
|
|
14
|
+
const { jsonpaths } = options.json || {};
|
|
15
|
+
let isFirstChunk = true;
|
|
16
|
+
// TODO fix Schema deduction
|
|
17
|
+
const schema = null; // new Schema([]);
|
|
18
|
+
const shape = options?.json?.shape || 'row-table';
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
const tableBatchBuilder = new schema_1.TableBatchBuilder(schema, {
|
|
21
|
+
...options,
|
|
22
|
+
shape
|
|
23
|
+
});
|
|
24
|
+
const parser = new streaming_json_parser_1.default({ jsonpaths });
|
|
25
|
+
for await (const chunk of asyncIterator) {
|
|
26
|
+
const rows = parser.write(chunk);
|
|
27
|
+
const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
|
|
28
|
+
if (rows.length > 0 && isFirstChunk) {
|
|
29
|
+
if (metadata) {
|
|
30
|
+
const initialBatch = {
|
|
31
|
+
// Common fields
|
|
32
|
+
shape,
|
|
33
|
+
batchType: 'partial-result',
|
|
34
|
+
data: [],
|
|
35
|
+
length: 0,
|
|
36
|
+
bytesUsed: 0,
|
|
37
|
+
// JSON additions
|
|
38
|
+
container: parser.getPartialResult(),
|
|
39
|
+
jsonpath
|
|
40
|
+
};
|
|
41
|
+
yield initialBatch;
|
|
42
|
+
}
|
|
43
|
+
isFirstChunk = false;
|
|
44
|
+
// schema = deduceSchema(rows);
|
|
45
|
+
}
|
|
46
|
+
// Add the row
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
tableBatchBuilder.addRow(row);
|
|
49
|
+
// If a batch has been completed, emit it
|
|
50
|
+
const batch = tableBatchBuilder.getFullBatch({ jsonpath });
|
|
51
|
+
if (batch) {
|
|
52
|
+
yield batch;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
tableBatchBuilder.chunkComplete(chunk);
|
|
56
|
+
const batch = tableBatchBuilder.getFullBatch({ jsonpath });
|
|
57
|
+
if (batch) {
|
|
58
|
+
yield batch;
|
|
59
|
+
}
|
|
43
60
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
jsonpath
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
if (batch) {
|
|
61
|
+
// yield final batch
|
|
62
|
+
const jsonpath = parser.getStreamingJsonPathAsString();
|
|
63
|
+
const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
|
|
64
|
+
if (batch) {
|
|
52
65
|
yield batch;
|
|
53
|
-
}
|
|
54
66
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
if (metadata) {
|
|
68
|
+
const finalBatch = {
|
|
69
|
+
shape,
|
|
70
|
+
batchType: 'final-result',
|
|
71
|
+
container: parser.getPartialResult(),
|
|
72
|
+
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
73
|
+
data: [],
|
|
74
|
+
length: 0
|
|
75
|
+
// schema: null
|
|
76
|
+
};
|
|
77
|
+
yield finalBatch;
|
|
63
78
|
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const jsonpath = parser.getStreamingJsonPathAsString();
|
|
67
|
-
const batch = tableBatchBuilder.getFinalBatch({
|
|
68
|
-
jsonpath
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
if (batch) {
|
|
72
|
-
yield batch;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (metadata) {
|
|
76
|
-
const finalBatch = {
|
|
77
|
-
shape,
|
|
78
|
-
batchType: 'final-result',
|
|
79
|
-
container: parser.getPartialResult(),
|
|
80
|
-
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
81
|
-
data: [],
|
|
82
|
-
length: 0
|
|
83
|
-
};
|
|
84
|
-
yield finalBatch;
|
|
85
|
-
}
|
|
86
79
|
}
|
|
87
|
-
|
|
80
|
+
exports.default = parseJSONInBatches;
|
|
@@ -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"}
|
package/dist/lib/parse-json.js
CHANGED
|
@@ -1,34 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function parseJSONSync(jsonText, options) {
|
|
4
|
+
try {
|
|
5
|
+
const json = JSON.parse(jsonText);
|
|
6
|
+
if (options.json?.table) {
|
|
7
|
+
return getFirstArray(json) || json;
|
|
8
|
+
}
|
|
9
|
+
return json;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
throw new Error('JSONLoader: failed to parse JSON');
|
|
9
13
|
}
|
|
10
|
-
|
|
11
|
-
return json;
|
|
12
|
-
} catch (error) {
|
|
13
|
-
throw new Error('JSONLoader: failed to parse JSON');
|
|
14
|
-
}
|
|
15
14
|
}
|
|
16
|
-
|
|
15
|
+
exports.default = parseJSONSync;
|
|
17
16
|
function getFirstArray(json) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
17
|
+
if (Array.isArray(json)) {
|
|
18
|
+
return json;
|
|
19
|
+
}
|
|
20
|
+
if (json && typeof json === 'object') {
|
|
21
|
+
for (const value of Object.values(json)) {
|
|
22
|
+
const array = getFirstArray(value);
|
|
23
|
+
if (array) {
|
|
24
|
+
return array;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return null;
|
|
28
|
+
return null;
|
|
33
29
|
}
|
|
34
|
-
//# sourceMappingURL=parse-json.js.map
|
|
@@ -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"}
|
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
shape
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const schema_1 = require("@loaders.gl/schema");
|
|
4
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
5
|
+
async function* parseNDJSONInBatches(binaryAsyncIterator, options) {
|
|
6
|
+
const textIterator = (0, loader_utils_1.makeTextDecoderIterator)(binaryAsyncIterator);
|
|
7
|
+
const lineIterator = (0, loader_utils_1.makeLineIterator)(textIterator);
|
|
8
|
+
const numberedLineIterator = (0, loader_utils_1.makeNumberedLineIterator)(lineIterator);
|
|
9
|
+
const schema = null;
|
|
10
|
+
const shape = 'row-table';
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const tableBatchBuilder = new schema_1.TableBatchBuilder(schema, {
|
|
13
|
+
...options,
|
|
14
|
+
shape
|
|
15
|
+
});
|
|
16
|
+
for await (const { counter, line } of numberedLineIterator) {
|
|
17
|
+
try {
|
|
18
|
+
const row = JSON.parse(line);
|
|
19
|
+
tableBatchBuilder.addRow(row);
|
|
20
|
+
tableBatchBuilder.chunkComplete(line);
|
|
21
|
+
const batch = tableBatchBuilder.getFullBatch();
|
|
22
|
+
if (batch) {
|
|
23
|
+
yield batch;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const batch = tableBatchBuilder.getFinalBatch();
|
|
31
|
+
if (batch) {
|
|
24
32
|
yield batch;
|
|
25
|
-
}
|
|
26
|
-
} catch (error) {
|
|
27
|
-
throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);
|
|
28
33
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const batch = tableBatchBuilder.getFinalBatch();
|
|
32
|
-
|
|
33
|
-
if (batch) {
|
|
34
|
-
yield batch;
|
|
35
|
-
}
|
|
36
34
|
}
|
|
37
|
-
|
|
35
|
+
exports.default = parseNDJSONInBatches;
|
|
@@ -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"}
|
package/dist/lib/parse-ndjson.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
function parseNDJSONSync(ndjsonText) {
|
|
4
|
+
const lines = ndjsonText.trim().split('\n');
|
|
5
|
+
return lines.map((line, counter) => {
|
|
6
|
+
try {
|
|
7
|
+
return JSON.parse(line);
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
10
13
|
}
|
|
11
|
-
|
|
14
|
+
exports.default = parseNDJSONSync;
|
|
@@ -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"}
|