diff --git a/src/transactions.ts b/src/transactions.ts index 1b73ae3683..29797ace72 100644 --- a/src/transactions.ts +++ b/src/transactions.ts @@ -1,6 +1,6 @@ import { ReadPreference } from './read_preference'; import { MongoRuntimeError, MongoTransactionError } from './error'; -import { ReadConcern } from './read_concern'; +import { ReadConcern, ReadConcernLike } from './read_concern'; import { WriteConcern } from './write_concern'; import type { Server } from './sdam/server'; import type { CommandOperationOptions } from './operations/command'; @@ -63,7 +63,7 @@ const COMMITTED_STATES: Set = new Set([ export interface TransactionOptions extends CommandOperationOptions { // TODO(NODE-3344): These options use the proper class forms of these settings, it should accept the basic enum values too /** A default read concern for commands in this transaction */ - readConcern?: ReadConcern; + readConcern?: ReadConcernLike; /** A default writeConcern for commands in this transaction */ writeConcern?: WriteConcern; /** A default read preference for commands in this transaction */ diff --git a/test/types/sessions.test-d.ts b/test/types/sessions.test-d.ts new file mode 100644 index 0000000000..dc2df9dd58 --- /dev/null +++ b/test/types/sessions.test-d.ts @@ -0,0 +1,17 @@ +import { expectType, expectError } from 'tsd'; +import { MongoClient } from '../../src/mongo_client'; +import { ReadConcern, ReadConcernLevel } from '../../src/read_concern'; +import type { ClientSession } from '../../src/sessions'; + +// test mapped cursor types +const client = new MongoClient(''); +// should allow ReadConcern or ReadConcernLike as readConcern in defaultTransactionOptions +expectType( + client.startSession({ defaultTransactionOptions: { readConcern: { level: 'snapshot' } } }) +); +expectType( + client.startSession({ + defaultTransactionOptions: { readConcern: new ReadConcern(ReadConcernLevel.local) } + }) +); +expectError(client.startSession({ defaultTransactionOptions: { readConcern: 1 } }));