/** * The shared HTTP route runtime: the mount-relative path, the route-table types * and matcher, the envelope helpers, and the param validators. * * Generic in the per-request context, because the matcher only ever READS * `request`/`path`/`segments` and WRITES `params` — whatever else a caller hangs * off its own context (composed deps, a RunContext resolver) is invisible here. * `@vendoai/vendo`'s wire binds this to its own WireContext (wire/shared.ts). */ import { VendoError } from "../core/index.js"; export declare function isJsonRequest(request: Request): boolean; /** The mount-relative raw path a route table matches on, or null when the URL falls outside the mount entirely (the caller answers not-found). */ export declare function relativePath(mount: string, url: URL): string | null; /** What the matcher needs from a per-request context: the raw request, the mount-relative raw path, the decoded segments, and the slot the matched entry's `:param` captures land in. */ export interface RouteContext { request: Request; path: string; readonly segments: string[]; params: Record; } /** A handler answers with a Response, or returns undefined to FALL THROUGH to the next entry — mirroring the old if-chain, where a matched-path block whose method/operation checks all missed simply fell out the bottom (any side effects it ran, e.g. context resolution, stand). */ export type RouteHandler = (wire: W) => Promise; type RoutePattern = /** Raw-path equality — no decoding, matching the old `path === "/x"` arms. */ { kind: "exact"; path: string; } /** Raw-path prefix — matching the old `path.startsWith("/x/")` arms. */ | { kind: "prefix"; prefix: string; } /** Decoded-segment match: literals compare against decoded values, `:name` captures, a trailing rest wildcard allows ZERO or more extra segments — matching the old `head === "x" && segments.length >= n` arms. */ | { kind: "segments"; parts: string[]; rest: boolean; }; export interface RouteEntry { /** Exact method, or "*" for grouped handlers that dispatch methods inside. */ method: string; pattern: RoutePattern; handler: RouteHandler; /** Opt-in: this handler makes a same-origin HOST CALL during its OWN dispatch, so a caller that learns a same-origin default from route matches must learn it at handler ENTRY for this entry (before the call), not after the handler returns. Off by default — the safe default is to learn only from a handler that TERMINALLY answered (returned a non-undefined Response), so a route that matched then fell through (returned undefined → 404) never teaches it. Consumed by @vendoai/vendo's wire wrapper; see server.ts. */ learnsOriginAtEntry?: boolean; } /** Table entry from a pattern string: no `:param` and no trailing `/*` means raw-path equality; otherwise decoded-segment matching (trailing `/*` = rest wildcard, zero or more segments). */ export declare function route(method: string, pattern: string, handler: RouteHandler): RouteEntry; /** Table entry matching on a raw path prefix (webhooks, proxy, the doctor production gate) — never decodes, exactly like the old startsWith arms. Raw string match, no segment boundary — include the trailing slash. */ export declare function prefixRoute(method: string, prefix: string, handler: RouteHandler): RouteEntry; /** Scan the table in order; a handler returning undefined keeps scanning (fall-through). No match → undefined; the caller answers not-found. */ export declare function dispatchRoutes(routes: readonly RouteEntry[], wire: W): Promise; export declare function json(body: unknown, status?: number): Response; export declare function errorResponse(error: VendoError): Response; export declare function internalError(): Response; export declare function object(value: unknown, label: string): Record; export declare function string(value: unknown, label: string): string; export declare function requestJson(request: Request): Promise>; export declare function routeSegments(path: string): string[]; /** Bytes → lowercase hex. Used by wire/misc.ts's timing-safe digest compare. */ export declare function hex(bytes: ArrayBuffer | Uint8Array): string; export {};