Skip to content

Commit 077fadf

Browse files
committed
chore: some comments
1 parent c35643f commit 077fadf

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

src/cmap/connection.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
416416
private async *sendWire(
417417
message: WriteProtocolMessageType,
418418
options: CommandOptions,
419-
returnAs?: typeof MongoDBResponse
419+
responseType?: typeof MongoDBResponse
420420
): AsyncGenerator<MongoDBResponse> {
421421
this.throwIfAborted();
422422

@@ -443,7 +443,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
443443
this.socket.setTimeout(0);
444444
const bson = response.parse();
445445

446-
const document = new (returnAs ?? MongoDBResponse)(bson, 0, false);
446+
const document = new (responseType ?? MongoDBResponse)(bson, 0, false);
447447

448448
yield document;
449449
this.throwIfAborted();
@@ -463,7 +463,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
463463
ns: MongoDBNamespace,
464464
command: Document,
465465
options: CommandOptions = {},
466-
returnAs?: typeof MongoDBResponse
466+
responseType?: typeof MongoDBResponse
467467
) {
468468
const message = this.prepareCommand(ns.db, command, options);
469469

@@ -482,7 +482,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
482482
let document;
483483
try {
484484
this.throwIfAborted();
485-
for await (document of this.sendWire(message, options, returnAs)) {
485+
for await (document of this.sendWire(message, options, responseType)) {
486486
if (options.session != null) {
487487
updateSessionFromResponse(options.session, document);
488488
}
@@ -520,7 +520,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
520520
);
521521
}
522522

523-
if (returnAs == null) {
523+
if (responseType == null) {
524524
// If `documentsReturnedIn` not set or raw is not enabled, use input bson options
525525
// Otherwise, support raw flag. Raw only works for cursors that hardcode firstBatch/nextBatch fields
526526
const bsonOptions =
@@ -578,7 +578,7 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
578578
ns: MongoDBNamespace,
579579
command: Document,
580580
options: CommandOptions | undefined,
581-
returnAs: T | undefined
581+
responseType: T | undefined
582582
): Promise<T extends undefined ? Document : InstanceType<T>>;
583583

584584
public async command(
@@ -599,10 +599,10 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
599599
ns: MongoDBNamespace,
600600
command: Document,
601601
options: CommandOptions = {},
602-
returnAs?: typeof MongoDBResponse
602+
responseType?: typeof MongoDBResponse
603603
): Promise<Document> {
604604
this.throwIfAborted();
605-
for await (const document of this.sendCommand(ns, command, options, returnAs)) {
605+
for await (const document of this.sendCommand(ns, command, options, responseType)) {
606606
return document;
607607
}
608608
throw new MongoUnexpectedServerResponseError('Unable to get response from server');
@@ -732,7 +732,7 @@ export class CryptoConnection extends Connection {
732732
ns: MongoDBNamespace,
733733
command: Document,
734734
options: CommandOptions | undefined,
735-
returnAs: T
735+
responseType: T
736736
): Promise<InstanceType<T>>;
737737

738738
public override async command(
@@ -747,7 +747,7 @@ export class CryptoConnection extends Connection {
747747
ns: MongoDBNamespace,
748748
cmd: Document,
749749
options?: CommandOptions,
750-
returnAs?: T | undefined
750+
responseType?: T | undefined
751751
): Promise<Document> {
752752
const { autoEncrypter } = this;
753753
if (!autoEncrypter) {
@@ -757,7 +757,7 @@ export class CryptoConnection extends Connection {
757757
const serverWireVersion = maxWireVersion(this);
758758
if (serverWireVersion === 0) {
759759
// This means the initial handshake hasn't happened yet
760-
return await super.command<T>(ns, cmd, options, returnAs);
760+
return await super.command<T>(ns, cmd, options, responseType);
761761
}
762762

763763
if (serverWireVersion < 8) {
@@ -791,7 +791,7 @@ export class CryptoConnection extends Connection {
791791
}
792792
}
793793

794-
const response = await super.command<T>(ns, encrypted, options, returnAs);
794+
const response = await super.command<T>(ns, encrypted, options, responseType);
795795

796796
return await autoEncrypter.decrypt(response, options);
797797
}

src/cmap/wire_protocol/responses.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ export class MongoDBResponse extends OnDemandDocument {
3838
public get atClusterTime(): Timestamp | null {
3939
return (
4040
this.get('cursor', BSONType.object)?.get('atClusterTime', BSONType.timestamp) ??
41-
this.get('atClusterTime', BSONType.timestamp) ??
42-
null
41+
this.get('atClusterTime', BSONType.timestamp)
4342
);
4443
}
4544

test/unit/cmap/wire_protocol/responses.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@ describe('class MongoDBResponse', () => {
1414
expect(doc.isError).to.be.true;
1515
});
1616

17+
it('returns true when $err is defined', () => {
18+
const doc = new MongoDBResponse(BSON.serialize({ $err: 0 }));
19+
expect(doc.isError).to.be.true;
20+
});
21+
22+
it('returns true when errmsg is defined', () => {
23+
const doc = new MongoDBResponse(BSON.serialize({ errmsg: 0 }));
24+
expect(doc.isError).to.be.true;
25+
});
26+
27+
it('returns true when code is defined', () => {
28+
const doc = new MongoDBResponse(BSON.serialize({ code: 0 }));
29+
expect(doc.isError).to.be.true;
30+
});
31+
1732
it('short circuits detection of $err, errmsg, code', () => {
1833
const doc = new MongoDBResponse(BSON.serialize({ ok: 0 }));
1934
expect(doc.isError).to.be.true;

0 commit comments

Comments
 (0)