@lppedd/di-wise-neo 0.7.0 → 0.7.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.
- package/dist/cjs/index.d.ts +51 -5
- package/dist/cjs/index.js +8 -11
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +51 -5
- package/dist/es/index.mjs +6 -12
- 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
|
@@ -1183,9 +1177,9 @@ function OptionalAll(token) {
|
|
1183
1177
|
}
|
1184
1178
|
}
|
1185
1179
|
return {
|
1186
|
-
inject: (token)=>withCurrentContext(()=>inject(token)),
|
1180
|
+
inject: (token, name)=>withCurrentContext(()=>inject(token, name)),
|
1187
1181
|
injectAll: (token)=>withCurrentContext(()=>injectAll(token)),
|
1188
|
-
optional: (token)=>withCurrentContext(()=>optional(token)),
|
1182
|
+
optional: (token, name)=>withCurrentContext(()=>optional(token, name)),
|
1189
1183
|
optionalAll: (token)=>withCurrentContext(()=>optionalAll(token))
|
1190
1184
|
};
|
1191
1185
|
});
|
@@ -1253,5 +1247,8 @@ exports.forwardRef = forwardRef;
|
|
1253
1247
|
exports.inject = inject;
|
1254
1248
|
exports.injectAll = injectAll;
|
1255
1249
|
exports.injectBy = injectBy;
|
1250
|
+
exports.optional = optional;
|
1251
|
+
exports.optionalAll = optionalAll;
|
1252
|
+
exports.optionalBy = optionalBy;
|
1256
1253
|
exports.setClassIdentityMapping = setClassIdentityMapping;
|
1257
1254
|
//# sourceMappingURL=index.js.map
|