@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.
@@ -5601,16 +5601,36 @@ 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
- * How far the local mirror can be trusted. See {@link UserHydrationStatus}.
5607
+ * How far the local mirror can be trusted, RIGHT NOW. See
5608
+ * {@link UserHydrationStatus}.
5606
5609
  *
5607
- * Consumers that would otherwise read a 404 as "new user" — onboarding
5608
- * gates, first-run experiences, progress dashboards should check for
5609
- * `failed` and present a retry affordance rather than an empty state.
5610
+ * This is a snapshot, and during login it can legitimately read
5611
+ * `hydrating` prefer awaitHydration() anywhere a decision hangs on the
5612
+ * answer.
5610
5613
  */
5611
5614
  hydrationStatus() {
5612
5615
  return { ...this._hydration };
5613
5616
  }
5617
+ /**
5618
+ * The hydration status once it has settled — never `hydrating`.
5619
+ *
5620
+ * Resolves immediately unless a pull is in flight. Exists for callers that
5621
+ * must decide something (a route guard, a first-run branch) and would
5622
+ * otherwise sample `hydrating` and guess. Since init() is awaited by both
5623
+ * app startup and login(), that only happens when something navigates
5624
+ * concurrently with a login still in progress — a window that stretches to
5625
+ * HYDRATION_TIMEOUT_MS on a slow connection.
5626
+ */
5627
+ async awaitHydration() {
5628
+ try {
5629
+ await this._hydrationPromise;
5630
+ } catch {
5631
+ }
5632
+ return this.hydrationStatus();
5633
+ }
5614
5634
  /**
5615
5635
  * Whether a missing document may be treated as genuinely absent, allowing
5616
5636
  * callers to create it with defaults.
@@ -6067,7 +6087,8 @@ Currently logged-in as ${this._username}.`
6067
6087
  }
6068
6088
  this.syncStrategy.stopSync?.();
6069
6089
  this.setDBandQ();
6070
- await this.hydrateLocalMirror();
6090
+ this._hydrationPromise = this.hydrateLocalMirror();
6091
+ await this._hydrationPromise;
6071
6092
  this.syncStrategy.startSync(this.localDB, this.remoteDB);
6072
6093
  this.applyDesignDocs().catch((error) => {
6073
6094
  log3(`Error in applyDesignDocs background task: ${error}`);