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

Method getCheckpoint

lib/index.es.js:9519–9587  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9517 }
9518
9519 getCheckpoint() {
9520 var self = this;
9521
9522 if (!self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
9523 return Promise.resolve(LOWEST_SEQ);
9524 }
9525
9526 if (self.opts && self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
9527 return self.src.get(self.id).then(function (sourceDoc) {
9528 return sourceDoc.last_seq || LOWEST_SEQ;
9529 }).catch(function (err) {
9530 /* istanbul ignore if */
9531 if (err.status !== 404) {
9532 throw err;
9533 }
9534 return LOWEST_SEQ;
9535 });
9536 }
9537
9538 return self.target.get(self.id).then(function (targetDoc) {
9539 if (self.opts && self.opts.writeTargetCheckpoint && !self.opts.writeSourceCheckpoint) {
9540 return targetDoc.last_seq || LOWEST_SEQ;
9541 }
9542
9543 return self.src.get(self.id).then(function (sourceDoc) {
9544 // Since we can't migrate an old version doc to a new one
9545 // (no session id), we just go with the lowest seq in this case
9546 /* istanbul ignore if */
9547 if (targetDoc.version !== sourceDoc.version) {
9548 return LOWEST_SEQ;
9549 }
9550
9551 var version;
9552 if (targetDoc.version) {
9553 version = targetDoc.version.toString();
9554 } else {
9555 version = "undefined";
9556 }
9557
9558 if (version in comparisons) {
9559 return comparisons[version](targetDoc, sourceDoc);
9560 }
9561 /* istanbul ignore next */
9562 return LOWEST_SEQ;
9563 }, function (err) {
9564 if (err.status === 404 && targetDoc.last_seq) {
9565 return self.src.put({
9566 _id: self.id,
9567 last_seq: LOWEST_SEQ
9568 }).then(function () {
9569 return LOWEST_SEQ;
9570 }, function (err) {
9571 if (isForbiddenError(err)) {
9572 self.opts.writeSourceCheckpoint = false;
9573 return targetDoc.last_seq;
9574 }
9575 /* istanbul ignore next */
9576 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