@vue-skuilder/db 0.1.14-2 → 0.1.15
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/core/index.js +40 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +40 -4
- package/dist/core/index.mjs.map +1 -1
- package/dist/impl/couch/index.js +40 -4
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +40 -4
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.mts +3 -1
- package/dist/impl/static/index.d.ts +3 -1
- package/dist/impl/static/index.js +71 -13
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +71 -13
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/index.d.mts +38 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +149 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +149 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/impl/common/BaseUserDB.ts +12 -2
- package/src/impl/couch/updateQueue.ts +28 -2
- package/src/impl/static/StaticDataLayerProvider.ts +32 -8
- package/src/impl/static/coursesDB.ts +15 -2
- package/src/study/SessionController.ts +50 -0
- package/src/study/services/CardHydrationService.ts +7 -0
- package/src/study/services/ResponseProcessor.ts +64 -25
|
@@ -129,6 +129,33 @@ var init_updateQueue = __esm({
|
|
|
129
129
|
// Database for read operations
|
|
130
130
|
writeDB;
|
|
131
131
|
// Database for write operations (local-first)
|
|
132
|
+
/**
|
|
133
|
+
* Queues an update for a document and applies it with conflict resolution.
|
|
134
|
+
*
|
|
135
|
+
* @param id - Document ID to update
|
|
136
|
+
* @param update - Partial object or function that transforms the document
|
|
137
|
+
* @returns Promise resolving to the updated document
|
|
138
|
+
*
|
|
139
|
+
* @throws {PouchError} with status 404 if document doesn't exist
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* **Error Handling Pattern:**
|
|
143
|
+
* - This method does NOT create documents if they don't exist
|
|
144
|
+
* - Callers are responsible for handling 404 errors and creating documents
|
|
145
|
+
* - This design maintains separation of concerns (UpdateQueue handles conflicts, callers handle lifecycle)
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* try {
|
|
150
|
+
* await updateQueue.update(docId, (doc) => ({ ...doc, field: newValue }));
|
|
151
|
+
* } catch (e) {
|
|
152
|
+
* if ((e as PouchError).status === 404) {
|
|
153
|
+
* // Create the document with initial values
|
|
154
|
+
* await db.put({ _id: docId, field: newValue, ...initialFields });
|
|
155
|
+
* }
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
132
159
|
update(id, update) {
|
|
133
160
|
logger.debug(`Update requested on doc: ${id}`);
|
|
134
161
|
if (this.pendingUpdates[id]) {
|
|
@@ -161,7 +188,6 @@ var init_updateQueue = __esm({
|
|
|
161
188
|
for (let i = 0; i < MAX_RETRIES; i++) {
|
|
162
189
|
try {
|
|
163
190
|
const doc = await this.readDB.get(id);
|
|
164
|
-
logger.debug(`Retrieved doc: ${id}`);
|
|
165
191
|
let updatedDoc = { ...doc };
|
|
166
192
|
const updatesToApply = [...this.pendingUpdates[id]];
|
|
167
193
|
for (const update of updatesToApply) {
|
|
@@ -175,7 +201,6 @@ var init_updateQueue = __esm({
|
|
|
175
201
|
}
|
|
176
202
|
}
|
|
177
203
|
await this.writeDB.put(updatedDoc);
|
|
178
|
-
logger.debug(`Put doc: ${id}`);
|
|
179
204
|
this.pendingUpdates[id].splice(0, updatesToApply.length);
|
|
180
205
|
if (this.pendingUpdates[id].length === 0) {
|
|
181
206
|
this.inprogressUpdates[id] = false;
|
|
@@ -190,6 +215,7 @@ var init_updateQueue = __esm({
|
|
|
190
215
|
await new Promise((res) => setTimeout(res, 50 * Math.random()));
|
|
191
216
|
} else if (e.name === "not_found" && i === 0) {
|
|
192
217
|
logger.warn(`Update failed for ${id} - does not exist. Throwing to caller.`);
|
|
218
|
+
delete this.inprogressUpdates[id];
|
|
193
219
|
throw e;
|
|
194
220
|
} else {
|
|
195
221
|
delete this.inprogressUpdates[id];
|
|
@@ -2726,12 +2752,22 @@ Currently logged-in as ${this._username}.`
|
|
|
2726
2752
|
}
|
|
2727
2753
|
/**
|
|
2728
2754
|
* Logs a record of the user's interaction with the card and returns the card's
|
|
2729
|
-
* up-to-date history
|
|
2755
|
+
* up-to-date history.
|
|
2756
|
+
*
|
|
2757
|
+
* **Automatic Initialization:**
|
|
2758
|
+
* If this is the user's first interaction with the card (CardHistory doesn't exist),
|
|
2759
|
+
* this method automatically creates the CardHistory document with initial values
|
|
2760
|
+
* (lapses: 0, streak: 0, bestInterval: 0).
|
|
2761
|
+
*
|
|
2762
|
+
* **Error Handling:**
|
|
2763
|
+
* - Handles 404 errors by creating initial CardHistory document
|
|
2764
|
+
* - Re-throws all other errors from UpdateQueue
|
|
2730
2765
|
*
|
|
2731
2766
|
* // [ ] #db-refactor extract to a smaller scope - eg, UserStudySession
|
|
2732
2767
|
*
|
|
2733
|
-
* @param record
|
|
2768
|
+
* @param record - The recent recorded interaction between user and card
|
|
2734
2769
|
* @returns The updated state of the card's CardHistory data
|
|
2770
|
+
* @throws Error if document creation fails or non-404 database error occurs
|
|
2735
2771
|
*/
|
|
2736
2772
|
async putCardRecord(record) {
|
|
2737
2773
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|