clear-router 2.5.9 → 2.5.11

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 (47) hide show
  1. package/dist/{bindings-CYpdvTjf.mjs → bindings-B6x2HfzP.mjs} +42 -2
  2. package/dist/{bindings-CoxxSopM.cjs → bindings-CDGLuAq4.cjs} +42 -2
  3. package/dist/{bindings-B5ttDy47.d.cts → bindings-CNL7bpz5.d.mts} +4 -0
  4. package/dist/{bindings-BWMHQe9i.d.mts → bindings-CxvtC8XS.d.cts} +4 -0
  5. package/dist/core/index.cjs +2 -2
  6. package/dist/core/index.d.cts +1 -1
  7. package/dist/core/index.d.mts +1 -1
  8. package/dist/core/index.mjs +2 -2
  9. package/dist/decorators/index.cjs +1 -1
  10. package/dist/decorators/index.d.cts +1 -1
  11. package/dist/decorators/index.d.mts +1 -1
  12. package/dist/decorators/index.mjs +1 -1
  13. package/dist/decorators/setup.cjs +2 -2
  14. package/dist/decorators/setup.d.cts +1 -1
  15. package/dist/decorators/setup.d.mts +1 -1
  16. package/dist/decorators/setup.mjs +2 -2
  17. package/dist/express/index.cjs +3 -3
  18. package/dist/express/index.d.cts +1 -1
  19. package/dist/express/index.d.mts +1 -1
  20. package/dist/express/index.mjs +3 -3
  21. package/dist/fastify/index.cjs +3 -3
  22. package/dist/fastify/index.d.cts +1 -1
  23. package/dist/fastify/index.d.mts +1 -1
  24. package/dist/fastify/index.mjs +3 -3
  25. package/dist/h3/index.cjs +3 -3
  26. package/dist/h3/index.d.cts +1 -1
  27. package/dist/h3/index.d.mts +1 -1
  28. package/dist/h3/index.mjs +3 -3
  29. package/dist/hono/index.cjs +3 -3
  30. package/dist/hono/index.d.cts +1 -1
  31. package/dist/hono/index.d.mts +1 -1
  32. package/dist/hono/index.mjs +3 -3
  33. package/dist/index.cjs +42 -2
  34. package/dist/index.d.cts +4 -0
  35. package/dist/index.d.mts +4 -0
  36. package/dist/index.mjs +42 -2
  37. package/dist/koa/index.cjs +3 -3
  38. package/dist/koa/index.d.cts +1 -1
  39. package/dist/koa/index.d.mts +1 -1
  40. package/dist/koa/index.mjs +3 -3
  41. package/dist/{responses-B7G02ibg.cjs → responses-CBP3RYjJ.cjs} +1 -1
  42. package/dist/{responses-DUFly0RZ.mjs → responses-DuZeRyGE.mjs} +1 -1
  43. package/dist/{router-DMFeflRM.d.mts → router-BkYtqjYr.d.mts} +1 -1
  44. package/dist/{router-B_ouWc5s.mjs → router-CArh9OHb.mjs} +1 -1
  45. package/dist/{router-SAdZ7fgy.d.cts → router-DCGZNRNj.d.cts} +1 -1
  46. package/dist/{router-Cmua21-t.cjs → router-DtqXUlJq.cjs} +1 -1
  47. package/package.json +1 -1
@@ -116,7 +116,7 @@ var Container = class {
116
116
  this.registry.clear();
117
117
  }
118
118
  static has(token) {
119
- return this.registry.has(token);
119
+ return this.registry.has(token) || Boolean(this.findEquivalentToken(token));
120
120
  }
121
121
  static bindings() {
122
122
  return Object.fromEntries(this.registry.entries());
@@ -124,9 +124,49 @@ var Container = class {
124
124
  static async resolve(token, ctx, autoDiscover = false) {
125
125
  if (token === Request) return ctx.clearRequest;
126
126
  if (token === Response) return ctx.clearResponse;
127
- if (this.registry.has(token)) return this.resolveBinding(this.registry.get(token), ctx, autoDiscover);
127
+ const binding = this.getBinding(token);
128
+ if (binding) return this.resolveBinding(binding, ctx, autoDiscover);
128
129
  if (autoDiscover && typeof token === "function") return new token();
129
130
  }
131
+ static getBinding(token) {
132
+ if (this.registry.has(token)) return this.registry.get(token);
133
+ const equivalent = this.findEquivalentToken(token);
134
+ return equivalent ? this.registry.get(equivalent) : void 0;
135
+ }
136
+ static findEquivalentToken(token) {
137
+ const name = token.name;
138
+ if (!name) return;
139
+ const tokenParent = Object.getPrototypeOf(token);
140
+ const tokenProps = this.getComparableStaticProps(token);
141
+ for (const registered of this.registry.keys()) {
142
+ if (registered === token) continue;
143
+ if (registered.name !== name) continue;
144
+ const registeredParent = Object.getPrototypeOf(registered);
145
+ if (tokenParent && registeredParent && tokenParent.name !== registeredParent.name) continue;
146
+ const registeredProps = this.getComparableStaticProps(registered);
147
+ if (!this.staticPropsMatch(token, registered, tokenProps, registeredProps)) continue;
148
+ return registered;
149
+ }
150
+ }
151
+ static getComparableStaticProps(token) {
152
+ return Object.getOwnPropertyNames(token).filter((prop) => {
153
+ return ![
154
+ "length",
155
+ "name",
156
+ "prototype",
157
+ "arguments",
158
+ "caller"
159
+ ].includes(prop);
160
+ });
161
+ }
162
+ static staticPropsMatch(token, registered, tokenProps, registeredProps) {
163
+ if (tokenProps.length !== registeredProps.length) return false;
164
+ for (const prop of tokenProps) {
165
+ if (!registeredProps.includes(prop)) return false;
166
+ if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
167
+ }
168
+ return true;
169
+ }
130
170
  static async resolveBinding(binding, ctx, autoDiscover) {
131
171
  if (!binding) return void 0;
132
172
  if (typeof binding !== "function") return binding;
@@ -117,7 +117,7 @@ var Container = class {
117
117
  this.registry.clear();
118
118
  }
119
119
  static has(token) {
120
- return this.registry.has(token);
120
+ return this.registry.has(token) || Boolean(this.findEquivalentToken(token));
121
121
  }
122
122
  static bindings() {
123
123
  return Object.fromEntries(this.registry.entries());
@@ -125,9 +125,49 @@ var Container = class {
125
125
  static async resolve(token, ctx, autoDiscover = false) {
126
126
  if (token === Request) return ctx.clearRequest;
127
127
  if (token === Response) return ctx.clearResponse;
128
- if (this.registry.has(token)) return this.resolveBinding(this.registry.get(token), ctx, autoDiscover);
128
+ const binding = this.getBinding(token);
129
+ if (binding) return this.resolveBinding(binding, ctx, autoDiscover);
129
130
  if (autoDiscover && typeof token === "function") return new token();
130
131
  }
132
+ static getBinding(token) {
133
+ if (this.registry.has(token)) return this.registry.get(token);
134
+ const equivalent = this.findEquivalentToken(token);
135
+ return equivalent ? this.registry.get(equivalent) : void 0;
136
+ }
137
+ static findEquivalentToken(token) {
138
+ const name = token.name;
139
+ if (!name) return;
140
+ const tokenParent = Object.getPrototypeOf(token);
141
+ const tokenProps = this.getComparableStaticProps(token);
142
+ for (const registered of this.registry.keys()) {
143
+ if (registered === token) continue;
144
+ if (registered.name !== name) continue;
145
+ const registeredParent = Object.getPrototypeOf(registered);
146
+ if (tokenParent && registeredParent && tokenParent.name !== registeredParent.name) continue;
147
+ const registeredProps = this.getComparableStaticProps(registered);
148
+ if (!this.staticPropsMatch(token, registered, tokenProps, registeredProps)) continue;
149
+ return registered;
150
+ }
151
+ }
152
+ static getComparableStaticProps(token) {
153
+ return Object.getOwnPropertyNames(token).filter((prop) => {
154
+ return ![
155
+ "length",
156
+ "name",
157
+ "prototype",
158
+ "arguments",
159
+ "caller"
160
+ ].includes(prop);
161
+ });
162
+ }
163
+ static staticPropsMatch(token, registered, tokenProps, registeredProps) {
164
+ if (tokenProps.length !== registeredProps.length) return false;
165
+ for (const prop of tokenProps) {
166
+ if (!registeredProps.includes(prop)) return false;
167
+ if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
168
+ }
169
+ return true;
170
+ }
131
171
  static async resolveBinding(binding, ctx, autoDiscover) {
132
172
  if (!binding) return void 0;
133
173
  if (typeof binding !== "function") return binding;
@@ -14,6 +14,10 @@ declare class Container {
14
14
  static has<T>(token: BindToken<T>): boolean;
15
15
  static bindings<V = any>(): Record<string, BindValue<V>>;
16
16
  static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
17
+ private static getBinding;
18
+ private static findEquivalentToken;
19
+ private static getComparableStaticProps;
20
+ private static staticPropsMatch;
17
21
  private static resolveBinding;
18
22
  }
19
23
  declare function Bind(...tokens: BindToken[]): BindDecorator;
@@ -14,6 +14,10 @@ declare class Container {
14
14
  static has<T>(token: BindToken<T>): boolean;
15
15
  static bindings<V = any>(): Record<string, BindValue<V>>;
16
16
  static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
17
+ private static getBinding;
18
+ private static findEquivalentToken;
19
+ private static getComparableStaticProps;
20
+ private static staticPropsMatch;
17
21
  private static resolveBinding;
18
22
  }
19
23
  declare function Bind(...tokens: BindToken[]): BindDecorator;
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_bindings = require('../bindings-CoxxSopM.cjs');
3
- const require_router = require('../router-Cmua21-t.cjs');
2
+ const require_bindings = require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DtqXUlJq.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-SAdZ7fgy.cjs";
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
2
  export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, 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-DMFeflRM.mjs";
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
2
  export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
@@ -1,5 +1,5 @@
1
- import { c as Request, s as Response } from "../bindings-CYpdvTjf.mjs";
2
- import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
1
+ import { c as Request, s as Response } from "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-CArh9OHb.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-CoxxSopM.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,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-B5ttDy47.cjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-CxvtC8XS.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-BWMHQe9i.mjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-CNL7bpz5.mjs";
2
2
  export { Bind, type BindDecorator, type BindFactory, type BindToken, type BindValue, Container };
@@ -1,3 +1,3 @@
1
- import { n as Container, t as Bind } from "../bindings-CYpdvTjf.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-CoxxSopM.cjs');
3
- const require_router = require('../router-Cmua21-t.cjs');
2
+ const require_bindings = require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DtqXUlJq.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-B5ttDy47.cjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-CxvtC8XS.cjs";
2
2
  export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
@@ -1,3 +1,3 @@
1
- import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-BWMHQe9i.mjs";
1
+ import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-CNL7bpz5.mjs";
2
2
  import "reflect-metadata";
3
3
  export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
@@ -1,5 +1,5 @@
1
- import { n as Container, t as Bind } from "../bindings-CYpdvTjf.mjs";
2
- import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
1
+ import { n as Container, t as Bind } from "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-CArh9OHb.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-CoxxSopM.cjs');
3
- const require_router = require('../router-Cmua21-t.cjs');
4
- const require_responses = require('../responses-B7G02ibg.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DtqXUlJq.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-SAdZ7fgy.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-DCGZNRNj.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-DMFeflRM.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-BkYtqjYr.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-CYpdvTjf.mjs";
2
- import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DUFly0RZ.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-CArh9OHb.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
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-CoxxSopM.cjs');
3
- const require_router = require('../router-Cmua21-t.cjs');
4
- const require_responses = require('../responses-B7G02ibg.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DtqXUlJq.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-SAdZ7fgy.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-DCGZNRNj.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-DMFeflRM.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-BkYtqjYr.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-CYpdvTjf.mjs";
2
- import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
3
- import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DUFly0RZ.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-CArh9OHb.mjs";
3
+ import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
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-CoxxSopM.cjs');
3
- const require_router = require('../router-Cmua21-t.cjs');
4
- const require_responses = require('../responses-B7G02ibg.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DtqXUlJq.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-SAdZ7fgy.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-DCGZNRNj.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-DMFeflRM.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-BkYtqjYr.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-CYpdvTjf.mjs";
2
- import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
3
- import { n as resolveResponseMeta } from "../responses-DUFly0RZ.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-CArh9OHb.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-CoxxSopM.cjs');
3
- const require_router = require('../router-Cmua21-t.cjs');
4
- const require_responses = require('../responses-B7G02ibg.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DtqXUlJq.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-SAdZ7fgy.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-DCGZNRNj.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-DMFeflRM.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-BkYtqjYr.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-CYpdvTjf.mjs";
2
- import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
3
- import { n as resolveResponseMeta } from "../responses-DUFly0RZ.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-CArh9OHb.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
@@ -163,7 +163,7 @@ var Container = class {
163
163
  this.registry.clear();
164
164
  }
165
165
  static has(token) {
166
- return this.registry.has(token);
166
+ return this.registry.has(token) || Boolean(this.findEquivalentToken(token));
167
167
  }
168
168
  static bindings() {
169
169
  return Object.fromEntries(this.registry.entries());
@@ -171,9 +171,49 @@ var Container = class {
171
171
  static async resolve(token, ctx, autoDiscover = false) {
172
172
  if (token === Request) return ctx.clearRequest;
173
173
  if (token === Response) return ctx.clearResponse;
174
- if (this.registry.has(token)) return this.resolveBinding(this.registry.get(token), ctx, autoDiscover);
174
+ const binding = this.getBinding(token);
175
+ if (binding) return this.resolveBinding(binding, ctx, autoDiscover);
175
176
  if (autoDiscover && typeof token === "function") return new token();
176
177
  }
178
+ static getBinding(token) {
179
+ if (this.registry.has(token)) return this.registry.get(token);
180
+ const equivalent = this.findEquivalentToken(token);
181
+ return equivalent ? this.registry.get(equivalent) : void 0;
182
+ }
183
+ static findEquivalentToken(token) {
184
+ const name = token.name;
185
+ if (!name) return;
186
+ const tokenParent = Object.getPrototypeOf(token);
187
+ const tokenProps = this.getComparableStaticProps(token);
188
+ for (const registered of this.registry.keys()) {
189
+ if (registered === token) continue;
190
+ if (registered.name !== name) continue;
191
+ const registeredParent = Object.getPrototypeOf(registered);
192
+ if (tokenParent && registeredParent && tokenParent.name !== registeredParent.name) continue;
193
+ const registeredProps = this.getComparableStaticProps(registered);
194
+ if (!this.staticPropsMatch(token, registered, tokenProps, registeredProps)) continue;
195
+ return registered;
196
+ }
197
+ }
198
+ static getComparableStaticProps(token) {
199
+ return Object.getOwnPropertyNames(token).filter((prop) => {
200
+ return ![
201
+ "length",
202
+ "name",
203
+ "prototype",
204
+ "arguments",
205
+ "caller"
206
+ ].includes(prop);
207
+ });
208
+ }
209
+ static staticPropsMatch(token, registered, tokenProps, registeredProps) {
210
+ if (tokenProps.length !== registeredProps.length) return false;
211
+ for (const prop of tokenProps) {
212
+ if (!registeredProps.includes(prop)) return false;
213
+ if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
214
+ }
215
+ return true;
216
+ }
177
217
  static async resolveBinding(binding, ctx, autoDiscover) {
178
218
  if (!binding) return void 0;
179
219
  if (typeof binding !== "function") return binding;
package/dist/index.d.cts CHANGED
@@ -140,6 +140,10 @@ declare class Container {
140
140
  static has<T>(token: BindToken<T>): boolean;
141
141
  static bindings<V = any>(): Record<string, BindValue<V>>;
142
142
  static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
143
+ private static getBinding;
144
+ private static findEquivalentToken;
145
+ private static getComparableStaticProps;
146
+ private static staticPropsMatch;
143
147
  private static resolveBinding;
144
148
  }
145
149
  //#endregion
package/dist/index.d.mts CHANGED
@@ -140,6 +140,10 @@ declare class Container {
140
140
  static has<T>(token: BindToken<T>): boolean;
141
141
  static bindings<V = any>(): Record<string, BindValue<V>>;
142
142
  static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
143
+ private static getBinding;
144
+ private static findEquivalentToken;
145
+ private static getComparableStaticProps;
146
+ private static staticPropsMatch;
143
147
  private static resolveBinding;
144
148
  }
145
149
  //#endregion
package/dist/index.mjs CHANGED
@@ -162,7 +162,7 @@ var Container = class {
162
162
  this.registry.clear();
163
163
  }
164
164
  static has(token) {
165
- return this.registry.has(token);
165
+ return this.registry.has(token) || Boolean(this.findEquivalentToken(token));
166
166
  }
167
167
  static bindings() {
168
168
  return Object.fromEntries(this.registry.entries());
@@ -170,9 +170,49 @@ var Container = class {
170
170
  static async resolve(token, ctx, autoDiscover = false) {
171
171
  if (token === Request) return ctx.clearRequest;
172
172
  if (token === Response) return ctx.clearResponse;
173
- if (this.registry.has(token)) return this.resolveBinding(this.registry.get(token), ctx, autoDiscover);
173
+ const binding = this.getBinding(token);
174
+ if (binding) return this.resolveBinding(binding, ctx, autoDiscover);
174
175
  if (autoDiscover && typeof token === "function") return new token();
175
176
  }
177
+ static getBinding(token) {
178
+ if (this.registry.has(token)) return this.registry.get(token);
179
+ const equivalent = this.findEquivalentToken(token);
180
+ return equivalent ? this.registry.get(equivalent) : void 0;
181
+ }
182
+ static findEquivalentToken(token) {
183
+ const name = token.name;
184
+ if (!name) return;
185
+ const tokenParent = Object.getPrototypeOf(token);
186
+ const tokenProps = this.getComparableStaticProps(token);
187
+ for (const registered of this.registry.keys()) {
188
+ if (registered === token) continue;
189
+ if (registered.name !== name) continue;
190
+ const registeredParent = Object.getPrototypeOf(registered);
191
+ if (tokenParent && registeredParent && tokenParent.name !== registeredParent.name) continue;
192
+ const registeredProps = this.getComparableStaticProps(registered);
193
+ if (!this.staticPropsMatch(token, registered, tokenProps, registeredProps)) continue;
194
+ return registered;
195
+ }
196
+ }
197
+ static getComparableStaticProps(token) {
198
+ return Object.getOwnPropertyNames(token).filter((prop) => {
199
+ return ![
200
+ "length",
201
+ "name",
202
+ "prototype",
203
+ "arguments",
204
+ "caller"
205
+ ].includes(prop);
206
+ });
207
+ }
208
+ static staticPropsMatch(token, registered, tokenProps, registeredProps) {
209
+ if (tokenProps.length !== registeredProps.length) return false;
210
+ for (const prop of tokenProps) {
211
+ if (!registeredProps.includes(prop)) return false;
212
+ if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
213
+ }
214
+ return true;
215
+ }
176
216
  static async resolveBinding(binding, ctx, autoDiscover) {
177
217
  if (!binding) return void 0;
178
218
  if (typeof binding !== "function") return binding;
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- require('../bindings-CoxxSopM.cjs');
3
- const require_router = require('../router-Cmua21-t.cjs');
4
- const require_responses = require('../responses-B7G02ibg.cjs');
2
+ require('../bindings-CDGLuAq4.cjs');
3
+ const require_router = require('../router-DtqXUlJq.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-SAdZ7fgy.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-DCGZNRNj.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-DMFeflRM.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-BkYtqjYr.mjs";
2
2
  import Koa from "koa";
3
3
  import Router$1 from "@koa/router";
4
4
 
@@ -1,6 +1,6 @@
1
- import "../bindings-CYpdvTjf.mjs";
2
- import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
3
- import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-DUFly0RZ.mjs";
1
+ import "../bindings-B6x2HfzP.mjs";
2
+ import { t as CoreRouter } from "../router-CArh9OHb.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-CoxxSopM.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-CYpdvTjf.mjs";
1
+ import { s as Response } from "./bindings-B6x2HfzP.mjs";
2
2
 
3
3
  //#region src/core/responses.ts
4
4
  function isFetchResponse(value) {
@@ -1,4 +1,4 @@
1
- import { a as BindValue, i as BindToken, o as Container } from "./bindings-BWMHQe9i.mjs";
1
+ import { a as BindValue, i as BindToken, o as Container } from "./bindings-CNL7bpz5.mjs";
2
2
  import { AsyncLocalStorage } from "node:async_hooks";
3
3
  import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
4
4
  import { NextFunction, Request, Response as Response$1 } from "express";
@@ -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-CYpdvTjf.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
@@ -1,4 +1,4 @@
1
- import { a as BindValue, i as BindToken, o as Container } from "./bindings-B5ttDy47.cjs";
1
+ import { a as BindValue, i as BindToken, o as Container } from "./bindings-CxvtC8XS.cjs";
2
2
  import { NextFunction, Request, Response as Response$1 } from "express";
3
3
  import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
4
4
  import { AsyncLocalStorage } from "node:async_hooks";
@@ -1,4 +1,4 @@
1
- const require_bindings = require('./bindings-CoxxSopM.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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-router",
3
- "version": "2.5.9",
3
+ "version": "2.5.11",
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",