@loaders.gl/json 3.1.0-alpha.4 → 3.1.0-beta.3

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 (96) hide show
  1. package/dist/bundle.d.ts +2 -0
  2. package/dist/bundle.d.ts.map +1 -0
  3. package/dist/bundle.js +1839 -0
  4. package/dist/es5/bundle.js +1 -1
  5. package/dist/es5/bundle.js.map +1 -1
  6. package/dist/es5/geojson-loader.js +29 -143
  7. package/dist/es5/geojson-loader.js.map +1 -1
  8. package/dist/es5/index.js +6 -6
  9. package/dist/es5/json-loader.js +18 -44
  10. package/dist/es5/json-loader.js.map +1 -1
  11. package/dist/es5/lib/clarinet/clarinet.js +406 -481
  12. package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
  13. package/dist/es5/lib/jsonpath/jsonpath.js +54 -101
  14. package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
  15. package/dist/es5/lib/parse-json-in-batches.js +78 -237
  16. package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
  17. package/dist/es5/lib/parse-json.js +4 -9
  18. package/dist/es5/lib/parse-json.js.map +1 -1
  19. package/dist/es5/lib/parse-ndjson-in-batches.js +31 -143
  20. package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -1
  21. package/dist/es5/lib/parse-ndjson.js +2 -2
  22. package/dist/es5/lib/parse-ndjson.js.map +1 -1
  23. package/dist/es5/lib/parser/json-parser.js +114 -137
  24. package/dist/es5/lib/parser/json-parser.js.map +1 -1
  25. package/dist/es5/lib/parser/streaming-json-parser.js +63 -128
  26. package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
  27. package/dist/es5/ndjson-loader.js +11 -30
  28. package/dist/es5/ndjson-loader.js.map +1 -1
  29. package/dist/esm/geojson-loader.js +1 -1
  30. package/dist/esm/geojson-loader.js.map +1 -1
  31. package/dist/esm/json-loader.js +1 -1
  32. package/dist/esm/json-loader.js.map +1 -1
  33. package/dist/esm/lib/clarinet/clarinet.js +222 -260
  34. package/dist/esm/lib/clarinet/clarinet.js.map +1 -1
  35. package/dist/esm/lib/parse-ndjson-in-batches.js +1 -1
  36. package/dist/esm/lib/parse-ndjson-in-batches.js.map +1 -1
  37. package/dist/esm/lib/parse-ndjson.js +1 -1
  38. package/dist/esm/lib/parse-ndjson.js.map +1 -1
  39. package/dist/esm/lib/parser/json-parser.js +48 -47
  40. package/dist/esm/lib/parser/json-parser.js.map +1 -1
  41. package/dist/esm/lib/parser/streaming-json-parser.js +29 -34
  42. package/dist/esm/lib/parser/streaming-json-parser.js.map +1 -1
  43. package/dist/esm/ndjson-loader.js +3 -1
  44. package/dist/esm/ndjson-loader.js.map +1 -1
  45. package/dist/geojson-loader.d.ts +16 -0
  46. package/dist/geojson-loader.d.ts.map +1 -0
  47. package/dist/geojson-loader.js +78 -0
  48. package/dist/geojson-worker.js +1702 -2
  49. package/dist/index.d.ts +8 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +17 -0
  52. package/dist/json-loader.d.ts +14 -0
  53. package/dist/json-loader.d.ts.map +1 -0
  54. package/dist/json-loader.js +57 -0
  55. package/dist/jsonl-loader.d.ts +1 -0
  56. package/dist/jsonl-loader.d.ts.map +1 -0
  57. package/dist/jsonl-loader.js +54 -0
  58. package/dist/lib/clarinet/clarinet.d.ts +74 -0
  59. package/dist/lib/clarinet/clarinet.d.ts.map +1 -0
  60. package/dist/lib/clarinet/clarinet.js +535 -0
  61. package/dist/lib/jsonpath/jsonpath.d.ts +32 -0
  62. package/dist/lib/jsonpath/jsonpath.d.ts.map +1 -0
  63. package/dist/lib/jsonpath/jsonpath.js +89 -0
  64. package/dist/lib/parse-json-in-batches.d.ts +4 -0
  65. package/dist/lib/parse-json-in-batches.d.ts.map +1 -0
  66. package/dist/lib/parse-json-in-batches.js +80 -0
  67. package/dist/lib/parse-json.d.ts +3 -0
  68. package/dist/lib/parse-json.d.ts.map +1 -0
  69. package/dist/lib/parse-json.js +29 -0
  70. package/dist/lib/parse-ndjson-in-batches.d.ts +4 -0
  71. package/dist/lib/parse-ndjson-in-batches.d.ts.map +1 -0
  72. package/dist/lib/parse-ndjson-in-batches.js +35 -0
  73. package/dist/lib/parse-ndjson.d.ts +2 -0
  74. package/dist/lib/parse-ndjson.d.ts.map +1 -0
  75. package/dist/lib/parse-ndjson.js +14 -0
  76. package/dist/lib/parser/json-parser.d.ts +22 -0
  77. package/dist/lib/parser/json-parser.d.ts.map +1 -0
  78. package/dist/lib/parser/json-parser.js +98 -0
  79. package/dist/lib/parser/streaming-json-parser.d.ts +37 -0
  80. package/dist/lib/parser/streaming-json-parser.d.ts.map +1 -0
  81. package/dist/lib/parser/streaming-json-parser.js +100 -0
  82. package/dist/ndjson-loader.d.ts +22 -0
  83. package/dist/ndjson-loader.d.ts.map +1 -0
  84. package/dist/ndjson-loader.js +35 -0
  85. package/dist/workers/geojson-worker.d.ts +2 -0
  86. package/dist/workers/geojson-worker.d.ts.map +1 -0
  87. package/dist/workers/geojson-worker.js +5 -0
  88. package/package.json +8 -8
  89. package/src/lib/clarinet/clarinet.ts +539 -0
  90. package/src/lib/parser/json-parser.ts +52 -55
  91. package/src/lib/parser/streaming-json-parser.ts +28 -32
  92. package/src/ndjson-loader.ts +3 -1
  93. package/dist/dist.min.js +0 -2
  94. package/dist/dist.min.js.map +0 -1
  95. package/dist/geojson-worker.js.map +0 -1
  96. package/src/lib/clarinet/clarinet.js +0 -578
@@ -7,154 +7,131 @@ 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);
23
- (0, _defineProperty2.default)(this, "jsonpath", void 0);
24
- (0, _defineProperty2.default)(this, "_parser", void 0);
16
+ class JSONParser {
17
+ constructor(options) {
18
+ (0, _defineProperty2.default)(this, "parser", void 0);
19
+ (0, _defineProperty2.default)(this, "result", undefined);
20
+ (0, _defineProperty2.default)(this, "previousStates", []);
21
+ (0, _defineProperty2.default)(this, "currentState", Object.freeze({
22
+ container: [],
23
+ key: null
24
+ }));
25
+ (0, _defineProperty2.default)(this, "jsonpath", new _jsonpath.default());
25
26
  this.reset();
27
+ this.parser = new _clarinet.default({
28
+ onready: () => {
29
+ this.jsonpath = new _jsonpath.default();
30
+ this.previousStates.length = 0;
31
+ this.currentState.container.length = 0;
32
+ },
33
+ onopenobject: name => {
34
+ this._openObject({});
35
+
36
+ if (typeof name !== 'undefined') {
37
+ this.parser.emit('onkey', name);
38
+ }
39
+ },
40
+ onkey: name => {
41
+ this.jsonpath.set(name);
42
+ this.currentState.key = name;
43
+ },
44
+ oncloseobject: () => {
45
+ this._closeObject();
46
+ },
47
+ onopenarray: () => {
48
+ this._openArray();
49
+ },
50
+ onclosearray: () => {
51
+ this._closeArray();
52
+ },
53
+ onvalue: value => {
54
+ this._pushOrSet(value);
55
+ },
56
+ onerror: error => {
57
+ throw error;
58
+ },
59
+ onend: () => {
60
+ this.result = this.currentState.container.pop();
61
+ },
62
+ ...options
63
+ });
64
+ }
26
65
 
27
- this._initializeParser();
66
+ reset() {
67
+ this.result = undefined;
68
+ this.previousStates = [];
69
+ this.currentState = Object.freeze({
70
+ container: [],
71
+ key: null
72
+ });
73
+ this.jsonpath = new _jsonpath.default();
28
74
  }
29
75
 
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();
106
- }
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();
147
- }
148
- });
149
- }
150
- }, {
151
- key: "parser",
152
- get: function get() {
153
- return this._parser;
76
+ write(chunk) {
77
+ this.parser.write(chunk);
78
+ }
79
+
80
+ close() {
81
+ this.parser.close();
82
+ }
83
+
84
+ _pushOrSet(value) {
85
+ const {
86
+ container,
87
+ key
88
+ } = this.currentState;
89
+
90
+ if (key !== null) {
91
+ container[key] = value;
92
+ this.currentState.key = null;
93
+ } else {
94
+ container.push(value);
154
95
  }
155
- }]);
156
- return JSONParser;
157
- }();
96
+ }
97
+
98
+ _openArray(newContainer = []) {
99
+ this.jsonpath.push(null);
100
+
101
+ this._pushOrSet(newContainer);
102
+
103
+ this.previousStates.push(this.currentState);
104
+ this.currentState = {
105
+ container: newContainer,
106
+ isArray: true,
107
+ key: null
108
+ };
109
+ }
110
+
111
+ _closeArray() {
112
+ this.jsonpath.pop();
113
+ this.currentState = this.previousStates.pop();
114
+ }
115
+
116
+ _openObject(newContainer = {}) {
117
+ this.jsonpath.push(null);
118
+
119
+ this._pushOrSet(newContainer);
120
+
121
+ this.previousStates.push(this.currentState);
122
+ this.currentState = {
123
+ container: newContainer,
124
+ isArray: false,
125
+ key: null
126
+ };
127
+ }
128
+
129
+ _closeObject() {
130
+ this.jsonpath.pop();
131
+ this.currentState = this.previousStates.pop();
132
+ }
133
+
134
+ }
158
135
 
159
136
  exports.default = JSONParser;
160
137
  //# 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;AAChBD,QAAAA,SAAS,CAACC,GAAD,CAAT,GAAiBO,KAAjB;AACA,aAAKX,YAAL,CAAkBI,GAAlB,GAAwB,IAAxB;AACD,OAHD,MAGO;AACLD,QAAAA,SAAS,CAACS,IAAV,CAAeD,KAAf;AACD;AACF;;;WAED,sBAAoC;AAAA,UAAzBE,YAAyB,uEAAV,EAAU;AAClC,WAAKR,QAAL,CAAcO,IAAd,CAAmB,IAAnB;;AACA,WAAKE,UAAL,CAAgBD,YAAhB;;AACA,WA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KAAZ,CAAkBF,IAAlB;AACD;AACF,SAZ+B;AAchCE,QAAAA,KAAK,EAAE,eAACF,IAAD,EAAU;AACf,UAAA,KAAI,CAACjB,QAAL,CAAcoB,GAAd,CAAkBH,IAAlB;;AACA,UAAA,KAAI,CAACtB,YAAL,CAAkBI,GAAlB,GAAwBkB,IAAxB;AACD,SAjB+B;AAmBhCI,QAAAA,aAAa,EAAE,yBAAM;AACnB,UAAA,KAAI,CAACC,YAAL;AACD,SArB+B;AAuBhCC,QAAAA,WAAW,EAAE,uBAAM;AACjB,UAAA,KAAI,CAACC,UAAL;AACD,SAzB+B;AA2BhCC,QAAAA,YAAY,EAAE,wBAAM;AAClB,UAAA,KAAI,CAACC,WAAL;AACD,SA7B+B;AA+BhCC,QAAAA,OAAO,EAAE,iBAACrB,KAAD,EAAW;AAClB,UAAA,KAAI,CAACG,UAAL,CAAgBH,KAAhB;AACD,SAjC+B;AAmChCsB,QAAAA,OAAO,EAAE,iBAACC,KAAD,EAAW;AAClB,gBAAMA,KAAN;AACD,SArC+B;AAuChCC,QAAAA,KAAK,EAAE,iBAAM;AACX,UAAA,KAAI,CAACtC,MAAL,GAAc,KAAI,CAACG,YAAL,CAAkBG,SAAlB,CAA4Ba,GAA5B,EAAd;AACD;AAzC+B,OAAnB,CAAf;AA2CD;;;SAED,eAAuC;AACrC,aAAO,KAAKC,OAAZ;AACD","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"}
1
+ {"version":3,"sources":["../../../../src/lib/parser/json-parser.ts"],"names":["JSONParser","constructor","options","undefined","Object","freeze","container","key","JSONPath","reset","parser","ClarinetParser","onready","jsonpath","previousStates","length","currentState","onopenobject","name","_openObject","emit","onkey","set","oncloseobject","_closeObject","onopenarray","_openArray","onclosearray","_closeArray","onvalue","value","_pushOrSet","onerror","error","onend","result","pop","write","chunk","close","push","newContainer","isArray"],"mappings":";;;;;;;;;;;AAEA;;AACA;;AAIe,MAAMA,UA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A,OAAO,EAAE,IAAnC;AAAyCnC,MAAAA,GAAG,EAAE;AAA9C,KAApB;AACD;;AAEDqB,EAAAA,WAAW,GAAS;AAClB,SAAKf,QAAL,CAAcuB,GAAd;AACA,SAAKpB,YAAL,GAAoB,KAAKF,cAAL,CAAoBsB,GAApB,EAApB;AACD;;AAEDjB,EAAAA,WAAW,CAACsB,YAAY,GAAG,EAAhB,EAA0B;AACnC,SAAK5B,QAAL,CAAc2B,IAAd,CAAmB,IAAnB;;AACA,SAAKT,UAAL,CAAgBU,YAAhB;;AACA,SAAK3B,cAAL,CAAoB0B,IAApB,CAAyB,KAAKxB,YAA9B;AACA,SAAKA,YAAL,GAAoB;AAACV,MAAAA,SAAS,EAAEmC,YAAZ;AAA0BC,MAAAA,OAAO,EAAE,KAAnC;AAA0CnC,MAAAA,GAAG,EAAE;AAA/C,KAApB;AACD;;AAEDiB,EAAAA,YAAY,GAAS;AACnB,SAAKX,QAAL,CAAcuB,GAAd;AACA,SAAKpB,YAAL,GAAoB,KAAKF,cAAL,CAAoBsB,GAApB,EAApB;AACD;;AAzG6B","sourcesContent":["// @ts-nocheck\n\nimport ClarinetParser, {ClarinetParserOptions} 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 readonly parser: ClarinetParser;\n result = undefined;\n previousStates = [];\n currentState = Object.freeze({container: [], key: null});\n jsonpath: JSONPath = new JSONPath();\n\n constructor(options: ClarinetParserOptions) {\n this.reset();\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.emit('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 ...options\n });\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"],"file":"json-parser.js"}
@@ -7,161 +7,96 @@ 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; } } }; }
16
+ class StreamingJSONParser extends _jsonParser.default {
17
+ constructor(options = {}) {
18
+ super({
19
+ onopenarray: () => {
20
+ if (!this.streamingArray) {
21
+ if (this._matchJSONPath()) {
22
+ this.streamingJsonPath = this.getJsonPath().clone();
23
+ this.streamingArray = [];
33
24
 
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); }
25
+ this._openArray(this.streamingArray);
35
26
 
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; }
27
+ return;
28
+ }
29
+ }
37
30
 
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); }; }
31
+ this._openArray();
32
+ },
33
+ onopenobject: name => {
34
+ if (!this.topLevelObject) {
35
+ this.topLevelObject = {};
39
36
 
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; } }
37
+ this._openObject(this.topLevelObject);
38
+ } else {
39
+ this._openObject({});
40
+ }
41
41
 
42
- var StreamingJSONParser = function (_JSONParser) {
43
- (0, _inherits2.default)(StreamingJSONParser, _JSONParser);
42
+ if (typeof name !== 'undefined') {
43
+ this.parser.emit('onkey', name);
44
+ }
45
+ }
46
+ });
47
+ (0, _defineProperty2.default)(this, "jsonPaths", void 0);
48
+ (0, _defineProperty2.default)(this, "streamingJsonPath", null);
49
+ (0, _defineProperty2.default)(this, "streamingArray", null);
50
+ (0, _defineProperty2.default)(this, "topLevelObject", null);
51
+ const jsonpaths = options.jsonpaths || [];
52
+ this.jsonPaths = jsonpaths.map(jsonpath => new _jsonpath.default(jsonpath));
53
+ }
44
54
 
45
- var _super = _createSuper(StreamingJSONParser);
55
+ write(chunk) {
56
+ super.write(chunk);
57
+ let array = [];
46
58
 
47
- function StreamingJSONParser() {
48
- var _this;
59
+ if (this.streamingArray) {
60
+ array = [...this.streamingArray];
61
+ this.streamingArray.length = 0;
62
+ }
49
63
 
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
- });
64
+ return array;
65
+ }
61
66
 
62
- _this._extendParser();
67
+ getPartialResult() {
68
+ return this.topLevelObject;
69
+ }
63
70
 
64
- return _this;
71
+ getStreamingJsonPath() {
72
+ return this.streamingJsonPath;
65
73
  }
66
74
 
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 = [];
75
+ getStreamingJsonPathAsString() {
76
+ return this.streamingJsonPath && this.streamingJsonPath.toString();
77
+ }
72
78
 
73
- if (this.streamingArray) {
74
- array = (0, _toConsumableArray2.default)(this.streamingArray);
75
- this.streamingArray.length = 0;
76
- }
79
+ getJsonPath() {
80
+ return this.jsonpath;
81
+ }
77
82
 
78
- return array;
79
- }
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;
83
+ _matchJSONPath() {
84
+ const currentPath = this.getJsonPath();
85
+
86
+ if (this.jsonPaths.length === 0) {
87
+ return true;
99
88
  }
100
- }, {
101
- key: "_matchJSONPath",
102
- value: function _matchJSONPath() {
103
- var currentPath = this.getJsonPath();
104
89
 
105
- if (this.jsonPaths.length === 0) {
90
+ for (const jsonPath of this.jsonPaths) {
91
+ if (jsonPath.equals(currentPath)) {
106
92
  return true;
107
93
  }
108
-
109
- var _iterator = _createForOfIteratorHelper(this.jsonPaths),
110
- _step;
111
-
112
- try {
113
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
114
- var jsonPath = _step.value;
115
-
116
- if (jsonPath.equals(currentPath)) {
117
- return true;
118
- }
119
- }
120
- } catch (err) {
121
- _iterator.e(err);
122
- } finally {
123
- _iterator.f();
124
- }
125
-
126
- return false;
127
94
  }
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 = [];
138
-
139
- _this2._openArray(_this2.streamingArray);
140
95
 
141
- return;
142
- }
143
- }
144
-
145
- _this2._openArray();
146
- };
147
-
148
- this.parser.onopenobject = function (name) {
149
- if (!_this2.topLevelObject) {
150
- _this2.topLevelObject = {};
151
-
152
- _this2._openObject(_this2.topLevelObject);
153
- } else {
154
- _this2._openObject({});
155
- }
96
+ return false;
97
+ }
156
98
 
157
- if (typeof name !== 'undefined') {
158
- _this2.parser.onkey(name);
159
- }
160
- };
161
- }
162
- }]);
163
- return StreamingJSONParser;
164
- }(_jsonParser.default);
99
+ }
165
100
 
166
101
  exports.default = StreamingJSONParser;
167
102
  //# 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;;;WAED,uBAAc;AACZ,aAAO,KAAKT,QAAZ;AACD;;;WAOD,0BAAiB;AACf,UAAMU,WAAW,GAAG,KAAKC,WAAL,EAApB;;AAKA,UAAI,KAAKb,SAAL,CAAeQ,MAAf,KAA0B,CAA9B,EAAiC;AAC/B,eAAO,IAAP;AACD;;AARc,iDAUQ,KAAKR,SAVb;AAAA;;AAAA;AAUf,4DAAuC;AAAA,cAA5Bc,QAA4B;;AACrC,cAAIA,QAAQ,CAACC,MAAT,CAAgBH,WAAhB,CAAJ,EAAkC;AAChC,mBAAO,IAAP;AACD;AACF;AAdc;AAAA;AAAA;AAAA;AAAA;;AAgBf,aAAO,KAAP;AACD;;;WAED,yBAAgB;AAAA;;AAEd,WAAKI,MAAL,CAAYC,WAAZ,GAA0B,YAAM;AAC9B,YAAI,CAAC,MAAI,CAACV,cAAV,EAA0B;AACxB,cAAI,MAAI,CAACW,cAAL,EAAJ,EAA2B;AAEzB,YAAA,MAAI,CAACR,iBAAL,GAAyB,MAAI,CAACG,WAAL,GAAmBM,KAAnB,EAAzB;AACA,YAAA,MAAI,CAACZ,cAAL,GAAsB,EAAtB;;AACA,YAAA,MAAI,CAACa,UAAL,CAAgB,MAAI,CAACb,cAArB;;AACA;AACD;AACF;;AAED,QAAA,MAAI,CAACa,UAAL;AACD,OAZD;;AAeA,WAAKJ,MAAL,CAAYK,YAAZ,GAA2B,UAACC,IAAD,EAAU;AACnC,YAAI,CAAC,MAAI,CAACb,cAAV,EAA0B;AACxB,UAAA,MAAI,CAACA,cAAL,GAAsB,EAAtB;;AACA,UAAA,MAAI,CAACc,WAAL,CAAiB,MAAI,CAACd,cAAtB;AACD,SAHD,MAGO;AACL,UAAA,MAAI,CAACc,WAAL,CAAiB,EAAjB;AACD;;AACD,YAAI,OAAOD,IAAP,KAAgB,WAApB,EAAiC;AAC/B,UAAA,MAAI,CAACN,MAAL,CAAYQ,KAAZ,CAAkBF,IAAlB;AACD;AACF,OAVD;AAWD;;;EAvG8CG,mB","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
+ {"version":3,"sources":["../../../../src/lib/parser/streaming-json-parser.ts"],"names":["StreamingJSONParser","JSONParser","constructor","options","onopenarray","streamingArray","_matchJSONPath","streamingJsonPath","getJsonPath","clone","_openArray","onopenobject","name","topLevelObject","_openObject","parser","emit","jsonpaths","jsonPaths","map","jsonpath","JSONPath","write","chunk","array","length","getPartialResult","getStreamingJsonPath","getStreamingJsonPathAsString","toString","currentPath","jsonPath","equals"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAMe,MAAMA,mBAAN,SAAkCC,mBAAlC,CAA6C;AAM1DC,EAAAA,WAAW,CAACC,OAA6B,GAAG,EAAjC,EAAqC;AAC9C,UAAM;AACJC,MAAAA,WAAW,EAAE,MAAM;AACjB,YAAI,CAAC,KAAKC,cAAV,EAA0B;AACxB,cAAI,KAAKC,cAAL,EAAJ,EAA2B;AAEzB,iBAAKC,iBAAL,GAAyB,KAAKC,WAAL,GAAmBC,KAAnB,EAAzB;AACA,iBAAKJ,cAAL,GAAsB,EAAtB;;AACA,iBAAKK,UAAL,CAAgB,KAAKL,cAArB;;AACA;AACD;AACF;;AAED,aAAKK,UAAL;AACD,OAbG;AAgBJC,MAAAA,YAAY,EAAGC,IAAD,IAAU;AACtB,YAAI,CAAC,KAAKC,cAAV,EAA0B;AACxB,eAAKA,cAAL,GAAsB,EAAtB;;AACA,eAAKC,WAAL,CAAiB,KAAKD,cAAtB;AACD,SAHD,MAGO;AACL,eAAKC,WAAL,CAAiB,EAAjB;AACD;;AACD,YAAI,OAAOF,IAAP,KAAgB,WAApB,EAAiC;AAC/B,eAAKG,MAAL,CAAYC,IAAZ,CAAiB,OAAjB,EAA0BJ,IAA1B;AACD;AACF;AA1BG,KAAN;AAD8C;AAAA,6DAJH,IAIG;AAAA,0DAHT,IAGS;AAAA,0DAFR,IAEQ;AA6B9C,UAAMK,SAAS,GAAGd,OAAO,CAACc,SAAR,IAAqB,EAAvC;AACA,SAAKC,SAAL,GAAiBD,SAAS,CAACE,GAAV,CAAeC,QAAD,IAAc,IAAIC,iBAAJ,CAAaD,QAAb,CAA5B,CAAjB;AACD;;AASDE,EAAAA,KAAK,CAACC,KAAD,EAAQ;AACX,UAAMD,KAAN,CAAYC,KAAZ;AACA,QAAIC,KAAY,GAAG,EAAnB;;AACA,QAAI,KAAKnB,cAAT,EAAyB;AACvBmB,MAAAA,KAAK,GAAG,CAAC,GAAG,KAAKnB,cAAT,CAAR;AACA,WAAKA,cAAL,CAAoBoB,MAApB,GAA6B,CAA7B;AACD;;AACD,WAAOD,KAAP;AACD;;AAODE,EAAAA,gBAAgB,GAAG;AACjB,WAAO,KAAKb,cAAZ;AACD;;AAEDc,EAAAA,oBAAoB,GAAG;AACrB,WAAO,KAAKpB,iBAAZ;AACD;;AAEDqB,EAAAA,4BAA4B,GAAG;AAC7B,WAAO,KAAKrB,iBAAL,IAA0B,KAAKA,iBAAL,CAAuBsB,QAAvB,EAAjC;AACD;;AAEDrB,EAAAA,WAAW,GAAG;AACZ,WAAO,KAAKY,QAAZ;AACD;;AAODd,EAAAA,cAAc,GAAG;AACf,UAAMwB,WAAW,GAAG,KAAKtB,WAAL,EAApB;;AAKA,QAAI,KAAKU,SAAL,CAAeO,MAAf,KAA0B,CAA9B,EAAiC;AAC/B,aAAO,IAAP;AACD;;AAED,SAAK,MAAMM,QAAX,IAAuB,KAAKb,SAA5B,EAAuC;AACrC,UAAIa,QAAQ,CAACC,MAAT,CAAgBF,WAAhB,CAAJ,EAAkC;AAChC,eAAO,IAAP;AACD;AACF;;AAED,WAAO,KAAP;AACD;;AAnGyD","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 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 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.emit('onkey', name);\n }\n }\n });\n const jsonpaths = options.jsonpaths || [];\n this.jsonPaths = jsonpaths.map((jsonpath) => new JSONPath(jsonpath));\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"],"file":"streaming-json-parser.js"}
@@ -5,18 +5,14 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.NDJSONLoader = void 0;
9
-
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
-
12
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
8
+ exports._typecheckNDJSONLoader = exports.NDJSONLoader = void 0;
13
9
 
14
10
  var _parseNdjson = _interopRequireDefault(require("./lib/parse-ndjson"));
15
11
 
16
12
  var _parseNdjsonInBatches = _interopRequireDefault(require("./lib/parse-ndjson-in-batches"));
17
13
 
18
- var VERSION = typeof "3.1.0-alpha.4" !== 'undefined' ? "3.1.0-alpha.4" : 'latest';
19
- var NDJSONLoader = {
14
+ const VERSION = typeof "3.1.0-beta.3" !== 'undefined' ? "3.1.0-beta.3" : 'latest';
15
+ const NDJSONLoader = {
20
16
  name: 'NDJSON',
21
17
  id: 'ndjson',
22
18
  module: 'json',
@@ -25,33 +21,15 @@ var NDJSONLoader = {
25
21
  mimeTypes: ['application/x-ndjson'],
26
22
  category: 'table',
27
23
  text: true,
28
- parse: parse,
29
- parseTextSync: parseTextSync,
30
- parseInBatches: parseInBatches,
24
+ parse,
25
+ parseTextSync,
26
+ parseInBatches,
31
27
  options: {}
32
28
  };
33
29
  exports.NDJSONLoader = NDJSONLoader;
34
30
 
35
- function parse(_x) {
36
- return _parse.apply(this, arguments);
37
- }
38
-
39
- function _parse() {
40
- _parse = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(arrayBuffer) {
41
- return _regenerator.default.wrap(function _callee$(_context) {
42
- while (1) {
43
- switch (_context.prev = _context.next) {
44
- case 0:
45
- return _context.abrupt("return", parseTextSync(new TextDecoder().decode(arrayBuffer)));
46
-
47
- case 1:
48
- case "end":
49
- return _context.stop();
50
- }
51
- }
52
- }, _callee);
53
- }));
54
- return _parse.apply(this, arguments);
31
+ async function parse(arrayBuffer) {
32
+ return parseTextSync(new TextDecoder().decode(arrayBuffer));
55
33
  }
56
34
 
57
35
  function parseTextSync(text) {
@@ -61,4 +39,7 @@ function parseTextSync(text) {
61
39
  function parseInBatches(asyncIterator, options) {
62
40
  return (0, _parseNdjsonInBatches.default)(asyncIterator, options);
63
41
  }
42
+
43
+ const _typecheckNDJSONLoader = NDJSONLoader;
44
+ exports._typecheckNDJSONLoader = _typecheckNDJSONLoader;
64
45
  //# sourceMappingURL=ndjson-loader.js.map