@conform-ed/contracts 0.0.4 → 0.0.5
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/package.json +1 -1
- package/src/xapi/shared.ts +44 -3
package/package.json
CHANGED
package/src/xapi/shared.ts
CHANGED
|
@@ -132,6 +132,8 @@ export const InteractionComponentSchema = strictObject({
|
|
|
132
132
|
description: LanguageMapSchema.optional(),
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
+
const interactionSubProperties = ["correctResponsesPattern", "choices", "scale", "source", "target", "steps"] as const;
|
|
136
|
+
|
|
135
137
|
export const ActivityDefinitionSchema = strictObject({
|
|
136
138
|
name: LanguageMapSchema.optional(),
|
|
137
139
|
description: LanguageMapSchema.optional(),
|
|
@@ -145,6 +147,17 @@ export const ActivityDefinitionSchema = strictObject({
|
|
|
145
147
|
target: z.array(InteractionComponentSchema).min(1).optional(),
|
|
146
148
|
steps: z.array(InteractionComponentSchema).min(1).optional(),
|
|
147
149
|
extensions: ExtensionsSchema.optional(),
|
|
150
|
+
}).superRefine((value, ctx) => {
|
|
151
|
+
if (value.interactionType !== undefined) return;
|
|
152
|
+
for (const prop of interactionSubProperties) {
|
|
153
|
+
if (value[prop] !== undefined) {
|
|
154
|
+
ctx.addIssue({
|
|
155
|
+
code: z.ZodIssueCode.custom,
|
|
156
|
+
message: `Activity definition property '${prop}' requires interactionType to be set`,
|
|
157
|
+
path: [prop],
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
148
161
|
});
|
|
149
162
|
|
|
150
163
|
export const ActivitySchema = strictObject({
|
|
@@ -163,6 +176,29 @@ export const ScoreSchema = strictObject({
|
|
|
163
176
|
raw: z.number().optional(),
|
|
164
177
|
min: z.number().optional(),
|
|
165
178
|
max: z.number().optional(),
|
|
179
|
+
}).superRefine((value, ctx) => {
|
|
180
|
+
const { min, max, raw } = value;
|
|
181
|
+
if (min !== undefined && max !== undefined && min >= max) {
|
|
182
|
+
ctx.addIssue({
|
|
183
|
+
code: z.ZodIssueCode.custom,
|
|
184
|
+
message: "Score max must be greater than min",
|
|
185
|
+
path: ["max"],
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (raw !== undefined && min !== undefined && raw < min) {
|
|
189
|
+
ctx.addIssue({
|
|
190
|
+
code: z.ZodIssueCode.custom,
|
|
191
|
+
message: "Score raw must be greater than or equal to min",
|
|
192
|
+
path: ["raw"],
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (raw !== undefined && max !== undefined && raw > max) {
|
|
196
|
+
ctx.addIssue({
|
|
197
|
+
code: z.ZodIssueCode.custom,
|
|
198
|
+
message: "Score raw must be less than or equal to max",
|
|
199
|
+
path: ["raw"],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
166
202
|
});
|
|
167
203
|
|
|
168
204
|
export const ResultSchema = strictObject({
|
|
@@ -285,11 +321,16 @@ export const ActivityProfileDocumentListingQuerySchema = strictObject({
|
|
|
285
321
|
|
|
286
322
|
export const XapiDocumentIdListSchema = z.array(NonEmptyStringSchema);
|
|
287
323
|
|
|
324
|
+
// When Agent or Group is used as a Statement Object, objectType is required per spec.
|
|
325
|
+
// "When Agent is used as a Statement Object, the objectType property MUST be included."
|
|
326
|
+
const AgentAsObjectSchema = AgentSchema.and(z.object({ objectType: z.literal("Agent") }));
|
|
327
|
+
const GroupAsObjectSchema = GroupSchema.and(z.object({ objectType: z.literal("Group") }));
|
|
328
|
+
|
|
288
329
|
export const SubStatementSchema = strictObject({
|
|
289
330
|
objectType: z.literal("SubStatement"),
|
|
290
331
|
actor: z.union([AgentSchema, GroupSchema]),
|
|
291
332
|
verb: VerbSchema,
|
|
292
|
-
object: z.union([ActivitySchema,
|
|
333
|
+
object: z.union([ActivitySchema, AgentAsObjectSchema, GroupAsObjectSchema, StatementRefSchema]),
|
|
293
334
|
result: ResultSchema.optional(),
|
|
294
335
|
context: ContextSchema.optional(),
|
|
295
336
|
timestamp: Iso8601TimestampSchema.optional(),
|
|
@@ -297,8 +338,8 @@ export const SubStatementSchema = strictObject({
|
|
|
297
338
|
|
|
298
339
|
export const StatementObjectSchema = z.union([
|
|
299
340
|
ActivitySchema,
|
|
300
|
-
|
|
301
|
-
|
|
341
|
+
AgentAsObjectSchema,
|
|
342
|
+
GroupAsObjectSchema,
|
|
302
343
|
StatementRefSchema,
|
|
303
344
|
SubStatementSchema,
|
|
304
345
|
]);
|