clear-router 2.7.5 → 2.7.7

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 (107) hide show
  1. package/dist/ClearRequest.cjs +23 -0
  2. package/dist/ClearRequest.d.cts +28 -0
  3. package/dist/ClearRequest.d.mts +28 -0
  4. package/dist/ClearRequest.mjs +22 -0
  5. package/dist/Contracts.d.cts +12 -0
  6. package/dist/Contracts.d.mts +12 -0
  7. package/dist/Controller.cjs +12 -0
  8. package/dist/Controller.d.cts +14 -0
  9. package/dist/Controller.d.mts +14 -0
  10. package/dist/Controller.mjs +11 -0
  11. package/dist/{Request-DKXwa_W0.d.mts → Request-BhTJDR_5.d.mts} +5 -5
  12. package/dist/Route.cjs +58 -0
  13. package/dist/Route.d.cts +35 -0
  14. package/dist/Route.d.mts +35 -0
  15. package/dist/Route.mjs +57 -0
  16. package/dist/core/Request.cjs +35 -0
  17. package/dist/core/Request.d.cts +25 -0
  18. package/dist/core/Request.d.mts +25 -0
  19. package/dist/core/Request.mjs +35 -0
  20. package/dist/core/Response.cjs +59 -0
  21. package/dist/core/Response.d.cts +24 -0
  22. package/dist/core/Response.d.mts +24 -0
  23. package/dist/core/Response.mjs +58 -0
  24. package/dist/{bindings-CLsZjOEy.cjs → core/bindings.cjs} +10 -160
  25. package/dist/{bindings-CNL7bpz5.d.mts → core/bindings.d.cts} +1 -1
  26. package/dist/{bindings-CxvtC8XS.d.cts → core/bindings.d.mts} +1 -1
  27. package/dist/{bindings-XLDXFpHZ.mjs → core/bindings.mjs} +3 -110
  28. package/dist/core/index.cjs +4 -20
  29. package/dist/core/index.d.cts +4 -1
  30. package/dist/core/index.d.mts +4 -1
  31. package/dist/core/index.mjs +4 -14
  32. package/dist/core/plugins.cjs +14 -0
  33. package/dist/core/plugins.d.cts +109 -0
  34. package/dist/core/plugins.d.mts +109 -0
  35. package/dist/core/plugins.mjs +13 -0
  36. package/dist/{responses-Bvnk0uvc.cjs → core/responses.cjs} +5 -20
  37. package/dist/{responses-BvETUeDL.mjs → core/responses.mjs} +2 -2
  38. package/dist/{router-C6W-k6sS.cjs → core/router.cjs} +11 -69
  39. package/dist/core/router.d.cts +274 -0
  40. package/dist/core/router.d.mts +274 -0
  41. package/dist/{router-Dc9w86Wn.mjs → core/router.mjs} +5 -58
  42. package/dist/decorators/index.cjs +1 -1
  43. package/dist/decorators/index.d.cts +1 -1
  44. package/dist/decorators/index.d.mts +1 -1
  45. package/dist/decorators/index.mjs +1 -1
  46. package/dist/decorators/setup.cjs +2 -2
  47. package/dist/decorators/setup.d.cts +1 -1
  48. package/dist/decorators/setup.d.mts +1 -1
  49. package/dist/decorators/setup.mjs +2 -2
  50. package/dist/express/index.cjs +2 -265
  51. package/dist/express/index.d.cts +1 -127
  52. package/dist/express/index.d.mts +1 -127
  53. package/dist/express/index.mjs +1 -264
  54. package/dist/express/router.cjs +265 -0
  55. package/dist/express/router.d.cts +131 -0
  56. package/dist/express/router.d.mts +131 -0
  57. package/dist/express/router.mjs +265 -0
  58. package/dist/fastify/index.cjs +2 -254
  59. package/dist/fastify/index.d.cts +1 -125
  60. package/dist/fastify/index.d.mts +1 -125
  61. package/dist/fastify/index.mjs +1 -253
  62. package/dist/fastify/router.cjs +254 -0
  63. package/dist/fastify/router.d.cts +129 -0
  64. package/dist/fastify/router.d.mts +129 -0
  65. package/dist/fastify/router.mjs +254 -0
  66. package/dist/h3/index.cjs +2 -260
  67. package/dist/h3/index.d.cts +1 -128
  68. package/dist/h3/index.d.mts +1 -128
  69. package/dist/h3/index.mjs +1 -259
  70. package/dist/h3/router.cjs +260 -0
  71. package/dist/h3/router.d.cts +132 -0
  72. package/dist/h3/router.d.mts +132 -0
  73. package/dist/h3/router.mjs +260 -0
  74. package/dist/hono/index.cjs +2 -251
  75. package/dist/hono/index.d.cts +1 -130
  76. package/dist/hono/index.d.mts +1 -130
  77. package/dist/hono/index.mjs +1 -250
  78. package/dist/hono/router.cjs +251 -0
  79. package/dist/hono/router.d.cts +134 -0
  80. package/dist/hono/router.d.mts +134 -0
  81. package/dist/hono/router.mjs +251 -0
  82. package/dist/index.cjs +16 -1097
  83. package/dist/index.d.cts +9 -563
  84. package/dist/index.d.mts +9 -563
  85. package/dist/index.mjs +8 -1089
  86. package/dist/koa/index.cjs +2 -261
  87. package/dist/koa/index.d.cts +1 -131
  88. package/dist/koa/index.d.mts +1 -131
  89. package/dist/koa/index.mjs +1 -260
  90. package/dist/koa/router.cjs +261 -0
  91. package/dist/koa/router.d.cts +135 -0
  92. package/dist/koa/router.d.mts +135 -0
  93. package/dist/koa/router.mjs +261 -0
  94. package/dist/types/basic.d.cts +43 -0
  95. package/dist/types/express.d.cts +44 -0
  96. package/dist/types/express.d.mts +4 -2
  97. package/dist/types/fastify.d.cts +23 -0
  98. package/dist/types/fastify.d.mts +4 -2
  99. package/dist/types/h3.d.cts +41 -0
  100. package/dist/types/h3.d.mts +5 -6
  101. package/dist/types/hono.d.cts +21 -0
  102. package/dist/types/hono.d.mts +5 -5
  103. package/dist/types/koa.d.cts +25 -0
  104. package/dist/types/koa.d.mts +5 -5
  105. package/package.json +1 -1
  106. package/dist/router-CYBshGMl.d.mts +0 -652
  107. package/dist/router-tpnSi_Y7.d.cts +0 -652
@@ -1,652 +0,0 @@
1
- import { a as BindValue, i as BindToken, o as Container } from "./bindings-CxvtC8XS.cjs";
2
- import { NextFunction, Request, Response as Response$1 } from "express";
3
- import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
4
- import { EventHandlerRequest, H3, H3Event, Middleware as Middleware$2, TypedServerRequest } from "h3";
5
- import { Context, HonoRequest, MiddlewareHandler } from "hono";
6
- import Koa from "koa";
7
- import Router$1 from "@koa/router";
8
- import { AsyncLocalStorage } from "node:async_hooks";
9
-
10
- //#region src/types/basic.d.ts
11
- /**
12
- * Controller method reference
13
- */
14
- type ControllerHandler = [any, string];
15
- /**
16
- * HTTP methods supported by the router
17
- */
18
- type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
19
- /**
20
- * Common controller action names
21
- */
22
- type ControllerAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
23
- /**
24
- * Generic Object type for request data
25
- */
26
- type RequestData = Record<string, any>;
27
- type ApiResourceMiddleware<M = any> = M | M[] | { [K in ControllerAction]?: M | M[] };
28
- interface RouterConfig {
29
- /**
30
- * When enabled, API param name will be infered from the route path.
31
- * So instead of getting /api/users/:id, we will now get /api/users/:user
32
- */
33
- inferParamName?: boolean;
34
- /**
35
- * Configuration for method override functionality, allowing clients to use a
36
- * specific header or body parameter to override the HTTP method.
37
- */
38
- methodOverride?: {
39
- /** Whether method override is enabled */enabled?: boolean; /** Keys in the request body to check for method override */
40
- bodyKeys?: string[] | string; /** Keys in the request headers to check for method override */
41
- headerKeys?: string[] | string;
42
- };
43
- /**
44
- * Optional method binding / container resolution support. Disabled by default.
45
- */
46
- container?: {
47
- /** Whether decorated handler parameter binding is enabled */enabled?: boolean; /** Whether unknown constructor tokens should be instantiated automatically */
48
- autoDiscover?: boolean;
49
- };
50
- }
51
- //#endregion
52
- //#region src/Contracts.d.ts
53
- /**
54
- * HTTP context passed to route handlers
55
- */
56
- interface ClearHttpContext {}
57
- //#endregion
58
- //#region src/core/Response.d.ts
59
- declare class Response$2 {
60
- [key: string]: any;
61
- body: any;
62
- headers: Headers;
63
- sent: boolean;
64
- statusCode: number;
65
- statusText: string;
66
- constructor(init?: Partial<Response$2 | globalThis.Response>);
67
- status(code: number): this;
68
- setStatusText(text: string): this;
69
- code(code: number): this;
70
- setHeader(name: string, value: string): this;
71
- header(name: string, value: string): this;
72
- set(name: string, value: string): this;
73
- type(contentType: string): this;
74
- send(body?: any): this;
75
- json(body: any): this;
76
- html(body: string): this;
77
- text(body: string): this;
78
- noContent(): this;
79
- }
80
- //#endregion
81
- //#region src/types/express.d.ts
82
- interface RequestWithGetBody$3 extends Request {
83
- getBody: () => Record<string, any>;
84
- }
85
- /**
86
- * HTTP context passed to route handlers
87
- */
88
- interface HttpContext$4 extends ClearHttpContext {
89
- req: RequestWithGetBody$3;
90
- res: Response$1;
91
- next: NextFunction;
92
- clearRequest: Request$1;
93
- clearResponse: Response$2;
94
- }
95
- /**
96
- * Route handler function type
97
- */
98
- type RouteHandler$4 = (
99
- /**
100
- * Express context object containing req, res, and next
101
- */
102
-
103
- ctx: HttpContext$4,
104
- /**
105
- * ClearRequest instance
106
- */
107
-
108
- req: Request$1) => any | Promise<any>;
109
- /**
110
- * Handler can be either a function or controller reference
111
- */
112
- type Handler$4 = RouteHandler$4 | ControllerHandler;
113
- /**
114
- * Middleware function type
115
- */
116
- type Middleware$4 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
117
- //#endregion
118
- //#region src/types/fastify.d.ts
119
- interface RequestWithGetBody$2 extends FastifyRequest {
120
- getBody: () => Record<string, any>;
121
- }
122
- interface HttpContext$3 extends ClearHttpContext {
123
- req: RequestWithGetBody$2;
124
- reply: FastifyReply;
125
- clearRequest: Request$1;
126
- clearResponse: Response$2;
127
- }
128
- type RouteHandler$3 = (ctx: HttpContext$3, req: Request$1) => any | Promise<any>;
129
- type Handler$3 = RouteHandler$3 | ControllerHandler;
130
- type NextFunction$1 = (err?: Error) => void;
131
- type Middleware$3 = (req: RequestWithGetBody$2, reply: FastifyReply, next: NextFunction$1) => any | Promise<any>;
132
- type FastifyApp = FastifyInstance;
133
- //#endregion
134
- //#region src/types/h3.d.ts
135
- type H3App = Omit<H3, 'fetch'> & {
136
- fetch: (request: TypedServerRequest<EventHandlerRequest>) => Promise<Response>;
137
- };
138
- interface HttpRequest extends TypedServerRequest<EventHandlerRequest> {
139
- getBody: () => Record<string, any>;
140
- }
141
- type MergedHttpContext$2 = Omit<H3Event, 'req'> & ClearHttpContext;
142
- /**
143
- * HTTP context passed to route handlers
144
- */
145
- interface HttpContext$2 extends MergedHttpContext$2 {
146
- req: HttpRequest;
147
- clearRequest: Request$1;
148
- clearResponse: Response$2;
149
- }
150
- /**
151
- * Route handler function type
152
- */
153
- type RouteHandler$2 = (
154
- /**
155
- * H3 event context
156
- */
157
-
158
- ctx: HttpContext$2,
159
- /**
160
- * ClearRequest instance
161
- */
162
-
163
- req: Request$1) => any | Promise<any>;
164
- /**
165
- * Handler can be either a function or controller reference
166
- */
167
- type Handler$2 = RouteHandler$2 | ControllerHandler;
168
- //#endregion
169
- //#region src/types/hono.d.ts
170
- type RequestWithGetBody$1 = HonoRequest & {
171
- getBody: () => Record<string, any>;
172
- };
173
- type MergedHttpContext$1 = ClearHttpContext & Context;
174
- interface HttpContext$1 extends MergedHttpContext$1 {
175
- req: RequestWithGetBody$1;
176
- clearRequest: Request$1;
177
- clearResponse: Response$2;
178
- }
179
- type RouteHandler$1 = (ctx: HttpContext$1, req: Request$1) => any | Promise<any>;
180
- type Handler$1 = RouteHandler$1 | ControllerHandler;
181
- type Middleware$1 = MiddlewareHandler;
182
- type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: Middleware$1[]) => any };
183
- //#endregion
184
- //#region src/types/koa.d.ts
185
- interface RequestWithGetBody extends Koa.Request {
186
- getBody: () => Record<string, any>;
187
- body?: any;
188
- }
189
- type MergedHttpContext = ClearHttpContext & Koa.Context;
190
- interface HttpContext extends MergedHttpContext {
191
- request: RequestWithGetBody;
192
- clearRequest: Request$1;
193
- clearResponse: Response$2;
194
- params: Record<string, any>;
195
- query: Record<string, any>;
196
- }
197
- type RouteHandler = (ctx: HttpContext, req: Request$1) => any | Promise<any>;
198
- type Handler = RouteHandler | ControllerHandler;
199
- type Middleware = Koa.Middleware<any, any>;
200
- type KoaRouterApp = Router$1<any, any>;
201
- //#endregion
202
- //#region src/Route.d.ts
203
- interface RouteParameter {
204
- name: string;
205
- field?: string;
206
- optional: boolean;
207
- }
208
- declare class Route<X = any, M = Middleware$2 | Middleware$4, H = any> {
209
- ctx: X;
210
- body: RequestData;
211
- query: RequestData;
212
- params: RequestData;
213
- clearRequest: ClearRequest;
214
- methods: HttpMethod[];
215
- path: string;
216
- registrationPaths: string[];
217
- parameters: RouteParameter[];
218
- routeName?: string;
219
- handler: H;
220
- middlewares: M[];
221
- controllerName?: string;
222
- actionName?: string;
223
- handlerType: 'function' | 'controller';
224
- middlewareCount: number;
225
- constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[], options?: {
226
- registrationPaths?: string[];
227
- parameters?: RouteParameter[];
228
- onName?: (name: string, route: Route<X, M, H>, previousName?: string) => void;
229
- });
230
- private onName?;
231
- name(name: string): this;
232
- toPath(params?: RequestData): string;
233
- }
234
- //#endregion
235
- //#region src/ClearRequest.d.ts
236
- declare class ClearRequest<X = any, M = Middleware$2 | Middleware$4 | Middleware$3 | Middleware$1 | Middleware> {
237
- [key: string]: any;
238
- /**
239
- * @param body - Parsed request body
240
- */
241
- body: RequestData;
242
- /**
243
- * @param query - Parsed query parameters
244
- */
245
- query: RequestData;
246
- /**
247
- * @param params - Parsed route parameters
248
- */
249
- params: RequestData;
250
- route: Route<X, M>;
251
- constructor(init?: Partial<ClearRequest>);
252
- }
253
- //#endregion
254
- //#region src/core/Request.d.ts
255
- declare class Request$1<X = any, M = any> extends ClearRequest<X, M> {
256
- original?: any;
257
- method: string;
258
- path: string;
259
- url: string;
260
- headers: Headers | Record<string, any>;
261
- constructor(init?: Partial<Request$1<X, M>> & {
262
- body?: RequestData;
263
- query?: RequestData;
264
- params?: RequestData;
265
- route?: Route<X, M>;
266
- });
267
- getBody(): RequestData;
268
- header(name: string): string;
269
- param(name: string): any;
270
- input(name: string): any;
271
- is(method: HttpMethod | string): boolean;
272
- }
273
- //#endregion
274
- //#region src/core/plugins.d.ts
275
- type PluginSetupResult = void | Promise<void>;
276
- interface ClearRouterPluginRequestContext<HttpContext = any> {
277
- ctx: HttpContext;
278
- request: Request$1;
279
- response: Response$2;
280
- getBindings: () => Record<string, BindValue>;
281
- [key: string]: any;
282
- }
283
- interface ClearRouterPluginArgumentsContext<X = any> extends ClearRouterPluginRequestContext<X> {
284
- target?: object;
285
- method?: PropertyKey;
286
- handler?: object;
287
- metadata?: object;
288
- tokens: BindToken[];
289
- designTokens: BindToken[];
290
- }
291
- type PluginBindFactory<T = any, X = any> = (ctx: ClearRouterPluginRequestContext<X>) => T | Promise<T>;
292
- type PluginBindValue<T = any, X = any> = BindValue<T> | PluginBindFactory<T, X>;
293
- type PluginBind<X = any> = <T>(token: BindToken<T>, value: PluginBindValue<T, X>) => void;
294
- type PluginArgumentsResolver<HttpContext = any> = (ctx: ClearRouterPluginArgumentsContext<HttpContext>) => any[] | undefined | Promise<any[] | undefined>;
295
- interface ClearRouterPluginContext<Options = any, HttpContext = any> {
296
- /**
297
- * The service container
298
- */
299
- container: typeof Container;
300
- /**
301
- * Register service container bindings
302
- */
303
- bind: PluginBind<HttpContext>;
304
- /**
305
- * Replace all controller method arguments
306
- * @param resolver
307
- * @returns
308
- */
309
- resolveArguments: (resolver: PluginArgumentsResolver<HttpContext>) => void;
310
- /**
311
- * Use the current http context
312
- */
313
- useHttpContext: (resolver: PluginArgumentsResolver<HttpContext>) => void;
314
- /**
315
- * All registered service container bindings
316
- */
317
- bindings: Record<string, BindValue>;
318
- /**
319
- * Configures the router with the given options, such as method override settings
320
- *
321
- * @param options
322
- * @returns
323
- */
324
- configure: (options: RouterConfig) => void;
325
- /**
326
- * Default configuration used for everytime the router is reset
327
- *
328
- * @param options
329
- */
330
- configureDefaults: (options: RouterConfig) => void;
331
- /**
332
- * The current Request instance
333
- */
334
- readonly request?: Request$1;
335
- /**
336
- * The current Response instance
337
- * @returns
338
- */
339
- readonly response?: Response$2;
340
- /**
341
- * Get the current Request instance
342
- * @returns
343
- */
344
- getRequest: () => Request$1 | undefined;
345
- /**
346
- * Get the current Response instance
347
- * @returns
348
- */
349
- getResponse: () => Response$2 | undefined;
350
- /**
351
- * Plugin configuration options
352
- */
353
- options: Options;
354
- }
355
- interface ClearRouterPlugin<Options = any, HttpContext = any> {
356
- /**
357
- * The name of the plugin
358
- */
359
- name?: string;
360
- /**
361
- * Plugin setup an implemnetation
362
- *
363
- * @param ctx
364
- * @returns
365
- */
366
- setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
367
- }
368
- type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
369
- /**
370
- * Creates a new plugin
371
- *
372
- * @param plugin
373
- * @returns
374
- */
375
- declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
376
- //#endregion
377
- //#region src/Controller.d.ts
378
- declare abstract class Controller<X = any> {
379
- [x: string]: any;
380
- ctx: X;
381
- body: RequestData;
382
- query: RequestData;
383
- params: RequestData;
384
- clearRequest: ClearRequest;
385
- }
386
- //#endregion
387
- //#region src/core/router.d.ts
388
- /**
389
- * @class clear-router CoreRouter
390
- * @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
391
- * @author 3m1n3nc3
392
- * @repository https://github.com/arkstack-tmp/clear-router
393
- */
394
- declare abstract class CoreRouter {
395
- protected static routerStateNamespace: string;
396
- private static readonly stateStoreKey;
397
- private static readonly stateBoundKey;
398
- private static readonly defaultConfigKey;
399
- private static readonly pluginStoreKey;
400
- private static readonly pluginPendingKey;
401
- private static readonly pluginHttpCtxResolversKey;
402
- private static readonly pluginArgumentResolversKey;
403
- private static requestProvider?;
404
- private static responseProvider?;
405
- static config: RouterConfig;
406
- protected static groupContext: AsyncLocalStorage<{
407
- prefix: string;
408
- groupMiddlewares: any[];
409
- }>;
410
- protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext<any>>;
411
- static routes: Set<Route<any, any, any>>;
412
- static routesByPathMethod: Map<string, Route<any, any, any>>;
413
- static routesByMethod: Map<"GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD", Route<any, any, any>[]>;
414
- static routesByName: Map<string, Route<any, any, any>>;
415
- static prefix: string;
416
- static groupMiddlewares: any[];
417
- static globalMiddlewares: any[];
418
- /**
419
- * Resets the router to it's default state
420
- */
421
- static reset(): typeof CoreRouter;
422
- protected static createBaseConfig(): RouterConfig;
423
- protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
424
- protected static getDefaultConfig(): RouterConfig;
425
- protected static resolveStateNamespace(): string;
426
- protected static getStateStore(): Record<string, any>;
427
- protected static getPluginStore(): Set<string>;
428
- protected static getPluginPendingStore(): Set<Promise<void>>;
429
- protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
430
- protected static getPluginHttpCtxResolvers(): Set<PluginArgumentsResolver>;
431
- protected static createDefaultState(): {
432
- config: RouterConfig;
433
- groupContext: AsyncLocalStorage<{
434
- prefix: string;
435
- groupMiddlewares: any[];
436
- }>;
437
- routes: Set<never>;
438
- routesByPathMethod: Map<any, any>;
439
- routesByMethod: Map<any, any>;
440
- routesByName: Map<any, any>;
441
- prefix: string;
442
- groupMiddlewares: any[];
443
- globalMiddlewares: any[];
444
- };
445
- protected static bindStateAccessors(): void;
446
- protected static createDefaultOptionsHandler(): any;
447
- /**
448
- * Default configuration used for everytime the router is reset
449
- *
450
- * @param options
451
- */
452
- static configureDefaults(options?: RouterConfig): void;
453
- /**
454
- * Use a registered plugin
455
- *
456
- * @param this
457
- * @param plugin
458
- * @param options
459
- * @returns
460
- */
461
- static use<Options = any>(plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
462
- protected static pluginsReady(): Promise<void>;
463
- protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
464
- protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
465
- protected static createPluginBind(): PluginBind;
466
- protected static resolvePluginArguments(ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
467
- protected static resolvePluginHttpCtx(ctx: any): Promise<void>;
468
- protected static ensureState(): void;
469
- /**
470
- * Normalizes a path by ensuring it starts with a single slash and does not have trailing
471
- * slashes, while preserving dynamic segments and parameters.
472
- *
473
- * @param path The path to normalize.
474
- * @returns The normalized path.
475
- */
476
- static normalizePath(path: string): string;
477
- protected static parseRouteParameters(path: string): Array<{
478
- name: string;
479
- field?: string;
480
- optional: boolean;
481
- }>;
482
- protected static expandRoutePath(path: string): string[];
483
- protected static routeRegistrationPaths(path: string): string[];
484
- /**
485
- * Configures the router with the given options, such as method override settings.
486
- *
487
- * @param this
488
- * @param options
489
- * @returns
490
- */
491
- static configure(this: any, options?: RouterConfig): void;
492
- protected static resolveMethodOverride(method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
493
- /**
494
- * Adds a new route to the router.
495
- *
496
- * @param this
497
- * @param methods
498
- * @param path
499
- * @param handler
500
- * @param middlewares
501
- */
502
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
503
- /**
504
- * Define a resourceful API controller with standard CRUD routes.
505
- *
506
- * @param this
507
- * @param basePath
508
- * @param controller
509
- * @param options
510
- */
511
- static apiResource(basePath: string, controller: any, options?: {
512
- only?: ControllerAction[];
513
- except?: ControllerAction[];
514
- middlewares?: ApiResourceMiddleware<any>;
515
- }): void;
516
- /**
517
- * Adds a new GET route to the router.
518
- *
519
- * @param this The router instance.
520
- * @param path The path for the GET route.
521
- * @param handler The handler function for the GET route.
522
- * @param middlewares Optional middlewares to apply to the GET route.
523
- */
524
- static get(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
525
- /**
526
- * Adds a new POST route to the router.
527
- *
528
- * @param this
529
- * @param path
530
- * @param handler
531
- * @param middlewares
532
- */
533
- static post(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
534
- /**
535
- * Adds a new PUT route to the router.
536
- *
537
- * @param this
538
- * @param path
539
- * @param handler
540
- * @param middlewares
541
- */
542
- static put(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
543
- /**
544
- * Adds a new DELETE route to the router.
545
- *
546
- * @param this
547
- * @param path
548
- * @param handler
549
- * @param middlewares
550
- */
551
- static delete(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
552
- /**
553
- * Adds a new PATCH route to the router.
554
- *
555
- * @param this
556
- * @param path
557
- * @param handler
558
- * @param middlewares
559
- */
560
- static patch(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
561
- /**
562
- * Adds a new OPTIONS route to the router.
563
- *
564
- * @param this
565
- * @param path
566
- * @param handler
567
- * @param middlewares
568
- */
569
- static options(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
570
- /**
571
- * Adds a new HEAD route to the router.
572
- *
573
- * @param this
574
- * @param path
575
- * @param handler
576
- * @param middlewares
577
- */
578
- static head(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
579
- /**
580
- * Defines a group of routes with a common prefix.
581
- *
582
- * @param this
583
- * @param prefix
584
- * @param callback
585
- * @param middlewares
586
- */
587
- static group(prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
588
- /**
589
- * Adds global middlewares to the router, which will be applied to all routes.
590
- *
591
- * @param this
592
- * @param middlewares
593
- * @param callback
594
- */
595
- static middleware(middlewares: any[], callback: () => void): void;
596
- /**
597
- * Retrieves all registered routes in the router, optionally organized by path or method
598
- * for easier access and management.
599
- *
600
- * @param this
601
- */
602
- static allRoutes(): Array<Route<any, any, any>>;
603
- /**
604
- * @param this
605
- * @param type - 'path' to get routes organized by path
606
- */
607
- static allRoutes(type: 'path'): Record<string, Route<any, any, any>>;
608
- /**
609
- * @param this
610
- * @param type - 'method' to get routes organized by method
611
- */
612
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
613
- static allRoutes(type: 'name'): Record<string, Route<any, any, any>>;
614
- static route(name: string): Route<any, any, any> | undefined;
615
- static url(name: string, params?: Record<string, any>): string | undefined;
616
- /**
617
- * Provide a class that will overide the base Request instance
618
- *
619
- * @param provider
620
- */
621
- static setRequestProvider(provider: typeof Request$1): void;
622
- /**
623
- * Provide a class that will overide the base Response instance
624
- *
625
- * @param provider
626
- */
627
- static setResponseProvider(provider: typeof Response$2): void;
628
- private static hasPackageInstalled;
629
- /**
630
- * Provide a class that will overide the base Response instance
631
- *
632
- * @param provider
633
- */
634
- private static initializeInstance;
635
- protected static resolveHandler(route: Route<any, any, any>): {
636
- handlerFunction: ((ctx: any, req: Request$1) => any | Promise<any>) | null;
637
- instance: Controller<any> | null;
638
- bindingTarget?: object;
639
- bindingMethod?: PropertyKey;
640
- bindingHandler?: object;
641
- bindingMetadata?: object;
642
- };
643
- protected static callHandler(handlerFunction: (ctx: any, req: Request$1) => any | Promise<any>, ctx: any, bindingTarget?: object, bindingMethod?: PropertyKey, bindingHandler?: object, bindingMetadata?: object): Promise<any>;
644
- protected static bindRequestToInstance(ctx: any, instance: Controller<any> | Route<any, any, any> | null, route: Route<any, any, any>, payload: {
645
- body: Record<string, any>;
646
- query: Record<string, any>;
647
- params: Record<string, any>;
648
- method?: HttpMethod | string;
649
- }): void;
650
- }
651
- //#endregion
652
- export { Middleware$3 as A, H3App as C, FastifyApp as D, Middleware$2 as E, ApiResourceMiddleware as F, ControllerAction as I, HttpMethod as L, HttpContext$4 as M, Middleware$4 as N, Handler$3 as O, Response$2 as P, Middleware$1 as S, HttpContext$2 as T, KoaRouterApp as _, ClearRouterPluginInput as a, HonoApp as b, PluginBind as c, PluginSetupResult as d, definePlugin as f, HttpContext as g, Handler as h, ClearRouterPluginContext as i, Handler$4 as j, HttpContext$3 as k, PluginBindFactory as l, Route as m, ClearRouterPlugin as n, ClearRouterPluginRequestContext as o, Request$1 as p, ClearRouterPluginArgumentsContext as r, PluginArgumentsResolver as s, CoreRouter as t, PluginBindValue as u, Middleware as v, Handler$2 as w, HttpContext$1 as x, Handler$1 as y };