@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.
Files changed (131) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +1838 -4
  4. package/dist/es5/bundle.js +7 -0
  5. package/dist/es5/bundle.js.map +1 -0
  6. package/dist/es5/geojson-loader.js +95 -0
  7. package/dist/es5/geojson-loader.js.map +1 -0
  8. package/dist/es5/index.js +54 -0
  9. package/dist/es5/index.js.map +1 -0
  10. package/dist/es5/json-loader.js +59 -0
  11. package/dist/es5/json-loader.js.map +1 -0
  12. package/dist/es5/jsonl-loader.js +2 -0
  13. package/dist/{jsonl-loader.js.map → es5/jsonl-loader.js.map} +0 -0
  14. package/dist/{lib → es5/lib}/clarinet/LICENSE +0 -0
  15. package/dist/es5/lib/clarinet/clarinet.js +511 -0
  16. package/dist/es5/lib/clarinet/clarinet.js.map +1 -0
  17. package/dist/es5/lib/jsonpath/jsonpath.js +97 -0
  18. package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -0
  19. package/dist/es5/lib/parse-json-in-batches.js +99 -0
  20. package/dist/es5/lib/parse-json-in-batches.js.map +1 -0
  21. package/dist/es5/lib/parse-json.js +41 -0
  22. package/dist/es5/lib/parse-json.js.map +1 -0
  23. package/dist/es5/lib/parse-ndjson-in-batches.js +46 -0
  24. package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -0
  25. package/dist/es5/lib/parse-ndjson.js +18 -0
  26. package/dist/es5/lib/parse-ndjson.js.map +1 -0
  27. package/dist/es5/lib/parser/json-parser.js +137 -0
  28. package/dist/es5/lib/parser/json-parser.js.map +1 -0
  29. package/dist/es5/lib/parser/streaming-json-parser.js +102 -0
  30. package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -0
  31. package/dist/es5/ndjson-loader.js +45 -0
  32. package/dist/es5/ndjson-loader.js.map +1 -0
  33. package/dist/es5/workers/geojson-worker.js +8 -0
  34. package/dist/es5/workers/geojson-worker.js.map +1 -0
  35. package/dist/esm/bundle.js +5 -0
  36. package/dist/esm/bundle.js.map +1 -0
  37. package/dist/esm/geojson-loader.js +81 -0
  38. package/dist/esm/geojson-loader.js.map +1 -0
  39. package/dist/esm/index.js +6 -0
  40. package/dist/esm/index.js.map +1 -0
  41. package/dist/esm/json-loader.js +47 -0
  42. package/dist/esm/json-loader.js.map +1 -0
  43. package/dist/esm/jsonl-loader.js +2 -0
  44. package/dist/esm/jsonl-loader.js.map +1 -0
  45. package/dist/esm/lib/clarinet/LICENSE +28 -0
  46. package/dist/esm/lib/clarinet/clarinet.js +518 -0
  47. package/dist/esm/lib/clarinet/clarinet.js.map +1 -0
  48. package/dist/esm/lib/jsonpath/jsonpath.js +86 -0
  49. package/dist/esm/lib/jsonpath/jsonpath.js.map +1 -0
  50. package/dist/esm/lib/parse-json-in-batches.js +87 -0
  51. package/dist/esm/lib/parse-json-in-batches.js.map +1 -0
  52. package/dist/esm/lib/parse-json.js +34 -0
  53. package/dist/esm/lib/parse-json.js.map +1 -0
  54. package/dist/esm/lib/parse-ndjson-in-batches.js +37 -0
  55. package/dist/esm/lib/parse-ndjson-in-batches.js.map +1 -0
  56. package/dist/esm/lib/parse-ndjson.js +11 -0
  57. package/dist/esm/lib/parse-ndjson.js.map +1 -0
  58. package/dist/esm/lib/parser/json-parser.js +128 -0
  59. package/dist/esm/lib/parser/json-parser.js.map +1 -0
  60. package/dist/esm/lib/parser/streaming-json-parser.js +93 -0
  61. package/dist/esm/lib/parser/streaming-json-parser.js.map +1 -0
  62. package/dist/esm/ndjson-loader.js +32 -0
  63. package/dist/esm/ndjson-loader.js.map +1 -0
  64. package/dist/esm/workers/geojson-worker.js +4 -0
  65. package/dist/esm/workers/geojson-worker.js.map +1 -0
  66. package/dist/geojson-loader.d.ts +16 -0
  67. package/dist/geojson-loader.d.ts.map +1 -0
  68. package/dist/geojson-loader.js +66 -69
  69. package/dist/geojson-worker.js +1702 -2
  70. package/dist/index.d.ts +8 -0
  71. package/dist/index.d.ts.map +1 -0
  72. package/dist/index.js +17 -6
  73. package/dist/json-loader.d.ts +14 -0
  74. package/dist/json-loader.d.ts.map +1 -0
  75. package/dist/json-loader.js +48 -38
  76. package/dist/jsonl-loader.d.ts +1 -0
  77. package/dist/jsonl-loader.d.ts.map +1 -0
  78. package/dist/jsonl-loader.js +53 -1
  79. package/dist/lib/clarinet/clarinet.d.ts +74 -0
  80. package/dist/lib/clarinet/clarinet.d.ts.map +1 -0
  81. package/dist/lib/clarinet/clarinet.js +517 -538
  82. package/dist/lib/jsonpath/jsonpath.d.ts +32 -0
  83. package/dist/lib/jsonpath/jsonpath.d.ts.map +1 -0
  84. package/dist/lib/jsonpath/jsonpath.js +81 -78
  85. package/dist/lib/parse-json-in-batches.d.ts +4 -0
  86. package/dist/lib/parse-json-in-batches.d.ts.map +1 -0
  87. package/dist/lib/parse-json-in-batches.js +75 -82
  88. package/dist/lib/parse-json.d.ts +3 -0
  89. package/dist/lib/parse-json.d.ts.map +1 -0
  90. package/dist/lib/parse-json.js +24 -29
  91. package/dist/lib/parse-ndjson-in-batches.d.ts +4 -0
  92. package/dist/lib/parse-ndjson-in-batches.d.ts.map +1 -0
  93. package/dist/lib/parse-ndjson-in-batches.js +32 -34
  94. package/dist/lib/parse-ndjson.d.ts +2 -0
  95. package/dist/lib/parse-ndjson.d.ts.map +1 -0
  96. package/dist/lib/parse-ndjson.js +13 -10
  97. package/dist/lib/parser/json-parser.d.ts +22 -0
  98. package/dist/lib/parser/json-parser.d.ts.map +1 -0
  99. package/dist/lib/parser/json-parser.js +95 -124
  100. package/dist/lib/parser/streaming-json-parser.d.ts +37 -0
  101. package/dist/lib/parser/streaming-json-parser.d.ts.map +1 -0
  102. package/dist/lib/parser/streaming-json-parser.js +95 -93
  103. package/dist/ndjson-loader.d.ts +22 -0
  104. package/dist/ndjson-loader.d.ts.map +1 -0
  105. package/dist/ndjson-loader.js +28 -23
  106. package/dist/workers/geojson-worker.d.ts +2 -0
  107. package/dist/workers/geojson-worker.d.ts.map +1 -0
  108. package/dist/workers/geojson-worker.js +5 -4
  109. package/package.json +10 -10
  110. package/src/lib/clarinet/clarinet.ts +539 -0
  111. package/src/lib/parser/json-parser.ts +52 -55
  112. package/src/lib/parser/streaming-json-parser.ts +28 -32
  113. package/src/ndjson-loader.ts +3 -1
  114. package/dist/bundle.js.map +0 -1
  115. package/dist/dist.min.js +0 -2
  116. package/dist/dist.min.js.map +0 -1
  117. package/dist/geojson-loader.js.map +0 -1
  118. package/dist/geojson-worker.js.map +0 -1
  119. package/dist/index.js.map +0 -1
  120. package/dist/json-loader.js.map +0 -1
  121. package/dist/lib/clarinet/clarinet.js.map +0 -1
  122. package/dist/lib/jsonpath/jsonpath.js.map +0 -1
  123. package/dist/lib/parse-json-in-batches.js.map +0 -1
  124. package/dist/lib/parse-json.js.map +0 -1
  125. package/dist/lib/parse-ndjson-in-batches.js.map +0 -1
  126. package/dist/lib/parse-ndjson.js.map +0 -1
  127. package/dist/lib/parser/json-parser.js.map +0 -1
  128. package/dist/lib/parser/streaming-json-parser.js.map +0 -1
  129. package/dist/ndjson-loader.js.map +0 -1
  130. package/dist/workers/geojson-worker.js.map +0 -1
  131. 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
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
- export default class JSONPath {
3
- constructor(path = null) {
4
- _defineProperty(this, "path", void 0);
5
-
6
- this.path = ['$'];
7
-
8
- if (path instanceof JSONPath) {
9
- this.path = [...path.path];
10
- return;
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
- if (Array.isArray(path)) {
14
- this.path.push(...path);
15
- return;
31
+ clone() {
32
+ return new JSONPath(this);
16
33
  }
17
-
18
- if (typeof path === 'string') {
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
- for (let i = 0; i < this.path.length; ++i) {
53
- if (this.path[i] !== other.path[i]) {
54
- return false;
55
- }
40
+ pop() {
41
+ return this.path.pop();
56
42
  }
57
-
58
- return true;
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
- object[field] = value;
71
- }
72
-
73
- getFieldAtPath(object) {
74
- const path = [...this.path];
75
- path.shift();
76
- const field = path.pop();
77
-
78
- for (const component of path) {
79
- object = object[component];
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
- //# sourceMappingURL=jsonpath.js.map
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
- import { TableBatchBuilder } from '@loaders.gl/schema';
2
- import { makeTextDecoderIterator } from '@loaders.gl/loader-utils';
3
- import StreamingJSONParser from './parser/streaming-json-parser';
4
- export default async function* parseJSONInBatches(binaryAsyncIterator, options) {
5
- var _options$json;
6
-
7
- const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
8
- const {
9
- metadata
10
- } = options;
11
- const {
12
- jsonpaths
13
- } = options.json || {};
14
- let isFirstChunk = true;
15
- const schema = null;
16
- 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';
17
- const tableBatchBuilder = new TableBatchBuilder(schema, { ...options,
18
- shape
19
- });
20
- const parser = new StreamingJSONParser({
21
- jsonpaths
22
- });
23
-
24
- for await (const chunk of asyncIterator) {
25
- const rows = parser.write(chunk);
26
- const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
27
-
28
- if (rows.length > 0 && isFirstChunk) {
29
- if (metadata) {
30
- const initialBatch = {
31
- shape,
32
- batchType: 'partial-result',
33
- data: [],
34
- length: 0,
35
- bytesUsed: 0,
36
- container: parser.getPartialResult(),
37
- jsonpath
38
- };
39
- yield initialBatch;
40
- }
41
-
42
- isFirstChunk = false;
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
- for (const row of rows) {
46
- tableBatchBuilder.addRow(row);
47
- const batch = tableBatchBuilder.getFullBatch({
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
- tableBatchBuilder.chunkComplete(chunk);
57
- const batch = tableBatchBuilder.getFullBatch({
58
- jsonpath
59
- });
60
-
61
- if (batch) {
62
- yield batch;
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
- //# sourceMappingURL=parse-json-in-batches.js.map
80
+ exports.default = parseJSONInBatches;
@@ -0,0 +1,3 @@
1
+ import type { JSONLoaderOptions } from '../json-loader';
2
+ export default function parseJSONSync(jsonText: string, options: JSONLoaderOptions): any;
3
+ //# sourceMappingURL=parse-json.d.ts.map
@@ -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"}
@@ -1,34 +1,29 @@
1
- export default function parseJSONSync(jsonText, options) {
2
- try {
3
- var _options$json;
4
-
5
- const json = JSON.parse(jsonText);
6
-
7
- if ((_options$json = options.json) !== null && _options$json !== void 0 && _options$json.table) {
8
- return getFirstArray(json) || json;
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
- if (Array.isArray(json)) {
19
- return json;
20
- }
21
-
22
- if (json && typeof json === 'object') {
23
- for (const value of Object.values(json)) {
24
- const array = getFirstArray(value);
25
-
26
- if (array) {
27
- return array;
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
- import { TableBatchBuilder } from '@loaders.gl/schema';
2
- import { makeLineIterator, makeNumberedLineIterator, makeTextDecoderIterator } from '@loaders.gl/loader-utils';
3
- export default async function* parseNDJSONInBatches(binaryAsyncIterator, options) {
4
- const textIterator = makeTextDecoderIterator(binaryAsyncIterator);
5
- const lineIterator = makeLineIterator(textIterator);
6
- const numberedLineIterator = makeNumberedLineIterator(lineIterator);
7
- const schema = null;
8
- const shape = 'row-table';
9
- const tableBatchBuilder = new TableBatchBuilder(schema, { ...options,
10
- shape
11
- });
12
-
13
- for await (const {
14
- counter,
15
- line
16
- } of numberedLineIterator) {
17
- try {
18
- const row = JSON.parse(line);
19
- tableBatchBuilder.addRow(row);
20
- tableBatchBuilder.chunkComplete(line);
21
- const batch = tableBatchBuilder.getFullBatch();
22
-
23
- if (batch) {
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
- //# sourceMappingURL=parse-ndjson-in-batches.js.map
35
+ exports.default = parseNDJSONInBatches;
@@ -0,0 +1,2 @@
1
+ export default function parseNDJSONSync(ndjsonText: string): any[];
2
+ //# sourceMappingURL=parse-ndjson.d.ts.map
@@ -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"}
@@ -1,11 +1,14 @@
1
- export default function parseNDJSONSync(ndjsonText) {
2
- const lines = ndjsonText.trim().split('\n');
3
- return lines.map((line, counter) => {
4
- try {
5
- return JSON.parse(line);
6
- } catch (error) {
7
- throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);
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
- //# sourceMappingURL=parse-ndjson.js.map
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"}