bson 5.0.0-alpha.3 → 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/lib/bson.cjs CHANGED
@@ -82,13 +82,21 @@ class BSONVersionError extends BSONError {
82
82
  super(`Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.0 or later`);
83
83
  }
84
84
  }
85
+ class BSONRuntimeError extends BSONError {
86
+ get name() {
87
+ return 'BSONRuntimeError';
88
+ }
89
+ constructor(message) {
90
+ super(message);
91
+ }
92
+ }
85
93
 
86
94
  function nodejsMathRandomBytes(byteLength) {
87
95
  return nodeJsByteUtils.fromNumberArray(Array.from({ length: byteLength }, () => Math.floor(Math.random() * 256)));
88
96
  }
89
97
  const nodejsRandomBytes = (() => {
90
98
  try {
91
- return require('node:crypto').randomBytes;
99
+ return require('crypto').randomBytes;
92
100
  }
93
101
  catch {
94
102
  return nodejsMathRandomBytes;
@@ -3722,6 +3730,10 @@ function deserializeValue(value, options = {}) {
3722
3730
  date.setTime(d);
3723
3731
  else if (typeof d === 'string')
3724
3732
  date.setTime(Date.parse(d));
3733
+ else if (typeof d === 'bigint')
3734
+ date.setTime(Number(d));
3735
+ else
3736
+ throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
3725
3737
  }
3726
3738
  else {
3727
3739
  if (typeof d === 'string')
@@ -3730,6 +3742,10 @@ function deserializeValue(value, options = {}) {
3730
3742
  date.setTime(d.toNumber());
3731
3743
  else if (typeof d === 'number' && options.relaxed)
3732
3744
  date.setTime(d);
3745
+ else if (typeof d === 'bigint')
3746
+ date.setTime(Number(d));
3747
+ else
3748
+ throw new BSONRuntimeError(`Unrecognized type for EJSON date: ${typeof d}`);
3733
3749
  }
3734
3750
  return date;
3735
3751
  }
@@ -4034,6 +4050,7 @@ var bson = /*#__PURE__*/Object.freeze({
4034
4050
  BSONValue: BSONValue,
4035
4051
  BSONError: BSONError,
4036
4052
  BSONVersionError: BSONVersionError,
4053
+ BSONRuntimeError: BSONRuntimeError,
4037
4054
  BSONType: BSONType,
4038
4055
  EJSON: EJSON
4039
4056
  });
@@ -4041,6 +4058,7 @@ var bson = /*#__PURE__*/Object.freeze({
4041
4058
  exports.BSON = bson;
4042
4059
  exports.BSONError = BSONError;
4043
4060
  exports.BSONRegExp = BSONRegExp;
4061
+ exports.BSONRuntimeError = BSONRuntimeError;
4044
4062
  exports.BSONSymbol = BSONSymbol;
4045
4063
  exports.BSONType = BSONType;
4046
4064
  exports.BSONValue = BSONValue;