@loaders.gl/json 4.0.0-alpha.5 → 4.0.0-alpha.7
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.js +2 -2
- package/dist/dist.min.js +643 -92
- package/dist/es5/bundle.js +6 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/geojson-loader.js +157 -0
- package/dist/es5/geojson-loader.js.map +1 -0
- package/dist/es5/geojson-writer.js +27 -0
- package/dist/es5/geojson-writer.js.map +1 -0
- package/dist/es5/index.js +69 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/json-loader.js +67 -0
- package/dist/es5/json-loader.js.map +1 -0
- package/dist/es5/json-writer.js +42 -0
- package/dist/es5/json-writer.js.map +1 -0
- package/dist/es5/lib/clarinet/clarinet.js +446 -0
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -0
- package/dist/es5/lib/encoders/encode-utils.js +42 -0
- package/dist/es5/lib/encoders/encode-utils.js.map +1 -0
- package/dist/es5/lib/encoders/geojson-encoder.js +178 -0
- package/dist/es5/lib/encoders/geojson-encoder.js.map +1 -0
- package/dist/es5/lib/encoders/json-encoder.js +30 -0
- package/dist/es5/lib/encoders/json-encoder.js.map +1 -0
- package/dist/es5/lib/encoders/utf8-encoder.js +54 -0
- package/dist/es5/lib/encoders/utf8-encoder.js.map +1 -0
- package/dist/es5/lib/json-parser/json-parser.js +140 -0
- package/dist/es5/lib/json-parser/json-parser.js.map +1 -0
- package/dist/es5/lib/json-parser/streaming-json-parser.js +123 -0
- package/dist/es5/lib/json-parser/streaming-json-parser.js.map +1 -0
- package/dist/es5/lib/jsonpath/jsonpath.js +119 -0
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/es5/lib/parsers/parse-json-in-batches.js +206 -0
- package/dist/es5/lib/parsers/parse-json-in-batches.js.map +1 -0
- package/dist/es5/lib/parsers/parse-json.js +38 -0
- package/dist/es5/lib/parsers/parse-json.js.map +1 -0
- package/dist/es5/lib/parsers/parse-ndjson-in-batches.js +114 -0
- package/dist/es5/lib/parsers/parse-ndjson-in-batches.js.map +1 -0
- package/dist/es5/lib/parsers/parse-ndjson.js +19 -0
- package/dist/es5/lib/parsers/parse-ndjson.js.map +1 -0
- package/dist/es5/ndgeoson-loader.js +54 -0
- package/dist/es5/ndgeoson-loader.js.map +1 -0
- package/dist/es5/ndjson-loader.js +44 -0
- package/dist/es5/ndjson-loader.js.map +1 -0
- package/dist/es5/workers/geojson-worker.js +6 -0
- package/dist/es5/workers/geojson-worker.js.map +1 -0
- package/dist/esm/bundle.js +4 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/geojson-loader.js +79 -0
- package/dist/esm/geojson-loader.js.map +1 -0
- package/dist/esm/geojson-writer.js +18 -0
- package/dist/esm/geojson-writer.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json-loader.js +48 -0
- package/dist/esm/json-loader.js.map +1 -0
- package/dist/esm/json-writer.js +14 -0
- package/dist/esm/json-writer.js.map +1 -0
- package/dist/esm/lib/clarinet/LICENSE +28 -0
- package/dist/esm/lib/clarinet/clarinet.js +415 -0
- package/dist/esm/lib/clarinet/clarinet.js.map +1 -0
- package/dist/esm/lib/encoders/encode-utils.js +31 -0
- package/dist/esm/lib/encoders/encode-utils.js.map +1 -0
- package/dist/esm/lib/encoders/geojson-encoder.js +98 -0
- package/dist/esm/lib/encoders/geojson-encoder.js.map +1 -0
- package/dist/esm/lib/encoders/json-encoder.js +12 -0
- package/dist/esm/lib/encoders/json-encoder.js.map +1 -0
- package/dist/esm/lib/encoders/utf8-encoder.js +32 -0
- package/dist/esm/lib/encoders/utf8-encoder.js.map +1 -0
- package/dist/{lib/parser → esm/lib/json-parser}/json-parser.js +4 -22
- package/dist/esm/lib/json-parser/json-parser.js.map +1 -0
- package/dist/{lib/parser → esm/lib/json-parser}/streaming-json-parser.js +2 -23
- package/dist/esm/lib/json-parser/streaming-json-parser.js.map +1 -0
- package/dist/esm/lib/jsonpath/jsonpath.js +67 -0
- package/dist/esm/lib/jsonpath/jsonpath.js.map +1 -0
- package/dist/{lib → esm/lib/parsers}/parse-json-in-batches.js +5 -18
- package/dist/esm/lib/parsers/parse-json-in-batches.js.map +1 -0
- package/dist/{lib → esm/lib/parsers}/parse-json.js +4 -9
- package/dist/esm/lib/parsers/parse-json.js.map +1 -0
- package/dist/{lib → esm/lib/parsers}/parse-ndjson-in-batches.js +3 -6
- package/dist/esm/lib/parsers/parse-ndjson-in-batches.js.map +1 -0
- package/dist/esm/lib/parsers/parse-ndjson.js +13 -0
- package/dist/esm/lib/parsers/parse-ndjson.js.map +1 -0
- package/dist/esm/ndgeoson-loader.js +27 -0
- package/dist/esm/ndgeoson-loader.js.map +1 -0
- package/dist/esm/ndjson-loader.js +18 -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 +2 -2
- package/dist/geojson-loader.d.ts.map +1 -1
- package/dist/geojson-loader.js +65 -69
- package/dist/geojson-worker.js +251 -68
- package/dist/geojson-writer.d.ts +6 -0
- package/dist/geojson-writer.d.ts.map +1 -0
- package/dist/geojson-writer.js +22 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -7
- package/dist/json-loader.d.ts +10 -7
- package/dist/json-loader.d.ts.map +1 -1
- package/dist/json-loader.js +33 -38
- package/dist/json-writer.d.ts +6 -0
- package/dist/json-writer.d.ts.map +1 -0
- package/dist/json-writer.js +18 -0
- package/dist/lib/clarinet/clarinet.d.ts +3 -3
- package/dist/lib/clarinet/clarinet.d.ts.map +1 -1
- package/dist/lib/clarinet/clarinet.js +510 -493
- package/dist/lib/encoders/encode-utils.d.ts +19 -0
- package/dist/lib/encoders/encode-utils.d.ts.map +1 -0
- package/dist/lib/encoders/encode-utils.js +47 -0
- package/dist/lib/encoders/geojson-encoder.d.ts +14 -0
- package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -0
- package/dist/lib/encoders/geojson-encoder.js +104 -0
- package/dist/lib/encoders/json-encoder.d.ts +16 -0
- package/dist/lib/encoders/json-encoder.d.ts.map +1 -0
- package/dist/lib/encoders/json-encoder.js +22 -0
- package/dist/lib/encoders/utf8-encoder.d.ts +12 -0
- package/dist/lib/encoders/utf8-encoder.d.ts.map +1 -0
- package/dist/lib/encoders/utf8-encoder.js +32 -0
- package/dist/lib/json-parser/json-parser.d.ts.map +1 -0
- package/dist/lib/json-parser/json-parser.js +98 -0
- package/dist/lib/json-parser/streaming-json-parser.d.ts.map +1 -0
- package/dist/lib/json-parser/streaming-json-parser.js +100 -0
- package/dist/lib/jsonpath/jsonpath.js +81 -78
- package/dist/lib/parsers/parse-json-in-batches.d.ts +5 -0
- package/dist/lib/parsers/parse-json-in-batches.d.ts.map +1 -0
- package/dist/lib/parsers/parse-json-in-batches.js +100 -0
- package/dist/lib/parsers/parse-json.d.ts +4 -0
- package/dist/lib/parsers/parse-json.d.ts.map +1 -0
- package/dist/lib/parsers/parse-json.js +32 -0
- package/dist/lib/{parse-ndjson-in-batches.d.ts → parsers/parse-ndjson-in-batches.d.ts} +1 -1
- package/dist/lib/parsers/parse-ndjson-in-batches.d.ts.map +1 -0
- package/dist/lib/parsers/parse-ndjson-in-batches.js +36 -0
- package/dist/lib/parsers/parse-ndjson.d.ts +3 -0
- package/dist/lib/parsers/parse-ndjson.d.ts.map +1 -0
- package/dist/lib/parsers/parse-ndjson.js +17 -0
- package/dist/ndgeoson-loader.d.ts +34 -0
- package/dist/ndgeoson-loader.d.ts.map +1 -0
- package/dist/ndgeoson-loader.js +37 -0
- package/dist/ndjson-loader.d.ts +3 -21
- package/dist/ndjson-loader.d.ts.map +1 -1
- package/dist/ndjson-loader.js +26 -31
- package/dist/workers/geojson-worker.js +5 -4
- package/package.json +7 -7
- package/src/geojson-loader.ts +10 -6
- package/src/geojson-writer.ts +27 -0
- package/src/index.ts +9 -1
- package/src/json-loader.ts +15 -24
- package/src/json-writer.ts +24 -0
- package/src/lib/encoders/encode-utils.ts +54 -0
- package/src/lib/encoders/geojson-encoder.ts +139 -0
- package/src/lib/encoders/json-encoder.ts +30 -0
- package/src/lib/encoders/utf8-encoder.ts +35 -0
- package/src/lib/{parse-json-in-batches.ts → parsers/parse-json-in-batches.ts} +8 -8
- package/src/lib/{parse-json.ts → parsers/parse-json.ts} +7 -3
- package/src/lib/{parse-ndjson-in-batches.ts → parsers/parse-ndjson-in-batches.ts} +1 -1
- package/src/lib/parsers/parse-ndjson.ts +15 -0
- package/src/ndgeoson-loader.ts +48 -0
- package/src/ndjson-loader.ts +20 -27
- package/dist/bundle.js.map +0 -1
- package/dist/geojson-loader.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/jsonl-loader.d.ts +0 -1
- package/dist/jsonl-loader.d.ts.map +0 -1
- package/dist/jsonl-loader.js +0 -2
- package/dist/jsonl-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.d.ts +0 -5
- package/dist/lib/parse-json-in-batches.d.ts.map +0 -1
- package/dist/lib/parse-json-in-batches.js.map +0 -1
- package/dist/lib/parse-json.d.ts +0 -3
- package/dist/lib/parse-json.d.ts.map +0 -1
- package/dist/lib/parse-json.js.map +0 -1
- package/dist/lib/parse-ndjson-in-batches.d.ts.map +0 -1
- package/dist/lib/parse-ndjson-in-batches.js.map +0 -1
- package/dist/lib/parse-ndjson.d.ts +0 -2
- package/dist/lib/parse-ndjson.d.ts.map +0 -1
- package/dist/lib/parse-ndjson.js +0 -11
- package/dist/lib/parse-ndjson.js.map +0 -1
- package/dist/lib/parser/json-parser.d.ts.map +0 -1
- package/dist/lib/parser/json-parser.js.map +0 -1
- package/dist/lib/parser/streaming-json-parser.d.ts.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/jsonl-loader.ts +0 -53
- package/src/lib/parse-ndjson.ts +0 -10
- /package/dist/{lib → es5/lib}/clarinet/LICENSE +0 -0
- /package/dist/lib/{parser → json-parser}/json-parser.d.ts +0 -0
- /package/dist/lib/{parser → json-parser}/streaming-json-parser.d.ts +0 -0
- /package/src/lib/{parser → json-parser}/json-parser.ts +0 -0
- /package/src/lib/{parser → json-parser}/streaming-json-parser.ts +0 -0
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
exports.rebuildJsonObject = exports.parseJSONInBatches = void 0;
|
|
7
|
+
const schema_1 = require("@loaders.gl/schema");
|
|
8
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
9
|
+
const streaming_json_parser_1 = __importDefault(require("../json-parser/streaming-json-parser"));
|
|
10
|
+
const jsonpath_1 = __importDefault(require("../jsonpath/jsonpath"));
|
|
11
|
+
// TODO - support batch size 0 = no batching/single batch?
|
|
12
|
+
// eslint-disable-next-line max-statements, complexity
|
|
13
|
+
async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
14
|
+
const asyncIterator = (0, loader_utils_1.makeTextDecoderIterator)(binaryAsyncIterator);
|
|
15
|
+
const { metadata } = options;
|
|
16
|
+
const { jsonpaths } = options.json || {};
|
|
17
|
+
let isFirstChunk = true;
|
|
18
|
+
// TODO fix Schema deduction
|
|
19
|
+
const schema = null; // new Schema([]);
|
|
20
|
+
const shape = options?.json?.shape || 'row-table';
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
const tableBatchBuilder = new schema_1.TableBatchBuilder(schema, {
|
|
23
|
+
...options,
|
|
24
|
+
shape
|
|
25
|
+
});
|
|
26
|
+
const parser = new streaming_json_parser_1.default({ jsonpaths });
|
|
27
|
+
for await (const chunk of asyncIterator) {
|
|
28
|
+
const rows = parser.write(chunk);
|
|
29
|
+
const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
|
|
30
|
+
if (rows.length > 0 && isFirstChunk) {
|
|
31
|
+
if (metadata) {
|
|
32
|
+
const initialBatch = {
|
|
33
|
+
// Common fields
|
|
34
|
+
shape,
|
|
35
|
+
batchType: 'partial-result',
|
|
36
|
+
data: [],
|
|
37
|
+
length: 0,
|
|
38
|
+
bytesUsed: 0,
|
|
39
|
+
// JSON additions
|
|
40
|
+
container: parser.getPartialResult(),
|
|
41
|
+
jsonpath
|
|
42
|
+
};
|
|
43
|
+
yield initialBatch;
|
|
44
|
+
}
|
|
45
|
+
isFirstChunk = false;
|
|
46
|
+
// schema = deduceSchema(rows);
|
|
47
|
+
}
|
|
48
|
+
// Add the row
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
tableBatchBuilder.addRow(row);
|
|
51
|
+
// If a batch has been completed, emit it
|
|
52
|
+
const batch = tableBatchBuilder.getFullBatch({ jsonpath });
|
|
53
|
+
if (batch) {
|
|
54
|
+
yield batch;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
tableBatchBuilder.chunkComplete(chunk);
|
|
58
|
+
const batch = tableBatchBuilder.getFullBatch({ jsonpath });
|
|
59
|
+
if (batch) {
|
|
60
|
+
yield batch;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// yield final batch
|
|
64
|
+
const jsonpath = parser.getStreamingJsonPathAsString();
|
|
65
|
+
const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
|
|
66
|
+
if (batch) {
|
|
67
|
+
yield batch;
|
|
68
|
+
}
|
|
69
|
+
if (metadata) {
|
|
70
|
+
const finalBatch = {
|
|
71
|
+
shape,
|
|
72
|
+
batchType: 'final-result',
|
|
73
|
+
container: parser.getPartialResult(),
|
|
74
|
+
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
75
|
+
data: [],
|
|
76
|
+
length: 0
|
|
77
|
+
// schema: null
|
|
78
|
+
};
|
|
79
|
+
yield finalBatch;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.parseJSONInBatches = parseJSONInBatches;
|
|
83
|
+
function rebuildJsonObject(batch, data) {
|
|
84
|
+
// Last batch will have this special type and will provide all the root object of the parsed file
|
|
85
|
+
(0, loader_utils_1.assert)(batch.batchType === 'final-result');
|
|
86
|
+
// The streamed JSON data is a top level array (jsonpath = '$'), just return the array of row objects
|
|
87
|
+
if (batch.jsonpath === '$') {
|
|
88
|
+
return data;
|
|
89
|
+
}
|
|
90
|
+
// (jsonpath !== '$') The streamed data is not a top level array, so stitch it back in to the top-level object
|
|
91
|
+
if (batch.jsonpath && batch.jsonpath.length > 1) {
|
|
92
|
+
const topLevelObject = batch.container;
|
|
93
|
+
const streamingPath = new jsonpath_1.default(batch.jsonpath);
|
|
94
|
+
streamingPath.setFieldAtPath(topLevelObject, data);
|
|
95
|
+
return topLevelObject;
|
|
96
|
+
}
|
|
97
|
+
// No jsonpath, in this case nothing was streamed.
|
|
98
|
+
return batch.container;
|
|
99
|
+
}
|
|
100
|
+
exports.rebuildJsonObject = rebuildJsonObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-json.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-json.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAEjD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;AAEzD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,QAAQ,CAWpF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseJSONSync = void 0;
|
|
4
|
+
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
+
function parseJSONSync(jsonText, options) {
|
|
6
|
+
try {
|
|
7
|
+
const json = JSON.parse(jsonText);
|
|
8
|
+
if (options.json?.table) {
|
|
9
|
+
const data = getFirstArray(json) || json;
|
|
10
|
+
return (0, schema_1.makeTableFromData)(data);
|
|
11
|
+
}
|
|
12
|
+
return json;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw new Error('JSONLoader: failed to parse JSON');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.parseJSONSync = parseJSONSync;
|
|
19
|
+
function getFirstArray(json) {
|
|
20
|
+
if (Array.isArray(json)) {
|
|
21
|
+
return json;
|
|
22
|
+
}
|
|
23
|
+
if (json && typeof json === 'object') {
|
|
24
|
+
for (const value of Object.values(json)) {
|
|
25
|
+
const array = getFirstArray(value);
|
|
26
|
+
if (array) {
|
|
27
|
+
return array;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Batch } from '@loaders.gl/schema';
|
|
2
2
|
import { LoaderOptions } from '@loaders.gl/loader-utils';
|
|
3
|
-
export
|
|
3
|
+
export declare function parseNDJSONInBatches(binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options?: LoaderOptions): AsyncIterable<Batch>;
|
|
4
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/parsers/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,wBAAuB,oBAAoB,CACzC,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,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseNDJSONInBatches = void 0;
|
|
4
|
+
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
6
|
+
async function* parseNDJSONInBatches(binaryAsyncIterator, options) {
|
|
7
|
+
const textIterator = (0, loader_utils_1.makeTextDecoderIterator)(binaryAsyncIterator);
|
|
8
|
+
const lineIterator = (0, loader_utils_1.makeLineIterator)(textIterator);
|
|
9
|
+
const numberedLineIterator = (0, loader_utils_1.makeNumberedLineIterator)(lineIterator);
|
|
10
|
+
const schema = null;
|
|
11
|
+
const shape = 'row-table';
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
const tableBatchBuilder = new schema_1.TableBatchBuilder(schema, {
|
|
14
|
+
...options,
|
|
15
|
+
shape
|
|
16
|
+
});
|
|
17
|
+
for await (const { counter, line } of numberedLineIterator) {
|
|
18
|
+
try {
|
|
19
|
+
const row = JSON.parse(line);
|
|
20
|
+
tableBatchBuilder.addRow(row);
|
|
21
|
+
tableBatchBuilder.chunkComplete(line);
|
|
22
|
+
const batch = tableBatchBuilder.getFullBatch();
|
|
23
|
+
if (batch) {
|
|
24
|
+
yield batch;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const batch = tableBatchBuilder.getFinalBatch();
|
|
32
|
+
if (batch) {
|
|
33
|
+
yield batch;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.parseNDJSONInBatches = parseNDJSONInBatches;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-ndjson.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-ndjson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,cAAc,EAAC,MAAM,oBAAoB,CAAC;AAGtE,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,CAWlF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseNDJSONSync = void 0;
|
|
4
|
+
const schema_1 = require("@loaders.gl/schema");
|
|
5
|
+
function parseNDJSONSync(ndjsonText) {
|
|
6
|
+
const lines = ndjsonText.trim().split('\n');
|
|
7
|
+
const parsedLines = lines.map((line, counter) => {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(line);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
return (0, schema_1.makeTableFromData)(parsedLines);
|
|
16
|
+
}
|
|
17
|
+
exports.parseNDJSONSync = parseNDJSONSync;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { parseNDJSONSync } from './lib/parsers/parse-ndjson';
|
|
3
|
+
import { parseNDJSONInBatches } from './lib/parsers/parse-ndjson-in-batches';
|
|
4
|
+
export type NDGeoJSONLoaderOptions = LoaderOptions & {
|
|
5
|
+
geojson?: {
|
|
6
|
+
shape?: 'object-row-table';
|
|
7
|
+
};
|
|
8
|
+
gis?: {
|
|
9
|
+
format: 'geojson';
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare const NDJSONLoader: {
|
|
13
|
+
name: string;
|
|
14
|
+
id: string;
|
|
15
|
+
module: string;
|
|
16
|
+
version: any;
|
|
17
|
+
extensions: string[];
|
|
18
|
+
mimeTypes: string[];
|
|
19
|
+
category: string;
|
|
20
|
+
text: boolean;
|
|
21
|
+
parse: (arrayBuffer: ArrayBuffer) => Promise<import("@loaders.gl/schema").ArrayRowTable | import("@loaders.gl/schema").ObjectRowTable>;
|
|
22
|
+
parseTextSync: typeof parseNDJSONSync;
|
|
23
|
+
parseInBatches: typeof parseNDJSONInBatches;
|
|
24
|
+
options: {
|
|
25
|
+
geojson: {
|
|
26
|
+
shape: string;
|
|
27
|
+
};
|
|
28
|
+
gis: {
|
|
29
|
+
format: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare const _typecheckNDJSONLoader: LoaderWithParser;
|
|
34
|
+
//# sourceMappingURL=ndgeoson-loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ndgeoson-loader.d.ts","sourceRoot":"","sources":["../src/ndgeoson-loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAC,oBAAoB,EAAC,MAAM,uCAAuC,CAAC;AAM3E,MAAM,MAAM,sBAAsB,GAAG,aAAa,GAAG;IACnD,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,kBAAkB,CAAC;KAC5B,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,MAAM,EAAE,SAAS,CAAC;KACnB,CAAC;CACH,CAAC;AAWF,eAAO,MAAM,YAAY;;;;;;;;;yBAeI,WAAW;;;;;;;;;;;CAIvC,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,gBAA+B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._typecheckNDJSONLoader = exports.NDJSONLoader = void 0;
|
|
4
|
+
const parse_ndjson_1 = require("./lib/parsers/parse-ndjson");
|
|
5
|
+
const parse_ndjson_in_batches_1 = require("./lib/parsers/parse-ndjson-in-batches");
|
|
6
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
7
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
8
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
9
|
+
const DEFAULT_NDGEOJSON_LOADER_OPTIONS = {
|
|
10
|
+
geojson: {
|
|
11
|
+
shape: 'object-row-table'
|
|
12
|
+
},
|
|
13
|
+
gis: {
|
|
14
|
+
format: 'geojson'
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
exports.NDJSONLoader = {
|
|
18
|
+
name: 'NDJSON',
|
|
19
|
+
id: 'ndjson',
|
|
20
|
+
module: 'json',
|
|
21
|
+
version: VERSION,
|
|
22
|
+
extensions: ['ndjson', 'ndgeojson'],
|
|
23
|
+
mimeTypes: [
|
|
24
|
+
'application/geo+x-ndjson',
|
|
25
|
+
'application/geo+x-ldjson',
|
|
26
|
+
'application/jsonlines',
|
|
27
|
+
'application/geo+json-seq',
|
|
28
|
+
'application/x-ndjson'
|
|
29
|
+
],
|
|
30
|
+
category: 'table',
|
|
31
|
+
text: true,
|
|
32
|
+
parse: async (arrayBuffer) => (0, parse_ndjson_1.parseNDJSONSync)(new TextDecoder().decode(arrayBuffer)),
|
|
33
|
+
parseTextSync: parse_ndjson_1.parseNDJSONSync,
|
|
34
|
+
parseInBatches: parse_ndjson_in_batches_1.parseNDJSONInBatches,
|
|
35
|
+
options: DEFAULT_NDGEOJSON_LOADER_OPTIONS
|
|
36
|
+
};
|
|
37
|
+
exports._typecheckNDJSONLoader = exports.NDJSONLoader;
|
package/dist/ndjson-loader.d.ts
CHANGED
|
@@ -1,22 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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 {};
|
|
1
|
+
import { LoaderWithParser, LoaderOptions } from '@loaders.gl/loader-utils';
|
|
2
|
+
import { ObjectRowTable, ArrayRowTable, TableBatch } from '@loaders.gl/schema';
|
|
3
|
+
export declare const NDJSONLoader: LoaderWithParser<ObjectRowTable | ArrayRowTable, TableBatch, LoaderOptions>;
|
|
22
4
|
//# sourceMappingURL=ndjson-loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ndjson-loader.d.ts","sourceRoot":"","sources":["../src/ndjson-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ndjson-loader.d.ts","sourceRoot":"","sources":["../src/ndjson-loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,gBAAgB,EAAE,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACzE,OAAO,EAAC,cAAc,EAAE,aAAa,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAQ7E,eAAO,MAAM,YAAY,EAAE,gBAAgB,CACzC,cAAc,GAAG,aAAa,EAC9B,UAAU,EACV,aAAa,CAkBd,CAAC"}
|
package/dist/ndjson-loader.js
CHANGED
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
// loaders.gl, MIT license
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.NDJSONLoader = void 0;
|
|
5
|
+
const parse_ndjson_1 = require("./lib/parsers/parse-ndjson");
|
|
6
|
+
const parse_ndjson_in_batches_1 = require("./lib/parsers/parse-ndjson-in-batches");
|
|
7
|
+
// __VERSION__ is injected by babel-plugin-version-inline
|
|
8
|
+
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
9
|
+
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
10
|
+
exports.NDJSONLoader = {
|
|
11
|
+
name: 'NDJSON',
|
|
12
|
+
id: 'ndjson',
|
|
13
|
+
module: 'json',
|
|
14
|
+
version: VERSION,
|
|
15
|
+
extensions: ['ndjson', 'jsonl'],
|
|
16
|
+
mimeTypes: [
|
|
17
|
+
'application/x-ndjson',
|
|
18
|
+
'application/jsonlines',
|
|
19
|
+
'application/json-seq'
|
|
20
|
+
],
|
|
21
|
+
category: 'table',
|
|
22
|
+
text: true,
|
|
23
|
+
parse: async (arrayBuffer) => (0, parse_ndjson_1.parseNDJSONSync)(new TextDecoder().decode(arrayBuffer)),
|
|
24
|
+
parseTextSync: parse_ndjson_1.parseNDJSONSync,
|
|
25
|
+
parseInBatches: parse_ndjson_in_batches_1.parseNDJSONInBatches,
|
|
26
|
+
options: {}
|
|
17
27
|
};
|
|
18
|
-
|
|
19
|
-
async function parse(arrayBuffer) {
|
|
20
|
-
return parseTextSync(new TextDecoder().decode(arrayBuffer));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function parseTextSync(text) {
|
|
24
|
-
return parseNDJSONSync(text);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function parseInBatches(asyncIterator, options) {
|
|
28
|
-
return parseNDJSONInBatches(asyncIterator, options);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const _typecheckNDJSONLoader = NDJSONLoader;
|
|
32
|
-
//# sourceMappingURL=ndjson-loader.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const loader_utils_1 = require("@loaders.gl/loader-utils");
|
|
4
|
+
const geojson_loader_1 = require("../geojson-loader");
|
|
5
|
+
(0, loader_utils_1.createLoaderWorker)(geojson_loader_1.GeoJSONLoader);
|
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.7",
|
|
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": "dist/index.d.ts",
|
|
24
|
-
"main": "dist/index.js",
|
|
25
|
-
"module": "dist/index.js",
|
|
24
|
+
"main": "dist/es5/index.js",
|
|
25
|
+
"module": "dist/esm/index.js",
|
|
26
26
|
"sideEffects": false,
|
|
27
27
|
"files": [
|
|
28
28
|
"src",
|
|
@@ -35,9 +35,9 @@
|
|
|
35
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.7",
|
|
39
|
+
"@loaders.gl/loader-utils": "4.0.0-alpha.7",
|
|
40
|
+
"@loaders.gl/schema": "4.0.0-alpha.7"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "afb59c4d8e5d8ebb9c28f111cb0c96c5527d0ffd"
|
|
43
43
|
}
|
package/src/geojson-loader.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
1
3
|
import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
2
4
|
import type {JSONLoaderOptions} from './json-loader';
|
|
3
5
|
import {geojsonToBinary} from '@loaders.gl/gis';
|
|
4
|
-
import parseJSONSync from './lib/parse-json';
|
|
5
|
-
import parseJSONInBatches from './lib/parse-json-in-batches';
|
|
6
|
+
import {parseJSONSync} from './lib/parsers/parse-json';
|
|
7
|
+
import {parseJSONInBatches} from './lib/parsers/parse-json-in-batches';
|
|
8
|
+
import {GeoJSONRowTable} from '@loaders.gl/schema';
|
|
6
9
|
|
|
7
10
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
8
11
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
@@ -13,7 +16,7 @@ export type GeoJSONLoaderOptions = JSONLoaderOptions & {
|
|
|
13
16
|
shape?: 'object-row-table';
|
|
14
17
|
};
|
|
15
18
|
gis?: {
|
|
16
|
-
format
|
|
19
|
+
format?: 'geojson' | 'binary';
|
|
17
20
|
};
|
|
18
21
|
};
|
|
19
22
|
|
|
@@ -61,12 +64,13 @@ function parseTextSync(text, options) {
|
|
|
61
64
|
options = {...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options};
|
|
62
65
|
options.json = {...DEFAULT_GEOJSON_LOADER_OPTIONS.geojson, ...options.geojson};
|
|
63
66
|
options.gis = options.gis || {};
|
|
64
|
-
const
|
|
67
|
+
const table = parseJSONSync(text, options) as GeoJSONRowTable;
|
|
68
|
+
table.shape = 'geojson-row-table';
|
|
65
69
|
switch (options.gis.format) {
|
|
66
70
|
case 'binary':
|
|
67
|
-
return geojsonToBinary(
|
|
71
|
+
return geojsonToBinary(table.data);
|
|
68
72
|
default:
|
|
69
|
-
return
|
|
73
|
+
return table;
|
|
70
74
|
}
|
|
71
75
|
}
|
|
72
76
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
// Copyright Foursquare, Inc 20222
|
|
3
|
+
|
|
4
|
+
import type {Writer} from '@loaders.gl/loader-utils';
|
|
5
|
+
import type {Table, TableBatch} from '@loaders.gl/schema';
|
|
6
|
+
import type {GeoJSONWriterOptions} from './lib/encoders/geojson-encoder';
|
|
7
|
+
import {encodeTableAsGeojsonInBatches} from './lib/encoders/geojson-encoder';
|
|
8
|
+
|
|
9
|
+
export type {GeoJSONWriterOptions};
|
|
10
|
+
|
|
11
|
+
export const GeoJSONWriter: Writer<Table, TableBatch, GeoJSONWriterOptions> = {
|
|
12
|
+
id: 'geojson',
|
|
13
|
+
version: 'latest',
|
|
14
|
+
module: 'geojson',
|
|
15
|
+
name: 'GeoJSON',
|
|
16
|
+
extensions: ['geojson'],
|
|
17
|
+
mimeTypes: ['application/geo+json'],
|
|
18
|
+
options: {
|
|
19
|
+
geojson: {
|
|
20
|
+
featureArray: false,
|
|
21
|
+
geometryColumn: null
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
text: true,
|
|
25
|
+
encodeInBatches: (tableIterator: AsyncIterable<TableBatch>, options) =>
|
|
26
|
+
encodeTableAsGeojsonInBatches(tableIterator, options)
|
|
27
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
1
3
|
export type {JSONLoaderOptions} from './json-loader';
|
|
2
4
|
export {JSONLoader} from './json-loader';
|
|
3
5
|
export {NDJSONLoader} from './ndjson-loader';
|
|
4
6
|
|
|
7
|
+
export type {JSONWriterOptions} from './json-writer';
|
|
8
|
+
export {JSONWriter} from './json-writer';
|
|
9
|
+
|
|
5
10
|
// EXPERIMENTAL EXPORTS - WARNING: MAY BE REMOVED WIHTOUT NOTICE IN FUTURE RELEASES
|
|
6
11
|
export type {GeoJSONLoaderOptions as _GeoJSONLoaderOptions} from './geojson-loader';
|
|
7
12
|
export {
|
|
@@ -9,7 +14,10 @@ export {
|
|
|
9
14
|
GeoJSONWorkerLoader as _GeoJSONWorkerLoader
|
|
10
15
|
} from './geojson-loader';
|
|
11
16
|
|
|
17
|
+
export type {GeoJSONWriterOptions as _GeoJSONWriterOptions} from './geojson-writer';
|
|
18
|
+
export {GeoJSONWriter as _GeoJSONWriter} from './geojson-writer';
|
|
19
|
+
|
|
12
20
|
export {default as _JSONPath} from './lib/jsonpath/jsonpath';
|
|
13
21
|
export {default as _ClarinetParser} from './lib/clarinet/clarinet';
|
|
14
22
|
|
|
15
|
-
export {rebuildJsonObject as _rebuildJsonObject} from './lib/parse-json-in-batches';
|
|
23
|
+
export {rebuildJsonObject as _rebuildJsonObject} from './lib/parsers/parse-json-in-batches';
|
package/src/json-loader.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
|
|
3
|
+
import type {Table, TableBatch} from '@loaders.gl/schema';
|
|
2
4
|
import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
3
|
-
import parseJSONSync from './lib/parse-json';
|
|
4
|
-
import parseJSONInBatches from './lib/parse-json-in-batches';
|
|
5
|
+
import {parseJSONSync} from './lib/parsers/parse-json';
|
|
6
|
+
import {parseJSONInBatches} from './lib/parsers/parse-json-in-batches';
|
|
5
7
|
|
|
6
8
|
// __VERSION__ is injected by babel-plugin-version-inline
|
|
7
9
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
8
10
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
9
11
|
|
|
12
|
+
type ParseJSONOptions = {
|
|
13
|
+
shape?: 'row-table';
|
|
14
|
+
table?: boolean;
|
|
15
|
+
jsonpaths?: string[];
|
|
16
|
+
};
|
|
17
|
+
|
|
10
18
|
/**
|
|
11
19
|
* @param table -
|
|
12
20
|
* @param jsonpaths -
|
|
13
21
|
*/
|
|
14
22
|
export type JSONLoaderOptions = LoaderOptions & {
|
|
15
|
-
json?:
|
|
16
|
-
shape?: 'row-table';
|
|
17
|
-
table?: false;
|
|
18
|
-
jsonpaths?: string[];
|
|
19
|
-
};
|
|
23
|
+
json?: ParseJSONOptions;
|
|
20
24
|
};
|
|
21
25
|
|
|
22
|
-
const DEFAULT_JSON_LOADER_OPTIONS = {
|
|
26
|
+
const DEFAULT_JSON_LOADER_OPTIONS: {json: Required<ParseJSONOptions>} = {
|
|
23
27
|
json: {
|
|
24
28
|
shape: 'row-table',
|
|
25
29
|
table: false,
|
|
@@ -28,26 +32,13 @@ const DEFAULT_JSON_LOADER_OPTIONS = {
|
|
|
28
32
|
}
|
|
29
33
|
};
|
|
30
34
|
|
|
31
|
-
export const JSONLoader: LoaderWithParser = {
|
|
35
|
+
export const JSONLoader: LoaderWithParser<Table, TableBatch, JSONLoaderOptions> = {
|
|
32
36
|
name: 'JSON',
|
|
33
37
|
id: 'json',
|
|
34
38
|
module: 'json',
|
|
35
39
|
version: VERSION,
|
|
36
40
|
extensions: ['json', 'geojson'],
|
|
37
41
|
mimeTypes: ['application/json'],
|
|
38
|
-
// TODO - support various line based JSON formats
|
|
39
|
-
/*
|
|
40
|
-
extensions: {
|
|
41
|
-
json: null,
|
|
42
|
-
jsonl: {stream: true},
|
|
43
|
-
ndjson: {stream: true}
|
|
44
|
-
},
|
|
45
|
-
mimeTypes: {
|
|
46
|
-
'application/json': null,
|
|
47
|
-
'application/json-seq': {stream: true},
|
|
48
|
-
'application/x-ndjson': {stream: true}
|
|
49
|
-
},
|
|
50
|
-
*/
|
|
51
42
|
category: 'table',
|
|
52
43
|
text: true,
|
|
53
44
|
parse,
|
|
@@ -68,7 +59,7 @@ function parseTextSync(text: string, options?: JSONLoaderOptions) {
|
|
|
68
59
|
function parseInBatches(
|
|
69
60
|
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
70
61
|
options?: JSONLoaderOptions
|
|
71
|
-
): AsyncIterable<
|
|
62
|
+
): AsyncIterable<TableBatch> {
|
|
72
63
|
const jsonOptions = {...options, json: {...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json}};
|
|
73
64
|
return parseJSONInBatches(asyncIterator, jsonOptions as JSONLoaderOptions);
|
|
74
65
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// loaders.gl, MIT license
|
|
2
|
+
// Copyright 2022 Foursquare Labs, Inc.
|
|
3
|
+
|
|
4
|
+
/* global TextEncoder */
|
|
5
|
+
import type {Writer} from '@loaders.gl/loader-utils';
|
|
6
|
+
import type {Table, TableBatch} from '@loaders.gl/schema';
|
|
7
|
+
import type {JSONWriterOptions} from './lib/encoders/json-encoder';
|
|
8
|
+
import {encodeTableAsJSON} from './lib/encoders/json-encoder';
|
|
9
|
+
|
|
10
|
+
export type {JSONWriterOptions};
|
|
11
|
+
|
|
12
|
+
export const JSONWriter: Writer<Table, TableBatch, JSONWriterOptions> = {
|
|
13
|
+
id: 'json',
|
|
14
|
+
version: 'latest',
|
|
15
|
+
module: 'json',
|
|
16
|
+
name: 'JSON',
|
|
17
|
+
extensions: ['json'],
|
|
18
|
+
mimeTypes: ['application/json'],
|
|
19
|
+
options: {},
|
|
20
|
+
text: true,
|
|
21
|
+
encode: async (table: Table, options: JSONWriterOptions) =>
|
|
22
|
+
new TextEncoder().encode(encodeTableAsJSON(table, options)).buffer,
|
|
23
|
+
encodeText: (table: Table, options: JSONWriterOptions) => encodeTableAsJSON(table, options)
|
|
24
|
+
};
|