Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-3344): allow setting defaultTransactionOptions with POJO rather than ReadConcern instance #3032

Merged
merged 4 commits into from Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 } }));