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.
- package/bower.json +1 -1
- package/bson-ts34.d.ts +1133 -0
- package/bson.d.ts +1228 -1118
- package/dist/bson.browser.esm.js +40 -35
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +40 -35
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +40 -35
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +40 -35
- package/dist/bson.esm.js.map +1 -1
- package/lib/binary.js +1 -0
- package/lib/binary.js.map +1 -1
- package/lib/code.js +1 -0
- package/lib/code.js.map +1 -1
- package/lib/db_ref.js +1 -0
- package/lib/db_ref.js.map +1 -1
- package/lib/decimal128.js +9 -1
- package/lib/decimal128.js.map +1 -1
- package/lib/double.js +1 -0
- package/lib/double.js.map +1 -1
- package/lib/int_32.js +1 -0
- package/lib/int_32.js.map +1 -1
- package/lib/long.js +1 -0
- package/lib/long.js.map +1 -1
- package/lib/max_key.js +1 -0
- package/lib/max_key.js.map +1 -1
- package/lib/min_key.js +1 -0
- package/lib/min_key.js.map +1 -1
- package/lib/objectid.js +10 -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/lib/regexp.js +1 -0
- package/lib/regexp.js.map +1 -1
- package/lib/symbol.js +1 -0
- package/lib/symbol.js.map +1 -1
- package/lib/timestamp.js +4 -1
- package/lib/timestamp.js.map +1 -1
- package/package.json +11 -3
- package/src/binary.ts +1 -0
- package/src/code.ts +1 -0
- package/src/db_ref.ts +1 -0
- package/src/decimal128.ts +8 -1
- package/src/double.ts +1 -0
- package/src/int_32.ts +1 -0
- package/src/long.ts +1 -0
- package/src/max_key.ts +1 -0
- package/src/min_key.ts +1 -0
- package/src/objectid.ts +13 -29
- package/src/parser/calculate_size.ts +2 -2
- package/src/parser/serializer.ts +6 -8
- package/src/regexp.ts +1 -0
- package/src/symbol.ts +1 -0
- package/src/timestamp.ts +4 -1
- package/HISTORY.md +0 -572
package/dist/bson.esm.js
CHANGED
|
@@ -413,6 +413,7 @@ Object.defineProperty(UUID.prototype, '_bsontype', { value: 'UUID' });
|
|
|
413
413
|
/**
|
|
414
414
|
* A class representation of the BSON Binary type.
|
|
415
415
|
* @public
|
|
416
|
+
* @category BSONType
|
|
416
417
|
*/
|
|
417
418
|
var Binary = /** @class */ (function () {
|
|
418
419
|
/**
|
|
@@ -643,6 +644,7 @@ Object.defineProperty(Binary.prototype, '_bsontype', { value: 'Binary' });
|
|
|
643
644
|
/**
|
|
644
645
|
* A class representation of the BSON Code type.
|
|
645
646
|
* @public
|
|
647
|
+
* @category BSONType
|
|
646
648
|
*/
|
|
647
649
|
var Code = /** @class */ (function () {
|
|
648
650
|
/**
|
|
@@ -691,6 +693,7 @@ function isDBRefLike(value) {
|
|
|
691
693
|
/**
|
|
692
694
|
* A class representation of the BSON DBRef type.
|
|
693
695
|
* @public
|
|
696
|
+
* @category BSONType
|
|
694
697
|
*/
|
|
695
698
|
var DBRef = /** @class */ (function () {
|
|
696
699
|
/**
|
|
@@ -795,6 +798,7 @@ var UINT_CACHE = {};
|
|
|
795
798
|
/**
|
|
796
799
|
* A class representing a 64-bit integer
|
|
797
800
|
* @public
|
|
801
|
+
* @category BSONType
|
|
798
802
|
* @remarks
|
|
799
803
|
* The internal representation of a long is the two given signed, 32-bit values.
|
|
800
804
|
* We use 32-bit pieces because these are the size of integers on which
|
|
@@ -1757,6 +1761,7 @@ function invalidErr(string, message) {
|
|
|
1757
1761
|
/**
|
|
1758
1762
|
* A class representation of the BSON Decimal128 type.
|
|
1759
1763
|
* @public
|
|
1764
|
+
* @category BSONType
|
|
1760
1765
|
*/
|
|
1761
1766
|
var Decimal128 = /** @class */ (function () {
|
|
1762
1767
|
/**
|
|
@@ -1769,9 +1774,15 @@ var Decimal128 = /** @class */ (function () {
|
|
|
1769
1774
|
if (typeof bytes === 'string') {
|
|
1770
1775
|
this.bytes = Decimal128.fromString(bytes).bytes;
|
|
1771
1776
|
}
|
|
1772
|
-
else {
|
|
1777
|
+
else if (isUint8Array(bytes)) {
|
|
1778
|
+
if (bytes.byteLength !== 16) {
|
|
1779
|
+
throw new BSONTypeError('Decimal128 must take a Buffer of 16 bytes');
|
|
1780
|
+
}
|
|
1773
1781
|
this.bytes = bytes;
|
|
1774
1782
|
}
|
|
1783
|
+
else {
|
|
1784
|
+
throw new BSONTypeError('Decimal128 must take a Buffer or string');
|
|
1785
|
+
}
|
|
1775
1786
|
}
|
|
1776
1787
|
/**
|
|
1777
1788
|
* Create a Decimal128 instance from a string representation
|
|
@@ -2322,6 +2333,7 @@ Object.defineProperty(Decimal128.prototype, '_bsontype', { value: 'Decimal128' }
|
|
|
2322
2333
|
/**
|
|
2323
2334
|
* A class representation of the BSON Double type.
|
|
2324
2335
|
* @public
|
|
2336
|
+
* @category BSONType
|
|
2325
2337
|
*/
|
|
2326
2338
|
var Double = /** @class */ (function () {
|
|
2327
2339
|
/**
|
|
@@ -2393,6 +2405,7 @@ Object.defineProperty(Double.prototype, '_bsontype', { value: 'Double' });
|
|
|
2393
2405
|
/**
|
|
2394
2406
|
* A class representation of a BSON Int32 type.
|
|
2395
2407
|
* @public
|
|
2408
|
+
* @category BSONType
|
|
2396
2409
|
*/
|
|
2397
2410
|
var Int32 = /** @class */ (function () {
|
|
2398
2411
|
/**
|
|
@@ -2446,6 +2459,7 @@ Object.defineProperty(Int32.prototype, '_bsontype', { value: 'Int32' });
|
|
|
2446
2459
|
/**
|
|
2447
2460
|
* A class representation of the BSON MaxKey type.
|
|
2448
2461
|
* @public
|
|
2462
|
+
* @category BSONType
|
|
2449
2463
|
*/
|
|
2450
2464
|
var MaxKey = /** @class */ (function () {
|
|
2451
2465
|
function MaxKey() {
|
|
@@ -2474,6 +2488,7 @@ Object.defineProperty(MaxKey.prototype, '_bsontype', { value: 'MaxKey' });
|
|
|
2474
2488
|
/**
|
|
2475
2489
|
* A class representation of the BSON MinKey type.
|
|
2476
2490
|
* @public
|
|
2491
|
+
* @category BSONType
|
|
2477
2492
|
*/
|
|
2478
2493
|
var MinKey = /** @class */ (function () {
|
|
2479
2494
|
function MinKey() {
|
|
@@ -2507,6 +2522,7 @@ var kId = Symbol('id');
|
|
|
2507
2522
|
/**
|
|
2508
2523
|
* A class representation of the BSON ObjectId type.
|
|
2509
2524
|
* @public
|
|
2525
|
+
* @category BSONType
|
|
2510
2526
|
*/
|
|
2511
2527
|
var ObjectId = /** @class */ (function () {
|
|
2512
2528
|
/**
|
|
@@ -2556,7 +2572,7 @@ var ObjectId = /** @class */ (function () {
|
|
|
2556
2572
|
this[kId] = Buffer.from(workingId, 'hex');
|
|
2557
2573
|
}
|
|
2558
2574
|
else {
|
|
2559
|
-
throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters');
|
|
2575
|
+
throw new BSONTypeError('Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer');
|
|
2560
2576
|
}
|
|
2561
2577
|
}
|
|
2562
2578
|
else {
|
|
@@ -2673,7 +2689,7 @@ var ObjectId = /** @class */ (function () {
|
|
|
2673
2689
|
return false;
|
|
2674
2690
|
}
|
|
2675
2691
|
if (otherId instanceof ObjectId) {
|
|
2676
|
-
return this
|
|
2692
|
+
return this[kId][11] === otherId[kId][11] && this[kId].equals(otherId[kId]);
|
|
2677
2693
|
}
|
|
2678
2694
|
if (typeof otherId === 'string' &&
|
|
2679
2695
|
ObjectId.isValid(otherId) &&
|
|
@@ -2690,7 +2706,9 @@ var ObjectId = /** @class */ (function () {
|
|
|
2690
2706
|
if (typeof otherId === 'object' &&
|
|
2691
2707
|
'toHexString' in otherId &&
|
|
2692
2708
|
typeof otherId.toHexString === 'function') {
|
|
2693
|
-
|
|
2709
|
+
var otherIdString = otherId.toHexString();
|
|
2710
|
+
var thisIdString = this.toHexString().toLowerCase();
|
|
2711
|
+
return typeof otherIdString === 'string' && otherIdString.toLowerCase() === thisIdString;
|
|
2694
2712
|
}
|
|
2695
2713
|
return false;
|
|
2696
2714
|
};
|
|
@@ -2737,26 +2755,13 @@ var ObjectId = /** @class */ (function () {
|
|
|
2737
2755
|
ObjectId.isValid = function (id) {
|
|
2738
2756
|
if (id == null)
|
|
2739
2757
|
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) {
|
|
2758
|
+
try {
|
|
2759
|
+
new ObjectId(id);
|
|
2750
2760
|
return true;
|
|
2751
2761
|
}
|
|
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'));
|
|
2762
|
+
catch (_a) {
|
|
2763
|
+
return false;
|
|
2758
2764
|
}
|
|
2759
|
-
return false;
|
|
2760
2765
|
};
|
|
2761
2766
|
/** @internal */
|
|
2762
2767
|
ObjectId.prototype.toExtendedJSON = function () {
|
|
@@ -2805,6 +2810,7 @@ function alphabetize(str) {
|
|
|
2805
2810
|
/**
|
|
2806
2811
|
* A class representation of the BSON RegExp type.
|
|
2807
2812
|
* @public
|
|
2813
|
+
* @category BSONType
|
|
2808
2814
|
*/
|
|
2809
2815
|
var BSONRegExp = /** @class */ (function () {
|
|
2810
2816
|
/**
|
|
@@ -2870,6 +2876,7 @@ Object.defineProperty(BSONRegExp.prototype, '_bsontype', { value: 'BSONRegExp' }
|
|
|
2870
2876
|
/**
|
|
2871
2877
|
* A class representation of the BSON Symbol type.
|
|
2872
2878
|
* @public
|
|
2879
|
+
* @category BSONType
|
|
2873
2880
|
*/
|
|
2874
2881
|
var BSONSymbol = /** @class */ (function () {
|
|
2875
2882
|
/**
|
|
@@ -2912,7 +2919,10 @@ Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
|
|
|
2912
2919
|
|
|
2913
2920
|
/** @public */
|
|
2914
2921
|
var LongWithoutOverridesClass = Long;
|
|
2915
|
-
/**
|
|
2922
|
+
/**
|
|
2923
|
+
* @public
|
|
2924
|
+
* @category BSONType
|
|
2925
|
+
* */
|
|
2916
2926
|
var Timestamp = /** @class */ (function (_super) {
|
|
2917
2927
|
__extends(Timestamp, _super);
|
|
2918
2928
|
function Timestamp(low, high) {
|
|
@@ -3552,7 +3562,7 @@ function calculateObjectSize$1(object, serializeFunctions, ignoreUndefined) {
|
|
|
3552
3562
|
}
|
|
3553
3563
|
else {
|
|
3554
3564
|
// If we have toBSON defined, override the current object
|
|
3555
|
-
if (object.toBSON) {
|
|
3565
|
+
if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
|
|
3556
3566
|
object = object.toBSON();
|
|
3557
3567
|
}
|
|
3558
3568
|
// Calculate size
|
|
@@ -3570,7 +3580,7 @@ value, serializeFunctions, isArray, ignoreUndefined) {
|
|
|
3570
3580
|
if (isArray === void 0) { isArray = false; }
|
|
3571
3581
|
if (ignoreUndefined === void 0) { ignoreUndefined = false; }
|
|
3572
3582
|
// If we have toBSON defined, override the current object
|
|
3573
|
-
if (value
|
|
3583
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
3574
3584
|
value = value.toBSON();
|
|
3575
3585
|
}
|
|
3576
3586
|
switch (typeof value) {
|
|
@@ -5018,9 +5028,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5018
5028
|
var key = '' + i;
|
|
5019
5029
|
var value = object[i];
|
|
5020
5030
|
// Is there an override value
|
|
5021
|
-
if (value
|
|
5022
|
-
if (typeof value.toBSON !== 'function')
|
|
5023
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
5031
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
5024
5032
|
value = value.toBSON();
|
|
5025
5033
|
}
|
|
5026
5034
|
if (typeof value === 'string') {
|
|
@@ -5196,21 +5204,18 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
5196
5204
|
}
|
|
5197
5205
|
}
|
|
5198
5206
|
else {
|
|
5199
|
-
|
|
5200
|
-
|
|
5201
|
-
if (typeof object.toBSON !== 'function')
|
|
5202
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
5207
|
+
if (typeof (object === null || object === void 0 ? void 0 : object.toBSON) === 'function') {
|
|
5208
|
+
// Provided a custom serialization method
|
|
5203
5209
|
object = object.toBSON();
|
|
5204
|
-
if (object != null && typeof object !== 'object')
|
|
5210
|
+
if (object != null && typeof object !== 'object') {
|
|
5205
5211
|
throw new BSONTypeError('toBSON function did not return an object');
|
|
5212
|
+
}
|
|
5206
5213
|
}
|
|
5207
5214
|
// Iterate over all the keys
|
|
5208
5215
|
for (var key in object) {
|
|
5209
5216
|
var value = object[key];
|
|
5210
5217
|
// Is there an override value
|
|
5211
|
-
if (value
|
|
5212
|
-
if (typeof value.toBSON !== 'function')
|
|
5213
|
-
throw new BSONTypeError('toBSON is not a function');
|
|
5218
|
+
if (typeof (value === null || value === void 0 ? void 0 : value.toBSON) === 'function') {
|
|
5214
5219
|
value = value.toBSON();
|
|
5215
5220
|
}
|
|
5216
5221
|
// Check the type of the value
|