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

Function writeDoc

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

Source from the content-addressed store, hash-verified

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