@vue-skuilder/db 0.2.12 → 0.2.14

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
@@ -7398,6 +7398,14 @@ var init_CouchDBSyncStrategy = __esm({
7398
7398
  } else {
7399
7399
  logger.info("No documents to migrate from funnel account");
7400
7400
  }
7401
+ try {
7402
+ await oldLocalDB.destroy();
7403
+ logger.info(`Destroyed consumed guest DB for ${oldUsername}`);
7404
+ } catch (destroyErr) {
7405
+ logger.warn(
7406
+ `Failed to destroy consumed guest DB for ${oldUsername} (non-fatal): ${destroyErr instanceof Error ? destroyErr.message : String(destroyErr)}`
7407
+ );
7408
+ }
7401
7409
  return { success: true };
7402
7410
  } catch (error) {
7403
7411
  logger.error("Migration failed:", error);
@@ -7829,6 +7837,11 @@ Currently logged-in as ${this._username}.`
7829
7837
  return { ok: true };
7830
7838
  }
7831
7839
  const ret = await this.syncStrategy.logout();
7840
+ try {
7841
+ localStorage.removeItem("sk-guest-uuid");
7842
+ } catch (e) {
7843
+ logger.warn("localStorage not available (Node.js environment):", e);
7844
+ }
7832
7845
  this._username = await this.syncStrategy.getCurrentUsername();
7833
7846
  await this.init();
7834
7847
  return ret;
@@ -10983,13 +10996,18 @@ var EloService = class {
10983
10996
  logger.warn(`k value interpretation not currently implemented`);
10984
10997
  }
10985
10998
  const courseDB = this.dataLayer.getCourseDB(currentCard.card.course_id);
10986
- const userElo = toCourseElo7(
10987
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo
10988
- );
10999
+ const courseReg = userCourseRegDoc.courses.find((c) => c.courseID === course_id);
11000
+ if (!courseReg) {
11001
+ logger.error(
11002
+ `[EloService] No registration for course ${course_id} on user's registration doc \u2014 skipping ELO update for card ${card_id}. (Is the user registered for this course?)`
11003
+ );
11004
+ return;
11005
+ }
11006
+ const userElo = toCourseElo7(courseReg.elo);
10989
11007
  const cardElo = (await courseDB.getCardEloData([currentCard.card.card_id]))[0];
10990
11008
  if (cardElo && userElo) {
10991
11009
  const eloUpdate = adjustCourseScores(userElo, cardElo, userScore);
10992
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo = eloUpdate.userElo;
11010
+ courseReg.elo = eloUpdate.userElo;
10993
11011
  const results = await Promise.allSettled([
10994
11012
  this.user.updateUserElo(course_id, eloUpdate.userElo),
10995
11013
  courseDB.updateCardElo(card_id, eloUpdate.cardElo)
@@ -11034,9 +11052,14 @@ var EloService = class {
11034
11052
  */
11035
11053
  async updateUserAndCardEloPerTag(taggedPerformance, course_id, card_id, userCourseRegDoc, currentCard) {
11036
11054
  const courseDB = this.dataLayer.getCourseDB(currentCard.card.course_id);
11037
- const userElo = toCourseElo7(
11038
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo
11039
- );
11055
+ const courseReg = userCourseRegDoc.courses.find((c) => c.courseID === course_id);
11056
+ if (!courseReg) {
11057
+ logger.error(
11058
+ `[EloService] No registration for course ${course_id} on user's registration doc \u2014 skipping per-tag ELO update for card ${card_id}. (Is the user registered for this course?)`
11059
+ );
11060
+ return;
11061
+ }
11062
+ const userElo = toCourseElo7(courseReg.elo);
11040
11063
  const [cardEloResults, cardTagsMap] = await Promise.all([
11041
11064
  courseDB.getCardEloData([currentCard.card.card_id]),
11042
11065
  courseDB.getAppliedTagsBatch([card_id])
@@ -11052,7 +11075,7 @@ var EloService = class {
11052
11075
  }
11053
11076
  if (cardElo && userElo) {
11054
11077
  const eloUpdate = adjustCourseScoresPerTag(userElo, cardElo, enriched);
11055
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo = eloUpdate.userElo;
11078
+ courseReg.elo = eloUpdate.userElo;
11056
11079
  const results = await Promise.allSettled([
11057
11080
  this.user.updateUserElo(course_id, eloUpdate.userElo),
11058
11081
  courseDB.updateCardElo(card_id, eloUpdate.cardElo)
@@ -11099,6 +11122,14 @@ var ResponseProcessor = class {
11099
11122
  this.srsService = srsService;
11100
11123
  this.eloService = eloService;
11101
11124
  }
11125
+ /**
11126
+ * ELO updates are fired without awaiting so response handling isn't blocked
11127
+ * on DB writes — but an unhandled rejection silently drops the update.
11128
+ * This produces a catch handler that surfaces the failure in logs.
11129
+ */
11130
+ logEloFailure(context, cardId) {
11131
+ return (e) => logger.error(`[ResponseProcessor] ELO update failed (${context}) for ${cardId}:`, e);
11132
+ }
11102
11133
  /**
11103
11134
  * Parses performance data into global score and optional per-tag scores.
11104
11135
  *
@@ -11216,17 +11247,11 @@ var ResponseProcessor = class {
11216
11247
  cardId,
11217
11248
  courseRegistrationDoc,
11218
11249
  currentCard
11219
- );
11250
+ ).catch(this.logEloFailure("correct per-tag", cardId));
11220
11251
  } else {
11221
11252
  const userScore = 0.5 + globalScore / 2;
11222
11253
  if (history.records.length === 1) {
11223
- void this.eloService.updateUserAndCardElo(
11224
- userScore,
11225
- courseId,
11226
- cardId,
11227
- courseRegistrationDoc,
11228
- currentCard
11229
- );
11254
+ void this.eloService.updateUserAndCardElo(userScore, courseId, cardId, courseRegistrationDoc, currentCard).catch(this.logEloFailure("correct", cardId));
11230
11255
  } else {
11231
11256
  const k = Math.ceil(32 / history.records.length);
11232
11257
  void this.eloService.updateUserAndCardElo(
@@ -11236,7 +11261,7 @@ var ResponseProcessor = class {
11236
11261
  courseRegistrationDoc,
11237
11262
  currentCard,
11238
11263
  k
11239
- );
11264
+ ).catch(this.logEloFailure("correct repeat-view", cardId));
11240
11265
  }
11241
11266
  logger.info(
11242
11267
  `[FirstContactElo] correct first-attempt ELO update (score=${userScore.toFixed(3)}) for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps})`
@@ -11277,7 +11302,7 @@ var ResponseProcessor = class {
11277
11302
  cardId,
11278
11303
  courseRegistrationDoc,
11279
11304
  currentCard
11280
- );
11305
+ ).catch(this.logEloFailure("incorrect per-tag", cardId));
11281
11306
  logger.info(
11282
11307
  `[FirstContactElo] incorrect first-attempt per-tag ELO update for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps}, tags=${Object.keys(taggedPerformance).length - 1})`
11283
11308
  );
@@ -11289,7 +11314,7 @@ var ResponseProcessor = class {
11289
11314
  cardId,
11290
11315
  courseRegistrationDoc,
11291
11316
  currentCard
11292
- );
11317
+ ).catch(this.logEloFailure("incorrect", cardId));
11293
11318
  logger.info(
11294
11319
  `[FirstContactElo] incorrect first-attempt ELO update (score=0) for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps})`
11295
11320
  );
@@ -11310,15 +11335,9 @@ var ResponseProcessor = class {
11310
11335
  cardId,
11311
11336
  courseRegistrationDoc,
11312
11337
  currentCard
11313
- );
11338
+ ).catch(this.logEloFailure("dismiss-failed per-tag", cardId));
11314
11339
  } else {
11315
- void this.eloService.updateUserAndCardElo(
11316
- 0,
11317
- courseId,
11318
- cardId,
11319
- courseRegistrationDoc,
11320
- currentCard
11321
- );
11340
+ void this.eloService.updateUserAndCardElo(0, courseId, cardId, courseRegistrationDoc, currentCard).catch(this.logEloFailure("dismiss-failed", cardId));
11322
11341
  }
11323
11342
  logger.info(
11324
11343
  `[FirstContactElo] dismiss-failed final ELO penalty for ${cardId} (historyLen=${history.records.length}, sessionViews=${sessionViews})`