import type { RouteMatch } from "./api-route-matcher.js"; import type { FileSystemAdapter } from "../../platform/adapters/base.js"; import { parseCookies } from "../../utils/cookie-utils.js"; import type { ApplicationIdentity } from "../../security/application-auth/types.js"; export { parseCookies }; /** Context object passed to API route handlers. */ export interface APIContext { request: Request; req: Request; identity?: ApplicationIdentity | null; applicationIdentity?: ApplicationIdentity | null; params: Record; query: URLSearchParams; cookies: Record; headers: Headers; url: URL; /** * Build a JSON `Response`. `ctx.json(data, init?)` mirrors `Response.json`. * * To read the request body, use `ctx.body()` or the raw `ctx.request.json()`. */ json: (data: unknown, init?: ResponseInit) => Response; /** * Read and parse the request body as JSON. * * The result is cached, so calling it more than once (or alongside a manual * `ctx.request.json()`) does not throw `Body already consumed`. A body that * is not valid JSON becomes a 400, not an unhandled 500. */ body: () => Promise; text: (data: string, init?: ResponseInit) => Response; fs: FileSystemAdapter; /** Immutable environment snapshot for the current project request. */ env: Readonly>; } /** * Build the `ctx.json` response helper. Writes only; mirrors `Response.json`. * * Exported because the isolation Worker builds its own context and has to * behave identically. Handlers must not care which one ran them. */ export declare function createJsonHelper(_request: Request): APIContext["json"]; /** * Build the `ctx.text` response helper. * * Exported for the isolation Worker so both execution modes share Fetch's * null-body status handling instead of maintaining separate implementations. */ export declare function createTextHelper(): APIContext["text"]; /** * Build the `ctx.body` request-body reader. * * The parse is memoised on the first call, so a validation helper and a handler * that both read the body do not fight over a single-use stream. The clone is * taken up front, while the context is built, so `ctx.request` is left intact * for a handler that still wants the raw stream — and, crucially, so a handler * that reads `ctx.request` raw *before* calling `ctx.body()` cannot make the * clone throw `Body already consumed` (`request.clone()` throws synchronously * once the original stream is disturbed). A malformed body is turned into a * catalogued 400 rather than escaping as a 500. */ export declare function createBodyReader(request: Request): APIContext["body"]; export declare function createContext(request: Request, match: RouteMatch, fs: FileSystemAdapter, env?: Readonly>, identity?: ApplicationIdentity | null): APIContext; /** * @deprecated Use {@link flattenRouteParams} directly. Kept as a thin alias so * the routing barrel exposes a single flattener implementation (issue #2742). */ export declare function normalizeParams(params: Record): Record; //# sourceMappingURL=context-builder.d.ts.map