@nakafa/aksara-contracts 0.48.9 → 0.49.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/README.md +9 -0
- package/dist/assessment/choice.d.ts +154 -0
- package/dist/assessment/choice.js +87 -0
- package/dist/assessment/document.d.ts +219 -0
- package/dist/assessment/document.js +162 -0
- package/dist/assessment/entry.d.ts +50 -0
- package/dist/assessment/entry.js +48 -0
- package/dist/assessment/explanation.d.ts +19 -0
- package/dist/assessment/explanation.js +18 -0
- package/dist/assessment/figure.d.ts +1938 -0
- package/dist/assessment/figure.js +236 -0
- package/dist/assessment/fit.d.ts +21 -0
- package/dist/assessment/fit.js +42 -0
- package/dist/assessment/graphic.d.ts +95 -0
- package/dist/assessment/graphic.js +106 -0
- package/dist/assessment/hash.d.ts +1444 -0
- package/dist/assessment/hash.js +66 -0
- package/dist/assessment/identity.d.ts +37 -0
- package/dist/assessment/identity.js +50 -0
- package/dist/assessment/inline.d.ts +124 -0
- package/dist/assessment/inline.js +92 -0
- package/dist/assessment/interaction.d.ts +219 -0
- package/dist/assessment/interaction.js +38 -0
- package/dist/assessment/item.d.ts +759 -0
- package/dist/assessment/item.js +98 -0
- package/dist/assessment/key.d.ts +195 -0
- package/dist/assessment/key.js +136 -0
- package/dist/assessment/paper.d.ts +799 -0
- package/dist/assessment/paper.js +69 -0
- package/dist/assessment/part.d.ts +47 -0
- package/dist/assessment/part.js +32 -0
- package/dist/assessment/profile.d.ts +153 -0
- package/dist/assessment/profile.js +160 -0
- package/dist/assessment/record.d.ts +18 -0
- package/dist/assessment/record.js +27 -0
- package/dist/assessment/scalar.d.ts +18 -0
- package/dist/assessment/scalar.js +18 -0
- package/dist/assessment/scoring.d.ts +157 -0
- package/dist/assessment/scoring.js +150 -0
- package/dist/assessment/stimulus.d.ts +48 -0
- package/dist/assessment/stimulus.js +42 -0
- package/dist/assessment/structure.d.ts +13 -0
- package/dist/assessment/structure.js +29 -0
- package/dist/assessment/tools.d.ts +17 -0
- package/dist/assessment/tools.js +39 -0
- package/dist/projection/verify.d.ts +23 -23
- package/dist/runtime/verify.d.ts +46 -46
- package/dist/transport/request.d.ts +138 -138
- package/package.json +69 -1
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
|
+
import { AssessmentDocumentSchema } from "#contracts/assessment/document";
|
|
3
|
+
import { hasFittingRules, hasPlacedInteractions, } from "#contracts/assessment/fit";
|
|
4
|
+
import { hasDistinctIds, ItemFamilyIdSchema, KebabKeySchema, StimulusIdSchema, } from "#contracts/assessment/identity";
|
|
5
|
+
import { InteractionSchema } from "#contracts/assessment/interaction";
|
|
6
|
+
import { isWithinRecordLimit } from "#contracts/assessment/record";
|
|
7
|
+
import { ScoringOverrideSchema } from "#contracts/assessment/scoring";
|
|
8
|
+
import { hasSameStructure } from "#contracts/assessment/structure";
|
|
9
|
+
import { Sha256HashSchema } from "#contracts/ids";
|
|
10
|
+
import { DeliveryLanguageSchema } from "#contracts/locale";
|
|
11
|
+
/** The editorial facts that place an item in a blueprint. */
|
|
12
|
+
export const ItemBlueprintSchema = Schema.Struct({
|
|
13
|
+
cognitiveLevel: KebabKeySchema,
|
|
14
|
+
competency: KebabKeySchema,
|
|
15
|
+
topic: KebabKeySchema,
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* One item, whatever its language: a language-neutral identifier, its
|
|
19
|
+
* blueprint, and the shared reading it belongs to, if any.
|
|
20
|
+
*/
|
|
21
|
+
export const ItemFamilySchema = Schema.Struct({
|
|
22
|
+
blueprint: Schema.optionalKey(ItemBlueprintSchema),
|
|
23
|
+
id: ItemFamilyIdSchema,
|
|
24
|
+
stimulus: Schema.optionalKey(StimulusIdSchema),
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* A shared reading, pinned to the exact version that this item version was
|
|
28
|
+
* written against. The reading is never copied into the prompt.
|
|
29
|
+
*/
|
|
30
|
+
export const StimulusReferenceSchema = Schema.Struct({
|
|
31
|
+
hash: Sha256HashSchema,
|
|
32
|
+
id: StimulusIdSchema,
|
|
33
|
+
});
|
|
34
|
+
/** The fields of an item version except its hash, which covers all of them. */
|
|
35
|
+
const VersionFields = {
|
|
36
|
+
deliveryLanguage: DeliveryLanguageSchema,
|
|
37
|
+
family: ItemFamilyIdSchema,
|
|
38
|
+
interactions: Schema.NonEmptyArray(InteractionSchema),
|
|
39
|
+
prompt: AssessmentDocumentSchema,
|
|
40
|
+
scoring: Schema.Array(ScoringOverrideSchema),
|
|
41
|
+
stimulus: Schema.optionalKey(StimulusReferenceSchema),
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* One item in one delivery language, without its hash: the prompt document,
|
|
45
|
+
* its interactions, the scoring rules that override the exam profile, and the
|
|
46
|
+
* shared reading it was written against, if it has one. The prompt carries no
|
|
47
|
+
* answer key, and the version holds no explanation: the key and the explanation
|
|
48
|
+
* are records of their own (`assessment/key`, `assessment/explanation`).
|
|
49
|
+
*/
|
|
50
|
+
export const ItemVersionBodySchema = Schema.Struct(VersionFields).check(Schema.makeFilter(hasPlacedInteractions, {
|
|
51
|
+
message: "Expected the prompt to place each interaction once, as its kind allows, and no other.",
|
|
52
|
+
}), Schema.makeFilter(hasFittingRules, {
|
|
53
|
+
message: "Expected each scoring rule to fit its interaction, and each extended text to carry a rubric.",
|
|
54
|
+
}));
|
|
55
|
+
/**
|
|
56
|
+
* An item version is immutable once published: a change is a new version. Its
|
|
57
|
+
* `hash` is the SHA-256 of the canonical encoding of the body (see
|
|
58
|
+
* `assessment/hash`), so the hash names the exact content. Its size is limited
|
|
59
|
+
* by `assessment/record`.
|
|
60
|
+
*/
|
|
61
|
+
export const ItemVersionSchema = ItemVersionBodySchema.mapFields((fields) => ({ ...fields, hash: Sha256HashSchema }), { unsafePreserveChecks: true }).check(isWithinRecordLimit);
|
|
62
|
+
const ItemFieldsSchema = Schema.Struct({
|
|
63
|
+
family: ItemFamilySchema,
|
|
64
|
+
versions: Schema.NonEmptyArray(ItemVersionSchema),
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* Checks that every version of a family has the same interaction structure.
|
|
68
|
+
* The old contract required translations to preserve their format, structure,
|
|
69
|
+
* and answer key, and it still holds: a translation may change words, never
|
|
70
|
+
* the task. If the structure were free to differ, one answer key, one scoring
|
|
71
|
+
* rule, and one calibrated difficulty could not serve every language of an
|
|
72
|
+
* item. The identifiers, counts, bounds, and scoring rules must agree; the
|
|
73
|
+
* labels, the text alternatives, and the units are the words of a language.
|
|
74
|
+
*/
|
|
75
|
+
function hasOneStructure(item) {
|
|
76
|
+
return hasSameStructure(Arr.map(item.versions, ({ interactions, scoring }) => ({
|
|
77
|
+
interactions,
|
|
78
|
+
scoring,
|
|
79
|
+
})));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Checks that the versions belong to the family: each names its identifier and
|
|
83
|
+
* its shared reading, and no two are written in one language.
|
|
84
|
+
*/
|
|
85
|
+
function hasFamilyVersions(item) {
|
|
86
|
+
return (Arr.every(item.versions, ({ family, stimulus }) => family === item.family.id && stimulus?.id === item.family.stimulus) &&
|
|
87
|
+
hasDistinctIds(Arr.map(item.versions, ({ deliveryLanguage }) => deliveryLanguage)));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* One item with its versions, one for each delivery language. Every version
|
|
91
|
+
* names the family and the shared reading of the family, is written in its own
|
|
92
|
+
* language, and has the same interaction structure as the others.
|
|
93
|
+
*/
|
|
94
|
+
export const ItemSchema = ItemFieldsSchema.check(Schema.makeFilter(hasFamilyVersions, {
|
|
95
|
+
message: "Expected each version to name the family and its shared reading, in a language of its own.",
|
|
96
|
+
}), Schema.makeFilter(hasOneStructure, {
|
|
97
|
+
message: "Expected every version of a family to have one interaction structure.",
|
|
98
|
+
}));
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
/** The answer to one interaction. */
|
|
3
|
+
export declare const InteractionKeySchema: Schema.Union<readonly [Schema.Struct<{
|
|
4
|
+
readonly interaction: Schema.String;
|
|
5
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
6
|
+
readonly kind: Schema.Literal<"choice">;
|
|
7
|
+
}>, Schema.Struct<{
|
|
8
|
+
readonly interaction: Schema.String;
|
|
9
|
+
readonly answers: Schema.NonEmptyArray<Schema.Struct<{
|
|
10
|
+
readonly column: Schema.String;
|
|
11
|
+
readonly statement: Schema.String;
|
|
12
|
+
}>>;
|
|
13
|
+
readonly kind: Schema.Literal<"matrix">;
|
|
14
|
+
}>, Schema.Struct<{
|
|
15
|
+
readonly interaction: Schema.String;
|
|
16
|
+
readonly kind: Schema.Literal<"match">;
|
|
17
|
+
readonly pairs: Schema.NonEmptyArray<Schema.Struct<{
|
|
18
|
+
readonly source: Schema.String;
|
|
19
|
+
readonly target: Schema.String;
|
|
20
|
+
}>>;
|
|
21
|
+
}>, Schema.Struct<{
|
|
22
|
+
readonly interaction: Schema.String;
|
|
23
|
+
readonly kind: Schema.Literal<"order">;
|
|
24
|
+
readonly sequence: Schema.NonEmptyArray<Schema.String>;
|
|
25
|
+
}>, Schema.Struct<{
|
|
26
|
+
readonly interaction: Schema.String;
|
|
27
|
+
readonly correct: Schema.String;
|
|
28
|
+
readonly kind: Schema.Literal<"inlineChoice">;
|
|
29
|
+
}>, Schema.Struct<{
|
|
30
|
+
readonly interaction: Schema.String;
|
|
31
|
+
readonly accepted: Schema.Struct<{
|
|
32
|
+
readonly acceptedAnswers: Schema.NonEmptyArray<Schema.Trimmed>;
|
|
33
|
+
readonly collapseWhitespace: Schema.Boolean;
|
|
34
|
+
readonly ignoreCase: Schema.Boolean;
|
|
35
|
+
readonly kind: Schema.Literal<"text">;
|
|
36
|
+
}>;
|
|
37
|
+
readonly kind: Schema.Literal<"textEntry">;
|
|
38
|
+
}>, Schema.Struct<{
|
|
39
|
+
readonly interaction: Schema.String;
|
|
40
|
+
readonly kind: Schema.Literal<"numericEntry">;
|
|
41
|
+
readonly tolerance: Schema.optionalKey<Schema.Struct<{
|
|
42
|
+
readonly kind: Schema.Literals<readonly ["absolute", "relative"]>;
|
|
43
|
+
readonly value: Schema.String;
|
|
44
|
+
}>>;
|
|
45
|
+
readonly value: Schema.String;
|
|
46
|
+
}>, Schema.Struct<{
|
|
47
|
+
readonly interaction: Schema.String;
|
|
48
|
+
readonly expression: Schema.Trimmed;
|
|
49
|
+
readonly kind: Schema.Literal<"mathEntry">;
|
|
50
|
+
}>, Schema.Struct<{
|
|
51
|
+
readonly interaction: Schema.String;
|
|
52
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
53
|
+
readonly kind: Schema.Literal<"hotspot">;
|
|
54
|
+
}>, Schema.Struct<{
|
|
55
|
+
readonly interaction: Schema.String;
|
|
56
|
+
readonly kind: Schema.Literal<"gapMatch">;
|
|
57
|
+
readonly pairs: Schema.NonEmptyArray<Schema.Struct<{
|
|
58
|
+
readonly choice: Schema.String;
|
|
59
|
+
readonly gap: Schema.String;
|
|
60
|
+
}>>;
|
|
61
|
+
}>, Schema.Struct<{
|
|
62
|
+
readonly interaction: Schema.String;
|
|
63
|
+
readonly kind: Schema.Literal<"graphPoint">;
|
|
64
|
+
readonly target: Schema.Union<readonly [Schema.Struct<{
|
|
65
|
+
readonly kind: Schema.Literal<"points">;
|
|
66
|
+
readonly points: Schema.NonEmptyArray<Schema.Struct<{
|
|
67
|
+
readonly x: Schema.Finite;
|
|
68
|
+
readonly y: Schema.Finite;
|
|
69
|
+
}>>;
|
|
70
|
+
}>, Schema.Struct<{
|
|
71
|
+
readonly kind: Schema.Literal<"lines">;
|
|
72
|
+
readonly lines: Schema.NonEmptyArray<Schema.Struct<{
|
|
73
|
+
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
74
|
+
readonly x: Schema.Finite;
|
|
75
|
+
readonly y: Schema.Finite;
|
|
76
|
+
}>, Schema.Struct<{
|
|
77
|
+
readonly x: Schema.Finite;
|
|
78
|
+
readonly y: Schema.Finite;
|
|
79
|
+
}>]>;
|
|
80
|
+
}>>;
|
|
81
|
+
}>]>;
|
|
82
|
+
readonly tolerance: Schema.Finite;
|
|
83
|
+
}>, Schema.Struct<{
|
|
84
|
+
readonly interaction: Schema.String;
|
|
85
|
+
readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
|
|
86
|
+
readonly criterion: Schema.String;
|
|
87
|
+
readonly levels: Schema.NonEmptyArray<Schema.Struct<{
|
|
88
|
+
readonly descriptor: Schema.Trimmed;
|
|
89
|
+
readonly level: Schema.String;
|
|
90
|
+
}>>;
|
|
91
|
+
}>>;
|
|
92
|
+
readonly kind: Schema.Literal<"extendedText">;
|
|
93
|
+
}>]>;
|
|
94
|
+
export type InteractionKey = typeof InteractionKeySchema.Type;
|
|
95
|
+
/**
|
|
96
|
+
* The answer key of one item version: its own schema and its own artifact,
|
|
97
|
+
* delivered only to a reader who is entitled to it. The prompt of the item
|
|
98
|
+
* carries no key. `version` is the hash of the item version it belongs to. Its
|
|
99
|
+
* size is limited by `assessment/record`.
|
|
100
|
+
*/
|
|
101
|
+
export declare const ItemKeySchema: Schema.Struct<{
|
|
102
|
+
readonly answers: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
|
|
103
|
+
readonly interaction: Schema.String;
|
|
104
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
105
|
+
readonly kind: Schema.Literal<"choice">;
|
|
106
|
+
}>, Schema.Struct<{
|
|
107
|
+
readonly interaction: Schema.String;
|
|
108
|
+
readonly answers: Schema.NonEmptyArray<Schema.Struct<{
|
|
109
|
+
readonly column: Schema.String;
|
|
110
|
+
readonly statement: Schema.String;
|
|
111
|
+
}>>;
|
|
112
|
+
readonly kind: Schema.Literal<"matrix">;
|
|
113
|
+
}>, Schema.Struct<{
|
|
114
|
+
readonly interaction: Schema.String;
|
|
115
|
+
readonly kind: Schema.Literal<"match">;
|
|
116
|
+
readonly pairs: Schema.NonEmptyArray<Schema.Struct<{
|
|
117
|
+
readonly source: Schema.String;
|
|
118
|
+
readonly target: Schema.String;
|
|
119
|
+
}>>;
|
|
120
|
+
}>, Schema.Struct<{
|
|
121
|
+
readonly interaction: Schema.String;
|
|
122
|
+
readonly kind: Schema.Literal<"order">;
|
|
123
|
+
readonly sequence: Schema.NonEmptyArray<Schema.String>;
|
|
124
|
+
}>, Schema.Struct<{
|
|
125
|
+
readonly interaction: Schema.String;
|
|
126
|
+
readonly correct: Schema.String;
|
|
127
|
+
readonly kind: Schema.Literal<"inlineChoice">;
|
|
128
|
+
}>, Schema.Struct<{
|
|
129
|
+
readonly interaction: Schema.String;
|
|
130
|
+
readonly accepted: Schema.Struct<{
|
|
131
|
+
readonly acceptedAnswers: Schema.NonEmptyArray<Schema.Trimmed>;
|
|
132
|
+
readonly collapseWhitespace: Schema.Boolean;
|
|
133
|
+
readonly ignoreCase: Schema.Boolean;
|
|
134
|
+
readonly kind: Schema.Literal<"text">;
|
|
135
|
+
}>;
|
|
136
|
+
readonly kind: Schema.Literal<"textEntry">;
|
|
137
|
+
}>, Schema.Struct<{
|
|
138
|
+
readonly interaction: Schema.String;
|
|
139
|
+
readonly kind: Schema.Literal<"numericEntry">;
|
|
140
|
+
readonly tolerance: Schema.optionalKey<Schema.Struct<{
|
|
141
|
+
readonly kind: Schema.Literals<readonly ["absolute", "relative"]>;
|
|
142
|
+
readonly value: Schema.String;
|
|
143
|
+
}>>;
|
|
144
|
+
readonly value: Schema.String;
|
|
145
|
+
}>, Schema.Struct<{
|
|
146
|
+
readonly interaction: Schema.String;
|
|
147
|
+
readonly expression: Schema.Trimmed;
|
|
148
|
+
readonly kind: Schema.Literal<"mathEntry">;
|
|
149
|
+
}>, Schema.Struct<{
|
|
150
|
+
readonly interaction: Schema.String;
|
|
151
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
152
|
+
readonly kind: Schema.Literal<"hotspot">;
|
|
153
|
+
}>, Schema.Struct<{
|
|
154
|
+
readonly interaction: Schema.String;
|
|
155
|
+
readonly kind: Schema.Literal<"gapMatch">;
|
|
156
|
+
readonly pairs: Schema.NonEmptyArray<Schema.Struct<{
|
|
157
|
+
readonly choice: Schema.String;
|
|
158
|
+
readonly gap: Schema.String;
|
|
159
|
+
}>>;
|
|
160
|
+
}>, Schema.Struct<{
|
|
161
|
+
readonly interaction: Schema.String;
|
|
162
|
+
readonly kind: Schema.Literal<"graphPoint">;
|
|
163
|
+
readonly target: Schema.Union<readonly [Schema.Struct<{
|
|
164
|
+
readonly kind: Schema.Literal<"points">;
|
|
165
|
+
readonly points: Schema.NonEmptyArray<Schema.Struct<{
|
|
166
|
+
readonly x: Schema.Finite;
|
|
167
|
+
readonly y: Schema.Finite;
|
|
168
|
+
}>>;
|
|
169
|
+
}>, Schema.Struct<{
|
|
170
|
+
readonly kind: Schema.Literal<"lines">;
|
|
171
|
+
readonly lines: Schema.NonEmptyArray<Schema.Struct<{
|
|
172
|
+
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
173
|
+
readonly x: Schema.Finite;
|
|
174
|
+
readonly y: Schema.Finite;
|
|
175
|
+
}>, Schema.Struct<{
|
|
176
|
+
readonly x: Schema.Finite;
|
|
177
|
+
readonly y: Schema.Finite;
|
|
178
|
+
}>]>;
|
|
179
|
+
}>>;
|
|
180
|
+
}>]>;
|
|
181
|
+
readonly tolerance: Schema.Finite;
|
|
182
|
+
}>, Schema.Struct<{
|
|
183
|
+
readonly interaction: Schema.String;
|
|
184
|
+
readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
|
|
185
|
+
readonly criterion: Schema.String;
|
|
186
|
+
readonly levels: Schema.NonEmptyArray<Schema.Struct<{
|
|
187
|
+
readonly descriptor: Schema.Trimmed;
|
|
188
|
+
readonly level: Schema.String;
|
|
189
|
+
}>>;
|
|
190
|
+
}>>;
|
|
191
|
+
readonly kind: Schema.Literal<"extendedText">;
|
|
192
|
+
}>]>>;
|
|
193
|
+
readonly version: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
194
|
+
}>;
|
|
195
|
+
export type ItemKey = typeof ItemKeySchema.Type;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
|
+
import { hasDistinctIds, LocalIdSchema } from "#contracts/assessment/identity";
|
|
3
|
+
import { isWithinRecordLimit } from "#contracts/assessment/record";
|
|
4
|
+
import { LatexSchema, PlainTextSchema } from "#contracts/assessment/scalar";
|
|
5
|
+
import { Sha256HashSchema } from "#contracts/ids";
|
|
6
|
+
import { PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
|
|
7
|
+
import { QuestionDecimalSchema, QuestionTextKeySchema, QuestionToleranceSchema, } from "#contracts/question/answer";
|
|
8
|
+
const DISTINCT_MESSAGE = "Expected no part to be named twice.";
|
|
9
|
+
/** Each key names the interaction of the item version that it answers. */
|
|
10
|
+
const KeyFields = { interaction: LocalIdSchema };
|
|
11
|
+
/** The options that are correct. */
|
|
12
|
+
const ChoiceKeySchema = Schema.Struct({
|
|
13
|
+
...KeyFields,
|
|
14
|
+
correct: Schema.NonEmptyArray(LocalIdSchema).check(Schema.makeFilter(hasDistinctIds, { message: DISTINCT_MESSAGE })),
|
|
15
|
+
kind: Schema.Literal("choice"),
|
|
16
|
+
});
|
|
17
|
+
/** The column of each statement. */
|
|
18
|
+
const MatrixKeySchema = Schema.Struct({
|
|
19
|
+
...KeyFields,
|
|
20
|
+
answers: Schema.NonEmptyArray(Schema.Struct({ column: LocalIdSchema, statement: LocalIdSchema })).check(Schema.makeFilter((answers) => hasDistinctIds(Arr.map(answers, ({ statement }) => statement)), { message: "Expected one column for each statement." })),
|
|
21
|
+
kind: Schema.Literal("matrix"),
|
|
22
|
+
});
|
|
23
|
+
/** The correct pairs, each from a source to a target. */
|
|
24
|
+
const MatchKeySchema = Schema.Struct({
|
|
25
|
+
...KeyFields,
|
|
26
|
+
kind: Schema.Literal("match"),
|
|
27
|
+
pairs: Schema.NonEmptyArray(Schema.Struct({ source: LocalIdSchema, target: LocalIdSchema })).check(Schema.makeFilter((pairs) => hasDistinctIds(Arr.map(pairs, ({ source, target }) => `${source} ${target}`)), { message: "Expected no pair to be named twice." })),
|
|
28
|
+
});
|
|
29
|
+
/** The correct order of the items. */
|
|
30
|
+
const OrderKeySchema = Schema.Struct({
|
|
31
|
+
...KeyFields,
|
|
32
|
+
kind: Schema.Literal("order"),
|
|
33
|
+
sequence: Schema.NonEmptyArray(LocalIdSchema).check(Schema.makeFilter(hasDistinctIds, { message: DISTINCT_MESSAGE })),
|
|
34
|
+
});
|
|
35
|
+
/** The option that is correct. */
|
|
36
|
+
const InlineChoiceKeySchema = Schema.Struct({
|
|
37
|
+
...KeyFields,
|
|
38
|
+
correct: LocalIdSchema,
|
|
39
|
+
kind: Schema.Literal("inlineChoice"),
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* The accepted texts with their normalization. They are the text key of
|
|
43
|
+
* `question/answer`, so one grammar and one matcher grade both generations.
|
|
44
|
+
*/
|
|
45
|
+
const TextEntryKeySchema = Schema.Struct({
|
|
46
|
+
...KeyFields,
|
|
47
|
+
accepted: QuestionTextKeySchema,
|
|
48
|
+
kind: Schema.Literal("textEntry"),
|
|
49
|
+
});
|
|
50
|
+
/** The exact value and the tolerance around it. */
|
|
51
|
+
const NumericEntryKeySchema = Schema.Struct({
|
|
52
|
+
...KeyFields,
|
|
53
|
+
kind: Schema.Literal("numericEntry"),
|
|
54
|
+
tolerance: Schema.optionalKey(QuestionToleranceSchema),
|
|
55
|
+
value: QuestionDecimalSchema,
|
|
56
|
+
}).check(Schema.makeFilter(({ tolerance, value }) => tolerance?.kind !== "relative" || value !== "0", { message: "A relative tolerance cannot measure distance from zero." }));
|
|
57
|
+
/** The expression that the answer must be equivalent to. */
|
|
58
|
+
const MathEntryKeySchema = Schema.Struct({
|
|
59
|
+
...KeyFields,
|
|
60
|
+
expression: LatexSchema,
|
|
61
|
+
kind: Schema.Literal("mathEntry"),
|
|
62
|
+
});
|
|
63
|
+
/** The areas that are correct. */
|
|
64
|
+
const HotspotKeySchema = Schema.Struct({
|
|
65
|
+
...KeyFields,
|
|
66
|
+
correct: Schema.NonEmptyArray(LocalIdSchema).check(Schema.makeFilter(hasDistinctIds, { message: DISTINCT_MESSAGE })),
|
|
67
|
+
kind: Schema.Literal("hotspot"),
|
|
68
|
+
});
|
|
69
|
+
/** The choice of each gap. */
|
|
70
|
+
const GapMatchKeySchema = Schema.Struct({
|
|
71
|
+
...KeyFields,
|
|
72
|
+
kind: Schema.Literal("gapMatch"),
|
|
73
|
+
pairs: Schema.NonEmptyArray(Schema.Struct({ choice: LocalIdSchema, gap: LocalIdSchema })).check(Schema.makeFilter((pairs) => hasDistinctIds(Arr.map(pairs, ({ gap }) => gap)), { message: "Expected one choice for each gap." })),
|
|
74
|
+
});
|
|
75
|
+
/** A line through two different points. */
|
|
76
|
+
const LineSchema = Schema.Struct({
|
|
77
|
+
through: Schema.Tuple([PlanePointSchema, PlanePointSchema]),
|
|
78
|
+
}).check(Schema.makeFilter(({ through: [from, to] }) => !samePlanePoint(from, to), {
|
|
79
|
+
message: "Expected a line through two different points.",
|
|
80
|
+
}));
|
|
81
|
+
/**
|
|
82
|
+
* The points or the lines that are correct, and how far a placed point may be
|
|
83
|
+
* from one, in the units of the plane.
|
|
84
|
+
*/
|
|
85
|
+
const GraphPointKeySchema = Schema.Struct({
|
|
86
|
+
...KeyFields,
|
|
87
|
+
kind: Schema.Literal("graphPoint"),
|
|
88
|
+
target: Schema.Union([
|
|
89
|
+
Schema.Struct({
|
|
90
|
+
kind: Schema.Literal("points"),
|
|
91
|
+
points: Schema.NonEmptyArray(PlanePointSchema),
|
|
92
|
+
}),
|
|
93
|
+
Schema.Struct({
|
|
94
|
+
kind: Schema.Literal("lines"),
|
|
95
|
+
lines: Schema.NonEmptyArray(LineSchema),
|
|
96
|
+
}),
|
|
97
|
+
]),
|
|
98
|
+
tolerance: PositiveMeasureSchema,
|
|
99
|
+
});
|
|
100
|
+
/**
|
|
101
|
+
* The rubric descriptors: for each criterion, what earns each level. They are
|
|
102
|
+
* for a grader and are never shown to a learner before the key is released.
|
|
103
|
+
*/
|
|
104
|
+
const ExtendedTextKeySchema = Schema.Struct({
|
|
105
|
+
...KeyFields,
|
|
106
|
+
criteria: Schema.NonEmptyArray(Schema.Struct({
|
|
107
|
+
criterion: LocalIdSchema,
|
|
108
|
+
levels: Schema.NonEmptyArray(Schema.Struct({ descriptor: PlainTextSchema, level: LocalIdSchema })).check(Schema.makeFilter((levels) => hasDistinctIds(Arr.map(levels, ({ level }) => level)), { message: DISTINCT_MESSAGE })),
|
|
109
|
+
})).check(Schema.makeFilter((criteria) => hasDistinctIds(Arr.map(criteria, ({ criterion }) => criterion)), { message: DISTINCT_MESSAGE })),
|
|
110
|
+
kind: Schema.Literal("extendedText"),
|
|
111
|
+
});
|
|
112
|
+
/** The answer to one interaction. */
|
|
113
|
+
export const InteractionKeySchema = Schema.Union([
|
|
114
|
+
ChoiceKeySchema,
|
|
115
|
+
MatrixKeySchema,
|
|
116
|
+
MatchKeySchema,
|
|
117
|
+
OrderKeySchema,
|
|
118
|
+
InlineChoiceKeySchema,
|
|
119
|
+
TextEntryKeySchema,
|
|
120
|
+
NumericEntryKeySchema,
|
|
121
|
+
MathEntryKeySchema,
|
|
122
|
+
HotspotKeySchema,
|
|
123
|
+
GapMatchKeySchema,
|
|
124
|
+
GraphPointKeySchema,
|
|
125
|
+
ExtendedTextKeySchema,
|
|
126
|
+
]);
|
|
127
|
+
/**
|
|
128
|
+
* The answer key of one item version: its own schema and its own artifact,
|
|
129
|
+
* delivered only to a reader who is entitled to it. The prompt of the item
|
|
130
|
+
* carries no key. `version` is the hash of the item version it belongs to. Its
|
|
131
|
+
* size is limited by `assessment/record`.
|
|
132
|
+
*/
|
|
133
|
+
export const ItemKeySchema = Schema.Struct({
|
|
134
|
+
answers: Schema.NonEmptyArray(InteractionKeySchema).check(Schema.makeFilter((answers) => hasDistinctIds(Arr.map(answers, ({ interaction }) => interaction)), { message: "Expected one answer for each interaction." })),
|
|
135
|
+
version: Sha256HashSchema,
|
|
136
|
+
}).check(isWithinRecordLimit);
|