Initial push, working on test cases

This commit is contained in:
Jonathan Putney
2019-11-10 12:29:43 -05:00
parent 377d9f977a
commit da4af1edba
18 changed files with 9571 additions and 0 deletions

120
src/cmi/aicc_cmi.js Normal file
View File

@@ -0,0 +1,120 @@
/*
* Copyright (C) Noverant, Inc - All Rights Reserved Unauthorized copying of this file, via any
* medium is strictly prohibited Proprietary and confidential
*/
import * as Scorm12CMI from './scorm12_cmi';
import {BaseCMI, CMIArray, CMIScore} from "./common";
import {aicc_constants} from "../constants";
import {aicc_regex} from "../regex";
const constants = aicc_constants;
const regex = aicc_regex;
export class CMI extends Scorm12CMI.CMI {
constructor(API) {
super(API, constants.cmi_children, new AICCCMIStudentData(API));
this.evaluation = new CMIEvaluation(API);
}
}
class CMIEvaluation extends BaseCMI {
constructor(API) {
super(API);
}
comments = new class extends CMIArray {
constructor(API) {
super(API, constants.comments_children, 402);
}
};
}
class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
constructor(API) {
super(API, constants.student_data_children);
}
#tries_during_lesson = "";
get tries_during_lesson() { return this.#tries_during_lesson; }
set tries_during_lesson(tries_during_lesson) { this.API.isNotInitialized() ? this.#tries_during_lesson = tries_during_lesson : this.throwReadOnlyError() }
tries = new class extends CMIArray {
constructor(API) {
super(API, aicc_constants.tries_children);
}
};
}
export class CMITriesObject extends BaseCMI {
constructor(API) {
super(API);
}
#status = "";
#time = "";
get status() { return this.#status; }
set status(status) {
if(this.API.checkValidFormat(status, regex.CMIStatus2)) {
this.#status = status;
}
}
get time() { return this.#time; }
set time(time) {
if(this.API.checkValidFormat(time, regex.CMITime)) {
this.#time = time;
}
}
score = new CMIScore(API);
}
export class CMIEvaluationCommentsObject extends BaseCMI {
constructor(API) {
super(API);
}
#content = "";
#location = "";
#time = "";
get content() { return this.#content; }
set content(content) {
if(this.API.checkValidFormat(content, regex.CMIString256)) {
this.#content = content;
}
}
get location() { return this.#location; }
set location(location) {
if(this.API.checkValidFormat(location, regex.CMIString256)) {
this.#location = location;
}
}
get time() { return this.#time; }
set time(time) {
if(this.API.checkValidFormat(time, regex.CMITime)) {
this.#time = time;
}
}
}
export class NAV extends BaseCMI {
constructor(API) {
super(API);
}
#event = "";
get event() { return (!this.jsonString) ? this.API.throwSCORMError(404) : this.#event; }
set event(event) {
if(this.API.checkValidFormat(event, regex.NAVEvent)) {
this.#event = event;
}
}
}

95
src/cmi/common.js Normal file
View File

@@ -0,0 +1,95 @@
/*
* Copyright (C) Noverant, Inc - All Rights Reserved Unauthorized copying of this file, via any
* medium is strictly prohibited Proprietary and confidential
*/
import {scorm12_constants, scorm12_error_codes} from "../constants";
export class BaseCMI {
jsonString = false;
API;
constructor(API: any) {
this.API = API;
}
}
export class CMIScore extends BaseCMI {
constructor(API, score_children?, score_range?, invalidErrorCode) {
super(API);
this.#_children = score_children? score_children : scorm12_constants.score_children;
this.#_score_range = score_range? score_range : false;
this.#_invalid_error_code = invalidErrorCode ? invalidErrorCode : scorm12_error_codes.INVALID_SET_VALUE;
}
#_children;
#_score_range;
#_invalid_error_code;
#raw = "";
#min = "";
#max = "100";
get _children() { return this.#_children; }
set _children(_children) { this.API.throwSCORMError(this.#_invalid_error_code); }
get raw() { return this.#raw; }
set raw(raw) {
if(this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal)
&& (!this.#_score_range || this.API.checkValidRange(raw, this.#_score_range))) {
this.#raw = raw;
}
}
get min() { return this.#min; }
set min(min) {
if(this.API.checkValidFormat(min, scorm12_constants.CMIDecimal)
&& (!this.#_score_range || this.API.checkValidRange(min, this.#_score_range))) {
this.#min = min;
}
}
get max() { return this.#max; }
set max(max) {
if(this.API.checkValidFormat(max, scorm12_constants.CMIDecimal)
&& (!this.#_score_range || this.API.checkValidRange(max, this.#_score_range))) {
this.#max = max;
}
}
toJSON = () => {
return {
'raw': this.raw,
'min': this.min,
'max': this.max
}
}
}
export class CMIArray extends BaseCMI {
constructor({API, children, errorCode}) {
super(API);
this.#_children = children;
this.#errorCode = errorCode;
this.childArray = [];
}
#errorCode;
#_children;
get _children() { return this.#_children; }
set _children(_children) { this.API.throwSCORMError(this.#errorCode); }
get _count() { return this.childArray.length; }
set _count(_count) { this.API.throwSCORMError(this.#errorCode); }
toJSON = () => {
this.jsonString = true;
let result = {};
for(let i = 0; i < this.childArray.length; i++) {
result[i + ''] = this.childArray[i];
}
delete this.jsonString;
return result;
}
}

467
src/cmi/scorm12_cmi.js Normal file
View File

@@ -0,0 +1,467 @@
/*
* Copyright (C) Noverant, Inc - All Rights Reserved Unauthorized copying of this file, via any
* medium is strictly prohibited Proprietary and confidential
*/
import {BaseCMI, CMIArray, CMIScore} from './common';
import {scorm12_constants, scorm12_error_codes} from "../constants";
import {scorm12_regex} from "../regex";
const constants = scorm12_constants;
const regex = scorm12_regex;
function throwReadOnlyError(API) {
API.throwSCORMError(scorm12_error_codes.READ_ONLY_ELEMENT);
}
function throwWriteOnlyError(API) {
API.throwSCORMError(scorm12_error_codes.WRITE_ONLY_ELEMENT);
}
function throwInvalidValueError(API) {
API.throwSCORMError(scorm12_error_codes.INVALID_SET_VALUE);
}
export class CMI extends BaseCMI {
#_children = "";
#_version = "3.4";
#suspend_data = "";
#launch_data = "";
#comments = "";
#comments_from_lms = "";
student_data = null;
constructor(API, cmi_children, student_data) {
super(API);
this.#_children = cmi_children ? cmi_children : constants.cmi_children;
this.core = new CMICore(API);
this.objectives = new CMIObjectives(API);
this.student_data = student_data ? student_data : new CMIStudentData(API);
this.student_preference = new CMIStudentPreference(API);
this.interactions = new CMIInteractions(API);
}
toJSON = () => {
this.jsonString = true;
const result = {
'suspend_data': this.suspend_data,
'launch_data': this.launch_data,
'comments': this.comments,
'comments_from_lms': this.comments_from_lms,
'core': this.core,
'objectives': this.objectives,
'student_data': this.student_data,
'student_preference': this.student_preference,
'interactions': this.interactions
};
delete this.jsonString;
return result;
};
get _version() { return this.#_version; }
set _version(_version) { throwInvalidValueError(this.API); }
get _children() { return this.#_children; }
set _children(_children) { throwInvalidValueError(this.API); }
get suspend_data() { return this.#suspend_data; }
set suspend_data(suspend_data) {
if(this.API.checkValidFormat(suspend_data, regex.CMIString4096)) {
this.#suspend_data = suspend_data;
}
}
get launch_data() { return this.#launch_data; }
set launch_data(launch_data) { this.API.isNotInitialized() ? this.#launch_data = launch_data : throwReadOnlyError(this.API); }
get comments() { return this.#comments; }
set comments(comments) {
if(this.API.checkValidFormat(comments, regex.CMIString4096)) {
this.#comments = comments;
}
}
get comments_from_lms() { return this.#comments_from_lms; }
set comments_from_lms(comments_from_lms) { this.API.isNotInitialized() ? this.#comments_from_lms = comments_from_lms : throwReadOnlyError(this.API); }
}
class CMICore extends BaseCMI {
constructor(API) {
super(API);
this.score = new CMIScore(API, constants.score_children, regex.score_range);
}
#_children = constants.core_children;
#student_id = "";
#student_name = "";
#lesson_location = "";
#credit = "";
#lesson_status = "";
#entry = "";
#total_time = "";
#lesson_mode = "normal";
#exit = "";
#session_time = "00:00:00";
get _children() { return this.#_children; }
set _children(_children) { throwInvalidValueError(this.API); }
get student_id() { return this.#student_id; }
set student_id(student_id) { this.API.isNotInitialized() ? this.#student_id = student_id : throwReadOnlyError(this.API); }
get student_name() { return this.#student_name; }
set student_name(student_name) { this.API.isNotInitialized() ? this.#student_name = student_name : throwReadOnlyError(this.API); }
get lesson_location() { return this.#lesson_location; }
set lesson_location(lesson_location) {
if(this.API.checkValidFormat(lesson_location, regex.CMIString256)) {
this.#lesson_location = lesson_location;
}
}
get credit() { return this.#credit; }
set credit(credit) { this.API.isNotInitialized() ? this.#credit = credit : throwReadOnlyError(this.API); }
get lesson_status() { return this.#lesson_status; }
set lesson_status(lesson_status) {
if(this.API.checkValidFormat(lesson_status, regex.CMIStatus)) {
this.#lesson_status = lesson_status;
}
}
get entry() { return this.#entry; }
set entry(entry) { this.API.isNotInitialized() ? this.#entry = entry : throwReadOnlyError(this.API); }
get total_time() { return this.#total_time; }
set total_time(total_time) { this.API.isNotInitialized() ? this.#total_time = total_time : throwReadOnlyError(this.API); }
get lesson_mode() { return this.#lesson_mode; }
set lesson_mode(lesson_mode) { this.API.isNotInitialized() ? this.#lesson_mode = lesson_mode : throwReadOnlyError(this.API); }
get exit() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#exit; }
set exit(exit) {
if(this.API.checkValidFormat(exit, regex.CMIExit)) {
this.#exit = exit;
}
}
get session_time() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#session_time; }
set session_time(session_time) {
if(this.API.checkValidFormat(session_time, regex.CMITimespan)) {
this.#session_time = session_time;
}
}
toJSON = () => {
this.jsonString = true;
const result = {
'student_id': this.student_id,
'student_name': this.student_name,
'lesson_location': this.lesson_location,
'credit': this.credit,
'lesson_status': this.lesson_status,
'entry': this.entry,
'total_time': this.total_time,
'lesson_mode': this.lesson_mode,
'exit': this.exit,
'session_time': this.session_time,
'score': this.score
};
delete this.jsonString;
return result;
}
}
class CMIObjectives extends CMIArray {
constructor(API) {
super({
API: API,
children: constants.objectives_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE
});
}
}
export class CMIStudentData extends BaseCMI {
#_children;
#mastery_score = "";
#max_time_allowed = "";
#time_limit_action = "";
constructor(API, student_data_children) {
super(API);
this.#_children = student_data_children? student_data_children : constants.student_data_children;
}
get _children() { return this.#_children; }
set _children(_children) { throwInvalidValueError(this.API); }
get mastery_score() { return this.#mastery_score; }
set mastery_score(mastery_score) { this.API.isNotInitialized() ? this.#mastery_score = mastery_score : throwReadOnlyError(this.API); }
get max_time_allowed() { return this.#max_time_allowed; }
set max_time_allowed(max_time_allowed) { this.API.isNotInitialized() ? this.#max_time_allowed = max_time_allowed : throwReadOnlyError(this.API); }
get time_limit_action() { return this.#time_limit_action; }
set time_limit_action(time_limit_action) { this.API.isNotInitialized() ? this.#time_limit_action = time_limit_action : throwReadOnlyError(this.API); }
toJSON = () => {
this.jsonString = true;
const result = {
'mastery_score': this.mastery_score,
'max_time_allowed': this.max_time_allowed,
'time_limit_action': this.time_limit_action
};
delete this.jsonString;
return result;
}
}
class CMIStudentPreference extends BaseCMI {
constructor(API) {
super(API);
}
#_children = constants.student_preference_children;
#audio = "";
#language = "";
#speed = "";
#text = "";
get _children() { return this.#_children; }
set _children(_children) { throwInvalidValueError(this.API); }
get audio() { return this.#audio; }
set audio(audio) {
if(this.API.checkValidFormat(audio, regex.CMISInteger)
&& this.API.checkValidRange(audio, regex.audio_range)) {
this.#audio = audio;
}
}
get language() { return this.#language; }
set language(language) {
if(this.API.checkValidFormat(language, regex.CMIString256)) {
this.#language = language;
}
}
get speed() { return this.#speed; }
set speed(speed) {
if(this.API.checkValidFormat(speed, regex.CMISInteger)
&& this.API.checkValidRange(speed, regex.speed_range)) {
this.#speed = speed;
}
}
get text() { return this.#text; }
set text(text) {
if(this.API.checkValidFormat(text, regex.CMISInteger)
&& this.API.checkValidRange(text, regex.text_range)) {
this.#text = text;
}
}
toJSON = () => {
this.jsonString = true;
const result = {
'audio': this.audio,
'language': this.language,
'speed': this.speed,
'text': this.text
};
delete this.jsonString;
return result;
}
}
class CMIInteractions extends CMIArray {
constructor(API) {
super({
API: API,
children: constants.interactions_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE
});
}
}
export class CMIInteractionsObject extends BaseCMI {
constructor(API) {
super(API);
this.objectives = new CMIArray({
API: API,
errorCode: 402,
children: constants.objectives_children
});
this.correct_responses = new CMIArray({
API: API,
errorCode: 402,
children: constants.correct_responses_children
});
}
#id: "";
#time: "";
#type: "";
#weighting: "";
#student_response: "";
#result: "";
#latency: "";
get id() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#id; }
set id(id) {
if(this.API.checkValidFormat(id, regex.CMIIdentifier)) {
this.#id = id;
}
}
get time() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#time; }
set time(time) {
if(this.API.checkValidFormat(time, regex.CMITime)) {
this.#time = time;
}
}
get type() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#type; }
set type(type) {
if(this.API.checkValidFormat(type, regex.CMIType)) {
this.#type = type;
}
}
get weighting() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#weighting; }
set weighting(weighting) {
if(this.API.checkValidFormat(weighting, regex.CMIDecimal)
&& this.API.checkValidRange(weighting, regex.weighting_range)) {
this.#weighting = weighting;
}
}
get student_response() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#student_response; }
set student_response(student_response) {
if(this.API.checkValidFormat(student_response, regex.CMIFeedback)) {
this.#student_response = student_response;
}
}
get result() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#result; }
set result(result) {
if(this.API.checkValidFormat(result, regex.CMIResult)) {
this.#result = result;
}
}
get latency() { return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#latency; }
set latency(latency) {
if(this.API.checkValidFormat(latency, regex.CMITimespan)) {
this.#latency = latency;
}
}
toJSON = () => {
this.jsonString = true;
const result = {
'id': this.id,
'time': this.time,
'type': this.type,
'weighting': this.weighting,
'student_response': this.student_response,
'result': this.result,
'latency': this.latency,
'objectives': this.objectives,
'correct_responses': this.correct_responses
};
delete this.jsonString;
return result;
}
}
export class CMIObjectivesObject extends BaseCMI {
constructor(API) {
super(API);
this.score = new CMIScore(API);
}
#id: "";
#status: "";
get id() { return this.#id; }
set id(id) {
if(this.API.checkValidFormat(id, regex.CMIIdentifier)) {
this.#id = id;
}
}
get status() { return this.#status; }
set status(status) {
if(this.API.checkValidFormat(status, regex.CMIStatus2)) {
this.#status = status;
}
}
toJSON = () => {
this.jsonString = true;
const result = {
'id': this.id,
'status': this.status,
'score': this.score
};
delete this.jsonString;
return result;
}
}
export class CMIInteractionsObjectivesObject extends BaseCMI {
constructor(API) {
super(API);
}
#id: "";
get id() { return this.#id; }
set id(id) {
if(this.API.checkValidFormat(id, regex.CMIIdentifier)) {
this.#id = id;
}
}
toJSON = () => {
this.jsonString = true;
const result = {
'id': this.id,
};
delete this.jsonString;
return result;
}
}
export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
constructor(API) {
super(API);
}
#pattern: "";
get pattern() { return this.#pattern; }
set pattern(pattern) {
if(this.API.checkValidFormat(pattern, regex.CMIFeedback)) {
this.#pattern = pattern;
}
}
toJSON = () => {
this.jsonString = true;
const result = {
'pattern': this.pattern,
};
delete this.jsonString;
return result;
}
}

522
src/cmi/scorm2004_cmi.js Normal file
View File

@@ -0,0 +1,522 @@
/*
* Copyright (C) Noverant, Inc - All Rights Reserved Unauthorized copying of this file, via any
* medium is strictly prohibited Proprietary and confidential
*/
import {BaseCMI, CMIScore, CMIArray} from './common';
import {scorm2004_constants, learner_responses} from "../constants";
import {scorm2004_regex} from "../regex";
const constants = scorm2004_constants;
const regex = scorm2004_regex;
export class CMI extends BaseCMI {
constructor(API) {
super(API);
this.learner_preference = new CMILearnerPreference(API);
}
#_version: "1.0";
#_children = constants.cmi_children;
#completion_status: "unknown";
#completion_threshold: "";
#credit: "credit";
#entry: "";
#exit: "";
#launch_data: "";
#learner_id: "";
#learner_name: "";
#location: "";
#max_time_allowed: "";
#mode: "normal";
#progress_measure: "";
#scaled_passing_score: "";
#session_time: "PT0H0M0S";
#success_status: "unknown";
#suspend_data: "";
#time_limit_action: "continue,no message";
#total_time: "0";
get _version() { return this.#_version; }
set _version(_version) { this.throwReadOnlyError(); }
get _children() { return this.#_children; }
set _children(_children) { this.throwReadOnlyError(); }
get completion_status() { return this.#completion_status; }
set completion_status(completion_status) {
if(this.API.checkValidFormat(completion_status, regex.CMICStatus)) {
this.#completion_status = completion_status;
}
}
get completion_threshold() { return this.#completion_threshold; }
set completion_threshold(completion_threshold) { this.API.isNotInitialized() ? this.#completion_threshold = completion_threshold : this.throwReadOnlyError(); }
get credit() { return this.#credit; }
set credit(credit) { this.API.isNotInitialized() ? this.#credit = credit : this.throwReadOnlyError(); }
get entry() { return this.#entry; }
set entry(entry) { this.API.isNotInitialized() ? this.#entry = entry : this.throwReadOnlyError(); }
get exit() { return (!this.jsonString) ? this.throwWriteOnlyError() : this.#exit; }
set exit(exit) {
if(this.API.checkValidFormat(exit, regex.CMIExit)) {
this.#exit = exit;
}
}
get launch_data() { return this.#launch_data; }
set launch_data(launch_data) { this.API.isNotInitialized() ? this.#launch_data = launch_data : this.throwReadOnlyError(); }
get learner_id() { return this.#learner_id; }
set learner_id(learner_id) { this.API.isNotInitialized() ? this.#learner_id = learner_id : this.throwReadOnlyError(); }
get learner_name() { return this.#learner_name; }
set learner_name(learner_name) { this.API.isNotInitialized() ? this.#learner_name = learner_name : this.throwReadOnlyError(); }
get location() { return this.#location; }
set location(location) {
if(this.API.checkValidFormat(location, regex.CMIString1000)) {
this.#location = location;
}
}
get max_time_allowed() { return this.#max_time_allowed; }
set max_time_allowed(max_time_allowed) { this.API.isNotInitialized() ? this.#max_time_allowed = max_time_allowed : this.throwReadOnlyError(); }
get mode() { return this.#mode; }
set mode(mode) { this.API.isNotInitialized() ? this.#mode = mode : this.throwReadOnlyError(); }
get progress_measure() { return this.#progress_measure; }
set progress_measure(progress_measure) {
if(this.API.checkValidFormat(progress_measure, regex.CMIDecimal)
&& this.API.checkValidRange(progress_measure, regex.progress_range)) {
this.#progress_measure = progress_measure;
}
}
get scaled_passing_score() { return this.#scaled_passing_score; }
set scaled_passing_score(scaled_passing_score) { this.API.isNotInitialized() ? this.#scaled_passing_score = scaled_passing_score : this.throwReadOnlyError(); }
get session_time() { return (!this.jsonString) ? this.API.throwSCORMError(405) : this.#session_time; }
set session_time(session_time) {
if(this.API.checkValidFormat(session_time, regex.CMITimespan)) {
this.#session_time = session_time;
}
}
get success_status() { return this.#success_status; }
set success_status(success_status) {
if(this.API.checkValidFormat(success_status, regex.CMISStatus)) {
this.#success_status = success_status;
}
}
get suspend_data() { return this.#suspend_data; }
set suspend_data(suspend_data) {
if(this.API.checkValidFormat(suspend_data, regex.CMIString64000)) {
this.#suspend_data = suspend_data;
}
}
get time_limit_action() { return this.#time_limit_action; }
set time_limit_action(time_limit_action) { this.API.isNotInitialized() ? this.#time_limit_action = time_limit_action : this.throwReadOnlyError(); }
get total_time() { return this.#total_time; }
set total_time(total_time) { this.API.isNotInitialized() ? this.#total_time = total_time : this.throwReadOnlyError(); }
comments_from_learner = new class extends CMIArray {
constructor(API) {
super({
API: API,
children: constants.comments_children,
errorCode: 404
});
}
};
comments_from_lms = new class extends CMIArray {
constructor(API) {
super({
API: API,
children: constants.comments_children,
errorCode: 404
});
}
};
interactions = new class extends CMIArray {
constructor(API) {
super({
API: API,
children: constants.interactions_children,
errorCode: 404
});
}
};
objectives = new class extends CMIArray {
constructor(API) {
super({
API: API,
children: constants.objectives_children,
errorCode: 404
});
}
};
}
class CMILearnerPreference extends BaseCMI {
constructor(API) {
super(API);
}
#_children: constants.student_preference_children;
#audio_level: "1";
#language: "";
#delivery_speed: "1";
#audio_captioning: "0";
get _children() { return this.#_children; }
set _children(_children) { this.throwReadOnlyError(); }
get audio_level() { return this.#audio_level; }
set audio_level(audio_level) {
if(this.API.checkValidFormat(audio_level, regex.CMIDecimal)
&& this.API.checkValidRange(audio_level, regex.audio_range)) {
this.#audio_level = audio_level;
}
}
get language() { return this.#language; }
set language(language) {
if(this.API.checkValidFormat(language, regex.CMILang)) {
this.#language = language;
}
}
get delivery_speed() { return this.#delivery_speed; }
set delivery_speed(delivery_speed) {
if(this.API.checkValidFormat(delivery_speed, regex.CMIDecimal)
&& this.API.checkValidRange(delivery_speed, regex.speed_range)) {
this.#delivery_speed = delivery_speed;
}
}
get audio_captioning() { return this.#audio_captioning; }
set audio_captioning(audio_captioning) {
if(this.API.checkValidFormat(audio_captioning, regex.CMISInteger)
&& this.API.checkValidRange(audio_captioning, regex.text_range)) {
this.#audio_captioning = audio_captioning;
}
}
}
export class CMIInteractionsObject extends BaseCMI {
constructor(API) {
super(API);
this.objectives = new CMIArray({
API: API,
errorCode: 404,
children: constants.objectives_children
});
this.correct_responses = new CMIArray({
API: API,
errorCode: 404,
children: constants.correct_responses_children
});
}
#id: "";
#type: "";
#timestamp: "";
#weighting: "";
#learner_response: "";
#result: "";
#latency: "";
#description: "";
get id() { return this.#id; }
set id(id) {
if(this.API.checkValidFormat(id, regex.CMILongIdentifier)) {
this.#id = id;
}
}
get type() { return this.#type; }
set type(type) {
if(this.API.checkValidFormat(type, regex.CMIType)) {
this.#type = type;
}
}
get timestamp() { return this.#timestamp; }
set timestamp(timestamp) {
if(this.API.checkValidFormat(timestamp, regex.CMITime)) {
this.#timestamp = timestamp;
}
}
get weighting() { return this.#weighting; }
set weighting(weighting) {
if (this.API.checkValidFormat(weighting, regex.CMIDecimal)) {
this.#weighting = weighting;
}
}
get learner_response() { return this.#learner_response; }
set learner_response(learner_response) {
if(typeof this.type === 'undefined') {
this.API.throwSCORMError(this.API.error.DEPENDENCY_NOT_ESTABLISHED);
} else {
let nodes = [];
let response_type = learner_responses[this.type];
if(response_type.delimiter !== '') {
nodes = learner_response.split(response_type.delimiter);
} else {
nodes[0] = learner_response;
}
if((nodes.length > 0) && (nodes.length <= response_type.max)) {
const formatRegex = new RegExp(response_type.format);
for(let i = 0; (i < nodes.length) && (this.API.lastErrorCode === 0); i++) {
if(typeof response_type.delimiter2 !== 'undefined') {
let values = nodes[i].split(response_type.delimiter2);
if(values.length === 2) {
if(!values[0].match(formatRegex)) {
this.API.throwSCORMError(this.API.error.TYPE_MISMATCH);
} else {
if(!values[1].match(new RegExp(response_type.format2))) {
this.API.throwSCORMError(this.API.error.TYPE_MISMATCH);
}
}
} else {
this.API.throwSCORMError(this.API.error.TYPE_MISMATCH);
}
} else {
if(!nodes[i].match(formatRegex)) {
this.API.throwSCORMError(this.API.error.TYPE_MISMATCH);
} else {
if(nodes[i] !== '' && response_type.unique) {
for(let j = 0; (j < i) && this.API.lastErrorCode === 0; j++) {
if(nodes[i] === nodes[j]) {
this.API.throwSCORMError(this.API.error.TYPE_MISMATCH);
}
}
}
}
}
}
} else {
this.API.throwSCORMError(this.API.error.GENERAL_SET_FAILURE);
}
}
}
get result() { return this.#result; }
set result(result) {
if(this.API.checkValidFormat(result, regex.CMIResult)) {
this.#result = result;
}
}
get latency() { return this.#latency; }
set latency(latency) {
if(this.API.checkValidFormat(latency, regex.CMITimespan)) {
this.#latency = latency;
}
}
get description() { return this.#description; }
set description(description) {
if(this.API.checkValidFormat(description, regex.CMILangString250)) {
this.#description = description;
}
}
}
export class CMIObjectivesObject extends BaseCMI {
constructor(API) {
super(API);
}
#id: "";
#success_status: "unknown"; // Allowed values: "passed", "failed", "unknown"
#completion_status: "unknown"; // Allowed values: "completed", "incomplete", "not attempted", "unknown"
#progress_measure: ""; // Data type: real (10,7). Range: 0.0 to 1.0
#description: ""; // SPM 250 characters
get id() { return this.#id; }
set id(id) {
if(this.API.checkValidFormat(id, regex.CMILongIdentifier)) {
this.#id = id;
}
}
get success_status() { return this.#success_status; }
set success_status(success_status) {
if(this.API.checkValidFormat(success_status, regex.CMISStatus)) {
this.#success_status = success_status;
}
}
get completion_status() { return this.#completion_status; }
set completion_status(completion_status) {
if(this.API.checkValidFormat(completion_status, regex.CMICStatus)) {
this.#completion_status = completion_status;
}
}
get progress_measure() { return this.#progress_measure; }
set progress_measure(progress_measure) {
if(this.API.checkValidFormat(progress_measure, regex.CMIDecimal)
&& this.API.checkValidRange(progress_measure, regex.progress_range)) {
this.#progress_measure = progress_measure;
}
}
get description() { return this.#description; }
set description(description) {
if(this.API.checkValidFormat(description, regex.CMILangString250)) {
this.#description = description;
}
}
score = new Scorm2004CMIScore(this.API);
}
class Scorm2004CMIScore extends CMIScore {
constructor(API) {
super(API, constants.score_children);
this.max = "";
}
#scaled: "";
get scaled() { return this.#scaled; }
set scaled(scaled) {
if(this.API.checkValidFormat(scaled, regex.CMIDecimal)
&& this.API.checkValidRange(scaled, regex.scaled_range)) {
this.#scaled = scaled;
}
}
}
export class CMICommentsFromLearnerObject extends BaseCMI {
constructor(API) {
super(API);
}
#comment = "";
#location = "";
#timestamp = "";
get comment() { return this.#comment; }
set comment(comment) {
if(this.API.checkValidFormat(comment, regex.CMILangString4000)) {
this.#comment = comment;
}
}
get location() { return this.#location; }
set location(location) {
if(this.API.checkValidFormat(location, regex.CMIString250)) {
this.#location = location;
}
}
get timestamp() { return this.#timestamp; }
set timestamp(timestamp) {
if(this.API.checkValidFormat(timestamp, regex.CMITime)) {
this.#timestamp = timestamp;
}
}
}
export class CMICommentsFromLMSObject extends CMICommentsFromLearnerObject {
constructor(API) {
super(API);
}
set comment(comment) { this.API.isNotInitialized() ? this.comment = comment : this.throwReadOnlyError(); }
set location(location) { this.API.isNotInitialized() ? this.location = location : this.throwReadOnlyError(); }
set timestamp(timestamp) { this.API.isNotInitialized() ? this.timestamp = timestamp : this.throwReadOnlyError(); }
}
export class CMIInteractionsObjectivesObject extends BaseCMI {
constructor(API) {
super(API);
}
#id: "";
get id() { return this.#id; }
set id(id) {
if(this.API.checkValidFormat(id, regex.CMILongIdentifier)) {
this.#id = id;
}
}
}
export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
constructor(API) {
super(API);
}
#pattern: "";
get pattern() { return this.#pattern; }
set pattern(pattern) {
if(this.API.checkValidFormat(pattern, regex.CMIFeedback)) {
this.#pattern = pattern;
}
}
}
export class ADL extends BaseCMI {
constructor(API) {
super(API);
}
nav = new class extends BaseCMI {
constructor(API) {
super(API);
}
#request = "_none_"; // Allowed values: "continue", "previous", "choice", "jump", "exit", "exitAll", "abandon", "abandonAll", "_none_"
get request() { return this.#request; }
set request(request) {
if(this.API.checkValidFormat(request, regex.NAVEvent)) {
this.#request = request;
}
}
request_valid = new class extends BaseCMI {
constructor(API) {
super(API);
}
#continue = "unknown"; // Allowed values: "true", "false", "unknown"
#previous = "unknown"; // Allowed values: "true", "false", "unknown"
get continue() { return this.#continue; }
set continue(_) { API.throwSCORMError(404); }
get previous() { return this.#previous; }
set previous(_) { API.throwSCORMError(404); }
choice = class {
_isTargetValid = (_target) => "unknown";
};
jump = class {
_isTargetValid = (_target) => "unknown";
};
}
};
}