@qti-components/delivery 0.1.0-next.7 → 0.1.0-next.9

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.
@@ -52,11 +52,16 @@ export interface ItemRules {
52
52
  * `show-solution`. False in `solution` itself; whether the solution shows is the state.
53
53
  */
54
54
  readonly mayBeginSolution: boolean;
55
+ /**
56
+ * The candidate may set a comment on the item now: `allow-comment`, while `interacting`. The
57
+ * comment is not assessed; QTI leaves capturing it to the delivery (§7.19, `allow-comment`).
58
+ */
59
+ readonly mayComment: boolean;
55
60
  }
56
61
  /** What the rules of one item session are read from: its lifecycle input, its state and its responses. */
57
62
  export interface ItemRulesInput extends Omit<ItemLifecycleInput, 'sessionControl'> {
58
63
  /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */
59
- sessionControl: Omit<SessionControl, 'allowComment'>;
64
+ sessionControl: SessionControl;
60
65
  /** The item session's lifecycle state. */
61
66
  state: ItemLifecycleState;
62
67
  /**
@@ -18,7 +18,8 @@ export function itemRules(input) {
18
18
  sessionControl.showFeedback ||
19
19
  (state === 'review' && adaptive && sessionControl.allowReview),
20
20
  mayBeginReview: transition(state, 'beginReview', guards) !== null,
21
- mayBeginSolution: transition(state, 'beginSolution', guards) !== null
21
+ mayBeginSolution: transition(state, 'beginSolution', guards) !== null,
22
+ mayComment: sessionControl.allowComment && state === 'interacting'
22
23
  };
23
24
  }
24
25
  /** The navigation answers of a part. Pure. */
@@ -1 +1 @@
1
- {"version":3,"file":"item-rules.js","sourceRoot":"","sources":["../../src/lifecycle/item-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA0EtE,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,mBAAmB,CAAC,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SAAS,EAAE,MAAM,IAAI,KAAK,GAAG,KAAK,GAAG,CAAC,IAAI,CAAC,CAAC,WAAW,IAAI,OAAO,CAAC,SAAS,CAAC;QAC7E,aAAa,EAAE,MAAM,IAAI,KAAK,GAAG,CAAC,IAAI,cAAc,KAAK,WAAW;KACrE,CAAC;AACJ,CAAC","sourcesContent":["import { itemLifecycleGuards, transition } from './item-lifecycle.js';\n\nimport type { SessionControl, TestPartModel } from '../model/test-model.js';\nimport type { ItemLifecycleInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/**\n * What one item session may do now, answered from its lifecycle state, its session control and its\n * responses. Every reader of attempts, skipping, feedback, review or the solution asks here instead\n * of working the rule out itself (roadmap 1, T3b).\n *\n * The answers follow QTI 3 (`qti-item-session-control`, info model §7.19; implementation guide\n * §4.1 and §4.4.2) and nothing else: whether the last attempt was optimal decides none of them\n * (decided 2026-11-27, `plans/host-api.md`).\n *\n * Experimental (0.x).\n */\nexport interface ItemRules {\n /**\n * Another attempt is allowed: `max-attempts` not reached (0 is unlimited), or, for an adaptive\n * item, which ignores `max-attempts`, `completionStatus` not `completed`.\n */\n readonly attemptsLeft: boolean;\n /** No further attempt is allowed: the negation of `attemptsLeft`. */\n readonly attemptsUsed: boolean;\n /** The responses can change: only while `interacting`. In every other state they are fixed or not shown. */\n readonly interactive: boolean;\n /** The item session is over: `closed`, or in `review` or `solution`, which come back to `closed`. */\n readonly done: boolean;\n /**\n * The candidate may end the attempt now: the item is `interacting` in a part with individual\n * submission, and `maySubmit` holds.\n */\n readonly mayEndAttempt: boolean;\n /**\n * The responses may be submitted as they are: `allow-skipping=\"false\"` refuses an item with no\n * response, `validate-responses` an invalid one. Two separate rules, both for individual\n * submission only (§7.19).\n */\n readonly maySubmit: boolean;\n /** Submitting no response is allowed: `allow-skipping`, or a response given, or simultaneous submission. */\n readonly maySkip: boolean;\n /**\n * Feedback, modal and integrated, may show: always while attempts are left, after the last\n * attempt only with `show-feedback`. In `review`, an adaptive item with `allow-review` shows its\n * feedback whatever `show-feedback` says (§7.19, `allow-review`).\n */\n readonly mayShowFeedback: boolean;\n /**\n * The item session may enter `review` now: it is `closed`, with `allow-review`. False in `review`\n * itself; whether review shows is the state.\n */\n readonly mayBeginReview: boolean;\n /**\n * The item session may enter `solution`, which shows the correct responses: it is `closed`, with\n * `show-solution`. False in `solution` itself; whether the solution shows is the state.\n */\n readonly mayBeginSolution: boolean;\n}\n\n/** What the rules of one item session are read from: its lifecycle input, its state and its responses. */\nexport interface ItemRulesInput extends Omit<ItemLifecycleInput, 'sessionControl'> {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: Omit<SessionControl, 'allowComment'>;\n /** The item session's lifecycle state. */\n state: ItemLifecycleState;\n /**\n * The candidate gave no response: every response variable holds its default or NULL. False for an\n * item with no response variables, which \"by definition cannot be skipped\" (§7.19).\n */\n skipped: boolean;\n /** Every interaction's response satisfies its constraints (the item's `valid`). */\n valid: boolean;\n}\n\n/** The rules of one item session. Pure: the same input gives the same answers on every runtime. */\nexport function itemRules(input: ItemRulesInput): ItemRules {\n const { state, sessionControl, adaptive } = input;\n const guards = itemLifecycleGuards(input);\n const individual = guards.individualSubmission;\n const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;\n const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);\n return {\n attemptsLeft: guards.attemptsLeft,\n attemptsUsed: !guards.attemptsLeft,\n interactive: state === 'interacting',\n done: state === 'closed' || state === 'review' || state === 'solution',\n mayEndAttempt: maySubmit && transition(state, 'endAttempt', guards) !== null,\n maySubmit,\n maySkip,\n mayShowFeedback:\n guards.attemptsLeft ||\n sessionControl.showFeedback ||\n (state === 'review' && adaptive && sessionControl.allowReview),\n mayBeginReview: transition(state, 'beginReview', guards) !== null,\n mayBeginSolution: transition(state, 'beginSolution', guards) !== null\n };\n}\n\n/** Where the candidate is in a part, for its navigation answers. */\nexport interface NavigationRulesInput {\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /** The current item's position among the part's items in order, from 0; -1 when none is current. */\n index: number;\n /** The number of items in the part. */\n count: number;\n /** The rules of the current item. */\n current: Pick<ItemRules, 'maySubmit' | 'interactive'>;\n}\n\n/** Whether the candidate may move to the next or the previous item of a part. */\nexport interface NavigationRules {\n /**\n * There is a next item and, in a linear part with individual submission, the current item may be\n * left: Next ends an attempt that was not ended and closes the item (decided 2026-11-27), so its\n * responses must be ones the candidate may submit.\n */\n readonly mayGoNext: boolean;\n /** There is a previous item, in a nonlinear part: a linear part never goes back (§4.1). */\n readonly mayGoPrevious: boolean;\n}\n\n/** The navigation answers of a part. Pure. */\nexport function navigationRules({\n navigationMode,\n submissionMode,\n index,\n count,\n current\n}: NavigationRulesInput): NavigationRules {\n const onItem = index >= 0 && index < count;\n const endsAttempt = navigationMode === 'linear' && submissionMode === 'individual' && current.interactive;\n return {\n mayGoNext: onItem && index < count - 1 && (!endsAttempt || current.maySubmit),\n mayGoPrevious: onItem && index > 0 && navigationMode === 'nonlinear'\n };\n}\n"]}
1
+ {"version":3,"file":"item-rules.js","sourceRoot":"","sources":["../../src/lifecycle/item-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AA+EtE,mGAAmG;AACnG,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAClD,MAAM,MAAM,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,MAAM,CAAC,oBAAoB,CAAC;IAC/C,MAAM,OAAO,GAAG,CAAC,UAAU,IAAI,cAAc,CAAC,aAAa,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;IAC9E,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,cAAc,CAAC,iBAAiB,IAAI,KAAK,CA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esContent":["import { itemLifecycleGuards, transition } from './item-lifecycle.js';\n\nimport type { SessionControl, TestPartModel } from '../model/test-model.js';\nimport type { ItemLifecycleInput, ItemLifecycleState } from './item-lifecycle.js';\n\n/**\n * What one item session may do now, answered from its lifecycle state, its session control and its\n * responses. Every reader of attempts, skipping, feedback, review or the solution asks here instead\n * of working the rule out itself (roadmap 1, T3b).\n *\n * The answers follow QTI 3 (`qti-item-session-control`, info model §7.19; implementation guide\n * §4.1 and §4.4.2) and nothing else: whether the last attempt was optimal decides none of them\n * (decided 2026-11-27, `plans/host-api.md`).\n *\n * Experimental (0.x).\n */\nexport interface ItemRules {\n /**\n * Another attempt is allowed: `max-attempts` not reached (0 is unlimited), or, for an adaptive\n * item, which ignores `max-attempts`, `completionStatus` not `completed`.\n */\n readonly attemptsLeft: boolean;\n /** No further attempt is allowed: the negation of `attemptsLeft`. */\n readonly attemptsUsed: boolean;\n /** The responses can change: only while `interacting`. In every other state they are fixed or not shown. */\n readonly interactive: boolean;\n /** The item session is over: `closed`, or in `review` or `solution`, which come back to `closed`. */\n readonly done: boolean;\n /**\n * The candidate may end the attempt now: the item is `interacting` in a part with individual\n * submission, and `maySubmit` holds.\n */\n readonly mayEndAttempt: boolean;\n /**\n * The responses may be submitted as they are: `allow-skipping=\"false\"` refuses an item with no\n * response, `validate-responses` an invalid one. Two separate rules, both for individual\n * submission only (§7.19).\n */\n readonly maySubmit: boolean;\n /** Submitting no response is allowed: `allow-skipping`, or a response given, or simultaneous submission. */\n readonly maySkip: boolean;\n /**\n * Feedback, modal and integrated, may show: always while attempts are left, after the last\n * attempt only with `show-feedback`. In `review`, an adaptive item with `allow-review` shows its\n * feedback whatever `show-feedback` says (§7.19, `allow-review`).\n */\n readonly mayShowFeedback: boolean;\n /**\n * The item session may enter `review` now: it is `closed`, with `allow-review`. False in `review`\n * itself; whether review shows is the state.\n */\n readonly mayBeginReview: boolean;\n /**\n * The item session may enter `solution`, which shows the correct responses: it is `closed`, with\n * `show-solution`. False in `solution` itself; whether the solution shows is the state.\n */\n readonly mayBeginSolution: boolean;\n /**\n * The candidate may set a comment on the item now: `allow-comment`, while `interacting`. The\n * comment is not assessed; QTI leaves capturing it to the delivery (§7.19, `allow-comment`).\n */\n readonly mayComment: boolean;\n}\n\n/** What the rules of one item session are read from: its lifecycle input, its state and its responses. */\nexport interface ItemRulesInput extends Omit<ItemLifecycleInput, 'sessionControl'> {\n /** The item-ref's resolved session control (`ItemRefModel.sessionControl`). */\n sessionControl: SessionControl;\n /** The item session's lifecycle state. */\n state: ItemLifecycleState;\n /**\n * The candidate gave no response: every response variable holds its default or NULL. False for an\n * item with no response variables, which \"by definition cannot be skipped\" (§7.19).\n */\n skipped: boolean;\n /** Every interaction's response satisfies its constraints (the item's `valid`). */\n valid: boolean;\n}\n\n/** The rules of one item session. Pure: the same input gives the same answers on every runtime. */\nexport function itemRules(input: ItemRulesInput): ItemRules {\n const { state, sessionControl, adaptive } = input;\n const guards = itemLifecycleGuards(input);\n const individual = guards.individualSubmission;\n const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;\n const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);\n return {\n attemptsLeft: guards.attemptsLeft,\n attemptsUsed: !guards.attemptsLeft,\n interactive: state === 'interacting',\n done: state === 'closed' || state === 'review' || state === 'solution',\n mayEndAttempt: maySubmit && transition(state, 'endAttempt', guards) !== null,\n maySubmit,\n maySkip,\n mayShowFeedback:\n guards.attemptsLeft ||\n sessionControl.showFeedback ||\n (state === 'review' && adaptive && sessionControl.allowReview),\n mayBeginReview: transition(state, 'beginReview', guards) !== null,\n mayBeginSolution: transition(state, 'beginSolution', guards) !== null,\n mayComment: sessionControl.allowComment && state === 'interacting'\n };\n}\n\n/** Where the candidate is in a part, for its navigation answers. */\nexport interface NavigationRulesInput {\n navigationMode: TestPartModel['navigationMode'];\n submissionMode: TestPartModel['submissionMode'];\n /** The current item's position among the part's items in order, from 0; -1 when none is current. */\n index: number;\n /** The number of items in the part. */\n count: number;\n /** The rules of the current item. */\n current: Pick<ItemRules, 'maySubmit' | 'interactive'>;\n}\n\n/** Whether the candidate may move to the next or the previous item of a part. */\nexport interface NavigationRules {\n /**\n * There is a next item and, in a linear part with individual submission, the current item may be\n * left: Next ends an attempt that was not ended and closes the item (decided 2026-11-27), so its\n * responses must be ones the candidate may submit.\n */\n readonly mayGoNext: boolean;\n /** There is a previous item, in a nonlinear part: a linear part never goes back (§4.1). */\n readonly mayGoPrevious: boolean;\n}\n\n/** The navigation answers of a part. Pure. */\nexport function navigationRules({\n navigationMode,\n submissionMode,\n index,\n count,\n current\n}: NavigationRulesInput): NavigationRules {\n const onItem = index >= 0 && index < count;\n const endsAttempt = navigationMode === 'linear' && submissionMode === 'individual' && current.interactive;\n return {\n mayGoNext: onItem && index < count - 1 && (!endsAttempt || current.maySubmit),\n mayGoPrevious: onItem && index > 0 && navigationMode === 'nonlinear'\n };\n}\n"]}
@@ -12,7 +12,7 @@ export interface CreateDeliveryStateOptions {
12
12
  order?: readonly string[];
13
13
  }
14
14
  /**
15
- * A fresh delivery state: the item instances in `order`, nothing on screen, no plugin entries,
16
- * started now by the given clock.
15
+ * A fresh delivery state: the item instances in `order`, each `initial` with no attempts and
16
+ * `not_attempted`, nothing on screen, no plugin entries, started now by the given clock.
17
17
  */
18
18
  export declare function createDeliveryState({ clock, seed, order }: CreateDeliveryStateOptions): DeliveryState;
@@ -1,7 +1,7 @@
1
1
  import { DELIVERY_STATE_VERSION, itemInstanceId, parseItemInstanceId } from './delivery-state.js';
2
2
  /**
3
- * A fresh delivery state: the item instances in `order`, nothing on screen, no plugin entries,
4
- * started now by the given clock.
3
+ * A fresh delivery state: the item instances in `order`, each `initial` with no attempts and
4
+ * `not_attempted`, nothing on screen, no plugin entries, started now by the given clock.
5
5
  */
6
6
  export function createDeliveryState({ clock, seed = null, order = [] }) {
7
7
  const parsed = order.map(parseItemInstanceId);
@@ -17,7 +17,13 @@ export function createDeliveryState({ clock, seed = null, order = [] }) {
17
17
  else if (Object.hasOwn(items, id)) {
18
18
  throw new RangeError(`The order lists the item instance ${id} twice.`);
19
19
  }
20
- items[id] = { itemRefIdentifier, occurrence };
20
+ items[id] = {
21
+ itemRefIdentifier,
22
+ occurrence,
23
+ lifecycle: 'initial',
24
+ numAttempts: 0,
25
+ completionStatus: 'not_attempted'
26
+ };
21
27
  return id;
22
28
  });
23
29
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"create-delivery-state.js","sourceRoot":"","sources":["../../src/state/create-delivery-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAiBlG;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,EAA8B;IAChG,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC9C,qFAAqF;IACrF,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CACjG,CAAC;IACF,MAAM,KAAK,GAA8C,EAAE,CAAC;IAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,EAAE,UAAU,EAAE,EAAE,EAAE;QACjE,IAAI,EAAE,GAAG,cAAc,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QACvD,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,EAAE,GAAG,cAAc,CAAC,iBAAiB,EAAE,EAAE,UAAU,CAAC,CAAC;QACzG,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,UAAU,CAAC,qCAAqC,EAAE,SAAS,CAAC,CAAC;QACzE,CAAC;QACD,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE,sBAAsB;QAC/B,IAAI;QACJ,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE;QACtB,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,EAAE;QACX,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { DELIVERY_STATE_VERSION, itemInstanceId, parseItemInstanceId } from './delivery-state.js';\n\nimport type { Clock } from './clock.js';\nimport type { DeliveryState, ItemDeliveryState, ItemInstanceId } from './delivery-state.js';\n\nexport interface CreateDeliveryStateOptions {\n clock: Clock;\n seed?: string | null;\n /**\n * The items after selection and ordering, in the order the candidate meets them: the rendered\n * test's item-ref identifiers, where a `with-replacement` clone is its instance id (`item-3#2`,\n * roadmap 1 T4) and keeps that occurrence wherever ordering put it. An item-ref listed again\n * without a suffix is its next free occurrence.\n */\n order?: readonly string[];\n}\n\n/**\n * A fresh delivery state: the item instances in `order`, nothing on screen, no plugin entries,\n * started now by the given clock.\n */\nexport function createDeliveryState({ clock, seed = null, order = [] }: CreateDeliveryStateOptions): DeliveryState {\n const parsed = order.map(parseItemInstanceId);\n // Occurrences the order names itself, so a bare repeat never takes a clone's number.\n const taken = new Set(\n parsed.filter(p => p.occurrence > 1).map(p => itemInstanceId(p.itemRefIdentifier, p.occurrence))\n );\n const items: Record<ItemInstanceId, ItemDeliveryState> = {};\n const instances = parsed.map(({ itemRefIdentifier, occurrence }) => {\n let id = itemInstanceId(itemRefIdentifier, occurrence);\n if (occurrence === 1) {\n while (Object.hasOwn(items, id) || taken.has(id)) id = itemInstanceId(itemRefIdentifier, ++occurrence);\n } else if (Object.hasOwn(items, id)) {\n throw new RangeError(`The order lists the item instance ${id} twice.`);\n }\n items[id] = { itemRefIdentifier, occurrence };\n return id;\n });\n return {\n version: DELIVERY_STATE_VERSION,\n seed,\n startedAt: clock.now(),\n current: null,\n order: instances,\n plugins: {},\n items\n };\n}\n"]}
1
+ {"version":3,"file":"create-delivery-state.js","sourceRoot":"","sources":["../../src/state/create-delivery-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAiBlG;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,EAA8B;IAChG,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;IAC9C,qFAAqF;IACrF,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,CAAC,iBAAiB,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC,CACjG,CAAC;IACF,MAAM,KAAK,GAA8C,EAAE,CAAC;IAC5D,MAAM,SAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,iBAAiB,EAAE,UAAU,EAAE,EAAE,EAAE;QACjE,IAAI,EAAE,GAAG,cAAc,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;QACvD,IAAI,UAAU,KAAK,CAAC,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;gBAAE,EAAE,GAAG,cAAc,CAAC,iBAAiB,EAAE,EAAE,UAAU,CAAC,CAAC;QACzG,CAAC;aAAM,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC;YACpC,MAAM,IAAI,UAAU,CAAC,qCAAqC,EAAE,SAAS,CAAC,CAAC;QACzE,CAAC;QACD,KAAK,CAAC,EAAE,CAAC,GAAG;YACV,iBAAiB;YACjB,UAAU;YACV,SAAS,EAAE,SAAS;YACpB,WAAW,EAAE,CAAC;YACd,gBAAgB,EAAE,eAAe;SAClC,CAAC;QACF,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,OAAO;QACL,OAAO,EAAE,sBAAsB;QAC/B,IAAI;QACJ,SAAS,EAAE,KAAK,CAAC,GAAG,EAAE;QACtB,OAAO,EAAE,IAAI;QACb,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,EAAE;QACX,KAAK;KACN,CAAC;AACJ,CAAC","sourcesContent":["import { DELIVERY_STATE_VERSION, itemInstanceId, parseItemInstanceId } from './delivery-state.js';\n\nimport type { Clock } from './clock.js';\nimport type { DeliveryState, ItemDeliveryState, ItemInstanceId } from './delivery-state.js';\n\nexport interface CreateDeliveryStateOptions {\n clock: Clock;\n seed?: string | null;\n /**\n * The items after selection and ordering, in the order the candidate meets them: the rendered\n * test's item-ref identifiers, where a `with-replacement` clone is its instance id (`item-3#2`,\n * roadmap 1 T4) and keeps that occurrence wherever ordering put it. An item-ref listed again\n * without a suffix is its next free occurrence.\n */\n order?: readonly string[];\n}\n\n/**\n * A fresh delivery state: the item instances in `order`, each `initial` with no attempts and\n * `not_attempted`, nothing on screen, no plugin entries, started now by the given clock.\n */\nexport function createDeliveryState({ clock, seed = null, order = [] }: CreateDeliveryStateOptions): DeliveryState {\n const parsed = order.map(parseItemInstanceId);\n // Occurrences the order names itself, so a bare repeat never takes a clone's number.\n const taken = new Set(\n parsed.filter(p => p.occurrence > 1).map(p => itemInstanceId(p.itemRefIdentifier, p.occurrence))\n );\n const items: Record<ItemInstanceId, ItemDeliveryState> = {};\n const instances = parsed.map(({ itemRefIdentifier, occurrence }) => {\n let id = itemInstanceId(itemRefIdentifier, occurrence);\n if (occurrence === 1) {\n while (Object.hasOwn(items, id) || taken.has(id)) id = itemInstanceId(itemRefIdentifier, ++occurrence);\n } else if (Object.hasOwn(items, id)) {\n throw new RangeError(`The order lists the item instance ${id} twice.`);\n }\n items[id] = {\n itemRefIdentifier,\n occurrence,\n lifecycle: 'initial',\n numAttempts: 0,\n completionStatus: 'not_attempted'\n };\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"]}
@@ -1,14 +1,8 @@
1
- /**
2
- * The one source of truth for one candidate in one test: what a resumed test, or a server taking
3
- * over, needs to carry on. Written only through commands; every context is an input or a view
4
- * derived from it, and anything derivable (done, can*, scores) is never stored here. Plain JSON,
5
- * versioned, so a stored state can be read back by a later release (or a .NET port) and refused
6
- * when it cannot.
7
- *
8
- * Experimental (0.x): roadmap 1 fills in the target fields, phase by phase; see
9
- * `plans/delivery-state.md`.
10
- */
1
+ import type { ItemLifecycleState } from '../lifecycle/item-lifecycle.js';
11
2
  export declare const DELIVERY_STATE_VERSION = 1;
3
+ /** QTI's values of the built-in `completionStatus` outcome (info model §2.2.2). */
4
+ export declare const COMPLETION_STATUSES: readonly ["not_attempted", "unknown", "incomplete", "completed"];
5
+ export type CompletionStatus = (typeof COMPLETION_STATUSES)[number];
12
6
  /**
13
7
  * One item session. With `with-replacement` selection a single item-ref appears more than once,
14
8
  * so a session is keyed by its instance, never by the item-ref identifier alone.
@@ -19,6 +13,18 @@ export interface ItemDeliveryState {
19
13
  itemRefIdentifier: string;
20
14
  /** 1 for the first time the item-ref was selected, 2 for its first clone, and so on. */
21
15
  occurrence: number;
16
+ /**
17
+ * The item session's state in QTI's lifecycle (`ITEM_LIFECYCLE_STATES`, roadmap 1 T3d). What the
18
+ * session may do (`itemRules`: the can* answers) is derived from it, never stored.
19
+ */
20
+ lifecycle: ItemLifecycleState;
21
+ /**
22
+ * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this
23
+ * delivery counts it when it ends, as a version 1 `QtiTestState` stores it (`plans/item-lifecycle.md`).
24
+ */
25
+ numAttempts: number;
26
+ /** QTI's built-in `completionStatus`: `not_attempted` until the item is shown. */
27
+ completionStatus: CompletionStatus;
22
28
  }
23
29
  export interface DeliveryState {
24
30
  version: typeof DELIVERY_STATE_VERSION;
@@ -8,7 +8,10 @@
8
8
  * Experimental (0.x): roadmap 1 fills in the target fields, phase by phase; see
9
9
  * `plans/delivery-state.md`.
10
10
  */
11
+ import { ITEM_LIFECYCLE_STATES } from '../lifecycle/item-lifecycle.js';
11
12
  export const DELIVERY_STATE_VERSION = 1;
13
+ /** QTI's values of the built-in `completionStatus` outcome (info model §2.2.2). */
14
+ export const COMPLETION_STATUSES = ['not_attempted', 'unknown', 'incomplete', 'completed'];
12
15
  /** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */
13
16
  export const itemInstanceId = (itemRefIdentifier, occurrence = 1) => occurrence === 1 ? itemRefIdentifier : `${itemRefIdentifier}#${occurrence}`;
14
17
  /**
@@ -52,6 +55,16 @@ export function parseDeliveryState(value) {
52
55
  if (!isRecord(item) || typeof item.itemRefIdentifier !== 'string' || !Number.isInteger(item.occurrence)) {
53
56
  fail(`items["${id}"]`, 'an object with an itemRefIdentifier and an integer occurrence');
54
57
  }
58
+ const session = item;
59
+ if (!ITEM_LIFECYCLE_STATES.includes(session.lifecycle)) {
60
+ fail(`items["${id}"].lifecycle`, `one of ${ITEM_LIFECYCLE_STATES.join(', ')}`);
61
+ }
62
+ if (!Number.isInteger(session.numAttempts) || session.numAttempts < 0) {
63
+ fail(`items["${id}"].numAttempts`, 'a whole number, 0 or more');
64
+ }
65
+ if (!COMPLETION_STATUSES.includes(session.completionStatus)) {
66
+ fail(`items["${id}"].completionStatus`, `one of ${COMPLETION_STATUSES.join(', ')}`);
67
+ }
55
68
  }
56
69
  const known = (id) => typeof id === 'string' && Object.hasOwn(items, id);
57
70
  if (!Array.isArray(order) || !order.every(known))
@@ -1 +1 @@
1
- {"version":3,"file":"delivery-state.js","sourceRoot":"","sources":["../../src/state/delivery-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAwCxC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,iBAAyB,EAAE,UAAU,GAAG,CAAC,EAAkB,EAAE,CAC1F,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,IAAI,UAAU,EAAE,CAAC;AAE9E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAkB;IACpD,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAChD,OAAO,KAAK,IAAI,UAAU,IAAI,CAAC;QAC7B,CAAC,CAAC,EAAE,iBAAiB,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE;QAC7C,CAAC,CAAC,EAAE,iBAAiB,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,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;IA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+D,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;IACD,MAAM,KAAK,GAAG,CAAC,EAAW,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC;IAC5F,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;QAAE,IAAI,CAAC,OAAO,EAAE,mCAAmC,CAAC,CAAC;IACrG,IAAI,OAAO,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,IAAI,CAAC,SAAS,EAAE,iCAAiC,CAAC,CAAC;IAC5F,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IACrD,OAAO,KAAiC,CAAC;AAC3C,CAAC","sourcesContent":["/**\n * The one source of truth for one candidate in one test: what a resumed test, or a server taking\n * over, needs to carry on. Written only through commands; every context is an input or a view\n * derived from it, and anything derivable (done, can*, scores) is never stored here. Plain JSON,\n * versioned, so a stored state can be read back by a later release (or a .NET port) and refused\n * when it cannot.\n *\n * Experimental (0.x): roadmap 1 fills in the target fields, phase by phase; see\n * `plans/delivery-state.md`.\n */\nexport const DELIVERY_STATE_VERSION = 1;\n\n/**\n * One item session. With `with-replacement` selection a single item-ref appears more than once,\n * so a session is keyed by its instance, never by the item-ref identifier alone.\n */\nexport type ItemInstanceId = string;\n\nexport interface ItemDeliveryState {\n /** The `identifier` of the `qti-assessment-item-ref` this instance was selected from. */\n itemRefIdentifier: string;\n /** 1 for the first time the item-ref was selected, 2 for its first clone, and so on. */\n occurrence: number;\n}\n\nexport interface DeliveryState {\n version: typeof DELIVERY_STATE_VERSION;\n /**\n * The seed actually used for selection and ordering; the same seed gives the same test on every\n * runtime. On a first start it comes from the host (`qtiContext.seed`); on resume this one wins.\n */\n seed: string | null;\n /** When the test started, in milliseconds since the epoch, read from the injected clock. */\n startedAt: number;\n /** The item instance on screen, or null before the first navigation and after the end. */\n current: ItemInstanceId | null;\n /**\n * Every item instance of the test after selection and ordering, in the order the candidate meets\n * them; written once, when the test starts. Each one is a key of `items`.\n */\n order: ItemInstanceId[];\n /**\n * What test plugins keep, by plugin name: JSON, stored and restored without being read (a\n * plugin reads its own entry).\n */\n plugins: Record<string, unknown>;\n /** One entry per instance in `order`. */\n items: Record<ItemInstanceId, ItemDeliveryState>;\n}\n\n/** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */\nexport const itemInstanceId = (itemRefIdentifier: string, occurrence = 1): ItemInstanceId =>\n occurrence === 1 ? itemRefIdentifier : `${itemRefIdentifier}#${occurrence}`;\n\n/**\n * The item-ref and occurrence an instance id names, the inverse of `itemInstanceId`: `item-3#2` is\n * the second selection of `item-3`. Only a suffix `itemInstanceId` writes (`#2` and up) counts; `#`\n * cannot occur in a QTI identifier, so no authored identifier reads as a clone.\n */\nexport function parseItemInstanceId(id: ItemInstanceId): { itemRefIdentifier: string; occurrence: number } {\n const match = /^(.+)#([1-9]\\d*)$/.exec(id);\n const occurrence = match ? Number(match[2]) : 1;\n return match && occurrence >= 2\n ? { itemRefIdentifier: match[1], occurrence }\n : { itemRefIdentifier: id, occurrence: 1 };\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read a stored state back. Throws on a state this release cannot read rather than guessing, so a\n * host never resumes from something half understood: a `RangeError` for another version, a\n * `TypeError` for anything that is not a version 1 state (a missing or mistyped field, an `order`\n * or `current` that names an instance `items` does not have).\n */\nexport function parseDeliveryState(value: unknown): DeliveryState {\n if (!isRecord(value)) {\n throw new TypeError('A delivery state is an object.');\n }\n const { version } = value;\n if (version !== DELIVERY_STATE_VERSION) {\n throw new RangeError(\n `Delivery state version ${String(version)} is not supported; expected ${DELIVERY_STATE_VERSION}.`\n );\n }\n const { seed, startedAt, current, order, plugins, items } = value;\n const fail = (field: string, expected: string): never => {\n throw new TypeError(`A delivery state's ${field} must be ${expected}.`);\n };\n if (seed !== null && typeof seed !== 'string') fail('seed', 'a string or null');\n if (typeof startedAt !== 'number' || !Number.isFinite(startedAt)) fail('startedAt', 'a number');\n if (!isRecord(items)) fail('items', 'an object');\n for (const [id, item] of Object.entries(items as Record<string, unknown>)) {\n if (!isRecord(item) || typeof item.itemRefIdentifier !== 'string' || !Number.isInteger(item.occurrence)) {\n fail(`items[\"${id}\"]`, 'an object with an itemRefIdentifier and an integer occurrence');\n }\n }\n const known = (id: unknown) => typeof id === 'string' && Object.hasOwn(items as object, id);\n if (!Array.isArray(order) || !order.every(known)) fail('order', 'an array of instance ids in items');\n if (current !== null && !known(current)) fail('current', 'null or an instance id in items');\n if (!isRecord(plugins)) fail('plugins', 'an object');\n return value as unknown as DeliveryState;\n}\n"]}
1
+ {"version":3,"file":"delivery-state.js","sourceRoot":"","sources":["../../src/state/delivery-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAC;AAIvE,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,mFAAmF;AACnF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,eAAe,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,CAAU,CAAC;AAsDpG,4FAA4F;AAC5F,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,iBAAyB,EAAE,UAAU,GAAG,CAAC,EAAkB,EAAE,CAC1F,UAAU,KAAK,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,iBAAiB,IAAI,UAAU,EAAE,CAAC;AAE9E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAkB;IACpD,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,UAAU,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AC,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 */\nimport { ITEM_LIFECYCLE_STATES } from '../lifecycle/item-lifecycle.js';\n\nimport type { ItemLifecycleState } from '../lifecycle/item-lifecycle.js';\n\nexport const DELIVERY_STATE_VERSION = 1;\n\n/** QTI's values of the built-in `completionStatus` outcome (info model §2.2.2). */\nexport const COMPLETION_STATUSES = ['not_attempted', 'unknown', 'incomplete', 'completed'] as const;\n\nexport type CompletionStatus = (typeof COMPLETION_STATUSES)[number];\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 * The item session's state in QTI's lifecycle (`ITEM_LIFECYCLE_STATES`, roadmap 1 T3d). What the\n * session may do (`itemRules`: the can* answers) is derived from it, never stored.\n */\n lifecycle: ItemLifecycleState;\n /**\n * The attempts the candidate has ended. QTI's `numAttempts` counts an attempt as it begins; this\n * delivery counts it when it ends, as a version 1 `QtiTestState` stores it (`plans/item-lifecycle.md`).\n */\n numAttempts: number;\n /** QTI's built-in `completionStatus`: `not_attempted` until the item is shown. */\n completionStatus: CompletionStatus;\n}\n\nexport interface DeliveryState {\n version: typeof DELIVERY_STATE_VERSION;\n /**\n * The seed actually used for selection and ordering; the same seed gives the same test on every\n * runtime. On a first start it comes from the host (`qtiContext.seed`); on resume this one wins.\n */\n seed: string | null;\n /** When the test started, in milliseconds since the epoch, read from the injected clock. */\n startedAt: number;\n /** The item instance on screen, or null before the first navigation and after the end. */\n current: ItemInstanceId | null;\n /**\n * Every item instance of the test after selection and ordering, in the order the candidate meets\n * them; written once, when the test starts. Each one is a key of `items`.\n */\n order: ItemInstanceId[];\n /**\n * What test plugins keep, by plugin name: JSON, stored and restored without being read (a\n * plugin reads its own entry).\n */\n plugins: Record<string, unknown>;\n /** One entry per instance in `order`. */\n items: Record<ItemInstanceId, ItemDeliveryState>;\n}\n\n/** The instance id of the `occurrence`th selection of an item-ref: `item-3`, `item-3#2`. */\nexport const itemInstanceId = (itemRefIdentifier: string, occurrence = 1): ItemInstanceId =>\n occurrence === 1 ? itemRefIdentifier : `${itemRefIdentifier}#${occurrence}`;\n\n/**\n * The item-ref and occurrence an instance id names, the inverse of `itemInstanceId`: `item-3#2` is\n * the second selection of `item-3`. Only a suffix `itemInstanceId` writes (`#2` and up) counts; `#`\n * cannot occur in a QTI identifier, so no authored identifier reads as a clone.\n */\nexport function parseItemInstanceId(id: ItemInstanceId): { itemRefIdentifier: string; occurrence: number } {\n const match = /^(.+)#([1-9]\\d*)$/.exec(id);\n const occurrence = match ? Number(match[2]) : 1;\n return match && occurrence >= 2\n ? { itemRefIdentifier: match[1], occurrence }\n : { itemRefIdentifier: id, occurrence: 1 };\n}\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/**\n * Read a stored state back. Throws on a state this release cannot read rather than guessing, so a\n * host never resumes from something half understood: a `RangeError` for another version, a\n * `TypeError` for anything that is not a version 1 state (a missing or mistyped field, an `order`\n * or `current` that names an instance `items` does not have).\n */\nexport function parseDeliveryState(value: unknown): DeliveryState {\n if (!isRecord(value)) {\n throw new TypeError('A delivery state is an object.');\n }\n const { version } = value;\n if (version !== DELIVERY_STATE_VERSION) {\n throw new RangeError(\n `Delivery state version ${String(version)} is not supported; expected ${DELIVERY_STATE_VERSION}.`\n );\n }\n const { seed, startedAt, current, order, plugins, items } = value;\n const fail = (field: string, expected: string): never => {\n throw new TypeError(`A delivery state's ${field} must be ${expected}.`);\n };\n if (seed !== null && typeof seed !== 'string') fail('seed', 'a string or null');\n if (typeof startedAt !== 'number' || !Number.isFinite(startedAt)) fail('startedAt', 'a number');\n if (!isRecord(items)) fail('items', 'an object');\n for (const [id, item] of Object.entries(items as Record<string, unknown>)) {\n if (!isRecord(item) || typeof item.itemRefIdentifier !== 'string' || !Number.isInteger(item.occurrence)) {\n fail(`items[\"${id}\"]`, 'an object with an itemRefIdentifier and an integer occurrence');\n }\n const session = item as Record<string, unknown>;\n if (!(ITEM_LIFECYCLE_STATES as readonly unknown[]).includes(session.lifecycle)) {\n fail(`items[\"${id}\"].lifecycle`, `one of ${ITEM_LIFECYCLE_STATES.join(', ')}`);\n }\n if (!Number.isInteger(session.numAttempts) || (session.numAttempts as number) < 0) {\n fail(`items[\"${id}\"].numAttempts`, 'a whole number, 0 or more');\n }\n if (!(COMPLETION_STATUSES as readonly unknown[]).includes(session.completionStatus)) {\n fail(`items[\"${id}\"].completionStatus`, `one of ${COMPLETION_STATUSES.join(', ')}`);\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.7",
4
+ "version": "0.1.0-next.9",
5
5
  "author": "",
6
6
  "keywords": [
7
7
  "qti",