Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function updateOne (state, idOrDoc, change, prefix) {
var doc
if (typeof idOrDoc === 'string' && !change) {
return Promise.reject(PouchDBErrors.NOT_AN_OBJECT)
}
return findOne(state, idOrDoc, prefix)
.then(function (doc) {
if (!change) {
return assign(doc, idOrDoc, {_id: doc._id, _rev: doc._rev, hoodie: doc.hoodie})
}
return changeObject(state, change, doc)
})
.then(function (_doc) {
doc = _doc
return put(state, addTimestamps(doc))
})
function addOne (state, doc, prefix) {
if (typeof doc !== 'object') {
return Promise.reject(PouchDBErrors.NOT_AN_OBJECT)
}
doc = clone(doc)
if (!doc._id) {
doc._id = uuid()
}
if (prefix) {
doc._id = prefix + doc._id
}
delete doc.hoodie
return validate(state, doc)
return docs.map(function (doc, index) {
var passedDoc = array[index]
if (doc instanceof Error) {
return doc
}
if (typeof passedDoc !== 'object') {
return PouchDBErrors.NOT_AN_OBJECT
}
return assign(doc, passedDoc, {_id: doc._id, _rev: doc._rev, hoodie: doc.hoodie})
})
})