clear-router 2.1.11 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,64 +1,32 @@
1
- import { c as Route, d as HttpContext, f as Middleware, i as RouterConfig, l as H3App, n as ControllerAction, r as HttpMethod, t as ApiResourceMiddleware, u as Handler } from "../basic-vvrFwa_Y.mjs";
1
+ import { c as Route, d as HttpContext, f as Middleware, i as HttpMethod, l as H3App, n as ApiResourceMiddleware, r as ControllerAction, t as CoreRouter, u as Handler } from "../router-C1jVRytA.mjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
5
5
  /**
6
- * @class clear-router
6
+ * @class clear-router H3 Router
7
7
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
8
8
  * @author 3m1n3nc3
9
9
  * @repository https://github.com/toneflix/clear-router
10
10
  */
11
- declare class Router {
12
- static config: RouterConfig;
11
+ declare class Router extends CoreRouter {
13
12
  private static readonly bodyCache;
14
- private static readonly groupContext;
15
- /**
16
- * All registered routes
17
- */
18
- static routes: Array<Route<HttpContext, Middleware>>;
19
- /**
20
- * Mapping of routes by path and method for quick lookup.
21
- */
22
- static routesByPathMethod: Record<string, Route<HttpContext, Middleware>>;
23
- /**
24
- * Mapping of routes by method for quick lookup.
25
- */
26
- static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware>> };
27
- /**
28
- * Current route prefix
29
- */
30
- static prefix: string;
31
- /**
32
- * Group-level middlewares
33
- */
34
- static groupMiddlewares: Middleware[];
35
- /**
36
- * Global-level middlewares
37
- */
38
- static globalMiddlewares: Middleware[];
39
- /**
40
- * Normalize path by removing duplicate slashes and ensuring leading slash
41
- * @param path - Path to normalize
42
- * @returns Normalized path
43
- */
44
- static normalizePath(path: string): string;
45
- static configure(options?: RouterConfig): void;
46
13
  private static readBodyCached;
47
- private static resolveMethodOverride;
48
14
  /**
49
- * Add a route with specified HTTP methods, path, handler, and middlewares
50
- * @param methods - HTTP method(s) for the route
51
- * @param path - Route path
52
- * @param handler - Route handler function or controller reference
53
- * @param middlewares - Array of middleware functions
54
- */
15
+ * Adds a new route to the router with the specified HTTP methods, path, handler, and optional middlewares.
16
+ *
17
+ * @param methods
18
+ * @param path
19
+ * @param handler
20
+ * @param middlewares
21
+ */
55
22
  static add(methods: HttpMethod | HttpMethod[], path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
56
23
  /**
57
- * Register RESTful API resource routes for a controller with optional action filtering
24
+ * Adds a new API resource route to the router for a given base path and controller, with options
25
+ * to specify included/excluded actions and middlewares.
58
26
  *
59
- * @param basePath - Base path for the resource
60
- * @param controller - Controller object containing action methods
61
- * @param options - Optional filtering options for actions
27
+ * @param basePath
28
+ * @param controller
29
+ * @param options
62
30
  */
63
31
  static apiResource(basePath: string, controller: any, options?: {
64
32
  only?: ControllerAction[];
@@ -66,83 +34,94 @@ declare class Router {
66
34
  middlewares?: ApiResourceMiddleware<Middleware>;
67
35
  }): void;
68
36
  /**
69
- * Register a GET route
70
- * @param path - Route path
71
- * @param handler - Route handler
72
- * @param middlewares - Middleware functions
37
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
38
+ *
39
+ * @param path
40
+ * @param handler
41
+ * @param middlewares
73
42
  */
74
43
  static get(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
75
44
  /**
76
- * Register a POST route
77
- * @param path - Route path
78
- * @param handler - Route handler
79
- * @param middlewares - Middleware functions
45
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
46
+ *
47
+ * @param path
48
+ * @param handler
49
+ * @param middlewares
80
50
  */
81
51
  static post(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
82
52
  /**
83
- * Register a PUT route
84
- * @param path - Route path
85
- * @param handler - Route handler
86
- * @param middlewares - Middleware functions
53
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
54
+ *
55
+ * @param path
56
+ * @param handler
57
+ * @param middlewares
87
58
  */
88
59
  static put(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
89
60
  /**
90
- * Register a DELETE route
91
- * @param path - Route path
92
- * @param handler - Route handler
93
- * @param middlewares - Middleware functions
61
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
62
+ *
63
+ * @param path
64
+ * @param handler
65
+ * @param middlewares
94
66
  */
95
67
  static delete(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
96
68
  /**
97
- * Register a PATCH route
98
- * @param path - Route path
99
- * @param handler - Route handler
100
- * @param middlewares - Middleware functions
69
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
70
+ *
71
+ * @param path
72
+ * @param handler
73
+ * @param middlewares
101
74
  */
102
75
  static patch(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
103
76
  /**
104
- * Register an OPTIONS route
105
- * @param path - Route path
106
- * @param handler - Route handler
107
- * @param middlewares - Middleware functions
77
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
78
+ *
79
+ * @param path
80
+ * @param handler
81
+ * @param middlewares
108
82
  */
109
83
  static options(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
110
84
  /**
111
- * Register a HEAD route
112
- * @param path - Route path
113
- * @param handler - Route handler
114
- * @param middlewares - Middleware functions
85
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
86
+ *
87
+ * @param path
88
+ * @param handler
89
+ * @param middlewares
115
90
  */
116
91
  static head(path: string, handler: Handler, middlewares?: Middleware[] | Middleware): void;
117
92
  /**
118
- * Group routes with a common prefix and middlewares
119
- * @param prefix - URL prefix for grouped routes
120
- * @param callback - Function containing route definitions
121
- * @param middlewares - Middleware functions applied to all routes in group
93
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
94
+ * organization and reuse of route configurations.
95
+ *
96
+ * @param prefix
97
+ * @param callback
98
+ * @param middlewares
122
99
  */
123
100
  static group(prefix: string, callback: () => void | Promise<void>, middlewares?: Middleware[]): Promise<void>;
124
101
  /**
125
- * Apply global middlewares for the duration of the callback
126
- * @param middlewares - Middleware functions
127
- * @param callback - Function containing route definitions
102
+ * Adds global middlewares to the router, which will be applied to all routes.
103
+ *
104
+ * @param middlewares
105
+ * @param callback
128
106
  */
129
107
  static middleware(middlewares: Middleware[], callback: () => void): void;
130
108
  /**
131
- * Get all registered routes with their information
132
- * @returns Array of route information objects
133
- */
134
- static allRoutes(): Array<Route<HttpContext, Middleware>>;
135
- static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware>>;
136
- static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware>> };
109
+ * Retrieves all registered routes in the router, optionally organized by path or method
110
+ * for easier access and management.
111
+ *
112
+ * @param type
113
+ */
114
+ static allRoutes(): Array<Route<HttpContext, Middleware, Handler>>;
115
+ static allRoutes(type: 'path'): Record<string, Route<HttpContext, Middleware, Handler>>;
116
+ static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<HttpContext, Middleware, Handler>> };
137
117
  /**
138
- * Apply all registered routes to the provided H3 Router instance
139
- * Handles controller-method binding and middleware application
140
- * All errors are thrown to H3 error handling middleware
118
+ * Applies the registered routes to the given H3 application instance, setting up the
119
+ * necessary handlers and middlewares for each route.
141
120
  *
142
- * @param app - H3 app instance
121
+ * @param app
122
+ * @returns
143
123
  */
144
124
  static apply(app: H3): H3App;
145
- private static bindRequestToInstance;
146
125
  }
147
126
  //#endregion
148
127
  export { Router };
package/dist/h3/index.mjs CHANGED
@@ -1,299 +1,160 @@
1
- import { n as ClearRequest, t as Route } from "../Route-BbPXcDGX.mjs";
2
- import { AsyncLocalStorage } from "node:async_hooks";
1
+ import { t as CoreRouter } from "../router-BiCuy5TZ.mjs";
3
2
  import { getQuery, getRouterParams, readBody } from "h3";
4
3
 
5
4
  //#region src/h3/router.ts
6
5
  /**
7
- * @class clear-router
6
+ * @class clear-router H3 Router
8
7
  * @description Laravel-style routing system for Express.js and H3 with support for CommonJS, ESM, and TypeScript
9
8
  * @author 3m1n3nc3
10
9
  * @repository https://github.com/toneflix/clear-router
11
10
  */
12
- var Router = class Router {
13
- static config = { methodOverride: {
14
- enabled: true,
15
- bodyKeys: ["_method"],
16
- headerKeys: ["x-http-method"]
17
- } };
11
+ var Router = class Router extends CoreRouter {
18
12
  static bodyCache = /* @__PURE__ */ new WeakMap();
19
- static groupContext = new AsyncLocalStorage();
20
- /**
21
- * All registered routes
22
- */
23
- static routes = [];
24
- /**
25
- * Mapping of routes by path and method for quick lookup.
26
- */
27
- static routesByPathMethod = {};
28
- /**
29
- * Mapping of routes by method for quick lookup.
30
- */
31
- static routesByMethod = {};
32
- /**
33
- * Current route prefix
34
- */
35
- static prefix = "";
36
- /**
37
- * Group-level middlewares
38
- */
39
- static groupMiddlewares = [];
40
- /**
41
- * Global-level middlewares
42
- */
43
- static globalMiddlewares = [];
44
- /**
45
- * Normalize path by removing duplicate slashes and ensuring leading slash
46
- * @param path - Path to normalize
47
- * @returns Normalized path
48
- */
49
- static normalizePath(path) {
50
- return "/" + path.split("/").filter(Boolean).join("/");
51
- }
52
- static configure(options) {
53
- if (!this.config.methodOverride) this.config.methodOverride = {
54
- enabled: true,
55
- bodyKeys: ["_method"],
56
- headerKeys: ["x-http-method"]
57
- };
58
- const override = options?.methodOverride;
59
- if (!override) return;
60
- if (typeof override.enabled === "boolean") this.config.methodOverride.enabled = override.enabled;
61
- const bodyKeys = override.bodyKeys;
62
- if (typeof bodyKeys !== "undefined") this.config.methodOverride.bodyKeys = (Array.isArray(bodyKeys) ? bodyKeys : [bodyKeys]).map((e) => String(e).trim()).filter(Boolean);
63
- const headerKeys = override.headerKeys;
64
- if (typeof headerKeys !== "undefined") this.config.methodOverride.headerKeys = (Array.isArray(headerKeys) ? headerKeys : [headerKeys]).map((e) => String(e).trim().toLowerCase()).filter(Boolean);
65
- }
66
13
  static async readBodyCached(ctx) {
67
- if (this.bodyCache.has(ctx)) return this.bodyCache.get(ctx);
68
- const body = await readBody(ctx) ?? {};
14
+ if (this.bodyCache.has(ctx)) {
15
+ const cached = this.bodyCache.get(ctx);
16
+ ctx.req.getBody = () => cached;
17
+ return cached;
18
+ }
19
+ let body = {};
20
+ if (ctx.req.headers.get("content-type")?.includes("multipart/form-data")) (await ctx.req.formData()).forEach((value, key) => {
21
+ body[key] = value;
22
+ });
23
+ else body = await readBody(ctx) ?? {};
24
+ ctx.req.getBody = () => body;
69
25
  this.bodyCache.set(ctx, body);
70
26
  return body;
71
27
  }
72
- static resolveMethodOverride(method, headers, body) {
73
- if (!this.config.methodOverride?.enabled || method.toLowerCase() !== "post") return null;
74
- let override;
75
- for (const key of this.config.methodOverride?.headerKeys || []) {
76
- const value = headers.get(key);
77
- if (value) {
78
- override = value;
79
- break;
80
- }
81
- }
82
- if (!override && body && typeof body === "object") for (const key of this.config.methodOverride?.bodyKeys || []) {
83
- const value = body[key];
84
- if (typeof value !== "undefined" && value !== null && value !== "") {
85
- override = value;
86
- break;
87
- }
88
- }
89
- const normalized = String(override || "").trim().toLowerCase();
90
- if (!normalized) return null;
91
- if ([
92
- "put",
93
- "patch",
94
- "delete",
95
- "post"
96
- ].includes(normalized)) return normalized;
97
- return null;
98
- }
99
28
  /**
100
- * Add a route with specified HTTP methods, path, handler, and middlewares
101
- * @param methods - HTTP method(s) for the route
102
- * @param path - Route path
103
- * @param handler - Route handler function or controller reference
104
- * @param middlewares - Array of middleware functions
29
+ * Adds a new route to the router with the specified HTTP methods, path, handler, and optional middlewares.
30
+ *
31
+ * @param methods
32
+ * @param path
33
+ * @param handler
34
+ * @param middlewares
105
35
  */
106
36
  static add(methods, path, handler, middlewares) {
107
- const context = this.groupContext.getStore();
108
- const activePrefix = context?.prefix ?? this.prefix;
109
- const activeGroupMiddlewares = context?.groupMiddlewares ?? this.groupMiddlewares;
110
- methods = Array.isArray(methods) ? methods : [methods];
111
- middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
112
- const fullPath = this.normalizePath(`${activePrefix}/${path}`);
113
- const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
114
- ...this.globalMiddlewares,
115
- ...activeGroupMiddlewares,
116
- ...middlewares || []
117
- ]);
118
- if (!methods.includes("options") && !this.routesByPathMethod[`OPTIONS ${fullPath}`]) this.options(path, ({ res }) => {
119
- res.headers.set("Allow", "GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD");
120
- res.status = 204;
121
- });
122
- this.routes.push(route);
123
- for (const method of methods.map((m) => m.toUpperCase())) {
124
- this.routesByPathMethod[`${method} ${fullPath}`] = route;
125
- if (!this.routesByMethod[method]) this.routesByMethod[method] = [];
126
- this.routesByMethod[method].push(route);
127
- }
37
+ super.add(methods, path, handler, middlewares);
128
38
  }
129
39
  /**
130
- * Register RESTful API resource routes for a controller with optional action filtering
40
+ * Adds a new API resource route to the router for a given base path and controller, with options
41
+ * to specify included/excluded actions and middlewares.
131
42
  *
132
- * @param basePath - Base path for the resource
133
- * @param controller - Controller object containing action methods
134
- * @param options - Optional filtering options for actions
43
+ * @param basePath
44
+ * @param controller
45
+ * @param options
135
46
  */
136
47
  static apiResource(basePath, controller, options) {
137
- const actions = {
138
- index: {
139
- method: "get",
140
- path: "/"
141
- },
142
- show: {
143
- method: "get",
144
- path: "/:id"
145
- },
146
- create: {
147
- method: "post",
148
- path: "/"
149
- },
150
- update: {
151
- method: "put",
152
- path: "/:id"
153
- },
154
- destroy: {
155
- method: "delete",
156
- path: "/:id"
157
- }
158
- };
159
- const only = options?.only || Object.keys(actions);
160
- const except = options?.except || [];
161
- const preController = typeof controller === "function" ? new controller() : controller;
162
- for (const action of only) {
163
- if (except.includes(action)) continue;
164
- if (typeof preController[action] === "function") {
165
- const { method, path } = actions[action];
166
- const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
167
- this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0);
168
- }
169
- }
48
+ super.apiResource(basePath, controller, options);
170
49
  }
171
50
  /**
172
- * Register a GET route
173
- * @param path - Route path
174
- * @param handler - Route handler
175
- * @param middlewares - Middleware functions
51
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
52
+ *
53
+ * @param path
54
+ * @param handler
55
+ * @param middlewares
176
56
  */
177
57
  static get(path, handler, middlewares) {
178
- this.add("get", path, handler, middlewares);
58
+ super.get(path, handler, middlewares);
179
59
  }
180
60
  /**
181
- * Register a POST route
182
- * @param path - Route path
183
- * @param handler - Route handler
184
- * @param middlewares - Middleware functions
61
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
62
+ *
63
+ * @param path
64
+ * @param handler
65
+ * @param middlewares
185
66
  */
186
67
  static post(path, handler, middlewares) {
187
- this.add("post", path, handler, middlewares);
68
+ super.post(path, handler, middlewares);
188
69
  }
189
70
  /**
190
- * Register a PUT route
191
- * @param path - Route path
192
- * @param handler - Route handler
193
- * @param middlewares - Middleware functions
71
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
72
+ *
73
+ * @param path
74
+ * @param handler
75
+ * @param middlewares
194
76
  */
195
77
  static put(path, handler, middlewares) {
196
- this.add("put", path, handler, middlewares);
78
+ super.put(path, handler, middlewares);
197
79
  }
198
80
  /**
199
- * Register a DELETE route
200
- * @param path - Route path
201
- * @param handler - Route handler
202
- * @param middlewares - Middleware functions
81
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
82
+ *
83
+ * @param path
84
+ * @param handler
85
+ * @param middlewares
203
86
  */
204
87
  static delete(path, handler, middlewares) {
205
- this.add("delete", path, handler, middlewares);
88
+ super.delete(path, handler, middlewares);
206
89
  }
207
90
  /**
208
- * Register a PATCH route
209
- * @param path - Route path
210
- * @param handler - Route handler
211
- * @param middlewares - Middleware functions
91
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
92
+ *
93
+ * @param path
94
+ * @param handler
95
+ * @param middlewares
212
96
  */
213
97
  static patch(path, handler, middlewares) {
214
- this.add("patch", path, handler, middlewares);
98
+ super.patch(path, handler, middlewares);
215
99
  }
216
100
  /**
217
- * Register an OPTIONS route
218
- * @param path - Route path
219
- * @param handler - Route handler
220
- * @param middlewares - Middleware functions
101
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
102
+ *
103
+ * @param path
104
+ * @param handler
105
+ * @param middlewares
221
106
  */
222
107
  static options(path, handler, middlewares) {
223
- this.add("options", path, handler, middlewares);
108
+ super.options(path, handler, middlewares);
224
109
  }
225
110
  /**
226
- * Register a HEAD route
227
- * @param path - Route path
228
- * @param handler - Route handler
229
- * @param middlewares - Middleware functions
111
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
112
+ *
113
+ * @param path
114
+ * @param handler
115
+ * @param middlewares
230
116
  */
231
117
  static head(path, handler, middlewares) {
232
- this.add("head", path, handler, middlewares);
118
+ super.head(path, handler, middlewares);
233
119
  }
234
120
  /**
235
- * Group routes with a common prefix and middlewares
236
- * @param prefix - URL prefix for grouped routes
237
- * @param callback - Function containing route definitions
238
- * @param middlewares - Middleware functions applied to all routes in group
121
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
122
+ * organization and reuse of route configurations.
123
+ *
124
+ * @param prefix
125
+ * @param callback
126
+ * @param middlewares
239
127
  */
240
128
  static async group(prefix, callback, middlewares) {
241
- const context = this.groupContext.getStore();
242
- const previousPrefix = context?.prefix ?? this.prefix;
243
- const previousMiddlewares = context?.groupMiddlewares ?? this.groupMiddlewares;
244
- const fullPrefix = [previousPrefix, prefix].filter(Boolean).join("/");
245
- const nextContext = {
246
- prefix: this.normalizePath(fullPrefix),
247
- groupMiddlewares: [...previousMiddlewares, ...middlewares || []]
248
- };
249
- await this.groupContext.run(nextContext, async () => {
250
- await Promise.resolve(callback());
251
- });
129
+ await super.group(prefix, callback, middlewares);
252
130
  }
253
131
  /**
254
- * Apply global middlewares for the duration of the callback
255
- * @param middlewares - Middleware functions
256
- * @param callback - Function containing route definitions
132
+ * Adds global middlewares to the router, which will be applied to all routes.
133
+ *
134
+ * @param middlewares
135
+ * @param callback
257
136
  */
258
137
  static middleware(middlewares, callback) {
259
- const prevMiddlewares = this.globalMiddlewares;
260
- this.globalMiddlewares = [...prevMiddlewares, ...middlewares || []];
261
- callback();
262
- this.globalMiddlewares = prevMiddlewares;
138
+ super.middleware(middlewares, callback);
263
139
  }
264
140
  static allRoutes(type) {
265
- if (type === "method") return this.routesByMethod;
266
- if (type === "path") return this.routesByPathMethod;
267
- return this.routes.filter((e) => e.methods.length > 1 || e.methods[0] !== "options");
141
+ return super.allRoutes(type);
268
142
  }
269
143
  /**
270
- * Apply all registered routes to the provided H3 Router instance
271
- * Handles controller-method binding and middleware application
272
- * All errors are thrown to H3 error handling middleware
144
+ * Applies the registered routes to the given H3 application instance, setting up the
145
+ * necessary handlers and middlewares for each route.
273
146
  *
274
- * @param app - H3 app instance
147
+ * @param app
148
+ * @returns
275
149
  */
276
150
  static apply(app) {
277
151
  for (const route of this.routes) {
278
152
  let handlerFunction = null;
279
153
  let instance = null;
280
154
  try {
281
- if (typeof route.handler === "function")
282
- /**
283
- * Since we do not have a controller instance, we will call the handler function directly and the route instance will be the this argument. This allows for both controller-based and function-based handlers to work seamlessly.
284
- */
285
- handlerFunction = route.handler.bind(route);
286
- else if (Array.isArray(route.handler) && route.handler.length === 2) {
287
- const [Controller, method] = route.handler;
288
- if (["function", "object"].includes(typeof Controller) && typeof Controller[method] === "function") {
289
- instance = Controller;
290
- handlerFunction = Controller[method].bind(Controller);
291
- } else if (typeof Controller === "function") {
292
- instance = new Controller();
293
- if (typeof instance[method] === "function") handlerFunction = instance[method].bind(instance);
294
- else throw new Error(`Method "${method}" not found in controller instance "${Controller.name}"`);
295
- } else throw new Error(`Invalid controller type for route: ${route.path}`);
296
- } else throw new Error(`Invalid handler format for route: ${route.path}`);
155
+ const resolved = this.resolveHandler(route);
156
+ handlerFunction = resolved.handlerFunction;
157
+ instance = resolved.instance;
297
158
  } catch (error) {
298
159
  console.error(`[ROUTES] Error setting up route ${route.path}:`, error.message);
299
160
  throw error;
@@ -322,7 +183,11 @@ var Router = class Router {
322
183
  const override = Router.resolveMethodOverride(ctx.req.method, ctx.req.headers, reqBody);
323
184
  if (method === "post" && override && override !== "post") return;
324
185
  const inst = instance ?? route;
325
- await Router.bindRequestToInstance(ctx, inst, route, reqBody);
186
+ Router.bindRequestToInstance(ctx, inst, route, {
187
+ body: reqBody,
188
+ query: getQuery(ctx),
189
+ params: getRouterParams(ctx, { decode: true })
190
+ });
326
191
  const result = handlerFunction(ctx, inst.clearRequest);
327
192
  return await Promise.resolve(result);
328
193
  } catch (error) {
@@ -339,7 +204,11 @@ var Router = class Router {
339
204
  const reqBody = await Router.readBodyCached(ctx);
340
205
  if (Router.resolveMethodOverride(ctx.req.method, ctx.req.headers, reqBody) !== method) return;
341
206
  const inst = instance ?? route;
342
- await Router.bindRequestToInstance(ctx, inst, route, reqBody);
207
+ Router.bindRequestToInstance(ctx, inst, route, {
208
+ body: reqBody,
209
+ query: getQuery(ctx),
210
+ params: getRouterParams(ctx, { decode: true })
211
+ });
343
212
  const result = handlerFunction(ctx, inst.clearRequest);
344
213
  return await Promise.resolve(result);
345
214
  } catch (error) {
@@ -350,20 +219,6 @@ var Router = class Router {
350
219
  }
351
220
  return app;
352
221
  }
353
- static async bindRequestToInstance(ctx, instance, route, body) {
354
- if (!instance) return;
355
- instance.ctx = ctx;
356
- instance.body = body ?? await Router.readBodyCached(ctx);
357
- instance.query = getQuery(ctx);
358
- instance.params = getRouterParams(ctx, { decode: true });
359
- instance.clearRequest = new ClearRequest({
360
- ctx,
361
- route,
362
- body: instance.body,
363
- query: instance.query,
364
- params: instance.params
365
- });
366
- }
367
222
  };
368
223
 
369
224
  //#endregion