This repository was archived by the owner on Sep 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
63 lines (56 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var BSONExt = require('bindings')('bson').BSON;
var jsBson = require('bson');
const BSON = new BSONExt([
jsBson.Binary,
jsBson.Code,
jsBson.DBRef,
jsBson.Decimal128,
jsBson.Double,
jsBson.Int32,
jsBson.Long,
jsBson.Map,
jsBson.MaxKey,
jsBson.MinKey,
jsBson.ObjectId,
jsBson.BSONRegExp,
jsBson.BSONSymbol,
jsBson.Timestamp
]);
// BSON MAX VALUES
BSON.BSON_INT32_MAX = 0x7fffffff;
BSON.BSON_INT32_MIN = -0x80000000;
BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1;
BSON.BSON_INT64_MIN = -Math.pow(2, 63);
// JS MAX PRECISE VALUES
BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double.
BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double.
// Decorate BSON with types from js-bson
[
'Binary',
'Code',
'DBRef',
'Decimal128',
'Double',
'Int32',
'Long',
'Map',
'MaxKey',
'MinKey',
'ObjectId',
'BSONRegExp',
'Symbol',
'Timestamp'
].forEach(function(type) {
BSON[type] = jsBson[type];
});
// special case for deprecated names
BSON.ObjectID = BSON.ObjectId;
// Just add constants to the Native BSON parser
BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0;
BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1;
BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
BSON.BSON_BINARY_SUBTYPE_UUID = 3;
BSON.BSON_BINARY_SUBTYPE_MD5 = 4;
BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
// Return the BSON
module.exports = BSON;