@qti-components/delivery 0.1.0-next.3 → 0.1.0-next.4
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lifecycle/item-lifecycle.d.ts +91 -0
- package/dist/lifecycle/item-lifecycle.js +144 -0
- package/dist/lifecycle/item-lifecycle.js.map +1 -0
- package/dist/state/create-delivery-state.d.ts +4 -2
- package/dist/state/create-delivery-state.js +13 -6
- package/dist/state/create-delivery-state.js.map +1 -1
- package/dist/state/delivery-state.d.ts +9 -0
- package/dist/state/delivery-state.js +12 -0
- package/dist/state/delivery-state.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
4
5
|
export * from './random/seeded-random.js';
|
|
5
6
|
export * from './random/selection.js';
|
|
6
7
|
export * from './random/shuffle.js';
|
package/dist/index.js
CHANGED
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,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","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/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';\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,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","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 './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';\n"]}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
/** The item's `numAttempts`. */
|
|
76
|
+
numAttempts: number;
|
|
77
|
+
/** The item's `completionStatus` (`not_attempted`, `unknown`, `incomplete`, `completed`). */
|
|
78
|
+
completionStatus: string | null;
|
|
79
|
+
/** The candidate has moved on from the item; in a linear part there is no way back. */
|
|
80
|
+
left: boolean;
|
|
81
|
+
/** The last response processing set modal feedback to show. */
|
|
82
|
+
modalFeedback: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Whether another attempt is allowed (implementation guide §4.4.2.1): a non-adaptive item until it
|
|
86
|
+
* has used `max-attempts` (0 is unlimited); an adaptive item, which ignores `max-attempts`, until its
|
|
87
|
+
* response processing set `completionStatus` to `completed`.
|
|
88
|
+
*/
|
|
89
|
+
export declare function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus }: Pick<ItemLifecycleInput, 'sessionControl' | 'adaptive' | 'numAttempts' | 'completionStatus'>): boolean;
|
|
90
|
+
/** The guards of one item session, from its session control, its facts, its part and its variables. */
|
|
91
|
+
export declare function itemLifecycleGuards(input: ItemLifecycleInput): ItemLifecycleGuards;
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
//# 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,EA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,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 /** The item's `numAttempts`. */\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"]}
|
|
@@ -4,8 +4,10 @@ export interface CreateDeliveryStateOptions {
|
|
|
4
4
|
clock: Clock;
|
|
5
5
|
seed?: string | null;
|
|
6
6
|
/**
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
7
|
+
* The items after selection and ordering, in the order the candidate meets them: the rendered
|
|
8
|
+
* test's item-ref identifiers, where a `with-replacement` clone is its instance id (`item-3#2`,
|
|
9
|
+
* roadmap 1 T4) and keeps that occurrence wherever ordering put it. An item-ref listed again
|
|
10
|
+
* without a suffix is its next free occurrence.
|
|
9
11
|
*/
|
|
10
12
|
order?: readonly string[];
|
|
11
13
|
}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import { DELIVERY_STATE_VERSION, itemInstanceId } from './delivery-state.js';
|
|
1
|
+
import { DELIVERY_STATE_VERSION, itemInstanceId, parseItemInstanceId } from './delivery-state.js';
|
|
2
2
|
/**
|
|
3
3
|
* A fresh delivery state: the item instances in `order`, nothing on screen, no plugin entries,
|
|
4
4
|
* started now by the given clock.
|
|
5
5
|
*/
|
|
6
6
|
export function createDeliveryState({ clock, seed = null, order = [] }) {
|
|
7
|
-
const
|
|
7
|
+
const parsed = order.map(parseItemInstanceId);
|
|
8
|
+
// Occurrences the order names itself, so a bare repeat never takes a clone's number.
|
|
9
|
+
const taken = new Set(parsed.filter(p => p.occurrence > 1).map(p => itemInstanceId(p.itemRefIdentifier, p.occurrence)));
|
|
8
10
|
const items = {};
|
|
9
|
-
const instances =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const instances = parsed.map(({ itemRefIdentifier, occurrence }) => {
|
|
12
|
+
let id = itemInstanceId(itemRefIdentifier, occurrence);
|
|
13
|
+
if (occurrence === 1) {
|
|
14
|
+
while (Object.hasOwn(items, id) || taken.has(id))
|
|
15
|
+
id = itemInstanceId(itemRefIdentifier, ++occurrence);
|
|
16
|
+
}
|
|
17
|
+
else if (Object.hasOwn(items, id)) {
|
|
18
|
+
throw new RangeError(`The order lists the item instance ${id} twice.`);
|
|
19
|
+
}
|
|
13
20
|
items[id] = { itemRefIdentifier, occurrence };
|
|
14
21
|
return id;
|
|
15
22
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-delivery-state.js","sourceRoot":"","sources":["../../src/state/create-delivery-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-delivery-state.js","sourceRoot":"","sources":["../../src/state/create-delivery-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAiBlG;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,EAA8B;IAChG,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC9C,qFAAqF;IACrF,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CACjG,CAAC;IACF,MAAM,KAAK,GAA8C,EAAE,CAAC;IAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,EAAE,UAAU,EAAE,EAAE,EAAE;QACjE,IAAI,EAAE,GAAG,cAAc,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QACvD,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,EAAE,GAAG,cAAc,CAAC,iBAAiB,EAAE,EAAE,UAAU,CAAC,CAAC;QACzG,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,UAAU,CAAC,qCAAqC,EAAE,SAAS,CAAC,CAAC;QACzE,CAAC;QACD,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE,sBAAsB;QAC/B,IAAI;QACJ,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE;QACtB,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,EAAE;QACX,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { DELIVERY_STATE_VERSION, itemInstanceId, parseItemInstanceId } from './delivery-state.js';\n\nimport type { Clock } from './clock.js';\nimport type { DeliveryState, ItemDeliveryState, ItemInstanceId } from './delivery-state.js';\n\nexport interface CreateDeliveryStateOptions {\n clock: Clock;\n seed?: string | null;\n /**\n * The items after selection and ordering, in the order the candidate meets them: the rendered\n * test's item-ref identifiers, where a `with-replacement` clone is its instance id (`item-3#2`,\n * roadmap 1 T4) and keeps that occurrence wherever ordering put it. An item-ref listed again\n * without a suffix is its next free occurrence.\n */\n order?: readonly string[];\n}\n\n/**\n * A fresh delivery state: the item instances in `order`, nothing on screen, no plugin entries,\n * started now by the given clock.\n */\nexport function createDeliveryState({ clock, seed = null, order = [] }: CreateDeliveryStateOptions): DeliveryState {\n const parsed = order.map(parseItemInstanceId);\n // Occurrences the order names itself, so a bare repeat never takes a clone's number.\n const taken = new Set(\n parsed.filter(p => p.occurrence > 1).map(p => itemInstanceId(p.itemRefIdentifier, p.occurrence))\n );\n const items: Record<ItemInstanceId, ItemDeliveryState> = {};\n const instances = parsed.map(({ itemRefIdentifier, occurrence }) => {\n let id = itemInstanceId(itemRefIdentifier, occurrence);\n if (occurrence === 1) {\n while (Object.hasOwn(items, id) || taken.has(id)) id = itemInstanceId(itemRefIdentifier, ++occurrence);\n } else if (Object.hasOwn(items, id)) {\n throw new RangeError(`The order lists the item instance ${id} twice.`);\n }\n items[id] = { itemRefIdentifier, occurrence };\n return id;\n });\n return {\n version: DELIVERY_STATE_VERSION,\n seed,\n startedAt: clock.now(),\n current: null,\n order: instances,\n plugins: {},\n items\n };\n}\n"]}
|
|
@@ -46,6 +46,15 @@ export interface DeliveryState {
|
|
|
46
46
|
}
|
|
47
47
|
/** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */
|
|
48
48
|
export declare const itemInstanceId: (itemRefIdentifier: string, occurrence?: number) => ItemInstanceId;
|
|
49
|
+
/**
|
|
50
|
+
* The item-ref and occurrence an instance id names, the inverse of `itemInstanceId`: `item-3#2` is
|
|
51
|
+
* the second selection of `item-3`. Only a suffix `itemInstanceId` writes (`#2` and up) counts; `#`
|
|
52
|
+
* cannot occur in a QTI identifier, so no authored identifier reads as a clone.
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseItemInstanceId(id: ItemInstanceId): {
|
|
55
|
+
itemRefIdentifier: string;
|
|
56
|
+
occurrence: number;
|
|
57
|
+
};
|
|
49
58
|
/**
|
|
50
59
|
* Read a stored state back. Throws on a state this release cannot read rather than guessing, so a
|
|
51
60
|
* host never resumes from something half understood: a `RangeError` for another version, a
|
|
@@ -11,6 +11,18 @@
|
|
|
11
11
|
export const DELIVERY_STATE_VERSION = 1;
|
|
12
12
|
/** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */
|
|
13
13
|
export const itemInstanceId = (itemRefIdentifier, occurrence = 1) => occurrence === 1 ? itemRefIdentifier : `${itemRefIdentifier}#${occurrence}`;
|
|
14
|
+
/**
|
|
15
|
+
* The item-ref and occurrence an instance id names, the inverse of `itemInstanceId`: `item-3#2` is
|
|
16
|
+
* the second selection of `item-3`. Only a suffix `itemInstanceId` writes (`#2` and up) counts; `#`
|
|
17
|
+
* cannot occur in a QTI identifier, so no authored identifier reads as a clone.
|
|
18
|
+
*/
|
|
19
|
+
export function parseItemInstanceId(id) {
|
|
20
|
+
const match = /^(.+)#([1-9]\d*)$/.exec(id);
|
|
21
|
+
const occurrence = match ? Number(match[2]) : 1;
|
|
22
|
+
return match && occurrence >= 2
|
|
23
|
+
? { itemRefIdentifier: match[1], occurrence }
|
|
24
|
+
: { itemRefIdentifier: id, occurrence: 1 };
|
|
25
|
+
}
|
|
14
26
|
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
15
27
|
/**
|
|
16
28
|
* Read a stored state back. Throws on a state this release cannot read rather than guessing, so a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery-state.js","sourceRoot":"","sources":["../../src/state/delivery-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAwCxC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,iBAAyB,EAAE,UAAU,GAAG,CAAC,EAAkB,EAAE,CAC1F,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAA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,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;QAC1E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,iBAAiB,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACxG,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,+DAA+D,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,CAAC,EAAW,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC;IAC5F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,OAAO,EAAE,mCAAmC,CAAC,CAAC;IACrG,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,IAAI,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;IAC5F,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACrD,OAAO,KAAiC,CAAC;AAC3C,CAAC","sourcesContent":["/**\n * The one source of truth for one candidate in one test: what a resumed test, or a server taking\n * over, needs to carry on. Written only through commands; every context is an input or a view\n * derived from it, and anything derivable (done, can*, scores) is never stored here. Plain JSON,\n * versioned, so a stored state can be read back by a later release (or a .NET port) and refused\n * when it cannot.\n *\n * Experimental (0.x): roadmap 1 fills in the target fields, phase by phase; see\n * `plans/delivery-state.md`.\n */\nexport const DELIVERY_STATE_VERSION = 1;\n\n/**\n * One item session. With `with-replacement` selection a single item-ref appears more than once,\n * so a session is keyed by its instance, never by the item-ref identifier alone.\n */\nexport type ItemInstanceId = string;\n\nexport interface ItemDeliveryState {\n /** The `identifier` of the `qti-assessment-item-ref` this instance was selected from. */\n itemRefIdentifier: string;\n /** 1 for the first time the item-ref was selected, 2 for its first clone, and so on. */\n occurrence: number;\n}\n\nexport interface DeliveryState {\n version: typeof DELIVERY_STATE_VERSION;\n /**\n * The seed actually used for selection and ordering; the same seed gives the same test on every\n * runtime. On a first start it comes from the host (`qtiContext.seed`); on resume this one wins.\n */\n seed: string | null;\n /** When the test started, in milliseconds since the epoch, read from the injected clock. */\n startedAt: number;\n /** The item instance on screen, or null before the first navigation and after the end. */\n current: ItemInstanceId | null;\n /**\n * Every item instance of the test after selection and ordering, in the order the candidate meets\n * them; written once, when the test starts. Each one is a key of `items`.\n */\n order: ItemInstanceId[];\n /**\n * What test plugins keep, by plugin name: JSON, stored and restored without being read (a\n * plugin reads its own entry).\n */\n plugins: Record<string, unknown>;\n /** One entry per instance in `order`. */\n items: Record<ItemInstanceId, ItemDeliveryState>;\n}\n\n/** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */\nexport const itemInstanceId = (itemRefIdentifier: string, occurrence = 1): ItemInstanceId =>\n occurrence === 1 ? itemRefIdentifier : `${itemRefIdentifier}#${occurrence}`;\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read a stored state back. Throws on a state this release cannot read rather than guessing, so a\n * host never resumes from something half understood: a `RangeError` for another version, a\n * `TypeError` for anything that is not a version 1 state (a missing or mistyped field, an `order`\n * or `current` that names an instance `items` does not have).\n */\nexport function parseDeliveryState(value: unknown): DeliveryState {\n if (!isRecord(value)) {\n throw new TypeError('A delivery state is an object.');\n }\n const { version } = value;\n if (version !== DELIVERY_STATE_VERSION) {\n throw new RangeError(\n `Delivery state version ${String(version)} is not supported; expected ${DELIVERY_STATE_VERSION}.`\n );\n }\n const { seed, startedAt, current, order, plugins, items } = value;\n const fail = (field: string, expected: string): never => {\n throw new TypeError(`A delivery state's ${field} must be ${expected}.`);\n };\n if (seed !== null && typeof seed !== 'string') fail('seed', 'a string or null');\n if (typeof startedAt !== 'number' || !Number.isFinite(startedAt)) fail('startedAt', 'a number');\n if (!isRecord(items)) fail('items', 'an object');\n for (const [id, item] of Object.entries(items as Record<string, unknown>)) {\n if (!isRecord(item) || typeof item.itemRefIdentifier !== 'string' || !Number.isInteger(item.occurrence)) {\n fail(`items[\"${id}\"]`, 'an object with an itemRefIdentifier and an integer occurrence');\n }\n }\n const known = (id: unknown) => typeof id === 'string' && Object.hasOwn(items as object, id);\n if (!Array.isArray(order) || !order.every(known)) fail('order', 'an array of instance ids in items');\n if (current !== null && !known(current)) fail('current', 'null or an instance id in items');\n if (!isRecord(plugins)) fail('plugins', 'an object');\n return value as unknown as DeliveryState;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"delivery-state.js","sourceRoot":"","sources":["../../src/state/delivery-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAwCxC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,iBAAyB,EAAE,UAAU,GAAG,CAAC,EAAkB,EAAE,CAC1F,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,IAAI,UAAU,EAAE,CAAC;AAE9E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAkB;IACpD,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,KAAK,IAAI,UAAU,IAAI,CAAC;QAC7B,CAAC,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE;QAC7C,CAAC,CAAC,EAAE,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AE,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,EAAE,CAAC;QAC1E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,OAAO,IAAI,CAAC,iBAAiB,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACxG,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,+DAA+D,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,CAAC,EAAW,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC;IAC5F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,OAAO,EAAE,mCAAmC,CAAC,CAAC;IACrG,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,IAAI,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;IAC5F,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACrD,OAAO,KAAiC,CAAC;AAC3C,CAAC","sourcesContent":["/**\n * The one source of truth for one candidate in one test: what a resumed test, or a server taking\n * over, needs to carry on. Written only through commands; every context is an input or a view\n * derived from it, and anything derivable (done, can*, scores) is never stored here. Plain JSON,\n * versioned, so a stored state can be read back by a later release (or a .NET port) and refused\n * when it cannot.\n *\n * Experimental (0.x): roadmap 1 fills in the target fields, phase by phase; see\n * `plans/delivery-state.md`.\n */\nexport const DELIVERY_STATE_VERSION = 1;\n\n/**\n * One item session. With `with-replacement` selection a single item-ref appears more than once,\n * so a session is keyed by its instance, never by the item-ref identifier alone.\n */\nexport type ItemInstanceId = string;\n\nexport interface ItemDeliveryState {\n /** The `identifier` of the `qti-assessment-item-ref` this instance was selected from. */\n itemRefIdentifier: string;\n /** 1 for the first time the item-ref was selected, 2 for its first clone, and so on. */\n occurrence: number;\n}\n\nexport interface DeliveryState {\n version: typeof DELIVERY_STATE_VERSION;\n /**\n * The seed actually used for selection and ordering; the same seed gives the same test on every\n * runtime. On a first start it comes from the host (`qtiContext.seed`); on resume this one wins.\n */\n seed: string | null;\n /** When the test started, in milliseconds since the epoch, read from the injected clock. */\n startedAt: number;\n /** The item instance on screen, or null before the first navigation and after the end. */\n current: ItemInstanceId | null;\n /**\n * Every item instance of the test after selection and ordering, in the order the candidate meets\n * them; written once, when the test starts. Each one is a key of `items`.\n */\n order: ItemInstanceId[];\n /**\n * What test plugins keep, by plugin name: JSON, stored and restored without being read (a\n * plugin reads its own entry).\n */\n plugins: Record<string, unknown>;\n /** One entry per instance in `order`. */\n items: Record<ItemInstanceId, ItemDeliveryState>;\n}\n\n/** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */\nexport const itemInstanceId = (itemRefIdentifier: string, occurrence = 1): ItemInstanceId =>\n occurrence === 1 ? itemRefIdentifier : `${itemRefIdentifier}#${occurrence}`;\n\n/**\n * The item-ref and occurrence an instance id names, the inverse of `itemInstanceId`: `item-3#2` is\n * the second selection of `item-3`. Only a suffix `itemInstanceId` writes (`#2` and up) counts; `#`\n * cannot occur in a QTI identifier, so no authored identifier reads as a clone.\n */\nexport function parseItemInstanceId(id: ItemInstanceId): { itemRefIdentifier: string; occurrence: number } {\n const match = /^(.+)#([1-9]\\d*)$/.exec(id);\n const occurrence = match ? Number(match[2]) : 1;\n return match && occurrence >= 2\n ? { itemRefIdentifier: match[1], occurrence }\n : { itemRefIdentifier: id, occurrence: 1 };\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read a stored state back. Throws on a state this release cannot read rather than guessing, so a\n * host never resumes from something half understood: a `RangeError` for another version, a\n * `TypeError` for anything that is not a version 1 state (a missing or mistyped field, an `order`\n * or `current` that names an instance `items` does not have).\n */\nexport function parseDeliveryState(value: unknown): DeliveryState {\n if (!isRecord(value)) {\n throw new TypeError('A delivery state is an object.');\n }\n const { version } = value;\n if (version !== DELIVERY_STATE_VERSION) {\n throw new RangeError(\n `Delivery state version ${String(version)} is not supported; expected ${DELIVERY_STATE_VERSION}.`\n );\n }\n const { seed, startedAt, current, order, plugins, items } = value;\n const fail = (field: string, expected: string): never => {\n throw new TypeError(`A delivery state's ${field} must be ${expected}.`);\n };\n if (seed !== null && typeof seed !== 'string') fail('seed', 'a string or null');\n if (typeof startedAt !== 'number' || !Number.isFinite(startedAt)) fail('startedAt', 'a number');\n if (!isRecord(items)) fail('items', 'an object');\n for (const [id, item] of Object.entries(items as Record<string, unknown>)) {\n if (!isRecord(item) || typeof item.itemRefIdentifier !== 'string' || !Number.isInteger(item.occurrence)) {\n fail(`items[\"${id}\"]`, 'an object with an itemRefIdentifier and an integer occurrence');\n }\n }\n const known = (id: unknown) => typeof id === 'string' && Object.hasOwn(items as object, id);\n if (!Array.isArray(order) || !order.every(known)) fail('order', 'an array of instance ids in items');\n if (current !== null && !known(current)) fail('current', 'null or an instance id in items');\n if (!isRecord(plugins)) fail('plugins', 'an object');\n return value as unknown as DeliveryState;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qti-components/delivery",
|
|
3
3
|
"description": "The QTI 3 delivery engine: test model, item session lifecycle, sequencing and session state, with no browser globals",
|
|
4
|
-
"version": "0.1.0-next.
|
|
4
|
+
"version": "0.1.0-next.4",
|
|
5
5
|
"author": "",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"qti",
|