-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (45 loc) · 1.4 KB
/
index.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
const mongodb = require('@apostrophecms/emulate-mongo-3-driver');
const binary = require('./binary.js');
const collection = require('./collection.js');
const cursor = require('./cursor.js');
const db = require('./db.js');
const mongoClient = require('./mongo-client.js');
const emulateClasses = new Map([
[ 'Binary', binary ],
[ 'FindCursor', cursor ],
[ 'AggregationCursor', cursor ],
[ 'Collection', collection ],
[ 'Db', db ],
[ 'MongoClient', mongoClient ]
]);
const entries = Object.entries(mongodb);
for (const [ mongodbExportName, mongodbExportValue ] of entries) {
const emulateClass = emulateClasses.get(mongodbExportName);
if (emulateClass != null) {
const patchedClass = emulateClass(mongodbExportValue);
Object.defineProperty(
module.exports,
mongodbExportName,
{
enumerable: true,
get: function () {
return patchedClass;
}
}
);
} else {
Object.defineProperty(
module.exports,
mongodbExportName,
{
enumerable: true,
get: function () {
return mongodbExportValue;
}
}
);
}
}
// TODO: https://github.com/mongodb/node-mongodb-native/blob/master/CHANGES_3.0.0.md#bulkwriteresult--bulkwriteerror (we don't use it)
// https://github.com/mongodb/node-mongodb-native/blob/master/CHANGES_3.0.0.md#mapreduce-inlined-results (we don't use it)
// See others on that page