Skip to content

Commit 53b3164

Browse files
durranvkarpov15
andauthored
fix(NODE-3344): allow setting defaultTransactionOptions with POJO rather than ReadConcern instance (#3032)
Co-authored-by: Valeri Karpov <[email protected]>
1 parent 526beb7 commit 53b3164

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/transactions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReadPreference } from './read_preference';
22
import { MongoRuntimeError, MongoTransactionError } from './error';
3-
import { ReadConcern } from './read_concern';
3+
import { ReadConcern, ReadConcernLike } from './read_concern';
44
import { WriteConcern } from './write_concern';
55
import type { Server } from './sdam/server';
66
import type { CommandOperationOptions } from './operations/command';
@@ -63,7 +63,7 @@ const COMMITTED_STATES: Set<TxnState> = new Set([
6363
export interface TransactionOptions extends CommandOperationOptions {
6464
// TODO(NODE-3344): These options use the proper class forms of these settings, it should accept the basic enum values too
6565
/** A default read concern for commands in this transaction */
66-
readConcern?: ReadConcern;
66+
readConcern?: ReadConcernLike;
6767
/** A default writeConcern for commands in this transaction */
6868
writeConcern?: WriteConcern;
6969
/** A default read preference for commands in this transaction */

test/types/sessions.test-d.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expectType, expectError } from 'tsd';
2+
import { MongoClient } from '../../src/mongo_client';
3+
import { ReadConcern, ReadConcernLevel } from '../../src/read_concern';
4+
import type { ClientSession } from '../../src/sessions';
5+
6+
// test mapped cursor types
7+
const client = new MongoClient('');
8+
// should allow ReadConcern or ReadConcernLike as readConcern in defaultTransactionOptions
9+
expectType<ClientSession>(
10+
client.startSession({ defaultTransactionOptions: { readConcern: { level: 'snapshot' } } })
11+
);
12+
expectType<ClientSession>(
13+
client.startSession({
14+
defaultTransactionOptions: { readConcern: new ReadConcern(ReadConcernLevel.local) }
15+
})
16+
);
17+
expectError(client.startSession({ defaultTransactionOptions: { readConcern: 1 } }));

0 commit comments

Comments
 (0)