import { Middleware } from "./middleware.mjs"; import { Endpoint, EndpointOptions } from "./endpoint.mjs"; //#region src/router.d.ts interface RouterConfig { throwError?: boolean; onError?: (e: unknown) => void | Promise | Response | Promise; basePath?: string; routerMiddleware?: Array<{ path: string; middleware: Middleware; }>; /** * additional Context that needs to passed to endpoints * * this will be available on `ctx.context` on endpoints */ routerContext?: Record; /** * A callback to run before any response */ onResponse?: (res: Response) => any | Promise; /** * A callback to run before any request */ onRequest?: (req: Request) => any | Promise; /** * List of allowed media types (MIME types) for the router * * if provided, only the media types in the list will be allowed to be passed in the body. * * If an endpoint has allowed media types, it will override the router's allowed media types. * * @example * ```ts * const router = createRouter({ * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"], * }) */ allowedMediaTypes?: string[]; /** * Skip trailing slashes * * @default false */ skipTrailingSlashes?: boolean; /** * Open API route configuration */ openapi?: { /** * Disable openapi route * * @default false */ disabled?: boolean; /** * A path to display open api using scalar * * @default "/api/reference" */ path?: string; /** * Scalar Configuration */ scalar?: { /** * Title * @default "Open API Reference" */ title?: string; /** * Description * * @default "Better Call Open API Reference" */ description?: string; /** * Logo URL */ logo?: string; /** * Scalar theme * @default "saturn" */ theme?: string; }; }; } declare const createRouter: , Config extends RouterConfig>(endpoints: E, config?: Config) => { handler: (request: Request) => Promise; endpoints: E; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: Endpoint & { path: string; }; params: Record; }; /** * Extend the router with new endpoints * @param newEndpoints new endpoints to extend the router with * @returns new router with additional endpoints */ extend: >(newEndpoints: NE) => { handler: (request: Request) => Promise; endpoints: E & NE; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_1) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_2) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_3) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2 & NE_3; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_4) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2 & NE_3 & NE_4; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_5) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_6) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_7) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6 & NE_7; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_8) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6 & NE_7 & NE_8; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_9) => { handler: (request: Request) => Promise; endpoints: E & NE & NE_1 & NE_2 & NE_3 & NE_4 & NE_5 & NE_6 & NE_7 & NE_8 & NE_9; /** * Add a new endpoint to the router. * This is useful if you want to add an endpoint to the router after it has been created. */ addEndpoint: (endpoint: Endpoint) => void; /** * Find a route in the router. * @param method - The HTTP method of the route. * @param path - The path of the route. * @returns The route data and parameters. */ findRoute: (method: string, path: string) => { data: ((inputCtx: any) => Promise) & { options: EndpointOptions; path: string; } & { path: string; }; params: Record; }; extend: >(newEndpoints: NE_10) => /*elided*/any; }; }; }; }; }; }; }; }; }; }; }; type Router = ReturnType; //#endregion export { Router, RouterConfig, createRouter }; //# sourceMappingURL=router.d.mts.map