|
1 |
| -var BSON = require('bindings')('bson').BSON; |
2 |
| -var jsBson = require('bson'); |
3 |
| - |
4 |
| -// BSON MAX VALUES |
5 |
| -BSON.BSON_INT32_MAX = 0x7FFFFFFF; |
6 |
| -BSON.BSON_INT32_MIN = -0x80000000; |
7 |
| - |
8 |
| -BSON.BSON_INT64_MAX = Math.pow(2, 63) - 1; |
9 |
| -BSON.BSON_INT64_MIN = -Math.pow(2, 63); |
10 |
| - |
11 |
| -// JS MAX PRECISE VALUES |
12 |
| -BSON.JS_INT_MAX = 0x20000000000000; // Any integer up to 2^53 can be precisely represented by a double. |
13 |
| -BSON.JS_INT_MIN = -0x20000000000000; // Any integer down to -2^53 can be precisely represented by a double. |
14 |
| - |
15 |
| -// Decorate BSON with types from js-bson |
16 |
| -[ |
17 |
| - 'Binary', |
18 |
| - 'Code', |
19 |
| - 'DBRef', |
20 |
| - 'Decimal128', |
21 |
| - 'Double', |
22 |
| - 'Int32', |
23 |
| - 'Long', |
24 |
| - 'Map', |
25 |
| - 'MaxKey', |
26 |
| - 'MinKey', |
27 |
| - 'ObjectId', |
28 |
| - 'BSONRegExp', |
29 |
| - 'Symbol', |
30 |
| - 'Timestamp' |
31 |
| -].forEach(function(type) { |
32 |
| - BSON[type] = jsBson[type]; |
33 |
| -}); |
| 1 | +var BSONExtModule = require('bindings')('bson').BSON; |
34 | 2 |
|
35 |
| -// special case for deprecated names |
36 |
| -BSON.ObjectID = BSON.ObjectId; |
| 3 | +var BSONJS = require('bson'); |
| 4 | + |
| 5 | +const BSON = new BSONExtModule([ |
| 6 | + BSONJS.Binary, |
| 7 | + BSONJS.Code, |
| 8 | + BSONJS.DBRef, |
| 9 | + BSONJS.Decimal128, |
| 10 | + BSONJS.Double, |
| 11 | + BSONJS.Int32, |
| 12 | + BSONJS.Long, |
| 13 | + BSONJS.Map, |
| 14 | + BSONJS.MaxKey, |
| 15 | + BSONJS.MinKey, |
| 16 | + BSONJS.ObjectId, |
| 17 | + BSONJS.BSONRegExp, |
| 18 | + BSONJS.BSONSymbol, |
| 19 | + BSONJS.Timestamp |
| 20 | +]); |
| 21 | + |
| 22 | +module.exports = Object.create(null); |
| 23 | + |
| 24 | +module.exports.BSON_INT32_MAX = 0x7fffffff; |
| 25 | +module.exports.BSON_INT32_MIN = -0x80000000; |
| 26 | + |
| 27 | +module.exports.BSON_INT64_MAX = BSONJS.Long.MAX_VALUE; |
| 28 | +module.exports.BSON_INT64_MIN = BSONJS.Long.MIN_VALUE; |
| 29 | + |
| 30 | +module.exports.JS_INT_MAX = Number.MAX_SAFE_INTEGER; |
| 31 | +module.exports.JS_INT_MIN = Number.MIN_SAFE_INTEGER; |
37 | 32 |
|
38 | 33 | // Just add constants to the Native BSON parser
|
39 |
| -BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0; |
40 |
| -BSON.BSON_BINARY_SUBTYPE_FUNCTION = 1; |
41 |
| -BSON.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; |
42 |
| -BSON.BSON_BINARY_SUBTYPE_UUID = 3; |
43 |
| -BSON.BSON_BINARY_SUBTYPE_MD5 = 4; |
44 |
| -BSON.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; |
45 |
| - |
46 |
| -// Return the BSON |
47 |
| -module.exports = BSON; |
| 34 | +module.exports.BSON_BINARY_SUBTYPE_DEFAULT = 0; |
| 35 | +module.exports.BSON_BINARY_SUBTYPE_FUNCTION = 1; |
| 36 | +module.exports.BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2; |
| 37 | +module.exports.BSON_BINARY_SUBTYPE_UUID = 3; |
| 38 | +module.exports.BSON_BINARY_SUBTYPE_UUID_NEW = 4; |
| 39 | +module.exports.BSON_BINARY_SUBTYPE_MD5 = 5; |
| 40 | +module.exports.BSON_BINARY_SUBTYPE_ENCRYPTED = 6; |
| 41 | +module.exports.BSON_BINARY_SUBTYPE_USER_DEFINED = 128; |
| 42 | + |
| 43 | +/** @type {import('bson').Binary} */ |
| 44 | +module.exports.Binary = BSONJS.Binary; |
| 45 | +/** @type {import('bson').Code} */ |
| 46 | +module.exports.Code = BSONJS.Code; |
| 47 | +/** @type {import('bson').DBRef} */ |
| 48 | +module.exports.DBRef = BSONJS.DBRef; |
| 49 | +/** @type {import('bson').Decimal128} */ |
| 50 | +module.exports.Decimal128 = BSONJS.Decimal128; |
| 51 | +/** @type {import('bson').Double} */ |
| 52 | +module.exports.Double = BSONJS.Double; |
| 53 | +/** @type {import('bson').Int32} */ |
| 54 | +module.exports.Int32 = BSONJS.Int32; |
| 55 | +/** @type {import('bson').Long} */ |
| 56 | +module.exports.Long = BSONJS.Long; |
| 57 | +/** @type {import('bson').Map} */ |
| 58 | +module.exports.Map = BSONJS.Map; |
| 59 | +/** @type {import('bson').MaxKey} */ |
| 60 | +module.exports.MaxKey = BSONJS.MaxKey; |
| 61 | +/** @type {import('bson').MinKey} */ |
| 62 | +module.exports.MinKey = BSONJS.MinKey; |
| 63 | +/** @type {import('bson').ObjectId} */ |
| 64 | +module.exports.ObjectId = BSONJS.ObjectId; |
| 65 | +/** @type {import('bson').BSONRegExp} */ |
| 66 | +module.exports.BSONRegExp = BSONJS.BSONRegExp; |
| 67 | +/** @type {import('bson').BSONSymbol} */ |
| 68 | +module.exports.BSONSymbol = BSONJS.BSONSymbol; |
| 69 | +/** @type {import('bson').Timestamp} */ |
| 70 | +module.exports.Timestamp = BSONJS.Timestamp; |
| 71 | + |
| 72 | +// special case for deprecated names |
| 73 | +/** @type {import('bson').ObjectId} */ |
| 74 | +module.exports.ObjectID = BSONJS.ObjectId; |
| 75 | + |
| 76 | +/** @type {import('bson').calculateObjectSize} */ |
| 77 | +module.exports.calculateObjectSize = BSON.calculateObjectSize.bind(BSON); |
| 78 | +/** @type {import('bson').serialize} */ |
| 79 | +module.exports.serialize = BSON.serialize.bind(BSON); |
| 80 | +/** @type {import('bson').serializeWithBufferAndIndex} */ |
| 81 | +module.exports.serializeWithBufferAndIndex = BSON.serializeWithBufferAndIndex.bind(BSON); |
| 82 | +/** @type {import('bson').deserialize} */ |
| 83 | +module.exports.deserialize = BSON.deserialize.bind(BSON); |
| 84 | +/** @type {import('bson').deserializeStream} */ |
| 85 | +module.exports.deserializeStream = BSON.deserializeStream.bind(BSON); |
| 86 | + |
| 87 | +Object.freeze(module.exports); |
0 commit comments