不要怂,就是干,撸起袖子干!

Commit 04573fd3 by Andy Edwards Committed by GitHub

refactor: remove bluebird Promise.prototype.return usage (#12065)

1 parent e0343afe
...@@ -800,7 +800,7 @@ class BelongsToMany extends Association { ...@@ -800,7 +800,7 @@ class BelongsToMany extends Association {
// Create the related model instance // Create the related model instance
return association.target.create(values, options).then(newAssociatedObject => return association.target.create(values, options).then(newAssociatedObject =>
sourceInstance[association.accessors.add](newAssociatedObject, _.omit(options, ['fields'])).return(newAssociatedObject) sourceInstance[association.accessors.add](newAssociatedObject, _.omit(options, ['fields'])).then(() => newAssociatedObject)
); );
} }
......
...@@ -378,7 +378,7 @@ class HasMany extends Association { ...@@ -378,7 +378,7 @@ class HasMany extends Association {
)); ));
} }
return Utils.Promise.all(promises).return(sourceInstance); return Utils.Promise.all(promises).then(() => sourceInstance);
}); });
} }
...@@ -408,7 +408,7 @@ class HasMany extends Association { ...@@ -408,7 +408,7 @@ class HasMany extends Association {
) )
}; };
return this.target.unscoped().update(update, _.defaults({ where }, options)).return(sourceInstance); return this.target.unscoped().update(update, _.defaults({ where }, options)).then(() => sourceInstance);
} }
/** /**
...@@ -434,7 +434,7 @@ class HasMany extends Association { ...@@ -434,7 +434,7 @@ class HasMany extends Association {
) )
}; };
return this.target.unscoped().update(update, _.defaults({ where }, options)).return(this); return this.target.unscoped().update(update, _.defaults({ where }, options)).then(() => this);
} }
/** /**
......
...@@ -309,7 +309,7 @@ class ConnectionManager { ...@@ -309,7 +309,7 @@ class ConnectionManager {
_connect(config) { _connect(config) {
return this.sequelize.runHooks('beforeConnect', config) return this.sequelize.runHooks('beforeConnect', config)
.then(() => this.dialect.connectionManager.connect(config)) .then(() => this.dialect.connectionManager.connect(config))
.then(connection => this.sequelize.runHooks('afterConnect', connection, config).return(connection)); .then(connection => this.sequelize.runHooks('afterConnect', connection, config).then(() => connection));
} }
/** /**
......
...@@ -128,7 +128,7 @@ const Hooks = { ...@@ -128,7 +128,7 @@ const Hooks = {
debug(`running hook ${hookType}`); debug(`running hook ${hookType}`);
return hook.apply(this, hookArgs); return hook.apply(this, hookArgs);
}).return(); }).then(() => undefined);
}, },
/** /**
......
...@@ -109,8 +109,7 @@ class InstanceValidator { ...@@ -109,8 +109,7 @@ class InstanceValidator {
.catch(error => runHooks('validationFailed', this.modelInstance, this.options, error) .catch(error => runHooks('validationFailed', this.modelInstance, this.options, error)
.then(newError => { throw newError || error; })) .then(newError => { throw newError || error; }))
) )
.then(() => runHooks('afterValidate', this.modelInstance, this.options)) .then(() => runHooks('afterValidate', this.modelInstance, this.options)).then(() => this.modelInstance);
.return(this.modelInstance);
} }
/** /**
......
...@@ -1374,7 +1374,7 @@ class Model { ...@@ -1374,7 +1374,7 @@ class Model {
if (options.hooks) { if (options.hooks) {
return this.runHooks('afterSync', options); return this.runHooks('afterSync', options);
} }
}).return(this); }).then(() => this);
} }
/** /**
...@@ -1856,7 +1856,7 @@ class Model { ...@@ -1856,7 +1856,7 @@ class Model {
); );
} }
}); });
})).return(original); })).then(() => original);
} }
/** /**
...@@ -4357,7 +4357,7 @@ class Model { ...@@ -4357,7 +4357,7 @@ class Model {
options.where = Object.assign({}, options.where, identifier); options.where = Object.assign({}, options.where, identifier);
options.instance = this; options.instance = this;
return this.constructor.increment(fields, options).return(this); return this.constructor.increment(fields, options).then(() => this);
} }
/** /**
......
...@@ -826,7 +826,7 @@ class Sequelize { ...@@ -826,7 +826,7 @@ class Sequelize {
if (options.hooks) { if (options.hooks) {
return this.runHooks('afterBulkSync', options); return this.runHooks('afterBulkSync', options);
} }
}).return(this); }).then(() => this);
} }
/** /**
...@@ -895,7 +895,7 @@ class Sequelize { ...@@ -895,7 +895,7 @@ class Sequelize {
type: QueryTypes.SELECT type: QueryTypes.SELECT
}, options); }, options);
return this.query('SELECT 1+1 AS result', options).return(); return this.query('SELECT 1+1 AS result', options).then(() => undefined);
} }
databaseVersion(options) { databaseVersion(options) {
...@@ -1104,7 +1104,7 @@ class Sequelize { ...@@ -1104,7 +1104,7 @@ class Sequelize {
const transaction = new Transaction(this, options); const transaction = new Transaction(this, options);
if (!autoCallback) return transaction.prepareEnvironment(false).return(transaction); if (!autoCallback) return transaction.prepareEnvironment(false).then(() => transaction);
// autoCallback provided // autoCallback provided
return Sequelize._clsRun(() => { return Sequelize._clsRun(() => {
......
...@@ -1556,7 +1556,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -1556,7 +1556,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Member.create({ member_id: 10, email: 'team@sequelizejs.com' }) Member.create({ member_id: 10, email: 'team@sequelizejs.com' })
]); ]);
}).then(([group, member]) => { }).then(([group, member]) => {
return group.addMember(member).return(group); return group.addMember(member).then(() => group);
}).then(group => { }).then(group => {
return group.getMembers(); return group.getMembers();
}).then(members => { }).then(members => {
...@@ -1728,7 +1728,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -1728,7 +1728,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Task.create({ id: 51, title: 'following up' }) Task.create({ id: 51, title: 'following up' })
]); ]);
}).then(([user, task1, task2]) => { }).then(([user, task1, task2]) => {
return user.setTasks([task1, task2]).return(user); return user.setTasks([task1, task2]).then(() => user);
}).then(user => { }).then(user => {
return user.getTasks(); return user.getTasks();
}).then(userTasks => { }).then(userTasks => {
...@@ -1867,7 +1867,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -1867,7 +1867,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return Promise.all([ return Promise.all([
user.addTask(task1), user.addTask(task1),
user.addTask([task2]) user.addTask([task2])
]).return(user); ]).then(() => user);
}).then(user => { }).then(user => {
return user.getTasks(); return user.getTasks();
}).then(tasks => { }).then(tasks => {
...@@ -1965,7 +1965,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -1965,7 +1965,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Task.create({ id: 50, title: 'get started' }) Task.create({ id: 50, title: 'get started' })
]); ]);
}).then(([user, task]) => { }).then(([user, task]) => {
return user.addTask(task.id).return(user); return user.addTask(task.id).then(() => user);
}).then(user => { }).then(user => {
return user.getTasks(); return user.getTasks();
}).then(tasks => { }).then(tasks => {
...@@ -2026,7 +2026,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2026,7 +2026,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
Task.create({ id: 50, title: 'get started' }) Task.create({ id: 50, title: 'get started' })
]); ]);
}).then(([user, task]) => { }).then(([user, task]) => {
return user.addTask(task).return(user); return user.addTask(task).then(() => user);
}).then(user => { }).then(user => {
return user.getTasks(); return user.getTasks();
}).then(tasks => { }).then(tasks => {
...@@ -2074,7 +2074,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2074,7 +2074,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
return Promise.all([ return Promise.all([
user.addTasks(task1), user.addTasks(task1),
user.addTasks([task2]) user.addTasks([task2])
]).return(user); ]).then(() => user);
}).then(user => { }).then(user => {
return user.getTasks(); return user.getTasks();
}).then(tasks => { }).then(tasks => {
...@@ -2213,7 +2213,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2213,7 +2213,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this.Task.create({ title: 'task1' }), this.Task.create({ title: 'task1' }),
this.Task.create({ title: 'task2' }) this.Task.create({ title: 'task2' })
]).then(([user, task1, task2]) => { ]).then(([user, task1, task2]) => {
return user.setTasks([task1, task2]).return(user); return user.setTasks([task1, task2]).then(() => user);
}).then(user => { }).then(user => {
return user.setTasks(null, { return user.setTasks(null, {
logging: spy logging: spy
...@@ -2391,7 +2391,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2391,7 +2391,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}).then(([user, project1, project2]) => { }).then(([user, project1, project2]) => {
return user.addProjects([project1, project2], { return user.addProjects([project1, project2], {
logging: spy logging: spy
}).return(user); }).then(() => user);
}).then(user => { }).then(user => {
expect(spy).to.have.been.calledTwice; expect(spy).to.have.been.calledTwice;
spy.resetHistory(); spy.resetHistory();
...@@ -2405,7 +2405,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2405,7 +2405,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
expect(spy.calledOnce).to.be.ok; expect(spy.calledOnce).to.be.ok;
const project = projects[0]; const project = projects[0];
expect(project).to.be.ok; expect(project).to.be.ok;
return project.destroy().return(user); return project.destroy().then(() => user);
}).then(user => { }).then(user => {
return this.User.findOne({ return this.User.findOne({
where: { id: user.id }, where: { id: user.id },
...@@ -2429,7 +2429,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2429,7 +2429,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}).then(([user, project]) => { }).then(([user, project]) => {
this.user = user; this.user = user;
this.project = project; this.project = project;
return user.addProject(project, { logging: spy }).return(user); return user.addProject(project, { logging: spy }).then(() => user);
}).then(user => { }).then(user => {
expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for INSERT expect(spy.calledTwice).to.be.ok; // Once for SELECT, once for INSERT
spy.resetHistory(); spy.resetHistory();
...@@ -2444,7 +2444,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2444,7 +2444,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
expect(project).to.be.ok; expect(project).to.be.ok;
return this.user.removeProject(project, { return this.user.removeProject(project, {
logging: spy logging: spy
}).return(project); }).then(() => project);
}).then(() => { }).then(() => {
expect(spy).to.have.been.calledOnce; expect(spy).to.have.been.calledOnce;
}); });
...@@ -2486,7 +2486,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2486,7 +2486,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
); );
}).then(([group, user, project]) => { }).then(([group, user, project]) => {
return user.addProject(project).then(() => { return user.addProject(project).then(() => {
return group.addUser(user).return(group); return group.addUser(user).then(() => group);
}); });
}).then(group => { }).then(group => {
// get the group and include both the users in the group and their project's // get the group and include both the users in the group and their project's
...@@ -2591,7 +2591,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2591,7 +2591,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this.User.create({ username: 'foo' }), this.User.create({ username: 'foo' }),
this.Task.create({ title: 'foo' }) this.Task.create({ title: 'foo' })
]).then(([user, task]) => { ]).then(([user, task]) => {
return user.addTask(task).return(user); return user.addTask(task).then(() => user);
}).then(user => { }).then(user => {
return user.setTasks(null); return user.setTasks(null);
}).then(result => { }).then(result => {
...@@ -2622,7 +2622,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2622,7 +2622,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this.User.create(), this.User.create(),
this.Project.create() this.Project.create()
]).then(([user, project]) => { ]).then(([user, project]) => {
return user.addProject(project, { through: { status: 'active', data: 42 } }).return(user); return user.addProject(project, { through: { status: 'active', data: 42 } }).then(() => user);
}).then(user => { }).then(user => {
return user.getProjects(); return user.getProjects();
}).then(projects => { }).then(projects => {
...@@ -2640,7 +2640,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2640,7 +2640,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this.User.create(), this.User.create(),
this.Project.create() this.Project.create()
]).then(([user, project]) => { ]).then(([user, project]) => {
return user.addProject(project, { through: { status: 'active', data: 42 } }).return(user); return user.addProject(project, { through: { status: 'active', data: 42 } }).then(() => user);
}).then(() => { }).then(() => {
return this.User.findAll({ return this.User.findAll({
include: [{ include: [{
...@@ -2666,7 +2666,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2666,7 +2666,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
this.User.create(), this.User.create(),
this.Project.create() this.Project.create()
]).then(([user, project]) => { ]).then(([user, project]) => {
return user.addProject(project, { through: { status: 'active', data: 42 } }).return(user); return user.addProject(project, { through: { status: 'active', data: 42 } }).then(() => user);
}).then(user => { }).then(user => {
return user.getProjects({ joinTableAttributes: ['status'] }); return user.getProjects({ joinTableAttributes: ['status'] });
}).then(projects => { }).then(projects => {
...@@ -2867,7 +2867,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => { ...@@ -2867,7 +2867,7 @@ describe(Support.getTestDialectTeaser('BelongsToMany'), () => {
}) })
]); ]);
}).then(([worker, tasks]) => { }).then(([worker, tasks]) => {
return worker.setTasks(tasks).return([worker, tasks]); return worker.setTasks(tasks).then(() => [worker, tasks]);
}).then(([worker, tasks]) => { }).then(([worker, tasks]) => {
return worker.setTasks(tasks); return worker.setTasks(tasks);
}); });
......
...@@ -48,7 +48,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -48,7 +48,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
return Promise.join( return Promise.join(
user.get('Tasks')[0].createSubtask({ title: 'Make a startup', active: false }), user.get('Tasks')[0].createSubtask({ title: 'Make a startup', active: false }),
user.get('Tasks')[0].createSubtask({ title: 'Engage rock stars', active: true }) user.get('Tasks')[0].createSubtask({ title: 'Engage rock stars', active: true })
).return(user); ).then(() => user);
}).then(user => { }).then(user => {
return expect(user.countTasks({ return expect(user.countTasks({
attributes: [Task.primaryKeyField, 'title'], attributes: [Task.primaryKeyField, 'title'],
...@@ -943,7 +943,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -943,7 +943,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
return this.sequelize.sync({ force: true }).then(() => { return this.sequelize.sync({ force: true }).then(() => {
return Article.create({ title: 'foo' }); return Article.create({ title: 'foo' });
}).then(article => { }).then(article => {
return article.createLabel({ text: 'bar' }).return(article); return article.createLabel({ text: 'bar' }).then(() => article);
}).then(article => { }).then(article => {
return Label.findAll({ where: { ArticleId: article.id } }); return Label.findAll({ where: { ArticleId: article.id } });
}).then(labels => { }).then(labels => {
...@@ -1027,7 +1027,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -1027,7 +1027,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
text: 'yolo' text: 'yolo'
}, { }, {
fields: ['text'] fields: ['text']
}).return(article); }).then(() => article);
}).then(article => { }).then(article => {
return article.getLabels(); return article.getLabels();
}).then(labels => { }).then(labels => {
...@@ -1265,7 +1265,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -1265,7 +1265,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task.create({ title: 'task' }) Task.create({ title: 'task' })
]); ]);
}).then(([user, task]) => { }).then(([user, task]) => {
return user.setTasks([task]).return(user); return user.setTasks([task]).then(() => user);
}).then(user => { }).then(user => {
// Changing the id of a DAO requires a little dance since // Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the // the `UPDATE` query generated by `save()` uses `id` in the
...@@ -1321,7 +1321,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => { ...@@ -1321,7 +1321,7 @@ describe(Support.getTestDialectTeaser('HasMany'), () => {
Task.create({ title: 'task' }) Task.create({ title: 'task' })
]); ]);
}).then(([user, task]) => { }).then(([user, task]) => {
return user.setTasks([task]).return(user); return user.setTasks([task]).then(() => user);
}).then(user => { }).then(user => {
// Changing the id of a DAO requires a little dance since // Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the // the `UPDATE` query generated by `save()` uses `id` in the
......
...@@ -866,7 +866,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -866,7 +866,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
return Sequelize.Promise.all([ return Sequelize.Promise.all([
task.addMiniTask(minitask), task.addMiniTask(minitask),
project.addTask(task) project.addTask(task)
]).return(project); ]).then(() => project);
}).then(project => { }).then(project => {
return project.destroy(); return project.destroy();
}).then(() => { }).then(() => {
...@@ -921,7 +921,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => { ...@@ -921,7 +921,7 @@ describe(Support.getTestDialectTeaser('Hooks'), () => {
return Sequelize.Promise.all([ return Sequelize.Promise.all([
task.addMiniTask(minitask), task.addMiniTask(minitask),
project.addTask(task) project.addTask(task)
]).return(project); ]).then(() => project);
}).then(project => { }).then(project => {
return expect(project.destroy()).to.eventually.be.rejectedWith(CustomErrorText).then(() => { return expect(project.destroy()).to.eventually.be.rejectedWith(CustomErrorText).then(() => {
expect(beforeProject).to.be.true; expect(beforeProject).to.be.true;
......
...@@ -273,7 +273,7 @@ describe(Support.getTestDialectTeaser('Include'), () => { ...@@ -273,7 +273,7 @@ describe(Support.getTestDialectTeaser('Include'), () => {
return Promise.join( return Promise.join(
props.task.setUser(props.user), props.task.setUser(props.user),
props.user.setGroup(props.group) props.user.setGroup(props.group)
).return(props); ).then(() => props);
}).then(props => { }).then(props => {
return Task.findOne({ return Task.findOne({
where: { where: {
......
...@@ -244,7 +244,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -244,7 +244,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
include: [Shoe] include: [Shoe]
}).then(lePlayer => { }).then(lePlayer => {
expect(lePlayer.Shoe).not.to.be.null; expect(lePlayer.Shoe).not.to.be.null;
return lePlayer.Shoe.destroy().return(lePlayer); return lePlayer.Shoe.destroy().then(() => lePlayer);
}).then(lePlayer => { }).then(lePlayer => {
return lePlayer.reload(); return lePlayer.reload();
}).then(lePlayer => { }).then(lePlayer => {
...@@ -277,7 +277,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -277,7 +277,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
expect(leTeam.Players).not.to.be.empty; expect(leTeam.Players).not.to.be.empty;
return leTeam.Players[1].destroy().then(() => { return leTeam.Players[1].destroy().then(() => {
return leTeam.Players[0].destroy(); return leTeam.Players[0].destroy();
}).return(leTeam); }).then(() => leTeam);
}).then(leTeam => { }).then(leTeam => {
return leTeam.reload(); return leTeam.reload();
}).then(leTeam => { }).then(leTeam => {
...@@ -309,7 +309,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => { ...@@ -309,7 +309,7 @@ describe(Support.getTestDialectTeaser('Instance'), () => {
include: [Player] include: [Player]
}).then(leTeam => { }).then(leTeam => {
expect(leTeam.Players).to.have.length(2); expect(leTeam.Players).to.have.length(2);
return leTeam.Players[0].destroy().return(leTeam); return leTeam.Players[0].destroy().then(() => leTeam);
}).then(leTeam => { }).then(leTeam => {
return leTeam.reload(); return leTeam.reload();
}).then(leTeam => { }).then(leTeam => {
......
...@@ -44,7 +44,7 @@ const Support = { ...@@ -44,7 +44,7 @@ const Support = {
const options = Object.assign({}, sequelize.options, { storage: p }), const options = Object.assign({}, sequelize.options, { storage: p }),
_sequelize = new Sequelize(sequelize.config.database, null, null, options); _sequelize = new Sequelize(sequelize.config.database, null, null, options);
return _sequelize.sync({ force: true }).return(_sequelize); return _sequelize.sync({ force: true }).then(() => _sequelize);
} }
return Sequelize.Promise.resolve(sequelize); return Sequelize.Promise.resolve(sequelize);
}, },
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!