Skip to content

Commit 169ad84

Browse files
author
Grace Chong
committed
refactor: refactor to keep change internal by removing option from BSONSerializeOptions and options registry
1 parent 77c83f6 commit 169ad84

File tree

5 files changed

+17
-20
lines changed

5 files changed

+17
-20
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bson.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ export interface BSONSerializeOptions
5151
| 'cacheFunctionsCrc32'
5252
| 'allowObjectSmallerThanBufferSize'
5353
| 'index'
54+
| 'validation'
5455
> {
5556
/** Return BSON filled buffers from operations */
5657
raw?: boolean;
57-
validation?: { utf8: boolean | Record<string, true> | Record<string, false> };
5858
}
5959

6060
export function pluckBSONSerializeOptions(options: BSONSerializeOptions): BSONSerializeOptions {

src/cmap/commands.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,17 @@ export class BinMsg {
850850
promoteLongs,
851851
promoteValues,
852852
promoteBuffers,
853-
bsonRegExp,
854-
validation
853+
bsonRegExp
855854
};
856855

857856
while (this.index < this.data.length) {
858857
const payloadType = this.data.readUInt8(this.index++);
859858
if (payloadType === 0) {
860859
const bsonSize = this.data.readUInt32LE(this.index);
861860
const bin = this.data.slice(this.index, this.index + bsonSize);
862-
this.documents.push(raw ? bin : BSON.deserialize(bin, _options));
863-
861+
this.documents.push(
862+
raw ? bin : BSON.deserialize(bin, Object.assign({ validation }, _options))
863+
);
864864
this.index += bsonSize;
865865
} else if (payloadType === 1) {
866866
// It was decided that no driver makes use of payload type 1
@@ -874,8 +874,10 @@ export class BinMsg {
874874
const fieldsAsRaw: Document = {};
875875
fieldsAsRaw[documentsReturnedIn] = true;
876876
_options.fieldsAsRaw = fieldsAsRaw;
877-
878-
const doc = BSON.deserialize(this.documents[0] as Buffer, _options);
877+
const doc = BSON.deserialize(
878+
this.documents[0] as Buffer,
879+
Object.assign({ validation }, _options)
880+
);
879881
this.documents = [doc];
880882
}
881883

src/connection_string.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,10 +864,6 @@ export const OPTIONS = {
864864
default: false,
865865
type: 'boolean'
866866
},
867-
validation: {
868-
default: { utf8: { writeErrors: false } },
869-
type: 'record'
870-
},
871867
readConcern: {
872868
transform({ values: [value], options }) {
873869
if (value instanceof ReadConcern || isRecord(value, ['level'] as const)) {

test/types/bson.test-d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ type PermittedBSONOptionKeys =
2121
| 'promoteValues'
2222
| 'bsonRegExp'
2323
| 'fieldsAsRaw'
24-
| 'raw'
25-
| 'validation';
24+
| 'raw';
2625

2726
const keys = null as unknown as PermittedBSONOptionKeys;
2827
// creates an explicit allow list assertion

0 commit comments

Comments
 (0)