Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
txn.get(stores.localStore, doc._id, function (err, resp) {
if (err) {
/* istanbul ignore if */
if (err.name !== 'NotFoundError') {
return callback(err);
} else {
return callback(pouchdbErrors.createError(pouchdbErrors.MISSING_DOC));
}
}
if (resp._rev !== doc._rev) {
return callback(pouchdbErrors.createError(pouchdbErrors.REV_CONFLICT));
}
txn.batch([{
prefix: stores.localStore,
type: 'del',
key: doc._id
}]);
var ret = {ok: true, id: doc._id, rev: '0-0'};
if (opts.ctx) {
// don't execute immediately
return callback(null, ret);
}
txn.execute(db, function (err) {
/* istanbul ignore if */
if (err) {
return callback(err);
}
txn.get(stores.localStore, doc._id, function (err, resp) {
if (err) {
/* istanbul ignore if */
if (err.name !== 'NotFoundError') {
return callback(err);
} else {
return callback(pouchdbErrors.createError(pouchdbErrors.MISSING_DOC));
}
}
if (resp._rev !== doc._rev) {
return callback(pouchdbErrors.createError(pouchdbErrors.REV_CONFLICT));
}
txn.batch([{
prefix: stores.localStore,
type: 'del',
key: doc._id
}]);
var ret = {ok: true, id: doc._id, rev: '0-0'};
if (opts.ctx) {
// don't execute immediately
return callback(null, ret);
}
txn.execute(db, function (err) {
/* istanbul ignore if */
if (err) {
return callback(err);
}