/** The middleware function signature. */ export type Middleware = (request: Request, context: MiddlewareContext) => Response | void | Promise; /** Context passed to the middleware function. */ export interface MiddlewareContext { /** Helper to continue to the next handler. Can attach headers, params, and locals. */ next(options?: { headers?: Record; params?: Record; locals?: Record; }): void; /** Matched route params (only available if the path matches a page route). */ params?: Record; /** Per-request locals (populated by middleware, available to loaders/actions). */ locals?: Record; } /** Configuration for the middleware module. */ export interface MiddlewareConfig { /** Path patterns that trigger the middleware. Supports `:param` and `:param*`. */ matcher?: string[]; } export interface LoadedMiddleware { handler: Middleware; config: MiddlewareConfig; } /** Result of running middleware: either a response to short-circuit with, or continue. */ export type MiddlewareResult = { kind: "response"; response: Response; } | { kind: "continue"; headers?: Record; params?: Record; locals?: Record; }; /** * Loads the user's `src/middleware.ts` module. Returns `null` if no middleware * file exists. Distinguishes "file not found" from "file has errors" (§6): * an import error is not silently treated as "no middleware". */ export declare function loadMiddleware(root: string): Promise; /** * Checks if a pathname matches any of the middleware's matcher patterns. * If no matcher is configured, the middleware runs for every request. * * Catch-all patterns (`:param*`) match both the base path and any sub-paths, * e.g. `/dashboard/:path*` matches `/dashboard` and `/dashboard/settings/users`. */ export declare function matchesMiddleware(pathname: string, config: MiddlewareConfig): boolean; /** * Runs the middleware for a request. Returns the result indicating whether to * short-circuit with a response or continue with propagated headers/params/locals. * * Per §6: cleanup runs in `finally`, response short-circuits the pipeline, * headers/params/locals are propagated to downstream handlers. */ export declare function runMiddleware(middleware: LoadedMiddleware, request: Request, params?: Record): Promise;