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

Function writeDocs

lib/index.es.js:9822–9870  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9820 }
9821
9822 function writeDocs() {
9823 changedDocs = [];
9824
9825 if (currentBatch.docs.length === 0) {
9826 return;
9827 }
9828 var docs = currentBatch.docs;
9829 var bulkOpts = {timeout: opts.timeout};
9830 return target.bulkDocs({docs, new_edits: false}, bulkOpts).then(function (res$$1) {
9831 /* istanbul ignore if */
9832 if (returnValue.cancelled) {
9833 completeReplication();
9834 throw new Error('cancelled');
9835 }
9836
9837 // `res` doesn't include full documents (which live in `docs`), so we create a map of
9838 // (id -> error), and check for errors while iterating over `docs`
9839 var errorsById = Object.create(null);
9840 res$$1.forEach(function (res$$1) {
9841 if (res$$1.error) {
9842 errorsById[res$$1.id] = res$$1;
9843 }
9844 });
9845
9846 var errorsNo = Object.keys(errorsById).length;
9847 result.doc_write_failures += errorsNo;
9848 result.docs_written += docs.length - errorsNo;
9849
9850 docs.forEach(function (doc) {
9851 var error = errorsById[doc._id];
9852 if (error) {
9853 result.errors.push(error);
9854 // Normalize error name. i.e. 'Unauthorized' -> 'unauthorized' (eg Sync Gateway)
9855 var errorName = (error.name || '').toLowerCase();
9856 if (errorName === 'unauthorized' || errorName === 'forbidden') {
9857 returnValue.emit('denied', clone(error));
9858 } else {
9859 throw error;
9860 }
9861 } else {
9862 changedDocs.push(doc);
9863 }
9864 });
9865
9866 }, function (err) {
9867 result.doc_write_failures += docs.length;
9868 throw err;
9869 });
9870 }
9871
9872 function finishBatch() {
9873 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…