bson 4.2.2 → 4.2.3

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.
Files changed (74) hide show
  1. package/HISTORY.md +10 -0
  2. package/bower.json +1 -1
  3. package/bson.d.ts +3 -0
  4. package/dist/bson.browser.esm.js +1507 -952
  5. package/dist/bson.browser.esm.js.map +1 -1
  6. package/dist/bson.browser.umd.js +1507 -952
  7. package/dist/bson.browser.umd.js.map +1 -1
  8. package/dist/bson.bundle.js +1507 -952
  9. package/dist/bson.bundle.js.map +1 -1
  10. package/dist/bson.esm.js +1507 -952
  11. package/dist/bson.esm.js.map +1 -1
  12. package/lib/binary.js +62 -59
  13. package/lib/binary.js.map +1 -1
  14. package/lib/bson.js +55 -51
  15. package/lib/bson.js.map +1 -1
  16. package/lib/code.js +18 -15
  17. package/lib/code.js.map +1 -1
  18. package/lib/db_ref.js +36 -29
  19. package/lib/db_ref.js.map +1 -1
  20. package/lib/decimal128.js +125 -122
  21. package/lib/decimal128.js.map +1 -1
  22. package/lib/double.js +24 -21
  23. package/lib/double.js.map +1 -1
  24. package/lib/ensure_buffer.js +2 -2
  25. package/lib/ensure_buffer.js.map +1 -1
  26. package/lib/extended_json.js +67 -64
  27. package/lib/extended_json.js.map +1 -1
  28. package/lib/float_parser.js +21 -21
  29. package/lib/float_parser.js.map +1 -1
  30. package/lib/int_32.js +19 -16
  31. package/lib/int_32.js.map +1 -1
  32. package/lib/long.js +232 -227
  33. package/lib/long.js.map +1 -1
  34. package/lib/map.js +54 -45
  35. package/lib/map.js.map +1 -1
  36. package/lib/max_key.js +16 -11
  37. package/lib/max_key.js.map +1 -1
  38. package/lib/min_key.js +16 -11
  39. package/lib/min_key.js.map +1 -1
  40. package/lib/objectid.js +93 -82
  41. package/lib/objectid.js.map +1 -1
  42. package/lib/parser/calculate_size.js +12 -9
  43. package/lib/parser/calculate_size.js.map +1 -1
  44. package/lib/parser/deserializer.js +89 -88
  45. package/lib/parser/deserializer.js.map +1 -1
  46. package/lib/parser/serializer.js +94 -75
  47. package/lib/parser/serializer.js.map +1 -1
  48. package/lib/parser/utils.js +19 -8
  49. package/lib/parser/utils.js.map +1 -1
  50. package/lib/regexp.js +15 -12
  51. package/lib/regexp.js.map +1 -1
  52. package/lib/symbol.js +21 -18
  53. package/lib/symbol.js.map +1 -1
  54. package/lib/timestamp.js +48 -27
  55. package/lib/timestamp.js.map +1 -1
  56. package/lib/uuid.js +3 -3
  57. package/lib/uuid.js.map +1 -1
  58. package/lib/validate_utf8.js +12 -12
  59. package/lib/validate_utf8.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/binary.ts +6 -4
  62. package/src/code.ts +6 -2
  63. package/src/db_ref.ts +8 -4
  64. package/src/decimal128.ts +4 -2
  65. package/src/double.ts +4 -2
  66. package/src/int_32.ts +4 -2
  67. package/src/long.ts +6 -4
  68. package/src/max_key.ts +5 -1
  69. package/src/min_key.ts +5 -1
  70. package/src/objectid.ts +3 -1
  71. package/src/parser/utils.ts +1 -1
  72. package/src/regexp.ts +4 -2
  73. package/src/symbol.ts +4 -2
  74. package/src/timestamp.ts +6 -1
package/lib/long.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Long = void 0;
4
- const utils_1 = require("./parser/utils");
4
+ var utils_1 = require("./parser/utils");
5
5
  /**
6
6
  * wasm optimizations, to do native i64 multiplication and divide
7
7
  */
8
- let wasm = undefined;
8
+ var wasm = undefined;
9
9
  try {
10
10
  wasm = new WebAssembly.Instance(new WebAssembly.Module(
11
11
  // prettier-ignore
@@ -14,15 +14,15 @@ try {
14
14
  catch (_a) {
15
15
  // no wasm support
16
16
  }
17
- const TWO_PWR_16_DBL = 1 << 16;
18
- const TWO_PWR_24_DBL = 1 << 24;
19
- const TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
20
- const TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
21
- const TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
17
+ var TWO_PWR_16_DBL = 1 << 16;
18
+ var TWO_PWR_24_DBL = 1 << 24;
19
+ var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
20
+ var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
21
+ var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
22
22
  /** A cache of the Long representations of small integer values. */
23
- const INT_CACHE = {};
23
+ var INT_CACHE = {};
24
24
  /** A cache of the Long representations of small unsigned integer values. */
25
- const UINT_CACHE = {};
25
+ var UINT_CACHE = {};
26
26
  /**
27
27
  * A class representing a 64-bit integer
28
28
  * @public
@@ -41,7 +41,7 @@ const UINT_CACHE = {};
41
41
  * case would often result in infinite recursion.
42
42
  * Common constant values ZERO, ONE, NEG_ONE, etc. are found as static properties on this class.
43
43
  */
44
- class Long {
44
+ var Long = /** @class */ (function () {
45
45
  /**
46
46
  * Constructs a 64 bit two's-complement integer, given its low and high 32 bit values as *signed* integers.
47
47
  * See the from* functions below for more convenient ways of constructing Longs.
@@ -49,7 +49,11 @@ class Long {
49
49
  * @param high - The high (signed) 32 bits of the long
50
50
  * @param unsigned - Whether unsigned or not, defaults to signed
51
51
  */
52
- constructor(low = 0, high = 0, unsigned) {
52
+ function Long(low, high, unsigned) {
53
+ if (low === void 0) { low = 0; }
54
+ if (high === void 0) { high = 0; }
55
+ if (!(this instanceof Long))
56
+ return new Long(low, high, unsigned);
53
57
  this.low = low | 0;
54
58
  this.high = high | 0;
55
59
  this.unsigned = !!unsigned;
@@ -68,17 +72,17 @@ class Long {
68
72
  * @param unsigned - Whether unsigned or not, defaults to signed
69
73
  * @returns The corresponding Long value
70
74
  */
71
- static fromBits(lowBits, highBits, unsigned) {
75
+ Long.fromBits = function (lowBits, highBits, unsigned) {
72
76
  return new Long(lowBits, highBits, unsigned);
73
- }
77
+ };
74
78
  /**
75
79
  * Returns a Long representing the given 32 bit integer value.
76
80
  * @param value - The 32 bit integer in question
77
81
  * @param unsigned - Whether unsigned or not, defaults to signed
78
82
  * @returns The corresponding Long value
79
83
  */
80
- static fromInt(value, unsigned) {
81
- let obj, cachedObj, cache;
84
+ Long.fromInt = function (value, unsigned) {
85
+ var obj, cachedObj, cache;
82
86
  if (unsigned) {
83
87
  value >>>= 0;
84
88
  if ((cache = 0 <= value && value < 256)) {
@@ -103,14 +107,14 @@ class Long {
103
107
  INT_CACHE[value] = obj;
104
108
  return obj;
105
109
  }
106
- }
110
+ };
107
111
  /**
108
112
  * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
109
113
  * @param value - The number in question
110
114
  * @param unsigned - Whether unsigned or not, defaults to signed
111
115
  * @returns The corresponding Long value
112
116
  */
113
- static fromNumber(value, unsigned) {
117
+ Long.fromNumber = function (value, unsigned) {
114
118
  if (isNaN(value))
115
119
  return unsigned ? Long.UZERO : Long.ZERO;
116
120
  if (unsigned) {
@@ -128,16 +132,16 @@ class Long {
128
132
  if (value < 0)
129
133
  return Long.fromNumber(-value, unsigned).neg();
130
134
  return Long.fromBits(value % TWO_PWR_32_DBL | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
131
- }
135
+ };
132
136
  /**
133
137
  * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
134
138
  * @param value - The number in question
135
139
  * @param unsigned - Whether unsigned or not, defaults to signed
136
140
  * @returns The corresponding Long value
137
141
  */
138
- static fromBigInt(value, unsigned) {
142
+ Long.fromBigInt = function (value, unsigned) {
139
143
  return Long.fromString(value.toString(), unsigned);
140
- }
144
+ };
141
145
  /**
142
146
  * Returns a Long representation of the given string, written using the specified radix.
143
147
  * @param str - The textual representation of the Long
@@ -145,7 +149,7 @@ class Long {
145
149
  * @param radix - The radix in which the text is written (2-36), defaults to 10
146
150
  * @returns The corresponding Long value
147
151
  */
148
- static fromString(str, unsigned, radix) {
152
+ Long.fromString = function (str, unsigned, radix) {
149
153
  if (str.length === 0)
150
154
  throw Error('empty string');
151
155
  if (str === 'NaN' || str === 'Infinity' || str === '+Infinity' || str === '-Infinity')
@@ -160,7 +164,7 @@ class Long {
160
164
  radix = radix || 10;
161
165
  if (radix < 2 || 36 < radix)
162
166
  throw RangeError('radix');
163
- let p;
167
+ var p;
164
168
  if ((p = str.indexOf('-')) > 0)
165
169
  throw Error('interior hyphen');
166
170
  else if (p === 0) {
@@ -168,12 +172,12 @@ class Long {
168
172
  }
169
173
  // Do several (8) digits each time through the loop, so as to
170
174
  // minimize the calls to the very expensive emulated div.
171
- const radixToPower = Long.fromNumber(Math.pow(radix, 8));
172
- let result = Long.ZERO;
173
- for (let i = 0; i < str.length; i += 8) {
174
- const size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
175
+ var radixToPower = Long.fromNumber(Math.pow(radix, 8));
176
+ var result = Long.ZERO;
177
+ for (var i = 0; i < str.length; i += 8) {
178
+ var size = Math.min(8, str.length - i), value = parseInt(str.substring(i, i + size), radix);
175
179
  if (size < 8) {
176
- const power = Long.fromNumber(Math.pow(radix, size));
180
+ var power = Long.fromNumber(Math.pow(radix, size));
177
181
  result = result.mul(power).add(Long.fromNumber(value));
178
182
  }
179
183
  else {
@@ -183,7 +187,7 @@ class Long {
183
187
  }
184
188
  result.unsigned = unsigned;
185
189
  return result;
186
- }
190
+ };
187
191
  /**
188
192
  * Creates a Long from its byte representation.
189
193
  * @param bytes - Byte representation
@@ -191,60 +195,60 @@ class Long {
191
195
  * @param le - Whether little or big endian, defaults to big endian
192
196
  * @returns The corresponding Long value
193
197
  */
194
- static fromBytes(bytes, unsigned, le) {
198
+ Long.fromBytes = function (bytes, unsigned, le) {
195
199
  return le ? Long.fromBytesLE(bytes, unsigned) : Long.fromBytesBE(bytes, unsigned);
196
- }
200
+ };
197
201
  /**
198
202
  * Creates a Long from its little endian byte representation.
199
203
  * @param bytes - Little endian byte representation
200
204
  * @param unsigned - Whether unsigned or not, defaults to signed
201
205
  * @returns The corresponding Long value
202
206
  */
203
- static fromBytesLE(bytes, unsigned) {
207
+ Long.fromBytesLE = function (bytes, unsigned) {
204
208
  return new Long(bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24), bytes[4] | (bytes[5] << 8) | (bytes[6] << 16) | (bytes[7] << 24), unsigned);
205
- }
209
+ };
206
210
  /**
207
211
  * Creates a Long from its big endian byte representation.
208
212
  * @param bytes - Big endian byte representation
209
213
  * @param unsigned - Whether unsigned or not, defaults to signed
210
214
  * @returns The corresponding Long value
211
215
  */
212
- static fromBytesBE(bytes, unsigned) {
216
+ Long.fromBytesBE = function (bytes, unsigned) {
213
217
  return new Long((bytes[4] << 24) | (bytes[5] << 16) | (bytes[6] << 8) | bytes[7], (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3], unsigned);
214
- }
218
+ };
215
219
  /**
216
220
  * Tests if the specified object is a Long.
217
221
  */
218
222
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
219
- static isLong(value) {
223
+ Long.isLong = function (value) {
220
224
  return utils_1.isObjectLike(value) && value['__isLong__'] === true;
221
- }
225
+ };
222
226
  /**
223
227
  * Converts the specified value to a Long.
224
228
  * @param unsigned - Whether unsigned or not, defaults to signed
225
229
  */
226
- static fromValue(val, unsigned) {
230
+ Long.fromValue = function (val, unsigned) {
227
231
  if (typeof val === 'number')
228
232
  return Long.fromNumber(val, unsigned);
229
233
  if (typeof val === 'string')
230
234
  return Long.fromString(val, unsigned);
231
235
  // Throws for non-objects, converts non-instanceof Long:
232
236
  return Long.fromBits(val.low, val.high, typeof unsigned === 'boolean' ? unsigned : val.unsigned);
233
- }
237
+ };
234
238
  /** Returns the sum of this and the specified Long. */
235
- add(addend) {
239
+ Long.prototype.add = function (addend) {
236
240
  if (!Long.isLong(addend))
237
241
  addend = Long.fromValue(addend);
238
242
  // Divide each number into 4 chunks of 16 bits, and then sum the chunks.
239
- const a48 = this.high >>> 16;
240
- const a32 = this.high & 0xffff;
241
- const a16 = this.low >>> 16;
242
- const a00 = this.low & 0xffff;
243
- const b48 = addend.high >>> 16;
244
- const b32 = addend.high & 0xffff;
245
- const b16 = addend.low >>> 16;
246
- const b00 = addend.low & 0xffff;
247
- let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
243
+ var a48 = this.high >>> 16;
244
+ var a32 = this.high & 0xffff;
245
+ var a16 = this.low >>> 16;
246
+ var a00 = this.low & 0xffff;
247
+ var b48 = addend.high >>> 16;
248
+ var b32 = addend.high & 0xffff;
249
+ var b16 = addend.low >>> 16;
250
+ var b00 = addend.low & 0xffff;
251
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
248
252
  c00 += a00 + b00;
249
253
  c16 += c00 >>> 16;
250
254
  c00 &= 0xffff;
@@ -257,26 +261,26 @@ class Long {
257
261
  c48 += a48 + b48;
258
262
  c48 &= 0xffff;
259
263
  return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
260
- }
264
+ };
261
265
  /**
262
266
  * Returns the sum of this and the specified Long.
263
267
  * @returns Sum
264
268
  */
265
- and(other) {
269
+ Long.prototype.and = function (other) {
266
270
  if (!Long.isLong(other))
267
271
  other = Long.fromValue(other);
268
272
  return Long.fromBits(this.low & other.low, this.high & other.high, this.unsigned);
269
- }
273
+ };
270
274
  /**
271
275
  * Compares this Long's value with the specified's.
272
276
  * @returns 0 if they are the same, 1 if the this is greater and -1 if the given one is greater
273
277
  */
274
- compare(other) {
278
+ Long.prototype.compare = function (other) {
275
279
  if (!Long.isLong(other))
276
280
  other = Long.fromValue(other);
277
281
  if (this.eq(other))
278
282
  return 0;
279
- const thisNeg = this.isNegative(), otherNeg = other.isNegative();
283
+ var thisNeg = this.isNegative(), otherNeg = other.isNegative();
280
284
  if (thisNeg && !otherNeg)
281
285
  return -1;
282
286
  if (!thisNeg && otherNeg)
@@ -289,16 +293,16 @@ class Long {
289
293
  (other.high === this.high && other.low >>> 0 > this.low >>> 0)
290
294
  ? -1
291
295
  : 1;
292
- }
296
+ };
293
297
  /** This is an alias of {@link Long.compare} */
294
- comp(other) {
298
+ Long.prototype.comp = function (other) {
295
299
  return this.compare(other);
296
- }
300
+ };
297
301
  /**
298
302
  * Returns this Long divided by the specified. The result is signed if this Long is signed or unsigned if this Long is unsigned.
299
303
  * @returns Quotient
300
304
  */
301
- divide(divisor) {
305
+ Long.prototype.divide = function (divisor) {
302
306
  if (!Long.isLong(divisor))
303
307
  divisor = Long.fromValue(divisor);
304
308
  if (divisor.isZero())
@@ -315,12 +319,12 @@ class Long {
315
319
  // be consistent with non-wasm code path
316
320
  return this;
317
321
  }
318
- const low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
322
+ var low = (this.unsigned ? wasm.div_u : wasm.div_s)(this.low, this.high, divisor.low, divisor.high);
319
323
  return Long.fromBits(low, wasm.get_high(), this.unsigned);
320
324
  }
321
325
  if (this.isZero())
322
326
  return this.unsigned ? Long.UZERO : Long.ZERO;
323
- let approx, rem, res;
327
+ var approx, rem, res;
324
328
  if (!this.unsigned) {
325
329
  // This section is only relevant for signed longs and is derived from the
326
330
  // closure library as a whole.
@@ -332,7 +336,7 @@ class Long {
332
336
  return Long.ONE;
333
337
  else {
334
338
  // At this point, we have |other| >= 2, so |this/other| < |MIN_VALUE|.
335
- const halfThis = this.shr(1);
339
+ var halfThis = this.shr(1);
336
340
  approx = halfThis.div(divisor).shl(1);
337
341
  if (approx.eq(Long.ZERO)) {
338
342
  return divisor.isNegative() ? Long.ONE : Long.NEG_ONE;
@@ -379,12 +383,12 @@ class Long {
379
383
  approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
380
384
  // We will tweak the approximate result by changing it in the 48-th digit or
381
385
  // the smallest non-fractional digit, whichever is larger.
382
- const log2 = Math.ceil(Math.log(approx) / Math.LN2);
383
- const delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
386
+ var log2 = Math.ceil(Math.log(approx) / Math.LN2);
387
+ var delta = log2 <= 48 ? 1 : Math.pow(2, log2 - 48);
384
388
  // Decrease the approximation until it is smaller than the remainder. Note
385
389
  // that if it is too large, the product overflows and is negative.
386
- let approxRes = Long.fromNumber(approx);
387
- let approxRem = approxRes.mul(divisor);
390
+ var approxRes = Long.fromNumber(approx);
391
+ var approxRem = approxRes.mul(divisor);
388
392
  while (approxRem.isNegative() || approxRem.gt(rem)) {
389
393
  approx -= delta;
390
394
  approxRes = Long.fromNumber(approx, this.unsigned);
@@ -398,143 +402,143 @@ class Long {
398
402
  rem = rem.sub(approxRem);
399
403
  }
400
404
  return res;
401
- }
405
+ };
402
406
  /**This is an alias of {@link Long.divide} */
403
- div(divisor) {
407
+ Long.prototype.div = function (divisor) {
404
408
  return this.divide(divisor);
405
- }
409
+ };
406
410
  /**
407
411
  * Tests if this Long's value equals the specified's.
408
412
  * @param other - Other value
409
413
  */
410
- equals(other) {
414
+ Long.prototype.equals = function (other) {
411
415
  if (!Long.isLong(other))
412
416
  other = Long.fromValue(other);
413
417
  if (this.unsigned !== other.unsigned && this.high >>> 31 === 1 && other.high >>> 31 === 1)
414
418
  return false;
415
419
  return this.high === other.high && this.low === other.low;
416
- }
420
+ };
417
421
  /** This is an alias of {@link Long.equals} */
418
- eq(other) {
422
+ Long.prototype.eq = function (other) {
419
423
  return this.equals(other);
420
- }
424
+ };
421
425
  /** Gets the high 32 bits as a signed integer. */
422
- getHighBits() {
426
+ Long.prototype.getHighBits = function () {
423
427
  return this.high;
424
- }
428
+ };
425
429
  /** Gets the high 32 bits as an unsigned integer. */
426
- getHighBitsUnsigned() {
430
+ Long.prototype.getHighBitsUnsigned = function () {
427
431
  return this.high >>> 0;
428
- }
432
+ };
429
433
  /** Gets the low 32 bits as a signed integer. */
430
- getLowBits() {
434
+ Long.prototype.getLowBits = function () {
431
435
  return this.low;
432
- }
436
+ };
433
437
  /** Gets the low 32 bits as an unsigned integer. */
434
- getLowBitsUnsigned() {
438
+ Long.prototype.getLowBitsUnsigned = function () {
435
439
  return this.low >>> 0;
436
- }
440
+ };
437
441
  /** Gets the number of bits needed to represent the absolute value of this Long. */
438
- getNumBitsAbs() {
442
+ Long.prototype.getNumBitsAbs = function () {
439
443
  if (this.isNegative()) {
440
444
  // Unsigned Longs are never negative
441
445
  return this.eq(Long.MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
442
446
  }
443
- const val = this.high !== 0 ? this.high : this.low;
444
- let bit;
447
+ var val = this.high !== 0 ? this.high : this.low;
448
+ var bit;
445
449
  for (bit = 31; bit > 0; bit--)
446
450
  if ((val & (1 << bit)) !== 0)
447
451
  break;
448
452
  return this.high !== 0 ? bit + 33 : bit + 1;
449
- }
453
+ };
450
454
  /** Tests if this Long's value is greater than the specified's. */
451
- greaterThan(other) {
455
+ Long.prototype.greaterThan = function (other) {
452
456
  return this.comp(other) > 0;
453
- }
457
+ };
454
458
  /** This is an alias of {@link Long.greaterThan} */
455
- gt(other) {
459
+ Long.prototype.gt = function (other) {
456
460
  return this.greaterThan(other);
457
- }
461
+ };
458
462
  /** Tests if this Long's value is greater than or equal the specified's. */
459
- greaterThanOrEqual(other) {
463
+ Long.prototype.greaterThanOrEqual = function (other) {
460
464
  return this.comp(other) >= 0;
461
- }
465
+ };
462
466
  /** This is an alias of {@link Long.greaterThanOrEqual} */
463
- gte(other) {
467
+ Long.prototype.gte = function (other) {
464
468
  return this.greaterThanOrEqual(other);
465
- }
469
+ };
466
470
  /** This is an alias of {@link Long.greaterThanOrEqual} */
467
- ge(other) {
471
+ Long.prototype.ge = function (other) {
468
472
  return this.greaterThanOrEqual(other);
469
- }
473
+ };
470
474
  /** Tests if this Long's value is even. */
471
- isEven() {
475
+ Long.prototype.isEven = function () {
472
476
  return (this.low & 1) === 0;
473
- }
477
+ };
474
478
  /** Tests if this Long's value is negative. */
475
- isNegative() {
479
+ Long.prototype.isNegative = function () {
476
480
  return !this.unsigned && this.high < 0;
477
- }
481
+ };
478
482
  /** Tests if this Long's value is odd. */
479
- isOdd() {
483
+ Long.prototype.isOdd = function () {
480
484
  return (this.low & 1) === 1;
481
- }
485
+ };
482
486
  /** Tests if this Long's value is positive. */
483
- isPositive() {
487
+ Long.prototype.isPositive = function () {
484
488
  return this.unsigned || this.high >= 0;
485
- }
489
+ };
486
490
  /** Tests if this Long's value equals zero. */
487
- isZero() {
491
+ Long.prototype.isZero = function () {
488
492
  return this.high === 0 && this.low === 0;
489
- }
493
+ };
490
494
  /** Tests if this Long's value is less than the specified's. */
491
- lessThan(other) {
495
+ Long.prototype.lessThan = function (other) {
492
496
  return this.comp(other) < 0;
493
- }
497
+ };
494
498
  /** This is an alias of {@link Long#lessThan}. */
495
- lt(other) {
499
+ Long.prototype.lt = function (other) {
496
500
  return this.lessThan(other);
497
- }
501
+ };
498
502
  /** Tests if this Long's value is less than or equal the specified's. */
499
- lessThanOrEqual(other) {
503
+ Long.prototype.lessThanOrEqual = function (other) {
500
504
  return this.comp(other) <= 0;
501
- }
505
+ };
502
506
  /** This is an alias of {@link Long.lessThanOrEqual} */
503
- lte(other) {
507
+ Long.prototype.lte = function (other) {
504
508
  return this.lessThanOrEqual(other);
505
- }
509
+ };
506
510
  /** Returns this Long modulo the specified. */
507
- modulo(divisor) {
511
+ Long.prototype.modulo = function (divisor) {
508
512
  if (!Long.isLong(divisor))
509
513
  divisor = Long.fromValue(divisor);
510
514
  // use wasm support if present
511
515
  if (wasm) {
512
- const low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
516
+ var low = (this.unsigned ? wasm.rem_u : wasm.rem_s)(this.low, this.high, divisor.low, divisor.high);
513
517
  return Long.fromBits(low, wasm.get_high(), this.unsigned);
514
518
  }
515
519
  return this.sub(this.div(divisor).mul(divisor));
516
- }
520
+ };
517
521
  /** This is an alias of {@link Long.modulo} */
518
- mod(divisor) {
522
+ Long.prototype.mod = function (divisor) {
519
523
  return this.modulo(divisor);
520
- }
524
+ };
521
525
  /** This is an alias of {@link Long.modulo} */
522
- rem(divisor) {
526
+ Long.prototype.rem = function (divisor) {
523
527
  return this.modulo(divisor);
524
- }
528
+ };
525
529
  /**
526
530
  * Returns the product of this and the specified Long.
527
531
  * @param multiplier - Multiplier
528
532
  * @returns Product
529
533
  */
530
- multiply(multiplier) {
534
+ Long.prototype.multiply = function (multiplier) {
531
535
  if (this.isZero())
532
536
  return Long.ZERO;
533
537
  if (!Long.isLong(multiplier))
534
538
  multiplier = Long.fromValue(multiplier);
535
539
  // use wasm support if present
536
540
  if (wasm) {
537
- const low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
541
+ var low = wasm.mul(this.low, this.high, multiplier.low, multiplier.high);
538
542
  return Long.fromBits(low, wasm.get_high(), this.unsigned);
539
543
  }
540
544
  if (multiplier.isZero())
@@ -556,15 +560,15 @@ class Long {
556
560
  return Long.fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
557
561
  // Divide each long into 4 chunks of 16 bits, and then add up 4x4 products.
558
562
  // We can skip products that would overflow.
559
- const a48 = this.high >>> 16;
560
- const a32 = this.high & 0xffff;
561
- const a16 = this.low >>> 16;
562
- const a00 = this.low & 0xffff;
563
- const b48 = multiplier.high >>> 16;
564
- const b32 = multiplier.high & 0xffff;
565
- const b16 = multiplier.low >>> 16;
566
- const b00 = multiplier.low & 0xffff;
567
- let c48 = 0, c32 = 0, c16 = 0, c00 = 0;
563
+ var a48 = this.high >>> 16;
564
+ var a32 = this.high & 0xffff;
565
+ var a16 = this.low >>> 16;
566
+ var a00 = this.low & 0xffff;
567
+ var b48 = multiplier.high >>> 16;
568
+ var b32 = multiplier.high & 0xffff;
569
+ var b16 = multiplier.low >>> 16;
570
+ var b00 = multiplier.low & 0xffff;
571
+ var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
568
572
  c00 += a00 * b00;
569
573
  c16 += c00 >>> 16;
570
574
  c00 &= 0xffff;
@@ -586,51 +590,51 @@ class Long {
586
590
  c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
587
591
  c48 &= 0xffff;
588
592
  return Long.fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
589
- }
593
+ };
590
594
  /** This is an alias of {@link Long.multiply} */
591
- mul(multiplier) {
595
+ Long.prototype.mul = function (multiplier) {
592
596
  return this.multiply(multiplier);
593
- }
597
+ };
594
598
  /** Returns the Negation of this Long's value. */
595
- negate() {
599
+ Long.prototype.negate = function () {
596
600
  if (!this.unsigned && this.eq(Long.MIN_VALUE))
597
601
  return Long.MIN_VALUE;
598
602
  return this.not().add(Long.ONE);
599
- }
603
+ };
600
604
  /** This is an alias of {@link Long.negate} */
601
- neg() {
605
+ Long.prototype.neg = function () {
602
606
  return this.negate();
603
- }
607
+ };
604
608
  /** Returns the bitwise NOT of this Long. */
605
- not() {
609
+ Long.prototype.not = function () {
606
610
  return Long.fromBits(~this.low, ~this.high, this.unsigned);
607
- }
611
+ };
608
612
  /** Tests if this Long's value differs from the specified's. */
609
- notEquals(other) {
613
+ Long.prototype.notEquals = function (other) {
610
614
  return !this.equals(other);
611
- }
615
+ };
612
616
  /** This is an alias of {@link Long.notEquals} */
613
- neq(other) {
617
+ Long.prototype.neq = function (other) {
614
618
  return this.notEquals(other);
615
- }
619
+ };
616
620
  /** This is an alias of {@link Long.notEquals} */
617
- ne(other) {
621
+ Long.prototype.ne = function (other) {
618
622
  return this.notEquals(other);
619
- }
623
+ };
620
624
  /**
621
625
  * Returns the bitwise OR of this Long and the specified.
622
626
  */
623
- or(other) {
627
+ Long.prototype.or = function (other) {
624
628
  if (!Long.isLong(other))
625
629
  other = Long.fromValue(other);
626
630
  return Long.fromBits(this.low | other.low, this.high | other.high, this.unsigned);
627
- }
631
+ };
628
632
  /**
629
633
  * Returns this Long with bits shifted to the left by the given amount.
630
634
  * @param numBits - Number of bits
631
635
  * @returns Shifted Long
632
636
  */
633
- shiftLeft(numBits) {
637
+ Long.prototype.shiftLeft = function (numBits) {
634
638
  if (Long.isLong(numBits))
635
639
  numBits = numBits.toInt();
636
640
  if ((numBits &= 63) === 0)
@@ -639,17 +643,17 @@ class Long {
639
643
  return Long.fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
640
644
  else
641
645
  return Long.fromBits(0, this.low << (numBits - 32), this.unsigned);
642
- }
646
+ };
643
647
  /** This is an alias of {@link Long.shiftLeft} */
644
- shl(numBits) {
648
+ Long.prototype.shl = function (numBits) {
645
649
  return this.shiftLeft(numBits);
646
- }
650
+ };
647
651
  /**
648
652
  * Returns this Long with bits arithmetically shifted to the right by the given amount.
649
653
  * @param numBits - Number of bits
650
654
  * @returns Shifted Long
651
655
  */
652
- shiftRight(numBits) {
656
+ Long.prototype.shiftRight = function (numBits) {
653
657
  if (Long.isLong(numBits))
654
658
  numBits = numBits.toInt();
655
659
  if ((numBits &= 63) === 0)
@@ -658,26 +662,26 @@ class Long {
658
662
  return Long.fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
659
663
  else
660
664
  return Long.fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
661
- }
665
+ };
662
666
  /** This is an alias of {@link Long.shiftRight} */
663
- shr(numBits) {
667
+ Long.prototype.shr = function (numBits) {
664
668
  return this.shiftRight(numBits);
665
- }
669
+ };
666
670
  /**
667
671
  * Returns this Long with bits logically shifted to the right by the given amount.
668
672
  * @param numBits - Number of bits
669
673
  * @returns Shifted Long
670
674
  */
671
- shiftRightUnsigned(numBits) {
675
+ Long.prototype.shiftRightUnsigned = function (numBits) {
672
676
  if (Long.isLong(numBits))
673
677
  numBits = numBits.toInt();
674
678
  numBits &= 63;
675
679
  if (numBits === 0)
676
680
  return this;
677
681
  else {
678
- const high = this.high;
682
+ var high = this.high;
679
683
  if (numBits < 32) {
680
- const low = this.low;
684
+ var low = this.low;
681
685
  return Long.fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
682
686
  }
683
687
  else if (numBits === 32)
@@ -685,57 +689,57 @@ class Long {
685
689
  else
686
690
  return Long.fromBits(high >>> (numBits - 32), 0, this.unsigned);
687
691
  }
688
- }
692
+ };
689
693
  /** This is an alias of {@link Long.shiftRightUnsigned} */
690
- shr_u(numBits) {
694
+ Long.prototype.shr_u = function (numBits) {
691
695
  return this.shiftRightUnsigned(numBits);
692
- }
696
+ };
693
697
  /** This is an alias of {@link Long.shiftRightUnsigned} */
694
- shru(numBits) {
698
+ Long.prototype.shru = function (numBits) {
695
699
  return this.shiftRightUnsigned(numBits);
696
- }
700
+ };
697
701
  /**
698
702
  * Returns the difference of this and the specified Long.
699
703
  * @param subtrahend - Subtrahend
700
704
  * @returns Difference
701
705
  */
702
- subtract(subtrahend) {
706
+ Long.prototype.subtract = function (subtrahend) {
703
707
  if (!Long.isLong(subtrahend))
704
708
  subtrahend = Long.fromValue(subtrahend);
705
709
  return this.add(subtrahend.neg());
706
- }
710
+ };
707
711
  /** This is an alias of {@link Long.subtract} */
708
- sub(subtrahend) {
712
+ Long.prototype.sub = function (subtrahend) {
709
713
  return this.subtract(subtrahend);
710
- }
714
+ };
711
715
  /** Converts the Long to a 32 bit integer, assuming it is a 32 bit integer. */
712
- toInt() {
716
+ Long.prototype.toInt = function () {
713
717
  return this.unsigned ? this.low >>> 0 : this.low;
714
- }
718
+ };
715
719
  /** Converts the Long to a the nearest floating-point representation of this value (double, 53 bit mantissa). */
716
- toNumber() {
720
+ Long.prototype.toNumber = function () {
717
721
  if (this.unsigned)
718
722
  return (this.high >>> 0) * TWO_PWR_32_DBL + (this.low >>> 0);
719
723
  return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
720
- }
724
+ };
721
725
  /** Converts the Long to a BigInt (arbitrary precision). */
722
- toBigInt() {
726
+ Long.prototype.toBigInt = function () {
723
727
  return BigInt(this.toString());
724
- }
728
+ };
725
729
  /**
726
730
  * Converts this Long to its byte representation.
727
731
  * @param le - Whether little or big endian, defaults to big endian
728
732
  * @returns Byte representation
729
733
  */
730
- toBytes(le) {
734
+ Long.prototype.toBytes = function (le) {
731
735
  return le ? this.toBytesLE() : this.toBytesBE();
732
- }
736
+ };
733
737
  /**
734
738
  * Converts this Long to its little endian byte representation.
735
739
  * @returns Little endian byte representation
736
740
  */
737
- toBytesLE() {
738
- const hi = this.high, lo = this.low;
741
+ Long.prototype.toBytesLE = function () {
742
+ var hi = this.high, lo = this.low;
739
743
  return [
740
744
  lo & 0xff,
741
745
  (lo >>> 8) & 0xff,
@@ -746,13 +750,13 @@ class Long {
746
750
  (hi >>> 16) & 0xff,
747
751
  hi >>> 24
748
752
  ];
749
- }
753
+ };
750
754
  /**
751
755
  * Converts this Long to its big endian byte representation.
752
756
  * @returns Big endian byte representation
753
757
  */
754
- toBytesBE() {
755
- const hi = this.high, lo = this.low;
758
+ Long.prototype.toBytesBE = function () {
759
+ var hi = this.high, lo = this.low;
756
760
  return [
757
761
  hi >>> 24,
758
762
  (hi >>> 16) & 0xff,
@@ -763,21 +767,21 @@ class Long {
763
767
  (lo >>> 8) & 0xff,
764
768
  lo & 0xff
765
769
  ];
766
- }
770
+ };
767
771
  /**
768
772
  * Converts this Long to signed.
769
773
  */
770
- toSigned() {
774
+ Long.prototype.toSigned = function () {
771
775
  if (!this.unsigned)
772
776
  return this;
773
777
  return Long.fromBits(this.low, this.high, false);
774
- }
778
+ };
775
779
  /**
776
780
  * Converts the Long to a string written in the specified radix.
777
781
  * @param radix - Radix (2-36), defaults to 10
778
782
  * @throws RangeError If `radix` is out of range
779
783
  */
780
- toString(radix) {
784
+ Long.prototype.toString = function (radix) {
781
785
  radix = radix || 10;
782
786
  if (radix < 2 || 36 < radix)
783
787
  throw RangeError('radix');
@@ -788,7 +792,7 @@ class Long {
788
792
  if (this.eq(Long.MIN_VALUE)) {
789
793
  // We need to change the Long value before it can be negated, so we remove
790
794
  // the bottom-most digit in this base and then recurse to do the rest.
791
- const radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
795
+ var radixLong = Long.fromNumber(radix), div = this.div(radixLong), rem1 = div.mul(radixLong).sub(this);
792
796
  return div.toString(radix) + rem1.toInt().toString(radix);
793
797
  }
794
798
  else
@@ -796,15 +800,15 @@ class Long {
796
800
  }
797
801
  // Do several (6) digits each time through the loop, so as to
798
802
  // minimize the calls to the very expensive emulated div.
799
- const radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);
803
+ var radixToPower = Long.fromNumber(Math.pow(radix, 6), this.unsigned);
800
804
  // eslint-disable-next-line @typescript-eslint/no-this-alias
801
- let rem = this;
802
- let result = '';
805
+ var rem = this;
806
+ var result = '';
803
807
  // eslint-disable-next-line no-constant-condition
804
808
  while (true) {
805
- const remDiv = rem.div(radixToPower);
806
- const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
807
- let digits = intval.toString(radix);
809
+ var remDiv = rem.div(radixToPower);
810
+ var intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
811
+ var digits = intval.toString(radix);
808
812
  rem = remDiv;
809
813
  if (rem.isZero()) {
810
814
  return digits + result;
@@ -815,67 +819,68 @@ class Long {
815
819
  result = '' + digits + result;
816
820
  }
817
821
  }
818
- }
822
+ };
819
823
  /** Converts this Long to unsigned. */
820
- toUnsigned() {
824
+ Long.prototype.toUnsigned = function () {
821
825
  if (this.unsigned)
822
826
  return this;
823
827
  return Long.fromBits(this.low, this.high, true);
824
- }
828
+ };
825
829
  /** Returns the bitwise XOR of this Long and the given one. */
826
- xor(other) {
830
+ Long.prototype.xor = function (other) {
827
831
  if (!Long.isLong(other))
828
832
  other = Long.fromValue(other);
829
833
  return Long.fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
830
- }
834
+ };
831
835
  /** This is an alias of {@link Long.isZero} */
832
- eqz() {
836
+ Long.prototype.eqz = function () {
833
837
  return this.isZero();
834
- }
838
+ };
835
839
  /** This is an alias of {@link Long.lessThanOrEqual} */
836
- le(other) {
840
+ Long.prototype.le = function (other) {
837
841
  return this.lessThanOrEqual(other);
838
- }
842
+ };
839
843
  /*
840
844
  ****************************************************************
841
845
  * BSON SPECIFIC ADDITIONS *
842
846
  ****************************************************************
843
847
  */
844
- toExtendedJSON(options) {
848
+ Long.prototype.toExtendedJSON = function (options) {
845
849
  if (options && options.relaxed)
846
850
  return this.toNumber();
847
851
  return { $numberLong: this.toString() };
848
- }
849
- static fromExtendedJSON(doc, options) {
850
- const result = Long.fromString(doc.$numberLong);
852
+ };
853
+ Long.fromExtendedJSON = function (doc, options) {
854
+ var result = Long.fromString(doc.$numberLong);
851
855
  return options && options.relaxed ? result.toNumber() : result;
852
- }
856
+ };
853
857
  /** @internal */
854
- [Symbol.for('nodejs.util.inspect.custom')]() {
858
+ Long.prototype[Symbol.for('nodejs.util.inspect.custom')] = function () {
855
859
  return this.inspect();
856
- }
857
- inspect() {
858
- return `Long("${this.toString()}")`;
859
- }
860
- }
860
+ };
861
+ Long.prototype.inspect = function () {
862
+ return "new Long(\"" + this.toString() + "\")";
863
+ };
864
+ Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
865
+ /** Maximum unsigned value. */
866
+ Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
867
+ /** Signed zero */
868
+ Long.ZERO = Long.fromInt(0);
869
+ /** Unsigned zero. */
870
+ Long.UZERO = Long.fromInt(0, true);
871
+ /** Signed one. */
872
+ Long.ONE = Long.fromInt(1);
873
+ /** Unsigned one. */
874
+ Long.UONE = Long.fromInt(1, true);
875
+ /** Signed negative one. */
876
+ Long.NEG_ONE = Long.fromInt(-1);
877
+ /** Maximum signed value. */
878
+ Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
879
+ /** Minimum signed value. */
880
+ Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
881
+ return Long;
882
+ }());
861
883
  exports.Long = Long;
862
- Long.TWO_PWR_24 = Long.fromInt(TWO_PWR_24_DBL);
863
- /** Maximum unsigned value. */
864
- Long.MAX_UNSIGNED_VALUE = Long.fromBits(0xffffffff | 0, 0xffffffff | 0, true);
865
- /** Signed zero */
866
- Long.ZERO = Long.fromInt(0);
867
- /** Unsigned zero. */
868
- Long.UZERO = Long.fromInt(0, true);
869
- /** Signed one. */
870
- Long.ONE = Long.fromInt(1);
871
- /** Unsigned one. */
872
- Long.UONE = Long.fromInt(1, true);
873
- /** Signed negative one. */
874
- Long.NEG_ONE = Long.fromInt(-1);
875
- /** Maximum signed value. */
876
- Long.MAX_VALUE = Long.fromBits(0xffffffff | 0, 0x7fffffff | 0, false);
877
- /** Minimum signed value. */
878
- Long.MIN_VALUE = Long.fromBits(0, 0x80000000 | 0, false);
879
884
  Object.defineProperty(Long.prototype, '__isLong__', { value: true });
880
885
  Object.defineProperty(Long.prototype, '_bsontype', { value: 'Long' });
881
886
  //# sourceMappingURL=long.js.map