Skip to content
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

Upgrade bluebird to 3.x (take two) #591

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ Document.prototype._save = function(docToSave, saveAll, savedModel, callback) {
async: true,
fn: self._saveHook,
fnArgs: [docToSave, saveAll, savedModel]
}).nodeify(callback);
}).asCallback(callback);
}


Expand Down Expand Up @@ -664,7 +664,7 @@ Document.prototype._saveHook = function(docToSave, saveAll, savedModel) {
self.getModel().ready().then(function() {
Promise.all(promises).then(function() {
self._onSavedBelongsTo(copy, docToSave, belongsToKeysSaved, saveAll, savedModel, resolve, reject);
}).error(reject);
}).catch(reject);
});
});
return p;
Expand Down Expand Up @@ -781,14 +781,14 @@ Document.prototype._saveSelf = function(
querySaveSelf = buildQuery();
querySaveSelf.run().then(function(result) {
self._onSaved(result, docToSave, saveAll, savedModel, resolve, reject)
}).error(reject)
}).error(reject);
}).catch(reject)
}).catch(reject);
}
else {
querySaveSelf = buildQuery();
querySaveSelf.run().then(function(result) {
self._onSaved(result, docToSave, saveAll, savedModel, resolve, reject)
}).error(reject)
}).catch(reject)
}
}, reject);
});
Expand Down Expand Up @@ -828,7 +828,7 @@ Document.prototype._onSaved = function(result, docToSave, saveAll, savedModel, r
if (promise instanceof Promise) {
promise.then(function() {
self._saveMany(docToSave, saveAll, savedModel, resolve, reject)
}).error(reject);
}).catch(reject);
}
else {
self._saveMany(docToSave, saveAll, savedModel, resolve, reject)
Expand Down Expand Up @@ -875,7 +875,7 @@ Document.prototype._saveMany = function(docToSave, saveAll, savedModel, resolve,
key: key
});
resolve();
}).error(reject);
}).catch(reject);
}))
})(key)
}
Expand Down Expand Up @@ -941,11 +941,11 @@ Document.prototype._saveMany = function(docToSave, saveAll, savedModel, resolve,
});

resolve();
}).error(reject);
}).catch(reject);
}

if (self[key][i] instanceof Promise) {
self[key][i].then(callback).error(reject);
self[key][i].then(callback).catch(reject);
}
else {
callback();
Expand Down Expand Up @@ -982,11 +982,11 @@ Document.prototype._saveMany = function(docToSave, saveAll, savedModel, resolve,
key: key
});
resolve();
}).error(reject);
}).catch(reject);
}

if (self[key][i] instanceof Promise) {
self[key][i].then(callback).error(reject);
self[key][i].then(callback).catch(reject);
}
else {
callback();
Expand All @@ -1002,7 +1002,7 @@ Document.prototype._saveMany = function(docToSave, saveAll, savedModel, resolve,
if (promisesMany.length > 0) {
Promise.all(promisesMany).then(function() {
self._saveLinks(docToSave, saveAll, resolve, reject)
}).error(reject);
}).catch(reject);
}
else {
self._saveLinks(docToSave, saveAll, resolve, reject)
Expand Down Expand Up @@ -1097,7 +1097,7 @@ Document.prototype._saveLinks = function(docToSave, saveAll, resolve, reject) {
self.__proto__._links[joins[key].link][newLink[joins[key].model.getTableName()+"_"+joins[key].rightKey]] = true;
}
resolve();
}).error(reject);
}).catch(reject);
}))
})(key, link);
}
Expand Down Expand Up @@ -1129,7 +1129,7 @@ Document.prototype._saveLinks = function(docToSave, saveAll, resolve, reject) {
if (promisesLink.length > 0) {
Promise.all(promisesLink).then(function() {
resolve(self);
}).error(reject);
}).catch(reject);
}
else {
resolve(self);
Expand Down Expand Up @@ -1410,7 +1410,7 @@ Document.prototype._deleteHook = function(docToDelete, deleteAll, deletedDocs, d
self[key]._delete(docToDelete[key], deleteAll, deletedDocs, true, false).then(function() {
delete self[key];
resolve();
}).error(reject);
}).catch(reject);
}))
})(key);
}
Expand All @@ -1430,7 +1430,7 @@ Document.prototype._deleteHook = function(docToDelete, deleteAll, deletedDocs, d
self[key]._delete(docToDelete[key], deleteAll, deletedDocs, true, false).then(function() {
delete self[key];
resolve();
}).error(reject);
}).catch(reject);
}));
})(key);
}
Expand Down Expand Up @@ -1580,7 +1580,7 @@ Document.prototype._deleteHook = function(docToDelete, deleteAll, deletedDocs, d
self._setUnSaved();
self.emit('deleted', self);
resolve(self);
}).error(reject);
}).catch(reject);
}))
}
// else we don't throw an error, should we?
Expand All @@ -1589,11 +1589,11 @@ Document.prototype._deleteHook = function(docToDelete, deleteAll, deletedDocs, d
var p = new Promise(function(resolve, reject) {
Promise.all(promises).then(function(result) {
resolve(self);
}).error(function(error) {
}).catch(function(error) {
reject(error)
});
})
return p.nodeify(callback);
return p.asCallback(callback);
}

/*
Expand Down Expand Up @@ -1702,8 +1702,8 @@ Document.prototype.purge = function(callback) {
return new Promise(function(resolve, reject) {
Promise.all(promises).then(function() {
resolve(self);
}).error(reject);
}).nodeify(callback);
}).catch(reject);
}).asCallback(callback);
}

Document.prototype.addRelation = function() {
Expand Down
14 changes: 7 additions & 7 deletions lib/feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ Feed.prototype._next = function() {
self.model._parse(data.new_val).then(function(doc) {
doc._setOldValue(data.old_val);
resolve(doc);
}).error(reject);
}).catch(reject);
}
else if (data.old_val != null) { // new_val is null
self.model._parse(data.old_val).then(function(doc) {
doc._setUnSaved();
resolve(doc);
}).error(reject);
}).catch(reject);
}
//else we just drop the change as it's a state/initializing object
}, function(err) {
reject(err);
})
}).error(reject);
}).catch(reject);
});
}

Expand All @@ -64,15 +64,15 @@ Feed.prototype._each = function(callback, onFinish) {
self.model._parse(data.new_val).then(function(doc) {
doc._setOldValue(data.old_val);
callback(null, doc);
}).error(function(err) {
}).catch(function(err) {
callback(err);
});
}
else if (data.old_val != null) { // new_val is null
self.model._parse(data.old_val).then(function(doc) {
doc._setUnSaved();
callback(null, doc);
}).error(function(err) {
}).catch(function(err) {
callback(err);
});
}
Expand Down Expand Up @@ -110,15 +110,15 @@ Feed.prototype._eachCb = function(err, data) {
self.model._parse(data.new_val).then(function(doc) {
doc._setOldValue(data.old_val);
self._eventEmitter.emit('data', doc);
}).error(function(err) {
}).catch(function(err) {
self._eventEmitter.emit('error', err);
});
}
else if (data.old_val !== null) { // new_val is null
self.model._parse(data.old_val).then(function(doc) {
doc._setUnSaved();
self._eventEmitter.emit('data', doc);
}).error(function(err) {
}).catch(function(err) {
self._eventEmitter.emit('error', err);
});
}
Expand Down
40 changes: 20 additions & 20 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Model.prototype.tableReady = function() {
.then(function() {
return r.tableCreate(model._name, model._table).run();
})
.error(function(error) {
.catch(function(error) {
if (error.message.match(/Table `.*` already exists/)) {
return;
}
Expand Down Expand Up @@ -344,7 +344,7 @@ Model.prototype._createIndex = function(name, fn, opts) {
)
.run()
.then(resolve)
.error(function(error) {
.catch(function(error) {
if (error.message.match(/^Index/)) {
// TODO: This regex seems a bit too generous since messages such
// as "Index `id` was not found on table..." will be accepted.
Expand Down Expand Up @@ -627,7 +627,7 @@ Model.prototype.hasAndBelongsToMany = function(joinedModel, fieldDoc, leftKey, r
self._getModel()._indexes[leftKey] = true;
joinedModel._getModel()._indexes[rightKey] = true;
})
.error(function(error) {
.catch(function(error) {
if (error.message.match(/^Index `/)) {
return;
}
Expand Down Expand Up @@ -806,7 +806,7 @@ Model.prototype.save = function(docs, options) {
rejects[i](new Error("An error occurred during the batch insert. Original results:\n"+JSON.stringify(results, null, 2)));
}
}
}).error(reject);
}).catch(reject);
}
};

Expand Down Expand Up @@ -837,12 +837,12 @@ Model.prototype.save = function(docs, options) {
for(var i=0; i<docs.length; i++) {
promises.push(docs[i]._batchSave(executeInsert));
}
Promise.all(promises).then(function() {
mainResolve(docs);
}).error(function(error) {
mainReject(error)
return Promise.all(promises).then(function() {
return mainResolve(docs);
}).catch(function(error) {
return mainReject(error)
});
}).error(function(error) {
}).catch(function(error) {
mainReject(new Errors.ValidationError("One of the documents is not valid. Original error:\n"+error.message))
});
}
Expand Down Expand Up @@ -910,12 +910,12 @@ Model.prototype._parse = function(data, ungroup) {
if (promise instanceof Promise) {
promise.then(function() {
resolve(data)
}).error(reject);
}).catch(reject);
}
else {
resolve(data);
}
}).error(reject);
}).catch(reject);
promises.push(promise);
}
else {
Expand All @@ -933,7 +933,7 @@ Model.prototype._parse = function(data, ungroup) {
if (promises.length > 0) {
Promise.all(promises).then(function() {
resolve(data);
}).error(reject);
}).catch(reject);
}
else {
resolve(data);
Expand Down Expand Up @@ -968,12 +968,12 @@ Model.prototype._parse = function(data, ungroup) {
if (promise instanceof Promise) {
promise.then(function() {
resolve(data)
}).error(reject);
}).catch(reject);
}
else {
resolve(data);
}
}).error(reject);
}).catch(reject);
promises.push(promise);
}
else {
Expand Down Expand Up @@ -1007,12 +1007,12 @@ Model.prototype._parse = function(data, ungroup) {
if (promise instanceof Promise) {
promise.then(function() {
resolve(result)
}).error(reject);
}).catch(reject);
}
else {
resolve(result);
}
}).error(reject);
}).catch(reject);
promises.push(promise);
}
else {
Expand All @@ -1031,7 +1031,7 @@ Model.prototype._parse = function(data, ungroup) {
if (promises.length > 0) {
Promise.all(promises).then(function() {
resolve(result)
}).error(reject);
}).catch(reject);
}
else {
resolve(result);
Expand Down Expand Up @@ -1060,12 +1060,12 @@ Model.prototype._parse = function(data, ungroup) {
if (promise instanceof Promise) {
promise.then(function() {
resolve(newDoc);
}).error(reject);
}).catch(reject);
}
else {
resolve(newDoc);
}
}).error(reject);
}).catch(reject);
}
else {
promise = newDoc.validate();
Expand All @@ -1074,7 +1074,7 @@ Model.prototype._parse = function(data, ungroup) {
if (promise instanceof Promise) {
promise.then(function() {
resolve(newDoc)
}).error(function(err) {
}).catch(function(err) {
reject(err)
});
}
Expand Down
Loading