@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
|
@@ -5601,16 +5601,44 @@ var init_BaseUserDB = __esm({
|
|
|
5601
5601
|
// Database to use for write operations (local-first approach)
|
|
5602
5602
|
updateQueue;
|
|
5603
5603
|
_hydration = { state: "not-required" };
|
|
5604
|
+
/** In-flight hydration, so concurrent callers can wait for a real answer. */
|
|
5605
|
+
_hydrationPromise = null;
|
|
5604
5606
|
/**
|
|
5605
|
-
*
|
|
5607
|
+
* Sequence the local mirror was filled to by a hydration that succeeded in
|
|
5608
|
+
* THIS init(), handed to startSync() so the live pull can skip history it
|
|
5609
|
+
* would otherwise re-walk. Undefined whenever there is no such guarantee —
|
|
5610
|
+
* hydration skipped, not required, or failed. Never persisted; see the
|
|
5611
|
+
* `since` note in CouchDBSyncStrategy.startSync().
|
|
5612
|
+
*/
|
|
5613
|
+
_hydratedSeq;
|
|
5614
|
+
/**
|
|
5615
|
+
* How far the local mirror can be trusted, RIGHT NOW. See
|
|
5616
|
+
* {@link UserHydrationStatus}.
|
|
5606
5617
|
*
|
|
5607
|
-
*
|
|
5608
|
-
*
|
|
5609
|
-
*
|
|
5618
|
+
* This is a snapshot, and during login it can legitimately read
|
|
5619
|
+
* `hydrating` — prefer awaitHydration() anywhere a decision hangs on the
|
|
5620
|
+
* answer.
|
|
5610
5621
|
*/
|
|
5611
5622
|
hydrationStatus() {
|
|
5612
5623
|
return { ...this._hydration };
|
|
5613
5624
|
}
|
|
5625
|
+
/**
|
|
5626
|
+
* The hydration status once it has settled — never `hydrating`.
|
|
5627
|
+
*
|
|
5628
|
+
* Resolves immediately unless a pull is in flight. Exists for callers that
|
|
5629
|
+
* must decide something (a route guard, a first-run branch) and would
|
|
5630
|
+
* otherwise sample `hydrating` and guess. Since init() is awaited by both
|
|
5631
|
+
* app startup and login(), that only happens when something navigates
|
|
5632
|
+
* concurrently with a login still in progress — a window that stretches to
|
|
5633
|
+
* HYDRATION_TIMEOUT_MS on a slow connection.
|
|
5634
|
+
*/
|
|
5635
|
+
async awaitHydration() {
|
|
5636
|
+
try {
|
|
5637
|
+
await this._hydrationPromise;
|
|
5638
|
+
} catch {
|
|
5639
|
+
}
|
|
5640
|
+
return this.hydrationStatus();
|
|
5641
|
+
}
|
|
5614
5642
|
/**
|
|
5615
5643
|
* Whether a missing document may be treated as genuinely absent, allowing
|
|
5616
5644
|
* callers to create it with defaults.
|
|
@@ -6067,8 +6095,9 @@ Currently logged-in as ${this._username}.`
|
|
|
6067
6095
|
}
|
|
6068
6096
|
this.syncStrategy.stopSync?.();
|
|
6069
6097
|
this.setDBandQ();
|
|
6070
|
-
|
|
6071
|
-
|
|
6098
|
+
this._hydrationPromise = this.hydrateLocalMirror();
|
|
6099
|
+
await this._hydrationPromise;
|
|
6100
|
+
this.syncStrategy.startSync(this.localDB, this.remoteDB, this._hydratedSeq);
|
|
6072
6101
|
this.applyDesignDocs().catch((error) => {
|
|
6073
6102
|
log3(`Error in applyDesignDocs background task: ${error}`);
|
|
6074
6103
|
if (error && typeof error === "object") {
|
|
@@ -6096,6 +6125,7 @@ Currently logged-in as ${this._username}.`
|
|
|
6096
6125
|
* ceiling). Callers decide what a failure means for them.
|
|
6097
6126
|
*/
|
|
6098
6127
|
async hydrateLocalMirror() {
|
|
6128
|
+
this._hydratedSeq = void 0;
|
|
6099
6129
|
if (this.localDB.name === this.remoteDB.name || !this.syncStrategy.hydrate) {
|
|
6100
6130
|
this._hydration = { state: "not-required" };
|
|
6101
6131
|
return;
|
|
@@ -6107,11 +6137,12 @@ Currently logged-in as ${this._username}.`
|
|
|
6107
6137
|
this._hydration = { state: "hydrating" };
|
|
6108
6138
|
const start = Date.now();
|
|
6109
6139
|
try {
|
|
6110
|
-
const { docsWritten } = await withTimeout(
|
|
6140
|
+
const { docsWritten, lastSeq } = await withTimeout(
|
|
6111
6141
|
this.syncStrategy.hydrate(this.localDB, this.remoteDB),
|
|
6112
6142
|
HYDRATION_TIMEOUT_MS,
|
|
6113
6143
|
`Hydration of local mirror for ${this._username}`
|
|
6114
6144
|
);
|
|
6145
|
+
this._hydratedSeq = lastSeq;
|
|
6115
6146
|
await this.writeHydrationMarker();
|
|
6116
6147
|
this._hydration = {
|
|
6117
6148
|
state: "hydrated",
|