@qti-components/delivery 0.1.0-next.0 → 0.1.0-next.2
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/model/item-facts.d.ts +34 -0
- package/dist/model/item-facts.js +37 -0
- package/dist/model/item-facts.js.map +1 -0
- package/dist/state/create-delivery-state.d.ts +10 -2
- package/dist/state/create-delivery-state.js +24 -4
- package/dist/state/create-delivery-state.js.map +1 -1
- package/dist/state/delivery-state.d.ts +15 -2
- package/dist/state/delivery-state.js +28 -3
- package/dist/state/delivery-state.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
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;AAEtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './random/seeded-random.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kCAAkC,CAAC;AACjD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iBAAiB,CAAC","sourcesContent":["export * from './model/test-model.js';\nexport * from './model/item-facts.js';\nexport type { XmlElement, XmlNode } from './model/xml-node.js';\nexport * from './random/seeded-random.js';\nexport * from './random/shuffle.js';\nexport * from './state/clock.js';\nexport * from './state/commands.js';\nexport * from './state/create-delivery-state.js';\nexport * from './state/delivery-state.js';\nexport * from './processing.js';\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { XmlElement } from './xml-node.js';
|
|
2
|
+
/**
|
|
3
|
+
* What a `qti-assessment-item` says about itself, read from its XML when it is fetched: no live
|
|
4
|
+
* state, nothing that needs the item rendered. Plain JSON, so a server can read the same file.
|
|
5
|
+
*
|
|
6
|
+
* Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.
|
|
7
|
+
*/
|
|
8
|
+
export interface ItemFacts {
|
|
9
|
+
/** The item's own `identifier`, which may differ from the item-ref's. */
|
|
10
|
+
identifier: string;
|
|
11
|
+
/** `adaptive`; false when absent (XSD default). */
|
|
12
|
+
adaptive: boolean;
|
|
13
|
+
/** `time-dependent`; false when absent. */
|
|
14
|
+
timeDependent: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* A response declaration has a correct response, or a mapping with a map entry, or an area
|
|
17
|
+
* mapping with an area-map entry: something to compare a response with.
|
|
18
|
+
*/
|
|
19
|
+
hasCorrectResponse: boolean;
|
|
20
|
+
/** The item has `qti-response-processing`. */
|
|
21
|
+
hasResponseProcessing: boolean;
|
|
22
|
+
/** `external-scored` on the `SCORE` outcome declaration, or null when not externally scored. */
|
|
23
|
+
externalScored: 'human' | 'externalMachine' | null;
|
|
24
|
+
/** `label`, or null when absent. */
|
|
25
|
+
label: string | null;
|
|
26
|
+
/** `title`; empty when absent. */
|
|
27
|
+
title: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Read the facts of an item from its `qti-assessment-item` element: the XML document under Node,
|
|
31
|
+
* the fetched document in the browser. Reads attributes and child elements only, so no element
|
|
32
|
+
* needs to be registered.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readItemFacts(item: XmlElement): ItemFacts;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { booleanAttribute, childElement, childElements } from './xml-node.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read the facts of an item from its `qti-assessment-item` element: the XML document under Node,
|
|
4
|
+
* the fetched document in the browser. Reads attributes and child elements only, so no element
|
|
5
|
+
* needs to be registered.
|
|
6
|
+
*/
|
|
7
|
+
export function readItemFacts(item) {
|
|
8
|
+
if (item.localName !== 'qti-assessment-item') {
|
|
9
|
+
throw new TypeError(`Expected a qti-assessment-item element, not ${String(item.localName)}.`);
|
|
10
|
+
}
|
|
11
|
+
const responseDeclarations = childElements(item, 'qti-response-declaration');
|
|
12
|
+
const score = childElements(item, 'qti-outcome-declaration').find(declaration => declaration.getAttribute('identifier') === 'SCORE');
|
|
13
|
+
return {
|
|
14
|
+
identifier: item.getAttribute('identifier') ?? '',
|
|
15
|
+
adaptive: booleanAttribute(item, 'adaptive') ?? false,
|
|
16
|
+
timeDependent: booleanAttribute(item, 'time-dependent') ?? false,
|
|
17
|
+
hasCorrectResponse: responseDeclarations.some(hasSomethingToCompareWith),
|
|
18
|
+
hasResponseProcessing: childElement(item, 'qti-response-processing') !== null,
|
|
19
|
+
externalScored: externalScored(score),
|
|
20
|
+
label: item.getAttribute('label'),
|
|
21
|
+
title: item.getAttribute('title') ?? ''
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function hasSomethingToCompareWith(declaration) {
|
|
25
|
+
if (childElement(declaration, 'qti-correct-response'))
|
|
26
|
+
return true;
|
|
27
|
+
const mapping = childElement(declaration, 'qti-mapping');
|
|
28
|
+
if (mapping && childElement(mapping, 'qti-map-entry'))
|
|
29
|
+
return true;
|
|
30
|
+
const areaMapping = childElement(declaration, 'qti-area-mapping');
|
|
31
|
+
return areaMapping !== null && childElement(areaMapping, 'qti-area-map-entry') !== null;
|
|
32
|
+
}
|
|
33
|
+
function externalScored(declaration) {
|
|
34
|
+
const value = declaration?.getAttribute('external-scored')?.trim();
|
|
35
|
+
return value === 'human' || value === 'externalMachine' ? value : null;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=item-facts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-facts.js","sourceRoot":"","sources":["../../src/model/item-facts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAgC9E;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAgB;IAC5C,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,MAAM,oBAAoB,GAAG,aAAa,CAAC,IAAI,EAAE,0BAA0B,CAAC,CAAC;IAC7E,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC,IAAI,CAC/D,WAAW,CAAC,EAAE,CAAC,WAAW,CAAC,YAAY,CAAC,YAAY,CAAC,KAAK,OAAO,CAClE,CAAC;IACF,OAAO;QACL,UAAU,EAAE,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,EAAE;QACjD,QAAQ,EAAE,gBAAgB,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,KAAK;QACrD,aAAa,EAAE,gBAAgB,CAAC,IAAI,EAAE,gBAAgB,CAAC,IAAI,KAAK;QAChE,kBAAkB,EAAE,oBAAoB,CAAC,IAAI,CAAC,yBAAyB,CAAC;QACxE,qBAAqB,EAAE,YAAY,CAAC,IAAI,EAAE,yBAAyB,CAAC,KAAK,IAAI;QAC7E,cAAc,EAAE,cAAc,CAAC,KAAK,CAAC;QACrC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC;QACjC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,EAAE;KACxC,CAAC;AACJ,CAAC;AAED,SAAS,yBAAyB,CAAC,WAAuB;IACxD,IAAI,YAAY,CAAC,WAAW,EAAE,sBAAsB,CAAC;QAAE,OAAO,IAAI,CAAC;IACnE,MAAM,OAAO,GAAG,YAAY,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;IACzD,IAAI,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC;QAAE,OAAO,IAAI,CAAC;IACnE,MAAM,WAAW,GAAG,YAAY,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC;IAClE,OAAO,WAAW,KAAK,IAAI,IAAI,YAAY,CAAC,WAAW,EAAE,oBAAoB,CAAC,KAAK,IAAI,CAAC;AAC1F,CAAC;AAED,SAAS,cAAc,CAAC,WAAmC;IACzD,MAAM,KAAK,GAAG,WAAW,EAAE,YAAY,CAAC,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC;IACnE,OAAO,KAAK,KAAK,OAAO,IAAI,KAAK,KAAK,iBAAiB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;AACzE,CAAC","sourcesContent":["import { booleanAttribute, childElement, childElements } from './xml-node.js';\n\nimport type { XmlElement } from './xml-node.js';\n\n/**\n * What a `qti-assessment-item` says about itself, read from its XML when it is fetched: no live\n * state, nothing that needs the item rendered. Plain JSON, so a server can read the same file.\n *\n * Experimental (0.x): roadmap 1 phase T1; see `plans/test-model.md`.\n */\nexport interface ItemFacts {\n /** The item's own `identifier`, which may differ from the item-ref's. */\n identifier: string;\n /** `adaptive`; false when absent (XSD default). */\n adaptive: boolean;\n /** `time-dependent`; false when absent. */\n timeDependent: boolean;\n /**\n * A response declaration has a correct response, or a mapping with a map entry, or an area\n * mapping with an area-map entry: something to compare a response with.\n */\n hasCorrectResponse: boolean;\n /** The item has `qti-response-processing`. */\n hasResponseProcessing: boolean;\n /** `external-scored` on the `SCORE` outcome declaration, or null when not externally scored. */\n externalScored: 'human' | 'externalMachine' | null;\n /** `label`, or null when absent. */\n label: string | null;\n /** `title`; empty when absent. */\n title: string;\n}\n\n/**\n * Read the facts of an item from its `qti-assessment-item` element: the XML document under Node,\n * the fetched document in the browser. Reads attributes and child elements only, so no element\n * needs to be registered.\n */\nexport function readItemFacts(item: XmlElement): ItemFacts {\n if (item.localName !== 'qti-assessment-item') {\n throw new TypeError(`Expected a qti-assessment-item element, not ${String(item.localName)}.`);\n }\n const responseDeclarations = childElements(item, 'qti-response-declaration');\n const score = childElements(item, 'qti-outcome-declaration').find(\n declaration => declaration.getAttribute('identifier') === 'SCORE'\n );\n return {\n identifier: item.getAttribute('identifier') ?? '',\n adaptive: booleanAttribute(item, 'adaptive') ?? false,\n timeDependent: booleanAttribute(item, 'time-dependent') ?? false,\n hasCorrectResponse: responseDeclarations.some(hasSomethingToCompareWith),\n hasResponseProcessing: childElement(item, 'qti-response-processing') !== null,\n externalScored: externalScored(score),\n label: item.getAttribute('label'),\n title: item.getAttribute('title') ?? ''\n };\n}\n\nfunction hasSomethingToCompareWith(declaration: XmlElement): boolean {\n if (childElement(declaration, 'qti-correct-response')) return true;\n const mapping = childElement(declaration, 'qti-mapping');\n if (mapping && childElement(mapping, 'qti-map-entry')) return true;\n const areaMapping = childElement(declaration, 'qti-area-mapping');\n return areaMapping !== null && childElement(areaMapping, 'qti-area-map-entry') !== null;\n}\n\nfunction externalScored(declaration: XmlElement | undefined): ItemFacts['externalScored'] {\n const value = declaration?.getAttribute('external-scored')?.trim();\n return value === 'human' || value === 'externalMachine' ? value : null;\n}\n"]}
|
|
@@ -3,6 +3,14 @@ import type { DeliveryState } from './delivery-state.js';
|
|
|
3
3
|
export interface CreateDeliveryStateOptions {
|
|
4
4
|
clock: Clock;
|
|
5
5
|
seed?: string | null;
|
|
6
|
+
/**
|
|
7
|
+
* The item-ref identifiers after selection and ordering, in the order the candidate meets them.
|
|
8
|
+
* An item-ref listed again is its next occurrence (`with-replacement`, roadmap 1 T4).
|
|
9
|
+
*/
|
|
10
|
+
order?: readonly string[];
|
|
6
11
|
}
|
|
7
|
-
/**
|
|
8
|
-
|
|
12
|
+
/**
|
|
13
|
+
* A fresh delivery state: the item instances in `order`, nothing on screen, no plugin entries,
|
|
14
|
+
* started now by the given clock.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createDeliveryState({ clock, seed, order }: CreateDeliveryStateOptions): DeliveryState;
|
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
import { DELIVERY_STATE_VERSION } from './delivery-state.js';
|
|
2
|
-
/**
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { DELIVERY_STATE_VERSION, itemInstanceId } from './delivery-state.js';
|
|
2
|
+
/**
|
|
3
|
+
* A fresh delivery state: the item instances in `order`, nothing on screen, no plugin entries,
|
|
4
|
+
* started now by the given clock.
|
|
5
|
+
*/
|
|
6
|
+
export function createDeliveryState({ clock, seed = null, order = [] }) {
|
|
7
|
+
const occurrences = new Map();
|
|
8
|
+
const items = {};
|
|
9
|
+
const instances = order.map(itemRefIdentifier => {
|
|
10
|
+
const occurrence = (occurrences.get(itemRefIdentifier) ?? 0) + 1;
|
|
11
|
+
occurrences.set(itemRefIdentifier, occurrence);
|
|
12
|
+
const id = itemInstanceId(itemRefIdentifier, occurrence);
|
|
13
|
+
items[id] = { itemRefIdentifier, occurrence };
|
|
14
|
+
return id;
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
version: DELIVERY_STATE_VERSION,
|
|
18
|
+
seed,
|
|
19
|
+
startedAt: clock.now(),
|
|
20
|
+
current: null,
|
|
21
|
+
order: instances,
|
|
22
|
+
plugins: {},
|
|
23
|
+
items
|
|
24
|
+
};
|
|
5
25
|
}
|
|
6
26
|
//# sourceMappingURL=create-delivery-state.js.map
|
|
@@ -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,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,MAAM,qBAAqB,CAAC;AAe7E;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,EAA8B;IAChG,MAAM,WAAW,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC9C,MAAM,KAAK,GAA8C,EAAE,CAAC;IAC5D,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;QAC9C,MAAM,UAAU,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;QACjE,WAAW,CAAC,GAAG,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QAC/C,MAAM,EAAE,GAAG,cAAc,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QACzD,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 } 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 item-ref identifiers after selection and ordering, in the order the candidate meets them.\n * An item-ref listed again is its next occurrence (`with-replacement`, roadmap 1 T4).\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 occurrences = new Map<string, number>();\n const items: Record<ItemInstanceId, ItemDeliveryState> = {};\n const instances = order.map(itemRefIdentifier => {\n const occurrence = (occurrences.get(itemRefIdentifier) ?? 0) + 1;\n occurrences.set(itemRefIdentifier, occurrence);\n const id = itemInstanceId(itemRefIdentifier, occurrence);\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"]}
|
|
@@ -31,12 +31,25 @@ export interface DeliveryState {
|
|
|
31
31
|
startedAt: number;
|
|
32
32
|
/** The item instance on screen, or null before the first navigation and after the end. */
|
|
33
33
|
current: ItemInstanceId | null;
|
|
34
|
+
/**
|
|
35
|
+
* Every item instance of the test after selection and ordering, in the order the candidate meets
|
|
36
|
+
* them; written once, when the test starts. Each one is a key of `items`.
|
|
37
|
+
*/
|
|
38
|
+
order: ItemInstanceId[];
|
|
39
|
+
/**
|
|
40
|
+
* What test plugins keep, by plugin name: JSON, stored and restored without being read (a
|
|
41
|
+
* plugin reads its own entry).
|
|
42
|
+
*/
|
|
43
|
+
plugins: Record<string, unknown>;
|
|
44
|
+
/** One entry per instance in `order`. */
|
|
34
45
|
items: Record<ItemInstanceId, ItemDeliveryState>;
|
|
35
46
|
}
|
|
36
47
|
/** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */
|
|
37
48
|
export declare const itemInstanceId: (itemRefIdentifier: string, occurrence?: number) => ItemInstanceId;
|
|
38
49
|
/**
|
|
39
|
-
* Read a stored state back. Throws on a state this release cannot read
|
|
40
|
-
*
|
|
50
|
+
* Read a stored state back. Throws on a state this release cannot read rather than guessing, so a
|
|
51
|
+
* host never resumes from something half understood: a `RangeError` for another version, a
|
|
52
|
+
* `TypeError` for anything that is not a version 1 state (a missing or mistyped field, an `order`
|
|
53
|
+
* or `current` that names an instance `items` does not have).
|
|
41
54
|
*/
|
|
42
55
|
export declare function parseDeliveryState(value: unknown): DeliveryState;
|
|
@@ -11,18 +11,43 @@
|
|
|
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
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
14
15
|
/**
|
|
15
|
-
* Read a stored state back. Throws on a state this release cannot read
|
|
16
|
-
*
|
|
16
|
+
* Read a stored state back. Throws on a state this release cannot read rather than guessing, so a
|
|
17
|
+
* host never resumes from something half understood: a `RangeError` for another version, a
|
|
18
|
+
* `TypeError` for anything that is not a version 1 state (a missing or mistyped field, an `order`
|
|
19
|
+
* or `current` that names an instance `items` does not have).
|
|
17
20
|
*/
|
|
18
21
|
export function parseDeliveryState(value) {
|
|
19
|
-
if (
|
|
22
|
+
if (!isRecord(value)) {
|
|
20
23
|
throw new TypeError('A delivery state is an object.');
|
|
21
24
|
}
|
|
22
25
|
const { version } = value;
|
|
23
26
|
if (version !== DELIVERY_STATE_VERSION) {
|
|
24
27
|
throw new RangeError(`Delivery state version ${String(version)} is not supported; expected ${DELIVERY_STATE_VERSION}.`);
|
|
25
28
|
}
|
|
29
|
+
const { seed, startedAt, current, order, plugins, items } = value;
|
|
30
|
+
const fail = (field, expected) => {
|
|
31
|
+
throw new TypeError(`A delivery state's ${field} must be ${expected}.`);
|
|
32
|
+
};
|
|
33
|
+
if (seed !== null && typeof seed !== 'string')
|
|
34
|
+
fail('seed', 'a string or null');
|
|
35
|
+
if (typeof startedAt !== 'number' || !Number.isFinite(startedAt))
|
|
36
|
+
fail('startedAt', 'a number');
|
|
37
|
+
if (!isRecord(items))
|
|
38
|
+
fail('items', 'an object');
|
|
39
|
+
for (const [id, item] of Object.entries(items)) {
|
|
40
|
+
if (!isRecord(item) || typeof item.itemRefIdentifier !== 'string' || !Number.isInteger(item.occurrence)) {
|
|
41
|
+
fail(`items["${id}"]`, 'an object with an itemRefIdentifier and an integer occurrence');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const known = (id) => typeof id === 'string' && Object.hasOwn(items, id);
|
|
45
|
+
if (!Array.isArray(order) || !order.every(known))
|
|
46
|
+
fail('order', 'an array of instance ids in items');
|
|
47
|
+
if (current !== null && !known(current))
|
|
48
|
+
fail('current', 'null or an instance id in items');
|
|
49
|
+
if (!isRecord(plugins))
|
|
50
|
+
fail('plugins', 'an object');
|
|
26
51
|
return value;
|
|
27
52
|
}
|
|
28
53
|
//# sourceMappingURL=delivery-state.js.map
|
|
@@ -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;
|
|
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,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAEvE;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC1B,IAAI,OAAO,KAAK,sBAAsB,EAAE,CAAC;QACvC,MAAM,IAAI,UAAU,CAClB,0BAA0B,MAAM,CAAC,OAAO,CAAC,+BAA+B,sBAAsB,GAAG,CAClG,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;IAClE,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,QAAgB,EAAS,EAAE;QACtD,MAAM,IAAI,SAAS,CAAC,sBAAsB,KAAK,YAAY,QAAQ,GAAG,CAAC,CAAC;IAC1E,CAAC,CAAC;IACF,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,IAAI,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;IAChF,IAAI,OAAO,SAAS,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAChG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IACjD,KAAK,MAAM,CAAC,EAAE,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\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.2",
|
|
5
5
|
"author": "",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"qti",
|