@nakafa/aksara-contracts 0.48.1 → 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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Checks that a list names members of one canonical list, each at most once,
3
+ * in the canonical order. A value outside the canonical list fails the check.
4
+ */
5
+ export declare function hasCanonicalOrder(canonical: readonly string[], values: readonly string[]): boolean;
@@ -0,0 +1,10 @@
1
+ import { Array as Arr } from "effect";
2
+ /**
3
+ * Checks that a list names members of one canonical list, each at most once,
4
+ * in the canonical order. A value outside the canonical list fails the check.
5
+ */
6
+ export function hasCanonicalOrder(canonical, values) {
7
+ const expected = Arr.filter(canonical, (member) => Arr.some(values, (value) => value === member));
8
+ return (expected.length === values.length &&
9
+ Arr.every(values, (value, index) => value === expected[index]));
10
+ }
package/dist/locale.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Schema } from "effect";
2
+ import { hasCanonicalOrder } from "#contracts/canonical";
2
3
  /** Stable locale codes supported by the current Aksara contract. */
3
4
  export const AppLocaleCodeSchema = Schema.Literals(["en", "id", "de"]);
4
5
  export const [ENGLISH_APP_LOCALE_CODE, INDONESIAN_APP_LOCALE_CODE, GERMAN_APP_LOCALE_CODE,] = AppLocaleCodeSchema.literals;
@@ -35,15 +36,7 @@ export function artifactLocaleCode(artifactLocale) {
35
36
  }
36
37
  /** Checks a nonempty locale subset for uniqueness and canonical order. */
37
38
  function hasCanonicalActiveAppLocales(locales) {
38
- let previousIndex = -1;
39
- for (const locale of locales) {
40
- const index = APP_LOCALE_CODES.indexOf(locale);
41
- if (index <= previousIndex) {
42
- return false;
43
- }
44
- previousIndex = index;
45
- }
46
- return true;
39
+ return hasCanonicalOrder(APP_LOCALE_CODES, locales);
47
40
  }
48
41
  /** Nonempty unique active locale subset in canonical contract order. */
49
42
  export const ActiveAppLocaleListSchema = Schema.NonEmptyArray(AppLocaleSchema).pipe(Schema.check(Schema.makeFilter(hasCanonicalActiveAppLocales, {
package/dist/math/base.js CHANGED
@@ -68,7 +68,7 @@ export function sameSpacePoint(left, right) {
68
68
  function duplicateKeyIndexes(values, keyOf) {
69
69
  const seen = MutableHashSet.empty();
70
70
  const duplicates = MutableList.make();
71
- for (const [index, value] of values.entries()) {
71
+ Arr.forEach(values, (value, index) => {
72
72
  const key = keyOf(value);
73
73
  if (MutableHashSet.has(seen, key)) {
74
74
  MutableList.append(duplicates, index);
@@ -76,7 +76,7 @@ function duplicateKeyIndexes(values, keyOf) {
76
76
  else {
77
77
  MutableHashSet.add(seen, key);
78
78
  }
79
- }
79
+ });
80
80
  return MutableList.toArray(duplicates);
81
81
  }
82
82
  /** Reports every repeated scene identity at its exact authored key path. */
@@ -12,7 +12,7 @@ function hasPlaneArea(vertices) {
12
12
  let twiceArea = 0;
13
13
  let termMagnitude = 0;
14
14
  let previous = { x: 0, y: 0 };
15
- for (const current of offsets.slice(1)) {
15
+ for (const current of Arr.drop(offsets, 1)) {
16
16
  const positive = previous.x * current.y;
17
17
  const negative = previous.y * current.x;
18
18
  twiceArea += positive - negative;
@@ -78,7 +78,7 @@ export function polygonAltitudeUnresolved(vertices, threshold) {
78
78
  z: decimal("z" in point ? point.z : 0),
79
79
  }));
80
80
  const thresholdSquared = BigDecimal.multiply(threshold, threshold);
81
- for (const [index, point] of exact.entries()) {
81
+ return EffectArray.some(exact, (point, index) => {
82
82
  const previous = EffectArray.getUnsafe(exact, (index + exact.length - 1) % exact.length);
83
83
  const next = EffectArray.getUnsafe(exact, (index + 1) % exact.length);
84
84
  const baseline = {
@@ -98,14 +98,11 @@ export function polygonAltitudeUnresolved(vertices, threshold) {
98
98
  };
99
99
  const crossSquared = BigDecimal.sumAll(EffectArray.map(Rec.values(cross), (value) => BigDecimal.multiply(value, value)));
100
100
  if (BigDecimal.isZero(crossSquared)) {
101
- continue;
101
+ return false;
102
102
  }
103
103
  const baselineSquared = BigDecimal.sumAll(EffectArray.map(Rec.values(baseline), (value) => BigDecimal.multiply(value, value)));
104
- if (BigDecimal.isLessThan(crossSquared, BigDecimal.multiply(thresholdSquared, baselineSquared))) {
105
- return true;
106
- }
107
- }
108
- return false;
104
+ return BigDecimal.isLessThan(crossSquared, BigDecimal.multiply(thresholdSquared, baselineSquared));
105
+ });
109
106
  }
110
107
  /** Checks exact quadratic curvature without relying on renderer sampling. */
111
108
  export function quadraticCurvatureUnresolved(coefficient, domainSpan, threshold) {
@@ -138,7 +138,7 @@ export function unresolvedProximityIndexes(entries, threshold) {
138
138
  const leftTree = makeTree(upper.values.length);
139
139
  const rightTree = makeTree(lower.values.length);
140
140
  const unresolved = MutableHashSet.empty();
141
- for (const [sourceIndex, interval] of intervals.entries()) {
141
+ EffectArray.forEach(intervals, (interval, sourceIndex) => {
142
142
  const leftEnd = firstRank(upper.values, interval.lower, false);
143
143
  const closestLeft = queryTree(leftTree, 0, leftEnd, greaterRatio);
144
144
  const rightStart = firstRank(lower.values, interval.upper, true);
@@ -153,6 +153,6 @@ export function unresolvedProximityIndexes(entries, threshold) {
153
153
  }
154
154
  updateTree(leftTree, EffectArray.getUnsafe(upper.ranks, sourceIndex), interval.lower, greaterRatio);
155
155
  updateTree(rightTree, EffectArray.getUnsafe(lower.ranks, sourceIndex), interval.upper, lesserRatio);
156
- }
156
+ });
157
157
  return unresolved;
158
158
  }
@@ -3,19 +3,7 @@ import { GEOMETRY_TOLERANCE } from "#contracts/math/base";
3
3
  /** Checks a space polygon is planar and has non-zero area. */
4
4
  export function hasCoplanarArea(vertices) {
5
5
  const offsets = normalizedSpaceOffsets(vertices);
6
- let strongestNormal;
7
- let strongestLength = 0;
8
- const vectors = offsets.slice(1);
9
- for (const [leftIndex, left] of vectors.entries()) {
10
- for (const right of vectors.slice(leftIndex + 1)) {
11
- const candidate = cross(left, right);
12
- const candidateLength = length(candidate);
13
- if (candidateLength > strongestLength) {
14
- strongestLength = candidateLength;
15
- strongestNormal = candidate;
16
- }
17
- }
18
- }
6
+ const [strongestNormal, strongestLength] = strongestCrossProduct(Arr.drop(offsets, 1));
19
7
  if (!(strongestNormal && strongestLength > GEOMETRY_TOLERANCE)) {
20
8
  return false;
21
9
  }
@@ -23,6 +11,15 @@ export function hasCoplanarArea(vertices) {
23
11
  return Arr.every(offsets, (offset) => Math.abs(dot(unitNormal, offset)) <=
24
12
  GEOMETRY_TOLERANCE * Math.max(1, length(offset)));
25
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
+ }
26
23
  /** Translates before scaling so coplanarity is independent of scene location. */
27
24
  function normalizedSpaceOffsets(vertices) {
28
25
  const [origin] = vertices;
@@ -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.includes(row.appLocale) ||
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
  }
@@ -1,4 +1,5 @@
1
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 Arr.every(translations, (translation, index) => {
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.",
@@ -42,12 +42,14 @@ function parseQuestionSetParts(input) {
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: keys.at(0),
47
- examKey: keys.at(1),
48
- intermediateBankKeys: keys.slice(2, -2),
49
- sectionKey: keys.at(-2),
50
- setKey: keys.at(-1),
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. */
@@ -114,7 +114,7 @@ function analyzeTranslation(source) {
114
114
  referenceOffset: uniqueReferences[index]?.start ?? -1,
115
115
  }));
116
116
  const definitionNumbers = Arr.map(definitions, ({ number }) => number);
117
- const hasDuplicateDefinition = Arr.some(definitionNumbers, (number, index) => definitionNumbers.indexOf(number) !== index);
117
+ const hasDuplicateDefinition = Arr.some(definitionNumbers, (number, index) => Option.getOrUndefined(Arr.findFirstIndex(definitionNumbers, (value) => value === number)) !== index);
118
118
  const hasMismatchedMarkers = hasDuplicateDefinition ||
119
119
  uniqueReferences.length !== definitionNumbers.length ||
120
120
  Arr.some(noteCandidates, ({ definition, referenceOffset }, index) => referenceOffset < 0 ||
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { Array as Arr, 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";
@@ -25,6 +25,10 @@ export class QuranRowOrderError extends Schema.TaggedError()("QuranRowOrderError
25
25
  function joinIdentity(parts) {
26
26
  return Arr.join(Arr.map(parts, String), ":");
27
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
+ }
28
32
  /** Resolves one complete stable current row identity. */
29
33
  function rowIdentity(payload) {
30
34
  if (payload.kind === "quran-attribution") {
@@ -115,7 +119,7 @@ class QuranDigestState {
115
119
  if (payload.kind !== "quran-chunk") {
116
120
  return true;
117
121
  }
118
- const expectedTafsir = this.#activeAppLocales.includes(AppLocaleSchema.make("id"))
122
+ const expectedTafsir = Arr.contains(this.#activeAppLocales, AppLocaleSchema.make("id"))
119
123
  ? ["id"]
120
124
  : [];
121
125
  return Arr.every(payload.verses, (verse) => encodeJsonText(Arr.map(verse.translations, (translation) => translation.appLocale)) === encodeJsonText(this.#activeAppLocales) &&
@@ -142,7 +146,7 @@ class QuranDigestState {
142
146
  this.#nextSurahVerse = payload.lastVerse + 1;
143
147
  return;
144
148
  }
145
- const localeIndex = this.#activeAppLocales.indexOf(this.#nextSearchLocale);
149
+ const localeIndex = Option.getOrThrow(Arr.findFirstIndex(this.#activeAppLocales, (locale) => locale === this.#nextSearchLocale));
146
150
  const nextLocale = this.#activeAppLocales[localeIndex + 1];
147
151
  if (nextLocale !== undefined) {
148
152
  this.#nextSearchLocale = nextLocale;
@@ -204,11 +208,11 @@ class QuranDigestState {
204
208
  attributionCount: this.attributionCount,
205
209
  chunkCount: this.chunkCount,
206
210
  projectionCount: this.projectionCount,
207
- projectionDigest: Sha256HashSchema.make(`sha256:${this.#projection.digest("hex")}`),
211
+ projectionDigest: sha256Digest(this.#projection),
208
212
  runtimeCount: this.runtimeCount,
209
- runtimeDigest: Sha256HashSchema.make(`sha256:${this.#runtime.digest("hex")}`),
213
+ runtimeDigest: sha256Digest(this.#runtime),
210
214
  searchCount: this.searchCount,
211
- searchDigest: Sha256HashSchema.make(`sha256:${this.#search.digest("hex")}`),
215
+ searchDigest: sha256Digest(this.#search),
212
216
  };
213
217
  }
214
218
  }
@@ -1,4 +1,5 @@
1
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 Arr.every(translations, (translation, index) => {
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.",
@@ -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.includes(AppLocaleSchema.make("id"));
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 &&
@@ -1,4 +1,5 @@
1
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";
@@ -14,13 +15,13 @@ export function quranSourceIds(activeAppLocales) {
14
15
  return [
15
16
  "tanzil-text",
16
17
  "tanzil-metadata",
17
- ...Arr.filter(QURAN_SOURCE_IDS.slice(2), (sourceId) => sourceIds.includes(sourceId)),
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
23
  const supplementalNameFileCount = Arr.filter(activeAppLocales, (appLocale) => quranNameSourceId(appLocale) !== "tanzil-metadata").length;
23
- const tafsirFileCount = activeAppLocales.includes(AppLocaleSchema.make("id"))
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,12 +104,7 @@ 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 Arr.every(sources, (source, index) => {
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) {
@@ -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.includes(item.change.family)) {
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;
@@ -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.includes(family)) {
60
+ if (!Arr.contains(input.scope.families, family)) {
61
61
  return yield* failClosure({
62
62
  actual: "partial",
63
63
  expected: "complete-family",
@@ -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.includes(family)) {
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.includes("tryout")) {
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 { Array as Arr, 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 [first] = page.records;
115
- const last = page.records.at(-1);
116
- if (!(first && last)) {
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 = Arr.every(page.records, (record, offset) => record.index === first.index + offset);
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
  }
@@ -1,4 +1,4 @@
1
- import { Array as Arr, 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 [first] = page.records;
26
- const last = page.records.at(-1);
27
- if (!(first && last)) {
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 = Arr.every(page.records, (record, offset) => record.current.index === first.current.index + offset);
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
  }
@@ -1,4 +1,5 @@
1
- import { Array as Arr, Schema } from "effect";
1
+ import { Schema } from "effect";
2
+ import { hasCanonicalOrder } from "#contracts/canonical";
2
3
  import { ContentFamilySchema } from "#contracts/content";
3
4
  /** Fixed structured families selected by the one global release pointer. */
4
5
  export const ContentSnapshotKindSchema = Schema.Literals([
@@ -8,20 +9,8 @@ export const ContentSnapshotKindSchema = Schema.Literals([
8
9
  ]);
9
10
  /** Checks strict canonical ordering for selected content and snapshot families. */
10
11
  function hasCanonicalPublicationScope(input) {
11
- const snapshotsAreCanonical = Arr.every(input.snapshots, (family, index) => {
12
- const previous = input.snapshots[index - 1];
13
- return (previous === undefined ||
14
- ContentSnapshotKindSchema.literals.indexOf(previous) <
15
- ContentSnapshotKindSchema.literals.indexOf(family));
16
- });
17
- const familiesAreCanonical = Arr.every(input.families, (family, index) => {
18
- const previous = input.families[index - 1];
19
- return (previous === undefined ||
20
- ContentFamilySchema.literals.indexOf(previous) <
21
- ContentFamilySchema.literals.indexOf(family));
22
- });
23
- return (familiesAreCanonical &&
24
- snapshotsAreCanonical &&
12
+ return (hasCanonicalOrder(ContentFamilySchema.literals, input.families) &&
13
+ hasCanonicalOrder(ContentSnapshotKindSchema.literals, input.snapshots) &&
25
14
  input.families.length + input.snapshots.length > 0);
26
15
  }
27
16
  /** Whole content and structured families authenticated by one signed release. */
@@ -24,7 +24,8 @@ 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 Arr.every(ContentSnapshotKindSchema.literals, (family) => scope.snapshots.includes(family) || snapshots[family].mode === "inherit");
27
+ return Arr.every(ContentSnapshotKindSchema.literals, (family) => Arr.contains(scope.snapshots, family) ||
28
+ snapshots[family].mode === "inherit");
28
29
  }
29
30
  /** Checks inheritance, replacement, and forward restore row semantics. */
30
31
  export function hasCoherentSnapshotState(state) {
@@ -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
  import { ContentDeliveryClassSchema } from "#contracts/delivery";
4
4
  import { ContentKeySchema, CorpusSourcePathSchema, Ed25519SignatureSchema, ReleaseIdSchema, Sha256HashSchema, SigningKeyIdSchema, } from "#contracts/ids";
@@ -110,7 +110,7 @@ export const SignedContentReleaseSchema = Schema.Struct({
110
110
  });
111
111
  /** Checks whether one application locale is active in a signed release. */
112
112
  export function releaseActivatesAppLocale(release, appLocale) {
113
- return release.manifest.activeAppLocales.includes(appLocale);
113
+ return Arr.contains(release.manifest.activeAppLocales, appLocale);
114
114
  }
115
115
  /** Signed release contract accepted only for rollback-owned operations. */
116
116
  export const RollbackSignedContentReleaseSchema = SignedContentReleaseSchema.pipe(Schema.refine((release) => release.manifest.origin.kind === "rollback", { message: "Expected a signed rollback release." }));
@@ -1,4 +1,4 @@
1
- import { Effect, HashSet, Schema } from "effect";
1
+ import { Array as Arr, Effect, HashSet, Schema } from "effect";
2
2
  import { ArtifactRendererComponentMissingError, ArtifactRendererDomainUnpublishedError, } from "#contracts/artifact/spec";
3
3
  import { RendererComponentNameSchema, } from "#contracts/renderer/component";
4
4
  import { selectRendererDomainCapability, } from "#contracts/renderer/contract";
@@ -37,7 +37,7 @@ export const verifyRendererManifestCompatibility = Effect.fn("AksaraContracts.ve
37
37
  }
38
38
  yield* verifyCapabilitySuperset(input.frozen.base, input.live.base, "base");
39
39
  for (const rendererDomain of input.frozen.publishedDomains) {
40
- if (!input.live.publishedDomains.includes(rendererDomain)) {
40
+ if (!Arr.contains(input.live.publishedDomains, rendererDomain)) {
41
41
  return yield* new RendererManifestDomainUnpublishedError({
42
42
  rendererDomain,
43
43
  });
@@ -51,7 +51,7 @@ export const verifyRendererManifestCompatibility = Effect.fn("AksaraContracts.ve
51
51
  /** Verifies that a deployed live renderer can route and execute one artifact. */
52
52
  export const verifyContentRendererCompatibility = Effect.fn("AksaraContracts.verifyContentRendererCompatibility")(function* ({ payload, rendererManifest, }) {
53
53
  const manifest = yield* validateRendererManifestHash(rendererManifest);
54
- if (!manifest.publishedDomains.includes(payload.rendererDomain)) {
54
+ if (!Arr.contains(manifest.publishedDomains, payload.rendererDomain)) {
55
55
  return yield* new ArtifactRendererDomainUnpublishedError({
56
56
  contentKey: payload.contentKey,
57
57
  rendererDomain: payload.rendererDomain,
@@ -24,20 +24,15 @@ function decodePublicKeyPem(keyId, publicKeyPem, subject) {
24
24
  normalizedPublicKeyPem.trimEnd().endsWith(PUBLIC_KEY_FOOTER))) {
25
25
  return Effect.fail(new PublicKeyParseError({ keyId, subject }));
26
26
  }
27
- return Effect.try({
28
- catch: () => new PublicKeyParseError({ keyId, subject }),
29
- try: () => {
30
- const body = normalizedPublicKeyPem
31
- .slice(PUBLIC_KEY_HEADER.length)
32
- .replace(PUBLIC_KEY_FOOTER, "")
33
- .replaceAll("\n", "")
34
- .trim();
35
- if (!PUBLIC_KEY_BASE64_PATTERN.test(body) || body.length % 4 !== 0) {
36
- throw new TypeError("Invalid public-key base64");
37
- }
38
- return decodeBase64(body);
39
- },
40
- });
27
+ const body = normalizedPublicKeyPem
28
+ .slice(PUBLIC_KEY_HEADER.length)
29
+ .replace(PUBLIC_KEY_FOOTER, "")
30
+ .replaceAll("\n", "")
31
+ .trim();
32
+ if (!PUBLIC_KEY_BASE64_PATTERN.test(body) || body.length % 4 !== 0) {
33
+ return Effect.fail(new PublicKeyParseError({ keyId, subject }));
34
+ }
35
+ return Effect.succeed(decodeBase64(body));
41
36
  }
42
37
  /** Imports one exact Ed25519 SPKI key through Web Crypto. */
43
38
  function importEd25519PublicKey(keyId, publicKeyPem, subject) {
@@ -22,7 +22,7 @@ function localeSetIdentity(locales, activeAppLocales) {
22
22
  }
23
23
  /** Adds one active locale to a logical identity without duplicates. */
24
24
  export function addLocale(localesByIdentity, activeAppLocales, identity, appLocale) {
25
- if (!activeAppLocales.includes(appLocale)) {
25
+ if (!Arr.contains(activeAppLocales, appLocale)) {
26
26
  return Effect.fail(new TryoutClosureError({
27
27
  actual: appLocale,
28
28
  code: "inactive-locale",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nakafa/aksara-contracts",
3
- "version": "0.48.1",
3
+ "version": "0.48.2",
4
4
  "description": "Schemas and verification contracts for Nakafa content releases.",
5
5
  "homepage": "https://github.com/nakafaai/aksara#readme",
6
6
  "license": "SEE LICENSE IN LICENSE",