clear-router 2.1.12 → 2.3.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.
Files changed (43) hide show
  1. package/README.md +4 -4
  2. package/dist/core/index.cjs +4 -0
  3. package/dist/core/index.d.cts +2 -0
  4. package/dist/core/index.d.mts +2 -0
  5. package/dist/core/index.mjs +3 -0
  6. package/dist/express/index.cjs +86 -247
  7. package/dist/express/index.d.cts +68 -97
  8. package/dist/express/index.d.mts +68 -97
  9. package/dist/express/index.mjs +86 -247
  10. package/dist/fastify/index.cjs +213 -0
  11. package/dist/fastify/index.d.cts +137 -0
  12. package/dist/fastify/index.d.mts +137 -0
  13. package/dist/fastify/index.mjs +212 -0
  14. package/dist/h3/index.cjs +88 -242
  15. package/dist/h3/index.d.cts +72 -93
  16. package/dist/h3/index.d.mts +72 -93
  17. package/dist/h3/index.mjs +88 -242
  18. package/dist/hono/index.cjs +227 -0
  19. package/dist/hono/index.d.cts +141 -0
  20. package/dist/hono/index.d.mts +141 -0
  21. package/dist/hono/index.mjs +226 -0
  22. package/dist/index.cjs +357 -0
  23. package/dist/index.d.cts +195 -40
  24. package/dist/index.d.mts +195 -40
  25. package/dist/index.mjs +358 -1
  26. package/dist/router-Ba2MVNn-.cjs +412 -0
  27. package/dist/router-Bug2IE_u.mjs +407 -0
  28. package/dist/router-DLmimm_U.d.cts +320 -0
  29. package/dist/router-cWYmcfTX.d.mts +320 -0
  30. package/dist/types/ClearRequest.d.mts +1 -1
  31. package/dist/types/Route.d.mts +5 -5
  32. package/dist/types/basic.d.mts +1 -4
  33. package/dist/types/express.d.mts +1 -1
  34. package/dist/types/fastify.d.mts +19 -0
  35. package/dist/types/fastify.mjs +1 -0
  36. package/dist/types/h3.d.mts +1 -1
  37. package/dist/types/hono.d.mts +18 -0
  38. package/dist/types/hono.mjs +1 -0
  39. package/package.json +26 -2
  40. package/dist/Route-BbPXcDGX.mjs +0 -50
  41. package/dist/Route-DhC4kNPX.cjs +0 -62
  42. package/dist/basic-C_1O6RVq.d.cts +0 -138
  43. package/dist/basic-cLeny2Zk.d.mts +0 -138
@@ -0,0 +1,320 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { NextFunction, Request, Response as Response$1 } from "express";
3
+ import { H3, H3Event, Middleware, TypedServerRequest } from "h3";
4
+
5
+ //#region types/basic.d.ts
6
+ /**
7
+ * Controller method reference
8
+ */
9
+ type ControllerHandler = [any, string];
10
+ /**
11
+ * HTTP methods supported by the router
12
+ */
13
+ type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
14
+ /**
15
+ * Common controller action names
16
+ */
17
+ type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
18
+ /**
19
+ * Generic Object type for request data
20
+ */
21
+ type RequestData = Record<string, any>;
22
+ type ApiResourceMiddleware<M = any> = M | M[] | { [K in ControllerAction]?: M | M[] };
23
+ interface RouterConfig {
24
+ /**
25
+ * Configuration for method override functionality, allowing clients to use a
26
+ * specific header or body parameter to override the HTTP method.
27
+ */
28
+ methodOverride?: {
29
+ /** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
30
+ bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
31
+ headerKeys?: string[] | string;
32
+ };
33
+ }
34
+ //#endregion
35
+ //#region types/express.d.ts
36
+ interface RequestWithGetBody extends Request {
37
+ getBody: () => Record<string, any>;
38
+ }
39
+ /**
40
+ * HTTP context passed to route handlers
41
+ */
42
+ interface HttpContext$1 {
43
+ req: RequestWithGetBody;
44
+ res: Response$1;
45
+ next: NextFunction;
46
+ }
47
+ /**
48
+ * Route handler function type
49
+ */
50
+ type RouteHandler$1 = (
51
+ /**
52
+ * Express context object containing req, res, and next
53
+ */
54
+
55
+ ctx: HttpContext$1,
56
+ /**
57
+ * ClearRequest instance
58
+ */
59
+
60
+ req: ClearRequest) => any | Promise<any>;
61
+ /**
62
+ * Handler can be either a function or controller reference
63
+ */
64
+ type Handler$1 = RouteHandler$1 | ControllerHandler;
65
+ /**
66
+ * Middleware function type
67
+ */
68
+ type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
69
+ //#endregion
70
+ //#region types/h3.d.ts
71
+ type H3App = Omit<H3['fetch'], 'fetch'> & {
72
+ fetch: (request: TypedServerRequest) => Promise<Response>;
73
+ };
74
+ type HttpRequest = H3Event['req'] & {
75
+ getBody: () => Record<string, any>;
76
+ };
77
+ /**
78
+ * HTTP context passed to route handlers
79
+ */
80
+ type HttpContext = Omit<H3Event, 'req'> & {
81
+ req: HttpRequest;
82
+ };
83
+ /**
84
+ * Route handler function type
85
+ */
86
+ type RouteHandler = (
87
+ /**
88
+ * H3 event context
89
+ */
90
+
91
+ ctx: HttpContext,
92
+ /**
93
+ * ClearRequest instance
94
+ */
95
+
96
+ req: ClearRequest) => any | Promise<any>;
97
+ /**
98
+ * Handler can be either a function or controller reference
99
+ */
100
+ type Handler = RouteHandler | ControllerHandler;
101
+ //#endregion
102
+ //#region src/Route.d.ts
103
+ declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
104
+ ctx: X;
105
+ body: RequestData;
106
+ query: RequestData;
107
+ params: RequestData;
108
+ clearRequest: ClearRequest;
109
+ methods: HttpMethod[];
110
+ path: string;
111
+ handler: H;
112
+ middlewares: M[];
113
+ controllerName?: string;
114
+ actionName?: string;
115
+ handlerType: 'function' | 'controller';
116
+ middlewareCount: number;
117
+ constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[]);
118
+ }
119
+ //#endregion
120
+ //#region src/ClearRequest.d.ts
121
+ declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
122
+ [key: string]: any;
123
+ /**
124
+ * @param body - Parsed request body
125
+ */
126
+ body: RequestData;
127
+ /**
128
+ * @param query - Parsed query parameters
129
+ */
130
+ query: RequestData;
131
+ /**
132
+ * @param params - Parsed route parameters
133
+ */
134
+ params: RequestData;
135
+ route: Route<X, M>;
136
+ constructor(init?: Partial<ClearRequest>);
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
+ protected static createDefaultOptionsHandler(): any;
158
+ static config: RouterConfig;
159
+ protected static groupContext: AsyncLocalStorage<{
160
+ prefix: string;
161
+ groupMiddlewares: any[];
162
+ }>;
163
+ static routes: Array<Route<any, any, any>>;
164
+ static routesByPathMethod: Record<string, Route<any, any, any>>;
165
+ static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
166
+ static prefix: string;
167
+ static groupMiddlewares: any[];
168
+ static globalMiddlewares: any[];
169
+ protected static ensureState(this: any): void;
170
+ /**
171
+ * Normalizes a path by ensuring it starts with a single slash and does not have trailing
172
+ * slashes, while preserving dynamic segments and parameters.
173
+ *
174
+ * @param path The path to normalize.
175
+ * @returns The normalized path.
176
+ */
177
+ static normalizePath(path: string): string;
178
+ /**
179
+ * Configures the router with the given options, such as method override settings.
180
+ *
181
+ * @param this
182
+ * @param options
183
+ * @returns
184
+ */
185
+ static configure(this: any, options?: RouterConfig): void;
186
+ protected static resolveMethodOverride(this: any, method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
187
+ /**
188
+ * Adds a new route to the router with the specified methods, path, handler, and middlewares.
189
+ *
190
+ * @param this
191
+ * @param methods
192
+ * @param path
193
+ * @param handler
194
+ * @param middlewares
195
+ */
196
+ static add(this: any, methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): void;
197
+ /**
198
+ * Adds a new API resource route to the router for the specified base path and controller, with
199
+ * options to include/exclude specific actions and apply middlewares.
200
+ *
201
+ * @param this
202
+ * @param basePath
203
+ * @param controller
204
+ * @param options
205
+ */
206
+ static apiResource(this: any, basePath: string, controller: any, options?: {
207
+ only?: ControllerAction[];
208
+ except?: ControllerAction[];
209
+ middlewares?: ApiResourceMiddleware<any>;
210
+ }): void;
211
+ /**
212
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
213
+ *
214
+ * @param this The router instance.
215
+ * @param path The path for the GET route.
216
+ * @param handler The handler function for the GET route.
217
+ * @param middlewares Optional middlewares to apply to the GET route.
218
+ */
219
+ static get(this: any, path: string, handler: any, middlewares?: any[] | any): void;
220
+ /**
221
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
222
+ *
223
+ * @param this
224
+ * @param path
225
+ * @param handler
226
+ * @param middlewares
227
+ */
228
+ static post(this: any, path: string, handler: any, middlewares?: any[] | any): void;
229
+ /**
230
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
231
+ *
232
+ * @param this
233
+ * @param path
234
+ * @param handler
235
+ * @param middlewares
236
+ */
237
+ static put(this: any, path: string, handler: any, middlewares?: any[] | any): void;
238
+ /**
239
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
240
+ *
241
+ * @param this
242
+ * @param path
243
+ * @param handler
244
+ * @param middlewares
245
+ */
246
+ static delete(this: any, path: string, handler: any, middlewares?: any[] | any): void;
247
+ /**
248
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
249
+ *
250
+ * @param this
251
+ * @param path
252
+ * @param handler
253
+ * @param middlewares
254
+ */
255
+ static patch(this: any, path: string, handler: any, middlewares?: any[] | any): void;
256
+ /**
257
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
258
+ *
259
+ * @param this
260
+ * @param path
261
+ * @param handler
262
+ * @param middlewares
263
+ */
264
+ static options(this: any, path: string, handler: any, middlewares?: any[] | any): void;
265
+ /**
266
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
267
+ *
268
+ * @param this
269
+ * @param path
270
+ * @param handler
271
+ * @param middlewares
272
+ */
273
+ static head(this: any, path: string, handler: any, middlewares?: any[] | any): void;
274
+ /**
275
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
276
+ * organization and reuse of route configurations.
277
+ *
278
+ * @param this
279
+ * @param prefix
280
+ * @param callback
281
+ * @param middlewares
282
+ */
283
+ static group(this: any, prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
284
+ /**
285
+ * Adds global middlewares to the router, which will be applied to all routes.
286
+ *
287
+ * @param this
288
+ * @param middlewares
289
+ * @param callback
290
+ */
291
+ static middleware(this: any, middlewares: any[], callback: () => void): void;
292
+ /**
293
+ * Retrieves all registered routes in the router, optionally organized by path or method
294
+ * for easier access and management.
295
+ *
296
+ * @param this
297
+ */
298
+ static allRoutes(this: any): Array<Route<any, any, any>>;
299
+ /**
300
+ * @param this
301
+ * @param type - 'path' to get routes organized by path
302
+ */
303
+ static allRoutes(this: any, type: 'path'): Record<string, Route<any, any, any>>;
304
+ /**
305
+ * @param this
306
+ * @param type - 'method' to get routes organized by method
307
+ */
308
+ static allRoutes(this: any, type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
309
+ protected static resolveHandler(route: Route<any, any, any>): {
310
+ handlerFunction: ((ctx: any, req: ClearRequest) => any | Promise<any>) | null;
311
+ instance: Controller<any> | null;
312
+ };
313
+ protected static bindRequestToInstance(ctx: any, instance: Controller<any> | Route<any, any, any> | null, route: Route<any, any, any>, payload: {
314
+ body: Record<string, any>;
315
+ query: Record<string, any>;
316
+ params: Record<string, any>;
317
+ }): void;
318
+ }
319
+ //#endregion
320
+ export { Handler as a, Handler$1 as c, ApiResourceMiddleware as d, ControllerAction as f, H3App as i, HttpContext$1 as l, HttpMethod as m, ClearRequest as n, HttpContext as o, ControllerHandler as p, Route as r, Middleware as s, CoreRouter as t, Middleware$1 as u };
@@ -0,0 +1,320 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { H3, H3Event, Middleware, TypedServerRequest } from "h3";
3
+ import { NextFunction, Request, Response as Response$1 } from "express";
4
+
5
+ //#region types/basic.d.ts
6
+ /**
7
+ * Controller method reference
8
+ */
9
+ type ControllerHandler = [any, string];
10
+ /**
11
+ * HTTP methods supported by the router
12
+ */
13
+ type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
14
+ /**
15
+ * Common controller action names
16
+ */
17
+ type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
18
+ /**
19
+ * Generic Object type for request data
20
+ */
21
+ type RequestData = Record<string, any>;
22
+ type ApiResourceMiddleware<M = any> = M | M[] | { [K in ControllerAction]?: M | M[] };
23
+ interface RouterConfig {
24
+ /**
25
+ * Configuration for method override functionality, allowing clients to use a
26
+ * specific header or body parameter to override the HTTP method.
27
+ */
28
+ methodOverride?: {
29
+ /** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
30
+ bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
31
+ headerKeys?: string[] | string;
32
+ };
33
+ }
34
+ //#endregion
35
+ //#region types/express.d.ts
36
+ interface RequestWithGetBody extends Request {
37
+ getBody: () => Record<string, any>;
38
+ }
39
+ /**
40
+ * HTTP context passed to route handlers
41
+ */
42
+ interface HttpContext$1 {
43
+ req: RequestWithGetBody;
44
+ res: Response$1;
45
+ next: NextFunction;
46
+ }
47
+ /**
48
+ * Route handler function type
49
+ */
50
+ type RouteHandler$1 = (
51
+ /**
52
+ * Express context object containing req, res, and next
53
+ */
54
+
55
+ ctx: HttpContext$1,
56
+ /**
57
+ * ClearRequest instance
58
+ */
59
+
60
+ req: ClearRequest) => any | Promise<any>;
61
+ /**
62
+ * Handler can be either a function or controller reference
63
+ */
64
+ type Handler$1 = RouteHandler$1 | ControllerHandler;
65
+ /**
66
+ * Middleware function type
67
+ */
68
+ type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
69
+ //#endregion
70
+ //#region types/h3.d.ts
71
+ type H3App = Omit<H3['fetch'], 'fetch'> & {
72
+ fetch: (request: TypedServerRequest) => Promise<Response>;
73
+ };
74
+ type HttpRequest = H3Event['req'] & {
75
+ getBody: () => Record<string, any>;
76
+ };
77
+ /**
78
+ * HTTP context passed to route handlers
79
+ */
80
+ type HttpContext = Omit<H3Event, 'req'> & {
81
+ req: HttpRequest;
82
+ };
83
+ /**
84
+ * Route handler function type
85
+ */
86
+ type RouteHandler = (
87
+ /**
88
+ * H3 event context
89
+ */
90
+
91
+ ctx: HttpContext,
92
+ /**
93
+ * ClearRequest instance
94
+ */
95
+
96
+ req: ClearRequest) => any | Promise<any>;
97
+ /**
98
+ * Handler can be either a function or controller reference
99
+ */
100
+ type Handler = RouteHandler | ControllerHandler;
101
+ //#endregion
102
+ //#region src/Route.d.ts
103
+ declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
104
+ ctx: X;
105
+ body: RequestData;
106
+ query: RequestData;
107
+ params: RequestData;
108
+ clearRequest: ClearRequest;
109
+ methods: HttpMethod[];
110
+ path: string;
111
+ handler: H;
112
+ middlewares: M[];
113
+ controllerName?: string;
114
+ actionName?: string;
115
+ handlerType: 'function' | 'controller';
116
+ middlewareCount: number;
117
+ constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[]);
118
+ }
119
+ //#endregion
120
+ //#region src/ClearRequest.d.ts
121
+ declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
122
+ [key: string]: any;
123
+ /**
124
+ * @param body - Parsed request body
125
+ */
126
+ body: RequestData;
127
+ /**
128
+ * @param query - Parsed query parameters
129
+ */
130
+ query: RequestData;
131
+ /**
132
+ * @param params - Parsed route parameters
133
+ */
134
+ params: RequestData;
135
+ route: Route<X, M>;
136
+ constructor(init?: Partial<ClearRequest>);
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
+ protected static createDefaultOptionsHandler(): any;
158
+ static config: RouterConfig;
159
+ protected static groupContext: AsyncLocalStorage<{
160
+ prefix: string;
161
+ groupMiddlewares: any[];
162
+ }>;
163
+ static routes: Array<Route<any, any, any>>;
164
+ static routesByPathMethod: Record<string, Route<any, any, any>>;
165
+ static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
166
+ static prefix: string;
167
+ static groupMiddlewares: any[];
168
+ static globalMiddlewares: any[];
169
+ protected static ensureState(this: any): void;
170
+ /**
171
+ * Normalizes a path by ensuring it starts with a single slash and does not have trailing
172
+ * slashes, while preserving dynamic segments and parameters.
173
+ *
174
+ * @param path The path to normalize.
175
+ * @returns The normalized path.
176
+ */
177
+ static normalizePath(path: string): string;
178
+ /**
179
+ * Configures the router with the given options, such as method override settings.
180
+ *
181
+ * @param this
182
+ * @param options
183
+ * @returns
184
+ */
185
+ static configure(this: any, options?: RouterConfig): void;
186
+ protected static resolveMethodOverride(this: any, method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
187
+ /**
188
+ * Adds a new route to the router with the specified methods, path, handler, and middlewares.
189
+ *
190
+ * @param this
191
+ * @param methods
192
+ * @param path
193
+ * @param handler
194
+ * @param middlewares
195
+ */
196
+ static add(this: any, methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): void;
197
+ /**
198
+ * Adds a new API resource route to the router for the specified base path and controller, with
199
+ * options to include/exclude specific actions and apply middlewares.
200
+ *
201
+ * @param this
202
+ * @param basePath
203
+ * @param controller
204
+ * @param options
205
+ */
206
+ static apiResource(this: any, basePath: string, controller: any, options?: {
207
+ only?: ControllerAction[];
208
+ except?: ControllerAction[];
209
+ middlewares?: ApiResourceMiddleware<any>;
210
+ }): void;
211
+ /**
212
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
213
+ *
214
+ * @param this The router instance.
215
+ * @param path The path for the GET route.
216
+ * @param handler The handler function for the GET route.
217
+ * @param middlewares Optional middlewares to apply to the GET route.
218
+ */
219
+ static get(this: any, path: string, handler: any, middlewares?: any[] | any): void;
220
+ /**
221
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
222
+ *
223
+ * @param this
224
+ * @param path
225
+ * @param handler
226
+ * @param middlewares
227
+ */
228
+ static post(this: any, path: string, handler: any, middlewares?: any[] | any): void;
229
+ /**
230
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
231
+ *
232
+ * @param this
233
+ * @param path
234
+ * @param handler
235
+ * @param middlewares
236
+ */
237
+ static put(this: any, path: string, handler: any, middlewares?: any[] | any): void;
238
+ /**
239
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
240
+ *
241
+ * @param this
242
+ * @param path
243
+ * @param handler
244
+ * @param middlewares
245
+ */
246
+ static delete(this: any, path: string, handler: any, middlewares?: any[] | any): void;
247
+ /**
248
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
249
+ *
250
+ * @param this
251
+ * @param path
252
+ * @param handler
253
+ * @param middlewares
254
+ */
255
+ static patch(this: any, path: string, handler: any, middlewares?: any[] | any): void;
256
+ /**
257
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
258
+ *
259
+ * @param this
260
+ * @param path
261
+ * @param handler
262
+ * @param middlewares
263
+ */
264
+ static options(this: any, path: string, handler: any, middlewares?: any[] | any): void;
265
+ /**
266
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
267
+ *
268
+ * @param this
269
+ * @param path
270
+ * @param handler
271
+ * @param middlewares
272
+ */
273
+ static head(this: any, path: string, handler: any, middlewares?: any[] | any): void;
274
+ /**
275
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
276
+ * organization and reuse of route configurations.
277
+ *
278
+ * @param this
279
+ * @param prefix
280
+ * @param callback
281
+ * @param middlewares
282
+ */
283
+ static group(this: any, prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
284
+ /**
285
+ * Adds global middlewares to the router, which will be applied to all routes.
286
+ *
287
+ * @param this
288
+ * @param middlewares
289
+ * @param callback
290
+ */
291
+ static middleware(this: any, middlewares: any[], callback: () => void): void;
292
+ /**
293
+ * Retrieves all registered routes in the router, optionally organized by path or method
294
+ * for easier access and management.
295
+ *
296
+ * @param this
297
+ */
298
+ static allRoutes(this: any): Array<Route<any, any, any>>;
299
+ /**
300
+ * @param this
301
+ * @param type - 'path' to get routes organized by path
302
+ */
303
+ static allRoutes(this: any, type: 'path'): Record<string, Route<any, any, any>>;
304
+ /**
305
+ * @param this
306
+ * @param type - 'method' to get routes organized by method
307
+ */
308
+ static allRoutes(this: any, type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
309
+ protected static resolveHandler(route: Route<any, any, any>): {
310
+ handlerFunction: ((ctx: any, req: ClearRequest) => any | Promise<any>) | null;
311
+ instance: Controller<any> | null;
312
+ };
313
+ protected static bindRequestToInstance(ctx: any, instance: Controller<any> | Route<any, any, any> | null, route: Route<any, any, any>, payload: {
314
+ body: Record<string, any>;
315
+ query: Record<string, any>;
316
+ params: Record<string, any>;
317
+ }): void;
318
+ }
319
+ //#endregion
320
+ export { Handler as a, Handler$1 as c, ApiResourceMiddleware as d, ControllerAction as f, H3App as i, HttpContext$1 as l, HttpMethod as m, ClearRequest as n, HttpContext as o, ControllerHandler as p, Route as r, Middleware as s, CoreRouter as t, Middleware$1 as u };
@@ -1,7 +1,7 @@
1
+ import { RequestData } from "../types/basic.mjs";
1
2
  import { Middleware } from "../types/h3.mjs";
2
3
  import { Route } from "./Route.mjs";
3
4
  import { Middleware as Middleware$1 } from "../types/express.mjs";
4
- import { RequestData } from "../types/basic.mjs";
5
5
 
6
6
  //#region src/ClearRequest.d.ts
7
7
  declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
@@ -1,10 +1,10 @@
1
- import { Handler, Middleware } from "../types/h3.mjs";
1
+ import { HttpMethod, RequestData } from "../types/basic.mjs";
2
+ import { Middleware } from "../types/h3.mjs";
2
3
  import { ClearRequest } from "./ClearRequest.mjs";
3
4
  import { Middleware as Middleware$1 } from "../types/express.mjs";
4
- import { HttpMethod, RequestData } from "../types/basic.mjs";
5
5
 
6
6
  //#region src/Route.d.ts
7
- declare class Route<X = any, M = Middleware | Middleware$1> {
7
+ declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
8
8
  ctx: X;
9
9
  body: RequestData;
10
10
  query: RequestData;
@@ -12,13 +12,13 @@ declare class Route<X = any, M = Middleware | Middleware$1> {
12
12
  clearRequest: ClearRequest;
13
13
  methods: HttpMethod[];
14
14
  path: string;
15
- handler: Handler;
15
+ handler: H;
16
16
  middlewares: M[];
17
17
  controllerName?: string;
18
18
  actionName?: string;
19
19
  handlerType: 'function' | 'controller';
20
20
  middlewareCount: number;
21
- constructor(methods: HttpMethod[], path: string, handler: Handler, middlewares?: M[]);
21
+ constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[]);
22
22
  }
23
23
  //#endregion
24
24
  export { Route };
@@ -1,6 +1,3 @@
1
- import { Middleware } from "./h3.mjs";
2
- import { Middleware as Middleware$1 } from "./express.mjs";
3
-
4
1
  //#region types/basic.d.ts
5
2
  /**
6
3
  * Controller method reference
@@ -18,7 +15,7 @@ type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
18
15
  * Generic Object type for request data
19
16
  */
20
17
  type RequestData = Record<string, any>;
21
- type ApiResourceMiddleware<M extends Middleware$1 | Middleware> = M | M[] | { [K in ControllerAction]?: M | M[] };
18
+ type ApiResourceMiddleware<M = any> = M | M[] | { [K in ControllerAction]?: M | M[] };
22
19
  interface RouterConfig {
23
20
  /**
24
21
  * Configuration for method override functionality, allowing clients to use a
@@ -1,5 +1,5 @@
1
- import { ClearRequest } from "./ClearRequest.mjs";
2
1
  import { ControllerHandler } from "./basic.mjs";
2
+ import { ClearRequest } from "./ClearRequest.mjs";
3
3
  import { NextFunction, Request, Response } from "express";
4
4
 
5
5
  //#region types/express.d.ts