bson 4.5.2 → 4.5.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.d.ts +16 -0
- package/dist/bson.browser.esm.js +187 -127
- package/dist/bson.browser.esm.js.map +1 -1
- package/dist/bson.browser.umd.js +190 -126
- package/dist/bson.browser.umd.js.map +1 -1
- package/dist/bson.bundle.js +190 -126
- package/dist/bson.bundle.js.map +1 -1
- package/dist/bson.esm.js +187 -127
- package/dist/bson.esm.js.map +1 -1
- package/lib/binary.js +11 -6
- package/lib/binary.js.map +1 -1
- package/lib/bson.js +11 -3
- package/lib/bson.js.map +1 -1
- package/lib/constants.js +5 -1
- package/lib/constants.js.map +1 -1
- package/lib/decimal128.js +5 -4
- package/lib/decimal128.js.map +1 -1
- package/lib/ensure_buffer.js +2 -1
- package/lib/ensure_buffer.js.map +1 -1
- package/lib/error.js +51 -0
- package/lib/error.js.map +1 -0
- package/lib/extended_json.js +11 -5
- package/lib/extended_json.js.map +1 -1
- package/lib/objectid.js +3 -2
- package/lib/objectid.js.map +1 -1
- package/lib/parser/deserializer.js +60 -51
- package/lib/parser/deserializer.js.map +1 -1
- package/lib/parser/serializer.js +13 -12
- package/lib/parser/serializer.js.map +1 -1
- package/lib/regexp.js +9 -2
- package/lib/regexp.js.map +1 -1
- package/lib/uuid.js +2 -1
- package/lib/uuid.js.map +1 -1
- package/lib/uuid_utils.js +2 -1
- package/lib/uuid_utils.js.map +1 -1
- package/package.json +3 -1
- package/src/binary.ts +11 -6
- package/src/bson.ts +7 -1
- package/src/constants.ts +6 -0
- package/src/decimal128.ts +5 -4
- package/src/ensure_buffer.ts +2 -1
- package/src/error.ts +13 -0
- package/src/extended_json.ts +13 -5
- package/src/objectid.ts +3 -2
- package/src/parser/deserializer.ts +65 -53
- package/src/parser/serializer.ts +13 -12
- package/src/regexp.ts +14 -2
- package/src/uuid.ts +2 -1
- package/src/uuid_utils.ts +2 -1
package/dist/bson.browser.esm.js
CHANGED
|
@@ -2031,6 +2031,77 @@ buffer$1.SlowBuffer;
|
|
|
2031
2031
|
buffer$1.INSPECT_MAX_BYTES;
|
|
2032
2032
|
buffer$1.kMaxLength;
|
|
2033
2033
|
|
|
2034
|
+
/*! *****************************************************************************
|
|
2035
|
+
Copyright (c) Microsoft Corporation.
|
|
2036
|
+
|
|
2037
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
2038
|
+
purpose with or without fee is hereby granted.
|
|
2039
|
+
|
|
2040
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
2041
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
2042
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
2043
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
2044
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
2045
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
2046
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
2047
|
+
***************************************************************************** */
|
|
2048
|
+
|
|
2049
|
+
/* global Reflect, Promise */
|
|
2050
|
+
var _extendStatics = function extendStatics(d, b) {
|
|
2051
|
+
_extendStatics = Object.setPrototypeOf || {
|
|
2052
|
+
__proto__: []
|
|
2053
|
+
} instanceof Array && function (d, b) {
|
|
2054
|
+
d.__proto__ = b;
|
|
2055
|
+
} || function (d, b) {
|
|
2056
|
+
for (var p in b) {
|
|
2057
|
+
if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
2058
|
+
}
|
|
2059
|
+
};
|
|
2060
|
+
|
|
2061
|
+
return _extendStatics(d, b);
|
|
2062
|
+
};
|
|
2063
|
+
|
|
2064
|
+
function __extends(d, b) {
|
|
2065
|
+
_extendStatics(d, b);
|
|
2066
|
+
|
|
2067
|
+
function __() {
|
|
2068
|
+
this.constructor = d;
|
|
2069
|
+
}
|
|
2070
|
+
|
|
2071
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
/** @public */
|
|
2075
|
+
var BSONError = /** @class */ (function (_super) {
|
|
2076
|
+
__extends(BSONError, _super);
|
|
2077
|
+
function BSONError() {
|
|
2078
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2079
|
+
}
|
|
2080
|
+
Object.defineProperty(BSONError.prototype, "name", {
|
|
2081
|
+
get: function () {
|
|
2082
|
+
return 'BSONError';
|
|
2083
|
+
},
|
|
2084
|
+
enumerable: false,
|
|
2085
|
+
configurable: true
|
|
2086
|
+
});
|
|
2087
|
+
return BSONError;
|
|
2088
|
+
}(Error));
|
|
2089
|
+
/** @public */
|
|
2090
|
+
var BSONTypeError = /** @class */ (function (_super) {
|
|
2091
|
+
__extends(BSONTypeError, _super);
|
|
2092
|
+
function BSONTypeError() {
|
|
2093
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
2094
|
+
}
|
|
2095
|
+
Object.defineProperty(BSONTypeError.prototype, "name", {
|
|
2096
|
+
get: function () {
|
|
2097
|
+
return 'BSONTypeError';
|
|
2098
|
+
},
|
|
2099
|
+
enumerable: false,
|
|
2100
|
+
configurable: true
|
|
2101
|
+
});
|
|
2102
|
+
return BSONTypeError;
|
|
2103
|
+
}(TypeError));
|
|
2104
|
+
|
|
2034
2105
|
function checkForMath(potentialGlobal) {
|
|
2035
2106
|
// eslint-disable-next-line eqeqeq
|
|
2036
2107
|
return potentialGlobal && potentialGlobal.Math == Math && potentialGlobal;
|
|
@@ -2151,7 +2222,7 @@ function ensureBuffer(potentialBuffer) {
|
|
|
2151
2222
|
if (isAnyArrayBuffer(potentialBuffer)) {
|
|
2152
2223
|
return buffer_1.from(potentialBuffer);
|
|
2153
2224
|
}
|
|
2154
|
-
throw new
|
|
2225
|
+
throw new BSONTypeError('Must use either Buffer or TypedArray');
|
|
2155
2226
|
}
|
|
2156
2227
|
|
|
2157
2228
|
// Validation regex for v4 uuid (validates with or without dashes)
|
|
@@ -2161,7 +2232,7 @@ var uuidValidateString = function (str) {
|
|
|
2161
2232
|
};
|
|
2162
2233
|
var uuidHexStringToBuffer = function (hexString) {
|
|
2163
2234
|
if (!uuidValidateString(hexString)) {
|
|
2164
|
-
throw new
|
|
2235
|
+
throw new BSONTypeError('UUID string representations must be a 32 or 36 character hex string (dashes excluded/included). Format: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" or "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".');
|
|
2165
2236
|
}
|
|
2166
2237
|
var sanitizedHexString = hexString.replace(/-/g, '');
|
|
2167
2238
|
return buffer_1.from(sanitizedHexString, 'hex');
|
|
@@ -2209,7 +2280,7 @@ var UUID = /** @class */ (function () {
|
|
|
2209
2280
|
this.id = uuidHexStringToBuffer(input);
|
|
2210
2281
|
}
|
|
2211
2282
|
else {
|
|
2212
|
-
throw new
|
|
2283
|
+
throw new BSONTypeError('Argument passed in UUID constructor must be a UUID, a 16 byte Buffer or a 32/36 character hex string (dashes excluded/included, format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).');
|
|
2213
2284
|
}
|
|
2214
2285
|
}
|
|
2215
2286
|
Object.defineProperty(UUID.prototype, "id", {
|
|
@@ -2367,7 +2438,7 @@ var Binary = /** @class */ (function () {
|
|
|
2367
2438
|
!ArrayBuffer.isView(buffer) &&
|
|
2368
2439
|
!(buffer instanceof ArrayBuffer) &&
|
|
2369
2440
|
!Array.isArray(buffer)) {
|
|
2370
|
-
throw new
|
|
2441
|
+
throw new BSONTypeError('Binary can only be constructed from string, Buffer, TypedArray, or Array<number>');
|
|
2371
2442
|
}
|
|
2372
2443
|
this.sub_type = subType !== null && subType !== void 0 ? subType : Binary.BSON_BINARY_SUBTYPE_DEFAULT;
|
|
2373
2444
|
if (buffer == null) {
|
|
@@ -2399,10 +2470,10 @@ var Binary = /** @class */ (function () {
|
|
|
2399
2470
|
Binary.prototype.put = function (byteValue) {
|
|
2400
2471
|
// If it's a string and a has more than one character throw an error
|
|
2401
2472
|
if (typeof byteValue === 'string' && byteValue.length !== 1) {
|
|
2402
|
-
throw new
|
|
2473
|
+
throw new BSONTypeError('only accepts single character String');
|
|
2403
2474
|
}
|
|
2404
2475
|
else if (typeof byteValue !== 'number' && byteValue.length !== 1)
|
|
2405
|
-
throw new
|
|
2476
|
+
throw new BSONTypeError('only accepts single character Uint8Array or Array');
|
|
2406
2477
|
// Decode the byte value once
|
|
2407
2478
|
var decodedByte;
|
|
2408
2479
|
if (typeof byteValue === 'string') {
|
|
@@ -2415,7 +2486,7 @@ var Binary = /** @class */ (function () {
|
|
|
2415
2486
|
decodedByte = byteValue[0];
|
|
2416
2487
|
}
|
|
2417
2488
|
if (decodedByte < 0 || decodedByte > 255) {
|
|
2418
|
-
throw new
|
|
2489
|
+
throw new BSONTypeError('only accepts number in a valid unsigned byte range 0-255');
|
|
2419
2490
|
}
|
|
2420
2491
|
if (this.buffer.length > this.position) {
|
|
2421
2492
|
this.buffer[this.position++] = decodedByte;
|
|
@@ -2515,7 +2586,7 @@ var Binary = /** @class */ (function () {
|
|
|
2515
2586
|
if (this.sub_type === Binary.SUBTYPE_UUID) {
|
|
2516
2587
|
return new UUID(this.buffer.slice(0, this.position));
|
|
2517
2588
|
}
|
|
2518
|
-
throw new
|
|
2589
|
+
throw new BSONError("Binary sub_type \"" + this.sub_type + "\" is not supported for converting to UUID. Only \"" + Binary.SUBTYPE_UUID + "\" is currently supported.");
|
|
2519
2590
|
};
|
|
2520
2591
|
/** @internal */
|
|
2521
2592
|
Binary.fromExtendedJSON = function (doc, options) {
|
|
@@ -2539,7 +2610,7 @@ var Binary = /** @class */ (function () {
|
|
|
2539
2610
|
data = uuidHexStringToBuffer(doc.$uuid);
|
|
2540
2611
|
}
|
|
2541
2612
|
if (!data) {
|
|
2542
|
-
throw new
|
|
2613
|
+
throw new BSONTypeError("Unexpected Binary Extended JSON format " + JSON.stringify(doc));
|
|
2543
2614
|
}
|
|
2544
2615
|
return new Binary(data, type);
|
|
2545
2616
|
};
|
|
@@ -2570,6 +2641,10 @@ var Binary = /** @class */ (function () {
|
|
|
2570
2641
|
Binary.SUBTYPE_UUID = 4;
|
|
2571
2642
|
/** MD5 BSON type */
|
|
2572
2643
|
Binary.SUBTYPE_MD5 = 5;
|
|
2644
|
+
/** Encrypted BSON type */
|
|
2645
|
+
Binary.SUBTYPE_ENCRYPTED = 6;
|
|
2646
|
+
/** Column BSON type */
|
|
2647
|
+
Binary.SUBTYPE_COLUMN = 7;
|
|
2573
2648
|
/** User BSON type */
|
|
2574
2649
|
Binary.SUBTYPE_USER_DEFINED = 128;
|
|
2575
2650
|
return Binary;
|
|
@@ -3688,7 +3763,7 @@ function lessThan(left, right) {
|
|
|
3688
3763
|
return false;
|
|
3689
3764
|
}
|
|
3690
3765
|
function invalidErr(string, message) {
|
|
3691
|
-
throw new
|
|
3766
|
+
throw new BSONTypeError("\"" + string + "\" is not a valid Decimal128 string - " + message);
|
|
3692
3767
|
}
|
|
3693
3768
|
/**
|
|
3694
3769
|
* A class representation of the BSON Decimal128 type.
|
|
@@ -3755,7 +3830,7 @@ var Decimal128 = /** @class */ (function () {
|
|
|
3755
3830
|
// TODO: implementing a custom parsing for this, or refactoring the regex would yield
|
|
3756
3831
|
// further gains.
|
|
3757
3832
|
if (representation.length >= 7000) {
|
|
3758
|
-
throw new
|
|
3833
|
+
throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');
|
|
3759
3834
|
}
|
|
3760
3835
|
// Results
|
|
3761
3836
|
var stringMatch = representation.match(PARSE_STRING_REGEXP);
|
|
@@ -3763,7 +3838,7 @@ var Decimal128 = /** @class */ (function () {
|
|
|
3763
3838
|
var nanMatch = representation.match(PARSE_NAN_REGEXP);
|
|
3764
3839
|
// Validate the string
|
|
3765
3840
|
if ((!stringMatch && !infMatch && !nanMatch) || representation.length === 0) {
|
|
3766
|
-
throw new
|
|
3841
|
+
throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');
|
|
3767
3842
|
}
|
|
3768
3843
|
if (stringMatch) {
|
|
3769
3844
|
// full_match = stringMatch[0]
|
|
@@ -3825,7 +3900,7 @@ var Decimal128 = /** @class */ (function () {
|
|
|
3825
3900
|
index = index + 1;
|
|
3826
3901
|
}
|
|
3827
3902
|
if (sawRadix && !nDigitsRead)
|
|
3828
|
-
throw new
|
|
3903
|
+
throw new BSONTypeError('' + representation + ' not a valid Decimal128 string');
|
|
3829
3904
|
// Read exponent if exists
|
|
3830
3905
|
if (representation[index] === 'e' || representation[index] === 'E') {
|
|
3831
3906
|
// Read exponent digits
|
|
@@ -4489,7 +4564,7 @@ var ObjectId = /** @class */ (function () {
|
|
|
4489
4564
|
this[kId] = buffer_1.from(id, 'hex');
|
|
4490
4565
|
}
|
|
4491
4566
|
else {
|
|
4492
|
-
throw new
|
|
4567
|
+
throw new BSONTypeError('Argument passed in must be a Buffer or string of 12 bytes or a string of 24 hex characters');
|
|
4493
4568
|
}
|
|
4494
4569
|
}
|
|
4495
4570
|
if (ObjectId.cacheHexString) {
|
|
@@ -4654,7 +4729,7 @@ var ObjectId = /** @class */ (function () {
|
|
|
4654
4729
|
ObjectId.createFromHexString = function (hexString) {
|
|
4655
4730
|
// Throw an error if it's not a valid setup
|
|
4656
4731
|
if (typeof hexString === 'undefined' || (hexString != null && hexString.length !== 24)) {
|
|
4657
|
-
throw new
|
|
4732
|
+
throw new BSONTypeError('Argument passed in must be a single String of 12 bytes or a string of 24 hex characters');
|
|
4658
4733
|
}
|
|
4659
4734
|
return new ObjectId(buffer_1.from(hexString, 'hex'));
|
|
4660
4735
|
};
|
|
@@ -4745,6 +4820,12 @@ var BSONRegExp = /** @class */ (function () {
|
|
|
4745
4820
|
return new BSONRegExp(pattern, options);
|
|
4746
4821
|
this.pattern = pattern;
|
|
4747
4822
|
this.options = alphabetize(options !== null && options !== void 0 ? options : '');
|
|
4823
|
+
if (this.pattern.indexOf('\x00') !== -1) {
|
|
4824
|
+
throw new BSONError("BSON Regex patterns cannot contain null bytes, found: " + JSON.stringify(this.pattern));
|
|
4825
|
+
}
|
|
4826
|
+
if (this.options.indexOf('\x00') !== -1) {
|
|
4827
|
+
throw new BSONError("BSON Regex options cannot contain null bytes, found: " + JSON.stringify(this.options));
|
|
4828
|
+
}
|
|
4748
4829
|
// Validate options
|
|
4749
4830
|
for (var i = 0; i < this.options.length; i++) {
|
|
4750
4831
|
if (!(this.options[i] === 'i' ||
|
|
@@ -4753,7 +4834,7 @@ var BSONRegExp = /** @class */ (function () {
|
|
|
4753
4834
|
this.options[i] === 'l' ||
|
|
4754
4835
|
this.options[i] === 's' ||
|
|
4755
4836
|
this.options[i] === 'u')) {
|
|
4756
|
-
throw new
|
|
4837
|
+
throw new BSONError("The regular expression option [" + this.options[i] + "] is not supported");
|
|
4757
4838
|
}
|
|
4758
4839
|
}
|
|
4759
4840
|
}
|
|
@@ -4784,7 +4865,7 @@ var BSONRegExp = /** @class */ (function () {
|
|
|
4784
4865
|
if ('$regularExpression' in doc) {
|
|
4785
4866
|
return new BSONRegExp(doc.$regularExpression.pattern, BSONRegExp.parseOptions(doc.$regularExpression.options));
|
|
4786
4867
|
}
|
|
4787
|
-
throw new
|
|
4868
|
+
throw new BSONTypeError("Unexpected BSONRegExp EJSON object form: " + JSON.stringify(doc));
|
|
4788
4869
|
};
|
|
4789
4870
|
return BSONRegExp;
|
|
4790
4871
|
}());
|
|
@@ -4833,46 +4914,6 @@ var BSONSymbol = /** @class */ (function () {
|
|
|
4833
4914
|
}());
|
|
4834
4915
|
Object.defineProperty(BSONSymbol.prototype, '_bsontype', { value: 'Symbol' });
|
|
4835
4916
|
|
|
4836
|
-
/*! *****************************************************************************
|
|
4837
|
-
Copyright (c) Microsoft Corporation.
|
|
4838
|
-
|
|
4839
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
4840
|
-
purpose with or without fee is hereby granted.
|
|
4841
|
-
|
|
4842
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
4843
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
4844
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
4845
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
4846
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
4847
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
4848
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
4849
|
-
***************************************************************************** */
|
|
4850
|
-
|
|
4851
|
-
/* global Reflect, Promise */
|
|
4852
|
-
var _extendStatics = function extendStatics(d, b) {
|
|
4853
|
-
_extendStatics = Object.setPrototypeOf || {
|
|
4854
|
-
__proto__: []
|
|
4855
|
-
} instanceof Array && function (d, b) {
|
|
4856
|
-
d.__proto__ = b;
|
|
4857
|
-
} || function (d, b) {
|
|
4858
|
-
for (var p in b) {
|
|
4859
|
-
if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
4860
|
-
}
|
|
4861
|
-
};
|
|
4862
|
-
|
|
4863
|
-
return _extendStatics(d, b);
|
|
4864
|
-
};
|
|
4865
|
-
|
|
4866
|
-
function __extends(d, b) {
|
|
4867
|
-
_extendStatics(d, b);
|
|
4868
|
-
|
|
4869
|
-
function __() {
|
|
4870
|
-
this.constructor = d;
|
|
4871
|
-
}
|
|
4872
|
-
|
|
4873
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
4874
|
-
}
|
|
4875
|
-
|
|
4876
4917
|
/** @public */
|
|
4877
4918
|
var LongWithoutOverridesClass = Long;
|
|
4878
4919
|
/** @public */
|
|
@@ -5087,7 +5128,7 @@ function serializeValue(value, options) {
|
|
|
5087
5128
|
var current = props[props.length - 1];
|
|
5088
5129
|
var leadingSpace = ' '.repeat(leadingPart.length + alreadySeen.length / 2);
|
|
5089
5130
|
var dashes = '-'.repeat(circularPart.length + (alreadySeen.length + current.length) / 2 - 1);
|
|
5090
|
-
throw new
|
|
5131
|
+
throw new BSONTypeError('Converting circular structure to EJSON:\n' +
|
|
5091
5132
|
(" " + leadingPart + alreadySeen + circularPart + current + "\n") +
|
|
5092
5133
|
(" " + leadingSpace + "\\" + dashes + "/"));
|
|
5093
5134
|
}
|
|
@@ -5160,7 +5201,7 @@ var BSON_TYPE_MAPPINGS = {
|
|
|
5160
5201
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5161
5202
|
function serializeDocument(doc, options) {
|
|
5162
5203
|
if (doc == null || typeof doc !== 'object')
|
|
5163
|
-
throw new
|
|
5204
|
+
throw new BSONError('not an object instance');
|
|
5164
5205
|
var bsontype = doc._bsontype;
|
|
5165
5206
|
if (typeof bsontype === 'undefined') {
|
|
5166
5207
|
// It's a regular object. Recursively serialize its property values.
|
|
@@ -5187,7 +5228,7 @@ function serializeDocument(doc, options) {
|
|
|
5187
5228
|
// Copy the object into this library's version of that type.
|
|
5188
5229
|
var mapper = BSON_TYPE_MAPPINGS[doc._bsontype];
|
|
5189
5230
|
if (!mapper) {
|
|
5190
|
-
throw new
|
|
5231
|
+
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + doc._bsontype);
|
|
5191
5232
|
}
|
|
5192
5233
|
outDoc = mapper(outDoc);
|
|
5193
5234
|
}
|
|
@@ -5201,7 +5242,7 @@ function serializeDocument(doc, options) {
|
|
|
5201
5242
|
return outDoc.toExtendedJSON(options);
|
|
5202
5243
|
}
|
|
5203
5244
|
else {
|
|
5204
|
-
throw new
|
|
5245
|
+
throw new BSONError('_bsontype must be a string, but was: ' + typeof bsontype);
|
|
5205
5246
|
}
|
|
5206
5247
|
}
|
|
5207
5248
|
/**
|
|
@@ -5236,7 +5277,12 @@ var EJSON;
|
|
|
5236
5277
|
finalOptions.strict = !finalOptions.relaxed;
|
|
5237
5278
|
if (typeof finalOptions.strict === 'boolean')
|
|
5238
5279
|
finalOptions.relaxed = !finalOptions.strict;
|
|
5239
|
-
return JSON.parse(text, function (
|
|
5280
|
+
return JSON.parse(text, function (key, value) {
|
|
5281
|
+
if (key.indexOf('\x00') !== -1) {
|
|
5282
|
+
throw new BSONError("BSON Document field names cannot contain null bytes, found: " + JSON.stringify(key));
|
|
5283
|
+
}
|
|
5284
|
+
return deserializeValue(value, finalOptions);
|
|
5285
|
+
});
|
|
5240
5286
|
}
|
|
5241
5287
|
EJSON.parse = parse;
|
|
5242
5288
|
/**
|
|
@@ -5494,6 +5540,10 @@ var BSON_BINARY_SUBTYPE_UUID = 3;
|
|
|
5494
5540
|
var BSON_BINARY_SUBTYPE_UUID_NEW = 4;
|
|
5495
5541
|
/** Binary MD5 Type @internal */
|
|
5496
5542
|
var BSON_BINARY_SUBTYPE_MD5 = 5;
|
|
5543
|
+
/** Encrypted BSON type @internal */
|
|
5544
|
+
var BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
|
|
5545
|
+
/** Column BSON type @internal */
|
|
5546
|
+
var BSON_BINARY_SUBTYPE_COLUMN = 7;
|
|
5497
5547
|
/** Binary User Defined Type @internal */
|
|
5498
5548
|
var BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
|
|
5499
5549
|
|
|
@@ -5738,20 +5788,20 @@ function deserialize$1(buffer, options, isArray) {
|
|
|
5738
5788
|
(buffer[index + 2] << 16) |
|
|
5739
5789
|
(buffer[index + 3] << 24);
|
|
5740
5790
|
if (size < 5) {
|
|
5741
|
-
throw new
|
|
5791
|
+
throw new BSONError("bson size must be >= 5, is " + size);
|
|
5742
5792
|
}
|
|
5743
5793
|
if (options.allowObjectSmallerThanBufferSize && buffer.length < size) {
|
|
5744
|
-
throw new
|
|
5794
|
+
throw new BSONError("buffer length " + buffer.length + " must be >= bson size " + size);
|
|
5745
5795
|
}
|
|
5746
5796
|
if (!options.allowObjectSmallerThanBufferSize && buffer.length !== size) {
|
|
5747
|
-
throw new
|
|
5797
|
+
throw new BSONError("buffer length " + buffer.length + " must === bson size " + size);
|
|
5748
5798
|
}
|
|
5749
5799
|
if (size + index > buffer.byteLength) {
|
|
5750
|
-
throw new
|
|
5800
|
+
throw new BSONError("(bson size " + size + " + options.index " + index + " must be <= buffer length " + buffer.byteLength + ")");
|
|
5751
5801
|
}
|
|
5752
5802
|
// Illegal end value
|
|
5753
5803
|
if (buffer[index + size - 1] !== 0) {
|
|
5754
|
-
throw new
|
|
5804
|
+
throw new BSONError("One object, sized correctly, with a spot for an EOO, but the EOO isn't 0x00");
|
|
5755
5805
|
}
|
|
5756
5806
|
// Start deserializtion
|
|
5757
5807
|
return deserializeObject(buffer, index, options, isArray);
|
|
@@ -5774,12 +5824,12 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5774
5824
|
var startIndex = index;
|
|
5775
5825
|
// Validate that we have at least 4 bytes of buffer
|
|
5776
5826
|
if (buffer.length < 5)
|
|
5777
|
-
throw new
|
|
5827
|
+
throw new BSONError('corrupt bson message < 5 bytes long');
|
|
5778
5828
|
// Read the document size
|
|
5779
5829
|
var size = buffer[index++] | (buffer[index++] << 8) | (buffer[index++] << 16) | (buffer[index++] << 24);
|
|
5780
5830
|
// Ensure buffer is valid size
|
|
5781
5831
|
if (size < 5 || size > buffer.length)
|
|
5782
|
-
throw new
|
|
5832
|
+
throw new BSONError('corrupt bson message');
|
|
5783
5833
|
// Create holding object
|
|
5784
5834
|
var object = isArray ? [] : {};
|
|
5785
5835
|
// Used for arrays to skip having to perform utf8 decoding
|
|
@@ -5801,7 +5851,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5801
5851
|
}
|
|
5802
5852
|
// If are at the end of the buffer there is a problem with the document
|
|
5803
5853
|
if (i >= buffer.byteLength)
|
|
5804
|
-
throw new
|
|
5854
|
+
throw new BSONError('Bad BSON Document: illegal CString');
|
|
5805
5855
|
var name = isArray ? arrayIndex++ : buffer.toString('utf8', index, i);
|
|
5806
5856
|
if (isPossibleDBRef !== false && name[0] === '$') {
|
|
5807
5857
|
isPossibleDBRef = allowedDBRefKeys.test(name);
|
|
@@ -5815,17 +5865,10 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5815
5865
|
(buffer[index++] << 24);
|
|
5816
5866
|
if (stringSize <= 0 ||
|
|
5817
5867
|
stringSize > buffer.length - index ||
|
|
5818
|
-
buffer[index + stringSize - 1] !== 0)
|
|
5819
|
-
throw new
|
|
5820
|
-
value = buffer.toString('utf8', index, index + stringSize - 1);
|
|
5821
|
-
for (var i_1 = 0; i_1 < value.length; i_1++) {
|
|
5822
|
-
if (value.charCodeAt(i_1) === 0xfffd) {
|
|
5823
|
-
if (!validateUtf8(buffer, index, index + stringSize - 1)) {
|
|
5824
|
-
throw new Error('Invalid UTF-8 string in BSON document');
|
|
5825
|
-
}
|
|
5826
|
-
break;
|
|
5827
|
-
}
|
|
5868
|
+
buffer[index + stringSize - 1] !== 0) {
|
|
5869
|
+
throw new BSONError('bad string length in bson');
|
|
5828
5870
|
}
|
|
5871
|
+
value = getValidatedString(buffer, index, index + stringSize - 1);
|
|
5829
5872
|
index = index + stringSize;
|
|
5830
5873
|
}
|
|
5831
5874
|
else if (elementType === BSON_DATA_OID) {
|
|
@@ -5865,7 +5908,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5865
5908
|
}
|
|
5866
5909
|
else if (elementType === BSON_DATA_BOOLEAN) {
|
|
5867
5910
|
if (buffer[index] !== 0 && buffer[index] !== 1)
|
|
5868
|
-
throw new
|
|
5911
|
+
throw new BSONError('illegal boolean type value');
|
|
5869
5912
|
value = buffer[index++] === 1;
|
|
5870
5913
|
}
|
|
5871
5914
|
else if (elementType === BSON_DATA_OBJECT) {
|
|
@@ -5875,7 +5918,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5875
5918
|
(buffer[index + 2] << 16) |
|
|
5876
5919
|
(buffer[index + 3] << 24);
|
|
5877
5920
|
if (objectSize <= 0 || objectSize > buffer.length - index)
|
|
5878
|
-
throw new
|
|
5921
|
+
throw new BSONError('bad embedded document length in bson');
|
|
5879
5922
|
// We have a raw value
|
|
5880
5923
|
if (raw) {
|
|
5881
5924
|
value = buffer.slice(index, index + objectSize);
|
|
@@ -5905,9 +5948,9 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5905
5948
|
value = deserializeObject(buffer, _index, arrayOptions, true);
|
|
5906
5949
|
index = index + objectSize;
|
|
5907
5950
|
if (buffer[index - 1] !== 0)
|
|
5908
|
-
throw new
|
|
5951
|
+
throw new BSONError('invalid array terminator byte');
|
|
5909
5952
|
if (index !== stopIndex)
|
|
5910
|
-
throw new
|
|
5953
|
+
throw new BSONError('corrupted array bson');
|
|
5911
5954
|
}
|
|
5912
5955
|
else if (elementType === BSON_DATA_UNDEFINED) {
|
|
5913
5956
|
value = undefined;
|
|
@@ -5963,10 +6006,10 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5963
6006
|
var subType = buffer[index++];
|
|
5964
6007
|
// Did we have a negative binary size, throw
|
|
5965
6008
|
if (binarySize < 0)
|
|
5966
|
-
throw new
|
|
6009
|
+
throw new BSONError('Negative binary type element size found');
|
|
5967
6010
|
// Is the length longer than the document
|
|
5968
6011
|
if (binarySize > buffer.byteLength)
|
|
5969
|
-
throw new
|
|
6012
|
+
throw new BSONError('Binary type size larger than document size');
|
|
5970
6013
|
// Decode as raw Buffer object if options specifies it
|
|
5971
6014
|
if (buffer['slice'] != null) {
|
|
5972
6015
|
// If we have subtype 2 skip the 4 bytes for the size
|
|
@@ -5977,11 +6020,11 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
5977
6020
|
(buffer[index++] << 16) |
|
|
5978
6021
|
(buffer[index++] << 24);
|
|
5979
6022
|
if (binarySize < 0)
|
|
5980
|
-
throw new
|
|
6023
|
+
throw new BSONError('Negative binary type element size found for subtype 0x02');
|
|
5981
6024
|
if (binarySize > totalBinarySize - 4)
|
|
5982
|
-
throw new
|
|
6025
|
+
throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
|
|
5983
6026
|
if (binarySize < totalBinarySize - 4)
|
|
5984
|
-
throw new
|
|
6027
|
+
throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
|
|
5985
6028
|
}
|
|
5986
6029
|
if (promoteBuffers && promoteValues) {
|
|
5987
6030
|
value = buffer.slice(index, index + binarySize);
|
|
@@ -6000,11 +6043,11 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6000
6043
|
(buffer[index++] << 16) |
|
|
6001
6044
|
(buffer[index++] << 24);
|
|
6002
6045
|
if (binarySize < 0)
|
|
6003
|
-
throw new
|
|
6046
|
+
throw new BSONError('Negative binary type element size found for subtype 0x02');
|
|
6004
6047
|
if (binarySize > totalBinarySize - 4)
|
|
6005
|
-
throw new
|
|
6048
|
+
throw new BSONError('Binary type with subtype 0x02 contains too long binary size');
|
|
6006
6049
|
if (binarySize < totalBinarySize - 4)
|
|
6007
|
-
throw new
|
|
6050
|
+
throw new BSONError('Binary type with subtype 0x02 contains too short binary size');
|
|
6008
6051
|
}
|
|
6009
6052
|
// Copy the data
|
|
6010
6053
|
for (i = 0; i < binarySize; i++) {
|
|
@@ -6029,7 +6072,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6029
6072
|
}
|
|
6030
6073
|
// If are at the end of the buffer there is a problem with the document
|
|
6031
6074
|
if (i >= buffer.length)
|
|
6032
|
-
throw new
|
|
6075
|
+
throw new BSONError('Bad BSON Document: illegal CString');
|
|
6033
6076
|
// Return the C string
|
|
6034
6077
|
var source = buffer.toString('utf8', index, i);
|
|
6035
6078
|
// Create the regexp
|
|
@@ -6042,7 +6085,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6042
6085
|
}
|
|
6043
6086
|
// If are at the end of the buffer there is a problem with the document
|
|
6044
6087
|
if (i >= buffer.length)
|
|
6045
|
-
throw new
|
|
6088
|
+
throw new BSONError('Bad BSON Document: illegal CString');
|
|
6046
6089
|
// Return the C string
|
|
6047
6090
|
var regExpOptions = buffer.toString('utf8', index, i);
|
|
6048
6091
|
index = i + 1;
|
|
@@ -6073,7 +6116,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6073
6116
|
}
|
|
6074
6117
|
// If are at the end of the buffer there is a problem with the document
|
|
6075
6118
|
if (i >= buffer.length)
|
|
6076
|
-
throw new
|
|
6119
|
+
throw new BSONError('Bad BSON Document: illegal CString');
|
|
6077
6120
|
// Return the C string
|
|
6078
6121
|
var source = buffer.toString('utf8', index, i);
|
|
6079
6122
|
index = i + 1;
|
|
@@ -6085,7 +6128,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6085
6128
|
}
|
|
6086
6129
|
// If are at the end of the buffer there is a problem with the document
|
|
6087
6130
|
if (i >= buffer.length)
|
|
6088
|
-
throw new
|
|
6131
|
+
throw new BSONError('Bad BSON Document: illegal CString');
|
|
6089
6132
|
// Return the C string
|
|
6090
6133
|
var regExpOptions = buffer.toString('utf8', index, i);
|
|
6091
6134
|
index = i + 1;
|
|
@@ -6099,9 +6142,10 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6099
6142
|
(buffer[index++] << 24);
|
|
6100
6143
|
if (stringSize <= 0 ||
|
|
6101
6144
|
stringSize > buffer.length - index ||
|
|
6102
|
-
buffer[index + stringSize - 1] !== 0)
|
|
6103
|
-
throw new
|
|
6104
|
-
|
|
6145
|
+
buffer[index + stringSize - 1] !== 0) {
|
|
6146
|
+
throw new BSONError('bad string length in bson');
|
|
6147
|
+
}
|
|
6148
|
+
var symbol = getValidatedString(buffer, index, index + stringSize - 1);
|
|
6105
6149
|
value = promoteValues ? symbol : new BSONSymbol(symbol);
|
|
6106
6150
|
index = index + stringSize;
|
|
6107
6151
|
}
|
|
@@ -6129,9 +6173,10 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6129
6173
|
(buffer[index++] << 24);
|
|
6130
6174
|
if (stringSize <= 0 ||
|
|
6131
6175
|
stringSize > buffer.length - index ||
|
|
6132
|
-
buffer[index + stringSize - 1] !== 0)
|
|
6133
|
-
throw new
|
|
6134
|
-
|
|
6176
|
+
buffer[index + stringSize - 1] !== 0) {
|
|
6177
|
+
throw new BSONError('bad string length in bson');
|
|
6178
|
+
}
|
|
6179
|
+
var functionString = getValidatedString(buffer, index, index + stringSize - 1);
|
|
6135
6180
|
// If we are evaluating the functions
|
|
6136
6181
|
if (evalFunctions) {
|
|
6137
6182
|
// If we have cache enabled let's look for the md5 of the function in the cache
|
|
@@ -6156,7 +6201,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6156
6201
|
(buffer[index++] << 24);
|
|
6157
6202
|
// Element cannot be shorter than totalSize + stringSize + documentSize + terminator
|
|
6158
6203
|
if (totalSize < 4 + 4 + 4 + 1) {
|
|
6159
|
-
throw new
|
|
6204
|
+
throw new BSONError('code_w_scope total size shorter minimum expected length');
|
|
6160
6205
|
}
|
|
6161
6206
|
// Get the code string size
|
|
6162
6207
|
var stringSize = buffer[index++] |
|
|
@@ -6166,10 +6211,11 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6166
6211
|
// Check if we have a valid string
|
|
6167
6212
|
if (stringSize <= 0 ||
|
|
6168
6213
|
stringSize > buffer.length - index ||
|
|
6169
|
-
buffer[index + stringSize - 1] !== 0)
|
|
6170
|
-
throw new
|
|
6214
|
+
buffer[index + stringSize - 1] !== 0) {
|
|
6215
|
+
throw new BSONError('bad string length in bson');
|
|
6216
|
+
}
|
|
6171
6217
|
// Javascript function
|
|
6172
|
-
var functionString = buffer
|
|
6218
|
+
var functionString = getValidatedString(buffer, index, index + stringSize - 1);
|
|
6173
6219
|
// Update parse index position
|
|
6174
6220
|
index = index + stringSize;
|
|
6175
6221
|
// Parse the element
|
|
@@ -6185,11 +6231,11 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6185
6231
|
index = index + objectSize;
|
|
6186
6232
|
// Check if field length is too short
|
|
6187
6233
|
if (totalSize < 4 + 4 + objectSize + stringSize) {
|
|
6188
|
-
throw new
|
|
6234
|
+
throw new BSONError('code_w_scope total size is too short, truncating scope');
|
|
6189
6235
|
}
|
|
6190
6236
|
// Check if totalSize field is too long
|
|
6191
6237
|
if (totalSize > 4 + 4 + objectSize + stringSize) {
|
|
6192
|
-
throw new
|
|
6238
|
+
throw new BSONError('code_w_scope total size is too long, clips outer document');
|
|
6193
6239
|
}
|
|
6194
6240
|
// If we are evaluating the functions
|
|
6195
6241
|
if (evalFunctions) {
|
|
@@ -6217,10 +6263,10 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6217
6263
|
if (stringSize <= 0 ||
|
|
6218
6264
|
stringSize > buffer.length - index ||
|
|
6219
6265
|
buffer[index + stringSize - 1] !== 0)
|
|
6220
|
-
throw new
|
|
6266
|
+
throw new BSONError('bad string length in bson');
|
|
6221
6267
|
// Namespace
|
|
6222
6268
|
if (!validateUtf8(buffer, index, index + stringSize - 1)) {
|
|
6223
|
-
throw new
|
|
6269
|
+
throw new BSONError('Invalid UTF-8 string in BSON document');
|
|
6224
6270
|
}
|
|
6225
6271
|
var namespace = buffer.toString('utf8', index, index + stringSize - 1);
|
|
6226
6272
|
// Update parse index position
|
|
@@ -6235,7 +6281,7 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6235
6281
|
value = new DBRef(namespace, oid);
|
|
6236
6282
|
}
|
|
6237
6283
|
else {
|
|
6238
|
-
throw new
|
|
6284
|
+
throw new BSONError('Detected unknown BSON type ' + elementType.toString(16) + ' for fieldname "' + name + '"');
|
|
6239
6285
|
}
|
|
6240
6286
|
if (name === '__proto__') {
|
|
6241
6287
|
Object.defineProperty(object, name, {
|
|
@@ -6252,8 +6298,8 @@ function deserializeObject(buffer, index, options, isArray) {
|
|
|
6252
6298
|
// Check if the deserialization was against a valid array/object
|
|
6253
6299
|
if (size !== index - startIndex) {
|
|
6254
6300
|
if (isArray)
|
|
6255
|
-
throw new
|
|
6256
|
-
throw new
|
|
6301
|
+
throw new BSONError('corrupt array bson');
|
|
6302
|
+
throw new BSONError('corrupt object bson');
|
|
6257
6303
|
}
|
|
6258
6304
|
// if we did not find "$ref", "$id", "$db", or found an extraneous $key, don't make a DBRef
|
|
6259
6305
|
if (!isPossibleDBRef)
|
|
@@ -6282,6 +6328,18 @@ function isolateEval(functionString, functionCache, object) {
|
|
|
6282
6328
|
// Set the object
|
|
6283
6329
|
return functionCache[functionString].bind(object);
|
|
6284
6330
|
}
|
|
6331
|
+
function getValidatedString(buffer, start, end) {
|
|
6332
|
+
var value = buffer.toString('utf8', start, end);
|
|
6333
|
+
for (var i = 0; i < value.length; i++) {
|
|
6334
|
+
if (value.charCodeAt(i) === 0xfffd) {
|
|
6335
|
+
if (!validateUtf8(buffer, start, end)) {
|
|
6336
|
+
throw new BSONError('Invalid UTF-8 string in BSON document');
|
|
6337
|
+
}
|
|
6338
|
+
break;
|
|
6339
|
+
}
|
|
6340
|
+
}
|
|
6341
|
+
return value;
|
|
6342
|
+
}
|
|
6285
6343
|
|
|
6286
6344
|
// Copyright (c) 2008, Fair Oaks Labs, Inc.
|
|
6287
6345
|
function writeIEEE754(buffer, value, offset, endian, mLen, nBytes) {
|
|
@@ -6566,7 +6624,7 @@ function serializeObjectId(buffer, key, value, index, isArray) {
|
|
|
6566
6624
|
buffer.set(value.id.subarray(0, 12), index);
|
|
6567
6625
|
}
|
|
6568
6626
|
else {
|
|
6569
|
-
throw new
|
|
6627
|
+
throw new BSONTypeError('object [' + JSON.stringify(value) + '] is not a valid ObjectId');
|
|
6570
6628
|
}
|
|
6571
6629
|
// Adjust index
|
|
6572
6630
|
return index + 12;
|
|
@@ -6605,7 +6663,7 @@ function serializeObject(buffer, key, value, index, checkKeys, depth, serializeF
|
|
|
6605
6663
|
if (path === void 0) { path = []; }
|
|
6606
6664
|
for (var i = 0; i < path.length; i++) {
|
|
6607
6665
|
if (path[i] === value)
|
|
6608
|
-
throw new
|
|
6666
|
+
throw new BSONError('cyclic dependency detected');
|
|
6609
6667
|
}
|
|
6610
6668
|
// Push value to stack
|
|
6611
6669
|
path.push(value);
|
|
@@ -6908,7 +6966,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
6908
6966
|
// Is there an override value
|
|
6909
6967
|
if (value && value.toBSON) {
|
|
6910
6968
|
if (typeof value.toBSON !== 'function')
|
|
6911
|
-
throw new
|
|
6969
|
+
throw new BSONTypeError('toBSON is not a function');
|
|
6912
6970
|
value = value.toBSON();
|
|
6913
6971
|
}
|
|
6914
6972
|
if (typeof value === 'string') {
|
|
@@ -6918,7 +6976,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
6918
6976
|
index = serializeNumber(buffer, key, value, index, true);
|
|
6919
6977
|
}
|
|
6920
6978
|
else if (typeof value === 'bigint') {
|
|
6921
|
-
throw new
|
|
6979
|
+
throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
|
|
6922
6980
|
}
|
|
6923
6981
|
else if (typeof value === 'boolean') {
|
|
6924
6982
|
index = serializeBoolean(buffer, key, value, index, true);
|
|
@@ -6980,7 +7038,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
6980
7038
|
index = serializeMinMax(buffer, key, value, index, true);
|
|
6981
7039
|
}
|
|
6982
7040
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
6983
|
-
throw new
|
|
7041
|
+
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
|
|
6984
7042
|
}
|
|
6985
7043
|
}
|
|
6986
7044
|
}
|
|
@@ -7022,7 +7080,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
7022
7080
|
index = serializeNumber(buffer, key, value, index);
|
|
7023
7081
|
}
|
|
7024
7082
|
else if (type === 'bigint' || isBigInt64Array(value) || isBigUInt64Array(value)) {
|
|
7025
|
-
throw new
|
|
7083
|
+
throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
|
|
7026
7084
|
}
|
|
7027
7085
|
else if (type === 'boolean') {
|
|
7028
7086
|
index = serializeBoolean(buffer, key, value, index);
|
|
@@ -7079,7 +7137,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
7079
7137
|
index = serializeMinMax(buffer, key, value, index);
|
|
7080
7138
|
}
|
|
7081
7139
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7082
|
-
throw new
|
|
7140
|
+
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
|
|
7083
7141
|
}
|
|
7084
7142
|
}
|
|
7085
7143
|
}
|
|
@@ -7087,10 +7145,10 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
7087
7145
|
// Did we provide a custom serialization method
|
|
7088
7146
|
if (object.toBSON) {
|
|
7089
7147
|
if (typeof object.toBSON !== 'function')
|
|
7090
|
-
throw new
|
|
7148
|
+
throw new BSONTypeError('toBSON is not a function');
|
|
7091
7149
|
object = object.toBSON();
|
|
7092
7150
|
if (object != null && typeof object !== 'object')
|
|
7093
|
-
throw new
|
|
7151
|
+
throw new BSONTypeError('toBSON function did not return an object');
|
|
7094
7152
|
}
|
|
7095
7153
|
// Iterate over all the keys
|
|
7096
7154
|
for (var key in object) {
|
|
@@ -7098,7 +7156,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
7098
7156
|
// Is there an override value
|
|
7099
7157
|
if (value && value.toBSON) {
|
|
7100
7158
|
if (typeof value.toBSON !== 'function')
|
|
7101
|
-
throw new
|
|
7159
|
+
throw new BSONTypeError('toBSON is not a function');
|
|
7102
7160
|
value = value.toBSON();
|
|
7103
7161
|
}
|
|
7104
7162
|
// Check the type of the value
|
|
@@ -7126,7 +7184,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
7126
7184
|
index = serializeNumber(buffer, key, value, index);
|
|
7127
7185
|
}
|
|
7128
7186
|
else if (type === 'bigint') {
|
|
7129
|
-
throw new
|
|
7187
|
+
throw new BSONTypeError('Unsupported type BigInt, please use Decimal128');
|
|
7130
7188
|
}
|
|
7131
7189
|
else if (type === 'boolean') {
|
|
7132
7190
|
index = serializeBoolean(buffer, key, value, index);
|
|
@@ -7187,7 +7245,7 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
7187
7245
|
index = serializeMinMax(buffer, key, value, index);
|
|
7188
7246
|
}
|
|
7189
7247
|
else if (typeof value['_bsontype'] !== 'undefined') {
|
|
7190
|
-
throw new
|
|
7248
|
+
throw new BSONTypeError('Unrecognized or invalid _bsontype: ' + value['_bsontype']);
|
|
7191
7249
|
}
|
|
7192
7250
|
}
|
|
7193
7251
|
}
|
|
@@ -7360,9 +7418,11 @@ var BSON = {
|
|
|
7360
7418
|
serializeWithBufferAndIndex: serializeWithBufferAndIndex,
|
|
7361
7419
|
deserialize: deserialize,
|
|
7362
7420
|
calculateObjectSize: calculateObjectSize,
|
|
7363
|
-
deserializeStream: deserializeStream
|
|
7421
|
+
deserializeStream: deserializeStream,
|
|
7422
|
+
BSONError: BSONError,
|
|
7423
|
+
BSONTypeError: BSONTypeError
|
|
7364
7424
|
};
|
|
7365
7425
|
|
|
7366
7426
|
export default BSON;
|
|
7367
|
-
export { BSONRegExp, BSONSymbol, BSON_BINARY_SUBTYPE_BYTE_ARRAY, BSON_BINARY_SUBTYPE_DEFAULT, BSON_BINARY_SUBTYPE_FUNCTION, BSON_BINARY_SUBTYPE_MD5, BSON_BINARY_SUBTYPE_USER_DEFINED, BSON_BINARY_SUBTYPE_UUID, BSON_BINARY_SUBTYPE_UUID_NEW, BSON_DATA_ARRAY, BSON_DATA_BINARY, BSON_DATA_BOOLEAN, BSON_DATA_CODE, BSON_DATA_CODE_W_SCOPE, BSON_DATA_DATE, BSON_DATA_DBPOINTER, BSON_DATA_DECIMAL128, BSON_DATA_INT, BSON_DATA_LONG, BSON_DATA_MAX_KEY, BSON_DATA_MIN_KEY, BSON_DATA_NULL, BSON_DATA_NUMBER, BSON_DATA_OBJECT, BSON_DATA_OID, BSON_DATA_REGEXP, BSON_DATA_STRING, BSON_DATA_SYMBOL, BSON_DATA_TIMESTAMP, BSON_DATA_UNDEFINED, BSON_INT32_MAX, BSON_INT32_MIN, BSON_INT64_MAX, BSON_INT64_MIN, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, LongWithoutOverridesClass, bsonMap as Map, MaxKey, MinKey, ObjectId as ObjectID, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
|
|
7427
|
+
export { BSONError, BSONRegExp, BSONSymbol, BSONTypeError, BSON_BINARY_SUBTYPE_BYTE_ARRAY, BSON_BINARY_SUBTYPE_COLUMN, BSON_BINARY_SUBTYPE_DEFAULT, BSON_BINARY_SUBTYPE_ENCRYPTED, BSON_BINARY_SUBTYPE_FUNCTION, BSON_BINARY_SUBTYPE_MD5, BSON_BINARY_SUBTYPE_USER_DEFINED, BSON_BINARY_SUBTYPE_UUID, BSON_BINARY_SUBTYPE_UUID_NEW, BSON_DATA_ARRAY, BSON_DATA_BINARY, BSON_DATA_BOOLEAN, BSON_DATA_CODE, BSON_DATA_CODE_W_SCOPE, BSON_DATA_DATE, BSON_DATA_DBPOINTER, BSON_DATA_DECIMAL128, BSON_DATA_INT, BSON_DATA_LONG, BSON_DATA_MAX_KEY, BSON_DATA_MIN_KEY, BSON_DATA_NULL, BSON_DATA_NUMBER, BSON_DATA_OBJECT, BSON_DATA_OID, BSON_DATA_REGEXP, BSON_DATA_STRING, BSON_DATA_SYMBOL, BSON_DATA_TIMESTAMP, BSON_DATA_UNDEFINED, BSON_INT32_MAX, BSON_INT32_MIN, BSON_INT64_MAX, BSON_INT64_MIN, Binary, Code, DBRef, Decimal128, Double, EJSON, Int32, Long, LongWithoutOverridesClass, bsonMap as Map, MaxKey, MinKey, ObjectId as ObjectID, ObjectId, Timestamp, UUID, calculateObjectSize, deserialize, deserializeStream, serialize, serializeWithBufferAndIndex, setInternalBufferSize };
|
|
7368
7428
|
//# sourceMappingURL=bson.browser.esm.js.map
|