@lppedd/di-wise-neo 0.25.0 → 0.26.1

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.
@@ -75,6 +75,10 @@ interface Type<T> extends ParameterDecorator {
75
75
  * An injectable type `T` with a default {@link Provider} and optional default registration options.
76
76
  */
77
77
  interface ProviderType<T> extends Type<T> {
78
+ /**
79
+ * The underlying `Type<T>`.
80
+ */
81
+ readonly type: Type<T>;
78
82
  /**
79
83
  * The type's default provider.
80
84
  */
@@ -399,7 +403,7 @@ interface Container {
399
403
  /**
400
404
  * Registers a {@link ClassProvider}, using the class itself as its token.
401
405
  *
402
- * Tokens provided via the {@link Injectable} decorator applied to the class
406
+ * Tokens provided via the {@link Alias} decorator applied to the class
403
407
  * are also registered as aliases.
404
408
  *
405
409
  * The scope is determined by the {@link Scoped} decorator - if present -
@@ -436,7 +440,10 @@ interface Container {
436
440
  */
437
441
  register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ValueProvider<ProviderValue>): Container;
438
442
  /**
439
- * Removes all registrations for the given token from the container's internal registry.
443
+ * Removes registrations for the given token from the container's internal registry.
444
+ *
445
+ * When a `name` is provided, only the registration with that `name` is removed.
446
+ * Otherwise, all registrations are removed.
440
447
  *
441
448
  * Returns an array of the distinct values that were cached by this container for the
442
449
  * removed registrations. Values from {@link ValueProvider} registrations are not included,
@@ -731,25 +738,25 @@ declare function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;
731
738
  *
732
739
  * Example:
733
740
  * ```ts
734
- * @Injectable(Weapon)
741
+ * @Alias(Weapon)
735
742
  * class Rifle {}
736
743
  * ```
737
744
  *
738
- * Note that `@Injectable` decorators can be stacked to add multiple aliases.
745
+ * Note that `@Alias` decorators can be stacked to add multiple aliases.
739
746
  *
740
747
  * Example:
741
748
  * ```ts
742
- * @Injectable(Weapon)
743
- * @Injectable(Gun) // Or just @Injectable(Weapon, Gun)
749
+ * @Alias(Weapon)
750
+ * @Alias(Gun) // Or just @Alias(Weapon, Gun)
744
751
  * class Rifle {}
745
752
  * ```
746
753
  */
747
- declare function Injectable<Value, This extends Value & object>(token: Token<Value>): ClassDecorator<This>;
748
- declare function Injectable<VA, VB, This extends VA & VB & object>(tokenA: Token<VA>, tokenB: Token<VB>): ClassDecorator<This>;
749
- declare function Injectable<VA, VB, VC, This extends VA & VB & VC & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>): ClassDecorator<This>;
750
- declare function Injectable<VA, VB, VC, VD, This extends VA & VB & VC & VD & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>): ClassDecorator<This>;
751
- declare function Injectable<VA, VB, VC, VD, VE, This extends VA & VB & VC & VD & VE & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>, tokenE: Token<VE>): ClassDecorator<This>;
752
- declare function Injectable<VA, VB, VC, VD, VE, VF, This extends VA & VB & VC & VD & VE & VF & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>, tokenE: Token<VE>, tokenF: Token<VF>): ClassDecorator<This>;
754
+ declare function Alias<Value, This extends Value & object>(token: Token<Value>): ClassDecorator<This>;
755
+ declare function Alias<VA, VB, This extends VA & VB & object>(tokenA: Token<VA>, tokenB: Token<VB>): ClassDecorator<This>;
756
+ declare function Alias<VA, VB, VC, This extends VA & VB & VC & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>): ClassDecorator<This>;
757
+ declare function Alias<VA, VB, VC, VD, This extends VA & VB & VC & VD & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>): ClassDecorator<This>;
758
+ declare function Alias<VA, VB, VC, VD, VE, This extends VA & VB & VC & VD & VE & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>, tokenE: Token<VE>): ClassDecorator<This>;
759
+ declare function Alias<VA, VB, VC, VD, VE, VF, This extends VA & VB & VC & VD & VE & VF & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>, tokenD: Token<VD>, tokenE: Token<VE>, tokenF: Token<VF>): ClassDecorator<This>;
753
760
  /**
754
761
  * Class decorator that registers an additional aliasing token for the decorated type.
755
762
  *
@@ -761,22 +768,26 @@ declare function Injectable<VA, VB, VC, VD, VE, VF, This extends VA & VB & VC &
761
768
  *
762
769
  * Example:
763
770
  * ```ts
764
- * @Injectable(tokenRef(() => Weapon)) // Weapon is declared after Rifle
771
+ * @Alias(tokenRef(() => Weapon)) // Weapon is declared after Rifle
765
772
  * class Rifle {}
766
773
  * // Other code...
767
774
  * const Weapon = createType("Weapon");
768
775
  * ```
769
776
  *
770
- * Note that `@Injectable` decorators can be stacked to add multiple aliases.
777
+ * Note that `@Alias` decorators can be stacked to add multiple aliases.
771
778
  *
772
779
  * Example:
773
780
  * ```ts
774
- * @Injectable(tokenRef(() => Weapon))
775
- * @Injectable(Gun)
781
+ * @Alias(tokenRef(() => Weapon))
782
+ * @Alias(Gun)
776
783
  * class Rifle {}
777
784
  * ```
778
785
  */
779
- declare function Injectable<Value, This extends Value & object>(tokens: TokenRef<Value>): ClassDecorator<This>;
786
+ declare function Alias<Value, This extends Value & object>(tokens: TokenRef<Value>): ClassDecorator<This>;
787
+ /**
788
+ * @deprecated Use {@link Alias} instead.
789
+ */
790
+ declare const Injectable: typeof Alias;
780
791
 
781
792
  /**
782
793
  * Parameter decorator that injects all instances provided by the registrations
@@ -1245,5 +1256,5 @@ declare function optionalBy<Instance extends object>(thisArg: object, Class: Con
1245
1256
  */
1246
1257
  declare function optionalBy<Value>(thisArg: object, token: Token<Value>, name?: string): Value | undefined;
1247
1258
 
1248
- export { AutoRegister, ContainerScoped, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, ResolutionScoped, Scope, Scoped, TransientScoped, assertInjectionContext, build, classRef, createContainer, createType, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping, tokenRef };
1259
+ export { Alias, AutoRegister, ContainerScoped, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, ResolutionScoped, Scope, Scoped, TransientScoped, assertInjectionContext, build, classRef, createContainer, createType, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping, tokenRef };
1249
1260
  export type { ChildContainerOptions, ClassProvider, ClassRef, Constructor, Container, ContainerHook, ContainerOptions, ExistingProvider, FactoryProvider, Provider, ProviderType, RegistrationOptions, Token, TokenRef, Tokens, Type, ValueProvider };
package/dist/es/index.mjs CHANGED
@@ -451,6 +451,7 @@ function createType(debugName, provider, options) {
451
451
  type.__type = undefined;
452
452
  type.toString = ()=>name;
453
453
  if (provider) {
454
+ type.type = type;
454
455
  type.provider = provider;
455
456
  type.options = options;
456
457
  }
@@ -788,10 +789,10 @@ function isDisposable(value) {
788
789
  };
789
790
  // Register the class itself
790
791
  this.myTokenRegistry.put(Class, registration);
791
- // Register the additional tokens specified via class decorators.
792
- // These tokens will point to the original Class token and will have the same scope.
793
- for (const token of metadata.tokenRef.getRefTokens()){
794
- this.myTokenRegistry.put(token, {
792
+ // Register additional aliasing tokens specified via class decorators.
793
+ // These tokens will point to the original class token and will have the same scope.
794
+ for (const aliasToken of metadata.tokenRef.getRefTokens()){
795
+ this.myTokenRegistry.put(aliasToken, {
795
796
  name: name,
796
797
  provider: {
797
798
  useExisting: [
@@ -813,9 +814,10 @@ function isDisposable(value) {
813
814
  check(name === undefined || name.trim(), `name qualifier for token ${getTokenName(token)} must not be empty`);
814
815
  if (isClassProvider(provider)) {
815
816
  const metadata = getMetadata(provider.useClass);
817
+ // An explicit provider name overrides what is specified via @Named
818
+ const effectiveName = name ?? metadata.name;
816
819
  const registration = {
817
- // An explicit provider name overrides what is specified via @Named
818
- name: metadata.name ?? name,
820
+ name: effectiveName,
819
821
  provider: metadata.provider,
820
822
  options: {
821
823
  // Explicit registration options override what is specified via class decorators (e.g., @Scoped)
@@ -824,7 +826,21 @@ function isDisposable(value) {
824
826
  },
825
827
  dependencies: metadata.dependencies
826
828
  };
829
+ // Register the class itself
827
830
  this.myTokenRegistry.put(token, registration);
831
+ // Register additional aliasing tokens specified via class decorators.
832
+ // These tokens will point to the original class token and will have the same scope.
833
+ for (const aliasToken of metadata.tokenRef.getRefTokens()){
834
+ this.myTokenRegistry.put(aliasToken, {
835
+ name: effectiveName,
836
+ provider: {
837
+ useExisting: [
838
+ token,
839
+ effectiveName
840
+ ]
841
+ }
842
+ });
843
+ }
828
844
  // Eager-instantiate only if the provided class is container-scoped.
829
845
  // Note that we are comparing the scope using the registration configured just above,
830
846
  // which takes into account both the metadata and the container option as a fallback.
@@ -1178,7 +1194,7 @@ function Inject(token) {
1178
1194
  }
1179
1195
 
1180
1196
  // @__NO_SIDE_EFFECTS__
1181
- function Injectable(...args) {
1197
+ function Alias(...args) {
1182
1198
  return (target)=>{
1183
1199
  const metadata = getMetadata(target);
1184
1200
  const arg0 = args[0];
@@ -1196,6 +1212,9 @@ function Injectable(...args) {
1196
1212
  };
1197
1213
  };
1198
1214
  }
1215
+ /**
1216
+ * @deprecated Use {@link Alias} instead.
1217
+ */ const Injectable = Alias;
1199
1218
 
1200
1219
  // @__NO_SIDE_EFFECTS__
1201
1220
  function InjectAll(token) {
@@ -1419,5 +1438,5 @@ const Scope = {
1419
1438
  */ Container: "Container"
1420
1439
  };
1421
1440
 
1422
- export { AutoRegister, ContainerScoped, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, ResolutionScoped, Scope, Scoped, TransientScoped, assertInjectionContext, build, classRef, createContainer, createType, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping, tokenRef };
1441
+ export { Alias, AutoRegister, ContainerScoped, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, ResolutionScoped, Scope, Scoped, TransientScoped, assertInjectionContext, build, classRef, createContainer, createType, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping, tokenRef };
1423
1442
  //# sourceMappingURL=index.mjs.map