/** * Tree-based routing primitives. Types only. * * Internal segment syntax: `':name'` for single-segment params, `'*name'` * for splats. Translation layer converts user-facing path syntax to this * shape. */ import type { RequestContentTypeMap } from '../../validate/contentType.ts'; import type { StandardSchemaV1 } from '../../validate/types.ts'; import type AbstractMiddleware from '../middleware/AbstractMiddleware.ts'; /** * HTTP methods, upper-case. Single source of truth for the framework; * the runtime const + the `HttpMethod` type derive from this one array. */ export declare const HTTP_METHODS: readonly ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD', 'OPTIONS']; export type HttpMethod = (typeof HTTP_METHODS)[number]; /** * Body parsing mode per route. * * - `'parsed'` (default): Content-Type-aware parser dispatch. **The only mode * that takes effect today.** * * `'raw'` and `'none'` are **reserved and not implemented yet**. The matcher * resolves and propagates the mode, but the request pipeline does not act on * it: `RequestParser` is mounted globally, so every body is parsed regardless — * `req.rawBody` is never set and the stream is always consumed. Do not rely on * them until they ship (the parser-registry design lives in the refactor plans). * * - `'raw'` *(reserved)*: capture bytes into `req.rawBody: Buffer`, skip parsing. * - `'none'` *(reserved)*: pass-through, leave the request stream untouched. */ export type BodyParsingMode = 'parsed' | 'raw' | 'none'; /** * Canonical middleware shape stored in the registry. The `[Class, params]` * tuple shorthand is normalized to this struct at the boundary * (`middlewareNormalization.ts`). */ export interface MiddlewareEntry { Class: typeof AbstractMiddleware; params?: Record; } /** * Per-method handler entry. `meta` carries fields codegen uses * (`Request` alias) and observability uses (`code.filepath`, * `code.function`). */ export interface HandlerEntry { handler: Function; request?: StandardSchemaV1 | RequestContentTypeMap; query?: StandardSchemaV1; params?: StandardSchemaV1; middlewares?: MiddlewareEntry[]; bodyParsing?: BodyParsingMode; paramNames?: string[]; meta?: { methodName?: string; controllerClass?: string; sourceFile?: string; /** Author-supplied `RouteObject.description` — surfaced by the OpenAPI generator. */ description?: string; }; } /** * Tree node. Walked at request time: enter → run middlewares → descend. * * Specificity is structural: static `children` first, then `paramChild`, * then `splatChild`. At most one `paramChild` and one `splatChild` per * node. Different HTTP methods may use different param names at the same * position — each handler carries its own `paramNames` array. */ export interface RouteNode { segment: string; middlewares: MiddlewareEntry[]; methods?: Partial>; children: Map; paramChild?: RouteNode; splatChild?: RouteNode; bodyParsing?: BodyParsingMode; meta?: { sourceFile?: string; controllerClass?: string; }; } /** * Match outcome: * - `entry !== null` → success; adapter runs middlewares then handler. * - `entry === null` → the path matched but no matching route has the method * (405); `allowedMethods` lists the methods of every route matching the * path, for the `Allow` header. `middlewares` and `params` come from the most * specific of them — adapter chooses whether to run the middlewares. * * `match()` returns `null` when nothing matches (404). */ export interface MatchResult { entry: HandlerEntry | null; allowedMethods: HttpMethod[]; middlewares: MiddlewareEntry[]; params: Record; bodyParsing: BodyParsingMode; } /** One entry per (method, full-path) leaf — produced by `flatten()`. */ export interface FlatRoute { method: HttpMethod; path: string; entry: HandlerEntry; middlewares: MiddlewareEntry[]; bodyParsing: BodyParsingMode; }