@@ -121,24 +121,25 @@ export default function constructShellBson(bson: typeof BSON, printWarning: (msg
121
121
return new bson . Code ( c , s ) ;
122
122
} , { ...bson . Code , prototype : bson . Code . prototype } ) ,
123
123
NumberDecimal : Object . assign ( function NumberDecimal ( s = '0' ) : typeof bson . Decimal128 . prototype {
124
- assertArgsDefinedType ( [ s ] , [ [ 'string' , 'number' ] ] , 'NumberDecimal' ) ;
125
- if ( typeof s === 'string ' ) {
126
- return bson . Decimal128 . fromString ( s ) ;
124
+ assertArgsDefinedType ( [ s ] , [ [ 'string' , 'number' , 'bson:Long' , 'bson:Int32' , 'bson:Decimal128' ] ] , 'NumberDecimal' ) ;
125
+ if ( typeof s === 'number ' ) {
126
+ printWarning ( 'NumberDecimal: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead' ) ;
127
127
}
128
- printWarning ( 'NumberDecimal: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead' ) ;
129
128
return bson . Decimal128 . fromString ( `${ s } ` ) ;
130
129
} , { prototype : bson . Decimal128 . prototype } ) ,
131
130
NumberInt : Object . assign ( function NumberInt ( v = '0' ) : typeof bson . Int32 . prototype {
132
- assertArgsDefinedType ( [ v ] , [ [ 'string' , 'number' ] ] , 'NumberInt' ) ;
131
+ v ??= '0' ;
132
+ assertArgsDefinedType ( [ v ] , [ [ 'string' , 'number' , 'bson:Long' , 'bson:Int32' ] ] , 'NumberInt' ) ;
133
133
return new bson . Int32 ( parseInt ( `${ v } ` , 10 ) ) ;
134
134
} , { prototype : bson . Int32 . prototype } ) ,
135
135
NumberLong : Object . assign ( function NumberLong ( s : string | number = '0' ) : typeof bson . Long . prototype {
136
- assertArgsDefinedType ( [ s ] , [ [ 'string' , 'number' ] ] , 'NumberLong' ) ;
137
- if ( typeof s === 'string' ) {
138
- return bson . Long . fromString ( s ) ;
136
+ s ??= '0' ;
137
+ assertArgsDefinedType ( [ s ] , [ [ 'string' , 'number' , 'bson:Long' , 'bson:Int32' ] ] , 'NumberLong' ) ;
138
+ if ( typeof s === 'number' ) {
139
+ printWarning ( 'NumberLong: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead' ) ;
140
+ return bson . Long . fromNumber ( s ) ;
139
141
}
140
- printWarning ( 'NumberLong: specifying a number as argument is deprecated and may lead to loss of precision, pass a string instead' ) ;
141
- return bson . Long . fromNumber ( s ) ;
142
+ return bson . Long . fromString ( `${ s } ` ) ;
142
143
} , { prototype : bson . Long . prototype } ) ,
143
144
ISODate : function ISODate ( input ?: string ) : Date {
144
145
if ( ! input ) input = new Date ( ) . toISOString ( ) ;
0 commit comments