bson 5.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bson.d.ts +23 -2
- package/lib/bson.bundle.js +19 -1
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +19 -1
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +19 -2
- package/lib/bson.mjs.map +1 -1
- package/package.json +16 -4
- package/src/bson.ts +1 -1
- package/src/error.ts +27 -2
- package/src/extended_json.ts +8 -1
- package/src/long.ts +3 -0
- package/src/utils/node_byte_utils.ts +2 -2
package/bson.d.ts
CHANGED
|
@@ -144,6 +144,7 @@ declare namespace BSON {
|
|
|
144
144
|
BSONValue,
|
|
145
145
|
BSONError,
|
|
146
146
|
BSONVersionError,
|
|
147
|
+
BSONRuntimeError,
|
|
147
148
|
BSONType,
|
|
148
149
|
EJSON,
|
|
149
150
|
Document,
|
|
@@ -154,7 +155,11 @@ export { BSON }
|
|
|
154
155
|
|
|
155
156
|
/**
|
|
156
157
|
* @public
|
|
157
|
-
*
|
|
158
|
+
* @category Error
|
|
159
|
+
*
|
|
160
|
+
* `BSONError` objects are thrown when BSON ecounters an error.
|
|
161
|
+
*
|
|
162
|
+
* This is the parent class for all the other errors thrown by this library.
|
|
158
163
|
*/
|
|
159
164
|
export declare class BSONError extends Error {
|
|
160
165
|
/* Excluded from this release type: bsonError */
|
|
@@ -206,6 +211,19 @@ export declare interface BSONRegExpExtendedLegacy {
|
|
|
206
211
|
$options: string;
|
|
207
212
|
}
|
|
208
213
|
|
|
214
|
+
/**
|
|
215
|
+
* @public
|
|
216
|
+
* @category Error
|
|
217
|
+
*
|
|
218
|
+
* An error generated when BSON functions encounter an unexpected input
|
|
219
|
+
* or reaches an unexpected/invalid internal state
|
|
220
|
+
*
|
|
221
|
+
*/
|
|
222
|
+
export declare class BSONRuntimeError extends BSONError {
|
|
223
|
+
get name(): 'BSONRuntimeError';
|
|
224
|
+
constructor(message: string);
|
|
225
|
+
}
|
|
226
|
+
|
|
209
227
|
/**
|
|
210
228
|
* A class representation of the BSON Symbol type.
|
|
211
229
|
* @public
|
|
@@ -269,7 +287,10 @@ export declare abstract class BSONValue {
|
|
|
269
287
|
/* Excluded from this release type: toExtendedJSON */
|
|
270
288
|
}
|
|
271
289
|
|
|
272
|
-
/**
|
|
290
|
+
/**
|
|
291
|
+
* @public
|
|
292
|
+
* @category Error
|
|
293
|
+
*/
|
|
273
294
|
export declare class BSONVersionError extends BSONError {
|
|
274
295
|
get name(): 'BSONVersionError';
|
|
275
296
|
constructor();
|
package/lib/bson.bundle.js
CHANGED
|
@@ -83,13 +83,21 @@ class BSONVersionError extends BSONError {
|
|
|
83
83
|
super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.0 or later`);
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
+
class BSONRuntimeError extends BSONError {
|
|
87
|
+
get name() {
|
|
88
|
+
return 'BSONRuntimeError';
|
|
89
|
+
}
|
|
90
|
+
constructor(message) {
|
|
91
|
+
super(message);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
86
94
|
|
|
87
95
|
function nodejsMathRandomBytes(byteLength) {
|
|
88
96
|
return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
|
|
89
97
|
}
|
|
90
98
|
const nodejsRandomBytes = (() => {
|
|
91
99
|
try {
|
|
92
|
-
return require('
|
|
100
|
+
return require('crypto').randomBytes;
|
|
93
101
|
}
|
|
94
102
|
catch {
|
|
95
103
|
return nodejsMathRandomBytes;
|
|
@@ -3723,6 +3731,10 @@ function deserializeValue(value, options = {}) {
|
|
|
3723
3731
|
date.setTime(d);
|
|
3724
3732
|
else if (typeof d === 'string')
|
|
3725
3733
|
date.setTime(Date.parse(d));
|
|
3734
|
+
else if (typeof d === 'bigint')
|
|
3735
|
+
date.setTime(Number(d));
|
|
3736
|
+
else
|
|
3737
|
+
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
|
3726
3738
|
}
|
|
3727
3739
|
else {
|
|
3728
3740
|
if (typeof d === 'string')
|
|
@@ -3731,6 +3743,10 @@ function deserializeValue(value, options = {}) {
|
|
|
3731
3743
|
date.setTime(d.toNumber());
|
|
3732
3744
|
else if (typeof d === 'number' && options.relaxed)
|
|
3733
3745
|
date.setTime(d);
|
|
3746
|
+
else if (typeof d === 'bigint')
|
|
3747
|
+
date.setTime(Number(d));
|
|
3748
|
+
else
|
|
3749
|
+
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
|
3734
3750
|
}
|
|
3735
3751
|
return date;
|
|
3736
3752
|
}
|
|
@@ -4035,6 +4051,7 @@ deserializeStream: deserializeStream,
|
|
|
4035
4051
|
BSONValue: BSONValue,
|
|
4036
4052
|
BSONError: BSONError,
|
|
4037
4053
|
BSONVersionError: BSONVersionError,
|
|
4054
|
+
BSONRuntimeError: BSONRuntimeError,
|
|
4038
4055
|
BSONType: BSONType,
|
|
4039
4056
|
EJSON: EJSON
|
|
4040
4057
|
});
|
|
@@ -4042,6 +4059,7 @@ EJSON: EJSON
|
|
|
4042
4059
|
exports.BSON = bson;
|
|
4043
4060
|
exports.BSONError = BSONError;
|
|
4044
4061
|
exports.BSONRegExp = BSONRegExp;
|
|
4062
|
+
exports.BSONRuntimeError = BSONRuntimeError;
|
|
4045
4063
|
exports.BSONSymbol = BSONSymbol;
|
|
4046
4064
|
exports.BSONType = BSONType;
|
|
4047
4065
|
exports.BSONValue = BSONValue;
|