@nakafa/aksara-contracts 0.48.0 → 0.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/graph/identity.js +2 -2
- package/dist/math/arc.js +3 -3
- package/dist/math/base.js +9 -9
- 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 +5 -5
- package/dist/math/precision.js +3 -3
- package/dist/math/proximity.js +15 -12
- package/dist/math/resolution.js +6 -6
- package/dist/math/scene.js +8 -8
- package/dist/math/vector.js +6 -5
- 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 +12 -12
- package/dist/program/spec.js +4 -4
- 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 +2 -2
- 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 +18 -13
- package/dist/quran/snapshot/row/hash.js +6 -6
- package/dist/quran/snapshot/row.js +3 -3
- package/dist/quran/source.js +10 -10
- package/dist/release/current/evidence.js +2 -2
- package/dist/release/head.js +2 -2
- package/dist/release/policy.js +5 -5
- package/dist/release/rollback/spec.js +4 -5
- package/dist/release/route/page.js +2 -2
- package/dist/release/snapshot/scope.js +3 -3
- package/dist/release/snapshot/spec.js +5 -5
- 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/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 +2 -2
- 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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { Effect, Schema, Stream } from "effect";
|
|
2
|
+
import { Array as Arr, Effect, 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,29 @@ 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
|
+
}
|
|
24
28
|
/** Resolves one complete stable current row identity. */
|
|
25
29
|
function rowIdentity(payload) {
|
|
26
30
|
if (payload.kind === "quran-attribution") {
|
|
27
|
-
|
|
31
|
+
const sourceIds = Arr.map(payload.sources, ({ id }) => id);
|
|
32
|
+
return `quran-attribution:${Arr.join(payload.activeAppLocales, ",")}:${Arr.join(sourceIds, ":")}`;
|
|
28
33
|
}
|
|
29
34
|
if (payload.kind === "quran-surah") {
|
|
30
35
|
return `quran-surah:${payload.number}`;
|
|
31
36
|
}
|
|
32
37
|
if (payload.kind === "quran-chunk") {
|
|
33
|
-
return [
|
|
38
|
+
return joinIdentity([
|
|
34
39
|
"quran-chunk",
|
|
35
40
|
payload.surahNumber,
|
|
36
41
|
payload.firstVerse,
|
|
37
42
|
payload.lastVerse,
|
|
38
43
|
payload.firstQuranNumber,
|
|
39
|
-
]
|
|
44
|
+
]);
|
|
40
45
|
}
|
|
41
|
-
return [
|
|
46
|
+
return joinIdentity([
|
|
42
47
|
"quran-search",
|
|
43
48
|
payload.surahNumber,
|
|
44
49
|
payload.appLocale,
|
|
@@ -48,7 +53,7 @@ function rowIdentity(payload) {
|
|
|
48
53
|
payload.graph.conceptId,
|
|
49
54
|
payload.graph.learningObjectId,
|
|
50
55
|
payload.graph.lensId,
|
|
51
|
-
]
|
|
56
|
+
]);
|
|
52
57
|
}
|
|
53
58
|
/** Keeps current locale closure and digest state private to one replay. */
|
|
54
59
|
class QuranDigestState {
|
|
@@ -75,23 +80,23 @@ class QuranDigestState {
|
|
|
75
80
|
/** Returns the only row identity valid at the current stream position. */
|
|
76
81
|
expectedIdentity() {
|
|
77
82
|
if (this.attributionCount === 0) {
|
|
78
|
-
return `quran-attribution:${this.#activeAppLocales
|
|
83
|
+
return `quran-attribution:${Arr.join(this.#activeAppLocales, ",")}:${Arr.join(quranSourceIds(this.#activeAppLocales), ":")}`;
|
|
79
84
|
}
|
|
80
85
|
if (this.#nextSurah <= QURAN_SURAH_COUNT) {
|
|
81
86
|
if (this.#nextSurahVerse === 0) {
|
|
82
87
|
return `quran-surah:${this.#nextSurah}`;
|
|
83
88
|
}
|
|
84
89
|
const lastVerse = Math.min(this.#nextSurahVerse + QURAN_CHUNK_SIZE - 1, this.#surahVerseCount);
|
|
85
|
-
return [
|
|
90
|
+
return joinIdentity([
|
|
86
91
|
"quran-chunk",
|
|
87
92
|
this.#nextSurah,
|
|
88
93
|
this.#nextSurahVerse,
|
|
89
94
|
lastVerse,
|
|
90
95
|
this.#nextQuranNumber,
|
|
91
|
-
]
|
|
96
|
+
]);
|
|
92
97
|
}
|
|
93
98
|
if (this.#nextSearchSurah <= QURAN_SURAH_COUNT) {
|
|
94
|
-
return [
|
|
99
|
+
return joinIdentity([
|
|
95
100
|
"quran-search",
|
|
96
101
|
this.#nextSearchSurah,
|
|
97
102
|
this.#nextSearchLocale,
|
|
@@ -101,7 +106,7 @@ class QuranDigestState {
|
|
|
101
106
|
`concept:quran:surah:${this.#nextSearchSurah}`,
|
|
102
107
|
`lo:quran-surah:${this.#nextSearchSurah}`,
|
|
103
108
|
"lens:quran",
|
|
104
|
-
]
|
|
109
|
+
]);
|
|
105
110
|
}
|
|
106
111
|
return "end";
|
|
107
112
|
}
|
|
@@ -113,8 +118,8 @@ class QuranDigestState {
|
|
|
113
118
|
const expectedTafsir = this.#activeAppLocales.includes(AppLocaleSchema.make("id"))
|
|
114
119
|
? ["id"]
|
|
115
120
|
: [];
|
|
116
|
-
return payload.verses
|
|
117
|
-
encodeJsonText(verse.tafsir
|
|
121
|
+
return Arr.every(payload.verses, (verse) => encodeJsonText(Arr.map(verse.translations, (translation) => translation.appLocale)) === encodeJsonText(this.#activeAppLocales) &&
|
|
122
|
+
encodeJsonText(Arr.map(verse.tafsir, (tafsir) => tafsir.appLocale)) ===
|
|
118
123
|
encodeJsonText(expectedTafsir));
|
|
119
124
|
}
|
|
120
125
|
/** Advances deterministic identity state after one accepted row. */
|
|
@@ -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,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { LearningGraphIdentitySchema } from "#contracts/graph/spec";
|
|
3
3
|
import { PublicPathSchema, Sha256HashSchema } from "#contracts/ids";
|
|
4
4
|
import { APP_LOCALE_CODES, AppLocaleSchema } from "#contracts/locale";
|
|
@@ -13,7 +13,7 @@ export const QuranLocalizedTranslationSchema = Schema.Struct({
|
|
|
13
13
|
});
|
|
14
14
|
/** Checks translation entries for unique canonical app-locale order. */
|
|
15
15
|
function hasCanonicalTranslations(translations) {
|
|
16
|
-
return
|
|
16
|
+
return Arr.every(translations, (translation, index) => {
|
|
17
17
|
const previous = translations[index - 1];
|
|
18
18
|
return (previous === undefined ||
|
|
19
19
|
APP_LOCALE_CODES.indexOf(previous.appLocale) <
|
|
@@ -52,7 +52,7 @@ function hasCoherentChunk(input) {
|
|
|
52
52
|
if (input.lastVerse - input.firstVerse + 1 !== input.verses.length) {
|
|
53
53
|
return false;
|
|
54
54
|
}
|
|
55
|
-
return input.verses
|
|
55
|
+
return Arr.every(input.verses, (verse, index) => verse.number.inSurah === input.firstVerse + index &&
|
|
56
56
|
verse.number.inQuran === input.firstQuranNumber + index);
|
|
57
57
|
}
|
|
58
58
|
/** Immutable bounded runtime row containing ordered verses. */
|
package/dist/quran/source.js
CHANGED
|
@@ -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, appLocaleLiteral, } from "#contracts/locale";
|
|
4
4
|
import { QURAN_SOURCE_IDS, QuranEmbeddedSourceIdSchema, QuranExternalSourceIdSchema, quranNameSourceId, quranTafsirSourceId, quranTranslationSourceId, } from "#contracts/quran/identity";
|
|
@@ -6,7 +6,7 @@ import { QURAN_SURAH_COUNT, QuranExternalTafsirLocaleSchema, QuranTafsirLocaleSc
|
|
|
6
6
|
import { isHttpsUrl } from "#contracts/text/syntax";
|
|
7
7
|
/** Derives the exact source identities required by one active locale set. */
|
|
8
8
|
export function quranSourceIds(activeAppLocales) {
|
|
9
|
-
const sourceIds =
|
|
9
|
+
const sourceIds = Arr.flatMap(activeAppLocales, (appLocale) => [
|
|
10
10
|
quranNameSourceId(appLocale),
|
|
11
11
|
quranTranslationSourceId(appLocale),
|
|
12
12
|
quranTafsirSourceId(appLocale),
|
|
@@ -14,12 +14,12 @@ export function quranSourceIds(activeAppLocales) {
|
|
|
14
14
|
return [
|
|
15
15
|
"tanzil-text",
|
|
16
16
|
"tanzil-metadata",
|
|
17
|
-
...QURAN_SOURCE_IDS.slice(2)
|
|
17
|
+
...Arr.filter(QURAN_SOURCE_IDS.slice(2), (sourceId) => sourceIds.includes(sourceId)),
|
|
18
18
|
];
|
|
19
19
|
}
|
|
20
20
|
/** Counts exact source files required by one active locale set. */
|
|
21
21
|
export function quranSourceFileCount(activeAppLocales) {
|
|
22
|
-
const supplementalNameFileCount =
|
|
22
|
+
const supplementalNameFileCount = Arr.filter(activeAppLocales, (appLocale) => quranNameSourceId(appLocale) !== "tanzil-metadata").length;
|
|
23
23
|
const tafsirFileCount = activeAppLocales.includes(AppLocaleSchema.make("id"))
|
|
24
24
|
? QURAN_SURAH_COUNT
|
|
25
25
|
: 0;
|
|
@@ -103,7 +103,7 @@ export const QuranTafsirAccessSchema = Schema.Union([
|
|
|
103
103
|
]);
|
|
104
104
|
/** Checks source identities for uniqueness and canonical contract order. */
|
|
105
105
|
function hasCanonicalSources(sources) {
|
|
106
|
-
return
|
|
106
|
+
return Arr.every(sources, (source, index) => {
|
|
107
107
|
const previous = sources[index - 1];
|
|
108
108
|
return (previous === undefined ||
|
|
109
109
|
QURAN_SOURCE_IDS.indexOf(previous.id) <
|
|
@@ -113,20 +113,20 @@ function hasCanonicalSources(sources) {
|
|
|
113
113
|
/** Checks every source copy against the exact active locale set and order. */
|
|
114
114
|
export function hasCompleteQuranSourceCopy(source, activeAppLocales) {
|
|
115
115
|
return (source.copy.length === activeAppLocales.length &&
|
|
116
|
-
source.copy
|
|
116
|
+
Arr.every(source.copy, ({ appLocale }, index) => appLocale === activeAppLocales[index]));
|
|
117
117
|
}
|
|
118
118
|
/** Checks localized copy closure across every selected official source. */
|
|
119
119
|
function hasCompleteLocalizedCopy(input) {
|
|
120
|
-
return input.sources
|
|
120
|
+
return Arr.every(input.sources, (source) => hasCompleteQuranSourceCopy(source, input.activeAppLocales));
|
|
121
121
|
}
|
|
122
122
|
/** Checks every signed Tafsir access record against one attributed source. */
|
|
123
123
|
function hasAttributedTafsirSources(input) {
|
|
124
|
-
return input.tafsirAccess
|
|
124
|
+
return Arr.every(input.tafsirAccess, (access) => Arr.some(input.sources, (source) => source.id === access.sourceId));
|
|
125
125
|
}
|
|
126
126
|
/** Checks exact Tafsir access coverage against one active locale set. */
|
|
127
127
|
export function hasCompleteQuranTafsirAccess(access, activeAppLocales) {
|
|
128
128
|
return (access.length === activeAppLocales.length &&
|
|
129
|
-
|
|
129
|
+
Arr.every(access, ({ appLocale }, index) => appLocale === activeAppLocales[index]));
|
|
130
130
|
}
|
|
131
131
|
/** Visible attribution row carrying the active official source subset. */
|
|
132
132
|
export const QuranAttributionRowSchema = Schema.Struct({
|
|
@@ -149,5 +149,5 @@ export const QuranAttributionRowSchema = Schema.Struct({
|
|
|
149
149
|
export function hasRequiredQuranSources(sources, activeAppLocales) {
|
|
150
150
|
const expected = quranSourceIds(activeAppLocales);
|
|
151
151
|
return (sources.length === expected.length &&
|
|
152
|
-
|
|
152
|
+
Arr.every(sources, ({ id }, index) => id === expected[index]));
|
|
153
153
|
}
|
|
@@ -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/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
|
});
|
|
@@ -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),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, 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";
|
|
@@ -116,7 +116,7 @@ function hasCoherentRollbackPage(page) {
|
|
|
116
116
|
if (!(first && 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.index + offset);
|
|
120
120
|
return (hasContiguousRecords &&
|
|
121
121
|
last.index === page.nextIndex &&
|
|
122
122
|
page.nextIndex < page.total &&
|
|
@@ -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, 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. */
|
|
@@ -27,7 +27,7 @@ function hasCoherentRoutePage(page) {
|
|
|
27
27
|
if (!(first && 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.current.index + offset);
|
|
31
31
|
return (contiguous &&
|
|
32
32
|
last.current.index === page.nextIndex &&
|
|
33
33
|
page.nextIndex < page.total &&
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ContentFamilySchema } from "#contracts/content";
|
|
3
3
|
/** Fixed structured families selected by the one global release pointer. */
|
|
4
4
|
export const ContentSnapshotKindSchema = Schema.Literals([
|
|
@@ -8,13 +8,13 @@ export const ContentSnapshotKindSchema = Schema.Literals([
|
|
|
8
8
|
]);
|
|
9
9
|
/** Checks strict canonical ordering for selected content and snapshot families. */
|
|
10
10
|
function hasCanonicalPublicationScope(input) {
|
|
11
|
-
const snapshotsAreCanonical = input.snapshots
|
|
11
|
+
const snapshotsAreCanonical = Arr.every(input.snapshots, (family, index) => {
|
|
12
12
|
const previous = input.snapshots[index - 1];
|
|
13
13
|
return (previous === undefined ||
|
|
14
14
|
ContentSnapshotKindSchema.literals.indexOf(previous) <
|
|
15
15
|
ContentSnapshotKindSchema.literals.indexOf(family));
|
|
16
16
|
});
|
|
17
|
-
const familiesAreCanonical = input.families
|
|
17
|
+
const familiesAreCanonical = Arr.every(input.families, (family, index) => {
|
|
18
18
|
const previous = input.families[index - 1];
|
|
19
19
|
return (previous === undefined ||
|
|
20
20
|
ContentFamilySchema.literals.indexOf(previous) <
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Signed structured snapshot transition contracts. */
|
|
2
|
-
import { Record as Rec, Schema } from "effect";
|
|
2
|
+
import { Array as Arr, Record as Rec, Schema } from "effect";
|
|
3
3
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
4
4
|
import { ContentSnapshotKindSchema, } from "#contracts/release/snapshot/scope";
|
|
5
5
|
import { encodeJsonText } from "#contracts/text/json";
|
|
@@ -24,7 +24,7 @@ export const ContentSnapshotSetSchema = Schema.Struct({
|
|
|
24
24
|
});
|
|
25
25
|
/** Requires every unselected structured family to remain inherited. */
|
|
26
26
|
export function hasScopedSnapshotTransitions(scope, snapshots) {
|
|
27
|
-
return ContentSnapshotKindSchema.literals
|
|
27
|
+
return Arr.every(ContentSnapshotKindSchema.literals, (family) => scope.snapshots.includes(family) || snapshots[family].mode === "inherit");
|
|
28
28
|
}
|
|
29
29
|
/** Checks inheritance, replacement, and forward restore row semantics. */
|
|
30
30
|
export function hasCoherentSnapshotState(state) {
|
|
@@ -98,15 +98,15 @@ export function invertContentSnapshots(snapshots) {
|
|
|
98
98
|
}
|
|
99
99
|
/** Checks that an initial release does not claim an unstated snapshot base. */
|
|
100
100
|
export function hasEmptySnapshotBases(snapshots) {
|
|
101
|
-
return Rec.values(snapshots)
|
|
101
|
+
return Arr.every(Rec.values(snapshots), ({ baseSnapshotId }) => baseSnapshotId === null);
|
|
102
102
|
}
|
|
103
103
|
/** Checks that a rollback only inherits or restores immutable snapshots. */
|
|
104
104
|
export function hasRollbackSnapshotModes(snapshots) {
|
|
105
|
-
return Rec.values(snapshots)
|
|
105
|
+
return Arr.every(Rec.values(snapshots), ({ mode }) => mode !== "replace");
|
|
106
106
|
}
|
|
107
107
|
/** Checks that reviewed Git sources only inherit or replace snapshots. */
|
|
108
108
|
export function hasGitSnapshotModes(snapshots) {
|
|
109
|
-
return Rec.values(snapshots)
|
|
109
|
+
return Arr.every(Rec.values(snapshots), ({ mode }) => mode !== "restore");
|
|
110
110
|
}
|
|
111
111
|
/** Returns the number of rows that must be staged for this release. */
|
|
112
112
|
export function snapshotRowCount(snapshots) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Order, Schema } from "effect";
|
|
2
2
|
import { compareCodeUnits } from "#contracts/text/order";
|
|
3
3
|
const COMPONENT_NAME_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/;
|
|
4
4
|
/** Renderer names identify one current implementation, never member paths. */
|
|
@@ -20,5 +20,5 @@ export const RendererComponentsSchema = Schema.Array(RendererComponentNameSchema
|
|
|
20
20
|
}));
|
|
21
21
|
/** Sorts current names without discarding duplicate input. */
|
|
22
22
|
export function sortRendererComponents(names) {
|
|
23
|
-
return
|
|
23
|
+
return Arr.sort(names, Order.String);
|
|
24
24
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Effect, HashSet, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, HashSet, Option, Order, Schema } from "effect";
|
|
2
2
|
import { Sha256HashSchema } from "#contracts/ids";
|
|
3
3
|
import { RendererComponentsSchema, } from "#contracts/renderer/component";
|
|
4
4
|
import { RENDERER_DOMAINS, RendererDomainSchema, } from "#contracts/renderer/domain";
|
|
5
5
|
import { encodeJsonText } from "#contracts/text/json";
|
|
6
|
-
import { compareCodeUnits } from "#contracts/text/order";
|
|
7
6
|
/** Stable format for the one current domain-scoped renderer manifest. */
|
|
8
7
|
export const RENDERER_MANIFEST_FORMAT = "nakafa-mdx-renderer";
|
|
9
8
|
/** One route-domain component contract with an exact real domain name. */
|
|
@@ -13,8 +12,8 @@ export const RendererDomainCapabilitySchema = Schema.Struct({
|
|
|
13
12
|
});
|
|
14
13
|
/** Checks published route domains are unique and ordered by code unit. */
|
|
15
14
|
function hasCanonicalPublishedDomains(domains) {
|
|
16
|
-
const canonical =
|
|
17
|
-
return
|
|
15
|
+
const canonical = Arr.sort(domains, Order.String);
|
|
16
|
+
return Arr.every(domains, (domain, index) => domain === canonical[index] && domain !== domains[index - 1]);
|
|
18
17
|
}
|
|
19
18
|
/** Canonical route domains that the deployed Nakafa app can publish. */
|
|
20
19
|
export const RendererPublishedDomainsSchema = Schema.Array(RendererDomainSchema).pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.makeFilter(hasCanonicalPublishedDomains, {
|
|
@@ -22,11 +21,11 @@ export const RendererPublishedDomainsSchema = Schema.Array(RendererDomainSchema)
|
|
|
22
21
|
})));
|
|
23
22
|
/** Sorts route-domain registries with cross-machine code-unit ordering. */
|
|
24
23
|
export function sortRendererDomains(domains) {
|
|
25
|
-
return
|
|
24
|
+
return Arr.sortWith(domains, (domain) => domain.name, Order.String);
|
|
26
25
|
}
|
|
27
26
|
/** Complete current domain set shared by published and deployed manifests. */
|
|
28
27
|
export const RendererManifestDomainsSchema = Schema.Array(RendererDomainCapabilitySchema).check(Schema.makeFilter((domains) => domains.length === RENDERER_DOMAINS.length &&
|
|
29
|
-
|
|
28
|
+
Arr.every(domains, ({ name }, index) => name === RENDERER_DOMAINS[index]), {
|
|
30
29
|
message: "Expected every renderer domain exactly once in canonical order.",
|
|
31
30
|
}));
|
|
32
31
|
/** Keeps base component names out of every route-owned registry. */
|
|
@@ -56,11 +55,11 @@ export class RendererDomainCapabilityMissingError extends Schema.TaggedError()("
|
|
|
56
55
|
}
|
|
57
56
|
/** Selects the one physical route registry authorized for a document. */
|
|
58
57
|
export const selectRendererDomainCapability = Effect.fn("AksaraContracts.selectRendererDomainCapability")(function* (manifest, rendererDomain) {
|
|
59
|
-
const capability = manifest.domains
|
|
60
|
-
if (
|
|
58
|
+
const capability = Arr.findFirst(manifest.domains, ({ name }) => name === rendererDomain);
|
|
59
|
+
if (Option.isNone(capability)) {
|
|
61
60
|
return yield* new RendererDomainCapabilityMissingError({ rendererDomain });
|
|
62
61
|
}
|
|
63
|
-
return capability;
|
|
62
|
+
return capability.value;
|
|
64
63
|
});
|
|
65
64
|
/** SHA-256 could not be calculated for the renderer contract bytes. */
|
|
66
65
|
export class RendererManifestHashComputeError extends Schema.TaggedError()("RendererManifestHashComputeError", { cause: Schema.Unknown }) {
|
|
@@ -76,7 +75,7 @@ export function canonicalizeRendererManifestContract(input) {
|
|
|
76
75
|
return encodeJsonText([
|
|
77
76
|
RENDERER_MANIFEST_FORMAT,
|
|
78
77
|
input.base,
|
|
79
|
-
sortRendererDomains(input.domains)
|
|
78
|
+
Arr.map(sortRendererDomains(input.domains), ({ name, components }) => ({
|
|
80
79
|
components,
|
|
81
80
|
name,
|
|
82
81
|
})),
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Order, Schema } from "effect";
|
|
2
2
|
import { decodeContract } from "#contracts/decode";
|
|
3
3
|
import { hashText } from "#contracts/hash/text";
|
|
4
4
|
import { RendererComponentNameSchema, sortRendererComponents, } from "#contracts/renderer/component";
|
|
5
5
|
import { canonicalizeRendererManifestContract, RENDERER_MANIFEST_FORMAT, RendererManifestDomainsSchema, RendererManifestEnvelopeSchema, RendererManifestHashComputeError, RendererManifestHashMismatchError, sortRendererDomains, } from "#contracts/renderer/contract";
|
|
6
6
|
import { RendererDomainSchema } from "#contracts/renderer/domain";
|
|
7
|
-
import { compareCodeUnits } from "#contracts/text/order";
|
|
8
7
|
const RendererManifestCreationSchema = Schema.Struct({
|
|
9
8
|
base: Schema.Array(RendererComponentNameSchema),
|
|
10
9
|
domains: Schema.Array(Schema.Struct({
|
|
@@ -18,14 +17,14 @@ const hashRendererContract = Effect.fn("AksaraContracts.hashRendererContract")((
|
|
|
18
17
|
/** Creates a complete authenticated manifest from one current name set. */
|
|
19
18
|
export const createRendererManifest = Effect.fn("AksaraContracts.createRendererManifest")(function* (input) {
|
|
20
19
|
const wire = yield* decodeContract(RendererManifestCreationSchema, "RendererManifestCreation", input);
|
|
21
|
-
const domains = yield* decodeContract(RendererManifestDomainsSchema, "RendererManifestDomains", sortRendererDomains(wire.domains
|
|
20
|
+
const domains = yield* decodeContract(RendererManifestDomainsSchema, "RendererManifestDomains", sortRendererDomains(Arr.map(wire.domains, ({ name, components }) => ({
|
|
22
21
|
components: sortRendererComponents(components),
|
|
23
22
|
name,
|
|
24
23
|
}))));
|
|
25
24
|
const contract = {
|
|
26
25
|
base: sortRendererComponents(wire.base),
|
|
27
26
|
domains,
|
|
28
|
-
publishedDomains:
|
|
27
|
+
publishedDomains: Arr.sort(wire.publishedDomains, Order.String),
|
|
29
28
|
};
|
|
30
29
|
const hash = yield* hashRendererContract(contract);
|
|
31
30
|
return yield* decodeContract(RendererManifestEnvelopeSchema, "RendererManifestEnvelope", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, HashSet, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, HashSet, Schema } from "effect";
|
|
2
2
|
import { SignedContentArtifactSchema, } from "#contracts/content";
|
|
3
3
|
import { decodeContract } from "#contracts/decode";
|
|
4
4
|
import { ContentKeySchema, CorpusSourcePathSchema, Sha256HashSchema, } from "#contracts/ids";
|
|
@@ -32,7 +32,7 @@ export const ProtectedContentRuntimeSelectorSchema = Schema.Struct({
|
|
|
32
32
|
})));
|
|
33
33
|
/** Checks a batch never requests the same immutable artifact twice. */
|
|
34
34
|
function hasUniqueSelectors(selectors) {
|
|
35
|
-
const hashes =
|
|
35
|
+
const hashes = Arr.map(selectors, ({ artifactHash }) => artifactHash);
|
|
36
36
|
return HashSet.size(HashSet.fromIterable(hashes)) === hashes.length;
|
|
37
37
|
}
|
|
38
38
|
const ProtectedContentRuntimeSelectorsSchema = Schema.Array(ProtectedContentRuntimeSelectorSchema).pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.isMaxLength(MAX_PROTECTED_RUNTIME_SELECTORS)), Schema.check(Schema.makeFilter(hasUniqueSelectors, {
|
|
@@ -52,7 +52,7 @@ export const ProtectedContentRuntimeItemSchema = Schema.Struct({
|
|
|
52
52
|
});
|
|
53
53
|
/** Checks one protected response never repeats an immutable artifact. */
|
|
54
54
|
function hasUniqueArtifacts(items) {
|
|
55
|
-
const hashes =
|
|
55
|
+
const hashes = Arr.map(items, ({ artifact }) => artifact.artifactHash);
|
|
56
56
|
return HashSet.size(HashSet.fromIterable(hashes)) === hashes.length;
|
|
57
57
|
}
|
|
58
58
|
const ProtectedContentRuntimeItemsSchema = Schema.Array(ProtectedContentRuntimeItemSchema).pipe(Schema.check(Schema.isMinLength(1)), Schema.check(Schema.isMaxLength(MAX_PROTECTED_RUNTIME_SELECTORS)), Schema.check(Schema.makeFilter(hasUniqueArtifacts, {
|
package/dist/runtime/verify.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect } from "effect";
|
|
1
|
+
import { Array as Arr, Effect } from "effect";
|
|
2
2
|
import { verifySignedContentArtifact } from "#contracts/artifact/verify";
|
|
3
3
|
import { hashContentProjection } from "#contracts/projection/hash";
|
|
4
4
|
import { verifyContentReleaseBundle } from "#contracts/release/verify";
|
|
@@ -15,7 +15,7 @@ function hasArticleSourcePath(projection, sourcePath) {
|
|
|
15
15
|
}
|
|
16
16
|
const sourceRoot = sourcePath.slice(prefix.length, -suffix.length);
|
|
17
17
|
const segments = sourceRoot.split("/");
|
|
18
|
-
return segments.length === 2 &&
|
|
18
|
+
return (segments.length === 2 && Arr.join(segments, "-") === projection.articleSlug);
|
|
19
19
|
}
|
|
20
20
|
/** Checks one page path matches its signed source-owned provenance. */
|
|
21
21
|
function hasPageSourcePath(projection, sourcePath) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Effect, Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Effect, Schema } from "effect";
|
|
2
2
|
import { SigningKeyIdSchema } from "#contracts/ids";
|
|
3
3
|
import { ContentVerificationKeyResolver, SigningKeyNotFoundError, SigningKeyResolutionError, } from "#contracts/signature/spec";
|
|
4
4
|
/** One code-reviewed Ed25519 public key retained for release verification. */
|
|
@@ -16,10 +16,10 @@ export const ACTIVE_SIGNING_KEY_ID = ACTIVE_CONTENT_KEY.keyId;
|
|
|
16
16
|
export const TRUSTED_CONTENT_KEYS = Object.freeze([ACTIVE_CONTENT_KEY]);
|
|
17
17
|
/** Builds an immutable exact-ID resolver from code-owned retained entries. */
|
|
18
18
|
export function makeTrustedKeyResolver(entries) {
|
|
19
|
-
const retained =
|
|
19
|
+
const retained = Arr.map(entries, (entry) => ({ ...entry }));
|
|
20
20
|
return ContentVerificationKeyResolver.of({
|
|
21
21
|
resolve: (keyId) => {
|
|
22
|
-
const [match, ...duplicates] =
|
|
22
|
+
const [match, ...duplicates] = Arr.filter(retained, (entry) => entry.keyId === keyId);
|
|
23
23
|
if (match === undefined) {
|
|
24
24
|
return Effect.fail(new SigningKeyNotFoundError({ keyId }));
|
|
25
25
|
}
|
package/dist/transport/batch.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { SignedContentArtifactSchema } from "#contracts/content";
|
|
3
3
|
import { ReleaseIdSchema } from "#contracts/ids";
|
|
4
4
|
import { ContentProjectionSchema } from "#contracts/projection/spec";
|
|
@@ -15,7 +15,7 @@ const StageItemBatchFields = {
|
|
|
15
15
|
/** Checks batch ownership and contiguous signed item indexes. */
|
|
16
16
|
function hasBoundReleaseItems(input) {
|
|
17
17
|
const [first] = input.items;
|
|
18
|
-
return input.items
|
|
18
|
+
return Arr.every(input.items, (item, offset) => item.releaseId === input.releaseId && item.index === first.index + offset);
|
|
19
19
|
}
|
|
20
20
|
/** Canonical input for one bounded ordered-item staging operation. */
|
|
21
21
|
export const StageItemBatchInputSchema = Schema.Struct(StageItemBatchFields).pipe(Schema.check(Schema.makeFilter(hasBoundReleaseItems, {
|
|
@@ -42,7 +42,7 @@ const StageRouteBatchFields = {
|
|
|
42
42
|
/** Checks batch ownership and contiguous signed route indexes. */
|
|
43
43
|
function hasBoundRouteItems(input) {
|
|
44
44
|
const [first] = input.routes;
|
|
45
|
-
return input.routes
|
|
45
|
+
return Arr.every(input.routes, (route, offset) => route.releaseId === input.releaseId &&
|
|
46
46
|
route.index === first.index + offset);
|
|
47
47
|
}
|
|
48
48
|
/** Canonical input for one bounded ordered-route staging operation. */
|
package/dist/transport/group.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ReleaseIdSchema } from "#contracts/ids";
|
|
3
3
|
import { StageArtifactBatchRequestSchema, StageItemBatchRequestSchema, StageProjectionBatchRequestSchema, StageRouteBatchRequestSchema, } from "#contracts/transport/batch";
|
|
4
4
|
import { MAX_STAGE_GROUP_COUNT } from "#contracts/transport/limits";
|
|
@@ -20,7 +20,7 @@ const StageGroupFields = {
|
|
|
20
20
|
};
|
|
21
21
|
/** Requires every grouped transaction to belong to the outer release. */
|
|
22
22
|
function hasBoundRequests(input) {
|
|
23
|
-
return input.requests
|
|
23
|
+
return Arr.every(input.requests, (request) => request.releaseId === input.releaseId);
|
|
24
24
|
}
|
|
25
25
|
/** Canonical target input for one bounded authenticated request group. */
|
|
26
26
|
export const StageGroupInputSchema = Schema.Struct(StageGroupFields).pipe(Schema.check(Schema.makeFilter(hasBoundRequests, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from "effect";
|
|
1
|
+
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ReleaseIdSchema, Sha256HashSchema } from "#contracts/ids";
|
|
3
3
|
import { ContentSnapshotManifestSchema, ContentSnapshotRowSchema, } from "#contracts/release/snapshot/data";
|
|
4
4
|
import { ContentSnapshotKindSchema } from "#contracts/release/snapshot/scope";
|
|
@@ -27,7 +27,7 @@ const StageSnapshotBatchFields = {
|
|
|
27
27
|
};
|
|
28
28
|
/** Checks that every row belongs to the envelope and Quran snapshot identity. */
|
|
29
29
|
function hasBoundSnapshotRows(input) {
|
|
30
|
-
return input.rows
|
|
30
|
+
return Arr.every(input.rows, (row) => {
|
|
31
31
|
if (row.family !== input.family) {
|
|
32
32
|
return false;
|
|
33
33
|
}
|