bson 4.6.0 → 4.6.2

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.
@@ -3803,9 +3803,15 @@ var BSON = (function (exports) {
3803
3803
  if (typeof bytes === 'string') {
3804
3804
  this.bytes = Decimal128.fromString(bytes).bytes;
3805
3805
  }
3806
- else {
3806
+ else if (isUint8Array(bytes)) {
3807
+ if (bytes.byteLength !== 16) {
3808
+ throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
3809
+ }
3807
3810
  this.bytes = bytes;
3808
3811
  }
3812
+ else {
3813
+ throw new BSONTypeError('Decimal128 must take a Buffer or string');
3814
+ }
3809
3815
  }
3810
3816
  /**
3811
3817
  * Create a Decimal128 instance from a string representation
@@ -4590,7 +4596,7 @@ var BSON = (function (exports) {
4590
4596
  this[kId] = buffer_1.from(workingId, 'hex');
4591
4597
  }
4592
4598
  else {
4593
- throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters');
4599
+ throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
4594
4600
  }
4595
4601
  }
4596
4602
  else {
@@ -4707,7 +4713,7 @@ var BSON = (function (exports) {
4707
4713
  return false;
4708
4714
  }
4709
4715
  if (otherId instanceof ObjectId) {
4710
- return this.toString() === otherId.toString();
4716
+ return this[kId][11] === otherId[kId][11] && this[kId].equals(otherId[kId]);
4711
4717
  }
4712
4718
  if (typeof otherId === 'string' &&
4713
4719
  ObjectId.isValid(otherId) &&
@@ -4724,7 +4730,9 @@ var BSON = (function (exports) {
4724
4730
  if (typeof otherId === 'object' &&
4725
4731
  'toHexString' in otherId &&
4726
4732
  typeof otherId.toHexString === 'function') {
4727
- return otherId.toHexString() === this.toHexString();
4733
+ var otherIdString = otherId.toHexString();
4734
+ var thisIdString = this.toHexString().toLowerCase();
4735
+ return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
4728
4736
  }
4729
4737
  return false;
4730
4738
  };
@@ -4771,26 +4779,13 @@ var BSON = (function (exports) {
4771
4779
  ObjectId.isValid = function (id) {
4772
4780
  if (id == null)
4773
4781
  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) {
4782
+ try {
4783
+ new ObjectId(id);
4784
4784
  return true;
4785
4785
  }
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'));
4786
+ catch (_a) {
4787
+ return false;
4792
4788
  }
4793
- return false;
4794
4789
  };
4795
4790
  /** @internal */
4796
4791
  ObjectId.prototype.toExtendedJSON = function () {
@@ -5586,7 +5581,7 @@ var BSON = (function (exports) {
5586
5581
  }
5587
5582
  else {
5588
5583
  // If we have toBSON defined, override the current object
5589
- if (object.toBSON) {
5584
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
5590
5585
  object = object.toBSON();
5591
5586
  }
5592
5587
  // Calculate size
@@ -5604,7 +5599,7 @@ var BSON = (function (exports) {
5604
5599
  if (isArray === void 0) { isArray = false; }
5605
5600
  if (ignoreUndefined === void 0) { ignoreUndefined = false; }
5606
5601
  // If we have toBSON defined, override the current object
5607
- if (value && value.toBSON) {
5602
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
5608
5603
  value = value.toBSON();
5609
5604
  }
5610
5605
  switch (typeof value) {
@@ -7052,9 +7047,7 @@ var BSON = (function (exports) {
7052
7047
  var key = '' + i;
7053
7048
  var value = object[i];
7054
7049
  // 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');
7050
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7058
7051
  value = value.toBSON();
7059
7052
  }
7060
7053
  if (typeof value === 'string') {
@@ -7230,21 +7223,18 @@ var BSON = (function (exports) {
7230
7223
  }
7231
7224
  }
7232
7225
  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');
7226
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
7227
+ // Provided a custom serialization method
7237
7228
  object = object.toBSON();
7238
- if (object != null && typeof object !== 'object')
7229
+ if (object != null && typeof object !== 'object') {
7239
7230
  throw new BSONTypeError('toBSON function did not return an object');
7231
+ }
7240
7232
  }
7241
7233
  // Iterate over all the keys
7242
7234
  for (var key in object) {
7243
7235
  var value = object[key];
7244
7236
  // 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');
7237
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7248
7238
  value = value.toBSON();
7249
7239
  }
7250
7240
  // Check the type of the value