scorm-again 1.5.3 → 1.7.0
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/.circleci/config.yml +4 -9
- package/.run/Mocha Unit Tests.run.xml +14 -0
- package/.run/compile.run.xml +12 -0
- package/README.md +12 -3
- package/dist/aicc.js +7362 -0
- package/dist/aicc.js.map +1 -0
- package/dist/aicc.min.js +40 -0
- package/dist/scorm-again.js +1353 -1006
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +52 -41
- package/dist/scorm12.js +5610 -0
- package/dist/scorm12.js.map +1 -0
- package/dist/scorm12.min.js +34 -0
- package/dist/scorm2004.js +7011 -0
- package/dist/scorm2004.js.map +1 -0
- package/dist/scorm2004.min.js +40 -0
- package/package.json +36 -28
- package/src/BaseAPI.js +71 -39
- package/src/Scorm12API.js +8 -15
- package/src/Scorm2004API.js +5 -8
- package/src/cmi/aicc_cmi.js +73 -35
- package/src/cmi/common.js +27 -21
- package/src/cmi/scorm12_cmi.js +24 -8
- package/src/cmi/scorm2004_cmi.js +67 -47
- package/src/constants/api_constants.js +8 -0
- package/src/constants/response_constants.js +2 -2
- package/src/exceptions.js +77 -6
- package/src/exports/aicc.js +3 -0
- package/src/exports/scorm-again.js +7 -0
- package/src/exports/scorm12.js +3 -0
- package/src/exports/scorm2004.js +3 -0
- package/test/Scorm2004API.spec.js +37 -7
- package/test/api_helpers.js +4 -4
- package/test/cmi_helpers.js +3 -3
- package/test/exceptions.spec.js +59 -4
- package/webpack.js +78 -0
- package/gruntfile.js +0 -87
- package/src/exports.js +0 -7
package/src/Scorm12API.js
CHANGED
|
@@ -202,7 +202,7 @@ export default class Scorm12API extends BaseAPI {
|
|
|
202
202
|
* Returns the message that corresponds to errorNumber.
|
|
203
203
|
*
|
|
204
204
|
* @param {*} errorNumber
|
|
205
|
-
* @param {boolean
|
|
205
|
+
* @param {boolean} detail
|
|
206
206
|
* @return {string}
|
|
207
207
|
*/
|
|
208
208
|
getLmsErrorMessageDetails(errorNumber, detail) {
|
|
@@ -278,8 +278,7 @@ export default class Scorm12API extends BaseAPI {
|
|
|
278
278
|
if (this.settings.mastery_override &&
|
|
279
279
|
this.cmi.student_data.mastery_score !== '' &&
|
|
280
280
|
this.cmi.core.score.raw !== '') {
|
|
281
|
-
if (parseFloat(this.cmi.core.score.raw) >=
|
|
282
|
-
parseFloat(this.cmi.student_data.mastery_score)) {
|
|
281
|
+
if (parseFloat(this.cmi.core.score.raw) >= parseFloat(this.cmi.student_data.mastery_score)) {
|
|
283
282
|
this.cmi.core.lesson_status = 'passed';
|
|
284
283
|
} else {
|
|
285
284
|
this.cmi.core.lesson_status = 'failed';
|
|
@@ -287,8 +286,7 @@ export default class Scorm12API extends BaseAPI {
|
|
|
287
286
|
}
|
|
288
287
|
}
|
|
289
288
|
} else if (this.cmi.core.lesson_mode === 'browse') {
|
|
290
|
-
if ((this.startingData?.cmi?.core?.lesson_status || '') === '' &&
|
|
291
|
-
originalStatus === 'not attempted') {
|
|
289
|
+
if ((this.startingData?.cmi?.core?.lesson_status || '') === '' && originalStatus === 'not attempted') {
|
|
292
290
|
this.cmi.core.lesson_status = 'browsed';
|
|
293
291
|
}
|
|
294
292
|
}
|
|
@@ -297,18 +295,13 @@ export default class Scorm12API extends BaseAPI {
|
|
|
297
295
|
const commitObject = this.renderCommitCMI(terminateCommit ||
|
|
298
296
|
this.settings.alwaysSendTotalTime);
|
|
299
297
|
|
|
298
|
+
if (this.apiLogLevel === global_constants.LOG_LEVEL_DEBUG) {
|
|
299
|
+
console.debug('Commit (terminated: ' + (terminateCommit ? 'yes' : 'no') + '): ');
|
|
300
|
+
console.debug(commitObject);
|
|
301
|
+
}
|
|
300
302
|
if (this.settings.lmsCommitUrl) {
|
|
301
|
-
|
|
302
|
-
console.debug('Commit (terminated: ' +
|
|
303
|
-
(terminateCommit ? 'yes' : 'no') + '): ');
|
|
304
|
-
console.debug(commitObject);
|
|
305
|
-
}
|
|
306
|
-
return this.processHttpRequest(this.settings.lmsCommitUrl, commitObject,
|
|
307
|
-
terminateCommit);
|
|
303
|
+
return this.processHttpRequest(this.settings.lmsCommitUrl, commitObject, terminateCommit);
|
|
308
304
|
} else {
|
|
309
|
-
console.log('Commit (terminated: ' +
|
|
310
|
-
(terminateCommit ? 'yes' : 'no') + '): ');
|
|
311
|
-
console.log(commitObject);
|
|
312
305
|
return global_constants.SCORM_TRUE;
|
|
313
306
|
}
|
|
314
307
|
}
|
package/src/Scorm2004API.js
CHANGED
|
@@ -548,12 +548,12 @@ export default class Scorm2004API extends BaseAPI {
|
|
|
548
548
|
const commitObject = this.renderCommitCMI(terminateCommit ||
|
|
549
549
|
this.settings.alwaysSendTotalTime);
|
|
550
550
|
|
|
551
|
-
if (this.
|
|
552
|
-
|
|
553
|
-
console.debug('Commit (terminated: ' +
|
|
551
|
+
if (this.apiLogLevel === global_constants.LOG_LEVEL_DEBUG) {
|
|
552
|
+
console.debug('Commit (terminated: ' +
|
|
554
553
|
(terminateCommit ? 'yes' : 'no') + '): ');
|
|
555
|
-
|
|
556
|
-
|
|
554
|
+
console.debug(commitObject);
|
|
555
|
+
}
|
|
556
|
+
if (this.settings.lmsCommitUrl) {
|
|
557
557
|
const result = this.processHttpRequest(this.settings.lmsCommitUrl,
|
|
558
558
|
commitObject, terminateCommit);
|
|
559
559
|
|
|
@@ -566,9 +566,6 @@ export default class Scorm2004API extends BaseAPI {
|
|
|
566
566
|
}
|
|
567
567
|
return result;
|
|
568
568
|
} else {
|
|
569
|
-
console.log('Commit (terminated: ' +
|
|
570
|
-
(terminateCommit ? 'yes' : 'no') + '): ');
|
|
571
|
-
console.log(commitObject);
|
|
572
569
|
return global_constants.SCORM_TRUE;
|
|
573
570
|
}
|
|
574
571
|
}
|
package/src/cmi/aicc_cmi.js
CHANGED
|
@@ -1,16 +1,40 @@
|
|
|
1
1
|
import * as Scorm12CMI from './scorm12_cmi';
|
|
2
|
-
import {BaseCMI, CMIArray, CMIScore} from './common';
|
|
2
|
+
import {BaseCMI, checkValidFormat, CMIArray, CMIScore} from './common';
|
|
3
3
|
import APIConstants from '../constants/api_constants';
|
|
4
4
|
import Regex from '../constants/regex';
|
|
5
5
|
import ErrorCodes from '../constants/error_codes';
|
|
6
|
-
import {
|
|
7
|
-
check12ValidFormat,
|
|
8
|
-
throwReadOnlyError,
|
|
9
|
-
} from './scorm12_cmi';
|
|
6
|
+
import {AICCValidationError} from '../exceptions';
|
|
10
7
|
|
|
11
8
|
const aicc_constants = APIConstants.aicc;
|
|
12
9
|
const aicc_regex = Regex.aicc;
|
|
13
|
-
const
|
|
10
|
+
const aicc_error_codes = ErrorCodes.scorm12;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Helper method for throwing Read Only error
|
|
14
|
+
*/
|
|
15
|
+
function throwReadOnlyError() {
|
|
16
|
+
throw new AICCValidationError(aicc_error_codes.READ_ONLY_ELEMENT);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Helper method, no reason to have to pass the same error codes every time
|
|
21
|
+
* @param {*} value
|
|
22
|
+
* @param {string} regexPattern
|
|
23
|
+
* @param {boolean} allowEmptyString
|
|
24
|
+
* @return {boolean}
|
|
25
|
+
*/
|
|
26
|
+
function checkAICCValidFormat(
|
|
27
|
+
value: String,
|
|
28
|
+
regexPattern: String,
|
|
29
|
+
allowEmptyString?: boolean) {
|
|
30
|
+
return checkValidFormat(
|
|
31
|
+
value,
|
|
32
|
+
regexPattern,
|
|
33
|
+
aicc_error_codes.TYPE_MISMATCH,
|
|
34
|
+
AICCValidationError,
|
|
35
|
+
allowEmptyString
|
|
36
|
+
);
|
|
37
|
+
}
|
|
14
38
|
|
|
15
39
|
/**
|
|
16
40
|
* CMI Class for AICC
|
|
@@ -126,8 +150,11 @@ class CMIEvaluationComments extends CMIArray {
|
|
|
126
150
|
* Constructor for AICC Evaluation Comments object
|
|
127
151
|
*/
|
|
128
152
|
constructor() {
|
|
129
|
-
super(
|
|
130
|
-
|
|
153
|
+
super({
|
|
154
|
+
children: aicc_constants.comments_children,
|
|
155
|
+
errorCode: aicc_error_codes.INVALID_SET_VALUE,
|
|
156
|
+
errorClass: AICCValidationError,
|
|
157
|
+
});
|
|
131
158
|
}
|
|
132
159
|
}
|
|
133
160
|
|
|
@@ -142,7 +169,8 @@ class AICCStudentPreferences extends Scorm12CMI.CMIStudentPreference {
|
|
|
142
169
|
super(aicc_constants.student_preference_children);
|
|
143
170
|
|
|
144
171
|
this.windows = new CMIArray({
|
|
145
|
-
errorCode:
|
|
172
|
+
errorCode: aicc_error_codes.INVALID_SET_VALUE,
|
|
173
|
+
errorClass: AICCValidationError,
|
|
146
174
|
children: '',
|
|
147
175
|
});
|
|
148
176
|
}
|
|
@@ -174,7 +202,7 @@ class AICCStudentPreferences extends Scorm12CMI.CMIStudentPreference {
|
|
|
174
202
|
* @param {string} lesson_type
|
|
175
203
|
*/
|
|
176
204
|
set lesson_type(lesson_type: string) {
|
|
177
|
-
if (
|
|
205
|
+
if (checkAICCValidFormat(lesson_type, aicc_regex.CMIString256)) {
|
|
178
206
|
this.#lesson_type = lesson_type;
|
|
179
207
|
}
|
|
180
208
|
}
|
|
@@ -192,7 +220,7 @@ class AICCStudentPreferences extends Scorm12CMI.CMIStudentPreference {
|
|
|
192
220
|
* @param {string} text_color
|
|
193
221
|
*/
|
|
194
222
|
set text_color(text_color: string) {
|
|
195
|
-
if (
|
|
223
|
+
if (checkAICCValidFormat(text_color, aicc_regex.CMIString256)) {
|
|
196
224
|
this.#text_color = text_color;
|
|
197
225
|
}
|
|
198
226
|
}
|
|
@@ -210,7 +238,7 @@ class AICCStudentPreferences extends Scorm12CMI.CMIStudentPreference {
|
|
|
210
238
|
* @param {string} text_location
|
|
211
239
|
*/
|
|
212
240
|
set text_location(text_location: string) {
|
|
213
|
-
if (
|
|
241
|
+
if (checkAICCValidFormat(text_location, aicc_regex.CMIString256)) {
|
|
214
242
|
this.#text_location = text_location;
|
|
215
243
|
}
|
|
216
244
|
}
|
|
@@ -228,7 +256,7 @@ class AICCStudentPreferences extends Scorm12CMI.CMIStudentPreference {
|
|
|
228
256
|
* @param {string} text_size
|
|
229
257
|
*/
|
|
230
258
|
set text_size(text_size: string) {
|
|
231
|
-
if (
|
|
259
|
+
if (checkAICCValidFormat(text_size, aicc_regex.CMIString256)) {
|
|
232
260
|
this.#text_size = text_size;
|
|
233
261
|
}
|
|
234
262
|
}
|
|
@@ -246,7 +274,7 @@ class AICCStudentPreferences extends Scorm12CMI.CMIStudentPreference {
|
|
|
246
274
|
* @param {string} video
|
|
247
275
|
*/
|
|
248
276
|
set video(video: string) {
|
|
249
|
-
if (
|
|
277
|
+
if (checkAICCValidFormat(video, aicc_regex.CMIString256)) {
|
|
250
278
|
this.#video = video;
|
|
251
279
|
}
|
|
252
280
|
}
|
|
@@ -374,6 +402,14 @@ export class CMIStudentDemographics extends BaseCMI {
|
|
|
374
402
|
#telephone = '';
|
|
375
403
|
#years_experience = '';
|
|
376
404
|
|
|
405
|
+
/**
|
|
406
|
+
* Getter for _children
|
|
407
|
+
* @return {string}
|
|
408
|
+
*/
|
|
409
|
+
get _children() {
|
|
410
|
+
return this.#_children;
|
|
411
|
+
}
|
|
412
|
+
|
|
377
413
|
/**
|
|
378
414
|
* Getter for city
|
|
379
415
|
* @return {string}
|
|
@@ -671,7 +707,7 @@ export class CMIPaths extends CMIArray {
|
|
|
671
707
|
* Constructor for inline Paths Array class
|
|
672
708
|
*/
|
|
673
709
|
constructor() {
|
|
674
|
-
super(aicc_constants.paths_children);
|
|
710
|
+
super({children: aicc_constants.paths_children});
|
|
675
711
|
}
|
|
676
712
|
}
|
|
677
713
|
|
|
@@ -706,7 +742,7 @@ export class CMIPathsObject extends BaseCMI {
|
|
|
706
742
|
* @param {string} location_id
|
|
707
743
|
*/
|
|
708
744
|
set location_id(location_id) {
|
|
709
|
-
if (
|
|
745
|
+
if (checkAICCValidFormat(location_id, aicc_regex.CMIString256)) {
|
|
710
746
|
this.#location_id = location_id;
|
|
711
747
|
}
|
|
712
748
|
}
|
|
@@ -724,7 +760,7 @@ export class CMIPathsObject extends BaseCMI {
|
|
|
724
760
|
* @param {string} date
|
|
725
761
|
*/
|
|
726
762
|
set date(date) {
|
|
727
|
-
if (
|
|
763
|
+
if (checkAICCValidFormat(date, aicc_regex.CMIString256)) {
|
|
728
764
|
this.#date = date;
|
|
729
765
|
}
|
|
730
766
|
}
|
|
@@ -742,7 +778,7 @@ export class CMIPathsObject extends BaseCMI {
|
|
|
742
778
|
* @param {string} time
|
|
743
779
|
*/
|
|
744
780
|
set time(time) {
|
|
745
|
-
if (
|
|
781
|
+
if (checkAICCValidFormat(time, aicc_regex.CMITime)) {
|
|
746
782
|
this.#time = time;
|
|
747
783
|
}
|
|
748
784
|
}
|
|
@@ -760,7 +796,7 @@ export class CMIPathsObject extends BaseCMI {
|
|
|
760
796
|
* @param {string} status
|
|
761
797
|
*/
|
|
762
798
|
set status(status) {
|
|
763
|
-
if (
|
|
799
|
+
if (checkAICCValidFormat(status, aicc_regex.CMIStatus2)) {
|
|
764
800
|
this.#status = status;
|
|
765
801
|
}
|
|
766
802
|
}
|
|
@@ -778,7 +814,7 @@ export class CMIPathsObject extends BaseCMI {
|
|
|
778
814
|
* @param {string} why_left
|
|
779
815
|
*/
|
|
780
816
|
set why_left(why_left) {
|
|
781
|
-
if (
|
|
817
|
+
if (checkAICCValidFormat(why_left, aicc_regex.CMIString256)) {
|
|
782
818
|
this.#why_left = why_left;
|
|
783
819
|
}
|
|
784
820
|
}
|
|
@@ -796,7 +832,7 @@ export class CMIPathsObject extends BaseCMI {
|
|
|
796
832
|
* @param {string} time_in_element
|
|
797
833
|
*/
|
|
798
834
|
set time_in_element(time_in_element) {
|
|
799
|
-
if (
|
|
835
|
+
if (checkAICCValidFormat(time_in_element, aicc_regex.CMITime)) {
|
|
800
836
|
this.#time_in_element = time_in_element;
|
|
801
837
|
}
|
|
802
838
|
}
|
|
@@ -837,7 +873,7 @@ export class CMITries extends CMIArray {
|
|
|
837
873
|
* Constructor for inline Tries Array class
|
|
838
874
|
*/
|
|
839
875
|
constructor() {
|
|
840
|
-
super(aicc_constants.tries_children);
|
|
876
|
+
super({children: aicc_constants.tries_children});
|
|
841
877
|
}
|
|
842
878
|
}
|
|
843
879
|
|
|
@@ -855,9 +891,10 @@ export class CMITriesObject extends BaseCMI {
|
|
|
855
891
|
{
|
|
856
892
|
score_children: aicc_constants.score_children,
|
|
857
893
|
score_range: aicc_regex.score_range,
|
|
858
|
-
invalidErrorCode:
|
|
859
|
-
invalidTypeCode:
|
|
860
|
-
invalidRangeCode:
|
|
894
|
+
invalidErrorCode: aicc_error_codes.INVALID_SET_VALUE,
|
|
895
|
+
invalidTypeCode: aicc_error_codes.TYPE_MISMATCH,
|
|
896
|
+
invalidRangeCode: aicc_error_codes.VALUE_OUT_OF_RANGE,
|
|
897
|
+
errorClass: AICCValidationError,
|
|
861
898
|
});
|
|
862
899
|
}
|
|
863
900
|
|
|
@@ -885,7 +922,7 @@ export class CMITriesObject extends BaseCMI {
|
|
|
885
922
|
* @param {string} status
|
|
886
923
|
*/
|
|
887
924
|
set status(status) {
|
|
888
|
-
if (
|
|
925
|
+
if (checkAICCValidFormat(status, aicc_regex.CMIStatus2)) {
|
|
889
926
|
this.#status = status;
|
|
890
927
|
}
|
|
891
928
|
}
|
|
@@ -903,7 +940,7 @@ export class CMITriesObject extends BaseCMI {
|
|
|
903
940
|
* @param {string} time
|
|
904
941
|
*/
|
|
905
942
|
set time(time) {
|
|
906
|
-
if (
|
|
943
|
+
if (checkAICCValidFormat(time, aicc_regex.CMITime)) {
|
|
907
944
|
this.#time = time;
|
|
908
945
|
}
|
|
909
946
|
}
|
|
@@ -938,7 +975,7 @@ export class CMIAttemptRecords extends CMIArray {
|
|
|
938
975
|
* Constructor for inline Tries Array class
|
|
939
976
|
*/
|
|
940
977
|
constructor() {
|
|
941
|
-
super(aicc_constants.attempt_records_children);
|
|
978
|
+
super({children: aicc_constants.attempt_records_children});
|
|
942
979
|
}
|
|
943
980
|
}
|
|
944
981
|
|
|
@@ -956,9 +993,10 @@ export class CMIAttemptRecordsObject extends BaseCMI {
|
|
|
956
993
|
{
|
|
957
994
|
score_children: aicc_constants.score_children,
|
|
958
995
|
score_range: aicc_regex.score_range,
|
|
959
|
-
invalidErrorCode:
|
|
960
|
-
invalidTypeCode:
|
|
961
|
-
invalidRangeCode:
|
|
996
|
+
invalidErrorCode: aicc_error_codes.INVALID_SET_VALUE,
|
|
997
|
+
invalidTypeCode: aicc_error_codes.TYPE_MISMATCH,
|
|
998
|
+
invalidRangeCode: aicc_error_codes.VALUE_OUT_OF_RANGE,
|
|
999
|
+
errorClass: AICCValidationError,
|
|
962
1000
|
});
|
|
963
1001
|
}
|
|
964
1002
|
|
|
@@ -985,7 +1023,7 @@ export class CMIAttemptRecordsObject extends BaseCMI {
|
|
|
985
1023
|
* @param {string} lesson_status
|
|
986
1024
|
*/
|
|
987
1025
|
set lesson_status(lesson_status) {
|
|
988
|
-
if (
|
|
1026
|
+
if (checkAICCValidFormat(lesson_status, aicc_regex.CMIStatus2)) {
|
|
989
1027
|
this.#lesson_status = lesson_status;
|
|
990
1028
|
}
|
|
991
1029
|
}
|
|
@@ -1039,7 +1077,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
|
|
|
1039
1077
|
* @param {string} content
|
|
1040
1078
|
*/
|
|
1041
1079
|
set content(content) {
|
|
1042
|
-
if (
|
|
1080
|
+
if (checkAICCValidFormat(content, aicc_regex.CMIString256)) {
|
|
1043
1081
|
this.#content = content;
|
|
1044
1082
|
}
|
|
1045
1083
|
}
|
|
@@ -1057,7 +1095,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
|
|
|
1057
1095
|
* @param {string} location
|
|
1058
1096
|
*/
|
|
1059
1097
|
set location(location) {
|
|
1060
|
-
if (
|
|
1098
|
+
if (checkAICCValidFormat(location, aicc_regex.CMIString256)) {
|
|
1061
1099
|
this.#location = location;
|
|
1062
1100
|
}
|
|
1063
1101
|
}
|
|
@@ -1075,7 +1113,7 @@ export class CMIEvaluationCommentsObject extends BaseCMI {
|
|
|
1075
1113
|
* @param {string} time
|
|
1076
1114
|
*/
|
|
1077
1115
|
set time(time) {
|
|
1078
|
-
if (
|
|
1116
|
+
if (checkAICCValidFormat(time, aicc_regex.CMITime)) {
|
|
1079
1117
|
this.#time = time;
|
|
1080
1118
|
}
|
|
1081
1119
|
}
|
package/src/cmi/common.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import APIConstants from '../constants/api_constants';
|
|
3
3
|
import ErrorCodes from '../constants/error_codes';
|
|
4
|
-
import {ValidationError} from '../exceptions';
|
|
5
4
|
import Regex from '../constants/regex';
|
|
6
5
|
|
|
7
6
|
const scorm12_constants = APIConstants.scorm12;
|
|
@@ -14,6 +13,7 @@ const scorm12_error_codes = ErrorCodes.scorm12;
|
|
|
14
13
|
* @param {string} value
|
|
15
14
|
* @param {string} regexPattern
|
|
16
15
|
* @param {number} errorCode
|
|
16
|
+
* @param {class} errorClass
|
|
17
17
|
* @param {boolean} allowEmptyString
|
|
18
18
|
* @return {boolean}
|
|
19
19
|
*/
|
|
@@ -21,6 +21,7 @@ export function checkValidFormat(
|
|
|
21
21
|
value: String,
|
|
22
22
|
regexPattern: String,
|
|
23
23
|
errorCode: number,
|
|
24
|
+
errorClass: function,
|
|
24
25
|
allowEmptyString?: boolean) {
|
|
25
26
|
const formatRegex = new RegExp(regexPattern);
|
|
26
27
|
const matches = value.match(formatRegex);
|
|
@@ -28,7 +29,7 @@ export function checkValidFormat(
|
|
|
28
29
|
return true;
|
|
29
30
|
}
|
|
30
31
|
if (value === undefined || !matches || matches[0] === '') {
|
|
31
|
-
throw new
|
|
32
|
+
throw new errorClass.prototype.constructor(errorCode);
|
|
32
33
|
}
|
|
33
34
|
return true;
|
|
34
35
|
}
|
|
@@ -39,20 +40,24 @@ export function checkValidFormat(
|
|
|
39
40
|
* @param {*} value
|
|
40
41
|
* @param {string} rangePattern
|
|
41
42
|
* @param {number} errorCode
|
|
43
|
+
* @param {class} errorClass
|
|
42
44
|
* @return {boolean}
|
|
43
45
|
*/
|
|
44
46
|
export function checkValidRange(
|
|
45
|
-
value: any,
|
|
47
|
+
value: any,
|
|
48
|
+
rangePattern: String,
|
|
49
|
+
errorCode: number,
|
|
50
|
+
errorClass: function) {
|
|
46
51
|
const ranges = rangePattern.split('#');
|
|
47
52
|
value = value * 1.0;
|
|
48
53
|
if (value >= ranges[0]) {
|
|
49
54
|
if ((ranges[1] === '*') || (value <= ranges[1])) {
|
|
50
55
|
return true;
|
|
51
56
|
} else {
|
|
52
|
-
throw new
|
|
57
|
+
throw new errorClass.prototype.constructor(errorCode);
|
|
53
58
|
}
|
|
54
59
|
} else {
|
|
55
|
-
throw new
|
|
60
|
+
throw new errorClass.prototype.constructor(errorCode);
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
|
|
@@ -118,6 +123,7 @@ export class CMIScore extends BaseCMI {
|
|
|
118
123
|
* @param {number} invalidTypeCode
|
|
119
124
|
* @param {number} invalidRangeCode
|
|
120
125
|
* @param {string} decimalRegex
|
|
126
|
+
* @param {class} errorClass
|
|
121
127
|
*/
|
|
122
128
|
constructor(
|
|
123
129
|
{
|
|
@@ -128,6 +134,7 @@ export class CMIScore extends BaseCMI {
|
|
|
128
134
|
invalidTypeCode,
|
|
129
135
|
invalidRangeCode,
|
|
130
136
|
decimalRegex,
|
|
137
|
+
errorClass,
|
|
131
138
|
}) {
|
|
132
139
|
super();
|
|
133
140
|
|
|
@@ -143,6 +150,7 @@ export class CMIScore extends BaseCMI {
|
|
|
143
150
|
scorm12_error_codes.VALUE_OUT_OF_RANGE;
|
|
144
151
|
this.#_decimal_regex = decimalRegex ||
|
|
145
152
|
scorm12_regex.CMIDecimal;
|
|
153
|
+
this.#_error_class = errorClass;
|
|
146
154
|
}
|
|
147
155
|
|
|
148
156
|
#_children;
|
|
@@ -151,6 +159,7 @@ export class CMIScore extends BaseCMI {
|
|
|
151
159
|
#_invalid_type_code;
|
|
152
160
|
#_invalid_range_code;
|
|
153
161
|
#_decimal_regex;
|
|
162
|
+
#_error_class;
|
|
154
163
|
#raw = '';
|
|
155
164
|
#min = '';
|
|
156
165
|
#max;
|
|
@@ -170,7 +179,7 @@ export class CMIScore extends BaseCMI {
|
|
|
170
179
|
* @private
|
|
171
180
|
*/
|
|
172
181
|
set _children(_children) {
|
|
173
|
-
throw new
|
|
182
|
+
throw new this.#_error_class.prototype.constructor(this.#_invalid_error_code);
|
|
174
183
|
}
|
|
175
184
|
|
|
176
185
|
/**
|
|
@@ -186,11 +195,9 @@ export class CMIScore extends BaseCMI {
|
|
|
186
195
|
* @param {string} raw
|
|
187
196
|
*/
|
|
188
197
|
set raw(raw) {
|
|
189
|
-
if (checkValidFormat(raw, this.#_decimal_regex,
|
|
190
|
-
this.#_invalid_type_code) &&
|
|
198
|
+
if (checkValidFormat(raw, this.#_decimal_regex, this.#_invalid_type_code, this.#_error_class) &&
|
|
191
199
|
(!this.#_score_range ||
|
|
192
|
-
checkValidRange(raw, this.#_score_range,
|
|
193
|
-
this.#_invalid_range_code))) {
|
|
200
|
+
checkValidRange(raw, this.#_score_range, this.#_invalid_range_code, this.#_error_class))) {
|
|
194
201
|
this.#raw = raw;
|
|
195
202
|
}
|
|
196
203
|
}
|
|
@@ -208,11 +215,9 @@ export class CMIScore extends BaseCMI {
|
|
|
208
215
|
* @param {string} min
|
|
209
216
|
*/
|
|
210
217
|
set min(min) {
|
|
211
|
-
if (checkValidFormat(min, this.#_decimal_regex,
|
|
212
|
-
this.#_invalid_type_code) &&
|
|
218
|
+
if (checkValidFormat(min, this.#_decimal_regex, this.#_invalid_type_code, this.#_error_class) &&
|
|
213
219
|
(!this.#_score_range ||
|
|
214
|
-
checkValidRange(min, this.#_score_range,
|
|
215
|
-
this.#_invalid_range_code))) {
|
|
220
|
+
checkValidRange(min, this.#_score_range, this.#_invalid_range_code, this.#_error_class))) {
|
|
216
221
|
this.#min = min;
|
|
217
222
|
}
|
|
218
223
|
}
|
|
@@ -230,11 +235,9 @@ export class CMIScore extends BaseCMI {
|
|
|
230
235
|
* @param {string} max
|
|
231
236
|
*/
|
|
232
237
|
set max(max) {
|
|
233
|
-
if (checkValidFormat(max, this.#_decimal_regex,
|
|
234
|
-
this.#_invalid_type_code) &&
|
|
238
|
+
if (checkValidFormat(max, this.#_decimal_regex, this.#_invalid_type_code, this.#_error_class) &&
|
|
235
239
|
(!this.#_score_range ||
|
|
236
|
-
checkValidRange(max, this.#_score_range,
|
|
237
|
-
this.#_invalid_range_code))) {
|
|
240
|
+
checkValidRange(max, this.#_score_range, this.#_invalid_range_code, this.#_error_class))) {
|
|
238
241
|
this.#max = max;
|
|
239
242
|
}
|
|
240
243
|
}
|
|
@@ -263,15 +266,18 @@ export class CMIArray extends BaseCMI {
|
|
|
263
266
|
* Constructor cmi *.n arrays
|
|
264
267
|
* @param {string} children
|
|
265
268
|
* @param {number} errorCode
|
|
269
|
+
* @param {class} errorClass
|
|
266
270
|
*/
|
|
267
|
-
constructor({children, errorCode}) {
|
|
271
|
+
constructor({children, errorCode, errorClass}) {
|
|
268
272
|
super();
|
|
269
273
|
this.#_children = children;
|
|
270
274
|
this.#errorCode = errorCode;
|
|
275
|
+
this.#errorClass = errorClass;
|
|
271
276
|
this.childArray = [];
|
|
272
277
|
}
|
|
273
278
|
|
|
274
279
|
#errorCode;
|
|
280
|
+
#errorClass;
|
|
275
281
|
#_children;
|
|
276
282
|
|
|
277
283
|
/**
|
|
@@ -287,7 +293,7 @@ export class CMIArray extends BaseCMI {
|
|
|
287
293
|
* @param {string} _children
|
|
288
294
|
*/
|
|
289
295
|
set _children(_children) {
|
|
290
|
-
throw new
|
|
296
|
+
throw new this.#errorClass.prototype.constructor(this.#errorCode);
|
|
291
297
|
}
|
|
292
298
|
|
|
293
299
|
/**
|
|
@@ -303,7 +309,7 @@ export class CMIArray extends BaseCMI {
|
|
|
303
309
|
* @param {number} _count
|
|
304
310
|
*/
|
|
305
311
|
set _count(_count) {
|
|
306
|
-
throw new
|
|
312
|
+
throw new this.#errorClass.prototype.constructor(this.#errorCode);
|
|
307
313
|
}
|
|
308
314
|
|
|
309
315
|
/**
|
package/src/cmi/scorm12_cmi.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import APIConstants from '../constants/api_constants';
|
|
10
10
|
import ErrorCodes from '../constants/error_codes';
|
|
11
11
|
import Regex from '../constants/regex';
|
|
12
|
-
import {
|
|
12
|
+
import {Scorm12ValidationError} from '../exceptions';
|
|
13
13
|
import * as Utilities from '../utilities';
|
|
14
14
|
import * as Util from '../utilities';
|
|
15
15
|
|
|
@@ -21,21 +21,21 @@ const scorm12_error_codes = ErrorCodes.scorm12;
|
|
|
21
21
|
* Helper method for throwing Read Only error
|
|
22
22
|
*/
|
|
23
23
|
export function throwReadOnlyError() {
|
|
24
|
-
throw new
|
|
24
|
+
throw new Scorm12ValidationError(scorm12_error_codes.READ_ONLY_ELEMENT);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Helper method for throwing Write Only error
|
|
29
29
|
*/
|
|
30
30
|
export function throwWriteOnlyError() {
|
|
31
|
-
throw new
|
|
31
|
+
throw new Scorm12ValidationError(scorm12_error_codes.WRITE_ONLY_ELEMENT);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Helper method for throwing Invalid Set error
|
|
36
36
|
*/
|
|
37
37
|
function throwInvalidValueError() {
|
|
38
|
-
throw new
|
|
38
|
+
throw new Scorm12ValidationError(scorm12_error_codes.INVALID_SET_VALUE);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/**
|
|
@@ -49,8 +49,13 @@ export function check12ValidFormat(
|
|
|
49
49
|
value: String,
|
|
50
50
|
regexPattern: String,
|
|
51
51
|
allowEmptyString?: boolean) {
|
|
52
|
-
return checkValidFormat(
|
|
53
|
-
|
|
52
|
+
return checkValidFormat(
|
|
53
|
+
value,
|
|
54
|
+
regexPattern,
|
|
55
|
+
scorm12_error_codes.TYPE_MISMATCH,
|
|
56
|
+
Scorm12ValidationError,
|
|
57
|
+
allowEmptyString
|
|
58
|
+
);
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
/**
|
|
@@ -64,8 +69,13 @@ export function check12ValidRange(
|
|
|
64
69
|
value: any,
|
|
65
70
|
rangePattern: String,
|
|
66
71
|
allowEmptyString?: boolean) {
|
|
67
|
-
return checkValidRange(
|
|
68
|
-
|
|
72
|
+
return checkValidRange(
|
|
73
|
+
value,
|
|
74
|
+
rangePattern,
|
|
75
|
+
scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
|
76
|
+
Scorm12ValidationError,
|
|
77
|
+
allowEmptyString
|
|
78
|
+
);
|
|
69
79
|
}
|
|
70
80
|
|
|
71
81
|
/**
|
|
@@ -277,6 +287,7 @@ class CMICore extends BaseCMI {
|
|
|
277
287
|
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
|
|
278
288
|
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
|
|
279
289
|
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
|
290
|
+
errorClass: Scorm12ValidationError,
|
|
280
291
|
});
|
|
281
292
|
}
|
|
282
293
|
|
|
@@ -583,6 +594,7 @@ class CMIObjectives extends CMIArray {
|
|
|
583
594
|
super({
|
|
584
595
|
children: scorm12_constants.objectives_children,
|
|
585
596
|
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
|
|
597
|
+
errorClass: Scorm12ValidationError,
|
|
586
598
|
});
|
|
587
599
|
}
|
|
588
600
|
}
|
|
@@ -858,6 +870,7 @@ class CMIInteractions extends CMIArray {
|
|
|
858
870
|
super({
|
|
859
871
|
children: scorm12_constants.interactions_children,
|
|
860
872
|
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
|
|
873
|
+
errorClass: Scorm12ValidationError,
|
|
861
874
|
});
|
|
862
875
|
}
|
|
863
876
|
}
|
|
@@ -875,10 +888,12 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
875
888
|
|
|
876
889
|
this.objectives = new CMIArray({
|
|
877
890
|
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
|
|
891
|
+
errorClass: Scorm12ValidationError,
|
|
878
892
|
children: scorm12_constants.objectives_children,
|
|
879
893
|
});
|
|
880
894
|
this.correct_responses = new CMIArray({
|
|
881
895
|
errorCode: scorm12_error_codes.INVALID_SET_VALUE,
|
|
896
|
+
errorClass: Scorm12ValidationError,
|
|
882
897
|
children: scorm12_constants.correct_responses_children,
|
|
883
898
|
});
|
|
884
899
|
}
|
|
@@ -1082,6 +1097,7 @@ export class CMIObjectivesObject extends BaseCMI {
|
|
|
1082
1097
|
invalidErrorCode: scorm12_error_codes.INVALID_SET_VALUE,
|
|
1083
1098
|
invalidTypeCode: scorm12_error_codes.TYPE_MISMATCH,
|
|
1084
1099
|
invalidRangeCode: scorm12_error_codes.VALUE_OUT_OF_RANGE,
|
|
1100
|
+
errorClass: Scorm12ValidationError,
|
|
1085
1101
|
});
|
|
1086
1102
|
}
|
|
1087
1103
|
|