Skip to content

Commit 8394223

Browse files
committed
fix(NODE-6328): pass through optional options in txn APIs
1 parent a54d25e commit 8394223

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/legacy_wrappers/session.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,28 @@ Object.defineProperty(module.exports, '__esModule', { value: true });
77

88
module.exports.makeLegacyClientSession = function (baseClass) {
99
class LegacyClientSession extends baseClass {
10-
abortTransaction(callback) {
11-
return maybeCallback(super.abortTransaction(), callback);
10+
abortTransaction(options, callback) {
11+
callback =
12+
typeof callback === 'function'
13+
? callback
14+
: typeof options === 'function'
15+
? options
16+
: undefined;
17+
options = typeof options !== 'function' ? options : undefined;
18+
19+
return maybeCallback(super.abortTransaction(options), callback);
1220
}
1321

14-
commitTransaction(callback) {
15-
return maybeCallback(super.commitTransaction(), callback);
22+
commitTransaction(options, callback) {
23+
callback =
24+
typeof callback === 'function'
25+
? callback
26+
: typeof options === 'function'
27+
? options
28+
: undefined;
29+
options = typeof options !== 'function' ? options : undefined;
30+
31+
return maybeCallback(super.commitTransaction(options), callback);
1632
}
1733

1834
endSession(options, callback) {

test/tools/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ const api = [
5757
{ className: 'ChangeStream', method: 'next', returnType: 'Promise<TChange>' },
5858
{ className: 'ChangeStream', method: 'tryNext', returnType: 'Promise<Document | null>' },
5959

60-
{ className: 'ClientSession', method: 'abortTransaction', returnType: 'Promise<Document>' },
61-
{ className: 'ClientSession', method: 'commitTransaction', returnType: 'Promise<Document>' },
60+
{ className: 'ClientSession', method: 'abortTransaction', returnType: 'Promise<Document>', possibleCallbackPositions: [1, 2] },
61+
{ className: 'ClientSession', method: 'commitTransaction', returnType: 'Promise<Document>', possibleCallbackPositions: [1, 2] },
6262
{ className: 'ClientSession', method: 'endSession', returnType: 'Promise<void>' },
6363
{ className: 'ClientSession', method: 'withTransaction', returnType: 'Promise<void>', notAsync: true },
6464

0 commit comments

Comments
 (0)