From 2496267f89bf53d1922cdabcce71bbeee1ea4697 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 28 Aug 2023 11:59:18 -0400 Subject: [PATCH 1/3] fix(NODE-5592): fix withTransaction return type --- src/sessions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sessions.ts b/src/sessions.ts index 1f8df23490a..b6f451b606a 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -453,7 +453,7 @@ export class ClientSession extends TypedEventEmitter { async withTransaction( fn: WithTransactionCallback, options?: TransactionOptions - ): Promise { + ): Promise { const startTime = now(); return attemptTransaction(this, startTime, fn, options); } From 5757fb0457aa428ee88d2839219b2a6b674c7725 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 28 Aug 2023 12:00:00 -0400 Subject: [PATCH 2/3] test(NODE-5592): fix test to properly check withTransaction return type --- test/types/community/transaction.test-d.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/types/community/transaction.test-d.ts b/test/types/community/transaction.test-d.ts index 50cd9133b3a..949d5a17f6f 100644 --- a/test/types/community/transaction.test-d.ts +++ b/test/types/community/transaction.test-d.ts @@ -1,4 +1,6 @@ -import { type ClientSession, MongoClient, ReadConcern } from '../../mongodb'; +import { expectType } from 'tsd'; + +import { type ClientSession, type InsertOneResult, MongoClient, ReadConcern } from '../../mongodb'; // TODO(NODE-3345): Improve these tests to use expect assertions more @@ -111,11 +113,7 @@ try { client.withSession(session => runTransactionWithRetry(updateEmployeeInfo, client, session)); const col = client.db('test').collection<{ _id: string }>('col'); -const ok = await session.withTransaction(async () => { +const insertResult = await session.withTransaction(async () => { return await col.insertOne({ _id: 'one' }, { session }); }); -if (ok) { - console.log('success'); -} else { - console.log('nothing done'); -} +expectType>(insertResult); From 50cf5535a1ccf3cf320846ad592e628ecb6085b5 Mon Sep 17 00:00:00 2001 From: Warren James Date: Mon, 28 Aug 2023 12:07:03 -0400 Subject: [PATCH 3/3] fix(NODE-5592): remove optionally undefined type --- src/sessions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sessions.ts b/src/sessions.ts index b6f451b606a..b4b59f232c5 100644 --- a/src/sessions.ts +++ b/src/sessions.ts @@ -453,7 +453,7 @@ export class ClientSession extends TypedEventEmitter { async withTransaction( fn: WithTransactionCallback, options?: TransactionOptions - ): Promise { + ): Promise { const startTime = now(); return attemptTransaction(this, startTime, fn, options); }