mongodb-livedata-server 0.0.7 → 0.0.9
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/meteor/ddp/livedata_server.d.ts +2 -2
- package/dist/meteor/ddp/method-invocation.d.ts +12 -2
- package/dist/meteor/ddp/method-invocation.js +2 -2
- package/dist/meteor/ddp/session-collection-view.d.ts +2 -9
- package/dist/meteor/ddp/session-collection-view.js +4 -3
- package/dist/meteor/ddp/session.d.ts +7 -6
- package/dist/meteor/ddp/session.js +10 -7
- package/dist/meteor/ddp/subscription.d.ts +6 -3
- package/dist/meteor/ddp/subscription.js +13 -6
- package/dist/meteor/diff-sequence/diff.d.ts +9 -4
- package/dist/meteor/id-map/id_map.d.ts +1 -1
- package/dist/meteor/mongo/caching_change_observer.d.ts +2 -1
- package/dist/meteor/mongo/caching_change_observer.js +3 -2
- package/dist/meteor/mongo/live_connection.d.ts +3 -2
- package/dist/meteor/mongo/live_connection.js +2 -2
- package/dist/meteor/mongo/live_cursor.d.ts +2 -2
- package/dist/meteor/mongo/live_cursor.js +2 -2
- package/dist/meteor/mongo/observe_multiplexer.d.ts +18 -10
- package/dist/meteor/mongo/observe_multiplexer.js +10 -11
- package/dist/meteor/mongo/oplog-observe-driver.d.ts +1 -1
- package/dist/meteor/mongo/oplog-observe-driver.js +5 -5
- package/dist/meteor/mongo/synchronous-queue.d.ts +1 -2
- package/dist/meteor/ordered-dict/ordered_dict.d.ts +1 -1
- package/dist/meteor/types.d.ts +1 -0
- package/dist/meteor/types.js +2 -0
- package/package.json +2 -2
|
@@ -121,8 +121,8 @@ export declare class DDPServer {
|
|
|
121
121
|
_urlForSession(sessionId: any): string;
|
|
122
122
|
}
|
|
123
123
|
export declare function _calculateVersion(clientSupportedVersions: any, serverSupportedVersions: any): any;
|
|
124
|
-
export declare function wrapInternalException(exception: any, context:
|
|
125
|
-
export declare function maybeAuditArgumentChecks(f:
|
|
124
|
+
export declare function wrapInternalException(exception: any, context: string): any;
|
|
125
|
+
export declare function maybeAuditArgumentChecks<T>(f: (...args: any[]) => T, context: any, args: any[] | null, description: string): T;
|
|
126
126
|
export declare function ddpError(error: string | number, reason?: string, details?: string): {
|
|
127
127
|
isClientSafe: boolean;
|
|
128
128
|
error: string | number;
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import { SessionConnectionHandle } from "./session";
|
|
2
|
+
interface MethodInvocationOptions {
|
|
3
|
+
isSimulation: boolean;
|
|
4
|
+
isFromCallAsync?: boolean;
|
|
5
|
+
userId: string;
|
|
6
|
+
setUserId: (userId: string) => void;
|
|
7
|
+
connection: SessionConnectionHandle;
|
|
8
|
+
randomSeed: number;
|
|
9
|
+
}
|
|
1
10
|
/**
|
|
2
11
|
* @summary The state for a single invocation of a method, referenced by this
|
|
3
12
|
* inside a method definition.
|
|
@@ -7,13 +16,13 @@
|
|
|
7
16
|
*/
|
|
8
17
|
export declare class MethodInvocation {
|
|
9
18
|
userId: string;
|
|
10
|
-
connection:
|
|
19
|
+
connection: SessionConnectionHandle;
|
|
11
20
|
private isSimulation;
|
|
12
21
|
private _isFromCallAsync;
|
|
13
22
|
private _setUserId;
|
|
14
23
|
private randomSeed;
|
|
15
24
|
private randomStream;
|
|
16
|
-
constructor(options:
|
|
25
|
+
constructor(options: MethodInvocationOptions);
|
|
17
26
|
/**
|
|
18
27
|
* @summary Set the logged in user.
|
|
19
28
|
* @locus Server
|
|
@@ -23,3 +32,4 @@ export declare class MethodInvocation {
|
|
|
23
32
|
*/
|
|
24
33
|
setUserId(userId: string | null): void;
|
|
25
34
|
}
|
|
35
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MethodInvocation = void 0;
|
|
4
2
|
// Instance name is this because it is usually referred to as this inside a
|
|
5
3
|
// method definition
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.MethodInvocation = void 0;
|
|
6
6
|
/**
|
|
7
7
|
* @summary The state for a single invocation of a method, referenced by this
|
|
8
8
|
* inside a method definition.
|
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { SessionDocumentView } from "./session-document-view";
|
|
2
|
-
|
|
3
|
-
added: (collectionName: string, id: string, fields: Record<string, any>) => void;
|
|
4
|
-
changed: (collectionName: string, id: string, fields: Record<string, any>) => void;
|
|
5
|
-
removed: (collectionName: string, id: string) => void;
|
|
6
|
-
}
|
|
7
|
-
interface SubscriptionHandle {
|
|
8
|
-
}
|
|
2
|
+
import { SubscriptionCallbacks, SubscriptionHandle } from "./subscription";
|
|
9
3
|
/**
|
|
10
4
|
* Represents a client's view of a single collection
|
|
11
5
|
* @param {String} collectionName Name of the collection it represents
|
|
@@ -22,6 +16,5 @@ export declare class SessionCollectionView {
|
|
|
22
16
|
diffDocument(id: string, prevDV: SessionDocumentView, nowDV: SessionDocumentView): void;
|
|
23
17
|
added(subscriptionHandle: SubscriptionHandle, id: string, fields: Record<string, any>): void;
|
|
24
18
|
changed(subscriptionHandle: SubscriptionHandle, id: string, changed: Record<string, any>): void;
|
|
25
|
-
removed(subscriptionHandle:
|
|
19
|
+
removed(subscriptionHandle: SubscriptionHandle, id: string): void;
|
|
26
20
|
}
|
|
27
|
-
export {};
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.SessionCollectionView = void 0;
|
|
4
4
|
const diff_1 = require("../diff-sequence/diff");
|
|
5
5
|
const ejson_1 = require("../ejson/ejson");
|
|
6
|
+
const id_map_1 = require("../id-map/id_map");
|
|
6
7
|
const session_document_view_1 = require("./session-document-view");
|
|
7
8
|
/**
|
|
8
9
|
* Represents a client's view of a single collection
|
|
@@ -14,10 +15,10 @@ class SessionCollectionView {
|
|
|
14
15
|
constructor(collectionName, callbacks) {
|
|
15
16
|
this.collectionName = collectionName;
|
|
16
17
|
this.callbacks = callbacks;
|
|
17
|
-
this.documents = new
|
|
18
|
+
this.documents = new id_map_1.IdMap();
|
|
18
19
|
}
|
|
19
20
|
isEmpty() {
|
|
20
|
-
return this.documents.
|
|
21
|
+
return this.documents.empty();
|
|
21
22
|
}
|
|
22
23
|
diff(previous) {
|
|
23
24
|
diff_1.DiffSequence.diffMaps(previous.documents, this.documents, {
|
|
@@ -90,7 +91,7 @@ class SessionCollectionView {
|
|
|
90
91
|
if (docView.existsIn.size === 0) {
|
|
91
92
|
// it is gone from everyone
|
|
92
93
|
self.callbacks.removed(self.collectionName, id);
|
|
93
|
-
self.documents.
|
|
94
|
+
self.documents.remove(id);
|
|
94
95
|
}
|
|
95
96
|
else {
|
|
96
97
|
var changed = {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import DoubleEndedQueue from "double-ended-queue";
|
|
2
2
|
import { StreamServerSocket } from "./stream_server";
|
|
3
3
|
import { DDPServer } from "./livedata_server";
|
|
4
|
+
import { SubscriptionHandle } from "./subscription";
|
|
4
5
|
export interface SessionConnectionHandle {
|
|
5
6
|
id: string;
|
|
6
7
|
close: Function;
|
|
@@ -38,7 +39,7 @@ export declare class DDPSession {
|
|
|
38
39
|
private _respondToPings;
|
|
39
40
|
private heartbeat;
|
|
40
41
|
constructor(server: DDPServer, version: string, socket: StreamServerSocket, options: any);
|
|
41
|
-
sendReady(subscriptionIds:
|
|
42
|
+
sendReady(subscriptionIds: string[]): void;
|
|
42
43
|
_canSend(collectionName: any): boolean;
|
|
43
44
|
sendAdded(collectionName: string, id: string, fields: Record<string, any>): void;
|
|
44
45
|
sendChanged(collectionName: string, id: string, fields: Record<string, any>): void;
|
|
@@ -48,10 +49,10 @@ export declare class DDPSession {
|
|
|
48
49
|
changed: any;
|
|
49
50
|
removed: any;
|
|
50
51
|
};
|
|
51
|
-
getCollectionView(collectionName:
|
|
52
|
-
added(subscriptionHandle:
|
|
53
|
-
removed(subscriptionHandle:
|
|
54
|
-
changed(subscriptionHandle:
|
|
52
|
+
getCollectionView(collectionName: string): any;
|
|
53
|
+
added(subscriptionHandle: SubscriptionHandle, collectionName: string, id: string, fields: Record<string, any>): void;
|
|
54
|
+
removed(subscriptionHandle: SubscriptionHandle, collectionName: string, id: string): void;
|
|
55
|
+
changed(subscriptionHandle: SubscriptionHandle, collectionName: string, id: string, fields: Record<string, any>): void;
|
|
55
56
|
startUniversalSubs(): void;
|
|
56
57
|
close(): void;
|
|
57
58
|
send(msg: any): void;
|
|
@@ -61,7 +62,7 @@ export declare class DDPSession {
|
|
|
61
62
|
_eachSub(f: any): void;
|
|
62
63
|
_diffCollectionViews(beforeCVs: any): void;
|
|
63
64
|
_setUserId(userId: any): void;
|
|
64
|
-
_startSubscription(handler: any, subId?: any, params?: any, name?: any): void
|
|
65
|
+
_startSubscription(handler: any, subId?: any, params?: any, name?: any): Promise<void>;
|
|
65
66
|
_stopSubscription(subId: any, error?: any): void;
|
|
66
67
|
_deactivateAllSubscriptions(): void;
|
|
67
68
|
_clientAddress(): string;
|
|
@@ -14,6 +14,7 @@ const utils_1 = require("./utils");
|
|
|
14
14
|
const diff_1 = require("../diff-sequence/diff");
|
|
15
15
|
const session_collection_view_1 = require("./session-collection-view");
|
|
16
16
|
const subscription_1 = require("./subscription");
|
|
17
|
+
const id_map_1 = require("../id-map/id_map");
|
|
17
18
|
class DDPSession {
|
|
18
19
|
constructor(server, version, socket, options) {
|
|
19
20
|
this.protocol_handlers = {
|
|
@@ -139,6 +140,8 @@ class DDPSession {
|
|
|
139
140
|
self.send(payload);
|
|
140
141
|
}, (exception) => {
|
|
141
142
|
finish();
|
|
143
|
+
if (exception && !exception.isClientSafe)
|
|
144
|
+
console.error(`Exception while invoking method '${msg.method}'`, exception);
|
|
142
145
|
payload.error = (0, livedata_server_1.wrapInternalException)(exception, `while invoking method '${msg.method}'`);
|
|
143
146
|
self.send(payload);
|
|
144
147
|
});
|
|
@@ -158,7 +161,7 @@ class DDPSession {
|
|
|
158
161
|
self._namedSubs = new Map();
|
|
159
162
|
self._universalSubs = [];
|
|
160
163
|
self.userId = null;
|
|
161
|
-
self.collectionViews = new
|
|
164
|
+
self.collectionViews = new id_map_1.IdMap();
|
|
162
165
|
// Set this to false to not send messages when collectionViews are
|
|
163
166
|
// modified. This is done when rerunning subs in _setUserId and those messages
|
|
164
167
|
// are calculated via a diff instead.
|
|
@@ -277,7 +280,7 @@ class DDPSession {
|
|
|
277
280
|
const view = this.getCollectionView(collectionName);
|
|
278
281
|
view.removed(subscriptionHandle, id);
|
|
279
282
|
if (view.isEmpty()) {
|
|
280
|
-
this.collectionViews.
|
|
283
|
+
this.collectionViews.remove(collectionName);
|
|
281
284
|
}
|
|
282
285
|
}
|
|
283
286
|
else {
|
|
@@ -313,7 +316,7 @@ class DDPSession {
|
|
|
313
316
|
return;
|
|
314
317
|
// Drop the merge box data immediately.
|
|
315
318
|
self.inQueue = null;
|
|
316
|
-
self.collectionViews = new
|
|
319
|
+
self.collectionViews = new id_map_1.IdMap();
|
|
317
320
|
if (self.heartbeat) {
|
|
318
321
|
self.heartbeat.stop();
|
|
319
322
|
self.heartbeat = null;
|
|
@@ -454,7 +457,7 @@ class DDPSession {
|
|
|
454
457
|
// update the userId.
|
|
455
458
|
self._isSending = false;
|
|
456
459
|
var beforeCVs = self.collectionViews;
|
|
457
|
-
self.collectionViews = new
|
|
460
|
+
self.collectionViews = new id_map_1.IdMap();
|
|
458
461
|
self.userId = userId;
|
|
459
462
|
// _setUserId is normally called from a Meteor method with
|
|
460
463
|
// DDP._CurrentMethodInvocation set. But DDP._CurrentMethodInvocation is not
|
|
@@ -488,19 +491,19 @@ class DDPSession {
|
|
|
488
491
|
// this diff, so that other changes cannot interleave.
|
|
489
492
|
self._isSending = true;
|
|
490
493
|
self._diffCollectionViews(beforeCVs);
|
|
491
|
-
if (
|
|
494
|
+
if (self._pendingReady.length > 0) {
|
|
492
495
|
self.sendReady(self._pendingReady);
|
|
493
496
|
self._pendingReady = [];
|
|
494
497
|
}
|
|
495
498
|
}
|
|
496
|
-
_startSubscription(handler, subId, params, name) {
|
|
499
|
+
async _startSubscription(handler, subId, params, name) {
|
|
497
500
|
var self = this;
|
|
498
501
|
var sub = new subscription_1.Subscription(self, handler, subId, params, name);
|
|
499
502
|
if (subId)
|
|
500
503
|
self._namedSubs.set(subId, sub);
|
|
501
504
|
else
|
|
502
505
|
self._universalSubs.push(sub);
|
|
503
|
-
sub._runHandler();
|
|
506
|
+
await sub._runHandler();
|
|
504
507
|
}
|
|
505
508
|
// Tear down specified subscription
|
|
506
509
|
_stopSubscription(subId, error) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { AsyncFunction } from "../types";
|
|
1
2
|
import { DDPSession, SessionConnectionHandle } from "./session";
|
|
3
|
+
export declare type SubscriptionHandle = `N${string}` | `U${string}`;
|
|
4
|
+
export declare type SubscriptionCallbacks = Pick<Subscription, "added" | "changed" | "removed">;
|
|
2
5
|
/**
|
|
3
6
|
* @summary The server's side of a subscription
|
|
4
7
|
* @class Subscription
|
|
@@ -19,9 +22,9 @@ export declare class Subscription {
|
|
|
19
22
|
private _ready;
|
|
20
23
|
userId: string | null;
|
|
21
24
|
private _idFilter;
|
|
22
|
-
constructor(_session: DDPSession, _handler: any, _subscriptionId: string, _params?: any[], _name?: string);
|
|
23
|
-
_runHandler(): void
|
|
24
|
-
_publishHandlerResult(res: any): void
|
|
25
|
+
constructor(_session: DDPSession, _handler: (...args: any[]) => any | AsyncFunction, _subscriptionId: string, _params?: any[], _name?: string);
|
|
26
|
+
_runHandler(): Promise<void>;
|
|
27
|
+
_publishHandlerResult(res: any): Promise<void>;
|
|
25
28
|
_deactivate(): void;
|
|
26
29
|
_callStopCallbacks(): void;
|
|
27
30
|
_removeAllDocuments(): void;
|
|
@@ -68,7 +68,7 @@ class Subscription {
|
|
|
68
68
|
this.userId = this._session.userId;
|
|
69
69
|
}
|
|
70
70
|
;
|
|
71
|
-
_runHandler() {
|
|
71
|
+
async _runHandler() {
|
|
72
72
|
// XXX should we unblock() here? Either before running the publish
|
|
73
73
|
// function, or before running _publishCursor.
|
|
74
74
|
//
|
|
@@ -100,13 +100,20 @@ class Subscription {
|
|
|
100
100
|
// or thenable and will be resolved asynchronously.
|
|
101
101
|
const isThenable = resultOrThenable && typeof resultOrThenable.then === 'function';
|
|
102
102
|
if (isThenable) {
|
|
103
|
-
|
|
103
|
+
let result;
|
|
104
|
+
try {
|
|
105
|
+
result = await resultOrThenable;
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
this.error(e);
|
|
109
|
+
}
|
|
110
|
+
await this._publishHandlerResult(result);
|
|
104
111
|
}
|
|
105
112
|
else {
|
|
106
|
-
this._publishHandlerResult(resultOrThenable);
|
|
113
|
+
await this._publishHandlerResult(resultOrThenable);
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
|
-
_publishHandlerResult(res) {
|
|
116
|
+
async _publishHandlerResult(res) {
|
|
110
117
|
// SPECIAL CASE: Instead of writing their own callbacks that invoke
|
|
111
118
|
// this.added/changed/ready/etc, the user can just return a collection
|
|
112
119
|
// cursor or array of cursors from the publish function; we call their
|
|
@@ -129,7 +136,7 @@ class Subscription {
|
|
|
129
136
|
};
|
|
130
137
|
if (isCursor(res)) {
|
|
131
138
|
try {
|
|
132
|
-
res._publishCursor(self);
|
|
139
|
+
await res._publishCursor(self);
|
|
133
140
|
}
|
|
134
141
|
catch (e) {
|
|
135
142
|
self.error(e);
|
|
@@ -161,7 +168,7 @@ class Subscription {
|
|
|
161
168
|
;
|
|
162
169
|
try {
|
|
163
170
|
for (const cur of res) {
|
|
164
|
-
cur._publishCursor(self);
|
|
171
|
+
await cur._publishCursor(self);
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
174
|
catch (e) {
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { IdMap } from "../id-map/id_map";
|
|
2
|
+
interface DiffCallbacks {
|
|
3
|
+
both: (key: string, left: any, right: any) => void;
|
|
4
|
+
leftOnly: (key: string, value: any) => void;
|
|
5
|
+
rightOnly: (key: string, value: any) => void;
|
|
6
|
+
}
|
|
2
7
|
interface DiffSequence {
|
|
3
8
|
diffQueryChanges(ordered: boolean, oldResults: any[], newResults: any[], observer: any, options?: any): any;
|
|
4
9
|
diffQueryChanges(ordered: boolean, oldResults: IdMap, newResults: IdMap, observer: any, options?: any): any;
|
|
5
10
|
diffQueryUnorderedChanges(oldResults: any, newResults: any, observer: any, options?: any): any;
|
|
6
11
|
diffQueryOrderedChanges(old_results: any, new_results: any, observer: any, options?: any): any;
|
|
7
|
-
diffObjects(left:
|
|
8
|
-
diffMaps(left:
|
|
9
|
-
makeChangedFields(newDoc:
|
|
10
|
-
applyChanges(doc:
|
|
12
|
+
diffObjects(left: Record<string, any>, right: Record<string, any>, callbacks: DiffCallbacks): any;
|
|
13
|
+
diffMaps(left: IdMap, right: IdMap, callbacks: DiffCallbacks): any;
|
|
14
|
+
makeChangedFields(newDoc: Record<string, any>, oldDoc: Record<string, any>): any;
|
|
15
|
+
applyChanges(doc: Record<string, any>, changeFields: Record<string, any>): void;
|
|
11
16
|
}
|
|
12
17
|
export declare const DiffSequence: DiffSequence;
|
|
13
18
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { IdMap } from "../id-map/id_map";
|
|
1
2
|
import { OrderedDict } from "../ordered-dict/ordered_dict";
|
|
2
3
|
export declare class _CachingChangeObserver {
|
|
3
|
-
docs: OrderedDict |
|
|
4
|
+
docs: OrderedDict | IdMap;
|
|
4
5
|
applyChange: {
|
|
5
6
|
added?: (id: string, fields: any) => void;
|
|
6
7
|
changed?: (id: string, fields: any) => void;
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports._CachingChangeObserver = void 0;
|
|
10
10
|
const diff_1 = require("../diff-sequence/diff");
|
|
11
11
|
const ejson_1 = require("../ejson/ejson");
|
|
12
|
+
const id_map_1 = require("../id-map/id_map");
|
|
12
13
|
const ordered_dict_1 = require("../ordered-dict/ordered_dict");
|
|
13
14
|
// available as `this` to those callbacks.
|
|
14
15
|
class _CachingChangeObserver {
|
|
@@ -57,7 +58,7 @@ class _CachingChangeObserver {
|
|
|
57
58
|
};
|
|
58
59
|
}
|
|
59
60
|
else {
|
|
60
|
-
this.docs = new
|
|
61
|
+
this.docs = new id_map_1.IdMap();
|
|
61
62
|
this.applyChange = {
|
|
62
63
|
added: (id, fields) => {
|
|
63
64
|
// Take a shallow copy since the top-level properties can be changed
|
|
@@ -86,7 +87,7 @@ class _CachingChangeObserver {
|
|
|
86
87
|
if (callbacks.removed) {
|
|
87
88
|
callbacks.removed.call(this, id);
|
|
88
89
|
}
|
|
89
|
-
this.docs.
|
|
90
|
+
this.docs.remove(id);
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
}
|
|
@@ -2,6 +2,7 @@ import { Db } from "mongodb";
|
|
|
2
2
|
import { CursorDescription } from "./live_cursor";
|
|
3
3
|
import { OplogHandle } from "./oplog_tailing";
|
|
4
4
|
import { DocFetcher } from "./doc_fetcher";
|
|
5
|
+
import { ObserveCallbacks } from "./observe_multiplexer";
|
|
5
6
|
export declare class LiveMongoConnection {
|
|
6
7
|
private client;
|
|
7
8
|
db: Db;
|
|
@@ -14,9 +15,9 @@ export declare class LiveMongoConnection {
|
|
|
14
15
|
tail<T>(cursorDescription: CursorDescription<T>, docCallback: (doc: T) => void, timeoutMS?: number): {
|
|
15
16
|
stop: () => void;
|
|
16
17
|
};
|
|
17
|
-
_observeChanges(cursorDescription: CursorDescription<any>, ordered: boolean, callbacks:
|
|
18
|
+
_observeChanges(cursorDescription: CursorDescription<any>, ordered: boolean, callbacks: ObserveCallbacks, nonMutatingCallbacks: boolean): Promise<{
|
|
18
19
|
stop: () => void;
|
|
19
|
-
}
|
|
20
|
+
}>;
|
|
20
21
|
_observeChangesTailable(cursorDescription: CursorDescription<any>, ordered: boolean, callbacks: any): {
|
|
21
22
|
stop: () => void;
|
|
22
23
|
};
|
|
@@ -129,7 +129,7 @@ class LiveMongoConnection {
|
|
|
129
129
|
}
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
-
_observeChanges(cursorDescription, ordered, callbacks, nonMutatingCallbacks) {
|
|
132
|
+
async _observeChanges(cursorDescription, ordered, callbacks, nonMutatingCallbacks) {
|
|
133
133
|
var self = this;
|
|
134
134
|
if (cursorDescription.options.tailable) {
|
|
135
135
|
return self._observeChangesTailable(cursorDescription, ordered, callbacks);
|
|
@@ -203,7 +203,7 @@ class LiveMongoConnection {
|
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
205
|
// Blocks until the initial adds have been sent.
|
|
206
|
-
multiplexer.addHandleAndSendInitialAdds(observeHandle);
|
|
206
|
+
await multiplexer.addHandleAndSendInitialAdds(observeHandle);
|
|
207
207
|
return observeHandle;
|
|
208
208
|
}
|
|
209
209
|
// observeChanges for tailable cursors on capped collections.
|
|
@@ -18,8 +18,8 @@ export declare class LiveCursor<T> {
|
|
|
18
18
|
mongo: LiveMongoConnection;
|
|
19
19
|
cursorDescription: CursorDescription<T>;
|
|
20
20
|
constructor(mongo: LiveMongoConnection, collectionName: string, selector: MongoDB.Filter<MongoDB.WithId<T>>, options: CustomFindOptions<MongoDB.WithId<T>>);
|
|
21
|
-
_publishCursor(sub: Subscription): {
|
|
21
|
+
_publishCursor(sub: Subscription): Promise<{
|
|
22
22
|
stop: () => void;
|
|
23
|
-
}
|
|
23
|
+
}>;
|
|
24
24
|
}
|
|
25
25
|
export {};
|
|
@@ -17,8 +17,8 @@ class LiveCursor {
|
|
|
17
17
|
this.mongo = mongo;
|
|
18
18
|
this.cursorDescription = new CursorDescription(collectionName, selector, options);
|
|
19
19
|
}
|
|
20
|
-
_publishCursor(sub) {
|
|
21
|
-
const observeHandle = this.mongo._observeChanges(this.cursorDescription, false, {
|
|
20
|
+
async _publishCursor(sub) {
|
|
21
|
+
const observeHandle = await this.mongo._observeChanges(this.cursorDescription, false, {
|
|
22
22
|
added: (id, fields) => {
|
|
23
23
|
sub.added(this.cursorDescription.collectionName, id, fields);
|
|
24
24
|
},
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export interface ObserveCallbacks {
|
|
2
|
+
added: (id: string, fields: Record<string, any>) => void;
|
|
3
|
+
changed: (id: string, fields: Record<string, any>) => void;
|
|
4
|
+
removed: (id: string) => void;
|
|
5
|
+
addedBefore?: (id: string, fields: Record<string, any>, before?: any) => void;
|
|
6
|
+
movedBefore?: (id: string, fields: Record<string, any>, before?: any) => void;
|
|
7
|
+
_testOnlyPollCallback?: any;
|
|
8
|
+
}
|
|
1
9
|
export declare class ObserveMultiplexer {
|
|
2
10
|
private _ordered;
|
|
3
11
|
private _onStop;
|
|
@@ -6,9 +14,9 @@ export declare class ObserveMultiplexer {
|
|
|
6
14
|
private _readyFuture;
|
|
7
15
|
private _cache;
|
|
8
16
|
private _addHandleTasksScheduledButNotPerformed;
|
|
9
|
-
added:
|
|
10
|
-
changed:
|
|
11
|
-
removed:
|
|
17
|
+
added: ObserveCallbacks["added"];
|
|
18
|
+
changed: ObserveCallbacks["changed"];
|
|
19
|
+
removed: ObserveCallbacks["removed"];
|
|
12
20
|
constructor(options: any);
|
|
13
21
|
addHandleAndSendInitialAdds(handle: ObserveHandle): Promise<void>;
|
|
14
22
|
removeHandle(id: number): void;
|
|
@@ -18,19 +26,19 @@ export declare class ObserveMultiplexer {
|
|
|
18
26
|
onFlush(cb: any): void;
|
|
19
27
|
callbackNames(): string[];
|
|
20
28
|
_ready(): boolean;
|
|
21
|
-
_applyCallback(callbackName: string, args: any): void
|
|
29
|
+
_applyCallback(callbackName: string, args: any): Promise<void>;
|
|
22
30
|
_sendAdds(handle: ObserveHandle): void;
|
|
23
31
|
}
|
|
24
32
|
export declare class ObserveHandle {
|
|
25
33
|
private _multiplexer;
|
|
26
34
|
nonMutatingCallbacks: boolean;
|
|
27
35
|
_id: number;
|
|
28
|
-
_addedBefore:
|
|
29
|
-
_movedBefore:
|
|
30
|
-
_added:
|
|
31
|
-
_changed:
|
|
32
|
-
_removed:
|
|
36
|
+
_addedBefore: ObserveCallbacks["addedBefore"];
|
|
37
|
+
_movedBefore: ObserveCallbacks["movedBefore"];
|
|
38
|
+
_added: ObserveCallbacks["added"];
|
|
39
|
+
_changed: ObserveCallbacks["changed"];
|
|
40
|
+
_removed: ObserveCallbacks["removed"];
|
|
33
41
|
private _stopped;
|
|
34
|
-
constructor(_multiplexer: ObserveMultiplexer, callbacks:
|
|
42
|
+
constructor(_multiplexer: ObserveMultiplexer, callbacks: ObserveCallbacks, nonMutatingCallbacks?: boolean);
|
|
35
43
|
stop(): void;
|
|
36
44
|
}
|
|
@@ -35,8 +35,8 @@ class ObserveMultiplexer {
|
|
|
35
35
|
// callback.
|
|
36
36
|
self._addHandleTasksScheduledButNotPerformed = 0;
|
|
37
37
|
for (const callbackName of self.callbackNames()) {
|
|
38
|
-
self[callbackName] = function ( /* ... */) {
|
|
39
|
-
self._applyCallback(callbackName, Array.from(arguments));
|
|
38
|
+
self[callbackName] = async function ( /* ... */) {
|
|
39
|
+
await self._applyCallback(callbackName, Array.from(arguments));
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -51,7 +51,7 @@ class ObserveMultiplexer {
|
|
|
51
51
|
++self._addHandleTasksScheduledButNotPerformed;
|
|
52
52
|
await self._queue.runTask(async () => {
|
|
53
53
|
self._handles[handle._id] = handle;
|
|
54
|
-
// Send out whatever adds we have so far (whether or not
|
|
54
|
+
// Send out whatever adds we have so far (whether or not the
|
|
55
55
|
// multiplexer is ready).
|
|
56
56
|
self._sendAdds(handle);
|
|
57
57
|
--self._addHandleTasksScheduledButNotPerformed;
|
|
@@ -78,7 +78,7 @@ class ObserveMultiplexer {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
_stop(options) {
|
|
81
|
-
|
|
81
|
+
const self = this;
|
|
82
82
|
options = options || {};
|
|
83
83
|
// It shouldn't be possible for us to stop when all our handles still
|
|
84
84
|
// haven't been returned from observeChanges!
|
|
@@ -94,12 +94,11 @@ class ObserveMultiplexer {
|
|
|
94
94
|
// Allows all addHandleAndSendInitialAdds calls to return, once all preceding
|
|
95
95
|
// adds have been processed. Does not block.
|
|
96
96
|
ready() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (self._ready())
|
|
97
|
+
this._queue.queueTask(async () => {
|
|
98
|
+
if (this._ready())
|
|
100
99
|
throw Error("can't make ObserveMultiplex ready twice!");
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
this._readyFuture.resolve();
|
|
101
|
+
this._readyFuture.isResolved = true;
|
|
103
102
|
});
|
|
104
103
|
}
|
|
105
104
|
// If trying to execute the query results in an error, call this. This is
|
|
@@ -138,7 +137,7 @@ class ObserveMultiplexer {
|
|
|
138
137
|
_ready() {
|
|
139
138
|
return this._readyFuture.isResolved;
|
|
140
139
|
}
|
|
141
|
-
_applyCallback(callbackName, args) {
|
|
140
|
+
async _applyCallback(callbackName, args) {
|
|
142
141
|
var self = this;
|
|
143
142
|
self._queue.queueTask(async () => {
|
|
144
143
|
// If we stopped in the meantime, do nothing.
|
|
@@ -179,7 +178,7 @@ class ObserveMultiplexer {
|
|
|
179
178
|
if (!add)
|
|
180
179
|
return;
|
|
181
180
|
// note: docs may be an _IdMap or an OrderedDict
|
|
182
|
-
self._cache.docs.forEach(
|
|
181
|
+
self._cache.docs.forEach((doc, id) => {
|
|
183
182
|
if (!self._handles.hasOwnProperty(handle._id))
|
|
184
183
|
throw Error("handle got removed before sending initial adds!");
|
|
185
184
|
const _a = handle.nonMutatingCallbacks ? doc : (0, ejson_1.clone)(doc), { _id } = _a, fields = __rest(_a, ["_id"]);
|
|
@@ -51,7 +51,7 @@ export declare class OplogObserveDriver {
|
|
|
51
51
|
_beSteady(): void;
|
|
52
52
|
_handleOplogEntryQuerying(op: any): void;
|
|
53
53
|
_handleOplogEntrySteadyOrFetching(op: any): void;
|
|
54
|
-
_runInitialQuery(): void
|
|
54
|
+
_runInitialQuery(): Promise<void>;
|
|
55
55
|
_pollQuery(): void;
|
|
56
56
|
_runQuery(options?: any): Promise<void>;
|
|
57
57
|
_needToPollQuery(): void;
|
|
@@ -107,8 +107,8 @@ class OplogObserveDriver {
|
|
|
107
107
|
self._stopHandles.push(self._mongoHandle._oplogHandle.onSkippedEntries(finishIfNeedToPollQuery(function () {
|
|
108
108
|
self._needToPollQuery();
|
|
109
109
|
})));
|
|
110
|
-
(0, observe_driver_utils_1.forEachTrigger)(self._cursorDescription,
|
|
111
|
-
self._stopHandles.push(
|
|
110
|
+
(0, observe_driver_utils_1.forEachTrigger)(self._cursorDescription, async (trigger) => {
|
|
111
|
+
self._stopHandles.push(await self._mongoHandle._oplogHandle.onOplogEntry(trigger, function (notification) {
|
|
112
112
|
//Meteor._noYieldsAllowed(finishIfNeedToPollQuery(function () {
|
|
113
113
|
var op = notification.op;
|
|
114
114
|
if (notification.dropCollection || notification.dropDatabase) {
|
|
@@ -613,17 +613,17 @@ class OplogObserveDriver {
|
|
|
613
613
|
//});
|
|
614
614
|
}
|
|
615
615
|
// Yields!
|
|
616
|
-
_runInitialQuery() {
|
|
616
|
+
async _runInitialQuery() {
|
|
617
617
|
var self = this;
|
|
618
618
|
if (self._stopped)
|
|
619
619
|
throw new Error("oplog stopped surprisingly early");
|
|
620
|
-
self._runQuery({ initial: true }); // yields
|
|
620
|
+
await self._runQuery({ initial: true }); // yields
|
|
621
621
|
if (self._stopped)
|
|
622
622
|
return; // can happen on queryError
|
|
623
623
|
// Allow observeChanges calls to return. (After this, it's possible for
|
|
624
624
|
// stop() to be called.)
|
|
625
625
|
self._multiplexer.ready();
|
|
626
|
-
self._doneQuerying(); // yields
|
|
626
|
+
await self._doneQuerying(); // yields
|
|
627
627
|
}
|
|
628
628
|
// In various circumstances, we may just want to stop processing the oplog and
|
|
629
629
|
// re-run the initial query, just as if we were a PollingObserveDriver.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { AsyncFunction } from "../types";
|
|
2
2
|
export declare class _SynchronousQueue {
|
|
3
3
|
private _taskHandles;
|
|
4
4
|
private _runningOrRunScheduled;
|
|
@@ -11,4 +11,3 @@ export declare class _SynchronousQueue {
|
|
|
11
11
|
_scheduleRun(): void;
|
|
12
12
|
_run(): Promise<void>;
|
|
13
13
|
}
|
|
14
|
-
export {};
|
|
@@ -18,7 +18,7 @@ export declare class OrderedDict {
|
|
|
18
18
|
remove(key: any): any;
|
|
19
19
|
get(key: any): any;
|
|
20
20
|
has(key: any): any;
|
|
21
|
-
forEach(iter: any, context?: any): void;
|
|
21
|
+
forEach(iter: (doc: any, key: string, index: number) => any, context?: any): void;
|
|
22
22
|
first(): any;
|
|
23
23
|
firstValue(): any;
|
|
24
24
|
last(): any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type AsyncFunction = (...args: any[]) => Promise<any>;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongodb-livedata-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "MongoDB live data server, extracted from Meteor, Fibers removed and converted to TypeScript",
|
|
5
5
|
"main": "dist/livedata_server.js",
|
|
6
6
|
"types": "dist/livedata_server.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
8
|
+
"build": "tsc"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [],
|
|
11
11
|
"author": "Andrei Markeev",
|