-
-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(document+model): pass options to pre('deleteOne') and update+options to pre('updateOne') hooks #15908
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
Conversation
…ions to pre('updateOne') hooks
Fix #15870
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.
Pull request overview
This pull request enhances document middleware for deleteOne and updateOne operations by making options and update parameters accessible in pre-hooks. This addresses issue #15870 where these parameters were previously inaccessible in document middleware.
Key Changes:
- Added new TypeScript middleware function types (
PreDeleteOneMiddlewareFunctionandPreUpdateOneMiddlewareFunction) with extended parameter signatures - Updated middleware execution in
lib/model.jsandlib/document.jsto pass options (and update forupdateOne) to pre-hooks - Added specific method overloads for
deleteOneandupdateOnein schema pre-hook type definitions
Reviewed changes
Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| types/middlewares.d.ts | Defines new middleware function types with additional parameters for document-level deleteOne and updateOne hooks |
| types/index.d.ts | Adds specific overloads for deleteOne and updateOne pre-hooks to support the new parameter signatures |
| test/types/schema.test.ts | Updates type tests to verify the new middleware signatures accept doc, update, and options parameters |
| test/model.middleware.test.js | Enhances deleteOne test to verify options parameter is accessible in pre-hook |
| test/document.test.js | Updates updateOne test to verify both update and options parameters are accessible in pre-hook, but incorrectly extends this to post-hook |
| lib/model.js | Modifies deleteOne middleware execution to pass options parameter to pre-hooks |
| lib/document.js | Updates parameter name from doc to update for clarity and modifies updateOne middleware execution to pass document, update, and options to pre-hooks |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ment middleware Re: #15870
hasezoey
left a comment
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
Fix #15870
Summary
Make it possible to access parameters from document middleware - currently not possible in Mongoose 8 or 9. Can't make this change for post middleware because that would be backwards breaking.
With this PR, you can do:
Examples