import type { Server as BunServer } from "bun"; import { BunRequest } from "./request"; import { BunResponse } from "./response"; import type { Handler, ErrorHandler, RouteDefinition, RouterOptions, WebSocketHandlers, WebSocketRouteDefinition } from "../types"; import { FastMatcher } from "./fast-matcher"; import { Route } from "./route"; interface SubRouter { prefix: string; router: Router; prefixRegex?: RegExp; prefixKeys?: string[]; } interface GroupOptions { middleware?: Handler[]; } type GroupCallback = (router: Router) => void; type ParamHandler = (req: BunRequest, res: BunResponse, next: (err?: unknown) => void, value: string, name: string) => void; export declare class Router { protected routes: RouteDefinition[]; protected middlewares: Handler[]; protected prefixMiddlewares: Array<{ prefix: string; handlers: Handler[]; }>; protected errorHandlers: ErrorHandler[]; protected children: SubRouter[]; protected routerOptions: RouterOptions; protected paramHandlers: Map; protected wsRoutes: WebSocketRouteDefinition[]; private readonly _mergeParams; protected fastMatcher: FastMatcher; protected _appContext: { setApp: (req: BunRequest, res: BunResponse) => void; } | null; constructor(opts?: RouterOptions); /** * Set the app context for direct injection (used by BunWayApp) */ setAppContext(context: { setApp: (req: BunRequest, res: BunResponse) => void; }): void; protected getRoutes(): RouteDefinition[]; protected getMiddlewares(): Handler[]; protected getErrorHandlers(): ErrorHandler[]; protected getChildren(): SubRouter[]; param(name: string, handler: ParamHandler): this; private collectRouteMatches; private dispatchMatchingRoutes; private dispatchFromMatch; private matchChild; private prefixToRegex; private pathToRegex; private addRoute; private addRegexRoute; get(path: string | RegExp, ...handlers: Handler[]): this; post(path: string | RegExp, ...handlers: Handler[]): this; put(path: string | RegExp, ...handlers: Handler[]): this; delete(path: string | RegExp, ...handlers: Handler[]): this; patch(path: string | RegExp, ...handlers: Handler[]): this; options(path: string | RegExp, ...handlers: Handler[]): this; head(path: string | RegExp, ...handlers: Handler[]): this; all(path: string | RegExp, ...handlers: Handler[]): this; route(path: string): Route; use(handler: Handler): this; use(paths: string[], router: Router): this; use(paths: string[], ...handlers: Handler[]): this; use(path: string, router: Router): this; use(path: string, ...handlers: Handler[]): this; group(prefix: string, callbackOrOptions?: GroupCallback | GroupOptions, callback?: GroupCallback): this; ws(path: string, handlers: WebSocketHandlers): this; ws(path: string, ...args: [...Handler[], WebSocketHandlers]): this; getWsRoutes(): WebSocketRouteDefinition[]; matchWebSocketRoute(pathname: string): { route: WebSocketRouteDefinition; params: Record; } | null; /** * Print all registered routes for debugging. * Useful during development to see what routes are available. * * @example * app.printRoutes(); * // Output: * // GET / * // GET /users * // POST /users * // GET /users/:id * // WS /chat */ printRoutes(prefix?: string): void; /** * Get all registered routes as an array (for programmatic access). * * @example * const routes = app.getRegisteredRoutes(); * // [{ method: 'GET', path: '/', ... }, ...] */ getRegisteredRoutes(prefix?: string): Array<{ method: string; path: string; fullPath: string; }>; handle(original: Request, server?: BunServer): Promise; /** * Internal handle method for child router delegation - avoids creating new Request/URL objects */ protected handleInternal(original: Request, pathname: string, method: string, server?: BunServer, parentParams?: Record, baseUrl?: string, errorBubble?: (err: unknown, req: BunRequest, res: BunResponse) => Promise): Promise; /** * Handle request with middleware pipeline - creates req/res upfront */ private handleWithMiddleware; private runPipeline; private handleError; } export {}; //# sourceMappingURL=router.d.ts.map