@ai-sdk-tool/rxml 0.1.1 → 0.1.2

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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { Transform, TransformCallback, Readable } from 'stream';
1
+ import { Transform, TransformCallback, Readable } from 'node:stream';
2
2
 
3
3
  /**
4
4
  * Core types for the robust-xml parser
@@ -58,14 +58,40 @@ interface StringifyOptions {
58
58
  /** Error handling callback */
59
59
  onError?: OnErrorFn;
60
60
  /**
61
- * When true, serialize boolean-like attributes (value === null)
61
+ * Whether to serialize boolean-like attributes (value === null)
62
62
  * as name="name" to follow strict XML attribute rules.
63
63
  * When false (default), serialize as a convenience flag without value
64
64
  * (e.g., <item checked>), for compatibility with existing outputs.
65
65
  */
66
66
  strictBooleanAttributes?: boolean;
67
+ /**
68
+ * Whether to include the XML declaration
69
+ */
70
+ declaration?: boolean;
67
71
  }
68
72
 
73
+ /**
74
+ * XML stringification based on TXML's stringify approach
75
+ * Replaces the fast-xml-parser XMLBuilder with a native implementation
76
+ */
77
+
78
+ /**
79
+ * Stringify an object to XML
80
+ */
81
+ declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
82
+ /**
83
+ * Stringify parsed XML nodes back to XML string
84
+ */
85
+ declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
86
+ /**
87
+ * Stringify a single XML node
88
+ */
89
+ declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
90
+ /**
91
+ * Convert content to a string representation (similar to TXML's toContentString)
92
+ */
93
+ declare function toContentString(nodes: (RXMLNode | string)[]): string;
94
+
69
95
  /**
70
96
  * Main XML parser that integrates tokenization, schema awareness, and error tolerance
71
97
  * This replaces the fast-xml-parser dependency with a TXML-based implementation
@@ -90,7 +116,7 @@ declare function simplify(children: (RXMLNode | string)[]): unknown;
90
116
  /**
91
117
  * Filter XML nodes (similar to TXML's filter)
92
118
  */
93
- declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, depth: number, path: string) => boolean, depth?: number, path?: string): RXMLNode[];
119
+ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, currentDepth: number, currentPath: string) => boolean, depth?: number, path?: string): RXMLNode[];
94
120
 
95
121
  /**
96
122
  * Streaming XML parser based on TXML's transformStream approach
@@ -102,14 +128,22 @@ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNo
102
128
  */
103
129
  declare class XMLTransformStream extends Transform {
104
130
  private buffer;
105
- private position;
106
131
  private readonly parseOptions;
107
132
  private emittedCount;
108
133
  private sawTagChar;
109
- constructor(offset?: number | string, parseOptions?: ParseOptions);
110
- _transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
134
+ constructor(_offset?: number | string, parseOptions?: ParseOptions);
135
+ _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void;
111
136
  _flush(callback: TransformCallback): void;
112
137
  private processBuffer;
138
+ private trimToNextTag;
139
+ private tryProcessSpecialNode;
140
+ private trySkipStrayClosingTag;
141
+ private extractTagInfo;
142
+ private tryProcessSelfClosingTag;
143
+ private tryProcessRegularElement;
144
+ private findMatchingClosingTag;
145
+ private findNextOpeningTag;
146
+ private advancePastClosingTag;
113
147
  /**
114
148
  * Emit an element and recursively emit its children as separate events
115
149
  */
@@ -146,10 +180,62 @@ declare class XMLTokenizer {
146
180
  private readonly xmlString;
147
181
  private readonly options;
148
182
  constructor(xmlString: string, options?: ParseOptions);
183
+ /**
184
+ * Handle closing tag parsing
185
+ */
186
+ private handleClosingTag;
187
+ /**
188
+ * Check if we're at end of string and should throw unclosed tag error
189
+ */
190
+ private checkUnclosedTag;
191
+ /**
192
+ * Process special content (comments, CDATA, DOCTYPE) and track if we consumed to end
193
+ */
194
+ private processSpecialContent;
195
+ /**
196
+ * Handle text content parsing
197
+ */
198
+ private handleTextContent;
199
+ /**
200
+ * Handle regular element parsing
201
+ */
202
+ private handleRegularElement;
203
+ /**
204
+ * Process a single child element based on the current character
205
+ */
206
+ private processSingleChild;
149
207
  /**
150
208
  * Parse XML children recursively
151
209
  */
152
210
  parseChildren(tagName?: string): (RXMLNode | string)[];
211
+ /**
212
+ * Check if character is whitespace
213
+ */
214
+ private isWhitespace;
215
+ /**
216
+ * Skip whitespace characters
217
+ */
218
+ private skipWhitespace;
219
+ /**
220
+ * Parse attribute value
221
+ */
222
+ private parseAttributeValue;
223
+ /**
224
+ * Parse single attribute
225
+ */
226
+ private parseAttribute;
227
+ /**
228
+ * Parse all attributes
229
+ */
230
+ private parseAttributes;
231
+ /**
232
+ * Parse special tag content (script, style)
233
+ */
234
+ private parseSpecialTagContent;
235
+ /**
236
+ * Parse node children based on tag type
237
+ */
238
+ private parseNodeChildren;
153
239
  /**
154
240
  * Parse a single XML node
155
241
  */
@@ -184,6 +270,31 @@ declare class XMLTokenizer {
184
270
  setPosition(pos: number): void;
185
271
  }
186
272
 
273
+ /**
274
+ * Error classes for robust-xml parser
275
+ */
276
+ declare class RXMLParseError extends Error {
277
+ cause?: unknown;
278
+ line?: number;
279
+ column?: number;
280
+ constructor(message: string, cause?: unknown, line?: number, column?: number);
281
+ }
282
+ declare class RXMLDuplicateStringTagError extends Error {
283
+ constructor(message: string);
284
+ }
285
+ declare class RXMLCoercionError extends Error {
286
+ cause?: unknown;
287
+ constructor(message: string, cause?: unknown);
288
+ }
289
+ declare class RXMLStringifyError extends Error {
290
+ cause?: unknown;
291
+ constructor(message: string, cause?: unknown);
292
+ }
293
+ declare class RXMLStreamError extends Error {
294
+ cause?: unknown;
295
+ constructor(message: string, cause?: unknown);
296
+ }
297
+
187
298
  declare function unwrapJsonSchema(schema: unknown): unknown;
188
299
  declare function getSchemaType(schema: unknown): string | undefined;
189
300
  declare function coerceBySchema(value: unknown, schema?: unknown): unknown;
@@ -250,58 +361,11 @@ declare function findAllTopLevelRanges(xmlContent: string, tagName: string): Arr
250
361
  end: number;
251
362
  }>;
252
363
 
253
- /**
254
- * XML stringification based on TXML's stringify approach
255
- * Replaces the fast-xml-parser XMLBuilder with a native implementation
256
- */
257
-
258
- /**
259
- * Stringify an object to XML
260
- */
261
- declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
262
- /**
263
- * Stringify parsed XML nodes back to XML string
264
- */
265
- declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
266
- /**
267
- * Stringify a single XML node
268
- */
269
- declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
270
- /**
271
- * Convert content to a string representation (similar to TXML's toContentString)
272
- */
273
- declare function toContentString(nodes: (RXMLNode | string)[]): string;
274
-
275
364
  /**
276
365
  * Unescape XML entities
277
366
  */
278
367
  declare function unescapeXml(text: string): string;
279
368
 
280
- /**
281
- * Error classes for robust-xml parser
282
- */
283
- declare class RXMLParseError extends Error {
284
- cause?: unknown | undefined;
285
- line?: number | undefined;
286
- column?: number | undefined;
287
- constructor(message: string, cause?: unknown | undefined, line?: number | undefined, column?: number | undefined);
288
- }
289
- declare class RXMLDuplicateStringTagError extends Error {
290
- constructor(message: string);
291
- }
292
- declare class RXMLCoercionError extends Error {
293
- cause?: unknown | undefined;
294
- constructor(message: string, cause?: unknown | undefined);
295
- }
296
- declare class RXMLStringifyError extends Error {
297
- cause?: unknown | undefined;
298
- constructor(message: string, cause?: unknown | undefined);
299
- }
300
- declare class RXMLStreamError extends Error {
301
- cause?: unknown | undefined;
302
- constructor(message: string, cause?: unknown | undefined);
303
- }
304
-
305
369
  interface Options {
306
370
  textNodeName?: string;
307
371
  throwOnDuplicateStringTags?: boolean;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Transform, TransformCallback, Readable } from 'stream';
1
+ import { Transform, TransformCallback, Readable } from 'node:stream';
2
2
 
3
3
  /**
4
4
  * Core types for the robust-xml parser
@@ -58,14 +58,40 @@ interface StringifyOptions {
58
58
  /** Error handling callback */
59
59
  onError?: OnErrorFn;
60
60
  /**
61
- * When true, serialize boolean-like attributes (value === null)
61
+ * Whether to serialize boolean-like attributes (value === null)
62
62
  * as name="name" to follow strict XML attribute rules.
63
63
  * When false (default), serialize as a convenience flag without value
64
64
  * (e.g., <item checked>), for compatibility with existing outputs.
65
65
  */
66
66
  strictBooleanAttributes?: boolean;
67
+ /**
68
+ * Whether to include the XML declaration
69
+ */
70
+ declaration?: boolean;
67
71
  }
68
72
 
73
+ /**
74
+ * XML stringification based on TXML's stringify approach
75
+ * Replaces the fast-xml-parser XMLBuilder with a native implementation
76
+ */
77
+
78
+ /**
79
+ * Stringify an object to XML
80
+ */
81
+ declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
82
+ /**
83
+ * Stringify parsed XML nodes back to XML string
84
+ */
85
+ declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
86
+ /**
87
+ * Stringify a single XML node
88
+ */
89
+ declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
90
+ /**
91
+ * Convert content to a string representation (similar to TXML's toContentString)
92
+ */
93
+ declare function toContentString(nodes: (RXMLNode | string)[]): string;
94
+
69
95
  /**
70
96
  * Main XML parser that integrates tokenization, schema awareness, and error tolerance
71
97
  * This replaces the fast-xml-parser dependency with a TXML-based implementation
@@ -90,7 +116,7 @@ declare function simplify(children: (RXMLNode | string)[]): unknown;
90
116
  /**
91
117
  * Filter XML nodes (similar to TXML's filter)
92
118
  */
93
- declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, depth: number, path: string) => boolean, depth?: number, path?: string): RXMLNode[];
119
+ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, currentDepth: number, currentPath: string) => boolean, depth?: number, path?: string): RXMLNode[];
94
120
 
95
121
  /**
96
122
  * Streaming XML parser based on TXML's transformStream approach
@@ -102,14 +128,22 @@ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNo
102
128
  */
103
129
  declare class XMLTransformStream extends Transform {
104
130
  private buffer;
105
- private position;
106
131
  private readonly parseOptions;
107
132
  private emittedCount;
108
133
  private sawTagChar;
109
- constructor(offset?: number | string, parseOptions?: ParseOptions);
110
- _transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
134
+ constructor(_offset?: number | string, parseOptions?: ParseOptions);
135
+ _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void;
111
136
  _flush(callback: TransformCallback): void;
112
137
  private processBuffer;
138
+ private trimToNextTag;
139
+ private tryProcessSpecialNode;
140
+ private trySkipStrayClosingTag;
141
+ private extractTagInfo;
142
+ private tryProcessSelfClosingTag;
143
+ private tryProcessRegularElement;
144
+ private findMatchingClosingTag;
145
+ private findNextOpeningTag;
146
+ private advancePastClosingTag;
113
147
  /**
114
148
  * Emit an element and recursively emit its children as separate events
115
149
  */
@@ -146,10 +180,62 @@ declare class XMLTokenizer {
146
180
  private readonly xmlString;
147
181
  private readonly options;
148
182
  constructor(xmlString: string, options?: ParseOptions);
183
+ /**
184
+ * Handle closing tag parsing
185
+ */
186
+ private handleClosingTag;
187
+ /**
188
+ * Check if we're at end of string and should throw unclosed tag error
189
+ */
190
+ private checkUnclosedTag;
191
+ /**
192
+ * Process special content (comments, CDATA, DOCTYPE) and track if we consumed to end
193
+ */
194
+ private processSpecialContent;
195
+ /**
196
+ * Handle text content parsing
197
+ */
198
+ private handleTextContent;
199
+ /**
200
+ * Handle regular element parsing
201
+ */
202
+ private handleRegularElement;
203
+ /**
204
+ * Process a single child element based on the current character
205
+ */
206
+ private processSingleChild;
149
207
  /**
150
208
  * Parse XML children recursively
151
209
  */
152
210
  parseChildren(tagName?: string): (RXMLNode | string)[];
211
+ /**
212
+ * Check if character is whitespace
213
+ */
214
+ private isWhitespace;
215
+ /**
216
+ * Skip whitespace characters
217
+ */
218
+ private skipWhitespace;
219
+ /**
220
+ * Parse attribute value
221
+ */
222
+ private parseAttributeValue;
223
+ /**
224
+ * Parse single attribute
225
+ */
226
+ private parseAttribute;
227
+ /**
228
+ * Parse all attributes
229
+ */
230
+ private parseAttributes;
231
+ /**
232
+ * Parse special tag content (script, style)
233
+ */
234
+ private parseSpecialTagContent;
235
+ /**
236
+ * Parse node children based on tag type
237
+ */
238
+ private parseNodeChildren;
153
239
  /**
154
240
  * Parse a single XML node
155
241
  */
@@ -184,6 +270,31 @@ declare class XMLTokenizer {
184
270
  setPosition(pos: number): void;
185
271
  }
186
272
 
273
+ /**
274
+ * Error classes for robust-xml parser
275
+ */
276
+ declare class RXMLParseError extends Error {
277
+ cause?: unknown;
278
+ line?: number;
279
+ column?: number;
280
+ constructor(message: string, cause?: unknown, line?: number, column?: number);
281
+ }
282
+ declare class RXMLDuplicateStringTagError extends Error {
283
+ constructor(message: string);
284
+ }
285
+ declare class RXMLCoercionError extends Error {
286
+ cause?: unknown;
287
+ constructor(message: string, cause?: unknown);
288
+ }
289
+ declare class RXMLStringifyError extends Error {
290
+ cause?: unknown;
291
+ constructor(message: string, cause?: unknown);
292
+ }
293
+ declare class RXMLStreamError extends Error {
294
+ cause?: unknown;
295
+ constructor(message: string, cause?: unknown);
296
+ }
297
+
187
298
  declare function unwrapJsonSchema(schema: unknown): unknown;
188
299
  declare function getSchemaType(schema: unknown): string | undefined;
189
300
  declare function coerceBySchema(value: unknown, schema?: unknown): unknown;
@@ -250,58 +361,11 @@ declare function findAllTopLevelRanges(xmlContent: string, tagName: string): Arr
250
361
  end: number;
251
362
  }>;
252
363
 
253
- /**
254
- * XML stringification based on TXML's stringify approach
255
- * Replaces the fast-xml-parser XMLBuilder with a native implementation
256
- */
257
-
258
- /**
259
- * Stringify an object to XML
260
- */
261
- declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
262
- /**
263
- * Stringify parsed XML nodes back to XML string
264
- */
265
- declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
266
- /**
267
- * Stringify a single XML node
268
- */
269
- declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
270
- /**
271
- * Convert content to a string representation (similar to TXML's toContentString)
272
- */
273
- declare function toContentString(nodes: (RXMLNode | string)[]): string;
274
-
275
364
  /**
276
365
  * Unescape XML entities
277
366
  */
278
367
  declare function unescapeXml(text: string): string;
279
368
 
280
- /**
281
- * Error classes for robust-xml parser
282
- */
283
- declare class RXMLParseError extends Error {
284
- cause?: unknown | undefined;
285
- line?: number | undefined;
286
- column?: number | undefined;
287
- constructor(message: string, cause?: unknown | undefined, line?: number | undefined, column?: number | undefined);
288
- }
289
- declare class RXMLDuplicateStringTagError extends Error {
290
- constructor(message: string);
291
- }
292
- declare class RXMLCoercionError extends Error {
293
- cause?: unknown | undefined;
294
- constructor(message: string, cause?: unknown | undefined);
295
- }
296
- declare class RXMLStringifyError extends Error {
297
- cause?: unknown | undefined;
298
- constructor(message: string, cause?: unknown | undefined);
299
- }
300
- declare class RXMLStreamError extends Error {
301
- cause?: unknown | undefined;
302
- constructor(message: string, cause?: unknown | undefined);
303
- }
304
-
305
369
  interface Options {
306
370
  textNodeName?: string;
307
371
  throwOnDuplicateStringTags?: boolean;