basyx-typescript-sdk 2.2.3 → 2.2.4
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/bundle/index.cjs +223 -86
- package/bundle/index.cjs.map +1 -1
- package/bundle/index.mjs +223 -86
- package/bundle/index.mjs.map +1 -1
- package/dist/lib/aas-dataformat-xml/xmlization.js +1 -1
- package/package.json +12 -12
package/bundle/index.cjs
CHANGED
|
@@ -31968,12 +31968,14 @@ var AasService = class {
|
|
|
31968
31968
|
//#region dist/models/BaSyxEnvironment.js
|
|
31969
31969
|
var BaSyxEnvironment = class extends Environment {};
|
|
31970
31970
|
//#endregion
|
|
31971
|
-
//#region node_modules/.pnpm/
|
|
31972
|
-
var
|
|
31973
|
-
|
|
31974
|
-
|
|
31975
|
-
|
|
31976
|
-
|
|
31971
|
+
//#region node_modules/.pnpm/xmlsax-typescript@1.0.0-rc.1/node_modules/xmlsax-typescript/dist/index.js
|
|
31972
|
+
var XmlSaxLibraryError = class extends Error {
|
|
31973
|
+
constructor(message, code) {
|
|
31974
|
+
super(message);
|
|
31975
|
+
this.name = "XmlSaxLibraryError";
|
|
31976
|
+
this.code = code;
|
|
31977
|
+
}
|
|
31978
|
+
};
|
|
31977
31979
|
var XmlSaxError = class extends Error {
|
|
31978
31980
|
constructor(message, offset, line, column) {
|
|
31979
31981
|
super(`${message} at ${line}:${column}`);
|
|
@@ -31983,6 +31985,24 @@ var XmlSaxError = class extends Error {
|
|
|
31983
31985
|
this.column = column;
|
|
31984
31986
|
}
|
|
31985
31987
|
};
|
|
31988
|
+
var XmlSaxBuildError = class extends XmlSaxLibraryError {
|
|
31989
|
+
constructor(message, phase) {
|
|
31990
|
+
super(message, "XMLSAX_BUILD_ERROR");
|
|
31991
|
+
this.name = "XmlSaxBuildError";
|
|
31992
|
+
this.phase = phase;
|
|
31993
|
+
}
|
|
31994
|
+
};
|
|
31995
|
+
var XmlSaxInvariantError = class extends XmlSaxLibraryError {
|
|
31996
|
+
constructor(message) {
|
|
31997
|
+
super(message, "XMLSAX_INVARIANT_ERROR");
|
|
31998
|
+
this.name = "XmlSaxInvariantError";
|
|
31999
|
+
}
|
|
32000
|
+
};
|
|
32001
|
+
var DEV = globalThis.process?.env?.NODE_ENV !== "production";
|
|
32002
|
+
function assert(condition, message) {
|
|
32003
|
+
if (!DEV) return;
|
|
32004
|
+
if (!condition) throw new XmlSaxInvariantError(`Invariant failed: ${message}`);
|
|
32005
|
+
}
|
|
31986
32006
|
function decodeEntities(input, onError) {
|
|
31987
32007
|
if (input.indexOf("&") === -1) return input;
|
|
31988
32008
|
let result = "";
|
|
@@ -31995,21 +32015,13 @@ function decodeEntities(input, onError) {
|
|
|
31995
32015
|
}
|
|
31996
32016
|
if (amp > i) result += input.slice(i, amp);
|
|
31997
32017
|
const semi = input.indexOf(";", amp + 1);
|
|
31998
|
-
if (semi === -1)
|
|
31999
|
-
const err = new XmlSaxError("Unterminated entity", amp, 0, 0);
|
|
32000
|
-
onError?.(err);
|
|
32001
|
-
throw err;
|
|
32002
|
-
}
|
|
32018
|
+
if (semi === -1) throw new XmlSaxError("Unterminated entity", amp, 0, 0);
|
|
32003
32019
|
let decoded;
|
|
32004
32020
|
if (input[amp + 1] === "#") {
|
|
32005
32021
|
const numeric = parseNumericEntity(input, amp + 2, semi);
|
|
32006
32022
|
decoded = numeric === void 0 ? void 0 : decodeCodePoint(numeric);
|
|
32007
32023
|
} else decoded = decodeNamedEntity(input, amp + 1, semi);
|
|
32008
|
-
if (decoded === void 0) {
|
|
32009
|
-
const err = new XmlSaxError(`Unknown entity: &${input.slice(amp + 1, semi)};`, amp, 0, 0);
|
|
32010
|
-
onError?.(err);
|
|
32011
|
-
throw err;
|
|
32012
|
-
}
|
|
32024
|
+
if (decoded === void 0) throw new XmlSaxError(`Unknown entity: &${input.slice(amp + 1, semi)};`, amp, 0, 0);
|
|
32013
32025
|
result += decoded;
|
|
32014
32026
|
i = semi + 1;
|
|
32015
32027
|
}
|
|
@@ -32084,6 +32096,63 @@ function splitTextForEntities(text) {
|
|
|
32084
32096
|
carry: ""
|
|
32085
32097
|
};
|
|
32086
32098
|
}
|
|
32099
|
+
var XmlToken = class {
|
|
32100
|
+
constructor(kind, position) {
|
|
32101
|
+
this.kind = kind;
|
|
32102
|
+
this.position = position;
|
|
32103
|
+
}
|
|
32104
|
+
};
|
|
32105
|
+
var OpenTagToken = class extends XmlToken {
|
|
32106
|
+
constructor(tag, depth, path, position) {
|
|
32107
|
+
super("open-tag", position);
|
|
32108
|
+
this.tag = tag;
|
|
32109
|
+
this.depth = depth;
|
|
32110
|
+
this.path = path;
|
|
32111
|
+
}
|
|
32112
|
+
};
|
|
32113
|
+
var CloseTagToken = class extends XmlToken {
|
|
32114
|
+
constructor(tag, depth, path, position) {
|
|
32115
|
+
super("close-tag", position);
|
|
32116
|
+
this.tag = tag;
|
|
32117
|
+
this.depth = depth;
|
|
32118
|
+
this.path = path;
|
|
32119
|
+
}
|
|
32120
|
+
};
|
|
32121
|
+
var TextToken = class extends XmlToken {
|
|
32122
|
+
constructor(text, position) {
|
|
32123
|
+
super("text", position);
|
|
32124
|
+
this.text = text;
|
|
32125
|
+
}
|
|
32126
|
+
};
|
|
32127
|
+
var CdataToken = class extends XmlToken {
|
|
32128
|
+
constructor(text, position) {
|
|
32129
|
+
super("cdata", position);
|
|
32130
|
+
this.text = text;
|
|
32131
|
+
}
|
|
32132
|
+
};
|
|
32133
|
+
var CommentToken = class extends XmlToken {
|
|
32134
|
+
constructor(text, position) {
|
|
32135
|
+
super("comment", position);
|
|
32136
|
+
this.text = text;
|
|
32137
|
+
}
|
|
32138
|
+
};
|
|
32139
|
+
var ProcessingInstructionToken = class extends XmlToken {
|
|
32140
|
+
constructor(processingInstruction, position) {
|
|
32141
|
+
super("processing-instruction", position);
|
|
32142
|
+
this.processingInstruction = processingInstruction;
|
|
32143
|
+
}
|
|
32144
|
+
};
|
|
32145
|
+
var DoctypeToken = class extends XmlToken {
|
|
32146
|
+
constructor(doctype, position) {
|
|
32147
|
+
super("doctype", position);
|
|
32148
|
+
this.doctype = doctype;
|
|
32149
|
+
}
|
|
32150
|
+
};
|
|
32151
|
+
var EndToken = class extends XmlToken {
|
|
32152
|
+
constructor(position) {
|
|
32153
|
+
super("end", position);
|
|
32154
|
+
}
|
|
32155
|
+
};
|
|
32087
32156
|
var DEFAULT_OPTIONS = {
|
|
32088
32157
|
xmlns: true,
|
|
32089
32158
|
includeNamespaceAttributes: false,
|
|
@@ -32117,6 +32186,8 @@ var XmlSaxParser = class {
|
|
|
32117
32186
|
this.offset = 0;
|
|
32118
32187
|
this.line = 1;
|
|
32119
32188
|
this.column = 1;
|
|
32189
|
+
this.pathStack = [];
|
|
32190
|
+
this.tokenQueue = [];
|
|
32120
32191
|
this.elementStack = [];
|
|
32121
32192
|
this.nsStack = [Object.assign(/* @__PURE__ */ Object.create(null), {
|
|
32122
32193
|
xml: XML_NAMESPACE_URI,
|
|
@@ -32135,29 +32206,42 @@ var XmlSaxParser = class {
|
|
|
32135
32206
|
this.allowDoctype = resolved.allowDoctype;
|
|
32136
32207
|
this.coalesceText = resolved.coalesceText;
|
|
32137
32208
|
this.trackPosition = resolved.trackPosition;
|
|
32138
|
-
this.onOpenTag = resolved.onOpenTag;
|
|
32139
|
-
this.onCloseTag = resolved.onCloseTag;
|
|
32140
|
-
this.onText = resolved.onText;
|
|
32141
|
-
this.onCdata = resolved.onCdata;
|
|
32142
|
-
this.onComment = resolved.onComment;
|
|
32143
|
-
this.onProcessingInstruction = resolved.onProcessingInstruction;
|
|
32144
|
-
this.onDoctype = resolved.onDoctype;
|
|
32145
|
-
this.onError = resolved.onError;
|
|
32146
32209
|
}
|
|
32147
32210
|
feed(chunk) {
|
|
32148
32211
|
if (this.closed) this._error("Parser is closed");
|
|
32149
|
-
|
|
32212
|
+
this._assertInternalState("before feed");
|
|
32213
|
+
if (!chunk) return this.drainTokens();
|
|
32150
32214
|
this.buffer += chunk;
|
|
32151
32215
|
this._parseBuffer(false);
|
|
32216
|
+
this._assertInternalState("after feed");
|
|
32217
|
+
return this.drainTokens();
|
|
32152
32218
|
}
|
|
32153
32219
|
close() {
|
|
32154
|
-
if (this.closed) return;
|
|
32220
|
+
if (this.closed) return this.drainTokens();
|
|
32155
32221
|
this._parseBuffer(true);
|
|
32156
32222
|
this._flushPendingCR();
|
|
32157
32223
|
this._flushTextBuffer();
|
|
32224
|
+
this._assertInternalState("before close validation");
|
|
32158
32225
|
if (this.buffer.length > 0) this._error("Unexpected end of input");
|
|
32159
32226
|
if (this.elementStack.length > 0) this._error("Unclosed tag(s) remaining");
|
|
32160
32227
|
this.closed = true;
|
|
32228
|
+
this._pushToken(new EndToken(this._position()));
|
|
32229
|
+
this._assertInternalState("after close");
|
|
32230
|
+
return this.drainTokens();
|
|
32231
|
+
}
|
|
32232
|
+
drainTokens() {
|
|
32233
|
+
if (this.tokenQueue.length === 0) return [];
|
|
32234
|
+
return this.tokenQueue.splice(0, this.tokenQueue.length);
|
|
32235
|
+
}
|
|
32236
|
+
*[Symbol.iterator]() {
|
|
32237
|
+
while (this.tokenQueue.length > 0) {
|
|
32238
|
+
const token = this.tokenQueue.shift();
|
|
32239
|
+
if (token) yield token;
|
|
32240
|
+
}
|
|
32241
|
+
}
|
|
32242
|
+
async *iterateChunks(chunks) {
|
|
32243
|
+
for await (const chunk of chunks) for (const token of this.feed(chunk)) yield token;
|
|
32244
|
+
for (const token of this.close()) yield token;
|
|
32161
32245
|
}
|
|
32162
32246
|
_parseBuffer(final) {
|
|
32163
32247
|
let i = 0;
|
|
@@ -32215,7 +32299,7 @@ var XmlSaxParser = class {
|
|
|
32215
32299
|
body: split === -1 ? "" : body.slice(split).trim()
|
|
32216
32300
|
};
|
|
32217
32301
|
this._flushTextBuffer();
|
|
32218
|
-
this.
|
|
32302
|
+
this._pushToken(new ProcessingInstructionToken(pi, this._position()));
|
|
32219
32303
|
return end + 2 - start;
|
|
32220
32304
|
}
|
|
32221
32305
|
if (secondCode === 33) {
|
|
@@ -32228,7 +32312,7 @@ var XmlSaxParser = class {
|
|
|
32228
32312
|
}
|
|
32229
32313
|
const comment = this.buffer.slice(start + 4, end);
|
|
32230
32314
|
this._flushTextBuffer();
|
|
32231
|
-
this.
|
|
32315
|
+
this._pushToken(new CommentToken(comment, this._position()));
|
|
32232
32316
|
return end + 3 - start;
|
|
32233
32317
|
}
|
|
32234
32318
|
if (thirdCode === 91 && this.buffer.startsWith("<![CDATA[", start)) {
|
|
@@ -32241,7 +32325,7 @@ var XmlSaxParser = class {
|
|
|
32241
32325
|
const normalized = this._normalizeText(cdata, false);
|
|
32242
32326
|
if (normalized.length > 0) {
|
|
32243
32327
|
this._flushTextBuffer();
|
|
32244
|
-
this.
|
|
32328
|
+
this._pushToken(new CdataToken(normalized, this._position()));
|
|
32245
32329
|
}
|
|
32246
32330
|
return end + 3 - start;
|
|
32247
32331
|
}
|
|
@@ -32254,7 +32338,7 @@ var XmlSaxParser = class {
|
|
|
32254
32338
|
if (!this.allowDoctype) this._error("Doctype is not allowed");
|
|
32255
32339
|
const doctype = { raw: this.buffer.slice(start + 9, end).trim() };
|
|
32256
32340
|
this._flushTextBuffer();
|
|
32257
|
-
this.
|
|
32341
|
+
this._pushToken(new DoctypeToken(doctype, this._position()));
|
|
32258
32342
|
return end + 1 - start;
|
|
32259
32343
|
}
|
|
32260
32344
|
}
|
|
@@ -32280,6 +32364,7 @@ var XmlSaxParser = class {
|
|
|
32280
32364
|
return tagEnd + 1 - start;
|
|
32281
32365
|
}
|
|
32282
32366
|
_handleStartTagRange(start, end) {
|
|
32367
|
+
this._assertInternalState("before start tag");
|
|
32283
32368
|
this._flushTextBuffer();
|
|
32284
32369
|
const parsed = this._parseStartTagRange(start, end);
|
|
32285
32370
|
const selfClosing = parsed.selfClosing;
|
|
@@ -32292,15 +32377,19 @@ var XmlSaxParser = class {
|
|
|
32292
32377
|
attributes: attributes2,
|
|
32293
32378
|
isSelfClosing: selfClosing
|
|
32294
32379
|
};
|
|
32295
|
-
this.
|
|
32380
|
+
const openPath2 = Object.freeze([...this.pathStack, plainName]);
|
|
32381
|
+
const depth2 = openPath2.length;
|
|
32382
|
+
this._pushToken(new OpenTagToken(tag2, depth2, openPath2, this._position()));
|
|
32296
32383
|
if (selfClosing) {
|
|
32297
|
-
this.
|
|
32384
|
+
this._pushToken(new CloseTagToken({ name: plainName }, depth2, openPath2, this._position()));
|
|
32298
32385
|
return;
|
|
32299
32386
|
}
|
|
32300
32387
|
this.elementStack.push({
|
|
32301
32388
|
rawName: parsed.name,
|
|
32302
32389
|
closeTag: { name: plainName }
|
|
32303
32390
|
});
|
|
32391
|
+
this.pathStack.push(plainName);
|
|
32392
|
+
this._assertInternalState("after start tag (plain mode)");
|
|
32304
32393
|
return;
|
|
32305
32394
|
}
|
|
32306
32395
|
const parentNs = this._currentNs();
|
|
@@ -32335,14 +32424,16 @@ var XmlSaxParser = class {
|
|
|
32335
32424
|
attributes,
|
|
32336
32425
|
isSelfClosing: selfClosing
|
|
32337
32426
|
};
|
|
32338
|
-
this.
|
|
32427
|
+
const openPath = Object.freeze([...this.pathStack, resolvedName.name]);
|
|
32428
|
+
const depth = openPath.length;
|
|
32429
|
+
this._pushToken(new OpenTagToken(tag, depth, openPath, this._position()));
|
|
32339
32430
|
if (selfClosing) {
|
|
32340
|
-
this.
|
|
32431
|
+
this._pushToken(new CloseTagToken({
|
|
32341
32432
|
name: resolvedName.name,
|
|
32342
32433
|
prefix: resolvedName.prefix,
|
|
32343
32434
|
local: resolvedName.local,
|
|
32344
32435
|
uri: resolvedName.uri
|
|
32345
|
-
});
|
|
32436
|
+
}, depth, openPath, this._position()));
|
|
32346
32437
|
return;
|
|
32347
32438
|
}
|
|
32348
32439
|
this.elementStack.push({
|
|
@@ -32354,7 +32445,9 @@ var XmlSaxParser = class {
|
|
|
32354
32445
|
uri: resolvedName.uri
|
|
32355
32446
|
}
|
|
32356
32447
|
});
|
|
32448
|
+
this.pathStack.push(resolvedName.name);
|
|
32357
32449
|
this.nsStack.push(ns);
|
|
32450
|
+
this._assertInternalState("after start tag");
|
|
32358
32451
|
}
|
|
32359
32452
|
_parseStartTagRange(start, end) {
|
|
32360
32453
|
let i = this._skipWhitespace(this.buffer, start, end);
|
|
@@ -32387,7 +32480,7 @@ var XmlSaxParser = class {
|
|
|
32387
32480
|
if (valueEnd === -1 || valueEnd >= end) this._error("Unterminated attribute value");
|
|
32388
32481
|
const rawValue = this.buffer.slice(i, valueEnd);
|
|
32389
32482
|
const normalized = rawValue.includes("\r") ? rawValue.replace(CRLF_RE, "\n") : rawValue;
|
|
32390
|
-
const value = !normalized.includes("&") ? normalized : decodeEntities(normalized
|
|
32483
|
+
const value = !normalized.includes("&") ? normalized : decodeEntities(normalized);
|
|
32391
32484
|
attributes.push({
|
|
32392
32485
|
name: attrName.name,
|
|
32393
32486
|
value
|
|
@@ -32401,12 +32494,19 @@ var XmlSaxParser = class {
|
|
|
32401
32494
|
};
|
|
32402
32495
|
}
|
|
32403
32496
|
_handleCloseTag(rawName, _nameEnd) {
|
|
32497
|
+
this._assertInternalState("before close tag");
|
|
32404
32498
|
this._flushTextBuffer();
|
|
32405
32499
|
const entry = this.elementStack.pop();
|
|
32406
32500
|
const ns = this.xmlns ? this.nsStack.pop() : this._currentNs();
|
|
32407
32501
|
if (!entry || !ns) this._error("Closing tag without matching start tag");
|
|
32408
32502
|
if (entry.rawName !== rawName) this._error(`Mismatched closing tag: expected </${entry.rawName}>`);
|
|
32409
|
-
|
|
32503
|
+
const closePath = Object.freeze([...this.pathStack]);
|
|
32504
|
+
const depth = closePath.length;
|
|
32505
|
+
assert(depth > 0, "Path stack cannot be empty when closing a tag");
|
|
32506
|
+
assert(closePath[depth - 1] === entry.closeTag.name, "Path stack must match closing tag name");
|
|
32507
|
+
if (depth > 0) this.pathStack.pop();
|
|
32508
|
+
this._pushToken(new CloseTagToken(entry.closeTag, depth, closePath, this._position()));
|
|
32509
|
+
this._assertInternalState("after close tag");
|
|
32410
32510
|
}
|
|
32411
32511
|
_emitText(text, allowPendingCR) {
|
|
32412
32512
|
const normalized = this._normalizeText(text, allowPendingCR);
|
|
@@ -32415,12 +32515,12 @@ var XmlSaxParser = class {
|
|
|
32415
32515
|
this._emitDecodedText(normalized);
|
|
32416
32516
|
return;
|
|
32417
32517
|
}
|
|
32418
|
-
const decoded = decodeEntities(normalized
|
|
32518
|
+
const decoded = decodeEntities(normalized);
|
|
32419
32519
|
if (decoded.length > 0) this._emitDecodedText(decoded);
|
|
32420
32520
|
}
|
|
32421
32521
|
_emitDecodedText(text) {
|
|
32422
32522
|
if (!this.coalesceText) {
|
|
32423
|
-
this.
|
|
32523
|
+
this._pushToken(new TextToken(text, this._position()));
|
|
32424
32524
|
return;
|
|
32425
32525
|
}
|
|
32426
32526
|
this.pendingTextParts.push(text);
|
|
@@ -32430,7 +32530,7 @@ var XmlSaxParser = class {
|
|
|
32430
32530
|
const first = this.pendingTextParts[0];
|
|
32431
32531
|
const text = this.pendingTextParts.length === 1 && first !== void 0 ? first : this.pendingTextParts.join("");
|
|
32432
32532
|
this.pendingTextParts.length = 0;
|
|
32433
|
-
this.
|
|
32533
|
+
this._pushToken(new TextToken(text, this._position()));
|
|
32434
32534
|
}
|
|
32435
32535
|
_resolveName(rawName, ns) {
|
|
32436
32536
|
if (!this.xmlns) {
|
|
@@ -32542,7 +32642,7 @@ var XmlSaxParser = class {
|
|
|
32542
32642
|
_parseName(input, start, end) {
|
|
32543
32643
|
if (start >= end) this._error("Expected name");
|
|
32544
32644
|
const firstCode = input.charCodeAt(start);
|
|
32545
|
-
if (firstCode
|
|
32645
|
+
if (firstCode >= 128 || NAME_START_TABLE[firstCode] === 0) this._error(`Invalid name start: '${input[start] ?? ""}'`);
|
|
32546
32646
|
let i = start + 1;
|
|
32547
32647
|
while (i < end) {
|
|
32548
32648
|
const code = input.charCodeAt(i);
|
|
@@ -32628,59 +32728,95 @@ var XmlSaxParser = class {
|
|
|
32628
32728
|
_error(message) {
|
|
32629
32729
|
const line = this.trackPosition ? this.line : 0;
|
|
32630
32730
|
const column = this.trackPosition ? this.column : 0;
|
|
32631
|
-
|
|
32632
|
-
|
|
32633
|
-
|
|
32731
|
+
throw new XmlSaxError(message, this.offset, line, column);
|
|
32732
|
+
}
|
|
32733
|
+
_position() {
|
|
32734
|
+
return {
|
|
32735
|
+
offset: this.offset,
|
|
32736
|
+
line: this.trackPosition ? this.line : 0,
|
|
32737
|
+
column: this.trackPosition ? this.column : 0
|
|
32738
|
+
};
|
|
32739
|
+
}
|
|
32740
|
+
_pushToken(token) {
|
|
32741
|
+
this.tokenQueue.push(token);
|
|
32742
|
+
}
|
|
32743
|
+
_assertInternalState(stage) {
|
|
32744
|
+
assert(this.pathStack.length === this.elementStack.length, `Path and element stack lengths diverged (${stage})`);
|
|
32745
|
+
if (!this.xmlns) {
|
|
32746
|
+
assert(this.nsStack.length === 1, `Namespace stack must stay at depth 1 in plain mode (${stage})`);
|
|
32747
|
+
return;
|
|
32748
|
+
}
|
|
32749
|
+
assert(this.nsStack.length === this.elementStack.length + 1, `Namespace stack depth must be element depth + 1 (${stage})`);
|
|
32634
32750
|
}
|
|
32635
32751
|
};
|
|
32752
|
+
function isBuildToken(token) {
|
|
32753
|
+
switch (token.kind) {
|
|
32754
|
+
case "open-tag":
|
|
32755
|
+
case "close-tag":
|
|
32756
|
+
case "text":
|
|
32757
|
+
case "cdata": return true;
|
|
32758
|
+
default: return false;
|
|
32759
|
+
}
|
|
32760
|
+
}
|
|
32636
32761
|
var TreeBuilder = class {
|
|
32637
32762
|
constructor() {
|
|
32638
32763
|
this.stack = [];
|
|
32639
32764
|
this.root = null;
|
|
32640
|
-
|
|
32641
|
-
|
|
32642
|
-
|
|
32643
|
-
|
|
32644
|
-
|
|
32645
|
-
|
|
32646
|
-
|
|
32647
|
-
if (parent) parent.children?.push(node);
|
|
32648
|
-
else this.root = node;
|
|
32649
|
-
this.stack.push(node);
|
|
32650
|
-
};
|
|
32651
|
-
this.onText = (text) => {
|
|
32652
|
-
if (!this.stack.length) return;
|
|
32653
|
-
const node = this.stack[this.stack.length - 1];
|
|
32654
|
-
if (!node) return;
|
|
32655
|
-
const children = node.children ?? [];
|
|
32656
|
-
const last = children[children.length - 1];
|
|
32657
|
-
if (typeof last === "string") children[children.length - 1] = last + text;
|
|
32658
|
-
else children.push(text);
|
|
32659
|
-
node.children = children;
|
|
32660
|
-
};
|
|
32661
|
-
this.onCdata = (text) => {
|
|
32662
|
-
this.onText(text);
|
|
32663
|
-
};
|
|
32664
|
-
this.onCloseTag = () => {
|
|
32665
|
-
this.stack.pop();
|
|
32765
|
+
}
|
|
32766
|
+
onOpenTag(tag) {
|
|
32767
|
+
if (this.stack.length === 0 && this.root !== null) throw new XmlSaxBuildError("Multiple root elements are not supported", "tree");
|
|
32768
|
+
const node = {
|
|
32769
|
+
name: tag.name,
|
|
32770
|
+
attributes: Object.fromEntries(Object.entries(tag.attributes).map(([key, attr]) => [key, typeof attr === "string" ? attr : attr.value])),
|
|
32771
|
+
children: []
|
|
32666
32772
|
};
|
|
32773
|
+
const parent = this.stack[this.stack.length - 1];
|
|
32774
|
+
if (parent) parent.children?.push(node);
|
|
32775
|
+
else this.root = node;
|
|
32776
|
+
this.stack.push(node);
|
|
32777
|
+
}
|
|
32778
|
+
onText(text) {
|
|
32779
|
+
if (!this.stack.length) return;
|
|
32780
|
+
const node = this.stack[this.stack.length - 1];
|
|
32781
|
+
if (!node) return;
|
|
32782
|
+
const children = node.children ?? [];
|
|
32783
|
+
const last = children[children.length - 1];
|
|
32784
|
+
if (typeof last === "string") children[children.length - 1] = last + text;
|
|
32785
|
+
else children.push(text);
|
|
32786
|
+
node.children = children;
|
|
32787
|
+
}
|
|
32788
|
+
onCdata(text) {
|
|
32789
|
+
this.onText(text);
|
|
32790
|
+
}
|
|
32791
|
+
onCloseTag() {
|
|
32792
|
+
if (this.stack.length === 0) throw new XmlSaxBuildError("Closing tag without matching open tag", "tree");
|
|
32793
|
+
this.stack.pop();
|
|
32794
|
+
}
|
|
32795
|
+
consume(token) {
|
|
32796
|
+
if (token instanceof OpenTagToken) {
|
|
32797
|
+
this.onOpenTag(token.tag);
|
|
32798
|
+
return;
|
|
32799
|
+
}
|
|
32800
|
+
if (token instanceof TextToken) {
|
|
32801
|
+
this.onText(token.text);
|
|
32802
|
+
return;
|
|
32803
|
+
}
|
|
32804
|
+
if (token instanceof CdataToken) {
|
|
32805
|
+
this.onCdata(token.text);
|
|
32806
|
+
return;
|
|
32807
|
+
}
|
|
32808
|
+
this.onCloseTag();
|
|
32667
32809
|
}
|
|
32668
32810
|
getRoot() {
|
|
32669
|
-
if (!this.root) throw new
|
|
32811
|
+
if (!this.root) throw new XmlSaxBuildError("No root element found", "tree");
|
|
32670
32812
|
return this.root;
|
|
32671
32813
|
}
|
|
32672
32814
|
};
|
|
32673
32815
|
function parseXmlString(xml, options = {}) {
|
|
32674
32816
|
const builder = new TreeBuilder();
|
|
32675
|
-
const parser = new XmlSaxParser(
|
|
32676
|
-
|
|
32677
|
-
|
|
32678
|
-
onText: builder.onText,
|
|
32679
|
-
onCdata: builder.onCdata,
|
|
32680
|
-
onCloseTag: builder.onCloseTag
|
|
32681
|
-
});
|
|
32682
|
-
parser.feed(xml);
|
|
32683
|
-
parser.close();
|
|
32817
|
+
const parser = new XmlSaxParser(options);
|
|
32818
|
+
for (const token of parser.feed(xml)) if (isBuildToken(token)) builder.consume(token);
|
|
32819
|
+
for (const token of parser.close()) if (isBuildToken(token)) builder.consume(token);
|
|
32684
32820
|
return builder.getRoot();
|
|
32685
32821
|
}
|
|
32686
32822
|
var DEFAULT_OPTIONS2 = {
|
|
@@ -32764,6 +32900,7 @@ function buildXmlSettings(options) {
|
|
|
32764
32900
|
}
|
|
32765
32901
|
function buildNode(node, options, path) {
|
|
32766
32902
|
const name = normalizeName(node.name, options);
|
|
32903
|
+
const nextPath = [...path, name];
|
|
32767
32904
|
const state = {
|
|
32768
32905
|
attributes: normalizeAttributeMap(node.attributes ?? {}, options),
|
|
32769
32906
|
textParts: [],
|
|
@@ -32775,9 +32912,9 @@ function buildNode(node, options, path) {
|
|
|
32775
32912
|
if (child) state.textParts.push(child);
|
|
32776
32913
|
continue;
|
|
32777
32914
|
}
|
|
32778
|
-
const value = buildNode(child, options,
|
|
32915
|
+
const value = buildNode(child, options, nextPath);
|
|
32779
32916
|
const childName = normalizeName(child.name, options);
|
|
32780
|
-
addChild(state.children, childName, value, options,
|
|
32917
|
+
addChild(state.children, childName, value, options, () => nextPath.slice());
|
|
32781
32918
|
}
|
|
32782
32919
|
return finalizeElement(state, options);
|
|
32783
32920
|
}
|
|
@@ -32814,7 +32951,7 @@ function shouldForceArray(name, path, options) {
|
|
|
32814
32951
|
const rule = options.arrayElements;
|
|
32815
32952
|
if (!rule) return false;
|
|
32816
32953
|
if (rule instanceof Set) return rule.has(name);
|
|
32817
|
-
return rule(name, path);
|
|
32954
|
+
return rule(name, typeof path === "function" ? path() : path);
|
|
32818
32955
|
}
|
|
32819
32956
|
function resolveRoot(obj, options) {
|
|
32820
32957
|
if (isRecord(obj)) {
|
|
@@ -32827,7 +32964,7 @@ function resolveRoot(obj, options) {
|
|
|
32827
32964
|
};
|
|
32828
32965
|
}
|
|
32829
32966
|
}
|
|
32830
|
-
if (!options.rootName) throw new
|
|
32967
|
+
if (!options.rootName) throw new XmlSaxBuildError("Root element name is required when object has multiple keys", "xml-builder");
|
|
32831
32968
|
return {
|
|
32832
32969
|
name: options.rootName,
|
|
32833
32970
|
value: obj
|
|
@@ -32862,8 +32999,8 @@ function buildElement(name, value, options, path) {
|
|
|
32862
32999
|
return finalizeNode(name, attributes, children);
|
|
32863
33000
|
}
|
|
32864
33001
|
function addChildElements(children, name, value, options, path) {
|
|
32865
|
-
|
|
32866
|
-
const items = Array.isArray(value) ? value :
|
|
33002
|
+
shouldForceArray(name, path, options);
|
|
33003
|
+
const items = Array.isArray(value) ? value : [value];
|
|
32867
33004
|
for (const item of items) {
|
|
32868
33005
|
if (item === void 0 || item === null) {
|
|
32869
33006
|
children.push({ name });
|