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/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "vendor"
15
15
  ],
16
16
  "types": "bson.d.ts",
17
- "version": "6.7.0",
17
+ "version": "6.8.0",
18
18
  "author": {
19
19
  "name": "The MongoDB NodeJS Team",
20
20
  "email": "dbx-node@mongodb.com"
@@ -28,7 +28,6 @@
28
28
  "devDependencies": {
29
29
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
30
30
  "@microsoft/api-extractor": "^7.43.1",
31
- "@octokit/core": "^6.1.2",
32
31
  "@rollup/plugin-node-resolve": "^15.2.3",
33
32
  "@rollup/plugin-typescript": "^11.1.6",
34
33
  "@types/chai": "^4.3.14",
package/src/long.ts CHANGED
@@ -119,42 +119,57 @@ export class Long extends BSONValue {
119
119
  /**
120
120
  * The high 32 bits as a signed value.
121
121
  */
122
- high!: number;
122
+ high: number;
123
123
 
124
124
  /**
125
125
  * The low 32 bits as a signed value.
126
126
  */
127
- low!: number;
127
+ low: number;
128
128
 
129
129
  /**
130
130
  * Whether unsigned or not.
131
131
  */
132
- unsigned!: boolean;
132
+ unsigned: boolean;
133
133
 
134
134
  /**
135
135
  * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
136
- * See the from* functions below for more convenient ways of constructing Longs.
137
- *
138
- * Acceptable signatures are:
139
- * - Long(low, high, unsigned?)
140
- * - Long(bigint, unsigned?)
141
- * - Long(string, unsigned?)
142
136
  *
143
137
  * @param low - The low (signed) 32 bits of the long
144
138
  * @param high - The high (signed) 32 bits of the long
145
139
  * @param unsigned - Whether unsigned or not, defaults to signed
146
140
  */
147
- constructor(low: number | bigint | string = 0, high?: number | boolean, unsigned?: boolean) {
141
+ constructor(low: number, high?: number, unsigned?: boolean);
142
+ /**
143
+ * Constructs a 64 bit two's-complement integer, given a bigint representation.
144
+ *
145
+ * @param value - BigInt representation of the long value
146
+ * @param unsigned - Whether unsigned or not, defaults to signed
147
+ */
148
+ constructor(value: bigint, unsigned?: boolean);
149
+ /**
150
+ * Constructs a 64 bit two's-complement integer, given a string representation.
151
+ *
152
+ * @param value - String representation of the long value
153
+ * @param unsigned - Whether unsigned or not, defaults to signed
154
+ */
155
+ constructor(value: string, unsigned?: boolean);
156
+ constructor(
157
+ lowOrValue: number | bigint | string = 0,
158
+ highOrUnsigned?: number | boolean,
159
+ unsigned?: boolean
160
+ ) {
148
161
  super();
149
- if (typeof low === 'bigint') {
150
- Object.assign(this, Long.fromBigInt(low, !!high));
151
- } else if (typeof low === 'string') {
152
- Object.assign(this, Long.fromString(low, !!high));
153
- } else {
154
- this.low = low | 0;
155
- this.high = (high as number) | 0;
156
- this.unsigned = !!unsigned;
157
- }
162
+ const unsignedBool = typeof highOrUnsigned === 'boolean' ? highOrUnsigned : Boolean(unsigned);
163
+ const high = typeof highOrUnsigned === 'number' ? highOrUnsigned : 0;
164
+ const res =
165
+ typeof lowOrValue === 'string'
166
+ ? Long.fromString(lowOrValue, unsignedBool)
167
+ : typeof lowOrValue === 'bigint'
168
+ ? Long.fromBigInt(lowOrValue, unsignedBool)
169
+ : { low: lowOrValue | 0, high: high | 0, unsigned: unsignedBool };
170
+ this.low = res.low;
171
+ this.high = res.high;
172
+ this.unsigned = res.unsigned;
158
173
  }
159
174
 
160
175
  static TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
@@ -243,7 +258,15 @@ export class Long extends BSONValue {
243
258
  * @returns The corresponding Long value
244
259
  */
245
260
  static fromBigInt(value: bigint, unsigned?: boolean): Long {
246
- return Long.fromString(value.toString(), unsigned);
261
+ // eslint-disable-next-line no-restricted-globals
262
+ const FROM_BIGINT_BIT_MASK = BigInt(0xffffffff);
263
+ // eslint-disable-next-line no-restricted-globals
264
+ const FROM_BIGINT_BIT_SHIFT = BigInt(32);
265
+ return new Long(
266
+ Number(value & FROM_BIGINT_BIT_MASK),
267
+ Number((value >> FROM_BIGINT_BIT_SHIFT) & FROM_BIGINT_BIT_MASK),
268
+ unsigned
269
+ );
247
270
  }
248
271
 
249
272
  /**