clear-router 2.5.10 → 2.5.12

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 (41) hide show
  1. package/dist/{bindings-BQMqEHcR.mjs → bindings-B6x2HfzP.mjs} +0 -1
  2. package/dist/{bindings--vhubKAz.cjs → bindings-CDGLuAq4.cjs} +0 -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 +33 -5
  28. package/dist/index.d.cts +15 -1
  29. package/dist/index.d.mts +15 -1
  30. package/dist/index.mjs +33 -5
  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-DBIiiAmd.cjs → responses-CBP3RYjJ.cjs} +1 -1
  36. package/dist/{responses-BuQBx5wu.mjs → responses-DuZeRyGE.mjs} +1 -1
  37. package/dist/{router-DCGZNRNj.d.cts → router-35iBbCaF.d.cts} +15 -1
  38. package/dist/{router-BkYtqjYr.d.mts → router-91xVPlV0.d.mts} +15 -1
  39. package/dist/{router-C04c3Lom.mjs → router-BkJMl4xv.mjs} +34 -5
  40. package/dist/{router-CdchSCSK.cjs → router-DPJfzvy5.cjs} +34 -5
  41. package/package.json +1 -1
@@ -161,7 +161,6 @@ var Container = class {
161
161
  }
162
162
  static staticPropsMatch(token, registered, tokenProps, registeredProps) {
163
163
  if (tokenProps.length !== registeredProps.length) return false;
164
- console.log(token, registered);
165
164
  for (const prop of tokenProps) {
166
165
  if (!registeredProps.includes(prop)) return false;
167
166
  if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
@@ -162,7 +162,6 @@ var Container = class {
162
162
  }
163
163
  static staticPropsMatch(token, registered, tokenProps, registeredProps) {
164
164
  if (tokenProps.length !== registeredProps.length) return false;
165
- console.log(token, registered);
166
165
  for (const prop of tokenProps) {
167
166
  if (!registeredProps.includes(prop)) return false;
168
167
  if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_bindings = require('../bindings--vhubKAz.cjs');
3
- const require_router = require('../router-CdchSCSK.cjs');
2
+ const require_bindings = require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DPJfzvy5.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-35iBbCaF.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-91xVPlV0.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-BQMqEHcR.mjs";
2
- import { t as CoreRouter } from "../router-C04c3Lom.mjs";
1
+ import { c as Request, s as Response } from "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-BkJMl4xv.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--vhubKAz.cjs');
2
+ const require_bindings = require('../bindings-CDGLuAq4.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-BQMqEHcR.mjs";
1
+ import { n as Container, t as Bind } from "../bindings-B6x2HfzP.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--vhubKAz.cjs');
3
- const require_router = require('../router-CdchSCSK.cjs');
2
+ const require_bindings = require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DPJfzvy5.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-BQMqEHcR.mjs";
2
- import { t as CoreRouter } from "../router-C04c3Lom.mjs";
1
+ import { n as Container, t as Bind } from "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-BkJMl4xv.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--vhubKAz.cjs');
3
- const require_router = require('../router-CdchSCSK.cjs');
4
- const require_responses = require('../responses-DBIiiAmd.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DPJfzvy5.cjs');
4
+ const require_responses = require('../responses-CBP3RYjJ.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-35iBbCaF.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-91xVPlV0.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-BQMqEHcR.mjs";
2
- import { t as CoreRouter } from "../router-C04c3Lom.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BuQBx5wu.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.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--vhubKAz.cjs');
3
- const require_router = require('../router-CdchSCSK.cjs');
4
- const require_responses = require('../responses-DBIiiAmd.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DPJfzvy5.cjs');
4
+ const require_responses = require('../responses-CBP3RYjJ.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-35iBbCaF.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-91xVPlV0.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-BQMqEHcR.mjs";
2
- import { t as CoreRouter } from "../router-C04c3Lom.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BuQBx5wu.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.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--vhubKAz.cjs');
3
- const require_router = require('../router-CdchSCSK.cjs');
4
- const require_responses = require('../responses-DBIiiAmd.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DPJfzvy5.cjs');
4
+ const require_responses = require('../responses-CBP3RYjJ.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-35iBbCaF.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-91xVPlV0.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-BQMqEHcR.mjs";
2
- import { t as CoreRouter } from "../router-C04c3Lom.mjs";
3
- import { n as resolveResponseMeta } from "../responses-BuQBx5wu.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
3
+ import { n as resolveResponseMeta } from "../responses-DuZeRyGE.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--vhubKAz.cjs');
3
- const require_router = require('../router-CdchSCSK.cjs');
4
- const require_responses = require('../responses-DBIiiAmd.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DPJfzvy5.cjs');
4
+ const require_responses = require('../responses-CBP3RYjJ.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-35iBbCaF.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-91xVPlV0.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-BQMqEHcR.mjs";
2
- import { t as CoreRouter } from "../router-C04c3Lom.mjs";
3
- import { n as resolveResponseMeta } from "../responses-BuQBx5wu.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
3
+ import { n as resolveResponseMeta } from "../responses-DuZeRyGE.mjs";
4
4
 
5
5
  //#region src/hono/router.ts
6
6
  /**
package/dist/index.cjs CHANGED
@@ -208,7 +208,6 @@ var Container = class {
208
208
  }
209
209
  static staticPropsMatch(token, registered, tokenProps, registeredProps) {
210
210
  if (tokenProps.length !== registeredProps.length) return false;
211
- console.log(token, registered);
212
211
  for (const prop of tokenProps) {
213
212
  if (!registeredProps.includes(prop)) return false;
214
213
  if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
@@ -264,6 +263,7 @@ var CoreRouter = class {
264
263
  static defaultConfigKey = Symbol.for("clear-router:default-config");
265
264
  static pluginStoreKey = Symbol.for("clear-router:plugins");
266
265
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
266
+ static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
267
267
  static createBaseConfig() {
268
268
  return {
269
269
  methodOverride: {
@@ -315,6 +315,11 @@ var CoreRouter = class {
315
315
  if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
316
316
  return g[this.pluginPendingKey];
317
317
  }
318
+ static getPluginArgumentResolvers() {
319
+ const g = globalThis;
320
+ if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
321
+ return g[this.pluginArgumentResolversKey];
322
+ }
318
323
  static createDefaultState() {
319
324
  return {
320
325
  config: this.getDefaultConfig(),
@@ -429,6 +434,9 @@ var CoreRouter = class {
429
434
  const ctx = {
430
435
  container: Container,
431
436
  bind: this.createPluginBind(),
437
+ resolveArguments: (resolver) => {
438
+ this.getPluginArgumentResolvers().add(resolver);
439
+ },
432
440
  bindings: Container.bindings(),
433
441
  configure: this.configure.bind(this),
434
442
  configureDefaults: this.configureDefaults.bind(this),
@@ -481,8 +489,7 @@ var CoreRouter = class {
481
489
  ctx,
482
490
  request,
483
491
  response,
484
- clearRequest: request,
485
- clearResponse: response
492
+ getBindings: () => Container.bindings()
486
493
  };
487
494
  }
488
495
  static createPluginBind() {
@@ -496,6 +503,18 @@ var CoreRouter = class {
496
503
  };
497
504
  return bind;
498
505
  }
506
+ static async resolvePluginArguments(ctx, routeContext) {
507
+ const resolvers = Array.from(this.getPluginArgumentResolvers());
508
+ if (!resolvers.length) return void 0;
509
+ const pluginContext = {
510
+ ...this.createPluginRequestContext(ctx),
511
+ ...routeContext
512
+ };
513
+ for (const resolver of resolvers) {
514
+ const args = await resolver(pluginContext);
515
+ if (Array.isArray(args)) return args;
516
+ }
517
+ }
499
518
  static ensureState() {
500
519
  this.bindStateAccessors();
501
520
  if (!this.config) this.config = { methodOverride: {
@@ -813,6 +832,7 @@ var CoreRouter = class {
813
832
  return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
814
833
  await this.pluginsReady();
815
834
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
835
+ const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
816
836
  const metadata = getBindingMetadataFromTargets([
817
837
  {
818
838
  target: bindingTarget,
@@ -824,9 +844,17 @@ var CoreRouter = class {
824
844
  propertyKey: "__class__"
825
845
  }
826
846
  ]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
847
+ const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
848
+ const pluginArgs = await this.resolvePluginArguments(ctx, {
849
+ target: bindingTarget,
850
+ method: bindingMethod,
851
+ handler: bindingHandler,
852
+ metadata: bindingMetadata,
853
+ tokens,
854
+ designTokens
855
+ });
856
+ if (pluginArgs) return handlerFunction(...pluginArgs);
827
857
  if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
828
- const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
829
- const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
830
858
  if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
831
859
  const args = [];
832
860
  for (const token of tokens) {
package/dist/index.d.cts CHANGED
@@ -153,14 +153,25 @@ interface ClearRouterPluginRequestContext {
153
153
  ctx: any;
154
154
  request: Request;
155
155
  response: Response$1;
156
+ getBindings: () => Record<string, BindValue>;
156
157
  [key: string]: any;
157
158
  }
159
+ interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
160
+ target?: object;
161
+ method?: PropertyKey;
162
+ handler?: object;
163
+ metadata?: object;
164
+ tokens: BindToken[];
165
+ designTokens: BindToken[];
166
+ }
158
167
  type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
159
168
  type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
160
169
  type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
170
+ type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
161
171
  interface ClearRouterPluginContext<Options = any> {
162
172
  container: typeof Container;
163
173
  bind: PluginBind;
174
+ resolveArguments: (resolver: PluginArgumentsResolver) => void;
164
175
  bindings: Record<string, BindValue>;
165
176
  configure: (options: RouterConfig) => void;
166
177
  configureDefaults: (options: RouterConfig) => void;
@@ -191,6 +202,7 @@ declare abstract class CoreRouter {
191
202
  private static readonly defaultConfigKey;
192
203
  private static readonly pluginStoreKey;
193
204
  private static readonly pluginPendingKey;
205
+ private static readonly pluginArgumentResolversKey;
194
206
  protected static createBaseConfig(): RouterConfig;
195
207
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
196
208
  protected static getDefaultConfig(): RouterConfig;
@@ -198,6 +210,7 @@ declare abstract class CoreRouter {
198
210
  protected static getStateStore(): Record<string, any>;
199
211
  protected static getPluginStore(): Set<string>;
200
212
  protected static getPluginPendingStore(): Set<Promise<void>>;
213
+ protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
201
214
  protected static createDefaultState(): {
202
215
  config: RouterConfig;
203
216
  groupContext: AsyncLocalStorage<{
@@ -239,6 +252,7 @@ declare abstract class CoreRouter {
239
252
  protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
240
253
  protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
241
254
  protected static createPluginBind(): PluginBind;
255
+ protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
242
256
  protected static ensureState(this: any): void;
243
257
  /**
244
258
  * Normalizes a path by ensuring it starts with a single slash and does not have trailing
@@ -394,4 +408,4 @@ declare abstract class CoreRouter {
394
408
  }): void;
395
409
  }
396
410
  //#endregion
397
- export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
411
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
package/dist/index.d.mts CHANGED
@@ -153,14 +153,25 @@ interface ClearRouterPluginRequestContext {
153
153
  ctx: any;
154
154
  request: Request;
155
155
  response: Response$1;
156
+ getBindings: () => Record<string, BindValue>;
156
157
  [key: string]: any;
157
158
  }
159
+ interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
160
+ target?: object;
161
+ method?: PropertyKey;
162
+ handler?: object;
163
+ metadata?: object;
164
+ tokens: BindToken[];
165
+ designTokens: BindToken[];
166
+ }
158
167
  type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
159
168
  type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
160
169
  type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
170
+ type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
161
171
  interface ClearRouterPluginContext<Options = any> {
162
172
  container: typeof Container;
163
173
  bind: PluginBind;
174
+ resolveArguments: (resolver: PluginArgumentsResolver) => void;
164
175
  bindings: Record<string, BindValue>;
165
176
  configure: (options: RouterConfig) => void;
166
177
  configureDefaults: (options: RouterConfig) => void;
@@ -191,6 +202,7 @@ declare abstract class CoreRouter {
191
202
  private static readonly defaultConfigKey;
192
203
  private static readonly pluginStoreKey;
193
204
  private static readonly pluginPendingKey;
205
+ private static readonly pluginArgumentResolversKey;
194
206
  protected static createBaseConfig(): RouterConfig;
195
207
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
196
208
  protected static getDefaultConfig(): RouterConfig;
@@ -198,6 +210,7 @@ declare abstract class CoreRouter {
198
210
  protected static getStateStore(): Record<string, any>;
199
211
  protected static getPluginStore(): Set<string>;
200
212
  protected static getPluginPendingStore(): Set<Promise<void>>;
213
+ protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
201
214
  protected static createDefaultState(): {
202
215
  config: RouterConfig;
203
216
  groupContext: AsyncLocalStorage<{
@@ -239,6 +252,7 @@ declare abstract class CoreRouter {
239
252
  protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
240
253
  protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
241
254
  protected static createPluginBind(): PluginBind;
255
+ protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
242
256
  protected static ensureState(this: any): void;
243
257
  /**
244
258
  * Normalizes a path by ensuring it starts with a single slash and does not have trailing
@@ -394,4 +408,4 @@ declare abstract class CoreRouter {
394
408
  }): void;
395
409
  }
396
410
  //#endregion
397
- export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
411
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
package/dist/index.mjs CHANGED
@@ -207,7 +207,6 @@ var Container = class {
207
207
  }
208
208
  static staticPropsMatch(token, registered, tokenProps, registeredProps) {
209
209
  if (tokenProps.length !== registeredProps.length) return false;
210
- console.log(token, registered);
211
210
  for (const prop of tokenProps) {
212
211
  if (!registeredProps.includes(prop)) return false;
213
212
  if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
@@ -263,6 +262,7 @@ var CoreRouter = class {
263
262
  static defaultConfigKey = Symbol.for("clear-router:default-config");
264
263
  static pluginStoreKey = Symbol.for("clear-router:plugins");
265
264
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
265
+ static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
266
266
  static createBaseConfig() {
267
267
  return {
268
268
  methodOverride: {
@@ -314,6 +314,11 @@ var CoreRouter = class {
314
314
  if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
315
315
  return g[this.pluginPendingKey];
316
316
  }
317
+ static getPluginArgumentResolvers() {
318
+ const g = globalThis;
319
+ if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
320
+ return g[this.pluginArgumentResolversKey];
321
+ }
317
322
  static createDefaultState() {
318
323
  return {
319
324
  config: this.getDefaultConfig(),
@@ -428,6 +433,9 @@ var CoreRouter = class {
428
433
  const ctx = {
429
434
  container: Container,
430
435
  bind: this.createPluginBind(),
436
+ resolveArguments: (resolver) => {
437
+ this.getPluginArgumentResolvers().add(resolver);
438
+ },
431
439
  bindings: Container.bindings(),
432
440
  configure: this.configure.bind(this),
433
441
  configureDefaults: this.configureDefaults.bind(this),
@@ -480,8 +488,7 @@ var CoreRouter = class {
480
488
  ctx,
481
489
  request,
482
490
  response,
483
- clearRequest: request,
484
- clearResponse: response
491
+ getBindings: () => Container.bindings()
485
492
  };
486
493
  }
487
494
  static createPluginBind() {
@@ -495,6 +502,18 @@ var CoreRouter = class {
495
502
  };
496
503
  return bind;
497
504
  }
505
+ static async resolvePluginArguments(ctx, routeContext) {
506
+ const resolvers = Array.from(this.getPluginArgumentResolvers());
507
+ if (!resolvers.length) return void 0;
508
+ const pluginContext = {
509
+ ...this.createPluginRequestContext(ctx),
510
+ ...routeContext
511
+ };
512
+ for (const resolver of resolvers) {
513
+ const args = await resolver(pluginContext);
514
+ if (Array.isArray(args)) return args;
515
+ }
516
+ }
498
517
  static ensureState() {
499
518
  this.bindStateAccessors();
500
519
  if (!this.config) this.config = { methodOverride: {
@@ -812,6 +831,7 @@ var CoreRouter = class {
812
831
  return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
813
832
  await this.pluginsReady();
814
833
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
834
+ const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
815
835
  const metadata = getBindingMetadataFromTargets([
816
836
  {
817
837
  target: bindingTarget,
@@ -823,9 +843,17 @@ var CoreRouter = class {
823
843
  propertyKey: "__class__"
824
844
  }
825
845
  ]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
846
+ const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
847
+ const pluginArgs = await this.resolvePluginArguments(ctx, {
848
+ target: bindingTarget,
849
+ method: bindingMethod,
850
+ handler: bindingHandler,
851
+ metadata: bindingMetadata,
852
+ tokens,
853
+ designTokens
854
+ });
855
+ if (pluginArgs) return handlerFunction(...pluginArgs);
826
856
  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
857
  if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
830
858
  const args = [];
831
859
  for (const token of tokens) {
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- require('../bindings--vhubKAz.cjs');
3
- const require_router = require('../router-CdchSCSK.cjs');
4
- const require_responses = require('../responses-DBIiiAmd.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DPJfzvy5.cjs');
4
+ const require_responses = require('../responses-CBP3RYjJ.cjs');
5
5
 
6
6
  //#region src/koa/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-35iBbCaF.cjs";
2
2
  import Koa from "koa";
3
3
  import Router$1 from "@koa/router";
4
4
 
@@ -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-91xVPlV0.mjs";
2
2
  import Koa from "koa";
3
3
  import Router$1 from "@koa/router";
4
4
 
@@ -1,6 +1,6 @@
1
- import "../bindings-BQMqEHcR.mjs";
2
- import { t as CoreRouter } from "../router-C04c3Lom.mjs";
3
- import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-BuQBx5wu.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
3
+ import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
4
4
 
5
5
  //#region src/koa/router.ts
6
6
  /**
@@ -1,4 +1,4 @@
1
- const require_bindings = require('./bindings--vhubKAz.cjs');
1
+ const require_bindings = require('./bindings-CDGLuAq4.cjs');
2
2
 
3
3
  //#region src/core/responses.ts
4
4
  function isFetchResponse(value) {
@@ -1,4 +1,4 @@
1
- import { s as Response } from "./bindings-BQMqEHcR.mjs";
1
+ import { s as Response } from "./bindings-B6x2HfzP.mjs";
2
2
 
3
3
  //#region src/core/responses.ts
4
4
  function isFetchResponse(value) {
@@ -195,14 +195,25 @@ interface ClearRouterPluginRequestContext {
195
195
  ctx: any;
196
196
  request: Request$1;
197
197
  response: Response$2;
198
+ getBindings: () => Record<string, BindValue>;
198
199
  [key: string]: any;
199
200
  }
201
+ interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
202
+ target?: object;
203
+ method?: PropertyKey;
204
+ handler?: object;
205
+ metadata?: object;
206
+ tokens: BindToken[];
207
+ designTokens: BindToken[];
208
+ }
200
209
  type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
201
210
  type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
202
211
  type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
212
+ type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
203
213
  interface ClearRouterPluginContext<Options = any> {
204
214
  container: typeof Container;
205
215
  bind: PluginBind;
216
+ resolveArguments: (resolver: PluginArgumentsResolver) => void;
206
217
  bindings: Record<string, BindValue>;
207
218
  configure: (options: RouterConfig) => void;
208
219
  configureDefaults: (options: RouterConfig) => void;
@@ -243,6 +254,7 @@ declare abstract class CoreRouter {
243
254
  private static readonly defaultConfigKey;
244
255
  private static readonly pluginStoreKey;
245
256
  private static readonly pluginPendingKey;
257
+ private static readonly pluginArgumentResolversKey;
246
258
  protected static createBaseConfig(): RouterConfig;
247
259
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
248
260
  protected static getDefaultConfig(): RouterConfig;
@@ -250,6 +262,7 @@ declare abstract class CoreRouter {
250
262
  protected static getStateStore(): Record<string, any>;
251
263
  protected static getPluginStore(): Set<string>;
252
264
  protected static getPluginPendingStore(): Set<Promise<void>>;
265
+ protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
253
266
  protected static createDefaultState(): {
254
267
  config: RouterConfig;
255
268
  groupContext: AsyncLocalStorage<{
@@ -291,6 +304,7 @@ declare abstract class CoreRouter {
291
304
  protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
292
305
  protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
293
306
  protected static createPluginBind(): PluginBind;
307
+ protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
294
308
  protected static ensureState(this: any): void;
295
309
  /**
296
310
  * Normalizes a path by ensuring it starts with a single slash and does not have trailing
@@ -446,4 +460,4 @@ declare abstract class CoreRouter {
446
460
  }): void;
447
461
  }
448
462
  //#endregion
449
- export { HttpMethod as C, ControllerHandler as S, Handler$1 as _, ClearRouterPluginRequestContext as a, ApiResourceMiddleware as b, PluginBindValue as c, Request$1 as d, Route as f, Middleware as g, HttpContext as h, ClearRouterPluginInput as i, PluginSetupResult as l, Handler as m, ClearRouterPlugin as n, PluginBind as o, H3App as p, ClearRouterPluginContext as r, PluginBindFactory as s, CoreRouter as t, definePlugin as u, HttpContext$1 as v, Response$2 as w, ControllerAction as x, Middleware$1 as y };
463
+ 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 };
@@ -195,14 +195,25 @@ interface ClearRouterPluginRequestContext {
195
195
  ctx: any;
196
196
  request: Request$1;
197
197
  response: Response$2;
198
+ getBindings: () => Record<string, BindValue>;
198
199
  [key: string]: any;
199
200
  }
201
+ interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
202
+ target?: object;
203
+ method?: PropertyKey;
204
+ handler?: object;
205
+ metadata?: object;
206
+ tokens: BindToken[];
207
+ designTokens: BindToken[];
208
+ }
200
209
  type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
201
210
  type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
202
211
  type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
212
+ type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
203
213
  interface ClearRouterPluginContext<Options = any> {
204
214
  container: typeof Container;
205
215
  bind: PluginBind;
216
+ resolveArguments: (resolver: PluginArgumentsResolver) => void;
206
217
  bindings: Record<string, BindValue>;
207
218
  configure: (options: RouterConfig) => void;
208
219
  configureDefaults: (options: RouterConfig) => void;
@@ -243,6 +254,7 @@ declare abstract class CoreRouter {
243
254
  private static readonly defaultConfigKey;
244
255
  private static readonly pluginStoreKey;
245
256
  private static readonly pluginPendingKey;
257
+ private static readonly pluginArgumentResolversKey;
246
258
  protected static createBaseConfig(): RouterConfig;
247
259
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
248
260
  protected static getDefaultConfig(): RouterConfig;
@@ -250,6 +262,7 @@ declare abstract class CoreRouter {
250
262
  protected static getStateStore(): Record<string, any>;
251
263
  protected static getPluginStore(): Set<string>;
252
264
  protected static getPluginPendingStore(): Set<Promise<void>>;
265
+ protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
253
266
  protected static createDefaultState(): {
254
267
  config: RouterConfig;
255
268
  groupContext: AsyncLocalStorage<{
@@ -291,6 +304,7 @@ declare abstract class CoreRouter {
291
304
  protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
292
305
  protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
293
306
  protected static createPluginBind(): PluginBind;
307
+ protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
294
308
  protected static ensureState(this: any): void;
295
309
  /**
296
310
  * Normalizes a path by ensuring it starts with a single slash and does not have trailing
@@ -446,4 +460,4 @@ declare abstract class CoreRouter {
446
460
  }): void;
447
461
  }
448
462
  //#endregion
449
- export { HttpMethod as C, ControllerHandler as S, Handler$1 as _, ClearRouterPluginRequestContext as a, ApiResourceMiddleware as b, PluginBindValue as c, Request$1 as d, Route as f, Middleware as g, HttpContext as h, ClearRouterPluginInput as i, PluginSetupResult as l, Handler as m, ClearRouterPlugin as n, PluginBind as o, H3App as p, ClearRouterPluginContext as r, PluginBindFactory as s, CoreRouter as t, definePlugin as u, HttpContext$1 as v, Response$2 as w, ControllerAction as x, Middleware$1 as y };
463
+ 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 };
@@ -1,4 +1,4 @@
1
- import { a as getStandardMetadata, c as Request, i as getDesignParamTypes, n as Container, o as isClass, r as getBindingMetadataFromTargets, s as Response } from "./bindings-BQMqEHcR.mjs";
1
+ import { a as getStandardMetadata, c as Request, i as getDesignParamTypes, n as Container, o as isClass, r as getBindingMetadataFromTargets, s as Response } from "./bindings-B6x2HfzP.mjs";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
 
4
4
  //#region src/Route.ts
@@ -43,6 +43,7 @@ var CoreRouter = class {
43
43
  static defaultConfigKey = Symbol.for("clear-router:default-config");
44
44
  static pluginStoreKey = Symbol.for("clear-router:plugins");
45
45
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
46
+ static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
46
47
  static createBaseConfig() {
47
48
  return {
48
49
  methodOverride: {
@@ -94,6 +95,11 @@ var CoreRouter = class {
94
95
  if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
95
96
  return g[this.pluginPendingKey];
96
97
  }
98
+ static getPluginArgumentResolvers() {
99
+ const g = globalThis;
100
+ if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
101
+ return g[this.pluginArgumentResolversKey];
102
+ }
97
103
  static createDefaultState() {
98
104
  return {
99
105
  config: this.getDefaultConfig(),
@@ -208,6 +214,9 @@ var CoreRouter = class {
208
214
  const ctx = {
209
215
  container: Container,
210
216
  bind: this.createPluginBind(),
217
+ resolveArguments: (resolver) => {
218
+ this.getPluginArgumentResolvers().add(resolver);
219
+ },
211
220
  bindings: Container.bindings(),
212
221
  configure: this.configure.bind(this),
213
222
  configureDefaults: this.configureDefaults.bind(this),
@@ -260,8 +269,7 @@ var CoreRouter = class {
260
269
  ctx,
261
270
  request,
262
271
  response,
263
- clearRequest: request,
264
- clearResponse: response
272
+ getBindings: () => Container.bindings()
265
273
  };
266
274
  }
267
275
  static createPluginBind() {
@@ -275,6 +283,18 @@ var CoreRouter = class {
275
283
  };
276
284
  return bind;
277
285
  }
286
+ static async resolvePluginArguments(ctx, routeContext) {
287
+ const resolvers = Array.from(this.getPluginArgumentResolvers());
288
+ if (!resolvers.length) return void 0;
289
+ const pluginContext = {
290
+ ...this.createPluginRequestContext(ctx),
291
+ ...routeContext
292
+ };
293
+ for (const resolver of resolvers) {
294
+ const args = await resolver(pluginContext);
295
+ if (Array.isArray(args)) return args;
296
+ }
297
+ }
278
298
  static ensureState() {
279
299
  this.bindStateAccessors();
280
300
  if (!this.config) this.config = { methodOverride: {
@@ -592,6 +612,7 @@ var CoreRouter = class {
592
612
  return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
593
613
  await this.pluginsReady();
594
614
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
615
+ const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
595
616
  const metadata = getBindingMetadataFromTargets([
596
617
  {
597
618
  target: bindingTarget,
@@ -603,9 +624,17 @@ var CoreRouter = class {
603
624
  propertyKey: "__class__"
604
625
  }
605
626
  ]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
627
+ const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
628
+ const pluginArgs = await this.resolvePluginArguments(ctx, {
629
+ target: bindingTarget,
630
+ method: bindingMethod,
631
+ handler: bindingHandler,
632
+ metadata: bindingMetadata,
633
+ tokens,
634
+ designTokens
635
+ });
636
+ if (pluginArgs) return handlerFunction(...pluginArgs);
606
637
  if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
607
- const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
608
- const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
609
638
  if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
610
639
  const args = [];
611
640
  for (const token of tokens) {
@@ -1,4 +1,4 @@
1
- const require_bindings = require('./bindings--vhubKAz.cjs');
1
+ const require_bindings = require('./bindings-CDGLuAq4.cjs');
2
2
  let node_async_hooks = require("node:async_hooks");
3
3
 
4
4
  //#region src/Route.ts
@@ -43,6 +43,7 @@ var CoreRouter = class {
43
43
  static defaultConfigKey = Symbol.for("clear-router:default-config");
44
44
  static pluginStoreKey = Symbol.for("clear-router:plugins");
45
45
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
46
+ static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
46
47
  static createBaseConfig() {
47
48
  return {
48
49
  methodOverride: {
@@ -94,6 +95,11 @@ var CoreRouter = class {
94
95
  if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
95
96
  return g[this.pluginPendingKey];
96
97
  }
98
+ static getPluginArgumentResolvers() {
99
+ const g = globalThis;
100
+ if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
101
+ return g[this.pluginArgumentResolversKey];
102
+ }
97
103
  static createDefaultState() {
98
104
  return {
99
105
  config: this.getDefaultConfig(),
@@ -208,6 +214,9 @@ var CoreRouter = class {
208
214
  const ctx = {
209
215
  container: require_bindings.Container,
210
216
  bind: this.createPluginBind(),
217
+ resolveArguments: (resolver) => {
218
+ this.getPluginArgumentResolvers().add(resolver);
219
+ },
211
220
  bindings: require_bindings.Container.bindings(),
212
221
  configure: this.configure.bind(this),
213
222
  configureDefaults: this.configureDefaults.bind(this),
@@ -260,8 +269,7 @@ var CoreRouter = class {
260
269
  ctx,
261
270
  request,
262
271
  response,
263
- clearRequest: request,
264
- clearResponse: response
272
+ getBindings: () => require_bindings.Container.bindings()
265
273
  };
266
274
  }
267
275
  static createPluginBind() {
@@ -275,6 +283,18 @@ var CoreRouter = class {
275
283
  };
276
284
  return bind;
277
285
  }
286
+ static async resolvePluginArguments(ctx, routeContext) {
287
+ const resolvers = Array.from(this.getPluginArgumentResolvers());
288
+ if (!resolvers.length) return void 0;
289
+ const pluginContext = {
290
+ ...this.createPluginRequestContext(ctx),
291
+ ...routeContext
292
+ };
293
+ for (const resolver of resolvers) {
294
+ const args = await resolver(pluginContext);
295
+ if (Array.isArray(args)) return args;
296
+ }
297
+ }
278
298
  static ensureState() {
279
299
  this.bindStateAccessors();
280
300
  if (!this.config) this.config = { methodOverride: {
@@ -592,6 +612,7 @@ var CoreRouter = class {
592
612
  return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
593
613
  await this.pluginsReady();
594
614
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
615
+ const designTokens = [...bindingTarget ? require_bindings.getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? require_bindings.getDesignParamTypes(bindingHandler) : []];
595
616
  const metadata = require_bindings.getBindingMetadataFromTargets([
596
617
  {
597
618
  target: bindingTarget,
@@ -603,9 +624,17 @@ var CoreRouter = class {
603
624
  propertyKey: "__class__"
604
625
  }
605
626
  ]) ?? require_bindings.getStandardMetadata(bindingMetadata, bindingMethod) ?? require_bindings.getStandardMetadata(bindingMetadata, "__class__");
627
+ const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
628
+ const pluginArgs = await this.resolvePluginArguments(ctx, {
629
+ target: bindingTarget,
630
+ method: bindingMethod,
631
+ handler: bindingHandler,
632
+ metadata: bindingMetadata,
633
+ tokens,
634
+ designTokens
635
+ });
636
+ if (pluginArgs) return handlerFunction(...pluginArgs);
606
637
  if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
607
- const designTokens = [...bindingTarget ? require_bindings.getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? require_bindings.getDesignParamTypes(bindingHandler) : []];
608
- const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
609
638
  if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
610
639
  const args = [];
611
640
  for (const token of tokens) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.5.10",
3
+ "version": "2.5.12",
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",