@nakafa/aksara-contracts 0.50.0 → 0.51.0
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/artifact/integrity.d.ts +15 -2
- package/dist/artifact/integrity.js +3 -15
- package/dist/artifact/limits.js +3 -4
- package/dist/artifact/source.js +4 -8
- package/dist/artifact/spec.d.ts +30 -10
- package/dist/assessment/hash.d.ts +3 -1
- package/dist/assessment/paper.d.ts +3 -1
- package/dist/errors.d.ts +3 -1
- package/dist/graph/family.d.ts +6 -2
- package/dist/graph/identity.d.ts +3 -1
- package/dist/hash/digest.d.ts +10 -0
- package/dist/hash/digest.js +40 -0
- package/dist/hash/stream.d.ts +12 -0
- package/dist/hash/stream.js +27 -0
- package/dist/hash/text.d.ts +3 -1
- package/dist/hash/text.js +2 -15
- package/dist/preview/auth.d.ts +4 -2
- package/dist/preview/auth.js +26 -12
- package/dist/program/snapshot/digest.d.ts +3 -1
- package/dist/program/snapshot/digest.js +14 -22
- package/dist/program/snapshot/hash.d.ts +6 -2
- package/dist/program/snapshot/hash.js +10 -21
- package/dist/projection/digest.d.ts +11 -9
- package/dist/projection/digest.js +23 -32
- package/dist/projection/hash.d.ts +222 -2
- package/dist/projection/hash.js +6 -8
- package/dist/projection/verify.d.ts +16 -6
- package/dist/question/item.d.ts +3 -1
- package/dist/question/item.js +3 -1
- package/dist/quran/notes.d.ts +3 -1
- package/dist/quran/provenance.d.ts +6 -2
- package/dist/quran/provenance.js +8 -15
- package/dist/quran/snapshot/digest.d.ts +9 -5
- package/dist/quran/snapshot/digest.js +33 -41
- package/dist/quran/snapshot/hash.d.ts +3 -1
- package/dist/quran/snapshot/hash.js +9 -15
- package/dist/quran/snapshot/row/hash.d.ts +3 -1
- package/dist/quran/snapshot/row/hash.js +2 -8
- package/dist/release/digest.d.ts +10 -8
- package/dist/release/digest.js +22 -31
- package/dist/release/hash.d.ts +3 -1
- package/dist/release/hash.js +3 -8
- package/dist/release/items.d.ts +25 -9
- package/dist/release/items.js +12 -3
- package/dist/release/policy.d.ts +3 -1
- package/dist/release/result/digest.d.ts +23 -13
- package/dist/release/result/digest.js +20 -29
- package/dist/release/rollback/digest.d.ts +16 -10
- package/dist/release/rollback/digest.js +25 -32
- package/dist/release/route/digest.d.ts +10 -8
- package/dist/release/route/digest.js +22 -31
- package/dist/release/route/verify.d.ts +16 -6
- package/dist/release/route/verify.js +8 -2
- package/dist/release/snapshot/evidence/requirement.d.ts +3 -1
- package/dist/release/snapshot/evidence/tryout.d.ts +1 -1
- package/dist/release/snapshot/evidence/tryout.js +1 -1
- package/dist/release/snapshot/evidence.d.ts +1 -1
- package/dist/release/snapshot/verify.d.ts +19 -7
- package/dist/release/snapshot/verify.js +20 -18
- package/dist/release/verify.d.ts +9 -3
- package/dist/renderer/compatibility.d.ts +6 -2
- package/dist/renderer/compatibility.js +3 -1
- package/dist/renderer/contract.d.ts +9 -3
- package/dist/renderer/contract.js +3 -1
- package/dist/runtime/error.d.ts +3 -1
- package/dist/runtime/protected/verify.d.ts +1 -1
- package/dist/runtime/verify.d.ts +2 -2
- package/dist/runtime/verify.js +2 -1
- package/dist/signature/key.d.ts +21 -0
- package/dist/signature/key.js +104 -0
- package/dist/signature/spec.d.ts +18 -6
- package/dist/signature/spec.js +16 -4
- package/dist/transport/request.d.ts +728 -728
- package/dist/transport/response.d.ts +26 -26
- package/dist/tryout/canonical.d.ts +11 -1
- package/dist/tryout/canonical.js +6 -10
- package/dist/tryout/closure/accounting.d.ts +3 -1
- package/dist/tryout/digest.d.ts +12 -6
- package/dist/tryout/digest.js +21 -14
- package/dist/tryout/hash/catalog.d.ts +228 -3
- package/dist/tryout/hash/catalog.js +5 -7
- package/dist/tryout/hash/content.d.ts +113 -2
- package/dist/tryout/hash/content.js +10 -8
- package/dist/tryout/hash/placement.d.ts +236 -5
- package/dist/tryout/hash/placement.js +7 -8
- package/dist/tryout/runtime/hash.d.ts +3 -1
- package/dist/tryout/runtime/hash.js +3 -1
- package/dist/tryout/runtime/source.d.ts +3 -1
- package/dist/tryout/runtime/verify.d.ts +13 -5
- package/dist/tryout/runtime/verify.js +1 -1
- package/dist/tryout/scoring.d.ts +3 -1
- package/dist/tryout/snapshot/hash.d.ts +45 -4
- package/dist/tryout/snapshot/hash.js +9 -7
- package/package.json +18 -2
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { Effect, Schema } from "effect";
|
|
3
|
-
import {
|
|
2
|
+
import { hashText } from "#contracts/hash/text";
|
|
4
3
|
import { CurriculumRouteRecordSchema, canonicalizeProgramSnapshotRow, LearningProgramRecordSchema, } from "#contracts/program/snapshot/row";
|
|
5
4
|
import { PROGRAM_SNAPSHOT_FORMAT, ProgramSnapshotSchema, } from "#contracts/program/snapshot/spec";
|
|
6
5
|
import { encodeJsonText } from "#contracts/text/json";
|
|
@@ -26,19 +25,14 @@ export function canonicalizeProgramSnapshot(input) {
|
|
|
26
25
|
});
|
|
27
26
|
}
|
|
28
27
|
/** Creates the content-addressed identity of one complete program snapshot. */
|
|
29
|
-
export const makeProgramSnapshot = Effect.fn("AksaraContracts.makeProgramSnapshot")((input)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
format: PROGRAM_SNAPSHOT_FORMAT,
|
|
38
|
-
snapshotId,
|
|
39
|
-
});
|
|
40
|
-
},
|
|
41
|
-
}));
|
|
28
|
+
export const makeProgramSnapshot = Effect.fn("AksaraContracts.makeProgramSnapshot")(function* (input) {
|
|
29
|
+
const snapshotId = yield* hashText(`${SNAPSHOT_DOMAIN}\n${canonicalizeProgramSnapshot(input)}`).pipe(Effect.mapError(() => new ProgramSnapshotHashError()));
|
|
30
|
+
return ProgramSnapshotSchema.make({
|
|
31
|
+
...input,
|
|
32
|
+
format: PROGRAM_SNAPSHOT_FORMAT,
|
|
33
|
+
snapshotId,
|
|
34
|
+
});
|
|
35
|
+
});
|
|
42
36
|
/** Recomputes the content identity of one stored current snapshot. */
|
|
43
37
|
export function verifyProgramSnapshotHash(snapshot) {
|
|
44
38
|
const { format: _format, snapshotId: _snapshotId, ...facts } = snapshot;
|
|
@@ -46,12 +40,7 @@ export function verifyProgramSnapshotHash(snapshot) {
|
|
|
46
40
|
}
|
|
47
41
|
/** Hashes one current program or curriculum row. */
|
|
48
42
|
function hashProgramRow(record) {
|
|
49
|
-
return Effect.
|
|
50
|
-
catch: () => new ProgramRowHashError({ scope: "row" }),
|
|
51
|
-
try: () => Sha256HashSchema.make(`sha256:${createHash("sha256")
|
|
52
|
-
.update(`${ROW_DOMAIN}\n${canonicalizeProgramSnapshotRow(record)}`)
|
|
53
|
-
.digest("hex")}`),
|
|
54
|
-
});
|
|
43
|
+
return hashText(`${ROW_DOMAIN}\n${canonicalizeProgramSnapshotRow(record)}`).pipe(Effect.mapError(() => new ProgramRowHashError({ scope: "row" })));
|
|
55
44
|
}
|
|
56
45
|
/** Creates one authenticated current program record. */
|
|
57
46
|
export const makeProgramSnapshotRow = Effect.fn("AksaraContracts.makeProgramSnapshotRow")(function* (row) {
|
|
@@ -3,28 +3,30 @@ import { ReleaseIdSchema } from "#contracts/ids";
|
|
|
3
3
|
import { type ContentProjection } from "#contracts/projection/spec";
|
|
4
4
|
declare const ProjectionHashError_base: Schema.Class<ProjectionHashError, Schema.TaggedStruct<"ProjectionHashError", {
|
|
5
5
|
readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
|
|
6
|
-
}>, import("effect/Cause").YieldableError
|
|
6
|
+
}>, import("effect/Cause").YieldableError & {
|
|
7
|
+
readonly brand: unique symbol;
|
|
8
|
+
}>;
|
|
7
9
|
/** SHA-256 computation failed before projection integrity was established. */
|
|
8
10
|
export declare class ProjectionHashError extends ProjectionHashError_base {
|
|
9
11
|
}
|
|
10
|
-
/** Keeps
|
|
12
|
+
/** Keeps the digest stream private while exposing only canonical counters. */
|
|
11
13
|
declare class ProjectionDigestState {
|
|
12
14
|
#private;
|
|
13
15
|
count: number;
|
|
14
|
-
/**
|
|
16
|
+
/** Starts one domain-separated projection digest. */
|
|
15
17
|
constructor();
|
|
16
18
|
/** Adds one canonical projection to this invocation-owned digest. */
|
|
17
19
|
update(projection: ContentProjection): void;
|
|
18
|
-
/**
|
|
19
|
-
digest(): string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
20
|
+
/** Digests the complete stream once and returns its branded immutable identity. */
|
|
21
|
+
digest(): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, import("effect/PlatformError").PlatformError, never>;
|
|
20
22
|
}
|
|
21
23
|
/** Creates a fresh domain-separated projection digest state. */
|
|
22
|
-
export declare
|
|
24
|
+
export declare const createProjectionDigest: Effect.Effect<ProjectionDigestState, never, never>;
|
|
23
25
|
/** Adds one canonical content projection to an incremental digest. */
|
|
24
|
-
export declare function updateProjectionDigest(
|
|
25
|
-
/** Finalizes one
|
|
26
|
+
export declare function updateProjectionDigest(state: ProjectionDigestState, projection: ContentProjection): Effect.Effect<ProjectionDigestState, never, never>;
|
|
27
|
+
/** Finalizes one projection digest with a typed hash failure. */
|
|
26
28
|
export declare function finalizeProjectionDigest(releaseId: typeof ReleaseIdSchema.Type, state: ProjectionDigestState): Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ProjectionHashError, never>;
|
|
27
|
-
/** Digests a projection stream
|
|
29
|
+
/** Digests a projection stream. Its canonical bytes are held until one Web Crypto digest runs. */
|
|
28
30
|
export declare const digestProjections: <E, R>(releaseId: string & import("effect/Brand").Brand<"@NakafaAI/AksaraReleaseId">, projections: Stream.Stream<{
|
|
29
31
|
readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
30
32
|
readonly articleRouteSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleRouteSlug">;
|
|
@@ -1,59 +1,50 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { Effect, Schema, Stream } from "effect";
|
|
3
|
-
import {
|
|
2
|
+
import { DigestStream } from "#contracts/hash/stream";
|
|
3
|
+
import { ReleaseIdSchema } from "#contracts/ids";
|
|
4
4
|
import { canonicalizeContentProjection, } from "#contracts/projection/spec";
|
|
5
5
|
const CONTENT_PROJECTION_DIGEST_DOMAIN = "nakafa.aksara.content-projections";
|
|
6
6
|
/** SHA-256 computation failed before projection integrity was established. */
|
|
7
7
|
export class ProjectionHashError extends Schema.TaggedError()("ProjectionHashError", { releaseId: ReleaseIdSchema }) {
|
|
8
8
|
}
|
|
9
|
-
/** Keeps
|
|
9
|
+
/** Keeps the digest stream private while exposing only canonical counters. */
|
|
10
10
|
class ProjectionDigestState {
|
|
11
|
-
#
|
|
11
|
+
#stream = new DigestStream();
|
|
12
12
|
count = 0;
|
|
13
|
-
/**
|
|
13
|
+
/** Starts one domain-separated projection digest. */
|
|
14
14
|
constructor() {
|
|
15
|
-
this.#
|
|
16
|
-
this.#
|
|
15
|
+
this.#stream.add(CONTENT_PROJECTION_DIGEST_DOMAIN);
|
|
16
|
+
this.#stream.add("\n");
|
|
17
17
|
}
|
|
18
18
|
/** Adds one canonical projection to this invocation-owned digest. */
|
|
19
19
|
update(projection) {
|
|
20
|
-
this.#
|
|
21
|
-
this.#
|
|
20
|
+
this.#stream.add(canonicalizeContentProjection(projection));
|
|
21
|
+
this.#stream.add("\n");
|
|
22
22
|
this.count += 1;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
24
|
+
/** Digests the complete stream once and returns its branded immutable identity. */
|
|
25
25
|
digest() {
|
|
26
|
-
return
|
|
26
|
+
return this.#stream.digest();
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
/** Creates a fresh domain-separated projection digest state. */
|
|
30
|
-
export
|
|
31
|
-
return Effect.try({
|
|
32
|
-
catch: () => new ProjectionHashError({ releaseId }),
|
|
33
|
-
try: () => new ProjectionDigestState(),
|
|
34
|
-
});
|
|
35
|
-
}
|
|
30
|
+
export const createProjectionDigest = Effect.sync(() => new ProjectionDigestState());
|
|
36
31
|
/** Adds one canonical content projection to an incremental digest. */
|
|
37
|
-
export function updateProjectionDigest(
|
|
38
|
-
return Effect.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
state.update(projection);
|
|
42
|
-
return state;
|
|
43
|
-
},
|
|
32
|
+
export function updateProjectionDigest(state, projection) {
|
|
33
|
+
return Effect.sync(() => {
|
|
34
|
+
state.update(projection);
|
|
35
|
+
return state;
|
|
44
36
|
});
|
|
45
37
|
}
|
|
46
|
-
/** Finalizes one
|
|
38
|
+
/** Finalizes one projection digest with a typed hash failure. */
|
|
47
39
|
export function finalizeProjectionDigest(releaseId, state) {
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
40
|
+
return state
|
|
41
|
+
.digest()
|
|
42
|
+
.pipe(Effect.mapError(() => new ProjectionHashError({ releaseId })));
|
|
52
43
|
}
|
|
53
|
-
/** Digests a projection stream
|
|
44
|
+
/** Digests a projection stream. Its canonical bytes are held until one Web Crypto digest runs. */
|
|
54
45
|
export const digestProjections = Effect.fn("AksaraContracts.digestProjections")(function* (releaseId, projections) {
|
|
55
|
-
const initial = yield* createProjectionDigest
|
|
56
|
-
const state = yield* projections.pipe(Stream.runFoldEffect(() => initial, (current, projection) => updateProjectionDigest(
|
|
46
|
+
const initial = yield* createProjectionDigest;
|
|
47
|
+
const state = yield* projections.pipe(Stream.runFoldEffect(() => initial, (current, projection) => updateProjectionDigest(current, projection)));
|
|
57
48
|
const digest = yield* finalizeProjectionDigest(releaseId, state);
|
|
58
49
|
return { count: state.count, digest };
|
|
59
50
|
});
|
|
@@ -1,3 +1,223 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
declare const ContentProjectionHashError_base: Schema.Class<ContentProjectionHashError, Schema.TaggedStruct<"ContentProjectionHashError", {
|
|
3
|
+
readonly contentKey: Schema.String;
|
|
4
|
+
}>, import("effect/Cause").YieldableError & {
|
|
5
|
+
readonly brand: unique symbol;
|
|
6
|
+
}>;
|
|
7
|
+
/** The projection identity could not be computed for one content key. */
|
|
8
|
+
export declare class ContentProjectionHashError extends ContentProjectionHashError_base {
|
|
9
|
+
}
|
|
2
10
|
/** Hashes one canonical projection for authoritative content-head diffing. */
|
|
3
|
-
export declare
|
|
11
|
+
export declare const hashContentProjection: (projection: {
|
|
12
|
+
readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
13
|
+
readonly articleRouteSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleRouteSlug">;
|
|
14
|
+
readonly articleSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleSlug">;
|
|
15
|
+
readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
|
|
16
|
+
readonly category: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleCategory">;
|
|
17
|
+
readonly categoryRouteSlug: string & import("effect/Brand").Brand<"@NakafaAI/AksaraArticleRouteSlug">;
|
|
18
|
+
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
19
|
+
readonly graph: {
|
|
20
|
+
readonly alignmentId: string;
|
|
21
|
+
readonly assetId: string;
|
|
22
|
+
readonly conceptId: string;
|
|
23
|
+
readonly learningObjectId: string;
|
|
24
|
+
readonly lensId: string;
|
|
25
|
+
};
|
|
26
|
+
readonly publicPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
|
|
27
|
+
readonly categoryTitle: string;
|
|
28
|
+
readonly kind: "article";
|
|
29
|
+
readonly metadata: {
|
|
30
|
+
readonly dateModified?: string;
|
|
31
|
+
readonly datePublished: string;
|
|
32
|
+
readonly authors: readonly {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
}[];
|
|
35
|
+
readonly description?: string | undefined;
|
|
36
|
+
readonly title: string;
|
|
37
|
+
};
|
|
38
|
+
readonly official: boolean;
|
|
39
|
+
readonly parentPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
|
|
40
|
+
readonly references: readonly {
|
|
41
|
+
readonly authors: string;
|
|
42
|
+
readonly citation?: string | undefined;
|
|
43
|
+
readonly details?: string | undefined;
|
|
44
|
+
readonly publication?: string | undefined;
|
|
45
|
+
readonly title: string;
|
|
46
|
+
readonly url?: string | undefined;
|
|
47
|
+
readonly year: number;
|
|
48
|
+
}[];
|
|
49
|
+
readonly sitemap: true;
|
|
50
|
+
} | {
|
|
51
|
+
readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
52
|
+
readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
|
|
53
|
+
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
54
|
+
readonly graph: {
|
|
55
|
+
readonly alignmentId: string;
|
|
56
|
+
readonly assetId: string;
|
|
57
|
+
readonly conceptId: string;
|
|
58
|
+
readonly learningObjectId: string;
|
|
59
|
+
readonly lensId: string;
|
|
60
|
+
};
|
|
61
|
+
readonly materialKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraMaterialKey">;
|
|
62
|
+
readonly order: number;
|
|
63
|
+
readonly publicPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
|
|
64
|
+
readonly sectionKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraMaterialSection">;
|
|
65
|
+
readonly kind: "subject-lesson";
|
|
66
|
+
readonly metadata: {
|
|
67
|
+
readonly dateModified?: string;
|
|
68
|
+
readonly datePublished: string;
|
|
69
|
+
readonly authors: readonly {
|
|
70
|
+
readonly name: string;
|
|
71
|
+
}[];
|
|
72
|
+
readonly description?: string | undefined;
|
|
73
|
+
readonly searchTitle?: string;
|
|
74
|
+
readonly subject?: string | undefined;
|
|
75
|
+
readonly title: string;
|
|
76
|
+
};
|
|
77
|
+
readonly parentPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
|
|
78
|
+
readonly sitemap: true;
|
|
79
|
+
readonly topicTitle: string;
|
|
80
|
+
} | {
|
|
81
|
+
readonly appLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraAppLocale">;
|
|
82
|
+
readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
|
|
83
|
+
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
84
|
+
readonly pageKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPageKey">;
|
|
85
|
+
readonly publicPath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraPublicPath">;
|
|
86
|
+
readonly kind: "public-page";
|
|
87
|
+
readonly metadata: {
|
|
88
|
+
readonly dateModified?: string;
|
|
89
|
+
readonly datePublished: string;
|
|
90
|
+
readonly description: string;
|
|
91
|
+
readonly title: string;
|
|
92
|
+
};
|
|
93
|
+
readonly sitemap: true;
|
|
94
|
+
readonly sourcePath: string & import("effect/Brand").Brand<"@NakafaAI/AksaraCorpusSourcePath">;
|
|
95
|
+
} | {
|
|
96
|
+
readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
|
|
97
|
+
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
98
|
+
readonly peerContentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
99
|
+
readonly questionKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraQuestionKey">;
|
|
100
|
+
readonly questionNumber: number;
|
|
101
|
+
readonly setKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraQuestionSetKey">;
|
|
102
|
+
readonly bodyKind: "question";
|
|
103
|
+
readonly blueprint?: {
|
|
104
|
+
readonly cognitiveLevel: string;
|
|
105
|
+
readonly contentDomain: string;
|
|
106
|
+
readonly topic: string;
|
|
107
|
+
};
|
|
108
|
+
readonly kind: "question-body";
|
|
109
|
+
readonly metadata: {
|
|
110
|
+
readonly dateModified?: string;
|
|
111
|
+
readonly datePublished: string;
|
|
112
|
+
readonly authors: readonly {
|
|
113
|
+
readonly name: string;
|
|
114
|
+
}[];
|
|
115
|
+
readonly title: string;
|
|
116
|
+
};
|
|
117
|
+
readonly stimulusKey?: string;
|
|
118
|
+
readonly response: {
|
|
119
|
+
readonly categories: readonly {
|
|
120
|
+
readonly categoryKey: string;
|
|
121
|
+
readonly label: string;
|
|
122
|
+
readonly order: number;
|
|
123
|
+
}[];
|
|
124
|
+
readonly kind: "category";
|
|
125
|
+
readonly statements: readonly {
|
|
126
|
+
readonly correctCategoryKey: string;
|
|
127
|
+
readonly label: string;
|
|
128
|
+
readonly order: number;
|
|
129
|
+
readonly statementKey: string;
|
|
130
|
+
}[];
|
|
131
|
+
} | {
|
|
132
|
+
readonly kind: "multiple-choice";
|
|
133
|
+
readonly options: readonly {
|
|
134
|
+
readonly isCorrect: boolean;
|
|
135
|
+
readonly label: string;
|
|
136
|
+
readonly optionKey: string;
|
|
137
|
+
readonly order: number;
|
|
138
|
+
}[];
|
|
139
|
+
} | {
|
|
140
|
+
readonly kind: "single-choice";
|
|
141
|
+
readonly options: readonly {
|
|
142
|
+
readonly isCorrect: boolean;
|
|
143
|
+
readonly label: string;
|
|
144
|
+
readonly optionKey: string;
|
|
145
|
+
readonly order: number;
|
|
146
|
+
}[];
|
|
147
|
+
} | {
|
|
148
|
+
readonly criteria: readonly {
|
|
149
|
+
readonly criterionKey: string;
|
|
150
|
+
readonly finalAnswer?: {
|
|
151
|
+
readonly acceptsFractions: boolean;
|
|
152
|
+
readonly kind: "number";
|
|
153
|
+
readonly tolerance?: {
|
|
154
|
+
readonly kind: "absolute" | "relative";
|
|
155
|
+
readonly value: string;
|
|
156
|
+
};
|
|
157
|
+
readonly value: string;
|
|
158
|
+
} | {
|
|
159
|
+
readonly acceptedAnswers: readonly [string, ...string[]];
|
|
160
|
+
readonly collapseWhitespace: boolean;
|
|
161
|
+
readonly ignoreCase: boolean;
|
|
162
|
+
readonly kind: "text";
|
|
163
|
+
};
|
|
164
|
+
readonly order: number;
|
|
165
|
+
readonly label: {
|
|
166
|
+
readonly de: string;
|
|
167
|
+
readonly en: string;
|
|
168
|
+
readonly id: string;
|
|
169
|
+
};
|
|
170
|
+
readonly levels: readonly {
|
|
171
|
+
readonly levelKey: string;
|
|
172
|
+
readonly order: number;
|
|
173
|
+
readonly points: number;
|
|
174
|
+
readonly label: {
|
|
175
|
+
readonly de: string;
|
|
176
|
+
readonly en: string;
|
|
177
|
+
readonly id: string;
|
|
178
|
+
};
|
|
179
|
+
}[];
|
|
180
|
+
}[];
|
|
181
|
+
readonly kind: "rubric";
|
|
182
|
+
} | {
|
|
183
|
+
readonly key: {
|
|
184
|
+
readonly acceptsFractions: boolean;
|
|
185
|
+
readonly kind: "number";
|
|
186
|
+
readonly tolerance?: {
|
|
187
|
+
readonly kind: "absolute" | "relative";
|
|
188
|
+
readonly value: string;
|
|
189
|
+
};
|
|
190
|
+
readonly value: string;
|
|
191
|
+
} | {
|
|
192
|
+
readonly acceptedAnswers: readonly [string, ...string[]];
|
|
193
|
+
readonly collapseWhitespace: boolean;
|
|
194
|
+
readonly ignoreCase: boolean;
|
|
195
|
+
readonly kind: "text";
|
|
196
|
+
};
|
|
197
|
+
readonly kind: "short-answer";
|
|
198
|
+
};
|
|
199
|
+
} | {
|
|
200
|
+
readonly artifactLocale: ("de" | "en" | "id") & import("effect/Brand").Brand<"@NakafaAI/AksaraArtifactLocale">;
|
|
201
|
+
readonly contentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
202
|
+
readonly peerContentKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraContentKey">;
|
|
203
|
+
readonly questionKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraQuestionKey">;
|
|
204
|
+
readonly questionNumber: number;
|
|
205
|
+
readonly setKey: string & import("effect/Brand").Brand<"@NakafaAI/AksaraQuestionSetKey">;
|
|
206
|
+
readonly bodyKind: "answer";
|
|
207
|
+
readonly blueprint?: {
|
|
208
|
+
readonly cognitiveLevel: string;
|
|
209
|
+
readonly contentDomain: string;
|
|
210
|
+
readonly topic: string;
|
|
211
|
+
};
|
|
212
|
+
readonly kind: "question-body";
|
|
213
|
+
readonly metadata: {
|
|
214
|
+
readonly dateModified?: string;
|
|
215
|
+
readonly datePublished: string;
|
|
216
|
+
readonly authors: readonly {
|
|
217
|
+
readonly name: string;
|
|
218
|
+
}[];
|
|
219
|
+
readonly title: string;
|
|
220
|
+
};
|
|
221
|
+
readonly stimulusKey?: string;
|
|
222
|
+
}) => Effect.Effect<string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">, ContentProjectionHashError, never>;
|
|
223
|
+
export {};
|
package/dist/projection/hash.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { hashText } from "#contracts/hash/text";
|
|
3
3
|
import { canonicalizeContentProjection, } from "#contracts/projection/spec";
|
|
4
|
-
/**
|
|
5
|
-
export
|
|
6
|
-
const digest = createHash("sha256")
|
|
7
|
-
.update(canonicalizeContentProjection(projection))
|
|
8
|
-
.digest("hex");
|
|
9
|
-
return Sha256HashSchema.make(`sha256:${digest}`);
|
|
4
|
+
/** The projection identity could not be computed for one content key. */
|
|
5
|
+
export class ContentProjectionHashError extends Schema.TaggedError()("ContentProjectionHashError", { contentKey: Schema.String }) {
|
|
10
6
|
}
|
|
7
|
+
/** Hashes one canonical projection for authoritative content-head diffing. */
|
|
8
|
+
export const hashContentProjection = Effect.fn("AksaraContracts.hashContentProjection")((projection) => hashText(canonicalizeContentProjection(projection)).pipe(Effect.mapError(() => new ContentProjectionHashError({ contentKey: projection.contentKey }))));
|
|
@@ -2,13 +2,17 @@ import { Effect, Schema, Stream } from "effect";
|
|
|
2
2
|
import type { ContentReleaseManifest } from "#contracts/release/spec";
|
|
3
3
|
declare const ProjectionDecodeError_base: Schema.Class<ProjectionDecodeError, Schema.TaggedStruct<"ProjectionDecodeError", {
|
|
4
4
|
readonly projectionIndex: Schema.Finite;
|
|
5
|
-
}>, import("effect/Cause").YieldableError
|
|
5
|
+
}>, import("effect/Cause").YieldableError & {
|
|
6
|
+
readonly brand: unique symbol;
|
|
7
|
+
}>;
|
|
6
8
|
/** One streamed projection failed strict schema decoding. */
|
|
7
9
|
export declare class ProjectionDecodeError extends ProjectionDecodeError_base {
|
|
8
10
|
}
|
|
9
11
|
declare const ProjectionOrderError_base: Schema.Class<ProjectionOrderError, Schema.TaggedStruct<"ProjectionOrderError", {
|
|
10
12
|
readonly projectionIndex: Schema.Finite;
|
|
11
|
-
}>, import("effect/Cause").YieldableError
|
|
13
|
+
}>, import("effect/Cause").YieldableError & {
|
|
14
|
+
readonly brand: unique symbol;
|
|
15
|
+
}>;
|
|
12
16
|
/** Projections are duplicated or not in canonical content-head order. */
|
|
13
17
|
export declare class ProjectionOrderError extends ProjectionOrderError_base {
|
|
14
18
|
}
|
|
@@ -16,7 +20,9 @@ declare const ProjectionRouteError_base: Schema.Class<ProjectionRouteError, Sche
|
|
|
16
20
|
readonly duplicateIndex: Schema.Finite;
|
|
17
21
|
readonly firstIndex: Schema.Finite;
|
|
18
22
|
readonly publicPath: Schema.brand<Schema.String, "@NakafaAI/AksaraPublicPath">;
|
|
19
|
-
}>, import("effect/Cause").YieldableError
|
|
23
|
+
}>, import("effect/Cause").YieldableError & {
|
|
24
|
+
readonly brand: unique symbol;
|
|
25
|
+
}>;
|
|
20
26
|
/** Two content projections claim the same locale-specific public route. */
|
|
21
27
|
export declare class ProjectionRouteError extends ProjectionRouteError_base {
|
|
22
28
|
}
|
|
@@ -24,7 +30,9 @@ declare const ProjectionCountError_base: Schema.Class<ProjectionCountError, Sche
|
|
|
24
30
|
readonly actualCount: Schema.Finite;
|
|
25
31
|
readonly expectedCount: Schema.Finite;
|
|
26
32
|
readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
|
|
27
|
-
}>, import("effect/Cause").YieldableError
|
|
33
|
+
}>, import("effect/Cause").YieldableError & {
|
|
34
|
+
readonly brand: unique symbol;
|
|
35
|
+
}>;
|
|
28
36
|
/** The streamed projection count differs from the signed manifest. */
|
|
29
37
|
export declare class ProjectionCountError extends ProjectionCountError_base {
|
|
30
38
|
}
|
|
@@ -32,14 +40,16 @@ declare const ProjectionDigestError_base: Schema.Class<ProjectionDigestError, Sc
|
|
|
32
40
|
readonly actualDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
33
41
|
readonly expectedDigest: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
34
42
|
readonly releaseId: Schema.brand<Schema.String, "@NakafaAI/AksaraReleaseId">;
|
|
35
|
-
}>, import("effect/Cause").YieldableError
|
|
43
|
+
}>, import("effect/Cause").YieldableError & {
|
|
44
|
+
readonly brand: unique symbol;
|
|
45
|
+
}>;
|
|
36
46
|
/** The streamed projection digest differs from the signed manifest. */
|
|
37
47
|
export declare class ProjectionDigestError extends ProjectionDigestError_base {
|
|
38
48
|
}
|
|
39
49
|
declare const VerifiedContentProjectionsSchema: Schema.Struct<{
|
|
40
50
|
readonly count: Schema.Finite;
|
|
41
51
|
}>;
|
|
42
|
-
/** Count authenticated
|
|
52
|
+
/** Count authenticated against the signed manifest. The digest holds every canonical byte until its one final call, so its memory grows with the stream. */
|
|
43
53
|
export type VerifiedContentProjections = typeof VerifiedContentProjectionsSchema.Type;
|
|
44
54
|
/** Strictly decodes a replayable canonical content projection stream. */
|
|
45
55
|
export declare function decodeContentProjections<E, R>(projections: Stream.Stream<unknown, E, R>): Stream.Stream<{
|
package/dist/question/item.d.ts
CHANGED
|
@@ -148,7 +148,9 @@ export declare function canonicalQuestionBlueprint(blueprint: QuestionBlueprint)
|
|
|
148
148
|
};
|
|
149
149
|
declare const QuestionResponseLocaleMissingError_base: Schema.Class<QuestionResponseLocaleMissingError, Schema.TaggedStruct<"QuestionResponseLocaleMissingError", {
|
|
150
150
|
readonly artifactLocale: Schema.brand<Schema.Literals<readonly ["en", "id", "de"]>, "@NakafaAI/AksaraArtifactLocale">;
|
|
151
|
-
}>, import("effect/Cause").YieldableError
|
|
151
|
+
}>, import("effect/Cause").YieldableError & {
|
|
152
|
+
readonly brand: unique symbol;
|
|
153
|
+
}>;
|
|
152
154
|
/** One item does not contain the exact artifact locale it must assess. */
|
|
153
155
|
export declare class QuestionResponseLocaleMissingError extends QuestionResponseLocaleMissingError_base {
|
|
154
156
|
}
|
package/dist/question/item.js
CHANGED
|
@@ -160,7 +160,9 @@ export function canonicalQuestionBlueprint(blueprint) {
|
|
|
160
160
|
};
|
|
161
161
|
}
|
|
162
162
|
/** One item does not contain the exact artifact locale it must assess. */
|
|
163
|
-
export class QuestionResponseLocaleMissingError extends Schema.TaggedError()("QuestionResponseLocaleMissingError", {
|
|
163
|
+
export class QuestionResponseLocaleMissingError extends Schema.TaggedError()("QuestionResponseLocaleMissingError", {
|
|
164
|
+
artifactLocale: ArtifactLocaleSchema,
|
|
165
|
+
}) {
|
|
164
166
|
}
|
|
165
167
|
/** Resolves and freezes one exact-locale response from an authored item. */
|
|
166
168
|
export const questionResponseFor = Effect.fn("AksaraContracts.questionResponseFor")(function* (item, artifactLocale) {
|
package/dist/quran/notes.d.ts
CHANGED
|
@@ -19,7 +19,9 @@ export declare const QuranTranslationDocumentSchema: Schema.Struct<{
|
|
|
19
19
|
export type QuranTranslationDocument = typeof QuranTranslationDocumentSchema.Type;
|
|
20
20
|
declare const QuranTranslationNotesError_base: Schema.Class<QuranTranslationNotesError, Schema.TaggedStruct<"QuranTranslationNotesError", {
|
|
21
21
|
readonly reason: Schema.Literals<readonly ["empty-note", "invalid-marker", "invalid-source", "mismatched-markers"]>;
|
|
22
|
-
}>, import("effect/Cause").YieldableError
|
|
22
|
+
}>, import("effect/Cause").YieldableError & {
|
|
23
|
+
readonly brand: unique symbol;
|
|
24
|
+
}>;
|
|
23
25
|
/** The translation and note markers do not form one exact projection. */
|
|
24
26
|
export declare class QuranTranslationNotesError extends QuranTranslationNotesError_base {
|
|
25
27
|
}
|
|
@@ -117,11 +117,15 @@ export declare const QuranProvenanceManifestSchema: Schema.Struct<{
|
|
|
117
117
|
export type QuranProvenanceManifest = typeof QuranProvenanceManifestSchema.Type;
|
|
118
118
|
declare const QuranProvenanceCoverageError_base: Schema.Class<QuranProvenanceCoverageError, Schema.TaggedStruct<"QuranProvenanceCoverageError", {
|
|
119
119
|
readonly actualScopes: Schema.$Array<Schema.Union<readonly [Schema.Union<readonly [Schema.Literals<readonly ["arabic-text", "metadata"]>, Schema.Literals<readonly ["en-tafsir-access", "de-tafsir-access"]>, Schema.Literal<"id-tafsir">]>, Schema.TemplateLiteral<readonly [Schema.Literals<readonly ["en", "id", "de"]>, "-surah-name"]>, Schema.TemplateLiteral<readonly [Schema.Literals<readonly ["en", "id", "de"]>, "-translation"]>]>>;
|
|
120
|
-
}>, import("effect/Cause").YieldableError
|
|
120
|
+
}>, import("effect/Cause").YieldableError & {
|
|
121
|
+
readonly brand: unique symbol;
|
|
122
|
+
}>;
|
|
121
123
|
/** Quran provenance omitted or misordered an active-locale scope. */
|
|
122
124
|
export declare class QuranProvenanceCoverageError extends QuranProvenanceCoverageError_base {
|
|
123
125
|
}
|
|
124
|
-
declare const QuranProvenanceHashError_base: Schema.Class<QuranProvenanceHashError, Schema.TaggedStruct<"QuranProvenanceHashError", {}>, import("effect/Cause").YieldableError
|
|
126
|
+
declare const QuranProvenanceHashError_base: Schema.Class<QuranProvenanceHashError, Schema.TaggedStruct<"QuranProvenanceHashError", {}>, import("effect/Cause").YieldableError & {
|
|
127
|
+
readonly brand: unique symbol;
|
|
128
|
+
}>;
|
|
125
129
|
/** Node could not compute the deterministic provenance digest. */
|
|
126
130
|
export declare class QuranProvenanceHashError extends QuranProvenanceHashError_base {
|
|
127
131
|
}
|
package/dist/quran/provenance.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import { Array as Arr, Effect, MutableList, Schema } from "effect";
|
|
2
|
+
import { hashText } from "#contracts/hash/text";
|
|
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";
|
|
@@ -116,20 +116,13 @@ export function canonicalizeQuranProvenance(record) {
|
|
|
116
116
|
});
|
|
117
117
|
}
|
|
118
118
|
/** Digests exact ordered provenance records under their active locale set. */
|
|
119
|
-
export const hashQuranProvenance = Effect.fn("AksaraContracts.hashQuranProvenance")((input)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (const record of input.records) {
|
|
127
|
-
hash.update(canonicalizeQuranProvenance(record));
|
|
128
|
-
hash.update("\n");
|
|
129
|
-
}
|
|
130
|
-
return Sha256HashSchema.make(`sha256:${hash.digest("hex")}`);
|
|
131
|
-
},
|
|
132
|
-
}));
|
|
119
|
+
export const hashQuranProvenance = Effect.fn("AksaraContracts.hashQuranProvenance")(function* (input) {
|
|
120
|
+
let canonical = `${PROVENANCE_DOMAIN}\n${encodeJsonText(input.activeAppLocales)}\n`;
|
|
121
|
+
for (const record of input.records) {
|
|
122
|
+
canonical += `${canonicalizeQuranProvenance(record)}\n`;
|
|
123
|
+
}
|
|
124
|
+
return yield* hashText(canonical).pipe(Effect.mapError(() => new QuranProvenanceHashError()));
|
|
125
|
+
});
|
|
133
126
|
/** Builds a snapshot provenance gate from exact reviewed source records. */
|
|
134
127
|
export const makeQuranProvenanceManifest = Effect.fn("AksaraContracts.makeQuranProvenanceManifest")(function* (input) {
|
|
135
128
|
const decoded = yield* Schema.decodeUnknownEffect(Schema.Struct({
|
|
@@ -5,14 +5,18 @@ import { QuranRowHashError } from "#contracts/quran/snapshot/row/hash";
|
|
|
5
5
|
declare const QuranRowIntegrityError_base: Schema.Class<QuranRowIntegrityError, Schema.TaggedStruct<"QuranRowIntegrityError", {
|
|
6
6
|
readonly actual: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
7
7
|
readonly expected: Schema.brand<Schema.String, "@NakafaAI/AksaraSha256Hash">;
|
|
8
|
-
}>, import("effect/Cause").YieldableError
|
|
8
|
+
}>, import("effect/Cause").YieldableError & {
|
|
9
|
+
readonly brand: unique symbol;
|
|
10
|
+
}>;
|
|
9
11
|
/** A current row hash does not authenticate its structured payload. */
|
|
10
12
|
export declare class QuranRowIntegrityError extends QuranRowIntegrityError_base {
|
|
11
13
|
}
|
|
12
14
|
declare const QuranRowOrderError_base: Schema.Class<QuranRowOrderError, Schema.TaggedStruct<"QuranRowOrderError", {
|
|
13
15
|
readonly actual: Schema.String;
|
|
14
16
|
readonly expected: Schema.String;
|
|
15
|
-
}>, import("effect/Cause").YieldableError
|
|
17
|
+
}>, import("effect/Cause").YieldableError & {
|
|
18
|
+
readonly brand: unique symbol;
|
|
19
|
+
}>;
|
|
16
20
|
/** A current row does not match the next deterministic snapshot identity. */
|
|
17
21
|
export declare class QuranRowOrderError extends QuranRowOrderError_base {
|
|
18
22
|
}
|
|
@@ -21,13 +25,13 @@ export declare const digestQuranRows: <E, R>(input: {
|
|
|
21
25
|
readonly activeAppLocales: ActiveAppLocaleList;
|
|
22
26
|
readonly rows: Stream.Stream<Pick<QuranSnapshotRow, "payload" | "rowHash">, E, R>;
|
|
23
27
|
}) => Effect.Effect<{
|
|
28
|
+
projectionDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
29
|
+
runtimeDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
30
|
+
searchDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
24
31
|
attributionCount: number;
|
|
25
32
|
chunkCount: number;
|
|
26
33
|
projectionCount: number;
|
|
27
|
-
projectionDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
28
34
|
runtimeCount: number;
|
|
29
|
-
runtimeDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
30
35
|
searchCount: number;
|
|
31
|
-
searchDigest: string & import("effect/Brand").Brand<"@NakafaAI/AksaraSha256Hash">;
|
|
32
36
|
}, E | QuranRowHashError | QuranRowIntegrityError | QuranRowOrderError, R>;
|
|
33
37
|
export {};
|