@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/es/index.d.mts
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/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
|
|
792
|
+
// Register additional aliasing tokens specified via class decorators.
|
|
792
793
|
// These tokens will point to the original Class token and will have the same scope.
|
|
793
|
-
for (const
|
|
794
|
-
this.myTokenRegistry.put(
|
|
794
|
+
for (const aliasToken of metadata.tokenRef.getRefTokens()){
|
|
795
|
+
this.myTokenRegistry.put(aliasToken, {
|
|
795
796
|
name: name,
|
|
796
797
|
provider: {
|
|
797
798
|
useExisting: [
|
|
@@ -825,6 +826,19 @@ function isDisposable(value) {
|
|
|
825
826
|
dependencies: metadata.dependencies
|
|
826
827
|
};
|
|
827
828
|
this.myTokenRegistry.put(token, registration);
|
|
829
|
+
// Register additional aliasing tokens specified via class decorators.
|
|
830
|
+
// These tokens will point to the original token and will have the same scope.
|
|
831
|
+
for (const aliasToken of metadata.tokenRef.getRefTokens()){
|
|
832
|
+
this.myTokenRegistry.put(aliasToken, {
|
|
833
|
+
name: name,
|
|
834
|
+
provider: {
|
|
835
|
+
useExisting: [
|
|
836
|
+
token,
|
|
837
|
+
name
|
|
838
|
+
]
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
828
842
|
// Eager-instantiate only if the provided class is container-scoped.
|
|
829
843
|
// Note that we are comparing the scope using the registration configured just above,
|
|
830
844
|
// which takes into account both the metadata and the container option as a fallback.
|
|
@@ -1178,7 +1192,7 @@ function Inject(token) {
|
|
|
1178
1192
|
}
|
|
1179
1193
|
|
|
1180
1194
|
// @__NO_SIDE_EFFECTS__
|
|
1181
|
-
function
|
|
1195
|
+
function Alias(...args) {
|
|
1182
1196
|
return (target)=>{
|
|
1183
1197
|
const metadata = getMetadata(target);
|
|
1184
1198
|
const arg0 = args[0];
|
|
@@ -1196,6 +1210,9 @@ function Injectable(...args) {
|
|
|
1196
1210
|
};
|
|
1197
1211
|
};
|
|
1198
1212
|
}
|
|
1213
|
+
/**
|
|
1214
|
+
* @deprecated Use {@link Alias} instead.
|
|
1215
|
+
*/ const Injectable = Alias;
|
|
1199
1216
|
|
|
1200
1217
|
// @__NO_SIDE_EFFECTS__
|
|
1201
1218
|
function InjectAll(token) {
|
|
@@ -1419,5 +1436,5 @@ const Scope = {
|
|
|
1419
1436
|
*/ Container: "Container"
|
|
1420
1437
|
};
|
|
1421
1438
|
|
|
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 };
|
|
1439
|
+
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
1440
|
//# sourceMappingURL=index.mjs.map
|