@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.
@@ -7541,16 +7541,36 @@ var init_BaseUserDB = __esm({
7541
7541
  // Database to use for write operations (local-first approach)
7542
7542
  updateQueue;
7543
7543
  _hydration = { state: "not-required" };
7544
+ /** In-flight hydration, so concurrent callers can wait for a real answer. */
7545
+ _hydrationPromise = null;
7544
7546
  /**
7545
- * How far the local mirror can be trusted. See {@link UserHydrationStatus}.
7547
+ * How far the local mirror can be trusted, RIGHT NOW. See
7548
+ * {@link UserHydrationStatus}.
7546
7549
  *
7547
- * Consumers that would otherwise read a 404 as "new user" — onboarding
7548
- * gates, first-run experiences, progress dashboards should check for
7549
- * `failed` and present a retry affordance rather than an empty state.
7550
+ * This is a snapshot, and during login it can legitimately read
7551
+ * `hydrating` prefer awaitHydration() anywhere a decision hangs on the
7552
+ * answer.
7550
7553
  */
7551
7554
  hydrationStatus() {
7552
7555
  return { ...this._hydration };
7553
7556
  }
7557
+ /**
7558
+ * The hydration status once it has settled — never `hydrating`.
7559
+ *
7560
+ * Resolves immediately unless a pull is in flight. Exists for callers that
7561
+ * must decide something (a route guard, a first-run branch) and would
7562
+ * otherwise sample `hydrating` and guess. Since init() is awaited by both
7563
+ * app startup and login(), that only happens when something navigates
7564
+ * concurrently with a login still in progress — a window that stretches to
7565
+ * HYDRATION_TIMEOUT_MS on a slow connection.
7566
+ */
7567
+ async awaitHydration() {
7568
+ try {
7569
+ await this._hydrationPromise;
7570
+ } catch {
7571
+ }
7572
+ return this.hydrationStatus();
7573
+ }
7554
7574
  /**
7555
7575
  * Whether a missing document may be treated as genuinely absent, allowing
7556
7576
  * callers to create it with defaults.
@@ -8007,7 +8027,8 @@ Currently logged-in as ${this._username}.`
8007
8027
  }
8008
8028
  this.syncStrategy.stopSync?.();
8009
8029
  this.setDBandQ();
8010
- await this.hydrateLocalMirror();
8030
+ this._hydrationPromise = this.hydrateLocalMirror();
8031
+ await this._hydrationPromise;
8011
8032
  this.syncStrategy.startSync(this.localDB, this.remoteDB);
8012
8033
  this.applyDesignDocs().catch((error) => {
8013
8034
  log3(`Error in applyDesignDocs background task: ${error}`);