@flighthq/xml 0.5.1-next.973.788d3d7 → 0.6.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/README.md +2 -2
- package/dist/contract.d.ts +3 -2
- package/dist/contract.d.ts.map +1 -1
- package/dist/contract.js +4 -2
- package/dist/contract.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +14 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/xmlNative.d.ts +24 -0
- package/dist/xmlNative.d.ts.map +1 -0
- package/dist/xmlNative.js +198 -0
- package/dist/xmlNative.js.map +1 -0
- package/dist/xmlParse.d.ts +12 -7
- package/dist/xmlParse.d.ts.map +1 -1
- package/dist/xmlParse.js +111 -226
- package/dist/xmlParse.js.map +1 -1
- package/dist/xmlQuery.d.ts +16 -6
- package/dist/xmlQuery.d.ts.map +1 -1
- package/dist/xmlQuery.js +42 -16
- package/dist/xmlQuery.js.map +1 -1
- package/package.json +4 -5
- package/src/xmlNative.test.ts +206 -0
- package/src/xmlParse.test.ts +170 -212
- package/src/xmlQuery.test.ts +38 -37
package/dist/xmlParse.js
CHANGED
|
@@ -1,271 +1,156 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
// (& < > " ' plus numeric references), general entities declared in a DOCTYPE's
|
|
5
|
-
// internal subset, XML comments (<!-- -->), CDATA sections (<![CDATA[...]]>), the XML declaration,
|
|
6
|
-
// and DOCTYPE.
|
|
7
|
-
/** Parse all attributes from an element's attribute string.
|
|
8
|
-
* Supports double-quoted and single-quoted values and XML entity escapes. */
|
|
9
|
-
export function parseXmlAttributes(attrs) {
|
|
10
|
-
const result = {};
|
|
11
|
-
// Match name="value" or name='value', capturing both quote styles
|
|
12
|
-
const re = /([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
13
|
-
let m;
|
|
14
|
-
while ((m = re.exec(attrs)) !== null) {
|
|
15
|
-
const attrName = m[1];
|
|
16
|
-
const value = m[2] !== undefined ? m[2] : (m[3] ?? '');
|
|
17
|
-
result[attrName] = decodeXmlEntities(value);
|
|
18
|
-
}
|
|
19
|
-
return result;
|
|
20
|
-
}
|
|
21
|
-
/** Parse a simple XML document into a tree of XmlElement objects.
|
|
22
|
-
* Returns the root element, or null when the input contains no recognizable element.
|
|
23
|
-
* Does not validate DTD, namespaces, or processing instructions. */
|
|
24
|
-
export function parseXmlDocument(xml) {
|
|
25
|
-
// Normalize: strip comments and normalize line endings.
|
|
26
|
-
let src = stripXmlComments(xml).replace(/\r\n?/g, '\n');
|
|
27
|
-
// Strip XML declaration and DOCTYPE before parsing the root element. The DOCTYPE is discarded but
|
|
28
|
-
// its internal subset is read on the way out, because a general entity's replacement text is markup
|
|
29
|
-
// and so has to be substituted into the source before the tree is built, not decoded out of a text
|
|
30
|
-
// node afterwards.
|
|
31
|
-
const entities = {};
|
|
32
|
-
src = stripXmlDoctypes(src.replace(/<\?[\s\S]*?\?>/g, ''), entities).trim();
|
|
33
|
-
return parseElement(expandXmlEntities(src, entities), { depth: 0, depthExceeded: false, pos: 0 });
|
|
34
|
-
}
|
|
35
|
-
// An entity may nest a few levels legitimately; past that a document is recursing, not composing.
|
|
36
|
-
const MAX_XML_ENTITY_PASSES = 8;
|
|
37
|
-
const MAX_XML_ENTITY_GROWTH = 16;
|
|
38
|
-
const MAX_XML_ENTITY_BUDGET = 65536;
|
|
39
|
-
// Authored XML rarely nests beyond a few dozen elements. This leaves an order of magnitude of margin
|
|
40
|
-
// while stopping recursion well below the engine-dependent call-stack limit.
|
|
41
|
-
const MAX_XML_ELEMENT_DEPTH = 256;
|
|
42
|
-
const XML_ENTITIES = {
|
|
43
|
-
amp: '&',
|
|
44
|
-
apos: "'",
|
|
45
|
-
gt: '>',
|
|
46
|
-
lt: '<',
|
|
47
|
-
quot: '"',
|
|
48
|
-
};
|
|
1
|
+
// Generated from crates/flight-xml/src/xml_parse.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { createXmlRecord, createXmlScanner, decodeXmlEntitiesNative, expandXmlEntitiesNative, parseXmlAttributesNative, prepareXmlDocumentNative, pushXmlElementContent, pushXmlTextContent, xmlIsWhitespace, xmlScannerFind, xmlScannerLength, xmlScannerStartsWith, xmlScannerUnitAt, xmlTrim, xmlUtf16Slice, } from './xmlNative.js';
|
|
49
4
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* A replacement may itself reference an entity, so expansion repeats until it settles. Both the pass
|
|
53
|
-
* count and the resulting size are capped: entities that reference each other are otherwise an
|
|
54
|
-
* exponential bomb ("billion laughs"), and the budget is what keeps a hostile document costing
|
|
55
|
-
* bounded work. Exhausting the budget stops expansion and keeps what resolved, since a partially
|
|
56
|
-
* expanded document still parses.
|
|
57
|
-
*
|
|
58
|
-
* Only the predefined five and declared general entities substitute. An undeclared reference is left
|
|
59
|
-
* alone for `decodeXmlEntities` to see as text.
|
|
5
|
+
* Authored XML rarely nests beyond a few dozen elements. This leaves an order of magnitude of
|
|
6
|
+
* margin while stopping recursion well below the engine-dependent call-stack limit.
|
|
60
7
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
for (let pass = 0; pass < MAX_XML_ENTITY_PASSES; pass++) {
|
|
65
|
-
let expanded = false;
|
|
66
|
-
const next = output.replace(/&([\w:.-]+);/g, (reference, name) => {
|
|
67
|
-
const replacement = entities[name];
|
|
68
|
-
if (replacement === undefined)
|
|
69
|
-
return reference;
|
|
70
|
-
expanded = true;
|
|
71
|
-
return replacement;
|
|
72
|
-
});
|
|
73
|
-
if (!expanded || next.length > budget)
|
|
74
|
-
return output;
|
|
75
|
-
output = next;
|
|
76
|
-
}
|
|
77
|
-
return output;
|
|
78
|
-
}
|
|
79
|
-
function decodeXmlEntities(s) {
|
|
80
|
-
return s.replace(/&(?:#(\d+)|#x([\da-fA-F]+)|(\w+));/g, (reference, dec, hex, name) => {
|
|
81
|
-
const numeric = dec ?? hex;
|
|
82
|
-
if (numeric !== undefined) {
|
|
83
|
-
const codepoint = parseInt(numeric, dec !== undefined ? 10 : 16);
|
|
84
|
-
if (codepoint > 0x10ffff || (codepoint >= 0xd800 && codepoint <= 0xdfff))
|
|
85
|
-
return reference;
|
|
86
|
-
return String.fromCodePoint(codepoint);
|
|
87
|
-
}
|
|
88
|
-
return XML_ENTITIES[name] ?? reference;
|
|
89
|
-
});
|
|
8
|
+
const MAX_XML_ELEMENT_DEPTH = 256;
|
|
9
|
+
function isTagNameEnd(unit) {
|
|
10
|
+
return xmlIsWhitespace(unit) || unit === 62 || unit === 47;
|
|
90
11
|
}
|
|
91
|
-
function parseElement(
|
|
12
|
+
function parseElement(source, scanner, state) {
|
|
92
13
|
if (state.depth >= MAX_XML_ELEMENT_DEPTH) {
|
|
93
14
|
state.depthExceeded = true;
|
|
94
15
|
return null;
|
|
95
16
|
}
|
|
96
|
-
|
|
97
|
-
|
|
17
|
+
const len = xmlScannerLength(scanner);
|
|
18
|
+
state.pos = skipWhitespace(scanner, state.pos);
|
|
19
|
+
if (state.pos >= len || xmlScannerUnitAt(scanner, state.pos) !== 60) {
|
|
98
20
|
return null;
|
|
99
|
-
// Find the end of the opening tag
|
|
100
|
-
state.pos++; // consume '<'
|
|
101
|
-
// Skip processing instructions
|
|
102
|
-
if (src[state.pos] === '?') {
|
|
103
|
-
const end = src.indexOf('?>', state.pos);
|
|
104
|
-
state.pos = end >= 0 ? end + 2 : src.length;
|
|
105
|
-
return parseElement(src, state);
|
|
106
21
|
}
|
|
107
|
-
|
|
22
|
+
state.pos++;
|
|
23
|
+
if (state.pos < len && xmlScannerUnitAt(scanner, state.pos) === 63) {
|
|
24
|
+
const instructionEnd = xmlScannerFind(scanner, '?>', state.pos);
|
|
25
|
+
if (instructionEnd !== null) {
|
|
26
|
+
const end = instructionEnd;
|
|
27
|
+
state.pos = end + 2;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
state.pos = len;
|
|
31
|
+
}
|
|
32
|
+
return parseElement(source, scanner, state);
|
|
33
|
+
}
|
|
108
34
|
const nameStart = state.pos;
|
|
109
|
-
while (state.pos <
|
|
35
|
+
while (state.pos < len && !isTagNameEnd(xmlScannerUnitAt(scanner, state.pos))) {
|
|
110
36
|
state.pos++;
|
|
111
|
-
|
|
112
|
-
|
|
37
|
+
}
|
|
38
|
+
const name = xmlUtf16Slice(source, nameStart, state.pos);
|
|
39
|
+
if (name.length === 0) {
|
|
113
40
|
return null;
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
quote = '';
|
|
41
|
+
}
|
|
42
|
+
state.pos = skipWhitespace(scanner, state.pos);
|
|
43
|
+
const attributesStart = state.pos;
|
|
44
|
+
let quote = 0;
|
|
45
|
+
while (state.pos < len) {
|
|
46
|
+
const unit = xmlScannerUnitAt(scanner, state.pos);
|
|
47
|
+
if (quote !== 0) {
|
|
48
|
+
if (unit === quote) {
|
|
49
|
+
quote = 0;
|
|
50
|
+
}
|
|
125
51
|
}
|
|
126
|
-
else if (
|
|
127
|
-
quote =
|
|
52
|
+
else if (unit === 34 || unit === 39) {
|
|
53
|
+
quote = unit;
|
|
128
54
|
}
|
|
129
|
-
else if (
|
|
55
|
+
else if (unit === 62 || (unit === 47 && state.pos + 1 < len && xmlScannerUnitAt(scanner, state.pos + 1) === 62)) {
|
|
130
56
|
break;
|
|
131
57
|
}
|
|
132
|
-
attrsStr += ch;
|
|
133
58
|
state.pos++;
|
|
134
59
|
}
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
60
|
+
const attributesSource = xmlUtf16Slice(source, attributesStart, state.pos);
|
|
61
|
+
const selfClosing = state.pos < len && xmlScannerUnitAt(scanner, state.pos) === 47;
|
|
62
|
+
state.pos += selfClosing ? 2 : 1;
|
|
63
|
+
const attributes = parseXmlAttributes(attributesSource);
|
|
64
|
+
let children = [];
|
|
65
|
+
let content = [];
|
|
140
66
|
let text = '';
|
|
141
67
|
if (!selfClosing) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (state.pos >= src.length)
|
|
145
|
-
break;
|
|
146
|
-
if (src[state.pos] !== '<') {
|
|
147
|
-
// Text node
|
|
68
|
+
while (state.pos < len) {
|
|
69
|
+
if (xmlScannerUnitAt(scanner, state.pos) !== 60) {
|
|
148
70
|
const textStart = state.pos;
|
|
149
|
-
while (state.pos <
|
|
71
|
+
while (state.pos < len && xmlScannerUnitAt(scanner, state.pos) !== 60) {
|
|
150
72
|
state.pos++;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
73
|
+
}
|
|
74
|
+
const decoded = decodeXmlEntitiesNative(xmlUtf16Slice(source, textStart, state.pos));
|
|
75
|
+
text += xmlTrim(decoded);
|
|
76
|
+
if (decoded.length !== 0) {
|
|
77
|
+
pushXmlTextContent(content, decoded);
|
|
78
|
+
}
|
|
155
79
|
continue;
|
|
156
80
|
}
|
|
157
|
-
if (
|
|
81
|
+
if (xmlScannerStartsWith(scanner, state.pos, '<![CDATA[')) {
|
|
158
82
|
const cdataStart = state.pos + 9;
|
|
159
|
-
const cdataEnd =
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
83
|
+
const cdataEnd = xmlScannerFind(scanner, ']]>', cdataStart);
|
|
84
|
+
if (cdataEnd !== null) {
|
|
85
|
+
const end = cdataEnd;
|
|
86
|
+
const cdata = xmlUtf16Slice(source, cdataStart, end);
|
|
87
|
+
text += xmlTrim(cdata);
|
|
88
|
+
if (cdata.length !== 0) {
|
|
89
|
+
pushXmlTextContent(content, cdata);
|
|
90
|
+
}
|
|
91
|
+
state.pos = end + 3;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const cdata = xmlUtf16Slice(source, cdataStart, len);
|
|
95
|
+
text += xmlTrim(cdata);
|
|
96
|
+
if (cdata.length !== 0) {
|
|
97
|
+
pushXmlTextContent(content, cdata);
|
|
98
|
+
}
|
|
99
|
+
state.pos = len;
|
|
100
|
+
}
|
|
166
101
|
continue;
|
|
167
102
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
// Skip to '>'
|
|
171
|
-
while (state.pos < src.length && src[state.pos] !== '>')
|
|
103
|
+
if (state.pos + 1 < len && xmlScannerUnitAt(scanner, state.pos + 1) === 47) {
|
|
104
|
+
while (state.pos < len && xmlScannerUnitAt(scanner, state.pos) !== 62) {
|
|
172
105
|
state.pos++;
|
|
173
|
-
|
|
106
|
+
}
|
|
107
|
+
if (state.pos < len) {
|
|
108
|
+
state.pos++;
|
|
109
|
+
}
|
|
174
110
|
break;
|
|
175
111
|
}
|
|
176
112
|
state.depth++;
|
|
177
|
-
const
|
|
113
|
+
const parsedChild = parseElement(source, scanner, state);
|
|
178
114
|
state.depth--;
|
|
179
|
-
if (state.depthExceeded)
|
|
115
|
+
if (state.depthExceeded) {
|
|
180
116
|
return null;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
117
|
+
}
|
|
118
|
+
if (parsedChild !== null) {
|
|
119
|
+
const child = parsedChild;
|
|
120
|
+
const childRef = child;
|
|
121
|
+
children.push(childRef);
|
|
122
|
+
pushXmlElementContent(content, childRef);
|
|
184
123
|
}
|
|
185
124
|
}
|
|
186
125
|
}
|
|
187
126
|
return { attributes, children, content, name, text };
|
|
188
127
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
function
|
|
194
|
-
|
|
195
|
-
let output = '';
|
|
196
|
-
let pos = 0;
|
|
197
|
-
while (pos < xml.length) {
|
|
198
|
-
if (xml.slice(pos, pos + 9) === '<![CDATA[') {
|
|
199
|
-
const cdataEnd = xml.indexOf(']]>', pos + 9);
|
|
200
|
-
pos = cdataEnd >= 0 ? cdataEnd + 3 : xml.length;
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
if (xml.slice(pos, pos + 4) !== '<!--') {
|
|
204
|
-
pos++;
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
output += xml.slice(copyStart, pos);
|
|
208
|
-
const commentEnd = xml.indexOf('-->', pos + 4);
|
|
209
|
-
pos = commentEnd >= 0 ? commentEnd + 3 : xml.length;
|
|
210
|
-
copyStart = pos;
|
|
211
|
-
}
|
|
212
|
-
return output + xml.slice(copyStart);
|
|
128
|
+
/**
|
|
129
|
+
* Parse all attributes from an element's attribute string.
|
|
130
|
+
* Supports double-quoted and single-quoted values and XML entity escapes.
|
|
131
|
+
*/
|
|
132
|
+
export function parseXmlAttributes(attributes) {
|
|
133
|
+
return parseXmlAttributesNative(attributes);
|
|
213
134
|
}
|
|
214
135
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
* not collected: an external entity resolves a URL or a file path at parse time, which is a document
|
|
219
|
-
* reading whatever the process can reach, so the parser has no business honoring one.
|
|
136
|
+
* Parse a simple XML document into a tree of XmlElement objects.
|
|
137
|
+
* Returns the root element, or None when the input contains no recognizable element.
|
|
138
|
+
* Does not validate DTD, namespaces, or processing instructions.
|
|
220
139
|
*/
|
|
221
|
-
function
|
|
222
|
-
let
|
|
223
|
-
let
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
output += xml.slice(copyStart, pos);
|
|
231
|
-
const doctypeStart = pos;
|
|
232
|
-
pos += 9;
|
|
233
|
-
let internalSubsetDepth = 0;
|
|
234
|
-
let quote = '';
|
|
235
|
-
while (pos < xml.length) {
|
|
236
|
-
const ch = xml[pos];
|
|
237
|
-
if (quote) {
|
|
238
|
-
if (ch === quote)
|
|
239
|
-
quote = '';
|
|
240
|
-
}
|
|
241
|
-
else if (ch === '"' || ch === "'") {
|
|
242
|
-
quote = ch;
|
|
243
|
-
}
|
|
244
|
-
else if (ch === '[') {
|
|
245
|
-
internalSubsetDepth++;
|
|
246
|
-
}
|
|
247
|
-
else if (ch === ']' && internalSubsetDepth > 0) {
|
|
248
|
-
internalSubsetDepth--;
|
|
249
|
-
}
|
|
250
|
-
else if (ch === '>' && internalSubsetDepth === 0) {
|
|
251
|
-
pos++;
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
pos++;
|
|
255
|
-
}
|
|
256
|
-
collectXmlEntityDeclarations(xml.slice(doctypeStart, pos), out);
|
|
257
|
-
copyStart = pos;
|
|
258
|
-
}
|
|
259
|
-
return output + xml.slice(copyStart);
|
|
140
|
+
export function parseXmlDocument(xml) {
|
|
141
|
+
let entities = createXmlRecord();
|
|
142
|
+
let source = prepareXmlDocumentNative(xml, entities);
|
|
143
|
+
source = xmlTrim(source);
|
|
144
|
+
const expanded = expandXmlEntitiesNative(source, entities);
|
|
145
|
+
const scanner = createXmlScanner(expanded);
|
|
146
|
+
let state = { depth: 0, depthExceeded: false, pos: 0 };
|
|
147
|
+
return parseElement(expanded, scanner, state);
|
|
260
148
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
const declaration = /<!ENTITY\s+([\w:.-]+)\s*(?:"([^"]*)"|'([^']*)')\s*>/g;
|
|
266
|
-
let match;
|
|
267
|
-
while ((match = declaration.exec(doctype)) !== null) {
|
|
268
|
-
out[match[1]] = match[2] ?? match[3] ?? '';
|
|
149
|
+
function skipWhitespace(scanner, position) {
|
|
150
|
+
const len = xmlScannerLength(scanner);
|
|
151
|
+
while (position < len && xmlIsWhitespace(xmlScannerUnitAt(scanner, position))) {
|
|
152
|
+
position++;
|
|
269
153
|
}
|
|
154
|
+
return position;
|
|
270
155
|
}
|
|
271
156
|
//# sourceMappingURL=xmlParse.js.map
|
package/dist/xmlParse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xmlParse.js","sourceRoot":"","sources":["../src/xmlParse.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"xmlParse.js","sourceRoot":"","sources":["../src/xmlParse.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,mEAAmE;AAInE,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,uBAAuB,EACvB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EAChB,OAAO,EACP,aAAa,GACd,MAAM,gBAAgB,CAAC;AAQxB;;;GAGG;AACH,MAAM,qBAAqB,GAAW,GAAG,CAAC;AAE1C,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,CAAC;AAC7D,CAAC;AAED,SAAS,YAAY,CAAC,MAAc,EAAE,OAA6B,EAAE,KAAiB;IACpF,IAAI,KAAK,CAAC,KAAK,IAAI,qBAAqB,EAAE,CAAC;QACzC,KAAK,CAAC,aAAa,GAAG,IAAI,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACtC,KAAK,CAAC,GAAG,GAAG,cAAc,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;IAC/C,IAAI,KAAK,CAAC,GAAG,IAAI,GAAG,IAAI,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC;QACpE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,KAAK,CAAC,GAAG,EAAE,CAAC;IACZ,IAAI,KAAK,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kBAAkB,CAAC,UAAkB;IACnD,OAAO,wBAAwB,CAAC,UAAU,CAAC,CAAC;AAC9C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,IAAI,QAAQ,GAAG,eAAe,EAAE,CAAC;IACjC,IAAI,MAAM,GAAG,wBAAwB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IACrD,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzB,MAAM,QAAQ,GAAG,uBAAuB,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC3C,IAAI,KAAK,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;IACvD,OAAO,YAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,cAAc,CAAC,OAA6B,EAAE,QAAgB;IACrE,MAAM,GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACtC,OAAO,QAAQ,GAAG,GAAG,IAAI,eAAe,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC;QAC9E,QAAQ,EAAE,CAAC;IACb,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/xmlQuery.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import type { XmlElement } from '
|
|
2
|
-
/**
|
|
1
|
+
import type { XmlElement } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* The attribute value for `name`, or None when the element has no such attribute.
|
|
4
|
+
*/
|
|
3
5
|
export declare function getXmlElementAttribute(element: Readonly<XmlElement>, name: string): string | null;
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
+
/**
|
|
7
|
+
* The attribute value for `name` parsed as a number, or None when the
|
|
8
|
+
* attribute is absent or does not parse to a finite number.
|
|
9
|
+
*/
|
|
6
10
|
export declare function getXmlElementAttributeNumber(element: Readonly<XmlElement>, name: string): number | null;
|
|
7
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* The first direct child element with tag name `name`, or None when none matches.
|
|
13
|
+
* Returns a cloned shared handle, so the caller keeps the node alive independently.
|
|
14
|
+
*/
|
|
8
15
|
export declare function getXmlElementChildByName(element: Readonly<XmlElement>, name: string): XmlElement | null;
|
|
9
|
-
/**
|
|
16
|
+
/**
|
|
17
|
+
* All direct child elements with tag name `name`, in document order (empty when none match).
|
|
18
|
+
* Returns cloned shared handles, so the caller keeps the nodes alive independently.
|
|
19
|
+
*/
|
|
10
20
|
export declare function getXmlElementChildrenByName(element: Readonly<XmlElement>, name: string): XmlElement[];
|
|
11
21
|
//# sourceMappingURL=xmlQuery.d.ts.map
|
package/dist/xmlQuery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xmlQuery.d.ts","sourceRoot":"","sources":["../src/xmlQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xmlQuery.d.ts","sourceRoot":"","sources":["../src/xmlQuery.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAG7C;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEjG;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAgBvG;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAOvG;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAQrG"}
|
package/dist/xmlQuery.js
CHANGED
|
@@ -1,30 +1,56 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
/**
|
|
1
|
+
// Generated from crates/flight-xml/src/xml_query.rs by flight-compiler.
|
|
2
|
+
// Rust is authoritative; run `npm run generate` after changing it.
|
|
3
|
+
import { getXmlRecordValue, parseXmlNumberNative, xmlTrim } from './xmlNative.js';
|
|
4
|
+
/**
|
|
5
|
+
* The attribute value for `name`, or None when the element has no such attribute.
|
|
6
|
+
*/
|
|
5
7
|
export function getXmlElementAttribute(element, name) {
|
|
6
|
-
|
|
7
|
-
return value !== undefined ? value : null;
|
|
8
|
+
return getXmlRecordValue(element.attributes, name);
|
|
8
9
|
}
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
10
|
+
/**
|
|
11
|
+
* The attribute value for `name` parsed as a number, or None when the
|
|
12
|
+
* attribute is absent or does not parse to a finite number.
|
|
13
|
+
*/
|
|
11
14
|
export function getXmlElementAttributeNumber(element, name) {
|
|
12
|
-
const value = element.attributes
|
|
13
|
-
if (value ===
|
|
15
|
+
const value = getXmlRecordValue(element.attributes, name);
|
|
16
|
+
if (value === null) {
|
|
14
17
|
return null;
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
}
|
|
19
|
+
if (xmlTrim(value).length === 0) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const parsed = parseXmlNumberNative(value);
|
|
23
|
+
if (parsed === null) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (Number.isFinite(parsed)) {
|
|
27
|
+
return parsed;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
17
30
|
}
|
|
18
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* The first direct child element with tag name `name`, or None when none matches.
|
|
33
|
+
* Returns a cloned shared handle, so the caller keeps the node alive independently.
|
|
34
|
+
*/
|
|
19
35
|
export function getXmlElementChildByName(element, name) {
|
|
20
36
|
for (const child of element.children) {
|
|
21
|
-
if (child.name === name)
|
|
37
|
+
if (child.name === name) {
|
|
22
38
|
return child;
|
|
39
|
+
}
|
|
23
40
|
}
|
|
24
41
|
return null;
|
|
25
42
|
}
|
|
26
|
-
/**
|
|
43
|
+
/**
|
|
44
|
+
* All direct child elements with tag name `name`, in document order (empty when none match).
|
|
45
|
+
* Returns cloned shared handles, so the caller keeps the nodes alive independently.
|
|
46
|
+
*/
|
|
27
47
|
export function getXmlElementChildrenByName(element, name) {
|
|
28
|
-
|
|
48
|
+
let out = [];
|
|
49
|
+
for (const child of element.children) {
|
|
50
|
+
if (child.name === name) {
|
|
51
|
+
out.push(child);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
29
55
|
}
|
|
30
56
|
//# sourceMappingURL=xmlQuery.js.map
|
package/dist/xmlQuery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xmlQuery.js","sourceRoot":"","sources":["../src/xmlQuery.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"xmlQuery.js","sourceRoot":"","sources":["../src/xmlQuery.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,mEAAmE;AAGnE,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAElF;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAA6B,EAAE,IAAY;IAChF,OAAO,iBAAiB,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;AACrD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAAC,OAA6B,EAAE,IAAY;IACtF,MAAM,KAAK,GAAG,iBAAiB,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC1D,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,oBAAoB,CAAC,KAAK,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAA6B,EAAE,IAAY;IAClF,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrC,IAAI,KAAM,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACzB,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,OAA6B,EAAE,IAAY;IACrF,IAAI,GAAG,GAAiB,EAAE,CAAC;IAC3B,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACrC,IAAI,KAAM,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACzB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flighthq/xml",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"author": "Joshua Granick and other contributors",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -32,16 +32,15 @@
|
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc -b",
|
|
34
34
|
"clean": "tsc -b --clean",
|
|
35
|
+
"generate": "tsx ../../scripts/generate-rust-package.ts --crate flight-xml --package xml --lenient",
|
|
36
|
+
"generate:check": "tsx ../../scripts/generate-rust-package.ts --crate flight-xml --package xml --lenient --check",
|
|
35
37
|
"test": "vitest run --config vitest.config.ts",
|
|
36
38
|
"test:watch": "vitest --watch --config vitest.config.ts",
|
|
37
39
|
"prepack": "npm run clean && npm run clean:dist && npm run build",
|
|
38
40
|
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
41
|
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@flighthq/types": "0.5.1-next.973.788d3d7"
|
|
42
|
-
},
|
|
43
42
|
"devDependencies": {
|
|
44
|
-
"typescript": "^
|
|
43
|
+
"typescript": "^7.0.2"
|
|
45
44
|
},
|
|
46
45
|
"description": "Lightweight tree-building (DOM-style) XML parser: parseXmlDocument builds an XmlElement tree, plus parseXmlAttributes and element query helpers, for atlas, plist, and sprite-sheet format files",
|
|
47
46
|
"sideEffects": false
|