@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.
- package/README.md +28 -7
- package/dist/components/createPlayerConnection.svelte.d.ts +90 -0
- package/dist/components/createPlayerConnection.svelte.js +151 -0
- package/dist/components/createPlayerConnection.svelte.js.map +1 -0
- package/dist/components/displaySettings.svelte.d.ts +23 -0
- package/dist/components/displaySettings.svelte.js +40 -0
- package/dist/components/displaySettings.svelte.js.map +1 -0
- package/dist/components/srOnly.d.ts +29 -0
- package/dist/components/srOnly.js +55 -0
- package/dist/components/srOnly.js.map +1 -0
- package/dist/components/submitDialogAction.d.ts +25 -0
- package/dist/components/submitDialogAction.js +89 -0
- package/dist/components/submitDialogAction.js.map +1 -0
- package/dist/core/AssessmentPlayer.d.ts +1102 -53
- package/dist/core/AssessmentPlayer.js +2835 -460
- package/dist/core/AssessmentPlayer.js.map +1 -1
- package/dist/core/AssessmentSessionCoordinator.d.ts +76 -7
- package/dist/core/AssessmentSessionCoordinator.js +185 -10
- package/dist/core/AssessmentSessionCoordinator.js.map +1 -1
- package/dist/core/AutosaveManager.d.ts +104 -0
- package/dist/core/AutosaveManager.js +181 -0
- package/dist/core/AutosaveManager.js.map +1 -0
- package/dist/core/ItemSessionController.d.ts +17 -26
- package/dist/core/ItemSessionController.js +33 -73
- package/dist/core/ItemSessionController.js.map +1 -1
- package/dist/core/NavigationManager.d.ts +18 -50
- package/dist/core/NavigationManager.js +21 -83
- package/dist/core/NavigationManager.js.map +1 -1
- package/dist/core/TimeManager.d.ts +62 -16
- package/dist/core/TimeManager.js +148 -57
- package/dist/core/TimeManager.js.map +1 -1
- package/dist/core/autosave.d.ts +44 -0
- package/dist/core/autosave.js +46 -0
- package/dist/core/autosave.js.map +1 -0
- package/dist/core/deliveryStructure.d.ts +54 -0
- package/dist/core/deliveryStructure.js +72 -0
- package/dist/core/deliveryStructure.js.map +1 -0
- package/dist/core/errors.d.ts +116 -0
- package/dist/core/errors.js +77 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/exitBoundaries.d.ts +64 -0
- package/dist/core/exitBoundaries.js +98 -0
- package/dist/core/exitBoundaries.js.map +1 -0
- package/dist/core/feedback.d.ts +46 -0
- package/dist/core/feedback.js +47 -0
- package/dist/core/feedback.js.map +1 -0
- package/dist/core/formatTime.d.ts +8 -0
- package/dist/core/formatTime.js +20 -0
- package/dist/core/formatTime.js.map +1 -0
- package/dist/core/index.d.ts +7 -4
- package/dist/core/index.js +4 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/navigationPolicy.d.ts +42 -0
- package/dist/core/navigationPolicy.js +62 -0
- package/dist/core/navigationPolicy.js.map +1 -0
- package/dist/core/pause.d.ts +58 -0
- package/dist/core/pause.js +101 -0
- package/dist/core/pause.js.map +1 -0
- package/dist/core/playerEvents.d.ts +51 -0
- package/dist/core/playerEvents.js +66 -0
- package/dist/core/playerEvents.js.map +1 -0
- package/dist/core/reviewState.d.ts +81 -0
- package/dist/core/reviewState.js +113 -0
- package/dist/core/reviewState.js.map +1 -0
- package/dist/core/reviewViews.d.ts +43 -0
- package/dist/core/reviewViews.js +88 -0
- package/dist/core/reviewViews.js.map +1 -0
- package/dist/core/scopeLocks.d.ts +36 -0
- package/dist/core/scopeLocks.js +78 -0
- package/dist/core/scopeLocks.js.map +1 -0
- package/dist/core/sessionRecords.d.ts +31 -0
- package/dist/core/sessionRecords.js +74 -0
- package/dist/core/sessionRecords.js.map +1 -0
- package/dist/core/submissionPolicy.d.ts +62 -0
- package/dist/core/submissionPolicy.js +67 -0
- package/dist/core/submissionPolicy.js.map +1 -0
- package/dist/core/templateDefaults.d.ts +26 -0
- package/dist/core/templateDefaults.js +53 -0
- package/dist/core/templateDefaults.js.map +1 -0
- package/dist/core/testStructure.d.ts +118 -3
- package/dist/core/testStructure.js +252 -6
- package/dist/core/testStructure.js.map +1 -1
- package/dist/core/timePolicy.d.ts +40 -0
- package/dist/core/timePolicy.js +106 -0
- package/dist/core/timePolicy.js.map +1 -0
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +64 -101
- package/dist/integration/ReferenceBackendAdapter.js +216 -1035
- package/dist/integration/ReferenceBackendAdapter.js.map +1 -1
- package/dist/integration/api-contract.d.ts +179 -17
- package/dist/integration/api-contract.js.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +56 -5
- package/dist/integration/assessment-item-scorer.js +116 -13
- package/dist/integration/assessment-item-scorer.js.map +1 -1
- package/dist/integration/index.d.ts +2 -2
- package/dist/integration/index.js +1 -1
- package/dist/integration/index.js.map +1 -1
- package/dist/integration/qti-test-parser.d.ts +44 -0
- package/dist/integration/qti-test-parser.js +529 -0
- package/dist/integration/qti-test-parser.js.map +1 -0
- package/dist/integration/session-store.d.ts +54 -0
- package/dist/integration/session-store.js +75 -0
- package/dist/integration/session-store.js.map +1 -0
- package/dist/integration/test-navigation.d.ts +23 -0
- package/dist/integration/test-navigation.js +32 -0
- package/dist/integration/test-navigation.js.map +1 -0
- package/dist/integration/toSectionComposition.js +8 -1
- package/dist/integration/toSectionComposition.js.map +1 -1
- package/dist/reporting/index.d.ts +3 -0
- package/dist/reporting/index.js +3 -0
- package/dist/reporting/index.js.map +1 -0
- package/dist/reporting/inferBaseType.d.ts +13 -0
- package/dist/reporting/inferBaseType.js +26 -0
- package/dist/reporting/inferBaseType.js.map +1 -0
- package/dist/reporting/serializeAssessmentResult.d.ts +27 -0
- package/dist/reporting/serializeAssessmentResult.js +377 -0
- package/dist/reporting/serializeAssessmentResult.js.map +1 -0
- package/dist/reporting/toAssessmentResultXml.d.ts +39 -0
- package/dist/reporting/toAssessmentResultXml.js +304 -0
- package/dist/reporting/toAssessmentResultXml.js.map +1 -0
- package/dist/reporting/types.d.ts +85 -0
- package/dist/reporting/types.js +8 -0
- package/dist/reporting/types.js.map +1 -0
- package/dist/types/index.d.ts +96 -9
- package/dist/types/index.js.map +1 -1
- package/package.json +21 -15
- package/dist/core/StatePersistenceManager.d.ts +0 -125
- package/dist/core/StatePersistenceManager.js +0 -268
- package/dist/core/StatePersistenceManager.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -114
- package/dist/utils/PerformanceMonitor.js +0 -172
- package/dist/utils/PerformanceMonitor.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeManager.js","sourceRoot":"","sources":["../../src/core/TimeManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAyEH,gGAAgG;AAChG,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,QAAkC;IAClF,IAAI,CAAC,QAAQ,EAAE,MAAM;QAAE,OAAO,OAAO,CAAC;IACtC,IAAI,QAAQ,CAAC,UAAU,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACvD,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC;IACjF,MAAM,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC;IAC3C,OAAO,YAAY,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,YAAY,GAAG,CAAC;QACrF,CAAC,CAAC,MAAM,GAAG,YAAY,GAAG,EAAE;QAC5B,CAAC,CAAC,MAAM,CAAC;AACX,CAAC;AAED,MAAM,OAAO,WAAW;IAYvB,YAAY,MAAyB;QARrC,kBAAkB;QACV,eAAU,GAA0C,IAAI,CAAC;QACzD,mBAAc,GAAkB,IAAI,CAAC;QACrC,qBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;QACrC,wBAAmB,GAAG,IAAI,GAAG,EAAU,CAAC;QACxC,iBAAY,GAAqB,EAAE,CAAC;QAI3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;Q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C,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAE3C,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;YACf,OAAO,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;QACvE,CAAC;QAED,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,OAAO;QACN,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD","sourcesContent":["/**\n * TimeManager\n *\n * Manages time limits and tracking for QTI assessments.\n * Supports test-level, section-level, and item-level time limits.\n *\n * Features:\n * - Countdown timers with warnings\n * - Auto-submission when time expires\n * - Time spent tracking per item\n * - Pause/resume support\n * - Late submission handling\n */\n\nimport type { TimeLimits } from '../types/index.js';\n\nexport interface TimeManagerConfig {\n\t/** Assessment-level time limits */\n\tassessmentTimeLimits?: TimeLimits;\n\t/** Warning threshold (seconds before expiry) */\n\twarningThreshold?: number;\n\t/** Callback when time warning is triggered */\n\tonWarning?: (remainingSeconds: number) => void;\n\t/** Callback when time expires */\n\tonExpired?: () => void;\n\t/**\n\t * Callback when a test part, section or item limit without late submission expires. When set,\n\t * those expiries lock the scope through this callback and the timer keeps running; only the\n\t * assessment limit calls `onExpired`.\n\t */\n\tonScopeExpired?: (scope: 'testPart' | 'section' | 'item', identifier: string) => void;\n\t/** Callback for time updates (fires every second) */\n\tonTick?: (remainingSeconds: number, elapsedSeconds: number) => void;\n\t/**\n\t * QTI 3.0 PNP extended time accommodation, applied to every time limit by\n\t * `extendTimeLimit`.\n\t */\n\textendedTime?: ExtendedTime;\n\t/** Injectable monotonic wall clock for deterministic hosts/tests. */\n\tnow?: () => number;\n}\n\nexport interface ActiveTimeScopes {\n\ttestPart?: { identifier: string; timeLimits?: TimeLimits };\n\tsection?: { identifier: string; timeLimits?: TimeLimits };\n\titem?: { identifier: string; timeLimits?: TimeLimits };\n}\n\nexport interface TimeTrackingState {\n\t/** Total elapsed time (ms) */\n\ttotalElapsed: number;\n\t/** Time spent per item identifier (ms) */\n\titemTimes: Record<string, number>;\n\t/** Time spent per section identifier (ms) */\n\tsectionTimes: Record<string, number>;\n\t/** Time spent per testPart identifier (ms) */\n\ttestPartTimes: Record<string, number>;\n\t/** Session start timestamp */\n\tstartedAt: number;\n\t/** Current item start time (for tracking) */\n\tcurrentItemStartTime?: number;\n\t/** Current item identifier */\n\tcurrentItemId?: string;\n\t/** Current section identifier */\n\tcurrentSectionId?: string;\n\t/** Current section start time */\n\tcurrentSectionStartTime?: number;\n\t/** Current testPart identifier */\n\tcurrentTestPartId?: string;\n\t/** Current testPart start time */\n\tcurrentTestPartStartTime?: number;\n\t/** Is timer currently paused */\n\tisPaused: boolean;\n}\n\n/**\n * The PNP extended-time accommodation: `multiplier` scales a limit (Infinity removes it)\n * and `fixedMinutes`, AfA's `fixed-minutes`, adds to it.\n */\nexport interface ExtendedTime {\n\tactive: boolean;\n\tmultiplier: number;\n\tfixedMinutes?: number;\n}\n\n/** A time limit in seconds under extended time; undefined when the accommodation removes it. */\nexport function extendTimeLimit(seconds: number, extended: ExtendedTime | undefined): number | undefined {\n\tif (!extended?.active) return seconds;\n\tif (extended.multiplier === Infinity) return undefined;\n\tconst scaled = extended.multiplier > 0 ? seconds * extended.multiplier : seconds;\n\tconst fixedMinutes = extended.fixedMinutes;\n\treturn fixedMinutes !== undefined && Number.isFinite(fixedMinutes) && fixedMinutes > 0\n\t\t? scaled + fixedMinutes * 60\n\t\t: scaled;\n}\n\nexport class TimeManager {\n\tprivate config: TimeManagerConfig;\n\tprivate state: TimeTrackingState;\n\n\t// Timer internals\n\tprivate intervalId: ReturnType<typeof setInterval> | null = null;\n\tprivate maxTimeSeconds: number | null = null;\n\tprivate warningTriggered = new Set<string>();\n\tprivate expirationTriggered = new Set<string>();\n\tprivate activeScopes: ActiveTimeScopes = {};\n\tprivate lastTickAt: number;\n\n\tconstructor(config: TimeManagerConfig) {\n\t\tthis.config = config;\n\t\tthis.state = {\n\t\t\ttotalElapsed: 0,\n\t\t\titemTimes: {},\n\t\t\tsectionTimes: {},\n\t\t\ttestPartTimes: {},\n\t\t\tstartedAt: this.now(),\n\t\t\tisPaused: false,\n\t\t};\n\t\tthis.lastTickAt = this.now();\n\n\t\t// Initialize timer if time limit exists, applying PNP extended-time multiplier if set.\n\t\tif (config.assessmentTimeLimits?.maxTime) {\n\t\t\tthis.maxTimeSeconds = extendTimeLimit(config.assessmentTimeLimits.maxTime, config.extendedTime) ?? null;\n\t\t}\n\t\t// Scope timing is required even when the assessment itself has no maxTime.\n\t\tthis.startTimer();\n\t}\n\n\tprivate now(): number {\n\t\treturn this.config.now?.() ?? Date.now();\n\t}\n\n\tprivate applyExtendedTime(seconds: number | undefined): number | null {\n\t\tif (seconds === undefined) return null;\n\t\treturn extendTimeLimit(seconds, this.config.extendedTime) ?? null;\n\t}\n\n\t/**\n\t * Start or resume the timer\n\t */\n\tprivate startTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\treturn; // Already running\n\t\t}\n\n\t\tthis.state.isPaused = false;\n\t\tthis.lastTickAt = this.now();\n\n\t\tthis.intervalId = setInterval(() => {\n\t\t\tconst now = this.now();\n\t\t\tif (this.state.isPaused) {\n\t\t\t\tthis.lastTickAt = now;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.state.totalElapsed += Math.max(0, now - this.lastTickAt);\n\t\t\tthis.lastTickAt = now;\n\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\t\tconst candidates = this.getActiveCandidates();\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.remainingSeconds > 0 || this.expirationTriggered.has(candidate.key)) continue;\n\t\t\t\tthis.expirationTriggered.add(candidate.key);\n\t\t\t\tif (!candidate.allowLateSubmission) {\n\t\t\t\t\tconst separator = candidate.key.indexOf(':');\n\t\t\t\t\tif (separator > 0 && this.config.onScopeExpired) {\n\t\t\t\t\t\tconst scope = candidate.key.slice(0, separator) as 'testPart' | 'section' | 'item';\n\t\t\t\t\t\tthis.config.onScopeExpired(scope, candidate.key.slice(separator + 1));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.handleExpiration();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst activeRemaining = this.nearestRemaining(candidates);\n\t\t\tif (activeRemaining) {\n\t\t\t\tconst { key, remainingSeconds } = activeRemaining;\n\n\t\t\t\t// Trigger warning\n\t\t\t\tconst warningThreshold = this.config.warningThreshold ?? 60;\n\t\t\t\tif (!this.warningTriggered.has(key) && remainingSeconds <= warningThreshold && remainingSeconds > 0) {\n\t\t\t\t\tthis.warningTriggered.add(key);\n\t\t\t\t\tthis.config.onWarning?.(remainingSeconds);\n\t\t\t\t}\n\n\t\t\t\t// Tick callback\n\t\t\t\tthis.config.onTick?.(remainingSeconds, elapsedSeconds);\n\t\t\t} else {\n\t\t\t\t// No limit - just count up\n\t\t\t\tthis.config.onTick?.(0, elapsedSeconds);\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\tprivate getActiveCandidates(): Array<{\n\t\tkey: string;\n\t\tremainingSeconds: number;\n\t\tallowLateSubmission: boolean;\n\t}> {\n\t\tconst candidates: Array<{ key: string; remainingSeconds: number; allowLateSubmission: boolean }> = [];\n\t\tif (this.maxTimeSeconds !== null) {\n\t\t\tcandidates.push({\n\t\t\t\tkey: 'assessment',\n\t\t\t\tremainingSeconds: this.maxTimeSeconds - this.getElapsedSeconds(),\n\t\t\t\tallowLateSubmission: this.config.assessmentTimeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\tfor (const scope of ['testPart', 'section', 'item'] as const) {\n\t\t\tconst active = this.activeScopes[scope];\n\t\t\tconst max = this.applyExtendedTime(active?.timeLimits?.maxTime);\n\t\t\tif (!active || max === null) continue;\n\t\t\tcandidates.push({\n\t\t\t\tkey: `${scope}:${active.identifier}`,\n\t\t\t\tremainingSeconds: max - this.getScopeElapsedMs(scope, active.identifier) / 1000,\n\t\t\t\tallowLateSubmission: active.timeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\treturn candidates;\n\t}\n\n\tprivate nearestRemaining(\n\t\tcandidates: Array<{ key: string; remainingSeconds: number; allowLateSubmission: boolean }>,\n\t): { key: string; remainingSeconds: number; allowLateSubmission: boolean } | null {\n\t\tif (candidates.length === 0) return null;\n\t\treturn candidates.reduce((nearest, candidate) =>\n\t\t\tcandidate.remainingSeconds < nearest.remainingSeconds ? candidate : nearest\n\t\t);\n\t}\n\n\tprivate getActiveRemaining(): { key: string; remainingSeconds: number; allowLateSubmission: boolean } | null {\n\t\treturn this.nearestRemaining(this.getActiveCandidates());\n\t}\n\n\t/**\n\t * Handle time expiration\n\t */\n\tprivate handleExpiration(): void {\n\t\tthis.stopTimer();\n\t\tthis.config.onExpired?.();\n\t}\n\n\t/**\n\t * Stop the timer\n\t */\n\tstopTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\tclearInterval(this.intervalId);\n\t\t\tthis.intervalId = null;\n\t\t}\n\t}\n\n\t/**\n\t * Pause the timer\n\t */\n\tpause(): void {\n\t\tif (this.state.isPaused) return;\n\t\tthis.state.totalElapsed = this.getTotalElapsedMs();\n\t\tthis.lastTickAt = this.now();\n\t\tthis.checkpointActiveScopes(false);\n\t\tthis.state.isPaused = true;\n\t}\n\n\t/**\n\t * Resume the timer\n\t */\n\tresume(): void {\n\t\tif (!this.state.isPaused) return;\n\t\tthis.state.isPaused = false;\n\t\tconst now = this.now();\n\t\tif (this.state.currentItemId) this.state.currentItemStartTime = now;\n\t\tif (this.state.currentSectionId) this.state.currentSectionStartTime = now;\n\t\tif (this.state.currentTestPartId) this.state.currentTestPartStartTime = now;\n\t\tthis.lastTickAt = now;\n\t}\n\n\t/**\n\t * Start tracking time for an item\n\t */\n\tstartItem(itemIdentifier: string): void {\n\t\tif (this.state.currentItemId === itemIdentifier && this.state.currentItemStartTime) return;\n\t\t// End previous item if any\n\t\tif (this.state.currentItemStartTime) {\n\t\t\tthis.endCurrentItem();\n\t\t}\n\n\t\tthis.state.currentItemId = itemIdentifier;\n\t\tthis.state.currentItemStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\t/**\n\t * End tracking time for current item\n\t */\n\tprivate endCurrentItem(): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = this.now() - this.state.currentItemStartTime;\n\t\tif (this.state.currentItemId) {\n\t\t\tthis.state.itemTimes[this.state.currentItemId] =\n\t\t\t\t(this.state.itemTimes[this.state.currentItemId] || 0) + Math.max(0, timeSpent);\n\t\t}\n\t\tthis.state.currentItemStartTime = undefined;\n\t\tthis.state.currentItemId = undefined;\n\t}\n\n\t/**\n\t * End tracking time for an item\n\t */\n\tendItem(itemIdentifier: string): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = this.now() - this.state.currentItemStartTime;\n\t\tconst activeIdentifier = this.state.currentItemId ?? itemIdentifier;\n\t\tthis.state.itemTimes[activeIdentifier] = (this.state.itemTimes[activeIdentifier] || 0) + Math.max(0, timeSpent);\n\t\tthis.state.currentItemStartTime = undefined;\n\t\tthis.state.currentItemId = undefined;\n\t}\n\n\t/**\n\t * Start tracking time for a section\n\t */\n\tstartSection(sectionIdentifier: string): void {\n\t\tif (this.state.currentSectionId === sectionIdentifier && this.state.currentSectionStartTime) return;\n\t\tthis.endCurrentSection();\n\t\tthis.state.currentSectionId = sectionIdentifier;\n\t\tthis.state.currentSectionStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\tstartTestPart(testPartIdentifier: string): void {\n\t\tif (this.state.currentTestPartId === testPartIdentifier && this.state.currentTestPartStartTime) return;\n\t\tthis.endCurrentTestPart();\n\t\tthis.state.currentTestPartId = testPartIdentifier;\n\t\tthis.state.currentTestPartStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\tactivateScopes(scopes: ActiveTimeScopes): void {\n\t\tif (scopes.testPart) this.startTestPart(scopes.testPart.identifier);\n\t\tif (scopes.section) this.startSection(scopes.section.identifier);\n\t\tif (scopes.item) this.startItem(scopes.item.identifier);\n\t\tthis.activeScopes = scopes;\n\t}\n\n\tprivate endCurrentSection(): void {\n\t\tif (this.state.currentSectionId && this.state.currentSectionStartTime) {\n\t\t\tconst elapsed = Math.max(0, this.now() - this.state.currentSectionStartTime);\n\t\t\tthis.state.sectionTimes[this.state.currentSectionId] =\n\t\t\t\t(this.state.sectionTimes[this.state.currentSectionId] || 0) + elapsed;\n\t\t}\n\t\tthis.state.currentSectionStartTime = undefined;\n\t}\n\n\tprivate endCurrentTestPart(): void {\n\t\tif (this.state.currentTestPartId && this.state.currentTestPartStartTime) {\n\t\t\tconst elapsed = Math.max(0, this.now() - this.state.currentTestPartStartTime);\n\t\t\tthis.state.testPartTimes[this.state.currentTestPartId] =\n\t\t\t\t(this.state.testPartTimes[this.state.currentTestPartId] || 0) + elapsed;\n\t\t}\n\t\tthis.state.currentTestPartStartTime = undefined;\n\t}\n\n\tprivate checkpointActiveScopes(restart: boolean): void {\n\t\tconst itemId = this.state.currentItemId;\n\t\tconst sectionId = this.state.currentSectionId;\n\t\tconst testPartId = this.state.currentTestPartId;\n\t\tthis.endCurrentItem();\n\t\tthis.endCurrentSection();\n\t\tthis.endCurrentTestPart();\n\t\tthis.state.currentItemId = itemId;\n\t\tthis.state.currentSectionId = sectionId;\n\t\tthis.state.currentTestPartId = testPartId;\n\t\tif (restart && !this.state.isPaused) {\n\t\t\tconst now = this.now();\n\t\t\tif (itemId) this.state.currentItemStartTime = now;\n\t\t\tif (sectionId) this.state.currentSectionStartTime = now;\n\t\t\tif (testPartId) this.state.currentTestPartStartTime = now;\n\t\t}\n\t}\n\n\t/**\n\t * Get remaining time in seconds (null if no limit)\n\t */\n\tgetRemainingSeconds(): number | null {\n\t\tconst active = this.getActiveRemaining();\n\t\treturn active ? Math.max(0, Math.ceil(active.remainingSeconds)) : null;\n\t}\n\n\t/**\n\t * Get elapsed time in seconds\n\t */\n\tgetElapsedSeconds(): number {\n\t\treturn Math.floor(this.getTotalElapsedMs() / 1000);\n\t}\n\n\tprivate getTotalElapsedMs(): number {\n\t\tif (this.state.isPaused) return this.state.totalElapsed;\n\t\treturn this.state.totalElapsed + Math.max(0, this.now() - this.lastTickAt);\n\t}\n\n\t/**\n\t * Get time spent on a specific item (ms)\n\t */\n\tgetItemTime(itemIdentifier: string): number {\n\t\treturn this.getScopeElapsedMs('item', itemIdentifier);\n\t}\n\n\tgetScopeElapsedMs(scope: 'assessment' | 'testPart' | 'section' | 'item', identifier?: string): number {\n\t\tif (scope === 'assessment') return this.getTotalElapsedMs();\n\t\tconst now = this.now();\n\t\tif (scope === 'item') {\n\t\t\tconst id = identifier ?? this.state.currentItemId;\n\t\t\tif (!id) return 0;\n\t\t\tconst active = id === this.state.currentItemId && this.state.currentItemStartTime && !this.state.isPaused\n\t\t\t\t? Math.max(0, now - this.state.currentItemStartTime)\n\t\t\t\t: 0;\n\t\t\treturn (this.state.itemTimes[id] || 0) + active;\n\t\t}\n\t\tif (scope === 'section') {\n\t\t\tconst id = identifier ?? this.state.currentSectionId;\n\t\t\tif (!id) return 0;\n\t\t\tconst active = id === this.state.currentSectionId && this.state.currentSectionStartTime && !this.state.isPaused\n\t\t\t\t? Math.max(0, now - this.state.currentSectionStartTime)\n\t\t\t\t: 0;\n\t\t\treturn (this.state.sectionTimes[id] || 0) + active;\n\t\t}\n\t\tconst id = identifier ?? this.state.currentTestPartId;\n\t\tif (!id) return 0;\n\t\tconst active = id === this.state.currentTestPartId && this.state.currentTestPartStartTime && !this.state.isPaused\n\t\t\t? Math.max(0, now - this.state.currentTestPartStartTime)\n\t\t\t: 0;\n\t\treturn (this.state.testPartTimes[id] || 0) + active;\n\t}\n\n\t/**\n\t * Get current tracking state (for persistence)\n\t */\n\tgetState(): TimeTrackingState {\n\t\tif (!this.state.isPaused) {\n\t\t\tthis.state.totalElapsed = this.getTotalElapsedMs();\n\t\t\tthis.lastTickAt = this.now();\n\t\t}\n\t\tthis.checkpointActiveScopes(true);\n\t\treturn {\n\t\t\t...this.state,\n\t\t\titemTimes: { ...this.state.itemTimes },\n\t\t\tsectionTimes: { ...this.state.sectionTimes },\n\t\t\ttestPartTimes: { ...this.state.testPartTimes },\n\t\t};\n\t}\n\n\t/**\n\t * Restore tracking state (for resume)\n\t */\n\trestoreState(state: TimeTrackingState): void {\n\t\tthis.state = {\n\t\t\t...state,\n\t\t\titemTimes: { ...state.itemTimes },\n\t\t\tsectionTimes: { ...state.sectionTimes },\n\t\t\ttestPartTimes: { ...(state.testPartTimes ?? {}) },\n\t\t\tcurrentItemStartTime: undefined,\n\t\t\tcurrentSectionStartTime: undefined,\n\t\t\tcurrentTestPartStartTime: undefined,\n\t\t};\n\t\tif (!this.state.isPaused) {\n\t\t\tconst now = this.now();\n\t\t\tif (this.state.currentItemId) this.state.currentItemStartTime = now;\n\t\t\tif (this.state.currentSectionId) this.state.currentSectionStartTime = now;\n\t\t\tif (this.state.currentTestPartId) this.state.currentTestPartStartTime = now;\n\t\t\tthis.lastTickAt = now;\n\t\t}\n\n\t\t// Restart timer if not expired\n\t\tif (this.maxTimeSeconds) {\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\t\tif (elapsedSeconds < this.maxTimeSeconds) {\n\t\t\t\tthis.startTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Check if time has expired\n\t */\n\tisExpired(): boolean {\n\t\tconst active = this.getActiveRemaining();\n\t\treturn active !== null && active.remainingSeconds <= 0;\n\t}\n\n\t/**\n\t * Check if late submission is allowed\n\t */\n\tallowsLateSubmission(): boolean {\n\t\tconst candidates = this.getActiveCandidates();\n\t\tconst expired = candidates.filter((candidate) => candidate.remainingSeconds <= 0);\n\t\tif (expired.length > 0) {\n\t\t\treturn expired.every((candidate) => candidate.allowLateSubmission);\n\t\t}\n\t\treturn this.nearestRemaining(candidates)?.allowLateSubmission ?? false;\n\t}\n\n\t/**\n\t * Format time as MM:SS or HH:MM:SS\n\t *\n\t * Pass the provider's `formatNumber` to render the locale's digits; without\n\t * it the digits are Western.\n\t */\n\tstatic formatTime(\n\t\tseconds: number,\n\t\tformatNumber?: (value: number, options?: Intl.NumberFormatOptions) => string\n\t): string {\n\t\tconst hours = Math.floor(seconds / 3600);\n\t\tconst minutes = Math.floor((seconds % 3600) / 60);\n\t\tconst secs = seconds % 60;\n\t\tconst format = (value: number, digits: number) =>\n\t\t\tformatNumber\n\t\t\t\t? formatNumber(value, { minimumIntegerDigits: digits, useGrouping: false })\n\t\t\t\t: value.toString().padStart(digits, '0');\n\n\t\tif (hours > 0) {\n\t\t\treturn `${format(hours, 1)}:${format(minutes, 2)}:${format(secs, 2)}`;\n\t\t}\n\n\t\treturn `${format(minutes, 1)}:${format(secs, 2)}`;\n\t}\n\n\t/**\n\t * Cleanup - stop all timers\n\t */\n\tdestroy(): void {\n\t\tthis.checkpointActiveScopes(false);\n\t\tthis.stopTimer();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TimeManager.js","sourceRoot":"","sources":["../../src/core/TimeManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4FH,gGAAgG;AAChG,MAAM,UAAU,eAAe,CAAC,OAAe,EAAE,QAAkC;IAClF,IAAI,CAAC,QAAQ,EAAE,MAAM;QAAE,OAAO,OAAO,CAAC;IACtC,IAAI,QAAQ,CAAC,UAAU,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IACvD,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,OAA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AAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACpE,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,mBAAmB,IAAI,KAAK,CAAC;IACxE,CAAC;IAED;;OAEG;IACH,OAAO;QACN,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,CAAC,SAAS,EAAE,CAAC;IAClB,CAAC;CACD","sourcesContent":["/**\n * TimeManager\n *\n * Manages time limits and tracking for QTI assessments.\n * Supports test-level, section-level, and item-level time limits.\n *\n * Features:\n * - Countdown timers with warnings\n * - Auto-submission when time expires\n * - Time spent tracking per item\n * - Pause/resume support\n * - Late submission handling\n */\n\nimport type { TimeLimits } from '../types/index.js';\n\nexport interface TimeManagerConfig {\n\t/** Assessment-level time limits */\n\tassessmentTimeLimits?: TimeLimits;\n\t/**\n\t * Warning thresholds (seconds before expiry). Each fires once per limiting scope when\n\t * the remaining time first reaches it, largest first. Without any, nothing warns.\n\t */\n\twarningThresholds?: number[];\n\t/** Callback when a warning threshold is reached */\n\tonWarning?: (remainingSeconds: number) => void;\n\t/** Callback when time expires */\n\tonExpired?: () => void;\n\t/**\n\t * Callback when a test part, section or item limit without late submission expires. When set,\n\t * those expiries lock the scope through this callback and the timer keeps running; only the\n\t * assessment limit calls `onExpired`.\n\t */\n\tonScopeExpired?: (scope: 'testPart' | 'section' | 'item', identifier: string) => void;\n\t/** Callback for time updates (fires every second) */\n\tonTick?: (remainingSeconds: number, elapsedSeconds: number) => void;\n\t/**\n\t * QTI 3.0 PNP extended time accommodation, applied to every time limit by\n\t * `extendTimeLimit`.\n\t */\n\textendedTime?: ExtendedTime;\n\t/** Injectable monotonic wall clock for deterministic hosts/tests. */\n\tnow?: () => number;\n}\n\nexport interface ActiveTimeScopes {\n\ttestPart?: { identifier: string; timeLimits?: TimeLimits };\n\t/** The innermost enclosing section. */\n\tsection?: { identifier: string; timeLimits?: TimeLimits };\n\t/**\n\t * Every enclosing section, outermost first. Delivery is nested inside all of them, so\n\t * each runs its own clock and its `timeLimits` expire and gate like any other scope.\n\t * When set, `section` must be its last entry (kept in sync by the caller).\n\t */\n\tsections?: Array<{ identifier: string; timeLimits?: TimeLimits }>;\n\titem?: { identifier: string; timeLimits?: TimeLimits };\n}\n\n/** The active hard maximum that runs out first: what a countdown UI shows. */\nexport interface NearestTimeLimit {\n\t/** The scope the limit was authored on; `assessment` is the whole test. */\n\tscope: 'assessment' | 'testPart' | 'section' | 'item';\n\t/** Scope identifier; undefined for the assessment scope. */\n\tidentifier?: string;\n\t/** Seconds left (may be fractional; the ticking UI rounds up). */\n\tremainingSeconds: number;\n\tallowLateSubmission: boolean;\n}\n\nexport interface TimeTrackingState {\n\t/** Total elapsed time (ms) */\n\ttotalElapsed: number;\n\t/** Time spent per item identifier (ms) */\n\titemTimes: Record<string, number>;\n\t/** Time spent per section identifier (ms) */\n\tsectionTimes: Record<string, number>;\n\t/** Time spent per testPart identifier (ms) */\n\ttestPartTimes: Record<string, number>;\n\t/** Session start timestamp */\n\tstartedAt: number;\n\t/** Current item start time (for tracking) */\n\tcurrentItemStartTime?: number;\n\t/** Current item identifier */\n\tcurrentItemId?: string;\n\t/** Current section identifier */\n\tcurrentSectionId?: string;\n\t/** Current testPart identifier */\n\tcurrentTestPartId?: string;\n\t/** Current testPart start time */\n\tcurrentTestPartStartTime?: number;\n\t/** Is timer currently paused */\n\tisPaused: boolean;\n}\n\n/**\n * The PNP extended-time accommodation: `multiplier` scales a limit (Infinity removes it)\n * and `fixedMinutes`, AfA's `fixed-minutes`, adds to it.\n */\nexport interface ExtendedTime {\n\tactive: boolean;\n\tmultiplier: number;\n\tfixedMinutes?: number;\n}\n\n/** A time limit in seconds under extended time; undefined when the accommodation removes it. */\nexport function extendTimeLimit(seconds: number, extended: ExtendedTime | undefined): number | undefined {\n\tif (!extended?.active) return seconds;\n\tif (extended.multiplier === Infinity) return undefined;\n\tconst scaled = extended.multiplier > 0 ? seconds * extended.multiplier : seconds;\n\tconst fixedMinutes = extended.fixedMinutes;\n\treturn fixedMinutes !== undefined && Number.isFinite(fixedMinutes) && fixedMinutes > 0\n\t\t? scaled + fixedMinutes * 60\n\t\t: scaled;\n}\n\nexport class TimeManager {\n\tprivate config: TimeManagerConfig;\n\tprivate state: TimeTrackingState;\n\n\t// Timer internals\n\tprivate intervalId: ReturnType<typeof setInterval> | null = null;\n\tprivate maxTimeSeconds: number | null = null;\n\tprivate warningTriggered = new Set<string>();\n\tprivate expirationTriggered = new Set<string>();\n\tprivate activeScopes: ActiveTimeScopes = {};\n\t/**\n\t * Sections currently being timed (every enclosing scope), identifier → start (ms).\n\t * Nested sections run alongside each other, so a single \"current section\" start\n\t * cannot hold them; completed segments accumulate into `state.sectionTimes`.\n\t */\n\tprivate readonly sectionStarts = new Map<string, number>();\n\tprivate lastTickAt: number;\n\n\tconstructor(config: TimeManagerConfig) {\n\t\tthis.config = config;\n\t\tthis.state = {\n\t\t\ttotalElapsed: 0,\n\t\t\titemTimes: {},\n\t\t\tsectionTimes: {},\n\t\t\ttestPartTimes: {},\n\t\t\tstartedAt: this.now(),\n\t\t\tisPaused: false,\n\t\t};\n\t\tthis.lastTickAt = this.now();\n\n\t\t// Initialize timer if time limit exists, applying PNP extended-time multiplier if set.\n\t\tif (config.assessmentTimeLimits?.maxTime) {\n\t\t\tthis.maxTimeSeconds = extendTimeLimit(config.assessmentTimeLimits.maxTime, config.extendedTime) ?? null;\n\t\t}\n\t\t// Scope timing is required even when the assessment itself has no maxTime.\n\t\tthis.startTimer();\n\t}\n\n\tprivate now(): number {\n\t\treturn this.config.now?.() ?? Date.now();\n\t}\n\n\tprivate applyExtendedTime(seconds: number | undefined): number | null {\n\t\tif (seconds === undefined) return null;\n\t\treturn extendTimeLimit(seconds, this.config.extendedTime) ?? null;\n\t}\n\n\t/**\n\t * Start or resume the timer\n\t */\n\tprivate startTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\treturn; // Already running\n\t\t}\n\n\t\tthis.state.isPaused = false;\n\t\tthis.lastTickAt = this.now();\n\n\t\tthis.intervalId = setInterval(() => {\n\t\t\tconst now = this.now();\n\t\t\tif (this.state.isPaused) {\n\t\t\t\tthis.lastTickAt = now;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.state.totalElapsed += Math.max(0, now - this.lastTickAt);\n\t\t\tthis.lastTickAt = now;\n\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\t\tconst candidates = this.getActiveCandidates();\n\t\t\tfor (const candidate of candidates) {\n\t\t\t\tif (candidate.remainingSeconds > 0 || this.expirationTriggered.has(candidate.key)) continue;\n\t\t\t\tthis.expirationTriggered.add(candidate.key);\n\t\t\t\tif (!candidate.allowLateSubmission) {\n\t\t\t\t\tconst separator = candidate.key.indexOf(':');\n\t\t\t\t\tif (separator > 0 && this.config.onScopeExpired) {\n\t\t\t\t\t\tconst scope = candidate.key.slice(0, separator) as 'testPart' | 'section' | 'item';\n\t\t\t\t\t\tthis.config.onScopeExpired(scope, candidate.key.slice(separator + 1));\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tthis.handleExpiration();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst activeRemaining = this.nearestRemaining(candidates);\n\t\t\tif (activeRemaining) {\n\t\t\t\tconst { key, remainingSeconds } = activeRemaining;\n\n\t\t\t\t// Trigger each configured warning threshold once, largest first, per scope.\n\t\t\t\tfor (const threshold of this.warningThresholdList()) {\n\t\t\t\t\tconst warningKey = `${key}@${threshold}`;\n\t\t\t\t\tif (this.warningTriggered.has(warningKey)) continue;\n\t\t\t\t\tif (remainingSeconds <= threshold && remainingSeconds > 0) {\n\t\t\t\t\t\tthis.warningTriggered.add(warningKey);\n\t\t\t\t\t\tthis.config.onWarning?.(remainingSeconds);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Tick callback\n\t\t\t\tthis.config.onTick?.(remainingSeconds, elapsedSeconds);\n\t\t\t} else {\n\t\t\t\t// No limit - just count up\n\t\t\t\tthis.config.onTick?.(0, elapsedSeconds);\n\t\t\t}\n\t\t}, 1000);\n\t}\n\n\t/** Every configured warning threshold, deduplicated, largest first. */\n\tprivate warningThresholdList(): number[] {\n\t\treturn [...new Set(this.config.warningThresholds ?? [])].sort((a, b) => b - a);\n\t}\n\n\tprivate getActiveCandidates(): Array<{\n\t\tkey: string;\n\t\tremainingSeconds: number;\n\t\tallowLateSubmission: boolean;\n\t\tscope: NearestTimeLimit['scope'];\n\t\tidentifier?: string;\n\t}> {\n\t\tconst candidates: Array<{\n\t\t\tkey: string;\n\t\t\tremainingSeconds: number;\n\t\t\tallowLateSubmission: boolean;\n\t\t\tscope: NearestTimeLimit['scope'];\n\t\t\tidentifier?: string;\n\t\t}> = [];\n\t\tif (this.maxTimeSeconds !== null) {\n\t\t\tcandidates.push({\n\t\t\t\tkey: 'assessment',\n\t\t\t\tscope: 'assessment',\n\t\t\t\tremainingSeconds: this.maxTimeSeconds - this.getElapsedSeconds(),\n\t\t\t\tallowLateSubmission: this.config.assessmentTimeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\tconst testPart = this.activeScopes.testPart;\n\t\tconst testPartMax = this.applyExtendedTime(testPart?.timeLimits?.maxTime);\n\t\tif (testPart && testPartMax !== null) {\n\t\t\tcandidates.push({\n\t\t\t\tkey: `testPart:${testPart.identifier}`,\n\t\t\t\tscope: 'testPart',\n\t\t\t\tidentifier: testPart.identifier,\n\t\t\t\tremainingSeconds: testPartMax - this.getScopeElapsedMs('testPart', testPart.identifier) / 1000,\n\t\t\t\tallowLateSubmission: testPart.timeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\t// Every enclosing section carries its own limit, outermost included.\n\t\tfor (const section of this.activeSectionScopes()) {\n\t\t\tconst max = this.applyExtendedTime(section.timeLimits?.maxTime);\n\t\t\tif (max === null) continue;\n\t\t\tcandidates.push({\n\t\t\t\tkey: `section:${section.identifier}`,\n\t\t\t\tscope: 'section',\n\t\t\t\tidentifier: section.identifier,\n\t\t\t\tremainingSeconds: max - this.getScopeElapsedMs('section', section.identifier) / 1000,\n\t\t\t\tallowLateSubmission: section.timeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\tconst item = this.activeScopes.item;\n\t\tconst itemMax = this.applyExtendedTime(item?.timeLimits?.maxTime);\n\t\tif (item && itemMax !== null) {\n\t\t\tcandidates.push({\n\t\t\t\tkey: `item:${item.identifier}`,\n\t\t\t\tscope: 'item',\n\t\t\t\tidentifier: item.identifier,\n\t\t\t\tremainingSeconds: itemMax - this.getScopeElapsedMs('item', item.identifier) / 1000,\n\t\t\t\tallowLateSubmission: item.timeLimits?.allowLateSubmission === true,\n\t\t\t});\n\t\t}\n\t\treturn candidates;\n\t}\n\n\tprivate nearestRemaining<T extends { remainingSeconds: number }>(candidates: T[]): T | null {\n\t\tif (candidates.length === 0) return null;\n\t\treturn candidates.reduce((nearest, candidate) =>\n\t\t\tcandidate.remainingSeconds < nearest.remainingSeconds ? candidate : nearest\n\t\t);\n\t}\n\n\t/**\n\t * The active hard maximum that runs out first — the countdown a shell displays — or\n\t * null when nothing limits the current scope.\n\t */\n\tgetNearestLimit(): NearestTimeLimit | null {\n\t\tconst candidates = this.getActiveCandidates();\n\t\tif (candidates.length === 0) return null;\n\t\tconst nearest = this.nearestRemaining(candidates)!;\n\t\treturn {\n\t\t\tscope: nearest.scope,\n\t\t\tidentifier: nearest.identifier,\n\t\t\tremainingSeconds: nearest.remainingSeconds,\n\t\t\tallowLateSubmission: nearest.allowLateSubmission,\n\t\t};\n\t}\n\n\tprivate getActiveRemaining(): { key: string; remainingSeconds: number; allowLateSubmission: boolean } | null {\n\t\treturn this.nearestRemaining(this.getActiveCandidates());\n\t}\n\n\t/**\n\t * Handle time expiration\n\t */\n\tprivate handleExpiration(): void {\n\t\tthis.stopTimer();\n\t\tthis.config.onExpired?.();\n\t}\n\n\t/**\n\t * Stop the timer\n\t */\n\tstopTimer(): void {\n\t\tif (this.intervalId) {\n\t\t\tclearInterval(this.intervalId);\n\t\t\tthis.intervalId = null;\n\t\t}\n\t}\n\n\t/**\n\t * Pause the timer\n\t */\n\tpause(): void {\n\t\tif (this.state.isPaused) return;\n\t\tthis.state.totalElapsed = this.getTotalElapsedMs();\n\t\tthis.lastTickAt = this.now();\n\t\tthis.checkpointActiveScopes(false);\n\t\tthis.state.isPaused = true;\n\t}\n\n\t/**\n\t * Resume the timer\n\t */\n\tresume(): void {\n\t\tif (!this.state.isPaused) return;\n\t\tthis.state.isPaused = false;\n\t\tconst now = this.now();\n\t\tif (this.state.currentItemId) this.state.currentItemStartTime = now;\n\t\tif (this.state.currentTestPartId) this.state.currentTestPartStartTime = now;\n\t\t// Every enclosing section the delivery sits in restarts where it froze.\n\t\tfor (const section of this.activeSectionScopes()) {\n\t\t\tconst start = this.sectionStarts.get(section.identifier);\n\t\t\tif (start === undefined || !Number.isFinite(start)) this.sectionStarts.set(section.identifier, now);\n\t\t}\n\t\tthis.lastTickAt = now;\n\t}\n\n\t/**\n\t * Start tracking time for an item\n\t */\n\tstartItem(itemIdentifier: string): void {\n\t\tif (this.state.currentItemId === itemIdentifier && this.state.currentItemStartTime) return;\n\t\t// End previous item if any\n\t\tif (this.state.currentItemStartTime) {\n\t\t\tthis.endCurrentItem();\n\t\t}\n\n\t\tthis.state.currentItemId = itemIdentifier;\n\t\tthis.state.currentItemStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\t/**\n\t * End tracking time for current item\n\t */\n\tprivate endCurrentItem(): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = this.now() - this.state.currentItemStartTime;\n\t\tif (this.state.currentItemId) {\n\t\t\tthis.state.itemTimes[this.state.currentItemId] =\n\t\t\t\t(this.state.itemTimes[this.state.currentItemId] || 0) + Math.max(0, timeSpent);\n\t\t}\n\t\tthis.state.currentItemStartTime = undefined;\n\t\tthis.state.currentItemId = undefined;\n\t}\n\n\t/**\n\t * End tracking time for an item\n\t */\n\tendItem(itemIdentifier: string): void {\n\t\tif (!this.state.currentItemStartTime) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst timeSpent = this.now() - this.state.currentItemStartTime;\n\t\tconst activeIdentifier = this.state.currentItemId ?? itemIdentifier;\n\t\tthis.state.itemTimes[activeIdentifier] = (this.state.itemTimes[activeIdentifier] || 0) + Math.max(0, timeSpent);\n\t\tthis.state.currentItemStartTime = undefined;\n\t\tthis.state.currentItemId = undefined;\n\t}\n\n\tstartTestPart(testPartIdentifier: string): void {\n\t\tif (this.state.currentTestPartId === testPartIdentifier && this.state.currentTestPartStartTime) return;\n\t\tthis.endCurrentTestPart();\n\t\tthis.state.currentTestPartId = testPartIdentifier;\n\t\tthis.state.currentTestPartStartTime = this.state.isPaused ? undefined : this.now();\n\t}\n\n\t/**\n\t * Enter a new item's scope chain: every enclosing section runs its own clock, so\n\t * entering starts the newly enclosed ones and leaving folds the exited ones into\n\t * their persisted `sectionTimes`. An outer section shared with the previous item\n\t * keeps its running clock.\n\t */\n\tactivateScopes(scopes: ActiveTimeScopes): void {\n\t\tif (scopes.testPart) this.startTestPart(scopes.testPart.identifier);\n\t\tthis.activateSections(this.activeSectionScopes(scopes));\n\t\tif (scopes.item) this.startItem(scopes.item.identifier);\n\t\tthis.activeScopes = scopes;\n\t}\n\n\t/** The enclosing section scopes of an activation, outermost first. */\n\tprivate activeSectionScopes(scopes: ActiveTimeScopes = this.activeScopes): Array<{\n\t\tidentifier: string;\n\t\ttimeLimits?: TimeLimits;\n\t}> {\n\t\tif (scopes.sections) return scopes.sections;\n\t\treturn scopes.section ? [scopes.section] : [];\n\t}\n\n\tprivate activateSections(\n\t\tsections: ReadonlyArray<{ identifier: string; timeLimits?: TimeLimits }>,\n\t): void {\n\t\tconst now = this.now();\n\t\tconst wanted = new Set(sections.map((section) => section.identifier));\n\t\t// Sections delivery left: fold their running time into the persisted clock.\n\t\tfor (const [identifier, start] of this.sectionStarts) {\n\t\t\tif (wanted.has(identifier)) continue;\n\t\t\tconst elapsed = Math.max(0, now - start);\n\t\t\tthis.state.sectionTimes[identifier] = (this.state.sectionTimes[identifier] || 0) + elapsed;\n\t\t\tthis.sectionStarts.delete(identifier);\n\t\t}\n\t\t// Sections delivery entered (or the clocks were checkpointed): start them. While\n\t\t// paused the start is recorded but no elapsed time accrues until resume reseeds.\n\t\tfor (const section of sections) {\n\t\t\tif (this.sectionStarts.has(section.identifier)) continue;\n\t\t\tthis.sectionStarts.set(section.identifier, this.state.isPaused ? Number.NaN : now);\n\t\t}\n\t\t// The innermost section stays the \"current\" one for the persisted snapshot.\n\t\tthis.state.currentSectionId = sections[sections.length - 1]?.identifier;\n\t}\n\n\t/** Fold every running section clock into `sectionTimes` and stop them. */\n\tprivate endRunningSections(): void {\n\t\tconst now = this.now();\n\t\tfor (const [identifier, start] of this.sectionStarts) {\n\t\t\tif (Number.isFinite(start)) {\n\t\t\t\tconst elapsed = Math.max(0, now - start);\n\t\t\t\tthis.state.sectionTimes[identifier] = (this.state.sectionTimes[identifier] || 0) + elapsed;\n\t\t\t}\n\t\t\tthis.sectionStarts.delete(identifier);\n\t\t}\n\t}\n\n\tprivate endCurrentTestPart(): void {\n\t\tif (this.state.currentTestPartId && this.state.currentTestPartStartTime) {\n\t\t\tconst elapsed = Math.max(0, this.now() - this.state.currentTestPartStartTime);\n\t\t\tthis.state.testPartTimes[this.state.currentTestPartId] =\n\t\t\t\t(this.state.testPartTimes[this.state.currentTestPartId] || 0) + elapsed;\n\t\t}\n\t\tthis.state.currentTestPartStartTime = undefined;\n\t}\n\n\tprivate checkpointActiveScopes(restart: boolean): void {\n\t\tconst itemId = this.state.currentItemId;\n\t\tconst sectionId = this.state.currentSectionId;\n\t\tconst testPartId = this.state.currentTestPartId;\n\t\tthis.endCurrentItem();\n\t\tthis.endRunningSections();\n\t\tthis.endCurrentTestPart();\n\t\tthis.state.currentItemId = itemId;\n\t\tthis.state.currentSectionId = sectionId;\n\t\tthis.state.currentTestPartId = testPartId;\n\t\tif (restart && !this.state.isPaused) {\n\t\t\tconst now = this.now();\n\t\t\tif (itemId) this.state.currentItemStartTime = now;\n\t\t\tfor (const section of this.activeSectionScopes()) this.sectionStarts.set(section.identifier, now);\n\t\t\tif (testPartId) this.state.currentTestPartStartTime = now;\n\t\t}\n\t}\n\n\t/**\n\t * Record limits that already ran out — restored from a snapshot's clocks — so the live\n\t * timer never fires their expiry a second time. Keys are `assessment` or\n\t * `scope:identifier` (`testPart:P1`, `section:S1`, `item:I1`).\n\t */\n\tmarkExpired(keys: Iterable<string>): void {\n\t\tfor (const key of keys) this.expirationTriggered.add(key);\n\t}\n\n\t/** Forget the fired expiries, before another snapshot's clocks replace these. */\n\tresetExpiryRecord(): void {\n\t\tthis.expirationTriggered.clear();\n\t}\n\n\t/**\n\t * Get remaining time in seconds (null if no limit)\n\t */\n\tgetRemainingSeconds(): number | null {\n\t\tconst active = this.getActiveRemaining();\n\t\treturn active ? Math.max(0, Math.ceil(active.remainingSeconds)) : null;\n\t}\n\n\t/**\n\t * Remaining seconds on the assessment-level limit only (null when the test has no\n\t * maximum); what a start screen states as \"You have N minutes\".\n\t */\n\tgetAssessmentRemainingSeconds(): number | null {\n\t\tif (this.maxTimeSeconds === null) return null;\n\t\treturn Math.max(0, Math.ceil(this.maxTimeSeconds - this.getElapsedSeconds()));\n\t}\n\n\t/**\n\t * Get elapsed time in seconds\n\t */\n\tgetElapsedSeconds(): number {\n\t\treturn Math.floor(this.getTotalElapsedMs() / 1000);\n\t}\n\n\tprivate getTotalElapsedMs(): number {\n\t\tif (this.state.isPaused) return this.state.totalElapsed;\n\t\treturn this.state.totalElapsed + Math.max(0, this.now() - this.lastTickAt);\n\t}\n\n\t/**\n\t * Get time spent on a specific item (ms)\n\t */\n\tgetItemTime(itemIdentifier: string): number {\n\t\treturn this.getScopeElapsedMs('item', itemIdentifier);\n\t}\n\n\tgetScopeElapsedMs(scope: 'assessment' | 'testPart' | 'section' | 'item', identifier?: string): number {\n\t\tif (scope === 'assessment') return this.getTotalElapsedMs();\n\t\tconst now = this.now();\n\t\tif (scope === 'item') {\n\t\t\tconst id = identifier ?? this.state.currentItemId;\n\t\t\tif (!id) return 0;\n\t\t\tconst active = id === this.state.currentItemId && this.state.currentItemStartTime && !this.state.isPaused\n\t\t\t\t? Math.max(0, now - this.state.currentItemStartTime)\n\t\t\t\t: 0;\n\t\t\treturn (this.state.itemTimes[id] || 0) + active;\n\t\t}\n\t\tif (scope === 'section') {\n\t\t\tconst id = identifier ?? this.state.currentSectionId;\n\t\t\tif (!id) return 0;\n\t\t\tconst start = this.sectionStarts.get(id);\n\t\t\tconst active = start !== undefined && Number.isFinite(start) && !this.state.isPaused\n\t\t\t\t? Math.max(0, now - start)\n\t\t\t\t: 0;\n\t\t\treturn (this.state.sectionTimes[id] || 0) + active;\n\t\t}\n\t\tconst id = identifier ?? this.state.currentTestPartId;\n\t\tif (!id) return 0;\n\t\tconst active = id === this.state.currentTestPartId && this.state.currentTestPartStartTime && !this.state.isPaused\n\t\t\t? Math.max(0, now - this.state.currentTestPartStartTime)\n\t\t\t: 0;\n\t\treturn (this.state.testPartTimes[id] || 0) + active;\n\t}\n\n\t/**\n\t * Get current tracking state (for persistence)\n\t */\n\tgetState(): TimeTrackingState {\n\t\tif (!this.state.isPaused) {\n\t\t\tthis.state.totalElapsed = this.getTotalElapsedMs();\n\t\t\tthis.lastTickAt = this.now();\n\t\t}\n\t\tthis.checkpointActiveScopes(true);\n\t\treturn {\n\t\t\t...this.state,\n\t\t\titemTimes: { ...this.state.itemTimes },\n\t\t\tsectionTimes: { ...this.state.sectionTimes },\n\t\t\ttestPartTimes: { ...this.state.testPartTimes },\n\t\t};\n\t}\n\n\t/**\n\t * Restore tracking state (for resume)\n\t */\n\trestoreState(state: TimeTrackingState): void {\n\t\tthis.state = {\n\t\t\t...state,\n\t\t\titemTimes: { ...state.itemTimes },\n\t\t\tsectionTimes: { ...state.sectionTimes },\n\t\t\ttestPartTimes: { ...(state.testPartTimes ?? {}) },\n\t\t\tcurrentItemStartTime: undefined,\n\t\t\tcurrentTestPartStartTime: undefined,\n\t\t};\n\t\tthis.sectionStarts.clear();\n\t\tif (!this.state.isPaused) {\n\t\t\tconst now = this.now();\n\t\t\tif (this.state.currentItemId) this.state.currentItemStartTime = now;\n\t\t\t// The innermost section restarts at once; the enclosing scopes start when\n\t\t\t// delivery activates them (the restoring navigation follows immediately).\n\t\t\tif (this.state.currentSectionId) this.sectionStarts.set(this.state.currentSectionId, now);\n\t\t\tif (this.state.currentTestPartId) this.state.currentTestPartStartTime = now;\n\t\t\tthis.lastTickAt = now;\n\t\t}\n\n\t\t// Restart timer if not expired\n\t\tif (this.maxTimeSeconds) {\n\t\t\tconst elapsedSeconds = Math.floor(this.state.totalElapsed / 1000);\n\t\t\tif (elapsedSeconds < this.maxTimeSeconds) {\n\t\t\t\tthis.startTimer();\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Check if time has expired\n\t */\n\tisExpired(): boolean {\n\t\tconst active = this.getActiveRemaining();\n\t\treturn active !== null && active.remainingSeconds <= 0;\n\t}\n\n\t/**\n\t * Check if late submission is allowed\n\t */\n\tallowsLateSubmission(): boolean {\n\t\tconst candidates = this.getActiveCandidates();\n\t\tconst expired = candidates.filter((candidate) => candidate.remainingSeconds <= 0);\n\t\tif (expired.length > 0) {\n\t\t\treturn expired.every((candidate) => candidate.allowLateSubmission);\n\t\t}\n\t\treturn this.nearestRemaining(candidates)?.allowLateSubmission ?? false;\n\t}\n\n\t/**\n\t * Cleanup - stop all timers\n\t */\n\tdestroy(): void {\n\t\tthis.checkpointActiveScopes(false);\n\t\tthis.stopTimer();\n\t}\n}\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autosave wiring: the debounced draft snapshot the player persists through
|
|
3
|
+
* `BackendAdapter.saveState`.
|
|
4
|
+
*
|
|
5
|
+
* The engine is `AutosaveManager` (debounce, busy-deferral, bounded backoff,
|
|
6
|
+
* stop semantics). This module owns the player-side defaults: the capability +
|
|
7
|
+
* config decision, the 1500 ms default window, and the snapshot shape — the
|
|
8
|
+
* current session snapshot, with every item session closed when the caller says
|
|
9
|
+
* the snapshot records an ended test, and the save time stamped on the timing.
|
|
10
|
+
*
|
|
11
|
+
* Extracted from `AssessmentPlayer.ts` (pure code motion): the caller supplies
|
|
12
|
+
* the live reads (snapshot, blocked/stopped probes) exactly as before.
|
|
13
|
+
*/
|
|
14
|
+
import type { AssessmentSessionState, BackendAdapter, SessionId } from '../integration/api-contract.js';
|
|
15
|
+
import { AutosaveManager, type AutosaveState } from './AutosaveManager.js';
|
|
16
|
+
export interface SessionAutosaveOptions {
|
|
17
|
+
/** `config.autosave` (off for hosts that persist state themselves). */
|
|
18
|
+
autosave?: boolean;
|
|
19
|
+
/** `config.autosaveIntervalMs` (default 1500). */
|
|
20
|
+
autosaveIntervalMs?: number;
|
|
21
|
+
/** `backend.canSaveState` (a backend that cannot store drafts disables autosave). */
|
|
22
|
+
canSaveState: BackendAdapter['canSaveState'];
|
|
23
|
+
sessionId: SessionId;
|
|
24
|
+
/** The current session snapshot (`getState({ includeItemSessions: true })`). */
|
|
25
|
+
getSnapshot: () => AssessmentSessionState;
|
|
26
|
+
/** True while the snapshot being taken records an ended test (its item sessions are closed). */
|
|
27
|
+
snapshotsCloseItemSessions: () => boolean;
|
|
28
|
+
/** True while a navigation or submission transition is in flight. */
|
|
29
|
+
isBlocked: () => boolean;
|
|
30
|
+
/** True once delivery has ended (finalized or destroyed). */
|
|
31
|
+
isStopped: () => boolean;
|
|
32
|
+
/** `backend.saveState`. */
|
|
33
|
+
saveState: BackendAdapter['saveState'];
|
|
34
|
+
/** Indicator/host state changes. */
|
|
35
|
+
onStateChange: (state: AutosaveState) => void;
|
|
36
|
+
/** Raw failure detail for logs and host callbacks. */
|
|
37
|
+
onError: (error: Error) => void;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The debounced draft persistence, ON by default when the backend reports the save
|
|
41
|
+
* capability (`canSaveState !== false`); `autosave === false` disables it for hosts
|
|
42
|
+
* that persist state themselves. Null when disabled.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createSessionAutosave(options: SessionAutosaveOptions): AutosaveManager | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Autosave wiring: the debounced draft snapshot the player persists through
|
|
3
|
+
* `BackendAdapter.saveState`.
|
|
4
|
+
*
|
|
5
|
+
* The engine is `AutosaveManager` (debounce, busy-deferral, bounded backoff,
|
|
6
|
+
* stop semantics). This module owns the player-side defaults: the capability +
|
|
7
|
+
* config decision, the 1500 ms default window, and the snapshot shape — the
|
|
8
|
+
* current session snapshot, with every item session closed when the caller says
|
|
9
|
+
* the snapshot records an ended test, and the save time stamped on the timing.
|
|
10
|
+
*
|
|
11
|
+
* Extracted from `AssessmentPlayer.ts` (pure code motion): the caller supplies
|
|
12
|
+
* the live reads (snapshot, blocked/stopped probes) exactly as before.
|
|
13
|
+
*/
|
|
14
|
+
import { closedItemSession } from './sessionRecords.js';
|
|
15
|
+
import { AutosaveManager } from './AutosaveManager.js';
|
|
16
|
+
/**
|
|
17
|
+
* The debounced draft persistence, ON by default when the backend reports the save
|
|
18
|
+
* capability (`canSaveState !== false`); `autosave === false` disables it for hosts
|
|
19
|
+
* that persist state themselves. Null when disabled.
|
|
20
|
+
*/
|
|
21
|
+
export function createSessionAutosave(options) {
|
|
22
|
+
const enabled = options.autosave !== false && options.canSaveState !== false;
|
|
23
|
+
if (!enabled)
|
|
24
|
+
return null;
|
|
25
|
+
return new AutosaveManager({
|
|
26
|
+
enabled: true,
|
|
27
|
+
intervalMs: options.autosaveIntervalMs ?? 1500,
|
|
28
|
+
collect: () => {
|
|
29
|
+
const snapshot = options.getSnapshot();
|
|
30
|
+
if (options.snapshotsCloseItemSessions() && snapshot.itemSessions) {
|
|
31
|
+
snapshot.itemSessions = Object.fromEntries(Object.entries(snapshot.itemSessions).map(([identifier, session]) => [
|
|
32
|
+
identifier,
|
|
33
|
+
closedItemSession(session),
|
|
34
|
+
]));
|
|
35
|
+
}
|
|
36
|
+
snapshot.timing = { ...snapshot.timing, savedAt: Date.now() };
|
|
37
|
+
return { sessionId: options.sessionId, state: snapshot };
|
|
38
|
+
},
|
|
39
|
+
save: (request) => options.saveState(request),
|
|
40
|
+
isBlocked: options.isBlocked,
|
|
41
|
+
isStopped: options.isStopped,
|
|
42
|
+
onStateChange: options.onStateChange,
|
|
43
|
+
onError: options.onError,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=autosave.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autosave.js","sourceRoot":"","sources":["../../src/core/autosave.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAsB,MAAM,sBAAsB,CAAC;AA0B3E;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA+B;IACpE,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,KAAK,IAAI,OAAO,CAAC,YAAY,KAAK,KAAK,CAAC;IAC7E,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAC;IAC1B,OAAO,IAAI,eAAe,CAAC;QAC1B,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,OAAO,CAAC,kBAAkB,IAAI,IAAI;QAC9C,OAAO,EAAE,GAAG,EAAE;YACb,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;YACvC,IAAI,OAAO,CAAC,0BAA0B,EAAE,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;gBACnE,QAAQ,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CACzC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,CAAC;oBACpE,UAAU;oBACV,iBAAiB,CAAC,OAAO,CAAC;iBAC1B,CAAC,CACF,CAAC;YACH,CAAC;YACD,QAAQ,CAAC,MAAM,GAAG,EAAE,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YAC9D,OAAO,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;QAC1D,CAAC;QACD,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,OAAgB,CAAC;QACtD,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,OAAO,EAAE,OAAO,CAAC,OAAO;KACxB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Autosave wiring: the debounced draft snapshot the player persists through\n * `BackendAdapter.saveState`.\n *\n * The engine is `AutosaveManager` (debounce, busy-deferral, bounded backoff,\n * stop semantics). This module owns the player-side defaults: the capability +\n * config decision, the 1500 ms default window, and the snapshot shape — the\n * current session snapshot, with every item session closed when the caller says\n * the snapshot records an ended test, and the save time stamped on the timing.\n *\n * Extracted from `AssessmentPlayer.ts` (pure code motion): the caller supplies\n * the live reads (snapshot, blocked/stopped probes) exactly as before.\n */\n\nimport type { AssessmentSessionState, BackendAdapter, SessionId } from '../integration/api-contract.js';\nimport { closedItemSession } from './sessionRecords.js';\nimport { AutosaveManager, type AutosaveState } from './AutosaveManager.js';\n\nexport interface SessionAutosaveOptions {\n\t/** `config.autosave` (off for hosts that persist state themselves). */\n\tautosave?: boolean;\n\t/** `config.autosaveIntervalMs` (default 1500). */\n\tautosaveIntervalMs?: number;\n\t/** `backend.canSaveState` (a backend that cannot store drafts disables autosave). */\n\tcanSaveState: BackendAdapter['canSaveState'];\n\tsessionId: SessionId;\n\t/** The current session snapshot (`getState({ includeItemSessions: true })`). */\n\tgetSnapshot: () => AssessmentSessionState;\n\t/** True while the snapshot being taken records an ended test (its item sessions are closed). */\n\tsnapshotsCloseItemSessions: () => boolean;\n\t/** True while a navigation or submission transition is in flight. */\n\tisBlocked: () => boolean;\n\t/** True once delivery has ended (finalized or destroyed). */\n\tisStopped: () => boolean;\n\t/** `backend.saveState`. */\n\tsaveState: BackendAdapter['saveState'];\n\t/** Indicator/host state changes. */\n\tonStateChange: (state: AutosaveState) => void;\n\t/** Raw failure detail for logs and host callbacks. */\n\tonError: (error: Error) => void;\n}\n\n/**\n * The debounced draft persistence, ON by default when the backend reports the save\n * capability (`canSaveState !== false`); `autosave === false` disables it for hosts\n * that persist state themselves. Null when disabled.\n */\nexport function createSessionAutosave(options: SessionAutosaveOptions): AutosaveManager | null {\n\tconst enabled = options.autosave !== false && options.canSaveState !== false;\n\tif (!enabled) return null;\n\treturn new AutosaveManager({\n\t\tenabled: true,\n\t\tintervalMs: options.autosaveIntervalMs ?? 1500,\n\t\tcollect: () => {\n\t\t\tconst snapshot = options.getSnapshot();\n\t\t\tif (options.snapshotsCloseItemSessions() && snapshot.itemSessions) {\n\t\t\t\tsnapshot.itemSessions = Object.fromEntries(\n\t\t\t\t\tObject.entries(snapshot.itemSessions).map(([identifier, session]) => [\n\t\t\t\t\t\tidentifier,\n\t\t\t\t\t\tclosedItemSession(session),\n\t\t\t\t\t]),\n\t\t\t\t);\n\t\t\t}\n\t\t\tsnapshot.timing = { ...snapshot.timing, savedAt: Date.now() };\n\t\t\treturn { sessionId: options.sessionId, state: snapshot };\n\t\t},\n\t\tsave: (request) => options.saveState(request as never),\n\t\tisBlocked: options.isBlocked,\n\t\tisStopped: options.isStopped,\n\t\tonStateChange: options.onStateChange,\n\t\tonError: options.onError,\n\t});\n}\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delivery structure: the assessment flattened into delivered items with
|
|
3
|
+
* their enclosing scopes, and the candidate-facing section list.
|
|
4
|
+
*
|
|
5
|
+
* Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions
|
|
6
|
+
* over the parsed assessment, no lock, no session state. `FlatItem` is the
|
|
7
|
+
* orchestrator's unit of delivery — every policy module reads it.
|
|
8
|
+
*/
|
|
9
|
+
import type { SecureAssessment, SecureItemRef, SecureSection, SecureTestPart } from '../integration/api-contract.js';
|
|
10
|
+
export type FlatItem = {
|
|
11
|
+
identifier: string;
|
|
12
|
+
item: SecureItemRef;
|
|
13
|
+
/** Innermost enclosing section. */
|
|
14
|
+
section: SecureSection;
|
|
15
|
+
/** Enclosing sections, outermost first. */
|
|
16
|
+
sections: SecureSection[];
|
|
17
|
+
/** Outermost enclosing section the candidate is actually shown (QTI visible="false" merges content into the parent). */
|
|
18
|
+
presentedSection: SecureSection | undefined;
|
|
19
|
+
testPart: SecureTestPart;
|
|
20
|
+
index: number;
|
|
21
|
+
/** Index of `presentedSection` in the candidate-facing section list; -1 when none is visible. */
|
|
22
|
+
sectionIndex: number;
|
|
23
|
+
};
|
|
24
|
+
export type CurrentItemView = {
|
|
25
|
+
identifier: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
required?: boolean;
|
|
28
|
+
itemXml: string;
|
|
29
|
+
deliveryContext?: SecureItemRef['deliveryContext'];
|
|
30
|
+
};
|
|
31
|
+
export type SectionItemRefView = {
|
|
32
|
+
identifier: string;
|
|
33
|
+
href?: string;
|
|
34
|
+
title?: string;
|
|
35
|
+
itemXml: string;
|
|
36
|
+
deliveryContext?: SecureItemRef['deliveryContext'];
|
|
37
|
+
};
|
|
38
|
+
/** What the presentation of an item session shows: QTI showFeedback / showSolution, resolved. */
|
|
39
|
+
export type PresentationPolicy = {
|
|
40
|
+
showFeedback: boolean;
|
|
41
|
+
showSolution: boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare function flattenItems(assessment: SecureAssessment): FlatItem[];
|
|
44
|
+
/**
|
|
45
|
+
* Sections presented to the candidate: visible themselves and under visible ancestors.
|
|
46
|
+
* A QTI `visible="false"` section is not presented as a section — its content appears as
|
|
47
|
+
* part of the parent — so neither it nor its descendants surface a title here. Items
|
|
48
|
+
* inside keep being delivered in order.
|
|
49
|
+
*/
|
|
50
|
+
export declare function presentedSections(assessment: SecureAssessment): SecureSection[];
|
|
51
|
+
/** Outermost enclosing section of an item that the candidate is shown, if any. */
|
|
52
|
+
export declare function presentedSectionOf(sections: readonly SecureSection[]): SecureSection | undefined;
|
|
53
|
+
/** Delivery order of the item's test part (parts are delivered in sequence). */
|
|
54
|
+
export declare function partOrderOf(assessment: SecureAssessment, q: FlatItem | undefined): number;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delivery structure: the assessment flattened into delivered items with
|
|
3
|
+
* their enclosing scopes, and the candidate-facing section list.
|
|
4
|
+
*
|
|
5
|
+
* Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions
|
|
6
|
+
* over the parsed assessment, no lock, no session state. `FlatItem` is the
|
|
7
|
+
* orchestrator's unit of delivery — every policy module reads it.
|
|
8
|
+
*/
|
|
9
|
+
import { deliveredItems, sectionComponents } from './testStructure.js';
|
|
10
|
+
export function flattenItems(assessment) {
|
|
11
|
+
const sectionIndexes = new Map(presentedSections(assessment).map((section, index) => [section.identifier, index]));
|
|
12
|
+
return deliveredItems(assessment).map(({ item, testPart, sections }, index) => {
|
|
13
|
+
const section = sections[sections.length - 1];
|
|
14
|
+
const presentedSection = presentedSectionOf(sections);
|
|
15
|
+
return {
|
|
16
|
+
identifier: item.identifier,
|
|
17
|
+
item,
|
|
18
|
+
section,
|
|
19
|
+
sections,
|
|
20
|
+
presentedSection,
|
|
21
|
+
testPart,
|
|
22
|
+
index,
|
|
23
|
+
sectionIndex: presentedSection ? (sectionIndexes.get(presentedSection.identifier) ?? -1) : -1,
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Sections presented to the candidate: visible themselves and under visible ancestors.
|
|
29
|
+
* A QTI `visible="false"` section is not presented as a section — its content appears as
|
|
30
|
+
* part of the parent — so neither it nor its descendants surface a title here. Items
|
|
31
|
+
* inside keep being delivered in order.
|
|
32
|
+
*/
|
|
33
|
+
export function presentedSections(assessment) {
|
|
34
|
+
const out = [];
|
|
35
|
+
const seen = new Set();
|
|
36
|
+
const visit = (section, underInvisible) => {
|
|
37
|
+
const hidden = underInvisible || section.visible === false;
|
|
38
|
+
if (!hidden && !seen.has(section.identifier)) {
|
|
39
|
+
seen.add(section.identifier);
|
|
40
|
+
out.push(section);
|
|
41
|
+
}
|
|
42
|
+
for (const component of sectionComponents(section)) {
|
|
43
|
+
if (component.type === 'section')
|
|
44
|
+
visit(component.section, hidden);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
for (const tp of assessment.testParts || []) {
|
|
48
|
+
for (const section of tp.sections || [])
|
|
49
|
+
visit(section, false);
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
/** Outermost enclosing section of an item that the candidate is shown, if any. */
|
|
54
|
+
export function presentedSectionOf(sections) {
|
|
55
|
+
let underInvisible = false;
|
|
56
|
+
for (const section of sections) {
|
|
57
|
+
if (section.visible === false) {
|
|
58
|
+
underInvisible = true;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (!underInvisible)
|
|
62
|
+
return section;
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
/** Delivery order of the item's test part (parts are delivered in sequence). */
|
|
67
|
+
export function partOrderOf(assessment, q) {
|
|
68
|
+
if (!q)
|
|
69
|
+
return 0;
|
|
70
|
+
return (assessment.testParts ?? []).findIndex((part) => part.identifier === q.testPart.identifier);
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=deliveryStructure.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deliveryStructure.js","sourceRoot":"","sources":["../../src/core/deliveryStructure.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAoCvE,MAAM,UAAU,YAAY,CAAC,UAA4B;IACxD,MAAM,cAAc,GAAG,IAAI,GAAG,CAC7B,iBAAiB,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAClF,CAAC;IACF,OAAO,cAAc,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE;QAC7E,MAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9C,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtD,OAAO;YACN,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI;YACJ,OAAO;YACP,QAAQ;YACR,gBAAgB;YAChB,QAAQ;YACR,KAAK;YACL,YAAY,EAAE,gBAAgB,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;SAC7F,CAAC;IACH,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,UAA4B;IAC7D,MAAM,GAAG,GAAoB,EAAE,CAAC;IAChC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;I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CAAC;IACjB,OAAO,CAAC,UAAU,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,KAAK,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AACpG,CAAC","sourcesContent":["/**\n * The delivery structure: the assessment flattened into delivered items with\n * their enclosing scopes, and the candidate-facing section list.\n *\n * Moved out of `AssessmentPlayer.ts` verbatim (pure code motion): pure functions\n * over the parsed assessment, no lock, no session state. `FlatItem` is the\n * orchestrator's unit of delivery — every policy module reads it.\n */\n\nimport type {\n\tSecureAssessment,\n\tSecureItemRef,\n\tSecureSection,\n\tSecureTestPart,\n} from '../integration/api-contract.js';\nimport { deliveredItems, sectionComponents } from './testStructure.js';\n\nexport type FlatItem = {\n\tidentifier: string;\n\titem: SecureItemRef;\n\t/** Innermost enclosing section. */\n\tsection: SecureSection;\n\t/** Enclosing sections, outermost first. */\n\tsections: SecureSection[];\n\t/** Outermost enclosing section the candidate is actually shown (QTI visible=\"false\" merges content into the parent). */\n\tpresentedSection: SecureSection | undefined;\n\ttestPart: SecureTestPart;\n\tindex: number;\n\t/** Index of `presentedSection` in the candidate-facing section list; -1 when none is visible. */\n\tsectionIndex: number;\n};\n\nexport type CurrentItemView = {\n\tidentifier: string;\n\ttitle?: string;\n\trequired?: boolean;\n\titemXml: string;\n\tdeliveryContext?: SecureItemRef['deliveryContext'];\n};\n\nexport type SectionItemRefView = {\n\tidentifier: string;\n\thref?: string;\n\ttitle?: string;\n\titemXml: string;\n\tdeliveryContext?: SecureItemRef['deliveryContext'];\n};\n\n/** What the presentation of an item session shows: QTI showFeedback / showSolution, resolved. */\nexport type PresentationPolicy = { showFeedback: boolean; showSolution: boolean };\n\nexport function flattenItems(assessment: SecureAssessment): FlatItem[] {\n\tconst sectionIndexes = new Map(\n\t\tpresentedSections(assessment).map((section, index) => [section.identifier, index]),\n\t);\n\treturn deliveredItems(assessment).map(({ item, testPart, sections }, index) => {\n\t\tconst section = sections[sections.length - 1];\n\t\tconst presentedSection = presentedSectionOf(sections);\n\t\treturn {\n\t\t\tidentifier: item.identifier,\n\t\t\titem,\n\t\t\tsection,\n\t\t\tsections,\n\t\t\tpresentedSection,\n\t\t\ttestPart,\n\t\t\tindex,\n\t\t\tsectionIndex: presentedSection ? (sectionIndexes.get(presentedSection.identifier) ?? -1) : -1,\n\t\t};\n\t});\n}\n\n/**\n * Sections presented to the candidate: visible themselves and under visible ancestors.\n * A QTI `visible=\"false\"` section is not presented as a section — its content appears as\n * part of the parent — so neither it nor its descendants surface a title here. Items\n * inside keep being delivered in order.\n */\nexport function presentedSections(assessment: SecureAssessment): SecureSection[] {\n\tconst out: SecureSection[] = [];\n\tconst seen = new Set<string>();\n\tconst visit = (section: SecureSection, underInvisible: boolean): void => {\n\t\tconst hidden = underInvisible || section.visible === false;\n\t\tif (!hidden && !seen.has(section.identifier)) {\n\t\t\tseen.add(section.identifier);\n\t\t\tout.push(section);\n\t\t}\n\t\tfor (const component of sectionComponents(section)) {\n\t\t\tif (component.type === 'section') visit(component.section, hidden);\n\t\t}\n\t};\n\tfor (const tp of assessment.testParts || []) {\n\t\tfor (const section of tp.sections || []) visit(section, false);\n\t}\n\treturn out;\n}\n\n/** Outermost enclosing section of an item that the candidate is shown, if any. */\nexport function presentedSectionOf(sections: readonly SecureSection[]): SecureSection | undefined {\n\tlet underInvisible = false;\n\tfor (const section of sections) {\n\t\tif (section.visible === false) {\n\t\t\tunderInvisible = true;\n\t\t\tcontinue;\n\t\t}\n\t\tif (!underInvisible) return section;\n\t}\n\treturn undefined;\n}\n\n/** Delivery order of the item's test part (parts are delivered in sequence). */\nexport function partOrderOf(assessment: SecureAssessment, q: FlatItem | undefined): number {\n\tif (!q) return 0;\n\treturn (assessment.testParts ?? []).findIndex((part) => part.identifier === q.testPart.identifier);\n}\n"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coded errors thrown by the assessment player core.
|
|
3
|
+
*
|
|
4
|
+
* The core must never surface raw English or backend strings to candidates: every
|
|
5
|
+
* candidate-visible failure carries a stable `code` that shells localize through
|
|
6
|
+
* `@pie-qti/i18n` under `assessment.errors.codes.<code>`. The original message is
|
|
7
|
+
* preserved on the Error itself for logs and host callbacks.
|
|
8
|
+
*/
|
|
9
|
+
/** Stable machine-readable failure codes. Never rename a code; shells key translations on it. */
|
|
10
|
+
export type AssessmentPlayerErrorCode =
|
|
11
|
+
/** A navigation index or section identifier does not resolve to a deliverable item. */
|
|
12
|
+
'invalidNavigationTarget'
|
|
13
|
+
/** Linear navigation mode only permits moving to the next item. */
|
|
14
|
+
| 'linearNavigationOnly'
|
|
15
|
+
/** The requested jump is not legal for the current navigation mode or test state. */
|
|
16
|
+
| 'navigationNotAllowed'
|
|
17
|
+
/** A navigation or submission transition is already in flight. */
|
|
18
|
+
| 'navigationInFlight'
|
|
19
|
+
/** The assessment has already been finalized; navigation is closed. */
|
|
20
|
+
| 'testFinalized'
|
|
21
|
+
/** A scoped minimum time has not elapsed. */
|
|
22
|
+
| 'minTimeNotElapsed'
|
|
23
|
+
/** The target item is locked because its time limit expired. */
|
|
24
|
+
| 'itemTimeExpired'
|
|
25
|
+
/** The item was submitted and its session control forbids review. */
|
|
26
|
+
| 'reviewNotAllowed'
|
|
27
|
+
/** The item must be answered before navigation away is allowed. */
|
|
28
|
+
| 'responseRequired'
|
|
29
|
+
/**
|
|
30
|
+
* Ending the test was refused: items in individual parts that do not allow skipping
|
|
31
|
+
* still have no response (`params.items` lists their numbers).
|
|
32
|
+
*/
|
|
33
|
+
| 'finalizeResponseRequired'
|
|
34
|
+
/**
|
|
35
|
+
* Ending the test was refused: items in individual parts that validate responses
|
|
36
|
+
* hold responses that do not satisfy their interactions (`params.items`).
|
|
37
|
+
*/
|
|
38
|
+
| 'finalizeResponseInvalid'
|
|
39
|
+
/**
|
|
40
|
+
* Leaving an individual test part was refused (a left part cannot be re-entered):
|
|
41
|
+
* questions in the part that do not allow skipping still have no response
|
|
42
|
+
* (`params.items` lists their numbers).
|
|
43
|
+
*/
|
|
44
|
+
| 'leavePartResponseRequired'
|
|
45
|
+
/**
|
|
46
|
+
* Leaving an individual test part was refused: questions in the part that validate
|
|
47
|
+
* responses hold responses that do not satisfy their interactions (`params.items`).
|
|
48
|
+
*/
|
|
49
|
+
| 'leavePartResponseInvalid'
|
|
50
|
+
/** Ending the attempt failed response validation. */
|
|
51
|
+
| 'attemptValidationFailed'
|
|
52
|
+
/** The item's maxAttempts are used up; no further attempt can be submitted. */
|
|
53
|
+
| 'maxAttemptsReached'
|
|
54
|
+
/** The item session lifecycle forbids response updates. */
|
|
55
|
+
| 'itemSessionLocked'
|
|
56
|
+
/** The item's session control forbids candidate comments. */
|
|
57
|
+
| 'commentsNotAllowed'
|
|
58
|
+
/** The backend rejected a response submission. */
|
|
59
|
+
| 'submitFailed'
|
|
60
|
+
/** The backend failed to finalize the assessment. */
|
|
61
|
+
| 'finalizeFailed'
|
|
62
|
+
/** A proctor (or the host) paused the assessment; candidate actions are unavailable. */
|
|
63
|
+
| 'assessmentPaused'
|
|
64
|
+
/** Test-level outcome processing failed on the backend. */
|
|
65
|
+
| 'outcomeProcessingFailed'
|
|
66
|
+
/**
|
|
67
|
+
* A test-scope branch rule or preCondition could not be evaluated (it failed to parse
|
|
68
|
+
* or evaluate). Delivery proceeds on the default path (the rule reads as false) and the
|
|
69
|
+
* host is informed, so a broken rule is never indistinguishable from an authored false.
|
|
70
|
+
*/
|
|
71
|
+
| 'testConditionFailed'
|
|
72
|
+
/** Item response processing failed; the item scores 0 and delivery continues. */
|
|
73
|
+
| 'itemScoringFailed'
|
|
74
|
+
/** Anything else: shells show a generic localized message plus a support code. */
|
|
75
|
+
| 'unexpected';
|
|
76
|
+
/** Parameters interpolated into the localized message for a coded error. */
|
|
77
|
+
export type AssessmentPlayerErrorParams = Record<string, string | number>;
|
|
78
|
+
/**
|
|
79
|
+
* Error thrown (or returned as a typed rejection) by the assessment player core.
|
|
80
|
+
*
|
|
81
|
+
* `message` keeps the original, developer-facing text (including raw backend error
|
|
82
|
+
* strings) for logs and host callbacks; `code` and `params` drive the localized,
|
|
83
|
+
* candidate-safe rendering in the shell. Recognize one with `isAssessmentPlayerError`,
|
|
84
|
+
* not `instanceof`, which fails for an error made by another copy of the package.
|
|
85
|
+
*/
|
|
86
|
+
export declare class AssessmentPlayerError extends Error {
|
|
87
|
+
readonly code: AssessmentPlayerErrorCode;
|
|
88
|
+
readonly params: AssessmentPlayerErrorParams;
|
|
89
|
+
readonly originalError?: unknown;
|
|
90
|
+
constructor(code: AssessmentPlayerErrorCode, message: string, params?: AssessmentPlayerErrorParams, options?: {
|
|
91
|
+
cause?: unknown;
|
|
92
|
+
});
|
|
93
|
+
/** i18n key the shell renders this error through (`assessment.errors.codes.*`). */
|
|
94
|
+
get i18nKey(): string;
|
|
95
|
+
}
|
|
96
|
+
/** True for an `AssessmentPlayerError` from any copy of this package. */
|
|
97
|
+
export declare function isAssessmentPlayerError(error: unknown): error is AssessmentPlayerError;
|
|
98
|
+
/**
|
|
99
|
+
* The coded refusals that name questions still needing an answer (or a complete one):
|
|
100
|
+
* the end of the test, or leaving an individual test part. They are warnings the
|
|
101
|
+
* candidate resolves by answering, never failures to retry.
|
|
102
|
+
*/
|
|
103
|
+
export declare function isSubmissionBlockedError(error: unknown): error is AssessmentPlayerError;
|
|
104
|
+
/**
|
|
105
|
+
* Candidate-safe rendering plan for any error the core (or a backend) produced.
|
|
106
|
+
*
|
|
107
|
+
* `i18nKey`/`params` resolve to a friendly localized message; `supportCode` is a
|
|
108
|
+
* short stable code the shell may append so hosts can correlate reports without
|
|
109
|
+
* ever showing raw backend messages to candidates.
|
|
110
|
+
*/
|
|
111
|
+
export interface AssessmentErrorDisplay {
|
|
112
|
+
i18nKey: string;
|
|
113
|
+
params: AssessmentPlayerErrorParams;
|
|
114
|
+
supportCode: string;
|
|
115
|
+
}
|
|
116
|
+
export declare function assessmentErrorDisplay(error: unknown): AssessmentErrorDisplay;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coded errors thrown by the assessment player core.
|
|
3
|
+
*
|
|
4
|
+
* The core must never surface raw English or backend strings to candidates: every
|
|
5
|
+
* candidate-visible failure carries a stable `code` that shells localize through
|
|
6
|
+
* `@pie-qti/i18n` under `assessment.errors.codes.<code>`. The original message is
|
|
7
|
+
* preserved on the Error itself for logs and host callbacks.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Brand on every `AssessmentPlayerError`, which `isAssessmentPlayerError` checks instead of
|
|
11
|
+
* `instanceof`: an error often crosses copies of this module (the player-elements bundle
|
|
12
|
+
* carries its own; a host may load this package beside it), and `Symbol.for` gives every
|
|
13
|
+
* copy the same symbol.
|
|
14
|
+
*/
|
|
15
|
+
const ASSESSMENT_PLAYER_ERROR_BRAND = Symbol.for('pie-qti.AssessmentPlayerError');
|
|
16
|
+
/**
|
|
17
|
+
* Error thrown (or returned as a typed rejection) by the assessment player core.
|
|
18
|
+
*
|
|
19
|
+
* `message` keeps the original, developer-facing text (including raw backend error
|
|
20
|
+
* strings) for logs and host callbacks; `code` and `params` drive the localized,
|
|
21
|
+
* candidate-safe rendering in the shell. Recognize one with `isAssessmentPlayerError`,
|
|
22
|
+
* not `instanceof`, which fails for an error made by another copy of the package.
|
|
23
|
+
*/
|
|
24
|
+
export class AssessmentPlayerError extends Error {
|
|
25
|
+
constructor(code, message, params = {}, options) {
|
|
26
|
+
// No ErrorOptions argument: svelte-check's lib config predates ES2022 Error cause.
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = 'AssessmentPlayerError';
|
|
29
|
+
this.code = code;
|
|
30
|
+
this.params = params;
|
|
31
|
+
this.originalError = options?.cause;
|
|
32
|
+
Object.defineProperty(this, ASSESSMENT_PLAYER_ERROR_BRAND, { value: true });
|
|
33
|
+
}
|
|
34
|
+
/** i18n key the shell renders this error through (`assessment.errors.codes.*`). */
|
|
35
|
+
get i18nKey() {
|
|
36
|
+
return `assessment.errors.codes.${this.code}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** True for an `AssessmentPlayerError` from any copy of this package. */
|
|
40
|
+
export function isAssessmentPlayerError(error) {
|
|
41
|
+
return (typeof error === 'object' &&
|
|
42
|
+
error !== null &&
|
|
43
|
+
error[ASSESSMENT_PLAYER_ERROR_BRAND] === true);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The coded refusals that name questions still needing an answer (or a complete one):
|
|
47
|
+
* the end of the test, or leaving an individual test part. They are warnings the
|
|
48
|
+
* candidate resolves by answering, never failures to retry.
|
|
49
|
+
*/
|
|
50
|
+
export function isSubmissionBlockedError(error) {
|
|
51
|
+
return (isAssessmentPlayerError(error) &&
|
|
52
|
+
(error.code === 'finalizeResponseRequired' ||
|
|
53
|
+
error.code === 'finalizeResponseInvalid' ||
|
|
54
|
+
error.code === 'leavePartResponseRequired' ||
|
|
55
|
+
error.code === 'leavePartResponseInvalid'));
|
|
56
|
+
}
|
|
57
|
+
/** Deterministic short support code for an arbitrary (non-coded) error message. */
|
|
58
|
+
function shortSupportCode(message) {
|
|
59
|
+
let hash = 0;
|
|
60
|
+
const source = message.slice(0, 256);
|
|
61
|
+
for (let i = 0; i < source.length; i++) {
|
|
62
|
+
hash = (hash * 31 + source.charCodeAt(i)) >>> 0;
|
|
63
|
+
}
|
|
64
|
+
return `E-${hash.toString(36).toUpperCase().padStart(6, '0').slice(-6)}`;
|
|
65
|
+
}
|
|
66
|
+
export function assessmentErrorDisplay(error) {
|
|
67
|
+
if (isAssessmentPlayerError(error)) {
|
|
68
|
+
return { i18nKey: error.i18nKey, params: error.params, supportCode: error.code };
|
|
69
|
+
}
|
|
70
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
71
|
+
return {
|
|
72
|
+
i18nKey: 'assessment.errors.unexpected',
|
|
73
|
+
params: {},
|
|
74
|
+
supportCode: shortSupportCode(message),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=errors.js.map
|