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.rn.cjs CHANGED
@@ -872,19 +872,18 @@ class Long extends BSONValue {
872
872
  get __isLong__() {
873
873
  return true;
874
874
  }
875
- constructor(low = 0, high, unsigned) {
875
+ constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
876
876
  super();
877
- if (typeof low === 'bigint') {
878
- Object.assign(this, Long.fromBigInt(low, !!high));
879
- }
880
- else if (typeof low === 'string') {
881
- Object.assign(this, Long.fromString(low, !!high));
882
- }
883
- else {
884
- this.low = low | 0;
885
- this.high = high | 0;
886
- this.unsigned = !!unsigned;
887
- }
877
+ const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
878
+ const high = typeof highOrUnsigned === 'number' ? highOrUnsigned : 0;
879
+ const res = typeof lowOrValue === 'string'
880
+ ? Long.fromString(lowOrValue, unsignedBool)
881
+ : typeof lowOrValue === 'bigint'
882
+ ? Long.fromBigInt(lowOrValue, unsignedBool)
883
+ : { low: lowOrValue | 0, high: high | 0, unsigned: unsignedBool };
884
+ this.low = res.low;
885
+ this.high = res.high;
886
+ this.unsigned = res.unsigned;
888
887
  }
889
888
  static fromBits(lowBits, highBits, unsigned) {
890
889
  return new Long(lowBits, highBits, unsigned);
@@ -936,7 +935,9 @@ class Long extends BSONValue {
936
935
  return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
937
936
  }
938
937
  static fromBigInt(value, unsigned) {
939
- return Long.fromString(value.toString(), unsigned);
938
+ const FROM_BIGINT_BIT_MASK = BigInt(0xffffffff);
939
+ const FROM_BIGINT_BIT_SHIFT = BigInt(32);
940
+ return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK), unsigned);
940
941
  }
941
942
  static _fromString(str, unsigned, radix) {
942
943
  if (str.length === 0)