mongodb-livedata-server 0.1.2 → 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.
Files changed (91) hide show
  1. package/dist/livedata_server.d.ts +4 -4
  2. package/dist/livedata_server.js +11 -11
  3. package/dist/meteor/binary-heap/max_heap.d.ts +31 -31
  4. package/dist/meteor/binary-heap/max_heap.js +186 -186
  5. package/dist/meteor/binary-heap/min_heap.d.ts +6 -6
  6. package/dist/meteor/binary-heap/min_heap.js +17 -17
  7. package/dist/meteor/binary-heap/min_max_heap.d.ts +11 -11
  8. package/dist/meteor/binary-heap/min_max_heap.js +48 -48
  9. package/dist/meteor/callback-hook/hook.d.ts +11 -11
  10. package/dist/meteor/callback-hook/hook.js +78 -78
  11. package/dist/meteor/ddp/crossbar.d.ts +15 -15
  12. package/dist/meteor/ddp/crossbar.js +136 -136
  13. package/dist/meteor/ddp/heartbeat.d.ts +19 -19
  14. package/dist/meteor/ddp/heartbeat.js +77 -77
  15. package/dist/meteor/ddp/livedata_server.d.ts +141 -142
  16. package/dist/meteor/ddp/livedata_server.js +403 -403
  17. package/dist/meteor/ddp/method-invocation.d.ts +35 -35
  18. package/dist/meteor/ddp/method-invocation.js +72 -72
  19. package/dist/meteor/ddp/random-stream.d.ts +8 -8
  20. package/dist/meteor/ddp/random-stream.js +100 -100
  21. package/dist/meteor/ddp/session-collection-view.d.ts +20 -20
  22. package/dist/meteor/ddp/session-collection-view.js +106 -106
  23. package/dist/meteor/ddp/session-document-view.d.ts +8 -8
  24. package/dist/meteor/ddp/session-document-view.js +82 -82
  25. package/dist/meteor/ddp/session.d.ts +75 -74
  26. package/dist/meteor/ddp/session.js +590 -589
  27. package/dist/meteor/ddp/stream_server.d.ts +20 -21
  28. package/dist/meteor/ddp/stream_server.js +181 -181
  29. package/dist/meteor/ddp/subscription.d.ts +94 -94
  30. package/dist/meteor/ddp/subscription.js +370 -370
  31. package/dist/meteor/ddp/utils.d.ts +8 -8
  32. package/dist/meteor/ddp/utils.js +104 -104
  33. package/dist/meteor/ddp/writefence.d.ts +20 -20
  34. package/dist/meteor/ddp/writefence.js +111 -111
  35. package/dist/meteor/diff-sequence/diff.d.ts +17 -17
  36. package/dist/meteor/diff-sequence/diff.js +257 -257
  37. package/dist/meteor/ejson/ejson.d.ts +82 -82
  38. package/dist/meteor/ejson/ejson.js +568 -569
  39. package/dist/meteor/ejson/stringify.d.ts +2 -2
  40. package/dist/meteor/ejson/stringify.js +119 -119
  41. package/dist/meteor/ejson/utils.d.ts +12 -12
  42. package/dist/meteor/ejson/utils.js +42 -42
  43. package/dist/meteor/mongo/caching_change_observer.d.ts +16 -16
  44. package/dist/meteor/mongo/caching_change_observer.js +63 -63
  45. package/dist/meteor/mongo/doc_fetcher.d.ts +7 -7
  46. package/dist/meteor/mongo/doc_fetcher.js +53 -53
  47. package/dist/meteor/mongo/geojson_utils.d.ts +3 -3
  48. package/dist/meteor/mongo/geojson_utils.js +40 -41
  49. package/dist/meteor/mongo/live_connection.d.ts +28 -28
  50. package/dist/meteor/mongo/live_connection.js +264 -264
  51. package/dist/meteor/mongo/live_cursor.d.ts +25 -25
  52. package/dist/meteor/mongo/live_cursor.js +60 -60
  53. package/dist/meteor/mongo/minimongo_common.d.ts +84 -84
  54. package/dist/meteor/mongo/minimongo_common.js +1998 -2002
  55. package/dist/meteor/mongo/minimongo_matcher.d.ts +23 -23
  56. package/dist/meteor/mongo/minimongo_matcher.js +283 -283
  57. package/dist/meteor/mongo/minimongo_sorter.d.ts +16 -16
  58. package/dist/meteor/mongo/minimongo_sorter.js +268 -268
  59. package/dist/meteor/mongo/observe_driver_utils.d.ts +9 -9
  60. package/dist/meteor/mongo/observe_driver_utils.js +72 -73
  61. package/dist/meteor/mongo/observe_multiplexer.d.ts +46 -46
  62. package/dist/meteor/mongo/observe_multiplexer.js +203 -203
  63. package/dist/meteor/mongo/oplog-observe-driver.d.ts +68 -68
  64. package/dist/meteor/mongo/oplog-observe-driver.js +918 -918
  65. package/dist/meteor/mongo/oplog_tailing.d.ts +35 -35
  66. package/dist/meteor/mongo/oplog_tailing.js +352 -352
  67. package/dist/meteor/mongo/oplog_v2_converter.d.ts +1 -1
  68. package/dist/meteor/mongo/oplog_v2_converter.js +125 -126
  69. package/dist/meteor/mongo/polling_observe_driver.d.ts +30 -30
  70. package/dist/meteor/mongo/polling_observe_driver.js +216 -221
  71. package/dist/meteor/mongo/synchronous-cursor.d.ts +17 -17
  72. package/dist/meteor/mongo/synchronous-cursor.js +261 -261
  73. package/dist/meteor/mongo/synchronous-queue.d.ts +13 -13
  74. package/dist/meteor/mongo/synchronous-queue.js +110 -110
  75. package/dist/meteor/ordered-dict/ordered_dict.d.ts +31 -31
  76. package/dist/meteor/ordered-dict/ordered_dict.js +198 -198
  77. package/dist/meteor/random/AbstractRandomGenerator.d.ts +42 -42
  78. package/dist/meteor/random/AbstractRandomGenerator.js +92 -92
  79. package/dist/meteor/random/AleaRandomGenerator.d.ts +13 -13
  80. package/dist/meteor/random/AleaRandomGenerator.js +90 -90
  81. package/dist/meteor/random/NodeRandomGenerator.d.ts +16 -16
  82. package/dist/meteor/random/NodeRandomGenerator.js +42 -42
  83. package/dist/meteor/random/createAleaGenerator.d.ts +2 -2
  84. package/dist/meteor/random/createAleaGenerator.js +32 -32
  85. package/dist/meteor/random/createRandom.d.ts +1 -1
  86. package/dist/meteor/random/createRandom.js +22 -22
  87. package/dist/meteor/random/main.d.ts +1 -1
  88. package/dist/meteor/random/main.js +12 -12
  89. package/dist/meteor/types.d.ts +1 -1
  90. package/dist/meteor/types.js +2 -2
  91. package/package.json +6 -5
@@ -1,221 +1,216 @@
1
- "use strict";
2
- var __asyncValues = (this && this.__asyncValues) || function (o) {
3
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
- var m = o[Symbol.asyncIterator], i;
5
- 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);
6
- 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); }); }; }
7
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.PollingObserveDriver = void 0;
11
- const writefence_1 = require("../ddp/writefence");
12
- const diff_1 = require("../diff-sequence/diff");
13
- const synchronous_queue_1 = require("./synchronous-queue");
14
- const observe_driver_utils_1 = require("./observe_driver_utils");
15
- var POLLING_THROTTLE_MS = +process.env.METEOR_POLLING_THROTTLE_MS || 50;
16
- var POLLING_INTERVAL_MS = +process.env.METEOR_POLLING_INTERVAL_MS || 10 * 1000;
17
- class PollingObserveDriver {
18
- constructor(options) {
19
- var self = this;
20
- self._cursorDescription = options.cursorDescription;
21
- self._mongoHandle = options.mongoHandle;
22
- self._ordered = options.ordered;
23
- self._multiplexer = options.multiplexer;
24
- self._stopCallbacks = [];
25
- self._stopped = false;
26
- // previous results snapshot. on each poll cycle, diffs against
27
- // results drives the callbacks.
28
- self._results = null;
29
- // The number of _pollMongo calls that have been added to self._taskQueue but
30
- // have not started running. Used to make sure we never schedule more than one
31
- // _pollMongo (other than possibly the one that is currently running). It's
32
- // also used by _suspendPolling to pretend there's a poll scheduled. Usually,
33
- // it's either 0 (for "no polls scheduled other than maybe one currently
34
- // running") or 1 (for "a poll scheduled that isn't running yet"), but it can
35
- // also be 2 if incremented by _suspendPolling.
36
- self._pollsScheduledButNotStarted = 0;
37
- self._pendingWrites = []; // people to notify when polling completes
38
- // Make sure to create a separately throttled function for each
39
- // PollingObserveDriver object.
40
- self._ensurePollIsScheduled = throttle(self._unthrottledEnsurePollIsScheduled, self._cursorDescription.options.pollingThrottleMs || POLLING_THROTTLE_MS /* ms */);
41
- // XXX figure out if we still need a queue
42
- self._taskQueue = new synchronous_queue_1._SynchronousQueue();
43
- var listenersHandle = (0, observe_driver_utils_1.listenAll)(self._cursorDescription, function (notification) {
44
- // When someone does a transaction that might affect us, schedule a poll
45
- // of the database. If that transaction happens inside of a write fence,
46
- // block the fence until we've polled and notified observers.
47
- var fence = writefence_1._WriteFence._CurrentWriteFence;
48
- if (fence)
49
- self._pendingWrites.push(fence.beginWrite());
50
- // Ensure a poll is scheduled... but if we already know that one is,
51
- // don't hit the throttled _ensurePollIsScheduled function (which might
52
- // lead to us calling it unnecessarily in <pollingThrottleMs> ms).
53
- if (self._pollsScheduledButNotStarted === 0)
54
- self._ensurePollIsScheduled();
55
- });
56
- self._stopCallbacks.push(function () { listenersHandle.stop(); });
57
- // every once and a while, poll even if we don't think we're dirty, for
58
- // eventual consistency with database writes from outside the Meteor
59
- // universe.
60
- var pollingInterval = self._cursorDescription.options.pollingIntervalMs || POLLING_INTERVAL_MS;
61
- var intervalHandle = setInterval(() => self._ensurePollIsScheduled(), pollingInterval);
62
- self._stopCallbacks.push(function () {
63
- clearInterval(intervalHandle);
64
- });
65
- // Make sure we actually poll soon!
66
- self._unthrottledEnsurePollIsScheduled();
67
- }
68
- ;
69
- // This is always called through _.throttle (except once at startup).
70
- _unthrottledEnsurePollIsScheduled() {
71
- var self = this;
72
- if (self._pollsScheduledButNotStarted > 0)
73
- return;
74
- ++self._pollsScheduledButNotStarted;
75
- self._taskQueue.queueTask(async () => await self._pollMongo());
76
- }
77
- async _pollMongo() {
78
- var _a, e_1, _b, _c;
79
- var self = this;
80
- --self._pollsScheduledButNotStarted;
81
- if (self._stopped)
82
- return;
83
- var first = false;
84
- var newResults;
85
- var oldResults = self._results;
86
- if (!oldResults) {
87
- first = true;
88
- // XXX maybe use OrderedDict instead?
89
- oldResults = self._ordered ? [] : new Map();
90
- }
91
- // Save the list of pending writes which this round will commit.
92
- var writesForCycle = self._pendingWrites;
93
- self._pendingWrites = [];
94
- // Get the new query results. (This yields.)
95
- try {
96
- const cursor = self._mongoHandle.db.collection(self._cursorDescription.collectionName).find(self._cursorDescription.selector);
97
- if (!self._ordered) {
98
- newResults = new Map();
99
- try {
100
- for (var _d = true, cursor_1 = __asyncValues(cursor), cursor_1_1; cursor_1_1 = await cursor_1.next(), _a = cursor_1_1.done, !_a;) {
101
- _c = cursor_1_1.value;
102
- _d = false;
103
- try {
104
- const doc = _c;
105
- newResults.set(doc._id, doc);
106
- }
107
- finally {
108
- _d = true;
109
- }
110
- }
111
- }
112
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
113
- finally {
114
- try {
115
- if (!_d && !_a && (_b = cursor_1.return)) await _b.call(cursor_1);
116
- }
117
- finally { if (e_1) throw e_1.error; }
118
- }
119
- }
120
- else
121
- newResults = await cursor.toArray();
122
- }
123
- catch (e) {
124
- if (first && typeof (e.code) === 'number') {
125
- // This is an error document sent to us by mongod, not a connection
126
- // error generated by the client. And we've never seen this query work
127
- // successfully. Probably it's a bad selector or something, so we should
128
- // NOT retry. Instead, we should halt the observe (which ends up calling
129
- // `stop` on us).
130
- self._multiplexer.queryError(new Error("Exception while polling query " +
131
- JSON.stringify(self._cursorDescription) + ": " + e.message));
132
- return;
133
- }
134
- // getRawObjects can throw if we're having trouble talking to the
135
- // database. That's fine --- we will repoll later anyway. But we should
136
- // make sure not to lose track of this cycle's writes.
137
- // (It also can throw if there's just something invalid about this query;
138
- // unfortunately the ObserveDriver API doesn't provide a good way to
139
- // "cancel" the observe from the inside in this case.
140
- Array.prototype.push.apply(self._pendingWrites, writesForCycle);
141
- console.warn("Exception while polling query " + JSON.stringify(self._cursorDescription), e);
142
- return;
143
- }
144
- // Run diffs.
145
- // This will trigger the callbacks via the multiplexer
146
- if (!self._stopped) {
147
- diff_1.DiffSequence.diffQueryChanges(self._ordered, oldResults, newResults, self._multiplexer);
148
- }
149
- // Signals the multiplexer to allow all observeChanges calls that share this
150
- // multiplexer to return. (This happens asynchronously, via the
151
- // multiplexer's queue.)
152
- if (first)
153
- self._multiplexer.ready();
154
- // Replace self._results atomically. (This assignment is what makes `first`
155
- // stay through on the next cycle, so we've waited until after we've
156
- // committed to ready-ing the multiplexer.)
157
- self._results = newResults;
158
- // Once the ObserveMultiplexer has processed everything we've done in this
159
- // round, mark all the writes which existed before this call as
160
- // commmitted. (If new writes have shown up in the meantime, there'll
161
- // already be another _pollMongo task scheduled.)
162
- self._multiplexer.onFlush(function () {
163
- for (const w of writesForCycle) {
164
- w.committed();
165
- }
166
- });
167
- }
168
- stop() {
169
- var self = this;
170
- self._stopped = true;
171
- for (const c of self._stopCallbacks) {
172
- c();
173
- }
174
- // Release any write fences that are waiting on us.
175
- for (const w of self._pendingWrites) {
176
- w.committed();
177
- }
178
- }
179
- }
180
- exports.PollingObserveDriver = PollingObserveDriver;
181
- function throttle(func, wait, options) {
182
- var timeout, context, args, result;
183
- var previous = 0;
184
- if (!options)
185
- options = {};
186
- var later = function () {
187
- previous = options.leading === false ? 0 : Date.now();
188
- timeout = null;
189
- result = func.apply(context, args);
190
- if (!timeout)
191
- context = args = null;
192
- };
193
- var throttled = function () {
194
- var _now = Date.now();
195
- if (!previous && options.leading === false)
196
- previous = _now;
197
- var remaining = wait - (_now - previous);
198
- context = this;
199
- args = arguments;
200
- if (remaining <= 0 || remaining > wait) {
201
- if (timeout) {
202
- clearTimeout(timeout);
203
- timeout = null;
204
- }
205
- previous = _now;
206
- result = func.apply(context, args);
207
- if (!timeout)
208
- context = args = null;
209
- }
210
- else if (!timeout && options.trailing !== false) {
211
- timeout = setTimeout(later, remaining);
212
- }
213
- return result;
214
- };
215
- throttled.cancel = function () {
216
- clearTimeout(timeout);
217
- previous = 0;
218
- timeout = context = args = null;
219
- };
220
- return throttled;
221
- }
1
+ "use strict";
2
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
3
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
4
+ var m = o[Symbol.asyncIterator], i;
5
+ 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);
6
+ 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); }); }; }
7
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PollingObserveDriver = void 0;
11
+ const writefence_1 = require("../ddp/writefence");
12
+ const diff_1 = require("../diff-sequence/diff");
13
+ const synchronous_queue_1 = require("./synchronous-queue");
14
+ const observe_driver_utils_1 = require("./observe_driver_utils");
15
+ var POLLING_THROTTLE_MS = +process.env.METEOR_POLLING_THROTTLE_MS || 50;
16
+ var POLLING_INTERVAL_MS = +process.env.METEOR_POLLING_INTERVAL_MS || 10 * 1000;
17
+ class PollingObserveDriver {
18
+ constructor(options) {
19
+ var self = this;
20
+ self._cursorDescription = options.cursorDescription;
21
+ self._mongoHandle = options.mongoHandle;
22
+ self._ordered = options.ordered;
23
+ self._multiplexer = options.multiplexer;
24
+ self._stopCallbacks = [];
25
+ self._stopped = false;
26
+ // previous results snapshot. on each poll cycle, diffs against
27
+ // results drives the callbacks.
28
+ self._results = null;
29
+ // The number of _pollMongo calls that have been added to self._taskQueue but
30
+ // have not started running. Used to make sure we never schedule more than one
31
+ // _pollMongo (other than possibly the one that is currently running). It's
32
+ // also used by _suspendPolling to pretend there's a poll scheduled. Usually,
33
+ // it's either 0 (for "no polls scheduled other than maybe one currently
34
+ // running") or 1 (for "a poll scheduled that isn't running yet"), but it can
35
+ // also be 2 if incremented by _suspendPolling.
36
+ self._pollsScheduledButNotStarted = 0;
37
+ self._pendingWrites = []; // people to notify when polling completes
38
+ // Make sure to create a separately throttled function for each
39
+ // PollingObserveDriver object.
40
+ self._ensurePollIsScheduled = throttle(self._unthrottledEnsurePollIsScheduled, self._cursorDescription.options.pollingThrottleMs || POLLING_THROTTLE_MS /* ms */);
41
+ // XXX figure out if we still need a queue
42
+ self._taskQueue = new synchronous_queue_1._SynchronousQueue();
43
+ var listenersHandle = (0, observe_driver_utils_1.listenAll)(self._cursorDescription, function (notification) {
44
+ // When someone does a transaction that might affect us, schedule a poll
45
+ // of the database. If that transaction happens inside of a write fence,
46
+ // block the fence until we've polled and notified observers.
47
+ var fence = writefence_1._WriteFence._CurrentWriteFence;
48
+ if (fence)
49
+ self._pendingWrites.push(fence.beginWrite());
50
+ // Ensure a poll is scheduled... but if we already know that one is,
51
+ // don't hit the throttled _ensurePollIsScheduled function (which might
52
+ // lead to us calling it unnecessarily in <pollingThrottleMs> ms).
53
+ if (self._pollsScheduledButNotStarted === 0)
54
+ self._ensurePollIsScheduled();
55
+ });
56
+ self._stopCallbacks.push(function () { listenersHandle.stop(); });
57
+ // every once and a while, poll even if we don't think we're dirty, for
58
+ // eventual consistency with database writes from outside the Meteor
59
+ // universe.
60
+ var pollingInterval = self._cursorDescription.options.pollingIntervalMs || POLLING_INTERVAL_MS;
61
+ var intervalHandle = setInterval(() => self._ensurePollIsScheduled(), pollingInterval);
62
+ self._stopCallbacks.push(function () {
63
+ clearInterval(intervalHandle);
64
+ });
65
+ // Make sure we actually poll soon!
66
+ self._unthrottledEnsurePollIsScheduled();
67
+ }
68
+ ;
69
+ // This is always called through _.throttle (except once at startup).
70
+ _unthrottledEnsurePollIsScheduled() {
71
+ var self = this;
72
+ if (self._pollsScheduledButNotStarted > 0)
73
+ return;
74
+ ++self._pollsScheduledButNotStarted;
75
+ self._taskQueue.queueTask(async () => await self._pollMongo());
76
+ }
77
+ async _pollMongo() {
78
+ var _a, e_1, _b, _c;
79
+ var self = this;
80
+ --self._pollsScheduledButNotStarted;
81
+ if (self._stopped)
82
+ return;
83
+ var first = false;
84
+ var newResults;
85
+ var oldResults = self._results;
86
+ if (!oldResults) {
87
+ first = true;
88
+ // XXX maybe use OrderedDict instead?
89
+ oldResults = self._ordered ? [] : new Map();
90
+ }
91
+ // Save the list of pending writes which this round will commit.
92
+ var writesForCycle = self._pendingWrites;
93
+ self._pendingWrites = [];
94
+ // Get the new query results. (This yields.)
95
+ try {
96
+ const cursor = self._mongoHandle.db.collection(self._cursorDescription.collectionName).find(self._cursorDescription.selector);
97
+ if (!self._ordered) {
98
+ newResults = new Map();
99
+ try {
100
+ for (var _d = true, cursor_1 = __asyncValues(cursor), cursor_1_1; cursor_1_1 = await cursor_1.next(), _a = cursor_1_1.done, !_a; _d = true) {
101
+ _c = cursor_1_1.value;
102
+ _d = false;
103
+ const doc = _c;
104
+ newResults.set(doc._id, doc);
105
+ }
106
+ }
107
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
108
+ finally {
109
+ try {
110
+ if (!_d && !_a && (_b = cursor_1.return)) await _b.call(cursor_1);
111
+ }
112
+ finally { if (e_1) throw e_1.error; }
113
+ }
114
+ }
115
+ else
116
+ newResults = await cursor.toArray();
117
+ }
118
+ catch (e) {
119
+ if (first && typeof (e.code) === 'number') {
120
+ // This is an error document sent to us by mongod, not a connection
121
+ // error generated by the client. And we've never seen this query work
122
+ // successfully. Probably it's a bad selector or something, so we should
123
+ // NOT retry. Instead, we should halt the observe (which ends up calling
124
+ // `stop` on us).
125
+ self._multiplexer.queryError(new Error("Exception while polling query " +
126
+ JSON.stringify(self._cursorDescription) + ": " + e.message));
127
+ return;
128
+ }
129
+ // getRawObjects can throw if we're having trouble talking to the
130
+ // database. That's fine --- we will repoll later anyway. But we should
131
+ // make sure not to lose track of this cycle's writes.
132
+ // (It also can throw if there's just something invalid about this query;
133
+ // unfortunately the ObserveDriver API doesn't provide a good way to
134
+ // "cancel" the observe from the inside in this case.
135
+ Array.prototype.push.apply(self._pendingWrites, writesForCycle);
136
+ console.warn("Exception while polling query " + JSON.stringify(self._cursorDescription), e);
137
+ return;
138
+ }
139
+ // Run diffs.
140
+ // This will trigger the callbacks via the multiplexer
141
+ if (!self._stopped) {
142
+ diff_1.DiffSequence.diffQueryChanges(self._ordered, oldResults, newResults, self._multiplexer);
143
+ }
144
+ // Signals the multiplexer to allow all observeChanges calls that share this
145
+ // multiplexer to return. (This happens asynchronously, via the
146
+ // multiplexer's queue.)
147
+ if (first)
148
+ self._multiplexer.ready();
149
+ // Replace self._results atomically. (This assignment is what makes `first`
150
+ // stay through on the next cycle, so we've waited until after we've
151
+ // committed to ready-ing the multiplexer.)
152
+ self._results = newResults;
153
+ // Once the ObserveMultiplexer has processed everything we've done in this
154
+ // round, mark all the writes which existed before this call as
155
+ // commmitted. (If new writes have shown up in the meantime, there'll
156
+ // already be another _pollMongo task scheduled.)
157
+ self._multiplexer.onFlush(function () {
158
+ for (const w of writesForCycle) {
159
+ w.committed();
160
+ }
161
+ });
162
+ }
163
+ stop() {
164
+ var self = this;
165
+ self._stopped = true;
166
+ for (const c of self._stopCallbacks) {
167
+ c();
168
+ }
169
+ // Release any write fences that are waiting on us.
170
+ for (const w of self._pendingWrites) {
171
+ w.committed();
172
+ }
173
+ }
174
+ }
175
+ exports.PollingObserveDriver = PollingObserveDriver;
176
+ function throttle(func, wait, options) {
177
+ var timeout, context, args, result;
178
+ var previous = 0;
179
+ if (!options)
180
+ options = {};
181
+ var later = function () {
182
+ previous = options.leading === false ? 0 : Date.now();
183
+ timeout = null;
184
+ result = func.apply(context, args);
185
+ if (!timeout)
186
+ context = args = null;
187
+ };
188
+ var throttled = function () {
189
+ var _now = Date.now();
190
+ if (!previous && options.leading === false)
191
+ previous = _now;
192
+ var remaining = wait - (_now - previous);
193
+ context = this;
194
+ args = arguments;
195
+ if (remaining <= 0 || remaining > wait) {
196
+ if (timeout) {
197
+ clearTimeout(timeout);
198
+ timeout = null;
199
+ }
200
+ previous = _now;
201
+ result = func.apply(context, args);
202
+ if (!timeout)
203
+ context = args = null;
204
+ }
205
+ else if (!timeout && options.trailing !== false) {
206
+ timeout = setTimeout(later, remaining);
207
+ }
208
+ return result;
209
+ };
210
+ throttled.cancel = function () {
211
+ clearTimeout(timeout);
212
+ previous = 0;
213
+ timeout = context = args = null;
214
+ };
215
+ return throttled;
216
+ }
@@ -1,17 +1,17 @@
1
- import * as MongoDB from "mongodb";
2
- import { CursorDescription } from "./live_cursor";
3
- export declare function _createSynchronousCursor(db: MongoDB.Db, cursorDescription: CursorDescription<any>, options?: any): SynchronousCursor;
4
- export declare class SynchronousCursor {
5
- private _dbCursor;
6
- private _cursorDescription;
7
- private _transform;
8
- private _visitedIds;
9
- constructor(_dbCursor: MongoDB.FindCursor, _cursorDescription: CursorDescription<any>, options: {
10
- useTransform?: boolean;
11
- });
12
- _nextObjectPromise(): Promise<any>;
13
- _nextObjectPromiseWithTimeout(timeoutMS: number): Promise<any>;
14
- close(): void;
15
- forEach(callback: (doc: any, index: number, cursor: SynchronousCursor) => void, thisArg?: any): Promise<void>;
16
- _rewind(): void;
17
- }
1
+ import * as MongoDB from "mongodb";
2
+ import { CursorDescription } from "./live_cursor";
3
+ export declare function _createSynchronousCursor(db: MongoDB.Db, cursorDescription: CursorDescription<any>, options?: any): SynchronousCursor;
4
+ export declare class SynchronousCursor {
5
+ private _dbCursor;
6
+ private _cursorDescription;
7
+ private _transform;
8
+ private _visitedIds;
9
+ constructor(_dbCursor: MongoDB.FindCursor, _cursorDescription: CursorDescription<any>, options: {
10
+ useTransform?: boolean;
11
+ });
12
+ _nextObjectPromise(): Promise<any>;
13
+ _nextObjectPromiseWithTimeout(timeoutMS: number): Promise<any>;
14
+ close(): void;
15
+ forEach(callback: (doc: any, index: number, cursor: SynchronousCursor) => void, thisArg?: any): Promise<void>;
16
+ _rewind(): void;
17
+ }