mongodb-livedata-server 0.0.4 → 0.0.6

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.
Files changed (93) hide show
  1. package/{livedata_server.ts → dist/livedata_server.d.ts} +1 -1
  2. package/dist/livedata_server.js +3 -1
  3. package/dist/meteor/binary-heap/max_heap.d.ts +31 -0
  4. package/dist/meteor/binary-heap/min_heap.d.ts +6 -0
  5. package/dist/meteor/binary-heap/min_max_heap.d.ts +11 -0
  6. package/dist/meteor/callback-hook/hook.d.ts +11 -0
  7. package/dist/meteor/ddp/crossbar.d.ts +15 -0
  8. package/dist/meteor/ddp/heartbeat.d.ts +19 -0
  9. package/dist/meteor/ddp/livedata_server.d.ts +141 -0
  10. package/dist/meteor/ddp/method-invocation.d.ts +25 -0
  11. package/dist/meteor/ddp/random-stream.d.ts +8 -0
  12. package/dist/meteor/ddp/session-collection-view.d.ts +27 -0
  13. package/dist/meteor/ddp/session-document-view.d.ts +8 -0
  14. package/dist/meteor/ddp/session.d.ts +69 -0
  15. package/dist/meteor/ddp/stream_server.d.ts +21 -0
  16. package/dist/meteor/ddp/subscription.d.ts +89 -0
  17. package/dist/meteor/ddp/utils.d.ts +8 -0
  18. package/dist/meteor/ddp/writefence.d.ts +20 -0
  19. package/dist/meteor/diff-sequence/diff.d.ts +13 -0
  20. package/dist/meteor/ejson/ejson.d.ts +82 -0
  21. package/dist/meteor/ejson/stringify.d.ts +2 -0
  22. package/dist/meteor/ejson/utils.d.ts +12 -0
  23. package/dist/meteor/id-map/id_map.d.ts +16 -0
  24. package/dist/meteor/mongo/caching_change_observer.d.ts +16 -0
  25. package/dist/meteor/mongo/doc_fetcher.d.ts +7 -0
  26. package/dist/meteor/mongo/geojson_utils.d.ts +3 -0
  27. package/dist/meteor/mongo/live_connection.d.ts +27 -0
  28. package/dist/meteor/mongo/live_cursor.d.ts +25 -0
  29. package/dist/meteor/mongo/minimongo_common.d.ts +84 -0
  30. package/dist/meteor/mongo/minimongo_matcher.d.ts +22 -0
  31. package/dist/meteor/mongo/minimongo_sorter.d.ts +16 -0
  32. package/dist/meteor/mongo/observe_driver_utils.d.ts +9 -0
  33. package/dist/meteor/mongo/observe_multiplexer.d.ts +36 -0
  34. package/dist/meteor/mongo/oplog-observe-driver.d.ts +67 -0
  35. package/dist/meteor/mongo/oplog_tailing.d.ts +35 -0
  36. package/dist/meteor/mongo/oplog_v2_converter.d.ts +1 -0
  37. package/dist/meteor/mongo/polling_observe_driver.d.ts +30 -0
  38. package/dist/meteor/mongo/synchronous-cursor.d.ts +17 -0
  39. package/dist/meteor/mongo/synchronous-queue.d.ts +14 -0
  40. package/dist/meteor/ordered-dict/ordered_dict.d.ts +31 -0
  41. package/dist/meteor/random/AbstractRandomGenerator.d.ts +42 -0
  42. package/dist/meteor/random/AleaRandomGenerator.d.ts +13 -0
  43. package/dist/meteor/random/NodeRandomGenerator.d.ts +16 -0
  44. package/dist/meteor/random/createAleaGenerator.d.ts +2 -0
  45. package/dist/meteor/random/createRandom.d.ts +1 -0
  46. package/dist/meteor/random/main.d.ts +1 -0
  47. package/package.json +2 -2
  48. package/meteor/LICENSE +0 -28
  49. package/meteor/binary-heap/max_heap.ts +0 -225
  50. package/meteor/binary-heap/min_heap.ts +0 -15
  51. package/meteor/binary-heap/min_max_heap.ts +0 -53
  52. package/meteor/callback-hook/hook.ts +0 -85
  53. package/meteor/ddp/crossbar.ts +0 -148
  54. package/meteor/ddp/heartbeat.ts +0 -97
  55. package/meteor/ddp/livedata_server.ts +0 -474
  56. package/meteor/ddp/method-invocation.ts +0 -86
  57. package/meteor/ddp/random-stream.ts +0 -102
  58. package/meteor/ddp/session-collection-view.ts +0 -119
  59. package/meteor/ddp/session-document-view.ts +0 -92
  60. package/meteor/ddp/session.ts +0 -708
  61. package/meteor/ddp/stream_server.ts +0 -204
  62. package/meteor/ddp/subscription.ts +0 -392
  63. package/meteor/ddp/utils.ts +0 -119
  64. package/meteor/ddp/writefence.ts +0 -130
  65. package/meteor/diff-sequence/diff.ts +0 -295
  66. package/meteor/ejson/ejson.ts +0 -601
  67. package/meteor/ejson/stringify.ts +0 -122
  68. package/meteor/ejson/utils.ts +0 -38
  69. package/meteor/id-map/id_map.ts +0 -84
  70. package/meteor/mongo/caching_change_observer.ts +0 -120
  71. package/meteor/mongo/doc_fetcher.ts +0 -52
  72. package/meteor/mongo/geojson_utils.ts +0 -42
  73. package/meteor/mongo/live_connection.ts +0 -302
  74. package/meteor/mongo/live_cursor.ts +0 -79
  75. package/meteor/mongo/minimongo_common.ts +0 -2440
  76. package/meteor/mongo/minimongo_matcher.ts +0 -275
  77. package/meteor/mongo/minimongo_sorter.ts +0 -331
  78. package/meteor/mongo/observe_driver_utils.ts +0 -79
  79. package/meteor/mongo/observe_multiplexer.ts +0 -256
  80. package/meteor/mongo/oplog-observe-driver.ts +0 -1049
  81. package/meteor/mongo/oplog_tailing.ts +0 -414
  82. package/meteor/mongo/oplog_v2_converter.ts +0 -124
  83. package/meteor/mongo/polling_observe_driver.ts +0 -247
  84. package/meteor/mongo/synchronous-cursor.ts +0 -293
  85. package/meteor/mongo/synchronous-queue.ts +0 -119
  86. package/meteor/ordered-dict/ordered_dict.ts +0 -229
  87. package/meteor/random/AbstractRandomGenerator.ts +0 -99
  88. package/meteor/random/AleaRandomGenerator.ts +0 -96
  89. package/meteor/random/NodeRandomGenerator.ts +0 -37
  90. package/meteor/random/createAleaGenerator.ts +0 -31
  91. package/meteor/random/createRandom.ts +0 -19
  92. package/meteor/random/main.ts +0 -8
  93. package/tsconfig.json +0 -10
@@ -1,225 +0,0 @@
1
- export interface MaxHeapOptions {
2
- initData?: {id: string, value: any}[],
3
- IdMap?: any
4
- }
5
-
6
- // Constructor of Heap
7
- // - comparator - Function - given two items returns a number
8
- // - options:
9
- // - initData - Array - Optional - the initial data in a format:
10
- // Object:
11
- // - id - String - unique id of the item
12
- // - value - Any - the data value
13
- // each value is retained
14
- // - IdMap - Constructor - Optional - custom IdMap class to store id->index
15
- // mappings internally. Standard IdMap is used by default.
16
- export class MaxHeap {
17
- protected _comparator: (a: any, b: any) => number;
18
- protected _heap: any[];
19
- private _heapIdx: any;
20
- constructor(comparator: (a: any, b: any) => number, options: MaxHeapOptions = {}) {
21
- if (typeof comparator !== 'function') {
22
- throw new Error('Passed comparator is invalid, should be a comparison function');
23
- }
24
-
25
- // a C-style comparator that is given two values and returns a number,
26
- // negative if the first value is less than the second, positive if the second
27
- // value is greater than the first and zero if they are equal.
28
- this._comparator = comparator;
29
-
30
- if (!options.IdMap) {
31
- options.IdMap = Map;
32
- }
33
-
34
- // _heapIdx maps an id to an index in the Heap array the corresponding value
35
- // is located on.
36
- this._heapIdx = new options.IdMap;
37
-
38
- // The Heap data-structure implemented as a 0-based contiguous array where
39
- // every item on index idx is a node in a complete binary tree. Every node can
40
- // have children on indexes idx*2+1 and idx*2+2, except for the leaves. Every
41
- // node has a parent on index (idx-1)/2;
42
- this._heap = [];
43
-
44
- // If the initial array is passed, we can build the heap in linear time
45
- // complexity (O(N)) compared to linearithmic time complexity (O(nlogn)) if
46
- // we push elements one by one.
47
- if (Array.isArray(options.initData)) {
48
- this._initFromData(options.initData);
49
- }
50
- }
51
-
52
- // Builds a new heap in-place in linear time based on passed data
53
- _initFromData(data) {
54
- this._heap = data.map(({ id, value }) => ({ id, value }));
55
-
56
- data.forEach(({ id }, i) => this._heapIdx.set(id, i));
57
-
58
- if (!data.length) {
59
- return;
60
- }
61
-
62
- // start from the first non-leaf - the parent of the last leaf
63
- for (let i = parentIdx(data.length - 1); i >= 0; i--) {
64
- this._downHeap(i);
65
- }
66
- }
67
-
68
- _downHeap(idx) {
69
- while (leftChildIdx(idx) < this.size()) {
70
- const left = leftChildIdx(idx);
71
- const right = rightChildIdx(idx);
72
- let largest = idx;
73
-
74
- if (left < this.size()) {
75
- largest = this._maxIndex(largest, left);
76
- }
77
-
78
- if (right < this.size()) {
79
- largest = this._maxIndex(largest, right);
80
- }
81
-
82
- if (largest === idx) {
83
- break;
84
- }
85
-
86
- this._swap(largest, idx);
87
- idx = largest;
88
- }
89
- }
90
-
91
- _upHeap(idx) {
92
- while (idx > 0) {
93
- const parent = parentIdx(idx);
94
- if (this._maxIndex(parent, idx) === idx) {
95
- this._swap(parent, idx)
96
- idx = parent;
97
- } else {
98
- break;
99
- }
100
- }
101
- }
102
-
103
- _maxIndex(idxA, idxB) {
104
- const valueA = this._get(idxA);
105
- const valueB = this._get(idxB);
106
- return this._comparator(valueA, valueB) >= 0 ? idxA : idxB;
107
- }
108
-
109
- // Internal: gets raw data object placed on idxth place in heap
110
- _get(idx) {
111
- return this._heap[idx].value;
112
- }
113
-
114
- _swap(idxA, idxB) {
115
- const recA = this._heap[idxA];
116
- const recB = this._heap[idxB];
117
-
118
- this._heapIdx.set(recA.id, idxB);
119
- this._heapIdx.set(recB.id, idxA);
120
-
121
- this._heap[idxA] = recB;
122
- this._heap[idxB] = recA;
123
- }
124
-
125
- get(id) {
126
- return this.has(id) ?
127
- this._get(this._heapIdx.get(id)) :
128
- null;
129
- }
130
-
131
- set(id, value) {
132
- if (this.has(id)) {
133
- if (this.get(id) === value) {
134
- return;
135
- }
136
-
137
- const idx = this._heapIdx.get(id);
138
- this._heap[idx].value = value;
139
-
140
- // Fix the new value's position
141
- // Either bubble new value up if it is greater than its parent
142
- this._upHeap(idx);
143
- // or bubble it down if it is smaller than one of its children
144
- this._downHeap(idx);
145
- } else {
146
- this._heapIdx.set(id, this._heap.length);
147
- this._heap.push({ id, value });
148
- this._upHeap(this._heap.length - 1);
149
- }
150
- }
151
-
152
- remove(id) {
153
- if (this.has(id)) {
154
- const last = this._heap.length - 1;
155
- const idx = this._heapIdx.get(id);
156
-
157
- if (idx !== last) {
158
- this._swap(idx, last);
159
- this._heap.pop();
160
- this._heapIdx.remove(id);
161
-
162
- // Fix the swapped value's position
163
- this._upHeap(idx);
164
- this._downHeap(idx);
165
- } else {
166
- this._heap.pop();
167
- this._heapIdx.remove(id);
168
- }
169
- }
170
- }
171
-
172
- has(id) {
173
- return this._heapIdx.has(id);
174
- }
175
-
176
- empty() {
177
- return !this.size();
178
- }
179
-
180
- clear() {
181
- this._heap = [];
182
- this._heapIdx.clear();
183
- }
184
-
185
- // iterate over values in no particular order
186
- forEach(iterator) {
187
- this._heap.forEach(obj => iterator(obj.value, obj.id));
188
- }
189
-
190
- size() {
191
- return this._heap.length;
192
- }
193
-
194
- setDefault(id, def) {
195
- if (this.has(id)) {
196
- return this.get(id);
197
- }
198
-
199
- this.set(id, def);
200
- return def;
201
- }
202
-
203
- clone() {
204
- const clone = new MaxHeap(this._comparator, { initData: this._heap });
205
- return clone;
206
- }
207
-
208
- maxElementId() {
209
- return this.size() ? this._heap[0].id : null;
210
- }
211
-
212
- _selfCheck() {
213
- for (let i = 1; i < this._heap.length; i++) {
214
- if (this._maxIndex(parentIdx(i), i) !== parentIdx(i)) {
215
- throw new Error(`An item with id ${this._heap[i].id}` +
216
- " has a parent younger than it: " +
217
- this._heap[parentIdx(i)].id);
218
- }
219
- }
220
- }
221
- }
222
-
223
- const leftChildIdx = i => i * 2 + 1;
224
- const rightChildIdx = i => i * 2 + 2;
225
- const parentIdx = i => (i - 1) >> 1;
@@ -1,15 +0,0 @@
1
- import { MaxHeap, MaxHeapOptions } from './max_heap';
2
-
3
- export class MinHeap extends MaxHeap {
4
- constructor(comparator, options?: MaxHeapOptions) {
5
- super((a, b) => -comparator(a, b), options);
6
- }
7
-
8
- maxElementId() {
9
- throw new Error("Cannot call maxElementId on MinHeap");
10
- }
11
-
12
- minElementId() {
13
- return super.maxElementId();
14
- }
15
- };
@@ -1,53 +0,0 @@
1
- import { MaxHeap, MaxHeapOptions } from './max_heap';
2
- import { MinHeap } from './min_heap';
3
-
4
- // This implementation of Min/Max-Heap is just a subclass of Max-Heap
5
- // with a Min-Heap as an encapsulated property.
6
- //
7
- // Most of the operations are just proxy methods to call the same method on both
8
- // heaps.
9
- //
10
- // This implementation takes 2*N memory but is fairly simple to write and
11
- // understand. And the constant factor of a simple Heap is usually smaller
12
- // compared to other two-way priority queues like Min/Max Heaps
13
- // (http://www.cs.otago.ac.nz/staffpriv/mike/Papers/MinMaxHeaps/MinMaxHeaps.pdf)
14
- // and Interval Heaps
15
- // (http://www.cise.ufl.edu/~sahni/dsaac/enrich/c13/double.htm)
16
- export class MinMaxHeap extends MaxHeap {
17
- private _minHeap: MinHeap;
18
-
19
- constructor(comparator, options?: MaxHeapOptions) {
20
- super(comparator, options);
21
- this._minHeap = new MinHeap(comparator, options);
22
- }
23
-
24
- set(id: string, value: any) {
25
- super.set(id, value);
26
- this._minHeap.set(id, value);
27
- }
28
-
29
- remove(id: string) {
30
- super.remove(id);
31
- this._minHeap.remove(id);
32
- }
33
-
34
- clear() {
35
- super.clear();
36
- this._minHeap.clear();
37
- }
38
-
39
- setDefault(id: string, def: any) {
40
- super.setDefault(id, def);
41
- return this._minHeap.setDefault(id, def);
42
- }
43
-
44
- clone() {
45
- const clone = new MinMaxHeap(this._comparator, { initData: this._heap });
46
- return clone;
47
- }
48
-
49
- minElementId() {
50
- return this._minHeap.minElementId();
51
- }
52
-
53
- };
@@ -1,85 +0,0 @@
1
- const hasOwn = Object.prototype.hasOwnProperty;
2
-
3
- export class Hook {
4
- private nextCallbackId: number;
5
- private callbacks: Record<string, Function>;
6
- private exceptionHandler: Function;
7
-
8
- constructor(options?) {
9
- options = options || {};
10
- this.nextCallbackId = 0;
11
- this.callbacks = Object.create(null);
12
- // Whether to wrap callbacks with Meteor.bindEnvironment
13
-
14
- if (options.exceptionHandler) {
15
- this.exceptionHandler = options.exceptionHandler;
16
- } else if (options.debugPrintExceptions) {
17
- if (typeof options.debugPrintExceptions !== "string") {
18
- throw new Error("Hook option debugPrintExceptions should be a string");
19
- }
20
- this.exceptionHandler = options.debugPrintExceptions;
21
- }
22
- }
23
-
24
- register(callback) {
25
- var exceptionHandler = this.exceptionHandler || function (exception) {
26
- // Note: this relies on the undocumented fact that if bindEnvironment's
27
- // onException throws, and you are invoking the callback either in the
28
- // browser or from within a Fiber in Node, the exception is propagated.
29
- throw exception;
30
- };
31
-
32
- callback = dontBindEnvironment(callback, exceptionHandler);
33
-
34
- var id = this.nextCallbackId++;
35
- this.callbacks[id] = callback;
36
-
37
- return {
38
- callback,
39
- stop: () => {
40
- delete this.callbacks[id];
41
- }
42
- };
43
- }
44
-
45
- // For each registered callback, call the passed iterator function
46
- // with the callback.
47
- //
48
- // The iterator function can choose whether or not to call the
49
- // callback. (For example, it might not call the callback if the
50
- // observed object has been closed or terminated).
51
- //
52
- // The iteration is stopped if the iterator function returns a falsy
53
- // value or throws an exception.
54
- each(iterator: (callback: Function) => boolean) {
55
- var ids = Object.keys(this.callbacks);
56
- for (var i = 0; i < ids.length; ++i) {
57
- var id = ids[i];
58
- // check to see if the callback was removed during iteration
59
- if (hasOwn.call(this.callbacks, id)) {
60
- var callback = this.callbacks[id];
61
- if (!iterator(callback)) {
62
- break;
63
- }
64
- }
65
- }
66
- }
67
- }
68
-
69
- function dontBindEnvironment(func, onException, _this?) {
70
- if (!onException || typeof (onException) === 'string') {
71
- var description = onException || "callback of async function";
72
- onException = function (error) {
73
- console.error("Exception in " + description, error);
74
- };
75
- }
76
-
77
- return function (...args) {
78
- try {
79
- var ret = func.apply(_this, args);
80
- } catch (e) {
81
- onException(e);
82
- }
83
- return ret;
84
- };
85
- }
@@ -1,148 +0,0 @@
1
- import { clone, equals } from "../ejson/ejson";
2
-
3
- // A "crossbar" is a class that provides structured notification registration.
4
- // See _match for the definition of how a notification matches a trigger.
5
- // All notifications and triggers must have a string key named 'collection'.
6
-
7
- export class _Crossbar {
8
- private listenersByCollection: Record<string, any> = {};
9
- private listenersByCollectionCount: Record<string, number> = {};
10
- private nextId: number;
11
-
12
- constructor(options) {
13
- options = options || {};
14
-
15
- this.nextId = 1;
16
- }
17
-
18
- // msg is a trigger or a notification
19
- _collectionForMessage(msg: { collection?: any }) {
20
- if (!msg.hasOwnProperty('collection')) {
21
- return '';
22
- } else if (typeof (msg.collection) === 'string') {
23
- if (msg.collection === '')
24
- throw Error("Message has empty collection!");
25
- return msg.collection;
26
- } else {
27
- throw Error("Message has non-string collection!");
28
- }
29
- }
30
-
31
- // Listen for notification that match 'trigger'. A notification
32
- // matches if it has the key-value pairs in trigger as a
33
- // subset. When a notification matches, call 'callback', passing
34
- // the actual notification.
35
- //
36
- // Returns a listen handle, which is an object with a method
37
- // stop(). Call stop() to stop listening.
38
- //
39
- // XXX It should be legal to call fire() from inside a listen()
40
- // callback?
41
- listen(trigger, callback) {
42
- var self = this;
43
- var id = self.nextId++;
44
-
45
- var collection = self._collectionForMessage(trigger);
46
- var record = { trigger: clone(trigger), callback: callback };
47
- if (!self.listenersByCollection.hasOwnProperty(collection)) {
48
- self.listenersByCollection[collection] = {};
49
- self.listenersByCollectionCount[collection] = 0;
50
- }
51
- self.listenersByCollection[collection][id] = record;
52
- self.listenersByCollectionCount[collection]++;
53
-
54
- return {
55
- stop: function () {
56
- delete self.listenersByCollection[collection][id];
57
- self.listenersByCollectionCount[collection]--;
58
- if (self.listenersByCollectionCount[collection] === 0) {
59
- delete self.listenersByCollection[collection];
60
- delete self.listenersByCollectionCount[collection];
61
- }
62
- }
63
- };
64
- }
65
-
66
- // Fire the provided 'notification' (an object whose attribute
67
- // values are all JSON-compatibile) -- inform all matching listeners
68
- // (registered with listen()).
69
- //
70
- // If fire() is called inside a write fence, then each of the
71
- // listener callbacks will be called inside the write fence as well.
72
- //
73
- // The listeners may be invoked in parallel, rather than serially.
74
- fire(notification: Record<string, any>) {
75
- var self = this;
76
-
77
- var collection = self._collectionForMessage(notification);
78
-
79
- if (!self.listenersByCollection.hasOwnProperty(collection)) {
80
- return;
81
- }
82
-
83
- var listenersForCollection = self.listenersByCollection[collection];
84
- var callbackIds = [];
85
- Object.entries<{ trigger: Record<string, any> }>(listenersForCollection).forEach(function ([id, l]) {
86
- if (self._matches(notification, l.trigger)) {
87
- callbackIds.push(id);
88
- }
89
- });
90
-
91
- // Listener callbacks can yield, so we need to first find all the ones that
92
- // match in a single iteration over self.listenersByCollection (which can't
93
- // be mutated during this iteration), and then invoke the matching
94
- // callbacks, checking before each call to ensure they haven't stopped.
95
- // Note that we don't have to check that
96
- // self.listenersByCollection[collection] still === listenersForCollection,
97
- // because the only way that stops being true is if listenersForCollection
98
- // first gets reduced down to the empty object (and then never gets
99
- // increased again).
100
- for (const id of callbackIds) {
101
- if (listenersForCollection.hasOwnProperty(id)) {
102
- listenersForCollection[id].callback(notification);
103
- }
104
- }
105
- }
106
-
107
- // A notification matches a trigger if all keys that exist in both are equal.
108
- //
109
- // Examples:
110
- // N:{collection: "C"} matches T:{collection: "C"}
111
- // (a non-targeted write to a collection matches a
112
- // non-targeted query)
113
- // N:{collection: "C", id: "X"} matches T:{collection: "C"}
114
- // (a targeted write to a collection matches a non-targeted query)
115
- // N:{collection: "C"} matches T:{collection: "C", id: "X"}
116
- // (a non-targeted write to a collection matches a
117
- // targeted query)
118
- // N:{collection: "C", id: "X"} matches T:{collection: "C", id: "X"}
119
- // (a targeted write to a collection matches a targeted query targeted
120
- // at the same document)
121
- // N:{collection: "C", id: "X"} does not match T:{collection: "C", id: "Y"}
122
- // (a targeted write to a collection does not match a targeted query
123
- // targeted at a different document)
124
- _matches(notification: Record<string, any>, trigger: Record<string, any>) {
125
- // Most notifications that use the crossbar have a string `collection` and
126
- // maybe an `id` that is a string or ObjectID. We're already dividing up
127
- // triggers by collection, but let's fast-track "nope, different ID" (and
128
- // avoid the overly generic EJSON.equals). This makes a noticeable
129
- // performance difference; see https://github.com/meteor/meteor/pull/3697
130
- if (typeof (notification.id) === 'string' && typeof (trigger.id) === 'string' && notification.id !== trigger.id) {
131
- return false;
132
- }
133
-
134
- return Object.entries(trigger).every(([key, triggerValue]) => {
135
- return !notification.hasOwnProperty(key) || equals(triggerValue, notification[key]);
136
- });
137
- }
138
-
139
- }
140
-
141
- // The "invalidation crossbar" is a specific instance used by the DDP server to
142
- // implement write fence notifications. Listener callbacks on this crossbar
143
- // should call beginWrite on the current write fence before they return, if they
144
- // want to delay the write fence from firing (ie, the DDP method-data-updated
145
- // message from being sent).
146
- export const _InvalidationCrossbar = new _Crossbar({
147
- factName: "invalidation-crossbar-listeners"
148
- });
@@ -1,97 +0,0 @@
1
- // Heartbeat options:
2
- // heartbeatInterval: interval to send pings, in milliseconds.
3
- // heartbeatTimeout: timeout to close the connection if a reply isn't
4
- // received, in milliseconds.
5
- // sendPing: function to call to send a ping on the connection.
6
- // onTimeout: function to call to close the connection.
7
-
8
- export class Heartbeat {
9
- private heartbeatInterval: number;
10
- private heartbeatTimeout: number;
11
- private _sendPing: Function;
12
- private _onTimeout: Function;
13
- private _seenPacket: boolean;
14
- private _heartbeatIntervalHandle: any;
15
- private _heartbeatTimeoutHandle: any;
16
-
17
- constructor(options) {
18
- this.heartbeatInterval = options.heartbeatInterval;
19
- this.heartbeatTimeout = options.heartbeatTimeout;
20
- this._sendPing = options.sendPing;
21
- this._onTimeout = options.onTimeout;
22
- this._seenPacket = false;
23
-
24
- this._heartbeatIntervalHandle = null;
25
- this._heartbeatTimeoutHandle = null;
26
- }
27
-
28
- stop() {
29
- this._clearHeartbeatIntervalTimer();
30
- this._clearHeartbeatTimeoutTimer();
31
- }
32
-
33
- start() {
34
- this.stop();
35
- this._startHeartbeatIntervalTimer();
36
- }
37
-
38
- _startHeartbeatIntervalTimer() {
39
- this._heartbeatIntervalHandle = setInterval(
40
- () => this._heartbeatIntervalFired(),
41
- this.heartbeatInterval
42
- );
43
- }
44
-
45
- _startHeartbeatTimeoutTimer() {
46
- this._heartbeatTimeoutHandle = setTimeout(
47
- () => this._heartbeatTimeoutFired(),
48
- this.heartbeatTimeout
49
- );
50
- }
51
-
52
- _clearHeartbeatIntervalTimer() {
53
- if (this._heartbeatIntervalHandle) {
54
- clearInterval(this._heartbeatIntervalHandle);
55
- this._heartbeatIntervalHandle = null;
56
- }
57
- }
58
-
59
- _clearHeartbeatTimeoutTimer() {
60
- if (this._heartbeatTimeoutHandle) {
61
- clearTimeout(this._heartbeatTimeoutHandle);
62
- this._heartbeatTimeoutHandle = null;
63
- }
64
- }
65
-
66
- // The heartbeat interval timer is fired when we should send a ping.
67
- _heartbeatIntervalFired() {
68
- // don't send ping if we've seen a packet since we last checked,
69
- // *or* if we have already sent a ping and are awaiting a timeout.
70
- // That shouldn't happen, but it's possible if
71
- // `this.heartbeatInterval` is smaller than
72
- // `this.heartbeatTimeout`.
73
- if (! this._seenPacket && ! this._heartbeatTimeoutHandle) {
74
- this._sendPing();
75
- // Set up timeout, in case a pong doesn't arrive in time.
76
- this._startHeartbeatTimeoutTimer();
77
- }
78
- this._seenPacket = false;
79
- }
80
-
81
- // The heartbeat timeout timer is fired when we sent a ping, but we
82
- // timed out waiting for the pong.
83
- _heartbeatTimeoutFired() {
84
- this._heartbeatTimeoutHandle = null;
85
- this._onTimeout();
86
- }
87
-
88
- messageReceived() {
89
- // Tell periodic checkin that we have seen a packet, and thus it
90
- // does not need to send a ping this cycle.
91
- this._seenPacket = true;
92
- // If we were waiting for a pong, we got it.
93
- if (this._heartbeatTimeoutHandle) {
94
- this._clearHeartbeatTimeoutTimer();
95
- }
96
- }
97
- };