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

Method getCheckpoint

lib/index-browser.js:9490–9558  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9488 }
9489
9490 getCheckpoint() {
9491 var self = this;
9492
9493 if (!self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
9494 return Promise.resolve(LOWEST_SEQ);
9495 }
9496
9497 if (self.opts && self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
9498 return self.src.get(self.id).then(function (sourceDoc) {
9499 return sourceDoc.last_seq || LOWEST_SEQ;
9500 }).catch(function (err) {
9501 /* istanbul ignore if */
9502 if (err.status !== 404) {
9503 throw err;
9504 }
9505 return LOWEST_SEQ;
9506 });
9507 }
9508
9509 return self.target.get(self.id).then(function (targetDoc) {
9510 if (self.opts && self.opts.writeTargetCheckpoint && !self.opts.writeSourceCheckpoint) {
9511 return targetDoc.last_seq || LOWEST_SEQ;
9512 }
9513
9514 return self.src.get(self.id).then(function (sourceDoc) {
9515 // Since we can't migrate an old version doc to a new one
9516 // (no session id), we just go with the lowest seq in this case
9517 /* istanbul ignore if */
9518 if (targetDoc.version !== sourceDoc.version) {
9519 return LOWEST_SEQ;
9520 }
9521
9522 var version;
9523 if (targetDoc.version) {
9524 version = targetDoc.version.toString();
9525 } else {
9526 version = "undefined";
9527 }
9528
9529 if (version in comparisons) {
9530 return comparisons[version](targetDoc, sourceDoc);
9531 }
9532 /* istanbul ignore next */
9533 return LOWEST_SEQ;
9534 }, function (err) {
9535 if (err.status === 404 && targetDoc.last_seq) {
9536 return self.src.put({
9537 _id: self.id,
9538 last_seq: LOWEST_SEQ
9539 }).then(function () {
9540 return LOWEST_SEQ;
9541 }, function (err) {
9542 if (isForbiddenError(err)) {
9543 self.opts.writeSourceCheckpoint = false;
9544 return targetDoc.last_seq;
9545 }
9546 /* istanbul ignore next */
9547 return LOWEST_SEQ;

Callers 1

startChangesFunction · 0.45

Calls 3

isForbiddenErrorFunction · 0.70
getMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected