import type { HttpResponse } from "../contracts/typegen/http/response.ts"; import type { RequestContext } from "../contracts/typegen/http/request.ts"; import type { RouteDefinition } from "./router.ts"; export type RouteGuard = (context: RequestContext, route: RouteDefinition) => Promise | void | HttpResponse; export class RoutePipeline { private readonly guards: RouteGuard[] = []; use(guard: RouteGuard): this { this.guards.push(guard); return this; } async run(context: RequestContext, route: RouteDefinition): Promise { for (const guard of this.guards) { const result = await guard(context, route); if (result) return result; } return undefined; } }