/** * @module HttpRouter */ import { type Router } from "hono/router"; import { SmartRouter } from "hono/router/smart-router"; import { type HttpMiddleware, type HttpRouteGroup, type IHttpEndpoint, type IHttpRouter, type IHttpRouterBase, type WinterTcMiddleware, type WinterTcRequestHandler, type HttpHandlerFn } from "../../http-router/contracts/_module.js"; import { type RouterEntry } from "../../http-router/implementations/types.js"; import { type OneOrMore } from "../../utilities/_module.js"; /** * Configuration options for {@link HttpRouter}. * * IMPORT_PATH: `"@daiso-tech/core/http-router"` * @group Implementations */ export type HttpRouterSettings = { /** * A Hono router instance. * @default * ```ts * import { RegExpRouter } from "hono/router/reg-exp-router"; * import { SmartRouter } from "hono/router/smart-router"; * import { TrieRouter } from "hono/router/trie-router"; * * new SmartRouter({ * routers: [new RegExpRouter(), new TrieRouter()], * }) * ``` */ router: Router; /** * One or more WinterTC middleware functions or objects to apply to * every incoming request before route matching. * * These run at the top level of the router, before any route-specific * middlewares or endpoint handlers. Useful for cross-cutting concerns * such as logging, CORS, authentication, or request timing. */ middlewares?: OneOrMore; }; /** * A pre-configured default Hono router adapter combining {@link https://github.com/honojs/router | RegExpRouter} * and {@link https://github.com/honojs/router | TrieRouter} via {@link https://github.com/honojs/router | SmartRouter}. * * `SmartRouter` automatically selects the best matching router for each route, * providing optimized routing performance across different URL patterns. * * @default * ```ts * new SmartRouter({ * routers: [new RegExpRouter(), new TrieRouter()], * }) * ``` * * IMPORT_PATH: `"@daiso-tech/core/http-router"` * @group Implementations */ export declare const defaultHttpRouterAdapter: SmartRouter; /** * @group Implementations */ export declare class HttpRouter implements IHttpRouter { private readonly router; private readonly httpRouterBase; private readonly middlewares; readonly fetch: WinterTcRequestHandler; /** * Creates a new `HttpRouter` instance. * * @param settings - Configuration options for the router. */ constructor(settings: HttpRouterSettings); /** * Adapts a Winter TC request handler into an `HttpHandlerFn` that can be * used with `HttpRouter.endpoint()`. * * Winter TC handlers use the standard fetch signature * `(request: Request) => Promise`, while `HttpRouter` endpoint * handlers receive the richer `HttpHandlerArgs` interface. This method * bridges the two by passing `args.req.webReq` (the underlying Web API * `Request`) to the Winter TC handler and converting the returned * `Response` back via `args.fromWebRes()`. * * @param winterTcHandler - A Winter TC handler function conforming to * `WinterTcRequestHandler` (`(request: Request) => Promise`). * @returns An `HttpHandlerFn` suitable for use in `router.endpoint()`. * * @example * ```typescript * const winterHandler: WinterTcRequestHandler = async (request) => { * const url = new URL(request.url); * if (url.pathname === "/health") { * return new Response("OK", { status: 200 }); * } * return fetch(request); * }; * * router.endpoint({ * url: "/proxy/*", * method: ["GET"], * handler: HttpRouter.fromWinterTcHandler(winterHandler), * }); * ``` */ static fromWinterTcHandler(winterTcHandler: WinterTcRequestHandler): HttpHandlerFn; private static resolveRoute; private static isParamIndexMap; private static resolveParams; private static buildHandlerChain; use(middleware: HttpMiddleware): IHttpRouterBase; endpoint(endpoint: IHttpEndpoint): IHttpRouterBase; group(group: HttpRouteGroup): IHttpRouterBase; group(prefix: string, group: HttpRouteGroup): IHttpRouterBase; }