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
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/src/engine/test/storage-helper.ts?format=json
46 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 111, 2 versions changed it
1import { DatabaseSync } from "node:sqlite";
2import type { GraphStateStorage } from "../state-source.ts";
3
4export class SqlState implements GraphStateStorage {
5 readonly db: DatabaseSync;
6 reads = 0;
7 writes = 0;
8 scans = 0;
9 failWrite = Infinity;
10 constructor(filename = ":memory:") {
11 this.db = new DatabaseSync(filename);
12 this.db.exec(
13 "CREATE TABLE IF NOT EXISTS state (collection TEXT, key TEXT, value TEXT, PRIMARY KEY(collection,key))",
14 );
15 }
16 read(collection: string, key: string): unknown {
17 this.reads++;
18 const row = this.db.prepare("SELECT value FROM state WHERE collection = ? AND key = ?").get(collection, key);
19 return row ? JSON.parse(row.value as string).value : undefined;
20 }
21 write(collection: string, key: string, value: unknown): void {
22 if (++this.writes === this.failWrite) throw new Error("injected storage failure");
23 this.db.prepare("INSERT OR REPLACE INTO state VALUES (?, ?, ?)").run(collection, key, JSON.stringify({ value }));
24 }
25 remove(collection: string, key: string): void {
26 this.db.prepare("DELETE FROM state WHERE collection = ? AND key = ?").run(collection, key);
27 }
28 *entries(collection: string): Iterable<readonly [string, unknown]> {
29 this.scans++;
30 for (const row of this.db
31 .prepare("SELECT key, value FROM state WHERE collection = ? ORDER BY key")
32 .iterate(collection))
33 yield [row.key as string, JSON.parse(row.value as string).value];
34 }
35 transaction<T>(body: () => T): T {
36 this.db.exec("SAVEPOINT graph_change");
37 try {
38 const value = body();
39 this.db.exec("RELEASE graph_change");
40 return value;
41 } catch (error) {
42 this.db.exec("ROLLBACK TO graph_change; RELEASE graph_change");
43 throw error;
44 }
45 }