@loaders.gl/json 3.0.9 → 3.0.13

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.
@@ -7,19 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
-
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
-
14
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
11
 
16
12
  var _clarinet = _interopRequireDefault(require("../clarinet/clarinet"));
17
13
 
18
14
  var _jsonpath = _interopRequireDefault(require("../jsonpath/jsonpath"));
19
15
 
20
- var JSONParser = function () {
21
- function JSONParser() {
22
- (0, _classCallCheck2.default)(this, JSONParser);
16
+ class JSONParser {
17
+ constructor() {
23
18
  (0, _defineProperty2.default)(this, "jsonpath", void 0);
24
19
  (0, _defineProperty2.default)(this, "_parser", void 0);
25
20
  this.reset();
@@ -27,134 +22,118 @@ var JSONParser = function () {
27
22
  this._initializeParser();
28
23
  }
29
24
 
30
- (0, _createClass2.default)(JSONParser, [{
31
- key: "reset",
32
- value: function reset() {
33
- this.result = undefined;
34
- this.previousStates = [];
35
- this.currentState = Object.freeze({
36
- container: [],
37
- key: null
38
- });
39
- this.jsonpath = new _jsonpath.default();
40
- }
41
- }, {
42
- key: "write",
43
- value: function write(chunk) {
44
- this.parser.write(chunk);
45
- }
46
- }, {
47
- key: "close",
48
- value: function close() {
49
- this.parser.close();
50
- }
51
- }, {
52
- key: "_pushOrSet",
53
- value: function _pushOrSet(value) {
54
- var _this$currentState = this.currentState,
55
- container = _this$currentState.container,
56
- key = _this$currentState.key;
57
-
58
- if (key !== null) {
59
- container[key] = value;
60
- this.currentState.key = null;
61
- } else {
62
- container.push(value);
63
- }
64
- }
65
- }, {
66
- key: "_openArray",
67
- value: function _openArray() {
68
- var newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
69
- this.jsonpath.push(null);
70
-
71
- this._pushOrSet(newContainer);
72
-
73
- this.previousStates.push(this.currentState);
74
- this.currentState = {
75
- container: newContainer,
76
- isArray: true,
77
- key: null
78
- };
79
- }
80
- }, {
81
- key: "_closeArray",
82
- value: function _closeArray() {
83
- this.jsonpath.pop();
84
- this.currentState = this.previousStates.pop();
85
- }
86
- }, {
87
- key: "_openObject",
88
- value: function _openObject() {
89
- var newContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
90
- this.jsonpath.push(null);
91
-
92
- this._pushOrSet(newContainer);
93
-
94
- this.previousStates.push(this.currentState);
95
- this.currentState = {
96
- container: newContainer,
97
- isArray: false,
98
- key: null
99
- };
100
- }
101
- }, {
102
- key: "_closeObject",
103
- value: function _closeObject() {
104
- this.jsonpath.pop();
105
- this.currentState = this.previousStates.pop();
25
+ reset() {
26
+ this.result = undefined;
27
+ this.previousStates = [];
28
+ this.currentState = Object.freeze({
29
+ container: [],
30
+ key: null
31
+ });
32
+ this.jsonpath = new _jsonpath.default();
33
+ }
34
+
35
+ write(chunk) {
36
+ this.parser.write(chunk);
37
+ }
38
+
39
+ close() {
40
+ this.parser.close();
41
+ }
42
+
43
+ _pushOrSet(value) {
44
+ const {
45
+ container,
46
+ key
47
+ } = this.currentState;
48
+
49
+ if (key !== null) {
50
+ container[key] = value;
51
+ this.currentState.key = null;
52
+ } else {
53
+ container.push(value);
106
54
  }
107
- }, {
108
- key: "_initializeParser",
109
- value: function _initializeParser() {
110
- var _this = this;
111
-
112
- this._parser = new _clarinet.default({
113
- onready: function onready() {
114
- _this.jsonpath = new _jsonpath.default();
115
- _this.previousStates.length = 0;
116
- _this.currentState.container.length = 0;
117
- },
118
- onopenobject: function onopenobject(name) {
119
- _this._openObject({});
120
-
121
- if (typeof name !== 'undefined') {
122
- _this.parser.onkey(name);
123
- }
124
- },
125
- onkey: function onkey(name) {
126
- _this.jsonpath.set(name);
127
-
128
- _this.currentState.key = name;
129
- },
130
- oncloseobject: function oncloseobject() {
131
- _this._closeObject();
132
- },
133
- onopenarray: function onopenarray() {
134
- _this._openArray();
135
- },
136
- onclosearray: function onclosearray() {
137
- _this._closeArray();
138
- },
139
- onvalue: function onvalue(value) {
140
- _this._pushOrSet(value);
141
- },
142
- onerror: function onerror(error) {
143
- throw error;
144
- },
145
- onend: function onend() {
146
- _this.result = _this.currentState.container.pop();
55
+ }
56
+
57
+ _openArray(newContainer = []) {
58
+ this.jsonpath.push(null);
59
+
60
+ this._pushOrSet(newContainer);
61
+
62
+ this.previousStates.push(this.currentState);
63
+ this.currentState = {
64
+ container: newContainer,
65
+ isArray: true,
66
+ key: null
67
+ };
68
+ }
69
+
70
+ _closeArray() {
71
+ this.jsonpath.pop();
72
+ this.currentState = this.previousStates.pop();
73
+ }
74
+
75
+ _openObject(newContainer = {}) {
76
+ this.jsonpath.push(null);
77
+
78
+ this._pushOrSet(newContainer);
79
+
80
+ this.previousStates.push(this.currentState);
81
+ this.currentState = {
82
+ container: newContainer,
83
+ isArray: false,
84
+ key: null
85
+ };
86
+ }
87
+
88
+ _closeObject() {
89
+ this.jsonpath.pop();
90
+ this.currentState = this.previousStates.pop();
91
+ }
92
+
93
+ _initializeParser() {
94
+ this._parser = new _clarinet.default({
95
+ onready: () => {
96
+ this.jsonpath = new _jsonpath.default();
97
+ this.previousStates.length = 0;
98
+ this.currentState.container.length = 0;
99
+ },
100
+ onopenobject: name => {
101
+ this._openObject({});
102
+
103
+ if (typeof name !== 'undefined') {
104
+ this.parser.onkey(name);
147
105
  }
148
- });
149
- }
150
- }, {
151
- key: "parser",
152
- get: function get() {
153
- return this._parser;
154
- }
155
- }]);
156
- return JSONParser;
157
- }();
106
+ },
107
+ onkey: name => {
108
+ this.jsonpath.set(name);
109
+ this.currentState.key = name;
110
+ },
111
+ oncloseobject: () => {
112
+ this._closeObject();
113
+ },
114
+ onopenarray: () => {
115
+ this._openArray();
116
+ },
117
+ onclosearray: () => {
118
+ this._closeArray();
119
+ },
120
+ onvalue: value => {
121
+ this._pushOrSet(value);
122
+ },
123
+ onerror: error => {
124
+ throw error;
125
+ },
126
+ onend: () => {
127
+ this.result = this.currentState.container.pop();
128
+ }
129
+ });
130
+ }
131
+
132
+ get parser() {
133
+ return this._parser;
134
+ }
135
+
136
+ }
158
137
 
159
138
  exports.default = JSONParser;
160
139
  //# sourceMappingURL=json-parser.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/parser/json-parser.ts"],"names":["JSONParser","reset","_initializeParser","result","undefined","previousStates","currentState","Object","freeze","container","key","jsonpath","JSONPath","chunk","parser","write","close","value","push","newContainer","_pushOrSet","isArray","pop","_parser","ClarinetParser","onready","length","onopenobject","name","_openObject","onkey","set","oncloseobject","_closeObject","onopenarray","_openArray","onclosearray","_closeArray","onvalue","onerror","error","onend"],"mappings":";;;;;;;;;;;;;;;AAEA;;AACA;;IAIqBA,U;AAInB,wBAAc;AAAA;AAAA;AAAA;AACZ,SAAKC,KAAL;;AACA,SAAKC,iBAAL;AACD;;;;WAED,iBAAc;AACZ,WAAKC,MAAL,GAAcC,SAAd;AACA,WAAKC,cAAL,GAAsB,EAAtB;AACA,WAAKC,YAAL,GAAoBC,MAAM,CAACC,MAAP,CAAc;AAACC,QAAAA,SAAS,EAAE,EAAZ;AAAgBC,QAAAA,GAAG,EAAE;AAArB,OAAd,CAApB;AACA,WAAKC,QAAL,GAAgB,IAAIC,iBAAJ,EAAhB;AACD;;;WAED,eAAMC,KAAN,EAAmB;AACjB,WAAKC,MAAL,CAAYC,KAAZ,CAAkBF,KAAlB;AACD;;;WAED,iBAAc;AACZ,WAAKC,MAAL,CAAYE,KAAZ;AACD;;;WAID,oBAAWC,KAAX,EAAwB;AACtB,+BAAyB,KAAKX,YAA9B;AAAA,UAAOG,SAAP,sBAAOA,SAAP;AAAA,UAAkBC,GAAlB,sBAAkBA,GAAlB;;AACA,UAAIA,GAAG,KAAK,IAAZ,EAAkB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ath from '../jsonpath/jsonpath';\n\n// JSONParser builds a JSON object using the events emitted by the Clarinet parser\n\nexport default class JSONParser {\n jsonpath: JSONPath;\n _parser?: ClarinetParser;\n\n constructor() {\n this.reset();\n this._initializeParser();\n }\n\n reset(): void {\n this.result = undefined;\n this.previousStates = [];\n this.currentState = Object.freeze({container: [], key: null});\n this.jsonpath = new JSONPath();\n }\n\n write(chunk): void {\n this.parser.write(chunk);\n }\n\n close(): void {\n this.parser.close();\n }\n\n // PRIVATE METHODS\n\n _pushOrSet(value): void {\n const {container, key} = this.currentState;\n if (key !== null) {\n container[key] = value;\n this.currentState.key = null;\n } else {\n container.push(value);\n }\n }\n\n _openArray(newContainer = []): void {\n this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: true, key: null};\n }\n\n _closeArray(): void {\n this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _openObject(newContainer = {}): void {\n this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: false, key: null};\n }\n\n _closeObject(): void {\n this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _initializeParser(): void {\n this._parser = new ClarinetParser({\n onready: () => {\n this.jsonpath = new JSONPath();\n this.previousStates.length = 0;\n this.currentState.container.length = 0;\n },\n\n onopenobject: (name) => {\n this._openObject({});\n if (typeof name !== 'undefined') {\n this.parser.onkey(name);\n }\n },\n\n onkey: (name) => {\n this.jsonpath.set(name);\n this.currentState.key = name;\n },\n\n oncloseobject: () => {\n this._closeObject();\n },\n\n onopenarray: () => {\n this._openArray();\n },\n\n onclosearray: () => {\n this._closeArray();\n },\n\n onvalue: (value) => {\n this._pushOrSet(value);\n },\n\n onerror: (error) => {\n throw error;\n },\n\n onend: () => {\n this.result = this.currentState.container.pop();\n }\n });\n }\n\n protected get parser(): ClarinetParser {\n return this._parser as ClarinetParser;\n }\n}\n"],"file":"json-parser.js"}
1
+ {"version":3,"sources":["../../../../src/lib/parser/json-parser.ts"],"names":["JSONParser","constructor","reset","_initializeParser","result","undefined","previousStates","currentState","Object","freeze","container","key","jsonpath","JSONPath","write","chunk","parser","close","_pushOrSet","value","push","_openArray","newContainer","isArray","_closeArray","pop","_openObject","_closeObject","_parser","ClarinetParser","onready","length","onopenobject","name","onkey","set","oncloseobject","onopenarray","onclosearray","onvalue","onerror","error","onend"],"mappings":";;;;;;;;;;;AAEA;;AACA;;AAIe,MAAMA,UAAN,CAAiB;AAI9BC,EAAAA,WAAW,GAAG;AAAA;AAAA;AACZ,SAAKC,KAAL;;AACA,SAAKC,iBAAL;AACD;;AAEDD,EAAAA,KAAK,GAAS;AACZ,SAAKE,MAAL,GAAcC,SAAd;AACA,SAAKC,cAAL,GAAsB,EAAtB;AACA,SAAKC,YAAL,GAAoBC,MAAM,CAACC,MAAP,CAAc;AAACC,MAAAA,SAAS,EAAE,EAAZ;AAAgBC,MAAAA,GAAG,EAAE;AAArB,KAAd,CAApB;AACA,SAAKC,QAAL,GAAgB,IAAIC,iBAAJ,EAAhB;AACD;;AAEDC,EAAAA,KAAK,CAACC,KAAD,EAAc;AACjB,SAAKC,MAAL,CAAYF,KAAZ,CAAkBC,KAAlB;AACD;;AAEDE,EAAAA,KAAK,GAAS;AACZ,SAAKD,MAAL,CAAYC,KAAZ;AACD;;AAIDC,EAAAA,UAAU,CAACC,KAAD,EAAc;AACtB,UAAM;AAACT,MAAAA,SAAD;AAAYC,MAAAA;AAAZ,QAAmB,KAAKJ,YAA9B;;AACA,QAAII,GAAG,KAAK,IAAZ,EAAkB;AAChBD,MAAAA,SAAS,CAACC,GAAD,CAAT,GAAiBQ,KAAjB;AACA,WAAKZ,YAAL,CAAkBI,GAAlB,GAAwB,IAAxB;AACD,KAHD,MAGO;AACLD,MAAAA,SAAS,CAACU,IAAV,CAAeD,KAAf;AACD;AACF;;AAEDE,EAAAA,UAAU,CAACC,YAAY,GAAG,EAAhB,EAA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;;AACA,YAAI,OAAOO,IAAP,KAAgB,WAApB,EAAiC;AAC/B,eAAKjB,MAAL,CAAYkB,KAAZ,CAAkBD,IAAlB;AACD;AACF,OAZ+B;AAchCC,MAAAA,KAAK,EAAGD,IAAD,IAAU;AACf,aAAKrB,QAAL,CAAcuB,GAAd,CAAkBF,IAAlB;AACA,aAAK1B,YAAL,CAAkBI,GAAlB,GAAwBsB,IAAxB;AACD,OAjB+B;AAmBhCG,MAAAA,aAAa,EAAE,MAAM;AACnB,aAAKT,YAAL;AACD,OArB+B;AAuBhCU,MAAAA,WAAW,EAAE,MAAM;AACjB,aAAKhB,UAAL;AACD,OAzB+B;AA2BhCiB,MAAAA,YAAY,EAAE,MAAM;AAClB,aAAKd,WAAL;AACD,OA7B+B;AA+BhCe,MAAAA,OAAO,EAAGpB,KAAD,IAAW;AAClB,aAAKD,UAAL,CAAgBC,KAAhB;AACD,OAjC+B;AAmChCqB,MAAAA,OAAO,EAAGC,KAAD,IAAW;AAClB,cAAMA,KAAN;AACD,OArC+B;AAuChCC,MAAAA,KAAK,EAAE,MAAM;AACX,aAAKtC,MAAL,GAAc,KAAKG,YAAL,CAAkBG,SAAlB,CAA4Be,GAA5B,EAAd;AACD;AAzC+B,KAAnB,CAAf;AA2CD;;AAEmB,MAANT,MAAM,GAAmB;AACrC,WAAO,KAAKY,OAAZ;AACD;;AA5G6B","sourcesContent":["// @ts-nocheck\n\nimport ClarinetParser from '../clarinet/clarinet';\nimport JSONPath from '../jsonpath/jsonpath';\n\n// JSONParser builds a JSON object using the events emitted by the Clarinet parser\n\nexport default class JSONParser {\n jsonpath: JSONPath;\n _parser?: ClarinetParser;\n\n constructor() {\n this.reset();\n this._initializeParser();\n }\n\n reset(): void {\n this.result = undefined;\n this.previousStates = [];\n this.currentState = Object.freeze({container: [], key: null});\n this.jsonpath = new JSONPath();\n }\n\n write(chunk): void {\n this.parser.write(chunk);\n }\n\n close(): void {\n this.parser.close();\n }\n\n // PRIVATE METHODS\n\n _pushOrSet(value): void {\n const {container, key} = this.currentState;\n if (key !== null) {\n container[key] = value;\n this.currentState.key = null;\n } else {\n container.push(value);\n }\n }\n\n _openArray(newContainer = []): void {\n this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: true, key: null};\n }\n\n _closeArray(): void {\n this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _openObject(newContainer = {}): void {\n this.jsonpath.push(null);\n this._pushOrSet(newContainer);\n this.previousStates.push(this.currentState);\n this.currentState = {container: newContainer, isArray: false, key: null};\n }\n\n _closeObject(): void {\n this.jsonpath.pop();\n this.currentState = this.previousStates.pop();\n }\n\n _initializeParser(): void {\n this._parser = new ClarinetParser({\n onready: () => {\n this.jsonpath = new JSONPath();\n this.previousStates.length = 0;\n this.currentState.container.length = 0;\n },\n\n onopenobject: (name) => {\n this._openObject({});\n if (typeof name !== 'undefined') {\n this.parser.onkey(name);\n }\n },\n\n onkey: (name) => {\n this.jsonpath.set(name);\n this.currentState.key = name;\n },\n\n oncloseobject: () => {\n this._closeObject();\n },\n\n onopenarray: () => {\n this._openArray();\n },\n\n onclosearray: () => {\n this._closeArray();\n },\n\n onvalue: (value) => {\n this._pushOrSet(value);\n },\n\n onerror: (error) => {\n throw error;\n },\n\n onend: () => {\n this.result = this.currentState.container.pop();\n }\n });\n }\n\n protected get parser(): ClarinetParser {\n return this._parser as ClarinetParser;\n }\n}\n"],"file":"json-parser.js"}
@@ -7,161 +7,101 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
-
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
-
14
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
-
16
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
-
18
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
19
-
20
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
-
22
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
-
24
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
-
26
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
11
 
28
12
  var _jsonParser = _interopRequireDefault(require("./json-parser"));
29
13
 
30
14
  var _jsonpath = _interopRequireDefault(require("../jsonpath/jsonpath"));
31
15
 
32
- 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; } } }; }
33
-
34
- 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); }
35
-
36
- 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; }
37
-
38
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
39
-
40
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
16
+ class StreamingJSONParser extends _jsonParser.default {
17
+ constructor(options = {}) {
18
+ super();
19
+ (0, _defineProperty2.default)(this, "jsonPaths", void 0);
20
+ (0, _defineProperty2.default)(this, "streamingJsonPath", null);
21
+ (0, _defineProperty2.default)(this, "streamingArray", null);
22
+ (0, _defineProperty2.default)(this, "topLevelObject", null);
23
+ const jsonpaths = options.jsonpaths || [];
24
+ this.jsonPaths = jsonpaths.map(jsonpath => new _jsonpath.default(jsonpath));
25
+
26
+ this._extendParser();
27
+ }
41
28
 
42
- var StreamingJSONParser = function (_JSONParser) {
43
- (0, _inherits2.default)(StreamingJSONParser, _JSONParser);
29
+ write(chunk) {
30
+ super.write(chunk);
31
+ let array = [];
44
32
 
45
- var _super = _createSuper(StreamingJSONParser);
33
+ if (this.streamingArray) {
34
+ array = [...this.streamingArray];
35
+ this.streamingArray.length = 0;
36
+ }
46
37
 
47
- function StreamingJSONParser() {
48
- var _this;
38
+ return array;
39
+ }
49
40
 
50
- var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
51
- (0, _classCallCheck2.default)(this, StreamingJSONParser);
52
- _this = _super.call(this);
53
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "jsonPaths", void 0);
54
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "streamingJsonPath", null);
55
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "streamingArray", null);
56
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "topLevelObject", null);
57
- var jsonpaths = options.jsonpaths || [];
58
- _this.jsonPaths = jsonpaths.map(function (jsonpath) {
59
- return new _jsonpath.default(jsonpath);
60
- });
41
+ getPartialResult() {
42
+ return this.topLevelObject;
43
+ }
61
44
 
62
- _this._extendParser();
45
+ getStreamingJsonPath() {
46
+ return this.streamingJsonPath;
47
+ }
63
48
 
64
- return _this;
49
+ getStreamingJsonPathAsString() {
50
+ return this.streamingJsonPath && this.streamingJsonPath.toString();
65
51
  }
66
52
 
67
- (0, _createClass2.default)(StreamingJSONParser, [{
68
- key: "write",
69
- value: function write(chunk) {
70
- (0, _get2.default)((0, _getPrototypeOf2.default)(StreamingJSONParser.prototype), "write", this).call(this, chunk);
71
- var array = [];
53
+ getJsonPath() {
54
+ return this.jsonpath;
55
+ }
72
56
 
73
- if (this.streamingArray) {
74
- array = (0, _toConsumableArray2.default)(this.streamingArray);
75
- this.streamingArray.length = 0;
76
- }
57
+ _matchJSONPath() {
58
+ const currentPath = this.getJsonPath();
77
59
 
78
- return array;
60
+ if (this.jsonPaths.length === 0) {
61
+ return true;
79
62
  }
80
- }, {
81
- key: "getPartialResult",
82
- value: function getPartialResult() {
83
- return this.topLevelObject;
84
- }
85
- }, {
86
- key: "getStreamingJsonPath",
87
- value: function getStreamingJsonPath() {
88
- return this.streamingJsonPath;
89
- }
90
- }, {
91
- key: "getStreamingJsonPathAsString",
92
- value: function getStreamingJsonPathAsString() {
93
- return this.streamingJsonPath && this.streamingJsonPath.toString();
94
- }
95
- }, {
96
- key: "getJsonPath",
97
- value: function getJsonPath() {
98
- return this.jsonpath;
99
- }
100
- }, {
101
- key: "_matchJSONPath",
102
- value: function _matchJSONPath() {
103
- var currentPath = this.getJsonPath();
104
63
 
105
- if (this.jsonPaths.length === 0) {
64
+ for (const jsonPath of this.jsonPaths) {
65
+ if (jsonPath.equals(currentPath)) {
106
66
  return true;
107
67
  }
68
+ }
108
69
 
109
- var _iterator = _createForOfIteratorHelper(this.jsonPaths),
110
- _step;
70
+ return false;
71
+ }
72
+
73
+ _extendParser() {
74
+ this.parser.onopenarray = () => {
75
+ if (!this.streamingArray) {
76
+ if (this._matchJSONPath()) {
77
+ this.streamingJsonPath = this.getJsonPath().clone();
78
+ this.streamingArray = [];
111
79
 
112
- try {
113
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
114
- var jsonPath = _step.value;
80
+ this._openArray(this.streamingArray);
115
81
 
116
- if (jsonPath.equals(currentPath)) {
117
- return true;
118
- }
82
+ return;
119
83
  }
120
- } catch (err) {
121
- _iterator.e(err);
122
- } finally {
123
- _iterator.f();
124
84
  }
125
85
 
126
- return false;
127
- }
128
- }, {
129
- key: "_extendParser",
130
- value: function _extendParser() {
131
- var _this2 = this;
132
-
133
- this.parser.onopenarray = function () {
134
- if (!_this2.streamingArray) {
135
- if (_this2._matchJSONPath()) {
136
- _this2.streamingJsonPath = _this2.getJsonPath().clone();
137
- _this2.streamingArray = [];
86
+ this._openArray();
87
+ };
138
88
 
139
- _this2._openArray(_this2.streamingArray);
89
+ this.parser.onopenobject = name => {
90
+ if (!this.topLevelObject) {
91
+ this.topLevelObject = {};
140
92
 
141
- return;
142
- }
143
- }
144
-
145
- _this2._openArray();
146
- };
147
-
148
- this.parser.onopenobject = function (name) {
149
- if (!_this2.topLevelObject) {
150
- _this2.topLevelObject = {};
93
+ this._openObject(this.topLevelObject);
94
+ } else {
95
+ this._openObject({});
96
+ }
151
97
 
152
- _this2._openObject(_this2.topLevelObject);
153
- } else {
154
- _this2._openObject({});
155
- }
98
+ if (typeof name !== 'undefined') {
99
+ this.parser.onkey(name);
100
+ }
101
+ };
102
+ }
156
103
 
157
- if (typeof name !== 'undefined') {
158
- _this2.parser.onkey(name);
159
- }
160
- };
161
- }
162
- }]);
163
- return StreamingJSONParser;
164
- }(_jsonParser.default);
104
+ }
165
105
 
166
106
  exports.default = StreamingJSONParser;
167
107
  //# sourceMappingURL=streaming-json-parser.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/lib/parser/streaming-json-parser.ts"],"names":["StreamingJSONParser","options","jsonpaths","jsonPaths","map","jsonpath","JSONPath","_extendParser","chunk","array","streamingArray","length","topLevelObject","streamingJsonPath","toString","currentPath","getJsonPath","jsonPath","equals","parser","onopenarray","_matchJSONPath","clone","_openArray","onopenobject","name","_openObject","onkey","JSONParser"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;;;;;;;;;;;IAMqBA,mB;;;;;AAMnB,iCAAgD;AAAA;;AAAA,QAApCC,OAAoC,uEAAJ,EAAI;AAAA;AAC9C;AAD8C;AAAA,oGAJH,IAIG;AAAA,iGAHT,IAGS;AAAA,iGAFR,IAEQ;AAE9C,QAAMC,SAAS,GAAGD,OAAO,CAACC,SAAR,IAAqB,EAAvC;AACA,UAAKC,SAAL,GAAiBD,SAAS,CAACE,GAAV,CAAc,UAACC,QAAD;AAAA,aAAc,IAAIC,iBAAJ,CAAaD,QAAb,CAAd;AAAA,KAAd,CAAjB;;AACA,UAAKE,aAAL;;AAJ8C;AAK/C;;;;WASD,eAAMC,KAAN,EAAa;AACX,iHAAYA,KAAZ;AACA,UAAIC,KAAY,GAAG,EAAnB;;AACA,UAAI,KAAKC,cAAT,EAAyB;AACvBD,QAAAA,KAAK,oCAAO,KAAKC,cAAZ,CAAL;AACA,aAAKA,cAAL,CAAoBC,MAApB,GAA6B,CAA7B;AACD;;AACD,aAAOF,KAAP;AACD;;;WAOD,4BAAmB;AACjB,aAAO,KAAKG,cAAZ;AACD;;;WAED,gCAAuB;AACrB,aAAO,KAAKC,iBAAZ;AACD;;;WAED,wCAA+B;AAC7B,aAAO,KAAKA,iBAAL,IAA0B,KAAKA,iBAAL,CAAuBC,QAAvB,EAAjC;AACD;;;W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Content":["import {default as JSONParser} from './json-parser';\nimport JSONPath from '../jsonpath/jsonpath';\n\n/**\n * The `StreamingJSONParser` looks for the first array in the JSON structure.\n * and emits an array of chunks\n */\nexport default class StreamingJSONParser extends JSONParser {\n private jsonPaths: JSONPath[];\n private streamingJsonPath: JSONPath | null = null;\n private streamingArray: any[] | null = null;\n private topLevelObject: object | null = null;\n\n constructor(options: {[key: string]: any} = {}) {\n super();\n const jsonpaths = options.jsonpaths || [];\n this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));\n this._extendParser();\n }\n\n /**\n * write REDEFINITION\n * - super.write() chunk to parser\n * - get the contents (so far) of \"topmost-level\" array as batch of rows\n * - clear top-level array\n * - return the batch of rows\\\n */\n write(chunk) {\n super.write(chunk);\n let array: any[] = [];\n if (this.streamingArray) {\n array = [...this.streamingArray];\n this.streamingArray.length = 0;\n }\n return array;\n }\n\n /**\n * Returns a partially formed result object\n * Useful for returning the \"wrapper\" object when array is not top level\n * e.g. GeoJSON\n */\n getPartialResult() {\n return this.topLevelObject;\n }\n\n getStreamingJsonPath() {\n return this.streamingJsonPath;\n }\n\n getStreamingJsonPathAsString() {\n return this.streamingJsonPath && this.streamingJsonPath.toString();\n }\n\n getJsonPath() {\n return this.jsonpath;\n }\n\n // PRIVATE METHODS\n\n /**\n * Checks is this.getJsonPath matches the jsonpaths provided in options\n */\n _matchJSONPath() {\n const currentPath = this.getJsonPath();\n // console.debug(`Testing JSONPath`, currentPath);\n\n // Backwards compatibility, match any array\n // TODO implement using wildcard once that is supported\n if (this.jsonPaths.length === 0) {\n return true;\n }\n\n for (const jsonPath of this.jsonPaths) {\n if (jsonPath.equals(currentPath)) {\n return true;\n }\n }\n\n return false;\n }\n\n _extendParser() {\n // Redefine onopenarray to locate and inject value for top-level array\n this.parser.onopenarray = () => {\n if (!this.streamingArray) {\n if (this._matchJSONPath()) {\n // @ts-ignore\n this.streamingJsonPath = this.getJsonPath().clone();\n this.streamingArray = [];\n this._openArray(this.streamingArray as []);\n return;\n }\n }\n\n this._openArray();\n };\n\n // Redefine onopenarray to inject value for top-level object\n this.parser.onopenobject = (name) => {\n if (!this.topLevelObject) {\n this.topLevelObject = {};\n this._openObject(this.topLevelObject);\n } else {\n this._openObject({});\n }\n if (typeof name !== 'undefined') {\n this.parser.onkey(name);\n }\n };\n }\n}\n"],"file":"streaming-json-parser.js"}
1
+ {"version":3,"sources":["../../../../src/lib/parser/streaming-json-parser.ts"],"names":["StreamingJSONParser","JSONParser","constructor","options","jsonpaths","jsonPaths","map","jsonpath","JSONPath","_extendParser","write","chunk","array","streamingArray","length","getPartialResult","topLevelObject","getStreamingJsonPath","streamingJsonPath","getStreamingJsonPathAsString","toString","getJsonPath","_matchJSONPath","currentPath","jsonPath","equals","parser","onopenarray","clone","_openArray","onopenobject","name","_openObject","onkey"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAMe,MAAMA,mBAAN,SAAkCC,mBAAlC,CAA6C;AAM1DC,EAAAA,WAAW,CAACC,OAA6B,GAAG,EAAjC,EAAqC;AAC9C;AAD8C;AAAA,6DAJH,IAIG;AAAA,0DAHT,IAGS;AAAA,0DAFR,IAEQ;AAE9C,UAAMC,SAAS,GAAGD,OAAO,CAACC,SAAR,IAAqB,EAAvC;AACA,SAAKC,SAAL,GAAiBD,SAAS,CAACE,GAAV,CAAeC,QAAD,IAAc,IAAIC,iBAAJ,CAAaD,QAAb,CAA5B,CAAjB;;AACA,SAAKE,aAAL;AACD;;AASDC,EAAAA,KAAK,CAACC,KAAD,EAAQ;AACX,UAAMD,KAAN,CAAYC,KAAZ;AACA,QAAIC,KAAY,GAAG,EAAnB;;AACA,QAAI,KAAKC,cAAT,EAAyB;AACvBD,MAAAA,KAAK,GAAG,CAAC,GAAG,KAAKC,cAAT,CAAR;AACA,WAAKA,cAAL,CAAoBC,MAApB,GAA6B,CAA7B;AACD;;AACD,WAAOF,KAAP;AACD;;AAODG,EAAAA,gBAAgB,GAAG;AACjB,WAAO,KAAKC,cA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;AACF,KAVD;AAWD;;AAvGyD","sourcesContent":["import {default as JSONParser} from './json-parser';\nimport JSONPath from '../jsonpath/jsonpath';\n\n/**\n * The `StreamingJSONParser` looks for the first array in the JSON structure.\n * and emits an array of chunks\n */\nexport default class StreamingJSONParser extends JSONParser {\n private jsonPaths: JSONPath[];\n private streamingJsonPath: JSONPath | null = null;\n private streamingArray: any[] | null = null;\n private topLevelObject: object | null = null;\n\n constructor(options: {[key: string]: any} = {}) {\n super();\n const jsonpaths = options.jsonpaths || [];\n this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));\n this._extendParser();\n }\n\n /**\n * write REDEFINITION\n * - super.write() chunk to parser\n * - get the contents (so far) of \"topmost-level\" array as batch of rows\n * - clear top-level array\n * - return the batch of rows\\\n */\n write(chunk) {\n super.write(chunk);\n let array: any[] = [];\n if (this.streamingArray) {\n array = [...this.streamingArray];\n this.streamingArray.length = 0;\n }\n return array;\n }\n\n /**\n * Returns a partially formed result object\n * Useful for returning the \"wrapper\" object when array is not top level\n * e.g. GeoJSON\n */\n getPartialResult() {\n return this.topLevelObject;\n }\n\n getStreamingJsonPath() {\n return this.streamingJsonPath;\n }\n\n getStreamingJsonPathAsString() {\n return this.streamingJsonPath && this.streamingJsonPath.toString();\n }\n\n getJsonPath() {\n return this.jsonpath;\n }\n\n // PRIVATE METHODS\n\n /**\n * Checks is this.getJsonPath matches the jsonpaths provided in options\n */\n _matchJSONPath() {\n const currentPath = this.getJsonPath();\n // console.debug(`Testing JSONPath`, currentPath);\n\n // Backwards compatibility, match any array\n // TODO implement using wildcard once that is supported\n if (this.jsonPaths.length === 0) {\n return true;\n }\n\n for (const jsonPath of this.jsonPaths) {\n if (jsonPath.equals(currentPath)) {\n return true;\n }\n }\n\n return false;\n }\n\n _extendParser() {\n // Redefine onopenarray to locate and inject value for top-level array\n this.parser.onopenarray = () => {\n if (!this.streamingArray) {\n if (this._matchJSONPath()) {\n // @ts-ignore\n this.streamingJsonPath = this.getJsonPath().clone();\n this.streamingArray = [];\n this._openArray(this.streamingArray as []);\n return;\n }\n }\n\n this._openArray();\n };\n\n // Redefine onopenarray to inject value for top-level object\n this.parser.onopenobject = (name) => {\n if (!this.topLevelObject) {\n this.topLevelObject = {};\n this._openObject(this.topLevelObject);\n } else {\n this._openObject({});\n }\n if (typeof name !== 'undefined') {\n this.parser.onkey(name);\n }\n };\n }\n}\n"],"file":"streaming-json-parser.js"}
@@ -1,7 +1,7 @@
1
1
  import { geojsonToBinary } from '@loaders.gl/gis';
2
2
  import parseJSONSync from './lib/parse-json';
3
3
  import parseJSONInBatches from './lib/parse-json-in-batches';
4
- const VERSION = typeof "3.0.9" !== 'undefined' ? "3.0.9" : 'latest';
4
+ const VERSION = typeof "3.0.13" !== 'undefined' ? "3.0.13" : 'latest';
5
5
  const DEFAULT_GEOJSON_LOADER_OPTIONS = {
6
6
  geojson: {
7
7
  shape: 'object-row-table'
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/geojson-loader.ts"],"names":["geojsonToBinary","parseJSONSync","parseJSONInBatches","VERSION","DEFAULT_GEOJSON_LOADER_OPTIONS","geojson","shape","json","jsonpaths","gis","format","GeoJSONWorkerLoader","name","id","module","version","worker","extensions","mimeTypes","category","text","options","GeoJSONLoader","parse","parseTextSync","parseInBatches","arrayBuffer","TextDecoder","decode","asyncIterator","geojsonIterator","makeBinaryGeometryIterator","batch","data"],"mappings":"AAEA,SAAQA,eAAR,QAA8B,iBAA9B;AACA,OAAOC,aAAP,MAA0B,kBAA1B;AACA,OAAOC,kBAAP,MAA+B,6BAA/B;AAIA,MAAMC,OAAO,GAAG,mBAAuB,WAAvB,aAAmD,QAAnE;AAWA,MAAMC,8BAA8B,GAAG;AACrCC,EAAAA,OAAO,EAAE;AACPC,IAAAA,KAAK,EAAE;AADA,GAD4B;AAIrCC,EAAAA,IAAI,EAAE;AACJC,IAAAA,SAAS,EAAE,CAAC,GAAD,EAAM,YAAN;AADP,GAJ+B;AAOrCC,EAAAA,GAA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CAACO,IAAD,CAAtB;;AACF;AACE,aAAOA,IAAP;AAJJ;AAMD;;AAED,SAASkB,cAAT,CAAwBI,aAAxB,EAAuCR,OAAvC,EAAoE;AAElEA,EAAAA,OAAO,GAAG,EAAC,GAAGjB,8BAAJ;AAAoC,OAAGiB;AAAvC,GAAV;AACAA,EAAAA,OAAO,CAACd,IAAR,GAAe,EAAC,GAAGH,8BAA8B,CAACC,OAAnC;AAA4C,OAAGgB,OAAO,CAAChB;AAAvD,GAAf;AAEA,QAAMyB,eAAe,GAAG5B,kBAAkB,CAAC2B,aAAD,EAAgBR,OAAhB,CAA1C;;AAEA,UAAQA,OAAO,CAACZ,GAAR,CAAYC,MAApB;AACE,SAAK,QAAL;AACE,aAAOqB,0BAA0B,CAACD,eAAD,CAAjC;;AACF;AACE,aAAOA,eAAP;AAJJ;AAMD;;AAED,gBAAgBC,0BAAhB,CAA2CD,eAA3C,EAA4D;AAC1D,aAAW,MAAME,KAAjB,IAA0BF,eAA1B,EAA2C;AACzCE,IAAAA,KAAK,CAACC,IAAN,GAAajC,eAAe,CAACgC,KAAK,CAACC,IAAP,CAA5B;AACA,UAAMD,KAAN;AACD;AACF","sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {JSONLoaderOptions} from './json-loader';\nimport {geojsonToBinary} from '@loaders.gl/gis';\nimport parseJSONSync from './lib/parse-json';\nimport parseJSONInBatches from './lib/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';\n };\n};\n\nconst DEFAULT_GEOJSON_LOADER_OPTIONS = {\n geojson: {\n shape: 'object-row-table'\n },\n json: {\n jsonpaths: ['$', '$.features']\n },\n gis: {\n format: 'geojson'\n }\n};\n\n/**\n * GeoJSON loader\n */\nexport const GeoJSONWorkerLoader: Loader = {\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: DEFAULT_GEOJSON_LOADER_OPTIONS\n};\n\nexport const GeoJSONLoader: LoaderWithParser = {\n ...GeoJSONWorkerLoader,\n parse,\n parseTextSync,\n parseInBatches\n};\n\nasync function parse(arrayBuffer, options) {\n return parseTextSync(new TextDecoder().decode(arrayBuffer), options);\n}\n\nfunction parseTextSync(text, options) {\n // Apps can call the parse method directly, we so apply default options here\n options = {...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options};\n options.json = {...DEFAULT_GEOJSON_LOADER_OPTIONS.geojson, ...options.geojson};\n options.gis = options.gis || {};\n const json = parseJSONSync(text, options);\n switch (options.gis.format) {\n case 'binary':\n return geojsonToBinary(json);\n default:\n return json;\n }\n}\n\nfunction parseInBatches(asyncIterator, options): AsyncIterable<any> {\n // Apps can call the parse method directly, we so apply default options here\n options = {...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options};\n options.json = {...DEFAULT_GEOJSON_LOADER_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;\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"],"file":"geojson-loader.js"}
1
+ {"version":3,"sources":["../../src/geojson-loader.ts"],"names":["geojsonToBinary","parseJSONSync","parseJSONInBatches","VERSION","DEFAULT_GEOJSON_LOADER_OPTIONS","geojson","shape","json","jsonpaths","gis","format","GeoJSONWorkerLoader","name","id","module","version","worker","extensions","mimeTypes","category","text","options","GeoJSONLoader","parse","parseTextSync","parseIn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EAA6BC,OAA7B,EAAsC;AAEpCA,EAAAA,OAAO,GAAG,EAAC,GAAGjB,8BAAJ;AAAoC,OAAGiB;AAAvC,GAAV;AACAA,EAAAA,OAAO,CAACd,IAAR,GAAe,EAAC,GAAGH,8BAA8B,CAACC,OAAnC;AAA4C,OAAGgB,OAAO,CAAChB;AAAvD,GAAf;AACAgB,EAAAA,OAAO,CAACZ,GAAR,GAAcY,OAAO,CAACZ,GAAR,IAAe,EAA7B;AACA,QAAMF,IAAI,GAAGN,aAAa,CAACmB,IAAD,EAAOC,OAAP,CAA1B;;AACA,UAAQA,OAAO,CAACZ,GAAR,CAAYC,MAApB;AACE,SAAK,QAAL;AACE,aAAOV,eAAe,CAACO,IAAD,CAAtB;;AACF;AACE,aAAOA,IAAP;AAJJ;AAMD;;AAED,SAASkB,cAAT,CAAwBI,aAAxB,EAAuCR,OAAvC,EAAoE;AAElEA,EAAAA,OAAO,GAAG,EAAC,GAAGjB,8BAAJ;AAAoC,OAAGiB;AAAvC,GAAV;AACAA,EAAAA,OAAO,CAACd,IAAR,GAAe,EAAC,GAAGH,8BAA8B,CAACC,OAAnC;AAA4C,OAAGgB,OAAO,CAAChB;AAAvD,GAAf;AAEA,QAAMyB,eAAe,GAAG5B,kBAAkB,CAAC2B,aAAD,EAAgBR,OAAhB,CAA1C;;AAEA,UAAQA,OAAO,CAACZ,GAAR,CAAYC,MAApB;AACE,SAAK,QAAL;AACE,aAAOqB,0BAA0B,CAACD,eAAD,CAAjC;;AACF;AACE,aAAOA,eAAP;AAJJ;AAMD;;AAED,gBAAgBC,0BAAhB,CAA2CD,eAA3C,EAA4D;AAC1D,aAAW,MAAME,KAAjB,IAA0BF,eAA1B,EAA2C;AACzCE,IAAAA,KAAK,CAACC,IAAN,GAAajC,eAAe,CAACgC,KAAK,CAACC,IAAP,CAA5B;AACA,UAAMD,KAAN;AACD;AACF","sourcesContent":["import type {Loader, LoaderWithParser} from '@loaders.gl/loader-utils';\nimport type {JSONLoaderOptions} from './json-loader';\nimport {geojsonToBinary} from '@loaders.gl/gis';\nimport parseJSONSync from './lib/parse-json';\nimport parseJSONInBatches from './lib/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';\n };\n};\n\nconst DEFAULT_GEOJSON_LOADER_OPTIONS = {\n geojson: {\n shape: 'object-row-table'\n },\n json: {\n jsonpaths: ['$', '$.features']\n },\n gis: {\n format: 'geojson'\n }\n};\n\n/**\n * GeoJSON loader\n */\nexport const GeoJSONWorkerLoader: Loader = {\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: DEFAULT_GEOJSON_LOADER_OPTIONS\n};\n\nexport const GeoJSONLoader: LoaderWithParser = {\n ...GeoJSONWorkerLoader,\n parse,\n parseTextSync,\n parseInBatches\n};\n\nasync function parse(arrayBuffer, options) {\n return parseTextSync(new TextDecoder().decode(arrayBuffer), options);\n}\n\nfunction parseTextSync(text, options) {\n // Apps can call the parse method directly, we so apply default options here\n options = {...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options};\n options.json = {...DEFAULT_GEOJSON_LOADER_OPTIONS.geojson, ...options.geojson};\n options.gis = options.gis || {};\n const json = parseJSONSync(text, options);\n switch (options.gis.format) {\n case 'binary':\n return geojsonToBinary(json);\n default:\n return json;\n }\n}\n\nfunction parseInBatches(asyncIterator, options): AsyncIterable<any> {\n // Apps can call the parse method directly, we so apply default options here\n options = {...DEFAULT_GEOJSON_LOADER_OPTIONS, ...options};\n options.json = {...DEFAULT_GEOJSON_LOADER_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;\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"],"file":"geojson-loader.js"}
@@ -1,6 +1,6 @@
1
1
  import parseJSONSync from './lib/parse-json';
2
2
  import parseJSONInBatches from './lib/parse-json-in-batches';
3
- const VERSION = typeof "3.0.9" !== 'undefined' ? "3.0.9" : 'latest';
3
+ const VERSION = typeof "3.0.13" !== 'undefined' ? "3.0.13" : 'latest';
4
4
  const DEFAULT_JSON_LOADER_OPTIONS = {
5
5
  json: {
6
6
  shape: 'row-table',
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/json-loader.ts"],"names":["parseJSONSync","parseJSONInBatches","VERSION","DEFAULT_JSON_LOADER_OPTIONS","json","shape","table","jsonpaths","JSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parse","parseTextSync","parseInBatches","options","arrayBuffer","TextDecoder","decode","jsonOptions","asyncIterator"],"mappings":"AAEA,OAAOA,aAAP,MAA0B,kBAA1B;AACA,OAAOC,kBAAP,MAA+B,6BAA/B;AAIA,MAAMC,OAAO,GAAG,mBAAuB,WAAvB,aAAmD,QAAnE;AAcA,MAAMC,2BAA2B,GAAG;AAClCC,EAAAA,IAAI,EAAE;AACJC,IAAAA,KAAK,EAAE,WADH;AAEJC,IAAAA,KAAK,EAAE,KAFH;AAGJC,IAAAA,SAAS,EAAE;AAHP;AAD4B,CAApC;AASA,OAAO,MAAMC,UAA4B,GAAG;AAC1CC,EAAAA,IAAI,EAAE,MADoC;AAE1CC,EAAAA,EAAE,EAAE,MAFsC;AAG1CC,EAAAA,MAAM,EAAE,MAHkC;AAI1CC,EAAAA,OAAO,EAAEV,OAJiC;AAK1CW,EAAAA,UAAU,EAAE,CAAC,MAAD,EAAS,SAAT,CAL8B;AAM1CC,EAAAA,SAAS,EAAE,CAAC,kBAAD,CAN+B;AAoB1CC,EAAAA,QAAQ,EAAE,OApBgC;AAqB1CC,EAAAA,IAAI,EAAE,IArBoC;AAsB1CC,EAAAA,KAtB0C;AAuB1CC,EAAAA,aAvB0C;AAwB1CC,EAAAA,cAxB0C;AAyB1CC,EAAAA,OAAO,EAAEjB;AAzBiC,CAArC;;AA4BP,eAAec,KAAf,CAAqBI,WAArB,EAA+CD,OAA/C,EAA4E;AAC1E,SAAOF,aAAa,CAAC,IAAII,WAAJ,GAAkBC,MAAlB,CAAyBF,WAAzB,CAAD,EAAwCD,OAAxC,CAApB;AACD;;AAED,SAASF,aAAT,CAAuBF,IAAvB,EAAqCI,OAArC,EAAkE;AAChE,QAAMI,WAAW,GAAG,EAAC,GAAGJ,OAAJ;AAAahB,IAAAA,IAAI,EAAE,EAAC,GAAGD,2BAA2B,CAACC,IAAhC;AAAsC,UAAGgB,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEhB,IAAZ;AAAtC;AAAnB,GAApB;AACA,SAAOJ,aAAa,CAACgB,IAAD,EAAOQ,WAAP,CAApB;AACD;;AAED,SAASL,cAAT,CACEM,aADF,EAEEL,OAFF,EAGwB;AACtB,QAAMI,WAAW,GAAG,EAAC,GAAGJ,OAAJ;AAAahB,IAAAA,IAAI,EAAE,EAAC,GAAGD,2BAA2B,CAACC,IAAhC;AAAsC,UAAGgB,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEhB,IAAZ;AAAtC;AAAnB,GAApB;AACA,SAAOH,kBAAkB,CAACwB,aAAD,EAAgBD,WAAhB,CAAzB;AACD","sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport parseJSONSync from './lib/parse-json';\nimport parseJSONInBatches from './lib/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\n/**\n * @param table -\n * @param jsonpaths -\n */\nexport type JSONLoaderOptions = LoaderOptions & {\n json?: {\n shape?: 'row-table';\n table?: false;\n jsonpaths?: string[];\n };\n};\n\nconst DEFAULT_JSON_LOADER_OPTIONS = {\n json: {\n shape: 'row-table',\n table: false,\n jsonpaths: []\n // batchSize: 'auto'\n }\n};\n\nexport const JSONLoader: LoaderWithParser = {\n name: 'JSON',\n id: 'json',\n module: 'json',\n version: VERSION,\n extensions: ['json', 'geojson'],\n mimeTypes: ['application/json'],\n // TODO - support various line based JSON formats\n /*\n extensions: {\n json: null,\n jsonl: {stream: true},\n ndjson: {stream: true}\n },\n mimeTypes: {\n 'application/json': null,\n 'application/json-seq': {stream: true},\n 'application/x-ndjson': {stream: true}\n },\n */\n category: 'table',\n text: true,\n parse,\n parseTextSync,\n parseInBatches,\n options: DEFAULT_JSON_LOADER_OPTIONS\n};\n\nasync function parse(arrayBuffer: ArrayBuffer, options?: JSONLoaderOptions) {\n return parseTextSync(new TextDecoder().decode(arrayBuffer), options);\n}\n\nfunction parseTextSync(text: string, options?: JSONLoaderOptions) {\n const jsonOptions = {...options, json: {...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json}};\n return parseJSONSync(text, jsonOptions as JSONLoaderOptions);\n}\n\nfunction parseInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: JSONLoaderOptions\n): AsyncIterable<Batch> {\n const jsonOptions = {...options, json: {...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json}};\n return parseJSONInBatches(asyncIterator, jsonOptions as JSONLoaderOptions);\n}\n"],"file":"json-loader.js"}
1
+ {"version":3,"sources":["../../src/json-loader.ts"],"names":["parseJSONSync","parseJSONInBatches","VERSION","DEFAULT_JSON_LOADER_OPTIONS","json","shape","table","jsonpaths","JSONLoader","name","id","module","version","extensions","mimeTypes","category","text","parse","parseTextSync","parseInBatches","options","arrayB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CAACgB,IAAD,EAAOQ,WAAP,CAApB;AACD;;AAED,SAASL,cAAT,CACEM,aADF,EAEEL,OAFF,EAGwB;AACtB,QAAMI,WAAW,GAAG,EAAC,GAAGJ,OAAJ;AAAahB,IAAAA,IAAI,EAAE,EAAC,GAAGD,2BAA2B,CAACC,IAAhC;AAAsC,UAAGgB,OAAH,aAAGA,OAAH,uBAAGA,OAAO,CAAEhB,IAAZ;AAAtC;AAAnB,GAApB;AACA,SAAOH,kBAAkB,CAACwB,aAAD,EAAgBD,WAAhB,CAAzB;AACD","sourcesContent":["import type {Batch} from '@loaders.gl/schema';\nimport type {LoaderWithParser, LoaderOptions} from '@loaders.gl/loader-utils';\nimport parseJSONSync from './lib/parse-json';\nimport parseJSONInBatches from './lib/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\n/**\n * @param table -\n * @param jsonpaths -\n */\nexport type JSONLoaderOptions = LoaderOptions & {\n json?: {\n shape?: 'row-table';\n table?: false;\n jsonpaths?: string[];\n };\n};\n\nconst DEFAULT_JSON_LOADER_OPTIONS = {\n json: {\n shape: 'row-table',\n table: false,\n jsonpaths: []\n // batchSize: 'auto'\n }\n};\n\nexport const JSONLoader: LoaderWithParser = {\n name: 'JSON',\n id: 'json',\n module: 'json',\n version: VERSION,\n extensions: ['json', 'geojson'],\n mimeTypes: ['application/json'],\n // TODO - support various line based JSON formats\n /*\n extensions: {\n json: null,\n jsonl: {stream: true},\n ndjson: {stream: true}\n },\n mimeTypes: {\n 'application/json': null,\n 'application/json-seq': {stream: true},\n 'application/x-ndjson': {stream: true}\n },\n */\n category: 'table',\n text: true,\n parse,\n parseTextSync,\n parseInBatches,\n options: DEFAULT_JSON_LOADER_OPTIONS\n};\n\nasync function parse(arrayBuffer: ArrayBuffer, options?: JSONLoaderOptions) {\n return parseTextSync(new TextDecoder().decode(arrayBuffer), options);\n}\n\nfunction parseTextSync(text: string, options?: JSONLoaderOptions) {\n const jsonOptions = {...options, json: {...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json}};\n return parseJSONSync(text, jsonOptions as JSONLoaderOptions);\n}\n\nfunction parseInBatches(\n asyncIterator: AsyncIterable<ArrayBuffer> | Iterable<ArrayBuffer>,\n options?: JSONLoaderOptions\n): AsyncIterable<Batch> {\n const jsonOptions = {...options, json: {...DEFAULT_JSON_LOADER_OPTIONS.json, ...options?.json}};\n return parseJSONInBatches(asyncIterator, jsonOptions as JSONLoaderOptions);\n}\n"],"file":"json-loader.js"}