@nakafa/aksara-contracts 0.47.0 → 0.47.2
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/content.d.ts +8 -6
- package/dist/content.js +8 -3
- package/dist/math/arc.js +5 -1
- package/dist/math/base.js +6 -6
- package/dist/math/collision.d.ts +4 -4
- package/dist/math/collision.js +15 -9
- package/dist/math/coordinate.d.ts +24 -13
- package/dist/math/coordinate.js +16 -2
- package/dist/math/extent.d.ts +26 -17
- package/dist/math/extent.js +18 -2
- package/dist/math/intersection.d.ts +21 -11
- package/dist/math/intersection.js +14 -1
- package/dist/math/precision.js +3 -3
- package/dist/math/proximity.d.ts +11 -7
- package/dist/math/proximity.js +21 -4
- package/dist/math/rational.d.ts +6 -5
- package/dist/math/rational.js +6 -1
- package/dist/math/resolution.d.ts +1 -1
- package/dist/math/resolution.js +12 -4
- package/dist/math/scene.d.ts +22 -3
- package/dist/preview/auth.js +2 -1
- package/dist/preview/target.js +7 -0
- package/dist/program/curriculum.js +2 -1
- package/dist/program/snapshot/digest.js +32 -31
- package/dist/program/snapshot/hash.js +2 -1
- package/dist/program/spec.js +2 -1
- package/dist/projection/article.js +2 -1
- package/dist/projection/material.js +2 -1
- package/dist/projection/page.js +2 -1
- package/dist/projection/question.d.ts +544 -17
- package/dist/projection/question.js +17 -3
- package/dist/projection/verify.d.ts +4 -3
- package/dist/projection/verify.js +14 -7
- package/dist/question/answer.d.ts +12 -6
- package/dist/question/answer.js +17 -2
- package/dist/question/item.js +5 -4
- package/dist/question/response.js +3 -3
- package/dist/question/rubric.js +2 -1
- package/dist/quran/identity.js +11 -0
- package/dist/quran/notes.js +13 -0
- package/dist/quran/provenance.js +3 -2
- package/dist/quran/snapshot/digest.js +4 -3
- package/dist/quran/snapshot/hash.js +2 -1
- package/dist/quran/snapshot/row/hash.js +5 -4
- package/dist/quran/snapshot/spec.js +3 -2
- package/dist/release/canonical.js +2 -1
- package/dist/release/head.js +2 -1
- package/dist/release/items.d.ts +5 -4
- package/dist/release/items.js +14 -9
- package/dist/release/result/digest.js +4 -4
- package/dist/release/rollback/spec.js +6 -5
- package/dist/release/route/spec.js +4 -3
- package/dist/release/route/verify.d.ts +4 -3
- package/dist/release/route/verify.js +9 -6
- package/dist/release/signing.js +2 -1
- package/dist/release/snapshot/data.js +3 -2
- package/dist/release/snapshot/evidence/tryout.js +6 -1
- package/dist/release/snapshot/spec.js +7 -6
- package/dist/release/snapshot/verify.d.ts +27 -4
- package/dist/release/snapshot/verify.js +13 -9
- package/dist/renderer/compatibility.js +8 -5
- package/dist/renderer/contract.js +5 -4
- package/dist/runtime/protected/limits.js +2 -1
- package/dist/runtime/protected/spec.js +3 -3
- package/dist/text/json.d.ts +5 -0
- package/dist/text/json.js +5 -0
- package/dist/transport/request.d.ts +108 -108
- package/dist/tryout/closure/accounting.d.ts +5 -3
- package/dist/tryout/closure/accounting.js +12 -10
- package/dist/tryout/closure/locale.js +32 -24
- package/dist/tryout/closure/placement.js +3 -2
- package/dist/tryout/hash/catalog.js +11 -10
- package/dist/tryout/hash/content.js +2 -1
- package/dist/tryout/hash/placement.js +2 -1
- package/dist/tryout/language.js +2 -4
- package/dist/tryout/runtime/canonical.js +2 -1
- package/dist/tryout/scoring.d.ts +13 -9
- package/dist/tryout/scoring.js +17 -8
- package/dist/tryout/snapshot/canonical.js +2 -1
- package/dist/tryout/snapshot/hash.js +2 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Effect, MutableHashMap, MutableHashSet, Option, Schema } from "effect";
|
|
2
|
+
import { encodeJsonText } from "#contracts/text/json";
|
|
2
3
|
/** A try-out snapshot is incomplete or inconsistent across app locales. */
|
|
3
4
|
export class TryoutClosureError extends Schema.TaggedError()("TryoutClosureError", {
|
|
4
5
|
actual: Schema.String,
|
|
@@ -17,7 +18,7 @@ export class TryoutClosureError extends Schema.TaggedError()("TryoutClosureError
|
|
|
17
18
|
}
|
|
18
19
|
/** Serializes locale sets through the active list's signed canonical order. */
|
|
19
20
|
function localeSetIdentity(locales, activeAppLocales) {
|
|
20
|
-
return
|
|
21
|
+
return encodeJsonText(activeAppLocales.filter((locale) => MutableHashSet.has(locales, locale)));
|
|
21
22
|
}
|
|
22
23
|
/** Adds one active locale to a logical identity without duplicates. */
|
|
23
24
|
export function addLocale(localesByIdentity, activeAppLocales, identity, appLocale) {
|
|
@@ -25,12 +26,13 @@ export function addLocale(localesByIdentity, activeAppLocales, identity, appLoca
|
|
|
25
26
|
return Effect.fail(new TryoutClosureError({
|
|
26
27
|
actual: appLocale,
|
|
27
28
|
code: "inactive-locale",
|
|
28
|
-
expected:
|
|
29
|
+
expected: encodeJsonText(activeAppLocales),
|
|
29
30
|
identity,
|
|
30
31
|
}));
|
|
31
32
|
}
|
|
32
|
-
const locales =
|
|
33
|
-
|
|
33
|
+
const locales = Option.getOrUndefined(MutableHashMap.get(localesByIdentity, identity)) ??
|
|
34
|
+
MutableHashSet.empty();
|
|
35
|
+
if (MutableHashSet.has(locales, appLocale)) {
|
|
34
36
|
return Effect.fail(new TryoutClosureError({
|
|
35
37
|
actual: appLocale,
|
|
36
38
|
code: "duplicate-locale",
|
|
@@ -38,23 +40,23 @@ export function addLocale(localesByIdentity, activeAppLocales, identity, appLoca
|
|
|
38
40
|
identity,
|
|
39
41
|
}));
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
MutableHashSet.add(locales, appLocale);
|
|
44
|
+
MutableHashMap.set(localesByIdentity, identity, locales);
|
|
43
45
|
return Effect.void;
|
|
44
46
|
}
|
|
45
47
|
/** Confirms every logical row closes over the exact active locale list. */
|
|
46
48
|
export function validateLocales(localesByIdentity, activeAppLocales) {
|
|
47
|
-
if (
|
|
49
|
+
if (MutableHashMap.size(localesByIdentity) === 0) {
|
|
48
50
|
return Effect.fail(new TryoutClosureError({
|
|
49
51
|
actual: "[]",
|
|
50
52
|
code: "missing-locale",
|
|
51
|
-
expected:
|
|
53
|
+
expected: encodeJsonText(activeAppLocales),
|
|
52
54
|
identity: "empty",
|
|
53
55
|
}));
|
|
54
56
|
}
|
|
55
57
|
return Effect.forEach(localesByIdentity, ([identity, locales]) => {
|
|
56
58
|
const actual = localeSetIdentity(locales, activeAppLocales);
|
|
57
|
-
const expected =
|
|
59
|
+
const expected = encodeJsonText(activeAppLocales);
|
|
58
60
|
if (actual === expected) {
|
|
59
61
|
return Effect.void;
|
|
60
62
|
}
|
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
import { Effect, Stream } from "effect";
|
|
1
|
+
import { Effect, MutableHashMap, Option, Stream, } from "effect";
|
|
2
2
|
import { addLocale, TryoutClosureError, validateLocales, } from "#contracts/tryout/closure/accounting";
|
|
3
3
|
import { canonicalizeAssessedLanguagePlacementFacts, canonicalizeLocaleNeutralPlacementFacts, } from "#contracts/tryout/closure/placement";
|
|
4
4
|
import { canonicalizeTryoutCatalogFacts, tryoutCatalogLogicalIdentity, tryoutSectionLogicalIdentity, } from "#contracts/tryout/hash/catalog";
|
|
5
5
|
import { tryoutPlacementLogicalIdentity } from "#contracts/tryout/identity";
|
|
6
6
|
import { makeTryoutScoringFacts, recordTryoutScoringFacts, validateTryoutPlacementScoring, validateTryoutScoringFacts, } from "#contracts/tryout/scoring";
|
|
7
|
+
/** Creates the catalog facts that one stream of catalog rows shares while it folds. */
|
|
8
|
+
function catalogClosureState() {
|
|
9
|
+
return {
|
|
10
|
+
factsByIdentity: MutableHashMap.empty(),
|
|
11
|
+
localesByIdentity: MutableHashMap.empty(),
|
|
12
|
+
scoring: makeTryoutScoringFacts(),
|
|
13
|
+
sections: MutableHashMap.empty(),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** Creates the placement facts that one stream of placements shares while it folds. */
|
|
17
|
+
function placementClosureState() {
|
|
18
|
+
return {
|
|
19
|
+
assessedFacts: MutableHashMap.empty(),
|
|
20
|
+
countsBySectionLocale: MutableHashMap.empty(),
|
|
21
|
+
factsByIdentity: MutableHashMap.empty(),
|
|
22
|
+
localesByIdentity: MutableHashMap.empty(),
|
|
23
|
+
};
|
|
24
|
+
}
|
|
7
25
|
/** Adds one catalog row and compares its locale-neutral facts. */
|
|
8
26
|
function addCatalogRow(state, activeAppLocales, row) {
|
|
9
27
|
const identity = tryoutCatalogLogicalIdentity(row);
|
|
10
28
|
const facts = canonicalizeTryoutCatalogFacts(row);
|
|
11
|
-
const expectedFacts =
|
|
29
|
+
const expectedFacts = Option.getOrUndefined(MutableHashMap.get(state.factsByIdentity, identity));
|
|
12
30
|
if (expectedFacts !== undefined && expectedFacts !== facts) {
|
|
13
31
|
return Effect.fail(new TryoutClosureError({
|
|
14
32
|
actual: facts,
|
|
@@ -17,10 +35,10 @@ function addCatalogRow(state, activeAppLocales, row) {
|
|
|
17
35
|
identity,
|
|
18
36
|
}));
|
|
19
37
|
}
|
|
20
|
-
state.factsByIdentity
|
|
38
|
+
MutableHashMap.set(state.factsByIdentity, identity, facts);
|
|
21
39
|
recordTryoutScoringFacts(state.scoring, row);
|
|
22
40
|
if (row.kind === "section") {
|
|
23
|
-
state.sections
|
|
41
|
+
MutableHashMap.set(state.sections, identity, row.questionCount);
|
|
24
42
|
}
|
|
25
43
|
return addLocale(state.localesByIdentity, activeAppLocales, identity, row.appLocale).pipe(Effect.as(state));
|
|
26
44
|
}
|
|
@@ -28,7 +46,7 @@ function addCatalogRow(state, activeAppLocales, row) {
|
|
|
28
46
|
function addPlacement(state, catalog, activeAppLocales, row) {
|
|
29
47
|
const identity = tryoutPlacementLogicalIdentity(row);
|
|
30
48
|
const sectionIdentity = tryoutSectionLogicalIdentity(row);
|
|
31
|
-
if (!catalog.sections
|
|
49
|
+
if (!MutableHashMap.has(catalog.sections, sectionIdentity)) {
|
|
32
50
|
return Effect.fail(new TryoutClosureError({
|
|
33
51
|
actual: "missing",
|
|
34
52
|
code: "missing-section",
|
|
@@ -37,7 +55,7 @@ function addPlacement(state, catalog, activeAppLocales, row) {
|
|
|
37
55
|
}));
|
|
38
56
|
}
|
|
39
57
|
const facts = canonicalizeLocaleNeutralPlacementFacts(row);
|
|
40
|
-
const expectedFacts =
|
|
58
|
+
const expectedFacts = Option.getOrUndefined(MutableHashMap.get(state.factsByIdentity, identity));
|
|
41
59
|
if (expectedFacts !== undefined && expectedFacts !== facts) {
|
|
42
60
|
return Effect.fail(new TryoutClosureError({
|
|
43
61
|
actual: facts,
|
|
@@ -46,10 +64,10 @@ function addPlacement(state, catalog, activeAppLocales, row) {
|
|
|
46
64
|
identity,
|
|
47
65
|
}));
|
|
48
66
|
}
|
|
49
|
-
state.factsByIdentity
|
|
67
|
+
MutableHashMap.set(state.factsByIdentity, identity, facts);
|
|
50
68
|
if (row.languagePolicy.kind === "fixed") {
|
|
51
69
|
const assessedFacts = canonicalizeAssessedLanguagePlacementFacts(row);
|
|
52
|
-
const expectedAssessedFacts =
|
|
70
|
+
const expectedAssessedFacts = Option.getOrUndefined(MutableHashMap.get(state.assessedFacts, identity));
|
|
53
71
|
if (expectedAssessedFacts !== undefined &&
|
|
54
72
|
expectedAssessedFacts !== assessedFacts) {
|
|
55
73
|
return Effect.fail(new TryoutClosureError({
|
|
@@ -59,17 +77,17 @@ function addPlacement(state, catalog, activeAppLocales, row) {
|
|
|
59
77
|
identity,
|
|
60
78
|
}));
|
|
61
79
|
}
|
|
62
|
-
state.assessedFacts
|
|
80
|
+
MutableHashMap.set(state.assessedFacts, identity, assessedFacts);
|
|
63
81
|
}
|
|
64
82
|
const sectionLocaleIdentity = `${sectionIdentity}\0${row.appLocale}`;
|
|
65
|
-
|
|
83
|
+
const count = Option.getOrElse(MutableHashMap.get(state.countsBySectionLocale, sectionLocaleIdentity), () => 0);
|
|
84
|
+
MutableHashMap.set(state.countsBySectionLocale, sectionLocaleIdentity, count + 1);
|
|
66
85
|
return validateTryoutPlacementScoring(catalog.scoring, row).pipe(Effect.andThen(addLocale(state.localesByIdentity, activeAppLocales, identity, row.appLocale)), Effect.as(state));
|
|
67
86
|
}
|
|
68
87
|
/** Confirms each localized section owns its declared question inventory. */
|
|
69
88
|
function validateQuestionCounts(catalog, placements, activeAppLocales) {
|
|
70
89
|
return Effect.forEach(catalog.sections, ([identity, questionCount]) => Effect.forEach(activeAppLocales, (appLocale) => {
|
|
71
|
-
const actual =
|
|
72
|
-
0;
|
|
90
|
+
const actual = Option.getOrElse(MutableHashMap.get(placements.countsBySectionLocale, `${identity}\0${appLocale}`), () => 0);
|
|
73
91
|
if (actual === questionCount) {
|
|
74
92
|
return Effect.void;
|
|
75
93
|
}
|
|
@@ -86,20 +104,10 @@ function validateQuestionCounts(catalog, placements, activeAppLocales) {
|
|
|
86
104
|
* locales in one pass over each stream.
|
|
87
105
|
*/
|
|
88
106
|
export const verifyTryoutLocaleClosure = Effect.fn("AksaraContracts.verifyTryoutLocaleClosure")(function* (input) {
|
|
89
|
-
const catalog = yield* input.catalog.pipe(Stream.runFoldEffect(() => (
|
|
90
|
-
factsByIdentity: new Map(),
|
|
91
|
-
localesByIdentity: new Map(),
|
|
92
|
-
scoring: makeTryoutScoringFacts(),
|
|
93
|
-
sections: new Map(),
|
|
94
|
-
}), (state, record) => addCatalogRow(state, input.activeAppLocales, record.row)));
|
|
107
|
+
const catalog = yield* input.catalog.pipe(Stream.runFoldEffect(catalogClosureState, (state, record) => addCatalogRow(state, input.activeAppLocales, record.row)));
|
|
95
108
|
yield* validateLocales(catalog.localesByIdentity, input.activeAppLocales);
|
|
96
109
|
yield* validateTryoutScoringFacts(catalog.scoring);
|
|
97
|
-
const placements = yield* input.placements.pipe(Stream.runFoldEffect(() => (
|
|
98
|
-
assessedFacts: new Map(),
|
|
99
|
-
countsBySectionLocale: new Map(),
|
|
100
|
-
factsByIdentity: new Map(),
|
|
101
|
-
localesByIdentity: new Map(),
|
|
102
|
-
}), (state, record) => addPlacement(state, catalog, input.activeAppLocales, record.row)));
|
|
110
|
+
const placements = yield* input.placements.pipe(Stream.runFoldEffect(placementClosureState, (state, record) => addPlacement(state, catalog, input.activeAppLocales, record.row)));
|
|
103
111
|
yield* validateLocales(placements.localesByIdentity, input.activeAppLocales);
|
|
104
112
|
yield* validateQuestionCounts(catalog, placements, input.activeAppLocales);
|
|
105
113
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { canonicalQuestionBlueprint } from "#contracts/question/item";
|
|
2
2
|
import { canonicalQuestionResponse, canonicalQuestionResponseStructure, } from "#contracts/question/response";
|
|
3
|
+
import { encodeJsonText } from "#contracts/text/json";
|
|
3
4
|
import { canonicalAssessmentLanguagePolicy } from "#contracts/tryout/language";
|
|
4
5
|
/** Serializes assessed prompt facts reused across application locales. */
|
|
5
6
|
export function canonicalizeAssessedLanguagePlacementFacts(row) {
|
|
6
|
-
return
|
|
7
|
+
return encodeJsonText({
|
|
7
8
|
deliveryLanguage: row.deliveryLanguage,
|
|
8
9
|
questionArtifactHash: row.questionArtifactHash,
|
|
9
10
|
questionArtifactLocale: row.questionArtifactLocale,
|
|
@@ -13,7 +14,7 @@ export function canonicalizeAssessedLanguagePlacementFacts(row) {
|
|
|
13
14
|
}
|
|
14
15
|
/** Serializes placement facts that cannot vary with application locale. */
|
|
15
16
|
export function canonicalizeLocaleNeutralPlacementFacts(row) {
|
|
16
|
-
return
|
|
17
|
+
return encodeJsonText({
|
|
17
18
|
answerContentKey: row.answerContentKey,
|
|
18
19
|
...(row.blueprint === undefined
|
|
19
20
|
? {}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Effect } from "effect";
|
|
2
2
|
import { canonicalizeLearningGraphIdentity } from "#contracts/graph/spec";
|
|
3
|
+
import { encodeJsonText } from "#contracts/text/json";
|
|
3
4
|
import { compareCodeUnits } from "#contracts/text/order";
|
|
4
5
|
import { hashTryoutCanonical } from "#contracts/tryout/canonical";
|
|
5
6
|
import { TryoutCatalogRecordSchema, } from "#contracts/tryout/catalog";
|
|
@@ -52,14 +53,14 @@ export function canonicalizeTryoutCatalogFacts(row) {
|
|
|
52
53
|
sourceRevision: row.sourceRevision,
|
|
53
54
|
};
|
|
54
55
|
if (row.kind === "country") {
|
|
55
|
-
return
|
|
56
|
+
return encodeJsonText({
|
|
56
57
|
...shared,
|
|
57
58
|
countryCode: row.countryCode,
|
|
58
59
|
countryKey: row.countryKey,
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
if (row.kind === "exam") {
|
|
62
|
-
return
|
|
63
|
+
return encodeJsonText({
|
|
63
64
|
...shared,
|
|
64
65
|
countryKey: row.countryKey,
|
|
65
66
|
examKey: row.examKey,
|
|
@@ -67,7 +68,7 @@ export function canonicalizeTryoutCatalogFacts(row) {
|
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
if (row.kind === "track") {
|
|
70
|
-
return
|
|
71
|
+
return encodeJsonText({
|
|
71
72
|
...shared,
|
|
72
73
|
countryKey: row.countryKey,
|
|
73
74
|
examKey: row.examKey,
|
|
@@ -80,7 +81,7 @@ export function canonicalizeTryoutCatalogFacts(row) {
|
|
|
80
81
|
});
|
|
81
82
|
}
|
|
82
83
|
if (row.kind === "set") {
|
|
83
|
-
return
|
|
84
|
+
return encodeJsonText({
|
|
84
85
|
...shared,
|
|
85
86
|
countryKey: row.countryKey,
|
|
86
87
|
examKey: row.examKey,
|
|
@@ -93,7 +94,7 @@ export function canonicalizeTryoutCatalogFacts(row) {
|
|
|
93
94
|
visibleSectionCount: row.visibleSectionCount,
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
|
-
return
|
|
97
|
+
return encodeJsonText({
|
|
97
98
|
...shared,
|
|
98
99
|
countryKey: row.countryKey,
|
|
99
100
|
examKey: row.examKey,
|
|
@@ -119,7 +120,7 @@ export function canonicalizeTryoutCatalog(row) {
|
|
|
119
120
|
title: row.title,
|
|
120
121
|
};
|
|
121
122
|
if (row.kind === "country") {
|
|
122
|
-
return
|
|
123
|
+
return encodeJsonText({
|
|
123
124
|
...localized,
|
|
124
125
|
countryCode: row.countryCode,
|
|
125
126
|
countryKey: row.countryKey,
|
|
@@ -129,7 +130,7 @@ export function canonicalizeTryoutCatalog(row) {
|
|
|
129
130
|
});
|
|
130
131
|
}
|
|
131
132
|
if (row.kind === "exam") {
|
|
132
|
-
return
|
|
133
|
+
return encodeJsonText({
|
|
133
134
|
...localized,
|
|
134
135
|
countryKey: row.countryKey,
|
|
135
136
|
examKey: row.examKey,
|
|
@@ -140,7 +141,7 @@ export function canonicalizeTryoutCatalog(row) {
|
|
|
140
141
|
});
|
|
141
142
|
}
|
|
142
143
|
if (row.kind === "track") {
|
|
143
|
-
return
|
|
144
|
+
return encodeJsonText({
|
|
144
145
|
...localized,
|
|
145
146
|
countryKey: row.countryKey,
|
|
146
147
|
examKey: row.examKey,
|
|
@@ -156,7 +157,7 @@ export function canonicalizeTryoutCatalog(row) {
|
|
|
156
157
|
});
|
|
157
158
|
}
|
|
158
159
|
if (row.kind === "set") {
|
|
159
|
-
return
|
|
160
|
+
return encodeJsonText({
|
|
160
161
|
...localized,
|
|
161
162
|
countryKey: row.countryKey,
|
|
162
163
|
examKey: row.examKey,
|
|
@@ -172,7 +173,7 @@ export function canonicalizeTryoutCatalog(row) {
|
|
|
172
173
|
visibleSectionCount: row.visibleSectionCount,
|
|
173
174
|
});
|
|
174
175
|
}
|
|
175
|
-
return
|
|
176
|
+
return encodeJsonText({
|
|
176
177
|
...localized,
|
|
177
178
|
countryKey: row.countryKey,
|
|
178
179
|
examKey: row.examKey,
|
|
@@ -5,6 +5,7 @@ import { AppLocaleSchema, ArtifactLocaleSchema, DeliveryLanguageSchema, } from "
|
|
|
5
5
|
import { QuestionKeySchema } from "#contracts/question/identity";
|
|
6
6
|
import { canonicalQuestionBlueprint, QuestionBlueprintSchema, } from "#contracts/question/item";
|
|
7
7
|
import { canonicalQuestionResponse, QuestionResponseSchema, } from "#contracts/question/response";
|
|
8
|
+
import { encodeJsonText } from "#contracts/text/json";
|
|
8
9
|
import { TryoutKeySchema } from "#contracts/tryout/key";
|
|
9
10
|
import { AssessmentLanguagePolicySchema, canonicalAssessmentLanguagePolicy, } from "#contracts/tryout/language";
|
|
10
11
|
import { TryoutContentHashSchema, TryoutSourceRevisionSchema, } from "#contracts/tryout/spec";
|
|
@@ -40,7 +41,7 @@ function dateEpoch(date) {
|
|
|
40
41
|
}
|
|
41
42
|
/** Serializes every current question-pair identity field in stable order. */
|
|
42
43
|
export function canonicalizeTryoutContent(input) {
|
|
43
|
-
return
|
|
44
|
+
return encodeJsonText({
|
|
44
45
|
answerArtifactLocale: input.answerArtifactLocale,
|
|
45
46
|
answerBody: normalizeBody(input.answerBody),
|
|
46
47
|
appLocale: input.appLocale,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { canonicalQuestionBlueprint } from "#contracts/question/item";
|
|
2
2
|
import { canonicalQuestionResponse } from "#contracts/question/response";
|
|
3
|
+
import { encodeJsonText } from "#contracts/text/json";
|
|
3
4
|
import { hashTryoutCanonical } from "#contracts/tryout/canonical";
|
|
4
5
|
import { digestTryoutRecords } from "#contracts/tryout/digest";
|
|
5
6
|
import { tryoutPlacementIdentity } from "#contracts/tryout/identity";
|
|
@@ -8,7 +9,7 @@ import { TryoutPlacementRecordSchema, } from "#contracts/tryout/placement";
|
|
|
8
9
|
const PLACEMENT_DOMAIN = "nakafa.aksara.tryout-placements";
|
|
9
10
|
/** Serializes one artifact-bound placement with stable field order. */
|
|
10
11
|
export function canonicalizeTryoutPlacement(row) {
|
|
11
|
-
return
|
|
12
|
+
return encodeJsonText({
|
|
12
13
|
answerArtifactHash: row.answerArtifactHash,
|
|
13
14
|
answerArtifactLocale: row.answerArtifactLocale,
|
|
14
15
|
answerContentKey: row.answerContentKey,
|
package/dist/tryout/language.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ACTIVE_APP_LOCALES, ArtifactLocaleSchema, DeliveryLanguageSchema, } from "#contracts/locale";
|
|
3
3
|
/** Source-owned policy for the language presented by one assessment section. */
|
|
4
4
|
export const AssessmentLanguagePolicySchema = Schema.Union([
|
|
@@ -20,9 +20,7 @@ export function questionArtifactLocaleForPolicy(policy, appLocale) {
|
|
|
20
20
|
}
|
|
21
21
|
/** Lists unique prompt and response locales required by one section policy. */
|
|
22
22
|
export function questionArtifactLocalesForPolicy(policy) {
|
|
23
|
-
return Object.freeze(
|
|
24
|
-
...new Set(ACTIVE_APP_LOCALES.map((appLocale) => questionArtifactLocaleForPolicy(policy, appLocale))),
|
|
25
|
-
]);
|
|
23
|
+
return Object.freeze(Arr.dedupe(ACTIVE_APP_LOCALES.map((appLocale) => questionArtifactLocaleForPolicy(policy, appLocale))));
|
|
26
24
|
}
|
|
27
25
|
/** Returns policy facts in stable field order for signed canonicalizers. */
|
|
28
26
|
export function canonicalAssessmentLanguagePolicy(policy) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { encodeJsonText } from "#contracts/text/json";
|
|
1
2
|
import { TRYOUT_RUNTIME_BUNDLE_FORMAT } from "#contracts/tryout/runtime/spec";
|
|
2
3
|
/** Ed25519 domain separating runtime bundles from every other signed object. */
|
|
3
4
|
export const TRYOUT_RUNTIME_BUNDLE_SIGNATURE_DOMAIN = "nakafa.aksara.tryout-runtime-bundle";
|
|
4
5
|
/** Serializes one complete runtime payload with stable signed field order. */
|
|
5
6
|
export function canonicalizeTryoutRuntimeBundlePayload(payload) {
|
|
6
|
-
return
|
|
7
|
+
return encodeJsonText({
|
|
7
8
|
format: TRYOUT_RUNTIME_BUNDLE_FORMAT,
|
|
8
9
|
rendererManifestHash: payload.rendererManifestHash,
|
|
9
10
|
snapshot: {
|
package/dist/tryout/scoring.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Effect, MutableHashMap, Schema } from "effect";
|
|
2
2
|
import type { TryoutCatalogRow, TryoutSection, TryoutSet } from "#contracts/tryout/catalog";
|
|
3
3
|
import type { TryoutPlacement } from "#contracts/tryout/placement";
|
|
4
4
|
import type { TryoutScoring } from "#contracts/tryout/spec";
|
|
@@ -14,21 +14,25 @@ declare const TryoutScoringError_base: Schema.Class<TryoutScoringError, Schema.T
|
|
|
14
14
|
*/
|
|
15
15
|
export declare class TryoutScoringError extends TryoutScoringError_base {
|
|
16
16
|
}
|
|
17
|
-
/** Exam strategies, sets, and sections gathered while a catalog is read. */
|
|
18
|
-
export interface TryoutScoringFacts {
|
|
19
|
-
readonly exams: Map<string, TryoutScoring>;
|
|
20
|
-
readonly sections: TryoutSection[];
|
|
21
|
-
readonly sets: Map<string, TryoutSet>;
|
|
22
|
-
}
|
|
23
17
|
/** Creates empty scoring facts for one snapshot verification pass. */
|
|
24
|
-
export declare function makeTryoutScoringFacts():
|
|
18
|
+
export declare function makeTryoutScoringFacts(): {
|
|
19
|
+
readonly exams: MutableHashMap.MutableHashMap<string, TryoutScoring>;
|
|
20
|
+
readonly sections: TryoutSection[];
|
|
21
|
+
readonly sets: MutableHashMap.MutableHashMap<string, TryoutSet>;
|
|
22
|
+
};
|
|
23
|
+
/** Exam strategies, sets, and sections gathered while a catalog is read. */
|
|
24
|
+
export type TryoutScoringFacts = ReturnType<typeof makeTryoutScoringFacts>;
|
|
25
25
|
/** Records the scoring facts carried by one localized catalog row. */
|
|
26
26
|
export declare function recordTryoutScoringFacts(facts: TryoutScoringFacts, row: TryoutCatalogRow): void;
|
|
27
27
|
/**
|
|
28
28
|
* Requires every set to repeat its exam's strategy and marks on exactly the
|
|
29
29
|
* sections of penalized sets, once the complete catalog has been recorded.
|
|
30
30
|
*/
|
|
31
|
-
export declare const validateTryoutScoringFacts: (facts:
|
|
31
|
+
export declare const validateTryoutScoringFacts: (facts: {
|
|
32
|
+
readonly exams: MutableHashMap.MutableHashMap<string, TryoutScoring>;
|
|
33
|
+
readonly sections: TryoutSection[];
|
|
34
|
+
readonly sets: MutableHashMap.MutableHashMap<string, TryoutSet>;
|
|
35
|
+
}) => Effect.Effect<void, TryoutScoringError, never>;
|
|
32
36
|
/**
|
|
33
37
|
* Requires one rubric placement to belong to a raw-scored set, because a
|
|
34
38
|
* rubric awards points per criterion instead of a correct or wrong outcome.
|
package/dist/tryout/scoring.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Effect, MutableHashMap, Option, Schema } from "effect";
|
|
2
2
|
import { tryoutCatalogIdentity, tryoutCatalogNodeIdentity, tryoutPlacementIdentity, } from "#contracts/tryout/identity";
|
|
3
3
|
/**
|
|
4
4
|
* A signed try-out row cannot be scored as published. `strategy` means a set
|
|
@@ -13,21 +13,28 @@ export class TryoutScoringError extends Schema.TaggedError()("TryoutScoringError
|
|
|
13
13
|
}
|
|
14
14
|
/** Creates empty scoring facts for one snapshot verification pass. */
|
|
15
15
|
export function makeTryoutScoringFacts() {
|
|
16
|
-
return {
|
|
16
|
+
return {
|
|
17
|
+
exams: MutableHashMap.empty(),
|
|
18
|
+
sections: [],
|
|
19
|
+
sets: MutableHashMap.empty(),
|
|
20
|
+
};
|
|
17
21
|
}
|
|
18
22
|
/** Records the scoring facts carried by one localized catalog row. */
|
|
19
23
|
export function recordTryoutScoringFacts(facts, row) {
|
|
20
24
|
if (row.kind === "exam") {
|
|
21
|
-
facts.exams
|
|
25
|
+
MutableHashMap.set(facts.exams, tryoutCatalogIdentity(row), row.scoringStrategy);
|
|
22
26
|
}
|
|
23
27
|
if (row.kind === "set") {
|
|
24
|
-
facts.sets
|
|
28
|
+
MutableHashMap.set(facts.sets, tryoutCatalogIdentity(row), row);
|
|
25
29
|
}
|
|
26
30
|
if (row.kind === "section") {
|
|
27
31
|
facts.sections.push(row);
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Returns the strategy of the set that owns one section or placement. The row
|
|
36
|
+
* is a locale-specific set reference shared by sections and placements.
|
|
37
|
+
*/
|
|
31
38
|
function setStrategy(facts, row) {
|
|
32
39
|
const identity = tryoutCatalogNodeIdentity({
|
|
33
40
|
appLocale: row.appLocale,
|
|
@@ -37,7 +44,8 @@ function setStrategy(facts, row) {
|
|
|
37
44
|
setKey: row.setKey,
|
|
38
45
|
trackKey: row.trackKey,
|
|
39
46
|
});
|
|
40
|
-
return
|
|
47
|
+
return Option.getOrUndefined(MutableHashMap.get(facts.sets, identity))
|
|
48
|
+
?.scoringStrategy;
|
|
41
49
|
}
|
|
42
50
|
/** Requires one set to score with the strategy its exam declares. */
|
|
43
51
|
function validateSetStrategy(facts, row) {
|
|
@@ -47,7 +55,8 @@ function validateSetStrategy(facts, row) {
|
|
|
47
55
|
examKey: row.examKey,
|
|
48
56
|
kind: "exam",
|
|
49
57
|
});
|
|
50
|
-
if (
|
|
58
|
+
if (Option.getOrUndefined(MutableHashMap.get(facts.exams, exam)) ===
|
|
59
|
+
row.scoringStrategy) {
|
|
51
60
|
return Effect.void;
|
|
52
61
|
}
|
|
53
62
|
return Effect.fail(new TryoutScoringError({
|
|
@@ -71,7 +80,7 @@ function validateSectionMarks(facts, row) {
|
|
|
71
80
|
* sections of penalized sets, once the complete catalog has been recorded.
|
|
72
81
|
*/
|
|
73
82
|
export const validateTryoutScoringFacts = Effect.fn("AksaraContracts.validateTryoutScoringFacts")(function* (facts) {
|
|
74
|
-
yield* Effect.forEach(facts.sets
|
|
83
|
+
yield* Effect.forEach(MutableHashMap.values(facts.sets), (row) => validateSetStrategy(facts, row), { discard: true });
|
|
75
84
|
yield* Effect.forEach(facts.sections, (row) => validateSectionMarks(facts, row), { discard: true });
|
|
76
85
|
});
|
|
77
86
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { encodeJsonText } from "#contracts/text/json";
|
|
1
2
|
import { TRYOUT_SNAPSHOT_FORMAT } from "#contracts/tryout/snapshot/spec";
|
|
2
3
|
/** Domain separating snapshot identities from every other try-out digest. */
|
|
3
4
|
export const TRYOUT_SNAPSHOT_DOMAIN = "nakafa.aksara.localized-tryout-snapshot";
|
|
@@ -5,7 +6,7 @@ export const TRYOUT_SNAPSHOT_DOMAIN = "nakafa.aksara.localized-tryout-snapshot";
|
|
|
5
6
|
export const TRYOUT_SNAPSHOT_ROWS_DOMAIN = "nakafa.aksara.tryout-rows";
|
|
6
7
|
/** Serializes snapshot facts without content-addressed identity. */
|
|
7
8
|
export function canonicalizeTryoutSnapshot(input) {
|
|
8
|
-
return
|
|
9
|
+
return encodeJsonText({
|
|
9
10
|
activeAppLocales: input.activeAppLocales,
|
|
10
11
|
catalogDigest: input.catalogDigest,
|
|
11
12
|
counts: input.counts,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Record as Rec } from "effect";
|
|
1
2
|
import { hashTryoutCanonical } from "#contracts/tryout/canonical";
|
|
2
3
|
import { canonicalizeTryoutSnapshot, TRYOUT_SNAPSHOT_DOMAIN, TRYOUT_SNAPSHOT_ROWS_DOMAIN, } from "#contracts/tryout/snapshot/canonical";
|
|
3
4
|
import { TRYOUT_SNAPSHOT_FORMAT, TryoutSnapshotSchema, } from "#contracts/tryout/snapshot/spec";
|
|
@@ -12,7 +13,7 @@ export function makeTryoutSnapshot(input) {
|
|
|
12
13
|
/** Returns exact structured row evidence authenticated by a snapshot. */
|
|
13
14
|
export function tryoutSnapshotRowEvidence(input) {
|
|
14
15
|
return {
|
|
15
|
-
rowCount:
|
|
16
|
+
rowCount: Rec.values(input.counts).reduce((total, count) => total + count, 0) +
|
|
16
17
|
input.placementCount,
|
|
17
18
|
rowDigest: hashTryoutCanonical(TRYOUT_SNAPSHOT_ROWS_DOMAIN, `${input.catalogDigest}\n${input.placementDigest}`),
|
|
18
19
|
};
|
package/package.json
CHANGED