@qti-components/delivery 0.1.0-next.1 → 0.1.0-next.10

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/index.d.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  export * from './model/test-model.js';
2
2
  export * from './model/item-facts.js';
3
3
  export type { XmlElement, XmlNode } from './model/xml-node.js';
4
+ export * from './lifecycle/item-lifecycle.js';
5
+ export * from './lifecycle/item-rules.js';
6
+ export * from './lifecycle/item-session.js';
4
7
  export * from './random/seeded-random.js';
8
+ export * from './random/selection.js';
5
9
  export * from './random/shuffle.js';
6
10
  export * from './state/clock.js';
7
11
  export * from './state/commands.js';
8
12
  export * from './state/create-delivery-state.js';
9
13
  export * from './state/delivery-state.js';
10
14
  export * from './processing.js';
15
+ export * from './timing/timing.js';
16
+ export * from './timing/time-limits.js';
package/dist/index.js CHANGED
@@ -1,10 +1,16 @@
1
1
  export * from './model/test-model.js';
2
2
  export * from './model/item-facts.js';
3
+ export * from './lifecycle/item-lifecycle.js';
4
+ export * from './lifecycle/item-rules.js';
5
+ export * from './lifecycle/item-session.js';
3
6
  export * from './random/seeded-random.js';
7
+ export * from './random/selection.js';
4
8
  export * from './random/shuffle.js';
5
9
  export * from './state/clock.js';
6
10
  export * from './state/commands.js';
7
11
  export * from './state/create-delivery-state.js';
8
12
  export * from './state/delivery-state.js';
9
13
  export * from './processing.js';
14
+ export * from './timing/timing.js';
15
+ export * from './timing/time-limits.js';
10
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport * from './model/item-facts.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './random/seeded-random.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport * from './model/item-facts.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './lifecycle/item-lifecycle.js';\nexport * from './lifecycle/item-rules.js';\nexport * from './lifecycle/item-session.js';\nexport * from './random/seeded-random.js';\nexport * from './random/selection.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\nexport * from './timing/timing.js';\nexport * from './timing/time-limits.js';\n"]}
@@ -0,0 +1,108 @@
1
+ import type { SessionControl, TestPartModel } from '../model/test-model.js';
2
+ /**
3
+ * The item session lifecycle (QTI 3 info model §2.2.1, Figure 2.1) as one finite state machine per
4
+ * item instance: every item session is in exactly one of these states, and only the transitions in
5
+ * `ITEM_LIFECYCLE` happen. Each rule of item session control is a guard on one of them.
6
+ *
7
+ * ```mermaid
8
+ * stateDiagram-v2
9
+ * [*] --> initial
10
+ * initial --> interacting: beginAttempt [attemptsLeft]
11
+ * initial --> closed: endItemSession
12
+ * interacting --> closed: endAttempt [individualSubmission, no attemptsLeft]
13
+ * interacting --> modalFeedback: endAttempt [individualSubmission, attemptsLeft, modalFeedback]
14
+ * interacting --> interacting: endAttempt [individualSubmission, attemptsLeft]
15
+ * interacting --> suspended: endCandidateSession
16
+ * interacting --> closed: endItemSession
17
+ * modalFeedback --> interacting: beginAttempt [attemptsLeft]
18
+ * modalFeedback --> suspended: endCandidateSession
19
+ * modalFeedback --> closed: endItemSession
20
+ * suspended --> interacting: beginCandidateSession [mayResume]
21
+ * suspended --> closed: endItemSession
22
+ * closed --> review: beginReview [allowReview]
23
+ * review --> closed: endReview
24
+ * closed --> solution: beginSolution [showSolution]
25
+ * solution --> closed: endSolution
26
+ * ```
27
+ *
28
+ * What QTI ties to the states: interactions are enabled in `interacting` only; in `closed` and
29
+ * `review` the responses show but are fixed; in `solution` the correct responses show instead. An
30
+ * item that goes from `initial` straight to `closed` keeps NULL responses.
31
+ *
32
+ * The text of §2.2.1 names six states; `modalFeedback` comes from its figure (Figure 2.1, as this
33
+ * plan reads it): the item after an attempt whose response processing set modal feedback, with
34
+ * attempts left ("modal feedback is shown to the candidate directly following response
35
+ * processing", §2.6). The candidate reads it before trying again.
36
+ *
37
+ * Experimental (0.x): roadmap 1 phase T3; see `plans/delivery-state.md`.
38
+ */
39
+ export declare const ITEM_LIFECYCLE_STATES: readonly ["initial", "interacting", "modalFeedback", "suspended", "closed", "review", "solution"];
40
+ export type ItemLifecycleState = (typeof ITEM_LIFECYCLE_STATES)[number];
41
+ /**
42
+ * What happens to an item session, in QTI's words (info model §2.2.1). The delivery's commands
43
+ * (`navigate`, `beginAttempt`, `endAttempt`, `endTestPart`, `timeUp`) are turned into these, per item.
44
+ */
45
+ export declare const ITEM_LIFECYCLE_EVENTS: readonly ["beginAttempt", "endAttempt", "endCandidateSession", "beginCandidateSession", "endItemSession", "beginReview", "endReview", "beginSolution", "endSolution"];
46
+ export type ItemLifecycleEvent = (typeof ITEM_LIFECYCLE_EVENTS)[number];
47
+ /** The conditions a transition can depend on; `itemLifecycleGuards` reads them for one item. */
48
+ export declare const ITEM_LIFECYCLE_GUARDS: readonly ["attemptsLeft", "individualSubmission", "modalFeedback", "mayResume", "allowReview", "showSolution"];
49
+ export type ItemLifecycleGuard = (typeof ITEM_LIFECYCLE_GUARDS)[number];
50
+ export type ItemLifecycleGuards = Readonly<Record<ItemLifecycleGuard, boolean>>;
51
+ /** One way out of a state: taken when every `when` guard holds and no `unless` guard does. */
52
+ export interface ItemLifecycleBranch {
53
+ readonly to: ItemLifecycleState;
54
+ readonly when?: readonly ItemLifecycleGuard[];
55
+ readonly unless?: readonly ItemLifecycleGuard[];
56
+ }
57
+ /** A state with no guard, or branches tried in order, the first that holds taken. */
58
+ export type ItemLifecycleTarget = ItemLifecycleState | readonly ItemLifecycleBranch[];
59
+ /** The transition table: a pair it does not list is refused. */
60
+ export declare const ITEM_LIFECYCLE: Readonly<Record<ItemLifecycleState, Readonly<Partial<Record<ItemLifecycleEvent, ItemLifecycleTarget>>>>>;
61
+ /**
62
+ * The state an item session goes to on `event`, or null when the table refuses it: the pair is not
63
+ * listed, or no branch's guards hold. Pure: the same state, event and guards give the same answer
64
+ * on every runtime.
65
+ */
66
+ export declare function transition(state: ItemLifecycleState, event: ItemLifecycleEvent, guards: ItemLifecycleGuards): ItemLifecycleState | null;
67
+ /** What the guards of one item session are read from. */
68
+ export interface ItemLifecycleInput {
69
+ /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */
70
+ sessionControl: Pick<SessionControl, 'maxAttempts' | 'allowReview' | 'showSolution'>;
71
+ /** From the item's facts (`ItemFacts.adaptive`). */
72
+ adaptive: boolean;
73
+ navigationMode: TestPartModel['navigationMode'];
74
+ submissionMode: TestPartModel['submissionMode'];
75
+ /**
76
+ * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this
77
+ * delivery counts it when it ends, and T3d keeps that (`plans/delivery-state.md`).
78
+ */
79
+ numAttempts: number;
80
+ /** The item's `completionStatus` (`not_attempted`, `unknown`, `incomplete`, `completed`). */
81
+ completionStatus: string | null;
82
+ /** The candidate has moved on from the item; in a linear part there is no way back. */
83
+ left: boolean;
84
+ /** The last response processing set modal feedback to show. */
85
+ modalFeedback: boolean;
86
+ }
87
+ /**
88
+ * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it
89
+ * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its
90
+ * response processing set `completionStatus` to `completed`.
91
+ */
92
+ export declare function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus }: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>): boolean;
93
+ /** The guards of one item session, from its session control, its facts, its part and its variables. */
94
+ export declare function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards;
95
+ /** What a version 1 state, or a test restored from one, tells about an item session. */
96
+ export interface ItemLifecycleSeedInput extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> {
97
+ /** The item is on screen: the current item, or one of the section on screen with `navigate="section"`. */
98
+ presented: boolean;
99
+ /** The item comes before the current one in a linear part: the candidate has left it for good. */
100
+ passed: boolean;
101
+ }
102
+ /**
103
+ * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored
104
+ * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part
105
+ * has passed it; interacting when it is on screen; initial before its first ended attempt; else
106
+ * suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
107
+ */
108
+ export declare function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState;
@@ -0,0 +1,157 @@
1
+ /**
2
+ * The item session lifecycle (QTI 3 info model §2.2.1, Figure 2.1) as one finite state machine per
3
+ * item instance: every item session is in exactly one of these states, and only the transitions in
4
+ * `ITEM_LIFECYCLE` happen. Each rule of item session control is a guard on one of them.
5
+ *
6
+ * ```mermaid
7
+ * stateDiagram-v2
8
+ * [*] --> initial
9
+ * initial --> interacting: beginAttempt [attemptsLeft]
10
+ * initial --> closed: endItemSession
11
+ * interacting --> closed: endAttempt [individualSubmission, no attemptsLeft]
12
+ * interacting --> modalFeedback: endAttempt [individualSubmission, attemptsLeft, modalFeedback]
13
+ * interacting --> interacting: endAttempt [individualSubmission, attemptsLeft]
14
+ * interacting --> suspended: endCandidateSession
15
+ * interacting --> closed: endItemSession
16
+ * modalFeedback --> interacting: beginAttempt [attemptsLeft]
17
+ * modalFeedback --> suspended: endCandidateSession
18
+ * modalFeedback --> closed: endItemSession
19
+ * suspended --> interacting: beginCandidateSession [mayResume]
20
+ * suspended --> closed: endItemSession
21
+ * closed --> review: beginReview [allowReview]
22
+ * review --> closed: endReview
23
+ * closed --> solution: beginSolution [showSolution]
24
+ * solution --> closed: endSolution
25
+ * ```
26
+ *
27
+ * What QTI ties to the states: interactions are enabled in `interacting` only; in `closed` and
28
+ * `review` the responses show but are fixed; in `solution` the correct responses show instead. An
29
+ * item that goes from `initial` straight to `closed` keeps NULL responses.
30
+ *
31
+ * The text of §2.2.1 names six states; `modalFeedback` comes from its figure (Figure 2.1, as this
32
+ * plan reads it): the item after an attempt whose response processing set modal feedback, with
33
+ * attempts left ("modal feedback is shown to the candidate directly following response
34
+ * processing", §2.6). The candidate reads it before trying again.
35
+ *
36
+ * Experimental (0.x): roadmap 1 phase T3; see `plans/delivery-state.md`.
37
+ */
38
+ export const ITEM_LIFECYCLE_STATES = [
39
+ 'initial',
40
+ 'interacting',
41
+ 'modalFeedback',
42
+ 'suspended',
43
+ 'closed',
44
+ 'review',
45
+ 'solution'
46
+ ];
47
+ /**
48
+ * What happens to an item session, in QTI's words (info model §2.2.1). The delivery's commands
49
+ * (`navigate`, `beginAttempt`, `endAttempt`, `endTestPart`, `timeUp`) are turned into these, per item.
50
+ */
51
+ export const ITEM_LIFECYCLE_EVENTS = [
52
+ 'beginAttempt',
53
+ 'endAttempt',
54
+ 'endCandidateSession',
55
+ 'beginCandidateSession',
56
+ 'endItemSession',
57
+ 'beginReview',
58
+ 'endReview',
59
+ 'beginSolution',
60
+ 'endSolution'
61
+ ];
62
+ /** The conditions a transition can depend on; `itemLifecycleGuards` reads them for one item. */
63
+ export const ITEM_LIFECYCLE_GUARDS = [
64
+ 'attemptsLeft',
65
+ 'individualSubmission',
66
+ 'modalFeedback',
67
+ 'mayResume',
68
+ 'allowReview',
69
+ 'showSolution'
70
+ ];
71
+ /** The transition table: a pair it does not list is refused. */
72
+ export const ITEM_LIFECYCLE = {
73
+ initial: {
74
+ beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],
75
+ endItemSession: 'closed'
76
+ },
77
+ interacting: {
78
+ // The guards are read after response processing, with the ended attempt counted.
79
+ endAttempt: [
80
+ { to: 'closed', when: ['individualSubmission'], unless: ['attemptsLeft'] },
81
+ { to: 'modalFeedback', when: ['individualSubmission', 'attemptsLeft', 'modalFeedback'] },
82
+ { to: 'interacting', when: ['individualSubmission', 'attemptsLeft'] }
83
+ ],
84
+ endCandidateSession: 'suspended',
85
+ endItemSession: 'closed'
86
+ },
87
+ modalFeedback: {
88
+ beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],
89
+ endCandidateSession: 'suspended',
90
+ endItemSession: 'closed'
91
+ },
92
+ suspended: {
93
+ beginCandidateSession: [{ to: 'interacting', when: ['mayResume'] }],
94
+ endItemSession: 'closed'
95
+ },
96
+ closed: {
97
+ beginReview: [{ to: 'review', when: ['allowReview'] }],
98
+ beginSolution: [{ to: 'solution', when: ['showSolution'] }]
99
+ },
100
+ review: {
101
+ endReview: 'closed'
102
+ },
103
+ solution: {
104
+ endSolution: 'closed'
105
+ }
106
+ };
107
+ /**
108
+ * The state an item session goes to on `event`, or null when the table refuses it: the pair is not
109
+ * listed, or no branch's guards hold. Pure: the same state, event and guards give the same answer
110
+ * on every runtime.
111
+ */
112
+ export function transition(state, event, guards) {
113
+ const target = ITEM_LIFECYCLE[state][event];
114
+ if (target === undefined)
115
+ return null;
116
+ if (typeof target === 'string')
117
+ return target;
118
+ const branch = target.find(({ when = [], unless = [] }) => when.every(guard => guards[guard]) && !unless.some(guard => guards[guard]));
119
+ return branch?.to ?? null;
120
+ }
121
+ /**
122
+ * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it
123
+ * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its
124
+ * response processing set `completionStatus` to `completed`.
125
+ */
126
+ export function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus }) {
127
+ if (adaptive)
128
+ return completionStatus !== 'completed';
129
+ return maxAttempts === 0 || numAttempts < maxAttempts;
130
+ }
131
+ /** The guards of one item session, from its session control, its facts, its part and its variables. */
132
+ export function itemLifecycleGuards(input) {
133
+ return {
134
+ attemptsLeft: hasAttemptsLeft(input),
135
+ // In a simultaneous part every response is processed when the part is submitted (§4.1).
136
+ individualSubmission: input.submissionMode === 'individual',
137
+ modalFeedback: input.modalFeedback,
138
+ // A linear part restricts the candidate to each item in turn: once left, never again (§4.1).
139
+ mayResume: input.navigationMode === 'nonlinear' || !input.left,
140
+ allowReview: input.sessionControl.allowReview,
141
+ showSolution: input.sessionControl.showSolution
142
+ };
143
+ }
144
+ /**
145
+ * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored
146
+ * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part
147
+ * has passed it; interacting when it is on screen; initial before its first ended attempt; else
148
+ * suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.
149
+ */
150
+ export function seedItemLifecycle(input) {
151
+ if (!hasAttemptsLeft(input) || input.passed)
152
+ return 'closed';
153
+ if (input.presented)
154
+ return 'interacting';
155
+ return input.numAttempts === 0 ? 'initial' : 'suspended';
156
+ }
157
+ //# sourceMappingURL=item-lifecycle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle/item-lifecycle.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,SAAS;IACT,aAAa;IACb,eAAe;IACf,WAAW;IACX,QAAQ;IACR,QAAQ;IACR,UAAU;CACF,CAAC;AAIX;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,YAAY;IACZ,qBAAqB;IACrB,uBAAuB;IACvB,gBAAgB;IAChB,aAAa;IACb,WAAW;IACX,eAAe;IACf,aAAa;CACL,CAAC;AAIX,gGAAgG;AAChG,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,cAAc;IACd,sBAAsB;IACtB,eAAe;IACf,WAAW;IACX,aAAa;IACb,cAAc;CACN,CAAC;AAgBX,gEAAgE;AAChE,MAAM,CAAC,MAAM,cAAc,GAEvB;IACF,OAAO,EAAE;QACP,YAAY,EAAE,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC;QAC7D,cAAc,EAAE,QAAQ;KACzB;IACD,WAAW,EAAE;QACX,iFAAiF;QACjF,UAAU,EAAE;YACV,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,sBAAsB,CAAC,EAAE,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE;YAC1E,EAAE,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,sBAAsB,EAAE,cAAc,EAAE,eAAe,CAAC,EAAE;YACxF,EAAE,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,sBAAsB,EAAE,cAAc,CAAC,EAAE;SACtE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AAM,CAAC,KAAK,CAAC,CAAC,CAC3G,CAAC;IACF,OAAO,MAAM,EAAE,EAAE,IAAI,IAAI,CAAC;AAC5B,CAAC;AAuBD;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,EAC9B,cAAc,EAAE,EAAE,WAAW,EAAE,EAC/B,QAAQ,EACR,WAAW,EACX,gBAAgB,EAC6E;IAC7F,IAAI,QAAQ;QAAE,OAAO,gBAAgB,KAAK,WAAW,CAAC;IACtD,OAAO,WAAW,KAAK,CAAC,IAAI,WAAW,GAAG,WAAW,CAAC;AACxD,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,mBAAmB,CAAC,KAAyB;IAC3D,OAAO;QACL,YAAY,EAAE,eAAe,CAAC,KAAK,CAAC;QACpC,wFAAwF;QACxF,oBAAoB,EAAE,KAAK,CAAC,cAAc,KAAK,YAAY;QAC3D,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,6FAA6F;QAC7F,SAAS,EAAE,KAAK,CAAC,cAAc,KAAK,WAAW,IAAI,CAAC,KAAK,CAAC,IAAI;QAC9D,WAAW,EAAE,KAAK,CAAC,cAAc,CAAC,WAAW;QAC7C,YAAY,EAAE,KAAK,CAAC,cAAc,CAAC,YAAY;KAChD,CAAC;AACJ,CAAC;AAWD;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAA6B;IAC7D,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,QAAQ,CAAC;IAC7D,IAAI,KAAK,CAAC,SAAS;QAAE,OAAO,aAAa,CAAC;IAC1C,OAAO,KAAK,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC;AAC3D,CAAC","sourcesContent":["import type { SessionControl, TestPartModel } from '../model/test-model.js';\n\n/**\n * The item session lifecycle (QTI 3 info model §2.2.1, Figure 2.1) as one finite state machine per\n * item instance: every item session is in exactly one of these states, and only the transitions in\n * `ITEM_LIFECYCLE` happen. Each rule of item session control is a guard on one of them.\n *\n * ```mermaid\n * stateDiagram-v2\n * [*] --> initial\n * initial --> interacting: beginAttempt [attemptsLeft]\n * initial --> closed: endItemSession\n * interacting --> closed: endAttempt [individualSubmission, no attemptsLeft]\n * interacting --> modalFeedback: endAttempt [individualSubmission, attemptsLeft, modalFeedback]\n * interacting --> interacting: endAttempt [individualSubmission, attemptsLeft]\n * interacting --> suspended: endCandidateSession\n * interacting --> closed: endItemSession\n * modalFeedback --> interacting: beginAttempt [attemptsLeft]\n * modalFeedback --> suspended: endCandidateSession\n * modalFeedback --> closed: endItemSession\n * suspended --> interacting: beginCandidateSession [mayResume]\n * suspended --> closed: endItemSession\n * closed --> review: beginReview [allowReview]\n * review --> closed: endReview\n * closed --> solution: beginSolution [showSolution]\n * solution --> closed: endSolution\n * ```\n *\n * What QTI ties to the states: interactions are enabled in `interacting` only; in `closed` and\n * `review` the responses show but are fixed; in `solution` the correct responses show instead. An\n * item that goes from `initial` straight to `closed` keeps NULL responses.\n *\n * The text of §2.2.1 names six states; `modalFeedback` comes from its figure (Figure 2.1, as this\n * plan reads it): the item after an attempt whose response processing set modal feedback, with\n * attempts left (\"modal feedback is shown to the candidate directly following response\n * processing\", §2.6). The candidate reads it before trying again.\n *\n * Experimental (0.x): roadmap 1 phase T3; see `plans/delivery-state.md`.\n */\nexport const ITEM_LIFECYCLE_STATES = [\n 'initial',\n 'interacting',\n 'modalFeedback',\n 'suspended',\n 'closed',\n 'review',\n 'solution'\n] as const;\n\nexport type ItemLifecycleState = (typeof ITEM_LIFECYCLE_STATES)[number];\n\n/**\n * What happens to an item session, in QTI's words (info model §2.2.1). The delivery's commands\n * (`navigate`, `beginAttempt`, `endAttempt`, `endTestPart`, `timeUp`) are turned into these, per item.\n */\nexport const ITEM_LIFECYCLE_EVENTS = [\n 'beginAttempt',\n 'endAttempt',\n 'endCandidateSession',\n 'beginCandidateSession',\n 'endItemSession',\n 'beginReview',\n 'endReview',\n 'beginSolution',\n 'endSolution'\n] as const;\n\nexport type ItemLifecycleEvent = (typeof ITEM_LIFECYCLE_EVENTS)[number];\n\n/** The conditions a transition can depend on; `itemLifecycleGuards` reads them for one item. */\nexport const ITEM_LIFECYCLE_GUARDS = [\n 'attemptsLeft',\n 'individualSubmission',\n 'modalFeedback',\n 'mayResume',\n 'allowReview',\n 'showSolution'\n] as const;\n\nexport type ItemLifecycleGuard = (typeof ITEM_LIFECYCLE_GUARDS)[number];\n\nexport type ItemLifecycleGuards = Readonly<Record<ItemLifecycleGuard, boolean>>;\n\n/** One way out of a state: taken when every `when` guard holds and no `unless` guard does. */\nexport interface ItemLifecycleBranch {\n readonly to: ItemLifecycleState;\n readonly when?: readonly ItemLifecycleGuard[];\n readonly unless?: readonly ItemLifecycleGuard[];\n}\n\n/** A state with no guard, or branches tried in order, the first that holds taken. */\nexport type ItemLifecycleTarget = ItemLifecycleState | readonly ItemLifecycleBranch[];\n\n/** The transition table: a pair it does not list is refused. */\nexport const ITEM_LIFECYCLE: Readonly<\n Record<ItemLifecycleState, Readonly<Partial<Record<ItemLifecycleEvent, ItemLifecycleTarget>>>>\n> = {\n initial: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endItemSession: 'closed'\n },\n interacting: {\n // The guards are read after response processing, with the ended attempt counted.\n endAttempt: [\n { to: 'closed', when: ['individualSubmission'], unless: ['attemptsLeft'] },\n { to: 'modalFeedback', when: ['individualSubmission', 'attemptsLeft', 'modalFeedback'] },\n { to: 'interacting', when: ['individualSubmission', 'attemptsLeft'] }\n ],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n modalFeedback: {\n beginAttempt: [{ to: 'interacting', when: ['attemptsLeft'] }],\n endCandidateSession: 'suspended',\n endItemSession: 'closed'\n },\n suspended: {\n beginCandidateSession: [{ to: 'interacting', when: ['mayResume'] }],\n endItemSession: 'closed'\n },\n closed: {\n beginReview: [{ to: 'review', when: ['allowReview'] }],\n beginSolution: [{ to: 'solution', when: ['showSolution'] }]\n },\n review: {\n endReview: 'closed'\n },\n solution: {\n endSolution: 'closed'\n }\n};\n\n/**\n * The state an item session goes to on `event`, or null when the table refuses it: the pair is not\n * listed, or no branch's guards hold. Pure: the same state, event and guards give the same answer\n * on every runtime.\n */\nexport function transition(\n state: ItemLifecycleState,\n event: ItemLifecycleEvent,\n guards: ItemLifecycleGuards\n): ItemLifecycleState | null {\n const target = ITEM_LIFECYCLE[state][event];\n if (target === undefined) return null;\n if (typeof target === 'string') return target;\n const branch = target.find(\n ({ when = [], unless = [] }) => when.every(guard => guards[guard]) && !unless.some(guard => guards[guard])\n );\n return branch?.to ?? null;\n}\n\n/** What the guards of one item session are read from. */\nexport interface ItemLifecycleInput {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: Pick<SessionControl, 'maxAttempts' | 'allowReview' | 'showSolution'>;\n /** From the item's facts (`ItemFacts.adaptive`). */\n adaptive: boolean;\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /**\n * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this\n * delivery counts it when it ends, and T3d keeps that (`plans/delivery-state.md`).\n */\n numAttempts: number;\n /** The item's `completionStatus` (`not_attempted`, `unknown`, `incomplete`, `completed`). */\n completionStatus: string | null;\n /** The candidate has moved on from the item; in a linear part there is no way back. */\n left: boolean;\n /** The last response processing set modal feedback to show. */\n modalFeedback: boolean;\n}\n\n/**\n * Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it\n * has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its\n * response processing set `completionStatus` to `completed`.\n */\nexport function hasAttemptsLeft({\n sessionControl: { maxAttempts },\n adaptive,\n numAttempts,\n completionStatus\n}: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>): boolean {\n if (adaptive) return completionStatus !== 'completed';\n return maxAttempts === 0 || numAttempts < maxAttempts;\n}\n\n/** The guards of one item session, from its session control, its facts, its part and its variables. */\nexport function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards {\n return {\n attemptsLeft: hasAttemptsLeft(input),\n // In a simultaneous part every response is processed when the part is submitted (§4.1).\n individualSubmission: input.submissionMode === 'individual',\n modalFeedback: input.modalFeedback,\n // A linear part restricts the candidate to each item in turn: once left, never again (§4.1).\n mayResume: input.navigationMode === 'nonlinear' || !input.left,\n allowReview: input.sessionControl.allowReview,\n showSolution: input.sessionControl.showSolution\n };\n}\n\n/** What a version 1 state, or a test restored from one, tells about an item session. */\nexport interface ItemLifecycleSeedInput\n extends Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'> {\n /** The item is on screen: the current item, or one of the section on screen with `navigate=\"section\"`. */\n presented: boolean;\n /** The item comes before the current one in a linear part: the candidate has left it for good. */\n passed: boolean;\n}\n\n/**\n * The lifecycle state of an item session that has none stored: a version 1 state, or a test restored\n * or assigned from one (`plans/delivery-state.md`). Closed when no attempt is left or a linear part\n * has passed it; interacting when it is on screen; initial before its first ended attempt; else\n * suspended. Never `modalFeedback`, `review` or `solution`: a version 1 state cannot tell them apart.\n */\nexport function seedItemLifecycle(input: ItemLifecycleSeedInput): ItemLifecycleState {\n if (!hasAttemptsLeft(input) || input.passed) return 'closed';\n if (input.presented) return 'interacting';\n return input.numAttempts === 0 ? 'initial' : 'suspended';\n}\n"]}
@@ -0,0 +1,100 @@
1
+ import type { SessionControl, TestPartModel } from '../model/test-model.js';
2
+ import type { ItemLifecycleInput, ItemLifecycleState } from './item-lifecycle.js';
3
+ /**
4
+ * What one item session may do now, answered from its lifecycle state, its session control and its
5
+ * responses. Every reader of attempts, skipping, feedback, review or the solution asks here instead
6
+ * of working the rule out itself (roadmap 1, T3b).
7
+ *
8
+ * The answers follow QTI 3 (`qti-item-session-control`, info model §7.19; implementation guide
9
+ * §4.1 and §4.4.2) and nothing else: whether the last attempt was optimal decides none of them
10
+ * (decided 2026-11-27, `plans/host-api.md`).
11
+ *
12
+ * Experimental (0.x).
13
+ */
14
+ export interface ItemRules {
15
+ /**
16
+ * Another attempt is allowed: `max-attempts` not reached (0 is unlimited), or, for an adaptive
17
+ * item, which ignores `max-attempts`, `completionStatus` not `completed`.
18
+ */
19
+ readonly attemptsLeft: boolean;
20
+ /** No further attempt is allowed: the negation of `attemptsLeft`. */
21
+ readonly attemptsUsed: boolean;
22
+ /** The responses can change: only while `interacting`. In every other state they are fixed or not shown. */
23
+ readonly interactive: boolean;
24
+ /** The item session is over: `closed`, or in `review` or `solution`, which come back to `closed`. */
25
+ readonly done: boolean;
26
+ /**
27
+ * The candidate may end the attempt now: the item is `interacting` in a part with individual
28
+ * submission, and `maySubmit` holds.
29
+ */
30
+ readonly mayEndAttempt: boolean;
31
+ /**
32
+ * The responses may be submitted as they are: `allow-skipping="false"` refuses an item with no
33
+ * response, `validate-responses` an invalid one. Two separate rules, both for individual
34
+ * submission only (§7.19).
35
+ */
36
+ readonly maySubmit: boolean;
37
+ /** Submitting no response is allowed: `allow-skipping`, or a response given, or simultaneous submission. */
38
+ readonly maySkip: boolean;
39
+ /**
40
+ * Feedback, modal and integrated, may show: always while attempts are left, after the last
41
+ * attempt only with `show-feedback`. In `review`, an adaptive item with `allow-review` shows its
42
+ * feedback whatever `show-feedback` says (§7.19, `allow-review`).
43
+ */
44
+ readonly mayShowFeedback: boolean;
45
+ /**
46
+ * The item session may enter `review` now: it is `closed`, with `allow-review`. False in `review`
47
+ * itself; whether review shows is the state.
48
+ */
49
+ readonly mayBeginReview: boolean;
50
+ /**
51
+ * The item session may enter `solution`, which shows the correct responses: it is `closed`, with
52
+ * `show-solution`. False in `solution` itself; whether the solution shows is the state.
53
+ */
54
+ readonly mayBeginSolution: boolean;
55
+ /**
56
+ * The candidate may set a comment on the item now: `allow-comment`, while `interacting`. The
57
+ * comment is not assessed; QTI leaves capturing it to the delivery (§7.19, `allow-comment`).
58
+ */
59
+ readonly mayComment: boolean;
60
+ }
61
+ /** What the rules of one item session are read from: its lifecycle input, its state and its responses. */
62
+ export interface ItemRulesInput extends Omit<ItemLifecycleInput, 'sessionControl'> {
63
+ /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */
64
+ sessionControl: SessionControl;
65
+ /** The item session's lifecycle state. */
66
+ state: ItemLifecycleState;
67
+ /**
68
+ * The candidate gave no response: every response variable holds its default or NULL. False for an
69
+ * item with no response variables, which "by definition cannot be skipped" (§7.19).
70
+ */
71
+ skipped: boolean;
72
+ /** Every interaction's response satisfies its constraints (the item's `valid`). */
73
+ valid: boolean;
74
+ }
75
+ /** The rules of one item session. Pure: the same input gives the same answers on every runtime. */
76
+ export declare function itemRules(input: ItemRulesInput): ItemRules;
77
+ /** Where the candidate is in a part, for its navigation answers. */
78
+ export interface NavigationRulesInput {
79
+ navigationMode: TestPartModel['navigationMode'];
80
+ submissionMode: TestPartModel['submissionMode'];
81
+ /** The current item's position among the part's items in order, from 0; -1 when none is current. */
82
+ index: number;
83
+ /** The number of items in the part. */
84
+ count: number;
85
+ /** The rules of the current item. */
86
+ current: Pick<ItemRules, 'maySubmit' | 'interactive'>;
87
+ }
88
+ /** Whether the candidate may move to the next or the previous item of a part. */
89
+ export interface NavigationRules {
90
+ /**
91
+ * There is a next item and, in a linear part with individual submission, the current item may be
92
+ * left: Next ends an attempt that was not ended and closes the item (decided 2026-11-27), so its
93
+ * responses must be ones the candidate may submit.
94
+ */
95
+ readonly mayGoNext: boolean;
96
+ /** There is a previous item, in a nonlinear part: a linear part never goes back (§4.1). */
97
+ readonly mayGoPrevious: boolean;
98
+ }
99
+ /** The navigation answers of a part. Pure. */
100
+ export declare function navigationRules({ navigationMode, submissionMode, index, count, current }: NavigationRulesInput): NavigationRules;
@@ -0,0 +1,34 @@
1
+ import { itemLifecycleGuards, transition } from './item-lifecycle.js';
2
+ /** The rules of one item session. Pure: the same input gives the same answers on every runtime. */
3
+ export function itemRules(input) {
4
+ const { state, sessionControl, adaptive } = input;
5
+ const guards = itemLifecycleGuards(input);
6
+ const individual = guards.individualSubmission;
7
+ const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;
8
+ const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);
9
+ return {
10
+ attemptsLeft: guards.attemptsLeft,
11
+ attemptsUsed: !guards.attemptsLeft,
12
+ interactive: state === 'interacting',
13
+ done: state === 'closed' || state === 'review' || state === 'solution',
14
+ mayEndAttempt: maySubmit && transition(state, 'endAttempt', guards) !== null,
15
+ maySubmit,
16
+ maySkip,
17
+ mayShowFeedback: guards.attemptsLeft ||
18
+ sessionControl.showFeedback ||
19
+ (state === 'review' && adaptive && sessionControl.allowReview),
20
+ mayBeginReview: transition(state, 'beginReview', guards) !== null,
21
+ mayBeginSolution: transition(state, 'beginSolution', guards) !== null,
22
+ mayComment: sessionControl.allowComment && state === 'interacting'
23
+ };
24
+ }
25
+ /** The navigation answers of a part. Pure. */
26
+ export function navigationRules({ navigationMode, submissionMode, index, count, current }) {
27
+ const onItem = index >= 0 && index < count;
28
+ const endsAttempt = navigationMode === 'linear' && submissionMode === 'individual' && current.interactive;
29
+ return {
30
+ mayGoNext: onItem && index < count - 1 && (!endsAttempt || current.maySubmit),
31
+ mayGoPrevious: onItem && index > 0 && navigationMode === 'nonlinear'
32
+ };
33
+ }
34
+ //# sourceMappingURL=item-rules.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-rules.js","sourceRoot":"","sources":["../../src/lifecycle/item-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA+EtE,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,oB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L,SAAS,EAAE,MAAM,IAAI,KAAK,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC;QAC7E,aAAa,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,IAAI,cAAc,KAAK,WAAW;KACrE,CAAC;AACJ,CAAC","sourcesContent":["import { itemLifecycleGuards, transition } from './item-lifecycle.js';\n\nimport type { SessionControl, TestPartModel } from '../model/test-model.js';\nimport type { ItemLifecycleInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/**\n * What one item session may do now, answered from its lifecycle state, its session control and its\n * responses. Every reader of attempts, skipping, feedback, review or the solution asks here instead\n * of working the rule out itself (roadmap 1, T3b).\n *\n * The answers follow QTI 3 (`qti-item-session-control`, info model §7.19; implementation guide\n * §4.1 and §4.4.2) and nothing else: whether the last attempt was optimal decides none of them\n * (decided 2026-11-27, `plans/host-api.md`).\n *\n * Experimental (0.x).\n */\nexport interface ItemRules {\n /**\n * Another attempt is allowed: `max-attempts` not reached (0 is unlimited), or, for an adaptive\n * item, which ignores `max-attempts`, `completionStatus` not `completed`.\n */\n readonly attemptsLeft: boolean;\n /** No further attempt is allowed: the negation of `attemptsLeft`. */\n readonly attemptsUsed: boolean;\n /** The responses can change: only while `interacting`. In every other state they are fixed or not shown. */\n readonly interactive: boolean;\n /** The item session is over: `closed`, or in `review` or `solution`, which come back to `closed`. */\n readonly done: boolean;\n /**\n * The candidate may end the attempt now: the item is `interacting` in a part with individual\n * submission, and `maySubmit` holds.\n */\n readonly mayEndAttempt: boolean;\n /**\n * The responses may be submitted as they are: `allow-skipping=\"false\"` refuses an item with no\n * response, `validate-responses` an invalid one. Two separate rules, both for individual\n * submission only (§7.19).\n */\n readonly maySubmit: boolean;\n /** Submitting no response is allowed: `allow-skipping`, or a response given, or simultaneous submission. */\n readonly maySkip: boolean;\n /**\n * Feedback, modal and integrated, may show: always while attempts are left, after the last\n * attempt only with `show-feedback`. In `review`, an adaptive item with `allow-review` shows its\n * feedback whatever `show-feedback` says (§7.19, `allow-review`).\n */\n readonly mayShowFeedback: boolean;\n /**\n * The item session may enter `review` now: it is `closed`, with `allow-review`. False in `review`\n * itself; whether review shows is the state.\n */\n readonly mayBeginReview: boolean;\n /**\n * The item session may enter `solution`, which shows the correct responses: it is `closed`, with\n * `show-solution`. False in `solution` itself; whether the solution shows is the state.\n */\n readonly mayBeginSolution: boolean;\n /**\n * The candidate may set a comment on the item now: `allow-comment`, while `interacting`. The\n * comment is not assessed; QTI leaves capturing it to the delivery (§7.19, `allow-comment`).\n */\n readonly mayComment: boolean;\n}\n\n/** What the rules of one item session are read from: its lifecycle input, its state and its responses. */\nexport interface ItemRulesInput extends Omit<ItemLifecycleInput, 'sessionControl'> {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: SessionControl;\n /** The item session's lifecycle state. */\n state: ItemLifecycleState;\n /**\n * The candidate gave no response: every response variable holds its default or NULL. False for an\n * item with no response variables, which \"by definition cannot be skipped\" (§7.19).\n */\n skipped: boolean;\n /** Every interaction's response satisfies its constraints (the item's `valid`). */\n valid: boolean;\n}\n\n/** The rules of one item session. Pure: the same input gives the same answers on every runtime. */\nexport function itemRules(input: ItemRulesInput): ItemRules {\n const { state, sessionControl, adaptive } = input;\n const guards = itemLifecycleGuards(input);\n const individual = guards.individualSubmission;\n const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;\n const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);\n return {\n attemptsLeft: guards.attemptsLeft,\n attemptsUsed: !guards.attemptsLeft,\n interactive: state === 'interacting',\n done: state === 'closed' || state === 'review' || state === 'solution',\n mayEndAttempt: maySubmit && transition(state, 'endAttempt', guards) !== null,\n maySubmit,\n maySkip,\n mayShowFeedback:\n guards.attemptsLeft ||\n sessionControl.showFeedback ||\n (state === 'review' && adaptive && sessionControl.allowReview),\n mayBeginReview: transition(state, 'beginReview', guards) !== null,\n mayBeginSolution: transition(state, 'beginSolution', guards) !== null,\n mayComment: sessionControl.allowComment && state === 'interacting'\n };\n}\n\n/** Where the candidate is in a part, for its navigation answers. */\nexport interface NavigationRulesInput {\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /** The current item's position among the part's items in order, from 0; -1 when none is current. */\n index: number;\n /** The number of items in the part. */\n count: number;\n /** The rules of the current item. */\n current: Pick<ItemRules, 'maySubmit' | 'interactive'>;\n}\n\n/** Whether the candidate may move to the next or the previous item of a part. */\nexport interface NavigationRules {\n /**\n * There is a next item and, in a linear part with individual submission, the current item may be\n * left: Next ends an attempt that was not ended and closes the item (decided 2026-11-27), so its\n * responses must be ones the candidate may submit.\n */\n readonly mayGoNext: boolean;\n /** There is a previous item, in a nonlinear part: a linear part never goes back (§4.1). */\n readonly mayGoPrevious: boolean;\n}\n\n/** The navigation answers of a part. Pure. */\nexport function navigationRules({\n navigationMode,\n submissionMode,\n index,\n count,\n current\n}: NavigationRulesInput): NavigationRules {\n const onItem = index >= 0 && index < count;\n const endsAttempt = navigationMode === 'linear' && submissionMode === 'individual' && current.interactive;\n return {\n mayGoNext: onItem && index < count - 1 && (!endsAttempt || current.maySubmit),\n mayGoPrevious: onItem && index > 0 && navigationMode === 'nonlinear'\n };\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { ItemLifecycleInput, ItemLifecycleSeedInput, ItemLifecycleState } from './item-lifecycle.js';
2
+ /** One item session as a delivery keeps it between updates: its state, and the attempts it was last seen with. */
3
+ export interface ItemSession {
4
+ readonly state: ItemLifecycleState;
5
+ /** The ended attempts when `state` was last set; a different count means the state came from elsewhere. */
6
+ readonly numAttempts: number;
7
+ /** Whether the item was adaptive when `state` was last set; its facts may arrive after the first update. */
8
+ readonly adaptive: boolean;
9
+ }
10
+ /** What a delivery knows about an item session at an update. */
11
+ export interface ItemSessionFacts extends ItemLifecycleSeedInput, Pick<ItemLifecycleInput, 'navigationMode' | 'submissionMode'> {
12
+ sessionControl: ItemLifecycleInput['sessionControl'];
13
+ }
14
+ /**
15
+ * The session after the candidate moved (or a state was restored), through the lifecycle table: an
16
+ * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a
17
+ * linear part has passed is closed. A session not seen before, or whose attempts changed outside
18
+ * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came
19
+ * later), is seeded again with `seedItemLifecycle`.
20
+ */
21
+ export declare function followItemSession(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession;
22
+ /**
23
+ * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes
24
+ * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery
25
+ * saw it begin, so it is seeded as an item on screen.
26
+ */
27
+ export declare function endItemAttempt(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession;
@@ -0,0 +1,47 @@
1
+ import { itemLifecycleGuards, seedItemLifecycle, transition } from './item-lifecycle.js';
2
+ const guardsFor = (facts) =>
3
+ // Modal feedback does not stop a session yet: nothing reports it, so `modalFeedback` is never entered.
4
+ itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });
5
+ const OVER = ['closed', 'review', 'solution'];
6
+ /**
7
+ * The session after the candidate moved (or a state was restored), through the lifecycle table: an
8
+ * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a
9
+ * linear part has passed is closed. A session not seen before, or whose attempts changed outside
10
+ * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came
11
+ * later), is seeded again with `seedItemLifecycle`.
12
+ */
13
+ export function followItemSession(previous, facts) {
14
+ const { numAttempts, adaptive } = facts;
15
+ if (!previous || previous.numAttempts !== numAttempts || previous.adaptive !== adaptive) {
16
+ return { state: seedItemLifecycle(facts), numAttempts, adaptive };
17
+ }
18
+ const guards = guardsFor(facts);
19
+ let state = previous.state;
20
+ if (facts.passed) {
21
+ if (!OVER.includes(state))
22
+ state = transition(state, 'endItemSession', guards) ?? state;
23
+ }
24
+ else if (facts.presented) {
25
+ if (state === 'initial')
26
+ state = transition(state, 'beginAttempt', guards) ?? state;
27
+ else if (state === 'suspended')
28
+ state = transition(state, 'beginCandidateSession', guards) ?? state;
29
+ }
30
+ else if (state === 'interacting' || state === 'modalFeedback') {
31
+ state = transition(state, 'endCandidateSession', guards) ?? state;
32
+ }
33
+ return { state, numAttempts, adaptive };
34
+ }
35
+ /**
36
+ * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes
37
+ * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery
38
+ * saw it begin, so it is seeded as an item on screen.
39
+ */
40
+ export function endItemAttempt(previous, facts) {
41
+ const { numAttempts, adaptive } = facts;
42
+ if (previous?.state !== 'interacting') {
43
+ return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts, adaptive };
44
+ }
45
+ return { state: transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting', numAttempts, adaptive };
46
+ }
47
+ //# sourceMappingURL=item-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"item-session.js","sourceRoot":"","sources":["../../src/lifecycle/item-session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAoBzF,MAAM,SAAS,GAAG,CAAC,KAAuB,EAAE,EAAE;AAC5C,uGAAuG;AACvG,mBAAmB,CAAC,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;AAE9E,MAAM,IAAI,GAAkC,CAAC,QAAQ,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;AAE7E;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiC,EAAE,KAAuB;IAC1F,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,WAAW,KAAK,WAAW,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,EA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,EAAE,QAAQ,EAAE,CAAC;IAC5F,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,aAAa,EAAE,YAAY,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACtH,CAAC","sourcesContent":["import { itemLifecycleGuards, seedItemLifecycle, transition } from './item-lifecycle.js';\n\nimport type { ItemLifecycleInput, ItemLifecycleSeedInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/** One item session as a delivery keeps it between updates: its state, and the attempts it was last seen with. */\nexport interface ItemSession {\n readonly state: ItemLifecycleState;\n /** The ended attempts when `state` was last set; a different count means the state came from elsewhere. */\n readonly numAttempts: number;\n /** Whether the item was adaptive when `state` was last set; its facts may arrive after the first update. */\n readonly adaptive: boolean;\n}\n\n/** What a delivery knows about an item session at an update. */\nexport interface ItemSessionFacts\n extends ItemLifecycleSeedInput,\n Pick<ItemLifecycleInput, 'navigationMode' | 'submissionMode'> {\n sessionControl: ItemLifecycleInput['sessionControl'];\n}\n\nconst guardsFor = (facts: ItemSessionFacts) =>\n // Modal feedback does not stop a session yet: nothing reports it, so `modalFeedback` is never entered.\n itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n\nconst OVER: readonly ItemLifecycleState[] = ['closed', 'review', 'solution'];\n\n/**\n * The session after the candidate moved (or a state was restored), through the lifecycle table: an\n * item put on screen begins its attempt or resumes, one taken off screen is suspended, and one a\n * linear part has passed is closed. A session not seen before, or whose attempts changed outside\n * `endItemAttempt` (a restored or assigned state) or whose item turned out adaptive (its facts came\n * later), is seeded again with `seedItemLifecycle`.\n */\nexport function followItemSession(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (!previous || previous.numAttempts !== numAttempts || previous.adaptive !== adaptive) {\n return { state: seedItemLifecycle(facts), numAttempts, adaptive };\n }\n const guards = guardsFor(facts);\n let state = previous.state;\n if (facts.passed) {\n if (!OVER.includes(state)) state = transition(state, 'endItemSession', guards) ?? state;\n } else if (facts.presented) {\n if (state === 'initial') state = transition(state, 'beginAttempt', guards) ?? state;\n else if (state === 'suspended') state = transition(state, 'beginCandidateSession', guards) ?? state;\n } else if (state === 'interacting' || state === 'modalFeedback') {\n state = transition(state, 'endCandidateSession', guards) ?? state;\n }\n return { state, numAttempts, adaptive };\n}\n\n/**\n * The session after an attempt ended, `facts.numAttempts` counting it. An interacting session goes\n * through the table's `endAttempt`; one in any other state had its attempt ended before this delivery\n * saw it begin, so it is seeded as an item on screen.\n */\nexport function endItemAttempt(previous: ItemSession | undefined, facts: ItemSessionFacts): ItemSession {\n const { numAttempts, adaptive } = facts;\n if (previous?.state !== 'interacting') {\n return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts, adaptive };\n }\n return { state: transition('interacting', 'endAttempt', guardsFor(facts)) ?? 'interacting', numAttempts, adaptive };\n}\n"]}