@vue-skuilder/standalone-ui 0.2.17 → 0.2.18

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.
@@ -24639,6 +24639,7 @@ var init_v4 = __esmMin((() => {
24639
24639
  ENV: () => ENV,
24640
24640
  FileSystemError: () => FileSystemError,
24641
24641
  GuestUsername: () => GuestUsername,
24642
+ HYDRATION_MARKER_ID: () => HYDRATION_MARKER_ID,
24642
24643
  Loggable: () => Loggable,
24643
24644
  NOT_SET: () => NOT_SET,
24644
24645
  NavigatorRole: () => NavigatorRole,
@@ -25791,6 +25792,14 @@ function getStartAndEndKeys2(t) {
25791
25792
  endkey: t + "￰"
25792
25793
  };
25793
25794
  }
25795
+ function withTimeout(t, c, u) {
25796
+ let d;
25797
+ return Promise.race([t, new Promise((t, m) => {
25798
+ d = setTimeout(() => m(/* @__PURE__ */ Error(`${u} timed out after ${c}ms`)), c);
25799
+ })]).finally(() => {
25800
+ d !== void 0 && clearTimeout(d);
25801
+ });
25802
+ }
25794
25803
  function accomodateGuest() {
25795
25804
  if (logger.log("[funnel] accomodateGuest() called"), typeof localStorage > "u") return logger.log("[funnel] localStorage not available (Node.js environment), returning default guest"), {
25796
25805
  username: GuestUsername + "nodejs-test",
@@ -26887,7 +26896,7 @@ function mountSessionDebugger() {
26887
26896
  let t = window;
26888
26897
  t.skuilder = t.skuilder || {}, t.skuilder.session = sessionDebugAPI;
26889
26898
  }
26890
- var import___vite_browser_external, import___vite_browser_external$1, import___vite_browser_external$2, import_browser_ponyfill, import_browser_ponyfill$1, import_browser, _SessionController2, __defProp, __getOwnPropNames, __glob, __esm, __export, init_adminDB, init_classroomDB, init_SyncStrategy, isDevelopment, logger, init_logger, GuestUsername, log, DocType, DocTypePrefixes, init_types_legacy, init_util, pouchdb_setup_default, init_pouchdb_setup, init_dataDirectory, REVIEW_TIME_FORMAT, log2, init_userDBHelpers, Loggable, init_Loggable, UpdateQueue, init_updateQueue, UsrCrsData, init_user_course_relDB, CLIENT_CACHE, init_clientCache, AlreadyTaggedErr, init_courseAPI, courseLookupDBTitle, CourseLookup, init_courseLookupDB, diversityRerank_exports, DIVERSITY_STRENGTH, DIVERSITY_FLOOR, STRATEGY, STRATEGY_ID, STRATEGY_NAME, init_diversityRerank, PipelineDebugger_exports, _activePipeline, MAX_RUNS, runHistory, DISCARDED_KEEP_TOP, _uiContainer, _selectedRunIndex, _cardSearchQuery, pipelineDebugAPI, init_PipelineDebugger, SrsDebugger_exports, snapshots, init_SrsDebugger, StrategyPressureDebugger_exports, snapshots2, init_StrategyPressureDebugger, CompositeGenerator_exports, AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator, init_CompositeGenerator, elo_exports, ELO_RELEVANCE_SIGMA, ELONavigator, init_elo, generators_exports, init_generators, prescribed_exports, DEFAULT_FRESHNESS_WINDOW, DEFAULT_MAX_DIRECT_PER_RUN, DEFAULT_MAX_SUPPORT_PER_RUN, DEFAULT_HIERARCHY_DEPTH, DEFAULT_MIN_COUNT, DEFAULT_PRACTICE_MIN_COUNT, DEFAULT_MAX_PRACTICE_PER_RUN, BASE_TARGET_SCORE, BASE_SUPPORT_SCORE, DISCOVERED_SUPPORT_SCORE, BASE_PRACTICE_SCORE, PRACTICE_BASE_MULT, MAX_PRACTICE_MULTIPLIER, PRACTICE_STALENESS_BUMP_PER_DAY, MAX_TARGET_MULTIPLIER, MAX_SUPPORT_MULTIPLIER, PRESCRIBED_DEBUG_VERSION, PrescribedCardsGenerator, init_prescribed, srs_exports, DEFAULT_HEALTHY_BACKLOG, BACKLOG_GROWTH_RATE, SRSNavigator, init_srs, types_exports, init_types, globImport_generators, init_, DEFAULT_LEARNABLE_WEIGHT, init_contentNavigationStrategy, WeightedFilter_exports, WeightedFilter, init_WeightedFilter, eloDistance_exports, DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER, init_eloDistance, hierarchyDefinition_exports, DEFAULT_MIN_COUNT2, HierarchyDefinitionNavigator, init_hierarchyDefinition, userTagPreference_exports, UserTagPreferenceFilter, init_userTagPreference, filters_exports, init_filters, inferredPreferenceStub_exports, INFERRED_PREFERENCE_NAVIGATOR_STUB, init_inferredPreferenceStub, interferenceMitigator_exports, DEFAULT_MIN_COUNT3, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator, init_interferenceMitigator, relativePriority_exports, DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator, init_relativePriority, types_exports2, init_types2, userGoalStub_exports, USER_GOAL_NAVIGATOR_STUB, init_userGoalStub, globImport_filters, init_2, init_gradient, MIN_OBSERVATIONS_FOR_UPDATE, LEARNING_RATE, MAX_WEIGHT_DELTA, MIN_R_SQUARED_FOR_GRADIENT, FLAT_GRADIENT_THRESHOLD, MAX_HISTORY_LENGTH, init_learning, init_signal, init_recording, MIN_SPREAD, MAX_SPREAD, MIN_WEIGHT, MAX_WEIGHT, init_orchestration, Pipeline_exports, VERBOSE_RESULTS, Pipeline, init_Pipeline, defaults_exports, init_defaults, PipelineAssembler_exports, PipelineAssembler, init_PipelineAssembler, globImport, init_3, navigators_exports, navigatorRegistry, Navigators, NavigatorRole, NavigatorRoles, ContentNavigator, init_navigators, CoursesDB, CourseDB, init_courseDB, classroomLookupDBTitle, CLASSROOM_CONFIG, ClassroomDBBase, StudentClassroomDB, TeacherClassroomDB, ClassroomLookupDB, init_classroomDB2, AdminDB, init_adminDB2, CourseSyncService_exports, DEFAULT_REPLICATION, CourseSyncService, init_CourseSyncService, init_auth, CouchDBSyncStrategy_exports, log3, CouchDBSyncStrategy, init_CouchDBSyncStrategy, isBrowser, GUEST_LOCAL_DB, localUserDB, pouchDBincludeCredentialsConfig, REVIEW_TIME_FORMAT2, init_couch, log4, BaseUser, userCoursesDoc, userClassroomsDoc, init_BaseUserDB, init_common, PouchDataLayerProvider_exports, CouchDataLayerProvider, init_PouchDataLayerProvider, pathUtils, nodeFS, StaticDataUnpacker, init_StaticDataUnpacker, StaticCourseDB, init_courseDB2, StaticCoursesDB, init_coursesDB, NoOpSyncStrategy, init_NoOpSyncStrategy, StaticDataLayerProvider_exports, StaticDataLayerProvider, init_StaticDataLayerProvider, NOT_SET, ENV, dataLayerInstance, init_factory, TagFilteredContentSource, init_TagFilteredContentSource, init_contentSource, init_courseDB3, init_dataLayerProvider, init_userDB, init_interfaces, init_user, init_strategyState, init_userOutcome, init_cardProcessor, init_types3, init_bulkImport, userDBDebugAPI, init_UserDBDebugger, init_core, duration, SrsService, EloService, ResponseProcessor, CardHydrationService, ItemQueue, CouchDBToStaticPacker, DEFAULT_MIGRATION_OPTIONS, FileSystemError, nodeFS2, nodeFS3, nodePath, StaticToCouchDBMigrator, QuotaRoundRobinMixer, MAX_RUNS2, runHistory2, mixerDebugAPI, activeController, OVERLAY_ID, POLL_MS, INLINE_THRESHOLD, SPINNER_FRAMES, spinnerFrame, overlayEl, pollHandle, lastSnapshot, copyFlashUntil, minified, expanded, activeSession, sessionHistory, MAX_HISTORY, sessionDebugAPI, SessionController, init_dist = __esmMin((() => {
26899
+ var import___vite_browser_external, import___vite_browser_external$1, import___vite_browser_external$2, import_browser_ponyfill, import_browser_ponyfill$1, import_browser, _SessionController2, __defProp, __getOwnPropNames, __glob, __esm, __export, init_adminDB, init_classroomDB, init_SyncStrategy, isDevelopment, logger, init_logger, GuestUsername, log, DocType, DocTypePrefixes, init_types_legacy, init_util, pouchdb_setup_default, init_pouchdb_setup, init_dataDirectory, REVIEW_TIME_FORMAT, log2, init_userDBHelpers, Loggable, init_Loggable, UpdateQueue, init_updateQueue, UsrCrsData, init_user_course_relDB, CLIENT_CACHE, init_clientCache, AlreadyTaggedErr, init_courseAPI, courseLookupDBTitle, CourseLookup, init_courseLookupDB, diversityRerank_exports, DIVERSITY_STRENGTH, DIVERSITY_FLOOR, STRATEGY, STRATEGY_ID, STRATEGY_NAME, init_diversityRerank, PipelineDebugger_exports, _activePipeline, MAX_RUNS, runHistory, DISCARDED_KEEP_TOP, _uiContainer, _selectedRunIndex, _cardSearchQuery, pipelineDebugAPI, init_PipelineDebugger, SrsDebugger_exports, snapshots, init_SrsDebugger, StrategyPressureDebugger_exports, snapshots2, init_StrategyPressureDebugger, CompositeGenerator_exports, AggregationMode, DEFAULT_AGGREGATION_MODE, FREQUENCY_BOOST_FACTOR, CompositeGenerator, init_CompositeGenerator, elo_exports, ELO_RELEVANCE_SIGMA, ELONavigator, init_elo, generators_exports, init_generators, prescribed_exports, DEFAULT_FRESHNESS_WINDOW, DEFAULT_MAX_DIRECT_PER_RUN, DEFAULT_MAX_SUPPORT_PER_RUN, DEFAULT_HIERARCHY_DEPTH, DEFAULT_MIN_COUNT, DEFAULT_PRACTICE_MIN_COUNT, DEFAULT_MAX_PRACTICE_PER_RUN, BASE_TARGET_SCORE, BASE_SUPPORT_SCORE, DISCOVERED_SUPPORT_SCORE, BASE_PRACTICE_SCORE, PRACTICE_BASE_MULT, MAX_PRACTICE_MULTIPLIER, PRACTICE_STALENESS_BUMP_PER_DAY, MAX_TARGET_MULTIPLIER, MAX_SUPPORT_MULTIPLIER, PRESCRIBED_DEBUG_VERSION, PrescribedCardsGenerator, init_prescribed, srs_exports, DEFAULT_HEALTHY_BACKLOG, BACKLOG_GROWTH_RATE, SRSNavigator, init_srs, types_exports, init_types, globImport_generators, init_, DEFAULT_LEARNABLE_WEIGHT, init_contentNavigationStrategy, WeightedFilter_exports, WeightedFilter, init_WeightedFilter, eloDistance_exports, DEFAULT_HALF_LIFE, DEFAULT_MIN_MULTIPLIER, DEFAULT_MAX_MULTIPLIER, init_eloDistance, hierarchyDefinition_exports, DEFAULT_MIN_COUNT2, HierarchyDefinitionNavigator, init_hierarchyDefinition, userTagPreference_exports, UserTagPreferenceFilter, init_userTagPreference, filters_exports, init_filters, inferredPreferenceStub_exports, INFERRED_PREFERENCE_NAVIGATOR_STUB, init_inferredPreferenceStub, interferenceMitigator_exports, DEFAULT_MIN_COUNT3, DEFAULT_MIN_ELAPSED_DAYS, DEFAULT_INTERFERENCE_DECAY, InterferenceMitigatorNavigator, init_interferenceMitigator, relativePriority_exports, DEFAULT_PRIORITY, DEFAULT_PRIORITY_INFLUENCE, DEFAULT_COMBINE_MODE, RelativePriorityNavigator, init_relativePriority, types_exports2, init_types2, userGoalStub_exports, USER_GOAL_NAVIGATOR_STUB, init_userGoalStub, globImport_filters, init_2, init_gradient, MIN_OBSERVATIONS_FOR_UPDATE, LEARNING_RATE, MAX_WEIGHT_DELTA, MIN_R_SQUARED_FOR_GRADIENT, FLAT_GRADIENT_THRESHOLD, MAX_HISTORY_LENGTH, init_learning, init_signal, init_recording, MIN_SPREAD, MAX_SPREAD, MIN_WEIGHT, MAX_WEIGHT, init_orchestration, Pipeline_exports, VERBOSE_RESULTS, Pipeline, init_Pipeline, defaults_exports, init_defaults, PipelineAssembler_exports, PipelineAssembler, init_PipelineAssembler, globImport, init_3, navigators_exports, navigatorRegistry, Navigators, NavigatorRole, NavigatorRoles, ContentNavigator, init_navigators, CoursesDB, CourseDB, init_courseDB, classroomLookupDBTitle, CLASSROOM_CONFIG, ClassroomDBBase, StudentClassroomDB, TeacherClassroomDB, ClassroomLookupDB, init_classroomDB2, AdminDB, init_adminDB2, CourseSyncService_exports, DEFAULT_REPLICATION, CourseSyncService, init_CourseSyncService, init_auth, CouchDBSyncStrategy_exports, log3, CouchDBSyncStrategy, init_CouchDBSyncStrategy, isBrowser, GUEST_LOCAL_DB, localUserDB, pouchDBincludeCredentialsConfig, REVIEW_TIME_FORMAT2, init_couch, log4, HYDRATION_TIMEOUT_MS, BaseUser, userCoursesDoc, userClassroomsDoc, init_BaseUserDB, init_common, PouchDataLayerProvider_exports, CouchDataLayerProvider, init_PouchDataLayerProvider, pathUtils, nodeFS, StaticDataUnpacker, init_StaticDataUnpacker, StaticCourseDB, init_courseDB2, StaticCoursesDB, init_coursesDB, NoOpSyncStrategy, init_NoOpSyncStrategy, StaticDataLayerProvider_exports, StaticDataLayerProvider, init_StaticDataLayerProvider, NOT_SET, ENV, dataLayerInstance, init_factory, TagFilteredContentSource, init_TagFilteredContentSource, init_contentSource, init_courseDB3, init_dataLayerProvider, init_userDB, init_interfaces, init_user, init_strategyState, init_userOutcome, HYDRATION_MARKER_ID, init_hydration, init_cardProcessor, init_types3, init_bulkImport, userDBDebugAPI, init_UserDBDebugger, init_core, duration, SrsService, EloService, ResponseProcessor, CardHydrationService, ItemQueue, CouchDBToStaticPacker, DEFAULT_MIGRATION_OPTIONS, FileSystemError, nodeFS2, nodeFS3, nodePath, StaticToCouchDBMigrator, QuotaRoundRobinMixer, MAX_RUNS2, runHistory2, mixerDebugAPI, activeController, OVERLAY_ID, POLL_MS, INLINE_THRESHOLD, SPINNER_FRAMES, spinnerFrame, overlayEl, pollHandle, lastSnapshot, copyFlashUntil, minified, expanded, activeSession, sessionHistory, MAX_HISTORY, sessionDebugAPI, SessionController, init_dist = __esmMin((() => {
26891
26900
  init_defineProperty(), init_index_browser_es$5(), init_index_browser_es(), init_index_es(), import___vite_browser_external = /* @__PURE__ */ __toESM$2(require___vite_browser_external(), 1), import___vite_browser_external$1 = /* @__PURE__ */ __toESM$2(require___vite_browser_external(), 1), import___vite_browser_external$2 = /* @__PURE__ */ __toESM$2(require___vite_browser_external(), 1), init_moment(), init_dist$1(), init_esm_browser(), import_browser_ponyfill = /* @__PURE__ */ __toESM$2(require_browser_ponyfill(), 1), import_browser_ponyfill$1 = /* @__PURE__ */ __toESM$2(require_browser_ponyfill(), 1), import_browser = /* @__PURE__ */ __toESM$2(require_browser(), 1), __defProp = Object.defineProperty, __getOwnPropNames = Object.getOwnPropertyNames, __glob = (t) => (c) => {
26892
26901
  var u = t[c];
26893
26902
  if (u) return u();
@@ -29614,7 +29623,7 @@ ${t.stack}` : JSON.stringify(t);
29614
29623
  logger.info(t);
29615
29624
  }, CouchDBSyncStrategy = class {
29616
29625
  constructor() {
29617
- _defineProperty$2(this, "syncHandle", void 0);
29626
+ _defineProperty$2(this, "syncHandle", void 0), _defineProperty$2(this, "hydrationHandle", void 0);
29618
29627
  }
29619
29628
  setupRemoteDB(t) {
29620
29629
  return t === GuestUsername || t.startsWith(GuestUsername) ? getLocalUserDB(t) : this.getUserDB(t);
@@ -29622,14 +29631,38 @@ ${t.stack}` : JSON.stringify(t);
29622
29631
  getWriteDB(t) {
29623
29632
  return t === GuestUsername || t.startsWith(GuestUsername) ? getLocalUserDB(t) : this.getUserDB(t);
29624
29633
  }
29634
+ async hydrate(t, c) {
29635
+ let u = pouchdb_setup_default.replicate(c, t, {});
29636
+ this.hydrationHandle = u;
29637
+ try {
29638
+ return { docsWritten: (await u).docs_written };
29639
+ } finally {
29640
+ this.hydrationHandle = void 0;
29641
+ }
29642
+ }
29625
29643
  startSync(t, c) {
29626
- t !== c && (this.syncHandle = pouchdb_setup_default.sync(t, c, {
29644
+ t.name !== c.name && (this.syncHandle = pouchdb_setup_default.sync(t, c, {
29627
29645
  live: !0,
29628
29646
  retry: !0
29629
29647
  }));
29630
29648
  }
29631
29649
  stopSync() {
29632
- this.syncHandle && (this.syncHandle.cancel(), this.syncHandle = void 0);
29650
+ if (this.hydrationHandle) {
29651
+ try {
29652
+ this.hydrationHandle.cancel();
29653
+ } catch (t) {
29654
+ logger.warn(`Failed to cancel hydration pull (continuing anyway): ${t}`);
29655
+ }
29656
+ this.hydrationHandle = void 0;
29657
+ }
29658
+ if (this.syncHandle) {
29659
+ try {
29660
+ this.syncHandle.cancel();
29661
+ } catch (t) {
29662
+ logger.warn(`Failed to cancel user sync (continuing anyway): ${t}`);
29663
+ }
29664
+ this.syncHandle = void 0;
29665
+ }
29633
29666
  }
29634
29667
  canCreateAccount() {
29635
29668
  return !0;
@@ -29759,7 +29792,7 @@ ${t.stack}` : JSON.stringify(t);
29759
29792
  var t;
29760
29793
  init_core(), init_util(), init_types_legacy(), init_logger(), init_userDBHelpers(), init_updateQueue(), init_user_course_relDB(), init_couch(), log4 = (t) => {
29761
29794
  logger.info(t);
29762
- }, BaseUser = (t = class _BaseUser {
29795
+ }, HYDRATION_TIMEOUT_MS = 15e3, BaseUser = (t = class _BaseUser {
29763
29796
  static Dummy(t) {
29764
29797
  return new _BaseUser("Me", t);
29765
29798
  }
@@ -29772,6 +29805,12 @@ ${t.stack}` : JSON.stringify(t);
29772
29805
  remote() {
29773
29806
  return this.remoteDB;
29774
29807
  }
29808
+ hydrationStatus() {
29809
+ return { ...this._hydration };
29810
+ }
29811
+ canMaterializeDefaults() {
29812
+ return this._hydration.state !== "failed" && this._hydration.state !== "hydrating";
29813
+ }
29775
29814
  async createAccount(t, c) {
29776
29815
  if (!this.syncStrategy.canCreateAccount()) throw Error("Account creation not supported by current sync strategy");
29777
29816
  if (!this._username.startsWith(GuestUsername)) throw Error(`Cannot create a new account while logged in:
@@ -29854,12 +29893,14 @@ Currently logged-in as ${this._username}.`);
29854
29893
  try {
29855
29894
  return await this.localDB.get(_BaseUser.DOC_IDS.COURSE_REGISTRATIONS);
29856
29895
  } catch (c) {
29857
- if (c.status === 404) await this.localDB.put({
29858
- _id: _BaseUser.DOC_IDS.COURSE_REGISTRATIONS,
29859
- courses: [],
29860
- studyWeight: {}
29861
- }), t = await this.getCourseRegistrationsDoc();
29862
- else throw Error(`Unexpected error ${JSON.stringify(c)} in getOrCreateCourseRegistrationDoc...`);
29896
+ if (c.status === 404) {
29897
+ if (!this.canMaterializeDefaults()) throw Error(`Cannot read course registrations for ${this._username}: the local mirror is unavailable (hydration state '${this._hydration.state}'). Refusing to create an empty registration doc \u2014 that would report an existing user as unregistered, and then lose to their real document once sync resumes.`);
29898
+ await this.localDB.put({
29899
+ _id: _BaseUser.DOC_IDS.COURSE_REGISTRATIONS,
29900
+ courses: [],
29901
+ studyWeight: {}
29902
+ }), t = await this.getCourseRegistrationsDoc();
29903
+ } else throw Error(`Unexpected error ${JSON.stringify(c)} in getOrCreateCourseRegistrationDoc...`);
29863
29904
  }
29864
29905
  return t;
29865
29906
  }
@@ -30002,8 +30043,10 @@ Currently logged-in as ${this._username}.`);
30002
30043
  return logger.debug("Raw config from DB:", t), t;
30003
30044
  } catch (c) {
30004
30045
  let u = c;
30005
- if (u.name && u.name === "not_found") return await this.localDB.put(t), this.getConfig();
30006
- throw logger.error("Error setting user default config:", c), Error(`Error returning the user's configuration: ${JSON.stringify(c)}`);
30046
+ if (u.name && u.name === "not_found") {
30047
+ if (!this.canMaterializeDefaults()) throw Error(`Cannot read config for ${this._username}: the local mirror is unavailable (hydration state '${this._hydration.state}'). Refusing to write a default config over what may be an existing one.`);
30048
+ return await this.localDB.put(t), this.getConfig();
30049
+ } else throw logger.error("Error setting user default config:", c), Error(`Error returning the user's configuration: ${JSON.stringify(c)}`);
30007
30050
  }
30008
30051
  }
30009
30052
  async setConfig(t) {
@@ -30023,7 +30066,7 @@ Currently logged-in as ${this._username}.`);
30023
30066
  }) : (_BaseUser._instance = new _BaseUser(await t.getCurrentUsername(), t), await _BaseUser._instance.init(), _BaseUser._instance);
30024
30067
  }
30025
30068
  constructor(t, c) {
30026
- _defineProperty$2(this, "_username", void 0), _defineProperty$2(this, "syncStrategy", void 0), _defineProperty$2(this, "localDB", void 0), _defineProperty$2(this, "remoteDB", void 0), _defineProperty$2(this, "writeDB", void 0), _defineProperty$2(this, "updateQueue", void 0), _BaseUser._initialized = !1, this._username = t, this.syncStrategy = c, this.setDBandQ();
30069
+ _defineProperty$2(this, "_username", void 0), _defineProperty$2(this, "syncStrategy", void 0), _defineProperty$2(this, "localDB", void 0), _defineProperty$2(this, "remoteDB", void 0), _defineProperty$2(this, "writeDB", void 0), _defineProperty$2(this, "updateQueue", void 0), _defineProperty$2(this, "_hydration", { state: "not-required" }), _BaseUser._initialized = !1, this._username = t, this.syncStrategy = c, this.setDBandQ();
30027
30070
  }
30028
30071
  setDBandQ() {
30029
30072
  this.localDB = getLocalUserDB(this._username), this.remoteDB = this.syncStrategy.setupRemoteDB(this._username), this.writeDB = this.syncStrategy.getWriteDB ? this.syncStrategy.getWriteDB(this._username) : this.localDB, this.updateQueue = new UpdateQueue(this.localDB, this.writeDB);
@@ -30033,12 +30076,61 @@ Currently logged-in as ${this._username}.`);
30033
30076
  _BaseUser._initialized = !0;
30034
30077
  return;
30035
30078
  }
30036
- this.setDBandQ(), this.syncStrategy.startSync(this.localDB, this.remoteDB), this.applyDesignDocs().catch((t) => {
30079
+ this.syncStrategy.stopSync?.(), this.setDBandQ(), await this.hydrateLocalMirror(), this.syncStrategy.startSync(this.localDB, this.remoteDB), this.applyDesignDocs().catch((t) => {
30037
30080
  log4(`Error in applyDesignDocs background task: ${t}`), t && typeof t == "object" && log4(`Full error details in applyDesignDocs: ${JSON.stringify(t)}`);
30038
30081
  }), this.deduplicateReviews().catch((t) => {
30039
30082
  log4(`Error in deduplicateReviews background task: ${t}`), t && typeof t == "object" && log4(`Full error details in background task: ${JSON.stringify(t)}`);
30040
30083
  }), _BaseUser._initialized = !0;
30041
30084
  }
30085
+ async hydrateLocalMirror() {
30086
+ if (this.localDB.name === this.remoteDB.name || !this.syncStrategy.hydrate) {
30087
+ this._hydration = { state: "not-required" };
30088
+ return;
30089
+ }
30090
+ if (await this.hasHydrationMarker()) {
30091
+ this._hydration = { state: "stale" };
30092
+ return;
30093
+ }
30094
+ this._hydration = { state: "hydrating" };
30095
+ let t = Date.now();
30096
+ try {
30097
+ let { docsWritten: c } = await withTimeout(this.syncStrategy.hydrate(this.localDB, this.remoteDB), HYDRATION_TIMEOUT_MS, `Hydration of local mirror for ${this._username}`);
30098
+ await this.writeHydrationMarker(), this._hydration = {
30099
+ state: "hydrated",
30100
+ docsWritten: c,
30101
+ durationMs: Date.now() - t
30102
+ }, log4(`Hydrated local mirror for ${this._username}: ${c} docs in ${this._hydration.durationMs}ms`);
30103
+ } catch (c) {
30104
+ this.syncStrategy.stopSync?.(), this._hydration = {
30105
+ state: "failed",
30106
+ durationMs: Date.now() - t,
30107
+ error: c instanceof Error ? c.message : String(c)
30108
+ }, logger.error(`Failed to hydrate local mirror for ${this._username}:`, c);
30109
+ }
30110
+ }
30111
+ async hasHydrationMarker() {
30112
+ try {
30113
+ return (await this.localDB.get(HYDRATION_MARKER_ID)).username === this._username;
30114
+ } catch {
30115
+ return !1;
30116
+ }
30117
+ }
30118
+ async writeHydrationMarker() {
30119
+ try {
30120
+ let t;
30121
+ try {
30122
+ t = (await this.localDB.get(HYDRATION_MARKER_ID))._rev;
30123
+ } catch {}
30124
+ await this.localDB.put({
30125
+ _id: HYDRATION_MARKER_ID,
30126
+ _rev: t,
30127
+ username: this._username,
30128
+ hydratedAt: (/* @__PURE__ */ new Date()).toISOString()
30129
+ });
30130
+ } catch (t) {
30131
+ logger.warn(`Could not write hydration marker for ${this._username}: ${t}`);
30132
+ }
30133
+ }
30042
30134
  async applyDesignDocs() {
30043
30135
  if (log4(`Starting applyDesignDocs for user: ${this._username}`), log4(`Remote DB name: ${this.remoteDB.name || "unknown"}`), this._username === "admin") {
30044
30136
  log4("Skipping design docs for admin user");
@@ -30218,7 +30310,10 @@ Currently logged-in as ${this._username}.`);
30218
30310
  try {
30219
30311
  return (await this.localDB.get(u)).data;
30220
30312
  } catch (t) {
30221
- if (t.status === 404) return null;
30313
+ if (t.status === 404) {
30314
+ if (!this.canMaterializeDefaults()) throw Error(`Cannot read strategy state '${c}' for ${this._username}: the local mirror is unavailable (hydration state '${this._hydration.state}').`);
30315
+ return null;
30316
+ }
30222
30317
  throw t;
30223
30318
  }
30224
30319
  }
@@ -31020,7 +31115,9 @@ Currently logged-in as ${this._username}.`);
31020
31115
  init_factory(), init_classroomDB2(), init_TagFilteredContentSource();
31021
31116
  } }), init_courseDB3 = __esm({ "src/core/interfaces/courseDB.ts"() {} }), init_dataLayerProvider = __esm({ "src/core/interfaces/dataLayerProvider.ts"() {} }), init_userDB = __esm({ "src/core/interfaces/userDB.ts"() {} }), init_interfaces = __esm({ "src/core/interfaces/index.ts"() {
31022
31117
  init_adminDB(), init_classroomDB(), init_contentSource(), init_courseDB3(), init_dataLayerProvider(), init_userDB();
31023
- } }), init_user = __esm({ "src/core/types/user.ts"() {} }), init_strategyState = __esm({ "src/core/types/strategyState.ts"() {} }), init_userOutcome = __esm({ "src/core/types/userOutcome.ts"() {} }), init_cardProcessor = __esm({ "src/core/bulkImport/cardProcessor.ts"() {
31118
+ } }), init_user = __esm({ "src/core/types/user.ts"() {} }), init_strategyState = __esm({ "src/core/types/strategyState.ts"() {} }), init_userOutcome = __esm({ "src/core/types/userOutcome.ts"() {} }), init_hydration = __esm({ "src/core/types/hydration.ts"() {
31119
+ HYDRATION_MARKER_ID = "_local/hydration";
31120
+ } }), init_cardProcessor = __esm({ "src/core/bulkImport/cardProcessor.ts"() {
31024
31121
  init_logger();
31025
31122
  } }), init_types3 = __esm({ "src/core/bulkImport/types.ts"() {} }), init_bulkImport = __esm({ "src/core/bulkImport/index.ts"() {
31026
31123
  init_cardProcessor(), init_types3();
@@ -31195,7 +31292,7 @@ ${c.id}:`), logger.info(JSON.stringify(c.doc, null, 2));
31195
31292
  }
31196
31293
  }, mountUserDBDebugger();
31197
31294
  } }), init_core = __esm({ "src/core/index.ts"() {
31198
- init_interfaces(), init_types_legacy(), init_user(), init_strategyState(), init_userOutcome(), init_Loggable(), init_util(), init_navigators(), init_bulkImport(), init_orchestration(), init_UserDBDebugger();
31295
+ init_interfaces(), init_types_legacy(), init_user(), init_strategyState(), init_userOutcome(), init_hydration(), init_Loggable(), init_util(), init_navigators(), init_bulkImport(), init_orchestration(), init_UserDBDebugger();
31199
31296
  } }), init_core(), init_courseLookupDB(), init_logger(), init_couch(), init_util(), init_logger(), duration = hooks.duration, init_logger(), SrsService = class {
31200
31297
  constructor(t) {
31201
31298
  _defineProperty$2(this, "user", void 0), this.user = t;