@nakafa/aksara-contracts 0.49.0 → 0.51.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.
- package/dist/artifact/integrity.d.ts +15 -2
- package/dist/artifact/integrity.js +3 -15
- package/dist/artifact/limits.js +3 -4
- package/dist/artifact/source.js +4 -8
- package/dist/artifact/spec.d.ts +30 -10
- package/dist/assessment/hash.d.ts +251 -213
- package/dist/assessment/item.d.ts +44 -7
- package/dist/assessment/item.js +19 -9
- package/dist/assessment/joint.d.ts +62 -0
- package/dist/assessment/joint.js +85 -0
- package/dist/assessment/paper.d.ts +22 -2
- package/dist/assessment/profile.d.ts +6 -0
- package/dist/assessment/scoring.d.ts +55 -2
- package/dist/assessment/scoring.js +63 -8
- package/dist/assessment/stimulus.d.ts +3 -3
- package/dist/assessment/stimulus.js +2 -2
- package/dist/errors.d.ts +3 -1
- package/dist/graph/family.d.ts +6 -2
- package/dist/graph/identity.d.ts +3 -1
- package/dist/hash/digest.d.ts +10 -0
- package/dist/hash/digest.js +40 -0
- package/dist/hash/stream.d.ts +12 -0
- package/dist/hash/stream.js +27 -0
- package/dist/hash/text.d.ts +3 -1
- package/dist/hash/text.js +2 -15
- package/dist/locale.d.ts +9 -0
- package/dist/locale.js +25 -1
- package/dist/preview/auth.d.ts +4 -2
- package/dist/preview/auth.js +26 -12
- package/dist/program/snapshot/digest.d.ts +3 -1
- package/dist/program/snapshot/digest.js +14 -22
- package/dist/program/snapshot/hash.d.ts +6 -2
- package/dist/program/snapshot/hash.js +10 -21
- package/dist/projection/digest.d.ts +11 -9
- package/dist/projection/digest.js +23 -32
- package/dist/projection/hash.d.ts +222 -2
- package/dist/projection/hash.js +6 -8
- package/dist/projection/verify.d.ts +16 -6
- package/dist/question/item.d.ts +3 -1
- package/dist/question/item.js +3 -1
- package/dist/quran/notes.d.ts +3 -1
- package/dist/quran/provenance.d.ts +6 -2
- package/dist/quran/provenance.js +8 -15
- package/dist/quran/snapshot/digest.d.ts +9 -5
- package/dist/quran/snapshot/digest.js +33 -41
- package/dist/quran/snapshot/hash.d.ts +3 -1
- package/dist/quran/snapshot/hash.js +9 -15
- package/dist/quran/snapshot/row/hash.d.ts +3 -1
- package/dist/quran/snapshot/row/hash.js +2 -8
- package/dist/release/digest.d.ts +10 -8
- package/dist/release/digest.js +22 -31
- package/dist/release/hash.d.ts +3 -1
- package/dist/release/hash.js +3 -8
- package/dist/release/items.d.ts +25 -9
- package/dist/release/items.js +12 -3
- package/dist/release/policy.d.ts +3 -1
- package/dist/release/result/digest.d.ts +23 -13
- package/dist/release/result/digest.js +20 -29
- package/dist/release/rollback/digest.d.ts +16 -10
- package/dist/release/rollback/digest.js +25 -32
- package/dist/release/route/digest.d.ts +10 -8
- package/dist/release/route/digest.js +22 -31
- package/dist/release/route/verify.d.ts +16 -6
- package/dist/release/route/verify.js +8 -2
- package/dist/release/snapshot/evidence/requirement.d.ts +3 -1
- package/dist/release/snapshot/evidence/tryout.d.ts +1 -1
- package/dist/release/snapshot/evidence/tryout.js +1 -1
- package/dist/release/snapshot/evidence.d.ts +1 -1
- package/dist/release/snapshot/verify.d.ts +19 -7
- package/dist/release/snapshot/verify.js +20 -18
- package/dist/release/verify.d.ts +9 -3
- package/dist/renderer/compatibility.d.ts +6 -2
- package/dist/renderer/compatibility.js +3 -1
- package/dist/renderer/contract.d.ts +9 -3
- package/dist/renderer/contract.js +3 -1
- package/dist/runtime/error.d.ts +3 -1
- package/dist/runtime/protected/verify.d.ts +1 -1
- package/dist/runtime/verify.d.ts +2 -2
- package/dist/runtime/verify.js +2 -1
- package/dist/signature/key.d.ts +21 -0
- package/dist/signature/key.js +104 -0
- package/dist/signature/spec.d.ts +18 -6
- package/dist/signature/spec.js +16 -4
- package/dist/transport/request.d.ts +728 -728
- package/dist/transport/response.d.ts +26 -26
- package/dist/tryout/canonical.d.ts +11 -1
- package/dist/tryout/canonical.js +6 -10
- package/dist/tryout/closure/accounting.d.ts +3 -1
- package/dist/tryout/digest.d.ts +12 -6
- package/dist/tryout/digest.js +21 -14
- package/dist/tryout/hash/catalog.d.ts +228 -3
- package/dist/tryout/hash/catalog.js +5 -7
- package/dist/tryout/hash/content.d.ts +113 -2
- package/dist/tryout/hash/content.js +10 -8
- package/dist/tryout/hash/placement.d.ts +236 -5
- package/dist/tryout/hash/placement.js +7 -8
- package/dist/tryout/runtime/hash.d.ts +3 -1
- package/dist/tryout/runtime/hash.js +3 -1
- package/dist/tryout/runtime/source.d.ts +3 -1
- package/dist/tryout/runtime/verify.d.ts +13 -5
- package/dist/tryout/runtime/verify.js +1 -1
- package/dist/tryout/scoring.d.ts +3 -1
- package/dist/tryout/snapshot/hash.d.ts +45 -4
- package/dist/tryout/snapshot/hash.js +9 -7
- package/package.json +22 -2
package/dist/assessment/item.js
CHANGED
|
@@ -3,11 +3,12 @@ import { AssessmentDocumentSchema } from "#contracts/assessment/document";
|
|
|
3
3
|
import { hasFittingRules, hasPlacedInteractions, } from "#contracts/assessment/fit";
|
|
4
4
|
import { hasDistinctIds, ItemFamilyIdSchema, KebabKeySchema, StimulusIdSchema, } from "#contracts/assessment/identity";
|
|
5
5
|
import { InteractionSchema } from "#contracts/assessment/interaction";
|
|
6
|
+
import { hasJointParts, hasOneItemRule, JointRuleSchema, sortedJoint, } from "#contracts/assessment/joint";
|
|
6
7
|
import { isWithinRecordLimit } from "#contracts/assessment/record";
|
|
7
8
|
import { ScoringOverrideSchema } from "#contracts/assessment/scoring";
|
|
8
9
|
import { hasSameStructure } from "#contracts/assessment/structure";
|
|
9
10
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
10
|
-
import {
|
|
11
|
+
import { ContentLanguageSchema } from "#contracts/locale";
|
|
11
12
|
/** The editorial facts that place an item in a blueprint. */
|
|
12
13
|
export const ItemBlueprintSchema = Schema.Struct({
|
|
13
14
|
cognitiveLevel: KebabKeySchema,
|
|
@@ -33,24 +34,30 @@ export const StimulusReferenceSchema = Schema.Struct({
|
|
|
33
34
|
});
|
|
34
35
|
/** The fields of an item version except its hash, which covers all of them. */
|
|
35
36
|
const VersionFields = {
|
|
36
|
-
deliveryLanguage:
|
|
37
|
+
deliveryLanguage: ContentLanguageSchema,
|
|
37
38
|
family: ItemFamilyIdSchema,
|
|
38
39
|
interactions: Schema.NonEmptyArray(InteractionSchema),
|
|
40
|
+
joint: Schema.optionalKey(JointRuleSchema),
|
|
39
41
|
prompt: AssessmentDocumentSchema,
|
|
40
42
|
scoring: Schema.Array(ScoringOverrideSchema),
|
|
41
43
|
stimulus: Schema.optionalKey(StimulusReferenceSchema),
|
|
42
44
|
};
|
|
43
45
|
/**
|
|
44
46
|
* One item in one delivery language, without its hash: the prompt document,
|
|
45
|
-
* its interactions, the scoring rules that override the exam profile,
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
47
|
+
* its interactions, the scoring rules that override the exam profile, the joint
|
|
48
|
+
* rule when its answers depend on each other, and the shared reading it was
|
|
49
|
+
* written against, if it has one. The prompt carries no answer key, and the
|
|
50
|
+
* version holds no explanation: the key and the explanation are records of their
|
|
51
|
+
* own (`assessment/key`, `assessment/explanation`).
|
|
49
52
|
*/
|
|
50
53
|
export const ItemVersionBodySchema = Schema.Struct(VersionFields).check(Schema.makeFilter(hasPlacedInteractions, {
|
|
51
54
|
message: "Expected the prompt to place each interaction once, as its kind allows, and no other.",
|
|
52
55
|
}), Schema.makeFilter(hasFittingRules, {
|
|
53
56
|
message: "Expected each scoring rule to fit its interaction, and each extended text to carry a rubric.",
|
|
57
|
+
}), Schema.makeFilter(hasJointParts, {
|
|
58
|
+
message: "Expected a joint rule to name at least two interactions of the version, each level naming only those.",
|
|
59
|
+
}), Schema.makeFilter(hasOneItemRule, {
|
|
60
|
+
message: "Expected a joint rule to leave the scoring overrides empty, because one rule scores the item.",
|
|
54
61
|
}));
|
|
55
62
|
/**
|
|
56
63
|
* An item version is immutable once published: a change is a new version. Its
|
|
@@ -69,12 +76,15 @@ const ItemFieldsSchema = Schema.Struct({
|
|
|
69
76
|
* and answer key, and it still holds: a translation may change words, never
|
|
70
77
|
* the task. If the structure were free to differ, one answer key, one scoring
|
|
71
78
|
* rule, and one calibrated difficulty could not serve every language of an
|
|
72
|
-
* item. The identifiers, counts, bounds, and scoring rules must
|
|
73
|
-
* labels, the text alternatives, and the units are the words of a
|
|
79
|
+
* item. The identifiers, counts, bounds, joint rule, and scoring rules must
|
|
80
|
+
* agree; the labels, the text alternatives, and the units are the words of a
|
|
81
|
+
* language. The interactions of a joint level are a set, so a language may list
|
|
82
|
+
* them in another order.
|
|
74
83
|
*/
|
|
75
84
|
function hasOneStructure(item) {
|
|
76
|
-
return hasSameStructure(Arr.map(item.versions, ({ interactions, scoring }) => ({
|
|
85
|
+
return hasSameStructure(Arr.map(item.versions, ({ interactions, joint, scoring }) => ({
|
|
77
86
|
interactions,
|
|
87
|
+
joint: joint === undefined ? undefined : sortedJoint(joint),
|
|
78
88
|
scoring,
|
|
79
89
|
})));
|
|
80
90
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { Interaction } from "#contracts/assessment/interaction";
|
|
3
|
+
import type { ScoringOverride } from "#contracts/assessment/scoring";
|
|
4
|
+
/**
|
|
5
|
+
* One level of a joint rule: the interactions that must all be correct for an
|
|
6
|
+
* item to earn the points of the level. An interaction is correct when its key
|
|
7
|
+
* matches it completely. The interactions form a set, so their order in the
|
|
8
|
+
* list carries no meaning.
|
|
9
|
+
*/
|
|
10
|
+
export declare const JointLevelSchema: Schema.Struct<{
|
|
11
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
12
|
+
readonly points: Schema.Int;
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* One rule for the whole item, for answers that depend on each other, such as an
|
|
16
|
+
* answer and its reason. The item scores the points of the first level whose
|
|
17
|
+
* interactions are all correct, and 0 when none is. Interactions scored together
|
|
18
|
+
* make a composite item, which QTI 3 scores by general response processing, not
|
|
19
|
+
* by a standard template (Best Practices and Implementation Guide, section 3.4.2).
|
|
20
|
+
*/
|
|
21
|
+
export declare const JointRuleSchema: Schema.Struct<{
|
|
22
|
+
readonly levels: Schema.NonEmptyArray<Schema.Struct<{
|
|
23
|
+
readonly correct: Schema.NonEmptyArray<Schema.String>;
|
|
24
|
+
readonly points: Schema.Int;
|
|
25
|
+
}>>;
|
|
26
|
+
}>;
|
|
27
|
+
export type JointRule = typeof JointRuleSchema.Type;
|
|
28
|
+
/** Returns the most points that a joint rule can award: the points of its first level. */
|
|
29
|
+
export declare function jointCeiling(joint: JointRule): number;
|
|
30
|
+
/**
|
|
31
|
+
* Returns a joint rule with the interactions of each level in code-unit order.
|
|
32
|
+
* A level names a set, so the order of its listing is not part of the task: the
|
|
33
|
+
* structure check of a family compares this form, and the hash keeps the exact
|
|
34
|
+
* listing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function sortedJoint(joint: JointRule): {
|
|
37
|
+
levels: [{
|
|
38
|
+
correct: [string, ...string[]];
|
|
39
|
+
points: number;
|
|
40
|
+
}, ...{
|
|
41
|
+
correct: [string, ...string[]];
|
|
42
|
+
points: number;
|
|
43
|
+
}[]];
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Checks that a joint rule has interactions to join: at least two in the
|
|
47
|
+
* version, and each level names only interactions of the version.
|
|
48
|
+
*/
|
|
49
|
+
export declare function hasJointParts(version: {
|
|
50
|
+
readonly interactions: readonly Interaction[];
|
|
51
|
+
readonly joint?: JointRule;
|
|
52
|
+
}): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Checks that a version with a joint rule sets no scoring override: one rule
|
|
55
|
+
* scores the item. This also refuses an extended text in a joint item, because
|
|
56
|
+
* an extended text needs a rubric override (`fit`), and a joint item has none. A
|
|
57
|
+
* person judges an extended text, so no key can say that it is correct.
|
|
58
|
+
*/
|
|
59
|
+
export declare function hasOneItemRule(version: {
|
|
60
|
+
readonly joint?: JointRule;
|
|
61
|
+
readonly scoring: readonly ScoringOverride[];
|
|
62
|
+
}): boolean;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Array as Arr, Order, Schema } from "effect";
|
|
2
|
+
import { hasDistinctIds, LocalIdSchema } from "#contracts/assessment/identity";
|
|
3
|
+
import { PositiveIntSchema } from "#contracts/assessment/scalar";
|
|
4
|
+
/**
|
|
5
|
+
* One level of a joint rule: the interactions that must all be correct for an
|
|
6
|
+
* item to earn the points of the level. An interaction is correct when its key
|
|
7
|
+
* matches it completely. The interactions form a set, so their order in the
|
|
8
|
+
* list carries no meaning.
|
|
9
|
+
*/
|
|
10
|
+
export const JointLevelSchema = Schema.Struct({
|
|
11
|
+
correct: Schema.NonEmptyArray(LocalIdSchema).check(Schema.makeFilter(hasDistinctIds, {
|
|
12
|
+
message: "Expected each interaction of a level once.",
|
|
13
|
+
})),
|
|
14
|
+
points: PositiveIntSchema,
|
|
15
|
+
});
|
|
16
|
+
/** Checks that each level is worth fewer points than the level above it. */
|
|
17
|
+
function hasDescendingPoints(levels) {
|
|
18
|
+
return Arr.every(Arr.zip(levels, Arr.drop(levels, 1)), ([higher, lower]) => higher.points > lower.points);
|
|
19
|
+
}
|
|
20
|
+
/** Checks that the later list names every interaction of the earlier list. */
|
|
21
|
+
function namesEveryOf(later, earlier) {
|
|
22
|
+
return Arr.every(earlier, (id) => Arr.contains(later, id));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Checks that every level can score. The item awards the first level whose
|
|
26
|
+
* interactions are all correct, so a later level that names every interaction
|
|
27
|
+
* of an earlier level could never score: each answer that earns it also earns
|
|
28
|
+
* the earlier level, which comes first.
|
|
29
|
+
*/
|
|
30
|
+
function hasReachableLevels(levels) {
|
|
31
|
+
return Arr.every(levels, (level, index) => Arr.every(Arr.take(levels, index), (earlier) => !namesEveryOf(level.correct, earlier.correct)));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* One rule for the whole item, for answers that depend on each other, such as an
|
|
35
|
+
* answer and its reason. The item scores the points of the first level whose
|
|
36
|
+
* interactions are all correct, and 0 when none is. Interactions scored together
|
|
37
|
+
* make a composite item, which QTI 3 scores by general response processing, not
|
|
38
|
+
* by a standard template (Best Practices and Implementation Guide, section 3.4.2).
|
|
39
|
+
*/
|
|
40
|
+
export const JointRuleSchema = Schema.Struct({
|
|
41
|
+
levels: Schema.NonEmptyArray(JointLevelSchema).check(Schema.makeFilter(hasDescendingPoints, {
|
|
42
|
+
message: "Expected the points of the levels to descend.",
|
|
43
|
+
}), Schema.makeFilter(hasReachableLevels, {
|
|
44
|
+
message: "Expected no level to name every interaction of an earlier level, because the earlier level would always score first.",
|
|
45
|
+
})),
|
|
46
|
+
});
|
|
47
|
+
/** Returns the most points that a joint rule can award: the points of its first level. */
|
|
48
|
+
export function jointCeiling(joint) {
|
|
49
|
+
return Arr.headNonEmpty(joint.levels).points;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Returns a joint rule with the interactions of each level in code-unit order.
|
|
53
|
+
* A level names a set, so the order of its listing is not part of the task: the
|
|
54
|
+
* structure check of a family compares this form, and the hash keeps the exact
|
|
55
|
+
* listing.
|
|
56
|
+
*/
|
|
57
|
+
export function sortedJoint(joint) {
|
|
58
|
+
return {
|
|
59
|
+
levels: Arr.map(joint.levels, ({ correct, points }) => ({
|
|
60
|
+
correct: Arr.sort(correct, Order.String),
|
|
61
|
+
points,
|
|
62
|
+
})),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Checks that a joint rule has interactions to join: at least two in the
|
|
67
|
+
* version, and each level names only interactions of the version.
|
|
68
|
+
*/
|
|
69
|
+
export function hasJointParts(version) {
|
|
70
|
+
if (version.joint === undefined) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
const ids = Arr.map(version.interactions, ({ id }) => id);
|
|
74
|
+
return (version.interactions.length >= 2 &&
|
|
75
|
+
Arr.every(version.joint.levels, ({ correct }) => Arr.every(correct, (id) => Arr.contains(ids, id))));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Checks that a version with a joint rule sets no scoring override: one rule
|
|
79
|
+
* scores the item. This also refuses an extended text in a joint item, because
|
|
80
|
+
* an extended text needs a rubric override (`fit`), and a joint item has none. A
|
|
81
|
+
* person judges an extended text, so no key can say that it is correct.
|
|
82
|
+
*/
|
|
83
|
+
export function hasOneItemRule(version) {
|
|
84
|
+
return version.joint === undefined || version.scoring.length === 0;
|
|
85
|
+
}
|
|
@@ -50,7 +50,9 @@ declare const PaperStimuliMismatchError_base: Schema.Class<PaperStimuliMismatchE
|
|
|
50
50
|
readonly hash: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
51
51
|
readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
|
|
52
52
|
}>>;
|
|
53
|
-
}>, import("effect/Cause").YieldableError
|
|
53
|
+
}>, import("effect/Cause").YieldableError & {
|
|
54
|
+
readonly brand: unique symbol;
|
|
55
|
+
}>;
|
|
54
56
|
/**
|
|
55
57
|
* A paper does not list the stimulus versions that its item versions use.
|
|
56
58
|
* `missing` are the ones the items use and the paper leaves out, and `unused`
|
|
@@ -95,7 +97,7 @@ export declare const verifyPaperStimuli: (paper: {
|
|
|
95
97
|
readonly id: string & import("effect/Brand").Brand<"@NakafaAI/AksaraStimulusId">;
|
|
96
98
|
}[];
|
|
97
99
|
}, versions: readonly {
|
|
98
|
-
readonly deliveryLanguage:
|
|
100
|
+
readonly deliveryLanguage: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentLanguage">;
|
|
99
101
|
readonly family: string & import("effect/Brand").Brand<"@NakafaAI/AksaraItemFamilyId">;
|
|
100
102
|
readonly interactions: readonly [{
|
|
101
103
|
readonly id: string;
|
|
@@ -756,6 +758,15 @@ export declare const verifyPaperStimuli: (paper: {
|
|
|
756
758
|
readonly expectedLines?: number;
|
|
757
759
|
readonly kind: "extendedText";
|
|
758
760
|
})[]];
|
|
761
|
+
readonly joint?: {
|
|
762
|
+
readonly levels: readonly [{
|
|
763
|
+
readonly correct: readonly [string, ...string[]];
|
|
764
|
+
readonly points: number;
|
|
765
|
+
}, ...{
|
|
766
|
+
readonly correct: readonly [string, ...string[]];
|
|
767
|
+
readonly points: number;
|
|
768
|
+
}[]];
|
|
769
|
+
};
|
|
759
770
|
readonly prompt: {
|
|
760
771
|
readonly content: readonly [import("./document.js").BlockNode, ...import("./document.js").BlockNode[]];
|
|
761
772
|
readonly type: "doc";
|
|
@@ -769,6 +780,15 @@ export declare const verifyPaperStimuli: (paper: {
|
|
|
769
780
|
readonly kind: "perPart";
|
|
770
781
|
readonly penaltyPerWrongPart?: number;
|
|
771
782
|
readonly pointsPerPart: number;
|
|
783
|
+
} | {
|
|
784
|
+
readonly bands: readonly [{
|
|
785
|
+
readonly points: number;
|
|
786
|
+
readonly wrong: number;
|
|
787
|
+
}, ...{
|
|
788
|
+
readonly points: number;
|
|
789
|
+
readonly wrong: number;
|
|
790
|
+
}[]];
|
|
791
|
+
readonly kind: "wrongParts";
|
|
772
792
|
} | {
|
|
773
793
|
readonly criteria: readonly [{
|
|
774
794
|
readonly id: string;
|
|
@@ -89,6 +89,12 @@ export declare const ExamProfileSchema: Schema.Struct<{
|
|
|
89
89
|
readonly kind: Schema.Literal<"perPart">;
|
|
90
90
|
readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
|
|
91
91
|
readonly pointsPerPart: Schema.Int;
|
|
92
|
+
}>, Schema.Struct<{
|
|
93
|
+
readonly bands: Schema.NonEmptyArray<Schema.Struct<{
|
|
94
|
+
readonly points: Schema.Int;
|
|
95
|
+
readonly wrong: Schema.Int;
|
|
96
|
+
}>>;
|
|
97
|
+
readonly kind: Schema.Literal<"wrongParts">;
|
|
92
98
|
}>]>;
|
|
93
99
|
}>>;
|
|
94
100
|
/**
|
|
@@ -28,6 +28,33 @@ export declare const PerPartRuleSchema: Schema.Struct<{
|
|
|
28
28
|
readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
|
|
29
29
|
readonly pointsPerPart: Schema.Int;
|
|
30
30
|
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Points by the number of wrong parts, such as the AKM rule of a complex
|
|
33
|
+
* multiple choice with more than five statements and more than two options: 2
|
|
34
|
+
* points with no wrong part, 1 point with one or two, and 0 with more. An answer
|
|
35
|
+
* scores the points of the first band whose `wrong` is at least its number of
|
|
36
|
+
* wrong parts, and 0 when no band holds it. The parts are the ones the per-part
|
|
37
|
+
* rule counts, as the key defines them for each kind.
|
|
38
|
+
*
|
|
39
|
+
* It corresponds to no standard response processing template of QTI 3.
|
|
40
|
+
* `match_correct` gives 1 or 0 for the whole interaction. `map_response` maps
|
|
41
|
+
* each response value and sums the results. With one value for the correct parts
|
|
42
|
+
* and one for the wrong parts, each wrong part moves the score by the same step,
|
|
43
|
+
* and clamping the sum to its bounds flattens only its two ends. The table 2, 1,
|
|
44
|
+
* 1, 0 for 0 to 3 wrong parts has a flat step in the middle, so no sum over the
|
|
45
|
+
* parts gives it. Section 3.4.2 of the QTI 3 Best Practices and Implementation
|
|
46
|
+
* Guide says that a composite item needs general response processing, not a
|
|
47
|
+
* standard template. A table over the wrong parts is that kind of score, so it
|
|
48
|
+
* corresponds to the general response processing of that section.
|
|
49
|
+
*/
|
|
50
|
+
export declare const WrongPartsRuleSchema: Schema.Struct<{
|
|
51
|
+
readonly bands: Schema.NonEmptyArray<Schema.Struct<{
|
|
52
|
+
readonly points: Schema.Int;
|
|
53
|
+
readonly wrong: Schema.Int;
|
|
54
|
+
}>>;
|
|
55
|
+
readonly kind: Schema.Literal<"wrongParts">;
|
|
56
|
+
}>;
|
|
57
|
+
export type WrongPartsRule = typeof WrongPartsRuleSchema.Type;
|
|
31
58
|
/**
|
|
32
59
|
* Criteria, each with ordered levels and the points of each level. The learner
|
|
33
60
|
* sees the criteria and the level reached; what earns a level is a descriptor
|
|
@@ -54,6 +81,12 @@ export declare const ScoringRuleSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
54
81
|
readonly kind: Schema.Literal<"perPart">;
|
|
55
82
|
readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
|
|
56
83
|
readonly pointsPerPart: Schema.Int;
|
|
84
|
+
}>, Schema.Struct<{
|
|
85
|
+
readonly bands: Schema.NonEmptyArray<Schema.Struct<{
|
|
86
|
+
readonly points: Schema.Int;
|
|
87
|
+
readonly wrong: Schema.Int;
|
|
88
|
+
}>>;
|
|
89
|
+
readonly kind: Schema.Literal<"wrongParts">;
|
|
57
90
|
}>, Schema.Struct<{
|
|
58
91
|
readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
|
|
59
92
|
readonly id: Schema.String;
|
|
@@ -78,6 +111,12 @@ export declare const DefaultRuleSchema: Schema.Union<readonly [Schema.Struct<{
|
|
|
78
111
|
readonly kind: Schema.Literal<"perPart">;
|
|
79
112
|
readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
|
|
80
113
|
readonly pointsPerPart: Schema.Int;
|
|
114
|
+
}>, Schema.Struct<{
|
|
115
|
+
readonly bands: Schema.NonEmptyArray<Schema.Struct<{
|
|
116
|
+
readonly points: Schema.Int;
|
|
117
|
+
readonly wrong: Schema.Int;
|
|
118
|
+
}>>;
|
|
119
|
+
readonly kind: Schema.Literal<"wrongParts">;
|
|
81
120
|
}>]>;
|
|
82
121
|
/** A rule that one item sets for one of its interactions, instead of the default. */
|
|
83
122
|
export declare const ScoringOverrideSchema: Schema.Struct<{
|
|
@@ -89,6 +128,12 @@ export declare const ScoringOverrideSchema: Schema.Struct<{
|
|
|
89
128
|
readonly kind: Schema.Literal<"perPart">;
|
|
90
129
|
readonly penaltyPerWrongPart: Schema.optionalKey<Schema.Int>;
|
|
91
130
|
readonly pointsPerPart: Schema.Int;
|
|
131
|
+
}>, Schema.Struct<{
|
|
132
|
+
readonly bands: Schema.NonEmptyArray<Schema.Struct<{
|
|
133
|
+
readonly points: Schema.Int;
|
|
134
|
+
readonly wrong: Schema.Int;
|
|
135
|
+
}>>;
|
|
136
|
+
readonly kind: Schema.Literal<"wrongParts">;
|
|
92
137
|
}>, Schema.Struct<{
|
|
93
138
|
readonly criteria: Schema.NonEmptyArray<Schema.Struct<{
|
|
94
139
|
readonly id: Schema.String;
|
|
@@ -109,13 +154,21 @@ export type ScoringOverride = typeof ScoringOverrideSchema.Type;
|
|
|
109
154
|
* interaction, and only a per-part rule reads it.
|
|
110
155
|
*/
|
|
111
156
|
export declare function scoreCeiling(rule: ScoringRule, parts: number): number;
|
|
157
|
+
/**
|
|
158
|
+
* Returns the points that a wrong-parts table gives an answer with this many
|
|
159
|
+
* wrong parts: the points of the first band that holds it, or 0 when none does.
|
|
160
|
+
* It reads the table alone, never a learner's answer: grading an answer is the
|
|
161
|
+
* work of Nakafa's engine.
|
|
162
|
+
*/
|
|
163
|
+
export declare function pointsForWrongParts(rule: WrongPartsRule, wrongParts: number): number;
|
|
112
164
|
/**
|
|
113
165
|
* Checks that a rule can score an interaction of this kind. A rubric scores an
|
|
114
166
|
* extended text and nothing else, and an extended text takes no other rule. A
|
|
115
167
|
* field has one part, worth the points of its rule: one point, or more when
|
|
116
168
|
* the item is worth more. The floor of a rule per part is at most those
|
|
117
|
-
* points
|
|
118
|
-
* the floor of a rule
|
|
169
|
+
* points, and a wrong-parts table has one band for no wrong part. Every other
|
|
170
|
+
* kind has the parts that its key counts, so the key checks the floor of a rule
|
|
171
|
+
* for those.
|
|
119
172
|
*/
|
|
120
173
|
export declare function supportsRule(kind: InteractionKind, rule: ScoringRule): boolean;
|
|
121
174
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Array as Arr, Match, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Match, Option, Schema } from "effect";
|
|
2
2
|
import { hasUniqueIds, LocalIdSchema } from "#contracts/assessment/identity";
|
|
3
3
|
import { canSitInText, } from "#contracts/assessment/interaction";
|
|
4
4
|
import { LocalizedTextSchema, NonNegativeIntSchema, PlainTextSchema, PositiveIntSchema, } from "#contracts/assessment/scalar";
|
|
@@ -30,6 +30,40 @@ export const PerPartRuleSchema = Schema.Struct({
|
|
|
30
30
|
penaltyPerWrongPart: Schema.optionalKey(PositiveIntSchema),
|
|
31
31
|
pointsPerPart: PositiveIntSchema,
|
|
32
32
|
});
|
|
33
|
+
/** One band of a wrong-parts table: the points that an answer keeps with up to `wrong` wrong parts. */
|
|
34
|
+
const WrongPartsBandSchema = Schema.Struct({
|
|
35
|
+
points: PositiveIntSchema,
|
|
36
|
+
wrong: NonNegativeIntSchema,
|
|
37
|
+
});
|
|
38
|
+
/** Checks that the bands rise in wrong parts and fall in points, so each band is a step. */
|
|
39
|
+
function hasWrongPartsSteps(bands) {
|
|
40
|
+
return Arr.every(Arr.zip(bands, Arr.drop(bands, 1)), ([lower, higher]) => lower.wrong < higher.wrong && lower.points > higher.points);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Points by the number of wrong parts, such as the AKM rule of a complex
|
|
44
|
+
* multiple choice with more than five statements and more than two options: 2
|
|
45
|
+
* points with no wrong part, 1 point with one or two, and 0 with more. An answer
|
|
46
|
+
* scores the points of the first band whose `wrong` is at least its number of
|
|
47
|
+
* wrong parts, and 0 when no band holds it. The parts are the ones the per-part
|
|
48
|
+
* rule counts, as the key defines them for each kind.
|
|
49
|
+
*
|
|
50
|
+
* It corresponds to no standard response processing template of QTI 3.
|
|
51
|
+
* `match_correct` gives 1 or 0 for the whole interaction. `map_response` maps
|
|
52
|
+
* each response value and sums the results. With one value for the correct parts
|
|
53
|
+
* and one for the wrong parts, each wrong part moves the score by the same step,
|
|
54
|
+
* and clamping the sum to its bounds flattens only its two ends. The table 2, 1,
|
|
55
|
+
* 1, 0 for 0 to 3 wrong parts has a flat step in the middle, so no sum over the
|
|
56
|
+
* parts gives it. Section 3.4.2 of the QTI 3 Best Practices and Implementation
|
|
57
|
+
* Guide says that a composite item needs general response processing, not a
|
|
58
|
+
* standard template. A table over the wrong parts is that kind of score, so it
|
|
59
|
+
* corresponds to the general response processing of that section.
|
|
60
|
+
*/
|
|
61
|
+
export const WrongPartsRuleSchema = Schema.Struct({
|
|
62
|
+
bands: Schema.NonEmptyArray(WrongPartsBandSchema).check(Schema.makeFilter(hasWrongPartsSteps, {
|
|
63
|
+
message: "Expected the bands to rise in wrong parts and fall in points.",
|
|
64
|
+
})),
|
|
65
|
+
kind: Schema.Literal("wrongParts"),
|
|
66
|
+
});
|
|
33
67
|
const RubricLevelSchema = Schema.Struct({
|
|
34
68
|
id: LocalIdSchema,
|
|
35
69
|
label: PlainTextSchema,
|
|
@@ -64,6 +98,7 @@ export const RubricRuleSchema = Schema.Struct({
|
|
|
64
98
|
export const ScoringRuleSchema = Schema.Union([
|
|
65
99
|
AllOrNothingRuleSchema,
|
|
66
100
|
PerPartRuleSchema,
|
|
101
|
+
WrongPartsRuleSchema,
|
|
67
102
|
RubricRuleSchema,
|
|
68
103
|
]);
|
|
69
104
|
/**
|
|
@@ -73,6 +108,7 @@ export const ScoringRuleSchema = Schema.Union([
|
|
|
73
108
|
export const DefaultRuleSchema = Schema.Union([
|
|
74
109
|
AllOrNothingRuleSchema,
|
|
75
110
|
PerPartRuleSchema,
|
|
111
|
+
WrongPartsRuleSchema,
|
|
76
112
|
]);
|
|
77
113
|
/** A rule that one item sets for one of its interactions, instead of the default. */
|
|
78
114
|
export const ScoringOverrideSchema = Schema.Struct({
|
|
@@ -93,26 +129,45 @@ export function scoreCeiling(rule, parts) {
|
|
|
93
129
|
allOrNothing: () => 1,
|
|
94
130
|
perPart: ({ pointsPerPart }) => pointsPerPart * parts,
|
|
95
131
|
rubric: ({ criteria }) => Arr.reduce(criteria, 0, (total, criterion) => total + highestPoints(criterion)),
|
|
132
|
+
wrongParts: ({ bands }) => Arr.headNonEmpty(bands).points,
|
|
96
133
|
}));
|
|
97
134
|
}
|
|
98
135
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
136
|
+
* Returns the points that a wrong-parts table gives an answer with this many
|
|
137
|
+
* wrong parts: the points of the first band that holds it, or 0 when none does.
|
|
138
|
+
* It reads the table alone, never a learner's answer: grading an answer is the
|
|
139
|
+
* work of Nakafa's engine.
|
|
140
|
+
*/
|
|
141
|
+
export function pointsForWrongParts(rule, wrongParts) {
|
|
142
|
+
return Arr.findFirst(rule.bands, ({ wrong }) => wrong >= wrongParts).pipe(Option.map(({ points }) => points), Option.getOrElse(() => 0));
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Checks that a rule can score a field, which has one part. The floor of a
|
|
146
|
+
* per-part rule is at most the points of that part. A wrong-parts table has one
|
|
147
|
+
* band, for no wrong part, because a field has one part: any other band would
|
|
148
|
+
* award points for a wrong answer.
|
|
101
149
|
*/
|
|
102
|
-
function
|
|
103
|
-
|
|
150
|
+
function fitsField(rule) {
|
|
151
|
+
if (rule.kind === "perPart") {
|
|
152
|
+
return rule.floor <= scoreCeiling(rule, 1);
|
|
153
|
+
}
|
|
154
|
+
if (rule.kind === "wrongParts") {
|
|
155
|
+
return rule.bands.length === 1 && Arr.headNonEmpty(rule.bands).wrong === 0;
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
104
158
|
}
|
|
105
159
|
/**
|
|
106
160
|
* Checks that a rule can score an interaction of this kind. A rubric scores an
|
|
107
161
|
* extended text and nothing else, and an extended text takes no other rule. A
|
|
108
162
|
* field has one part, worth the points of its rule: one point, or more when
|
|
109
163
|
* the item is worth more. The floor of a rule per part is at most those
|
|
110
|
-
* points
|
|
111
|
-
* the floor of a rule
|
|
164
|
+
* points, and a wrong-parts table has one band for no wrong part. Every other
|
|
165
|
+
* kind has the parts that its key counts, so the key checks the floor of a rule
|
|
166
|
+
* for those.
|
|
112
167
|
*/
|
|
113
168
|
export function supportsRule(kind, rule) {
|
|
114
169
|
return ((kind === "extendedText") === (rule.kind === "rubric") &&
|
|
115
|
-
(!canSitInText(kind) ||
|
|
170
|
+
(!canSitInText(kind) || fitsField(rule)));
|
|
116
171
|
}
|
|
117
172
|
/**
|
|
118
173
|
* Whole marks that a penalized exam awards for a correct, a wrong, and a blank
|
|
@@ -4,7 +4,7 @@ import { Schema } from "effect";
|
|
|
4
4
|
* is a document that places no interaction.
|
|
5
5
|
*/
|
|
6
6
|
export declare const StimulusVersionBodySchema: Schema.Struct<{
|
|
7
|
-
deliveryLanguage: Schema.brand<Schema.
|
|
7
|
+
deliveryLanguage: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
|
|
8
8
|
document: Schema.decodeTo<Schema.Struct<{
|
|
9
9
|
readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
|
|
10
10
|
readonly type: Schema.Literal<"doc">;
|
|
@@ -19,7 +19,7 @@ export declare const StimulusVersionBodySchema: Schema.Struct<{
|
|
|
19
19
|
* `assessment/record`.
|
|
20
20
|
*/
|
|
21
21
|
export declare const StimulusVersionSchema: Schema.Struct<{
|
|
22
|
-
readonly deliveryLanguage: Schema.brand<Schema.
|
|
22
|
+
readonly deliveryLanguage: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
|
|
23
23
|
readonly document: Schema.decodeTo<Schema.Struct<{
|
|
24
24
|
readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
|
|
25
25
|
readonly type: Schema.Literal<"doc">;
|
|
@@ -36,7 +36,7 @@ export type StimulusVersion = typeof StimulusVersionSchema.Type;
|
|
|
36
36
|
export declare const StimulusSchema: Schema.Struct<{
|
|
37
37
|
readonly id: Schema.brand<Schema.String, "@NakafaAI/AksaraStimulusId">;
|
|
38
38
|
readonly versions: Schema.NonEmptyArray<Schema.Struct<{
|
|
39
|
-
readonly deliveryLanguage: Schema.brand<Schema.
|
|
39
|
+
readonly deliveryLanguage: Schema.brand<Schema.String, "@NakafaAI/AksaraContentLanguage">;
|
|
40
40
|
readonly document: Schema.decodeTo<Schema.Struct<{
|
|
41
41
|
readonly content: Schema.NonEmptyArray<Schema.Codec<import("#contracts/assessment/document").BlockNode, import("#contracts/assessment/document").BlockNode, never, never>>;
|
|
42
42
|
readonly type: Schema.Literal<"doc">;
|
|
@@ -3,10 +3,10 @@ import { ContentDocumentSchema } from "#contracts/assessment/document";
|
|
|
3
3
|
import { hasDistinctIds, StimulusIdSchema, } from "#contracts/assessment/identity";
|
|
4
4
|
import { isWithinRecordLimit } from "#contracts/assessment/record";
|
|
5
5
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
6
|
-
import {
|
|
6
|
+
import { ContentLanguageSchema } from "#contracts/locale";
|
|
7
7
|
/** The fields of a stimulus version except its hash, which covers all of them. */
|
|
8
8
|
const VersionFields = {
|
|
9
|
-
deliveryLanguage:
|
|
9
|
+
deliveryLanguage: ContentLanguageSchema,
|
|
10
10
|
document: ContentDocumentSchema,
|
|
11
11
|
id: StimulusIdSchema,
|
|
12
12
|
};
|
package/dist/errors.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ declare const ContractDecodeError_base: Schema.Class<ContractDecodeError, Schema
|
|
|
3
3
|
readonly cause: Schema.Unknown;
|
|
4
4
|
readonly contract: Schema.Trimmed;
|
|
5
5
|
readonly message: Schema.Trimmed;
|
|
6
|
-
}>, import("effect/Cause").YieldableError
|
|
6
|
+
}>, import("effect/Cause").YieldableError & {
|
|
7
|
+
readonly brand: unique symbol;
|
|
8
|
+
}>;
|
|
7
9
|
/** Describes a wire value that failed its named Effect Schema contract. */
|
|
8
10
|
export declare class ContractDecodeError extends ContractDecodeError_base {
|
|
9
11
|
}
|
package/dist/graph/family.d.ts
CHANGED
|
@@ -13,7 +13,9 @@ export declare const LearningGraphAssetOwnerSchema: Schema.Struct<{
|
|
|
13
13
|
export type LearningGraphAssetOwner = typeof LearningGraphAssetOwnerSchema.Type;
|
|
14
14
|
declare const LearningGraphAssetFamilyError_base: Schema.Class<LearningGraphAssetFamilyError, Schema.TaggedStruct<"LearningGraphAssetFamilyError", {
|
|
15
15
|
readonly assetId: Schema.String;
|
|
16
|
-
}>, import("effect/Cause").YieldableError
|
|
16
|
+
}>, import("effect/Cause").YieldableError & {
|
|
17
|
+
readonly brand: unique symbol;
|
|
18
|
+
}>;
|
|
17
19
|
/** One asset ID cannot address a supported current semantic content family. */
|
|
18
20
|
export declare class LearningGraphAssetFamilyError extends LearningGraphAssetFamilyError_base {
|
|
19
21
|
}
|
|
@@ -25,7 +27,9 @@ declare const LearningGraphFamilyError_base: Schema.Class<LearningGraphFamilyErr
|
|
|
25
27
|
readonly learningObjectId: Schema.String;
|
|
26
28
|
readonly lensId: Schema.String;
|
|
27
29
|
}>;
|
|
28
|
-
}>, import("effect/Cause").YieldableError
|
|
30
|
+
}>, import("effect/Cause").YieldableError & {
|
|
31
|
+
readonly brand: unique symbol;
|
|
32
|
+
}>;
|
|
29
33
|
/** One graph identity does not coherently belong to a current semantic family. */
|
|
30
34
|
export declare class LearningGraphFamilyError extends LearningGraphFamilyError_base {
|
|
31
35
|
}
|
package/dist/graph/identity.d.ts
CHANGED
|
@@ -10,7 +10,9 @@ export declare const LearningGraphSegmentsSchema: Schema.Struct<{
|
|
|
10
10
|
export type LearningGraphSegments = typeof LearningGraphSegmentsSchema.Type;
|
|
11
11
|
declare const LearningGraphIdentityError_base: Schema.Class<LearningGraphIdentityError, Schema.TaggedStruct<"LearningGraphIdentityError", {
|
|
12
12
|
readonly cause: Schema.Unknown;
|
|
13
|
-
}>, import("effect/Cause").YieldableError
|
|
13
|
+
}>, import("effect/Cause").YieldableError & {
|
|
14
|
+
readonly brand: unique symbol;
|
|
15
|
+
}>;
|
|
14
16
|
/** Source segments could not produce valid stable graph identities. */
|
|
15
17
|
export declare class LearningGraphIdentityError extends LearningGraphIdentityError_base {
|
|
16
18
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Crypto, Effect, PlatformError } from "effect";
|
|
2
|
+
/**
|
|
3
|
+
* Web Crypto behind Effect's `Crypto` service. Every runtime that Aksara
|
|
4
|
+
* contracts run in has `crypto.subtle`, so digests need no runtime layer.
|
|
5
|
+
*/
|
|
6
|
+
export declare const webCryptoService: Crypto.Crypto;
|
|
7
|
+
/** Computes the SHA-256 digest bytes of one byte sequence through Effect's Crypto service. */
|
|
8
|
+
export declare const digestSha256: (bytes: Uint8Array<ArrayBufferLike>) => Effect.Effect<Uint8Array<ArrayBufferLike>, PlatformError.PlatformError, never>;
|
|
9
|
+
/** Computes the `sha256:` identity of one byte sequence, the form every stored hash uses. */
|
|
10
|
+
export declare const hashBytes: (bytes: Uint8Array<ArrayBufferLike>) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, PlatformError.PlatformError, never>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Crypto, Effect, PlatformError } from "effect";
|
|
2
|
+
import { Hex } from "effect/encoding";
|
|
3
|
+
import { Sha256HashSchema } from "#contracts/ids";
|
|
4
|
+
/** Largest byte count that one `crypto.getRandomValues` call accepts. */
|
|
5
|
+
const RANDOM_CHUNK_BYTES = 65_536;
|
|
6
|
+
/**
|
|
7
|
+
* Web Crypto behind Effect's `Crypto` service. Every runtime that Aksara
|
|
8
|
+
* contracts run in has `crypto.subtle`, so digests need no runtime layer.
|
|
9
|
+
*/
|
|
10
|
+
export const webCryptoService = Crypto.make({
|
|
11
|
+
digest: (algorithm, data) => Effect.tryPromise({
|
|
12
|
+
catch: (cause) => PlatformError.systemError({
|
|
13
|
+
_tag: "Unknown",
|
|
14
|
+
cause,
|
|
15
|
+
description: "Could not compute digest",
|
|
16
|
+
method: "digest",
|
|
17
|
+
module: "Crypto",
|
|
18
|
+
}),
|
|
19
|
+
try: () => globalThis.crypto.subtle
|
|
20
|
+
.digest(algorithm, new Uint8Array(data))
|
|
21
|
+
.then((digest) => new Uint8Array(digest)),
|
|
22
|
+
}),
|
|
23
|
+
randomBytes: (size) => {
|
|
24
|
+
const bytes = new Uint8Array(size);
|
|
25
|
+
for (let offset = 0; offset < size; offset += RANDOM_CHUNK_BYTES) {
|
|
26
|
+
globalThis.crypto.getRandomValues(bytes.subarray(offset, offset + RANDOM_CHUNK_BYTES));
|
|
27
|
+
}
|
|
28
|
+
return bytes;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
/** Computes the SHA-256 digest bytes of one byte sequence through Effect's Crypto service. */
|
|
32
|
+
export const digestSha256 = Effect.fn("AksaraContracts.digestSha256")(function* (bytes) {
|
|
33
|
+
const crypto = yield* Crypto.Crypto;
|
|
34
|
+
return yield* crypto.digest("SHA-256", bytes);
|
|
35
|
+
}, Effect.provideService(Crypto.Crypto, webCryptoService));
|
|
36
|
+
/** Computes the `sha256:` identity of one byte sequence, the form every stored hash uses. */
|
|
37
|
+
export const hashBytes = Effect.fn("AksaraContracts.hashBytes")(function* (bytes) {
|
|
38
|
+
const digest = yield* digestSha256(bytes);
|
|
39
|
+
return Sha256HashSchema.make(`sha256:${Hex.encode(digest)}`);
|
|
40
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collects the UTF-8 bytes of one digest stream so that Web Crypto can digest
|
|
3
|
+
* it in one call. Each piece is encoded on its own, exactly as an incremental
|
|
4
|
+
* hash encoded it, so a lone surrogate keeps the bytes it always had.
|
|
5
|
+
*/
|
|
6
|
+
export declare class DigestStream {
|
|
7
|
+
#private;
|
|
8
|
+
/** Appends one piece of text in the order the stream was built. */
|
|
9
|
+
add(text: string): void;
|
|
10
|
+
/** Digests every piece in order and returns the branded sha256 identity. */
|
|
11
|
+
digest(): import("effect/Effect").Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, import("effect/PlatformError").PlatformError, never>;
|
|
12
|
+
}
|