@loopback/context 4.0.0-alpha.6 → 4.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/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/dist/json-types.js +7 -0
- 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/dist/provider.js +7 -0
- 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 -36
- 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 -102
- package/lib/context.d.ts +0 -14
- package/lib/context.js +0 -96
- package/lib/index.d.ts +0 -5
- package/lib/index.js +0 -13
- package/lib/inject.d.ts +0 -24
- package/lib/inject.js +0 -43
- package/lib/isPromise.d.ts +0 -1
- package/lib/isPromise.js +0 -14
- package/lib/resolver.d.ts +0 -26
- package/lib/resolver.js +0 -72
- package/lib6/binding.d.ts +0 -75
- package/lib6/binding.js +0 -102
- package/lib6/context.d.ts +0 -14
- package/lib6/context.js +0 -96
- package/lib6/index.d.ts +0 -5
- package/lib6/index.js +0 -13
- package/lib6/inject.d.ts +0 -24
- package/lib6/inject.js +0 -43
- package/lib6/isPromise.d.ts +0 -1
- package/lib6/isPromise.js +0 -14
- package/lib6/resolver.d.ts +0 -26
- package/lib6/resolver.js +0 -72
|
@@ -0,0 +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,+DAAiC;AACjC,mCAAoC;AACpC,2DAAuD;AACvD,+CAAyD;AAEzD,qCAA2C;AAC3C,6DAAiE;AACjE,6CAA0C;AAE1C,iCAAmC;AAEnC,6DAO8B;AAC9B,yCAA4C;AAC5C,mDAOyB;AAEzB,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,0BAA0B,CAAC,CAAC;AAEvD;;GAEG;AACH,IAAY,YAiIX;AAjID,WAAY,YAAY;IACtB;;;;;;;;;;;;;;;;;OAiBG;IACH,uCAA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EAAE,QAAQ,CAAC,CAAC;IACnC,CAAC;IAeD,8DAA8D;IAC9D,IAAI,CAAC,KAAsB,EAAE,QAAkC;QAC7D,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;CACF;AA5tBD,0BA4tBC;AAYD,SAAS,mCAAmC,CAC1C,aAAgC,EAChC,OAAgB,EAChB,OAA2B;IAE3B,OAAO,IAAA,uCAAuB,EAAC,aAAa,EAAE,IAAI,CAAC,EAAE;QACnD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,IAAI,IAAI;YAAE,OAAO,IAAI,CAAC;QAC1D,OAAO,IAAA,gDAA2B;QAChC,iCAAiC;QACjC,IAAyB,EACzB,OAAO,EACP,OAAO,CACQ,CAAC;IACpB,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"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Binding } from './binding';
|
|
2
|
+
import { BindingFilter } from './binding-filter';
|
|
3
|
+
import { Context } from './context';
|
|
4
|
+
import { ValueOrPromise } from './value-promise';
|
|
5
|
+
/**
|
|
6
|
+
* Context event types. We support `bind` and `unbind` for now but
|
|
7
|
+
* keep it open for new types
|
|
8
|
+
*/
|
|
9
|
+
export declare type ContextEventType = 'bind' | 'unbind' | string;
|
|
10
|
+
/**
|
|
11
|
+
* Listen on `bind`, `unbind`, or other events
|
|
12
|
+
* @param eventType - Context event type
|
|
13
|
+
* @param binding - The binding as event source
|
|
14
|
+
* @param context - Context object for the binding event
|
|
15
|
+
*/
|
|
16
|
+
export declare type ContextObserverFn = (eventType: ContextEventType, binding: Readonly<Binding<unknown>>, context: Context) => ValueOrPromise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Observers of context bind/unbind events
|
|
19
|
+
*/
|
|
20
|
+
export interface ContextObserver {
|
|
21
|
+
/**
|
|
22
|
+
* An optional filter function to match bindings. If not present, the listener
|
|
23
|
+
* will be notified of all binding events.
|
|
24
|
+
*/
|
|
25
|
+
filter?: BindingFilter;
|
|
26
|
+
/**
|
|
27
|
+
* Listen on `bind`, `unbind`, or other events
|
|
28
|
+
* @param eventType - Context event type
|
|
29
|
+
* @param binding - The binding as event source
|
|
30
|
+
*/
|
|
31
|
+
observe: ContextObserverFn;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Context event observer type - An instance of `ContextObserver` or a function
|
|
35
|
+
*/
|
|
36
|
+
export declare type ContextEventObserver = ContextObserver | ContextObserverFn;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,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-observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-observer.js","sourceRoot":"","sources":["../src/context-observer.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE"}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. 2019,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.ContextSubscriptionManager = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
10
|
+
const events_1 = require("events");
|
|
11
|
+
const p_event_1 = require("p-event");
|
|
12
|
+
const debug = (0, debug_1.default)('loopback:context:subscription');
|
|
13
|
+
/**
|
|
14
|
+
* An implementation of `Subscription` interface for context events
|
|
15
|
+
*/
|
|
16
|
+
class ContextSubscription {
|
|
17
|
+
constructor(context, observer) {
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.observer = observer;
|
|
20
|
+
this._closed = false;
|
|
21
|
+
}
|
|
22
|
+
unsubscribe() {
|
|
23
|
+
this.context.unsubscribe(this.observer);
|
|
24
|
+
this._closed = true;
|
|
25
|
+
}
|
|
26
|
+
get closed() {
|
|
27
|
+
return this._closed;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Manager for context observer subscriptions
|
|
32
|
+
*/
|
|
33
|
+
class ContextSubscriptionManager extends events_1.EventEmitter {
|
|
34
|
+
constructor(context) {
|
|
35
|
+
super();
|
|
36
|
+
this.context = context;
|
|
37
|
+
/**
|
|
38
|
+
* Internal counter for pending notification events which are yet to be
|
|
39
|
+
* processed by observers.
|
|
40
|
+
*/
|
|
41
|
+
this.pendingNotifications = 0;
|
|
42
|
+
this.setMaxListeners(Infinity);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
get parentContextEventListener() {
|
|
48
|
+
return this._parentContextEventListener;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
get observers() {
|
|
54
|
+
return this._observers;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Wrap the debug statement so that it always print out the context name
|
|
58
|
+
* as the prefix
|
|
59
|
+
* @param args - Arguments for the debug
|
|
60
|
+
*/
|
|
61
|
+
_debug(...args) {
|
|
62
|
+
/* istanbul ignore if */
|
|
63
|
+
if (!debug.enabled)
|
|
64
|
+
return;
|
|
65
|
+
const formatter = args.shift();
|
|
66
|
+
if (typeof formatter === 'string') {
|
|
67
|
+
debug(`[%s] ${formatter}`, this.context.name, ...args);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
debug('[%s] ', this.context.name, formatter, ...args);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Set up an internal listener to notify registered observers asynchronously
|
|
75
|
+
* upon `bind` and `unbind` events. This method will be called lazily when
|
|
76
|
+
* the first observer is added.
|
|
77
|
+
*/
|
|
78
|
+
setupEventHandlersIfNeeded() {
|
|
79
|
+
if (this.notificationQueue != null)
|
|
80
|
+
return;
|
|
81
|
+
if (this.context.parent != null) {
|
|
82
|
+
/**
|
|
83
|
+
* Add an event listener to its parent context so that this context will
|
|
84
|
+
* be notified of parent events, such as `bind` or `unbind`.
|
|
85
|
+
*/
|
|
86
|
+
this._parentContextEventListener = event => {
|
|
87
|
+
this.handleParentEvent(event);
|
|
88
|
+
};
|
|
89
|
+
// Listen on the parent context events
|
|
90
|
+
this.context.parent.on('bind', this._parentContextEventListener);
|
|
91
|
+
this.context.parent.on('unbind', this._parentContextEventListener);
|
|
92
|
+
}
|
|
93
|
+
// The following are two async functions. Returned promises are ignored as
|
|
94
|
+
// they are long-running background tasks.
|
|
95
|
+
this.startNotificationTask().catch(err => {
|
|
96
|
+
this.handleNotificationError(err);
|
|
97
|
+
});
|
|
98
|
+
let ctx = this.context.parent;
|
|
99
|
+
while (ctx) {
|
|
100
|
+
ctx.subscriptionManager.setupEventHandlersIfNeeded();
|
|
101
|
+
ctx = ctx.parent;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
handleParentEvent(event) {
|
|
105
|
+
const { binding, context, type } = event;
|
|
106
|
+
// Propagate the event to this context only if the binding key does not
|
|
107
|
+
// exist in this context. The parent binding is shadowed if there is a
|
|
108
|
+
// binding with the same key in this one.
|
|
109
|
+
if (this.context.contains(binding.key)) {
|
|
110
|
+
this._debug('Event %s %s is not re-emitted from %s to %s', type, binding.key, context.name, this.context.name);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this._debug('Re-emitting %s %s from %s to %s', type, binding.key, context.name, this.context.name);
|
|
114
|
+
this.context.emitEvent(type, event);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A strongly-typed method to emit context events
|
|
118
|
+
* @param type Event type
|
|
119
|
+
* @param event Context event
|
|
120
|
+
*/
|
|
121
|
+
emitEvent(type, event) {
|
|
122
|
+
this.emit(type, event);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Emit an `error` event
|
|
126
|
+
* @param err Error
|
|
127
|
+
*/
|
|
128
|
+
emitError(err) {
|
|
129
|
+
this.emit('error', err);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Start a background task to listen on context events and notify observers
|
|
133
|
+
*/
|
|
134
|
+
startNotificationTask() {
|
|
135
|
+
// Set up listeners on `bind` and `unbind` for notifications
|
|
136
|
+
this.setupNotification('bind', 'unbind');
|
|
137
|
+
// Create an async iterator for the `notification` event as a queue
|
|
138
|
+
this.notificationQueue = (0, p_event_1.iterator)(this, 'notification', {
|
|
139
|
+
// Do not end the iterator if an error event is emitted on the
|
|
140
|
+
// subscription manager
|
|
141
|
+
rejectionEvents: [],
|
|
142
|
+
});
|
|
143
|
+
return this.processNotifications();
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Publish an event to the registered observers. Please note the
|
|
147
|
+
* notification is queued and performed asynchronously so that we allow fluent
|
|
148
|
+
* APIs such as `ctx.bind('key').to(...).tag(...);` and give observers the
|
|
149
|
+
* fully populated binding.
|
|
150
|
+
*
|
|
151
|
+
* @param event - Context event
|
|
152
|
+
* @param observers - Current set of context observers
|
|
153
|
+
*/
|
|
154
|
+
async notifyObservers(event, observers = this._observers) {
|
|
155
|
+
if (!observers || observers.size === 0)
|
|
156
|
+
return;
|
|
157
|
+
const { type, binding, context } = event;
|
|
158
|
+
for (const observer of observers) {
|
|
159
|
+
if (typeof observer === 'function') {
|
|
160
|
+
await observer(type, binding, context);
|
|
161
|
+
}
|
|
162
|
+
else if (!observer.filter || observer.filter(binding)) {
|
|
163
|
+
await observer.observe(type, binding, context);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Process notification events as they arrive on the queue
|
|
169
|
+
*/
|
|
170
|
+
async processNotifications() {
|
|
171
|
+
const events = this.notificationQueue;
|
|
172
|
+
if (events == null)
|
|
173
|
+
return;
|
|
174
|
+
for await (const { type, binding, context, observers } of events) {
|
|
175
|
+
// The loop will happen asynchronously upon events
|
|
176
|
+
try {
|
|
177
|
+
// The execution of observers happen in the Promise micro-task queue
|
|
178
|
+
await this.notifyObservers({ type, binding, context }, observers);
|
|
179
|
+
this.pendingNotifications--;
|
|
180
|
+
this._debug('Observers notified for %s of binding %s', type, binding.key);
|
|
181
|
+
this.emitEvent('observersNotified', { type, binding, context });
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
// Do not reduce the pending notification count so that errors
|
|
185
|
+
// can be captured by waitUntilPendingNotificationsDone
|
|
186
|
+
this._debug('Error caught from observers', err);
|
|
187
|
+
// Errors caught from observers.
|
|
188
|
+
if (this.listenerCount('error') > 0) {
|
|
189
|
+
// waitUntilPendingNotificationsDone may be called
|
|
190
|
+
this.emitError(err);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
// Emit it to the current context. If no error listeners are
|
|
194
|
+
// registered, crash the process.
|
|
195
|
+
this.handleNotificationError(err);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Listen on given event types and emit `notification` event. This method
|
|
202
|
+
* merge multiple event types into one for notification.
|
|
203
|
+
* @param eventTypes - Context event types
|
|
204
|
+
*/
|
|
205
|
+
setupNotification(...eventTypes) {
|
|
206
|
+
for (const type of eventTypes) {
|
|
207
|
+
this.context.on(type, ({ binding, context }) => {
|
|
208
|
+
// No need to schedule notifications if no observers are present
|
|
209
|
+
if (!this._observers || this._observers.size === 0)
|
|
210
|
+
return;
|
|
211
|
+
// Track pending events
|
|
212
|
+
this.pendingNotifications++;
|
|
213
|
+
// Take a snapshot of current observers to ensure notifications of this
|
|
214
|
+
// event will only be sent to current ones. Emit a new event to notify
|
|
215
|
+
// current context observers.
|
|
216
|
+
this.emitEvent('notification', {
|
|
217
|
+
type,
|
|
218
|
+
binding,
|
|
219
|
+
context,
|
|
220
|
+
observers: new Set(this._observers),
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Wait until observers are notified for all of currently pending notification
|
|
227
|
+
* events.
|
|
228
|
+
*
|
|
229
|
+
* This method is for test only to perform assertions after observers are
|
|
230
|
+
* notified for relevant events.
|
|
231
|
+
*/
|
|
232
|
+
async waitUntilPendingNotificationsDone(timeout) {
|
|
233
|
+
const count = this.pendingNotifications;
|
|
234
|
+
debug('Number of pending notifications: %d', count);
|
|
235
|
+
if (count === 0)
|
|
236
|
+
return;
|
|
237
|
+
await (0, p_event_1.multiple)(this, 'observersNotified', { count, timeout });
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Add a context event observer to the context
|
|
241
|
+
* @param observer - Context observer instance or function
|
|
242
|
+
*/
|
|
243
|
+
subscribe(observer) {
|
|
244
|
+
var _a;
|
|
245
|
+
this._observers = (_a = this._observers) !== null && _a !== void 0 ? _a : new Set();
|
|
246
|
+
this.setupEventHandlersIfNeeded();
|
|
247
|
+
this._observers.add(observer);
|
|
248
|
+
return new ContextSubscription(this.context, observer);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Remove the context event observer from the context
|
|
252
|
+
* @param observer - Context event observer
|
|
253
|
+
*/
|
|
254
|
+
unsubscribe(observer) {
|
|
255
|
+
if (!this._observers)
|
|
256
|
+
return false;
|
|
257
|
+
return this._observers.delete(observer);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Check if an observer is subscribed to this context
|
|
261
|
+
* @param observer - Context observer
|
|
262
|
+
*/
|
|
263
|
+
isSubscribed(observer) {
|
|
264
|
+
if (!this._observers)
|
|
265
|
+
return false;
|
|
266
|
+
return this._observers.has(observer);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Handle errors caught during the notification of observers
|
|
270
|
+
* @param err - Error
|
|
271
|
+
*/
|
|
272
|
+
handleNotificationError(err) {
|
|
273
|
+
// Bubbling up the error event over the context chain
|
|
274
|
+
// until we find an error listener
|
|
275
|
+
let ctx = this.context;
|
|
276
|
+
while (ctx) {
|
|
277
|
+
if (ctx.listenerCount('error') === 0) {
|
|
278
|
+
// No error listener found, try its parent
|
|
279
|
+
ctx = ctx.parent;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
this._debug('Emitting error to context %s', ctx.name, err);
|
|
283
|
+
ctx.emitError(err);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
// No context with error listeners found
|
|
287
|
+
this._debug('No error handler is configured for the context chain', err);
|
|
288
|
+
// Let it crash now by emitting an error event
|
|
289
|
+
this.context.emitError(err);
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Close the context: clear observers, stop notifications, and remove event
|
|
293
|
+
* listeners from its parent context.
|
|
294
|
+
*
|
|
295
|
+
* @remarks
|
|
296
|
+
* This method MUST be called to avoid memory leaks once a context object is
|
|
297
|
+
* no longer needed and should be recycled. An example is the `RequestContext`,
|
|
298
|
+
* which is created per request.
|
|
299
|
+
*/
|
|
300
|
+
close() {
|
|
301
|
+
this._observers = undefined;
|
|
302
|
+
if (this.notificationQueue != null) {
|
|
303
|
+
// Cancel the notification iterator
|
|
304
|
+
this.notificationQueue.return(undefined).catch(err => {
|
|
305
|
+
this.handleNotificationError(err);
|
|
306
|
+
});
|
|
307
|
+
this.notificationQueue = undefined;
|
|
308
|
+
}
|
|
309
|
+
if (this.context.parent && this._parentContextEventListener) {
|
|
310
|
+
this.context.parent.removeListener('bind', this._parentContextEventListener);
|
|
311
|
+
this.context.parent.removeListener('unbind', this._parentContextEventListener);
|
|
312
|
+
this._parentContextEventListener = undefined;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
exports.ContextSubscriptionManager = ContextSubscriptionManager;
|
|
317
|
+
//# sourceMappingURL=context-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-subscription.js","sourceRoot":"","sources":["../src/context-subscription.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+DAAiC;AACjC,mCAAoC;AACpC,qCAA2C;AAS3C,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,+BAA+B,CAAC,CAAC;AA2B5D;;GAEG;AACH,MAAM,mB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I,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,2BAA2B,EAAE;YAC3D,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAChC,MAAM,EACN,IAAI,CAAC,2BAA2B,CACjC,CAAC;YACF,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,cAAc,CAChC,QAAQ,EACR,IAAI,CAAC,2BAA2B,CACjC,CAAC;YACF,IAAI,CAAC,2BAA2B,GAAG,SAAS,CAAC;SAC9C;IACH,CAAC;CACF;AA9UD,gEA8UC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Binding, BindingTag } from './binding';
|
|
2
|
+
import { Context } from './context';
|
|
3
|
+
import { BoundValue } from './value-promise';
|
|
4
|
+
/**
|
|
5
|
+
* Indexer for context bindings by tag
|
|
6
|
+
*/
|
|
7
|
+
export declare class ContextTagIndexer {
|
|
8
|
+
protected readonly context: Context;
|
|
9
|
+
/**
|
|
10
|
+
* Index for bindings by tag names
|
|
11
|
+
*/
|
|
12
|
+
readonly bindingsIndexedByTag: Map<string, Set<Readonly<Binding<unknown>>>>;
|
|
13
|
+
/**
|
|
14
|
+
* A listener for binding events
|
|
15
|
+
*/
|
|
16
|
+
private bindingEventListener;
|
|
17
|
+
/**
|
|
18
|
+
* A listener to maintain tag index for bindings
|
|
19
|
+
*/
|
|
20
|
+
private tagIndexListener;
|
|
21
|
+
constructor(context: Context);
|
|
22
|
+
/**
|
|
23
|
+
* Set up context/binding listeners and refresh index for bindings by tag
|
|
24
|
+
*/
|
|
25
|
+
private setupTagIndexForBindings;
|
|
26
|
+
/**
|
|
27
|
+
* Remove tag index for the given binding
|
|
28
|
+
* @param binding - Binding object
|
|
29
|
+
*/
|
|
30
|
+
private removeTagIndexForBinding;
|
|
31
|
+
/**
|
|
32
|
+
* Update tag index for the given binding
|
|
33
|
+
* @param binding - Binding object
|
|
34
|
+
*/
|
|
35
|
+
private updateTagIndexForBinding;
|
|
36
|
+
/**
|
|
37
|
+
* Find bindings by tag leveraging indexes
|
|
38
|
+
* @param tag - Tag name pattern or name/value pairs
|
|
39
|
+
*/
|
|
40
|
+
findByTagIndex<ValueType = BoundValue>(tag: BindingTag | RegExp): Readonly<Binding<ValueType>>[];
|
|
41
|
+
close(): void;
|
|
42
|
+
}
|