-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
BREAKING CHANGE: remove support for callbacks in pre middleware #15599
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: 9.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -886,9 +886,9 @@ describe('aggregate: ', function() { | |||||
const s = new Schema({ name: String }); | ||||||
|
||||||
let called = 0; | ||||||
s.pre('aggregate', function(next) { | ||||||
s.pre('aggregate', function() { | ||||||
++called; | ||||||
next(); | ||||||
return Promise.resolve(); | ||||||
}); | ||||||
|
||||||
const M = db.model('Test', s); | ||||||
|
@@ -902,9 +902,9 @@ describe('aggregate: ', function() { | |||||
it('setting option in pre (gh-7606)', async function() { | ||||||
const s = new Schema({ name: String }); | ||||||
|
||||||
s.pre('aggregate', function(next) { | ||||||
s.pre('aggregate', function() { | ||||||
this.options.collation = { locale: 'en_US', strength: 1 }; | ||||||
next(); | ||||||
return Promise.resolve(); | ||||||
}); | ||||||
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. [nitpick] Returning Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
const M = db.model('Test', s); | ||||||
|
@@ -920,9 +920,9 @@ describe('aggregate: ', function() { | |||||
it('adding to pipeline in pre (gh-8017)', async function() { | ||||||
const s = new Schema({ name: String }); | ||||||
|
||||||
s.pre('aggregate', function(next) { | ||||||
s.pre('aggregate', function() { | ||||||
this.append({ $limit: 1 }); | ||||||
next(); | ||||||
return Promise.resolve(); | ||||||
}); | ||||||
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. [nitpick] Returning Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
const M = db.model('Test', s); | ||||||
|
@@ -980,8 +980,8 @@ describe('aggregate: ', function() { | |||||
const s = new Schema({ name: String }); | ||||||
|
||||||
const calledWith = []; | ||||||
s.pre('aggregate', function(next) { | ||||||
next(new Error('woops')); | ||||||
s.pre('aggregate', function() { | ||||||
return Promise.reject(new Error('woops')); | ||||||
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. [nitpick] Instead of returning a rejected promise, use
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback 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. Curious if it'll make a difference to |
||||||
}); | ||||||
s.post('aggregate', function(error, res, next) { | ||||||
calledWith.push(error); | ||||||
|
@@ -1003,9 +1003,9 @@ describe('aggregate: ', function() { | |||||
|
||||||
let calledPre = 0; | ||||||
let calledPost = 0; | ||||||
s.pre('aggregate', function(next) { | ||||||
s.pre('aggregate', function() { | ||||||
++calledPre; | ||||||
next(); | ||||||
return Promise.resolve(); | ||||||
}); | ||||||
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. [nitpick] Returning
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
s.post('aggregate', function(res, next) { | ||||||
++calledPost; | ||||||
|
@@ -1030,9 +1030,9 @@ describe('aggregate: ', function() { | |||||
|
||||||
let calledPre = 0; | ||||||
const calledPost = []; | ||||||
s.pre('aggregate', function(next) { | ||||||
s.pre('aggregate', function() { | ||||||
++calledPre; | ||||||
next(); | ||||||
return Promise.resolve(); | ||||||
}); | ||||||
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. [nitpick] Returning
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
s.post('aggregate', function(res, next) { | ||||||
calledPost.push(res); | ||||||
|
@@ -1295,11 +1295,10 @@ describe('aggregate: ', function() { | |||||
it('cursor() errors out if schema pre aggregate hook throws an error (gh-15279)', async function() { | ||||||
const schema = new Schema({ name: String }); | ||||||
|
||||||
schema.pre('aggregate', function(next) { | ||||||
schema.pre('aggregate', function() { | ||||||
if (!this.options.allowed) { | ||||||
throw new Error('Unauthorized aggregate operation: only allowed operations are permitted'); | ||||||
} | ||||||
next(); | ||||||
}); | ||||||
|
||||||
const Test = db.model('Test', schema); | ||||||
|
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.
[nitpick] Returning
Promise.resolve()
is unnecessary for synchronous operations. Either declare the function asasync
or simply remove the return statement since the middleware doesn't need to return anything for synchronous operations.Copilot uses AI. Check for mistakes.