@vue-skuilder/db 0.2.13 → 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
@@ -11109,13 +11109,18 @@ var EloService = class {
11109
11109
  logger.warn(`k value interpretation not currently implemented`);
11110
11110
  }
11111
11111
  const courseDB = this.dataLayer.getCourseDB(currentCard.card.course_id);
11112
- const userElo = (0, import_common23.toCourseElo)(
11113
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo
11114
- );
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);
11115
11120
  const cardElo = (await courseDB.getCardEloData([currentCard.card.card_id]))[0];
11116
11121
  if (cardElo && userElo) {
11117
11122
  const eloUpdate = (0, import_common23.adjustCourseScores)(userElo, cardElo, userScore);
11118
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo = eloUpdate.userElo;
11123
+ courseReg.elo = eloUpdate.userElo;
11119
11124
  const results = await Promise.allSettled([
11120
11125
  this.user.updateUserElo(course_id, eloUpdate.userElo),
11121
11126
  courseDB.updateCardElo(card_id, eloUpdate.cardElo)
@@ -11160,9 +11165,14 @@ var EloService = class {
11160
11165
  */
11161
11166
  async updateUserAndCardEloPerTag(taggedPerformance, course_id, card_id, userCourseRegDoc, currentCard) {
11162
11167
  const courseDB = this.dataLayer.getCourseDB(currentCard.card.course_id);
11163
- const userElo = (0, import_common23.toCourseElo)(
11164
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo
11165
- );
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);
11166
11176
  const [cardEloResults, cardTagsMap] = await Promise.all([
11167
11177
  courseDB.getCardEloData([currentCard.card.card_id]),
11168
11178
  courseDB.getAppliedTagsBatch([card_id])
@@ -11178,7 +11188,7 @@ var EloService = class {
11178
11188
  }
11179
11189
  if (cardElo && userElo) {
11180
11190
  const eloUpdate = (0, import_common23.adjustCourseScoresPerTag)(userElo, cardElo, enriched);
11181
- userCourseRegDoc.courses.find((c) => c.courseID === course_id).elo = eloUpdate.userElo;
11191
+ courseReg.elo = eloUpdate.userElo;
11182
11192
  const results = await Promise.allSettled([
11183
11193
  this.user.updateUserElo(course_id, eloUpdate.userElo),
11184
11194
  courseDB.updateCardElo(card_id, eloUpdate.cardElo)
@@ -11225,6 +11235,14 @@ var ResponseProcessor = class {
11225
11235
  this.srsService = srsService;
11226
11236
  this.eloService = eloService;
11227
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
+ }
11228
11246
  /**
11229
11247
  * Parses performance data into global score and optional per-tag scores.
11230
11248
  *
@@ -11342,17 +11360,11 @@ var ResponseProcessor = class {
11342
11360
  cardId,
11343
11361
  courseRegistrationDoc,
11344
11362
  currentCard
11345
- );
11363
+ ).catch(this.logEloFailure("correct per-tag", cardId));
11346
11364
  } else {
11347
11365
  const userScore = 0.5 + globalScore / 2;
11348
11366
  if (history.records.length === 1) {
11349
- void this.eloService.updateUserAndCardElo(
11350
- userScore,
11351
- courseId,
11352
- cardId,
11353
- courseRegistrationDoc,
11354
- currentCard
11355
- );
11367
+ void this.eloService.updateUserAndCardElo(userScore, courseId, cardId, courseRegistrationDoc, currentCard).catch(this.logEloFailure("correct", cardId));
11356
11368
  } else {
11357
11369
  const k = Math.ceil(32 / history.records.length);
11358
11370
  void this.eloService.updateUserAndCardElo(
@@ -11362,7 +11374,7 @@ var ResponseProcessor = class {
11362
11374
  courseRegistrationDoc,
11363
11375
  currentCard,
11364
11376
  k
11365
- );
11377
+ ).catch(this.logEloFailure("correct repeat-view", cardId));
11366
11378
  }
11367
11379
  logger.info(
11368
11380
  `[FirstContactElo] correct first-attempt ELO update (score=${userScore.toFixed(3)}) for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps})`
@@ -11403,7 +11415,7 @@ var ResponseProcessor = class {
11403
11415
  cardId,
11404
11416
  courseRegistrationDoc,
11405
11417
  currentCard
11406
- );
11418
+ ).catch(this.logEloFailure("incorrect per-tag", cardId));
11407
11419
  logger.info(
11408
11420
  `[FirstContactElo] incorrect first-attempt per-tag ELO update for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps}, tags=${Object.keys(taggedPerformance).length - 1})`
11409
11421
  );
@@ -11415,7 +11427,7 @@ var ResponseProcessor = class {
11415
11427
  cardId,
11416
11428
  courseRegistrationDoc,
11417
11429
  currentCard
11418
- );
11430
+ ).catch(this.logEloFailure("incorrect", cardId));
11419
11431
  logger.info(
11420
11432
  `[FirstContactElo] incorrect first-attempt ELO update (score=0) for ${cardId} (historyLen=${history.records.length}, priorAttemps=${cardRecord.priorAttemps})`
11421
11433
  );
@@ -11436,15 +11448,9 @@ var ResponseProcessor = class {
11436
11448
  cardId,
11437
11449
  courseRegistrationDoc,
11438
11450
  currentCard
11439
- );
11451
+ ).catch(this.logEloFailure("dismiss-failed per-tag", cardId));
11440
11452
  } else {
11441
- void this.eloService.updateUserAndCardElo(
11442
- 0,
11443
- courseId,
11444
- cardId,
11445
- courseRegistrationDoc,
11446
- currentCard
11447
- );
11453
+ void this.eloService.updateUserAndCardElo(0, courseId, cardId, courseRegistrationDoc, currentCard).catch(this.logEloFailure("dismiss-failed", cardId));
11448
11454
  }
11449
11455
  logger.info(
11450
11456
  `[FirstContactElo] dismiss-failed final ELO penalty for ${cardId} (historyLen=${history.records.length}, sessionViews=${sessionViews})`