@vue-skuilder/db 0.2.25 → 0.2.27

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.
Files changed (40) hide show
  1. package/dist/{SyncStrategy-CCU1H81I.d.cts → SyncStrategy-BXliog1m.d.cts} +14 -1
  2. package/dist/{SyncStrategy-CCU1H81I.d.ts → SyncStrategy-BXliog1m.d.ts} +14 -1
  3. package/dist/{contentSource-CrRnbjBx.d.cts → contentSource-D3c1fMAk.d.cts} +11 -0
  4. package/dist/{contentSource-kD35o65m.d.ts → contentSource-LPf044hY.d.ts} +11 -0
  5. package/dist/core/index.d.cts +3 -3
  6. package/dist/core/index.d.ts +3 -3
  7. package/dist/core/index.js +55 -13
  8. package/dist/core/index.js.map +1 -1
  9. package/dist/core/index.mjs +55 -13
  10. package/dist/core/index.mjs.map +1 -1
  11. package/dist/{dataLayerProvider-IecbidDO.d.cts → dataLayerProvider-CeLiFbHv.d.cts} +1 -1
  12. package/dist/{dataLayerProvider-CtzddVdy.d.ts → dataLayerProvider-DaAootVV.d.ts} +1 -1
  13. package/dist/impl/couch/index.d.cts +4 -3
  14. package/dist/impl/couch/index.d.ts +4 -3
  15. package/dist/impl/couch/index.js +71 -13
  16. package/dist/impl/couch/index.js.map +1 -1
  17. package/dist/impl/couch/index.mjs +71 -13
  18. package/dist/impl/couch/index.mjs.map +1 -1
  19. package/dist/impl/static/index.d.cts +3 -3
  20. package/dist/impl/static/index.d.ts +3 -3
  21. package/dist/impl/static/index.js +55 -13
  22. package/dist/impl/static/index.js.map +1 -1
  23. package/dist/impl/static/index.mjs +55 -13
  24. package/dist/impl/static/index.mjs.map +1 -1
  25. package/dist/index.d.cts +3 -3
  26. package/dist/index.d.ts +3 -3
  27. package/dist/index.js +72 -14
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +72 -14
  30. package/dist/index.mjs.map +1 -1
  31. package/package.json +3 -3
  32. package/src/core/interfaces/userDB.ts +10 -0
  33. package/src/core/navigators/generators/prescribed.ts +43 -14
  34. package/src/impl/common/BaseUserDB.ts +40 -0
  35. package/src/impl/common/SyncStrategy.ts +11 -1
  36. package/src/impl/common/index.ts +1 -0
  37. package/src/impl/common/types.ts +5 -0
  38. package/src/impl/couch/CouchDBSyncStrategy.ts +25 -1
  39. package/src/study/SessionController.ts +6 -2
  40. package/tests/core/navigators/prescribedIntroExposure.test.ts +29 -0
package/dist/index.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { U as UserDBInterface, s as CourseRegistrationDoc, t as SessionEloEvent, S as StudySessionItem, W as WeightedCard, R as ReplanHints, h as StudyContentSource, u as SessionStateSnapshotProvider, G as GeneratorResult, C as CourseDBInterface } from './contentSource-CrRnbjBx.cjs';
2
- export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, b as CoursesDBInterface, ay as DocumentUpdater, aq as FilterImpact, ag as GeneratorContext, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, as as LearnableWeight, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, at as OrchestrationContext, ar as PipelineForecaster, ao as PipelineRunReport, j as ScheduledCard, V as SessionStateSnapshot, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, O as UserOutcomeRecord, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, aB as getLapses, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, aA as getStreak, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, az as newInterval, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from './contentSource-CrRnbjBx.cjs';
3
- import { D as DataLayerProvider } from './dataLayerProvider-IecbidDO.cjs';
1
+ import { U as UserDBInterface, s as CourseRegistrationDoc, t as SessionEloEvent, S as StudySessionItem, W as WeightedCard, R as ReplanHints, h as StudyContentSource, u as SessionStateSnapshotProvider, G as GeneratorResult, C as CourseDBInterface } from './contentSource-D3c1fMAk.cjs';
2
+ export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, b as CoursesDBInterface, ay as DocumentUpdater, aq as FilterImpact, ag as GeneratorContext, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, as as LearnableWeight, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, at as OrchestrationContext, ar as PipelineForecaster, ao as PipelineRunReport, j as ScheduledCard, V as SessionStateSnapshot, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, O as UserOutcomeRecord, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, aB as getLapses, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, aA as getStreak, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, az as newInterval, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from './contentSource-D3c1fMAk.cjs';
3
+ import { D as DataLayerProvider } from './dataLayerProvider-CeLiFbHv.cjs';
4
4
  import { C as CardHistory, b as CardRecord, c as QuestionRecord } from './types-legacy-CrwyZIvI.cjs';
5
5
  export { d as CardData, e as CourseListData, g as DataShapeData, f as DisplayableData, D as DocType, i as DocTypePrefixes, F as Field, G as GuestUsername, Q as QualifiedCardID, h as QuestionData, S as SkuilderCourseData, a as Tag, T as TagStub, l as log } from './types-legacy-CrwyZIvI.cjs';
6
6
  import { SrsBacklogDebug, StrategyPressureDebug, Loggable } from './core/index.cjs';
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { U as UserDBInterface, s as CourseRegistrationDoc, t as SessionEloEvent, S as StudySessionItem, W as WeightedCard, R as ReplanHints, h as StudyContentSource, u as SessionStateSnapshotProvider, G as GeneratorResult, C as CourseDBInterface } from './contentSource-kD35o65m.js';
2
- export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, b as CoursesDBInterface, ay as DocumentUpdater, aq as FilterImpact, ag as GeneratorContext, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, as as LearnableWeight, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, at as OrchestrationContext, ar as PipelineForecaster, ao as PipelineRunReport, j as ScheduledCard, V as SessionStateSnapshot, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, O as UserOutcomeRecord, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, aB as getLapses, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, aA as getStreak, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, az as newInterval, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from './contentSource-kD35o65m.js';
3
- import { D as DataLayerProvider } from './dataLayerProvider-CtzddVdy.js';
1
+ import { U as UserDBInterface, s as CourseRegistrationDoc, t as SessionEloEvent, S as StudySessionItem, W as WeightedCard, R as ReplanHints, h as StudyContentSource, u as SessionStateSnapshotProvider, G as GeneratorResult, C as CourseDBInterface } from './contentSource-LPf044hY.js';
2
+ export { M as ActivityRecord, A as AdminDBInterface, x as AssignedCard, g as AssignedContent, w as AssignedCourse, v as AssignedTag, af as CardGenerator, ah as CardGeneratorFactory, c as ClassroomDBInterface, I as ClassroomRegistration, H as ClassroomRegistrationDesignation, J as ClassroomRegistrationDoc, e as ContentNavigationStrategyData, f as ContentNavigator, q as ContentSourceID, d as CourseInfo, N as CourseRegistration, b as CoursesDBInterface, ay as DocumentUpdater, aq as FilterImpact, ag as GeneratorContext, ap as GeneratorSummary, $ as HYDRATION_MARKER_ID, a0 as HydrationMarker, as as LearnableWeight, a1 as NavigatorConstructor, ab as NavigatorRole, ac as NavigatorRoles, aa as Navigators, at as OrchestrationContext, ar as PipelineForecaster, ao as PipelineRunReport, j as ScheduledCard, V as SessionStateSnapshot, K as SessionTrackingData, a8 as StrategyContribution, i as StudentClassroomDBInterface, P as StudySessionDoc, k as StudySessionFailedItem, l as StudySessionFailedNewItem, m as StudySessionFailedReviewItem, n as StudySessionNewItem, o as StudySessionReviewItem, Q as StudySessionRunSummary, T as TeacherClassroomDBInterface, L as UserConfig, E as UserCourseSetting, B as UserCourseSettings, z as UserDBAuthenticator, a as UserDBReader, y as UserDBWriter, Z as UserHydrationState, _ as UserHydrationStatus, O as UserOutcomeRecord, F as UsrCrsDataInterface, au as computeDeviation, aw as computeEffectiveWeight, av as computeSpread, ax as createOrchestrationContext, an as drainCapturedRuns, ak as getActivePipeline, a9 as getCardOrigin, aB as getLapses, a3 as getRegisteredNavigator, a6 as getRegisteredNavigatorNames, a5 as getRegisteredNavigatorRole, am as getRunsForSession, aA as getStreak, r as getStudySource, a4 as hasRegisteredNavigator, a7 as initializeNavigatorRegistry, ae as isFilter, ad as isGenerator, p as isReview, X as makeStudySessionId, aj as mountPipelineDebugger, az as newInterval, Y as newSessionId, ai as pipelineDebugAPI, a2 as registerNavigator, al as setDebugSessionId } from './contentSource-LPf044hY.js';
3
+ import { D as DataLayerProvider } from './dataLayerProvider-DaAootVV.js';
4
4
  import { C as CardHistory, b as CardRecord, c as QuestionRecord } from './types-legacy-CrwyZIvI.js';
5
5
  export { d as CardData, e as CourseListData, g as DataShapeData, f as DisplayableData, D as DocType, i as DocTypePrefixes, F as Field, G as GuestUsername, Q as QualifiedCardID, h as QuestionData, S as SkuilderCourseData, a as Tag, T as TagStub, l as log } from './types-legacy-CrwyZIvI.js';
6
6
  import { SrsBacklogDebug, StrategyPressureDebug, Loggable } from './core/index.js';
package/dist/index.js CHANGED
@@ -2000,7 +2000,8 @@ var init_generators = __esm({
2000
2000
  // src/core/navigators/generators/prescribed.ts
2001
2001
  var prescribed_exports = {};
2002
2002
  __export(prescribed_exports, {
2003
- default: () => PrescribedCardsGenerator
2003
+ default: () => PrescribedCardsGenerator,
2004
+ unmetIntroExposeTags: () => unmetIntroExposeTags
2004
2005
  });
2005
2006
  function dedupe(arr) {
2006
2007
  return [...new Set(arr)];
@@ -2040,6 +2041,19 @@ function formatAge(ms) {
2040
2041
  if (hours < 24) return `${hours}h`;
2041
2042
  return `${Math.round(hours / 24)}d`;
2042
2043
  }
2044
+ function unmetIntroExposeTags(tags, userTagElo, minCount) {
2045
+ if (minCount <= 0) return [];
2046
+ const exposeTags = new Set(tags.filter((tag) => tag.startsWith("gpc:expose:")));
2047
+ for (const tag of tags) {
2048
+ if (!tag.startsWith("gpc:intro:")) continue;
2049
+ const suffix = tag.slice("gpc:intro:".length);
2050
+ if (suffix) exposeTags.add(`gpc:expose:${suffix}`);
2051
+ }
2052
+ return [...exposeTags].filter((tag) => {
2053
+ const tagElo = userTagElo[tag];
2054
+ return !tagElo || tagElo.count < minCount;
2055
+ });
2056
+ }
2043
2057
  function pickTopByScore(cards, limit) {
2044
2058
  return [...cards].sort((a, b) => b.score - a.score || a.cardId.localeCompare(b.cardId)).slice(0, limit);
2045
2059
  }
@@ -2338,6 +2352,7 @@ var init_prescribed = __esm({
2338
2352
  freshnessWindowSessions: typeof raw.freshnessWindowSessions === "number" ? raw.freshnessWindowSessions : DEFAULT_FRESHNESS_WINDOW,
2339
2353
  maxDirectTargetsPerRun: typeof raw.maxDirectTargetsPerRun === "number" ? raw.maxDirectTargetsPerRun : DEFAULT_MAX_DIRECT_PER_RUN,
2340
2354
  maxSupportCardsPerRun: typeof raw.maxSupportCardsPerRun === "number" ? raw.maxSupportCardsPerRun : DEFAULT_MAX_SUPPORT_PER_RUN,
2355
+ introExposeMinCount: typeof raw.introExposeMinCount === "number" ? raw.introExposeMinCount : DEFAULT_MIN_COUNT,
2341
2356
  hierarchyWalk: {
2342
2357
  enabled: raw.hierarchyWalk?.enabled !== false,
2343
2358
  maxDepth: typeof raw.hierarchyWalk?.maxDepth === "number" ? raw.hierarchyWalk.maxDepth : DEFAULT_HIERARCHY_DEPTH
@@ -2413,18 +2428,11 @@ var init_prescribed = __esm({
2413
2428
  group.hierarchyWalk?.enabled !== false,
2414
2429
  group.hierarchyWalk?.maxDepth ?? DEFAULT_HIERARCHY_DEPTH
2415
2430
  );
2416
- const introTags = tags.filter((tag) => tag.startsWith("gpc:intro:"));
2417
- const exposeTags = new Set(tags.filter((tag) => tag.startsWith("gpc:expose:")));
2418
- for (const introTag of introTags) {
2419
- const suffix = introTag.slice("gpc:intro:".length);
2420
- if (suffix) {
2421
- exposeTags.add(`gpc:expose:${suffix}`);
2422
- }
2423
- }
2424
- const unmetExposeTags = [...exposeTags].filter((tag) => {
2425
- const tagElo = userTagElo[tag];
2426
- return !tagElo || tagElo.count < DEFAULT_MIN_COUNT;
2427
- });
2431
+ const unmetExposeTags = unmetIntroExposeTags(
2432
+ tags,
2433
+ userTagElo,
2434
+ group.introExposeMinCount ?? DEFAULT_MIN_COUNT
2435
+ );
2428
2436
  if (unmetExposeTags.length > 0) {
2429
2437
  unmetExposeTags.forEach((tag) => supportTags.add(tag));
2430
2438
  }
@@ -7368,6 +7376,22 @@ var init_CouchDBSyncStrategy = __esm({
7368
7376
  };
7369
7377
  }
7370
7378
  }
7379
+ async adoptSession(migrateFromGuest) {
7380
+ let username;
7381
+ try {
7382
+ username = await getLoggedInUsername();
7383
+ } catch {
7384
+ return { ok: false, error: "No session to adopt" };
7385
+ }
7386
+ if (migrateFromGuest?.startsWith(GuestUsername)) {
7387
+ logger.info(`Migrating data from funnel account ${migrateFromGuest} to ${username}`);
7388
+ const migrationResult = await this.migrateFunnelData(migrateFromGuest, username);
7389
+ if (!migrationResult.success) {
7390
+ logger.warn(`Migration failed: ${migrationResult.error}`);
7391
+ }
7392
+ }
7393
+ return { ok: true, username };
7394
+ }
7371
7395
  async logout() {
7372
7396
  try {
7373
7397
  const result = await this.getRemoteCouchRootDB().logOut();
@@ -11958,7 +11982,7 @@ var init_SessionController = __esm({
11958
11982
  });
11959
11983
  } catch (error) {
11960
11984
  this.error(`Failed to get content from source ${i}:`, error);
11961
- if (this.sources.length === 1) {
11985
+ if (this.sources.length === 1 && !replan) {
11962
11986
  throw new Error(`Cannot start session: failed to load content from source ${i}`);
11963
11987
  }
11964
11988
  }
@@ -13094,6 +13118,40 @@ Currently logged-in as ${this._username}.`
13094
13118
  }
13095
13119
  return loginResult;
13096
13120
  }
13121
+ /**
13122
+ * Adopt a remote session that was established outside this client — e.g. a
13123
+ * backend verified a third-party sign-in (Google) and set the session cookie
13124
+ * on its response. Afterwards the user is logged in exactly as after
13125
+ * login(): username switched, guest pointer cleared, init() re-run.
13126
+ *
13127
+ * @param opts.migrateGuestData Carry the current guest account's local data
13128
+ * into the adopted account. Pass true for a freshly created account (as
13129
+ * createAccount() does), false for an existing one (as login() does).
13130
+ */
13131
+ async adoptSession(opts) {
13132
+ if (!this.syncStrategy.canAuthenticate() || !this.syncStrategy.adoptSession) {
13133
+ throw new Error("Session adoption not supported by current sync strategy");
13134
+ }
13135
+ const guestUsername = this._username.startsWith(GuestUsername) ? this._username : void 0;
13136
+ if (!guestUsername) {
13137
+ throw new Error(`Cannot adopt a session while logged in.
13138
+ Log out of account ${this.getUsername()} first.`);
13139
+ }
13140
+ const result = await this.syncStrategy.adoptSession(
13141
+ opts.migrateGuestData ? guestUsername : void 0
13142
+ );
13143
+ if (result.ok && result.username) {
13144
+ log4(`Adopted session for ${result.username}`);
13145
+ this._username = result.username;
13146
+ try {
13147
+ localStorage.removeItem("sk-guest-uuid");
13148
+ } catch (e) {
13149
+ logger.warn("localStorage not available (Node.js environment):", e);
13150
+ }
13151
+ await this.init();
13152
+ }
13153
+ return result;
13154
+ }
13097
13155
  async resetUserData() {
13098
13156
  if (this.syncStrategy.canAuthenticate()) {
13099
13157
  return {