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
@@ -0,0 +1,129 @@
1
+ import { ApiResourceMiddleware, ControllerAction, HttpMethod } from "../types/basic.cjs";
2
+ import { FastifyApp, Handler, HttpContext, Middleware } from "../types/fastify.cjs";
3
+ import { Route } from "../Route.cjs";
4
+ import { CoreRouter } from "../core/router.cjs";
5
+
6
+ //#region src/fastify/router.d.ts
7
+ /**
8
+ * @class clear-router Fastify Router
9
+ * @description Laravel-style routing system for Fastify using shared clear-router core
10
+ * @author 3m1n3nc3
11
+ * @repository https://github.com/arkstack-tmp/clear-router
12
+ */
13
+ declare class Router extends CoreRouter {
14
+ protected static routerStateNamespace: string;
15
+ private static ensureRequestBodyAccessor;
16
+ private static sendReturnValue;
17
+ /**
18
+ * Add a route to the router
19
+ *
20
+ * @param methods HTTP methods for the route
21
+ * @param path Route path
22
+ * @param handler Route handler function
23
+ * @param middlewares Optional middlewares for the route
24
+ */
25
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
26
+ /**
27
+ * Define a resourceful API controller with standard CRUD routes
28
+ *
29
+ * @param basePath Base path for the resource
30
+ * @param controller Controller class or instance
31
+ * @param options Optional configuration for the resource
32
+ */
33
+ static apiResource(basePath: string, controller: any, options?: {
34
+ only?: ControllerAction[];
35
+ except?: ControllerAction[];
36
+ middlewares?: ApiResourceMiddleware<Middleware>;
37
+ }): void;
38
+ /**
39
+ * Define a GET route
40
+ *
41
+ * @param path
42
+ * @param handler
43
+ * @param middlewares
44
+ */
45
+ static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
46
+ /**
47
+ * Define a POST route
48
+ *
49
+ * @param path
50
+ * @param handler
51
+ * @param middlewares
52
+ */
53
+ static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
54
+ /**
55
+ * Define a PUT route
56
+ *
57
+ * @param path
58
+ * @param handler
59
+ * @param middlewares
60
+ */
61
+ static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
62
+ /**
63
+ * Define a DELETE route
64
+ *
65
+ * @param path
66
+ * @param handler
67
+ * @param middlewares
68
+ */
69
+ static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
70
+ /**
71
+ * Define a PATCH route
72
+ *
73
+ * @param path
74
+ * @param handler
75
+ * @param middlewares
76
+ */
77
+ static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
78
+ /**
79
+ * Define an OPTIONS route
80
+ *
81
+ * @param path
82
+ * @param handler
83
+ * @param middlewares
84
+ */
85
+ static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
86
+ /**
87
+ * Define a HEAD route
88
+ *
89
+ * @param path
90
+ * @param handler
91
+ * @param middlewares
92
+ */
93
+ static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
94
+ /**
95
+ * Define a group of routes with a common prefix and optional middlewares
96
+ *
97
+ * @param prefix
98
+ * @param callback
99
+ * @param middlewares
100
+ */
101
+ static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
102
+ /**
103
+ * Apply middlewares to a group of routes defined within the callback
104
+ *
105
+ * @param middlewares
106
+ * @param callback
107
+ */
108
+ static middleware(middlewares: Middleware[], callback: () => void): void;
109
+ static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
110
+ /**
111
+ * @param type - 'path' to get routes organized by path
112
+ */
113
+ static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
114
+ /**
115
+ * @param type - 'method' to get routes organized by method
116
+ */
117
+ static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
118
+ static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
119
+ static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
120
+ /**
121
+ * Apply the defined routes to a Fastify application instance
122
+ *
123
+ * @param app - The Fastify application instance
124
+ * @returns The Fastify application instance with the applied routes
125
+ */
126
+ static apply(app: FastifyApp): FastifyApp;
127
+ }
128
+ //#endregion
129
+ export { Router };
@@ -0,0 +1,129 @@
1
+ import { ApiResourceMiddleware, ControllerAction, HttpMethod } from "../types/basic.mjs";
2
+ import { FastifyApp, Handler, HttpContext, Middleware } from "../types/fastify.mjs";
3
+ import { Route } from "../Route.mjs";
4
+ import { CoreRouter } from "../core/router.mjs";
5
+
6
+ //#region src/fastify/router.d.ts
7
+ /**
8
+ * @class clear-router Fastify Router
9
+ * @description Laravel-style routing system for Fastify using shared clear-router core
10
+ * @author 3m1n3nc3
11
+ * @repository https://github.com/arkstack-tmp/clear-router
12
+ */
13
+ declare class Router extends CoreRouter {
14
+ protected static routerStateNamespace: string;
15
+ private static ensureRequestBodyAccessor;
16
+ private static sendReturnValue;
17
+ /**
18
+ * Add a route to the router
19
+ *
20
+ * @param methods HTTP methods for the route
21
+ * @param path Route path
22
+ * @param handler Route handler function
23
+ * @param middlewares Optional middlewares for the route
24
+ */
25
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
26
+ /**
27
+ * Define a resourceful API controller with standard CRUD routes
28
+ *
29
+ * @param basePath Base path for the resource
30
+ * @param controller Controller class or instance
31
+ * @param options Optional configuration for the resource
32
+ */
33
+ static apiResource(basePath: string, controller: any, options?: {
34
+ only?: ControllerAction[];
35
+ except?: ControllerAction[];
36
+ middlewares?: ApiResourceMiddleware<Middleware>;
37
+ }): void;
38
+ /**
39
+ * Define a GET route
40
+ *
41
+ * @param path
42
+ * @param handler
43
+ * @param middlewares
44
+ */
45
+ static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
46
+ /**
47
+ * Define a POST route
48
+ *
49
+ * @param path
50
+ * @param handler
51
+ * @param middlewares
52
+ */
53
+ static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
54
+ /**
55
+ * Define a PUT route
56
+ *
57
+ * @param path
58
+ * @param handler
59
+ * @param middlewares
60
+ */
61
+ static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
62
+ /**
63
+ * Define a DELETE route
64
+ *
65
+ * @param path
66
+ * @param handler
67
+ * @param middlewares
68
+ */
69
+ static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
70
+ /**
71
+ * Define a PATCH route
72
+ *
73
+ * @param path
74
+ * @param handler
75
+ * @param middlewares
76
+ */
77
+ static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
78
+ /**
79
+ * Define an OPTIONS route
80
+ *
81
+ * @param path
82
+ * @param handler
83
+ * @param middlewares
84
+ */
85
+ static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
86
+ /**
87
+ * Define a HEAD route
88
+ *
89
+ * @param path
90
+ * @param handler
91
+ * @param middlewares
92
+ */
93
+ static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): Route<HttpContext, Middleware, Handler>;
94
+ /**
95
+ * Define a group of routes with a common prefix and optional middlewares
96
+ *
97
+ * @param prefix
98
+ * @param callback
99
+ * @param middlewares
100
+ */
101
+ static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
102
+ /**
103
+ * Apply middlewares to a group of routes defined within the callback
104
+ *
105
+ * @param middlewares
106
+ * @param callback
107
+ */
108
+ static middleware(middlewares: Middleware[], callback: () => void): void;
109
+ static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
110
+ /**
111
+ * @param type - 'path' to get routes organized by path
112
+ */
113
+ static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
114
+ /**
115
+ * @param type - 'method' to get routes organized by method
116
+ */
117
+ static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
118
+ static allRoutes(type: 'name'): Record<string, Route<HttpContext, Middleware, Handler>>;
119
+ static route(name: string): Route<HttpContext, Middleware, Handler> | undefined;
120
+ /**
121
+ * Apply the defined routes to a Fastify application instance
122
+ *
123
+ * @param app - The Fastify application instance
124
+ * @returns The Fastify application instance with the applied routes
125
+ */
126
+ static apply(app: FastifyApp): FastifyApp;
127
+ }
128
+ //#endregion
129
+ export { Router };
@@ -0,0 +1,254 @@
1
+ import { CoreRouter } from "../core/router.mjs";
2
+ import { isFetchResponse, resolveResponseMeta, responseWasSent } from "../core/responses.mjs";
3
+
4
+ //#region src/fastify/router.ts
5
+ /**
6
+ * @class clear-router Fastify Router
7
+ * @description Laravel-style routing system for Fastify using shared clear-router core
8
+ * @author 3m1n3nc3
9
+ * @repository https://github.com/arkstack-tmp/clear-router
10
+ */
11
+ var Router = class Router extends CoreRouter {
12
+ static routerStateNamespace = "clear-router:fastify";
13
+ static ensureRequestBodyAccessor(req) {
14
+ if (typeof req.getBody !== "function") req.getBody = () => req.body ?? {};
15
+ }
16
+ static async sendReturnValue(req, reply, value, method, path) {
17
+ if (responseWasSent(reply) || value === reply || responseWasSent(value)) return value;
18
+ const meta = resolveResponseMeta(value, {
19
+ headers: req.headers,
20
+ method,
21
+ path
22
+ });
23
+ if (!meta) return void 0;
24
+ reply.code(meta.status);
25
+ meta.headers?.forEach((headerValue, key) => {
26
+ reply.header(key, headerValue);
27
+ });
28
+ if (isFetchResponse(meta.body)) {
29
+ meta.body.headers.forEach((headerValue, key) => {
30
+ reply.header(key, headerValue);
31
+ });
32
+ reply.code(meta.body.status);
33
+ return reply.send(Buffer.from(await meta.body.arrayBuffer()));
34
+ }
35
+ if (meta.contentType) reply.type(meta.contentType);
36
+ if (meta.isEmpty) return reply.send();
37
+ return reply.send(meta.body);
38
+ }
39
+ /**
40
+ * Add a route to the router
41
+ *
42
+ * @param methods HTTP methods for the route
43
+ * @param path Route path
44
+ * @param handler Route handler function
45
+ * @param middlewares Optional middlewares for the route
46
+ */
47
+ static add(methods, path, handler, middlewares) {
48
+ return super.add(methods, path, handler, middlewares);
49
+ }
50
+ /**
51
+ * Define a resourceful API controller with standard CRUD routes
52
+ *
53
+ * @param basePath Base path for the resource
54
+ * @param controller Controller class or instance
55
+ * @param options Optional configuration for the resource
56
+ */
57
+ static apiResource(basePath, controller, options) {
58
+ super.apiResource(basePath, controller, options);
59
+ }
60
+ /**
61
+ * Define a GET route
62
+ *
63
+ * @param path
64
+ * @param handler
65
+ * @param middlewares
66
+ */
67
+ static get(path, handler, middlewares) {
68
+ return super.get(path, handler, middlewares);
69
+ }
70
+ /**
71
+ * Define a POST route
72
+ *
73
+ * @param path
74
+ * @param handler
75
+ * @param middlewares
76
+ */
77
+ static post(path, handler, middlewares) {
78
+ return super.post(path, handler, middlewares);
79
+ }
80
+ /**
81
+ * Define a PUT route
82
+ *
83
+ * @param path
84
+ * @param handler
85
+ * @param middlewares
86
+ */
87
+ static put(path, handler, middlewares) {
88
+ return super.put(path, handler, middlewares);
89
+ }
90
+ /**
91
+ * Define a DELETE route
92
+ *
93
+ * @param path
94
+ * @param handler
95
+ * @param middlewares
96
+ */
97
+ static delete(path, handler, middlewares) {
98
+ return super.delete(path, handler, middlewares);
99
+ }
100
+ /**
101
+ * Define a PATCH route
102
+ *
103
+ * @param path
104
+ * @param handler
105
+ * @param middlewares
106
+ */
107
+ static patch(path, handler, middlewares) {
108
+ return super.patch(path, handler, middlewares);
109
+ }
110
+ /**
111
+ * Define an OPTIONS route
112
+ *
113
+ * @param path
114
+ * @param handler
115
+ * @param middlewares
116
+ */
117
+ static options(path, handler, middlewares) {
118
+ return super.options(path, handler, middlewares);
119
+ }
120
+ /**
121
+ * Define a HEAD route
122
+ *
123
+ * @param path
124
+ * @param handler
125
+ * @param middlewares
126
+ */
127
+ static head(path, handler, middlewares) {
128
+ return super.head(path, handler, middlewares);
129
+ }
130
+ /**
131
+ * Define a group of routes with a common prefix and optional middlewares
132
+ *
133
+ * @param prefix
134
+ * @param callback
135
+ * @param middlewares
136
+ */
137
+ static async group(prefix, callback, middlewares) {
138
+ await super.group(prefix, callback, middlewares);
139
+ }
140
+ /**
141
+ * Apply middlewares to a group of routes defined within the callback
142
+ *
143
+ * @param middlewares
144
+ * @param callback
145
+ */
146
+ static middleware(middlewares, callback) {
147
+ super.middleware(middlewares, callback);
148
+ }
149
+ static allRoutes(type) {
150
+ return super.allRoutes(type);
151
+ }
152
+ static route(name) {
153
+ return super.route(name);
154
+ }
155
+ /**
156
+ * Apply the defined routes to a Fastify application instance
157
+ *
158
+ * @param app - The Fastify application instance
159
+ * @returns The Fastify application instance with the applied routes
160
+ */
161
+ static apply(app) {
162
+ for (const route of Array.from(this.routes)) {
163
+ let handlerFunction = null;
164
+ let instance = null;
165
+ let bindingTarget;
166
+ let bindingMethod;
167
+ let bindingHandler;
168
+ let bindingMetadata;
169
+ try {
170
+ const resolved = this.resolveHandler(route);
171
+ handlerFunction = resolved.handlerFunction;
172
+ instance = resolved.instance;
173
+ bindingTarget = resolved.bindingTarget;
174
+ bindingMethod = resolved.bindingMethod;
175
+ bindingHandler = resolved.bindingHandler;
176
+ bindingMetadata = resolved.bindingMetadata;
177
+ } catch (error) {
178
+ console.error(`[ROUTES] Error setting up route ${route.path}:`, error.message);
179
+ throw error;
180
+ }
181
+ if (!handlerFunction) continue;
182
+ for (const method of route.methods) {
183
+ const allowedMethods = [
184
+ "get",
185
+ "post",
186
+ "put",
187
+ "delete",
188
+ "patch",
189
+ "options",
190
+ "head"
191
+ ];
192
+ if (method === "options" && route.methods.length > 1) continue;
193
+ if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
194
+ for (const registrationPath of route.registrationPaths) app.route({
195
+ method: method.toUpperCase(),
196
+ url: registrationPath,
197
+ preHandler: route.middlewares,
198
+ handler: async (req, reply) => {
199
+ Router.ensureRequestBodyAccessor(req);
200
+ const override = Router.resolveMethodOverride(req.method, req.headers, req.body);
201
+ if (method === "post" && override && override !== "post") return reply.code(404).send();
202
+ const ctx = {
203
+ req,
204
+ reply
205
+ };
206
+ const inst = instance ?? route;
207
+ Router.bindRequestToInstance(ctx, inst, route, {
208
+ body: ctx.req.getBody(),
209
+ query: ctx.req.query ?? {},
210
+ params: ctx.req.params ?? {},
211
+ method
212
+ });
213
+ const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
214
+ const resolved = await Promise.resolve(result);
215
+ const outgoing = typeof resolved === "undefined" && ctx.clearResponse?.sent ? ctx.clearResponse : resolved;
216
+ return Router.sendReturnValue(req, reply, outgoing, method, route.path);
217
+ }
218
+ });
219
+ if ([
220
+ "put",
221
+ "patch",
222
+ "delete"
223
+ ].includes(method)) for (const registrationPath of route.registrationPaths) app.route({
224
+ method: "POST",
225
+ url: registrationPath,
226
+ preHandler: route.middlewares,
227
+ handler: async (req, reply) => {
228
+ Router.ensureRequestBodyAccessor(req);
229
+ if (Router.resolveMethodOverride(req.method, req.headers, req.body) !== method) return reply.code(404).send();
230
+ const ctx = {
231
+ req,
232
+ reply
233
+ };
234
+ const inst = instance ?? route;
235
+ Router.bindRequestToInstance(ctx, inst, route, {
236
+ body: ctx.req.getBody(),
237
+ query: ctx.req.query ?? {},
238
+ params: ctx.req.params ?? {},
239
+ method
240
+ });
241
+ const result = await Router.callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata);
242
+ const resolved = await Promise.resolve(result);
243
+ const outgoing = typeof resolved === "undefined" && ctx.clearResponse?.sent ? ctx.clearResponse : resolved;
244
+ return Router.sendReturnValue(req, reply, outgoing, method, route.path);
245
+ }
246
+ });
247
+ }
248
+ }
249
+ return app;
250
+ }
251
+ };
252
+
253
+ //#endregion
254
+ export { Router as default };