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

Method getCheckpoint

lib/index-browser.es.js:9486–9554  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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