@lppedd/di-wise-neo 0.25.0 → 0.26.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.
- package/dist/cjs/index.d.ts +25 -17
- package/dist/cjs/index.js +22 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +25 -17
- package/dist/es/index.mjs +22 -5
- package/dist/es/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/cjs/index.d.ts
CHANGED
|
@@ -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
|
|
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 -
|
|
@@ -731,25 +735,25 @@ declare function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;
|
|
|
731
735
|
*
|
|
732
736
|
* Example:
|
|
733
737
|
* ```ts
|
|
734
|
-
* @
|
|
738
|
+
* @Alias(Weapon)
|
|
735
739
|
* class Rifle {}
|
|
736
740
|
* ```
|
|
737
741
|
*
|
|
738
|
-
* Note that `@
|
|
742
|
+
* Note that `@Alias` decorators can be stacked to add multiple aliases.
|
|
739
743
|
*
|
|
740
744
|
* Example:
|
|
741
745
|
* ```ts
|
|
742
|
-
* @
|
|
743
|
-
* @
|
|
746
|
+
* @Alias(Weapon)
|
|
747
|
+
* @Alias(Gun) // Or just @Alias(Weapon, Gun)
|
|
744
748
|
* class Rifle {}
|
|
745
749
|
* ```
|
|
746
750
|
*/
|
|
747
|
-
declare function
|
|
748
|
-
declare function
|
|
749
|
-
declare function
|
|
750
|
-
declare function
|
|
751
|
-
declare function
|
|
752
|
-
declare function
|
|
751
|
+
declare function Alias<Value, This extends Value & object>(token: Token<Value>): ClassDecorator<This>;
|
|
752
|
+
declare function Alias<VA, VB, This extends VA & VB & object>(tokenA: Token<VA>, tokenB: Token<VB>): ClassDecorator<This>;
|
|
753
|
+
declare function Alias<VA, VB, VC, This extends VA & VB & VC & object>(tokenA: Token<VA>, tokenB: Token<VB>, tokenC: Token<VC>): ClassDecorator<This>;
|
|
754
|
+
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>;
|
|
755
|
+
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>;
|
|
756
|
+
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
757
|
/**
|
|
754
758
|
* Class decorator that registers an additional aliasing token for the decorated type.
|
|
755
759
|
*
|
|
@@ -761,22 +765,26 @@ declare function Injectable<VA, VB, VC, VD, VE, VF, This extends VA & VB & VC &
|
|
|
761
765
|
*
|
|
762
766
|
* Example:
|
|
763
767
|
* ```ts
|
|
764
|
-
* @
|
|
768
|
+
* @Alias(tokenRef(() => Weapon)) // Weapon is declared after Rifle
|
|
765
769
|
* class Rifle {}
|
|
766
770
|
* // Other code...
|
|
767
771
|
* const Weapon = createType("Weapon");
|
|
768
772
|
* ```
|
|
769
773
|
*
|
|
770
|
-
* Note that `@
|
|
774
|
+
* Note that `@Alias` decorators can be stacked to add multiple aliases.
|
|
771
775
|
*
|
|
772
776
|
* Example:
|
|
773
777
|
* ```ts
|
|
774
|
-
* @
|
|
775
|
-
* @
|
|
778
|
+
* @Alias(tokenRef(() => Weapon))
|
|
779
|
+
* @Alias(Gun)
|
|
776
780
|
* class Rifle {}
|
|
777
781
|
* ```
|
|
778
782
|
*/
|
|
779
|
-
declare function
|
|
783
|
+
declare function Alias<Value, This extends Value & object>(tokens: TokenRef<Value>): ClassDecorator<This>;
|
|
784
|
+
/**
|
|
785
|
+
* @deprecated Use {@link Alias} instead.
|
|
786
|
+
*/
|
|
787
|
+
declare const Injectable: typeof Alias;
|
|
780
788
|
|
|
781
789
|
/**
|
|
782
790
|
* Parameter decorator that injects all instances provided by the registrations
|
|
@@ -1245,5 +1253,5 @@ declare function optionalBy<Instance extends object>(thisArg: object, Class: Con
|
|
|
1245
1253
|
*/
|
|
1246
1254
|
declare function optionalBy<Value>(thisArg: object, token: Token<Value>, name?: string): Value | undefined;
|
|
1247
1255
|
|
|
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 };
|
|
1256
|
+
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
1257
|
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
|
@@ -453,6 +453,7 @@ function createType(debugName, provider, options) {
|
|
|
453
453
|
type.__type = undefined;
|
|
454
454
|
type.toString = ()=>name;
|
|
455
455
|
if (provider) {
|
|
456
|
+
type.type = type;
|
|
456
457
|
type.provider = provider;
|
|
457
458
|
type.options = options;
|
|
458
459
|
}
|
|
@@ -790,10 +791,10 @@ function isDisposable(value) {
|
|
|
790
791
|
};
|
|
791
792
|
// Register the class itself
|
|
792
793
|
this.myTokenRegistry.put(Class, registration);
|
|
793
|
-
// Register
|
|
794
|
+
// Register additional aliasing tokens specified via class decorators.
|
|
794
795
|
// These tokens will point to the original Class token and will have the same scope.
|
|
795
|
-
for (const
|
|
796
|
-
this.myTokenRegistry.put(
|
|
796
|
+
for (const aliasToken of metadata.tokenRef.getRefTokens()){
|
|
797
|
+
this.myTokenRegistry.put(aliasToken, {
|
|
797
798
|
name: name,
|
|
798
799
|
provider: {
|
|
799
800
|
useExisting: [
|
|
@@ -827,6 +828,19 @@ function isDisposable(value) {
|
|
|
827
828
|
dependencies: metadata.dependencies
|
|
828
829
|
};
|
|
829
830
|
this.myTokenRegistry.put(token, registration);
|
|
831
|
+
// Register additional aliasing tokens specified via class decorators.
|
|
832
|
+
// These tokens will point to the original token and will have the same scope.
|
|
833
|
+
for (const aliasToken of metadata.tokenRef.getRefTokens()){
|
|
834
|
+
this.myTokenRegistry.put(aliasToken, {
|
|
835
|
+
name: name,
|
|
836
|
+
provider: {
|
|
837
|
+
useExisting: [
|
|
838
|
+
token,
|
|
839
|
+
name
|
|
840
|
+
]
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
}
|
|
830
844
|
// Eager-instantiate only if the provided class is container-scoped.
|
|
831
845
|
// Note that we are comparing the scope using the registration configured just above,
|
|
832
846
|
// which takes into account both the metadata and the container option as a fallback.
|
|
@@ -1180,7 +1194,7 @@ function Inject(token) {
|
|
|
1180
1194
|
}
|
|
1181
1195
|
|
|
1182
1196
|
// @__NO_SIDE_EFFECTS__
|
|
1183
|
-
function
|
|
1197
|
+
function Alias(...args) {
|
|
1184
1198
|
return (target)=>{
|
|
1185
1199
|
const metadata = getMetadata(target);
|
|
1186
1200
|
const arg0 = args[0];
|
|
@@ -1198,6 +1212,9 @@ function Injectable(...args) {
|
|
|
1198
1212
|
};
|
|
1199
1213
|
};
|
|
1200
1214
|
}
|
|
1215
|
+
/**
|
|
1216
|
+
* @deprecated Use {@link Alias} instead.
|
|
1217
|
+
*/ const Injectable = Alias;
|
|
1201
1218
|
|
|
1202
1219
|
// @__NO_SIDE_EFFECTS__
|
|
1203
1220
|
function InjectAll(token) {
|
|
@@ -1421,6 +1438,7 @@ const Scope = {
|
|
|
1421
1438
|
*/ Container: "Container"
|
|
1422
1439
|
};
|
|
1423
1440
|
|
|
1441
|
+
exports.Alias = Alias;
|
|
1424
1442
|
exports.AutoRegister = AutoRegister;
|
|
1425
1443
|
exports.ContainerScoped = ContainerScoped;
|
|
1426
1444
|
exports.EagerInstantiate = EagerInstantiate;
|