mongodb-livedata-server 0.1.3 → 0.1.4
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/dist/livedata_server.d.ts +4 -4
- package/dist/livedata_server.js +11 -11
- package/dist/meteor/binary-heap/max_heap.d.ts +31 -31
- package/dist/meteor/binary-heap/max_heap.js +186 -186
- package/dist/meteor/binary-heap/min_heap.d.ts +6 -6
- package/dist/meteor/binary-heap/min_heap.js +17 -17
- package/dist/meteor/binary-heap/min_max_heap.d.ts +11 -11
- package/dist/meteor/binary-heap/min_max_heap.js +48 -48
- package/dist/meteor/callback-hook/hook.d.ts +11 -11
- package/dist/meteor/callback-hook/hook.js +78 -78
- package/dist/meteor/ddp/crossbar.d.ts +15 -15
- package/dist/meteor/ddp/crossbar.js +136 -136
- package/dist/meteor/ddp/heartbeat.d.ts +19 -19
- package/dist/meteor/ddp/heartbeat.js +77 -77
- package/dist/meteor/ddp/livedata_server.d.ts +141 -142
- package/dist/meteor/ddp/livedata_server.js +403 -403
- package/dist/meteor/ddp/method-invocation.d.ts +35 -35
- package/dist/meteor/ddp/method-invocation.js +72 -72
- package/dist/meteor/ddp/random-stream.d.ts +8 -8
- package/dist/meteor/ddp/random-stream.js +100 -100
- package/dist/meteor/ddp/session-collection-view.d.ts +20 -20
- package/dist/meteor/ddp/session-collection-view.js +106 -106
- package/dist/meteor/ddp/session-document-view.d.ts +8 -8
- package/dist/meteor/ddp/session-document-view.js +82 -82
- package/dist/meteor/ddp/session.d.ts +75 -75
- package/dist/meteor/ddp/session.js +590 -590
- package/dist/meteor/ddp/stream_server.d.ts +20 -21
- package/dist/meteor/ddp/stream_server.js +181 -181
- package/dist/meteor/ddp/subscription.d.ts +94 -94
- package/dist/meteor/ddp/subscription.js +370 -370
- package/dist/meteor/ddp/utils.d.ts +8 -8
- package/dist/meteor/ddp/utils.js +104 -104
- package/dist/meteor/ddp/writefence.d.ts +20 -20
- package/dist/meteor/ddp/writefence.js +111 -111
- package/dist/meteor/diff-sequence/diff.d.ts +17 -17
- package/dist/meteor/diff-sequence/diff.js +257 -257
- package/dist/meteor/ejson/ejson.d.ts +82 -82
- package/dist/meteor/ejson/ejson.js +568 -569
- package/dist/meteor/ejson/stringify.d.ts +2 -2
- package/dist/meteor/ejson/stringify.js +119 -119
- package/dist/meteor/ejson/utils.d.ts +12 -12
- package/dist/meteor/ejson/utils.js +42 -42
- package/dist/meteor/mongo/caching_change_observer.d.ts +16 -16
- package/dist/meteor/mongo/caching_change_observer.js +63 -63
- package/dist/meteor/mongo/doc_fetcher.d.ts +7 -7
- package/dist/meteor/mongo/doc_fetcher.js +53 -53
- package/dist/meteor/mongo/geojson_utils.d.ts +3 -3
- package/dist/meteor/mongo/geojson_utils.js +40 -41
- package/dist/meteor/mongo/live_connection.d.ts +28 -28
- package/dist/meteor/mongo/live_connection.js +264 -264
- package/dist/meteor/mongo/live_cursor.d.ts +25 -25
- package/dist/meteor/mongo/live_cursor.js +60 -60
- package/dist/meteor/mongo/minimongo_common.d.ts +84 -84
- package/dist/meteor/mongo/minimongo_common.js +1998 -1998
- package/dist/meteor/mongo/minimongo_matcher.d.ts +23 -23
- package/dist/meteor/mongo/minimongo_matcher.js +283 -283
- package/dist/meteor/mongo/minimongo_sorter.d.ts +16 -16
- package/dist/meteor/mongo/minimongo_sorter.js +268 -268
- package/dist/meteor/mongo/observe_driver_utils.d.ts +9 -9
- package/dist/meteor/mongo/observe_driver_utils.js +72 -73
- package/dist/meteor/mongo/observe_multiplexer.d.ts +46 -46
- package/dist/meteor/mongo/observe_multiplexer.js +203 -203
- package/dist/meteor/mongo/oplog-observe-driver.d.ts +68 -68
- package/dist/meteor/mongo/oplog-observe-driver.js +918 -918
- package/dist/meteor/mongo/oplog_tailing.d.ts +35 -35
- package/dist/meteor/mongo/oplog_tailing.js +352 -352
- package/dist/meteor/mongo/oplog_v2_converter.d.ts +1 -1
- package/dist/meteor/mongo/oplog_v2_converter.js +125 -126
- package/dist/meteor/mongo/polling_observe_driver.d.ts +30 -30
- package/dist/meteor/mongo/polling_observe_driver.js +216 -221
- package/dist/meteor/mongo/synchronous-cursor.d.ts +17 -17
- package/dist/meteor/mongo/synchronous-cursor.js +261 -261
- package/dist/meteor/mongo/synchronous-queue.d.ts +13 -13
- package/dist/meteor/mongo/synchronous-queue.js +110 -110
- package/dist/meteor/ordered-dict/ordered_dict.d.ts +31 -31
- package/dist/meteor/ordered-dict/ordered_dict.js +198 -198
- package/dist/meteor/random/AbstractRandomGenerator.d.ts +42 -42
- package/dist/meteor/random/AbstractRandomGenerator.js +92 -92
- package/dist/meteor/random/AleaRandomGenerator.d.ts +13 -13
- package/dist/meteor/random/AleaRandomGenerator.js +90 -90
- package/dist/meteor/random/NodeRandomGenerator.d.ts +16 -16
- package/dist/meteor/random/NodeRandomGenerator.js +42 -42
- package/dist/meteor/random/createAleaGenerator.d.ts +2 -2
- package/dist/meteor/random/createAleaGenerator.js +32 -32
- package/dist/meteor/random/createRandom.d.ts +1 -1
- package/dist/meteor/random/createRandom.js +22 -22
- package/dist/meteor/random/main.d.ts +1 -1
- package/dist/meteor/random/main.js +12 -12
- package/dist/meteor/types.d.ts +1 -1
- package/dist/meteor/types.js +2 -2
- package/package.json +5 -5
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Hook = void 0;
|
|
4
|
-
const hasOwn = Object.prototype.hasOwnProperty;
|
|
5
|
-
class Hook {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
options = options || {};
|
|
8
|
-
this.nextCallbackId = 0;
|
|
9
|
-
this.callbacks = Object.create(null);
|
|
10
|
-
// Whether to wrap callbacks with Meteor.bindEnvironment
|
|
11
|
-
if (options.exceptionHandler) {
|
|
12
|
-
this.exceptionHandler = options.exceptionHandler;
|
|
13
|
-
}
|
|
14
|
-
else if (options.debugPrintExceptions) {
|
|
15
|
-
if (typeof options.debugPrintExceptions !== "string") {
|
|
16
|
-
throw new Error("Hook option debugPrintExceptions should be a string");
|
|
17
|
-
}
|
|
18
|
-
this.exceptionHandler = options.debugPrintExceptions;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
register(callback) {
|
|
22
|
-
var exceptionHandler = this.exceptionHandler || function (exception) {
|
|
23
|
-
// Note: this relies on the undocumented fact that if bindEnvironment's
|
|
24
|
-
// onException throws, and you are invoking the callback either in the
|
|
25
|
-
// browser or from within a Fiber in Node, the exception is propagated.
|
|
26
|
-
throw exception;
|
|
27
|
-
};
|
|
28
|
-
callback = dontBindEnvironment(callback, exceptionHandler);
|
|
29
|
-
var id = this.nextCallbackId++;
|
|
30
|
-
this.callbacks[id] = callback;
|
|
31
|
-
return {
|
|
32
|
-
callback,
|
|
33
|
-
stop: () => {
|
|
34
|
-
delete this.callbacks[id];
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
// For each registered callback, call the passed iterator function
|
|
39
|
-
// with the callback.
|
|
40
|
-
//
|
|
41
|
-
// The iterator function can choose whether or not to call the
|
|
42
|
-
// callback. (For example, it might not call the callback if the
|
|
43
|
-
// observed object has been closed or terminated).
|
|
44
|
-
//
|
|
45
|
-
// The iteration is stopped if the iterator function returns a falsy
|
|
46
|
-
// value or throws an exception.
|
|
47
|
-
each(iterator) {
|
|
48
|
-
var ids = Object.keys(this.callbacks);
|
|
49
|
-
for (var i = 0; i < ids.length; ++i) {
|
|
50
|
-
var id = ids[i];
|
|
51
|
-
// check to see if the callback was removed during iteration
|
|
52
|
-
if (hasOwn.call(this.callbacks, id)) {
|
|
53
|
-
var callback = this.callbacks[id];
|
|
54
|
-
if (!iterator(callback)) {
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.Hook = Hook;
|
|
62
|
-
function dontBindEnvironment(func, onException, _this) {
|
|
63
|
-
if (!onException || typeof (onException) === 'string') {
|
|
64
|
-
var description = onException || "callback of async function";
|
|
65
|
-
onException = function (error) {
|
|
66
|
-
console.error("Exception in " + description, error);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return function (...args) {
|
|
70
|
-
try {
|
|
71
|
-
var ret = func.apply(_this, args);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
onException(e);
|
|
75
|
-
}
|
|
76
|
-
return ret;
|
|
77
|
-
};
|
|
78
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Hook = void 0;
|
|
4
|
+
const hasOwn = Object.prototype.hasOwnProperty;
|
|
5
|
+
class Hook {
|
|
6
|
+
constructor(options) {
|
|
7
|
+
options = options || {};
|
|
8
|
+
this.nextCallbackId = 0;
|
|
9
|
+
this.callbacks = Object.create(null);
|
|
10
|
+
// Whether to wrap callbacks with Meteor.bindEnvironment
|
|
11
|
+
if (options.exceptionHandler) {
|
|
12
|
+
this.exceptionHandler = options.exceptionHandler;
|
|
13
|
+
}
|
|
14
|
+
else if (options.debugPrintExceptions) {
|
|
15
|
+
if (typeof options.debugPrintExceptions !== "string") {
|
|
16
|
+
throw new Error("Hook option debugPrintExceptions should be a string");
|
|
17
|
+
}
|
|
18
|
+
this.exceptionHandler = options.debugPrintExceptions;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
register(callback) {
|
|
22
|
+
var exceptionHandler = this.exceptionHandler || function (exception) {
|
|
23
|
+
// Note: this relies on the undocumented fact that if bindEnvironment's
|
|
24
|
+
// onException throws, and you are invoking the callback either in the
|
|
25
|
+
// browser or from within a Fiber in Node, the exception is propagated.
|
|
26
|
+
throw exception;
|
|
27
|
+
};
|
|
28
|
+
callback = dontBindEnvironment(callback, exceptionHandler);
|
|
29
|
+
var id = this.nextCallbackId++;
|
|
30
|
+
this.callbacks[id] = callback;
|
|
31
|
+
return {
|
|
32
|
+
callback,
|
|
33
|
+
stop: () => {
|
|
34
|
+
delete this.callbacks[id];
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// For each registered callback, call the passed iterator function
|
|
39
|
+
// with the callback.
|
|
40
|
+
//
|
|
41
|
+
// The iterator function can choose whether or not to call the
|
|
42
|
+
// callback. (For example, it might not call the callback if the
|
|
43
|
+
// observed object has been closed or terminated).
|
|
44
|
+
//
|
|
45
|
+
// The iteration is stopped if the iterator function returns a falsy
|
|
46
|
+
// value or throws an exception.
|
|
47
|
+
each(iterator) {
|
|
48
|
+
var ids = Object.keys(this.callbacks);
|
|
49
|
+
for (var i = 0; i < ids.length; ++i) {
|
|
50
|
+
var id = ids[i];
|
|
51
|
+
// check to see if the callback was removed during iteration
|
|
52
|
+
if (hasOwn.call(this.callbacks, id)) {
|
|
53
|
+
var callback = this.callbacks[id];
|
|
54
|
+
if (!iterator(callback)) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Hook = Hook;
|
|
62
|
+
function dontBindEnvironment(func, onException, _this) {
|
|
63
|
+
if (!onException || typeof (onException) === 'string') {
|
|
64
|
+
var description = onException || "callback of async function";
|
|
65
|
+
onException = function (error) {
|
|
66
|
+
console.error("Exception in " + description, error);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return function (...args) {
|
|
70
|
+
try {
|
|
71
|
+
var ret = func.apply(_this, args);
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
onException(e);
|
|
75
|
+
}
|
|
76
|
+
return ret;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export declare class _Crossbar {
|
|
2
|
-
private listenersByCollection;
|
|
3
|
-
private listenersByCollectionCount;
|
|
4
|
-
private nextId;
|
|
5
|
-
constructor(options: any);
|
|
6
|
-
_collectionForMessage(msg: {
|
|
7
|
-
collection?: any;
|
|
8
|
-
}): string;
|
|
9
|
-
listen(trigger: any, callback: any): {
|
|
10
|
-
stop: () => void;
|
|
11
|
-
};
|
|
12
|
-
fire(notification: Record<string, any>): void;
|
|
13
|
-
_matches(notification: Record<string, any>, trigger: Record<string, any>): boolean;
|
|
14
|
-
}
|
|
15
|
-
export declare const _InvalidationCrossbar: _Crossbar;
|
|
1
|
+
export declare class _Crossbar {
|
|
2
|
+
private listenersByCollection;
|
|
3
|
+
private listenersByCollectionCount;
|
|
4
|
+
private nextId;
|
|
5
|
+
constructor(options: any);
|
|
6
|
+
_collectionForMessage(msg: {
|
|
7
|
+
collection?: any;
|
|
8
|
+
}): string;
|
|
9
|
+
listen(trigger: any, callback: any): {
|
|
10
|
+
stop: () => void;
|
|
11
|
+
};
|
|
12
|
+
fire(notification: Record<string, any>): void;
|
|
13
|
+
_matches(notification: Record<string, any>, trigger: Record<string, any>): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const _InvalidationCrossbar: _Crossbar;
|
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._InvalidationCrossbar = exports._Crossbar = void 0;
|
|
4
|
-
const ejson_1 = require("../ejson/ejson");
|
|
5
|
-
// A "crossbar" is a class that provides structured notification registration.
|
|
6
|
-
// See _match for the definition of how a notification matches a trigger.
|
|
7
|
-
// All notifications and triggers must have a string key named 'collection'.
|
|
8
|
-
class _Crossbar {
|
|
9
|
-
constructor(options) {
|
|
10
|
-
this.listenersByCollection = {};
|
|
11
|
-
this.listenersByCollectionCount = {};
|
|
12
|
-
options = options || {};
|
|
13
|
-
this.nextId = 1;
|
|
14
|
-
}
|
|
15
|
-
// msg is a trigger or a notification
|
|
16
|
-
_collectionForMessage(msg) {
|
|
17
|
-
if (!msg.hasOwnProperty('collection')) {
|
|
18
|
-
return '';
|
|
19
|
-
}
|
|
20
|
-
else if (typeof (msg.collection) === 'string') {
|
|
21
|
-
if (msg.collection === '')
|
|
22
|
-
throw Error("Message has empty collection!");
|
|
23
|
-
return msg.collection;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw Error("Message has non-string collection!");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
// Listen for notification that match 'trigger'. A notification
|
|
30
|
-
// matches if it has the key-value pairs in trigger as a
|
|
31
|
-
// subset. When a notification matches, call 'callback', passing
|
|
32
|
-
// the actual notification.
|
|
33
|
-
//
|
|
34
|
-
// Returns a listen handle, which is an object with a method
|
|
35
|
-
// stop(). Call stop() to stop listening.
|
|
36
|
-
//
|
|
37
|
-
// XXX It should be legal to call fire() from inside a listen()
|
|
38
|
-
// callback?
|
|
39
|
-
listen(trigger, callback) {
|
|
40
|
-
var self = this;
|
|
41
|
-
var id = self.nextId++;
|
|
42
|
-
var collection = self._collectionForMessage(trigger);
|
|
43
|
-
var record = { trigger: (0, ejson_1.clone)(trigger), callback: callback };
|
|
44
|
-
if (!self.listenersByCollection.hasOwnProperty(collection)) {
|
|
45
|
-
self.listenersByCollection[collection] = {};
|
|
46
|
-
self.listenersByCollectionCount[collection] = 0;
|
|
47
|
-
}
|
|
48
|
-
self.listenersByCollection[collection][id] = record;
|
|
49
|
-
self.listenersByCollectionCount[collection]++;
|
|
50
|
-
return {
|
|
51
|
-
stop: function () {
|
|
52
|
-
delete self.listenersByCollection[collection][id];
|
|
53
|
-
self.listenersByCollectionCount[collection]--;
|
|
54
|
-
if (self.listenersByCollectionCount[collection] === 0) {
|
|
55
|
-
delete self.listenersByCollection[collection];
|
|
56
|
-
delete self.listenersByCollectionCount[collection];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
// Fire the provided 'notification' (an object whose attribute
|
|
62
|
-
// values are all JSON-compatibile) -- inform all matching listeners
|
|
63
|
-
// (registered with listen()).
|
|
64
|
-
//
|
|
65
|
-
// If fire() is called inside a write fence, then each of the
|
|
66
|
-
// listener callbacks will be called inside the write fence as well.
|
|
67
|
-
//
|
|
68
|
-
// The listeners may be invoked in parallel, rather than serially.
|
|
69
|
-
fire(notification) {
|
|
70
|
-
var self = this;
|
|
71
|
-
var collection = self._collectionForMessage(notification);
|
|
72
|
-
if (!self.listenersByCollection.hasOwnProperty(collection)) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
var listenersForCollection = self.listenersByCollection[collection];
|
|
76
|
-
var callbackIds = [];
|
|
77
|
-
Object.entries(listenersForCollection).forEach(function ([id, l]) {
|
|
78
|
-
if (self._matches(notification, l.trigger)) {
|
|
79
|
-
callbackIds.push(id);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
// Listener callbacks can yield, so we need to first find all the ones that
|
|
83
|
-
// match in a single iteration over self.listenersByCollection (which can't
|
|
84
|
-
// be mutated during this iteration), and then invoke the matching
|
|
85
|
-
// callbacks, checking before each call to ensure they haven't stopped.
|
|
86
|
-
// Note that we don't have to check that
|
|
87
|
-
// self.listenersByCollection[collection] still === listenersForCollection,
|
|
88
|
-
// because the only way that stops being true is if listenersForCollection
|
|
89
|
-
// first gets reduced down to the empty object (and then never gets
|
|
90
|
-
// increased again).
|
|
91
|
-
for (const id of callbackIds) {
|
|
92
|
-
if (listenersForCollection.hasOwnProperty(id)) {
|
|
93
|
-
listenersForCollection[id].callback(notification);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
// A notification matches a trigger if all keys that exist in both are equal.
|
|
98
|
-
//
|
|
99
|
-
// Examples:
|
|
100
|
-
// N:{collection: "C"} matches T:{collection: "C"}
|
|
101
|
-
// (a non-targeted write to a collection matches a
|
|
102
|
-
// non-targeted query)
|
|
103
|
-
// N:{collection: "C", id: "X"} matches T:{collection: "C"}
|
|
104
|
-
// (a targeted write to a collection matches a non-targeted query)
|
|
105
|
-
// N:{collection: "C"} matches T:{collection: "C", id: "X"}
|
|
106
|
-
// (a non-targeted write to a collection matches a
|
|
107
|
-
// targeted query)
|
|
108
|
-
// N:{collection: "C", id: "X"} matches T:{collection: "C", id: "X"}
|
|
109
|
-
// (a targeted write to a collection matches a targeted query targeted
|
|
110
|
-
// at the same document)
|
|
111
|
-
// N:{collection: "C", id: "X"} does not match T:{collection: "C", id: "Y"}
|
|
112
|
-
// (a targeted write to a collection does not match a targeted query
|
|
113
|
-
// targeted at a different document)
|
|
114
|
-
_matches(notification, trigger) {
|
|
115
|
-
// Most notifications that use the crossbar have a string `collection` and
|
|
116
|
-
// maybe an `id` that is a string or ObjectID. We're already dividing up
|
|
117
|
-
// triggers by collection, but let's fast-track "nope, different ID" (and
|
|
118
|
-
// avoid the overly generic EJSON.equals). This makes a noticeable
|
|
119
|
-
// performance difference; see https://github.com/meteor/meteor/pull/3697
|
|
120
|
-
if (typeof (notification.id) === 'string' && typeof (trigger.id) === 'string' && notification.id !== trigger.id) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
return Object.entries(trigger).every(([key, triggerValue]) => {
|
|
124
|
-
return !notification.hasOwnProperty(key) || (0, ejson_1.equals)(triggerValue, notification[key]);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports._Crossbar = _Crossbar;
|
|
129
|
-
// The "invalidation crossbar" is a specific instance used by the DDP server to
|
|
130
|
-
// implement write fence notifications. Listener callbacks on this crossbar
|
|
131
|
-
// should call beginWrite on the current write fence before they return, if they
|
|
132
|
-
// want to delay the write fence from firing (ie, the DDP method-data-updated
|
|
133
|
-
// message from being sent).
|
|
134
|
-
exports._InvalidationCrossbar = new _Crossbar({
|
|
135
|
-
factName: "invalidation-crossbar-listeners"
|
|
136
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._InvalidationCrossbar = exports._Crossbar = void 0;
|
|
4
|
+
const ejson_1 = require("../ejson/ejson");
|
|
5
|
+
// A "crossbar" is a class that provides structured notification registration.
|
|
6
|
+
// See _match for the definition of how a notification matches a trigger.
|
|
7
|
+
// All notifications and triggers must have a string key named 'collection'.
|
|
8
|
+
class _Crossbar {
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.listenersByCollection = {};
|
|
11
|
+
this.listenersByCollectionCount = {};
|
|
12
|
+
options = options || {};
|
|
13
|
+
this.nextId = 1;
|
|
14
|
+
}
|
|
15
|
+
// msg is a trigger or a notification
|
|
16
|
+
_collectionForMessage(msg) {
|
|
17
|
+
if (!msg.hasOwnProperty('collection')) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
else if (typeof (msg.collection) === 'string') {
|
|
21
|
+
if (msg.collection === '')
|
|
22
|
+
throw Error("Message has empty collection!");
|
|
23
|
+
return msg.collection;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw Error("Message has non-string collection!");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Listen for notification that match 'trigger'. A notification
|
|
30
|
+
// matches if it has the key-value pairs in trigger as a
|
|
31
|
+
// subset. When a notification matches, call 'callback', passing
|
|
32
|
+
// the actual notification.
|
|
33
|
+
//
|
|
34
|
+
// Returns a listen handle, which is an object with a method
|
|
35
|
+
// stop(). Call stop() to stop listening.
|
|
36
|
+
//
|
|
37
|
+
// XXX It should be legal to call fire() from inside a listen()
|
|
38
|
+
// callback?
|
|
39
|
+
listen(trigger, callback) {
|
|
40
|
+
var self = this;
|
|
41
|
+
var id = self.nextId++;
|
|
42
|
+
var collection = self._collectionForMessage(trigger);
|
|
43
|
+
var record = { trigger: (0, ejson_1.clone)(trigger), callback: callback };
|
|
44
|
+
if (!self.listenersByCollection.hasOwnProperty(collection)) {
|
|
45
|
+
self.listenersByCollection[collection] = {};
|
|
46
|
+
self.listenersByCollectionCount[collection] = 0;
|
|
47
|
+
}
|
|
48
|
+
self.listenersByCollection[collection][id] = record;
|
|
49
|
+
self.listenersByCollectionCount[collection]++;
|
|
50
|
+
return {
|
|
51
|
+
stop: function () {
|
|
52
|
+
delete self.listenersByCollection[collection][id];
|
|
53
|
+
self.listenersByCollectionCount[collection]--;
|
|
54
|
+
if (self.listenersByCollectionCount[collection] === 0) {
|
|
55
|
+
delete self.listenersByCollection[collection];
|
|
56
|
+
delete self.listenersByCollectionCount[collection];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
// Fire the provided 'notification' (an object whose attribute
|
|
62
|
+
// values are all JSON-compatibile) -- inform all matching listeners
|
|
63
|
+
// (registered with listen()).
|
|
64
|
+
//
|
|
65
|
+
// If fire() is called inside a write fence, then each of the
|
|
66
|
+
// listener callbacks will be called inside the write fence as well.
|
|
67
|
+
//
|
|
68
|
+
// The listeners may be invoked in parallel, rather than serially.
|
|
69
|
+
fire(notification) {
|
|
70
|
+
var self = this;
|
|
71
|
+
var collection = self._collectionForMessage(notification);
|
|
72
|
+
if (!self.listenersByCollection.hasOwnProperty(collection)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
var listenersForCollection = self.listenersByCollection[collection];
|
|
76
|
+
var callbackIds = [];
|
|
77
|
+
Object.entries(listenersForCollection).forEach(function ([id, l]) {
|
|
78
|
+
if (self._matches(notification, l.trigger)) {
|
|
79
|
+
callbackIds.push(id);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
// Listener callbacks can yield, so we need to first find all the ones that
|
|
83
|
+
// match in a single iteration over self.listenersByCollection (which can't
|
|
84
|
+
// be mutated during this iteration), and then invoke the matching
|
|
85
|
+
// callbacks, checking before each call to ensure they haven't stopped.
|
|
86
|
+
// Note that we don't have to check that
|
|
87
|
+
// self.listenersByCollection[collection] still === listenersForCollection,
|
|
88
|
+
// because the only way that stops being true is if listenersForCollection
|
|
89
|
+
// first gets reduced down to the empty object (and then never gets
|
|
90
|
+
// increased again).
|
|
91
|
+
for (const id of callbackIds) {
|
|
92
|
+
if (listenersForCollection.hasOwnProperty(id)) {
|
|
93
|
+
listenersForCollection[id].callback(notification);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
// A notification matches a trigger if all keys that exist in both are equal.
|
|
98
|
+
//
|
|
99
|
+
// Examples:
|
|
100
|
+
// N:{collection: "C"} matches T:{collection: "C"}
|
|
101
|
+
// (a non-targeted write to a collection matches a
|
|
102
|
+
// non-targeted query)
|
|
103
|
+
// N:{collection: "C", id: "X"} matches T:{collection: "C"}
|
|
104
|
+
// (a targeted write to a collection matches a non-targeted query)
|
|
105
|
+
// N:{collection: "C"} matches T:{collection: "C", id: "X"}
|
|
106
|
+
// (a non-targeted write to a collection matches a
|
|
107
|
+
// targeted query)
|
|
108
|
+
// N:{collection: "C", id: "X"} matches T:{collection: "C", id: "X"}
|
|
109
|
+
// (a targeted write to a collection matches a targeted query targeted
|
|
110
|
+
// at the same document)
|
|
111
|
+
// N:{collection: "C", id: "X"} does not match T:{collection: "C", id: "Y"}
|
|
112
|
+
// (a targeted write to a collection does not match a targeted query
|
|
113
|
+
// targeted at a different document)
|
|
114
|
+
_matches(notification, trigger) {
|
|
115
|
+
// Most notifications that use the crossbar have a string `collection` and
|
|
116
|
+
// maybe an `id` that is a string or ObjectID. We're already dividing up
|
|
117
|
+
// triggers by collection, but let's fast-track "nope, different ID" (and
|
|
118
|
+
// avoid the overly generic EJSON.equals). This makes a noticeable
|
|
119
|
+
// performance difference; see https://github.com/meteor/meteor/pull/3697
|
|
120
|
+
if (typeof (notification.id) === 'string' && typeof (trigger.id) === 'string' && notification.id !== trigger.id) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
return Object.entries(trigger).every(([key, triggerValue]) => {
|
|
124
|
+
return !notification.hasOwnProperty(key) || (0, ejson_1.equals)(triggerValue, notification[key]);
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports._Crossbar = _Crossbar;
|
|
129
|
+
// The "invalidation crossbar" is a specific instance used by the DDP server to
|
|
130
|
+
// implement write fence notifications. Listener callbacks on this crossbar
|
|
131
|
+
// should call beginWrite on the current write fence before they return, if they
|
|
132
|
+
// want to delay the write fence from firing (ie, the DDP method-data-updated
|
|
133
|
+
// message from being sent).
|
|
134
|
+
exports._InvalidationCrossbar = new _Crossbar({
|
|
135
|
+
factName: "invalidation-crossbar-listeners"
|
|
136
|
+
});
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
export declare class Heartbeat {
|
|
2
|
-
private heartbeatInterval;
|
|
3
|
-
private heartbeatTimeout;
|
|
4
|
-
private _sendPing;
|
|
5
|
-
private _onTimeout;
|
|
6
|
-
private _seenPacket;
|
|
7
|
-
private _heartbeatIntervalHandle;
|
|
8
|
-
private _heartbeatTimeoutHandle;
|
|
9
|
-
constructor(options: any);
|
|
10
|
-
stop(): void;
|
|
11
|
-
start(): void;
|
|
12
|
-
_startHeartbeatIntervalTimer(): void;
|
|
13
|
-
_startHeartbeatTimeoutTimer(): void;
|
|
14
|
-
_clearHeartbeatIntervalTimer(): void;
|
|
15
|
-
_clearHeartbeatTimeoutTimer(): void;
|
|
16
|
-
_heartbeatIntervalFired(): void;
|
|
17
|
-
_heartbeatTimeoutFired(): void;
|
|
18
|
-
messageReceived(): void;
|
|
19
|
-
}
|
|
1
|
+
export declare class Heartbeat {
|
|
2
|
+
private heartbeatInterval;
|
|
3
|
+
private heartbeatTimeout;
|
|
4
|
+
private _sendPing;
|
|
5
|
+
private _onTimeout;
|
|
6
|
+
private _seenPacket;
|
|
7
|
+
private _heartbeatIntervalHandle;
|
|
8
|
+
private _heartbeatTimeoutHandle;
|
|
9
|
+
constructor(options: any);
|
|
10
|
+
stop(): void;
|
|
11
|
+
start(): void;
|
|
12
|
+
_startHeartbeatIntervalTimer(): void;
|
|
13
|
+
_startHeartbeatTimeoutTimer(): void;
|
|
14
|
+
_clearHeartbeatIntervalTimer(): void;
|
|
15
|
+
_clearHeartbeatTimeoutTimer(): void;
|
|
16
|
+
_heartbeatIntervalFired(): void;
|
|
17
|
+
_heartbeatTimeoutFired(): void;
|
|
18
|
+
messageReceived(): void;
|
|
19
|
+
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Heartbeat options:
|
|
3
|
-
// heartbeatInterval: interval to send pings, in milliseconds.
|
|
4
|
-
// heartbeatTimeout: timeout to close the connection if a reply isn't
|
|
5
|
-
// received, in milliseconds.
|
|
6
|
-
// sendPing: function to call to send a ping on the connection.
|
|
7
|
-
// onTimeout: function to call to close the connection.
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.Heartbeat = void 0;
|
|
10
|
-
class Heartbeat {
|
|
11
|
-
constructor(options) {
|
|
12
|
-
this.heartbeatInterval = options.heartbeatInterval;
|
|
13
|
-
this.heartbeatTimeout = options.heartbeatTimeout;
|
|
14
|
-
this._sendPing = options.sendPing;
|
|
15
|
-
this._onTimeout = options.onTimeout;
|
|
16
|
-
this._seenPacket = false;
|
|
17
|
-
this._heartbeatIntervalHandle = null;
|
|
18
|
-
this._heartbeatTimeoutHandle = null;
|
|
19
|
-
}
|
|
20
|
-
stop() {
|
|
21
|
-
this._clearHeartbeatIntervalTimer();
|
|
22
|
-
this._clearHeartbeatTimeoutTimer();
|
|
23
|
-
}
|
|
24
|
-
start() {
|
|
25
|
-
this.stop();
|
|
26
|
-
this._startHeartbeatIntervalTimer();
|
|
27
|
-
}
|
|
28
|
-
_startHeartbeatIntervalTimer() {
|
|
29
|
-
this._heartbeatIntervalHandle = setInterval(() => this._heartbeatIntervalFired(), this.heartbeatInterval);
|
|
30
|
-
}
|
|
31
|
-
_startHeartbeatTimeoutTimer() {
|
|
32
|
-
this._heartbeatTimeoutHandle = setTimeout(() => this._heartbeatTimeoutFired(), this.heartbeatTimeout);
|
|
33
|
-
}
|
|
34
|
-
_clearHeartbeatIntervalTimer() {
|
|
35
|
-
if (this._heartbeatIntervalHandle) {
|
|
36
|
-
clearInterval(this._heartbeatIntervalHandle);
|
|
37
|
-
this._heartbeatIntervalHandle = null;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
_clearHeartbeatTimeoutTimer() {
|
|
41
|
-
if (this._heartbeatTimeoutHandle) {
|
|
42
|
-
clearTimeout(this._heartbeatTimeoutHandle);
|
|
43
|
-
this._heartbeatTimeoutHandle = null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
// The heartbeat interval timer is fired when we should send a ping.
|
|
47
|
-
_heartbeatIntervalFired() {
|
|
48
|
-
// don't send ping if we've seen a packet since we last checked,
|
|
49
|
-
// *or* if we have already sent a ping and are awaiting a timeout.
|
|
50
|
-
// That shouldn't happen, but it's possible if
|
|
51
|
-
// `this.heartbeatInterval` is smaller than
|
|
52
|
-
// `this.heartbeatTimeout`.
|
|
53
|
-
if (!this._seenPacket && !this._heartbeatTimeoutHandle) {
|
|
54
|
-
this._sendPing();
|
|
55
|
-
// Set up timeout, in case a pong doesn't arrive in time.
|
|
56
|
-
this._startHeartbeatTimeoutTimer();
|
|
57
|
-
}
|
|
58
|
-
this._seenPacket = false;
|
|
59
|
-
}
|
|
60
|
-
// The heartbeat timeout timer is fired when we sent a ping, but we
|
|
61
|
-
// timed out waiting for the pong.
|
|
62
|
-
_heartbeatTimeoutFired() {
|
|
63
|
-
this._heartbeatTimeoutHandle = null;
|
|
64
|
-
this._onTimeout();
|
|
65
|
-
}
|
|
66
|
-
messageReceived() {
|
|
67
|
-
// Tell periodic checkin that we have seen a packet, and thus it
|
|
68
|
-
// does not need to send a ping this cycle.
|
|
69
|
-
this._seenPacket = true;
|
|
70
|
-
// If we were waiting for a pong, we got it.
|
|
71
|
-
if (this._heartbeatTimeoutHandle) {
|
|
72
|
-
this._clearHeartbeatTimeoutTimer();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.Heartbeat = Heartbeat;
|
|
77
|
-
;
|
|
1
|
+
"use strict";
|
|
2
|
+
// Heartbeat options:
|
|
3
|
+
// heartbeatInterval: interval to send pings, in milliseconds.
|
|
4
|
+
// heartbeatTimeout: timeout to close the connection if a reply isn't
|
|
5
|
+
// received, in milliseconds.
|
|
6
|
+
// sendPing: function to call to send a ping on the connection.
|
|
7
|
+
// onTimeout: function to call to close the connection.
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Heartbeat = void 0;
|
|
10
|
+
class Heartbeat {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.heartbeatInterval = options.heartbeatInterval;
|
|
13
|
+
this.heartbeatTimeout = options.heartbeatTimeout;
|
|
14
|
+
this._sendPing = options.sendPing;
|
|
15
|
+
this._onTimeout = options.onTimeout;
|
|
16
|
+
this._seenPacket = false;
|
|
17
|
+
this._heartbeatIntervalHandle = null;
|
|
18
|
+
this._heartbeatTimeoutHandle = null;
|
|
19
|
+
}
|
|
20
|
+
stop() {
|
|
21
|
+
this._clearHeartbeatIntervalTimer();
|
|
22
|
+
this._clearHeartbeatTimeoutTimer();
|
|
23
|
+
}
|
|
24
|
+
start() {
|
|
25
|
+
this.stop();
|
|
26
|
+
this._startHeartbeatIntervalTimer();
|
|
27
|
+
}
|
|
28
|
+
_startHeartbeatIntervalTimer() {
|
|
29
|
+
this._heartbeatIntervalHandle = setInterval(() => this._heartbeatIntervalFired(), this.heartbeatInterval);
|
|
30
|
+
}
|
|
31
|
+
_startHeartbeatTimeoutTimer() {
|
|
32
|
+
this._heartbeatTimeoutHandle = setTimeout(() => this._heartbeatTimeoutFired(), this.heartbeatTimeout);
|
|
33
|
+
}
|
|
34
|
+
_clearHeartbeatIntervalTimer() {
|
|
35
|
+
if (this._heartbeatIntervalHandle) {
|
|
36
|
+
clearInterval(this._heartbeatIntervalHandle);
|
|
37
|
+
this._heartbeatIntervalHandle = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
_clearHeartbeatTimeoutTimer() {
|
|
41
|
+
if (this._heartbeatTimeoutHandle) {
|
|
42
|
+
clearTimeout(this._heartbeatTimeoutHandle);
|
|
43
|
+
this._heartbeatTimeoutHandle = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// The heartbeat interval timer is fired when we should send a ping.
|
|
47
|
+
_heartbeatIntervalFired() {
|
|
48
|
+
// don't send ping if we've seen a packet since we last checked,
|
|
49
|
+
// *or* if we have already sent a ping and are awaiting a timeout.
|
|
50
|
+
// That shouldn't happen, but it's possible if
|
|
51
|
+
// `this.heartbeatInterval` is smaller than
|
|
52
|
+
// `this.heartbeatTimeout`.
|
|
53
|
+
if (!this._seenPacket && !this._heartbeatTimeoutHandle) {
|
|
54
|
+
this._sendPing();
|
|
55
|
+
// Set up timeout, in case a pong doesn't arrive in time.
|
|
56
|
+
this._startHeartbeatTimeoutTimer();
|
|
57
|
+
}
|
|
58
|
+
this._seenPacket = false;
|
|
59
|
+
}
|
|
60
|
+
// The heartbeat timeout timer is fired when we sent a ping, but we
|
|
61
|
+
// timed out waiting for the pong.
|
|
62
|
+
_heartbeatTimeoutFired() {
|
|
63
|
+
this._heartbeatTimeoutHandle = null;
|
|
64
|
+
this._onTimeout();
|
|
65
|
+
}
|
|
66
|
+
messageReceived() {
|
|
67
|
+
// Tell periodic checkin that we have seen a packet, and thus it
|
|
68
|
+
// does not need to send a ping this cycle.
|
|
69
|
+
this._seenPacket = true;
|
|
70
|
+
// If we were waiting for a pong, we got it.
|
|
71
|
+
if (this._heartbeatTimeoutHandle) {
|
|
72
|
+
this._clearHeartbeatTimeoutTimer();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Heartbeat = Heartbeat;
|
|
77
|
+
;
|