@nakafa/aksara-contracts 8.4.1 → 8.9.1

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 (78) hide show
  1. package/dist/assessment/answer.d.ts +2 -0
  2. package/dist/assessment/answer.js +5 -3
  3. package/dist/assessment/closure.js +2 -1
  4. package/dist/assessment/fit.d.ts +16 -2
  5. package/dist/assessment/fit.js +23 -5
  6. package/dist/assessment/graphic.d.ts +27 -0
  7. package/dist/assessment/graphic.js +17 -1
  8. package/dist/assessment/hash.d.ts +71 -3
  9. package/dist/assessment/interaction.d.ts +18 -1
  10. package/dist/assessment/interaction.js +2 -1
  11. package/dist/assessment/item.d.ts +85 -0
  12. package/dist/assessment/item.js +1 -1
  13. package/dist/assessment/joint.d.ts +4 -3
  14. package/dist/assessment/joint.js +4 -3
  15. package/dist/assessment/key.d.ts +138 -0
  16. package/dist/assessment/key.js +6 -0
  17. package/dist/assessment/paper.d.ts +316 -0
  18. package/dist/assessment/profile.d.ts +3 -3
  19. package/dist/assessment/profile.js +4 -4
  20. package/dist/assessment/rows.d.ts +285 -3
  21. package/dist/assessment/scoring.d.ts +12 -6
  22. package/dist/assessment/scoring.js +25 -8
  23. package/dist/assessment/sketch.d.ts +125 -0
  24. package/dist/assessment/sketch.js +175 -0
  25. package/dist/assessment/snapshot.d.ts +746 -10
  26. package/dist/assessment/structure.js +4 -4
  27. package/dist/hash/sha256.d.ts +16 -0
  28. package/dist/hash/sha256.js +164 -0
  29. package/dist/hash/stream.d.ts +7 -5
  30. package/dist/hash/stream.js +13 -18
  31. package/dist/math/boundary.js +3 -22
  32. package/dist/math/edge.d.ts +11 -0
  33. package/dist/math/edge.js +74 -0
  34. package/dist/math/graph.d.ts +9 -0
  35. package/dist/math/graph.js +66 -0
  36. package/dist/math/plane.js +6 -0
  37. package/dist/math/shape.d.ts +392 -0
  38. package/dist/math/shape.js +59 -0
  39. package/dist/math/straight.d.ts +13 -0
  40. package/dist/math/straight.js +26 -0
  41. package/dist/release/snapshot/data.d.ts +88 -2
  42. package/dist/release/snapshot/verify.d.ts +285 -3
  43. package/dist/transport/group.d.ts +264 -6
  44. package/dist/transport/request.d.ts +1886 -22
  45. package/dist/transport/snapshot.d.ts +176 -4
  46. package/dist/visual/biology/blood.d.ts +91 -0
  47. package/dist/visual/biology/blood.js +55 -0
  48. package/dist/visual/biology/heart.d.ts +92 -0
  49. package/dist/visual/biology/heart.js +54 -0
  50. package/dist/visual/biology/mitochondrion.d.ts +91 -0
  51. package/dist/visual/biology/mitochondrion.js +45 -0
  52. package/dist/visual/biology/muscle.d.ts +103 -0
  53. package/dist/visual/biology/muscle.js +62 -0
  54. package/dist/visual/biology/neuron.d.ts +97 -0
  55. package/dist/visual/biology/neuron.js +48 -0
  56. package/dist/visual/biology/paddy.d.ts +100 -0
  57. package/dist/visual/biology/paddy.js +54 -0
  58. package/dist/visual/biology/synapse.d.ts +101 -0
  59. package/dist/visual/biology/synapse.js +46 -0
  60. package/dist/visual/biology/vessel.d.ts +104 -0
  61. package/dist/visual/biology/vessel.js +60 -0
  62. package/dist/visual/biology/yeast.d.ts +108 -0
  63. package/dist/visual/biology/yeast.js +61 -0
  64. package/dist/visual/catalog.d.ts +2177 -778
  65. package/dist/visual/catalog.js +28 -0
  66. package/dist/visual/mathematics/journey.d.ts +118 -0
  67. package/dist/visual/mathematics/journey.js +125 -0
  68. package/dist/visual/mathematics/logic.d.ts +90 -0
  69. package/dist/visual/mathematics/logic.js +49 -0
  70. package/dist/visual/mathematics/network.d.ts +101 -0
  71. package/dist/visual/mathematics/network.js +97 -0
  72. package/dist/visual/mathematics/numeral.d.ts +81 -0
  73. package/dist/visual/mathematics/numeral.js +48 -0
  74. package/dist/visual/mathematics/sets.d.ts +92 -0
  75. package/dist/visual/mathematics/sets.js +95 -0
  76. package/dist/visual/physics/thermodynamics.d.ts +117 -0
  77. package/dist/visual/physics/thermodynamics.js +95 -0
  78. package/package.json +2 -2
@@ -0,0 +1,175 @@
1
+ import { Array as Arr, BigDecimal, HashSet, Schema } from "effect";
2
+ import { DecimalSchema, PositiveDecimalSchema, } from "#contracts/assessment/answer";
3
+ import { hasDistinctIds, LocalIdSchema } from "#contracts/assessment/identity";
4
+ import { PlainTextSchema } from "#contracts/assessment/scalar";
5
+ /** Where a graph meets the x-axis, and whether it crosses there or touches and turns back. */
6
+ const ZeroFeatureSchema = Schema.Struct({
7
+ contact: Schema.Literals(["cross", "touch"]),
8
+ kind: Schema.Literal("zero"),
9
+ x: DecimalSchema,
10
+ });
11
+ /** Where a graph crosses the y-axis. */
12
+ const InterceptFeatureSchema = Schema.Struct({
13
+ kind: Schema.Literal("yIntercept"),
14
+ y: DecimalSchema,
15
+ });
16
+ /** A turning point: a local maximum or minimum. */
17
+ const ExtremumFeatureSchema = Schema.Struct({
18
+ kind: Schema.Literal("extremum"),
19
+ turn: Schema.Literals(["maximum", "minimum"]),
20
+ x: DecimalSchema,
21
+ y: DecimalSchema,
22
+ });
23
+ /**
24
+ * A line the graph comes ever closer to: vertical at an x, or `y = slope * x +
25
+ * intercept`, which is horizontal when the slope is zero and oblique otherwise.
26
+ */
27
+ const AsymptoteFeatureSchema = Schema.Struct({
28
+ kind: Schema.Literal("asymptote"),
29
+ line: Schema.Union([
30
+ Schema.Struct({ kind: Schema.Literal("vertical"), x: DecimalSchema }),
31
+ Schema.Struct({
32
+ intercept: DecimalSchema,
33
+ kind: Schema.Literal("sloped"),
34
+ slope: DecimalSchema,
35
+ }),
36
+ ]),
37
+ });
38
+ /** Whether `from` lies left of `to`, exactly; an open end, written null, is unbounded. */
39
+ function isOrdered(from, to) {
40
+ return (from === null ||
41
+ to === null ||
42
+ BigDecimal.isLessThan(BigDecimal.fromStringUnsafe(from), BigDecimal.fromStringUnsafe(to)));
43
+ }
44
+ /** A stretch where the graph only rises or only falls; a null end is unbounded. */
45
+ const IntervalFeatureSchema = Schema.Struct({
46
+ direction: Schema.Literals(["falling", "rising"]),
47
+ from: Schema.NullOr(DecimalSchema),
48
+ kind: Schema.Literal("interval"),
49
+ to: Schema.NullOr(DecimalSchema),
50
+ }).check(Schema.makeFilter(({ from, to }) => isOrdered(from, to), {
51
+ message: "Expected an interval whose start lies left of its end.",
52
+ }));
53
+ /**
54
+ * Where the graph goes at one side: up or down without bound, or towards a
55
+ * value. An end without bound is earned when the graph's outermost stretch on
56
+ * that side moves away in the limit's direction as it goes out along that side,
57
+ * up for `positiveInfinity` and down for `negativeInfinity`: on the left that
58
+ * stretch falls from left to right for `positiveInfinity`, on the right it
59
+ * rises. No distance measures it, so it takes no tolerance. An end towards a
60
+ * value is earned when the graph's last point on that side lies within the end
61
+ * tolerance of it.
62
+ */
63
+ const EndFeatureSchema = Schema.Struct({
64
+ kind: Schema.Literal("end"),
65
+ limit: Schema.Union([
66
+ Schema.Literals(["negativeInfinity", "positiveInfinity"]),
67
+ DecimalSchema,
68
+ ]),
69
+ side: Schema.Literals(["left", "right"]),
70
+ });
71
+ /** A point where the graph changes how it bends, from concave up to concave down or back. */
72
+ const InflectionFeatureSchema = Schema.Struct({
73
+ kind: Schema.Literal("inflection"),
74
+ x: DecimalSchema,
75
+ y: DecimalSchema,
76
+ });
77
+ /**
78
+ * A point the graph passes through, such as a given point or an end of its
79
+ * domain. `end`, when present, says that the graph stops there and whether the
80
+ * point belongs to it (`closed`, drawn filled) or not (`open`, drawn hollow).
81
+ */
82
+ const PointFeatureSchema = Schema.Struct({
83
+ end: Schema.optionalKey(Schema.Literals(["closed", "open"])),
84
+ kind: Schema.Literal("point"),
85
+ x: DecimalSchema,
86
+ y: DecimalSchema,
87
+ });
88
+ /** One key feature of a graph, in the units of the plane. */
89
+ export const SketchFeatureSchema = Schema.Union([
90
+ ZeroFeatureSchema,
91
+ InterceptFeatureSchema,
92
+ ExtremumFeatureSchema,
93
+ AsymptoteFeatureSchema,
94
+ IntervalFeatureSchema,
95
+ EndFeatureSchema,
96
+ InflectionFeatureSchema,
97
+ PointFeatureSchema,
98
+ ]);
99
+ /**
100
+ * How far a drawn feature may lie from the key's and still earn its
101
+ * criterion, in the units of the plane, for each kind of feature the key
102
+ * holds. A zero, an intercept and an interval's ends are judged along the
103
+ * axis they lie on; an extremum, an inflection and a point by their distance in
104
+ * each axis; an asymptote by its distance across the frame; an end only when
105
+ * it tends towards a value.
106
+ */
107
+ const SketchTolerancesSchema = Schema.Struct({
108
+ asymptote: Schema.optionalKey(PositiveDecimalSchema),
109
+ end: Schema.optionalKey(PositiveDecimalSchema),
110
+ extremum: Schema.optionalKey(PositiveDecimalSchema),
111
+ inflection: Schema.optionalKey(PositiveDecimalSchema),
112
+ interval: Schema.optionalKey(PositiveDecimalSchema),
113
+ point: Schema.optionalKey(PositiveDecimalSchema),
114
+ yIntercept: Schema.optionalKey(PositiveDecimalSchema),
115
+ zero: Schema.optionalKey(PositiveDecimalSchema),
116
+ });
117
+ /**
118
+ * What the learner reads about one criterion of a rubric once it is scored, in
119
+ * a teacher's voice: a line for a criterion earned and one for a criterion
120
+ * missed. It is words of a language, so translations may change it.
121
+ */
122
+ export const CriterionFeedbackSchema = Schema.Struct({
123
+ earned: PlainTextSchema,
124
+ missed: PlainTextSchema,
125
+ });
126
+ /**
127
+ * One criterion of a sketch's rubric. Its points are the levels of the rubric
128
+ * rule with the same `criterion`; the key says how it is checked and what the
129
+ * learner reads when it is earned or missed, in a teacher's voice. A `feature`
130
+ * check is graded by code from the drawn strokes and marks. `requires` names
131
+ * criteria that must be earned first, written before this one, such as the
132
+ * shape of the graph before any of its points.
133
+ */
134
+ const SketchCriterionSchema = Schema.Struct({
135
+ check: Schema.Struct({
136
+ feature: SketchFeatureSchema,
137
+ kind: Schema.Literal("feature"),
138
+ }),
139
+ criterion: LocalIdSchema,
140
+ feedback: CriterionFeedbackSchema,
141
+ requires: Schema.optionalKey(Schema.NonEmptyArray(LocalIdSchema)),
142
+ });
143
+ /** Checks that each criterion requires only criteria written before it, so no chain of requirements loops. */
144
+ function requiresEarlier(criteria) {
145
+ return Arr.every(criteria, ({ requires }, index) => {
146
+ const earlier = HashSet.fromIterable(Arr.map(Arr.take(criteria, index), ({ criterion }) => criterion));
147
+ return Arr.every(requires ?? [], (id) => HashSet.has(earlier, id));
148
+ });
149
+ }
150
+ /** Checks that the key has a tolerance for every kind of feature that a criterion checks, apart from an end towards infinity. */
151
+ function hasTolerances({ criteria, tolerances, }) {
152
+ return Arr.every(criteria, ({ check: { feature } }) => isUnbounded(feature) || tolerances[feature.kind] !== undefined);
153
+ }
154
+ /** Whether a feature is an end that goes up or down without bound, which no distance measures. */
155
+ function isUnbounded(feature) {
156
+ return (feature.kind === "end" &&
157
+ (feature.limit === "negativeInfinity" ||
158
+ feature.limit === "positiveInfinity"));
159
+ }
160
+ /**
161
+ * The key of a sketch: the features its graph must show, each a criterion of
162
+ * the item's rubric, and the tolerances they are judged with. A grader reads
163
+ * the features of the learner's strokes exactly, never from pixels, and awards
164
+ * a criterion only when every criterion it requires is earned.
165
+ */
166
+ export const SketchKeySchema = Schema.Struct({
167
+ criteria: Schema.NonEmptyArray(SketchCriterionSchema).check(Schema.makeFilter((criteria) => hasDistinctIds(Arr.map(criteria, ({ criterion }) => criterion)), { message: "Expected no criterion to be named twice." }), Schema.makeFilter(requiresEarlier, {
168
+ message: "Expected each criterion to require only criteria before it.",
169
+ })),
170
+ interaction: LocalIdSchema,
171
+ kind: Schema.Literal("sketch"),
172
+ tolerances: SketchTolerancesSchema,
173
+ }).check(Schema.makeFilter(hasTolerances, {
174
+ message: "Expected a tolerance for every kind of feature the key checks.",
175
+ }));