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/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"vendor"
|
|
15
15
|
],
|
|
16
16
|
"types": "bson.d.ts",
|
|
17
|
-
"version": "6.
|
|
17
|
+
"version": "6.9.0",
|
|
18
18
|
"author": {
|
|
19
19
|
"name": "The MongoDB NodeJS Team",
|
|
20
20
|
"email": "dbx-node@mongodb.com"
|
|
@@ -27,41 +27,41 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@istanbuljs/nyc-config-typescript": "^1.0.2",
|
|
30
|
-
"@microsoft/api-extractor": "^7.
|
|
30
|
+
"@microsoft/api-extractor": "^7.47.5",
|
|
31
31
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
32
32
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
33
|
-
"@types/chai": "^4.3.
|
|
34
|
-
"@types/mocha": "^10.0.
|
|
35
|
-
"@types/node": "^
|
|
33
|
+
"@types/chai": "^4.3.17",
|
|
34
|
+
"@types/mocha": "^10.0.7",
|
|
35
|
+
"@types/node": "^22.1.0",
|
|
36
36
|
"@types/sinon": "^17.0.3",
|
|
37
37
|
"@types/sinon-chai": "^3.2.12",
|
|
38
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
39
|
-
"@typescript-eslint/parser": "^
|
|
38
|
+
"@typescript-eslint/eslint-plugin": "^8.0.1",
|
|
39
|
+
"@typescript-eslint/parser": "^8.0.1",
|
|
40
40
|
"benchmark": "^2.1.4",
|
|
41
41
|
"chai": "^4.4.1",
|
|
42
42
|
"chalk": "^5.3.0",
|
|
43
43
|
"dbx-js-tools": "github:mongodb-js/dbx-js-tools",
|
|
44
|
-
"eslint": "^8.
|
|
44
|
+
"eslint": "^9.8.0",
|
|
45
45
|
"eslint-config-prettier": "^9.1.0",
|
|
46
46
|
"eslint-plugin-no-bigint-usage": "file:etc/eslint/no-bigint-usage",
|
|
47
|
-
"eslint-plugin-prettier": "^5.1
|
|
48
|
-
"eslint-plugin-tsdoc": "^0.
|
|
49
|
-
"magic-string": "^0.30.
|
|
50
|
-
"mocha": "^10.
|
|
47
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
48
|
+
"eslint-plugin-tsdoc": "^0.3.0",
|
|
49
|
+
"magic-string": "^0.30.11",
|
|
50
|
+
"mocha": "^10.7.0",
|
|
51
51
|
"node-fetch": "^3.3.2",
|
|
52
52
|
"nyc": "^15.1.0",
|
|
53
|
-
"prettier": "^3.
|
|
54
|
-
"rollup": "^4.
|
|
55
|
-
"sinon": "^
|
|
53
|
+
"prettier": "^3.3.3",
|
|
54
|
+
"rollup": "^4.20.0",
|
|
55
|
+
"sinon": "^18.0.0",
|
|
56
56
|
"sinon-chai": "^3.7.0",
|
|
57
57
|
"source-map-support": "^0.5.21",
|
|
58
58
|
"standard-version": "^9.5.0",
|
|
59
|
-
"tar": "^7.
|
|
59
|
+
"tar": "^7.4.3",
|
|
60
60
|
"ts-node": "^10.9.2",
|
|
61
|
-
"tsd": "^0.31.
|
|
62
|
-
"typescript": "5.
|
|
61
|
+
"tsd": "^0.31.1",
|
|
62
|
+
"typescript": "^5.5.4",
|
|
63
63
|
"typescript-cached-transpile": "0.0.6",
|
|
64
|
-
"uuid": "^
|
|
64
|
+
"uuid": "^10.0.0"
|
|
65
65
|
},
|
|
66
66
|
"tsd": {
|
|
67
67
|
"directory": "test/types",
|
|
@@ -105,12 +105,13 @@
|
|
|
105
105
|
"check:web-no-bigint": "WEB=true NO_BIGINT=true mocha test/node",
|
|
106
106
|
"check:granular-bench": "npm run build:bench && node ./test/bench/etc/run_granular_benchmarks.js",
|
|
107
107
|
"check:spec-bench": "npm run build:bench && node ./test/bench/lib/spec/bsonBench.js",
|
|
108
|
+
"check:custom-bench": "npm run build && node ./test/bench/custom/main.mjs",
|
|
108
109
|
"build:bench": "cd test/bench && npx tsc",
|
|
109
110
|
"build:ts": "node ./node_modules/typescript/bin/tsc",
|
|
110
111
|
"build:dts": "npm run build:ts && api-extractor run --typescript-compiler-folder node_modules/typescript --local && node etc/clean_definition_files.cjs",
|
|
111
112
|
"build:bundle": "rollup -c rollup.config.mjs",
|
|
112
113
|
"build": "npm run build:dts && npm run build:bundle",
|
|
113
|
-
"check:lint": "eslint -v && eslint --ext '.js,.ts' --max-warnings=0 src test && npm run build:dts && npm run check:tsd",
|
|
114
|
+
"check:lint": "ESLINT_USE_FLAT_CONFIG=false eslint -v && ESLINT_USE_FLAT_CONFIG=false eslint --ext '.js,.ts' --max-warnings=0 src test && npm run build:dts && npm run check:tsd",
|
|
114
115
|
"format": "eslint --ext '.js,.ts' src test --fix",
|
|
115
116
|
"check:coverage": "nyc --check-coverage npm run check:node",
|
|
116
117
|
"prepare": "node etc/prepare.js",
|
package/src/bson_value.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BSON_MAJOR_VERSION } from './constants';
|
|
2
2
|
import { type InspectFn } from './parser/utils';
|
|
3
|
+
import { BSON_VERSION_SYMBOL } from './constants';
|
|
3
4
|
|
|
4
5
|
/** @public */
|
|
5
6
|
export abstract class BSONValue {
|
|
@@ -7,7 +8,7 @@ export abstract class BSONValue {
|
|
|
7
8
|
public abstract get _bsontype(): string;
|
|
8
9
|
|
|
9
10
|
/** @internal */
|
|
10
|
-
get [
|
|
11
|
+
get [BSON_VERSION_SYMBOL](): typeof BSON_MAJOR_VERSION {
|
|
11
12
|
return BSON_MAJOR_VERSION;
|
|
12
13
|
}
|
|
13
14
|
|
package/src/constants.ts
CHANGED
package/src/decimal128.ts
CHANGED
|
@@ -142,7 +142,7 @@ export class Decimal128 extends BSONValue {
|
|
|
142
142
|
super();
|
|
143
143
|
if (typeof bytes === 'string') {
|
|
144
144
|
this.bytes = Decimal128.fromString(bytes).bytes;
|
|
145
|
-
} else if (isUint8Array(bytes)) {
|
|
145
|
+
} else if (bytes instanceof Uint8Array || isUint8Array(bytes)) {
|
|
146
146
|
if (bytes.byteLength !== 16) {
|
|
147
147
|
throw new BSONError('Decimal128 must take a Buffer of 16 bytes');
|
|
148
148
|
}
|
package/src/extended_json.ts
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
BSON_INT32_MIN,
|
|
7
7
|
BSON_INT64_MAX,
|
|
8
8
|
BSON_INT64_MIN,
|
|
9
|
-
BSON_MAJOR_VERSION
|
|
9
|
+
BSON_MAJOR_VERSION,
|
|
10
|
+
BSON_VERSION_SYMBOL
|
|
10
11
|
} from './constants';
|
|
11
12
|
import { DBRef, isDBRefLike } from './db_ref';
|
|
12
13
|
import { Decimal128 } from './decimal128';
|
|
@@ -358,7 +359,7 @@ function serializeDocument(doc: any, options: EJSONSerializeOptions) {
|
|
|
358
359
|
doc != null &&
|
|
359
360
|
typeof doc === 'object' &&
|
|
360
361
|
typeof doc._bsontype === 'string' &&
|
|
361
|
-
doc[
|
|
362
|
+
doc[BSON_VERSION_SYMBOL] !== BSON_MAJOR_VERSION
|
|
362
363
|
) {
|
|
363
364
|
throw new BSONVersionError();
|
|
364
365
|
} else if (isBSONType(doc)) {
|
package/src/long.ts
CHANGED
|
@@ -1163,7 +1163,6 @@ export class Long extends BSONValue {
|
|
|
1163
1163
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1164
1164
|
let rem: Long = this;
|
|
1165
1165
|
let result = '';
|
|
1166
|
-
// eslint-disable-next-line no-constant-condition
|
|
1167
1166
|
while (true) {
|
|
1168
1167
|
const remDiv = rem.div(radixToPower);
|
|
1169
1168
|
const intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0;
|
package/src/objectid.ts
CHANGED
|
@@ -4,9 +4,6 @@ import { type InspectFn, defaultInspect } from './parser/utils';
|
|
|
4
4
|
import { ByteUtils } from './utils/byte_utils';
|
|
5
5
|
import { NumberUtils } from './utils/number_utils';
|
|
6
6
|
|
|
7
|
-
// Regular expression that checks for hex value
|
|
8
|
-
const checkForHexRegExp = new RegExp('^[0-9a-fA-F]{24}$');
|
|
9
|
-
|
|
10
7
|
// Unique sequence for the current process (initialized on first use)
|
|
11
8
|
let PROCESS_UNIQUE: Uint8Array | null = null;
|
|
12
9
|
|
|
@@ -112,7 +109,7 @@ export class ObjectId extends BSONValue {
|
|
|
112
109
|
// If intstanceof matches we can escape calling ensure buffer in Node.js environments
|
|
113
110
|
this.buffer = ByteUtils.toLocalBufferType(workingId);
|
|
114
111
|
} else if (typeof workingId === 'string') {
|
|
115
|
-
if (
|
|
112
|
+
if (ObjectId.validateHexString(workingId)) {
|
|
116
113
|
this.buffer = ByteUtils.fromHex(workingId);
|
|
117
114
|
} else {
|
|
118
115
|
throw new BSONError(
|
|
@@ -143,6 +140,29 @@ export class ObjectId extends BSONValue {
|
|
|
143
140
|
}
|
|
144
141
|
}
|
|
145
142
|
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
* Validates the input string is a valid hex representation of an ObjectId.
|
|
146
|
+
*/
|
|
147
|
+
private static validateHexString(string: string): boolean {
|
|
148
|
+
if (string?.length !== 24) return false;
|
|
149
|
+
for (let i = 0; i < 24; i++) {
|
|
150
|
+
const char = string.charCodeAt(i);
|
|
151
|
+
if (
|
|
152
|
+
// Check for ASCII 0-9
|
|
153
|
+
(char >= 48 && char <= 57) ||
|
|
154
|
+
// Check for ASCII a-f
|
|
155
|
+
(char >= 97 && char <= 102) ||
|
|
156
|
+
// Check for ASCII A-F
|
|
157
|
+
(char >= 65 && char <= 70)
|
|
158
|
+
) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
|
|
146
166
|
/** Returns the ObjectId id as a 24 lowercase character hex string representation */
|
|
147
167
|
toHexString(): string {
|
|
148
168
|
if (ObjectId.cacheHexString && this.__id) {
|
|
@@ -329,6 +349,7 @@ export class ObjectId extends BSONValue {
|
|
|
329
349
|
*/
|
|
330
350
|
static isValid(id: string | number | ObjectId | ObjectIdLike | Uint8Array): boolean {
|
|
331
351
|
if (id == null) return false;
|
|
352
|
+
if (typeof id === 'string') return ObjectId.validateHexString(id);
|
|
332
353
|
|
|
333
354
|
try {
|
|
334
355
|
new ObjectId(id);
|
|
@@ -81,7 +81,7 @@ function calculateElement(
|
|
|
81
81
|
if (
|
|
82
82
|
value != null &&
|
|
83
83
|
typeof value._bsontype === 'string' &&
|
|
84
|
-
value[
|
|
84
|
+
value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION
|
|
85
85
|
) {
|
|
86
86
|
throw new BSONVersionError();
|
|
87
87
|
} else if (value == null || value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
package/src/parser/serializer.ts
CHANGED
|
@@ -633,77 +633,81 @@ export function serializeInto(
|
|
|
633
633
|
value = value.toBSON();
|
|
634
634
|
}
|
|
635
635
|
|
|
636
|
-
|
|
636
|
+
// Check the type of the value
|
|
637
|
+
const type = typeof value;
|
|
638
|
+
|
|
639
|
+
if (value === undefined) {
|
|
640
|
+
index = serializeNull(buffer, key, value, index);
|
|
641
|
+
} else if (value === null) {
|
|
642
|
+
index = serializeNull(buffer, key, value, index);
|
|
643
|
+
} else if (type === 'string') {
|
|
637
644
|
index = serializeString(buffer, key, value, index);
|
|
638
|
-
} else if (
|
|
645
|
+
} else if (type === 'number') {
|
|
639
646
|
index = serializeNumber(buffer, key, value, index);
|
|
640
|
-
} else if (
|
|
647
|
+
} else if (type === 'bigint') {
|
|
641
648
|
index = serializeBigInt(buffer, key, value, index);
|
|
642
|
-
} else if (
|
|
649
|
+
} else if (type === 'boolean') {
|
|
643
650
|
index = serializeBoolean(buffer, key, value, index);
|
|
644
|
-
} else if (
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
)
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
651
|
+
} else if (type === 'object' && value._bsontype == null) {
|
|
652
|
+
if (value instanceof Date || isDate(value)) {
|
|
653
|
+
index = serializeDate(buffer, key, value, index);
|
|
654
|
+
} else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
655
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
656
|
+
} else if (value instanceof RegExp || isRegExp(value)) {
|
|
657
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
658
|
+
} else {
|
|
659
|
+
index = serializeObject(
|
|
660
|
+
buffer,
|
|
661
|
+
key,
|
|
662
|
+
value,
|
|
663
|
+
index,
|
|
664
|
+
checkKeys,
|
|
665
|
+
depth,
|
|
666
|
+
serializeFunctions,
|
|
667
|
+
ignoreUndefined,
|
|
668
|
+
path
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
} else if (type === 'object') {
|
|
672
|
+
if (value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION) {
|
|
673
|
+
throw new BSONVersionError();
|
|
674
|
+
} else if (value._bsontype === 'ObjectId') {
|
|
675
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
676
|
+
} else if (value._bsontype === 'Decimal128') {
|
|
677
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
678
|
+
} else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
679
|
+
index = serializeLong(buffer, key, value, index);
|
|
680
|
+
} else if (value._bsontype === 'Double') {
|
|
681
|
+
index = serializeDouble(buffer, key, value, index);
|
|
682
|
+
} else if (value._bsontype === 'Code') {
|
|
683
|
+
index = serializeCode(
|
|
684
|
+
buffer,
|
|
685
|
+
key,
|
|
686
|
+
value,
|
|
687
|
+
index,
|
|
688
|
+
checkKeys,
|
|
689
|
+
depth,
|
|
690
|
+
serializeFunctions,
|
|
691
|
+
ignoreUndefined,
|
|
692
|
+
path
|
|
693
|
+
);
|
|
694
|
+
} else if (value._bsontype === 'Binary') {
|
|
695
|
+
index = serializeBinary(buffer, key, value, index);
|
|
696
|
+
} else if (value._bsontype === 'BSONSymbol') {
|
|
697
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
698
|
+
} else if (value._bsontype === 'DBRef') {
|
|
699
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
700
|
+
} else if (value._bsontype === 'BSONRegExp') {
|
|
701
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
702
|
+
} else if (value._bsontype === 'Int32') {
|
|
703
|
+
index = serializeInt32(buffer, key, value, index);
|
|
704
|
+
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
705
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
706
|
+
} else if (typeof value._bsontype !== 'undefined') {
|
|
707
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
708
|
+
}
|
|
709
|
+
} else if (type === 'function' && serializeFunctions) {
|
|
680
710
|
index = serializeFunction(buffer, key, value, index);
|
|
681
|
-
} else if (value._bsontype === 'Code') {
|
|
682
|
-
index = serializeCode(
|
|
683
|
-
buffer,
|
|
684
|
-
key,
|
|
685
|
-
value,
|
|
686
|
-
index,
|
|
687
|
-
checkKeys,
|
|
688
|
-
depth,
|
|
689
|
-
serializeFunctions,
|
|
690
|
-
ignoreUndefined,
|
|
691
|
-
path
|
|
692
|
-
);
|
|
693
|
-
} else if (value._bsontype === 'Binary') {
|
|
694
|
-
index = serializeBinary(buffer, key, value, index);
|
|
695
|
-
} else if (value._bsontype === 'BSONSymbol') {
|
|
696
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
697
|
-
} else if (value._bsontype === 'DBRef') {
|
|
698
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
699
|
-
} else if (value._bsontype === 'BSONRegExp') {
|
|
700
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
701
|
-
} else if (value._bsontype === 'Int32') {
|
|
702
|
-
index = serializeInt32(buffer, key, value, index);
|
|
703
|
-
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
704
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
705
|
-
} else if (typeof value._bsontype !== 'undefined') {
|
|
706
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
707
711
|
}
|
|
708
712
|
}
|
|
709
713
|
} else if (object instanceof Map || isMap(object)) {
|
|
@@ -745,7 +749,11 @@ export function serializeInto(
|
|
|
745
749
|
}
|
|
746
750
|
}
|
|
747
751
|
|
|
748
|
-
if (
|
|
752
|
+
if (value === undefined) {
|
|
753
|
+
if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index);
|
|
754
|
+
} else if (value === null) {
|
|
755
|
+
index = serializeNull(buffer, key, value, index);
|
|
756
|
+
} else if (type === 'string') {
|
|
749
757
|
index = serializeString(buffer, key, value, index);
|
|
750
758
|
} else if (type === 'number') {
|
|
751
759
|
index = serializeNumber(buffer, key, value, index);
|
|
@@ -753,67 +761,66 @@ export function serializeInto(
|
|
|
753
761
|
index = serializeBigInt(buffer, key, value, index);
|
|
754
762
|
} else if (type === 'boolean') {
|
|
755
763
|
index = serializeBoolean(buffer, key, value, index);
|
|
756
|
-
} else if (value instanceof Date || isDate(value)) {
|
|
757
|
-
index = serializeDate(buffer, key, value, index);
|
|
758
|
-
} else if (value === null || (value === undefined && ignoreUndefined === false)) {
|
|
759
|
-
index = serializeNull(buffer, key, value, index);
|
|
760
|
-
} else if (isUint8Array(value)) {
|
|
761
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
762
|
-
} else if (value instanceof RegExp || isRegExp(value)) {
|
|
763
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
764
764
|
} else if (type === 'object' && value._bsontype == null) {
|
|
765
|
-
|
|
766
|
-
buffer,
|
|
767
|
-
|
|
768
|
-
value,
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
key,
|
|
793
|
-
|
|
794
|
-
index,
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
765
|
+
if (value instanceof Date || isDate(value)) {
|
|
766
|
+
index = serializeDate(buffer, key, value, index);
|
|
767
|
+
} else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
768
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
769
|
+
} else if (value instanceof RegExp || isRegExp(value)) {
|
|
770
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
771
|
+
} else {
|
|
772
|
+
index = serializeObject(
|
|
773
|
+
buffer,
|
|
774
|
+
key,
|
|
775
|
+
value,
|
|
776
|
+
index,
|
|
777
|
+
checkKeys,
|
|
778
|
+
depth,
|
|
779
|
+
serializeFunctions,
|
|
780
|
+
ignoreUndefined,
|
|
781
|
+
path
|
|
782
|
+
);
|
|
783
|
+
}
|
|
784
|
+
} else if (type === 'object') {
|
|
785
|
+
if (value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION) {
|
|
786
|
+
throw new BSONVersionError();
|
|
787
|
+
} else if (value._bsontype === 'ObjectId') {
|
|
788
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
789
|
+
} else if (value._bsontype === 'Decimal128') {
|
|
790
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
791
|
+
} else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
792
|
+
index = serializeLong(buffer, key, value, index);
|
|
793
|
+
} else if (value._bsontype === 'Double') {
|
|
794
|
+
index = serializeDouble(buffer, key, value, index);
|
|
795
|
+
} else if (value._bsontype === 'Code') {
|
|
796
|
+
index = serializeCode(
|
|
797
|
+
buffer,
|
|
798
|
+
key,
|
|
799
|
+
value,
|
|
800
|
+
index,
|
|
801
|
+
checkKeys,
|
|
802
|
+
depth,
|
|
803
|
+
serializeFunctions,
|
|
804
|
+
ignoreUndefined,
|
|
805
|
+
path
|
|
806
|
+
);
|
|
807
|
+
} else if (value._bsontype === 'Binary') {
|
|
808
|
+
index = serializeBinary(buffer, key, value, index);
|
|
809
|
+
} else if (value._bsontype === 'BSONSymbol') {
|
|
810
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
811
|
+
} else if (value._bsontype === 'DBRef') {
|
|
812
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
813
|
+
} else if (value._bsontype === 'BSONRegExp') {
|
|
814
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
815
|
+
} else if (value._bsontype === 'Int32') {
|
|
816
|
+
index = serializeInt32(buffer, key, value, index);
|
|
817
|
+
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
818
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
819
|
+
} else if (typeof value._bsontype !== 'undefined') {
|
|
820
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
821
|
+
}
|
|
822
|
+
} else if (type === 'function' && serializeFunctions) {
|
|
802
823
|
index = serializeFunction(buffer, key, value, index);
|
|
803
|
-
} else if (value._bsontype === 'Binary') {
|
|
804
|
-
index = serializeBinary(buffer, key, value, index);
|
|
805
|
-
} else if (value._bsontype === 'BSONSymbol') {
|
|
806
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
807
|
-
} else if (value._bsontype === 'DBRef') {
|
|
808
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
809
|
-
} else if (value._bsontype === 'BSONRegExp') {
|
|
810
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
811
|
-
} else if (value._bsontype === 'Int32') {
|
|
812
|
-
index = serializeInt32(buffer, key, value, index);
|
|
813
|
-
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
814
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
815
|
-
} else if (typeof value._bsontype !== 'undefined') {
|
|
816
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
817
824
|
}
|
|
818
825
|
}
|
|
819
826
|
} else {
|
|
@@ -853,7 +860,11 @@ export function serializeInto(
|
|
|
853
860
|
}
|
|
854
861
|
}
|
|
855
862
|
|
|
856
|
-
if (
|
|
863
|
+
if (value === undefined) {
|
|
864
|
+
if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index);
|
|
865
|
+
} else if (value === null) {
|
|
866
|
+
index = serializeNull(buffer, key, value, index);
|
|
867
|
+
} else if (type === 'string') {
|
|
857
868
|
index = serializeString(buffer, key, value, index);
|
|
858
869
|
} else if (type === 'number') {
|
|
859
870
|
index = serializeNumber(buffer, key, value, index);
|
|
@@ -861,69 +872,66 @@ export function serializeInto(
|
|
|
861
872
|
index = serializeBigInt(buffer, key, value, index);
|
|
862
873
|
} else if (type === 'boolean') {
|
|
863
874
|
index = serializeBoolean(buffer, key, value, index);
|
|
864
|
-
} else if (value instanceof Date || isDate(value)) {
|
|
865
|
-
index = serializeDate(buffer, key, value, index);
|
|
866
|
-
} else if (value === undefined) {
|
|
867
|
-
if (ignoreUndefined === false) index = serializeNull(buffer, key, value, index);
|
|
868
|
-
} else if (value === null) {
|
|
869
|
-
index = serializeNull(buffer, key, value, index);
|
|
870
|
-
} else if (isUint8Array(value)) {
|
|
871
|
-
index = serializeBuffer(buffer, key, value, index);
|
|
872
|
-
} else if (value instanceof RegExp || isRegExp(value)) {
|
|
873
|
-
index = serializeRegExp(buffer, key, value, index);
|
|
874
875
|
} else if (type === 'object' && value._bsontype == null) {
|
|
875
|
-
|
|
876
|
-
buffer,
|
|
877
|
-
|
|
878
|
-
value,
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
key,
|
|
903
|
-
|
|
904
|
-
index,
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
876
|
+
if (value instanceof Date || isDate(value)) {
|
|
877
|
+
index = serializeDate(buffer, key, value, index);
|
|
878
|
+
} else if (value instanceof Uint8Array || isUint8Array(value)) {
|
|
879
|
+
index = serializeBuffer(buffer, key, value, index);
|
|
880
|
+
} else if (value instanceof RegExp || isRegExp(value)) {
|
|
881
|
+
index = serializeRegExp(buffer, key, value, index);
|
|
882
|
+
} else {
|
|
883
|
+
index = serializeObject(
|
|
884
|
+
buffer,
|
|
885
|
+
key,
|
|
886
|
+
value,
|
|
887
|
+
index,
|
|
888
|
+
checkKeys,
|
|
889
|
+
depth,
|
|
890
|
+
serializeFunctions,
|
|
891
|
+
ignoreUndefined,
|
|
892
|
+
path
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
} else if (type === 'object') {
|
|
896
|
+
if (value[constants.BSON_VERSION_SYMBOL] !== constants.BSON_MAJOR_VERSION) {
|
|
897
|
+
throw new BSONVersionError();
|
|
898
|
+
} else if (value._bsontype === 'ObjectId') {
|
|
899
|
+
index = serializeObjectId(buffer, key, value, index);
|
|
900
|
+
} else if (value._bsontype === 'Decimal128') {
|
|
901
|
+
index = serializeDecimal128(buffer, key, value, index);
|
|
902
|
+
} else if (value._bsontype === 'Long' || value._bsontype === 'Timestamp') {
|
|
903
|
+
index = serializeLong(buffer, key, value, index);
|
|
904
|
+
} else if (value._bsontype === 'Double') {
|
|
905
|
+
index = serializeDouble(buffer, key, value, index);
|
|
906
|
+
} else if (value._bsontype === 'Code') {
|
|
907
|
+
index = serializeCode(
|
|
908
|
+
buffer,
|
|
909
|
+
key,
|
|
910
|
+
value,
|
|
911
|
+
index,
|
|
912
|
+
checkKeys,
|
|
913
|
+
depth,
|
|
914
|
+
serializeFunctions,
|
|
915
|
+
ignoreUndefined,
|
|
916
|
+
path
|
|
917
|
+
);
|
|
918
|
+
} else if (value._bsontype === 'Binary') {
|
|
919
|
+
index = serializeBinary(buffer, key, value, index);
|
|
920
|
+
} else if (value._bsontype === 'BSONSymbol') {
|
|
921
|
+
index = serializeSymbol(buffer, key, value, index);
|
|
922
|
+
} else if (value._bsontype === 'DBRef') {
|
|
923
|
+
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
924
|
+
} else if (value._bsontype === 'BSONRegExp') {
|
|
925
|
+
index = serializeBSONRegExp(buffer, key, value, index);
|
|
926
|
+
} else if (value._bsontype === 'Int32') {
|
|
927
|
+
index = serializeInt32(buffer, key, value, index);
|
|
928
|
+
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
929
|
+
index = serializeMinMax(buffer, key, value, index);
|
|
930
|
+
} else if (typeof value._bsontype !== 'undefined') {
|
|
931
|
+
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
932
|
+
}
|
|
933
|
+
} else if (type === 'function' && serializeFunctions) {
|
|
912
934
|
index = serializeFunction(buffer, key, value, index);
|
|
913
|
-
} else if (value._bsontype === 'Binary') {
|
|
914
|
-
index = serializeBinary(buffer, key, value, index);
|
|
915
|
-
} else if (value._bsontype === 'BSONSymbol') {
|
|
916
|
-
index = serializeSymbol(buffer, key, value, index);
|
|
917
|
-
} else if (value._bsontype === 'DBRef') {
|
|
918
|
-
index = serializeDBRef(buffer, key, value, index, depth, serializeFunctions, path);
|
|
919
|
-
} else if (value._bsontype === 'BSONRegExp') {
|
|
920
|
-
index = serializeBSONRegExp(buffer, key, value, index);
|
|
921
|
-
} else if (value._bsontype === 'Int32') {
|
|
922
|
-
index = serializeInt32(buffer, key, value, index);
|
|
923
|
-
} else if (value._bsontype === 'MinKey' || value._bsontype === 'MaxKey') {
|
|
924
|
-
index = serializeMinMax(buffer, key, value, index);
|
|
925
|
-
} else if (typeof value._bsontype !== 'undefined') {
|
|
926
|
-
throw new BSONError(`Unrecognized or invalid _bsontype: ${String(value._bsontype)}`);
|
|
927
935
|
}
|
|
928
936
|
}
|
|
929
937
|
}
|