bson 6.8.0 → 6.9.0
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/bson.d.ts +16 -0
- package/lib/bson.bundle.js +251 -189
- package/lib/bson.bundle.js.map +1 -1
- package/lib/bson.cjs +251 -189
- package/lib/bson.cjs.map +1 -1
- package/lib/bson.mjs +251 -189
- package/lib/bson.mjs.map +1 -1
- package/lib/bson.rn.cjs +255 -191
- package/lib/bson.rn.cjs.map +1 -1
- package/package.json +21 -20
- package/src/bson_value.ts +2 -1
- package/src/constants.ts +3 -0
- package/src/decimal128.ts +1 -1
- package/src/extended_json.ts +3 -2
- package/src/long.ts +0 -1
- package/src/objectid.ts +25 -4
- package/src/parser/calculate_size.ts +1 -1
- package/src/parser/serializer.ts +196 -188
- package/src/parser/utils.ts +43 -9
- package/src/timestamp.ts +19 -3
package/bson.d.ts
CHANGED
|
@@ -151,6 +151,10 @@ declare namespace BSON {
|
|
|
151
151
|
}
|
|
152
152
|
export { BSON }
|
|
153
153
|
|
|
154
|
+
/* Excluded from this release type: BSON_MAJOR_VERSION */
|
|
155
|
+
|
|
156
|
+
/* Excluded from this release type: BSON_VERSION_SYMBOL */
|
|
157
|
+
|
|
154
158
|
/**
|
|
155
159
|
* @public
|
|
156
160
|
* @experimental
|
|
@@ -311,6 +315,7 @@ export declare type BSONType = (typeof BSONType)[keyof typeof BSONType];
|
|
|
311
315
|
export declare abstract class BSONValue {
|
|
312
316
|
/** @public */
|
|
313
317
|
abstract get _bsontype(): string;
|
|
318
|
+
/* Excluded from this release type: [BSON_VERSION_SYMBOL] */
|
|
314
319
|
/**
|
|
315
320
|
* @public
|
|
316
321
|
* Prints a human-readable string of BSON value information
|
|
@@ -1285,6 +1290,7 @@ export declare class ObjectId extends BSONValue {
|
|
|
1285
1290
|
*/
|
|
1286
1291
|
get id(): Uint8Array;
|
|
1287
1292
|
set id(value: Uint8Array);
|
|
1293
|
+
/* Excluded from this release type: validateHexString */
|
|
1288
1294
|
/** Returns the ObjectId id as a 24 lowercase character hex string representation */
|
|
1289
1295
|
toHexString(): string;
|
|
1290
1296
|
/* Excluded from this release type: getInc */
|
|
@@ -1472,10 +1478,20 @@ declare function stringify(value: any, replacer?: (number | string)[] | ((this:
|
|
|
1472
1478
|
/**
|
|
1473
1479
|
* @public
|
|
1474
1480
|
* @category BSONType
|
|
1481
|
+
*
|
|
1482
|
+
* A special type for _internal_ MongoDB use and is **not** associated with the regular Date type.
|
|
1475
1483
|
*/
|
|
1476
1484
|
export declare class Timestamp extends LongWithoutOverridesClass {
|
|
1477
1485
|
get _bsontype(): 'Timestamp';
|
|
1478
1486
|
static readonly MAX_VALUE: Long;
|
|
1487
|
+
/**
|
|
1488
|
+
* An incrementing ordinal for operations within a given second.
|
|
1489
|
+
*/
|
|
1490
|
+
get i(): number;
|
|
1491
|
+
/**
|
|
1492
|
+
* A `time_t` value measuring seconds since the Unix epoch
|
|
1493
|
+
*/
|
|
1494
|
+
get t(): number;
|
|
1479
1495
|
/**
|
|
1480
1496
|
* @param int - A 64-bit bigint representing the Timestamp.
|
|
1481
1497
|
*/
|
package/lib/bson.bundle.js
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
1
|
var BSON = (function (exports) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
const map = new WeakMap();
|
|
5
|
+
const TYPES = {
|
|
6
|
+
ArrayBuffer: '[object ArrayBuffer]',
|
|
7
|
+
SharedArrayBuffer: '[object SharedArrayBuffer]',
|
|
8
|
+
Uint8Array: '[object Uint8Array]',
|
|
9
|
+
BigInt64Array: '[object BigInt64Array]',
|
|
10
|
+
BigUint64Array: '[object BigUint64Array]',
|
|
11
|
+
RegExp: '[object RegExp]',
|
|
12
|
+
Map: '[object Map]',
|
|
13
|
+
Date: '[object Date]'
|
|
14
|
+
};
|
|
15
|
+
function getPrototypeString(value) {
|
|
16
|
+
let str = map.get(value);
|
|
17
|
+
if (!str) {
|
|
18
|
+
str = Object.prototype.toString.call(value);
|
|
19
|
+
if (value !== null && typeof value === 'object') {
|
|
20
|
+
map.set(value, str);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return str;
|
|
24
|
+
}
|
|
4
25
|
function isAnyArrayBuffer(value) {
|
|
5
|
-
|
|
26
|
+
const type = getPrototypeString(value);
|
|
27
|
+
return type === TYPES.ArrayBuffer || type === TYPES.SharedArrayBuffer;
|
|
6
28
|
}
|
|
7
29
|
function isUint8Array(value) {
|
|
8
|
-
|
|
30
|
+
const type = getPrototypeString(value);
|
|
31
|
+
return type === TYPES.Uint8Array;
|
|
9
32
|
}
|
|
10
33
|
function isRegExp(d) {
|
|
11
|
-
|
|
34
|
+
const type = getPrototypeString(d);
|
|
35
|
+
return type === TYPES.RegExp;
|
|
12
36
|
}
|
|
13
37
|
function isMap(d) {
|
|
14
|
-
|
|
38
|
+
const type = getPrototypeString(d);
|
|
39
|
+
return type === TYPES.Map;
|
|
15
40
|
}
|
|
16
41
|
function isDate(d) {
|
|
17
|
-
|
|
42
|
+
const type = getPrototypeString(d);
|
|
43
|
+
return type === TYPES.Date;
|
|
18
44
|
}
|
|
19
45
|
function defaultInspect(x, _options) {
|
|
20
46
|
return JSON.stringify(x, (k, v) => {
|
|
@@ -38,6 +64,7 @@ function getStylizeFunction(options) {
|
|
|
38
64
|
}
|
|
39
65
|
|
|
40
66
|
const BSON_MAJOR_VERSION = 6;
|
|
67
|
+
const BSON_VERSION_SYMBOL = Symbol.for('@@mdb.bson.version');
|
|
41
68
|
const BSON_INT32_MAX = 0x7fffffff;
|
|
42
69
|
const BSON_INT32_MIN = -0x80000000;
|
|
43
70
|
const BSON_INT64_MAX = Math.pow(2, 63) - 1;
|
|
@@ -412,7 +439,7 @@ const hasGlobalBuffer = typeof Buffer === 'function' && Buffer.prototype?._isBuf
|
|
|
412
439
|
const ByteUtils = hasGlobalBuffer ? nodeJsByteUtils : webByteUtils;
|
|
413
440
|
|
|
414
441
|
class BSONValue {
|
|
415
|
-
get [
|
|
442
|
+
get [BSON_VERSION_SYMBOL]() {
|
|
416
443
|
return BSON_MAJOR_VERSION;
|
|
417
444
|
}
|
|
418
445
|
[Symbol.for('nodejs.util.inspect.custom')](depth, options, inspect) {
|
|
@@ -1589,7 +1616,7 @@ class Decimal128 extends BSONValue {
|
|
|
1589
1616
|
if (typeof bytes === 'string') {
|
|
1590
1617
|
this.bytes = Decimal128.fromString(bytes).bytes;
|
|
1591
1618
|
}
|
|
1592
|
-
else if (isUint8Array(bytes)) {
|
|
1619
|
+
else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
|
|
1593
1620
|
if (bytes.byteLength !== 16) {
|
|
1594
1621
|
throw new BSONError('Decimal128 must take a Buffer of 16 bytes');
|
|
1595
1622
|
}
|
|
@@ -2280,7 +2307,7 @@ const NumberUtils = {
|
|
|
2280
2307
|
return 4;
|
|
2281
2308
|
},
|
|
2282
2309
|
setBigInt64LE(destination, offset, value) {
|
|
2283
|
-
const mask32bits = BigInt(
|
|
2310
|
+
const mask32bits = BigInt(0xffff_ffff);
|
|
2284
2311
|
let lo = Number(value & mask32bits);
|
|
2285
2312
|
destination[offset] = lo;
|
|
2286
2313
|
lo >>= 8;
|
|
@@ -2326,7 +2353,6 @@ const NumberUtils = {
|
|
|
2326
2353
|
}
|
|
2327
2354
|
};
|
|
2328
2355
|
|
|
2329
|
-
const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
|
|
2330
2356
|
let PROCESS_UNIQUE = null;
|
|
2331
2357
|
class ObjectId extends BSONValue {
|
|
2332
2358
|
get _bsontype() {
|
|
@@ -2356,7 +2382,7 @@ class ObjectId extends BSONValue {
|
|
|
2356
2382
|
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
|
2357
2383
|
}
|
|
2358
2384
|
else if (typeof workingId === 'string') {
|
|
2359
|
-
if (
|
|
2385
|
+
if (ObjectId.validateHexString(workingId)) {
|
|
2360
2386
|
this.buffer = ByteUtils.fromHex(workingId);
|
|
2361
2387
|
}
|
|
2362
2388
|
else {
|
|
@@ -2379,6 +2405,20 @@ class ObjectId extends BSONValue {
|
|
|
2379
2405
|
this.__id = ByteUtils.toHex(value);
|
|
2380
2406
|
}
|
|
2381
2407
|
}
|
|
2408
|
+
static validateHexString(string) {
|
|
2409
|
+
if (string?.length !== 24)
|
|
2410
|
+
return false;
|
|
2411
|
+
for (let i = 0; i < 24; i++) {
|
|
2412
|
+
const char = string.charCodeAt(i);
|
|
2413
|
+
if ((char >= 48 && char <= 57) ||
|
|
2414
|
+
(char >= 97 && char <= 102) ||
|
|
2415
|
+
(char >= 65 && char <= 70)) {
|
|
2416
|
+
continue;
|
|
2417
|
+
}
|
|
2418
|
+
return false;
|
|
2419
|
+
}
|
|
2420
|
+
return true;
|
|
2421
|
+
}
|
|
2382
2422
|
toHexString() {
|
|
2383
2423
|
if (ObjectId.cacheHexString && this.__id) {
|
|
2384
2424
|
return this.__id;
|
|
@@ -2491,6 +2531,8 @@ class ObjectId extends BSONValue {
|
|
|
2491
2531
|
static isValid(id) {
|
|
2492
2532
|
if (id == null)
|
|
2493
2533
|
return false;
|
|
2534
|
+
if (typeof id === 'string')
|
|
2535
|
+
return ObjectId.validateHexString(id);
|
|
2494
2536
|
try {
|
|
2495
2537
|
new ObjectId(id);
|
|
2496
2538
|
return true;
|
|
@@ -2561,7 +2603,7 @@ function calculateElement(name, value, serializeFunctions = false, isArray = fal
|
|
|
2561
2603
|
case 'object':
|
|
2562
2604
|
if (value != null &&
|
|
2563
2605
|
typeof value._bsontype === 'string' &&
|
|
2564
|
-
value[
|
|
2606
|
+
value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
2565
2607
|
throw new BSONVersionError();
|
|
2566
2608
|
}
|
|
2567
2609
|
else if (value == null || value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
@@ -2765,6 +2807,12 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2765
2807
|
get _bsontype() {
|
|
2766
2808
|
return 'Timestamp';
|
|
2767
2809
|
}
|
|
2810
|
+
get i() {
|
|
2811
|
+
return this.low >>> 0;
|
|
2812
|
+
}
|
|
2813
|
+
get t() {
|
|
2814
|
+
return this.high >>> 0;
|
|
2815
|
+
}
|
|
2768
2816
|
constructor(low) {
|
|
2769
2817
|
if (low == null) {
|
|
2770
2818
|
super(0, 0, true);
|
|
@@ -2790,10 +2838,10 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2790
2838
|
if (i < 0 || Number.isNaN(i)) {
|
|
2791
2839
|
throw new BSONError('Timestamp constructed from { t, i } must provide a positive i');
|
|
2792
2840
|
}
|
|
2793
|
-
if (t >
|
|
2841
|
+
if (t > 0xffff_ffff) {
|
|
2794
2842
|
throw new BSONError('Timestamp constructed from { t, i } must provide t equal or less than uint32 max');
|
|
2795
2843
|
}
|
|
2796
|
-
if (i >
|
|
2844
|
+
if (i > 0xffff_ffff) {
|
|
2797
2845
|
throw new BSONError('Timestamp constructed from { t, i } must provide i equal or less than uint32 max');
|
|
2798
2846
|
}
|
|
2799
2847
|
super(i, t, true);
|
|
@@ -2820,7 +2868,7 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2820
2868
|
return new Timestamp(Long.fromString(str, true, optRadix));
|
|
2821
2869
|
}
|
|
2822
2870
|
toExtendedJSON() {
|
|
2823
|
-
return { $timestamp: { t: this.
|
|
2871
|
+
return { $timestamp: { t: this.t, i: this.i } };
|
|
2824
2872
|
}
|
|
2825
2873
|
static fromExtendedJSON(doc) {
|
|
2826
2874
|
const i = Long.isLong(doc.$timestamp.i)
|
|
@@ -2833,8 +2881,8 @@ class Timestamp extends LongWithoutOverridesClass {
|
|
|
2833
2881
|
}
|
|
2834
2882
|
inspect(depth, options, inspect) {
|
|
2835
2883
|
inspect ??= defaultInspect;
|
|
2836
|
-
const t = inspect(this.
|
|
2837
|
-
const i = inspect(this.
|
|
2884
|
+
const t = inspect(this.t, options);
|
|
2885
|
+
const i = inspect(this.i, options);
|
|
2838
2886
|
return `new Timestamp({ t: ${t}, i: ${i} })`;
|
|
2839
2887
|
}
|
|
2840
2888
|
}
|
|
@@ -3603,79 +3651,83 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
3603
3651
|
if (typeof value?.toBSON === 'function') {
|
|
3604
3652
|
value = value.toBSON();
|
|
3605
3653
|
}
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
}
|
|
3609
|
-
else if (typeof value === 'number') {
|
|
3610
|
-
index = serializeNumber(buffer, key, value, index);
|
|
3611
|
-
}
|
|
3612
|
-
else if (typeof value === 'bigint') {
|
|
3613
|
-
index = serializeBigInt(buffer, key, value, index);
|
|
3614
|
-
}
|
|
3615
|
-
else if (typeof value === 'boolean') {
|
|
3616
|
-
index = serializeBoolean(buffer, key, value, index);
|
|
3617
|
-
}
|
|
3618
|
-
else if (value instanceof Date || isDate(value)) {
|
|
3619
|
-
index = serializeDate(buffer, key, value, index);
|
|
3620
|
-
}
|
|
3621
|
-
else if (value === undefined) {
|
|
3654
|
+
const type = typeof value;
|
|
3655
|
+
if (value === undefined) {
|
|
3622
3656
|
index = serializeNull(buffer, key, value, index);
|
|
3623
3657
|
}
|
|
3624
3658
|
else if (value === null) {
|
|
3625
3659
|
index = serializeNull(buffer, key, value, index);
|
|
3626
3660
|
}
|
|
3627
|
-
else if (
|
|
3628
|
-
index =
|
|
3629
|
-
}
|
|
3630
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
3631
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
3632
|
-
}
|
|
3633
|
-
else if (typeof value === 'object' && value._bsontype == null) {
|
|
3634
|
-
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3661
|
+
else if (type === 'string') {
|
|
3662
|
+
index = serializeString(buffer, key, value, index);
|
|
3635
3663
|
}
|
|
3636
|
-
else if (
|
|
3637
|
-
|
|
3638
|
-
throw new BSONVersionError();
|
|
3664
|
+
else if (type === 'number') {
|
|
3665
|
+
index = serializeNumber(buffer, key, value, index);
|
|
3639
3666
|
}
|
|
3640
|
-
else if (
|
|
3641
|
-
index =
|
|
3667
|
+
else if (type === 'bigint') {
|
|
3668
|
+
index = serializeBigInt(buffer, key, value, index);
|
|
3642
3669
|
}
|
|
3643
|
-
else if (
|
|
3644
|
-
index =
|
|
3670
|
+
else if (type === 'boolean') {
|
|
3671
|
+
index = serializeBoolean(buffer, key, value, index);
|
|
3645
3672
|
}
|
|
3646
|
-
else if (
|
|
3647
|
-
|
|
3673
|
+
else if (type === 'object' && value._bsontype == null) {
|
|
3674
|
+
if (value instanceof Date || isDate(value)) {
|
|
3675
|
+
index = serializeDate(buffer, key, value, index);
|
|
3676
|
+
}
|
|
3677
|
+
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
3678
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
3679
|
+
}
|
|
3680
|
+
else if (value instanceof RegExp || isRegExp(value)) {
|
|
3681
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
3682
|
+
}
|
|
3683
|
+
else {
|
|
3684
|
+
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3685
|
+
}
|
|
3648
3686
|
}
|
|
3649
|
-
else if (
|
|
3650
|
-
|
|
3687
|
+
else if (type === 'object') {
|
|
3688
|
+
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
3689
|
+
throw new BSONVersionError();
|
|
3690
|
+
}
|
|
3691
|
+
else if (value._bsontype === 'ObjectId') {
|
|
3692
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
3693
|
+
}
|
|
3694
|
+
else if (value._bsontype === 'Decimal128') {
|
|
3695
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
3696
|
+
}
|
|
3697
|
+
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
3698
|
+
index = serializeLong(buffer, key, value, index);
|
|
3699
|
+
}
|
|
3700
|
+
else if (value._bsontype === 'Double') {
|
|
3701
|
+
index = serializeDouble(buffer, key, value, index);
|
|
3702
|
+
}
|
|
3703
|
+
else if (value._bsontype === 'Code') {
|
|
3704
|
+
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3705
|
+
}
|
|
3706
|
+
else if (value._bsontype === 'Binary') {
|
|
3707
|
+
index = serializeBinary(buffer, key, value, index);
|
|
3708
|
+
}
|
|
3709
|
+
else if (value._bsontype === 'BSONSymbol') {
|
|
3710
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
3711
|
+
}
|
|
3712
|
+
else if (value._bsontype === 'DBRef') {
|
|
3713
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
3714
|
+
}
|
|
3715
|
+
else if (value._bsontype === 'BSONRegExp') {
|
|
3716
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
3717
|
+
}
|
|
3718
|
+
else if (value._bsontype === 'Int32') {
|
|
3719
|
+
index = serializeInt32(buffer, key, value, index);
|
|
3720
|
+
}
|
|
3721
|
+
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
3722
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
3723
|
+
}
|
|
3724
|
+
else if (typeof value._bsontype !== 'undefined') {
|
|
3725
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
3726
|
+
}
|
|
3651
3727
|
}
|
|
3652
|
-
else if (
|
|
3728
|
+
else if (type === 'function' && serializeFunctions) {
|
|
3653
3729
|
index = serializeFunction(buffer, key, value, index);
|
|
3654
3730
|
}
|
|
3655
|
-
else if (value._bsontype === 'Code') {
|
|
3656
|
-
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3657
|
-
}
|
|
3658
|
-
else if (value._bsontype === 'Binary') {
|
|
3659
|
-
index = serializeBinary(buffer, key, value, index);
|
|
3660
|
-
}
|
|
3661
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
3662
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
3663
|
-
}
|
|
3664
|
-
else if (value._bsontype === 'DBRef') {
|
|
3665
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
3666
|
-
}
|
|
3667
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
3668
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
3669
|
-
}
|
|
3670
|
-
else if (value._bsontype === 'Int32') {
|
|
3671
|
-
index = serializeInt32(buffer, key, value, index);
|
|
3672
|
-
}
|
|
3673
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
3674
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
3675
|
-
}
|
|
3676
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
3677
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
3678
|
-
}
|
|
3679
3731
|
}
|
|
3680
3732
|
}
|
|
3681
3733
|
else if (object instanceof Map || isMap(object)) {
|
|
@@ -3705,7 +3757,14 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
3705
3757
|
}
|
|
3706
3758
|
}
|
|
3707
3759
|
}
|
|
3708
|
-
if (
|
|
3760
|
+
if (value === undefined) {
|
|
3761
|
+
if (ignoreUndefined === false)
|
|
3762
|
+
index = serializeNull(buffer, key, value, index);
|
|
3763
|
+
}
|
|
3764
|
+
else if (value === null) {
|
|
3765
|
+
index = serializeNull(buffer, key, value, index);
|
|
3766
|
+
}
|
|
3767
|
+
else if (type === 'string') {
|
|
3709
3768
|
index = serializeString(buffer, key, value, index);
|
|
3710
3769
|
}
|
|
3711
3770
|
else if (type === 'number') {
|
|
@@ -3717,64 +3776,64 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
3717
3776
|
else if (type === 'boolean') {
|
|
3718
3777
|
index = serializeBoolean(buffer, key, value, index);
|
|
3719
3778
|
}
|
|
3720
|
-
else if (value instanceof Date || isDate(value)) {
|
|
3721
|
-
index = serializeDate(buffer, key, value, index);
|
|
3722
|
-
}
|
|
3723
|
-
else if (value === null || (value === undefined && ignoreUndefined === false)) {
|
|
3724
|
-
index = serializeNull(buffer, key, value, index);
|
|
3725
|
-
}
|
|
3726
|
-
else if (isUint8Array(value)) {
|
|
3727
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
3728
|
-
}
|
|
3729
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
3730
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
3731
|
-
}
|
|
3732
3779
|
else if (type === 'object' && value._bsontype == null) {
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
value
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
3746
|
-
index = serializeLong(buffer, key, value, index);
|
|
3747
|
-
}
|
|
3748
|
-
else if (value._bsontype === 'Double') {
|
|
3749
|
-
index = serializeDouble(buffer, key, value, index);
|
|
3780
|
+
if (value instanceof Date || isDate(value)) {
|
|
3781
|
+
index = serializeDate(buffer, key, value, index);
|
|
3782
|
+
}
|
|
3783
|
+
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
3784
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
3785
|
+
}
|
|
3786
|
+
else if (value instanceof RegExp || isRegExp(value)) {
|
|
3787
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
3788
|
+
}
|
|
3789
|
+
else {
|
|
3790
|
+
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3791
|
+
}
|
|
3750
3792
|
}
|
|
3751
|
-
else if (
|
|
3752
|
-
|
|
3793
|
+
else if (type === 'object') {
|
|
3794
|
+
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
3795
|
+
throw new BSONVersionError();
|
|
3796
|
+
}
|
|
3797
|
+
else if (value._bsontype === 'ObjectId') {
|
|
3798
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
3799
|
+
}
|
|
3800
|
+
else if (value._bsontype === 'Decimal128') {
|
|
3801
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
3802
|
+
}
|
|
3803
|
+
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
3804
|
+
index = serializeLong(buffer, key, value, index);
|
|
3805
|
+
}
|
|
3806
|
+
else if (value._bsontype === 'Double') {
|
|
3807
|
+
index = serializeDouble(buffer, key, value, index);
|
|
3808
|
+
}
|
|
3809
|
+
else if (value._bsontype === 'Code') {
|
|
3810
|
+
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3811
|
+
}
|
|
3812
|
+
else if (value._bsontype === 'Binary') {
|
|
3813
|
+
index = serializeBinary(buffer, key, value, index);
|
|
3814
|
+
}
|
|
3815
|
+
else if (value._bsontype === 'BSONSymbol') {
|
|
3816
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
3817
|
+
}
|
|
3818
|
+
else if (value._bsontype === 'DBRef') {
|
|
3819
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
3820
|
+
}
|
|
3821
|
+
else if (value._bsontype === 'BSONRegExp') {
|
|
3822
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
3823
|
+
}
|
|
3824
|
+
else if (value._bsontype === 'Int32') {
|
|
3825
|
+
index = serializeInt32(buffer, key, value, index);
|
|
3826
|
+
}
|
|
3827
|
+
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
3828
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
3829
|
+
}
|
|
3830
|
+
else if (typeof value._bsontype !== 'undefined') {
|
|
3831
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
3832
|
+
}
|
|
3753
3833
|
}
|
|
3754
|
-
else if (
|
|
3834
|
+
else if (type === 'function' && serializeFunctions) {
|
|
3755
3835
|
index = serializeFunction(buffer, key, value, index);
|
|
3756
3836
|
}
|
|
3757
|
-
else if (value._bsontype === 'Binary') {
|
|
3758
|
-
index = serializeBinary(buffer, key, value, index);
|
|
3759
|
-
}
|
|
3760
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
3761
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
3762
|
-
}
|
|
3763
|
-
else if (value._bsontype === 'DBRef') {
|
|
3764
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
3765
|
-
}
|
|
3766
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
3767
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
3768
|
-
}
|
|
3769
|
-
else if (value._bsontype === 'Int32') {
|
|
3770
|
-
index = serializeInt32(buffer, key, value, index);
|
|
3771
|
-
}
|
|
3772
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
3773
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
3774
|
-
}
|
|
3775
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
3776
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
3777
|
-
}
|
|
3778
3837
|
}
|
|
3779
3838
|
}
|
|
3780
3839
|
else {
|
|
@@ -3803,7 +3862,14 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
3803
3862
|
}
|
|
3804
3863
|
}
|
|
3805
3864
|
}
|
|
3806
|
-
if (
|
|
3865
|
+
if (value === undefined) {
|
|
3866
|
+
if (ignoreUndefined === false)
|
|
3867
|
+
index = serializeNull(buffer, key, value, index);
|
|
3868
|
+
}
|
|
3869
|
+
else if (value === null) {
|
|
3870
|
+
index = serializeNull(buffer, key, value, index);
|
|
3871
|
+
}
|
|
3872
|
+
else if (type === 'string') {
|
|
3807
3873
|
index = serializeString(buffer, key, value, index);
|
|
3808
3874
|
}
|
|
3809
3875
|
else if (type === 'number') {
|
|
@@ -3815,68 +3881,64 @@ function serializeInto(buffer, object, checkKeys, startingIndex, depth, serializ
|
|
|
3815
3881
|
else if (type === 'boolean') {
|
|
3816
3882
|
index = serializeBoolean(buffer, key, value, index);
|
|
3817
3883
|
}
|
|
3818
|
-
else if (value instanceof Date || isDate(value)) {
|
|
3819
|
-
index = serializeDate(buffer, key, value, index);
|
|
3820
|
-
}
|
|
3821
|
-
else if (value === undefined) {
|
|
3822
|
-
if (ignoreUndefined === false)
|
|
3823
|
-
index = serializeNull(buffer, key, value, index);
|
|
3824
|
-
}
|
|
3825
|
-
else if (value === null) {
|
|
3826
|
-
index = serializeNull(buffer, key, value, index);
|
|
3827
|
-
}
|
|
3828
|
-
else if (isUint8Array(value)) {
|
|
3829
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
3830
|
-
}
|
|
3831
|
-
else if (value instanceof RegExp || isRegExp(value)) {
|
|
3832
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
3833
|
-
}
|
|
3834
3884
|
else if (type === 'object' && value._bsontype == null) {
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
value
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
3848
|
-
index = serializeLong(buffer, key, value, index);
|
|
3849
|
-
}
|
|
3850
|
-
else if (value._bsontype === 'Double') {
|
|
3851
|
-
index = serializeDouble(buffer, key, value, index);
|
|
3885
|
+
if (value instanceof Date || isDate(value)) {
|
|
3886
|
+
index = serializeDate(buffer, key, value, index);
|
|
3887
|
+
}
|
|
3888
|
+
else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
3889
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
3890
|
+
}
|
|
3891
|
+
else if (value instanceof RegExp || isRegExp(value)) {
|
|
3892
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
3893
|
+
}
|
|
3894
|
+
else {
|
|
3895
|
+
index = serializeObject(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3896
|
+
}
|
|
3852
3897
|
}
|
|
3853
|
-
else if (
|
|
3854
|
-
|
|
3898
|
+
else if (type === 'object') {
|
|
3899
|
+
if (value[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
3900
|
+
throw new BSONVersionError();
|
|
3901
|
+
}
|
|
3902
|
+
else if (value._bsontype === 'ObjectId') {
|
|
3903
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
3904
|
+
}
|
|
3905
|
+
else if (value._bsontype === 'Decimal128') {
|
|
3906
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
3907
|
+
}
|
|
3908
|
+
else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
3909
|
+
index = serializeLong(buffer, key, value, index);
|
|
3910
|
+
}
|
|
3911
|
+
else if (value._bsontype === 'Double') {
|
|
3912
|
+
index = serializeDouble(buffer, key, value, index);
|
|
3913
|
+
}
|
|
3914
|
+
else if (value._bsontype === 'Code') {
|
|
3915
|
+
index = serializeCode(buffer, key, value, index, checkKeys, depth, serializeFunctions, ignoreUndefined, path);
|
|
3916
|
+
}
|
|
3917
|
+
else if (value._bsontype === 'Binary') {
|
|
3918
|
+
index = serializeBinary(buffer, key, value, index);
|
|
3919
|
+
}
|
|
3920
|
+
else if (value._bsontype === 'BSONSymbol') {
|
|
3921
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
3922
|
+
}
|
|
3923
|
+
else if (value._bsontype === 'DBRef') {
|
|
3924
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
3925
|
+
}
|
|
3926
|
+
else if (value._bsontype === 'BSONRegExp') {
|
|
3927
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
3928
|
+
}
|
|
3929
|
+
else if (value._bsontype === 'Int32') {
|
|
3930
|
+
index = serializeInt32(buffer, key, value, index);
|
|
3931
|
+
}
|
|
3932
|
+
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
3933
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
3934
|
+
}
|
|
3935
|
+
else if (typeof value._bsontype !== 'undefined') {
|
|
3936
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
3937
|
+
}
|
|
3855
3938
|
}
|
|
3856
|
-
else if (
|
|
3939
|
+
else if (type === 'function' && serializeFunctions) {
|
|
3857
3940
|
index = serializeFunction(buffer, key, value, index);
|
|
3858
3941
|
}
|
|
3859
|
-
else if (value._bsontype === 'Binary') {
|
|
3860
|
-
index = serializeBinary(buffer, key, value, index);
|
|
3861
|
-
}
|
|
3862
|
-
else if (value._bsontype === 'BSONSymbol') {
|
|
3863
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
3864
|
-
}
|
|
3865
|
-
else if (value._bsontype === 'DBRef') {
|
|
3866
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
3867
|
-
}
|
|
3868
|
-
else if (value._bsontype === 'BSONRegExp') {
|
|
3869
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
3870
|
-
}
|
|
3871
|
-
else if (value._bsontype === 'Int32') {
|
|
3872
|
-
index = serializeInt32(buffer, key, value, index);
|
|
3873
|
-
}
|
|
3874
|
-
else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
3875
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
3876
|
-
}
|
|
3877
|
-
else if (typeof value._bsontype !== 'undefined') {
|
|
3878
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
3879
|
-
}
|
|
3880
3942
|
}
|
|
3881
3943
|
}
|
|
3882
3944
|
path.delete(object);
|
|
@@ -4128,7 +4190,7 @@ function serializeDocument(doc, options) {
|
|
|
4128
4190
|
else if (doc != null &&
|
|
4129
4191
|
typeof doc === 'object' &&
|
|
4130
4192
|
typeof doc._bsontype === 'string' &&
|
|
4131
|
-
doc[
|
|
4193
|
+
doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION) {
|
|
4132
4194
|
throw new BSONVersionError();
|
|
4133
4195
|
}
|
|
4134
4196
|
else if (isBSONType(doc)) {
|