//#region src/converter/converter/errors.d.ts /** * XML parse error with detailed issue information * * @public */ declare class XmlParseError extends Error { /** * List of validation issues */ issues: Array<{ path: string[]; message: string; code: string; }>; constructor(issues: Array<{ path: string[]; message: string; code: string; }>); } /** * Parse result type for safe parsing operations * * @public */ type ParseResult = { success: true; data: T; } | { success: false; error: XmlParseError; }; //#endregion //#region src/core/types.d.ts /** * Enumeration of XML stream event types used by the StAX parser * * @public */ declare const XmlEventType: { readonly START_DOCUMENT: "START_DOCUMENT"; readonly END_DOCUMENT: "END_DOCUMENT"; readonly START_ELEMENT: "START_ELEMENT"; readonly END_ELEMENT: "END_ELEMENT"; readonly CHARACTERS: "CHARACTERS"; readonly CDATA: "CDATA"; readonly COMMENT: "COMMENT"; readonly PROCESSING_INSTRUCTION: "PROCESSING_INSTRUCTION"; readonly DTD: "DTD"; }; type XmlEventType = (typeof XmlEventType)[keyof typeof XmlEventType]; /** * Event fired when the document starts parsing * * @public */ interface StartDocumentEvent { type: typeof XmlEventType.START_DOCUMENT; /** Present only when the source contained an XML declaration. */ version?: "1.0"; encoding?: string; standalone?: boolean; } /** * Event fired when the document ends parsing * * @public */ interface EndDocumentEvent { type: typeof XmlEventType.END_DOCUMENT; } /** * Event fired when an XML element starts * * @public */ interface StartElementEvent { type: typeof XmlEventType.START_ELEMENT; name: string; localName: string; prefix: string; namespaceURI: string; /** Attributes in source order, or undefined when the element has none. */ attributes?: EventAttributes; /** Whether the source used an empty-element tag (``). */ selfClosing: boolean; } /** Materialized attribute attached to a start-element event. */ interface EventAttribute { name: string; localName: string; prefix: string; namespaceURI: string; value: string; } /** * Attribute lookup table keyed by qualified XML name. * * @remarks * Iteration follows source order. `JSON.stringify()` emits the same object * shape as a record while reserved JavaScript property names remain safe. */ interface EventAttributes extends ReadonlyMap { /** Return a qualified-name record for JSON serialization. */ toJSON(): Record; } /** Event emitted when an XML element ends. */ interface EndElementEvent { type: typeof XmlEventType.END_ELEMENT; name: string; localName: string; prefix: string; namespaceURI: string; } /** Event containing ordinary character data. */ interface CharactersEvent { type: typeof XmlEventType.CHARACTERS; value: string; } /** Event containing CDATA content. */ interface CdataEvent { type: typeof XmlEventType.CDATA; value: string; } /** Event containing an XML comment. */ interface CommentEvent { type: typeof XmlEventType.COMMENT; value: string; } /** Event containing an XML processing instruction. */ interface ProcessingInstructionEvent { type: typeof XmlEventType.PROCESSING_INSTRUCTION; target: string; data: string; } /** Event containing a document type declaration. */ interface DtdEvent { type: typeof XmlEventType.DTD; value: string; } /** * Discriminated Union type for developer use */ type AnyXmlEvent = StartDocumentEvent | EndDocumentEvent | StartElementEvent | EndElementEvent | CharactersEvent | CdataEvent | CommentEvent | ProcessingInstructionEvent | DtdEvent; /** * Attribute information interface */ interface AttributeInfo { value: string; prefix?: string; uri?: string; } /** * Element writing options interface (for Writer) */ interface WriteElementOptions { prefix?: string; uri?: string; attributes?: Record; selfClosing?: boolean; comment?: string; } /** * XML document conformance mode. * * @public */ type DocumentMode = "fragment" | "document"; //#endregion //#region src/async/Writer.d.ts /** Options shared by the asynchronous XML writer and its serializer core. */ interface WriterOptions { encoding?: string; prettyPrint?: boolean; indentString?: string; addEntities?: { entity: string; value: string; }[]; autoEncodeEntities?: boolean; bufferSize?: number; flushThreshold?: number; enableAutoFlush?: boolean; } /** Text sink for external streaming encoders. */ interface AsyncTextSink { readonly encoding: string; /** Write a serialized XML text chunk. */ write(chunk: string): void | Promise; /** Flush buffered text when supported. */ flush?(): void | Promise; /** Close the sink when supported. */ close?(): void | Promise; } /** Asynchronous I/O wrapper for the shared WriterCore serializer. */ declare class Writer { private writer; private textSink; private textBuffer; private readonly encoder; private buffer; private bufferPosition; private pendingText; private readonly core; private readonly bufferSize; private readonly flushThreshold; private readonly enableAutoFlush; constructor(output: WritableStream | AsyncTextSink, options?: WriterOptions); private run; /** Write an XML declaration. */ writeStartDocument(version?: "1.0", encoding?: string, standalone?: boolean): Promise; /** Open an element. */ writeStartElement(localName: string, options?: WriteElementOptions): Promise; /** Close the current element. */ writeEndElement(): Promise; /** Write escaped character data. */ writeCharacters(text: string): Promise; /** Write a CDATA section. */ writeCData(cdata: string): Promise; /** Add an attribute to the open start tag. */ writeAttribute(localName: string, value: string, prefix?: string): Promise; /** Add a namespace declaration to the open start tag. */ writeNamespace(prefix: string, uri: string): Promise; /** Write an XML comment. */ writeComment(comment: string): Promise; /** Write a processing instruction. */ writeProcessingInstruction(target: string, data?: string): Promise; /** Write a document type declaration. */ writeDTD(value: string): Promise; /** Write one standard materialized XML event. */ writeEvent(event: AnyXmlEvent): Promise; /** Write trusted XML text without escaping. */ writeRaw(xml: string): Promise; /** Finish the XML document and close the output. */ writeEndDocument(): Promise; /** Close the writer and its output. */ close(): Promise; /** Flush buffered output. */ flush(): Promise; private writeToBuffer; private flushBuffer; private writeBytes; private writeText; } //#endregion //#region src/WriterCore.d.ts interface WriterCoreOptions { encoding: string; prettyPrint?: boolean; indentString?: string; addEntities?: { entity: string; value: string; }[]; autoEncodeEntities?: boolean; } /** Shared XML serializer state machine. It only produces text chunks; wrappers own I/O. */ declare class WriterCore { private static readonly entities; private static readonly entityPattern; private state; private readonly chunks; private readonly emit; private readonly elements; private readonly elementPrefixes; private readonly textContent; private readonly namespaces; private undoStarts; private undoPrefixes; private undoPrevious; private attributes; private eventElements; private suppressedEnd; private seenDtd; private seenRoot; private indentLevel; private needsIndent; private indentCache; private readonly options; private readonly customEntities?; private readonly customPattern?; private readonly customKeys?; constructor(options: WriterCoreOptions, emit?: (chunk: string) => void); /** Return and clear chunks produced since the last call. */ takeChunks(): string[]; get closed(): boolean; get failed(): boolean; fail(): void; setPrettyPrint(enabled: boolean): void; setIndentString(indentString: string): void; isPrettyPrintEnabled(): boolean; getIndentString(): string; writeStartDocument(version?: "1.0", encoding?: string, standalone?: boolean): void; writeEndDocument(): void; writeStartElement(localName: string, options?: WriteElementOptions): void; writeAttribute(localName: string, value: string, prefix?: string): void; writeNamespace(prefix: string, uri: string): void; writeCharacters(text: string): void; writeCData(cdata: string): void; writeComment(comment: string): void; writeProcessingInstruction(target: string, data?: string): void; writeDTD(value: string): void; writeRaw(xml: string): void; writeEndElement(): void; writeEvent(event: AnyXmlEvent): void; private eventStart; private writeCommentValue; private write; private assertWritable; private closeStart; private assertPrefixBound; private writeIndent; private newline; private getIndent; private bind; private restore; private escape; } //#endregion //#region src/sync/WriterSync.d.ts /** Sink interface for custom sync targets. */ interface SyncTextSink { readonly encoding?: string; /** Write a serialized XML text chunk. */ write(chunk: string): void; /** Flush buffered text when supported. */ flush?(): void; /** Close the sink when supported. */ close?(): void; } /** Options for string-based synchronous writing. */ interface WriterSyncOptions { encoding?: string; prettyPrint?: boolean; indentString?: string; addEntities?: { entity: string; value: string; }[]; autoEncodeEntities?: boolean; } /** Options for incremental synchronous sink writing. */ interface WriterSyncSinkOptions extends WriterSyncOptions { bufferSize?: number; enableAutoFlush?: boolean; flushOnClose?: boolean; flushThreshold?: number; } /** String-based synchronous XML writer. */ declare class WriterSync { protected readonly core: WriterCore; private xmlString; constructor(options?: WriterSyncOptions, encoding?: string); /** Return XML accumulated by this string writer. */ getXmlString(): string; /** Extension hook retained for existing subclasses; wrappers call it only for core chunks. */ protected _emit(chunk: string): void; /** Write an XML declaration. */ writeStartDocument(version?: "1.0", encoding?: string, standalone?: boolean): this; /** Finish the XML document. */ writeEndDocument(): void; /** Open an element. */ writeStartElement(localName: string, options?: WriteElementOptions): this; /** Close the current element. */ writeEndElement(): this; /** Write escaped character data. */ writeCharacters(text: string): this; /** Write a CDATA section. */ writeCData(cdata: string): this; /** Add an attribute to the open start tag. */ writeAttribute(localName: string, value: string, prefix?: string): this; /** Add a namespace declaration to the open start tag. */ writeNamespace(prefix: string, uri: string): this; /** Write an XML comment. */ writeComment(comment: string): this; /** Write a processing instruction. */ writeProcessingInstruction(target: string, data?: string): this; /** Write a document type declaration. */ writeDTD(value: string): this; /** Write one standard materialized XML event. */ writeEvent(event: AnyXmlEvent): this; /** Write trusted XML text without escaping. */ writeRaw(xml: string): this; /** Enable or disable pretty printing. */ setPrettyPrint(enabled: boolean): this; /** Set the indentation unit used by pretty printing. */ setIndentString(indentString: string): this; /** Return whether pretty printing is enabled. */ isPrettyPrintEnabled(): boolean; /** Return the current indentation unit. */ getIndentString(): string; } /** Sink-based sync writer. I/O and flushing live here, outside WriterCore. */ declare class WriterSyncSink extends WriterSync { private readonly sink; private buffer; private readonly bufferSize; private readonly enableAutoFlush; private readonly flushThreshold; private readonly flushOnClose; constructor(sink: SyncTextSink, options?: WriterSyncSinkOptions); protected _emit(chunk: string): void; /** Finish the document and flush serialized text to the sink. */ writeEndDocument(): void; /** Flush buffered text to the sink. */ flush(): void; /** Finalize the document and close the sink. */ close(): void; private flushBuffer; } //#endregion //#region src/converter/converter/XmlStringSchema.d.ts /** * Schema for parsing XML string values * * @public */ declare class XmlStringSchema extends XmlSchema { options: XmlStringOptions; readonly schemaType: "STRING"; constructor(options?: XmlStringOptions); _parseText(text: string): string; /** * Set XPath expression for locating the element * @param path - XPath expression * @returns New schema with XPath */ xpath(path: string): XmlStringSchema; /** * Write raw content only (used inside object schema) * @internal */ _writeContent(data: string, options?: XmlWriteOptions): string; /** * Write string data to XML synchronously * @internal */ _writeSync(data: string, options?: XmlWriteOptions): string; /** * Write string data to WritableStream asynchronously * @internal */ _write(data: string, stream: WritableStream, options?: XmlWriteOptions): Promise; } //#endregion //#region src/converter/converter/XmlNumberSchema.d.ts /** * Schema for parsing XML number values * * @public */ declare class XmlNumberSchema extends XmlSchema { options: XmlNumberOptions; readonly schemaType: "NUMBER"; constructor(options?: XmlNumberOptions); _parseText(text: string): number; /** * Set XPath expression for locating the element * @param path - XPath expression * @returns New schema with XPath */ xpath(path: string): XmlNumberSchema; /** * Set minimum value * @param value - Minimum value * @returns New schema with minimum */ min(value: number): XmlNumberSchema; /** * Set maximum value * @param value - Maximum value * @returns New schema with maximum */ max(value: number): XmlNumberSchema; /** * Require integer value * @returns New schema that only accepts integers */ int(): XmlNumberSchema; /** * Write raw content only (used inside object schema) * @internal */ _writeContent(data: number, options?: XmlWriteOptions): string; /** * Write number data to XML synchronously * @internal */ _writeSync(data: number, options?: XmlWriteOptions): string; /** * Write number data to WritableStream asynchronously * @internal */ _write(data: number, stream: WritableStream, options?: XmlWriteOptions): Promise; } //#endregion //#region src/converter/converter/XmlArraySchema.d.ts /** * Schema for parsing XML array values * * @public */ declare class XmlArraySchema> extends XmlSchemaBase { readonly element: T; readonly xpath?: string | undefined; readonly schemaType: "ARRAY"; constructor(element: T, xpath?: string | undefined); /** * Write array data to XML synchronously * @internal */ _writeSync(data: T["_output"][], options?: XmlWriteOptions): string; /** * Write array data to WritableStream asynchronously * @internal */ _write(data: T["_output"][], stream: WritableStream, options?: XmlWriteOptions): Promise; } //#endregion //#region src/converter/converter/XmlObjectSchema.d.ts /** * Shape type for object schema * * @public */ type XmlObjectShape = Record>; /** * Infer output type from object shape * * @public */ type InferObjectOutput = { [K in keyof T]: T[K]["_output"]; }; /** * Schema for parsing XML object values * * @public */ declare class XmlObjectSchema extends XmlSchema, unknown> { readonly shape: T; options: XmlObjectOptions; readonly schemaType: "OBJECT"; constructor(shape: T, options?: XmlObjectOptions); /** * Set XPath expression for locating the object * @param path - XPath expression * @returns New schema with XPath */ xpath(path: string): XmlObjectSchema; /** * Write object data to XML synchronously * @internal */ _writeSync(data: InferObjectOutput, options?: XmlWriteOptions): string; /** * Write object data to WritableStream asynchronously * @internal */ _write(data: InferObjectOutput, stream: WritableStream, options?: XmlWriteOptions): Promise; private _collectAttributes; private _hasElementContent; } //#endregion //#region src/converter/converter/XmlTransformSchema.d.ts /** * Schema for transforming parsed values * * @public */ declare class XmlTransformSchema extends XmlSchemaBase { readonly schemaType: "TRANSFORM"; /** @internal */ readonly schema: XmlSchemaBase; /** @internal */ readonly transformFn: (value: IntermediateOutput) => Output; constructor(schema: XmlSchemaBase, transformFn: (value: IntermediateOutput) => Output); _parseText(text: string): Output; /** * Write transformed data to XML synchronously * Note: Transform is not reversible, so writing is not supported * @internal */ _writeSync(data: Output, options?: XmlWriteOptions): string; /** * Write transformed data to WritableStream asynchronously * Note: Transform is not reversible, so writing is not supported * @internal */ _write(data: Output, stream: WritableStream, options?: XmlWriteOptions): Promise; } //#endregion //#region src/converter/converter/XmlOptionalSchema.d.ts /** * Schema for optional values * * @public */ declare class XmlOptionalSchema> extends XmlSchemaBase { readonly schema: T; readonly schemaType: "OPTIONAL"; constructor(schema: T); _parseText(text: string): T['_output'] | undefined; /** * Write optional data to XML synchronously * @internal */ _writeSync(data: T['_output'] | undefined, options?: XmlWriteOptions): string; /** * Write optional data to WritableStream asynchronously * @internal */ _write(data: T['_output'] | undefined, stream: WritableStream, options?: XmlWriteOptions): Promise; } //#endregion //#region src/converter/converter/types.d.ts /** * Parse options for XML converter * * @public */ interface ParseOptions { /** * TextDecoder encoding label for byte input. * String and materialized-event inputs are already decoded and ignore it. * @defaultValue 'utf-8' */ encoding?: string; /** * Whether to trim whitespace from text content * @defaultValue true */ trimText?: boolean; /** * XML document conformance mode. * * @defaultValue 'fragment' */ documentMode?: DocumentMode; /** * Maximum XML depth * @defaultValue Infinity */ maxDepth?: number; /** * Maximum number of events to process * @defaultValue Infinity */ maxEvents?: number; } /** * Options for string schema * * @public */ interface XmlStringOptions { /** * XPath expression to locate the element */ xpath?: string; } /** * Options for number schema * * @public */ interface XmlNumberOptions { /** * XPath expression to locate the element */ xpath?: string; /** * Minimum value */ min?: number; /** * Maximum value */ max?: number; /** * Whether the number must be an integer * @defaultValue false */ int?: boolean; } /** * Options for object schema * * @public */ interface XmlObjectOptions { /** * XPath expression to locate the element */ xpath?: string; } /** * Writer configuration for XML element * * @public */ interface XmlElementWriteConfig { /** * Element name. Object fields may omit this to use the field key. */ element?: string; /** * Write as attribute instead of element * Value is the attribute name */ asAttribute?: string; /** * Namespace configuration */ namespace?: { /** * Namespace prefix (e.g., 'dc', 'xsi') */ prefix?: string; /** * Namespace URI (e.g., 'http://purl.org/dc/elements/1.1/') */ uri: string; }; /** * Wrap content in CDATA section * @defaultValue false */ cdata?: boolean; /** * Use self-closing tag for empty elements * @defaultValue false */ selfClosing?: boolean; /** * Add XML comment before element */ comment?: string; } /** * Options for XML writer * * @public */ interface XmlWriteOptions { /** * Format output with indentation * @defaultValue false */ prettyPrint?: boolean; /** * Indentation string * @defaultValue ' ' */ indentString?: string; /** * Text encoding for output * @defaultValue 'utf-8' */ encoding?: 'utf-8' | 'UTF-8'; /** * Root element name * If not provided, no root element wrapper is added */ rootElement?: string; /** * Include XML declaration * @defaultValue true */ includeDeclaration?: boolean; /** * XML version for declaration * @defaultValue '1.0' */ xmlVersion?: '1.0'; /** * Custom writer instance * - WriterSync: for writeSync() method * - WriterSyncSink: for writeSync() with custom sink * - Writer: for write() async method */ writer?: WriterSync | WriterSyncSink | Writer; } /** * Schema type constants for XML schema classification * * @public */ declare const SchemaType: { readonly STRING: "STRING"; readonly NUMBER: "NUMBER"; readonly ARRAY: "ARRAY"; readonly OBJECT: "OBJECT"; readonly TRANSFORM: "TRANSFORM"; readonly OPTIONAL: "OPTIONAL"; }; /** * Schema type union * * @public */ type SchemaType = typeof SchemaType[keyof typeof SchemaType]; //#endregion //#region src/converter/converter/base.d.ts /** * Parse input type for XML text, byte chunks, or materialized StAX events. * * @public */ type ParseInput = string | Uint8Array | Iterable | Iterable | Iterable | AsyncIterable | AsyncIterable | AsyncIterable | ReadableStream; /** * Base abstract class for all XML schema types * * @remarks * This class provides the foundation for zod-style declarative XML parsing. * Each schema type extends this class and implements the parsing logic. * * @public */ declare abstract class XmlSchemaBase { readonly _output: Output; readonly _input: Input; /** * Schema type identifier * @internal */ abstract readonly schemaType: SchemaType; /** * Writer configuration for this schema * @internal */ protected writeConfig?: XmlElementWriteConfig; /** * Write data to XML string synchronously * @param data - Data to write * @param options - Write options * @returns XML string * @internal */ abstract _writeSync(data: Output, options?: XmlWriteOptions): string; /** * Write data to WritableStream asynchronously * @param data - Data to write * @param stream - Writable stream to write to * @param options - Write options * @internal */ abstract _write(data: Output, stream: WritableStream, options?: XmlWriteOptions): Promise; /** * Parse text content (used internally by parser) * @param text - Text content * @returns Parsed output * @internal */ _parseText?(text: string): Output; /** * Parse XML asynchronously (public API) * @param input - XML string, stream, or async iterator * @param options - Parse options * @returns Parsed output * @throws {XmlParseError} If parsing fails */ parse(input: ParseInput, options?: ParseOptions): Promise; /** * Parse XML synchronously (public API) * @param input - XML string or sync iterator * @param options - Parse options * @returns Parsed output * @throws {XmlParseError} If parsing fails */ parseSync(input: string | Uint8Array | Iterable | Iterable | Iterable, options?: ParseOptions): Output; /** * Build and cache the schema-specific IR program before parsing. * * Normal `parse()` and `parseSync()` calls do this automatically. Call * `precompile()` during server or worker startup only when the one-time * lowering and executor creation cost should happen before the first request. * The returned schema is the same instance, so startup code can precompile a * shared schema and request handlers can use it normally. * * @returns This schema instance */ precompile(): this; /** * Parse XML asynchronously with error handling * @param input - XML string, stream, or async iterator * @param options - Parse options * @returns Parse result with success flag */ safeParse(input: ParseInput, options?: ParseOptions): Promise>; /** * Parse XML synchronously with error handling * @param input - XML string, byte view, or sync iterator * @param options - Parse options * @returns Parse result with success flag */ safeParseSync(input: string | Uint8Array | Iterable | Iterable | Iterable, options?: ParseOptions): ParseResult; /** * Transform the parsed output * @param fn - Transform function * @returns New schema with transform applied */ transform(fn: (value: Output) => NewOutput): XmlSchemaBase; /** * Make this schema optional * @returns New optional schema */ optional(): XmlSchemaBase; /** * Convert this schema to an array schema * @param xpath - XPath expression for array elements * @returns New array schema */ array(xpath?: string): XmlSchemaBase; /** * Write data to XML string asynchronously (public API) * @param data - Data to write * @param options - Write options * @returns XML string */ write(data: Output, options?: XmlWriteOptions): Promise; /** * Write data to WritableStream asynchronously (public API) * @param data - Data to write * @param stream - Writable stream to write to * @param options - Write options */ writeToStream(data: Output, stream: WritableStream, options?: XmlWriteOptions): Promise; /** * Write data to XML string synchronously (public API) * @param data - Data to write * @param options - Write options * @returns XML string */ writeSync(data: Output, options?: XmlWriteOptions): string; /** * Configure writer settings for this schema * @param config - Writer configuration * @returns This schema with writer config */ writer(config: XmlElementWriteConfig): this; /** @internal */ static _createTransform: (schema: XmlSchemaBase, fn: (value: Output) => NewOutput) => XmlSchemaBase; /** @internal */ static _createOptional: >(schema: T) => XmlSchemaBase; /** @internal */ static _createArray: >(schema: T, xpath?: string) => XmlSchemaBase; /** @internal */ static _tryParseWithCompiledPlan?: (schema: XmlSchemaBase, input: string | Uint8Array | Iterable | Iterable | Iterable, options?: ParseOptions) => Output; /** @internal */ static _tryParseAsyncWithCompiledPlan?: (schema: XmlSchemaBase, input: ParseInput, options?: ParseOptions) => Promise; /** @internal */ static _precompileWithCompiledPlan?: (schema: XmlSchemaBase) => void; } //#endregion //#region src/converter/converter/XmlSchema.d.ts /** * Main XML schema class (extends XmlSchemaBase with all methods) * * @public */ declare abstract class XmlSchema extends XmlSchemaBase {} //#endregion //#region src/converter/converter/XmlBuilder.d.ts /** * Builder API for creating XML schemas * * @public */ declare class XmlBuilder { /** * Create a string schema * @param xpath - Optional XPath expression * @returns String schema */ string(xpath?: string): XmlStringSchema; /** * Create a number schema * @param xpath - Optional XPath expression * @returns Number schema */ number(xpath?: string): XmlNumberSchema; /** * Create an object schema * @param shape - Object shape definition * @param options - Optional object options * @returns Object schema */ object(shape: T, options?: XmlObjectOptions): XmlObjectSchema; /** * Create an array schema * @param element - Element schema * @param xpath - XPath expression for array elements * @returns Array schema */ array>(element: T, xpath?: string): XmlArraySchema; } /** * Singleton builder instance * * @public */ declare const x: XmlBuilder; //#endregion //#region src/converter/converter/index.d.ts /** Infer the parsed output type of a converter schema. */ type Infer> = T['_output']; //#endregion export { Infer, type InferObjectOutput, type ParseInput, type ParseOptions, type ParseResult, type XmlArraySchema, type XmlBuilder, type XmlElementWriteConfig, type XmlNumberOptions, type XmlNumberSchema, type XmlObjectOptions, type XmlObjectSchema, type XmlObjectShape, type XmlOptionalSchema, XmlParseError, type XmlSchema, type XmlSchemaBase, type XmlStringOptions, type XmlStringSchema, type XmlTransformSchema, type XmlWriteOptions, x };