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 +1 -1
- package/bson.d.ts +3 -3
- package/dist/bson.browser.esm.js +24 -34
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +24 -34
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +24 -34
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +24 -34
- package/dist/bson.esm.js.map +1 -1
- package/lib/decimal128.js +8 -1
- package/lib/decimal128.js.map +1 -1
- package/lib/objectid.js +9 -20
- package/lib/objectid.js.map +1 -1
- package/lib/parser/calculate_size.js +2 -2
- package/lib/parser/calculate_size.js.map +1 -1
- package/lib/parser/serializer.js +6 -11
- package/lib/parser/serializer.js.map +1 -1
- package/package.json +1 -1
- package/src/decimal128.ts +7 -1
- package/src/objectid.ts +12 -29
- package/src/parser/calculate_size.ts +2 -2
- package/src/parser/serializer.ts +6 -8
- package/HISTORY.md +0 -572
package/dist/bson.browser.umd.js
CHANGED
|
@@ -3806,9 +3806,15 @@
|
|
|
3806
3806
|
if (typeof bytes === 'string') {
|
|
3807
3807
|
this.bytes = Decimal128.fromString(bytes).bytes;
|
|
3808
3808
|
}
|
|
3809
|
-
else {
|
|
3809
|
+
else if (isUint8Array(bytes)) {
|
|
3810
|
+
if (bytes.byteLength !== 16) {
|
|
3811
|
+
throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
|
|
3812
|
+
}
|
|
3810
3813
|
this.bytes = bytes;
|
|
3811
3814
|
}
|
|
3815
|
+
else {
|
|
3816
|
+
throw new BSONTypeError('Decimal128 must take a Buffer or string');
|
|
3817
|
+
}
|
|
3812
3818
|
}
|
|
3813
3819
|
/**
|
|
3814
3820
|
* Create a Decimal128 instance from a string representation
|
|
@@ -4593,7 +4599,7 @@
|
|
|
4593
4599
|
this[kId] = buffer_1.from(workingId, 'hex');
|
|
4594
4600
|
}
|
|
4595
4601
|
else {
|
|
4596
|
-
throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters');
|
|
4602
|
+
throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
|
|
4597
4603
|
}
|
|
4598
4604
|
}
|
|
4599
4605
|
else {
|
|
@@ -4710,7 +4716,7 @@
|
|
|
4710
4716
|
return false;
|
|
4711
4717
|
}
|
|
4712
4718
|
if (otherId instanceof ObjectId) {
|
|
4713
|
-
return this
|
|
4719
|
+
return this[kId][11] === otherId[kId][11] && this[kId].equals(otherId[kId]);
|
|
4714
4720
|
}
|
|
4715
4721
|
if (typeof otherId === 'string' &&
|
|
4716
4722
|
ObjectId.isValid(otherId) &&
|
|
@@ -4727,7 +4733,9 @@
|
|
|
4727
4733
|
if (typeof otherId === 'object' &&
|
|
4728
4734
|
'toHexString' in otherId &&
|
|
4729
4735
|
typeof otherId.toHexString === 'function') {
|
|
4730
|
-
|
|
4736
|
+
var otherIdString = otherId.toHexString();
|
|
4737
|
+
var thisIdString = this.toHexString().toLowerCase();
|
|
4738
|
+
return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
|
|
4731
4739
|
}
|
|
4732
4740
|
return false;
|
|
4733
4741
|
};
|
|
@@ -4774,26 +4782,13 @@
|
|
|
4774
4782
|
ObjectId.isValid = function (id) {
|
|
4775
4783
|
if (id == null)
|
|
4776
4784
|
return false;
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
}
|
|
4780
|
-
if (typeof id === 'string') {
|
|
4781
|
-
return id.length === 12 || (id.length === 24 && checkForHexRegExp.test(id));
|
|
4782
|
-
}
|
|
4783
|
-
if (id instanceof ObjectId) {
|
|
4784
|
-
return true;
|
|
4785
|
-
}
|
|
4786
|
-
if (isUint8Array(id) && id.length === 12) {
|
|
4785
|
+
try {
|
|
4786
|
+
new ObjectId(id);
|
|
4787
4787
|
return true;
|
|
4788
4788
|
}
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
if (typeof id.id === 'string') {
|
|
4792
|
-
return id.id.length === 12;
|
|
4793
|
-
}
|
|
4794
|
-
return id.toHexString().length === 24 && checkForHexRegExp.test(id.id.toString('hex'));
|
|
4789
|
+
catch (_a) {
|
|
4790
|
+
return false;
|
|
4795
4791
|
}
|
|
4796
|
-
return false;
|
|
4797
4792
|
};
|
|
4798
4793
|
/** @internal */
|
|
4799
4794
|
ObjectId.prototype.toExtendedJSON = function () {
|
|
@@ -5589,7 +5584,7 @@
|
|
|
5589
5584
|
}
|
|
5590
5585
|
else {
|
|
5591
5586
|
// If we have toBSON defined, override the current object
|
|
5592
|
-
if (object.toBSON) {
|
|
5587
|
+
if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
|
|
5593
5588
|
object = object.toBSON();
|
|
5594
5589
|
}
|
|
5595
5590
|
// Calculate size
|
|
@@ -5607,7 +5602,7 @@
|
|
|
5607
5602
|
if (isArray === void 0) { isArray = false; }
|
|
5608
5603
|
if (ignoreUndefined === void 0) { ignoreUndefined = false; }
|
|
5609
5604
|
// If we have toBSON defined, override the current object
|
|
5610
|
-
if (value
|
|
5605
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
5611
5606
|
value = value.toBSON();
|
|
5612
5607
|
}
|
|
5613
5608
|
switch (typeof value) {
|
|
@@ -7055,9 +7050,7 @@
|
|
|
7055
7050
|
var key = '' + i;
|
|
7056
7051
|
var value = object[i];
|
|
7057
7052
|
// Is there an override value
|
|
7058
|
-
if (value
|
|
7059
|
-
if (typeof value.toBSON !== 'function')
|
|
7060
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
7053
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
7061
7054
|
value = value.toBSON();
|
|
7062
7055
|
}
|
|
7063
7056
|
if (typeof value === 'string') {
|
|
@@ -7233,21 +7226,18 @@
|
|
|
7233
7226
|
}
|
|
7234
7227
|
}
|
|
7235
7228
|
else {
|
|
7236
|
-
|
|
7237
|
-
|
|
7238
|
-
if (typeof object.toBSON !== 'function')
|
|
7239
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
7229
|
+
if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
|
|
7230
|
+
// Provided a custom serialization method
|
|
7240
7231
|
object = object.toBSON();
|
|
7241
|
-
if (object != null && typeof object !== 'object')
|
|
7232
|
+
if (object != null && typeof object !== 'object') {
|
|
7242
7233
|
throw new BSONTypeError('toBSON function did not return an object');
|
|
7234
|
+
}
|
|
7243
7235
|
}
|
|
7244
7236
|
// Iterate over all the keys
|
|
7245
7237
|
for (var key in object) {
|
|
7246
7238
|
var value = object[key];
|
|
7247
7239
|
// Is there an override value
|
|
7248
|
-
if (value
|
|
7249
|
-
if (typeof value.toBSON !== 'function')
|
|
7250
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
7240
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
7251
7241
|
value = value.toBSON();
|
|
7252
7242
|
}
|
|
7253
7243
|
// Check the type of the value
|