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.
package/bower.json CHANGED
@@ -22,5 +22,5 @@
22
22
  "test",
23
23
  "tools"
24
24
  ],
25
- "version": "4.6.0"
25
+ "version": "4.6.2"
26
26
  }
package/bson.d.ts CHANGED
@@ -875,7 +875,7 @@ export declare interface MinKeyExtended {
875
875
  * @public
876
876
  */
877
877
  declare class ObjectId {
878
- _bsontype: 'ObjectId';
878
+ _bsontype: 'ObjectID';
879
879
  /* Excluded from this release type: index */
880
880
  static cacheHexString: boolean;
881
881
  /* Excluded from this release type: [kId] */
@@ -885,7 +885,7 @@ declare class ObjectId {
885
885
  *
886
886
  * @param inputId - Can be a 24 character hex string, 12 byte binary Buffer, or a number.
887
887
  */
888
- constructor(inputId?: string | Buffer | number | ObjectIdLike | ObjectId);
888
+ constructor(inputId?: string | number | ObjectId | ObjectIdLike | Buffer | Uint8Array);
889
889
  /*
890
890
  * The ObjectId bytes
891
891
  * @readonly
@@ -939,7 +939,7 @@ declare class ObjectId {
939
939
  *
940
940
  * @param id - ObjectId instance to validate.
941
941
  */
942
- static isValid(id: number | string | ObjectId | Uint8Array | ObjectIdLike): boolean;
942
+ static isValid(id: string | number | ObjectId | ObjectIdLike | Buffer | Uint8Array): boolean;
943
943
  /* Excluded from this release type: toExtendedJSON */
944
944
  /* Excluded from this release type: fromExtendedJSON */
945
945
  inspect(): string;
@@ -3800,9 +3800,15 @@ var Decimal128 = /** @class */ (function () {
3800
3800
  if (typeof bytes === 'string') {
3801
3801
  this.bytes = Decimal128.fromString(bytes).bytes;
3802
3802
  }
3803
- else {
3803
+ else if (isUint8Array(bytes)) {
3804
+ if (bytes.byteLength !== 16) {
3805
+ throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
3806
+ }
3804
3807
  this.bytes = bytes;
3805
3808
  }
3809
+ else {
3810
+ throw new BSONTypeError('Decimal128 must take a Buffer or string');
3811
+ }
3806
3812
  }
3807
3813
  /**
3808
3814
  * Create a Decimal128 instance from a string representation
@@ -4587,7 +4593,7 @@ var ObjectId = /** @class */ (function () {
4587
4593
  this[kId] = buffer_1.from(workingId, 'hex');
4588
4594
  }
4589
4595
  else {
4590
- throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters');
4596
+ throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
4591
4597
  }
4592
4598
  }
4593
4599
  else {
@@ -4704,7 +4710,7 @@ var ObjectId = /** @class */ (function () {
4704
4710
  return false;
4705
4711
  }
4706
4712
  if (otherId instanceof ObjectId) {
4707
- return this.toString() === otherId.toString();
4713
+ return this[kId][11] === otherId[kId][11] && this[kId].equals(otherId[kId]);
4708
4714
  }
4709
4715
  if (typeof otherId === 'string' &&
4710
4716
  ObjectId.isValid(otherId) &&
@@ -4721,7 +4727,9 @@ var ObjectId = /** @class */ (function () {
4721
4727
  if (typeof otherId === 'object' &&
4722
4728
  'toHexString' in otherId &&
4723
4729
  typeof otherId.toHexString === 'function') {
4724
- return otherId.toHexString() === this.toHexString();
4730
+ var otherIdString = otherId.toHexString();
4731
+ var thisIdString = this.toHexString().toLowerCase();
4732
+ return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
4725
4733
  }
4726
4734
  return false;
4727
4735
  };
@@ -4768,26 +4776,13 @@ var ObjectId = /** @class */ (function () {
4768
4776
  ObjectId.isValid = function (id) {
4769
4777
  if (id == null)
4770
4778
  return false;
4771
- if (typeof id === 'number') {
4772
- return true;
4773
- }
4774
- if (typeof id === 'string') {
4775
- return id.length === 12 || (id.length === 24 && checkForHexRegExp.test(id));
4776
- }
4777
- if (id instanceof ObjectId) {
4778
- return true;
4779
- }
4780
- if (isUint8Array(id) && id.length === 12) {
4779
+ try {
4780
+ new ObjectId(id);
4781
4781
  return true;
4782
4782
  }
4783
- // Duck-Typing detection of ObjectId like objects
4784
- if (typeof id === 'object' && 'toHexString' in id && typeof id.toHexString === 'function') {
4785
- if (typeof id.id === 'string') {
4786
- return id.id.length === 12;
4787
- }
4788
- return id.toHexString().length === 24 && checkForHexRegExp.test(id.id.toString('hex'));
4783
+ catch (_a) {
4784
+ return false;
4789
4785
  }
4790
- return false;
4791
4786
  };
4792
4787
  /** @internal */
4793
4788
  ObjectId.prototype.toExtendedJSON = function () {
@@ -5583,7 +5578,7 @@ function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
5583
5578
  }
5584
5579
  else {
5585
5580
  // If we have toBSON defined, override the current object
5586
- if (object.toBSON) {
5581
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
5587
5582
  object = object.toBSON();
5588
5583
  }
5589
5584
  // Calculate size
@@ -5601,7 +5596,7 @@ value, serializeFunctions, isArray, ignoreUndefined) {
5601
5596
  if (isArray === void 0) { isArray = false; }
5602
5597
  if (ignoreUndefined === void 0) { ignoreUndefined = false; }
5603
5598
  // If we have toBSON defined, override the current object
5604
- if (value && value.toBSON) {
5599
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
5605
5600
  value = value.toBSON();
5606
5601
  }
5607
5602
  switch (typeof value) {
@@ -7049,9 +7044,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7049
7044
  var key = '' + i;
7050
7045
  var value = object[i];
7051
7046
  // Is there an override value
7052
- if (value && value.toBSON) {
7053
- if (typeof value.toBSON !== 'function')
7054
- throw new BSONTypeError('toBSON is not a function');
7047
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7055
7048
  value = value.toBSON();
7056
7049
  }
7057
7050
  if (typeof value === 'string') {
@@ -7227,21 +7220,18 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7227
7220
  }
7228
7221
  }
7229
7222
  else {
7230
- // Did we provide a custom serialization method
7231
- if (object.toBSON) {
7232
- if (typeof object.toBSON !== 'function')
7233
- throw new BSONTypeError('toBSON is not a function');
7223
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
7224
+ // Provided a custom serialization method
7234
7225
  object = object.toBSON();
7235
- if (object != null && typeof object !== 'object')
7226
+ if (object != null && typeof object !== 'object') {
7236
7227
  throw new BSONTypeError('toBSON function did not return an object');
7228
+ }
7237
7229
  }
7238
7230
  // Iterate over all the keys
7239
7231
  for (var key in object) {
7240
7232
  var value = object[key];
7241
7233
  // Is there an override value
7242
- if (value && value.toBSON) {
7243
- if (typeof value.toBSON !== 'function')
7244
- throw new BSONTypeError('toBSON is not a function');
7234
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7245
7235
  value = value.toBSON();
7246
7236
  }
7247
7237
  // Check the type of the value