@loopback/context 4.0.0-alpha.8 → 4.1.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/LICENSE +25 -0
- package/README.md +116 -0
- package/dist/binding-config.d.ts +40 -0
- package/dist/binding-config.js +33 -0
- package/dist/binding-config.js.map +1 -0
- package/dist/binding-decorator.d.ts +45 -0
- package/dist/binding-decorator.js +118 -0
- package/dist/binding-decorator.js.map +1 -0
- package/dist/binding-filter.d.ts +108 -0
- package/dist/binding-filter.js +162 -0
- package/dist/binding-filter.js.map +1 -0
- package/dist/binding-inspector.d.ts +150 -0
- package/dist/binding-inspector.js +249 -0
- package/dist/binding-inspector.js.map +1 -0
- package/dist/binding-key.d.ts +66 -0
- package/dist/binding-key.js +121 -0
- package/dist/binding-key.js.map +1 -0
- package/dist/binding-sorter.d.ts +71 -0
- package/dist/binding-sorter.js +89 -0
- package/dist/binding-sorter.js.map +1 -0
- package/dist/binding.d.ts +577 -0
- package/dist/binding.js +788 -0
- package/dist/binding.js.map +1 -0
- package/dist/context-event.d.ts +23 -0
- package/dist/context-event.js +7 -0
- package/dist/context-event.js.map +1 -0
- package/dist/context-observer.d.ts +36 -0
- package/dist/context-observer.js +7 -0
- package/dist/context-observer.js.map +1 -0
- package/dist/context-subscription.d.ts +147 -0
- package/dist/context-subscription.js +317 -0
- package/dist/context-subscription.js.map +1 -0
- package/dist/context-tag-indexer.d.ts +42 -0
- package/dist/context-tag-indexer.js +135 -0
- package/dist/context-tag-indexer.js.map +1 -0
- package/dist/context-view.d.ts +209 -0
- package/dist/context-view.js +240 -0
- package/dist/context-view.js.map +1 -0
- package/dist/context.d.ts +513 -0
- package/dist/context.js +717 -0
- package/dist/context.js.map +1 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/inject-config.d.ts +67 -0
- package/dist/inject-config.js +181 -0
- package/dist/inject-config.js.map +1 -0
- package/dist/inject.d.ts +250 -0
- package/dist/inject.js +535 -0
- package/dist/inject.js.map +1 -0
- package/dist/interception-proxy.d.ts +76 -0
- package/dist/interception-proxy.js +67 -0
- package/dist/interception-proxy.js.map +1 -0
- package/dist/interceptor-chain.d.ts +121 -0
- package/dist/interceptor-chain.js +148 -0
- package/dist/interceptor-chain.js.map +1 -0
- package/dist/interceptor.d.ts +138 -0
- package/dist/interceptor.js +299 -0
- package/dist/interceptor.js.map +1 -0
- package/dist/invocation.d.ts +101 -0
- package/dist/invocation.js +163 -0
- package/dist/invocation.js.map +1 -0
- package/dist/json-types.d.ts +28 -0
- package/{lib/src/provider.js → dist/json-types.js} +3 -3
- package/dist/json-types.js.map +1 -0
- package/dist/keys.d.ts +65 -0
- package/dist/keys.js +74 -0
- package/dist/keys.js.map +1 -0
- package/dist/provider.d.ts +31 -0
- package/{lib6/src → dist}/provider.js +2 -2
- package/dist/provider.js.map +1 -0
- package/dist/resolution-session.d.ts +180 -0
- package/dist/resolution-session.js +274 -0
- package/dist/resolution-session.js.map +1 -0
- package/dist/resolver.d.ts +46 -0
- package/dist/resolver.js +203 -0
- package/dist/resolver.js.map +1 -0
- package/dist/unique-id.d.ts +14 -0
- package/dist/unique-id.js +26 -0
- package/dist/unique-id.js.map +1 -0
- package/dist/value-promise.d.ts +134 -0
- package/dist/value-promise.js +277 -0
- package/dist/value-promise.js.map +1 -0
- package/package.json +49 -34
- package/src/binding-config.ts +73 -0
- package/src/binding-decorator.ts +136 -0
- package/src/binding-filter.ts +250 -0
- package/src/binding-inspector.ts +371 -0
- package/src/binding-key.ts +136 -0
- package/src/binding-sorter.ts +124 -0
- package/src/binding.ts +1107 -0
- package/src/context-event.ts +30 -0
- package/src/context-observer.ts +50 -0
- package/src/context-subscription.ts +402 -0
- package/src/context-tag-indexer.ts +147 -0
- package/src/context-view.ts +440 -0
- package/src/context.ts +1079 -0
- package/src/index.ts +58 -0
- package/src/inject-config.ts +239 -0
- package/src/inject.ts +796 -0
- package/src/interception-proxy.ts +127 -0
- package/src/interceptor-chain.ts +268 -0
- package/src/interceptor.ts +430 -0
- package/src/invocation.ts +269 -0
- package/src/json-types.ts +35 -0
- package/src/keys.ts +85 -0
- package/src/provider.ts +37 -0
- package/src/resolution-session.ts +414 -0
- package/src/resolver.ts +282 -0
- package/src/unique-id.ts +24 -0
- package/src/value-promise.ts +318 -0
- package/index.d.ts +0 -6
- package/index.js +0 -9
- package/lib/binding.d.ts +0 -75
- package/lib/binding.js +0 -103
- package/lib/binding.js.map +0 -1
- package/lib/context.d.ts +0 -14
- package/lib/context.js +0 -97
- package/lib/context.js.map +0 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -12
- package/lib/index.js.map +0 -1
- package/lib/inject.d.ts +0 -46
- package/lib/inject.js +0 -74
- package/lib/inject.js.map +0 -1
- package/lib/isPromise.d.ts +0 -1
- package/lib/isPromise.js +0 -15
- package/lib/isPromise.js.map +0 -1
- package/lib/reflect.d.ts +0 -39
- package/lib/reflect.js +0 -20
- package/lib/reflect.js.map +0 -1
- package/lib/resolver.d.ts +0 -30
- package/lib/resolver.js +0 -129
- package/lib/resolver.js.map +0 -1
- package/lib/src/binding.d.ts +0 -85
- package/lib/src/binding.js +0 -123
- package/lib/src/binding.js.map +0 -1
- package/lib/src/context.d.ts +0 -14
- package/lib/src/context.js +0 -97
- package/lib/src/context.js.map +0 -1
- package/lib/src/index.d.ts +0 -10
- package/lib/src/index.js +0 -27
- package/lib/src/index.js.map +0 -1
- package/lib/src/inject.d.ts +0 -46
- package/lib/src/inject.js +0 -74
- package/lib/src/inject.js.map +0 -1
- package/lib/src/isPromise.d.ts +0 -1
- package/lib/src/isPromise.js +0 -15
- package/lib/src/isPromise.js.map +0 -1
- package/lib/src/provider.d.ts +0 -29
- package/lib/src/provider.js.map +0 -1
- package/lib/src/reflect.d.ts +0 -38
- package/lib/src/reflect.js +0 -143
- package/lib/src/reflect.js.map +0 -1
- package/lib/src/resolver.d.ts +0 -34
- package/lib/src/resolver.js +0 -144
- package/lib/src/resolver.js.map +0 -1
- package/lib6/binding.d.ts +0 -75
- package/lib6/binding.js +0 -103
- package/lib6/binding.js.map +0 -1
- package/lib6/context.d.ts +0 -14
- package/lib6/context.js +0 -97
- package/lib6/context.js.map +0 -1
- package/lib6/index.d.ts +0 -1
- package/lib6/index.js +0 -12
- package/lib6/index.js.map +0 -1
- package/lib6/inject.d.ts +0 -46
- package/lib6/inject.js +0 -74
- package/lib6/inject.js.map +0 -1
- package/lib6/isPromise.d.ts +0 -1
- package/lib6/isPromise.js +0 -15
- package/lib6/isPromise.js.map +0 -1
- package/lib6/reflect.d.ts +0 -39
- package/lib6/reflect.js +0 -20
- package/lib6/reflect.js.map +0 -1
- package/lib6/resolver.d.ts +0 -30
- package/lib6/resolver.js +0 -129
- package/lib6/resolver.js.map +0 -1
- package/lib6/src/binding.d.ts +0 -85
- package/lib6/src/binding.js +0 -133
- package/lib6/src/binding.js.map +0 -1
- package/lib6/src/context.d.ts +0 -14
- package/lib6/src/context.js +0 -97
- package/lib6/src/context.js.map +0 -1
- package/lib6/src/index.d.ts +0 -10
- package/lib6/src/index.js +0 -27
- package/lib6/src/index.js.map +0 -1
- package/lib6/src/inject.d.ts +0 -46
- package/lib6/src/inject.js +0 -74
- package/lib6/src/inject.js.map +0 -1
- package/lib6/src/isPromise.d.ts +0 -1
- package/lib6/src/isPromise.js +0 -15
- package/lib6/src/isPromise.js.map +0 -1
- package/lib6/src/provider.d.ts +0 -29
- package/lib6/src/provider.js.map +0 -1
- package/lib6/src/reflect.d.ts +0 -38
- package/lib6/src/reflect.js +0 -143
- package/lib6/src/reflect.js.map +0 -1
- package/lib6/src/resolver.d.ts +0 -34
- package/lib6/src/resolver.js +0 -154
- package/lib6/src/resolver.js.map +0 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/context
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.UUID_PATTERN = exports.uuid = exports.transformValueOrPromise = exports.resolveUntil = exports.tryCatchFinally = exports.tryWithFinally = exports.resolveList = exports.resolveMap = exports.getDeepProperty = exports.isPromiseLike = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* This module contains types for values and/or promises as well as a set of
|
|
10
|
+
* utility methods to handle values and/or promises.
|
|
11
|
+
*/
|
|
12
|
+
const uuid_1 = require("uuid");
|
|
13
|
+
/**
|
|
14
|
+
* Check whether a value is a Promise-like instance.
|
|
15
|
+
* Recognizes both native promises and third-party promise libraries.
|
|
16
|
+
*
|
|
17
|
+
* @param value - The value to check.
|
|
18
|
+
*/
|
|
19
|
+
function isPromiseLike(value) {
|
|
20
|
+
if (!value)
|
|
21
|
+
return false;
|
|
22
|
+
if (typeof value !== 'object' && typeof value !== 'function')
|
|
23
|
+
return false;
|
|
24
|
+
return typeof value.then === 'function';
|
|
25
|
+
}
|
|
26
|
+
exports.isPromiseLike = isPromiseLike;
|
|
27
|
+
/**
|
|
28
|
+
* Get nested properties of an object by path
|
|
29
|
+
* @param value - Value of the source object
|
|
30
|
+
* @param path - Path to the property
|
|
31
|
+
*/
|
|
32
|
+
function getDeepProperty(value, path) {
|
|
33
|
+
let result = value;
|
|
34
|
+
const props = path.split('.').filter(Boolean);
|
|
35
|
+
for (const p of props) {
|
|
36
|
+
if (result == null) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
result = result[p];
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
exports.getDeepProperty = getDeepProperty;
|
|
44
|
+
/**
|
|
45
|
+
* Resolve entries of an object into a new object with the same keys. If one or
|
|
46
|
+
* more entries of the source object are resolved to a promise by the `resolver`
|
|
47
|
+
* function, this method returns a promise which will be resolved to the new
|
|
48
|
+
* object with fully resolved entries.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
*
|
|
52
|
+
* - Example 1: resolve all entries synchronously
|
|
53
|
+
* ```ts
|
|
54
|
+
* const result = resolveMap({a: 'x', b: 'y'}, v => v.toUpperCase());
|
|
55
|
+
* ```
|
|
56
|
+
* The `result` will be `{a: 'X', b: 'Y'}`.
|
|
57
|
+
*
|
|
58
|
+
* - Example 2: resolve one or more entries asynchronously
|
|
59
|
+
* ```ts
|
|
60
|
+
* const result = resolveMap({a: 'x', b: 'y'}, v =>
|
|
61
|
+
* Promise.resolve(v.toUpperCase()),
|
|
62
|
+
* );
|
|
63
|
+
* ```
|
|
64
|
+
* The `result` will be a promise of `{a: 'X', b: 'Y'}`.
|
|
65
|
+
*
|
|
66
|
+
* @param map - The original object containing the source entries
|
|
67
|
+
* @param resolver - A function resolves an entry to a value or promise. It will
|
|
68
|
+
* be invoked with the property value, the property name, and the source object.
|
|
69
|
+
*/
|
|
70
|
+
function resolveMap(map, resolver) {
|
|
71
|
+
const result = {};
|
|
72
|
+
let asyncResolvers = undefined;
|
|
73
|
+
const setter = (key) => (val) => {
|
|
74
|
+
if (val !== undefined) {
|
|
75
|
+
// Only set the value if it's not undefined so that the default value
|
|
76
|
+
// for a key will be honored
|
|
77
|
+
result[key] = val;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
for (const key in map) {
|
|
81
|
+
const valueOrPromise = resolver(map[key], key, map);
|
|
82
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
83
|
+
if (!asyncResolvers)
|
|
84
|
+
asyncResolvers = [];
|
|
85
|
+
asyncResolvers.push(valueOrPromise.then(setter(key)));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
if (valueOrPromise !== undefined) {
|
|
89
|
+
// Only set the value if it's not undefined so that the default value
|
|
90
|
+
// for a key will be honored
|
|
91
|
+
result[key] = valueOrPromise;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (asyncResolvers) {
|
|
96
|
+
return Promise.all(asyncResolvers).then(() => result);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.resolveMap = resolveMap;
|
|
103
|
+
/**
|
|
104
|
+
* Resolve entries of an array into a new array with the same indexes. If one or
|
|
105
|
+
* more entries of the source array are resolved to a promise by the `resolver`
|
|
106
|
+
* function, this method returns a promise which will be resolved to the new
|
|
107
|
+
* array with fully resolved entries.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
*
|
|
111
|
+
* - Example 1: resolve all entries synchronously
|
|
112
|
+
* ```ts
|
|
113
|
+
* const result = resolveList(['a', 'b'], v => v.toUpperCase());
|
|
114
|
+
* ```
|
|
115
|
+
* The `result` will be `['A', 'B']`.
|
|
116
|
+
*
|
|
117
|
+
* - Example 2: resolve one or more entries asynchronously
|
|
118
|
+
* ```ts
|
|
119
|
+
* const result = resolveList(['a', 'b'], v =>
|
|
120
|
+
* Promise.resolve(v.toUpperCase()),
|
|
121
|
+
* );
|
|
122
|
+
* ```
|
|
123
|
+
* The `result` will be a promise of `['A', 'B']`.
|
|
124
|
+
*
|
|
125
|
+
* @param list - The original array containing the source entries
|
|
126
|
+
* @param resolver - A function resolves an entry to a value or promise. It will
|
|
127
|
+
* be invoked with the property value, the property index, and the source array.
|
|
128
|
+
*/
|
|
129
|
+
function resolveList(list, resolver) {
|
|
130
|
+
const result = new Array(list.length);
|
|
131
|
+
let asyncResolvers = undefined;
|
|
132
|
+
const setter = (index) => (val) => {
|
|
133
|
+
result[index] = val;
|
|
134
|
+
};
|
|
135
|
+
for (let ix = 0; ix < list.length; ix++) {
|
|
136
|
+
const valueOrPromise = resolver(list[ix], ix, list);
|
|
137
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
138
|
+
if (!asyncResolvers)
|
|
139
|
+
asyncResolvers = [];
|
|
140
|
+
asyncResolvers.push(valueOrPromise.then(setter(ix)));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
result[ix] = valueOrPromise;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (asyncResolvers) {
|
|
147
|
+
return Promise.all(asyncResolvers).then(() => result);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.resolveList = resolveList;
|
|
154
|
+
/**
|
|
155
|
+
* Try to run an action that returns a promise or a value
|
|
156
|
+
* @param action - A function that returns a promise or a value
|
|
157
|
+
* @param finalAction - A function to be called once the action
|
|
158
|
+
* is fulfilled or rejected (synchronously or asynchronously)
|
|
159
|
+
*
|
|
160
|
+
* @typeParam T - Type for the return value
|
|
161
|
+
*/
|
|
162
|
+
function tryWithFinally(action, finalAction) {
|
|
163
|
+
return tryCatchFinally(action, undefined, finalAction);
|
|
164
|
+
}
|
|
165
|
+
exports.tryWithFinally = tryWithFinally;
|
|
166
|
+
/**
|
|
167
|
+
* Try to run an action that returns a promise or a value with error and final
|
|
168
|
+
* actions to mimic `try {} catch(err) {} finally {}` for a value or promise.
|
|
169
|
+
*
|
|
170
|
+
* @param action - A function that returns a promise or a value
|
|
171
|
+
* @param errorAction - A function to be called once the action
|
|
172
|
+
* is rejected (synchronously or asynchronously). It must either return a new
|
|
173
|
+
* value or throw an error.
|
|
174
|
+
* @param finalAction - A function to be called once the action
|
|
175
|
+
* is fulfilled or rejected (synchronously or asynchronously)
|
|
176
|
+
*
|
|
177
|
+
* @typeParam T - Type for the return value
|
|
178
|
+
*/
|
|
179
|
+
function tryCatchFinally(action, errorAction = err => {
|
|
180
|
+
throw err;
|
|
181
|
+
}, finalAction = () => { }) {
|
|
182
|
+
let result;
|
|
183
|
+
try {
|
|
184
|
+
result = action();
|
|
185
|
+
}
|
|
186
|
+
catch (err) {
|
|
187
|
+
result = reject(err);
|
|
188
|
+
}
|
|
189
|
+
if (isPromiseLike(result)) {
|
|
190
|
+
return result.then(resolve, reject);
|
|
191
|
+
}
|
|
192
|
+
return resolve(result);
|
|
193
|
+
function resolve(value) {
|
|
194
|
+
try {
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
197
|
+
finally {
|
|
198
|
+
finalAction();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function reject(err) {
|
|
202
|
+
try {
|
|
203
|
+
return errorAction(err);
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
finalAction();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.tryCatchFinally = tryCatchFinally;
|
|
211
|
+
/**
|
|
212
|
+
* Resolve an iterator of source values into a result until the evaluator
|
|
213
|
+
* returns `true`
|
|
214
|
+
* @param source - The iterator of source values
|
|
215
|
+
* @param resolver - The resolve function that maps the source value to a result
|
|
216
|
+
* @param evaluator - The evaluate function that decides when to stop
|
|
217
|
+
*/
|
|
218
|
+
function resolveUntil(source, resolver, evaluator) {
|
|
219
|
+
// Do iteration in loop for synchronous values to avoid stack overflow
|
|
220
|
+
// eslint-disable-next-line no-constant-condition
|
|
221
|
+
while (true) {
|
|
222
|
+
const next = source.next();
|
|
223
|
+
if (next.done)
|
|
224
|
+
return undefined; // End of the iterator
|
|
225
|
+
const sourceVal = next.value;
|
|
226
|
+
const valueOrPromise = resolver(sourceVal);
|
|
227
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
228
|
+
return valueOrPromise.then(v => {
|
|
229
|
+
if (evaluator(sourceVal, v)) {
|
|
230
|
+
return v;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
return resolveUntil(source, resolver, evaluator);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
if (evaluator(sourceVal, valueOrPromise)) {
|
|
239
|
+
return valueOrPromise;
|
|
240
|
+
}
|
|
241
|
+
// Continue with the while loop
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
exports.resolveUntil = resolveUntil;
|
|
246
|
+
/**
|
|
247
|
+
* Transform a value or promise with a function that produces a new value or
|
|
248
|
+
* promise
|
|
249
|
+
* @param valueOrPromise - The value or promise
|
|
250
|
+
* @param transformer - A function that maps the source value to a value or promise
|
|
251
|
+
*/
|
|
252
|
+
function transformValueOrPromise(valueOrPromise, transformer) {
|
|
253
|
+
if (isPromiseLike(valueOrPromise)) {
|
|
254
|
+
return valueOrPromise.then(transformer);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
return transformer(valueOrPromise);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
exports.transformValueOrPromise = transformValueOrPromise;
|
|
261
|
+
/**
|
|
262
|
+
* A utility to generate uuid v4
|
|
263
|
+
*
|
|
264
|
+
* @deprecated Use `generateUniqueId`, [uuid](https://www.npmjs.com/package/uuid)
|
|
265
|
+
* or [hyperid](https://www.npmjs.com/package/hyperid) instead.
|
|
266
|
+
*/
|
|
267
|
+
function uuid() {
|
|
268
|
+
return (0, uuid_1.v4)();
|
|
269
|
+
}
|
|
270
|
+
exports.uuid = uuid;
|
|
271
|
+
/**
|
|
272
|
+
* A regular expression for testing uuid v4 PATTERN
|
|
273
|
+
* @deprecated This pattern is an internal helper used by unit-tests, we are no
|
|
274
|
+
* longer using it.
|
|
275
|
+
*/
|
|
276
|
+
exports.UUID_PATTERN = /[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}/i;
|
|
277
|
+
//# sourceMappingURL=value-promise.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-promise.js","sourceRoot":"","sources":["../src/value-promise.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;AAEhE;;;GAGG;AAEH,+BAAkC;AAwBlC;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,KAAqC;IAErC,IAAI,CAAC,KAA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AI,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,IAAI,CAAC,IAAI;YAAE,OAAO,SAAS,CAAC,CAAC,sBAAsB;QACvD,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC;QAC7B,MAAM,cAAc,GAAG,QAAQ,CAAC,SAAS,CAAC,CAAC;QAC3C,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE;YACjC,OAAO,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;gBAC7B,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE;oBAC3B,OAAO,CAAC,CAAC;iBACV;qBAAM;oBACL,OAAO,YAAY,CAAC,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;iBAClD;YACH,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,IAAI,SAAS,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE;gBACxC,OAAO,cAAc,CAAC;aACvB;YACD,+BAA+B;SAChC;KACF;AACH,CAAC;AA3BD,oCA2BC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,cAAiC,EACjC,WAA0C;IAE1C,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE;QACjC,OAAO,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;KACzC;SAAM;QACL,OAAO,WAAW,CAAC,cAAc,CAAC,CAAC;KACpC;AACH,CAAC;AATD,0DASC;AAED;;;;;GAKG;AACH,SAAgB,IAAI;IAClB,OAAO,IAAA,SAAM,GAAE,CAAC;AAClB,CAAC;AAFD,oBAEC;AAED;;;;GAIG;AACU,QAAA,YAAY,GACvB,wEAAwE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,31 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/context",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"scripts": {
|
|
6
|
-
"acceptance": "mocha --opts ../../test/mocha.opts 'test/acceptance/**/*.ts'",
|
|
7
|
-
"build": "npm run build:lib && npm run build:lib6",
|
|
8
|
-
"build:lib": "node ../../bin/compile-package es2017",
|
|
9
|
-
"build:lib6": "node ../../bin/compile-package es2015",
|
|
10
|
-
"clean": "rm -rf loopback-context*.tgz lib* package",
|
|
11
|
-
"prepublish": "npm run build",
|
|
12
|
-
"pretest": "npm run build",
|
|
13
|
-
"test": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts' 'test/acceptance/**/*.ts'",
|
|
14
|
-
"unit": "mocha --opts ../../test/mocha.opts 'test/unit/**/*.ts'",
|
|
15
|
-
"verify": "npm pack && tar xf loopback-context*.tgz && tree package && npm run clean"
|
|
16
|
-
},
|
|
17
|
-
"author": "IBM",
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"reflect-metadata": "^0.1.10"
|
|
21
|
-
},
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"@loopback/testlab": "^4.0.0-alpha.4",
|
|
24
|
-
"@types/bluebird": "^3.5.2",
|
|
25
|
-
"bluebird": "^3.5.0",
|
|
26
|
-
"mocha": "^3.2.0",
|
|
27
|
-
"typescript": "^2.3.2"
|
|
28
|
-
},
|
|
3
|
+
"description": "Facilities to manage artifacts and their dependencies in your Node.js applications. The module exposes TypeScript/JavaScript APIs and decorators to register artifacts, declare dependencies, and resolve artifacts by keys. It also serves as an IoC container to support dependency injection",
|
|
4
|
+
"version": "4.1.0",
|
|
29
5
|
"keywords": [
|
|
30
6
|
"LoopBack",
|
|
31
7
|
"IoC",
|
|
@@ -35,15 +11,54 @@
|
|
|
35
11
|
"Decorators",
|
|
36
12
|
"Context"
|
|
37
13
|
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"author": "IBM Corp.",
|
|
18
|
+
"copyright.owner": "IBM Corp.",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/loopbackio/loopback-next.git",
|
|
22
|
+
"directory": "packages/context"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": "12 || 14 || 16 || 17"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"acceptance": "lb-mocha \"dist/__tests__/acceptance/**/*.js\"",
|
|
29
|
+
"build": "lb-tsc",
|
|
30
|
+
"clean": "lb-clean loopback-context*.tgz dist *.tsbuildinfo package",
|
|
31
|
+
"pretest": "npm run build",
|
|
32
|
+
"test": "lb-mocha \"dist/__tests__/**/*.js\"",
|
|
33
|
+
"unit": "lb-mocha \"dist/__tests__/unit/**/*.js\"",
|
|
34
|
+
"verify": "npm pack && tar xf loopback-context*.tgz && tree package && npm run clean"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
38
39
|
"files": [
|
|
39
40
|
"README.md",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"lib6"
|
|
41
|
+
"dist",
|
|
42
|
+
"src",
|
|
43
|
+
"!*/__tests__"
|
|
44
44
|
],
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@loopback/metadata": "^4.1.0",
|
|
47
|
+
"@types/debug": "^4.1.7",
|
|
48
|
+
"debug": "^4.3.3",
|
|
49
|
+
"hyperid": "^3.0.0",
|
|
50
|
+
"p-event": "^4.2.0",
|
|
51
|
+
"tslib": "^2.3.1",
|
|
52
|
+
"uuid": "^8.3.2"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@loopback/build": "^8.1.0",
|
|
56
|
+
"@loopback/eslint-config": "^12.0.2",
|
|
57
|
+
"@loopback/testlab": "^4.1.0",
|
|
58
|
+
"@types/bluebird": "^3.5.36",
|
|
59
|
+
"@types/node": "^12.20.43",
|
|
60
|
+
"@types/uuid": "^8.3.4",
|
|
61
|
+
"bluebird": "^3.7.2"
|
|
62
|
+
},
|
|
63
|
+
"gitHead": "e16818ccb01edc0269ef6c45b022c5f1b67f852c"
|
|
49
64
|
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2019,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/context
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {BindingAddress, BindingKey} from './binding-key';
|
|
7
|
+
import {Context} from './context';
|
|
8
|
+
import {ResolutionOptions} from './resolution-session';
|
|
9
|
+
import {ValueOrPromise} from './value-promise';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolver for configuration of bindings. It's responsible for finding
|
|
13
|
+
* corresponding configuration for a given binding key.
|
|
14
|
+
*
|
|
15
|
+
* By default, `undefined` is expected if no configuration is provided. The
|
|
16
|
+
* behavior can be overridden by setting `optional` to `false` in resolution
|
|
17
|
+
* options.
|
|
18
|
+
*/
|
|
19
|
+
export interface ConfigurationResolver {
|
|
20
|
+
/**
|
|
21
|
+
* Resolve config for the binding key
|
|
22
|
+
*
|
|
23
|
+
* @param key - Binding key
|
|
24
|
+
* @param propertyPath - Property path for the option. For example, `x.y`
|
|
25
|
+
* requests for `<config>.x.y`. If not set, the `config` object will be
|
|
26
|
+
* returned.
|
|
27
|
+
* @param resolutionOptions - Options for the resolution.
|
|
28
|
+
* - optional: if not set or set to `true`, `undefined` will be returned if
|
|
29
|
+
* no corresponding value is found. Otherwise, an error will be thrown.
|
|
30
|
+
*/
|
|
31
|
+
getConfigAsValueOrPromise<ConfigValueType>(
|
|
32
|
+
key: BindingAddress<unknown>,
|
|
33
|
+
propertyPath?: string,
|
|
34
|
+
resolutionOptions?: ResolutionOptions,
|
|
35
|
+
): ValueOrPromise<ConfigValueType | undefined>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Resolver for configurations of bindings
|
|
40
|
+
*/
|
|
41
|
+
export class DefaultConfigurationResolver implements ConfigurationResolver {
|
|
42
|
+
constructor(public readonly context: Context) {}
|
|
43
|
+
|
|
44
|
+
getConfigAsValueOrPromise<ConfigValueType>(
|
|
45
|
+
key: BindingAddress<unknown>,
|
|
46
|
+
propertyPath?: string,
|
|
47
|
+
resolutionOptions?: ResolutionOptions,
|
|
48
|
+
): ValueOrPromise<ConfigValueType | undefined> {
|
|
49
|
+
propertyPath = propertyPath ?? '';
|
|
50
|
+
const configKey = configBindingKeyFor(key, propertyPath);
|
|
51
|
+
|
|
52
|
+
const options: ResolutionOptions = Object.assign(
|
|
53
|
+
{optional: true},
|
|
54
|
+
resolutionOptions,
|
|
55
|
+
);
|
|
56
|
+
return this.context.getValueOrPromise<ConfigValueType>(configKey, options);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Create binding key for configuration of the binding
|
|
62
|
+
* @param key - Binding key for the target binding
|
|
63
|
+
* @param propertyPath - Property path for the configuration
|
|
64
|
+
*/
|
|
65
|
+
export function configBindingKeyFor<ConfigValueType = unknown>(
|
|
66
|
+
key: BindingAddress,
|
|
67
|
+
propertyPath?: string,
|
|
68
|
+
) {
|
|
69
|
+
return BindingKey.create<ConfigValueType>(
|
|
70
|
+
BindingKey.buildKeyForConfig<ConfigValueType>(key).toString(),
|
|
71
|
+
propertyPath,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
|
|
2
|
+
// Node module: @loopback/context
|
|
3
|
+
// This file is licensed under the MIT License.
|
|
4
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
import {ClassDecoratorFactory} from '@loopback/metadata';
|
|
7
|
+
import {
|
|
8
|
+
asBindingTemplate,
|
|
9
|
+
asClassOrProvider,
|
|
10
|
+
asProvider,
|
|
11
|
+
BindingMetadata,
|
|
12
|
+
BindingSpec,
|
|
13
|
+
BINDING_METADATA_KEY,
|
|
14
|
+
isProviderClass,
|
|
15
|
+
removeNameAndKeyTags,
|
|
16
|
+
} from './binding-inspector';
|
|
17
|
+
import {Constructor} from './value-promise';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Decorator factory for `@injectable`
|
|
21
|
+
*/
|
|
22
|
+
class InjectableDecoratorFactory extends ClassDecoratorFactory<BindingMetadata> {
|
|
23
|
+
mergeWithInherited(inherited: BindingMetadata, target: Function) {
|
|
24
|
+
if (inherited) {
|
|
25
|
+
return {
|
|
26
|
+
templates: [
|
|
27
|
+
...inherited.templates,
|
|
28
|
+
removeNameAndKeyTags,
|
|
29
|
+
...this.spec.templates,
|
|
30
|
+
],
|
|
31
|
+
target: this.spec.target,
|
|
32
|
+
};
|
|
33
|
+
} else {
|
|
34
|
+
this.withTarget(this.spec, target);
|
|
35
|
+
return this.spec;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
mergeWithOwn(ownMetadata: BindingMetadata) {
|
|
40
|
+
return {
|
|
41
|
+
templates: [...ownMetadata.templates, ...this.spec.templates],
|
|
42
|
+
target: this.spec.target,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
withTarget(spec: BindingMetadata, target: Function) {
|
|
47
|
+
spec.target = target as Constructor<unknown>;
|
|
48
|
+
return spec;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Decorate a class with binding configuration
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* @injectable((binding) => {binding.inScope(BindingScope.SINGLETON).tag('controller')}
|
|
58
|
+
* )
|
|
59
|
+
* @injectable({scope: BindingScope.SINGLETON})
|
|
60
|
+
* export class MyController {
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* @param specs - A list of binding scope/tags or template functions to
|
|
65
|
+
* configure the binding
|
|
66
|
+
*/
|
|
67
|
+
export function injectable(...specs: BindingSpec[]): ClassDecorator {
|
|
68
|
+
const templateFunctions = specs.map(t => {
|
|
69
|
+
if (typeof t === 'function') {
|
|
70
|
+
return t;
|
|
71
|
+
} else {
|
|
72
|
+
return asBindingTemplate(t);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return (target: Function) => {
|
|
77
|
+
const cls = target as Constructor<unknown>;
|
|
78
|
+
const spec: BindingMetadata = {
|
|
79
|
+
templates: [asClassOrProvider(cls), ...templateFunctions],
|
|
80
|
+
target: cls,
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const decorator = InjectableDecoratorFactory.createDecorator(
|
|
84
|
+
BINDING_METADATA_KEY,
|
|
85
|
+
spec,
|
|
86
|
+
{decoratorName: '@injectable'},
|
|
87
|
+
);
|
|
88
|
+
decorator(target);
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* A namespace to host shortcuts for `@injectable`
|
|
94
|
+
*/
|
|
95
|
+
export namespace injectable {
|
|
96
|
+
/**
|
|
97
|
+
* `@injectable.provider` to denote a provider class
|
|
98
|
+
*
|
|
99
|
+
* A list of binding scope/tags or template functions to configure the binding
|
|
100
|
+
*/
|
|
101
|
+
export function provider(
|
|
102
|
+
...specs: BindingSpec[]
|
|
103
|
+
): (target: Constructor<unknown>) => void {
|
|
104
|
+
return (target: Constructor<unknown>) => {
|
|
105
|
+
if (!isProviderClass(target)) {
|
|
106
|
+
throw new Error(`Target ${target} is not a Provider`);
|
|
107
|
+
}
|
|
108
|
+
injectable(
|
|
109
|
+
// Set up the default for providers
|
|
110
|
+
asProvider(target),
|
|
111
|
+
// Call other template functions
|
|
112
|
+
...specs,
|
|
113
|
+
)(target);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* `@bind` is now an alias to {@link injectable} for backward compatibility
|
|
120
|
+
* {@inheritDoc injectable}
|
|
121
|
+
*/
|
|
122
|
+
export function bind(...specs: BindingSpec[]): ClassDecorator {
|
|
123
|
+
return injectable(...specs);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Alias namespace `bind` to `injectable` for backward compatibility
|
|
128
|
+
*
|
|
129
|
+
* It should have the same members as `bind`.
|
|
130
|
+
*/
|
|
131
|
+
export namespace bind {
|
|
132
|
+
/**
|
|
133
|
+
* {@inheritDoc injectable.provider}
|
|
134
|
+
*/
|
|
135
|
+
export const provider = injectable.provider;
|
|
136
|
+
}
|