@nakafa/aksara-contracts 0.48.0 → 0.48.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/canonical.d.ts +5 -0
- package/dist/canonical.js +10 -0
- package/dist/graph/identity.js +2 -2
- package/dist/locale.js +2 -9
- package/dist/math/arc.js +3 -3
- package/dist/math/base.js +11 -11
- package/dist/math/bounds.d.ts +1 -1
- package/dist/math/bounds.js +13 -12
- package/dist/math/collision.js +21 -23
- package/dist/math/coordinate.js +3 -3
- package/dist/math/extent.js +10 -14
- package/dist/math/plane.js +6 -6
- package/dist/math/precision.js +7 -10
- package/dist/math/proximity.js +17 -14
- package/dist/math/resolution.js +6 -6
- package/dist/math/scene.js +8 -8
- package/dist/math/vector.js +16 -18
- package/dist/math/visual.js +2 -2
- package/dist/preview/target.js +5 -5
- package/dist/program/curriculum.js +3 -3
- package/dist/program/snapshot/digest.js +13 -13
- package/dist/program/spec.js +5 -9
- package/dist/projection/article.js +3 -3
- package/dist/projection/material.js +2 -2
- package/dist/projection/question.js +2 -2
- package/dist/question/answer.js +3 -3
- package/dist/question/identity.js +9 -7
- package/dist/question/item.js +10 -10
- package/dist/question/response.js +12 -12
- package/dist/question/rubric.js +9 -9
- package/dist/quran/attribution.d.ts +12 -4
- package/dist/quran/attribution.js +2 -1
- package/dist/quran/notes.js +24 -17
- package/dist/quran/provenance.js +14 -13
- package/dist/quran/snapshot/digest.js +27 -18
- package/dist/quran/snapshot/row/hash.js +6 -6
- package/dist/quran/snapshot/row.js +4 -8
- package/dist/quran/snapshot/spec.js +2 -2
- package/dist/quran/source.js +12 -16
- package/dist/release/current/evidence.js +2 -2
- package/dist/release/head.js +2 -2
- package/dist/release/items.js +2 -2
- package/dist/release/policy.js +8 -8
- package/dist/release/rollback/spec.js +8 -9
- package/dist/release/route/page.js +6 -6
- package/dist/release/snapshot/scope.js +3 -14
- package/dist/release/snapshot/spec.js +6 -5
- package/dist/release/spec.js +2 -2
- package/dist/renderer/compatibility.js +3 -3
- package/dist/renderer/component.js +2 -2
- package/dist/renderer/contract.js +9 -10
- package/dist/renderer/manifest.js +3 -4
- package/dist/runtime/protected/spec.js +3 -3
- package/dist/runtime/verify.js +2 -2
- package/dist/signature/trusted.js +3 -3
- package/dist/signature/verify.js +9 -14
- package/dist/transport/batch.js +3 -3
- package/dist/transport/group.js +2 -2
- package/dist/transport/snapshot.js +2 -2
- package/dist/tryout/closure/accounting.js +3 -3
- package/dist/tryout/hash/catalog.js +5 -5
- package/dist/tryout/identity.js +7 -6
- package/dist/tryout/language.d.ts +1 -1
- package/dist/tryout/language.js +1 -1
- package/dist/tryout/scoring.d.ts +3 -3
- package/dist/tryout/scoring.js +4 -4
- package/dist/tryout/snapshot/hash.js +2 -2
- package/package.json +1 -1
package/dist/math/vector.js
CHANGED
|
@@ -1,41 +1,39 @@
|
|
|
1
|
+
import { Array as Arr } from "effect";
|
|
1
2
|
import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
|
|
2
3
|
/** Checks a space polygon is planar and has non-zero area. */
|
|
3
4
|
export function hasCoplanarArea(vertices) {
|
|
4
5
|
const offsets = normalizedSpaceOffsets(vertices);
|
|
5
|
-
|
|
6
|
-
let strongestLength = 0;
|
|
7
|
-
const vectors = offsets.slice(1);
|
|
8
|
-
for (const [leftIndex, left] of vectors.entries()) {
|
|
9
|
-
for (const right of vectors.slice(leftIndex + 1)) {
|
|
10
|
-
const candidate = cross(left, right);
|
|
11
|
-
const candidateLength = length(candidate);
|
|
12
|
-
if (candidateLength > strongestLength) {
|
|
13
|
-
strongestLength = candidateLength;
|
|
14
|
-
strongestNormal = candidate;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
6
|
+
const [strongestNormal, strongestLength] = strongestCrossProduct(Arr.drop(offsets, 1));
|
|
18
7
|
if (!(strongestNormal && strongestLength > GEOMETRY_TOLERANCE)) {
|
|
19
8
|
return false;
|
|
20
9
|
}
|
|
21
10
|
const unitNormal = divide(strongestNormal, strongestLength);
|
|
22
|
-
return
|
|
11
|
+
return Arr.every(offsets, (offset) => Math.abs(dot(unitNormal, offset)) <=
|
|
23
12
|
GEOMETRY_TOLERANCE * Math.max(1, length(offset)));
|
|
24
13
|
}
|
|
14
|
+
/** Returns the first longest cross product of every ordered pair, with its length. */
|
|
15
|
+
function strongestCrossProduct(vectors) {
|
|
16
|
+
const initial = [undefined, 0];
|
|
17
|
+
return Arr.reduce(vectors, initial, (strongest, left, leftIndex) => Arr.reduce(Arr.drop(vectors, leftIndex + 1), strongest, (best, right) => {
|
|
18
|
+
const candidate = cross(left, right);
|
|
19
|
+
const candidateLength = length(candidate);
|
|
20
|
+
return candidateLength > best[1] ? [candidate, candidateLength] : best;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
25
23
|
/** Translates before scaling so coplanarity is independent of scene location. */
|
|
26
24
|
function normalizedSpaceOffsets(vertices) {
|
|
27
25
|
const [origin] = vertices;
|
|
28
|
-
let offsets =
|
|
26
|
+
let offsets = Arr.map(vertices, ({ x, y, z }) => ({
|
|
29
27
|
x: x - origin.x,
|
|
30
28
|
y: y - origin.y,
|
|
31
29
|
z: z - origin.z,
|
|
32
30
|
}));
|
|
33
|
-
if (
|
|
31
|
+
if (Arr.some(offsets, ({ x, y, z }) => !(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z)))) {
|
|
34
32
|
let sourceScale = 1;
|
|
35
33
|
for (const { x, y, z } of vertices) {
|
|
36
34
|
sourceScale = Math.max(sourceScale, Math.abs(x), Math.abs(y), Math.abs(z));
|
|
37
35
|
}
|
|
38
|
-
offsets =
|
|
36
|
+
offsets = Arr.map(vertices, ({ x, y, z }) => ({
|
|
39
37
|
x: x / sourceScale - origin.x / sourceScale,
|
|
40
38
|
y: y / sourceScale - origin.y / sourceScale,
|
|
41
39
|
z: z / sourceScale - origin.z / sourceScale,
|
|
@@ -46,7 +44,7 @@ function normalizedSpaceOffsets(vertices) {
|
|
|
46
44
|
extent = Math.max(extent, Math.abs(x), Math.abs(y), Math.abs(z));
|
|
47
45
|
}
|
|
48
46
|
const divisor = Math.max(extent, Number.MIN_VALUE);
|
|
49
|
-
return
|
|
47
|
+
return Arr.map(offsets, (offset) => divide(offset, divisor));
|
|
50
48
|
}
|
|
51
49
|
/** Returns the cross product of two space vectors. */
|
|
52
50
|
function cross(left, right) {
|
package/dist/math/visual.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
2
2
|
import { decodeContract } from "#contracts/decode";
|
|
3
3
|
import { PlaneMathVisualSchema } from "#contracts/math/plane";
|
|
4
4
|
import { SpaceMathVisualSchema } from "#contracts/math/space";
|
|
@@ -11,5 +11,5 @@ export const MathVisualSchema = Schema.Union([
|
|
|
11
11
|
export const decodeMathVisual = Effect.fn("AksaraContracts.decodeMathVisual")((input) => decodeContract(MathVisualSchema, "MathVisual", input));
|
|
12
12
|
/** Returns every rich-label key in authored anchor order. */
|
|
13
13
|
export function mathVisualLabelKeys(visual) {
|
|
14
|
-
return (visual.labels ?? []
|
|
14
|
+
return Arr.map(visual.labels ?? [], ({ key }) => key);
|
|
15
15
|
}
|
package/dist/preview/target.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema, Struct } from "effect";
|
|
1
|
+
import { Array as Arr, Schema, Struct } from "effect";
|
|
2
2
|
import { PublicPathSchema } from "#contracts/ids";
|
|
3
3
|
import { AppLocaleSchema } from "#contracts/locale";
|
|
4
4
|
import { TryoutExamSchema, TryoutSectionSchema, TryoutSetSchema, TryoutTrackSchema, } from "#contracts/tryout/catalog";
|
|
@@ -23,10 +23,10 @@ const TryoutPreviewTargetInputSchema = Schema.Struct({
|
|
|
23
23
|
/** Checks that every target row belongs to one locale-specific hierarchy. */
|
|
24
24
|
function hasCoherentTryoutHierarchy(input) {
|
|
25
25
|
const rows = [input.track, input.set, input.section, input.placement];
|
|
26
|
-
return (
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
return (Arr.every(rows, ({ countryKey }) => countryKey === input.exam.countryKey) &&
|
|
27
|
+
Arr.every(rows, ({ examKey }) => examKey === input.exam.examKey) &&
|
|
28
|
+
Arr.every(rows, ({ appLocale }) => appLocale === input.exam.appLocale) &&
|
|
29
|
+
Arr.every(rows, ({ sourceRevision }) => sourceRevision === input.exam.sourceRevision) &&
|
|
30
30
|
input.set.trackKey === input.track.trackKey &&
|
|
31
31
|
input.section.trackKey === input.track.trackKey &&
|
|
32
32
|
input.placement.trackKey === input.track.trackKey &&
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { CorpusSourcePathSchema, PublicPathSchema } from "#contracts/ids";
|
|
3
3
|
import { AppLocaleSchema } from "#contracts/locale";
|
|
4
4
|
import { MaterialDomainSchema } from "#contracts/material/domain";
|
|
@@ -98,11 +98,11 @@ function hasCoherentRoute(input) {
|
|
|
98
98
|
function hasCoherentMaterialLink(input) {
|
|
99
99
|
const ownsMaterial = input.materialKey !== undefined;
|
|
100
100
|
const ownsCanonical = input.canonicalPath !== undefined;
|
|
101
|
-
const contextCount = [
|
|
101
|
+
const contextCount = Arr.filter([
|
|
102
102
|
input.materialContextNodeKey,
|
|
103
103
|
input.materialContextParentPath,
|
|
104
104
|
input.materialContextPublicPath,
|
|
105
|
-
]
|
|
105
|
+
], (value) => value !== undefined).length;
|
|
106
106
|
if (!ownsMaterial) {
|
|
107
107
|
return !ownsCanonical && contextCount === 0;
|
|
108
108
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { Effect, MutableHashMap, MutableHashSet, Option, Schema, Stream, } from "effect";
|
|
2
|
+
import { Array as Arr, Effect, MutableHashMap, MutableHashSet, Option, Schema, Stream, } from "effect";
|
|
3
3
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
4
4
|
import { curriculumNamespace, } from "#contracts/program/curriculum";
|
|
5
5
|
import { ProgramRowHashError, verifyProgramSnapshotRowHash, } from "#contracts/program/snapshot/hash";
|
|
@@ -25,22 +25,22 @@ export class ProgramDigestError extends Schema.TaggedError()("ProgramDigestError
|
|
|
25
25
|
}
|
|
26
26
|
/** Serializes source-derived counts for exact replay comparison. */
|
|
27
27
|
function countIdentity(counts) {
|
|
28
|
-
|
|
28
|
+
const values = [
|
|
29
29
|
counts.curriculumRowCount,
|
|
30
30
|
counts.programRowCount,
|
|
31
31
|
counts.rowCount,
|
|
32
32
|
counts.sitemapCount,
|
|
33
33
|
counts.slugCount,
|
|
34
|
-
]
|
|
34
|
+
];
|
|
35
|
+
return Arr.join(Arr.map(values, String), ":");
|
|
35
36
|
}
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Checks that one root is the exact localized route owned by its program.
|
|
39
|
+
* Translation locales are unique, because the catalog row must repeat the
|
|
40
|
+
* signed active locale list, so at most one translation matches the root.
|
|
41
|
+
*/
|
|
41
42
|
function isExactProgramRoot(row, program) {
|
|
42
|
-
|
|
43
|
-
return (translation !== undefined &&
|
|
43
|
+
return Arr.some(program.translations, (translation) => translation.appLocale === row.appLocale &&
|
|
44
44
|
row.iconKey === program.iconKey &&
|
|
45
45
|
row.order === program.displayOrder &&
|
|
46
46
|
row.publicPath ===
|
|
@@ -99,7 +99,7 @@ class ProgramDigestState {
|
|
|
99
99
|
MutableHashSet.size(this.#slugs) ===
|
|
100
100
|
this.programRowCount * this.#activeAppLocales.length &&
|
|
101
101
|
MutableHashSet.size(expectedRoots) === MutableHashSet.size(this.#roots) &&
|
|
102
|
-
[...expectedRoots]
|
|
102
|
+
Arr.every([...expectedRoots], (root) => MutableHashSet.has(this.#roots, root)) &&
|
|
103
103
|
countIdentity(counts) === countIdentity(expectedCounts)) {
|
|
104
104
|
return Effect.void;
|
|
105
105
|
}
|
|
@@ -122,7 +122,7 @@ class ProgramDigestState {
|
|
|
122
122
|
/** Adds one catalog row before any current curriculum records. */
|
|
123
123
|
#addProgram(record) {
|
|
124
124
|
const { row } = record;
|
|
125
|
-
const translationLocales = row.translations
|
|
125
|
+
const translationLocales = Arr.map(row.translations, (translation) => translation.appLocale);
|
|
126
126
|
if (this.curriculumRowCount > 0 ||
|
|
127
127
|
row.displayOrder <= this.#lastProgramOrder) {
|
|
128
128
|
return Effect.fail(new ProgramDigestError({ code: "order", identity: row.key }));
|
|
@@ -148,7 +148,7 @@ class ProgramDigestState {
|
|
|
148
148
|
#addCurriculum(record) {
|
|
149
149
|
const { row } = record;
|
|
150
150
|
const program = Option.getOrUndefined(MutableHashMap.get(this.#programs, row.programKey));
|
|
151
|
-
if (!this.#activeAppLocales
|
|
151
|
+
if (!Arr.contains(this.#activeAppLocales, row.appLocale) ||
|
|
152
152
|
program?.navigation.model !== "curriculum-tree") {
|
|
153
153
|
return Effect.fail(new ProgramDigestError({ code: "program", identity: row.programKey }));
|
|
154
154
|
}
|
package/dist/program/spec.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
|
+
import { hasCanonicalOrder } from "#contracts/canonical";
|
|
2
3
|
import { CountryCodeSchema } from "#contracts/country";
|
|
3
4
|
import { DateOnlySchema } from "#contracts/date";
|
|
4
5
|
import { APP_LOCALE_CODES, AppLocaleSchema } from "#contracts/locale";
|
|
@@ -102,12 +103,7 @@ export const ProgramTranslationSchema = Schema.Struct({
|
|
|
102
103
|
});
|
|
103
104
|
/** Checks translations for unique canonical application-locale order. */
|
|
104
105
|
function hasCanonicalTranslations(translations) {
|
|
105
|
-
return
|
|
106
|
-
const previous = translations[index - 1];
|
|
107
|
-
return (previous === undefined ||
|
|
108
|
-
APP_LOCALE_CODES.indexOf(previous.appLocale) <
|
|
109
|
-
APP_LOCALE_CODES.indexOf(translation.appLocale));
|
|
110
|
-
});
|
|
106
|
+
return hasCanonicalOrder(APP_LOCALE_CODES, Arr.map(translations, (translation) => translation.appLocale));
|
|
111
107
|
}
|
|
112
108
|
const ProgramTranslationListSchema = Schema.NonEmptyArray(ProgramTranslationSchema).pipe(Schema.check(Schema.makeFilter(hasCanonicalTranslations, {
|
|
113
109
|
message: "Program translations must use unique canonical app-locale order.",
|
|
@@ -171,7 +167,7 @@ export function canonicalizeLearningProgram(program) {
|
|
|
171
167
|
...(program.recommendedCountry === undefined
|
|
172
168
|
? {}
|
|
173
169
|
: { recommendedCountry: program.recommendedCountry }),
|
|
174
|
-
sources: program.sources
|
|
170
|
+
sources: Arr.map(program.sources, (source) => ({
|
|
175
171
|
label: source.label,
|
|
176
172
|
retrievedAt: source.retrievedAt,
|
|
177
173
|
...(source.reviewAfter === undefined
|
|
@@ -180,7 +176,7 @@ export function canonicalizeLearningProgram(program) {
|
|
|
180
176
|
type: source.type,
|
|
181
177
|
url: source.url,
|
|
182
178
|
})),
|
|
183
|
-
translations: program.translations
|
|
179
|
+
translations: Arr.map(program.translations, (translation) => ({
|
|
184
180
|
appLocale: translation.appLocale,
|
|
185
181
|
publicSlug: translation.publicSlug,
|
|
186
182
|
title: translation.title,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ContentAuthorSchema } from "#contracts/content";
|
|
3
3
|
import { withPublicationDates } from "#contracts/date";
|
|
4
4
|
import { canonicalizeLearningGraphIdentity, LearningGraphIdentitySchema, } from "#contracts/graph/spec";
|
|
@@ -106,7 +106,7 @@ export function makeArticleProjection(input) {
|
|
|
106
106
|
/** Serializes one article projection with stable signed field order. */
|
|
107
107
|
export function canonicalizeArticleProjection(projection) {
|
|
108
108
|
const metadata = {
|
|
109
|
-
authors: projection.metadata.authors
|
|
109
|
+
authors: Arr.map(projection.metadata.authors, ({ name }) => ({ name })),
|
|
110
110
|
...(projection.metadata.dateModified === undefined
|
|
111
111
|
? {}
|
|
112
112
|
: { dateModified: projection.metadata.dateModified }),
|
|
@@ -131,7 +131,7 @@ export function canonicalizeArticleProjection(projection) {
|
|
|
131
131
|
official: projection.official,
|
|
132
132
|
parentPath: projection.parentPath,
|
|
133
133
|
publicPath: projection.publicPath,
|
|
134
|
-
references: projection.references
|
|
134
|
+
references: Arr.map(projection.references, (reference) => ({
|
|
135
135
|
authors: reference.authors,
|
|
136
136
|
...(reference.citation === undefined
|
|
137
137
|
? {}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ContentAuthorSchema } from "#contracts/content";
|
|
3
3
|
import { withPublicationDates } from "#contracts/date";
|
|
4
4
|
import { canonicalizeLearningGraphIdentity, LearningGraphIdentitySchema, } from "#contracts/graph/spec";
|
|
@@ -142,7 +142,7 @@ export function makeMaterialLessonProjection(route, metadata) {
|
|
|
142
142
|
/** Serializes one material projection with stable signed field order. */
|
|
143
143
|
export function canonicalizeMaterialProjection(projection) {
|
|
144
144
|
const metadata = {
|
|
145
|
-
authors: projection.metadata.authors
|
|
145
|
+
authors: Arr.map(projection.metadata.authors, ({ name }) => ({ name })),
|
|
146
146
|
...(projection.metadata.dateModified === undefined
|
|
147
147
|
? {}
|
|
148
148
|
: { dateModified: projection.metadata.dateModified }),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
2
2
|
import { ContentAuthorSchema } from "#contracts/content";
|
|
3
3
|
import { withPublicationDates } from "#contracts/date";
|
|
4
4
|
import { ContentKeySchema } from "#contracts/ids";
|
|
@@ -103,7 +103,7 @@ export function canonicalizeQuestionProjection(projection) {
|
|
|
103
103
|
contentKey: projection.contentKey,
|
|
104
104
|
kind: projection.kind,
|
|
105
105
|
metadata: {
|
|
106
|
-
authors: projection.metadata.authors
|
|
106
|
+
authors: Arr.map(projection.metadata.authors, ({ name }) => ({ name })),
|
|
107
107
|
...(projection.metadata.dateModified === undefined
|
|
108
108
|
? {}
|
|
109
109
|
: { dateModified: projection.metadata.dateModified }),
|
package/dist/question/answer.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BigDecimal, HashSet, Option, Schema, String as Str } from "effect";
|
|
1
|
+
import { Array as Arr, BigDecimal, HashSet, Option, Schema, String as Str, } from "effect";
|
|
2
2
|
const DECIMAL_PATTERN = /^(?:0|-?[1-9]\d*|-?(?:0|[1-9]\d*)\.\d*[1-9])$/u;
|
|
3
3
|
const UNTYPABLE_CHARACTER_PATTERN = /[\p{Cc}\p{Cf}]|[^\S ]/u;
|
|
4
4
|
const FORMAT_CHARACTER_PATTERN = /\p{Cf}/gu;
|
|
@@ -98,7 +98,7 @@ function normalizeTextAnswer(text, rules) {
|
|
|
98
98
|
}
|
|
99
99
|
/** Checks that no two accepted answers grade as the same normalized text. */
|
|
100
100
|
function hasDistinctAcceptedAnswers(key) {
|
|
101
|
-
const normalized = key.acceptedAnswers
|
|
101
|
+
const normalized = Arr.map(key.acceptedAnswers, (text) => normalizeTextAnswer(text, key));
|
|
102
102
|
return HashSet.size(HashSet.fromIterable(normalized)) === normalized.length;
|
|
103
103
|
}
|
|
104
104
|
/**
|
|
@@ -213,7 +213,7 @@ function matchesNumberKey(key, answer) {
|
|
|
213
213
|
export function matchesAnswerKey(key, answer, language) {
|
|
214
214
|
if (key.kind === "text") {
|
|
215
215
|
const typed = normalizeTextAnswer(answer, key);
|
|
216
|
-
return key.acceptedAnswers
|
|
216
|
+
return Arr.some(key.acceptedAnswers, (accepted) => normalizeTextAnswer(accepted, key) === typed);
|
|
217
217
|
}
|
|
218
218
|
return Option.exists(readNumberAnswer(answer, language), (number) => matchesNumberKey(key, number));
|
|
219
219
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { CONTENT_KEY_MAX_LENGTH, ContentKeySchema, CorpusSourcePathSchema, } from "#contracts/ids";
|
|
3
3
|
import { ArtifactLocaleSchema } from "#contracts/locale";
|
|
4
4
|
import { TryoutKeySchema } from "#contracts/tryout/key";
|
|
@@ -39,15 +39,17 @@ function parseQuestionSetParts(input) {
|
|
|
39
39
|
}
|
|
40
40
|
const keys = input.slice(prefix.length).split("/");
|
|
41
41
|
if (keys.length < 4 ||
|
|
42
|
-
|
|
42
|
+
Arr.some(keys, (key) => !isTryoutKey(key) || isQuestionSegment(key))) {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
|
+
const [countryKey, examKey, ...rest] = keys;
|
|
46
|
+
const [sectionKey, setKey] = Arr.takeRight(rest, 2);
|
|
45
47
|
return Schema.decodeUnknownSync(QuestionSetPartsSchema)({
|
|
46
|
-
countryKey
|
|
47
|
-
examKey
|
|
48
|
-
intermediateBankKeys:
|
|
49
|
-
sectionKey
|
|
50
|
-
setKey
|
|
48
|
+
countryKey,
|
|
49
|
+
examKey,
|
|
50
|
+
intermediateBankKeys: Arr.dropRight(rest, 2),
|
|
51
|
+
sectionKey,
|
|
52
|
+
setKey,
|
|
51
53
|
});
|
|
52
54
|
}
|
|
53
55
|
/** Parses one numbered question beneath a structurally valid set identity. */
|
package/dist/question/item.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Record as Rec, Schema, Struct } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Record as Rec, Schema, Struct } from "effect";
|
|
2
2
|
import { AppLocaleCodeSchema, ArtifactLocaleSchema, artifactLocaleCode, } from "#contracts/locale";
|
|
3
3
|
import { QuestionAnswerKeySchema } from "#contracts/question/answer";
|
|
4
4
|
import { QuestionResponseLabelSchema } from "#contracts/question/label";
|
|
@@ -19,11 +19,11 @@ function hasAtLeastTwoOptions(options) {
|
|
|
19
19
|
}
|
|
20
20
|
/** Requires exactly one authored option to carry correctness. */
|
|
21
21
|
function hasOneCorrectOption(options) {
|
|
22
|
-
return
|
|
22
|
+
return Arr.filter(options, ({ isCorrect }) => isCorrect).length === 1;
|
|
23
23
|
}
|
|
24
24
|
/** Requires several correct options while retaining at least one distractor. */
|
|
25
25
|
function hasSeveralCorrectOptions(options) {
|
|
26
|
-
const correct =
|
|
26
|
+
const correct = Arr.filter(options, ({ isCorrect }) => isCorrect).length;
|
|
27
27
|
return correct >= 2 && correct < options.length;
|
|
28
28
|
}
|
|
29
29
|
const QuestionOptionSourceListSchema = Schema.Array(QuestionOptionSourceSchema).pipe(Schema.mutable, Schema.check(Schema.makeFilter(hasAtLeastTwoOptions, {
|
|
@@ -49,7 +49,7 @@ const CategoryStatementSourceSchema = Schema.Struct({
|
|
|
49
49
|
function hasCoherentCategoryResponse(input) {
|
|
50
50
|
return (input.categories.length >= 2 &&
|
|
51
51
|
input.statements.length > 0 &&
|
|
52
|
-
input.statements
|
|
52
|
+
Arr.every(input.statements, ({ correctCategoryOrder }) => correctCategoryOrder <= input.categories.length));
|
|
53
53
|
}
|
|
54
54
|
const CategoryResponseSourceSchema = Schema.Struct({
|
|
55
55
|
categories: Schema.Array(QuestionResponseLabelSchema).pipe(Schema.mutable),
|
|
@@ -82,7 +82,7 @@ export const QuestionBlueprintSchema = Schema.Struct({
|
|
|
82
82
|
});
|
|
83
83
|
/** Derives stable option keys and orders from source-authored array order. */
|
|
84
84
|
function freezeOptions(options) {
|
|
85
|
-
return
|
|
85
|
+
return Arr.map(options, ({ isCorrect, label }, index) => ({
|
|
86
86
|
isCorrect,
|
|
87
87
|
label,
|
|
88
88
|
optionKey: `option-${index + 1}`,
|
|
@@ -102,13 +102,13 @@ function freezeQuestionResponse(response) {
|
|
|
102
102
|
}
|
|
103
103
|
if (response.kind === "category") {
|
|
104
104
|
return QuestionResponseSchema.make({
|
|
105
|
-
categories: response.categories
|
|
105
|
+
categories: Arr.map(response.categories, (label, index) => ({
|
|
106
106
|
categoryKey: `category-${index + 1}`,
|
|
107
107
|
label,
|
|
108
108
|
order: index + 1,
|
|
109
109
|
})),
|
|
110
110
|
kind: response.kind,
|
|
111
|
-
statements: response.statements
|
|
111
|
+
statements: Arr.map(response.statements, ({ correctCategoryOrder, label }, index) => ({
|
|
112
112
|
correctCategoryKey: `category-${correctCategoryOrder}`,
|
|
113
113
|
label,
|
|
114
114
|
order: index + 1,
|
|
@@ -127,15 +127,15 @@ function responseStructure(response) {
|
|
|
127
127
|
}
|
|
128
128
|
/** Requires locale siblings to preserve one response format and answer key. */
|
|
129
129
|
function hasCoherentLocalizedResponses(input) {
|
|
130
|
-
const responses = Rec.values(input.responses)
|
|
130
|
+
const responses = Arr.filter(Rec.values(input.responses), (response) => response !== undefined);
|
|
131
131
|
const [first] = responses;
|
|
132
132
|
return (first !== undefined &&
|
|
133
|
-
|
|
133
|
+
Arr.every(responses, (response) => responseStructure(response) === responseStructure(first)));
|
|
134
134
|
}
|
|
135
135
|
/** Requires a rubric item to take its worth from the rubric total alone. */
|
|
136
136
|
function hasCoherentPoints(input) {
|
|
137
137
|
return (input.points === undefined ||
|
|
138
|
-
Rec.values(input.responses)
|
|
138
|
+
Arr.every(Rec.values(input.responses), (response) => response?.kind !== "rubric"));
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* Complete source-owned item with optional shared-stimulus identity and points.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HashSet, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, HashSet, Schema } from "effect";
|
|
2
2
|
import { canonicalQuestionAnswerKey, canonicalQuestionAnswerKeyStructure, QuestionAnswerKeySchema, } from "#contracts/question/answer";
|
|
3
3
|
import { QuestionResponseLabelSchema } from "#contracts/question/label";
|
|
4
4
|
import { canonicalQuestionRubric, canonicalQuestionRubricStructure, QuestionRubricResponseSchema, } from "#contracts/question/rubric";
|
|
@@ -26,9 +26,9 @@ const QuestionOptionSchema = Schema.Struct({
|
|
|
26
26
|
});
|
|
27
27
|
/** Checks stable option identities, order, and format-specific correctness. */
|
|
28
28
|
function hasCanonicalOptions(options, kind) {
|
|
29
|
-
const correct =
|
|
29
|
+
const correct = Arr.filter(options, ({ isCorrect }) => isCorrect).length;
|
|
30
30
|
return (options.length >= 2 &&
|
|
31
|
-
|
|
31
|
+
Arr.every(options, ({ optionKey, order }, index) => order === index + 1 && optionKey === `option-${order}`) &&
|
|
32
32
|
(kind === "single-choice"
|
|
33
33
|
? correct === 1
|
|
34
34
|
: correct >= 2 && correct < options.length));
|
|
@@ -58,11 +58,11 @@ const QuestionCategoryStatementSchema = Schema.Struct({
|
|
|
58
58
|
});
|
|
59
59
|
/** Checks stable category and statement identities plus valid references. */
|
|
60
60
|
function hasCanonicalCategories(input) {
|
|
61
|
-
const categoryKeys = HashSet.fromIterable(input.categories
|
|
61
|
+
const categoryKeys = HashSet.fromIterable(Arr.map(input.categories, ({ categoryKey }) => categoryKey));
|
|
62
62
|
return (input.categories.length >= 2 &&
|
|
63
63
|
input.statements.length > 0 &&
|
|
64
|
-
input.categories
|
|
65
|
-
input.statements
|
|
64
|
+
Arr.every(input.categories, ({ categoryKey, order }, index) => order === index + 1 && categoryKey === `category-${order}`) &&
|
|
65
|
+
Arr.every(input.statements, ({ correctCategoryKey, order, statementKey }, index) => order === index + 1 &&
|
|
66
66
|
statementKey === `statement-${order}` &&
|
|
67
67
|
HashSet.has(categoryKeys, correctCategoryKey)));
|
|
68
68
|
}
|
|
@@ -104,12 +104,12 @@ export function canonicalQuestionResponseStructure(response) {
|
|
|
104
104
|
}
|
|
105
105
|
if (response.kind === "category") {
|
|
106
106
|
return {
|
|
107
|
-
categories: response.categories
|
|
107
|
+
categories: Arr.map(response.categories, ({ categoryKey, order }) => ({
|
|
108
108
|
categoryKey,
|
|
109
109
|
order,
|
|
110
110
|
})),
|
|
111
111
|
kind: response.kind,
|
|
112
|
-
statements: response.statements
|
|
112
|
+
statements: Arr.map(response.statements, ({ correctCategoryKey, order, statementKey }) => ({
|
|
113
113
|
correctCategoryKey,
|
|
114
114
|
order,
|
|
115
115
|
statementKey,
|
|
@@ -118,7 +118,7 @@ export function canonicalQuestionResponseStructure(response) {
|
|
|
118
118
|
}
|
|
119
119
|
return {
|
|
120
120
|
kind: response.kind,
|
|
121
|
-
options: response.options
|
|
121
|
+
options: Arr.map(response.options, ({ isCorrect, optionKey, order }) => ({
|
|
122
122
|
isCorrect,
|
|
123
123
|
optionKey,
|
|
124
124
|
order,
|
|
@@ -138,13 +138,13 @@ export function canonicalQuestionResponse(response) {
|
|
|
138
138
|
}
|
|
139
139
|
if (response.kind === "category") {
|
|
140
140
|
return {
|
|
141
|
-
categories: response.categories
|
|
141
|
+
categories: Arr.map(response.categories, ({ categoryKey, label, order }) => ({
|
|
142
142
|
categoryKey,
|
|
143
143
|
label,
|
|
144
144
|
order,
|
|
145
145
|
})),
|
|
146
146
|
kind: response.kind,
|
|
147
|
-
statements: response.statements
|
|
147
|
+
statements: Arr.map(response.statements, ({ correctCategoryKey, label, order, statementKey }) => ({
|
|
148
148
|
correctCategoryKey,
|
|
149
149
|
label,
|
|
150
150
|
order,
|
|
@@ -154,7 +154,7 @@ export function canonicalQuestionResponse(response) {
|
|
|
154
154
|
}
|
|
155
155
|
return {
|
|
156
156
|
kind: response.kind,
|
|
157
|
-
options: response.options
|
|
157
|
+
options: Arr.map(response.options, ({ isCorrect, label, optionKey, order }) => ({
|
|
158
158
|
isCorrect,
|
|
159
159
|
label,
|
|
160
160
|
optionKey,
|
package/dist/question/rubric.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema, Struct } from "effect";
|
|
1
|
+
import { Array as Arr, Schema, Struct } from "effect";
|
|
2
2
|
import { ActiveAppLocaleCodeSchema } from "#contracts/locale";
|
|
3
3
|
import { canonicalQuestionAnswerKey, canonicalQuestionAnswerKeyStructure, QuestionAnswerKeySchema, } from "#contracts/question/answer";
|
|
4
4
|
import { QuestionResponseLabelSchema } from "#contracts/question/label";
|
|
@@ -37,9 +37,9 @@ const ORDERED_SCALE_MESSAGE = "Rubric criteria need two or more levels whose poi
|
|
|
37
37
|
/** Checks one or more criteria and the stable keys derived from their order. */
|
|
38
38
|
function hasCanonicalCriteria(criteria) {
|
|
39
39
|
return (criteria.length > 0 &&
|
|
40
|
-
|
|
40
|
+
Arr.every(criteria, ({ criterionKey, levels, order }, index) => order === index + 1 &&
|
|
41
41
|
criterionKey === `criterion-${order}` &&
|
|
42
|
-
|
|
42
|
+
Arr.every(levels, (level, levelIndex) => level.order === levelIndex + 1 &&
|
|
43
43
|
level.levelKey === `level-${level.order}`)));
|
|
44
44
|
}
|
|
45
45
|
const CANONICAL_CRITERIA_MESSAGE = "Rubric criteria and levels require canonical keys and order.";
|
|
@@ -120,13 +120,13 @@ export const QuestionRubricResponseSourceSchema = Schema.Struct({
|
|
|
120
120
|
/** Derives stable criterion and level keys once from authored array order. */
|
|
121
121
|
export function freezeQuestionRubric(source) {
|
|
122
122
|
return QuestionRubricResponseSchema.make({
|
|
123
|
-
criteria: source.criteria
|
|
123
|
+
criteria: Arr.map(source.criteria, (criterion, index) => ({
|
|
124
124
|
criterionKey: `criterion-${index + 1}`,
|
|
125
125
|
...(criterion.finalAnswer === undefined
|
|
126
126
|
? {}
|
|
127
127
|
: { finalAnswer: criterion.finalAnswer }),
|
|
128
128
|
label: criterion.label,
|
|
129
|
-
levels: criterion.levels
|
|
129
|
+
levels: Arr.map(criterion.levels, ({ label, points }, levelIndex) => ({
|
|
130
130
|
label,
|
|
131
131
|
levelKey: `level-${levelIndex + 1}`,
|
|
132
132
|
order: levelIndex + 1,
|
|
@@ -143,13 +143,13 @@ function canonicalRubricLabel(label) {
|
|
|
143
143
|
}
|
|
144
144
|
/** Serializes criteria in stable field order with one answer-key encoding. */
|
|
145
145
|
function canonicalRubricCriteria(rubric, canonicalKey) {
|
|
146
|
-
return rubric.criteria
|
|
146
|
+
return Arr.map(rubric.criteria, ({ criterionKey, finalAnswer, label, levels, order }) => ({
|
|
147
147
|
criterionKey,
|
|
148
148
|
...(finalAnswer === undefined
|
|
149
149
|
? {}
|
|
150
150
|
: { finalAnswer: canonicalKey(finalAnswer) }),
|
|
151
151
|
label: canonicalRubricLabel(label),
|
|
152
|
-
levels:
|
|
152
|
+
levels: Arr.map(levels, (level) => ({
|
|
153
153
|
label: canonicalRubricLabel(level.label),
|
|
154
154
|
levelKey: level.levelKey,
|
|
155
155
|
order: level.order,
|
|
@@ -178,6 +178,6 @@ export function canonicalQuestionRubric(rubric) {
|
|
|
178
178
|
}
|
|
179
179
|
/** Returns the rubric total: the sum of every criterion's highest level. */
|
|
180
180
|
export function questionRubricPoints(rubric) {
|
|
181
|
-
return rubric.criteria
|
|
182
|
-
|
|
181
|
+
return Arr.reduce(rubric.criteria, 0, (total, { levels }) => total +
|
|
182
|
+
Arr.reduce(levels, 0, (highest, { points }) => Math.max(highest, points)));
|
|
183
183
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import type { QuranSourceAttribution } from "#contracts/quran/source";
|
|
2
2
|
/** Serializes one source attribution without trusting object insertion order. */
|
|
3
3
|
export declare function canonicalizeQuranAttribution(attribution: QuranSourceAttribution): {
|
|
4
|
-
copy: {
|
|
4
|
+
copy: [{
|
|
5
5
|
appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
6
6
|
notice: string;
|
|
7
7
|
title: string;
|
|
8
|
-
}
|
|
8
|
+
}, ...{
|
|
9
|
+
appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
10
|
+
notice: string;
|
|
11
|
+
title: string;
|
|
12
|
+
}[]];
|
|
9
13
|
id: "bubenheim-names" | "kemenag-names" | "mokhtasar-english" | "mokhtasar-german" | "quranenc-english" | "quranenc-german" | "quranenc-indonesian" | "quranenc-tafsir" | "tanzil-metadata" | "tanzil-text";
|
|
10
14
|
kind: "embedded" | "external";
|
|
11
15
|
publisher: string;
|
|
@@ -19,11 +23,15 @@ export declare function canonicalizeQuranAttribution(attribution: QuranSourceAtt
|
|
|
19
23
|
updateUrl: string;
|
|
20
24
|
version: string;
|
|
21
25
|
} | {
|
|
22
|
-
copy: {
|
|
26
|
+
copy: [{
|
|
27
|
+
appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
28
|
+
notice: string;
|
|
29
|
+
title: string;
|
|
30
|
+
}, ...{
|
|
23
31
|
appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
24
32
|
notice: string;
|
|
25
33
|
title: string;
|
|
26
|
-
}[];
|
|
34
|
+
}[]];
|
|
27
35
|
id: "bubenheim-names" | "kemenag-names" | "mokhtasar-english" | "mokhtasar-german" | "quranenc-english" | "quranenc-german" | "quranenc-indonesian" | "quranenc-tafsir" | "tanzil-metadata" | "tanzil-text";
|
|
28
36
|
kind: "embedded" | "external";
|
|
29
37
|
publisher: string;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { Array as Arr } from "effect";
|
|
1
2
|
/** Serializes one source attribution without trusting object insertion order. */
|
|
2
3
|
export function canonicalizeQuranAttribution(attribution) {
|
|
3
4
|
const common = {
|
|
4
|
-
copy: attribution.copy
|
|
5
|
+
copy: Arr.map(attribution.copy, (entry) => ({
|
|
5
6
|
appLocale: entry.appLocale,
|
|
6
7
|
notice: entry.notice,
|
|
7
8
|
title: entry.title,
|