@lppedd/di-wise-neo 0.5.1 → 0.5.2

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.
@@ -792,6 +792,24 @@ interface Injector {
792
792
  */
793
793
  declare const Injector: Type<Injector>;
794
794
 
795
+ /**
796
+ * Registers a mapping between a generated (e.g., decorated or proxied) constructor
797
+ * and its original, underlying constructor.
798
+ *
799
+ * This allows libraries or consumers that manipulate constructors, such as through
800
+ * class decorators, to inform the DI system about the real "identity" of a class.
801
+ *
802
+ * @param transformedClass The constructor function returned by a class decorator or factory.
803
+ * @param originalClass The original constructor function.
804
+ *
805
+ * @remarks
806
+ * This API affects the core class identity resolution mechanism of the DI system.
807
+ * Incorrect usage may cause metadata to be misassociated, leading to subtle errors.
808
+ * Use only when manipulating constructors (e.g., via decorators or proxies),
809
+ * and ensure the mapping is correct.
810
+ */
811
+ declare function setClassIdentityMapping<T extends object>(transformedClass: Constructor<T>, originalClass: Constructor<T>): void;
812
+
795
813
  /**
796
814
  * Composer API for middleware functions.
797
815
  */
@@ -847,5 +865,5 @@ interface Middleware {
847
865
  */
848
866
  declare function applyMiddleware(container: Container, middlewares: Middleware[]): Container;
849
867
 
850
- export { AutoRegister, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy };
868
+ export { AutoRegister, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy, setClassIdentityMapping };
851
869
  export type { ClassProvider, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, Type, ValueProvider };
package/dist/cjs/index.js CHANGED
@@ -156,16 +156,35 @@ function injectAll(token) {
156
156
  return context.container.resolveAll(token);
157
157
  }
158
158
 
159
+ /**
160
+ * Registers a mapping between a generated (e.g., decorated or proxied) constructor
161
+ * and its original, underlying constructor.
162
+ *
163
+ * This allows libraries or consumers that manipulate constructors, such as through
164
+ * class decorators, to inform the DI system about the real "identity" of a class.
165
+ *
166
+ * @param transformedClass The constructor function returned by a class decorator or factory.
167
+ * @param originalClass The original constructor function.
168
+ *
169
+ * @remarks
170
+ * This API affects the core class identity resolution mechanism of the DI system.
171
+ * Incorrect usage may cause metadata to be misassociated, leading to subtle errors.
172
+ * Use only when manipulating constructors (e.g., via decorators or proxies),
173
+ * and ensure the mapping is correct.
174
+ */ function setClassIdentityMapping(transformedClass, originalClass) {
175
+ classIdentityMap.set(transformedClass, originalClass);
176
+ }
159
177
  // @internal
160
178
  function getMetadata(Class) {
161
- let metadata = metadataMap.get(Class);
179
+ const originalClass = classIdentityMap.get(Class) ?? Class;
180
+ let metadata = metadataMap.get(originalClass);
162
181
  if (!metadata) {
163
- metadataMap.set(Class, metadata = {
182
+ metadataMap.set(originalClass, metadata = {
164
183
  tokensRef: {
165
184
  getRefTokens: ()=>new Set()
166
185
  },
167
186
  provider: {
168
- useClass: Class
187
+ useClass: originalClass
169
188
  },
170
189
  dependencies: {
171
190
  constructor: [],
@@ -175,6 +194,7 @@ function getMetadata(Class) {
175
194
  }
176
195
  return metadata;
177
196
  }
197
+ const classIdentityMap = new WeakMap();
178
198
  const metadataMap = new WeakMap();
179
199
 
180
200
  function optional(token) {
@@ -1120,4 +1140,5 @@ exports.forwardRef = forwardRef;
1120
1140
  exports.inject = inject;
1121
1141
  exports.injectAll = injectAll;
1122
1142
  exports.injectBy = injectBy;
1143
+ exports.setClassIdentityMapping = setClassIdentityMapping;
1123
1144
  //# sourceMappingURL=index.js.map