@qti-components/delivery 0.1.0-next.10 → 0.1.0-next.12
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 +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lifecycle/part-submission.d.ts +34 -0
- package/dist/lifecycle/part-submission.js +44 -0
- package/dist/lifecycle/part-submission.js.map +1 -0
- package/dist/model/test-model.d.ts +24 -0
- package/dist/model/test-model.js +13 -0
- package/dist/model/test-model.js.map +1 -1
- package/dist/sequencing/sequencing.d.ts +62 -0
- package/dist/sequencing/sequencing.js +226 -0
- package/dist/sequencing/sequencing.js.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export type { XmlElement, XmlNode } from './model/xml-node.js';
|
|
|
4
4
|
export * from './lifecycle/item-lifecycle.js';
|
|
5
5
|
export * from './lifecycle/item-rules.js';
|
|
6
6
|
export * from './lifecycle/item-session.js';
|
|
7
|
+
export * from './lifecycle/part-submission.js';
|
|
7
8
|
export * from './random/seeded-random.js';
|
|
8
9
|
export * from './random/selection.js';
|
|
9
10
|
export * from './random/shuffle.js';
|
|
@@ -12,5 +13,6 @@ export * from './state/commands.js';
|
|
|
12
13
|
export * from './state/create-delivery-state.js';
|
|
13
14
|
export * from './state/delivery-state.js';
|
|
14
15
|
export * from './processing.js';
|
|
16
|
+
export * from './sequencing/sequencing.js';
|
|
15
17
|
export * from './timing/timing.js';
|
|
16
18
|
export * from './timing/time-limits.js';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from './model/item-facts.js';
|
|
|
3
3
|
export * from './lifecycle/item-lifecycle.js';
|
|
4
4
|
export * from './lifecycle/item-rules.js';
|
|
5
5
|
export * from './lifecycle/item-session.js';
|
|
6
|
+
export * from './lifecycle/part-submission.js';
|
|
6
7
|
export * from './random/seeded-random.js';
|
|
7
8
|
export * from './random/selection.js';
|
|
8
9
|
export * from './random/shuffle.js';
|
|
@@ -11,6 +12,7 @@ export * from './state/commands.js';
|
|
|
11
12
|
export * from './state/create-delivery-state.js';
|
|
12
13
|
export * from './state/delivery-state.js';
|
|
13
14
|
export * from './processing.js';
|
|
15
|
+
export * from './sequencing/sequencing.js';
|
|
14
16
|
export * from './timing/timing.js';
|
|
15
17
|
export * from './timing/time-limits.js';
|
|
16
18
|
//# 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,+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"]}
|
|
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,gCAAgC,CAAC;AAC/C,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,4BAA4B,CAAC;AAC3C,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 './lifecycle/part-submission.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 './sequencing/sequencing.js';\nexport * from './timing/timing.js';\nexport * from './timing/time-limits.js';\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Effect } from '../state/commands.js';
|
|
2
|
+
import type { ItemInstanceId } from '../state/delivery-state.js';
|
|
3
|
+
import type { ItemSession, ItemSessionFacts } from './item-session.js';
|
|
4
|
+
/** One item session of the part being submitted: its instance, its session so far, and its facts now. */
|
|
5
|
+
export interface PartSubmissionItem {
|
|
6
|
+
readonly item: ItemInstanceId;
|
|
7
|
+
/** The session as the delivery kept it; null when it has none yet (a restored state). */
|
|
8
|
+
readonly previous: ItemSession | null;
|
|
9
|
+
readonly facts: ItemSessionFacts;
|
|
10
|
+
}
|
|
11
|
+
/** The part's item sessions after the submission, in the order given, and what the runtime has to run. */
|
|
12
|
+
export interface PartSubmission {
|
|
13
|
+
readonly sessions: {
|
|
14
|
+
readonly item: ItemInstanceId;
|
|
15
|
+
readonly session: ItemSession;
|
|
16
|
+
}[];
|
|
17
|
+
/** `runOutcomeProcessing` once, after the items. */
|
|
18
|
+
readonly effects: Effect[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Submits a part with simultaneous submission as a whole (QTI 3 info model §2.8.2, implementation
|
|
22
|
+
* guide §4.1): "response processing cannot take place until the test part is complete", and then
|
|
23
|
+
* the candidate's responses "are all submitted together". Each item the candidate opened has its one
|
|
24
|
+
* and only attempt counted and its session closes. Its responses were already processed in the
|
|
25
|
+
* background while the part ran, without ending the attempt (the paper-exam model, decided
|
|
26
|
+
* 2026-12-01), so nothing is processed again here. An item never opened (`completionStatus`
|
|
27
|
+
* `not_attempted`) is closed with its NULL responses and counts no attempt, as a skipped item is. A
|
|
28
|
+
* session already over is left as it is. Outcome processing runs once, after the items (§2.9).
|
|
29
|
+
*
|
|
30
|
+
* Returns null for a part with individual submission: its items are submitted one by one.
|
|
31
|
+
*
|
|
32
|
+
* Experimental (0.x): roadmap 1 phase T6; see `plans/submission-mode-scoring.md`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function submitTestPart(items: readonly PartSubmissionItem[]): PartSubmission | null;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { seedItemLifecycle, transition, itemLifecycleGuards } from './item-lifecycle.js';
|
|
2
|
+
const OVER = new Set(['closed', 'review', 'solution']);
|
|
3
|
+
/**
|
|
4
|
+
* Submits a part with simultaneous submission as a whole (QTI 3 info model §2.8.2, implementation
|
|
5
|
+
* guide §4.1): "response processing cannot take place until the test part is complete", and then
|
|
6
|
+
* the candidate's responses "are all submitted together". Each item the candidate opened has its one
|
|
7
|
+
* and only attempt counted and its session closes. Its responses were already processed in the
|
|
8
|
+
* background while the part ran, without ending the attempt (the paper-exam model, decided
|
|
9
|
+
* 2026-12-01), so nothing is processed again here. An item never opened (`completionStatus`
|
|
10
|
+
* `not_attempted`) is closed with its NULL responses and counts no attempt, as a skipped item is. A
|
|
11
|
+
* session already over is left as it is. Outcome processing runs once, after the items (§2.9).
|
|
12
|
+
*
|
|
13
|
+
* Returns null for a part with individual submission: its items are submitted one by one.
|
|
14
|
+
*
|
|
15
|
+
* Experimental (0.x): roadmap 1 phase T6; see `plans/submission-mode-scoring.md`.
|
|
16
|
+
*/
|
|
17
|
+
export function submitTestPart(items) {
|
|
18
|
+
if (items.some(({ facts }) => facts.submissionMode !== 'simultaneous'))
|
|
19
|
+
return null;
|
|
20
|
+
const sessions = [];
|
|
21
|
+
const effects = [];
|
|
22
|
+
for (const { item, previous, facts } of items) {
|
|
23
|
+
const { adaptive } = facts;
|
|
24
|
+
const state = previous?.state ?? seedItemLifecycle(facts);
|
|
25
|
+
if (OVER.has(state)) {
|
|
26
|
+
sessions.push({ item, session: { state, numAttempts: facts.numAttempts, adaptive } });
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
// A restored session not on screen seeds as `initial`; `completionStatus` still says it was opened.
|
|
30
|
+
const opened = state !== 'initial' || facts.completionStatus !== 'not_attempted';
|
|
31
|
+
const guards = itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });
|
|
32
|
+
sessions.push({
|
|
33
|
+
item,
|
|
34
|
+
session: {
|
|
35
|
+
state: transition(state, 'endItemSession', guards) ?? 'closed',
|
|
36
|
+
numAttempts: facts.numAttempts + (opened ? 1 : 0),
|
|
37
|
+
adaptive
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
effects.push({ type: 'runOutcomeProcessing' });
|
|
42
|
+
return { sessions, effects };
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=part-submission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"part-submission.js","sourceRoot":"","sources":["../../src/lifecycle/part-submission.ts"],"names":[],"mappings":"AA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,KAAK,EAAE,gBAAgB,EAAE,MAAM,CAAC,IAAI,QAAQ;gBAC9D,WAAW,EAAE,KAAK,CAAC,WAAW,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACjD,QAAQ;aACT;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,sBAAsB,EAAE,CAAC,CAAC;IAC/C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC","sourcesContent":["import { seedItemLifecycle, transition, itemLifecycleGuards } from './item-lifecycle.js';\n\nimport type { Effect } from '../state/commands.js';\nimport type { ItemInstanceId } from '../state/delivery-state.js';\nimport type { ItemSession, ItemSessionFacts } from './item-session.js';\n\n/** One item session of the part being submitted: its instance, its session so far, and its facts now. */\nexport interface PartSubmissionItem {\n readonly item: ItemInstanceId;\n /** The session as the delivery kept it; null when it has none yet (a restored state). */\n readonly previous: ItemSession | null;\n readonly facts: ItemSessionFacts;\n}\n\n/** The part's item sessions after the submission, in the order given, and what the runtime has to run. */\nexport interface PartSubmission {\n readonly sessions: { readonly item: ItemInstanceId; readonly session: ItemSession }[];\n /** `runOutcomeProcessing` once, after the items. */\n readonly effects: Effect[];\n}\n\nconst OVER = new Set(['closed', 'review', 'solution']);\n\n/**\n * Submits a part with simultaneous submission as a whole (QTI 3 info model §2.8.2, implementation\n * guide §4.1): \"response processing cannot take place until the test part is complete\", and then\n * the candidate's responses \"are all submitted together\". Each item the candidate opened has its one\n * and only attempt counted and its session closes. Its responses were already processed in the\n * background while the part ran, without ending the attempt (the paper-exam model, decided\n * 2026-12-01), so nothing is processed again here. An item never opened (`completionStatus`\n * `not_attempted`) is closed with its NULL responses and counts no attempt, as a skipped item is. A\n * session already over is left as it is. Outcome processing runs once, after the items (§2.9).\n *\n * Returns null for a part with individual submission: its items are submitted one by one.\n *\n * Experimental (0.x): roadmap 1 phase T6; see `plans/submission-mode-scoring.md`.\n */\nexport function submitTestPart(items: readonly PartSubmissionItem[]): PartSubmission | null {\n if (items.some(({ facts }) => facts.submissionMode !== 'simultaneous')) return null;\n const sessions: PartSubmission['sessions'] = [];\n const effects: Effect[] = [];\n for (const { item, previous, facts } of items) {\n const { adaptive } = facts;\n const state = previous?.state ?? seedItemLifecycle(facts);\n if (OVER.has(state)) {\n sessions.push({ item, session: { state, numAttempts: facts.numAttempts, adaptive } });\n continue;\n }\n // A restored session not on screen seeds as `initial`; `completionStatus` still says it was opened.\n const opened = state !== 'initial' || facts.completionStatus !== 'not_attempted';\n const guards = itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false });\n sessions.push({\n item,\n session: {\n state: transition(state, 'endItemSession', guards) ?? 'closed',\n numAttempts: facts.numAttempts + (opened ? 1 : 0),\n adaptive\n }\n });\n }\n effects.push({ type: 'runOutcomeProcessing' });\n return { sessions, effects };\n}\n"]}
|
|
@@ -18,16 +18,36 @@ export interface TestPartModel {
|
|
|
18
18
|
navigationMode: 'linear' | 'nonlinear';
|
|
19
19
|
submissionMode: 'individual' | 'simultaneous';
|
|
20
20
|
sessionControl: SessionControl;
|
|
21
|
+
/** How many `qti-pre-condition`s the part has; a part's are always considered (impl. guide §4.5.3). */
|
|
22
|
+
preConditions: number;
|
|
23
|
+
/** Its `qti-branch-rule`s, in document order; a part's are always considered. */
|
|
24
|
+
branchRules: BranchRuleModel[];
|
|
21
25
|
/** The part's own `qti-time-limits`; absent when it declares none. */
|
|
22
26
|
timeLimits?: TimeLimits;
|
|
23
27
|
sections: SectionModel[];
|
|
24
28
|
}
|
|
29
|
+
/** A `qti-branch-rule`: where the test goes when its expression is true (info model §5.23). */
|
|
30
|
+
export interface BranchRuleModel {
|
|
31
|
+
/** An item-ref, section or test part identifier, or `EXIT_SECTION`, `EXIT_TESTPART`, `EXIT_TEST`. */
|
|
32
|
+
target: string;
|
|
33
|
+
}
|
|
34
|
+
/** The attribute `qtiTransformTest` puts on a section it merged from a `qti-assessment-section-ref`. */
|
|
35
|
+
export declare const SECTION_REF_ATTRIBUTE = "data-qc-section-ref";
|
|
25
36
|
export interface SectionModel {
|
|
26
37
|
kind: 'section';
|
|
27
38
|
identifier: string;
|
|
28
39
|
title: string;
|
|
29
40
|
visible: boolean;
|
|
30
41
|
sessionControl: SessionControl;
|
|
42
|
+
/**
|
|
43
|
+
* Merged from a `qti-assessment-section-ref`: branch rules outside it treat it as a leaf and
|
|
44
|
+
* cannot target what is inside it (info model §7.5).
|
|
45
|
+
*/
|
|
46
|
+
fromSectionRef: boolean;
|
|
47
|
+
/** How many `qti-pre-condition`s it has; considered only in a linear part. */
|
|
48
|
+
preConditions: number;
|
|
49
|
+
/** Its `qti-branch-rule`s, in document order; considered only in a linear part. */
|
|
50
|
+
branchRules: BranchRuleModel[];
|
|
31
51
|
/** The section's own `qti-time-limits`; absent when it declares none. */
|
|
32
52
|
timeLimits?: TimeLimits;
|
|
33
53
|
/** The item-refs and sections directly inside this one, in document order, as the XML has them. */
|
|
@@ -41,6 +61,10 @@ export interface ItemRefModel {
|
|
|
41
61
|
sessionControl: SessionControl;
|
|
42
62
|
/** What this item-ref's own `qti-item-session-control` declares, nothing inherited. */
|
|
43
63
|
declaredSessionControl: Partial<SessionControl>;
|
|
64
|
+
/** How many `qti-pre-condition`s it has; considered only in a linear part. */
|
|
65
|
+
preConditions: number;
|
|
66
|
+
/** Its `qti-branch-rule`s, in document order; considered only in a linear part. */
|
|
67
|
+
branchRules: BranchRuleModel[];
|
|
44
68
|
/** The item-ref's own `qti-time-limits`; absent when it declares none. */
|
|
45
69
|
timeLimits?: TimeLimits;
|
|
46
70
|
}
|
package/dist/model/test-model.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { booleanAttribute, childElement, childElements, integerAttribute, nonNegativeNumberAttribute } from './xml-node.js';
|
|
2
|
+
/** The attribute `qtiTransformTest` puts on a section it merged from a `qti-assessment-section-ref`. */
|
|
3
|
+
export const SECTION_REF_ATTRIBUTE = 'data-qc-section-ref';
|
|
2
4
|
/**
|
|
3
5
|
* The values when no level declares an attribute: the XSD defaults, and 1 for `max-attempts`,
|
|
4
6
|
* which the spec text gives ("if it is unspecified it is treated as 1 for non-adaptive items").
|
|
@@ -40,6 +42,7 @@ function buildTestPart(part) {
|
|
|
40
42
|
navigationMode: part.getAttribute('navigation-mode') === 'linear' ? 'linear' : 'nonlinear',
|
|
41
43
|
submissionMode: part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual',
|
|
42
44
|
sessionControl,
|
|
45
|
+
...sequencingRules(part),
|
|
43
46
|
...timeLimitsOf(part),
|
|
44
47
|
sections: childElements(part, 'qti-assessment-section').map(section => buildSection(section, sessionControl))
|
|
45
48
|
};
|
|
@@ -52,6 +55,8 @@ function buildSection(section, inherited) {
|
|
|
52
55
|
title: section.getAttribute('title') ?? '',
|
|
53
56
|
visible: booleanAttribute(section, 'visible') ?? true,
|
|
54
57
|
sessionControl,
|
|
58
|
+
fromSectionRef: section.getAttribute(SECTION_REF_ATTRIBUTE) !== null,
|
|
59
|
+
...sequencingRules(section),
|
|
55
60
|
...timeLimitsOf(section),
|
|
56
61
|
content: childElements(section, 'qti-assessment-section', 'qti-assessment-item-ref').map(child => child.localName === 'qti-assessment-section'
|
|
57
62
|
? buildSection(child, sessionControl)
|
|
@@ -67,9 +72,17 @@ function buildItemRef(itemRef, inherited) {
|
|
|
67
72
|
categories: category ? category.split(/\s+/) : [],
|
|
68
73
|
sessionControl: resolveSessionControl(inherited, itemRef),
|
|
69
74
|
declaredSessionControl: declaredSessionControl(itemRef),
|
|
75
|
+
...sequencingRules(itemRef),
|
|
70
76
|
...timeLimitsOf(itemRef)
|
|
71
77
|
};
|
|
72
78
|
}
|
|
79
|
+
/** The `qti-pre-condition`s (counted) and `qti-branch-rule`s directly inside `owner`. */
|
|
80
|
+
function sequencingRules(owner) {
|
|
81
|
+
return {
|
|
82
|
+
preConditions: childElements(owner, 'qti-pre-condition').length,
|
|
83
|
+
branchRules: childElements(owner, 'qti-branch-rule').map(rule => ({ target: rule.getAttribute('target') ?? '' }))
|
|
84
|
+
};
|
|
85
|
+
}
|
|
73
86
|
/** `inherited`, with what `owner`'s own `qti-item-session-control` declares on top. */
|
|
74
87
|
function resolveSessionControl(inherited, owner) {
|
|
75
88
|
return { ...inherited, ...declaredSessionControl(owner) };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-model.js","sourceRoot":"","sources":["../../src/model/test-model.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,eAAe,CAAC;AAsFvB;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAA6B,MAAM,CAAC,MAAM,CAAC;IAC7E,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,KAAK;IACnB,WAAW,EAAE,IAAI;IACjB,YAAY,EAAE,KAAK;IACnB,YAAY,EAAE,KAAK;IACnB,aAAa,EAAE,IAAI;IACnB,iBAAiB,EAAE,KAAK;CACzB,CAAC,CAAC;AAEH;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,IAAI,IAAI,CAAC,SAAS,KAAK,qBAAqB,EAAE,CAAC;QAC7C,MAAM,IAAI,SAAS,CAAC,+CAA+C,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAChG,CAAC;IACD,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,EAAE;QACjD,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE;QACvC,GAAG,YAAY,CAAC,IAAI,CAAC;QACrB,SAAS,EAAE,aAAa,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC;KACnE,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,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ACL,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,eAAe,CAAC,QAA0B;IACxD,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC","sourcesContent":["import {\n booleanAttribute,\n childElement,\n childElements,\n integerAttribute,\n nonNegativeNumberAttribute\n} from './xml-node.js';\n\nimport type { XmlElement } from './xml-node.js';\n\n/**\n * The structure and the resolved rules of a `qti-assessment-test`, read from its XML once per load.\n * Plain JSON, so a server can build it from the same file.\n *\n * Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.\n */\nexport interface TestModel {\n identifier: string;\n title: string;\n /** The test's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n testParts: TestPartModel[];\n}\n\nexport interface TestPartModel {\n identifier: string;\n /** Defined on the test part only (QTI 3 XSD); a section never changes it. */\n navigationMode: 'linear' | 'nonlinear';\n submissionMode: 'individual' | 'simultaneous';\n sessionControl: SessionControl;\n /** The part's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n sections: SectionModel[];\n}\n\nexport interface SectionModel {\n kind: 'section';\n identifier: string;\n title: string;\n visible: boolean;\n sessionControl: SessionControl;\n /** The section's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n /** The item-refs and sections directly inside this one, in document order, as the XML has them. */\n content: SectionContent[];\n}\n\nexport interface ItemRefModel {\n kind: 'itemRef';\n identifier: string;\n href: string;\n categories: string[];\n sessionControl: SessionControl;\n /** What this item-ref's own `qti-item-session-control` declares, nothing inherited. */\n declaredSessionControl: Partial<SessionControl>;\n /** The item-ref's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n}\n\nexport type SectionContent = SectionModel | ItemRefModel;\n\n/** `qti-item-session-control`, resolved for one level (QTI 3 info model §7.19). */\nexport interface SessionControl {\n /** 0 is unlimited. Ignored for adaptive items, which end by `completionStatus`. */\n maxAttempts: number;\n showFeedback: boolean;\n allowReview: boolean;\n showSolution: boolean;\n allowComment: boolean;\n /** Applies only in a test part with individual submission. */\n allowSkipping: boolean;\n /** Applies only in a test part with individual submission. */\n validateResponses: boolean;\n}\n\n/**\n * `qti-time-limits` as one level declares it (QTI 3 info model §7.40, §2.8.5). Never inherited: each\n * limit is on the time spent in its own level, the item-ref's on the item session's `duration`, a\n * section's, part's or test's on all the time spent in it, navigation included.\n */\nexport interface TimeLimits {\n /**\n * Seconds; null when not declared. On a section or item-ref it applies only in a linear part\n * (§2.8.5); `timeLimitRules` leaves it out elsewhere.\n */\n minTime: number | null;\n /** Seconds; null when not declared. */\n maxTime: number | null;\n /** Whether a response given after `maxTime` is still accepted. False when not declared (the XSD default). */\n allowLateSubmission: boolean;\n}\n\n/**\n * The values when no level declares an attribute: the XSD defaults, and 1 for `max-attempts`,\n * which the spec text gives (\"if it is unspecified it is treated as 1 for non-adaptive items\").\n */\nexport const DEFAULT_SESSION_CONTROL: Readonly<SessionControl> = Object.freeze({\n maxAttempts: 1,\n showFeedback: false,\n allowReview: true,\n showSolution: false,\n allowComment: false,\n allowSkipping: true,\n validateResponses: false\n});\n\n/**\n * Build the model of a test from its `qti-assessment-test` element: the XML document under Node, the\n * rendered element in the browser. Reads attributes and child elements only, so no element needs\n * to be registered.\n *\n * Session control inherits per attribute: each one comes from the closest level that declares it\n * (item-ref, then each enclosing section, then the test part), and its default only when none does.\n * The spec: a test-part setting applies \"unless the setting is overridden\", and the defaults \"are\n * used only in the absence of any applicable constraint\" (implementation guide §4.4.2).\n */\nexport function buildTestModel(test: XmlElement): TestModel {\n if (test.localName !== 'qti-assessment-test') {\n throw new TypeError(`Expected a qti-assessment-test element, not ${String(test.localName)}.`);\n }\n return {\n identifier: test.getAttribute('identifier') ?? '',\n title: test.getAttribute('title') ?? '',\n ...timeLimitsOf(test),\n testParts: childElements(test, 'qti-test-part').map(buildTestPart)\n };\n}\n\nfunction buildTestPart(part: XmlElement): TestPartModel {\n const sessionControl = resolveSessionControl(DEFAULT_SESSION_CONTROL, part);\n return {\n identifier: part.getAttribute('identifier') ?? '',\n navigationMode: part.getAttribute('navigation-mode') === 'linear' ? 'linear' : 'nonlinear',\n submissionMode: part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual',\n sessionControl,\n ...timeLimitsOf(part),\n sections: childElements(part, 'qti-assessment-section').map(section => buildSection(section, sessionControl))\n };\n}\n\nfunction buildSection(section: XmlElement, inherited: SessionControl): SectionModel {\n const sessionControl = resolveSessionControl(inherited, section);\n return {\n kind: 'section',\n identifier: section.getAttribute('identifier') ?? '',\n title: section.getAttribute('title') ?? '',\n visible: booleanAttribute(section, 'visible') ?? true,\n sessionControl,\n ...timeLimitsOf(section),\n content: childElements(section, 'qti-assessment-section', 'qti-assessment-item-ref').map(child =>\n child.localName === 'qti-assessment-section'\n ? buildSection(child, sessionControl)\n : buildItemRef(child, sessionControl)\n )\n };\n}\n\nfunction buildItemRef(itemRef: XmlElement, inherited: SessionControl): ItemRefModel {\n const category = itemRef.getAttribute('category')?.trim();\n return {\n kind: 'itemRef',\n identifier: itemRef.getAttribute('identifier') ?? '',\n href: itemRef.getAttribute('href') ?? '',\n categories: category ? category.split(/\\s+/) : [],\n sessionControl: resolveSessionControl(inherited, itemRef),\n declaredSessionControl: declaredSessionControl(itemRef),\n ...timeLimitsOf(itemRef)\n };\n}\n\n/** `inherited`, with what `owner`'s own `qti-item-session-control` declares on top. */\nfunction resolveSessionControl(inherited: Readonly<SessionControl>, owner: XmlElement): SessionControl {\n return { ...inherited, ...declaredSessionControl(owner) };\n}\n\n/** Only the attributes `owner`'s `qti-item-session-control` declares, so an absent one inherits. */\nfunction declaredSessionControl(owner: XmlElement): Partial<SessionControl> {\n const element = childElement(owner, 'qti-item-session-control');\n if (!element) return {};\n const declared: Partial<SessionControl> = {\n maxAttempts: integerAttribute(element, 'max-attempts'),\n showFeedback: booleanAttribute(element, 'show-feedback'),\n allowReview: booleanAttribute(element, 'allow-review'),\n showSolution: booleanAttribute(element, 'show-solution'),\n allowComment: booleanAttribute(element, 'allow-comment'),\n allowSkipping: booleanAttribute(element, 'allow-skipping'),\n validateResponses: booleanAttribute(element, 'validate-responses')\n };\n return Object.fromEntries(Object.entries(declared).filter(([, value]) => value !== undefined));\n}\n\n/**\n * `owner`'s own `qti-time-limits` as `{ timeLimits }`, or nothing when it declares none, so the\n * model holds the key only where the XML has the element. A value that is not a non-negative number\n * counts as not declared.\n */\nfunction timeLimitsOf(owner: XmlElement): { timeLimits?: TimeLimits } {\n const element = childElement(owner, 'qti-time-limits');\n if (!element) return {};\n return {\n timeLimits: {\n minTime: nonNegativeNumberAttribute(element, 'min-time') ?? null,\n maxTime: nonNegativeNumberAttribute(element, 'max-time') ?? null,\n allowLateSubmission: booleanAttribute(element, 'allow-late-submission') ?? false\n }\n };\n}\n\n/** The item-refs directly inside a section, in document order; not those of its subsections. */\nexport const ownItemRefs = (section: SectionModel): ItemRefModel[] =>\n section.content.filter((child): child is ItemRefModel => child.kind === 'itemRef');\n\n/** Every section, depth first in document order: a section before its subsections. */\nexport function sectionsInOrder(sections: SectionModel[]): SectionModel[] {\n return sections.flatMap(section => [\n section,\n ...sectionsInOrder(section.content.filter((child): child is SectionModel => child.kind === 'section'))\n ]);\n}\n\n/** Every item-ref inside the given sections, at any depth, in document order. */\nexport function itemRefsInOrder(sections: SectionContent[]): ItemRefModel[] {\n return sections.flatMap(child => (child.kind === 'itemRef' ? [child] : itemRefsInOrder(child.content)));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-model.js","sourceRoot":"","sources":["../../src/model/test-model.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,0BAA0B,EAC3B,MAAM,eAAe,CAAC;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O;QACP,GAAG,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAyB,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;KACvG,CAAC,CAAC;AACL,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,eAAe,CAAC,QAA0B;IACxD,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1G,CAAC","sourcesContent":["import {\n booleanAttribute,\n childElement,\n childElements,\n integerAttribute,\n nonNegativeNumberAttribute\n} from './xml-node.js';\n\nimport type { XmlElement } from './xml-node.js';\n\n/**\n * The structure and the resolved rules of a `qti-assessment-test`, read from its XML once per load.\n * Plain JSON, so a server can build it from the same file.\n *\n * Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.\n */\nexport interface TestModel {\n identifier: string;\n title: string;\n /** The test's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n testParts: TestPartModel[];\n}\n\nexport interface TestPartModel {\n identifier: string;\n /** Defined on the test part only (QTI 3 XSD); a section never changes it. */\n navigationMode: 'linear' | 'nonlinear';\n submissionMode: 'individual' | 'simultaneous';\n sessionControl: SessionControl;\n /** How many `qti-pre-condition`s the part has; a part's are always considered (impl. guide §4.5.3). */\n preConditions: number;\n /** Its `qti-branch-rule`s, in document order; a part's are always considered. */\n branchRules: BranchRuleModel[];\n /** The part's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n sections: SectionModel[];\n}\n\n/** A `qti-branch-rule`: where the test goes when its expression is true (info model §5.23). */\nexport interface BranchRuleModel {\n /** An item-ref, section or test part identifier, or `EXIT_SECTION`, `EXIT_TESTPART`, `EXIT_TEST`. */\n target: string;\n}\n\n/** The attribute `qtiTransformTest` puts on a section it merged from a `qti-assessment-section-ref`. */\nexport const SECTION_REF_ATTRIBUTE = 'data-qc-section-ref';\n\nexport interface SectionModel {\n kind: 'section';\n identifier: string;\n title: string;\n visible: boolean;\n sessionControl: SessionControl;\n /**\n * Merged from a `qti-assessment-section-ref`: branch rules outside it treat it as a leaf and\n * cannot target what is inside it (info model §7.5).\n */\n fromSectionRef: boolean;\n /** How many `qti-pre-condition`s it has; considered only in a linear part. */\n preConditions: number;\n /** Its `qti-branch-rule`s, in document order; considered only in a linear part. */\n branchRules: BranchRuleModel[];\n /** The section's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n /** The item-refs and sections directly inside this one, in document order, as the XML has them. */\n content: SectionContent[];\n}\n\nexport interface ItemRefModel {\n kind: 'itemRef';\n identifier: string;\n href: string;\n categories: string[];\n sessionControl: SessionControl;\n /** What this item-ref's own `qti-item-session-control` declares, nothing inherited. */\n declaredSessionControl: Partial<SessionControl>;\n /** How many `qti-pre-condition`s it has; considered only in a linear part. */\n preConditions: number;\n /** Its `qti-branch-rule`s, in document order; considered only in a linear part. */\n branchRules: BranchRuleModel[];\n /** The item-ref's own `qti-time-limits`; absent when it declares none. */\n timeLimits?: TimeLimits;\n}\n\nexport type SectionContent = SectionModel | ItemRefModel;\n\n/** `qti-item-session-control`, resolved for one level (QTI 3 info model §7.19). */\nexport interface SessionControl {\n /** 0 is unlimited. Ignored for adaptive items, which end by `completionStatus`. */\n maxAttempts: number;\n showFeedback: boolean;\n allowReview: boolean;\n showSolution: boolean;\n allowComment: boolean;\n /** Applies only in a test part with individual submission. */\n allowSkipping: boolean;\n /** Applies only in a test part with individual submission. */\n validateResponses: boolean;\n}\n\n/**\n * `qti-time-limits` as one level declares it (QTI 3 info model §7.40, §2.8.5). Never inherited: each\n * limit is on the time spent in its own level, the item-ref's on the item session's `duration`, a\n * section's, part's or test's on all the time spent in it, navigation included.\n */\nexport interface TimeLimits {\n /**\n * Seconds; null when not declared. On a section or item-ref it applies only in a linear part\n * (§2.8.5); `timeLimitRules` leaves it out elsewhere.\n */\n minTime: number | null;\n /** Seconds; null when not declared. */\n maxTime: number | null;\n /** Whether a response given after `maxTime` is still accepted. False when not declared (the XSD default). */\n allowLateSubmission: boolean;\n}\n\n/**\n * The values when no level declares an attribute: the XSD defaults, and 1 for `max-attempts`,\n * which the spec text gives (\"if it is unspecified it is treated as 1 for non-adaptive items\").\n */\nexport const DEFAULT_SESSION_CONTROL: Readonly<SessionControl> = Object.freeze({\n maxAttempts: 1,\n showFeedback: false,\n allowReview: true,\n showSolution: false,\n allowComment: false,\n allowSkipping: true,\n validateResponses: false\n});\n\n/**\n * Build the model of a test from its `qti-assessment-test` element: the XML document under Node, the\n * rendered element in the browser. Reads attributes and child elements only, so no element needs\n * to be registered.\n *\n * Session control inherits per attribute: each one comes from the closest level that declares it\n * (item-ref, then each enclosing section, then the test part), and its default only when none does.\n * The spec: a test-part setting applies \"unless the setting is overridden\", and the defaults \"are\n * used only in the absence of any applicable constraint\" (implementation guide §4.4.2).\n */\nexport function buildTestModel(test: XmlElement): TestModel {\n if (test.localName !== 'qti-assessment-test') {\n throw new TypeError(`Expected a qti-assessment-test element, not ${String(test.localName)}.`);\n }\n return {\n identifier: test.getAttribute('identifier') ?? '',\n title: test.getAttribute('title') ?? '',\n ...timeLimitsOf(test),\n testParts: childElements(test, 'qti-test-part').map(buildTestPart)\n };\n}\n\nfunction buildTestPart(part: XmlElement): TestPartModel {\n const sessionControl = resolveSessionControl(DEFAULT_SESSION_CONTROL, part);\n return {\n identifier: part.getAttribute('identifier') ?? '',\n navigationMode: part.getAttribute('navigation-mode') === 'linear' ? 'linear' : 'nonlinear',\n submissionMode: part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual',\n sessionControl,\n ...sequencingRules(part),\n ...timeLimitsOf(part),\n sections: childElements(part, 'qti-assessment-section').map(section => buildSection(section, sessionControl))\n };\n}\n\nfunction buildSection(section: XmlElement, inherited: SessionControl): SectionModel {\n const sessionControl = resolveSessionControl(inherited, section);\n return {\n kind: 'section',\n identifier: section.getAttribute('identifier') ?? '',\n title: section.getAttribute('title') ?? '',\n visible: booleanAttribute(section, 'visible') ?? true,\n sessionControl,\n fromSectionRef: section.getAttribute(SECTION_REF_ATTRIBUTE) !== null,\n ...sequencingRules(section),\n ...timeLimitsOf(section),\n content: childElements(section, 'qti-assessment-section', 'qti-assessment-item-ref').map(child =>\n child.localName === 'qti-assessment-section'\n ? buildSection(child, sessionControl)\n : buildItemRef(child, sessionControl)\n )\n };\n}\n\nfunction buildItemRef(itemRef: XmlElement, inherited: SessionControl): ItemRefModel {\n const category = itemRef.getAttribute('category')?.trim();\n return {\n kind: 'itemRef',\n identifier: itemRef.getAttribute('identifier') ?? '',\n href: itemRef.getAttribute('href') ?? '',\n categories: category ? category.split(/\\s+/) : [],\n sessionControl: resolveSessionControl(inherited, itemRef),\n declaredSessionControl: declaredSessionControl(itemRef),\n ...sequencingRules(itemRef),\n ...timeLimitsOf(itemRef)\n };\n}\n\n/** The `qti-pre-condition`s (counted) and `qti-branch-rule`s directly inside `owner`. */\nfunction sequencingRules(owner: XmlElement): { preConditions: number; branchRules: BranchRuleModel[] } {\n return {\n preConditions: childElements(owner, 'qti-pre-condition').length,\n branchRules: childElements(owner, 'qti-branch-rule').map(rule => ({ target: rule.getAttribute('target') ?? '' }))\n };\n}\n\n/** `inherited`, with what `owner`'s own `qti-item-session-control` declares on top. */\nfunction resolveSessionControl(inherited: Readonly<SessionControl>, owner: XmlElement): SessionControl {\n return { ...inherited, ...declaredSessionControl(owner) };\n}\n\n/** Only the attributes `owner`'s `qti-item-session-control` declares, so an absent one inherits. */\nfunction declaredSessionControl(owner: XmlElement): Partial<SessionControl> {\n const element = childElement(owner, 'qti-item-session-control');\n if (!element) return {};\n const declared: Partial<SessionControl> = {\n maxAttempts: integerAttribute(element, 'max-attempts'),\n showFeedback: booleanAttribute(element, 'show-feedback'),\n allowReview: booleanAttribute(element, 'allow-review'),\n showSolution: booleanAttribute(element, 'show-solution'),\n allowComment: booleanAttribute(element, 'allow-comment'),\n allowSkipping: booleanAttribute(element, 'allow-skipping'),\n validateResponses: booleanAttribute(element, 'validate-responses')\n };\n return Object.fromEntries(Object.entries(declared).filter(([, value]) => value !== undefined));\n}\n\n/**\n * `owner`'s own `qti-time-limits` as `{ timeLimits }`, or nothing when it declares none, so the\n * model holds the key only where the XML has the element. A value that is not a non-negative number\n * counts as not declared.\n */\nfunction timeLimitsOf(owner: XmlElement): { timeLimits?: TimeLimits } {\n const element = childElement(owner, 'qti-time-limits');\n if (!element) return {};\n return {\n timeLimits: {\n minTime: nonNegativeNumberAttribute(element, 'min-time') ?? null,\n maxTime: nonNegativeNumberAttribute(element, 'max-time') ?? null,\n allowLateSubmission: booleanAttribute(element, 'allow-late-submission') ?? false\n }\n };\n}\n\n/** The item-refs directly inside a section, in document order; not those of its subsections. */\nexport const ownItemRefs = (section: SectionModel): ItemRefModel[] =>\n section.content.filter((child): child is ItemRefModel => child.kind === 'itemRef');\n\n/** Every section, depth first in document order: a section before its subsections. */\nexport function sectionsInOrder(sections: SectionModel[]): SectionModel[] {\n return sections.flatMap(section => [\n section,\n ...sectionsInOrder(section.content.filter((child): child is SectionModel => child.kind === 'section'))\n ]);\n}\n\n/** Every item-ref inside the given sections, at any depth, in document order. */\nexport function itemRefsInOrder(sections: SectionContent[]): ItemRefModel[] {\n return sections.flatMap(child => (child.kind === 'itemRef' ? [child] : itemRefsInOrder(child.content)));\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { TestModel } from '../model/test-model.js';
|
|
2
|
+
import type { ItemInstanceId } from '../state/delivery-state.js';
|
|
3
|
+
/**
|
|
4
|
+
* Sequencing between items (QTI 3 implementation guide §4.5.3, info model §2.8.3): which item a
|
|
5
|
+
* test presents next, from the test model and the order of item instances, never the live DOM.
|
|
6
|
+
*
|
|
7
|
+
* The rules' expressions are QTI expressions, which this package does not evaluate (roadmap 3), so
|
|
8
|
+
* the caller answers each one through `evaluate`. The structure is decided here: which rules count
|
|
9
|
+
* (on items and sections only in a linear part, on test parts always), in what order, and where a
|
|
10
|
+
* target lands.
|
|
11
|
+
*/
|
|
12
|
+
export type SequencingLevel = 'testPart' | 'section' | 'itemRef';
|
|
13
|
+
/** One `qti-pre-condition` or `qti-branch-rule`, by its owner and its place among the owner's rules. */
|
|
14
|
+
export interface SequencingRule {
|
|
15
|
+
level: SequencingLevel;
|
|
16
|
+
/** The identifier of the test part, section or item-ref (instance id) that holds the rule. */
|
|
17
|
+
owner: string;
|
|
18
|
+
kind: 'preCondition' | 'branchRule';
|
|
19
|
+
/** Its index among the owner's rules of this kind, in document order. */
|
|
20
|
+
index: number;
|
|
21
|
+
}
|
|
22
|
+
/** Answers whether a rule's expression is true now. */
|
|
23
|
+
export type EvaluateRule = (rule: SequencingRule) => boolean;
|
|
24
|
+
/** A stable text key for a rule, `level:owner:kind:index`, as the test vectors write it. */
|
|
25
|
+
export declare const ruleKey: ({ level, owner, kind, index }: SequencingRule) => string;
|
|
26
|
+
export declare const EXIT_SECTION = "EXIT_SECTION";
|
|
27
|
+
export declare const EXIT_TESTPART = "EXIT_TESTPART";
|
|
28
|
+
export declare const EXIT_TEST = "EXIT_TEST";
|
|
29
|
+
export interface NextItem {
|
|
30
|
+
/** The item instance to present, or null when the test has no item left. */
|
|
31
|
+
id: ItemInstanceId | null;
|
|
32
|
+
/** The item instances passed over on the way, in order: not presented. */
|
|
33
|
+
skipped: ItemInstanceId[];
|
|
34
|
+
/** Branch targets ignored because selection or ordering left them nowhere ahead (§4.5.3: "not defined"). */
|
|
35
|
+
warnings: string[];
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The item to present after `current`: branch rules first (the item's, then those of each section
|
|
39
|
+
* it ends from the inside out, then the test part's when it ends the part), the first one that is
|
|
40
|
+
* true wins; then pre-conditions on the target and on, skipping forward until all pass (impl. guide
|
|
41
|
+
* §4.5.3 steps 2 and 3).
|
|
42
|
+
*
|
|
43
|
+
* @param model the test model, built from the test as rendered: after selection and ordering
|
|
44
|
+
* @param current the item instance that was just presented
|
|
45
|
+
*/
|
|
46
|
+
export declare function nextItem(model: TestModel, current: ItemInstanceId, evaluate: EvaluateRule): NextItem;
|
|
47
|
+
/** The first item to present: the first one whose test part, sections and own pre-conditions pass. */
|
|
48
|
+
export declare function firstItem(model: TestModel, evaluate: EvaluateRule): NextItem;
|
|
49
|
+
/** A branch target QTI forbids (info model §2.8.3.2, §7.5). */
|
|
50
|
+
export interface SequencingError {
|
|
51
|
+
level: SequencingLevel;
|
|
52
|
+
owner: string;
|
|
53
|
+
target: string;
|
|
54
|
+
reason: 'backward' | 'other-part' | 'not-a-part' | 'not-found' | 'inside-section-ref';
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The branch rules whose target QTI forbids, in the test as authored (before selection and
|
|
58
|
+
* ordering): an item or section target must be ahead in the same test part and not inside a
|
|
59
|
+
* section merged from a section-ref that the rule is outside of; a test part's target must be a
|
|
60
|
+
* later test part. Reserved targets are always allowed.
|
|
61
|
+
*/
|
|
62
|
+
export declare function sequencingErrors(model: TestModel): SequencingError[];
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { parseItemInstanceId } from '../state/delivery-state.js';
|
|
2
|
+
/** A stable text key for a rule, `level:owner:kind:index`, as the test vectors write it. */
|
|
3
|
+
export const ruleKey = ({ level, owner, kind, index }) => `${level}:${owner}:${kind}:${index}`;
|
|
4
|
+
export const EXIT_SECTION = 'EXIT_SECTION';
|
|
5
|
+
export const EXIT_TESTPART = 'EXIT_TESTPART';
|
|
6
|
+
export const EXIT_TEST = 'EXIT_TEST';
|
|
7
|
+
const RESERVED_TARGETS = new Set([EXIT_SECTION, EXIT_TESTPART, EXIT_TEST]);
|
|
8
|
+
/** Array.prototype.findLastIndex, which this package's ES2022 target lacks. */
|
|
9
|
+
function lastIndex(items, matches) {
|
|
10
|
+
for (let i = items.length - 1; i >= 0; i--)
|
|
11
|
+
if (matches(items[i]))
|
|
12
|
+
return i;
|
|
13
|
+
return -1;
|
|
14
|
+
}
|
|
15
|
+
function stepsOf(model) {
|
|
16
|
+
const steps = [];
|
|
17
|
+
const walk = (part, content, sections) => {
|
|
18
|
+
for (const child of content) {
|
|
19
|
+
if (child.kind === 'itemRef')
|
|
20
|
+
steps.push({ part, sections, itemRef: child });
|
|
21
|
+
else
|
|
22
|
+
walk(part, child.content, [...sections, child]);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
for (const part of model.testParts)
|
|
26
|
+
walk(part, part.sections, []);
|
|
27
|
+
return steps;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The item to present after `current`: branch rules first (the item's, then those of each section
|
|
31
|
+
* it ends from the inside out, then the test part's when it ends the part), the first one that is
|
|
32
|
+
* true wins; then pre-conditions on the target and on, skipping forward until all pass (impl. guide
|
|
33
|
+
* §4.5.3 steps 2 and 3).
|
|
34
|
+
*
|
|
35
|
+
* @param model the test model, built from the test as rendered: after selection and ordering
|
|
36
|
+
* @param current the item instance that was just presented
|
|
37
|
+
*/
|
|
38
|
+
export function nextItem(model, current, evaluate) {
|
|
39
|
+
const steps = stepsOf(model);
|
|
40
|
+
const index = steps.findIndex(step => step.itemRef.identifier === current);
|
|
41
|
+
if (index < 0)
|
|
42
|
+
throw new RangeError(`Item "${current}" is not in the test.`);
|
|
43
|
+
const from = steps[index];
|
|
44
|
+
const warnings = [];
|
|
45
|
+
let start = index + 1;
|
|
46
|
+
const fired = firingBranchRule(steps, index, evaluate);
|
|
47
|
+
if (fired) {
|
|
48
|
+
const target = branchTarget(steps, index, fired);
|
|
49
|
+
if (target === undefined) {
|
|
50
|
+
warnings.push(`qti-branch-rule target "${fired.rule.target}" of "${fired.owner}" is nowhere ahead in the test; ignored.`);
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
start = target;
|
|
54
|
+
}
|
|
55
|
+
const skipped = steps.slice(index + 1, start).map(step => step.itemRef.identifier);
|
|
56
|
+
return { ...presentable(steps, start, from, evaluate, skipped), warnings };
|
|
57
|
+
}
|
|
58
|
+
/** The first item to present: the first one whose test part, sections and own pre-conditions pass. */
|
|
59
|
+
export function firstItem(model, evaluate) {
|
|
60
|
+
return { ...presentable(stepsOf(model), 0, undefined, evaluate, []), warnings: [] };
|
|
61
|
+
}
|
|
62
|
+
function firingBranchRule(steps, index, evaluate) {
|
|
63
|
+
const from = steps[index];
|
|
64
|
+
const next = steps[index + 1];
|
|
65
|
+
const owners = [];
|
|
66
|
+
const rulesOf = new Map();
|
|
67
|
+
const add = (owner, rules) => {
|
|
68
|
+
owners.push(owner);
|
|
69
|
+
rulesOf.set(owner, rules);
|
|
70
|
+
};
|
|
71
|
+
if (from.part.navigationMode === 'linear') {
|
|
72
|
+
add({ level: 'itemRef', owner: from.itemRef.identifier }, from.itemRef.branchRules);
|
|
73
|
+
for (const section of [...from.sections].reverse()) {
|
|
74
|
+
if (next?.sections.includes(section))
|
|
75
|
+
break; // not its last item, nor of any section around it
|
|
76
|
+
add({ level: 'section', owner: section.identifier, section }, section.branchRules);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!next || next.part !== from.part)
|
|
80
|
+
add({ level: 'testPart', owner: from.part.identifier }, from.part.branchRules);
|
|
81
|
+
for (const owner of owners) {
|
|
82
|
+
const rules = rulesOf.get(owner);
|
|
83
|
+
for (let i = 0; i < rules.length; i++) {
|
|
84
|
+
if (evaluate({ level: owner.level, owner: owner.owner, kind: 'branchRule', index: i })) {
|
|
85
|
+
return { ...owner, rule: rules[i] };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
/** The index of the first step to consider after a branch, `steps.length` for the end, undefined when nowhere ahead. */
|
|
92
|
+
function branchTarget(steps, index, fired) {
|
|
93
|
+
const from = steps[index];
|
|
94
|
+
const after = (inside) => lastIndex(steps, inside) + 1;
|
|
95
|
+
const ahead = (matches) => {
|
|
96
|
+
const found = steps.findIndex((step, i) => i > index && matches(step));
|
|
97
|
+
return found < 0 ? undefined : found;
|
|
98
|
+
};
|
|
99
|
+
const target = fired.rule.target;
|
|
100
|
+
switch (target) {
|
|
101
|
+
case EXIT_TEST:
|
|
102
|
+
return steps.length;
|
|
103
|
+
case EXIT_TESTPART:
|
|
104
|
+
return after(step => step.part === from.part);
|
|
105
|
+
case EXIT_SECTION: {
|
|
106
|
+
const section = fired.level === 'section' ? fired.section : from.sections.at(-1);
|
|
107
|
+
return section ? after(step => step.sections.includes(section)) : undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (fired.level === 'testPart') {
|
|
111
|
+
return ahead(step => step.part !== from.part && step.part.identifier === target);
|
|
112
|
+
}
|
|
113
|
+
return ahead(step => step.part === from.part && targetableIn(step, from).includes(target));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* What a rule of `from`'s item or sections may target in `step`: the sections it has not entered,
|
|
117
|
+
* down to a section merged from a section-ref, which is a leaf (info model §7.5), and the item.
|
|
118
|
+
*/
|
|
119
|
+
function targetableIn(step, from) {
|
|
120
|
+
const ids = [];
|
|
121
|
+
for (const section of step.sections) {
|
|
122
|
+
if (from.sections.includes(section))
|
|
123
|
+
continue;
|
|
124
|
+
ids.push(section.identifier);
|
|
125
|
+
if (section.fromSectionRef)
|
|
126
|
+
return ids;
|
|
127
|
+
}
|
|
128
|
+
const { identifier } = step.itemRef;
|
|
129
|
+
return [...ids, identifier, parseItemInstanceId(identifier).itemRefIdentifier];
|
|
130
|
+
}
|
|
131
|
+
/** From `start` on, the first step whose entered levels' pre-conditions all pass. */
|
|
132
|
+
function presentable(steps, start, from, evaluate, skipped) {
|
|
133
|
+
const passed = new Map();
|
|
134
|
+
const passes = (level, owner) => {
|
|
135
|
+
if (!passed.has(owner)) {
|
|
136
|
+
let all = true;
|
|
137
|
+
for (let i = 0; all && i < owner.preConditions; i++) {
|
|
138
|
+
all = evaluate({ level, owner: owner.identifier, kind: 'preCondition', index: i });
|
|
139
|
+
}
|
|
140
|
+
passed.set(owner, all);
|
|
141
|
+
}
|
|
142
|
+
return passed.get(owner);
|
|
143
|
+
};
|
|
144
|
+
const skipTo = (from, to) => {
|
|
145
|
+
skipped.push(...steps.slice(from, to).map(step => step.itemRef.identifier));
|
|
146
|
+
return to;
|
|
147
|
+
};
|
|
148
|
+
let i = start;
|
|
149
|
+
while (i < steps.length) {
|
|
150
|
+
const step = steps[i];
|
|
151
|
+
if ((!from || step.part !== from.part) && !passes('testPart', step.part)) {
|
|
152
|
+
i = skipTo(i, lastIndex(steps, (s) => s.part === step.part) + 1);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (step.part.navigationMode === 'linear') {
|
|
156
|
+
const failed = step.sections.find(section => !from?.sections.includes(section) && !passes('section', section));
|
|
157
|
+
if (failed) {
|
|
158
|
+
i = skipTo(i, lastIndex(steps, (s) => s.sections.includes(failed)) + 1);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (!passes('itemRef', step.itemRef)) {
|
|
162
|
+
i = skipTo(i, i + 1);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { id: step.itemRef.identifier, skipped };
|
|
167
|
+
}
|
|
168
|
+
return { id: null, skipped };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The branch rules whose target QTI forbids, in the test as authored (before selection and
|
|
172
|
+
* ordering): an item or section target must be ahead in the same test part and not inside a
|
|
173
|
+
* section merged from a section-ref that the rule is outside of; a test part's target must be a
|
|
174
|
+
* later test part. Reserved targets are always allowed.
|
|
175
|
+
*/
|
|
176
|
+
export function sequencingErrors(model) {
|
|
177
|
+
const errors = [];
|
|
178
|
+
const nodesByPart = model.testParts.map(part => nodesOf(part.sections));
|
|
179
|
+
const anywhere = (target) => model.testParts.some(part => part.identifier === target) ||
|
|
180
|
+
nodesByPart.some(nodes => nodes.some(node => matches(node, target)));
|
|
181
|
+
model.testParts.forEach((part, partIndex) => {
|
|
182
|
+
for (const { target } of part.branchRules) {
|
|
183
|
+
if (RESERVED_TARGETS.has(target))
|
|
184
|
+
continue;
|
|
185
|
+
const targetIndex = model.testParts.findIndex(p => p.identifier === target);
|
|
186
|
+
if (targetIndex > partIndex)
|
|
187
|
+
continue;
|
|
188
|
+
const reason = targetIndex >= 0 ? 'backward' : anywhere(target) ? 'not-a-part' : 'not-found';
|
|
189
|
+
errors.push({ level: 'testPart', owner: part.identifier, target, reason });
|
|
190
|
+
}
|
|
191
|
+
const nodes = nodesByPart[partIndex];
|
|
192
|
+
for (const node of nodes) {
|
|
193
|
+
for (const { target } of node.model.branchRules) {
|
|
194
|
+
if (RESERVED_TARGETS.has(target))
|
|
195
|
+
continue;
|
|
196
|
+
const error = (reason) => errors.push({ level: node.level, owner: node.model.identifier, target, reason });
|
|
197
|
+
const found = nodes.find(other => matches(other, target));
|
|
198
|
+
if (!found)
|
|
199
|
+
error(anywhere(target) ? 'other-part' : 'not-found');
|
|
200
|
+
else if (found.start <= node.end)
|
|
201
|
+
error('backward');
|
|
202
|
+
else if (found.ancestors.some(section => section.fromSectionRef && section !== node.model && !node.ancestors.includes(section))) {
|
|
203
|
+
error('inside-section-ref');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
return errors;
|
|
209
|
+
}
|
|
210
|
+
const matches = (node, target) => node.model.identifier === target ||
|
|
211
|
+
(node.level === 'itemRef' && parseItemInstanceId(node.model.identifier).itemRefIdentifier === target);
|
|
212
|
+
function nodesOf(content) {
|
|
213
|
+
const nodes = [];
|
|
214
|
+
const walk = (children, ancestors) => {
|
|
215
|
+
for (const child of children) {
|
|
216
|
+
const node = { level: child.kind, model: child, start: nodes.length, end: nodes.length, ancestors };
|
|
217
|
+
nodes.push(node);
|
|
218
|
+
if (child.kind === 'section')
|
|
219
|
+
walk(child.content, [...ancestors, child]);
|
|
220
|
+
node.end = nodes.length - 1;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
walk(content, []);
|
|
224
|
+
return nodes;
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=sequencing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequencing.js","sourceRoot":"","sources":["../../src/sequencing/sequencing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAqCjE,4FAA4F;AAC5F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAkB,EAAU,EAAE,CAAC,GAAG,KAAK,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC;AAEvH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAC3C,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAC7C,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC;AACrC,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,CAAC,YAAY,EAAE,aAAa,EAAE,SAAS,CAAC,CAAC,CAAC;AAW3E,+EAA+E;AAC/E,SAAS,SAAS,CAAI,KAAU,EAAE,OAA6B;IAC7D,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;QAAE,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YAAE,OAAO,CAAC,CAAC;IAC5E,OAAO,CAAC,CAAC,CAAC;AACZ,CAAC;AAUD,SAAS,OAAO,CAAC,KAAgB;IAC/B,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,MAAM,IAAI,GAAG,CAAC,IAAmB,EAAE,OAAyB,EAAE,QAAwB,EAAE,EAAE;QACxF,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CA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AE,CAAC;YAC1G,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;gBAAE,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,GAAG,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;YACzE,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC,CAAC;IACF,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC;AACf,CAAC","sourcesContent":["import { parseItemInstanceId } from '../state/delivery-state.js';\n\nimport type {\n BranchRuleModel,\n ItemRefModel,\n SectionContent,\n SectionModel,\n TestModel,\n TestPartModel\n} from '../model/test-model.js';\nimport type { ItemInstanceId } from '../state/delivery-state.js';\n\n/**\n * Sequencing between items (QTI 3 implementation guide §4.5.3, info model §2.8.3): which item a\n * test presents next, from the test model and the order of item instances, never the live DOM.\n *\n * The rules' expressions are QTI expressions, which this package does not evaluate (roadmap 3), so\n * the caller answers each one through `evaluate`. The structure is decided here: which rules count\n * (on items and sections only in a linear part, on test parts always), in what order, and where a\n * target lands.\n */\n\nexport type SequencingLevel = 'testPart' | 'section' | 'itemRef';\n\n/** One `qti-pre-condition` or `qti-branch-rule`, by its owner and its place among the owner's rules. */\nexport interface SequencingRule {\n level: SequencingLevel;\n /** The identifier of the test part, section or item-ref (instance id) that holds the rule. */\n owner: string;\n kind: 'preCondition' | 'branchRule';\n /** Its index among the owner's rules of this kind, in document order. */\n index: number;\n}\n\n/** Answers whether a rule's expression is true now. */\nexport type EvaluateRule = (rule: SequencingRule) => boolean;\n\n/** A stable text key for a rule, `level:owner:kind:index`, as the test vectors write it. */\nexport const ruleKey = ({ level, owner, kind, index }: SequencingRule): string => `${level}:${owner}:${kind}:${index}`;\n\nexport const EXIT_SECTION = 'EXIT_SECTION';\nexport const EXIT_TESTPART = 'EXIT_TESTPART';\nexport const EXIT_TEST = 'EXIT_TEST';\nconst RESERVED_TARGETS = new Set([EXIT_SECTION, EXIT_TESTPART, EXIT_TEST]);\n\nexport interface NextItem {\n /** The item instance to present, or null when the test has no item left. */\n id: ItemInstanceId | null;\n /** The item instances passed over on the way, in order: not presented. */\n skipped: ItemInstanceId[];\n /** Branch targets ignored because selection or ordering left them nowhere ahead (§4.5.3: \"not defined\"). */\n warnings: string[];\n}\n\n/** Array.prototype.findLastIndex, which this package's ES2022 target lacks. */\nfunction lastIndex<T>(items: T[], matches: (item: T) => boolean): number {\n for (let i = items.length - 1; i >= 0; i--) if (matches(items[i])) return i;\n return -1;\n}\n\n/** One item instance in the order of the test, with the part and the sections around it. */\ninterface Step {\n part: TestPartModel;\n /** Outermost first. */\n sections: SectionModel[];\n itemRef: ItemRefModel;\n}\n\nfunction stepsOf(model: TestModel): Step[] {\n const steps: Step[] = [];\n const walk = (part: TestPartModel, content: SectionContent[], sections: SectionModel[]) => {\n for (const child of content) {\n if (child.kind === 'itemRef') steps.push({ part, sections, itemRef: child });\n else walk(part, child.content, [...sections, child]);\n }\n };\n for (const part of model.testParts) walk(part, part.sections, []);\n return steps;\n}\n\n/**\n * The item to present after `current`: branch rules first (the item's, then those of each section\n * it ends from the inside out, then the test part's when it ends the part), the first one that is\n * true wins; then pre-conditions on the target and on, skipping forward until all pass (impl. guide\n * §4.5.3 steps 2 and 3).\n *\n * @param model the test model, built from the test as rendered: after selection and ordering\n * @param current the item instance that was just presented\n */\nexport function nextItem(model: TestModel, current: ItemInstanceId, evaluate: EvaluateRule): NextItem {\n const steps = stepsOf(model);\n const index = steps.findIndex(step => step.itemRef.identifier === current);\n if (index < 0) throw new RangeError(`Item \"${current}\" is not in the test.`);\n\n const from = steps[index];\n const warnings: string[] = [];\n let start = index + 1;\n const fired = firingBranchRule(steps, index, evaluate);\n if (fired) {\n const target = branchTarget(steps, index, fired);\n if (target === undefined) {\n warnings.push(\n `qti-branch-rule target \"${fired.rule.target}\" of \"${fired.owner}\" is nowhere ahead in the test; ignored.`\n );\n } else start = target;\n }\n const skipped = steps.slice(index + 1, start).map(step => step.itemRef.identifier);\n return { ...presentable(steps, start, from, evaluate, skipped), warnings };\n}\n\n/** The first item to present: the first one whose test part, sections and own pre-conditions pass. */\nexport function firstItem(model: TestModel, evaluate: EvaluateRule): NextItem {\n return { ...presentable(stepsOf(model), 0, undefined, evaluate, []), warnings: [] };\n}\n\ninterface FiredRule {\n level: SequencingLevel;\n owner: string;\n rule: BranchRuleModel;\n section?: SectionModel;\n}\n\nfunction firingBranchRule(steps: Step[], index: number, evaluate: EvaluateRule): FiredRule | null {\n const from = steps[index];\n const next = steps[index + 1];\n const owners: Omit<FiredRule, 'rule'>[] = [];\n const rulesOf = new Map<Omit<FiredRule, 'rule'>, BranchRuleModel[]>();\n const add = (owner: Omit<FiredRule, 'rule'>, rules: BranchRuleModel[]) => {\n owners.push(owner);\n rulesOf.set(owner, rules);\n };\n\n if (from.part.navigationMode === 'linear') {\n add({ level: 'itemRef', owner: from.itemRef.identifier }, from.itemRef.branchRules);\n for (const section of [...from.sections].reverse()) {\n if (next?.sections.includes(section)) break; // not its last item, nor of any section around it\n add({ level: 'section', owner: section.identifier, section }, section.branchRules);\n }\n }\n if (!next || next.part !== from.part) add({ level: 'testPart', owner: from.part.identifier }, from.part.branchRules);\n\n for (const owner of owners) {\n const rules = rulesOf.get(owner)!;\n for (let i = 0; i < rules.length; i++) {\n if (evaluate({ level: owner.level, owner: owner.owner, kind: 'branchRule', index: i })) {\n return { ...owner, rule: rules[i] };\n }\n }\n }\n return null;\n}\n\n/** The index of the first step to consider after a branch, `steps.length` for the end, undefined when nowhere ahead. */\nfunction branchTarget(steps: Step[], index: number, fired: FiredRule): number | undefined {\n const from = steps[index];\n const after = (inside: (step: Step) => boolean) => lastIndex(steps, inside) + 1;\n const ahead = (matches: (step: Step) => boolean) => {\n const found = steps.findIndex((step, i) => i > index && matches(step));\n return found < 0 ? undefined : found;\n };\n const target = fired.rule.target;\n\n switch (target) {\n case EXIT_TEST:\n return steps.length;\n case EXIT_TESTPART:\n return after(step => step.part === from.part);\n case EXIT_SECTION: {\n const section = fired.level === 'section' ? fired.section : from.sections.at(-1);\n return section ? after(step => step.sections.includes(section)) : undefined;\n }\n }\n if (fired.level === 'testPart') {\n return ahead(step => step.part !== from.part && step.part.identifier === target);\n }\n return ahead(step => step.part === from.part && targetableIn(step, from).includes(target));\n}\n\n/**\n * What a rule of `from`'s item or sections may target in `step`: the sections it has not entered,\n * down to a section merged from a section-ref, which is a leaf (info model §7.5), and the item.\n */\nfunction targetableIn(step: Step, from: Step): string[] {\n const ids: string[] = [];\n for (const section of step.sections) {\n if (from.sections.includes(section)) continue;\n ids.push(section.identifier);\n if (section.fromSectionRef) return ids;\n }\n const { identifier } = step.itemRef;\n return [...ids, identifier, parseItemInstanceId(identifier).itemRefIdentifier];\n}\n\n/** From `start` on, the first step whose entered levels' pre-conditions all pass. */\nfunction presentable(\n steps: Step[],\n start: number,\n from: Step | undefined,\n evaluate: EvaluateRule,\n skipped: ItemInstanceId[]\n): Omit<NextItem, 'warnings'> {\n const passed = new Map<object, boolean>();\n const passes = (level: SequencingLevel, owner: TestPartModel | SectionModel | ItemRefModel) => {\n if (!passed.has(owner)) {\n let all = true;\n for (let i = 0; all && i < owner.preConditions; i++) {\n all = evaluate({ level, owner: owner.identifier, kind: 'preCondition', index: i });\n }\n passed.set(owner, all);\n }\n return passed.get(owner)!;\n };\n const skipTo = (from: number, to: number) => {\n skipped.push(...steps.slice(from, to).map(step => step.itemRef.identifier));\n return to;\n };\n\n let i = start;\n while (i < steps.length) {\n const step = steps[i];\n if ((!from || step.part !== from.part) && !passes('testPart', step.part)) {\n i = skipTo(i, lastIndex(steps, (s: Step) => s.part === step.part) + 1);\n continue;\n }\n if (step.part.navigationMode === 'linear') {\n const failed = step.sections.find(section => !from?.sections.includes(section) && !passes('section', section));\n if (failed) {\n i = skipTo(i, lastIndex(steps, (s: Step) => s.sections.includes(failed)) + 1);\n continue;\n }\n if (!passes('itemRef', step.itemRef)) {\n i = skipTo(i, i + 1);\n continue;\n }\n }\n return { id: step.itemRef.identifier, skipped };\n }\n return { id: null, skipped };\n}\n\n/** A branch target QTI forbids (info model §2.8.3.2, §7.5). */\nexport interface SequencingError {\n level: SequencingLevel;\n owner: string;\n target: string;\n reason: 'backward' | 'other-part' | 'not-a-part' | 'not-found' | 'inside-section-ref';\n}\n\ninterface Node {\n level: 'section' | 'itemRef';\n model: SectionModel | ItemRefModel;\n /** Pre-order position in its test part, and that of its last descendant. */\n start: number;\n end: number;\n ancestors: SectionModel[];\n}\n\n/**\n * The branch rules whose target QTI forbids, in the test as authored (before selection and\n * ordering): an item or section target must be ahead in the same test part and not inside a\n * section merged from a section-ref that the rule is outside of; a test part's target must be a\n * later test part. Reserved targets are always allowed.\n */\nexport function sequencingErrors(model: TestModel): SequencingError[] {\n const errors: SequencingError[] = [];\n const nodesByPart = model.testParts.map(part => nodesOf(part.sections));\n const anywhere = (target: string) =>\n model.testParts.some(part => part.identifier === target) ||\n nodesByPart.some(nodes => nodes.some(node => matches(node, target)));\n\n model.testParts.forEach((part, partIndex) => {\n for (const { target } of part.branchRules) {\n if (RESERVED_TARGETS.has(target)) continue;\n const targetIndex = model.testParts.findIndex(p => p.identifier === target);\n if (targetIndex > partIndex) continue;\n const reason = targetIndex >= 0 ? 'backward' : anywhere(target) ? 'not-a-part' : 'not-found';\n errors.push({ level: 'testPart', owner: part.identifier, target, reason });\n }\n\n const nodes = nodesByPart[partIndex];\n for (const node of nodes) {\n for (const { target } of node.model.branchRules) {\n if (RESERVED_TARGETS.has(target)) continue;\n const error = (reason: SequencingError['reason']) =>\n errors.push({ level: node.level, owner: node.model.identifier, target, reason });\n const found = nodes.find(other => matches(other, target));\n if (!found) error(anywhere(target) ? 'other-part' : 'not-found');\n else if (found.start <= node.end) error('backward');\n else if (\n found.ancestors.some(\n section => section.fromSectionRef && section !== node.model && !node.ancestors.includes(section)\n )\n ) {\n error('inside-section-ref');\n }\n }\n }\n });\n return errors;\n}\n\nconst matches = (node: Node, target: string) =>\n node.model.identifier === target ||\n (node.level === 'itemRef' && parseItemInstanceId(node.model.identifier).itemRefIdentifier === target);\n\nfunction nodesOf(content: SectionContent[]): Node[] {\n const nodes: Node[] = [];\n const walk = (children: SectionContent[], ancestors: SectionModel[]) => {\n for (const child of children) {\n const node: Node = { level: child.kind, model: child, start: nodes.length, end: nodes.length, ancestors };\n nodes.push(node);\n if (child.kind === 'section') walk(child.content, [...ancestors, child]);\n node.end = nodes.length - 1;\n }\n };\n walk(content, []);\n return nodes;\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.12",
|
|
5
5
|
"author": "",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"qti",
|