//#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; } /** * Type guard function - Check if the event is a START_ELEMENT event * @param event XML event to check * @returns true if the event is a START_ELEMENT event, false otherwise */ declare function isStartElement(event: AnyXmlEvent): event is StartElementEvent; /** * Type guard function - Check if the event is an END_ELEMENT event * @param event XML event to check * @returns true if the event is an END_ELEMENT event, false otherwise */ declare function isEndElement(event: AnyXmlEvent): event is EndElementEvent; /** * Type guard function - Check if the event is a CHARACTERS event * @param event XML event to check * @returns true if the event is a CHARACTERS event, false otherwise */ declare function isCharacters(event: AnyXmlEvent): event is CharactersEvent; /** * Type guard function - Check if the event is a CDATA event * @param event XML event to check * @returns true if the event is a CDATA event, false otherwise */ declare function isCdata(event: AnyXmlEvent): event is CdataEvent; /** * Type guard function - Check if the event is an ERROR event * @param event XML event to check * @returns true if the event is an ERROR event, false otherwise */ /** * Type guard function - Check if the event is a START_DOCUMENT event * @param event XML event to check * @returns true if the event is a START_DOCUMENT event, false otherwise */ declare function isStartDocument(event: AnyXmlEvent): event is StartDocumentEvent; /** * Type guard function - Check if the event is an END_DOCUMENT event * @param event XML event to check * @returns true if the event is an END_DOCUMENT event, false otherwise */ declare function isEndDocument(event: AnyXmlEvent): event is EndDocumentEvent; /** * 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/StreamReader.d.ts /** Byte-stream sources accepted by `StreamReader`. */ type StreamReaderSource = AsyncIterable | ReadableStream; /** Options for asynchronous current-token parsing. */ interface StreamReaderOptions { documentMode?: DocumentMode; /** Resolve namespaces while retaining xmlns declarations in start-event attributes. @defaultValue true */ namespaceAware?: boolean; /** Decode predefined, numeric, and configured custom entities. @defaultValue true */ autoDecodeEntities?: boolean; /** Trusted internal entity replacements available without parsing a DTD. */ addEntities?: { entity: string; value: string; }[]; /** TextDecoder encoding label for byte input. @defaultValue 'utf-8' */ encoding?: string; } /** * Asynchronous, forward-only XML reader backed by a reusable token cursor. * Call `next()` before accessing the current token through the accessor methods. */ declare class StreamReader { private readonly cursor; private readonly iterator; private readonly decoder; private inFlight; private closed; private closing; constructor(source: StreamReaderSource, options?: StreamReaderOptions); /** Advance to the next token, or return `null` at end of input. */ next(): Promise; /** Stop parsing and close the underlying input iterator. */ close(): Promise; /** Return the current token type. */ eventType(): XmlEventType; /** Return the current element's qualified name. */ name(): string | undefined; /** Return text carried by the current text-like token. */ text(): string | undefined; /** Return the current element's local name. */ localName(): string | undefined; /** Return the current element's namespace prefix, or an empty string. */ prefix(): string; /** Return the namespace URI resolved for the current element. */ namespaceURI(): string; /** Return the number of attributes on the current start element. */ attributeCount(): number; /** Return an attribute's qualified name by zero-based index. */ attributeName(index: number): string | undefined; /** Return an attribute's local name by zero-based index. */ attributeLocalName(index: number): string | undefined; /** Return an attribute's namespace prefix by zero-based index. */ attributePrefix(index: number): string | undefined; /** Return an attribute's namespace URI by zero-based index. */ attributeNamespaceURI(index: number): string | undefined; /** Return an attribute value by index, qualified name, or namespace URI plus local name. */ attributeValue(indexOrNameOrNamespace: number | string, localName?: string): string | undefined; /** Resolve a namespace prefix in the current element scope. */ namespaceURIForPrefix(prefix: string): string; } //#endregion //#region src/async/EventReader.d.ts /** Options for the asynchronous materialized-event reader. */ interface EventReaderOptions extends StreamReaderOptions {} /** * Async iterator that yields stable, materialized XML event objects. * * Use `StreamReader` instead when current-token access and lower allocation are * more important than retaining event objects. */ declare class EventReader implements AsyncIterable, AsyncIterator { private readonly reader; constructor(input: StreamReaderSource, options?: EventReaderOptions); /** Return this reader as its async iterator. */ [Symbol.asyncIterator](): AsyncIterator; /** Read the next materialized event. */ next(): Promise>; /** Stop parsing and close the underlying input iterator. */ close(): Promise; /** Close the reader when async iteration ends early. */ return(): Promise>; } //#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/sync/StreamReaderSync.d.ts /** Inputs accepted by `StreamReaderSync`. */ type StreamReaderSyncInput = string | Uint8Array | Iterable; /** Options for synchronous current-token parsing. */ interface StreamReaderSyncOptions { documentMode?: DocumentMode; /** Resolve namespaces while retaining xmlns declarations in start-event attributes. @defaultValue true */ namespaceAware?: boolean; /** Decode predefined, numeric, and configured custom entities. @defaultValue true */ autoDecodeEntities?: boolean; /** Trusted internal entity replacements available without parsing a DTD. */ addEntities?: { entity: string; value: string; }[]; /** TextDecoder encoding label for byte input. @defaultValue 'utf-8' */ encoding?: string; } /** * Synchronous current-token reader. Strings are scanned directly without * encoding; byte inputs are decoded in fatal mode with the configured encoding. */ declare class StreamReaderSync { private readonly cursor; private iterator; private readonly decoder; private closed; constructor(input: StreamReaderSyncInput, options?: StreamReaderSyncOptions); /** Advance to the next token, or return `null` at end of input. */ next(): XmlEventType | null; /** Stop parsing and release the underlying input iterator. */ close(): void; /** Return the current token type. */ eventType(): XmlEventType; /** Return the current element's qualified name. */ name(): string | undefined; /** Return text carried by the current text-like token. */ text(): string | undefined; /** Return the current element's local name. */ localName(): string | undefined; /** Return the current element's namespace prefix, or an empty string. */ prefix(): string; /** Return the namespace URI resolved for the current element. */ namespaceURI(): string; /** Return the number of attributes on the current start element. */ attributeCount(): number; /** Return an attribute's qualified name by zero-based index. */ attributeName(index: number): string | undefined; /** Return an attribute's local name by zero-based index. */ attributeLocalName(index: number): string | undefined; /** Return an attribute's namespace prefix by zero-based index. */ attributePrefix(index: number): string | undefined; /** Return an attribute's namespace URI by zero-based index. */ attributeNamespaceURI(index: number): string | undefined; /** Return an attribute value by index, qualified name, or namespace URI plus local name. */ attributeValue(indexOrNameOrNamespace: number | string, localName?: string): string | undefined; /** Resolve a namespace prefix in the current element scope. */ namespaceURIForPrefix(prefix: string): string; } //#endregion //#region src/sync/EventReaderSync.d.ts /** Options for the synchronous materialized-event reader. */ interface EventReaderSyncOptions extends StreamReaderSyncOptions {} /** Synchronous iterator that yields stable, materialized XML event objects. */ declare class EventReaderSync implements Iterable, Iterator { private readonly reader; private finished; constructor(input: StreamReaderSyncInput, options?: EventReaderSyncOptions); /** Return this reader as its iterator. */ [Symbol.iterator](): Iterator; /** Read the next materialized event. */ next(): IteratorResult; /** Close the reader when iteration ends early. */ return(): IteratorResult; /** Stop parsing and release the underlying input iterator. */ close(): void; } //#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 export { type AnyXmlEvent, type AsyncTextSink, type AttributeInfo, type CdataEvent, type CharactersEvent, type CommentEvent, type DocumentMode, type DtdEvent, type EndDocumentEvent, type EndElementEvent, type EventAttribute, type EventAttributes, EventReader, type EventReaderOptions, EventReaderSync, type EventReaderSyncOptions, type ProcessingInstructionEvent, type StartDocumentEvent, type StartElementEvent, StreamReader, type StreamReaderOptions, type StreamReaderSource, StreamReaderSync, type StreamReaderSyncInput, type StreamReaderSyncOptions, type SyncTextSink, type WriteElementOptions, Writer, type WriterOptions, WriterSync, type WriterSyncOptions, WriterSyncSink, type WriterSyncSinkOptions, XmlEventType, isCdata, isCharacters, isEndDocument, isEndElement, isStartDocument, isStartElement };