@pie-qti/assessment-player 1.0.0-beta.4 → 1.0.0-beta.6

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.
Files changed (134) hide show
  1. package/README.md +28 -7
  2. package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
  3. package/dist/components/createPlayerConnection.svelte.js +151 -0
  4. package/dist/components/createPlayerConnection.svelte.js.map +1 -0
  5. package/dist/components/displaySettings.svelte.d.ts +23 -0
  6. package/dist/components/displaySettings.svelte.js +40 -0
  7. package/dist/components/displaySettings.svelte.js.map +1 -0
  8. package/dist/components/srOnly.d.ts +29 -0
  9. package/dist/components/srOnly.js +55 -0
  10. package/dist/components/srOnly.js.map +1 -0
  11. package/dist/components/submitDialogAction.d.ts +25 -0
  12. package/dist/components/submitDialogAction.js +89 -0
  13. package/dist/components/submitDialogAction.js.map +1 -0
  14. package/dist/core/AssessmentPlayer.d.ts +1102 -53
  15. package/dist/core/AssessmentPlayer.js +2835 -460
  16. package/dist/core/AssessmentPlayer.js.map +1 -1
  17. package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
  18. package/dist/core/AssessmentSessionCoordinator.js +185 -10
  19. package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
  20. package/dist/core/AutosaveManager.d.ts +104 -0
  21. package/dist/core/AutosaveManager.js +181 -0
  22. package/dist/core/AutosaveManager.js.map +1 -0
  23. package/dist/core/ItemSessionController.d.ts +17 -26
  24. package/dist/core/ItemSessionController.js +33 -73
  25. package/dist/core/ItemSessionController.js.map +1 -1
  26. package/dist/core/NavigationManager.d.ts +18 -50
  27. package/dist/core/NavigationManager.js +21 -83
  28. package/dist/core/NavigationManager.js.map +1 -1
  29. package/dist/core/TimeManager.d.ts +62 -16
  30. package/dist/core/TimeManager.js +148 -57
  31. package/dist/core/TimeManager.js.map +1 -1
  32. package/dist/core/autosave.d.ts +44 -0
  33. package/dist/core/autosave.js +46 -0
  34. package/dist/core/autosave.js.map +1 -0
  35. package/dist/core/deliveryStructure.d.ts +54 -0
  36. package/dist/core/deliveryStructure.js +72 -0
  37. package/dist/core/deliveryStructure.js.map +1 -0
  38. package/dist/core/errors.d.ts +116 -0
  39. package/dist/core/errors.js +77 -0
  40. package/dist/core/errors.js.map +1 -0
  41. package/dist/core/exitBoundaries.d.ts +64 -0
  42. package/dist/core/exitBoundaries.js +98 -0
  43. package/dist/core/exitBoundaries.js.map +1 -0
  44. package/dist/core/feedback.d.ts +46 -0
  45. package/dist/core/feedback.js +47 -0
  46. package/dist/core/feedback.js.map +1 -0
  47. package/dist/core/formatTime.d.ts +8 -0
  48. package/dist/core/formatTime.js +20 -0
  49. package/dist/core/formatTime.js.map +1 -0
  50. package/dist/core/index.d.ts +7 -4
  51. package/dist/core/index.js +4 -1
  52. package/dist/core/index.js.map +1 -1
  53. package/dist/core/navigationPolicy.d.ts +42 -0
  54. package/dist/core/navigationPolicy.js +62 -0
  55. package/dist/core/navigationPolicy.js.map +1 -0
  56. package/dist/core/pause.d.ts +58 -0
  57. package/dist/core/pause.js +101 -0
  58. package/dist/core/pause.js.map +1 -0
  59. package/dist/core/playerEvents.d.ts +51 -0
  60. package/dist/core/playerEvents.js +66 -0
  61. package/dist/core/playerEvents.js.map +1 -0
  62. package/dist/core/reviewState.d.ts +81 -0
  63. package/dist/core/reviewState.js +113 -0
  64. package/dist/core/reviewState.js.map +1 -0
  65. package/dist/core/reviewViews.d.ts +43 -0
  66. package/dist/core/reviewViews.js +88 -0
  67. package/dist/core/reviewViews.js.map +1 -0
  68. package/dist/core/scopeLocks.d.ts +36 -0
  69. package/dist/core/scopeLocks.js +78 -0
  70. package/dist/core/scopeLocks.js.map +1 -0
  71. package/dist/core/sessionRecords.d.ts +31 -0
  72. package/dist/core/sessionRecords.js +74 -0
  73. package/dist/core/sessionRecords.js.map +1 -0
  74. package/dist/core/submissionPolicy.d.ts +62 -0
  75. package/dist/core/submissionPolicy.js +67 -0
  76. package/dist/core/submissionPolicy.js.map +1 -0
  77. package/dist/core/templateDefaults.d.ts +26 -0
  78. package/dist/core/templateDefaults.js +53 -0
  79. package/dist/core/templateDefaults.js.map +1 -0
  80. package/dist/core/testStructure.d.ts +118 -3
  81. package/dist/core/testStructure.js +252 -6
  82. package/dist/core/testStructure.js.map +1 -1
  83. package/dist/core/timePolicy.d.ts +40 -0
  84. package/dist/core/timePolicy.js +106 -0
  85. package/dist/core/timePolicy.js.map +1 -0
  86. package/dist/index.d.ts +7 -4
  87. package/dist/index.js +5 -1
  88. package/dist/index.js.map +1 -1
  89. package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
  90. package/dist/integration/ReferenceBackendAdapter.js +216 -1035
  91. package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
  92. package/dist/integration/api-contract.d.ts +179 -17
  93. package/dist/integration/api-contract.js.map +1 -1
  94. package/dist/integration/assessment-item-scorer.d.ts +56 -5
  95. package/dist/integration/assessment-item-scorer.js +116 -13
  96. package/dist/integration/assessment-item-scorer.js.map +1 -1
  97. package/dist/integration/index.d.ts +2 -2
  98. package/dist/integration/index.js +1 -1
  99. package/dist/integration/index.js.map +1 -1
  100. package/dist/integration/qti-test-parser.d.ts +44 -0
  101. package/dist/integration/qti-test-parser.js +529 -0
  102. package/dist/integration/qti-test-parser.js.map +1 -0
  103. package/dist/integration/session-store.d.ts +54 -0
  104. package/dist/integration/session-store.js +75 -0
  105. package/dist/integration/session-store.js.map +1 -0
  106. package/dist/integration/test-navigation.d.ts +23 -0
  107. package/dist/integration/test-navigation.js +32 -0
  108. package/dist/integration/test-navigation.js.map +1 -0
  109. package/dist/integration/toSectionComposition.js +8 -1
  110. package/dist/integration/toSectionComposition.js.map +1 -1
  111. package/dist/reporting/index.d.ts +3 -0
  112. package/dist/reporting/index.js +3 -0
  113. package/dist/reporting/index.js.map +1 -0
  114. package/dist/reporting/inferBaseType.d.ts +13 -0
  115. package/dist/reporting/inferBaseType.js +26 -0
  116. package/dist/reporting/inferBaseType.js.map +1 -0
  117. package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
  118. package/dist/reporting/serializeAssessmentResult.js +377 -0
  119. package/dist/reporting/serializeAssessmentResult.js.map +1 -0
  120. package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
  121. package/dist/reporting/toAssessmentResultXml.js +304 -0
  122. package/dist/reporting/toAssessmentResultXml.js.map +1 -0
  123. package/dist/reporting/types.d.ts +85 -0
  124. package/dist/reporting/types.js +8 -0
  125. package/dist/reporting/types.js.map +1 -0
  126. package/dist/types/index.d.ts +96 -9
  127. package/dist/types/index.js.map +1 -1
  128. package/package.json +21 -15
  129. package/dist/core/StatePersistenceManager.d.ts +0 -125
  130. package/dist/core/StatePersistenceManager.js +0 -268
  131. package/dist/core/StatePersistenceManager.js.map +0 -1
  132. package/dist/utils/PerformanceMonitor.d.ts +0 -114
  133. package/dist/utils/PerformanceMonitor.js +0 -172
  134. package/dist/utils/PerformanceMonitor.js.map +0 -1
@@ -0,0 +1,54 @@
1
+ /**
2
+ * localStorage session store for the reference backend adapter.
3
+ *
4
+ * Sessions store the full assessment (with QTI XML and correct answers) client-side —
5
+ * INSECURE by design; this is a reference implementation, not a production backend.
6
+ */
7
+ import type { AssessmentSessionState, OutcomeProcessingError, SecureAssessment, SessionId } from './api-contract.js';
8
+ import type { ItemTestState } from './assessment-item-scorer.js';
9
+ /**
10
+ * Stored session data (includes full QTI XML - INSECURE)
11
+ */
12
+ export interface StoredSession {
13
+ sessionId: SessionId;
14
+ assessmentId: string;
15
+ candidateId: string;
16
+ /** Full assessment structure with QTI XML */
17
+ assessment: SecureAssessment;
18
+ /** Current state */
19
+ state: AssessmentSessionState;
20
+ /** Created timestamp */
21
+ createdAt: number;
22
+ /** Finalized flag */
23
+ finalized: boolean;
24
+ /**
25
+ * Per-item variables and flags from each item's latest counted submission, read by
26
+ * test-level outcome processing. Absent until the session's first counted submission.
27
+ */
28
+ itemTestStates?: Record<string, ItemTestState>;
29
+ /**
30
+ * Set when test-level outcome processing failed: candidate responses stay persisted,
31
+ * but SCORE/testFeedback outcomes could not be computed and the error must surface
32
+ * to the host instead of failing silently.
33
+ */
34
+ outcomeProcessingError?: OutcomeProcessingError;
35
+ }
36
+ export declare function generateSessionId(assessmentId: string, candidateId: string): SessionId;
37
+ export declare function loadSession(sessionId: SessionId): StoredSession | null;
38
+ /**
39
+ * Persist one session. Returns true only when the write landed: callers propagate the
40
+ * failure honestly (a `saveState` that reports success while nothing was stored would
41
+ * silently lose the draft; a finalize that reports finalized while the flag never
42
+ * persisted would resurrect the test on resume). Best-effort callers (the init write,
43
+ * the outcome-processing-error bookkeeping) may ignore the result.
44
+ */
45
+ export declare function saveSession(session: StoredSession): boolean;
46
+ /**
47
+ * The most recent stored session for an assessment and candidate, or null. Unfinalized
48
+ * sessions only by default: a finalized test has nothing left to resume. This is the
49
+ * reference loader behind `ReferenceBackendAdapter.latestSessionId()`, which demos and
50
+ * tests use to resume a draft after a refresh.
51
+ */
52
+ export declare function findLatestSession(assessmentId: string, candidateId: string, options?: {
53
+ includeFinalized?: boolean;
54
+ }): StoredSession | null;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * localStorage session store for the reference backend adapter.
3
+ *
4
+ * Sessions store the full assessment (with QTI XML and correct answers) client-side —
5
+ * INSECURE by design; this is a reference implementation, not a production backend.
6
+ */
7
+ /**
8
+ * localStorage key prefix of every stored session, defined only here. Saved sessions are
9
+ * found and resumed by it, so the value must not change.
10
+ */
11
+ const STORAGE_PREFIX = 'qti_session_';
12
+ export function generateSessionId(assessmentId, candidateId) {
13
+ return `${assessmentId}:${candidateId}:${Date.now()}`;
14
+ }
15
+ export function loadSession(sessionId) {
16
+ try {
17
+ const key = STORAGE_PREFIX + sessionId;
18
+ const data = localStorage.getItem(key);
19
+ if (!data)
20
+ return null;
21
+ return JSON.parse(data);
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ }
27
+ /**
28
+ * Persist one session. Returns true only when the write landed: callers propagate the
29
+ * failure honestly (a `saveState` that reports success while nothing was stored would
30
+ * silently lose the draft; a finalize that reports finalized while the flag never
31
+ * persisted would resurrect the test on resume). Best-effort callers (the init write,
32
+ * the outcome-processing-error bookkeeping) may ignore the result.
33
+ */
34
+ export function saveSession(session) {
35
+ try {
36
+ const key = STORAGE_PREFIX + session.sessionId;
37
+ localStorage.setItem(key, JSON.stringify(session));
38
+ return true;
39
+ }
40
+ catch (error) {
41
+ // Quota exceeded and friends: the failure is the caller's to surface.
42
+ console.error('Failed to save session to localStorage:', error);
43
+ return false;
44
+ }
45
+ }
46
+ /**
47
+ * The most recent stored session for an assessment and candidate, or null. Unfinalized
48
+ * sessions only by default: a finalized test has nothing left to resume. This is the
49
+ * reference loader behind `ReferenceBackendAdapter.latestSessionId()`, which demos and
50
+ * tests use to resume a draft after a refresh.
51
+ */
52
+ export function findLatestSession(assessmentId, candidateId, options = {}) {
53
+ let latest = null;
54
+ try {
55
+ for (let index = 0; index < localStorage.length; index++) {
56
+ const key = localStorage.key(index);
57
+ if (!key?.startsWith(STORAGE_PREFIX))
58
+ continue;
59
+ const session = loadSession(key.slice(STORAGE_PREFIX.length));
60
+ if (!session)
61
+ continue;
62
+ if (session.assessmentId !== assessmentId || session.candidateId !== candidateId)
63
+ continue;
64
+ if (session.finalized && !options.includeFinalized)
65
+ continue;
66
+ if (!latest || session.createdAt > latest.createdAt)
67
+ latest = session;
68
+ }
69
+ }
70
+ catch {
71
+ return null;
72
+ }
73
+ return latest;
74
+ }
75
+ //# sourceMappingURL=session-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-store.js","sourceRoot":"","sources":["../../src/integration/session-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;;GAGG;AACH,MAAM,cAAc,GAAG,cAAc,CAAC;AA8BtC,MAAM,UAAU,iBAAiB,CAAC,YAAoB,EAAE,WAAmB;IAC1E,OAAO,GAAG,YAAY,IAAI,WAAW,IAAI,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;AACvD,CAAC;AAED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;YAC9D,IAAI,CAAC,OAAO;gBAAE,SAAS;YACvB,IAAI,OAAO,CAAC,YAAY,KAAK,YAAY,IAAI,OAAO,CAAC,WAAW,KAAK,WAAW;gBAAE,SAAS;YAC3F,IAAI,OAAO,CAAC,SAAS,IAAI,CAAC,OAAO,CAAC,gBAAgB;gBAAE,SAAS;YAC7D,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS;gBAAE,MAAM,GAAG,OAAO,CAAC;QACvE,CAAC;IACF,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/**\n * localStorage session store for the reference backend adapter.\n *\n * Sessions store the full assessment (with QTI XML and correct answers) client-side —\n * INSECURE by design; this is a reference implementation, not a production backend.\n */\n\nimport type {\n\tAssessmentSessionState,\n\tOutcomeProcessingError,\n\tSecureAssessment,\n\tSessionId,\n} from './api-contract.js';\nimport type { ItemTestState } from './assessment-item-scorer.js';\n\n/**\n * localStorage key prefix of every stored session, defined only here. Saved sessions are\n * found and resumed by it, so the value must not change.\n */\nconst STORAGE_PREFIX = 'qti_session_';\n\n/**\n * Stored session data (includes full QTI XML - INSECURE)\n */\nexport interface StoredSession {\n\tsessionId: SessionId;\n\tassessmentId: string;\n\tcandidateId: string;\n\t/** Full assessment structure with QTI XML */\n\tassessment: SecureAssessment;\n\t/** Current state */\n\tstate: AssessmentSessionState;\n\t/** Created timestamp */\n\tcreatedAt: number;\n\t/** Finalized flag */\n\tfinalized: boolean;\n\t/**\n\t * Per-item variables and flags from each item's latest counted submission, read by\n\t * test-level outcome processing. Absent until the session's first counted submission.\n\t */\n\titemTestStates?: Record<string, ItemTestState>;\n\t/**\n\t * Set when test-level outcome processing failed: candidate responses stay persisted,\n\t * but SCORE/testFeedback outcomes could not be computed and the error must surface\n\t * to the host instead of failing silently.\n\t */\n\toutcomeProcessingError?: OutcomeProcessingError;\n}\n\nexport function generateSessionId(assessmentId: string, candidateId: string): SessionId {\n\treturn `${assessmentId}:${candidateId}:${Date.now()}`;\n}\n\nexport function loadSession(sessionId: SessionId): StoredSession | null {\n\ttry {\n\t\tconst key = STORAGE_PREFIX + sessionId;\n\t\tconst data = localStorage.getItem(key);\n\t\tif (!data) return null;\n\t\treturn JSON.parse(data) as StoredSession;\n\t} catch {\n\t\treturn null;\n\t}\n}\n\n/**\n * Persist one session. Returns true only when the write landed: callers propagate the\n * failure honestly (a `saveState` that reports success while nothing was stored would\n * silently lose the draft; a finalize that reports finalized while the flag never\n * persisted would resurrect the test on resume). Best-effort callers (the init write,\n * the outcome-processing-error bookkeeping) may ignore the result.\n */\nexport function saveSession(session: StoredSession): boolean {\n\ttry {\n\t\tconst key = STORAGE_PREFIX + session.sessionId;\n\t\tlocalStorage.setItem(key, JSON.stringify(session));\n\t\treturn true;\n\t} catch (error) {\n\t\t// Quota exceeded and friends: the failure is the caller's to surface.\n\t\tconsole.error('Failed to save session to localStorage:', error);\n\t\treturn false;\n\t}\n}\n\n/**\n * The most recent stored session for an assessment and candidate, or null. Unfinalized\n * sessions only by default: a finalized test has nothing left to resume. This is the\n * reference loader behind `ReferenceBackendAdapter.latestSessionId()`, which demos and\n * tests use to resume a draft after a refresh.\n */\nexport function findLatestSession(\n\tassessmentId: string,\n\tcandidateId: string,\n\toptions: { includeFinalized?: boolean } = {},\n): StoredSession | null {\n\tlet latest: StoredSession | null = null;\n\ttry {\n\t\tfor (let index = 0; index < localStorage.length; index++) {\n\t\t\tconst key = localStorage.key(index);\n\t\t\tif (!key?.startsWith(STORAGE_PREFIX)) continue;\n\t\t\tconst session = loadSession(key.slice(STORAGE_PREFIX.length));\n\t\t\tif (!session) continue;\n\t\t\tif (session.assessmentId !== assessmentId || session.candidateId !== candidateId) continue;\n\t\t\tif (session.finalized && !options.includeFinalized) continue;\n\t\t\tif (!latest || session.createdAt > latest.createdAt) latest = session;\n\t\t}\n\t} catch {\n\t\treturn null;\n\t}\n\treturn latest;\n}\n"]}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Test-level navigation: the session-fed declarations the branch rules and preconditions
3
+ * read, and the delivered item refs in order.
4
+ *
5
+ * The pure delivery-rules walk itself (branch rules, preconditions, eligibility) is shared
6
+ * with the player through `core/testStructure.ts` and re-exported here — the reference
7
+ * backend and the client evaluate the same rules; this module is the backend's entry. The
8
+ * adapter threads its RNG so conditional evaluation stays deterministic per session.
9
+ */
10
+ import type { DeclarationMap, QtiValue } from '@pie-qti/qti-processing';
11
+ import type { SecureAssessment, SecureItemRef, TestOutcomeValues } from './api-contract.js';
12
+ import type { StoredSession } from './session-store.js';
13
+ export { firstEligibleItem, nextItemIdentifier } from '../core/testStructure.js';
14
+ /**
15
+ * Context for branch rules and preconditions: test outcomes, every submitted item's variables as
16
+ * `itemIdentifier.VARIABLE`, and `current` unprefixed where the test declares no such outcome.
17
+ */
18
+ export declare function navigationDeclarations(session: StoredSession, outcomes: TestOutcomeValues | undefined, current?: Record<string, QtiValue>): DeclarationMap;
19
+ /** Delivered item refs in order, each with the identifiers of the sections containing it (outermost first). */
20
+ export declare function getItemRefsInOrder(assessment: SecureAssessment): Array<{
21
+ item: SecureItemRef;
22
+ sectionIdentifiers: string[];
23
+ }>;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Test-level navigation: the session-fed declarations the branch rules and preconditions
3
+ * read, and the delivered item refs in order.
4
+ *
5
+ * The pure delivery-rules walk itself (branch rules, preconditions, eligibility) is shared
6
+ * with the player through `core/testStructure.ts` and re-exported here — the reference
7
+ * backend and the client evaluate the same rules; this module is the backend's entry. The
8
+ * adapter threads its RNG so conditional evaluation stays deterministic per session.
9
+ */
10
+ import { addItemVariableDeclarations, applyVariableMappings, deliveredItems, testOutcomeDeclarations, } from '../core/testStructure.js';
11
+ export { firstEligibleItem, nextItemIdentifier } from '../core/testStructure.js';
12
+ /**
13
+ * Context for branch rules and preconditions: test outcomes, every submitted item's variables as
14
+ * `itemIdentifier.VARIABLE`, and `current` unprefixed where the test declares no such outcome.
15
+ */
16
+ export function navigationDeclarations(session, outcomes, current = {}) {
17
+ const itemVariables = {};
18
+ for (const { item } of deliveredItems(session.assessment)) {
19
+ const variables = session.itemTestStates?.[item.identifier]?.variables;
20
+ if (variables)
21
+ itemVariables[item.identifier] = applyVariableMappings(variables, item.variableMappings);
22
+ }
23
+ return addItemVariableDeclarations(testOutcomeDeclarations(session.assessment, outcomes), itemVariables, current);
24
+ }
25
+ /** Delivered item refs in order, each with the identifiers of the sections containing it (outermost first). */
26
+ export function getItemRefsInOrder(assessment) {
27
+ return deliveredItems(assessment).map(({ item, sections }) => ({
28
+ item,
29
+ sectionIdentifiers: sections.map((section) => section.identifier),
30
+ }));
31
+ }
32
+ //# sourceMappingURL=test-navigation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-navigation.js","sourceRoot":"","sources":["../../src/integration/test-navigation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACN,2BAA2B,EAC3B,qBAAqB,EACrB,cAAc,EACd,uBAAuB,GACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEjF;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACrC,OAAsB,EACtB,QAAuC,EACvC,UAAoC,EAAE;IAEtC,MAAM,aAAa,GAA6C,EAAE,CAAC;IACnE,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC3D,MAAM,SAAS,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC;QACvE,IAAI,SAAS;YAAE,aAAa,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,qBAAqB,CAAC,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACzG,CAAC;IACD,OAAO,2BAA2B,CAAC,uBAAuB,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AACnH,CAAC;AAED,+GAA+G;AAC/G,MAAM,UAAU,kBAAkB,CACjC,UAA4B;IAE5B,OAAO,cAAc,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9D,IAAI;QACJ,kBAAkB,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC;KACjE,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Test-level navigation: the session-fed declarations the branch rules and preconditions\n * read, and the delivered item refs in order.\n *\n * The pure delivery-rules walk itself (branch rules, preconditions, eligibility) is shared\n * with the player through `core/testStructure.ts` and re-exported here — the reference\n * backend and the client evaluate the same rules; this module is the backend's entry. The\n * adapter threads its RNG so conditional evaluation stays deterministic per session.\n */\n\nimport type { DeclarationMap, QtiValue } from '@pie-qti/qti-processing';\nimport type { SecureAssessment, SecureItemRef, TestOutcomeValues } from './api-contract.js';\nimport {\n\taddItemVariableDeclarations,\n\tapplyVariableMappings,\n\tdeliveredItems,\n\ttestOutcomeDeclarations,\n} from '../core/testStructure.js';\nimport type { StoredSession } from './session-store.js';\n\nexport { firstEligibleItem, nextItemIdentifier } from '../core/testStructure.js';\n\n/**\n * Context for branch rules and preconditions: test outcomes, every submitted item's variables as\n * `itemIdentifier.VARIABLE`, and `current` unprefixed where the test declares no such outcome.\n */\nexport function navigationDeclarations(\n\tsession: StoredSession,\n\toutcomes: TestOutcomeValues | undefined,\n\tcurrent: Record<string, QtiValue> = {},\n): DeclarationMap {\n\tconst itemVariables: Record<string, Record<string, QtiValue>> = {};\n\tfor (const { item } of deliveredItems(session.assessment)) {\n\t\tconst variables = session.itemTestStates?.[item.identifier]?.variables;\n\t\tif (variables) itemVariables[item.identifier] = applyVariableMappings(variables, item.variableMappings);\n\t}\n\treturn addItemVariableDeclarations(testOutcomeDeclarations(session.assessment, outcomes), itemVariables, current);\n}\n\n/** Delivered item refs in order, each with the identifiers of the sections containing it (outermost first). */\nexport function getItemRefsInOrder(\n\tassessment: SecureAssessment\n): Array<{ item: SecureItemRef; sectionIdentifiers: string[] }> {\n\treturn deliveredItems(assessment).map(({ item, sections }) => ({\n\t\titem,\n\t\tsectionIdentifiers: sections.map((section) => section.identifier),\n\t}));\n}\n"]}
@@ -28,6 +28,10 @@ export function toSectionComposition(player, config = {}) {
28
28
  passageTools: scopedTools(config.passageTools, 'passage'),
29
29
  });
30
30
  const activeSession = player.getCurrentItemSession();
31
+ // One shallow snapshot of the section's response records. Inactive items here are
32
+ // read-only composition data (only the active item renders, from its live session),
33
+ // so per-item deep clones would copy every answer on every composition build.
34
+ const sectionResponses = player.getSectionItemResponses();
31
35
  const sectionItems = player.getCurrentSectionItemRefs().map((item) => {
32
36
  const common = {
33
37
  identifier: item.identifier,
@@ -39,9 +43,12 @@ export function toSectionComposition(player, config = {}) {
39
43
  };
40
44
  return item.identifier === currentItem?.identifier && activeSession
41
45
  ? { ...common, session: activeSession }
42
- : { ...common, responses: player.getResponsesForItem(item.identifier) };
46
+ : { ...common, responses: sectionResponses[item.identifier] ?? {} };
43
47
  });
44
48
  return resolveQtiSectionComposition({
49
+ // The assessment the section belongs to: section tool bars name it (catalogs,
50
+ // display-settings session keys), not the section identifier.
51
+ assessmentId: player.getAssessmentId(),
45
52
  section: {
46
53
  identifier: navState.currentSection?.id ?? 'active-section',
47
54
  title: navState.currentSection?.title ?? currentItem?.title,
@@ -1 +1 @@
1
- {"version":3,"file":"toSectionComposition.js","sourceRoot":"","sources":["../../src/integration/toSectionComposition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACN,4BAA4B,GAK5B,MAAM,yBAAyB,CAAC;AAGjC,SA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YACjB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC;SAC5C,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,KAAK,WAAW,EAAE,UAAU,IAAI,aAAa;YAClE,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE;YACvC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;IAC1E,CAAC,CAAC,CAAC;IAEH,OAAO,4BAA4B,CAAC;QACnC,OAAO,EAAE;YACR,UAAU,EAAE,QAAQ,CAAC,cAAc,EAAE,EAAE,IAAI,gBAAgB;YAC3D,KAAK,EAAE,QAAQ,CAAC,cAAc,EAAE,KAAK,IAAI,WAAW,EAAE,KAAK;YAC3D,IAAI;YACJ,gBAAgB,EAAE,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;YAC/E,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC;YAClD,QAAQ,EAAE,YAAY;YACtB,aAAa;SACb;QACD,oBAAoB,EAAE,WAAW,EAAE,UAAU;QAC7C,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,WAAW;QACxB,GAAG,EAAE,MAAM,CAAC,GAAG;KACf,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { normalizeQtiSharedContext } from '@pie-qti/assessment-toolkit';\nimport {\n\tresolveQtiSectionComposition,\n\ttype QtiSectionItemRef,\n\ttype QtiSectionRole,\n\ttype QtiSectionToolConfig,\n\ttype ResolvedQtiSectionComposition,\n} from '@pie-qti/section-player';\nimport type { AssessmentPlayer, BackendAssessmentPlayerConfig } from '../core/AssessmentPlayer.js';\n\nfunction toSectionRole(role: BackendAssessmentPlayerConfig['role']): QtiSectionRole {\n\tswitch (role) {\n\t\tcase 'author':\n\t\tcase 'candidate':\n\t\tcase 'proctor':\n\t\tcase 'scorer':\n\t\tcase 'testConstructor':\n\t\tcase 'tutor':\n\t\t\treturn role;\n\t\tdefault:\n\t\t\treturn 'candidate';\n\t}\n}\n\nfunction scopedTools(tools: QtiSectionToolConfig[] | undefined, scope: QtiSectionToolConfig['scope']): QtiSectionToolConfig[] | undefined {\n\tif (!tools || tools.length === 0) return undefined;\n\treturn tools.map((tool) => ({ ...tool, scope }));\n}\n\nexport function toSectionComposition(\n\tplayer: AssessmentPlayer,\n\tconfig: Partial<BackendAssessmentPlayerConfig> = {}\n): ResolvedQtiSectionComposition {\n\tconst navState = player.getNavigationState();\n\tconst currentItem = player.getCurrentItem();\n\tconst role = toSectionRole(config.role);\n\tconst sharedContext = normalizeQtiSharedContext({\n\t\trubricBlocks: player.getCurrentSharedRubricBlocks(),\n\t\trole,\n\t\tpassageTools: scopedTools(config.passageTools, 'passage'),\n\t});\n\tconst activeSession = player.getCurrentItemSession();\n\tconst sectionItems: QtiSectionItemRef[] = player.getCurrentSectionItemRefs().map((item) => {\n\t\tconst common = {\n\t\t\tidentifier: item.identifier,\n\t\t\thref: item.href,\n\t\t\ttitle: item.title,\n\t\t\titemXml: item.itemXml,\n\t\t\tdeliveryContext: item.deliveryContext,\n\t\t\ttools: scopedTools(config.itemTools, 'item'),\n\t\t};\n\t\treturn item.identifier === currentItem?.identifier && activeSession\n\t\t\t? { ...common, session: activeSession }\n\t\t\t: { ...common, responses: player.getResponsesForItem(item.identifier) };\n\t});\n\n\treturn resolveQtiSectionComposition({\n\t\tsection: {\n\t\t\tidentifier: navState.currentSection?.id ?? 'active-section',\n\t\t\ttitle: navState.currentSection?.title ?? currentItem?.title,\n\t\t\trole,\n\t\t\tlayoutPreference: sharedContext.passages.length > 0 ? 'split-pane' : 'vertical',\n\t\t\ttools: scopedTools(config.sectionTools, 'section'),\n\t\t\titemRefs: sectionItems,\n\t\t\tsharedContext,\n\t\t},\n\t\tactiveItemIdentifier: currentItem?.identifier,\n\t\tcanPrevious: navState.canPrevious,\n\t\tcanNext: navState.canNext,\n\t\tsecurity: config.security,\n\t\thost: config.sectionHost,\n\t\tpnp: config.pnp,\n\t});\n}\n"]}
1
+ {"version":3,"file":"toSectionComposition.js","sourceRoot":"","sources":["../../src/integration/toSectionComposition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EACN,4BAA4B,GAK5B,MAAM,yBAAyB,CAAC;AAGjC,SAAS,aAAa,CAAC,IAA2C;IACjE,QAAQ,IAAI,EAAE,CAAC;QACd,KAAK,QAAQ,CAAC;QACd,KAAK,WAAW,CAAC;QACjB,KAAK,SAAS,CAAC;QACf,KAAK,QAAQ,CAAC;QACd,KAAK,iBAAiB,CAAC;QACvB,KAAK,OAAO;YACX,OAAO,IAAI,CAAC;QACb;YACC,OAAO,WAAW,CAAC;IACrB,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,KAAyC,EAAE,KAAoC;IACnG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,oBAAoB,CACnC,MAAwB,EACxB,SAAiD,EAAE;IAEnD,MAAM,QAAQ,GAAG,MAAM,CAAC,kBAAkB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAAG,MAAM,CAAC,cAAc,EAAE,CAAC;IAC5C,MAAM,IAAI,G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AE,QAAQ,CAAC,cAAc,EAAE,KAAK,IAAI,WAAW,EAAE,KAAK;YAC3D,IAAI;YACJ,gBAAgB,EAAE,aAAa,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU;YAC/E,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC;YAClD,QAAQ,EAAE,YAAY;YACtB,aAAa;SACb;QACD,oBAAoB,EAAE,WAAW,EAAE,UAAU;QAC7C,WAAW,EAAE,QAAQ,CAAC,WAAW;QACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,IAAI,EAAE,MAAM,CAAC,WAAW;QACxB,GAAG,EAAE,MAAM,CAAC,GAAG;KACf,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import { normalizeQtiSharedContext } from '@pie-qti/assessment-toolkit';\nimport {\n\tresolveQtiSectionComposition,\n\ttype QtiSectionItemRef,\n\ttype QtiSectionRole,\n\ttype QtiSectionToolConfig,\n\ttype ResolvedQtiSectionComposition,\n} from '@pie-qti/section-player';\nimport type { AssessmentPlayer, BackendAssessmentPlayerConfig } from '../core/AssessmentPlayer.js';\n\nfunction toSectionRole(role: BackendAssessmentPlayerConfig['role']): QtiSectionRole {\n\tswitch (role) {\n\t\tcase 'author':\n\t\tcase 'candidate':\n\t\tcase 'proctor':\n\t\tcase 'scorer':\n\t\tcase 'testConstructor':\n\t\tcase 'tutor':\n\t\t\treturn role;\n\t\tdefault:\n\t\t\treturn 'candidate';\n\t}\n}\n\nfunction scopedTools(tools: QtiSectionToolConfig[] | undefined, scope: QtiSectionToolConfig['scope']): QtiSectionToolConfig[] | undefined {\n\tif (!tools || tools.length === 0) return undefined;\n\treturn tools.map((tool) => ({ ...tool, scope }));\n}\n\nexport function toSectionComposition(\n\tplayer: AssessmentPlayer,\n\tconfig: Partial<BackendAssessmentPlayerConfig> = {}\n): ResolvedQtiSectionComposition {\n\tconst navState = player.getNavigationState();\n\tconst currentItem = player.getCurrentItem();\n\tconst role = toSectionRole(config.role);\n\tconst sharedContext = normalizeQtiSharedContext({\n\t\trubricBlocks: player.getCurrentSharedRubricBlocks(),\n\t\trole,\n\t\tpassageTools: scopedTools(config.passageTools, 'passage'),\n\t});\n\tconst activeSession = player.getCurrentItemSession();\n\t// One shallow snapshot of the section's response records. Inactive items here are\n\t// read-only composition data (only the active item renders, from its live session),\n\t// so per-item deep clones would copy every answer on every composition build.\n\tconst sectionResponses = player.getSectionItemResponses();\n\tconst sectionItems: QtiSectionItemRef[] = player.getCurrentSectionItemRefs().map((item) => {\n\t\tconst common = {\n\t\t\tidentifier: item.identifier,\n\t\t\thref: item.href,\n\t\t\ttitle: item.title,\n\t\t\titemXml: item.itemXml,\n\t\t\tdeliveryContext: item.deliveryContext,\n\t\t\ttools: scopedTools(config.itemTools, 'item'),\n\t\t};\n\t\treturn item.identifier === currentItem?.identifier && activeSession\n\t\t\t? { ...common, session: activeSession }\n\t\t\t: { ...common, responses: sectionResponses[item.identifier] ?? {} };\n\t});\n\n\treturn resolveQtiSectionComposition({\n\t\t// The assessment the section belongs to: section tool bars name it (catalogs,\n\t\t// display-settings session keys), not the section identifier.\n\t\tassessmentId: player.getAssessmentId(),\n\t\tsection: {\n\t\t\tidentifier: navState.currentSection?.id ?? 'active-section',\n\t\t\ttitle: navState.currentSection?.title ?? currentItem?.title,\n\t\t\trole,\n\t\t\tlayoutPreference: sharedContext.passages.length > 0 ? 'split-pane' : 'vertical',\n\t\t\ttools: scopedTools(config.sectionTools, 'section'),\n\t\t\titemRefs: sectionItems,\n\t\t\tsharedContext,\n\t\t},\n\t\tactiveItemIdentifier: currentItem?.identifier,\n\t\tcanPrevious: navState.canPrevious,\n\t\tcanNext: navState.canNext,\n\t\tsecurity: config.security,\n\t\thost: config.sectionHost,\n\t\tpnp: config.pnp,\n\t});\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export { ASSESSMENT_RESULT_NAMESPACES, AssessmentResultSerializationError, type SerializeAssessmentResultOptions, serializeAssessmentResult, } from './serializeAssessmentResult.js';
2
+ export { type AssessmentResultsData, type AssessmentResultXmlOptions, buildAssessmentResultReport, toAssessmentResultXml, } from './toAssessmentResultXml.js';
3
+ export type { AssessmentItemResult, AssessmentResultContext, AssessmentResultReport, AssessmentResultVersion, AssessmentTestResult, ResultBaseType, ResultCardinality, ResultContextVariable, ResultDatestamp, ResultOutcomeVariable, ResultResponseVariable, ResultSessionIdentifier, ResultSessionStatus, ResultTemplateVariable, ResultVariable, } from './types.js';
@@ -0,0 +1,3 @@
1
+ export { ASSESSMENT_RESULT_NAMESPACES, AssessmentResultSerializationError, serializeAssessmentResult, } from './serializeAssessmentResult.js';
2
+ export { buildAssessmentResultReport, toAssessmentResultXml, } from './toAssessmentResultXml.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/reporting/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,4BAA4B,EAC5B,kCAAkC,EAElC,yBAAyB,GACzB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAGN,2BAA2B,EAC3B,qBAAqB,GACrB,MAAM,4BAA4B,CAAC","sourcesContent":["export {\n\tASSESSMENT_RESULT_NAMESPACES,\n\tAssessmentResultSerializationError,\n\ttype SerializeAssessmentResultOptions,\n\tserializeAssessmentResult,\n} from './serializeAssessmentResult.js';\nexport {\n\ttype AssessmentResultsData,\n\ttype AssessmentResultXmlOptions,\n\tbuildAssessmentResultReport,\n\ttoAssessmentResultXml,\n} from './toAssessmentResultXml.js';\nexport type {\n\tAssessmentItemResult,\n\tAssessmentResultContext,\n\tAssessmentResultReport,\n\tAssessmentResultVersion,\n\tAssessmentTestResult,\n\tResultBaseType,\n\tResultCardinality,\n\tResultContextVariable,\n\tResultDatestamp,\n\tResultOutcomeVariable,\n\tResultResponseVariable,\n\tResultSessionIdentifier,\n\tResultSessionStatus,\n\tResultTemplateVariable,\n\tResultVariable,\n} from './types.js';\n"]}
@@ -0,0 +1,13 @@
1
+ import type { ResultBaseType } from './types.js';
2
+ /**
3
+ * The base type of a report value that no declaration and no serialized field types: a boolean is
4
+ * a QTI boolean, a whole number an integer (the base type whose value space whole numbers live in),
5
+ * a fractional number a float, anything else a string. A list types itself by its members:
6
+ * integer only when every member is a whole number, float when any member is fractional, else the
7
+ * first member's type (so `[3, 4]` is integer while `[3, 3.5]` stays float and loses nothing).
8
+ *
9
+ * One rule shared by every report writer, so an undeclared value writes the same base type
10
+ * whichever writer reports it — `toAssessmentResultXml` and `serializeAssessmentResult` both
11
+ * delegate here.
12
+ */
13
+ export declare function inferBaseType(value: unknown): ResultBaseType;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The base type of a report value that no declaration and no serialized field types: a boolean is
3
+ * a QTI boolean, a whole number an integer (the base type whose value space whole numbers live in),
4
+ * a fractional number a float, anything else a string. A list types itself by its members:
5
+ * integer only when every member is a whole number, float when any member is fractional, else the
6
+ * first member's type (so `[3, 4]` is integer while `[3, 3.5]` stays float and loses nothing).
7
+ *
8
+ * One rule shared by every report writer, so an undeclared value writes the same base type
9
+ * whichever writer reports it — `toAssessmentResultXml` and `serializeAssessmentResult` both
10
+ * delegate here.
11
+ */
12
+ export function inferBaseType(value) {
13
+ if (Array.isArray(value)) {
14
+ const members = value.filter((entry) => entry !== null && entry !== undefined);
15
+ if (members.length > 0 && members.every((entry) => typeof entry === 'number')) {
16
+ return members.every((entry) => Number.isInteger(entry)) ? 'integer' : 'float';
17
+ }
18
+ return members.length > 0 ? inferBaseType(members[0]) : 'string';
19
+ }
20
+ if (typeof value === 'boolean')
21
+ return 'boolean';
22
+ if (typeof value === 'number')
23
+ return Number.isInteger(value) ? 'integer' : 'float';
24
+ return 'string';
25
+ }
26
+ //# sourceMappingURL=inferBaseType.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inferBaseType.js","sourceRoot":"","sources":["../../src/reporting/inferBaseType.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC1B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC;QAC/E,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE,CAAC;YAC/E,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QAChF,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IACnE,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,SAAS;QAAE,OAAO,SAAS,CAAC;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IACpF,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["import type { ResultBaseType } from './types.js';\n\n/**\n * The base type of a report value that no declaration and no serialized field types: a boolean is\n * a QTI boolean, a whole number an integer (the base type whose value space whole numbers live in),\n * a fractional number a float, anything else a string. A list types itself by its members:\n * integer only when every member is a whole number, float when any member is fractional, else the\n * first member's type (so `[3, 4]` is integer while `[3, 3.5]` stays float and loses nothing).\n *\n * One rule shared by every report writer, so an undeclared value writes the same base type\n * whichever writer reports it — `toAssessmentResultXml` and `serializeAssessmentResult` both\n * delegate here.\n */\nexport function inferBaseType(value: unknown): ResultBaseType {\n\tif (Array.isArray(value)) {\n\t\tconst members = value.filter((entry) => entry !== null && entry !== undefined);\n\t\tif (members.length > 0 && members.every((entry) => typeof entry === 'number')) {\n\t\t\treturn members.every((entry) => Number.isInteger(entry)) ? 'integer' : 'float';\n\t\t}\n\t\treturn members.length > 0 ? inferBaseType(members[0]!) : 'string';\n\t}\n\tif (typeof value === 'boolean') return 'boolean';\n\tif (typeof value === 'number') return Number.isInteger(value) ? 'integer' : 'float';\n\treturn 'string';\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import type { AssessmentResultReport, AssessmentResultVersion } from './types.js';
2
+ /**
3
+ * The QTI Results Reporting namespaces and schema locations, as the 1EdTech schemas declare them:
4
+ * `imsqti_result_v2p2.xsd` (QTI 2.2) and `imsqti_resultv3p0_v1p0.xsd` (QTI 3.0). Both versions use
5
+ * the same camelCase element and attribute names.
6
+ */
7
+ export declare const ASSESSMENT_RESULT_NAMESPACES: Readonly<Record<AssessmentResultVersion, {
8
+ readonly namespace: string;
9
+ readonly schemaLocation: string;
10
+ }>>;
11
+ export interface SerializeAssessmentResultOptions {
12
+ readonly version: AssessmentResultVersion;
13
+ /** Declare `xsi:schemaLocation` for the version's results schema. Default: true. */
14
+ readonly schemaLocation?: boolean;
15
+ }
16
+ /** The report cannot be written as a schema-valid `assessmentResult` of the requested version. */
17
+ export declare class AssessmentResultSerializationError extends Error {
18
+ constructor(message: string);
19
+ }
20
+ /**
21
+ * Writes a QTI Results Reporting `assessmentResult` document. Every value and attribute is
22
+ * XML-escaped (characters XML 1.0 cannot carry become U+FFFD); identifiers the version's schema
23
+ * types as NCName, an unknown base type or cardinality, a session status the version lacks, or an
24
+ * invalid date throw an `AssessmentResultSerializationError`. Durations are written as seconds,
25
+ * the xsd:double form QTI defines.
26
+ */
27
+ export declare function serializeAssessmentResult(report: AssessmentResultReport, options: SerializeAssessmentResultOptions): string;