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/lib/bson.mjs
CHANGED
|
@@ -80,13 +80,21 @@ class BSONVersionError extends BSONError {
|
|
|
80
80
|
super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.0 or later`);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
|
+
class BSONRuntimeError extends BSONError {
|
|
84
|
+
get name() {
|
|
85
|
+
return 'BSONRuntimeError';
|
|
86
|
+
}
|
|
87
|
+
constructor(message) {
|
|
88
|
+
super(message);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
83
91
|
|
|
84
92
|
function nodejsMathRandomBytes(byteLength) {
|
|
85
93
|
return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
|
|
86
94
|
}
|
|
87
95
|
const nodejsRandomBytes = await (async () => {
|
|
88
96
|
try {
|
|
89
|
-
return (await import('
|
|
97
|
+
return (await import('crypto')).randomBytes;
|
|
90
98
|
}
|
|
91
99
|
catch {
|
|
92
100
|
return nodejsMathRandomBytes;
|
|
@@ -3720,6 +3728,10 @@ function deserializeValue(value, options = {}) {
|
|
|
3720
3728
|
date.setTime(d);
|
|
3721
3729
|
else if (typeof d === 'string')
|
|
3722
3730
|
date.setTime(Date.parse(d));
|
|
3731
|
+
else if (typeof d === 'bigint')
|
|
3732
|
+
date.setTime(Number(d));
|
|
3733
|
+
else
|
|
3734
|
+
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
|
3723
3735
|
}
|
|
3724
3736
|
else {
|
|
3725
3737
|
if (typeof d === 'string')
|
|
@@ -3728,6 +3740,10 @@ function deserializeValue(value, options = {}) {
|
|
|
3728
3740
|
date.setTime(d.toNumber());
|
|
3729
3741
|
else if (typeof d === 'number' && options.relaxed)
|
|
3730
3742
|
date.setTime(d);
|
|
3743
|
+
else if (typeof d === 'bigint')
|
|
3744
|
+
date.setTime(Number(d));
|
|
3745
|
+
else
|
|
3746
|
+
throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
|
|
3731
3747
|
}
|
|
3732
3748
|
return date;
|
|
3733
3749
|
}
|
|
@@ -4032,9 +4048,10 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4032
4048
|
BSONValue: BSONValue,
|
|
4033
4049
|
BSONError: BSONError,
|
|
4034
4050
|
BSONVersionError: BSONVersionError,
|
|
4051
|
+
BSONRuntimeError: BSONRuntimeError,
|
|
4035
4052
|
BSONType: BSONType,
|
|
4036
4053
|
EJSON: EJSON
|
|
4037
4054
|
});
|
|
4038
4055
|
|
|
4039
|
-
export { bson as BSON, BSONError, BSONRegExp, BSONSymbol, BSONType, BSONValue, BSONVersionError, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, MaxKey, MinKey, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
|
|
4056
|
+
export { bson as BSON, BSONError, BSONRegExp, BSONRuntimeError, BSONSymbol, BSONType, BSONValue, BSONVersionError, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, MaxKey, MinKey, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
|
|
4040
4057
|
//# sourceMappingURL=bson.mjs.map
|