@loopback/context 1.23.4 → 1.25.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/CHANGELOG.md +41 -0
- package/dist/binding-config.js +1 -1
- package/dist/binding-config.js.map +1 -1
- package/dist/binding-inspector.js +12 -11
- package/dist/binding-inspector.js.map +1 -1
- package/dist/binding-sorter.js +2 -2
- package/dist/binding-sorter.js.map +1 -1
- package/dist/binding.d.ts +13 -7
- package/dist/binding.js +26 -9
- package/dist/binding.js.map +1 -1
- package/dist/context-view.d.ts +1 -1
- package/dist/context-view.js +5 -2
- package/dist/context-view.js.map +1 -1
- package/dist/context.d.ts +6 -1
- package/dist/context.js +33 -10
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/inject-config.js +3 -3
- package/dist/inject-config.js.map +1 -1
- package/dist/inject.d.ts +1 -1
- package/dist/inject.js +18 -11
- package/dist/inject.js.map +1 -1
- package/dist/interception-proxy.d.ts +15 -3
- package/dist/interception-proxy.js +20 -4
- package/dist/interception-proxy.js.map +1 -1
- package/dist/interceptor-chain.js +5 -2
- package/dist/interceptor-chain.js.map +1 -1
- package/dist/interceptor.d.ts +6 -0
- package/dist/interceptor.js +37 -11
- package/dist/interceptor.js.map +1 -1
- package/dist/invocation.d.ts +23 -4
- package/dist/invocation.js +14 -8
- package/dist/invocation.js.map +1 -1
- package/dist/keys.d.ts +6 -0
- package/dist/keys.js +6 -0
- package/dist/keys.js.map +1 -1
- package/dist/resolution-session.d.ts +5 -4
- package/dist/resolution-session.js +13 -6
- package/dist/resolution-session.js.map +1 -1
- package/dist/resolver.js +13 -8
- package/dist/resolver.js.map +1 -1
- package/package.json +10 -10
- package/src/binding-config.ts +1 -1
- package/src/binding-inspector.ts +6 -8
- package/src/binding-sorter.ts +2 -2
- package/src/binding.ts +30 -8
- package/src/context-view.ts +1 -1
- package/src/context.ts +26 -10
- package/src/index.ts +3 -3
- package/src/inject-config.ts +3 -3
- package/src/inject.ts +19 -10
- package/src/interception-proxy.ts +25 -3
- package/src/interceptor-chain.ts +1 -1
- package/src/interceptor.ts +31 -6
- package/src/invocation.ts +25 -4
- package/src/keys.ts +7 -0
- package/src/resolution-session.ts +9 -5
- package/src/resolver.ts +5 -5
package/dist/invocation.js
CHANGED
|
@@ -3,15 +3,18 @@
|
|
|
3
3
|
// Node module: @loopback/context
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
const metadata_1 = require("@loopback/metadata");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
11
|
+
const assert_1 = __importDefault(require("assert"));
|
|
12
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
13
|
const context_1 = require("./context");
|
|
11
14
|
const interceptor_1 = require("./interceptor");
|
|
12
15
|
const resolver_1 = require("./resolver");
|
|
13
16
|
const value_promise_1 = require("./value-promise");
|
|
14
|
-
const debug =
|
|
17
|
+
const debug = debug_1.default('loopback:context:invocation');
|
|
15
18
|
const getTargetName = metadata_1.DecoratorFactory.getTargetName;
|
|
16
19
|
/**
|
|
17
20
|
* InvocationContext represents the context to invoke interceptors for a method.
|
|
@@ -30,12 +33,13 @@ class InvocationContext extends context_1.Context {
|
|
|
30
33
|
constructor(
|
|
31
34
|
// Make `parent` public so that the interceptor can add bindings to
|
|
32
35
|
// the request context, for example, tracing id
|
|
33
|
-
parent, target, methodName, args) {
|
|
36
|
+
parent, target, methodName, args, source) {
|
|
34
37
|
super(parent);
|
|
35
38
|
this.parent = parent;
|
|
36
39
|
this.target = target;
|
|
37
40
|
this.methodName = methodName;
|
|
38
41
|
this.args = args;
|
|
42
|
+
this.source = source;
|
|
39
43
|
}
|
|
40
44
|
/**
|
|
41
45
|
* The target class, such as `OrderController`
|
|
@@ -55,7 +59,8 @@ class InvocationContext extends context_1.Context {
|
|
|
55
59
|
* Description of the invocation
|
|
56
60
|
*/
|
|
57
61
|
get description() {
|
|
58
|
-
|
|
62
|
+
const source = this.source == null ? '' : `${this.source} => `;
|
|
63
|
+
return `InvocationContext(${this.name}): ${source}${this.targetName}`;
|
|
59
64
|
}
|
|
60
65
|
toString() {
|
|
61
66
|
return this.description;
|
|
@@ -68,7 +73,7 @@ class InvocationContext extends context_1.Context {
|
|
|
68
73
|
const targetWithMethods = this.target;
|
|
69
74
|
if (typeof targetWithMethods[this.methodName] !== 'function') {
|
|
70
75
|
const targetName = getTargetName(this.target, this.methodName);
|
|
71
|
-
|
|
76
|
+
assert_1.default(false, `Method ${targetName} not found`);
|
|
72
77
|
}
|
|
73
78
|
return targetWithMethods;
|
|
74
79
|
}
|
|
@@ -119,17 +124,18 @@ exports.invokeMethod = invokeMethod;
|
|
|
119
124
|
* @param nonInjectedArgs - Optional array of args for non-injected parameters
|
|
120
125
|
*/
|
|
121
126
|
function invokeTargetMethodWithInjection(ctx, target, method, nonInjectedArgs) {
|
|
127
|
+
var _a;
|
|
122
128
|
const methodName = getTargetName(target, method);
|
|
123
129
|
/* istanbul ignore if */
|
|
124
130
|
if (debug.enabled) {
|
|
125
131
|
debug('Invoking method %s', methodName);
|
|
126
|
-
if (nonInjectedArgs
|
|
132
|
+
if ((_a = nonInjectedArgs) === null || _a === void 0 ? void 0 : _a.length) {
|
|
127
133
|
debug('Non-injected arguments:', nonInjectedArgs);
|
|
128
134
|
}
|
|
129
135
|
}
|
|
130
136
|
const argsOrPromise = resolver_1.resolveInjectedArguments(target, method, ctx, undefined, nonInjectedArgs);
|
|
131
137
|
const targetWithMethods = target;
|
|
132
|
-
|
|
138
|
+
assert_1.default(typeof targetWithMethods[method] === 'function', `Method ${method} not found`);
|
|
133
139
|
return value_promise_1.transformValueOrPromise(argsOrPromise, args => {
|
|
134
140
|
/* istanbul ignore if */
|
|
135
141
|
if (debug.enabled) {
|
package/dist/invocation.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invocation.js","sourceRoot":"","sources":["../src/invocation.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"invocation.js","sourceRoot":"","sources":["../src/invocation.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,iDAAoD;AACpD,oDAA4B;AAC5B,kDAAiC;AACjC,uCAAkC;AAClC,+CAA2D;AAC3D,yCAAoD;AACpD,mDAAwE;AAExE,MAAM,KAAK,GAAG,eAAY,CAAC,6BAA6B,CAAC,CAAC;AAC1D,MAAM,aAAa,GAAG,2BAAgB,CAAC,aAAa,CAAC;AA4BrD;;;;GAIG;AACH,MAAa,iBAAkB,SAAQ,iBAAO;IAC5C;;;;;;;OAOG;IACH;IACE,mEAAmE;IACnE,+CAA+C;IAC/B,MAAe,EACf,MAAc,EACd,UAAkB,EAClB,IAAoB,EACpB,MAAyB;QAEzC,KAAK,CAAC,MAAM,CAAC,CAAC;QANE,WAAM,GAAN,MAAM,CAAS;QACf,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,SAAI,GAAJ,IAAI,CAAgB;QACpB,WAAM,GAAN,MAAM,CAAmB;IAG3C,CAAC;IAED;;OAEG;IACH,IAAI,WAAW;QACb,OAAO,OAAO,IAAI,CAAC,MAAM,KAAK,UAAU;YACtC,CAAC,CAAC,IAAI,CAAC,MAAM;YACb,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACZ,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAA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EAAE,IAAI,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,GAAY,EAAE,WAAW;AACzB,MAAc,EACd,UAAkB,EAClB,IAAoB;IAEpB,MAAM,iBAAiB,GAAG,MAAkC,CAAC;IAC7D,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAAK,CAAC,oBAAoB,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,IAAI,CAAC,CAAC;KACtE;IACD,2BAA2B;IAC3B,MAAM,MAAM,GAAG,iBAAiB,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IACtD,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAAK,CAAC,oBAAoB,EAAE,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;KACxE;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/keys.d.ts
CHANGED
|
@@ -30,6 +30,12 @@ export declare namespace ContextTags {
|
|
|
30
30
|
* Binding tag for global interceptors
|
|
31
31
|
*/
|
|
32
32
|
const GLOBAL_INTERCEPTOR = "globalInterceptor";
|
|
33
|
+
/**
|
|
34
|
+
* Binding tag for global interceptors to specify sources of invocations that
|
|
35
|
+
* the interceptor should apply. The tag value can be a string or string[], such
|
|
36
|
+
* as `'route'` or `['route', 'proxy']`.
|
|
37
|
+
*/
|
|
38
|
+
const GLOBAL_INTERCEPTOR_SOURCE = "globalInterceptorSource";
|
|
33
39
|
/**
|
|
34
40
|
* Binding tag for group name of global interceptors
|
|
35
41
|
*/
|
package/dist/keys.js
CHANGED
|
@@ -36,6 +36,12 @@ var ContextTags;
|
|
|
36
36
|
* Binding tag for global interceptors
|
|
37
37
|
*/
|
|
38
38
|
ContextTags.GLOBAL_INTERCEPTOR = 'globalInterceptor';
|
|
39
|
+
/**
|
|
40
|
+
* Binding tag for global interceptors to specify sources of invocations that
|
|
41
|
+
* the interceptor should apply. The tag value can be a string or string[], such
|
|
42
|
+
* as `'route'` or `['route', 'proxy']`.
|
|
43
|
+
*/
|
|
44
|
+
ContextTags.GLOBAL_INTERCEPTOR_SOURCE = 'globalInterceptorSource';
|
|
39
45
|
/**
|
|
40
46
|
* Binding tag for group name of global interceptors
|
|
41
47
|
*/
|
package/dist/keys.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAGhE,+CAAyC;AAEzC;;GAEG;AACH,IAAiB,WAAW,
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAGhE,+CAAyC;AAEzC;;GAEG;AACH,IAAiB,WAAW,CA0C3B;AA1CD,WAAiB,WAAW;IACb,iBAAK,GAAG,OAAO,CAAC;IAChB,oBAAQ,GAAG,UAAU,CAAC;IAEnC;;OAEG;IACU,gBAAI,GAAG,MAAM,CAAC;IAC3B;;OAEG;IACU,qBAAS,GAAG,WAAW,CAAC;IACrC;;OAEG;IACU,gBAAI,GAAG,MAAM,CAAC;IAC3B;;OAEG;IACU,eAAG,GAAG,KAAK,CAAC;IAEzB;;OAEG;IACU,6BAAiB,GAAG,kBAAkB,CAAC;IAEpD;;OAEG;IACU,8BAAkB,GAAG,mBAAmB,CAAC;IAEtD;;;;OAIG;IACU,qCAAyB,GAAG,yBAAyB,CAAC;IAEnE;;OAEG;IACU,oCAAwB,GAAG,wBAAwB,CAAC;AACnE,CAAC,EA1CgB,WAAW,GAAX,mBAAW,KAAX,mBAAW,QA0C3B;AAED;;GAEG;AACU,QAAA,4BAA4B,GAAG,oBAAoB,CAAC;AAEjE;;GAEG;AACH,IAAiB,eAAe,CAc/B;AAdD,WAAiB,eAAe;IAC9B;;OAEG;IACU,sCAAsB,GAAG,wBAAU,CAAC,MAAM,CAErD,GAAG,wBAAU,CAAC,gBAAgB,WAAW,CAAC,CAAC;IAE7C;;OAEG;IACU,iDAAiC,GAAG,wBAAU,CAAC,MAAM,CAChE,iCAAiC,CAClC,CAAC;AACJ,CAAC,EAdgB,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAc/B"}
|
|
@@ -91,11 +91,11 @@ export declare class ResolutionSession {
|
|
|
91
91
|
/**
|
|
92
92
|
* Getter for the current injection
|
|
93
93
|
*/
|
|
94
|
-
|
|
94
|
+
get currentInjection(): Readonly<Injection> | undefined;
|
|
95
95
|
/**
|
|
96
96
|
* Getter for the current binding
|
|
97
97
|
*/
|
|
98
|
-
|
|
98
|
+
get currentBinding(): Readonly<Binding> | undefined;
|
|
99
99
|
/**
|
|
100
100
|
* Enter the resolution of the given binding. If
|
|
101
101
|
* @param binding - Binding
|
|
@@ -108,11 +108,11 @@ export declare class ResolutionSession {
|
|
|
108
108
|
/**
|
|
109
109
|
* Getter for bindings on the stack
|
|
110
110
|
*/
|
|
111
|
-
|
|
111
|
+
get bindingStack(): Readonly<Binding>[];
|
|
112
112
|
/**
|
|
113
113
|
* Getter for injections on the stack
|
|
114
114
|
*/
|
|
115
|
-
|
|
115
|
+
get injectionStack(): Readonly<Injection>[];
|
|
116
116
|
/**
|
|
117
117
|
* Get the binding path as `bindingA --> bindingB --> bindingC`.
|
|
118
118
|
*/
|
|
@@ -128,6 +128,7 @@ export declare class ResolutionSession {
|
|
|
128
128
|
* --> bindingC`.
|
|
129
129
|
*/
|
|
130
130
|
getResolutionPath(): string;
|
|
131
|
+
toString(): string;
|
|
131
132
|
}
|
|
132
133
|
/**
|
|
133
134
|
* Options for binding/dependency resolution
|
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
// Node module: @loopback/context
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
const metadata_1 = require("@loopback/metadata");
|
|
8
|
-
const
|
|
11
|
+
const debug_1 = __importDefault(require("debug"));
|
|
9
12
|
const value_promise_1 = require("./value-promise");
|
|
10
|
-
const debugSession =
|
|
13
|
+
const debugSession = debug_1.default('loopback:context:resolver:session');
|
|
11
14
|
const getTargetName = metadata_1.DecoratorFactory.getTargetName;
|
|
12
15
|
/**
|
|
13
16
|
* Type guard for binding elements
|
|
@@ -54,7 +57,7 @@ class ResolutionSession {
|
|
|
54
57
|
* @param session - The current resolution session
|
|
55
58
|
*/
|
|
56
59
|
static enterBinding(binding, session) {
|
|
57
|
-
session = session
|
|
60
|
+
session = (session !== null && session !== void 0 ? session : new ResolutionSession());
|
|
58
61
|
session.pushBinding(binding);
|
|
59
62
|
return session;
|
|
60
63
|
}
|
|
@@ -74,7 +77,7 @@ class ResolutionSession {
|
|
|
74
77
|
* @param session - The current resolution session
|
|
75
78
|
*/
|
|
76
79
|
static enterInjection(injection, session) {
|
|
77
|
-
session = session
|
|
80
|
+
session = (session !== null && session !== void 0 ? session : new ResolutionSession());
|
|
78
81
|
session.pushInjection(injection);
|
|
79
82
|
return session;
|
|
80
83
|
}
|
|
@@ -182,6 +185,7 @@ class ResolutionSession {
|
|
|
182
185
|
* Exit the resolution of a binding
|
|
183
186
|
*/
|
|
184
187
|
popBinding() {
|
|
188
|
+
var _a;
|
|
185
189
|
const top = this.stack.pop();
|
|
186
190
|
if (!isBinding(top)) {
|
|
187
191
|
throw new Error('The top element must be a binding');
|
|
@@ -189,7 +193,7 @@ class ResolutionSession {
|
|
|
189
193
|
const binding = top.value;
|
|
190
194
|
/* istanbul ignore if */
|
|
191
195
|
if (debugSession.enabled) {
|
|
192
|
-
debugSession('Exit binding:', binding
|
|
196
|
+
debugSession('Exit binding:', (_a = binding) === null || _a === void 0 ? void 0 : _a.toJSON());
|
|
193
197
|
debugSession('Resolution path:', this.getResolutionPath() || '<empty>');
|
|
194
198
|
}
|
|
195
199
|
return binding;
|
|
@@ -236,6 +240,9 @@ class ResolutionSession {
|
|
|
236
240
|
getResolutionPath() {
|
|
237
241
|
return this.stack.map(i => ResolutionSession.describe(i)).join(' --> ');
|
|
238
242
|
}
|
|
243
|
+
toString() {
|
|
244
|
+
return this.getResolutionPath();
|
|
245
|
+
}
|
|
239
246
|
}
|
|
240
247
|
exports.ResolutionSession = ResolutionSession;
|
|
241
248
|
/**
|
|
@@ -247,7 +254,7 @@ function asResolutionOptions(optionsOrSession) {
|
|
|
247
254
|
if (optionsOrSession instanceof ResolutionSession) {
|
|
248
255
|
return { session: optionsOrSession };
|
|
249
256
|
}
|
|
250
|
-
return optionsOrSession
|
|
257
|
+
return (optionsOrSession !== null && optionsOrSession !== void 0 ? optionsOrSession : {});
|
|
251
258
|
}
|
|
252
259
|
exports.asResolutionOptions = asResolutionOptions;
|
|
253
260
|
//# sourceMappingURL=resolution-session.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolution-session.js","sourceRoot":"","sources":["../src/resolution-session.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"resolution-session.js","sourceRoot":"","sources":["../src/resolution-session.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,iDAAoD;AACpD,kDAAgC;AAGhC,mDAA2E;AAE3E,MAAM,YAAY,GAAG,eAAW,CAAC,mCAAmC,CAAC,CAAC;AACtE,MAAM,aAAa,GAAG,2BAAgB,CAAC,aAAa,CAAC;AA8BrD;;;GAGG;AACH,SAAS,SAAS,CAChB,OAAsC;I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qQC;AA+BD;;;GAGG;AACH,SAAgB,mBAAmB,CACjC,gBAA6C;IAE7C,0BAA0B;IAC1B,IAAI,gBAAgB,YAAY,iBAAiB,EAAE;QACjD,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAC,CAAC;KACpC;IACD,QAAO,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,EAAE,EAAC;AAChC,CAAC;AARD,kDAQC"}
|
package/dist/resolver.js
CHANGED
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
// Node module: @loopback/context
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
6
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
10
|
const metadata_1 = require("@loopback/metadata");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
11
|
+
const assert_1 = __importDefault(require("assert"));
|
|
12
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
13
|
const binding_1 = require("./binding");
|
|
11
14
|
const binding_filter_1 = require("./binding-filter");
|
|
12
15
|
const inject_1 = require("./inject");
|
|
13
16
|
const resolution_session_1 = require("./resolution-session");
|
|
14
17
|
const value_promise_1 = require("./value-promise");
|
|
15
|
-
const debug =
|
|
18
|
+
const debug = debug_1.default('loopback:context:resolver');
|
|
16
19
|
const getTargetName = metadata_1.DecoratorFactory.getTargetName;
|
|
17
20
|
/**
|
|
18
21
|
* Create an instance of a class which constructor has arguments
|
|
@@ -29,10 +32,11 @@ const getTargetName = metadata_1.DecoratorFactory.getTargetName;
|
|
|
29
32
|
function instantiateClass(ctor, ctx, session,
|
|
30
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
34
|
nonInjectedArgs) {
|
|
35
|
+
var _a;
|
|
32
36
|
/* istanbul ignore if */
|
|
33
37
|
if (debug.enabled) {
|
|
34
38
|
debug('Instantiating %s', getTargetName(ctor));
|
|
35
|
-
if (nonInjectedArgs
|
|
39
|
+
if ((_a = nonInjectedArgs) === null || _a === void 0 ? void 0 : _a.length) {
|
|
36
40
|
debug('Non-injected arguments:', nonInjectedArgs);
|
|
37
41
|
}
|
|
38
42
|
}
|
|
@@ -61,7 +65,8 @@ exports.instantiateClass = instantiateClass;
|
|
|
61
65
|
* injection is for method (excluding constructor) parameters.
|
|
62
66
|
*/
|
|
63
67
|
function resolveContext(ctx, injection, session) {
|
|
64
|
-
|
|
68
|
+
var _a;
|
|
69
|
+
const currentBinding = (_a = session) === null || _a === void 0 ? void 0 : _a.currentBinding;
|
|
65
70
|
if (currentBinding == null ||
|
|
66
71
|
currentBinding.scope !== binding_1.BindingScope.SINGLETON) {
|
|
67
72
|
// No current binding or its scope is not `SINGLETON`
|
|
@@ -98,7 +103,7 @@ function resolve(ctx, injection, session) {
|
|
|
98
103
|
}
|
|
99
104
|
else {
|
|
100
105
|
// Default to resolve the value from the context by binding key
|
|
101
|
-
|
|
106
|
+
assert_1.default(binding_filter_1.isBindingAddress(injection.bindingSelector), 'The binding selector must be an address (string or BindingKey)');
|
|
102
107
|
const key = injection.bindingSelector;
|
|
103
108
|
const options = Object.assign({ session: s }, injection.metadata);
|
|
104
109
|
return ctx.getValueOrPromise(key, options);
|
|
@@ -131,14 +136,14 @@ nonInjectedArgs) {
|
|
|
131
136
|
}
|
|
132
137
|
const targetWithMethods = target;
|
|
133
138
|
if (method) {
|
|
134
|
-
|
|
139
|
+
assert_1.default(typeof targetWithMethods[method] === 'function', `Method ${method} not found`);
|
|
135
140
|
}
|
|
136
141
|
// NOTE: the array may be sparse, i.e.
|
|
137
142
|
// Object.keys(injectedArgs).length !== injectedArgs.length
|
|
138
143
|
// Example value:
|
|
139
144
|
// [ , 'key1', , 'key2']
|
|
140
145
|
const injectedArgs = inject_1.describeInjectedArguments(target, method);
|
|
141
|
-
const extraArgs = nonInjectedArgs
|
|
146
|
+
const extraArgs = (nonInjectedArgs !== null && nonInjectedArgs !== void 0 ? nonInjectedArgs : []);
|
|
142
147
|
let argLength = metadata_1.DecoratorFactory.getNumberOfParameters(target, method);
|
|
143
148
|
// Please note `injectedArgs` contains `undefined` for non-injected args
|
|
144
149
|
const numberOfInjected = injectedArgs.filter(i => i != null).length;
|
package/dist/resolver.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"resolver.js","sourceRoot":"","sources":["../src/resolver.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,iDAAoD;AACpD,oDAA4B;AAC5B,kDAAgC;AAChC,uCAAuC;AACvC,qDAAkD;AAGlD,qCAIkB;AAClB,6DAA0E;AAC1E,mDAQyB;AAEzB,MAAM,KAAK,GAAG,eAAW,CAAC,2BAA2B,CAAC,CAAC;AACvD,MAAM,aAAa,GAAG,2BAAgB,CAAC,aAAa,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB,CAC9B,IAAoB,EACpB,GAAY,EACZ,OAA2B;AAC3B,8DAA8D;AAC9D,eAAuB;;IAEvB,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAAK,CAAC,kBAAkB,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QAC/C,UAAI,eAAe,0CAAE,MAAM,EAAE;YAC3B,KAAK,CAAC,yBAAyB,EAAE,eAAe,CAAC,CAAC;SACnD;KACF;IACD,MAAM,aAAa,GAAG,wBAAwB,CAC5C,IAAI,EACJ,EAAE,EACF,GAAG,EACH,OAAO,EACP,eAAe,CAChB,CAAC;IACF,MAAM,mBAAmB,GAAG,yBAAyB,CAAC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,EAAE,EAAE,CAAC,CAAC;gBAC/C,MAAM,IAAI,KAAK,CACb,yCAAyC,IAAI,IAAI;oBAC/C,iBAAiB,EAAE,+CAA+C;oBAClE,6BAA6B,CAChC,CAAC;aACH;SACF;QAED,OAAO,OAAO,CACZ,GAAG,EACH,SAAS;QACT,2EAA2E;QAC3E,sCAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAChC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AApED,4DAoEC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,yBAAyB,CACvC,WAAqB,EACrB,GAAY,EACZ,OAA2B;IAE3B,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAAK,CAAC,sCAAsC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;KAC3E;IACD,MAAM,kBAAkB,GAAG,mCAA0B,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;IAE7E,OAAO,0BAAU,CAAC,kBAAkB,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE;QACrD,IAAI,CAAC,SAAS,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE;YACpD,MAAM,IAAI,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;YAC3C,MAAM,IAAI,KAAK,CACb,oCAAoC,IAAI,IAAI;gBAC1C,gBAAgB,CAAC,6CAA6C,CACjE,CAAC;SACH;QAED,OAAO,OAAO,CACZ,GAAG,EACH,SAAS;QACT,4EAA4E;QAC5E,sCAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,CAChC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA3BD,8DA2BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/context",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.1",
|
|
4
4
|
"description": "LoopBack's container for Inversion of Control",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.9"
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
"copyright.owner": "IBM Corp.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@loopback/metadata": "^1.3.
|
|
21
|
+
"@loopback/metadata": "^1.3.10",
|
|
22
22
|
"debug": "^4.1.1",
|
|
23
23
|
"p-event": "^4.1.0",
|
|
24
24
|
"uuid": "^3.3.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@loopback/build": "^
|
|
28
|
-
"@loopback/eslint-config": "^
|
|
29
|
-
"@loopback/testlab": "^1.
|
|
30
|
-
"@types/bluebird": "^3.5.
|
|
27
|
+
"@loopback/build": "^3.0.1",
|
|
28
|
+
"@loopback/eslint-config": "^5.0.1",
|
|
29
|
+
"@loopback/testlab": "^1.10.1",
|
|
30
|
+
"@types/bluebird": "^3.5.29",
|
|
31
31
|
"@types/debug": "^4.1.5",
|
|
32
|
-
"@types/node": "^10.17.
|
|
33
|
-
"@types/uuid": "^3.4.
|
|
34
|
-
"bluebird": "^3.7.
|
|
32
|
+
"@types/node": "^10.17.13",
|
|
33
|
+
"@types/uuid": "^3.4.6",
|
|
34
|
+
"bluebird": "^3.7.2"
|
|
35
35
|
},
|
|
36
36
|
"keywords": [
|
|
37
37
|
"LoopBack",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
56
56
|
"directory": "packages/context"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "598baf6e84de3917bb67aff47a1ab1cb1111e3d2"
|
|
59
59
|
}
|
package/src/binding-config.ts
CHANGED
|
@@ -46,7 +46,7 @@ export class DefaultConfigurationResolver implements ConfigurationResolver {
|
|
|
46
46
|
propertyPath?: string,
|
|
47
47
|
resolutionOptions?: ResolutionOptions,
|
|
48
48
|
): ValueOrPromise<ConfigValueType | undefined> {
|
|
49
|
-
propertyPath = propertyPath
|
|
49
|
+
propertyPath = propertyPath ?? '';
|
|
50
50
|
const configKey = configBindingKeyFor(key, propertyPath);
|
|
51
51
|
|
|
52
52
|
const options: ResolutionOptions = Object.assign(
|
package/src/binding-inspector.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
6
|
import {MetadataAccessor, MetadataInspector} from '@loopback/metadata';
|
|
7
|
-
import
|
|
7
|
+
import debugFactory from 'debug';
|
|
8
8
|
import {Binding, BindingScope, BindingTag, BindingTemplate} from './binding';
|
|
9
9
|
import {BindingAddress} from './binding-key';
|
|
10
10
|
import {ContextTags} from './keys';
|
|
@@ -145,9 +145,7 @@ export function bindingTemplateFor<T = unknown>(
|
|
|
145
145
|
): BindingTemplate<T> {
|
|
146
146
|
const spec = getBindingMetadata(cls);
|
|
147
147
|
debug('class %s has binding metadata', cls.name, spec);
|
|
148
|
-
const templateFunctions =
|
|
149
|
-
asClassOrProvider(cls),
|
|
150
|
-
];
|
|
148
|
+
const templateFunctions = spec?.templates ?? [asClassOrProvider(cls)];
|
|
151
149
|
return function applyBindingTemplatesFromMetadata(binding) {
|
|
152
150
|
for (const t of templateFunctions) {
|
|
153
151
|
binding.apply(t);
|
|
@@ -297,7 +295,7 @@ function buildBindingKey(
|
|
|
297
295
|
if (key) return key;
|
|
298
296
|
|
|
299
297
|
let namespace =
|
|
300
|
-
options.namespace
|
|
298
|
+
options.namespace ?? bindingTemplate.tagMap[ContextTags.NAMESPACE];
|
|
301
299
|
if (!namespace) {
|
|
302
300
|
const namespaces = Object.assign(
|
|
303
301
|
{},
|
|
@@ -305,17 +303,17 @@ function buildBindingKey(
|
|
|
305
303
|
options.typeNamespaceMapping,
|
|
306
304
|
);
|
|
307
305
|
// Derive the key from type + name
|
|
308
|
-
let type = options.type
|
|
306
|
+
let type = options.type ?? bindingTemplate.tagMap[ContextTags.TYPE];
|
|
309
307
|
if (!type) {
|
|
310
308
|
type =
|
|
311
|
-
bindingTemplate.tagNames.find(t => namespaces[t] != null)
|
|
309
|
+
bindingTemplate.tagNames.find(t => namespaces[t] != null) ??
|
|
312
310
|
ContextTags.CLASS;
|
|
313
311
|
}
|
|
314
312
|
namespace = getNamespace(type, namespaces);
|
|
315
313
|
}
|
|
316
314
|
|
|
317
315
|
const name =
|
|
318
|
-
options.name
|
|
316
|
+
options.name ?? (bindingTemplate.tagMap[ContextTags.NAME] || cls.name);
|
|
319
317
|
key = `${namespace}.${name}`;
|
|
320
318
|
|
|
321
319
|
return key;
|
package/src/binding-sorter.ts
CHANGED
|
@@ -85,8 +85,8 @@ export function compareByOrder(
|
|
|
85
85
|
b: string | symbol | undefined | null,
|
|
86
86
|
order: (string | symbol)[] = [],
|
|
87
87
|
) {
|
|
88
|
-
a = a
|
|
89
|
-
b = b
|
|
88
|
+
a = a ?? '';
|
|
89
|
+
b = b ?? '';
|
|
90
90
|
const i1 = order.indexOf(a);
|
|
91
91
|
const i2 = order.indexOf(b);
|
|
92
92
|
if (i1 !== -1 || i2 !== -1) {
|
package/src/binding.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import debugFactory from 'debug';
|
|
7
7
|
import {BindingAddress, BindingKey} from './binding-key';
|
|
8
8
|
import {Context} from './context';
|
|
9
9
|
import {createProxyWithInterceptors} from './interception-proxy';
|
|
@@ -165,7 +165,7 @@ export class Binding<T = BoundValue> {
|
|
|
165
165
|
*/
|
|
166
166
|
public get scope(): BindingScope {
|
|
167
167
|
// Default to TRANSIENT if not set
|
|
168
|
-
return this._scope
|
|
168
|
+
return this._scope ?? BindingScope.TRANSIENT;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
private _type?: BindingType;
|
|
@@ -180,14 +180,24 @@ export class Binding<T = BoundValue> {
|
|
|
180
180
|
private _getValue: ValueGetter<T>;
|
|
181
181
|
|
|
182
182
|
private _valueConstructor?: Constructor<T>;
|
|
183
|
+
private _providerConstructor?: Constructor<Provider<T>>;
|
|
184
|
+
|
|
183
185
|
/**
|
|
184
|
-
* For bindings bound via toClass
|
|
185
|
-
* function
|
|
186
|
+
* For bindings bound via `toClass()`, this property contains the constructor
|
|
187
|
+
* function of the class
|
|
186
188
|
*/
|
|
187
189
|
public get valueConstructor(): Constructor<T> | undefined {
|
|
188
190
|
return this._valueConstructor;
|
|
189
191
|
}
|
|
190
192
|
|
|
193
|
+
/**
|
|
194
|
+
* For bindings bound via `toProvider()`, this property contains the
|
|
195
|
+
* constructor function of the provider class
|
|
196
|
+
*/
|
|
197
|
+
public get providerConstructor(): Constructor<Provider<T>> | undefined {
|
|
198
|
+
return this._providerConstructor;
|
|
199
|
+
}
|
|
200
|
+
|
|
191
201
|
constructor(key: BindingAddress<T>, public isLocked: boolean = false) {
|
|
192
202
|
BindingKey.validate(key);
|
|
193
203
|
this.key = key.toString();
|
|
@@ -494,6 +504,7 @@ export class Binding<T = BoundValue> {
|
|
|
494
504
|
debug('Bind %s to provider %s', this.key, providerClass.name);
|
|
495
505
|
}
|
|
496
506
|
this._type = BindingType.PROVIDER;
|
|
507
|
+
this._providerConstructor = providerClass;
|
|
497
508
|
this._setValueGetter((ctx, options) => {
|
|
498
509
|
const providerOrPromise = instantiateClass<Provider<T>>(
|
|
499
510
|
providerClass,
|
|
@@ -521,7 +532,11 @@ export class Binding<T = BoundValue> {
|
|
|
521
532
|
this._setValueGetter((ctx, options) => {
|
|
522
533
|
const instOrPromise = instantiateClass(ctor, ctx, options.session);
|
|
523
534
|
if (!options.asProxyWithInterceptors) return instOrPromise;
|
|
524
|
-
return createInterceptionProxyFromInstance(
|
|
535
|
+
return createInterceptionProxyFromInstance(
|
|
536
|
+
instOrPromise,
|
|
537
|
+
ctx,
|
|
538
|
+
options.session,
|
|
539
|
+
);
|
|
525
540
|
});
|
|
526
541
|
this._valueConstructor = ctor;
|
|
527
542
|
return this;
|
|
@@ -576,9 +591,8 @@ export class Binding<T = BoundValue> {
|
|
|
576
591
|
/**
|
|
577
592
|
* Convert to a plain JSON object
|
|
578
593
|
*/
|
|
579
|
-
toJSON():
|
|
580
|
-
|
|
581
|
-
const json: {[name: string]: any} = {
|
|
594
|
+
toJSON(): object {
|
|
595
|
+
const json: Record<string, unknown> = {
|
|
582
596
|
key: this.key,
|
|
583
597
|
scope: this.scope,
|
|
584
598
|
tags: this.tagMap,
|
|
@@ -587,6 +601,12 @@ export class Binding<T = BoundValue> {
|
|
|
587
601
|
if (this.type != null) {
|
|
588
602
|
json.type = this.type;
|
|
589
603
|
}
|
|
604
|
+
if (this._valueConstructor != null) {
|
|
605
|
+
json.valueConstructor = this._valueConstructor.name;
|
|
606
|
+
}
|
|
607
|
+
if (this._providerConstructor != null) {
|
|
608
|
+
json.providerConstructor = this._providerConstructor.name;
|
|
609
|
+
}
|
|
590
610
|
return json;
|
|
591
611
|
}
|
|
592
612
|
|
|
@@ -624,6 +644,7 @@ export class Binding<T = BoundValue> {
|
|
|
624
644
|
function createInterceptionProxyFromInstance<T>(
|
|
625
645
|
instOrPromise: ValueOrPromise<T>,
|
|
626
646
|
context: Context,
|
|
647
|
+
session?: ResolutionSession,
|
|
627
648
|
) {
|
|
628
649
|
return transformValueOrPromise(instOrPromise, inst => {
|
|
629
650
|
if (typeof inst !== 'object') return inst;
|
|
@@ -631,6 +652,7 @@ function createInterceptionProxyFromInstance<T>(
|
|
|
631
652
|
// Cast inst from `T` to `object`
|
|
632
653
|
(inst as unknown) as object,
|
|
633
654
|
context,
|
|
655
|
+
session,
|
|
634
656
|
) as unknown) as T;
|
|
635
657
|
});
|
|
636
658
|
}
|
package/src/context-view.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// This file is licensed under the MIT License.
|
|
4
4
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
5
|
|
|
6
|
-
import
|
|
6
|
+
import debugFactory from 'debug';
|
|
7
7
|
import {EventEmitter} from 'events';
|
|
8
8
|
import {promisify} from 'util';
|
|
9
9
|
import {Binding} from './binding';
|