Skip to content

Commit 99bd9ed

Browse files
fix(NODE-6420): support options for aggregationcursor/findcursor.explain() (#52)
1 parent 2702b72 commit 99bd9ed

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

.eslintrc.json

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@
99
"node": true,
1010
"es6": true
1111
},
12-
"plugins": ["prettier", "@typescript-eslint"],
13-
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
12+
"plugins": [
13+
"prettier",
14+
"@typescript-eslint"
15+
],
16+
"extends": [
17+
"eslint:recommended",
18+
"plugin:prettier/recommended"
19+
],
1420
"rules": {
1521
"strict": "error",
1622
"prettier/prettier": "error",
@@ -24,6 +30,9 @@
2430
}
2531
],
2632
"no-implicit-coercion": "error",
27-
"@typescript-eslint/strict-boolean-expressions": "error"
33+
"@typescript-eslint/strict-boolean-expressions": "error",
34+
"no-unused-vars": ["error", {
35+
"argsIgnorePattern": "^_"
36+
}]
2837
}
29-
}
38+
}

src/legacy_wrappers/cursors.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@ module.exports.makeLegacyFindCursor = function (baseClass) {
2525
return maybeCallback(super.count(options), callback);
2626
}
2727

28-
explain(verbosity, callback) {
28+
explain(verbosity, options, callback) {
2929
callback =
3030
typeof callback === 'function'
3131
? callback
32-
: typeof verbosity === 'function'
33-
? verbosity
34-
: undefined;
32+
: typeof options === 'function'
33+
? options
34+
: typeof verbosity === 'function'
35+
? verbosity
36+
: undefined;
37+
options = typeof options !== 'function' ? options : undefined;
3538
verbosity = typeof verbosity !== 'function' ? verbosity : undefined;
36-
return maybeCallback(super.explain(verbosity), callback);
39+
return maybeCallback(super.explain(verbosity, options), callback);
3740
}
3841

3942
close(options, callback) {
@@ -180,15 +183,18 @@ module.exports.makeLegacyAggregationCursor = function (baseClass) {
180183
}
181184

182185
class LegacyAggregationCursor extends baseClass {
183-
explain(verbosity, callback) {
186+
explain(verbosity, options, callback) {
184187
callback =
185188
typeof callback === 'function'
186189
? callback
187-
: typeof verbosity === 'function'
188-
? verbosity
189-
: undefined;
190+
: typeof options === 'function'
191+
? options
192+
: typeof verbosity === 'function'
193+
? verbosity
194+
: undefined;
195+
options = typeof options !== 'function' ? options : undefined;
190196
verbosity = typeof verbosity !== 'function' ? verbosity : undefined;
191-
return maybeCallback(super.explain(verbosity), callback);
197+
return maybeCallback(super.explain(verbosity, options), callback);
192198
}
193199

194200
close(options, callback) {

test/tools/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const api = [
3838
{ className: 'Admin', method: 'serverStatus', returnType: 'Promise<Document>' },
3939
{ className: 'Admin', method: 'validateCollection', returnType: 'Promise<Document>' },
4040

41-
{ className: 'AggregationCursor', method: 'explain', returnType: 'Promise<Document>' },
41+
{ className: 'AggregationCursor', method: 'explain', returnType: 'Promise<Document>', possibleCallbackPositions: [1, 2, 3] },
4242
{ className: 'AggregationCursor', method: 'clone', returnType: 'AggregationCursor', notAsync: true },
4343

4444
{ className: 'FindCursor', method: 'clone', returnType: 'FindCursor', notAsync: true },
@@ -115,7 +115,7 @@ const api = [
115115
{ className: 'Db', method: 'watch', returnType: 'ChangeStream', notAsync: true },
116116

117117
{ className: 'FindCursor', method: 'count', returnType: 'Promise<number>' },
118-
{ className: 'FindCursor', method: 'explain', returnType: 'Promise<Document>' },
118+
{ className: 'FindCursor', method: 'explain', returnType: 'Promise<Document>', possibleCallbackPositions: [1,2,3] },
119119

120120
{ className: 'GridFSBucket', method: 'delete', returnType: 'Promise<void>', possibleCallbackPositions: [1, 2] },
121121
{ className: 'GridFSBucket', method: 'drop', returnType: 'Promise<void>', possibleCallbackPositions: [1, 2] },

0 commit comments

Comments
 (0)