@loaders.gl/json 4.1.0-alpha.2 → 4.1.0-alpha.4
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/dist.dev.js +79 -40
- package/dist/geojson-loader.d.ts.map +1 -1
- package/dist/geojson-loader.js +1 -1
- package/dist/geojson-loader.js.map +1 -1
- package/dist/geojson-worker.js +41 -26
- package/dist/geojson-writer.d.ts +1 -1
- package/dist/geojson-writer.d.ts.map +1 -1
- package/dist/geojson-writer.js +7 -1
- package/dist/geojson-writer.js.map +1 -1
- package/dist/index.cjs +24 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/json-loader.d.ts +15 -8
- package/dist/json-loader.d.ts.map +1 -1
- package/dist/json-loader.js +11 -12
- package/dist/json-loader.js.map +1 -1
- package/dist/json-writer.d.ts.map +1 -1
- package/dist/json-writer.js.map +1 -1
- package/dist/lib/clarinet/clarinet.d.ts.map +1 -1
- package/dist/lib/clarinet/clarinet.js.map +1 -1
- package/dist/lib/encoder-utils/encode-table-row.d.ts.map +1 -1
- package/dist/lib/encoder-utils/encode-table-row.js.map +1 -1
- package/dist/lib/encoder-utils/encode-utils.d.ts.map +1 -1
- package/dist/lib/encoder-utils/encode-utils.js.map +1 -1
- package/dist/lib/encoder-utils/utf8-encoder.d.ts.map +1 -1
- package/dist/lib/encoder-utils/utf8-encoder.js.map +1 -1
- package/dist/lib/encoders/geojson-encoder.d.ts +1 -1
- package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/geojson-encoder.js.map +1 -1
- package/dist/lib/encoders/json-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/json-encoder.js.map +1 -1
- package/dist/lib/parsers/parse-json-in-batches.d.ts +2 -2
- package/dist/lib/parsers/parse-json-in-batches.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json-in-batches.js +4 -8
- package/dist/lib/parsers/parse-json-in-batches.js.map +1 -1
- package/dist/lib/parsers/parse-json.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json.js.map +1 -1
- package/dist/ndgeoson-loader.js +1 -1
- package/dist/ndgeoson-loader.js.map +1 -1
- package/dist/ndjson-loader.d.ts.map +1 -1
- package/dist/ndjson-loader.js +1 -1
- package/dist/ndjson-loader.js.map +1 -1
- package/package.json +5 -5
- package/src/geojson-loader.ts +3 -2
- package/src/geojson-writer.ts +16 -4
- package/src/index.ts +2 -1
- package/src/json-loader.ts +34 -22
- package/src/json-writer.ts +2 -1
- package/src/lib/clarinet/clarinet.ts +2 -1
- package/src/lib/encoder-utils/encode-table-row.ts +2 -1
- package/src/lib/encoder-utils/encode-utils.ts +2 -1
- package/src/lib/encoder-utils/utf8-encoder.ts +2 -1
- package/src/lib/encoders/geojson-encoder.ts +3 -2
- package/src/lib/encoders/json-encoder.ts +2 -1
- package/src/lib/parsers/parse-json-in-batches.ts +9 -14
- package/src/lib/parsers/parse-json.ts +2 -1
- package/src/ndjson-loader.ts +2 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TableBatch } from '@loaders.gl/schema';
|
|
2
|
-
import type { JSONLoaderOptions } from '../../json-loader';
|
|
3
|
-
export declare function parseJSONInBatches(binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options: JSONLoaderOptions): AsyncIterable<TableBatch>;
|
|
2
|
+
import type { JSONLoaderOptions, MetadataBatch, JSONBatch } from '../../json-loader';
|
|
3
|
+
export declare function parseJSONInBatches(binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>, options: JSONLoaderOptions): AsyncIterable<TableBatch | MetadataBatch | JSONBatch>;
|
|
4
4
|
export declare function rebuildJsonObject(batch: any, data: any): any;
|
|
5
5
|
//# sourceMappingURL=parse-json-in-batches.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-json-in-batches.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-json-in-batches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"parse-json-in-batches.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-json-in-batches.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAC,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAC,MAAM,mBAAmB,CAAC;AAQnF,wBAAuB,kBAAkB,CACvC,mBAAmB,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAC,WAAW,CAAC,EACvE,OAAO,EAAE,iBAAiB,GACzB,aAAa,CAAC,UAAU,GAAG,aAAa,GAAG,SAAS,CAAC,CA2EvD;AAED,wBAAgB,iBAAiB,CAAC,KAAK,KAAA,EAAE,IAAI,KAAA,OAmB5C"}
|
|
@@ -3,7 +3,6 @@ import { assert, makeTextDecoderIterator } from '@loaders.gl/loader-utils';
|
|
|
3
3
|
import StreamingJSONParser from "../json-parser/streaming-json-parser.js";
|
|
4
4
|
import JSONPath from "../jsonpath/jsonpath.js";
|
|
5
5
|
export async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
6
|
-
var _options$json;
|
|
7
6
|
const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
|
|
8
7
|
const {
|
|
9
8
|
metadata
|
|
@@ -13,11 +12,7 @@ export async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
|
13
12
|
} = options.json || {};
|
|
14
13
|
let isFirstChunk = true;
|
|
15
14
|
const schema = null;
|
|
16
|
-
const
|
|
17
|
-
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
18
|
-
...options,
|
|
19
|
-
shape
|
|
20
|
-
});
|
|
15
|
+
const tableBatchBuilder = new TableBatchBuilder(schema, options);
|
|
21
16
|
const parser = new StreamingJSONParser({
|
|
22
17
|
jsonpaths
|
|
23
18
|
});
|
|
@@ -26,8 +21,9 @@ export async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
|
26
21
|
const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
|
|
27
22
|
if (rows.length > 0 && isFirstChunk) {
|
|
28
23
|
if (metadata) {
|
|
24
|
+
var _options$json;
|
|
29
25
|
const initialBatch = {
|
|
30
|
-
shape,
|
|
26
|
+
shape: (options === null || options === void 0 ? void 0 : (_options$json = options.json) === null || _options$json === void 0 ? void 0 : _options$json.shape) || 'array-row-table',
|
|
31
27
|
batchType: 'partial-result',
|
|
32
28
|
data: [],
|
|
33
29
|
length: 0,
|
|
@@ -65,7 +61,7 @@ export async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
|
65
61
|
}
|
|
66
62
|
if (metadata) {
|
|
67
63
|
const finalBatch = {
|
|
68
|
-
shape,
|
|
64
|
+
shape: 'json',
|
|
69
65
|
batchType: 'final-result',
|
|
70
66
|
container: parser.getPartialResult(),
|
|
71
67
|
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-json-in-batches.js","names":["TableBatchBuilder","assert","makeTextDecoderIterator","StreamingJSONParser","JSONPath","parseJSONInBatches","binaryAsyncIterator","options","
|
|
1
|
+
{"version":3,"file":"parse-json-in-batches.js","names":["TableBatchBuilder","assert","makeTextDecoderIterator","StreamingJSONParser","JSONPath","parseJSONInBatches","binaryAsyncIterator","options","asyncIterator","metadata","jsonpaths","json","isFirstChunk","schema","tableBatchBuilder","parser","chunk","rows","write","jsonpath","length","getStreamingJsonPathAsString","_options$json","initialBatch","shape","batchType","data","bytesUsed","container","getPartialResult","row","addRow","batch","getFullBatch","chunkComplete","getFinalBatch","finalBatch","rebuildJsonObject","topLevelObject","streamingPath","setFieldAtPath"],"sources":["../../../src/lib/parsers/parse-json-in-batches.ts"],"sourcesContent":["import type {TableBatch} from '@loaders.gl/schema';\nimport type {JSONLoaderOptions, MetadataBatch, JSONBatch} from '../../json-loader';\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {assert, makeTextDecoderIterator} from '@loaders.gl/loader-utils';\nimport StreamingJSONParser from '../json-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 async function* parseJSONInBatches(\n binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options: JSONLoaderOptions\n): AsyncIterable<TableBatch | MetadataBatch | JSONBatch> {\n const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);\n\n const {metadata} = options;\n const {jsonpaths} = options.json || {};\n\n let isFirstChunk: boolean = true;\n\n // @ts-expect-error TODO fix Schema deduction\n const schema: Schema = null;\n const tableBatchBuilder = new TableBatchBuilder(schema, options);\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: TableBatch = {\n // Common fields\n shape: options?.json?.shape || 'array-row-table',\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: JSONBatch = {\n shape: 'json',\n batchType: 'final-result',\n container: parser.getPartialResult(),\n jsonpath: parser.getStreamingJsonPathAsString(),\n /** Data Just to avoid crashing? */\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"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-json.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-json.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-json.d.ts","sourceRoot":"","sources":["../../../src/lib/parsers/parse-json.ts"],"names":[],"mappings":"AAGA,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-json.js","names":["makeTableFromData","parseJSONSync","jsonText","options","_options$json","json","JSON","parse","table","data","getFirstArray","error","Error","Array","isArray","value","Object","values","array"],"sources":["../../../src/lib/parsers/parse-json.ts"],"sourcesContent":["// loaders.gl
|
|
1
|
+
{"version":3,"file":"parse-json.js","names":["makeTableFromData","parseJSONSync","jsonText","options","_options$json","json","JSON","parse","table","data","getFirstArray","error","Error","Array","isArray","value","Object","values","array"],"sources":["../../../src/lib/parsers/parse-json.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\nimport type {RowTable} from '@loaders.gl/schema';\nimport {makeTableFromData} from '@loaders.gl/schema';\nimport type {JSONLoaderOptions} from '../../json-loader';\n\nexport function parseJSONSync(jsonText: string, options: JSONLoaderOptions): RowTable {\n try {\n const json = JSON.parse(jsonText);\n if (options.json?.table) {\n const data = getFirstArray(json) || json;\n return makeTableFromData(data);\n }\n return json;\n } catch (error) {\n throw new Error('JSONLoader: failed to parse JSON');\n }\n}\n\nfunction getFirstArray(json) {\n if (Array.isArray(json)) {\n return json;\n }\n if (json && typeof json === 'object') {\n for (const value of Object.values(json)) {\n const array = getFirstArray(value);\n if (array) {\n return array;\n }\n }\n }\n return null;\n}\n"],"mappings":"AAIA,SAAQA,iBAAiB,QAAO,oBAAoB;AAGpD,OAAO,SAASC,aAAaA,CAACC,QAAgB,EAAEC,OAA0B,EAAY;EACpF,IAAI;IAAA,IAAAC,aAAA;IACF,MAAMC,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACL,QAAQ,CAAC;IACjC,KAAAE,aAAA,GAAID,OAAO,CAACE,IAAI,cAAAD,aAAA,eAAZA,aAAA,CAAcI,KAAK,EAAE;MACvB,MAAMC,IAAI,GAAGC,aAAa,CAACL,IAAI,CAAC,IAAIA,IAAI;MACxC,OAAOL,iBAAiB,CAACS,IAAI,CAAC;IAChC;IACA,OAAOJ,IAAI;EACb,CAAC,CAAC,OAAOM,KAAK,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,kCAAkC,CAAC;EACrD;AACF;AAEA,SAASF,aAAaA,CAACL,IAAI,EAAE;EAC3B,IAAIQ,KAAK,CAACC,OAAO,CAACT,IAAI,CAAC,EAAE;IACvB,OAAOA,IAAI;EACb;EACA,IAAIA,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACpC,KAAK,MAAMU,KAAK,IAAIC,MAAM,CAACC,MAAM,CAACZ,IAAI,CAAC,EAAE;MACvC,MAAMa,KAAK,GAAGR,aAAa,CAACK,KAAK,CAAC;MAClC,IAAIG,KAAK,EAAE;QACT,OAAOA,KAAK;MACd;IACF;EACF;EACA,OAAO,IAAI;AACb"}
|
package/dist/ndgeoson-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { parseNDJSONSync } from "./lib/parsers/parse-ndjson.js";
|
|
2
2
|
import { parseNDJSONInBatches } from "./lib/parsers/parse-ndjson-in-batches.js";
|
|
3
|
-
const VERSION = typeof
|
|
3
|
+
const VERSION = typeof "4.1.0-alpha.4" !== 'undefined' ? "4.1.0-alpha.4" : 'latest';
|
|
4
4
|
export const NDJSONLoader = {
|
|
5
5
|
name: 'NDJSON',
|
|
6
6
|
id: 'ndjson',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ndgeoson-loader.js","names":["parseNDJSONSync","parseNDJSONInBatches","VERSION","
|
|
1
|
+
{"version":3,"file":"ndgeoson-loader.js","names":["parseNDJSONSync","parseNDJSONInBatches","VERSION","NDJSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parse","arrayBuffer","TextDecoder","decode","parseTextSync","parseInBatches","options","geojson","shape","gis","format"],"sources":["../src/ndgeoson-loader.ts"],"sourcesContent":["import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {parseNDJSONSync} from './lib/parsers/parse-ndjson';\nimport {parseNDJSONInBatches} from './lib/parsers/parse-ndjson-in-batches';\nimport {ArrayRowTable, ObjectRowTable, Batch} from '@loaders.gl/schema';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\n/** Options for NDGeoJSONLoader */\nexport type NDGeoJSONLoaderOptions = LoaderOptions & {\n geojson?: {\n shape?: 'object-row-table';\n };\n gis?: {\n format: 'geojson';\n };\n};\n\n/** NDGeoJSONLoader */\nexport const NDJSONLoader: LoaderWithParser<\n ArrayRowTable | ObjectRowTable,\n Batch,\n NDGeoJSONLoaderOptions\n> = {\n name: 'NDJSON',\n id: 'ndjson',\n module: 'json',\n version: VERSION,\n extensions: ['ndjson', 'ndgeojson'],\n mimeTypes: [\n 'application/geo+x-ndjson',\n 'application/geo+x-ldjson',\n 'application/jsonlines', // https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#cm-batch\n 'application/geo+json-seq',\n 'application/x-ndjson'\n ],\n category: 'table',\n text: true,\n parse: async (arrayBuffer: ArrayBuffer) => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),\n parseTextSync: parseNDJSONSync,\n parseInBatches: parseNDJSONInBatches,\n options: {\n geojson: {\n shape: 'object-row-table'\n },\n gis: {\n format: 'geojson'\n }\n }\n};\n"],"mappings":"SACQA,eAAe;AAAA,SACfC,oBAAoB;AAK5B,MAAMC,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAa3E,OAAO,MAAMC,YAIZ,GAAG;EACFC,IAAI,EAAE,QAAQ;EACdC,EAAE,EAAE,QAAQ;EACZC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;EACnCC,SAAS,EAAE,CACT,0BAA0B,EAC1B,0BAA0B,EAC1B,uBAAuB,EACvB,0BAA0B,EAC1B,sBAAsB,CACvB;EACDC,QAAQ,EAAE,OAAO;EACjBC,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE,MAAOC,WAAwB,IAAKb,eAAe,CAAC,IAAIc,WAAW,CAAC,CAAC,CAACC,MAAM,CAACF,WAAW,CAAC,CAAC;EACjGG,aAAa,EAAEhB,eAAe;EAC9BiB,cAAc,EAAEhB,oBAAoB;EACpCiB,OAAO,EAAE;IACPC,OAAO,EAAE;MACPC,KAAK,EAAE;IACT,CAAC;IACDC,GAAG,EAAE;MACHC,MAAM,EAAE;IACV;EACF;AACF,CAAC"}
|
|
@@ -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":"AAIA,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,6 +1,6 @@
|
|
|
1
1
|
import { parseNDJSONSync } from "./lib/parsers/parse-ndjson.js";
|
|
2
2
|
import { parseNDJSONInBatches } from "./lib/parsers/parse-ndjson-in-batches.js";
|
|
3
|
-
const VERSION = typeof
|
|
3
|
+
const VERSION = typeof "4.1.0-alpha.4" !== 'undefined' ? "4.1.0-alpha.4" : 'latest';
|
|
4
4
|
export const NDJSONLoader = {
|
|
5
5
|
name: 'NDJSON',
|
|
6
6
|
id: 'ndjson',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ndjson-loader.js","names":["parseNDJSONSync","parseNDJSONInBatches","VERSION","
|
|
1
|
+
{"version":3,"file":"ndjson-loader.js","names":["parseNDJSONSync","parseNDJSONInBatches","VERSION","NDJSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parse","arrayBuffer","TextDecoder","decode","parseTextSync","parseInBatches","options"],"sources":["../src/ndjson-loader.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport {ObjectRowTable, ArrayRowTable, TableBatch} from '@loaders.gl/schema';\nimport {parseNDJSONSync} from './lib/parsers/parse-ndjson';\nimport {parseNDJSONInBatches} from './lib/parsers/parse-ndjson-in-batches';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport const NDJSONLoader: LoaderWithParser<\n ObjectRowTable | ArrayRowTable,\n TableBatch,\n LoaderOptions\n> = {\n name: 'NDJSON',\n id: 'ndjson',\n module: 'json',\n version: VERSION,\n extensions: ['ndjson', 'jsonl'],\n mimeTypes: [\n 'application/x-ndjson',\n 'application/jsonlines', // https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#cm-batch\n 'application/json-seq'\n ],\n category: 'table',\n text: true,\n parse: async (arrayBuffer: ArrayBuffer) => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),\n parseTextSync: parseNDJSONSync,\n parseInBatches: parseNDJSONInBatches,\n options: {}\n};\n"],"mappings":"SAMQA,eAAe;AAAA,SACfC,oBAAoB;AAI5B,MAAMC,OAAO,GAAG,sBAAkB,KAAK,WAAW,qBAAiB,QAAQ;AAE3E,OAAO,MAAMC,YAIZ,GAAG;EACFC,IAAI,EAAE,QAAQ;EACdC,EAAE,EAAE,QAAQ;EACZC,MAAM,EAAE,MAAM;EACdC,OAAO,EAAEL,OAAO;EAChBM,UAAU,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC;EAC/BC,SAAS,EAAE,CACT,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,CACvB;EACDC,QAAQ,EAAE,OAAO;EACjBC,IAAI,EAAE,IAAI;EACVC,KAAK,EAAE,MAAOC,WAAwB,IAAKb,eAAe,CAAC,IAAIc,WAAW,CAAC,CAAC,CAACC,MAAM,CAACF,WAAW,CAAC,CAAC;EACjGG,aAAa,EAAEhB,eAAe;EAC9BiB,cAAc,EAAEhB,oBAAoB;EACpCiB,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loaders.gl/json",
|
|
3
|
-
"version": "4.1.0-alpha.
|
|
3
|
+
"version": "4.1.0-alpha.4",
|
|
4
4
|
"description": "Framework-independent loader for JSON and streaming JSON formats",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
"build-worker": "esbuild src/workers/geojson-worker.ts --bundle --outfile=dist/geojson-worker.js --define:__VERSION__=\\\"$npm_package_version\\\""
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@loaders.gl/gis": "4.1.0-alpha.
|
|
47
|
-
"@loaders.gl/loader-utils": "4.1.0-alpha.
|
|
48
|
-
"@loaders.gl/schema": "4.1.0-alpha.
|
|
46
|
+
"@loaders.gl/gis": "4.1.0-alpha.4",
|
|
47
|
+
"@loaders.gl/loader-utils": "4.1.0-alpha.4",
|
|
48
|
+
"@loaders.gl/schema": "4.1.0-alpha.4"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "b18ba1d63be704fd021e4470e8ab84175621e62d"
|
|
51
51
|
}
|
package/src/geojson-loader.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
5
|
import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';
|
|
@@ -101,7 +102,7 @@ function parseInBatches(asyncIterator, options): AsyncIterable<TableBatch> {
|
|
|
101
102
|
case 'binary':
|
|
102
103
|
return makeBinaryGeometryIterator(geojsonIterator);
|
|
103
104
|
default:
|
|
104
|
-
return geojsonIterator
|
|
105
|
+
return geojsonIterator as AsyncIterable<TableBatch>;
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
108
|
|
package/src/geojson-writer.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
// Copyright Foursquare, Inc 20222
|
|
4
5
|
|
|
5
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
type WriterWithEncoder,
|
|
8
|
+
type WriterOptions,
|
|
9
|
+
concatenateArrayBuffersAsync
|
|
10
|
+
} from '@loaders.gl/loader-utils';
|
|
6
11
|
import type {Table, TableBatch} from '@loaders.gl/schema';
|
|
7
12
|
import {encodeTableAsGeojsonInBatches} from './lib/encoders/geojson-encoder';
|
|
8
13
|
|
|
@@ -21,13 +26,20 @@ export const GeoJSONWriter: WriterWithEncoder<Table, TableBatch, GeoJSONWriterOp
|
|
|
21
26
|
name: 'GeoJSON',
|
|
22
27
|
extensions: ['geojson'],
|
|
23
28
|
mimeTypes: ['application/geo+json'],
|
|
29
|
+
text: true,
|
|
24
30
|
options: {
|
|
25
31
|
geojson: {
|
|
26
32
|
featureArray: false,
|
|
27
33
|
geometryColumn: null
|
|
28
34
|
}
|
|
29
35
|
},
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
|
|
37
|
+
async encode(table: Table, options: GeoJSONWriterOptions): Promise<ArrayBuffer> {
|
|
38
|
+
const tableIterator = [table] as TableBatch[];
|
|
39
|
+
const batches = encodeTableAsGeojsonInBatches(tableIterator, options);
|
|
40
|
+
return await concatenateArrayBuffersAsync(batches);
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
encodeInBatches: (tableIterator: AsyncIterable<TableBatch> | Iterable<TableBatch>, options) =>
|
|
32
44
|
encodeTableAsGeojsonInBatches(tableIterator, options)
|
|
33
45
|
};
|
package/src/index.ts
CHANGED
package/src/json-loader.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
|
|
4
|
-
import type {Table, TableBatch} from '@loaders.gl/schema';
|
|
5
|
+
import type {Table, TableBatch, Batch} from '@loaders.gl/schema';
|
|
5
6
|
import type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';
|
|
6
7
|
import {parseJSONSync} from './lib/parsers/parse-json';
|
|
7
8
|
import {parseJSONInBatches} from './lib/parsers/parse-json-in-batches';
|
|
@@ -10,10 +11,14 @@ import {parseJSONInBatches} from './lib/parsers/parse-json-in-batches';
|
|
|
10
11
|
// @ts-ignore TS2304: Cannot find name '__VERSION__'.
|
|
11
12
|
const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
|
|
12
13
|
|
|
13
|
-
type
|
|
14
|
-
shape: '
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
export type MetadataBatch = Batch & {
|
|
15
|
+
shape: 'metadata';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type JSONBatch = Batch & {
|
|
19
|
+
shape: 'json';
|
|
20
|
+
/** JSON data */
|
|
21
|
+
container: any;
|
|
17
22
|
};
|
|
18
23
|
|
|
19
24
|
/**
|
|
@@ -21,19 +26,19 @@ type ParseJSONOptions = {
|
|
|
21
26
|
* @param jsonpaths -
|
|
22
27
|
*/
|
|
23
28
|
export type JSONLoaderOptions = LoaderOptions & {
|
|
24
|
-
json?:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
table: false,
|
|
31
|
-
jsonpaths: []
|
|
32
|
-
// batchSize: 'auto'
|
|
33
|
-
}
|
|
29
|
+
json?: {
|
|
30
|
+
/** Not specifying shape leaves avoids changes */
|
|
31
|
+
shape?: 'object-row-table' | 'array-row-table';
|
|
32
|
+
table?: boolean;
|
|
33
|
+
jsonpaths?: string[];
|
|
34
|
+
};
|
|
34
35
|
};
|
|
35
36
|
|
|
36
|
-
export const JSONLoader: LoaderWithParser<
|
|
37
|
+
export const JSONLoader: LoaderWithParser<
|
|
38
|
+
Table,
|
|
39
|
+
TableBatch | MetadataBatch | JSONBatch,
|
|
40
|
+
JSONLoaderOptions
|
|
41
|
+
> = {
|
|
37
42
|
name: 'JSON',
|
|
38
43
|
id: 'json',
|
|
39
44
|
module: 'json',
|
|
@@ -42,10 +47,17 @@ export const JSONLoader: LoaderWithParser<Table, TableBatch, JSONLoaderOptions>
|
|
|
42
47
|
mimeTypes: ['application/json'],
|
|
43
48
|
category: 'table',
|
|
44
49
|
text: true,
|
|
50
|
+
options: {
|
|
51
|
+
json: {
|
|
52
|
+
shape: undefined,
|
|
53
|
+
table: false,
|
|
54
|
+
jsonpaths: []
|
|
55
|
+
// batchSize: 'auto'
|
|
56
|
+
}
|
|
57
|
+
},
|
|
45
58
|
parse,
|
|
46
59
|
parseTextSync,
|
|
47
|
-
parseInBatches
|
|
48
|
-
options: DEFAULT_JSON_LOADER_OPTIONS
|
|
60
|
+
parseInBatches
|
|
49
61
|
};
|
|
50
62
|
|
|
51
63
|
async function parse(arrayBuffer: ArrayBuffer, options?: JSONLoaderOptions) {
|
|
@@ -53,14 +65,14 @@ async function parse(arrayBuffer: ArrayBuffer, options?: JSONLoaderOptions) {
|
|
|
53
65
|
}
|
|
54
66
|
|
|
55
67
|
function parseTextSync(text: string, options?: JSONLoaderOptions) {
|
|
56
|
-
const jsonOptions = {...options, json: {...
|
|
68
|
+
const jsonOptions = {...options, json: {...JSONLoader.options.json, ...options?.json}};
|
|
57
69
|
return parseJSONSync(text, jsonOptions as JSONLoaderOptions);
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
function parseInBatches(
|
|
61
73
|
asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
62
74
|
options?: JSONLoaderOptions
|
|
63
|
-
): AsyncIterable<TableBatch> {
|
|
64
|
-
const jsonOptions = {...options, json: {...
|
|
75
|
+
): AsyncIterable<TableBatch | MetadataBatch | JSONBatch> {
|
|
76
|
+
const jsonOptions = {...options, json: {...JSONLoader.options.json, ...options?.json}};
|
|
65
77
|
return parseJSONInBatches(asyncIterator, jsonOptions as JSONLoaderOptions);
|
|
66
78
|
}
|
package/src/json-writer.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
// loaders.gl
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
2
3
|
// Copyright (c) vis.gl contributors
|
|
3
4
|
// Copyright 2022 Foursquare Labs, Inc.
|
|
4
5
|
|
|
@@ -14,7 +15,7 @@ import type {GeoJSONWriterOptions} from '../../geojson-writer';
|
|
|
14
15
|
*/
|
|
15
16
|
// eslint-disable-next-line max-statements
|
|
16
17
|
export async function* encodeTableAsGeojsonInBatches(
|
|
17
|
-
batchIterator: AsyncIterable<TableBatch>, // | Iterable<TableBatch>,
|
|
18
|
+
batchIterator: AsyncIterable<TableBatch> | Iterable<TableBatch>, // | Iterable<TableBatch>,
|
|
18
19
|
inputOpts: GeoJSONWriterOptions = {}
|
|
19
20
|
): AsyncIterable<ArrayBuffer> {
|
|
20
21
|
// @ts-expect-error
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {TableBatch} from '@loaders.gl/schema';
|
|
2
|
-
import type {JSONLoaderOptions} from '../../json-loader';
|
|
2
|
+
import type {JSONLoaderOptions, MetadataBatch, JSONBatch} from '../../json-loader';
|
|
3
3
|
import {TableBatchBuilder} from '@loaders.gl/schema';
|
|
4
4
|
import {assert, makeTextDecoderIterator} from '@loaders.gl/loader-utils';
|
|
5
5
|
import StreamingJSONParser from '../json-parser/streaming-json-parser';
|
|
@@ -10,7 +10,7 @@ import JSONPath from '../jsonpath/jsonpath';
|
|
|
10
10
|
export async function* parseJSONInBatches(
|
|
11
11
|
binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,
|
|
12
12
|
options: JSONLoaderOptions
|
|
13
|
-
): AsyncIterable<TableBatch> {
|
|
13
|
+
): AsyncIterable<TableBatch | MetadataBatch | JSONBatch> {
|
|
14
14
|
const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
|
|
15
15
|
|
|
16
16
|
const {metadata} = options;
|
|
@@ -18,15 +18,9 @@ export async function* parseJSONInBatches(
|
|
|
18
18
|
|
|
19
19
|
let isFirstChunk: boolean = true;
|
|
20
20
|
|
|
21
|
-
// TODO fix Schema deduction
|
|
22
|
-
const schema = null;
|
|
23
|
-
|
|
24
|
-
const shape = options?.json?.shape || 'object-row-table';
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
27
|
-
...options,
|
|
28
|
-
shape
|
|
29
|
-
});
|
|
21
|
+
// @ts-expect-error TODO fix Schema deduction
|
|
22
|
+
const schema: Schema = null;
|
|
23
|
+
const tableBatchBuilder = new TableBatchBuilder(schema, options);
|
|
30
24
|
|
|
31
25
|
const parser = new StreamingJSONParser({jsonpaths});
|
|
32
26
|
|
|
@@ -39,7 +33,7 @@ export async function* parseJSONInBatches(
|
|
|
39
33
|
if (metadata) {
|
|
40
34
|
const initialBatch: TableBatch = {
|
|
41
35
|
// Common fields
|
|
42
|
-
shape,
|
|
36
|
+
shape: options?.json?.shape || 'array-row-table',
|
|
43
37
|
batchType: 'partial-result',
|
|
44
38
|
data: [],
|
|
45
39
|
length: 0,
|
|
@@ -79,11 +73,12 @@ export async function* parseJSONInBatches(
|
|
|
79
73
|
}
|
|
80
74
|
|
|
81
75
|
if (metadata) {
|
|
82
|
-
const finalBatch:
|
|
83
|
-
shape,
|
|
76
|
+
const finalBatch: JSONBatch = {
|
|
77
|
+
shape: 'json',
|
|
84
78
|
batchType: 'final-result',
|
|
85
79
|
container: parser.getPartialResult(),
|
|
86
80
|
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
81
|
+
/** Data Just to avoid crashing? */
|
|
87
82
|
data: [],
|
|
88
83
|
length: 0
|
|
89
84
|
// schema: null
|
package/src/ndjson-loader.ts
CHANGED