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

Function parseDoc

lib/index.es.js:4568–4646  ·  view source on GitHub ↗
(doc, newEdits, dbOpts)

Source from the content-addressed store, hash-verified

4566// Preprocess documents, parse their revisions, assign an id and a
4567// revision for new writes that are missing them, etc
4568function parseDoc(doc, newEdits, dbOpts) {
4569 if (!dbOpts) {
4570 dbOpts = {
4571 deterministic_revs: true
4572 };
4573 }
4574
4575 var nRevNum;
4576 var newRevId;
4577 var revInfo;
4578 var opts = {status: 'available'};
4579 if (doc._deleted) {
4580 opts.deleted = true;
4581 }
4582
4583 if (newEdits) {
4584 if (!doc._id) {
4585 doc._id = uuid();
4586 }
4587 newRevId = rev(doc, dbOpts.deterministic_revs);
4588 if (doc._rev) {
4589 revInfo = parseRevisionInfo(doc._rev);
4590 if (revInfo.error) {
4591 return revInfo;
4592 }
4593 doc._rev_tree = [{
4594 pos: revInfo.prefix,
4595 ids: [revInfo.id, {status: 'missing'}, [[newRevId, opts, []]]]
4596 }];
4597 nRevNum = revInfo.prefix + 1;
4598 } else {
4599 doc._rev_tree = [{
4600 pos: 1,
4601 ids : [newRevId, opts, []]
4602 }];
4603 nRevNum = 1;
4604 }
4605 } else {
4606 if (doc._revisions) {
4607 doc._rev_tree = makeRevTreeFromRevisions(doc._revisions, opts);
4608 nRevNum = doc._revisions.start;
4609 newRevId = doc._revisions.ids[0];
4610 }
4611 if (!doc._rev_tree) {
4612 revInfo = parseRevisionInfo(doc._rev);
4613 if (revInfo.error) {
4614 return revInfo;
4615 }
4616 nRevNum = revInfo.prefix;
4617 newRevId = revInfo.id;
4618 doc._rev_tree = [{
4619 pos: nRevNum,
4620 ids: [newRevId, opts, []]
4621 }];
4622 }
4623 }
4624
4625 invalidIdError(doc._id);

Callers 2

updateDocFunction · 0.70
LevelPouchFunction · 0.70

Calls 5

revFunction · 0.70
parseRevisionInfoFunction · 0.70
makeRevTreeFromRevisionsFunction · 0.70
invalidIdErrorFunction · 0.70
createErrorFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…