@vue-skuilder/db 0.2.18 → 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.
- package/dist/{SyncStrategy-BJMZq3WO.d.cts → SyncStrategy-CCU1H81I.d.cts} +8 -2
- package/dist/{SyncStrategy-BJMZq3WO.d.ts → SyncStrategy-CCU1H81I.d.ts} +8 -2
- package/dist/{contentSource-CudEz5Tm.d.ts → contentSource-BDRX_YYJ.d.ts} +13 -1
- package/dist/{contentSource-CBqZCoGU.d.cts → contentSource-D-LQYFyx.d.cts} +13 -1
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +38 -7
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +38 -7
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-BBA8tJNx.d.cts → dataLayerProvider-Dd2UcCif.d.cts} +1 -1
- package/dist/{dataLayerProvider-C9WgkBzR.d.ts → dataLayerProvider-Dpshuql4.d.ts} +1 -1
- package/dist/impl/couch/index.d.cts +20 -4
- package/dist/impl/couch/index.d.ts +20 -4
- package/dist/impl/couch/index.js +80 -11
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +80 -11
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +3 -3
- package/dist/impl/static/index.d.ts +3 -3
- package/dist/impl/static/index.js +38 -7
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +38 -7
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +80 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/core/interfaces/userDB.ts +14 -1
- package/src/impl/common/BaseUserDB.ts +56 -8
- package/src/impl/common/SyncStrategy.ts +17 -4
- package/src/impl/couch/CouchDBSyncStrategy.ts +52 -4
- package/tests/impl/hydration.test.ts +49 -0
package/dist/core/index.mjs
CHANGED
|
@@ -6899,16 +6899,44 @@ var init_BaseUserDB = __esm({
|
|
|
6899
6899
|
// Database to use for write operations (local-first approach)
|
|
6900
6900
|
updateQueue;
|
|
6901
6901
|
_hydration = { state: "not-required" };
|
|
6902
|
+
/** In-flight hydration, so concurrent callers can wait for a real answer. */
|
|
6903
|
+
_hydrationPromise = null;
|
|
6902
6904
|
/**
|
|
6903
|
-
*
|
|
6905
|
+
* Sequence the local mirror was filled to by a hydration that succeeded in
|
|
6906
|
+
* THIS init(), handed to startSync() so the live pull can skip history it
|
|
6907
|
+
* would otherwise re-walk. Undefined whenever there is no such guarantee —
|
|
6908
|
+
* hydration skipped, not required, or failed. Never persisted; see the
|
|
6909
|
+
* `since` note in CouchDBSyncStrategy.startSync().
|
|
6910
|
+
*/
|
|
6911
|
+
_hydratedSeq;
|
|
6912
|
+
/**
|
|
6913
|
+
* How far the local mirror can be trusted, RIGHT NOW. See
|
|
6914
|
+
* {@link UserHydrationStatus}.
|
|
6904
6915
|
*
|
|
6905
|
-
*
|
|
6906
|
-
*
|
|
6907
|
-
*
|
|
6916
|
+
* This is a snapshot, and during login it can legitimately read
|
|
6917
|
+
* `hydrating` — prefer awaitHydration() anywhere a decision hangs on the
|
|
6918
|
+
* answer.
|
|
6908
6919
|
*/
|
|
6909
6920
|
hydrationStatus() {
|
|
6910
6921
|
return { ...this._hydration };
|
|
6911
6922
|
}
|
|
6923
|
+
/**
|
|
6924
|
+
* The hydration status once it has settled — never `hydrating`.
|
|
6925
|
+
*
|
|
6926
|
+
* Resolves immediately unless a pull is in flight. Exists for callers that
|
|
6927
|
+
* must decide something (a route guard, a first-run branch) and would
|
|
6928
|
+
* otherwise sample `hydrating` and guess. Since init() is awaited by both
|
|
6929
|
+
* app startup and login(), that only happens when something navigates
|
|
6930
|
+
* concurrently with a login still in progress — a window that stretches to
|
|
6931
|
+
* HYDRATION_TIMEOUT_MS on a slow connection.
|
|
6932
|
+
*/
|
|
6933
|
+
async awaitHydration() {
|
|
6934
|
+
try {
|
|
6935
|
+
await this._hydrationPromise;
|
|
6936
|
+
} catch {
|
|
6937
|
+
}
|
|
6938
|
+
return this.hydrationStatus();
|
|
6939
|
+
}
|
|
6912
6940
|
/**
|
|
6913
6941
|
* Whether a missing document may be treated as genuinely absent, allowing
|
|
6914
6942
|
* callers to create it with defaults.
|
|
@@ -7365,8 +7393,9 @@ Currently logged-in as ${this._username}.`
|
|
|
7365
7393
|
}
|
|
7366
7394
|
this.syncStrategy.stopSync?.();
|
|
7367
7395
|
this.setDBandQ();
|
|
7368
|
-
|
|
7369
|
-
|
|
7396
|
+
this._hydrationPromise = this.hydrateLocalMirror();
|
|
7397
|
+
await this._hydrationPromise;
|
|
7398
|
+
this.syncStrategy.startSync(this.localDB, this.remoteDB, this._hydratedSeq);
|
|
7370
7399
|
this.applyDesignDocs().catch((error) => {
|
|
7371
7400
|
log3(`Error in applyDesignDocs background task: ${error}`);
|
|
7372
7401
|
if (error && typeof error === "object") {
|
|
@@ -7394,6 +7423,7 @@ Currently logged-in as ${this._username}.`
|
|
|
7394
7423
|
* ceiling). Callers decide what a failure means for them.
|
|
7395
7424
|
*/
|
|
7396
7425
|
async hydrateLocalMirror() {
|
|
7426
|
+
this._hydratedSeq = void 0;
|
|
7397
7427
|
if (this.localDB.name === this.remoteDB.name || !this.syncStrategy.hydrate) {
|
|
7398
7428
|
this._hydration = { state: "not-required" };
|
|
7399
7429
|
return;
|
|
@@ -7405,11 +7435,12 @@ Currently logged-in as ${this._username}.`
|
|
|
7405
7435
|
this._hydration = { state: "hydrating" };
|
|
7406
7436
|
const start = Date.now();
|
|
7407
7437
|
try {
|
|
7408
|
-
const { docsWritten } = await withTimeout(
|
|
7438
|
+
const { docsWritten, lastSeq } = await withTimeout(
|
|
7409
7439
|
this.syncStrategy.hydrate(this.localDB, this.remoteDB),
|
|
7410
7440
|
HYDRATION_TIMEOUT_MS,
|
|
7411
7441
|
`Hydration of local mirror for ${this._username}`
|
|
7412
7442
|
);
|
|
7443
|
+
this._hydratedSeq = lastSeq;
|
|
7413
7444
|
await this.writeHydrationMarker();
|
|
7414
7445
|
this._hydration = {
|
|
7415
7446
|
state: "hydrated",
|