@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.d.cts CHANGED
@@ -70,6 +70,12 @@ declare class ResponseProcessor {
70
70
  private srsService;
71
71
  private eloService;
72
72
  constructor(srsService: SrsService, eloService: EloService);
73
+ /**
74
+ * ELO updates are fired without awaiting so response handling isn't blocked
75
+ * on DB writes — but an unhandled rejection silently drops the update.
76
+ * This produces a catch handler that surfaces the failure in logs.
77
+ */
78
+ private logEloFailure;
73
79
  /**
74
80
  * Parses performance data into global score and optional per-tag scores.
75
81
  *
package/dist/index.d.ts CHANGED
@@ -70,6 +70,12 @@ declare class ResponseProcessor {
70
70
  private srsService;
71
71
  private eloService;
72
72
  constructor(srsService: SrsService, eloService: EloService);
73
+ /**
74
+ * ELO updates are fired without awaiting so response handling isn't blocked
75
+ * on DB writes — but an unhandled rejection silently drops the update.
76
+ * This produces a catch handler that surfaces the failure in logs.
77
+ */
78
+ private logEloFailure;
73
79
  /**
74
80
  * Parses performance data into global score and optional per-tag scores.
75
81
  *
package/dist/index.js CHANGED
@@ -7417,6 +7417,14 @@ var init_CouchDBSyncStrategy = __esm({
7417
7417
  } else {
7418
7418
  logger.info("No documents to migrate from funnel account");
7419
7419
  }
7420
+ try {
7421
+ await oldLocalDB.destroy();
7422
+ logger.info(`Destroyed consumed guest DB for ${oldUsername}`);
7423
+ } catch (destroyErr) {
7424
+ logger.warn(
7425
+ `Failed to destroy consumed guest DB for ${oldUsername} (non-fatal): ${destroyErr instanceof Error ? destroyErr.message : String(destroyErr)}`
7426
+ );
7427
+ }
7420
7428
  return { success: true };
7421
7429
  } catch (error) {
7422
7430
  logger.error("Migration failed:", error);
@@ -7848,6 +7856,11 @@ Currently logged-in as ${this._username}.`
7848
7856
  return { ok: true };
7849
7857
  }
7850
7858
  const ret = await this.syncStrategy.logout();
7859
+ try {
7860
+ localStorage.removeItem("sk-guest-uuid");
7861
+ } catch (e) {
7862
+ logger.warn("localStorage not available (Node.js environment):", e);
7863
+ }
7851
7864
  this._username = await this.syncStrategy.getCurrentUsername();
7852
7865
  await this.init();
7853
7866
  return ret;
@@ -11096,13 +11109,18 @@ var EloService = class {
11096
11109
  logger.warn(`k value interpretation not currently implemented`);
11097
11110
  }
11098
11111
  const courseDB = this.dataLayer.getCourseDB(currentCard.card.course_id);
11099
- const userElo = (0, import_common23.toCourseElo)(
11100
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo
11101
- );
11112
+ const courseReg = userCourseRegDoc.courses.find((c) => c.courseID === course_id);
11113
+ if (!courseReg) {
11114
+ logger.error(
11115
+ `[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?)`
11116
+ );
11117
+ return;
11118
+ }
11119
+ const userElo = (0, import_common23.toCourseElo)(courseReg.elo);
11102
11120
  const cardElo = (await courseDB.getCardEloData([currentCard.card.card_id]))[0];
11103
11121
  if (cardElo && userElo) {
11104
11122
  const eloUpdate = (0, import_common23.adjustCourseScores)(userElo, cardElo, userScore);
11105
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo = eloUpdate.userElo;
11123
+ courseReg.elo = eloUpdate.userElo;
11106
11124
  const results = await Promise.allSettled([
11107
11125
  this.user.updateUserElo(course_id, eloUpdate.userElo),
11108
11126
  courseDB.updateCardElo(card_id, eloUpdate.cardElo)
@@ -11147,9 +11165,14 @@ var EloService = class {
11147
11165
  */
11148
11166
  async updateUserAndCardEloPerTag(taggedPerformance, course_id, card_id, userCourseRegDoc, currentCard) {
11149
11167
  const courseDB = this.dataLayer.getCourseDB(currentCard.card.course_id);
11150
- const userElo = (0, import_common23.toCourseElo)(
11151
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo
11152
- );
11168
+ const courseReg = userCourseRegDoc.courses.find((c) => c.courseID === course_id);
11169
+ if (!courseReg) {
11170
+ logger.error(
11171
+ `[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?)`
11172
+ );
11173
+ return;
11174
+ }
11175
+ const userElo = (0, import_common23.toCourseElo)(courseReg.elo);
11153
11176
  const [cardEloResults, cardTagsMap] = await Promise.all([
11154
11177
  courseDB.getCardEloData([currentCard.card.card_id]),
11155
11178
  courseDB.getAppliedTagsBatch([card_id])
@@ -11165,7 +11188,7 @@ var EloService = class {
11165
11188
  }
11166
11189
  if (cardElo && userElo) {
11167
11190
  const eloUpdate = (0, import_common23.adjustCourseScoresPerTag)(userElo, cardElo, enriched);
11168
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo = eloUpdate.userElo;
11191
+ courseReg.elo = eloUpdate.userElo;
11169
11192
  const results = await Promise.allSettled([
11170
11193
  this.user.updateUserElo(course_id, eloUpdate.userElo),
11171
11194
  courseDB.updateCardElo(card_id, eloUpdate.cardElo)
@@ -11212,6 +11235,14 @@ var ResponseProcessor = class {
11212
11235
  this.srsService = srsService;
11213
11236
  this.eloService = eloService;
11214
11237
  }
11238
+ /**
11239
+ * ELO updates are fired without awaiting so response handling isn't blocked
11240
+ * on DB writes — but an unhandled rejection silently drops the update.
11241
+ * This produces a catch handler that surfaces the failure in logs.
11242
+ */
11243
+ logEloFailure(context, cardId) {
11244
+ return (e) => logger.error(`[ResponseProcessor] ELO update failed (${context}) for ${cardId}:`, e);
11245
+ }
11215
11246
  /**
11216
11247
  * Parses performance data into global score and optional per-tag scores.
11217
11248
  *
@@ -11329,17 +11360,11 @@ var ResponseProcessor = class {
11329
11360
  cardId,
11330
11361
  courseRegistrationDoc,
11331
11362
  currentCard
11332
- );
11363
+ ).catch(this.logEloFailure("correct per-tag", cardId));
11333
11364
  } else {
11334
11365
  const userScore = 0.5 + globalScore / 2;
11335
11366
  if (history.records.length === 1) {
11336
- void this.eloService.updateUserAndCardElo(
11337
- userScore,
11338
- courseId,
11339
- cardId,
11340
- courseRegistrationDoc,
11341
- currentCard
11342
- );
11367
+ void this.eloService.updateUserAndCardElo(userScore, courseId, cardId, courseRegistrationDoc, currentCard).catch(this.logEloFailure("correct", cardId));
11343
11368
  } else {
11344
11369
  const k = Math.ceil(32 / history.records.length);
11345
11370
  void this.eloService.updateUserAndCardElo(
@@ -11349,7 +11374,7 @@ var ResponseProcessor = class {
11349
11374
  courseRegistrationDoc,
11350
11375
  currentCard,
11351
11376
  k
11352
- );
11377
+ ).catch(this.logEloFailure("correct repeat-view", cardId));
11353
11378
  }
11354
11379
  logger.info(
11355
11380
  `[FirstContactElo] correct first-attempt ELO update (score=${userScore.toFixed(3)}) for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps})`
@@ -11390,7 +11415,7 @@ var ResponseProcessor = class {
11390
11415
  cardId,
11391
11416
  courseRegistrationDoc,
11392
11417
  currentCard
11393
- );
11418
+ ).catch(this.logEloFailure("incorrect per-tag", cardId));
11394
11419
  logger.info(
11395
11420
  `[FirstContactElo] incorrect first-attempt per-tag ELO update for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps}, tags=${Object.keys(taggedPerformance).length - 1})`
11396
11421
  );
@@ -11402,7 +11427,7 @@ var ResponseProcessor = class {
11402
11427
  cardId,
11403
11428
  courseRegistrationDoc,
11404
11429
  currentCard
11405
- );
11430
+ ).catch(this.logEloFailure("incorrect", cardId));
11406
11431
  logger.info(
11407
11432
  `[FirstContactElo] incorrect first-attempt ELO update (score=0) for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps})`
11408
11433
  );
@@ -11423,15 +11448,9 @@ var ResponseProcessor = class {
11423
11448
  cardId,
11424
11449
  courseRegistrationDoc,
11425
11450
  currentCard
11426
- );
11451
+ ).catch(this.logEloFailure("dismiss-failed per-tag", cardId));
11427
11452
  } else {
11428
- void this.eloService.updateUserAndCardElo(
11429
- 0,
11430
- courseId,
11431
- cardId,
11432
- courseRegistrationDoc,
11433
- currentCard
11434
- );
11453
+ void this.eloService.updateUserAndCardElo(0, courseId, cardId, courseRegistrationDoc, currentCard).catch(this.logEloFailure("dismiss-failed", cardId));
11435
11454
  }
11436
11455
  logger.info(
11437
11456
  `[FirstContactElo] dismiss-failed final ELO penalty for ${cardId} (historyLen=${history.records.length}, sessionViews=${sessionViews})`