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