clear-router 2.6.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/core/index.cjs +1 -1
  2. package/dist/core/index.d.cts +1 -1
  3. package/dist/core/index.d.mts +1 -1
  4. package/dist/core/index.mjs +1 -1
  5. package/dist/decorators/setup.cjs +1 -1
  6. package/dist/decorators/setup.d.mts +0 -1
  7. package/dist/decorators/setup.mjs +1 -1
  8. package/dist/express/index.cjs +1 -1
  9. package/dist/express/index.d.cts +1 -1
  10. package/dist/express/index.d.mts +1 -1
  11. package/dist/express/index.mjs +1 -1
  12. package/dist/fastify/index.cjs +1 -1
  13. package/dist/fastify/index.d.cts +1 -18
  14. package/dist/fastify/index.d.mts +1 -18
  15. package/dist/fastify/index.mjs +1 -1
  16. package/dist/h3/index.cjs +1 -1
  17. package/dist/h3/index.d.cts +1 -1
  18. package/dist/h3/index.d.mts +1 -1
  19. package/dist/h3/index.mjs +1 -1
  20. package/dist/hono/index.cjs +1 -1
  21. package/dist/hono/index.d.cts +1 -16
  22. package/dist/hono/index.d.mts +1 -16
  23. package/dist/hono/index.mjs +1 -1
  24. package/dist/index.cjs +35 -2
  25. package/dist/index.d.cts +41 -4
  26. package/dist/index.d.mts +41 -4
  27. package/dist/index.mjs +35 -2
  28. package/dist/koa/index.cjs +1 -1
  29. package/dist/koa/index.d.cts +1 -20
  30. package/dist/koa/index.d.mts +1 -20
  31. package/dist/koa/index.mjs +1 -1
  32. package/dist/{router-jwZwD8ZT.d.cts → router-B90hsOKM.d.cts} +86 -14
  33. package/dist/{router-CAnd539U.cjs → router-BJYHBKMY.cjs} +35 -2
  34. package/dist/{router-Bk8mXRu1.d.mts → router-BfYAFCqD.d.mts} +86 -14
  35. package/dist/{router-DSq9dtuQ.mjs → router-CbrVYD5L.mjs} +35 -2
  36. package/dist/types/ClearRequest.d.mts +6 -3
  37. package/dist/types/core/Response.d.mts +1 -0
  38. package/package.json +3 -2
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_bindings = require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-CAnd539U.cjs');
3
+ const require_router = require('../router-BJYHBKMY.cjs');
4
4
 
5
5
  //#region src/core/plugins.ts
6
6
  function definePlugin(plugin) {
@@ -1,2 +1,2 @@
1
- import { E as Response, a as ClearRouterPluginInput, c as PluginBind, d as PluginSetupResult, f as definePlugin, i as ClearRouterPluginContext, l as PluginBindFactory, n as ClearRouterPlugin, o as ClearRouterPluginRequestContext, p as Request, r as ClearRouterPluginArgumentsContext, s as PluginArgumentsResolver, t as CoreRouter, u as PluginBindValue } from "../router-jwZwD8ZT.cjs";
1
+ import { L as Response, a as ClearRouterPluginInput, c as PluginBind, d as PluginSetupResult, f as definePlugin, i as ClearRouterPluginContext, l as PluginBindFactory, n as ClearRouterPlugin, o as ClearRouterPluginRequestContext, p as Request, r as ClearRouterPluginArgumentsContext, s as PluginArgumentsResolver, t as CoreRouter, u as PluginBindValue } from "../router-B90hsOKM.cjs";
2
2
  export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
@@ -1,2 +1,2 @@
1
- import { E as Response, a as ClearRouterPluginInput, c as PluginBind, d as PluginSetupResult, f as definePlugin, i as ClearRouterPluginContext, l as PluginBindFactory, n as ClearRouterPlugin, o as ClearRouterPluginRequestContext, p as Request, r as ClearRouterPluginArgumentsContext, s as PluginArgumentsResolver, t as CoreRouter, u as PluginBindValue } from "../router-Bk8mXRu1.mjs";
1
+ import { L as Response, a as ClearRouterPluginInput, c as PluginBind, d as PluginSetupResult, f as definePlugin, i as ClearRouterPluginContext, l as PluginBindFactory, n as ClearRouterPlugin, o as ClearRouterPluginRequestContext, p as Request, r as ClearRouterPluginArgumentsContext, s as PluginArgumentsResolver, t as CoreRouter, u as PluginBindValue } from "../router-BfYAFCqD.mjs";
2
2
  export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
@@ -1,5 +1,5 @@
1
1
  import { c as Request, s as Response } from "../bindings-XLDXFpHZ.mjs";
2
- import { t as CoreRouter } from "../router-DSq9dtuQ.mjs";
2
+ import { t as CoreRouter } from "../router-CbrVYD5L.mjs";
3
3
 
4
4
  //#region src/core/plugins.ts
5
5
  function definePlugin(plugin) {
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_bindings = require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-CAnd539U.cjs');
3
+ const require_router = require('../router-BJYHBKMY.cjs');
4
4
  require('./index.cjs');
5
5
  require("reflect-metadata");
6
6
 
@@ -1,3 +1,2 @@
1
1
  import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-CNL7bpz5.mjs";
2
- import "reflect-metadata";
3
2
  export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
@@ -1,5 +1,5 @@
1
1
  import { n as Container, t as Bind } from "../bindings-XLDXFpHZ.mjs";
2
- import { t as CoreRouter } from "../router-DSq9dtuQ.mjs";
2
+ import { t as CoreRouter } from "../router-CbrVYD5L.mjs";
3
3
  import "./index.mjs";
4
4
  import "reflect-metadata";
5
5
 
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-CAnd539U.cjs');
3
+ const require_router = require('../router-BJYHBKMY.cjs');
4
4
  const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/express/router.ts
@@ -1,4 +1,4 @@
1
- import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, b as HttpContext, m as Route, t as CoreRouter, x as Middleware, y as Handler } from "../router-jwZwD8ZT.cjs";
1
+ import { F as ControllerAction, I as HttpMethod, M as HttpContext, N as Middleware, P as ApiResourceMiddleware, j as Handler, m as Route, t as CoreRouter } from "../router-B90hsOKM.cjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
@@ -1,4 +1,4 @@
1
- import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, b as HttpContext, m as Route, t as CoreRouter, x as Middleware, y as Handler } from "../router-Bk8mXRu1.mjs";
1
+ import { F as ControllerAction, I as HttpMethod, M as HttpContext, N as Middleware, P as ApiResourceMiddleware, j as Handler, m as Route, t as CoreRouter } from "../router-BfYAFCqD.mjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
@@ -1,5 +1,5 @@
1
1
  import "../bindings-XLDXFpHZ.mjs";
2
- import { t as CoreRouter } from "../router-DSq9dtuQ.mjs";
2
+ import { t as CoreRouter } from "../router-CbrVYD5L.mjs";
3
3
  import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BvETUeDL.mjs";
4
4
 
5
5
  //#region src/express/router.ts
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-CAnd539U.cjs');
3
+ const require_router = require('../router-BJYHBKMY.cjs');
4
4
  const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/fastify/router.ts
@@ -1,22 +1,5 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-jwZwD8ZT.cjs";
2
- import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
1
+ import { A as Middleware, D as FastifyApp, F as ControllerAction, I as HttpMethod, O as Handler, P as ApiResourceMiddleware, k as HttpContext, m as Route, t as CoreRouter } from "../router-B90hsOKM.cjs";
3
2
 
4
- //#region types/fastify.d.ts
5
- interface RequestWithGetBody extends FastifyRequest {
6
- getBody: () => Record<string, any>;
7
- }
8
- interface HttpContext {
9
- req: RequestWithGetBody;
10
- reply: FastifyReply;
11
- clearRequest: Request;
12
- clearResponse: Response;
13
- }
14
- type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
15
- type Handler = RouteHandler | ControllerHandler;
16
- type NextFunction = (err?: Error) => void;
17
- type Middleware = (req: RequestWithGetBody, reply: FastifyReply, next: NextFunction) => any | Promise<any>;
18
- type FastifyApp = FastifyInstance;
19
- //#endregion
20
3
  //#region src/fastify/router.d.ts
21
4
  /**
22
5
  * @class clear-router Fastify Router
@@ -1,22 +1,5 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-Bk8mXRu1.mjs";
2
- import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
1
+ import { A as Middleware, D as FastifyApp, F as ControllerAction, I as HttpMethod, O as Handler, P as ApiResourceMiddleware, k as HttpContext, m as Route, t as CoreRouter } from "../router-BfYAFCqD.mjs";
3
2
 
4
- //#region types/fastify.d.ts
5
- interface RequestWithGetBody extends FastifyRequest {
6
- getBody: () => Record<string, any>;
7
- }
8
- interface HttpContext {
9
- req: RequestWithGetBody;
10
- reply: FastifyReply;
11
- clearRequest: Request;
12
- clearResponse: Response;
13
- }
14
- type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
15
- type Handler = RouteHandler | ControllerHandler;
16
- type NextFunction = (err?: Error) => void;
17
- type Middleware = (req: RequestWithGetBody, reply: FastifyReply, next: NextFunction) => any | Promise<any>;
18
- type FastifyApp = FastifyInstance;
19
- //#endregion
20
3
  //#region src/fastify/router.d.ts
21
4
  /**
22
5
  * @class clear-router Fastify Router
@@ -1,5 +1,5 @@
1
1
  import "../bindings-XLDXFpHZ.mjs";
2
- import { t as CoreRouter } from "../router-DSq9dtuQ.mjs";
2
+ import { t as CoreRouter } from "../router-CbrVYD5L.mjs";
3
3
  import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BvETUeDL.mjs";
4
4
 
5
5
  //#region src/fastify/router.ts
package/dist/h3/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-CAnd539U.cjs');
3
+ const require_router = require('../router-BJYHBKMY.cjs');
4
4
  const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
  let h3 = require("h3");
6
6
 
@@ -1,4 +1,4 @@
1
- import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, _ as HttpContext, g as Handler, h as H3App, m as Route, t as CoreRouter, v as Middleware } from "../router-jwZwD8ZT.cjs";
1
+ import { C as H3App, E as Middleware, F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, T as HttpContext, m as Route, t as CoreRouter, w as Handler } from "../router-B90hsOKM.cjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
@@ -1,4 +1,4 @@
1
- import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, _ as HttpContext, g as Handler, h as H3App, m as Route, t as CoreRouter, v as Middleware } from "../router-Bk8mXRu1.mjs";
1
+ import { C as H3App, E as Middleware, F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, T as HttpContext, m as Route, t as CoreRouter, w as Handler } from "../router-BfYAFCqD.mjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
package/dist/h3/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "../bindings-XLDXFpHZ.mjs";
2
- import { t as CoreRouter } from "../router-DSq9dtuQ.mjs";
2
+ import { t as CoreRouter } from "../router-CbrVYD5L.mjs";
3
3
  import { n as resolveResponseMeta } from "../responses-BvETUeDL.mjs";
4
4
  import { HTTPResponse, getQuery, getRouterParams, readBody } from "h3";
5
5
 
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-CAnd539U.cjs');
3
+ const require_router = require('../router-BJYHBKMY.cjs');
4
4
  const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/hono/router.ts
@@ -1,20 +1,5 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-jwZwD8ZT.cjs";
2
- import { Context, HonoRequest, MiddlewareHandler } from "hono";
1
+ import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, S as Middleware, b as HonoApp, m as Route, t as CoreRouter, x as HttpContext, y as Handler } from "../router-B90hsOKM.cjs";
3
2
 
4
- //#region types/hono.d.ts
5
- type RequestWithGetBody = HonoRequest & {
6
- getBody: () => Record<string, any>;
7
- };
8
- type HttpContext = Context & {
9
- req: RequestWithGetBody;
10
- clearRequest: Request;
11
- clearResponse: Response;
12
- };
13
- type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
14
- type Handler = RouteHandler | ControllerHandler;
15
- type Middleware = MiddlewareHandler;
16
- type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: Middleware[]) => any };
17
- //#endregion
18
3
  //#region src/hono/router.d.ts
19
4
  /**
20
5
  * @class clear-router Hono Router
@@ -1,20 +1,5 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-Bk8mXRu1.mjs";
2
- import { Context, HonoRequest, MiddlewareHandler } from "hono";
1
+ import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, S as Middleware, b as HonoApp, m as Route, t as CoreRouter, x as HttpContext, y as Handler } from "../router-BfYAFCqD.mjs";
3
2
 
4
- //#region types/hono.d.ts
5
- type RequestWithGetBody = HonoRequest & {
6
- getBody: () => Record<string, any>;
7
- };
8
- type HttpContext = Context & {
9
- req: RequestWithGetBody;
10
- clearRequest: Request;
11
- clearResponse: Response;
12
- };
13
- type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
14
- type Handler = RouteHandler | ControllerHandler;
15
- type Middleware = MiddlewareHandler;
16
- type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: Middleware[]) => any };
17
- //#endregion
18
3
  //#region src/hono/router.d.ts
19
4
  /**
20
5
  * @class clear-router Hono Router
@@ -1,5 +1,5 @@
1
1
  import "../bindings-XLDXFpHZ.mjs";
2
- import { t as CoreRouter } from "../router-DSq9dtuQ.mjs";
2
+ import { t as CoreRouter } from "../router-CbrVYD5L.mjs";
3
3
  import { n as resolveResponseMeta } from "../responses-BvETUeDL.mjs";
4
4
 
5
5
  //#region src/hono/router.ts
package/dist/index.cjs CHANGED
@@ -299,6 +299,8 @@ var CoreRouter = class {
299
299
  static pluginStoreKey = Symbol.for("clear-router:plugins");
300
300
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
301
301
  static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
302
+ static requestProvider;
303
+ static responseProvider;
302
304
  static createBaseConfig() {
303
305
  return {
304
306
  methodOverride: {
@@ -886,6 +888,37 @@ var CoreRouter = class {
886
888
  static url(name, params) {
887
889
  return this.route(name)?.toPath(params);
888
890
  }
891
+ /**
892
+ * Provide a class that will overide the base Request instance
893
+ *
894
+ * @param provider
895
+ */
896
+ static setRequestProvider(provider) {
897
+ this.requestProvider = provider;
898
+ }
899
+ /**
900
+ * Provide a class that will overide the base Response instance
901
+ *
902
+ * @param provider
903
+ */
904
+ static setResponseProvider(provider) {
905
+ this.responseProvider = provider;
906
+ }
907
+ static initializeInstance(provider, args) {
908
+ const isRequest = [
909
+ "CoreRequest",
910
+ "Request",
911
+ "ClearRequest"
912
+ ].includes(provider.name);
913
+ const isResponse = [
914
+ "CoreResponse",
915
+ "Response",
916
+ "ClearResponse"
917
+ ].includes(provider.name);
918
+ if (isRequest && this.requestProvider) return new this.requestProvider(args);
919
+ else if (isResponse && this.responseProvider) return new this.responseProvider(args);
920
+ return new provider(args);
921
+ }
889
922
  static resolveHandler(route) {
890
923
  let handlerFunction;
891
924
  let instance = null;
@@ -963,7 +996,7 @@ var CoreRouter = class {
963
996
  });
964
997
  }
965
998
  static bindRequestToInstance(ctx, instance, route, payload) {
966
- const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
999
+ const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : this.initializeInstance(Request, {
967
1000
  ctx,
968
1001
  route,
969
1002
  body: payload.body,
@@ -983,7 +1016,7 @@ var CoreRouter = class {
983
1016
  ctx.clearRequest = clearRequest;
984
1017
  Container.bind(Request, ctx.clearRequest);
985
1018
  if (!(ctx.clearResponse instanceof Response)) {
986
- ctx.clearResponse = new Response(ctx.response ?? ctx.reply ?? ctx.res);
1019
+ ctx.clearResponse = this.initializeInstance(Response, ctx.response ?? ctx.reply ?? ctx.res);
987
1020
  Container.bind(Response, ctx.clearResponse);
988
1021
  }
989
1022
  if (!instance) return;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,8 @@
1
1
  import { NextFunction, Request as Request$1, Response as Response$2 } from "express";
2
- import { Middleware as Middleware$1 } from "h3";
2
+ import { Middleware as Middleware$4 } from "h3";
3
+ import { FastifyReply, FastifyRequest } from "fastify";
4
+ import { MiddlewareHandler } from "hono";
5
+ import Koa from "koa";
3
6
  import { AsyncLocalStorage } from "node:async_hooks";
4
7
 
5
8
  //#region types/basic.d.ts
@@ -37,6 +40,7 @@ interface RouterConfig {
37
40
  //#endregion
38
41
  //#region src/core/Response.d.ts
39
42
  declare class Response$1 {
43
+ [key: string]: any;
40
44
  body: any;
41
45
  headers: Headers;
42
46
  sent: boolean;
@@ -63,7 +67,7 @@ interface RouteParameter {
63
67
  field?: string;
64
68
  optional: boolean;
65
69
  }
66
- declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
70
+ declare class Route<X = any, M = Middleware$4 | Middleware$3, H = any> {
67
71
  ctx: X;
68
72
  body: RequestData;
69
73
  query: RequestData;
@@ -114,10 +118,23 @@ declare class Request<X = any, M = any> extends ClearRequest<X, M> {
114
118
  /**
115
119
  * Middleware function type
116
120
  */
117
- type Middleware = (req: Request$1, res: Response$2, next: NextFunction) => any | Promise<any>;
121
+ type Middleware$3 = (req: Request$1, res: Response$2, next: NextFunction) => any | Promise<any>;
122
+ //#endregion
123
+ //#region types/fastify.d.ts
124
+ interface RequestWithGetBody extends FastifyRequest {
125
+ getBody: () => Record<string, any>;
126
+ }
127
+ type NextFunction$1 = (err?: Error) => void;
128
+ type Middleware$2 = (req: RequestWithGetBody, reply: FastifyReply, next: NextFunction$1) => any | Promise<any>;
129
+ //#endregion
130
+ //#region types/hono.d.ts
131
+ type Middleware$1 = MiddlewareHandler;
132
+ //#endregion
133
+ //#region types/koa.d.ts
134
+ type Middleware = Koa.Middleware<any, any>;
118
135
  //#endregion
119
136
  //#region src/ClearRequest.d.ts
120
- declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
137
+ declare class ClearRequest<X = any, M = Middleware$4 | Middleware$3 | Middleware$2 | Middleware$1 | Middleware> {
121
138
  [key: string]: any;
122
139
  /**
123
140
  * @param body - Parsed request body
@@ -220,6 +237,8 @@ declare abstract class CoreRouter {
220
237
  private static readonly pluginStoreKey;
221
238
  private static readonly pluginPendingKey;
222
239
  private static readonly pluginArgumentResolversKey;
240
+ private static requestProvider?;
241
+ private static responseProvider?;
223
242
  protected static createBaseConfig(): RouterConfig;
224
243
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
225
244
  protected static getDefaultConfig(): RouterConfig;
@@ -420,6 +439,24 @@ declare abstract class CoreRouter {
420
439
  static allRoutes(type: 'name'): Record<string, Route<any, any, any>>;
421
440
  static route(name: string): Route<any, any, any> | undefined;
422
441
  static url(name: string, params?: Record<string, any>): string | undefined;
442
+ /**
443
+ * Provide a class that will overide the base Request instance
444
+ *
445
+ * @param provider
446
+ */
447
+ static setRequestProvider(provider: typeof Request): void;
448
+ /**
449
+ * Provide a class that will overide the base Response instance
450
+ *
451
+ * @param provider
452
+ */
453
+ static setResponseProvider(provider: typeof Response$1): void;
454
+ /**
455
+ * Provide a class that will overide the base Response instance
456
+ *
457
+ * @param provider
458
+ */
459
+ private static initializeInstance;
423
460
  protected static resolveHandler(route: Route<any, any, any>): {
424
461
  handlerFunction: ((ctx: any, req: Request) => any | Promise<any>) | null;
425
462
  instance: Controller<any> | null;
package/dist/index.d.mts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { NextFunction, Request as Request$1, Response as Response$2 } from "express";
3
- import { Middleware as Middleware$1 } from "h3";
3
+ import { Middleware as Middleware$4 } from "h3";
4
+ import { FastifyReply, FastifyRequest } from "fastify";
5
+ import { MiddlewareHandler } from "hono";
6
+ import Koa from "koa";
4
7
 
5
8
  //#region types/basic.d.ts
6
9
  /**
@@ -37,6 +40,7 @@ interface RouterConfig {
37
40
  //#endregion
38
41
  //#region src/core/Response.d.ts
39
42
  declare class Response$1 {
43
+ [key: string]: any;
40
44
  body: any;
41
45
  headers: Headers;
42
46
  sent: boolean;
@@ -63,7 +67,7 @@ interface RouteParameter {
63
67
  field?: string;
64
68
  optional: boolean;
65
69
  }
66
- declare class Route<X = any, M = Middleware$1 | Middleware, H = any> {
70
+ declare class Route<X = any, M = Middleware$4 | Middleware$3, H = any> {
67
71
  ctx: X;
68
72
  body: RequestData;
69
73
  query: RequestData;
@@ -114,10 +118,23 @@ declare class Request<X = any, M = any> extends ClearRequest<X, M> {
114
118
  /**
115
119
  * Middleware function type
116
120
  */
117
- type Middleware = (req: Request$1, res: Response$2, next: NextFunction) => any | Promise<any>;
121
+ type Middleware$3 = (req: Request$1, res: Response$2, next: NextFunction) => any | Promise<any>;
122
+ //#endregion
123
+ //#region types/fastify.d.ts
124
+ interface RequestWithGetBody extends FastifyRequest {
125
+ getBody: () => Record<string, any>;
126
+ }
127
+ type NextFunction$1 = (err?: Error) => void;
128
+ type Middleware$2 = (req: RequestWithGetBody, reply: FastifyReply, next: NextFunction$1) => any | Promise<any>;
129
+ //#endregion
130
+ //#region types/hono.d.ts
131
+ type Middleware$1 = MiddlewareHandler;
132
+ //#endregion
133
+ //#region types/koa.d.ts
134
+ type Middleware = Koa.Middleware<any, any>;
118
135
  //#endregion
119
136
  //#region src/ClearRequest.d.ts
120
- declare class ClearRequest<X = any, M = Middleware$1 | Middleware> {
137
+ declare class ClearRequest<X = any, M = Middleware$4 | Middleware$3 | Middleware$2 | Middleware$1 | Middleware> {
121
138
  [key: string]: any;
122
139
  /**
123
140
  * @param body - Parsed request body
@@ -220,6 +237,8 @@ declare abstract class CoreRouter {
220
237
  private static readonly pluginStoreKey;
221
238
  private static readonly pluginPendingKey;
222
239
  private static readonly pluginArgumentResolversKey;
240
+ private static requestProvider?;
241
+ private static responseProvider?;
223
242
  protected static createBaseConfig(): RouterConfig;
224
243
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
225
244
  protected static getDefaultConfig(): RouterConfig;
@@ -420,6 +439,24 @@ declare abstract class CoreRouter {
420
439
  static allRoutes(type: 'name'): Record<string, Route<any, any, any>>;
421
440
  static route(name: string): Route<any, any, any> | undefined;
422
441
  static url(name: string, params?: Record<string, any>): string | undefined;
442
+ /**
443
+ * Provide a class that will overide the base Request instance
444
+ *
445
+ * @param provider
446
+ */
447
+ static setRequestProvider(provider: typeof Request): void;
448
+ /**
449
+ * Provide a class that will overide the base Response instance
450
+ *
451
+ * @param provider
452
+ */
453
+ static setResponseProvider(provider: typeof Response$1): void;
454
+ /**
455
+ * Provide a class that will overide the base Response instance
456
+ *
457
+ * @param provider
458
+ */
459
+ private static initializeInstance;
423
460
  protected static resolveHandler(route: Route<any, any, any>): {
424
461
  handlerFunction: ((ctx: any, req: Request) => any | Promise<any>) | null;
425
462
  instance: Controller<any> | null;
package/dist/index.mjs CHANGED
@@ -298,6 +298,8 @@ var CoreRouter = class {
298
298
  static pluginStoreKey = Symbol.for("clear-router:plugins");
299
299
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
300
300
  static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
301
+ static requestProvider;
302
+ static responseProvider;
301
303
  static createBaseConfig() {
302
304
  return {
303
305
  methodOverride: {
@@ -885,6 +887,37 @@ var CoreRouter = class {
885
887
  static url(name, params) {
886
888
  return this.route(name)?.toPath(params);
887
889
  }
890
+ /**
891
+ * Provide a class that will overide the base Request instance
892
+ *
893
+ * @param provider
894
+ */
895
+ static setRequestProvider(provider) {
896
+ this.requestProvider = provider;
897
+ }
898
+ /**
899
+ * Provide a class that will overide the base Response instance
900
+ *
901
+ * @param provider
902
+ */
903
+ static setResponseProvider(provider) {
904
+ this.responseProvider = provider;
905
+ }
906
+ static initializeInstance(provider, args) {
907
+ const isRequest = [
908
+ "CoreRequest",
909
+ "Request",
910
+ "ClearRequest"
911
+ ].includes(provider.name);
912
+ const isResponse = [
913
+ "CoreResponse",
914
+ "Response",
915
+ "ClearResponse"
916
+ ].includes(provider.name);
917
+ if (isRequest && this.requestProvider) return new this.requestProvider(args);
918
+ else if (isResponse && this.responseProvider) return new this.responseProvider(args);
919
+ return new provider(args);
920
+ }
888
921
  static resolveHandler(route) {
889
922
  let handlerFunction;
890
923
  let instance = null;
@@ -962,7 +995,7 @@ var CoreRouter = class {
962
995
  });
963
996
  }
964
997
  static bindRequestToInstance(ctx, instance, route, payload) {
965
- const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
998
+ const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : this.initializeInstance(Request, {
966
999
  ctx,
967
1000
  route,
968
1001
  body: payload.body,
@@ -982,7 +1015,7 @@ var CoreRouter = class {
982
1015
  ctx.clearRequest = clearRequest;
983
1016
  Container.bind(Request, ctx.clearRequest);
984
1017
  if (!(ctx.clearResponse instanceof Response)) {
985
- ctx.clearResponse = new Response(ctx.response ?? ctx.reply ?? ctx.res);
1018
+ ctx.clearResponse = this.initializeInstance(Response, ctx.response ?? ctx.reply ?? ctx.res);
986
1019
  Container.bind(Response, ctx.clearResponse);
987
1020
  }
988
1021
  if (!instance) return;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-CLsZjOEy.cjs');
3
- const require_router = require('../router-CAnd539U.cjs');
3
+ const require_router = require('../router-BJYHBKMY.cjs');
4
4
  const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/koa/router.ts
@@ -1,24 +1,5 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-jwZwD8ZT.cjs";
2
- import Koa from "koa";
3
- import Router$1 from "@koa/router";
1
+ import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, _ as KoaRouterApp, g as HttpContext, h as Handler, m as Route, t as CoreRouter, v as Middleware } from "../router-B90hsOKM.cjs";
4
2
 
5
- //#region types/koa.d.ts
6
- interface RequestWithGetBody extends Koa.Request {
7
- getBody: () => Record<string, any>;
8
- body?: any;
9
- }
10
- interface HttpContext extends Koa.Context {
11
- request: RequestWithGetBody;
12
- clearRequest: Request;
13
- clearResponse: Response;
14
- params: Record<string, any>;
15
- query: Record<string, any>;
16
- }
17
- type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
18
- type Handler = RouteHandler | ControllerHandler;
19
- type Middleware = Koa.Middleware<any, any>;
20
- type KoaRouterApp = Router$1<any, any>;
21
- //#endregion
22
3
  //#region src/koa/router.d.ts
23
4
  /**
24
5
  * @class clear-router Koa Router
@@ -1,24 +1,5 @@
1
- import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-Bk8mXRu1.mjs";
2
- import Koa from "koa";
3
- import Router$1 from "@koa/router";
1
+ import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, _ as KoaRouterApp, g as HttpContext, h as Handler, m as Route, t as CoreRouter, v as Middleware } from "../router-BfYAFCqD.mjs";
4
2
 
5
- //#region types/koa.d.ts
6
- interface RequestWithGetBody extends Koa.Request {
7
- getBody: () => Record<string, any>;
8
- body?: any;
9
- }
10
- interface HttpContext extends Koa.Context {
11
- request: RequestWithGetBody;
12
- clearRequest: Request;
13
- clearResponse: Response;
14
- params: Record<string, any>;
15
- query: Record<string, any>;
16
- }
17
- type RouteHandler = (ctx: HttpContext, req: Request) => any | Promise<any>;
18
- type Handler = RouteHandler | ControllerHandler;
19
- type Middleware = Koa.Middleware<any, any>;
20
- type KoaRouterApp = Router$1<any, any>;
21
- //#endregion
22
3
  //#region src/koa/router.d.ts
23
4
  /**
24
5
  * @class clear-router Koa Router
@@ -1,5 +1,5 @@
1
1
  import "../bindings-XLDXFpHZ.mjs";
2
- import { t as CoreRouter } from "../router-DSq9dtuQ.mjs";
2
+ import { t as CoreRouter } from "../router-CbrVYD5L.mjs";
3
3
  import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-BvETUeDL.mjs";
4
4
 
5
5
  //#region src/koa/router.ts
@@ -1,10 +1,15 @@
1
1
  import { a as BindValue, i as BindToken, o as Container } from "./bindings-CxvtC8XS.cjs";
2
2
  import { NextFunction, Request, Response as Response$1 } from "express";
3
- import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
3
+ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
4
+ import { EventHandlerRequest, H3, H3Event, Middleware as Middleware$2, TypedServerRequest } from "h3";
5
+ import { Context, HonoRequest, MiddlewareHandler } from "hono";
6
+ import Koa from "koa";
7
+ import Router$1 from "@koa/router";
4
8
  import { AsyncLocalStorage } from "node:async_hooks";
5
9
 
6
10
  //#region src/core/Response.d.ts
7
11
  declare class Response$2 {
12
+ [key: string]: any;
8
13
  body: any;
9
14
  headers: Headers;
10
15
  sent: boolean;
@@ -63,14 +68,14 @@ interface RouterConfig {
63
68
  }
64
69
  //#endregion
65
70
  //#region types/express.d.ts
66
- interface RequestWithGetBody extends Request {
71
+ interface RequestWithGetBody$3 extends Request {
67
72
  getBody: () => Record<string, any>;
68
73
  }
69
74
  /**
70
75
  * HTTP context passed to route handlers
71
76
  */
72
- interface HttpContext$1 {
73
- req: RequestWithGetBody;
77
+ interface HttpContext$4 {
78
+ req: RequestWithGetBody$3;
74
79
  res: Response$1;
75
80
  next: NextFunction;
76
81
  clearRequest: Request$1;
@@ -79,12 +84,12 @@ interface HttpContext$1 {
79
84
  /**
80
85
  * Route handler function type
81
86
  */
82
- type RouteHandler$1 = (
87
+ type RouteHandler$4 = (
83
88
  /**
84
89
  * Express context object containing req, res, and next
85
90
  */
86
91
 
87
- ctx: HttpContext$1,
92
+ ctx: HttpContext$4,
88
93
  /**
89
94
  * ClearRequest instance
90
95
  */
@@ -93,11 +98,27 @@ req: Request$1) => any | Promise<any>;
93
98
  /**
94
99
  * Handler can be either a function or controller reference
95
100
  */
96
- type Handler$1 = RouteHandler$1 | ControllerHandler;
101
+ type Handler$4 = RouteHandler$4 | ControllerHandler;
97
102
  /**
98
103
  * Middleware function type
99
104
  */
100
- type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
105
+ type Middleware$4 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
106
+ //#endregion
107
+ //#region types/fastify.d.ts
108
+ interface RequestWithGetBody$2 extends FastifyRequest {
109
+ getBody: () => Record<string, any>;
110
+ }
111
+ interface HttpContext$3 {
112
+ req: RequestWithGetBody$2;
113
+ reply: FastifyReply;
114
+ clearRequest: Request$1;
115
+ clearResponse: Response$2;
116
+ }
117
+ type RouteHandler$3 = (ctx: HttpContext$3, req: Request$1) => any | Promise<any>;
118
+ type Handler$3 = RouteHandler$3 | ControllerHandler;
119
+ type NextFunction$1 = (err?: Error) => void;
120
+ type Middleware$3 = (req: RequestWithGetBody$2, reply: FastifyReply, next: NextFunction$1) => any | Promise<any>;
121
+ type FastifyApp = FastifyInstance;
101
122
  //#endregion
102
123
  //#region types/h3.d.ts
103
124
  type H3App = Omit<H3, 'fetch'> & {
@@ -110,7 +131,7 @@ type RequestlessH3Event = Omit<H3Event, 'req'>;
110
131
  /**
111
132
  * HTTP context passed to route handlers
112
133
  */
113
- interface HttpContext extends RequestlessH3Event {
134
+ interface HttpContext$2 extends RequestlessH3Event {
114
135
  req: HttpRequest;
115
136
  clearRequest: Request$1;
116
137
  clearResponse: Response$2;
@@ -118,12 +139,12 @@ interface HttpContext extends RequestlessH3Event {
118
139
  /**
119
140
  * Route handler function type
120
141
  */
121
- type RouteHandler = (
142
+ type RouteHandler$2 = (
122
143
  /**
123
144
  * H3 event context
124
145
  */
125
146
 
126
- ctx: HttpContext,
147
+ ctx: HttpContext$2,
127
148
  /**
128
149
  * ClearRequest instance
129
150
  */
@@ -132,7 +153,38 @@ req: Request$1) => any | Promise<any>;
132
153
  /**
133
154
  * Handler can be either a function or controller reference
134
155
  */
156
+ type Handler$2 = RouteHandler$2 | ControllerHandler;
157
+ //#endregion
158
+ //#region types/hono.d.ts
159
+ type RequestWithGetBody$1 = HonoRequest & {
160
+ getBody: () => Record<string, any>;
161
+ };
162
+ type HttpContext$1 = Context & {
163
+ req: RequestWithGetBody$1;
164
+ clearRequest: Request$1;
165
+ clearResponse: Response$2;
166
+ };
167
+ type RouteHandler$1 = (ctx: HttpContext$1, req: Request$1) => any | Promise<any>;
168
+ type Handler$1 = RouteHandler$1 | ControllerHandler;
169
+ type Middleware$1 = MiddlewareHandler;
170
+ type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: Middleware$1[]) => any };
171
+ //#endregion
172
+ //#region types/koa.d.ts
173
+ interface RequestWithGetBody extends Koa.Request {
174
+ getBody: () => Record<string, any>;
175
+ body?: any;
176
+ }
177
+ interface HttpContext extends Koa.Context {
178
+ request: RequestWithGetBody;
179
+ clearRequest: Request$1;
180
+ clearResponse: Response$2;
181
+ params: Record<string, any>;
182
+ query: Record<string, any>;
183
+ }
184
+ type RouteHandler = (ctx: HttpContext, req: Request$1) => any | Promise<any>;
135
185
  type Handler = RouteHandler | ControllerHandler;
186
+ type Middleware = Koa.Middleware<any, any>;
187
+ type KoaRouterApp = Router$1<any, any>;
136
188
  //#endregion
137
189
  //#region src/Route.d.ts
138
190
  interface RouteParameter {
@@ -140,7 +192,7 @@ interface RouteParameter {
140
192
  field?: string;
141
193
  optional: boolean;
142
194
  }
143
- declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
195
+ declare class Route<X = any, M = Middleware$2 | Middleware$4, H = any> {
144
196
  ctx: X;
145
197
  body: RequestData;
146
198
  query: RequestData;
@@ -168,7 +220,7 @@ declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
168
220
  }
169
221
  //#endregion
170
222
  //#region src/ClearRequest.d.ts
171
- declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
223
+ declare class ClearRequest<X = any, M = Middleware$2 | Middleware$4 | Middleware$3 | Middleware$1 | Middleware> {
172
224
  [key: string]: any;
173
225
  /**
174
226
  * @param body - Parsed request body
@@ -272,6 +324,8 @@ declare abstract class CoreRouter {
272
324
  private static readonly pluginStoreKey;
273
325
  private static readonly pluginPendingKey;
274
326
  private static readonly pluginArgumentResolversKey;
327
+ private static requestProvider?;
328
+ private static responseProvider?;
275
329
  protected static createBaseConfig(): RouterConfig;
276
330
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
277
331
  protected static getDefaultConfig(): RouterConfig;
@@ -472,6 +526,24 @@ declare abstract class CoreRouter {
472
526
  static allRoutes(type: 'name'): Record<string, Route<any, any, any>>;
473
527
  static route(name: string): Route<any, any, any> | undefined;
474
528
  static url(name: string, params?: Record<string, any>): string | undefined;
529
+ /**
530
+ * Provide a class that will overide the base Request instance
531
+ *
532
+ * @param provider
533
+ */
534
+ static setRequestProvider(provider: typeof Request$1): void;
535
+ /**
536
+ * Provide a class that will overide the base Response instance
537
+ *
538
+ * @param provider
539
+ */
540
+ static setResponseProvider(provider: typeof Response$2): void;
541
+ /**
542
+ * Provide a class that will overide the base Response instance
543
+ *
544
+ * @param provider
545
+ */
546
+ private static initializeInstance;
475
547
  protected static resolveHandler(route: Route<any, any, any>): {
476
548
  handlerFunction: ((ctx: any, req: Request$1) => any | Promise<any>) | null;
477
549
  instance: Controller<any> | null;
@@ -489,4 +561,4 @@ declare abstract class CoreRouter {
489
561
  }): void;
490
562
  }
491
563
  //#endregion
492
- export { ControllerAction as C, Response$2 as E, ApiResourceMiddleware as S, HttpMethod as T, HttpContext as _, ClearRouterPluginInput as a, HttpContext$1 as b, PluginBind as c, PluginSetupResult as d, definePlugin as f, Handler as g, H3App as h, ClearRouterPluginContext as i, PluginBindFactory as l, Route as m, ClearRouterPlugin as n, ClearRouterPluginRequestContext as o, Request$1 as p, ClearRouterPluginArgumentsContext as r, PluginArgumentsResolver as s, CoreRouter as t, PluginBindValue as u, Middleware as v, ControllerHandler as w, Middleware$1 as x, Handler$1 as y };
564
+ export { Middleware$3 as A, H3App as C, FastifyApp as D, Middleware$2 as E, ControllerAction as F, HttpMethod as I, Response$2 as L, HttpContext$4 as M, Middleware$4 as N, Handler$3 as O, ApiResourceMiddleware as P, Middleware$1 as S, HttpContext$2 as T, KoaRouterApp as _, ClearRouterPluginInput as a, HonoApp as b, PluginBind as c, PluginSetupResult as d, definePlugin as f, HttpContext as g, Handler as h, ClearRouterPluginContext as i, Handler$4 as j, HttpContext$3 as k, PluginBindFactory as l, Route as m, ClearRouterPlugin as n, ClearRouterPluginRequestContext as o, Request$1 as p, ClearRouterPluginArgumentsContext as r, PluginArgumentsResolver as s, CoreRouter as t, PluginBindValue as u, Middleware as v, Handler$2 as w, HttpContext$1 as x, Handler$1 as y };
@@ -72,6 +72,8 @@ var CoreRouter = class {
72
72
  static pluginStoreKey = Symbol.for("clear-router:plugins");
73
73
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
74
74
  static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
75
+ static requestProvider;
76
+ static responseProvider;
75
77
  static createBaseConfig() {
76
78
  return {
77
79
  methodOverride: {
@@ -659,6 +661,37 @@ var CoreRouter = class {
659
661
  static url(name, params) {
660
662
  return this.route(name)?.toPath(params);
661
663
  }
664
+ /**
665
+ * Provide a class that will overide the base Request instance
666
+ *
667
+ * @param provider
668
+ */
669
+ static setRequestProvider(provider) {
670
+ this.requestProvider = provider;
671
+ }
672
+ /**
673
+ * Provide a class that will overide the base Response instance
674
+ *
675
+ * @param provider
676
+ */
677
+ static setResponseProvider(provider) {
678
+ this.responseProvider = provider;
679
+ }
680
+ static initializeInstance(provider, args) {
681
+ const isRequest = [
682
+ "CoreRequest",
683
+ "Request",
684
+ "ClearRequest"
685
+ ].includes(provider.name);
686
+ const isResponse = [
687
+ "CoreResponse",
688
+ "Response",
689
+ "ClearResponse"
690
+ ].includes(provider.name);
691
+ if (isRequest && this.requestProvider) return new this.requestProvider(args);
692
+ else if (isResponse && this.responseProvider) return new this.responseProvider(args);
693
+ return new provider(args);
694
+ }
662
695
  static resolveHandler(route) {
663
696
  let handlerFunction;
664
697
  let instance = null;
@@ -736,7 +769,7 @@ var CoreRouter = class {
736
769
  });
737
770
  }
738
771
  static bindRequestToInstance(ctx, instance, route, payload) {
739
- const clearRequest = ctx.clearRequest instanceof require_bindings.Request ? ctx.clearRequest : new require_bindings.Request({
772
+ const clearRequest = ctx.clearRequest instanceof require_bindings.Request ? ctx.clearRequest : this.initializeInstance(require_bindings.Request, {
740
773
  ctx,
741
774
  route,
742
775
  body: payload.body,
@@ -756,7 +789,7 @@ var CoreRouter = class {
756
789
  ctx.clearRequest = clearRequest;
757
790
  require_bindings.Container.bind(require_bindings.Request, ctx.clearRequest);
758
791
  if (!(ctx.clearResponse instanceof require_bindings.Response)) {
759
- ctx.clearResponse = new require_bindings.Response(ctx.response ?? ctx.reply ?? ctx.res);
792
+ ctx.clearResponse = this.initializeInstance(require_bindings.Response, ctx.response ?? ctx.reply ?? ctx.res);
760
793
  require_bindings.Container.bind(require_bindings.Response, ctx.clearResponse);
761
794
  }
762
795
  if (!instance) return;
@@ -1,10 +1,15 @@
1
1
  import { a as BindValue, i as BindToken, o as Container } from "./bindings-CNL7bpz5.mjs";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
- import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
3
+ import { EventHandlerRequest, H3, H3Event, Middleware as Middleware$2, TypedServerRequest } from "h3";
4
4
  import { NextFunction, Request, Response as Response$1 } from "express";
5
+ import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
6
+ import { Context, HonoRequest, MiddlewareHandler } from "hono";
7
+ import Koa from "koa";
8
+ import Router$1 from "@koa/router";
5
9
 
6
10
  //#region src/core/Response.d.ts
7
11
  declare class Response$2 {
12
+ [key: string]: any;
8
13
  body: any;
9
14
  headers: Headers;
10
15
  sent: boolean;
@@ -63,14 +68,14 @@ interface RouterConfig {
63
68
  }
64
69
  //#endregion
65
70
  //#region types/express.d.ts
66
- interface RequestWithGetBody extends Request {
71
+ interface RequestWithGetBody$3 extends Request {
67
72
  getBody: () => Record<string, any>;
68
73
  }
69
74
  /**
70
75
  * HTTP context passed to route handlers
71
76
  */
72
- interface HttpContext$1 {
73
- req: RequestWithGetBody;
77
+ interface HttpContext$4 {
78
+ req: RequestWithGetBody$3;
74
79
  res: Response$1;
75
80
  next: NextFunction;
76
81
  clearRequest: Request$1;
@@ -79,12 +84,12 @@ interface HttpContext$1 {
79
84
  /**
80
85
  * Route handler function type
81
86
  */
82
- type RouteHandler$1 = (
87
+ type RouteHandler$4 = (
83
88
  /**
84
89
  * Express context object containing req, res, and next
85
90
  */
86
91
 
87
- ctx: HttpContext$1,
92
+ ctx: HttpContext$4,
88
93
  /**
89
94
  * ClearRequest instance
90
95
  */
@@ -93,11 +98,27 @@ req: Request$1) => any | Promise<any>;
93
98
  /**
94
99
  * Handler can be either a function or controller reference
95
100
  */
96
- type Handler$1 = RouteHandler$1 | ControllerHandler;
101
+ type Handler$4 = RouteHandler$4 | ControllerHandler;
97
102
  /**
98
103
  * Middleware function type
99
104
  */
100
- type Middleware$1 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
105
+ type Middleware$4 = (req: Request, res: Response$1, next: NextFunction) => any | Promise<any>;
106
+ //#endregion
107
+ //#region types/fastify.d.ts
108
+ interface RequestWithGetBody$2 extends FastifyRequest {
109
+ getBody: () => Record<string, any>;
110
+ }
111
+ interface HttpContext$3 {
112
+ req: RequestWithGetBody$2;
113
+ reply: FastifyReply;
114
+ clearRequest: Request$1;
115
+ clearResponse: Response$2;
116
+ }
117
+ type RouteHandler$3 = (ctx: HttpContext$3, req: Request$1) => any | Promise<any>;
118
+ type Handler$3 = RouteHandler$3 | ControllerHandler;
119
+ type NextFunction$1 = (err?: Error) => void;
120
+ type Middleware$3 = (req: RequestWithGetBody$2, reply: FastifyReply, next: NextFunction$1) => any | Promise<any>;
121
+ type FastifyApp = FastifyInstance;
101
122
  //#endregion
102
123
  //#region types/h3.d.ts
103
124
  type H3App = Omit<H3, 'fetch'> & {
@@ -110,7 +131,7 @@ type RequestlessH3Event = Omit<H3Event, 'req'>;
110
131
  /**
111
132
  * HTTP context passed to route handlers
112
133
  */
113
- interface HttpContext extends RequestlessH3Event {
134
+ interface HttpContext$2 extends RequestlessH3Event {
114
135
  req: HttpRequest;
115
136
  clearRequest: Request$1;
116
137
  clearResponse: Response$2;
@@ -118,12 +139,12 @@ interface HttpContext extends RequestlessH3Event {
118
139
  /**
119
140
  * Route handler function type
120
141
  */
121
- type RouteHandler = (
142
+ type RouteHandler$2 = (
122
143
  /**
123
144
  * H3 event context
124
145
  */
125
146
 
126
- ctx: HttpContext,
147
+ ctx: HttpContext$2,
127
148
  /**
128
149
  * ClearRequest instance
129
150
  */
@@ -132,7 +153,38 @@ req: Request$1) => any | Promise<any>;
132
153
  /**
133
154
  * Handler can be either a function or controller reference
134
155
  */
156
+ type Handler$2 = RouteHandler$2 | ControllerHandler;
157
+ //#endregion
158
+ //#region types/hono.d.ts
159
+ type RequestWithGetBody$1 = HonoRequest & {
160
+ getBody: () => Record<string, any>;
161
+ };
162
+ type HttpContext$1 = Context & {
163
+ req: RequestWithGetBody$1;
164
+ clearRequest: Request$1;
165
+ clearResponse: Response$2;
166
+ };
167
+ type RouteHandler$1 = (ctx: HttpContext$1, req: Request$1) => any | Promise<any>;
168
+ type Handler$1 = RouteHandler$1 | ControllerHandler;
169
+ type Middleware$1 = MiddlewareHandler;
170
+ type HonoApp = { [K in 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head']: (path: string, ...handlers: Middleware$1[]) => any };
171
+ //#endregion
172
+ //#region types/koa.d.ts
173
+ interface RequestWithGetBody extends Koa.Request {
174
+ getBody: () => Record<string, any>;
175
+ body?: any;
176
+ }
177
+ interface HttpContext extends Koa.Context {
178
+ request: RequestWithGetBody;
179
+ clearRequest: Request$1;
180
+ clearResponse: Response$2;
181
+ params: Record<string, any>;
182
+ query: Record<string, any>;
183
+ }
184
+ type RouteHandler = (ctx: HttpContext, req: Request$1) => any | Promise<any>;
135
185
  type Handler = RouteHandler | ControllerHandler;
186
+ type Middleware = Koa.Middleware<any, any>;
187
+ type KoaRouterApp = Router$1<any, any>;
136
188
  //#endregion
137
189
  //#region src/Route.d.ts
138
190
  interface RouteParameter {
@@ -140,7 +192,7 @@ interface RouteParameter {
140
192
  field?: string;
141
193
  optional: boolean;
142
194
  }
143
- declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
195
+ declare class Route<X = any, M = Middleware$2 | Middleware$4, H = any> {
144
196
  ctx: X;
145
197
  body: RequestData;
146
198
  query: RequestData;
@@ -168,7 +220,7 @@ declare class Route<X = any, M = Middleware | Middleware$1, H = any> {
168
220
  }
169
221
  //#endregion
170
222
  //#region src/ClearRequest.d.ts
171
- declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
223
+ declare class ClearRequest<X = any, M = Middleware$2 | Middleware$4 | Middleware$3 | Middleware$1 | Middleware> {
172
224
  [key: string]: any;
173
225
  /**
174
226
  * @param body - Parsed request body
@@ -272,6 +324,8 @@ declare abstract class CoreRouter {
272
324
  private static readonly pluginStoreKey;
273
325
  private static readonly pluginPendingKey;
274
326
  private static readonly pluginArgumentResolversKey;
327
+ private static requestProvider?;
328
+ private static responseProvider?;
275
329
  protected static createBaseConfig(): RouterConfig;
276
330
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
277
331
  protected static getDefaultConfig(): RouterConfig;
@@ -472,6 +526,24 @@ declare abstract class CoreRouter {
472
526
  static allRoutes(type: 'name'): Record<string, Route<any, any, any>>;
473
527
  static route(name: string): Route<any, any, any> | undefined;
474
528
  static url(name: string, params?: Record<string, any>): string | undefined;
529
+ /**
530
+ * Provide a class that will overide the base Request instance
531
+ *
532
+ * @param provider
533
+ */
534
+ static setRequestProvider(provider: typeof Request$1): void;
535
+ /**
536
+ * Provide a class that will overide the base Response instance
537
+ *
538
+ * @param provider
539
+ */
540
+ static setResponseProvider(provider: typeof Response$2): void;
541
+ /**
542
+ * Provide a class that will overide the base Response instance
543
+ *
544
+ * @param provider
545
+ */
546
+ private static initializeInstance;
475
547
  protected static resolveHandler(route: Route<any, any, any>): {
476
548
  handlerFunction: ((ctx: any, req: Request$1) => any | Promise<any>) | null;
477
549
  instance: Controller<any> | null;
@@ -489,4 +561,4 @@ declare abstract class CoreRouter {
489
561
  }): void;
490
562
  }
491
563
  //#endregion
492
- export { ControllerAction as C, Response$2 as E, ApiResourceMiddleware as S, HttpMethod as T, HttpContext as _, ClearRouterPluginInput as a, HttpContext$1 as b, PluginBind as c, PluginSetupResult as d, definePlugin as f, Handler as g, H3App as h, ClearRouterPluginContext as i, PluginBindFactory as l, Route as m, ClearRouterPlugin as n, ClearRouterPluginRequestContext as o, Request$1 as p, ClearRouterPluginArgumentsContext as r, PluginArgumentsResolver as s, CoreRouter as t, PluginBindValue as u, Middleware as v, ControllerHandler as w, Middleware$1 as x, Handler$1 as y };
564
+ export { Middleware$3 as A, H3App as C, FastifyApp as D, Middleware$2 as E, ControllerAction as F, HttpMethod as I, Response$2 as L, HttpContext$4 as M, Middleware$4 as N, Handler$3 as O, ApiResourceMiddleware as P, Middleware$1 as S, HttpContext$2 as T, KoaRouterApp as _, ClearRouterPluginInput as a, HonoApp as b, PluginBind as c, PluginSetupResult as d, definePlugin as f, HttpContext as g, Handler as h, ClearRouterPluginContext as i, Handler$4 as j, HttpContext$3 as k, PluginBindFactory as l, Route as m, ClearRouterPlugin as n, ClearRouterPluginRequestContext as o, Request$1 as p, ClearRouterPluginArgumentsContext as r, PluginArgumentsResolver as s, CoreRouter as t, PluginBindValue as u, Middleware as v, Handler$2 as w, HttpContext$1 as x, Handler$1 as y };
@@ -72,6 +72,8 @@ var CoreRouter = class {
72
72
  static pluginStoreKey = Symbol.for("clear-router:plugins");
73
73
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
74
74
  static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
75
+ static requestProvider;
76
+ static responseProvider;
75
77
  static createBaseConfig() {
76
78
  return {
77
79
  methodOverride: {
@@ -659,6 +661,37 @@ var CoreRouter = class {
659
661
  static url(name, params) {
660
662
  return this.route(name)?.toPath(params);
661
663
  }
664
+ /**
665
+ * Provide a class that will overide the base Request instance
666
+ *
667
+ * @param provider
668
+ */
669
+ static setRequestProvider(provider) {
670
+ this.requestProvider = provider;
671
+ }
672
+ /**
673
+ * Provide a class that will overide the base Response instance
674
+ *
675
+ * @param provider
676
+ */
677
+ static setResponseProvider(provider) {
678
+ this.responseProvider = provider;
679
+ }
680
+ static initializeInstance(provider, args) {
681
+ const isRequest = [
682
+ "CoreRequest",
683
+ "Request",
684
+ "ClearRequest"
685
+ ].includes(provider.name);
686
+ const isResponse = [
687
+ "CoreResponse",
688
+ "Response",
689
+ "ClearResponse"
690
+ ].includes(provider.name);
691
+ if (isRequest && this.requestProvider) return new this.requestProvider(args);
692
+ else if (isResponse && this.responseProvider) return new this.responseProvider(args);
693
+ return new provider(args);
694
+ }
662
695
  static resolveHandler(route) {
663
696
  let handlerFunction;
664
697
  let instance = null;
@@ -736,7 +769,7 @@ var CoreRouter = class {
736
769
  });
737
770
  }
738
771
  static bindRequestToInstance(ctx, instance, route, payload) {
739
- const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
772
+ const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : this.initializeInstance(Request, {
740
773
  ctx,
741
774
  route,
742
775
  body: payload.body,
@@ -756,7 +789,7 @@ var CoreRouter = class {
756
789
  ctx.clearRequest = clearRequest;
757
790
  Container.bind(Request, ctx.clearRequest);
758
791
  if (!(ctx.clearResponse instanceof Response)) {
759
- ctx.clearResponse = new Response(ctx.response ?? ctx.reply ?? ctx.res);
792
+ ctx.clearResponse = this.initializeInstance(Response, ctx.response ?? ctx.reply ?? ctx.res);
760
793
  Container.bind(Response, ctx.clearResponse);
761
794
  }
762
795
  if (!instance) return;
@@ -1,10 +1,13 @@
1
1
  import { RequestData } from "../types/basic.mjs";
2
- import { Middleware } from "../types/h3.mjs";
2
+ import { Middleware } from "../types/fastify.mjs";
3
+ import { Middleware as Middleware$1 } from "../types/h3.mjs";
4
+ import { Middleware as Middleware$2 } from "../types/hono.mjs";
5
+ import { Middleware as Middleware$3 } from "../types/koa.mjs";
3
6
  import { Route } from "./Route.mjs";
4
- import { Middleware as Middleware$1 } from "../types/express.mjs";
7
+ import { Middleware as Middleware$4 } from "../types/express.mjs";
5
8
 
6
9
  //#region src/ClearRequest.d.ts
7
- declare class ClearRequest<X = any, M = Middleware | Middleware$1> {
10
+ declare class ClearRequest<X = any, M = Middleware$1 | Middleware$4 | Middleware | Middleware$2 | Middleware$3> {
8
11
  [key: string]: any;
9
12
  /**
10
13
  * @param body - Parsed request body
@@ -1,5 +1,6 @@
1
1
  //#region src/core/Response.d.ts
2
2
  declare class Response {
3
+ [key: string]: any;
3
4
  body: any;
4
5
  headers: Headers;
5
6
  sent: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "description": "Laravel-style routing for Node.js with support for Express, H3, Fastify, Hono, and Koa, including CommonJS, ESM, and TypeScript support.",
5
5
  "keywords": [
6
6
  "h3",
@@ -141,7 +141,8 @@
141
141
  "node": ">=20.0.0"
142
142
  },
143
143
  "scripts": {
144
- "test": "vitest",
144
+ "test": "vitest run",
145
+ "test:watch": "vitest --watch",
145
146
  "lint": "eslint",
146
147
  "docs:dev": "vitepress dev docs",
147
148
  "docs:build": "vitepress build docs",