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
@@ -2444,6 +2444,7 @@ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
2444
2444
  /**
2445
2445
  * A class representation of the BSON Binary type.
2446
2446
  * @public
2447
+ * @category BSONType
2447
2448
  */
2448
2449
  var Binary = /** @class */ (function () {
2449
2450
  /**
@@ -2674,6 +2675,7 @@ Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
2674
2675
  /**
2675
2676
  * A class representation of the BSON Code type.
2676
2677
  * @public
2678
+ * @category BSONType
2677
2679
  */
2678
2680
  var Code = /** @class */ (function () {
2679
2681
  /**
@@ -2722,6 +2724,7 @@ function isDBRefLike(value) {
2722
2724
  /**
2723
2725
  * A class representation of the BSON DBRef type.
2724
2726
  * @public
2727
+ * @category BSONType
2725
2728
  */
2726
2729
  var DBRef = /** @class */ (function () {
2727
2730
  /**
@@ -2826,6 +2829,7 @@ var UINT_CACHE = {};
2826
2829
  /**
2827
2830
  * A class representing a 64-bit integer
2828
2831
  * @public
2832
+ * @category BSONType
2829
2833
  * @remarks
2830
2834
  * The internal representation of a long is the two given signed, 32-bit values.
2831
2835
  * We use 32-bit pieces because these are the size of integers on which
@@ -3788,6 +3792,7 @@ function invalidErr(string, message) {
3788
3792
  /**
3789
3793
  * A class representation of the BSON Decimal128 type.
3790
3794
  * @public
3795
+ * @category BSONType
3791
3796
  */
3792
3797
  var Decimal128 = /** @class */ (function () {
3793
3798
  /**
@@ -3800,9 +3805,15 @@ var Decimal128 = /** @class */ (function () {
3800
3805
  if (typeof bytes === 'string') {
3801
3806
  this.bytes = Decimal128.fromString(bytes).bytes;
3802
3807
  }
3803
- else {
3808
+ else if (isUint8Array(bytes)) {
3809
+ if (bytes.byteLength !== 16) {
3810
+ throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
3811
+ }
3804
3812
  this.bytes = bytes;
3805
3813
  }
3814
+ else {
3815
+ throw new BSONTypeError('Decimal128 must take a Buffer or string');
3816
+ }
3806
3817
  }
3807
3818
  /**
3808
3819
  * Create a Decimal128 instance from a string representation
@@ -4353,6 +4364,7 @@ Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' }
4353
4364
  /**
4354
4365
  * A class representation of the BSON Double type.
4355
4366
  * @public
4367
+ * @category BSONType
4356
4368
  */
4357
4369
  var Double = /** @class */ (function () {
4358
4370
  /**
@@ -4424,6 +4436,7 @@ Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
4424
4436
  /**
4425
4437
  * A class representation of a BSON Int32 type.
4426
4438
  * @public
4439
+ * @category BSONType
4427
4440
  */
4428
4441
  var Int32 = /** @class */ (function () {
4429
4442
  /**
@@ -4477,6 +4490,7 @@ Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
4477
4490
  /**
4478
4491
  * A class representation of the BSON MaxKey type.
4479
4492
  * @public
4493
+ * @category BSONType
4480
4494
  */
4481
4495
  var MaxKey = /** @class */ (function () {
4482
4496
  function MaxKey() {
@@ -4505,6 +4519,7 @@ Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
4505
4519
  /**
4506
4520
  * A class representation of the BSON MinKey type.
4507
4521
  * @public
4522
+ * @category BSONType
4508
4523
  */
4509
4524
  var MinKey = /** @class */ (function () {
4510
4525
  function MinKey() {
@@ -4538,6 +4553,7 @@ var kId = Symbol('id');
4538
4553
  /**
4539
4554
  * A class representation of the BSON ObjectId type.
4540
4555
  * @public
4556
+ * @category BSONType
4541
4557
  */
4542
4558
  var ObjectId = /** @class */ (function () {
4543
4559
  /**
@@ -4587,7 +4603,7 @@ var ObjectId = /** @class */ (function () {
4587
4603
  this[kId] = buffer_1.from(workingId, 'hex');
4588
4604
  }
4589
4605
  else {
4590
- throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters');
4606
+ throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
4591
4607
  }
4592
4608
  }
4593
4609
  else {
@@ -4704,7 +4720,7 @@ var ObjectId = /** @class */ (function () {
4704
4720
  return false;
4705
4721
  }
4706
4722
  if (otherId instanceof ObjectId) {
4707
- return this.toString() === otherId.toString();
4723
+ return this[kId][11] === otherId[kId][11] && this[kId].equals(otherId[kId]);
4708
4724
  }
4709
4725
  if (typeof otherId === 'string' &&
4710
4726
  ObjectId.isValid(otherId) &&
@@ -4721,7 +4737,9 @@ var ObjectId = /** @class */ (function () {
4721
4737
  if (typeof otherId === 'object' &&
4722
4738
  'toHexString' in otherId &&
4723
4739
  typeof otherId.toHexString === 'function') {
4724
- return otherId.toHexString() === this.toHexString();
4740
+ var otherIdString = otherId.toHexString();
4741
+ var thisIdString = this.toHexString().toLowerCase();
4742
+ return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
4725
4743
  }
4726
4744
  return false;
4727
4745
  };
@@ -4768,26 +4786,13 @@ var ObjectId = /** @class */ (function () {
4768
4786
  ObjectId.isValid = function (id) {
4769
4787
  if (id == null)
4770
4788
  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) {
4789
+ try {
4790
+ new ObjectId(id);
4781
4791
  return true;
4782
4792
  }
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'));
4793
+ catch (_a) {
4794
+ return false;
4789
4795
  }
4790
- return false;
4791
4796
  };
4792
4797
  /** @internal */
4793
4798
  ObjectId.prototype.toExtendedJSON = function () {
@@ -4836,6 +4841,7 @@ function alphabetize(str) {
4836
4841
  /**
4837
4842
  * A class representation of the BSON RegExp type.
4838
4843
  * @public
4844
+ * @category BSONType
4839
4845
  */
4840
4846
  var BSONRegExp = /** @class */ (function () {
4841
4847
  /**
@@ -4901,6 +4907,7 @@ Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' }
4901
4907
  /**
4902
4908
  * A class representation of the BSON Symbol type.
4903
4909
  * @public
4910
+ * @category BSONType
4904
4911
  */
4905
4912
  var BSONSymbol = /** @class */ (function () {
4906
4913
  /**
@@ -4943,7 +4950,10 @@ Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
4943
4950
 
4944
4951
  /** @public */
4945
4952
  var LongWithoutOverridesClass = Long;
4946
- /** @public */
4953
+ /**
4954
+ * @public
4955
+ * @category BSONType
4956
+ * */
4947
4957
  var Timestamp = /** @class */ (function (_super) {
4948
4958
  __extends(Timestamp, _super);
4949
4959
  function Timestamp(low, high) {
@@ -5583,7 +5593,7 @@ function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
5583
5593
  }
5584
5594
  else {
5585
5595
  // If we have toBSON defined, override the current object
5586
- if (object.toBSON) {
5596
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
5587
5597
  object = object.toBSON();
5588
5598
  }
5589
5599
  // Calculate size
@@ -5601,7 +5611,7 @@ value, serializeFunctions, isArray, ignoreUndefined) {
5601
5611
  if (isArray === void 0) { isArray = false; }
5602
5612
  if (ignoreUndefined === void 0) { ignoreUndefined = false; }
5603
5613
  // If we have toBSON defined, override the current object
5604
- if (value && value.toBSON) {
5614
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
5605
5615
  value = value.toBSON();
5606
5616
  }
5607
5617
  switch (typeof value) {
@@ -7049,9 +7059,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7049
7059
  var key = '' + i;
7050
7060
  var value = object[i];
7051
7061
  // 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');
7062
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7055
7063
  value = value.toBSON();
7056
7064
  }
7057
7065
  if (typeof value === 'string') {
@@ -7227,21 +7235,18 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
7227
7235
  }
7228
7236
  }
7229
7237
  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');
7238
+ if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
7239
+ // Provided a custom serialization method
7234
7240
  object = object.toBSON();
7235
- if (object != null && typeof object !== 'object')
7241
+ if (object != null && typeof object !== 'object') {
7236
7242
  throw new BSONTypeError('toBSON function did not return an object');
7243
+ }
7237
7244
  }
7238
7245
  // Iterate over all the keys
7239
7246
  for (var key in object) {
7240
7247
  var value = object[key];
7241
7248
  // 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');
7249
+ if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
7245
7250
  value = value.toBSON();
7246
7251
  }
7247
7252
  // Check the type of the value