@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
package/README.md CHANGED
@@ -30,31 +30,10 @@ Current consumers use unversioned semantic Interfaces:
30
30
  `canonicalizeContentTree` gives the bytes that hashes and signatures cover.
31
31
  - `graph/family` classifies either a complete graph identity or one exact
32
32
  asset ID into its application locale and content family.
33
- - `tryout/catalog` owns minimal catalog node schemas, while `tryout/identity`
34
- builds their pure lookup identities before complete signed rows are loaded.
35
33
  - `projection/material` owns the application-locale material namespace and
36
34
  validates every signed route and projection against it. Lesson metadata may
37
35
  carry an optional `searchTitle` for the HTML title, while `title` stays the
38
36
  short navigation name.
39
- - `question/response` owns the frozen response formats: `single-choice`,
40
- `multiple-choice`, `category`, `short-answer`, and `rubric`.
41
- - `question/answer` owns deterministic short-answer and final-answer keys: an
42
- exact canonical decimal with an optional tolerance and an explicit fraction
43
- flag, or accepted text with explicit normalization rules. Every runtime
44
- grades a typed answer only through `matchesAnswerKey`, reads a typed number
45
- only through `readNumberAnswer`, the one number grammar, and decides that a
46
- typed answer is blank only through `isBlankAnswer`, so whitespace and
47
- invisible format characters alone never count as an answer.
48
- - `question/rubric` owns the locale-neutral `QuestionRubricScaleSchema`
49
- (ordered criteria and levels with points and optional final-answer keys)
50
- and the Aksara rubric, which labels every criterion and level in every
51
- active app locale. Each judged criterion maps onto one Effect
52
- `Decision.rate` decision, and its total is derived, never stored.
53
- - `question/points` owns a question's worth. Raw, penalized, and IRT scoring
54
- read it only through `questionPoints`.
55
- - `tryout/spec` owns the `irt`, `penalized`, and `raw` scoring strategies, the
56
- per-section marks of a penalized exam, and the `institution`, `subject`, and
57
- `year` track kinds.
58
37
  - `projection/page` owns stable public page identities, localized paths, and
59
38
  signed metadata for human, agent, and sitemap delivery.
60
39
  - `math/base` owns the unversioned base schemas that mathematical visuals
@@ -68,15 +47,19 @@ Current consumers use unversioned semantic Interfaces:
68
47
  with typed `figure` props, twelve `interaction` kinds that hold no answer
69
48
  key, `scoring` as data, the `key` and the `explanation` of an item version as
70
49
  records of their own, `item` and `stimulus` versions named by a content hash,
71
- and the exam `profile`, the frozen `paper`, and the `tools` registry. It is
72
- the successor to the `question/` and `tryout/` contracts, which the change that
73
- switches their readers deletes.
50
+ the exam `profile`, the frozen `paper`, and the `tools` registry. `answer`
51
+ owns the typed-answer keys: every runtime grades a typed answer only through
52
+ `matchesAnswerKey`, reads a typed number only through `readNumberAnswer`, the
53
+ one number grammar, and decides that a typed answer is blank only through
54
+ `isBlankAnswer`. `catalog` owns the try-out navigation rows, each set naming
55
+ its paper, and `snapshot` the `assessment` snapshot family that publishes all
56
+ of it in one signed release.
74
57
  [ADR 0005](https://github.com/nakafaai/aksara/blob/main/docs/adr/assessment.md)
75
58
  records the decisions.
76
59
 
77
60
  ## Publication dates
78
61
 
79
- Article, material, public page, and question metadata carry one required
62
+ Article, material, and public page metadata carry one required
80
63
  `datePublished` and one optional `dateModified`, both as exact `DateOnly`
81
64
  values.
82
65
 
@@ -7,26 +7,26 @@ import type { AppLocaleCode } from "#contracts/locale";
7
7
  * Graders compare it exactly through `matchesAnswerKey`, never through binary
8
8
  * floating point.
9
9
  */
10
- export declare const QuestionDecimalSchema: Schema.String;
11
- export type QuestionDecimal = typeof QuestionDecimalSchema.Type;
10
+ export declare const DecimalSchema: Schema.String;
11
+ export type Decimal = typeof DecimalSchema.Type;
12
12
  /**
13
13
  * Largest accepted distance from the exact value, inclusive. An absolute
14
14
  * tolerance `t` accepts `|answer - value| <= t`. A relative tolerance `r`
15
15
  * accepts `|answer - value| <= r * |value|`, is below one, and needs a nonzero
16
16
  * value.
17
17
  */
18
- export declare const QuestionToleranceSchema: Schema.Struct<{
18
+ export declare const ToleranceSchema: Schema.Struct<{
19
19
  readonly kind: Schema.Literals<readonly ["absolute", "relative"]>;
20
20
  readonly value: Schema.String;
21
21
  }>;
22
- export type QuestionTolerance = typeof QuestionToleranceSchema.Type;
22
+ export type Tolerance = typeof ToleranceSchema.Type;
23
23
  /**
24
24
  * Deterministic numeric answer key. A learner number, read by
25
25
  * `readNumberAnswer` in the delivery language, matches when its exact value
26
26
  * equals `value`, or lies within `tolerance` when present. A fraction such as
27
27
  * `6/8` matches only when `acceptsFractions` is true.
28
28
  */
29
- export declare const QuestionNumberKeySchema: Schema.Struct<{
29
+ export declare const NumberKeySchema: Schema.Struct<{
30
30
  readonly acceptsFractions: Schema.Boolean;
31
31
  readonly kind: Schema.Literal<"number">;
32
32
  readonly tolerance: Schema.optionalKey<Schema.Struct<{
@@ -35,22 +35,22 @@ export declare const QuestionNumberKeySchema: Schema.Struct<{
35
35
  }>>;
36
36
  readonly value: Schema.String;
37
37
  }>;
38
- export type QuestionNumberKey = typeof QuestionNumberKeySchema.Type;
38
+ export type NumberKey = typeof NumberKeySchema.Type;
39
39
  /**
40
40
  * Deterministic text answer key written in the delivery language. A learner
41
41
  * answer matches when it normalizes, under `ignoreCase` and
42
42
  * `collapseWhitespace`, to the same text as one accepted answer. Accepted
43
43
  * answers are plain text, never Markdown, so show them without rich rendering.
44
44
  */
45
- export declare const QuestionTextKeySchema: Schema.Struct<{
45
+ export declare const TextKeySchema: Schema.Struct<{
46
46
  readonly acceptedAnswers: Schema.NonEmptyArray<Schema.Trimmed>;
47
47
  readonly collapseWhitespace: Schema.Boolean;
48
48
  readonly ignoreCase: Schema.Boolean;
49
49
  readonly kind: Schema.Literal<"text">;
50
50
  }>;
51
- export type QuestionTextKey = typeof QuestionTextKeySchema.Type;
52
- /** Deterministic key shared by short answers and rubric final results. */
53
- export declare const QuestionAnswerKeySchema: Schema.Union<readonly [Schema.Struct<{
51
+ export type TextKey = typeof TextKeySchema.Type;
52
+ /** A key that a typed answer is graded against: a number or accepted texts. */
53
+ export declare const AnswerKeySchema: Schema.Union<readonly [Schema.Struct<{
54
54
  readonly acceptsFractions: Schema.Boolean;
55
55
  readonly kind: Schema.Literal<"number">;
56
56
  readonly tolerance: Schema.optionalKey<Schema.Struct<{
@@ -64,18 +64,18 @@ export declare const QuestionAnswerKeySchema: Schema.Union<readonly [Schema.Stru
64
64
  readonly ignoreCase: Schema.Boolean;
65
65
  readonly kind: Schema.Literal<"text">;
66
66
  }>]>;
67
- export type QuestionAnswerKey = typeof QuestionAnswerKeySchema.Type;
67
+ export type AnswerKey = typeof AnswerKeySchema.Type;
68
68
  /**
69
69
  * One learner number read exactly as `numerator / denominator`, with a
70
70
  * positive integer denominator that is one for a typed decimal. `fraction`
71
71
  * records that the learner wrote `p/q`.
72
72
  */
73
- declare const QuestionNumberAnswerSchema: Schema.Struct<{
73
+ declare const NumberAnswerSchema: Schema.Struct<{
74
74
  readonly denominator: Schema.BigDecimal;
75
75
  readonly fraction: Schema.Boolean;
76
76
  readonly numerator: Schema.BigDecimal;
77
77
  }>;
78
- export type QuestionNumberAnswer = typeof QuestionNumberAnswerSchema.Type;
78
+ export type NumberAnswer = typeof NumberAnswerSchema.Type;
79
79
  /**
80
80
  * Checks whether one typed learner answer is blank: nothing remains once it is
81
81
  * read as visible text, so whitespace and invisible format characters alone
@@ -107,49 +107,5 @@ export declare function readNumberAnswer(input: string, language: AppLocaleCode)
107
107
  * language and compares its exact value, so an unreadable or empty answer
108
108
  * never matches.
109
109
  */
110
- export declare function matchesAnswerKey(key: QuestionAnswerKey, answer: string, language: AppLocaleCode): boolean;
111
- /** Returns one answer key in stable field order for signed canonicalizers. */
112
- export declare function canonicalQuestionAnswerKey(key: QuestionAnswerKey): {
113
- acceptedAnswers: [string, ...string[]];
114
- collapseWhitespace: boolean;
115
- ignoreCase: boolean;
116
- kind: "text";
117
- } | {
118
- acceptedAnswers?: never;
119
- collapseWhitespace?: never;
120
- ignoreCase?: never;
121
- acceptsFractions: boolean;
122
- kind: "number";
123
- tolerance?: {
124
- kind: "absolute" | "relative";
125
- value: string;
126
- };
127
- value: string;
128
- };
129
- /**
130
- * Returns the grading rules shared by every delivery language. A numeric key is
131
- * language-neutral and stays whole; text keeps its rules but drops accepted
132
- * answers, which each delivery language writes in its own words.
133
- */
134
- export declare function canonicalQuestionAnswerKeyStructure(key: QuestionAnswerKey): {
135
- acceptedAnswers: [string, ...string[]];
136
- collapseWhitespace: boolean;
137
- ignoreCase: boolean;
138
- kind: "text";
139
- } | {
140
- acceptedAnswers?: never;
141
- collapseWhitespace?: never;
142
- ignoreCase?: never;
143
- acceptsFractions: boolean;
144
- kind: "number";
145
- tolerance?: {
146
- kind: "absolute" | "relative";
147
- value: string;
148
- };
149
- value: string;
150
- } | {
151
- collapseWhitespace: boolean;
152
- ignoreCase: boolean;
153
- kind: "text";
154
- };
110
+ export declare function matchesAnswerKey(key: AnswerKey, answer: string, language: AppLocaleCode): boolean;
155
111
  export {};
@@ -21,9 +21,9 @@ const NUMBER_PATTERNS = {
21
21
  * Graders compare it exactly through `matchesAnswerKey`, never through binary
22
22
  * floating point.
23
23
  */
24
- export const QuestionDecimalSchema = Schema.String.check(Schema.isPattern(DECIMAL_PATTERN, {
24
+ export const DecimalSchema = Schema.String.check(Schema.isPattern(DECIMAL_PATTERN, {
25
25
  description: "Exact decimal written in its canonical dot-separated form.",
26
- identifier: "QuestionDecimal",
26
+ identifier: "AssessmentDecimal",
27
27
  message: "Invalid canonical decimal.",
28
28
  }));
29
29
  /** Checks that one canonical decimal is strictly greater than zero. */
@@ -36,9 +36,9 @@ function isPositiveDecimal(value) {
36
36
  * accepts `|answer - value| <= r * |value|`, is below one, and needs a nonzero
37
37
  * value.
38
38
  */
39
- export const QuestionToleranceSchema = Schema.Struct({
39
+ export const ToleranceSchema = Schema.Struct({
40
40
  kind: Schema.Literals(["absolute", "relative"]),
41
- value: QuestionDecimalSchema.check(Schema.makeFilter(isPositiveDecimal, {
41
+ value: DecimalSchema.check(Schema.makeFilter(isPositiveDecimal, {
42
42
  message: "Expected a positive tolerance.",
43
43
  })),
44
44
  }).check(Schema.makeFilter(({ kind, value }) => kind === "absolute" || value.startsWith("0."), { message: "Expected a relative tolerance below one." }));
@@ -48,11 +48,11 @@ export const QuestionToleranceSchema = Schema.Struct({
48
48
  * equals `value`, or lies within `tolerance` when present. A fraction such as
49
49
  * `6/8` matches only when `acceptsFractions` is true.
50
50
  */
51
- export const QuestionNumberKeySchema = Schema.Struct({
51
+ export const NumberKeySchema = Schema.Struct({
52
52
  acceptsFractions: Schema.Boolean,
53
53
  kind: Schema.Literal("number"),
54
- tolerance: Schema.optionalKey(QuestionToleranceSchema),
55
- value: QuestionDecimalSchema,
54
+ tolerance: Schema.optionalKey(ToleranceSchema),
55
+ value: DecimalSchema,
56
56
  }).check(Schema.makeFilter(({ tolerance, value }) => tolerance?.kind !== "relative" || value !== "0", { message: "A relative tolerance cannot measure distance from zero." }));
57
57
  /**
58
58
  * One accepted answer as a learner types it on one line: trimmed, non-empty,
@@ -60,7 +60,7 @@ export const QuestionNumberKeySchema = Schema.Struct({
60
60
  * control or invisible format character. Each key therefore has one signed
61
61
  * spelling and can be typed into a single-line answer field.
62
62
  */
63
- const QuestionAcceptedTextSchema = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.makeFilter((text) => !UNTYPABLE_CHARACTER_PATTERN.test(text), {
63
+ const AcceptedTextSchema = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.makeFilter((text) => !UNTYPABLE_CHARACTER_PATTERN.test(text), {
64
64
  message: "Expected one typed line whose only whitespace is the ordinary space.",
65
65
  }), Schema.makeFilter((text) => text === text.normalize("NFC"), {
66
66
  message: "Expected NFC text.",
@@ -107,25 +107,22 @@ function hasDistinctAcceptedAnswers(key) {
107
107
  * `collapseWhitespace`, to the same text as one accepted answer. Accepted
108
108
  * answers are plain text, never Markdown, so show them without rich rendering.
109
109
  */
110
- export const QuestionTextKeySchema = Schema.Struct({
111
- acceptedAnswers: Schema.NonEmptyArray(QuestionAcceptedTextSchema),
110
+ export const TextKeySchema = Schema.Struct({
111
+ acceptedAnswers: Schema.NonEmptyArray(AcceptedTextSchema),
112
112
  collapseWhitespace: Schema.Boolean,
113
113
  ignoreCase: Schema.Boolean,
114
114
  kind: Schema.Literal("text"),
115
115
  }).check(Schema.makeFilter(hasDistinctAcceptedAnswers, {
116
116
  message: "Accepted answers must stay distinct after normalization.",
117
117
  }));
118
- /** Deterministic key shared by short answers and rubric final results. */
119
- export const QuestionAnswerKeySchema = Schema.Union([
120
- QuestionNumberKeySchema,
121
- QuestionTextKeySchema,
122
- ]);
118
+ /** A key that a typed answer is graded against: a number or accepted texts. */
119
+ export const AnswerKeySchema = Schema.Union([NumberKeySchema, TextKeySchema]);
123
120
  /**
124
121
  * One learner number read exactly as `numerator / denominator`, with a
125
122
  * positive integer denominator that is one for a typed decimal. `fraction`
126
123
  * records that the learner wrote `p/q`.
127
124
  */
128
- const QuestionNumberAnswerSchema = Schema.Struct({
125
+ const NumberAnswerSchema = Schema.Struct({
129
126
  denominator: Schema.BigDecimal,
130
127
  fraction: Schema.Boolean,
131
128
  numerator: Schema.BigDecimal,
@@ -217,47 +214,3 @@ export function matchesAnswerKey(key, answer, language) {
217
214
  }
218
215
  return Option.exists(readNumberAnswer(answer, language), (number) => matchesNumberKey(key, number));
219
216
  }
220
- /** Copies accepted answers while keeping their non-empty tuple type. */
221
- function canonicalAcceptedAnswers(answers) {
222
- const [first, ...rest] = answers;
223
- return [first, ...rest];
224
- }
225
- /** Returns one answer key in stable field order for signed canonicalizers. */
226
- export function canonicalQuestionAnswerKey(key) {
227
- if (key.kind === "text") {
228
- return {
229
- acceptedAnswers: canonicalAcceptedAnswers(key.acceptedAnswers),
230
- collapseWhitespace: key.collapseWhitespace,
231
- ignoreCase: key.ignoreCase,
232
- kind: key.kind,
233
- };
234
- }
235
- return {
236
- acceptsFractions: key.acceptsFractions,
237
- kind: key.kind,
238
- ...(key.tolerance === undefined
239
- ? {}
240
- : {
241
- tolerance: {
242
- kind: key.tolerance.kind,
243
- value: key.tolerance.value,
244
- },
245
- }),
246
- value: key.value,
247
- };
248
- }
249
- /**
250
- * Returns the grading rules shared by every delivery language. A numeric key is
251
- * language-neutral and stays whole; text keeps its rules but drops accepted
252
- * answers, which each delivery language writes in its own words.
253
- */
254
- export function canonicalQuestionAnswerKeyStructure(key) {
255
- if (key.kind === "text") {
256
- return {
257
- collapseWhitespace: key.collapseWhitespace,
258
- ignoreCase: key.ignoreCase,
259
- kind: key.kind,
260
- };
261
- }
262
- return canonicalQuestionAnswerKey(key);
263
- }
@@ -0,0 +1,235 @@
1
+ import { Schema } from "effect";
2
+ /** Bounded authored revision shared by one catalog source hierarchy. */
3
+ export declare const CatalogRevisionSchema: Schema.Trimmed;
4
+ /**
5
+ * Navigation role of one track: one exam `year`, one `subject`, or the sets of
6
+ * one `institution`, such as a Studienkolleg.
7
+ */
8
+ export declare const TrackKindSchema: Schema.Literals<readonly ["institution", "subject", "year"]>;
9
+ /**
10
+ * Public route behavior of one section: `visible` sections have a page of
11
+ * their own, and an `internal-entry` section is entered from its set.
12
+ */
13
+ export declare const SectionVisibilitySchema: Schema.Literals<readonly ["internal-entry", "visible"]>;
14
+ /** One localized country of the catalog. */
15
+ export declare const CatalogCountrySchema: Schema.Struct<{
16
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
17
+ readonly description: Schema.optionalKey<Schema.String>;
18
+ readonly graph: Schema.Struct<{
19
+ readonly alignmentId: Schema.String;
20
+ readonly assetId: Schema.String;
21
+ readonly conceptId: Schema.String;
22
+ readonly learningObjectId: Schema.String;
23
+ readonly lensId: Schema.String;
24
+ }>;
25
+ readonly sourceRevision: Schema.Trimmed;
26
+ readonly title: Schema.String;
27
+ readonly countryKey: Schema.String;
28
+ readonly countryCode: Schema.String;
29
+ readonly kind: Schema.Literal<"country">;
30
+ readonly order: Schema.Int;
31
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
32
+ }>;
33
+ /** One localized exam of a country. */
34
+ export declare const CatalogExamSchema: Schema.Struct<{
35
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
36
+ readonly description: Schema.optionalKey<Schema.String>;
37
+ readonly graph: Schema.Struct<{
38
+ readonly alignmentId: Schema.String;
39
+ readonly assetId: Schema.String;
40
+ readonly conceptId: Schema.String;
41
+ readonly learningObjectId: Schema.String;
42
+ readonly lensId: Schema.String;
43
+ }>;
44
+ readonly sourceRevision: Schema.Trimmed;
45
+ readonly title: Schema.String;
46
+ readonly countryKey: Schema.String;
47
+ readonly examKey: Schema.String;
48
+ readonly kind: Schema.Literal<"exam">;
49
+ readonly order: Schema.Int;
50
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
51
+ }>;
52
+ /** One localized track of an exam: a year, a subject, or an institution. */
53
+ export declare const CatalogTrackSchema: Schema.Struct<{
54
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
55
+ readonly description: Schema.optionalKey<Schema.String>;
56
+ readonly graph: Schema.Struct<{
57
+ readonly alignmentId: Schema.String;
58
+ readonly assetId: Schema.String;
59
+ readonly conceptId: Schema.String;
60
+ readonly learningObjectId: Schema.String;
61
+ readonly lensId: Schema.String;
62
+ }>;
63
+ readonly sourceRevision: Schema.Trimmed;
64
+ readonly title: Schema.String;
65
+ readonly countryKey: Schema.String;
66
+ readonly examKey: Schema.String;
67
+ readonly trackKey: Schema.String;
68
+ readonly kind: Schema.Literal<"track">;
69
+ readonly order: Schema.Int;
70
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
71
+ readonly trackKind: Schema.Literals<readonly ["institution", "subject", "year"]>;
72
+ }>;
73
+ /**
74
+ * One localized set of a track, and the paper a learner sits for it, by
75
+ * identifier and hash. A set whose only section is entered from the set names
76
+ * that section.
77
+ */
78
+ export declare const CatalogSetSchema: Schema.Struct<{
79
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
80
+ readonly description: Schema.optionalKey<Schema.String>;
81
+ readonly graph: Schema.Struct<{
82
+ readonly alignmentId: Schema.String;
83
+ readonly assetId: Schema.String;
84
+ readonly conceptId: Schema.String;
85
+ readonly learningObjectId: Schema.String;
86
+ readonly lensId: Schema.String;
87
+ }>;
88
+ readonly sourceRevision: Schema.Trimmed;
89
+ readonly title: Schema.String;
90
+ readonly countryKey: Schema.String;
91
+ readonly examKey: Schema.String;
92
+ readonly trackKey: Schema.String;
93
+ readonly setKey: Schema.String;
94
+ readonly internalEntrySectionKey: Schema.optionalKey<Schema.String>;
95
+ readonly kind: Schema.Literal<"set">;
96
+ readonly order: Schema.Int;
97
+ readonly paper: Schema.Struct<{
98
+ readonly hash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
99
+ readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraPaperId">;
100
+ }>;
101
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
102
+ }>;
103
+ /**
104
+ * One localized section of a set. Its key is the identifier of a section of
105
+ * the exam profile that the set's paper follows, so the profile owns its time,
106
+ * its items, and its scoring, and the paper owns its places.
107
+ */
108
+ export declare const CatalogSectionSchema: Schema.Struct<{
109
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
110
+ readonly description: Schema.optionalKey<Schema.String>;
111
+ readonly graph: Schema.Struct<{
112
+ readonly alignmentId: Schema.String;
113
+ readonly assetId: Schema.String;
114
+ readonly conceptId: Schema.String;
115
+ readonly learningObjectId: Schema.String;
116
+ readonly lensId: Schema.String;
117
+ }>;
118
+ readonly sourceRevision: Schema.Trimmed;
119
+ readonly title: Schema.String;
120
+ readonly countryKey: Schema.String;
121
+ readonly examKey: Schema.String;
122
+ readonly trackKey: Schema.String;
123
+ readonly setKey: Schema.String;
124
+ readonly kind: Schema.Literal<"section">;
125
+ readonly order: Schema.Int;
126
+ readonly publicPath: Schema.optionalKey<Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">>;
127
+ readonly sectionKey: Schema.String;
128
+ readonly visibility: Schema.Literals<readonly ["internal-entry", "visible"]>;
129
+ }>;
130
+ /** One row of the catalog, the navigation of the public try-outs. */
131
+ export declare const CatalogRowSchema: Schema.Union<readonly [Schema.Struct<{
132
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
133
+ readonly description: Schema.optionalKey<Schema.String>;
134
+ readonly graph: Schema.Struct<{
135
+ readonly alignmentId: Schema.String;
136
+ readonly assetId: Schema.String;
137
+ readonly conceptId: Schema.String;
138
+ readonly learningObjectId: Schema.String;
139
+ readonly lensId: Schema.String;
140
+ }>;
141
+ readonly sourceRevision: Schema.Trimmed;
142
+ readonly title: Schema.String;
143
+ readonly countryKey: Schema.String;
144
+ readonly countryCode: Schema.String;
145
+ readonly kind: Schema.Literal<"country">;
146
+ readonly order: Schema.Int;
147
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
148
+ }>, Schema.Struct<{
149
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
150
+ readonly description: Schema.optionalKey<Schema.String>;
151
+ readonly graph: Schema.Struct<{
152
+ readonly alignmentId: Schema.String;
153
+ readonly assetId: Schema.String;
154
+ readonly conceptId: Schema.String;
155
+ readonly learningObjectId: Schema.String;
156
+ readonly lensId: Schema.String;
157
+ }>;
158
+ readonly sourceRevision: Schema.Trimmed;
159
+ readonly title: Schema.String;
160
+ readonly countryKey: Schema.String;
161
+ readonly examKey: Schema.String;
162
+ readonly kind: Schema.Literal<"exam">;
163
+ readonly order: Schema.Int;
164
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
165
+ }>, Schema.Struct<{
166
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
167
+ readonly description: Schema.optionalKey<Schema.String>;
168
+ readonly graph: Schema.Struct<{
169
+ readonly alignmentId: Schema.String;
170
+ readonly assetId: Schema.String;
171
+ readonly conceptId: Schema.String;
172
+ readonly learningObjectId: Schema.String;
173
+ readonly lensId: Schema.String;
174
+ }>;
175
+ readonly sourceRevision: Schema.Trimmed;
176
+ readonly title: Schema.String;
177
+ readonly countryKey: Schema.String;
178
+ readonly examKey: Schema.String;
179
+ readonly trackKey: Schema.String;
180
+ readonly kind: Schema.Literal<"track">;
181
+ readonly order: Schema.Int;
182
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
183
+ readonly trackKind: Schema.Literals<readonly ["institution", "subject", "year"]>;
184
+ }>, Schema.Struct<{
185
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
186
+ readonly description: Schema.optionalKey<Schema.String>;
187
+ readonly graph: Schema.Struct<{
188
+ readonly alignmentId: Schema.String;
189
+ readonly assetId: Schema.String;
190
+ readonly conceptId: Schema.String;
191
+ readonly learningObjectId: Schema.String;
192
+ readonly lensId: Schema.String;
193
+ }>;
194
+ readonly sourceRevision: Schema.Trimmed;
195
+ readonly title: Schema.String;
196
+ readonly countryKey: Schema.String;
197
+ readonly examKey: Schema.String;
198
+ readonly trackKey: Schema.String;
199
+ readonly setKey: Schema.String;
200
+ readonly internalEntrySectionKey: Schema.optionalKey<Schema.String>;
201
+ readonly kind: Schema.Literal<"set">;
202
+ readonly order: Schema.Int;
203
+ readonly paper: Schema.Struct<{
204
+ readonly hash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
205
+ readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraPaperId">;
206
+ }>;
207
+ readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
208
+ }>, Schema.Struct<{
209
+ readonly appLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraAppLocale">;
210
+ readonly description: Schema.optionalKey<Schema.String>;
211
+ readonly graph: Schema.Struct<{
212
+ readonly alignmentId: Schema.String;
213
+ readonly assetId: Schema.String;
214
+ readonly conceptId: Schema.String;
215
+ readonly learningObjectId: Schema.String;
216
+ readonly lensId: Schema.String;
217
+ }>;
218
+ readonly sourceRevision: Schema.Trimmed;
219
+ readonly title: Schema.String;
220
+ readonly countryKey: Schema.String;
221
+ readonly examKey: Schema.String;
222
+ readonly trackKey: Schema.String;
223
+ readonly setKey: Schema.String;
224
+ readonly kind: Schema.Literal<"section">;
225
+ readonly order: Schema.Int;
226
+ readonly publicPath: Schema.optionalKey<Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">>;
227
+ readonly sectionKey: Schema.String;
228
+ readonly visibility: Schema.Literals<readonly ["internal-entry", "visible"]>;
229
+ }>]>;
230
+ export type CatalogRow = typeof CatalogRowSchema.Type;
231
+ /**
232
+ * The identity of one catalog row, unique within a snapshot: its locale, its
233
+ * kind, and the keys of its node and of every node above it.
234
+ */
235
+ export declare function catalogRowIdentity(row: CatalogRow): string;
@@ -0,0 +1,115 @@
1
+ import { Array as Arr, Schema } from "effect";
2
+ import { KebabKeySchema, PaperIdSchema } from "#contracts/assessment/identity";
3
+ import { CountryCodeSchema } from "#contracts/country";
4
+ import { LearningGraphIdentitySchema } from "#contracts/graph/spec";
5
+ import { PublicPathSchema, Sha256HashSchema } from "#contracts/ids";
6
+ import { AppLocaleSchema } from "#contracts/locale";
7
+ const PositiveCountSchema = Schema.Int.check(Schema.isGreaterThan(0));
8
+ /** Bounded authored revision shared by one catalog source hierarchy. */
9
+ export const CatalogRevisionSchema = Schema.Trimmed.check(Schema.isNonEmpty(), Schema.isMaxLength(128));
10
+ /**
11
+ * Navigation role of one track: one exam `year`, one `subject`, or the sets of
12
+ * one `institution`, such as a Studienkolleg.
13
+ */
14
+ export const TrackKindSchema = Schema.Literals([
15
+ "institution",
16
+ "subject",
17
+ "year",
18
+ ]);
19
+ /**
20
+ * Public route behavior of one section: `visible` sections have a page of
21
+ * their own, and an `internal-entry` section is entered from its set.
22
+ */
23
+ export const SectionVisibilitySchema = Schema.Literals([
24
+ "internal-entry",
25
+ "visible",
26
+ ]);
27
+ /** What every row of the catalog says in one app locale. */
28
+ const LocalizedFields = {
29
+ appLocale: AppLocaleSchema,
30
+ description: Schema.optionalKey(Schema.String),
31
+ graph: LearningGraphIdentitySchema,
32
+ sourceRevision: CatalogRevisionSchema,
33
+ title: Schema.String,
34
+ };
35
+ const CountryFields = { countryKey: KebabKeySchema };
36
+ const ExamFields = { ...CountryFields, examKey: KebabKeySchema };
37
+ const TrackFields = { ...ExamFields, trackKey: KebabKeySchema };
38
+ const SetFields = { ...TrackFields, setKey: KebabKeySchema };
39
+ /** One localized country of the catalog. */
40
+ export const CatalogCountrySchema = Schema.Struct({
41
+ ...LocalizedFields,
42
+ ...CountryFields,
43
+ countryCode: CountryCodeSchema,
44
+ kind: Schema.Literal("country"),
45
+ order: PositiveCountSchema,
46
+ publicPath: PublicPathSchema,
47
+ });
48
+ /** One localized exam of a country. */
49
+ export const CatalogExamSchema = Schema.Struct({
50
+ ...LocalizedFields,
51
+ ...ExamFields,
52
+ kind: Schema.Literal("exam"),
53
+ order: PositiveCountSchema,
54
+ publicPath: PublicPathSchema,
55
+ });
56
+ /** One localized track of an exam: a year, a subject, or an institution. */
57
+ export const CatalogTrackSchema = Schema.Struct({
58
+ ...LocalizedFields,
59
+ ...TrackFields,
60
+ kind: Schema.Literal("track"),
61
+ order: PositiveCountSchema,
62
+ publicPath: PublicPathSchema,
63
+ trackKind: TrackKindSchema,
64
+ });
65
+ /**
66
+ * One localized set of a track, and the paper a learner sits for it, by
67
+ * identifier and hash. A set whose only section is entered from the set names
68
+ * that section.
69
+ */
70
+ export const CatalogSetSchema = Schema.Struct({
71
+ ...LocalizedFields,
72
+ ...SetFields,
73
+ internalEntrySectionKey: Schema.optionalKey(KebabKeySchema),
74
+ kind: Schema.Literal("set"),
75
+ order: PositiveCountSchema,
76
+ paper: Schema.Struct({ hash: Sha256HashSchema, id: PaperIdSchema }),
77
+ publicPath: PublicPathSchema,
78
+ });
79
+ /**
80
+ * One localized section of a set. Its key is the identifier of a section of
81
+ * the exam profile that the set's paper follows, so the profile owns its time,
82
+ * its items, and its scoring, and the paper owns its places.
83
+ */
84
+ export const CatalogSectionSchema = Schema.Struct({
85
+ ...LocalizedFields,
86
+ ...SetFields,
87
+ kind: Schema.Literal("section"),
88
+ order: PositiveCountSchema,
89
+ publicPath: Schema.optionalKey(PublicPathSchema),
90
+ sectionKey: KebabKeySchema,
91
+ visibility: SectionVisibilitySchema,
92
+ }).check(Schema.makeFilter(({ publicPath, visibility }) => (visibility === "visible") === (publicPath !== undefined), { message: "Expected a public path on a visible section only." }));
93
+ /** One row of the catalog, the navigation of the public try-outs. */
94
+ export const CatalogRowSchema = Schema.Union([
95
+ CatalogCountrySchema,
96
+ CatalogExamSchema,
97
+ CatalogTrackSchema,
98
+ CatalogSetSchema,
99
+ CatalogSectionSchema,
100
+ ]);
101
+ /**
102
+ * The identity of one catalog row, unique within a snapshot: its locale, its
103
+ * kind, and the keys of its node and of every node above it.
104
+ */
105
+ export function catalogRowIdentity(row) {
106
+ return Arr.join([
107
+ row.appLocale,
108
+ row.kind,
109
+ row.countryKey,
110
+ "examKey" in row ? row.examKey : "",
111
+ "trackKey" in row ? row.trackKey : "",
112
+ "setKey" in row ? row.setKey : "",
113
+ "sectionKey" in row ? row.sectionKey : "",
114
+ ], "\0");
115
+ }