import { HttpStatus } from "@mpen/http"; //#region src/router/fetch-types.d.ts /** * Headers initializer accepted by the active Fetch runtime. * * @internal */ type RouterHeadersInit = NonNullable[0]>; /** * Response body initializer accepted by the active Fetch runtime. * * @internal */ type RouterBodyInit = NonNullable[0]>; //#endregion //#region src/router/response/core.d.ts declare const routekitResponseBrand: unique symbol; declare const routekitBodyBrand: unique symbol; /** * Logical route result used by Routekit before it is finalized into a native [`Response`]{@link Response}. * * @example * ```ts * const result = ok({payload: 'ready'}) * ``` */ interface RoutekitResponse { readonly [routekitResponseBrand]: true; /** * HTTP status code to use for the finalized response. */ status: Status; /** * Headers to include in the finalized response. */ headers: Headers; /** * Logical or represented response body. */ body: T; } /** * Options accepted by logical response helpers. */ interface RoutekitResponseInit { /** * HTTP status code for the response. Defaults to `200`. */ status?: Status; /** * Headers to include in the finalized response. */ headers?: RouterHeadersInit; } /** * Final body wrapper returned from a handler or generator. * * @example * ```ts * return body({payload: 'done'}) * ``` */ interface RoutekitBody { readonly [routekitBodyBrand]: true; /** * Logical response body value. */ value: T; } /** * Test whether a value can be passed directly to the native [`Response`]{@link Response} constructor. * * @example * ```ts * isResponseBodyInit('ok') * ``` * * @param value - Value to inspect. * @returns Whether `value` is a native response body. */ declare function isResponseBodyInit(value: unknown): value is RouterBodyInit | null | undefined; /** * Test whether a value is a Routekit logical response. * * @example * ```ts * if (isRoutekitResponse(result)) result.headers.set('x-request-id', id) * ``` * * @param value - Value to inspect. * @returns Whether `value` was created by a Routekit response helper. */ declare function isRoutekitResponse(value: unknown): value is RoutekitResponse; /** * Test whether a value is a final body wrapper. * * @example * ```ts * const value = isRoutekitBody(result) ? result.value : result * ``` * * @param value - Value to inspect. * @returns Whether `value` was created by [`body`]{@link body}. */ declare function isRoutekitBody(value: unknown): value is RoutekitBody; /** * Create a logical response. * * If `headers` contains `Content-Type`, the body must be compatible with the native * [`Response`]{@link Response} constructor because the router will skip negotiation. * * @example * ```ts * return response({ok: true}, {status: 202}) * ``` * * @param responseBody - Logical or represented response body. * @param init - Response status and headers. * @returns Routekit logical response. */ declare function response(responseBody: T): RoutekitResponse; declare function response(responseBody: T, init: Omit): RoutekitResponse; declare function response(responseBody: T, init: RoutekitResponseInit & { status: Status; }): RoutekitResponse; /** * Wrap a returned value as the final response body. * * @example * ```ts * return body({payload: 'done'}) * ``` * * @param value - Logical response body. * @returns Final body wrapper. */ declare function body(value: T): RoutekitBody; //#endregion export { isResponseBodyInit as a, response as c, body as i, RouterBodyInit as l, RoutekitResponse as n, isRoutekitBody as o, RoutekitResponseInit as r, isRoutekitResponse as s, RoutekitBody as t, RouterHeadersInit as u };