@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/quran/notes.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, MutableList, Option, Schema } from "effect";
|
|
2
2
|
import { QuranMeaningfulTextSchema } from "#contracts/quran/text";
|
|
3
3
|
const QuranTranslationNoteNumberSchema = Schema.Int.pipe(Schema.check(Schema.isGreaterThan(0)));
|
|
4
4
|
const QuranTranslationOffsetSchema = Schema.Int.pipe(Schema.check(Schema.isGreaterThanOrEqualTo(0)));
|
|
@@ -53,7 +53,7 @@ const QuranTranslationSourceSchema = Schema.Struct({
|
|
|
53
53
|
});
|
|
54
54
|
/** Reads every numeric marker without treating editorial brackets as notes. */
|
|
55
55
|
function readMarkers(source) {
|
|
56
|
-
const markers =
|
|
56
|
+
const markers = MutableList.make();
|
|
57
57
|
for (const match of source.matchAll(/\[(\d+)\]/gu)) {
|
|
58
58
|
const rawNumber = match[0].slice(1, -1);
|
|
59
59
|
const start = match.index;
|
|
@@ -62,23 +62,27 @@ function readMarkers(source) {
|
|
|
62
62
|
!Schema.is(QuranTranslationNoteNumberSchema)(number)) {
|
|
63
63
|
return { _tag: "Failure" };
|
|
64
64
|
}
|
|
65
|
-
|
|
65
|
+
MutableList.append(markers, {
|
|
66
|
+
end: start + match[0].length,
|
|
67
|
+
number,
|
|
68
|
+
start,
|
|
69
|
+
});
|
|
66
70
|
}
|
|
67
|
-
return { _tag: "Success", markers };
|
|
71
|
+
return { _tag: "Success", markers: MutableList.toArray(markers) };
|
|
68
72
|
}
|
|
69
73
|
/** Converts the translation body to text and note-reference segments. */
|
|
70
74
|
function segmentTranslation(source, markers) {
|
|
71
|
-
const segments =
|
|
75
|
+
const segments = MutableList.make();
|
|
72
76
|
let start = 0;
|
|
73
77
|
for (const marker of markers) {
|
|
74
78
|
if (marker.start > start) {
|
|
75
|
-
|
|
79
|
+
MutableList.append(segments, {
|
|
76
80
|
kind: "text",
|
|
77
81
|
offset: start,
|
|
78
82
|
value: source.slice(start, marker.start),
|
|
79
83
|
});
|
|
80
84
|
}
|
|
81
|
-
|
|
85
|
+
MutableList.append(segments, {
|
|
82
86
|
kind: "note",
|
|
83
87
|
number: marker.number,
|
|
84
88
|
offset: marker.start,
|
|
@@ -86,9 +90,13 @@ function segmentTranslation(source, markers) {
|
|
|
86
90
|
start = marker.end;
|
|
87
91
|
}
|
|
88
92
|
if (start < source.length || segments.length === 0) {
|
|
89
|
-
|
|
93
|
+
MutableList.append(segments, {
|
|
94
|
+
kind: "text",
|
|
95
|
+
offset: start,
|
|
96
|
+
value: source.slice(start),
|
|
97
|
+
});
|
|
90
98
|
}
|
|
91
|
-
return segments;
|
|
99
|
+
return MutableList.toArray(segments);
|
|
92
100
|
}
|
|
93
101
|
/** Analyzes one source translation through the canonical note grammar. */
|
|
94
102
|
function analyzeTranslation(source) {
|
|
@@ -100,17 +108,16 @@ function analyzeTranslation(source) {
|
|
|
100
108
|
}
|
|
101
109
|
const references = referencesResult.markers;
|
|
102
110
|
const definitions = definitionsResult.markers;
|
|
103
|
-
const uniqueReferences =
|
|
104
|
-
|
|
105
|
-
const noteCandidates = definitions.map((definition, index) => ({
|
|
111
|
+
const uniqueReferences = Arr.filter(references, (reference, index) => Option.contains(Arr.findFirstIndex(references, ({ number }) => number === reference.number), index));
|
|
112
|
+
const noteCandidates = Arr.map(definitions, (definition, index) => ({
|
|
106
113
|
definition,
|
|
107
114
|
referenceOffset: uniqueReferences[index]?.start ?? -1,
|
|
108
115
|
}));
|
|
109
|
-
const definitionNumbers =
|
|
110
|
-
const hasDuplicateDefinition =
|
|
116
|
+
const definitionNumbers = Arr.map(definitions, ({ number }) => number);
|
|
117
|
+
const hasDuplicateDefinition = Arr.some(definitionNumbers, (number, index) => Option.getOrUndefined(Arr.findFirstIndex(definitionNumbers, (value) => value === number)) !== index);
|
|
111
118
|
const hasMismatchedMarkers = hasDuplicateDefinition ||
|
|
112
119
|
uniqueReferences.length !== definitionNumbers.length ||
|
|
113
|
-
|
|
120
|
+
Arr.some(noteCandidates, ({ definition, referenceOffset }, index) => referenceOffset < 0 ||
|
|
114
121
|
definition.number !== uniqueReferences[index]?.number) ||
|
|
115
122
|
(definitions[0] === undefined
|
|
116
123
|
? source.footnotes.trim().length > 0
|
|
@@ -118,14 +125,14 @@ function analyzeTranslation(source) {
|
|
|
118
125
|
if (hasMismatchedMarkers) {
|
|
119
126
|
return { _tag: "Failure", reason: "mismatched-markers" };
|
|
120
127
|
}
|
|
121
|
-
const notes =
|
|
128
|
+
const notes = Arr.map(noteCandidates, ({ definition, referenceOffset }, index) => ({
|
|
122
129
|
number: definition.number,
|
|
123
130
|
referenceOffset,
|
|
124
131
|
text: source.footnotes
|
|
125
132
|
.slice(definition.end, definitions[index + 1]?.start)
|
|
126
133
|
.trim(),
|
|
127
134
|
}));
|
|
128
|
-
if (
|
|
135
|
+
if (Arr.some(notes, ({ text }) => text.length === 0)) {
|
|
129
136
|
return { _tag: "Failure", reason: "empty-note" };
|
|
130
137
|
}
|
|
131
138
|
return {
|
package/dist/quran/provenance.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Array as Arr, Effect, MutableList, Schema } from "effect";
|
|
3
3
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
4
4
|
import { ActiveAppLocaleListSchema, AppLocaleSchema, ENGLISH_APP_LOCALE_CODE, GERMAN_APP_LOCALE_CODE, INDONESIAN_APP_LOCALE_CODE, } from "#contracts/locale";
|
|
5
5
|
import { canonicalizeQuranAttribution } from "#contracts/quran/attribution";
|
|
@@ -29,22 +29,23 @@ export const QuranProvenanceScopeSchema = Schema.Union([
|
|
|
29
29
|
]);
|
|
30
30
|
/** Derives the exact provenance scope order for one active locale set. */
|
|
31
31
|
export function quranProvenanceScopes(activeAppLocales) {
|
|
32
|
-
const scopes =
|
|
32
|
+
const scopes = MutableList.make();
|
|
33
|
+
MutableList.append(scopes, "arabic-text");
|
|
33
34
|
for (const appLocale of activeAppLocales) {
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
MutableList.append(scopes, quranNameProvenanceScope(appLocale));
|
|
36
|
+
MutableList.append(scopes, quranTranslationProvenanceScope(appLocale));
|
|
36
37
|
if (appLocale === AppLocaleSchema.make("en")) {
|
|
37
|
-
|
|
38
|
+
MutableList.append(scopes, "en-tafsir-access");
|
|
38
39
|
}
|
|
39
40
|
else if (appLocale === AppLocaleSchema.make("id")) {
|
|
40
|
-
|
|
41
|
+
MutableList.append(scopes, "id-tafsir");
|
|
41
42
|
}
|
|
42
43
|
else {
|
|
43
|
-
|
|
44
|
+
MutableList.append(scopes, "de-tafsir-access");
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
|
|
47
|
-
return scopes;
|
|
47
|
+
MutableList.append(scopes, "metadata");
|
|
48
|
+
return MutableList.toArray(scopes);
|
|
48
49
|
}
|
|
49
50
|
const QURAN_STATIC_PROVENANCE_SOURCE = {
|
|
50
51
|
"arabic-text": "tanzil-text",
|
|
@@ -74,13 +75,13 @@ export const QuranProvenanceRecordSchema = Schema.Struct({
|
|
|
74
75
|
function hasCanonicalSourceCoverage(input) {
|
|
75
76
|
const expected = quranProvenanceScopes(input.activeAppLocales);
|
|
76
77
|
return (input.records.length === expected.length &&
|
|
77
|
-
input.records
|
|
78
|
+
Arr.every(input.records, (record, index) => record.scope === expected[index] &&
|
|
78
79
|
record.attribution.id === quranSourceForProvenanceScope(record.scope) &&
|
|
79
80
|
hasCompleteQuranSourceCopy(record.attribution, input.activeAppLocales)));
|
|
80
81
|
}
|
|
81
82
|
/** Checks that the declared gate status matches every reviewed record. */
|
|
82
83
|
function hasCoherentProvenanceStatus(input) {
|
|
83
|
-
const expected = input.records
|
|
84
|
+
const expected = Arr.some(input.records, (record) => record.status === "blocked")
|
|
84
85
|
? "blocked"
|
|
85
86
|
: "approved";
|
|
86
87
|
return input.status === expected;
|
|
@@ -135,10 +136,10 @@ export const makeQuranProvenanceManifest = Effect.fn("AksaraContracts.makeQuranP
|
|
|
135
136
|
activeAppLocales: ActiveAppLocaleListSchema,
|
|
136
137
|
records: Schema.NonEmptyArray(QuranProvenanceRecordSchema),
|
|
137
138
|
}).pipe(Schema.check(Schema.makeFilter(hasCanonicalSourceCoverage))))(input).pipe(Effect.mapError(() => new QuranProvenanceCoverageError({
|
|
138
|
-
actualScopes: input.records
|
|
139
|
+
actualScopes: Arr.map(input.records, ({ scope }) => scope),
|
|
139
140
|
})));
|
|
140
141
|
const digest = yield* hashQuranProvenance(decoded);
|
|
141
|
-
const status = decoded.records
|
|
142
|
+
const status = Arr.some(decoded.records, (record) => record.status === "blocked")
|
|
142
143
|
? "blocked"
|
|
143
144
|
: "approved";
|
|
144
145
|
return QuranProvenanceManifestSchema.make({ ...decoded, digest, status });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { Effect, Schema, Stream } from "effect";
|
|
2
|
+
import { Array as Arr, Effect, Option, Schema, Stream } from "effect";
|
|
3
3
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
4
4
|
import { AppLocaleSchema } from "#contracts/locale";
|
|
5
5
|
import { hashQuranRow, QuranRowHashError, } from "#contracts/quran/snapshot/row/hash";
|
|
@@ -21,24 +21,33 @@ export class QuranRowOrderError extends Schema.TaggedError()("QuranRowOrderError
|
|
|
21
21
|
expected: Schema.String,
|
|
22
22
|
}) {
|
|
23
23
|
}
|
|
24
|
+
/** Joins the parts of one row identity with colons, stringifying each part. */
|
|
25
|
+
function joinIdentity(parts) {
|
|
26
|
+
return Arr.join(Arr.map(parts, String), ":");
|
|
27
|
+
}
|
|
28
|
+
/** Formats one finished digest as the signed sha256 hash of a Quran domain. */
|
|
29
|
+
function sha256Digest(hash) {
|
|
30
|
+
return Sha256HashSchema.make(`sha256:${hash.digest("hex")}`);
|
|
31
|
+
}
|
|
24
32
|
/** Resolves one complete stable current row identity. */
|
|
25
33
|
function rowIdentity(payload) {
|
|
26
34
|
if (payload.kind === "quran-attribution") {
|
|
27
|
-
|
|
35
|
+
const sourceIds = Arr.map(payload.sources, ({ id }) => id);
|
|
36
|
+
return `quran-attribution:${Arr.join(payload.activeAppLocales, ",")}:${Arr.join(sourceIds, ":")}`;
|
|
28
37
|
}
|
|
29
38
|
if (payload.kind === "quran-surah") {
|
|
30
39
|
return `quran-surah:${payload.number}`;
|
|
31
40
|
}
|
|
32
41
|
if (payload.kind === "quran-chunk") {
|
|
33
|
-
return [
|
|
42
|
+
return joinIdentity([
|
|
34
43
|
"quran-chunk",
|
|
35
44
|
payload.surahNumber,
|
|
36
45
|
payload.firstVerse,
|
|
37
46
|
payload.lastVerse,
|
|
38
47
|
payload.firstQuranNumber,
|
|
39
|
-
]
|
|
48
|
+
]);
|
|
40
49
|
}
|
|
41
|
-
return [
|
|
50
|
+
return joinIdentity([
|
|
42
51
|
"quran-search",
|
|
43
52
|
payload.surahNumber,
|
|
44
53
|
payload.appLocale,
|
|
@@ -48,7 +57,7 @@ function rowIdentity(payload) {
|
|
|
48
57
|
payload.graph.conceptId,
|
|
49
58
|
payload.graph.learningObjectId,
|
|
50
59
|
payload.graph.lensId,
|
|
51
|
-
]
|
|
60
|
+
]);
|
|
52
61
|
}
|
|
53
62
|
/** Keeps current locale closure and digest state private to one replay. */
|
|
54
63
|
class QuranDigestState {
|
|
@@ -75,23 +84,23 @@ class QuranDigestState {
|
|
|
75
84
|
/** Returns the only row identity valid at the current stream position. */
|
|
76
85
|
expectedIdentity() {
|
|
77
86
|
if (this.attributionCount === 0) {
|
|
78
|
-
return `quran-attribution:${this.#activeAppLocales
|
|
87
|
+
return `quran-attribution:${Arr.join(this.#activeAppLocales, ",")}:${Arr.join(quranSourceIds(this.#activeAppLocales), ":")}`;
|
|
79
88
|
}
|
|
80
89
|
if (this.#nextSurah <= QURAN_SURAH_COUNT) {
|
|
81
90
|
if (this.#nextSurahVerse === 0) {
|
|
82
91
|
return `quran-surah:${this.#nextSurah}`;
|
|
83
92
|
}
|
|
84
93
|
const lastVerse = Math.min(this.#nextSurahVerse + QURAN_CHUNK_SIZE - 1, this.#surahVerseCount);
|
|
85
|
-
return [
|
|
94
|
+
return joinIdentity([
|
|
86
95
|
"quran-chunk",
|
|
87
96
|
this.#nextSurah,
|
|
88
97
|
this.#nextSurahVerse,
|
|
89
98
|
lastVerse,
|
|
90
99
|
this.#nextQuranNumber,
|
|
91
|
-
]
|
|
100
|
+
]);
|
|
92
101
|
}
|
|
93
102
|
if (this.#nextSearchSurah <= QURAN_SURAH_COUNT) {
|
|
94
|
-
return [
|
|
103
|
+
return joinIdentity([
|
|
95
104
|
"quran-search",
|
|
96
105
|
this.#nextSearchSurah,
|
|
97
106
|
this.#nextSearchLocale,
|
|
@@ -101,7 +110,7 @@ class QuranDigestState {
|
|
|
101
110
|
`concept:quran:surah:${this.#nextSearchSurah}`,
|
|
102
111
|
`lo:quran-surah:${this.#nextSearchSurah}`,
|
|
103
112
|
"lens:quran",
|
|
104
|
-
]
|
|
113
|
+
]);
|
|
105
114
|
}
|
|
106
115
|
return "end";
|
|
107
116
|
}
|
|
@@ -110,11 +119,11 @@ class QuranDigestState {
|
|
|
110
119
|
if (payload.kind !== "quran-chunk") {
|
|
111
120
|
return true;
|
|
112
121
|
}
|
|
113
|
-
const expectedTafsir = this.#activeAppLocales
|
|
122
|
+
const expectedTafsir = Arr.contains(this.#activeAppLocales, AppLocaleSchema.make("id"))
|
|
114
123
|
? ["id"]
|
|
115
124
|
: [];
|
|
116
|
-
return payload.verses
|
|
117
|
-
encodeJsonText(verse.tafsir
|
|
125
|
+
return Arr.every(payload.verses, (verse) => encodeJsonText(Arr.map(verse.translations, (translation) => translation.appLocale)) === encodeJsonText(this.#activeAppLocales) &&
|
|
126
|
+
encodeJsonText(Arr.map(verse.tafsir, (tafsir) => tafsir.appLocale)) ===
|
|
118
127
|
encodeJsonText(expectedTafsir));
|
|
119
128
|
}
|
|
120
129
|
/** Advances deterministic identity state after one accepted row. */
|
|
@@ -137,7 +146,7 @@ class QuranDigestState {
|
|
|
137
146
|
this.#nextSurahVerse = payload.lastVerse + 1;
|
|
138
147
|
return;
|
|
139
148
|
}
|
|
140
|
-
const localeIndex = this.#activeAppLocales
|
|
149
|
+
const localeIndex = Option.getOrThrow(Arr.findFirstIndex(this.#activeAppLocales, (locale) => locale === this.#nextSearchLocale));
|
|
141
150
|
const nextLocale = this.#activeAppLocales[localeIndex + 1];
|
|
142
151
|
if (nextLocale !== undefined) {
|
|
143
152
|
this.#nextSearchLocale = nextLocale;
|
|
@@ -199,11 +208,11 @@ class QuranDigestState {
|
|
|
199
208
|
attributionCount: this.attributionCount,
|
|
200
209
|
chunkCount: this.chunkCount,
|
|
201
210
|
projectionCount: this.projectionCount,
|
|
202
|
-
projectionDigest:
|
|
211
|
+
projectionDigest: sha256Digest(this.#projection),
|
|
203
212
|
runtimeCount: this.runtimeCount,
|
|
204
|
-
runtimeDigest:
|
|
213
|
+
runtimeDigest: sha256Digest(this.#runtime),
|
|
205
214
|
searchCount: this.searchCount,
|
|
206
|
-
searchDigest:
|
|
215
|
+
searchDigest: sha256Digest(this.#search),
|
|
207
216
|
};
|
|
208
217
|
}
|
|
209
218
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
3
3
|
import { canonicalizeLearningGraphIdentity } from "#contracts/graph/spec";
|
|
4
4
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
5
5
|
import { canonicalizeQuranAttribution } from "#contracts/quran/attribution";
|
|
@@ -11,7 +11,7 @@ export class QuranRowHashError extends Schema.TaggedError()("QuranRowHashError",
|
|
|
11
11
|
}
|
|
12
12
|
/** Serializes one published translation list in signed field order. */
|
|
13
13
|
function canonicalizeTranslations(translations) {
|
|
14
|
-
return
|
|
14
|
+
return Arr.map(translations, (translation) => ({
|
|
15
15
|
appLocale: translation.appLocale,
|
|
16
16
|
value: {
|
|
17
17
|
footnotes: translation.value.footnotes,
|
|
@@ -43,7 +43,7 @@ function canonicalizeVerse(verse) {
|
|
|
43
43
|
inQuran: verse.number.inQuran,
|
|
44
44
|
inSurah: verse.number.inSurah,
|
|
45
45
|
},
|
|
46
|
-
tafsir: verse.tafsir
|
|
46
|
+
tafsir: Arr.map(verse.tafsir, (entry) => ({
|
|
47
47
|
appLocale: entry.appLocale,
|
|
48
48
|
footnotes: entry.footnotes,
|
|
49
49
|
text: entry.text,
|
|
@@ -58,8 +58,8 @@ export function canonicalizeQuranRow(payload) {
|
|
|
58
58
|
return encodeJsonText({
|
|
59
59
|
activeAppLocales: payload.activeAppLocales,
|
|
60
60
|
kind: payload.kind,
|
|
61
|
-
sources: payload.sources
|
|
62
|
-
tafsirAccess: payload.tafsirAccess
|
|
61
|
+
sources: Arr.map(payload.sources, canonicalizeQuranAttribution),
|
|
62
|
+
tafsirAccess: Arr.map(payload.tafsirAccess, canonicalizeTafsirAccess),
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
if (payload.kind === "quran-surah") {
|
|
@@ -89,7 +89,7 @@ export function canonicalizeQuranRow(payload) {
|
|
|
89
89
|
kind: payload.kind,
|
|
90
90
|
lastVerse: payload.lastVerse,
|
|
91
91
|
surahNumber: payload.surahNumber,
|
|
92
|
-
verses: payload.verses
|
|
92
|
+
verses: Arr.map(payload.verses, canonicalizeVerse),
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
return encodeJsonText({
|
|
@@ -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 { LearningGraphIdentitySchema } from "#contracts/graph/spec";
|
|
3
4
|
import { PublicPathSchema, Sha256HashSchema } from "#contracts/ids";
|
|
4
5
|
import { APP_LOCALE_CODES, AppLocaleSchema } from "#contracts/locale";
|
|
@@ -13,12 +14,7 @@ export const QuranLocalizedTranslationSchema = Schema.Struct({
|
|
|
13
14
|
});
|
|
14
15
|
/** Checks translation entries for unique canonical app-locale order. */
|
|
15
16
|
function hasCanonicalTranslations(translations) {
|
|
16
|
-
return
|
|
17
|
-
const previous = translations[index - 1];
|
|
18
|
-
return (previous === undefined ||
|
|
19
|
-
APP_LOCALE_CODES.indexOf(previous.appLocale) <
|
|
20
|
-
APP_LOCALE_CODES.indexOf(translation.appLocale));
|
|
21
|
-
});
|
|
17
|
+
return hasCanonicalOrder(APP_LOCALE_CODES, Arr.map(translations, (translation) => translation.appLocale));
|
|
22
18
|
}
|
|
23
19
|
const QuranTranslationListSchema = Schema.NonEmptyArray(QuranLocalizedTranslationSchema).pipe(Schema.check(Schema.makeFilter(hasCanonicalTranslations, {
|
|
24
20
|
message: "Quran translations must use unique canonical app-locale order.",
|
|
@@ -52,7 +48,7 @@ function hasCoherentChunk(input) {
|
|
|
52
48
|
if (input.lastVerse - input.firstVerse + 1 !== input.verses.length) {
|
|
53
49
|
return false;
|
|
54
50
|
}
|
|
55
|
-
return input.verses
|
|
51
|
+
return Arr.every(input.verses, (verse, index) => verse.number.inSurah === input.firstVerse + index &&
|
|
56
52
|
verse.number.inQuran === input.firstQuranNumber + index);
|
|
57
53
|
}
|
|
58
54
|
/** Immutable bounded runtime row containing ordered verses. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
3
3
|
import { ActiveAppLocaleListSchema, AppLocaleSchema, } from "#contracts/locale";
|
|
4
4
|
import { quranSourceFileCount } from "#contracts/quran/source";
|
|
@@ -34,7 +34,7 @@ const QuranSnapshotFactFields = {
|
|
|
34
34
|
};
|
|
35
35
|
/** Checks source, translation, and Tafsir counts against active locales. */
|
|
36
36
|
function hasCompleteSnapshotCounts(input) {
|
|
37
|
-
const hasIndonesian = input.activeAppLocales
|
|
37
|
+
const hasIndonesian = Arr.contains(input.activeAppLocales, AppLocaleSchema.make("id"));
|
|
38
38
|
return (input.attributionCount === QURAN_ATTRIBUTION_COUNT &&
|
|
39
39
|
input.surahCount === QURAN_SURAH_COUNT &&
|
|
40
40
|
input.verseCount === QURAN_VERSE_COUNT &&
|
package/dist/quran/source.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 { Sha256HashSchema } from "#contracts/ids";
|
|
3
4
|
import { ActiveAppLocaleListSchema, AppLocaleSchema, appLocaleLiteral, } from "#contracts/locale";
|
|
4
5
|
import { QURAN_SOURCE_IDS, QuranEmbeddedSourceIdSchema, QuranExternalSourceIdSchema, quranNameSourceId, quranTafsirSourceId, quranTranslationSourceId, } from "#contracts/quran/identity";
|
|
@@ -6,7 +7,7 @@ import { QURAN_SURAH_COUNT, QuranExternalTafsirLocaleSchema, QuranTafsirLocaleSc
|
|
|
6
7
|
import { isHttpsUrl } from "#contracts/text/syntax";
|
|
7
8
|
/** Derives the exact source identities required by one active locale set. */
|
|
8
9
|
export function quranSourceIds(activeAppLocales) {
|
|
9
|
-
const sourceIds =
|
|
10
|
+
const sourceIds = Arr.flatMap(activeAppLocales, (appLocale) => [
|
|
10
11
|
quranNameSourceId(appLocale),
|
|
11
12
|
quranTranslationSourceId(appLocale),
|
|
12
13
|
quranTafsirSourceId(appLocale),
|
|
@@ -14,13 +15,13 @@ export function quranSourceIds(activeAppLocales) {
|
|
|
14
15
|
return [
|
|
15
16
|
"tanzil-text",
|
|
16
17
|
"tanzil-metadata",
|
|
17
|
-
...
|
|
18
|
+
...Arr.filter(Arr.drop(QURAN_SOURCE_IDS, 2), (sourceId) => Arr.contains(sourceIds, sourceId)),
|
|
18
19
|
];
|
|
19
20
|
}
|
|
20
21
|
/** Counts exact source files required by one active locale set. */
|
|
21
22
|
export function quranSourceFileCount(activeAppLocales) {
|
|
22
|
-
const supplementalNameFileCount =
|
|
23
|
-
const tafsirFileCount =
|
|
23
|
+
const supplementalNameFileCount = Arr.filter(activeAppLocales, (appLocale) => quranNameSourceId(appLocale) !== "tanzil-metadata").length;
|
|
24
|
+
const tafsirFileCount = Arr.contains(activeAppLocales, AppLocaleSchema.make("id"))
|
|
24
25
|
? QURAN_SURAH_COUNT
|
|
25
26
|
: 0;
|
|
26
27
|
return (2 + activeAppLocales.length + supplementalNameFileCount + tafsirFileCount);
|
|
@@ -103,30 +104,25 @@ export const QuranTafsirAccessSchema = Schema.Union([
|
|
|
103
104
|
]);
|
|
104
105
|
/** Checks source identities for uniqueness and canonical contract order. */
|
|
105
106
|
function hasCanonicalSources(sources) {
|
|
106
|
-
return
|
|
107
|
-
const previous = sources[index - 1];
|
|
108
|
-
return (previous === undefined ||
|
|
109
|
-
QURAN_SOURCE_IDS.indexOf(previous.id) <
|
|
110
|
-
QURAN_SOURCE_IDS.indexOf(source.id));
|
|
111
|
-
});
|
|
107
|
+
return hasCanonicalOrder(QURAN_SOURCE_IDS, Arr.map(sources, (source) => source.id));
|
|
112
108
|
}
|
|
113
109
|
/** Checks every source copy against the exact active locale set and order. */
|
|
114
110
|
export function hasCompleteQuranSourceCopy(source, activeAppLocales) {
|
|
115
111
|
return (source.copy.length === activeAppLocales.length &&
|
|
116
|
-
source.copy
|
|
112
|
+
Arr.every(source.copy, ({ appLocale }, index) => appLocale === activeAppLocales[index]));
|
|
117
113
|
}
|
|
118
114
|
/** Checks localized copy closure across every selected official source. */
|
|
119
115
|
function hasCompleteLocalizedCopy(input) {
|
|
120
|
-
return input.sources
|
|
116
|
+
return Arr.every(input.sources, (source) => hasCompleteQuranSourceCopy(source, input.activeAppLocales));
|
|
121
117
|
}
|
|
122
118
|
/** Checks every signed Tafsir access record against one attributed source. */
|
|
123
119
|
function hasAttributedTafsirSources(input) {
|
|
124
|
-
return input.tafsirAccess
|
|
120
|
+
return Arr.every(input.tafsirAccess, (access) => Arr.some(input.sources, (source) => source.id === access.sourceId));
|
|
125
121
|
}
|
|
126
122
|
/** Checks exact Tafsir access coverage against one active locale set. */
|
|
127
123
|
export function hasCompleteQuranTafsirAccess(access, activeAppLocales) {
|
|
128
124
|
return (access.length === activeAppLocales.length &&
|
|
129
|
-
|
|
125
|
+
Arr.every(access, ({ appLocale }, index) => appLocale === activeAppLocales[index]));
|
|
130
126
|
}
|
|
131
127
|
/** Visible attribution row carrying the active official source subset. */
|
|
132
128
|
export const QuranAttributionRowSchema = Schema.Struct({
|
|
@@ -149,5 +145,5 @@ export const QuranAttributionRowSchema = Schema.Struct({
|
|
|
149
145
|
export function hasRequiredQuranSources(sources, activeAppLocales) {
|
|
150
146
|
const expected = quranSourceIds(activeAppLocales);
|
|
151
147
|
return (sources.length === expected.length &&
|
|
152
|
-
|
|
148
|
+
Arr.every(sources, ({ id }, index) => id === expected[index]));
|
|
153
149
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ContentReleaseBundleSchema, } from "#contracts/release/lifecycle";
|
|
3
3
|
import { hasSameContentSnapshots, snapshotRowCount, } from "#contracts/release/snapshot/spec";
|
|
4
4
|
import { PublicationReceiptSchema } from "#contracts/release/spec";
|
|
5
5
|
/** Compares canonical signed locale lists without erasing their role. */
|
|
6
6
|
export function hasSameAppLocales(left, right) {
|
|
7
7
|
return (left.length === right.length &&
|
|
8
|
-
|
|
8
|
+
Arr.every(left, (locale, index) => locale === right[index]));
|
|
9
9
|
}
|
|
10
10
|
/** Checks terminal receipt counts against its signed immutable manifest. */
|
|
11
11
|
function hasBoundCompletedReceipt(input) {
|
package/dist/release/head.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ContentFamilySchema, compareContentHeads } from "#contracts/content";
|
|
3
3
|
import { ContentDeliveryClassSchema } from "#contracts/delivery";
|
|
4
4
|
import { ContentKeySchema, CorpusSourcePathSchema, PublicPathSchema, ReleaseIdSchema, Sha256HashSchema, } from "#contracts/ids";
|
|
@@ -76,7 +76,7 @@ export const HeadPageRequestSchema = Schema.Struct({
|
|
|
76
76
|
});
|
|
77
77
|
/** Checks deterministic head order and opaque cursor progress. */
|
|
78
78
|
function hasCanonicalHeadPage(page) {
|
|
79
|
-
const hasCanonicalOrder = page.heads
|
|
79
|
+
const hasCanonicalOrder = Arr.every(page.heads, (head, index) => {
|
|
80
80
|
const previous = page.heads[index - 1];
|
|
81
81
|
return previous === undefined || compareContentHeads(previous, head) < 0;
|
|
82
82
|
});
|
package/dist/release/items.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, MutableRef, Option, Schema, Stream } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, MutableRef, Option, Schema, Stream, } from "effect";
|
|
2
2
|
import { compareContentHeads } from "#contracts/content";
|
|
3
3
|
import { ReleaseIdSchema, Sha256HashSchema } from "#contracts/ids";
|
|
4
4
|
import { digestItems } from "#contracts/release/digest";
|
|
@@ -55,7 +55,7 @@ function validateItemIdentity(manifest, item, expectedIndex) {
|
|
|
55
55
|
expectedIndex,
|
|
56
56
|
}));
|
|
57
57
|
}
|
|
58
|
-
if (!manifest.scope.families
|
|
58
|
+
if (!Arr.contains(manifest.scope.families, item.change.family)) {
|
|
59
59
|
return Effect.fail(new ReleaseItemScopeError({ itemOffset: expectedIndex }));
|
|
60
60
|
}
|
|
61
61
|
return Effect.void;
|
package/dist/release/policy.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
2
2
|
import { ContentFamilySchema } from "#contracts/content";
|
|
3
3
|
import { ActiveAppLocaleListSchema } from "#contracts/locale";
|
|
4
4
|
import { ContentSnapshotKindSchema, } from "#contracts/release/snapshot/scope";
|
|
@@ -24,7 +24,7 @@ export class ReleasePolicyClosureError extends Schema.TaggedError()("ReleasePoli
|
|
|
24
24
|
/** Compares locale lists without exchanging their branded element roles. */
|
|
25
25
|
function hasSameLocaleCodes(left, right) {
|
|
26
26
|
return (left.length === right.length &&
|
|
27
|
-
|
|
27
|
+
Arr.every(left, (locale, index) => locale === right[index]));
|
|
28
28
|
}
|
|
29
29
|
/** Returns whether two release policies have the same signed identity. */
|
|
30
30
|
function hasSamePolicy(left, right) {
|
|
@@ -38,8 +38,8 @@ function failClosure(input) {
|
|
|
38
38
|
function verifyManifestPolicy(manifest, policy) {
|
|
39
39
|
if (!hasSameLocaleCodes(manifest.manifest.activeAppLocales, policy.activeAppLocales)) {
|
|
40
40
|
return failClosure({
|
|
41
|
-
actual: manifest.manifest.activeAppLocales
|
|
42
|
-
expected: policy.activeAppLocales
|
|
41
|
+
actual: Arr.join(manifest.manifest.activeAppLocales, ","),
|
|
42
|
+
expected: Arr.join(policy.activeAppLocales, ","),
|
|
43
43
|
family: manifest.family,
|
|
44
44
|
field: "activeAppLocales",
|
|
45
45
|
});
|
|
@@ -57,7 +57,7 @@ export const verifyReleasePolicyTransition = Effect.fn("AksaraContracts.verifyRe
|
|
|
57
57
|
const requiresCompleteReplacement = input.basePolicy === null || !hasSamePolicy(input.basePolicy, input.policy);
|
|
58
58
|
if (requiresCompleteReplacement) {
|
|
59
59
|
for (const family of ContentFamilySchema.literals) {
|
|
60
|
-
if (!input.scope.families
|
|
60
|
+
if (!Arr.contains(input.scope.families, family)) {
|
|
61
61
|
return yield* failClosure({
|
|
62
62
|
actual: "partial",
|
|
63
63
|
expected: "complete-family",
|
|
@@ -68,7 +68,7 @@ export const verifyReleasePolicyTransition = Effect.fn("AksaraContracts.verifyRe
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
for (const family of ContentSnapshotKindSchema.literals) {
|
|
71
|
-
const manifests = input.manifests
|
|
71
|
+
const manifests = Arr.filter(input.manifests, (candidate) => candidate.family === family);
|
|
72
72
|
if (manifests.length > 1) {
|
|
73
73
|
return yield* failClosure({
|
|
74
74
|
actual: String(manifests.length),
|
|
@@ -105,7 +105,7 @@ export const verifyRendererPolicyTransition = Effect.fn("AksaraContracts.verifyR
|
|
|
105
105
|
return;
|
|
106
106
|
}
|
|
107
107
|
for (const family of ContentFamilySchema.literals) {
|
|
108
|
-
if (!input.scope.families
|
|
108
|
+
if (!Arr.contains(input.scope.families, family)) {
|
|
109
109
|
return yield* failClosure({
|
|
110
110
|
actual: "partial",
|
|
111
111
|
expected: "complete-family",
|
|
@@ -115,7 +115,7 @@ export const verifyRendererPolicyTransition = Effect.fn("AksaraContracts.verifyR
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
if (input.baseTryoutSnapshotId !== null &&
|
|
118
|
-
!input.scope.snapshots
|
|
118
|
+
!Arr.contains(input.scope.snapshots, "tryout")) {
|
|
119
119
|
return yield* failClosure({
|
|
120
120
|
actual: "missing",
|
|
121
121
|
expected: "renderer-refresh",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Option, Schema } from "effect";
|
|
2
2
|
import { ContentFamilySchema, canonicalizeSignedContentArtifact, SignedContentArtifactSchema, } from "#contracts/content";
|
|
3
3
|
import { ContentKeySchema, ReleaseIdSchema, Sha256HashSchema, } from "#contracts/ids";
|
|
4
4
|
import { ContentProjectionSchema, canonicalizeContentProjection, familyForProjection, projectionArtifactLocale, } from "#contracts/projection/spec";
|
|
@@ -111,14 +111,14 @@ export const RollbackPageRequestSchema = Schema.Struct({
|
|
|
111
111
|
});
|
|
112
112
|
/** Checks that one response describes a real final or progressing page. */
|
|
113
113
|
function hasCoherentRollbackPage(page) {
|
|
114
|
-
const
|
|
115
|
-
const last = page.records
|
|
116
|
-
if (
|
|
114
|
+
const first = Arr.head(page.records);
|
|
115
|
+
const last = Arr.last(page.records);
|
|
116
|
+
if (Option.isNone(first) || Option.isNone(last)) {
|
|
117
117
|
return page.done && page.nextIndex === -1 && page.total === 0;
|
|
118
118
|
}
|
|
119
|
-
const hasContiguousRecords = page.records
|
|
119
|
+
const hasContiguousRecords = Arr.every(page.records, (record, offset) => record.index === first.value.index + offset);
|
|
120
120
|
return (hasContiguousRecords &&
|
|
121
|
-
last.index === page.nextIndex &&
|
|
121
|
+
last.value.index === page.nextIndex &&
|
|
122
122
|
page.nextIndex < page.total &&
|
|
123
123
|
page.done === (page.nextIndex + 1 === page.total));
|
|
124
124
|
}
|
|
@@ -151,7 +151,6 @@ export function canonicalizeRollbackRecord(record) {
|
|
|
151
151
|
}
|
|
152
152
|
/** Serializes the complete body-bearing page for an exact byte ceiling. */
|
|
153
153
|
export function canonicalizeRollbackPage(page) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
.join(",")}],"rollbackOfManifestHash":${encodeJsonText(page.rollbackOfManifestHash)},"rollbackOf":${encodeJsonText(page.rollbackOf)},"total":${page.total}}`;
|
|
154
|
+
const records = Arr.join(Arr.map(page.records, canonicalizeRollbackRecord), ",");
|
|
155
|
+
return `{"done":${page.done},"nextIndex":${page.nextIndex},"records":[${records}],"rollbackOfManifestHash":${encodeJsonText(page.rollbackOfManifestHash)},"rollbackOf":${encodeJsonText(page.rollbackOf)},"total":${page.total}}`;
|
|
157
156
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Option, Schema } from "effect";
|
|
2
2
|
import { ContentKeySchema, ReleaseIdSchema, Sha256HashSchema, } from "#contracts/ids";
|
|
3
3
|
import { ContentRouteItemSchema } from "#contracts/release/route/spec";
|
|
4
4
|
/** Maximum route rollback records returned by one target page. */
|
|
@@ -22,14 +22,14 @@ export const RoutePageRequestSchema = Schema.Struct({
|
|
|
22
22
|
});
|
|
23
23
|
/** Checks stable total and contiguous signed route indexes. */
|
|
24
24
|
function hasCoherentRoutePage(page) {
|
|
25
|
-
const
|
|
26
|
-
const last = page.records
|
|
27
|
-
if (
|
|
25
|
+
const first = Arr.head(page.records);
|
|
26
|
+
const last = Arr.last(page.records);
|
|
27
|
+
if (Option.isNone(first) || Option.isNone(last)) {
|
|
28
28
|
return page.done && page.nextIndex === -1 && page.total === 0;
|
|
29
29
|
}
|
|
30
|
-
const contiguous = page.records
|
|
30
|
+
const contiguous = Arr.every(page.records, (record, offset) => record.current.index === first.value.current.index + offset);
|
|
31
31
|
return (contiguous &&
|
|
32
|
-
last.current.index === page.nextIndex &&
|
|
32
|
+
last.value.current.index === page.nextIndex &&
|
|
33
33
|
page.nextIndex < page.total &&
|
|
34
34
|
page.done === (page.nextIndex + 1 === page.total));
|
|
35
35
|
}
|