clear-router 2.5.13 → 2.5.14

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 (38) hide show
  1. package/README.md +2 -0
  2. package/dist/core/index.cjs +1 -1
  3. package/dist/core/index.d.cts +1 -1
  4. package/dist/core/index.d.mts +1 -1
  5. package/dist/core/index.mjs +1 -1
  6. package/dist/decorators/setup.cjs +1 -1
  7. package/dist/decorators/setup.d.mts +0 -1
  8. package/dist/decorators/setup.mjs +1 -1
  9. package/dist/express/index.cjs +14 -11
  10. package/dist/express/index.d.cts +11 -9
  11. package/dist/express/index.d.mts +11 -9
  12. package/dist/express/index.mjs +14 -11
  13. package/dist/fastify/index.cjs +16 -13
  14. package/dist/fastify/index.d.cts +11 -9
  15. package/dist/fastify/index.d.mts +11 -9
  16. package/dist/fastify/index.mjs +16 -13
  17. package/dist/h3/index.cjs +14 -11
  18. package/dist/h3/index.d.cts +11 -9
  19. package/dist/h3/index.d.mts +11 -9
  20. package/dist/h3/index.mjs +14 -11
  21. package/dist/hono/index.cjs +14 -11
  22. package/dist/hono/index.d.cts +11 -9
  23. package/dist/hono/index.d.mts +11 -9
  24. package/dist/hono/index.mjs +14 -11
  25. package/dist/index.cjs +101 -11
  26. package/dist/index.d.cts +37 -10
  27. package/dist/index.d.mts +37 -10
  28. package/dist/index.mjs +101 -11
  29. package/dist/koa/index.cjs +14 -11
  30. package/dist/koa/index.d.cts +11 -9
  31. package/dist/koa/index.d.mts +11 -9
  32. package/dist/koa/index.mjs +14 -11
  33. package/dist/{router-DiKqUyvk.d.mts → router-Bk8mXRu1.d.mts} +36 -9
  34. package/dist/{router-D9H9-T27.cjs → router-CAnd539U.cjs} +101 -11
  35. package/dist/{router-CPmZcbU0.mjs → router-DSq9dtuQ.mjs} +101 -11
  36. package/dist/{router-DTI0BowV.d.cts → router-jwZwD8ZT.d.cts} +36 -9
  37. package/dist/types/Route.d.mts +16 -1
  38. package/package.json +1 -1
package/dist/index.d.mts CHANGED
@@ -58,6 +58,11 @@ declare class Response$1 {
58
58
  }
59
59
  //#endregion
60
60
  //#region src/Route.d.ts
61
+ interface RouteParameter {
62
+ name: string;
63
+ field?: string;
64
+ optional: boolean;
65
+ }
61
66
  declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
62
67
  ctx: X;
63
68
  body: RequestData;
@@ -66,13 +71,23 @@ declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
66
71
  clearRequest: ClearRequest;
67
72
  methods: HttpMethod[];
68
73
  path: string;
74
+ registrationPaths: string[];
75
+ parameters: RouteParameter[];
76
+ routeName?: string;
69
77
  handler: H;
70
78
  middlewares: M[];
71
79
  controllerName?: string;
72
80
  actionName?: string;
73
81
  handlerType: 'function' | 'controller';
74
82
  middlewareCount: number;
75
- constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[]);
83
+ constructor(methods: HttpMethod[], path: string, handler: H, middlewares?: M[], options?: {
84
+ registrationPaths?: string[];
85
+ parameters?: RouteParameter[];
86
+ onName?: (name: string, route: Route<X, M, H>, previousName?: string) => void;
87
+ });
88
+ private onName?;
89
+ name(name: string): this;
90
+ toPath(params?: RequestData): string;
76
91
  }
77
92
  //#endregion
78
93
  //#region src/core/Request.d.ts
@@ -222,6 +237,7 @@ declare abstract class CoreRouter {
222
237
  routes: Array<Route<any, any, any>>;
223
238
  routesByPathMethod: Record<string, Route<any, any, any>>;
224
239
  routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
240
+ routesByName: Record<string, Route<any, any, any>>;
225
241
  prefix: string;
226
242
  groupMiddlewares: any[];
227
243
  globalMiddlewares: any[];
@@ -248,6 +264,7 @@ declare abstract class CoreRouter {
248
264
  static routes: Array<Route<any, any, any>>;
249
265
  static routesByPathMethod: Record<string, Route<any, any, any>>;
250
266
  static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
267
+ static routesByName: Record<string, Route<any, any, any>>;
251
268
  static prefix: string;
252
269
  static groupMiddlewares: any[];
253
270
  static globalMiddlewares: any[];
@@ -264,6 +281,13 @@ declare abstract class CoreRouter {
264
281
  * @returns The normalized path.
265
282
  */
266
283
  static normalizePath(path: string): string;
284
+ protected static parseRouteParameters(path: string): Array<{
285
+ name: string;
286
+ field?: string;
287
+ optional: boolean;
288
+ }>;
289
+ protected static expandRoutePath(path: string): string[];
290
+ protected static routeRegistrationPaths(path: string): string[];
267
291
  /**
268
292
  * Configures the router with the given options, such as method override settings.
269
293
  *
@@ -282,7 +306,7 @@ declare abstract class CoreRouter {
282
306
  * @param handler
283
307
  * @param middlewares
284
308
  */
285
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): void;
309
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
286
310
  /**
287
311
  * Define a resourceful API controller with standard CRUD routes.
288
312
  *
@@ -304,7 +328,7 @@ declare abstract class CoreRouter {
304
328
  * @param handler The handler function for the GET route.
305
329
  * @param middlewares Optional middlewares to apply to the GET route.
306
330
  */
307
- static get(path: string, handler: any, middlewares?: any[] | any): void;
331
+ static get(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
308
332
  /**
309
333
  * Adds a new POST route to the router.
310
334
  *
@@ -313,7 +337,7 @@ declare abstract class CoreRouter {
313
337
  * @param handler
314
338
  * @param middlewares
315
339
  */
316
- static post(path: string, handler: any, middlewares?: any[] | any): void;
340
+ static post(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
317
341
  /**
318
342
  * Adds a new PUT route to the router.
319
343
  *
@@ -322,7 +346,7 @@ declare abstract class CoreRouter {
322
346
  * @param handler
323
347
  * @param middlewares
324
348
  */
325
- static put(path: string, handler: any, middlewares?: any[] | any): void;
349
+ static put(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
326
350
  /**
327
351
  * Adds a new DELETE route to the router.
328
352
  *
@@ -331,7 +355,7 @@ declare abstract class CoreRouter {
331
355
  * @param handler
332
356
  * @param middlewares
333
357
  */
334
- static delete(path: string, handler: any, middlewares?: any[] | any): void;
358
+ static delete(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
335
359
  /**
336
360
  * Adds a new PATCH route to the router.
337
361
  *
@@ -340,7 +364,7 @@ declare abstract class CoreRouter {
340
364
  * @param handler
341
365
  * @param middlewares
342
366
  */
343
- static patch(path: string, handler: any, middlewares?: any[] | any): void;
367
+ static patch(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
344
368
  /**
345
369
  * Adds a new OPTIONS route to the router.
346
370
  *
@@ -349,7 +373,7 @@ declare abstract class CoreRouter {
349
373
  * @param handler
350
374
  * @param middlewares
351
375
  */
352
- static options(path: string, handler: any, middlewares?: any[] | any): void;
376
+ static options(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
353
377
  /**
354
378
  * Adds a new HEAD route to the router.
355
379
  *
@@ -358,7 +382,7 @@ declare abstract class CoreRouter {
358
382
  * @param handler
359
383
  * @param middlewares
360
384
  */
361
- static head(path: string, handler: any, middlewares?: any[] | any): void;
385
+ static head(path: string, handler: any, middlewares?: any[] | any): Route<any, any, any>;
362
386
  /**
363
387
  * Defines a group of routes with a common prefix.
364
388
  *
@@ -393,6 +417,9 @@ declare abstract class CoreRouter {
393
417
  * @param type - 'method' to get routes organized by method
394
418
  */
395
419
  static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
420
+ static allRoutes(type: 'name'): Record<string, Route<any, any, any>>;
421
+ static route(name: string): Route<any, any, any> | undefined;
422
+ static url(name: string, params?: Record<string, any>): string | undefined;
396
423
  protected static resolveHandler(route: Route<any, any, any>): {
397
424
  handlerFunction: ((ctx: any, req: Request) => any | Promise<any>) | null;
398
425
  instance: Controller<any> | null;
@@ -410,4 +437,4 @@ declare abstract class CoreRouter {
410
437
  }): void;
411
438
  }
412
439
  //#endregion
413
- export { ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
440
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, RouteParameter, definePlugin };
package/dist/index.mjs CHANGED
@@ -40,21 +40,49 @@ var Route = class {
40
40
  clearRequest;
41
41
  methods;
42
42
  path;
43
+ registrationPaths;
44
+ parameters;
45
+ routeName;
43
46
  handler;
44
47
  middlewares;
45
48
  controllerName;
46
49
  actionName;
47
50
  handlerType;
48
51
  middlewareCount;
49
- constructor(methods, path, handler, middlewares = []) {
52
+ constructor(methods, path, handler, middlewares = [], options = {}) {
50
53
  this.methods = methods;
51
54
  this.path = path;
55
+ this.registrationPaths = options.registrationPaths || [path];
56
+ this.parameters = options.parameters || [];
52
57
  this.handler = handler;
53
58
  this.middlewares = middlewares;
54
59
  this.handlerType = Array.isArray(handler) ? "controller" : "function";
55
60
  this.middlewareCount = middlewares.length;
56
61
  this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
57
62
  this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
63
+ this.onName = options.onName;
64
+ }
65
+ onName;
66
+ name(name) {
67
+ const previousName = this.routeName;
68
+ this.routeName = name;
69
+ this.onName?.(name, this, previousName);
70
+ return this;
71
+ }
72
+ toPath(params = {}) {
73
+ return this.path.replace(/\/?\{([^{}]+)\}/g, (segment, raw) => {
74
+ const optional = raw.endsWith("?");
75
+ const [rawName, rawField] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
76
+ const name = rawName.trim();
77
+ const field = rawField?.trim();
78
+ const value = params[name];
79
+ const resolved = field && value && typeof value === "object" ? value[field] : value;
80
+ if (typeof resolved === "undefined" || resolved === null || resolved === "") {
81
+ if (optional) return "";
82
+ throw new Error(`Missing required route parameter: ${name}`);
83
+ }
84
+ return `${segment.startsWith("/") ? "/" : ""}${encodeURIComponent(String(resolved))}`;
85
+ }) || "/";
58
86
  }
59
87
  };
60
88
 
@@ -333,6 +361,7 @@ var CoreRouter = class {
333
361
  routes: [],
334
362
  routesByPathMethod: {},
335
363
  routesByMethod: {},
364
+ routesByName: {},
336
365
  prefix: "",
337
366
  groupMiddlewares: [],
338
367
  globalMiddlewares: []
@@ -349,6 +378,7 @@ var CoreRouter = class {
349
378
  "routes",
350
379
  "routesByPathMethod",
351
380
  "routesByMethod",
381
+ "routesByName",
352
382
  "prefix",
353
383
  "groupMiddlewares",
354
384
  "globalMiddlewares"
@@ -481,6 +511,7 @@ var CoreRouter = class {
481
511
  static routes = [];
482
512
  static routesByPathMethod = {};
483
513
  static routesByMethod = {};
514
+ static routesByName = {};
484
515
  static prefix = "";
485
516
  static groupMiddlewares = [];
486
517
  static globalMiddlewares = [];
@@ -532,6 +563,7 @@ var CoreRouter = class {
532
563
  if (!Array.isArray(this.routes)) this.routes = [];
533
564
  if (!this.routesByPathMethod || typeof this.routesByPathMethod !== "object") this.routesByPathMethod = {};
534
565
  if (!this.routesByMethod || typeof this.routesByMethod !== "object") this.routesByMethod = {};
566
+ if (!this.routesByName || typeof this.routesByName !== "object") this.routesByName = {};
535
567
  if (typeof this.prefix !== "string") this.prefix = "";
536
568
  if (!Array.isArray(this.groupMiddlewares)) this.groupMiddlewares = [];
537
569
  if (!Array.isArray(this.globalMiddlewares)) this.globalMiddlewares = [];
@@ -546,6 +578,47 @@ var CoreRouter = class {
546
578
  static normalizePath(path) {
547
579
  return "/" + path.split("/").filter(Boolean).join("/");
548
580
  }
581
+ static parseRouteParameters(path) {
582
+ const parameters = [];
583
+ const seen = /* @__PURE__ */ new Set();
584
+ const pattern = /\{([^{}]+)\}/g;
585
+ let match;
586
+ while ((match = pattern.exec(path)) !== null) {
587
+ const raw = match[1].trim();
588
+ const optional = raw.endsWith("?");
589
+ const [name, field] = (optional ? raw.slice(0, -1) : raw).split(":", 2).map((part) => part.trim());
590
+ if (!name || seen.has(name)) continue;
591
+ seen.add(name);
592
+ parameters.push({
593
+ name,
594
+ field: field || void 0,
595
+ optional
596
+ });
597
+ }
598
+ return parameters;
599
+ }
600
+ static expandRoutePath(path) {
601
+ let paths = [""];
602
+ const segments = this.normalizePath(path).split("/").filter(Boolean);
603
+ for (const segment of segments) {
604
+ const match = segment.match(/^\{([^{}]+)\}$/);
605
+ if (!match) {
606
+ paths = paths.map((current) => `${current}/${segment}`);
607
+ continue;
608
+ }
609
+ const raw = match[1].trim();
610
+ const optional = raw.endsWith("?");
611
+ const [rawName] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
612
+ const name = rawName.trim();
613
+ if (!name) continue;
614
+ const parameterSegment = `/:${name}`;
615
+ paths = optional ? paths.flatMap((current) => [current, `${current}${parameterSegment}`]) : paths.map((current) => `${current}${parameterSegment}`);
616
+ }
617
+ return paths.map((path) => path || "/");
618
+ }
619
+ static routeRegistrationPaths(path) {
620
+ return this.expandRoutePath(path);
621
+ }
549
622
  /**
550
623
  * Configures the router with the given options, such as method override settings.
551
624
  *
@@ -619,11 +692,20 @@ var CoreRouter = class {
619
692
  methods = Array.isArray(methods) ? methods : [methods];
620
693
  middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
621
694
  const fullPath = this.normalizePath(`${activePrefix}/${path}`);
695
+ const registrationPaths = this.routeRegistrationPaths(fullPath);
696
+ const parameters = this.parseRouteParameters(fullPath);
622
697
  const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
623
698
  ...this.globalMiddlewares,
624
699
  ...activeGroupMiddlewares,
625
700
  ...middlewares || []
626
- ]);
701
+ ], {
702
+ registrationPaths,
703
+ parameters,
704
+ onName: (name, route, previousName) => {
705
+ if (previousName && this.routesByName[previousName] === route) delete this.routesByName[previousName];
706
+ this.routesByName[name] = route;
707
+ }
708
+ });
627
709
  if (!methods.includes("options") && !this.routesByPathMethod[`OPTIONS ${fullPath}`]) this.options(path, this.createDefaultOptionsHandler());
628
710
  this.routes.push(route);
629
711
  for (const method of methods.map((m) => m.toUpperCase())) {
@@ -631,6 +713,7 @@ var CoreRouter = class {
631
713
  if (!this.routesByMethod[method]) this.routesByMethod[method] = [];
632
714
  this.routesByMethod[method].push(route);
633
715
  }
716
+ return route;
634
717
  }
635
718
  /**
636
719
  * Define a resourceful API controller with standard CRUD routes.
@@ -684,7 +767,7 @@ var CoreRouter = class {
684
767
  * @param middlewares Optional middlewares to apply to the GET route.
685
768
  */
686
769
  static get(path, handler, middlewares) {
687
- this.add("get", path, handler, middlewares);
770
+ return this.add("get", path, handler, middlewares);
688
771
  }
689
772
  /**
690
773
  * Adds a new POST route to the router.
@@ -695,7 +778,7 @@ var CoreRouter = class {
695
778
  * @param middlewares
696
779
  */
697
780
  static post(path, handler, middlewares) {
698
- this.add("post", path, handler, middlewares);
781
+ return this.add("post", path, handler, middlewares);
699
782
  }
700
783
  /**
701
784
  * Adds a new PUT route to the router.
@@ -706,7 +789,7 @@ var CoreRouter = class {
706
789
  * @param middlewares
707
790
  */
708
791
  static put(path, handler, middlewares) {
709
- this.add("put", path, handler, middlewares);
792
+ return this.add("put", path, handler, middlewares);
710
793
  }
711
794
  /**
712
795
  * Adds a new DELETE route to the router.
@@ -717,7 +800,7 @@ var CoreRouter = class {
717
800
  * @param middlewares
718
801
  */
719
802
  static delete(path, handler, middlewares) {
720
- this.add("delete", path, handler, middlewares);
803
+ return this.add("delete", path, handler, middlewares);
721
804
  }
722
805
  /**
723
806
  * Adds a new PATCH route to the router.
@@ -728,7 +811,7 @@ var CoreRouter = class {
728
811
  * @param middlewares
729
812
  */
730
813
  static patch(path, handler, middlewares) {
731
- this.add("patch", path, handler, middlewares);
814
+ return this.add("patch", path, handler, middlewares);
732
815
  }
733
816
  /**
734
817
  * Adds a new OPTIONS route to the router.
@@ -739,7 +822,7 @@ var CoreRouter = class {
739
822
  * @param middlewares
740
823
  */
741
824
  static options(path, handler, middlewares) {
742
- this.add("options", path, handler, middlewares);
825
+ return this.add("options", path, handler, middlewares);
743
826
  }
744
827
  /**
745
828
  * Adds a new HEAD route to the router.
@@ -750,7 +833,7 @@ var CoreRouter = class {
750
833
  * @param middlewares
751
834
  */
752
835
  static head(path, handler, middlewares) {
753
- this.add("head", path, handler, middlewares);
836
+ return this.add("head", path, handler, middlewares);
754
837
  }
755
838
  /**
756
839
  * Defines a group of routes with a common prefix.
@@ -792,8 +875,16 @@ var CoreRouter = class {
792
875
  this.ensureState();
793
876
  if (type === "method") return this.routesByMethod;
794
877
  if (type === "path") return this.routesByPathMethod;
878
+ if (type === "name") return this.routesByName;
795
879
  return this.routes.filter((e) => e.methods.length > 1 || e.methods[0] !== "options");
796
880
  }
881
+ static route(name) {
882
+ this.ensureState();
883
+ return this.routesByName[name];
884
+ }
885
+ static url(name, params) {
886
+ return this.route(name)?.toPath(params);
887
+ }
797
888
  static resolveHandler(route) {
798
889
  let handlerFunction;
799
890
  let instance = null;
@@ -860,8 +951,7 @@ var CoreRouter = class {
860
951
  designTokens
861
952
  });
862
953
  if (pluginArgs) return handlerFunction(...pluginArgs);
863
- if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
864
- if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
954
+ if (!metadata || !tokens.length) return handlerFunction(ctx, ctx.clearRequest);
865
955
  const args = [];
866
956
  for (const token of tokens) {
867
957
  const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-D9H9-T27.cjs');
3
+ const require_router = require('../router-CAnd539U.cjs');
4
4
  const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/koa/router.ts
@@ -69,7 +69,7 @@ var Router = class Router extends require_router.CoreRouter {
69
69
  * @param middlewares
70
70
  */
71
71
  static add(methods, path, handler, middlewares) {
72
- super.add(methods, path, handler, middlewares);
72
+ return super.add(methods, path, handler, middlewares);
73
73
  }
74
74
  /**
75
75
  * Define a resourceful API controller with standard CRUD routes
@@ -89,7 +89,7 @@ var Router = class Router extends require_router.CoreRouter {
89
89
  * @param middlewares
90
90
  */
91
91
  static get(path, handler, middlewares) {
92
- super.get(path, handler, middlewares);
92
+ return super.get(path, handler, middlewares);
93
93
  }
94
94
  /**
95
95
  * Define a POST route
@@ -99,7 +99,7 @@ var Router = class Router extends require_router.CoreRouter {
99
99
  * @param middlewares
100
100
  */
101
101
  static post(path, handler, middlewares) {
102
- super.post(path, handler, middlewares);
102
+ return super.post(path, handler, middlewares);
103
103
  }
104
104
  /**
105
105
  * Define a PUT route
@@ -109,7 +109,7 @@ var Router = class Router extends require_router.CoreRouter {
109
109
  * @param middlewares
110
110
  */
111
111
  static put(path, handler, middlewares) {
112
- super.put(path, handler, middlewares);
112
+ return super.put(path, handler, middlewares);
113
113
  }
114
114
  /**
115
115
  * Define a DELETE route
@@ -119,7 +119,7 @@ var Router = class Router extends require_router.CoreRouter {
119
119
  * @param middlewares
120
120
  */
121
121
  static delete(path, handler, middlewares) {
122
- super.delete(path, handler, middlewares);
122
+ return super.delete(path, handler, middlewares);
123
123
  }
124
124
  /**
125
125
  * Define a PATCH route
@@ -129,7 +129,7 @@ var Router = class Router extends require_router.CoreRouter {
129
129
  * @param middlewares
130
130
  */
131
131
  static patch(path, handler, middlewares) {
132
- super.patch(path, handler, middlewares);
132
+ return super.patch(path, handler, middlewares);
133
133
  }
134
134
  /**
135
135
  * Define an OPTIONS route
@@ -139,7 +139,7 @@ var Router = class Router extends require_router.CoreRouter {
139
139
  * @param middlewares
140
140
  */
141
141
  static options(path, handler, middlewares) {
142
- super.options(path, handler, middlewares);
142
+ return super.options(path, handler, middlewares);
143
143
  }
144
144
  /**
145
145
  * Adds a new HEAD route to the router.
@@ -150,7 +150,7 @@ var Router = class Router extends require_router.CoreRouter {
150
150
  * @param middlewares
151
151
  */
152
152
  static head(path, handler, middlewares) {
153
- super.head(path, handler, middlewares);
153
+ return super.head(path, handler, middlewares);
154
154
  }
155
155
  /**
156
156
  * Defines a group of routes with a common prefix.
@@ -174,6 +174,9 @@ var Router = class Router extends require_router.CoreRouter {
174
174
  static allRoutes(type) {
175
175
  return super.allRoutes(type);
176
176
  }
177
+ static route(name) {
178
+ return super.route(name);
179
+ }
177
180
  /**
178
181
  * Apply the defined routes to a @koa/router instance
179
182
  *
@@ -213,7 +216,7 @@ var Router = class Router extends require_router.CoreRouter {
213
216
  ];
214
217
  if (method === "options" && route.methods.length > 1) continue;
215
218
  if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
216
- router[method](route.path, ...route.middlewares || [], async (context, next) => {
219
+ for (const registrationPath of route.registrationPaths) router[method](registrationPath, ...route.middlewares || [], async (context, next) => {
217
220
  const ctx = context;
218
221
  const reqBody = await Router.readBodyCached(ctx);
219
222
  const override = Router.resolveMethodOverride(ctx.method, ctx.headers, reqBody);
@@ -234,7 +237,7 @@ var Router = class Router extends require_router.CoreRouter {
234
237
  "put",
235
238
  "patch",
236
239
  "delete"
237
- ].includes(method)) router.post(route.path, ...route.middlewares || [], async (context, next) => {
240
+ ].includes(method)) for (const registrationPath of route.registrationPaths) router.post(registrationPath, ...route.middlewares || [], async (context, next) => {
238
241
  const ctx = context;
239
242
  const reqBody = await Router.readBodyCached(ctx);
240
243
  if (Router.resolveMethodOverride(ctx.method, ctx.headers, reqBody) !== method) return next();
@@ -1,4 +1,4 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-DTI0BowV.cjs";
1
+ import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-jwZwD8ZT.cjs";
2
2
  import Koa from "koa";
3
3
  import Router$1 from "@koa/router";
4
4
 
@@ -40,7 +40,7 @@ declare class Router extends CoreRouter {
40
40
  * @param handler
41
41
  * @param middlewares
42
42
  */
43
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
43
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
44
44
  /**
45
45
  * Define a resourceful API controller with standard CRUD routes
46
46
  *
@@ -60,7 +60,7 @@ declare class Router extends CoreRouter {
60
60
  * @param handler
61
61
  * @param middlewares
62
62
  */
63
- static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
63
+ static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
64
64
  /**
65
65
  * Define a POST route
66
66
  *
@@ -68,7 +68,7 @@ declare class Router extends CoreRouter {
68
68
  * @param handler
69
69
  * @param middlewares
70
70
  */
71
- static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
71
+ static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
72
72
  /**
73
73
  * Define a PUT route
74
74
  *
@@ -76,7 +76,7 @@ declare class Router extends CoreRouter {
76
76
  * @param handler
77
77
  * @param middlewares
78
78
  */
79
- static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
79
+ static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
80
80
  /**
81
81
  * Define a DELETE route
82
82
  *
@@ -84,7 +84,7 @@ declare class Router extends CoreRouter {
84
84
  * @param handler
85
85
  * @param middlewares
86
86
  */
87
- static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
87
+ static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
88
88
  /**
89
89
  * Define a PATCH route
90
90
  *
@@ -92,7 +92,7 @@ declare class Router extends CoreRouter {
92
92
  * @param handler
93
93
  * @param middlewares
94
94
  */
95
- static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
95
+ static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
96
96
  /**
97
97
  * Define an OPTIONS route
98
98
  *
@@ -100,7 +100,7 @@ declare class Router extends CoreRouter {
100
100
  * @param handler
101
101
  * @param middlewares
102
102
  */
103
- static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
103
+ static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
104
104
  /**
105
105
  * Adds a new HEAD route to the router.
106
106
  *
@@ -109,7 +109,7 @@ declare class Router extends CoreRouter {
109
109
  * @param handler
110
110
  * @param middlewares
111
111
  */
112
- static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
112
+ static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
113
113
  /**
114
114
  * Defines a group of routes with a common prefix.
115
115
  *
@@ -137,6 +137,8 @@ declare class Router extends CoreRouter {
137
137
  * @param type - 'method' to get routes organized by method
138
138
  */
139
139
  static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
140
+ static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
141
+ static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
140
142
  /**
141
143
  * Apply the defined routes to a @koa/router instance
142
144
  *
@@ -1,4 +1,4 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-DiKqUyvk.mjs";
1
+ import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-Bk8mXRu1.mjs";
2
2
  import Koa from "koa";
3
3
  import Router$1 from "@koa/router";
4
4
 
@@ -40,7 +40,7 @@ declare class Router extends CoreRouter {
40
40
  * @param handler
41
41
  * @param middlewares
42
42
  */
43
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
43
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
44
44
  /**
45
45
  * Define a resourceful API controller with standard CRUD routes
46
46
  *
@@ -60,7 +60,7 @@ declare class Router extends CoreRouter {
60
60
  * @param handler
61
61
  * @param middlewares
62
62
  */
63
- static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
63
+ static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
64
64
  /**
65
65
  * Define a POST route
66
66
  *
@@ -68,7 +68,7 @@ declare class Router extends CoreRouter {
68
68
  * @param handler
69
69
  * @param middlewares
70
70
  */
71
- static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
71
+ static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
72
72
  /**
73
73
  * Define a PUT route
74
74
  *
@@ -76,7 +76,7 @@ declare class Router extends CoreRouter {
76
76
  * @param handler
77
77
  * @param middlewares
78
78
  */
79
- static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
79
+ static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
80
80
  /**
81
81
  * Define a DELETE route
82
82
  *
@@ -84,7 +84,7 @@ declare class Router extends CoreRouter {
84
84
  * @param handler
85
85
  * @param middlewares
86
86
  */
87
- static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
87
+ static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
88
88
  /**
89
89
  * Define a PATCH route
90
90
  *
@@ -92,7 +92,7 @@ declare class Router extends CoreRouter {
92
92
  * @param handler
93
93
  * @param middlewares
94
94
  */
95
- static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
95
+ static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
96
96
  /**
97
97
  * Define an OPTIONS route
98
98
  *
@@ -100,7 +100,7 @@ declare class Router extends CoreRouter {
100
100
  * @param handler
101
101
  * @param middlewares
102
102
  */
103
- static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
103
+ static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
104
104
  /**
105
105
  * Adds a new HEAD route to the router.
106
106
  *
@@ -109,7 +109,7 @@ declare class Router extends CoreRouter {
109
109
  * @param handler
110
110
  * @param middlewares
111
111
  */
112
- static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
112
+ static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
113
113
  /**
114
114
  * Defines a group of routes with a common prefix.
115
115
  *
@@ -137,6 +137,8 @@ declare class Router extends CoreRouter {
137
137
  * @param type - 'method' to get routes organized by method
138
138
  */
139
139
  static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
140
+ static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
141
+ static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
140
142
  /**
141
143
  * Apply the defined routes to a @koa/router instance
142
144
  *