You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pouchdb.apache.org by ja...@apache.org on 2026/02/19 14:35:37 UTC
(pouchdb) branch master updated (7695fac10 -> 1d7c9354f)
This is an automated email from the ASF dual-hosted git repository.
jan pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/pouchdb.git
from 7695fac10 Modernize query planner: use Object.values instead of manual mapping
new 326d582d9 modernize checkpointer with some ES6 syntax
new 392475e49 make updateCheckpoint class method and class methods private
new a22960a7a rewrite methods using async/await and extract initCheckpointDoc helper fn
new 904c5630d refactor: change methods to private by adding '#' prefix
new a8cb8b6b5 revert 0b4e70a78974637fcfe0d874c695251d5b851948
new 1d7c9354f fix getCheckpoint 404 handling on iinitial replication
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../node_modules/pouchdb-checkpointer/src/index.js | 307 ++++++++++-----------
1 file changed, 150 insertions(+), 157 deletions(-)
(pouchdb) 03/06: rewrite methods using async/await and extract initCheckpointDoc helper fn
Posted by ja...@apache.org.
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 a22960a7aec890372b5f9dc09057f86035515777
Author: ems <em...@gmail.com>
AuthorDate: Thu Jan 22 00:41:10 2026 +0100
rewrite methods using async/await and extract initCheckpointDoc helper fn
---
.../node_modules/pouchdb-checkpointer/src/index.js | 200 +++++++++++----------
1 file changed, 102 insertions(+), 98 deletions(-)
diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js b/packages/node_modules/pouchdb-checkpointer/src/index.js
index e455d814a..74253c731 100644
--- a/packages/node_modules/pouchdb-checkpointer/src/index.js
+++ b/packages/node_modules/pouchdb-checkpointer/src/index.js
@@ -33,70 +33,50 @@ class CheckpointerInternal {
}
}
- writeCheckpoint(checkpoint, session) {
- const self = this;
- return this._updateTarget(checkpoint, session).then(function () {
- return self._updateSource(checkpoint, session);
- });
+ async writeCheckpoint(checkpoint, session) {
+ // update target before source every time
+ // because otherwise, compareHistory will pick a too new seq from source
+ // after an error writing a checkpoint to the target
+ await this._updateTarget(checkpoint, session);
+ return this._updateSource(checkpoint, session);
}
- _updateTarget(checkpoint, session) {
+ async _updateTarget(checkpoint, session) {
if (this.opts.writeTargetCheckpoint) {
- return this._updateCheckpoint(this.target, this.id, checkpoint,
+ return await this._updateCheckpoint(this.target, this.id, checkpoint,
session, this.returnValue);
- } else {
- return Promise.resolve(true);
- }
+ } return true;
}
- _updateSource(checkpoint, session) {
+ async _updateSource(checkpoint, session) {
if (this.opts.writeSourceCheckpoint) {
- const self = this;
- return this._updateCheckpoint(this.src, this.id, checkpoint,
- session, this.returnValue)
- .catch(function (err) {
- if (isForbiddenError(err)) {
- self.opts.writeSourceCheckpoint = false;
- return true;
- }
- throw err;
- });
- } else {
- return Promise.resolve(true);
+ try {
+ return await this._updateCheckpoint(this.src, this.id, checkpoint,
+ session, this.returnValue);
+ } catch (err) {
+ if (isForbiddenError(err)) {
+ this.opts.writeSourceCheckpoint = false;
+ return true;
+ }
+ throw err;
+ }
}
}
- _updateCheckpoint(db, id, checkpoint, session, returnValue) {
- return db.get(id).catch(function (err) {
- if (err.status === 404) {
- if (db.adapter === 'http' || db.adapter === 'https') {
- explainError(
- 404, 'PouchDB is just checking if a remote checkpoint exists.'
- );
- }
- return {
- session_id: session,
- _id: id,
- history: [],
- replicator: REPLICATOR,
- version: CHECKPOINT_VERSION
- };
- }
- throw err;
- }).then(function (doc) {
- if (returnValue.cancelled) {
+ async _updateCheckpoint(db, id, checkpoint, session, returnValue) {
+ //retrieve checkpoint doc from db or create a new one
+ const doc = await this._initCheckpointDoc(db, id, session);
+
+ if (returnValue.cancelled) {
return;
}
-
// if the checkpoint has not changed, do not update
if (doc.last_seq === checkpoint) {
return;
}
// Filter out current entry for this replication
- doc.history = (doc.history || []).filter(function (item) {
- return item.session_id !== session;
- });
+ doc.history = (doc.history || []).filter(item => item.session_id !== session);
// Add the latest checkpoint to history
doc.history.unshift({
@@ -115,90 +95,114 @@ class CheckpointerInternal {
doc.session_id = session;
doc.last_seq = checkpoint;
- return db.put(doc).catch(function (err) {
+ try {
+ return await db.put(doc);
+ } catch (err) {
if (err.status === 409) {
// retry; someone is trying to write a checkpoint simultaneously
return this._updateCheckpoint(db, id, checkpoint, session, returnValue);
}
- throw err;
- });
- });
+ throw err;
+ }
}
- getCheckpoint() {
- const self = this;
+ async _initCheckpointDoc(db, id, session) {
+ try {
+ return await db.get(id);
+ } catch (err) {
+ if (err.status === 404) {
+ if (db.adapter === 'http' || db.adapter === 'https') {
+ explainError(
+ 404, 'PouchDB is just checking if a remote checkpoint exists.'
+ );
+ }
+ return {
+ session_id: session,
+ _id: id,
+ history: [],
+ replicator: REPLICATOR,
+ version: CHECKPOINT_VERSION
+ };
+ } else {
+ throw err;
+ }
+ }
+ }
- if (!self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
- return Promise.resolve(LOWEST_SEQ);
+ async getCheckpoint() {
+ if (!this.opts.writeSourceCheckpoint && !this.opts.writeTargetCheckpoint) {
+ return LOWEST_SEQ;
}
- if (self.opts && self.opts.writeSourceCheckpoint && !self.opts.writeTargetCheckpoint) {
- return self.src.get(self.id).then(function (sourceDoc) {
+ if (this.opts && this.opts.writeSourceCheckpoint && !this.opts.writeTargetCheckpoint) {
+ try {
+ const sourceDoc = await this.src.get(this.id);
return sourceDoc.last_seq || LOWEST_SEQ;
- }).catch(function (err) {
+ } catch (err) {
/* istanbul ignore if */
if (err.status !== 404) {
throw err;
}
return LOWEST_SEQ;
- });
- }
-
- return self.target.get(self.id).then(function (targetDoc) {
- if (self.opts && self.opts.writeTargetCheckpoint && !self.opts.writeSourceCheckpoint) {
- return targetDoc.last_seq || LOWEST_SEQ;
}
+ }
- return self.src.get(self.id).then(function (sourceDoc) {
- // Since we can't migrate an old version doc to a new one
- // (no session id), we just go with the lowest seq in this case
- /* istanbul ignore if */
- if (targetDoc.version !== sourceDoc.version) {
+ let targetDoc;
+ try {
+ targetDoc = await this.target.get(this.id);
+ } catch (err) {
+ if (err.status !== 404) {
+ throw err;
+ }
return LOWEST_SEQ;
- }
+ }
- const version = targetDoc.version ? targetDoc.version.toString() : "undefined";
+ if (this.opts && this.opts.writeTargetCheckpoint && !this.opts.writeSourceCheckpoint) {
+ return targetDoc.last_seq || LOWEST_SEQ;
+ }
- if (version in comparisons) {
- return comparisons[version](targetDoc, sourceDoc);
- }
- /* istanbul ignore next */
+ try {
+ const sourceDoc = await this.src.get(this.id);
+ // Since we can't migrate an old version doc to a new one
+ // (no session id), we just go with the lowest seq in this case
+ /* istanbul ignore if */
+ if (targetDoc.version !== sourceDoc.version) {
return LOWEST_SEQ;
- }, function (err) {
- if (err.status === 404 && targetDoc.last_seq) {
- return self.src.put({
- _id: self.id,
+ }
+ const version = targetDoc.version ? targetDoc.version.toString() : "undefined";
+
+ if (version in comparisons) {
+ return comparisons[version](targetDoc, sourceDoc);
+ }
+ /* istanbul ignore next */
+ return LOWEST_SEQ;
+ } catch (err) {
+ if (err.status === 404 && targetDoc.last_seq) {
+ try {
+ await this.src.put({
+ _id: this.id,
last_seq: LOWEST_SEQ
- }).then(function () {
- return LOWEST_SEQ;
- }, function (err) {
- if (isForbiddenError(err)) {
- self.opts.writeSourceCheckpoint = false;
- return targetDoc.last_seq;
- }
- /* istanbul ignore next */
- return LOWEST_SEQ;
});
+ return LOWEST_SEQ;
+ } catch (err) {
+ if (isForbiddenError(err)) {
+ this.opts.writeSourceCheckpoint = false;
+ return targetDoc.last_seq;
+ }
+ /* istanbul ignore next */
+ return LOWEST_SEQ;
}
- throw err;
- });
- }).catch(function (err) {
- if (err.status !== 404) {
- throw err;
}
- return LOWEST_SEQ;
- });
+ throw err;
+ }
}
}
const comparisons = {
"undefined": (targetDoc, sourceDoc) => {
// This is the previous comparison function
- if (collate(targetDoc.last_seq, sourceDoc.last_seq) === 0) {
- return sourceDoc.last_seq;
- }
/* istanbul ignore next */
- return 0;
+ return collate(targetDoc.last_seq, sourceDoc.last_seq) === 0 ? sourceDoc.last_seq : 0;
},
"1": (targetDoc, sourceDoc) => {
// This is the comparison function ported from CouchDB
(pouchdb) 06/06: fix getCheckpoint 404 handling on iinitial replication
Posted by ja...@apache.org.
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 1d7c9354fd3bdbc187326f8b011870f184cb3ff8
Author: ems <em...@gmail.com>
AuthorDate: Thu Jan 22 19:04:56 2026 +0100
fix getCheckpoint 404 handling on iinitial replication
---
packages/node_modules/pouchdb-checkpointer/src/index.js | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js b/packages/node_modules/pouchdb-checkpointer/src/index.js
index 74253c731..68e7fa9eb 100644
--- a/packages/node_modules/pouchdb-checkpointer/src/index.js
+++ b/packages/node_modules/pouchdb-checkpointer/src/index.js
@@ -193,6 +193,10 @@ class CheckpointerInternal {
return LOWEST_SEQ;
}
}
+ //missing sourceDoc on initial replication returns LOWEST_SEQ
+ if (err.status === 404) {
+ return LOWEST_SEQ;
+ }
throw err;
}
}
(pouchdb) 04/06: refactor: change methods to private by adding '#' prefix
Posted by ja...@apache.org.
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 904c5630d251562367f32c6de9e57d6c7d64d6c0
Author: Steven <So...@users.noreply.github.com>
AuthorDate: Thu Jan 22 15:39:46 2026 +0100
refactor: change methods to private by adding '#' prefix
Using "real" private methods
---
.../node_modules/pouchdb-checkpointer/src/index.js | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js b/packages/node_modules/pouchdb-checkpointer/src/index.js
index 74253c731..830638f41 100644
--- a/packages/node_modules/pouchdb-checkpointer/src/index.js
+++ b/packages/node_modules/pouchdb-checkpointer/src/index.js
@@ -37,21 +37,21 @@ class CheckpointerInternal {
// update target before source every time
// because otherwise, compareHistory will pick a too new seq from source
// after an error writing a checkpoint to the target
- await this._updateTarget(checkpoint, session);
- return this._updateSource(checkpoint, session);
+ await this.#updateTarget(checkpoint, session);
+ return this.#updateSource(checkpoint, session);
}
- async _updateTarget(checkpoint, session) {
+ async #updateTarget(checkpoint, session) {
if (this.opts.writeTargetCheckpoint) {
- return await this._updateCheckpoint(this.target, this.id, checkpoint,
+ return await this.#updateCheckpoint(this.target, this.id, checkpoint,
session, this.returnValue);
} return true;
}
- async _updateSource(checkpoint, session) {
+ async #updateSource(checkpoint, session) {
if (this.opts.writeSourceCheckpoint) {
try {
- return await this._updateCheckpoint(this.src, this.id, checkpoint,
+ return await this.#updateCheckpoint(this.src, this.id, checkpoint,
session, this.returnValue);
} catch (err) {
if (isForbiddenError(err)) {
@@ -63,9 +63,9 @@ class CheckpointerInternal {
}
}
- async _updateCheckpoint(db, id, checkpoint, session, returnValue) {
+ async #updateCheckpoint(db, id, checkpoint, session, returnValue) {
//retrieve checkpoint doc from db or create a new one
- const doc = await this._initCheckpointDoc(db, id, session);
+ const doc = await this.#initCheckpointDoc(db, id, session);
if (returnValue.cancelled) {
return;
@@ -100,13 +100,13 @@ class CheckpointerInternal {
} catch (err) {
if (err.status === 409) {
// retry; someone is trying to write a checkpoint simultaneously
- return this._updateCheckpoint(db, id, checkpoint, session, returnValue);
+ return this.#updateCheckpoint(db, id, checkpoint, session, returnValue);
}
throw err;
}
}
- async _initCheckpointDoc(db, id, session) {
+ async #initCheckpointDoc(db, id, session) {
try {
return await db.get(id);
} catch (err) {
(pouchdb) 02/06: make updateCheckpoint class method and class methods private
Posted by ja...@apache.org.
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 392475e498ded1004fadf6efeb149979dd6e9275
Author: ems <em...@gmail.com>
AuthorDate: Thu Jan 22 00:11:02 2026 +0100
make updateCheckpoint class method and class methods private
---
.../node_modules/pouchdb-checkpointer/src/index.js | 130 ++++++++++-----------
1 file changed, 65 insertions(+), 65 deletions(-)
diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js b/packages/node_modules/pouchdb-checkpointer/src/index.js
index a6df3ba05..e455d814a 100644
--- a/packages/node_modules/pouchdb-checkpointer/src/index.js
+++ b/packages/node_modules/pouchdb-checkpointer/src/index.js
@@ -13,65 +13,6 @@ const REPLICATOR = "pouchdb";
const CHECKPOINT_HISTORY_SIZE = 5;
const LOWEST_SEQ = 0;
-function updateCheckpoint(db, id, checkpoint, session, returnValue) {
- return db.get(id).catch(function (err) {
- if (err.status === 404) {
- if (db.adapter === 'http' || db.adapter === 'https') {
- explainError(
- 404, 'PouchDB is just checking if a remote checkpoint exists.'
- );
- }
- return {
- session_id: session,
- _id: id,
- history: [],
- replicator: REPLICATOR,
- version: CHECKPOINT_VERSION
- };
- }
- throw err;
- }).then(function (doc) {
- if (returnValue.cancelled) {
- return;
- }
-
- // if the checkpoint has not changed, do not update
- if (doc.last_seq === checkpoint) {
- return;
- }
-
- // Filter out current entry for this replication
- doc.history = (doc.history || []).filter(function (item) {
- return item.session_id !== session;
- });
-
- // Add the latest checkpoint to history
- doc.history.unshift({
- last_seq: checkpoint,
- session_id: session
- });
-
- // Just take the last pieces in history, to
- // avoid really big checkpoint docs.
- // see comment on history size above
- doc.history = doc.history.slice(0, CHECKPOINT_HISTORY_SIZE);
-
- doc.version = CHECKPOINT_VERSION;
- doc.replicator = REPLICATOR;
-
- doc.session_id = session;
- doc.last_seq = checkpoint;
-
- return db.put(doc).catch(function (err) {
- if (err.status === 409) {
- // retry; someone is trying to write a checkpoint simultaneously
- return updateCheckpoint(db, id, checkpoint, session, returnValue);
- }
- throw err;
- });
- });
-}
-
class CheckpointerInternal {
constructor(src, target, id, returnValue, opts = {
writeSourceCheckpoint: true,
@@ -94,24 +35,24 @@ class CheckpointerInternal {
writeCheckpoint(checkpoint, session) {
const self = this;
- return this.updateTarget(checkpoint, session).then(function () {
- return self.updateSource(checkpoint, session);
+ return this._updateTarget(checkpoint, session).then(function () {
+ return self._updateSource(checkpoint, session);
});
}
- updateTarget(checkpoint, session) {
+ _updateTarget(checkpoint, session) {
if (this.opts.writeTargetCheckpoint) {
- return updateCheckpoint(this.target, this.id, checkpoint,
+ return this._updateCheckpoint(this.target, this.id, checkpoint,
session, this.returnValue);
} else {
return Promise.resolve(true);
}
}
- updateSource(checkpoint, session) {
+ _updateSource(checkpoint, session) {
if (this.opts.writeSourceCheckpoint) {
const self = this;
- return updateCheckpoint(this.src, this.id, checkpoint,
+ return this._updateCheckpoint(this.src, this.id, checkpoint,
session, this.returnValue)
.catch(function (err) {
if (isForbiddenError(err)) {
@@ -125,6 +66,65 @@ class CheckpointerInternal {
}
}
+ _updateCheckpoint(db, id, checkpoint, session, returnValue) {
+ return db.get(id).catch(function (err) {
+ if (err.status === 404) {
+ if (db.adapter === 'http' || db.adapter === 'https') {
+ explainError(
+ 404, 'PouchDB is just checking if a remote checkpoint exists.'
+ );
+ }
+ return {
+ session_id: session,
+ _id: id,
+ history: [],
+ replicator: REPLICATOR,
+ version: CHECKPOINT_VERSION
+ };
+ }
+ throw err;
+ }).then(function (doc) {
+ if (returnValue.cancelled) {
+ return;
+ }
+
+ // if the checkpoint has not changed, do not update
+ if (doc.last_seq === checkpoint) {
+ return;
+ }
+
+ // Filter out current entry for this replication
+ doc.history = (doc.history || []).filter(function (item) {
+ return item.session_id !== session;
+ });
+
+ // Add the latest checkpoint to history
+ doc.history.unshift({
+ last_seq: checkpoint,
+ session_id: session
+ });
+
+ // Just take the last pieces in history, to
+ // avoid really big checkpoint docs.
+ // see comment on history size above
+ doc.history = doc.history.slice(0, CHECKPOINT_HISTORY_SIZE);
+
+ doc.version = CHECKPOINT_VERSION;
+ doc.replicator = REPLICATOR;
+
+ doc.session_id = session;
+ doc.last_seq = checkpoint;
+
+ return db.put(doc).catch(function (err) {
+ if (err.status === 409) {
+ // retry; someone is trying to write a checkpoint simultaneously
+ return this._updateCheckpoint(db, id, checkpoint, session, returnValue);
+ }
+ throw err;
+ });
+ });
+ }
+
getCheckpoint() {
const self = this;
(pouchdb) 01/06: modernize checkpointer with some ES6 syntax
Posted by ja...@apache.org.
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 <em...@gmail.com>
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) {
(pouchdb) 05/06: revert 0b4e70a78974637fcfe0d874c695251d5b851948
Posted by ja...@apache.org.
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 a8cb8b6b547257b455504c2efa3a3309fa46cf83
Author: Steven <So...@users.noreply.github.com>
AuthorDate: Thu Jan 22 15:48:48 2026 +0100
revert 0b4e70a78974637fcfe0d874c695251d5b851948
need an updated linter before this refactor can happen
---
.../node_modules/pouchdb-checkpointer/src/index.js | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/packages/node_modules/pouchdb-checkpointer/src/index.js b/packages/node_modules/pouchdb-checkpointer/src/index.js
index 830638f41..74253c731 100644
--- a/packages/node_modules/pouchdb-checkpointer/src/index.js
+++ b/packages/node_modules/pouchdb-checkpointer/src/index.js
@@ -37,21 +37,21 @@ class CheckpointerInternal {
// update target before source every time
// because otherwise, compareHistory will pick a too new seq from source
// after an error writing a checkpoint to the target
- await this.#updateTarget(checkpoint, session);
- return this.#updateSource(checkpoint, session);
+ await this._updateTarget(checkpoint, session);
+ return this._updateSource(checkpoint, session);
}
- async #updateTarget(checkpoint, session) {
+ async _updateTarget(checkpoint, session) {
if (this.opts.writeTargetCheckpoint) {
- return await this.#updateCheckpoint(this.target, this.id, checkpoint,
+ return await this._updateCheckpoint(this.target, this.id, checkpoint,
session, this.returnValue);
} return true;
}
- async #updateSource(checkpoint, session) {
+ async _updateSource(checkpoint, session) {
if (this.opts.writeSourceCheckpoint) {
try {
- return await this.#updateCheckpoint(this.src, this.id, checkpoint,
+ return await this._updateCheckpoint(this.src, this.id, checkpoint,
session, this.returnValue);
} catch (err) {
if (isForbiddenError(err)) {
@@ -63,9 +63,9 @@ class CheckpointerInternal {
}
}
- async #updateCheckpoint(db, id, checkpoint, session, returnValue) {
+ async _updateCheckpoint(db, id, checkpoint, session, returnValue) {
//retrieve checkpoint doc from db or create a new one
- const doc = await this.#initCheckpointDoc(db, id, session);
+ const doc = await this._initCheckpointDoc(db, id, session);
if (returnValue.cancelled) {
return;
@@ -100,13 +100,13 @@ class CheckpointerInternal {
} catch (err) {
if (err.status === 409) {
// retry; someone is trying to write a checkpoint simultaneously
- return this.#updateCheckpoint(db, id, checkpoint, session, returnValue);
+ return this._updateCheckpoint(db, id, checkpoint, session, returnValue);
}
throw err;
}
}
- async #initCheckpointDoc(db, id, session) {
+ async _initCheckpointDoc(db, id, session) {
try {
return await db.get(id);
} catch (err) {