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/README.md CHANGED
@@ -11,6 +11,33 @@ You can learn more about it in [the specification](http://bsonspec.org).
11
11
  - [Documentation](#documentation)
12
12
  - [FAQ](#faq)
13
13
 
14
+
15
+ ### Release Integrity
16
+
17
+ Releases are created automatically and signed using the [Node team's GPG key](https://pgp.mongodb.com/node-driver.asc). This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg:
18
+
19
+ ```shell
20
+ gpg --import node-driver.asc
21
+ ```
22
+
23
+ The GitHub release contains a detached signature file for the NPM package (named
24
+ `bson-X.Y.Z.tgz.sig`).
25
+
26
+ The following command returns the link npm package.
27
+ ```shell
28
+ npm view bson@vX.Y.Z dist.tarball
29
+ ```
30
+
31
+ Using the result of the above command, a `curl` command can return the official npm package for the release.
32
+
33
+ To verify the integrity of the downloaded package, run the following command:
34
+ ```shell
35
+ gpg --verify bson-X.Y.Z.tgz.sig bson-X.Y.Z.tgz
36
+ ```
37
+
38
+ >[!Note]
39
+ No verification is done when using npm to install the package. The contents of the Github tarball and npm's tarball are identical.
40
+
14
41
  ## Bugs / Feature Requests
15
42
 
16
43
  Think you've found a bug? Want to see a new feature in `bson`? Please open a case in our issue management tool, JIRA:
package/bson.d.ts CHANGED
@@ -760,18 +760,26 @@ export declare class Long extends BSONValue {
760
760
  unsigned: boolean;
761
761
  /**
762
762
  * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
763
- * See the from* functions below for more convenient ways of constructing Longs.
764
- *
765
- * Acceptable signatures are:
766
- * - Long(low, high, unsigned?)
767
- * - Long(bigint, unsigned?)
768
- * - Long(string, unsigned?)
769
763
  *
770
764
  * @param low - The low (signed) 32 bits of the long
771
765
  * @param high - The high (signed) 32 bits of the long
772
766
  * @param unsigned - Whether unsigned or not, defaults to signed
773
767
  */
774
- constructor(low?: number | bigint | string, high?: number | boolean, unsigned?: boolean);
768
+ constructor(low: number, high?: number, unsigned?: boolean);
769
+ /**
770
+ * Constructs a 64 bit two's-complement integer, given a bigint representation.
771
+ *
772
+ * @param value - BigInt representation of the long value
773
+ * @param unsigned - Whether unsigned or not, defaults to signed
774
+ */
775
+ constructor(value: bigint, unsigned?: boolean);
776
+ /**
777
+ * Constructs a 64 bit two's-complement integer, given a string representation.
778
+ *
779
+ * @param value - String representation of the long value
780
+ * @param unsigned - Whether unsigned or not, defaults to signed
781
+ */
782
+ constructor(value: string, unsigned?: boolean);
775
783
  static TWO_PWR_24: Long;
776
784
  /** Maximum unsigned value. */
777
785
  static MAX_UNSIGNED_VALUE: Long;
@@ -856,19 +856,18 @@ class Long extends BSONValue {
856
856
  get __isLong__() {
857
857
  return true;
858
858
  }
859
- constructor(low = 0, high, unsigned) {
859
+ constructor(lowOrValue = 0, highOrUnsigned, unsigned) {
860
860
  super();
861
- if (typeof low === 'bigint') {
862
- Object.assign(this, Long.fromBigInt(low, !!high));
863
- }
864
- else if (typeof low === 'string') {
865
- Object.assign(this, Long.fromString(low, !!high));
866
- }
867
- else {
868
- this.low = low | 0;
869
- this.high = high | 0;
870
- this.unsigned = !!unsigned;
871
- }
861
+ const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
862
+ const high = typeof highOrUnsigned === 'number' ? highOrUnsigned : 0;
863
+ const res = typeof lowOrValue === 'string'
864
+ ? Long.fromString(lowOrValue, unsignedBool)
865
+ : typeof lowOrValue === 'bigint'
866
+ ? Long.fromBigInt(lowOrValue, unsignedBool)
867
+ : { low: lowOrValue | 0, high: high | 0, unsigned: unsignedBool };
868
+ this.low = res.low;
869
+ this.high = res.high;
870
+ this.unsigned = res.unsigned;
872
871
  }
873
872
  static fromBits(lowBits, highBits, unsigned) {
874
873
  return new Long(lowBits, highBits, unsigned);
@@ -920,7 +919,9 @@ class Long extends BSONValue {
920
919
  return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
921
920
  }
922
921
  static fromBigInt(value, unsigned) {
923
- return Long.fromString(value.toString(), unsigned);
922
+ const FROM_BIGINT_BIT_MASK = BigInt(0xffffffff);
923
+ const FROM_BIGINT_BIT_SHIFT = BigInt(32);
924
+ return new Long(Number(value & FROM_BIGINT_BIT_MASK), Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK), unsigned);
924
925
  }
925
926
  static _fromString(str, unsigned, radix) {
926
927
  if (str.length === 0)