import { FastifyApp, Handler, HttpContext, Middleware } from "../types/fastify.mjs"; import { Route } from "../Route.mjs"; import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs"; import { ResourceRoutes } from "../ResourceRoutes.mjs"; import { RouteGroup } from "../RouteGroup.mjs"; import { CoreRouter } from "../core/CoreRouter.mjs"; //#region src/fastify/router.d.ts /** * @class clear-router Fastify Router * @description Laravel-style routing system for Fastify using shared clear-router core * @author 3m1n3nc3 * @repository https://github.com/arkstack-hq/clear-router */ declare class Router extends CoreRouter { protected static routerStateNamespace: string; protected static formatWildcardParam(): string; private static ensureRequestBodyAccessor; private static sendReturnValue; /** * Add a route to the router * * @param methods HTTP methods for the route * @param path Route path * @param handler Route handler function * @param middlewares Optional middlewares for the route */ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a resourceful API controller with standard CRUD routes * * @param basePath Base path for the resource * @param controller Controller class or instance * @param options Optional configuration for the resource */ static apiResource(basePath: string, controller: any, options?: { only?: ResourceAction[]; except?: ResourceAction[]; middlewares?: ApiResourceMiddleware; }): ResourceRoutes; /** * Define a GET route * * @param path * @param handler * @param middlewares */ static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a POST route * * @param path * @param handler * @param middlewares */ static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a PUT route * * @param path * @param handler * @param middlewares */ static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a DELETE route * * @param path * @param handler * @param middlewares */ static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a PATCH route * * @param path * @param handler * @param middlewares */ static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define an OPTIONS route * * @param path * @param handler * @param middlewares */ static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a HEAD route * * @param path * @param handler * @param middlewares */ static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a group of routes with a common prefix and optional middlewares * * @param prefix * @param callback * @param middlewares */ static group(prefix: string, source: S, middlewares?: Middleware[]): RouteGroup, S>; /** * Apply middlewares to a group of routes defined within the callback * * @param middlewares * @param callback */ static middleware(middlewares: Middleware[], callback: () => void): void; static allRoutes(): Array>>; /** * @param type - 'path' to get routes organized by path */ static allRoutes(type: 'path'): Record>>; /** * @param type - 'method' to get routes organized by method */ static allRoutes(type: 'method'): { [method in Uppercase]?: Array>> }; static allRoutes(type: 'name'): Record>>; static route(name: string): Route> | undefined; /** * Apply the defined routes to a Fastify application instance * * @param app - The Fastify application instance * @returns The Fastify application instance with the applied routes */ static apply(app: FastifyApp): FastifyApp; } //#endregion export { Router };