@nakafa/aksara-contracts 0.48.9 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +9 -0
  2. package/dist/assessment/choice.d.ts +154 -0
  3. package/dist/assessment/choice.js +87 -0
  4. package/dist/assessment/document.d.ts +219 -0
  5. package/dist/assessment/document.js +162 -0
  6. package/dist/assessment/entry.d.ts +50 -0
  7. package/dist/assessment/entry.js +48 -0
  8. package/dist/assessment/explanation.d.ts +19 -0
  9. package/dist/assessment/explanation.js +18 -0
  10. package/dist/assessment/figure.d.ts +1938 -0
  11. package/dist/assessment/figure.js +236 -0
  12. package/dist/assessment/fit.d.ts +21 -0
  13. package/dist/assessment/fit.js +42 -0
  14. package/dist/assessment/graphic.d.ts +95 -0
  15. package/dist/assessment/graphic.js +106 -0
  16. package/dist/assessment/hash.d.ts +1480 -0
  17. package/dist/assessment/hash.js +66 -0
  18. package/dist/assessment/identity.d.ts +37 -0
  19. package/dist/assessment/identity.js +50 -0
  20. package/dist/assessment/inline.d.ts +124 -0
  21. package/dist/assessment/inline.js +92 -0
  22. package/dist/assessment/interaction.d.ts +219 -0
  23. package/dist/assessment/interaction.js +38 -0
  24. package/dist/assessment/item.d.ts +796 -0
  25. package/dist/assessment/item.js +108 -0
  26. package/dist/assessment/joint.d.ts +62 -0
  27. package/dist/assessment/joint.js +85 -0
  28. package/dist/assessment/key.d.ts +195 -0
  29. package/dist/assessment/key.js +136 -0
  30. package/dist/assessment/paper.d.ts +817 -0
  31. package/dist/assessment/paper.js +69 -0
  32. package/dist/assessment/part.d.ts +47 -0
  33. package/dist/assessment/part.js +32 -0
  34. package/dist/assessment/profile.d.ts +159 -0
  35. package/dist/assessment/profile.js +160 -0
  36. package/dist/assessment/record.d.ts +18 -0
  37. package/dist/assessment/record.js +27 -0
  38. package/dist/assessment/scalar.d.ts +18 -0
  39. package/dist/assessment/scalar.js +18 -0
  40. package/dist/assessment/scoring.d.ts +210 -0
  41. package/dist/assessment/scoring.js +205 -0
  42. package/dist/assessment/stimulus.d.ts +48 -0
  43. package/dist/assessment/stimulus.js +42 -0
  44. package/dist/assessment/structure.d.ts +13 -0
  45. package/dist/assessment/structure.js +29 -0
  46. package/dist/assessment/tools.d.ts +17 -0
  47. package/dist/assessment/tools.js +39 -0
  48. package/dist/locale.d.ts +9 -0
  49. package/dist/locale.js +25 -1
  50. package/dist/projection/verify.d.ts +23 -23
  51. package/dist/runtime/verify.d.ts +46 -46
  52. package/dist/transport/request.d.ts +138 -138
  53. package/package.json +73 -1
package/README.md CHANGED
@@ -61,6 +61,15 @@ Current consumers use unversioned semantic Interfaces:
61
61
  - `math/visual` owns the unversioned, renderer-neutral plane and space scene
62
62
  contract, including exact straight geometry, rich-label anchors, and the
63
63
  axis-aligned cuboid dimension mapping.
64
+ - `assessment/*` owns the assessment contract: a ProseMirror JSON `document`
65
+ with typed `figure` props, twelve `interaction` kinds that hold no answer
66
+ key, `scoring` as data, the `key` and the `explanation` of an item version as
67
+ records of their own, `item` and `stimulus` versions named by a content hash,
68
+ and the exam `profile`, the frozen `paper`, and the `tools` registry. It sits
69
+ beside the `question/` and `tryout/` contracts until the release that
70
+ switches their readers deletes them.
71
+ [ADR 0005](https://github.com/nakafaai/aksara/blob/main/docs/adr/assessment.md)
72
+ records the decisions.
64
73
 
65
74
  ## Publication dates
66
75
 
@@ -0,0 +1,154 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * Pick one option, or several. Single choice is `maxChoices` 1. Maps to
4
+ * `qti-choice-interaction` with `min-choices`, `max-choices`, and `shuffle`.
5
+ */
6
+ export declare const ChoiceInteractionSchema: Schema.Struct<{
7
+ readonly id: Schema.String;
8
+ readonly label: Schema.Trimmed;
9
+ readonly kind: Schema.Literal<"choice">;
10
+ readonly maxChoices: Schema.Int;
11
+ readonly minChoices: Schema.Int;
12
+ readonly options: Schema.$Array<Schema.Struct<{
13
+ readonly id: Schema.String;
14
+ readonly label: Schema.decodeTo<Schema.Struct<{
15
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
16
+ readonly type: Schema.Literal<"doc">;
17
+ }>, Schema.Unknown, never, never>;
18
+ }>>;
19
+ readonly shuffle: Schema.Boolean;
20
+ }>;
21
+ /**
22
+ * Statements by columns, one column for each statement. True or False for each
23
+ * statement is two columns. Maps to `qti-match-interaction`, whose first set
24
+ * is the statements and whose second set is the columns.
25
+ */
26
+ export declare const MatrixInteractionSchema: Schema.Struct<{
27
+ readonly id: Schema.String;
28
+ readonly label: Schema.Trimmed;
29
+ readonly columns: Schema.$Array<Schema.Struct<{
30
+ readonly id: Schema.String;
31
+ readonly label: Schema.decodeTo<Schema.Struct<{
32
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
33
+ readonly type: Schema.Literal<"doc">;
34
+ }>, Schema.Unknown, never, never>;
35
+ }>>;
36
+ readonly kind: Schema.Literal<"matrix">;
37
+ readonly shuffle: Schema.Boolean;
38
+ readonly statements: Schema.NonEmptyArray<Schema.Struct<{
39
+ readonly id: Schema.String;
40
+ readonly label: Schema.decodeTo<Schema.Struct<{
41
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
42
+ readonly type: Schema.Literal<"doc">;
43
+ }>, Schema.Unknown, never, never>;
44
+ }>>;
45
+ }>;
46
+ /**
47
+ * Two sets and directed pairs from a source to a target, each end with its
48
+ * own limit. Maps to `qti-match-interaction` with `qti-simple-match-set` and
49
+ * `match-max` on every `qti-simple-associable-choice`.
50
+ */
51
+ export declare const MatchInteractionSchema: Schema.Struct<{
52
+ readonly id: Schema.String;
53
+ readonly label: Schema.Trimmed;
54
+ readonly kind: Schema.Literal<"match">;
55
+ readonly shuffle: Schema.Boolean;
56
+ readonly sources: Schema.NonEmptyArray<Schema.Struct<{
57
+ readonly id: Schema.String;
58
+ readonly label: Schema.decodeTo<Schema.Struct<{
59
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
60
+ readonly type: Schema.Literal<"doc">;
61
+ }>, Schema.Unknown, never, never>;
62
+ readonly maxMatches: Schema.Int;
63
+ }>>;
64
+ readonly targets: Schema.NonEmptyArray<Schema.Struct<{
65
+ readonly id: Schema.String;
66
+ readonly label: Schema.decodeTo<Schema.Struct<{
67
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
68
+ readonly type: Schema.Literal<"doc">;
69
+ }>, Schema.Unknown, never, never>;
70
+ readonly maxMatches: Schema.Int;
71
+ }>>;
72
+ }>;
73
+ /**
74
+ * Put items in order: all of them, or a subset of `minChoices` to `maxChoices`.
75
+ * Maps to `qti-order-interaction`.
76
+ */
77
+ export declare const OrderInteractionSchema: Schema.Struct<{
78
+ readonly id: Schema.String;
79
+ readonly label: Schema.Trimmed;
80
+ readonly items: Schema.$Array<Schema.Struct<{
81
+ readonly id: Schema.String;
82
+ readonly label: Schema.decodeTo<Schema.Struct<{
83
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
84
+ readonly type: Schema.Literal<"doc">;
85
+ }>, Schema.Unknown, never, never>;
86
+ }>>;
87
+ readonly kind: Schema.Literal<"order">;
88
+ readonly maxChoices: Schema.Int;
89
+ readonly minChoices: Schema.Int;
90
+ readonly shuffle: Schema.Boolean;
91
+ }>;
92
+ /** A drop-down inside a line of text. Maps to `qti-inline-choice-interaction`. */
93
+ export declare const InlineChoiceInteractionSchema: Schema.Struct<{
94
+ readonly id: Schema.String;
95
+ readonly label: Schema.Trimmed;
96
+ readonly kind: Schema.Literal<"inlineChoice">;
97
+ readonly options: Schema.$Array<Schema.Struct<{
98
+ readonly id: Schema.String;
99
+ readonly label: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
100
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
101
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
102
+ }>, Schema.Struct<{
103
+ readonly attrs: Schema.Struct<{
104
+ readonly href: Schema.String;
105
+ }>;
106
+ readonly type: Schema.Literal<"link">;
107
+ }>]>>>;
108
+ readonly text: Schema.String;
109
+ readonly type: Schema.Literal<"text">;
110
+ }>, Schema.Struct<{
111
+ readonly attrs: Schema.Struct<{
112
+ readonly latex: Schema.Trimmed;
113
+ }>;
114
+ readonly type: Schema.Literal<"mathInline">;
115
+ }>]>>;
116
+ }>>;
117
+ readonly shuffle: Schema.Boolean;
118
+ }>;
119
+ /**
120
+ * Fill the gaps of a text from a shared set of choices, each used up to its
121
+ * own limit. Each gap sits in the prompt as an inline interaction that names
122
+ * it. Maps to `qti-gap-match-interaction` with `qti-gap-text` (`match-max`)
123
+ * and one `qti-gap` for each gap.
124
+ */
125
+ export declare const GapMatchInteractionSchema: Schema.Struct<{
126
+ readonly id: Schema.String;
127
+ readonly label: Schema.Trimmed;
128
+ readonly choices: Schema.NonEmptyArray<Schema.Struct<{
129
+ readonly id: Schema.String;
130
+ readonly label: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
131
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
132
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
133
+ }>, Schema.Struct<{
134
+ readonly attrs: Schema.Struct<{
135
+ readonly href: Schema.String;
136
+ }>;
137
+ readonly type: Schema.Literal<"link">;
138
+ }>]>>>;
139
+ readonly text: Schema.String;
140
+ readonly type: Schema.Literal<"text">;
141
+ }>, Schema.Struct<{
142
+ readonly attrs: Schema.Struct<{
143
+ readonly latex: Schema.Trimmed;
144
+ }>;
145
+ readonly type: Schema.Literal<"mathInline">;
146
+ }>]>>;
147
+ readonly maxMatches: Schema.Int;
148
+ }>>;
149
+ readonly gaps: Schema.NonEmptyArray<Schema.Struct<{
150
+ readonly id: Schema.String;
151
+ }>>;
152
+ readonly kind: Schema.Literal<"gapMatch">;
153
+ readonly shuffle: Schema.Boolean;
154
+ }>;
@@ -0,0 +1,87 @@
1
+ import { Array as Arr, Schema } from "effect";
2
+ import { hasUniqueIds, LocalIdSchema } from "#contracts/assessment/identity";
3
+ import { DocumentPartSchema, hasSelectionBounds, InteractionFields, TextPartSchema, } from "#contracts/assessment/part";
4
+ import { NonNegativeIntSchema, PositiveIntSchema, } from "#contracts/assessment/scalar";
5
+ const UNIQUE_IDS_MESSAGE = "Expected each part to have its own identifier.";
6
+ const SELECTION_MESSAGE = "Expected the fewest choices to be at most the most choices, and the most choices to be at most the number of parts.";
7
+ /**
8
+ * Pick one option, or several. Single choice is `maxChoices` 1. Maps to
9
+ * `qti-choice-interaction` with `min-choices`, `max-choices`, and `shuffle`.
10
+ */
11
+ export const ChoiceInteractionSchema = Schema.Struct({
12
+ ...InteractionFields,
13
+ kind: Schema.Literal("choice"),
14
+ maxChoices: PositiveIntSchema,
15
+ minChoices: NonNegativeIntSchema,
16
+ options: Schema.Array(DocumentPartSchema).check(Schema.isMinLength(2)),
17
+ shuffle: Schema.Boolean,
18
+ }).check(Schema.makeFilter(({ options }) => hasUniqueIds(options), {
19
+ message: UNIQUE_IDS_MESSAGE,
20
+ }), Schema.makeFilter((choice) => hasSelectionBounds(choice, choice.options.length), { message: SELECTION_MESSAGE }));
21
+ /**
22
+ * Statements by columns, one column for each statement. True or False for each
23
+ * statement is two columns. Maps to `qti-match-interaction`, whose first set
24
+ * is the statements and whose second set is the columns.
25
+ */
26
+ export const MatrixInteractionSchema = Schema.Struct({
27
+ ...InteractionFields,
28
+ columns: Schema.Array(DocumentPartSchema).check(Schema.isMinLength(2)),
29
+ kind: Schema.Literal("matrix"),
30
+ shuffle: Schema.Boolean,
31
+ statements: Schema.NonEmptyArray(DocumentPartSchema),
32
+ }).check(Schema.makeFilter(({ columns, statements }) => hasUniqueIds(Arr.appendAll(statements, columns)), { message: UNIQUE_IDS_MESSAGE }));
33
+ /** One end of a match: a part that can be paired up to `maxMatches` times. */
34
+ const MatchPartSchema = Schema.Struct({
35
+ ...DocumentPartSchema.fields,
36
+ maxMatches: PositiveIntSchema,
37
+ });
38
+ /**
39
+ * Two sets and directed pairs from a source to a target, each end with its
40
+ * own limit. Maps to `qti-match-interaction` with `qti-simple-match-set` and
41
+ * `match-max` on every `qti-simple-associable-choice`.
42
+ */
43
+ export const MatchInteractionSchema = Schema.Struct({
44
+ ...InteractionFields,
45
+ kind: Schema.Literal("match"),
46
+ shuffle: Schema.Boolean,
47
+ sources: Schema.NonEmptyArray(MatchPartSchema),
48
+ targets: Schema.NonEmptyArray(MatchPartSchema),
49
+ }).check(Schema.makeFilter(({ sources, targets }) => hasUniqueIds(Arr.appendAll(sources, targets)), { message: UNIQUE_IDS_MESSAGE }));
50
+ /**
51
+ * Put items in order: all of them, or a subset of `minChoices` to `maxChoices`.
52
+ * Maps to `qti-order-interaction`.
53
+ */
54
+ export const OrderInteractionSchema = Schema.Struct({
55
+ ...InteractionFields,
56
+ items: Schema.Array(DocumentPartSchema).check(Schema.isMinLength(2)),
57
+ kind: Schema.Literal("order"),
58
+ maxChoices: PositiveIntSchema,
59
+ minChoices: PositiveIntSchema,
60
+ shuffle: Schema.Boolean,
61
+ }).check(Schema.makeFilter(({ items }) => hasUniqueIds(items), {
62
+ message: UNIQUE_IDS_MESSAGE,
63
+ }), Schema.makeFilter((order) => hasSelectionBounds(order, order.items.length), {
64
+ message: SELECTION_MESSAGE,
65
+ }));
66
+ /** A drop-down inside a line of text. Maps to `qti-inline-choice-interaction`. */
67
+ export const InlineChoiceInteractionSchema = Schema.Struct({
68
+ ...InteractionFields,
69
+ kind: Schema.Literal("inlineChoice"),
70
+ options: Schema.Array(TextPartSchema).check(Schema.isMinLength(2)),
71
+ shuffle: Schema.Boolean,
72
+ }).check(Schema.makeFilter(({ options }) => hasUniqueIds(options), {
73
+ message: UNIQUE_IDS_MESSAGE,
74
+ }));
75
+ /**
76
+ * Fill the gaps of a text from a shared set of choices, each used up to its
77
+ * own limit. Each gap sits in the prompt as an inline interaction that names
78
+ * it. Maps to `qti-gap-match-interaction` with `qti-gap-text` (`match-max`)
79
+ * and one `qti-gap` for each gap.
80
+ */
81
+ export const GapMatchInteractionSchema = Schema.Struct({
82
+ ...InteractionFields,
83
+ choices: Schema.NonEmptyArray(Schema.Struct({ ...TextPartSchema.fields, maxMatches: PositiveIntSchema })),
84
+ gaps: Schema.NonEmptyArray(Schema.Struct({ id: LocalIdSchema })),
85
+ kind: Schema.Literal("gapMatch"),
86
+ shuffle: Schema.Boolean,
87
+ }).check(Schema.makeFilter(({ choices, gaps }) => hasUniqueIds(Arr.appendAll(choices, gaps)), { message: UNIQUE_IDS_MESSAGE }));
@@ -0,0 +1,219 @@
1
+ import { Schema } from "effect";
2
+ import { FigureNodeSchema } from "#contracts/assessment/figure";
3
+ import { type InlineInteractionNode, type InlineNode } from "#contracts/assessment/inline";
4
+ /**
5
+ * Deepest nesting a document may have, counting `doc` as level 1 and a text
6
+ * node as a level. Sixteen is the nesting that Convex allows in one stored
7
+ * document (https://docs.convex.dev/production/state/limits, section
8
+ * "Documents", row "Nesting depth", read 13 October 2026), and this contract
9
+ * applies the same number to levels of nodes. A node is an object that holds an
10
+ * array, so Convex counts about two of its levels for each level here: a
11
+ * document this deep is stored as encoded JSON text and not as a Convex object.
12
+ */
13
+ export declare const MAX_DOCUMENT_DEPTH = 16;
14
+ declare const ParagraphSchema: Schema.Struct<{
15
+ readonly content: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
16
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
17
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
18
+ }>, Schema.Struct<{
19
+ readonly attrs: Schema.Struct<{
20
+ readonly href: Schema.String;
21
+ }>;
22
+ readonly type: Schema.Literal<"link">;
23
+ }>]>>>;
24
+ readonly text: Schema.String;
25
+ readonly type: Schema.Literal<"text">;
26
+ }>, Schema.Struct<{
27
+ readonly attrs: Schema.Struct<{
28
+ readonly latex: Schema.Trimmed;
29
+ }>;
30
+ readonly type: Schema.Literal<"mathInline">;
31
+ }>, Schema.Struct<{
32
+ readonly type: Schema.Literal<"hardBreak">;
33
+ }>, Schema.Struct<{
34
+ readonly attrs: Schema.Struct<{
35
+ readonly gap: Schema.NullOr<Schema.String>;
36
+ readonly interaction: Schema.String;
37
+ }>;
38
+ readonly type: Schema.Literal<"inlineInteraction">;
39
+ }>]>>>;
40
+ readonly type: Schema.Literal<"paragraph">;
41
+ }>;
42
+ export type ParagraphNode = typeof ParagraphSchema.Type;
43
+ declare const HeadingSchema: Schema.Struct<{
44
+ readonly attrs: Schema.Struct<{
45
+ readonly level: Schema.Literals<readonly [1, 2, 3]>;
46
+ }>;
47
+ readonly content: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
48
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
49
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
50
+ }>, Schema.Struct<{
51
+ readonly attrs: Schema.Struct<{
52
+ readonly href: Schema.String;
53
+ }>;
54
+ readonly type: Schema.Literal<"link">;
55
+ }>]>>>;
56
+ readonly text: Schema.String;
57
+ readonly type: Schema.Literal<"text">;
58
+ }>, Schema.Struct<{
59
+ readonly attrs: Schema.Struct<{
60
+ readonly latex: Schema.Trimmed;
61
+ }>;
62
+ readonly type: Schema.Literal<"mathInline">;
63
+ }>, Schema.Struct<{
64
+ readonly type: Schema.Literal<"hardBreak">;
65
+ }>, Schema.Struct<{
66
+ readonly attrs: Schema.Struct<{
67
+ readonly gap: Schema.NullOr<Schema.String>;
68
+ readonly interaction: Schema.String;
69
+ }>;
70
+ readonly type: Schema.Literal<"inlineInteraction">;
71
+ }>]>>>;
72
+ readonly type: Schema.Literal<"heading">;
73
+ }>;
74
+ /** Code is one run of plain text: a code block allows no marks. */
75
+ declare const CodeBlockSchema: Schema.Struct<{
76
+ readonly attrs: Schema.Struct<{
77
+ readonly language: Schema.NullOr<Schema.Trimmed>;
78
+ }>;
79
+ readonly content: Schema.optionalKey<Schema.Tuple<readonly [Schema.Struct<{
80
+ readonly text: Schema.String;
81
+ readonly type: Schema.Literal<"text">;
82
+ }>]>>;
83
+ readonly type: Schema.Literal<"codeBlock">;
84
+ }>;
85
+ declare const MathBlockSchema: Schema.Struct<{
86
+ readonly attrs: Schema.Struct<{
87
+ readonly latex: Schema.Trimmed;
88
+ }>;
89
+ readonly type: Schema.Literal<"mathBlock">;
90
+ }>;
91
+ declare const ImageNodeSchema: Schema.Struct<{
92
+ readonly attrs: Schema.Struct<{
93
+ readonly alt: Schema.Trimmed;
94
+ readonly asset: Schema.String;
95
+ readonly height: Schema.Int;
96
+ readonly width: Schema.Int;
97
+ }>;
98
+ readonly type: Schema.Literal<"image">;
99
+ }>;
100
+ /**
101
+ * The place of an interaction as a block of its own. The attribute names an
102
+ * interaction of the same item version.
103
+ */
104
+ declare const InteractionNodeSchema: Schema.Struct<{
105
+ readonly attrs: Schema.Struct<{
106
+ readonly interaction: Schema.String;
107
+ }>;
108
+ readonly type: Schema.Literal<"interaction">;
109
+ }>;
110
+ export type InteractionNode = typeof InteractionNodeSchema.Type;
111
+ /**
112
+ * Every block a document can hold. The blocks that hold blocks are written
113
+ * out here, because a recursive schema needs its type named in its own
114
+ * definition; every other node type is derived from its schema.
115
+ */
116
+ export type BlockNode = ParagraphNode | typeof HeadingSchema.Type | typeof CodeBlockSchema.Type | typeof MathBlockSchema.Type | typeof FigureNodeSchema.Type | typeof ImageNodeSchema.Type | InteractionNode | {
117
+ readonly content: readonly [ListItemNode, ...ListItemNode[]];
118
+ readonly type: "bulletList";
119
+ } | {
120
+ readonly attrs: {
121
+ readonly start: number;
122
+ };
123
+ readonly content: readonly [ListItemNode, ...ListItemNode[]];
124
+ readonly type: "orderedList";
125
+ } | {
126
+ readonly content: readonly [BlockNode, ...BlockNode[]];
127
+ readonly type: "blockquote";
128
+ } | {
129
+ readonly content: readonly [TableRowNode, ...TableRowNode[]];
130
+ readonly type: "table";
131
+ };
132
+ export type ListItemNode = typeof ListItemSchema.Type;
133
+ export type TableRowNode = typeof TableRowSchema.Type;
134
+ export type TableCellNode = typeof TableCellSchema.Type;
135
+ /** A list item opens with a paragraph, then holds any blocks, as in Tiptap. */
136
+ declare const ListItemSchema: Schema.Struct<{
137
+ readonly content: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
138
+ readonly content: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
139
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
140
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
141
+ }>, Schema.Struct<{
142
+ readonly attrs: Schema.Struct<{
143
+ readonly href: Schema.String;
144
+ }>;
145
+ readonly type: Schema.Literal<"link">;
146
+ }>]>>>;
147
+ readonly text: Schema.String;
148
+ readonly type: Schema.Literal<"text">;
149
+ }>, Schema.Struct<{
150
+ readonly attrs: Schema.Struct<{
151
+ readonly latex: Schema.Trimmed;
152
+ }>;
153
+ readonly type: Schema.Literal<"mathInline">;
154
+ }>, Schema.Struct<{
155
+ readonly type: Schema.Literal<"hardBreak">;
156
+ }>, Schema.Struct<{
157
+ readonly attrs: Schema.Struct<{
158
+ readonly gap: Schema.NullOr<Schema.String>;
159
+ readonly interaction: Schema.String;
160
+ }>;
161
+ readonly type: Schema.Literal<"inlineInteraction">;
162
+ }>]>>>;
163
+ readonly type: Schema.Literal<"paragraph">;
164
+ }>]>, readonly [Schema.suspend<Schema.Codec<BlockNode, BlockNode, never, never>>]>;
165
+ readonly type: Schema.Literal<"listItem">;
166
+ }>;
167
+ /** A header cell and a body cell differ only in their type. */
168
+ declare const TableCellSchema: Schema.Struct<{
169
+ readonly attrs: Schema.Struct<{
170
+ readonly colspan: Schema.Int;
171
+ readonly rowspan: Schema.Int;
172
+ }>;
173
+ readonly content: Schema.NonEmptyArray<Schema.suspend<Schema.Codec<BlockNode, BlockNode, never, never>>>;
174
+ readonly type: Schema.Literals<readonly ["tableCell", "tableHeader"]>;
175
+ }>;
176
+ declare const TableRowSchema: Schema.Struct<{
177
+ readonly content: Schema.NonEmptyArray<Schema.Struct<{
178
+ readonly attrs: Schema.Struct<{
179
+ readonly colspan: Schema.Int;
180
+ readonly rowspan: Schema.Int;
181
+ }>;
182
+ readonly content: Schema.NonEmptyArray<Schema.suspend<Schema.Codec<BlockNode, BlockNode, never, never>>>;
183
+ readonly type: Schema.Literals<readonly ["tableCell", "tableHeader"]>;
184
+ }>>;
185
+ readonly type: Schema.Literal<"tableRow">;
186
+ }>;
187
+ /** One block of a document. */
188
+ export declare const BlockSchema: Schema.Codec<BlockNode>;
189
+ /** Every node of a document, whatever its level. */
190
+ export type DocumentNode = typeof DocumentRootSchema.Type | BlockNode | ListItemNode | TableRowNode | TableCellNode | InlineNode;
191
+ declare const DocumentRootSchema: Schema.Struct<{
192
+ readonly content: Schema.NonEmptyArray<Schema.Codec<BlockNode, BlockNode, never, never>>;
193
+ readonly type: Schema.Literal<"doc">;
194
+ }>;
195
+ /**
196
+ * The Assessment Document: a ProseMirror JSON tree that Tiptap edits as it is.
197
+ * Its nodes and marks are the ones of this module, each with typed attributes.
198
+ * It holds the prompt of an item, so it may place interactions. A document is
199
+ * at most `MAX_DOCUMENT_DEPTH` levels deep, checked before the nodes are read.
200
+ * Its encoded type is `unknown` for that reason: the input is bounded as it
201
+ * arrives, before it is read as nodes. A document has no size limit of its own:
202
+ * `assessment/record` limits the record that holds it.
203
+ */
204
+ export declare const AssessmentDocumentSchema: Schema.decodeTo<Schema.Struct<{
205
+ readonly content: Schema.NonEmptyArray<Schema.Codec<BlockNode, BlockNode, never, never>>;
206
+ readonly type: Schema.Literal<"doc">;
207
+ }>, Schema.Unknown, never, never>;
208
+ export type AssessmentDocument = typeof AssessmentDocumentSchema.Type;
209
+ /** Returns every place where a document puts an interaction, in reading order. */
210
+ export declare function documentPlacements(node: DocumentNode): readonly (InteractionNode | InlineInteractionNode)[];
211
+ /**
212
+ * A document that places no interaction: an option label, an explanation, or a
213
+ * shared reading. Only the prompt of an item places interactions.
214
+ */
215
+ export declare const ContentDocumentSchema: Schema.decodeTo<Schema.Struct<{
216
+ readonly content: Schema.NonEmptyArray<Schema.Codec<BlockNode, BlockNode, never, never>>;
217
+ readonly type: Schema.Literal<"doc">;
218
+ }>, Schema.Unknown, never, never>;
219
+ export {};
@@ -0,0 +1,162 @@
1
+ import { Array as Arr, Predicate, Schema, SchemaTransformation } from "effect";
2
+ import { FigureNodeSchema, ImageSchema } from "#contracts/assessment/figure";
3
+ import { LocalIdSchema } from "#contracts/assessment/identity";
4
+ import { InlineContentSchema, } from "#contracts/assessment/inline";
5
+ import { LatexSchema, PlainTextSchema, PositiveIntSchema, } from "#contracts/assessment/scalar";
6
+ /**
7
+ * Deepest nesting a document may have, counting `doc` as level 1 and a text
8
+ * node as a level. Sixteen is the nesting that Convex allows in one stored
9
+ * document (https://docs.convex.dev/production/state/limits, section
10
+ * "Documents", row "Nesting depth", read 13 October 2026), and this contract
11
+ * applies the same number to levels of nodes. A node is an object that holds an
12
+ * array, so Convex counts about two of its levels for each level here: a
13
+ * document this deep is stored as encoded JSON text and not as a Convex object.
14
+ */
15
+ export const MAX_DOCUMENT_DEPTH = 16;
16
+ const ParagraphSchema = Schema.Struct({
17
+ content: Schema.optionalKey(InlineContentSchema),
18
+ type: Schema.Literal("paragraph"),
19
+ });
20
+ const HeadingSchema = Schema.Struct({
21
+ attrs: Schema.Struct({ level: Schema.Literals([1, 2, 3]) }),
22
+ content: Schema.optionalKey(InlineContentSchema),
23
+ type: Schema.Literal("heading"),
24
+ });
25
+ /** Code is one run of plain text: a code block allows no marks. */
26
+ const CodeBlockSchema = Schema.Struct({
27
+ attrs: Schema.Struct({ language: Schema.NullOr(PlainTextSchema) }),
28
+ content: Schema.optionalKey(Schema.Tuple([
29
+ Schema.Struct({
30
+ text: Schema.String.check(Schema.isNonEmpty()),
31
+ type: Schema.Literal("text"),
32
+ }),
33
+ ])),
34
+ type: Schema.Literal("codeBlock"),
35
+ });
36
+ const MathBlockSchema = Schema.Struct({
37
+ attrs: Schema.Struct({ latex: LatexSchema }),
38
+ type: Schema.Literal("mathBlock"),
39
+ });
40
+ const ImageNodeSchema = Schema.Struct({
41
+ attrs: ImageSchema,
42
+ type: Schema.Literal("image"),
43
+ });
44
+ /**
45
+ * The place of an interaction as a block of its own. The attribute names an
46
+ * interaction of the same item version.
47
+ */
48
+ const InteractionNodeSchema = Schema.Struct({
49
+ attrs: Schema.Struct({ interaction: LocalIdSchema }),
50
+ type: Schema.Literal("interaction"),
51
+ });
52
+ const BlockRef = Schema.suspend(() => BlockSchema);
53
+ /** A list item opens with a paragraph, then holds any blocks, as in Tiptap. */
54
+ const ListItemSchema = Schema.Struct({
55
+ content: Schema.TupleWithRest(Schema.Tuple([ParagraphSchema]), [BlockRef]),
56
+ type: Schema.Literal("listItem"),
57
+ });
58
+ const BulletListSchema = Schema.Struct({
59
+ content: Schema.NonEmptyArray(ListItemSchema),
60
+ type: Schema.Literal("bulletList"),
61
+ });
62
+ const OrderedListSchema = Schema.Struct({
63
+ attrs: Schema.Struct({ start: PositiveIntSchema }),
64
+ content: Schema.NonEmptyArray(ListItemSchema),
65
+ type: Schema.Literal("orderedList"),
66
+ });
67
+ const BlockquoteSchema = Schema.Struct({
68
+ content: Schema.NonEmptyArray(BlockRef),
69
+ type: Schema.Literal("blockquote"),
70
+ });
71
+ /** A header cell and a body cell differ only in their type. */
72
+ const TableCellSchema = Schema.Struct({
73
+ attrs: Schema.Struct({
74
+ colspan: PositiveIntSchema,
75
+ rowspan: PositiveIntSchema,
76
+ }),
77
+ content: Schema.NonEmptyArray(BlockRef),
78
+ type: Schema.Literals(["tableCell", "tableHeader"]),
79
+ });
80
+ const TableRowSchema = Schema.Struct({
81
+ content: Schema.NonEmptyArray(TableCellSchema),
82
+ type: Schema.Literal("tableRow"),
83
+ });
84
+ const TableSchema = Schema.Struct({
85
+ content: Schema.NonEmptyArray(TableRowSchema),
86
+ type: Schema.Literal("table"),
87
+ });
88
+ /** One block of a document. */
89
+ export const BlockSchema = Schema.Union([
90
+ ParagraphSchema,
91
+ HeadingSchema,
92
+ CodeBlockSchema,
93
+ MathBlockSchema,
94
+ FigureNodeSchema,
95
+ ImageNodeSchema,
96
+ InteractionNodeSchema,
97
+ BulletListSchema,
98
+ OrderedListSchema,
99
+ BlockquoteSchema,
100
+ TableSchema,
101
+ ]);
102
+ const DocumentRootSchema = Schema.Struct({
103
+ content: Schema.NonEmptyArray(BlockSchema),
104
+ type: Schema.Literal("doc"),
105
+ });
106
+ /** Returns the child nodes of one node, in reading order. */
107
+ function childrenOf(node) {
108
+ return "content" in node && node.content !== undefined ? node.content : [];
109
+ }
110
+ /**
111
+ * Checks that a value, read as a node, has at most `levels` levels from it
112
+ * down: the node is one level, and the nodes of its `content` are the levels
113
+ * below. It reads input that no schema has checked yet, so it assumes no shape,
114
+ * and it stops at the limit: it never calls itself more than `levels` times in
115
+ * a row, whatever the input.
116
+ */
117
+ function fitsLevels(value, levels) {
118
+ if (levels < 1) {
119
+ return false;
120
+ }
121
+ const content = Predicate.isObject(value) ? value.content : undefined;
122
+ return (!Arr.isArray(content) ||
123
+ Arr.every(content, (child) => fitsLevels(child, levels - 1)));
124
+ }
125
+ /**
126
+ * A document as it arrives, before any node is read. Reading the nodes calls
127
+ * itself once or more for each level, so a document that is deep enough
128
+ * overflows the stack before any check on the decoded tree can run, and the
129
+ * overflow is a defect, not a failure. The depth is bounded here first, on the
130
+ * input, by a walk that stops at the limit.
131
+ */
132
+ const BoundedInputSchema = Schema.Unknown.check(Schema.makeFilter((input) => fitsLevels(input, MAX_DOCUMENT_DEPTH), {
133
+ message: `Expected a document at most ${MAX_DOCUMENT_DEPTH} levels deep.`,
134
+ }));
135
+ /**
136
+ * The Assessment Document: a ProseMirror JSON tree that Tiptap edits as it is.
137
+ * Its nodes and marks are the ones of this module, each with typed attributes.
138
+ * It holds the prompt of an item, so it may place interactions. A document is
139
+ * at most `MAX_DOCUMENT_DEPTH` levels deep, checked before the nodes are read.
140
+ * Its encoded type is `unknown` for that reason: the input is bounded as it
141
+ * arrives, before it is read as nodes. A document has no size limit of its own:
142
+ * `assessment/record` limits the record that holds it.
143
+ */
144
+ export const AssessmentDocumentSchema = BoundedInputSchema.pipe(Schema.decodeTo(DocumentRootSchema, SchemaTransformation.passthroughSupertype()));
145
+ /** Returns every place where a document puts an interaction, in reading order. */
146
+ export function documentPlacements(node) {
147
+ const own = node.type === "interaction" || node.type === "inlineInteraction"
148
+ ? [node]
149
+ : [];
150
+ return Arr.appendAll(own, Arr.flatMap(childrenOf(node), documentPlacements));
151
+ }
152
+ /** Checks that a document places no interaction. */
153
+ function hasNoPlacements(document) {
154
+ return Arr.isReadonlyArrayEmpty(documentPlacements(document));
155
+ }
156
+ /**
157
+ * A document that places no interaction: an option label, an explanation, or a
158
+ * shared reading. Only the prompt of an item places interactions.
159
+ */
160
+ export const ContentDocumentSchema = AssessmentDocumentSchema.check(Schema.makeFilter(hasNoPlacements, {
161
+ message: "Expected a document without interaction places.",
162
+ }));