@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.
Files changed (49) 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 +1444 -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 +759 -0
  25. package/dist/assessment/item.js +98 -0
  26. package/dist/assessment/key.d.ts +195 -0
  27. package/dist/assessment/key.js +136 -0
  28. package/dist/assessment/paper.d.ts +799 -0
  29. package/dist/assessment/paper.js +69 -0
  30. package/dist/assessment/part.d.ts +47 -0
  31. package/dist/assessment/part.js +32 -0
  32. package/dist/assessment/profile.d.ts +153 -0
  33. package/dist/assessment/profile.js +160 -0
  34. package/dist/assessment/record.d.ts +18 -0
  35. package/dist/assessment/record.js +27 -0
  36. package/dist/assessment/scalar.d.ts +18 -0
  37. package/dist/assessment/scalar.js +18 -0
  38. package/dist/assessment/scoring.d.ts +157 -0
  39. package/dist/assessment/scoring.js +150 -0
  40. package/dist/assessment/stimulus.d.ts +48 -0
  41. package/dist/assessment/stimulus.js +42 -0
  42. package/dist/assessment/structure.d.ts +13 -0
  43. package/dist/assessment/structure.js +29 -0
  44. package/dist/assessment/tools.d.ts +17 -0
  45. package/dist/assessment/tools.js +39 -0
  46. package/dist/projection/verify.d.ts +23 -23
  47. package/dist/runtime/verify.d.ts +46 -46
  48. package/dist/transport/request.d.ts +138 -138
  49. package/package.json +69 -1
@@ -0,0 +1,69 @@
1
+ import { Array as Arr, Effect, Schema } from "effect";
2
+ import { ExamProfileIdSchema, hasDistinctIds, ItemFamilyIdSchema, KebabKeySchema, PaperIdSchema, } from "#contracts/assessment/identity";
3
+ import { StimulusReferenceSchema, } from "#contracts/assessment/item";
4
+ import { Sha256HashSchema } from "#contracts/ids";
5
+ /** One place in a section: an item version, named by its family and its hash. */
6
+ export const PlacementSchema = Schema.Struct({
7
+ family: ItemFamilyIdSchema,
8
+ hash: Sha256HashSchema,
9
+ });
10
+ /** One section of a paper: the key of a section of the profile and its places in order. */
11
+ export const PaperSectionSchema = Schema.Struct({
12
+ placements: Schema.NonEmptyArray(PlacementSchema),
13
+ section: KebabKeySchema,
14
+ });
15
+ /**
16
+ * Checks that no section, and no item, appears twice. An item takes one place
17
+ * in a paper, because a paper is written in the languages of its places.
18
+ */
19
+ function hasOnePlaceEach(paper) {
20
+ return (hasDistinctIds(Arr.map(paper.sections, ({ section }) => section)) &&
21
+ hasDistinctIds(Arr.flatMap(paper.sections, ({ placements }) => Arr.map(placements, ({ family }) => family))));
22
+ }
23
+ /**
24
+ * A frozen paper: the profile it follows, by identifier and hash; the sections
25
+ * with their places in order, each place an item version by family and hash;
26
+ * and the stimulus versions that the items use, by identifier and hash. A
27
+ * paper is frozen and named by its content hash. A paper bundle carries
28
+ * prompts and stimuli only, never an answer key and never an explanation. A
29
+ * paper whose items use no shared reading lists none. The schema cannot see the
30
+ * item versions, so `verifyPaperStimuli` checks that the list is the one the
31
+ * items use.
32
+ */
33
+ export const PaperSchema = Schema.Struct({
34
+ id: PaperIdSchema,
35
+ profile: Schema.Struct({ hash: Sha256HashSchema, id: ExamProfileIdSchema }),
36
+ sections: Schema.NonEmptyArray(PaperSectionSchema),
37
+ stimuli: Schema.Array(StimulusReferenceSchema).check(Schema.makeFilter((stimuli) => hasDistinctIds(Arr.map(stimuli, ({ hash, id }) => `${id} ${hash}`)), { message: "Expected each stimulus version once." })),
38
+ }).check(Schema.makeFilter(hasOnePlaceEach, {
39
+ message: "Expected each section and each item once.",
40
+ }));
41
+ /** Whether two references name one stimulus version: the same identifier and hash. */
42
+ function sameReference(left, right) {
43
+ return left.id === right.id && left.hash === right.hash;
44
+ }
45
+ /**
46
+ * A paper does not list the stimulus versions that its item versions use.
47
+ * `missing` are the ones the items use and the paper leaves out, and `unused`
48
+ * are the ones the paper lists and no item uses.
49
+ */
50
+ export class PaperStimuliMismatchError extends Schema.TaggedError()("PaperStimuliMismatchError", {
51
+ missing: Schema.Array(StimulusReferenceSchema),
52
+ unused: Schema.Array(StimulusReferenceSchema),
53
+ }) {
54
+ }
55
+ /**
56
+ * Requires a paper to list the stimulus versions that its item versions use,
57
+ * each once, and no other: the paper names the readings it uses and its items
58
+ * name theirs, and the two must agree. `versions` are the item versions that
59
+ * the places of the paper name, one for each place. Run it before the paper is
60
+ * frozen.
61
+ */
62
+ export const verifyPaperStimuli = Effect.fn("AksaraContracts.verifyPaperStimuli")(function* (paper, versions) {
63
+ const used = Arr.dedupeWith(Arr.flatMap(versions, ({ stimulus }) => stimulus === undefined ? [] : [stimulus]), sameReference);
64
+ const missing = Arr.differenceWith(sameReference)(used, paper.stimuli);
65
+ const unused = Arr.differenceWith(sameReference)(paper.stimuli, used);
66
+ if (missing.length > 0 || unused.length > 0) {
67
+ return yield* new PaperStimuliMismatchError({ missing, unused });
68
+ }
69
+ });
@@ -0,0 +1,47 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * What every interaction has: an identifier inside its item version, and a
4
+ * label for screen readers. No interaction carries a color or any other cue
5
+ * that a reader without sight or color vision would miss.
6
+ */
7
+ export declare const InteractionFields: {
8
+ id: Schema.String;
9
+ label: Schema.Trimmed;
10
+ };
11
+ /** One option, statement, column, or item that is labeled by a document. */
12
+ export declare const DocumentPartSchema: Schema.Struct<{
13
+ readonly id: Schema.String;
14
+ readonly label: Schema.decodeTo<Schema.Struct<{
15
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
16
+ readonly type: Schema.Literal<"doc">;
17
+ }>, Schema.Unknown, never, never>;
18
+ }>;
19
+ /** One short option that is labeled by rich text, such as an inline choice. */
20
+ export declare const TextPartSchema: Schema.Struct<{
21
+ readonly id: Schema.String;
22
+ readonly label: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
23
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
24
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
25
+ }>, Schema.Struct<{
26
+ readonly attrs: Schema.Struct<{
27
+ readonly href: Schema.String;
28
+ }>;
29
+ readonly type: Schema.Literal<"link">;
30
+ }>]>>>;
31
+ readonly text: Schema.String;
32
+ readonly type: Schema.Literal<"text">;
33
+ }>, Schema.Struct<{
34
+ readonly attrs: Schema.Struct<{
35
+ readonly latex: Schema.Trimmed;
36
+ }>;
37
+ readonly type: Schema.Literal<"mathInline">;
38
+ }>]>>;
39
+ }>;
40
+ /**
41
+ * Checks that the fewest and most selections fit the parts to select from:
42
+ * the fewest is at most the most, and the most is at most the part count.
43
+ */
44
+ export declare function hasSelectionBounds(selection: {
45
+ readonly maxChoices: number;
46
+ readonly minChoices: number;
47
+ }, partCount: number): boolean;
@@ -0,0 +1,32 @@
1
+ import { Schema } from "effect";
2
+ import { ContentDocumentSchema } from "#contracts/assessment/document";
3
+ import { LocalIdSchema } from "#contracts/assessment/identity";
4
+ import { RichTextSchema } from "#contracts/assessment/inline";
5
+ import { PlainTextSchema } from "#contracts/assessment/scalar";
6
+ /**
7
+ * What every interaction has: an identifier inside its item version, and a
8
+ * label for screen readers. No interaction carries a color or any other cue
9
+ * that a reader without sight or color vision would miss.
10
+ */
11
+ export const InteractionFields = {
12
+ id: LocalIdSchema,
13
+ label: PlainTextSchema,
14
+ };
15
+ /** One option, statement, column, or item that is labeled by a document. */
16
+ export const DocumentPartSchema = Schema.Struct({
17
+ id: LocalIdSchema,
18
+ label: ContentDocumentSchema,
19
+ });
20
+ /** One short option that is labeled by rich text, such as an inline choice. */
21
+ export const TextPartSchema = Schema.Struct({
22
+ id: LocalIdSchema,
23
+ label: RichTextSchema,
24
+ });
25
+ /**
26
+ * Checks that the fewest and most selections fit the parts to select from:
27
+ * the fewest is at most the most, and the most is at most the part count.
28
+ */
29
+ export function hasSelectionBounds(selection, partCount) {
30
+ return (selection.minChoices <= selection.maxChoices &&
31
+ selection.maxChoices <= partCount);
32
+ }
@@ -0,0 +1,153 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * One section of an exam: its name in every language, how many items it has,
4
+ * how long it lasts, how a learner moves through it, which interactions it
5
+ * allows, and which tools it enables.
6
+ */
7
+ export declare const SectionTemplateSchema: Schema.Struct<{
8
+ readonly id: Schema.String;
9
+ readonly interactions: Schema.NonEmptyArray<Schema.Union<[Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">, ...(Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">)[]]>>;
10
+ readonly items: Schema.Int;
11
+ readonly names: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.Trimmed>;
12
+ readonly navigation: Schema.Literals<readonly ["free", "linear"]>;
13
+ readonly seconds: Schema.Int;
14
+ readonly tools: 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"]>>;
15
+ }>;
16
+ export type SectionTemplate = typeof SectionTemplateSchema.Type;
17
+ /** A pause between two sections, in seconds. */
18
+ export declare const BreakSchema: Schema.Struct<{
19
+ readonly after: Schema.String;
20
+ readonly seconds: Schema.Int;
21
+ }>;
22
+ /**
23
+ * What a learner can switch on without asking, what a teacher or an admin
24
+ * assigns before the exam, and what a school records with evidence.
25
+ */
26
+ export declare const AccommodationCatalogSchema: Schema.Struct<{
27
+ /** Tier 2: support assigned before the exam. */
28
+ readonly assigned: Schema.$Array<Schema.Literals<readonly ["text-to-speech", "high-contrast", "separate-room"]>>;
29
+ /**
30
+ * Tier 3: accommodations recorded with evidence. They are frozen when an
31
+ * attempt starts, and every later change is an event.
32
+ */
33
+ readonly recorded: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
34
+ readonly kind: Schema.Literal<"extraTime">;
35
+ readonly maxPercent: Schema.Int;
36
+ }>, Schema.Struct<{
37
+ readonly kind: Schema.Literal<"extraBreak">;
38
+ readonly maxSeconds: Schema.Int;
39
+ }>, Schema.Struct<{
40
+ readonly kind: Schema.Literals<readonly ["reader", "scribe", "alternateFormat"]>;
41
+ }>]>>;
42
+ /** Tier 1: tools for every learner, who sets them at any time. */
43
+ readonly universal: 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"]>>;
44
+ }>;
45
+ /** What the result page shows. A score from IRT always shows its standard error. */
46
+ export declare const ReportFormSchema: Schema.Struct<{
47
+ readonly sections: Schema.Boolean;
48
+ readonly standardError: Schema.Boolean;
49
+ readonly total: Schema.Boolean;
50
+ }>;
51
+ /**
52
+ * An exam profile: signed data that a country profile carries, not code. Try-outs
53
+ * and school exams use the same profile. It holds the official names, the
54
+ * sections, the total time, the breaks, the default scoring rules for every
55
+ * interaction kind, the scoring strategy and its scale, the accommodations, the
56
+ * form of the report, the write allowance and the grace period that apply at
57
+ * every deadline, and what a sampled math verdict does.
58
+ */
59
+ export declare const ExamProfileSchema: Schema.Struct<{
60
+ readonly accommodations: Schema.Struct<{
61
+ /** Tier 2: support assigned before the exam. */
62
+ readonly assigned: Schema.$Array<Schema.Literals<readonly ["text-to-speech", "high-contrast", "separate-room"]>>;
63
+ /**
64
+ * Tier 3: accommodations recorded with evidence. They are frozen when an
65
+ * attempt starts, and every later change is an event.
66
+ */
67
+ readonly recorded: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
68
+ readonly kind: Schema.Literal<"extraTime">;
69
+ readonly maxPercent: Schema.Int;
70
+ }>, Schema.Struct<{
71
+ readonly kind: Schema.Literal<"extraBreak">;
72
+ readonly maxSeconds: Schema.Int;
73
+ }>, Schema.Struct<{
74
+ readonly kind: Schema.Literals<readonly ["reader", "scribe", "alternateFormat"]>;
75
+ }>]>>;
76
+ /** Tier 1: tools for every learner, who sets them at any time. */
77
+ readonly universal: 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"]>>;
78
+ }>;
79
+ readonly breaks: Schema.$Array<Schema.Struct<{
80
+ readonly after: Schema.String;
81
+ readonly seconds: Schema.Int;
82
+ }>>;
83
+ readonly defaults: Schema.$Array<Schema.Struct<{
84
+ readonly interaction: Schema.Union<[Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">, ...(Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">)[]]>;
85
+ readonly rule: Schema.Union<readonly [Schema.Struct<{
86
+ readonly kind: Schema.Literal<"allOrNothing">;
87
+ }>, Schema.Struct<{
88
+ readonly floor: Schema.Int;
89
+ readonly kind: Schema.Literal<"perPart">;
90
+ readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
91
+ readonly pointsPerPart: Schema.Int;
92
+ }>]>;
93
+ }>>;
94
+ /**
95
+ * The reconciliation grace period, in seconds: how long after a deadline an
96
+ * attempt that is reconciling keeps the queued records that arrive, before it
97
+ * is submitted without the rest (Nakafa ADR 0013). It applies at every
98
+ * section deadline and at the deadline of the attempt.
99
+ */
100
+ readonly graceSeconds: Schema.Int;
101
+ readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraExamProfileId">;
102
+ readonly names: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.Trimmed>;
103
+ readonly report: Schema.Struct<{
104
+ readonly sections: Schema.Boolean;
105
+ readonly standardError: Schema.Boolean;
106
+ readonly total: Schema.Boolean;
107
+ }>;
108
+ /**
109
+ * What a sampled verdict on a math entry does. A sample is not a proof, and
110
+ * the exam decides what it is worth. `score` lets it score the answer, as in
111
+ * practice and consumer try-outs. `review` sends it to the teacher, as in a
112
+ * school exam, so there a sample never grades a student on its own.
113
+ */
114
+ readonly sampledMath: Schema.Literals<readonly ["score", "review"]>;
115
+ readonly scale: Schema.optionalKey<Schema.Struct<{
116
+ readonly maximum: Schema.Finite;
117
+ readonly minimum: Schema.Finite;
118
+ }>>;
119
+ readonly scoring: Schema.Union<readonly [Schema.Struct<{
120
+ readonly kind: Schema.Literal<"irt">;
121
+ }>, Schema.Struct<{
122
+ readonly kind: Schema.Literal<"raw">;
123
+ }>, Schema.Struct<{
124
+ readonly kind: Schema.Literal<"penalized">;
125
+ readonly marks: Schema.Struct<{
126
+ readonly blank: Schema.Int;
127
+ readonly correct: Schema.Int;
128
+ readonly wrong: Schema.Int;
129
+ }>;
130
+ }>, Schema.Struct<{
131
+ readonly formula: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.Trimmed>;
132
+ readonly kind: Schema.Literal<"composite">;
133
+ }>]>;
134
+ readonly sections: Schema.NonEmptyArray<Schema.Struct<{
135
+ readonly id: Schema.String;
136
+ readonly interactions: Schema.NonEmptyArray<Schema.Union<[Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">, ...(Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">)[]]>>;
137
+ readonly items: Schema.Int;
138
+ readonly names: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.Trimmed>;
139
+ readonly navigation: Schema.Literals<readonly ["free", "linear"]>;
140
+ readonly seconds: Schema.Int;
141
+ readonly tools: 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"]>>;
142
+ }>>;
143
+ readonly totalSeconds: Schema.Int;
144
+ /**
145
+ * The write allowance, in seconds: how long after a deadline a write that was
146
+ * already in flight still counts as on time (Nakafa ADR 0013). It applies at
147
+ * every section deadline and at the deadline of the attempt. The contract
148
+ * bounds it to whole seconds above zero, and Nakafa checks it against its
149
+ * presence lease when it loads the profile.
150
+ */
151
+ readonly writeAllowanceSeconds: Schema.Int;
152
+ }>;
153
+ export type ExamProfile = typeof ExamProfileSchema.Type;
@@ -0,0 +1,160 @@
1
+ import { Array as Arr, HashSet, Schema } from "effect";
2
+ import { ExamProfileIdSchema, hasDistinctIds, KebabKeySchema, } from "#contracts/assessment/identity";
3
+ import { InteractionKindSchema } from "#contracts/assessment/interaction";
4
+ import { LocalizedTextSchema, PositiveIntSchema, } from "#contracts/assessment/scalar";
5
+ import { DefaultRuleSchema, ScoreScaleSchema, ScoringStrategySchema, supportsRule, } from "#contracts/assessment/scoring";
6
+ import { ToolSetSchema } from "#contracts/assessment/tools";
7
+ /**
8
+ * One section of an exam: its name in every language, how many items it has,
9
+ * how long it lasts, how a learner moves through it, which interactions it
10
+ * allows, and which tools it enables.
11
+ */
12
+ export const SectionTemplateSchema = Schema.Struct({
13
+ id: KebabKeySchema,
14
+ interactions: Schema.NonEmptyArray(InteractionKindSchema).check(Schema.makeFilter(hasDistinctIds, {
15
+ message: "Expected each interaction kind once.",
16
+ })),
17
+ items: PositiveIntSchema,
18
+ names: LocalizedTextSchema,
19
+ navigation: Schema.Literals(["free", "linear"]),
20
+ seconds: PositiveIntSchema,
21
+ tools: ToolSetSchema,
22
+ });
23
+ /** A pause between two sections, in seconds. */
24
+ export const BreakSchema = Schema.Struct({
25
+ after: KebabKeySchema,
26
+ seconds: PositiveIntSchema,
27
+ });
28
+ /**
29
+ * What a learner can switch on without asking, what a teacher or an admin
30
+ * assigns before the exam, and what a school records with evidence.
31
+ */
32
+ export const AccommodationCatalogSchema = Schema.Struct({
33
+ /** Tier 2: support assigned before the exam. */
34
+ assigned: Schema.Array(Schema.Literals(["text-to-speech", "high-contrast", "separate-room"])).check(Schema.makeFilter(hasDistinctIds, {
35
+ message: "Expected each assigned support once.",
36
+ })),
37
+ /**
38
+ * Tier 3: accommodations recorded with evidence. They are frozen when an
39
+ * attempt starts, and every later change is an event.
40
+ */
41
+ recorded: Schema.Array(Schema.Union([
42
+ Schema.Struct({
43
+ kind: Schema.Literal("extraTime"),
44
+ maxPercent: PositiveIntSchema,
45
+ }),
46
+ Schema.Struct({
47
+ kind: Schema.Literal("extraBreak"),
48
+ maxSeconds: PositiveIntSchema,
49
+ }),
50
+ Schema.Struct({
51
+ kind: Schema.Literals(["reader", "scribe", "alternateFormat"]),
52
+ }),
53
+ ])).check(Schema.makeFilter((recorded) => hasDistinctIds(Arr.map(recorded, ({ kind }) => kind)), {
54
+ message: "Expected each recorded accommodation once.",
55
+ })),
56
+ /** Tier 1: tools for every learner, who sets them at any time. */
57
+ universal: ToolSetSchema,
58
+ });
59
+ /** What the result page shows. A score from IRT always shows its standard error. */
60
+ export const ReportFormSchema = Schema.Struct({
61
+ sections: Schema.Boolean,
62
+ standardError: Schema.Boolean,
63
+ total: Schema.Boolean,
64
+ });
65
+ /**
66
+ * The rule an exam sets for every interaction of one kind. The rule fits the
67
+ * kind, as the rule of an item fits its interaction.
68
+ */
69
+ const DefaultSchema = Schema.Struct({
70
+ interaction: InteractionKindSchema,
71
+ rule: DefaultRuleSchema,
72
+ }).check(Schema.makeFilter(({ interaction, rule }) => supportsRule(interaction, rule), {
73
+ message: "Expected a default rule that fits its interaction kind.",
74
+ }));
75
+ const ProfileFieldsSchema = Schema.Struct({
76
+ accommodations: AccommodationCatalogSchema,
77
+ breaks: Schema.Array(BreakSchema),
78
+ defaults: Schema.Array(DefaultSchema),
79
+ /**
80
+ * The reconciliation grace period, in seconds: how long after a deadline an
81
+ * attempt that is reconciling keeps the queued records that arrive, before it
82
+ * is submitted without the rest (Nakafa ADR 0013). It applies at every
83
+ * section deadline and at the deadline of the attempt.
84
+ */
85
+ graceSeconds: PositiveIntSchema,
86
+ id: ExamProfileIdSchema,
87
+ names: LocalizedTextSchema,
88
+ report: ReportFormSchema,
89
+ /**
90
+ * What a sampled verdict on a math entry does. A sample is not a proof, and
91
+ * the exam decides what it is worth. `score` lets it score the answer, as in
92
+ * practice and consumer try-outs. `review` sends it to the teacher, as in a
93
+ * school exam, so there a sample never grades a student on its own.
94
+ */
95
+ sampledMath: Schema.Literals(["score", "review"]),
96
+ scale: Schema.optionalKey(ScoreScaleSchema),
97
+ scoring: ScoringStrategySchema,
98
+ sections: Schema.NonEmptyArray(SectionTemplateSchema).check(Schema.makeFilter((sections) => hasDistinctIds(Arr.map(sections, ({ id }) => id)), { message: "Expected each section once." })),
99
+ totalSeconds: PositiveIntSchema,
100
+ /**
101
+ * The write allowance, in seconds: how long after a deadline a write that was
102
+ * already in flight still counts as on time (Nakafa ADR 0013). It applies at
103
+ * every section deadline and at the deadline of the attempt. The contract
104
+ * bounds it to whole seconds above zero, and Nakafa checks it against its
105
+ * presence lease when it loads the profile.
106
+ */
107
+ writeAllowanceSeconds: PositiveIntSchema,
108
+ });
109
+ /** Checks that the total is the sum of the sections. */
110
+ function hasSectionTotal(profile) {
111
+ return (Arr.reduce(profile.sections, 0, (total, { seconds }) => total + seconds) ===
112
+ profile.totalSeconds);
113
+ }
114
+ /** Checks that each break comes after a section that another section follows. */
115
+ function hasBreaksBetweenSections(profile) {
116
+ const followed = Arr.map(Arr.dropRight(profile.sections, 1), ({ id }) => id);
117
+ return (hasDistinctIds(Arr.map(profile.breaks, ({ after }) => after)) &&
118
+ Arr.every(profile.breaks, ({ after }) => Arr.contains(followed, after)));
119
+ }
120
+ /**
121
+ * Checks that every kind a section allows has one default rule, except an
122
+ * extended text, which carries a rubric of its own, and that no other kind has
123
+ * one.
124
+ */
125
+ function hasDefaultRules(profile) {
126
+ const allowed = HashSet.fromIterable(Arr.filter(Arr.flatMap(profile.sections, ({ interactions }) => interactions), (kind) => kind !== "extendedText"));
127
+ const defaulted = Arr.map(profile.defaults, ({ interaction }) => interaction);
128
+ return (hasDistinctIds(defaulted) &&
129
+ HashSet.size(allowed) === defaulted.length &&
130
+ Arr.every(defaulted, (kind) => HashSet.has(allowed, kind)));
131
+ }
132
+ /**
133
+ * Checks that the scoring strategy, the scale, and the report agree. A score
134
+ * from IRT or a composite has a scale; a raw or penalized score is a sum and
135
+ * has none. Only IRT has a standard error, and it always shows it. The report
136
+ * shows the total, the sections, or both.
137
+ */
138
+ function hasCoherentReport(profile) {
139
+ const scaled = profile.scoring.kind === "irt" || profile.scoring.kind === "composite";
140
+ return (scaled === (profile.scale !== undefined) &&
141
+ profile.report.standardError === (profile.scoring.kind === "irt") &&
142
+ (profile.report.total || profile.report.sections));
143
+ }
144
+ /**
145
+ * An exam profile: signed data that a country profile carries, not code. Try-outs
146
+ * and school exams use the same profile. It holds the official names, the
147
+ * sections, the total time, the breaks, the default scoring rules for every
148
+ * interaction kind, the scoring strategy and its scale, the accommodations, the
149
+ * form of the report, the write allowance and the grace period that apply at
150
+ * every deadline, and what a sampled math verdict does.
151
+ */
152
+ export const ExamProfileSchema = ProfileFieldsSchema.check(Schema.makeFilter(hasSectionTotal, {
153
+ message: "Expected the total time to be the sum of the section times.",
154
+ }), Schema.makeFilter(hasBreaksBetweenSections, {
155
+ message: "Expected each break after a section that another section follows.",
156
+ }), Schema.makeFilter(hasDefaultRules, {
157
+ message: "Expected one default rule for each allowed interaction kind except an extended text.",
158
+ }), Schema.makeFilter(hasCoherentReport, {
159
+ message: "Expected a scale for IRT and composite scores only, a standard error for IRT scores only, and a report of the total or the sections.",
160
+ }));
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Largest record in UTF-8 bytes of its encoded JSON text: 1 MiB, the size that
3
+ * Convex allows for one stored document
4
+ * (https://docs.convex.dev/production/state/limits, section "Documents", row
5
+ * "Size", read 13 October 2026). That limit is on a whole stored document, which
6
+ * is one row, so it belongs to each record that Nakafa stores as one row (an
7
+ * item version, a stimulus version, an answer key, and an explanation) and not
8
+ * to a document inside it. The page does not say how Convex counts the size, so
9
+ * this is the length of the encoded JSON text of the record, and a store that
10
+ * adds fields around the record keeps a lower ceiling of its own.
11
+ */
12
+ export declare const MAX_RECORD_BYTES: number;
13
+ /**
14
+ * The one size check of a record that Nakafa stores as one row. It measures the
15
+ * whole record, its hash included, so a version whose documents each fit is
16
+ * refused when together they pass the limit.
17
+ */
18
+ export declare const isWithinRecordLimit: import("effect/SchemaAST").Filter<unknown>;
@@ -0,0 +1,27 @@
1
+ import { Schema } from "effect";
2
+ import { encodeJsonText } from "#contracts/text/json";
3
+ /**
4
+ * Largest record in UTF-8 bytes of its encoded JSON text: 1 MiB, the size that
5
+ * Convex allows for one stored document
6
+ * (https://docs.convex.dev/production/state/limits, section "Documents", row
7
+ * "Size", read 13 October 2026). That limit is on a whole stored document, which
8
+ * is one row, so it belongs to each record that Nakafa stores as one row (an
9
+ * item version, a stimulus version, an answer key, and an explanation) and not
10
+ * to a document inside it. The page does not say how Convex counts the size, so
11
+ * this is the length of the encoded JSON text of the record, and a store that
12
+ * adds fields around the record keeps a lower ceiling of its own.
13
+ */
14
+ export const MAX_RECORD_BYTES = 1024 * 1024;
15
+ /** Checks that the encoded JSON text of a whole record fits `MAX_RECORD_BYTES`. */
16
+ function fitsRecordLimit(record) {
17
+ return (new TextEncoder().encode(encodeJsonText(record)).byteLength <=
18
+ MAX_RECORD_BYTES);
19
+ }
20
+ /**
21
+ * The one size check of a record that Nakafa stores as one row. It measures the
22
+ * whole record, its hash included, so a version whose documents each fit is
23
+ * refused when together they pass the limit.
24
+ */
25
+ export const isWithinRecordLimit = Schema.makeFilter(fitsRecordLimit, {
26
+ message: `Expected a record of at most ${MAX_RECORD_BYTES} encoded bytes.`,
27
+ });
@@ -0,0 +1,18 @@
1
+ import { Schema } from "effect";
2
+ /** Whole number above zero, such as a count of choices or a number of points. */
3
+ export declare const PositiveIntSchema: Schema.Int;
4
+ /** Whole number from zero up, such as the fewest choices a learner must pick. */
5
+ export declare const NonNegativeIntSchema: Schema.Int;
6
+ /**
7
+ * Plain text that a screen reader, a list, or a label can show: trimmed and
8
+ * never empty. Rich content is a document or inline content instead.
9
+ */
10
+ export declare const PlainTextSchema: Schema.Trimmed;
11
+ /**
12
+ * One LaTeX source string. LaTeX is stored once; MathML is derived at render
13
+ * time (KaTeX 0.19 `output: "htmlAndMathml"`) and is never stored.
14
+ */
15
+ export declare const LatexSchema: Schema.Trimmed;
16
+ /** Plain text written for every active app locale, such as an official name. */
17
+ export declare const LocalizedTextSchema: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.Trimmed>;
18
+ export type LocalizedText = typeof LocalizedTextSchema.Type;
@@ -0,0 +1,18 @@
1
+ import { Schema } from "effect";
2
+ import { ActiveAppLocaleCodeSchema } from "#contracts/locale";
3
+ /** Whole number above zero, such as a count of choices or a number of points. */
4
+ export const PositiveIntSchema = Schema.Int.check(Schema.isGreaterThan(0));
5
+ /** Whole number from zero up, such as the fewest choices a learner must pick. */
6
+ export const NonNegativeIntSchema = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
7
+ /**
8
+ * Plain text that a screen reader, a list, or a label can show: trimmed and
9
+ * never empty. Rich content is a document or inline content instead.
10
+ */
11
+ export const PlainTextSchema = Schema.Trimmed.check(Schema.isNonEmpty());
12
+ /**
13
+ * One LaTeX source string. LaTeX is stored once; MathML is derived at render
14
+ * time (KaTeX 0.19 `output: "htmlAndMathml"`) and is never stored.
15
+ */
16
+ export const LatexSchema = PlainTextSchema;
17
+ /** Plain text written for every active app locale, such as an official name. */
18
+ export const LocalizedTextSchema = Schema.Record(ActiveAppLocaleCodeSchema, PlainTextSchema);