-
Notifications
You must be signed in to change notification settings - Fork 24
BREAKING CHANGE: rely on transforms over middleware to apply virtuals and add findOneAndReplace support #76
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
base: master
Are you sure you want to change the base?
Conversation
… and add findOneAndReplace support Fix #75
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 PR addresses a critical issue where query transforms run before middleware, which has been causing the plugin to misbehave. The changes include:
- Adding support for the findOneAndReplace operation in tests.
- Updating the middleware to unshift the transform across multiple query operations (including findOneAndReplace) so it executes prior to user-supplied transforms.
- Removing redundant post hooks in favor of the new pre hook approach.
Reviewed Changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
test/index.test.js | Added a new test case for the findOneAndReplace operation. |
index.js | Modified middleware to switch to an unshifted pre hook for multiple query types. |
Files not reviewed (1)
- package.json: Language not supported
Comments suppressed due to low confidence (1)
test/index.test.js:100
- [nitpick] It may be beneficial to extend the test case for findOneAndReplace by considering edge cases, such as scenarios where an empty dataset is returned, to ensure the transform behavior remains consistent.
return model.findOneAndReplace({ _id: docId }, { ...baseObj }).lean(leanOptions).exec();
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…-virtuals into vkarpov15/gh-75
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, though i have not much experience with this plugin.
for (const id in docs) { | ||
const doc = docs[id]; |
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.
for (const id in docs) { | |
const doc = docs[id]; | |
for (const [id, doc] of Object.entries(docs)) { |
Or did i misunderstand what docs
variable contains?
Fix #75
Summary
#75 points out a significant issue in this plugin's functionality: Query
transform()
s run before middleware, so transform that changes the query shape causes this plugin to break. Fix the issue by making this pluginunshift()
a transform to the front of the transforms array inpre()
, which will ensure this plugin's transform will run before any user-specified transforms.This change will require a 2.0.0 release because it may break some existing code.
@hasezoey can you please take a look at this one?
Examples