import type { ServerResponse } from "node:http"; /** * Response and route-matching helpers shared by api.ts and the per-domain * router modules (`-api.ts`, plus `files.ts`, which predates the naming). * * They live below api.ts rather than in it because a domain module importing * `json` from api.ts would be a real runtime import cycle — api.ts imports the * domain module to dispatch to it. * * The contract every domain module follows: * * 1. One exported `handleApi(req, res, route, context): Promise`. * `true` means the request was consumed; `false` falls through to api.ts. * 2. It receives the already-parsed `ParsedRoute` and never re-parses `req.url` * — one parse means one set of rejection rules for hostile targets. * 3. Sends go through `json`/`notFound`/`badRequest`/`serverError` from here. A * module that rolls its own `send` drops the gzip/br negotiation; one whose * envelope is its own may adapt `json`, never write past it. * 4. Unexpected errors throw to api.ts's outer try/catch. A module keeps a * boundary of its own only if it logs the cause and answers in a shape its * clients already depend on — workflow-api's `{ code, message }` is the one. * Catches for an *expected* failure (a corrupt file on disk) stay put. * 5. Operator-only authority stays in `operatorOnlyControlPlaneRoute` wherever a * route reaches it. Workflow, talk and heartbeat dispatch ahead of that table; * files dispatches after it but the table lists no `/api/files` route. So all * four gate themselves, and each one is a place a guard can go missing. * 6. The delegation call sits exactly where the route block used to sit in the * dispatch chain, in the same order. */ /** The request line api.ts has already parsed, handed down to a domain module. */ export interface ParsedRoute { method: string; pathname: string; url: URL; } /** Per-request Accept-Encoding, stashed by handleApiRequest so json() can compress. */ export type ResWithEncoding = ServerResponse & { __acceptEncoding?: string; }; export declare function json(res: ServerResponse, data: unknown, status?: number): void; export declare function notFound(res: ServerResponse): void; export declare function badRequest(res: ServerResponse, message: string): void; export declare function serverError(res: ServerResponse, message: string): void; export declare function matchRoute(pattern: string, pathname: string): Record | null; //# sourceMappingURL=route-helpers.d.ts.map