@loopback/context 1.25.1 → 2.0.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/CHANGELOG.md +48 -0
- package/dist/binding-filter.d.ts +19 -1
- package/dist/binding-filter.js +40 -7
- package/dist/binding-filter.js.map +1 -1
- package/dist/binding.d.ts +33 -1
- package/dist/binding.js +14 -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 +29 -65
- package/dist/context.js +50 -245
- package/dist/context.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +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/value-promise.d.ts +1 -3
- package/package.json +7 -7
- package/src/binding-filter.ts +61 -9
- package/src/binding.ts +43 -1
- 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 +71 -286
- package/src/index.ts +2 -0
- package/src/interceptor.ts +7 -6
- package/src/invocation.ts +1 -3
- package/src/value-promise.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,54 @@
|
|
|
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.0.0](https://github.com/strongloop/loopback-next/compare/@loopback/context@1.25.1...@loopback/context@2.0.0) (2020-01-27)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **context:** add ContextEventListener and tidy up parent event handling ([beb41a7](https://github.com/strongloop/loopback-next/commit/beb41a7b105cf1aea64982e3f43f4d5a8128581f))
|
|
12
|
+
* **context:** index bindings by tag to speed up matching by tag ([566b9d9](https://github.com/strongloop/loopback-next/commit/566b9d9a35ce52d9aeefe17e36f91c9714616b21))
|
|
13
|
+
* **context:** keep binding tag pattern for BindingTagFilter ([856b62d](https://github.com/strongloop/loopback-next/commit/856b62d7053c22ebe0f6acf6a1904e524175429c))
|
|
14
|
+
* **context:** make bindings as event emitters to report changes ([dddddb9](https://github.com/strongloop/loopback-next/commit/dddddb96fd6908a8d4caad8868e43d3d0bb742f6))
|
|
15
|
+
* **context:** refactor context observer subscription into a new class ([31ad9a5](https://github.com/strongloop/loopback-next/commit/31ad9a55bbd068cd8e41347fca5caaf0ae5eb6e7))
|
|
16
|
+
* **context:** set max listeners to Infinity by default ([0741e3b](https://github.com/strongloop/loopback-next/commit/0741e3b1293065a04f1ecd9dbda09df074a5dd34))
|
|
17
|
+
* **context:** use BindingEvent for binding event listeners ([ae5febc](https://github.com/strongloop/loopback-next/commit/ae5febc35679f4d77b9970ecc26a71938a1c972e))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### BREAKING CHANGES
|
|
21
|
+
|
|
22
|
+
* **context:** Context events are now emitted as `ContextEvent` objects
|
|
23
|
+
instead of positional arguments. Context listener functions must switch from
|
|
24
|
+
the old style to new style as follows:
|
|
25
|
+
|
|
26
|
+
1. Old style
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
ctx.on('bind', (binding, context) => {
|
|
30
|
+
// ...
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. New style
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
ctx.on('bind', (event: ContextEvent) => {
|
|
38
|
+
// ...
|
|
39
|
+
});
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
ctx.on('bind', ({binding, context, type}) => {
|
|
46
|
+
// ...
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
6
54
|
## [1.25.1](https://github.com/strongloop/loopback-next/compare/@loopback/context@1.25.0...@loopback/context@1.25.1) (2020-01-07)
|
|
7
55
|
|
|
8
56
|
**Note:** Version bump only for package @loopback/context
|
package/dist/binding-filter.d.ts
CHANGED
|
@@ -42,11 +42,29 @@ export declare type BindingSelector<ValueType = unknown> = BindingAddress<ValueT
|
|
|
42
42
|
* @param bindingSelector
|
|
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
|
@@ -12,28 +12,61 @@ function isBindingAddress(bindingSelector) {
|
|
|
12
12
|
return typeof bindingSelector !== 'function';
|
|
13
13
|
}
|
|
14
14
|
exports.isBindingAddress = isBindingAddress;
|
|
15
|
+
/**
|
|
16
|
+
* Type guard for BindingTagFilter
|
|
17
|
+
* @param filter - A BindingFilter function
|
|
18
|
+
*/
|
|
19
|
+
function isBindingTagFilter(filter) {
|
|
20
|
+
if (filter == null || !('bindingTagPattern' in filter))
|
|
21
|
+
return false;
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
23
|
+
const tagPattern = filter.bindingTagPattern;
|
|
24
|
+
return (tagPattern instanceof RegExp ||
|
|
25
|
+
typeof tagPattern === 'string' ||
|
|
26
|
+
typeof tagPattern === 'object');
|
|
27
|
+
}
|
|
28
|
+
exports.isBindingTagFilter = isBindingTagFilter;
|
|
15
29
|
/**
|
|
16
30
|
* Create a binding filter for the tag pattern
|
|
17
31
|
* @param tagPattern - Binding tag name, regexp, or object
|
|
18
32
|
*/
|
|
19
33
|
function filterByTag(tagPattern) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
let filter;
|
|
35
|
+
let regex = undefined;
|
|
36
|
+
if (tagPattern instanceof RegExp) {
|
|
37
|
+
// RegExp for tag names
|
|
38
|
+
regex = tagPattern;
|
|
39
|
+
}
|
|
40
|
+
if (typeof tagPattern === 'string' &&
|
|
41
|
+
(tagPattern.includes('*') || tagPattern.includes('?'))) {
|
|
42
|
+
// Wildcard tag name
|
|
43
|
+
regex = wildcardToRegExp(tagPattern);
|
|
44
|
+
}
|
|
45
|
+
if (regex != null) {
|
|
46
|
+
// RegExp or wildcard match
|
|
47
|
+
filter = b => b.tagNames.some(t => regex.test(t));
|
|
48
|
+
}
|
|
49
|
+
else if (typeof tagPattern === 'string') {
|
|
50
|
+
// Plain tag string match
|
|
51
|
+
filter = b => b.tagNames.includes(tagPattern);
|
|
25
52
|
}
|
|
26
53
|
else {
|
|
27
|
-
|
|
54
|
+
// Match tag name/value pairs
|
|
55
|
+
const tagMap = tagPattern;
|
|
56
|
+
filter = b => {
|
|
28
57
|
for (const t in tagPattern) {
|
|
29
58
|
// One tag name/value does not match
|
|
30
|
-
if (b.tagMap[t] !==
|
|
59
|
+
if (b.tagMap[t] !== tagMap[t])
|
|
31
60
|
return false;
|
|
32
61
|
}
|
|
33
62
|
// All tag name/value pairs match
|
|
34
63
|
return true;
|
|
35
64
|
};
|
|
36
65
|
}
|
|
66
|
+
// Set up binding tag for the filter
|
|
67
|
+
const tagFilter = filter;
|
|
68
|
+
tagFilter.bindingTagPattern = (regex !== null && regex !== void 0 ? regex : tagPattern);
|
|
69
|
+
return tagFilter;
|
|
37
70
|
}
|
|
38
71
|
exports.filterByTag = filterByTag;
|
|
39
72
|
/**
|
|
@@ -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,SAAgB,gBAAgB,CAC9B,eAAgC;IAEhC,OAAO,OAAO,eAAe,KAAK,UAAU,CAAC;AAC/C,CAAC;AAJD,4CAIC;AAgBD;;;GAGG;AACH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OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC;AACnC,CAAC"}
|
package/dist/binding.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
1
3
|
import { BindingAddress } from './binding-key';
|
|
2
4
|
import { Context } from './context';
|
|
3
5
|
import { Provider } from './provider';
|
|
@@ -107,11 +109,36 @@ export declare type BindingTag = TagMap | string;
|
|
|
107
109
|
* A function as the template to configure bindings
|
|
108
110
|
*/
|
|
109
111
|
export declare type BindingTemplate<T = unknown> = (binding: Binding<T>) => void;
|
|
112
|
+
/**
|
|
113
|
+
* Information for a binding event
|
|
114
|
+
*/
|
|
115
|
+
export declare type BindingEvent = {
|
|
116
|
+
/**
|
|
117
|
+
* Event type
|
|
118
|
+
*/
|
|
119
|
+
type: string;
|
|
120
|
+
/**
|
|
121
|
+
* Source binding that emits the event
|
|
122
|
+
*/
|
|
123
|
+
binding: Readonly<Binding<unknown>>;
|
|
124
|
+
/**
|
|
125
|
+
* Operation that triggers the event
|
|
126
|
+
*/
|
|
127
|
+
operation: string;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Event listeners for binding events
|
|
131
|
+
*/
|
|
132
|
+
export declare type BindingEventListener = (
|
|
133
|
+
/**
|
|
134
|
+
* Binding event
|
|
135
|
+
*/
|
|
136
|
+
event: BindingEvent) => void;
|
|
110
137
|
/**
|
|
111
138
|
* Binding represents an entry in the `Context`. Each binding has a key and a
|
|
112
139
|
* corresponding value getter.
|
|
113
140
|
*/
|
|
114
|
-
export declare class Binding<T = BoundValue> {
|
|
141
|
+
export declare class Binding<T = BoundValue> extends EventEmitter {
|
|
115
142
|
isLocked: boolean;
|
|
116
143
|
/**
|
|
117
144
|
* Key of the binding
|
|
@@ -194,6 +221,11 @@ export declare class Binding<T = BoundValue> {
|
|
|
194
221
|
* Lock the binding so that it cannot be rebound
|
|
195
222
|
*/
|
|
196
223
|
lock(): this;
|
|
224
|
+
/**
|
|
225
|
+
* Emit a `changed` event
|
|
226
|
+
* @param operation - Operation that makes changes
|
|
227
|
+
*/
|
|
228
|
+
private emitChangedEvent;
|
|
197
229
|
/**
|
|
198
230
|
* Tag the binding with names or name/value objects. A tag has a name and
|
|
199
231
|
* an optional value. If not supplied, the tag name is used as the value.
|
package/dist/binding.js
CHANGED
|
@@ -8,6 +8,7 @@ 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");
|
|
12
13
|
const interception_proxy_1 = require("./interception-proxy");
|
|
13
14
|
const keys_1 = require("./keys");
|
|
@@ -116,8 +117,9 @@ var BindingType;
|
|
|
116
117
|
* Binding represents an entry in the `Context`. Each binding has a key and a
|
|
117
118
|
* corresponding value getter.
|
|
118
119
|
*/
|
|
119
|
-
class Binding {
|
|
120
|
+
class Binding extends events_1.EventEmitter {
|
|
120
121
|
constructor(key, isLocked = false) {
|
|
122
|
+
super();
|
|
121
123
|
this.isLocked = isLocked;
|
|
122
124
|
/**
|
|
123
125
|
* Map for tag name/value pairs
|
|
@@ -225,6 +227,14 @@ class Binding {
|
|
|
225
227
|
this.isLocked = true;
|
|
226
228
|
return this;
|
|
227
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Emit a `changed` event
|
|
232
|
+
* @param operation - Operation that makes changes
|
|
233
|
+
*/
|
|
234
|
+
emitChangedEvent(operation) {
|
|
235
|
+
const event = { binding: this, operation, type: 'changed' };
|
|
236
|
+
this.emit('changed', event);
|
|
237
|
+
}
|
|
228
238
|
/**
|
|
229
239
|
* Tag the binding with names or name/value objects. A tag has a name and
|
|
230
240
|
* an optional value. If not supplied, the tag name is used as the value.
|
|
@@ -263,6 +273,7 @@ class Binding {
|
|
|
263
273
|
Object.assign(this.tagMap, t);
|
|
264
274
|
}
|
|
265
275
|
}
|
|
276
|
+
this.emitChangedEvent('tag');
|
|
266
277
|
return this;
|
|
267
278
|
}
|
|
268
279
|
/**
|
|
@@ -279,6 +290,7 @@ class Binding {
|
|
|
279
290
|
if (this._scope !== scope)
|
|
280
291
|
this._clearCache();
|
|
281
292
|
this._scope = scope;
|
|
293
|
+
this.emitChangedEvent('scope');
|
|
282
294
|
return this;
|
|
283
295
|
}
|
|
284
296
|
/**
|
|
@@ -305,6 +317,7 @@ class Binding {
|
|
|
305
317
|
}
|
|
306
318
|
return getValue(ctx, options);
|
|
307
319
|
};
|
|
320
|
+
this.emitChangedEvent('value');
|
|
308
321
|
}
|
|
309
322
|
/**
|
|
310
323
|
* Bind the key to a constant value. The value must be already available
|
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;AACjE,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;;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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
|
-
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { Context } from './context';
|
|
4
|
+
import { ContextEvent, ContextEventListener } from './context-event';
|
|
5
|
+
import { ContextEventObserver, ContextObserver } from './context-observer';
|
|
6
|
+
/**
|
|
7
|
+
* Subscription of context events. It's modeled after
|
|
8
|
+
* https://github.com/tc39/proposal-observable.
|
|
9
|
+
*/
|
|
10
|
+
export interface Subscription {
|
|
11
|
+
/**
|
|
12
|
+
* unsubscribe
|
|
13
|
+
*/
|
|
14
|
+
unsubscribe(): void;
|
|
15
|
+
/**
|
|
16
|
+
* Is the subscription closed?
|
|
17
|
+
*/
|
|
18
|
+
closed: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Event data for observer notifications
|
|
22
|
+
*/
|
|
23
|
+
export interface Notification extends ContextEvent {
|
|
24
|
+
/**
|
|
25
|
+
* A snapshot of observers when the original event is emitted
|
|
26
|
+
*/
|
|
27
|
+
observers: Set<ContextEventObserver>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Manager for context observer subscriptions
|
|
31
|
+
*/
|
|
32
|
+
export declare class ContextSubscriptionManager extends EventEmitter {
|
|
33
|
+
protected readonly context: Context;
|
|
34
|
+
/**
|
|
35
|
+
* A listener to watch parent context events
|
|
36
|
+
*/
|
|
37
|
+
protected _parentContextEventListener?: ContextEventListener;
|
|
38
|
+
/**
|
|
39
|
+
* A list of registered context observers. The Set will be created when the
|
|
40
|
+
* first observer is added.
|
|
41
|
+
*/
|
|
42
|
+
protected _observers: Set<ContextEventObserver> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Internal counter for pending notification events which are yet to be
|
|
45
|
+
* processed by observers.
|
|
46
|
+
*/
|
|
47
|
+
private pendingNotifications;
|
|
48
|
+
/**
|
|
49
|
+
* Queue for background notifications for observers
|
|
50
|
+
*/
|
|
51
|
+
private notificationQueue;
|
|
52
|
+
constructor(context: Context);
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
get parentContextEventListener(): ContextEventListener | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
get observers(): Set<ContextEventObserver> | undefined;
|
|
61
|
+
/**
|
|
62
|
+
* Wrap the debug statement so that it always print out the context name
|
|
63
|
+
* as the prefix
|
|
64
|
+
* @param args - Arguments for the debug
|
|
65
|
+
*/
|
|
66
|
+
private _debug;
|
|
67
|
+
/**
|
|
68
|
+
* Set up an internal listener to notify registered observers asynchronously
|
|
69
|
+
* upon `bind` and `unbind` events. This method will be called lazily when
|
|
70
|
+
* the first observer is added.
|
|
71
|
+
*/
|
|
72
|
+
private setupEventHandlersIfNeeded;
|
|
73
|
+
private handleParentEvent;
|
|
74
|
+
/**
|
|
75
|
+
* A strongly-typed method to emit context events
|
|
76
|
+
* @param type Event type
|
|
77
|
+
* @param event Context event
|
|
78
|
+
*/
|
|
79
|
+
private emitEvent;
|
|
80
|
+
/**
|
|
81
|
+
* Emit an `error` event
|
|
82
|
+
* @param err Error
|
|
83
|
+
*/
|
|
84
|
+
private emitError;
|
|
85
|
+
/**
|
|
86
|
+
* Start a background task to listen on context events and notify observers
|
|
87
|
+
*/
|
|
88
|
+
private startNotificationTask;
|
|
89
|
+
/**
|
|
90
|
+
* Publish an event to the registered observers. Please note the
|
|
91
|
+
* notification is queued and performed asynchronously so that we allow fluent
|
|
92
|
+
* APIs such as `ctx.bind('key').to(...).tag(...);` and give observers the
|
|
93
|
+
* fully populated binding.
|
|
94
|
+
*
|
|
95
|
+
* @param event - Context event
|
|
96
|
+
* @param observers - Current set of context observers
|
|
97
|
+
*/
|
|
98
|
+
protected notifyObservers(event: ContextEvent, observers?: Set<ContextEventObserver> | undefined): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Process notification events as they arrive on the queue
|
|
101
|
+
*/
|
|
102
|
+
private processNotifications;
|
|
103
|
+
/**
|
|
104
|
+
* Listen on given event types and emit `notification` event. This method
|
|
105
|
+
* merge multiple event types into one for notification.
|
|
106
|
+
* @param eventTypes - Context event types
|
|
107
|
+
*/
|
|
108
|
+
private setupNotification;
|
|
109
|
+
/**
|
|
110
|
+
* Wait until observers are notified for all of currently pending notification
|
|
111
|
+
* events.
|
|
112
|
+
*
|
|
113
|
+
* This method is for test only to perform assertions after observers are
|
|
114
|
+
* notified for relevant events.
|
|
115
|
+
*/
|
|
116
|
+
waitUntilPendingNotificationsDone(timeout?: number): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Add a context event observer to the context
|
|
119
|
+
* @param observer - Context observer instance or function
|
|
120
|
+
*/
|
|
121
|
+
subscribe(observer: ContextEventObserver): Subscription;
|
|
122
|
+
/**
|
|
123
|
+
* Remove the context event observer from the context
|
|
124
|
+
* @param observer - Context event observer
|
|
125
|
+
*/
|
|
126
|
+
unsubscribe(observer: ContextEventObserver): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Check if an observer is subscribed to this context
|
|
129
|
+
* @param observer - Context observer
|
|
130
|
+
*/
|
|
131
|
+
isSubscribed(observer: ContextObserver): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Handle errors caught during the notification of observers
|
|
134
|
+
* @param err - Error
|
|
135
|
+
*/
|
|
136
|
+
private handleNotificationError;
|
|
137
|
+
/**
|
|
138
|
+
* Close the context: clear observers, stop notifications, and remove event
|
|
139
|
+
* listeners from its parent context.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* This method MUST be called to avoid memory leaks once a context object is
|
|
143
|
+
* no longer needed and should be recycled. An example is the `RequestContext`,
|
|
144
|
+
* which is created per request.
|
|
145
|
+
*/
|
|
146
|
+
close(): void;
|
|
147
|
+
}
|