@vue-skuilder/db 0.2.18 → 0.2.19

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/index.mjs CHANGED
@@ -7896,16 +7896,36 @@ var init_BaseUserDB = __esm({
7896
7896
  // Database to use for write operations (local-first approach)
7897
7897
  updateQueue;
7898
7898
  _hydration = { state: "not-required" };
7899
+ /** In-flight hydration, so concurrent callers can wait for a real answer. */
7900
+ _hydrationPromise = null;
7899
7901
  /**
7900
- * How far the local mirror can be trusted. See {@link UserHydrationStatus}.
7902
+ * How far the local mirror can be trusted, RIGHT NOW. See
7903
+ * {@link UserHydrationStatus}.
7901
7904
  *
7902
- * Consumers that would otherwise read a 404 as "new user" — onboarding
7903
- * gates, first-run experiences, progress dashboards should check for
7904
- * `failed` and present a retry affordance rather than an empty state.
7905
+ * This is a snapshot, and during login it can legitimately read
7906
+ * `hydrating` prefer awaitHydration() anywhere a decision hangs on the
7907
+ * answer.
7905
7908
  */
7906
7909
  hydrationStatus() {
7907
7910
  return { ...this._hydration };
7908
7911
  }
7912
+ /**
7913
+ * The hydration status once it has settled — never `hydrating`.
7914
+ *
7915
+ * Resolves immediately unless a pull is in flight. Exists for callers that
7916
+ * must decide something (a route guard, a first-run branch) and would
7917
+ * otherwise sample `hydrating` and guess. Since init() is awaited by both
7918
+ * app startup and login(), that only happens when something navigates
7919
+ * concurrently with a login still in progress — a window that stretches to
7920
+ * HYDRATION_TIMEOUT_MS on a slow connection.
7921
+ */
7922
+ async awaitHydration() {
7923
+ try {
7924
+ await this._hydrationPromise;
7925
+ } catch {
7926
+ }
7927
+ return this.hydrationStatus();
7928
+ }
7909
7929
  /**
7910
7930
  * Whether a missing document may be treated as genuinely absent, allowing
7911
7931
  * callers to create it with defaults.
@@ -8362,7 +8382,8 @@ Currently logged-in as ${this._username}.`
8362
8382
  }
8363
8383
  this.syncStrategy.stopSync?.();
8364
8384
  this.setDBandQ();
8365
- await this.hydrateLocalMirror();
8385
+ this._hydrationPromise = this.hydrateLocalMirror();
8386
+ await this._hydrationPromise;
8366
8387
  this.syncStrategy.startSync(this.localDB, this.remoteDB);
8367
8388
  this.applyDesignDocs().catch((error) => {
8368
8389
  log4(`Error in applyDesignDocs background task: ${error}`);