@loaders.gl/json 3.0.12 → 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.
- package/dist/dist.es5.min.js +1 -1
- package/dist/dist.es5.min.js.map +1 -1
- package/dist/dist.min.js +1 -1
- package/dist/es5/bundle.js +2 -2
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/geojson-loader.js +29 -143
- package/dist/es5/geojson-loader.js.map +1 -1
- package/dist/es5/index.js +5 -5
- package/dist/es5/json-loader.js +18 -44
- package/dist/es5/json-loader.js.map +1 -1
- package/dist/es5/lib/clarinet/clarinet.js +373 -393
- package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
- package/dist/es5/lib/jsonpath/jsonpath.js +54 -101
- package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
- package/dist/es5/lib/parse-json-in-batches.js +78 -237
- package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
- package/dist/es5/lib/parse-json.js +4 -9
- package/dist/es5/lib/parse-json.js.map +1 -1
- package/dist/es5/lib/parser/json-parser.js +112 -133
- package/dist/es5/lib/parser/json-parser.js.map +1 -1
- package/dist/es5/lib/parser/streaming-json-parser.js +65 -125
- package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
- package/dist/esm/geojson-loader.js +1 -1
- package/dist/esm/json-loader.js +1 -1
- package/dist/geojson-worker.js +1 -1
- package/dist/geojson-worker.js.map +1 -1
- package/package.json +5 -5
|
@@ -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
|
-
|
|
21
|
-
|
|
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
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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","
|
|
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,EAA0B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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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
29
|
+
write(chunk) {
|
|
30
|
+
super.write(chunk);
|
|
31
|
+
let array = [];
|
|
44
32
|
|
|
45
|
-
|
|
33
|
+
if (this.streamingArray) {
|
|
34
|
+
array = [...this.streamingArray];
|
|
35
|
+
this.streamingArray.length = 0;
|
|
36
|
+
}
|
|
46
37
|
|
|
47
|
-
|
|
48
|
-
|
|
38
|
+
return array;
|
|
39
|
+
}
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
45
|
+
getStreamingJsonPath() {
|
|
46
|
+
return this.streamingJsonPath;
|
|
47
|
+
}
|
|
63
48
|
|
|
64
|
-
|
|
49
|
+
getStreamingJsonPathAsString() {
|
|
50
|
+
return this.streamingJsonPath && this.streamingJsonPath.toString();
|
|
65
51
|
}
|
|
66
52
|
|
|
67
|
-
(
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
this.streamingArray.length = 0;
|
|
76
|
-
}
|
|
57
|
+
_matchJSONPath() {
|
|
58
|
+
const currentPath = this.getJsonPath();
|
|
77
59
|
|
|
78
|
-
|
|
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
|
-
|
|
64
|
+
for (const jsonPath of this.jsonPaths) {
|
|
65
|
+
if (jsonPath.equals(currentPath)) {
|
|
106
66
|
return true;
|
|
107
67
|
}
|
|
68
|
+
}
|
|
108
69
|
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
113
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
114
|
-
var jsonPath = _step.value;
|
|
80
|
+
this._openArray(this.streamingArray);
|
|
115
81
|
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
+
this.parser.onopenobject = name => {
|
|
90
|
+
if (!this.topLevelObject) {
|
|
91
|
+
this.topLevelObject = {};
|
|
140
92
|
|
|
141
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
98
|
+
if (typeof name !== 'undefined') {
|
|
99
|
+
this.parser.onkey(name);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
156
103
|
|
|
157
|
-
|
|
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","
|
|
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,GA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AAZ,CAAkBF,IAAlB;AACD;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.
|
|
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'
|
package/dist/esm/json-loader.js
CHANGED
|
@@ -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.
|
|
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',
|