import type { Response, ResponseBody } from '../../api/platform/Requests.js'; /** * The shape of raw HTTP headers: names mapped to a value, a list of values, or no value. * A Node `IncomingHttpHeaders` object satisfies this shape. */ export type RawHeaders = Record; /** * The source of response chunks. A platform provides the iterator from its own stream type. * For example, a Node `IncomingMessage` provides a compatible iterator through its * `Symbol.asyncIterator` method. */ export interface ResponseChunkIterator { /** * Resolves with the next chunk, or with `done: true` when the stream ends. Rejects when * the connection terminates before the server ends the stream. A chunk delivered together * with `done: true` is discarded, so the iterator must deliver the last chunk on its own. */ next(): Promise<{ done?: boolean; value?: Uint8Array; }>; /** * Releases the iterator. A Node `Readable` iterator queues this call behind a pending * read, so this call alone does not release an idle stream. */ return?(): Promise<{ done?: boolean; value?: Uint8Array; }>; } /** * The key of the chunk iterator on a streaming response source. A consumer's compile-time * lib may not declare `Symbol.asyncIterator`. This conditional resolves to that symbol when * the lib declares it, and to no key at all otherwise. That keeps these declarations valid * for every consumer, like `AbortSignalLike` does for the abort signal. Without the symbol, * the source type cannot require the iterator, and a source without a stream fails at run * time instead of compile time. */ type AsyncIteratorKey = typeof Symbol extends { readonly asyncIterator: infer S; } ? S extends keyof any ? S : never : never; /** * The source of a streaming response: the metadata and the chunk stream. A Node * `IncomingMessage` satisfies this shape, so a platform can pass its message directly. */ export type StreamingResponseSource = { headers: RawHeaders; statusCode?: number; statusMessage?: string; /** * Destroys the underlying stream. `cancel` uses it to release the connection even while * a read is in progress. A Node `Readable` provides it. A source without it must release * through the iterator `return` method; a source whose `return` queues behind a pending * read, like a Node readable iterator, must provide `destroy` or `cancel` cannot release * it mid-read. */ destroy?(): void; } & { [K in AsyncIteratorKey]: () => ResponseChunkIterator; }; /** * A response for a streaming request. Unlike the base response, the body and the status * message are always present. */ export interface StreamingResponse extends Response { body: ResponseBody; statusText: string; } /** * Creates a response for a streaming request. The response does not buffer the body. Each * read hands out the next chunk from the source iterator. The body does not enforce a * consumer lock: every `getReader`, `text`, and `json` call reads from the same iterator, * so the caller uses one consumer per response. The `cancel` methods on the body and the * reader call every release function the source provides: they destroy the source when it * has a `destroy` method, and they also call the iterator's `return` method when one * exists. The body passes through as-is, so the caller decodes any content encoding first. * * @param source The raw platform response, for example a Node `IncomingMessage`. A missing * status code maps to 0, and a missing status message maps to an empty string. */ export declare function createStreamingResponse(source: StreamingResponseSource): StreamingResponse; export {}; //# sourceMappingURL=StreamingResponse.d.ts.map