@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
@@ -1,9 +1,9 @@
1
- import { U as UserDBInterface, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface, a as UserDBReader, d as CourseInfo, S as StudySessionItem, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, G as GeneratorResult } from '../../contentSource-CrRnbjBx.cjs';
2
- import { D as DataLayerProvider } from '../../dataLayerProvider-IecbidDO.cjs';
1
+ import { U as UserDBInterface, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface, a as UserDBReader, d as CourseInfo, S as StudySessionItem, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, G as GeneratorResult } from '../../contentSource-D3c1fMAk.cjs';
2
+ import { D as DataLayerProvider } from '../../dataLayerProvider-CeLiFbHv.cjs';
3
3
  import { S as StaticCourseManifest } from '../../types-DjiFOZxJ.cjs';
4
4
  import { CourseConfig, CourseElo, DataShape } from '@vue-skuilder/common';
5
5
  import { S as SkuilderCourseData, Q as QualifiedCardID, T as TagStub, a as Tag } from '../../types-legacy-CrwyZIvI.cjs';
6
- import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult } from '../../SyncStrategy-CCU1H81I.cjs';
6
+ import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult } from '../../SyncStrategy-BXliog1m.cjs';
7
7
  import 'moment';
8
8
 
9
9
  interface SkuilderManifest {
@@ -1,9 +1,9 @@
1
- import { U as UserDBInterface, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface, a as UserDBReader, d as CourseInfo, S as StudySessionItem, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, G as GeneratorResult } from '../../contentSource-kD35o65m.js';
2
- import { D as DataLayerProvider } from '../../dataLayerProvider-CtzddVdy.js';
1
+ import { U as UserDBInterface, C as CourseDBInterface, b as CoursesDBInterface, c as ClassroomDBInterface, A as AdminDBInterface, a as UserDBReader, d as CourseInfo, S as StudySessionItem, D as DataLayerResult, e as ContentNavigationStrategyData, f as ContentNavigator, R as ReplanHints, G as GeneratorResult } from '../../contentSource-LPf044hY.js';
2
+ import { D as DataLayerProvider } from '../../dataLayerProvider-DaAootVV.js';
3
3
  import { S as StaticCourseManifest } from '../../types-uJ2Xn3_X.js';
4
4
  import { CourseConfig, CourseElo, DataShape } from '@vue-skuilder/common';
5
5
  import { S as SkuilderCourseData, Q as QualifiedCardID, T as TagStub, a as Tag } from '../../types-legacy-CrwyZIvI.js';
6
- import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult } from '../../SyncStrategy-CCU1H81I.js';
6
+ import { S as SyncStrategy, A as AccountCreationResult, a as AuthenticationResult } from '../../SyncStrategy-BXliog1m.js';
7
7
  import 'moment';
8
8
 
9
9
  interface SkuilderManifest {
@@ -1698,7 +1698,8 @@ var init_generators = __esm({
1698
1698
  // src/core/navigators/generators/prescribed.ts
1699
1699
  var prescribed_exports = {};
1700
1700
  __export(prescribed_exports, {
1701
- default: () => PrescribedCardsGenerator
1701
+ default: () => PrescribedCardsGenerator,
1702
+ unmetIntroExposeTags: () => unmetIntroExposeTags
1702
1703
  });
1703
1704
  function dedupe(arr) {
1704
1705
  return [...new Set(arr)];
@@ -1738,6 +1739,19 @@ function formatAge(ms) {
1738
1739
  if (hours < 24) return `${hours}h`;
1739
1740
  return `${Math.round(hours / 24)}d`;
1740
1741
  }
1742
+ function unmetIntroExposeTags(tags, userTagElo, minCount) {
1743
+ if (minCount <= 0) return [];
1744
+ const exposeTags = new Set(tags.filter((tag) => tag.startsWith("gpc:expose:")));
1745
+ for (const tag of tags) {
1746
+ if (!tag.startsWith("gpc:intro:")) continue;
1747
+ const suffix = tag.slice("gpc:intro:".length);
1748
+ if (suffix) exposeTags.add(`gpc:expose:${suffix}`);
1749
+ }
1750
+ return [...exposeTags].filter((tag) => {
1751
+ const tagElo = userTagElo[tag];
1752
+ return !tagElo || tagElo.count < minCount;
1753
+ });
1754
+ }
1741
1755
  function pickTopByScore(cards, limit) {
1742
1756
  return [...cards].sort((a, b) => b.score - a.score || a.cardId.localeCompare(b.cardId)).slice(0, limit);
1743
1757
  }
@@ -2036,6 +2050,7 @@ var init_prescribed = __esm({
2036
2050
  freshnessWindowSessions: typeof raw.freshnessWindowSessions === "number" ? raw.freshnessWindowSessions : DEFAULT_FRESHNESS_WINDOW,
2037
2051
  maxDirectTargetsPerRun: typeof raw.maxDirectTargetsPerRun === "number" ? raw.maxDirectTargetsPerRun : DEFAULT_MAX_DIRECT_PER_RUN,
2038
2052
  maxSupportCardsPerRun: typeof raw.maxSupportCardsPerRun === "number" ? raw.maxSupportCardsPerRun : DEFAULT_MAX_SUPPORT_PER_RUN,
2053
+ introExposeMinCount: typeof raw.introExposeMinCount === "number" ? raw.introExposeMinCount : DEFAULT_MIN_COUNT,
2039
2054
  hierarchyWalk: {
2040
2055
  enabled: raw.hierarchyWalk?.enabled !== false,
2041
2056
  maxDepth: typeof raw.hierarchyWalk?.maxDepth === "number" ? raw.hierarchyWalk.maxDepth : DEFAULT_HIERARCHY_DEPTH
@@ -2111,18 +2126,11 @@ var init_prescribed = __esm({
2111
2126
  group.hierarchyWalk?.enabled !== false,
2112
2127
  group.hierarchyWalk?.maxDepth ?? DEFAULT_HIERARCHY_DEPTH
2113
2128
  );
2114
- const introTags = tags.filter((tag) => tag.startsWith("gpc:intro:"));
2115
- const exposeTags = new Set(tags.filter((tag) => tag.startsWith("gpc:expose:")));
2116
- for (const introTag of introTags) {
2117
- const suffix = introTag.slice("gpc:intro:".length);
2118
- if (suffix) {
2119
- exposeTags.add(`gpc:expose:${suffix}`);
2120
- }
2121
- }
2122
- const unmetExposeTags = [...exposeTags].filter((tag) => {
2123
- const tagElo = userTagElo[tag];
2124
- return !tagElo || tagElo.count < DEFAULT_MIN_COUNT;
2125
- });
2129
+ const unmetExposeTags = unmetIntroExposeTags(
2130
+ tags,
2131
+ userTagElo,
2132
+ group.introExposeMinCount ?? DEFAULT_MIN_COUNT
2133
+ );
2126
2134
  if (unmetExposeTags.length > 0) {
2127
2135
  unmetExposeTags.forEach((tag) => supportTags.add(tag));
2128
2136
  }
@@ -7761,6 +7769,40 @@ Currently logged-in as ${this._username}.`
7761
7769
  }
7762
7770
  return loginResult;
7763
7771
  }
7772
+ /**
7773
+ * Adopt a remote session that was established outside this client — e.g. a
7774
+ * backend verified a third-party sign-in (Google) and set the session cookie
7775
+ * on its response. Afterwards the user is logged in exactly as after
7776
+ * login(): username switched, guest pointer cleared, init() re-run.
7777
+ *
7778
+ * @param opts.migrateGuestData Carry the current guest account's local data
7779
+ * into the adopted account. Pass true for a freshly created account (as
7780
+ * createAccount() does), false for an existing one (as login() does).
7781
+ */
7782
+ async adoptSession(opts) {
7783
+ if (!this.syncStrategy.canAuthenticate() || !this.syncStrategy.adoptSession) {
7784
+ throw new Error("Session adoption not supported by current sync strategy");
7785
+ }
7786
+ const guestUsername = this._username.startsWith(GuestUsername) ? this._username : void 0;
7787
+ if (!guestUsername) {
7788
+ throw new Error(`Cannot adopt a session while logged in.
7789
+ Log out of account ${this.getUsername()} first.`);
7790
+ }
7791
+ const result = await this.syncStrategy.adoptSession(
7792
+ opts.migrateGuestData ? guestUsername : void 0
7793
+ );
7794
+ if (result.ok && result.username) {
7795
+ log3(`Adopted session for ${result.username}`);
7796
+ this._username = result.username;
7797
+ try {
7798
+ localStorage.removeItem("sk-guest-uuid");
7799
+ } catch (e) {
7800
+ logger.warn("localStorage not available (Node.js environment):", e);
7801
+ }
7802
+ await this.init();
7803
+ }
7804
+ return result;
7805
+ }
7764
7806
  async resetUserData() {
7765
7807
  if (this.syncStrategy.canAuthenticate()) {
7766
7808
  return {