This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pouchdb.git

commit 326d582d9a73cc4419ed0db27434cc7e0784a521
Author: ems <[email protected]>
AuthorDate: Thu Jan 22 00:00:30 2026 +0100

    modernize checkpointer with some ES6 syntax
---
 .../node_modules/pouchdb-checkpointer/src/index.js | 47 ++++++++--------------
 1 file changed, 16 insertions(+), 31 deletions(-)

diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js 
b/packages/node_modules/pouchdb-checkpointer/src/index.js
index 54e3e014b..a6df3ba05 100644
--- a/packages/node_modules/pouchdb-checkpointer/src/index.js
+++ b/packages/node_modules/pouchdb-checkpointer/src/index.js
@@ -1,8 +1,8 @@
 import { explainError } from 'pouchdb-utils';
 import { collate } from 'pouchdb-collate';
 
-var CHECKPOINT_VERSION = 1;
-var REPLICATOR = "pouchdb";
+const CHECKPOINT_VERSION = 1;
+const REPLICATOR = "pouchdb";
 // This is an arbitrary number to limit the
 // amount of replication history we save in the checkpoint.
 // If we save too much, the checkpoint docs will become very big,
@@ -10,8 +10,8 @@ var REPLICATOR = "pouchdb";
 // read all the changes from 0 when checkpoint PUTs fail
 // CouchDB 2.0 has a more involved history pruning,
 // but let's go for the simple version for now.
-var CHECKPOINT_HISTORY_SIZE = 5;
-var LOWEST_SEQ = 0;
+const CHECKPOINT_HISTORY_SIZE = 5;
+const LOWEST_SEQ = 0;
 
 function updateCheckpoint(db, id, checkpoint, session, returnValue) {
   return db.get(id).catch(function (err) {
@@ -93,7 +93,7 @@ class CheckpointerInternal {
   }
 
   writeCheckpoint(checkpoint, session) {
-    var self = this;
+    const self = this;
     return this.updateTarget(checkpoint, session).then(function () {
       return self.updateSource(checkpoint, session);
     });
@@ -110,7 +110,7 @@ class CheckpointerInternal {
 
   updateSource(checkpoint, session) {
     if (this.opts.writeSourceCheckpoint) {
-      var self = this;
+      const self = this;
       return updateCheckpoint(this.src, this.id, checkpoint,
         session, this.returnValue)
         .catch(function (err) {
@@ -126,7 +126,7 @@ class CheckpointerInternal {
   }
 
   getCheckpoint() {
-    var self = this;
+    const self = this;
 
     if (!self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
       return Promise.resolve(LOWEST_SEQ);
@@ -157,12 +157,7 @@ class CheckpointerInternal {
           return LOWEST_SEQ;
         }
 
-        var version;
-        if (targetDoc.version) {
-          version = targetDoc.version.toString();
-        } else {
-          version = "undefined";
-        }
+        const version = targetDoc.version ? targetDoc.version.toString() : 
"undefined";
 
         if (version in comparisons) {
           return comparisons[version](targetDoc, sourceDoc);
@@ -196,8 +191,8 @@ class CheckpointerInternal {
   }
 }
 
-var comparisons = {
-  "undefined": function (targetDoc, sourceDoc) {
+const comparisons = {
+  "undefined": (targetDoc, sourceDoc) => {
     // This is the previous comparison function
     if (collate(targetDoc.last_seq, sourceDoc.last_seq) === 0) {
       return sourceDoc.last_seq;
@@ -205,7 +200,7 @@ var comparisons = {
     /* istanbul ignore next */
     return 0;
   },
-  "1": function (targetDoc, sourceDoc) {
+  "1": (targetDoc, sourceDoc) => {
     // This is the comparison function ported from CouchDB
     return compareReplicationLogs(sourceDoc, targetDoc).last_seq;
   }
@@ -229,10 +224,8 @@ function compareReplicationLogs(srcDoc, tgtDoc) {
 function compareReplicationHistory(sourceHistory, targetHistory) {
   // the erlang loop via function arguments is not so easy to repeat in JS
   // therefore, doing this as recursion
-  var S = sourceHistory[0];
-  var sourceRest = sourceHistory.slice(1);
-  var T = targetHistory[0];
-  var targetRest = targetHistory.slice(1);
+  const [S, ...sourceRest] = sourceHistory;
+  const [T, ...targetRest] = targetHistory;
 
   if (!S || targetHistory.length === 0) {
     return {
@@ -241,7 +234,7 @@ function compareReplicationHistory(sourceHistory, 
targetHistory) {
     };
   }
 
-  var sourceId = S.session_id;
+  const sourceId = S.session_id;
   /* istanbul ignore if */
   if (hasSessionId(sourceId, targetHistory)) {
     return {
@@ -250,7 +243,7 @@ function compareReplicationHistory(sourceHistory, 
targetHistory) {
     };
   }
 
-  var targetId = T.session_id;
+  const targetId = T.session_id;
   if (hasSessionId(targetId, sourceRest)) {
     return {
       last_seq: T.last_seq,
@@ -262,18 +255,10 @@ function compareReplicationHistory(sourceHistory, 
targetHistory) {
 }
 
 function hasSessionId(sessionId, history) {
-  var props = history[0];
-  var rest = history.slice(1);
-
   if (!sessionId || history.length === 0) {
     return false;
   }
-
-  if (sessionId === props.session_id) {
-    return true;
-  }
-
-  return hasSessionId(sessionId, rest);
+  return history.some(entry => entry.session_id === sessionId);
 }
 
 function isForbiddenError(err) {

Reply via email to