clear-router 2.5.5 → 2.5.7

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/README.md +1 -0
  2. package/dist/core/index.cjs +9 -2
  3. package/dist/core/index.d.cts +2 -2
  4. package/dist/core/index.d.mts +2 -2
  5. package/dist/core/index.mjs +8 -2
  6. package/dist/decorators/index.d.cts +1 -1
  7. package/dist/decorators/index.d.mts +1 -1
  8. package/dist/decorators/setup.cjs +1 -1
  9. package/dist/decorators/setup.d.cts +1 -1
  10. package/dist/decorators/setup.d.mts +1 -1
  11. package/dist/decorators/setup.mjs +1 -1
  12. package/dist/express/index.cjs +1 -1
  13. package/dist/express/index.d.cts +1 -1
  14. package/dist/express/index.d.mts +1 -1
  15. package/dist/express/index.mjs +1 -1
  16. package/dist/fastify/index.cjs +1 -1
  17. package/dist/fastify/index.d.cts +1 -1
  18. package/dist/fastify/index.d.mts +1 -1
  19. package/dist/fastify/index.mjs +1 -1
  20. package/dist/h3/index.cjs +1 -1
  21. package/dist/h3/index.d.cts +1 -1
  22. package/dist/h3/index.d.mts +1 -1
  23. package/dist/h3/index.mjs +1 -1
  24. package/dist/hono/index.cjs +1 -1
  25. package/dist/hono/index.d.cts +1 -1
  26. package/dist/hono/index.d.mts +1 -1
  27. package/dist/hono/index.mjs +1 -1
  28. package/dist/index.cjs +62 -1
  29. package/dist/index.d.cts +46 -1
  30. package/dist/index.d.mts +46 -1
  31. package/dist/index.mjs +61 -1
  32. package/dist/koa/index.cjs +1 -1
  33. package/dist/koa/index.d.cts +1 -1
  34. package/dist/koa/index.d.mts +1 -1
  35. package/dist/koa/index.mjs +1 -1
  36. package/dist/{router-CCUF5FE7.cjs → router-BdMuUzGU.cjs} +54 -0
  37. package/dist/{router-BdfAh1me.d.mts → router-D7R3G8w-.d.mts} +33 -1
  38. package/dist/{router-BAWdklDQ.mjs → router-DzbF-ZV0.mjs} +54 -0
  39. package/dist/{router-78fDk87B.d.cts → router-WAxKAcWR.d.cts} +33 -1
  40. package/package.json +1 -1
  41. /package/dist/{bindings-BL1d0dFY.d.cts → bindings-CV1e5jho.d.mts} +0 -0
  42. /package/dist/{bindings-DqvZ9-YW.d.mts → bindings-NV0CdqGl.d.cts} +0 -0
package/README.md CHANGED
@@ -51,6 +51,7 @@ yarn add clear-router express
51
51
  - `clearRequest` is passed as second handler argument for controller handlers
52
52
  - Route handlers can return response values directly across Express, Fastify, Hono, H3, and Koa
53
53
  - Optional decorated container binding for controller method arguments
54
+ - Plugin API for registering container bindings from external packages
54
55
  - Supports TS 5.2+ standard decorators with explicit `@Bind(...)` tokens
55
56
  - Optional `clear-router/decorators/setup` entry imports `reflect-metadata` and enables container binding defaults
56
57
  - Auto-binds controller methods
@@ -1,7 +1,14 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_bindings = require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CCUF5FE7.cjs');
3
+ const require_router = require('../router-BdMuUzGU.cjs');
4
4
 
5
+ //#region src/core/plugins.ts
6
+ function definePlugin(plugin) {
7
+ return plugin;
8
+ }
9
+
10
+ //#endregion
5
11
  exports.CoreRouter = require_router.CoreRouter;
6
12
  exports.Request = require_bindings.Request;
7
- exports.Response = require_bindings.Response;
13
+ exports.Response = require_bindings.Response;
14
+ exports.definePlugin = definePlugin;
@@ -1,2 +1,2 @@
1
- import { h as Response, n as Request, t as CoreRouter } from "../router-78fDk87B.cjs";
2
- export { CoreRouter, Request, Response };
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-WAxKAcWR.cjs";
2
+ export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
@@ -1,2 +1,2 @@
1
- import { h as Response, n as Request, t as CoreRouter } from "../router-BdfAh1me.mjs";
2
- export { CoreRouter, Request, Response };
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-D7R3G8w-.mjs";
2
+ export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
@@ -1,4 +1,10 @@
1
1
  import { o as Response, s as Request } from "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-BAWdklDQ.mjs";
2
+ import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
3
3
 
4
- export { CoreRouter, Request, Response };
4
+ //#region src/core/plugins.ts
5
+ function definePlugin(plugin) {
6
+ return plugin;
7
+ }
8
+
9
+ //#endregion
10
+ export { CoreRouter, Request, Response, definePlugin };
@@ -1,2 +1,2 @@
1
- import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-BL1d0dFY.cjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-NV0CdqGl.cjs";
2
2
  export { Bind, type BindDecorator, type BindFactory, type BindToken, type BindValue, Container };
@@ -1,2 +1,2 @@
1
- import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-DqvZ9-YW.mjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-CV1e5jho.mjs";
2
2
  export { Bind, type BindDecorator, type BindFactory, type BindToken, type BindValue, Container };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_bindings = require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CCUF5FE7.cjs');
3
+ const require_router = require('../router-BdMuUzGU.cjs');
4
4
  require('./index.cjs');
5
5
  require("reflect-metadata");
6
6
 
@@ -1,2 +1,2 @@
1
- import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-BL1d0dFY.cjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-NV0CdqGl.cjs";
2
2
  export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
@@ -1,2 +1,2 @@
1
- import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-DqvZ9-YW.mjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-CV1e5jho.mjs";
2
2
  export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
@@ -1,5 +1,5 @@
1
1
  import { n as Container, t as Bind } from "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-BAWdklDQ.mjs";
2
+ import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
3
3
  import "./index.mjs";
4
4
  import "reflect-metadata";
5
5
 
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CCUF5FE7.cjs');
3
+ const require_router = require('../router-BdMuUzGU.cjs');
4
4
  const require_responses = require('../responses-JzXstGU5.cjs');
5
5
 
6
6
  //#region src/express/router.ts
@@ -1,4 +1,4 @@
1
- import { c as Handler, d as ApiResourceMiddleware, f as ControllerAction, l as HttpContext, m as HttpMethod, r as Route, t as CoreRouter, u as Middleware } from "../router-78fDk87B.cjs";
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-WAxKAcWR.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 Handler, d as ApiResourceMiddleware, f as ControllerAction, l as HttpContext, m as HttpMethod, r as Route, t as CoreRouter, u as Middleware } from "../router-BdfAh1me.mjs";
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-D7R3G8w-.mjs";
2
2
  import { Router as Router$1 } from "express";
3
3
 
4
4
  //#region src/express/router.d.ts
@@ -1,5 +1,5 @@
1
1
  import "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-BAWdklDQ.mjs";
2
+ import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
3
3
  import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-_II3dOJ5.mjs";
4
4
 
5
5
  //#region src/express/router.ts
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CCUF5FE7.cjs');
3
+ const require_router = require('../router-BdMuUzGU.cjs');
4
4
  const require_responses = require('../responses-JzXstGU5.cjs');
5
5
 
6
6
  //#region src/fastify/router.ts
@@ -1,4 +1,4 @@
1
- import { d as ApiResourceMiddleware, f as ControllerAction, h as Response, m as HttpMethod, n as Request, p as ControllerHandler, r as Route, t as CoreRouter } from "../router-78fDk87B.cjs";
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-WAxKAcWR.cjs";
2
2
  import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
3
 
4
4
  //#region types/fastify.d.ts
@@ -1,4 +1,4 @@
1
- import { d as ApiResourceMiddleware, f as ControllerAction, h as Response, m as HttpMethod, n as Request, p as ControllerHandler, r as Route, t as CoreRouter } from "../router-BdfAh1me.mjs";
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-D7R3G8w-.mjs";
2
2
  import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
3
3
 
4
4
  //#region types/fastify.d.ts
@@ -1,5 +1,5 @@
1
1
  import "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-BAWdklDQ.mjs";
2
+ import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
3
3
  import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-_II3dOJ5.mjs";
4
4
 
5
5
  //#region src/fastify/router.ts
package/dist/h3/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CCUF5FE7.cjs');
3
+ const require_router = require('../router-BdMuUzGU.cjs');
4
4
  const require_responses = require('../responses-JzXstGU5.cjs');
5
5
  let h3 = require("h3");
6
6
 
@@ -1,4 +1,4 @@
1
- import { a as Handler, d as ApiResourceMiddleware, f as ControllerAction, i as H3App, m as HttpMethod, o as HttpContext, r as Route, s as Middleware, t as CoreRouter } from "../router-78fDk87B.cjs";
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-WAxKAcWR.cjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
@@ -1,4 +1,4 @@
1
- import { a as Handler, d as ApiResourceMiddleware, f as ControllerAction, i as H3App, m as HttpMethod, o as HttpContext, r as Route, s as Middleware, t as CoreRouter } from "../router-BdfAh1me.mjs";
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-D7R3G8w-.mjs";
2
2
  import { H3 } from "h3";
3
3
 
4
4
  //#region src/h3/router.d.ts
package/dist/h3/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-BAWdklDQ.mjs";
2
+ import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
3
3
  import { n as resolveResponseMeta } from "../responses-_II3dOJ5.mjs";
4
4
  import { HTTPResponse, getQuery, getRouterParams, readBody } from "h3";
5
5
 
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CCUF5FE7.cjs');
3
+ const require_router = require('../router-BdMuUzGU.cjs');
4
4
  const require_responses = require('../responses-JzXstGU5.cjs');
5
5
 
6
6
  //#region src/hono/router.ts
@@ -1,4 +1,4 @@
1
- import { d as ApiResourceMiddleware, f as ControllerAction, h as Response, m as HttpMethod, n as Request, p as ControllerHandler, r as Route, t as CoreRouter } from "../router-78fDk87B.cjs";
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-WAxKAcWR.cjs";
2
2
  import { Context, HonoRequest, MiddlewareHandler } from "hono";
3
3
 
4
4
  //#region types/hono.d.ts
@@ -1,4 +1,4 @@
1
- import { d as ApiResourceMiddleware, f as ControllerAction, h as Response, m as HttpMethod, n as Request, p as ControllerHandler, r as Route, t as CoreRouter } from "../router-BdfAh1me.mjs";
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-D7R3G8w-.mjs";
2
2
  import { Context, HonoRequest, MiddlewareHandler } from "hono";
3
3
 
4
4
  //#region types/hono.d.ts
@@ -1,5 +1,5 @@
1
1
  import "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-BAWdklDQ.mjs";
2
+ import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
3
3
  import { n as resolveResponseMeta } from "../responses-_II3dOJ5.mjs";
4
4
 
5
5
  //#region src/hono/router.ts
package/dist/index.cjs CHANGED
@@ -141,6 +141,12 @@ var Response = class {
141
141
  }
142
142
  };
143
143
 
144
+ //#endregion
145
+ //#region src/core/plugins.ts
146
+ function definePlugin(plugin) {
147
+ return plugin;
148
+ }
149
+
144
150
  //#endregion
145
151
  //#region src/core/bindings.ts
146
152
  const metadataKey = Symbol.for("clear-router:binding-metadata");
@@ -212,6 +218,8 @@ var CoreRouter = class {
212
218
  static stateStoreKey = Symbol.for("clear-router:router-state");
213
219
  static stateBoundKey = Symbol.for("clear-router:router-state-bound");
214
220
  static defaultConfigKey = Symbol.for("clear-router:default-config");
221
+ static pluginStoreKey = Symbol.for("clear-router:plugins");
222
+ static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
215
223
  static createBaseConfig() {
216
224
  return {
217
225
  methodOverride: {
@@ -253,6 +261,16 @@ var CoreRouter = class {
253
261
  if (!g[this.stateStoreKey]) g[this.stateStoreKey] = Object.create(null);
254
262
  return g[this.stateStoreKey];
255
263
  }
264
+ static getPluginStore() {
265
+ const g = globalThis;
266
+ if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
267
+ return g[this.pluginStoreKey];
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
+ }
256
274
  static createDefaultState() {
257
275
  return {
258
276
  config: this.getDefaultConfig(),
@@ -350,6 +368,47 @@ var CoreRouter = class {
350
368
  const store = this.getStateStore();
351
369
  for (const state of Object.values(store)) state.config = this.mergeConfig(state.config || this.createBaseConfig(), options);
352
370
  }
371
+ /**
372
+ * Use a registered plugin
373
+ *
374
+ * @param this
375
+ * @param plugin
376
+ * @param options
377
+ * @returns
378
+ */
379
+ static async use(plugin, options) {
380
+ const name = typeof plugin === "function" ? plugin.name : plugin.name;
381
+ const store = this.getPluginStore();
382
+ if (name && store.has(name)) return;
383
+ if (name) store.add(name);
384
+ const setup = async () => {
385
+ const ctx = {
386
+ container: Container,
387
+ bind: Container.bind.bind(Container),
388
+ configure: this.configure.bind(this),
389
+ configureDefaults: this.configureDefaults.bind(this),
390
+ options
391
+ };
392
+ if (typeof plugin === "function") await plugin(ctx);
393
+ else await plugin.setup(ctx);
394
+ };
395
+ const pending = this.getPluginPendingStore();
396
+ const promise = setup();
397
+ pending.add(promise);
398
+ try {
399
+ await promise;
400
+ } catch (error) {
401
+ if (name) store.delete(name);
402
+ throw error;
403
+ } finally {
404
+ pending.delete(promise);
405
+ }
406
+ }
407
+ static async pluginsReady() {
408
+ const pending = Array.from(this.getPluginPendingStore());
409
+ if (!pending.length) return;
410
+ await Promise.all(pending);
411
+ }
353
412
  static groupContext = new node_async_hooks.AsyncLocalStorage();
354
413
  static routes = [];
355
414
  static routesByPathMethod = {};
@@ -671,6 +730,7 @@ var CoreRouter = class {
671
730
  };
672
731
  }
673
732
  static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
733
+ await this.pluginsReady();
674
734
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
675
735
  const metadata = getBindingMetadataFromTargets([
676
736
  {
@@ -730,4 +790,5 @@ exports.Controller = Controller;
730
790
  exports.CoreRouter = CoreRouter;
731
791
  exports.Request = Request;
732
792
  exports.Response = Response;
733
- exports.Route = Route;
793
+ exports.Route = Route;
794
+ exports.definePlugin = definePlugin;
package/dist/index.d.cts CHANGED
@@ -128,6 +128,37 @@ declare abstract class Controller<X = any> {
128
128
  clearRequest: ClearRequest;
129
129
  }
130
130
  //#endregion
131
+ //#region src/core/bindings.d.ts
132
+ type BindToken<T = any> = abstract new (...args: any[]) => T;
133
+ type BindFactory<T = any> = (ctx: any) => T | Promise<T>;
134
+ type BindValue<T = any> = T | BindFactory<T> | BindToken<T>;
135
+ declare class Container {
136
+ private static readonly registry;
137
+ static bind<T>(token: BindToken<T>, value: BindValue<T>): void;
138
+ static unbind<T>(token: BindToken<T>): void;
139
+ static clear(): void;
140
+ static has<T>(token: BindToken<T>): boolean;
141
+ static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
142
+ private static resolveBinding;
143
+ }
144
+ //#endregion
145
+ //#region src/core/plugins.d.ts
146
+ type PluginSetupResult = void | Promise<void>;
147
+ type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
148
+ interface ClearRouterPluginContext<Options = any> {
149
+ container: typeof Container;
150
+ bind: PluginBind;
151
+ configure: (options: RouterConfig) => void;
152
+ configureDefaults: (options: RouterConfig) => void;
153
+ options: Options;
154
+ }
155
+ interface ClearRouterPlugin<Options = any> {
156
+ name?: string;
157
+ setup: (ctx: ClearRouterPluginContext<Options>) => PluginSetupResult;
158
+ }
159
+ type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
160
+ declare function definePlugin<Options = any>(plugin: ClearRouterPlugin<Options>): ClearRouterPlugin<Options>;
161
+ //#endregion
131
162
  //#region src/core/router.d.ts
132
163
  /**
133
164
  * @class clear-router CoreRouter
@@ -140,11 +171,15 @@ declare abstract class CoreRouter {
140
171
  private static readonly stateStoreKey;
141
172
  private static readonly stateBoundKey;
142
173
  private static readonly defaultConfigKey;
174
+ private static readonly pluginStoreKey;
175
+ private static readonly pluginPendingKey;
143
176
  protected static createBaseConfig(): RouterConfig;
144
177
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
145
178
  protected static getDefaultConfig(): RouterConfig;
146
179
  protected static resolveStateNamespace(this: any): string;
147
180
  protected static getStateStore(): Record<string, any>;
181
+ protected static getPluginStore(): Set<string>;
182
+ protected static getPluginPendingStore(): Set<Promise<void>>;
148
183
  protected static createDefaultState(): {
149
184
  config: RouterConfig;
150
185
  groupContext: AsyncLocalStorage<{
@@ -162,6 +197,16 @@ declare abstract class CoreRouter {
162
197
  protected static createDefaultOptionsHandler(): any;
163
198
  static config: RouterConfig;
164
199
  static configureDefaults(this: any, options?: RouterConfig): void;
200
+ /**
201
+ * Use a registered plugin
202
+ *
203
+ * @param this
204
+ * @param plugin
205
+ * @param options
206
+ * @returns
207
+ */
208
+ static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
209
+ protected static pluginsReady(this: any): Promise<void>;
165
210
  protected static groupContext: AsyncLocalStorage<{
166
211
  prefix: string;
167
212
  groupMiddlewares: any[];
@@ -327,4 +372,4 @@ declare abstract class CoreRouter {
327
372
  }): void;
328
373
  }
329
374
  //#endregion
330
- export { ClearRequest, Controller, CoreRouter, Request, Response$1 as Response, Route };
375
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
package/dist/index.d.mts CHANGED
@@ -128,6 +128,37 @@ declare abstract class Controller<X = any> {
128
128
  clearRequest: ClearRequest;
129
129
  }
130
130
  //#endregion
131
+ //#region src/core/bindings.d.ts
132
+ type BindToken<T = any> = abstract new (...args: any[]) => T;
133
+ type BindFactory<T = any> = (ctx: any) => T | Promise<T>;
134
+ type BindValue<T = any> = T | BindFactory<T> | BindToken<T>;
135
+ declare class Container {
136
+ private static readonly registry;
137
+ static bind<T>(token: BindToken<T>, value: BindValue<T>): void;
138
+ static unbind<T>(token: BindToken<T>): void;
139
+ static clear(): void;
140
+ static has<T>(token: BindToken<T>): boolean;
141
+ static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
142
+ private static resolveBinding;
143
+ }
144
+ //#endregion
145
+ //#region src/core/plugins.d.ts
146
+ type PluginSetupResult = void | Promise<void>;
147
+ type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
148
+ interface ClearRouterPluginContext<Options = any> {
149
+ container: typeof Container;
150
+ bind: PluginBind;
151
+ configure: (options: RouterConfig) => void;
152
+ configureDefaults: (options: RouterConfig) => void;
153
+ options: Options;
154
+ }
155
+ interface ClearRouterPlugin<Options = any> {
156
+ name?: string;
157
+ setup: (ctx: ClearRouterPluginContext<Options>) => PluginSetupResult;
158
+ }
159
+ type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
160
+ declare function definePlugin<Options = any>(plugin: ClearRouterPlugin<Options>): ClearRouterPlugin<Options>;
161
+ //#endregion
131
162
  //#region src/core/router.d.ts
132
163
  /**
133
164
  * @class clear-router CoreRouter
@@ -140,11 +171,15 @@ declare abstract class CoreRouter {
140
171
  private static readonly stateStoreKey;
141
172
  private static readonly stateBoundKey;
142
173
  private static readonly defaultConfigKey;
174
+ private static readonly pluginStoreKey;
175
+ private static readonly pluginPendingKey;
143
176
  protected static createBaseConfig(): RouterConfig;
144
177
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
145
178
  protected static getDefaultConfig(): RouterConfig;
146
179
  protected static resolveStateNamespace(this: any): string;
147
180
  protected static getStateStore(): Record<string, any>;
181
+ protected static getPluginStore(): Set<string>;
182
+ protected static getPluginPendingStore(): Set<Promise<void>>;
148
183
  protected static createDefaultState(): {
149
184
  config: RouterConfig;
150
185
  groupContext: AsyncLocalStorage<{
@@ -162,6 +197,16 @@ declare abstract class CoreRouter {
162
197
  protected static createDefaultOptionsHandler(): any;
163
198
  static config: RouterConfig;
164
199
  static configureDefaults(this: any, options?: RouterConfig): void;
200
+ /**
201
+ * Use a registered plugin
202
+ *
203
+ * @param this
204
+ * @param plugin
205
+ * @param options
206
+ * @returns
207
+ */
208
+ static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
209
+ protected static pluginsReady(this: any): Promise<void>;
165
210
  protected static groupContext: AsyncLocalStorage<{
166
211
  prefix: string;
167
212
  groupMiddlewares: any[];
@@ -327,4 +372,4 @@ declare abstract class CoreRouter {
327
372
  }): void;
328
373
  }
329
374
  //#endregion
330
- export { ClearRequest, Controller, CoreRouter, Request, Response$1 as Response, Route };
375
+ export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
package/dist/index.mjs CHANGED
@@ -140,6 +140,12 @@ var Response = class {
140
140
  }
141
141
  };
142
142
 
143
+ //#endregion
144
+ //#region src/core/plugins.ts
145
+ function definePlugin(plugin) {
146
+ return plugin;
147
+ }
148
+
143
149
  //#endregion
144
150
  //#region src/core/bindings.ts
145
151
  const metadataKey = Symbol.for("clear-router:binding-metadata");
@@ -211,6 +217,8 @@ var CoreRouter = class {
211
217
  static stateStoreKey = Symbol.for("clear-router:router-state");
212
218
  static stateBoundKey = Symbol.for("clear-router:router-state-bound");
213
219
  static defaultConfigKey = Symbol.for("clear-router:default-config");
220
+ static pluginStoreKey = Symbol.for("clear-router:plugins");
221
+ static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
214
222
  static createBaseConfig() {
215
223
  return {
216
224
  methodOverride: {
@@ -252,6 +260,16 @@ var CoreRouter = class {
252
260
  if (!g[this.stateStoreKey]) g[this.stateStoreKey] = Object.create(null);
253
261
  return g[this.stateStoreKey];
254
262
  }
263
+ static getPluginStore() {
264
+ const g = globalThis;
265
+ if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
266
+ return g[this.pluginStoreKey];
267
+ }
268
+ static getPluginPendingStore() {
269
+ const g = globalThis;
270
+ if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
271
+ return g[this.pluginPendingKey];
272
+ }
255
273
  static createDefaultState() {
256
274
  return {
257
275
  config: this.getDefaultConfig(),
@@ -349,6 +367,47 @@ var CoreRouter = class {
349
367
  const store = this.getStateStore();
350
368
  for (const state of Object.values(store)) state.config = this.mergeConfig(state.config || this.createBaseConfig(), options);
351
369
  }
370
+ /**
371
+ * Use a registered plugin
372
+ *
373
+ * @param this
374
+ * @param plugin
375
+ * @param options
376
+ * @returns
377
+ */
378
+ static async use(plugin, options) {
379
+ const name = typeof plugin === "function" ? plugin.name : plugin.name;
380
+ const store = this.getPluginStore();
381
+ if (name && store.has(name)) return;
382
+ if (name) store.add(name);
383
+ const setup = async () => {
384
+ const ctx = {
385
+ container: Container,
386
+ bind: Container.bind.bind(Container),
387
+ configure: this.configure.bind(this),
388
+ configureDefaults: this.configureDefaults.bind(this),
389
+ options
390
+ };
391
+ if (typeof plugin === "function") await plugin(ctx);
392
+ else await plugin.setup(ctx);
393
+ };
394
+ const pending = this.getPluginPendingStore();
395
+ const promise = setup();
396
+ pending.add(promise);
397
+ try {
398
+ await promise;
399
+ } catch (error) {
400
+ if (name) store.delete(name);
401
+ throw error;
402
+ } finally {
403
+ pending.delete(promise);
404
+ }
405
+ }
406
+ static async pluginsReady() {
407
+ const pending = Array.from(this.getPluginPendingStore());
408
+ if (!pending.length) return;
409
+ await Promise.all(pending);
410
+ }
352
411
  static groupContext = new AsyncLocalStorage();
353
412
  static routes = [];
354
413
  static routesByPathMethod = {};
@@ -670,6 +729,7 @@ var CoreRouter = class {
670
729
  };
671
730
  }
672
731
  static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
732
+ await this.pluginsReady();
673
733
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
674
734
  const metadata = getBindingMetadataFromTargets([
675
735
  {
@@ -724,4 +784,4 @@ var CoreRouter = class {
724
784
  };
725
785
 
726
786
  //#endregion
727
- export { ClearRequest, Controller, CoreRouter, Request, Response, Route };
787
+ export { ClearRequest, Controller, CoreRouter, Request, Response, Route, definePlugin };
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  require('../bindings-DvV2DXWi.cjs');
3
- const require_router = require('../router-CCUF5FE7.cjs');
3
+ const require_router = require('../router-BdMuUzGU.cjs');
4
4
  const require_responses = require('../responses-JzXstGU5.cjs');
5
5
 
6
6
  //#region src/koa/router.ts
@@ -1,4 +1,4 @@
1
- import { d as ApiResourceMiddleware, f as ControllerAction, h as Response, m as HttpMethod, n as Request, p as ControllerHandler, r as Route, t as CoreRouter } from "../router-78fDk87B.cjs";
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-WAxKAcWR.cjs";
2
2
  import Koa from "koa";
3
3
  import Router$1 from "@koa/router";
4
4
 
@@ -1,4 +1,4 @@
1
- import { d as ApiResourceMiddleware, f as ControllerAction, h as Response, m as HttpMethod, n as Request, p as ControllerHandler, r as Route, t as CoreRouter } from "../router-BdfAh1me.mjs";
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-D7R3G8w-.mjs";
2
2
  import Koa from "koa";
3
3
  import Router$1 from "@koa/router";
4
4
 
@@ -1,5 +1,5 @@
1
1
  import "../bindings-DIanvIVd.mjs";
2
- import { t as CoreRouter } from "../router-BAWdklDQ.mjs";
2
+ import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
3
3
  import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-_II3dOJ5.mjs";
4
4
 
5
5
  //#region src/koa/router.ts
@@ -41,6 +41,8 @@ var CoreRouter = class {
41
41
  static stateStoreKey = Symbol.for("clear-router:router-state");
42
42
  static stateBoundKey = Symbol.for("clear-router:router-state-bound");
43
43
  static defaultConfigKey = Symbol.for("clear-router:default-config");
44
+ static pluginStoreKey = Symbol.for("clear-router:plugins");
45
+ static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
44
46
  static createBaseConfig() {
45
47
  return {
46
48
  methodOverride: {
@@ -82,6 +84,16 @@ var CoreRouter = class {
82
84
  if (!g[this.stateStoreKey]) g[this.stateStoreKey] = Object.create(null);
83
85
  return g[this.stateStoreKey];
84
86
  }
87
+ static getPluginStore() {
88
+ const g = globalThis;
89
+ if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
90
+ return g[this.pluginStoreKey];
91
+ }
92
+ static getPluginPendingStore() {
93
+ const g = globalThis;
94
+ if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
95
+ return g[this.pluginPendingKey];
96
+ }
85
97
  static createDefaultState() {
86
98
  return {
87
99
  config: this.getDefaultConfig(),
@@ -179,6 +191,47 @@ var CoreRouter = class {
179
191
  const store = this.getStateStore();
180
192
  for (const state of Object.values(store)) state.config = this.mergeConfig(state.config || this.createBaseConfig(), options);
181
193
  }
194
+ /**
195
+ * Use a registered plugin
196
+ *
197
+ * @param this
198
+ * @param plugin
199
+ * @param options
200
+ * @returns
201
+ */
202
+ static async use(plugin, options) {
203
+ const name = typeof plugin === "function" ? plugin.name : plugin.name;
204
+ const store = this.getPluginStore();
205
+ if (name && store.has(name)) return;
206
+ if (name) store.add(name);
207
+ const setup = async () => {
208
+ const ctx = {
209
+ container: require_bindings.Container,
210
+ bind: require_bindings.Container.bind.bind(require_bindings.Container),
211
+ configure: this.configure.bind(this),
212
+ configureDefaults: this.configureDefaults.bind(this),
213
+ options
214
+ };
215
+ if (typeof plugin === "function") await plugin(ctx);
216
+ else await plugin.setup(ctx);
217
+ };
218
+ const pending = this.getPluginPendingStore();
219
+ const promise = setup();
220
+ pending.add(promise);
221
+ try {
222
+ await promise;
223
+ } catch (error) {
224
+ if (name) store.delete(name);
225
+ throw error;
226
+ } finally {
227
+ pending.delete(promise);
228
+ }
229
+ }
230
+ static async pluginsReady() {
231
+ const pending = Array.from(this.getPluginPendingStore());
232
+ if (!pending.length) return;
233
+ await Promise.all(pending);
234
+ }
182
235
  static groupContext = new node_async_hooks.AsyncLocalStorage();
183
236
  static routes = [];
184
237
  static routesByPathMethod = {};
@@ -500,6 +553,7 @@ var CoreRouter = class {
500
553
  };
501
554
  }
502
555
  static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
556
+ await this.pluginsReady();
503
557
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
504
558
  const metadata = require_bindings.getBindingMetadataFromTargets([
505
559
  {
@@ -1,3 +1,4 @@
1
+ import { a as BindValue, i as BindToken, o as Container } from "./bindings-CV1e5jho.mjs";
1
2
  import { AsyncLocalStorage } from "node:async_hooks";
2
3
  import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
3
4
  import { NextFunction, Request, Response as Response$1 } from "express";
@@ -188,6 +189,23 @@ declare class Request$1<X = any, M = any> extends ClearRequest<X, M> {
188
189
  is(method: HttpMethod | string): boolean;
189
190
  }
190
191
  //#endregion
192
+ //#region src/core/plugins.d.ts
193
+ type PluginSetupResult = void | Promise<void>;
194
+ type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
195
+ interface ClearRouterPluginContext<Options = any> {
196
+ container: typeof Container;
197
+ bind: PluginBind;
198
+ configure: (options: RouterConfig) => void;
199
+ configureDefaults: (options: RouterConfig) => void;
200
+ options: Options;
201
+ }
202
+ interface ClearRouterPlugin<Options = any> {
203
+ name?: string;
204
+ setup: (ctx: ClearRouterPluginContext<Options>) => PluginSetupResult;
205
+ }
206
+ type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
207
+ declare function definePlugin<Options = any>(plugin: ClearRouterPlugin<Options>): ClearRouterPlugin<Options>;
208
+ //#endregion
191
209
  //#region src/Controller.d.ts
192
210
  declare abstract class Controller<X = any> {
193
211
  [x: string]: any;
@@ -210,11 +228,15 @@ declare abstract class CoreRouter {
210
228
  private static readonly stateStoreKey;
211
229
  private static readonly stateBoundKey;
212
230
  private static readonly defaultConfigKey;
231
+ private static readonly pluginStoreKey;
232
+ private static readonly pluginPendingKey;
213
233
  protected static createBaseConfig(): RouterConfig;
214
234
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
215
235
  protected static getDefaultConfig(): RouterConfig;
216
236
  protected static resolveStateNamespace(this: any): string;
217
237
  protected static getStateStore(): Record<string, any>;
238
+ protected static getPluginStore(): Set<string>;
239
+ protected static getPluginPendingStore(): Set<Promise<void>>;
218
240
  protected static createDefaultState(): {
219
241
  config: RouterConfig;
220
242
  groupContext: AsyncLocalStorage<{
@@ -232,6 +254,16 @@ declare abstract class CoreRouter {
232
254
  protected static createDefaultOptionsHandler(): any;
233
255
  static config: RouterConfig;
234
256
  static configureDefaults(this: any, options?: RouterConfig): void;
257
+ /**
258
+ * Use a registered plugin
259
+ *
260
+ * @param this
261
+ * @param plugin
262
+ * @param options
263
+ * @returns
264
+ */
265
+ static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
266
+ protected static pluginsReady(this: any): Promise<void>;
235
267
  protected static groupContext: AsyncLocalStorage<{
236
268
  prefix: string;
237
269
  groupMiddlewares: any[];
@@ -397,4 +429,4 @@ declare abstract class CoreRouter {
397
429
  }): void;
398
430
  }
399
431
  //#endregion
400
- export { Handler as a, Handler$1 as c, ApiResourceMiddleware as d, ControllerAction as f, Response$2 as h, H3App as i, HttpContext$1 as l, HttpMethod as m, Request$1 as n, HttpContext as o, ControllerHandler as p, Route as r, Middleware as s, CoreRouter as t, Middleware$1 as u };
432
+ export { ApiResourceMiddleware as _, PluginBind as a, HttpMethod as b, Request$1 as c, Handler as d, HttpContext as f, Middleware$1 as g, HttpContext$1 as h, ClearRouterPluginInput as i, Route as l, Handler$1 as m, ClearRouterPlugin as n, PluginSetupResult as o, Middleware as p, ClearRouterPluginContext as r, definePlugin as s, CoreRouter as t, H3App as u, ControllerAction as v, Response$2 as x, ControllerHandler as y };
@@ -41,6 +41,8 @@ var CoreRouter = class {
41
41
  static stateStoreKey = Symbol.for("clear-router:router-state");
42
42
  static stateBoundKey = Symbol.for("clear-router:router-state-bound");
43
43
  static defaultConfigKey = Symbol.for("clear-router:default-config");
44
+ static pluginStoreKey = Symbol.for("clear-router:plugins");
45
+ static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
44
46
  static createBaseConfig() {
45
47
  return {
46
48
  methodOverride: {
@@ -82,6 +84,16 @@ var CoreRouter = class {
82
84
  if (!g[this.stateStoreKey]) g[this.stateStoreKey] = Object.create(null);
83
85
  return g[this.stateStoreKey];
84
86
  }
87
+ static getPluginStore() {
88
+ const g = globalThis;
89
+ if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
90
+ return g[this.pluginStoreKey];
91
+ }
92
+ static getPluginPendingStore() {
93
+ const g = globalThis;
94
+ if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
95
+ return g[this.pluginPendingKey];
96
+ }
85
97
  static createDefaultState() {
86
98
  return {
87
99
  config: this.getDefaultConfig(),
@@ -179,6 +191,47 @@ var CoreRouter = class {
179
191
  const store = this.getStateStore();
180
192
  for (const state of Object.values(store)) state.config = this.mergeConfig(state.config || this.createBaseConfig(), options);
181
193
  }
194
+ /**
195
+ * Use a registered plugin
196
+ *
197
+ * @param this
198
+ * @param plugin
199
+ * @param options
200
+ * @returns
201
+ */
202
+ static async use(plugin, options) {
203
+ const name = typeof plugin === "function" ? plugin.name : plugin.name;
204
+ const store = this.getPluginStore();
205
+ if (name && store.has(name)) return;
206
+ if (name) store.add(name);
207
+ const setup = async () => {
208
+ const ctx = {
209
+ container: Container,
210
+ bind: Container.bind.bind(Container),
211
+ configure: this.configure.bind(this),
212
+ configureDefaults: this.configureDefaults.bind(this),
213
+ options
214
+ };
215
+ if (typeof plugin === "function") await plugin(ctx);
216
+ else await plugin.setup(ctx);
217
+ };
218
+ const pending = this.getPluginPendingStore();
219
+ const promise = setup();
220
+ pending.add(promise);
221
+ try {
222
+ await promise;
223
+ } catch (error) {
224
+ if (name) store.delete(name);
225
+ throw error;
226
+ } finally {
227
+ pending.delete(promise);
228
+ }
229
+ }
230
+ static async pluginsReady() {
231
+ const pending = Array.from(this.getPluginPendingStore());
232
+ if (!pending.length) return;
233
+ await Promise.all(pending);
234
+ }
182
235
  static groupContext = new AsyncLocalStorage();
183
236
  static routes = [];
184
237
  static routesByPathMethod = {};
@@ -500,6 +553,7 @@ var CoreRouter = class {
500
553
  };
501
554
  }
502
555
  static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
556
+ await this.pluginsReady();
503
557
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
504
558
  const metadata = getBindingMetadataFromTargets([
505
559
  {
@@ -1,3 +1,4 @@
1
+ import { a as BindValue, i as BindToken, o as Container } from "./bindings-NV0CdqGl.cjs";
1
2
  import { NextFunction, Request, Response as Response$1 } from "express";
2
3
  import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
3
4
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -188,6 +189,23 @@ declare class Request$1<X = any, M = any> extends ClearRequest<X, M> {
188
189
  is(method: HttpMethod | string): boolean;
189
190
  }
190
191
  //#endregion
192
+ //#region src/core/plugins.d.ts
193
+ type PluginSetupResult = void | Promise<void>;
194
+ type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
195
+ interface ClearRouterPluginContext<Options = any> {
196
+ container: typeof Container;
197
+ bind: PluginBind;
198
+ configure: (options: RouterConfig) => void;
199
+ configureDefaults: (options: RouterConfig) => void;
200
+ options: Options;
201
+ }
202
+ interface ClearRouterPlugin<Options = any> {
203
+ name?: string;
204
+ setup: (ctx: ClearRouterPluginContext<Options>) => PluginSetupResult;
205
+ }
206
+ type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
207
+ declare function definePlugin<Options = any>(plugin: ClearRouterPlugin<Options>): ClearRouterPlugin<Options>;
208
+ //#endregion
191
209
  //#region src/Controller.d.ts
192
210
  declare abstract class Controller<X = any> {
193
211
  [x: string]: any;
@@ -210,11 +228,15 @@ declare abstract class CoreRouter {
210
228
  private static readonly stateStoreKey;
211
229
  private static readonly stateBoundKey;
212
230
  private static readonly defaultConfigKey;
231
+ private static readonly pluginStoreKey;
232
+ private static readonly pluginPendingKey;
213
233
  protected static createBaseConfig(): RouterConfig;
214
234
  protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
215
235
  protected static getDefaultConfig(): RouterConfig;
216
236
  protected static resolveStateNamespace(this: any): string;
217
237
  protected static getStateStore(): Record<string, any>;
238
+ protected static getPluginStore(): Set<string>;
239
+ protected static getPluginPendingStore(): Set<Promise<void>>;
218
240
  protected static createDefaultState(): {
219
241
  config: RouterConfig;
220
242
  groupContext: AsyncLocalStorage<{
@@ -232,6 +254,16 @@ declare abstract class CoreRouter {
232
254
  protected static createDefaultOptionsHandler(): any;
233
255
  static config: RouterConfig;
234
256
  static configureDefaults(this: any, options?: RouterConfig): void;
257
+ /**
258
+ * Use a registered plugin
259
+ *
260
+ * @param this
261
+ * @param plugin
262
+ * @param options
263
+ * @returns
264
+ */
265
+ static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
266
+ protected static pluginsReady(this: any): Promise<void>;
235
267
  protected static groupContext: AsyncLocalStorage<{
236
268
  prefix: string;
237
269
  groupMiddlewares: any[];
@@ -397,4 +429,4 @@ declare abstract class CoreRouter {
397
429
  }): void;
398
430
  }
399
431
  //#endregion
400
- export { Handler as a, Handler$1 as c, ApiResourceMiddleware as d, ControllerAction as f, Response$2 as h, H3App as i, HttpContext$1 as l, HttpMethod as m, Request$1 as n, HttpContext as o, ControllerHandler as p, Route as r, Middleware as s, CoreRouter as t, Middleware$1 as u };
432
+ export { ApiResourceMiddleware as _, PluginBind as a, HttpMethod as b, Request$1 as c, Handler as d, HttpContext as f, Middleware$1 as g, HttpContext$1 as h, ClearRouterPluginInput as i, Route as l, Handler$1 as m, ClearRouterPlugin as n, PluginSetupResult as o, Middleware as p, ClearRouterPluginContext as r, definePlugin as s, CoreRouter as t, H3App as u, ControllerAction as v, Response$2 as x, ControllerHandler as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.5.5",
3
+ "version": "2.5.7",
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",