clear-router 2.8.3 → 2.8.5

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 (61) hide show
  1. package/dist/ClearRequest.d.cts +5 -5
  2. package/dist/ClearRequest.d.mts +1 -1
  3. package/dist/Controller.d.mts +1 -1
  4. package/dist/ResourceRouteSelection.d.cts +3 -3
  5. package/dist/ResourceRoutes.cjs +1 -1
  6. package/dist/ResourceRoutes.d.cts +4 -4
  7. package/dist/ResourceRoutes.d.mts +1 -1
  8. package/dist/ResourceRoutes.mjs +1 -1
  9. package/dist/Route.d.cts +4 -4
  10. package/dist/Route.d.mts +1 -1
  11. package/dist/RouteGroup.cjs +36 -6
  12. package/dist/RouteGroup.d.cts +14 -5
  13. package/dist/RouteGroup.d.mts +12 -3
  14. package/dist/RouteGroup.mjs +36 -6
  15. package/dist/core/CoreRouter.cjs +2 -2
  16. package/dist/core/CoreRouter.d.cts +4 -4
  17. package/dist/core/CoreRouter.d.mts +1 -1
  18. package/dist/core/CoreRouter.mjs +2 -2
  19. package/dist/core/Request.d.cts +1 -1
  20. package/dist/core/Request.d.mts +2 -2
  21. package/dist/core/bindings.d.cts +6 -1
  22. package/dist/core/helpers.d.cts +1 -1
  23. package/dist/core/helpers.d.mts +1 -1
  24. package/dist/core/index.cjs +9 -0
  25. package/dist/core/index.mjs +2 -2
  26. package/dist/core/plugins.d.cts +2 -2
  27. package/dist/core/plugins.d.mts +1 -1
  28. package/dist/decorators/setup.d.mts +1 -0
  29. package/dist/express/router.d.cts +15 -15
  30. package/dist/express/router.d.mts +15 -15
  31. package/dist/fastify/router.d.cts +15 -15
  32. package/dist/fastify/router.d.mts +15 -15
  33. package/dist/h3/router.d.cts +15 -15
  34. package/dist/h3/router.d.mts +15 -15
  35. package/dist/hono/router.d.cts +15 -15
  36. package/dist/hono/router.d.mts +15 -15
  37. package/dist/index.d.cts +2 -2
  38. package/dist/index.d.mts +2 -2
  39. package/dist/koa/router.d.cts +17 -17
  40. package/dist/koa/router.d.mts +17 -17
  41. package/dist/types/basic.cjs +0 -0
  42. package/dist/types/basic.d.cts +8 -3
  43. package/dist/types/basic.d.mts +5 -4
  44. package/dist/types/express.cjs +0 -0
  45. package/dist/types/express.d.cts +36 -2
  46. package/dist/types/express.d.mts +3 -3
  47. package/dist/types/fastify.cjs +0 -0
  48. package/dist/types/fastify.d.cts +15 -3
  49. package/dist/types/fastify.d.mts +3 -3
  50. package/dist/types/h3.cjs +0 -0
  51. package/dist/types/h3.d.cts +42 -5
  52. package/dist/types/h3.d.mts +8 -6
  53. package/dist/types/hono.cjs +0 -0
  54. package/dist/types/hono.d.cts +18 -3
  55. package/dist/types/hono.d.mts +4 -3
  56. package/dist/types/koa.cjs +0 -0
  57. package/dist/types/koa.d.cts +21 -2
  58. package/dist/types/koa.d.mts +4 -3
  59. package/package.json +25 -7
  60. package/dist/Route-tq-rge1g.d.mts +0 -136
  61. package/dist/types/index.d.mts +0 -1
@@ -1,6 +1,6 @@
1
+ import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
1
2
  import { Handler, HonoApp, HttpContext, Middleware } from "../types/hono.mjs";
2
3
  import { Route } from "../Route.mjs";
3
- import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
4
4
  import { ResourceRoutes } from "../ResourceRoutes.mjs";
5
5
  import { RouteGroup } from "../RouteGroup.mjs";
6
6
  import { CoreRouter } from "../core/CoreRouter.mjs";
@@ -26,7 +26,7 @@ declare class Router extends CoreRouter {
26
26
  * @param handler
27
27
  * @param middlewares
28
28
  */
29
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
29
+ static add<T = any>(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
30
30
  /**
31
31
  * Define a resourceful API controller with standard CRUD routes
32
32
  *
@@ -46,7 +46,7 @@ declare class Router extends CoreRouter {
46
46
  * @param handler
47
47
  * @param middlewares
48
48
  */
49
- static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
49
+ static get<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
50
50
  /**
51
51
  * Define a POST route
52
52
  *
@@ -54,7 +54,7 @@ declare class Router extends CoreRouter {
54
54
  * @param handler
55
55
  * @param middlewares
56
56
  */
57
- static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
57
+ static post<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
58
58
  /**
59
59
  * Define a PUT route
60
60
  *
@@ -62,7 +62,7 @@ declare class Router extends CoreRouter {
62
62
  * @param handler
63
63
  * @param middlewares
64
64
  */
65
- static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
65
+ static put<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
66
66
  /**
67
67
  * Define a DELETE route
68
68
  *
@@ -70,7 +70,7 @@ declare class Router extends CoreRouter {
70
70
  * @param handler
71
71
  * @param middlewares
72
72
  */
73
- static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
73
+ static delete<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
74
74
  /**
75
75
  * Define a PATCH route
76
76
  *
@@ -78,7 +78,7 @@ declare class Router extends CoreRouter {
78
78
  * @param handler
79
79
  * @param middlewares
80
80
  */
81
- static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
81
+ static patch<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
82
82
  /**
83
83
  * Define an OPTIONS route
84
84
  *
@@ -86,7 +86,7 @@ declare class Router extends CoreRouter {
86
86
  * @param handler
87
87
  * @param middlewares
88
88
  */
89
- static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
89
+ static options<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
90
90
  /**
91
91
  * Define a HEAD route
92
92
  *
@@ -94,7 +94,7 @@ declare class Router extends CoreRouter {
94
94
  * @param handler
95
95
  * @param middlewares
96
96
  */
97
- static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
97
+ static head<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
98
98
  /**
99
99
  * Defines a group of routes with a common prefix.
100
100
  *
@@ -102,7 +102,7 @@ declare class Router extends CoreRouter {
102
102
  * @param callback
103
103
  * @param middlewares
104
104
  */
105
- static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler>;
105
+ static group<T = any>(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler<T>>;
106
106
  /**
107
107
  * Apply middlewares to a group of routes defined within the callback
108
108
  *
@@ -113,17 +113,17 @@ declare class Router extends CoreRouter {
113
113
  /**
114
114
  * Get all defined routes, optionally organized by path or method
115
115
  */
116
- static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
116
+ static allRoutes<T = any>(): Array<Route<HttpContext, Middleware, Handler<T>>>;
117
117
  /**
118
118
  * @param type - 'path' to get routes organized by path
119
119
  */
120
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
120
+ static allRoutes<T = any>(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
121
121
  /**
122
122
  * @param type - 'method' to get routes organized by method
123
123
  */
124
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
125
- static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
126
- static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
124
+ static allRoutes<T = any>(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler<T>>> };
125
+ static allRoutes<T = any>(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
126
+ static route<T = any>(name: string): Route<HttpContext, Middleware, Handler<T>> | undefined;
127
127
  /**
128
128
  * Apply the defined routes to a Hono application instance
129
129
  *
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ClearHttpContext, RouteParameter } from "./Contracts.cjs";
2
- import { Request } from "./core/Request.cjs";
3
2
  import { Response } from "./core/Response.cjs";
4
3
  import { Route } from "./Route.cjs";
5
4
  import { ClearRequest } from "./ClearRequest.cjs";
5
+ import { Request } from "./core/Request.cjs";
6
+ import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.cjs";
6
7
  import { Controller } from "./Controller.cjs";
7
8
  import { RouteGroup } from "./RouteGroup.cjs";
8
- import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.cjs";
9
9
  import { CoreRouter } from "./core/CoreRouter.cjs";
10
10
  import { importFile, wrap } from "./core/helpers.cjs";
11
11
  export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, definePlugin, importFile, wrap };
package/dist/index.d.mts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { ClearHttpContext, RouteParameter } from "./Contracts.mjs";
2
- import { Request } from "./core/Request.mjs";
3
2
  import { Response } from "./core/Response.mjs";
4
3
  import { Route } from "./Route.mjs";
5
4
  import { ClearRequest } from "./ClearRequest.mjs";
5
+ import { Request } from "./core/Request.mjs";
6
+ import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.mjs";
6
7
  import { Controller } from "./Controller.mjs";
7
8
  import { RouteGroup } from "./RouteGroup.mjs";
8
- import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.mjs";
9
9
  import { CoreRouter } from "./core/CoreRouter.mjs";
10
10
  import { importFile, wrap } from "./core/helpers.mjs";
11
11
  export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteGroup, RouteParameter, definePlugin, importFile, wrap };
@@ -1,6 +1,6 @@
1
+ import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.cjs";
1
2
  import { Handler, HttpContext, KoaRouterApp, Middleware } from "../types/koa.cjs";
2
3
  import { Route } from "../Route.cjs";
3
- import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.cjs";
4
4
  import { ResourceRoutes } from "../ResourceRoutes.cjs";
5
5
  import { RouteGroup } from "../RouteGroup.cjs";
6
6
  import { CoreRouter } from "../core/CoreRouter.cjs";
@@ -26,7 +26,7 @@ declare class Router extends CoreRouter {
26
26
  * @param handler
27
27
  * @param middlewares
28
28
  */
29
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
29
+ static add<T = any>(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
30
30
  /**
31
31
  * Define a resourceful API controller with standard CRUD routes
32
32
  *
@@ -34,11 +34,11 @@ declare class Router extends CoreRouter {
34
34
  * @param controller
35
35
  * @param options
36
36
  */
37
- static apiResource(basePath: string, controller: any, options?: {
37
+ static apiResource<T = any>(basePath: string, controller: any, options?: {
38
38
  only?: ResourceAction[];
39
39
  except?: ResourceAction[];
40
40
  middlewares?: ApiResourceMiddleware<Middleware>;
41
- }): ResourceRoutes<HttpContext, Middleware, Handler>;
41
+ }): ResourceRoutes<HttpContext, Middleware, Handler<T>>;
42
42
  /**
43
43
  * Define a GET route
44
44
  *
@@ -46,7 +46,7 @@ declare class Router extends CoreRouter {
46
46
  * @param handler
47
47
  * @param middlewares
48
48
  */
49
- static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
49
+ static get<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
50
50
  /**
51
51
  * Define a POST route
52
52
  *
@@ -54,7 +54,7 @@ declare class Router extends CoreRouter {
54
54
  * @param handler
55
55
  * @param middlewares
56
56
  */
57
- static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
57
+ static post<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
58
58
  /**
59
59
  * Define a PUT route
60
60
  *
@@ -62,7 +62,7 @@ declare class Router extends CoreRouter {
62
62
  * @param handler
63
63
  * @param middlewares
64
64
  */
65
- static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
65
+ static put<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
66
66
  /**
67
67
  * Define a DELETE route
68
68
  *
@@ -70,7 +70,7 @@ declare class Router extends CoreRouter {
70
70
  * @param handler
71
71
  * @param middlewares
72
72
  */
73
- static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
73
+ static delete<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
74
74
  /**
75
75
  * Define a PATCH route
76
76
  *
@@ -78,7 +78,7 @@ declare class Router extends CoreRouter {
78
78
  * @param handler
79
79
  * @param middlewares
80
80
  */
81
- static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
81
+ static patch<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
82
82
  /**
83
83
  * Define an OPTIONS route
84
84
  *
@@ -86,7 +86,7 @@ declare class Router extends CoreRouter {
86
86
  * @param handler
87
87
  * @param middlewares
88
88
  */
89
- static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
89
+ static options<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
90
90
  /**
91
91
  * Adds a new HEAD route to the router.
92
92
  *
@@ -95,7 +95,7 @@ declare class Router extends CoreRouter {
95
95
  * @param handler
96
96
  * @param middlewares
97
97
  */
98
- static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
98
+ static head<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
99
99
  /**
100
100
  * Defines a group of routes with a common prefix.
101
101
  *
@@ -103,7 +103,7 @@ declare class Router extends CoreRouter {
103
103
  * @param callback
104
104
  * @param middlewares
105
105
  */
106
- static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler>;
106
+ static group<T = any>(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler<T>>;
107
107
  /**
108
108
  * Apply middlewares to a group of routes defined within the callback
109
109
  *
@@ -114,17 +114,17 @@ declare class Router extends CoreRouter {
114
114
  /**
115
115
  * Get all defined routes, optionally organized by path or method
116
116
  */
117
- static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
117
+ static allRoutes<T = any>(): Array<Route<HttpContext, Middleware, Handler<T>>>;
118
118
  /**
119
119
  * @param type - 'path' to get routes organized by path
120
120
  */
121
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
121
+ static allRoutes<T = any>(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
122
122
  /**
123
123
  * @param type - 'method' to get routes organized by method
124
124
  */
125
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
126
- static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
127
- static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
125
+ static allRoutes<T = any>(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler<T>>> };
126
+ static allRoutes<T = any>(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
127
+ static route<T = any>(name: string): Route<HttpContext, Middleware, Handler<T>> | undefined;
128
128
  /**
129
129
  * Apply the defined routes to a @koa/router instance
130
130
  *
@@ -1,6 +1,6 @@
1
+ import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
1
2
  import { Handler, HttpContext, KoaRouterApp, Middleware } from "../types/koa.mjs";
2
3
  import { Route } from "../Route.mjs";
3
- import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
4
4
  import { ResourceRoutes } from "../ResourceRoutes.mjs";
5
5
  import { RouteGroup } from "../RouteGroup.mjs";
6
6
  import { CoreRouter } from "../core/CoreRouter.mjs";
@@ -26,7 +26,7 @@ declare class Router extends CoreRouter {
26
26
  * @param handler
27
27
  * @param middlewares
28
28
  */
29
- static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
29
+ static add<T = any>(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
30
30
  /**
31
31
  * Define a resourceful API controller with standard CRUD routes
32
32
  *
@@ -34,11 +34,11 @@ declare class Router extends CoreRouter {
34
34
  * @param controller
35
35
  * @param options
36
36
  */
37
- static apiResource(basePath: string, controller: any, options?: {
37
+ static apiResource<T = any>(basePath: string, controller: any, options?: {
38
38
  only?: ResourceAction[];
39
39
  except?: ResourceAction[];
40
40
  middlewares?: ApiResourceMiddleware<Middleware>;
41
- }): ResourceRoutes<HttpContext, Middleware, Handler>;
41
+ }): ResourceRoutes<HttpContext, Middleware, Handler<T>>;
42
42
  /**
43
43
  * Define a GET route
44
44
  *
@@ -46,7 +46,7 @@ declare class Router extends CoreRouter {
46
46
  * @param handler
47
47
  * @param middlewares
48
48
  */
49
- static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
49
+ static get<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
50
50
  /**
51
51
  * Define a POST route
52
52
  *
@@ -54,7 +54,7 @@ declare class Router extends CoreRouter {
54
54
  * @param handler
55
55
  * @param middlewares
56
56
  */
57
- static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
57
+ static post<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
58
58
  /**
59
59
  * Define a PUT route
60
60
  *
@@ -62,7 +62,7 @@ declare class Router extends CoreRouter {
62
62
  * @param handler
63
63
  * @param middlewares
64
64
  */
65
- static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
65
+ static put<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
66
66
  /**
67
67
  * Define a DELETE route
68
68
  *
@@ -70,7 +70,7 @@ declare class Router extends CoreRouter {
70
70
  * @param handler
71
71
  * @param middlewares
72
72
  */
73
- static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
73
+ static delete<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
74
74
  /**
75
75
  * Define a PATCH route
76
76
  *
@@ -78,7 +78,7 @@ declare class Router extends CoreRouter {
78
78
  * @param handler
79
79
  * @param middlewares
80
80
  */
81
- static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
81
+ static patch<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
82
82
  /**
83
83
  * Define an OPTIONS route
84
84
  *
@@ -86,7 +86,7 @@ declare class Router extends CoreRouter {
86
86
  * @param handler
87
87
  * @param middlewares
88
88
  */
89
- static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
89
+ static options<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
90
90
  /**
91
91
  * Adds a new HEAD route to the router.
92
92
  *
@@ -95,7 +95,7 @@ declare class Router extends CoreRouter {
95
95
  * @param handler
96
96
  * @param middlewares
97
97
  */
98
- static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
98
+ static head<T = any>(path: string, handler: Handler<T>, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler<T>>;
99
99
  /**
100
100
  * Defines a group of routes with a common prefix.
101
101
  *
@@ -103,7 +103,7 @@ declare class Router extends CoreRouter {
103
103
  * @param callback
104
104
  * @param middlewares
105
105
  */
106
- static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler>;
106
+ static group<T = any>(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): RouteGroup<HttpContext, Middleware, Handler<T>>;
107
107
  /**
108
108
  * Apply middlewares to a group of routes defined within the callback
109
109
  *
@@ -114,17 +114,17 @@ declare class Router extends CoreRouter {
114
114
  /**
115
115
  * Get all defined routes, optionally organized by path or method
116
116
  */
117
- static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
117
+ static allRoutes<T = any>(): Array<Route<HttpContext, Middleware, Handler<T>>>;
118
118
  /**
119
119
  * @param type - 'path' to get routes organized by path
120
120
  */
121
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
121
+ static allRoutes<T = any>(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
122
122
  /**
123
123
  * @param type - 'method' to get routes organized by method
124
124
  */
125
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
126
- static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
127
- static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
125
+ static allRoutes<T = any>(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler<T>>> };
126
+ static allRoutes<T = any>(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler<T>>>;
127
+ static route<T = any>(name: string): Route<HttpContext, Middleware, Handler<T>> | undefined;
128
128
  /**
129
129
  * Apply the defined routes to a @koa/router instance
130
130
  *
File without changes
@@ -1,8 +1,13 @@
1
- import { Route } from "../Route.cjs";
2
1
  import { JitiOptions, JitiResolveOptions } from "jiti";
3
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
+ import { Route } from "src/Route";
4
4
 
5
5
  //#region src/types/basic.d.ts
6
+ type OwnStatics<T> = Omit<T, keyof Function | 'prototype'>;
7
+ /**
8
+ * Controller method reference
9
+ */
10
+ type ControllerHandler<T = any> = T extends (abstract new (...args: any[]) => infer I) ? [T, ({ [K in keyof I]: I[K] extends ((...args: any[]) => any) ? K : never }[keyof I] & string) | ({ [K in keyof OwnStatics<T>]: OwnStatics<T>[K] extends ((...args: any[]) => any) ? K : never }[keyof OwnStatics<T>] & string)] : [any, string];
6
11
  type MaybePromise<T = any> = T | Promise<T>;
7
12
  type RouteGroupCallback = () => MaybePromise<any>;
8
13
  type RouteGroupEntry = RouteGroupCallback | string;
@@ -84,7 +89,7 @@ interface RouteGroupOptions {
84
89
  normalizePath: (path: string) => string;
85
90
  removeRoute: (route: Route<any, any, any>) => void;
86
91
  }
87
- type RouteGroupCondition = (source: RouteGroupSource) => MaybePromise<unknown>;
92
+ type RouteGroupCondition = (source: RouteGroupEntry) => MaybePromise<unknown>;
88
93
  interface FileImporter {
89
94
  <T = unknown>(filePath: string): Promise<T>;
90
95
  <T = unknown>(filePath: string, userOptions?: JitiOptions | undefined): Promise<T>;
@@ -93,4 +98,4 @@ interface FileImporter {
93
98
  })): Promise<T>;
94
99
  }
95
100
  //#endregion
96
- export { ApiResourceMiddleware, ClassMiddleware, FileImporter, HttpMethod, MiddlewareHandle, RequestData, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions, RouteGroupCondition, RouteGroupContext, RouteGroupOptions, RouteGroupSource, RouterConfig };
101
+ export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MaybePromise, MiddlewareClass, MiddlewareHandle, MiddlewareInstance, RequestData, ResourceAction, ResourceRouteDefinition, ResourceRouteRegistrar, ResourceRouteRemover, ResourceRoutesOptions, RouteGroupCallback, RouteGroupCondition, RouteGroupContext, RouteGroupEntry, RouteGroupOptions, RouteGroupSource, RouterConfig };
@@ -1,12 +1,13 @@
1
- import { Route } from "../Route.mjs";
2
- import { AsyncLocalStorage } from "node:async_hooks";
3
1
  import { JitiOptions, JitiResolveOptions } from "jiti";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ import { Route } from "src/Route";
4
4
 
5
5
  //#region src/types/basic.d.ts
6
+ type OwnStatics<T> = Omit<T, keyof Function | 'prototype'>;
6
7
  /**
7
8
  * Controller method reference
8
9
  */
9
- type ControllerHandler = [any, string];
10
+ type ControllerHandler<T = any> = T extends (abstract new (...args: any[]) => infer I) ? [T, ({ [K in keyof I]: I[K] extends ((...args: any[]) => any) ? K : never }[keyof I] & string) | ({ [K in keyof OwnStatics<T>]: OwnStatics<T>[K] extends ((...args: any[]) => any) ? K : never }[keyof OwnStatics<T>] & string)] : [any, string];
10
11
  type MaybePromise<T = any> = T | Promise<T>;
11
12
  type RouteGroupCallback = () => MaybePromise<any>;
12
13
  type RouteGroupEntry = RouteGroupCallback | string;
@@ -88,7 +89,7 @@ interface RouteGroupOptions {
88
89
  normalizePath: (path: string) => string;
89
90
  removeRoute: (route: Route<any, any, any>) => void;
90
91
  }
91
- type RouteGroupCondition = (source: RouteGroupSource) => MaybePromise<unknown>;
92
+ type RouteGroupCondition = (source: RouteGroupEntry) => MaybePromise<unknown>;
92
93
  interface FileImporter {
93
94
  <T = unknown>(filePath: string): Promise<T>;
94
95
  <T = unknown>(filePath: string, userOptions?: JitiOptions | undefined): Promise<T>;
File without changes
@@ -1,7 +1,41 @@
1
- import { ClassMiddleware, MiddlewareHandle } from "./basic.cjs";
1
+ import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.cjs";
2
+ import { ClearHttpContext } from "../Contracts.cjs";
3
+ import { Response as Response$1 } from "../core/Response.cjs";
4
+ import { Request as Request$1 } from "../core/Request.cjs";
2
5
  import { NextFunction, Request, Response } from "express";
3
6
 
4
7
  //#region src/types/express.d.ts
8
+ interface RequestWithGetBody extends Request {
9
+ getBody: () => Record<string, any>;
10
+ }
11
+ /**
12
+ * HTTP context passed to route handlers
13
+ */
14
+ interface HttpContext extends ClearHttpContext {
15
+ req: RequestWithGetBody;
16
+ res: Response;
17
+ next: NextFunction;
18
+ clearRequest: Request$1;
19
+ clearResponse: Response$1;
20
+ }
21
+ /**
22
+ * Route handler function type
23
+ */
24
+ type RouteHandler = (
25
+ /**
26
+ * Express context object containing req, res, and next
27
+ */
28
+
29
+ ctx: HttpContext,
30
+ /**
31
+ * ClearRequest instance
32
+ */
33
+
34
+ req: Request$1) => any | Promise<any>;
35
+ /**
36
+ * Handler can be either a function or controller reference
37
+ */
38
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
5
39
  /**
6
40
  * Middleware function type
7
41
  */
@@ -11,4 +45,4 @@ type MiddlewareFunction = MiddlewareHandle<[Request, Response, NextFunction]>;
11
45
  */
12
46
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
13
47
  //#endregion
14
- export { Middleware };
48
+ export { Handler, HttpContext, Middleware, MiddlewareFunction, RequestWithGetBody, RouteHandler };
@@ -1,6 +1,6 @@
1
+ import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.mjs";
1
2
  import { ClearHttpContext } from "../Contracts.mjs";
2
3
  import { Response as Response$1 } from "../core/Response.mjs";
3
- import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.mjs";
4
4
  import { Request as Request$1 } from "../core/Request.mjs";
5
5
  import { NextFunction, Request, Response } from "express";
6
6
 
@@ -35,7 +35,7 @@ req: Request$1) => any | Promise<any>;
35
35
  /**
36
36
  * Handler can be either a function or controller reference
37
37
  */
38
- type Handler = RouteHandler | ControllerHandler;
38
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
39
39
  /**
40
40
  * Middleware function type
41
41
  */
@@ -45,4 +45,4 @@ type MiddlewareFunction = MiddlewareHandle<[Request, Response, NextFunction]>;
45
45
  */
46
46
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
47
47
  //#endregion
48
- export { Handler, HttpContext, Middleware };
48
+ export { Handler, HttpContext, Middleware, MiddlewareFunction, RequestWithGetBody, RouteHandler };
File without changes
@@ -1,12 +1,24 @@
1
- import { ClassMiddleware, MiddlewareHandle } from "./basic.cjs";
2
- import { FastifyReply, FastifyRequest } from "fastify";
1
+ import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.cjs";
2
+ import { ClearHttpContext } from "../Contracts.cjs";
3
+ import { Response } from "../core/Response.cjs";
4
+ import { Request } from "../core/Request.cjs";
5
+ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
6
 
4
7
  //#region src/types/fastify.d.ts
5
8
  interface RequestWithGetBody extends FastifyRequest {
6
9
  getBody: () => Record<string, any>;
7
10
  }
11
+ interface HttpContext extends ClearHttpContext {
12
+ req: RequestWithGetBody;
13
+ reply: FastifyReply;
14
+ clearRequest: Request;
15
+ clearResponse: Response;
16
+ }
17
+ type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
18
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
8
19
  type NextFunction = (err?: Error) => void;
9
20
  type MiddlewareFunction = MiddlewareHandle<[req: RequestWithGetBody, reply: FastifyReply, next: NextFunction]>;
10
21
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
22
+ type FastifyApp = FastifyInstance;
11
23
  //#endregion
12
- export { Middleware };
24
+ export { FastifyApp, Handler, HttpContext, Middleware, MiddlewareFunction, NextFunction, RequestWithGetBody, RouteHandler };
@@ -1,6 +1,6 @@
1
+ import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.mjs";
1
2
  import { ClearHttpContext } from "../Contracts.mjs";
2
3
  import { Response } from "../core/Response.mjs";
3
- import { ClassMiddleware, ControllerHandler, MiddlewareHandle } from "./basic.mjs";
4
4
  import { Request } from "../core/Request.mjs";
5
5
  import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
6
6
 
@@ -15,10 +15,10 @@ interface HttpContext extends ClearHttpContext {
15
15
  clearResponse: Response;
16
16
  }
17
17
  type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
18
- type Handler = RouteHandler | ControllerHandler;
18
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
19
19
  type NextFunction = (err?: Error) => void;
20
20
  type MiddlewareFunction = MiddlewareHandle<[req: RequestWithGetBody, reply: FastifyReply, next: NextFunction]>;
21
21
  type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
22
22
  type FastifyApp = FastifyInstance;
23
23
  //#endregion
24
- export { FastifyApp, Handler, HttpContext, Middleware };
24
+ export { FastifyApp, Handler, HttpContext, Middleware, MiddlewareFunction, NextFunction, RequestWithGetBody, RouteHandler };
File without changes
@@ -1,11 +1,48 @@
1
- import { ClassMiddleware } from "./basic.cjs";
2
- import { Middleware } from "h3";
1
+ import { ClassMiddleware, ControllerHandler } from "./basic.cjs";
2
+ import { ClearHttpContext } from "../Contracts.cjs";
3
+ import { Response as Response$1 } from "../core/Response.cjs";
4
+ import { Request } from "../core/Request.cjs";
5
+ import { EventHandlerRequest, H3, H3Event, Middleware as Middleware$1, TypedServerRequest } from "h3";
3
6
 
4
7
  //#region src/types/h3.d.ts
8
+ type H3App = Omit<H3, 'fetch'> & {
9
+ fetch: (request: TypedServerRequest<EventHandlerRequest>) => Promise<Response>;
10
+ };
11
+ type MaybePromise<T = unknown> = T | Promise<T>;
12
+ interface HttpRequest extends TypedServerRequest<EventHandlerRequest> {
13
+ getBody: () => Record<string, any>;
14
+ }
15
+ /**
16
+ * HTTP context passed to route handlers
17
+ */
18
+ interface HttpContext extends Omit<H3Event, 'req'>, ClearHttpContext {
19
+ req: HttpRequest;
20
+ clearRequest: Request;
21
+ clearResponse: Response$1;
22
+ }
23
+ /**
24
+ * Route handler function type
25
+ */
26
+ type RouteHandler = (
27
+ /**
28
+ * H3 event context
29
+ */
30
+
31
+ ctx: HttpContext,
32
+ /**
33
+ * ClearRequest instance
34
+ */
35
+
36
+ req: Request) => any | Promise<any>;
37
+ /**
38
+ * Handler can be either a function or controller reference
39
+ */
40
+ type Handler<T = any> = RouteHandler | ControllerHandler<T>;
41
+ type NextFunction = () => MaybePromise<unknown | undefined>;
5
42
  /**
6
43
  * Middleware function type
7
44
  */
8
- type MiddlewareFunction = Middleware;
9
- type Middleware$1 = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
45
+ type MiddlewareFunction = Middleware$1;
46
+ type Middleware = MiddlewareFunction | ClassMiddleware<MiddlewareFunction>;
10
47
  //#endregion
11
- export { Middleware$1 as Middleware };
48
+ export { H3App, Handler, HttpContext, HttpRequest, MaybePromise, Middleware, MiddlewareFunction, NextFunction, RouteHandler };