import type { Plugin } from 'vite'; interface Options { srcDir: string; } /** Handler shape a `src/api/**\/route.ts` module exports, one per HTTP method. */ export type RouteHandler = (request: Request, context: { params: RouteParams; }) => Response | Promise; export type RouteParams = Record; export type ApiRouteParamKind = 'dynamic' | 'catchAll' | 'optionalCatchAll'; export interface ApiRouteSource { /** URL pattern, e.g. `/api/users/:id` — same `:name` convention as file routing (vite-plugin/routing.ts). */ pattern: string; paramNames: string[]; paramKinds: ApiRouteParamKind[]; /** Higher values match before less-specific dynamic/catch-all routes. */ specificity: number; /** Regex source (no flags) matching a request pathname and capturing param values in declaration order. */ regexSource: string; /** Absolute path to the route.ts module. */ filePath: string; } export interface ApiRouteMatch { route: ApiRouteSource; params: RouteParams; } /** * File-based API routing over `src/api/**\/route.ts`. * * Mirrors Next's dynamic segment convention (`[name]`, `[...name]`, and * `[[...name]]`) but, unlike the * page router, compiles each entry to a regex: the prod counterpart * (cli/build-server.ts) has to bake the route table into a generated module * ahead of time, and a regex source string serializes into that module * trivially (`new RegExp(source)` at runtime) where a closure-based matcher * wouldn't. */ export declare function scanApiRoutes(apiDir: string): Promise; /** * Matches `pathname` against `routes`. Static segments win over dynamic ones * — same "more specific wins" tie-break as react/app-router.tsx's * `matchRoute` — via a score of how many literal (non-param) segments the * pattern has. */ export declare function matchApiRoute(routes: ApiRouteSource[], pathname: string): ApiRouteMatch | null; /** * Dev-time counterpart of `src/api/**\/route.ts` handlers: a middleware that * matches `/api/*` requests against the discovered route table, loads the * matched module via `ssrLoadModule` (like server-actions.ts does for * `'use server'` modules), and dispatches to the export named after the * request method. In prod this is played by the routes registry * (cli/build-server.ts's `dist/server/routes.mjs`) + assets/prod-server.mjs, * which mirror the request/response handling here as closely as possible. */ export declare function apiRoutesPlugin({ srcDir }: Options): Plugin; export {}; //# sourceMappingURL=api-routes.d.ts.map