@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
package/dist/impl/couch/index.js
CHANGED
|
@@ -151,6 +151,33 @@ var init_updateQueue = __esm({
|
|
|
151
151
|
// Database for read operations
|
|
152
152
|
writeDB;
|
|
153
153
|
// Database for write operations (local-first)
|
|
154
|
+
/**
|
|
155
|
+
* Queues an update for a document and applies it with conflict resolution.
|
|
156
|
+
*
|
|
157
|
+
* @param id - Document ID to update
|
|
158
|
+
* @param update - Partial object or function that transforms the document
|
|
159
|
+
* @returns Promise resolving to the updated document
|
|
160
|
+
*
|
|
161
|
+
* @throws {PouchError} with status 404 if document doesn't exist
|
|
162
|
+
*
|
|
163
|
+
* @remarks
|
|
164
|
+
* **Error Handling Pattern:**
|
|
165
|
+
* - This method does NOT create documents if they don't exist
|
|
166
|
+
* - Callers are responsible for handling 404 errors and creating documents
|
|
167
|
+
* - This design maintains separation of concerns (UpdateQueue handles conflicts, callers handle lifecycle)
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* try {
|
|
172
|
+
* await updateQueue.update(docId, (doc) => ({ ...doc, field: newValue }));
|
|
173
|
+
* } catch (e) {
|
|
174
|
+
* if ((e as PouchError).status === 404) {
|
|
175
|
+
* // Create the document with initial values
|
|
176
|
+
* await db.put({ _id: docId, field: newValue, ...initialFields });
|
|
177
|
+
* }
|
|
178
|
+
* }
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
154
181
|
update(id, update) {
|
|
155
182
|
logger.debug(`Update requested on doc: ${id}`);
|
|
156
183
|
if (this.pendingUpdates[id]) {
|
|
@@ -183,7 +210,6 @@ var init_updateQueue = __esm({
|
|
|
183
210
|
for (let i = 0; i < MAX_RETRIES; i++) {
|
|
184
211
|
try {
|
|
185
212
|
const doc = await this.readDB.get(id);
|
|
186
|
-
logger.debug(`Retrieved doc: ${id}`);
|
|
187
213
|
let updatedDoc = { ...doc };
|
|
188
214
|
const updatesToApply = [...this.pendingUpdates[id]];
|
|
189
215
|
for (const update of updatesToApply) {
|
|
@@ -197,7 +223,6 @@ var init_updateQueue = __esm({
|
|
|
197
223
|
}
|
|
198
224
|
}
|
|
199
225
|
await this.writeDB.put(updatedDoc);
|
|
200
|
-
logger.debug(`Put doc: ${id}`);
|
|
201
226
|
this.pendingUpdates[id].splice(0, updatesToApply.length);
|
|
202
227
|
if (this.pendingUpdates[id].length === 0) {
|
|
203
228
|
this.inprogressUpdates[id] = false;
|
|
@@ -212,6 +237,7 @@ var init_updateQueue = __esm({
|
|
|
212
237
|
await new Promise((res) => setTimeout(res, 50 * Math.random()));
|
|
213
238
|
} else if (e.name === "not_found" && i === 0) {
|
|
214
239
|
logger.warn(`Update failed for ${id} - does not exist. Throwing to caller.`);
|
|
240
|
+
delete this.inprogressUpdates[id];
|
|
215
241
|
throw e;
|
|
216
242
|
} else {
|
|
217
243
|
delete this.inprogressUpdates[id];
|
|
@@ -2745,12 +2771,22 @@ Currently logged-in as ${this._username}.`
|
|
|
2745
2771
|
}
|
|
2746
2772
|
/**
|
|
2747
2773
|
* Logs a record of the user's interaction with the card and returns the card's
|
|
2748
|
-
* up-to-date history
|
|
2774
|
+
* up-to-date history.
|
|
2775
|
+
*
|
|
2776
|
+
* **Automatic Initialization:**
|
|
2777
|
+
* If this is the user's first interaction with the card (CardHistory doesn't exist),
|
|
2778
|
+
* this method automatically creates the CardHistory document with initial values
|
|
2779
|
+
* (lapses: 0, streak: 0, bestInterval: 0).
|
|
2780
|
+
*
|
|
2781
|
+
* **Error Handling:**
|
|
2782
|
+
* - Handles 404 errors by creating initial CardHistory document
|
|
2783
|
+
* - Re-throws all other errors from UpdateQueue
|
|
2749
2784
|
*
|
|
2750
2785
|
* // [ ] #db-refactor extract to a smaller scope - eg, UserStudySession
|
|
2751
2786
|
*
|
|
2752
|
-
* @param record
|
|
2787
|
+
* @param record - The recent recorded interaction between user and card
|
|
2753
2788
|
* @returns The updated state of the card's CardHistory data
|
|
2789
|
+
* @throws Error if document creation fails or non-404 database error occurs
|
|
2754
2790
|
*/
|
|
2755
2791
|
async putCardRecord(record) {
|
|
2756
2792
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|