@lppedd/di-wise-neo 0.7.0 → 0.7.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.
- package/dist/cjs/index.d.ts +51 -5
- package/dist/cjs/index.js +12 -13
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +51 -5
- package/dist/es/index.mjs +10 -14
- package/dist/es/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.d.ts
CHANGED
@@ -772,13 +772,13 @@ interface Injector {
|
|
772
772
|
*
|
773
773
|
* Throws an error if the class is not registered in the container.
|
774
774
|
*/
|
775
|
-
inject<Instance extends object>(Class: Constructor<Instance
|
775
|
+
inject<Instance extends object>(Class: Constructor<Instance>, name?: string): Instance;
|
776
776
|
/**
|
777
777
|
* Injects the value associated with the given token.
|
778
778
|
*
|
779
779
|
* Throws an error if the token is not registered in the container.
|
780
780
|
*/
|
781
|
-
inject<Value>(token: Token<Value
|
781
|
+
inject<Value>(token: Token<Value>, name?: string): Value;
|
782
782
|
/**
|
783
783
|
* Injects all instances provided by the registrations associated with the given class.
|
784
784
|
*
|
@@ -795,12 +795,12 @@ interface Injector {
|
|
795
795
|
* Injects the instance associated with the given class,
|
796
796
|
* or `undefined` if the class is not registered in the container.
|
797
797
|
*/
|
798
|
-
optional<Instance extends object>(Class: Constructor<Instance
|
798
|
+
optional<Instance extends object>(Class: Constructor<Instance>, name?: string): Instance | undefined;
|
799
799
|
/**
|
800
800
|
* Injects the value associated with the given token,
|
801
801
|
* or `undefined` if the token is not registered in the container.
|
802
802
|
*/
|
803
|
-
optional<Value>(token: Token<Value
|
803
|
+
optional<Value>(token: Token<Value>, name?: string): Value | undefined;
|
804
804
|
/**
|
805
805
|
* Injects all instances provided by the registrations associated with the given class,
|
806
806
|
* or an empty array if the class is not registered in the container.
|
@@ -905,5 +905,51 @@ interface Middleware {
|
|
905
905
|
*/
|
906
906
|
declare function applyMiddleware(container: Container, middlewares: Middleware[]): Container;
|
907
907
|
|
908
|
-
|
908
|
+
/**
|
909
|
+
* Injects the instance associated with the given class,
|
910
|
+
* or `undefined` if the class is not registered in the container.
|
911
|
+
*/
|
912
|
+
declare function optional<Instance extends object>(Class: Constructor<Instance>, name?: string): Instance | undefined;
|
913
|
+
/**
|
914
|
+
* Injects the value associated with the given token,
|
915
|
+
* or `undefined` if the token is not registered in the container.
|
916
|
+
*/
|
917
|
+
declare function optional<Value>(token: Token<Value>, name?: string): Value | undefined;
|
918
|
+
/**
|
919
|
+
* Injects the instance associated with the given class,
|
920
|
+
* or `undefined` if the class is not registered in the container.
|
921
|
+
*
|
922
|
+
* Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument
|
923
|
+
* (the containing class) which is used to resolve circular dependencies.
|
924
|
+
*
|
925
|
+
* @param thisArg - The containing instance, used to help resolve circular dependencies.
|
926
|
+
* @param Class - The class to resolve.
|
927
|
+
* @param name - The name qualifier of the class to resolve.
|
928
|
+
*/
|
929
|
+
declare function optionalBy<Instance extends object>(thisArg: any, Class: Constructor<Instance>, name?: string): Instance | undefined;
|
930
|
+
/**
|
931
|
+
* Injects the value associated with the given token,
|
932
|
+
* or `undefined` if the token is not registered in the container.
|
933
|
+
*
|
934
|
+
* Compared to {@link optional}, `optionalBy` accepts a `thisArg` argument
|
935
|
+
* (the containing class) which is used to resolve circular dependencies.
|
936
|
+
*
|
937
|
+
* @param thisArg - The containing instance, used to help resolve circular dependencies.
|
938
|
+
* @param token - The token to resolve.
|
939
|
+
* @param name - The name qualifier of the token to resolve.
|
940
|
+
*/
|
941
|
+
declare function optionalBy<Value>(thisArg: any, token: Token<Value>, name?: string): Value | undefined;
|
942
|
+
|
943
|
+
/**
|
944
|
+
* Injects all instances provided by the registrations associated with the given class,
|
945
|
+
* or an empty array if the class is not registered in the container.
|
946
|
+
*/
|
947
|
+
declare function optionalAll<Instance extends object>(Class: Constructor<Instance>): Instance[];
|
948
|
+
/**
|
949
|
+
* Injects all values provided by the registrations associated with the given token,
|
950
|
+
* or an empty array if the token is not registered in the container.
|
951
|
+
*/
|
952
|
+
declare function optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];
|
953
|
+
|
954
|
+
export { AutoRegister, EagerInstantiate, Inject, InjectAll, Injectable, Injector, Named, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy, optional, optionalAll, optionalBy, setClassIdentityMapping };
|
909
955
|
export type { ClassProvider, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, Type, ValueProvider };
|
package/dist/cjs/index.js
CHANGED
@@ -3,8 +3,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
3
3
|
// @internal
|
4
4
|
function assert(condition, message) {
|
5
5
|
if (!condition) {
|
6
|
-
|
7
|
-
throw new Error(tag(resolvedMessage));
|
6
|
+
throw new Error(tag(typeof message === "string" ? message : message()));
|
8
7
|
}
|
9
8
|
}
|
10
9
|
// @internal
|
@@ -18,11 +17,7 @@ function throwUnregisteredError(token) {
|
|
18
17
|
// @internal
|
19
18
|
function throwExistingUnregisteredError(sourceToken, targetTokenOrError) {
|
20
19
|
let message = tag(`token resolution error encountered while resolving ${sourceToken.name}`);
|
21
|
-
|
22
|
-
message += `\n [cause] ${untag(targetTokenOrError.message)}`;
|
23
|
-
} else {
|
24
|
-
message += `\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;
|
25
|
-
}
|
20
|
+
message += isError(targetTokenOrError) ? `\n [cause] ${untag(targetTokenOrError.message)}` : `\n [cause] the aliased token ${targetTokenOrError.name} is not registered`;
|
26
21
|
throw new Error(message);
|
27
22
|
}
|
28
23
|
function isError(value) {
|
@@ -33,8 +28,7 @@ function tag(message) {
|
|
33
28
|
return `[di-wise-neo] ${message}`;
|
34
29
|
}
|
35
30
|
function untag(message) {
|
36
|
-
return message.startsWith("[di-wise-neo]")
|
37
|
-
? message.substring(13).trimStart() : message;
|
31
|
+
return message.startsWith("[di-wise-neo]") ? message.substring(13).trimStart() : message;
|
38
32
|
}
|
39
33
|
|
40
34
|
// @internal
|
@@ -583,6 +577,9 @@ function isDisposable(value) {
|
|
583
577
|
}
|
584
578
|
} else {
|
585
579
|
const [token, provider, options] = args;
|
580
|
+
const existingProvider = isExistingProvider(provider);
|
581
|
+
const name = existingProvider ? undefined : provider.name;
|
582
|
+
assert(name === undefined || name.trim(), "the provider name qualifier cannot be empty or blank");
|
586
583
|
if (isClassProvider(provider)) {
|
587
584
|
const metadata = getMetadata(provider.useClass);
|
588
585
|
const registration = {
|
@@ -602,12 +599,11 @@ function isDisposable(value) {
|
|
602
599
|
this.resolveProviderValue(registration, registration.provider);
|
603
600
|
}
|
604
601
|
} else {
|
605
|
-
const existingProvider = isExistingProvider(provider);
|
606
602
|
if (existingProvider) {
|
607
603
|
assert(token !== provider.useExisting, `the useExisting token ${token.name} cannot be the same as the token being registered`);
|
608
604
|
}
|
609
605
|
this.myTokenRegistry.set(token, {
|
610
|
-
name:
|
606
|
+
name: name,
|
611
607
|
provider: provider,
|
612
608
|
options: options
|
613
609
|
});
|
@@ -1183,9 +1179,9 @@ function OptionalAll(token) {
|
|
1183
1179
|
}
|
1184
1180
|
}
|
1185
1181
|
return {
|
1186
|
-
inject: (token)=>withCurrentContext(()=>inject(token)),
|
1182
|
+
inject: (token, name)=>withCurrentContext(()=>inject(token, name)),
|
1187
1183
|
injectAll: (token)=>withCurrentContext(()=>injectAll(token)),
|
1188
|
-
optional: (token)=>withCurrentContext(()=>optional(token)),
|
1184
|
+
optional: (token, name)=>withCurrentContext(()=>optional(token, name)),
|
1189
1185
|
optionalAll: (token)=>withCurrentContext(()=>optionalAll(token))
|
1190
1186
|
};
|
1191
1187
|
});
|
@@ -1253,5 +1249,8 @@ exports.forwardRef = forwardRef;
|
|
1253
1249
|
exports.inject = inject;
|
1254
1250
|
exports.injectAll = injectAll;
|
1255
1251
|
exports.injectBy = injectBy;
|
1252
|
+
exports.optional = optional;
|
1253
|
+
exports.optionalAll = optionalAll;
|
1254
|
+
exports.optionalBy = optionalBy;
|
1256
1255
|
exports.setClassIdentityMapping = setClassIdentityMapping;
|
1257
1256
|
//# sourceMappingURL=index.js.map
|