@loaders.gl/json 4.1.0-alpha.1 → 4.1.0-alpha.10
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 +82 -40
- package/dist/geojson-loader.d.ts.map +1 -1
- package/dist/geojson-loader.js +1 -1
- package/dist/geojson-loader.js.map +1 -1
- package/dist/geojson-worker.js +41 -26
- package/dist/geojson-writer.d.ts +1 -1
- package/dist/geojson-writer.d.ts.map +1 -1
- package/dist/geojson-writer.js +7 -1
- package/dist/geojson-writer.js.map +1 -1
- package/dist/index.cjs +24 -20
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/json-loader.d.ts +15 -8
- package/dist/json-loader.d.ts.map +1 -1
- package/dist/json-loader.js +11 -12
- package/dist/json-loader.js.map +1 -1
- package/dist/json-writer.d.ts.map +1 -1
- package/dist/json-writer.js.map +1 -1
- package/dist/lib/clarinet/clarinet.d.ts.map +1 -1
- package/dist/lib/clarinet/clarinet.js.map +1 -1
- package/dist/lib/encoder-utils/encode-table-row.d.ts.map +1 -1
- package/dist/lib/encoder-utils/encode-table-row.js.map +1 -1
- package/dist/lib/encoder-utils/encode-utils.d.ts.map +1 -1
- package/dist/lib/encoder-utils/encode-utils.js.map +1 -1
- package/dist/lib/encoder-utils/utf8-encoder.d.ts.map +1 -1
- package/dist/lib/encoder-utils/utf8-encoder.js.map +1 -1
- package/dist/lib/encoders/geojson-encoder.d.ts +1 -1
- package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/geojson-encoder.js.map +1 -1
- package/dist/lib/encoders/json-encoder.d.ts.map +1 -1
- package/dist/lib/encoders/json-encoder.js.map +1 -1
- package/dist/lib/parsers/parse-json-in-batches.d.ts +2 -2
- package/dist/lib/parsers/parse-json-in-batches.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json-in-batches.js +4 -8
- package/dist/lib/parsers/parse-json-in-batches.js.map +1 -1
- package/dist/lib/parsers/parse-json.d.ts.map +1 -1
- package/dist/lib/parsers/parse-json.js.map +1 -1
- package/dist/ndgeoson-loader.js +1 -1
- package/dist/ndgeoson-loader.js.map +1 -1
- package/dist/ndjson-loader.d.ts.map +1 -1
- package/dist/ndjson-loader.js +1 -1
- package/dist/ndjson-loader.js.map +1 -1
- package/package.json +7 -7
- package/src/geojson-loader.ts +3 -2
- package/src/geojson-writer.ts +16 -4
- package/src/index.ts +2 -1
- package/src/json-loader.ts +34 -22
- package/src/json-writer.ts +2 -1
- package/src/lib/clarinet/clarinet.ts +2 -1
- package/src/lib/encoder-utils/encode-table-row.ts +2 -1
- package/src/lib/encoder-utils/encode-utils.ts +2 -1
- package/src/lib/encoder-utils/utf8-encoder.ts +2 -1
- package/src/lib/encoders/geojson-encoder.ts +3 -2
- package/src/lib/encoders/json-encoder.ts +2 -1
- package/src/lib/parsers/parse-json-in-batches.ts +9 -14
- package/src/lib/parsers/parse-json.ts +2 -1
- package/src/ndjson-loader.ts +2 -1
package/dist/dist.dev.js
CHANGED
|
@@ -62,6 +62,7 @@ var __exports__ = (() => {
|
|
|
62
62
|
if (Number.isFinite(cursor)) {
|
|
63
63
|
this.cursor = cursor;
|
|
64
64
|
}
|
|
65
|
+
this.shape = "array-row-table";
|
|
65
66
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
66
67
|
this.rows[this.length] = row;
|
|
67
68
|
this.length++;
|
|
@@ -70,6 +71,7 @@ var __exports__ = (() => {
|
|
|
70
71
|
if (Number.isFinite(cursor)) {
|
|
71
72
|
this.cursor = cursor;
|
|
72
73
|
}
|
|
74
|
+
this.shape = "object-row-table";
|
|
73
75
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
74
76
|
this.rows[this.length] = row;
|
|
75
77
|
this.length++;
|
|
@@ -82,7 +84,7 @@ var __exports__ = (() => {
|
|
|
82
84
|
rows = rows.slice(0, this.length);
|
|
83
85
|
this.rows = null;
|
|
84
86
|
const batch = {
|
|
85
|
-
shape: this.
|
|
87
|
+
shape: this.shape || "array-row-table",
|
|
86
88
|
batchType: "data",
|
|
87
89
|
data: rows,
|
|
88
90
|
length: this.length,
|
|
@@ -98,12 +100,16 @@ var __exports__ = (() => {
|
|
|
98
100
|
if (!arrayRow) {
|
|
99
101
|
throw new Error("null row");
|
|
100
102
|
}
|
|
101
|
-
if (!headers) {
|
|
102
|
-
throw new Error("no headers");
|
|
103
|
-
}
|
|
104
103
|
const objectRow = {};
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
if (headers) {
|
|
105
|
+
for (let i = 0; i < headers.length; i++) {
|
|
106
|
+
objectRow[headers[i]] = arrayRow[i];
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
110
|
+
const columnName = `column-${i}`;
|
|
111
|
+
objectRow[columnName] = arrayRow[i];
|
|
112
|
+
}
|
|
107
113
|
}
|
|
108
114
|
return objectRow;
|
|
109
115
|
}
|
|
@@ -111,14 +117,25 @@ var __exports__ = (() => {
|
|
|
111
117
|
if (!objectRow) {
|
|
112
118
|
throw new Error("null row");
|
|
113
119
|
}
|
|
114
|
-
if (
|
|
115
|
-
|
|
120
|
+
if (headers) {
|
|
121
|
+
const arrayRow = new Array(headers.length);
|
|
122
|
+
for (let i = 0; i < headers.length; i++) {
|
|
123
|
+
arrayRow[i] = objectRow[headers[i]];
|
|
124
|
+
}
|
|
125
|
+
return arrayRow;
|
|
116
126
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
127
|
+
return Object.values(objectRow);
|
|
128
|
+
}
|
|
129
|
+
function inferHeadersFromArrayRow(arrayRow) {
|
|
130
|
+
const headers = [];
|
|
131
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
132
|
+
const columnName = `column-${i}`;
|
|
133
|
+
headers.push(columnName);
|
|
120
134
|
}
|
|
121
|
-
return
|
|
135
|
+
return headers;
|
|
136
|
+
}
|
|
137
|
+
function inferHeadersFromObjectRow(row) {
|
|
138
|
+
return Object.keys(row);
|
|
122
139
|
}
|
|
123
140
|
|
|
124
141
|
// ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
|
|
@@ -128,11 +145,11 @@ var __exports__ = (() => {
|
|
|
128
145
|
objectRows = null;
|
|
129
146
|
arrayRows = null;
|
|
130
147
|
cursor = 0;
|
|
131
|
-
_headers =
|
|
148
|
+
_headers = null;
|
|
132
149
|
constructor(schema, options) {
|
|
133
150
|
this.options = options;
|
|
134
151
|
this.schema = schema;
|
|
135
|
-
if (
|
|
152
|
+
if (schema) {
|
|
136
153
|
this._headers = [];
|
|
137
154
|
for (const key in schema) {
|
|
138
155
|
this._headers[schema[key].index] = schema[key].name;
|
|
@@ -146,6 +163,7 @@ var __exports__ = (() => {
|
|
|
146
163
|
if (Number.isFinite(cursor)) {
|
|
147
164
|
this.cursor = cursor;
|
|
148
165
|
}
|
|
166
|
+
this._headers ||= inferHeadersFromArrayRow(row);
|
|
149
167
|
switch (this.options.shape) {
|
|
150
168
|
case "object-row-table":
|
|
151
169
|
const rowObject = convertToObjectRow(row, this._headers);
|
|
@@ -162,6 +180,7 @@ var __exports__ = (() => {
|
|
|
162
180
|
if (Number.isFinite(cursor)) {
|
|
163
181
|
this.cursor = cursor;
|
|
164
182
|
}
|
|
183
|
+
this._headers ||= inferHeadersFromObjectRow(row);
|
|
165
184
|
switch (this.options.shape) {
|
|
166
185
|
case "array-row-table":
|
|
167
186
|
const rowArray = convertToArrayRow(row, this._headers);
|
|
@@ -271,7 +290,7 @@ var __exports__ = (() => {
|
|
|
271
290
|
|
|
272
291
|
// ../schema/src/lib/table/batches/table-batch-builder.ts
|
|
273
292
|
var DEFAULT_OPTIONS = {
|
|
274
|
-
shape:
|
|
293
|
+
shape: void 0,
|
|
275
294
|
batchSize: "auto",
|
|
276
295
|
batchDebounceMs: 0,
|
|
277
296
|
limit: 0,
|
|
@@ -383,8 +402,6 @@ var __exports__ = (() => {
|
|
|
383
402
|
}
|
|
384
403
|
_getTableBatchType() {
|
|
385
404
|
switch (this.options.shape) {
|
|
386
|
-
case "row-table":
|
|
387
|
-
return BaseTableBatchAggregator;
|
|
388
405
|
case "array-row-table":
|
|
389
406
|
case "object-row-table":
|
|
390
407
|
return RowTableBatchAggregator;
|
|
@@ -396,7 +413,7 @@ var __exports__ = (() => {
|
|
|
396
413
|
}
|
|
397
414
|
return TableBatchBuilder.ArrowBatch;
|
|
398
415
|
default:
|
|
399
|
-
|
|
416
|
+
return BaseTableBatchAggregator;
|
|
400
417
|
}
|
|
401
418
|
}
|
|
402
419
|
};
|
|
@@ -781,6 +798,22 @@ var __exports__ = (() => {
|
|
|
781
798
|
}
|
|
782
799
|
}
|
|
783
800
|
|
|
801
|
+
// ../loader-utils/src/lib/binary-utils/array-buffer-utils.ts
|
|
802
|
+
function concatenateArrayBuffers(...sources) {
|
|
803
|
+
return concatenateArrayBuffersFromArray(sources);
|
|
804
|
+
}
|
|
805
|
+
function concatenateArrayBuffersFromArray(sources) {
|
|
806
|
+
const sourceArrays = sources.map((source2) => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
|
|
807
|
+
const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
|
|
808
|
+
const result = new Uint8Array(byteLength);
|
|
809
|
+
let offset = 0;
|
|
810
|
+
for (const sourceArray of sourceArrays) {
|
|
811
|
+
result.set(sourceArray, offset);
|
|
812
|
+
offset += sourceArray.byteLength;
|
|
813
|
+
}
|
|
814
|
+
return result.buffer;
|
|
815
|
+
}
|
|
816
|
+
|
|
784
817
|
// ../loader-utils/src/lib/iterators/text-iterators.ts
|
|
785
818
|
async function* makeTextDecoderIterator(arrayBufferIterator, options = {}) {
|
|
786
819
|
const textDecoder = new TextDecoder(void 0, options);
|
|
@@ -816,6 +849,15 @@ var __exports__ = (() => {
|
|
|
816
849
|
}
|
|
817
850
|
}
|
|
818
851
|
|
|
852
|
+
// ../loader-utils/src/lib/iterators/async-iteration.ts
|
|
853
|
+
async function concatenateArrayBuffersAsync(asyncIterator) {
|
|
854
|
+
const arrayBuffers = [];
|
|
855
|
+
for await (const chunk of asyncIterator) {
|
|
856
|
+
arrayBuffers.push(chunk);
|
|
857
|
+
}
|
|
858
|
+
return concatenateArrayBuffers(...arrayBuffers);
|
|
859
|
+
}
|
|
860
|
+
|
|
819
861
|
// ../../node_modules/@babel/runtime/helpers/esm/typeof.js
|
|
820
862
|
function _typeof(obj) {
|
|
821
863
|
"@babel/helpers - typeof";
|
|
@@ -1605,11 +1647,7 @@ Char: ${this.c}`;
|
|
|
1605
1647
|
} = options.json || {};
|
|
1606
1648
|
let isFirstChunk = true;
|
|
1607
1649
|
const schema = null;
|
|
1608
|
-
const
|
|
1609
|
-
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
1610
|
-
...options,
|
|
1611
|
-
shape
|
|
1612
|
-
});
|
|
1650
|
+
const tableBatchBuilder = new TableBatchBuilder(schema, options);
|
|
1613
1651
|
const parser = new StreamingJSONParser({
|
|
1614
1652
|
jsonpaths
|
|
1615
1653
|
});
|
|
@@ -1619,7 +1657,7 @@ Char: ${this.c}`;
|
|
|
1619
1657
|
if (rows.length > 0 && isFirstChunk) {
|
|
1620
1658
|
if (metadata) {
|
|
1621
1659
|
const initialBatch = {
|
|
1622
|
-
shape,
|
|
1660
|
+
shape: options?.json?.shape || "array-row-table",
|
|
1623
1661
|
batchType: "partial-result",
|
|
1624
1662
|
data: [],
|
|
1625
1663
|
length: 0,
|
|
@@ -1657,7 +1695,7 @@ Char: ${this.c}`;
|
|
|
1657
1695
|
}
|
|
1658
1696
|
if (metadata) {
|
|
1659
1697
|
const finalBatch = {
|
|
1660
|
-
shape,
|
|
1698
|
+
shape: "json",
|
|
1661
1699
|
batchType: "final-result",
|
|
1662
1700
|
container: parser.getPartialResult(),
|
|
1663
1701
|
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
@@ -1682,14 +1720,7 @@ Char: ${this.c}`;
|
|
|
1682
1720
|
}
|
|
1683
1721
|
|
|
1684
1722
|
// src/json-loader.ts
|
|
1685
|
-
var VERSION =
|
|
1686
|
-
var DEFAULT_JSON_LOADER_OPTIONS = {
|
|
1687
|
-
json: {
|
|
1688
|
-
shape: "object-row-table",
|
|
1689
|
-
table: false,
|
|
1690
|
-
jsonpaths: []
|
|
1691
|
-
}
|
|
1692
|
-
};
|
|
1723
|
+
var VERSION = true ? "4.1.0-alpha.10" : "latest";
|
|
1693
1724
|
var JSONLoader = {
|
|
1694
1725
|
name: "JSON",
|
|
1695
1726
|
id: "json",
|
|
@@ -1699,10 +1730,16 @@ Char: ${this.c}`;
|
|
|
1699
1730
|
mimeTypes: ["application/json"],
|
|
1700
1731
|
category: "table",
|
|
1701
1732
|
text: true,
|
|
1733
|
+
options: {
|
|
1734
|
+
json: {
|
|
1735
|
+
shape: void 0,
|
|
1736
|
+
table: false,
|
|
1737
|
+
jsonpaths: []
|
|
1738
|
+
}
|
|
1739
|
+
},
|
|
1702
1740
|
parse,
|
|
1703
1741
|
parseTextSync,
|
|
1704
|
-
parseInBatches
|
|
1705
|
-
options: DEFAULT_JSON_LOADER_OPTIONS
|
|
1742
|
+
parseInBatches
|
|
1706
1743
|
};
|
|
1707
1744
|
async function parse(arrayBuffer, options) {
|
|
1708
1745
|
return parseTextSync(new TextDecoder().decode(arrayBuffer), options);
|
|
@@ -1711,7 +1748,7 @@ Char: ${this.c}`;
|
|
|
1711
1748
|
const jsonOptions = {
|
|
1712
1749
|
...options,
|
|
1713
1750
|
json: {
|
|
1714
|
-
...
|
|
1751
|
+
...JSONLoader.options.json,
|
|
1715
1752
|
...options?.json
|
|
1716
1753
|
}
|
|
1717
1754
|
};
|
|
@@ -1721,7 +1758,7 @@ Char: ${this.c}`;
|
|
|
1721
1758
|
const jsonOptions = {
|
|
1722
1759
|
...options,
|
|
1723
1760
|
json: {
|
|
1724
|
-
...
|
|
1761
|
+
...JSONLoader.options.json,
|
|
1725
1762
|
...options?.json
|
|
1726
1763
|
}
|
|
1727
1764
|
};
|
|
@@ -1775,7 +1812,7 @@ Char: ${this.c}`;
|
|
|
1775
1812
|
}
|
|
1776
1813
|
|
|
1777
1814
|
// src/ndjson-loader.ts
|
|
1778
|
-
var VERSION2 =
|
|
1815
|
+
var VERSION2 = true ? "4.1.0-alpha.10" : "latest";
|
|
1779
1816
|
var NDJSONLoader = {
|
|
1780
1817
|
name: "NDJSON",
|
|
1781
1818
|
id: "ndjson",
|
|
@@ -2844,7 +2881,7 @@ Char: ${this.c}`;
|
|
|
2844
2881
|
}
|
|
2845
2882
|
|
|
2846
2883
|
// src/geojson-loader.ts
|
|
2847
|
-
var VERSION3 =
|
|
2884
|
+
var VERSION3 = true ? "4.1.0-alpha.10" : "latest";
|
|
2848
2885
|
var GeoJSONWorkerLoader = {
|
|
2849
2886
|
name: "GeoJSON",
|
|
2850
2887
|
id: "geojson",
|
|
@@ -3081,13 +3118,18 @@ Char: ${this.c}`;
|
|
|
3081
3118
|
name: "GeoJSON",
|
|
3082
3119
|
extensions: ["geojson"],
|
|
3083
3120
|
mimeTypes: ["application/geo+json"],
|
|
3121
|
+
text: true,
|
|
3084
3122
|
options: {
|
|
3085
3123
|
geojson: {
|
|
3086
3124
|
featureArray: false,
|
|
3087
3125
|
geometryColumn: null
|
|
3088
3126
|
}
|
|
3089
3127
|
},
|
|
3090
|
-
|
|
3128
|
+
async encode(table, options) {
|
|
3129
|
+
const tableIterator = [table];
|
|
3130
|
+
const batches = encodeTableAsGeojsonInBatches(tableIterator, options);
|
|
3131
|
+
return await concatenateArrayBuffersAsync(batches);
|
|
3132
|
+
},
|
|
3091
3133
|
encodeInBatches: (tableIterator, options) => encodeTableAsGeojsonInBatches(tableIterator, options)
|
|
3092
3134
|
};
|
|
3093
3135
|
return __toCommonJS(src_exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-loader.d.ts","sourceRoot":"","sources":["../src/geojson-loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geojson-loader.d.ts","sourceRoot":"","sources":["../src/geojson-loader.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,gBAAgB,EAAC,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAC,OAAO,EAAgB,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC1E,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,eAAe,CAAC;AASrD,MAAM,MAAM,oBAAoB,GAAG,iBAAiB,GAAG;IACrD,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,kBAAkB,CAAC;KAC5B,CAAC;IACF,GAAG,CAAC,EAAE;QACJ,MAAM,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAC;KAC/B,CAAC;CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,EAAE,oBAAoB,CAsBjF,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,oBAAoB,CAOrF,CAAC"}
|
package/dist/geojson-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { geojsonToBinary } from '@loaders.gl/gis';
|
|
2
2
|
import { parseJSONInBatches } from "./lib/parsers/parse-json-in-batches.js";
|
|
3
|
-
const VERSION = typeof
|
|
3
|
+
const VERSION = typeof "4.1.0-alpha.10" !== 'undefined' ? "4.1.0-alpha.10" : 'latest';
|
|
4
4
|
export const GeoJSONWorkerLoader = {
|
|
5
5
|
name: 'GeoJSON',
|
|
6
6
|
id: 'geojson',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-loader.js","names":["geojsonToBinary","parseJSONInBatches","VERSION","
|
|
1
|
+
{"version":3,"file":"geojson-loader.js","names":["geojsonToBinary","parseJSONInBatches","VERSION","GeoJSONWorkerLoader","name","id","module","version","worker","extensions","mimeTypes","category","text","options","geojson","shape","json","jsonpaths","gis","format","GeoJSONLoader","parse","parseTextSync","parseInBatches","arrayBuffer","TextDecoder","decode","_geojson","JSON","table","type","features","asyncIterator","geojsonIterator","makeBinaryGeometryIterator","batch","data"],"sources":["../src/geojson-loader.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n\nimport type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {GeoJSON, GeoJSONTable, TableBatch} from '@loaders.gl/schema';\nimport type {JSONLoaderOptions} from './json-loader';\nimport {geojsonToBinary} from '@loaders.gl/gis';\n// import {parseJSONSync} from './lib/parsers/parse-json';\nimport {parseJSONInBatches} from './lib/parsers/parse-json-in-batches';\n\n// __VERSION__ is injected by babel-plugin-version-inline\n// @ts-ignore TS2304: Cannot find name '__VERSION__'.\nconst VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';\n\nexport type GeoJSONLoaderOptions = JSONLoaderOptions & {\n geojson?: {\n shape?: 'object-row-table';\n };\n gis?: {\n format?: 'geojson' | 'binary';\n };\n};\n\n/**\n * GeoJSON loader\n */\nexport const GeoJSONWorkerLoader: Loader<GeoJSON, TableBatch, GeoJSONLoaderOptions> = {\n name: 'GeoJSON',\n id: 'geojson',\n module: 'geojson',\n version: VERSION,\n worker: true,\n extensions: ['geojson'],\n mimeTypes: ['application/geo+json'],\n category: 'geometry',\n text: true,\n options: {\n geojson: {\n shape: 'object-row-table'\n },\n json: {\n shape: 'object-row-table',\n jsonpaths: ['$', '$.features']\n },\n gis: {\n format: 'geojson'\n }\n }\n};\n\nexport const GeoJSONLoader: LoaderWithParser<GeoJSON, TableBatch, GeoJSONLoaderOptions> = {\n ...GeoJSONWorkerLoader,\n // @ts-expect-error\n parse,\n // @ts-expect-error\n parseTextSync,\n parseInBatches\n};\n\nasync function parse(arrayBuffer: ArrayBuffer, options?: GeoJSONLoaderOptions) {\n return parseTextSync(new TextDecoder().decode(arrayBuffer), options);\n}\n\nfunction parseTextSync(text: string, options?: GeoJSONLoaderOptions) {\n // Apps can call the parse method directly, we so apply default options here\n options = {...GeoJSONLoader.options, ...options};\n options.geojson = {...GeoJSONLoader.options.geojson, ...options.geojson};\n options.gis = options.gis || {};\n\n let geojson;\n try {\n geojson = JSON.parse(text);\n } catch {\n geojson = {};\n }\n\n const table: GeoJSONTable = {\n shape: 'geojson-table',\n // TODO - deduce schema from geojson\n // TODO check that parsed data is of type FeatureCollection\n type: 'FeatureCollection',\n features: geojson?.features || []\n };\n\n switch (options.gis.format) {\n case 'binary':\n return geojsonToBinary(table.features);\n default:\n return table;\n }\n}\n\nfunction parseInBatches(asyncIterator, options): AsyncIterable<TableBatch> {\n // Apps can call the parse method directly, we so apply default options here\n options = {...GeoJSONLoader.options, ...options};\n options.json = {...GeoJSONLoader.options.geojson, ...options.geojson};\n\n const geojsonIterator = parseJSONInBatches(asyncIterator, options);\n\n switch (options.gis.format) {\n case 'binary':\n return makeBinaryGeometryIterator(geojsonIterator);\n default:\n return geojsonIterator as AsyncIterable<TableBatch>;\n }\n}\n\nasync function* makeBinaryGeometryIterator(geojsonIterator) {\n for await (const batch of geojsonIterator) {\n batch.data = geojsonToBinary(batch.data);\n yield batch;\n }\n}\n"],"mappings":"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"}
|
package/dist/geojson-worker.js
CHANGED
|
@@ -275,6 +275,7 @@
|
|
|
275
275
|
if (Number.isFinite(cursor)) {
|
|
276
276
|
this.cursor = cursor;
|
|
277
277
|
}
|
|
278
|
+
this.shape = "array-row-table";
|
|
278
279
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
279
280
|
this.rows[this.length] = row;
|
|
280
281
|
this.length++;
|
|
@@ -283,6 +284,7 @@
|
|
|
283
284
|
if (Number.isFinite(cursor)) {
|
|
284
285
|
this.cursor = cursor;
|
|
285
286
|
}
|
|
287
|
+
this.shape = "object-row-table";
|
|
286
288
|
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
287
289
|
this.rows[this.length] = row;
|
|
288
290
|
this.length++;
|
|
@@ -295,7 +297,7 @@
|
|
|
295
297
|
rows = rows.slice(0, this.length);
|
|
296
298
|
this.rows = null;
|
|
297
299
|
const batch = {
|
|
298
|
-
shape: this.
|
|
300
|
+
shape: this.shape || "array-row-table",
|
|
299
301
|
batchType: "data",
|
|
300
302
|
data: rows,
|
|
301
303
|
length: this.length,
|
|
@@ -311,12 +313,16 @@
|
|
|
311
313
|
if (!arrayRow) {
|
|
312
314
|
throw new Error("null row");
|
|
313
315
|
}
|
|
314
|
-
if (!headers) {
|
|
315
|
-
throw new Error("no headers");
|
|
316
|
-
}
|
|
317
316
|
const objectRow = {};
|
|
318
|
-
|
|
319
|
-
|
|
317
|
+
if (headers) {
|
|
318
|
+
for (let i = 0; i < headers.length; i++) {
|
|
319
|
+
objectRow[headers[i]] = arrayRow[i];
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
323
|
+
const columnName = `column-${i}`;
|
|
324
|
+
objectRow[columnName] = arrayRow[i];
|
|
325
|
+
}
|
|
320
326
|
}
|
|
321
327
|
return objectRow;
|
|
322
328
|
}
|
|
@@ -324,14 +330,25 @@
|
|
|
324
330
|
if (!objectRow) {
|
|
325
331
|
throw new Error("null row");
|
|
326
332
|
}
|
|
327
|
-
if (
|
|
328
|
-
|
|
333
|
+
if (headers) {
|
|
334
|
+
const arrayRow = new Array(headers.length);
|
|
335
|
+
for (let i = 0; i < headers.length; i++) {
|
|
336
|
+
arrayRow[i] = objectRow[headers[i]];
|
|
337
|
+
}
|
|
338
|
+
return arrayRow;
|
|
329
339
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
340
|
+
return Object.values(objectRow);
|
|
341
|
+
}
|
|
342
|
+
function inferHeadersFromArrayRow(arrayRow) {
|
|
343
|
+
const headers = [];
|
|
344
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
345
|
+
const columnName = `column-${i}`;
|
|
346
|
+
headers.push(columnName);
|
|
333
347
|
}
|
|
334
|
-
return
|
|
348
|
+
return headers;
|
|
349
|
+
}
|
|
350
|
+
function inferHeadersFromObjectRow(row) {
|
|
351
|
+
return Object.keys(row);
|
|
335
352
|
}
|
|
336
353
|
|
|
337
354
|
// ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
|
|
@@ -342,10 +359,10 @@
|
|
|
342
359
|
this.objectRows = null;
|
|
343
360
|
this.arrayRows = null;
|
|
344
361
|
this.cursor = 0;
|
|
345
|
-
this._headers =
|
|
362
|
+
this._headers = null;
|
|
346
363
|
this.options = options;
|
|
347
364
|
this.schema = schema;
|
|
348
|
-
if (
|
|
365
|
+
if (schema) {
|
|
349
366
|
this._headers = [];
|
|
350
367
|
for (const key in schema) {
|
|
351
368
|
this._headers[schema[key].index] = schema[key].name;
|
|
@@ -359,6 +376,7 @@
|
|
|
359
376
|
if (Number.isFinite(cursor)) {
|
|
360
377
|
this.cursor = cursor;
|
|
361
378
|
}
|
|
379
|
+
this._headers || (this._headers = inferHeadersFromArrayRow(row));
|
|
362
380
|
switch (this.options.shape) {
|
|
363
381
|
case "object-row-table":
|
|
364
382
|
const rowObject = convertToObjectRow(row, this._headers);
|
|
@@ -375,6 +393,7 @@
|
|
|
375
393
|
if (Number.isFinite(cursor)) {
|
|
376
394
|
this.cursor = cursor;
|
|
377
395
|
}
|
|
396
|
+
this._headers || (this._headers = inferHeadersFromObjectRow(row));
|
|
378
397
|
switch (this.options.shape) {
|
|
379
398
|
case "array-row-table":
|
|
380
399
|
const rowArray = convertToArrayRow(row, this._headers);
|
|
@@ -400,6 +419,7 @@
|
|
|
400
419
|
batchType: "data",
|
|
401
420
|
data: rows,
|
|
402
421
|
length: this.length,
|
|
422
|
+
// @ts-expect-error we should infer a schema
|
|
403
423
|
schema: this.schema,
|
|
404
424
|
cursor: this.cursor
|
|
405
425
|
};
|
|
@@ -485,7 +505,7 @@
|
|
|
485
505
|
|
|
486
506
|
// ../schema/src/lib/table/batches/table-batch-builder.ts
|
|
487
507
|
var DEFAULT_OPTIONS = {
|
|
488
|
-
shape:
|
|
508
|
+
shape: void 0,
|
|
489
509
|
batchSize: "auto",
|
|
490
510
|
batchDebounceMs: 0,
|
|
491
511
|
limit: 0,
|
|
@@ -602,8 +622,6 @@
|
|
|
602
622
|
}
|
|
603
623
|
_getTableBatchType() {
|
|
604
624
|
switch (this.options.shape) {
|
|
605
|
-
case "row-table":
|
|
606
|
-
return BaseTableBatchAggregator;
|
|
607
625
|
case "array-row-table":
|
|
608
626
|
case "object-row-table":
|
|
609
627
|
return RowTableBatchAggregator;
|
|
@@ -615,7 +633,7 @@
|
|
|
615
633
|
}
|
|
616
634
|
return TableBatchBuilder.ArrowBatch;
|
|
617
635
|
default:
|
|
618
|
-
|
|
636
|
+
return BaseTableBatchAggregator;
|
|
619
637
|
}
|
|
620
638
|
}
|
|
621
639
|
};
|
|
@@ -2356,11 +2374,7 @@ Char: ${this.c}`;
|
|
|
2356
2374
|
const { jsonpaths } = options.json || {};
|
|
2357
2375
|
let isFirstChunk = true;
|
|
2358
2376
|
const schema = null;
|
|
2359
|
-
const
|
|
2360
|
-
const tableBatchBuilder = new TableBatchBuilder(schema, {
|
|
2361
|
-
...options,
|
|
2362
|
-
shape
|
|
2363
|
-
});
|
|
2377
|
+
const tableBatchBuilder = new TableBatchBuilder(schema, options);
|
|
2364
2378
|
const parser = new StreamingJSONParser({ jsonpaths });
|
|
2365
2379
|
for await (const chunk of asyncIterator) {
|
|
2366
2380
|
const rows = parser.write(chunk);
|
|
@@ -2369,7 +2383,7 @@ Char: ${this.c}`;
|
|
|
2369
2383
|
if (metadata) {
|
|
2370
2384
|
const initialBatch = {
|
|
2371
2385
|
// Common fields
|
|
2372
|
-
shape,
|
|
2386
|
+
shape: options?.json?.shape || "array-row-table",
|
|
2373
2387
|
batchType: "partial-result",
|
|
2374
2388
|
data: [],
|
|
2375
2389
|
length: 0,
|
|
@@ -2402,10 +2416,11 @@ Char: ${this.c}`;
|
|
|
2402
2416
|
}
|
|
2403
2417
|
if (metadata) {
|
|
2404
2418
|
const finalBatch = {
|
|
2405
|
-
shape,
|
|
2419
|
+
shape: "json",
|
|
2406
2420
|
batchType: "final-result",
|
|
2407
2421
|
container: parser.getPartialResult(),
|
|
2408
2422
|
jsonpath: parser.getStreamingJsonPathAsString(),
|
|
2423
|
+
/** Data Just to avoid crashing? */
|
|
2409
2424
|
data: [],
|
|
2410
2425
|
length: 0
|
|
2411
2426
|
// schema: null
|
|
@@ -2415,7 +2430,7 @@ Char: ${this.c}`;
|
|
|
2415
2430
|
}
|
|
2416
2431
|
|
|
2417
2432
|
// src/geojson-loader.ts
|
|
2418
|
-
var VERSION = true ? "4.1.0-alpha.
|
|
2433
|
+
var VERSION = true ? "4.1.0-alpha.10" : "latest";
|
|
2419
2434
|
var GeoJSONWorkerLoader = {
|
|
2420
2435
|
name: "GeoJSON",
|
|
2421
2436
|
id: "geojson",
|
package/dist/geojson-writer.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type WriterWithEncoder, type WriterOptions } from '@loaders.gl/loader-utils';
|
|
2
2
|
import type { Table, TableBatch } from '@loaders.gl/schema';
|
|
3
3
|
export type GeoJSONWriterOptions = WriterOptions & {
|
|
4
4
|
geojson?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-writer.d.ts","sourceRoot":"","sources":["../src/geojson-writer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geojson-writer.d.ts","sourceRoot":"","sources":["../src/geojson-writer.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAC,KAAK,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAG1D,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG;IACjD,OAAO,CAAC,EAAE;QACR,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAChC,CAAC;IACF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,iBAAiB,CAAC,KAAK,EAAE,UAAU,EAAE,oBAAoB,CAuBpF,CAAC"}
|
package/dist/geojson-writer.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { concatenateArrayBuffersAsync } from '@loaders.gl/loader-utils';
|
|
1
2
|
import { encodeTableAsGeojsonInBatches } from "./lib/encoders/geojson-encoder.js";
|
|
2
3
|
export const GeoJSONWriter = {
|
|
3
4
|
id: 'geojson',
|
|
@@ -6,13 +7,18 @@ export const GeoJSONWriter = {
|
|
|
6
7
|
name: 'GeoJSON',
|
|
7
8
|
extensions: ['geojson'],
|
|
8
9
|
mimeTypes: ['application/geo+json'],
|
|
10
|
+
text: true,
|
|
9
11
|
options: {
|
|
10
12
|
geojson: {
|
|
11
13
|
featureArray: false,
|
|
12
14
|
geometryColumn: null
|
|
13
15
|
}
|
|
14
16
|
},
|
|
15
|
-
|
|
17
|
+
async encode(table, options) {
|
|
18
|
+
const tableIterator = [table];
|
|
19
|
+
const batches = encodeTableAsGeojsonInBatches(tableIterator, options);
|
|
20
|
+
return await concatenateArrayBuffersAsync(batches);
|
|
21
|
+
},
|
|
16
22
|
encodeInBatches: (tableIterator, options) => encodeTableAsGeojsonInBatches(tableIterator, options)
|
|
17
23
|
};
|
|
18
24
|
//# sourceMappingURL=geojson-writer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geojson-writer.js","names":["encodeTableAsGeojsonInBatches","GeoJSONWriter","id","version","module","name","extensions","mimeTypes","options","geojson","featureArray","geometryColumn","
|
|
1
|
+
{"version":3,"file":"geojson-writer.js","names":["concatenateArrayBuffersAsync","encodeTableAsGeojsonInBatches","GeoJSONWriter","id","version","module","name","extensions","mimeTypes","text","options","geojson","featureArray","geometryColumn","encode","table","tableIterator","batches","encodeInBatches"],"sources":["../src/geojson-writer.ts"],"sourcesContent":["// loaders.gl\n// SPDX-License-Identifier: MIT\n// Copyright (c) vis.gl contributors\n// Copyright Foursquare, Inc 20222\n\nimport {\n type WriterWithEncoder,\n type WriterOptions,\n concatenateArrayBuffersAsync\n} from '@loaders.gl/loader-utils';\nimport type {Table, TableBatch} from '@loaders.gl/schema';\nimport {encodeTableAsGeojsonInBatches} from './lib/encoders/geojson-encoder';\n\nexport type GeoJSONWriterOptions = WriterOptions & {\n geojson?: {\n featureArray?: boolean;\n geometryColumn?: number | null;\n };\n chunkSize?: number;\n};\n\nexport const GeoJSONWriter: WriterWithEncoder<Table, TableBatch, GeoJSONWriterOptions> = {\n id: 'geojson',\n version: 'latest',\n module: 'geojson',\n name: 'GeoJSON',\n extensions: ['geojson'],\n mimeTypes: ['application/geo+json'],\n text: true,\n options: {\n geojson: {\n featureArray: false,\n geometryColumn: null\n }\n },\n\n async encode(table: Table, options: GeoJSONWriterOptions): Promise<ArrayBuffer> {\n const tableIterator = [table] as TableBatch[];\n const batches = encodeTableAsGeojsonInBatches(tableIterator, options);\n return await concatenateArrayBuffersAsync(batches);\n },\n\n encodeInBatches: (tableIterator: AsyncIterable<TableBatch> | Iterable<TableBatch>, options) =>\n encodeTableAsGeojsonInBatches(tableIterator, options)\n};\n"],"mappings":"AAKA,SAGEA,4BAA4B,QACvB,0BAA0B;AAAC,SAE1BC,6BAA6B;AAUrC,OAAO,MAAMC,aAAyE,GAAG;EACvFC,EAAE,EAAE,SAAS;EACbC,OAAO,EAAE,QAAQ;EACjBC,MAAM,EAAE,SAAS;EACjBC,IAAI,EAAE,SAAS;EACfC,UAAU,EAAE,CAAC,SAAS,CAAC;EACvBC,SAAS,EAAE,CAAC,sBAAsB,CAAC;EACnCC,IAAI,EAAE,IAAI;EACVC,OAAO,EAAE;IACPC,OAAO,EAAE;MACPC,YAAY,EAAE,KAAK;MACnBC,cAAc,EAAE;IAClB;EACF,CAAC;EAED,MAAMC,MAAMA,CAACC,KAAY,EAAEL,OAA6B,EAAwB;IAC9E,MAAMM,aAAa,GAAG,CAACD,KAAK,CAAiB;IAC7C,MAAME,OAAO,GAAGhB,6BAA6B,CAACe,aAAa,EAAEN,OAAO,CAAC;IACrE,OAAO,MAAMV,4BAA4B,CAACiB,OAAO,CAAC;EACpD,CAAC;EAEDC,eAAe,EAAEA,CAACF,aAA+D,EAAEN,OAAO,KACxFT,6BAA6B,CAACe,aAAa,EAAEN,OAAO;AACxD,CAAC"}
|