@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/cjs/index.d.ts
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/cjs/index.js
CHANGED
|
@@ -33,9 +33,8 @@ function throwResolutionError(tokenInfo, aliases, cause) {
|
|
|
33
33
|
// @internal
|
|
34
34
|
function throwParameterResolutionError(ctor, methodKey, dependency, cause) {
|
|
35
35
|
const location = getLocation(ctor, methodKey);
|
|
36
|
-
const [token] = dependency.tokenRef.getRefTokens();
|
|
37
36
|
const tokenName = getFullTokenName([
|
|
38
|
-
|
|
37
|
+
dependency.tokenRef.getRefToken(),
|
|
39
38
|
dependency.name
|
|
40
39
|
]);
|
|
41
40
|
const msg = tag(`failed to resolve dependency for ${location}(parameter #${dependency.index}: ${tokenName})`);
|
|
@@ -227,13 +226,14 @@ function injectBy(thisArg, token, name) {
|
|
|
227
226
|
getRefClass: ()=>Class()
|
|
228
227
|
};
|
|
229
228
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
* into a lazily evaluated function.
|
|
233
|
-
*
|
|
234
|
-
* @__NO_SIDE_EFFECTS__
|
|
235
|
-
*/ function tokenRef(token) {
|
|
229
|
+
// @__NO_SIDE_EFFECTS__
|
|
230
|
+
function tokenRef(token) {
|
|
236
231
|
return {
|
|
232
|
+
getRefToken: ()=>{
|
|
233
|
+
const tokenOrTokens = token();
|
|
234
|
+
check(!Array.isArray(tokenOrTokens), "internal error: single token expected");
|
|
235
|
+
return tokenOrTokens;
|
|
236
|
+
},
|
|
237
237
|
getRefTokens: ()=>{
|
|
238
238
|
// Normalize the single token here so that we don't have to do it at every getRefTokens call site
|
|
239
239
|
const tokenOrTokens = token();
|
|
@@ -250,7 +250,7 @@ function isClassRef(value) {
|
|
|
250
250
|
}
|
|
251
251
|
// @internal
|
|
252
252
|
function isTokenRef(value) {
|
|
253
|
-
return value != null && typeof value === "object" && typeof value.
|
|
253
|
+
return value != null && typeof value === "object" && typeof value.getRefToken === "function";
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
// @internal
|
|
@@ -261,6 +261,10 @@ class Metadata {
|
|
|
261
261
|
methods: new Map()
|
|
262
262
|
};
|
|
263
263
|
this.tokenRef = {
|
|
264
|
+
// prettier-ignore
|
|
265
|
+
getRefToken: ()=>{
|
|
266
|
+
check(false, "internal error: unexpected call");
|
|
267
|
+
},
|
|
264
268
|
getRefTokens: ()=>new Set()
|
|
265
269
|
};
|
|
266
270
|
this.provider = {
|
|
@@ -1055,7 +1059,7 @@ function isDisposable(value) {
|
|
|
1055
1059
|
}
|
|
1056
1060
|
// Call context: decorator-based injection
|
|
1057
1061
|
resolveDependency(dependency, instance) {
|
|
1058
|
-
const
|
|
1062
|
+
const token = dependency.tokenRef.getRefToken();
|
|
1059
1063
|
check(token, `token passed to @${dependency.appliedBy} was undefined (possible circular imports)`);
|
|
1060
1064
|
const name = dependency.name;
|
|
1061
1065
|
switch(dependency.appliedBy){
|
|
@@ -1163,10 +1167,11 @@ function Injectable(...args) {
|
|
|
1163
1167
|
const metadata = getMetadata(Class);
|
|
1164
1168
|
const arg0 = args[0];
|
|
1165
1169
|
const ref = isTokenRef(arg0) ? arg0 : tokenRef(()=>args);
|
|
1166
|
-
const
|
|
1170
|
+
const currentRef = metadata.tokenRef;
|
|
1167
1171
|
metadata.tokenRef = {
|
|
1172
|
+
getRefToken: ()=>currentRef.getRefToken(),
|
|
1168
1173
|
getRefTokens: ()=>{
|
|
1169
|
-
const existingTokens =
|
|
1174
|
+
const existingTokens = currentRef.getRefTokens();
|
|
1170
1175
|
for (const token of ref.getRefTokens()){
|
|
1171
1176
|
existingTokens.add(token);
|
|
1172
1177
|
}
|