scorm-again 2.5.0 → 2.6.1
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/dist/aicc.js +657 -489
- package/dist/aicc.js.map +1 -1
- package/dist/aicc.min.js +1 -1
- package/dist/aicc.min.js.map +1 -1
- package/dist/esm/aicc.js +670 -489
- package/dist/esm/aicc.js.map +1 -1
- package/dist/esm/aicc.min.js +1 -1
- package/dist/esm/aicc.min.js.map +1 -1
- package/dist/esm/scorm-again.js +1113 -729
- package/dist/esm/scorm-again.js.map +1 -1
- package/dist/esm/scorm-again.min.js +1 -1
- package/dist/esm/scorm-again.min.js.map +1 -1
- package/dist/esm/scorm12.js +512 -394
- package/dist/esm/scorm12.js.map +1 -1
- package/dist/esm/scorm12.min.js +1 -1
- package/dist/esm/scorm12.min.js.map +1 -1
- package/dist/esm/scorm2004.js +678 -452
- package/dist/esm/scorm2004.js.map +1 -1
- package/dist/esm/scorm2004.min.js +1 -1
- package/dist/esm/scorm2004.min.js.map +1 -1
- package/dist/scorm-again.js +1100 -728
- package/dist/scorm-again.js.map +1 -1
- package/dist/scorm-again.min.js +1 -1
- package/dist/scorm-again.min.js.map +1 -1
- package/dist/scorm12.js +500 -394
- package/dist/scorm12.js.map +1 -1
- package/dist/scorm12.min.js +1 -1
- package/dist/scorm12.min.js.map +1 -1
- package/dist/scorm2004.js +665 -452
- package/dist/scorm2004.js.map +1 -1
- package/dist/scorm2004.min.js +1 -1
- package/dist/scorm2004.min.js.map +1 -1
- package/dist_test.html +208 -0
- package/package.json +14 -14
- package/src/AICC.ts +6 -3
- package/src/BaseAPI.ts +43 -37
- package/src/Scorm12API.ts +17 -23
- package/src/Scorm2004API.ts +99 -42
- package/src/ScormAgain.ts +3 -7
- package/src/cmi/aicc/attempts.ts +22 -12
- package/src/cmi/aicc/cmi.ts +2 -2
- package/src/cmi/aicc/core.ts +44 -26
- package/src/cmi/aicc/evaluation.ts +31 -12
- package/src/cmi/aicc/paths.ts +29 -15
- package/src/cmi/aicc/student_data.ts +14 -5
- package/src/cmi/aicc/student_demographics.ts +31 -24
- package/src/cmi/aicc/student_preferences.ts +11 -11
- package/src/cmi/aicc/tries.ts +24 -14
- package/src/cmi/aicc/validation.ts +3 -4
- package/src/cmi/common/array.ts +17 -5
- package/src/cmi/common/base_cmi.ts +3 -1
- package/src/cmi/common/score.ts +16 -13
- package/src/cmi/scorm12/cmi.ts +25 -10
- package/src/cmi/scorm12/interactions.ts +62 -28
- package/src/cmi/scorm12/nav.ts +13 -5
- package/src/cmi/scorm12/objectives.ts +28 -18
- package/src/cmi/scorm12/student_data.ts +15 -8
- package/src/cmi/scorm12/student_preference.ts +20 -13
- package/src/cmi/scorm12/validation.ts +7 -7
- package/src/cmi/scorm2004/adl.ts +141 -25
- package/src/cmi/scorm2004/cmi.ts +50 -55
- package/src/cmi/scorm2004/comments.ts +21 -20
- package/src/cmi/scorm2004/interactions.ts +73 -32
- package/src/cmi/scorm2004/learner_preference.ts +20 -13
- package/src/cmi/scorm2004/objectives.ts +41 -16
- package/src/cmi/scorm2004/score.ts +22 -11
- package/src/cmi/scorm2004/validation.ts +4 -4
- package/src/constants/api_constants.ts +8 -19
- package/src/constants/default_settings.ts +6 -5
- package/src/constants/error_codes.ts +5 -12
- package/src/constants/regex.ts +4 -10
- package/src/constants/response_constants.ts +1 -2
- package/src/exceptions/aicc_exceptions.ts +29 -0
- package/src/exceptions/scorm12_exceptions.ts +29 -0
- package/src/exceptions/scorm2004_exceptions.ts +29 -0
- package/src/exceptions.ts +0 -81
- package/src/types/api_types.ts +3 -2
- package/test/AICC.spec.ts +114 -43
- package/test/Scorm12API.spec.ts +60 -39
- package/test/Scorm2004API.spec.ts +165 -80
- package/test/cmi/aicc_cmi.spec.ts +6 -9
- package/test/cmi/scorm12_cmi.spec.ts +8 -8
- package/test/cmi/scorm2004_cmi.spec.ts +8 -9
- package/test/exceptions.spec.ts +11 -9
- package/test/types/api_types.spec.ts +3 -3
- package/test/utilities.spec.ts +1 -4
- package/webpack.config.js +5 -1
package/src/cmi/common/score.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { scorm12_constants } from "../../constants/api_constants";
|
|
2
|
+
import { scorm12_regex } from "../../constants/regex";
|
|
3
3
|
import { BaseCMI } from "./base_cmi";
|
|
4
4
|
import { checkValidFormat, checkValidRange } from "./validation";
|
|
5
|
-
import
|
|
5
|
+
import { scorm12_errors } from "../../constants/error_codes";
|
|
6
6
|
import { BaseScormValidationError } from "../../exceptions";
|
|
7
7
|
|
|
8
|
-
const scorm12_constants = APIConstants.scorm12;
|
|
9
|
-
const scorm12_regex = Regex.scorm12;
|
|
10
|
-
export const scorm12_error_codes = ErrorCodes.scorm12;
|
|
11
|
-
|
|
12
8
|
/**
|
|
13
9
|
* Base class for cmi *.score objects
|
|
14
10
|
*/
|
|
@@ -20,9 +16,9 @@ export class CMIScore extends BaseCMI {
|
|
|
20
16
|
private readonly __invalid_range_code: number;
|
|
21
17
|
private readonly __decimal_regex: string;
|
|
22
18
|
private readonly __error_class: typeof BaseScormValidationError;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
protected _raw = "";
|
|
20
|
+
protected _min = "";
|
|
21
|
+
protected _max: string;
|
|
26
22
|
|
|
27
23
|
/**
|
|
28
24
|
* Constructor for *.score
|
|
@@ -55,15 +51,22 @@ export class CMIScore extends BaseCMI {
|
|
|
55
51
|
: scorm12_regex.score_range;
|
|
56
52
|
this._max = params.max || params.max === "" ? params.max : "100";
|
|
57
53
|
this.__invalid_error_code =
|
|
58
|
-
params.invalidErrorCode ||
|
|
54
|
+
params.invalidErrorCode || scorm12_errors.INVALID_SET_VALUE;
|
|
59
55
|
this.__invalid_type_code =
|
|
60
|
-
params.invalidTypeCode ||
|
|
56
|
+
params.invalidTypeCode || scorm12_errors.TYPE_MISMATCH;
|
|
61
57
|
this.__invalid_range_code =
|
|
62
|
-
params.invalidRangeCode ||
|
|
58
|
+
params.invalidRangeCode || scorm12_errors.VALUE_OUT_OF_RANGE;
|
|
63
59
|
this.__decimal_regex = params.decimalRegex || scorm12_regex.CMIDecimal;
|
|
64
60
|
this.__error_class = params.errorClass;
|
|
65
61
|
}
|
|
66
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Called when the API has been reset
|
|
65
|
+
*/
|
|
66
|
+
reset(): void {
|
|
67
|
+
this._initialized = false;
|
|
68
|
+
}
|
|
69
|
+
|
|
67
70
|
/**
|
|
68
71
|
* Getter for _children
|
|
69
72
|
* @return {string}
|
package/src/cmi/scorm12/cmi.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Scorm12ValidationError } from "../../exceptions";
|
|
1
|
+
import { scorm12_constants } from "../../constants/api_constants";
|
|
2
|
+
import { scorm12_errors } from "../../constants/error_codes";
|
|
3
|
+
import { scorm12_regex } from "../../constants/regex";
|
|
4
|
+
import { Scorm12ValidationError } from "../../exceptions/scorm12_exceptions";
|
|
5
5
|
import { BaseRootCMI } from "../common/base_cmi";
|
|
6
6
|
import { check12ValidFormat } from "./validation";
|
|
7
7
|
import { CMICore } from "../aicc/core";
|
|
@@ -35,7 +35,7 @@ export class CMI extends BaseRootCMI {
|
|
|
35
35
|
if (initialized) this.initialize();
|
|
36
36
|
this.__children = cmi_children
|
|
37
37
|
? cmi_children
|
|
38
|
-
:
|
|
38
|
+
: scorm12_constants.cmi_children;
|
|
39
39
|
this.core = new CMICore();
|
|
40
40
|
this.objectives = new CMIObjectives();
|
|
41
41
|
this.student_data = student_data ? student_data : new CMIStudentData();
|
|
@@ -49,6 +49,21 @@ export class CMI extends BaseRootCMI {
|
|
|
49
49
|
public student_preference: CMIStudentPreference;
|
|
50
50
|
public interactions: CMIInteractions;
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Called when the API has been reset
|
|
54
|
+
*/
|
|
55
|
+
reset(): void {
|
|
56
|
+
this._initialized = false;
|
|
57
|
+
|
|
58
|
+
this._launch_data = "";
|
|
59
|
+
this._comments = "";
|
|
60
|
+
this.core?.reset();
|
|
61
|
+
this.objectives = new CMIObjectives();
|
|
62
|
+
this.interactions = new CMIInteractions();
|
|
63
|
+
this.student_data?.reset();
|
|
64
|
+
this.student_preference?.reset();
|
|
65
|
+
}
|
|
66
|
+
|
|
52
67
|
/**
|
|
53
68
|
* Called when the API has been initialized after the CMI has been created
|
|
54
69
|
*/
|
|
@@ -118,7 +133,7 @@ export class CMI extends BaseRootCMI {
|
|
|
118
133
|
* @param {string} _version
|
|
119
134
|
*/
|
|
120
135
|
set _version(_version: string) {
|
|
121
|
-
throw new Scorm12ValidationError(
|
|
136
|
+
throw new Scorm12ValidationError(scorm12_errors.INVALID_SET_VALUE);
|
|
122
137
|
}
|
|
123
138
|
|
|
124
139
|
/**
|
|
@@ -134,7 +149,7 @@ export class CMI extends BaseRootCMI {
|
|
|
134
149
|
* @param {string} _children
|
|
135
150
|
*/
|
|
136
151
|
set _children(_children: string) {
|
|
137
|
-
throw new Scorm12ValidationError(
|
|
152
|
+
throw new Scorm12ValidationError(scorm12_errors.INVALID_SET_VALUE);
|
|
138
153
|
}
|
|
139
154
|
|
|
140
155
|
/**
|
|
@@ -169,7 +184,7 @@ export class CMI extends BaseRootCMI {
|
|
|
169
184
|
*/
|
|
170
185
|
set launch_data(launch_data: string) {
|
|
171
186
|
if (this.initialized) {
|
|
172
|
-
throw new Scorm12ValidationError(
|
|
187
|
+
throw new Scorm12ValidationError(scorm12_errors.READ_ONLY_ELEMENT);
|
|
173
188
|
} else {
|
|
174
189
|
this._launch_data = launch_data;
|
|
175
190
|
}
|
|
@@ -188,7 +203,7 @@ export class CMI extends BaseRootCMI {
|
|
|
188
203
|
* @param {string} comments
|
|
189
204
|
*/
|
|
190
205
|
set comments(comments: string) {
|
|
191
|
-
if (check12ValidFormat(comments,
|
|
206
|
+
if (check12ValidFormat(comments, scorm12_regex.CMIString4096, true)) {
|
|
192
207
|
this._comments = comments;
|
|
193
208
|
}
|
|
194
209
|
}
|
|
@@ -207,7 +222,7 @@ export class CMI extends BaseRootCMI {
|
|
|
207
222
|
*/
|
|
208
223
|
set comments_from_lms(comments_from_lms: string) {
|
|
209
224
|
if (this.initialized) {
|
|
210
|
-
throw new Scorm12ValidationError(
|
|
225
|
+
throw new Scorm12ValidationError(scorm12_errors.READ_ONLY_ELEMENT);
|
|
211
226
|
} else {
|
|
212
227
|
this._comments_from_lms = comments_from_lms;
|
|
213
228
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { CMIArray } from "../common/array";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { Scorm12ValidationError } from "../../exceptions";
|
|
2
|
+
import { scorm12_constants } from "../../constants/api_constants";
|
|
3
|
+
import { scorm12_errors } from "../../constants/error_codes";
|
|
4
|
+
import { Scorm12ValidationError } from "../../exceptions/scorm12_exceptions";
|
|
5
5
|
import { BaseCMI } from "../common/base_cmi";
|
|
6
6
|
import { check12ValidFormat, check12ValidRange } from "./validation";
|
|
7
|
-
import
|
|
7
|
+
import { scorm12_regex } from "../../constants/regex";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Class representing the SCORM 1.2 `cmi.interactions`
|
|
@@ -16,8 +16,8 @@ export class CMIInteractions extends CMIArray {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor() {
|
|
18
18
|
super({
|
|
19
|
-
children:
|
|
20
|
-
errorCode:
|
|
19
|
+
children: scorm12_constants.interactions_children,
|
|
20
|
+
errorCode: scorm12_errors.INVALID_SET_VALUE,
|
|
21
21
|
errorClass: Scorm12ValidationError,
|
|
22
22
|
});
|
|
23
23
|
}
|
|
@@ -34,14 +34,14 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
34
34
|
constructor() {
|
|
35
35
|
super();
|
|
36
36
|
this.objectives = new CMIArray({
|
|
37
|
-
errorCode:
|
|
37
|
+
errorCode: scorm12_errors.INVALID_SET_VALUE,
|
|
38
38
|
errorClass: Scorm12ValidationError,
|
|
39
|
-
children:
|
|
39
|
+
children: scorm12_constants.objectives_children,
|
|
40
40
|
});
|
|
41
41
|
this.correct_responses = new CMIArray({
|
|
42
|
-
errorCode:
|
|
42
|
+
errorCode: scorm12_errors.INVALID_SET_VALUE,
|
|
43
43
|
errorClass: Scorm12ValidationError,
|
|
44
|
-
children:
|
|
44
|
+
children: scorm12_constants.correct_responses_children,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -65,13 +65,31 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
65
65
|
private _result = "";
|
|
66
66
|
private _latency = "";
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Called when the API has been reset
|
|
70
|
+
*/
|
|
71
|
+
override reset(): void {
|
|
72
|
+
this._initialized = false;
|
|
73
|
+
|
|
74
|
+
this._id = "";
|
|
75
|
+
this._time = "";
|
|
76
|
+
this._type = "";
|
|
77
|
+
this._weighting = "";
|
|
78
|
+
this._student_response = "";
|
|
79
|
+
this._result = "";
|
|
80
|
+
this._latency = "";
|
|
81
|
+
|
|
82
|
+
this.objectives?.reset();
|
|
83
|
+
this.correct_responses?.reset();
|
|
84
|
+
}
|
|
85
|
+
|
|
68
86
|
/**
|
|
69
87
|
* Getter for _id. Should only be called during JSON export.
|
|
70
88
|
* @return {string}
|
|
71
89
|
*/
|
|
72
90
|
get id(): string {
|
|
73
91
|
if (!this.jsonString) {
|
|
74
|
-
throw new Scorm12ValidationError(
|
|
92
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
75
93
|
}
|
|
76
94
|
return this._id;
|
|
77
95
|
}
|
|
@@ -81,7 +99,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
81
99
|
* @param {string} id
|
|
82
100
|
*/
|
|
83
101
|
set id(id: string) {
|
|
84
|
-
if (check12ValidFormat(id,
|
|
102
|
+
if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
|
|
85
103
|
this._id = id;
|
|
86
104
|
}
|
|
87
105
|
}
|
|
@@ -92,7 +110,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
92
110
|
*/
|
|
93
111
|
get time(): string {
|
|
94
112
|
if (!this.jsonString) {
|
|
95
|
-
throw new Scorm12ValidationError(
|
|
113
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
96
114
|
}
|
|
97
115
|
return this._time;
|
|
98
116
|
}
|
|
@@ -102,7 +120,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
102
120
|
* @param {string} time
|
|
103
121
|
*/
|
|
104
122
|
set time(time: string) {
|
|
105
|
-
if (check12ValidFormat(time,
|
|
123
|
+
if (check12ValidFormat(time, scorm12_regex.CMITime)) {
|
|
106
124
|
this._time = time;
|
|
107
125
|
}
|
|
108
126
|
}
|
|
@@ -113,7 +131,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
113
131
|
*/
|
|
114
132
|
get type(): string {
|
|
115
133
|
if (!this.jsonString) {
|
|
116
|
-
throw new Scorm12ValidationError(
|
|
134
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
117
135
|
}
|
|
118
136
|
return this._type;
|
|
119
137
|
}
|
|
@@ -123,7 +141,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
123
141
|
* @param {string} type
|
|
124
142
|
*/
|
|
125
143
|
set type(type: string) {
|
|
126
|
-
if (check12ValidFormat(type,
|
|
144
|
+
if (check12ValidFormat(type, scorm12_regex.CMIType)) {
|
|
127
145
|
this._type = type;
|
|
128
146
|
}
|
|
129
147
|
}
|
|
@@ -134,7 +152,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
134
152
|
*/
|
|
135
153
|
get weighting(): string {
|
|
136
154
|
if (!this.jsonString) {
|
|
137
|
-
throw new Scorm12ValidationError(
|
|
155
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
138
156
|
}
|
|
139
157
|
return this._weighting;
|
|
140
158
|
}
|
|
@@ -145,8 +163,8 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
145
163
|
*/
|
|
146
164
|
set weighting(weighting: string) {
|
|
147
165
|
if (
|
|
148
|
-
check12ValidFormat(weighting,
|
|
149
|
-
check12ValidRange(weighting,
|
|
166
|
+
check12ValidFormat(weighting, scorm12_regex.CMIDecimal) &&
|
|
167
|
+
check12ValidRange(weighting, scorm12_regex.weighting_range)
|
|
150
168
|
) {
|
|
151
169
|
this._weighting = weighting;
|
|
152
170
|
}
|
|
@@ -158,7 +176,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
158
176
|
*/
|
|
159
177
|
get student_response(): string {
|
|
160
178
|
if (!this.jsonString) {
|
|
161
|
-
throw new Scorm12ValidationError(
|
|
179
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
162
180
|
}
|
|
163
181
|
return this._student_response;
|
|
164
182
|
}
|
|
@@ -168,7 +186,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
168
186
|
* @param {string} student_response
|
|
169
187
|
*/
|
|
170
188
|
set student_response(student_response: string) {
|
|
171
|
-
if (check12ValidFormat(student_response,
|
|
189
|
+
if (check12ValidFormat(student_response, scorm12_regex.CMIFeedback, true)) {
|
|
172
190
|
this._student_response = student_response;
|
|
173
191
|
}
|
|
174
192
|
}
|
|
@@ -179,7 +197,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
179
197
|
*/
|
|
180
198
|
get result(): string {
|
|
181
199
|
if (!this.jsonString) {
|
|
182
|
-
throw new Scorm12ValidationError(
|
|
200
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
183
201
|
}
|
|
184
202
|
return this._result;
|
|
185
203
|
}
|
|
@@ -189,7 +207,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
189
207
|
* @param {string} result
|
|
190
208
|
*/
|
|
191
209
|
set result(result: string) {
|
|
192
|
-
if (check12ValidFormat(result,
|
|
210
|
+
if (check12ValidFormat(result, scorm12_regex.CMIResult)) {
|
|
193
211
|
this._result = result;
|
|
194
212
|
}
|
|
195
213
|
}
|
|
@@ -200,7 +218,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
200
218
|
*/
|
|
201
219
|
get latency(): string {
|
|
202
220
|
if (!this.jsonString) {
|
|
203
|
-
throw new Scorm12ValidationError(
|
|
221
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
204
222
|
}
|
|
205
223
|
return this._latency;
|
|
206
224
|
}
|
|
@@ -210,7 +228,7 @@ export class CMIInteractionsObject extends BaseCMI {
|
|
|
210
228
|
* @param {string} latency
|
|
211
229
|
*/
|
|
212
230
|
set latency(latency: string) {
|
|
213
|
-
if (check12ValidFormat(latency,
|
|
231
|
+
if (check12ValidFormat(latency, scorm12_regex.CMITimespan)) {
|
|
214
232
|
this._latency = latency;
|
|
215
233
|
}
|
|
216
234
|
}
|
|
@@ -274,6 +292,14 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
|
|
|
274
292
|
|
|
275
293
|
private _id = "";
|
|
276
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Called when the API has been reset
|
|
297
|
+
*/
|
|
298
|
+
reset(): void {
|
|
299
|
+
this._initialized = false;
|
|
300
|
+
this._id = "";
|
|
301
|
+
}
|
|
302
|
+
|
|
277
303
|
/**
|
|
278
304
|
* Getter for _id
|
|
279
305
|
* @return {string}
|
|
@@ -287,7 +313,7 @@ export class CMIInteractionsObjectivesObject extends BaseCMI {
|
|
|
287
313
|
* @param {string} id
|
|
288
314
|
*/
|
|
289
315
|
set id(id: string) {
|
|
290
|
-
if (check12ValidFormat(id,
|
|
316
|
+
if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
|
|
291
317
|
this._id = id;
|
|
292
318
|
}
|
|
293
319
|
}
|
|
@@ -326,13 +352,21 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
|
|
|
326
352
|
|
|
327
353
|
private _pattern = "";
|
|
328
354
|
|
|
355
|
+
/**
|
|
356
|
+
* Called when the API has been reset
|
|
357
|
+
*/
|
|
358
|
+
reset(): void {
|
|
359
|
+
this._initialized = false;
|
|
360
|
+
this._pattern = "";
|
|
361
|
+
}
|
|
362
|
+
|
|
329
363
|
/**
|
|
330
364
|
* Getter for _pattern
|
|
331
365
|
* @return {string}
|
|
332
366
|
*/
|
|
333
367
|
get pattern(): string {
|
|
334
368
|
if (!this.jsonString) {
|
|
335
|
-
throw new Scorm12ValidationError(
|
|
369
|
+
throw new Scorm12ValidationError(scorm12_errors.WRITE_ONLY_ELEMENT);
|
|
336
370
|
}
|
|
337
371
|
return this._pattern;
|
|
338
372
|
}
|
|
@@ -342,7 +376,7 @@ export class CMIInteractionsCorrectResponsesObject extends BaseCMI {
|
|
|
342
376
|
* @param {string} pattern
|
|
343
377
|
*/
|
|
344
378
|
set pattern(pattern: string) {
|
|
345
|
-
if (check12ValidFormat(pattern,
|
|
379
|
+
if (check12ValidFormat(pattern, scorm12_regex.CMIFeedback, true)) {
|
|
346
380
|
this._pattern = pattern;
|
|
347
381
|
}
|
|
348
382
|
}
|
package/src/cmi/scorm12/nav.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {BaseCMI} from "../common/base_cmi";
|
|
2
|
-
import {check12ValidFormat} from "./validation";
|
|
3
|
-
import
|
|
1
|
+
import { BaseCMI } from "../common/base_cmi";
|
|
2
|
+
import { check12ValidFormat } from "./validation";
|
|
3
|
+
import { scorm12_regex } from "../../constants/regex";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Class for AICC Navigation object
|
|
@@ -13,6 +13,14 @@ export class NAV extends BaseCMI {
|
|
|
13
13
|
super();
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Called when the API has been reset
|
|
18
|
+
*/
|
|
19
|
+
reset(): void {
|
|
20
|
+
this._event = "";
|
|
21
|
+
this._initialized = false;
|
|
22
|
+
}
|
|
23
|
+
|
|
16
24
|
private _event = "";
|
|
17
25
|
|
|
18
26
|
/**
|
|
@@ -28,7 +36,7 @@ export class NAV extends BaseCMI {
|
|
|
28
36
|
* @param {string} event
|
|
29
37
|
*/
|
|
30
38
|
set event(event: string) {
|
|
31
|
-
if (check12ValidFormat(event,
|
|
39
|
+
if (check12ValidFormat(event, scorm12_regex.NAVEvent)) {
|
|
32
40
|
this._event = event;
|
|
33
41
|
}
|
|
34
42
|
}
|
|
@@ -51,4 +59,4 @@ export class NAV extends BaseCMI {
|
|
|
51
59
|
delete this.jsonString;
|
|
52
60
|
return result;
|
|
53
61
|
}
|
|
54
|
-
}
|
|
62
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {BaseCMI} from "../common/base_cmi";
|
|
2
|
-
import {CMIScore} from "../common/score";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {Scorm12ValidationError} from "../../exceptions";
|
|
7
|
-
import {check12ValidFormat} from "./validation";
|
|
8
|
-
import {CMIArray} from "../common/array";
|
|
1
|
+
import { BaseCMI } from "../common/base_cmi";
|
|
2
|
+
import { CMIScore } from "../common/score";
|
|
3
|
+
import { scorm12_constants } from "../../constants/api_constants";
|
|
4
|
+
import { scorm12_regex } from "../../constants/regex";
|
|
5
|
+
import { scorm12_errors } from "../../constants/error_codes";
|
|
6
|
+
import { Scorm12ValidationError } from "../../exceptions/scorm12_exceptions";
|
|
7
|
+
import { check12ValidFormat } from "./validation";
|
|
8
|
+
import { CMIArray } from "../common/array";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Class representing SCORM 1.2's `cmi.objectives` object
|
|
@@ -17,8 +17,8 @@ export class CMIObjectives extends CMIArray {
|
|
|
17
17
|
*/
|
|
18
18
|
constructor() {
|
|
19
19
|
super({
|
|
20
|
-
children:
|
|
21
|
-
errorCode:
|
|
20
|
+
children: scorm12_constants.objectives_children,
|
|
21
|
+
errorCode: scorm12_errors.INVALID_SET_VALUE,
|
|
22
22
|
errorClass: Scorm12ValidationError,
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -35,11 +35,11 @@ export class CMIObjectivesObject extends BaseCMI {
|
|
|
35
35
|
constructor() {
|
|
36
36
|
super();
|
|
37
37
|
this.score = new CMIScore({
|
|
38
|
-
score_children:
|
|
39
|
-
score_range:
|
|
40
|
-
invalidErrorCode:
|
|
41
|
-
invalidTypeCode:
|
|
42
|
-
invalidRangeCode:
|
|
38
|
+
score_children: scorm12_constants.score_children,
|
|
39
|
+
score_range: scorm12_regex.score_range,
|
|
40
|
+
invalidErrorCode: scorm12_errors.INVALID_SET_VALUE,
|
|
41
|
+
invalidTypeCode: scorm12_errors.TYPE_MISMATCH,
|
|
42
|
+
invalidRangeCode: scorm12_errors.VALUE_OUT_OF_RANGE,
|
|
43
43
|
errorClass: Scorm12ValidationError,
|
|
44
44
|
});
|
|
45
45
|
}
|
|
@@ -49,6 +49,16 @@ export class CMIObjectivesObject extends BaseCMI {
|
|
|
49
49
|
private _id = "";
|
|
50
50
|
private _status = "";
|
|
51
51
|
|
|
52
|
+
/**
|
|
53
|
+
* Called when the API has been reset
|
|
54
|
+
*/
|
|
55
|
+
reset(): void {
|
|
56
|
+
this._initialized = false;
|
|
57
|
+
this._id = "";
|
|
58
|
+
this._status = "";
|
|
59
|
+
this.score?.reset();
|
|
60
|
+
}
|
|
61
|
+
|
|
52
62
|
/**
|
|
53
63
|
* Getter for _id
|
|
54
64
|
* @return {string}
|
|
@@ -62,7 +72,7 @@ export class CMIObjectivesObject extends BaseCMI {
|
|
|
62
72
|
* @param {string} id
|
|
63
73
|
*/
|
|
64
74
|
set id(id: string) {
|
|
65
|
-
if (check12ValidFormat(id,
|
|
75
|
+
if (check12ValidFormat(id, scorm12_regex.CMIIdentifier)) {
|
|
66
76
|
this._id = id;
|
|
67
77
|
}
|
|
68
78
|
}
|
|
@@ -80,7 +90,7 @@ export class CMIObjectivesObject extends BaseCMI {
|
|
|
80
90
|
* @param {string} status
|
|
81
91
|
*/
|
|
82
92
|
set status(status: string) {
|
|
83
|
-
if (check12ValidFormat(status,
|
|
93
|
+
if (check12ValidFormat(status, scorm12_regex.CMIStatus2)) {
|
|
84
94
|
this._status = status;
|
|
85
95
|
}
|
|
86
96
|
}
|
|
@@ -109,4 +119,4 @@ export class CMIObjectivesObject extends BaseCMI {
|
|
|
109
119
|
delete this.jsonString;
|
|
110
120
|
return result;
|
|
111
121
|
}
|
|
112
|
-
}
|
|
122
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseCMI } from "../common/base_cmi";
|
|
2
|
-
import
|
|
3
|
-
import { Scorm12ValidationError } from "../../exceptions";
|
|
4
|
-
import
|
|
2
|
+
import { scorm12_constants } from "../../constants/api_constants";
|
|
3
|
+
import { Scorm12ValidationError } from "../../exceptions/scorm12_exceptions";
|
|
4
|
+
import { scorm12_errors } from "../../constants/error_codes";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Class representing the SCORM 1.2 cmi.student_data object
|
|
@@ -21,7 +21,14 @@ export class CMIStudentData extends BaseCMI {
|
|
|
21
21
|
super();
|
|
22
22
|
this.__children = student_data_children
|
|
23
23
|
? student_data_children
|
|
24
|
-
:
|
|
24
|
+
: scorm12_constants.student_data_children;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Called when the API has been reset
|
|
29
|
+
*/
|
|
30
|
+
reset(): void {
|
|
31
|
+
this._initialized = false;
|
|
25
32
|
}
|
|
26
33
|
|
|
27
34
|
/**
|
|
@@ -39,7 +46,7 @@ export class CMIStudentData extends BaseCMI {
|
|
|
39
46
|
* @private
|
|
40
47
|
*/
|
|
41
48
|
set _children(_children: string) {
|
|
42
|
-
throw new Scorm12ValidationError(
|
|
49
|
+
throw new Scorm12ValidationError(scorm12_errors.INVALID_SET_VALUE);
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
/**
|
|
@@ -56,7 +63,7 @@ export class CMIStudentData extends BaseCMI {
|
|
|
56
63
|
*/
|
|
57
64
|
set mastery_score(mastery_score: string) {
|
|
58
65
|
if (this.initialized) {
|
|
59
|
-
throw new Scorm12ValidationError(
|
|
66
|
+
throw new Scorm12ValidationError(scorm12_errors.READ_ONLY_ELEMENT);
|
|
60
67
|
} else {
|
|
61
68
|
this._mastery_score = mastery_score;
|
|
62
69
|
}
|
|
@@ -76,7 +83,7 @@ export class CMIStudentData extends BaseCMI {
|
|
|
76
83
|
*/
|
|
77
84
|
set max_time_allowed(max_time_allowed: string) {
|
|
78
85
|
if (this.initialized) {
|
|
79
|
-
throw new Scorm12ValidationError(
|
|
86
|
+
throw new Scorm12ValidationError(scorm12_errors.READ_ONLY_ELEMENT);
|
|
80
87
|
} else {
|
|
81
88
|
this._max_time_allowed = max_time_allowed;
|
|
82
89
|
}
|
|
@@ -96,7 +103,7 @@ export class CMIStudentData extends BaseCMI {
|
|
|
96
103
|
*/
|
|
97
104
|
set time_limit_action(time_limit_action: string) {
|
|
98
105
|
if (this.initialized) {
|
|
99
|
-
throw new Scorm12ValidationError(
|
|
106
|
+
throw new Scorm12ValidationError(scorm12_errors.READ_ONLY_ELEMENT);
|
|
100
107
|
} else {
|
|
101
108
|
this._time_limit_action = time_limit_action;
|
|
102
109
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseCMI } from "../common/base_cmi";
|
|
2
|
-
import
|
|
3
|
-
import { Scorm12ValidationError } from "../../exceptions";
|
|
4
|
-
import ErrorCodes from "../../constants/error_codes";
|
|
2
|
+
import { scorm12_constants } from "../../constants/api_constants";
|
|
3
|
+
import { Scorm12ValidationError } from "../../exceptions/scorm12_exceptions";
|
|
5
4
|
import { check12ValidFormat, check12ValidRange } from "./validation";
|
|
6
|
-
import
|
|
5
|
+
import { scorm12_regex } from "../../constants/regex";
|
|
6
|
+
import { scorm12_errors } from "../../constants/error_codes";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Class representing the SCORM 1.2 cmi.student_preference object
|
|
@@ -20,7 +20,7 @@ export class CMIStudentPreference extends BaseCMI {
|
|
|
20
20
|
super();
|
|
21
21
|
this.__children = student_preference_children
|
|
22
22
|
? student_preference_children
|
|
23
|
-
:
|
|
23
|
+
: scorm12_constants.student_preference_children;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
private _audio = "";
|
|
@@ -28,6 +28,13 @@ export class CMIStudentPreference extends BaseCMI {
|
|
|
28
28
|
private _speed = "";
|
|
29
29
|
private _text = "";
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Called when the API has been reset
|
|
33
|
+
*/
|
|
34
|
+
reset(): void {
|
|
35
|
+
this._initialized = false;
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
/**
|
|
32
39
|
* Getter for __children
|
|
33
40
|
* @return {string}
|
|
@@ -43,7 +50,7 @@ export class CMIStudentPreference extends BaseCMI {
|
|
|
43
50
|
* @private
|
|
44
51
|
*/
|
|
45
52
|
set _children(_children: string) {
|
|
46
|
-
throw new Scorm12ValidationError(
|
|
53
|
+
throw new Scorm12ValidationError(scorm12_errors.INVALID_SET_VALUE);
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
/**
|
|
@@ -60,8 +67,8 @@ export class CMIStudentPreference extends BaseCMI {
|
|
|
60
67
|
*/
|
|
61
68
|
set audio(audio: string) {
|
|
62
69
|
if (
|
|
63
|
-
check12ValidFormat(audio,
|
|
64
|
-
check12ValidRange(audio,
|
|
70
|
+
check12ValidFormat(audio, scorm12_regex.CMISInteger) &&
|
|
71
|
+
check12ValidRange(audio, scorm12_regex.audio_range)
|
|
65
72
|
) {
|
|
66
73
|
this._audio = audio;
|
|
67
74
|
}
|
|
@@ -80,7 +87,7 @@ export class CMIStudentPreference extends BaseCMI {
|
|
|
80
87
|
* @param {string} language
|
|
81
88
|
*/
|
|
82
89
|
set language(language: string) {
|
|
83
|
-
if (check12ValidFormat(language,
|
|
90
|
+
if (check12ValidFormat(language, scorm12_regex.CMIString256)) {
|
|
84
91
|
this._language = language;
|
|
85
92
|
}
|
|
86
93
|
}
|
|
@@ -99,8 +106,8 @@ export class CMIStudentPreference extends BaseCMI {
|
|
|
99
106
|
*/
|
|
100
107
|
set speed(speed: string) {
|
|
101
108
|
if (
|
|
102
|
-
check12ValidFormat(speed,
|
|
103
|
-
check12ValidRange(speed,
|
|
109
|
+
check12ValidFormat(speed, scorm12_regex.CMISInteger) &&
|
|
110
|
+
check12ValidRange(speed, scorm12_regex.speed_range)
|
|
104
111
|
) {
|
|
105
112
|
this._speed = speed;
|
|
106
113
|
}
|
|
@@ -120,8 +127,8 @@ export class CMIStudentPreference extends BaseCMI {
|
|
|
120
127
|
*/
|
|
121
128
|
set text(text: string) {
|
|
122
129
|
if (
|
|
123
|
-
check12ValidFormat(text,
|
|
124
|
-
check12ValidRange(text,
|
|
130
|
+
check12ValidFormat(text, scorm12_regex.CMISInteger) &&
|
|
131
|
+
check12ValidRange(text, scorm12_regex.text_range)
|
|
125
132
|
) {
|
|
126
133
|
this._text = text;
|
|
127
134
|
}
|