@loopback/context 1.25.0 → 2.1.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 +80 -0
- package/dist/binding-filter.d.ts +20 -2
- package/dist/binding-filter.js +58 -9
- package/dist/binding-filter.js.map +1 -1
- package/dist/binding.d.ts +50 -2
- package/dist/binding.js +33 -1
- package/dist/binding.js.map +1 -1
- 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 +1 -36
- package/dist/context-subscription.d.ts +147 -0
- package/dist/context-subscription.js +336 -0
- package/dist/context-subscription.js.map +1 -0
- package/dist/context-tag-indexer.d.ts +42 -0
- package/dist/context-tag-indexer.js +134 -0
- package/dist/context-tag-indexer.js.map +1 -0
- package/dist/context-view.d.ts +2 -1
- package/dist/context-view.js.map +1 -1
- package/dist/context.d.ts +44 -68
- package/dist/context.js +69 -249
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +9 -2
- package/dist/inject.js +60 -0
- package/dist/inject.js.map +1 -1
- package/dist/interceptor.js +4 -4
- package/dist/interceptor.js.map +1 -1
- package/dist/invocation.d.ts +0 -1
- package/dist/invocation.js +1 -5
- package/dist/invocation.js.map +1 -1
- package/dist/json-types.d.ts +28 -0
- package/dist/json-types.js +7 -0
- package/dist/json-types.js.map +1 -0
- package/dist/resolution-session.d.ts +2 -6
- package/dist/resolution-session.js +0 -4
- package/dist/resolution-session.js.map +1 -1
- package/dist/value-promise.d.ts +1 -3
- package/package.json +9 -9
- package/src/binding-filter.ts +83 -11
- package/src/binding.ts +79 -3
- package/src/context-event.ts +30 -0
- package/src/context-observer.ts +1 -38
- package/src/context-subscription.ts +403 -0
- package/src/context-tag-indexer.ts +149 -0
- package/src/context-view.ts +2 -5
- package/src/context.ts +104 -290
- package/src/index.ts +3 -0
- package/src/inject.ts +65 -0
- package/src/interceptor.ts +7 -6
- package/src/invocation.ts +1 -3
- package/src/json-types.ts +35 -0
- package/src/resolution-session.ts +4 -7
- package/src/value-promise.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,86 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.1.1](https://github.com/strongloop/loopback-next/compare/@loopback/context@2.1.0...@loopback/context@2.1.1) (2020-02-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **context:** relax checking on instances of BindingKey class ([8668eb6](https://github.com/strongloop/loopback-next/commit/8668eb64b267e2644be87db92aeb86188d7e86f7))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [2.1.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@2.0.0...@loopback/context@2.1.0) (2020-02-05)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* **context:** allow more options to inspect context/binding objects ([3be32a3](https://github.com/strongloop/loopback-next/commit/3be32a34a0109e4f4f2eb0fcfa60171bd66743a6))
|
|
23
|
+
* **context:** improve context name with the subclass name as prefix ([42d2e1b](https://github.com/strongloop/loopback-next/commit/42d2e1b302e4c9f58df864c0ca01cb2ca181060a))
|
|
24
|
+
* **context:** tidy up binding information for inspection ([15d698b](https://github.com/strongloop/loopback-next/commit/15d698b46841efc0c6bc12bdc89538db77371254))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [2.0.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@1.25.1...@loopback/context@2.0.0) (2020-01-27)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* **context:** add ContextEventListener and tidy up parent event handling ([beb41a7](https://github.com/strongloop/loopback-next/commit/beb41a7b105cf1aea64982e3f43f4d5a8128581f))
|
|
36
|
+
* **context:** index bindings by tag to speed up matching by tag ([566b9d9](https://github.com/strongloop/loopback-next/commit/566b9d9a35ce52d9aeefe17e36f91c9714616b21))
|
|
37
|
+
* **context:** keep binding tag pattern for BindingTagFilter ([856b62d](https://github.com/strongloop/loopback-next/commit/856b62d7053c22ebe0f6acf6a1904e524175429c))
|
|
38
|
+
* **context:** make bindings as event emitters to report changes ([dddddb9](https://github.com/strongloop/loopback-next/commit/dddddb96fd6908a8d4caad8868e43d3d0bb742f6))
|
|
39
|
+
* **context:** refactor context observer subscription into a new class ([31ad9a5](https://github.com/strongloop/loopback-next/commit/31ad9a55bbd068cd8e41347fca5caaf0ae5eb6e7))
|
|
40
|
+
* **context:** set max listeners to Infinity by default ([0741e3b](https://github.com/strongloop/loopback-next/commit/0741e3b1293065a04f1ecd9dbda09df074a5dd34))
|
|
41
|
+
* **context:** use BindingEvent for binding event listeners ([ae5febc](https://github.com/strongloop/loopback-next/commit/ae5febc35679f4d77b9970ecc26a71938a1c972e))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### BREAKING CHANGES
|
|
45
|
+
|
|
46
|
+
* **context:** Context events are now emitted as `ContextEvent` objects
|
|
47
|
+
instead of positional arguments. Context listener functions must switch from
|
|
48
|
+
the old style to new style as follows:
|
|
49
|
+
|
|
50
|
+
1. Old style
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
ctx.on('bind', (binding, context) => {
|
|
54
|
+
// ...
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
2. New style
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
ctx.on('bind', (event: ContextEvent) => {
|
|
62
|
+
// ...
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Or:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
ctx.on('bind', ({binding, context, type}) => {
|
|
70
|
+
// ...
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## [1.25.1](https://github.com/strongloop/loopback-next/compare/@loopback/context@1.25.0...@loopback/context@1.25.1) (2020-01-07)
|
|
79
|
+
|
|
80
|
+
**Note:** Version bump only for package @loopback/context
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
6
86
|
# [1.25.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@1.24.0...@loopback/context@1.25.0) (2019-12-09)
|
|
7
87
|
|
|
8
88
|
|
package/dist/binding-filter.d.ts
CHANGED
|
@@ -39,14 +39,32 @@ export declare type BindingFilter<ValueType = unknown> = (binding: Readonly<Bind
|
|
|
39
39
|
export declare type BindingSelector<ValueType = unknown> = BindingAddress<ValueType> | BindingFilter<ValueType>;
|
|
40
40
|
/**
|
|
41
41
|
* Type guard for binding address
|
|
42
|
-
* @param bindingSelector
|
|
42
|
+
* @param bindingSelector - Binding key or filter function
|
|
43
43
|
*/
|
|
44
44
|
export declare function isBindingAddress(bindingSelector: BindingSelector): bindingSelector is BindingAddress;
|
|
45
|
+
/**
|
|
46
|
+
* Binding filter function that holds a binding tag pattern. `Context.find()`
|
|
47
|
+
* uses the `bindingTagPattern` to optimize the matching of bindings by tag to
|
|
48
|
+
* avoid expensive check for all bindings.
|
|
49
|
+
*/
|
|
50
|
+
export interface BindingTagFilter extends BindingFilter<unknown> {
|
|
51
|
+
/**
|
|
52
|
+
* A special property on the filter function to provide access to the binding
|
|
53
|
+
* tag pattern which can be utilized to optimize the matching of bindings by
|
|
54
|
+
* tag in a context.
|
|
55
|
+
*/
|
|
56
|
+
bindingTagPattern: BindingTag | RegExp;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Type guard for BindingTagFilter
|
|
60
|
+
* @param filter - A BindingFilter function
|
|
61
|
+
*/
|
|
62
|
+
export declare function isBindingTagFilter(filter?: BindingFilter): filter is BindingTagFilter;
|
|
45
63
|
/**
|
|
46
64
|
* Create a binding filter for the tag pattern
|
|
47
65
|
* @param tagPattern - Binding tag name, regexp, or object
|
|
48
66
|
*/
|
|
49
|
-
export declare function filterByTag(tagPattern: BindingTag | RegExp):
|
|
67
|
+
export declare function filterByTag(tagPattern: BindingTag | RegExp): BindingTagFilter;
|
|
50
68
|
/**
|
|
51
69
|
* Create a binding filter from key pattern
|
|
52
70
|
* @param keyPattern - Binding key/wildcard, regexp, or a filter function
|
package/dist/binding-filter.js
CHANGED
|
@@ -4,36 +4,85 @@
|
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
/**
|
|
8
|
+
* Check if an object is a `BindingKey` by duck typing
|
|
9
|
+
* @param selector Binding selector
|
|
10
|
+
*/
|
|
11
|
+
function isBindingKey(selector) {
|
|
12
|
+
if (selector == null || typeof selector !== 'object')
|
|
13
|
+
return false;
|
|
14
|
+
return (typeof selector.key === 'string' &&
|
|
15
|
+
typeof selector.deepProperty === 'function');
|
|
16
|
+
}
|
|
7
17
|
/**
|
|
8
18
|
* Type guard for binding address
|
|
9
|
-
* @param bindingSelector
|
|
19
|
+
* @param bindingSelector - Binding key or filter function
|
|
10
20
|
*/
|
|
11
21
|
function isBindingAddress(bindingSelector) {
|
|
12
|
-
return typeof bindingSelector !== 'function'
|
|
22
|
+
return (typeof bindingSelector !== 'function' &&
|
|
23
|
+
(typeof bindingSelector === 'string' ||
|
|
24
|
+
// See https://github.com/strongloop/loopback-next/issues/4570
|
|
25
|
+
// `bindingSelector instanceof BindingKey` is not always reliable as the
|
|
26
|
+
// `@loopback/context` module might be loaded from multiple locations if
|
|
27
|
+
// `npm install` does not dedupe or there are mixed versions in the tree
|
|
28
|
+
isBindingKey(bindingSelector)));
|
|
13
29
|
}
|
|
14
30
|
exports.isBindingAddress = isBindingAddress;
|
|
31
|
+
/**
|
|
32
|
+
* Type guard for BindingTagFilter
|
|
33
|
+
* @param filter - A BindingFilter function
|
|
34
|
+
*/
|
|
35
|
+
function isBindingTagFilter(filter) {
|
|
36
|
+
if (filter == null || !('bindingTagPattern' in filter))
|
|
37
|
+
return false;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
const tagPattern = filter.bindingTagPattern;
|
|
40
|
+
return (tagPattern instanceof RegExp ||
|
|
41
|
+
typeof tagPattern === 'string' ||
|
|
42
|
+
typeof tagPattern === 'object');
|
|
43
|
+
}
|
|
44
|
+
exports.isBindingTagFilter = isBindingTagFilter;
|
|
15
45
|
/**
|
|
16
46
|
* Create a binding filter for the tag pattern
|
|
17
47
|
* @param tagPattern - Binding tag name, regexp, or object
|
|
18
48
|
*/
|
|
19
49
|
function filterByTag(tagPattern) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
50
|
+
let filter;
|
|
51
|
+
let regex = undefined;
|
|
52
|
+
if (tagPattern instanceof RegExp) {
|
|
53
|
+
// RegExp for tag names
|
|
54
|
+
regex = tagPattern;
|
|
55
|
+
}
|
|
56
|
+
if (typeof tagPattern === 'string' &&
|
|
57
|
+
(tagPattern.includes('*') || tagPattern.includes('?'))) {
|
|
58
|
+
// Wildcard tag name
|
|
59
|
+
regex = wildcardToRegExp(tagPattern);
|
|
60
|
+
}
|
|
61
|
+
if (regex != null) {
|
|
62
|
+
// RegExp or wildcard match
|
|
63
|
+
filter = b => b.tagNames.some(t => regex.test(t));
|
|
64
|
+
}
|
|
65
|
+
else if (typeof tagPattern === 'string') {
|
|
66
|
+
// Plain tag string match
|
|
67
|
+
filter = b => b.tagNames.includes(tagPattern);
|
|
25
68
|
}
|
|
26
69
|
else {
|
|
27
|
-
|
|
70
|
+
// Match tag name/value pairs
|
|
71
|
+
const tagMap = tagPattern;
|
|
72
|
+
filter = b => {
|
|
28
73
|
for (const t in tagPattern) {
|
|
29
74
|
// One tag name/value does not match
|
|
30
|
-
if (b.tagMap[t] !==
|
|
75
|
+
if (b.tagMap[t] !== tagMap[t])
|
|
31
76
|
return false;
|
|
32
77
|
}
|
|
33
78
|
// All tag name/value pairs match
|
|
34
79
|
return true;
|
|
35
80
|
};
|
|
36
81
|
}
|
|
82
|
+
// Set up binding tag for the filter
|
|
83
|
+
const tagFilter = filter;
|
|
84
|
+
tagFilter.bindingTagPattern = (regex !== null && regex !== void 0 ? regex : tagPattern);
|
|
85
|
+
return tagFilter;
|
|
37
86
|
}
|
|
38
87
|
exports.filterByTag = filterByTag;
|
|
39
88
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding-filter.js","sourceRoot":"","sources":["../src/binding-filter.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;
|
|
1
|
+
{"version":3,"file":"binding-filter.js","sourceRoot":"","sources":["../src/binding-filter.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAiDhE;;;GAGG;AACH,SAAS,YAAY,CAAC,QAAyB;IAC7C,IAAI,QAAQ,IAAI,IAAI,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACnE,OAAO,CACL,OAAO,QAAQ,CAAC,GAAG,KAAK,QAAQ;QAChC,OAAO,QAAQ,CAAC,YAAY,KAAK,UAAU,CAC5C,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,gBAAgB,CAC9B,eAAgC;IAEhC,OAAO,CACL,OAAO,eAAe,KAAK,UAAU;QACrC,CAAC,OAAO,eAAe,KAAK,QAAQ;YAClC,8DAA8D;YAC9D,wEAAwE;YACxE,wEAAwE;YACxE,wEAAwE;YACxE,YAAY,CAAC,eAAe,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,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACjE,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/binding.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
1
3
|
import { BindingAddress } from './binding-key';
|
|
2
4
|
import { Context } from './context';
|
|
5
|
+
import { JSONObject } from './json-types';
|
|
3
6
|
import { Provider } from './provider';
|
|
4
7
|
import { ResolutionOptions, ResolutionSession } from './resolution-session';
|
|
5
8
|
import { BoundValue, Constructor, MapObject, ValueOrPromise } from './value-promise';
|
|
@@ -107,11 +110,36 @@ export declare type BindingTag = TagMap | string;
|
|
|
107
110
|
* A function as the template to configure bindings
|
|
108
111
|
*/
|
|
109
112
|
export declare type BindingTemplate<T = unknown> = (binding: Binding<T>) => void;
|
|
113
|
+
/**
|
|
114
|
+
* Information for a binding event
|
|
115
|
+
*/
|
|
116
|
+
export declare type BindingEvent = {
|
|
117
|
+
/**
|
|
118
|
+
* Event type
|
|
119
|
+
*/
|
|
120
|
+
type: string;
|
|
121
|
+
/**
|
|
122
|
+
* Source binding that emits the event
|
|
123
|
+
*/
|
|
124
|
+
binding: Readonly<Binding<unknown>>;
|
|
125
|
+
/**
|
|
126
|
+
* Operation that triggers the event
|
|
127
|
+
*/
|
|
128
|
+
operation: string;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Event listeners for binding events
|
|
132
|
+
*/
|
|
133
|
+
export declare type BindingEventListener = (
|
|
134
|
+
/**
|
|
135
|
+
* Binding event
|
|
136
|
+
*/
|
|
137
|
+
event: BindingEvent) => void;
|
|
110
138
|
/**
|
|
111
139
|
* Binding represents an entry in the `Context`. Each binding has a key and a
|
|
112
140
|
* corresponding value getter.
|
|
113
141
|
*/
|
|
114
|
-
export declare class Binding<T = BoundValue> {
|
|
142
|
+
export declare class Binding<T = BoundValue> extends EventEmitter {
|
|
115
143
|
isLocked: boolean;
|
|
116
144
|
/**
|
|
117
145
|
* Key of the binding
|
|
@@ -135,6 +163,7 @@ export declare class Binding<T = BoundValue> {
|
|
|
135
163
|
private _getValue;
|
|
136
164
|
private _valueConstructor?;
|
|
137
165
|
private _providerConstructor?;
|
|
166
|
+
private _alias?;
|
|
138
167
|
/**
|
|
139
168
|
* For bindings bound via `toClass()`, this property contains the constructor
|
|
140
169
|
* function of the class
|
|
@@ -194,6 +223,11 @@ export declare class Binding<T = BoundValue> {
|
|
|
194
223
|
* Lock the binding so that it cannot be rebound
|
|
195
224
|
*/
|
|
196
225
|
lock(): this;
|
|
226
|
+
/**
|
|
227
|
+
* Emit a `changed` event
|
|
228
|
+
* @param operation - Operation that makes changes
|
|
229
|
+
*/
|
|
230
|
+
private emitChangedEvent;
|
|
197
231
|
/**
|
|
198
232
|
* Tag the binding with names or name/value objects. A tag has a name and
|
|
199
233
|
* an optional value. If not supplied, the tag name is used as the value.
|
|
@@ -325,7 +359,12 @@ export declare class Binding<T = BoundValue> {
|
|
|
325
359
|
/**
|
|
326
360
|
* Convert to a plain JSON object
|
|
327
361
|
*/
|
|
328
|
-
toJSON():
|
|
362
|
+
toJSON(): JSONObject;
|
|
363
|
+
/**
|
|
364
|
+
* Inspect the binding to return a json representation of the binding information
|
|
365
|
+
* @param options - Options to control what information should be included
|
|
366
|
+
*/
|
|
367
|
+
inspect(options?: BindingInspectOptions): JSONObject;
|
|
329
368
|
/**
|
|
330
369
|
* A static method to create a binding so that we can do
|
|
331
370
|
* `Binding.bind('foo').to('bar');` as `new Binding('foo').to('bar')` is not
|
|
@@ -349,3 +388,12 @@ export declare class Binding<T = BoundValue> {
|
|
|
349
388
|
*/
|
|
350
389
|
static configure<T = unknown>(key: BindingAddress): Binding<T>;
|
|
351
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Options for binding.inspect()
|
|
393
|
+
*/
|
|
394
|
+
export interface BindingInspectOptions {
|
|
395
|
+
/**
|
|
396
|
+
* The flag to control if injections should be inspected
|
|
397
|
+
*/
|
|
398
|
+
includeInjections?: boolean;
|
|
399
|
+
}
|
package/dist/binding.js
CHANGED
|
@@ -8,7 +8,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
8
8
|
};
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
10
|
const debug_1 = __importDefault(require("debug"));
|
|
11
|
+
const events_1 = require("events");
|
|
11
12
|
const binding_key_1 = require("./binding-key");
|
|
13
|
+
const inject_1 = require("./inject");
|
|
12
14
|
const interception_proxy_1 = require("./interception-proxy");
|
|
13
15
|
const keys_1 = require("./keys");
|
|
14
16
|
const resolution_session_1 = require("./resolution-session");
|
|
@@ -116,8 +118,9 @@ var BindingType;
|
|
|
116
118
|
* Binding represents an entry in the `Context`. Each binding has a key and a
|
|
117
119
|
* corresponding value getter.
|
|
118
120
|
*/
|
|
119
|
-
class Binding {
|
|
121
|
+
class Binding extends events_1.EventEmitter {
|
|
120
122
|
constructor(key, isLocked = false) {
|
|
123
|
+
super();
|
|
121
124
|
this.isLocked = isLocked;
|
|
122
125
|
/**
|
|
123
126
|
* Map for tag name/value pairs
|
|
@@ -225,6 +228,14 @@ class Binding {
|
|
|
225
228
|
this.isLocked = true;
|
|
226
229
|
return this;
|
|
227
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Emit a `changed` event
|
|
233
|
+
* @param operation - Operation that makes changes
|
|
234
|
+
*/
|
|
235
|
+
emitChangedEvent(operation) {
|
|
236
|
+
const event = { binding: this, operation, type: 'changed' };
|
|
237
|
+
this.emit('changed', event);
|
|
238
|
+
}
|
|
228
239
|
/**
|
|
229
240
|
* Tag the binding with names or name/value objects. A tag has a name and
|
|
230
241
|
* an optional value. If not supplied, the tag name is used as the value.
|
|
@@ -263,6 +274,7 @@ class Binding {
|
|
|
263
274
|
Object.assign(this.tagMap, t);
|
|
264
275
|
}
|
|
265
276
|
}
|
|
277
|
+
this.emitChangedEvent('tag');
|
|
266
278
|
return this;
|
|
267
279
|
}
|
|
268
280
|
/**
|
|
@@ -279,6 +291,7 @@ class Binding {
|
|
|
279
291
|
if (this._scope !== scope)
|
|
280
292
|
this._clearCache();
|
|
281
293
|
this._scope = scope;
|
|
294
|
+
this.emitChangedEvent('scope');
|
|
282
295
|
return this;
|
|
283
296
|
}
|
|
284
297
|
/**
|
|
@@ -305,6 +318,7 @@ class Binding {
|
|
|
305
318
|
}
|
|
306
319
|
return getValue(ctx, options);
|
|
307
320
|
};
|
|
321
|
+
this.emitChangedEvent('value');
|
|
308
322
|
}
|
|
309
323
|
/**
|
|
310
324
|
* Bind the key to a constant value. The value must be already available
|
|
@@ -435,6 +449,7 @@ class Binding {
|
|
|
435
449
|
debug('Bind %s to alias %s', this.key, keyWithPath);
|
|
436
450
|
}
|
|
437
451
|
this._type = BindingType.ALIAS;
|
|
452
|
+
this._alias = keyWithPath;
|
|
438
453
|
this._setValueGetter((ctx, options) => {
|
|
439
454
|
return ctx.getValueOrPromise(keyWithPath, options);
|
|
440
455
|
});
|
|
@@ -486,6 +501,23 @@ class Binding {
|
|
|
486
501
|
if (this._providerConstructor != null) {
|
|
487
502
|
json.providerConstructor = this._providerConstructor.name;
|
|
488
503
|
}
|
|
504
|
+
if (this._alias != null) {
|
|
505
|
+
json.alias = this._alias.toString();
|
|
506
|
+
}
|
|
507
|
+
return json;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Inspect the binding to return a json representation of the binding information
|
|
511
|
+
* @param options - Options to control what information should be included
|
|
512
|
+
*/
|
|
513
|
+
inspect(options = {}) {
|
|
514
|
+
options = Object.assign({ includeInjections: false }, options);
|
|
515
|
+
const json = this.toJSON();
|
|
516
|
+
if (options.includeInjections) {
|
|
517
|
+
const injections = inject_1.inspectInjections(this);
|
|
518
|
+
if (Object.keys(injections).length)
|
|
519
|
+
json.injections = injections;
|
|
520
|
+
}
|
|
489
521
|
return json;
|
|
490
522
|
}
|
|
491
523
|
/**
|
package/dist/binding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,kDAAiC;AACjC,+CAAyD;AAEzD,6DAAiE;
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,kDAAiC;AACjC,mCAAoC;AACpC,+CAAyD;AAEzD,qCAA2C;AAC3C,6DAAiE;AAEjE,iCAAmC;AAEnC,6DAK8B;AAC9B,yCAA4C;AAC5C,mDAOyB;AAEzB,MAAM,KAAK,GAAG,eAAY,CAAC,0BAA0B,CAAC,CAAC;AAEvD;;GAEG;AACH,IAAY,YAoEX;AApED,WAAY,YAAY;IACtB;;;;;;;;;;;;;;;;;OAiBG;IACH,uCAAuB,CAAA;IAEvB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,mCAAmB,CAAA;IAEnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,uCAAuB,CAAA;AACzB,CAAC,EApEW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAoEvB;AAED;;GAEG;AACH,IAAY,WAqBX;AArBD,WAAY,WAAW;IACrB;;OAEG;IACH,oCAAqB,CAAA;IACrB;;OAEG;IACH,6CAA8B,CAAA;IAC9B;;OAEG;IACH,8BAAe,CAAA;IACf;;OAEG;IACH,oCAAqB,CAAA;IACrB;;OAEG;IACH,8BAAe,CAAA;AACjB,CAAC,EArBW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAqBtB;AAgDD;;;GAGG;AACH,MAAa,OAAwB,SAAQ,qBAAY;IAmDvD,YAAY,GAAsB,EAAS,WAAoB,KAAK;QAClE,KAAK,EAA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3C,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM;gBAAE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;SAClE;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAc,GAAsB;QAC7C,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,MAAM,CAAC,SAAS,CAAc,GAAmB;QAC/C,OAAO,IAAI,OAAO,CAAC,wBAAU,CAAC,iBAAiB,CAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;YAC3D,CAAC,kBAAW,CAAC,iBAAiB,CAAC,EAAE,GAAG,CAAC,QAAQ,EAAE;SAChD,CAAC,CAAC;IACL,CAAC;CACF;AA9gBD,0BA8gBC;AAYD,SAAS,mCAAmC,CAC1C,aAAgC,EAChC,OAAgB,EAChB,OAA2B;IAE3B,OAAO,uCAAuB,CAAC,aAAa,EAAE,IAAI,CAAC,EAAE;QACnD,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC1C,OAAQ,gDAA2B;QACjC,iCAAiC;QAChC,IAA0B,EAC3B,OAAO,EACP,OAAO,CACS,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Binding } from './binding';
|
|
2
|
+
import { Context } from './context';
|
|
3
|
+
/**
|
|
4
|
+
* Events emitted by a context
|
|
5
|
+
*/
|
|
6
|
+
export declare type ContextEvent = {
|
|
7
|
+
/**
|
|
8
|
+
* Source context that emits the event
|
|
9
|
+
*/
|
|
10
|
+
context: Context;
|
|
11
|
+
/**
|
|
12
|
+
* Binding that is being added/removed/updated
|
|
13
|
+
*/
|
|
14
|
+
binding: Readonly<Binding<unknown>>;
|
|
15
|
+
/**
|
|
16
|
+
* Event type
|
|
17
|
+
*/
|
|
18
|
+
type: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Synchronous listener for context events
|
|
22
|
+
*/
|
|
23
|
+
export declare type ContextEventListener = (event: ContextEvent) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 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
|
+
//# sourceMappingURL=context-event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-event.js","sourceRoot":"","sources":["../src/context-event.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Binding } from './binding';
|
|
2
2
|
import { BindingFilter } from './binding-filter';
|
|
3
|
-
import { ValueOrPromise } from './value-promise';
|
|
4
3
|
import { Context } from './context';
|
|
4
|
+
import { ValueOrPromise } from './value-promise';
|
|
5
5
|
/**
|
|
6
6
|
* Context event types. We support `bind` and `unbind` for now but
|
|
7
7
|
* keep it open for new types
|
|
@@ -34,38 +34,3 @@ export interface ContextObserver {
|
|
|
34
34
|
* Context event observer type - An instance of `ContextObserver` or a function
|
|
35
35
|
*/
|
|
36
36
|
export declare type ContextEventObserver = ContextObserver | ContextObserverFn;
|
|
37
|
-
/**
|
|
38
|
-
* Subscription of context events. It's modeled after
|
|
39
|
-
* https://github.com/tc39/proposal-observable.
|
|
40
|
-
*/
|
|
41
|
-
export interface Subscription {
|
|
42
|
-
/**
|
|
43
|
-
* unsubscribe
|
|
44
|
-
*/
|
|
45
|
-
unsubscribe(): void;
|
|
46
|
-
/**
|
|
47
|
-
* Is the subscription closed?
|
|
48
|
-
*/
|
|
49
|
-
closed: boolean;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Event data for observer notifications
|
|
53
|
-
*/
|
|
54
|
-
export declare type Notification = {
|
|
55
|
-
/**
|
|
56
|
-
* Context event type - bind/unbind
|
|
57
|
-
*/
|
|
58
|
-
eventType: ContextEventType;
|
|
59
|
-
/**
|
|
60
|
-
* Binding added/removed
|
|
61
|
-
*/
|
|
62
|
-
binding: Readonly<Binding<unknown>>;
|
|
63
|
-
/**
|
|
64
|
-
* Owner context for the binding
|
|
65
|
-
*/
|
|
66
|
-
context: Context;
|
|
67
|
-
/**
|
|
68
|
-
* A snapshot of observers when the original event is emitted
|
|
69
|
-
*/
|
|
70
|
-
observers: Set<ContextEventObserver>;
|
|
71
|
-
};
|