bson 5.0.0 → 5.1.0
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 +29 -1
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +29 -1
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +29 -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 +21 -2
- 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
|
}
|
|
@@ -3769,6 +3785,16 @@ function getISOString(date) {
|
|
|
3769
3785
|
return date.getUTCMilliseconds() !== 0 ? isoStr : isoStr.slice(0, -5) + 'Z';
|
|
3770
3786
|
}
|
|
3771
3787
|
function serializeValue(value, options) {
|
|
3788
|
+
if (value instanceof Map || isMap(value)) {
|
|
3789
|
+
const obj = Object.create(null);
|
|
3790
|
+
for (const [k, v] of value) {
|
|
3791
|
+
if (typeof k !== 'string') {
|
|
3792
|
+
throw new BSONError('Can only serialize maps with string keys');
|
|
3793
|
+
}
|
|
3794
|
+
obj[k] = v;
|
|
3795
|
+
}
|
|
3796
|
+
return serializeValue(obj, options);
|
|
3797
|
+
}
|
|
3772
3798
|
if ((typeof value === 'object' || typeof value === 'function') && value !== null) {
|
|
3773
3799
|
const index = options.seenObjects.findIndex(entry => entry.obj === value);
|
|
3774
3800
|
if (index !== -1) {
|
|
@@ -4032,9 +4058,10 @@ var bson = /*#__PURE__*/Object.freeze({
|
|
|
4032
4058
|
BSONValue: BSONValue,
|
|
4033
4059
|
BSONError: BSONError,
|
|
4034
4060
|
BSONVersionError: BSONVersionError,
|
|
4061
|
+
BSONRuntimeError: BSONRuntimeError,
|
|
4035
4062
|
BSONType: BSONType,
|
|
4036
4063
|
EJSON: EJSON
|
|
4037
4064
|
});
|
|
4038
4065
|
|
|
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 };
|
|
4066
|
+
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
4067
|
//# sourceMappingURL=bson.mjs.map
|