Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
blame on this site's /mcp
CLI
abso blame src/engine/experimental/projection-overlay-storage.ts --version 143 --json
JSON
/christopher/abso-core/blame/src/engine/experimental/projection-overlay-storage.ts?version=143&format=json
71 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 143,

71 lines from 1 change in 1 version.

codex-capacity-chair143Add inactive disk projection provider and verified transactional readers (#16)Compare1import type { GraphStateStorage } from "../state-source.ts";
2
3type OverlayRow = { collection: string; key: string; present: boolean; value?: unknown };
4
5/** Disk-backed temporary pages over immutable committed projection pages. */
6export class ProjectionOverlayStorage implements GraphStateStorage {
7 readonly #base: GraphStateStorage;
8 readonly #collection: string;
9 #open = true;
10 constructor(base: GraphStateStorage, namespace: string) {
11 if (!namespace) throw Error("missing projection overlay namespace");
12 this.#base = base;
13 this.#collection = `projection:temporary:${namespace}`;
14 for (const _ of base.entries(this.#collection)) throw Error("projection overlay namespace is occupied");
15 }
16 #check(): void {
17 if (!this.#open) throw Error("closed projection overlay");
18 }
19 #key(collection: string, key: string): string {
20 return JSON.stringify([collection, key]);
21 }
22 read(collection: string, key: string): unknown {
23 this.#check();
24 const row = this.#base.read(this.#collection, this.#key(collection, key)) as OverlayRow | undefined;
25 return row ? (row.present ? row.value : undefined) : this.#base.read(collection, key);
26 }
27 write(collection: string, key: string, value: unknown): void {
28 this.#check();
29 this.#base.write(this.#collection, this.#key(collection, key), { collection, key, present: true, value });
30 }
31 remove(collection: string, key: string): void {
32 this.#check();
33 this.#base.write(this.#collection, this.#key(collection, key), { collection, key, present: false });
34 }
35 *entries(collection: string): Iterable<readonly [string, unknown]> {
36 this.#check();
37 for (const [key, value] of this.#rows(collection)) {
38 this.#check();
39 if (!this.#base.read(this.#collection, this.#key(collection, key))) yield [key, value];
40 }
41 for (const [, value] of this.#rows(this.#collection)) {
42 this.#check();
43 const row = value as OverlayRow;
44 if (row.collection === collection && row.present) yield [row.key, row.value];
45 }
46 this.#check();
47 }
48 *#rows(collection: string): Iterable<readonly [string, unknown]> {
49 this.#check();
50 const iterator = this.#base.entries(collection)[Symbol.iterator]();
51 while (true) {
52 this.#check();
53 const next = iterator.next();
54 this.#check();
55 if (next.done) return;
56 yield next.value;
57 }
58 }
59 transaction<T>(body: () => T): T {
60 this.#check();
61 return this.#base.transaction(body);
62 }
63 /** Invoke before the owning outer transaction commits; failed cleanup must abort it. */
64 close(): void {
65 if (!this.#open) return;
66 this.#base.transaction(() => {
67 for (const [key] of this.#base.entries(this.#collection)) this.#base.remove(this.#collection, key);
68 });
69 this.#open = false;
70 }