clear-router 2.5.11 → 2.5.13

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 (42) hide show
  1. package/dist/{bindings-CDGLuAq4.cjs → bindings-CLsZjOEy.cjs} +8 -1
  2. package/dist/{bindings-B6x2HfzP.mjs → bindings-XLDXFpHZ.mjs} +8 -1
  3. package/dist/core/index.cjs +2 -2
  4. package/dist/core/index.d.cts +2 -2
  5. package/dist/core/index.d.mts +2 -2
  6. package/dist/core/index.mjs +2 -2
  7. package/dist/decorators/index.cjs +1 -1
  8. package/dist/decorators/index.mjs +1 -1
  9. package/dist/decorators/setup.cjs +2 -2
  10. package/dist/decorators/setup.mjs +2 -2
  11. package/dist/express/index.cjs +3 -3
  12. package/dist/express/index.d.cts +1 -1
  13. package/dist/express/index.d.mts +1 -1
  14. package/dist/express/index.mjs +3 -3
  15. package/dist/fastify/index.cjs +3 -3
  16. package/dist/fastify/index.d.cts +1 -1
  17. package/dist/fastify/index.d.mts +1 -1
  18. package/dist/fastify/index.mjs +3 -3
  19. package/dist/h3/index.cjs +3 -3
  20. package/dist/h3/index.d.cts +1 -1
  21. package/dist/h3/index.d.mts +1 -1
  22. package/dist/h3/index.mjs +3 -3
  23. package/dist/hono/index.cjs +3 -3
  24. package/dist/hono/index.d.cts +1 -1
  25. package/dist/hono/index.d.mts +1 -1
  26. package/dist/hono/index.mjs +3 -3
  27. package/dist/index.cjs +46 -6
  28. package/dist/index.d.cts +40 -24
  29. package/dist/index.d.mts +40 -24
  30. package/dist/index.mjs +46 -6
  31. package/dist/koa/index.cjs +3 -3
  32. package/dist/koa/index.d.cts +1 -1
  33. package/dist/koa/index.d.mts +1 -1
  34. package/dist/koa/index.mjs +3 -3
  35. package/dist/{responses-DuZeRyGE.mjs → responses-BvETUeDL.mjs} +1 -1
  36. package/dist/{responses-CBP3RYjJ.cjs → responses-Bvnk0uvc.cjs} +1 -1
  37. package/dist/{router-CArh9OHb.mjs → router-CPmZcbU0.mjs} +39 -6
  38. package/dist/{router-DtqXUlJq.cjs → router-D9H9-T27.cjs} +39 -6
  39. package/dist/{router-DCGZNRNj.d.cts → router-DTI0BowV.d.cts} +40 -24
  40. package/dist/{router-BkYtqjYr.d.mts → router-DiKqUyvk.d.mts} +40 -24
  41. package/dist/types/core/Response.d.mts +3 -1
  42. package/package.json +1 -1
@@ -58,14 +58,21 @@ var Response = class {
58
58
  headers = new Headers();
59
59
  sent = false;
60
60
  statusCode = 200;
61
+ statusText = "OK";
61
62
  constructor(init) {
62
- Object.assign(this, init);
63
+ const { status: _, ...rest } = init ?? {};
64
+ Object.assign(this, rest);
63
65
  if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
66
+ if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
64
67
  }
65
68
  status(code) {
66
69
  this.statusCode = code;
67
70
  return this;
68
71
  }
72
+ setStatusText(text) {
73
+ this.statusText = text;
74
+ return this;
75
+ }
69
76
  code(code) {
70
77
  return this.status(code);
71
78
  }
@@ -57,14 +57,21 @@ var Response = class {
57
57
  headers = new Headers();
58
58
  sent = false;
59
59
  statusCode = 200;
60
+ statusText = "OK";
60
61
  constructor(init) {
61
- Object.assign(this, init);
62
+ const { status: _, ...rest } = init ?? {};
63
+ Object.assign(this, rest);
62
64
  if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
65
+ if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
63
66
  }
64
67
  status(code) {
65
68
  this.statusCode = code;
66
69
  return this;
67
70
  }
71
+ setStatusText(text) {
72
+ this.statusText = text;
73
+ return this;
74
+ }
68
75
  code(code) {
69
76
  return this.status(code);
70
77
  }
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_bindings = require('../bindings-CDGLuAq4.cjs');
3
- const require_router = require('../router-DtqXUlJq.cjs');
2
+ const require_bindings = require('../bindings-CLsZjOEy.cjs');
3
+ const require_router = require('../router-D9H9-T27.cjs');
4
4
 
5
5
  //#region src/core/plugins.ts
6
6
  function definePlugin(plugin) {
@@ -1,2 +1,2 @@
1
- import { a as ClearRouterPluginRequestContext, c as PluginBindValue, d as Request, i as ClearRouterPluginInput, l as PluginSetupResult, n as ClearRouterPlugin, o as PluginBind, r as ClearRouterPluginContext, s as PluginBindFactory, t as CoreRouter, u as definePlugin, w as Response } from "../router-DCGZNRNj.cjs";
2
- export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
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-DTI0BowV.cjs";
2
+ export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
@@ -1,2 +1,2 @@
1
- import { a as ClearRouterPluginRequestContext, c as PluginBindValue, d as Request, i as ClearRouterPluginInput, l as PluginSetupResult, n as ClearRouterPlugin, o as PluginBind, r as ClearRouterPluginContext, s as PluginBindFactory, t as CoreRouter, u as definePlugin, w as Response } from "../router-BkYtqjYr.mjs";
2
- export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
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-DiKqUyvk.mjs";
2
+ export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
@@ -1,5 +1,5 @@
1
- import { c as Request, s as Response } from "../bindings-B6x2HfzP.mjs";
2
- import { t as CoreRouter } from "../router-CArh9OHb.mjs";
1
+ import { c as Request, s as Response } from "../bindings-XLDXFpHZ.mjs";
2
+ import { t as CoreRouter } from "../router-CPmZcbU0.mjs";
3
3
 
4
4
  //#region src/core/plugins.ts
5
5
  function definePlugin(plugin) {
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_bindings = require('../bindings-CDGLuAq4.cjs');
2
+ const require_bindings = require('../bindings-CLsZjOEy.cjs');
3
3
 
4
4
  exports.Bind = require_bindings.Bind;
5
5
  exports.Container = require_bindings.Container;
@@ -1,3 +1,3 @@
1
- import { n as Container, t as Bind } from "../bindings-B6x2HfzP.mjs";
1
+ import { n as Container, t as Bind } from "../bindings-XLDXFpHZ.mjs";
2
2
 
3
3
  export { Bind, Container };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_bindings = require('../bindings-CDGLuAq4.cjs');
3
- const require_router = require('../router-DtqXUlJq.cjs');
2
+ const require_bindings = require('../bindings-CLsZjOEy.cjs');
3
+ const require_router = require('../router-D9H9-T27.cjs');
4
4
  require('./index.cjs');
5
5
  require("reflect-metadata");
6
6
 
@@ -1,5 +1,5 @@
1
- import { n as Container, t as Bind } from "../bindings-B6x2HfzP.mjs";
2
- import { t as CoreRouter } from "../router-CArh9OHb.mjs";
1
+ import { n as Container, t as Bind } from "../bindings-XLDXFpHZ.mjs";
2
+ import { t as CoreRouter } from "../router-CPmZcbU0.mjs";
3
3
  import "./index.mjs";
4
4
  import "reflect-metadata";
5
5
 
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- require('../bindings-CDGLuAq4.cjs');
3
- const require_router = require('../router-DtqXUlJq.cjs');
4
- const require_responses = require('../responses-CBP3RYjJ.cjs');
2
+ require('../bindings-CLsZjOEy.cjs');
3
+ const require_router = require('../router-D9H9-T27.cjs');
4
+ const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/express/router.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { C as HttpMethod, _ as Handler, b as ApiResourceMiddleware, f as Route, t as CoreRouter, v as HttpContext, x as ControllerAction, y as Middleware } from "../router-DCGZNRNj.cjs";
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-DTI0BowV.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 HttpMethod, _ as Handler, b as ApiResourceMiddleware, f as Route, t as CoreRouter, v as HttpContext, x as ControllerAction, y as Middleware } from "../router-BkYtqjYr.mjs";
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-DiKqUyvk.mjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
@@ -1,6 +1,6 @@
1
- import "../bindings-B6x2HfzP.mjs";
2
- import { t as CoreRouter } from "../router-CArh9OHb.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
1
+ import "../bindings-XLDXFpHZ.mjs";
2
+ import { t as CoreRouter } from "../router-CPmZcbU0.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BvETUeDL.mjs";
4
4
 
5
5
  //#region src/express/router.ts
6
6
  /**
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- require('../bindings-CDGLuAq4.cjs');
3
- const require_router = require('../router-DtqXUlJq.cjs');
4
- const require_responses = require('../responses-CBP3RYjJ.cjs');
2
+ require('../bindings-CLsZjOEy.cjs');
3
+ const require_router = require('../router-D9H9-T27.cjs');
4
+ const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/fastify/router.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-DCGZNRNj.cjs";
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-DTI0BowV.cjs";
2
2
  import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
3
 
4
4
  //#region types/fastify.d.ts
@@ -1,4 +1,4 @@
1
- import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-BkYtqjYr.mjs";
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-DiKqUyvk.mjs";
2
2
  import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
3
 
4
4
  //#region types/fastify.d.ts
@@ -1,6 +1,6 @@
1
- import "../bindings-B6x2HfzP.mjs";
2
- import { t as CoreRouter } from "../router-CArh9OHb.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
1
+ import "../bindings-XLDXFpHZ.mjs";
2
+ import { t as CoreRouter } from "../router-CPmZcbU0.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BvETUeDL.mjs";
4
4
 
5
5
  //#region src/fastify/router.ts
6
6
  /**
package/dist/h3/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- require('../bindings-CDGLuAq4.cjs');
3
- const require_router = require('../router-DtqXUlJq.cjs');
4
- const require_responses = require('../responses-CBP3RYjJ.cjs');
2
+ require('../bindings-CLsZjOEy.cjs');
3
+ const require_router = require('../router-D9H9-T27.cjs');
4
+ const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
  let h3 = require("h3");
6
6
 
7
7
  //#region src/h3/router.ts
@@ -1,4 +1,4 @@
1
- import { C as HttpMethod, b as ApiResourceMiddleware, f as Route, g as Middleware, h as HttpContext, m as Handler, p as H3App, t as CoreRouter, x as ControllerAction } from "../router-DCGZNRNj.cjs";
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-DTI0BowV.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 HttpMethod, b as ApiResourceMiddleware, f as Route, g as Middleware, h as HttpContext, m as Handler, p as H3App, t as CoreRouter, x as ControllerAction } from "../router-BkYtqjYr.mjs";
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-DiKqUyvk.mjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
package/dist/h3/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import "../bindings-B6x2HfzP.mjs";
2
- import { t as CoreRouter } from "../router-CArh9OHb.mjs";
3
- import { n as resolveResponseMeta } from "../responses-DuZeRyGE.mjs";
1
+ import "../bindings-XLDXFpHZ.mjs";
2
+ import { t as CoreRouter } from "../router-CPmZcbU0.mjs";
3
+ import { n as resolveResponseMeta } from "../responses-BvETUeDL.mjs";
4
4
  import { HTTPResponse, getQuery, getRouterParams, readBody } from "h3";
5
5
 
6
6
  //#region src/h3/router.ts
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- require('../bindings-CDGLuAq4.cjs');
3
- const require_router = require('../router-DtqXUlJq.cjs');
4
- const require_responses = require('../responses-CBP3RYjJ.cjs');
2
+ require('../bindings-CLsZjOEy.cjs');
3
+ const require_router = require('../router-D9H9-T27.cjs');
4
+ const require_responses = require('../responses-Bvnk0uvc.cjs');
5
5
 
6
6
  //#region src/hono/router.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-DCGZNRNj.cjs";
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-DTI0BowV.cjs";
2
2
  import { Context, HonoRequest, MiddlewareHandler } from "hono";
3
3
 
4
4
  //#region types/hono.d.ts
@@ -1,4 +1,4 @@
1
- import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-BkYtqjYr.mjs";
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-DiKqUyvk.mjs";
2
2
  import { Context, HonoRequest, MiddlewareHandler } from "hono";
3
3
 
4
4
  //#region types/hono.d.ts
@@ -1,6 +1,6 @@
1
- import "../bindings-B6x2HfzP.mjs";
2
- import { t as CoreRouter } from "../router-CArh9OHb.mjs";
3
- import { n as resolveResponseMeta } from "../responses-DuZeRyGE.mjs";
1
+ import "../bindings-XLDXFpHZ.mjs";
2
+ import { t as CoreRouter } from "../router-CPmZcbU0.mjs";
3
+ import { n as resolveResponseMeta } from "../responses-BvETUeDL.mjs";
4
4
 
5
5
  //#region src/hono/router.ts
6
6
  /**
package/dist/index.cjs CHANGED
@@ -98,14 +98,21 @@ var Response = class {
98
98
  headers = new Headers();
99
99
  sent = false;
100
100
  statusCode = 200;
101
+ statusText = "OK";
101
102
  constructor(init) {
102
- Object.assign(this, init);
103
+ const { status: _, ...rest } = init ?? {};
104
+ Object.assign(this, rest);
103
105
  if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
106
+ if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
104
107
  }
105
108
  status(code) {
106
109
  this.statusCode = code;
107
110
  return this;
108
111
  }
112
+ setStatusText(text) {
113
+ this.statusText = text;
114
+ return this;
115
+ }
109
116
  code(code) {
110
117
  return this.status(code);
111
118
  }
@@ -263,6 +270,7 @@ var CoreRouter = class {
263
270
  static defaultConfigKey = Symbol.for("clear-router:default-config");
264
271
  static pluginStoreKey = Symbol.for("clear-router:plugins");
265
272
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
273
+ static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
266
274
  static createBaseConfig() {
267
275
  return {
268
276
  methodOverride: {
@@ -314,6 +322,11 @@ var CoreRouter = class {
314
322
  if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
315
323
  return g[this.pluginPendingKey];
316
324
  }
325
+ static getPluginArgumentResolvers() {
326
+ const g = globalThis;
327
+ if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
328
+ return g[this.pluginArgumentResolversKey];
329
+ }
317
330
  static createDefaultState() {
318
331
  return {
319
332
  config: this.getDefaultConfig(),
@@ -428,6 +441,9 @@ var CoreRouter = class {
428
441
  const ctx = {
429
442
  container: Container,
430
443
  bind: this.createPluginBind(),
444
+ resolveArguments: (resolver) => {
445
+ this.getPluginArgumentResolvers().add(resolver);
446
+ },
431
447
  bindings: Container.bindings(),
432
448
  configure: this.configure.bind(this),
433
449
  configureDefaults: this.configureDefaults.bind(this),
@@ -480,8 +496,7 @@ var CoreRouter = class {
480
496
  ctx,
481
497
  request,
482
498
  response,
483
- clearRequest: request,
484
- clearResponse: response
499
+ getBindings: () => Container.bindings()
485
500
  };
486
501
  }
487
502
  static createPluginBind() {
@@ -495,6 +510,18 @@ var CoreRouter = class {
495
510
  };
496
511
  return bind;
497
512
  }
513
+ static async resolvePluginArguments(ctx, routeContext) {
514
+ const resolvers = Array.from(this.getPluginArgumentResolvers());
515
+ if (!resolvers.length) return void 0;
516
+ const pluginContext = {
517
+ ...this.createPluginRequestContext(ctx),
518
+ ...routeContext
519
+ };
520
+ for (const resolver of resolvers) {
521
+ const args = await resolver(pluginContext);
522
+ if (Array.isArray(args)) return args;
523
+ }
524
+ }
498
525
  static ensureState() {
499
526
  this.bindStateAccessors();
500
527
  if (!this.config) this.config = { methodOverride: {
@@ -812,6 +839,7 @@ var CoreRouter = class {
812
839
  return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
813
840
  await this.pluginsReady();
814
841
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
842
+ const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
815
843
  const metadata = getBindingMetadataFromTargets([
816
844
  {
817
845
  target: bindingTarget,
@@ -823,9 +851,17 @@ var CoreRouter = class {
823
851
  propertyKey: "__class__"
824
852
  }
825
853
  ]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
854
+ const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
855
+ const pluginArgs = await this.resolvePluginArguments(ctx, {
856
+ target: bindingTarget,
857
+ method: bindingMethod,
858
+ handler: bindingHandler,
859
+ metadata: bindingMetadata,
860
+ tokens,
861
+ designTokens
862
+ });
863
+ if (pluginArgs) return handlerFunction(...pluginArgs);
826
864
  if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
827
- const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
828
- const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
829
865
  if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
830
866
  const args = [];
831
867
  for (const token of tokens) {
@@ -855,7 +891,11 @@ var CoreRouter = class {
855
891
  clearRequest.query = payload.query;
856
892
  clearRequest.params = payload.params;
857
893
  ctx.clearRequest = clearRequest;
858
- if (!(ctx.clearResponse instanceof Response)) ctx.clearResponse = new Response();
894
+ Container.bind(Request, ctx.clearRequest);
895
+ if (!(ctx.clearResponse instanceof Response)) {
896
+ ctx.clearResponse = new Response(ctx.response ?? ctx.reply ?? ctx.res);
897
+ Container.bind(Response, ctx.clearResponse);
898
+ }
859
899
  if (!instance) return;
860
900
  instance.ctx = ctx;
861
901
  instance.body = payload.body;
package/dist/index.d.cts CHANGED
@@ -41,8 +41,10 @@ declare class Response$1 {
41
41
  headers: Headers;
42
42
  sent: boolean;
43
43
  statusCode: number;
44
- constructor(init?: Partial<Response$1>);
44
+ statusText: string;
45
+ constructor(init?: Partial<Response$1 | globalThis.Response>);
45
46
  status(code: number): this;
47
+ setStatusText(text: string): this;
46
48
  code(code: number): this;
47
49
  setHeader(name: string, value: string): this;
48
50
  header(name: string, value: string): this;
@@ -153,14 +155,25 @@ interface ClearRouterPluginRequestContext {
153
155
  ctx: any;
154
156
  request: Request;
155
157
  response: Response$1;
158
+ getBindings: () => Record<string, BindValue>;
156
159
  [key: string]: any;
157
160
  }
161
+ interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
162
+ target?: object;
163
+ method?: PropertyKey;
164
+ handler?: object;
165
+ metadata?: object;
166
+ tokens: BindToken[];
167
+ designTokens: BindToken[];
168
+ }
158
169
  type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
159
170
  type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
160
171
  type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
172
+ type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
161
173
  interface ClearRouterPluginContext<Options = any> {
162
174
  container: typeof Container;
163
175
  bind: PluginBind;
176
+ resolveArguments: (resolver: PluginArgumentsResolver) => void;
164
177
  bindings: Record<string, BindValue>;
165
178
  configure: (options: RouterConfig) => void;
166
179
  configureDefaults: (options: RouterConfig) => void;
@@ -191,13 +204,15 @@ declare abstract class CoreRouter {
191
204
  private static readonly defaultConfigKey;
192
205
  private static readonly pluginStoreKey;
193
206
  private static readonly pluginPendingKey;
207
+ private static readonly pluginArgumentResolversKey;
194
208
  protected static createBaseConfig(): RouterConfig;
195
209
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
196
210
  protected static getDefaultConfig(): RouterConfig;
197
- protected static resolveStateNamespace(this: any): string;
211
+ protected static resolveStateNamespace(): string;
198
212
  protected static getStateStore(): Record<string, any>;
199
213
  protected static getPluginStore(): Set<string>;
200
214
  protected static getPluginPendingStore(): Set<Promise<void>>;
215
+ protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
201
216
  protected static createDefaultState(): {
202
217
  config: RouterConfig;
203
218
  groupContext: AsyncLocalStorage<{
@@ -211,10 +226,10 @@ declare abstract class CoreRouter {
211
226
  groupMiddlewares: any[];
212
227
  globalMiddlewares: any[];
213
228
  };
214
- protected static bindStateAccessors(this: any): void;
229
+ protected static bindStateAccessors(): void;
215
230
  protected static createDefaultOptionsHandler(): any;
216
231
  static config: RouterConfig;
217
- static configureDefaults(this: any, options?: RouterConfig): void;
232
+ static configureDefaults(options?: RouterConfig): void;
218
233
  /**
219
234
  * Use a registered plugin
220
235
  *
@@ -223,8 +238,8 @@ declare abstract class CoreRouter {
223
238
  * @param options
224
239
  * @returns
225
240
  */
226
- static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
227
- protected static pluginsReady(this: any): Promise<void>;
241
+ static use<Options = any>(plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
242
+ protected static pluginsReady(): Promise<void>;
228
243
  protected static groupContext: AsyncLocalStorage<{
229
244
  prefix: string;
230
245
  groupMiddlewares: any[];
@@ -239,7 +254,8 @@ declare abstract class CoreRouter {
239
254
  protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
240
255
  protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
241
256
  protected static createPluginBind(): PluginBind;
242
- protected static ensureState(this: any): void;
257
+ protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
258
+ protected static ensureState(): void;
243
259
  /**
244
260
  * Normalizes a path by ensuring it starts with a single slash and does not have trailing
245
261
  * slashes, while preserving dynamic segments and parameters.
@@ -256,7 +272,7 @@ declare abstract class CoreRouter {
256
272
  * @returns
257
273
  */
258
274
  static configure(this: any, options?: RouterConfig): void;
259
- protected static resolveMethodOverride(this: any, method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
275
+ protected static resolveMethodOverride(method: string, headers: Headers | Record<string, any>, body: unknown): HttpMethod | null;
260
276
  /**
261
277
  * Adds a new route to the router.
262
278
  *
@@ -266,7 +282,7 @@ declare abstract class CoreRouter {
266
282
  * @param handler
267
283
  * @param middlewares
268
284
  */
269
- static add(this: any, methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): void;
285
+ static add(methods: HttpMethod | HttpMethod[], path: string, handler: any, middlewares?: any[] | any): void;
270
286
  /**
271
287
  * Define a resourceful API controller with standard CRUD routes.
272
288
  *
@@ -275,7 +291,7 @@ declare abstract class CoreRouter {
275
291
  * @param controller
276
292
  * @param options
277
293
  */
278
- static apiResource(this: any, basePath: string, controller: any, options?: {
294
+ static apiResource(basePath: string, controller: any, options?: {
279
295
  only?: ControllerAction[];
280
296
  except?: ControllerAction[];
281
297
  middlewares?: ApiResourceMiddleware<any>;
@@ -288,7 +304,7 @@ declare abstract class CoreRouter {
288
304
  * @param handler The handler function for the GET route.
289
305
  * @param middlewares Optional middlewares to apply to the GET route.
290
306
  */
291
- static get(this: any, path: string, handler: any, middlewares?: any[] | any): void;
307
+ static get(path: string, handler: any, middlewares?: any[] | any): void;
292
308
  /**
293
309
  * Adds a new POST route to the router.
294
310
  *
@@ -297,7 +313,7 @@ declare abstract class CoreRouter {
297
313
  * @param handler
298
314
  * @param middlewares
299
315
  */
300
- static post(this: any, path: string, handler: any, middlewares?: any[] | any): void;
316
+ static post(path: string, handler: any, middlewares?: any[] | any): void;
301
317
  /**
302
318
  * Adds a new PUT route to the router.
303
319
  *
@@ -306,7 +322,7 @@ declare abstract class CoreRouter {
306
322
  * @param handler
307
323
  * @param middlewares
308
324
  */
309
- static put(this: any, path: string, handler: any, middlewares?: any[] | any): void;
325
+ static put(path: string, handler: any, middlewares?: any[] | any): void;
310
326
  /**
311
327
  * Adds a new DELETE route to the router.
312
328
  *
@@ -315,7 +331,7 @@ declare abstract class CoreRouter {
315
331
  * @param handler
316
332
  * @param middlewares
317
333
  */
318
- static delete(this: any, path: string, handler: any, middlewares?: any[] | any): void;
334
+ static delete(path: string, handler: any, middlewares?: any[] | any): void;
319
335
  /**
320
336
  * Adds a new PATCH route to the router.
321
337
  *
@@ -324,7 +340,7 @@ declare abstract class CoreRouter {
324
340
  * @param handler
325
341
  * @param middlewares
326
342
  */
327
- static patch(this: any, path: string, handler: any, middlewares?: any[] | any): void;
343
+ static patch(path: string, handler: any, middlewares?: any[] | any): void;
328
344
  /**
329
345
  * Adds a new OPTIONS route to the router.
330
346
  *
@@ -333,7 +349,7 @@ declare abstract class CoreRouter {
333
349
  * @param handler
334
350
  * @param middlewares
335
351
  */
336
- static options(this: any, path: string, handler: any, middlewares?: any[] | any): void;
352
+ static options(path: string, handler: any, middlewares?: any[] | any): void;
337
353
  /**
338
354
  * Adds a new HEAD route to the router.
339
355
  *
@@ -342,7 +358,7 @@ declare abstract class CoreRouter {
342
358
  * @param handler
343
359
  * @param middlewares
344
360
  */
345
- static head(this: any, path: string, handler: any, middlewares?: any[] | any): void;
361
+ static head(path: string, handler: any, middlewares?: any[] | any): void;
346
362
  /**
347
363
  * Defines a group of routes with a common prefix.
348
364
  *
@@ -351,7 +367,7 @@ declare abstract class CoreRouter {
351
367
  * @param callback
352
368
  * @param middlewares
353
369
  */
354
- static group(this: any, prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
370
+ static group(prefix: string, callback: () => void | Promise<void>, middlewares?: any[]): Promise<void>;
355
371
  /**
356
372
  * Adds global middlewares to the router, which will be applied to all routes.
357
373
  *
@@ -359,24 +375,24 @@ declare abstract class CoreRouter {
359
375
  * @param middlewares
360
376
  * @param callback
361
377
  */
362
- static middleware(this: any, middlewares: any[], callback: () => void): void;
378
+ static middleware(middlewares: any[], callback: () => void): void;
363
379
  /**
364
380
  * Retrieves all registered routes in the router, optionally organized by path or method
365
381
  * for easier access and management.
366
382
  *
367
383
  * @param this
368
384
  */
369
- static allRoutes(this: any): Array<Route<any, any, any>>;
385
+ static allRoutes(): Array<Route<any, any, any>>;
370
386
  /**
371
387
  * @param this
372
388
  * @param type - 'path' to get routes organized by path
373
389
  */
374
- static allRoutes(this: any, type: 'path'): Record<string, Route<any, any, any>>;
390
+ static allRoutes(type: 'path'): Record<string, Route<any, any, any>>;
375
391
  /**
376
392
  * @param this
377
393
  * @param type - 'method' to get routes organized by method
378
394
  */
379
- static allRoutes(this: any, type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
395
+ static allRoutes(type: 'method'): { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
380
396
  protected static resolveHandler(route: Route<any, any, any>): {
381
397
  handlerFunction: ((ctx: any, req: Request) => any | Promise<any>) | null;
382
398
  instance: Controller<any> | null;
@@ -385,7 +401,7 @@ declare abstract class CoreRouter {
385
401
  bindingHandler?: object;
386
402
  bindingMetadata?: object;
387
403
  };
388
- protected static callHandler(this: any, handlerFunction: (ctx: any, req: Request) => any | Promise<any>, ctx: any, bindingTarget?: object, bindingMethod?: PropertyKey, bindingHandler?: object, bindingMetadata?: object): Promise<any>;
404
+ protected static callHandler(handlerFunction: (ctx: any, req: Request) => any | Promise<any>, ctx: any, bindingTarget?: object, bindingMethod?: PropertyKey, bindingHandler?: object, bindingMetadata?: object): Promise<any>;
389
405
  protected static bindRequestToInstance(ctx: any, instance: Controller<any> | Route<any, any, any> | null, route: Route<any, any, any>, payload: {
390
406
  body: Record<string, any>;
391
407
  query: Record<string, any>;
@@ -394,4 +410,4 @@ declare abstract class CoreRouter {
394
410
  }): void;
395
411
  }
396
412
  //#endregion
397
- export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
413
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };