clear-router 2.6.6 → 2.7.0

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.
@@ -63,7 +63,7 @@ var Route = class {
63
63
  * @class clear-router CoreRouter
64
64
  * @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
65
65
  * @author 3m1n3nc3
66
- * @repository https://github.com/toneflix/clear-router
66
+ * @repository https://github.com/arkstack-tmp/clear-router
67
67
  */
68
68
  var CoreRouter = class {
69
69
  static routerStateNamespace = "clear-router:core";
@@ -72,6 +72,7 @@ var CoreRouter = class {
72
72
  static defaultConfigKey = Symbol.for("clear-router:default-config");
73
73
  static pluginStoreKey = Symbol.for("clear-router:plugins");
74
74
  static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
75
+ static pluginHttpCtxResolversKey = Symbol.for("clear-router:plugin-http-ctx");
75
76
  static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
76
77
  static requestProvider;
77
78
  static responseProvider;
@@ -167,6 +168,11 @@ var CoreRouter = class {
167
168
  if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
168
169
  return g[this.pluginArgumentResolversKey];
169
170
  }
171
+ static getPluginHttpCtxResolvers() {
172
+ const g = globalThis;
173
+ if (!g[this.pluginHttpCtxResolversKey]) g[this.pluginHttpCtxResolversKey] = /* @__PURE__ */ new Set();
174
+ return g[this.pluginHttpCtxResolversKey];
175
+ }
170
176
  static createDefaultState() {
171
177
  return {
172
178
  config: this.getDefaultConfig(),
@@ -248,6 +254,11 @@ var CoreRouter = class {
248
254
  }
249
255
  };
250
256
  }
257
+ /**
258
+ * Default configuration used for everytime the router is reset
259
+ *
260
+ * @param options
261
+ */
251
262
  static configureDefaults(options) {
252
263
  const g = globalThis;
253
264
  const defaults = this.mergeConfig(g[this.defaultConfigKey] || this.createBaseConfig(), options);
@@ -275,6 +286,9 @@ var CoreRouter = class {
275
286
  resolveArguments: (resolver) => {
276
287
  this.getPluginArgumentResolvers().add(resolver);
277
288
  },
289
+ useHttpContext: (resolver) => {
290
+ this.getPluginHttpCtxResolvers().add(resolver);
291
+ },
278
292
  bindings: Container.bindings(),
279
293
  configure: this.configure.bind(this),
280
294
  configureDefaults: this.configureDefaults.bind(this),
@@ -345,6 +359,12 @@ var CoreRouter = class {
345
359
  if (Array.isArray(args)) return args;
346
360
  }
347
361
  }
362
+ static async resolvePluginHttpCtx(ctx) {
363
+ const resolvers = Array.from(this.getPluginHttpCtxResolvers());
364
+ if (!resolvers.length) return void 0;
365
+ const pluginContext = this.createPluginRequestContext(ctx);
366
+ for (const resolver of resolvers) await resolver(pluginContext);
367
+ }
348
368
  static ensureState() {
349
369
  this.bindStateAccessors();
350
370
  if (!this.config) this.config = { methodOverride: {
@@ -768,6 +788,7 @@ var CoreRouter = class {
768
788
  static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
769
789
  return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
770
790
  await this.pluginsReady();
791
+ await this.resolvePluginHttpCtx(ctx);
771
792
  if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
772
793
  const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
773
794
  const metadata = getBindingMetadataFromTargets([
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.6.6",
3
+ "version": "2.7.0",
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",
@@ -19,11 +19,11 @@
19
19
  ],
20
20
  "homepage": "https://arkstack-tmp.github.io/clear-router",
21
21
  "bugs": {
22
- "url": "https://github.com/toneflix/clear-router/issues"
22
+ "url": "https://github.com/arkstack-tmp/clear-router/issues"
23
23
  },
24
24
  "repository": {
25
25
  "type": "git",
26
- "url": "git+https://github.com/toneflix/clear-router.git"
26
+ "url": "git+https://github.com/arkstack-tmp/clear-router.git"
27
27
  },
28
28
  "license": "MIT",
29
29
  "author": "3m1n1nce <3m1n1nce@toneflix.net>",