clear-router 2.5.6 → 2.5.8

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-DIanvIVd.mjs → bindings-DJDdQv1q.mjs} +1 -1
  2. package/dist/{bindings-DvV2DXWi.cjs → bindings-T0FKpWyi.cjs} +6 -0
  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 +94 -32
  28. package/dist/index.d.cts +23 -4
  29. package/dist/index.d.mts +23 -4
  30. package/dist/index.mjs +94 -32
  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-_II3dOJ5.mjs → responses-B184V5nj.mjs} +1 -1
  36. package/dist/{responses-JzXstGU5.cjs → responses-CfCmLLo9.cjs} +1 -1
  37. package/dist/{router-DCMtQ_Xi.d.mts → router-B8l8jerS.d.mts} +23 -4
  38. package/dist/{router-BYZmNzrZ.d.cts → router-CiGcLUZD.d.cts} +23 -4
  39. package/dist/{router-CU4V1kX0.cjs → router-DbPFGTYG.cjs} +95 -33
  40. package/dist/{router-B3QjblRX.mjs → router-we2Hw9nA.mjs} +95 -33
  41. package/package.json +5 -5
@@ -208,4 +208,4 @@ function isClass(value) {
208
208
  }
209
209
 
210
210
  //#endregion
211
- export { getStandardMetadata as a, getDesignParamTypes as i, Container as n, Response as o, getBindingMetadataFromTargets as r, Request as s, Bind as t };
211
+ export { getStandardMetadata as a, Request as c, getDesignParamTypes as i, Container as n, isClass as o, getBindingMetadataFromTargets as r, Response as s, Bind as t };
@@ -250,4 +250,10 @@ Object.defineProperty(exports, 'getStandardMetadata', {
250
250
  get: function () {
251
251
  return getStandardMetadata;
252
252
  }
253
+ });
254
+ Object.defineProperty(exports, 'isClass', {
255
+ enumerable: true,
256
+ get: function () {
257
+ return isClass;
258
+ }
253
259
  });
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_bindings = require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CU4V1kX0.cjs');
2
+ const require_bindings = require('../bindings-T0FKpWyi.cjs');
3
+ const require_router = require('../router-DbPFGTYG.cjs');
4
4
 
5
5
  //#region src/core/plugins.ts
6
6
  function definePlugin(plugin) {
@@ -1,2 +1,2 @@
1
- import { a as PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-BYZmNzrZ.cjs";
2
- export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
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-CiGcLUZD.cjs";
2
+ export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
@@ -1,2 +1,2 @@
1
- import { a as PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-DCMtQ_Xi.mjs";
2
- export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
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-B8l8jerS.mjs";
2
+ export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
@@ -1,5 +1,5 @@
1
- import { o as Response, s as Request } from "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-B3QjblRX.mjs";
1
+ import { c as Request, s as Response } from "../bindings-DJDdQv1q.mjs";
2
+ import { t as CoreRouter } from "../router-we2Hw9nA.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-DvV2DXWi.cjs');
2
+ const require_bindings = require('../bindings-T0FKpWyi.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-DIanvIVd.mjs";
1
+ import { n as Container, t as Bind } from "../bindings-DJDdQv1q.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-DvV2DXWi.cjs');
3
- const require_router = require('../router-CU4V1kX0.cjs');
2
+ const require_bindings = require('../bindings-T0FKpWyi.cjs');
3
+ const require_router = require('../router-DbPFGTYG.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-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-B3QjblRX.mjs";
1
+ import { n as Container, t as Bind } from "../bindings-DJDdQv1q.mjs";
2
+ import { t as CoreRouter } from "../router-we2Hw9nA.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-DvV2DXWi.cjs');
3
- const require_router = require('../router-CU4V1kX0.cjs');
4
- const require_responses = require('../responses-JzXstGU5.cjs');
2
+ require('../bindings-T0FKpWyi.cjs');
3
+ const require_router = require('../router-DbPFGTYG.cjs');
4
+ const require_responses = require('../responses-CfCmLLo9.cjs');
5
5
 
6
6
  //#region src/express/router.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { _ as ApiResourceMiddleware, b as HttpMethod, g as Middleware, h as HttpContext, l as Route, m as Handler, t as CoreRouter, v as ControllerAction } from "../router-BYZmNzrZ.cjs";
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-CiGcLUZD.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 { _ as ApiResourceMiddleware, b as HttpMethod, g as Middleware, h as HttpContext, l as Route, m as Handler, t as CoreRouter, v as ControllerAction } from "../router-DCMtQ_Xi.mjs";
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-B8l8jerS.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-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-B3QjblRX.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-_II3dOJ5.mjs";
1
+ import "../bindings-DJDdQv1q.mjs";
2
+ import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-B184V5nj.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-DvV2DXWi.cjs');
3
- const require_router = require('../router-CU4V1kX0.cjs');
4
- const require_responses = require('../responses-JzXstGU5.cjs');
2
+ require('../bindings-T0FKpWyi.cjs');
3
+ const require_router = require('../router-DbPFGTYG.cjs');
4
+ const require_responses = require('../responses-CfCmLLo9.cjs');
5
5
 
6
6
  //#region src/fastify/router.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-BYZmNzrZ.cjs";
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-CiGcLUZD.cjs";
2
2
  import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
3
 
4
4
  //#region types/fastify.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-DCMtQ_Xi.mjs";
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-B8l8jerS.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-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-B3QjblRX.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-_II3dOJ5.mjs";
1
+ import "../bindings-DJDdQv1q.mjs";
2
+ import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-B184V5nj.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-DvV2DXWi.cjs');
3
- const require_router = require('../router-CU4V1kX0.cjs');
4
- const require_responses = require('../responses-JzXstGU5.cjs');
2
+ require('../bindings-T0FKpWyi.cjs');
3
+ const require_router = require('../router-DbPFGTYG.cjs');
4
+ const require_responses = require('../responses-CfCmLLo9.cjs');
5
5
  let h3 = require("h3");
6
6
 
7
7
  //#region src/h3/router.ts
@@ -1,4 +1,4 @@
1
- import { _ as ApiResourceMiddleware, b as HttpMethod, d as Handler, f as HttpContext, l as Route, p as Middleware, t as CoreRouter, u as H3App, v as ControllerAction } from "../router-BYZmNzrZ.cjs";
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-CiGcLUZD.cjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as ApiResourceMiddleware, b as HttpMethod, d as Handler, f as HttpContext, l as Route, p as Middleware, t as CoreRouter, u as H3App, v as ControllerAction } from "../router-DCMtQ_Xi.mjs";
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-B8l8jerS.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-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-B3QjblRX.mjs";
3
- import { n as resolveResponseMeta } from "../responses-_II3dOJ5.mjs";
1
+ import "../bindings-DJDdQv1q.mjs";
2
+ import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
3
+ import { n as resolveResponseMeta } from "../responses-B184V5nj.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-DvV2DXWi.cjs');
3
- const require_router = require('../router-CU4V1kX0.cjs');
4
- const require_responses = require('../responses-JzXstGU5.cjs');
2
+ require('../bindings-T0FKpWyi.cjs');
3
+ const require_router = require('../router-DbPFGTYG.cjs');
4
+ const require_responses = require('../responses-CfCmLLo9.cjs');
5
5
 
6
6
  //#region src/hono/router.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-BYZmNzrZ.cjs";
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-CiGcLUZD.cjs";
2
2
  import { Context, HonoRequest, MiddlewareHandler } from "hono";
3
3
 
4
4
  //#region types/hono.d.ts
@@ -1,4 +1,4 @@
1
- import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-DCMtQ_Xi.mjs";
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-B8l8jerS.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-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-B3QjblRX.mjs";
3
- import { n as resolveResponseMeta } from "../responses-_II3dOJ5.mjs";
1
+ import "../bindings-DJDdQv1q.mjs";
2
+ import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
3
+ import { n as resolveResponseMeta } from "../responses-B184V5nj.mjs";
4
4
 
5
5
  //#region src/hono/router.ts
6
6
  /**
package/dist/index.cjs CHANGED
@@ -219,6 +219,7 @@ var CoreRouter = class {
219
219
  static stateBoundKey = Symbol.for("clear-router:router-state-bound");
220
220
  static defaultConfigKey = Symbol.for("clear-router:default-config");
221
221
  static pluginStoreKey = Symbol.for("clear-router:plugins");
222
+ static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
222
223
  static createBaseConfig() {
223
224
  return {
224
225
  methodOverride: {
@@ -265,6 +266,11 @@ var CoreRouter = class {
265
266
  if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
266
267
  return g[this.pluginStoreKey];
267
268
  }
269
+ static getPluginPendingStore() {
270
+ const g = globalThis;
271
+ if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
272
+ return g[this.pluginPendingKey];
273
+ }
268
274
  static createDefaultState() {
269
275
  return {
270
276
  config: this.getDefaultConfig(),
@@ -370,28 +376,81 @@ var CoreRouter = class {
370
376
  * @param options
371
377
  * @returns
372
378
  */
373
- static use(plugin, options) {
379
+ static async use(plugin, options) {
374
380
  const name = typeof plugin === "function" ? plugin.name : plugin.name;
375
381
  const store = this.getPluginStore();
376
382
  if (name && store.has(name)) return;
377
- const ctx = {
378
- container: Container,
379
- bind: Container.bind.bind(Container),
380
- configure: this.configure.bind(this),
381
- configureDefaults: this.configureDefaults.bind(this),
382
- options
383
- };
384
- if (typeof plugin === "function") plugin(ctx);
385
- else plugin.setup(ctx);
386
383
  if (name) store.add(name);
384
+ const setup = async () => {
385
+ const ctx = {
386
+ container: Container,
387
+ bind: this.createPluginBind(),
388
+ configure: this.configure.bind(this),
389
+ configureDefaults: this.configureDefaults.bind(this),
390
+ get request() {
391
+ return this.getRequest();
392
+ },
393
+ get response() {
394
+ return this.getResponse();
395
+ },
396
+ getRequest: () => this.getCurrentPluginRequestContext()?.request,
397
+ getResponse: () => this.getCurrentPluginRequestContext()?.response,
398
+ options
399
+ };
400
+ if (typeof plugin === "function") await plugin(ctx);
401
+ else await plugin.setup(ctx);
402
+ };
403
+ const pending = this.getPluginPendingStore();
404
+ const promise = setup();
405
+ pending.add(promise);
406
+ try {
407
+ await promise;
408
+ } catch (error) {
409
+ if (name) store.delete(name);
410
+ throw error;
411
+ } finally {
412
+ pending.delete(promise);
413
+ }
414
+ }
415
+ static async pluginsReady() {
416
+ const pending = Array.from(this.getPluginPendingStore());
417
+ if (!pending.length) return;
418
+ await Promise.all(pending);
387
419
  }
388
420
  static groupContext = new node_async_hooks.AsyncLocalStorage();
421
+ static pluginRequestContext = new node_async_hooks.AsyncLocalStorage();
389
422
  static routes = [];
390
423
  static routesByPathMethod = {};
391
424
  static routesByMethod = {};
392
425
  static prefix = "";
393
426
  static groupMiddlewares = [];
394
427
  static globalMiddlewares = [];
428
+ static getCurrentPluginRequestContext() {
429
+ return this.pluginRequestContext.getStore();
430
+ }
431
+ static createPluginRequestContext(ctx) {
432
+ const request = ctx.clearRequest;
433
+ const response = ctx.clearResponse;
434
+ return {
435
+ ...ctx,
436
+ ctx,
437
+ request,
438
+ response,
439
+ clearRequest: request,
440
+ clearResponse: response
441
+ };
442
+ }
443
+ static createPluginBind() {
444
+ const bind = (token, value) => {
445
+ if (typeof value === "function" && !isClass(value)) {
446
+ const factory = value;
447
+ Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
448
+ return;
449
+ }
450
+ Container.bind(token, value);
451
+ };
452
+ return bind;
453
+ }
395
454
  static ensureState() {
396
455
  this.bindStateAccessors();
397
456
  if (!this.config) this.config = { methodOverride: {
@@ -706,29 +765,32 @@ var CoreRouter = class {
706
765
  };
707
766
  }
708
767
  static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
709
- if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
710
- const metadata = getBindingMetadataFromTargets([
711
- {
712
- target: bindingTarget,
713
- propertyKey: bindingMethod
714
- },
715
- { target: bindingHandler },
716
- {
717
- target: bindingTarget,
718
- propertyKey: "__class__"
768
+ return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
769
+ await this.pluginsReady();
770
+ if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
771
+ const metadata = getBindingMetadataFromTargets([
772
+ {
773
+ target: bindingTarget,
774
+ propertyKey: bindingMethod
775
+ },
776
+ { target: bindingHandler },
777
+ {
778
+ target: bindingTarget,
779
+ propertyKey: "__class__"
780
+ }
781
+ ]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
782
+ if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
783
+ const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
784
+ const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
785
+ if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
786
+ const args = [];
787
+ for (const token of tokens) {
788
+ const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
789
+ if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
790
+ args.push(resolved);
719
791
  }
720
- ]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
721
- if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
722
- const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
723
- const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
724
- if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
725
- const args = [];
726
- for (const token of tokens) {
727
- const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
728
- if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
729
- args.push(resolved);
730
- }
731
- return handlerFunction(...args);
792
+ return handlerFunction(...args);
793
+ });
732
794
  }
733
795
  static bindRequestToInstance(ctx, instance, route, payload) {
734
796
  const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
package/dist/index.d.cts CHANGED
@@ -143,13 +143,25 @@ declare class Container {
143
143
  }
144
144
  //#endregion
145
145
  //#region src/core/plugins.d.ts
146
- type PluginSetupResult = void;
147
- type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
146
+ type PluginSetupResult = void | Promise<void>;
147
+ interface ClearRouterPluginRequestContext {
148
+ ctx: any;
149
+ request: Request;
150
+ response: Response$1;
151
+ [key: string]: any;
152
+ }
153
+ type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
154
+ type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
155
+ type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
148
156
  interface ClearRouterPluginContext<Options = any> {
149
157
  container: typeof Container;
150
158
  bind: PluginBind;
151
159
  configure: (options: RouterConfig) => void;
152
160
  configureDefaults: (options: RouterConfig) => void;
161
+ readonly request?: Request;
162
+ readonly response?: Response$1;
163
+ getRequest: () => Request | undefined;
164
+ getResponse: () => Response$1 | undefined;
153
165
  options: Options;
154
166
  }
155
167
  interface ClearRouterPlugin<Options = any> {
@@ -172,12 +184,14 @@ declare abstract class CoreRouter {
172
184
  private static readonly stateBoundKey;
173
185
  private static readonly defaultConfigKey;
174
186
  private static readonly pluginStoreKey;
187
+ private static readonly pluginPendingKey;
175
188
  protected static createBaseConfig(): RouterConfig;
176
189
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
177
190
  protected static getDefaultConfig(): RouterConfig;
178
191
  protected static resolveStateNamespace(this: any): string;
179
192
  protected static getStateStore(): Record<string, any>;
180
193
  protected static getPluginStore(): Set<string>;
194
+ protected static getPluginPendingStore(): Set<Promise<void>>;
181
195
  protected static createDefaultState(): {
182
196
  config: RouterConfig;
183
197
  groupContext: AsyncLocalStorage<{
@@ -203,17 +217,22 @@ declare abstract class CoreRouter {
203
217
  * @param options
204
218
  * @returns
205
219
  */
206
- static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): void;
220
+ static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
221
+ protected static pluginsReady(this: any): Promise<void>;
207
222
  protected static groupContext: AsyncLocalStorage<{
208
223
  prefix: string;
209
224
  groupMiddlewares: any[];
210
225
  }>;
226
+ protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
211
227
  static routes: Array<Route<any, any, any>>;
212
228
  static routesByPathMethod: Record<string, Route<any, any, any>>;
213
229
  static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
214
230
  static prefix: string;
215
231
  static groupMiddlewares: any[];
216
232
  static globalMiddlewares: any[];
233
+ protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
234
+ protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
235
+ protected static createPluginBind(): PluginBind;
217
236
  protected static ensureState(this: any): void;
218
237
  /**
219
238
  * Normalizes a path by ensuring it starts with a single slash and does not have trailing
@@ -369,4 +388,4 @@ declare abstract class CoreRouter {
369
388
  }): void;
370
389
  }
371
390
  //#endregion
372
- export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
391
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
package/dist/index.d.mts CHANGED
@@ -143,13 +143,25 @@ declare class Container {
143
143
  }
144
144
  //#endregion
145
145
  //#region src/core/plugins.d.ts
146
- type PluginSetupResult = void;
147
- type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
146
+ type PluginSetupResult = void | Promise<void>;
147
+ interface ClearRouterPluginRequestContext {
148
+ ctx: any;
149
+ request: Request;
150
+ response: Response$1;
151
+ [key: string]: any;
152
+ }
153
+ type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
154
+ type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
155
+ type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
148
156
  interface ClearRouterPluginContext<Options = any> {
149
157
  container: typeof Container;
150
158
  bind: PluginBind;
151
159
  configure: (options: RouterConfig) => void;
152
160
  configureDefaults: (options: RouterConfig) => void;
161
+ readonly request?: Request;
162
+ readonly response?: Response$1;
163
+ getRequest: () => Request | undefined;
164
+ getResponse: () => Response$1 | undefined;
153
165
  options: Options;
154
166
  }
155
167
  interface ClearRouterPlugin<Options = any> {
@@ -172,12 +184,14 @@ declare abstract class CoreRouter {
172
184
  private static readonly stateBoundKey;
173
185
  private static readonly defaultConfigKey;
174
186
  private static readonly pluginStoreKey;
187
+ private static readonly pluginPendingKey;
175
188
  protected static createBaseConfig(): RouterConfig;
176
189
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
177
190
  protected static getDefaultConfig(): RouterConfig;
178
191
  protected static resolveStateNamespace(this: any): string;
179
192
  protected static getStateStore(): Record<string, any>;
180
193
  protected static getPluginStore(): Set<string>;
194
+ protected static getPluginPendingStore(): Set<Promise<void>>;
181
195
  protected static createDefaultState(): {
182
196
  config: RouterConfig;
183
197
  groupContext: AsyncLocalStorage<{
@@ -203,17 +217,22 @@ declare abstract class CoreRouter {
203
217
  * @param options
204
218
  * @returns
205
219
  */
206
- static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): void;
220
+ static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
221
+ protected static pluginsReady(this: any): Promise<void>;
207
222
  protected static groupContext: AsyncLocalStorage<{
208
223
  prefix: string;
209
224
  groupMiddlewares: any[];
210
225
  }>;
226
+ protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
211
227
  static routes: Array<Route<any, any, any>>;
212
228
  static routesByPathMethod: Record<string, Route<any, any, any>>;
213
229
  static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
214
230
  static prefix: string;
215
231
  static groupMiddlewares: any[];
216
232
  static globalMiddlewares: any[];
233
+ protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
234
+ protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
235
+ protected static createPluginBind(): PluginBind;
217
236
  protected static ensureState(this: any): void;
218
237
  /**
219
238
  * Normalizes a path by ensuring it starts with a single slash and does not have trailing
@@ -369,4 +388,4 @@ declare abstract class CoreRouter {
369
388
  }): void;
370
389
  }
371
390
  //#endregion
372
- export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
391
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };