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: Mongoose types incorrect for when includeResultMetadata: true is set #14078
Conversation
…r all middlewares
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your PR. Please fix lint, add a test case, and address the comments in this review 👍
…sultMetadata, Fixed Lint
…dundant middlewares
…OneAndDeleteRes', 'findByIdAndDeleteRes'
…neAndReplace middlewares
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, though some minor questions / suggestions.
also does someone know why the tests are not running for the latest commits?
Can you please fix merge conflicts? |
Fixed Merge Conflicts ✅ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks 👍
… set (#14078) * Added Seperate type for Middlewares that support includeResultMetadata * Added Return Type as Raw Result when includeResultMetadata is TRUE for all middlewares * Added Seperate post query type for middlewares that support includeResultMetadata * Added Seperate post query type for middlewares that support includeResultMetadata, Fixed Lint * Updated MongooseRawResultQueryMiddleware and removed duplicate and redundant middlewares * Removed 'findByIdAndRemove' type definations : DEPRECATED, Fixed Linting Errors * Removed test cases for 'findByIdAndRemove', Added test case for 'findOneAndDeleteRes', 'findByIdAndDeleteRes' * Updated findOneAndDelete, Added test case for findOneAndUpdate, findOneAndReplace middlewares
Summary
Fixed Issue #13987
Mongoose Version: 8.0
When
includeResultMetadata
is set totrue
. The document parameter in post middleware can also beModifyResult<>
.Functions that support
includeResultMetadata
option are :findOneAndUpdate
,findByIdAndUpdate
,findOneAndReplace
,findByIdAndDelete
, andfindOneAndDelete
.Changes Done:
ModifyResult<>
.ModifyResult<>
whenincludeResultMetadata
was set to True. I've addressed this by adding appropriate return types.includeResultMetadata
is false and no matching document is found in any of these functions, the document parameter in the post middleware isNULL
. So I have includedNULL
as a possible doc type in the middleware parameter.Examples
I have fixed the issue for v8.0. If the solution is acceptable then I will also do it for v7.4 that was originally specified in the Issue. @hasezoey