@amazon/vinyl-xml 1.0.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/index.cjs +976 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +986 -0
- package/dist/index.js.map +7 -0
- package/dist/types/current/index.d.ts +14 -0
- package/dist/types/current/index.d.ts.map +1 -0
- package/dist/types/current/index.js +13 -0
- package/dist/types/current/tsconfig.tsbuildinfo +1 -0
- package/dist/types/current/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/current/xlink/actuateValidator.d.ts.map +1 -0
- package/dist/types/current/xlink/actuateValidator.js +11 -0
- package/dist/types/current/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/current/xml/ParseXmlHandler.d.ts.map +1 -0
- package/dist/types/current/xml/ParseXmlHandler.js +5 -0
- package/dist/types/current/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/current/xml/ParseXmlHandlerImpl.d.ts.map +1 -0
- package/dist/types/current/xml/ParseXmlHandlerImpl.js +198 -0
- package/dist/types/current/xml/QName.d.ts +33 -0
- package/dist/types/current/xml/QName.d.ts.map +1 -0
- package/dist/types/current/xml/QName.js +19 -0
- package/dist/types/current/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/current/xml/XmlSchemaError.d.ts.map +1 -0
- package/dist/types/current/xml/XmlSchemaError.js +23 -0
- package/dist/types/current/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/current/xml/mappedXmlRules.d.ts.map +1 -0
- package/dist/types/current/xml/mappedXmlRules.js +122 -0
- package/dist/types/current/xml/mergeXmlRules.d.ts +62 -0
- package/dist/types/current/xml/mergeXmlRules.d.ts.map +1 -0
- package/dist/types/current/xml/mergeXmlRules.js +89 -0
- package/dist/types/current/xml/parseXml.d.ts +76 -0
- package/dist/types/current/xml/parseXml.d.ts.map +1 -0
- package/dist/types/current/xml/parseXml.js +305 -0
- package/dist/types/current/xml/stringifyXml.d.ts +67 -0
- package/dist/types/current/xml/stringifyXml.d.ts.map +1 -0
- package/dist/types/current/xml/stringifyXml.js +225 -0
- package/dist/types/current/xml/xmlRules.d.ts +207 -0
- package/dist/types/current/xml/xmlRules.d.ts.map +1 -0
- package/dist/types/current/xml/xmlRules.js +134 -0
- package/dist/types/current/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/current/xmlns/org/w3/1999/xlink.d.ts.map +1 -0
- package/dist/types/current/xmlns/org/w3/1999/xlink.js +5 -0
- package/dist/types/current/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/dist/types/current/xmlns/org/w3/2001/XmlSchema.d.ts.map +1 -0
- package/dist/types/current/xmlns/org/w3/2001/XmlSchema.js +5 -0
- package/dist/types/ts3.7/index.d.ts +14 -0
- package/dist/types/ts3.7/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/ts3.7/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/ts3.7/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/ts3.7/xml/QName.d.ts +33 -0
- package/dist/types/ts3.7/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/ts3.7/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/ts3.7/xml/mergeXmlRules.d.ts +118 -0
- package/dist/types/ts3.7/xml/parseXml.d.ts +76 -0
- package/dist/types/ts3.7/xml/stringifyXml.d.ts +67 -0
- package/dist/types/ts3.7/xml/xmlRules.d.ts +207 -0
- package/dist/types/ts3.7/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/ts3.7/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/dist/types/ts4.1/index.d.ts +14 -0
- package/dist/types/ts4.1/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/ts4.1/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/ts4.1/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/ts4.1/xml/QName.d.ts +33 -0
- package/dist/types/ts4.1/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/ts4.1/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/ts4.1/xml/mergeXmlRules.d.ts +118 -0
- package/dist/types/ts4.1/xml/parseXml.d.ts +77 -0
- package/dist/types/ts4.1/xml/stringifyXml.d.ts +67 -0
- package/dist/types/ts4.1/xml/xmlRules.d.ts +207 -0
- package/dist/types/ts4.1/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/ts4.1/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/dist/types/ts4.7/index.d.ts +14 -0
- package/dist/types/ts4.7/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/ts4.7/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/ts4.7/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/ts4.7/xml/QName.d.ts +33 -0
- package/dist/types/ts4.7/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/ts4.7/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/ts4.7/xml/mergeXmlRules.d.ts +118 -0
- package/dist/types/ts4.7/xml/parseXml.d.ts +76 -0
- package/dist/types/ts4.7/xml/stringifyXml.d.ts +67 -0
- package/dist/types/ts4.7/xml/xmlRules.d.ts +207 -0
- package/dist/types/ts4.7/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/ts4.7/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/docs/XML_PARSING.md +210 -0
- package/package.json +82 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,986 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/xml/xmlRules.ts
|
|
23
|
+
import {
|
|
24
|
+
parseDate,
|
|
25
|
+
stringifyDate,
|
|
26
|
+
parseBoolean,
|
|
27
|
+
stringify
|
|
28
|
+
} from "@amazon/vinyl-util";
|
|
29
|
+
var XmlRuleType = /* @__PURE__ */ ((XmlRuleType2) => {
|
|
30
|
+
XmlRuleType2["CHARACTERS"] = "characters";
|
|
31
|
+
XmlRuleType2["ATTRIBUTE"] = "attribute";
|
|
32
|
+
XmlRuleType2["ELEMENT"] = "element";
|
|
33
|
+
XmlRuleType2["ELEMENTS"] = "elements";
|
|
34
|
+
return XmlRuleType2;
|
|
35
|
+
})(XmlRuleType || {});
|
|
36
|
+
function element(rules, options) {
|
|
37
|
+
return __spreadProps(__spreadValues({
|
|
38
|
+
type: "element" /* ELEMENT */,
|
|
39
|
+
localPart: void 0,
|
|
40
|
+
namespaceUri: void 0,
|
|
41
|
+
required: false
|
|
42
|
+
}, options), {
|
|
43
|
+
rules
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function elements(rules, options) {
|
|
47
|
+
return __spreadProps(__spreadValues({
|
|
48
|
+
type: "elements" /* ELEMENTS */,
|
|
49
|
+
localPart: void 0,
|
|
50
|
+
namespaceUri: void 0,
|
|
51
|
+
minOccurs: 0,
|
|
52
|
+
maxOccurs: null,
|
|
53
|
+
useEmptyArrays: false
|
|
54
|
+
}, options), {
|
|
55
|
+
rules
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function characters(parse, stringify2) {
|
|
59
|
+
return { type: "characters" /* CHARACTERS */, parse, stringify: stringify2 };
|
|
60
|
+
}
|
|
61
|
+
var charactersString = /* @__PURE__ */ characters((i) => i, stringify);
|
|
62
|
+
function attr(parse, stringify2, options) {
|
|
63
|
+
return __spreadProps(__spreadValues({
|
|
64
|
+
type: "attribute" /* ATTRIBUTE */,
|
|
65
|
+
localPart: void 0,
|
|
66
|
+
namespaceUri: null,
|
|
67
|
+
required: false,
|
|
68
|
+
default: void 0
|
|
69
|
+
}, options), {
|
|
70
|
+
parse,
|
|
71
|
+
stringify: stringify2
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function attrString(options) {
|
|
75
|
+
return attr((i) => i, stringify, options);
|
|
76
|
+
}
|
|
77
|
+
function attrInt(options) {
|
|
78
|
+
return attr(parseInt, stringify, options);
|
|
79
|
+
}
|
|
80
|
+
function attrFloat(options) {
|
|
81
|
+
return attr(parseFloat, stringify, options);
|
|
82
|
+
}
|
|
83
|
+
function attrBoolean(options) {
|
|
84
|
+
return attr(parseBoolean, stringify, options);
|
|
85
|
+
}
|
|
86
|
+
function attrDateTime(options) {
|
|
87
|
+
return attr(parseDate, stringifyDate, options);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/xml/stringifyXml.ts
|
|
91
|
+
import {
|
|
92
|
+
encodeEntities,
|
|
93
|
+
equalDeep,
|
|
94
|
+
getOrSet,
|
|
95
|
+
substitute
|
|
96
|
+
} from "@amazon/vinyl-util";
|
|
97
|
+
|
|
98
|
+
// src/xml/XmlSchemaError.ts
|
|
99
|
+
import { ErrorOrigin, ReportableError } from "@amazon/vinyl-util";
|
|
100
|
+
var xmlSchemaErrorLocale = {
|
|
101
|
+
atLeastElements: "Expected at least {expected} occurrences of {property} but was {actual}",
|
|
102
|
+
atMostElements: "Expected at most {expected} occurrences of {property} but was {actual}",
|
|
103
|
+
cyclicReferences: "Cyclic reference detected",
|
|
104
|
+
requiredAttribute: `Attribute '{property}' is required`
|
|
105
|
+
};
|
|
106
|
+
var XmlSchemaError = class _XmlSchemaError extends ReportableError {
|
|
107
|
+
get [Symbol.toStringTag]() {
|
|
108
|
+
return "XmlSchemaError";
|
|
109
|
+
}
|
|
110
|
+
constructor(message) {
|
|
111
|
+
super(message, ErrorOrigin.PARSING);
|
|
112
|
+
Object.setPrototypeOf(this, _XmlSchemaError.prototype);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/xml/stringifyXml.ts
|
|
117
|
+
var locale = {
|
|
118
|
+
/**
|
|
119
|
+
* When a namespace binding is generated, if the prefix was not provided in the stringifier
|
|
120
|
+
* options, it will be generated from this template.
|
|
121
|
+
*/
|
|
122
|
+
prefixTemplate: "ns_{value}"
|
|
123
|
+
};
|
|
124
|
+
var defaultStringifyOptions = {
|
|
125
|
+
indent: " ",
|
|
126
|
+
newline: "\n",
|
|
127
|
+
prefixMap: /* @__PURE__ */ new Map(),
|
|
128
|
+
includeXmlDeclaration: true
|
|
129
|
+
};
|
|
130
|
+
var XmlWriter = class {
|
|
131
|
+
constructor(rules, options) {
|
|
132
|
+
this.rules = rules;
|
|
133
|
+
__publicField(this, "options");
|
|
134
|
+
__publicField(this, "usedPrefixes", /* @__PURE__ */ new Map());
|
|
135
|
+
__publicField(this, "traversed", /* @__PURE__ */ new Set());
|
|
136
|
+
this.options = __spreadValues(__spreadValues({}, defaultStringifyOptions), options);
|
|
137
|
+
}
|
|
138
|
+
stringify(object) {
|
|
139
|
+
let str = this.options.includeXmlDeclaration ? '<?xml version="1.0"?>' + this.options.newline : "";
|
|
140
|
+
const state = new StringifyState();
|
|
141
|
+
str += this.stringifyChildren(object, this.rules.elements, state);
|
|
142
|
+
this.usedPrefixes.clear();
|
|
143
|
+
this.traversed.clear();
|
|
144
|
+
return str;
|
|
145
|
+
}
|
|
146
|
+
qName(localPart, namespaceUri) {
|
|
147
|
+
if (!namespaceUri) return localPart;
|
|
148
|
+
const prefixMap = this.options.prefixMap;
|
|
149
|
+
const prefix = getOrSet(this.usedPrefixes, namespaceUri, () => {
|
|
150
|
+
if (prefixMap.has(namespaceUri)) {
|
|
151
|
+
return prefixMap.get(namespaceUri);
|
|
152
|
+
}
|
|
153
|
+
return substitute(locale.prefixTemplate, {
|
|
154
|
+
value: (this.usedPrefixes.size + 1).toString(36)
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
return `${prefix}:${localPart}`;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Stringifies an element.
|
|
161
|
+
*
|
|
162
|
+
* @param object
|
|
163
|
+
* @param rule
|
|
164
|
+
* @param state
|
|
165
|
+
*/
|
|
166
|
+
stringifyElement(object, rule, state) {
|
|
167
|
+
var _a2;
|
|
168
|
+
if (this.traversed.has(object))
|
|
169
|
+
throw new XmlSchemaError(xmlSchemaErrorLocale.cyclicReferences);
|
|
170
|
+
this.traversed.add(object);
|
|
171
|
+
const nl = this.options.newline;
|
|
172
|
+
const isDocument = state.depth === 0;
|
|
173
|
+
let namespaces = "";
|
|
174
|
+
let xmlns = state.xmlns;
|
|
175
|
+
if (xmlns !== rule.namespaceUri && (xmlns == null || !rule.namespaceUri)) {
|
|
176
|
+
xmlns = rule.namespaceUri;
|
|
177
|
+
namespaces += ` xmlns="${(_a2 = rule.namespaceUri) != null ? _a2 : ""}"`;
|
|
178
|
+
}
|
|
179
|
+
const childState = state.createChild(xmlns, this.options.indent);
|
|
180
|
+
const rules = rule.rules();
|
|
181
|
+
const attributes = this.stringifyAttributes(object, rules.attributes);
|
|
182
|
+
const children = this.stringifyChildren(
|
|
183
|
+
object,
|
|
184
|
+
rules.elements,
|
|
185
|
+
childState
|
|
186
|
+
);
|
|
187
|
+
const text = this.stringifyCharacters(object, rules.characters);
|
|
188
|
+
if (isDocument) {
|
|
189
|
+
this.usedPrefixes.forEach((prefix, uri) => {
|
|
190
|
+
namespaces += ` xmlns:${prefix}="${uri}"`;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const indent = state.indent;
|
|
194
|
+
const childIndent = childState.indent;
|
|
195
|
+
const qName2 = rule.namespaceUri === xmlns ? rule.localPart : this.qName(rule.localPart, rule.namespaceUri);
|
|
196
|
+
let str = `${indent}<${qName2}${namespaces}${attributes}`;
|
|
197
|
+
if (children) {
|
|
198
|
+
str += `>`;
|
|
199
|
+
if (text) str += `${nl}${childIndent}${text}`;
|
|
200
|
+
str += nl + children;
|
|
201
|
+
str += `${nl}${indent}</${qName2}>`;
|
|
202
|
+
} else if (text) {
|
|
203
|
+
str += `>${text}</${qName2}>`;
|
|
204
|
+
} else {
|
|
205
|
+
str += "/>";
|
|
206
|
+
}
|
|
207
|
+
return str;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Stringifies an element's attributes.
|
|
211
|
+
*
|
|
212
|
+
* @param object
|
|
213
|
+
* @param attributes
|
|
214
|
+
* @return Returns the attributes string. This will include a leading space if there are any
|
|
215
|
+
* found attributes.
|
|
216
|
+
*/
|
|
217
|
+
stringifyAttributes(object, attributes) {
|
|
218
|
+
let str = "";
|
|
219
|
+
attributes.forEach((attributeRule) => {
|
|
220
|
+
const propertyValue = object[attributeRule.property];
|
|
221
|
+
if (propertyValue !== void 0) {
|
|
222
|
+
const attributeValue = attributeRule.stringify(propertyValue);
|
|
223
|
+
if (attributeRule.default === void 0 || !equalDeep(propertyValue, attributeRule.default)) {
|
|
224
|
+
str += ` ${this.qName(
|
|
225
|
+
attributeRule.localPart,
|
|
226
|
+
attributeRule.namespaceUri
|
|
227
|
+
)}="${encodeEntities(attributeValue)}"`;
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
if (attributeRule.required) {
|
|
231
|
+
throw new XmlSchemaError(
|
|
232
|
+
substitute(xmlSchemaErrorLocale.requiredAttribute, {
|
|
233
|
+
property: attributeRule.property
|
|
234
|
+
})
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
return str;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Stringifies a property as a CDATA node.
|
|
243
|
+
*
|
|
244
|
+
* @param object
|
|
245
|
+
* @param charactersRule
|
|
246
|
+
*/
|
|
247
|
+
stringifyCharacters(object, charactersRule) {
|
|
248
|
+
if (!charactersRule) return null;
|
|
249
|
+
const str = charactersRule.stringify(object[charactersRule.property]);
|
|
250
|
+
if (!str) return "";
|
|
251
|
+
return `<![CDATA[${str}]]>`;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Stringifies an element's child elements.
|
|
255
|
+
*
|
|
256
|
+
* @param object
|
|
257
|
+
* @param elements
|
|
258
|
+
* @param state
|
|
259
|
+
*/
|
|
260
|
+
stringifyChildren(object, elements2, state) {
|
|
261
|
+
let str = "";
|
|
262
|
+
elements2.forEach((elementsRule) => {
|
|
263
|
+
const child = object[elementsRule.property];
|
|
264
|
+
if (child) {
|
|
265
|
+
if (elementsRule.array) {
|
|
266
|
+
const arr = child;
|
|
267
|
+
if (elementsRule.minOccurs > arr.length) {
|
|
268
|
+
throw new XmlSchemaError(
|
|
269
|
+
substitute(xmlSchemaErrorLocale.atLeastElements, {
|
|
270
|
+
property: elementsRule.property,
|
|
271
|
+
expected: elementsRule.minOccurs,
|
|
272
|
+
actual: arr.length
|
|
273
|
+
})
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
if (elementsRule.maxOccurs != null && elementsRule.maxOccurs < arr.length) {
|
|
277
|
+
throw new XmlSchemaError(
|
|
278
|
+
substitute(xmlSchemaErrorLocale.atMostElements, {
|
|
279
|
+
property: elementsRule.property,
|
|
280
|
+
expected: elementsRule.maxOccurs,
|
|
281
|
+
actual: arr.length
|
|
282
|
+
})
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
for (const element2 of arr) {
|
|
286
|
+
if (str) str += this.options.newline;
|
|
287
|
+
str += this.stringifyElement(
|
|
288
|
+
element2,
|
|
289
|
+
elementsRule,
|
|
290
|
+
state
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
if (str) str += this.options.newline;
|
|
295
|
+
str += this.stringifyElement(child, elementsRule, state);
|
|
296
|
+
}
|
|
297
|
+
} else {
|
|
298
|
+
if (elementsRule.minOccurs > 0) {
|
|
299
|
+
throw new XmlSchemaError(
|
|
300
|
+
substitute(xmlSchemaErrorLocale.atLeastElements, {
|
|
301
|
+
property: elementsRule.property,
|
|
302
|
+
expected: elementsRule.minOccurs,
|
|
303
|
+
actual: 0
|
|
304
|
+
})
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
return str;
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
var StringifyState = class _StringifyState {
|
|
313
|
+
constructor(depth = 0, xmlns = null, indent = "") {
|
|
314
|
+
this.depth = depth;
|
|
315
|
+
this.xmlns = xmlns;
|
|
316
|
+
this.indent = indent;
|
|
317
|
+
}
|
|
318
|
+
createChild(xmlns, indent) {
|
|
319
|
+
return new _StringifyState(this.depth + 1, xmlns, this.indent + indent);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
function stringifyXml(object, rules, options) {
|
|
323
|
+
const writer = new XmlWriter(rules, options);
|
|
324
|
+
return writer.stringify(object);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// src/xml/parseXml.ts
|
|
328
|
+
import {
|
|
329
|
+
char,
|
|
330
|
+
decodeEntities,
|
|
331
|
+
last,
|
|
332
|
+
StringReader
|
|
333
|
+
} from "@amazon/vinyl-util";
|
|
334
|
+
var XMLNS = "http://www.w3.org/2000/xmlns/";
|
|
335
|
+
var LT = /* @__PURE__ */ char("<");
|
|
336
|
+
var GT = /* @__PURE__ */ char(">");
|
|
337
|
+
var EQ = /* @__PURE__ */ char("=");
|
|
338
|
+
var SLASH = /* @__PURE__ */ char("/");
|
|
339
|
+
var COLON = /* @__PURE__ */ char(":");
|
|
340
|
+
var QMARK = /* @__PURE__ */ char("?");
|
|
341
|
+
var EXCL = /* @__PURE__ */ char("!");
|
|
342
|
+
var APOS = /* @__PURE__ */ char("'");
|
|
343
|
+
var QUOT = /* @__PURE__ */ char('"');
|
|
344
|
+
var QUOTES = /* @__PURE__ */ new Set([APOS, QUOT]);
|
|
345
|
+
function parseXml(str, handler) {
|
|
346
|
+
const c = new StringReader(str);
|
|
347
|
+
let current = {
|
|
348
|
+
qName: "#document",
|
|
349
|
+
namespaceMap: /* @__PURE__ */ new Map(),
|
|
350
|
+
defaultNamespaceUri: null
|
|
351
|
+
};
|
|
352
|
+
const stack = [current];
|
|
353
|
+
const namespaceLookup = (prefix) => {
|
|
354
|
+
if (!prefix) return current.defaultNamespaceUri;
|
|
355
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
356
|
+
const map = stack[i].namespaceMap;
|
|
357
|
+
if (map.has(prefix)) return stack[i].namespaceMap.get(prefix);
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
};
|
|
361
|
+
try {
|
|
362
|
+
handler.startDocument();
|
|
363
|
+
} catch (e) {
|
|
364
|
+
c.err(e.message);
|
|
365
|
+
}
|
|
366
|
+
while (c.hasNext()) {
|
|
367
|
+
const charsStart = c.untilChar(LT);
|
|
368
|
+
if (charsStart < c.position) {
|
|
369
|
+
const chars = str.substring(charsStart, c.position);
|
|
370
|
+
try {
|
|
371
|
+
handler.textNode(chars);
|
|
372
|
+
} catch (e) {
|
|
373
|
+
c.err(e.message);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (!c.hasNext()) break;
|
|
377
|
+
c.next();
|
|
378
|
+
if (c.charIf(SLASH)) {
|
|
379
|
+
c.white();
|
|
380
|
+
const name = readQName(c);
|
|
381
|
+
if (name.qName !== current.qName)
|
|
382
|
+
c.err(`Expected </${current.qName}> but was </${name.qName}>`);
|
|
383
|
+
stack.pop();
|
|
384
|
+
current = last(stack);
|
|
385
|
+
c.white();
|
|
386
|
+
c.readChar(GT);
|
|
387
|
+
try {
|
|
388
|
+
handler.endElement();
|
|
389
|
+
} catch (e) {
|
|
390
|
+
c.err(e.message);
|
|
391
|
+
}
|
|
392
|
+
} else if (c.charIf(QMARK)) {
|
|
393
|
+
untilTagClose(c);
|
|
394
|
+
} else if (c.charIf(EXCL)) {
|
|
395
|
+
if (c.charIf(
|
|
396
|
+
45
|
|
397
|
+
/* - */
|
|
398
|
+
)) {
|
|
399
|
+
c.readChar(45);
|
|
400
|
+
c.untilString("-->");
|
|
401
|
+
c.read("-->");
|
|
402
|
+
} else if (c.stringIf("[CDATA[")) {
|
|
403
|
+
const charsStart2 = c.untilString("]]>");
|
|
404
|
+
try {
|
|
405
|
+
handler.cDataNode(str.substring(charsStart2, c.position));
|
|
406
|
+
} catch (e) {
|
|
407
|
+
c.err(e.message);
|
|
408
|
+
}
|
|
409
|
+
c.read("]]>");
|
|
410
|
+
} else {
|
|
411
|
+
untilTagClose(c);
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
const name = readQName(c);
|
|
415
|
+
current = {
|
|
416
|
+
qName: name.qName,
|
|
417
|
+
namespaceMap: /* @__PURE__ */ new Map(),
|
|
418
|
+
defaultNamespaceUri: current.defaultNamespaceUri
|
|
419
|
+
};
|
|
420
|
+
stack.push(current);
|
|
421
|
+
const attributes = xmlAttributes(c, current);
|
|
422
|
+
name.namespaceUri = namespaceLookup(name.prefix);
|
|
423
|
+
for (const attributesKey in attributes) {
|
|
424
|
+
const value = attributes[attributesKey];
|
|
425
|
+
const name2 = value.name;
|
|
426
|
+
if (name2.prefix && !name2.namespaceUri) {
|
|
427
|
+
name2.namespaceUri = namespaceLookup(name2.prefix);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
try {
|
|
431
|
+
handler.startElement(name, attributes);
|
|
432
|
+
} catch (e) {
|
|
433
|
+
c.err(e.message);
|
|
434
|
+
}
|
|
435
|
+
if (c.charIf(SLASH)) {
|
|
436
|
+
c.readChar(GT);
|
|
437
|
+
stack.pop();
|
|
438
|
+
current = last(stack);
|
|
439
|
+
try {
|
|
440
|
+
handler.endElement();
|
|
441
|
+
} catch (e) {
|
|
442
|
+
c.err(e.message);
|
|
443
|
+
}
|
|
444
|
+
} else {
|
|
445
|
+
c.readChar(GT);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
try {
|
|
450
|
+
return handler.endDocument();
|
|
451
|
+
} catch (e) {
|
|
452
|
+
return c.err(e.message);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function readAttributeValue(c) {
|
|
456
|
+
const quote = c.next();
|
|
457
|
+
if (!QUOTES.has(quote)) c.err(`Expected ' or "`);
|
|
458
|
+
const value = c.substringUntil((charCode) => charCode === quote);
|
|
459
|
+
c.readChar(quote);
|
|
460
|
+
return decodeEntities(value);
|
|
461
|
+
}
|
|
462
|
+
function untilTagClose(c) {
|
|
463
|
+
while (true) {
|
|
464
|
+
c.until((c2) => c2 === APOS || c2 === QUOT || c2 === GT);
|
|
465
|
+
const char2 = c.next();
|
|
466
|
+
if (QUOTES.has(char2)) {
|
|
467
|
+
c.untilChar(char2);
|
|
468
|
+
c.next();
|
|
469
|
+
} else {
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function isNameChar(charCode) {
|
|
475
|
+
if (charCode >= 97) {
|
|
476
|
+
if (charCode >= 183) {
|
|
477
|
+
if (charCode >= 768) {
|
|
478
|
+
if (charCode >= 8255) {
|
|
479
|
+
return charCode <= 8256;
|
|
480
|
+
} else {
|
|
481
|
+
return charCode <= 879;
|
|
482
|
+
}
|
|
483
|
+
} else {
|
|
484
|
+
return charCode === 183;
|
|
485
|
+
}
|
|
486
|
+
} else {
|
|
487
|
+
return charCode <= 122;
|
|
488
|
+
}
|
|
489
|
+
} else {
|
|
490
|
+
if (charCode >= 95) {
|
|
491
|
+
return charCode === 95;
|
|
492
|
+
} else {
|
|
493
|
+
if (charCode >= 65) {
|
|
494
|
+
return charCode <= 90;
|
|
495
|
+
} else {
|
|
496
|
+
if (charCode >= 45) {
|
|
497
|
+
if (charCode >= 48) {
|
|
498
|
+
return charCode <= 57;
|
|
499
|
+
} else {
|
|
500
|
+
return charCode <= 46;
|
|
501
|
+
}
|
|
502
|
+
} else {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
function readQName(reader) {
|
|
510
|
+
const prefixOrLocalName = reader.substringWhile(isNameChar);
|
|
511
|
+
let prefix, localPart, name;
|
|
512
|
+
if (reader.charIf(COLON)) {
|
|
513
|
+
prefix = prefixOrLocalName;
|
|
514
|
+
localPart = reader.substringWhile(isNameChar);
|
|
515
|
+
name = `${prefix}:${localPart}`;
|
|
516
|
+
} else {
|
|
517
|
+
prefix = null;
|
|
518
|
+
localPart = prefixOrLocalName;
|
|
519
|
+
name = localPart;
|
|
520
|
+
}
|
|
521
|
+
return { prefix, localPart, qName: name, namespaceUri: null };
|
|
522
|
+
}
|
|
523
|
+
function xmlAttributes(reader, stackElement) {
|
|
524
|
+
const attributes = {};
|
|
525
|
+
while (true) {
|
|
526
|
+
reader.white();
|
|
527
|
+
if (!isNameChar(reader.peek)) break;
|
|
528
|
+
const name = readQName(reader);
|
|
529
|
+
reader.white();
|
|
530
|
+
let value = "";
|
|
531
|
+
if (reader.charIf(EQ)) {
|
|
532
|
+
reader.white();
|
|
533
|
+
value = readAttributeValue(reader);
|
|
534
|
+
} else {
|
|
535
|
+
}
|
|
536
|
+
if (name.prefix === "xmlns") {
|
|
537
|
+
name.namespaceUri = XMLNS;
|
|
538
|
+
stackElement.namespaceMap.set(
|
|
539
|
+
name.localPart,
|
|
540
|
+
value === "" ? null : value
|
|
541
|
+
);
|
|
542
|
+
} else if (!name.prefix && name.localPart === "xmlns") {
|
|
543
|
+
name.namespaceUri = XMLNS;
|
|
544
|
+
stackElement.defaultNamespaceUri = !value ? null : value;
|
|
545
|
+
}
|
|
546
|
+
if (attributes[name.qName] != null)
|
|
547
|
+
reader.err(`Attribute '${name.qName}' is already specified.`);
|
|
548
|
+
attributes[name.qName] = { name, value };
|
|
549
|
+
}
|
|
550
|
+
return attributes;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
// src/xml/mergeXmlRules.ts
|
|
554
|
+
import {
|
|
555
|
+
plainObjectMergeRule,
|
|
556
|
+
substitute as substitute2,
|
|
557
|
+
ValidationError
|
|
558
|
+
} from "@amazon/vinyl-util";
|
|
559
|
+
var locale2 = {
|
|
560
|
+
illegalRuleOverrideTypeError: "Cannot override the rule {property} of type {sourceType} with a rule of type {overrideType}",
|
|
561
|
+
illegalQNameOverrideError: "Cannot override the rule {property} with a different localPart or namespace"
|
|
562
|
+
};
|
|
563
|
+
function mergeXmlRules(...rules) {
|
|
564
|
+
let finalRule = rules[0];
|
|
565
|
+
for (let i = 1; i < rules.length; i++) {
|
|
566
|
+
finalRule = plainObjectMergeRule.merge(
|
|
567
|
+
finalRule,
|
|
568
|
+
rules[i],
|
|
569
|
+
mergeXmlRule
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
return finalRule;
|
|
573
|
+
}
|
|
574
|
+
function mergeXmlRule(sourceA, sourceB, prop) {
|
|
575
|
+
var _a2, _b, _c, _d;
|
|
576
|
+
if (sourceA == null) return sourceB;
|
|
577
|
+
const sourceAIsLazy = typeof sourceA === "function";
|
|
578
|
+
const sourceBIsLazy = typeof sourceB === "function";
|
|
579
|
+
if (sourceAIsLazy || sourceBIsLazy) {
|
|
580
|
+
return () => {
|
|
581
|
+
const a = sourceAIsLazy ? sourceA() : sourceA;
|
|
582
|
+
const b = sourceBIsLazy ? sourceB() : sourceB;
|
|
583
|
+
return mergeXmlRule(a, b, prop);
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
if (sourceA.type !== sourceB.type) {
|
|
587
|
+
throw new ValidationError(
|
|
588
|
+
substitute2(locale2.illegalRuleOverrideTypeError, {
|
|
589
|
+
property: prop,
|
|
590
|
+
sourceType: sourceA.type,
|
|
591
|
+
overrideType: sourceB.type
|
|
592
|
+
})
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
switch (sourceA.type) {
|
|
596
|
+
case "attribute" /* ATTRIBUTE */:
|
|
597
|
+
case "element" /* ELEMENT */:
|
|
598
|
+
case "elements" /* ELEMENTS */: {
|
|
599
|
+
const b = sourceB;
|
|
600
|
+
if (sourceA.namespaceUri !== b.namespaceUri || ((_a2 = sourceA.localPart) != null ? _a2 : prop) !== ((_b = b.localPart) != null ? _b : prop)) {
|
|
601
|
+
throw new ValidationError(
|
|
602
|
+
substitute2(locale2.illegalQNameOverrideError, {
|
|
603
|
+
property: prop
|
|
604
|
+
})
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
break;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
switch (sourceA.type) {
|
|
611
|
+
case "attribute" /* ATTRIBUTE */: {
|
|
612
|
+
const b = sourceB;
|
|
613
|
+
return __spreadProps(__spreadValues({}, b), {
|
|
614
|
+
default: (_c = b.default) != null ? _c : sourceA.default
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
case "characters" /* CHARACTERS */:
|
|
618
|
+
return sourceB;
|
|
619
|
+
case "element" /* ELEMENT */: {
|
|
620
|
+
const b = sourceB;
|
|
621
|
+
return __spreadProps(__spreadValues({}, b), {
|
|
622
|
+
required: sourceA.required || b.required,
|
|
623
|
+
rules: mergeXmlRules(sourceA.rules, b.rules)
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
case "elements" /* ELEMENTS */: {
|
|
627
|
+
const b = sourceB;
|
|
628
|
+
const maxOccurs = sourceA.maxOccurs != null && b.maxOccurs != null ? Math.min(sourceA.maxOccurs, b.maxOccurs) : (_d = sourceA.maxOccurs) != null ? _d : b.maxOccurs;
|
|
629
|
+
return __spreadProps(__spreadValues({}, b), {
|
|
630
|
+
minOccurs: Math.max(sourceA.minOccurs, b.minOccurs),
|
|
631
|
+
maxOccurs,
|
|
632
|
+
useEmptyArrays: sourceA.useEmptyArrays || b.useEmptyArrays,
|
|
633
|
+
rules: mergeXmlRules(sourceA.rules, b.rules)
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// src/xml/mappedXmlRules.ts
|
|
640
|
+
import {
|
|
641
|
+
IllegalArgumentError,
|
|
642
|
+
invariant,
|
|
643
|
+
memoize
|
|
644
|
+
} from "@amazon/vinyl-util";
|
|
645
|
+
var EmptyRules = {
|
|
646
|
+
__type: /* @__PURE__ */ invariant(),
|
|
647
|
+
attributes: /* @__PURE__ */ new Map(),
|
|
648
|
+
elements: /* @__PURE__ */ new Map(),
|
|
649
|
+
characters: void 0
|
|
650
|
+
};
|
|
651
|
+
function mapXmlRules(rules, parentNamespaceUri = null) {
|
|
652
|
+
var _a2, _b, _c;
|
|
653
|
+
const attributeRules = /* @__PURE__ */ new Map();
|
|
654
|
+
const elementRules = /* @__PURE__ */ new Map();
|
|
655
|
+
let charactersRule = void 0;
|
|
656
|
+
for (const property in rules) {
|
|
657
|
+
const handlerOrFunction = rules[property];
|
|
658
|
+
let handler;
|
|
659
|
+
if (typeof handlerOrFunction === "function") {
|
|
660
|
+
handler = handlerOrFunction();
|
|
661
|
+
} else {
|
|
662
|
+
handler = handlerOrFunction;
|
|
663
|
+
}
|
|
664
|
+
let key;
|
|
665
|
+
switch (handler.type) {
|
|
666
|
+
case "characters" /* CHARACTERS */:
|
|
667
|
+
if (charactersRule !== void 0)
|
|
668
|
+
throw new IllegalArgumentError(
|
|
669
|
+
"characters handler already defined"
|
|
670
|
+
);
|
|
671
|
+
charactersRule = {
|
|
672
|
+
property,
|
|
673
|
+
parse: handler.parse,
|
|
674
|
+
stringify: handler.stringify
|
|
675
|
+
};
|
|
676
|
+
break;
|
|
677
|
+
case "element" /* ELEMENT */:
|
|
678
|
+
case "elements" /* ELEMENTS */: {
|
|
679
|
+
const localPart = (_a2 = handler.localPart) != null ? _a2 : property;
|
|
680
|
+
const namespaceUri = handler.namespaceUri === void 0 ? parentNamespaceUri : handler.namespaceUri;
|
|
681
|
+
key = xmlRuleKey(localPart, namespaceUri);
|
|
682
|
+
if (elementRules.has(key)) {
|
|
683
|
+
throw new IllegalArgumentError(
|
|
684
|
+
`Multiple element rules for ${key}`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
if (handler.type === "element" /* ELEMENT */) {
|
|
688
|
+
const rules2 = handler.rules;
|
|
689
|
+
elementRules.set(key, {
|
|
690
|
+
array: false,
|
|
691
|
+
property,
|
|
692
|
+
minOccurs: handler.required ? 1 : 0,
|
|
693
|
+
maxOccurs: 1,
|
|
694
|
+
rules: memoize(() => mapXmlRules(rules2, namespaceUri)),
|
|
695
|
+
useEmptyArrays: false,
|
|
696
|
+
localPart,
|
|
697
|
+
namespaceUri
|
|
698
|
+
});
|
|
699
|
+
} else {
|
|
700
|
+
const rules2 = handler.rules;
|
|
701
|
+
elementRules.set(key, {
|
|
702
|
+
array: true,
|
|
703
|
+
property,
|
|
704
|
+
maxOccurs: handler.maxOccurs,
|
|
705
|
+
minOccurs: handler.minOccurs,
|
|
706
|
+
rules: memoize(() => mapXmlRules(rules2, namespaceUri)),
|
|
707
|
+
useEmptyArrays: handler.useEmptyArrays,
|
|
708
|
+
localPart,
|
|
709
|
+
namespaceUri
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
break;
|
|
713
|
+
}
|
|
714
|
+
case "attribute" /* ATTRIBUTE */: {
|
|
715
|
+
const namespaceUri = handler.namespaceUri;
|
|
716
|
+
const localPart = (_b = handler.localPart) != null ? _b : property;
|
|
717
|
+
key = xmlRuleKey(localPart, namespaceUri);
|
|
718
|
+
if (attributeRules.has(key)) {
|
|
719
|
+
throw new IllegalArgumentError(
|
|
720
|
+
`Multiple attribute rules for ${key}`
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
attributeRules.set(key, {
|
|
724
|
+
property,
|
|
725
|
+
default: handler.default,
|
|
726
|
+
parse: handler.parse,
|
|
727
|
+
stringify: handler.stringify,
|
|
728
|
+
required: handler.required,
|
|
729
|
+
localPart,
|
|
730
|
+
namespaceUri: (_c = handler.namespaceUri) != null ? _c : null
|
|
731
|
+
});
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return {
|
|
737
|
+
__type: invariant(),
|
|
738
|
+
attributes: attributeRules,
|
|
739
|
+
elements: elementRules,
|
|
740
|
+
characters: charactersRule
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function xmlRuleKey(localPart, namespaceUri = null) {
|
|
744
|
+
return `${namespaceUri != null ? namespaceUri : ""}:${localPart}`;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// src/xml/QName.ts
|
|
748
|
+
function qName(localPart, prefix = null, namespaceUri = null) {
|
|
749
|
+
return {
|
|
750
|
+
localPart,
|
|
751
|
+
prefix,
|
|
752
|
+
namespaceUri,
|
|
753
|
+
qName: prefix ? `${prefix}:${localPart}` : localPart
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// src/xml/ParseXmlHandlerImpl.ts
|
|
758
|
+
import {
|
|
759
|
+
clone,
|
|
760
|
+
decodeEntities as decodeEntities2,
|
|
761
|
+
IllegalStateError,
|
|
762
|
+
last as last2,
|
|
763
|
+
substitute as substitute3,
|
|
764
|
+
toJson
|
|
765
|
+
} from "@amazon/vinyl-util";
|
|
766
|
+
function getRule(name, rules) {
|
|
767
|
+
return rules.get(xmlRuleKey(name.localPart, name.namespaceUri));
|
|
768
|
+
}
|
|
769
|
+
var ParseXmlHandlerImpl = class {
|
|
770
|
+
constructor(rules, options) {
|
|
771
|
+
this.rules = rules;
|
|
772
|
+
__publicField(this, "stack", []);
|
|
773
|
+
__publicField(this, "options");
|
|
774
|
+
__publicField(this, "busy", false);
|
|
775
|
+
this.options = __spreadValues({ validateRules: true }, options);
|
|
776
|
+
}
|
|
777
|
+
startDocument() {
|
|
778
|
+
if (this.busy)
|
|
779
|
+
throw new IllegalStateError("XML content handler is busy");
|
|
780
|
+
this.busy = true;
|
|
781
|
+
const rules = this.rules;
|
|
782
|
+
this.stack.push({
|
|
783
|
+
element: new XmlElementImpl(),
|
|
784
|
+
rules,
|
|
785
|
+
characters: ""
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
startElement(name, attributes) {
|
|
789
|
+
var _a2;
|
|
790
|
+
const parent = last2(this.stack);
|
|
791
|
+
let element2 = null;
|
|
792
|
+
const elementRule = getRule(name, parent.rules.elements);
|
|
793
|
+
const rules = (_a2 = elementRule == null ? void 0 : elementRule.rules()) != null ? _a2 : EmptyRules;
|
|
794
|
+
if (elementRule) {
|
|
795
|
+
const prop = elementRule.property;
|
|
796
|
+
element2 = new XmlElementImpl(parent.element);
|
|
797
|
+
if (elementRule.array) {
|
|
798
|
+
const arr = parent.element[prop];
|
|
799
|
+
if (Array.isArray(arr)) {
|
|
800
|
+
arr.push(element2);
|
|
801
|
+
} else {
|
|
802
|
+
parent.element[prop] = [element2];
|
|
803
|
+
}
|
|
804
|
+
} else {
|
|
805
|
+
if (parent.element[prop]) {
|
|
806
|
+
throw new XmlSchemaError(
|
|
807
|
+
`Expected single element with name ${name.qName}`
|
|
808
|
+
);
|
|
809
|
+
} else {
|
|
810
|
+
parent.element[prop] = element2;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
const attributeRules = rules.attributes;
|
|
814
|
+
for (const k in attributes) {
|
|
815
|
+
const attribute = attributes[k];
|
|
816
|
+
const name2 = attribute.name;
|
|
817
|
+
const attributeRule = getRule(name2, attributeRules);
|
|
818
|
+
if (attributeRule) {
|
|
819
|
+
element2[attributeRule.property] = attributeRule.parse(
|
|
820
|
+
attribute.value
|
|
821
|
+
);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
attributeRules.forEach((_value, key) => {
|
|
825
|
+
const rule = attributeRules.get(key);
|
|
826
|
+
if (!(rule.property in element2)) {
|
|
827
|
+
if (rule.default != null) {
|
|
828
|
+
element2[rule.property] = rule.default;
|
|
829
|
+
} else if (this.options.validateRules && rule.required) {
|
|
830
|
+
throw new XmlSchemaError(
|
|
831
|
+
substitute3(xmlSchemaErrorLocale.requiredAttribute, {
|
|
832
|
+
property: rule.property
|
|
833
|
+
})
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
this.stack.push({
|
|
840
|
+
element: element2,
|
|
841
|
+
rules,
|
|
842
|
+
characters: ""
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
textNode(str) {
|
|
846
|
+
const current = last2(this.stack);
|
|
847
|
+
if (!current.rules.characters) return;
|
|
848
|
+
current.characters += decodeEntities2(str.trim());
|
|
849
|
+
}
|
|
850
|
+
cDataNode(str) {
|
|
851
|
+
const current = last2(this.stack);
|
|
852
|
+
if (!current.rules.characters) return;
|
|
853
|
+
current.characters += str;
|
|
854
|
+
}
|
|
855
|
+
endElement() {
|
|
856
|
+
const lastEl = this.stack.pop();
|
|
857
|
+
const charactersRule = lastEl.rules.characters;
|
|
858
|
+
if (charactersRule)
|
|
859
|
+
lastEl.element[charactersRule.property] = charactersRule.parse(
|
|
860
|
+
lastEl.characters
|
|
861
|
+
);
|
|
862
|
+
lastEl.rules.elements.forEach((rule) => {
|
|
863
|
+
if (rule.array && !(rule.property in lastEl.element)) {
|
|
864
|
+
if (rule.useEmptyArrays) {
|
|
865
|
+
lastEl.element[rule.property] = [];
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
this.validate(lastEl);
|
|
870
|
+
}
|
|
871
|
+
endDocument() {
|
|
872
|
+
this.busy = false;
|
|
873
|
+
const last3 = this.stack.pop();
|
|
874
|
+
this.validate(last3);
|
|
875
|
+
return last3.element;
|
|
876
|
+
}
|
|
877
|
+
validate(current) {
|
|
878
|
+
if (!this.options.validateRules) return;
|
|
879
|
+
current.rules.elements.forEach((rule) => {
|
|
880
|
+
var _a2, _b;
|
|
881
|
+
const length = rule.array ? (_b = (_a2 = current.element[rule.property]) == null ? void 0 : _a2.length) != null ? _b : 0 : current.element[rule.property] ? 1 : 0;
|
|
882
|
+
if (length < rule.minOccurs) {
|
|
883
|
+
throw new XmlSchemaError(
|
|
884
|
+
substitute3(xmlSchemaErrorLocale.atLeastElements, {
|
|
885
|
+
property: rule.property,
|
|
886
|
+
expected: rule.minOccurs,
|
|
887
|
+
actual: length
|
|
888
|
+
})
|
|
889
|
+
);
|
|
890
|
+
}
|
|
891
|
+
if (rule.maxOccurs != null && length > rule.maxOccurs) {
|
|
892
|
+
throw new XmlSchemaError(
|
|
893
|
+
substitute3(xmlSchemaErrorLocale.atMostElements, {
|
|
894
|
+
property: rule.property,
|
|
895
|
+
expected: rule.maxOccurs,
|
|
896
|
+
actual: length
|
|
897
|
+
})
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
function parseXmlHandler(rules, options) {
|
|
904
|
+
return new ParseXmlHandlerImpl(mapXmlRules(rules), options);
|
|
905
|
+
}
|
|
906
|
+
var parentSymbol = /* @__PURE__ */ Symbol("parent");
|
|
907
|
+
var _a;
|
|
908
|
+
_a = parentSymbol;
|
|
909
|
+
var _XmlElementImpl = class _XmlElementImpl {
|
|
910
|
+
constructor(parent = null) {
|
|
911
|
+
__publicField(this, _a);
|
|
912
|
+
this[parentSymbol] = parent;
|
|
913
|
+
}
|
|
914
|
+
get parent() {
|
|
915
|
+
return this[parentSymbol];
|
|
916
|
+
}
|
|
917
|
+
set parent(value) {
|
|
918
|
+
this[parentSymbol] = value;
|
|
919
|
+
}
|
|
920
|
+
clone() {
|
|
921
|
+
const out = new _XmlElementImpl(this.parent);
|
|
922
|
+
for (const key in this) {
|
|
923
|
+
const child = clone(this[key]);
|
|
924
|
+
if (Array.isArray(child)) {
|
|
925
|
+
for (const e of child) {
|
|
926
|
+
if (typeof e === "object" && "parent" in e) e.parent = out;
|
|
927
|
+
}
|
|
928
|
+
} else if (typeof child === "object" && "parent" in child) {
|
|
929
|
+
child.parent = out;
|
|
930
|
+
}
|
|
931
|
+
out[key] = child;
|
|
932
|
+
}
|
|
933
|
+
return out;
|
|
934
|
+
}
|
|
935
|
+
toJSON() {
|
|
936
|
+
const out = {};
|
|
937
|
+
for (const key in this) {
|
|
938
|
+
out[key] = toJson(this[key]);
|
|
939
|
+
}
|
|
940
|
+
return out;
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
var XmlElementImpl = _XmlElementImpl;
|
|
944
|
+
|
|
945
|
+
// src/xlink/actuateValidator.ts
|
|
946
|
+
import { isOneOf } from "@amazon/vinyl-validation";
|
|
947
|
+
import { ErrorOrigin as ErrorOrigin2 } from "@amazon/vinyl-util";
|
|
948
|
+
var actuateValidator = /* @__PURE__ */ isOneOf("onLoad", "onRequest");
|
|
949
|
+
function assertActuateEnum(str) {
|
|
950
|
+
actuateValidator.assert(str, ErrorOrigin2.PARSING);
|
|
951
|
+
return str;
|
|
952
|
+
}
|
|
953
|
+
export {
|
|
954
|
+
EmptyRules,
|
|
955
|
+
ParseXmlHandlerImpl,
|
|
956
|
+
XMLNS,
|
|
957
|
+
XmlElementImpl,
|
|
958
|
+
XmlRuleType,
|
|
959
|
+
XmlSchemaError,
|
|
960
|
+
XmlWriter,
|
|
961
|
+
assertActuateEnum,
|
|
962
|
+
attr,
|
|
963
|
+
attrBoolean,
|
|
964
|
+
attrDateTime,
|
|
965
|
+
attrFloat,
|
|
966
|
+
attrInt,
|
|
967
|
+
attrString,
|
|
968
|
+
characters,
|
|
969
|
+
charactersString,
|
|
970
|
+
element,
|
|
971
|
+
elements,
|
|
972
|
+
isNameChar,
|
|
973
|
+
mapXmlRules,
|
|
974
|
+
mergeXmlRules,
|
|
975
|
+
parseXml,
|
|
976
|
+
parseXmlHandler,
|
|
977
|
+
qName,
|
|
978
|
+
readAttributeValue,
|
|
979
|
+
readQName,
|
|
980
|
+
stringifyXml,
|
|
981
|
+
untilTagClose,
|
|
982
|
+
xmlAttributes,
|
|
983
|
+
xmlRuleKey,
|
|
984
|
+
xmlSchemaErrorLocale
|
|
985
|
+
};
|
|
986
|
+
//# sourceMappingURL=index.js.map
|