clear-router 2.1.11 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,392 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+
3
+ //#region src/ClearRequest.ts
4
+ var ClearRequest = class {
5
+ /**
6
+ * @param body - Parsed request body
7
+ */
8
+ body;
9
+ /**
10
+ * @param query - Parsed query parameters
11
+ */
12
+ query;
13
+ /**
14
+ * @param params - Parsed route parameters
15
+ */
16
+ params;
17
+ route;
18
+ constructor(init) {
19
+ Object.assign(this, init);
20
+ }
21
+ };
22
+
23
+ //#endregion
24
+ //#region src/Route.ts
25
+ var Route = class {
26
+ ctx;
27
+ body = {};
28
+ query = {};
29
+ params = {};
30
+ clearRequest;
31
+ methods;
32
+ path;
33
+ handler;
34
+ middlewares;
35
+ controllerName;
36
+ actionName;
37
+ handlerType;
38
+ middlewareCount;
39
+ constructor(methods, path, handler, middlewares = []) {
40
+ this.methods = methods;
41
+ this.path = path;
42
+ this.handler = handler;
43
+ this.middlewares = middlewares;
44
+ this.handlerType = Array.isArray(handler) ? "controller" : "function";
45
+ this.middlewareCount = middlewares.length;
46
+ this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
47
+ this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
48
+ }
49
+ };
50
+
51
+ //#endregion
52
+ //#region src/core/router.ts
53
+ /**
54
+ * @class clear-router CoreRouter
55
+ * @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
56
+ * @author 3m1n3nc3
57
+ * @repository https://github.com/toneflix/clear-router
58
+ */
59
+ var CoreRouter = class {
60
+ static config = { methodOverride: {
61
+ enabled: true,
62
+ bodyKeys: ["_method"],
63
+ headerKeys: ["x-http-method"]
64
+ } };
65
+ static groupContext = new AsyncLocalStorage();
66
+ static routes = [];
67
+ static routesByPathMethod = {};
68
+ static routesByMethod = {};
69
+ static prefix = "";
70
+ static groupMiddlewares = [];
71
+ static globalMiddlewares = [];
72
+ static ensureState() {
73
+ if (!Object.prototype.hasOwnProperty.call(this, "config")) this.config = { methodOverride: {
74
+ enabled: true,
75
+ bodyKeys: ["_method"],
76
+ headerKeys: ["x-http-method"]
77
+ } };
78
+ if (!Object.prototype.hasOwnProperty.call(this, "groupContext")) this.groupContext = new AsyncLocalStorage();
79
+ if (!Object.prototype.hasOwnProperty.call(this, "routes")) this.routes = [];
80
+ if (!Object.prototype.hasOwnProperty.call(this, "routesByPathMethod")) this.routesByPathMethod = {};
81
+ if (!Object.prototype.hasOwnProperty.call(this, "routesByMethod")) this.routesByMethod = {};
82
+ if (!Object.prototype.hasOwnProperty.call(this, "prefix")) this.prefix = "";
83
+ if (!Object.prototype.hasOwnProperty.call(this, "groupMiddlewares")) this.groupMiddlewares = [];
84
+ if (!Object.prototype.hasOwnProperty.call(this, "globalMiddlewares")) this.globalMiddlewares = [];
85
+ }
86
+ /**
87
+ * Normalizes a path by ensuring it starts with a single slash and does not have trailing
88
+ * slashes, while preserving dynamic segments and parameters.
89
+ *
90
+ * @param path The path to normalize.
91
+ * @returns The normalized path.
92
+ */
93
+ static normalizePath(path) {
94
+ return "/" + path.split("/").filter(Boolean).join("/");
95
+ }
96
+ /**
97
+ * Configures the router with the given options, such as method override settings.
98
+ *
99
+ * @param this
100
+ * @param options
101
+ * @returns
102
+ */
103
+ static configure(options) {
104
+ this.ensureState();
105
+ if (!this.config.methodOverride) this.config.methodOverride = {
106
+ enabled: true,
107
+ bodyKeys: ["_method"],
108
+ headerKeys: ["x-http-method"]
109
+ };
110
+ const override = options?.methodOverride;
111
+ if (!override) return;
112
+ if (typeof override.enabled === "boolean") this.config.methodOverride.enabled = override.enabled;
113
+ const bodyKeys = override.bodyKeys;
114
+ if (typeof bodyKeys !== "undefined") this.config.methodOverride.bodyKeys = (Array.isArray(bodyKeys) ? bodyKeys : [bodyKeys]).map((e) => String(e).trim()).filter(Boolean);
115
+ const headerKeys = override.headerKeys;
116
+ if (typeof headerKeys !== "undefined") this.config.methodOverride.headerKeys = (Array.isArray(headerKeys) ? headerKeys : [headerKeys]).map((e) => String(e).trim().toLowerCase()).filter(Boolean);
117
+ }
118
+ static resolveMethodOverride(method, headers, body) {
119
+ this.ensureState();
120
+ if (!this.config.methodOverride?.enabled || method.toLowerCase() !== "post") return null;
121
+ let override;
122
+ const headerValueFor = (key) => {
123
+ if (typeof headers.get === "function") return headers.get(key);
124
+ const value = headers?.[key];
125
+ return Array.isArray(value) ? value[0] : value;
126
+ };
127
+ for (const key of this.config.methodOverride?.headerKeys || []) {
128
+ const value = headerValueFor(key);
129
+ if (value) {
130
+ override = value;
131
+ break;
132
+ }
133
+ }
134
+ if (!override && body && typeof body === "object") for (const key of this.config.methodOverride?.bodyKeys || []) {
135
+ const value = body[key];
136
+ if (typeof value !== "undefined" && value !== null && value !== "") {
137
+ override = value;
138
+ break;
139
+ }
140
+ }
141
+ const normalized = String(override || "").trim().toLowerCase();
142
+ if (!normalized) return null;
143
+ if ([
144
+ "put",
145
+ "patch",
146
+ "delete",
147
+ "post"
148
+ ].includes(normalized)) return normalized;
149
+ return null;
150
+ }
151
+ /**
152
+ * Adds a new route to the router with the specified methods, path, handler, and middlewares.
153
+ *
154
+ * @param this
155
+ * @param methods
156
+ * @param path
157
+ * @param handler
158
+ * @param middlewares
159
+ */
160
+ static add(methods, path, handler, middlewares) {
161
+ this.ensureState();
162
+ const context = this.groupContext.getStore();
163
+ const activePrefix = context?.prefix ?? this.prefix;
164
+ const activeGroupMiddlewares = context?.groupMiddlewares ?? this.groupMiddlewares;
165
+ methods = Array.isArray(methods) ? methods : [methods];
166
+ middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
167
+ const fullPath = this.normalizePath(`${activePrefix}/${path}`);
168
+ const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
169
+ ...this.globalMiddlewares,
170
+ ...activeGroupMiddlewares,
171
+ ...middlewares || []
172
+ ]);
173
+ if (!methods.includes("options") && !this.routesByPathMethod[`OPTIONS ${fullPath}`]) this.options(path, ({ res }) => {
174
+ if (res?.headers?.set) {
175
+ res.headers.set("Allow", "GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD");
176
+ res.status = 204;
177
+ return;
178
+ }
179
+ if (res?.set) {
180
+ res.set("Allow", "GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD");
181
+ res.sendStatus(204);
182
+ }
183
+ });
184
+ this.routes.push(route);
185
+ for (const method of methods.map((m) => m.toUpperCase())) {
186
+ this.routesByPathMethod[`${method} ${fullPath}`] = route;
187
+ if (!this.routesByMethod[method]) this.routesByMethod[method] = [];
188
+ this.routesByMethod[method].push(route);
189
+ }
190
+ }
191
+ /**
192
+ * Adds a new API resource route to the router for the specified base path and controller, with
193
+ * options to include/exclude specific actions and apply middlewares.
194
+ *
195
+ * @param this
196
+ * @param basePath
197
+ * @param controller
198
+ * @param options
199
+ */
200
+ static apiResource(basePath, controller, options) {
201
+ const actions = {
202
+ index: {
203
+ method: "get",
204
+ path: "/"
205
+ },
206
+ show: {
207
+ method: "get",
208
+ path: "/:id"
209
+ },
210
+ create: {
211
+ method: "post",
212
+ path: "/"
213
+ },
214
+ update: {
215
+ method: "put",
216
+ path: "/:id"
217
+ },
218
+ destroy: {
219
+ method: "delete",
220
+ path: "/:id"
221
+ }
222
+ };
223
+ const only = options?.only || Object.keys(actions);
224
+ const except = options?.except || [];
225
+ const preController = typeof controller === "function" ? new controller() : controller;
226
+ for (const action of only) {
227
+ if (except.includes(action)) continue;
228
+ if (typeof preController[action] === "function") {
229
+ const { method, path } = actions[action];
230
+ const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
231
+ this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0);
232
+ }
233
+ }
234
+ }
235
+ /**
236
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
237
+ *
238
+ * @param this The router instance.
239
+ * @param path The path for the GET route.
240
+ * @param handler The handler function for the GET route.
241
+ * @param middlewares Optional middlewares to apply to the GET route.
242
+ */
243
+ static get(path, handler, middlewares) {
244
+ this.add("get", path, handler, middlewares);
245
+ }
246
+ /**
247
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
248
+ *
249
+ * @param this
250
+ * @param path
251
+ * @param handler
252
+ * @param middlewares
253
+ */
254
+ static post(path, handler, middlewares) {
255
+ this.add("post", path, handler, middlewares);
256
+ }
257
+ /**
258
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
259
+ *
260
+ * @param this
261
+ * @param path
262
+ * @param handler
263
+ * @param middlewares
264
+ */
265
+ static put(path, handler, middlewares) {
266
+ this.add("put", path, handler, middlewares);
267
+ }
268
+ /**
269
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
270
+ *
271
+ * @param this
272
+ * @param path
273
+ * @param handler
274
+ * @param middlewares
275
+ */
276
+ static delete(path, handler, middlewares) {
277
+ this.add("delete", path, handler, middlewares);
278
+ }
279
+ /**
280
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
281
+ *
282
+ * @param this
283
+ * @param path
284
+ * @param handler
285
+ * @param middlewares
286
+ */
287
+ static patch(path, handler, middlewares) {
288
+ this.add("patch", path, handler, middlewares);
289
+ }
290
+ /**
291
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
292
+ *
293
+ * @param this
294
+ * @param path
295
+ * @param handler
296
+ * @param middlewares
297
+ */
298
+ static options(path, handler, middlewares) {
299
+ this.add("options", path, handler, middlewares);
300
+ }
301
+ /**
302
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
303
+ *
304
+ * @param this
305
+ * @param path
306
+ * @param handler
307
+ * @param middlewares
308
+ */
309
+ static head(path, handler, middlewares) {
310
+ this.add("head", path, handler, middlewares);
311
+ }
312
+ /**
313
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
314
+ * organization and reuse of route configurations.
315
+ *
316
+ * @param this
317
+ * @param prefix
318
+ * @param callback
319
+ * @param middlewares
320
+ */
321
+ static async group(prefix, callback, middlewares) {
322
+ this.ensureState();
323
+ const context = this.groupContext.getStore();
324
+ const previousPrefix = context?.prefix ?? this.prefix;
325
+ const previousMiddlewares = context?.groupMiddlewares ?? this.groupMiddlewares;
326
+ const fullPrefix = [previousPrefix, prefix].filter(Boolean).join("/");
327
+ const nextContext = {
328
+ prefix: this.normalizePath(fullPrefix),
329
+ groupMiddlewares: [...previousMiddlewares, ...middlewares || []]
330
+ };
331
+ await this.groupContext.run(nextContext, async () => {
332
+ await Promise.resolve(callback());
333
+ });
334
+ }
335
+ /**
336
+ * Adds global middlewares to the router, which will be applied to all routes.
337
+ *
338
+ * @param this
339
+ * @param middlewares
340
+ * @param callback
341
+ */
342
+ static middleware(middlewares, callback) {
343
+ this.ensureState();
344
+ const prevMiddlewares = this.globalMiddlewares;
345
+ this.globalMiddlewares = [...prevMiddlewares, ...middlewares || []];
346
+ callback();
347
+ this.globalMiddlewares = prevMiddlewares;
348
+ }
349
+ static allRoutes(type) {
350
+ this.ensureState();
351
+ if (type === "method") return this.routesByMethod;
352
+ if (type === "path") return this.routesByPathMethod;
353
+ return this.routes.filter((e) => e.methods.length > 1 || e.methods[0] !== "options");
354
+ }
355
+ static resolveHandler(route) {
356
+ let handlerFunction;
357
+ let instance = null;
358
+ if (typeof route.handler === "function") handlerFunction = route.handler.bind(route);
359
+ else if (Array.isArray(route.handler) && route.handler.length === 2) {
360
+ const [ControllerType, method] = route.handler;
361
+ if (["function", "object"].includes(typeof ControllerType) && typeof ControllerType[method] === "function") {
362
+ instance = ControllerType;
363
+ handlerFunction = ControllerType[method].bind(ControllerType);
364
+ } else if (typeof ControllerType === "function") {
365
+ instance = new ControllerType();
366
+ if (typeof instance[method] === "function") handlerFunction = instance[method].bind(instance);
367
+ else throw new Error(`Method "${method}" not found in controller instance "${ControllerType.name}"`);
368
+ } else throw new Error(`Invalid controller type for route: ${route.path}`);
369
+ } else throw new Error(`Invalid handler format for route: ${route.path}`);
370
+ return {
371
+ handlerFunction,
372
+ instance
373
+ };
374
+ }
375
+ static bindRequestToInstance(ctx, instance, route, payload) {
376
+ if (!instance) return;
377
+ instance.ctx = ctx;
378
+ instance.body = payload.body;
379
+ instance.query = payload.query;
380
+ instance.params = payload.params;
381
+ instance.clearRequest = new ClearRequest({
382
+ ctx,
383
+ route,
384
+ body: instance.body,
385
+ query: instance.query,
386
+ params: instance.params
387
+ });
388
+ }
389
+ };
390
+
391
+ //#endregion
392
+ export { CoreRouter as t };
@@ -0,0 +1,311 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
3
+ import { NextFunction, Request, Response as Response$1 } from "express";
4
+
5
+ //#region types/h3.d.ts
6
+ type H3App = Omit<H3['fetch'], 'fetch'> & {
7
+ fetch: (request: TypedServerRequest) => Promise<Response>;
8
+ };
9
+ type HttpRequest = H3Event['req'] & {
10
+ getBody: () => Record<string, any>;
11
+ };
12
+ /**
13
+ * HTTP context passed to route handlers
14
+ */
15
+ type HttpContext$1 = Omit<H3Event, 'req'> & {
16
+ req: HttpRequest;
17
+ };
18
+ /**
19
+ * Route handler function type
20
+ */
21
+ type RouteHandler$1 = (
22
+ /**
23
+ * H3 event context
24
+ */
25
+
26
+ ctx: HttpContext$1,
27
+ /**
28
+ * ClearRequest instance
29
+ */
30
+
31
+ req: ClearRequest) => any | Promise<any>;
32
+ /**
33
+ * Handler can be either a function or controller reference
34
+ */
35
+ type Handler$1 = RouteHandler$1 | ControllerHandler;
36
+ //#endregion
37
+ //#region src/Route.d.ts
38
+ declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
39
+ ctx: X;
40
+ body: RequestData;
41
+ query: RequestData;
42
+ params: RequestData;
43
+ clearRequest: ClearRequest;
44
+ methods: HttpMethod[];
45
+ path: string;
46
+ handler: H;
47
+ middlewares: M[];
48
+ controllerName?: string;
49
+ actionName?: string;
50
+ handlerType: 'function' | 'controller';
51
+ middlewareCount: number;
52
+ constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[]);
53
+ }
54
+ //#endregion
55
+ //#region src/ClearRequest.d.ts
56
+ declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
57
+ [key: string]: any;
58
+ /**
59
+ * @param body - Parsed request body
60
+ */
61
+ body: RequestData;
62
+ /**
63
+ * @param query - Parsed query parameters
64
+ */
65
+ query: RequestData;
66
+ /**
67
+ * @param params - Parsed route parameters
68
+ */
69
+ params: RequestData;
70
+ route: Route<X, M>;
71
+ constructor(init?: Partial<ClearRequest>);
72
+ }
73
+ //#endregion
74
+ //#region types/express.d.ts
75
+ interface RequestWithGetBody extends Request {
76
+ getBody: () => Record<string, any>;
77
+ }
78
+ /**
79
+ * HTTP context passed to route handlers
80
+ */
81
+ interface HttpContext {
82
+ req: RequestWithGetBody;
83
+ res: Response$1;
84
+ next: NextFunction;
85
+ }
86
+ /**
87
+ * Route handler function type
88
+ */
89
+ type RouteHandler = (
90
+ /**
91
+ * Express context object containing req, res, and next
92
+ */
93
+
94
+ ctx: HttpContext,
95
+ /**
96
+ * ClearRequest instance
97
+ */
98
+
99
+ req: ClearRequest) => any | Promise<any>;
100
+ /**
101
+ * Handler can be either a function or controller reference
102
+ */
103
+ type Handler = RouteHandler | ControllerHandler;
104
+ /**
105
+ * Middleware function type
106
+ */
107
+ type Middleware = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
108
+ //#endregion
109
+ //#region types/basic.d.ts
110
+ /**
111
+ * Controller method reference
112
+ */
113
+ type ControllerHandler = [any, string];
114
+ /**
115
+ * HTTP methods supported by the router
116
+ */
117
+ type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
118
+ /**
119
+ * Common controller action names
120
+ */
121
+ type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
122
+ /**
123
+ * Generic Object type for request data
124
+ */
125
+ type RequestData = Record<string, any>;
126
+ type ApiResourceMiddleware<M extends Middleware | Middleware$1> = M | M[] | { [K in ControllerAction]?: M | M[] };
127
+ interface RouterConfig {
128
+ /**
129
+ * Configuration for method override functionality, allowing clients to use a
130
+ * specific header or body parameter to override the HTTP method.
131
+ */
132
+ methodOverride?: {
133
+ /** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
134
+ bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
135
+ headerKeys?: string[] | string;
136
+ };
137
+ }
138
+ //#endregion
139
+ //#region src/Controller.d.ts
140
+ declare abstract class Controller<X = any> {
141
+ [x: string]: any;
142
+ ctx: X;
143
+ body: RequestData;
144
+ query: RequestData;
145
+ params: RequestData;
146
+ clearRequest: ClearRequest;
147
+ }
148
+ //#endregion
149
+ //#region src/core/router.d.ts
150
+ /**
151
+ * @class clear-router CoreRouter
152
+ * @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
153
+ * @author 3m1n3nc3
154
+ * @repository https://github.com/toneflix/clear-router
155
+ */
156
+ declare abstract class CoreRouter {
157
+ static config: RouterConfig;
158
+ protected static groupContext: AsyncLocalStorage<{
159
+ prefix: string;
160
+ groupMiddlewares: any[];
161
+ }>;
162
+ static routes: Array<Route<any, any, any>>;
163
+ static routesByPathMethod: Record<string, Route<any, any, any>>;
164
+ static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
165
+ static prefix: string;
166
+ static groupMiddlewares: any[];
167
+ static globalMiddlewares: any[];
168
+ protected static ensureState(this: any): void;
169
+ /**
170
+ * Normalizes a path by ensuring it starts with a single slash and does not have trailing
171
+ * slashes, while preserving dynamic segments and parameters.
172
+ *
173
+ * @param path The path to normalize.
174
+ * @returns The normalized path.
175
+ */
176
+ static normalizePath(path: string): string;
177
+ /**
178
+ * Configures the router with the given options, such as method override settings.
179
+ *
180
+ * @param this
181
+ * @param options
182
+ * @returns
183
+ */
184
+ static configure(this: any, options?: RouterConfig): void;
185
+ protected static resolveMethodOverride(this: any, method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
186
+ /**
187
+ * Adds a new route to the router with the specified methods, path, handler, and middlewares.
188
+ *
189
+ * @param this
190
+ * @param methods
191
+ * @param path
192
+ * @param handler
193
+ * @param middlewares
194
+ */
195
+ static add(this: any, methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): void;
196
+ /**
197
+ * Adds a new API resource route to the router for the specified base path and controller, with
198
+ * options to include/exclude specific actions and apply middlewares.
199
+ *
200
+ * @param this
201
+ * @param basePath
202
+ * @param controller
203
+ * @param options
204
+ */
205
+ static apiResource(this: any, basePath: string, controller: any, options?: {
206
+ only?: ControllerAction[];
207
+ except?: ControllerAction[];
208
+ middlewares?: ApiResourceMiddleware<any>;
209
+ }): void;
210
+ /**
211
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
212
+ *
213
+ * @param this The router instance.
214
+ * @param path The path for the GET route.
215
+ * @param handler The handler function for the GET route.
216
+ * @param middlewares Optional middlewares to apply to the GET route.
217
+ */
218
+ static get(this: any, path: string, handler: any, middlewares?: any[] | any): void;
219
+ /**
220
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
221
+ *
222
+ * @param this
223
+ * @param path
224
+ * @param handler
225
+ * @param middlewares
226
+ */
227
+ static post(this: any, path: string, handler: any, middlewares?: any[] | any): void;
228
+ /**
229
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
230
+ *
231
+ * @param this
232
+ * @param path
233
+ * @param handler
234
+ * @param middlewares
235
+ */
236
+ static put(this: any, path: string, handler: any, middlewares?: any[] | any): void;
237
+ /**
238
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
239
+ *
240
+ * @param this
241
+ * @param path
242
+ * @param handler
243
+ * @param middlewares
244
+ */
245
+ static delete(this: any, path: string, handler: any, middlewares?: any[] | any): void;
246
+ /**
247
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
248
+ *
249
+ * @param this
250
+ * @param path
251
+ * @param handler
252
+ * @param middlewares
253
+ */
254
+ static patch(this: any, path: string, handler: any, middlewares?: any[] | any): void;
255
+ /**
256
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
257
+ *
258
+ * @param this
259
+ * @param path
260
+ * @param handler
261
+ * @param middlewares
262
+ */
263
+ static options(this: any, path: string, handler: any, middlewares?: any[] | any): void;
264
+ /**
265
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
266
+ *
267
+ * @param this
268
+ * @param path
269
+ * @param handler
270
+ * @param middlewares
271
+ */
272
+ static head(this: any, path: string, handler: any, middlewares?: any[] | any): void;
273
+ /**
274
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
275
+ * organization and reuse of route configurations.
276
+ *
277
+ * @param this
278
+ * @param prefix
279
+ * @param callback
280
+ * @param middlewares
281
+ */
282
+ static group(this: any, prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
283
+ /**
284
+ * Adds global middlewares to the router, which will be applied to all routes.
285
+ *
286
+ * @param this
287
+ * @param middlewares
288
+ * @param callback
289
+ */
290
+ static middleware(this: any, middlewares: any[], callback: () => void): void;
291
+ /**
292
+ * Retrieves all registered routes in the router, optionally organized by path or method
293
+ * for easier access and management.
294
+ *
295
+ * @param this
296
+ */
297
+ static allRoutes(this: any): Array<Route<any, any, any>>;
298
+ static allRoutes(this: any, type: 'path'): Record<string, Route<any, any, any>>;
299
+ static allRoutes(this: any, type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
300
+ protected static resolveHandler(route: Route<any, any, any>): {
301
+ handlerFunction: ((ctx: any, req: ClearRequest) => any | Promise<any>) | null;
302
+ instance: Controller<any> | null;
303
+ };
304
+ protected static bindRequestToInstance(ctx: any, instance: Controller<any> | Route<any, any, any> | null, route: Route<any, any, any>, payload: {
305
+ body: Record<string, any>;
306
+ query: Record<string, any>;
307
+ params: Record<string, any>;
308
+ }): void;
309
+ }
310
+ //#endregion
311
+ export { Handler as a, Route as c, HttpContext$1 as d, Middleware$1 as f, HttpMethod as i, H3App as l, ApiResourceMiddleware as n, HttpContext as o, ControllerAction as r, Middleware as s, CoreRouter as t, Handler$1 as u };