Skip to content

Commit aa0e3a9

Browse files
committed
fix: utf
1 parent dd8f86d commit aa0e3a9

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

src/cmap/commands.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export type WriteProtocolMessageType = OpQueryRequest | OpMsgRequest;
3737
export interface OpQueryOptions extends CommandOptions {
3838
socketTimeoutMS?: number;
3939
session?: ClientSession;
40-
documentsReturnedIn?: string;
4140
numberToSkip?: number;
4241
numberToReturn?: number;
4342
returnFieldSelector?: Document;
@@ -280,17 +279,12 @@ export interface MessageHeader {
280279
fromCompressed?: boolean;
281280
}
282281

283-
/** @internal */
284-
export interface OpResponseOptions extends BSONSerializeOptions {
285-
documentsReturnedIn?: string | null;
286-
}
287-
288282
/** @internal */
289283
export class OpReply {
290284
parsed: boolean;
291285
raw: Buffer;
292286
data: Buffer;
293-
opts: OpResponseOptions;
287+
opts: BSONSerializeOptions;
294288
length: number;
295289
requestId: number;
296290
responseTo: number;
@@ -319,7 +313,7 @@ export class OpReply {
319313
message: Buffer,
320314
msgHeader: MessageHeader,
321315
msgBody: Buffer,
322-
opts?: OpResponseOptions
316+
opts?: BSONSerializeOptions
323317
) {
324318
this.parsed = false;
325319
this.raw = message;
@@ -526,7 +520,7 @@ export class OpMsgResponse {
526520
parsed: boolean;
527521
raw: Buffer;
528522
data: Buffer;
529-
opts: OpResponseOptions;
523+
opts: BSONSerializeOptions;
530524
length: number;
531525
requestId: number;
532526
responseTo: number;
@@ -549,7 +543,7 @@ export class OpMsgResponse {
549543
message: Buffer,
550544
msgHeader: MessageHeader,
551545
msgBody: Buffer,
552-
opts?: OpResponseOptions
546+
opts?: BSONSerializeOptions
553547
) {
554548
this.parsed = false;
555549
this.raw = message;

src/cmap/wire_protocol/responses.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,20 @@ export class MongoDBResponse extends OnDemandDocument {
8181

8282
/** TODO improve the special case of enableUtf8Validation for writeErrors */
8383
public override toObject(options: BSONSerializeOptions = {}): Record<string, any> {
84-
function parseBsonSerializationOptions({ enableUtf8Validation }: BSONSerializeOptions): {
85-
utf8: { writeErrors: false } | false;
86-
} {
87-
if (enableUtf8Validation === false) {
88-
return { utf8: false };
89-
}
90-
91-
return { utf8: { writeErrors: false } };
92-
}
9384
const optionsWithValidation = {
9485
...options,
95-
validation: parseBsonSerializationOptions(options)
86+
validation: this.parseBsonSerializationOptions(options)
9687
};
9788
return super.toObject(optionsWithValidation);
9889
}
90+
91+
private parseBsonSerializationOptions({ enableUtf8Validation }: BSONSerializeOptions): {
92+
utf8: { writeErrors: false } | false;
93+
} {
94+
if (enableUtf8Validation === false) {
95+
return { utf8: false };
96+
}
97+
98+
return { utf8: { writeErrors: false } };
99+
}
99100
}

test/integration/node-specific/bson-options/raw.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
ObjectId
88
} from '../../../mongodb';
99

10-
describe.skip('raw bson support', () => {
10+
describe.only('raw bson support', () => {
1111
// TODO: Fix raw option
1212
describe('raw', () => {
1313
describe('option inheritance', () => {

test/integration/node-specific/bson-options/utf8_validation.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import * as sinon from 'sinon';
33

4-
import { OpMsgResponse } from '../../../mongodb';
4+
import { MongoDBResponse } from '../../../mongodb';
55

66
const EXPECTED_VALIDATION_DISABLED_ARGUMENT = {
77
utf8: false
@@ -13,11 +13,11 @@ const EXPECTED_VALIDATION_ENABLED_ARGUMENT = {
1313
}
1414
};
1515

16-
describe('class OpMsgResponse', () => {
16+
describe('class MongoDBResponse', () => {
1717
let bsonSpy: sinon.SinonSpy;
1818

1919
beforeEach(() => {
20-
bsonSpy = sinon.spy(OpMsgResponse.prototype, 'parseBsonSerializationOptions');
20+
bsonSpy = sinon.spy(MongoDBResponse.prototype, 'parseBsonSerializationOptions');
2121
});
2222

2323
afterEach(() => {

0 commit comments

Comments
 (0)