@loaders.gl/json 3.4.13 → 3.4.15

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 (33) hide show
  1. package/dist/es5/bundle.js +1 -1
  2. package/dist/es5/bundle.js.map +1 -1
  3. package/dist/es5/geojson-loader.js +34 -103
  4. package/dist/es5/geojson-loader.js.map +1 -1
  5. package/dist/es5/index.js +7 -7
  6. package/dist/es5/json-loader.js +22 -33
  7. package/dist/es5/json-loader.js.map +1 -1
  8. package/dist/es5/lib/clarinet/clarinet.js +295 -318
  9. package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
  10. package/dist/es5/lib/jsonpath/jsonpath.js +44 -88
  11. package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
  12. package/dist/es5/lib/parse-json-in-batches.js +74 -181
  13. package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
  14. package/dist/es5/lib/parse-json.js +4 -7
  15. package/dist/es5/lib/parse-json.js.map +1 -1
  16. package/dist/es5/lib/parse-ndjson-in-batches.js +29 -103
  17. package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -1
  18. package/dist/es5/lib/parse-ndjson.js +2 -2
  19. package/dist/es5/lib/parse-ndjson.js.map +1 -1
  20. package/dist/es5/lib/parser/json-parser.js +84 -106
  21. package/dist/es5/lib/parser/json-parser.js.map +1 -1
  22. package/dist/es5/lib/parser/streaming-json-parser.js +52 -95
  23. package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
  24. package/dist/es5/ndgeoson-loader.js +5 -23
  25. package/dist/es5/ndgeoson-loader.js.map +1 -1
  26. package/dist/es5/ndjson-loader.js +3 -21
  27. package/dist/es5/ndjson-loader.js.map +1 -1
  28. package/dist/esm/geojson-loader.js +1 -1
  29. package/dist/esm/json-loader.js +1 -1
  30. package/dist/esm/ndgeoson-loader.js +1 -1
  31. package/dist/esm/ndjson-loader.js +1 -1
  32. package/dist/geojson-worker.js +1 -1
  33. package/package.json +5 -5
@@ -6,189 +6,82 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = parseJSONInBatches;
8
8
  exports.rebuildJsonObject = rebuildJsonObject;
9
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
12
- var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
13
9
  var _schema = require("@loaders.gl/schema");
14
10
  var _loaderUtils = require("@loaders.gl/loader-utils");
15
11
  var _streamingJsonParser = _interopRequireDefault(require("./parser/streaming-json-parser"));
16
- var _jsonpath2 = _interopRequireDefault(require("./jsonpath/jsonpath"));
17
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
18
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
19
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
22
- function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
23
- function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function _return(value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function _throw(value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); }
24
- function parseJSONInBatches(_x, _x2) {
25
- return _parseJSONInBatches.apply(this, arguments);
26
- }
27
- function _parseJSONInBatches() {
28
- _parseJSONInBatches = (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee(binaryAsyncIterator, options) {
29
- var _options$json;
30
- var asyncIterator, metadata, _ref, jsonpaths, isFirstChunk, schema, shape, tableBatchBuilder, parser, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, chunk, rows, _jsonpath, initialBatch, _iterator2, _step2, row, _batch2, _batch, jsonpath, batch, finalBatch;
31
- return _regenerator.default.wrap(function _callee$(_context) {
32
- while (1) switch (_context.prev = _context.next) {
33
- case 0:
34
- asyncIterator = (0, _loaderUtils.makeTextDecoderIterator)(binaryAsyncIterator);
35
- metadata = options.metadata;
36
- _ref = options.json || {}, jsonpaths = _ref.jsonpaths;
37
- isFirstChunk = true;
38
- schema = null;
39
- shape = (options === null || options === void 0 ? void 0 : (_options$json = options.json) === null || _options$json === void 0 ? void 0 : _options$json.shape) || 'row-table';
40
- tableBatchBuilder = new _schema.TableBatchBuilder(schema, _objectSpread(_objectSpread({}, options), {}, {
41
- shape: shape
42
- }));
43
- parser = new _streamingJsonParser.default({
44
- jsonpaths: jsonpaths
45
- });
46
- _iteratorAbruptCompletion = false;
47
- _didIteratorError = false;
48
- _context.prev = 10;
49
- _iterator = _asyncIterator(asyncIterator);
50
- case 12:
51
- _context.next = 14;
52
- return (0, _awaitAsyncGenerator2.default)(_iterator.next());
53
- case 14:
54
- if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
55
- _context.next = 52;
56
- break;
57
- }
58
- chunk = _step.value;
59
- rows = parser.write(chunk);
60
- _jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
61
- if (!(rows.length > 0 && isFirstChunk)) {
62
- _context.next = 24;
63
- break;
64
- }
65
- if (!metadata) {
66
- _context.next = 23;
67
- break;
68
- }
69
- initialBatch = {
70
- shape: shape,
71
- batchType: 'partial-result',
72
- data: [],
73
- length: 0,
74
- bytesUsed: 0,
75
- container: parser.getPartialResult(),
76
- jsonpath: _jsonpath
77
- };
78
- _context.next = 23;
79
- return initialBatch;
80
- case 23:
81
- isFirstChunk = false;
82
- case 24:
83
- _iterator2 = _createForOfIteratorHelper(rows);
84
- _context.prev = 25;
85
- _iterator2.s();
86
- case 27:
87
- if ((_step2 = _iterator2.n()).done) {
88
- _context.next = 36;
89
- break;
90
- }
91
- row = _step2.value;
92
- tableBatchBuilder.addRow(row);
93
- _batch2 = tableBatchBuilder.getFullBatch({
94
- jsonpath: _jsonpath
95
- });
96
- if (!_batch2) {
97
- _context.next = 34;
98
- break;
99
- }
100
- _context.next = 34;
101
- return _batch2;
102
- case 34:
103
- _context.next = 27;
104
- break;
105
- case 36:
106
- _context.next = 41;
107
- break;
108
- case 38:
109
- _context.prev = 38;
110
- _context.t0 = _context["catch"](25);
111
- _iterator2.e(_context.t0);
112
- case 41:
113
- _context.prev = 41;
114
- _iterator2.f();
115
- return _context.finish(41);
116
- case 44:
117
- tableBatchBuilder.chunkComplete(chunk);
118
- _batch = tableBatchBuilder.getFullBatch({
119
- jsonpath: _jsonpath
120
- });
121
- if (!_batch) {
122
- _context.next = 49;
123
- break;
124
- }
125
- _context.next = 49;
126
- return _batch;
127
- case 49:
128
- _iteratorAbruptCompletion = false;
129
- _context.next = 12;
130
- break;
131
- case 52:
132
- _context.next = 58;
133
- break;
134
- case 54:
135
- _context.prev = 54;
136
- _context.t1 = _context["catch"](10);
137
- _didIteratorError = true;
138
- _iteratorError = _context.t1;
139
- case 58:
140
- _context.prev = 58;
141
- _context.prev = 59;
142
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
143
- _context.next = 63;
144
- break;
145
- }
146
- _context.next = 63;
147
- return (0, _awaitAsyncGenerator2.default)(_iterator.return());
148
- case 63:
149
- _context.prev = 63;
150
- if (!_didIteratorError) {
151
- _context.next = 66;
152
- break;
153
- }
154
- throw _iteratorError;
155
- case 66:
156
- return _context.finish(63);
157
- case 67:
158
- return _context.finish(58);
159
- case 68:
160
- jsonpath = parser.getStreamingJsonPathAsString();
161
- batch = tableBatchBuilder.getFinalBatch({
162
- jsonpath: jsonpath
163
- });
164
- if (!batch) {
165
- _context.next = 73;
166
- break;
167
- }
168
- _context.next = 73;
169
- return batch;
170
- case 73:
171
- if (!metadata) {
172
- _context.next = 77;
173
- break;
174
- }
175
- finalBatch = {
176
- shape: shape,
177
- batchType: 'final-result',
178
- container: parser.getPartialResult(),
179
- jsonpath: parser.getStreamingJsonPathAsString(),
180
- data: [],
181
- length: 0
182
- };
183
- _context.next = 77;
184
- return finalBatch;
185
- case 77:
186
- case "end":
187
- return _context.stop();
12
+ var _jsonpath = _interopRequireDefault(require("./jsonpath/jsonpath"));
13
+ async function* parseJSONInBatches(binaryAsyncIterator, options) {
14
+ var _options$json;
15
+ const asyncIterator = (0, _loaderUtils.makeTextDecoderIterator)(binaryAsyncIterator);
16
+ const {
17
+ metadata
18
+ } = options;
19
+ const {
20
+ jsonpaths
21
+ } = options.json || {};
22
+ let isFirstChunk = true;
23
+ const schema = null;
24
+ const shape = (options === null || options === void 0 ? void 0 : (_options$json = options.json) === null || _options$json === void 0 ? void 0 : _options$json.shape) || 'row-table';
25
+ const tableBatchBuilder = new _schema.TableBatchBuilder(schema, {
26
+ ...options,
27
+ shape
28
+ });
29
+ const parser = new _streamingJsonParser.default({
30
+ jsonpaths
31
+ });
32
+ for await (const chunk of asyncIterator) {
33
+ const rows = parser.write(chunk);
34
+ const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();
35
+ if (rows.length > 0 && isFirstChunk) {
36
+ if (metadata) {
37
+ const initialBatch = {
38
+ shape,
39
+ batchType: 'partial-result',
40
+ data: [],
41
+ length: 0,
42
+ bytesUsed: 0,
43
+ container: parser.getPartialResult(),
44
+ jsonpath
45
+ };
46
+ yield initialBatch;
47
+ }
48
+ isFirstChunk = false;
49
+ }
50
+ for (const row of rows) {
51
+ tableBatchBuilder.addRow(row);
52
+ const batch = tableBatchBuilder.getFullBatch({
53
+ jsonpath
54
+ });
55
+ if (batch) {
56
+ yield batch;
188
57
  }
189
- }, _callee, null, [[10, 54, 58, 68], [25, 38, 41, 44], [59,, 63, 67]]);
190
- }));
191
- return _parseJSONInBatches.apply(this, arguments);
58
+ }
59
+ tableBatchBuilder.chunkComplete(chunk);
60
+ const batch = tableBatchBuilder.getFullBatch({
61
+ jsonpath
62
+ });
63
+ if (batch) {
64
+ yield batch;
65
+ }
66
+ }
67
+ const jsonpath = parser.getStreamingJsonPathAsString();
68
+ const batch = tableBatchBuilder.getFinalBatch({
69
+ jsonpath
70
+ });
71
+ if (batch) {
72
+ yield batch;
73
+ }
74
+ if (metadata) {
75
+ const finalBatch = {
76
+ shape,
77
+ batchType: 'final-result',
78
+ container: parser.getPartialResult(),
79
+ jsonpath: parser.getStreamingJsonPathAsString(),
80
+ data: [],
81
+ length: 0
82
+ };
83
+ yield finalBatch;
84
+ }
192
85
  }
193
86
  function rebuildJsonObject(batch, data) {
194
87
  (0, _loaderUtils.assert)(batch.batchType === 'final-result');
@@ -196,8 +89,8 @@ function rebuildJsonObject(batch, data) {
196
89
  return data;
197
90
  }
198
91
  if (batch.jsonpath && batch.jsonpath.length > 1) {
199
- var topLevelObject = batch.container;
200
- var streamingPath = new _jsonpath2.default(batch.jsonpath);
92
+ const topLevelObject = batch.container;
93
+ const streamingPath = new _jsonpath.default(batch.jsonpath);
201
94
  streamingPath.setFieldAtPath(topLevelObject, data);
202
95
  return topLevelObject;
203
96
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parse-json-in-batches.js","names":["_schema","require","_loaderUtils","_streamingJsonParser","_interopRequireDefault","_jsonpath2","_createForOfIteratorHelper","o","allowArrayLike","it","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","i","F","s","n","done","value","e","_e","f","TypeError","normalCompletion","didErr","err","call","step","next","_e2","return","minLen","_arrayLikeToArray","Object","prototype","toString","slice","constructor","name","from","test","arr","len","arr2","ownKeys","object","enumerableOnly","keys","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","arguments","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_asyncIterator","iterable","method","async","sync","retry","asyncIterator","AsyncFromSyncIterator","AsyncFromSyncIteratorContinuation","r","Promise","reject","resolve","then","_return","ret","throw","_throw","thr","parseJSONInBatches","_x","_x2","_parseJSONInBatches","_wrapAsyncGenerator2","_regenerator","mark","_callee","binaryAsyncIterator","options","_options$json","metadata","_ref","jsonpaths","isFirstChunk","schema","shape","tableBatchBuilder","parser","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","chunk","rows","_jsonpath","initialBatch","_iterator2","_step2","row","_batch2","_batch","jsonpath","batch","finalBatch","wrap","_callee$","_context","prev","makeTextDecoderIterator","json","TableBatchBuilder","StreamingJSONParser","_awaitAsyncGenerator2","sent","write","getStreamingJsonPathAsString","batchType","data","bytesUsed","container","getPartialResult","addRow","getFullBatch","t0","finish","chunkComplete","t1","getFinalBatch","stop","rebuildJsonObject","assert","topLevelObject","streamingPath","JSONPath","setFieldAtPath"],"sources":["../../../src/lib/parse-json-in-batches.ts"],"sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport type {JSONLoaderOptions} from '../json-loader';\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {assert, makeTextDecoderIterator} from '@loaders.gl/loader-utils';\nimport StreamingJSONParser from './parser/streaming-json-parser';\nimport JSONPath from './jsonpath/jsonpath';\n\n// TODO - support batch size 0 = no batching/single batch?\n// eslint-disable-next-line max-statements, complexity\nexport default async function* parseJSONInBatches(\n binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options: JSONLoaderOptions\n): AsyncIterable<Batch> {\n const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);\n\n const {metadata} = options;\n const {jsonpaths} = options.json || {};\n\n let isFirstChunk: boolean = true;\n\n // TODO fix Schema deduction\n const schema = null; // new Schema([]);\n const shape = options?.json?.shape || 'row-table';\n // @ts-ignore\n const tableBatchBuilder = new TableBatchBuilder(schema, {\n ...options,\n shape\n });\n\n const parser = new StreamingJSONParser({jsonpaths});\n\n for await (const chunk of asyncIterator) {\n const rows = parser.write(chunk);\n\n const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();\n\n if (rows.length > 0 && isFirstChunk) {\n if (metadata) {\n const initialBatch: Batch = {\n // Common fields\n shape,\n batchType: 'partial-result',\n data: [],\n length: 0,\n bytesUsed: 0,\n // JSON additions\n container: parser.getPartialResult(),\n jsonpath\n };\n yield initialBatch;\n }\n isFirstChunk = false;\n // schema = deduceSchema(rows);\n }\n\n // Add the row\n for (const row of rows) {\n tableBatchBuilder.addRow(row);\n // If a batch has been completed, emit it\n const batch = tableBatchBuilder.getFullBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n }\n\n tableBatchBuilder.chunkComplete(chunk);\n const batch = tableBatchBuilder.getFullBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n }\n\n // yield final batch\n const jsonpath = parser.getStreamingJsonPathAsString();\n const batch = tableBatchBuilder.getFinalBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n\n if (metadata) {\n const finalBatch: Batch = {\n shape,\n batchType: 'final-result',\n container: parser.getPartialResult(),\n jsonpath: parser.getStreamingJsonPathAsString(),\n data: [],\n length: 0\n // schema: null\n };\n yield finalBatch;\n }\n}\n\nexport function rebuildJsonObject(batch, data) {\n // Last batch will have this special type and will provide all the root object of the parsed file\n assert(batch.batchType === 'final-result');\n\n // The streamed JSON data is a top level array (jsonpath = '$'), just return the array of row objects\n if (batch.jsonpath === '$') {\n return data;\n }\n\n // (jsonpath !== '$') The streamed data is not a top level array, so stitch it back in to the top-level object\n if (batch.jsonpath && batch.jsonpath.length > 1) {\n const topLevelObject = batch.container;\n const streamingPath = new JSONPath(batch.jsonpath);\n streamingPath.setFieldAtPath(topLevelObject, data);\n return topLevelObject;\n }\n\n // No jsonpath, in this case nothing was streamed.\n return batch.container;\n}\n"],"mappings":";;;;;;;;;;;;AAEA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,oBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,UAAA,GAAAD,sBAAA,CAAAH,OAAA;AAA2C,SAAAK,2BAAAC,CAAA,EAAAC,cAAA,QAAAC,EAAA,UAAAC,MAAA,oBAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,KAAAJ,CAAA,qBAAAE,EAAA,QAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,MAAAE,EAAA,GAAAK,2BAAA,CAAAP,CAAA,MAAAC,cAAA,IAAAD,CAAA,WAAAA,CAAA,CAAAQ,MAAA,qBAAAN,EAAA,EAAAF,CAAA,GAAAE,EAAA,MAAAO,CAAA,UAAAC,CAAA,YAAAA,EAAA,eAAAC,CAAA,EAAAD,CAAA,EAAAE,CAAA,WAAAA,EAAA,QAAAH,CAAA,IAAAT,CAAA,CAAAQ,MAAA,WAAAK,IAAA,mBAAAA,IAAA,SAAAC,KAAA,EAAAd,CAAA,CAAAS,CAAA,UAAAM,CAAA,WAAAA,EAAAC,EAAA,UAAAA,EAAA,KAAAC,CAAA,EAAAP,CAAA,gBAAAQ,SAAA,iJAAAC,gBAAA,SAAAC,MAAA,UAAAC,GAAA,WAAAV,CAAA,WAAAA,EAAA,IAAAT,EAAA,GAAAA,EAAA,CAAAoB,IAAA,CAAAtB,CAAA,MAAAY,CAAA,WAAAA,EAAA,QAAAW,IAAA,GAAArB,EAAA,CAAAsB,IAAA,IAAAL,gBAAA,GAAAI,IAAA,CAAAV,IAAA,SAAAU,IAAA,KAAAR,CAAA,WAAAA,EAAAU,GAAA,IAAAL,MAAA,SAAAC,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AC,EAAE;IAC/C,IAAMyI,cAAc,GAAG7B,KAAK,CAACiB,SAAS;IACtC,IAAMa,aAAa,GAAG,IAAIC,kBAAQ,CAAC/B,KAAK,CAACD,QAAQ,CAAC;IAClD+B,aAAa,CAACE,cAAc,CAACH,cAAc,EAAEd,IAAI,CAAC;IAClD,OAAOc,cAAc;EACvB;EAGA,OAAO7B,KAAK,CAACiB,SAAS;AACxB"}
1
+ {"version":3,"file":"parse-json-in-batches.js","names":["_schema","require","_loaderUtils","_streamingJsonParser","_interopRequireDefault","_jsonpath","parseJSONInBatches","binaryAsyncIterator","options","_options$json","asyncIterator","makeTextDecoderIterator","metadata","jsonpaths","json","isFirstChunk","schema","shape","tableBatchBuilder","TableBatchBuilder","parser","StreamingJSONParser","chunk","rows","write","jsonpath","length","getStreamingJsonPathAsString","initialBatch","batchType","data","bytesUsed","container","getPartialResult","row","addRow","batch","getFullBatch","chunkComplete","getFinalBatch","finalBatch","rebuildJsonObject","assert","topLevelObject","streamingPath","JSONPath","setFieldAtPath"],"sources":["../../../src/lib/parse-json-in-batches.ts"],"sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport type {JSONLoaderOptions} from '../json-loader';\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {assert, makeTextDecoderIterator} from '@loaders.gl/loader-utils';\nimport StreamingJSONParser from './parser/streaming-json-parser';\nimport JSONPath from './jsonpath/jsonpath';\n\n// TODO - support batch size 0 = no batching/single batch?\n// eslint-disable-next-line max-statements, complexity\nexport default async function* parseJSONInBatches(\n binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options: JSONLoaderOptions\n): AsyncIterable<Batch> {\n const asyncIterator = makeTextDecoderIterator(binaryAsyncIterator);\n\n const {metadata} = options;\n const {jsonpaths} = options.json || {};\n\n let isFirstChunk: boolean = true;\n\n // TODO fix Schema deduction\n const schema = null; // new Schema([]);\n const shape = options?.json?.shape || 'row-table';\n // @ts-ignore\n const tableBatchBuilder = new TableBatchBuilder(schema, {\n ...options,\n shape\n });\n\n const parser = new StreamingJSONParser({jsonpaths});\n\n for await (const chunk of asyncIterator) {\n const rows = parser.write(chunk);\n\n const jsonpath = rows.length > 0 && parser.getStreamingJsonPathAsString();\n\n if (rows.length > 0 && isFirstChunk) {\n if (metadata) {\n const initialBatch: Batch = {\n // Common fields\n shape,\n batchType: 'partial-result',\n data: [],\n length: 0,\n bytesUsed: 0,\n // JSON additions\n container: parser.getPartialResult(),\n jsonpath\n };\n yield initialBatch;\n }\n isFirstChunk = false;\n // schema = deduceSchema(rows);\n }\n\n // Add the row\n for (const row of rows) {\n tableBatchBuilder.addRow(row);\n // If a batch has been completed, emit it\n const batch = tableBatchBuilder.getFullBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n }\n\n tableBatchBuilder.chunkComplete(chunk);\n const batch = tableBatchBuilder.getFullBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n }\n\n // yield final batch\n const jsonpath = parser.getStreamingJsonPathAsString();\n const batch = tableBatchBuilder.getFinalBatch({jsonpath});\n if (batch) {\n yield batch;\n }\n\n if (metadata) {\n const finalBatch: Batch = {\n shape,\n batchType: 'final-result',\n container: parser.getPartialResult(),\n jsonpath: parser.getStreamingJsonPathAsString(),\n data: [],\n length: 0\n // schema: null\n };\n yield finalBatch;\n }\n}\n\nexport function rebuildJsonObject(batch, data) {\n // Last batch will have this special type and will provide all the root object of the parsed file\n assert(batch.batchType === 'final-result');\n\n // The streamed JSON data is a top level array (jsonpath = '$'), just return the array of row objects\n if (batch.jsonpath === '$') {\n return data;\n }\n\n // (jsonpath !== '$') The streamed data is not a top level array, so stitch it back in to the top-level object\n if (batch.jsonpath && batch.jsonpath.length > 1) {\n const topLevelObject = batch.container;\n const streamingPath = new JSONPath(batch.jsonpath);\n streamingPath.setFieldAtPath(topLevelObject, data);\n return topLevelObject;\n }\n\n // No jsonpath, in this case nothing was streamed.\n return batch.container;\n}\n"],"mappings":";;;;;;;;AAEA,IAAAA,OA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AK,CAACX,QAAQ,IAAIW,KAAK,CAACX,QAAQ,CAACC,MAAM,GAAG,CAAC,EAAE;IAC/C,MAAMiB,cAAc,GAAGP,KAAK,CAACJ,SAAS;IACtC,MAAMY,aAAa,GAAG,IAAIC,iBAAQ,CAACT,KAAK,CAACX,QAAQ,CAAC;IAClDmB,aAAa,CAACE,cAAc,CAACH,cAAc,EAAEb,IAAI,CAAC;IAClD,OAAOa,cAAc;EACvB;EAGA,OAAOP,KAAK,CAACJ,SAAS;AACxB"}
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = parseJSONSync;
8
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
7
  function parseJSONSync(jsonText, options) {
10
8
  try {
11
9
  var _options$json;
12
- var json = JSON.parse(jsonText);
10
+ const json = JSON.parse(jsonText);
13
11
  if ((_options$json = options.json) !== null && _options$json !== void 0 && _options$json.table) {
14
12
  return getFirstArray(json) || json;
15
13
  }
@@ -22,10 +20,9 @@ function getFirstArray(json) {
22
20
  if (Array.isArray(json)) {
23
21
  return json;
24
22
  }
25
- if (json && (0, _typeof2.default)(json) === 'object') {
26
- for (var _i = 0, _Object$values = Object.values(json); _i < _Object$values.length; _i++) {
27
- var value = _Object$values[_i];
28
- var array = getFirstArray(value);
23
+ if (json && typeof json === 'object') {
24
+ for (const value of Object.values(json)) {
25
+ const array = getFirstArray(value);
29
26
  if (array) {
30
27
  return array;
31
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"parse-json.js","names":["parseJSONSync","jsonText","options","_options$json","json","JSON","parse","table","getFirstArray","error","Error","Array","isArray","_typeof2","default","_i","_Object$values","Object","values","length","value","array"],"sources":["../../../src/lib/parse-json.ts"],"sourcesContent":["import type {JSONLoaderOptions} from '../json-loader';\n\nexport default function parseJSONSync(jsonText: string, options: JSONLoaderOptions) {\n try {\n const json = JSON.parse(jsonText);\n if (options.json?.table) {\n return getFirstArray(json) || json;\n }\n return json;\n } catch (error) {\n throw new Error('JSONLoader: failed to parse JSON');\n }\n}\n\nfunction getFirstArray(json) {\n if (Array.isArray(json)) {\n return json;\n }\n if (json && typeof json === 'object') {\n for (const value of Object.values(json)) {\n const array = getFirstArray(value);\n if (array) {\n return array;\n }\n }\n }\n return null;\n}\n"],"mappings":";;;;;;;;AAEe,SAASA,aAAaA,CAACC,QAAgB,EAAEC,OAA0B,EAAE;EAClF,IAAI;IAAA,IAAAC,aAAA;IACF,IAAMC,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACL,QAAQ,CAAC;IACjC,KAAAE,aAAA,GAAID,OAAO,CAACE,IAAI,cAAAD,aAAA,eAAZA,aAAA,CAAcI,KAAK,EAAE;MACvB,OAAOC,aAAa,CAACJ,IAAI,CAAC,IAAIA,IAAI;IACpC;IACA,OAAOA,IAAI;EACb,CAAC,CAAC,OAAOK,KAAK,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,kCAAkC,CAAC;EACrD;AACF;AAEA,SAASF,aAAaA,CAACJ,IAAI,EAAE;EAC3B,IAAIO,KAAK,CAACC,OAAO,CAACR,IAAI,CAAC,EAAE;IACvB,OAAOA,IAAI;EACb;EACA,IAAIA,IAAI,IAAI,IAAAS,QAAA,CAAAC,OAAA,EAAOV,IAAI,MAAK,QAAQ,EAAE;IACpC,SAAAW,EAAA,MAAAC,cAAA,GAAoBC,MAAM,CAACC,MAAM,CAACd,IAAI,CAAC,EAAAW,EAAA,GAAAC,cAAA,CAAAG,MAAA,EAAAJ,EAAA,IAAE;MAApC,IAAMK,KAAK,GAAAJ,cAAA,CAAAD,EAAA;MACd,IAAMM,KAAK,GAAGb,aAAa,CAACY,KAAK,CAAC;MAClC,IAAIC,KAAK,EAAE;QACT,OAAOA,KAAK;MACd;IACF;EACF;EACA,OAAO,IAAI;AACb"}
1
+ {"version":3,"file":"parse-json.js","names":["parseJSONSync","jsonText","options","_options$json","json","JSON","parse","table","getFirstArray","error","Error","Array","isArray","value","Object","values","array"],"sources":["../../../src/lib/parse-json.ts"],"sourcesContent":["import type {JSONLoaderOptions} from '../json-loader';\n\nexport default function parseJSONSync(jsonText: string, options: JSONLoaderOptions) {\n try {\n const json = JSON.parse(jsonText);\n if (options.json?.table) {\n return getFirstArray(json) || json;\n }\n return json;\n } catch (error) {\n throw new Error('JSONLoader: failed to parse JSON');\n }\n}\n\nfunction getFirstArray(json) {\n if (Array.isArray(json)) {\n return json;\n }\n if (json && typeof json === 'object') {\n for (const value of Object.values(json)) {\n const array = getFirstArray(value);\n if (array) {\n return array;\n }\n }\n }\n return null;\n}\n"],"mappings":";;;;;;AAEe,SAASA,aAAaA,CAACC,QAAgB,EAAEC,OAA0B,EAAE;EAClF,IAAI;IAAA,IAAAC,aAAA;IACF,MAAMC,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACL,QAAQ,CAAC;IACjC,KAAAE,aAAA,GAAID,OAAO,CAACE,IAAI,cAAAD,aAAA,eAAZA,aAAA,CAAcI,KAAK,EAAE;MACvB,OAAOC,aAAa,CAACJ,IAAI,CAAC,IAAIA,IAAI;IACpC;IACA,OAAOA,IAAI;EACb,CAAC,CAAC,OAAOK,KAAK,EAAE;IACd,MAAM,IAAIC,KAAK,CAAC,kCAAkC,CAAC;EACrD;AACF;AAEA,SAASF,aAAaA,CAACJ,IAAI,EAAE;EAC3B,IAAIO,KAAK,CAACC,OAAO,CAACR,IAAI,CAAC,EAAE;IACvB,OAAOA,IAAI;EACb;EACA,IAAIA,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,EAAE;IACpC,KAAK,MAAMS,KAAK,IAAIC,MAAM,CAACC,MAAM,CAACX,IAAI,CAAC,EAAE;MACvC,MAAMY,KAAK,GAAGR,aAAa,CAACK,KAAK,CAAC;MAClC,IAAIG,KAAK,EAAE;QACT,OAAOA,KAAK;MACd;IACF;EACF;EACA,OAAO,IAAI;AACb"}
@@ -1,114 +1,40 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  exports.default = parseNDJSONInBatches;
8
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
- var _awaitAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/awaitAsyncGenerator"));
11
- var _wrapAsyncGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapAsyncGenerator"));
12
7
  var _schema = require("@loaders.gl/schema");
13
8
  var _loaderUtils = require("@loaders.gl/loader-utils");
14
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
- function _asyncIterator(iterable) { var method, async, sync, retry = 2; for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) { if (async && null != (method = iterable[async])) return method.call(iterable); if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable)); async = "@@asyncIterator", sync = "@@iterator"; } throw new TypeError("Object is not async iterable"); }
17
- function AsyncFromSyncIterator(s) { function AsyncFromSyncIteratorContinuation(r) { if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object.")); var done = r.done; return Promise.resolve(r.value).then(function (value) { return { value: value, done: done }; }); } return AsyncFromSyncIterator = function AsyncFromSyncIterator(s) { this.s = s, this.n = s.next; }, AsyncFromSyncIterator.prototype = { s: null, n: null, next: function next() { return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments)); }, return: function _return(value) { var ret = this.s.return; return void 0 === ret ? Promise.resolve({ value: value, done: !0 }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments)); }, throw: function _throw(value) { var thr = this.s.return; return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments)); } }, new AsyncFromSyncIterator(s); }
18
- function parseNDJSONInBatches(_x, _x2) {
19
- return _parseNDJSONInBatches.apply(this, arguments);
20
- }
21
- function _parseNDJSONInBatches() {
22
- _parseNDJSONInBatches = (0, _wrapAsyncGenerator2.default)(_regenerator.default.mark(function _callee(binaryAsyncIterator, options) {
23
- var textIterator, lineIterator, numberedLineIterator, schema, shape, tableBatchBuilder, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step$value, counter, line, row, _batch, batch;
24
- return _regenerator.default.wrap(function _callee$(_context) {
25
- while (1) switch (_context.prev = _context.next) {
26
- case 0:
27
- textIterator = (0, _loaderUtils.makeTextDecoderIterator)(binaryAsyncIterator);
28
- lineIterator = (0, _loaderUtils.makeLineIterator)(textIterator);
29
- numberedLineIterator = (0, _loaderUtils.makeNumberedLineIterator)(lineIterator);
30
- schema = null;
31
- shape = 'row-table';
32
- tableBatchBuilder = new _schema.TableBatchBuilder(schema, _objectSpread(_objectSpread({}, options), {}, {
33
- shape: shape
34
- }));
35
- _iteratorAbruptCompletion = false;
36
- _didIteratorError = false;
37
- _context.prev = 8;
38
- _iterator = _asyncIterator(numberedLineIterator);
39
- case 10:
40
- _context.next = 12;
41
- return (0, _awaitAsyncGenerator2.default)(_iterator.next());
42
- case 12:
43
- if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
44
- _context.next = 30;
45
- break;
46
- }
47
- _step$value = _step.value, counter = _step$value.counter, line = _step$value.line;
48
- _context.prev = 14;
49
- row = JSON.parse(line);
50
- tableBatchBuilder.addRow(row);
51
- tableBatchBuilder.chunkComplete(line);
52
- _batch = tableBatchBuilder.getFullBatch();
53
- if (!_batch) {
54
- _context.next = 22;
55
- break;
56
- }
57
- _context.next = 22;
58
- return _batch;
59
- case 22:
60
- _context.next = 27;
61
- break;
62
- case 24:
63
- _context.prev = 24;
64
- _context.t0 = _context["catch"](14);
65
- throw new Error("NDJSONLoader: failed to parse JSON on line ".concat(counter));
66
- case 27:
67
- _iteratorAbruptCompletion = false;
68
- _context.next = 10;
69
- break;
70
- case 30:
71
- _context.next = 36;
72
- break;
73
- case 32:
74
- _context.prev = 32;
75
- _context.t1 = _context["catch"](8);
76
- _didIteratorError = true;
77
- _iteratorError = _context.t1;
78
- case 36:
79
- _context.prev = 36;
80
- _context.prev = 37;
81
- if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
82
- _context.next = 41;
83
- break;
84
- }
85
- _context.next = 41;
86
- return (0, _awaitAsyncGenerator2.default)(_iterator.return());
87
- case 41:
88
- _context.prev = 41;
89
- if (!_didIteratorError) {
90
- _context.next = 44;
91
- break;
92
- }
93
- throw _iteratorError;
94
- case 44:
95
- return _context.finish(41);
96
- case 45:
97
- return _context.finish(36);
98
- case 46:
99
- batch = tableBatchBuilder.getFinalBatch();
100
- if (!batch) {
101
- _context.next = 50;
102
- break;
103
- }
104
- _context.next = 50;
105
- return batch;
106
- case 50:
107
- case "end":
108
- return _context.stop();
9
+ async function* parseNDJSONInBatches(binaryAsyncIterator, options) {
10
+ const textIterator = (0, _loaderUtils.makeTextDecoderIterator)(binaryAsyncIterator);
11
+ const lineIterator = (0, _loaderUtils.makeLineIterator)(textIterator);
12
+ const numberedLineIterator = (0, _loaderUtils.makeNumberedLineIterator)(lineIterator);
13
+ const schema = null;
14
+ const shape = 'row-table';
15
+ const tableBatchBuilder = new _schema.TableBatchBuilder(schema, {
16
+ ...options,
17
+ shape
18
+ });
19
+ for await (const {
20
+ counter,
21
+ line
22
+ } of numberedLineIterator) {
23
+ try {
24
+ const row = JSON.parse(line);
25
+ tableBatchBuilder.addRow(row);
26
+ tableBatchBuilder.chunkComplete(line);
27
+ const batch = tableBatchBuilder.getFullBatch();
28
+ if (batch) {
29
+ yield batch;
109
30
  }
110
- }, _callee, null, [[8, 32, 36, 46], [14, 24], [37,, 41, 45]]);
111
- }));
112
- return _parseNDJSONInBatches.apply(this, arguments);
31
+ } catch (error) {
32
+ throw new Error("NDJSONLoader: failed to parse JSON on line ".concat(counter));
33
+ }
34
+ }
35
+ const batch = tableBatchBuilder.getFinalBatch();
36
+ if (batch) {
37
+ yield batch;
38
+ }
113
39
  }
114
40
  //# sourceMappingURL=parse-ndjson-in-batches.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"parse-ndjson-in-batches.js","names":["_schema","require","_loaderUtils","ownKeys","object","enumerableOnly","keys","Object","getOwnPropertySymbols","symbols","filter","sym","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","target","i","arguments","length","source","forEach","key","_defineProperty2","default","getOwnPropertyDescriptors","defineProperties","defineProperty","_asyncIterator","iterable","method","async","sync","retry","Symbol","asyncIterator","iterator","call","AsyncFromSyncIterator","TypeError","s","AsyncFromSyncIteratorContinuation","r","Promise","reject","done","resolve","value","then","n","next","prototype","return","_return","ret","throw","_throw","thr","parseNDJSONInBatches","_x","_x2","_parseNDJSONInBatches","_wrapAsyncGenerator2","_regenerator","mark","_callee","binaryAsyncIterator","options","textIterator","lineIterator","numberedLineIterator","schema","shape","tableBatchBuilder","_iteratorAbruptCompletion","_didIteratorError","_iteratorError","_iterator","_step","_step$value","counter","line","row","_batch","batch","wrap","_callee$","_context","prev","makeTextDecoderIterator","makeLineIterator","makeNumberedLineIterator","TableBatchBuilder","_awaitAsyncGenerator2","sent","JSON","parse","addRow","chunkComplete","getFullBatch","t0","Error","concat","t1","finish","getFinalBatch","stop"],"sources":["../../../src/lib/parse-ndjson-in-batches.ts"],"sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {\n LoaderOptions,\n makeLineIterator,\n makeNumberedLineIterator,\n makeTextDecoderIterator\n} from '@loaders.gl/loader-utils';\n\nexport default async function* parseNDJSONInBatches(\n binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: LoaderOptions\n): AsyncIterable<Batch> {\n const textIterator = makeTextDecoderIterator(binaryAsyncIterator);\n const lineIterator = makeLineIterator(textIterator);\n const numberedLineIterator = makeNumberedLineIterator(lineIterator);\n\n const schema = null;\n const shape = 'row-table';\n // @ts-ignore\n const tableBatchBuilder = new TableBatchBuilder(schema, {\n ...options,\n shape\n });\n\n for await (const {counter, line} of numberedLineIterator) {\n try {\n const row = JSON.parse(line);\n tableBatchBuilder.addRow(row);\n tableBatchBuilder.chunkComplete(line);\n const batch = tableBatchBuilder.getFullBatch();\n if (batch) {\n yield batch;\n }\n } catch (error) {\n throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);\n }\n }\n\n const batch = tableBatchBuilder.getFinalBatch();\n if (batch) {\n yield batch;\n }\n}\n"],"mappings":";;;;;;;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAKkC,SAAAE,QAAAC,MAAA,EAAAC,cAAA,QAAAC,IAAA,GAAAC,MAAA,CAAAD,IAAA,CAAAF,MAAA,OAAAG,MAAA,CAAAC,qBAAA,QAAAC,OAAA,GAAAF,MAAA,CAAAC,qBAAA,CAAAJ,MAAA,GAAAC,cAAA,KAAAI,OAAA,GAAAA,OAAA,CAAAC,MAAA,WAAAC,GAAA,WAAAJ,MAAA,CAAAK,wBAAA,CAAAR,MAAA,EAAAO,GAAA,EAAAE,UAAA,OAAAP,IAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,I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AAmB,IAAA;MAAA;IAAA,GAAAzC,OAAA;EAAA,CAEd;EAAA,OAAAJ,qBAAA,CAAA/C,KAAA,OAAAI,SAAA;AAAA"}
1
+ {"version":3,"file":"parse-ndjson-in-batches.js","names":["_schema","require","_loaderUtils","parseNDJSONInBatches","binaryAsyncIterator","options","textIterator","makeTextDecoderIterator","lineIterator","makeLineIterator","numberedLineIterator","makeNumberedLineIterator","schema","shape","tableBatchBuilder","TableBatchBuilder","counter","line","row","JSON","parse","addRow","chunkComplete","batch","getFullBatch","error","Error","concat","getFinalBatch"],"sources":["../../../src/lib/parse-ndjson-in-batches.ts"],"sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport {TableBatchBuilder} from '@loaders.gl/schema';\nimport {\n LoaderOptions,\n makeLineIterator,\n makeNumberedLineIterator,\n makeTextDecoderIterator\n} from '@loaders.gl/loader-utils';\n\nexport default async function* parseNDJSONInBatches(\n binaryAsyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: LoaderOptions\n): AsyncIterable<Batch> {\n const textIterator = makeTextDecoderIterator(binaryAsyncIterator);\n const lineIterator = makeLineIterator(textIterator);\n const numberedLineIterator = makeNumberedLineIterator(lineIterator);\n\n const schema = null;\n const shape = 'row-table';\n // @ts-ignore\n const tableBatchBuilder = new TableBatchBuilder(schema, {\n ...options,\n shape\n });\n\n for await (const {counter, line} of numberedLineIterator) {\n try {\n const row = JSON.parse(line);\n tableBatchBuilder.addRow(row);\n tableBatchBuilder.chunkComplete(line);\n const batch = tableBatchBuilder.getFullBatch();\n if (batch) {\n yield batch;\n }\n } catch (error) {\n throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter}`);\n }\n }\n\n const batch = tableBatchBuilder.getFinalBatch();\n if (batch) {\n yield batch;\n }\n}\n"],"mappings":";;;;;;AACA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAOe,gBAAgBE,oBAAoBA,CACjDC,mBAAuE,EACvEC,OAAuB,EACD;EACtB,MAAMC,YAAY,GAAG,IAAAC,oCAAuB,EAACH,mBAAmB,CAAC;EACjE,MAAMI,YAAY,GAAG,IAAAC,6BAAgB,EAACH,YAAY,CAAC;EACnD,MAAMI,oBAAoB,GAAG,IAAAC,qCAAwB,EAACH,YAAY,CAAC;EAEnE,MAAMI,MAAM,GAAG,IAAI;EACnB,MAAMC,KAAK,GAAG,WAAW;EAEzB,MAAMC,iBAAiB,GAAG,IAAIC,yBAAiB,CAACH,MAAM,EAAE;IACtD,GAAGP,OAAO;IACVQ;EACF,CAAC,CAAC;EAEF,WAAW,MAAM;IAACG,OAAO;IAAEC;EAAI,CAAC,IAAIP,oBAAoB,EAAE;IACxD,IAAI;MACF,MAAMQ,GAAG,GAAGC,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;MAC5BH,iBAAiB,CAACO,MAAM,CAACH,GAAG,CAAC;MAC7BJ,iBAAiB,CAACQ,aAAa,CAACL,IAAI,CAAC;MACrC,MAAMM,KAAK,GAAGT,iBAAiB,CAACU,YAAY,CAAC,CAAC;MAC9C,IAAID,KAAK,EAAE;QACT,MAAMA,KAAK;MACb;IACF,CAAC,CAAC,OAAOE,KAAK,EAAE;MACd,MAAM,IAAIC,KAAK,+CAAAC,MAAA,CAA+CX,OAAO,CAAE,CAAC;IAC1E;EACF;EAEA,MAAMO,KAAK,GAAGT,iBAAiB,CAACc,aAAa,CAAC,CAAC;EAC/C,IAAIL,KAAK,EAAE;IACT,MAAMA,KAAK;EACb;AACF"}
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = parseNDJSONSync;
7
7
  function parseNDJSONSync(ndjsonText) {
8
- var lines = ndjsonText.trim().split('\n');
9
- return lines.map(function (line, counter) {
8
+ const lines = ndjsonText.trim().split('\n');
9
+ return lines.map((line, counter) => {
10
10
  try {
11
11
  return JSON.parse(line);
12
12
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"file":"parse-ndjson.js","names":["parseNDJSONSync","ndjsonText","lines","trim","split","map","line","counter","JSON","parse","error","Error","concat"],"sources":["../../../src/lib/parse-ndjson.ts"],"sourcesContent":["export default function parseNDJSONSync(ndjsonText: string) {\n const lines = ndjsonText.trim().split('\\n');\n return lines.map((line, counter) => {\n try {\n return JSON.parse(line);\n } catch (error) {\n throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);\n }\n });\n}\n"],"mappings":";;;;;;AAAe,SAASA,eAAeA,CAACC,UAAkB,EAAE;EAC1D,IAAMC,KAAK,GAAGD,UAAU,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAAC;EAC3C,OAAOF,KAAK,CAACG,GAAG,CAAC,UAACC,IAAI,EAAEC,OAAO,EAAK;IAClC,IAAI;MACF,OAAOC,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;IACzB,CAAC,CAAC,OAAOI,KAAK,EAAE;MACd,MAAM,IAAIC,KAAK,+CAAAC,MAAA,CAA+CL,OAAO,GAAG,CAAC,CAAE,CAAC;IAC9E;EACF,CAAC,CAAC;AACJ"}
1
+ {"version":3,"file":"parse-ndjson.js","names":["parseNDJSONSync","ndjsonText","lines","trim","split","map","line","counter","JSON","parse","error","Error","concat"],"sources":["../../../src/lib/parse-ndjson.ts"],"sourcesContent":["export default function parseNDJSONSync(ndjsonText: string) {\n const lines = ndjsonText.trim().split('\\n');\n return lines.map((line, counter) => {\n try {\n return JSON.parse(line);\n } catch (error) {\n throw new Error(`NDJSONLoader: failed to parse JSON on line ${counter + 1}`);\n }\n });\n}\n"],"mappings":";;;;;;AAAe,SAASA,eAAeA,CAACC,UAAkB,EAAE;EAC1D,MAAMC,KAAK,GAAGD,UAAU,CAACE,IAAI,CAAC,CAAC,CAACC,KAAK,CAAC,IAAI,CAAC;EAC3C,OAAOF,KAAK,CAACG,GAAG,CAAC,CAACC,IAAI,EAAEC,OAAO,KAAK;IAClC,IAAI;MACF,OAAOC,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;IACzB,CAAC,CAAC,OAAOI,KAAK,EAAE;MACd,MAAM,IAAIC,KAAK,+CAAAC,MAAA,CAA+CL,OAAO,GAAG,CAAC,CAAE,CAAC;IAC9E;EACF,CAAC,CAAC;AACJ"}