@loaders.gl/json 4.2.0-alpha.4 → 4.2.0-alpha.6
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 +319 -366
- 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 +75 -73
- package/dist/geojson-worker.js +78 -54
- package/dist/geojson-writer.js +23 -20
- package/dist/index.cjs +155 -121
- 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 +30 -37
- package/dist/json-writer.js +14 -11
- package/dist/lib/clarinet/clarinet.js +513 -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 +26 -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 +86 -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 +87 -63
- package/dist/lib/jsonpath/jsonpath.js +78 -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 +28 -20
- package/dist/ndjson-loader.js +22 -14
- 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,20 @@
|
|
|
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 __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
};
|
|
13
19
|
var __export = (target, all) => {
|
|
14
20
|
for (var name in all)
|
|
15
21
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -22,11 +28,31 @@ var __exports__ = (() => {
|
|
|
22
28
|
}
|
|
23
29
|
return to;
|
|
24
30
|
};
|
|
31
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
32
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
33
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
34
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
35
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
36
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
25
40
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var __publicField = (obj, key, value) => {
|
|
42
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
43
|
+
return value;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// external-global-plugin:@loaders.gl/core
|
|
47
|
+
var require_core = __commonJS({
|
|
48
|
+
"external-global-plugin:@loaders.gl/core"(exports, module) {
|
|
49
|
+
module.exports = globalThis.loaders;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
26
52
|
|
|
27
|
-
//
|
|
28
|
-
var
|
|
29
|
-
__export(
|
|
53
|
+
// bundle.ts
|
|
54
|
+
var bundle_exports = {};
|
|
55
|
+
__export(bundle_exports, {
|
|
30
56
|
JSONLoader: () => JSONLoader,
|
|
31
57
|
JSONWriter: () => JSONWriter,
|
|
32
58
|
NDJSONLoader: () => NDJSONLoader,
|
|
@@ -37,10 +63,14 @@ var __exports__ = (() => {
|
|
|
37
63
|
_JSONPath: () => JSONPath,
|
|
38
64
|
_rebuildJsonObject: () => rebuildJsonObject
|
|
39
65
|
});
|
|
66
|
+
__reExport(bundle_exports, __toESM(require_core(), 1));
|
|
40
67
|
|
|
41
68
|
// ../schema/src/lib/table/batches/base-table-batch-aggregator.ts
|
|
42
69
|
var DEFAULT_ROW_COUNT = 100;
|
|
43
70
|
var BaseTableBatchAggregator = class {
|
|
71
|
+
schema;
|
|
72
|
+
options;
|
|
73
|
+
shape;
|
|
44
74
|
length = 0;
|
|
45
75
|
rows = null;
|
|
46
76
|
cursor = 0;
|
|
@@ -141,6 +171,8 @@ var __exports__ = (() => {
|
|
|
141
171
|
// ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
|
|
142
172
|
var DEFAULT_ROW_COUNT2 = 100;
|
|
143
173
|
var RowTableBatchAggregator = class {
|
|
174
|
+
schema;
|
|
175
|
+
options;
|
|
144
176
|
length = 0;
|
|
145
177
|
objectRows = null;
|
|
146
178
|
arrayRows = null;
|
|
@@ -206,6 +238,7 @@ var __exports__ = (() => {
|
|
|
206
238
|
batchType: "data",
|
|
207
239
|
data: rows,
|
|
208
240
|
length: this.length,
|
|
241
|
+
// @ts-expect-error we should infer a schema
|
|
209
242
|
schema: this.schema,
|
|
210
243
|
cursor: this.cursor
|
|
211
244
|
};
|
|
@@ -215,6 +248,7 @@ var __exports__ = (() => {
|
|
|
215
248
|
// ../schema/src/lib/table/batches/columnar-table-batch-aggregator.ts
|
|
216
249
|
var DEFAULT_ROW_COUNT3 = 100;
|
|
217
250
|
var ColumnarTableBatchAggregator = class {
|
|
251
|
+
schema;
|
|
218
252
|
length = 0;
|
|
219
253
|
allocated = 0;
|
|
220
254
|
columns = {};
|
|
@@ -259,6 +293,7 @@ var __exports__ = (() => {
|
|
|
259
293
|
};
|
|
260
294
|
return batch;
|
|
261
295
|
}
|
|
296
|
+
// HELPERS
|
|
262
297
|
_reallocateColumns() {
|
|
263
298
|
if (this.length < this.allocated) {
|
|
264
299
|
return;
|
|
@@ -297,7 +332,9 @@ var __exports__ = (() => {
|
|
|
297
332
|
_limitMB: 0
|
|
298
333
|
};
|
|
299
334
|
var ERR_MESSAGE = "TableBatchBuilder";
|
|
300
|
-
var
|
|
335
|
+
var _TableBatchBuilder = class {
|
|
336
|
+
schema;
|
|
337
|
+
options;
|
|
301
338
|
aggregator = null;
|
|
302
339
|
batchCount = 0;
|
|
303
340
|
bytesUsed = 0;
|
|
@@ -308,10 +345,7 @@ var __exports__ = (() => {
|
|
|
308
345
|
rowBytes = 0;
|
|
309
346
|
constructor(schema, options) {
|
|
310
347
|
this.schema = schema;
|
|
311
|
-
this.options = {
|
|
312
|
-
...DEFAULT_OPTIONS,
|
|
313
|
-
...options
|
|
314
|
-
};
|
|
348
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
315
349
|
}
|
|
316
350
|
limitReached() {
|
|
317
351
|
if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
|
|
@@ -322,6 +356,7 @@ var __exports__ = (() => {
|
|
|
322
356
|
}
|
|
323
357
|
return false;
|
|
324
358
|
}
|
|
359
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
325
360
|
addRow(row) {
|
|
326
361
|
if (this.limitReached()) {
|
|
327
362
|
return;
|
|
@@ -335,6 +370,7 @@ var __exports__ = (() => {
|
|
|
335
370
|
this.addObjectRow(row);
|
|
336
371
|
}
|
|
337
372
|
}
|
|
373
|
+
/** Add one row to the batch */
|
|
338
374
|
addArrayRow(row) {
|
|
339
375
|
if (!this.aggregator) {
|
|
340
376
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -342,6 +378,7 @@ var __exports__ = (() => {
|
|
|
342
378
|
}
|
|
343
379
|
this.aggregator.addArrayRow(row);
|
|
344
380
|
}
|
|
381
|
+
/** Add one row to the batch */
|
|
345
382
|
addObjectRow(row) {
|
|
346
383
|
if (!this.aggregator) {
|
|
347
384
|
const TableBatchType = this._getTableBatchType();
|
|
@@ -349,6 +386,7 @@ var __exports__ = (() => {
|
|
|
349
386
|
}
|
|
350
387
|
this.aggregator.addObjectRow(row);
|
|
351
388
|
}
|
|
389
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
352
390
|
chunkComplete(chunk) {
|
|
353
391
|
if (chunk instanceof ArrayBuffer) {
|
|
354
392
|
this.bytesUsed += chunk.byteLength;
|
|
@@ -364,6 +402,7 @@ var __exports__ = (() => {
|
|
|
364
402
|
getFinalBatch(options) {
|
|
365
403
|
return this._getBatch(options);
|
|
366
404
|
}
|
|
405
|
+
// INTERNAL
|
|
367
406
|
_estimateRowMB(row) {
|
|
368
407
|
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
369
408
|
}
|
|
@@ -385,6 +424,9 @@ var __exports__ = (() => {
|
|
|
385
424
|
this.lastBatchEmittedMs = Date.now();
|
|
386
425
|
return true;
|
|
387
426
|
}
|
|
427
|
+
/**
|
|
428
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
429
|
+
*/
|
|
388
430
|
_getBatch(options) {
|
|
389
431
|
if (!this.aggregator) {
|
|
390
432
|
return null;
|
|
@@ -408,15 +450,17 @@ var __exports__ = (() => {
|
|
|
408
450
|
case "columnar-table":
|
|
409
451
|
return ColumnarTableBatchAggregator;
|
|
410
452
|
case "arrow-table":
|
|
411
|
-
if (!
|
|
453
|
+
if (!_TableBatchBuilder.ArrowBatch) {
|
|
412
454
|
throw new Error(ERR_MESSAGE);
|
|
413
455
|
}
|
|
414
|
-
return
|
|
456
|
+
return _TableBatchBuilder.ArrowBatch;
|
|
415
457
|
default:
|
|
416
458
|
return BaseTableBatchAggregator;
|
|
417
459
|
}
|
|
418
460
|
}
|
|
419
461
|
};
|
|
462
|
+
var TableBatchBuilder = _TableBatchBuilder;
|
|
463
|
+
__publicField(TableBatchBuilder, "ArrowBatch");
|
|
420
464
|
|
|
421
465
|
// ../schema/src/lib/table/simple-table/table-accessors.ts
|
|
422
466
|
function getTableLength(table) {
|
|
@@ -605,22 +649,13 @@ var __exports__ = (() => {
|
|
|
605
649
|
function getDataTypeFromArray(array) {
|
|
606
650
|
let type = getDataTypeFromTypedArray(array);
|
|
607
651
|
if (type !== "null") {
|
|
608
|
-
return {
|
|
609
|
-
type,
|
|
610
|
-
nullable: false
|
|
611
|
-
};
|
|
652
|
+
return { type, nullable: false };
|
|
612
653
|
}
|
|
613
654
|
if (array.length > 0) {
|
|
614
655
|
type = getDataTypeFromValue(array[0]);
|
|
615
|
-
return {
|
|
616
|
-
type,
|
|
617
|
-
nullable: true
|
|
618
|
-
};
|
|
656
|
+
return { type, nullable: true };
|
|
619
657
|
}
|
|
620
|
-
return {
|
|
621
|
-
type: "null",
|
|
622
|
-
nullable: true
|
|
623
|
-
};
|
|
658
|
+
return { type: "null", nullable: true };
|
|
624
659
|
}
|
|
625
660
|
function getDataTypeFromTypedArray(array) {
|
|
626
661
|
switch (array.constructor) {
|
|
@@ -665,10 +700,7 @@ var __exports__ = (() => {
|
|
|
665
700
|
const field = deduceFieldFromColumn(column, columnName);
|
|
666
701
|
fields.push(field);
|
|
667
702
|
}
|
|
668
|
-
return {
|
|
669
|
-
fields,
|
|
670
|
-
metadata: {}
|
|
671
|
-
};
|
|
703
|
+
return { fields, metadata: {} };
|
|
672
704
|
}
|
|
673
705
|
function deduceSchemaFromRows(rowTable) {
|
|
674
706
|
if (!rowTable.length) {
|
|
@@ -679,10 +711,7 @@ var __exports__ = (() => {
|
|
|
679
711
|
for (const [columnName, value] of Object.entries(row0)) {
|
|
680
712
|
fields.push(deduceFieldFromValue(value, columnName));
|
|
681
713
|
}
|
|
682
|
-
return {
|
|
683
|
-
fields,
|
|
684
|
-
metadata: {}
|
|
685
|
-
};
|
|
714
|
+
return { fields, metadata: {} };
|
|
686
715
|
}
|
|
687
716
|
function deduceFieldFromColumn(column, name) {
|
|
688
717
|
if (ArrayBuffer.isView(column)) {
|
|
@@ -691,6 +720,7 @@ var __exports__ = (() => {
|
|
|
691
720
|
name,
|
|
692
721
|
type: type.type || "null",
|
|
693
722
|
nullable: type.nullable
|
|
723
|
+
// metadata: {}
|
|
694
724
|
};
|
|
695
725
|
}
|
|
696
726
|
if (Array.isArray(column) && column.length > 0) {
|
|
@@ -700,6 +730,7 @@ var __exports__ = (() => {
|
|
|
700
730
|
name,
|
|
701
731
|
type,
|
|
702
732
|
nullable: true
|
|
733
|
+
// metadata: {},
|
|
703
734
|
};
|
|
704
735
|
}
|
|
705
736
|
throw new Error("empty table");
|
|
@@ -710,6 +741,7 @@ var __exports__ = (() => {
|
|
|
710
741
|
name,
|
|
711
742
|
type,
|
|
712
743
|
nullable: true
|
|
744
|
+
// metadata: {}
|
|
713
745
|
};
|
|
714
746
|
}
|
|
715
747
|
|
|
@@ -718,31 +750,19 @@ var __exports__ = (() => {
|
|
|
718
750
|
let table;
|
|
719
751
|
switch (getTableShapeFromData(data)) {
|
|
720
752
|
case "array-row-table":
|
|
721
|
-
table = {
|
|
722
|
-
shape: "array-row-table",
|
|
723
|
-
data
|
|
724
|
-
};
|
|
753
|
+
table = { shape: "array-row-table", data };
|
|
725
754
|
break;
|
|
726
755
|
case "object-row-table":
|
|
727
|
-
table = {
|
|
728
|
-
shape: "object-row-table",
|
|
729
|
-
data
|
|
730
|
-
};
|
|
756
|
+
table = { shape: "object-row-table", data };
|
|
731
757
|
break;
|
|
732
758
|
case "columnar-table":
|
|
733
|
-
table = {
|
|
734
|
-
shape: "columnar-table",
|
|
735
|
-
data
|
|
736
|
-
};
|
|
759
|
+
table = { shape: "columnar-table", data };
|
|
737
760
|
break;
|
|
738
761
|
default:
|
|
739
762
|
throw new Error("table");
|
|
740
763
|
}
|
|
741
764
|
const schema = deduceTableSchema(table);
|
|
742
|
-
return {
|
|
743
|
-
...table,
|
|
744
|
-
schema
|
|
745
|
-
};
|
|
765
|
+
return { ...table, schema };
|
|
746
766
|
}
|
|
747
767
|
function getTableShapeFromData(data) {
|
|
748
768
|
if (Array.isArray(data)) {
|
|
@@ -803,7 +823,9 @@ var __exports__ = (() => {
|
|
|
803
823
|
return concatenateArrayBuffersFromArray(sources);
|
|
804
824
|
}
|
|
805
825
|
function concatenateArrayBuffersFromArray(sources) {
|
|
806
|
-
const sourceArrays = sources.map(
|
|
826
|
+
const sourceArrays = sources.map(
|
|
827
|
+
(source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2
|
|
828
|
+
);
|
|
807
829
|
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
808
830
|
const result = new Uint8Array(byteLength);
|
|
809
831
|
let offset = 0;
|
|
@@ -818,9 +840,7 @@ var __exports__ = (() => {
|
|
|
818
840
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
819
841
|
const textDecoder = new TextDecoder(void 0, options);
|
|
820
842
|
for await (const arrayBuffer of arrayBufferIterator) {
|
|
821
|
-
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, {
|
|
822
|
-
stream: true
|
|
823
|
-
});
|
|
843
|
+
yield typeof arrayBuffer === "string" ? arrayBuffer : textDecoder.decode(arrayBuffer, { stream: true });
|
|
824
844
|
}
|
|
825
845
|
}
|
|
826
846
|
async function* makeLineIterator(textIterator) {
|
|
@@ -841,10 +861,7 @@ var __exports__ = (() => {
|
|
|
841
861
|
async function* makeNumberedLineIterator(lineIterator) {
|
|
842
862
|
let counter = 1;
|
|
843
863
|
for await (const line of lineIterator) {
|
|
844
|
-
yield {
|
|
845
|
-
counter,
|
|
846
|
-
line
|
|
847
|
-
};
|
|
864
|
+
yield { counter, line };
|
|
848
865
|
counter++;
|
|
849
866
|
}
|
|
850
867
|
}
|
|
@@ -906,62 +923,63 @@ var __exports__ = (() => {
|
|
|
906
923
|
|
|
907
924
|
// src/lib/clarinet/clarinet.ts
|
|
908
925
|
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
926
|
var Char = {
|
|
937
927
|
tab: 9,
|
|
928
|
+
// \t
|
|
938
929
|
lineFeed: 10,
|
|
930
|
+
// \n
|
|
939
931
|
carriageReturn: 13,
|
|
932
|
+
// \r
|
|
940
933
|
space: 32,
|
|
934
|
+
// " "
|
|
941
935
|
doubleQuote: 34,
|
|
936
|
+
// "
|
|
942
937
|
plus: 43,
|
|
938
|
+
// +
|
|
943
939
|
comma: 44,
|
|
940
|
+
// ,
|
|
944
941
|
minus: 45,
|
|
942
|
+
// -
|
|
945
943
|
period: 46,
|
|
944
|
+
// .
|
|
946
945
|
_0: 48,
|
|
946
|
+
// 0
|
|
947
947
|
_9: 57,
|
|
948
|
+
// 9
|
|
948
949
|
colon: 58,
|
|
950
|
+
// :
|
|
949
951
|
E: 69,
|
|
952
|
+
// E
|
|
950
953
|
openBracket: 91,
|
|
954
|
+
// [
|
|
951
955
|
backslash: 92,
|
|
956
|
+
// \
|
|
952
957
|
closeBracket: 93,
|
|
958
|
+
// ]
|
|
953
959
|
a: 97,
|
|
960
|
+
// a
|
|
954
961
|
b: 98,
|
|
962
|
+
// b
|
|
955
963
|
e: 101,
|
|
964
|
+
// e
|
|
956
965
|
f: 102,
|
|
966
|
+
// f
|
|
957
967
|
l: 108,
|
|
968
|
+
// l
|
|
958
969
|
n: 110,
|
|
970
|
+
// n
|
|
959
971
|
r: 114,
|
|
972
|
+
// r
|
|
960
973
|
s: 115,
|
|
974
|
+
// s
|
|
961
975
|
t: 116,
|
|
976
|
+
// t
|
|
962
977
|
u: 117,
|
|
978
|
+
// u
|
|
963
979
|
openBrace: 123,
|
|
980
|
+
// {
|
|
964
981
|
closeBrace: 125
|
|
982
|
+
// }
|
|
965
983
|
};
|
|
966
984
|
var stringTokenPattern = /[\\"\n]/g;
|
|
967
985
|
var DEFAULT_OPTIONS2 = {
|
|
@@ -995,9 +1013,11 @@ var __exports__ = (() => {
|
|
|
995
1013
|
closed = false;
|
|
996
1014
|
closedRoot = false;
|
|
997
1015
|
sawRoot = false;
|
|
1016
|
+
// tag = null;
|
|
998
1017
|
error = null;
|
|
999
|
-
state =
|
|
1018
|
+
state = 0 /* BEGIN */;
|
|
1000
1019
|
stack = [];
|
|
1020
|
+
// mostly just for error reporting
|
|
1001
1021
|
position = 0;
|
|
1002
1022
|
column = 0;
|
|
1003
1023
|
line = 1;
|
|
@@ -1005,17 +1025,16 @@ var __exports__ = (() => {
|
|
|
1005
1025
|
unicodeI = 0;
|
|
1006
1026
|
unicodeS = null;
|
|
1007
1027
|
depth = 0;
|
|
1028
|
+
textNode;
|
|
1029
|
+
numberNode;
|
|
1008
1030
|
constructor(options = {}) {
|
|
1009
|
-
this.options = {
|
|
1010
|
-
...DEFAULT_OPTIONS2,
|
|
1011
|
-
...options
|
|
1012
|
-
};
|
|
1031
|
+
this.options = { ...DEFAULT_OPTIONS2, ...options };
|
|
1013
1032
|
this.textNode = void 0;
|
|
1014
1033
|
this.numberNode = "";
|
|
1015
1034
|
this.emit("onready");
|
|
1016
1035
|
}
|
|
1017
1036
|
end() {
|
|
1018
|
-
if (this.state !==
|
|
1037
|
+
if (this.state !== 1 /* VALUE */ || this.depth !== 0)
|
|
1019
1038
|
this._error("Unexpected end");
|
|
1020
1039
|
this._closeValue();
|
|
1021
1040
|
this.c = "";
|
|
@@ -1030,6 +1049,7 @@ var __exports__ = (() => {
|
|
|
1030
1049
|
close() {
|
|
1031
1050
|
return this.write(null);
|
|
1032
1051
|
}
|
|
1052
|
+
// protected
|
|
1033
1053
|
emit(event, data) {
|
|
1034
1054
|
this.options[event]?.(data, this);
|
|
1035
1055
|
}
|
|
@@ -1037,6 +1057,8 @@ var __exports__ = (() => {
|
|
|
1037
1057
|
this._closeValue();
|
|
1038
1058
|
this.emit(event, data);
|
|
1039
1059
|
}
|
|
1060
|
+
/* eslint-disable no-continue */
|
|
1061
|
+
// eslint-disable-next-line complexity, max-statements
|
|
1040
1062
|
write(chunk) {
|
|
1041
1063
|
if (this.error) {
|
|
1042
1064
|
throw this.error;
|
|
@@ -1067,111 +1089,111 @@ var __exports__ = (() => {
|
|
|
1067
1089
|
} else
|
|
1068
1090
|
this.column++;
|
|
1069
1091
|
switch (this.state) {
|
|
1070
|
-
case
|
|
1092
|
+
case 0 /* BEGIN */:
|
|
1071
1093
|
if (c === Char.openBrace)
|
|
1072
|
-
this.state =
|
|
1094
|
+
this.state = 2 /* OPEN_OBJECT */;
|
|
1073
1095
|
else if (c === Char.openBracket)
|
|
1074
|
-
this.state =
|
|
1096
|
+
this.state = 4 /* OPEN_ARRAY */;
|
|
1075
1097
|
else if (!isWhitespace(c)) {
|
|
1076
1098
|
this._error("Non-whitespace before {[.");
|
|
1077
1099
|
}
|
|
1078
1100
|
continue;
|
|
1079
|
-
case
|
|
1080
|
-
case
|
|
1101
|
+
case 10 /* OPEN_KEY */:
|
|
1102
|
+
case 2 /* OPEN_OBJECT */:
|
|
1081
1103
|
if (isWhitespace(c))
|
|
1082
1104
|
continue;
|
|
1083
|
-
if (this.state ===
|
|
1084
|
-
this.stack.push(
|
|
1105
|
+
if (this.state === 10 /* OPEN_KEY */)
|
|
1106
|
+
this.stack.push(11 /* CLOSE_KEY */);
|
|
1085
1107
|
else if (c === Char.closeBrace) {
|
|
1086
1108
|
this.emit("onopenobject");
|
|
1087
1109
|
this.depth++;
|
|
1088
1110
|
this.emit("oncloseobject");
|
|
1089
1111
|
this.depth--;
|
|
1090
|
-
this.state = this.stack.pop() ||
|
|
1112
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1091
1113
|
continue;
|
|
1092
1114
|
} else
|
|
1093
|
-
this.stack.push(
|
|
1115
|
+
this.stack.push(3 /* CLOSE_OBJECT */);
|
|
1094
1116
|
if (c === Char.doubleQuote)
|
|
1095
|
-
this.state =
|
|
1117
|
+
this.state = 7 /* STRING */;
|
|
1096
1118
|
else
|
|
1097
1119
|
this._error('Malformed object key should start with "');
|
|
1098
1120
|
continue;
|
|
1099
|
-
case
|
|
1100
|
-
case
|
|
1121
|
+
case 11 /* CLOSE_KEY */:
|
|
1122
|
+
case 3 /* CLOSE_OBJECT */:
|
|
1101
1123
|
if (isWhitespace(c))
|
|
1102
1124
|
continue;
|
|
1103
1125
|
if (c === Char.colon) {
|
|
1104
|
-
if (this.state ===
|
|
1105
|
-
this.stack.push(
|
|
1126
|
+
if (this.state === 3 /* CLOSE_OBJECT */) {
|
|
1127
|
+
this.stack.push(3 /* CLOSE_OBJECT */);
|
|
1106
1128
|
this._closeValue("onopenobject");
|
|
1107
1129
|
this.depth++;
|
|
1108
1130
|
} else
|
|
1109
1131
|
this._closeValue("onkey");
|
|
1110
|
-
this.state =
|
|
1132
|
+
this.state = 1 /* VALUE */;
|
|
1111
1133
|
} else if (c === Char.closeBrace) {
|
|
1112
1134
|
this.emitNode("oncloseobject");
|
|
1113
1135
|
this.depth--;
|
|
1114
|
-
this.state = this.stack.pop() ||
|
|
1136
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1115
1137
|
} else if (c === Char.comma) {
|
|
1116
|
-
if (this.state ===
|
|
1117
|
-
this.stack.push(
|
|
1138
|
+
if (this.state === 3 /* CLOSE_OBJECT */)
|
|
1139
|
+
this.stack.push(3 /* CLOSE_OBJECT */);
|
|
1118
1140
|
this._closeValue();
|
|
1119
|
-
this.state =
|
|
1141
|
+
this.state = 10 /* OPEN_KEY */;
|
|
1120
1142
|
} else
|
|
1121
1143
|
this._error("Bad object");
|
|
1122
1144
|
continue;
|
|
1123
|
-
case
|
|
1124
|
-
case
|
|
1145
|
+
case 4 /* OPEN_ARRAY */:
|
|
1146
|
+
case 1 /* VALUE */:
|
|
1125
1147
|
if (isWhitespace(c))
|
|
1126
1148
|
continue;
|
|
1127
|
-
if (this.state ===
|
|
1149
|
+
if (this.state === 4 /* OPEN_ARRAY */) {
|
|
1128
1150
|
this.emit("onopenarray");
|
|
1129
1151
|
this.depth++;
|
|
1130
|
-
this.state =
|
|
1152
|
+
this.state = 1 /* VALUE */;
|
|
1131
1153
|
if (c === Char.closeBracket) {
|
|
1132
1154
|
this.emit("onclosearray");
|
|
1133
1155
|
this.depth--;
|
|
1134
|
-
this.state = this.stack.pop() ||
|
|
1156
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1135
1157
|
continue;
|
|
1136
1158
|
} else {
|
|
1137
|
-
this.stack.push(
|
|
1159
|
+
this.stack.push(5 /* CLOSE_ARRAY */);
|
|
1138
1160
|
}
|
|
1139
1161
|
}
|
|
1140
1162
|
if (c === Char.doubleQuote)
|
|
1141
|
-
this.state =
|
|
1163
|
+
this.state = 7 /* STRING */;
|
|
1142
1164
|
else if (c === Char.openBrace)
|
|
1143
|
-
this.state =
|
|
1165
|
+
this.state = 2 /* OPEN_OBJECT */;
|
|
1144
1166
|
else if (c === Char.openBracket)
|
|
1145
|
-
this.state =
|
|
1167
|
+
this.state = 4 /* OPEN_ARRAY */;
|
|
1146
1168
|
else if (c === Char.t)
|
|
1147
|
-
this.state =
|
|
1169
|
+
this.state = 12 /* TRUE */;
|
|
1148
1170
|
else if (c === Char.f)
|
|
1149
|
-
this.state =
|
|
1171
|
+
this.state = 15 /* FALSE */;
|
|
1150
1172
|
else if (c === Char.n)
|
|
1151
|
-
this.state =
|
|
1173
|
+
this.state = 19 /* NULL */;
|
|
1152
1174
|
else if (c === Char.minus) {
|
|
1153
1175
|
this.numberNode += "-";
|
|
1154
1176
|
} else if (Char._0 <= c && c <= Char._9) {
|
|
1155
1177
|
this.numberNode += String.fromCharCode(c);
|
|
1156
|
-
this.state =
|
|
1178
|
+
this.state = 23 /* NUMBER_DIGIT */;
|
|
1157
1179
|
} else
|
|
1158
1180
|
this._error("Bad value");
|
|
1159
1181
|
continue;
|
|
1160
|
-
case
|
|
1182
|
+
case 5 /* CLOSE_ARRAY */:
|
|
1161
1183
|
if (c === Char.comma) {
|
|
1162
|
-
this.stack.push(
|
|
1184
|
+
this.stack.push(5 /* CLOSE_ARRAY */);
|
|
1163
1185
|
this._closeValue("onvalue");
|
|
1164
|
-
this.state =
|
|
1186
|
+
this.state = 1 /* VALUE */;
|
|
1165
1187
|
} else if (c === Char.closeBracket) {
|
|
1166
1188
|
this.emitNode("onclosearray");
|
|
1167
1189
|
this.depth--;
|
|
1168
|
-
this.state = this.stack.pop() ||
|
|
1190
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1169
1191
|
} else if (isWhitespace(c))
|
|
1170
1192
|
continue;
|
|
1171
1193
|
else
|
|
1172
1194
|
this._error("Bad array");
|
|
1173
1195
|
continue;
|
|
1174
|
-
case
|
|
1196
|
+
case 7 /* STRING */:
|
|
1175
1197
|
if (this.textNode === void 0) {
|
|
1176
1198
|
this.textNode = "";
|
|
1177
1199
|
}
|
|
@@ -1195,7 +1217,7 @@ var __exports__ = (() => {
|
|
|
1195
1217
|
break STRING_BIGLOOP;
|
|
1196
1218
|
}
|
|
1197
1219
|
if (c === Char.doubleQuote && !slashed) {
|
|
1198
|
-
this.state = this.stack.pop() ||
|
|
1220
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1199
1221
|
this.textNode += chunk.substring(starti, i - 1);
|
|
1200
1222
|
this.position += i - 1 - starti;
|
|
1201
1223
|
break;
|
|
@@ -1254,77 +1276,77 @@ var __exports__ = (() => {
|
|
|
1254
1276
|
this.slashed = slashed;
|
|
1255
1277
|
this.unicodeI = unicodeI;
|
|
1256
1278
|
continue;
|
|
1257
|
-
case
|
|
1279
|
+
case 12 /* TRUE */:
|
|
1258
1280
|
if (c === Char.r)
|
|
1259
|
-
this.state =
|
|
1281
|
+
this.state = 13 /* TRUE2 */;
|
|
1260
1282
|
else
|
|
1261
1283
|
this._error(`Invalid true started with t${c}`);
|
|
1262
1284
|
continue;
|
|
1263
|
-
case
|
|
1285
|
+
case 13 /* TRUE2 */:
|
|
1264
1286
|
if (c === Char.u)
|
|
1265
|
-
this.state =
|
|
1287
|
+
this.state = 14 /* TRUE3 */;
|
|
1266
1288
|
else
|
|
1267
1289
|
this._error(`Invalid true started with tr${c}`);
|
|
1268
1290
|
continue;
|
|
1269
|
-
case
|
|
1291
|
+
case 14 /* TRUE3 */:
|
|
1270
1292
|
if (c === Char.e) {
|
|
1271
1293
|
this.emit("onvalue", true);
|
|
1272
|
-
this.state = this.stack.pop() ||
|
|
1294
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1273
1295
|
} else
|
|
1274
1296
|
this._error(`Invalid true started with tru${c}`);
|
|
1275
1297
|
continue;
|
|
1276
|
-
case
|
|
1298
|
+
case 15 /* FALSE */:
|
|
1277
1299
|
if (c === Char.a)
|
|
1278
|
-
this.state =
|
|
1300
|
+
this.state = 16 /* FALSE2 */;
|
|
1279
1301
|
else
|
|
1280
1302
|
this._error(`Invalid false started with f${c}`);
|
|
1281
1303
|
continue;
|
|
1282
|
-
case
|
|
1304
|
+
case 16 /* FALSE2 */:
|
|
1283
1305
|
if (c === Char.l)
|
|
1284
|
-
this.state =
|
|
1306
|
+
this.state = 17 /* FALSE3 */;
|
|
1285
1307
|
else
|
|
1286
1308
|
this._error(`Invalid false started with fa${c}`);
|
|
1287
1309
|
continue;
|
|
1288
|
-
case
|
|
1310
|
+
case 17 /* FALSE3 */:
|
|
1289
1311
|
if (c === Char.s)
|
|
1290
|
-
this.state =
|
|
1312
|
+
this.state = 18 /* FALSE4 */;
|
|
1291
1313
|
else
|
|
1292
1314
|
this._error(`Invalid false started with fal${c}`);
|
|
1293
1315
|
continue;
|
|
1294
|
-
case
|
|
1316
|
+
case 18 /* FALSE4 */:
|
|
1295
1317
|
if (c === Char.e) {
|
|
1296
1318
|
this.emit("onvalue", false);
|
|
1297
|
-
this.state = this.stack.pop() ||
|
|
1319
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1298
1320
|
} else
|
|
1299
1321
|
this._error(`Invalid false started with fals${c}`);
|
|
1300
1322
|
continue;
|
|
1301
|
-
case
|
|
1323
|
+
case 19 /* NULL */:
|
|
1302
1324
|
if (c === Char.u)
|
|
1303
|
-
this.state =
|
|
1325
|
+
this.state = 20 /* NULL2 */;
|
|
1304
1326
|
else
|
|
1305
1327
|
this._error(`Invalid null started with n${c}`);
|
|
1306
1328
|
continue;
|
|
1307
|
-
case
|
|
1329
|
+
case 20 /* NULL2 */:
|
|
1308
1330
|
if (c === Char.l)
|
|
1309
|
-
this.state =
|
|
1331
|
+
this.state = 21 /* NULL3 */;
|
|
1310
1332
|
else
|
|
1311
1333
|
this._error(`Invalid null started with nu${c}`);
|
|
1312
1334
|
continue;
|
|
1313
|
-
case
|
|
1335
|
+
case 21 /* NULL3 */:
|
|
1314
1336
|
if (c === Char.l) {
|
|
1315
1337
|
this.emit("onvalue", null);
|
|
1316
|
-
this.state = this.stack.pop() ||
|
|
1338
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1317
1339
|
} else
|
|
1318
1340
|
this._error(`Invalid null started with nul${c}`);
|
|
1319
1341
|
continue;
|
|
1320
|
-
case
|
|
1342
|
+
case 22 /* NUMBER_DECIMAL_POINT */:
|
|
1321
1343
|
if (c === Char.period) {
|
|
1322
1344
|
this.numberNode += ".";
|
|
1323
|
-
this.state =
|
|
1345
|
+
this.state = 23 /* NUMBER_DIGIT */;
|
|
1324
1346
|
} else
|
|
1325
1347
|
this._error("Leading zero not followed by .");
|
|
1326
1348
|
continue;
|
|
1327
|
-
case
|
|
1349
|
+
case 23 /* NUMBER_DIGIT */:
|
|
1328
1350
|
if (Char._0 <= c && c <= Char._9)
|
|
1329
1351
|
this.numberNode += String.fromCharCode(c);
|
|
1330
1352
|
else if (c === Char.period) {
|
|
@@ -1342,7 +1364,7 @@ var __exports__ = (() => {
|
|
|
1342
1364
|
} else {
|
|
1343
1365
|
this._closeNumber();
|
|
1344
1366
|
i--;
|
|
1345
|
-
this.state = this.stack.pop() ||
|
|
1367
|
+
this.state = this.stack.pop() || 1 /* VALUE */;
|
|
1346
1368
|
}
|
|
1347
1369
|
continue;
|
|
1348
1370
|
default:
|
|
@@ -1400,6 +1422,7 @@ Char: ${this.c}`;
|
|
|
1400
1422
|
|
|
1401
1423
|
// src/lib/jsonpath/jsonpath.ts
|
|
1402
1424
|
var JSONPath = class {
|
|
1425
|
+
path;
|
|
1403
1426
|
constructor(path = null) {
|
|
1404
1427
|
this.path = ["$"];
|
|
1405
1428
|
if (path instanceof JSONPath) {
|
|
@@ -1443,6 +1466,12 @@ Char: ${this.c}`;
|
|
|
1443
1466
|
}
|
|
1444
1467
|
return true;
|
|
1445
1468
|
}
|
|
1469
|
+
/**
|
|
1470
|
+
* Sets the value pointed at by path
|
|
1471
|
+
* TODO - handle root path
|
|
1472
|
+
* @param object
|
|
1473
|
+
* @param value
|
|
1474
|
+
*/
|
|
1446
1475
|
setFieldAtPath(object, value) {
|
|
1447
1476
|
const path = [...this.path];
|
|
1448
1477
|
path.shift();
|
|
@@ -1452,6 +1481,11 @@ Char: ${this.c}`;
|
|
|
1452
1481
|
}
|
|
1453
1482
|
object[field] = value;
|
|
1454
1483
|
}
|
|
1484
|
+
/**
|
|
1485
|
+
* Gets the value pointed at by path
|
|
1486
|
+
* TODO - handle root path
|
|
1487
|
+
* @param object
|
|
1488
|
+
*/
|
|
1455
1489
|
getFieldAtPath(object) {
|
|
1456
1490
|
const path = [...this.path];
|
|
1457
1491
|
path.shift();
|
|
@@ -1465,12 +1499,10 @@ Char: ${this.c}`;
|
|
|
1465
1499
|
|
|
1466
1500
|
// src/lib/json-parser/json-parser.ts
|
|
1467
1501
|
var JSONParser = class {
|
|
1502
|
+
parser;
|
|
1468
1503
|
result = void 0;
|
|
1469
1504
|
previousStates = [];
|
|
1470
|
-
currentState = Object.freeze({
|
|
1471
|
-
container: [],
|
|
1472
|
-
key: null
|
|
1473
|
-
});
|
|
1505
|
+
currentState = Object.freeze({ container: [], key: null });
|
|
1474
1506
|
jsonpath = new JSONPath();
|
|
1475
1507
|
constructor(options) {
|
|
1476
1508
|
this.reset();
|
|
@@ -1514,10 +1546,7 @@ Char: ${this.c}`;
|
|
|
1514
1546
|
reset() {
|
|
1515
1547
|
this.result = void 0;
|
|
1516
1548
|
this.previousStates = [];
|
|
1517
|
-
this.currentState = Object.freeze({
|
|
1518
|
-
container: [],
|
|
1519
|
-
key: null
|
|
1520
|
-
});
|
|
1549
|
+
this.currentState = Object.freeze({ container: [], key: null });
|
|
1521
1550
|
this.jsonpath = new JSONPath();
|
|
1522
1551
|
}
|
|
1523
1552
|
write(chunk) {
|
|
@@ -1526,11 +1555,9 @@ Char: ${this.c}`;
|
|
|
1526
1555
|
close() {
|
|
1527
1556
|
this.parser.close();
|
|
1528
1557
|
}
|
|
1558
|
+
// PRIVATE METHODS
|
|
1529
1559
|
_pushOrSet(value) {
|
|
1530
|
-
const {
|
|
1531
|
-
container,
|
|
1532
|
-
key
|
|
1533
|
-
} = this.currentState;
|
|
1560
|
+
const { container, key } = this.currentState;
|
|
1534
1561
|
if (key !== null) {
|
|
1535
1562
|
container[key] = value;
|
|
1536
1563
|
this.currentState.key = null;
|
|
@@ -1542,11 +1569,7 @@ Char: ${this.c}`;
|
|
|
1542
1569
|
this.jsonpath.push(null);
|
|
1543
1570
|
this._pushOrSet(newContainer);
|
|
1544
1571
|
this.previousStates.push(this.currentState);
|
|
1545
|
-
this.currentState = {
|
|
1546
|
-
container: newContainer,
|
|
1547
|
-
isArray: true,
|
|
1548
|
-
key: null
|
|
1549
|
-
};
|
|
1572
|
+
this.currentState = { container: newContainer, isArray: true, key: null };
|
|
1550
1573
|
}
|
|
1551
1574
|
_closeArray() {
|
|
1552
1575
|
this.jsonpath.pop();
|
|
@@ -1556,11 +1579,7 @@ Char: ${this.c}`;
|
|
|
1556
1579
|
this.jsonpath.push(null);
|
|
1557
1580
|
this._pushOrSet(newContainer);
|
|
1558
1581
|
this.previousStates.push(this.currentState);
|
|
1559
|
-
this.currentState = {
|
|
1560
|
-
container: newContainer,
|
|
1561
|
-
isArray: false,
|
|
1562
|
-
key: null
|
|
1563
|
-
};
|
|
1582
|
+
this.currentState = { container: newContainer, isArray: false, key: null };
|
|
1564
1583
|
}
|
|
1565
1584
|
_closeObject() {
|
|
1566
1585
|
this.jsonpath.pop();
|
|
@@ -1570,6 +1589,7 @@ Char: ${this.c}`;
|
|
|
1570
1589
|
|
|
1571
1590
|
// src/lib/json-parser/streaming-json-parser.ts
|
|
1572
1591
|
var StreamingJSONParser = class extends JSONParser {
|
|
1592
|
+
jsonPaths;
|
|
1573
1593
|
streamingJsonPath = null;
|
|
1574
1594
|
streamingArray = null;
|
|
1575
1595
|
topLevelObject = null;
|
|
@@ -1586,6 +1606,7 @@ Char: ${this.c}`;
|
|
|
1586
1606
|
}
|
|
1587
1607
|
this._openArray();
|
|
1588
1608
|
},
|
|
1609
|
+
// Redefine onopenarray to inject value for top-level object
|
|
1589
1610
|
onopenobject: (name) => {
|
|
1590
1611
|
if (!this.topLevelObject) {
|
|
1591
1612
|
this.topLevelObject = {};
|
|
@@ -1601,6 +1622,13 @@ Char: ${this.c}`;
|
|
|
1601
1622
|
const jsonpaths = options.jsonpaths || [];
|
|
1602
1623
|
this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));
|
|
1603
1624
|
}
|
|
1625
|
+
/**
|
|
1626
|
+
* write REDEFINITION
|
|
1627
|
+
* - super.write() chunk to parser
|
|
1628
|
+
* - get the contents (so far) of "topmost-level" array as batch of rows
|
|
1629
|
+
* - clear top-level array
|
|
1630
|
+
* - return the batch of rows\
|
|
1631
|
+
*/
|
|
1604
1632
|
write(chunk) {
|
|
1605
1633
|
super.write(chunk);
|
|
1606
1634
|
let array = [];
|
|
@@ -1610,6 +1638,11 @@ Char: ${this.c}`;
|
|
|
1610
1638
|
}
|
|
1611
1639
|
return array;
|
|
1612
1640
|
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Returns a partially formed result object
|
|
1643
|
+
* Useful for returning the "wrapper" object when array is not top level
|
|
1644
|
+
* e.g. GeoJSON
|
|
1645
|
+
*/
|
|
1613
1646
|
getPartialResult() {
|
|
1614
1647
|
return this.topLevelObject;
|
|
1615
1648
|
}
|
|
@@ -1622,6 +1655,10 @@ Char: ${this.c}`;
|
|
|
1622
1655
|
getJsonPath() {
|
|
1623
1656
|
return this.jsonpath;
|
|
1624
1657
|
}
|
|
1658
|
+
// PRIVATE METHODS
|
|
1659
|
+
/**
|
|
1660
|
+
* Checks is this.getJsonPath matches the jsonpaths provided in options
|
|
1661
|
+
*/
|
|
1625
1662
|
_matchJSONPath() {
|
|
1626
1663
|
const currentPath = this.getJsonPath();
|
|
1627
1664
|
if (this.jsonPaths.length === 0) {
|
|
@@ -1639,29 +1676,25 @@ Char: ${this.c}`;
|
|
|
1639
1676
|
// src/lib/parsers/parse-json-in-batches.ts
|
|
1640
1677
|
async function* parseJSONInBatches(binaryAsyncIterator, options) {
|
|
1641
1678
|
const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);
|
|
1642
|
-
const {
|
|
1643
|
-
|
|
1644
|
-
} = options;
|
|
1645
|
-
const {
|
|
1646
|
-
jsonpaths
|
|
1647
|
-
} = options.json || {};
|
|
1679
|
+
const { metadata } = options;
|
|
1680
|
+
const { jsonpaths } = options.json || {};
|
|
1648
1681
|
let isFirstChunk = true;
|
|
1649
1682
|
const schema = null;
|
|
1650
1683
|
const tableBatchBuilder = new TableBatchBuilder(schema, options);
|
|
1651
|
-
const parser = new StreamingJSONParser({
|
|
1652
|
-
jsonpaths
|
|
1653
|
-
});
|
|
1684
|
+
const parser = new StreamingJSONParser({ jsonpaths });
|
|
1654
1685
|
for await (const chunk of asyncIterator) {
|
|
1655
1686
|
const rows = parser.write(chunk);
|
|
1656
1687
|
const jsonpath2 = rows.length > 0 && parser.getStreamingJsonPathAsString();
|
|
1657
1688
|
if (rows.length > 0 && isFirstChunk) {
|
|
1658
1689
|
if (metadata) {
|
|
1659
1690
|
const initialBatch = {
|
|
1691
|
+
// Common fields
|
|
1660
1692
|
shape: options?.json?.shape || "array-row-table",
|
|
1661
1693
|
batchType: "partial-result",
|
|
1662
1694
|
data: [],
|
|
1663
1695
|
length: 0,
|
|
1664
1696
|
bytesUsed: 0,
|
|
1697
|
+
// JSON additions
|
|
1665
1698
|
container: parser.getPartialResult(),
|
|
1666
1699
|
jsonpath: jsonpath2
|
|
1667
1700
|
};
|
|
@@ -1671,25 +1704,19 @@ Char: ${this.c}`;
|
|
|
1671
1704
|
}
|
|
1672
1705
|
for (const row of rows) {
|
|
1673
1706
|
tableBatchBuilder.addRow(row);
|
|
1674
|
-
const batch3 = tableBatchBuilder.getFullBatch({
|
|
1675
|
-
jsonpath: jsonpath2
|
|
1676
|
-
});
|
|
1707
|
+
const batch3 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
|
|
1677
1708
|
if (batch3) {
|
|
1678
1709
|
yield batch3;
|
|
1679
1710
|
}
|
|
1680
1711
|
}
|
|
1681
1712
|
tableBatchBuilder.chunkComplete(chunk);
|
|
1682
|
-
const batch2 = tableBatchBuilder.getFullBatch({
|
|
1683
|
-
jsonpath: jsonpath2
|
|
1684
|
-
});
|
|
1713
|
+
const batch2 = tableBatchBuilder.getFullBatch({ jsonpath: jsonpath2 });
|
|
1685
1714
|
if (batch2) {
|
|
1686
1715
|
yield batch2;
|
|
1687
1716
|
}
|
|
1688
1717
|
}
|
|
1689
1718
|
const jsonpath = parser.getStreamingJsonPathAsString();
|
|
1690
|
-
const batch = tableBatchBuilder.getFinalBatch({
|
|
1691
|
-
jsonpath
|
|
1692
|
-
});
|
|
1719
|
+
const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
|
|
1693
1720
|
if (batch) {
|
|
1694
1721
|
yield batch;
|
|
1695
1722
|
}
|
|
@@ -1699,8 +1726,10 @@ Char: ${this.c}`;
|
|
|
1699
1726
|
batchType: "final-result",
|
|
1700
1727
|
container: parser.getPartialResult(),
|
|
1701
1728
|
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
1729
|
+
/** Data Just to avoid crashing? */
|
|
1702
1730
|
data: [],
|
|
1703
1731
|
length: 0
|
|
1732
|
+
// schema: null
|
|
1704
1733
|
};
|
|
1705
1734
|
yield finalBatch;
|
|
1706
1735
|
}
|
|
@@ -1720,7 +1749,7 @@ Char: ${this.c}`;
|
|
|
1720
1749
|
}
|
|
1721
1750
|
|
|
1722
1751
|
// src/json-loader.ts
|
|
1723
|
-
var VERSION =
|
|
1752
|
+
var VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1724
1753
|
var JSONLoader = {
|
|
1725
1754
|
name: "JSON",
|
|
1726
1755
|
id: "json",
|
|
@@ -1735,6 +1764,7 @@ Char: ${this.c}`;
|
|
|
1735
1764
|
shape: void 0,
|
|
1736
1765
|
table: false,
|
|
1737
1766
|
jsonpaths: []
|
|
1767
|
+
// batchSize: 'auto'
|
|
1738
1768
|
}
|
|
1739
1769
|
},
|
|
1740
1770
|
parse,
|
|
@@ -1745,23 +1775,11 @@ Char: ${this.c}`;
|
|
|
1745
1775
|
return parseTextSync(new TextDecoder().decode(arrayBuffer), options);
|
|
1746
1776
|
}
|
|
1747
1777
|
function parseTextSync(text, options) {
|
|
1748
|
-
const jsonOptions = {
|
|
1749
|
-
...options,
|
|
1750
|
-
json: {
|
|
1751
|
-
...JSONLoader.options.json,
|
|
1752
|
-
...options?.json
|
|
1753
|
-
}
|
|
1754
|
-
};
|
|
1778
|
+
const jsonOptions = { ...options, json: { ...JSONLoader.options.json, ...options?.json } };
|
|
1755
1779
|
return parseJSONSync(text, jsonOptions);
|
|
1756
1780
|
}
|
|
1757
1781
|
function parseInBatches(asyncIterator, options) {
|
|
1758
|
-
const jsonOptions = {
|
|
1759
|
-
...options,
|
|
1760
|
-
json: {
|
|
1761
|
-
...JSONLoader.options.json,
|
|
1762
|
-
...options?.json
|
|
1763
|
-
}
|
|
1764
|
-
};
|
|
1782
|
+
const jsonOptions = { ...options, json: { ...JSONLoader.options.json, ...options?.json } };
|
|
1765
1783
|
return parseJSONInBatches(asyncIterator, jsonOptions);
|
|
1766
1784
|
}
|
|
1767
1785
|
|
|
@@ -1789,10 +1807,7 @@ Char: ${this.c}`;
|
|
|
1789
1807
|
...options,
|
|
1790
1808
|
shape
|
|
1791
1809
|
});
|
|
1792
|
-
for await (const {
|
|
1793
|
-
counter,
|
|
1794
|
-
line
|
|
1795
|
-
} of numberedLineIterator) {
|
|
1810
|
+
for await (const { counter, line } of numberedLineIterator) {
|
|
1796
1811
|
try {
|
|
1797
1812
|
const row = JSON.parse(line);
|
|
1798
1813
|
tableBatchBuilder.addRow(row);
|
|
@@ -1812,14 +1827,19 @@ Char: ${this.c}`;
|
|
|
1812
1827
|
}
|
|
1813
1828
|
|
|
1814
1829
|
// src/ndjson-loader.ts
|
|
1815
|
-
var VERSION2 =
|
|
1830
|
+
var VERSION2 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
1816
1831
|
var NDJSONLoader = {
|
|
1817
1832
|
name: "NDJSON",
|
|
1818
1833
|
id: "ndjson",
|
|
1819
1834
|
module: "json",
|
|
1820
1835
|
version: VERSION2,
|
|
1821
1836
|
extensions: ["ndjson", "jsonl"],
|
|
1822
|
-
mimeTypes: [
|
|
1837
|
+
mimeTypes: [
|
|
1838
|
+
"application/x-ndjson",
|
|
1839
|
+
"application/jsonlines",
|
|
1840
|
+
// https://docs.aws.amazon.com/sagemaker/latest/dg/cdf-inference.html#cm-batch
|
|
1841
|
+
"application/json-seq"
|
|
1842
|
+
],
|
|
1823
1843
|
category: "table",
|
|
1824
1844
|
text: true,
|
|
1825
1845
|
parse: async (arrayBuffer) => parseNDJSONSync(new TextDecoder().decode(arrayBuffer)),
|
|
@@ -2370,14 +2390,18 @@ Char: ${this.c}`;
|
|
|
2370
2390
|
function flatGeojsonToBinary(features, geometryInfo, options) {
|
|
2371
2391
|
const propArrayTypes = extractNumericPropTypes(features);
|
|
2372
2392
|
const numericPropKeys = Object.keys(propArrayTypes).filter((k) => propArrayTypes[k] !== Array);
|
|
2373
|
-
return fillArrays(
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2393
|
+
return fillArrays(
|
|
2394
|
+
features,
|
|
2395
|
+
{
|
|
2396
|
+
propArrayTypes,
|
|
2397
|
+
...geometryInfo
|
|
2398
|
+
},
|
|
2399
|
+
{
|
|
2400
|
+
numericPropKeys: options && options.numericPropKeys || numericPropKeys,
|
|
2401
|
+
PositionDataType: options ? options.PositionDataType : Float32Array,
|
|
2402
|
+
triangulate: options ? options.triangulate : true
|
|
2403
|
+
}
|
|
2404
|
+
);
|
|
2381
2405
|
}
|
|
2382
2406
|
function extractNumericPropTypes(features) {
|
|
2383
2407
|
const propArrayTypes = {};
|
|
@@ -2405,11 +2429,7 @@ Char: ${this.c}`;
|
|
|
2405
2429
|
propArrayTypes,
|
|
2406
2430
|
coordLength
|
|
2407
2431
|
} = geometryInfo;
|
|
2408
|
-
const {
|
|
2409
|
-
numericPropKeys = [],
|
|
2410
|
-
PositionDataType = Float32Array,
|
|
2411
|
-
triangulate = true
|
|
2412
|
-
} = options;
|
|
2432
|
+
const { numericPropKeys = [], PositionDataType = Float32Array, triangulate = true } = options;
|
|
2413
2433
|
const hasGlobalId = features[0] && "id" in features[0];
|
|
2414
2434
|
const GlobalFeatureIdsDataType = features.length > 65535 ? Uint32Array : Uint16Array;
|
|
2415
2435
|
const points = {
|
|
@@ -2474,9 +2494,7 @@ Char: ${this.c}`;
|
|
|
2474
2494
|
handlePoint(geometry, points, indexMap, coordLength, properties);
|
|
2475
2495
|
points.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2476
2496
|
if (hasGlobalId) {
|
|
2477
|
-
points.fields.push({
|
|
2478
|
-
id: feature.id
|
|
2479
|
-
});
|
|
2497
|
+
points.fields.push({ id: feature.id });
|
|
2480
2498
|
}
|
|
2481
2499
|
indexMap.pointFeature++;
|
|
2482
2500
|
break;
|
|
@@ -2484,9 +2502,7 @@ Char: ${this.c}`;
|
|
|
2484
2502
|
handleLineString(geometry, lines, indexMap, coordLength, properties);
|
|
2485
2503
|
lines.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2486
2504
|
if (hasGlobalId) {
|
|
2487
|
-
lines.fields.push({
|
|
2488
|
-
id: feature.id
|
|
2489
|
-
});
|
|
2505
|
+
lines.fields.push({ id: feature.id });
|
|
2490
2506
|
}
|
|
2491
2507
|
indexMap.lineFeature++;
|
|
2492
2508
|
break;
|
|
@@ -2494,9 +2510,7 @@ Char: ${this.c}`;
|
|
|
2494
2510
|
handlePolygon(geometry, polygons, indexMap, coordLength, properties);
|
|
2495
2511
|
polygons.properties.push(keepStringProperties(properties, numericPropKeys));
|
|
2496
2512
|
if (hasGlobalId) {
|
|
2497
|
-
polygons.fields.push({
|
|
2498
|
-
id: feature.id
|
|
2499
|
-
});
|
|
2513
|
+
polygons.fields.push({ id: feature.id });
|
|
2500
2514
|
}
|
|
2501
2515
|
indexMap.polygonFeature++;
|
|
2502
2516
|
break;
|
|
@@ -2511,16 +2525,32 @@ Char: ${this.c}`;
|
|
|
2511
2525
|
points.positions.set(geometry.data, indexMap.pointPosition * coordLength);
|
|
2512
2526
|
const nPositions = geometry.data.length / coordLength;
|
|
2513
2527
|
fillNumericProperties(points, properties, indexMap.pointPosition, nPositions);
|
|
2514
|
-
points.globalFeatureIds.fill(
|
|
2515
|
-
|
|
2528
|
+
points.globalFeatureIds.fill(
|
|
2529
|
+
indexMap.feature,
|
|
2530
|
+
indexMap.pointPosition,
|
|
2531
|
+
indexMap.pointPosition + nPositions
|
|
2532
|
+
);
|
|
2533
|
+
points.featureIds.fill(
|
|
2534
|
+
indexMap.pointFeature,
|
|
2535
|
+
indexMap.pointPosition,
|
|
2536
|
+
indexMap.pointPosition + nPositions
|
|
2537
|
+
);
|
|
2516
2538
|
indexMap.pointPosition += nPositions;
|
|
2517
2539
|
}
|
|
2518
2540
|
function handleLineString(geometry, lines, indexMap, coordLength, properties) {
|
|
2519
2541
|
lines.positions.set(geometry.data, indexMap.linePosition * coordLength);
|
|
2520
2542
|
const nPositions = geometry.data.length / coordLength;
|
|
2521
2543
|
fillNumericProperties(lines, properties, indexMap.linePosition, nPositions);
|
|
2522
|
-
lines.globalFeatureIds.fill(
|
|
2523
|
-
|
|
2544
|
+
lines.globalFeatureIds.fill(
|
|
2545
|
+
indexMap.feature,
|
|
2546
|
+
indexMap.linePosition,
|
|
2547
|
+
indexMap.linePosition + nPositions
|
|
2548
|
+
);
|
|
2549
|
+
lines.featureIds.fill(
|
|
2550
|
+
indexMap.lineFeature,
|
|
2551
|
+
indexMap.linePosition,
|
|
2552
|
+
indexMap.linePosition + nPositions
|
|
2553
|
+
);
|
|
2524
2554
|
for (let i = 0, il = geometry.indices.length; i < il; ++i) {
|
|
2525
2555
|
const start = geometry.indices[i];
|
|
2526
2556
|
const end = i === il - 1 ? geometry.data.length : geometry.indices[i + 1];
|
|
@@ -2532,8 +2562,16 @@ Char: ${this.c}`;
|
|
|
2532
2562
|
polygons.positions.set(geometry.data, indexMap.polygonPosition * coordLength);
|
|
2533
2563
|
const nPositions = geometry.data.length / coordLength;
|
|
2534
2564
|
fillNumericProperties(polygons, properties, indexMap.polygonPosition, nPositions);
|
|
2535
|
-
polygons.globalFeatureIds.fill(
|
|
2536
|
-
|
|
2565
|
+
polygons.globalFeatureIds.fill(
|
|
2566
|
+
indexMap.feature,
|
|
2567
|
+
indexMap.polygonPosition,
|
|
2568
|
+
indexMap.polygonPosition + nPositions
|
|
2569
|
+
);
|
|
2570
|
+
polygons.featureIds.fill(
|
|
2571
|
+
indexMap.polygonFeature,
|
|
2572
|
+
indexMap.polygonPosition,
|
|
2573
|
+
indexMap.polygonPosition + nPositions
|
|
2574
|
+
);
|
|
2537
2575
|
for (let l = 0, ll = geometry.indices.length; l < ll; ++l) {
|
|
2538
2576
|
const startPosition = indexMap.polygonPosition;
|
|
2539
2577
|
polygons.polygonIndices[indexMap.polygonObject++] = startPosition;
|
|
@@ -2542,16 +2580,15 @@ Char: ${this.c}`;
|
|
|
2542
2580
|
const nextIndices = geometry.indices[l + 1];
|
|
2543
2581
|
for (let i = 0, il = indices.length; i < il; ++i) {
|
|
2544
2582
|
const start = indices[i];
|
|
2545
|
-
const end = i === il - 1 ?
|
|
2583
|
+
const end = i === il - 1 ? (
|
|
2584
|
+
// last line, so either read to:
|
|
2585
|
+
nextIndices === void 0 ? geometry.data.length : nextIndices[0]
|
|
2586
|
+
) : indices[i + 1];
|
|
2546
2587
|
polygons.primitivePolygonIndices[indexMap.polygonRing++] = indexMap.polygonPosition;
|
|
2547
2588
|
indexMap.polygonPosition += (end - start) / coordLength;
|
|
2548
2589
|
}
|
|
2549
2590
|
const endPosition = indexMap.polygonPosition;
|
|
2550
|
-
triangulatePolygon(polygons, areas, indices, {
|
|
2551
|
-
startPosition,
|
|
2552
|
-
endPosition,
|
|
2553
|
-
coordLength
|
|
2554
|
-
});
|
|
2591
|
+
triangulatePolygon(polygons, areas, indices, { startPosition, endPosition, coordLength });
|
|
2555
2592
|
}
|
|
2556
2593
|
}
|
|
2557
2594
|
function triangulatePolygon(polygons, areas, indices, {
|
|
@@ -2575,10 +2612,7 @@ Char: ${this.c}`;
|
|
|
2575
2612
|
function wrapProps(obj, size) {
|
|
2576
2613
|
const returnObj = {};
|
|
2577
2614
|
for (const key in obj) {
|
|
2578
|
-
returnObj[key] = {
|
|
2579
|
-
value: obj[key],
|
|
2580
|
-
size
|
|
2581
|
-
};
|
|
2615
|
+
returnObj[key] = { value: obj[key], size };
|
|
2582
2616
|
}
|
|
2583
2617
|
return returnObj;
|
|
2584
2618
|
}
|
|
@@ -2587,70 +2621,32 @@ Char: ${this.c}`;
|
|
|
2587
2621
|
shape: "binary-feature-collection",
|
|
2588
2622
|
points: {
|
|
2589
2623
|
...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
|
-
},
|
|
2624
|
+
positions: { value: points.positions, size: coordLength },
|
|
2625
|
+
globalFeatureIds: { value: points.globalFeatureIds, size: 1 },
|
|
2626
|
+
featureIds: { value: points.featureIds, size: 1 },
|
|
2602
2627
|
numericProps: wrapProps(points.numericProps, 1)
|
|
2603
2628
|
},
|
|
2604
2629
|
lines: {
|
|
2605
2630
|
...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
|
-
},
|
|
2631
|
+
positions: { value: lines.positions, size: coordLength },
|
|
2632
|
+
pathIndices: { value: lines.pathIndices, size: 1 },
|
|
2633
|
+
globalFeatureIds: { value: lines.globalFeatureIds, size: 1 },
|
|
2634
|
+
featureIds: { value: lines.featureIds, size: 1 },
|
|
2622
2635
|
numericProps: wrapProps(lines.numericProps, 1)
|
|
2623
2636
|
},
|
|
2624
2637
|
polygons: {
|
|
2625
2638
|
...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
|
-
},
|
|
2639
|
+
positions: { value: polygons.positions, size: coordLength },
|
|
2640
|
+
polygonIndices: { value: polygons.polygonIndices, size: 1 },
|
|
2641
|
+
primitivePolygonIndices: { value: polygons.primitivePolygonIndices, size: 1 },
|
|
2642
|
+
globalFeatureIds: { value: polygons.globalFeatureIds, size: 1 },
|
|
2643
|
+
featureIds: { value: polygons.featureIds, size: 1 },
|
|
2646
2644
|
numericProps: wrapProps(polygons.numericProps, 1)
|
|
2647
2645
|
}
|
|
2646
|
+
// triangles not expected
|
|
2648
2647
|
};
|
|
2649
2648
|
if (binaryFeatures.polygons && polygons.triangles) {
|
|
2650
|
-
binaryFeatures.polygons.triangles = {
|
|
2651
|
-
value: new Uint32Array(polygons.triangles),
|
|
2652
|
-
size: 1
|
|
2653
|
-
};
|
|
2649
|
+
binaryFeatures.polygons.triangles = { value: new Uint32Array(polygons.triangles), size: 1 };
|
|
2654
2650
|
}
|
|
2655
2651
|
return binaryFeatures;
|
|
2656
2652
|
}
|
|
@@ -2764,10 +2760,7 @@ Char: ${this.c}`;
|
|
|
2764
2760
|
}
|
|
2765
2761
|
|
|
2766
2762
|
// ../gis/src/lib/binary-features/geojson-to-flat-geojson.ts
|
|
2767
|
-
function geojsonToFlatGeojson(features, options = {
|
|
2768
|
-
coordLength: 2,
|
|
2769
|
-
fixRingWinding: true
|
|
2770
|
-
}) {
|
|
2763
|
+
function geojsonToFlatGeojson(features, options = { coordLength: 2, fixRingWinding: true }) {
|
|
2771
2764
|
return features.map((feature) => flattenFeature(feature, options));
|
|
2772
2765
|
}
|
|
2773
2766
|
function flattenPoint(coordinates, data, indices, options) {
|
|
@@ -2808,9 +2801,7 @@ Char: ${this.c}`;
|
|
|
2808
2801
|
}
|
|
2809
2802
|
}
|
|
2810
2803
|
function flattenFeature(feature, options) {
|
|
2811
|
-
const {
|
|
2812
|
-
geometry
|
|
2813
|
-
} = feature;
|
|
2804
|
+
const { geometry } = feature;
|
|
2814
2805
|
if (geometry.type === "GeometryCollection") {
|
|
2815
2806
|
throw new Error("GeometryCollection type not supported");
|
|
2816
2807
|
}
|
|
@@ -2848,31 +2839,15 @@ Char: ${this.c}`;
|
|
|
2848
2839
|
default:
|
|
2849
2840
|
throw new Error(`Unknown type: ${type}`);
|
|
2850
2841
|
}
|
|
2851
|
-
return {
|
|
2852
|
-
...feature,
|
|
2853
|
-
geometry: {
|
|
2854
|
-
type,
|
|
2855
|
-
indices,
|
|
2856
|
-
data,
|
|
2857
|
-
areas
|
|
2858
|
-
}
|
|
2859
|
-
};
|
|
2842
|
+
return { ...feature, geometry: { type, indices, data, areas } };
|
|
2860
2843
|
}
|
|
2861
2844
|
|
|
2862
2845
|
// ../gis/src/lib/binary-features/geojson-to-binary.ts
|
|
2863
|
-
function geojsonToBinary(features, options = {
|
|
2864
|
-
fixRingWinding: true,
|
|
2865
|
-
triangulate: true
|
|
2866
|
-
}) {
|
|
2846
|
+
function geojsonToBinary(features, options = { fixRingWinding: true, triangulate: true }) {
|
|
2867
2847
|
const geometryInfo = extractGeometryInfo(features);
|
|
2868
2848
|
const coordLength = geometryInfo.coordLength;
|
|
2869
|
-
const {
|
|
2870
|
-
|
|
2871
|
-
} = options;
|
|
2872
|
-
const flatFeatures = geojsonToFlatGeojson(features, {
|
|
2873
|
-
coordLength,
|
|
2874
|
-
fixRingWinding
|
|
2875
|
-
});
|
|
2849
|
+
const { fixRingWinding } = options;
|
|
2850
|
+
const flatFeatures = geojsonToFlatGeojson(features, { coordLength, fixRingWinding });
|
|
2876
2851
|
return flatGeojsonToBinary(flatFeatures, geometryInfo, {
|
|
2877
2852
|
numericPropKeys: options.numericPropKeys,
|
|
2878
2853
|
PositionDataType: options.PositionDataType || Float32Array,
|
|
@@ -2881,7 +2856,7 @@ Char: ${this.c}`;
|
|
|
2881
2856
|
}
|
|
2882
2857
|
|
|
2883
2858
|
// src/geojson-loader.ts
|
|
2884
|
-
var VERSION3 =
|
|
2859
|
+
var VERSION3 = typeof __VERSION__ !== "undefined" ? __VERSION__ : "latest";
|
|
2885
2860
|
var GeoJSONWorkerLoader = {
|
|
2886
2861
|
name: "GeoJSON",
|
|
2887
2862
|
id: "geojson",
|
|
@@ -2907,7 +2882,9 @@ Char: ${this.c}`;
|
|
|
2907
2882
|
};
|
|
2908
2883
|
var GeoJSONLoader = {
|
|
2909
2884
|
...GeoJSONWorkerLoader,
|
|
2885
|
+
// @ts-expect-error
|
|
2910
2886
|
parse: parse2,
|
|
2887
|
+
// @ts-expect-error
|
|
2911
2888
|
parseTextSync: parseTextSync2,
|
|
2912
2889
|
parseInBatches: parseInBatches2
|
|
2913
2890
|
};
|
|
@@ -2915,14 +2892,8 @@ Char: ${this.c}`;
|
|
|
2915
2892
|
return parseTextSync2(new TextDecoder().decode(arrayBuffer), options);
|
|
2916
2893
|
}
|
|
2917
2894
|
function parseTextSync2(text, options) {
|
|
2918
|
-
options = {
|
|
2919
|
-
|
|
2920
|
-
...options
|
|
2921
|
-
};
|
|
2922
|
-
options.geojson = {
|
|
2923
|
-
...GeoJSONLoader.options.geojson,
|
|
2924
|
-
...options.geojson
|
|
2925
|
-
};
|
|
2895
|
+
options = { ...GeoJSONLoader.options, ...options };
|
|
2896
|
+
options.geojson = { ...GeoJSONLoader.options.geojson, ...options.geojson };
|
|
2926
2897
|
options.gis = options.gis || {};
|
|
2927
2898
|
let geojson;
|
|
2928
2899
|
try {
|
|
@@ -2932,6 +2903,8 @@ Char: ${this.c}`;
|
|
|
2932
2903
|
}
|
|
2933
2904
|
const table = {
|
|
2934
2905
|
shape: "geojson-table",
|
|
2906
|
+
// TODO - deduce schema from geojson
|
|
2907
|
+
// TODO check that parsed data is of type FeatureCollection
|
|
2935
2908
|
type: "FeatureCollection",
|
|
2936
2909
|
features: geojson?.features || []
|
|
2937
2910
|
};
|
|
@@ -2943,14 +2916,8 @@ Char: ${this.c}`;
|
|
|
2943
2916
|
}
|
|
2944
2917
|
}
|
|
2945
2918
|
function parseInBatches2(asyncIterator, options) {
|
|
2946
|
-
options = {
|
|
2947
|
-
|
|
2948
|
-
...options
|
|
2949
|
-
};
|
|
2950
|
-
options.json = {
|
|
2951
|
-
...GeoJSONLoader.options.geojson,
|
|
2952
|
-
...options.geojson
|
|
2953
|
-
};
|
|
2919
|
+
options = { ...GeoJSONLoader.options, ...options };
|
|
2920
|
+
options.json = { ...GeoJSONLoader.options.geojson, ...options.geojson };
|
|
2954
2921
|
const geojsonIterator = parseJSONInBatches(asyncIterator, options);
|
|
2955
2922
|
switch (options.gis.format) {
|
|
2956
2923
|
case "binary":
|
|
@@ -3008,11 +2975,7 @@ Char: ${this.c}`;
|
|
|
3008
2975
|
const columnName = table.schema?.fields[geometryColumnIndex].name;
|
|
3009
2976
|
let featureOrGeometry = columnName && row[columnName];
|
|
3010
2977
|
if (!featureOrGeometry) {
|
|
3011
|
-
return {
|
|
3012
|
-
type: "Feature",
|
|
3013
|
-
geometry: null,
|
|
3014
|
-
properties
|
|
3015
|
-
};
|
|
2978
|
+
return { type: "Feature", geometry: null, properties };
|
|
3016
2979
|
}
|
|
3017
2980
|
if (typeof featureOrGeometry === "string") {
|
|
3018
2981
|
try {
|
|
@@ -3025,20 +2988,14 @@ Char: ${this.c}`;
|
|
|
3025
2988
|
throw new Error("invalid geometry column value");
|
|
3026
2989
|
}
|
|
3027
2990
|
if (featureOrGeometry?.type === "Feature") {
|
|
3028
|
-
return {
|
|
3029
|
-
...featureOrGeometry,
|
|
3030
|
-
properties
|
|
3031
|
-
};
|
|
2991
|
+
return { ...featureOrGeometry, properties };
|
|
3032
2992
|
}
|
|
3033
|
-
return {
|
|
3034
|
-
type: "Feature",
|
|
3035
|
-
geometry: featureOrGeometry,
|
|
3036
|
-
properties
|
|
3037
|
-
};
|
|
2993
|
+
return { type: "Feature", geometry: featureOrGeometry, properties };
|
|
3038
2994
|
}
|
|
3039
2995
|
|
|
3040
2996
|
// src/lib/encoder-utils/utf8-encoder.ts
|
|
3041
2997
|
var Utf8ArrayBufferEncoder = class {
|
|
2998
|
+
chunkSize;
|
|
3042
2999
|
strings = [];
|
|
3043
3000
|
totalLength = 0;
|
|
3044
3001
|
textEncoder = new TextEncoder();
|
|
@@ -3067,11 +3024,7 @@ Char: ${this.c}`;
|
|
|
3067
3024
|
|
|
3068
3025
|
// src/lib/encoders/geojson-encoder.ts
|
|
3069
3026
|
async function* encodeTableAsGeojsonInBatches(batchIterator, inputOpts = {}) {
|
|
3070
|
-
const options = {
|
|
3071
|
-
geojson: {},
|
|
3072
|
-
chunkSize: 1e4,
|
|
3073
|
-
...inputOpts
|
|
3074
|
-
};
|
|
3027
|
+
const options = { geojson: {}, chunkSize: 1e4, ...inputOpts };
|
|
3075
3028
|
const utf8Encoder = new Utf8ArrayBufferEncoder(options.chunkSize);
|
|
3076
3029
|
if (!options.geojson.featureArray) {
|
|
3077
3030
|
utf8Encoder.push("{\n", '"type": "FeatureCollection",\n', '"features":\n');
|
|
@@ -3132,7 +3085,7 @@ Char: ${this.c}`;
|
|
|
3132
3085
|
},
|
|
3133
3086
|
encodeInBatches: (tableIterator, options) => encodeTableAsGeojsonInBatches(tableIterator, options)
|
|
3134
3087
|
};
|
|
3135
|
-
return __toCommonJS(
|
|
3088
|
+
return __toCommonJS(bundle_exports);
|
|
3136
3089
|
})();
|
|
3137
3090
|
return __exports__;
|
|
3138
3091
|
});
|