@ai-sdk-tool/rxml 0.1.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/LICENSE +13 -0
- package/README.md +53 -0
- package/dist/index.cjs +2124 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +295 -0
- package/dist/index.d.ts +295 -0
- package/dist/index.js +2068 -0
- package/dist/index.js.map +1 -0
- package/index.d.ts +12 -0
- package/package.json +54 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { Transform, TransformCallback, Readable } from 'stream';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core types for the robust-xml parser
|
|
5
|
+
* Based on TXML structure but enhanced for schema-aware parsing
|
|
6
|
+
*/
|
|
7
|
+
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Represents a parsed XML node in the DOM tree
|
|
10
|
+
*/
|
|
11
|
+
interface RXMLNode {
|
|
12
|
+
tagName: string;
|
|
13
|
+
attributes: Record<string, string | null>;
|
|
14
|
+
children: (RXMLNode | string)[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for XML parsing
|
|
18
|
+
*/
|
|
19
|
+
interface ParseOptions {
|
|
20
|
+
/** Position to start parsing from (for streaming) */
|
|
21
|
+
pos?: number;
|
|
22
|
+
/** Array of tag names that don't have children and don't need to be closed */
|
|
23
|
+
noChildNodes?: string[];
|
|
24
|
+
/** Whether to set position information in result */
|
|
25
|
+
setPos?: boolean;
|
|
26
|
+
/** Keep comments in the parsed result */
|
|
27
|
+
keepComments?: boolean;
|
|
28
|
+
/** Keep whitespace like spaces, tabs and line breaks as string content */
|
|
29
|
+
keepWhitespace?: boolean;
|
|
30
|
+
/** Name of the text node property (default: "#text") */
|
|
31
|
+
textNodeName?: string;
|
|
32
|
+
/** Whether to throw on duplicate string tags */
|
|
33
|
+
throwOnDuplicateStringTags?: boolean;
|
|
34
|
+
/** Error handling callback */
|
|
35
|
+
onError?: OnErrorFn;
|
|
36
|
+
/** Whether to parse a single node instead of children */
|
|
37
|
+
parseNode?: boolean;
|
|
38
|
+
/** Filter function for nodes */
|
|
39
|
+
filter?: (node: RXMLNode, index: number, depth: number, path: string) => boolean;
|
|
40
|
+
/** Simplify the result structure */
|
|
41
|
+
simplify?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for XML stringification
|
|
45
|
+
*/
|
|
46
|
+
interface StringifyOptions {
|
|
47
|
+
/** Whether to format the output with indentation */
|
|
48
|
+
format?: boolean;
|
|
49
|
+
/** Whether to suppress empty nodes */
|
|
50
|
+
suppressEmptyNode?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to use minimal escaping per XML 1.0:
|
|
53
|
+
* - In character data: escape '&' and '<' (and '>' only in ']]>' sequence)
|
|
54
|
+
* - In attribute values: escape '&', '<', and only the wrapping quote
|
|
55
|
+
* Defaults to false (conservative escaping of &, <, >, ", ')
|
|
56
|
+
*/
|
|
57
|
+
minimalEscaping?: boolean;
|
|
58
|
+
/** Error handling callback */
|
|
59
|
+
onError?: OnErrorFn;
|
|
60
|
+
/**
|
|
61
|
+
* When true, serialize boolean-like attributes (value === null)
|
|
62
|
+
* as name="name" to follow strict XML attribute rules.
|
|
63
|
+
* When false (default), serialize as a convenience flag without value
|
|
64
|
+
* (e.g., <item checked>), for compatibility with existing outputs.
|
|
65
|
+
*/
|
|
66
|
+
strictBooleanAttributes?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Main XML parser that integrates tokenization, schema awareness, and error tolerance
|
|
71
|
+
* This replaces the fast-xml-parser dependency with a TXML-based implementation
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parse XML with schema-aware type coercion
|
|
76
|
+
*/
|
|
77
|
+
declare function parse(xmlInner: string, schema: unknown, options?: ParseOptions): Record<string, unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* Parse XML without schema (similar to TXML's parse function)
|
|
80
|
+
*/
|
|
81
|
+
declare function parseWithoutSchema(xmlString: string, options?: ParseOptions): (RXMLNode | string)[];
|
|
82
|
+
/**
|
|
83
|
+
* Parse a single XML node
|
|
84
|
+
*/
|
|
85
|
+
declare function parseNode(xmlString: string, options?: ParseOptions): RXMLNode;
|
|
86
|
+
/**
|
|
87
|
+
* Simplify parsed XML structure (similar to TXML's simplify)
|
|
88
|
+
*/
|
|
89
|
+
declare function simplify(children: (RXMLNode | string)[]): unknown;
|
|
90
|
+
/**
|
|
91
|
+
* Filter XML nodes (similar to TXML's filter)
|
|
92
|
+
*/
|
|
93
|
+
declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, depth: number, path: string) => boolean, depth?: number, path?: string): RXMLNode[];
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Streaming XML parser based on TXML's transformStream approach
|
|
97
|
+
* Provides memory-efficient parsing for large XML documents
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Transform stream for parsing XML
|
|
102
|
+
*/
|
|
103
|
+
declare class XMLTransformStream extends Transform {
|
|
104
|
+
private buffer;
|
|
105
|
+
private position;
|
|
106
|
+
private readonly parseOptions;
|
|
107
|
+
private emittedCount;
|
|
108
|
+
private sawTagChar;
|
|
109
|
+
constructor(offset?: number | string, parseOptions?: ParseOptions);
|
|
110
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
111
|
+
_flush(callback: TransformCallback): void;
|
|
112
|
+
private processBuffer;
|
|
113
|
+
/**
|
|
114
|
+
* Emit an element and recursively emit its children as separate events
|
|
115
|
+
*/
|
|
116
|
+
private emitElementAndChildren;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Create a transform stream for parsing XML
|
|
120
|
+
*/
|
|
121
|
+
declare function createXMLStream(offset?: number | string, parseOptions?: ParseOptions): XMLTransformStream;
|
|
122
|
+
/**
|
|
123
|
+
* Parse XML from a readable stream
|
|
124
|
+
*/
|
|
125
|
+
declare function parseFromStream(stream: Readable, offset?: number | string, parseOptions?: ParseOptions): Promise<(RXMLNode | string)[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Process XML stream with async iterator support
|
|
128
|
+
*/
|
|
129
|
+
declare function processXMLStream(stream: Readable, offset?: number | string, parseOptions?: ParseOptions): AsyncGenerator<RXMLNode | string, void, unknown>;
|
|
130
|
+
/**
|
|
131
|
+
* Find elements by ID in streaming fashion
|
|
132
|
+
*/
|
|
133
|
+
declare function findElementByIdStream(stream: Readable, id: string, offset?: number | string, parseOptions?: ParseOptions): AsyncGenerator<RXMLNode, void, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* Find elements by class name in streaming fashion
|
|
136
|
+
*/
|
|
137
|
+
declare function findElementsByClassStream(stream: Readable, className: string, offset?: number | string, parseOptions?: ParseOptions): AsyncGenerator<RXMLNode, void, unknown>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* XML Tokenizer based on TXML's character-by-character parsing approach
|
|
141
|
+
* with enhanced error tolerance and schema awareness
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
declare class XMLTokenizer {
|
|
145
|
+
private pos;
|
|
146
|
+
private readonly xmlString;
|
|
147
|
+
private readonly options;
|
|
148
|
+
constructor(xmlString: string, options?: ParseOptions);
|
|
149
|
+
/**
|
|
150
|
+
* Parse XML children recursively
|
|
151
|
+
*/
|
|
152
|
+
parseChildren(tagName?: string): (RXMLNode | string)[];
|
|
153
|
+
/**
|
|
154
|
+
* Parse a single XML node
|
|
155
|
+
*/
|
|
156
|
+
parseNode(): RXMLNode;
|
|
157
|
+
/**
|
|
158
|
+
* Parse text content until next tag
|
|
159
|
+
*/
|
|
160
|
+
private parseText;
|
|
161
|
+
/**
|
|
162
|
+
* Handle comments, CDATA, and DOCTYPE declarations
|
|
163
|
+
*/
|
|
164
|
+
private handleSpecialContent;
|
|
165
|
+
/**
|
|
166
|
+
* Handle XML comments
|
|
167
|
+
*/
|
|
168
|
+
private handleComment;
|
|
169
|
+
/**
|
|
170
|
+
* Handle CDATA sections
|
|
171
|
+
*/
|
|
172
|
+
private handleCData;
|
|
173
|
+
/**
|
|
174
|
+
* Handle DOCTYPE declarations
|
|
175
|
+
*/
|
|
176
|
+
private handleDoctype;
|
|
177
|
+
/**
|
|
178
|
+
* Get current position
|
|
179
|
+
*/
|
|
180
|
+
getPosition(): number;
|
|
181
|
+
/**
|
|
182
|
+
* Set position
|
|
183
|
+
*/
|
|
184
|
+
setPosition(pos: number): void;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Schema-aware type coercion for robust-xml
|
|
189
|
+
* Integrates with the existing coercion system but adds XML-specific handling
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get property schema from a parent schema
|
|
194
|
+
*/
|
|
195
|
+
declare function getPropertySchema(toolSchema: unknown, key: string): unknown;
|
|
196
|
+
/**
|
|
197
|
+
* Convert TXML-style DOM to flat object structure for schema coercion
|
|
198
|
+
*/
|
|
199
|
+
declare function domToObject(nodes: (RXMLNode | string)[], schema: unknown, textNodeName?: string): Record<string, unknown>;
|
|
200
|
+
/**
|
|
201
|
+
* Coerce DOM object using schema information
|
|
202
|
+
*/
|
|
203
|
+
declare function coerceDomBySchema(domObject: Record<string, unknown>, schema: unknown): Record<string, unknown>;
|
|
204
|
+
/**
|
|
205
|
+
* Extract string-typed property names from schema
|
|
206
|
+
*/
|
|
207
|
+
declare function getStringTypedProperties(schema: unknown): Set<string>;
|
|
208
|
+
/**
|
|
209
|
+
* Process array-like structures from XML
|
|
210
|
+
*/
|
|
211
|
+
declare function processArrayContent(value: unknown, schema: unknown, textNodeName: string): unknown;
|
|
212
|
+
/**
|
|
213
|
+
* Handle indexed tuple structures (elements with numeric keys)
|
|
214
|
+
*/
|
|
215
|
+
declare function processIndexedTuple(obj: Record<string, unknown>, textNodeName: string): unknown[];
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Raw content extraction utilities for string-typed properties
|
|
219
|
+
* This replaces the string-based extraction with DOM-based extraction
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Extract raw inner content from XML string for a specific tag
|
|
224
|
+
* This is used for string-typed properties to preserve exact content
|
|
225
|
+
*/
|
|
226
|
+
declare function extractRawInner(xmlContent: string, tagName: string): string | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* Find the first top-level range for a tag
|
|
229
|
+
*/
|
|
230
|
+
declare function findFirstTopLevelRange(xmlContent: string, tagName: string): {
|
|
231
|
+
start: number;
|
|
232
|
+
end: number;
|
|
233
|
+
} | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* Count tag occurrences, excluding specified ranges
|
|
236
|
+
*/
|
|
237
|
+
declare function countTagOccurrences(xmlContent: string, tagName: string, excludeRanges?: Array<{
|
|
238
|
+
start: number;
|
|
239
|
+
end: number;
|
|
240
|
+
}>, shouldSkipFirst?: boolean): number;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* XML stringification based on TXML's stringify approach
|
|
244
|
+
* Replaces the fast-xml-parser XMLBuilder with a native implementation
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Stringify an object to XML
|
|
249
|
+
*/
|
|
250
|
+
declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
|
|
251
|
+
/**
|
|
252
|
+
* Stringify parsed XML nodes back to XML string
|
|
253
|
+
*/
|
|
254
|
+
declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
|
|
255
|
+
/**
|
|
256
|
+
* Stringify a single XML node
|
|
257
|
+
*/
|
|
258
|
+
declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
|
|
259
|
+
/**
|
|
260
|
+
* Convert content to a string representation (similar to TXML's toContentString)
|
|
261
|
+
*/
|
|
262
|
+
declare function toContentString(nodes: (RXMLNode | string)[]): string;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Error classes for robust-xml parser
|
|
266
|
+
*/
|
|
267
|
+
declare class RXMLParseError extends Error {
|
|
268
|
+
cause?: unknown | undefined;
|
|
269
|
+
line?: number | undefined;
|
|
270
|
+
column?: number | undefined;
|
|
271
|
+
constructor(message: string, cause?: unknown | undefined, line?: number | undefined, column?: number | undefined);
|
|
272
|
+
}
|
|
273
|
+
declare class RXMLDuplicateStringTagError extends Error {
|
|
274
|
+
constructor(message: string);
|
|
275
|
+
}
|
|
276
|
+
declare class RXMLCoercionError extends Error {
|
|
277
|
+
cause?: unknown | undefined;
|
|
278
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
279
|
+
}
|
|
280
|
+
declare class RXMLStringifyError extends Error {
|
|
281
|
+
cause?: unknown | undefined;
|
|
282
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
283
|
+
}
|
|
284
|
+
declare class RXMLStreamError extends Error {
|
|
285
|
+
cause?: unknown | undefined;
|
|
286
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
interface Options {
|
|
290
|
+
textNodeName?: string;
|
|
291
|
+
throwOnDuplicateStringTags?: boolean;
|
|
292
|
+
onError?: (message: string, context?: Record<string, unknown>) => void;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export { type Options, type ParseOptions, RXMLCoercionError, RXMLDuplicateStringTagError, type RXMLNode, RXMLParseError, RXMLStreamError, RXMLStringifyError, type StringifyOptions, XMLTokenizer, XMLTransformStream, coerceDomBySchema, countTagOccurrences, createXMLStream, domToObject, extractRawInner, filter, findElementByIdStream, findElementsByClassStream, findFirstTopLevelRange, getPropertySchema, getStringTypedProperties, parse, parseFromStream, parseNode, parseWithoutSchema, processArrayContent, processIndexedTuple, processXMLStream, simplify, stringify, stringifyNode, stringifyNodes, toContentString };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { Transform, TransformCallback, Readable } from 'stream';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Core types for the robust-xml parser
|
|
5
|
+
* Based on TXML structure but enhanced for schema-aware parsing
|
|
6
|
+
*/
|
|
7
|
+
type OnErrorFn = (message: string, metadata?: Record<string, unknown>) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Represents a parsed XML node in the DOM tree
|
|
10
|
+
*/
|
|
11
|
+
interface RXMLNode {
|
|
12
|
+
tagName: string;
|
|
13
|
+
attributes: Record<string, string | null>;
|
|
14
|
+
children: (RXMLNode | string)[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for XML parsing
|
|
18
|
+
*/
|
|
19
|
+
interface ParseOptions {
|
|
20
|
+
/** Position to start parsing from (for streaming) */
|
|
21
|
+
pos?: number;
|
|
22
|
+
/** Array of tag names that don't have children and don't need to be closed */
|
|
23
|
+
noChildNodes?: string[];
|
|
24
|
+
/** Whether to set position information in result */
|
|
25
|
+
setPos?: boolean;
|
|
26
|
+
/** Keep comments in the parsed result */
|
|
27
|
+
keepComments?: boolean;
|
|
28
|
+
/** Keep whitespace like spaces, tabs and line breaks as string content */
|
|
29
|
+
keepWhitespace?: boolean;
|
|
30
|
+
/** Name of the text node property (default: "#text") */
|
|
31
|
+
textNodeName?: string;
|
|
32
|
+
/** Whether to throw on duplicate string tags */
|
|
33
|
+
throwOnDuplicateStringTags?: boolean;
|
|
34
|
+
/** Error handling callback */
|
|
35
|
+
onError?: OnErrorFn;
|
|
36
|
+
/** Whether to parse a single node instead of children */
|
|
37
|
+
parseNode?: boolean;
|
|
38
|
+
/** Filter function for nodes */
|
|
39
|
+
filter?: (node: RXMLNode, index: number, depth: number, path: string) => boolean;
|
|
40
|
+
/** Simplify the result structure */
|
|
41
|
+
simplify?: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for XML stringification
|
|
45
|
+
*/
|
|
46
|
+
interface StringifyOptions {
|
|
47
|
+
/** Whether to format the output with indentation */
|
|
48
|
+
format?: boolean;
|
|
49
|
+
/** Whether to suppress empty nodes */
|
|
50
|
+
suppressEmptyNode?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Whether to use minimal escaping per XML 1.0:
|
|
53
|
+
* - In character data: escape '&' and '<' (and '>' only in ']]>' sequence)
|
|
54
|
+
* - In attribute values: escape '&', '<', and only the wrapping quote
|
|
55
|
+
* Defaults to false (conservative escaping of &, <, >, ", ')
|
|
56
|
+
*/
|
|
57
|
+
minimalEscaping?: boolean;
|
|
58
|
+
/** Error handling callback */
|
|
59
|
+
onError?: OnErrorFn;
|
|
60
|
+
/**
|
|
61
|
+
* When true, serialize boolean-like attributes (value === null)
|
|
62
|
+
* as name="name" to follow strict XML attribute rules.
|
|
63
|
+
* When false (default), serialize as a convenience flag without value
|
|
64
|
+
* (e.g., <item checked>), for compatibility with existing outputs.
|
|
65
|
+
*/
|
|
66
|
+
strictBooleanAttributes?: boolean;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Main XML parser that integrates tokenization, schema awareness, and error tolerance
|
|
71
|
+
* This replaces the fast-xml-parser dependency with a TXML-based implementation
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Parse XML with schema-aware type coercion
|
|
76
|
+
*/
|
|
77
|
+
declare function parse(xmlInner: string, schema: unknown, options?: ParseOptions): Record<string, unknown>;
|
|
78
|
+
/**
|
|
79
|
+
* Parse XML without schema (similar to TXML's parse function)
|
|
80
|
+
*/
|
|
81
|
+
declare function parseWithoutSchema(xmlString: string, options?: ParseOptions): (RXMLNode | string)[];
|
|
82
|
+
/**
|
|
83
|
+
* Parse a single XML node
|
|
84
|
+
*/
|
|
85
|
+
declare function parseNode(xmlString: string, options?: ParseOptions): RXMLNode;
|
|
86
|
+
/**
|
|
87
|
+
* Simplify parsed XML structure (similar to TXML's simplify)
|
|
88
|
+
*/
|
|
89
|
+
declare function simplify(children: (RXMLNode | string)[]): unknown;
|
|
90
|
+
/**
|
|
91
|
+
* Filter XML nodes (similar to TXML's filter)
|
|
92
|
+
*/
|
|
93
|
+
declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, depth: number, path: string) => boolean, depth?: number, path?: string): RXMLNode[];
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Streaming XML parser based on TXML's transformStream approach
|
|
97
|
+
* Provides memory-efficient parsing for large XML documents
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Transform stream for parsing XML
|
|
102
|
+
*/
|
|
103
|
+
declare class XMLTransformStream extends Transform {
|
|
104
|
+
private buffer;
|
|
105
|
+
private position;
|
|
106
|
+
private readonly parseOptions;
|
|
107
|
+
private emittedCount;
|
|
108
|
+
private sawTagChar;
|
|
109
|
+
constructor(offset?: number | string, parseOptions?: ParseOptions);
|
|
110
|
+
_transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
|
|
111
|
+
_flush(callback: TransformCallback): void;
|
|
112
|
+
private processBuffer;
|
|
113
|
+
/**
|
|
114
|
+
* Emit an element and recursively emit its children as separate events
|
|
115
|
+
*/
|
|
116
|
+
private emitElementAndChildren;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Create a transform stream for parsing XML
|
|
120
|
+
*/
|
|
121
|
+
declare function createXMLStream(offset?: number | string, parseOptions?: ParseOptions): XMLTransformStream;
|
|
122
|
+
/**
|
|
123
|
+
* Parse XML from a readable stream
|
|
124
|
+
*/
|
|
125
|
+
declare function parseFromStream(stream: Readable, offset?: number | string, parseOptions?: ParseOptions): Promise<(RXMLNode | string)[]>;
|
|
126
|
+
/**
|
|
127
|
+
* Process XML stream with async iterator support
|
|
128
|
+
*/
|
|
129
|
+
declare function processXMLStream(stream: Readable, offset?: number | string, parseOptions?: ParseOptions): AsyncGenerator<RXMLNode | string, void, unknown>;
|
|
130
|
+
/**
|
|
131
|
+
* Find elements by ID in streaming fashion
|
|
132
|
+
*/
|
|
133
|
+
declare function findElementByIdStream(stream: Readable, id: string, offset?: number | string, parseOptions?: ParseOptions): AsyncGenerator<RXMLNode, void, unknown>;
|
|
134
|
+
/**
|
|
135
|
+
* Find elements by class name in streaming fashion
|
|
136
|
+
*/
|
|
137
|
+
declare function findElementsByClassStream(stream: Readable, className: string, offset?: number | string, parseOptions?: ParseOptions): AsyncGenerator<RXMLNode, void, unknown>;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* XML Tokenizer based on TXML's character-by-character parsing approach
|
|
141
|
+
* with enhanced error tolerance and schema awareness
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
declare class XMLTokenizer {
|
|
145
|
+
private pos;
|
|
146
|
+
private readonly xmlString;
|
|
147
|
+
private readonly options;
|
|
148
|
+
constructor(xmlString: string, options?: ParseOptions);
|
|
149
|
+
/**
|
|
150
|
+
* Parse XML children recursively
|
|
151
|
+
*/
|
|
152
|
+
parseChildren(tagName?: string): (RXMLNode | string)[];
|
|
153
|
+
/**
|
|
154
|
+
* Parse a single XML node
|
|
155
|
+
*/
|
|
156
|
+
parseNode(): RXMLNode;
|
|
157
|
+
/**
|
|
158
|
+
* Parse text content until next tag
|
|
159
|
+
*/
|
|
160
|
+
private parseText;
|
|
161
|
+
/**
|
|
162
|
+
* Handle comments, CDATA, and DOCTYPE declarations
|
|
163
|
+
*/
|
|
164
|
+
private handleSpecialContent;
|
|
165
|
+
/**
|
|
166
|
+
* Handle XML comments
|
|
167
|
+
*/
|
|
168
|
+
private handleComment;
|
|
169
|
+
/**
|
|
170
|
+
* Handle CDATA sections
|
|
171
|
+
*/
|
|
172
|
+
private handleCData;
|
|
173
|
+
/**
|
|
174
|
+
* Handle DOCTYPE declarations
|
|
175
|
+
*/
|
|
176
|
+
private handleDoctype;
|
|
177
|
+
/**
|
|
178
|
+
* Get current position
|
|
179
|
+
*/
|
|
180
|
+
getPosition(): number;
|
|
181
|
+
/**
|
|
182
|
+
* Set position
|
|
183
|
+
*/
|
|
184
|
+
setPosition(pos: number): void;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Schema-aware type coercion for robust-xml
|
|
189
|
+
* Integrates with the existing coercion system but adds XML-specific handling
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get property schema from a parent schema
|
|
194
|
+
*/
|
|
195
|
+
declare function getPropertySchema(toolSchema: unknown, key: string): unknown;
|
|
196
|
+
/**
|
|
197
|
+
* Convert TXML-style DOM to flat object structure for schema coercion
|
|
198
|
+
*/
|
|
199
|
+
declare function domToObject(nodes: (RXMLNode | string)[], schema: unknown, textNodeName?: string): Record<string, unknown>;
|
|
200
|
+
/**
|
|
201
|
+
* Coerce DOM object using schema information
|
|
202
|
+
*/
|
|
203
|
+
declare function coerceDomBySchema(domObject: Record<string, unknown>, schema: unknown): Record<string, unknown>;
|
|
204
|
+
/**
|
|
205
|
+
* Extract string-typed property names from schema
|
|
206
|
+
*/
|
|
207
|
+
declare function getStringTypedProperties(schema: unknown): Set<string>;
|
|
208
|
+
/**
|
|
209
|
+
* Process array-like structures from XML
|
|
210
|
+
*/
|
|
211
|
+
declare function processArrayContent(value: unknown, schema: unknown, textNodeName: string): unknown;
|
|
212
|
+
/**
|
|
213
|
+
* Handle indexed tuple structures (elements with numeric keys)
|
|
214
|
+
*/
|
|
215
|
+
declare function processIndexedTuple(obj: Record<string, unknown>, textNodeName: string): unknown[];
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Raw content extraction utilities for string-typed properties
|
|
219
|
+
* This replaces the string-based extraction with DOM-based extraction
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Extract raw inner content from XML string for a specific tag
|
|
224
|
+
* This is used for string-typed properties to preserve exact content
|
|
225
|
+
*/
|
|
226
|
+
declare function extractRawInner(xmlContent: string, tagName: string): string | undefined;
|
|
227
|
+
/**
|
|
228
|
+
* Find the first top-level range for a tag
|
|
229
|
+
*/
|
|
230
|
+
declare function findFirstTopLevelRange(xmlContent: string, tagName: string): {
|
|
231
|
+
start: number;
|
|
232
|
+
end: number;
|
|
233
|
+
} | undefined;
|
|
234
|
+
/**
|
|
235
|
+
* Count tag occurrences, excluding specified ranges
|
|
236
|
+
*/
|
|
237
|
+
declare function countTagOccurrences(xmlContent: string, tagName: string, excludeRanges?: Array<{
|
|
238
|
+
start: number;
|
|
239
|
+
end: number;
|
|
240
|
+
}>, shouldSkipFirst?: boolean): number;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* XML stringification based on TXML's stringify approach
|
|
244
|
+
* Replaces the fast-xml-parser XMLBuilder with a native implementation
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Stringify an object to XML
|
|
249
|
+
*/
|
|
250
|
+
declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
|
|
251
|
+
/**
|
|
252
|
+
* Stringify parsed XML nodes back to XML string
|
|
253
|
+
*/
|
|
254
|
+
declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
|
|
255
|
+
/**
|
|
256
|
+
* Stringify a single XML node
|
|
257
|
+
*/
|
|
258
|
+
declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
|
|
259
|
+
/**
|
|
260
|
+
* Convert content to a string representation (similar to TXML's toContentString)
|
|
261
|
+
*/
|
|
262
|
+
declare function toContentString(nodes: (RXMLNode | string)[]): string;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Error classes for robust-xml parser
|
|
266
|
+
*/
|
|
267
|
+
declare class RXMLParseError extends Error {
|
|
268
|
+
cause?: unknown | undefined;
|
|
269
|
+
line?: number | undefined;
|
|
270
|
+
column?: number | undefined;
|
|
271
|
+
constructor(message: string, cause?: unknown | undefined, line?: number | undefined, column?: number | undefined);
|
|
272
|
+
}
|
|
273
|
+
declare class RXMLDuplicateStringTagError extends Error {
|
|
274
|
+
constructor(message: string);
|
|
275
|
+
}
|
|
276
|
+
declare class RXMLCoercionError extends Error {
|
|
277
|
+
cause?: unknown | undefined;
|
|
278
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
279
|
+
}
|
|
280
|
+
declare class RXMLStringifyError extends Error {
|
|
281
|
+
cause?: unknown | undefined;
|
|
282
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
283
|
+
}
|
|
284
|
+
declare class RXMLStreamError extends Error {
|
|
285
|
+
cause?: unknown | undefined;
|
|
286
|
+
constructor(message: string, cause?: unknown | undefined);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
interface Options {
|
|
290
|
+
textNodeName?: string;
|
|
291
|
+
throwOnDuplicateStringTags?: boolean;
|
|
292
|
+
onError?: (message: string, context?: Record<string, unknown>) => void;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export { type Options, type ParseOptions, RXMLCoercionError, RXMLDuplicateStringTagError, type RXMLNode, RXMLParseError, RXMLStreamError, RXMLStringifyError, type StringifyOptions, XMLTokenizer, XMLTransformStream, coerceDomBySchema, countTagOccurrences, createXMLStream, domToObject, extractRawInner, filter, findElementByIdStream, findElementsByClassStream, findFirstTopLevelRange, getPropertySchema, getStringTypedProperties, parse, parseFromStream, parseNode, parseWithoutSchema, processArrayContent, processIndexedTuple, processXMLStream, simplify, stringify, stringifyNode, stringifyNodes, toContentString };
|