- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/src/engine/experimental/projection-records.ts?format=json
79 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 143, 1 version changed it
1/** Persisted records for the internal projection experiment; not a production format. */
2export type ProjectionPage = number | null;
3export interface FileMarker {
4 readonly contributions: number;
5 readonly kind: "file";
6 readonly enter: number;
7 readonly exit: number;
8}
9export interface LineMarker {
10 readonly kind: "line";
11 readonly enter: number;
12 readonly exit: number;
13 readonly parentKey: number;
14 readonly key: string;
15}
16export type ProjectionMarker = FileMarker | LineMarker;
17export interface ProjectionMembership {
18 readonly present: boolean;
19 readonly dependents: number;
20}
21export interface ProjectionChildRoot {
22 readonly root: ProjectionPage;
23}
24export type ProjectionAttributeName = "exists" | "exec" | "link" | "blob";
25export type ProjectionAttributes = Partial<Record<ProjectionAttributeName, ProjectionPage>>;
26export interface ProjectionAttributeValue {
27 readonly value: string | null;
28}
29const safe = (value: unknown): value is number => Number.isSafeInteger(value) && Number(value) >= 0;
30const record = (value: unknown): value is Record<string, unknown> =>
31 value !== null && typeof value === "object" && !Array.isArray(value);
32const markerId = (value: unknown): value is number => safe(value) && value < 2 ** 32;
33const page = (value: unknown): value is ProjectionPage => value === null || safe(value);
34export function projectionMarker(value: unknown): ProjectionMarker {
35 if (!record(value) || !markerId(value.enter) || !markerId(value.exit) || value.enter === value.exit)
36 throw Error("invalid projection marker endpoints");
37 if (value.kind === "file" && Object.keys(value).length === 4 && safe(value.contributions))
38 return { kind: "file", enter: value.enter, exit: value.exit, contributions: value.contributions };
39 if (
40 value.kind !== "line" ||
41 Object.keys(value).length !== 5 ||
42 !markerId(value.parentKey) ||
43 typeof value.key !== "string" ||
44 !/^[0-9a-f]{57}$/.test(value.key)
45 )
46 throw Error("invalid projection line marker");
47 return { kind: "line", enter: value.enter, exit: value.exit, parentKey: value.parentKey, key: value.key };
48}
49export function projectionMembership(value: unknown): ProjectionMembership {
50 if (
51 !record(value) ||
52 Object.keys(value).length !== 2 ||
53 typeof value.present !== "boolean" ||
54 !safe(value.dependents) ||
55 (!value.present && value.dependents !== 0)
56 )
57 throw Error("invalid projection membership");
58 return { present: value.present, dependents: value.dependents };
59}
60export function projectionChildRoot(value: unknown): ProjectionChildRoot {
61 if (!record(value) || Object.keys(value).length !== 1 || !page(value.root))
62 throw Error("invalid projection child root");
63 return { root: value.root };
64}
65export function projectionAttributes(value: unknown): ProjectionAttributes {
66 if (!record(value) || Object.keys(value).length > 4) throw Error("invalid projection attributes");
67 const out: ProjectionAttributes = {};
68 for (const [name, root] of Object.entries(value)) {
69 if (!["exists", "exec", "link", "blob"].includes(name) || !page(root))
70 throw Error("invalid projection attribute root");
71 out[name as ProjectionAttributeName] = root;
72 }
73 return out;
74}
75export function projectionAttributeValue(value: unknown): ProjectionAttributeValue {
76 if (!record(value) || Object.keys(value).length !== 1 || (value.value !== null && typeof value.value !== "string"))
77 throw Error("invalid projection attribute value");
78 return { value: value.value };
79}