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

Function processKeyValueDocs

lib/index-browser.js:8465–8502  ·  view source on GitHub ↗
(metaDoc, kvDocsRes)

Source from the content-addressed store, hash-verified

8463 }
8464
8465 function processKeyValueDocs(metaDoc, kvDocsRes) {
8466 const kvDocs = [];
8467 const oldKeys = new Set();
8468
8469 for (const row of kvDocsRes.rows) {
8470 const doc = row.doc;
8471 if (!doc) { // deleted
8472 continue;
8473 }
8474 kvDocs.push(doc);
8475 oldKeys.add(doc._id);
8476 doc._deleted = !indexableKeysToKeyValues.has(doc._id);
8477 if (!doc._deleted) {
8478 const keyValue = indexableKeysToKeyValues.get(doc._id);
8479 if ('value' in keyValue) {
8480 doc.value = keyValue.value;
8481 }
8482 }
8483 }
8484 const newKeys = mapToKeysArray(indexableKeysToKeyValues);
8485 for (const key of newKeys) {
8486 if (!oldKeys.has(key)) {
8487 // new doc
8488 const kvDoc = {
8489 _id: key
8490 };
8491 const keyValue = indexableKeysToKeyValues.get(key);
8492 if ('value' in keyValue) {
8493 kvDoc.value = keyValue.value;
8494 }
8495 kvDocs.push(kvDoc);
8496 }
8497 }
8498 metaDoc.keys = uniq(newKeys.concat(metaDoc.keys));
8499 kvDocs.push(metaDoc);
8500
8501 return kvDocs;
8502 }
8503
8504 const metaDoc = await getMetaDoc();
8505 const keyValueDocs = await getKeyValueDocs(metaDoc);

Callers 1

getDocsToPersistFunction · 0.70

Calls 4

mapToKeysArrayFunction · 0.70
uniqFunction · 0.70
addMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…