@vue-skuilder/db 0.2.19 → 0.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -48,17 +48,23 @@ interface SyncStrategy {
48
48
  *
49
49
  * @param localDB The local PouchDB instance
50
50
  * @param remoteDB The remote PouchDB instance
51
- * @returns Count of documents written locally
51
+ * @returns Count of documents written locally, and — only when the pull is
52
+ * known to have landed the remote's complete current state — the sequence
53
+ * it corresponds to, for startSync() to resume from. Omitted means "no
54
+ * safe shortcut, walk from the checkpoint".
52
55
  */
53
56
  hydrate?(localDB: PouchDB.Database, remoteDB: PouchDB.Database): Promise<{
54
57
  docsWritten: number;
58
+ lastSeq?: string | number;
55
59
  }>;
56
60
  /**
57
61
  * Start synchronization between local and remote databases
58
62
  * @param localDB The local PouchDB instance
59
63
  * @param remoteDB The remote PouchDB instance
64
+ * @param since Sequence to start the pull from, as returned by a hydrate()
65
+ * in the same session. Omit to resume from the stored checkpoint.
60
66
  */
61
- startSync(localDB: PouchDB.Database, remoteDB: PouchDB.Database): void;
67
+ startSync(localDB: PouchDB.Database, remoteDB: PouchDB.Database, since?: string | number): void;
62
68
  /**
63
69
  * Stop synchronization (optional - for cleanup)
64
70
  */
@@ -48,17 +48,23 @@ interface SyncStrategy {
48
48
  *
49
49
  * @param localDB The local PouchDB instance
50
50
  * @param remoteDB The remote PouchDB instance
51
- * @returns Count of documents written locally
51
+ * @returns Count of documents written locally, and — only when the pull is
52
+ * known to have landed the remote's complete current state — the sequence
53
+ * it corresponds to, for startSync() to resume from. Omitted means "no
54
+ * safe shortcut, walk from the checkpoint".
52
55
  */
53
56
  hydrate?(localDB: PouchDB.Database, remoteDB: PouchDB.Database): Promise<{
54
57
  docsWritten: number;
58
+ lastSeq?: string | number;
55
59
  }>;
56
60
  /**
57
61
  * Start synchronization between local and remote databases
58
62
  * @param localDB The local PouchDB instance
59
63
  * @param remoteDB The remote PouchDB instance
64
+ * @param since Sequence to start the pull from, as returned by a hydrate()
65
+ * in the same session. Omit to resume from the stored checkpoint.
60
66
  */
61
- startSync(localDB: PouchDB.Database, remoteDB: PouchDB.Database): void;
67
+ startSync(localDB: PouchDB.Database, remoteDB: PouchDB.Database, since?: string | number): void;
62
68
  /**
63
69
  * Stop synchronization (optional - for cleanup)
64
70
  */
@@ -6921,6 +6921,14 @@ var init_BaseUserDB = __esm({
6921
6921
  _hydration = { state: "not-required" };
6922
6922
  /** In-flight hydration, so concurrent callers can wait for a real answer. */
6923
6923
  _hydrationPromise = null;
6924
+ /**
6925
+ * Sequence the local mirror was filled to by a hydration that succeeded in
6926
+ * THIS init(), handed to startSync() so the live pull can skip history it
6927
+ * would otherwise re-walk. Undefined whenever there is no such guarantee —
6928
+ * hydration skipped, not required, or failed. Never persisted; see the
6929
+ * `since` note in CouchDBSyncStrategy.startSync().
6930
+ */
6931
+ _hydratedSeq;
6924
6932
  /**
6925
6933
  * How far the local mirror can be trusted, RIGHT NOW. See
6926
6934
  * {@link UserHydrationStatus}.
@@ -7407,7 +7415,7 @@ Currently logged-in as ${this._username}.`
7407
7415
  this.setDBandQ();
7408
7416
  this._hydrationPromise = this.hydrateLocalMirror();
7409
7417
  await this._hydrationPromise;
7410
- this.syncStrategy.startSync(this.localDB, this.remoteDB);
7418
+ this.syncStrategy.startSync(this.localDB, this.remoteDB, this._hydratedSeq);
7411
7419
  this.applyDesignDocs().catch((error) => {
7412
7420
  log3(`Error in applyDesignDocs background task: ${error}`);
7413
7421
  if (error && typeof error === "object") {
@@ -7435,6 +7443,7 @@ Currently logged-in as ${this._username}.`
7435
7443
  * ceiling). Callers decide what a failure means for them.
7436
7444
  */
7437
7445
  async hydrateLocalMirror() {
7446
+ this._hydratedSeq = void 0;
7438
7447
  if (this.localDB.name === this.remoteDB.name || !this.syncStrategy.hydrate) {
7439
7448
  this._hydration = { state: "not-required" };
7440
7449
  return;
@@ -7446,11 +7455,12 @@ Currently logged-in as ${this._username}.`
7446
7455
  this._hydration = { state: "hydrating" };
7447
7456
  const start = Date.now();
7448
7457
  try {
7449
- const { docsWritten } = await withTimeout(
7458
+ const { docsWritten, lastSeq } = await withTimeout(
7450
7459
  this.syncStrategy.hydrate(this.localDB, this.remoteDB),
7451
7460
  HYDRATION_TIMEOUT_MS,
7452
7461
  `Hydration of local mirror for ${this._username}`
7453
7462
  );
7463
+ this._hydratedSeq = lastSeq;
7454
7464
  await this.writeHydrationMarker();
7455
7465
  this._hydration = {
7456
7466
  state: "hydrated",