Skip to content

fix(mongodb): correct GridFSBucketWriteStream.abort callback#44553

Merged
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
peterblazejewicz:fix/44549
May 18, 2020
Merged

fix(mongodb): correct GridFSBucketWriteStream.abort callback#44553
typescript-bot merged 1 commit intoDefinitelyTyped:masterfrom
peterblazejewicz:fix/44549

Conversation

@peterblazejewicz
Copy link
Member

This fixes callback method definition to match documentation:
https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#~errorCallback

Also this error callback now has the same shape as default
MongoCallback, hence the extend.

/cc @alexy4744

Fixes #44549

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Run npm run lint package-name (or tsc if no tslint.json is present).
  • Provide a URL to documentation or source code which provides context for the suggested changes
  • Include tests for your changes

@typescript-bot
Copy link
Contributor

typescript-bot commented May 7, 2020

@peterblazejewicz Thank you for submitting this PR!

Code Reviews

Because you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • ✅ Most recent commit is approved by type definition owners or DT maintainers

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 44553,
  "author": "peterblazejewicz",
  "owners": [
    "CaselIT",
    "alanmarcell",
    "dante-101",
    "mcortesi",
    "EnricoPicci",
    "AJCStriker",
    "julien-c",
    "daprahamian",
    "denys-bushulyak",
    "BastienAr",
    "sindbach",
    "geraldinelemeur",
    "various89",
    "angela-1",
    "lirbank",
    "hector7",
    "floric",
    "erikc5000",
    "Manc",
    "jloveridge",
    "ranguna",
    "HosseinAgha",
    "albertossilva",
    "peterblazejewicz",
    "LinusU",
    "taxilian",
    "xamgore",
    "avaly",
    "HitkoDev",
    "jtassin"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "b78ef10",
  "headCommitOid": "b78ef10efc42b6c23a2123c6527dec011b57f51d",
  "mergeIsRequested": true,
  "stalenessInDays": 0,
  "lastCommitDate": "2020-05-18T18:36:28.000Z",
  "lastCommentDate": "2020-05-18T18:42:57.000Z",
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/44553/files",
  "hasMergeConflict": false,
  "authorIsOwner": true,
  "isFirstContribution": false,
  "popularityLevel": "Popular",
  "anyPackageIsNew": false,
  "packages": [
    "mongodb"
  ],
  "files": [
    {
      "filePath": "types/mongodb/index.d.ts",
      "kind": "definition",
      "package": "mongodb"
    },
    {
      "filePath": "types/mongodb/test/index.ts",
      "kind": "test",
      "package": "mongodb"
    }
  ],
  "hasDismissedReview": false,
  "travisResult": "pass",
  "lastReviewDate": "2020-05-18T18:41:49.000Z",
  "reviewersWithStaleReviews": [
    {
      "reviewedAbbrOid": "d4d38c2",
      "reviewer": "LinusU",
      "date": "2020-05-13T17:22:56Z"
    }
  ],
  "approvalFlags": 2,
  "isChangesRequested": false
}

@typescript-bot
Copy link
Contributor

typescript-bot commented May 7, 2020

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Author is Owner The author of this PR is a listed owner of the package. labels May 7, 2020
@typescript-bot
Copy link
Contributor

👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings.

Let’s review the numbers, shall we?

Comparison details 📊
master #44553 diff
Batch compilation
Memory usage (MiB) 77.0 74.6 -3.1%
Type count 16920 16927 0%
Assignability cache size 6282 6285 0%
Language service
Samples taken 2181 2196 +1%
Identifiers in tests 2181 2196 +1%
getCompletionsAtPosition
    Mean duration (ms) 347.2 337.0 -2.9%
    Mean CV 8.6% 9.2%
    Worst duration (ms) 454.1 454.9 +0.2%
    Worst identifier toArray _id
getQuickInfoAtPosition
    Mean duration (ms) 348.8 338.4 -3.0%
    Mean CV 9.0% 9.3% +3.2%
    Worst duration (ms) 462.4 441.6 -4.5%
    Worst identifier toArray name

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added the Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. label May 7, 2020
@sandersn
Copy link
Contributor

This looks like an improvement to me, but I don't like merging changes to such a widely used package without some authors signing off.

@CaselIT @alanmarcell @Dante-101 @mcortesi @EnricoPicci @AJCStriker @julien-c @daprahamian @Denys-Bushulyak @bastienar @sindbach @geraldinelemeur @various89 @angela-1 @lirbank @hector7 @floric @erikc5000 @Manc @jloveridge @Ranguna @HosseinAgha @albertossilva @LinusU @taxilian @xamgore @avaly @HitkoDev
Can you take a look?

@xamgore
Copy link
Contributor

xamgore commented May 13, 2020

I believe you should bump the package version, as it looks like a minor breaking change.

Copy link
Contributor

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok.

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner labels May 13, 2020
@CaselIT
Copy link
Contributor

CaselIT commented May 13, 2020

I believe you should bump the package version, as it looks like a minor breaking change.

From the added test it seems to not break the older callback

@HitkoDev
Copy link
Contributor

HitkoDev commented May 13, 2020

It seems most functions should only accept GridFSBucketErrorCallback<void>, as only GridFSBucketWriteStream~end and GridFSBucketWriteStream~write actually provide the second argument. This pattern is already used with MongoCallback<T> across the typings.

https://mongodb.github.io/node-mongodb-native/3.6/api/lib_gridfs-stream_upload.js.html#line112

(err?: MongoError): void;
/** http://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#~errorCallback */
export interface GridFSBucketErrorCallback<T = any> extends MongoCallback<T> {
(error: MongoError, result: T): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you removed ? I think that you should make this | undefined. The same goes for T since it won't be available when error is.

Suggested change
(error: MongoError, result: T): void;
(error: MongoError | undefined, result: T | undefined): void;

Maybe even, if it works:

Suggested change
(error: MongoError, result: T): void;
(error: undefined, result: T): void;
(error: MongoError, result: undefined): void;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since this is only used in one place (right?), I think it would be better to just:

Suggested change
(error: MongoError, result: T): void;
(error?: MongoError | null): void;

also here, I think that null is actually the value received, not undefined. I might be wrong though

@LinusU
Copy link
Contributor

LinusU commented May 13, 2020

Sorry for the late review, added som comments now.

Basically I think that the best approach would be:

export interface GridFSBucketErrorCallback extends MongoCallback<void> {}

together with a modification of MongoCallback to indicate the proper nullability:

export interface MongoCallback<T> {
    (error: MongoError | null, result?: T | null): void;
}

@peterblazejewicz
Copy link
Member Author

Let me see, be back with feedback/changes

Sorry for the late review, added som comments now.

absolutely not a problem nowadays

@peterblazejewicz
Copy link
Member Author

@LinusU

export interface MongoCallback<T> {
    (error: MongoError | null, result?: T | null): void;
}

It seems it would be impacting a lot of existing code, e.g.:

(err: mongodb.MongoError, client: mongodb.MongoClient) => {

This patch passses all tests (inluding referenced libs)

diff --git a/types/mongodb/index.d.ts b/types/mongodb/index.d.ts
index 1ca7230faa..b609a248a5 100644
--- a/types/mongodb/index.d.ts
+++ b/types/mongodb/index.d.ts
@@ -2439,10 +2439,8 @@ export interface GridFSBucketOptions {
     readPreference?: ReadPreferenceOrMode;
 }
 
-/** http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#~errorCallback */
-export interface GridFSBucketErrorCallback {
-    (err?: MongoError): void;
-}
+/** http://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#~errorCallback */
+export interface GridFSBucketErrorCallback extends MongoCallback<void> {}
 
 /** http://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucket.html#find */
 export interface GridFSBucketFindOptions {
@@ -2487,7 +2485,7 @@ export class GridFSBucketWriteStream extends Writable {
      * @param [callback] called when chunks are successfully removed or error occurred
      * @see {@link https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucketWriteStream.html#abort}
      */
-    abort(callback?: () => void): void;
+    abort(callback?: GridFSBucketErrorCallback): void;
 }
 
 /** https://mongodb.github.io/node-mongodb-native/3.1/api/GridFSBucketWriteStream.html */
diff --git a/types/mongodb/test/index.ts b/types/mongodb/test/index.ts
index a8b0645d31..93576621d0 100644
--- a/types/mongodb/test/index.ts
+++ b/types/mongodb/test/index.ts
@@ -89,10 +89,14 @@ const gridFSBucketTests = (bucket: mongodb.GridFSBucket) => {
     const openUploadStream  = bucket.openUploadStream('file.dat');
     openUploadStream.on('close', () => {});
     openUploadStream.on('end', () => {});
+    openUploadStream.abort(); // $ExpectType void
     openUploadStream.abort(() => {
         openUploadStream.removeAllListeners();
     });
-    openUploadStream.abort();
+    openUploadStream.abort((error) => {
+        error; // $ExpectType MongoError
+    });
+    openUploadStream.abort((error, result) => {});
 };
 
 // Compression

so, as you can see, only small, focused change to the callback interface for this specific stream type.

@LinusU
Copy link
Contributor

LinusU commented May 18, 2020

It seems it would be impacting a lot of existing code

Yes, but I think that that would be good. Currently the typings here are basically turning off strictNullChecks for anyone that uses it, which I think is a big no-no.

That being said, if you just want this PR to focus on changing the specific callback for abort that is of course okay. The patch you posted above looks good

@peterblazejewicz
Copy link
Member Author

That being said, if you just want this PR to focus on changing the specific callback for abort that is of course okay. The patch you posted above looks good

Yes, my exact intent. I'll amend with the patch described.
Again, thx for valuable input!

This fixes callback method definition to match documentation:
https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#~errorCallback

Also this error callback now has the same shape as default
MongoCallback, hence the extend.

/cc @alexy4744

Fixes DefinitelyTyped#44549
@typescript-bot typescript-bot removed Self Merge This PR can now be self-merged by the PR author or an owner Owner Approved A listed owner of this package signed off on the pull request. labels May 18, 2020
@typescript-bot
Copy link
Contributor

@CaselIT Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@peterblazejewicz
Copy link
Member Author

rebased, with minor changes (as per @LinusU feedback)

@typescript-bot typescript-bot added the Owner Approved A listed owner of this package signed off on the pull request. label May 18, 2020
@typescript-bot typescript-bot added the Self Merge This PR can now be self-merged by the PR author or an owner label May 18, 2020
@typescript-bot
Copy link
Contributor

@LinusU Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@peterblazejewicz
Copy link
Member Author

Ready to merge

@typescript-bot typescript-bot merged commit 23a359c into DefinitelyTyped:master May 18, 2020
@peterblazejewicz peterblazejewicz deleted the fix/44549 branch May 18, 2020 18:43
@typescript-bot
Copy link
Contributor

I just published @types/mongodb@3.5.18 to npm.

jjballano-qatium pushed a commit to jjballano-qatium/DefinitelyTyped that referenced this pull request Jun 16, 2020
…iteStream.abort callback by @peterblazejewicz

This fixes callback method definition to match documentation:
https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#~errorCallback

Also this error callback now has the same shape as default
MongoCallback, hence the extend.

/cc @alexy4744

Fixes DefinitelyTyped#44549
ngbrown pushed a commit to ngbrown-forks/DefinitelyTyped that referenced this pull request Jul 11, 2020
…iteStream.abort callback by @peterblazejewicz

This fixes callback method definition to match documentation:
https://mongodb.github.io/node-mongodb-native/3.6/api/GridFSBucket.html#~errorCallback

Also this error callback now has the same shape as default
MongoCallback, hence the extend.

/cc @alexy4744

Fixes DefinitelyTyped#44549
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author is Owner The author of this PR is a listed owner of the package. Owner Approved A listed owner of this package signed off on the pull request. Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Popular package This PR affects a popular package (as counted by NPM download counts). Self Merge This PR can now be self-merged by the PR author or an owner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[@types/mongodb] Missing error parameter in abort() callback for GridFSBucketWriteStream

7 participants