@nakafa/aksara-contracts 0.47.2 → 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.
Files changed (60) hide show
  1. package/dist/graph/identity.js +2 -2
  2. package/dist/math/arc.js +3 -3
  3. package/dist/math/base.js +9 -9
  4. package/dist/math/bounds.d.ts +1 -1
  5. package/dist/math/bounds.js +13 -12
  6. package/dist/math/collision.js +21 -23
  7. package/dist/math/coordinate.js +3 -3
  8. package/dist/math/extent.js +10 -14
  9. package/dist/math/plane.js +5 -5
  10. package/dist/math/precision.js +3 -3
  11. package/dist/math/proximity.js +15 -12
  12. package/dist/math/resolution.js +6 -6
  13. package/dist/math/scene.js +8 -8
  14. package/dist/math/vector.js +6 -5
  15. package/dist/math/visual.js +2 -2
  16. package/dist/preview/target.js +5 -5
  17. package/dist/program/curriculum.js +3 -3
  18. package/dist/program/snapshot/digest.js +12 -12
  19. package/dist/program/spec.js +4 -4
  20. package/dist/projection/article.js +3 -3
  21. package/dist/projection/material.js +2 -2
  22. package/dist/projection/question.js +2 -2
  23. package/dist/question/answer.js +3 -3
  24. package/dist/question/identity.js +2 -2
  25. package/dist/question/item.js +10 -10
  26. package/dist/question/response.js +12 -12
  27. package/dist/question/rubric.js +9 -9
  28. package/dist/quran/attribution.d.ts +12 -4
  29. package/dist/quran/attribution.js +2 -1
  30. package/dist/quran/notes.js +24 -17
  31. package/dist/quran/provenance.js +14 -13
  32. package/dist/quran/snapshot/digest.js +18 -13
  33. package/dist/quran/snapshot/row/hash.js +6 -6
  34. package/dist/quran/snapshot/row.js +3 -3
  35. package/dist/quran/source.js +10 -10
  36. package/dist/release/current/evidence.js +2 -2
  37. package/dist/release/head.js +2 -2
  38. package/dist/release/policy.js +5 -5
  39. package/dist/release/rollback/spec.js +4 -5
  40. package/dist/release/route/page.js +2 -2
  41. package/dist/release/snapshot/scope.js +3 -3
  42. package/dist/release/snapshot/spec.js +5 -5
  43. package/dist/renderer/component.js +2 -2
  44. package/dist/renderer/contract.js +9 -10
  45. package/dist/renderer/manifest.js +3 -4
  46. package/dist/runtime/protected/spec.js +3 -3
  47. package/dist/runtime/verify.js +2 -2
  48. package/dist/signature/trusted.js +3 -3
  49. package/dist/transport/batch.js +3 -3
  50. package/dist/transport/group.js +2 -2
  51. package/dist/transport/snapshot.js +2 -2
  52. package/dist/tryout/closure/accounting.js +2 -2
  53. package/dist/tryout/hash/catalog.js +5 -5
  54. package/dist/tryout/identity.js +7 -6
  55. package/dist/tryout/language.d.ts +1 -1
  56. package/dist/tryout/language.js +1 -1
  57. package/dist/tryout/scoring.d.ts +3 -3
  58. package/dist/tryout/scoring.js +4 -4
  59. package/dist/tryout/snapshot/hash.js +2 -2
  60. package/package.json +2 -2
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import { Array as Arr, Schema } from "effect";
2
2
  import { CorpusSourcePathSchema, PublicPathSchema } from "#contracts/ids";
3
3
  import { AppLocaleSchema } from "#contracts/locale";
4
4
  import { MaterialDomainSchema } from "#contracts/material/domain";
@@ -98,11 +98,11 @@ function hasCoherentRoute(input) {
98
98
  function hasCoherentMaterialLink(input) {
99
99
  const ownsMaterial = input.materialKey !== undefined;
100
100
  const ownsCanonical = input.canonicalPath !== undefined;
101
- const contextCount = [
101
+ const contextCount = Arr.filter([
102
102
  input.materialContextNodeKey,
103
103
  input.materialContextParentPath,
104
104
  input.materialContextPublicPath,
105
- ].filter((value) => value !== undefined).length;
105
+ ], (value) => value !== undefined).length;
106
106
  if (!ownsMaterial) {
107
107
  return !ownsCanonical && contextCount === 0;
108
108
  }
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { Effect, MutableHashMap, MutableHashSet, Option, Schema, Stream, } from "effect";
2
+ import { Array as Arr, Effect, MutableHashMap, MutableHashSet, Option, Schema, Stream, } from "effect";
3
3
  import { Sha256HashSchema } from "#contracts/ids";
4
4
  import { curriculumNamespace, } from "#contracts/program/curriculum";
5
5
  import { ProgramRowHashError, verifyProgramSnapshotRowHash, } from "#contracts/program/snapshot/hash";
@@ -25,22 +25,22 @@ export class ProgramDigestError extends Schema.TaggedError()("ProgramDigestError
25
25
  }
26
26
  /** Serializes source-derived counts for exact replay comparison. */
27
27
  function countIdentity(counts) {
28
- return [
28
+ const values = [
29
29
  counts.curriculumRowCount,
30
30
  counts.programRowCount,
31
31
  counts.rowCount,
32
32
  counts.sitemapCount,
33
33
  counts.slugCount,
34
- ].join(":");
34
+ ];
35
+ return Arr.join(Arr.map(values, String), ":");
35
36
  }
36
- /** Resolves one required localized program identity. */
37
- function translationFor(program, appLocale) {
38
- return program.translations.find((translation) => translation.appLocale === appLocale);
39
- }
40
- /** Checks that one root is the exact localized route owned by its program. */
37
+ /**
38
+ * Checks that one root is the exact localized route owned by its program.
39
+ * Translation locales are unique, because the catalog row must repeat the
40
+ * signed active locale list, so at most one translation matches the root.
41
+ */
41
42
  function isExactProgramRoot(row, program) {
42
- const translation = translationFor(program, row.appLocale);
43
- return (translation !== undefined &&
43
+ return Arr.some(program.translations, (translation) => translation.appLocale === row.appLocale &&
44
44
  row.iconKey === program.iconKey &&
45
45
  row.order === program.displayOrder &&
46
46
  row.publicPath ===
@@ -99,7 +99,7 @@ class ProgramDigestState {
99
99
  MutableHashSet.size(this.#slugs) ===
100
100
  this.programRowCount * this.#activeAppLocales.length &&
101
101
  MutableHashSet.size(expectedRoots) === MutableHashSet.size(this.#roots) &&
102
- [...expectedRoots].every((root) => MutableHashSet.has(this.#roots, root)) &&
102
+ Arr.every([...expectedRoots], (root) => MutableHashSet.has(this.#roots, root)) &&
103
103
  countIdentity(counts) === countIdentity(expectedCounts)) {
104
104
  return Effect.void;
105
105
  }
@@ -122,7 +122,7 @@ class ProgramDigestState {
122
122
  /** Adds one catalog row before any current curriculum records. */
123
123
  #addProgram(record) {
124
124
  const { row } = record;
125
- const translationLocales = row.translations.map((translation) => translation.appLocale);
125
+ const translationLocales = Arr.map(row.translations, (translation) => translation.appLocale);
126
126
  if (this.curriculumRowCount > 0 ||
127
127
  row.displayOrder <= this.#lastProgramOrder) {
128
128
  return Effect.fail(new ProgramDigestError({ code: "order", identity: row.key }));
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import { Array as Arr, Schema } from "effect";
2
2
  import { CountryCodeSchema } from "#contracts/country";
3
3
  import { DateOnlySchema } from "#contracts/date";
4
4
  import { APP_LOCALE_CODES, AppLocaleSchema } from "#contracts/locale";
@@ -102,7 +102,7 @@ export const ProgramTranslationSchema = Schema.Struct({
102
102
  });
103
103
  /** Checks translations for unique canonical application-locale order. */
104
104
  function hasCanonicalTranslations(translations) {
105
- return translations.every((translation, index) => {
105
+ return Arr.every(translations, (translation, index) => {
106
106
  const previous = translations[index - 1];
107
107
  return (previous === undefined ||
108
108
  APP_LOCALE_CODES.indexOf(previous.appLocale) <
@@ -171,7 +171,7 @@ export function canonicalizeLearningProgram(program) {
171
171
  ...(program.recommendedCountry === undefined
172
172
  ? {}
173
173
  : { recommendedCountry: program.recommendedCountry }),
174
- sources: program.sources.map((source) => ({
174
+ sources: Arr.map(program.sources, (source) => ({
175
175
  label: source.label,
176
176
  retrievedAt: source.retrievedAt,
177
177
  ...(source.reviewAfter === undefined
@@ -180,7 +180,7 @@ export function canonicalizeLearningProgram(program) {
180
180
  type: source.type,
181
181
  url: source.url,
182
182
  })),
183
- translations: program.translations.map((translation) => ({
183
+ translations: Arr.map(program.translations, (translation) => ({
184
184
  appLocale: translation.appLocale,
185
185
  publicSlug: translation.publicSlug,
186
186
  title: translation.title,
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import { Array as Arr, Schema } from "effect";
2
2
  import { ContentAuthorSchema } from "#contracts/content";
3
3
  import { withPublicationDates } from "#contracts/date";
4
4
  import { canonicalizeLearningGraphIdentity, LearningGraphIdentitySchema, } from "#contracts/graph/spec";
@@ -106,7 +106,7 @@ export function makeArticleProjection(input) {
106
106
  /** Serializes one article projection with stable signed field order. */
107
107
  export function canonicalizeArticleProjection(projection) {
108
108
  const metadata = {
109
- authors: projection.metadata.authors.map(({ name }) => ({ name })),
109
+ authors: Arr.map(projection.metadata.authors, ({ name }) => ({ name })),
110
110
  ...(projection.metadata.dateModified === undefined
111
111
  ? {}
112
112
  : { dateModified: projection.metadata.dateModified }),
@@ -131,7 +131,7 @@ export function canonicalizeArticleProjection(projection) {
131
131
  official: projection.official,
132
132
  parentPath: projection.parentPath,
133
133
  publicPath: projection.publicPath,
134
- references: projection.references.map((reference) => ({
134
+ references: Arr.map(projection.references, (reference) => ({
135
135
  authors: reference.authors,
136
136
  ...(reference.citation === undefined
137
137
  ? {}
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import { Array as Arr, Schema } from "effect";
2
2
  import { ContentAuthorSchema } from "#contracts/content";
3
3
  import { withPublicationDates } from "#contracts/date";
4
4
  import { canonicalizeLearningGraphIdentity, LearningGraphIdentitySchema, } from "#contracts/graph/spec";
@@ -142,7 +142,7 @@ export function makeMaterialLessonProjection(route, metadata) {
142
142
  /** Serializes one material projection with stable signed field order. */
143
143
  export function canonicalizeMaterialProjection(projection) {
144
144
  const metadata = {
145
- authors: projection.metadata.authors.map(({ name }) => ({ name })),
145
+ authors: Arr.map(projection.metadata.authors, ({ name }) => ({ name })),
146
146
  ...(projection.metadata.dateModified === undefined
147
147
  ? {}
148
148
  : { dateModified: projection.metadata.dateModified }),
@@ -1,4 +1,4 @@
1
- import { Effect, Schema } from "effect";
1
+ import { Array as Arr, Effect, Schema } from "effect";
2
2
  import { ContentAuthorSchema } from "#contracts/content";
3
3
  import { withPublicationDates } from "#contracts/date";
4
4
  import { ContentKeySchema } from "#contracts/ids";
@@ -103,7 +103,7 @@ export function canonicalizeQuestionProjection(projection) {
103
103
  contentKey: projection.contentKey,
104
104
  kind: projection.kind,
105
105
  metadata: {
106
- authors: projection.metadata.authors.map(({ name }) => ({ name })),
106
+ authors: Arr.map(projection.metadata.authors, ({ name }) => ({ name })),
107
107
  ...(projection.metadata.dateModified === undefined
108
108
  ? {}
109
109
  : { dateModified: projection.metadata.dateModified }),
@@ -1,4 +1,4 @@
1
- import { BigDecimal, HashSet, Option, Schema, String as Str } from "effect";
1
+ import { Array as Arr, BigDecimal, HashSet, Option, Schema, String as Str, } from "effect";
2
2
  const DECIMAL_PATTERN = /^(?:0|-?[1-9]\d*|-?(?:0|[1-9]\d*)\.\d*[1-9])$/u;
3
3
  const UNTYPABLE_CHARACTER_PATTERN = /[\p{Cc}\p{Cf}]|[^\S ]/u;
4
4
  const FORMAT_CHARACTER_PATTERN = /\p{Cf}/gu;
@@ -98,7 +98,7 @@ function normalizeTextAnswer(text, rules) {
98
98
  }
99
99
  /** Checks that no two accepted answers grade as the same normalized text. */
100
100
  function hasDistinctAcceptedAnswers(key) {
101
- const normalized = key.acceptedAnswers.map((text) => normalizeTextAnswer(text, key));
101
+ const normalized = Arr.map(key.acceptedAnswers, (text) => normalizeTextAnswer(text, key));
102
102
  return HashSet.size(HashSet.fromIterable(normalized)) === normalized.length;
103
103
  }
104
104
  /**
@@ -213,7 +213,7 @@ function matchesNumberKey(key, answer) {
213
213
  export function matchesAnswerKey(key, answer, language) {
214
214
  if (key.kind === "text") {
215
215
  const typed = normalizeTextAnswer(answer, key);
216
- return key.acceptedAnswers.some((accepted) => normalizeTextAnswer(accepted, key) === typed);
216
+ return Arr.some(key.acceptedAnswers, (accepted) => normalizeTextAnswer(accepted, key) === typed);
217
217
  }
218
218
  return Option.exists(readNumberAnswer(answer, language), (number) => matchesNumberKey(key, number));
219
219
  }
@@ -1,4 +1,4 @@
1
- import { Schema } from "effect";
1
+ import { Array as Arr, Schema } from "effect";
2
2
  import { CONTENT_KEY_MAX_LENGTH, ContentKeySchema, CorpusSourcePathSchema, } from "#contracts/ids";
3
3
  import { ArtifactLocaleSchema } from "#contracts/locale";
4
4
  import { TryoutKeySchema } from "#contracts/tryout/key";
@@ -39,7 +39,7 @@ function parseQuestionSetParts(input) {
39
39
  }
40
40
  const keys = input.slice(prefix.length).split("/");
41
41
  if (keys.length < 4 ||
42
- keys.some((key) => !isTryoutKey(key) || isQuestionSegment(key))) {
42
+ Arr.some(keys, (key) => !isTryoutKey(key) || isQuestionSegment(key))) {
43
43
  return;
44
44
  }
45
45
  return Schema.decodeUnknownSync(QuestionSetPartsSchema)({
@@ -1,4 +1,4 @@
1
- import { Effect, Record as Rec, Schema, Struct } from "effect";
1
+ import { Array as Arr, Effect, Record as Rec, Schema, Struct } from "effect";
2
2
  import { AppLocaleCodeSchema, ArtifactLocaleSchema, artifactLocaleCode, } from "#contracts/locale";
3
3
  import { QuestionAnswerKeySchema } from "#contracts/question/answer";
4
4
  import { QuestionResponseLabelSchema } from "#contracts/question/label";
@@ -19,11 +19,11 @@ function hasAtLeastTwoOptions(options) {
19
19
  }
20
20
  /** Requires exactly one authored option to carry correctness. */
21
21
  function hasOneCorrectOption(options) {
22
- return options.filter(({ isCorrect }) => isCorrect).length === 1;
22
+ return Arr.filter(options, ({ isCorrect }) => isCorrect).length === 1;
23
23
  }
24
24
  /** Requires several correct options while retaining at least one distractor. */
25
25
  function hasSeveralCorrectOptions(options) {
26
- const correct = options.filter(({ isCorrect }) => isCorrect).length;
26
+ const correct = Arr.filter(options, ({ isCorrect }) => isCorrect).length;
27
27
  return correct >= 2 && correct < options.length;
28
28
  }
29
29
  const QuestionOptionSourceListSchema = Schema.Array(QuestionOptionSourceSchema).pipe(Schema.mutable, Schema.check(Schema.makeFilter(hasAtLeastTwoOptions, {
@@ -49,7 +49,7 @@ const CategoryStatementSourceSchema = Schema.Struct({
49
49
  function hasCoherentCategoryResponse(input) {
50
50
  return (input.categories.length >= 2 &&
51
51
  input.statements.length > 0 &&
52
- input.statements.every(({ correctCategoryOrder }) => correctCategoryOrder <= input.categories.length));
52
+ Arr.every(input.statements, ({ correctCategoryOrder }) => correctCategoryOrder <= input.categories.length));
53
53
  }
54
54
  const CategoryResponseSourceSchema = Schema.Struct({
55
55
  categories: Schema.Array(QuestionResponseLabelSchema).pipe(Schema.mutable),
@@ -82,7 +82,7 @@ export const QuestionBlueprintSchema = Schema.Struct({
82
82
  });
83
83
  /** Derives stable option keys and orders from source-authored array order. */
84
84
  function freezeOptions(options) {
85
- return options.map(({ isCorrect, label }, index) => ({
85
+ return Arr.map(options, ({ isCorrect, label }, index) => ({
86
86
  isCorrect,
87
87
  label,
88
88
  optionKey: `option-${index + 1}`,
@@ -102,13 +102,13 @@ function freezeQuestionResponse(response) {
102
102
  }
103
103
  if (response.kind === "category") {
104
104
  return QuestionResponseSchema.make({
105
- categories: response.categories.map((label, index) => ({
105
+ categories: Arr.map(response.categories, (label, index) => ({
106
106
  categoryKey: `category-${index + 1}`,
107
107
  label,
108
108
  order: index + 1,
109
109
  })),
110
110
  kind: response.kind,
111
- statements: response.statements.map(({ correctCategoryOrder, label }, index) => ({
111
+ statements: Arr.map(response.statements, ({ correctCategoryOrder, label }, index) => ({
112
112
  correctCategoryKey: `category-${correctCategoryOrder}`,
113
113
  label,
114
114
  order: index + 1,
@@ -127,15 +127,15 @@ function responseStructure(response) {
127
127
  }
128
128
  /** Requires locale siblings to preserve one response format and answer key. */
129
129
  function hasCoherentLocalizedResponses(input) {
130
- const responses = Rec.values(input.responses).filter((response) => response !== undefined);
130
+ const responses = Arr.filter(Rec.values(input.responses), (response) => response !== undefined);
131
131
  const [first] = responses;
132
132
  return (first !== undefined &&
133
- responses.every((response) => responseStructure(response) === responseStructure(first)));
133
+ Arr.every(responses, (response) => responseStructure(response) === responseStructure(first)));
134
134
  }
135
135
  /** Requires a rubric item to take its worth from the rubric total alone. */
136
136
  function hasCoherentPoints(input) {
137
137
  return (input.points === undefined ||
138
- Rec.values(input.responses).every((response) => response?.kind !== "rubric"));
138
+ Arr.every(Rec.values(input.responses), (response) => response?.kind !== "rubric"));
139
139
  }
140
140
  /**
141
141
  * Complete source-owned item with optional shared-stimulus identity and points.
@@ -1,4 +1,4 @@
1
- import { HashSet, Schema } from "effect";
1
+ import { Array as Arr, HashSet, Schema } from "effect";
2
2
  import { canonicalQuestionAnswerKey, canonicalQuestionAnswerKeyStructure, QuestionAnswerKeySchema, } from "#contracts/question/answer";
3
3
  import { QuestionResponseLabelSchema } from "#contracts/question/label";
4
4
  import { canonicalQuestionRubric, canonicalQuestionRubricStructure, QuestionRubricResponseSchema, } from "#contracts/question/rubric";
@@ -26,9 +26,9 @@ const QuestionOptionSchema = Schema.Struct({
26
26
  });
27
27
  /** Checks stable option identities, order, and format-specific correctness. */
28
28
  function hasCanonicalOptions(options, kind) {
29
- const correct = options.filter(({ isCorrect }) => isCorrect).length;
29
+ const correct = Arr.filter(options, ({ isCorrect }) => isCorrect).length;
30
30
  return (options.length >= 2 &&
31
- options.every(({ optionKey, order }, index) => order === index + 1 && optionKey === `option-${order}`) &&
31
+ Arr.every(options, ({ optionKey, order }, index) => order === index + 1 && optionKey === `option-${order}`) &&
32
32
  (kind === "single-choice"
33
33
  ? correct === 1
34
34
  : correct >= 2 && correct < options.length));
@@ -58,11 +58,11 @@ const QuestionCategoryStatementSchema = Schema.Struct({
58
58
  });
59
59
  /** Checks stable category and statement identities plus valid references. */
60
60
  function hasCanonicalCategories(input) {
61
- const categoryKeys = HashSet.fromIterable(input.categories.map(({ categoryKey }) => categoryKey));
61
+ const categoryKeys = HashSet.fromIterable(Arr.map(input.categories, ({ categoryKey }) => categoryKey));
62
62
  return (input.categories.length >= 2 &&
63
63
  input.statements.length > 0 &&
64
- input.categories.every(({ categoryKey, order }, index) => order === index + 1 && categoryKey === `category-${order}`) &&
65
- input.statements.every(({ correctCategoryKey, order, statementKey }, index) => order === index + 1 &&
64
+ Arr.every(input.categories, ({ categoryKey, order }, index) => order === index + 1 && categoryKey === `category-${order}`) &&
65
+ Arr.every(input.statements, ({ correctCategoryKey, order, statementKey }, index) => order === index + 1 &&
66
66
  statementKey === `statement-${order}` &&
67
67
  HashSet.has(categoryKeys, correctCategoryKey)));
68
68
  }
@@ -104,12 +104,12 @@ export function canonicalQuestionResponseStructure(response) {
104
104
  }
105
105
  if (response.kind === "category") {
106
106
  return {
107
- categories: response.categories.map(({ categoryKey, order }) => ({
107
+ categories: Arr.map(response.categories, ({ categoryKey, order }) => ({
108
108
  categoryKey,
109
109
  order,
110
110
  })),
111
111
  kind: response.kind,
112
- statements: response.statements.map(({ correctCategoryKey, order, statementKey }) => ({
112
+ statements: Arr.map(response.statements, ({ correctCategoryKey, order, statementKey }) => ({
113
113
  correctCategoryKey,
114
114
  order,
115
115
  statementKey,
@@ -118,7 +118,7 @@ export function canonicalQuestionResponseStructure(response) {
118
118
  }
119
119
  return {
120
120
  kind: response.kind,
121
- options: response.options.map(({ isCorrect, optionKey, order }) => ({
121
+ options: Arr.map(response.options, ({ isCorrect, optionKey, order }) => ({
122
122
  isCorrect,
123
123
  optionKey,
124
124
  order,
@@ -138,13 +138,13 @@ export function canonicalQuestionResponse(response) {
138
138
  }
139
139
  if (response.kind === "category") {
140
140
  return {
141
- categories: response.categories.map(({ categoryKey, label, order }) => ({
141
+ categories: Arr.map(response.categories, ({ categoryKey, label, order }) => ({
142
142
  categoryKey,
143
143
  label,
144
144
  order,
145
145
  })),
146
146
  kind: response.kind,
147
- statements: response.statements.map(({ correctCategoryKey, label, order, statementKey }) => ({
147
+ statements: Arr.map(response.statements, ({ correctCategoryKey, label, order, statementKey }) => ({
148
148
  correctCategoryKey,
149
149
  label,
150
150
  order,
@@ -154,7 +154,7 @@ export function canonicalQuestionResponse(response) {
154
154
  }
155
155
  return {
156
156
  kind: response.kind,
157
- options: response.options.map(({ isCorrect, label, optionKey, order }) => ({
157
+ options: Arr.map(response.options, ({ isCorrect, label, optionKey, order }) => ({
158
158
  isCorrect,
159
159
  label,
160
160
  optionKey,
@@ -1,4 +1,4 @@
1
- import { Schema, Struct } from "effect";
1
+ import { Array as Arr, Schema, Struct } from "effect";
2
2
  import { ActiveAppLocaleCodeSchema } from "#contracts/locale";
3
3
  import { canonicalQuestionAnswerKey, canonicalQuestionAnswerKeyStructure, QuestionAnswerKeySchema, } from "#contracts/question/answer";
4
4
  import { QuestionResponseLabelSchema } from "#contracts/question/label";
@@ -37,9 +37,9 @@ const ORDERED_SCALE_MESSAGE = "Rubric criteria need two or more levels whose poi
37
37
  /** Checks one or more criteria and the stable keys derived from their order. */
38
38
  function hasCanonicalCriteria(criteria) {
39
39
  return (criteria.length > 0 &&
40
- criteria.every(({ criterionKey, levels, order }, index) => order === index + 1 &&
40
+ Arr.every(criteria, ({ criterionKey, levels, order }, index) => order === index + 1 &&
41
41
  criterionKey === `criterion-${order}` &&
42
- levels.every((level, levelIndex) => level.order === levelIndex + 1 &&
42
+ Arr.every(levels, (level, levelIndex) => level.order === levelIndex + 1 &&
43
43
  level.levelKey === `level-${level.order}`)));
44
44
  }
45
45
  const CANONICAL_CRITERIA_MESSAGE = "Rubric criteria and levels require canonical keys and order.";
@@ -120,13 +120,13 @@ export const QuestionRubricResponseSourceSchema = Schema.Struct({
120
120
  /** Derives stable criterion and level keys once from authored array order. */
121
121
  export function freezeQuestionRubric(source) {
122
122
  return QuestionRubricResponseSchema.make({
123
- criteria: source.criteria.map((criterion, index) => ({
123
+ criteria: Arr.map(source.criteria, (criterion, index) => ({
124
124
  criterionKey: `criterion-${index + 1}`,
125
125
  ...(criterion.finalAnswer === undefined
126
126
  ? {}
127
127
  : { finalAnswer: criterion.finalAnswer }),
128
128
  label: criterion.label,
129
- levels: criterion.levels.map(({ label, points }, levelIndex) => ({
129
+ levels: Arr.map(criterion.levels, ({ label, points }, levelIndex) => ({
130
130
  label,
131
131
  levelKey: `level-${levelIndex + 1}`,
132
132
  order: levelIndex + 1,
@@ -143,13 +143,13 @@ function canonicalRubricLabel(label) {
143
143
  }
144
144
  /** Serializes criteria in stable field order with one answer-key encoding. */
145
145
  function canonicalRubricCriteria(rubric, canonicalKey) {
146
- return rubric.criteria.map(({ criterionKey, finalAnswer, label, levels, order }) => ({
146
+ return Arr.map(rubric.criteria, ({ criterionKey, finalAnswer, label, levels, order }) => ({
147
147
  criterionKey,
148
148
  ...(finalAnswer === undefined
149
149
  ? {}
150
150
  : { finalAnswer: canonicalKey(finalAnswer) }),
151
151
  label: canonicalRubricLabel(label),
152
- levels: levels.map((level) => ({
152
+ levels: Arr.map(levels, (level) => ({
153
153
  label: canonicalRubricLabel(level.label),
154
154
  levelKey: level.levelKey,
155
155
  order: level.order,
@@ -178,6 +178,6 @@ export function canonicalQuestionRubric(rubric) {
178
178
  }
179
179
  /** Returns the rubric total: the sum of every criterion's highest level. */
180
180
  export function questionRubricPoints(rubric) {
181
- return rubric.criteria.reduce((total, { levels }) => total +
182
- levels.reduce((highest, { points }) => Math.max(highest, points), 0), 0);
181
+ return Arr.reduce(rubric.criteria, 0, (total, { levels }) => total +
182
+ Arr.reduce(levels, 0, (highest, { points }) => Math.max(highest, points)));
183
183
  }
@@ -1,11 +1,15 @@
1
1
  import type { QuranSourceAttribution } from "#contracts/quran/source";
2
2
  /** Serializes one source attribution without trusting object insertion order. */
3
3
  export declare function canonicalizeQuranAttribution(attribution: QuranSourceAttribution): {
4
- copy: {
4
+ copy: [{
5
5
  appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
6
6
  notice: string;
7
7
  title: string;
8
- }[];
8
+ }, ...{
9
+ appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
10
+ notice: string;
11
+ title: string;
12
+ }[]];
9
13
  id: "bubenheim-names" | "kemenag-names" | "mokhtasar-english" | "mokhtasar-german" | "quranenc-english" | "quranenc-german" | "quranenc-indonesian" | "quranenc-tafsir" | "tanzil-metadata" | "tanzil-text";
10
14
  kind: "embedded" | "external";
11
15
  publisher: string;
@@ -19,11 +23,15 @@ export declare function canonicalizeQuranAttribution(attribution: QuranSourceAtt
19
23
  updateUrl: string;
20
24
  version: string;
21
25
  } | {
22
- copy: {
26
+ copy: [{
27
+ appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
28
+ notice: string;
29
+ title: string;
30
+ }, ...{
23
31
  appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
24
32
  notice: string;
25
33
  title: string;
26
- }[];
34
+ }[]];
27
35
  id: "bubenheim-names" | "kemenag-names" | "mokhtasar-english" | "mokhtasar-german" | "quranenc-english" | "quranenc-german" | "quranenc-indonesian" | "quranenc-tafsir" | "tanzil-metadata" | "tanzil-text";
28
36
  kind: "embedded" | "external";
29
37
  publisher: string;
@@ -1,7 +1,8 @@
1
+ import { Array as Arr } from "effect";
1
2
  /** Serializes one source attribution without trusting object insertion order. */
2
3
  export function canonicalizeQuranAttribution(attribution) {
3
4
  const common = {
4
- copy: attribution.copy.map((entry) => ({
5
+ copy: Arr.map(attribution.copy, (entry) => ({
5
6
  appLocale: entry.appLocale,
6
7
  notice: entry.notice,
7
8
  title: entry.title,
@@ -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
- markers.push({ end: start + match[0].length, number, start });
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
- segments.push({
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
- segments.push({
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
- segments.push({ kind: "text", offset: start, value: source.slice(start) });
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 = references.filter((reference, index) => references.findIndex(({ number }) => number === reference.number) ===
104
- index);
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 = definitions.map(({ number }) => number);
110
- const hasDuplicateDefinition = definitionNumbers.some((number, index) => definitionNumbers.indexOf(number) !== index);
116
+ const definitionNumbers = Arr.map(definitions, ({ number }) => number);
117
+ const hasDuplicateDefinition = Arr.some(definitionNumbers, (number, index) => definitionNumbers.indexOf(number) !== index);
111
118
  const hasMismatchedMarkers = hasDuplicateDefinition ||
112
119
  uniqueReferences.length !== definitionNumbers.length ||
113
- noteCandidates.some(({ definition, referenceOffset }, index) => referenceOffset < 0 ||
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 = noteCandidates.map(({ definition, referenceOffset }, index) => ({
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 (notes.some(({ text }) => text.length === 0)) {
135
+ if (Arr.some(notes, ({ text }) => text.length === 0)) {
129
136
  return { _tag: "Failure", reason: "empty-note" };
130
137
  }
131
138
  return {
@@ -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 = ["arabic-text"];
32
+ const scopes = MutableList.make();
33
+ MutableList.append(scopes, "arabic-text");
33
34
  for (const appLocale of activeAppLocales) {
34
- scopes.push(quranNameProvenanceScope(appLocale));
35
- scopes.push(quranTranslationProvenanceScope(appLocale));
35
+ MutableList.append(scopes, quranNameProvenanceScope(appLocale));
36
+ MutableList.append(scopes, quranTranslationProvenanceScope(appLocale));
36
37
  if (appLocale === AppLocaleSchema.make("en")) {
37
- scopes.push("en-tafsir-access");
38
+ MutableList.append(scopes, "en-tafsir-access");
38
39
  }
39
40
  else if (appLocale === AppLocaleSchema.make("id")) {
40
- scopes.push("id-tafsir");
41
+ MutableList.append(scopes, "id-tafsir");
41
42
  }
42
43
  else {
43
- scopes.push("de-tafsir-access");
44
+ MutableList.append(scopes, "de-tafsir-access");
44
45
  }
45
46
  }
46
- scopes.push("metadata");
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.every((record, index) => record.scope === expected[index] &&
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.some((record) => record.status === "blocked")
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.map(({ scope }) => scope),
139
+ actualScopes: Arr.map(input.records, ({ scope }) => scope),
139
140
  })));
140
141
  const digest = yield* hashQuranProvenance(decoded);
141
- const status = decoded.records.some((record) => record.status === "blocked")
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 });