bson 4.6.0 → 4.6.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 (58) hide show
  1. package/bower.json +1 -1
  2. package/bson-ts34.d.ts +1133 -0
  3. package/bson.d.ts +1228 -1118
  4. package/dist/bson.browser.esm.js +40 -35
  5. package/dist/bson.browser.esm.js.map +1 -1
  6. package/dist/bson.browser.umd.js +40 -35
  7. package/dist/bson.browser.umd.js.map +1 -1
  8. package/dist/bson.bundle.js +40 -35
  9. package/dist/bson.bundle.js.map +1 -1
  10. package/dist/bson.esm.js +40 -35
  11. package/dist/bson.esm.js.map +1 -1
  12. package/lib/binary.js +1 -0
  13. package/lib/binary.js.map +1 -1
  14. package/lib/code.js +1 -0
  15. package/lib/code.js.map +1 -1
  16. package/lib/db_ref.js +1 -0
  17. package/lib/db_ref.js.map +1 -1
  18. package/lib/decimal128.js +9 -1
  19. package/lib/decimal128.js.map +1 -1
  20. package/lib/double.js +1 -0
  21. package/lib/double.js.map +1 -1
  22. package/lib/int_32.js +1 -0
  23. package/lib/int_32.js.map +1 -1
  24. package/lib/long.js +1 -0
  25. package/lib/long.js.map +1 -1
  26. package/lib/max_key.js +1 -0
  27. package/lib/max_key.js.map +1 -1
  28. package/lib/min_key.js +1 -0
  29. package/lib/min_key.js.map +1 -1
  30. package/lib/objectid.js +10 -20
  31. package/lib/objectid.js.map +1 -1
  32. package/lib/parser/calculate_size.js +2 -2
  33. package/lib/parser/calculate_size.js.map +1 -1
  34. package/lib/parser/serializer.js +6 -11
  35. package/lib/parser/serializer.js.map +1 -1
  36. package/lib/regexp.js +1 -0
  37. package/lib/regexp.js.map +1 -1
  38. package/lib/symbol.js +1 -0
  39. package/lib/symbol.js.map +1 -1
  40. package/lib/timestamp.js +4 -1
  41. package/lib/timestamp.js.map +1 -1
  42. package/package.json +11 -3
  43. package/src/binary.ts +1 -0
  44. package/src/code.ts +1 -0
  45. package/src/db_ref.ts +1 -0
  46. package/src/decimal128.ts +8 -1
  47. package/src/double.ts +1 -0
  48. package/src/int_32.ts +1 -0
  49. package/src/long.ts +1 -0
  50. package/src/max_key.ts +1 -0
  51. package/src/min_key.ts +1 -0
  52. package/src/objectid.ts +13 -29
  53. package/src/parser/calculate_size.ts +2 -2
  54. package/src/parser/serializer.ts +6 -8
  55. package/src/regexp.ts +1 -0
  56. package/src/symbol.ts +1 -0
  57. package/src/timestamp.ts +4 -1
  58. package/HISTORY.md +0 -572
@@ -2447,6 +2447,7 @@ var BSON = (function (exports) {
2447
2447
  /**
2448
2448
  * A class representation of the BSON Binary type.
2449
2449
  * @public
2450
+ * @category BSONType
2450
2451
  */
2451
2452
  var Binary = /** @class */ (function () {
2452
2453
  /**
@@ -2677,6 +2678,7 @@ var BSON = (function (exports) {
2677
2678
  /**
2678
2679
  * A class representation of the BSON Code type.
2679
2680
  * @public
2681
+ * @category BSONType
2680
2682
  */
2681
2683
  var Code = /** @class */ (function () {
2682
2684
  /**
@@ -2725,6 +2727,7 @@ var BSON = (function (exports) {
2725
2727
  /**
2726
2728
  * A class representation of the BSON DBRef type.
2727
2729
  * @public
2730
+ * @category BSONType
2728
2731
  */
2729
2732
  var DBRef = /** @class */ (function () {
2730
2733
  /**
@@ -2829,6 +2832,7 @@ var BSON = (function (exports) {
2829
2832
  /**
2830
2833
  * A class representing a 64-bit integer
2831
2834
  * @public
2835
+ * @category BSONType
2832
2836
  * @remarks
2833
2837
  * The internal representation of a long is the two given signed, 32-bit values.
2834
2838
  * We use 32-bit pieces because these are the size of integers on which
@@ -3791,6 +3795,7 @@ var BSON = (function (exports) {
3791
3795
  /**
3792
3796
  * A class representation of the BSON Decimal128 type.
3793
3797
  * @public
3798
+ * @category BSONType
3794
3799
  */
3795
3800
  var Decimal128 = /** @class */ (function () {
3796
3801
  /**
@@ -3803,9 +3808,15 @@ var BSON = (function (exports) {
3803
3808
  if (typeof bytes === 'string') {
3804
3809
  this.bytes = Decimal128.fromString(bytes).bytes;
3805
3810
  }
3806
- else {
3811
+ else if (isUint8Array(bytes)) {
3812
+ if (bytes.byteLength !== 16) {
3813
+ throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
3814
+ }
3807
3815
  this.bytes = bytes;
3808
3816
  }
3817
+ else {
3818
+ throw new BSONTypeError('Decimal128 must take a Buffer or string');
3819
+ }
3809
3820
  }
3810
3821
  /**
3811
3822
  * Create a Decimal128 instance from a string representation
@@ -4356,6 +4367,7 @@ var BSON = (function (exports) {
4356
4367
  /**
4357
4368
  * A class representation of the BSON Double type.
4358
4369
  * @public
4370
+ * @category BSONType
4359
4371
  */
4360
4372
  var Double = /** @class */ (function () {
4361
4373
  /**
@@ -4427,6 +4439,7 @@ var BSON = (function (exports) {
4427
4439
  /**
4428
4440
  * A class representation of a BSON Int32 type.
4429
4441
  * @public
4442
+ * @category BSONType
4430
4443
  */
4431
4444
  var Int32 = /** @class */ (function () {
4432
4445
  /**
@@ -4480,6 +4493,7 @@ var BSON = (function (exports) {
4480
4493
  /**
4481
4494
  * A class representation of the BSON MaxKey type.
4482
4495
  * @public
4496
+ * @category BSONType
4483
4497
  */
4484
4498
  var MaxKey = /** @class */ (function () {
4485
4499
  function MaxKey() {
@@ -4508,6 +4522,7 @@ var BSON = (function (exports) {
4508
4522
  /**
4509
4523
  * A class representation of the BSON MinKey type.
4510
4524
  * @public
4525
+ * @category BSONType
4511
4526
  */
4512
4527
  var MinKey = /** @class */ (function () {
4513
4528
  function MinKey() {
@@ -4541,6 +4556,7 @@ var BSON = (function (exports) {
4541
4556
  /**
4542
4557
  * A class representation of the BSON ObjectId type.
4543
4558
  * @public
4559
+ * @category BSONType
4544
4560
  */
4545
4561
  var ObjectId = /** @class */ (function () {
4546
4562
  /**
@@ -4590,7 +4606,7 @@ var BSON = (function (exports) {
4590
4606
  this[kId] = buffer_1.from(workingId, 'hex');
4591
4607
  }
4592
4608
  else {
4593
- throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters');
4609
+ throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
4594
4610
  }
4595
4611
  }
4596
4612
  else {
@@ -4707,7 +4723,7 @@ var BSON = (function (exports) {
4707
4723
  return false;
4708
4724
  }
4709
4725
  if (otherId instanceof ObjectId) {
4710
- return this.toString() === otherId.toString();
4726
+ return this[kId][11] === otherId[kId][11] && this[kId].equals(otherId[kId]);
4711
4727
  }
4712
4728
  if (typeof otherId === 'string' &&
4713
4729
  ObjectId.isValid(otherId) &&
@@ -4724,7 +4740,9 @@ var BSON = (function (exports) {
4724
4740
  if (typeof otherId === 'object' &&
4725
4741
  'toHexString' in otherId &&
4726
4742
  typeof otherId.toHexString === 'function') {
4727
- return otherId.toHexString() === this.toHexString();
4743
+ var otherIdString = otherId.toHexString();
4744
+ var thisIdString = this.toHexString().toLowerCase();
4745
+ return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
4728
4746
  }
4729
4747
  return false;
4730
4748
  };
@@ -4771,26 +4789,13 @@ var BSON = (function (exports) {
4771
4789
  ObjectId.isValid = function (id) {
4772
4790
  if (id == null)
4773
4791
  return false;
4774
- if (typeof id === 'number') {
4775
- return true;
4776
- }
4777
- if (typeof id === 'string') {
4778
- return id.length === 12 || (id.length === 24 && checkForHexRegExp.test(id));
4779
- }
4780
- if (id instanceof ObjectId) {
4781
- return true;
4782
- }
4783
- if (isUint8Array(id) && id.length === 12) {
4792
+ try {
4793
+ new ObjectId(id);
4784
4794
  return true;
4785
4795
  }
4786
- // Duck-Typing detection of ObjectId like objects
4787
- if (typeof id === 'object' && 'toHexString' in id && typeof id.toHexString === 'function') {
4788
- if (typeof id.id === 'string') {
4789
- return id.id.length === 12;
4790
- }
4791
- return id.toHexString().length === 24 && checkForHexRegExp.test(id.id.toString('hex'));
4796
+ catch (_a) {
4797
+ return false;
4792
4798
  }
4793
- return false;
4794
4799
  };
4795
4800
  /** @internal */
4796
4801
  ObjectId.prototype.toExtendedJSON = function () {
@@ -4839,6 +4844,7 @@ var BSON = (function (exports) {
4839
4844
  /**
4840
4845
  * A class representation of the BSON RegExp type.
4841
4846
  * @public
4847
+ * @category BSONType
4842
4848
  */
4843
4849
  var BSONRegExp = /** @class */ (function () {
4844
4850
  /**
@@ -4904,6 +4910,7 @@ var BSON = (function (exports) {
4904
4910
  /**
4905
4911
  * A class representation of the BSON Symbol type.
4906
4912
  * @public
4913
+ * @category BSONType
4907
4914
  */
4908
4915
  var BSONSymbol = /** @class */ (function () {
4909
4916
  /**
@@ -4946,7 +4953,10 @@ var BSON = (function (exports) {
4946
4953
 
4947
4954
  /** @public */
4948
4955
  var LongWithoutOverridesClass = Long;
4949
- /** @public */
4956
+ /**
4957
+ * @public
4958
+ * @category BSONType
4959
+ * */
4950
4960
  var Timestamp = /** @class */ (function (_super) {
4951
4961
  __extends(Timestamp, _super);
4952
4962
  function Timestamp(low, high) {
@@ -5586,7 +5596,7 @@ var BSON = (function (exports) {
5586
5596
  }
5587
5597
  else {
5588
5598
  // If we have toBSON defined, override the current object
5589
- if (object.toBSON) {
5599
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
5590
5600
  object = object.toBSON();
5591
5601
  }
5592
5602
  // Calculate size
@@ -5604,7 +5614,7 @@ var BSON = (function (exports) {
5604
5614
  if (isArray === void 0) { isArray = false; }
5605
5615
  if (ignoreUndefined === void 0) { ignoreUndefined = false; }
5606
5616
  // If we have toBSON defined, override the current object
5607
- if (value && value.toBSON) {
5617
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
5608
5618
  value = value.toBSON();
5609
5619
  }
5610
5620
  switch (typeof value) {
@@ -7052,9 +7062,7 @@ var BSON = (function (exports) {
7052
7062
  var key = '' + i;
7053
7063
  var value = object[i];
7054
7064
  // Is there an override value
7055
- if (value && value.toBSON) {
7056
- if (typeof value.toBSON !== 'function')
7057
- throw new BSONTypeError('toBSON is not a function');
7065
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7058
7066
  value = value.toBSON();
7059
7067
  }
7060
7068
  if (typeof value === 'string') {
@@ -7230,21 +7238,18 @@ var BSON = (function (exports) {
7230
7238
  }
7231
7239
  }
7232
7240
  else {
7233
- // Did we provide a custom serialization method
7234
- if (object.toBSON) {
7235
- if (typeof object.toBSON !== 'function')
7236
- throw new BSONTypeError('toBSON is not a function');
7241
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
7242
+ // Provided a custom serialization method
7237
7243
  object = object.toBSON();
7238
- if (object != null && typeof object !== 'object')
7244
+ if (object != null && typeof object !== 'object') {
7239
7245
  throw new BSONTypeError('toBSON function did not return an object');
7246
+ }
7240
7247
  }
7241
7248
  // Iterate over all the keys
7242
7249
  for (var key in object) {
7243
7250
  var value = object[key];
7244
7251
  // Is there an override value
7245
- if (value && value.toBSON) {
7246
- if (typeof value.toBSON !== 'function')
7247
- throw new BSONTypeError('toBSON is not a function');
7252
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7248
7253
  value = value.toBSON();
7249
7254
  }
7250
7255
  // Check the type of the value