deps: bluebird@3.1.2

closes #6361
- Updated bluebird dependency to latest 3.1.2.
- Updated update check to handle promises not resolving to arrays.
- Reviewed all other promise code and it looks good.
- Updated code using settle to use the new reflect function.
This commit is contained in:
JT Turner 2016-01-24 11:30:32 -08:00 committed by Jason Williams
parent 152d74b39e
commit 3db9913191
6 changed files with 58 additions and 53 deletions

View File

@ -52,11 +52,13 @@ DataImporter.prototype.doUserImport = function (t, tableData, owner, users, erro
}
// Import users, deduplicating with already present users
userOps = utils.importUsers(tableData.users, users, t);
userOps = utils.importUsers(tableData.users, users, t).map(function (userImport) {
return userImport.reflect();
});
return Promise.settle(userOps).then(function (descriptors) {
return Promise.all(userOps).then(function (descriptors) {
descriptors.forEach(function (d) {
if (d.isRejected()) {
if (!d.isFulfilled()) {
errors = errors.concat(d.reason());
} else {
imported.push(d.value().toJSON(internal));
@ -133,7 +135,7 @@ DataImporter.prototype.doImport = function (data) {
}
}).then(function () {
importResults.forEach(function (p) {
if (p.isRejected()) {
if (!p.isFulfilled()) {
errors = errors.concat(p.reason());
}
});

View File

@ -170,15 +170,16 @@ validate = function validate(data) {
_.each(_.keys(data.data), function (tableName) {
_.each(data.data[tableName], function (importValues) {
validateOps.push(validation.validateSchema(tableName, importValues));
validateOps.push(validation.
validateSchema(tableName, importValues).reflect());
});
});
return Promise.settle(validateOps).then(function (descriptors) {
return Promise.all(validateOps).then(function (descriptors) {
var errorList = [];
_.each(descriptors, function (d) {
if (d.isRejected()) {
if (!d.isFulfilled()) {
errorList = errorList.concat(d.reason());
}
});

View File

@ -204,10 +204,10 @@ utils = {
}
return _tag;
}));
}).reflect());
});
return Promise.settle(ops);
return Promise.all(ops);
},
importPosts: function importPosts(tableData, transaction) {
@ -232,11 +232,11 @@ utils = {
ops.push(models.Post.add(post, _.extend({}, internal, {transacting: transaction, importing: true}))
.catch(function (error) {
return Promise.reject({raw: error, model: 'post', data: post});
})
}).reflect()
);
});
return Promise.settle(ops);
return Promise.all(ops);
},
importUsers: function importUsers(tableData, existingUsers, transaction) {
@ -292,9 +292,9 @@ utils = {
if (!(error instanceof errors.NotFoundError)) {
return Promise.reject({raw: error, model: 'setting', data: tableData});
}
}));
}).reflect());
return Promise.settle(ops);
return Promise.all(ops);
},
/** For later **/
@ -317,10 +317,10 @@ utils = {
}
return _app;
}));
}).reflect());
});
return Promise.settle(ops);
return Promise.all(ops);
}
};

View File

@ -53,39 +53,41 @@ function updateCheckError(error) {
function updateCheckData() {
var data = {},
ops = [],
mailConfig = config.mail;
ops.push(api.settings.read(_.extend({key: 'dbHash'}, internal)).catch(errors.rejectError));
ops.push(api.settings.read(_.extend({key: 'activeTheme'}, internal)).catch(errors.rejectError));
ops.push(api.settings.read(_.extend({key: 'activeApps'}, internal))
.then(function (response) {
var apps = response.settings[0];
try {
apps = JSON.parse(apps.value);
} catch (e) {
return errors.rejectError(e);
}
return _.reduce(apps, function (memo, item) { return memo === '' ? memo + item : memo + ', ' + item; }, '');
}).catch(errors.rejectError));
ops.push(api.posts.browse().catch(errors.rejectError));
ops.push(api.users.browse(internal).catch(errors.rejectError));
ops.push(Promise.promisify(exec)('npm -v').catch(errors.rejectError));
data.ghost_version = currentVersion;
data.node_version = process.versions.node;
data.env = process.env.NODE_ENV;
data.database_type = config.database.client;
data.email_transport = mailConfig && (mailConfig.options && mailConfig.options.service ? mailConfig.options.service : mailConfig.transport);
data.email_transport = mailConfig &&
(mailConfig.options && mailConfig.options.service ?
mailConfig.options.service :
mailConfig.transport);
return Promise.settle(ops).then(function (descriptors) {
var hash = descriptors[0].value().settings[0],
theme = descriptors[1].value().settings[0],
apps = descriptors[2].value(),
posts = descriptors[3].value(),
users = descriptors[4].value(),
npm = descriptors[5].value(),
return Promise.props({
hash: api.settings.read(_.extend({key: 'dbHash'}, internal)).catch(errors.rejectError).reflect(),
theme: api.settings.read(_.extend({key: 'activeTheme'}, internal)).catch(errors.rejectError).reflect(),
apps: api.settings.read(_.extend({key: 'activeApps'}, internal))
.then(function (response) {
var apps = response.settings[0];
try {
apps = JSON.parse(apps.value);
} catch (e) {
return errors.rejectError(e);
}
return _.reduce(apps, function (memo, item) { return memo === '' ? memo + item : memo + ', ' + item; }, '');
}).catch(errors.rejectError).reflect(),
posts: api.posts.browse().catch(errors.rejectError).reflect(),
users: api.users.browse(internal).catch(errors.rejectError).reflect(),
npm: Promise.promisify(exec)('npm -v').catch(errors.rejectError).reflect()
}).then(function (descriptors) {
var hash = descriptors.hash.value().settings[0],
theme = descriptors.theme.value().settings[0],
apps = descriptors.apps.value(),
posts = descriptors.posts.value(),
users = descriptors.users.value(),
npm = descriptors.npm.value(),
blogUrl = url.parse(config.url),
blogId = blogUrl.hostname + blogUrl.pathname.replace(/\//, '') + hash.value;
@ -95,7 +97,7 @@ function updateCheckData() {
data.post_count = posts && posts.meta && posts.meta.pagination ? posts.meta.pagination.total : 0;
data.user_count = users && users.users && users.users.length ? users.users.length : 0;
data.blog_created_at = users && users.users && users.users[0] && users.users[0].created_at ? moment(users.users[0].created_at).unix() : '';
data.npm_version = _.isArray(npm) && npm[0] ? npm[0].toString().replace(/\n/, '') : '';
data.npm_version = npm.trim();
return data;
}).catch(updateCheckError);
@ -161,16 +163,16 @@ function updateCheckResponse(response) {
api.settings.edit(
{settings: [{key: 'nextUpdateCheck', value: response.next_check}]},
internal
).catch(errors.rejectError),
).catch(errors.rejectError).reflect(),
api.settings.edit(
{settings: [{key: 'displayUpdateNotification', value: response.version}]},
internal
).catch(errors.rejectError)
).catch(errors.rejectError).reflect()
);
return Promise.settle(ops).then(function then(descriptors) {
return Promise.map(ops).then(function then(descriptors) {
descriptors.forEach(function forEach(d) {
if (d.isRejected()) {
if (!d.isFulfilled()) {
errors.rejectError(d.reason());
}
});

View File

@ -104,14 +104,14 @@ describe('Mail', function () {
it('should fail to send messages when given insufficient data', function (done) {
mailer = new GhostMail();
Promise.settle([
mailer.send(),
mailer.send({}),
mailer.send({subject: '123'}),
mailer.send({subject: '', html: '123'})
Promise.all([
mailer.send().reflect(),
mailer.send({}).reflect(),
mailer.send({subject: '123'}).reflect(),
mailer.send({subject: '', html: '123'}).reflect()
]).then(function (descriptors) {
descriptors.forEach(function (d) {
d.isRejected().should.be.true();
d.isFulfilled().should.be.false();
d.reason().should.be.an.instanceOf(Error);
d.reason().message.should.eql('Error: Incomplete message data.');
});

View File

@ -28,7 +28,7 @@
},
"dependencies": {
"bcryptjs": "2.3.0",
"bluebird": "2.10.2",
"bluebird": "3.1.2",
"body-parser": "1.14.2",
"bookshelf": "0.9.1",
"busboy": "0.2.12",