@ai-sdk-tool/rxml 0.1.0 → 0.1.2-canary.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.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
@@ -66,6 +66,28 @@ interface StringifyOptions {
66
66
  strictBooleanAttributes?: boolean;
67
67
  }
68
68
 
69
+ /**
70
+ * XML stringification based on TXML's stringify approach
71
+ * Replaces the fast-xml-parser XMLBuilder with a native implementation
72
+ */
73
+
74
+ /**
75
+ * Stringify an object to XML
76
+ */
77
+ declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
78
+ /**
79
+ * Stringify parsed XML nodes back to XML string
80
+ */
81
+ declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
82
+ /**
83
+ * Stringify a single XML node
84
+ */
85
+ declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
86
+ /**
87
+ * Convert content to a string representation (similar to TXML's toContentString)
88
+ */
89
+ declare function toContentString(nodes: (RXMLNode | string)[]): string;
90
+
69
91
  /**
70
92
  * Main XML parser that integrates tokenization, schema awareness, and error tolerance
71
93
  * This replaces the fast-xml-parser dependency with a TXML-based implementation
@@ -90,7 +112,7 @@ declare function simplify(children: (RXMLNode | string)[]): unknown;
90
112
  /**
91
113
  * Filter XML nodes (similar to TXML's filter)
92
114
  */
93
- declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, depth: number, path: string) => boolean, depth?: number, path?: string): RXMLNode[];
115
+ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, currentDepth: number, currentPath: string) => boolean, depth?: number, path?: string): RXMLNode[];
94
116
 
95
117
  /**
96
118
  * Streaming XML parser based on TXML's transformStream approach
@@ -102,14 +124,22 @@ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNo
102
124
  */
103
125
  declare class XMLTransformStream extends Transform {
104
126
  private buffer;
105
- private position;
106
127
  private readonly parseOptions;
107
128
  private emittedCount;
108
129
  private sawTagChar;
109
- constructor(offset?: number | string, parseOptions?: ParseOptions);
110
- _transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
130
+ constructor(_offset?: number | string, parseOptions?: ParseOptions);
131
+ _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void;
111
132
  _flush(callback: TransformCallback): void;
112
133
  private processBuffer;
134
+ private trimToNextTag;
135
+ private tryProcessSpecialNode;
136
+ private trySkipStrayClosingTag;
137
+ private extractTagInfo;
138
+ private tryProcessSelfClosingTag;
139
+ private tryProcessRegularElement;
140
+ private findMatchingClosingTag;
141
+ private findNextOpeningTag;
142
+ private advancePastClosingTag;
113
143
  /**
114
144
  * Emit an element and recursively emit its children as separate events
115
145
  */
@@ -146,10 +176,62 @@ declare class XMLTokenizer {
146
176
  private readonly xmlString;
147
177
  private readonly options;
148
178
  constructor(xmlString: string, options?: ParseOptions);
179
+ /**
180
+ * Handle closing tag parsing
181
+ */
182
+ private handleClosingTag;
183
+ /**
184
+ * Check if we're at end of string and should throw unclosed tag error
185
+ */
186
+ private checkUnclosedTag;
187
+ /**
188
+ * Process special content (comments, CDATA, DOCTYPE) and track if we consumed to end
189
+ */
190
+ private processSpecialContent;
191
+ /**
192
+ * Handle text content parsing
193
+ */
194
+ private handleTextContent;
195
+ /**
196
+ * Handle regular element parsing
197
+ */
198
+ private handleRegularElement;
199
+ /**
200
+ * Process a single child element based on the current character
201
+ */
202
+ private processSingleChild;
149
203
  /**
150
204
  * Parse XML children recursively
151
205
  */
152
206
  parseChildren(tagName?: string): (RXMLNode | string)[];
207
+ /**
208
+ * Check if character is whitespace
209
+ */
210
+ private isWhitespace;
211
+ /**
212
+ * Skip whitespace characters
213
+ */
214
+ private skipWhitespace;
215
+ /**
216
+ * Parse attribute value
217
+ */
218
+ private parseAttributeValue;
219
+ /**
220
+ * Parse single attribute
221
+ */
222
+ private parseAttribute;
223
+ /**
224
+ * Parse all attributes
225
+ */
226
+ private parseAttributes;
227
+ /**
228
+ * Parse special tag content (script, style)
229
+ */
230
+ private parseSpecialTagContent;
231
+ /**
232
+ * Parse node children based on tag type
233
+ */
234
+ private parseNodeChildren;
153
235
  /**
154
236
  * Parse a single XML node
155
237
  */
@@ -184,6 +266,35 @@ declare class XMLTokenizer {
184
266
  setPosition(pos: number): void;
185
267
  }
186
268
 
269
+ /**
270
+ * Error classes for robust-xml parser
271
+ */
272
+ declare class RXMLParseError extends Error {
273
+ cause?: unknown;
274
+ line?: number;
275
+ column?: number;
276
+ constructor(message: string, cause?: unknown, line?: number, column?: number);
277
+ }
278
+ declare class RXMLDuplicateStringTagError extends Error {
279
+ constructor(message: string);
280
+ }
281
+ declare class RXMLCoercionError extends Error {
282
+ cause?: unknown;
283
+ constructor(message: string, cause?: unknown);
284
+ }
285
+ declare class RXMLStringifyError extends Error {
286
+ cause?: unknown;
287
+ constructor(message: string, cause?: unknown);
288
+ }
289
+ declare class RXMLStreamError extends Error {
290
+ cause?: unknown;
291
+ constructor(message: string, cause?: unknown);
292
+ }
293
+
294
+ declare function unwrapJsonSchema(schema: unknown): unknown;
295
+ declare function getSchemaType(schema: unknown): string | undefined;
296
+ declare function coerceBySchema(value: unknown, schema?: unknown): unknown;
297
+
187
298
  /**
188
299
  * Schema-aware type coercion for robust-xml
189
300
  * Integrates with the existing coercion system but adds XML-specific handling
@@ -238,53 +349,18 @@ declare function countTagOccurrences(xmlContent: string, tagName: string, exclud
238
349
  start: number;
239
350
  end: number;
240
351
  }>, 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
352
  /**
248
- * Stringify an object to XML
353
+ * Find all top-level ranges for a tag (for handling duplicates)
249
354
  */
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;
355
+ declare function findAllTopLevelRanges(xmlContent: string, tagName: string): Array<{
356
+ start: number;
357
+ end: number;
358
+ }>;
263
359
 
264
360
  /**
265
- * Error classes for robust-xml parser
361
+ * Unescape XML entities
266
362
  */
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
- }
363
+ declare function unescapeXml(text: string): string;
288
364
 
289
365
  interface Options {
290
366
  textNodeName?: string;
@@ -292,4 +368,4 @@ interface Options {
292
368
  onError?: (message: string, context?: Record<string, unknown>) => void;
293
369
  }
294
370
 
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 };
371
+ export { type Options, type ParseOptions, RXMLCoercionError, RXMLDuplicateStringTagError, type RXMLNode, RXMLParseError, RXMLStreamError, RXMLStringifyError, type StringifyOptions, XMLTokenizer, XMLTransformStream, coerceBySchema, coerceDomBySchema, countTagOccurrences, createXMLStream, domToObject, extractRawInner, filter, findAllTopLevelRanges, findElementByIdStream, findElementsByClassStream, findFirstTopLevelRange, getPropertySchema, getSchemaType, getStringTypedProperties, parse, parseFromStream, parseNode, parseWithoutSchema, processArrayContent, processIndexedTuple, processXMLStream, simplify, stringify, stringifyNode, stringifyNodes, toContentString, unescapeXml, unwrapJsonSchema };
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
@@ -66,6 +66,28 @@ interface StringifyOptions {
66
66
  strictBooleanAttributes?: boolean;
67
67
  }
68
68
 
69
+ /**
70
+ * XML stringification based on TXML's stringify approach
71
+ * Replaces the fast-xml-parser XMLBuilder with a native implementation
72
+ */
73
+
74
+ /**
75
+ * Stringify an object to XML
76
+ */
77
+ declare function stringify(rootTag: string, obj: unknown, options?: StringifyOptions): string;
78
+ /**
79
+ * Stringify parsed XML nodes back to XML string
80
+ */
81
+ declare function stringifyNodes(nodes: (RXMLNode | string)[], format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
82
+ /**
83
+ * Stringify a single XML node
84
+ */
85
+ declare function stringifyNode(node: RXMLNode, depth?: number, format?: boolean, options?: Pick<StringifyOptions, "strictBooleanAttributes" | "minimalEscaping">): string;
86
+ /**
87
+ * Convert content to a string representation (similar to TXML's toContentString)
88
+ */
89
+ declare function toContentString(nodes: (RXMLNode | string)[]): string;
90
+
69
91
  /**
70
92
  * Main XML parser that integrates tokenization, schema awareness, and error tolerance
71
93
  * This replaces the fast-xml-parser dependency with a TXML-based implementation
@@ -90,7 +112,7 @@ declare function simplify(children: (RXMLNode | string)[]): unknown;
90
112
  /**
91
113
  * Filter XML nodes (similar to TXML's filter)
92
114
  */
93
- declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, depth: number, path: string) => boolean, depth?: number, path?: string): RXMLNode[];
115
+ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNode, index: number, currentDepth: number, currentPath: string) => boolean, depth?: number, path?: string): RXMLNode[];
94
116
 
95
117
  /**
96
118
  * Streaming XML parser based on TXML's transformStream approach
@@ -102,14 +124,22 @@ declare function filter(children: (RXMLNode | string)[], filterFn: (node: RXMLNo
102
124
  */
103
125
  declare class XMLTransformStream extends Transform {
104
126
  private buffer;
105
- private position;
106
127
  private readonly parseOptions;
107
128
  private emittedCount;
108
129
  private sawTagChar;
109
- constructor(offset?: number | string, parseOptions?: ParseOptions);
110
- _transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void;
130
+ constructor(_offset?: number | string, parseOptions?: ParseOptions);
131
+ _transform(chunk: Buffer, _encoding: BufferEncoding, callback: TransformCallback): void;
111
132
  _flush(callback: TransformCallback): void;
112
133
  private processBuffer;
134
+ private trimToNextTag;
135
+ private tryProcessSpecialNode;
136
+ private trySkipStrayClosingTag;
137
+ private extractTagInfo;
138
+ private tryProcessSelfClosingTag;
139
+ private tryProcessRegularElement;
140
+ private findMatchingClosingTag;
141
+ private findNextOpeningTag;
142
+ private advancePastClosingTag;
113
143
  /**
114
144
  * Emit an element and recursively emit its children as separate events
115
145
  */
@@ -146,10 +176,62 @@ declare class XMLTokenizer {
146
176
  private readonly xmlString;
147
177
  private readonly options;
148
178
  constructor(xmlString: string, options?: ParseOptions);
179
+ /**
180
+ * Handle closing tag parsing
181
+ */
182
+ private handleClosingTag;
183
+ /**
184
+ * Check if we're at end of string and should throw unclosed tag error
185
+ */
186
+ private checkUnclosedTag;
187
+ /**
188
+ * Process special content (comments, CDATA, DOCTYPE) and track if we consumed to end
189
+ */
190
+ private processSpecialContent;
191
+ /**
192
+ * Handle text content parsing
193
+ */
194
+ private handleTextContent;
195
+ /**
196
+ * Handle regular element parsing
197
+ */
198
+ private handleRegularElement;
199
+ /**
200
+ * Process a single child element based on the current character
201
+ */
202
+ private processSingleChild;
149
203
  /**
150
204
  * Parse XML children recursively
151
205
  */
152
206
  parseChildren(tagName?: string): (RXMLNode | string)[];
207
+ /**
208
+ * Check if character is whitespace
209
+ */
210
+ private isWhitespace;
211
+ /**
212
+ * Skip whitespace characters
213
+ */
214
+ private skipWhitespace;
215
+ /**
216
+ * Parse attribute value
217
+ */
218
+ private parseAttributeValue;
219
+ /**
220
+ * Parse single attribute
221
+ */
222
+ private parseAttribute;
223
+ /**
224
+ * Parse all attributes
225
+ */
226
+ private parseAttributes;
227
+ /**
228
+ * Parse special tag content (script, style)
229
+ */
230
+ private parseSpecialTagContent;
231
+ /**
232
+ * Parse node children based on tag type
233
+ */
234
+ private parseNodeChildren;
153
235
  /**
154
236
  * Parse a single XML node
155
237
  */
@@ -184,6 +266,35 @@ declare class XMLTokenizer {
184
266
  setPosition(pos: number): void;
185
267
  }
186
268
 
269
+ /**
270
+ * Error classes for robust-xml parser
271
+ */
272
+ declare class RXMLParseError extends Error {
273
+ cause?: unknown;
274
+ line?: number;
275
+ column?: number;
276
+ constructor(message: string, cause?: unknown, line?: number, column?: number);
277
+ }
278
+ declare class RXMLDuplicateStringTagError extends Error {
279
+ constructor(message: string);
280
+ }
281
+ declare class RXMLCoercionError extends Error {
282
+ cause?: unknown;
283
+ constructor(message: string, cause?: unknown);
284
+ }
285
+ declare class RXMLStringifyError extends Error {
286
+ cause?: unknown;
287
+ constructor(message: string, cause?: unknown);
288
+ }
289
+ declare class RXMLStreamError extends Error {
290
+ cause?: unknown;
291
+ constructor(message: string, cause?: unknown);
292
+ }
293
+
294
+ declare function unwrapJsonSchema(schema: unknown): unknown;
295
+ declare function getSchemaType(schema: unknown): string | undefined;
296
+ declare function coerceBySchema(value: unknown, schema?: unknown): unknown;
297
+
187
298
  /**
188
299
  * Schema-aware type coercion for robust-xml
189
300
  * Integrates with the existing coercion system but adds XML-specific handling
@@ -238,53 +349,18 @@ declare function countTagOccurrences(xmlContent: string, tagName: string, exclud
238
349
  start: number;
239
350
  end: number;
240
351
  }>, 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
352
  /**
248
- * Stringify an object to XML
353
+ * Find all top-level ranges for a tag (for handling duplicates)
249
354
  */
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;
355
+ declare function findAllTopLevelRanges(xmlContent: string, tagName: string): Array<{
356
+ start: number;
357
+ end: number;
358
+ }>;
263
359
 
264
360
  /**
265
- * Error classes for robust-xml parser
361
+ * Unescape XML entities
266
362
  */
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
- }
363
+ declare function unescapeXml(text: string): string;
288
364
 
289
365
  interface Options {
290
366
  textNodeName?: string;
@@ -292,4 +368,4 @@ interface Options {
292
368
  onError?: (message: string, context?: Record<string, unknown>) => void;
293
369
  }
294
370
 
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 };
371
+ export { type Options, type ParseOptions, RXMLCoercionError, RXMLDuplicateStringTagError, type RXMLNode, RXMLParseError, RXMLStreamError, RXMLStringifyError, type StringifyOptions, XMLTokenizer, XMLTransformStream, coerceBySchema, coerceDomBySchema, countTagOccurrences, createXMLStream, domToObject, extractRawInner, filter, findAllTopLevelRanges, findElementByIdStream, findElementsByClassStream, findFirstTopLevelRange, getPropertySchema, getSchemaType, getStringTypedProperties, parse, parseFromStream, parseNode, parseWithoutSchema, processArrayContent, processIndexedTuple, processXMLStream, simplify, stringify, stringifyNode, stringifyNodes, toContentString, unescapeXml, unwrapJsonSchema };