import { Handler, HttpContext, KoaRouterApp, Middleware } from "../types/koa.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/koa/router.d.ts /** * @class clear-router Koa Router * @description Laravel-style routing system for Koa using @koa/router and 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(name: string): string; private static readonly bodyCache; private static readBodyCached; private static readBody; private static sendReturnValue; /** * Adds a new route to the router. * * @param methods * @param path * @param handler * @param middlewares */ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Define a resourceful API controller with standard CRUD routes * * @param basePath * @param controller * @param options */ 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>; /** * Adds a new HEAD route to the router. * * @param this * @param path * @param handler * @param middlewares */ static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route>; /** * Defines a group of routes with a common prefix. * * @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 - Middleware or array of middlewares to apply * @param callback - Function that defines the routes to which the middlewares will be applied */ static middleware(middlewares: Middleware[], callback: () => void): void; /** * Get all defined routes, optionally organized by path or method */ 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 @koa/router instance * * @param router @koa/router instance * @returns The @koa/router instance with the applied routes */ static apply(router: KoaRouterApp): KoaRouterApp; } //#endregion export { Router };