@nakafa/aksara-contracts 0.48.9 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +9 -0
  2. package/dist/assessment/choice.d.ts +154 -0
  3. package/dist/assessment/choice.js +87 -0
  4. package/dist/assessment/document.d.ts +219 -0
  5. package/dist/assessment/document.js +162 -0
  6. package/dist/assessment/entry.d.ts +50 -0
  7. package/dist/assessment/entry.js +48 -0
  8. package/dist/assessment/explanation.d.ts +19 -0
  9. package/dist/assessment/explanation.js +18 -0
  10. package/dist/assessment/figure.d.ts +1938 -0
  11. package/dist/assessment/figure.js +236 -0
  12. package/dist/assessment/fit.d.ts +21 -0
  13. package/dist/assessment/fit.js +42 -0
  14. package/dist/assessment/graphic.d.ts +95 -0
  15. package/dist/assessment/graphic.js +106 -0
  16. package/dist/assessment/hash.d.ts +1444 -0
  17. package/dist/assessment/hash.js +66 -0
  18. package/dist/assessment/identity.d.ts +37 -0
  19. package/dist/assessment/identity.js +50 -0
  20. package/dist/assessment/inline.d.ts +124 -0
  21. package/dist/assessment/inline.js +92 -0
  22. package/dist/assessment/interaction.d.ts +219 -0
  23. package/dist/assessment/interaction.js +38 -0
  24. package/dist/assessment/item.d.ts +759 -0
  25. package/dist/assessment/item.js +98 -0
  26. package/dist/assessment/key.d.ts +195 -0
  27. package/dist/assessment/key.js +136 -0
  28. package/dist/assessment/paper.d.ts +799 -0
  29. package/dist/assessment/paper.js +69 -0
  30. package/dist/assessment/part.d.ts +47 -0
  31. package/dist/assessment/part.js +32 -0
  32. package/dist/assessment/profile.d.ts +153 -0
  33. package/dist/assessment/profile.js +160 -0
  34. package/dist/assessment/record.d.ts +18 -0
  35. package/dist/assessment/record.js +27 -0
  36. package/dist/assessment/scalar.d.ts +18 -0
  37. package/dist/assessment/scalar.js +18 -0
  38. package/dist/assessment/scoring.d.ts +157 -0
  39. package/dist/assessment/scoring.js +150 -0
  40. package/dist/assessment/stimulus.d.ts +48 -0
  41. package/dist/assessment/stimulus.js +42 -0
  42. package/dist/assessment/structure.d.ts +13 -0
  43. package/dist/assessment/structure.js +29 -0
  44. package/dist/assessment/tools.d.ts +17 -0
  45. package/dist/assessment/tools.js +39 -0
  46. package/dist/projection/verify.d.ts +23 -23
  47. package/dist/runtime/verify.d.ts +46 -46
  48. package/dist/transport/request.d.ts +138 -138
  49. package/package.json +69 -1
@@ -0,0 +1,66 @@
1
+ import { Array as Arr, Effect, Order, Predicate, Record as Rec, Schema, } from "effect";
2
+ import { Sha256MismatchFields } from "#contracts/errors";
3
+ import { hashText } from "#contracts/hash/text";
4
+ import { encodeJsonText } from "#contracts/text/json";
5
+ /** Separates the hash of an item version from the hash of any other record. */
6
+ const ITEM_DOMAIN = "nakafa.aksara.assessment-item";
7
+ /** Separates the hash of a stimulus version from the hash of any other record. */
8
+ const STIMULUS_DOMAIN = "nakafa.aksara.assessment-stimulus";
9
+ /**
10
+ * Writes a value that is already known to be JSON as text, with the keys of
11
+ * every object in code-unit order. Every leaf is a string, a finite number, a
12
+ * boolean, or null, so writing it cannot fail.
13
+ */
14
+ function writeCanonical(value) {
15
+ if (Arr.isArray(value)) {
16
+ return `[${Arr.join(Arr.map(value, (part) => writeCanonical(part)), ",")}]`;
17
+ }
18
+ if (Predicate.isObject(value)) {
19
+ const members = Arr.map(Arr.sort(Rec.keys(value), Order.String), (key) => `${encodeJsonText(key)}:${writeCanonical(value[key])}`);
20
+ return `{${Arr.join(members, ",")}}`;
21
+ }
22
+ return encodeJsonText(value);
23
+ }
24
+ /**
25
+ * Writes a JSON value as text with the keys of every object in code-unit
26
+ * order, so equal content always has the same bytes whatever order the keys
27
+ * were built in. A value that is not JSON has no canonical text and fails with
28
+ * a schema error: a member that is `undefined`, a date, a number that is not
29
+ * finite, a class instance, or a cycle. Writing any of them as something else
30
+ * would give two different values one text, and so one hash.
31
+ */
32
+ export const canonicalJson = Effect.fn("AksaraContracts.canonicalJson")(function* (value) {
33
+ const json = yield* Schema.decodeUnknownEffect(Schema.Json)(value);
34
+ return writeCanonical(json);
35
+ });
36
+ /** A stored hash is not the hash of the content that carries it. */
37
+ export class VersionHashMismatchError extends Schema.TaggedError()("VersionHashMismatchError", { ...Sha256MismatchFields }) {
38
+ }
39
+ /** Hashes the canonical encoding of one record under the domain of its kind. */
40
+ const hashRecord = (domain, record) => canonicalJson(record).pipe(Effect.flatMap((canonical) => hashText(`${domain}\n${canonical}`)));
41
+ /** Computes the hash that an item version carries, from all of its other fields. */
42
+ export const hashItemVersion = Effect.fn("AksaraContracts.hashItemVersion")((body) => hashRecord(ITEM_DOMAIN, body));
43
+ /** Computes the hash that a stimulus version carries, from all of its other fields. */
44
+ export const hashStimulusVersion = Effect.fn("AksaraContracts.hashStimulusVersion")((body) => hashRecord(STIMULUS_DOMAIN, body));
45
+ /** Requires an item version to carry the hash of its own content. */
46
+ export const verifyItemVersion = Effect.fn("AksaraContracts.verifyItemVersion")(function* (version) {
47
+ const { hash, ...body } = version;
48
+ const actualHash = yield* hashItemVersion(body);
49
+ if (actualHash !== hash) {
50
+ return yield* new VersionHashMismatchError({
51
+ actualHash,
52
+ expectedHash: hash,
53
+ });
54
+ }
55
+ });
56
+ /** Requires a stimulus version to carry the hash of its own content. */
57
+ export const verifyStimulusVersion = Effect.fn("AksaraContracts.verifyStimulusVersion")(function* (version) {
58
+ const { hash, ...body } = version;
59
+ const actualHash = yield* hashStimulusVersion(body);
60
+ if (actualHash !== hash) {
61
+ return yield* new VersionHashMismatchError({
62
+ actualHash,
63
+ expectedHash: hash,
64
+ });
65
+ }
66
+ });
@@ -0,0 +1,37 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * Identifier of one part inside one item version: an interaction, an option, a
4
+ * statement, a column, a gap, an area, a criterion, or a level. It is lower
5
+ * kebab case, such as `option-1`, and starts with a letter, so it is also a
6
+ * valid XML name for a later QTI export.
7
+ */
8
+ export declare const LocalIdSchema: Schema.String;
9
+ /** Lower kebab case key of a section or of a blueprint fact, such as `algebra`. */
10
+ export declare const KebabKeySchema: Schema.String;
11
+ /** Language-neutral identity of one item, shared by every language version. */
12
+ export declare const ItemFamilyIdSchema: Schema.brand<Schema.String, "@NakafaAI/AksaraItemFamilyId">;
13
+ export type ItemFamilyId = typeof ItemFamilyIdSchema.Type;
14
+ /** Identity of one exam profile, such as a country's SNBT profile. */
15
+ export declare const ExamProfileIdSchema: Schema.brand<Schema.String, "@NakafaAI/AksaraExamProfileId">;
16
+ export type ExamProfileId = typeof ExamProfileIdSchema.Type;
17
+ /** Identity of one frozen paper. */
18
+ export declare const PaperIdSchema: Schema.brand<Schema.String, "@NakafaAI/AksaraPaperId">;
19
+ export type PaperId = typeof PaperIdSchema.Type;
20
+ /**
21
+ * Identity of one uploaded image file. It carries no brand: a document nests
22
+ * it in recursive nodes, whose encoded and decoded types must be the same.
23
+ */
24
+ export declare const AssetIdSchema: Schema.String;
25
+ /**
26
+ * Identity of one shared reading or figure. It is namespaced, with at least
27
+ * one `/`, so `passage-1` of one set and `passage-1` of another set are two
28
+ * stimuli: `<namespace>/passage-1`.
29
+ */
30
+ export declare const StimulusIdSchema: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
31
+ export type StimulusId = typeof StimulusIdSchema.Type;
32
+ /** Checks that no identifier appears twice in a list. */
33
+ export declare function hasDistinctIds(ids: readonly string[]): boolean;
34
+ /** Checks that no two parts of one list share an identifier. */
35
+ export declare function hasUniqueIds<Part extends {
36
+ readonly id: string;
37
+ }>(parts: readonly Part[]): boolean;
@@ -0,0 +1,50 @@
1
+ import { Array as Arr, HashSet, Schema } from "effect";
2
+ import { CONTENT_KEY_MAX_LENGTH } from "#contracts/ids";
3
+ import { isLowerKebab } from "#contracts/text/syntax";
4
+ const LOCAL_ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
5
+ const KEY_PATTERN = /^[a-z0-9][a-z0-9._:/-]*$/u;
6
+ const NAMESPACED_PATTERN = /^[a-z0-9][a-z0-9._-]*(?:\/[a-z0-9][a-z0-9._-]*)+$/u;
7
+ /**
8
+ * Longest local identifier or kebab key. It is the limit that try-out keys
9
+ * already use (`tryout/key`), so one family of identifiers has one bound.
10
+ */
11
+ const KEY_MAX_LENGTH = 128;
12
+ /**
13
+ * Identifier of one part inside one item version: an interaction, an option, a
14
+ * statement, a column, a gap, an area, a criterion, or a level. It is lower
15
+ * kebab case, such as `option-1`, and starts with a letter, so it is also a
16
+ * valid XML name for a later QTI export.
17
+ */
18
+ export const LocalIdSchema = Schema.String.pipe(Schema.check(Schema.isPattern(LOCAL_ID_PATTERN)), Schema.check(Schema.isMaxLength(KEY_MAX_LENGTH)));
19
+ /** Lower kebab case key of a section or of a blueprint fact, such as `algebra`. */
20
+ export const KebabKeySchema = Schema.String.pipe(Schema.check(Schema.makeFilter(isLowerKebab, {
21
+ description: "Lowercase kebab-case assessment key.",
22
+ identifier: "AssessmentKey",
23
+ message: "Invalid assessment key.",
24
+ })), Schema.check(Schema.isMaxLength(KEY_MAX_LENGTH)));
25
+ const AssessmentKeySchema = Schema.String.pipe(Schema.check(Schema.isPattern(KEY_PATTERN)), Schema.check(Schema.isMaxLength(CONTENT_KEY_MAX_LENGTH)));
26
+ /** Language-neutral identity of one item, shared by every language version. */
27
+ export const ItemFamilyIdSchema = AssessmentKeySchema.pipe(Schema.brand("@NakafaAI/AksaraItemFamilyId"));
28
+ /** Identity of one exam profile, such as a country's SNBT profile. */
29
+ export const ExamProfileIdSchema = AssessmentKeySchema.pipe(Schema.brand("@NakafaAI/AksaraExamProfileId"));
30
+ /** Identity of one frozen paper. */
31
+ export const PaperIdSchema = AssessmentKeySchema.pipe(Schema.brand("@NakafaAI/AksaraPaperId"));
32
+ /**
33
+ * Identity of one uploaded image file. It carries no brand: a document nests
34
+ * it in recursive nodes, whose encoded and decoded types must be the same.
35
+ */
36
+ export const AssetIdSchema = AssessmentKeySchema;
37
+ /**
38
+ * Identity of one shared reading or figure. It is namespaced, with at least
39
+ * one `/`, so `passage-1` of one set and `passage-1` of another set are two
40
+ * stimuli: `<namespace>/passage-1`.
41
+ */
42
+ export const StimulusIdSchema = Schema.String.pipe(Schema.check(Schema.isPattern(NAMESPACED_PATTERN)), Schema.check(Schema.isMaxLength(CONTENT_KEY_MAX_LENGTH)), Schema.brand("@NakafaAI/AksaraStimulusId"));
43
+ /** Checks that no identifier appears twice in a list. */
44
+ export function hasDistinctIds(ids) {
45
+ return HashSet.size(HashSet.fromIterable(ids)) === ids.length;
46
+ }
47
+ /** Checks that no two parts of one list share an identifier. */
48
+ export function hasUniqueIds(parts) {
49
+ return hasDistinctIds(Arr.map(parts, ({ id }) => id));
50
+ }
@@ -0,0 +1,124 @@
1
+ import { Schema } from "effect";
2
+ /** One text mark, as ProseMirror writes it: `{ type }` plus `attrs` when it has any. */
3
+ export declare const MarkSchema: Schema.Union<readonly [Schema.Struct<{
4
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
5
+ }>, Schema.Struct<{
6
+ readonly attrs: Schema.Struct<{
7
+ readonly href: Schema.String;
8
+ }>;
9
+ readonly type: Schema.Literal<"link">;
10
+ }>]>;
11
+ export type Mark = typeof MarkSchema.Type;
12
+ /** A run of text with the same marks. Text is never empty, as in ProseMirror. */
13
+ export declare const TextNodeSchema: Schema.Struct<{
14
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
15
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
16
+ }>, Schema.Struct<{
17
+ readonly attrs: Schema.Struct<{
18
+ readonly href: Schema.String;
19
+ }>;
20
+ readonly type: Schema.Literal<"link">;
21
+ }>]>>>;
22
+ readonly text: Schema.String;
23
+ readonly type: Schema.Literal<"text">;
24
+ }>;
25
+ export type TextNode = typeof TextNodeSchema.Type;
26
+ /** Inline math. The attribute is the LaTeX source, never MathML. */
27
+ export declare const MathInlineNodeSchema: Schema.Struct<{
28
+ readonly attrs: Schema.Struct<{
29
+ readonly latex: Schema.Trimmed;
30
+ }>;
31
+ readonly type: Schema.Literal<"mathInline">;
32
+ }>;
33
+ /** A forced line break inside one paragraph. */
34
+ export declare const HardBreakNodeSchema: Schema.Struct<{
35
+ readonly type: Schema.Literal<"hardBreak">;
36
+ }>;
37
+ /**
38
+ * An interaction that sits inside a line of text: an inline choice, a text
39
+ * entry, a numeric or math entry, or one gap of a gap match. `gap` names the
40
+ * gap of a gap match and is null for every other interaction.
41
+ */
42
+ export declare const InlineInteractionNodeSchema: Schema.Struct<{
43
+ readonly attrs: Schema.Struct<{
44
+ readonly gap: Schema.NullOr<Schema.String>;
45
+ readonly interaction: Schema.String;
46
+ }>;
47
+ readonly type: Schema.Literal<"inlineInteraction">;
48
+ }>;
49
+ export type InlineInteractionNode = typeof InlineInteractionNodeSchema.Type;
50
+ /** Every node that can sit inside a paragraph or a heading. */
51
+ export declare const InlineNodeSchema: Schema.Union<readonly [Schema.Struct<{
52
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
53
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
54
+ }>, Schema.Struct<{
55
+ readonly attrs: Schema.Struct<{
56
+ readonly href: Schema.String;
57
+ }>;
58
+ readonly type: Schema.Literal<"link">;
59
+ }>]>>>;
60
+ readonly text: Schema.String;
61
+ readonly type: Schema.Literal<"text">;
62
+ }>, Schema.Struct<{
63
+ readonly attrs: Schema.Struct<{
64
+ readonly latex: Schema.Trimmed;
65
+ }>;
66
+ readonly type: Schema.Literal<"mathInline">;
67
+ }>, Schema.Struct<{
68
+ readonly type: Schema.Literal<"hardBreak">;
69
+ }>, Schema.Struct<{
70
+ readonly attrs: Schema.Struct<{
71
+ readonly gap: Schema.NullOr<Schema.String>;
72
+ readonly interaction: Schema.String;
73
+ }>;
74
+ readonly type: Schema.Literal<"inlineInteraction">;
75
+ }>]>;
76
+ export type InlineNode = typeof InlineNodeSchema.Type;
77
+ /** The inline content of one paragraph or heading, in reading order. */
78
+ export declare const InlineContentSchema: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
79
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
80
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
81
+ }>, Schema.Struct<{
82
+ readonly attrs: Schema.Struct<{
83
+ readonly href: Schema.String;
84
+ }>;
85
+ readonly type: Schema.Literal<"link">;
86
+ }>]>>>;
87
+ readonly text: Schema.String;
88
+ readonly type: Schema.Literal<"text">;
89
+ }>, Schema.Struct<{
90
+ readonly attrs: Schema.Struct<{
91
+ readonly latex: Schema.Trimmed;
92
+ }>;
93
+ readonly type: Schema.Literal<"mathInline">;
94
+ }>, Schema.Struct<{
95
+ readonly type: Schema.Literal<"hardBreak">;
96
+ }>, Schema.Struct<{
97
+ readonly attrs: Schema.Struct<{
98
+ readonly gap: Schema.NullOr<Schema.String>;
99
+ readonly interaction: Schema.String;
100
+ }>;
101
+ readonly type: Schema.Literal<"inlineInteraction">;
102
+ }>]>>;
103
+ /**
104
+ * Short rich text for a label inside a figure or an option: text and inline
105
+ * math only, with no break and no interaction.
106
+ */
107
+ export declare const RichTextSchema: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
108
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
109
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
110
+ }>, Schema.Struct<{
111
+ readonly attrs: Schema.Struct<{
112
+ readonly href: Schema.String;
113
+ }>;
114
+ readonly type: Schema.Literal<"link">;
115
+ }>]>>>;
116
+ readonly text: Schema.String;
117
+ readonly type: Schema.Literal<"text">;
118
+ }>, Schema.Struct<{
119
+ readonly attrs: Schema.Struct<{
120
+ readonly latex: Schema.Trimmed;
121
+ }>;
122
+ readonly type: Schema.Literal<"mathInline">;
123
+ }>]>>;
124
+ export type RichText = typeof RichTextSchema.Type;
@@ -0,0 +1,92 @@
1
+ import { Array as Arr, Equal, Schema } from "effect";
2
+ import { LocalIdSchema } from "#contracts/assessment/identity";
3
+ import { LatexSchema } from "#contracts/assessment/scalar";
4
+ import { hasCanonicalOrder } from "#contracts/canonical";
5
+ import { isHttpsUrl } from "#contracts/text/syntax";
6
+ /** A mark that carries no attribute: it only changes how its text looks. */
7
+ const PlainMarkSchema = Schema.Struct({
8
+ type: Schema.Literals([
9
+ "bold",
10
+ "italic",
11
+ "underline",
12
+ "code",
13
+ "subscript",
14
+ "superscript",
15
+ ]),
16
+ });
17
+ /** A link mark. Only absolute HTTPS addresses are links. */
18
+ const LinkMarkSchema = Schema.Struct({
19
+ attrs: Schema.Struct({
20
+ href: Schema.String.check(Schema.makeFilter(isHttpsUrl, {
21
+ message: "Expected an absolute HTTPS address without whitespace.",
22
+ })),
23
+ }),
24
+ type: Schema.Literal("link"),
25
+ });
26
+ /** One text mark, as ProseMirror writes it: `{ type }` plus `attrs` when it has any. */
27
+ export const MarkSchema = Schema.Union([PlainMarkSchema, LinkMarkSchema]);
28
+ /**
29
+ * The one order of marks on a text node. ProseMirror keeps a mark set in the
30
+ * order of its schema, so an equal set always has one encoding: the plain marks
31
+ * in their written order, then the link.
32
+ */
33
+ const MARK_ORDER = Arr.append(PlainMarkSchema.fields.type.literals, LinkMarkSchema.fields.type.literal);
34
+ /** Checks that marks appear once each, in the one canonical order. */
35
+ function hasCanonicalMarks(marks) {
36
+ return hasCanonicalOrder(MARK_ORDER, Arr.map(marks, ({ type }) => type));
37
+ }
38
+ const MarkSetSchema = Schema.NonEmptyArray(MarkSchema).check(Schema.makeFilter(hasCanonicalMarks, {
39
+ message: "Expected each mark once, in the canonical order.",
40
+ }));
41
+ /** A run of text with the same marks. Text is never empty, as in ProseMirror. */
42
+ export const TextNodeSchema = Schema.Struct({
43
+ marks: Schema.optionalKey(MarkSetSchema),
44
+ text: Schema.String.check(Schema.isNonEmpty()),
45
+ type: Schema.Literal("text"),
46
+ });
47
+ /** Inline math. The attribute is the LaTeX source, never MathML. */
48
+ export const MathInlineNodeSchema = Schema.Struct({
49
+ attrs: Schema.Struct({ latex: LatexSchema }),
50
+ type: Schema.Literal("mathInline"),
51
+ });
52
+ /** A forced line break inside one paragraph. */
53
+ export const HardBreakNodeSchema = Schema.Struct({
54
+ type: Schema.Literal("hardBreak"),
55
+ });
56
+ /**
57
+ * An interaction that sits inside a line of text: an inline choice, a text
58
+ * entry, a numeric or math entry, or one gap of a gap match. `gap` names the
59
+ * gap of a gap match and is null for every other interaction.
60
+ */
61
+ export const InlineInteractionNodeSchema = Schema.Struct({
62
+ attrs: Schema.Struct({
63
+ gap: Schema.NullOr(LocalIdSchema),
64
+ interaction: LocalIdSchema,
65
+ }),
66
+ type: Schema.Literal("inlineInteraction"),
67
+ });
68
+ /** Every node that can sit inside a paragraph or a heading. */
69
+ export const InlineNodeSchema = Schema.Union([
70
+ TextNodeSchema,
71
+ MathInlineNodeSchema,
72
+ HardBreakNodeSchema,
73
+ InlineInteractionNodeSchema,
74
+ ]);
75
+ /**
76
+ * Checks that two text nodes with the same marks never touch. ProseMirror
77
+ * merges them into one node, so a document that keeps them apart is not the
78
+ * canonical encoding of its text.
79
+ */
80
+ function hasMergedRuns(nodes) {
81
+ return Arr.every(Arr.zip(nodes, Arr.drop(nodes, 1)), ([left, right]) => !(left.type === "text" &&
82
+ right.type === "text" &&
83
+ Equal.equals(left.marks, right.marks)));
84
+ }
85
+ const MERGED_RUNS_MESSAGE = "Expected neighboring text nodes to differ in their marks.";
86
+ /** The inline content of one paragraph or heading, in reading order. */
87
+ export const InlineContentSchema = Schema.NonEmptyArray(InlineNodeSchema).check(Schema.makeFilter(hasMergedRuns, { message: MERGED_RUNS_MESSAGE }));
88
+ /**
89
+ * Short rich text for a label inside a figure or an option: text and inline
90
+ * math only, with no break and no interaction.
91
+ */
92
+ export const RichTextSchema = Schema.NonEmptyArray(Schema.Union([TextNodeSchema, MathInlineNodeSchema])).check(Schema.makeFilter(hasMergedRuns, { message: MERGED_RUNS_MESSAGE }));
@@ -0,0 +1,219 @@
1
+ import { Schema } from "effect";
2
+ /**
3
+ * Every interaction of Assessment v2, aligned with QTI 3.0.1. An interaction
4
+ * holds what the learner sees and does, and never an answer key: the key is a
5
+ * separate record (`assessment/key`). Upload and audio are planned and are not
6
+ * part of this contract.
7
+ */
8
+ export declare const InteractionSchema: Schema.Union<readonly [Schema.Struct<{
9
+ readonly id: Schema.String;
10
+ readonly label: Schema.Trimmed;
11
+ readonly kind: Schema.Literal<"choice">;
12
+ readonly maxChoices: Schema.Int;
13
+ readonly minChoices: Schema.Int;
14
+ readonly options: Schema.$Array<Schema.Struct<{
15
+ readonly id: Schema.String;
16
+ readonly label: Schema.decodeTo<Schema.Struct<{
17
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
18
+ readonly type: Schema.Literal<"doc">;
19
+ }>, Schema.Unknown, never, never>;
20
+ }>>;
21
+ readonly shuffle: Schema.Boolean;
22
+ }>, Schema.Struct<{
23
+ readonly id: Schema.String;
24
+ readonly label: Schema.Trimmed;
25
+ readonly columns: Schema.$Array<Schema.Struct<{
26
+ readonly id: Schema.String;
27
+ readonly label: Schema.decodeTo<Schema.Struct<{
28
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
29
+ readonly type: Schema.Literal<"doc">;
30
+ }>, Schema.Unknown, never, never>;
31
+ }>>;
32
+ readonly kind: Schema.Literal<"matrix">;
33
+ readonly shuffle: Schema.Boolean;
34
+ readonly statements: Schema.NonEmptyArray<Schema.Struct<{
35
+ readonly id: Schema.String;
36
+ readonly label: Schema.decodeTo<Schema.Struct<{
37
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
38
+ readonly type: Schema.Literal<"doc">;
39
+ }>, Schema.Unknown, never, never>;
40
+ }>>;
41
+ }>, Schema.Struct<{
42
+ readonly id: Schema.String;
43
+ readonly label: Schema.Trimmed;
44
+ readonly kind: Schema.Literal<"match">;
45
+ readonly shuffle: Schema.Boolean;
46
+ readonly sources: Schema.NonEmptyArray<Schema.Struct<{
47
+ readonly id: Schema.String;
48
+ readonly label: Schema.decodeTo<Schema.Struct<{
49
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
50
+ readonly type: Schema.Literal<"doc">;
51
+ }>, Schema.Unknown, never, never>;
52
+ readonly maxMatches: Schema.Int;
53
+ }>>;
54
+ readonly targets: Schema.NonEmptyArray<Schema.Struct<{
55
+ readonly id: Schema.String;
56
+ readonly label: Schema.decodeTo<Schema.Struct<{
57
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
58
+ readonly type: Schema.Literal<"doc">;
59
+ }>, Schema.Unknown, never, never>;
60
+ readonly maxMatches: Schema.Int;
61
+ }>>;
62
+ }>, Schema.Struct<{
63
+ readonly id: Schema.String;
64
+ readonly label: Schema.Trimmed;
65
+ readonly items: Schema.$Array<Schema.Struct<{
66
+ readonly id: Schema.String;
67
+ readonly label: Schema.decodeTo<Schema.Struct<{
68
+ readonly content: Schema.NonEmptyArray<Schema.Codec<import("./document.js").BlockNode, import("./document.js").BlockNode, never, never>>;
69
+ readonly type: Schema.Literal<"doc">;
70
+ }>, Schema.Unknown, never, never>;
71
+ }>>;
72
+ readonly kind: Schema.Literal<"order">;
73
+ readonly maxChoices: Schema.Int;
74
+ readonly minChoices: Schema.Int;
75
+ readonly shuffle: Schema.Boolean;
76
+ }>, Schema.Struct<{
77
+ readonly id: Schema.String;
78
+ readonly label: Schema.Trimmed;
79
+ readonly kind: Schema.Literal<"inlineChoice">;
80
+ readonly options: Schema.$Array<Schema.Struct<{
81
+ readonly id: Schema.String;
82
+ readonly label: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
83
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
84
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
85
+ }>, Schema.Struct<{
86
+ readonly attrs: Schema.Struct<{
87
+ readonly href: Schema.String;
88
+ }>;
89
+ readonly type: Schema.Literal<"link">;
90
+ }>]>>>;
91
+ readonly text: Schema.String;
92
+ readonly type: Schema.Literal<"text">;
93
+ }>, Schema.Struct<{
94
+ readonly attrs: Schema.Struct<{
95
+ readonly latex: Schema.Trimmed;
96
+ }>;
97
+ readonly type: Schema.Literal<"mathInline">;
98
+ }>]>>;
99
+ }>>;
100
+ readonly shuffle: Schema.Boolean;
101
+ }>, Schema.Struct<{
102
+ readonly id: Schema.String;
103
+ readonly label: Schema.Trimmed;
104
+ readonly expectedLength: Schema.optionalKey<Schema.Int>;
105
+ readonly kind: Schema.Literal<"textEntry">;
106
+ }>, Schema.Struct<{
107
+ readonly id: Schema.String;
108
+ readonly label: Schema.Trimmed;
109
+ readonly acceptsFractions: Schema.Boolean;
110
+ readonly kind: Schema.Literal<"numericEntry">;
111
+ readonly unit: Schema.optionalKey<Schema.Trimmed>;
112
+ }>, Schema.Struct<{
113
+ readonly id: Schema.String;
114
+ readonly label: Schema.Trimmed;
115
+ readonly kind: Schema.Literal<"mathEntry">;
116
+ }>, Schema.Struct<{
117
+ readonly id: Schema.String;
118
+ readonly label: Schema.Trimmed;
119
+ readonly areas: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
120
+ readonly id: Schema.String;
121
+ readonly label: Schema.Trimmed;
122
+ readonly coords: Schema.Tuple<readonly [Schema.Finite, Schema.Finite, Schema.Finite, Schema.Finite]>;
123
+ readonly shape: Schema.Literal<"rect">;
124
+ }>, Schema.Struct<{
125
+ readonly id: Schema.String;
126
+ readonly label: Schema.Trimmed;
127
+ readonly coords: Schema.Tuple<readonly [Schema.Finite, Schema.Finite, Schema.Finite]>;
128
+ readonly shape: Schema.Literal<"circle">;
129
+ }>, Schema.Struct<{
130
+ readonly id: Schema.String;
131
+ readonly label: Schema.Trimmed;
132
+ readonly coords: Schema.Tuple<readonly [Schema.Finite, Schema.Finite, Schema.Finite, Schema.Finite]>;
133
+ readonly shape: Schema.Literal<"ellipse">;
134
+ }>, Schema.Struct<{
135
+ readonly id: Schema.String;
136
+ readonly label: Schema.Trimmed;
137
+ readonly coords: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Finite, Schema.Finite, Schema.Finite, Schema.Finite, Schema.Finite, Schema.Finite]>, readonly [Schema.Finite]>;
138
+ readonly shape: Schema.Literal<"poly">;
139
+ }>, Schema.Struct<{
140
+ readonly id: Schema.String;
141
+ readonly label: Schema.Trimmed;
142
+ readonly shape: Schema.Literal<"default">;
143
+ }>]>>;
144
+ readonly image: Schema.Struct<{
145
+ readonly alt: Schema.Trimmed;
146
+ readonly asset: Schema.String;
147
+ readonly height: Schema.Int;
148
+ readonly width: Schema.Int;
149
+ }>;
150
+ readonly kind: Schema.Literal<"hotspot">;
151
+ readonly maxChoices: Schema.Int;
152
+ readonly minChoices: Schema.Int;
153
+ }>, Schema.Struct<{
154
+ readonly id: Schema.String;
155
+ readonly label: Schema.Trimmed;
156
+ readonly choices: Schema.NonEmptyArray<Schema.Struct<{
157
+ readonly id: Schema.String;
158
+ readonly label: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
159
+ readonly marks: Schema.optionalKey<Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
160
+ readonly type: Schema.Literals<readonly ["bold", "italic", "underline", "code", "subscript", "superscript"]>;
161
+ }>, Schema.Struct<{
162
+ readonly attrs: Schema.Struct<{
163
+ readonly href: Schema.String;
164
+ }>;
165
+ readonly type: Schema.Literal<"link">;
166
+ }>]>>>;
167
+ readonly text: Schema.String;
168
+ readonly type: Schema.Literal<"text">;
169
+ }>, Schema.Struct<{
170
+ readonly attrs: Schema.Struct<{
171
+ readonly latex: Schema.Trimmed;
172
+ }>;
173
+ readonly type: Schema.Literal<"mathInline">;
174
+ }>]>>;
175
+ readonly maxMatches: Schema.Int;
176
+ }>>;
177
+ readonly gaps: Schema.NonEmptyArray<Schema.Struct<{
178
+ readonly id: Schema.String;
179
+ }>>;
180
+ readonly kind: Schema.Literal<"gapMatch">;
181
+ readonly shuffle: Schema.Boolean;
182
+ }>, Schema.Struct<{
183
+ readonly id: Schema.String;
184
+ readonly label: Schema.Trimmed;
185
+ readonly count: Schema.Int;
186
+ readonly frame: Schema.Struct<{
187
+ readonly kind: Schema.Literal<"cartesian">;
188
+ readonly x: Schema.Struct<{
189
+ readonly max: Schema.Finite;
190
+ readonly min: Schema.Finite;
191
+ }>;
192
+ readonly y: Schema.Struct<{
193
+ readonly max: Schema.Finite;
194
+ readonly min: Schema.Finite;
195
+ }>;
196
+ }>;
197
+ readonly kind: Schema.Literal<"graphPoint">;
198
+ readonly placing: Schema.Literals<readonly ["points", "lines"]>;
199
+ readonly snap: Schema.optionalKey<Schema.Finite>;
200
+ }>, Schema.Struct<{
201
+ readonly id: Schema.String;
202
+ readonly label: Schema.Trimmed;
203
+ readonly expectedLines: Schema.optionalKey<Schema.Int>;
204
+ readonly kind: Schema.Literal<"extendedText">;
205
+ }>]>;
206
+ export type Interaction = typeof InteractionSchema.Type;
207
+ /**
208
+ * The kind of an interaction. It is read from the union itself, so a new
209
+ * interaction adds its kind here and nowhere else.
210
+ */
211
+ export declare const InteractionKindSchema: Schema.Union<[Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">, ...(Schema.Literal<"choice"> | Schema.Literal<"extendedText"> | Schema.Literal<"gapMatch"> | Schema.Literal<"graphPoint"> | Schema.Literal<"hotspot"> | Schema.Literal<"inlineChoice"> | Schema.Literal<"match"> | Schema.Literal<"mathEntry"> | Schema.Literal<"matrix"> | Schema.Literal<"numericEntry"> | Schema.Literal<"order"> | Schema.Literal<"textEntry">)[]]>;
212
+ export type InteractionKind = typeof InteractionKindSchema.Type;
213
+ /**
214
+ * Checks that an interaction of this kind may sit inside a line of text, as a
215
+ * field: an inline choice, a text entry, a numeric entry, or a math entry.
216
+ * Every other kind sits as a block of its own, except a gap match, which sits
217
+ * inside the text once for each of its gaps.
218
+ */
219
+ export declare function canSitInText(kind: InteractionKind): boolean;
@@ -0,0 +1,38 @@
1
+ import { Array as Arr, Match, Schema } from "effect";
2
+ import { ChoiceInteractionSchema, GapMatchInteractionSchema, InlineChoiceInteractionSchema, MatchInteractionSchema, MatrixInteractionSchema, OrderInteractionSchema, } from "#contracts/assessment/choice";
3
+ import { ExtendedTextInteractionSchema, MathEntryInteractionSchema, NumericEntryInteractionSchema, TextEntryInteractionSchema, } from "#contracts/assessment/entry";
4
+ import { GraphPointInteractionSchema, HotspotInteractionSchema, } from "#contracts/assessment/graphic";
5
+ /**
6
+ * Every interaction of Assessment v2, aligned with QTI 3.0.1. An interaction
7
+ * holds what the learner sees and does, and never an answer key: the key is a
8
+ * separate record (`assessment/key`). Upload and audio are planned and are not
9
+ * part of this contract.
10
+ */
11
+ export const InteractionSchema = Schema.Union([
12
+ ChoiceInteractionSchema,
13
+ MatrixInteractionSchema,
14
+ MatchInteractionSchema,
15
+ OrderInteractionSchema,
16
+ InlineChoiceInteractionSchema,
17
+ TextEntryInteractionSchema,
18
+ NumericEntryInteractionSchema,
19
+ MathEntryInteractionSchema,
20
+ HotspotInteractionSchema,
21
+ GapMatchInteractionSchema,
22
+ GraphPointInteractionSchema,
23
+ ExtendedTextInteractionSchema,
24
+ ]);
25
+ /**
26
+ * The kind of an interaction. It is read from the union itself, so a new
27
+ * interaction adds its kind here and nowhere else.
28
+ */
29
+ export const InteractionKindSchema = Schema.Union(Arr.map(InteractionSchema.members, ({ fields }) => fields.kind));
30
+ /**
31
+ * Checks that an interaction of this kind may sit inside a line of text, as a
32
+ * field: an inline choice, a text entry, a numeric entry, or a math entry.
33
+ * Every other kind sits as a block of its own, except a gap match, which sits
34
+ * inside the text once for each of its gaps.
35
+ */
36
+ export function canSitInText(kind) {
37
+ return Match.value(kind).pipe(Match.whenOr("inlineChoice", "textEntry", "numericEntry", "mathEntry", () => true), Match.orElse(() => false));
38
+ }