@vue-skuilder/db 0.2.21 → 0.2.23
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/{contentSource-BMxsujRu.d.cts → contentSource-BvOpKUeU.d.ts} +442 -79
- package/dist/{contentSource-Bazgkf4C.d.ts → contentSource-DT9NaX69.d.cts} +442 -79
- package/dist/core/index.d.cts +84 -342
- package/dist/core/index.d.ts +84 -342
- package/dist/core/index.js +79 -4
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.mjs +74 -4
- package/dist/core/index.mjs.map +1 -1
- package/dist/{dataLayerProvider-Bt-D6xas.d.ts → dataLayerProvider-CY2B2lyW.d.ts} +1 -1
- package/dist/{dataLayerProvider-DifVCcIS.d.cts → dataLayerProvider-wY6s_4x9.d.cts} +1 -1
- package/dist/impl/couch/index.d.cts +3 -3
- package/dist/impl/couch/index.d.ts +3 -3
- package/dist/impl/couch/index.js +63 -4
- package/dist/impl/couch/index.js.map +1 -1
- package/dist/impl/couch/index.mjs +63 -4
- package/dist/impl/couch/index.mjs.map +1 -1
- package/dist/impl/static/index.d.cts +4 -4
- package/dist/impl/static/index.d.ts +4 -4
- package/dist/impl/static/index.js +63 -4
- package/dist/impl/static/index.js.map +1 -1
- package/dist/impl/static/index.mjs +63 -4
- package/dist/impl/static/index.mjs.map +1 -1
- package/dist/{index-BLLT5BYE.d.ts → index-BkBJlGDX.d.ts} +1 -1
- package/dist/{index-k9NFHpS1.d.cts → index-D7WdMDAs.d.cts} +1 -1
- package/dist/index.d.cts +51 -14
- package/dist/index.d.ts +51 -14
- package/dist/index.js +240 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +235 -12
- package/dist/index.mjs.map +1 -1
- package/dist/{types-BFUa1pa3.d.cts → types-DjiFOZxJ.d.cts} +1 -1
- package/dist/{types-legacy-4tlwHnXo.d.cts → types-legacy-CrwyZIvI.d.cts} +10 -2
- package/dist/{types-legacy-4tlwHnXo.d.ts → types-legacy-CrwyZIvI.d.ts} +10 -2
- package/dist/{types-CHgpWQAY.d.ts → types-uJ2Xn3_X.d.ts} +1 -1
- package/dist/util/packer/index.d.cts +3 -3
- package/dist/util/packer/index.d.ts +3 -3
- package/package.json +3 -3
- package/src/core/index.ts +1 -0
- package/src/core/interfaces/userDB.ts +7 -0
- package/src/core/navigators/PipelineDebugger.ts +41 -1
- package/src/core/navigators/index.ts +3 -0
- package/src/core/types/studySession.ts +125 -0
- package/src/core/types/types-legacy.ts +8 -0
- package/src/impl/common/BaseUserDB.ts +36 -0
- package/src/study/SessionController.ts +188 -2
- package/src/study/SessionDebugger.ts +4 -3
- package/src/study/SessionOverlay.ts +1 -0
- package/src/study/services/ResponseProcessor.ts +32 -4
|
@@ -16,7 +16,8 @@ declare enum DocType {
|
|
|
16
16
|
NAVIGATION_STRATEGY = "NAVIGATION_STRATEGY",
|
|
17
17
|
STRATEGY_STATE = "STRATEGY_STATE",
|
|
18
18
|
USER_OUTCOME = "USER_OUTCOME",
|
|
19
|
-
STRATEGY_LEARNING_STATE = "STRATEGY_LEARNING_STATE"
|
|
19
|
+
STRATEGY_LEARNING_STATE = "STRATEGY_LEARNING_STATE",
|
|
20
|
+
STUDY_SESSION = "STUDY_SESSION"
|
|
20
21
|
}
|
|
21
22
|
interface QualifiedCardID {
|
|
22
23
|
courseID: string;
|
|
@@ -95,6 +96,7 @@ declare const DocTypePrefixes: {
|
|
|
95
96
|
readonly STRATEGY_STATE: "STRATEGY_STATE";
|
|
96
97
|
readonly USER_OUTCOME: "USER_OUTCOME";
|
|
97
98
|
readonly STRATEGY_LEARNING_STATE: "STRATEGY_LEARNING_STATE";
|
|
99
|
+
readonly STUDY_SESSION: "SESSION";
|
|
98
100
|
};
|
|
99
101
|
interface CardHistory<T extends CardRecord> {
|
|
100
102
|
_id: PouchDB.Core.DocumentId;
|
|
@@ -145,6 +147,12 @@ interface CardRecord {
|
|
|
145
147
|
* time of user submission.
|
|
146
148
|
*/
|
|
147
149
|
timeStamp: Moment;
|
|
150
|
+
/**
|
|
151
|
+
* The study session this response was produced in. Absent on records
|
|
152
|
+
* predating session stamping, and on responses made outside a
|
|
153
|
+
* SessionController.
|
|
154
|
+
*/
|
|
155
|
+
sessionId?: string;
|
|
148
156
|
}
|
|
149
157
|
interface QuestionRecord extends CardRecord, Evaluation {
|
|
150
158
|
userAnswer: Answer;
|
|
@@ -157,4 +165,4 @@ interface QuestionRecord extends CardRecord, Evaluation {
|
|
|
157
165
|
priorAttemps: number;
|
|
158
166
|
}
|
|
159
167
|
|
|
160
|
-
export { type CardHistory as C, DocType as D, type Field as F, GuestUsername as G, type QualifiedCardID as Q, type SkuilderCourseData as S, type TagStub as T, type Tag as a,
|
|
168
|
+
export { type CardHistory as C, DocType as D, type Field as F, GuestUsername as G, type QualifiedCardID as Q, type SkuilderCourseData as S, type TagStub as T, type Tag as a, type CardRecord as b, type QuestionRecord as c, type CardData as d, type CourseListData as e, type DisplayableData as f, type DataShapeData as g, type QuestionData as h, DocTypePrefixes as i, log as l };
|
|
@@ -16,7 +16,8 @@ declare enum DocType {
|
|
|
16
16
|
NAVIGATION_STRATEGY = "NAVIGATION_STRATEGY",
|
|
17
17
|
STRATEGY_STATE = "STRATEGY_STATE",
|
|
18
18
|
USER_OUTCOME = "USER_OUTCOME",
|
|
19
|
-
STRATEGY_LEARNING_STATE = "STRATEGY_LEARNING_STATE"
|
|
19
|
+
STRATEGY_LEARNING_STATE = "STRATEGY_LEARNING_STATE",
|
|
20
|
+
STUDY_SESSION = "STUDY_SESSION"
|
|
20
21
|
}
|
|
21
22
|
interface QualifiedCardID {
|
|
22
23
|
courseID: string;
|
|
@@ -95,6 +96,7 @@ declare const DocTypePrefixes: {
|
|
|
95
96
|
readonly STRATEGY_STATE: "STRATEGY_STATE";
|
|
96
97
|
readonly USER_OUTCOME: "USER_OUTCOME";
|
|
97
98
|
readonly STRATEGY_LEARNING_STATE: "STRATEGY_LEARNING_STATE";
|
|
99
|
+
readonly STUDY_SESSION: "SESSION";
|
|
98
100
|
};
|
|
99
101
|
interface CardHistory<T extends CardRecord> {
|
|
100
102
|
_id: PouchDB.Core.DocumentId;
|
|
@@ -145,6 +147,12 @@ interface CardRecord {
|
|
|
145
147
|
* time of user submission.
|
|
146
148
|
*/
|
|
147
149
|
timeStamp: Moment;
|
|
150
|
+
/**
|
|
151
|
+
* The study session this response was produced in. Absent on records
|
|
152
|
+
* predating session stamping, and on responses made outside a
|
|
153
|
+
* SessionController.
|
|
154
|
+
*/
|
|
155
|
+
sessionId?: string;
|
|
148
156
|
}
|
|
149
157
|
interface QuestionRecord extends CardRecord, Evaluation {
|
|
150
158
|
userAnswer: Answer;
|
|
@@ -157,4 +165,4 @@ interface QuestionRecord extends CardRecord, Evaluation {
|
|
|
157
165
|
priorAttemps: number;
|
|
158
166
|
}
|
|
159
167
|
|
|
160
|
-
export { type CardHistory as C, DocType as D, type Field as F, GuestUsername as G, type QualifiedCardID as Q, type SkuilderCourseData as S, type TagStub as T, type Tag as a,
|
|
168
|
+
export { type CardHistory as C, DocType as D, type Field as F, GuestUsername as G, type QualifiedCardID as Q, type SkuilderCourseData as S, type TagStub as T, type Tag as a, type CardRecord as b, type QuestionRecord as c, type CardData as d, type CourseListData as e, type DisplayableData as f, type DataShapeData as g, type QuestionData as h, DocTypePrefixes as i, log as l };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-
|
|
2
|
-
export { C as CouchDBToStaticPacker } from '../../index-
|
|
1
|
+
export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-DjiFOZxJ.cjs';
|
|
2
|
+
export { C as CouchDBToStaticPacker } from '../../index-D7WdMDAs.cjs';
|
|
3
3
|
import '@vue-skuilder/common';
|
|
4
|
-
import '../../types-legacy-
|
|
4
|
+
import '../../types-legacy-CrwyZIvI.cjs';
|
|
5
5
|
import 'moment';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-
|
|
2
|
-
export { C as CouchDBToStaticPacker } from '../../index-
|
|
1
|
+
export { A as AttachmentData, C as ChunkMetadata, D as DesignDocument, I as IndexMetadata, a as PackedCourseData, P as PackerConfig, S as StaticCourseManifest } from '../../types-uJ2Xn3_X.js';
|
|
2
|
+
export { C as CouchDBToStaticPacker } from '../../index-BkBJlGDX.js';
|
|
3
3
|
import '@vue-skuilder/common';
|
|
4
|
-
import '../../types-legacy-
|
|
4
|
+
import '../../types-legacy-CrwyZIvI.js';
|
|
5
5
|
import 'moment';
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.2.
|
|
7
|
+
"version": "0.2.23",
|
|
8
8
|
"description": "Database layer for vue-skuilder",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/index.mjs",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@nilock2/pouchdb-authentication": "^1.0.2",
|
|
51
|
-
"@vue-skuilder/common": "0.2.
|
|
51
|
+
"@vue-skuilder/common": "0.2.23",
|
|
52
52
|
"cross-fetch": "^4.1.0",
|
|
53
53
|
"moment": "^2.29.4",
|
|
54
54
|
"pouchdb": "^9.0.0",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"vite": "^8.0.0",
|
|
64
64
|
"vitest": "^4.1.0"
|
|
65
65
|
},
|
|
66
|
-
"stableVersion": "0.2.
|
|
66
|
+
"stableVersion": "0.2.23"
|
|
67
67
|
}
|
package/src/core/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from './types/types-legacy';
|
|
|
5
5
|
export * from './types/user';
|
|
6
6
|
export * from './types/strategyState';
|
|
7
7
|
export * from './types/userOutcome';
|
|
8
|
+
export * from './types/studySession';
|
|
8
9
|
export * from './types/hydration';
|
|
9
10
|
export * from '../util/Loggable';
|
|
10
11
|
export * from './util';
|
|
@@ -8,6 +8,7 @@ import { CourseElo, Status } from '@vue-skuilder/common';
|
|
|
8
8
|
import { Moment } from 'moment';
|
|
9
9
|
import { CardHistory, CardRecord, QualifiedCardID } from '../types/types-legacy';
|
|
10
10
|
import { UserOutcomeRecord } from '../types/userOutcome';
|
|
11
|
+
import { StudySessionDoc } from '../types/studySession';
|
|
11
12
|
import { UserConfig } from '../types/user';
|
|
12
13
|
import { UserHydrationStatus } from '../types/hydration';
|
|
13
14
|
import { DocumentUpdater } from '@db/study';
|
|
@@ -79,6 +80,9 @@ export interface UserDBReader {
|
|
|
79
80
|
*/
|
|
80
81
|
getPendingReviews(courseId?: string): Promise<ScheduledCard[]>;
|
|
81
82
|
|
|
83
|
+
/** Study-session records for a course, newest session-start first. */
|
|
84
|
+
getStudySessions(courseId?: string): Promise<StudySessionDoc[]>;
|
|
85
|
+
|
|
82
86
|
/**
|
|
83
87
|
* Get all scheduled reviews due within the next `daysCount` days —
|
|
84
88
|
* including ones not yet due. `getPendingReviews` is the `daysCount = 0`
|
|
@@ -215,6 +219,9 @@ export interface UserDBWriter extends DocumentUpdater {
|
|
|
215
219
|
* Record a user learning outcome for evolutionary orchestration.
|
|
216
220
|
*/
|
|
217
221
|
putUserOutcome(record: UserOutcomeRecord): Promise<void>;
|
|
222
|
+
|
|
223
|
+
/** Write or overwrite a study-session record. */
|
|
224
|
+
putStudySession(doc: StudySessionDoc): Promise<void>;
|
|
218
225
|
}
|
|
219
226
|
|
|
220
227
|
/**
|
|
@@ -79,6 +79,8 @@ export interface FilterImpact {
|
|
|
79
79
|
*/
|
|
80
80
|
export interface PipelineRunReport {
|
|
81
81
|
runId: string;
|
|
82
|
+
/** Absent for runs fired outside a session (forecasts, editor probes). */
|
|
83
|
+
sessionId?: string;
|
|
82
84
|
timestamp: Date;
|
|
83
85
|
courseId: string;
|
|
84
86
|
courseName?: string;
|
|
@@ -155,6 +157,38 @@ export interface PipelineRunReport {
|
|
|
155
157
|
const MAX_RUNS = 10;
|
|
156
158
|
const runHistory: PipelineRunReport[] = [];
|
|
157
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Ambient, like `registerPipelineForDebug` — a pipeline is per content-source
|
|
162
|
+
* and can outlive any one session. Set by `SessionController`.
|
|
163
|
+
*/
|
|
164
|
+
let _currentSessionId: string | undefined;
|
|
165
|
+
|
|
166
|
+
export function setDebugSessionId(sessionId: string | undefined): void {
|
|
167
|
+
_currentSessionId = sessionId;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Runs captured since the last drain. `SessionController` drains after each
|
|
172
|
+
* plan and applies its own label — one plan can be several runs (one per
|
|
173
|
+
* source), and the label is the controller's knowledge, not the pipeline's.
|
|
174
|
+
*/
|
|
175
|
+
let _pendingRuns: PipelineRunReport[] = [];
|
|
176
|
+
|
|
177
|
+
/** Take and clear the runs captured since the previous call, in execution order. */
|
|
178
|
+
export function drainCapturedRuns(): PipelineRunReport[] {
|
|
179
|
+
const drained = _pendingRuns;
|
|
180
|
+
_pendingRuns = [];
|
|
181
|
+
return drained;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Runs for `sessionId`, oldest first. Bounded by {@link MAX_RUNS} — the
|
|
186
|
+
* complete record is `StudySessionDoc.runs`.
|
|
187
|
+
*/
|
|
188
|
+
export function getRunsForSession(sessionId: string): PipelineRunReport[] {
|
|
189
|
+
return runHistory.filter((r) => r.sessionId === sessionId).reverse();
|
|
190
|
+
}
|
|
191
|
+
|
|
158
192
|
/**
|
|
159
193
|
* Cap on non-selected ("discarded") cards retained per run report.
|
|
160
194
|
*
|
|
@@ -177,6 +211,7 @@ const DISCARDED_KEEP_TOP = 25;
|
|
|
177
211
|
*/
|
|
178
212
|
export function clearRunHistory(): void {
|
|
179
213
|
runHistory.length = 0;
|
|
214
|
+
_pendingRuns = [];
|
|
180
215
|
}
|
|
181
216
|
|
|
182
217
|
/**
|
|
@@ -196,10 +231,13 @@ function getOrigin(card: WeightedCard): 'new' | 'review' | 'unknown' {
|
|
|
196
231
|
/**
|
|
197
232
|
* Capture a pipeline run for later inspection.
|
|
198
233
|
*/
|
|
199
|
-
export function captureRun(
|
|
234
|
+
export function captureRun(
|
|
235
|
+
report: Omit<PipelineRunReport, 'runId' | 'timestamp' | 'sessionId'>
|
|
236
|
+
): PipelineRunReport {
|
|
200
237
|
const fullReport: PipelineRunReport = {
|
|
201
238
|
...report,
|
|
202
239
|
runId: `run-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
240
|
+
sessionId: _currentSessionId,
|
|
203
241
|
timestamp: new Date(),
|
|
204
242
|
};
|
|
205
243
|
|
|
@@ -207,6 +245,8 @@ export function captureRun(report: Omit<PipelineRunReport, 'runId' | 'timestamp'
|
|
|
207
245
|
if (runHistory.length > MAX_RUNS) {
|
|
208
246
|
runHistory.pop();
|
|
209
247
|
}
|
|
248
|
+
_pendingRuns.push(fullReport);
|
|
249
|
+
return fullReport;
|
|
210
250
|
}
|
|
211
251
|
|
|
212
252
|
/**
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { DocType, DocTypePrefixes } from './types-legacy';
|
|
2
|
+
import type { ReplanHints } from '../navigators/generators/types';
|
|
3
|
+
import type { GeneratorSummary, FilterImpact } from '../navigators/PipelineDebugger';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Durable per-sitting record. Join target for `CardRecord.sessionId`.
|
|
7
|
+
*
|
|
8
|
+
* Written twice: `open` at `prepareSession()`, overwritten at termination.
|
|
9
|
+
*/
|
|
10
|
+
export interface StudySessionDoc {
|
|
11
|
+
/** `SESSION::{courseId}::{userId}::{sessionId}` */
|
|
12
|
+
_id: string;
|
|
13
|
+
_rev?: string;
|
|
14
|
+
docType: DocType.STUDY_SESSION;
|
|
15
|
+
|
|
16
|
+
sessionId: string;
|
|
17
|
+
courseId: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
|
|
20
|
+
/** Session construction time, not first-card time. */
|
|
21
|
+
startTime: string;
|
|
22
|
+
endTime?: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `closed` — ran to natural termination.
|
|
26
|
+
* `abandoned` — host tore the study view down mid-session.
|
|
27
|
+
* `open` — never closed: tab closed, reload, crash. No tally or end state.
|
|
28
|
+
*/
|
|
29
|
+
status: 'open' | 'closed' | 'abandoned';
|
|
30
|
+
|
|
31
|
+
plannedSeconds: number;
|
|
32
|
+
|
|
33
|
+
config: {
|
|
34
|
+
defaultBatchLimit: number;
|
|
35
|
+
sourceCount: number;
|
|
36
|
+
initHints?: ReplanHints | null;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** Queue depths after the bootstrap run, before the first draw. */
|
|
40
|
+
initialQueues: { supplyQ: number; failedQ: number };
|
|
41
|
+
|
|
42
|
+
tally?: {
|
|
43
|
+
/** Distinct cards; a re-presented failed card counts once. */
|
|
44
|
+
cardsPresented: number;
|
|
45
|
+
/** Total responses, including repeat attempts on one card. */
|
|
46
|
+
responses: number;
|
|
47
|
+
correct: number;
|
|
48
|
+
incorrect: number;
|
|
49
|
+
failedQRemaining: number;
|
|
50
|
+
secondsRemaining: number;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/** Bootstrap run plus every replan, in execution order. */
|
|
54
|
+
runs?: StudySessionRunSummary[];
|
|
55
|
+
|
|
56
|
+
finalHints?: ReplanHints | null;
|
|
57
|
+
|
|
58
|
+
stateAtStart?: SessionStateSnapshot;
|
|
59
|
+
stateAtEnd?: SessionStateSnapshot;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface StudySessionRunSummary {
|
|
63
|
+
/** Joins to `PipelineRunReport.runId` while that run is still in memory. */
|
|
64
|
+
runId: string;
|
|
65
|
+
at: string;
|
|
66
|
+
/** `'bootstrap'`, a replan's label, or `'(auto)'`. */
|
|
67
|
+
label: string;
|
|
68
|
+
mode?: string;
|
|
69
|
+
generatedCount: number;
|
|
70
|
+
finalCount: number;
|
|
71
|
+
reviewsSelected: number;
|
|
72
|
+
newSelected: number;
|
|
73
|
+
|
|
74
|
+
// --- Detail projected from PipelineRunReport at record time ------------
|
|
75
|
+
// These make a run self-explanatory after the in-memory ring buffer that
|
|
76
|
+
// holds the full `PipelineRunReport` has rolled over (MAX_RUNS=10) — which
|
|
77
|
+
// is almost always, by the time anyone reads a persisted session. The
|
|
78
|
+
// multi-KB per-card provenance trail is deliberately NOT persisted; only
|
|
79
|
+
// the compact phase summaries are. All optional: absent on runs recorded
|
|
80
|
+
// before this shipped, and on any run whose report lacked the field.
|
|
81
|
+
|
|
82
|
+
/** User's global ELO at the moment this run's pipeline executed. */
|
|
83
|
+
userElo?: number;
|
|
84
|
+
/** Per-generator contribution (name, card/new/review counts, top score). */
|
|
85
|
+
generators?: GeneratorSummary[];
|
|
86
|
+
/** Per-filter impact (boosted / penalized / passed / removed). */
|
|
87
|
+
filters?: FilterImpact[];
|
|
88
|
+
/** Ephemeral replan hints in force for this run (what the navigator was told). */
|
|
89
|
+
hints?: ReplanHints;
|
|
90
|
+
/** Compact summary of the scored-but-dropped candidate tail. */
|
|
91
|
+
discardedTail?: {
|
|
92
|
+
count: number;
|
|
93
|
+
scoreRange?: [number, number];
|
|
94
|
+
eloRange?: [number, number];
|
|
95
|
+
note: string;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Host-defined learner state at a session boundary. Keep it thin — this is
|
|
101
|
+
* written on every session, and the deltas between consecutive snapshots are
|
|
102
|
+
* what it's read for.
|
|
103
|
+
*/
|
|
104
|
+
export type SessionStateSnapshot = Record<string, unknown>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Invoked at session open and close. Errors and slow calls are absorbed by
|
|
108
|
+
* the controller.
|
|
109
|
+
*/
|
|
110
|
+
export type SessionStateSnapshotProvider = (
|
|
111
|
+
phase: 'start' | 'end'
|
|
112
|
+
) => SessionStateSnapshot | Promise<SessionStateSnapshot>;
|
|
113
|
+
|
|
114
|
+
/** Stable across the open and close writes, unlike a timestamp-keyed id. */
|
|
115
|
+
export function makeStudySessionId(
|
|
116
|
+
courseId: string,
|
|
117
|
+
userId: string,
|
|
118
|
+
sessionId: string
|
|
119
|
+
): string {
|
|
120
|
+
return `${DocTypePrefixes[DocType.STUDY_SESSION]}::${courseId}::${userId}::${sessionId}`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function newSessionId(): string {
|
|
124
|
+
return `session-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
125
|
+
}
|
|
@@ -22,6 +22,7 @@ export enum DocType {
|
|
|
22
22
|
STRATEGY_STATE = 'STRATEGY_STATE',
|
|
23
23
|
USER_OUTCOME = 'USER_OUTCOME',
|
|
24
24
|
STRATEGY_LEARNING_STATE = 'STRATEGY_LEARNING_STATE',
|
|
25
|
+
STUDY_SESSION = 'STUDY_SESSION',
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export interface QualifiedCardID {
|
|
@@ -109,6 +110,7 @@ export const DocTypePrefixes = {
|
|
|
109
110
|
[DocType.STRATEGY_STATE]: 'STRATEGY_STATE',
|
|
110
111
|
[DocType.USER_OUTCOME]: 'USER_OUTCOME',
|
|
111
112
|
[DocType.STRATEGY_LEARNING_STATE]: 'STRATEGY_LEARNING_STATE',
|
|
113
|
+
[DocType.STUDY_SESSION]: 'SESSION',
|
|
112
114
|
} as const;
|
|
113
115
|
|
|
114
116
|
export interface CardHistory<T extends CardRecord> {
|
|
@@ -166,6 +168,12 @@ export interface CardRecord {
|
|
|
166
168
|
* time of user submission.
|
|
167
169
|
*/
|
|
168
170
|
timeStamp: Moment;
|
|
171
|
+
/**
|
|
172
|
+
* The study session this response was produced in. Absent on records
|
|
173
|
+
* predating session stamping, and on responses made outside a
|
|
174
|
+
* SessionController.
|
|
175
|
+
*/
|
|
176
|
+
sessionId?: string;
|
|
169
177
|
}
|
|
170
178
|
|
|
171
179
|
export interface QuestionRecord extends CardRecord, Evaluation {
|
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
import { DocumentUpdater } from '@db/study';
|
|
30
30
|
import { CardHistory, CardRecord } from '../../core/types/types-legacy';
|
|
31
31
|
import { UserOutcomeRecord } from '../../core/types/userOutcome';
|
|
32
|
+
import { StudySessionDoc } from '../../core/types/studySession';
|
|
32
33
|
import type { SyncStrategy } from './SyncStrategy';
|
|
33
34
|
import {
|
|
34
35
|
filterAllDocsByPrefix,
|
|
@@ -1364,6 +1365,41 @@ Currently logged-in as ${this._username}.`
|
|
|
1364
1365
|
await this.localDB.put(doc);
|
|
1365
1366
|
}
|
|
1366
1367
|
|
|
1368
|
+
/**
|
|
1369
|
+
* Open and close write the same `_id`, so the 409 path is the expected
|
|
1370
|
+
* route for the second write, not an error case.
|
|
1371
|
+
*/
|
|
1372
|
+
public async putStudySession(doc: StudySessionDoc): Promise<void> {
|
|
1373
|
+
try {
|
|
1374
|
+
await this.localDB.put(doc);
|
|
1375
|
+
} catch (err: any) {
|
|
1376
|
+
if (err.status === 409) {
|
|
1377
|
+
const existing = await this.localDB.get(doc._id);
|
|
1378
|
+
await this.localDB.put({ ...doc, _rev: existing._rev });
|
|
1379
|
+
} else {
|
|
1380
|
+
throw err;
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
public async getStudySessions(courseId?: string): Promise<StudySessionDoc[]> {
|
|
1386
|
+
const prefix = courseId
|
|
1387
|
+
? `${DocTypePrefixes[DocType.STUDY_SESSION]}::${courseId}::`
|
|
1388
|
+
: `${DocTypePrefixes[DocType.STUDY_SESSION]}::`;
|
|
1389
|
+
const keys = getStartAndEndKeys(prefix);
|
|
1390
|
+
|
|
1391
|
+
const res = await this.localDB.allDocs<StudySessionDoc>({
|
|
1392
|
+
startkey: keys.startkey,
|
|
1393
|
+
endkey: keys.endkey,
|
|
1394
|
+
include_docs: true,
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
return res.rows
|
|
1398
|
+
.map((r) => r.doc)
|
|
1399
|
+
.filter((d): d is StudySessionDoc & PouchDB.Core.RevisionIdMeta => !!d)
|
|
1400
|
+
.sort((a, b) => b.startTime.localeCompare(a.startTime));
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1367
1403
|
public async putUserOutcome(record: UserOutcomeRecord): Promise<void> {
|
|
1368
1404
|
try {
|
|
1369
1405
|
await this.localDB.put(record);
|