MCPcopy Index your code
hub / github.com/apache/pouchdb / writeDocs

Function writeDocs

lib/index-browser.js:9793–9841  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9791 }
9792
9793 function writeDocs() {
9794 changedDocs = [];
9795
9796 if (currentBatch.docs.length === 0) {
9797 return;
9798 }
9799 var docs = currentBatch.docs;
9800 var bulkOpts = {timeout: opts.timeout};
9801 return target.bulkDocs({docs, new_edits: false}, bulkOpts).then(function (res) {
9802 /* istanbul ignore if */
9803 if (returnValue.cancelled) {
9804 completeReplication();
9805 throw new Error('cancelled');
9806 }
9807
9808 // `res` doesn't include full documents (which live in `docs`), so we create a map of
9809 // (id -> error), and check for errors while iterating over `docs`
9810 var errorsById = Object.create(null);
9811 res.forEach(function (res) {
9812 if (res.error) {
9813 errorsById[res.id] = res;
9814 }
9815 });
9816
9817 var errorsNo = Object.keys(errorsById).length;
9818 result.doc_write_failures += errorsNo;
9819 result.docs_written += docs.length - errorsNo;
9820
9821 docs.forEach(function (doc) {
9822 var error = errorsById[doc._id];
9823 if (error) {
9824 result.errors.push(error);
9825 // Normalize error name. i.e. 'Unauthorized' -> 'unauthorized' (eg Sync Gateway)
9826 var errorName = (error.name || '').toLowerCase();
9827 if (errorName === 'unauthorized' || errorName === 'forbidden') {
9828 returnValue.emit('denied', clone(error));
9829 } else {
9830 throw error;
9831 }
9832 } else {
9833 changedDocs.push(doc);
9834 }
9835 });
9836
9837 }, function (err) {
9838 result.doc_write_failures += docs.length;
9839 throw err;
9840 });
9841 }
9842
9843 function finishBatch() {
9844 if (currentBatch.error) {

Callers

nothing calls this directly

Calls 2

completeReplicationFunction · 0.70
cloneFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…