Skip to content

Commit

Permalink
fix(NODE-3344): allow setting defaultTransactionOptions with POJO r…
Browse files Browse the repository at this point in the history
…ather than ReadConcern instance (#3032)

Co-authored-by: Valeri Karpov <val@karpov.io>
  • Loading branch information
durran and vkarpov15 committed Nov 10, 2021
1 parent 526beb7 commit 53b3164
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions 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';
Expand Down Expand Up @@ -63,7 +63,7 @@ const COMMITTED_STATES: Set<TxnState> = 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 */
Expand Down
17 changes: 17 additions & 0 deletions 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<ClientSession>(
client.startSession({ defaultTransactionOptions: { readConcern: { level: 'snapshot' } } })
);
expectType<ClientSession>(
client.startSession({
defaultTransactionOptions: { readConcern: new ReadConcern(ReadConcernLevel.local) }
})
);
expectError(client.startSession({ defaultTransactionOptions: { readConcern: 1 } }));

0 comments on commit 53b3164

Please sign in to comment.