@lppedd/di-wise-neo 0.26.2 → 0.27.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.
@@ -112,11 +112,23 @@ type Tokens<Value> = [Token<Value>, ...Token<Value>[]];
112
112
  */
113
113
  declare function createType<T>(debugName: string): Type<T>;
114
114
  /**
115
- * Creates a type token with a default {@link Provider} and optional default registration options.
115
+ * Creates a type token with a default {@link ClassProvider} and optional default registration options.
116
+ *
117
+ * Example:
118
+ * ```ts
119
+ * const ISpell = createType<Spell>("Spell", {
120
+ * useClass: DefaultSpell,
121
+ * });
122
+ *
123
+ * container.register(ISpell);
124
+ * ```
125
+ */
126
+ declare function createType<T extends object>(debugName: string, provider: ClassProvider<T>, options?: RegistrationOptions): ProviderType<T>;
127
+ /**
128
+ * Creates a type token with a default {@link FactoryProvider} and optional default registration options.
116
129
  *
117
130
  * Example:
118
131
  * ```ts
119
- * // Notice how we pass in a Provider directly at type creation site
120
132
  * const ISpell = createType<Spell>("Spell", {
121
133
  * useFactory: () => getDefaultSpell(),
122
134
  * });
@@ -124,7 +136,34 @@ declare function createType<T>(debugName: string): Type<T>;
124
136
  * container.register(ISpell);
125
137
  * ```
126
138
  */
127
- declare function createType<T>(debugName: string, provider: Provider<T>, options?: RegistrationOptions): ProviderType<T>;
139
+ declare function createType<T>(debugName: string, provider: FactoryProvider<T>, options?: RegistrationOptions): ProviderType<T>;
140
+ /**
141
+ * Creates a type token with a default {@link ValueProvider} and optional default registration options.
142
+ *
143
+ * Example:
144
+ * ```ts
145
+ * const defaultSpell = getDefaultSpell();
146
+ * const ISpell = createType<Spell>("Spell", {
147
+ * useValue: defaultSpell,
148
+ * });
149
+ *
150
+ * container.register(ISpell);
151
+ * ```
152
+ */
153
+ declare function createType<T>(debugName: string, provider: ValueProvider<T>, options?: RegistrationOptions): ProviderType<T>;
154
+ /**
155
+ * Creates a type token with a default {@link ExistingProvider} and optional default registration options.
156
+ *
157
+ * Example:
158
+ * ```ts
159
+ * const ISpell = createType<Spell>("Spell", {
160
+ * useExisting: IBaseSpell,
161
+ * });
162
+ *
163
+ * container.register(ISpell);
164
+ * ```
165
+ */
166
+ declare function createType<T>(debugName: string, provider: ExistingProvider<T>, options?: RegistrationOptions): ProviderType<T>;
128
167
 
129
168
  interface ClassRef<Instance extends object> {
130
169
  readonly getRefClass: () => Constructor<Instance>;
@@ -647,6 +686,61 @@ interface Container {
647
686
  */
648
687
  declare function createContainer(options?: ContainerOptions): Container;
649
688
 
689
+ /**
690
+ * Class decorator that registers additional aliasing tokens for the decorated type.
691
+ *
692
+ * The aliases are added using {@link ExistingProvider}(s) when the class is first
693
+ * registered in the container.
694
+ *
695
+ * Example:
696
+ * ```ts
697
+ * @Alias(Weapon)
698
+ * class Rifle {}
699
+ * ```
700
+ *
701
+ * Note that `@Alias` decorators can be stacked to add multiple aliases.
702
+ *
703
+ * Example:
704
+ * ```ts
705
+ * @Alias(Weapon)
706
+ * @Alias(Gun) // Or just @Alias(Weapon, Gun)
707
+ * class Rifle {}
708
+ * ```
709
+ */
710
+ declare function Alias<Value, This extends Value & object>(token: Token<Value>): ClassDecorator<This>;
711
+ declare function Alias<VA, VB, This extends VA & VB & object>(tokenA: Token<VA>, tokenB: Token<VB>): ClassDecorator<This>;
712
+ declare function Alias<VA, VB, VC, This extends VA & VB & VC & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>): ClassDecorator<This>;
713
+ 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>;
714
+ 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>;
715
+ 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>;
716
+ /**
717
+ * Class decorator that registers an additional aliasing token for the decorated type.
718
+ *
719
+ * The alias is added using an {@link ExistingProvider} when the class is first
720
+ * registered in the container.
721
+ *
722
+ * This overload allows referencing tokens that are declared later in the file
723
+ * by using the {@link tokenRef} helper function.
724
+ *
725
+ * Example:
726
+ * ```ts
727
+ * @Alias(tokenRef(() => Weapon)) // Weapon is declared after Rifle
728
+ * class Rifle {}
729
+ * // Other code...
730
+ * const Weapon = createType("Weapon");
731
+ * ```
732
+ *
733
+ * Note that `@Alias` decorators can be stacked to add multiple aliases.
734
+ *
735
+ * Example:
736
+ * ```ts
737
+ * @Alias(tokenRef(() => Weapon))
738
+ * @Alias(Gun)
739
+ * class Rifle {}
740
+ * ```
741
+ */
742
+ declare function Alias<Value, This extends Value & object>(tokens: TokenRef<Value>): ClassDecorator<This>;
743
+
650
744
  /**
651
745
  * Class decorator that enables auto-registration of an unregistered class
652
746
  * when the class is first resolved from the container.
@@ -726,65 +820,6 @@ declare function Inject<Value>(token: Token<Value>): ParameterDecorator;
726
820
  */
727
821
  declare function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;
728
822
 
729
- /**
730
- * Class decorator that registers additional aliasing tokens for the decorated type.
731
- *
732
- * The aliases are added using {@link ExistingProvider}(s) when the class is first
733
- * registered in the container.
734
- *
735
- * Example:
736
- * ```ts
737
- * @Alias(Weapon)
738
- * class Rifle {}
739
- * ```
740
- *
741
- * Note that `@Alias` decorators can be stacked to add multiple aliases.
742
- *
743
- * Example:
744
- * ```ts
745
- * @Alias(Weapon)
746
- * @Alias(Gun) // Or just @Alias(Weapon, Gun)
747
- * class Rifle {}
748
- * ```
749
- */
750
- declare function Alias<Value, This extends Value & object>(token: Token<Value>): ClassDecorator<This>;
751
- declare function Alias<VA, VB, This extends VA & VB & object>(tokenA: Token<VA>, tokenB: Token<VB>): ClassDecorator<This>;
752
- declare function Alias<VA, VB, VC, This extends VA & VB & VC & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>): ClassDecorator<This>;
753
- 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>;
754
- 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>;
755
- 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>;
756
- /**
757
- * Class decorator that registers an additional aliasing token for the decorated type.
758
- *
759
- * The alias is added using an {@link ExistingProvider} when the class is first
760
- * registered in the container.
761
- *
762
- * This overload allows referencing tokens that are declared later in the file
763
- * by using the {@link tokenRef} helper function.
764
- *
765
- * Example:
766
- * ```ts
767
- * @Alias(tokenRef(() => Weapon)) // Weapon is declared after Rifle
768
- * class Rifle {}
769
- * // Other code...
770
- * const Weapon = createType("Weapon");
771
- * ```
772
- *
773
- * Note that `@Alias` decorators can be stacked to add multiple aliases.
774
- *
775
- * Example:
776
- * ```ts
777
- * @Alias(tokenRef(() => Weapon))
778
- * @Alias(Gun)
779
- * class Rifle {}
780
- * ```
781
- */
782
- declare function Alias<Value, This extends Value & object>(tokens: TokenRef<Value>): ClassDecorator<This>;
783
- /**
784
- * @deprecated Use {@link Alias} instead.
785
- */
786
- declare const Injectable: typeof Alias;
787
-
788
823
  /**
789
824
  * Parameter decorator that injects all instances provided by the registrations
790
825
  * associated with the given class.
@@ -1252,5 +1287,5 @@ declare function optionalBy<Instance extends object>(thisArg: object, Class: Con
1252
1287
  */
1253
1288
  declare function optionalBy<Value>(thisArg: object, token: Token<Value>, name?: string): Value | undefined;
1254
1289
 
1255
- 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 };
1290
+ export { Alias, AutoRegister, ContainerScoped, EagerInstantiate, Inject, InjectAll, Injector, Named, Optional, OptionalAll, ResolutionScoped, Scope, Scoped, TransientScoped, assertInjectionContext, build, classRef, createContainer, createType, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping, tokenRef };
1256
1291
  export type { ChildContainerOptions, ClassProvider, ClassRef, Constructor, Container, ContainerHook, ContainerOptions, ExistingProvider, FactoryProvider, Provider, ProviderType, RegistrationOptions, Token, TokenRef, Tokens, Type, ValueProvider };
package/dist/cjs/index.js CHANGED
@@ -1130,6 +1130,26 @@ function isDisposable(value) {
1130
1130
  return new ContainerImpl(undefined, options);
1131
1131
  }
1132
1132
 
1133
+ // @__NO_SIDE_EFFECTS__
1134
+ function Alias(...args) {
1135
+ return (target)=>{
1136
+ const metadata = getMetadata(target);
1137
+ const arg0 = args[0];
1138
+ const ref = isTokenRef(arg0) ? arg0 : tokenRef(()=>args);
1139
+ const currentRef = metadata.tokenRef;
1140
+ metadata.tokenRef = {
1141
+ getRefToken: ()=>currentRef.getRefToken(),
1142
+ getRefTokens: ()=>{
1143
+ const existingTokens = currentRef.getRefTokens();
1144
+ for (const token of ref.getRefTokens()){
1145
+ existingTokens.add(token);
1146
+ }
1147
+ return existingTokens;
1148
+ }
1149
+ };
1150
+ };
1151
+ }
1152
+
1133
1153
  /**
1134
1154
  * Class decorator that enables auto-registration of an unregistered class
1135
1155
  * when the class is first resolved from the container.
@@ -1194,29 +1214,6 @@ function Inject(token) {
1194
1214
  };
1195
1215
  }
1196
1216
 
1197
- // @__NO_SIDE_EFFECTS__
1198
- function Alias(...args) {
1199
- return (target)=>{
1200
- const metadata = getMetadata(target);
1201
- const arg0 = args[0];
1202
- const ref = isTokenRef(arg0) ? arg0 : tokenRef(()=>args);
1203
- const currentRef = metadata.tokenRef;
1204
- metadata.tokenRef = {
1205
- getRefToken: ()=>currentRef.getRefToken(),
1206
- getRefTokens: ()=>{
1207
- const existingTokens = currentRef.getRefTokens();
1208
- for (const token of ref.getRefTokens()){
1209
- existingTokens.add(token);
1210
- }
1211
- return existingTokens;
1212
- }
1213
- };
1214
- };
1215
- }
1216
- /**
1217
- * @deprecated Use {@link Alias} instead.
1218
- */ const Injectable = Alias;
1219
-
1220
1217
  // @__NO_SIDE_EFFECTS__
1221
1218
  function InjectAll(token) {
1222
1219
  return (target, propertyKey, parameterIndex)=>{
@@ -1445,7 +1442,6 @@ exports.ContainerScoped = ContainerScoped;
1445
1442
  exports.EagerInstantiate = EagerInstantiate;
1446
1443
  exports.Inject = Inject;
1447
1444
  exports.InjectAll = InjectAll;
1448
- exports.Injectable = Injectable;
1449
1445
  exports.Injector = Injector;
1450
1446
  exports.Named = Named;
1451
1447
  exports.Optional = Optional;