bson 4.6.0 → 4.6.1
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 +2 -2
- package/dist/bson.browser.esm.js +19 -31
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +19 -31
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +19 -31
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +19 -31
- 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 +4 -17
- 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 +6 -25
- package/src/parser/calculate_size.ts +2 -2
- package/src/parser/serializer.ts +6 -8
- package/HISTORY.md +0 -572
package/dist/bson.esm.js
CHANGED
|
@@ -1769,9 +1769,15 @@ var Decimal128 = /** @class */ (function () {
|
|
|
1769
1769
|
if (typeof bytes === 'string') {
|
|
1770
1770
|
this.bytes = Decimal128.fromString(bytes).bytes;
|
|
1771
1771
|
}
|
|
1772
|
-
else {
|
|
1772
|
+
else if (isUint8Array(bytes)) {
|
|
1773
|
+
if (bytes.byteLength !== 16) {
|
|
1774
|
+
throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
|
|
1775
|
+
}
|
|
1773
1776
|
this.bytes = bytes;
|
|
1774
1777
|
}
|
|
1778
|
+
else {
|
|
1779
|
+
throw new BSONTypeError('Decimal128 must take a Buffer or string');
|
|
1780
|
+
}
|
|
1775
1781
|
}
|
|
1776
1782
|
/**
|
|
1777
1783
|
* Create a Decimal128 instance from a string representation
|
|
@@ -2737,26 +2743,13 @@ var ObjectId = /** @class */ (function () {
|
|
|
2737
2743
|
ObjectId.isValid = function (id) {
|
|
2738
2744
|
if (id == null)
|
|
2739
2745
|
return false;
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
}
|
|
2743
|
-
if (typeof id === 'string') {
|
|
2744
|
-
return id.length === 12 || (id.length === 24 && checkForHexRegExp.test(id));
|
|
2745
|
-
}
|
|
2746
|
-
if (id instanceof ObjectId) {
|
|
2747
|
-
return true;
|
|
2748
|
-
}
|
|
2749
|
-
if (isUint8Array(id) && id.length === 12) {
|
|
2746
|
+
try {
|
|
2747
|
+
new ObjectId(id);
|
|
2750
2748
|
return true;
|
|
2751
2749
|
}
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
if (typeof id.id === 'string') {
|
|
2755
|
-
return id.id.length === 12;
|
|
2756
|
-
}
|
|
2757
|
-
return id.toHexString().length === 24 && checkForHexRegExp.test(id.id.toString('hex'));
|
|
2750
|
+
catch (_a) {
|
|
2751
|
+
return false;
|
|
2758
2752
|
}
|
|
2759
|
-
return false;
|
|
2760
2753
|
};
|
|
2761
2754
|
/** @internal */
|
|
2762
2755
|
ObjectId.prototype.toExtendedJSON = function () {
|
|
@@ -3552,7 +3545,7 @@ function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
|
|
|
3552
3545
|
}
|
|
3553
3546
|
else {
|
|
3554
3547
|
// If we have toBSON defined, override the current object
|
|
3555
|
-
if (object.toBSON) {
|
|
3548
|
+
if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
|
|
3556
3549
|
object = object.toBSON();
|
|
3557
3550
|
}
|
|
3558
3551
|
// Calculate size
|
|
@@ -3570,7 +3563,7 @@ value, serializeFunctions, isArray, ignoreUndefined) {
|
|
|
3570
3563
|
if (isArray === void 0) { isArray = false; }
|
|
3571
3564
|
if (ignoreUndefined === void 0) { ignoreUndefined = false; }
|
|
3572
3565
|
// If we have toBSON defined, override the current object
|
|
3573
|
-
if (value
|
|
3566
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
3574
3567
|
value = value.toBSON();
|
|
3575
3568
|
}
|
|
3576
3569
|
switch (typeof value) {
|
|
@@ -5018,9 +5011,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5018
5011
|
var key = '' + i;
|
|
5019
5012
|
var value = object[i];
|
|
5020
5013
|
// Is there an override value
|
|
5021
|
-
if (value
|
|
5022
|
-
if (typeof value.toBSON !== 'function')
|
|
5023
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
5014
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
5024
5015
|
value = value.toBSON();
|
|
5025
5016
|
}
|
|
5026
5017
|
if (typeof value === 'string') {
|
|
@@ -5196,21 +5187,18 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5196
5187
|
}
|
|
5197
5188
|
}
|
|
5198
5189
|
else {
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
if (typeof object.toBSON !== 'function')
|
|
5202
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
5190
|
+
if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
|
|
5191
|
+
// Provided a custom serialization method
|
|
5203
5192
|
object = object.toBSON();
|
|
5204
|
-
if (object != null && typeof object !== 'object')
|
|
5193
|
+
if (object != null && typeof object !== 'object') {
|
|
5205
5194
|
throw new BSONTypeError('toBSON function did not return an object');
|
|
5195
|
+
}
|
|
5206
5196
|
}
|
|
5207
5197
|
// Iterate over all the keys
|
|
5208
5198
|
for (var key in object) {
|
|
5209
5199
|
var value = object[key];
|
|
5210
5200
|
// Is there an override value
|
|
5211
|
-
if (value
|
|
5212
|
-
if (typeof value.toBSON !== 'function')
|
|
5213
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
5201
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
5214
5202
|
value = value.toBSON();
|
|
5215
5203
|
}
|
|
5216
5204
|
// Check the type of the value
|