@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.
Files changed (53) hide show
  1. package/README.md +9 -0
  2. package/dist/assessment/choice.d.ts +154 -0
  3. package/dist/assessment/choice.js +87 -0
  4. package/dist/assessment/document.d.ts +219 -0
  5. package/dist/assessment/document.js +162 -0
  6. package/dist/assessment/entry.d.ts +50 -0
  7. package/dist/assessment/entry.js +48 -0
  8. package/dist/assessment/explanation.d.ts +19 -0
  9. package/dist/assessment/explanation.js +18 -0
  10. package/dist/assessment/figure.d.ts +1938 -0
  11. package/dist/assessment/figure.js +236 -0
  12. package/dist/assessment/fit.d.ts +21 -0
  13. package/dist/assessment/fit.js +42 -0
  14. package/dist/assessment/graphic.d.ts +95 -0
  15. package/dist/assessment/graphic.js +106 -0
  16. package/dist/assessment/hash.d.ts +1480 -0
  17. package/dist/assessment/hash.js +66 -0
  18. package/dist/assessment/identity.d.ts +37 -0
  19. package/dist/assessment/identity.js +50 -0
  20. package/dist/assessment/inline.d.ts +124 -0
  21. package/dist/assessment/inline.js +92 -0
  22. package/dist/assessment/interaction.d.ts +219 -0
  23. package/dist/assessment/interaction.js +38 -0
  24. package/dist/assessment/item.d.ts +796 -0
  25. package/dist/assessment/item.js +108 -0
  26. package/dist/assessment/joint.d.ts +62 -0
  27. package/dist/assessment/joint.js +85 -0
  28. package/dist/assessment/key.d.ts +195 -0
  29. package/dist/assessment/key.js +136 -0
  30. package/dist/assessment/paper.d.ts +817 -0
  31. package/dist/assessment/paper.js +69 -0
  32. package/dist/assessment/part.d.ts +47 -0
  33. package/dist/assessment/part.js +32 -0
  34. package/dist/assessment/profile.d.ts +159 -0
  35. package/dist/assessment/profile.js +160 -0
  36. package/dist/assessment/record.d.ts +18 -0
  37. package/dist/assessment/record.js +27 -0
  38. package/dist/assessment/scalar.d.ts +18 -0
  39. package/dist/assessment/scalar.js +18 -0
  40. package/dist/assessment/scoring.d.ts +210 -0
  41. package/dist/assessment/scoring.js +205 -0
  42. package/dist/assessment/stimulus.d.ts +48 -0
  43. package/dist/assessment/stimulus.js +42 -0
  44. package/dist/assessment/structure.d.ts +13 -0
  45. package/dist/assessment/structure.js +29 -0
  46. package/dist/assessment/tools.d.ts +17 -0
  47. package/dist/assessment/tools.js +39 -0
  48. package/dist/locale.d.ts +9 -0
  49. package/dist/locale.js +25 -1
  50. package/dist/projection/verify.d.ts +23 -23
  51. package/dist/runtime/verify.d.ts +46 -46
  52. package/dist/transport/request.d.ts +138 -138
  53. package/package.json +73 -1
@@ -0,0 +1,210 @@
1
+ import { Schema } from "effect";
2
+ import { type InteractionKind } from "#contracts/assessment/interaction";
3
+ /**
4
+ * All or nothing: category 1 for a fully correct answer and 0 for any other,
5
+ * so k is 1. It is `match_correct` of QTI response processing.
6
+ *
7
+ * Scoring is data. The outcome of an interaction is a score category from 0 to
8
+ * k, where k is the most points its rule can award, so a partial score can
9
+ * enter an IRT model through GPCM later.
10
+ */
11
+ export declare const AllOrNothingRuleSchema: Schema.Struct<{
12
+ readonly kind: Schema.Literal<"allOrNothing">;
13
+ }>;
14
+ /**
15
+ * Points for each correct part, an optional penalty for each wrong part, and a
16
+ * floor that the score never falls below. Because an outcome is a category
17
+ * from 0 to k, the floor is zero or more and at most k. A field has one part,
18
+ * so an item version and an exam profile check the floor of a field themselves
19
+ * (`supportsRule`); the key counts the parts of every other kind, so the check
20
+ * of those waits for the key. It is `map_response` of QTI response processing:
21
+ * a `qti-mapping` whose map entries are the correct parts, whose
22
+ * `default-value` is the negative of the penalty, and whose `lower-bound` is
23
+ * the floor.
24
+ */
25
+ export declare const PerPartRuleSchema: Schema.Struct<{
26
+ readonly floor: Schema.Int;
27
+ readonly kind: Schema.Literal<"perPart">;
28
+ readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
29
+ readonly pointsPerPart: Schema.Int;
30
+ }>;
31
+ /**
32
+ * Points by the number of wrong parts, such as the AKM rule of a complex
33
+ * multiple choice with more than five statements and more than two options: 2
34
+ * points with no wrong part, 1 point with one or two, and 0 with more. An answer
35
+ * scores the points of the first band whose `wrong` is at least its number of
36
+ * wrong parts, and 0 when no band holds it. The parts are the ones the per-part
37
+ * rule counts, as the key defines them for each kind.
38
+ *
39
+ * It corresponds to no standard response processing template of QTI 3.
40
+ * `match_correct` gives 1 or 0 for the whole interaction. `map_response` maps
41
+ * each response value and sums the results. With one value for the correct parts
42
+ * and one for the wrong parts, each wrong part moves the score by the same step,
43
+ * and clamping the sum to its bounds flattens only its two ends. The table 2, 1,
44
+ * 1, 0 for 0 to 3 wrong parts has a flat step in the middle, so no sum over the
45
+ * parts gives it. Section 3.4.2 of the QTI 3 Best Practices and Implementation
46
+ * Guide says that a composite item needs general response processing, not a
47
+ * standard template. A table over the wrong parts is that kind of score, so it
48
+ * corresponds to the general response processing of that section.
49
+ */
50
+ export declare const WrongPartsRuleSchema: Schema.Struct<{
51
+ readonly bands: Schema.NonEmptyArray<Schema.Struct<{
52
+ readonly points: Schema.Int;
53
+ readonly wrong: Schema.Int;
54
+ }>>;
55
+ readonly kind: Schema.Literal<"wrongParts">;
56
+ }>;
57
+ export type WrongPartsRule = typeof WrongPartsRuleSchema.Type;
58
+ /**
59
+ * Criteria, each with ordered levels and the points of each level. The learner
60
+ * sees the criteria and the level reached; what earns a level is a descriptor
61
+ * in the key. It is the rule of `qti-extended-text-interaction`, whose
62
+ * scoring QTI leaves to a person: `qti-rubric-block` with `use="scoring"`.
63
+ */
64
+ export declare const RubricRuleSchema: Schema.Struct<{
65
+ readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
66
+ readonly id: Schema.String;
67
+ readonly label: Schema.Trimmed;
68
+ readonly levels: Schema.$Array<Schema.Struct<{
69
+ readonly id: Schema.String;
70
+ readonly label: Schema.Trimmed;
71
+ readonly points: Schema.Int;
72
+ }>>;
73
+ }>>;
74
+ readonly kind: Schema.Literal<"rubric">;
75
+ }>;
76
+ /** The rule that scores one interaction. */
77
+ export declare const ScoringRuleSchema: Schema.Union<readonly [Schema.Struct<{
78
+ readonly kind: Schema.Literal<"allOrNothing">;
79
+ }>, Schema.Struct<{
80
+ readonly floor: Schema.Int;
81
+ readonly kind: Schema.Literal<"perPart">;
82
+ readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
83
+ readonly pointsPerPart: Schema.Int;
84
+ }>, Schema.Struct<{
85
+ readonly bands: Schema.NonEmptyArray<Schema.Struct<{
86
+ readonly points: Schema.Int;
87
+ readonly wrong: Schema.Int;
88
+ }>>;
89
+ readonly kind: Schema.Literal<"wrongParts">;
90
+ }>, Schema.Struct<{
91
+ readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
92
+ readonly id: Schema.String;
93
+ readonly label: Schema.Trimmed;
94
+ readonly levels: Schema.$Array<Schema.Struct<{
95
+ readonly id: Schema.String;
96
+ readonly label: Schema.Trimmed;
97
+ readonly points: Schema.Int;
98
+ }>>;
99
+ }>>;
100
+ readonly kind: Schema.Literal<"rubric">;
101
+ }>]>;
102
+ export type ScoringRule = typeof ScoringRuleSchema.Type;
103
+ /**
104
+ * A rule that an exam profile can set for every interaction of a kind. A
105
+ * rubric is never a default: its criteria belong to one item.
106
+ */
107
+ export declare const DefaultRuleSchema: Schema.Union<readonly [Schema.Struct<{
108
+ readonly kind: Schema.Literal<"allOrNothing">;
109
+ }>, Schema.Struct<{
110
+ readonly floor: Schema.Int;
111
+ readonly kind: Schema.Literal<"perPart">;
112
+ readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
113
+ readonly pointsPerPart: Schema.Int;
114
+ }>, Schema.Struct<{
115
+ readonly bands: Schema.NonEmptyArray<Schema.Struct<{
116
+ readonly points: Schema.Int;
117
+ readonly wrong: Schema.Int;
118
+ }>>;
119
+ readonly kind: Schema.Literal<"wrongParts">;
120
+ }>]>;
121
+ /** A rule that one item sets for one of its interactions, instead of the default. */
122
+ export declare const ScoringOverrideSchema: Schema.Struct<{
123
+ readonly interaction: Schema.String;
124
+ readonly rule: Schema.Union<readonly [Schema.Struct<{
125
+ readonly kind: Schema.Literal<"allOrNothing">;
126
+ }>, Schema.Struct<{
127
+ readonly floor: Schema.Int;
128
+ readonly kind: Schema.Literal<"perPart">;
129
+ readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
130
+ readonly pointsPerPart: Schema.Int;
131
+ }>, Schema.Struct<{
132
+ readonly bands: Schema.NonEmptyArray<Schema.Struct<{
133
+ readonly points: Schema.Int;
134
+ readonly wrong: Schema.Int;
135
+ }>>;
136
+ readonly kind: Schema.Literal<"wrongParts">;
137
+ }>, Schema.Struct<{
138
+ readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
139
+ readonly id: Schema.String;
140
+ readonly label: Schema.Trimmed;
141
+ readonly levels: Schema.$Array<Schema.Struct<{
142
+ readonly id: Schema.String;
143
+ readonly label: Schema.Trimmed;
144
+ readonly points: Schema.Int;
145
+ }>>;
146
+ }>>;
147
+ readonly kind: Schema.Literal<"rubric">;
148
+ }>]>;
149
+ }>;
150
+ export type ScoringOverride = typeof ScoringOverrideSchema.Type;
151
+ /**
152
+ * Returns k, the most points a rule can award, which is the top score
153
+ * category. `parts` is the number of parts the key defines for the
154
+ * interaction, and only a per-part rule reads it.
155
+ */
156
+ export declare function scoreCeiling(rule: ScoringRule, parts: number): number;
157
+ /**
158
+ * Returns the points that a wrong-parts table gives an answer with this many
159
+ * wrong parts: the points of the first band that holds it, or 0 when none does.
160
+ * It reads the table alone, never a learner's answer: grading an answer is the
161
+ * work of Nakafa's engine.
162
+ */
163
+ export declare function pointsForWrongParts(rule: WrongPartsRule, wrongParts: number): number;
164
+ /**
165
+ * Checks that a rule can score an interaction of this kind. A rubric scores an
166
+ * extended text and nothing else, and an extended text takes no other rule. A
167
+ * field has one part, worth the points of its rule: one point, or more when
168
+ * the item is worth more. The floor of a rule per part is at most those
169
+ * points, and a wrong-parts table has one band for no wrong part. Every other
170
+ * kind has the parts that its key counts, so the key checks the floor of a rule
171
+ * for those.
172
+ */
173
+ export declare function supportsRule(kind: InteractionKind, rule: ScoringRule): boolean;
174
+ /**
175
+ * Whole marks that a penalized exam awards for a correct, a wrong, and a blank
176
+ * answer, such as +4, -1, and 0. A wrong answer costs marks, a blank never
177
+ * scores below a wrong answer, and a correct answer scores above a blank.
178
+ */
179
+ export declare const MarksSchema: Schema.Struct<{
180
+ readonly blank: Schema.Int;
181
+ readonly correct: Schema.Int;
182
+ readonly wrong: Schema.Int;
183
+ }>;
184
+ /**
185
+ * How an exam turns outcomes into a score. `irt` estimates ability from the
186
+ * outcomes, `raw` sums points, `penalized` adds marks for each outcome, and
187
+ * `composite` combines section scores by a formula that is written out for
188
+ * the reader in every language.
189
+ */
190
+ export declare const ScoringStrategySchema: Schema.Union<readonly [Schema.Struct<{
191
+ readonly kind: Schema.Literal<"irt">;
192
+ }>, Schema.Struct<{
193
+ readonly kind: Schema.Literal<"raw">;
194
+ }>, Schema.Struct<{
195
+ readonly kind: Schema.Literal<"penalized">;
196
+ readonly marks: Schema.Struct<{
197
+ readonly blank: Schema.Int;
198
+ readonly correct: Schema.Int;
199
+ readonly wrong: Schema.Int;
200
+ }>;
201
+ }>, Schema.Struct<{
202
+ readonly formula: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.Trimmed>;
203
+ readonly kind: Schema.Literal<"composite">;
204
+ }>]>;
205
+ export type ScoringStrategy = typeof ScoringStrategySchema.Type;
206
+ /** The range of a reported score, such as 400 to 1600. */
207
+ export declare const ScoreScaleSchema: Schema.Struct<{
208
+ readonly maximum: Schema.Finite;
209
+ readonly minimum: Schema.Finite;
210
+ }>;
@@ -0,0 +1,205 @@
1
+ import { Array as Arr, Match, Option, Schema } from "effect";
2
+ import { hasUniqueIds, LocalIdSchema } from "#contracts/assessment/identity";
3
+ import { canSitInText, } from "#contracts/assessment/interaction";
4
+ import { LocalizedTextSchema, NonNegativeIntSchema, PlainTextSchema, PositiveIntSchema, } from "#contracts/assessment/scalar";
5
+ /**
6
+ * All or nothing: category 1 for a fully correct answer and 0 for any other,
7
+ * so k is 1. It is `match_correct` of QTI response processing.
8
+ *
9
+ * Scoring is data. The outcome of an interaction is a score category from 0 to
10
+ * k, where k is the most points its rule can award, so a partial score can
11
+ * enter an IRT model through GPCM later.
12
+ */
13
+ export const AllOrNothingRuleSchema = Schema.Struct({
14
+ kind: Schema.Literal("allOrNothing"),
15
+ });
16
+ /**
17
+ * Points for each correct part, an optional penalty for each wrong part, and a
18
+ * floor that the score never falls below. Because an outcome is a category
19
+ * from 0 to k, the floor is zero or more and at most k. A field has one part,
20
+ * so an item version and an exam profile check the floor of a field themselves
21
+ * (`supportsRule`); the key counts the parts of every other kind, so the check
22
+ * of those waits for the key. It is `map_response` of QTI response processing:
23
+ * a `qti-mapping` whose map entries are the correct parts, whose
24
+ * `default-value` is the negative of the penalty, and whose `lower-bound` is
25
+ * the floor.
26
+ */
27
+ export const PerPartRuleSchema = Schema.Struct({
28
+ floor: NonNegativeIntSchema,
29
+ kind: Schema.Literal("perPart"),
30
+ penaltyPerWrongPart: Schema.optionalKey(PositiveIntSchema),
31
+ pointsPerPart: PositiveIntSchema,
32
+ });
33
+ /** One band of a wrong-parts table: the points that an answer keeps with up to `wrong` wrong parts. */
34
+ const WrongPartsBandSchema = Schema.Struct({
35
+ points: PositiveIntSchema,
36
+ wrong: NonNegativeIntSchema,
37
+ });
38
+ /** Checks that the bands rise in wrong parts and fall in points, so each band is a step. */
39
+ function hasWrongPartsSteps(bands) {
40
+ return Arr.every(Arr.zip(bands, Arr.drop(bands, 1)), ([lower, higher]) => lower.wrong < higher.wrong && lower.points > higher.points);
41
+ }
42
+ /**
43
+ * Points by the number of wrong parts, such as the AKM rule of a complex
44
+ * multiple choice with more than five statements and more than two options: 2
45
+ * points with no wrong part, 1 point with one or two, and 0 with more. An answer
46
+ * scores the points of the first band whose `wrong` is at least its number of
47
+ * wrong parts, and 0 when no band holds it. The parts are the ones the per-part
48
+ * rule counts, as the key defines them for each kind.
49
+ *
50
+ * It corresponds to no standard response processing template of QTI 3.
51
+ * `match_correct` gives 1 or 0 for the whole interaction. `map_response` maps
52
+ * each response value and sums the results. With one value for the correct parts
53
+ * and one for the wrong parts, each wrong part moves the score by the same step,
54
+ * and clamping the sum to its bounds flattens only its two ends. The table 2, 1,
55
+ * 1, 0 for 0 to 3 wrong parts has a flat step in the middle, so no sum over the
56
+ * parts gives it. Section 3.4.2 of the QTI 3 Best Practices and Implementation
57
+ * Guide says that a composite item needs general response processing, not a
58
+ * standard template. A table over the wrong parts is that kind of score, so it
59
+ * corresponds to the general response processing of that section.
60
+ */
61
+ export const WrongPartsRuleSchema = Schema.Struct({
62
+ bands: Schema.NonEmptyArray(WrongPartsBandSchema).check(Schema.makeFilter(hasWrongPartsSteps, {
63
+ message: "Expected the bands to rise in wrong parts and fall in points.",
64
+ })),
65
+ kind: Schema.Literal("wrongParts"),
66
+ });
67
+ const RubricLevelSchema = Schema.Struct({
68
+ id: LocalIdSchema,
69
+ label: PlainTextSchema,
70
+ points: NonNegativeIntSchema,
71
+ });
72
+ /** Checks that each level is worth more than the one below it. */
73
+ function hasAscendingPoints(levels) {
74
+ return Arr.every(Arr.zip(levels, Arr.drop(levels, 1)), ([lower, higher]) => lower.points < higher.points);
75
+ }
76
+ const RubricCriterionSchema = Schema.Struct({
77
+ id: LocalIdSchema,
78
+ label: PlainTextSchema,
79
+ levels: Schema.Array(RubricLevelSchema).check(Schema.isMinLength(2), Schema.makeFilter(hasUniqueIds, {
80
+ message: "Expected each level to have its own identifier.",
81
+ }), Schema.makeFilter(hasAscendingPoints, {
82
+ message: "Expected the points of the levels to ascend.",
83
+ })),
84
+ });
85
+ /**
86
+ * Criteria, each with ordered levels and the points of each level. The learner
87
+ * sees the criteria and the level reached; what earns a level is a descriptor
88
+ * in the key. It is the rule of `qti-extended-text-interaction`, whose
89
+ * scoring QTI leaves to a person: `qti-rubric-block` with `use="scoring"`.
90
+ */
91
+ export const RubricRuleSchema = Schema.Struct({
92
+ criteria: Schema.NonEmptyArray(RubricCriterionSchema).check(Schema.makeFilter(hasUniqueIds, {
93
+ message: "Expected each criterion to have its own identifier.",
94
+ })),
95
+ kind: Schema.Literal("rubric"),
96
+ });
97
+ /** The rule that scores one interaction. */
98
+ export const ScoringRuleSchema = Schema.Union([
99
+ AllOrNothingRuleSchema,
100
+ PerPartRuleSchema,
101
+ WrongPartsRuleSchema,
102
+ RubricRuleSchema,
103
+ ]);
104
+ /**
105
+ * A rule that an exam profile can set for every interaction of a kind. A
106
+ * rubric is never a default: its criteria belong to one item.
107
+ */
108
+ export const DefaultRuleSchema = Schema.Union([
109
+ AllOrNothingRuleSchema,
110
+ PerPartRuleSchema,
111
+ WrongPartsRuleSchema,
112
+ ]);
113
+ /** A rule that one item sets for one of its interactions, instead of the default. */
114
+ export const ScoringOverrideSchema = Schema.Struct({
115
+ interaction: LocalIdSchema,
116
+ rule: ScoringRuleSchema,
117
+ });
118
+ /** Returns the points of the highest level of a criterion. */
119
+ function highestPoints(criterion) {
120
+ return Arr.reduce(criterion.levels, 0, (highest, { points }) => Math.max(highest, points));
121
+ }
122
+ /**
123
+ * Returns k, the most points a rule can award, which is the top score
124
+ * category. `parts` is the number of parts the key defines for the
125
+ * interaction, and only a per-part rule reads it.
126
+ */
127
+ export function scoreCeiling(rule, parts) {
128
+ return Match.value(rule).pipe(Match.discriminatorsExhaustive("kind")({
129
+ allOrNothing: () => 1,
130
+ perPart: ({ pointsPerPart }) => pointsPerPart * parts,
131
+ rubric: ({ criteria }) => Arr.reduce(criteria, 0, (total, criterion) => total + highestPoints(criterion)),
132
+ wrongParts: ({ bands }) => Arr.headNonEmpty(bands).points,
133
+ }));
134
+ }
135
+ /**
136
+ * Returns the points that a wrong-parts table gives an answer with this many
137
+ * wrong parts: the points of the first band that holds it, or 0 when none does.
138
+ * It reads the table alone, never a learner's answer: grading an answer is the
139
+ * work of Nakafa's engine.
140
+ */
141
+ export function pointsForWrongParts(rule, wrongParts) {
142
+ return Arr.findFirst(rule.bands, ({ wrong }) => wrong >= wrongParts).pipe(Option.map(({ points }) => points), Option.getOrElse(() => 0));
143
+ }
144
+ /**
145
+ * Checks that a rule can score a field, which has one part. The floor of a
146
+ * per-part rule is at most the points of that part. A wrong-parts table has one
147
+ * band, for no wrong part, because a field has one part: any other band would
148
+ * award points for a wrong answer.
149
+ */
150
+ function fitsField(rule) {
151
+ if (rule.kind === "perPart") {
152
+ return rule.floor <= scoreCeiling(rule, 1);
153
+ }
154
+ if (rule.kind === "wrongParts") {
155
+ return rule.bands.length === 1 && Arr.headNonEmpty(rule.bands).wrong === 0;
156
+ }
157
+ return true;
158
+ }
159
+ /**
160
+ * Checks that a rule can score an interaction of this kind. A rubric scores an
161
+ * extended text and nothing else, and an extended text takes no other rule. A
162
+ * field has one part, worth the points of its rule: one point, or more when
163
+ * the item is worth more. The floor of a rule per part is at most those
164
+ * points, and a wrong-parts table has one band for no wrong part. Every other
165
+ * kind has the parts that its key counts, so the key checks the floor of a rule
166
+ * for those.
167
+ */
168
+ export function supportsRule(kind, rule) {
169
+ return ((kind === "extendedText") === (rule.kind === "rubric") &&
170
+ (!canSitInText(kind) || fitsField(rule)));
171
+ }
172
+ /**
173
+ * Whole marks that a penalized exam awards for a correct, a wrong, and a blank
174
+ * answer, such as +4, -1, and 0. A wrong answer costs marks, a blank never
175
+ * scores below a wrong answer, and a correct answer scores above a blank.
176
+ */
177
+ export const MarksSchema = Schema.Struct({
178
+ blank: Schema.Int,
179
+ correct: Schema.Int.check(Schema.isGreaterThan(0)),
180
+ wrong: Schema.Int.check(Schema.isLessThan(0)),
181
+ }).check(Schema.makeFilter(({ blank, correct, wrong }) => wrong <= blank && blank < correct, {
182
+ message: "Expected wrong marks at or below blank marks, and blank marks below correct marks.",
183
+ }));
184
+ /**
185
+ * How an exam turns outcomes into a score. `irt` estimates ability from the
186
+ * outcomes, `raw` sums points, `penalized` adds marks for each outcome, and
187
+ * `composite` combines section scores by a formula that is written out for
188
+ * the reader in every language.
189
+ */
190
+ export const ScoringStrategySchema = Schema.Union([
191
+ Schema.Struct({ kind: Schema.Literal("irt") }),
192
+ Schema.Struct({ kind: Schema.Literal("raw") }),
193
+ Schema.Struct({ kind: Schema.Literal("penalized"), marks: MarksSchema }),
194
+ Schema.Struct({
195
+ formula: LocalizedTextSchema,
196
+ kind: Schema.Literal("composite"),
197
+ }),
198
+ ]);
199
+ /** The range of a reported score, such as 400 to 1600. */
200
+ export const ScoreScaleSchema = Schema.Struct({
201
+ maximum: Schema.Finite,
202
+ minimum: Schema.Finite,
203
+ }).check(Schema.makeFilter(({ maximum, minimum }) => minimum < maximum, {
204
+ message: "Expected a scale whose minimum is below its maximum.",
205
+ }));
@@ -0,0 +1,48 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * One shared reading or figure in one delivery language, without its hash. It
4
+ * is a document that places no interaction.
5
+ */
6
+ export declare const StimulusVersionBodySchema: Schema.Struct<{
7
+ deliveryLanguage: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
8
+ document: Schema.decodeTo<Schema.Struct<{
9
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
10
+ readonly type: Schema.Literal<"doc">;
11
+ }>, Schema.Unknown, never, never>;
12
+ id: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
13
+ }>;
14
+ /**
15
+ * A stimulus version is immutable once published: a change is a new version.
16
+ * Its `hash` is the SHA-256 of the canonical encoding of the body (see
17
+ * `assessment/hash`). Items use the version by identifier and hash and never
18
+ * copy its document into their prompts. Its size is limited by
19
+ * `assessment/record`.
20
+ */
21
+ export declare const StimulusVersionSchema: Schema.Struct<{
22
+ readonly deliveryLanguage: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
23
+ readonly document: Schema.decodeTo<Schema.Struct<{
24
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
25
+ readonly type: Schema.Literal<"doc">;
26
+ }>, Schema.Unknown, never, never>;
27
+ readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
28
+ readonly hash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
29
+ }>;
30
+ export type StimulusVersion = typeof StimulusVersionSchema.Type;
31
+ /**
32
+ * One stimulus with a version for each delivery language. Its identifier is
33
+ * namespaced, so two sets that both call a reading `passage-1` have two
34
+ * stimuli. A group of items uses one by reference and hash.
35
+ */
36
+ export declare const StimulusSchema: Schema.Struct<{
37
+ readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
38
+ readonly versions: Schema.NonEmptyArray<Schema.Struct<{
39
+ readonly deliveryLanguage: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
40
+ readonly document: Schema.decodeTo<Schema.Struct<{
41
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
42
+ readonly type: Schema.Literal<"doc">;
43
+ }>, Schema.Unknown, never, never>;
44
+ readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
45
+ readonly hash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
46
+ }>>;
47
+ }>;
48
+ export type Stimulus = typeof StimulusSchema.Type;
@@ -0,0 +1,42 @@
1
+ import { Array as Arr, Schema } from "effect";
2
+ import { ContentDocumentSchema } from "#contracts/assessment/document";
3
+ import { hasDistinctIds, StimulusIdSchema, } from "#contracts/assessment/identity";
4
+ import { isWithinRecordLimit } from "#contracts/assessment/record";
5
+ import { Sha256HashSchema } from "#contracts/ids";
6
+ import { ContentLanguageSchema } from "#contracts/locale";
7
+ /** The fields of a stimulus version except its hash, which covers all of them. */
8
+ const VersionFields = {
9
+ deliveryLanguage: ContentLanguageSchema,
10
+ document: ContentDocumentSchema,
11
+ id: StimulusIdSchema,
12
+ };
13
+ /**
14
+ * One shared reading or figure in one delivery language, without its hash. It
15
+ * is a document that places no interaction.
16
+ */
17
+ export const StimulusVersionBodySchema = Schema.Struct(VersionFields);
18
+ /**
19
+ * A stimulus version is immutable once published: a change is a new version.
20
+ * Its `hash` is the SHA-256 of the canonical encoding of the body (see
21
+ * `assessment/hash`). Items use the version by identifier and hash and never
22
+ * copy its document into their prompts. Its size is limited by
23
+ * `assessment/record`.
24
+ */
25
+ export const StimulusVersionSchema = StimulusVersionBodySchema.mapFields((fields) => ({ ...fields, hash: Sha256HashSchema }), { unsafePreserveChecks: true }).check(isWithinRecordLimit);
26
+ const StimulusFieldsSchema = Schema.Struct({
27
+ id: StimulusIdSchema,
28
+ versions: Schema.NonEmptyArray(StimulusVersionSchema),
29
+ });
30
+ /** Checks that every version names the stimulus, in a language of its own. */
31
+ function hasOwnVersions(stimulus) {
32
+ return (Arr.every(stimulus.versions, ({ id }) => id === stimulus.id) &&
33
+ hasDistinctIds(Arr.map(stimulus.versions, ({ deliveryLanguage }) => deliveryLanguage)));
34
+ }
35
+ /**
36
+ * One stimulus with a version for each delivery language. Its identifier is
37
+ * namespaced, so two sets that both call a reading `passage-1` have two
38
+ * stimuli. A group of items uses one by reference and hash.
39
+ */
40
+ export const StimulusSchema = StimulusFieldsSchema.check(Schema.makeFilter(hasOwnVersions, {
41
+ message: "Expected each version to name the stimulus, in a language of its own.",
42
+ }));
@@ -0,0 +1,13 @@
1
+ import { Array as Arr } from "effect";
2
+ /**
3
+ * Returns a value without its words: every field in `LANGUAGE_FIELDS` is
4
+ * dropped at every depth, so what remains is identifiers, counts, bounds, and
5
+ * flags.
6
+ */
7
+ export declare function structureOf(value: unknown): unknown;
8
+ /**
9
+ * Checks that every value has the structure of the first. The structure of an
10
+ * interaction is what its answer key and its scoring rule are written
11
+ * against, so translations of one item may change words and never structure.
12
+ */
13
+ export declare function hasSameStructure(values: Arr.NonEmptyReadonlyArray<unknown>): boolean;
@@ -0,0 +1,29 @@
1
+ import { Array as Arr, Equal, HashSet, Predicate, Record as Rec } from "effect";
2
+ /**
3
+ * The fields that hold the words of a language: a label, a text alternative,
4
+ * and a unit. Everything else in an interaction is structure.
5
+ */
6
+ const LANGUAGE_FIELDS = HashSet.make("alt", "label", "unit");
7
+ /**
8
+ * Returns a value without its words: every field in `LANGUAGE_FIELDS` is
9
+ * dropped at every depth, so what remains is identifiers, counts, bounds, and
10
+ * flags.
11
+ */
12
+ export function structureOf(value) {
13
+ if (Arr.isArray(value)) {
14
+ return Arr.map(value, (part) => structureOf(part));
15
+ }
16
+ if (Predicate.isObject(value)) {
17
+ return Rec.map(Rec.filter(value, (_, key) => !HashSet.has(LANGUAGE_FIELDS, key)), (part) => structureOf(part));
18
+ }
19
+ return value;
20
+ }
21
+ /**
22
+ * Checks that every value has the structure of the first. The structure of an
23
+ * interaction is what its answer key and its scoring rule are written
24
+ * against, so translations of one item may change words and never structure.
25
+ */
26
+ export function hasSameStructure(values) {
27
+ const first = structureOf(Arr.headNonEmpty(values));
28
+ return Arr.every(values, (value) => Equal.equals(structureOf(value), first));
29
+ }
@@ -0,0 +1,17 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * The calculators a section can offer. A section with none of them offers no
4
+ * calculator; "none" is the absence of every identifier here.
5
+ */
6
+ export declare const CalculatorToolSchema: Schema.Literals<readonly ["calculator-basic", "calculator-scientific", "calculator-graphing"]>;
7
+ /**
8
+ * The registry of player tools. A section of an exam profile enables tools by
9
+ * these identifiers: a calculator of one level, a formula sheet, an option
10
+ * eliminator, a highlighter, mark for review, notes, a line reader, zoom, hide
11
+ * timer, and text to speech.
12
+ */
13
+ export declare const ToolIdSchema: Schema.Literals<readonly ["calculator-basic", "calculator-scientific", "calculator-graphing", "formula-sheet", "option-eliminator", "highlighter", "mark-for-review", "notes", "line-reader", "zoom", "hide-timer", "text-to-speech"]>;
14
+ export type ToolId = typeof ToolIdSchema.Type;
15
+ /** A set of tools: each once, and at most one calculator. */
16
+ export declare const ToolSetSchema: Schema.$Array<Schema.Literals<readonly ["calculator-basic", "calculator-scientific", "calculator-graphing", "formula-sheet", "option-eliminator", "highlighter", "mark-for-review", "notes", "line-reader", "zoom", "hide-timer", "text-to-speech"]>>;
17
+ export type ToolSet = typeof ToolSetSchema.Type;
@@ -0,0 +1,39 @@
1
+ import { Array as Arr, Schema } from "effect";
2
+ import { hasDistinctIds } from "#contracts/assessment/identity";
3
+ /**
4
+ * The calculators a section can offer. A section with none of them offers no
5
+ * calculator; "none" is the absence of every identifier here.
6
+ */
7
+ export const CalculatorToolSchema = Schema.Literals([
8
+ "calculator-basic",
9
+ "calculator-scientific",
10
+ "calculator-graphing",
11
+ ]);
12
+ /**
13
+ * The registry of player tools. A section of an exam profile enables tools by
14
+ * these identifiers: a calculator of one level, a formula sheet, an option
15
+ * eliminator, a highlighter, mark for review, notes, a line reader, zoom, hide
16
+ * timer, and text to speech.
17
+ */
18
+ export const ToolIdSchema = Schema.Literals([
19
+ ...CalculatorToolSchema.literals,
20
+ "formula-sheet",
21
+ "option-eliminator",
22
+ "highlighter",
23
+ "mark-for-review",
24
+ "notes",
25
+ "line-reader",
26
+ "zoom",
27
+ "hide-timer",
28
+ "text-to-speech",
29
+ ]);
30
+ /** Checks that a set of tools offers at most one calculator. */
31
+ function hasOneCalculator(tools) {
32
+ return Arr.filter(tools, Schema.is(CalculatorToolSchema)).length <= 1;
33
+ }
34
+ /** A set of tools: each once, and at most one calculator. */
35
+ export const ToolSetSchema = Schema.Array(ToolIdSchema).check(Schema.makeFilter(hasDistinctIds, {
36
+ message: "Expected each tool once.",
37
+ }), Schema.makeFilter(hasOneCalculator, {
38
+ message: "Expected at most one calculator.",
39
+ }));
package/dist/locale.d.ts CHANGED
@@ -13,6 +13,15 @@ export declare function makeAppLocale<const Code extends AppLocaleCode>(code: Co
13
13
  /** Language delivered by content whose language may differ from the app shell. */
14
14
  export declare const DeliveryLanguageSchema: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraDeliveryLanguage">;
15
15
  export type DeliveryLanguage = typeof DeliveryLanguageSchema.Type;
16
+ /**
17
+ * A language of one assessment text, as a BCP 47 tag in its canonical form, such
18
+ * as `ar`, `de-CH`, or `zh-Hant-TW`. Unlike `DeliveryLanguageSchema`, it is not
19
+ * limited to the app locales, so a school can write in any language. The
20
+ * direction of a text is not stored: the renderer takes it from the script of
21
+ * each text.
22
+ */
23
+ export declare const ContentLanguageSchema: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
24
+ export type ContentLanguage = typeof ContentLanguageSchema.Type;
16
25
  /** Locale identity of one immutable compiled content artifact. */
17
26
  export declare const ArtifactLocaleSchema: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
18
27
  export type ArtifactLocale = typeof ArtifactLocaleSchema.Type;
package/dist/locale.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import { Array as Arr, Option, Schema } from "effect";
2
2
  import { hasCanonicalOrder } from "#contracts/canonical";
3
3
  /** Stable locale codes supported by the current Aksara contract. */
4
4
  export const AppLocaleCodeSchema = Schema.Literals(["en", "id", "de"]);
@@ -16,6 +16,30 @@ export function makeAppLocale(code) {
16
16
  }
17
17
  /** Language delivered by content whose language may differ from the app shell. */
18
18
  export const DeliveryLanguageSchema = AppLocaleCodeSchema.pipe(Schema.brand("@NakafaAI/AksaraDeliveryLanguage"));
19
+ const CONTENT_LANGUAGE_BRAND = "@NakafaAI/AksaraContentLanguage";
20
+ /** Intl's canonical form of one language tag, or nothing when Intl rejects the tag. */
21
+ const canonicalLanguageTag = Option.liftThrowable((tag) => Intl.getCanonicalLocales(tag));
22
+ /**
23
+ * Explains why a string is not a content language. Intl must accept it, and it
24
+ * must already be the one canonical form that Intl writes for it. A tag that
25
+ * Intl rewrites names that form, so the author can correct it.
26
+ */
27
+ function contentLanguageIssue(tag) {
28
+ return Option.match(Option.flatMap(canonicalLanguageTag(tag), Arr.head), {
29
+ onNone: () => "Expected a well-formed BCP 47 language tag.",
30
+ onSome: (canonical) => canonical === tag
31
+ ? undefined
32
+ : `Expected the canonical language tag "${canonical}".`,
33
+ });
34
+ }
35
+ /**
36
+ * A language of one assessment text, as a BCP 47 tag in its canonical form, such
37
+ * as `ar`, `de-CH`, or `zh-Hant-TW`. Unlike `DeliveryLanguageSchema`, it is not
38
+ * limited to the app locales, so a school can write in any language. The
39
+ * direction of a text is not stored: the renderer takes it from the script of
40
+ * each text.
41
+ */
42
+ export const ContentLanguageSchema = Schema.String.pipe(Schema.check(Schema.makeFilter(contentLanguageIssue)), Schema.brand(CONTENT_LANGUAGE_BRAND));
19
43
  /** Locale identity of one immutable compiled content artifact. */
20
44
  export const ArtifactLocaleSchema = AppLocaleCodeSchema.pipe(Schema.brand("@NakafaAI/AksaraArtifactLocale"));
21
45
  /** Canonical locale order used by every active-locale subset. */