MCPcopy
hub / github.com/apache/pouchdb / writeDoc

Function writeDoc

lib/index.es.js:5459–5573  ·  view source on GitHub ↗
(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
                      isUpdate, delta, resultsIdx, callback2)

Source from the content-addressed store, hash-verified

5457 }
5458
5459 function writeDoc(docInfo, winningRev$$1, winningRevIsDeleted, newRevIsDeleted,
5460 isUpdate, delta, resultsIdx, callback2) {
5461 docCountDelta += delta;
5462
5463 var err = null;
5464 var recv = 0;
5465
5466 docInfo.metadata.winningRev = winningRev$$1;
5467 docInfo.metadata.deleted = winningRevIsDeleted;
5468
5469 docInfo.data._id = docInfo.metadata.id;
5470 docInfo.data._rev = docInfo.metadata.rev;
5471
5472 if (newRevIsDeleted) {
5473 docInfo.data._deleted = true;
5474 }
5475
5476 if (docInfo.stemmedRevs.length) {
5477 stemmedRevs.set(docInfo.metadata.id, docInfo.stemmedRevs);
5478 }
5479
5480 var attachments = docInfo.data._attachments ?
5481 Object.keys(docInfo.data._attachments) :
5482 [];
5483
5484 function attachmentSaved(attachmentErr) {
5485 recv++;
5486 if (!err) {
5487 /* istanbul ignore if */
5488 if (attachmentErr) {
5489 err = attachmentErr;
5490 callback2(err);
5491 } else if (recv === attachments.length) {
5492 finish();
5493 }
5494 }
5495 }
5496
5497 function onMD5Load(doc, key, data, attachmentSaved) {
5498 return function (result) {
5499 saveAttachment(doc, MD5_PREFIX + result, key, data, attachmentSaved);
5500 };
5501 }
5502
5503 function doMD5(doc, key, attachmentSaved) {
5504 return function (data) {
5505 binaryMd5(data, onMD5Load(doc, key, data, attachmentSaved));
5506 };
5507 }
5508
5509 for (var i = 0; i < attachments.length; i++) {
5510 var key = attachments[i];
5511 var att = docInfo.data._attachments[key];
5512
5513 if (att.stub) {
5514 // still need to update the refs mapping
5515 var id = docInfo.data._id;
5516 var rev$$1 = docInfo.data._rev;

Callers 2

updateDocFunction · 0.70
insertDocFunction · 0.70

Calls 6

saveAttachmentRefsFunction · 0.70
thisAtobFunction · 0.70
createErrorFunction · 0.70
doMD5Function · 0.70
finishFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…