@nakafa/aksara-contracts 0.43.0 → 0.45.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 (77) hide show
  1. package/README.md +22 -1
  2. package/dist/math/resolution.js +1 -1
  3. package/dist/math/scene.js +1 -1
  4. package/dist/preview/artifact.d.ts +44 -0
  5. package/dist/preview/document.d.ts +36 -12
  6. package/dist/preview/spec.d.ts +196 -36
  7. package/dist/preview/target.d.ts +10 -3
  8. package/dist/program/snapshot/digest.d.ts +1 -1
  9. package/dist/program/snapshot/digest.js +1 -1
  10. package/dist/program/snapshot/hash.d.ts +153 -0
  11. package/dist/program/snapshot/hash.js +31 -0
  12. package/dist/projection/digest.d.ts +74 -22
  13. package/dist/projection/material.d.ts +10 -0
  14. package/dist/projection/material.js +15 -0
  15. package/dist/projection/question.d.ts +188 -0
  16. package/dist/projection/spec.d.ts +45 -0
  17. package/dist/projection/verify.d.ts +127 -75
  18. package/dist/question/answer.d.ts +149 -0
  19. package/dist/question/answer.js +248 -0
  20. package/dist/question/item.d.ts +276 -1
  21. package/dist/question/item.js +63 -38
  22. package/dist/question/label.d.ts +3 -0
  23. package/dist/question/label.js +3 -0
  24. package/dist/question/points.d.ts +18 -0
  25. package/dist/question/points.js +22 -0
  26. package/dist/question/response.d.ts +187 -5
  27. package/dist/question/response.js +41 -4
  28. package/dist/question/rubric.d.ts +234 -0
  29. package/dist/question/rubric.js +182 -0
  30. package/dist/release/rollback/spec.d.ts +264 -0
  31. package/dist/release/snapshot/data.d.ts +52 -3
  32. package/dist/release/snapshot/{program-evidence.d.ts → evidence/program.d.ts} +2 -2
  33. package/dist/release/snapshot/{program-evidence.js → evidence/program.js} +1 -1
  34. package/dist/release/snapshot/{quran-evidence.d.ts → evidence/quran.d.ts} +2 -2
  35. package/dist/release/snapshot/{quran-evidence.js → evidence/quran.js} +1 -1
  36. package/dist/release/snapshot/{tryout-evidence.d.ts → evidence/tryout.d.ts} +2 -2
  37. package/dist/release/snapshot/{tryout-evidence.js → evidence/tryout.js} +4 -4
  38. package/dist/release/snapshot/evidence.d.ts +2 -2
  39. package/dist/release/snapshot/evidence.js +3 -3
  40. package/dist/release/snapshot/verify.d.ts +88 -31
  41. package/dist/runtime/spec.d.ts +25 -22
  42. package/dist/runtime/verify.d.ts +46 -44
  43. package/dist/transport/batch.d.ts +88 -0
  44. package/dist/transport/group.d.ts +288 -9
  45. package/dist/transport/request.d.ts +1858 -1018
  46. package/dist/transport/response.d.ts +499 -131
  47. package/dist/transport/snapshot.d.ts +104 -6
  48. package/dist/tryout/catalog.d.ts +28 -10
  49. package/dist/tryout/catalog.js +6 -2
  50. package/dist/tryout/closure/accounting.d.ts +16 -0
  51. package/dist/tryout/closure/accounting.js +68 -0
  52. package/dist/tryout/closure/locale.d.ts +14 -0
  53. package/dist/tryout/{locale-closure.js → closure/locale.js} +13 -72
  54. package/dist/tryout/{placement-closure.js → closure/placement.js} +1 -0
  55. package/dist/tryout/{catalog-hash.d.ts → hash/catalog.d.ts} +25 -20
  56. package/dist/tryout/{catalog-hash.js → hash/catalog.js} +8 -1
  57. package/dist/tryout/{content-hash.d.ts → hash/content.d.ts} +43 -0
  58. package/dist/tryout/{placement-hash.d.ts → hash/placement.d.ts} +1 -1
  59. package/dist/tryout/{placement-hash.js → hash/placement.js} +2 -1
  60. package/dist/tryout/placement.d.ts +136 -1
  61. package/dist/tryout/placement.js +16 -2
  62. package/dist/tryout/scoring.d.ts +37 -0
  63. package/dist/tryout/scoring.js +89 -0
  64. package/dist/tryout/spec.d.ts +32 -4
  65. package/dist/tryout/spec.js +35 -4
  66. package/package.json +28 -20
  67. package/dist/program/snapshot/row-hash.d.ts +0 -155
  68. package/dist/program/snapshot/row-hash.js +0 -34
  69. package/dist/tryout/locale-closure.d.ts +0 -20
  70. /package/dist/math/{arc-precision.d.ts → arc.d.ts} +0 -0
  71. /package/dist/math/{arc-precision.js → arc.js} +0 -0
  72. /package/dist/release/snapshot/{evidence-requirement.d.ts → evidence/requirement.d.ts} +0 -0
  73. /package/dist/release/snapshot/{evidence-requirement.js → evidence/requirement.js} +0 -0
  74. /package/dist/tryout/{placement-closure.d.ts → closure/placement.d.ts} +0 -0
  75. /package/dist/tryout/{row-hash.d.ts → digest.d.ts} +0 -0
  76. /package/dist/tryout/{row-hash.js → digest.js} +0 -0
  77. /package/dist/tryout/{content-hash.js → hash/content.js} +0 -0
@@ -1,6 +1,10 @@
1
1
  import { Effect, Schema, Struct } from "effect";
2
2
  import { AppLocaleCodeSchema, ArtifactLocaleSchema, artifactLocaleCode, } from "#contracts/locale";
3
- import { QuestionResponseLabelSchema, QuestionResponseSchema, } from "#contracts/question/response";
3
+ import { QuestionAnswerKeySchema } from "#contracts/question/answer";
4
+ import { QuestionResponseLabelSchema } from "#contracts/question/label";
5
+ import { AuthoredQuestionPointsSchema } from "#contracts/question/points";
6
+ import { canonicalQuestionResponseStructure, QuestionResponseSchema, } from "#contracts/question/response";
7
+ import { freezeQuestionRubric, QuestionRubricResponseSourceSchema, } from "#contracts/question/rubric";
4
8
  import { TryoutKeySchema } from "#contracts/tryout/key";
5
9
  const PositiveOrderSchema = Schema.Int.pipe(Schema.check(Schema.isGreaterThan(0)));
6
10
  /** One source-authored option before stable runtime identities are derived. */
@@ -55,10 +59,17 @@ const CategoryResponseSourceSchema = Schema.Struct({
55
59
  .pipe(Schema.check(Schema.makeFilter(hasCoherentCategoryResponse, {
56
60
  message: "Category responses require at least two categories and classified statements.",
57
61
  })));
62
+ /** One typed answer authored exactly as it is frozen and graded. */
63
+ const ShortAnswerResponseSourceSchema = Schema.Struct({
64
+ key: QuestionAnswerKeySchema,
65
+ kind: Schema.Literal("short-answer"),
66
+ }).mapFields(Struct.map(Schema.mutableKey));
58
67
  /** One locale-specific response authored without duplicated runtime keys. */
59
68
  export const QuestionResponseSourceSchema = Schema.Union([
60
69
  CategoryResponseSourceSchema,
61
70
  MultipleChoiceResponseSourceSchema,
71
+ QuestionRubricResponseSourceSchema,
72
+ ShortAnswerResponseSourceSchema,
62
73
  SingleChoiceResponseSourceSchema,
63
74
  ]);
64
75
  const QuestionResponseSourceMapSchema = Schema.Record(AppLocaleCodeSchema, Schema.optional(QuestionResponseSourceSchema));
@@ -68,20 +79,51 @@ export const QuestionBlueprintSchema = Schema.Struct({
68
79
  contentDomain: TryoutKeySchema,
69
80
  topic: TryoutKeySchema,
70
81
  });
71
- /** Serializes response shape and answer-key positions for locale comparison. */
72
- function responseStructure(response) {
82
+ /** Derives stable option keys and orders from source-authored array order. */
83
+ function freezeOptions(options) {
84
+ return options.map(({ isCorrect, label }, index) => ({
85
+ isCorrect,
86
+ label,
87
+ optionKey: `option-${index + 1}`,
88
+ order: index + 1,
89
+ }));
90
+ }
91
+ /** Freezes one authored response, deriving every stable runtime key once. */
92
+ function freezeQuestionResponse(response) {
93
+ if (response.kind === "rubric") {
94
+ return freezeQuestionRubric(response);
95
+ }
96
+ if (response.kind === "short-answer") {
97
+ return QuestionResponseSchema.make({
98
+ key: response.key,
99
+ kind: response.kind,
100
+ });
101
+ }
73
102
  if (response.kind === "category") {
74
- return JSON.stringify({
75
- categories: response.categories.length,
103
+ return QuestionResponseSchema.make({
104
+ categories: response.categories.map((label, index) => ({
105
+ categoryKey: `category-${index + 1}`,
106
+ label,
107
+ order: index + 1,
108
+ })),
76
109
  kind: response.kind,
77
- statements: response.statements.map(({ correctCategoryOrder }) => correctCategoryOrder),
110
+ statements: response.statements.map(({ correctCategoryOrder, label }, index) => ({
111
+ correctCategoryKey: `category-${correctCategoryOrder}`,
112
+ label,
113
+ order: index + 1,
114
+ statementKey: `statement-${index + 1}`,
115
+ })),
78
116
  });
79
117
  }
80
- return JSON.stringify({
81
- correctness: response.options.map(({ isCorrect }) => isCorrect),
118
+ return QuestionResponseSchema.make({
82
119
  kind: response.kind,
120
+ options: freezeOptions(response.options),
83
121
  });
84
122
  }
123
+ /** Serializes response shape and answer key for locale comparison. */
124
+ function responseStructure(response) {
125
+ return JSON.stringify(canonicalQuestionResponseStructure(freezeQuestionResponse(response)));
126
+ }
85
127
  /** Requires locale siblings to preserve one response format and answer key. */
86
128
  function hasCoherentLocalizedResponses(input) {
87
129
  const responses = Object.values(input.responses).filter((response) => response !== undefined);
@@ -89,13 +131,24 @@ function hasCoherentLocalizedResponses(input) {
89
131
  return (first !== undefined &&
90
132
  responses.every((response) => responseStructure(response) === responseStructure(first)));
91
133
  }
92
- /** Complete source-owned item, including optional shared-stimulus identity. */
134
+ /** Requires a rubric item to take its worth from the rubric total alone. */
135
+ function hasCoherentPoints(input) {
136
+ return (input.points === undefined ||
137
+ Object.values(input.responses).every((response) => response?.kind !== "rubric"));
138
+ }
139
+ /**
140
+ * Complete source-owned item with optional shared-stimulus identity and points.
141
+ * Points appear only above the default single point and never on a rubric.
142
+ */
93
143
  export const QuestionItemSchema = Schema.Struct({
94
144
  blueprint: Schema.optionalKey(QuestionBlueprintSchema),
145
+ points: Schema.optionalKey(AuthoredQuestionPointsSchema),
95
146
  responses: QuestionResponseSourceMapSchema,
96
147
  stimulusKey: Schema.optionalKey(TryoutKeySchema),
97
148
  }).pipe(Schema.check(Schema.makeFilter(hasCoherentLocalizedResponses, {
98
149
  message: "Localized responses must preserve one format, structure, and answer key.",
150
+ })), Schema.check(Schema.makeFilter(hasCoherentPoints, {
151
+ message: "Rubric items derive their points from the rubric total.",
99
152
  })));
100
153
  /** Returns blueprint facts in stable field order for signed canonicalizers. */
101
154
  export function canonicalQuestionBlueprint(blueprint) {
@@ -108,39 +161,11 @@ export function canonicalQuestionBlueprint(blueprint) {
108
161
  /** One item does not contain the exact artifact locale it must assess. */
109
162
  export class QuestionResponseLocaleMissingError extends Schema.TaggedError()("QuestionResponseLocaleMissingError", { artifactLocale: ArtifactLocaleSchema }) {
110
163
  }
111
- /** Derives stable option keys and orders from source-authored array order. */
112
- function freezeOptions(options) {
113
- return options.map(({ isCorrect, label }, index) => ({
114
- isCorrect,
115
- label,
116
- optionKey: `option-${index + 1}`,
117
- order: index + 1,
118
- }));
119
- }
120
164
  /** Resolves and freezes one exact-locale response from an authored item. */
121
165
  export const questionResponseFor = Effect.fn("AksaraContracts.questionResponseFor")(function* (item, artifactLocale) {
122
166
  const response = item.responses[artifactLocaleCode(artifactLocale)];
123
167
  if (response === undefined) {
124
168
  return yield* new QuestionResponseLocaleMissingError({ artifactLocale });
125
169
  }
126
- if (response.kind !== "category") {
127
- return QuestionResponseSchema.make({
128
- kind: response.kind,
129
- options: freezeOptions(response.options),
130
- });
131
- }
132
- return QuestionResponseSchema.make({
133
- categories: response.categories.map((label, index) => ({
134
- categoryKey: `category-${index + 1}`,
135
- label,
136
- order: index + 1,
137
- })),
138
- kind: response.kind,
139
- statements: response.statements.map(({ correctCategoryOrder, label }, index) => ({
140
- correctCategoryKey: `category-${correctCategoryOrder}`,
141
- label,
142
- order: index + 1,
143
- statementKey: `statement-${index + 1}`,
144
- })),
145
- });
170
+ return freezeQuestionResponse(response);
146
171
  });
@@ -0,0 +1,3 @@
1
+ import { Schema } from "effect";
2
+ /** One non-empty Markdown label rendered by the product-owned content surface. */
3
+ export declare const QuestionResponseLabelSchema: Schema.String;
@@ -0,0 +1,3 @@
1
+ import { Schema } from "effect";
2
+ /** One non-empty Markdown label rendered by the product-owned content surface. */
3
+ export const QuestionResponseLabelSchema = Schema.String.check(Schema.isNonEmpty());
@@ -0,0 +1,18 @@
1
+ import { Schema } from "effect";
2
+ import type { QuestionResponse } from "#contracts/question/response";
3
+ /** Whole points one scored question is worth. */
4
+ export declare const QuestionPointsSchema: Schema.Int;
5
+ /**
6
+ * Points written only when a question is worth more than the default single
7
+ * point, so every placement keeps one canonical encoding of its worth.
8
+ */
9
+ export declare const AuthoredQuestionPointsSchema: Schema.Int;
10
+ /**
11
+ * Returns the points one placed question is worth. Every scoring strategy
12
+ * reads worth through this function: a rubric is worth its derived total, and
13
+ * any other response is worth its authored points or the default single point.
14
+ */
15
+ export declare function questionPoints(question: {
16
+ readonly points?: number;
17
+ readonly response: QuestionResponse;
18
+ }): number;
@@ -0,0 +1,22 @@
1
+ import { Schema } from "effect";
2
+ import { questionRubricPoints } from "#contracts/question/rubric";
3
+ /** Whole points one scored question is worth. */
4
+ export const QuestionPointsSchema = Schema.Int.check(Schema.isGreaterThan(0));
5
+ /**
6
+ * Points written only when a question is worth more than the default single
7
+ * point, so every placement keeps one canonical encoding of its worth.
8
+ */
9
+ export const AuthoredQuestionPointsSchema = QuestionPointsSchema.check(Schema.isGreaterThan(1, {
10
+ message: "Omit points to use the default of one point.",
11
+ }));
12
+ /**
13
+ * Returns the points one placed question is worth. Every scoring strategy
14
+ * reads worth through this function: a rubric is worth its derived total, and
15
+ * any other response is worth its authored points or the default single point.
16
+ */
17
+ export function questionPoints(question) {
18
+ if (question.response.kind === "rubric") {
19
+ return questionRubricPoints(question.response);
20
+ }
21
+ return question.points ?? 1;
22
+ }
@@ -1,9 +1,11 @@
1
1
  import { Schema } from "effect";
2
- /** Response formats supported by one assessment item. */
3
- export declare const QuestionResponseKindSchema: Schema.Literals<readonly ["category", "multiple-choice", "single-choice"]>;
2
+ /**
3
+ * Response formats supported by one assessment item. `short-answer` grades one
4
+ * typed number or text deterministically, and `rubric` scores an open response
5
+ * per criterion.
6
+ */
7
+ export declare const QuestionResponseKindSchema: Schema.Literals<readonly ["category", "multiple-choice", "rubric", "short-answer", "single-choice"]>;
4
8
  export type QuestionResponseKind = typeof QuestionResponseKindSchema.Type;
5
- /** One non-empty Markdown label rendered by the product-owned content surface. */
6
- export declare const QuestionResponseLabelSchema: Schema.String;
7
9
  /** Frozen locale-specific response used from publication through review. */
8
10
  export declare const QuestionResponseSchema: Schema.Union<readonly [Schema.Struct<{
9
11
  readonly categories: Schema.$Array<Schema.Struct<{
@@ -26,6 +28,49 @@ export declare const QuestionResponseSchema: Schema.Union<readonly [Schema.Struc
26
28
  readonly optionKey: Schema.String;
27
29
  readonly order: Schema.Int;
28
30
  }>>;
31
+ }>, Schema.Struct<{
32
+ readonly criteria: Schema.$Array<Schema.Struct<{
33
+ readonly criterionKey: Schema.String;
34
+ readonly finalAnswer: Schema.optionalKey<Schema.Union<readonly [Schema.Struct<{
35
+ readonly acceptsFractions: Schema.Boolean;
36
+ readonly kind: Schema.Literal<"number">;
37
+ readonly tolerance: Schema.optionalKey<Schema.Struct<{
38
+ readonly kind: Schema.Literals<readonly ["absolute", "relative"]>;
39
+ readonly value: Schema.String;
40
+ }>>;
41
+ readonly value: Schema.String;
42
+ }>, Schema.Struct<{
43
+ readonly acceptedAnswers: Schema.NonEmptyArray<Schema.Trimmed>;
44
+ readonly collapseWhitespace: Schema.Boolean;
45
+ readonly ignoreCase: Schema.Boolean;
46
+ readonly kind: Schema.Literal<"text">;
47
+ }>]>>;
48
+ readonly order: Schema.Int;
49
+ readonly label: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.String>;
50
+ readonly levels: Schema.$Array<Schema.Struct<{
51
+ readonly levelKey: Schema.String;
52
+ readonly order: Schema.Int;
53
+ readonly points: Schema.Int;
54
+ readonly label: Schema.$Record<Schema.Literals<readonly ["en", "id", "de"]>, Schema.String>;
55
+ }>>;
56
+ }>>;
57
+ readonly kind: Schema.Literal<"rubric">;
58
+ }>, Schema.Struct<{
59
+ readonly key: Schema.Union<readonly [Schema.Struct<{
60
+ readonly acceptsFractions: Schema.Boolean;
61
+ readonly kind: Schema.Literal<"number">;
62
+ readonly tolerance: Schema.optionalKey<Schema.Struct<{
63
+ readonly kind: Schema.Literals<readonly ["absolute", "relative"]>;
64
+ readonly value: Schema.String;
65
+ }>>;
66
+ readonly value: Schema.String;
67
+ }>, Schema.Struct<{
68
+ readonly acceptedAnswers: Schema.NonEmptyArray<Schema.Trimmed>;
69
+ readonly collapseWhitespace: Schema.Boolean;
70
+ readonly ignoreCase: Schema.Boolean;
71
+ readonly kind: Schema.Literal<"text">;
72
+ }>]>;
73
+ readonly kind: Schema.Literal<"short-answer">;
29
74
  }>, Schema.Struct<{
30
75
  readonly kind: Schema.Literal<"single-choice">;
31
76
  readonly options: Schema.$Array<Schema.Struct<{
@@ -36,8 +81,82 @@ export declare const QuestionResponseSchema: Schema.Union<readonly [Schema.Struc
36
81
  }>>;
37
82
  }>]>;
38
83
  export type QuestionResponse = typeof QuestionResponseSchema.Type;
39
- /** Returns locale-neutral response identity without localized label content. */
84
+ /**
85
+ * Returns the response identity shared by every delivery language: keys,
86
+ * order, and answer keys without labels or accepted text written in one
87
+ * delivery language. A rubric keeps its labels because each copy carries them
88
+ * in every active app locale.
89
+ */
40
90
  export declare function canonicalQuestionResponseStructure(response: QuestionResponse): {
91
+ criteria: {
92
+ criterionKey: string;
93
+ finalAnswer?: {
94
+ acceptedAnswers: [string, ...string[]];
95
+ collapseWhitespace: boolean;
96
+ ignoreCase: boolean;
97
+ kind: "text";
98
+ } | {
99
+ acceptedAnswers?: never;
100
+ collapseWhitespace?: never;
101
+ ignoreCase?: never;
102
+ acceptsFractions: boolean;
103
+ kind: "number";
104
+ tolerance?: {
105
+ kind: "absolute" | "relative";
106
+ value: string;
107
+ };
108
+ value: string;
109
+ } | {
110
+ collapseWhitespace: boolean;
111
+ ignoreCase: boolean;
112
+ kind: "text";
113
+ };
114
+ label: {
115
+ readonly de: string;
116
+ readonly en: string;
117
+ readonly id: string;
118
+ };
119
+ levels: {
120
+ label: {
121
+ readonly de: string;
122
+ readonly en: string;
123
+ readonly id: string;
124
+ };
125
+ levelKey: string;
126
+ order: number;
127
+ points: number;
128
+ }[];
129
+ order: number;
130
+ }[];
131
+ kind: "rubric";
132
+ } | {
133
+ key: {
134
+ acceptedAnswers: [string, ...string[]];
135
+ collapseWhitespace: boolean;
136
+ ignoreCase: boolean;
137
+ kind: "text";
138
+ } | {
139
+ acceptedAnswers?: never;
140
+ collapseWhitespace?: never;
141
+ ignoreCase?: never;
142
+ acceptsFractions: boolean;
143
+ kind: "number";
144
+ tolerance?: {
145
+ kind: "absolute" | "relative";
146
+ value: string;
147
+ };
148
+ value: string;
149
+ } | {
150
+ collapseWhitespace: boolean;
151
+ ignoreCase: boolean;
152
+ kind: "text";
153
+ };
154
+ kind: "short-answer";
155
+ categories?: never;
156
+ statements?: never;
157
+ options?: never;
158
+ } | {
159
+ key?: never;
41
160
  categories: {
42
161
  categoryKey: string;
43
162
  order: number;
@@ -50,6 +169,7 @@ export declare function canonicalQuestionResponseStructure(response: QuestionRes
50
169
  }[];
51
170
  options?: never;
52
171
  } | {
172
+ key?: never;
53
173
  categories?: never;
54
174
  statements?: never;
55
175
  kind: "multiple-choice" | "single-choice";
@@ -61,6 +181,67 @@ export declare function canonicalQuestionResponseStructure(response: QuestionRes
61
181
  };
62
182
  /** Returns response facts in stable field order for signed canonicalizers. */
63
183
  export declare function canonicalQuestionResponse(response: QuestionResponse): {
184
+ criteria: {
185
+ criterionKey: string;
186
+ finalAnswer?: {
187
+ acceptedAnswers: [string, ...string[]];
188
+ collapseWhitespace: boolean;
189
+ ignoreCase: boolean;
190
+ kind: "text";
191
+ } | {
192
+ acceptedAnswers?: never;
193
+ collapseWhitespace?: never;
194
+ ignoreCase?: never;
195
+ acceptsFractions: boolean;
196
+ kind: "number";
197
+ tolerance?: {
198
+ kind: "absolute" | "relative";
199
+ value: string;
200
+ };
201
+ value: string;
202
+ };
203
+ label: {
204
+ readonly de: string;
205
+ readonly en: string;
206
+ readonly id: string;
207
+ };
208
+ levels: {
209
+ label: {
210
+ readonly de: string;
211
+ readonly en: string;
212
+ readonly id: string;
213
+ };
214
+ levelKey: string;
215
+ order: number;
216
+ points: number;
217
+ }[];
218
+ order: number;
219
+ }[];
220
+ kind: "rubric";
221
+ } | {
222
+ categories?: never;
223
+ statements?: never;
224
+ options?: never;
225
+ key: {
226
+ acceptedAnswers: [string, ...string[]];
227
+ collapseWhitespace: boolean;
228
+ ignoreCase: boolean;
229
+ kind: "text";
230
+ } | {
231
+ acceptedAnswers?: never;
232
+ collapseWhitespace?: never;
233
+ ignoreCase?: never;
234
+ acceptsFractions: boolean;
235
+ kind: "number";
236
+ tolerance?: {
237
+ kind: "absolute" | "relative";
238
+ value: string;
239
+ };
240
+ value: string;
241
+ };
242
+ kind: "short-answer";
243
+ } | {
244
+ key?: never;
64
245
  options?: never;
65
246
  categories: {
66
247
  categoryKey: string;
@@ -75,6 +256,7 @@ export declare function canonicalQuestionResponse(response: QuestionResponse): {
75
256
  statementKey: string;
76
257
  }[];
77
258
  } | {
259
+ key?: never;
78
260
  categories?: never;
79
261
  statements?: never;
80
262
  kind: "multiple-choice" | "single-choice";
@@ -1,16 +1,23 @@
1
1
  import { Schema } from "effect";
2
+ import { canonicalQuestionAnswerKey, canonicalQuestionAnswerKeyStructure, QuestionAnswerKeySchema, } from "#contracts/question/answer";
3
+ import { QuestionResponseLabelSchema } from "#contracts/question/label";
4
+ import { canonicalQuestionRubric, canonicalQuestionRubricStructure, QuestionRubricResponseSchema, } from "#contracts/question/rubric";
2
5
  const OPTION_KEY_PATTERN = /^option-[1-9]\d*$/u;
3
6
  const CATEGORY_KEY_PATTERN = /^category-[1-9]\d*$/u;
4
7
  const STATEMENT_KEY_PATTERN = /^statement-[1-9]\d*$/u;
5
8
  const PositiveOrderSchema = Schema.Int.pipe(Schema.check(Schema.isGreaterThan(0)));
6
- /** Response formats supported by one assessment item. */
9
+ /**
10
+ * Response formats supported by one assessment item. `short-answer` grades one
11
+ * typed number or text deterministically, and `rubric` scores an open response
12
+ * per criterion.
13
+ */
7
14
  export const QuestionResponseKindSchema = Schema.Literals([
8
15
  "category",
9
16
  "multiple-choice",
17
+ "rubric",
18
+ "short-answer",
10
19
  "single-choice",
11
20
  ]);
12
- /** One non-empty Markdown label rendered by the product-owned content surface. */
13
- export const QuestionResponseLabelSchema = Schema.String.check(Schema.isNonEmpty());
14
21
  const QuestionOptionSchema = Schema.Struct({
15
22
  isCorrect: Schema.Boolean,
16
23
  label: QuestionResponseLabelSchema,
@@ -66,14 +73,35 @@ const CategoryResponseSchema = Schema.Struct({
66
73
  }).pipe(Schema.check(Schema.makeFilter(hasCanonicalCategories, {
67
74
  message: "Category responses require canonical categories and classified statements.",
68
75
  })));
76
+ /** One typed number or text graded with `matchesAnswerKey` against its key. */
77
+ const ShortAnswerResponseSchema = Schema.Struct({
78
+ key: QuestionAnswerKeySchema,
79
+ kind: Schema.Literal("short-answer"),
80
+ });
69
81
  /** Frozen locale-specific response used from publication through review. */
70
82
  export const QuestionResponseSchema = Schema.Union([
71
83
  CategoryResponseSchema,
72
84
  MultipleChoiceResponseSchema,
85
+ QuestionRubricResponseSchema,
86
+ ShortAnswerResponseSchema,
73
87
  SingleChoiceResponseSchema,
74
88
  ]);
75
- /** Returns locale-neutral response identity without localized label content. */
89
+ /**
90
+ * Returns the response identity shared by every delivery language: keys,
91
+ * order, and answer keys without labels or accepted text written in one
92
+ * delivery language. A rubric keeps its labels because each copy carries them
93
+ * in every active app locale.
94
+ */
76
95
  export function canonicalQuestionResponseStructure(response) {
96
+ if (response.kind === "rubric") {
97
+ return canonicalQuestionRubricStructure(response);
98
+ }
99
+ if (response.kind === "short-answer") {
100
+ return {
101
+ key: canonicalQuestionAnswerKeyStructure(response.key),
102
+ kind: response.kind,
103
+ };
104
+ }
77
105
  if (response.kind === "category") {
78
106
  return {
79
107
  categories: response.categories.map(({ categoryKey, order }) => ({
@@ -99,6 +127,15 @@ export function canonicalQuestionResponseStructure(response) {
99
127
  }
100
128
  /** Returns response facts in stable field order for signed canonicalizers. */
101
129
  export function canonicalQuestionResponse(response) {
130
+ if (response.kind === "rubric") {
131
+ return canonicalQuestionRubric(response);
132
+ }
133
+ if (response.kind === "short-answer") {
134
+ return {
135
+ key: canonicalQuestionAnswerKey(response.key),
136
+ kind: response.kind,
137
+ };
138
+ }
102
139
  if (response.kind === "category") {
103
140
  return {
104
141
  categories: response.categories.map(({ categoryKey, label, order }) => ({