@vue-skuilder/db 0.2.35 → 0.2.36

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 (258) hide show
  1. package/CLAUDE.md +15 -4
  2. package/build.entries.mjs +12 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  4. package/dist/{contentSource-BteiDpxH.d.ts → contentSource-D_E7JaxR.d.ts} +1 -1
  5. package/dist/core/UserDBDebugger.mjs +285 -0
  6. package/dist/core/UserDBDebugger.mjs.map +1 -0
  7. package/dist/core/bulkImport/cardProcessor.mjs +106 -0
  8. package/dist/core/bulkImport/cardProcessor.mjs.map +1 -0
  9. package/dist/core/{index.js → index.cjs} +6438 -7784
  10. package/dist/core/index.cjs.map +1 -0
  11. package/dist/core/index.d.ts +5 -5
  12. package/dist/core/index.mjs +20 -11368
  13. package/dist/core/interfaces/contentSource.mjs +20 -0
  14. package/dist/core/interfaces/contentSource.mjs.map +1 -0
  15. package/dist/core/navigators/Pipeline.mjs +723 -0
  16. package/dist/core/navigators/Pipeline.mjs.map +1 -0
  17. package/dist/core/navigators/PipelineAssembler.mjs +86 -0
  18. package/dist/core/navigators/PipelineAssembler.mjs.map +1 -0
  19. package/dist/core/navigators/PipelineDebugger.mjs +771 -0
  20. package/dist/core/navigators/PipelineDebugger.mjs.map +1 -0
  21. package/dist/core/navigators/SrsDebugger.mjs +34 -0
  22. package/dist/core/navigators/SrsDebugger.mjs.map +1 -0
  23. package/dist/core/navigators/StrategyPressureDebugger.mjs +19 -0
  24. package/dist/core/navigators/StrategyPressureDebugger.mjs.map +1 -0
  25. package/dist/core/navigators/defaults.mjs +96 -0
  26. package/dist/core/navigators/defaults.mjs.map +1 -0
  27. package/dist/core/navigators/diversityRerank.mjs +85 -0
  28. package/dist/core/navigators/diversityRerank.mjs.map +1 -0
  29. package/dist/core/navigators/filters/WeightedFilter.mjs +81 -0
  30. package/dist/core/navigators/filters/WeightedFilter.mjs.map +1 -0
  31. package/dist/core/navigators/filters/eloDistance.mjs +244 -0
  32. package/dist/core/navigators/filters/eloDistance.mjs.map +1 -0
  33. package/dist/core/navigators/filters/hierarchyDefinition.mjs +235 -0
  34. package/dist/core/navigators/filters/hierarchyDefinition.mjs.map +1 -0
  35. package/dist/core/navigators/filters/interferenceMitigator.mjs +201 -0
  36. package/dist/core/navigators/filters/interferenceMitigator.mjs.map +1 -0
  37. package/dist/core/navigators/filters/relativePriority.mjs +135 -0
  38. package/dist/core/navigators/filters/relativePriority.mjs.map +1 -0
  39. package/dist/core/navigators/filters/userTagPreference.mjs +101 -0
  40. package/dist/core/navigators/filters/userTagPreference.mjs.map +1 -0
  41. package/dist/core/navigators/generators/CompositeGenerator.mjs +203 -0
  42. package/dist/core/navigators/generators/CompositeGenerator.mjs.map +1 -0
  43. package/dist/core/navigators/generators/elo.mjs +77 -0
  44. package/dist/core/navigators/generators/elo.mjs.map +1 -0
  45. package/dist/core/navigators/generators/prescribed.mjs +676 -0
  46. package/dist/core/navigators/generators/prescribed.mjs.map +1 -0
  47. package/dist/core/navigators/generators/srs.mjs +158 -0
  48. package/dist/core/navigators/generators/srs.mjs.map +1 -0
  49. package/dist/core/navigators/index.mjs +345 -0
  50. package/dist/core/navigators/index.mjs.map +1 -0
  51. package/dist/core/navigators/pipelinePlan.mjs +109 -0
  52. package/dist/core/navigators/pipelinePlan.mjs.map +1 -0
  53. package/dist/core/navigators/regulators.mjs +128 -0
  54. package/dist/core/navigators/regulators.mjs.map +1 -0
  55. package/dist/core/orchestration/gradient.mjs +101 -0
  56. package/dist/core/orchestration/gradient.mjs.map +1 -0
  57. package/dist/core/orchestration/index.mjs +115 -0
  58. package/dist/core/orchestration/index.mjs.map +1 -0
  59. package/dist/core/orchestration/learning.mjs +140 -0
  60. package/dist/core/orchestration/learning.mjs.map +1 -0
  61. package/dist/core/orchestration/recording.mjs +64 -0
  62. package/dist/core/orchestration/recording.mjs.map +1 -0
  63. package/dist/core/orchestration/signal.mjs +40 -0
  64. package/dist/core/orchestration/signal.mjs.map +1 -0
  65. package/dist/core/types/contentNavigationStrategy.mjs +10 -0
  66. package/dist/core/types/contentNavigationStrategy.mjs.map +1 -0
  67. package/dist/core/types/hydration.mjs +13 -0
  68. package/dist/core/types/hydration.mjs.map +1 -0
  69. package/dist/core/types/strategyState.mjs +16 -0
  70. package/dist/core/types/strategyState.mjs.map +1 -0
  71. package/dist/core/types/studySession.mjs +14 -0
  72. package/dist/core/types/studySession.mjs.map +1 -0
  73. package/dist/core/types/types-legacy.mjs +44 -0
  74. package/dist/core/types/types-legacy.mjs.map +1 -0
  75. package/dist/core/util/index.mjs +31 -0
  76. package/dist/core/util/index.mjs.map +1 -0
  77. package/dist/core/versionStamps.mjs +46 -0
  78. package/dist/core/versionStamps.mjs.map +1 -0
  79. package/dist/courseConfigRegistration.mjs +306 -0
  80. package/dist/courseConfigRegistration.mjs.map +1 -0
  81. package/dist/{dataLayerProvider-C_QWzHf-.d.ts → dataLayerProvider-BDshhSp_.d.ts} +1 -1
  82. package/dist/diagnostics/dataset.mjs +118 -0
  83. package/dist/diagnostics/dataset.mjs.map +1 -0
  84. package/dist/diagnostics/derive.mjs +318 -0
  85. package/dist/diagnostics/derive.mjs.map +1 -0
  86. package/dist/diagnostics/{index.js → index.cjs} +1 -1
  87. package/dist/diagnostics/index.d.ts +3 -3
  88. package/dist/diagnostics/index.mjs +7 -1042
  89. package/dist/diagnostics/loader.mjs +151 -0
  90. package/dist/diagnostics/loader.mjs.map +1 -0
  91. package/dist/diagnostics/pipeline.mjs +161 -0
  92. package/dist/diagnostics/pipeline.mjs.map +1 -0
  93. package/dist/diagnostics/tagElo.mjs +177 -0
  94. package/dist/diagnostics/tagElo.mjs.map +1 -0
  95. package/dist/diagnostics/text.mjs +174 -0
  96. package/dist/diagnostics/text.mjs.map +1 -0
  97. package/dist/factory.mjs +70 -0
  98. package/dist/factory.mjs.map +1 -0
  99. package/dist/impl/common/BaseUserDB.mjs +1103 -0
  100. package/dist/impl/common/BaseUserDB.mjs.map +1 -0
  101. package/dist/impl/common/userDBHelpers.mjs +49 -0
  102. package/dist/impl/common/userDBHelpers.mjs.map +1 -0
  103. package/dist/impl/common/userDBKeys.mjs +45 -0
  104. package/dist/impl/common/userDBKeys.mjs.map +1 -0
  105. package/dist/impl/couch/CouchDBSyncStrategy.mjs +272 -0
  106. package/dist/impl/couch/CouchDBSyncStrategy.mjs.map +1 -0
  107. package/dist/impl/couch/CourseSyncService.mjs +242 -0
  108. package/dist/impl/couch/CourseSyncService.mjs.map +1 -0
  109. package/dist/impl/couch/PouchDataLayerProvider.mjs +74 -0
  110. package/dist/impl/couch/PouchDataLayerProvider.mjs.map +1 -0
  111. package/dist/impl/couch/adminDB.mjs +61 -0
  112. package/dist/impl/couch/adminDB.mjs.map +1 -0
  113. package/dist/impl/couch/auth.mjs +33 -0
  114. package/dist/impl/couch/auth.mjs.map +1 -0
  115. package/dist/impl/couch/classroomDB.mjs +227 -0
  116. package/dist/impl/couch/classroomDB.mjs.map +1 -0
  117. package/dist/impl/couch/clientCache.mjs +15 -0
  118. package/dist/impl/couch/clientCache.mjs.map +1 -0
  119. package/dist/impl/couch/courseAPI.mjs +183 -0
  120. package/dist/impl/couch/courseAPI.mjs.map +1 -0
  121. package/dist/impl/couch/courseDB.mjs +729 -0
  122. package/dist/impl/couch/courseDB.mjs.map +1 -0
  123. package/dist/impl/couch/courseLookupDB.mjs +94 -0
  124. package/dist/impl/couch/courseLookupDB.mjs.map +1 -0
  125. package/dist/impl/couch/{index.js → index.cjs} +6911 -10367
  126. package/dist/impl/couch/index.cjs.map +1 -0
  127. package/dist/impl/couch/index.d.ts +12 -5
  128. package/dist/impl/couch/index.mjs +134 -12146
  129. package/dist/impl/couch/index.mjs.map +1 -1
  130. package/dist/impl/couch/pouchdb-setup.mjs +15 -0
  131. package/dist/impl/couch/pouchdb-setup.mjs.map +1 -0
  132. package/dist/impl/couch/updateQueue.mjs +101 -0
  133. package/dist/impl/couch/updateQueue.mjs.map +1 -0
  134. package/dist/impl/couch/user-course-relDB.mjs +55 -0
  135. package/dist/impl/couch/user-course-relDB.mjs.map +1 -0
  136. package/dist/impl/static/NoOpSyncStrategy.mjs +49 -0
  137. package/dist/impl/static/NoOpSyncStrategy.mjs.map +1 -0
  138. package/dist/impl/static/StaticDataLayerProvider.mjs +94 -0
  139. package/dist/impl/static/StaticDataLayerProvider.mjs.map +1 -0
  140. package/dist/impl/static/StaticDataUnpacker.mjs +311 -0
  141. package/dist/impl/static/StaticDataUnpacker.mjs.map +1 -0
  142. package/dist/impl/static/courseDB.mjs +368 -0
  143. package/dist/impl/static/courseDB.mjs.map +1 -0
  144. package/dist/impl/static/coursesDB.mjs +38 -0
  145. package/dist/impl/static/coursesDB.mjs.map +1 -0
  146. package/dist/impl/static/{index.js → index.cjs} +2461 -5992
  147. package/dist/impl/static/index.cjs.map +1 -0
  148. package/dist/impl/static/index.d.ts +4 -4
  149. package/dist/impl/static/index.mjs +6 -10741
  150. package/dist/{index-C745YB_6.d.ts → index-BLDpFYG3.d.ts} +1 -1
  151. package/dist/{index.js → index.cjs} +14070 -14239
  152. package/dist/index.cjs.map +1 -0
  153. package/dist/index.d.ts +12 -23
  154. package/dist/index.mjs +38 -16937
  155. package/dist/pouch/{index.js → index.cjs} +5 -1
  156. package/dist/pouch/index.cjs.map +1 -0
  157. package/dist/pouch/index.mjs +2 -19
  158. package/dist/study/ItemQueue.mjs +95 -0
  159. package/dist/study/ItemQueue.mjs.map +1 -0
  160. package/dist/study/MixerDebugger.mjs +303 -0
  161. package/dist/study/MixerDebugger.mjs.map +1 -0
  162. package/dist/study/SessionController.mjs +1187 -0
  163. package/dist/study/SessionController.mjs.map +1 -0
  164. package/dist/study/SessionDebugger.mjs +271 -0
  165. package/dist/study/SessionDebugger.mjs.map +1 -0
  166. package/dist/study/SessionOverlay.mjs +407 -0
  167. package/dist/study/SessionOverlay.mjs.map +1 -0
  168. package/dist/study/SourceMixer.mjs +45 -0
  169. package/dist/study/SourceMixer.mjs.map +1 -0
  170. package/dist/study/SpacedRepetition.mjs +108 -0
  171. package/dist/study/SpacedRepetition.mjs.map +1 -0
  172. package/dist/study/TagFilteredContentSource.mjs +136 -0
  173. package/dist/study/TagFilteredContentSource.mjs.map +1 -0
  174. package/dist/study/services/CardHydrationService.mjs +172 -0
  175. package/dist/study/services/CardHydrationService.mjs.map +1 -0
  176. package/dist/study/services/EloService.mjs +217 -0
  177. package/dist/study/services/EloService.mjs.map +1 -0
  178. package/dist/study/services/ResponseProcessor.mjs +190 -0
  179. package/dist/study/services/ResponseProcessor.mjs.map +1 -0
  180. package/dist/study/services/SrsService.mjs +49 -0
  181. package/dist/study/services/SrsService.mjs.map +1 -0
  182. package/dist/study/services/tagRecent.mjs +65 -0
  183. package/dist/study/services/tagRecent.mjs.map +1 -0
  184. package/dist/{types-DF0JuPbs.d.ts → types-DChCz22D.d.ts} +1 -1
  185. package/dist/{types-legacy-DdVjg81H.d.cts → types-legacy-fT5Y1Wuy.d.ts} +1 -1
  186. package/dist/userDBKeys-ne1g4Xuq.d.ts +16 -0
  187. package/dist/util/Loggable.mjs +14 -0
  188. package/dist/util/Loggable.mjs.map +1 -0
  189. package/dist/util/dataDirectory.mjs +47 -0
  190. package/dist/util/dataDirectory.mjs.map +1 -0
  191. package/dist/util/logger.mjs +86 -0
  192. package/dist/util/logger.mjs.map +1 -0
  193. package/dist/util/migrator/FileSystemAdapter.mjs +18 -0
  194. package/dist/util/migrator/FileSystemAdapter.mjs.map +1 -0
  195. package/dist/util/migrator/StaticToCouchDBMigrator.mjs +428 -0
  196. package/dist/util/migrator/StaticToCouchDBMigrator.mjs.map +1 -0
  197. package/dist/util/migrator/types.mjs +11 -0
  198. package/dist/util/migrator/types.mjs.map +1 -0
  199. package/dist/util/migrator/validation.mjs +334 -0
  200. package/dist/util/migrator/validation.mjs.map +1 -0
  201. package/dist/util/packer/CouchDBToStaticPacker.mjs +438 -0
  202. package/dist/util/packer/CouchDBToStaticPacker.mjs.map +1 -0
  203. package/dist/util/packer/{index.js → index.cjs} +73 -9
  204. package/dist/util/packer/index.cjs.map +1 -0
  205. package/dist/util/packer/index.d.ts +3 -3
  206. package/dist/util/packer/index.mjs +2 -537
  207. package/eslint.config.mjs +9 -1
  208. package/package.json +25 -13
  209. package/rolldown.config.mjs +44 -0
  210. package/src/core/UserDBDebugger.ts +47 -46
  211. package/src/core/navigators/Pipeline.ts +10 -10
  212. package/src/core/navigators/PipelineDebugger.ts +55 -55
  213. package/src/core/navigators/filters/eloDistance.ts +1 -1
  214. package/src/core/navigators/generators/elo.ts +5 -1
  215. package/src/core/navigators/index.ts +9 -3
  216. package/src/factory.ts +10 -1
  217. package/src/impl/common/BaseUserDB.ts +1 -3
  218. package/src/impl/common/index.ts +2 -0
  219. package/src/impl/common/userDBHelpers.ts +4 -58
  220. package/src/impl/common/userDBKeys.ts +64 -0
  221. package/src/impl/couch/courseDB.ts +15 -3
  222. package/src/impl/couch/index.ts +2 -18
  223. package/src/impl/couch/pouchdb-setup.ts +8 -0
  224. package/src/index.ts +1 -1
  225. package/src/study/MixerDebugger.ts +46 -46
  226. package/src/study/SessionDebugger.ts +20 -20
  227. package/src/study/SessionOverlay.ts +4 -4
  228. package/src/util/logger.ts +112 -13
  229. package/tests/core/navigators/eloGenerator.test.ts +36 -0
  230. package/tsup.config.ts +24 -21
  231. package/dist/SyncStrategy-BXliog1m.d.cts +0 -116
  232. package/dist/classroomDB-DLTtLZct.d.cts +0 -86
  233. package/dist/contentSource-FQZcZopC.d.cts +0 -2007
  234. package/dist/core/index.d.cts +0 -521
  235. package/dist/core/index.js.map +0 -1
  236. package/dist/core/index.mjs.map +0 -1
  237. package/dist/dataLayerProvider-3y21KtF-.d.cts +0 -61
  238. package/dist/diagnostics/index.d.cts +0 -561
  239. package/dist/diagnostics/index.mjs.map +0 -1
  240. package/dist/impl/couch/index.d.cts +0 -620
  241. package/dist/impl/couch/index.js.map +0 -1
  242. package/dist/impl/static/index.d.cts +0 -232
  243. package/dist/impl/static/index.js.map +0 -1
  244. package/dist/impl/static/index.mjs.map +0 -1
  245. package/dist/index-BIum9Ue2.d.cts +0 -137
  246. package/dist/index.d.cts +0 -1663
  247. package/dist/index.js.map +0 -1
  248. package/dist/index.mjs.map +0 -1
  249. package/dist/pouch/index.d.cts +0 -1
  250. package/dist/pouch/index.js.map +0 -1
  251. package/dist/pouch/index.mjs.map +0 -1
  252. package/dist/types-BcWVH4ww.d.cts +0 -58
  253. package/dist/types-legacy-DdVjg81H.d.ts +0 -168
  254. package/dist/util/packer/index.d.cts +0 -5
  255. package/dist/util/packer/index.js.map +0 -1
  256. package/dist/util/packer/index.mjs.map +0 -1
  257. package/src/study/getCardDataShape.ts +0 -34
  258. /package/dist/diagnostics/{index.js.map → index.cjs.map} +0 -0
@@ -0,0 +1,729 @@
1
+ import "../../_virtual/_rolldown/runtime.mjs";
2
+ import { logger } from "../../util/logger.mjs";
3
+ import { Navigators } from "../../core/navigators/index.mjs";
4
+ import { DocType, DocTypePrefixes } from "../../core/types/types-legacy.mjs";
5
+ import CourseLookup from "./courseLookupDB.mjs";
6
+ import UpdateQueue from "./updateQueue.mjs";
7
+ import { GET_CACHED } from "./clientCache.mjs";
8
+ import { createDefaultPipeline } from "../../core/navigators/defaults.mjs";
9
+ import { PipelineAssembler } from "../../core/navigators/PipelineAssembler.mjs";
10
+ import { addNote55, addTagToCard, getCredentialledCourseConfig, getTagID } from "./courseAPI.mjs";
11
+ import { filterAllDocsByPrefix, getCourseDB } from "./index.mjs";
12
+ import { EloToNumber, Status, blankCourseElo, toCourseElo } from "@vue-skuilder/common";
13
+ //#region src/impl/couch/courseDB.ts
14
+ var CoursesDB = class {
15
+ _courseIDs;
16
+ constructor(courseIDs) {
17
+ if (courseIDs && courseIDs.length > 0) this._courseIDs = courseIDs;
18
+ else this._courseIDs = void 0;
19
+ }
20
+ async getCourseList() {
21
+ let crsList = await CourseLookup.allCourseWare();
22
+ logger.debug(`AllCourses: ${crsList.map((c) => c.name + ", " + c._id + "\n ")}`);
23
+ if (this._courseIDs) crsList = crsList.filter((c) => this._courseIDs.includes(c._id));
24
+ logger.debug(`AllCourses.filtered: ${crsList.map((c) => c.name + ", " + c._id + "\n ")}`);
25
+ return (await Promise.all(crsList.map(async (c) => {
26
+ try {
27
+ const cfg = await getCredentialledCourseConfig(c._id);
28
+ logger.debug(`Found cfg: ${JSON.stringify(cfg)}`);
29
+ return cfg;
30
+ } catch (e) {
31
+ logger.warn(`Error fetching cfg for course ${c.name}, ${c._id}: ${e}`);
32
+ return;
33
+ }
34
+ }))).filter((c) => !!c);
35
+ }
36
+ async getCourseConfig(courseId) {
37
+ if (this._courseIDs && this._courseIDs.length && !this._courseIDs.includes(courseId)) throw new Error(`Course ${courseId} not in course list`);
38
+ const cfg = await getCredentialledCourseConfig(courseId);
39
+ if (cfg === void 0) throw new Error(`Error fetching cfg for course ${courseId}`);
40
+ else return cfg;
41
+ }
42
+ async disambiguateCourse(courseId, disambiguator) {
43
+ await CourseLookup.updateDisambiguator(courseId, disambiguator);
44
+ }
45
+ };
46
+ function randIntWeightedTowardZero(n) {
47
+ return Math.floor(Math.random() * Math.random() * Math.random() * n);
48
+ }
49
+ var CourseDB = class {
50
+ /**
51
+ * Primary database handle used for all **read** operations (queries, gets).
52
+ *
53
+ * When local sync is active, this points to the local PouchDB replica for
54
+ * fast, network-free reads. Otherwise it points to the remote CouchDB.
55
+ */
56
+ db;
57
+ /**
58
+ * Remote database handle used for all **write** operations.
59
+ *
60
+ * Always points to the remote CouchDB so that writes (ELO updates, tag
61
+ * mutations, admin operations) aggregate on the server. The local replica
62
+ * is a read-only snapshot that refreshes on the next page load.
63
+ *
64
+ * When local sync is NOT active, this is the same instance as `this.db`.
65
+ */
66
+ remoteDB;
67
+ id;
68
+ _getCurrentUser;
69
+ updateQueue;
70
+ /**
71
+ * @param id - Course ID
72
+ * @param userLookup - Async function returning the current user DB
73
+ * @param localDB - Optional local PouchDB replica for reads. When provided,
74
+ * `this.db` uses the local replica and `this.remoteDB` stays remote.
75
+ * The UpdateQueue reads from remote and writes to remote (local `_rev`
76
+ * values may be stale, so read-modify-write cycles must go through
77
+ * the remote DB to avoid conflicts).
78
+ */
79
+ constructor(id, userLookup, localDB) {
80
+ this.id = id;
81
+ const remote = getCourseDB(this.id);
82
+ this.remoteDB = remote;
83
+ this.db = localDB ?? remote;
84
+ this._getCurrentUser = userLookup;
85
+ this.updateQueue = new UpdateQueue(this.remoteDB, this.remoteDB);
86
+ }
87
+ getCourseID() {
88
+ return this.id;
89
+ }
90
+ async getCourseInfo() {
91
+ return {
92
+ cardCount: (await this.db.find({
93
+ selector: { docType: DocType.CARD },
94
+ limit: 1e3
95
+ })).docs.length,
96
+ registeredUsers: 0
97
+ };
98
+ }
99
+ async getInexperiencedCards(limit = 2) {
100
+ return (await this.db.query("cardsByInexperience", { limit })).rows.map((r) => {
101
+ return {
102
+ courseId: this.id,
103
+ cardId: r.id,
104
+ count: r.key,
105
+ elo: r.value
106
+ };
107
+ });
108
+ }
109
+ async getCardsByEloLimits(options = {
110
+ low: 0,
111
+ high: Number.MIN_SAFE_INTEGER,
112
+ limit: 25,
113
+ page: 0
114
+ }) {
115
+ return (await this.db.query("elo", {
116
+ startkey: options.low,
117
+ endkey: options.high,
118
+ limit: options.limit,
119
+ skip: options.limit * options.page
120
+ })).rows.map((r) => {
121
+ return `${this.id}-${r.id}-${r.key}`;
122
+ });
123
+ }
124
+ async getCardEloData(id) {
125
+ const docs = await this.db.allDocs({
126
+ keys: id,
127
+ include_docs: true
128
+ });
129
+ const ret = [];
130
+ docs.rows.forEach((r) => {
131
+ if (isSuccessRow(r)) if (r.doc && r.doc.elo) ret.push(toCourseElo(r.doc.elo));
132
+ else {
133
+ logger.warn("no elo data for card: " + r.id);
134
+ ret.push(blankCourseElo());
135
+ }
136
+ else {
137
+ logger.warn("no elo data for card: " + JSON.stringify(r));
138
+ ret.push(blankCourseElo());
139
+ }
140
+ });
141
+ return ret;
142
+ }
143
+ /**
144
+ * Returns the lowest and highest `global` ELO ratings in the course
145
+ */
146
+ async getELOBounds() {
147
+ const [low, high] = await Promise.all([(await this.db.query("elo", {
148
+ startkey: 0,
149
+ limit: 1,
150
+ include_docs: false
151
+ })).rows[0].key, (await this.db.query("elo", {
152
+ limit: 1,
153
+ descending: true,
154
+ startkey: 1e5
155
+ })).rows[0].key]);
156
+ return {
157
+ low,
158
+ high
159
+ };
160
+ }
161
+ async removeCard(id) {
162
+ const doc = await this.remoteDB.get(id);
163
+ if (!doc.docType || !(doc.docType === DocType.CARD)) throw new Error(`failed to remove ${id} from course ${this.id}. id does not point to a card`);
164
+ try {
165
+ const appliedTags = await this.getAppliedTags(id);
166
+ (await Promise.allSettled(appliedTags.rows.map(async (tagRow) => {
167
+ const tagId = tagRow.id;
168
+ await this.removeTagFromCard(id, tagId);
169
+ }))).forEach((result, index) => {
170
+ if (result.status === "rejected") {
171
+ const tagId = appliedTags.rows[index].id;
172
+ logger.error(`Failed to remove card ${id} from tag ${tagId}: ${result.reason}`);
173
+ }
174
+ });
175
+ } catch (error) {
176
+ logger.error(`Error removing card ${id} from tags: ${error}`);
177
+ }
178
+ return this.remoteDB.remove(doc);
179
+ }
180
+ async getCardDisplayableDataIDs(id) {
181
+ logger.debug(id.join(", "));
182
+ const cards = await this.db.allDocs({
183
+ keys: id,
184
+ include_docs: true
185
+ });
186
+ const ret = {};
187
+ cards.rows.forEach((r) => {
188
+ if (isSuccessRow(r)) ret[r.id] = r.doc.id_displayable_data;
189
+ });
190
+ return ret;
191
+ }
192
+ async getCardsByELO(elo, cardLimit) {
193
+ elo = parseInt(elo);
194
+ const limit = cardLimit ? cardLimit : 25;
195
+ const below = await this.db.query("elo", {
196
+ limit: Math.ceil(limit / 2),
197
+ startkey: elo,
198
+ descending: true
199
+ });
200
+ const aboveLimit = limit - below.rows.length;
201
+ const above = await this.db.query("elo", {
202
+ limit: aboveLimit,
203
+ startkey: elo + 1
204
+ });
205
+ let cards = below.rows;
206
+ cards = cards.concat(above.rows);
207
+ const ret = cards.sort((a, b) => {
208
+ const s = Math.abs(a.key - elo) - Math.abs(b.key - elo);
209
+ if (s === 0) return Math.random() - .5;
210
+ else return s;
211
+ }).map((c) => {
212
+ return {
213
+ courseID: this.id,
214
+ cardID: c.id,
215
+ elo: c.key
216
+ };
217
+ });
218
+ const str = `below:\n${below.rows.map((r) => `\t${r.id}-${r.key}\n`)}
219
+
220
+ above:\n${above.rows.map((r) => `\t${r.id}-${r.key}\n`)}`;
221
+ logger.debug(`Getting ${limit} cards centered around elo: ${elo}:\n\n` + str);
222
+ return ret;
223
+ }
224
+ async getCourseConfig() {
225
+ const ret = await getCredentialledCourseConfig(this.id);
226
+ if (ret) return ret;
227
+ else throw new Error(`Course config not found for course ID: ${this.id}`);
228
+ }
229
+ async updateCourseConfig(cfg) {
230
+ logger.debug(`Updating: ${JSON.stringify(cfg)}`);
231
+ try {
232
+ return await updateCredentialledCourseConfig(this.id, cfg);
233
+ } catch (error) {
234
+ logger.error(`Error updating course config in course DB: ${error}`);
235
+ throw error;
236
+ }
237
+ }
238
+ async updateCardElo(cardId, elo) {
239
+ if (!elo) throw new Error(`Cannot update card elo with null or undefined value for card ID: ${cardId}`);
240
+ try {
241
+ return {
242
+ ok: true,
243
+ id: cardId,
244
+ rev: (await this.updateQueue.update(cardId, (card) => {
245
+ logger.debug(`Replacing ${JSON.stringify(card.elo)} with ${JSON.stringify(elo)}`);
246
+ card.elo = elo;
247
+ return card;
248
+ }))._rev
249
+ };
250
+ } catch (error) {
251
+ logger.error(`Failed to update card elo for card ID: ${cardId}`, error);
252
+ throw new Error(`Failed to update card elo for card ID: ${cardId}`);
253
+ }
254
+ }
255
+ async getAppliedTags(cardId) {
256
+ const ret = await getAppliedTags(this.id, cardId);
257
+ if (ret) return ret;
258
+ else throw new Error(`Failed to find tags for card ${this.id}-${cardId}`);
259
+ }
260
+ async getAppliedTagsBatch(cardIds) {
261
+ if (cardIds.length === 0) return /* @__PURE__ */ new Map();
262
+ const result = await this.db.query("getTags", {
263
+ keys: cardIds,
264
+ include_docs: false
265
+ });
266
+ const tagsByCard = /* @__PURE__ */ new Map();
267
+ for (const cardId of cardIds) tagsByCard.set(cardId, []);
268
+ for (const row of result.rows) {
269
+ const cardId = row.key;
270
+ const tagName = row.value?.name;
271
+ if (tagName && tagsByCard.has(cardId)) tagsByCard.get(cardId).push(tagName);
272
+ }
273
+ return tagsByCard;
274
+ }
275
+ async getAllCardIds() {
276
+ const prefix = `${DocTypePrefixes[DocType.CARD]}-`;
277
+ return (await this.db.allDocs({
278
+ startkey: prefix,
279
+ endkey: `${prefix}\ufff0`,
280
+ include_docs: false
281
+ })).rows.map((row) => row.id);
282
+ }
283
+ async addTagToCard(cardId, tagId, updateELO) {
284
+ return await addTagToCard(this.id, cardId, tagId, (await this._getCurrentUser()).getUsername(), updateELO);
285
+ }
286
+ async removeTagFromCard(cardId, tagId) {
287
+ return await removeTagFromCard(this.id, cardId, tagId);
288
+ }
289
+ async createTag(name, author) {
290
+ return await createTag(this.id, name, author);
291
+ }
292
+ async getTag(tagId) {
293
+ return await getTag(this.id, tagId);
294
+ }
295
+ async updateTag(tag) {
296
+ if (tag.course !== this.id) throw new Error(`Tag ${JSON.stringify(tag)} does not belong to course ${this.id}`);
297
+ return await updateTag(tag);
298
+ }
299
+ async getCourseTagStubs() {
300
+ return getCourseTagStubs(this.id);
301
+ }
302
+ async addNote(codeCourse, shape, data, author, tags, uploads, elo = blankCourseElo()) {
303
+ try {
304
+ const resp = await addNote55(this.id, codeCourse, shape, data, author, tags, uploads, elo);
305
+ if (resp.ok) {
306
+ if (resp.cardCreationFailed) {
307
+ logger.warn(`[courseDB.addNote] Note added but card creation failed: ${resp.cardCreationError}`);
308
+ return {
309
+ status: Status.error,
310
+ message: `Note was added but no cards were created: ${resp.cardCreationError}`,
311
+ id: resp.id
312
+ };
313
+ }
314
+ return {
315
+ status: Status.ok,
316
+ message: "",
317
+ id: resp.id
318
+ };
319
+ } else return {
320
+ status: Status.error,
321
+ message: "Unexpected error adding note"
322
+ };
323
+ } catch (e) {
324
+ const err = e;
325
+ logger.error(`[addNote] error ${err.name}\n\treason: ${err.reason}\n\tmessage: ${err.message}`);
326
+ return {
327
+ status: Status.error,
328
+ message: `Error adding note to course. ${e.reason || err.message}`
329
+ };
330
+ }
331
+ }
332
+ async getCourseDoc(id, options) {
333
+ return await this.db.get(id, options ?? {});
334
+ }
335
+ async getCourseDocs(ids, options = {}) {
336
+ return await this.db.allDocs({
337
+ ...options,
338
+ keys: ids
339
+ });
340
+ }
341
+ getNavigationStrategy(id) {
342
+ logger.debug(`[courseDB] Getting navigation strategy: ${id}`);
343
+ if (id == "") {
344
+ const strategy = {
345
+ _id: "NAVIGATION_STRATEGY-ELO",
346
+ docType: DocType.NAVIGATION_STRATEGY,
347
+ name: "ELO",
348
+ description: "ELO-based navigation strategy for ordering content by difficulty",
349
+ implementingClass: Navigators.ELO,
350
+ course: this.id,
351
+ serializedData: ""
352
+ };
353
+ return Promise.resolve(strategy);
354
+ } else return this.db.get(id);
355
+ }
356
+ async getAllNavigationStrategies() {
357
+ const prefix = DocTypePrefixes[DocType.NAVIGATION_STRATEGY];
358
+ return (await this.db.allDocs({
359
+ startkey: prefix,
360
+ endkey: `${prefix}\ufff0`,
361
+ include_docs: true
362
+ })).rows.map((row) => row.doc);
363
+ }
364
+ async addNavigationStrategy(data) {
365
+ logger.debug(`[courseDB] Adding navigation strategy: ${data._id}`);
366
+ this.invalidateNavigatorCache();
367
+ return this.remoteDB.put(data).then(() => {});
368
+ }
369
+ updateNavigationStrategy(id, data) {
370
+ logger.debug(`[courseDB] Updating navigation strategy: ${id}`);
371
+ logger.debug(JSON.stringify(data));
372
+ return Promise.resolve();
373
+ }
374
+ /**
375
+ * Creates an instantiated navigator for this course.
376
+ *
377
+ * Handles multiple generators by wrapping them in CompositeGenerator.
378
+ * This is the preferred method for getting a ready-to-use navigator.
379
+ *
380
+ * @param user - User database interface
381
+ * @returns Instantiated ContentNavigator ready for use
382
+ */
383
+ async createNavigator(user) {
384
+ try {
385
+ const allStrategies = await this.getAllNavigationStrategies();
386
+ if (allStrategies.length === 0) {
387
+ logger.debug("[courseDB] No strategy documents found, using default Pipeline(Composite(ELO, SRS), [eloDistanceFilter])");
388
+ return createDefaultPipeline(user, this);
389
+ }
390
+ const { pipeline, generatorStrategies, filterStrategies, warnings } = await new PipelineAssembler().assemble({
391
+ strategies: allStrategies,
392
+ user,
393
+ course: this
394
+ });
395
+ for (const warning of warnings) logger.warn(`[PipelineAssembler] ${warning}`);
396
+ if (!pipeline) {
397
+ logger.debug("[courseDB] Pipeline assembly failed, using default pipeline");
398
+ return createDefaultPipeline(user, this);
399
+ }
400
+ logger.debug(`[courseDB] Using assembled pipeline with ${generatorStrategies.length} generator(s) and ${filterStrategies.length} filter(s)`);
401
+ return pipeline;
402
+ } catch (e) {
403
+ const msg = e instanceof Error ? `${e.message}\n${e.stack}` : JSON.stringify(e);
404
+ logger.error(`[courseDB] Error creating navigator: ${msg}`);
405
+ throw e;
406
+ }
407
+ }
408
+ /**
409
+ * Get cards with suitability scores for presentation.
410
+ *
411
+ * This is the PRIMARY API for content sources going forward. Delegates to the
412
+ * course's configured NavigationStrategy to get scored candidates.
413
+ *
414
+ * @param limit - Maximum number of cards to return
415
+ * @returns Cards sorted by score descending
416
+ */
417
+ _pendingHints = null;
418
+ /**
419
+ * Session-scoped cache of the broad ELO-neighbor pool used by
420
+ * getCardsCenteredAtELO. The `elo` view query re-indexes on first touch per
421
+ * call (PouchDB 9 ignores `stale`), so without this each plan/replan pays
422
+ * ~1.5-2s. The pool is fetched once and re-ranked against the live (roaming)
423
+ * ELO in memory on subsequent calls.
424
+ */
425
+ _eloPoolCache = null;
426
+ _eloPoolTtlMs = 300 * 1e3;
427
+ /**
428
+ * How far the target may move from the pool's centre before the pool is
429
+ * refetched. Well above a learner's in-session roam; a different learner (or
430
+ * a far-off explicit ELO) on the same CourseDB gets a pool of their own.
431
+ */
432
+ _eloPoolMaxDrift = 200;
433
+ /**
434
+ * Cached assembled navigator (Pipeline). createNavigator() reads strategy
435
+ * docs and builds a fresh Pipeline every call — whose internal `_tagCache`
436
+ * and `_cachedOrchestration` are designed to make replans cheap but never
437
+ * survive, because the instance is discarded each run. Caching it lets those
438
+ * caches persist across plan/replan within a session (SessionController holds
439
+ * one CourseDB instance for the session's lifetime). Rebuilt on user change,
440
+ * TTL expiry, or explicit invalidation after a strategy-doc write.
441
+ */
442
+ _cachedNavigator = null;
443
+ _navigatorTtlMs = 300 * 1e3;
444
+ setEphemeralHints(hints) {
445
+ this._pendingHints = hints;
446
+ }
447
+ /**
448
+ * Forward a presentation to the navigator (a new card restarts its intake
449
+ * clock). Builds the navigator if the cached one has expired.
450
+ */
451
+ notePresented(card) {
452
+ if (card.status !== "new") return;
453
+ this._getCurrentUser().then((u) => this._getCachedNavigator(u)).then(({ navigator }) => navigator.notePresented?.(card)).catch((e) => logger.warn(`[courseDB] Could not note a presentation: ${e}`));
454
+ }
455
+ async getWeightedCards(limit) {
456
+ const u = await this._getCurrentUser();
457
+ try {
458
+ const { navigator } = await this._getCachedNavigator(u);
459
+ if (this._pendingHints) {
460
+ navigator.setEphemeralHints(this._pendingHints);
461
+ this._pendingHints = null;
462
+ }
463
+ return await navigator.getWeightedCards(limit);
464
+ } catch (e) {
465
+ logger.error(`[courseDB] Error getting weighted cards: ${e}`);
466
+ throw e;
467
+ }
468
+ }
469
+ /**
470
+ * Return the assembled navigator, reusing the cached instance when possible.
471
+ * Reuse preserves the Pipeline's per-session caches (tags, orchestration
472
+ * context) across replans, which is the dominant per-replan cost once the
473
+ * ELO-pool cost is removed. Rebuilds on user change or TTL expiry.
474
+ */
475
+ async _getCachedNavigator(user) {
476
+ const userId = user.getUsername();
477
+ const now = Date.now();
478
+ if (this._cachedNavigator && this._cachedNavigator.userId === userId && now - this._cachedNavigator.builtAt < this._navigatorTtlMs) return {
479
+ navigator: this._cachedNavigator.navigator,
480
+ cacheStatus: "hit"
481
+ };
482
+ const navigator = await this.createNavigator(user);
483
+ this._cachedNavigator = {
484
+ navigator,
485
+ userId,
486
+ builtAt: now
487
+ };
488
+ return {
489
+ navigator,
490
+ cacheStatus: "miss"
491
+ };
492
+ }
493
+ /**
494
+ * Drop the cached navigator so the next getWeightedCards() rebuilds it.
495
+ * Call after mutating this course's navigation strategy documents.
496
+ */
497
+ invalidateNavigatorCache() {
498
+ this._cachedNavigator = null;
499
+ }
500
+ async getCardsCenteredAtELO(options = {
501
+ limit: 99,
502
+ elo: "user"
503
+ }, filter) {
504
+ let targetElo;
505
+ if (options.elo === "user") {
506
+ const u = await this._getCurrentUser();
507
+ targetElo = -1;
508
+ try {
509
+ targetElo = EloToNumber((await u.getCourseRegistrationsDoc()).courses.find((c) => {
510
+ return c.courseID === this.id;
511
+ }).elo);
512
+ } catch {
513
+ targetElo = 1e3;
514
+ }
515
+ } else if (options.elo === "random") {
516
+ const bounds = await GET_CACHED(`elo-bounds-${this.id}`, () => this.getELOBounds());
517
+ targetElo = Math.round(bounds.low + Math.random() * (bounds.high - bounds.low));
518
+ } else targetElo = options.elo;
519
+ const POOL_SIZE = Math.max(2e3, options.limit * 4);
520
+ const nowMs = Date.now();
521
+ let cacheStatus = "hit";
522
+ if (!this._eloPoolCache || nowMs - this._eloPoolCache.fetchedAt > this._eloPoolTtlMs || Math.abs(targetElo - this._eloPoolCache.centerElo) > this._eloPoolMaxDrift) {
523
+ const fetched = await this.getCardsByELO(targetElo, POOL_SIZE);
524
+ if (fetched.length > 0) this._eloPoolCache = {
525
+ rows: fetched,
526
+ fetchedAt: nowMs,
527
+ centerElo: targetElo
528
+ };
529
+ cacheStatus = "miss";
530
+ }
531
+ const rankAgainstCurrentElo = () => {
532
+ const raw = this._eloPoolCache?.rows ?? [];
533
+ return (filter ? raw.filter((c) => filter(c)) : raw).map((c) => ({ ...c })).sort((a, b) => Math.abs((a.elo ?? targetElo) - targetElo) - Math.abs((b.elo ?? targetElo) - targetElo));
534
+ };
535
+ let cards = rankAgainstCurrentElo();
536
+ if (cards.length < options.limit && (cacheStatus === "hit" || !this._eloPoolCache)) {
537
+ const fetched = await this.getCardsByELO(targetElo, POOL_SIZE);
538
+ if (fetched.length > 0) this._eloPoolCache = {
539
+ rows: fetched,
540
+ fetchedAt: nowMs,
541
+ centerElo: targetElo
542
+ };
543
+ cards = rankAgainstCurrentElo();
544
+ cacheStatus = "refresh";
545
+ }
546
+ const selectedCards = [];
547
+ while (selectedCards.length < options.limit && cards.length > 0) {
548
+ const index = randIntWeightedTowardZero(cards.length);
549
+ const card = cards.splice(index, 1)[0];
550
+ selectedCards.push(card);
551
+ }
552
+ return selectedCards.map((c) => {
553
+ return {
554
+ courseID: this.id,
555
+ cardID: c.cardID,
556
+ contentSourceType: "course",
557
+ contentSourceID: this.id,
558
+ elo: c.elo,
559
+ status: "new"
560
+ };
561
+ });
562
+ }
563
+ async searchCards(query) {
564
+ logger.log(`[CourseDB ${this.id}] Searching for: "${query}"`);
565
+ let displayableData;
566
+ try {
567
+ displayableData = await this.db.find({ selector: {
568
+ docType: "DISPLAYABLE_DATA",
569
+ "data.0.data": { $regex: `.*${query}.*` }
570
+ } });
571
+ logger.log(`[CourseDB ${this.id}] Regex search on data[0].data successful`);
572
+ } catch (regexError) {
573
+ logger.log(`[CourseDB ${this.id}] Regex search failed, falling back to manual search:`, regexError);
574
+ const allDisplayable = await this.db.find({ selector: { docType: "DISPLAYABLE_DATA" } });
575
+ logger.log(`[CourseDB ${this.id}] Retrieved ${allDisplayable.docs.length} documents for manual filtering`);
576
+ displayableData = { docs: allDisplayable.docs.filter((doc) => {
577
+ const match = JSON.stringify(doc).toLowerCase().includes(query.toLowerCase());
578
+ if (match) logger.log(`[CourseDB ${this.id}] Manual match found in document: ${doc._id}`);
579
+ return match;
580
+ }) };
581
+ }
582
+ logger.log(`[CourseDB ${this.id}] Found ${displayableData.docs.length} displayable data documents`);
583
+ if (displayableData.docs.length === 0) {
584
+ const allDisplayableData = await this.db.find({
585
+ selector: { docType: "DISPLAYABLE_DATA" },
586
+ limit: 5
587
+ });
588
+ logger.log(`[CourseDB ${this.id}] Sample displayable data:`, allDisplayableData.docs.map((d) => ({
589
+ id: d._id,
590
+ docType: d.docType,
591
+ dataStructure: d.data ? Object.keys(d.data) : "no data field",
592
+ dataContent: d.data,
593
+ fullDoc: d
594
+ })));
595
+ }
596
+ const allResults = [];
597
+ for (const dd of displayableData.docs) {
598
+ const cards = await this.db.find({ selector: {
599
+ docType: "CARD",
600
+ id_displayable_data: { $in: [dd._id] }
601
+ } });
602
+ logger.log(`[CourseDB ${this.id}] Displayable data ${dd._id} linked to ${cards.docs.length} cards`);
603
+ allResults.push(...cards.docs);
604
+ }
605
+ logger.log(`[CourseDB ${this.id}] Total cards found: ${allResults.length}`);
606
+ return allResults;
607
+ }
608
+ async find(request) {
609
+ return this.db.find(request);
610
+ }
611
+ };
612
+ /**
613
+ * Returns a list of registered datashapes for the specified
614
+ * course.
615
+ * @param courseID The ID of the course
616
+ */
617
+ async function getCourseDataShapes(courseID) {
618
+ return (await getCredentialledCourseConfig(courseID)).dataShapes;
619
+ }
620
+ async function getCredentialledDataShapes(courseID) {
621
+ return (await getCredentialledCourseConfig(courseID)).dataShapes;
622
+ }
623
+ async function getCourseQuestionTypes(courseID) {
624
+ return (await getCredentialledCourseConfig(courseID)).questionTypes;
625
+ }
626
+ async function getCourseTagStubs(courseID) {
627
+ logger.debug(`Getting tag stubs for course: ${courseID}`);
628
+ const stubs = await filterAllDocsByPrefix(getCourseDB(courseID), DocType.TAG.valueOf() + "-");
629
+ stubs.rows.forEach((row) => {
630
+ logger.debug(`\tTag stub for doc: ${row.id}`);
631
+ });
632
+ return stubs;
633
+ }
634
+ async function deleteTag(courseID, tagName) {
635
+ tagName = getTagID(tagName);
636
+ const courseDB = getCourseDB(courseID);
637
+ const doc = await courseDB.get(DocType.TAG.valueOf() + "-" + tagName);
638
+ return await courseDB.remove(doc);
639
+ }
640
+ async function createTag(courseID, tagName, author) {
641
+ logger.debug(`Creating tag: ${tagName}...`);
642
+ const tagID = getTagID(tagName);
643
+ return await getCourseDB(courseID).put({
644
+ course: courseID,
645
+ docType: DocType.TAG,
646
+ name: tagName,
647
+ snippet: "",
648
+ taggedCards: [],
649
+ wiki: "",
650
+ author,
651
+ _id: tagID
652
+ });
653
+ }
654
+ async function updateTag(tag) {
655
+ const prior = await getTag(tag.course, tag.name);
656
+ return await getCourseDB(tag.course).put({
657
+ ...tag,
658
+ _rev: prior._rev
659
+ });
660
+ }
661
+ async function getTag(courseID, tagName) {
662
+ const tagID = getTagID(tagName);
663
+ return getCourseDB(courseID).get(tagID);
664
+ }
665
+ async function removeTagFromCard(courseID, cardID, tagID) {
666
+ tagID = getTagID(tagID);
667
+ const courseDB = getCourseDB(courseID);
668
+ const tag = await courseDB.get(tagID);
669
+ tag.taggedCards = tag.taggedCards.filter((taggedID) => {
670
+ return cardID !== taggedID;
671
+ });
672
+ return courseDB.put(tag);
673
+ }
674
+ /**
675
+ * Returns an array of ancestor tag IDs, where:
676
+ * return[0] = parent,
677
+ * return[1] = grandparent,
678
+ * return[2] = great grandparent,
679
+ * etc.
680
+ *
681
+ * If ret is empty, the tag itself is a root
682
+ */
683
+ function getAncestorTagIDs(courseID, tagID) {
684
+ tagID = getTagID(tagID);
685
+ const split = tagID.split(">");
686
+ if (split.length === 1) return [];
687
+ else {
688
+ split.pop();
689
+ const parent = split.join(">");
690
+ return [parent].concat(getAncestorTagIDs(courseID, parent));
691
+ }
692
+ }
693
+ async function getChildTagStubs(courseID, tagID) {
694
+ return await filterAllDocsByPrefix(getCourseDB(courseID), tagID + ">");
695
+ }
696
+ async function getAppliedTags(id_course, id_card) {
697
+ return await getCourseDB(id_course).query("getTags", {
698
+ startkey: id_card,
699
+ endkey: id_card
700
+ });
701
+ }
702
+ async function updateCardElo(courseID, cardID, elo) {
703
+ if (elo) {
704
+ const cDB = getCourseDB(courseID);
705
+ const card = await cDB.get(cardID);
706
+ logger.debug(`Replacing ${JSON.stringify(card.elo)} with ${JSON.stringify(elo)}`);
707
+ card.elo = elo;
708
+ return cDB.put(card);
709
+ }
710
+ }
711
+ async function updateCredentialledCourseConfig(courseID, config) {
712
+ logger.debug(`Updating course config:
713
+
714
+ ${JSON.stringify(config)}
715
+ `);
716
+ const db = getCourseDB(courseID);
717
+ const old = await getCredentialledCourseConfig(courseID);
718
+ return await db.put({
719
+ ...config,
720
+ _rev: old._rev
721
+ });
722
+ }
723
+ function isSuccessRow(row) {
724
+ return "doc" in row && row.doc !== null && row.doc !== void 0;
725
+ }
726
+ //#endregion
727
+ export { CourseDB, CoursesDB, createTag, deleteTag, getAncestorTagIDs, getAppliedTags, getChildTagStubs, getCourseDataShapes, getCourseQuestionTypes, getCourseTagStubs, getCredentialledDataShapes, getTag, removeTagFromCard, updateCardElo, updateCredentialledCourseConfig, updateTag };
728
+
729
+ //# sourceMappingURL=courseDB.mjs.map