@nakafa/aksara-contracts 1.0.1 → 2.0.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 (164) hide show
  1. package/README.md +8 -25
  2. package/dist/{question → assessment}/answer.d.ts +14 -58
  3. package/dist/{question → assessment}/answer.js +13 -60
  4. package/dist/assessment/catalog.d.ts +235 -0
  5. package/dist/assessment/catalog.js +115 -0
  6. package/dist/assessment/chart.d.ts +62 -0
  7. package/dist/assessment/chart.js +64 -0
  8. package/dist/assessment/closure.d.ts +28 -0
  9. package/dist/assessment/closure.js +164 -0
  10. package/dist/assessment/explanation.d.ts +13 -8
  11. package/dist/assessment/explanation.js +14 -8
  12. package/dist/assessment/figure.d.ts +140 -1
  13. package/dist/assessment/figure.js +9 -2
  14. package/dist/assessment/hash.d.ts +348 -208
  15. package/dist/assessment/hash.js +14 -0
  16. package/dist/assessment/inline.d.ts +3 -1
  17. package/dist/assessment/inline.js +20 -5
  18. package/dist/assessment/item.d.ts +8 -4
  19. package/dist/assessment/item.js +6 -2
  20. package/dist/assessment/key.js +6 -6
  21. package/dist/assessment/paper.d.ts +74 -74
  22. package/dist/assessment/snapshot.d.ts +3778 -0
  23. package/dist/assessment/snapshot.js +192 -0
  24. package/dist/cache/content.d.ts +4 -4
  25. package/dist/canonical.d.ts +6 -0
  26. package/dist/canonical.js +8 -1
  27. package/dist/content.d.ts +1 -1
  28. package/dist/content.js +0 -1
  29. package/dist/delivery.d.ts +0 -3
  30. package/dist/delivery.js +0 -5
  31. package/dist/preview/artifact.d.ts +1 -120
  32. package/dist/preview/document.d.ts +0 -586
  33. package/dist/preview/document.js +1 -47
  34. package/dist/preview/spec.d.ts +6 -1984
  35. package/dist/preview/spec.js +7 -47
  36. package/dist/preview/target.d.ts +0 -173
  37. package/dist/preview/target.js +1 -70
  38. package/dist/projection/digest.d.ts +0 -127
  39. package/dist/projection/hash.d.ts +0 -127
  40. package/dist/projection/spec.d.ts +6 -211
  41. package/dist/projection/spec.js +4 -18
  42. package/dist/projection/verify.d.ts +0 -127
  43. package/dist/projection/verify.js +0 -3
  44. package/dist/release/canonical.d.ts +2 -2
  45. package/dist/release/current/evidence.d.ts +24 -24
  46. package/dist/release/current/state.d.ts +28 -56
  47. package/dist/release/current/state.js +1 -6
  48. package/dist/release/digest.d.ts +2 -2
  49. package/dist/release/hash.d.ts +5 -5
  50. package/dist/release/head.d.ts +10 -57
  51. package/dist/release/head.js +3 -14
  52. package/dist/release/identity.d.ts +3 -3
  53. package/dist/release/items.d.ts +2 -2
  54. package/dist/release/lifecycle.d.ts +18 -18
  55. package/dist/release/policy.d.ts +3 -4
  56. package/dist/release/policy.js +2 -11
  57. package/dist/release/result/digest.d.ts +6 -18
  58. package/dist/release/result/digest.js +1 -2
  59. package/dist/release/rollback/digest.d.ts +4 -19
  60. package/dist/release/rollback/spec.d.ts +30 -792
  61. package/dist/release/rollback/spec.js +1 -4
  62. package/dist/release/snapshot/data.d.ts +599 -249
  63. package/dist/release/snapshot/data.js +11 -28
  64. package/dist/release/snapshot/evidence/assessment.d.ts +26 -0
  65. package/dist/release/snapshot/evidence/assessment.js +44 -0
  66. package/dist/release/snapshot/evidence/requirement.d.ts +1 -1
  67. package/dist/release/snapshot/evidence.d.ts +19 -19
  68. package/dist/release/snapshot/evidence.js +2 -2
  69. package/dist/release/snapshot/scope.d.ts +5 -5
  70. package/dist/release/snapshot/scope.js +1 -1
  71. package/dist/release/snapshot/spec.d.ts +15 -15
  72. package/dist/release/snapshot/spec.js +8 -8
  73. package/dist/release/snapshot/verify.d.ts +1278 -268
  74. package/dist/release/snapshot/verify.js +8 -5
  75. package/dist/release/spec.d.ts +33 -33
  76. package/dist/release/verify.d.ts +5 -5
  77. package/dist/runtime/spec.d.ts +38 -38
  78. package/dist/runtime/spec.js +4 -5
  79. package/dist/runtime/verify.d.ts +40 -40
  80. package/dist/signature/spec.d.ts +5 -5
  81. package/dist/signature/spec.js +0 -1
  82. package/dist/transport/batch.d.ts +6 -244
  83. package/dist/transport/failure.d.ts +6 -20
  84. package/dist/transport/failure.js +0 -10
  85. package/dist/transport/group.d.ts +1969 -1369
  86. package/dist/transport/group.js +0 -2
  87. package/dist/transport/request.d.ts +10691 -5086
  88. package/dist/transport/request.js +0 -3
  89. package/dist/transport/response.d.ts +219 -1442
  90. package/dist/transport/response.js +0 -4
  91. package/dist/transport/snapshot.d.ts +1187 -487
  92. package/package.json +187 -295
  93. package/dist/projection/question.d.ts +0 -1067
  94. package/dist/projection/question.js +0 -121
  95. package/dist/question/identity.d.ts +0 -175
  96. package/dist/question/identity.js +0 -207
  97. package/dist/question/item.d.ts +0 -450
  98. package/dist/question/item.js +0 -174
  99. package/dist/question/label.d.ts +0 -3
  100. package/dist/question/label.js +0 -3
  101. package/dist/question/points.d.ts +0 -18
  102. package/dist/question/points.js +0 -22
  103. package/dist/question/response.d.ts +0 -289
  104. package/dist/question/response.js +0 -167
  105. package/dist/question/rubric.d.ts +0 -234
  106. package/dist/question/rubric.js +0 -186
  107. package/dist/release/current/runtime.d.ts +0 -4
  108. package/dist/release/current/runtime.js +0 -15
  109. package/dist/release/snapshot/evidence/tryout.d.ts +0 -22
  110. package/dist/release/snapshot/evidence/tryout.js +0 -91
  111. package/dist/runtime/protected/limits.d.ts +0 -10
  112. package/dist/runtime/protected/limits.js +0 -16
  113. package/dist/runtime/protected/spec.d.ts +0 -310
  114. package/dist/runtime/protected/spec.js +0 -80
  115. package/dist/runtime/protected/verify.d.ts +0 -83
  116. package/dist/runtime/protected/verify.js +0 -70
  117. package/dist/transport/runtime.d.ts +0 -77
  118. package/dist/transport/runtime.js +0 -33
  119. package/dist/tryout/canonical.d.ts +0 -12
  120. package/dist/tryout/canonical.js +0 -7
  121. package/dist/tryout/catalog.d.ts +0 -396
  122. package/dist/tryout/catalog.js +0 -155
  123. package/dist/tryout/closure/accounting.d.ts +0 -20
  124. package/dist/tryout/closure/accounting.js +0 -70
  125. package/dist/tryout/closure/locale.d.ts +0 -14
  126. package/dist/tryout/closure/locale.js +0 -113
  127. package/dist/tryout/closure/placement.d.ts +0 -5
  128. package/dist/tryout/closure/placement.js +0 -32
  129. package/dist/tryout/digest.d.ts +0 -34
  130. package/dist/tryout/digest.js +0 -57
  131. package/dist/tryout/hash/catalog.d.ts +0 -364
  132. package/dist/tryout/hash/catalog.js +0 -209
  133. package/dist/tryout/hash/content.d.ts +0 -215
  134. package/dist/tryout/hash/content.js +0 -75
  135. package/dist/tryout/hash/placement.d.ts +0 -242
  136. package/dist/tryout/hash/placement.js +0 -56
  137. package/dist/tryout/identity.d.ts +0 -12
  138. package/dist/tryout/identity.js +0 -47
  139. package/dist/tryout/key.d.ts +0 -4
  140. package/dist/tryout/key.js +0 -8
  141. package/dist/tryout/language.d.ts +0 -24
  142. package/dist/tryout/language.js +0 -30
  143. package/dist/tryout/placement.d.ts +0 -331
  144. package/dist/tryout/placement.js +0 -96
  145. package/dist/tryout/runtime/canonical.d.ts +0 -8
  146. package/dist/tryout/runtime/canonical.js +0 -34
  147. package/dist/tryout/runtime/hash.d.ts +0 -34
  148. package/dist/tryout/runtime/hash.js +0 -13
  149. package/dist/tryout/runtime/source.d.ts +0 -44
  150. package/dist/tryout/runtime/source.js +0 -47
  151. package/dist/tryout/runtime/spec.d.ts +0 -58
  152. package/dist/tryout/runtime/spec.js +0 -21
  153. package/dist/tryout/runtime/verify.d.ts +0 -69
  154. package/dist/tryout/runtime/verify.js +0 -67
  155. package/dist/tryout/scoring.d.ts +0 -148
  156. package/dist/tryout/scoring.js +0 -98
  157. package/dist/tryout/snapshot/canonical.d.ts +0 -7
  158. package/dist/tryout/snapshot/canonical.js +0 -18
  159. package/dist/tryout/snapshot/hash.d.ts +0 -49
  160. package/dist/tryout/snapshot/hash.js +0 -22
  161. package/dist/tryout/snapshot/spec.d.ts +0 -46
  162. package/dist/tryout/snapshot/spec.js +0 -30
  163. package/dist/tryout/spec.d.ts +0 -41
  164. package/dist/tryout/spec.js +0 -46
@@ -0,0 +1,62 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * Props of `Chart`: categories along one axis and one or more series of
4
+ * values drawn as bars or lines over them, the data of a bar chart, a line
5
+ * chart, a histogram, or both marks at once. The data is the figure, so a
6
+ * learner reads the same values that the figure draws. Every series has a
7
+ * name, because no meaning may ride on color alone.
8
+ */
9
+ export declare const ChartPropsSchema: Schema.Struct<{
10
+ /**
11
+ * How the bars of a chart that has bars stand: `apart` leaves a gap between
12
+ * neighboring categories, as a bar chart does, and `touching` closes it, as a
13
+ * histogram of classes does. A chart of lines alone has no bars to place.
14
+ */
15
+ readonly bars: Schema.optionalKey<Schema.Literals<readonly ["apart", "touching"]>>;
16
+ readonly categories: Schema.NonEmptyArray<Schema.Trimmed>;
17
+ readonly description: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
18
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
19
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
20
+ }>, Schema.Struct<{
21
+ readonly attrs: Schema.Struct<{
22
+ readonly href: Schema.String;
23
+ }>;
24
+ readonly type: Schema.Literal<"link">;
25
+ }>]>>>;
26
+ readonly text: Schema.String;
27
+ readonly type: Schema.Literal<"text">;
28
+ }>, Schema.Struct<{
29
+ readonly attrs: Schema.Struct<{
30
+ readonly latex: Schema.Trimmed;
31
+ }>;
32
+ readonly type: Schema.Literal<"mathInline">;
33
+ }>]>>;
34
+ readonly series: Schema.NonEmptyArray<Schema.Struct<{
35
+ readonly label: Schema.Trimmed;
36
+ readonly mark: Schema.Literals<readonly ["bar", "line"]>;
37
+ readonly values: Schema.NonEmptyArray<Schema.NullOr<Schema.Finite>>;
38
+ }>>;
39
+ readonly title: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
40
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
41
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
42
+ }>, Schema.Struct<{
43
+ readonly attrs: Schema.Struct<{
44
+ readonly href: Schema.String;
45
+ }>;
46
+ readonly type: Schema.Literal<"link">;
47
+ }>]>>>;
48
+ readonly text: Schema.String;
49
+ readonly type: Schema.Literal<"text">;
50
+ }>, Schema.Struct<{
51
+ readonly attrs: Schema.Struct<{
52
+ readonly latex: Schema.Trimmed;
53
+ }>;
54
+ readonly type: Schema.Literal<"mathInline">;
55
+ }>]>>;
56
+ readonly valueLabel: Schema.optionalKey<Schema.Trimmed>;
57
+ readonly valueRange: Schema.optionalKey<Schema.Struct<{
58
+ readonly max: Schema.Finite;
59
+ readonly min: Schema.Finite;
60
+ }>>;
61
+ }>;
62
+ export type ChartProps = typeof ChartPropsSchema.Type;
@@ -0,0 +1,64 @@
1
+ import { Array as Arr, Schema } from "effect";
2
+ import { hasDistinctIds } from "#contracts/assessment/identity";
3
+ import { RichTextSchema } from "#contracts/assessment/inline";
4
+ import { PlainTextSchema } from "#contracts/assessment/scalar";
5
+ /**
6
+ * One series of a chart: its name, whether it is drawn as bars or as a line,
7
+ * and one value for each category. A value is null where the series has no
8
+ * value for that category, as a line of yearly growth that bars mark only in
9
+ * some years.
10
+ */
11
+ const ChartSeriesSchema = Schema.Struct({
12
+ label: PlainTextSchema,
13
+ mark: Schema.Literals(["bar", "line"]),
14
+ values: Schema.NonEmptyArray(Schema.NullOr(Schema.Finite)),
15
+ });
16
+ /** The part of the value axis that a chart shows, from its minimum to its maximum. */
17
+ const ValueRangeSchema = Schema.Struct({
18
+ max: Schema.Finite,
19
+ min: Schema.Finite,
20
+ }).check(Schema.makeFilter(({ max, min }) => min < max, {
21
+ message: "Expected a value range whose minimum is below its maximum.",
22
+ }));
23
+ const ChartFieldsSchema = Schema.Struct({
24
+ /**
25
+ * How the bars of a chart that has bars stand: `apart` leaves a gap between
26
+ * neighboring categories, as a bar chart does, and `touching` closes it, as a
27
+ * histogram of classes does. A chart of lines alone has no bars to place.
28
+ */
29
+ bars: Schema.optionalKey(Schema.Literals(["apart", "touching"])),
30
+ categories: Schema.NonEmptyArray(PlainTextSchema),
31
+ description: RichTextSchema,
32
+ series: Schema.NonEmptyArray(ChartSeriesSchema),
33
+ title: RichTextSchema,
34
+ valueLabel: Schema.optionalKey(PlainTextSchema),
35
+ valueRange: Schema.optionalKey(ValueRangeSchema),
36
+ });
37
+ /** Checks that every series has one value for each category, and at least one that is not null. */
38
+ function hasValuePerCategory(chart) {
39
+ return Arr.every(chart.series, ({ values }) => values.length === chart.categories.length &&
40
+ Arr.some(values, (value) => value !== null));
41
+ }
42
+ /** Checks that no two series share a name, so a legend tells them apart in words. */
43
+ function hasDistinctSeries(chart) {
44
+ return hasDistinctIds(Arr.map(chart.series, ({ label }) => label));
45
+ }
46
+ /** Checks that a chart says how its bars stand exactly when it has bars. */
47
+ function hasBarPlacement(chart) {
48
+ const hasBars = Arr.some(chart.series, ({ mark }) => mark === "bar");
49
+ return hasBars === (chart.bars !== undefined);
50
+ }
51
+ /**
52
+ * Props of `Chart`: categories along one axis and one or more series of
53
+ * values drawn as bars or lines over them, the data of a bar chart, a line
54
+ * chart, a histogram, or both marks at once. The data is the figure, so a
55
+ * learner reads the same values that the figure draws. Every series has a
56
+ * name, because no meaning may ride on color alone.
57
+ */
58
+ export const ChartPropsSchema = ChartFieldsSchema.check(Schema.makeFilter(hasValuePerCategory, {
59
+ message: "Expected each series to have one value for each category, and at least one value.",
60
+ }), Schema.makeFilter(hasDistinctSeries, {
61
+ message: "Expected each series to have a name of its own.",
62
+ }), Schema.makeFilter(hasBarPlacement, {
63
+ message: "Expected a bar placement on a chart with bars, and on no other.",
64
+ }));
@@ -0,0 +1,28 @@
1
+ import { Effect, Schema, Stream } from "effect";
2
+ import type { AssessmentRecord } from "#contracts/assessment/snapshot";
3
+ import type { ActiveAppLocaleList } from "#contracts/locale";
4
+ /**
5
+ * Why a snapshot is not closed: a reference names a row it does not hold, a
6
+ * row is never reached, or a paper does not fit the profile it follows.
7
+ */
8
+ export declare const AssessmentClosureReasonSchema: Schema.Literals<readonly ["explanation", "family", "key", "locale", "paper", "place", "profile", "section", "stimulus", "unplaced"]>;
9
+ declare const AssessmentClosureError_base: Schema.Class<AssessmentClosureError, Schema.TaggedStruct<"AssessmentClosureError", {
10
+ readonly identity: Schema.String;
11
+ readonly reason: Schema.Literals<readonly ["explanation", "family", "key", "locale", "paper", "place", "profile", "section", "stimulus", "unplaced"]>;
12
+ }>, import("effect/Cause").YieldableError & {
13
+ readonly brand: unique symbol;
14
+ }>;
15
+ /** A snapshot holds a reference that leads nowhere, or a row that nothing reaches. */
16
+ export declare class AssessmentClosureError extends AssessmentClosureError_base {
17
+ }
18
+ /**
19
+ * Verifies that an assessment snapshot is closed: the catalog reaches papers it
20
+ * holds, every paper fits the profile it follows and places versions it holds,
21
+ * every version has its family, its reading, its key, and an explanation in
22
+ * every active app locale, and no family, key, or explanation is left over.
23
+ */
24
+ export declare const verifyAssessmentClosure: <E, R>(input: {
25
+ readonly activeAppLocales: ActiveAppLocaleList;
26
+ readonly records: Stream.Stream<AssessmentRecord, E, R>;
27
+ }) => Effect.Effect<void, E | AssessmentClosureError, R>;
28
+ export {};
@@ -0,0 +1,164 @@
1
+ import { Array as Arr, Effect, HashMap, HashSet, Option, Result, Schema, Stream, } from "effect";
2
+ import { catalogRowIdentity } from "#contracts/assessment/catalog";
3
+ import { verifyPaperStimuli } from "#contracts/assessment/paper";
4
+ /**
5
+ * Why a snapshot is not closed: a reference names a row it does not hold, a
6
+ * row is never reached, or a paper does not fit the profile it follows.
7
+ */
8
+ export const AssessmentClosureReasonSchema = Schema.Literals([
9
+ "explanation",
10
+ "family",
11
+ "key",
12
+ "locale",
13
+ "paper",
14
+ "place",
15
+ "profile",
16
+ "section",
17
+ "stimulus",
18
+ "unplaced",
19
+ ]);
20
+ /** A snapshot holds a reference that leads nowhere, or a row that nothing reaches. */
21
+ export class AssessmentClosureError extends Schema.TaggedError()("AssessmentClosureError", {
22
+ identity: Schema.String,
23
+ reason: AssessmentClosureReasonSchema,
24
+ }) {
25
+ }
26
+ /** Gathers the rows of a snapshot by kind for the reference checks. */
27
+ function indexRows(records) {
28
+ const rows = Arr.map(records, ({ row }) => row);
29
+ return {
30
+ catalog: Arr.filterMap(rows, (row) => row.kind === "catalog" ? Result.succeed(row.row) : Result.failVoid),
31
+ explanations: HashMap.fromIterable(Arr.filterMap(rows, (row) => row.kind === "explanation"
32
+ ? Result.succeed([
33
+ explanationIdentity(row.explanation.version, row.explanation.language),
34
+ row.explanation.version,
35
+ ])
36
+ : Result.failVoid)),
37
+ families: HashMap.fromIterable(Arr.filterMap(rows, (row) => row.kind === "family"
38
+ ? Result.succeed([row.family.id, row.family])
39
+ : Result.failVoid)),
40
+ items: HashMap.fromIterable(Arr.filterMap(rows, (row) => row.kind === "item"
41
+ ? Result.succeed([row.version.hash, row.version])
42
+ : Result.failVoid)),
43
+ keys: HashSet.fromIterable(Arr.filterMap(rows, (row) => row.kind === "key" ? Result.succeed(row.key.version) : Result.failVoid)),
44
+ papers: HashMap.fromIterable(Arr.filterMap(rows, (row) => row.kind === "paper"
45
+ ? Result.succeed([row.paper.id, row])
46
+ : Result.failVoid)),
47
+ profiles: HashMap.fromIterable(Arr.filterMap(rows, (row) => row.kind === "profile"
48
+ ? Result.succeed([row.profile.id, row])
49
+ : Result.failVoid)),
50
+ stimuli: HashSet.fromIterable(Arr.filterMap(rows, (row) => row.kind === "stimulus"
51
+ ? Result.succeed(stimulusIdentity(row.version))
52
+ : Result.failVoid)),
53
+ };
54
+ }
55
+ /** The identity of one explanation: the version it explains and its language. */
56
+ function explanationIdentity(version, language) {
57
+ return `${version}\0${language}`;
58
+ }
59
+ /** The identity of one stimulus version: its identifier and its hash. */
60
+ function stimulusIdentity(version) {
61
+ return `${version.id}\0${version.hash}`;
62
+ }
63
+ /** Fails with one closure reason unless the condition holds. */
64
+ function require(holds, reason, identity) {
65
+ return holds
66
+ ? Effect.void
67
+ : Effect.fail(new AssessmentClosureError({ identity, reason }));
68
+ }
69
+ /** Checks that a paper follows its profile: the same sections, in order, each with its count of places. */
70
+ function fitsProfile(paper, profile) {
71
+ return (paper.sections.length === profile.sections.length &&
72
+ Arr.every(Arr.zip(paper.sections, profile.sections), ([placed, section]) => placed.section === section.id &&
73
+ placed.placements.length === section.items));
74
+ }
75
+ /** Verifies the papers: their profiles, their places, and the readings they list. */
76
+ const verifyPapers = Effect.fn("AksaraContracts.verifyAssessmentPapers")(function* (rows) {
77
+ for (const { paper } of HashMap.values(rows.papers)) {
78
+ const profile = HashMap.get(rows.profiles, paper.profile.id);
79
+ yield* require(Option.exists(profile, ({ hash }) => hash === paper.profile.hash), "profile", paper.id);
80
+ yield* require(Option.exists(profile, (entry) => fitsProfile(paper, entry.profile)), "section", paper.id);
81
+ const placed = Arr.flatMap(paper.sections, ({ placements }) => placements);
82
+ const versions = Arr.getSomes(Arr.map(placed, ({ family, hash }) => Option.filter(HashMap.get(rows.items, hash), (version) => version.family === family)));
83
+ yield* require(versions.length === placed.length, "place", paper.id);
84
+ yield* verifyPaperStimuli(paper, versions).pipe(Effect.mapError(() => new AssessmentClosureError({
85
+ identity: paper.id,
86
+ reason: "stimulus",
87
+ })));
88
+ }
89
+ });
90
+ /** Verifies each item version: its family, its reading, its key, its explanations, and a paper that places it. */
91
+ const verifyItems = Effect.fn("AksaraContracts.verifyAssessmentItems")(function* (rows, activeAppLocales) {
92
+ const placed = HashSet.fromIterable(Arr.flatMap(Arr.fromIterable(HashMap.values(rows.papers)), ({ paper }) => Arr.flatMap(paper.sections, ({ placements }) => Arr.map(placements, ({ hash }) => hash))));
93
+ for (const version of HashMap.values(rows.items)) {
94
+ const family = HashMap.get(rows.families, version.family);
95
+ yield* require(Option.exists(family, ({ stimulus }) => stimulus === version.stimulus?.id), "family", version.family);
96
+ yield* require(version.stimulus === undefined ||
97
+ HashSet.has(rows.stimuli, stimulusIdentity(version.stimulus)), "stimulus", version.family);
98
+ yield* require(HashSet.has(rows.keys, version.hash), "key", version.hash);
99
+ yield* require(HashSet.has(placed, version.hash), "unplaced", version.hash);
100
+ for (const language of activeAppLocales) {
101
+ const identity = explanationIdentity(version.hash, language);
102
+ yield* require(HashMap.has(rows.explanations, identity), "explanation", identity);
103
+ }
104
+ }
105
+ const familiesWithVersions = HashSet.fromIterable(Arr.map(Arr.fromIterable(HashMap.values(rows.items)), ({ family }) => family));
106
+ for (const id of HashMap.keys(rows.families)) {
107
+ yield* require(HashSet.has(familiesWithVersions, id), "family", id);
108
+ }
109
+ });
110
+ /** Verifies that keys and explanations name item versions the snapshot holds. */
111
+ function verifyRecordsOfItems(rows) {
112
+ return Effect.gen(function* () {
113
+ for (const version of rows.keys) {
114
+ yield* require(HashMap.has(rows.items, version), "key", version);
115
+ }
116
+ for (const [identity, version] of rows.explanations) {
117
+ yield* require(HashMap.has(rows.items, version), "explanation", identity);
118
+ }
119
+ });
120
+ }
121
+ /**
122
+ * Verifies the catalog: every node in every active app locale, every set's
123
+ * paper, and the sections of each set equal to the sections of its paper.
124
+ */
125
+ const verifyCatalog = Effect.fn("AksaraContracts.verifyAssessmentCatalog")(function* (rows, activeAppLocales) {
126
+ for (const row of rows.catalog) {
127
+ if (row.kind !== "set") {
128
+ continue;
129
+ }
130
+ const paper = HashMap.get(rows.papers, row.paper.id);
131
+ yield* require(Option.exists(paper, ({ hash }) => hash === row.paper.hash), "paper", row.paper.id);
132
+ const sections = Arr.filterMap(rows.catalog, (section) => section.kind === "section" &&
133
+ section.appLocale === row.appLocale &&
134
+ section.countryKey === row.countryKey &&
135
+ section.examKey === row.examKey &&
136
+ section.trackKey === row.trackKey &&
137
+ section.setKey === row.setKey
138
+ ? Result.succeed(section.sectionKey)
139
+ : Result.failVoid);
140
+ yield* require(Option.exists(paper, (entry) => HashSet.size(HashSet.fromIterable(sections)) === sections.length &&
141
+ sections.length === entry.paper.sections.length &&
142
+ Arr.every(entry.paper.sections, ({ section }) => Arr.contains(sections, section))), "section", `${row.appLocale}\0${row.setKey}`);
143
+ }
144
+ const present = HashSet.fromIterable(Arr.map(rows.catalog, catalogRowIdentity));
145
+ for (const row of rows.catalog) {
146
+ for (const appLocale of activeAppLocales) {
147
+ const identity = catalogRowIdentity({ ...row, appLocale });
148
+ yield* require(HashSet.has(present, identity), "locale", identity);
149
+ }
150
+ }
151
+ });
152
+ /**
153
+ * Verifies that an assessment snapshot is closed: the catalog reaches papers it
154
+ * holds, every paper fits the profile it follows and places versions it holds,
155
+ * every version has its family, its reading, its key, and an explanation in
156
+ * every active app locale, and no family, key, or explanation is left over.
157
+ */
158
+ export const verifyAssessmentClosure = Effect.fn("AksaraContracts.verifyAssessmentClosure")(function* (input) {
159
+ const rows = indexRows(yield* Stream.runCollect(input.records));
160
+ yield* verifyCatalog(rows, input.activeAppLocales);
161
+ yield* verifyPapers(rows);
162
+ yield* verifyItems(rows, input.activeAppLocales);
163
+ yield* verifyRecordsOfItems(rows);
164
+ });
@@ -1,19 +1,24 @@
1
1
  import { Schema } from "effect";
2
2
  /**
3
- * The explanation of one item version: its own schema and its own artifact, as
4
- * the answer key is. A paper bundle carries prompts and stimuli only, never a
5
- * key and never an explanation, so an explanation reaches a learner after
6
- * release, under the release policy that Nakafa applies, from this record. The
7
- * document places no interaction. `version` is the hash of the item version it
8
- * explains, which also fixes the delivery language it is written in. An item
9
- * version holds no explanation, and a version without one has no record. Its
10
- * size is limited by `assessment/record`.
3
+ * The explanation of one item version in one language: its own schema and its
4
+ * own artifact, as the answer key is. A paper bundle carries prompts and
5
+ * stimuli only, never a key and never an explanation, so an explanation
6
+ * reaches a learner after release, under the release policy that Nakafa
7
+ * applies, from this record. The document places no interaction. `version` is
8
+ * the hash of the item version it explains. `language` is the language the
9
+ * explanation is written in, which need not be the delivery language of the
10
+ * version: an item asked in Indonesian is explained to a learner in the
11
+ * language of the learner, and may quote the prompt in its own language. A
12
+ * version has at most one explanation in each language, and a version without
13
+ * one has no record. An item version holds no explanation. Its size is limited
14
+ * by `assessment/record`.
11
15
  */
12
16
  export declare const ItemExplanationSchema: Schema.Struct<{
13
17
  readonly document: Schema.decodeTo<Schema.Struct<{
14
18
  readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
15
19
  readonly type: Schema.Literal<"doc">;
16
20
  }>, Schema.Unknown, never, never>;
21
+ readonly language: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
17
22
  readonly version: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
18
23
  }>;
19
24
  export type ItemExplanation = typeof ItemExplanationSchema.Type;
@@ -2,17 +2,23 @@ import { Schema } from "effect";
2
2
  import { ContentDocumentSchema } from "#contracts/assessment/document";
3
3
  import { isWithinRecordLimit } from "#contracts/assessment/record";
4
4
  import { Sha256HashSchema } from "#contracts/ids";
5
+ import { ContentLanguageSchema } from "#contracts/locale";
5
6
  /**
6
- * The explanation of one item version: its own schema and its own artifact, as
7
- * the answer key is. A paper bundle carries prompts and stimuli only, never a
8
- * key and never an explanation, so an explanation reaches a learner after
9
- * release, under the release policy that Nakafa applies, from this record. The
10
- * document places no interaction. `version` is the hash of the item version it
11
- * explains, which also fixes the delivery language it is written in. An item
12
- * version holds no explanation, and a version without one has no record. Its
13
- * size is limited by `assessment/record`.
7
+ * The explanation of one item version in one language: its own schema and its
8
+ * own artifact, as the answer key is. A paper bundle carries prompts and
9
+ * stimuli only, never a key and never an explanation, so an explanation
10
+ * reaches a learner after release, under the release policy that Nakafa
11
+ * applies, from this record. The document places no interaction. `version` is
12
+ * the hash of the item version it explains. `language` is the language the
13
+ * explanation is written in, which need not be the delivery language of the
14
+ * version: an item asked in Indonesian is explained to a learner in the
15
+ * language of the learner, and may quote the prompt in its own language. A
16
+ * version has at most one explanation in each language, and a version without
17
+ * one has no record. An item version holds no explanation. Its size is limited
18
+ * by `assessment/record`.
14
19
  */
15
20
  export const ItemExplanationSchema = Schema.Struct({
16
21
  document: ContentDocumentSchema,
22
+ language: ContentLanguageSchema,
17
23
  version: Sha256HashSchema,
18
24
  }).check(isWithinRecordLimit);
@@ -508,6 +508,7 @@ export declare const LineEquationPropsSchema: Schema.Struct<{
508
508
  readonly labels: Schema.optionalKey<Schema.NonEmptyArray<Schema.Struct<{
509
509
  readonly anchorX: Schema.optionalKey<Schema.Literals<readonly ["center", "left", "right"]>>;
510
510
  readonly at: Schema.optionalKey<Schema.Int>;
511
+ readonly fontSize: Schema.optionalKey<Schema.Finite>;
511
512
  readonly offset: Schema.optionalKey<Schema.Tuple<readonly [Schema.Finite, Schema.Finite, Schema.Finite]>>;
512
513
  readonly text: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
513
514
  readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
@@ -589,10 +590,78 @@ export declare const MermaidPropsSchema: Schema.Struct<{
589
590
  readonly title: Schema.Trimmed;
590
591
  }>;
591
592
  /**
592
- * The attributes of a figure node: one of the five renderer components and the
593
+ * The attributes of a figure node: one of the six renderer components and the
593
594
  * typed props that component takes.
594
595
  */
595
596
  export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
597
+ readonly alt: Schema.Trimmed;
598
+ readonly caption: Schema.NullOr<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
599
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
600
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
601
+ }>, Schema.Struct<{
602
+ readonly attrs: Schema.Struct<{
603
+ readonly href: Schema.String;
604
+ }>;
605
+ readonly type: Schema.Literal<"link">;
606
+ }>]>>>;
607
+ readonly text: Schema.String;
608
+ readonly type: Schema.Literal<"text">;
609
+ }>, Schema.Struct<{
610
+ readonly attrs: Schema.Struct<{
611
+ readonly latex: Schema.Trimmed;
612
+ }>;
613
+ readonly type: Schema.Literal<"mathInline">;
614
+ }>]>>>;
615
+ readonly component: Schema.Literal<"Chart">;
616
+ readonly props: Schema.Struct<{
617
+ readonly bars: Schema.optionalKey<Schema.Literals<readonly ["apart", "touching"]>>;
618
+ readonly categories: Schema.NonEmptyArray<Schema.Trimmed>;
619
+ readonly description: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
620
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
621
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
622
+ }>, Schema.Struct<{
623
+ readonly attrs: Schema.Struct<{
624
+ readonly href: Schema.String;
625
+ }>;
626
+ readonly type: Schema.Literal<"link">;
627
+ }>]>>>;
628
+ readonly text: Schema.String;
629
+ readonly type: Schema.Literal<"text">;
630
+ }>, Schema.Struct<{
631
+ readonly attrs: Schema.Struct<{
632
+ readonly latex: Schema.Trimmed;
633
+ }>;
634
+ readonly type: Schema.Literal<"mathInline">;
635
+ }>]>>;
636
+ readonly series: Schema.NonEmptyArray<Schema.Struct<{
637
+ readonly label: Schema.Trimmed;
638
+ readonly mark: Schema.Literals<readonly ["bar", "line"]>;
639
+ readonly values: Schema.NonEmptyArray<Schema.NullOr<Schema.Finite>>;
640
+ }>>;
641
+ readonly title: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
642
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
643
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
644
+ }>, Schema.Struct<{
645
+ readonly attrs: Schema.Struct<{
646
+ readonly href: Schema.String;
647
+ }>;
648
+ readonly type: Schema.Literal<"link">;
649
+ }>]>>>;
650
+ readonly text: Schema.String;
651
+ readonly type: Schema.Literal<"text">;
652
+ }>, Schema.Struct<{
653
+ readonly attrs: Schema.Struct<{
654
+ readonly latex: Schema.Trimmed;
655
+ }>;
656
+ readonly type: Schema.Literal<"mathInline">;
657
+ }>]>>;
658
+ readonly valueLabel: Schema.optionalKey<Schema.Trimmed>;
659
+ readonly valueRange: Schema.optionalKey<Schema.Struct<{
660
+ readonly max: Schema.Finite;
661
+ readonly min: Schema.Finite;
662
+ }>>;
663
+ }>;
664
+ }>, Schema.Struct<{
596
665
  readonly alt: Schema.Trimmed;
597
666
  readonly caption: Schema.NullOr<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
598
667
  readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
@@ -1142,6 +1211,7 @@ export declare const FigureAttrsSchema: Schema.Union<readonly [Schema.Struct<{
1142
1211
  readonly labels: Schema.optionalKey<Schema.NonEmptyArray<Schema.Struct<{
1143
1212
  readonly anchorX: Schema.optionalKey<Schema.Literals<readonly ["center", "left", "right"]>>;
1144
1213
  readonly at: Schema.optionalKey<Schema.Int>;
1214
+ readonly fontSize: Schema.optionalKey<Schema.Finite>;
1145
1215
  readonly offset: Schema.optionalKey<Schema.Tuple<readonly [Schema.Finite, Schema.Finite, Schema.Finite]>>;
1146
1216
  readonly text: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1147
1217
  readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
@@ -1265,6 +1335,74 @@ export type FigureAttrs = typeof FigureAttrsSchema.Type;
1265
1335
  /** A figure block: an interactive visual with a required text alternative. */
1266
1336
  export declare const FigureNodeSchema: Schema.Struct<{
1267
1337
  readonly attrs: Schema.Union<readonly [Schema.Struct<{
1338
+ readonly alt: Schema.Trimmed;
1339
+ readonly caption: Schema.NullOr<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1340
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1341
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
1342
+ }>, Schema.Struct<{
1343
+ readonly attrs: Schema.Struct<{
1344
+ readonly href: Schema.String;
1345
+ }>;
1346
+ readonly type: Schema.Literal<"link">;
1347
+ }>]>>>;
1348
+ readonly text: Schema.String;
1349
+ readonly type: Schema.Literal<"text">;
1350
+ }>, Schema.Struct<{
1351
+ readonly attrs: Schema.Struct<{
1352
+ readonly latex: Schema.Trimmed;
1353
+ }>;
1354
+ readonly type: Schema.Literal<"mathInline">;
1355
+ }>]>>>;
1356
+ readonly component: Schema.Literal<"Chart">;
1357
+ readonly props: Schema.Struct<{
1358
+ readonly bars: Schema.optionalKey<Schema.Literals<readonly ["apart", "touching"]>>;
1359
+ readonly categories: Schema.NonEmptyArray<Schema.Trimmed>;
1360
+ readonly description: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1361
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1362
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
1363
+ }>, Schema.Struct<{
1364
+ readonly attrs: Schema.Struct<{
1365
+ readonly href: Schema.String;
1366
+ }>;
1367
+ readonly type: Schema.Literal<"link">;
1368
+ }>]>>>;
1369
+ readonly text: Schema.String;
1370
+ readonly type: Schema.Literal<"text">;
1371
+ }>, Schema.Struct<{
1372
+ readonly attrs: Schema.Struct<{
1373
+ readonly latex: Schema.Trimmed;
1374
+ }>;
1375
+ readonly type: Schema.Literal<"mathInline">;
1376
+ }>]>>;
1377
+ readonly series: Schema.NonEmptyArray<Schema.Struct<{
1378
+ readonly label: Schema.Trimmed;
1379
+ readonly mark: Schema.Literals<readonly ["bar", "line"]>;
1380
+ readonly values: Schema.NonEmptyArray<Schema.NullOr<Schema.Finite>>;
1381
+ }>>;
1382
+ readonly title: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1383
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1384
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
1385
+ }>, Schema.Struct<{
1386
+ readonly attrs: Schema.Struct<{
1387
+ readonly href: Schema.String;
1388
+ }>;
1389
+ readonly type: Schema.Literal<"link">;
1390
+ }>]>>>;
1391
+ readonly text: Schema.String;
1392
+ readonly type: Schema.Literal<"text">;
1393
+ }>, Schema.Struct<{
1394
+ readonly attrs: Schema.Struct<{
1395
+ readonly latex: Schema.Trimmed;
1396
+ }>;
1397
+ readonly type: Schema.Literal<"mathInline">;
1398
+ }>]>>;
1399
+ readonly valueLabel: Schema.optionalKey<Schema.Trimmed>;
1400
+ readonly valueRange: Schema.optionalKey<Schema.Struct<{
1401
+ readonly max: Schema.Finite;
1402
+ readonly min: Schema.Finite;
1403
+ }>>;
1404
+ }>;
1405
+ }>, Schema.Struct<{
1268
1406
  readonly alt: Schema.Trimmed;
1269
1407
  readonly caption: Schema.NullOr<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1270
1408
  readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
@@ -1814,6 +1952,7 @@ export declare const FigureNodeSchema: Schema.Struct<{
1814
1952
  readonly labels: Schema.optionalKey<Schema.NonEmptyArray<Schema.Struct<{
1815
1953
  readonly anchorX: Schema.optionalKey<Schema.Literals<readonly ["center", "left", "right"]>>;
1816
1954
  readonly at: Schema.optionalKey<Schema.Int>;
1955
+ readonly fontSize: Schema.optionalKey<Schema.Finite>;
1817
1956
  readonly offset: Schema.optionalKey<Schema.Tuple<readonly [Schema.Finite, Schema.Finite, Schema.Finite]>>;
1818
1957
  readonly text: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
1819
1958
  readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
@@ -1,4 +1,5 @@
1
1
  import { Array as Arr, Record as Rec, Schema } from "effect";
2
+ import { ChartPropsSchema } from "#contracts/assessment/chart";
2
3
  import { AssetIdSchema } from "#contracts/assessment/identity";
3
4
  import { RichTextSchema } from "#contracts/assessment/inline";
4
5
  import { LatexSchema, NonNegativeIntSchema, PlainTextSchema, PositiveIntSchema, } from "#contracts/assessment/scalar";
@@ -96,10 +97,11 @@ export const NumberLinePropsSchema = Schema.Struct({
96
97
  }));
97
98
  /** Whether the first or last point of a line belongs to it. */
98
99
  const EndpointStateSchema = Schema.Literals(["open", "closed"]);
99
- /** A label on a line: rich text at one of its points, nudged by an offset. */
100
+ /** A label on a line: rich text at one of its points, nudged by an offset, at an optional size. */
100
101
  const LineLabelSchema = Schema.Struct({
101
102
  anchorX: Schema.optionalKey(Schema.Literals(["center", "left", "right"])),
102
103
  at: Schema.optionalKey(NonNegativeIntSchema),
104
+ fontSize: Schema.optionalKey(PositiveMeasureSchema),
103
105
  offset: Schema.optionalKey(TripleSchema),
104
106
  text: RichTextSchema,
105
107
  });
@@ -199,10 +201,15 @@ const FigureFields = {
199
201
  caption: Schema.NullOr(RichTextSchema),
200
202
  };
201
203
  /**
202
- * The attributes of a figure node: one of the five renderer components and the
204
+ * The attributes of a figure node: one of the six renderer components and the
203
205
  * typed props that component takes.
204
206
  */
205
207
  export const FigureAttrsSchema = Schema.Union([
208
+ Schema.Struct({
209
+ ...FigureFields,
210
+ component: Schema.Literal("Chart"),
211
+ props: ChartPropsSchema,
212
+ }),
206
213
  Schema.Struct({
207
214
  ...FigureFields,
208
215
  component: Schema.Literal("MathVisual"),