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