-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
meteorx.js
108 lines (82 loc) · 2.46 KB
/
meteorx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* eslint-disable no-undef */
// Various tricks for accessing "private" Meteor APIs borrowed from the
// now-unmaintained meteorhacks:meteorx package.
export const Server = Meteor.server.constructor;
function getSession() {
const fakeSocket = {
send() {},
close() {},
headers: []
};
const server = Meteor.server;
server._handleConnect(fakeSocket, {
msg: 'connect',
version: 'pre1',
support: ['pre1']
});
const session = fakeSocket._meteorSession;
server._removeSession(session);
return session;
}
const session = getSession();
export const Session = session.constructor;
const collection = new Mongo.Collection(`__dummy_coll_${Random.id()}`);
collection.findOne();
const cursor = collection.find();
export const MongoCursor = cursor.constructor;
function getMultiplexer(multiCursor) {
const handle = multiCursor.observeChanges({
added() {}
});
handle.stop();
return handle._multiplexer;
}
export const Multiplexer = getMultiplexer(cursor).constructor;
export const MongoConnection = MongoInternals.defaultRemoteCollectionDriver().mongo.constructor;
function getSubscription(subSession) {
const subId = Random.id();
subSession._startSubscription(
function() {
this.ready();
},
subId,
[],
`__dummy_pub_${Random.id()}`
);
const subscription =
subSession._namedSubs instanceof Map
? subSession._namedSubs.get(subId)
: subSession._namedSubs[subId];
subSession._stopSubscription(subId);
return subscription;
}
export const Subscription = getSubscription(session).constructor;
function getObserverDriver(obsCursor) {
const multiplexer = getMultiplexer(obsCursor);
return (multiplexer && multiplexer._observeDriver) || null;
}
function getMongoOplogDriver() {
const driver = getObserverDriver(cursor);
const MongoOplogDriver = (driver && driver.constructor) || null;
if (MongoOplogDriver && typeof MongoOplogDriver.cursorSupported !== 'function') {
return null;
}
return MongoOplogDriver;
}
export const MongoOplogDriver = getMongoOplogDriver();
function getMongoPollingDriver() {
const driverCursor = collection.find(
{},
{
limit: 20,
_disableOplog: true
}
);
const driver = getObserverDriver(driverCursor);
// verify observer driver is a polling driver
if (driver && typeof driver.constructor.cursorSupported === 'undefined') {
return driver.constructor;
}
return null;
}
export const MongoPollingDriver = getMongoPollingDriver();