Skip to content

Commit 0125330

Browse files
committed
feat(NODE-4877): Add support for useBigInt64
1 parent 9d9babb commit 0125330

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

src/bson.ts

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface BSONSerializeOptions
6666
export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSerializeOptions {
6767
const {
6868
fieldsAsRaw,
69+
useBigInt64,
6970
promoteValues,
7071
promoteBuffers,
7172
promoteLongs,
@@ -77,6 +78,7 @@ export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSe
7778
} = options;
7879
return {
7980
fieldsAsRaw,
81+
useBigInt64,
8082
promoteValues,
8183
promoteBuffers,
8284
promoteLongs,
@@ -101,6 +103,7 @@ export function resolveBSONOptions(
101103
const parentOptions = parent?.bsonOptions;
102104
return {
103105
raw: options?.raw ?? parentOptions?.raw ?? false,
106+
useBigInt64: options?.useBigInt64 ?? parentOptions?.useBigInt64 ?? false,
104107
promoteLongs: options?.promoteLongs ?? parentOptions?.promoteLongs ?? true,
105108
promoteValues: options?.promoteValues ?? parentOptions?.promoteValues ?? true,
106109
promoteBuffers: options?.promoteBuffers ?? parentOptions?.promoteBuffers ?? false,

src/operations/create_collection.ts

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const ILLEGAL_COMMAND_FIELDS = new Set([
2323
'writeConcern',
2424
'raw',
2525
'fieldsAsRaw',
26+
'useBigInt64',
2627
'promoteLongs',
2728
'promoteValues',
2829
'promoteBuffers',

test/types/bson.test-d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const options: BSONSerializeOptions = {};
77
expectType<boolean | undefined>(options.checkKeys);
88
expectType<boolean | undefined>(options.serializeFunctions);
99
expectType<boolean | undefined>(options.ignoreUndefined);
10+
expectType<boolean | undefined>(options.useBigInt64);
1011
expectType<boolean | undefined>(options.promoteLongs);
1112
expectType<boolean | undefined>(options.promoteBuffers);
1213
expectType<boolean | undefined>(options.promoteValues);
@@ -17,6 +18,7 @@ type PermittedBSONOptionKeys =
1718
| 'checkKeys'
1819
| 'serializeFunctions'
1920
| 'ignoreUndefined'
21+
| 'useBigInt64'
2022
| 'promoteLongs'
2123
| 'promoteBuffers'
2224
| 'promoteValues'

test/unit/bson.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,12 @@ describe('When importing BSON', function () {
3939
}
4040

4141
testTypes();
42+
43+
it('does not throw when passed bigints', function () {
44+
expect(() => {
45+
const doc = { a: 100n };
46+
const ser = BSON.serialize(doc);
47+
return BSON.deserialize(ser);
48+
}).to.not.throw;
49+
});
4250
});

0 commit comments

Comments
 (0)