@lppedd/di-wise-neo 0.18.1 → 0.19.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 +3 -6
- package/dist/cjs/index.js +17 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +3 -6
- package/dist/es/index.mjs +17 -12
- package/dist/es/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/es/index.d.mts
CHANGED
|
@@ -130,7 +130,7 @@ interface ClassRef<Instance extends object> {
|
|
|
130
130
|
readonly getRefClass: () => Constructor<Instance>;
|
|
131
131
|
}
|
|
132
132
|
interface TokenRef<Value> {
|
|
133
|
-
readonly
|
|
133
|
+
readonly getRefToken: () => Token<Value>;
|
|
134
134
|
}
|
|
135
135
|
/**
|
|
136
136
|
* Allows referencing a class declared later in the file by wrapping it
|
|
@@ -140,12 +140,10 @@ interface TokenRef<Value> {
|
|
|
140
140
|
*/
|
|
141
141
|
declare function classRef<Instance extends object>(Class: () => Constructor<Instance>): ClassRef<Instance>;
|
|
142
142
|
/**
|
|
143
|
-
* Allows referencing
|
|
143
|
+
* Allows referencing a token declared later in the file by wrapping it
|
|
144
144
|
* into a lazily evaluated function.
|
|
145
|
-
*
|
|
146
|
-
* @__NO_SIDE_EFFECTS__
|
|
147
145
|
*/
|
|
148
|
-
declare function tokenRef<Value>(token: () => Token<Value>
|
|
146
|
+
declare function tokenRef<Value>(token: () => Token<Value>): TokenRef<Value>;
|
|
149
147
|
|
|
150
148
|
/**
|
|
151
149
|
* Provides a class instance for a token via a class constructor.
|
|
@@ -739,7 +737,6 @@ declare function Injectable<VA, VB, VC, This extends VA & VB & VC & object>(toke
|
|
|
739
737
|
declare function Injectable<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>;
|
|
740
738
|
declare function Injectable<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>;
|
|
741
739
|
declare function Injectable<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>;
|
|
742
|
-
declare function Injectable<This extends object>(...tokens: Tokens<unknown>): ClassDecorator<This>;
|
|
743
740
|
/**
|
|
744
741
|
* Class decorator that registers additional aliasing tokens for the decorated type
|
|
745
742
|
* when the type is first registered in the container.
|
package/dist/es/index.mjs
CHANGED
|
@@ -31,9 +31,8 @@ function throwResolutionError(tokenInfo, aliases, cause) {
|
|
|
31
31
|
// @internal
|
|
32
32
|
function throwParameterResolutionError(ctor, methodKey, dependency, cause) {
|
|
33
33
|
const location = getLocation(ctor, methodKey);
|
|
34
|
-
const [token] = dependency.tokenRef.getRefTokens();
|
|
35
34
|
const tokenName = getFullTokenName([
|
|
36
|
-
|
|
35
|
+
dependency.tokenRef.getRefToken(),
|
|
37
36
|
dependency.name
|
|
38
37
|
]);
|
|
39
38
|
const msg = tag(`failed to resolve dependency for ${location}(parameter #${dependency.index}: ${tokenName})`);
|
|
@@ -225,13 +224,14 @@ function injectBy(thisArg, token, name) {
|
|
|
225
224
|
getRefClass: ()=>Class()
|
|
226
225
|
};
|
|
227
226
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
* into a lazily evaluated function.
|
|
231
|
-
*
|
|
232
|
-
* @__NO_SIDE_EFFECTS__
|
|
233
|
-
*/ function tokenRef(token) {
|
|
227
|
+
// @__NO_SIDE_EFFECTS__
|
|
228
|
+
function tokenRef(token) {
|
|
234
229
|
return {
|
|
230
|
+
getRefToken: ()=>{
|
|
231
|
+
const tokenOrTokens = token();
|
|
232
|
+
check(!Array.isArray(tokenOrTokens), "internal error: single token expected");
|
|
233
|
+
return tokenOrTokens;
|
|
234
|
+
},
|
|
235
235
|
getRefTokens: ()=>{
|
|
236
236
|
// Normalize the single token here so that we don't have to do it at every getRefTokens call site
|
|
237
237
|
const tokenOrTokens = token();
|
|
@@ -248,7 +248,7 @@ function isClassRef(value) {
|
|
|
248
248
|
}
|
|
249
249
|
// @internal
|
|
250
250
|
function isTokenRef(value) {
|
|
251
|
-
return value != null && typeof value === "object" && typeof value.
|
|
251
|
+
return value != null && typeof value === "object" && typeof value.getRefToken === "function";
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
// @internal
|
|
@@ -259,6 +259,10 @@ class Metadata {
|
|
|
259
259
|
methods: new Map()
|
|
260
260
|
};
|
|
261
261
|
this.tokenRef = {
|
|
262
|
+
// prettier-ignore
|
|
263
|
+
getRefToken: ()=>{
|
|
264
|
+
check(false, "internal error: unexpected call");
|
|
265
|
+
},
|
|
262
266
|
getRefTokens: ()=>new Set()
|
|
263
267
|
};
|
|
264
268
|
this.provider = {
|
|
@@ -1053,7 +1057,7 @@ function isDisposable(value) {
|
|
|
1053
1057
|
}
|
|
1054
1058
|
// Call context: decorator-based injection
|
|
1055
1059
|
resolveDependency(dependency, instance) {
|
|
1056
|
-
const
|
|
1060
|
+
const token = dependency.tokenRef.getRefToken();
|
|
1057
1061
|
check(token, `token passed to @${dependency.appliedBy} was undefined (possible circular imports)`);
|
|
1058
1062
|
const name = dependency.name;
|
|
1059
1063
|
switch(dependency.appliedBy){
|
|
@@ -1161,10 +1165,11 @@ function Injectable(...args) {
|
|
|
1161
1165
|
const metadata = getMetadata(Class);
|
|
1162
1166
|
const arg0 = args[0];
|
|
1163
1167
|
const ref = isTokenRef(arg0) ? arg0 : tokenRef(()=>args);
|
|
1164
|
-
const
|
|
1168
|
+
const currentRef = metadata.tokenRef;
|
|
1165
1169
|
metadata.tokenRef = {
|
|
1170
|
+
getRefToken: ()=>currentRef.getRefToken(),
|
|
1166
1171
|
getRefTokens: ()=>{
|
|
1167
|
-
const existingTokens =
|
|
1172
|
+
const existingTokens = currentRef.getRefTokens();
|
|
1168
1173
|
for (const token of ref.getRefTokens()){
|
|
1169
1174
|
existingTokens.add(token);
|
|
1170
1175
|
}
|