clear-router 2.1.12 → 2.3.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.
Files changed (43) hide show
  1. package/README.md +4 -4
  2. package/dist/core/index.cjs +4 -0
  3. package/dist/core/index.d.cts +2 -0
  4. package/dist/core/index.d.mts +2 -0
  5. package/dist/core/index.mjs +3 -0
  6. package/dist/express/index.cjs +86 -247
  7. package/dist/express/index.d.cts +68 -97
  8. package/dist/express/index.d.mts +68 -97
  9. package/dist/express/index.mjs +86 -247
  10. package/dist/fastify/index.cjs +213 -0
  11. package/dist/fastify/index.d.cts +137 -0
  12. package/dist/fastify/index.d.mts +137 -0
  13. package/dist/fastify/index.mjs +212 -0
  14. package/dist/h3/index.cjs +88 -242
  15. package/dist/h3/index.d.cts +72 -93
  16. package/dist/h3/index.d.mts +72 -93
  17. package/dist/h3/index.mjs +88 -242
  18. package/dist/hono/index.cjs +227 -0
  19. package/dist/hono/index.d.cts +141 -0
  20. package/dist/hono/index.d.mts +141 -0
  21. package/dist/hono/index.mjs +226 -0
  22. package/dist/index.cjs +357 -0
  23. package/dist/index.d.cts +195 -40
  24. package/dist/index.d.mts +195 -40
  25. package/dist/index.mjs +358 -1
  26. package/dist/router-Ba2MVNn-.cjs +412 -0
  27. package/dist/router-Bug2IE_u.mjs +407 -0
  28. package/dist/router-DLmimm_U.d.cts +320 -0
  29. package/dist/router-cWYmcfTX.d.mts +320 -0
  30. package/dist/types/ClearRequest.d.mts +1 -1
  31. package/dist/types/Route.d.mts +5 -5
  32. package/dist/types/basic.d.mts +1 -4
  33. package/dist/types/express.d.mts +1 -1
  34. package/dist/types/fastify.d.mts +19 -0
  35. package/dist/types/fastify.mjs +1 -0
  36. package/dist/types/h3.d.mts +1 -1
  37. package/dist/types/hono.d.mts +18 -0
  38. package/dist/types/hono.mjs +1 -0
  39. package/package.json +26 -2
  40. package/dist/Route-BbPXcDGX.mjs +0 -50
  41. package/dist/Route-DhC4kNPX.cjs +0 -62
  42. package/dist/basic-C_1O6RVq.d.cts +0 -138
  43. package/dist/basic-cLeny2Zk.d.mts +0 -138
@@ -0,0 +1,226 @@
1
+ import { t as CoreRouter } from "../router-Bug2IE_u.mjs";
2
+
3
+ //#region src/hono/router.ts
4
+ /**
5
+ * @class clear-router Hono Router
6
+ * @description Laravel-style routing system for Hono using shared clear-router core
7
+ * @author 3m1n3nc3
8
+ * @repository https://github.com/toneflix/clear-router
9
+ */
10
+ var Router = class Router extends CoreRouter {
11
+ static bodyCache = /* @__PURE__ */ new WeakMap();
12
+ static toResponse(ctx, value) {
13
+ if (value instanceof Response) return value;
14
+ if (typeof value === "undefined") return void 0;
15
+ if (value === null) return ctx.body(null);
16
+ if (typeof value === "string") return ctx.text(value);
17
+ if (typeof value === "object") return ctx.json(value);
18
+ return ctx.text(String(value));
19
+ }
20
+ static getParams(ctx) {
21
+ try {
22
+ const raw = ctx.req.param?.();
23
+ return raw && typeof raw === "object" ? raw : {};
24
+ } catch {
25
+ return {};
26
+ }
27
+ }
28
+ static async readBodyCached(ctx) {
29
+ if (this.bodyCache.has(ctx)) {
30
+ const cached = this.bodyCache.get(ctx) || {};
31
+ ctx.req.getBody = () => cached;
32
+ return cached;
33
+ }
34
+ let body = {};
35
+ const contentType = (ctx.req.header("content-type") || "").toLowerCase();
36
+ if (contentType.includes("application/json")) body = await ctx.req.json().catch(() => ({}));
37
+ else if (contentType.includes("multipart/form-data") || contentType.includes("application/x-www-form-urlencoded")) body = await ctx.req.parseBody().then((v) => v).catch(() => ({}));
38
+ ctx.req.getBody = () => body;
39
+ this.bodyCache.set(ctx, body);
40
+ return body;
41
+ }
42
+ /**
43
+ * Resolve method override from query, headers, or body
44
+ *
45
+ * @param methods
46
+ * @param path
47
+ * @param handler
48
+ * @param middlewares
49
+ */
50
+ static add(methods, path, handler, middlewares) {
51
+ super.add(methods, path, handler, middlewares);
52
+ }
53
+ /**
54
+ * Define a resourceful API controller with standard CRUD routes
55
+ *
56
+ * @param basePath
57
+ * @param controller
58
+ * @param options
59
+ */
60
+ static apiResource(basePath, controller, options) {
61
+ super.apiResource(basePath, controller, options);
62
+ }
63
+ /**
64
+ * Define a GET route
65
+ *
66
+ * @param path
67
+ * @param handler
68
+ * @param middlewares
69
+ */
70
+ static get(path, handler, middlewares) {
71
+ super.get(path, handler, middlewares);
72
+ }
73
+ /**
74
+ * Define a POST route
75
+ *
76
+ * @param path
77
+ * @param handler
78
+ * @param middlewares
79
+ */
80
+ static post(path, handler, middlewares) {
81
+ super.post(path, handler, middlewares);
82
+ }
83
+ /**
84
+ * Define a PUT route
85
+ *
86
+ * @param path
87
+ * @param handler
88
+ * @param middlewares
89
+ */
90
+ static put(path, handler, middlewares) {
91
+ super.put(path, handler, middlewares);
92
+ }
93
+ /**
94
+ * Define a DELETE route
95
+ *
96
+ * @param path
97
+ * @param handler
98
+ * @param middlewares
99
+ */
100
+ static delete(path, handler, middlewares) {
101
+ super.delete(path, handler, middlewares);
102
+ }
103
+ /**
104
+ * Define a PATCH route
105
+ *
106
+ * @param path
107
+ * @param handler
108
+ * @param middlewares
109
+ */
110
+ static patch(path, handler, middlewares) {
111
+ super.patch(path, handler, middlewares);
112
+ }
113
+ /**
114
+ * Define an OPTIONS route
115
+ *
116
+ * @param path
117
+ * @param handler
118
+ * @param middlewares
119
+ */
120
+ static options(path, handler, middlewares) {
121
+ super.options(path, handler, middlewares);
122
+ }
123
+ /**
124
+ * Define a HEAD route
125
+ *
126
+ * @param path
127
+ * @param handler
128
+ * @param middlewares
129
+ */
130
+ static head(path, handler, middlewares) {
131
+ super.head(path, handler, middlewares);
132
+ }
133
+ /**
134
+ * Define a group of routes with a common prefix and optional middlewares
135
+ *
136
+ * @param prefix
137
+ * @param callback
138
+ * @param middlewares
139
+ */
140
+ static async group(prefix, callback, middlewares) {
141
+ await super.group(prefix, callback, middlewares);
142
+ }
143
+ /**
144
+ * Apply middlewares to a group of routes defined within the callback
145
+ *
146
+ * @param middlewares - Middleware or array of middlewares to apply
147
+ * @param callback - Function that defines the routes to which the middlewares will be applied
148
+ */
149
+ static middleware(middlewares, callback) {
150
+ super.middleware(middlewares, callback);
151
+ }
152
+ static allRoutes(type) {
153
+ return super.allRoutes(type);
154
+ }
155
+ /**
156
+ * Apply the defined routes to a Hono application instance
157
+ *
158
+ * @param app The Hono application instance
159
+ * @returns The Hono application instance with the applied routes
160
+ */
161
+ static apply(app) {
162
+ for (const route of this.routes) {
163
+ let handlerFunction = null;
164
+ let instance = null;
165
+ try {
166
+ const resolved = this.resolveHandler(route);
167
+ handlerFunction = resolved.handlerFunction;
168
+ instance = resolved.instance;
169
+ } catch (error) {
170
+ console.error(`[ROUTES] Error setting up route ${route.path}:`, error.message);
171
+ throw error;
172
+ }
173
+ if (!handlerFunction) continue;
174
+ for (const method of route.methods) {
175
+ const allowedMethods = [
176
+ "get",
177
+ "post",
178
+ "put",
179
+ "delete",
180
+ "patch",
181
+ "options",
182
+ "head"
183
+ ];
184
+ if (method === "options" && route.methods.length > 1) continue;
185
+ if (!allowedMethods.includes(method)) throw new Error(`Invalid HTTP method: ${method} for route: ${route.path}`);
186
+ app[method](route.path, ...route.middlewares || [], async (context) => {
187
+ const ctx = context;
188
+ const reqBody = await Router.readBodyCached(ctx);
189
+ const override = Router.resolveMethodOverride(ctx.req.method, ctx.req.header(), reqBody);
190
+ if (method === "post" && override && override !== "post") return;
191
+ const inst = instance ?? route;
192
+ Router.bindRequestToInstance(ctx, inst, route, {
193
+ body: reqBody,
194
+ query: ctx.req.query(),
195
+ params: Router.getParams(ctx)
196
+ });
197
+ const result = handlerFunction(ctx, inst.clearRequest);
198
+ const resolved = await Promise.resolve(result);
199
+ return Router.toResponse(ctx, resolved);
200
+ });
201
+ if ([
202
+ "put",
203
+ "patch",
204
+ "delete"
205
+ ].includes(method)) app.post(route.path, ...route.middlewares || [], async (context) => {
206
+ const ctx = context;
207
+ const reqBody = await Router.readBodyCached(ctx);
208
+ if (Router.resolveMethodOverride(ctx.req.method, ctx.req.header(), reqBody) !== method) return;
209
+ const inst = instance ?? route;
210
+ Router.bindRequestToInstance(ctx, inst, route, {
211
+ body: reqBody,
212
+ query: ctx.req.query(),
213
+ params: Router.getParams(ctx)
214
+ });
215
+ const result = handlerFunction(ctx, inst.clearRequest);
216
+ const resolved = await Promise.resolve(result);
217
+ return Router.toResponse(ctx, resolved);
218
+ });
219
+ }
220
+ }
221
+ return app;
222
+ }
223
+ };
224
+
225
+ //#endregion
226
+ export { Router };
package/dist/index.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let node_async_hooks = require("node:async_hooks");
2
3
 
3
4
  //#region src/ClearRequest.ts
4
5
  var ClearRequest = class {
@@ -58,7 +59,363 @@ var Route = class {
58
59
  }
59
60
  };
60
61
 
62
+ //#endregion
63
+ //#region src/core/router.ts
64
+ /**
65
+ * @class clear-router CoreRouter
66
+ * @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
67
+ * @author 3m1n3nc3
68
+ * @repository https://github.com/toneflix/clear-router
69
+ */
70
+ var CoreRouter = class {
71
+ static createDefaultOptionsHandler() {
72
+ return (ctx) => {
73
+ const allow = "GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD";
74
+ if (ctx?.header && ctx?.status && ctx?.body) {
75
+ ctx.header("Allow", allow);
76
+ ctx.status(204);
77
+ return ctx.body(null);
78
+ }
79
+ if (ctx?.res?.headers?.set) {
80
+ ctx.res.headers.set("Allow", allow);
81
+ ctx.res.status = 204;
82
+ return;
83
+ }
84
+ if (ctx?.res?.set) {
85
+ ctx.res.set("Allow", allow);
86
+ ctx.res.sendStatus(204);
87
+ return;
88
+ }
89
+ if (ctx?.reply?.header) {
90
+ ctx.reply.header("Allow", allow);
91
+ ctx.reply.code(204).send();
92
+ return;
93
+ }
94
+ };
95
+ }
96
+ static config = { methodOverride: {
97
+ enabled: true,
98
+ bodyKeys: ["_method"],
99
+ headerKeys: ["x-http-method"]
100
+ } };
101
+ static groupContext = new node_async_hooks.AsyncLocalStorage();
102
+ static routes = [];
103
+ static routesByPathMethod = {};
104
+ static routesByMethod = {};
105
+ static prefix = "";
106
+ static groupMiddlewares = [];
107
+ static globalMiddlewares = [];
108
+ static ensureState() {
109
+ if (!Object.prototype.hasOwnProperty.call(this, "config")) this.config = { methodOverride: {
110
+ enabled: true,
111
+ bodyKeys: ["_method"],
112
+ headerKeys: ["x-http-method"]
113
+ } };
114
+ if (!Object.prototype.hasOwnProperty.call(this, "groupContext")) this.groupContext = new node_async_hooks.AsyncLocalStorage();
115
+ if (!Object.prototype.hasOwnProperty.call(this, "routes")) this.routes = [];
116
+ if (!Object.prototype.hasOwnProperty.call(this, "routesByPathMethod")) this.routesByPathMethod = {};
117
+ if (!Object.prototype.hasOwnProperty.call(this, "routesByMethod")) this.routesByMethod = {};
118
+ if (!Object.prototype.hasOwnProperty.call(this, "prefix")) this.prefix = "";
119
+ if (!Object.prototype.hasOwnProperty.call(this, "groupMiddlewares")) this.groupMiddlewares = [];
120
+ if (!Object.prototype.hasOwnProperty.call(this, "globalMiddlewares")) this.globalMiddlewares = [];
121
+ }
122
+ /**
123
+ * Normalizes a path by ensuring it starts with a single slash and does not have trailing
124
+ * slashes, while preserving dynamic segments and parameters.
125
+ *
126
+ * @param path The path to normalize.
127
+ * @returns The normalized path.
128
+ */
129
+ static normalizePath(path) {
130
+ return "/" + path.split("/").filter(Boolean).join("/");
131
+ }
132
+ /**
133
+ * Configures the router with the given options, such as method override settings.
134
+ *
135
+ * @param this
136
+ * @param options
137
+ * @returns
138
+ */
139
+ static configure(options) {
140
+ this.ensureState();
141
+ if (!this.config.methodOverride) this.config.methodOverride = {
142
+ enabled: true,
143
+ bodyKeys: ["_method"],
144
+ headerKeys: ["x-http-method"]
145
+ };
146
+ const override = options?.methodOverride;
147
+ if (!override) return;
148
+ if (typeof override.enabled === "boolean") this.config.methodOverride.enabled = override.enabled;
149
+ const bodyKeys = override.bodyKeys;
150
+ if (typeof bodyKeys !== "undefined") this.config.methodOverride.bodyKeys = (Array.isArray(bodyKeys) ? bodyKeys : [bodyKeys]).map((e) => String(e).trim()).filter(Boolean);
151
+ const headerKeys = override.headerKeys;
152
+ if (typeof headerKeys !== "undefined") this.config.methodOverride.headerKeys = (Array.isArray(headerKeys) ? headerKeys : [headerKeys]).map((e) => String(e).trim().toLowerCase()).filter(Boolean);
153
+ }
154
+ static resolveMethodOverride(method, headers, body) {
155
+ this.ensureState();
156
+ if (!this.config.methodOverride?.enabled || method.toLowerCase() !== "post") return null;
157
+ let override;
158
+ const headerValueFor = (key) => {
159
+ if (typeof headers.get === "function") return headers.get(key);
160
+ const value = headers?.[key];
161
+ return Array.isArray(value) ? value[0] : value;
162
+ };
163
+ for (const key of this.config.methodOverride?.headerKeys || []) {
164
+ const value = headerValueFor(key);
165
+ if (value) {
166
+ override = value;
167
+ break;
168
+ }
169
+ }
170
+ if (!override && body && typeof body === "object") for (const key of this.config.methodOverride?.bodyKeys || []) {
171
+ const value = body[key];
172
+ if (typeof value !== "undefined" && value !== null && value !== "") {
173
+ override = value;
174
+ break;
175
+ }
176
+ }
177
+ const normalized = String(override || "").trim().toLowerCase();
178
+ if (!normalized) return null;
179
+ if ([
180
+ "put",
181
+ "patch",
182
+ "delete",
183
+ "post"
184
+ ].includes(normalized)) return normalized;
185
+ return null;
186
+ }
187
+ /**
188
+ * Adds a new route to the router with the specified methods, path, handler, and middlewares.
189
+ *
190
+ * @param this
191
+ * @param methods
192
+ * @param path
193
+ * @param handler
194
+ * @param middlewares
195
+ */
196
+ static add(methods, path, handler, middlewares) {
197
+ this.ensureState();
198
+ const context = this.groupContext.getStore();
199
+ const activePrefix = context?.prefix ?? this.prefix;
200
+ const activeGroupMiddlewares = context?.groupMiddlewares ?? this.groupMiddlewares;
201
+ methods = Array.isArray(methods) ? methods : [methods];
202
+ middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
203
+ const fullPath = this.normalizePath(`${activePrefix}/${path}`);
204
+ const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, [
205
+ ...this.globalMiddlewares,
206
+ ...activeGroupMiddlewares,
207
+ ...middlewares || []
208
+ ]);
209
+ if (!methods.includes("options") && !this.routesByPathMethod[`OPTIONS ${fullPath}`]) this.options(path, this.createDefaultOptionsHandler());
210
+ this.routes.push(route);
211
+ for (const method of methods.map((m) => m.toUpperCase())) {
212
+ this.routesByPathMethod[`${method} ${fullPath}`] = route;
213
+ if (!this.routesByMethod[method]) this.routesByMethod[method] = [];
214
+ this.routesByMethod[method].push(route);
215
+ }
216
+ }
217
+ /**
218
+ * Adds a new API resource route to the router for the specified base path and controller, with
219
+ * options to include/exclude specific actions and apply middlewares.
220
+ *
221
+ * @param this
222
+ * @param basePath
223
+ * @param controller
224
+ * @param options
225
+ */
226
+ static apiResource(basePath, controller, options) {
227
+ const actions = {
228
+ index: {
229
+ method: "get",
230
+ path: "/"
231
+ },
232
+ show: {
233
+ method: "get",
234
+ path: "/:id"
235
+ },
236
+ create: {
237
+ method: "post",
238
+ path: "/"
239
+ },
240
+ update: {
241
+ method: "put",
242
+ path: "/:id"
243
+ },
244
+ destroy: {
245
+ method: "delete",
246
+ path: "/:id"
247
+ }
248
+ };
249
+ const only = options?.only || Object.keys(actions);
250
+ const except = options?.except || [];
251
+ const preController = typeof controller === "function" ? new controller() : controller;
252
+ for (const action of only) {
253
+ if (except.includes(action)) continue;
254
+ if (typeof preController[action] === "function") {
255
+ const { method, path } = actions[action];
256
+ const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
257
+ this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0);
258
+ }
259
+ }
260
+ }
261
+ /**
262
+ * Adds a new GET route to the router with the specified path, handler, and optional middlewares.
263
+ *
264
+ * @param this The router instance.
265
+ * @param path The path for the GET route.
266
+ * @param handler The handler function for the GET route.
267
+ * @param middlewares Optional middlewares to apply to the GET route.
268
+ */
269
+ static get(path, handler, middlewares) {
270
+ this.add("get", path, handler, middlewares);
271
+ }
272
+ /**
273
+ * Adds a new POST route to the router with the specified path, handler, and optional middlewares.
274
+ *
275
+ * @param this
276
+ * @param path
277
+ * @param handler
278
+ * @param middlewares
279
+ */
280
+ static post(path, handler, middlewares) {
281
+ this.add("post", path, handler, middlewares);
282
+ }
283
+ /**
284
+ * Adds a new PUT route to the router with the specified path, handler, and optional middlewares.
285
+ *
286
+ * @param this
287
+ * @param path
288
+ * @param handler
289
+ * @param middlewares
290
+ */
291
+ static put(path, handler, middlewares) {
292
+ this.add("put", path, handler, middlewares);
293
+ }
294
+ /**
295
+ * Adds a new DELETE route to the router with the specified path, handler, and optional middlewares.
296
+ *
297
+ * @param this
298
+ * @param path
299
+ * @param handler
300
+ * @param middlewares
301
+ */
302
+ static delete(path, handler, middlewares) {
303
+ this.add("delete", path, handler, middlewares);
304
+ }
305
+ /**
306
+ * Adds a new PATCH route to the router with the specified path, handler, and optional middlewares.
307
+ *
308
+ * @param this
309
+ * @param path
310
+ * @param handler
311
+ * @param middlewares
312
+ */
313
+ static patch(path, handler, middlewares) {
314
+ this.add("patch", path, handler, middlewares);
315
+ }
316
+ /**
317
+ * Adds a new OPTIONS route to the router with the specified path, handler, and optional middlewares.
318
+ *
319
+ * @param this
320
+ * @param path
321
+ * @param handler
322
+ * @param middlewares
323
+ */
324
+ static options(path, handler, middlewares) {
325
+ this.add("options", path, handler, middlewares);
326
+ }
327
+ /**
328
+ * Adds a new HEAD route to the router with the specified path, handler, and optional middlewares.
329
+ *
330
+ * @param this
331
+ * @param path
332
+ * @param handler
333
+ * @param middlewares
334
+ */
335
+ static head(path, handler, middlewares) {
336
+ this.add("head", path, handler, middlewares);
337
+ }
338
+ /**
339
+ * Defines a group of routes with a common prefix and optional middlewares, allowing for better
340
+ * organization and reuse of route configurations.
341
+ *
342
+ * @param this
343
+ * @param prefix
344
+ * @param callback
345
+ * @param middlewares
346
+ */
347
+ static async group(prefix, callback, middlewares) {
348
+ this.ensureState();
349
+ const context = this.groupContext.getStore();
350
+ const previousPrefix = context?.prefix ?? this.prefix;
351
+ const previousMiddlewares = context?.groupMiddlewares ?? this.groupMiddlewares;
352
+ const fullPrefix = [previousPrefix, prefix].filter(Boolean).join("/");
353
+ const nextContext = {
354
+ prefix: this.normalizePath(fullPrefix),
355
+ groupMiddlewares: [...previousMiddlewares, ...middlewares || []]
356
+ };
357
+ await this.groupContext.run(nextContext, async () => {
358
+ await Promise.resolve(callback());
359
+ });
360
+ }
361
+ /**
362
+ * Adds global middlewares to the router, which will be applied to all routes.
363
+ *
364
+ * @param this
365
+ * @param middlewares
366
+ * @param callback
367
+ */
368
+ static middleware(middlewares, callback) {
369
+ this.ensureState();
370
+ const prevMiddlewares = this.globalMiddlewares;
371
+ this.globalMiddlewares = [...prevMiddlewares, ...middlewares || []];
372
+ callback();
373
+ this.globalMiddlewares = prevMiddlewares;
374
+ }
375
+ static allRoutes(type) {
376
+ this.ensureState();
377
+ if (type === "method") return this.routesByMethod;
378
+ if (type === "path") return this.routesByPathMethod;
379
+ return this.routes.filter((e) => e.methods.length > 1 || e.methods[0] !== "options");
380
+ }
381
+ static resolveHandler(route) {
382
+ let handlerFunction;
383
+ let instance = null;
384
+ if (typeof route.handler === "function") handlerFunction = route.handler.bind(route);
385
+ else if (Array.isArray(route.handler) && route.handler.length === 2) {
386
+ const [ControllerType, method] = route.handler;
387
+ if (["function", "object"].includes(typeof ControllerType) && typeof ControllerType[method] === "function") {
388
+ instance = ControllerType;
389
+ handlerFunction = ControllerType[method].bind(ControllerType);
390
+ } else if (typeof ControllerType === "function") {
391
+ instance = new ControllerType();
392
+ if (typeof instance[method] === "function") handlerFunction = instance[method].bind(instance);
393
+ else throw new Error(`Method "${method}" not found in controller instance "${ControllerType.name}"`);
394
+ } else throw new Error(`Invalid controller type for route: ${route.path}`);
395
+ } else throw new Error(`Invalid handler format for route: ${route.path}`);
396
+ return {
397
+ handlerFunction,
398
+ instance
399
+ };
400
+ }
401
+ static bindRequestToInstance(ctx, instance, route, payload) {
402
+ if (!instance) return;
403
+ instance.ctx = ctx;
404
+ instance.body = payload.body;
405
+ instance.query = payload.query;
406
+ instance.params = payload.params;
407
+ instance.clearRequest = new ClearRequest({
408
+ ctx,
409
+ route,
410
+ body: instance.body,
411
+ query: instance.query,
412
+ params: instance.params
413
+ });
414
+ }
415
+ };
416
+
61
417
  //#endregion
62
418
  exports.ClearRequest = ClearRequest;
63
419
  exports.Controller = Controller;
420
+ exports.CoreRouter = CoreRouter;
64
421
  exports.Route = Route;