This repository was archived by the owner on Feb 4, 2022. It is now read-only.
File tree 3 files changed +29
-1
lines changed
3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
var BSON = require ( 'bson' ) ;
4
4
var require_optional = require ( 'require_optional' ) ;
5
+ const EJSON = require ( './lib/utils' ) . retrieveEJSON ( ) ;
5
6
6
7
try {
7
8
// Attempt to grab the native BSON parser
@@ -31,6 +32,7 @@ module.exports = {
31
32
ReadPreference : require ( './lib/topologies/read_preference' ) ,
32
33
Sessions : require ( './lib/sessions' ) ,
33
34
BSON : BSON ,
35
+ EJSON : EJSON ,
34
36
// Raw operations
35
37
Query : require ( './lib/connection/commands' ) . Query ,
36
38
// Auth mechanisms
Original file line number Diff line number Diff line change 48
48
console . warn ( err . message ) ;
49
49
}
50
50
51
+ // Throw an error if an attempt to use EJSON is made when it is not installed
52
+ const noEJSONError = function ( ) {
53
+ throw new Error ( 'The `mongodb-extjson` package was not found. Please install it and try again.' ) ;
54
+ } ;
55
+
56
+ // Facilitate loading EJSON optionally
57
+ const retrieveEJSON = function ( ) {
58
+ let EJSON = null ;
59
+ try {
60
+ EJSON = requireOptional ( 'mongodb-extjson' ) ;
61
+ } catch ( error ) { } // eslint-disable-line
62
+ if ( ! EJSON ) {
63
+ EJSON = {
64
+ parse : noEJSONError ,
65
+ deserialize : noEJSONError ,
66
+ serialize : noEJSONError ,
67
+ stringify : noEJSONError ,
68
+ setBSONModule : noEJSONError ,
69
+ BSON : noEJSONError
70
+ } ;
71
+ }
72
+ return EJSON ;
73
+ } ;
74
+
51
75
/*
52
76
* Checks that collation is supported by server.
53
77
*
@@ -66,5 +90,6 @@ module.exports = {
66
90
relayEvents,
67
91
Kerberos,
68
92
MongoAuthProcess,
69
- collationNotSupported
93
+ collationNotSupported,
94
+ retrieveEJSON
70
95
} ;
Original file line number Diff line number Diff line change 40
40
},
41
41
"peerOptionalDependencies" : {
42
42
"kerberos" : " >= 0.0.23 < 1.0.0" ,
43
+ "mongodb-extjson" : " ^2.1.2" ,
43
44
"snappy" : " ^6.0.1" ,
44
45
"bson-ext" : " ^2.0.0"
45
46
},
You can’t perform that action at this time.
0 commit comments