bson 6.7.0 → 6.8.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/lib/bson.mjs CHANGED
@@ -853,19 +853,18 @@ class Long extends BSONValue {
853
853
  get __isLong__() {
854
854
  return true;
855
855
  }
856
- constructor(low = 0, high, unsigned) {
856
+ constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
857
857
  super();
858
- if (typeof low === 'bigint') {
859
- Object.assign(this, Long.fromBigInt(low, !!high));
860
- }
861
- else if (typeof low === 'string') {
862
- Object.assign(this, Long.fromString(low, !!high));
863
- }
864
- else {
865
- this.low = low | 0;
866
- this.high = high | 0;
867
- this.unsigned = !!unsigned;
868
- }
858
+ const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
859
+ const high = typeof highOrUnsigned === 'number' ? highOrUnsigned : 0;
860
+ const res = typeof lowOrValue === 'string'
861
+ ? Long.fromString(lowOrValue, unsignedBool)
862
+ : typeof lowOrValue === 'bigint'
863
+ ? Long.fromBigInt(lowOrValue, unsignedBool)
864
+ : { low: lowOrValue | 0, high: high | 0, unsigned: unsignedBool };
865
+ this.low = res.low;
866
+ this.high = res.high;
867
+ this.unsigned = res.unsigned;
869
868
  }
870
869
  static fromBits(lowBits, highBits, unsigned) {
871
870
  return new Long(lowBits, highBits, unsigned);
@@ -917,7 +916,9 @@ class Long extends BSONValue {
917
916
  return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
918
917
  }
919
918
  static fromBigInt(value, unsigned) {
920
- return Long.fromString(value.toString(), unsigned);
919
+ const FROM_BIGINT_BIT_MASK = BigInt(0xffffffff);
920
+ const FROM_BIGINT_BIT_SHIFT = BigInt(32);
921
+ return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK), unsigned);
921
922
  }
922
923
  static _fromString(str, unsigned, radix) {
923
924
  if (str.length === 0)