type StreamChunk = string | Uint8Array | ArrayBuffer; /** Server-side: where the writer sends text chunks. */ interface IOStreamTransport { send(chunk: string | Uint8Array): void | Promise; } /** * Client-side: a source of bytes/text chunks. * * Supported shapes: * - string * - Iterable * - AsyncIterable * - Web ReadableStream * - Node.js Readable (AsyncIterable) */ type IOStreamSource = string | Iterable | AsyncIterable | ReadableStream | AsyncIterable; interface StreamItem { data: T; schemaName: string; index: number; error?: Error; } interface StreamReaderOptions { /** Optional default schema name if header does not provide $schema. */ defaultSchema?: string; /** * Soft guardrails for streaming buffers. * This is not a security boundary, but prevents accidental unbounded growth. */ maxBufferedChars?: number; } interface StreamWriterOptions { /** Default: true. If false, schemas are not written into the header. */ includeSchemas?: boolean; /** If set, inserts a stable hash/id into header metadata (design hook). */ defsId?: string; /** * How to handle validation/serialization errors during write(). * - 'throw': Throw the error (default). * - 'ignore': Return empty string (skip the record). * - 'emit': Emit an error record (e.g. `!error { ... }`). */ onError?: 'throw' | 'ignore' | 'emit'; } export type { IOStreamSource, IOStreamTransport, StreamChunk, StreamItem, StreamReaderOptions, StreamWriterOptions };