-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
BREAKING CHANGE: use kareem@v3 promise-based execPre() for document hooks #15324
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
45fd784
make saveSubdocs fully async
vkarpov15 f4840bb
BREAKING CHANGE: use kareem@v3 promise-based execPre() for document h…
vkarpov15 acdbb9d
Merge branch '9.0' into vkarpov15/async-savesubdocs
vkarpov15 1ab5638
add note about dropping support for passing args to next middleware
vkarpov15 37896da
Update lib/browserDocument.js
vkarpov15 bf60a68
Update lib/helpers/model/applyHooks.js
vkarpov15 32ab2d5
Update lib/model.js
vkarpov15 333b72f
Update lib/model.js
vkarpov15 32d5ab7
Update lib/query.js
vkarpov15 f98aab4
refactor: use assert.rejects()
vkarpov15 cb59f37
docs: remove obsolete comment
vkarpov15 eb0368f
style: fix lint
vkarpov15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -810,19 +810,16 @@ Model.prototype.deleteOne = function deleteOne(options) { | |
| } | ||
| } | ||
|
|
||
| query.pre(function queryPreDeleteOne(cb) { | ||
| self.constructor._middleware.execPre('deleteOne', self, [self], cb); | ||
| query.pre(function queryPreDeleteOne() { | ||
| return self.constructor._middleware.execPre('deleteOne', self, [self]); | ||
| }); | ||
| query.pre(function callSubdocPreHooks(cb) { | ||
| each(self.$getAllSubdocs(), (subdoc, cb) => { | ||
| subdoc.constructor._middleware.execPre('deleteOne', subdoc, [subdoc], cb); | ||
| }, cb); | ||
| query.pre(function callSubdocPreHooks() { | ||
| return Promise.all(self.$getAllSubdocs().map(subdoc => subdoc.constructor._middleware.execPre('deleteOne', subdoc, [subdoc]))); | ||
|
Comment on lines
+813
to
+817
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should those functions be marked |
||
| }); | ||
| query.pre(function skipIfAlreadyDeleted(cb) { | ||
| query.pre(function skipIfAlreadyDeleted() { | ||
| if (self.$__.isDeleted) { | ||
| return cb(Kareem.skipWrappedFunction()); | ||
| throw new Kareem.skipWrappedFunction(); | ||
| } | ||
| return cb(); | ||
| }); | ||
| query.post(function callSubdocPostHooks(cb) { | ||
| each(self.$getAllSubdocs(), (subdoc, cb) => { | ||
|
|
@@ -1185,16 +1182,11 @@ Model.createCollection = async function createCollection(options) { | |
| throw new MongooseError('Model.createCollection() no longer accepts a callback'); | ||
| } | ||
|
|
||
| const shouldSkip = await new Promise((resolve, reject) => { | ||
| this.hooks.execPre('createCollection', this, [options], (err) => { | ||
| if (err != null) { | ||
| if (err instanceof Kareem.skipWrappedFunction) { | ||
| return resolve(true); | ||
| } | ||
| return reject(err); | ||
| } | ||
| resolve(); | ||
| }); | ||
| const shouldSkip = await this.hooks.execPre('createCollection', this, [options]).catch(err => { | ||
| if (err instanceof Kareem.skipWrappedFunction) { | ||
| return true; | ||
| } | ||
| throw err; | ||
| }); | ||
|
|
||
| const collectionOptions = this && | ||
|
|
@@ -3380,17 +3372,13 @@ Model.bulkWrite = async function bulkWrite(ops, options) { | |
| } | ||
| options = options || {}; | ||
|
|
||
| const shouldSkip = await new Promise((resolve, reject) => { | ||
| this.hooks.execPre('bulkWrite', this, [ops, options], (err) => { | ||
| if (err != null) { | ||
| if (err instanceof Kareem.skipWrappedFunction) { | ||
| return resolve(err); | ||
| } | ||
| return reject(err); | ||
| } | ||
| resolve(); | ||
| }); | ||
| }); | ||
| const shouldSkip = await this.hooks.execPre('bulkWrite', this, [ops, options]).catch(err => { | ||
| if (err instanceof Kareem.skipWrappedFunction) { | ||
| return err; | ||
| } | ||
| throw err; | ||
| } | ||
| ); | ||
|
|
||
| if (shouldSkip) { | ||
| return shouldSkip.args[0]; | ||
|
|
@@ -3621,16 +3609,8 @@ Model.bulkSave = async function bulkSave(documents, options) { | |
| return bulkWriteResult; | ||
| }; | ||
|
|
||
| function buildPreSavePromise(document, options) { | ||
| return new Promise((resolve, reject) => { | ||
| document.schema.s.hooks.execPre('save', document, [options], (err) => { | ||
| if (err) { | ||
| reject(err); | ||
| return; | ||
| } | ||
| resolve(); | ||
| }); | ||
| }); | ||
| async function buildPreSavePromise(document, options) { | ||
| return document.schema.s.hooks.execPre('save', document, [options]); | ||
| } | ||
|
|
||
| function handleSuccessfulWrite(document) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.