@nakafa/aksara-contracts 0.48.9 → 0.50.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 +1480 -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 +796 -0
- package/dist/assessment/item.js +108 -0
- package/dist/assessment/joint.d.ts +62 -0
- package/dist/assessment/joint.js +85 -0
- package/dist/assessment/key.d.ts +195 -0
- package/dist/assessment/key.js +136 -0
- package/dist/assessment/paper.d.ts +817 -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 +159 -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 +210 -0
- package/dist/assessment/scoring.js +205 -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/locale.d.ts +9 -0
- package/dist/locale.js +25 -1
- 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 +73 -1
|
@@ -0,0 +1,108 @@
|
|
|
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 { hasJointParts, hasOneItemRule, JointRuleSchema, sortedJoint, } from "#contracts/assessment/joint";
|
|
7
|
+
import { isWithinRecordLimit } from "#contracts/assessment/record";
|
|
8
|
+
import { ScoringOverrideSchema } from "#contracts/assessment/scoring";
|
|
9
|
+
import { hasSameStructure } from "#contracts/assessment/structure";
|
|
10
|
+
import { Sha256HashSchema } from "#contracts/ids";
|
|
11
|
+
import { ContentLanguageSchema } from "#contracts/locale";
|
|
12
|
+
/** The editorial facts that place an item in a blueprint. */
|
|
13
|
+
export const ItemBlueprintSchema = Schema.Struct({
|
|
14
|
+
cognitiveLevel: KebabKeySchema,
|
|
15
|
+
competency: KebabKeySchema,
|
|
16
|
+
topic: KebabKeySchema,
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* One item, whatever its language: a language-neutral identifier, its
|
|
20
|
+
* blueprint, and the shared reading it belongs to, if any.
|
|
21
|
+
*/
|
|
22
|
+
export const ItemFamilySchema = Schema.Struct({
|
|
23
|
+
blueprint: Schema.optionalKey(ItemBlueprintSchema),
|
|
24
|
+
id: ItemFamilyIdSchema,
|
|
25
|
+
stimulus: Schema.optionalKey(StimulusIdSchema),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* A shared reading, pinned to the exact version that this item version was
|
|
29
|
+
* written against. The reading is never copied into the prompt.
|
|
30
|
+
*/
|
|
31
|
+
export const StimulusReferenceSchema = Schema.Struct({
|
|
32
|
+
hash: Sha256HashSchema,
|
|
33
|
+
id: StimulusIdSchema,
|
|
34
|
+
});
|
|
35
|
+
/** The fields of an item version except its hash, which covers all of them. */
|
|
36
|
+
const VersionFields = {
|
|
37
|
+
deliveryLanguage: ContentLanguageSchema,
|
|
38
|
+
family: ItemFamilyIdSchema,
|
|
39
|
+
interactions: Schema.NonEmptyArray(InteractionSchema),
|
|
40
|
+
joint: Schema.optionalKey(JointRuleSchema),
|
|
41
|
+
prompt: AssessmentDocumentSchema,
|
|
42
|
+
scoring: Schema.Array(ScoringOverrideSchema),
|
|
43
|
+
stimulus: Schema.optionalKey(StimulusReferenceSchema),
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* One item in one delivery language, without its hash: the prompt document,
|
|
47
|
+
* its interactions, the scoring rules that override the exam profile, the joint
|
|
48
|
+
* rule when its answers depend on each other, and the shared reading it was
|
|
49
|
+
* written against, if it has one. The prompt carries no answer key, and the
|
|
50
|
+
* version holds no explanation: the key and the explanation are records of their
|
|
51
|
+
* own (`assessment/key`, `assessment/explanation`).
|
|
52
|
+
*/
|
|
53
|
+
export const ItemVersionBodySchema = Schema.Struct(VersionFields).check(Schema.makeFilter(hasPlacedInteractions, {
|
|
54
|
+
message: "Expected the prompt to place each interaction once, as its kind allows, and no other.",
|
|
55
|
+
}), Schema.makeFilter(hasFittingRules, {
|
|
56
|
+
message: "Expected each scoring rule to fit its interaction, and each extended text to carry a rubric.",
|
|
57
|
+
}), Schema.makeFilter(hasJointParts, {
|
|
58
|
+
message: "Expected a joint rule to name at least two interactions of the version, each level naming only those.",
|
|
59
|
+
}), Schema.makeFilter(hasOneItemRule, {
|
|
60
|
+
message: "Expected a joint rule to leave the scoring overrides empty, because one rule scores the item.",
|
|
61
|
+
}));
|
|
62
|
+
/**
|
|
63
|
+
* An item version is immutable once published: a change is a new version. Its
|
|
64
|
+
* `hash` is the SHA-256 of the canonical encoding of the body (see
|
|
65
|
+
* `assessment/hash`), so the hash names the exact content. Its size is limited
|
|
66
|
+
* by `assessment/record`.
|
|
67
|
+
*/
|
|
68
|
+
export const ItemVersionSchema = ItemVersionBodySchema.mapFields((fields) => ({ ...fields, hash: Sha256HashSchema }), { unsafePreserveChecks: true }).check(isWithinRecordLimit);
|
|
69
|
+
const ItemFieldsSchema = Schema.Struct({
|
|
70
|
+
family: ItemFamilySchema,
|
|
71
|
+
versions: Schema.NonEmptyArray(ItemVersionSchema),
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Checks that every version of a family has the same interaction structure.
|
|
75
|
+
* The old contract required translations to preserve their format, structure,
|
|
76
|
+
* and answer key, and it still holds: a translation may change words, never
|
|
77
|
+
* the task. If the structure were free to differ, one answer key, one scoring
|
|
78
|
+
* rule, and one calibrated difficulty could not serve every language of an
|
|
79
|
+
* item. The identifiers, counts, bounds, joint rule, and scoring rules must
|
|
80
|
+
* agree; the labels, the text alternatives, and the units are the words of a
|
|
81
|
+
* language. The interactions of a joint level are a set, so a language may list
|
|
82
|
+
* them in another order.
|
|
83
|
+
*/
|
|
84
|
+
function hasOneStructure(item) {
|
|
85
|
+
return hasSameStructure(Arr.map(item.versions, ({ interactions, joint, scoring }) => ({
|
|
86
|
+
interactions,
|
|
87
|
+
joint: joint === undefined ? undefined : sortedJoint(joint),
|
|
88
|
+
scoring,
|
|
89
|
+
})));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Checks that the versions belong to the family: each names its identifier and
|
|
93
|
+
* its shared reading, and no two are written in one language.
|
|
94
|
+
*/
|
|
95
|
+
function hasFamilyVersions(item) {
|
|
96
|
+
return (Arr.every(item.versions, ({ family, stimulus }) => family === item.family.id && stimulus?.id === item.family.stimulus) &&
|
|
97
|
+
hasDistinctIds(Arr.map(item.versions, ({ deliveryLanguage }) => deliveryLanguage)));
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* One item with its versions, one for each delivery language. Every version
|
|
101
|
+
* names the family and the shared reading of the family, is written in its own
|
|
102
|
+
* language, and has the same interaction structure as the others.
|
|
103
|
+
*/
|
|
104
|
+
export const ItemSchema = ItemFieldsSchema.check(Schema.makeFilter(hasFamilyVersions, {
|
|
105
|
+
message: "Expected each version to name the family and its shared reading, in a language of its own.",
|
|
106
|
+
}), Schema.makeFilter(hasOneStructure, {
|
|
107
|
+
message: "Expected every version of a family to have one interaction structure.",
|
|
108
|
+
}));
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { Interaction } from "#contracts/assessment/interaction";
|
|
3
|
+
import type { ScoringOverride } from "#contracts/assessment/scoring";
|
|
4
|
+
/**
|
|
5
|
+
* One level of a joint rule: the interactions that must all be correct for an
|
|
6
|
+
* item to earn the points of the level. An interaction is correct when its key
|
|
7
|
+
* matches it completely. The interactions form a set, so their order in the
|
|
8
|
+
* list carries no meaning.
|
|
9
|
+
*/
|
|
10
|
+
export declare const JointLevelSchema: Schema.Struct<{
|
|
11
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
12
|
+
readonly points: Schema.Int;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* One rule for the whole item, for answers that depend on each other, such as an
|
|
16
|
+
* answer and its reason. The item scores the points of the first level whose
|
|
17
|
+
* interactions are all correct, and 0 when none is. Interactions scored together
|
|
18
|
+
* make a composite item, which QTI 3 scores by general response processing, not
|
|
19
|
+
* by a standard template (Best Practices and Implementation Guide, section 3.4.2).
|
|
20
|
+
*/
|
|
21
|
+
export declare const JointRuleSchema: Schema.Struct<{
|
|
22
|
+
readonly levels: Schema.NonEmptyArray<Schema.Struct<{
|
|
23
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
24
|
+
readonly points: Schema.Int;
|
|
25
|
+
}>>;
|
|
26
|
+
}>;
|
|
27
|
+
export type JointRule = typeof JointRuleSchema.Type;
|
|
28
|
+
/** Returns the most points that a joint rule can award: the points of its first level. */
|
|
29
|
+
export declare function jointCeiling(joint: JointRule): number;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a joint rule with the interactions of each level in code-unit order.
|
|
32
|
+
* A level names a set, so the order of its listing is not part of the task: the
|
|
33
|
+
* structure check of a family compares this form, and the hash keeps the exact
|
|
34
|
+
* listing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function sortedJoint(joint: JointRule): {
|
|
37
|
+
levels: [{
|
|
38
|
+
correct: [string, ...string[]];
|
|
39
|
+
points: number;
|
|
40
|
+
}, ...{
|
|
41
|
+
correct: [string, ...string[]];
|
|
42
|
+
points: number;
|
|
43
|
+
}[]];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Checks that a joint rule has interactions to join: at least two in the
|
|
47
|
+
* version, and each level names only interactions of the version.
|
|
48
|
+
*/
|
|
49
|
+
export declare function hasJointParts(version: {
|
|
50
|
+
readonly interactions: readonly Interaction[];
|
|
51
|
+
readonly joint?: JointRule;
|
|
52
|
+
}): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Checks that a version with a joint rule sets no scoring override: one rule
|
|
55
|
+
* scores the item. This also refuses an extended text in a joint item, because
|
|
56
|
+
* an extended text needs a rubric override (`fit`), and a joint item has none. A
|
|
57
|
+
* person judges an extended text, so no key can say that it is correct.
|
|
58
|
+
*/
|
|
59
|
+
export declare function hasOneItemRule(version: {
|
|
60
|
+
readonly joint?: JointRule;
|
|
61
|
+
readonly scoring: readonly ScoringOverride[];
|
|
62
|
+
}): boolean;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Array as Arr, Order, Schema } from "effect";
|
|
2
|
+
import { hasDistinctIds, LocalIdSchema } from "#contracts/assessment/identity";
|
|
3
|
+
import { PositiveIntSchema } from "#contracts/assessment/scalar";
|
|
4
|
+
/**
|
|
5
|
+
* One level of a joint rule: the interactions that must all be correct for an
|
|
6
|
+
* item to earn the points of the level. An interaction is correct when its key
|
|
7
|
+
* matches it completely. The interactions form a set, so their order in the
|
|
8
|
+
* list carries no meaning.
|
|
9
|
+
*/
|
|
10
|
+
export const JointLevelSchema = Schema.Struct({
|
|
11
|
+
correct: Schema.NonEmptyArray(LocalIdSchema).check(Schema.makeFilter(hasDistinctIds, {
|
|
12
|
+
message: "Expected each interaction of a level once.",
|
|
13
|
+
})),
|
|
14
|
+
points: PositiveIntSchema,
|
|
15
|
+
});
|
|
16
|
+
/** Checks that each level is worth fewer points than the level above it. */
|
|
17
|
+
function hasDescendingPoints(levels) {
|
|
18
|
+
return Arr.every(Arr.zip(levels, Arr.drop(levels, 1)), ([higher, lower]) => higher.points > lower.points);
|
|
19
|
+
}
|
|
20
|
+
/** Checks that the later list names every interaction of the earlier list. */
|
|
21
|
+
function namesEveryOf(later, earlier) {
|
|
22
|
+
return Arr.every(earlier, (id) => Arr.contains(later, id));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks that every level can score. The item awards the first level whose
|
|
26
|
+
* interactions are all correct, so a later level that names every interaction
|
|
27
|
+
* of an earlier level could never score: each answer that earns it also earns
|
|
28
|
+
* the earlier level, which comes first.
|
|
29
|
+
*/
|
|
30
|
+
function hasReachableLevels(levels) {
|
|
31
|
+
return Arr.every(levels, (level, index) => Arr.every(Arr.take(levels, index), (earlier) => !namesEveryOf(level.correct, earlier.correct)));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One rule for the whole item, for answers that depend on each other, such as an
|
|
35
|
+
* answer and its reason. The item scores the points of the first level whose
|
|
36
|
+
* interactions are all correct, and 0 when none is. Interactions scored together
|
|
37
|
+
* make a composite item, which QTI 3 scores by general response processing, not
|
|
38
|
+
* by a standard template (Best Practices and Implementation Guide, section 3.4.2).
|
|
39
|
+
*/
|
|
40
|
+
export const JointRuleSchema = Schema.Struct({
|
|
41
|
+
levels: Schema.NonEmptyArray(JointLevelSchema).check(Schema.makeFilter(hasDescendingPoints, {
|
|
42
|
+
message: "Expected the points of the levels to descend.",
|
|
43
|
+
}), Schema.makeFilter(hasReachableLevels, {
|
|
44
|
+
message: "Expected no level to name every interaction of an earlier level, because the earlier level would always score first.",
|
|
45
|
+
})),
|
|
46
|
+
});
|
|
47
|
+
/** Returns the most points that a joint rule can award: the points of its first level. */
|
|
48
|
+
export function jointCeiling(joint) {
|
|
49
|
+
return Arr.headNonEmpty(joint.levels).points;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns a joint rule with the interactions of each level in code-unit order.
|
|
53
|
+
* A level names a set, so the order of its listing is not part of the task: the
|
|
54
|
+
* structure check of a family compares this form, and the hash keeps the exact
|
|
55
|
+
* listing.
|
|
56
|
+
*/
|
|
57
|
+
export function sortedJoint(joint) {
|
|
58
|
+
return {
|
|
59
|
+
levels: Arr.map(joint.levels, ({ correct, points }) => ({
|
|
60
|
+
correct: Arr.sort(correct, Order.String),
|
|
61
|
+
points,
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Checks that a joint rule has interactions to join: at least two in the
|
|
67
|
+
* version, and each level names only interactions of the version.
|
|
68
|
+
*/
|
|
69
|
+
export function hasJointParts(version) {
|
|
70
|
+
if (version.joint === undefined) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const ids = Arr.map(version.interactions, ({ id }) => id);
|
|
74
|
+
return (version.interactions.length >= 2 &&
|
|
75
|
+
Arr.every(version.joint.levels, ({ correct }) => Arr.every(correct, (id) => Arr.contains(ids, id))));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Checks that a version with a joint rule sets no scoring override: one rule
|
|
79
|
+
* scores the item. This also refuses an extended text in a joint item, because
|
|
80
|
+
* an extended text needs a rubric override (`fit`), and a joint item has none. A
|
|
81
|
+
* person judges an extended text, so no key can say that it is correct.
|
|
82
|
+
*/
|
|
83
|
+
export function hasOneItemRule(version) {
|
|
84
|
+
return version.joint === undefined || version.scoring.length === 0;
|
|
85
|
+
}
|
|
@@ -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);
|