import { type ClientResponsePlugin, type ResponsePluginMarker, type RouterResponsePlugin } from './response.js'; declare const codecId = "rouzer/ndjson"; /** Values accepted by Rouzer's NDJSON response encoder. */ export type NdjsonSource = Iterable | AsyncIterable; /** Options for Rouzer's NDJSON response encoder. */ export type NdjsonEncodeOptions = { /** Signal whose abort cancels the source iterator and closes the stream. */ signal?: AbortSignal; }; /** * Create a compile-time marker for newline-delimited JSON response items. * * @remarks The returned marker is handled by `clientPlugin` in clients and * `routerPlugin` in routers. Generated client action functions resolve to an * `AsyncIterable`, while route handlers may return either an `Iterable` * or an `AsyncIterable`. Rouzer does not validate streamed items at runtime. */ export declare function $type(): ResponsePluginMarker, NdjsonSource, typeof codecId>; /** * Client plugin that decodes successful NDJSON responses. * * @remarks Register this plugin with `createClient({ plugins })` when the route * tree contains `response: ndjson.$type()` markers. */ export declare const clientPlugin: ClientResponsePlugin; /** * Router plugin that encodes handler results as NDJSON responses. * * @remarks Register this plugin with `createRouter({ plugins })` when the route * tree contains `response: ndjson.$type()` markers. Handler or generator * errors are not encoded as NDJSON items; model application-level errors in the * item type when clients should receive them as data. */ export declare const routerPlugin: RouterResponsePlugin; /** * Encode an iterable of values as a newline-delimited JSON byte stream. * * @remarks Each yielded value is serialized with `JSON.stringify` and followed * by `\n`. Values that cannot be represented as a JSON text, such as * `undefined`, cause the stream to error when read. When `options.signal` * aborts, the source iterator's `return()` method is called and the stream is * closed. */ export declare function encodeNdjson(source: NdjsonSource, options?: NdjsonEncodeOptions): ReadableStream; /** * Decode a newline-delimited JSON byte stream. * * @remarks UTF-8 chunks may split JSON lines. Both `\n` and `\r\n` line endings * are accepted, and a final line does not need a trailing newline. Malformed * lines throw a `SyntaxError` that includes the 1-based line number. */ export declare function decodeNdjson(stream: ReadableStream): AsyncIterable; /** * Create a `Response` whose body is encoded as newline-delimited JSON. * * @remarks The response defaults to * `content-type: application/x-ndjson; charset=utf-8` unless the caller supplies * a content type in `init.headers`. */ export declare function ndjsonResponse(source: NdjsonSource, { signal, ...init }?: ResponseInit & NdjsonEncodeOptions): Response; export {};