@conform-ed/contracts 0.0.5 → 0.0.6
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 +17 -13
- package/src/xapi/v2_0/index.ts +5 -3
package/package.json
CHANGED
package/src/xapi/shared.ts
CHANGED
|
@@ -72,17 +72,21 @@ export const GroupSchema = strictObject({
|
|
|
72
72
|
openid: UriSchema.optional(),
|
|
73
73
|
account: AgentAccountSchema.optional(),
|
|
74
74
|
member: z.array(AgentSchema).min(1).optional(),
|
|
75
|
-
}).
|
|
76
|
-
(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
75
|
+
}).superRefine((value, ctx) => {
|
|
76
|
+
const ifiCount = [value.mbox, value.mbox_sha1sum, value.openid, value.account].filter(hasDefined).length;
|
|
77
|
+
if (ifiCount > 1) {
|
|
78
|
+
ctx.addIssue({
|
|
79
|
+
code: z.ZodIssueCode.custom,
|
|
80
|
+
message: "An identified xAPI Group MUST have exactly one Inverse Functional Identifier",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (ifiCount === 0 && !hasDefined(value.member)) {
|
|
84
|
+
ctx.addIssue({
|
|
85
|
+
code: z.ZodIssueCode.custom,
|
|
86
|
+
message: "An anonymous xAPI Group requires a member list",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
86
90
|
|
|
87
91
|
export const PersonSchema = strictObject({
|
|
88
92
|
objectType: z.literal("Person"),
|
|
@@ -323,8 +327,8 @@ export const XapiDocumentIdListSchema = z.array(NonEmptyStringSchema);
|
|
|
323
327
|
|
|
324
328
|
// When Agent or Group is used as a Statement Object, objectType is required per spec.
|
|
325
329
|
// "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") }));
|
|
330
|
+
export const AgentAsObjectSchema = AgentSchema.and(z.object({ objectType: z.literal("Agent") }));
|
|
331
|
+
export const GroupAsObjectSchema = GroupSchema.and(z.object({ objectType: z.literal("Group") }));
|
|
328
332
|
|
|
329
333
|
export const SubStatementSchema = strictObject({
|
|
330
334
|
objectType: z.literal("SubStatement"),
|
package/src/xapi/v2_0/index.ts
CHANGED
|
@@ -47,6 +47,8 @@ import {
|
|
|
47
47
|
XapiResourceSchema,
|
|
48
48
|
XapiResponseHeaderSchema,
|
|
49
49
|
XapiVersionSchema,
|
|
50
|
+
AgentAsObjectSchema,
|
|
51
|
+
GroupAsObjectSchema,
|
|
50
52
|
} from "../shared";
|
|
51
53
|
|
|
52
54
|
export const ContextAgentSchema = strictObject({
|
|
@@ -70,7 +72,7 @@ export const SubStatementV2Schema = strictObject({
|
|
|
70
72
|
objectType: z.literal("SubStatement"),
|
|
71
73
|
actor: z.union([AgentSchema, GroupSchema]),
|
|
72
74
|
verb: VerbSchema,
|
|
73
|
-
object: z.union([ActivitySchema,
|
|
75
|
+
object: z.union([ActivitySchema, AgentAsObjectSchema, GroupAsObjectSchema, StatementRefSchema]),
|
|
74
76
|
result: ResultSchema.optional(),
|
|
75
77
|
context: ContextV2Schema.optional(),
|
|
76
78
|
timestamp: Iso8601TimestampSchema.optional(),
|
|
@@ -78,8 +80,8 @@ export const SubStatementV2Schema = strictObject({
|
|
|
78
80
|
|
|
79
81
|
export const StatementObjectV2Schema = z.union([
|
|
80
82
|
ActivitySchema,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
AgentAsObjectSchema,
|
|
84
|
+
GroupAsObjectSchema,
|
|
83
85
|
StatementRefSchema,
|
|
84
86
|
SubStatementV2Schema,
|
|
85
87
|
]);
|