node-opcua-xml2json 2.176.0 → 2.181.0
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/source/definition_parser.d.ts +1 -1
- package/dist/source/definition_parser.js +3 -3
- package/dist/source/definition_parser.js.map +1 -1
- package/dist/source/fragment_cloner.d.ts +5 -5
- package/dist/source/fragment_cloner.js +11 -8
- package/dist/source/fragment_cloner.js.map +1 -1
- package/dist/source/fragment_cloner_parser.d.ts +2 -2
- package/dist/source/fragment_cloner_parser.js +7 -5
- package/dist/source/fragment_cloner_parser.js.map +1 -1
- package/dist/source/index.d.ts +5 -5
- package/dist/source/index.js +5 -5
- package/dist/source/index.js.map +1 -1
- package/dist/source/nodejs/xml2json_fs.d.ts +2 -2
- package/dist/source/nodejs/xml2json_fs.js +4 -4
- package/dist/source/nodejs/xml2json_fs.js.map +1 -1
- package/dist/source/thirdparties/escape.js +9 -14
- package/dist/source/thirdparties/escape.js.map +1 -1
- package/dist/source/thirdparties/parser/lts.d.ts +18 -2
- package/dist/source/thirdparties/parser/lts.js +110 -21
- package/dist/source/thirdparties/parser/lts.js.map +1 -1
- package/dist/source/xml2Json_pojo_tools.d.ts +1 -1
- package/dist/source/xml2Json_pojo_tools.js +2 -2
- package/dist/source/xml2Json_pojo_tools.js.map +1 -1
- package/dist/source/xml2json.d.ts +22 -38
- package/dist/source/xml2json.js +189 -86
- package/dist/source/xml2json.js.map +1 -1
- package/dist/source/xml2json_pojo.d.ts +2 -2
- package/dist/source/xml2json_pojo.js +9 -6
- package/dist/source/xml2json_pojo.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +8 -7
- package/source/definition_parser.ts +9 -5
- package/source/fragment_cloner.ts +8 -7
- package/source/fragment_cloner_parser.ts +8 -6
- package/source/index.ts +5 -5
- package/source/nodejs/xml2json_fs.ts +3 -3
- package/source/thirdparties/escape.ts +9 -20
- package/source/thirdparties/parser/lts.ts +133 -38
- package/source/xml2Json_pojo_tools.ts +3 -5
- package/source/xml2json.ts +219 -98
- package/source/xml2json_pojo.ts +8 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml2Json_pojo_tools.js","sourceRoot":"","sources":["../../source/xml2Json_pojo_tools.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD
|
|
1
|
+
{"version":3,"file":"xml2Json_pojo_tools.js","sourceRoot":"","sources":["../../source/xml2Json_pojo_tools.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,+CAAsG;AAGtG,MAAa,YAAa,SAAQ,6BAAe;IACtC,MAAM,CAAY;IAClB,KAAK,CAAU;IAEtB,0DAA0D;IACnD,QAAQ,CAAM;IACd,IAAI,CAAS;IACb,SAAS,CAAiB;IAEzB,SAAS,GAAG,CAAC,CAAC;IACtB;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,GAAG,CAAC,KAAc,EAAE,EAAE;YAChC,WAAW;QACf,CAAC,CAAC;IACN,CAAC;IAEM,QAAQ,CAAC,YAAoB,EAAE,MAAqB,EAAE,OAAqB,EAAE,KAAa,EAAE,OAAiB;QAChH,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACvB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;YAChB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAgC,CAAC;QAC1D,CAAC;IACL,CAAC;IAEM,UAAU;QACb,UAAU;IACd,CAAC;IAEM,gBAAgB,CAAC,MAAc,EAAE,WAAmB,EAAE,MAAqB;QAC9E,IAAI,CAAC,MAAM,CAAC,I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;QACpD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QAClC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxC,MAAM,MAAM,GAAG,IAAA,mCAAgB,EAAC,WAAW,CAAC,CAAC;YAC7C,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC;YAClC,mCAAmC;QACvC,CAAC;aAAM,CAAC;YACJ,MAAM,MAAM,GAAG,IAAA,mCAAgB,EAAC,WAAW,CAAC,CAAC;YAC7C,IAAI,IAAI,CAAC,SAAS,KAAK,KAAK,EAAE,CAAC;gBAC3B,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;oBACjB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;wBACnB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;oBACjD,CAAC;yBAAM,CAAC;wBACJ,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;oBAClD,CAAC;gBACL,CAAC;YACL,CAAC;QACL,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;IACnB,CAAC;IAEM,QAAQ,CAAC,IAAY;QACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ;AAxFD,oCAwFC"}
|
|
@@ -47,9 +47,9 @@ export declare class ReaderState extends ReaderStateBase {
|
|
|
47
47
|
_finish?: () => void;
|
|
48
48
|
_startElement?: (name: string, attrs: XmlAttributes) => void;
|
|
49
49
|
_endElement?: (name: string) => void;
|
|
50
|
-
parser:
|
|
50
|
+
parser: Parser;
|
|
51
51
|
attrs?: XmlAttributes;
|
|
52
|
-
chunks:
|
|
52
|
+
chunks: string[];
|
|
53
53
|
text: string;
|
|
54
54
|
name?: string | undefined;
|
|
55
55
|
level: number;
|
|
@@ -57,7 +57,10 @@ export declare class ReaderState extends ReaderStateBase {
|
|
|
57
57
|
engine?: Xml2Json;
|
|
58
58
|
parent?: IReaderState;
|
|
59
59
|
root?: Xml2Json;
|
|
60
|
-
|
|
60
|
+
private _data?;
|
|
61
|
+
/** scratch space for the reader, fresh for every element it reads, allocated on first use */
|
|
62
|
+
get data(): Record<string, unknown>;
|
|
63
|
+
set data(value: Record<string, unknown> | undefined);
|
|
61
64
|
constructor(options: ReaderStateParser | ReaderState);
|
|
62
65
|
/**
|
|
63
66
|
* @protected
|
|
@@ -74,7 +77,7 @@ export declare class ReaderState extends ReaderStateBase {
|
|
|
74
77
|
/**
|
|
75
78
|
* @protected
|
|
76
79
|
*/
|
|
77
|
-
_on_endElement2(
|
|
80
|
+
_on_endElement2(_level: number, elementName: string): void;
|
|
78
81
|
/**
|
|
79
82
|
|
|
80
83
|
* @protected
|
|
@@ -86,46 +89,27 @@ export declare class ReaderState extends ReaderStateBase {
|
|
|
86
89
|
*/
|
|
87
90
|
_on_text(text: string): void;
|
|
88
91
|
}
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
* var parser = new Xml2Json({
|
|
93
|
-
* parser: {
|
|
94
|
-
* 'person': {
|
|
95
|
-
* init: function(name,attrs) {
|
|
96
|
-
* this.parent.root.obj = {};
|
|
97
|
-
* this.obj = this.parent.root.obj;
|
|
98
|
-
* this.obj['name'] = attrs['name'];
|
|
99
|
-
* },
|
|
100
|
-
* parser: {
|
|
101
|
-
* 'address': {
|
|
102
|
-
* finish: function(){
|
|
103
|
-
* this.parent.obj['address'] = this.text;
|
|
104
|
-
* }
|
|
105
|
-
* }
|
|
106
|
-
* }
|
|
107
|
-
* }
|
|
108
|
-
* }
|
|
109
|
-
* });
|
|
110
|
-
*
|
|
111
|
-
* var xml_string = "<employees>" +
|
|
112
|
-
* " <person name='John'>" +
|
|
113
|
-
* " <address>Paris</address>" +
|
|
114
|
-
* " </person>" +
|
|
115
|
-
* "</employees>";
|
|
116
|
-
*
|
|
117
|
-
* parser.parseString(xml_string, function() {
|
|
118
|
-
* parser.obj.should.eql({name: 'John',address: 'Paris'});
|
|
119
|
-
* done();
|
|
120
|
-
* });
|
|
121
|
-
*/
|
|
122
92
|
export declare class Xml2Json {
|
|
123
93
|
currentLevel: number;
|
|
124
94
|
private state_stack;
|
|
95
|
+
private backup_stack;
|
|
125
96
|
private current_state;
|
|
126
|
-
private
|
|
97
|
+
private sax;
|
|
98
|
+
private decoder;
|
|
99
|
+
private atStart;
|
|
127
100
|
constructor(options: ReaderStateParser);
|
|
128
101
|
parseString(xml_text: string): Record<string, unknown>;
|
|
102
|
+
/**
|
|
103
|
+
* parse a document that arrives in pieces: text, or UTF-8 bytes decoded as they come (a
|
|
104
|
+
* multi-byte character or the byte-order mark may straddle two chunks)
|
|
105
|
+
*/
|
|
106
|
+
parseStream(chunks: AsyncIterable<string | Uint8Array> | Iterable<string | Uint8Array>): Promise<Record<string, unknown>>;
|
|
107
|
+
/** start a document that {@link write} will feed and {@link end} will finish */
|
|
108
|
+
begin(): void;
|
|
109
|
+
/** feed the next piece of the document started by {@link begin} */
|
|
110
|
+
write(chunk: string | Uint8Array): void;
|
|
111
|
+
/** finish the document started by {@link begin} and return what the reader states built */
|
|
112
|
+
end(): Record<string, unknown>;
|
|
129
113
|
/**
|
|
130
114
|
* @private
|
|
131
115
|
* @internal
|
package/dist/source/xml2json.js
CHANGED
|
@@ -6,25 +6,39 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.Xml2Json = exports.ReaderState = exports.ReaderStateBase = void 0;
|
|
8
8
|
const node_opcua_assert_1 = require("node-opcua-assert");
|
|
9
|
-
const
|
|
9
|
+
const lts_js_1 = require("./thirdparties/parser/lts.js");
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* the reader states of a definition, in a table of this engine's own. A definition is a plain
|
|
12
|
+
* object the caller may hand to any number of parsers (the shared Definition reader of the
|
|
13
|
+
* nodeset loader, for one), while a reader state carries the element being read: its parent, its
|
|
14
|
+
* attributes, its text so far. So the definition is never written to; each parser builds its
|
|
15
|
+
* states from it. A definition that refers to itself, directly or through a child, gets one state
|
|
16
|
+
* per engine for the cycle, the one being built when the cycle closes.
|
|
12
17
|
* @private
|
|
13
|
-
|
|
14
|
-
* @param parser {map<ReaderState|options>}
|
|
15
|
-
* @return {map}
|
|
16
18
|
*/
|
|
17
19
|
function _coerceParser(parser) {
|
|
20
|
+
// no prototype: an element name is looked up in this table for every element of the document,
|
|
21
|
+
// one hash probe that cannot find an Object member by mistake
|
|
22
|
+
const table = Object.create(null);
|
|
23
|
+
if (!parser) {
|
|
24
|
+
return table;
|
|
25
|
+
}
|
|
18
26
|
for (const name of Object.keys(parser)) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
delete parser[name];
|
|
23
|
-
parser[name] = new ReaderState(tmp);
|
|
27
|
+
const entry = parser[name];
|
|
28
|
+
if (!entry) {
|
|
29
|
+
continue;
|
|
24
30
|
}
|
|
31
|
+
table[name] = entry instanceof ReaderState ? entry : (statesUnderConstruction.get(entry) ?? new ReaderState(entry));
|
|
25
32
|
}
|
|
26
|
-
return
|
|
33
|
+
return table;
|
|
27
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* the states being built from a definition, for the duration of one root construction: the way a
|
|
37
|
+
* definition that closes a cycle finds the state already under way instead of recursing for ever
|
|
38
|
+
*/
|
|
39
|
+
let statesUnderConstruction = new WeakMap();
|
|
40
|
+
let constructionDepth = 0;
|
|
41
|
+
// biome-ignore lint/suspicious/noUnsafeDeclarationMerging: interface adds typed members/overloads for this class
|
|
28
42
|
class ReaderStateBase {
|
|
29
43
|
}
|
|
30
44
|
exports.ReaderStateBase = ReaderStateBase;
|
|
@@ -46,18 +60,38 @@ class ReaderState extends ReaderStateBase {
|
|
|
46
60
|
engine;
|
|
47
61
|
parent;
|
|
48
62
|
root;
|
|
49
|
-
|
|
63
|
+
_data;
|
|
64
|
+
/** scratch space for the reader, fresh for every element it reads, allocated on first use */
|
|
65
|
+
get data() {
|
|
66
|
+
if (!this._data) {
|
|
67
|
+
this._data = {};
|
|
68
|
+
}
|
|
69
|
+
return this._data;
|
|
70
|
+
}
|
|
71
|
+
set data(value) {
|
|
72
|
+
this._data = value;
|
|
73
|
+
}
|
|
50
74
|
constructor(options) {
|
|
51
75
|
super();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
76
|
+
if (options instanceof ReaderStateBase) {
|
|
77
|
+
this.parser = options.parser;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this._init = options.init;
|
|
81
|
+
this._finish = options.finish;
|
|
82
|
+
this._startElement = options.startElement;
|
|
83
|
+
this._endElement = options.endElement;
|
|
84
|
+
if (constructionDepth === 0) {
|
|
85
|
+
statesUnderConstruction = new WeakMap();
|
|
86
|
+
}
|
|
87
|
+
constructionDepth += 1;
|
|
88
|
+
try {
|
|
89
|
+
statesUnderConstruction.set(options, this);
|
|
90
|
+
this.parser = _coerceParser(options.parser);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
constructionDepth -= 1;
|
|
59
94
|
}
|
|
60
|
-
this.parser = _coerceParser(options.parser);
|
|
61
95
|
}
|
|
62
96
|
/**
|
|
63
97
|
* @protected
|
|
@@ -66,7 +100,7 @@ class ReaderState extends ReaderStateBase {
|
|
|
66
100
|
this.name = elementName;
|
|
67
101
|
this.parent = parent;
|
|
68
102
|
this.engine = engine;
|
|
69
|
-
this.
|
|
103
|
+
this._data = undefined;
|
|
70
104
|
this.level = level;
|
|
71
105
|
this.currentLevel = this.level;
|
|
72
106
|
this.attrs = attrs;
|
|
@@ -93,14 +127,15 @@ class ReaderState extends ReaderStateBase {
|
|
|
93
127
|
if (this._startElement) {
|
|
94
128
|
this._startElement(elementName, attrs);
|
|
95
129
|
}
|
|
96
|
-
|
|
97
|
-
|
|
130
|
+
const child = this.parser[elementName];
|
|
131
|
+
if (this.engine && child) {
|
|
132
|
+
this.engine._promote(child, level, elementName, attrs);
|
|
98
133
|
}
|
|
99
134
|
}
|
|
100
135
|
/**
|
|
101
136
|
* @protected
|
|
102
137
|
*/
|
|
103
|
-
_on_endElement2(
|
|
138
|
+
_on_endElement2(_level, elementName) {
|
|
104
139
|
if (this._endElement) {
|
|
105
140
|
this._endElement(elementName);
|
|
106
141
|
}
|
|
@@ -123,10 +158,8 @@ class ReaderState extends ReaderStateBase {
|
|
|
123
158
|
this.chunks = [];
|
|
124
159
|
// this is the end
|
|
125
160
|
this._on_finish();
|
|
126
|
-
if (this.parent &&
|
|
127
|
-
this.
|
|
128
|
-
Object.prototype.hasOwnProperty.call(this.parent.parser, elementName)) {
|
|
129
|
-
this.engine._demote(this, level, elementName);
|
|
161
|
+
if (this.parent instanceof ReaderState && this.parent.parser[elementName]) {
|
|
162
|
+
this.engine?._demote(this, level, elementName);
|
|
130
163
|
}
|
|
131
164
|
}
|
|
132
165
|
}
|
|
@@ -145,15 +178,20 @@ class ReaderState extends ReaderStateBase {
|
|
|
145
178
|
}
|
|
146
179
|
exports.ReaderState = ReaderState;
|
|
147
180
|
const regexp = /(([^:]+):)?(.*)/;
|
|
181
|
+
// a document uses a few dozen distinct element names, each of them thousands of times
|
|
182
|
+
const resolvedNames = new Map();
|
|
148
183
|
function resolve_namespace(name) {
|
|
184
|
+
const known = resolvedNames.get(name);
|
|
185
|
+
if (known) {
|
|
186
|
+
return known;
|
|
187
|
+
}
|
|
149
188
|
const m = name.match(regexp);
|
|
150
189
|
if (!m) {
|
|
151
190
|
throw new Error("Invalid match");
|
|
152
191
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
192
|
+
const resolved = { ns: m[2], tag: m[3] };
|
|
193
|
+
resolvedNames.set(name, resolved);
|
|
194
|
+
return resolved;
|
|
157
195
|
}
|
|
158
196
|
/**
|
|
159
197
|
*
|
|
@@ -188,21 +226,120 @@ function resolve_namespace(name) {
|
|
|
188
226
|
* done();
|
|
189
227
|
* });
|
|
190
228
|
*/
|
|
229
|
+
/** how many times a reader state is active at once, kept on the state itself */
|
|
230
|
+
const activations = Symbol("activations");
|
|
191
231
|
class Xml2Json {
|
|
192
232
|
currentLevel = 0;
|
|
233
|
+
// two parallel stacks rather than one record per element: an element is pushed and popped
|
|
234
|
+
// for each of the hundreds of thousands a nodeset carries
|
|
193
235
|
state_stack = [];
|
|
236
|
+
backup_stack = [];
|
|
194
237
|
current_state = null;
|
|
195
|
-
|
|
238
|
+
sax = null;
|
|
239
|
+
decoder = null;
|
|
240
|
+
atStart = false;
|
|
196
241
|
constructor(options) {
|
|
197
242
|
const state = options instanceof ReaderStateBase ? options : new ReaderState(options);
|
|
198
243
|
state.root = this;
|
|
199
244
|
this.state_stack = [];
|
|
245
|
+
this.backup_stack = [];
|
|
200
246
|
this.current_state = null;
|
|
201
247
|
this._promote(state, 0);
|
|
202
248
|
}
|
|
203
249
|
parseString(xml_text) {
|
|
204
250
|
return this.__parseInternal(xml_text);
|
|
205
251
|
}
|
|
252
|
+
/**
|
|
253
|
+
* parse a document that arrives in pieces: text, or UTF-8 bytes decoded as they come (a
|
|
254
|
+
* multi-byte character or the byte-order mark may straddle two chunks)
|
|
255
|
+
*/
|
|
256
|
+
async parseStream(chunks) {
|
|
257
|
+
this.begin();
|
|
258
|
+
for await (const chunk of chunks) {
|
|
259
|
+
this.write(chunk);
|
|
260
|
+
}
|
|
261
|
+
return this.end();
|
|
262
|
+
}
|
|
263
|
+
/** start a document that {@link write} will feed and {@link end} will finish */
|
|
264
|
+
begin() {
|
|
265
|
+
this.currentLevel = 0;
|
|
266
|
+
this.atStart = true;
|
|
267
|
+
this.decoder = null;
|
|
268
|
+
// direct handlers rather than events, and the blank runs between tags dropped by the
|
|
269
|
+
// parser before they are unescaped: see SaxLtxHandlers
|
|
270
|
+
const sax = new lts_js_1.SaxLtx({
|
|
271
|
+
skipBlankText: true,
|
|
272
|
+
onStartElement: (name, attrs) => {
|
|
273
|
+
const tag_ns = resolve_namespace(name);
|
|
274
|
+
this.currentLevel += 1;
|
|
275
|
+
if (this.current_state) {
|
|
276
|
+
this.current_state._on_startElement(this.currentLevel, tag_ns.tag, attrs);
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
onEndElement: (name) => {
|
|
280
|
+
const tag_ns = resolve_namespace(name);
|
|
281
|
+
if (this.current_state) {
|
|
282
|
+
this.current_state._on_endElement(this.currentLevel, tag_ns.tag);
|
|
283
|
+
}
|
|
284
|
+
this.currentLevel -= 1;
|
|
285
|
+
if (this.currentLevel === 0) {
|
|
286
|
+
sax.emit("close");
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
onText: (text) => {
|
|
290
|
+
// the reader state trims what it receives; nothing blank reaches this point
|
|
291
|
+
if (this.current_state) {
|
|
292
|
+
this.current_state._on_text(text);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
this.sax = sax;
|
|
297
|
+
}
|
|
298
|
+
/** feed the next piece of the document started by {@link begin} */
|
|
299
|
+
write(chunk) {
|
|
300
|
+
const sax = this.sax;
|
|
301
|
+
if (!sax) {
|
|
302
|
+
throw new Error("Xml2Json#write: begin() must be called first");
|
|
303
|
+
}
|
|
304
|
+
let text;
|
|
305
|
+
if (typeof chunk === "string") {
|
|
306
|
+
text = chunk;
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
this.decoder = this.decoder || new TextDecoder("utf-8");
|
|
310
|
+
text = this.decoder.decode(chunk, { stream: true });
|
|
311
|
+
}
|
|
312
|
+
if (text.length === 0) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
if (this.atStart) {
|
|
316
|
+
this.atStart = false;
|
|
317
|
+
if (text.charCodeAt(0) === 0xfeff) {
|
|
318
|
+
text = text.slice(1);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
sax.write(text);
|
|
322
|
+
}
|
|
323
|
+
/** finish the document started by {@link begin} and return what the reader states built */
|
|
324
|
+
end() {
|
|
325
|
+
const sax = this.sax;
|
|
326
|
+
if (!sax) {
|
|
327
|
+
throw new Error("Xml2Json#end: begin() must be called first");
|
|
328
|
+
}
|
|
329
|
+
if (this.decoder) {
|
|
330
|
+
const tail = this.decoder.decode();
|
|
331
|
+
this.decoder = null;
|
|
332
|
+
if (tail.length > 0) {
|
|
333
|
+
sax.write(tail);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
sax.end("");
|
|
337
|
+
this.sax = null;
|
|
338
|
+
if (!this.current_state) {
|
|
339
|
+
return {};
|
|
340
|
+
}
|
|
341
|
+
return this.current_state._pojo;
|
|
342
|
+
}
|
|
206
343
|
/**
|
|
207
344
|
* @private
|
|
208
345
|
* @internal
|
|
@@ -213,14 +350,17 @@ class Xml2Json {
|
|
|
213
350
|
// active at two levels at once. This happens when a data type refers to itself, directly or
|
|
214
351
|
// indirectly: the reader of the nested element is then the very same object as the outer one.
|
|
215
352
|
// In that case only, take a copy of the outer activation and restore it in _demote.
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
});
|
|
353
|
+
const counted = new_state;
|
|
354
|
+
const active = counted[activations] || 0;
|
|
355
|
+
counted[activations] = active + 1;
|
|
356
|
+
this.state_stack.push(this.current_state);
|
|
357
|
+
this.backup_stack.push(active > 0 ? { ...new_state } : null);
|
|
222
358
|
const parent = this.current_state;
|
|
223
359
|
this.current_state = new_state;
|
|
360
|
+
// parent is null only for the root element; every _on_init implementation in this codebase
|
|
361
|
+
// names the parameter `_parent` (unused), so widening the public IReaderState signature to
|
|
362
|
+
// accept null would ripple into every consumer package that already treats it as non-null.
|
|
363
|
+
// biome-ignore lint/style/noNonNullAssertion: see comment above
|
|
224
364
|
this.current_state._on_init(name || "???", attr, parent, level, this);
|
|
225
365
|
}
|
|
226
366
|
/**
|
|
@@ -229,18 +369,17 @@ class Xml2Json {
|
|
|
229
369
|
*/
|
|
230
370
|
_demote(cur_state, level, elementName) {
|
|
231
371
|
/// assert(this.current_state === cur_state);
|
|
232
|
-
|
|
372
|
+
if (this.state_stack.length === 0) {
|
|
373
|
+
throw new Error("_demote called without a matching _promote");
|
|
374
|
+
}
|
|
375
|
+
const state = this.state_stack.pop();
|
|
376
|
+
const backup = this.backup_stack.pop();
|
|
233
377
|
this.current_state = state;
|
|
234
378
|
if (this.current_state) {
|
|
235
379
|
this.current_state._on_endElement2(level, elementName);
|
|
236
380
|
}
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
this.activation_count.delete(cur_state);
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
this.activation_count.set(cur_state, count);
|
|
243
|
-
}
|
|
381
|
+
const counted = cur_state;
|
|
382
|
+
counted[activations] = (counted[activations] || 1) - 1;
|
|
244
383
|
if (backup) {
|
|
245
384
|
// cur_state was a nested activation of a state that is still active at an outer level:
|
|
246
385
|
// put the outer element back the way it was. The parent has already consumed the nested
|
|
@@ -257,45 +396,9 @@ class Xml2Json {
|
|
|
257
396
|
* @internal
|
|
258
397
|
*/
|
|
259
398
|
__parseInternal(data) {
|
|
260
|
-
|
|
261
|
-
this.
|
|
262
|
-
|
|
263
|
-
const tag_ns = resolve_namespace(name);
|
|
264
|
-
this.currentLevel += 1;
|
|
265
|
-
if (this.current_state) {
|
|
266
|
-
this.current_state._on_startElement(this.currentLevel, tag_ns.tag, attrs);
|
|
267
|
-
}
|
|
268
|
-
});
|
|
269
|
-
parser.on("endElement", (name) => {
|
|
270
|
-
const tag_ns = resolve_namespace(name);
|
|
271
|
-
if (this.current_state) {
|
|
272
|
-
this.current_state._on_endElement(this.currentLevel, tag_ns.tag);
|
|
273
|
-
}
|
|
274
|
-
this.currentLevel -= 1;
|
|
275
|
-
if (this.currentLevel === 0) {
|
|
276
|
-
parser.emit("close");
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
parser.on("text", (text) => {
|
|
280
|
-
text = text.trim();
|
|
281
|
-
if (text.length === 0) {
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
if (this.current_state) {
|
|
285
|
-
this.current_state._on_text(text);
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
parser.write(data);
|
|
289
|
-
parser.end("");
|
|
290
|
-
return this.current_state._pojo;
|
|
291
|
-
/*
|
|
292
|
-
return await new Promise((resolve) => {
|
|
293
|
-
parser.once("close", () => {
|
|
294
|
-
resolve((this.current_state! as any)._pojo);
|
|
295
|
-
});
|
|
296
|
-
//parser.write(data);
|
|
297
|
-
parser.end(data);
|
|
298
|
-
})*/
|
|
399
|
+
this.begin();
|
|
400
|
+
this.write(data);
|
|
401
|
+
return this.end();
|
|
299
402
|
}
|
|
300
403
|
}
|
|
301
404
|
exports.Xml2Json = Xml2Json;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml2json.js","sourceRoot":"","sources":["../../source/xml2json.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"xml2json.js","sourceRoot":"","sources":["../../source/xml2json.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yDAA2C;AAC3C,yDAAsD;AAStD;;;;;;;;GAQG;AACH,SAAS,aAAa,CAAC,MAA8B;IACjD,8FAA8F;IAC9F,8DAA8D;IAC9D,MAAM,KAAK,GAAW,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,C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
-
import {
|
|
1
|
+
import { type withPojoLambda } from "./xml2Json_pojo_tools.js";
|
|
2
|
+
import { type ReaderState, type ReaderStateParser, Xml2Json, type XmlAttributes } from "./xml2json.js";
|
|
3
3
|
export declare const json_parser: ReaderStateParser;
|
|
4
4
|
export declare function startPojo(pThis: ReaderState, elementName: string, attrs: XmlAttributes, withPojo: withPojoLambda): void;
|
|
5
5
|
export declare class Xml2JsonPojo extends Xml2Json {
|
|
@@ -2,25 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Xml2JsonPojo = exports.json_parser = void 0;
|
|
4
4
|
exports.startPojo = startPojo;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const json_extractor = new
|
|
5
|
+
const xml2Json_pojo_tools_js_1 = require("./xml2Json_pojo_tools.js");
|
|
6
|
+
const xml2json_js_1 = require("./xml2json.js");
|
|
7
|
+
const json_extractor = new xml2Json_pojo_tools_js_1.ReaderState2();
|
|
8
8
|
exports.json_parser = {
|
|
9
9
|
init(elementName, attrs, parent, engine) {
|
|
10
10
|
json_extractor._on_init(elementName, attrs, parent, 0, engine);
|
|
11
11
|
},
|
|
12
|
+
// ReaderStateParser.finish declares `this: IReaderState`, which doesn't expose `.parent` — the
|
|
13
|
+
// runtime `this` here is always the ReaderState instance that owns this parser entry.
|
|
14
|
+
// biome-ignore lint/suspicious/noExplicitAny: see comment above
|
|
12
15
|
finish() {
|
|
13
16
|
this.parent._pojo = json_extractor._pojo;
|
|
14
17
|
}
|
|
15
18
|
};
|
|
16
19
|
function startPojo(pThis, elementName, attrs, withPojo) {
|
|
17
|
-
pThis.engine
|
|
20
|
+
pThis.engine?._promote(json_extractor, pThis.engine?.currentLevel, elementName, attrs);
|
|
18
21
|
json_extractor._withPojo = (name, pojo) => {
|
|
19
22
|
withPojo(name, pojo);
|
|
20
|
-
pThis.engine
|
|
23
|
+
pThis.engine?._demote(json_extractor, pThis.engine?.currentLevel, elementName);
|
|
21
24
|
};
|
|
22
25
|
}
|
|
23
|
-
class Xml2JsonPojo extends
|
|
26
|
+
class Xml2JsonPojo extends xml2json_js_1.Xml2Json {
|
|
24
27
|
constructor() {
|
|
25
28
|
super(json_extractor);
|
|
26
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml2json_pojo.js","sourceRoot":"","sources":["../../source/xml2json_pojo.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"xml2json_pojo.js","sourceRoot":"","sources":["../../source/xml2json_pojo.ts"],"names":[],"mappings":";;;AAgBA,8BAMC;AAtBD,qEAA6E;AAC7E,+CAA0H;AAE1H,MAAM,cAAc,GAAiB,IAAI,qCAAY,EAAE,CAAC;AAC3C,QAAA,WAAW,GAAsB;IAC1C,IAAI,CAAqB,WAAmB,EAAE,KAAoB,EAAE,MAAoB,EAAE,MAAgB;QACtG,cAAc,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IACD,+FAA+F;IAC/F,sFAAsF;IACtF,gEAAgE;IAChE,MAAM;QACF,IAAI,CAAC,MAAM,CAAC,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC;IAC7C,CAAC;CACJ,CAAC;AAEF,SAAgB,SAAS,CAAC,KAAkB,EAAE,WAAmB,EAAE,KAAoB,EAAE,QAAwB;IAC7G,KAAK,CAAC,MAAM,EAAE,QAAQ,CAAC,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;IACvF,cAAc,CAAC,SAAS,GAAG,CAAC,IAAY,EAAE,IAAa,EAAE,EAAE;QACvD,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACrB,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,EAAE,KAAK,CAAC,MAAM,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;IACnF,CAAC,CAAC;AACN,CAAC;AAED,MAAa,YAAa,SAAQ,sBAAQ;IACtC;QACI,KAAK,CAAC,cAAmC,CAAC,CAAC;IAC/C,CAAC;CACJ;AAJD,oCAIC"}
|