/** * @module * BearMetal Router types */ /** * @description a context object for a request */ export interface RouterContext { url: URL; params: Record; state: Record; pattern: URLPattern; request: Request; } /** * @description a function that handles incoming requests */ export type Handler = ( req: Request, ctx: RouterContext, ) => Promise | Response; /** * @description a middleware function */ export type Middleware = ( req: Request, ctx: RouterContext, next: () => Promise, ) => Promise; /** * @description a route configuration */ export interface RouteConfig { pattern: URLPattern; handlers: { [method: string]: Handler }; } /** * @description a middleware configuration */ export interface MiddlewareConfig { pattern: URLPattern; handler: Middleware; path: string; } /** * @description a route configurator */ export interface RouteConfigurator { get(handler: Handler): RouteConfigurator; post(handler: Handler): RouteConfigurator; put(handler: Handler): RouteConfigurator; delete(handler: Handler): RouteConfigurator; patch(handler: Handler): RouteConfigurator; options(handler: Handler): RouteConfigurator; }