()
| 1656 | |
| 1657 | class AbstractPouchDB extends EE { |
| 1658 | _setup() { |
| 1659 | this.post = adapterFun('post', function (doc, opts, callback) { |
| 1660 | if (typeof opts === 'function') { |
| 1661 | callback = opts; |
| 1662 | opts = {}; |
| 1663 | } |
| 1664 | if (isNotSingleDoc(doc)) { |
| 1665 | return callback(createError(NOT_AN_OBJECT)); |
| 1666 | } |
| 1667 | this.bulkDocs({docs: [doc]}, opts, yankError(callback, doc._id)); |
| 1668 | }).bind(this); |
| 1669 | |
| 1670 | this.put = adapterFun('put', function (doc, opts, cb) { |
| 1671 | if (typeof opts === 'function') { |
| 1672 | cb = opts; |
| 1673 | opts = {}; |
| 1674 | } |
| 1675 | if (isNotSingleDoc(doc)) { |
| 1676 | return cb(createError(NOT_AN_OBJECT)); |
| 1677 | } |
| 1678 | invalidIdError(doc._id); |
| 1679 | if ('_rev' in doc && !isValidRev(doc._rev)) { |
| 1680 | return cb(createError(INVALID_REV)); |
| 1681 | } |
| 1682 | if (isLocalId(doc._id) && typeof this._putLocal === 'function') { |
| 1683 | if (doc._deleted) { |
| 1684 | return this._removeLocal(doc, cb); |
| 1685 | } else { |
| 1686 | return this._putLocal(doc, cb); |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | const putDoc = (next) => { |
| 1691 | if (typeof this._put === 'function' && opts.new_edits !== false) { |
| 1692 | this._put(doc, opts, next); |
| 1693 | } else { |
| 1694 | this.bulkDocs({docs: [doc]}, opts, yankError(next, doc._id)); |
| 1695 | } |
| 1696 | }; |
| 1697 | |
| 1698 | if (opts.force && doc._rev) { |
| 1699 | transformForceOptionToNewEditsOption(); |
| 1700 | putDoc(function (err) { |
| 1701 | var result = err ? null : {ok: true, id: doc._id, rev: doc._rev}; |
| 1702 | cb(err, result); |
| 1703 | }); |
| 1704 | } else { |
| 1705 | putDoc(cb); |
| 1706 | } |
| 1707 | |
| 1708 | function transformForceOptionToNewEditsOption() { |
| 1709 | var parts = doc._rev.split('-'); |
| 1710 | var oldRevId = parts[1]; |
| 1711 | var oldRevNum = parseInt(parts[0], 10); |
| 1712 | |
| 1713 | var newRevNum = oldRevNum + 1; |
| 1714 | var newRevId = rev(); |
| 1715 |
nothing calls this directly
no test coverage detected