@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
|
@@ -0,0 +1,336 @@
|
|
|
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
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
7
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
8
|
+
var m = o[Symbol.asyncIterator], i;
|
|
9
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
10
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
11
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const debug_1 = __importDefault(require("debug"));
|
|
18
|
+
const events_1 = require("events");
|
|
19
|
+
const debug = debug_1.default('loopback:context:subscription');
|
|
20
|
+
/**
|
|
21
|
+
* Polyfill Symbol.asyncIterator as required by TypeScript for Node 8.x.
|
|
22
|
+
* See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html
|
|
23
|
+
*/
|
|
24
|
+
if (!Symbol.asyncIterator) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
+
Symbol.asyncIterator = Symbol.for('Symbol.asyncIterator');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* WARNING: This following import must happen after the polyfill. The
|
|
30
|
+
* `auto-import` by an IDE such as VSCode may move the import before the
|
|
31
|
+
* polyfill. It must be then fixed manually.
|
|
32
|
+
*/
|
|
33
|
+
const p_event_1 = require("p-event");
|
|
34
|
+
/**
|
|
35
|
+
* An implementation of `Subscription` interface for context events
|
|
36
|
+
*/
|
|
37
|
+
class ContextSubscription {
|
|
38
|
+
constructor(context, observer) {
|
|
39
|
+
this.context = context;
|
|
40
|
+
this.observer = observer;
|
|
41
|
+
this._closed = false;
|
|
42
|
+
}
|
|
43
|
+
unsubscribe() {
|
|
44
|
+
this.context.unsubscribe(this.observer);
|
|
45
|
+
this._closed = true;
|
|
46
|
+
}
|
|
47
|
+
get closed() {
|
|
48
|
+
return this._closed;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Manager for context observer subscriptions
|
|
53
|
+
*/
|
|
54
|
+
class ContextSubscriptionManager extends events_1.EventEmitter {
|
|
55
|
+
constructor(context) {
|
|
56
|
+
super();
|
|
57
|
+
this.context = context;
|
|
58
|
+
/**
|
|
59
|
+
* Internal counter for pending notification events which are yet to be
|
|
60
|
+
* processed by observers.
|
|
61
|
+
*/
|
|
62
|
+
this.pendingNotifications = 0;
|
|
63
|
+
this.setMaxListeners(Infinity);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
get parentContextEventListener() {
|
|
69
|
+
return this._parentContextEventListener;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
get observers() {
|
|
75
|
+
return this._observers;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Wrap the debug statement so that it always print out the context name
|
|
79
|
+
* as the prefix
|
|
80
|
+
* @param args - Arguments for the debug
|
|
81
|
+
*/
|
|
82
|
+
_debug(...args) {
|
|
83
|
+
/* istanbul ignore if */
|
|
84
|
+
if (!debug.enabled)
|
|
85
|
+
return;
|
|
86
|
+
const formatter = args.shift();
|
|
87
|
+
if (typeof formatter === 'string') {
|
|
88
|
+
debug(`[%s] ${formatter}`, this.context.name, ...args);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
debug('[%s] ', this.context.name, formatter, ...args);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Set up an internal listener to notify registered observers asynchronously
|
|
96
|
+
* upon `bind` and `unbind` events. This method will be called lazily when
|
|
97
|
+
* the first observer is added.
|
|
98
|
+
*/
|
|
99
|
+
setupEventHandlersIfNeeded() {
|
|
100
|
+
if (this.notificationQueue != null)
|
|
101
|
+
return;
|
|
102
|
+
if (this.context.parent != null) {
|
|
103
|
+
/**
|
|
104
|
+
* Add an event listener to its parent context so that this context will
|
|
105
|
+
* be notified of parent events, such as `bind` or `unbind`.
|
|
106
|
+
*/
|
|
107
|
+
this._parentContextEventListener = event => {
|
|
108
|
+
this.handleParentEvent(event);
|
|
109
|
+
};
|
|
110
|
+
// Listen on the parent context events
|
|
111
|
+
this.context.parent.on('bind', this._parentContextEventListener);
|
|
112
|
+
this.context.parent.on('unbind', this._parentContextEventListener);
|
|
113
|
+
}
|
|
114
|
+
// The following are two async functions. Returned promises are ignored as
|
|
115
|
+
// they are long-running background tasks.
|
|
116
|
+
this.startNotificationTask().catch(err => {
|
|
117
|
+
this.handleNotificationError(err);
|
|
118
|
+
});
|
|
119
|
+
let ctx = this.context.parent;
|
|
120
|
+
while (ctx) {
|
|
121
|
+
ctx.subscriptionManager.setupEventHandlersIfNeeded();
|
|
122
|
+
ctx = ctx.parent;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
handleParentEvent(event) {
|
|
126
|
+
const { binding, context, type } = event;
|
|
127
|
+
// Propagate the event to this context only if the binding key does not
|
|
128
|
+
// exist in this context. The parent binding is shadowed if there is a
|
|
129
|
+
// binding with the same key in this one.
|
|
130
|
+
if (this.context.contains(binding.key)) {
|
|
131
|
+
this._debug('Event %s %s is not re-emitted from %s to %s', type, binding.key, context.name, this.context.name);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
this._debug('Re-emitting %s %s from %s to %s', type, binding.key, context.name, this.context.name);
|
|
135
|
+
this.context.emitEvent(type, event);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* A strongly-typed method to emit context events
|
|
139
|
+
* @param type Event type
|
|
140
|
+
* @param event Context event
|
|
141
|
+
*/
|
|
142
|
+
emitEvent(type, event) {
|
|
143
|
+
this.emit(type, event);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Emit an `error` event
|
|
147
|
+
* @param err Error
|
|
148
|
+
*/
|
|
149
|
+
emitError(err) {
|
|
150
|
+
this.emit('error', err);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Start a background task to listen on context events and notify observers
|
|
154
|
+
*/
|
|
155
|
+
startNotificationTask() {
|
|
156
|
+
// Set up listeners on `bind` and `unbind` for notifications
|
|
157
|
+
this.setupNotification('bind', 'unbind');
|
|
158
|
+
// Create an async iterator for the `notification` event as a queue
|
|
159
|
+
this.notificationQueue = p_event_1.iterator(this, 'notification');
|
|
160
|
+
return this.processNotifications();
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Publish an event to the registered observers. Please note the
|
|
164
|
+
* notification is queued and performed asynchronously so that we allow fluent
|
|
165
|
+
* APIs such as `ctx.bind('key').to(...).tag(...);` and give observers the
|
|
166
|
+
* fully populated binding.
|
|
167
|
+
*
|
|
168
|
+
* @param event - Context event
|
|
169
|
+
* @param observers - Current set of context observers
|
|
170
|
+
*/
|
|
171
|
+
async notifyObservers(event, observers = this._observers) {
|
|
172
|
+
if (!observers || observers.size === 0)
|
|
173
|
+
return;
|
|
174
|
+
const { type, binding, context } = event;
|
|
175
|
+
for (const observer of observers) {
|
|
176
|
+
if (typeof observer === 'function') {
|
|
177
|
+
await observer(type, binding, context);
|
|
178
|
+
}
|
|
179
|
+
else if (!observer.filter || observer.filter(binding)) {
|
|
180
|
+
await observer.observe(type, binding, context);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Process notification events as they arrive on the queue
|
|
186
|
+
*/
|
|
187
|
+
async processNotifications() {
|
|
188
|
+
var e_1, _a;
|
|
189
|
+
const events = this.notificationQueue;
|
|
190
|
+
if (events == null)
|
|
191
|
+
return;
|
|
192
|
+
try {
|
|
193
|
+
for (var events_2 = __asyncValues(events), events_2_1; events_2_1 = await events_2.next(), !events_2_1.done;) {
|
|
194
|
+
const { type, binding, context, observers } = events_2_1.value;
|
|
195
|
+
// The loop will happen asynchronously upon events
|
|
196
|
+
try {
|
|
197
|
+
// The execution of observers happen in the Promise micro-task queue
|
|
198
|
+
await this.notifyObservers({ type, binding, context }, observers);
|
|
199
|
+
this.pendingNotifications--;
|
|
200
|
+
this._debug('Observers notified for %s of binding %s', type, binding.key);
|
|
201
|
+
this.emitEvent('observersNotified', { type, binding, context });
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
this.pendingNotifications--;
|
|
205
|
+
this._debug('Error caught from observers', err);
|
|
206
|
+
// Errors caught from observers. Emit it to the current context.
|
|
207
|
+
// If no error listeners are registered, crash the process.
|
|
208
|
+
this.emitError(err);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
213
|
+
finally {
|
|
214
|
+
try {
|
|
215
|
+
if (events_2_1 && !events_2_1.done && (_a = events_2.return)) await _a.call(events_2);
|
|
216
|
+
}
|
|
217
|
+
finally { if (e_1) throw e_1.error; }
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Listen on given event types and emit `notification` event. This method
|
|
222
|
+
* merge multiple event types into one for notification.
|
|
223
|
+
* @param eventTypes - Context event types
|
|
224
|
+
*/
|
|
225
|
+
setupNotification(...eventTypes) {
|
|
226
|
+
for (const type of eventTypes) {
|
|
227
|
+
this.context.on(type, ({ binding, context }) => {
|
|
228
|
+
// No need to schedule notifications if no observers are present
|
|
229
|
+
if (!this._observers || this._observers.size === 0)
|
|
230
|
+
return;
|
|
231
|
+
// Track pending events
|
|
232
|
+
this.pendingNotifications++;
|
|
233
|
+
// Take a snapshot of current observers to ensure notifications of this
|
|
234
|
+
// event will only be sent to current ones. Emit a new event to notify
|
|
235
|
+
// current context observers.
|
|
236
|
+
this.emitEvent('notification', {
|
|
237
|
+
type,
|
|
238
|
+
binding,
|
|
239
|
+
context,
|
|
240
|
+
observers: new Set(this._observers),
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Wait until observers are notified for all of currently pending notification
|
|
247
|
+
* events.
|
|
248
|
+
*
|
|
249
|
+
* This method is for test only to perform assertions after observers are
|
|
250
|
+
* notified for relevant events.
|
|
251
|
+
*/
|
|
252
|
+
async waitUntilPendingNotificationsDone(timeout) {
|
|
253
|
+
const count = this.pendingNotifications;
|
|
254
|
+
if (count === 0)
|
|
255
|
+
return;
|
|
256
|
+
await p_event_1.multiple(this, 'observersNotified', { count, timeout });
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Add a context event observer to the context
|
|
260
|
+
* @param observer - Context observer instance or function
|
|
261
|
+
*/
|
|
262
|
+
subscribe(observer) {
|
|
263
|
+
var _a;
|
|
264
|
+
this._observers = (_a = this._observers, (_a !== null && _a !== void 0 ? _a : new Set()));
|
|
265
|
+
this.setupEventHandlersIfNeeded();
|
|
266
|
+
this._observers.add(observer);
|
|
267
|
+
return new ContextSubscription(this.context, observer);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Remove the context event observer from the context
|
|
271
|
+
* @param observer - Context event observer
|
|
272
|
+
*/
|
|
273
|
+
unsubscribe(observer) {
|
|
274
|
+
if (!this._observers)
|
|
275
|
+
return false;
|
|
276
|
+
return this._observers.delete(observer);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Check if an observer is subscribed to this context
|
|
280
|
+
* @param observer - Context observer
|
|
281
|
+
*/
|
|
282
|
+
isSubscribed(observer) {
|
|
283
|
+
if (!this._observers)
|
|
284
|
+
return false;
|
|
285
|
+
return this._observers.has(observer);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Handle errors caught during the notification of observers
|
|
289
|
+
* @param err - Error
|
|
290
|
+
*/
|
|
291
|
+
handleNotificationError(err) {
|
|
292
|
+
// Bubbling up the error event over the context chain
|
|
293
|
+
// until we find an error listener
|
|
294
|
+
let ctx = this.context;
|
|
295
|
+
while (ctx) {
|
|
296
|
+
if (ctx.listenerCount('error') === 0) {
|
|
297
|
+
// No error listener found, try its parent
|
|
298
|
+
ctx = ctx.parent;
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
this._debug('Emitting error to context %s', ctx.name, err);
|
|
302
|
+
ctx.emitError(err);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
// No context with error listeners found
|
|
306
|
+
this._debug('No error handler is configured for the context chain', err);
|
|
307
|
+
// Let it crash now by emitting an error event
|
|
308
|
+
this.context.emitError(err);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Close the context: clear observers, stop notifications, and remove event
|
|
312
|
+
* listeners from its parent context.
|
|
313
|
+
*
|
|
314
|
+
* @remarks
|
|
315
|
+
* This method MUST be called to avoid memory leaks once a context object is
|
|
316
|
+
* no longer needed and should be recycled. An example is the `RequestContext`,
|
|
317
|
+
* which is created per request.
|
|
318
|
+
*/
|
|
319
|
+
close() {
|
|
320
|
+
this._observers = undefined;
|
|
321
|
+
if (this.notificationQueue != null) {
|
|
322
|
+
// Cancel the notification iterator
|
|
323
|
+
this.notificationQueue.return(undefined).catch(err => {
|
|
324
|
+
this.handleNotificationError(err);
|
|
325
|
+
});
|
|
326
|
+
this.notificationQueue = undefined;
|
|
327
|
+
}
|
|
328
|
+
if (this.context.parent && this._parentContextEventListener) {
|
|
329
|
+
this.context.parent.removeListener('bind', this._parentContextEventListener);
|
|
330
|
+
this.context.parent.removeListener('unbind', this._parentContextEventListener);
|
|
331
|
+
this._parentContextEventListener = undefined;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
exports.ContextSubscriptionManager = ContextSubscriptionManager;
|
|
336
|
+
//# sourceMappingURL=context-subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-subscription.js","sourceRoot":"","sources":["../src/context-subscription.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;;;;;;;;;;;AAEhE,kDAAiC;AACjC,mCAAoC;AAQpC,MAAM,KAAK,GAAG,eAAY,CAAC,+BAA+B,CAAC,CAAC;AAE5D;;;GAGG;AACH,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;IACzB,8DAA8D;IAC7D,MAAc,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;CACpE;AACD;;;;GAIG;AACH,qCAA2C;AA2B3C;;GAEG;AACH,MAAM,mBAAmB;IACvB,YACY,OAAgB,EAChB,QAA8B;QAD9B,YAAO,GAAP,OAAO,CAAS;QAChB,aAAQ,GAAR,QAAQ,CAAsB;QAGlC,YAAO,GAAG,KAAK,CAAC;IAFrB,CAAC;IAIJ,WAAW;QACT,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACxC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAa,0BAA2B,SAAQ,qBAAY;IAuB1D,YAA+B,OAAgB;QAC7C,KAAK,EAAE,CAAC;QADqB,YAAO,GAAP,OAAO,CAAS;QAX/C;;;WAGG;QACK,yBAAoB,GAAG,CAAC,CAAC;QAS/B,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,I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AAC;IAC9B,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK;QACH,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,EAAE;YAClC,mCAAmC;YACnC,IAAI,CAAC,iBAAiB,CAAC,MAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;gBACpD,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;YACH,IAAI,CAAC,iBAAiB,GAAG,SAAS,CAAC;SACpC;QACD,IAAI,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;AAlUD,gEAkUC"}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
const binding_filter_1 = require("./binding-filter");
|
|
8
|
+
/**
|
|
9
|
+
* Indexer for context bindings by tag
|
|
10
|
+
*/
|
|
11
|
+
class ContextTagIndexer {
|
|
12
|
+
constructor(context) {
|
|
13
|
+
this.context = context;
|
|
14
|
+
/**
|
|
15
|
+
* Index for bindings by tag names
|
|
16
|
+
*/
|
|
17
|
+
this.bindingsIndexedByTag = new Map();
|
|
18
|
+
this.setupTagIndexForBindings();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set up context/binding listeners and refresh index for bindings by tag
|
|
22
|
+
*/
|
|
23
|
+
setupTagIndexForBindings() {
|
|
24
|
+
this.bindingEventListener = ({ binding, operation }) => {
|
|
25
|
+
if (operation === 'tag') {
|
|
26
|
+
this.updateTagIndexForBinding(binding);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
this.tagIndexListener = event => {
|
|
30
|
+
const { binding, type } = event;
|
|
31
|
+
if (event.context !== this.context)
|
|
32
|
+
return;
|
|
33
|
+
if (type === 'bind') {
|
|
34
|
+
this.updateTagIndexForBinding(binding);
|
|
35
|
+
binding.on('changed', this.bindingEventListener);
|
|
36
|
+
}
|
|
37
|
+
else if (type === 'unbind') {
|
|
38
|
+
this.removeTagIndexForBinding(binding);
|
|
39
|
+
binding.removeListener('changed', this.bindingEventListener);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
this.context.on('bind', this.tagIndexListener);
|
|
43
|
+
this.context.on('unbind', this.tagIndexListener);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Remove tag index for the given binding
|
|
47
|
+
* @param binding - Binding object
|
|
48
|
+
*/
|
|
49
|
+
removeTagIndexForBinding(binding) {
|
|
50
|
+
for (const [, bindings] of this.bindingsIndexedByTag) {
|
|
51
|
+
bindings.delete(binding);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Update tag index for the given binding
|
|
56
|
+
* @param binding - Binding object
|
|
57
|
+
*/
|
|
58
|
+
updateTagIndexForBinding(binding) {
|
|
59
|
+
this.removeTagIndexForBinding(binding);
|
|
60
|
+
for (const tag of binding.tagNames) {
|
|
61
|
+
let bindings = this.bindingsIndexedByTag.get(tag);
|
|
62
|
+
if (bindings == null) {
|
|
63
|
+
bindings = new Set();
|
|
64
|
+
this.bindingsIndexedByTag.set(tag, bindings);
|
|
65
|
+
}
|
|
66
|
+
bindings.add(binding);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Find bindings by tag leveraging indexes
|
|
71
|
+
* @param tag - Tag name pattern or name/value pairs
|
|
72
|
+
*/
|
|
73
|
+
findByTagIndex(tag) {
|
|
74
|
+
let tagNames;
|
|
75
|
+
// A flag to control if a union of matched bindings should be created
|
|
76
|
+
let union = false;
|
|
77
|
+
if (tag instanceof RegExp) {
|
|
78
|
+
// For wildcard/regexp, a union of matched bindings is desired
|
|
79
|
+
union = true;
|
|
80
|
+
// Find all matching tag names
|
|
81
|
+
tagNames = [];
|
|
82
|
+
for (const t of this.bindingsIndexedByTag.keys()) {
|
|
83
|
+
if (tag.test(t)) {
|
|
84
|
+
tagNames.push(t);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (typeof tag === 'string') {
|
|
89
|
+
tagNames = [tag];
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
tagNames = Object.keys(tag);
|
|
93
|
+
}
|
|
94
|
+
let filter;
|
|
95
|
+
let bindings;
|
|
96
|
+
for (const t of tagNames) {
|
|
97
|
+
const bindingsByTag = this.bindingsIndexedByTag.get(t);
|
|
98
|
+
if (bindingsByTag == null)
|
|
99
|
+
break; // One of the tags is not found
|
|
100
|
+
filter = (filter !== null && filter !== void 0 ? filter : binding_filter_1.filterByTag(tag));
|
|
101
|
+
const matched = new Set(Array.from(bindingsByTag).filter(filter));
|
|
102
|
+
if (!union && matched.size === 0)
|
|
103
|
+
break; // One of the tag name/value is not found
|
|
104
|
+
if (bindings == null) {
|
|
105
|
+
// First set of bindings matching the tag
|
|
106
|
+
bindings = matched;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (union) {
|
|
110
|
+
matched.forEach(b => { var _a; return (_a = bindings) === null || _a === void 0 ? void 0 : _a.add(b); });
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Now need to find intersected bindings against visited tags
|
|
114
|
+
const intersection = new Set();
|
|
115
|
+
bindings.forEach(b => {
|
|
116
|
+
if (matched.has(b)) {
|
|
117
|
+
intersection.add(b);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
bindings = intersection;
|
|
121
|
+
}
|
|
122
|
+
if (!union && bindings.size === 0)
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return bindings == null ? [] : Array.from(bindings);
|
|
127
|
+
}
|
|
128
|
+
close() {
|
|
129
|
+
this.context.removeListener('bind', this.tagIndexListener);
|
|
130
|
+
this.context.removeListener('unbind', this.tagIndexListener);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.ContextTagIndexer = ContextTagIndexer;
|
|
134
|
+
//# sourceMappingURL=context-tag-indexer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-tag-indexer.js","sourceRoot":"","sources":["../src/context-tag-indexer.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC/C,gEAAgE;;AAGhE,qDAA4D;AAK5D;;GAEG;AACH,MAAa,iBAAiB;IAmB5B,YAA+B,OAAgB;QAAhB,YAAO,GAAP,OAAO,CAAS;QAlB/C;;WAEG;QACM,yBAAoB,GAGzB,IAAI,GAAG,EAAE,CAAC;QAaZ,IAAI,CAAC,wBAAwB,EAAE,CAAC;IAClC,CAAC;IAED;;OAEG;IACK,wBAAwB;QAC9B,IAAI,CAAC,oBAAoB,GAAG,CAAC,EAAC,OAAO,EAAE,SAAS,EAAC,EAAE,EAAE;YACnD,IAAI,SAAS,KAAK,KAAK,EAAE;gBACvB,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;aACxC;QACH,CAAC,CAAC;QACF,IAAI,CAAC,gBAAgB,GAAG,KAAK,CAAC,EAAE;YAC9B,MAAM,EAAC,OAAO,EAAE,IAAI,EAAC,GAAG,KAAK,CAAC;YAC9B,IAAI,KAAK,CAAC,OAAO,KAAK,IAAI,CAAC,OAAO;gBAAE,OAAO;YAC3C,IAAI,IAAI,KAAK,MAAM,EAAE;gBACnB,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;gBACvC,OAAO,CAAC,EAAE,CAAC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AC7D,MAAM,YAAY,GAAG,IAAI,GAAG,EAAgC,CAAC;oBAC7D,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;wBACnB,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;4BAClB,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;yBACrB;oBACH,CAAC,CAAC,CAAC;oBACH,QAAQ,GAAG,YAAY,CAAC;iBACzB;gBACD,IAAI,CAAC,KAAK,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC;oBAAE,MAAM;aAC1C;SACF;QACD,OAAO,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACtD,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC3D,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC/D,CAAC;CACF;AAtID,8CAsIC"}
|
package/dist/context-view.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { Binding } from './binding';
|
|
|
4
4
|
import { BindingFilter } from './binding-filter';
|
|
5
5
|
import { BindingComparator } from './binding-sorter';
|
|
6
6
|
import { Context } from './context';
|
|
7
|
-
import { ContextEventType, ContextObserver
|
|
7
|
+
import { ContextEventType, ContextObserver } from './context-observer';
|
|
8
|
+
import { Subscription } from './context-subscription';
|
|
8
9
|
import { Getter } from './inject';
|
|
9
10
|
import { ResolutionSession } from './resolution-session';
|
|
10
11
|
import { ValueOrPromise } from './value-promise';
|
package/dist/context-view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context-view.js","sourceRoot":"","sources":["../src/context-view.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,iCAAiC;AACjC,+CAA+C;AAC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