Removed circular dependencies between APIs and CMI objects

No longer directly setting error codes on the API when a read/write or data validation fails, throwing exceptions instead that can then be caught by the APi.
This commit is contained in:
Jonathan Putney
2019-11-12 11:17:41 -05:00
parent 73ff260097
commit 9e8896fa32
10 changed files with 1114 additions and 868 deletions

View File

@@ -3,31 +3,38 @@ import {BaseCMI, CMIArray, CMIScore} from './common';
import {aicc_constants} from '../constants/api_constants';
import {aicc_regex} from '../regex';
import {scorm12_error_codes} from '../constants/error_codes';
import {ValidationError} from '../exceptions';
import {check12ValidFormat} from './scorm12_cmi';
import {throwReadOnlyError} from './scorm12_cmi';
import {throwWriteOnlyError} from './scorm12_cmi';
const constants = aicc_constants;
const regex = aicc_regex;
/**
* Sets a READ_ONLY error on the API
* @param {AICC} API
*/
function throwReadOnlyError(API) {
API.throwSCORMError(scorm12_error_codes.READ_ONLY_ELEMENT);
}
/**
* CMI Class for AICC
*/
export class CMI extends Scorm12CMI.CMI {
/**
* Constructor for AICC CMI object
* @param {AICC} API
* @param {boolean} initialized
*/
constructor(API) {
super(API, constants.cmi_children);
constructor(initialized: boolean) {
super(constants.cmi_children);
this.student_data = new AICCCMIStudentData(API);
this.evaluation = new CMIEvaluation(API);
if (initialized) this.initialize();
this.student_data = new AICCCMIStudentData();
this.evaluation = new CMIEvaluation();
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
super.initialize();
this.student_data?.initialize();
this.evaluation?.initialize();
}
}
@@ -37,12 +44,19 @@ export class CMI extends Scorm12CMI.CMI {
class CMIEvaluation extends BaseCMI {
/**
* Constructor for AICC Evaluation object
* @param {AICC} API
*/
constructor(API) {
super(API);
constructor() {
super();
this.comments = new CMIEvaluationComments(API);
this.comments = new CMIEvaluationComments();
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
super.initialize();
this.comments?.initialize();
}
}
@@ -52,10 +66,9 @@ class CMIEvaluation extends BaseCMI {
class CMIEvaluationComments extends CMIArray {
/**
* Constructor for AICC Evaluation Comments object
* @param {AICC} API
*/
constructor(API) {
super(API, constants.comments_children,
constructor() {
super(constants.comments_children,
scorm12_error_codes.INVALID_SET_VALUE);
}
}
@@ -66,12 +79,19 @@ class CMIEvaluationComments extends CMIArray {
class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
/**
* Constructor for AICC StudentData object
* @param {AICC} API
*/
constructor(API) {
super(API, constants.student_data_children);
constructor() {
super(constants.student_data_children);
this.tries = new CMITries(API);
this.tries = new CMITries();
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
super.initialize();
this.tries?.initialize();
}
#tries_during_lesson = '';
@@ -86,13 +106,13 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
/**
* Setter for #tries_during_lesson. Sets an error if trying to set after
* API initialization.
* initialization.
* @param {string} tries_during_lesson
*/
set tries_during_lesson(tries_during_lesson) {
this.API.isNotInitialized() ?
!this.initialized ?
this.#tries_during_lesson = tries_during_lesson :
throwReadOnlyError(this.API);
throwReadOnlyError();
}
}
@@ -102,10 +122,9 @@ class AICCCMIStudentData extends Scorm12CMI.CMIStudentData {
export class CMITries extends CMIArray {
/**
* Constructor for inline Tries Array class
* @param {AICC} API
*/
constructor(API) {
super(API, aicc_constants.tries_children);
constructor() {
super(aicc_constants.tries_children);
}
}
@@ -115,12 +134,19 @@ export class CMITries extends CMIArray {
export class CMITriesObject extends BaseCMI {
/**
* Constructor for AICC Tries object
* @param {AICC} API
*/
constructor(API) {
super(API);
constructor() {
super();
this.score = new CMIScore(API);
this.score = new CMIScore();
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
super.initialize();
this.score?.initialize();
}
#status = '';
@@ -139,7 +165,7 @@ export class CMITriesObject extends BaseCMI {
* @param {string} status
*/
set status(status) {
if (this.API.checkValidFormat(status, regex.CMIStatus2)) {
if (check12ValidFormat(status, regex.CMIStatus2)) {
this.#status = status;
}
}
@@ -157,7 +183,7 @@ export class CMITriesObject extends BaseCMI {
* @param {string} time
*/
set time(time) {
if (this.API.checkValidFormat(time, regex.CMITime)) {
if (check12ValidFormat(time, regex.CMITime)) {
this.#time = time;
}
}
@@ -169,10 +195,9 @@ export class CMITriesObject extends BaseCMI {
export class CMIEvaluationCommentsObject extends BaseCMI {
/**
* Constructor for Evaluation Comments
* @param {AICC} API
*/
constructor(API) {
super(API);
constructor() {
super();
}
#content = '';
@@ -192,7 +217,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} content
*/
set content(content) {
if (this.API.checkValidFormat(content, regex.CMIString256)) {
if (check12ValidFormat(content, regex.CMIString256)) {
this.#content = content;
}
}
@@ -210,7 +235,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} location
*/
set location(location) {
if (this.API.checkValidFormat(location, regex.CMIString256)) {
if (check12ValidFormat(location, regex.CMIString256)) {
this.#location = location;
}
}
@@ -228,7 +253,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
* @param {string} time
*/
set time(time) {
if (this.API.checkValidFormat(time, regex.CMITime)) {
if (check12ValidFormat(time, regex.CMITime)) {
this.#time = time;
}
}
@@ -240,10 +265,9 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
export class NAV extends BaseCMI {
/**
* Constructor for NAV object
* @param {AICC} API
*/
constructor(API) {
super(API);
constructor() {
super();
}
#event = '';
@@ -253,9 +277,7 @@ export class NAV extends BaseCMI {
* @return {string}
*/
get event() {
return (!this.jsonString) ?
this.API.throwSCORMError(scorm12_error_codes.WRITE_ONLY_ELEMENT) :
this.#event;
return (!this.jsonString) ? throwWriteOnlyError() : this.#event;
}
/**
@@ -263,7 +285,7 @@ export class NAV extends BaseCMI {
* @param {string} event
*/
set event(event) {
if (this.API.checkValidFormat(event, regex.NAVEvent)) {
if (check12ValidFormat(event, regex.NAVEvent)) {
this.#event = event;
}
}

View File

@@ -1,20 +1,68 @@
// @flow
import {scorm12_constants} from '../constants/api_constants';
import {scorm12_error_codes} from '../constants/error_codes';
import {ValidationError} from '../exceptions';
/**
* Check if the value matches the proper format. If not, throw proper error code.
*
* @param {string} value
* @param {string} regexPattern
* @param {number} errorCode
* @return {boolean}
*/
export function checkValidFormat(
value: String, regexPattern: String, errorCode: number) {
const formatRegex = new RegExp(regexPattern);
if (!value || !value.match(formatRegex)) {
throw new ValidationError(errorCode);
}
return true;
}
/**
* Check if the value matches the proper range. If not, throw proper error code.
*
* @param {*} value
* @param {string} rangePattern
* @param {number} errorCode
* @return {boolean}
*/
export function checkValidRange(
value: any, rangePattern: String, errorCode: number) {
const ranges = rangePattern.split('#');
value = value * 1.0;
if (value >= ranges[0]) {
if ((ranges[1] === '*') || (value <= ranges[1])) {
return true;
} else {
throw new ValidationError(errorCode);
}
} else {
throw new ValidationError(errorCode);
}
}
/**
* Base class for API cmi objects
*/
export class BaseCMI {
jsonString = false;
API;
#initialized = false;
/**
* Constructor for base cmi
* @param {BaseAPI} API
* Getter for #initialized
* @return {boolean}
*/
constructor(API: any) {
this.API = API;
get initialized() {
return this.#initialized;
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
this.#initialized = true;
}
}
@@ -24,29 +72,48 @@ export class BaseCMI {
export class CMIScore extends BaseCMI {
/**
* Constructor for *.score
* @param {BaseAPI} API
* @param {string} score_children
* @param {string} score_range
* @param {string} max
* @param {number} invalidErrorCode
* @param {number} invalidTypeCode
* @param {number} invalidRangeCode
*/
constructor(API, score_children?, score_range?, invalidErrorCode) {
super(API);
constructor(
{
score_children,
score_range,
max,
invalidErrorCode,
invalidTypeCode,
invalidRangeCode,
}) {
super();
this.#_children = score_children ?
score_children :
scorm12_constants.score_children;
this.#_score_range = score_range ? score_range : false;
this.#max = max ? max : '100';
this.#_invalid_error_code = invalidErrorCode ?
invalidErrorCode :
scorm12_error_codes.INVALID_SET_VALUE;
this.#_invalid_type_code = invalidTypeCode ?
invalidTypeCode :
scorm12_error_codes.TYPE_MISMATCH;
this.#_invalid_range_code = invalidRangeCode ?
invalidRangeCode :
scorm12_error_codes.VALUE_OUT_OF_RANGE;
}
#_children;
#_score_range;
#_invalid_error_code;
#_invalid_type_code;
#_invalid_range_code;
#raw = '';
#min = '';
#max = '100';
#max;
/**
* Getter for _children
@@ -63,7 +130,7 @@ export class CMIScore extends BaseCMI {
* @private
*/
set _children(_children) {
this.API.throwSCORMError(this.#_invalid_error_code);
throw new ValidationError(this.#_invalid_error_code);
}
/**
@@ -79,9 +146,11 @@ export class CMIScore extends BaseCMI {
* @param {string} raw
*/
set raw(raw) {
if (this.API.checkValidFormat(raw, scorm12_constants.CMIDecimal) &&
if (checkValidFormat(raw, scorm12_constants.CMIDecimal,
this.#_invalid_type_code) &&
(!this.#_score_range ||
this.API.checkValidRange(raw, this.#_score_range))) {
checkValidRange(raw, this.#_score_range,
this.#_invalid_range_code))) {
this.#raw = raw;
}
}
@@ -99,9 +168,11 @@ export class CMIScore extends BaseCMI {
* @param {string} min
*/
set min(min) {
if (this.API.checkValidFormat(min, scorm12_constants.CMIDecimal) &&
if (checkValidFormat(min, scorm12_constants.CMIDecimal,
this.#_invalid_type_code) &&
(!this.#_score_range ||
this.API.checkValidRange(min, this.#_score_range))) {
checkValidRange(min, this.#_score_range,
this.#_invalid_range_code))) {
this.#min = min;
}
}
@@ -119,9 +190,11 @@ export class CMIScore extends BaseCMI {
* @param {string} max
*/
set max(max) {
if (this.API.checkValidFormat(max, scorm12_constants.CMIDecimal) &&
if (checkValidFormat(max, scorm12_constants.CMIDecimal,
this.#_invalid_type_code) &&
(!this.#_score_range ||
this.API.checkValidRange(max, this.#_score_range))) {
checkValidRange(max, this.#_score_range,
this.#_invalid_range_code))) {
this.#max = max;
}
}
@@ -145,12 +218,11 @@ export class CMIScore extends BaseCMI {
export class CMIArray extends BaseCMI {
/**
* Constructor cmi *.n arrays
* @param {BaseAPI} API
* @param {string} children
* @param {number} errorCode
*/
constructor({API, children, errorCode}) {
super(API);
constructor({children, errorCode}) {
super();
this.#_children = children;
this.#errorCode = errorCode;
this.childArray = [];
@@ -174,7 +246,7 @@ export class CMIArray extends BaseCMI {
* @private
*/
set _children(_children) {
this.API.throwSCORMError(this.#errorCode);
throw new ValidationError(this.#errorCode);
}
/**
@@ -192,7 +264,7 @@ export class CMIArray extends BaseCMI {
* @private
*/
set _count(_count) {
this.API.throwSCORMError(this.#errorCode);
throw new ValidationError(this.#errorCode);
}
/**

View File

@@ -1,34 +1,60 @@
// @flow
import {BaseCMI, CMIArray, CMIScore} from './common';
import {
BaseCMI,
checkValidFormat,
checkValidRange,
CMIArray,
CMIScore,
} from './common';
import {scorm12_constants} from '../constants/api_constants';
import {scorm12_error_codes} from '../constants/error_codes';
import {scorm12_regex} from '../regex';
import {ValidationError} from '../exceptions';
const constants = scorm12_constants;
const regex = scorm12_regex;
/**
* Helper method for throwing Read Only error
* @param {Scorm12API} API
*/
function throwReadOnlyError(API) {
API.throwSCORMError(scorm12_error_codes.READ_ONLY_ELEMENT);
export function throwReadOnlyError() {
throw new ValidationError(scorm12_error_codes.READ_ONLY_ELEMENT);
}
/**
* Helper method for throwing Write Only error
* @param {Scorm12API} API
*/
function throwWriteOnlyError(API) {
API.throwSCORMError(scorm12_error_codes.WRITE_ONLY_ELEMENT);
export function throwWriteOnlyError() {
throw new ValidationError(scorm12_error_codes.WRITE_ONLY_ELEMENT);
}
/**
* Helper method for throwing Invalid Set error
* @param {Scorm12API} API
*/
function throwInvalidValueError(API) {
API.throwSCORMError(scorm12_error_codes.INVALID_SET_VALUE);
function throwInvalidValueError() {
throw new ValidationError(scorm12_error_codes.INVALID_SET_VALUE);
}
/**
* Helper method, no reason to have to pass the same error codes every time
* @param {*} value
* @param {string} regexPattern
* @return {boolean}
*/
export function check12ValidFormat(value: String, regexPattern: String) {
return checkValidFormat(value, regexPattern,
scorm12_error_codes.TYPE_MISMATCH);
}
/**
* Helper method, no reason to have to pass the same error codes every time
* @param {*} value
* @param {string} rangePattern
* @return {boolean}
*/
export function check12ValidRange(value: any, rangePattern: String) {
return checkValidRange(value, rangePattern,
scorm12_error_codes.VALUE_OUT_OF_RANGE);
}
/**
@@ -46,21 +72,33 @@ export class CMI extends BaseCMI {
/**
* Constructor for the SCORM 1.2 cmi object
* @param {Scorm12API} API
* @param {string} cmi_children
* @param {string} student_data
* @param {(CMIStudentData|AICCCMIStudentData)} student_data
* @param {boolean} initialized
*/
constructor(API, cmi_children, student_data) {
super(API);
constructor(cmi_children, student_data, initialized: boolean) {
super();
if (initialized) this.initialize();
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);
this.core = new CMICore();
this.objectives = new CMIObjectives();
this.student_data = student_data ? student_data : new CMIStudentData();
this.student_preference = new CMIStudentPreference();
this.interactions = new CMIInteractions();
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
super.initialize();
this.core?.initialize();
this.objectives?.initialize();
this.student_data?.initialize();
this.student_preference?.initialize();
this.interactions?.initialize();
}
/**
@@ -112,7 +150,7 @@ export class CMI extends BaseCMI {
* @private
*/
set _version(_version) {
throwInvalidValueError(this.API);
throwInvalidValueError();
}
/**
@@ -130,7 +168,7 @@ export class CMI extends BaseCMI {
* @private
*/
set _children(_children) {
throwInvalidValueError(this.API);
throwInvalidValueError();
}
/**
@@ -146,7 +184,7 @@ export class CMI extends BaseCMI {
* @param {string} suspend_data
*/
set suspend_data(suspend_data) {
if (this.API.checkValidFormat(suspend_data, regex.CMIString4096)) {
if (check12ValidFormat(suspend_data, regex.CMIString4096)) {
this.#suspend_data = suspend_data;
}
}
@@ -160,13 +198,11 @@ export class CMI extends BaseCMI {
}
/**
* Setter for #launch_data. Can only be called before API initialization.
* Setter for #launch_data. Can only be called before initialization.
* @param {string} launch_data
*/
set launch_data(launch_data) {
this.API.isNotInitialized() ?
this.#launch_data = launch_data :
throwReadOnlyError(this.API);
!this.initialized ? this.#launch_data = launch_data : throwReadOnlyError();
}
/**
@@ -182,7 +218,7 @@ export class CMI extends BaseCMI {
* @param {string} comments
*/
set comments(comments) {
if (this.API.checkValidFormat(comments, regex.CMIString4096)) {
if (check12ValidFormat(comments, regex.CMIString4096)) {
this.#comments = comments;
}
}
@@ -196,13 +232,11 @@ export class CMI extends BaseCMI {
}
/**
* Setter for #comments_from_lms. Can only be called before API initialization.
* Setter for #comments_from_lms. Can only be called before initialization.
* @param {string} comments_from_lms
*/
set comments_from_lms(comments_from_lms) {
this.API.isNotInitialized() ?
this.#comments_from_lms = comments_from_lms :
throwReadOnlyError(this.API);
!this.initialized ? this.#comments_from_lms = comments_from_lms : throwReadOnlyError();
}
}
@@ -212,13 +246,26 @@ export class CMI extends BaseCMI {
class CMICore extends BaseCMI {
/**
* Constructor for cmi.core
* @param {Scorm12API} API
*/
constructor(API) {
super(API);
constructor() {
super();
this.score = new Scorm12CMIScore(API, constants.score_children,
regex.score_range);
this.score = new Scorm12CMIScore(
{
score_children: constants.score_children,
score_range: regex.score_range,
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
});
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
super.initialize();
this.score?.initialize();
}
#_children = constants.core_children;
@@ -248,7 +295,7 @@ class CMICore extends BaseCMI {
* @private
*/
set _children(_children) {
throwInvalidValueError(this.API);
throwInvalidValueError();
}
/**
@@ -260,13 +307,11 @@ class CMICore extends BaseCMI {
}
/**
* Setter for #student_id. Can only be called before API initialization.
* Setter for #student_id. Can only be called before initialization.
* @param {string} student_id
*/
set student_id(student_id) {
this.API.isNotInitialized() ?
this.#student_id = student_id :
throwReadOnlyError(this.API);
!this.initialized ? this.#student_id = student_id : throwReadOnlyError();
}
/**
@@ -278,13 +323,11 @@ class CMICore extends BaseCMI {
}
/**
* Setter for #student_name. Can only be called before API initialization.
* Setter for #student_name. Can only be called before initialization.
* @param {string} student_name
*/
set student_name(student_name) {
this.API.isNotInitialized() ?
this.#student_name = student_name :
throwReadOnlyError(this.API);
!this.initialized ? this.#student_name = student_name : throwReadOnlyError();
}
/**
@@ -300,7 +343,7 @@ class CMICore extends BaseCMI {
* @param {string} lesson_location
*/
set lesson_location(lesson_location) {
if (this.API.checkValidFormat(lesson_location, regex.CMIString256)) {
if (check12ValidFormat(lesson_location, regex.CMIString256)) {
this.#lesson_location = lesson_location;
}
}
@@ -314,13 +357,11 @@ class CMICore extends BaseCMI {
}
/**
* Setter for #credit. Can only be called before API initialization.
* Setter for #credit. Can only be called before initialization.
* @param {string} credit
*/
set credit(credit) {
this.API.isNotInitialized() ?
this.#credit = credit :
throwReadOnlyError(this.API);
!this.initialized ? this.#credit = credit : throwReadOnlyError();
}
/**
@@ -336,7 +377,7 @@ class CMICore extends BaseCMI {
* @param {string} lesson_status
*/
set lesson_status(lesson_status) {
if (this.API.checkValidFormat(lesson_status, regex.CMIStatus)) {
if (check12ValidFormat(lesson_status, regex.CMIStatus)) {
this.#lesson_status = lesson_status;
}
}
@@ -350,13 +391,11 @@ class CMICore extends BaseCMI {
}
/**
* Setter for #entry. Can only be called before API initialization.
* Setter for #entry. Can only be called before initialization.
* @param {string} entry
*/
set entry(entry) {
this.API.isNotInitialized() ?
this.#entry = entry :
throwReadOnlyError(this.API);
!this.initialized ? this.#entry = entry : throwReadOnlyError();
}
/**
@@ -368,13 +407,11 @@ class CMICore extends BaseCMI {
}
/**
* Setter for #total_time. Can only be called before API initialization.
* Setter for #total_time. Can only be called before initialization.
* @param {string} total_time
*/
set total_time(total_time) {
this.API.isNotInitialized() ?
this.#total_time = total_time :
throwReadOnlyError(this.API);
!this.initialized ? this.#total_time = total_time : throwReadOnlyError();
}
/**
@@ -386,13 +423,11 @@ class CMICore extends BaseCMI {
}
/**
* Setter for #lesson_mode. Can only be called before API initialization.
* Setter for #lesson_mode. Can only be called before initialization.
* @param {string} lesson_mode
*/
set lesson_mode(lesson_mode) {
this.API.isNotInitialized() ?
this.#lesson_mode = lesson_mode :
throwReadOnlyError(this.API);
!this.initialized ? this.#lesson_mode = lesson_mode : throwReadOnlyError();
}
/**
@@ -400,7 +435,7 @@ class CMICore extends BaseCMI {
* @return {*}
*/
get exit() {
return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#exit;
return (!this.jsonString) ? throwWriteOnlyError() : this.#exit;
}
/**
@@ -408,7 +443,7 @@ class CMICore extends BaseCMI {
* @param {string} exit
*/
set exit(exit) {
if (this.API.checkValidFormat(exit, regex.CMIExit)) {
if (check12ValidFormat(exit, regex.CMIExit)) {
this.#exit = exit;
}
}
@@ -418,9 +453,7 @@ class CMICore extends BaseCMI {
* @return {*}
*/
get session_time() {
return (!this.jsonString) ?
throwWriteOnlyError(this.API) :
this.#session_time;
return (!this.jsonString) ? throwWriteOnlyError() : this.#session_time;
}
/**
@@ -428,7 +461,7 @@ class CMICore extends BaseCMI {
* @param {string} session_time
*/
set session_time(session_time) {
if (this.API.checkValidFormat(session_time, regex.CMITimespan)) {
if (check12ValidFormat(session_time, regex.CMITimespan)) {
this.#session_time = session_time;
}
}
@@ -478,11 +511,9 @@ class CMICore extends BaseCMI {
class CMIObjectives extends CMIArray {
/**
* Constructor for cmi.objectives
* @param {Scorm12API} API
*/
constructor(API) {
constructor() {
super({
API: API,
children: constants.objectives_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
});
@@ -500,11 +531,10 @@ export class CMIStudentData extends BaseCMI {
/**
* Constructor for cmi.student_data
* @param {Scorm12API} API
* @param {string} student_data_children
*/
constructor(API, student_data_children) {
super(API);
constructor(student_data_children) {
super();
this.#_children = student_data_children ?
student_data_children :
@@ -526,7 +556,7 @@ export class CMIStudentData extends BaseCMI {
* @private
*/
set _children(_children) {
throwInvalidValueError(this.API);
throwInvalidValueError();
}
/**
@@ -538,13 +568,11 @@ export class CMIStudentData extends BaseCMI {
}
/**
* Setter for #master_score. Can only be called before API initialization.
* Setter for #master_score. Can only be called before initialization.
* @param {string} mastery_score
*/
set mastery_score(mastery_score) {
this.API.isNotInitialized() ?
this.#mastery_score = mastery_score :
throwReadOnlyError(this.API);
!this.initialized ? this.#mastery_score = mastery_score : throwReadOnlyError();
}
/**
@@ -556,13 +584,11 @@ export class CMIStudentData extends BaseCMI {
}
/**
* Setter for #max_time_allowed. Can only be called before API initialization.
* Setter for #max_time_allowed. Can only be called before initialization.
* @param {string} max_time_allowed
*/
set max_time_allowed(max_time_allowed) {
this.API.isNotInitialized() ?
this.#max_time_allowed = max_time_allowed :
throwReadOnlyError(this.API);
!this.initialized ? this.#max_time_allowed = max_time_allowed : throwReadOnlyError();
}
/**
@@ -574,13 +600,11 @@ export class CMIStudentData extends BaseCMI {
}
/**
* Setter for #time_limit_action. Can only be called before API initialization.
* Setter for #time_limit_action. Can only be called before initialization.
* @param {string} time_limit_action
*/
set time_limit_action(time_limit_action) {
this.API.isNotInitialized() ?
this.#time_limit_action = time_limit_action :
throwReadOnlyError(this.API);
!this.initialized ? this.#time_limit_action = time_limit_action : throwReadOnlyError();
}
/**
@@ -612,10 +636,9 @@ export class CMIStudentData extends BaseCMI {
class CMIStudentPreference extends BaseCMI {
/**
* Constructor for cmi.student_preference
* @param {Scorm12API} API
*/
constructor(API) {
super(API);
constructor() {
super();
}
#_children = constants.student_preference_children;
@@ -639,7 +662,7 @@ class CMIStudentPreference extends BaseCMI {
* @private
*/
set _children(_children) {
throwInvalidValueError(this.API);
throwInvalidValueError();
}
/**
@@ -655,8 +678,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} audio
*/
set audio(audio) {
if (this.API.checkValidFormat(audio, regex.CMISInteger) &&
this.API.checkValidRange(audio, regex.audio_range)) {
if (check12ValidFormat(audio, regex.CMISInteger) &&
check12ValidRange(audio, regex.audio_range)) {
this.#audio = audio;
}
}
@@ -674,7 +697,7 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} language
*/
set language(language) {
if (this.API.checkValidFormat(language, regex.CMIString256)) {
if (check12ValidFormat(language, regex.CMIString256)) {
this.#language = language;
}
}
@@ -692,8 +715,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} speed
*/
set speed(speed) {
if (this.API.checkValidFormat(speed, regex.CMISInteger) &&
this.API.checkValidRange(speed, regex.speed_range)) {
if (check12ValidFormat(speed, regex.CMISInteger) &&
check12ValidRange(speed, regex.speed_range)) {
this.#speed = speed;
}
}
@@ -711,8 +734,8 @@ class CMIStudentPreference extends BaseCMI {
* @param {string} text
*/
set text(text) {
if (this.API.checkValidFormat(text, regex.CMISInteger) &&
this.API.checkValidRange(text, regex.text_range)) {
if (check12ValidFormat(text, regex.CMISInteger) &&
check12ValidRange(text, regex.text_range)) {
this.#text = text;
}
}
@@ -748,11 +771,9 @@ class CMIStudentPreference extends BaseCMI {
class CMIInteractions extends CMIArray {
/**
* Constructor for cmi.interactions
* @param {Scorm12API} API
*/
constructor(API) {
constructor() {
super({
API: API,
children: constants.interactions_children,
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
});
@@ -765,23 +786,29 @@ class CMIInteractions extends CMIArray {
export class CMIInteractionsObject extends BaseCMI {
/**
* Constructor for cmi.interactions.n object
* @param {Scorm12API} API
*/
constructor(API) {
super(API);
constructor() {
super();
this.objectives = new CMIArray({
API: API,
errorCode: 402,
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
children: constants.objectives_children,
});
this.correct_responses = new CMIArray({
API: API,
errorCode: 402,
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
children: constants.correct_responses_children,
});
}
/**
* Called when the API has been initialized after the CMI has been created
*/
initialize() {
super.initialize();
this.objectives?.initialize();
this.correct_responses?.initialize();
}
#id: '';
#time: '';
#type: '';
@@ -795,7 +822,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @return {*}
*/
get id() {
return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#id;
return (!this.jsonString) ? throwWriteOnlyError() : this.#id;
}
/**
@@ -803,7 +830,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (this.API.checkValidFormat(id, regex.CMIIdentifier)) {
if (check12ValidFormat(id, regex.CMIIdentifier)) {
this.#id = id;
}
}
@@ -813,7 +840,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @return {*}
*/
get time() {
return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#time;
return (!this.jsonString) ? throwWriteOnlyError() : this.#time;
}
/**
@@ -821,7 +848,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} time
*/
set time(time) {
if (this.API.checkValidFormat(time, regex.CMITime)) {
if (check12ValidFormat(time, regex.CMITime)) {
this.#time = time;
}
}
@@ -831,7 +858,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @return {*}
*/
get type() {
return (!this.jsonString) ? throwWriteOnlyError(this.API) : this.#type;
return (!this.jsonString) ? throwWriteOnlyError() : this.#type;
}
/**
@@ -839,7 +866,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} type
*/
set type(type) {
if (this.API.checkValidFormat(type, regex.CMIType)) {
if (check12ValidFormat(type, regex.CMIType)) {
this.#type = type;
}
}
@@ -850,7 +877,7 @@ export class CMIInteractionsObject extends BaseCMI {
*/
get weighting() {
return (!this.jsonString) ?
throwWriteOnlyError(this.API) :
throwWriteOnlyError() :
this.#weighting;
}
@@ -859,8 +886,8 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} weighting
*/
set weighting(weighting) {
if (this.API.checkValidFormat(weighting, regex.CMIDecimal) &&
this.API.checkValidRange(weighting, regex.weighting_range)) {
if (check12ValidFormat(weighting, regex.CMIDecimal) &&
check12ValidRange(weighting, regex.weighting_range)) {
this.#weighting = weighting;
}
}
@@ -870,9 +897,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @return {*}
*/
get student_response() {
return (!this.jsonString) ?
throwWriteOnlyError(this.API) :
this.#student_response;
return (!this.jsonString) ? throwWriteOnlyError() : this.#student_response;
}
/**
@@ -880,7 +905,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} student_response
*/
set student_response(student_response) {
if (this.API.checkValidFormat(student_response, regex.CMIFeedback)) {
if (check12ValidFormat(student_response, regex.CMIFeedback)) {
this.#student_response = student_response;
}
}
@@ -890,9 +915,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @return {*}
*/
get result() {
return (!this.jsonString) ?
throwWriteOnlyError(this.API) :
this.#result;
return (!this.jsonString) ? throwWriteOnlyError() : this.#result;
}
/**
@@ -900,7 +923,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} result
*/
set result(result) {
if (this.API.checkValidFormat(result, regex.CMIResult)) {
if (check12ValidFormat(result, regex.CMIResult)) {
this.#result = result;
}
}
@@ -910,9 +933,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @return {*}
*/
get latency() {
return (!this.jsonString) ?
throwWriteOnlyError(this.API) :
this.#latency;
return (!this.jsonString) ? throwWriteOnlyError() : this.#latency;
}
/**
@@ -920,7 +941,7 @@ export class CMIInteractionsObject extends BaseCMI {
* @param {string} latency
*/
set latency(latency) {
if (this.API.checkValidFormat(latency, regex.CMITimespan)) {
if (check12ValidFormat(latency, regex.CMITimespan)) {
this.#latency = latency;
}
}
@@ -966,12 +987,11 @@ export class CMIInteractionsObject extends BaseCMI {
export class CMIObjectivesObject extends BaseCMI {
/**
* Constructor for cmi.objectives.n
* @param {Scorm12API} API
*/
constructor(API) {
super(API);
constructor() {
super();
this.score = new Scorm12CMIScore(API);
this.score = new Scorm12CMIScore();
}
#id: '';
@@ -990,7 +1010,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (this.API.checkValidFormat(id, regex.CMIIdentifier)) {
if (check12ValidFormat(id, regex.CMIIdentifier)) {
this.#id = id;
}
}
@@ -1008,7 +1028,7 @@ export class CMIObjectivesObject extends BaseCMI {
* @param {string} status
*/
set status(status) {
if (this.API.checkValidFormat(status, regex.CMIStatus2)) {
if (check12ValidFormat(status, regex.CMIStatus2)) {
this.#status = status;
}
}
@@ -1041,10 +1061,9 @@ export class CMIObjectivesObject extends BaseCMI {
export class CMIInteractionsObjectivesObject extends BaseCMI {
/**
* Constructor for cmi.interactions.n.objectives.n
* @param {Scorm12API} API
*/
constructor(API) {
super(API);
constructor() {
super();
}
#id: '';
@@ -1062,7 +1081,7 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
* @param {string} id
*/
set id(id) {
if (this.API.checkValidFormat(id, regex.CMIIdentifier)) {
if (check12ValidFormat(id, regex.CMIIdentifier)) {
this.#id = id;
}
}
@@ -1091,10 +1110,9 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
/**
* Constructor for cmi.interactions.correct_responses.n
* @param {Scorm12API} API
*/
constructor(API) {
super(API);
constructor() {
super();
}
#pattern: '';
@@ -1112,7 +1130,7 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
* @param {string} pattern
*/
set pattern(pattern) {
if (this.API.checkValidFormat(pattern, regex.CMIFeedback)) {
if (check12ValidFormat(pattern, regex.CMIFeedback)) {
this.#pattern = pattern;
}
}

File diff suppressed because it is too large Load Diff