import type { FetchResponse } from '../types.ts'; /** * Directive that determines how the response body is parsed. * * Controls the response extraction method applied after the fetch resolves, * allowing callers to declaratively specify their expected format. */ export type ResponseDirective = 'json' | 'text' | 'blob' | 'arrayBuffer' | 'formData' | 'raw' | 'stream'; /** * A stream-mode FetchPromise that also supports async iteration over chunks. * * Returned by `.stream()` to signal that the caller wants raw streaming * access to the response body as `Uint8Array` chunks. */ export interface FetchStreamPromise extends FetchPromise, AsyncIterable { } /** * Extended Promise that carries a response directive for the fetch engine. * * Enables a fluent API where callers declare their expected response type * (e.g. `.json()`, `.text()`, `.blob()`) before awaiting. The directive is * read by the executor to determine how to parse the response body. * * An override guard prevents setting the directive more than once, catching * accidental double-calls that would silently discard the first directive. * * @template T - Type of the parsed response data * @template H - Type of request headers * @template P - Type of request params * @template RH - Type of response headers * * @example * const user = await api.get('/users/1').json(); * const html = await api.get('/page').text(); * const file = await api.get('/file').blob(); */ export declare class FetchPromise extends Promise> { /** * Whether the executor has resolved or rejected (without abort). */ get isFinished(): boolean; /** * Whether the request was aborted, either via `abort()` or * an external signal on the controller. */ get isAborted(): boolean; /** * Abort the in-flight request. * * Sets `isAborted` and delegates to the stored AbortController. * Safe to call even when no controller is present (plain constructor). */ abort(reason?: string): void; /** * Factory that wires an executor and AbortController into a FetchPromise * with automatic finish/abort tracking. * * Replaces the previous pattern of patching abort state onto a plain * promise, giving callers a typed, first-class abort surface. * * @example * const controller = new AbortController(); * const fp = FetchPromise.create( * () => engine.execute(request, controller.signal), * controller * ); * fp.abort('user cancelled'); */ static create(executor: () => Promise>, controller: AbortController): FetchPromise; /** * The active response directive, if any. */ get directive(): ResponseDirective | undefined; /** * Whether stream mode is active. */ get isStream(): boolean; /** * Parse the response body as JSON. */ json(): FetchPromise; /** * Parse the response body as plain text. */ text(): FetchPromise; /** * Parse the response body as a Blob. */ blob(): FetchPromise; /** * Parse the response body as an ArrayBuffer. */ arrayBuffer(): FetchPromise; /** * Parse the response body as FormData. */ formData(): FetchPromise; /** * Return the raw Response object without parsing. */ raw(): FetchPromise; /** * Enable streaming mode for the response. * * Returns the raw Response and marks the promise for async iteration * over response body chunks. */ stream(): FetchStreamPromise; /** * Async iterator that yields response body chunks as `Uint8Array`. * * Only available after calling `.stream()`. Reads from the underlying * `ReadableStream` and releases the reader lock when iteration ends. * * @example * for await (const chunk of api.get('/large-file').stream()) { * process(chunk); * } */ [Symbol.asyncIterator](): AsyncIterator; }