@loaders.gl/json 4.0.0-alpha.23 → 4.0.0-alpha.25

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.
Files changed (89) hide show
  1. package/dist/dist.min.js +87 -51
  2. package/dist/es5/geojson-loader.js +14 -5
  3. package/dist/es5/geojson-loader.js.map +1 -1
  4. package/dist/es5/geojson-writer.js.map +1 -1
  5. package/dist/es5/json-loader.js +1 -1
  6. package/dist/es5/json-writer.js +1 -1
  7. package/dist/es5/json-writer.js.map +1 -1
  8. package/dist/es5/lib/encoder-utils/encode-table-row.js +54 -0
  9. package/dist/es5/lib/encoder-utils/encode-table-row.js.map +1 -0
  10. package/dist/es5/lib/encoder-utils/encode-utils.js.map +1 -0
  11. package/dist/es5/lib/encoder-utils/utf8-encoder.js.map +1 -0
  12. package/dist/es5/lib/encoders/geojson-encoder.js +47 -84
  13. package/dist/es5/lib/encoders/geojson-encoder.js.map +1 -1
  14. package/dist/es5/lib/encoders/json-encoder.js +3 -3
  15. package/dist/es5/lib/encoders/json-encoder.js.map +1 -1
  16. package/dist/es5/ndgeoson-loader.js +1 -1
  17. package/dist/es5/ndjson-loader.js +1 -1
  18. package/dist/esm/geojson-loader.js +14 -5
  19. package/dist/esm/geojson-loader.js.map +1 -1
  20. package/dist/esm/geojson-writer.js.map +1 -1
  21. package/dist/esm/json-loader.js +1 -1
  22. package/dist/esm/json-writer.js +1 -1
  23. package/dist/esm/json-writer.js.map +1 -1
  24. package/dist/esm/lib/encoder-utils/encode-table-row.js +44 -0
  25. package/dist/esm/lib/encoder-utils/encode-table-row.js.map +1 -0
  26. package/dist/esm/lib/encoder-utils/encode-utils.js.map +1 -0
  27. package/dist/esm/lib/encoder-utils/utf8-encoder.js.map +1 -0
  28. package/dist/esm/lib/encoders/geojson-encoder.js +9 -52
  29. package/dist/esm/lib/encoders/geojson-encoder.js.map +1 -1
  30. package/dist/esm/lib/encoders/json-encoder.js +3 -3
  31. package/dist/esm/lib/encoders/json-encoder.js.map +1 -1
  32. package/dist/esm/ndgeoson-loader.js +1 -1
  33. package/dist/esm/ndjson-loader.js +1 -1
  34. package/dist/geojson-loader.d.ts.map +1 -1
  35. package/dist/geojson-worker.js +14 -183
  36. package/dist/geojson-writer.d.ts +8 -3
  37. package/dist/geojson-writer.d.ts.map +1 -1
  38. package/dist/json-writer.d.ts +13 -3
  39. package/dist/json-writer.d.ts.map +1 -1
  40. package/dist/lib/encoder-utils/encode-table-row.d.ts +7 -0
  41. package/dist/lib/encoder-utils/encode-table-row.d.ts.map +1 -0
  42. package/dist/lib/encoder-utils/encode-utils.d.ts.map +1 -0
  43. package/dist/lib/encoder-utils/utf8-encoder.d.ts.map +1 -0
  44. package/dist/lib/encoders/geojson-encoder.d.ts +2 -8
  45. package/dist/lib/encoders/geojson-encoder.d.ts.map +1 -1
  46. package/dist/lib/encoders/json-encoder.d.ts +1 -10
  47. package/dist/lib/encoders/json-encoder.d.ts.map +1 -1
  48. package/package.json +5 -5
  49. package/src/geojson-loader.ts +19 -5
  50. package/src/geojson-writer.ts +8 -3
  51. package/src/json-writer.ts +12 -4
  52. package/src/lib/encoder-utils/encode-table-row.ts +69 -0
  53. package/src/lib/encoders/geojson-encoder.ts +15 -78
  54. package/src/lib/encoders/json-encoder.ts +3 -11
  55. package/dist/bundle.js +0 -5
  56. package/dist/es5/lib/encoders/encode-utils.js.map +0 -1
  57. package/dist/es5/lib/encoders/utf8-encoder.js.map +0 -1
  58. package/dist/esm/lib/encoders/encode-utils.js.map +0 -1
  59. package/dist/esm/lib/encoders/utf8-encoder.js.map +0 -1
  60. package/dist/geojson-loader.js +0 -79
  61. package/dist/geojson-writer.js +0 -22
  62. package/dist/index.js +0 -24
  63. package/dist/json-loader.js +0 -42
  64. package/dist/json-writer.js +0 -18
  65. package/dist/lib/clarinet/clarinet.js +0 -535
  66. package/dist/lib/encoders/encode-utils.d.ts.map +0 -1
  67. package/dist/lib/encoders/encode-utils.js +0 -47
  68. package/dist/lib/encoders/geojson-encoder.js +0 -104
  69. package/dist/lib/encoders/json-encoder.js +0 -22
  70. package/dist/lib/encoders/utf8-encoder.d.ts.map +0 -1
  71. package/dist/lib/encoders/utf8-encoder.js +0 -32
  72. package/dist/lib/json-parser/json-parser.js +0 -98
  73. package/dist/lib/json-parser/streaming-json-parser.js +0 -100
  74. package/dist/lib/jsonpath/jsonpath.js +0 -89
  75. package/dist/lib/parsers/parse-json-in-batches.js +0 -101
  76. package/dist/lib/parsers/parse-json.js +0 -32
  77. package/dist/lib/parsers/parse-ndjson-in-batches.js +0 -36
  78. package/dist/lib/parsers/parse-ndjson.js +0 -17
  79. package/dist/ndgeoson-loader.js +0 -36
  80. package/dist/ndjson-loader.js +0 -27
  81. package/dist/workers/geojson-worker.js +0 -5
  82. /package/dist/es5/lib/{encoders → encoder-utils}/encode-utils.js +0 -0
  83. /package/dist/es5/lib/{encoders → encoder-utils}/utf8-encoder.js +0 -0
  84. /package/dist/esm/lib/{encoders → encoder-utils}/encode-utils.js +0 -0
  85. /package/dist/esm/lib/{encoders → encoder-utils}/utf8-encoder.js +0 -0
  86. /package/dist/lib/{encoders → encoder-utils}/encode-utils.d.ts +0 -0
  87. /package/dist/lib/{encoders → encoder-utils}/utf8-encoder.d.ts +0 -0
  88. /package/src/lib/{encoders → encoder-utils}/encode-utils.ts +0 -0
  89. /package/src/lib/{encoders → encoder-utils}/utf8-encoder.ts +0 -0
@@ -1,22 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- // Copyright 2022 Foursquare Labs, Inc.
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.encodeTableAsJSON = void 0;
6
- const schema_1 = require("@loaders.gl/schema");
7
- /**
8
- * Encode a table as a JSON string
9
- */
10
- function encodeTableAsJSON(table, options = {}) {
11
- const shape = options.shape || 'object-row-table';
12
- const strings = [];
13
- const rowIterator = (0, schema_1.makeRowIterator)(table, shape);
14
- for (const row of rowIterator) {
15
- // Round elements etc
16
- // processRow(wrappedRow, table.schema);
17
- // const wrappedRow = options.wrapper ? options.wrapper(row) : row;
18
- strings.push(JSON.stringify(row));
19
- }
20
- return `[${strings.join(',')}]`;
21
- }
22
- exports.encodeTableAsJSON = encodeTableAsJSON;
@@ -1 +0,0 @@
1
- {"version":3,"file":"utf8-encoder.d.ts","sourceRoot":"","sources":["../../../src/lib/encoders/utf8-encoder.ts"],"names":[],"mappings":"AAGA,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,WAAW,CAAkC;gBAEzC,SAAS,EAAE,MAAM;IAI7B,IAAI,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI;IAOhC,MAAM,IAAI,OAAO;IAIjB,mBAAmB,IAAI,eAAe;IAItC,cAAc,IAAI,MAAM;CAMzB"}
@@ -1,32 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT License
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.Utf8ArrayBufferEncoder = void 0;
5
- /* global TextEncoder */
6
- class Utf8ArrayBufferEncoder {
7
- constructor(chunkSize) {
8
- this.strings = [];
9
- this.totalLength = 0;
10
- this.textEncoder = new TextEncoder();
11
- this.chunkSize = chunkSize;
12
- }
13
- push(...strings) {
14
- for (const string of strings) {
15
- this.strings.push(string);
16
- this.totalLength += string.length;
17
- }
18
- }
19
- isFull() {
20
- return this.totalLength >= this.chunkSize;
21
- }
22
- getArrayBufferBatch() {
23
- return this.textEncoder.encode(this.getStringBatch()).buffer;
24
- }
25
- getStringBatch() {
26
- const stringChunk = this.strings.join('');
27
- this.strings = [];
28
- this.totalLength = 0;
29
- return stringChunk;
30
- }
31
- }
32
- exports.Utf8ArrayBufferEncoder = Utf8ArrayBufferEncoder;
@@ -1,98 +0,0 @@
1
- "use strict";
2
- // @ts-nocheck
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const clarinet_1 = __importDefault(require("../clarinet/clarinet"));
8
- const jsonpath_1 = __importDefault(require("../jsonpath/jsonpath"));
9
- // JSONParser builds a JSON object using the events emitted by the Clarinet parser
10
- class JSONParser {
11
- constructor(options) {
12
- this.result = undefined;
13
- this.previousStates = [];
14
- this.currentState = Object.freeze({ container: [], key: null });
15
- this.jsonpath = new jsonpath_1.default();
16
- this.reset();
17
- this.parser = new clarinet_1.default({
18
- onready: () => {
19
- this.jsonpath = new jsonpath_1.default();
20
- this.previousStates.length = 0;
21
- this.currentState.container.length = 0;
22
- },
23
- onopenobject: (name) => {
24
- this._openObject({});
25
- if (typeof name !== 'undefined') {
26
- this.parser.emit('onkey', name);
27
- }
28
- },
29
- onkey: (name) => {
30
- this.jsonpath.set(name);
31
- this.currentState.key = name;
32
- },
33
- oncloseobject: () => {
34
- this._closeObject();
35
- },
36
- onopenarray: () => {
37
- this._openArray();
38
- },
39
- onclosearray: () => {
40
- this._closeArray();
41
- },
42
- onvalue: (value) => {
43
- this._pushOrSet(value);
44
- },
45
- onerror: (error) => {
46
- throw error;
47
- },
48
- onend: () => {
49
- this.result = this.currentState.container.pop();
50
- },
51
- ...options
52
- });
53
- }
54
- reset() {
55
- this.result = undefined;
56
- this.previousStates = [];
57
- this.currentState = Object.freeze({ container: [], key: null });
58
- this.jsonpath = new jsonpath_1.default();
59
- }
60
- write(chunk) {
61
- this.parser.write(chunk);
62
- }
63
- close() {
64
- this.parser.close();
65
- }
66
- // PRIVATE METHODS
67
- _pushOrSet(value) {
68
- const { container, key } = this.currentState;
69
- if (key !== null) {
70
- container[key] = value;
71
- this.currentState.key = null;
72
- }
73
- else {
74
- container.push(value);
75
- }
76
- }
77
- _openArray(newContainer = []) {
78
- this.jsonpath.push(null);
79
- this._pushOrSet(newContainer);
80
- this.previousStates.push(this.currentState);
81
- this.currentState = { container: newContainer, isArray: true, key: null };
82
- }
83
- _closeArray() {
84
- this.jsonpath.pop();
85
- this.currentState = this.previousStates.pop();
86
- }
87
- _openObject(newContainer = {}) {
88
- this.jsonpath.push(null);
89
- this._pushOrSet(newContainer);
90
- this.previousStates.push(this.currentState);
91
- this.currentState = { container: newContainer, isArray: false, key: null };
92
- }
93
- _closeObject() {
94
- this.jsonpath.pop();
95
- this.currentState = this.previousStates.pop();
96
- }
97
- }
98
- exports.default = JSONParser;
@@ -1,100 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const json_parser_1 = __importDefault(require("./json-parser"));
7
- const jsonpath_1 = __importDefault(require("../jsonpath/jsonpath"));
8
- /**
9
- * The `StreamingJSONParser` looks for the first array in the JSON structure.
10
- * and emits an array of chunks
11
- */
12
- class StreamingJSONParser extends json_parser_1.default {
13
- constructor(options = {}) {
14
- super({
15
- onopenarray: () => {
16
- if (!this.streamingArray) {
17
- if (this._matchJSONPath()) {
18
- // @ts-ignore
19
- this.streamingJsonPath = this.getJsonPath().clone();
20
- this.streamingArray = [];
21
- this._openArray(this.streamingArray);
22
- return;
23
- }
24
- }
25
- this._openArray();
26
- },
27
- // Redefine onopenarray to inject value for top-level object
28
- onopenobject: (name) => {
29
- if (!this.topLevelObject) {
30
- this.topLevelObject = {};
31
- this._openObject(this.topLevelObject);
32
- }
33
- else {
34
- this._openObject({});
35
- }
36
- if (typeof name !== 'undefined') {
37
- this.parser.emit('onkey', name);
38
- }
39
- }
40
- });
41
- this.streamingJsonPath = null;
42
- this.streamingArray = null;
43
- this.topLevelObject = null;
44
- const jsonpaths = options.jsonpaths || [];
45
- this.jsonPaths = jsonpaths.map((jsonpath) => new jsonpath_1.default(jsonpath));
46
- }
47
- /**
48
- * write REDEFINITION
49
- * - super.write() chunk to parser
50
- * - get the contents (so far) of "topmost-level" array as batch of rows
51
- * - clear top-level array
52
- * - return the batch of rows\
53
- */
54
- write(chunk) {
55
- super.write(chunk);
56
- let array = [];
57
- if (this.streamingArray) {
58
- array = [...this.streamingArray];
59
- this.streamingArray.length = 0;
60
- }
61
- return array;
62
- }
63
- /**
64
- * Returns a partially formed result object
65
- * Useful for returning the "wrapper" object when array is not top level
66
- * e.g. GeoJSON
67
- */
68
- getPartialResult() {
69
- return this.topLevelObject;
70
- }
71
- getStreamingJsonPath() {
72
- return this.streamingJsonPath;
73
- }
74
- getStreamingJsonPathAsString() {
75
- return this.streamingJsonPath && this.streamingJsonPath.toString();
76
- }
77
- getJsonPath() {
78
- return this.jsonpath;
79
- }
80
- // PRIVATE METHODS
81
- /**
82
- * Checks is this.getJsonPath matches the jsonpaths provided in options
83
- */
84
- _matchJSONPath() {
85
- const currentPath = this.getJsonPath();
86
- // console.debug(`Testing JSONPath`, currentPath);
87
- // Backwards compatibility, match any array
88
- // TODO implement using wildcard once that is supported
89
- if (this.jsonPaths.length === 0) {
90
- return true;
91
- }
92
- for (const jsonPath of this.jsonPaths) {
93
- if (jsonPath.equals(currentPath)) {
94
- return true;
95
- }
96
- }
97
- return false;
98
- }
99
- }
100
- exports.default = StreamingJSONParser;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * A parser for a minimal subset of the jsonpath standard
5
- * Full JSON path parsers for JS exist but are quite large (bundle size)
6
- *
7
- * Supports
8
- *
9
- * `$.component.component.component`
10
- */
11
- class JSONPath {
12
- constructor(path = null) {
13
- this.path = ['$'];
14
- if (path instanceof JSONPath) {
15
- // @ts-ignore
16
- this.path = [...path.path];
17
- return;
18
- }
19
- if (Array.isArray(path)) {
20
- this.path.push(...path);
21
- return;
22
- }
23
- // Parse a string as a JSONPath
24
- if (typeof path === 'string') {
25
- this.path = path.split('.');
26
- if (this.path[0] !== '$') {
27
- throw new Error('JSONPaths must start with $');
28
- }
29
- }
30
- }
31
- clone() {
32
- return new JSONPath(this);
33
- }
34
- toString() {
35
- return this.path.join('.');
36
- }
37
- push(name) {
38
- this.path.push(name);
39
- }
40
- pop() {
41
- return this.path.pop();
42
- }
43
- set(name) {
44
- this.path[this.path.length - 1] = name;
45
- }
46
- equals(other) {
47
- if (!this || !other || this.path.length !== other.path.length) {
48
- return false;
49
- }
50
- for (let i = 0; i < this.path.length; ++i) {
51
- if (this.path[i] !== other.path[i]) {
52
- return false;
53
- }
54
- }
55
- return true;
56
- }
57
- /**
58
- * Sets the value pointed at by path
59
- * TODO - handle root path
60
- * @param object
61
- * @param value
62
- */
63
- setFieldAtPath(object, value) {
64
- const path = [...this.path];
65
- path.shift();
66
- const field = path.pop();
67
- for (const component of path) {
68
- object = object[component];
69
- }
70
- // @ts-ignore
71
- object[field] = value;
72
- }
73
- /**
74
- * Gets the value pointed at by path
75
- * TODO - handle root path
76
- * @param object
77
- */
78
- getFieldAtPath(object) {
79
- const path = [...this.path];
80
- path.shift();
81
- const field = path.pop();
82
- for (const component of path) {
83
- object = object[component];
84
- }
85
- // @ts-ignore
86
- return object[field];
87
- }
88
- }
89
- exports.default = JSONPath;
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.rebuildJsonObject = exports.parseJSONInBatches = void 0;
7
- const schema_1 = require("@loaders.gl/schema");
8
- const loader_utils_1 = require("@loaders.gl/loader-utils");
9
- const streaming_json_parser_1 = __importDefault(require("../json-parser/streaming-json-parser"));
10
- const jsonpath_1 = __importDefault(require("../jsonpath/jsonpath"));
11
- // TODO - support batch size 0 = no batching/single batch?
12
- // eslint-disable-next-line max-statements, complexity
13
- async function* parseJSONInBatches(binaryAsyncIterator, options) {
14
- const asyncIterator = (0, loader_utils_1.makeTextDecoderIterator)(binaryAsyncIterator);
15
- const { metadata } = options;
16
- const { jsonpaths } = options.json || {};
17
- let isFirstChunk = true;
18
- // TODO fix Schema deduction
19
- const schema = null; // new Schema([]);
20
- // TODO - detect shape from data?
21
- const shape = options?.json?.shape || 'object-row-table';
22
- // @ts-ignore
23
- const tableBatchBuilder = new schema_1.TableBatchBuilder(schema, {
24
- ...options,
25
- shape
26
- });
27
- const parser = new streaming_json_parser_1.default({ jsonpaths });
28
- for await (const chunk of asyncIterator) {
29
- const rows = parser.write(chunk);
30
- const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
31
- if (rows.length > 0 && isFirstChunk) {
32
- if (metadata) {
33
- const initialBatch = {
34
- // Common fields
35
- shape,
36
- batchType: 'partial-result',
37
- data: [],
38
- length: 0,
39
- bytesUsed: 0,
40
- // JSON additions
41
- container: parser.getPartialResult(),
42
- jsonpath
43
- };
44
- yield initialBatch;
45
- }
46
- isFirstChunk = false;
47
- // schema = deduceSchema(rows);
48
- }
49
- // Add the row
50
- for (const row of rows) {
51
- tableBatchBuilder.addRow(row);
52
- // If a batch has been completed, emit it
53
- const batch = tableBatchBuilder.getFullBatch({ jsonpath });
54
- if (batch) {
55
- yield batch;
56
- }
57
- }
58
- tableBatchBuilder.chunkComplete(chunk);
59
- const batch = tableBatchBuilder.getFullBatch({ jsonpath });
60
- if (batch) {
61
- yield batch;
62
- }
63
- }
64
- // yield final batch
65
- const jsonpath = parser.getStreamingJsonPathAsString();
66
- const batch = tableBatchBuilder.getFinalBatch({ jsonpath });
67
- if (batch) {
68
- yield batch;
69
- }
70
- if (metadata) {
71
- const finalBatch = {
72
- shape,
73
- batchType: 'final-result',
74
- container: parser.getPartialResult(),
75
- jsonpath: parser.getStreamingJsonPathAsString(),
76
- data: [],
77
- length: 0
78
- // schema: null
79
- };
80
- yield finalBatch;
81
- }
82
- }
83
- exports.parseJSONInBatches = parseJSONInBatches;
84
- function rebuildJsonObject(batch, data) {
85
- // Last batch will have this special type and will provide all the root object of the parsed file
86
- (0, loader_utils_1.assert)(batch.batchType === 'final-result');
87
- // The streamed JSON data is a top level array (jsonpath = '$'), just return the array of row objects
88
- if (batch.jsonpath === '$') {
89
- return data;
90
- }
91
- // (jsonpath !== '$') The streamed data is not a top level array, so stitch it back in to the top-level object
92
- if (batch.jsonpath && batch.jsonpath.length > 1) {
93
- const topLevelObject = batch.container;
94
- const streamingPath = new jsonpath_1.default(batch.jsonpath);
95
- streamingPath.setFieldAtPath(topLevelObject, data);
96
- return topLevelObject;
97
- }
98
- // No jsonpath, in this case nothing was streamed.
99
- return batch.container;
100
- }
101
- exports.rebuildJsonObject = rebuildJsonObject;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseJSONSync = void 0;
4
- const schema_1 = require("@loaders.gl/schema");
5
- function parseJSONSync(jsonText, options) {
6
- try {
7
- const json = JSON.parse(jsonText);
8
- if (options.json?.table) {
9
- const data = getFirstArray(json) || json;
10
- return (0, schema_1.makeTableFromData)(data);
11
- }
12
- return json;
13
- }
14
- catch (error) {
15
- throw new Error('JSONLoader: failed to parse JSON');
16
- }
17
- }
18
- exports.parseJSONSync = parseJSONSync;
19
- function getFirstArray(json) {
20
- if (Array.isArray(json)) {
21
- return json;
22
- }
23
- if (json && typeof json === 'object') {
24
- for (const value of Object.values(json)) {
25
- const array = getFirstArray(value);
26
- if (array) {
27
- return array;
28
- }
29
- }
30
- }
31
- return null;
32
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseNDJSONInBatches = void 0;
4
- const schema_1 = require("@loaders.gl/schema");
5
- const loader_utils_1 = require("@loaders.gl/loader-utils");
6
- async function* parseNDJSONInBatches(binaryAsyncIterator, options) {
7
- const textIterator = (0, loader_utils_1.makeTextDecoderIterator)(binaryAsyncIterator);
8
- const lineIterator = (0, loader_utils_1.makeLineIterator)(textIterator);
9
- const numberedLineIterator = (0, loader_utils_1.makeNumberedLineIterator)(lineIterator);
10
- const schema = null;
11
- const shape = 'row-table';
12
- // @ts-ignore
13
- const tableBatchBuilder = new schema_1.TableBatchBuilder(schema, {
14
- ...options,
15
- shape
16
- });
17
- for await (const { counter, line } of numberedLineIterator) {
18
- try {
19
- const row = JSON.parse(line);
20
- tableBatchBuilder.addRow(row);
21
- tableBatchBuilder.chunkComplete(line);
22
- const batch = tableBatchBuilder.getFullBatch();
23
- if (batch) {
24
- yield batch;
25
- }
26
- }
27
- catch (error) {
28
- throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);
29
- }
30
- }
31
- const batch = tableBatchBuilder.getFinalBatch();
32
- if (batch) {
33
- yield batch;
34
- }
35
- }
36
- exports.parseNDJSONInBatches = parseNDJSONInBatches;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseNDJSONSync = void 0;
4
- const schema_1 = require("@loaders.gl/schema");
5
- function parseNDJSONSync(ndjsonText) {
6
- const lines = ndjsonText.trim().split('\n');
7
- const parsedLines = lines.map((line, counter) => {
8
- try {
9
- return JSON.parse(line);
10
- }
11
- catch (error) {
12
- throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);
13
- }
14
- });
15
- return (0, schema_1.makeTableFromData)(parsedLines);
16
- }
17
- exports.parseNDJSONSync = parseNDJSONSync;
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NDJSONLoader = void 0;
4
- const parse_ndjson_1 = require("./lib/parsers/parse-ndjson");
5
- const parse_ndjson_in_batches_1 = require("./lib/parsers/parse-ndjson-in-batches");
6
- // __VERSION__ is injected by babel-plugin-version-inline
7
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
8
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
9
- /** NDGeoJSONLoader */
10
- exports.NDJSONLoader = {
11
- name: 'NDJSON',
12
- id: 'ndjson',
13
- module: 'json',
14
- version: VERSION,
15
- extensions: ['ndjson', 'ndgeojson'],
16
- mimeTypes: [
17
- 'application/geo+x-ndjson',
18
- 'application/geo+x-ldjson',
19
- 'application/jsonlines',
20
- 'application/geo+json-seq',
21
- 'application/x-ndjson'
22
- ],
23
- category: 'table',
24
- text: true,
25
- parse: async (arrayBuffer) => (0, parse_ndjson_1.parseNDJSONSync)(new TextDecoder().decode(arrayBuffer)),
26
- parseTextSync: parse_ndjson_1.parseNDJSONSync,
27
- parseInBatches: parse_ndjson_in_batches_1.parseNDJSONInBatches,
28
- options: {
29
- geojson: {
30
- shape: 'object-row-table'
31
- },
32
- gis: {
33
- format: 'geojson'
34
- }
35
- }
36
- };
@@ -1,27 +0,0 @@
1
- "use strict";
2
- // loaders.gl, MIT license
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.NDJSONLoader = void 0;
5
- const parse_ndjson_1 = require("./lib/parsers/parse-ndjson");
6
- const parse_ndjson_in_batches_1 = require("./lib/parsers/parse-ndjson-in-batches");
7
- // __VERSION__ is injected by babel-plugin-version-inline
8
- // @ts-ignore TS2304: Cannot find name '__VERSION__'.
9
- const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'latest';
10
- exports.NDJSONLoader = {
11
- name: 'NDJSON',
12
- id: 'ndjson',
13
- module: 'json',
14
- version: VERSION,
15
- extensions: ['ndjson', 'jsonl'],
16
- mimeTypes: [
17
- 'application/x-ndjson',
18
- 'application/jsonlines',
19
- 'application/json-seq'
20
- ],
21
- category: 'table',
22
- text: true,
23
- parse: async (arrayBuffer) => (0, parse_ndjson_1.parseNDJSONSync)(new TextDecoder().decode(arrayBuffer)),
24
- parseTextSync: parse_ndjson_1.parseNDJSONSync,
25
- parseInBatches: parse_ndjson_in_batches_1.parseNDJSONInBatches,
26
- options: {}
27
- };
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const loader_utils_1 = require("@loaders.gl/loader-utils");
4
- const geojson_loader_1 = require("../geojson-loader");
5
- (0, loader_utils_1.createLoaderWorker)(geojson_loader_1.GeoJSONLoader);