MCPcopy Create free account
hub / github.com/apache/pouchdb / processKeyValueDocs

Function processKeyValueDocs

lib/index.es.js:8498–8535  ·  view source on GitHub ↗
(metaDoc, kvDocsRes)

Source from the content-addressed store, hash-verified

8496 }
8497
8498 function processKeyValueDocs(metaDoc, kvDocsRes) {
8499 const kvDocs = [];
8500 const oldKeys = new Set();
8501
8502 for (const row of kvDocsRes.rows) {
8503 const doc = row.doc;
8504 if (!doc) { // deleted
8505 continue;
8506 }
8507 kvDocs.push(doc);
8508 oldKeys.add(doc._id);
8509 doc._deleted = !indexableKeysToKeyValues.has(doc._id);
8510 if (!doc._deleted) {
8511 const keyValue = indexableKeysToKeyValues.get(doc._id);
8512 if ('value' in keyValue) {
8513 doc.value = keyValue.value;
8514 }
8515 }
8516 }
8517 const newKeys = mapToKeysArray(indexableKeysToKeyValues);
8518 for (const key of newKeys) {
8519 if (!oldKeys.has(key)) {
8520 // new doc
8521 const kvDoc = {
8522 _id: key
8523 };
8524 const keyValue = indexableKeysToKeyValues.get(key);
8525 if ('value' in keyValue) {
8526 kvDoc.value = keyValue.value;
8527 }
8528 kvDocs.push(kvDoc);
8529 }
8530 }
8531 metaDoc.keys = uniq(newKeys.concat(metaDoc.keys));
8532 kvDocs.push(metaDoc);
8533
8534 return kvDocs;
8535 }
8536
8537 const metaDoc = await getMetaDoc();
8538 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…