Skip to content

Commit

Permalink
fix(NODE-6420): support options for aggregationcursor/findcursor.expl…
Browse files Browse the repository at this point in the history
…ain() (#52)
  • Loading branch information
baileympearson authored Oct 14, 2024
1 parent 2702b72 commit 99bd9ed
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
17 changes: 13 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
"node": true,
"es6": true
},
"plugins": ["prettier", "@typescript-eslint"],
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": [
"prettier",
"@typescript-eslint"
],
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"rules": {
"strict": "error",
"prettier/prettier": "error",
Expand All @@ -24,6 +30,9 @@
}
],
"no-implicit-coercion": "error",
"@typescript-eslint/strict-boolean-expressions": "error"
"@typescript-eslint/strict-boolean-expressions": "error",
"no-unused-vars": ["error", {
"argsIgnorePattern": "^_"
}]
}
}
}
26 changes: 16 additions & 10 deletions src/legacy_wrappers/cursors.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ module.exports.makeLegacyFindCursor = function (baseClass) {
return maybeCallback(super.count(options), callback);
}

explain(verbosity, callback) {
explain(verbosity, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof verbosity === 'function'
? verbosity
: undefined;
: typeof options === 'function'
? options
: typeof verbosity === 'function'
? verbosity
: undefined;
options = typeof options !== 'function' ? options : undefined;
verbosity = typeof verbosity !== 'function' ? verbosity : undefined;
return maybeCallback(super.explain(verbosity), callback);
return maybeCallback(super.explain(verbosity, options), callback);
}

close(options, callback) {
Expand Down Expand Up @@ -180,15 +183,18 @@ module.exports.makeLegacyAggregationCursor = function (baseClass) {
}

class LegacyAggregationCursor extends baseClass {
explain(verbosity, callback) {
explain(verbosity, options, callback) {
callback =
typeof callback === 'function'
? callback
: typeof verbosity === 'function'
? verbosity
: undefined;
: typeof options === 'function'
? options
: typeof verbosity === 'function'
? verbosity
: undefined;
options = typeof options !== 'function' ? options : undefined;
verbosity = typeof verbosity !== 'function' ? verbosity : undefined;
return maybeCallback(super.explain(verbosity), callback);
return maybeCallback(super.explain(verbosity, options), callback);
}

close(options, callback) {
Expand Down
4 changes: 2 additions & 2 deletions test/tools/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const api = [
{ className: 'Admin', method: 'serverStatus', returnType: 'Promise<Document>' },
{ className: 'Admin', method: 'validateCollection', returnType: 'Promise<Document>' },

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

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

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

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

0 comments on commit 99bd9ed

Please sign in to comment.