@loaders.gl/json 4.2.0-alpha.4 → 4.2.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +341 -409
- package/dist/dist.min.js +21 -0
- package/dist/geojson-loader.d.ts +1 -1
- package/dist/geojson-loader.d.ts.map +1 -1
- package/dist/geojson-loader.js +74 -72
- package/dist/geojson-writer.js +23 -20
- package/dist/index.cjs +120 -94
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +12 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/json-loader.js +29 -36
- package/dist/json-writer.js +14 -11
- package/dist/lib/clarinet/clarinet.js +511 -391
- package/dist/lib/encoder-utils/encode-table-row.d.ts +1 -1
- package/dist/lib/encoder-utils/encode-table-row.d.ts.map +1 -1
- package/dist/lib/encoder-utils/encode-table-row.js +46 -37
- package/dist/lib/encoder-utils/encode-utils.js +38 -25
- package/dist/lib/encoder-utils/utf8-encoder.js +25 -27
- 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 +43 -40
- package/dist/lib/encoders/json-encoder.d.ts +1 -1
- package/dist/lib/encoders/json-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/json-encoder.js +17 -9
- package/dist/lib/json-parser/json-parser.d.ts +2 -2
- package/dist/lib/json-parser/json-parser.d.ts.map +1 -1
- package/dist/lib/json-parser/json-parser.js +85 -102
- package/dist/lib/json-parser/streaming-json-parser.d.ts +2 -2
- package/dist/lib/json-parser/streaming-json-parser.d.ts.map +1 -1
- package/dist/lib/json-parser/streaming-json-parser.js +86 -63
- package/dist/lib/jsonpath/jsonpath.js +77 -57
- package/dist/lib/parsers/parse-json-in-batches.d.ts +1 -1
- package/dist/lib/parsers/parse-json-in-batches.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json-in-batches.js +76 -75
- package/dist/lib/parsers/parse-json.d.ts +1 -1
- package/dist/lib/parsers/parse-json.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json.js +21 -22
- package/dist/lib/parsers/parse-ndjson-in-batches.js +26 -28
- package/dist/lib/parsers/parse-ndjson.js +10 -10
- package/dist/ndgeoson-loader.js +27 -19
- package/dist/ndjson-loader.js +21 -13
- package/dist/workers/geojson-worker.js +0 -1
- package/package.json +11 -7
- package/dist/geojson-loader.js.map +0 -1
- package/dist/geojson-writer.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/json-loader.js.map +0 -1
- package/dist/json-writer.js.map +0 -1
- package/dist/lib/clarinet/LICENSE +0 -28
- package/dist/lib/clarinet/clarinet.js.map +0 -1
- package/dist/lib/encoder-utils/encode-table-row.js.map +0 -1
- package/dist/lib/encoder-utils/encode-utils.js.map +0 -1
- package/dist/lib/encoder-utils/utf8-encoder.js.map +0 -1
- package/dist/lib/encoders/geojson-encoder.js.map +0 -1
- package/dist/lib/encoders/json-encoder.js.map +0 -1
- package/dist/lib/json-parser/json-parser.js.map +0 -1
- package/dist/lib/json-parser/streaming-json-parser.js.map +0 -1
- package/dist/lib/jsonpath/jsonpath.js.map +0 -1
- package/dist/lib/parsers/parse-json-in-batches.js.map +0 -1
- package/dist/lib/parsers/parse-json.js.map +0 -1
- package/dist/lib/parsers/parse-ndjson-in-batches.js.map +0 -1
- package/dist/lib/parsers/parse-ndjson.js.map +0 -1
- package/dist/ndgeoson-loader.js.map +0 -1
- package/dist/ndjson-loader.js.map +0 -1
- package/dist/workers/geojson-worker.js.map +0 -1
package/dist/dist.dev.js
CHANGED
|
@@ -2,14 +2,19 @@
|
|
|
2
2
|
if (typeof exports === 'object' && typeof module === 'object')
|
|
3
3
|
module.exports = factory();
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
|
-
else if (typeof exports === 'object') exports['
|
|
6
|
-
else root['
|
|
5
|
+
else if (typeof exports === 'object') exports['loaders'] = factory();
|
|
6
|
+
else root['loaders'] = factory();})(globalThis, function () {
|
|
7
7
|
"use strict";
|
|
8
8
|
var __exports__ = (() => {
|
|
9
|
+
var __create = Object.create;
|
|
9
10
|
var __defProp = Object.defineProperty;
|
|
10
11
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
11
12
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
12
14
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
15
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
16
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
17
|
+
};
|
|
13
18
|
var __export = (target, all) => {
|
|
14
19
|
for (var name in all)
|
|
15
20
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,11 +27,27 @@ var __exports__ = (() => {
|
|
|
22
27
|
}
|
|
23
28
|
return to;
|
|
24
29
|
};
|
|
30
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
25
39
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
40
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
|
|
41
|
+
// external-global-plugin:@loaders.gl/core
|
|
42
|
+
var require_core = __commonJS({
|
|
43
|
+
"external-global-plugin:@loaders.gl/core"(exports, module) {
|
|
44
|
+
module.exports = globalThis.loaders;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// bundle.ts
|
|
49
|
+
var bundle_exports = {};
|
|
50
|
+
__export(bundle_exports, {
|
|
30
51
|
JSONLoader: () => JSONLoader,
|
|
31
52
|
JSONWriter: () => JSONWriter,
|
|
32
53
|
NDJSONLoader: () => NDJSONLoader,
|
|
@@ -37,15 +58,16 @@ var __exports__ = (() => {
|
|
|
37
58
|
_JSONPath: () => JSONPath,
|
|
38
59
|
_rebuildJsonObject: () => rebuildJsonObject
|
|
39
60
|
});
|
|
61
|
+
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
40
62
|
|
|
41
63
|
// ../schema/src/lib/table/batches/base-table-batch-aggregator.ts
|
|
42
64
|
var DEFAULT_ROW_COUNT = 100;
|
|
43
65
|
var BaseTableBatchAggregator = class {
|
|
44
|
-
length = 0;
|
|
45
|
-
rows = null;
|
|
46
|
-
cursor = 0;
|
|
47
|
-
_headers = [];
|
|
48
66
|
constructor(schema, options) {
|
|
67
|
+
this.length = 0;
|
|
68
|
+
this.rows = null;
|
|
69
|
+
this.cursor = 0;
|
|
70
|
+
this._headers = [];
|
|
49
71
|
this.options = options;
|
|
50
72
|
this.schema = schema;
|
|
51
73
|
if (!Array.isArray(schema)) {
|
|
@@ -141,12 +163,12 @@ var __exports__ = (() => {
|
|
|
141
163
|
// ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
|
|
142
164
|
var DEFAULT_ROW_COUNT2 = 100;
|
|
143
165
|
var RowTableBatchAggregator = class {
|
|
144
|
-
length = 0;
|
|
145
|
-
objectRows = null;
|
|
146
|
-
arrayRows = null;
|
|
147
|
-
cursor = 0;
|
|
148
|
-
_headers = null;
|
|
149
166
|
constructor(schema, options) {
|
|
167
|
+
this.length = 0;
|
|
168
|
+
this.objectRows = null;
|
|
169
|
+
this.arrayRows = null;
|
|
170
|
+
this.cursor = 0;
|
|
171
|
+
this._headers = null;
|
|
150
172
|
this.options = options;
|
|
151
173
|
this.schema = schema;
|
|
152
174
|
if (schema) {
|
|
@@ -206,6 +228,7 @@ var __exports__ = (() => {
|
|
|
206
228
|
batchType: "data",
|
|
207
229
|
data: rows,
|
|
208
230
|
length: this.length,
|
|
231
|
+
// @ts-expect-error we should infer a schema
|
|
209
232
|
schema: this.schema,
|
|
210
233
|
cursor: this.cursor
|
|
211
234
|
};
|
|
@@ -215,10 +238,10 @@ var __exports__ = (() => {
|
|
|
215
238
|
// ../schema/src/lib/table/batches/columnar-table-batch-aggregator.ts
|
|
216
239
|
var DEFAULT_ROW_COUNT3 = 100;
|
|
217
240
|
var ColumnarTableBatchAggregator = class {
|
|
218
|
-
length = 0;
|
|
219
|
-
allocated = 0;
|
|
220
|
-
columns = {};
|
|
221
241
|
constructor(schema, options) {
|
|
242
|
+
this.length = 0;
|
|
243
|
+
this.allocated = 0;
|
|
244
|
+
this.columns = {};
|
|
222
245
|
this.schema = schema;
|
|
223
246
|
this._reallocateColumns();
|
|
224
247
|
}
|
|
@@ -259,6 +282,7 @@ var __exports__ = (() => {
|
|
|
259
282
|
};
|
|
260
283
|
return batch;
|
|
261
284
|
}
|
|
285
|
+
// HELPERS
|
|
262
286
|
_reallocateColumns() {
|
|
263
287
|
if (this.length < this.allocated) {
|
|
264
288
|
return;
|
|
@@ -298,20 +322,17 @@ var __exports__ = (() => {
|
|
|
298
322
|
};
|
|
299
323
|
var ERR_MESSAGE = "TableBatchBuilder";
|
|
300
324
|
var TableBatchBuilder = class {
|
|
301
|
-
aggregator = null;
|
|
302
|
-
batchCount = 0;
|
|
303
|
-
bytesUsed = 0;
|
|
304
|
-
isChunkComplete = false;
|
|
305
|
-
lastBatchEmittedMs = Date.now();
|
|
306
|
-
totalLength = 0;
|
|
307
|
-
totalBytes = 0;
|
|
308
|
-
rowBytes = 0;
|
|
309
325
|
constructor(schema, options) {
|
|
326
|
+
this.aggregator = null;
|
|
327
|
+
this.batchCount = 0;
|
|
328
|
+
this.bytesUsed = 0;
|
|
329
|
+
this.isChunkComplete = false;
|
|
330
|
+
this.lastBatchEmittedMs = Date.now();
|
|
331
|
+
this.totalLength = 0;
|
|
332
|
+
this.totalBytes = 0;
|
|
333
|
+
this.rowBytes = 0;
|
|
310
334
|
this.schema = schema;
|
|
311
|
-
this.options = {
|
|
312
|
-
...DEFAULT_OPTIONS,
|
|
313
|
-
...options
|
|
314
|
-
};
|
|
335
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
315
336
|
}
|
|
316
337
|
limitReached() {
|
|
317
338
|
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
@@ -322,6 +343,7 @@ var __exports__ = (() => {
|
|
|
322
343
|
}
|
|
323
344
|
return false;
|
|
324
345
|
}
|
|
346
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
325
347
|
addRow(row) {
|
|
326
348
|
if (this.limitReached()) {
|
|
327
349
|
return;
|
|
@@ -335,6 +357,7 @@ var __exports__ = (() => {
|
|
|
335
357
|
this.addObjectRow(row);
|
|
336
358
|
}
|
|
337
359
|
}
|
|
360
|
+
/** Add one row to the batch */
|
|
338
361
|
addArrayRow(row) {
|
|
339
362
|
if (!this.aggregator) {
|
|
340
363
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -342,6 +365,7 @@ var __exports__ = (() => {
|
|
|
342
365
|
}
|
|
343
366
|
this.aggregator.addArrayRow(row);
|
|
344
367
|
}
|
|
368
|
+
/** Add one row to the batch */
|
|
345
369
|
addObjectRow(row) {
|
|
346
370
|
if (!this.aggregator) {
|
|
347
371
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -349,6 +373,7 @@ var __exports__ = (() => {
|
|
|
349
373
|
}
|
|
350
374
|
this.aggregator.addObjectRow(row);
|
|
351
375
|
}
|
|
376
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
352
377
|
chunkComplete(chunk) {
|
|
353
378
|
if (chunk instanceof ArrayBuffer) {
|
|
354
379
|
this.bytesUsed += chunk.byteLength;
|
|
@@ -364,6 +389,7 @@ var __exports__ = (() => {
|
|
|
364
389
|
getFinalBatch(options) {
|
|
365
390
|
return this._getBatch(options);
|
|
366
391
|
}
|
|
392
|
+
// INTERNAL
|
|
367
393
|
_estimateRowMB(row) {
|
|
368
394
|
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
369
395
|
}
|
|
@@ -385,6 +411,9 @@ var __exports__ = (() => {
|
|
|
385
411
|
this.lastBatchEmittedMs = Date.now();
|
|
386
412
|
return true;
|
|
387
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
416
|
+
*/
|
|
388
417
|
_getBatch(options) {
|
|
389
418
|
if (!this.aggregator) {
|
|
390
419
|
return null;
|
|
@@ -605,22 +634,13 @@ var __exports__ = (() => {
|
|
|
605
634
|
function getDataTypeFromArray(array) {
|
|
606
635
|
let type = getDataTypeFromTypedArray(array);
|
|
607
636
|
if (type !== "null") {
|
|
608
|
-
return {
|
|
609
|
-
type,
|
|
610
|
-
nullable: false
|
|
611
|
-
};
|
|
637
|
+
return { type, nullable: false };
|
|
612
638
|
}
|
|
613
639
|
if (array.length > 0) {
|
|
614
640
|
type = getDataTypeFromValue(array[0]);
|
|
615
|
-
return {
|
|
616
|
-
type,
|
|
617
|
-
nullable: true
|
|
618
|
-
};
|
|
641
|
+
return { type, nullable: true };
|
|
619
642
|
}
|
|
620
|
-
return {
|
|
621
|
-
type: "null",
|
|
622
|
-
nullable: true
|
|
623
|
-
};
|
|
643
|
+
return { type: "null", nullable: true };
|
|
624
644
|
}
|
|
625
645
|
function getDataTypeFromTypedArray(array) {
|
|
626
646
|
switch (array.constructor) {
|
|
@@ -665,10 +685,7 @@ var __exports__ = (() => {
|
|
|
665
685
|
const field = deduceFieldFromColumn(column, columnName);
|
|
666
686
|
fields.push(field);
|
|
667
687
|
}
|
|
668
|
-
return {
|
|
669
|
-
fields,
|
|
670
|
-
metadata: {}
|
|
671
|
-
};
|
|
688
|
+
return { fields, metadata: {} };
|
|
672
689
|
}
|
|
673
690
|
function deduceSchemaFromRows(rowTable) {
|
|
674
691
|
if (!rowTable.length) {
|
|
@@ -679,10 +696,7 @@ var __exports__ = (() => {
|
|
|
679
696
|
for (const [columnName, value] of Object.entries(row0)) {
|
|
680
697
|
fields.push(deduceFieldFromValue(value, columnName));
|
|
681
698
|
}
|
|
682
|
-
return {
|
|
683
|
-
fields,
|
|
684
|
-
metadata: {}
|
|
685
|
-
};
|
|
699
|
+
return { fields, metadata: {} };
|
|
686
700
|
}
|
|
687
701
|
function deduceFieldFromColumn(column, name) {
|
|
688
702
|
if (ArrayBuffer.isView(column)) {
|
|
@@ -691,6 +705,7 @@ var __exports__ = (() => {
|
|
|
691
705
|
name,
|
|
692
706
|
type: type.type || "null",
|
|
693
707
|
nullable: type.nullable
|
|
708
|
+
// metadata: {}
|
|
694
709
|
};
|
|
695
710
|
}
|
|
696
711
|
if (Array.isArray(column) && column.length > 0) {
|
|
@@ -700,6 +715,7 @@ var __exports__ = (() => {
|
|
|
700
715
|
name,
|
|
701
716
|
type,
|
|
702
717
|
nullable: true
|
|
718
|
+
// metadata: {},
|
|
703
719
|
};
|
|
704
720
|
}
|
|
705
721
|
throw new Error("empty table");
|
|
@@ -710,6 +726,7 @@ var __exports__ = (() => {
|
|
|
710
726
|
name,
|
|
711
727
|
type,
|
|
712
728
|
nullable: true
|
|
729
|
+
// metadata: {}
|
|
713
730
|
};
|
|
714
731
|
}
|
|
715
732
|
|
|
@@ -718,31 +735,19 @@ var __exports__ = (() => {
|
|
|
718
735
|
let table;
|
|
719
736
|
switch (getTableShapeFromData(data)) {
|
|
720
737
|
case "array-row-table":
|
|
721
|
-
table = {
|
|
722
|
-
shape: "array-row-table",
|
|
723
|
-
data
|
|
724
|
-
};
|
|
738
|
+
table = { shape: "array-row-table", data };
|
|
725
739
|
break;
|
|
726
740
|
case "object-row-table":
|
|
727
|
-
table = {
|
|
728
|
-
shape: "object-row-table",
|
|
729
|
-
data
|
|
730
|
-
};
|
|
741
|
+
table = { shape: "object-row-table", data };
|
|
731
742
|
break;
|
|
732
743
|
case "columnar-table":
|
|
733
|
-
table = {
|
|
734
|
-
shape: "columnar-table",
|
|
735
|
-
data
|
|
736
|
-
};
|
|
744
|
+
table = { shape: "columnar-table", data };
|
|
737
745
|
break;
|
|
738
746
|
default:
|
|
739
747
|
throw new Error("table");
|
|
740
748
|
}
|
|
741
749
|
const schema = deduceTableSchema(table);
|
|
742
|
-
return {
|
|
743
|
-
...table,
|
|
744
|
-
schema
|
|
745
|
-
};
|
|
750
|
+
return { ...table, schema };
|
|
746
751
|
}
|
|
747
752
|
function getTableShapeFromData(data) {
|
|
748
753
|
if (Array.isArray(data)) {
|
|
@@ -803,7 +808,9 @@ var __exports__ = (() => {
|
|
|
803
808
|
return concatenateArrayBuffersFromArray(sources);
|
|
804
809
|
}
|
|
805
810
|
function concatenateArrayBuffersFromArray(sources) {
|
|
806
|
-
const sourceArrays = sources.map(
|
|
811
|
+
const sourceArrays = sources.map(
|
|
812
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
813
|
+
);
|
|
807
814
|
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
808
815
|
const result = new Uint8Array(byteLength);
|
|
809
816
|
let offset = 0;
|
|
@@ -818,9 +825,7 @@ var __exports__ = (() => {
|
|
|
818
825
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
819
826
|
const textDecoder = new TextDecoder(void 0, options);
|
|
820
827
|
for await (const arrayBuffer of arrayBufferIterator) {
|
|
821
|
-
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, {
|
|
822
|
-
stream: true
|
|
823
|
-
});
|
|
828
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
824
829
|
}
|
|
825
830
|
}
|
|
826
831
|
async function* makeLineIterator(textIterator) {
|
|
@@ -841,10 +846,7 @@ var __exports__ = (() => {
|
|
|
841
846
|
async function* makeNumberedLineIterator(lineIterator) {
|
|
842
847
|
let counter = 1;
|
|
843
848
|
for await (const line of lineIterator) {
|
|
844
|
-
yield {
|
|
845
|
-
counter,
|
|
846
|
-
line
|
|
847
|
-
};
|
|
849
|
+
yield { counter, line };
|
|
848
850
|
counter++;
|
|
849
851
|
}
|
|
850
852
|
}
|
|
@@ -906,62 +908,63 @@ var __exports__ = (() => {
|
|
|
906
908
|
|
|
907
909
|
// src/lib/clarinet/clarinet.ts
|
|
908
910
|
var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
|
|
909
|
-
var STATE = function(STATE2) {
|
|
910
|
-
STATE2[STATE2["BEGIN"] = 0] = "BEGIN";
|
|
911
|
-
STATE2[STATE2["VALUE"] = 1] = "VALUE";
|
|
912
|
-
STATE2[STATE2["OPEN_OBJECT"] = 2] = "OPEN_OBJECT";
|
|
913
|
-
STATE2[STATE2["CLOSE_OBJECT"] = 3] = "CLOSE_OBJECT";
|
|
914
|
-
STATE2[STATE2["OPEN_ARRAY"] = 4] = "OPEN_ARRAY";
|
|
915
|
-
STATE2[STATE2["CLOSE_ARRAY"] = 5] = "CLOSE_ARRAY";
|
|
916
|
-
STATE2[STATE2["TEXT_ESCAPE"] = 6] = "TEXT_ESCAPE";
|
|
917
|
-
STATE2[STATE2["STRING"] = 7] = "STRING";
|
|
918
|
-
STATE2[STATE2["BACKSLASH"] = 8] = "BACKSLASH";
|
|
919
|
-
STATE2[STATE2["END"] = 9] = "END";
|
|
920
|
-
STATE2[STATE2["OPEN_KEY"] = 10] = "OPEN_KEY";
|
|
921
|
-
STATE2[STATE2["CLOSE_KEY"] = 11] = "CLOSE_KEY";
|
|
922
|
-
STATE2[STATE2["TRUE"] = 12] = "TRUE";
|
|
923
|
-
STATE2[STATE2["TRUE2"] = 13] = "TRUE2";
|
|
924
|
-
STATE2[STATE2["TRUE3"] = 14] = "TRUE3";
|
|
925
|
-
STATE2[STATE2["FALSE"] = 15] = "FALSE";
|
|
926
|
-
STATE2[STATE2["FALSE2"] = 16] = "FALSE2";
|
|
927
|
-
STATE2[STATE2["FALSE3"] = 17] = "FALSE3";
|
|
928
|
-
STATE2[STATE2["FALSE4"] = 18] = "FALSE4";
|
|
929
|
-
STATE2[STATE2["NULL"] = 19] = "NULL";
|
|
930
|
-
STATE2[STATE2["NULL2"] = 20] = "NULL2";
|
|
931
|
-
STATE2[STATE2["NULL3"] = 21] = "NULL3";
|
|
932
|
-
STATE2[STATE2["NUMBER_DECIMAL_POINT"] = 22] = "NUMBER_DECIMAL_POINT";
|
|
933
|
-
STATE2[STATE2["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
|
|
934
|
-
return STATE2;
|
|
935
|
-
}(STATE || {});
|
|
936
911
|
var Char = {
|
|
937
912
|
tab: 9,
|
|
913
|
+
// \t
|
|
938
914
|
lineFeed: 10,
|
|
915
|
+
// \n
|
|
939
916
|
carriageReturn: 13,
|
|
917
|
+
// \r
|
|
940
918
|
space: 32,
|
|
919
|
+
// " "
|
|
941
920
|
doubleQuote: 34,
|
|
921
|
+
// "
|
|
942
922
|
plus: 43,
|
|
923
|
+
// +
|
|
943
924
|
comma: 44,
|
|
925
|
+
// ,
|
|
944
926
|
minus: 45,
|
|
927
|
+
// -
|
|
945
928
|
period: 46,
|
|
929
|
+
// .
|
|
946
930
|
_0: 48,
|
|
931
|
+
// 0
|
|
947
932
|
_9: 57,
|
|
933
|
+
// 9
|
|
948
934
|
colon: 58,
|
|
935
|
+
// :
|
|
949
936
|
E: 69,
|
|
937
|
+
// E
|
|
950
938
|
openBracket: 91,
|
|
939
|
+
// [
|
|
951
940
|
backslash: 92,
|
|
941
|
+
// \
|
|
952
942
|
closeBracket: 93,
|
|
943
|
+
// ]
|
|
953
944
|
a: 97,
|
|
945
|
+
// a
|
|
954
946
|
b: 98,
|
|
947
|
+
// b
|
|
955
948
|
e: 101,
|
|
949
|
+
// e
|
|
956
950
|
f: 102,
|
|
951
|
+
// f
|
|
957
952
|
l: 108,
|
|
953
|
+
// l
|
|
958
954
|
n: 110,
|
|
955
|
+
// n
|
|
959
956
|
r: 114,
|
|
957
|
+
// r
|
|
960
958
|
s: 115,
|
|
959
|
+
// s
|
|
961
960
|
t: 116,
|
|
961
|
+
// t
|
|
962
962
|
u: 117,
|
|
963
|
+
// u
|
|
963
964
|
openBrace: 123,
|
|
965
|
+
// {
|
|
964
966
|
closeBrace: 125
|
|
967
|
+
// }
|
|
965
968
|
};
|
|
966
969
|
var stringTokenPattern = /[\\"\n]/g;
|
|
967
970
|
var DEFAULT_OPTIONS2 = {
|
|
@@ -987,35 +990,34 @@ var __exports__ = (() => {
|
|
|
987
990
|
}
|
|
988
991
|
};
|
|
989
992
|
var ClarinetParser = class {
|
|
990
|
-
options = DEFAULT_OPTIONS2;
|
|
991
|
-
bufferCheckPosition = MAX_BUFFER_LENGTH;
|
|
992
|
-
q = "";
|
|
993
|
-
c = "";
|
|
994
|
-
p = "";
|
|
995
|
-
closed = false;
|
|
996
|
-
closedRoot = false;
|
|
997
|
-
sawRoot = false;
|
|
998
|
-
error = null;
|
|
999
|
-
state = STATE.BEGIN;
|
|
1000
|
-
stack = [];
|
|
1001
|
-
position = 0;
|
|
1002
|
-
column = 0;
|
|
1003
|
-
line = 1;
|
|
1004
|
-
slashed = false;
|
|
1005
|
-
unicodeI = 0;
|
|
1006
|
-
unicodeS = null;
|
|
1007
|
-
depth = 0;
|
|
1008
993
|
constructor(options = {}) {
|
|
1009
|
-
this.options =
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
994
|
+
this.options = DEFAULT_OPTIONS2;
|
|
995
|
+
this.bufferCheckPosition = MAX_BUFFER_LENGTH;
|
|
996
|
+
this.q = "";
|
|
997
|
+
this.c = "";
|
|
998
|
+
this.p = "";
|
|
999
|
+
this.closed = false;
|
|
1000
|
+
this.closedRoot = false;
|
|
1001
|
+
this.sawRoot = false;
|
|
1002
|
+
// tag = null;
|
|
1003
|
+
this.error = null;
|
|
1004
|
+
this.state = 0 /* BEGIN */;
|
|
1005
|
+
this.stack = [];
|
|
1006
|
+
// mostly just for error reporting
|
|
1007
|
+
this.position = 0;
|
|
1008
|
+
this.column = 0;
|
|
1009
|
+
this.line = 1;
|
|
1010
|
+
this.slashed = false;
|
|
1011
|
+
this.unicodeI = 0;
|
|
1012
|
+
this.unicodeS = null;
|
|
1013
|
+
this.depth = 0;
|
|
1014
|
+
this.options = { ...DEFAULT_OPTIONS2, ...options };
|
|
1013
1015
|
this.textNode = void 0;
|
|
1014
1016
|
this.numberNode = "";
|
|
1015
1017
|
this.emit("onready");
|
|
1016
1018
|
}
|
|
1017
1019
|
end() {
|
|
1018
|
-
if (this.state !==
|
|
1020
|
+
if (this.state !== 1 /* VALUE */ || this.depth !== 0)
|
|
1019
1021
|
this._error("Unexpected end");
|
|
1020
1022
|
this._closeValue();
|
|
1021
1023
|
this.c = "";
|
|
@@ -1030,6 +1032,7 @@ var __exports__ = (() => {
|
|
|
1030
1032
|
close() {
|
|
1031
1033
|
return this.write(null);
|
|
1032
1034
|
}
|
|
1035
|
+
// protected
|
|
1033
1036
|
emit(event, data) {
|
|
1034
1037
|
this.options[event]?.(data, this);
|
|
1035
1038
|
}
|
|
@@ -1037,6 +1040,8 @@ var __exports__ = (() => {
|
|
|
1037
1040
|
this._closeValue();
|
|
1038
1041
|
this.emit(event, data);
|
|
1039
1042
|
}
|
|
1043
|
+
/* eslint-disable no-continue */
|
|
1044
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1040
1045
|
write(chunk) {
|
|
1041
1046
|
if (this.error) {
|
|
1042
1047
|
throw this.error;
|
|
@@ -1067,111 +1072,111 @@ var __exports__ = (() => {
|
|
|
1067
1072
|
} else
|
|
1068
1073
|
this.column++;
|
|
1069
1074
|
switch (this.state) {
|
|
1070
|
-
case
|
|
1075
|
+
case 0 /* BEGIN */:
|
|
1071
1076
|
if (c === Char.openBrace)
|
|
1072
|
-
this.state =
|
|
1077
|
+
this.state = 2 /* OPEN_OBJECT */;
|
|
1073
1078
|
else if (c === Char.openBracket)
|
|
1074
|
-
this.state =
|
|
1079
|
+
this.state = 4 /* OPEN_ARRAY */;
|
|
1075
1080
|
else if (!isWhitespace(c)) {
|
|
1076
1081
|
this._error("Non-whitespace before {[.");
|
|
1077
1082
|
}
|
|
1078
1083
|
continue;
|
|
1079
|
-
case
|
|
1080
|
-
case
|
|
1084
|
+
case 10 /* OPEN_KEY */:
|
|
1085
|
+
case 2 /* OPEN_OBJECT */:
|
|
1081
1086
|
if (isWhitespace(c))
|
|
1082
1087
|
continue;
|
|
1083
|
-
if (this.state ===
|
|
1084
|
-
this.stack.push(
|
|
1088
|
+
if (this.state === 10 /* OPEN_KEY */)
|
|
1089
|
+
this.stack.push(11 /* CLOSE_KEY */);
|
|
1085
1090
|
else if (c === Char.closeBrace) {
|
|
1086
1091
|
this.emit("onopenobject");
|
|
1087
1092
|
this.depth++;
|
|
1088
1093
|
this.emit("oncloseobject");
|
|
1089
1094
|
this.depth--;
|
|
1090
|
-
this.state = this.stack.pop() ||
|
|
1095
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1091
1096
|
continue;
|
|
1092
1097
|
} else
|
|
1093
|
-
this.stack.push(
|
|
1098
|
+
this.stack.push(3 /* CLOSE_OBJECT */);
|
|
1094
1099
|
if (c === Char.doubleQuote)
|
|
1095
|
-
this.state =
|
|
1100
|
+
this.state = 7 /* STRING */;
|
|
1096
1101
|
else
|
|
1097
1102
|
this._error('Malformed object key should start with "');
|
|
1098
1103
|
continue;
|
|
1099
|
-
case
|
|
1100
|
-
case
|
|
1104
|
+
case 11 /* CLOSE_KEY */:
|
|
1105
|
+
case 3 /* CLOSE_OBJECT */:
|
|
1101
1106
|
if (isWhitespace(c))
|
|
1102
1107
|
continue;
|
|
1103
1108
|
if (c === Char.colon) {
|
|
1104
|
-
if (this.state ===
|
|
1105
|
-
this.stack.push(
|
|
1109
|
+
if (this.state === 3 /* CLOSE_OBJECT */) {
|
|
1110
|
+
this.stack.push(3 /* CLOSE_OBJECT */);
|
|
1106
1111
|
this._closeValue("onopenobject");
|
|
1107
1112
|
this.depth++;
|
|
1108
1113
|
} else
|
|
1109
1114
|
this._closeValue("onkey");
|
|
1110
|
-
this.state =
|
|
1115
|
+
this.state = 1 /* VALUE */;
|
|
1111
1116
|
} else if (c === Char.closeBrace) {
|
|
1112
1117
|
this.emitNode("oncloseobject");
|
|
1113
1118
|
this.depth--;
|
|
1114
|
-
this.state = this.stack.pop() ||
|
|
1119
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1115
1120
|
} else if (c === Char.comma) {
|
|
1116
|
-
if (this.state ===
|
|
1117
|
-
this.stack.push(
|
|
1121
|
+
if (this.state === 3 /* CLOSE_OBJECT */)
|
|
1122
|
+
this.stack.push(3 /* CLOSE_OBJECT */);
|
|
1118
1123
|
this._closeValue();
|
|
1119
|
-
this.state =
|
|
1124
|
+
this.state = 10 /* OPEN_KEY */;
|
|
1120
1125
|
} else
|
|
1121
1126
|
this._error("Bad object");
|
|
1122
1127
|
continue;
|
|
1123
|
-
case
|
|
1124
|
-
case
|
|
1128
|
+
case 4 /* OPEN_ARRAY */:
|
|
1129
|
+
case 1 /* VALUE */:
|
|
1125
1130
|
if (isWhitespace(c))
|
|
1126
1131
|
continue;
|
|
1127
|
-
if (this.state ===
|
|
1132
|
+
if (this.state === 4 /* OPEN_ARRAY */) {
|
|
1128
1133
|
this.emit("onopenarray");
|
|
1129
1134
|
this.depth++;
|
|
1130
|
-
this.state =
|
|
1135
|
+
this.state = 1 /* VALUE */;
|
|
1131
1136
|
if (c === Char.closeBracket) {
|
|
1132
1137
|
this.emit("onclosearray");
|
|
1133
1138
|
this.depth--;
|
|
1134
|
-
this.state = this.stack.pop() ||
|
|
1139
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1135
1140
|
continue;
|
|
1136
1141
|
} else {
|
|
1137
|
-
this.stack.push(
|
|
1142
|
+
this.stack.push(5 /* CLOSE_ARRAY */);
|
|
1138
1143
|
}
|
|
1139
1144
|
}
|
|
1140
1145
|
if (c === Char.doubleQuote)
|
|
1141
|
-
this.state =
|
|
1146
|
+
this.state = 7 /* STRING */;
|
|
1142
1147
|
else if (c === Char.openBrace)
|
|
1143
|
-
this.state =
|
|
1148
|
+
this.state = 2 /* OPEN_OBJECT */;
|
|
1144
1149
|
else if (c === Char.openBracket)
|
|
1145
|
-
this.state =
|
|
1150
|
+
this.state = 4 /* OPEN_ARRAY */;
|
|
1146
1151
|
else if (c === Char.t)
|
|
1147
|
-
this.state =
|
|
1152
|
+
this.state = 12 /* TRUE */;
|
|
1148
1153
|
else if (c === Char.f)
|
|
1149
|
-
this.state =
|
|
1154
|
+
this.state = 15 /* FALSE */;
|
|
1150
1155
|
else if (c === Char.n)
|
|
1151
|
-
this.state =
|
|
1156
|
+
this.state = 19 /* NULL */;
|
|
1152
1157
|
else if (c === Char.minus) {
|
|
1153
1158
|
this.numberNode += "-";
|
|
1154
1159
|
} else if (Char._0 <= c && c <= Char._9) {
|
|
1155
1160
|
this.numberNode += String.fromCharCode(c);
|
|
1156
|
-
this.state =
|
|
1161
|
+
this.state = 23 /* NUMBER_DIGIT */;
|
|
1157
1162
|
} else
|
|
1158
1163
|
this._error("Bad value");
|
|
1159
1164
|
continue;
|
|
1160
|
-
case
|
|
1165
|
+
case 5 /* CLOSE_ARRAY */:
|
|
1161
1166
|
if (c === Char.comma) {
|
|
1162
|
-
this.stack.push(
|
|
1167
|
+
this.stack.push(5 /* CLOSE_ARRAY */);
|
|
1163
1168
|
this._closeValue("onvalue");
|
|
1164
|
-
this.state =
|
|
1169
|
+
this.state = 1 /* VALUE */;
|
|
1165
1170
|
} else if (c === Char.closeBracket) {
|
|
1166
1171
|
this.emitNode("onclosearray");
|
|
1167
1172
|
this.depth--;
|
|
1168
|
-
this.state = this.stack.pop() ||
|
|
1173
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1169
1174
|
} else if (isWhitespace(c))
|
|
1170
1175
|
continue;
|
|
1171
1176
|
else
|
|
1172
1177
|
this._error("Bad array");
|
|
1173
1178
|
continue;
|
|
1174
|
-
case
|
|
1179
|
+
case 7 /* STRING */:
|
|
1175
1180
|
if (this.textNode === void 0) {
|
|
1176
1181
|
this.textNode = "";
|
|
1177
1182
|
}
|
|
@@ -1195,7 +1200,7 @@ var __exports__ = (() => {
|
|
|
1195
1200
|
break STRING_BIGLOOP;
|
|
1196
1201
|
}
|
|
1197
1202
|
if (c === Char.doubleQuote && !slashed) {
|
|
1198
|
-
this.state = this.stack.pop() ||
|
|
1203
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1199
1204
|
this.textNode += chunk.substring(starti, i - 1);
|
|
1200
1205
|
this.position += i - 1 - starti;
|
|
1201
1206
|
break;
|
|
@@ -1254,77 +1259,77 @@ var __exports__ = (() => {
|
|
|
1254
1259
|
this.slashed = slashed;
|
|
1255
1260
|
this.unicodeI = unicodeI;
|
|
1256
1261
|
continue;
|
|
1257
|
-
case
|
|
1262
|
+
case 12 /* TRUE */:
|
|
1258
1263
|
if (c === Char.r)
|
|
1259
|
-
this.state =
|
|
1264
|
+
this.state = 13 /* TRUE2 */;
|
|
1260
1265
|
else
|
|
1261
1266
|
this._error(`Invalid true started with t${c}`);
|
|
1262
1267
|
continue;
|
|
1263
|
-
case
|
|
1268
|
+
case 13 /* TRUE2 */:
|
|
1264
1269
|
if (c === Char.u)
|
|
1265
|
-
this.state =
|
|
1270
|
+
this.state = 14 /* TRUE3 */;
|
|
1266
1271
|
else
|
|
1267
1272
|
this._error(`Invalid true started with tr${c}`);
|
|
1268
1273
|
continue;
|
|
1269
|
-
case
|
|
1274
|
+
case 14 /* TRUE3 */:
|
|
1270
1275
|
if (c === Char.e) {
|
|
1271
1276
|
this.emit("onvalue", true);
|
|
1272
|
-
this.state = this.stack.pop() ||
|
|
1277
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1273
1278
|
} else
|
|
1274
1279
|
this._error(`Invalid true started with tru${c}`);
|
|
1275
1280
|
continue;
|
|
1276
|
-
case
|
|
1281
|
+
case 15 /* FALSE */:
|
|
1277
1282
|
if (c === Char.a)
|
|
1278
|
-
this.state =
|
|
1283
|
+
this.state = 16 /* FALSE2 */;
|
|
1279
1284
|
else
|
|
1280
1285
|
this._error(`Invalid false started with f${c}`);
|
|
1281
1286
|
continue;
|
|
1282
|
-
case
|
|
1287
|
+
case 16 /* FALSE2 */:
|
|
1283
1288
|
if (c === Char.l)
|
|
1284
|
-
this.state =
|
|
1289
|
+
this.state = 17 /* FALSE3 */;
|
|
1285
1290
|
else
|
|
1286
1291
|
this._error(`Invalid false started with fa${c}`);
|
|
1287
1292
|
continue;
|
|
1288
|
-
case
|
|
1293
|
+
case 17 /* FALSE3 */:
|
|
1289
1294
|
if (c === Char.s)
|
|
1290
|
-
this.state =
|
|
1295
|
+
this.state = 18 /* FALSE4 */;
|
|
1291
1296
|
else
|
|
1292
1297
|
this._error(`Invalid false started with fal${c}`);
|
|
1293
1298
|
continue;
|
|
1294
|
-
case
|
|
1299
|
+
case 18 /* FALSE4 */:
|
|
1295
1300
|
if (c === Char.e) {
|
|
1296
1301
|
this.emit("onvalue", false);
|
|
1297
|
-
this.state = this.stack.pop() ||
|
|
1302
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1298
1303
|
} else
|
|
1299
1304
|
this._error(`Invalid false started with fals${c}`);
|
|
1300
1305
|
continue;
|
|
1301
|
-
case
|
|
1306
|
+
case 19 /* NULL */:
|
|
1302
1307
|
if (c === Char.u)
|
|
1303
|
-
this.state =
|
|
1308
|
+
this.state = 20 /* NULL2 */;
|
|
1304
1309
|
else
|
|
1305
1310
|
this._error(`Invalid null started with n${c}`);
|
|
1306
1311
|
continue;
|
|
1307
|
-
case
|
|
1312
|
+
case 20 /* NULL2 */:
|
|
1308
1313
|
if (c === Char.l)
|
|
1309
|
-
this.state =
|
|
1314
|
+
this.state = 21 /* NULL3 */;
|
|
1310
1315
|
else
|
|
1311
1316
|
this._error(`Invalid null started with nu${c}`);
|
|
1312
1317
|
continue;
|
|
1313
|
-
case
|
|
1318
|
+
case 21 /* NULL3 */:
|
|
1314
1319
|
if (c === Char.l) {
|
|
1315
1320
|
this.emit("onvalue", null);
|
|
1316
|
-
this.state = this.stack.pop() ||
|
|
1321
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1317
1322
|
} else
|
|
1318
1323
|
this._error(`Invalid null started with nul${c}`);
|
|
1319
1324
|
continue;
|
|
1320
|
-
case
|
|
1325
|
+
case 22 /* NUMBER_DECIMAL_POINT */:
|
|
1321
1326
|
if (c === Char.period) {
|
|
1322
1327
|
this.numberNode += ".";
|
|
1323
|
-
this.state =
|
|
1328
|
+
this.state = 23 /* NUMBER_DIGIT */;
|
|
1324
1329
|
} else
|
|
1325
1330
|
this._error("Leading zero not followed by .");
|
|
1326
1331
|
continue;
|
|
1327
|
-
case
|
|
1332
|
+
case 23 /* NUMBER_DIGIT */:
|
|
1328
1333
|
if (Char._0 <= c && c <= Char._9)
|
|
1329
1334
|
this.numberNode += String.fromCharCode(c);
|
|
1330
1335
|
else if (c === Char.period) {
|
|
@@ -1342,7 +1347,7 @@ var __exports__ = (() => {
|
|
|
1342
1347
|
} else {
|
|
1343
1348
|
this._closeNumber();
|
|
1344
1349
|
i--;
|
|
1345
|
-
this.state = this.stack.pop() ||
|
|
1350
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1346
1351
|
}
|
|
1347
1352
|
continue;
|
|
1348
1353
|
default:
|
|
@@ -1443,6 +1448,12 @@ Char: ${this.c}`;
|
|
|
1443
1448
|
}
|
|
1444
1449
|
return true;
|
|
1445
1450
|
}
|
|
1451
|
+
/**
|
|
1452
|
+
* Sets the value pointed at by path
|
|
1453
|
+
* TODO - handle root path
|
|
1454
|
+
* @param object
|
|
1455
|
+
* @param value
|
|
1456
|
+
*/
|
|
1446
1457
|
setFieldAtPath(object, value) {
|
|
1447
1458
|
const path = [...this.path];
|
|
1448
1459
|
path.shift();
|
|
@@ -1452,6 +1463,11 @@ Char: ${this.c}`;
|
|
|
1452
1463
|
}
|
|
1453
1464
|
object[field] = value;
|
|
1454
1465
|
}
|
|
1466
|
+
/**
|
|
1467
|
+
* Gets the value pointed at by path
|
|
1468
|
+
* TODO - handle root path
|
|
1469
|
+
* @param object
|
|
1470
|
+
*/
|
|
1455
1471
|
getFieldAtPath(object) {
|
|
1456
1472
|
const path = [...this.path];
|
|
1457
1473
|
path.shift();
|
|
@@ -1465,14 +1481,11 @@ Char: ${this.c}`;
|
|
|
1465
1481
|
|
|
1466
1482
|
// src/lib/json-parser/json-parser.ts
|
|
1467
1483
|
var JSONParser = class {
|
|
1468
|
-
result = void 0;
|
|
1469
|
-
previousStates = [];
|
|
1470
|
-
currentState = Object.freeze({
|
|
1471
|
-
container: [],
|
|
1472
|
-
key: null
|
|
1473
|
-
});
|
|
1474
|
-
jsonpath = new JSONPath();
|
|
1475
1484
|
constructor(options) {
|
|
1485
|
+
this.result = void 0;
|
|
1486
|
+
this.previousStates = [];
|
|
1487
|
+
this.currentState = Object.freeze({ container: [], key: null });
|
|
1488
|
+
this.jsonpath = new JSONPath();
|
|
1476
1489
|
this.reset();
|
|
1477
1490
|
this.parser = new ClarinetParser({
|
|
1478
1491
|
onready: () => {
|
|
@@ -1514,10 +1527,7 @@ Char: ${this.c}`;
|
|
|
1514
1527
|
reset() {
|
|
1515
1528
|
this.result = void 0;
|
|
1516
1529
|
this.previousStates = [];
|
|
1517
|
-
this.currentState = Object.freeze({
|
|
1518
|
-
container: [],
|
|
1519
|
-
key: null
|
|
1520
|
-
});
|
|
1530
|
+
this.currentState = Object.freeze({ container: [], key: null });
|
|
1521
1531
|
this.jsonpath = new JSONPath();
|
|
1522
1532
|
}
|
|
1523
1533
|
write(chunk) {
|
|
@@ -1526,11 +1536,9 @@ Char: ${this.c}`;
|
|
|
1526
1536
|
close() {
|
|
1527
1537
|
this.parser.close();
|
|
1528
1538
|
}
|
|
1539
|
+
// PRIVATE METHODS
|
|
1529
1540
|
_pushOrSet(value) {
|
|
1530
|
-
const {
|
|
1531
|
-
container,
|
|
1532
|
-
key
|
|
1533
|
-
} = this.currentState;
|
|
1541
|
+
const { container, key } = this.currentState;
|
|
1534
1542
|
if (key !== null) {
|
|
1535
1543
|
container[key] = value;
|
|
1536
1544
|
this.currentState.key = null;
|
|
@@ -1542,11 +1550,7 @@ Char: ${this.c}`;
|
|
|
1542
1550
|
this.jsonpath.push(null);
|
|
1543
1551
|
this._pushOrSet(newContainer);
|
|
1544
1552
|
this.previousStates.push(this.currentState);
|
|
1545
|
-
this.currentState = {
|
|
1546
|
-
container: newContainer,
|
|
1547
|
-
isArray: true,
|
|
1548
|
-
key: null
|
|
1549
|
-
};
|
|
1553
|
+
this.currentState = { container: newContainer, isArray: true, key: null };
|
|
1550
1554
|
}
|
|
1551
1555
|
_closeArray() {
|
|
1552
1556
|
this.jsonpath.pop();
|
|
@@ -1556,11 +1560,7 @@ Char: ${this.c}`;
|
|
|
1556
1560
|
this.jsonpath.push(null);
|
|
1557
1561
|
this._pushOrSet(newContainer);
|
|
1558
1562
|
this.previousStates.push(this.currentState);
|
|
1559
|
-
this.currentState = {
|
|
1560
|
-
container: newContainer,
|
|
1561
|
-
isArray: false,
|
|
1562
|
-
key: null
|
|
1563
|
-
};
|
|
1563
|
+
this.currentState = { container: newContainer, isArray: false, key: null };
|
|
1564
1564
|
}
|
|
1565
1565
|
_closeObject() {
|
|
1566
1566
|
this.jsonpath.pop();
|
|
@@ -1570,9 +1570,6 @@ Char: ${this.c}`;
|
|
|
1570
1570
|
|
|
1571
1571
|
// src/lib/json-parser/streaming-json-parser.ts
|
|
1572
1572
|
var StreamingJSONParser = class extends JSONParser {
|
|
1573
|
-
streamingJsonPath = null;
|
|
1574
|
-
streamingArray = null;
|
|
1575
|
-
topLevelObject = null;
|
|
1576
1573
|
constructor(options = {}) {
|
|
1577
1574
|
super({
|
|
1578
1575
|
onopenarray: () => {
|
|
@@ -1586,6 +1583,7 @@ Char: ${this.c}`;
|
|
|
1586
1583
|
}
|
|
1587
1584
|
this._openArray();
|
|
1588
1585
|
},
|
|
1586
|
+
// Redefine onopenarray to inject value for top-level object
|
|
1589
1587
|
onopenobject: (name) => {
|
|
1590
1588
|
if (!this.topLevelObject) {
|
|
1591
1589
|
this.topLevelObject = {};
|
|
@@ -1598,9 +1596,19 @@ Char: ${this.c}`;
|
|
|
1598
1596
|
}
|
|
1599
1597
|
}
|
|
1600
1598
|
});
|
|
1599
|
+
this.streamingJsonPath = null;
|
|
1600
|
+
this.streamingArray = null;
|
|
1601
|
+
this.topLevelObject = null;
|
|
1601
1602
|
const jsonpaths = options.jsonpaths || [];
|
|
1602
1603
|
this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));
|
|
1603
1604
|
}
|
|
1605
|
+
/**
|
|
1606
|
+
* write REDEFINITION
|
|
1607
|
+
* - super.write() chunk to parser
|
|
1608
|
+
* - get the contents (so far) of "topmost-level" array as batch of rows
|
|
1609
|
+
* - clear top-level array
|
|
1610
|
+
* - return the batch of rows\
|
|
1611
|
+
*/
|
|
1604
1612
|
write(chunk) {
|
|
1605
1613
|
super.write(chunk);
|
|
1606
1614
|
let array = [];
|
|
@@ -1610,6 +1618,11 @@ Char: ${this.c}`;
|
|
|
1610
1618
|
}
|
|
1611
1619
|
return array;
|
|
1612
1620
|
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Returns a partially formed result object
|
|
1623
|
+
* Useful for returning the "wrapper" object when array is not top level
|
|
1624
|
+
* e.g. GeoJSON
|
|
1625
|
+
*/
|
|
1613
1626
|
getPartialResult() {
|
|
1614
1627
|
return this.topLevelObject;
|
|
1615
1628
|
}
|
|
@@ -1622,6 +1635,10 @@ Char: ${this.c}`;
|
|
|
1622
1635
|
getJsonPath() {
|
|
1623
1636
|
return this.jsonpath;
|
|
1624
1637
|
}
|
|
1638
|
+
// PRIVATE METHODS
|
|
1639
|
+
/**
|
|
1640
|
+
* Checks is this.getJsonPath matches the jsonpaths provided in options
|
|
1641
|
+
*/
|
|
1625
1642
|
_matchJSONPath() {
|
|
1626
1643
|
const currentPath = this.getJsonPath();
|
|
1627
1644
|
if (this.jsonPaths.length === 0) {
|
|
@@ -1639,29 +1656,25 @@ Char: ${this.c}`;
|
|
|
1639
1656
|
// src/lib/parsers/parse-json-in-batches.ts
|
|
1640
1657
|
async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
1641
1658
|
const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
|
|
1642
|
-
const {
|
|
1643
|
-
|
|
1644
|
-
} = options;
|
|
1645
|
-
const {
|
|
1646
|
-
jsonpaths
|
|
1647
|
-
} = options.json || {};
|
|
1659
|
+
const { metadata } = options;
|
|
1660
|
+
const { jsonpaths } = options.json || {};
|
|
1648
1661
|
let isFirstChunk = true;
|
|
1649
1662
|
const schema = null;
|
|
1650
1663
|
const tableBatchBuilder = new TableBatchBuilder(schema, options);
|
|
1651
|
-
const parser = new StreamingJSONParser({
|
|
1652
|
-
jsonpaths
|
|
1653
|
-
});
|
|
1664
|
+
const parser = new StreamingJSONParser({ jsonpaths });
|
|
1654
1665
|
for await (const chunk of asyncIterator) {
|
|
1655
1666
|
const rows = parser.write(chunk);
|
|
1656
1667
|
const jsonpath2 = rows.length > 0 && parser.getStreamingJsonPathAsString();
|
|
1657
1668
|
if (rows.length > 0 && isFirstChunk) {
|
|
1658
1669
|
if (metadata) {
|
|
1659
1670
|
const initialBatch = {
|
|
1671
|
+
// Common fields
|
|
1660
1672
|
shape: options?.json?.shape || "array-row-table",
|
|
1661
1673
|
batchType: "partial-result",
|
|
1662
1674
|
data: [],
|
|
1663
1675
|
length: 0,
|
|
1664
1676
|
bytesUsed: 0,
|
|
1677
|
+
// JSON additions
|
|
1665
1678
|
container: parser.getPartialResult(),
|
|
1666
1679
|
jsonpath: jsonpath2
|
|
1667
1680
|
};
|
|
@@ -1671,25 +1684,19 @@ Char: ${this.c}`;
|
|
|
1671
1684
|
}
|
|
1672
1685
|
for (const row of rows) {
|
|
1673
1686
|
tableBatchBuilder.addRow(row);
|
|
1674
|
-
const batch3 = tableBatchBuilder.getFullBatch({
|
|
1675
|
-
jsonpath: jsonpath2
|
|
1676
|
-
});
|
|
1687
|
+
const batch3 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
|
|
1677
1688
|
if (batch3) {
|
|
1678
1689
|
yield batch3;
|
|
1679
1690
|
}
|
|
1680
1691
|
}
|
|
1681
1692
|
tableBatchBuilder.chunkComplete(chunk);
|
|
1682
|
-
const batch2 = tableBatchBuilder.getFullBatch({
|
|
1683
|
-
jsonpath: jsonpath2
|
|
1684
|
-
});
|
|
1693
|
+
const batch2 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
|
|
1685
1694
|
if (batch2) {
|
|
1686
1695
|
yield batch2;
|
|
1687
1696
|
}
|
|
1688
1697
|
}
|
|
1689
1698
|
const jsonpath = parser.getStreamingJsonPathAsString();
|
|
1690
|
-
const batch = tableBatchBuilder.getFinalBatch({
|
|
1691
|
-
jsonpath
|
|
1692
|
-
});
|
|
1699
|
+
const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
|
|
1693
1700
|
if (batch) {
|
|
1694
1701
|
yield batch;
|
|
1695
1702
|
}
|
|
@@ -1699,8 +1706,10 @@ Char: ${this.c}`;
|
|
|
1699
1706
|
batchType: "final-result",
|
|
1700
1707
|
container: parser.getPartialResult(),
|
|
1701
1708
|
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
1709
|
+
/** Data Just to avoid crashing? */
|
|
1702
1710
|
data: [],
|
|
1703
1711
|
length: 0
|
|
1712
|
+
// schema: null
|
|
1704
1713
|
};
|
|
1705
1714
|
yield finalBatch;
|
|
1706
1715
|
}
|
|
@@ -1720,7 +1729,7 @@ Char: ${this.c}`;
|
|
|
1720
1729
|
}
|
|
1721
1730
|
|
|
1722
1731
|
// src/json-loader.ts
|
|
1723
|
-
var VERSION =
|
|
1732
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1724
1733
|
var JSONLoader = {
|
|
1725
1734
|
name: "JSON",
|
|
1726
1735
|
id: "json",
|
|
@@ -1735,6 +1744,7 @@ Char: ${this.c}`;
|
|
|
1735
1744
|
shape: void 0,
|
|
1736
1745
|
table: false,
|
|
1737
1746
|
jsonpaths: []
|
|
1747
|
+
// batchSize: 'auto'
|
|
1738
1748
|
}
|
|
1739
1749
|
},
|
|
1740
1750
|
parse,
|
|
@@ -1745,23 +1755,11 @@ Char: ${this.c}`;
|
|
|
1745
1755
|
return parseTextSync(new TextDecoder().decode(arrayBuffer), options);
|
|
1746
1756
|
}
|
|
1747
1757
|
function parseTextSync(text, options) {
|
|
1748
|
-
const jsonOptions = {
|
|
1749
|
-
...options,
|
|
1750
|
-
json: {
|
|
1751
|
-
...JSONLoader.options.json,
|
|
1752
|
-
...options?.json
|
|
1753
|
-
}
|
|
1754
|
-
};
|
|
1758
|
+
const jsonOptions = { ...options, json: { ...JSONLoader.options.json, ...options?.json } };
|
|
1755
1759
|
return parseJSONSync(text, jsonOptions);
|
|
1756
1760
|
}
|
|
1757
1761
|
function parseInBatches(asyncIterator, options) {
|
|
1758
|
-
const jsonOptions = {
|
|
1759
|
-
...options,
|
|
1760
|
-
json: {
|
|
1761
|
-
...JSONLoader.options.json,
|
|
1762
|
-
...options?.json
|
|
1763
|
-
}
|
|
1764
|
-
};
|
|
1762
|
+
const jsonOptions = { ...options, json: { ...JSONLoader.options.json, ...options?.json } };
|
|
1765
1763
|
return parseJSONInBatches(asyncIterator, jsonOptions);
|
|
1766
1764
|
}
|
|
1767
1765
|
|
|
@@ -1789,10 +1787,7 @@ Char: ${this.c}`;
|
|
|
1789
1787
|
...options,
|
|
1790
1788
|
shape
|
|
1791
1789
|
});
|
|
1792
|
-
for await (const {
|
|
1793
|
-
counter,
|
|
1794
|
-
line
|
|
1795
|
-
} of numberedLineIterator) {
|
|
1790
|
+
for await (const { counter, line } of numberedLineIterator) {
|
|
1796
1791
|
try {
|
|
1797
1792
|
const row = JSON.parse(line);
|
|
1798
1793
|
tableBatchBuilder.addRow(row);
|
|
@@ -1812,14 +1807,19 @@ Char: ${this.c}`;
|
|
|
1812
1807
|
}
|
|
1813
1808
|
|
|
1814
1809
|
// src/ndjson-loader.ts
|
|
1815
|
-
var VERSION2 =
|
|
1810
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1816
1811
|
var NDJSONLoader = {
|
|
1817
1812
|
name: "NDJSON",
|
|
1818
1813
|
id: "ndjson",
|
|
1819
1814
|
module: "json",
|
|
1820
1815
|
version: VERSION2,
|
|
1821
1816
|
extensions: ["ndjson", "jsonl"],
|
|
1822
|
-
mimeTypes: [
|
|
1817
|
+
mimeTypes: [
|
|
1818
|
+
"application/x-ndjson",
|
|
1819
|
+
"application/jsonlines",
|
|
1820
|
+
// https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#cm-batch
|
|
1821
|
+
"application/json-seq"
|
|
1822
|
+
],
|
|
1823
1823
|
category: "table",
|
|
1824
1824
|
text: true,
|
|
1825
1825
|
parse: async (arrayBuffer) => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),
|
|
@@ -2370,14 +2370,18 @@ Char: ${this.c}`;
|
|
|
2370
2370
|
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
2371
2371
|
const propArrayTypes = extractNumericPropTypes(features);
|
|
2372
2372
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
2373
|
-
return fillArrays(
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2373
|
+
return fillArrays(
|
|
2374
|
+
features,
|
|
2375
|
+
{
|
|
2376
|
+
propArrayTypes,
|
|
2377
|
+
...geometryInfo
|
|
2378
|
+
},
|
|
2379
|
+
{
|
|
2380
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
2381
|
+
PositionDataType: options ? options.PositionDataType : Float32Array,
|
|
2382
|
+
triangulate: options ? options.triangulate : true
|
|
2383
|
+
}
|
|
2384
|
+
);
|
|
2381
2385
|
}
|
|
2382
2386
|
function extractNumericPropTypes(features) {
|
|
2383
2387
|
const propArrayTypes = {};
|
|
@@ -2405,11 +2409,7 @@ Char: ${this.c}`;
|
|
|
2405
2409
|
propArrayTypes,
|
|
2406
2410
|
coordLength
|
|
2407
2411
|
} = geometryInfo;
|
|
2408
|
-
const {
|
|
2409
|
-
numericPropKeys = [],
|
|
2410
|
-
PositionDataType = Float32Array,
|
|
2411
|
-
triangulate = true
|
|
2412
|
-
} = options;
|
|
2412
|
+
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
2413
2413
|
const hasGlobalId = features[0] && "id" in features[0];
|
|
2414
2414
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
2415
2415
|
const points = {
|
|
@@ -2474,9 +2474,7 @@ Char: ${this.c}`;
|
|
|
2474
2474
|
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
2475
2475
|
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2476
2476
|
if (hasGlobalId) {
|
|
2477
|
-
points.fields.push({
|
|
2478
|
-
id: feature.id
|
|
2479
|
-
});
|
|
2477
|
+
points.fields.push({ id: feature.id });
|
|
2480
2478
|
}
|
|
2481
2479
|
indexMap.pointFeature++;
|
|
2482
2480
|
break;
|
|
@@ -2484,9 +2482,7 @@ Char: ${this.c}`;
|
|
|
2484
2482
|
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
2485
2483
|
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2486
2484
|
if (hasGlobalId) {
|
|
2487
|
-
lines.fields.push({
|
|
2488
|
-
id: feature.id
|
|
2489
|
-
});
|
|
2485
|
+
lines.fields.push({ id: feature.id });
|
|
2490
2486
|
}
|
|
2491
2487
|
indexMap.lineFeature++;
|
|
2492
2488
|
break;
|
|
@@ -2494,9 +2490,7 @@ Char: ${this.c}`;
|
|
|
2494
2490
|
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
2495
2491
|
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2496
2492
|
if (hasGlobalId) {
|
|
2497
|
-
polygons.fields.push({
|
|
2498
|
-
id: feature.id
|
|
2499
|
-
});
|
|
2493
|
+
polygons.fields.push({ id: feature.id });
|
|
2500
2494
|
}
|
|
2501
2495
|
indexMap.polygonFeature++;
|
|
2502
2496
|
break;
|
|
@@ -2511,16 +2505,32 @@ Char: ${this.c}`;
|
|
|
2511
2505
|
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
2512
2506
|
const nPositions = geometry.data.length / coordLength;
|
|
2513
2507
|
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
2514
|
-
points.globalFeatureIds.fill(
|
|
2515
|
-
|
|
2508
|
+
points.globalFeatureIds.fill(
|
|
2509
|
+
indexMap.feature,
|
|
2510
|
+
indexMap.pointPosition,
|
|
2511
|
+
indexMap.pointPosition + nPositions
|
|
2512
|
+
);
|
|
2513
|
+
points.featureIds.fill(
|
|
2514
|
+
indexMap.pointFeature,
|
|
2515
|
+
indexMap.pointPosition,
|
|
2516
|
+
indexMap.pointPosition + nPositions
|
|
2517
|
+
);
|
|
2516
2518
|
indexMap.pointPosition += nPositions;
|
|
2517
2519
|
}
|
|
2518
2520
|
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
2519
2521
|
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
2520
2522
|
const nPositions = geometry.data.length / coordLength;
|
|
2521
2523
|
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
2522
|
-
lines.globalFeatureIds.fill(
|
|
2523
|
-
|
|
2524
|
+
lines.globalFeatureIds.fill(
|
|
2525
|
+
indexMap.feature,
|
|
2526
|
+
indexMap.linePosition,
|
|
2527
|
+
indexMap.linePosition + nPositions
|
|
2528
|
+
);
|
|
2529
|
+
lines.featureIds.fill(
|
|
2530
|
+
indexMap.lineFeature,
|
|
2531
|
+
indexMap.linePosition,
|
|
2532
|
+
indexMap.linePosition + nPositions
|
|
2533
|
+
);
|
|
2524
2534
|
for (let i = 0, il = geometry.indices.length; i < il; ++i) {
|
|
2525
2535
|
const start = geometry.indices[i];
|
|
2526
2536
|
const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
|
|
@@ -2532,8 +2542,16 @@ Char: ${this.c}`;
|
|
|
2532
2542
|
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
2533
2543
|
const nPositions = geometry.data.length / coordLength;
|
|
2534
2544
|
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
2535
|
-
polygons.globalFeatureIds.fill(
|
|
2536
|
-
|
|
2545
|
+
polygons.globalFeatureIds.fill(
|
|
2546
|
+
indexMap.feature,
|
|
2547
|
+
indexMap.polygonPosition,
|
|
2548
|
+
indexMap.polygonPosition + nPositions
|
|
2549
|
+
);
|
|
2550
|
+
polygons.featureIds.fill(
|
|
2551
|
+
indexMap.polygonFeature,
|
|
2552
|
+
indexMap.polygonPosition,
|
|
2553
|
+
indexMap.polygonPosition + nPositions
|
|
2554
|
+
);
|
|
2537
2555
|
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
2538
2556
|
const startPosition = indexMap.polygonPosition;
|
|
2539
2557
|
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
@@ -2542,16 +2560,15 @@ Char: ${this.c}`;
|
|
|
2542
2560
|
const nextIndices = geometry.indices[l + 1];
|
|
2543
2561
|
for (let i = 0, il = indices.length; i < il; ++i) {
|
|
2544
2562
|
const start = indices[i];
|
|
2545
|
-
const end = i === il - 1 ?
|
|
2563
|
+
const end = i === il - 1 ? (
|
|
2564
|
+
// last line, so either read to:
|
|
2565
|
+
nextIndices === void 0 ? geometry.data.length : nextIndices[0]
|
|
2566
|
+
) : indices[i + 1];
|
|
2546
2567
|
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
2547
2568
|
indexMap.polygonPosition += (end - start) / coordLength;
|
|
2548
2569
|
}
|
|
2549
2570
|
const endPosition = indexMap.polygonPosition;
|
|
2550
|
-
triangulatePolygon(polygons, areas, indices, {
|
|
2551
|
-
startPosition,
|
|
2552
|
-
endPosition,
|
|
2553
|
-
coordLength
|
|
2554
|
-
});
|
|
2571
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
2555
2572
|
}
|
|
2556
2573
|
}
|
|
2557
2574
|
function triangulatePolygon(polygons, areas, indices, {
|
|
@@ -2575,10 +2592,7 @@ Char: ${this.c}`;
|
|
|
2575
2592
|
function wrapProps(obj, size) {
|
|
2576
2593
|
const returnObj = {};
|
|
2577
2594
|
for (const key in obj) {
|
|
2578
|
-
returnObj[key] = {
|
|
2579
|
-
value: obj[key],
|
|
2580
|
-
size
|
|
2581
|
-
};
|
|
2595
|
+
returnObj[key] = { value: obj[key], size };
|
|
2582
2596
|
}
|
|
2583
2597
|
return returnObj;
|
|
2584
2598
|
}
|
|
@@ -2587,70 +2601,32 @@ Char: ${this.c}`;
|
|
|
2587
2601
|
shape: "binary-feature-collection",
|
|
2588
2602
|
points: {
|
|
2589
2603
|
...points,
|
|
2590
|
-
positions: {
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
},
|
|
2594
|
-
globalFeatureIds: {
|
|
2595
|
-
value: points.globalFeatureIds,
|
|
2596
|
-
size: 1
|
|
2597
|
-
},
|
|
2598
|
-
featureIds: {
|
|
2599
|
-
value: points.featureIds,
|
|
2600
|
-
size: 1
|
|
2601
|
-
},
|
|
2604
|
+
positions: { value: points.positions, size: coordLength },
|
|
2605
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
2606
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
2602
2607
|
numericProps: wrapProps(points.numericProps, 1)
|
|
2603
2608
|
},
|
|
2604
2609
|
lines: {
|
|
2605
2610
|
...lines,
|
|
2606
|
-
positions: {
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
},
|
|
2610
|
-
pathIndices: {
|
|
2611
|
-
value: lines.pathIndices,
|
|
2612
|
-
size: 1
|
|
2613
|
-
},
|
|
2614
|
-
globalFeatureIds: {
|
|
2615
|
-
value: lines.globalFeatureIds,
|
|
2616
|
-
size: 1
|
|
2617
|
-
},
|
|
2618
|
-
featureIds: {
|
|
2619
|
-
value: lines.featureIds,
|
|
2620
|
-
size: 1
|
|
2621
|
-
},
|
|
2611
|
+
positions: { value: lines.positions, size: coordLength },
|
|
2612
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
2613
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
2614
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
2622
2615
|
numericProps: wrapProps(lines.numericProps, 1)
|
|
2623
2616
|
},
|
|
2624
2617
|
polygons: {
|
|
2625
2618
|
...polygons,
|
|
2626
|
-
positions: {
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
},
|
|
2630
|
-
|
|
2631
|
-
value: polygons.polygonIndices,
|
|
2632
|
-
size: 1
|
|
2633
|
-
},
|
|
2634
|
-
primitivePolygonIndices: {
|
|
2635
|
-
value: polygons.primitivePolygonIndices,
|
|
2636
|
-
size: 1
|
|
2637
|
-
},
|
|
2638
|
-
globalFeatureIds: {
|
|
2639
|
-
value: polygons.globalFeatureIds,
|
|
2640
|
-
size: 1
|
|
2641
|
-
},
|
|
2642
|
-
featureIds: {
|
|
2643
|
-
value: polygons.featureIds,
|
|
2644
|
-
size: 1
|
|
2645
|
-
},
|
|
2619
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
2620
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
2621
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
2622
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
2623
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
2646
2624
|
numericProps: wrapProps(polygons.numericProps, 1)
|
|
2647
2625
|
}
|
|
2626
|
+
// triangles not expected
|
|
2648
2627
|
};
|
|
2649
2628
|
if (binaryFeatures.polygons && polygons.triangles) {
|
|
2650
|
-
binaryFeatures.polygons.triangles = {
|
|
2651
|
-
value: new Uint32Array(polygons.triangles),
|
|
2652
|
-
size: 1
|
|
2653
|
-
};
|
|
2629
|
+
binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
|
|
2654
2630
|
}
|
|
2655
2631
|
return binaryFeatures;
|
|
2656
2632
|
}
|
|
@@ -2764,10 +2740,7 @@ Char: ${this.c}`;
|
|
|
2764
2740
|
}
|
|
2765
2741
|
|
|
2766
2742
|
// ../gis/src/lib/binary-features/geojson-to-flat-geojson.ts
|
|
2767
|
-
function geojsonToFlatGeojson(features, options = {
|
|
2768
|
-
coordLength: 2,
|
|
2769
|
-
fixRingWinding: true
|
|
2770
|
-
}) {
|
|
2743
|
+
function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
|
|
2771
2744
|
return features.map((feature) => flattenFeature(feature, options));
|
|
2772
2745
|
}
|
|
2773
2746
|
function flattenPoint(coordinates, data, indices, options) {
|
|
@@ -2808,9 +2781,7 @@ Char: ${this.c}`;
|
|
|
2808
2781
|
}
|
|
2809
2782
|
}
|
|
2810
2783
|
function flattenFeature(feature, options) {
|
|
2811
|
-
const {
|
|
2812
|
-
geometry
|
|
2813
|
-
} = feature;
|
|
2784
|
+
const { geometry } = feature;
|
|
2814
2785
|
if (geometry.type === "GeometryCollection") {
|
|
2815
2786
|
throw new Error("GeometryCollection type not supported");
|
|
2816
2787
|
}
|
|
@@ -2848,31 +2819,15 @@ Char: ${this.c}`;
|
|
|
2848
2819
|
default:
|
|
2849
2820
|
throw new Error(`Unknown type: ${type}`);
|
|
2850
2821
|
}
|
|
2851
|
-
return {
|
|
2852
|
-
...feature,
|
|
2853
|
-
geometry: {
|
|
2854
|
-
type,
|
|
2855
|
-
indices,
|
|
2856
|
-
data,
|
|
2857
|
-
areas
|
|
2858
|
-
}
|
|
2859
|
-
};
|
|
2822
|
+
return { ...feature, geometry: { type, indices, data, areas } };
|
|
2860
2823
|
}
|
|
2861
2824
|
|
|
2862
2825
|
// ../gis/src/lib/binary-features/geojson-to-binary.ts
|
|
2863
|
-
function geojsonToBinary(features, options = {
|
|
2864
|
-
fixRingWinding: true,
|
|
2865
|
-
triangulate: true
|
|
2866
|
-
}) {
|
|
2826
|
+
function geojsonToBinary(features, options = { fixRingWinding: true, triangulate: true }) {
|
|
2867
2827
|
const geometryInfo = extractGeometryInfo(features);
|
|
2868
2828
|
const coordLength = geometryInfo.coordLength;
|
|
2869
|
-
const {
|
|
2870
|
-
|
|
2871
|
-
} = options;
|
|
2872
|
-
const flatFeatures = geojsonToFlatGeojson(features, {
|
|
2873
|
-
coordLength,
|
|
2874
|
-
fixRingWinding
|
|
2875
|
-
});
|
|
2829
|
+
const { fixRingWinding } = options;
|
|
2830
|
+
const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
|
|
2876
2831
|
return flatGeojsonToBinary(flatFeatures, geometryInfo, {
|
|
2877
2832
|
numericPropKeys: options.numericPropKeys,
|
|
2878
2833
|
PositionDataType: options.PositionDataType || Float32Array,
|
|
@@ -2881,7 +2836,7 @@ Char: ${this.c}`;
|
|
|
2881
2836
|
}
|
|
2882
2837
|
|
|
2883
2838
|
// src/geojson-loader.ts
|
|
2884
|
-
var VERSION3 =
|
|
2839
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2885
2840
|
var GeoJSONWorkerLoader = {
|
|
2886
2841
|
name: "GeoJSON",
|
|
2887
2842
|
id: "geojson",
|
|
@@ -2907,7 +2862,9 @@ Char: ${this.c}`;
|
|
|
2907
2862
|
};
|
|
2908
2863
|
var GeoJSONLoader = {
|
|
2909
2864
|
...GeoJSONWorkerLoader,
|
|
2865
|
+
// @ts-expect-error
|
|
2910
2866
|
parse: parse2,
|
|
2867
|
+
// @ts-expect-error
|
|
2911
2868
|
parseTextSync: parseTextSync2,
|
|
2912
2869
|
parseInBatches: parseInBatches2
|
|
2913
2870
|
};
|
|
@@ -2915,14 +2872,8 @@ Char: ${this.c}`;
|
|
|
2915
2872
|
return parseTextSync2(new TextDecoder().decode(arrayBuffer), options);
|
|
2916
2873
|
}
|
|
2917
2874
|
function parseTextSync2(text, options) {
|
|
2918
|
-
options = {
|
|
2919
|
-
|
|
2920
|
-
...options
|
|
2921
|
-
};
|
|
2922
|
-
options.geojson = {
|
|
2923
|
-
...GeoJSONLoader.options.geojson,
|
|
2924
|
-
...options.geojson
|
|
2925
|
-
};
|
|
2875
|
+
options = { ...GeoJSONLoader.options, ...options };
|
|
2876
|
+
options.geojson = { ...GeoJSONLoader.options.geojson, ...options.geojson };
|
|
2926
2877
|
options.gis = options.gis || {};
|
|
2927
2878
|
let geojson;
|
|
2928
2879
|
try {
|
|
@@ -2932,6 +2883,8 @@ Char: ${this.c}`;
|
|
|
2932
2883
|
}
|
|
2933
2884
|
const table = {
|
|
2934
2885
|
shape: "geojson-table",
|
|
2886
|
+
// TODO - deduce schema from geojson
|
|
2887
|
+
// TODO check that parsed data is of type FeatureCollection
|
|
2935
2888
|
type: "FeatureCollection",
|
|
2936
2889
|
features: geojson?.features || []
|
|
2937
2890
|
};
|
|
@@ -2943,14 +2896,8 @@ Char: ${this.c}`;
|
|
|
2943
2896
|
}
|
|
2944
2897
|
}
|
|
2945
2898
|
function parseInBatches2(asyncIterator, options) {
|
|
2946
|
-
options = {
|
|
2947
|
-
|
|
2948
|
-
...options
|
|
2949
|
-
};
|
|
2950
|
-
options.json = {
|
|
2951
|
-
...GeoJSONLoader.options.geojson,
|
|
2952
|
-
...options.geojson
|
|
2953
|
-
};
|
|
2899
|
+
options = { ...GeoJSONLoader.options, ...options };
|
|
2900
|
+
options.json = { ...GeoJSONLoader.options.geojson, ...options.geojson };
|
|
2954
2901
|
const geojsonIterator = parseJSONInBatches(asyncIterator, options);
|
|
2955
2902
|
switch (options.gis.format) {
|
|
2956
2903
|
case "binary":
|
|
@@ -3008,11 +2955,7 @@ Char: ${this.c}`;
|
|
|
3008
2955
|
const columnName = table.schema?.fields[geometryColumnIndex].name;
|
|
3009
2956
|
let featureOrGeometry = columnName && row[columnName];
|
|
3010
2957
|
if (!featureOrGeometry) {
|
|
3011
|
-
return {
|
|
3012
|
-
type: "Feature",
|
|
3013
|
-
geometry: null,
|
|
3014
|
-
properties
|
|
3015
|
-
};
|
|
2958
|
+
return { type: "Feature", geometry: null, properties };
|
|
3016
2959
|
}
|
|
3017
2960
|
if (typeof featureOrGeometry === "string") {
|
|
3018
2961
|
try {
|
|
@@ -3025,24 +2968,17 @@ Char: ${this.c}`;
|
|
|
3025
2968
|
throw new Error("invalid geometry column value");
|
|
3026
2969
|
}
|
|
3027
2970
|
if (featureOrGeometry?.type === "Feature") {
|
|
3028
|
-
return {
|
|
3029
|
-
...featureOrGeometry,
|
|
3030
|
-
properties
|
|
3031
|
-
};
|
|
2971
|
+
return { ...featureOrGeometry, properties };
|
|
3032
2972
|
}
|
|
3033
|
-
return {
|
|
3034
|
-
type: "Feature",
|
|
3035
|
-
geometry: featureOrGeometry,
|
|
3036
|
-
properties
|
|
3037
|
-
};
|
|
2973
|
+
return { type: "Feature", geometry: featureOrGeometry, properties };
|
|
3038
2974
|
}
|
|
3039
2975
|
|
|
3040
2976
|
// src/lib/encoder-utils/utf8-encoder.ts
|
|
3041
2977
|
var Utf8ArrayBufferEncoder = class {
|
|
3042
|
-
strings = [];
|
|
3043
|
-
totalLength = 0;
|
|
3044
|
-
textEncoder = new TextEncoder();
|
|
3045
2978
|
constructor(chunkSize) {
|
|
2979
|
+
this.strings = [];
|
|
2980
|
+
this.totalLength = 0;
|
|
2981
|
+
this.textEncoder = new TextEncoder();
|
|
3046
2982
|
this.chunkSize = chunkSize;
|
|
3047
2983
|
}
|
|
3048
2984
|
push(...strings) {
|
|
@@ -3067,11 +3003,7 @@ Char: ${this.c}`;
|
|
|
3067
3003
|
|
|
3068
3004
|
// src/lib/encoders/geojson-encoder.ts
|
|
3069
3005
|
async function* encodeTableAsGeojsonInBatches(batchIterator, inputOpts = {}) {
|
|
3070
|
-
const options = {
|
|
3071
|
-
geojson: {},
|
|
3072
|
-
chunkSize: 1e4,
|
|
3073
|
-
...inputOpts
|
|
3074
|
-
};
|
|
3006
|
+
const options = { geojson: {}, chunkSize: 1e4, ...inputOpts };
|
|
3075
3007
|
const utf8Encoder = new Utf8ArrayBufferEncoder(options.chunkSize);
|
|
3076
3008
|
if (!options.geojson.featureArray) {
|
|
3077
3009
|
utf8Encoder.push("{\n", '"type": "FeatureCollection",\n', '"features":\n');
|
|
@@ -3132,7 +3064,7 @@ Char: ${this.c}`;
|
|
|
3132
3064
|
},
|
|
3133
3065
|
encodeInBatches: (tableIterator, options) => encodeTableAsGeojsonInBatches(tableIterator, options)
|
|
3134
3066
|
};
|
|
3135
|
-
return __toCommonJS(
|
|
3067
|
+
return __toCommonJS(bundle_exports);
|
|
3136
3068
|
})();
|
|
3137
3069
|
return __exports__;
|
|
3138
3070
|
});
|