Versions 286 to 287
new file, 360 lines
1+// Local projects (abso init --local): the open server's own router and project object (server/src) run in this
2+// process, over Node's SQLite, so a project needs no server, account or network. Each project is one SQLite file in a
3+// store folder. Every call runs in one SQLite write transaction, which is the store's lock: another process's call
5+
12+
17+/** The shared token the in-process server is given, and that its calls carry. Not a secret: nothing listens. */
19+
21+
23+
25+ * Where local projects live: the folder's own store (--store, kept in its config), else ABSO_STORE, else the OS's
26+ * per-user data folder. Undefined when there is none to use (no data folder and nothing named), so nothing assumes a
29+export function storeDir(env: EnvMap, configured?: string, cwd = process.cwd()): string | undefined {
47+
49+ "there's no folder for local projects here: set ABSO_STORE to one, or give abso init --local a --store <folder>";
50+
51+// --- The Workers runtime's parts the server uses, over node:sqlite -----------------------------------------------
52+
63+
64+/** A Durable Object's storage: SQL, synchronous transactions, the key-value calls and the alarm, on one database. */
67+ "CREATE TABLE IF NOT EXISTS _local_kv (key TEXT PRIMARY KEY, value BLOB NOT NULL); CREATE TABLE IF NOT EXISTS _local_alarm (id INTEGER PRIMARY KEY CHECK (id = 0), at INTEGER)",
80+ const out = (v: unknown) => (v instanceof Uint8Array ? v.buffer.slice(v.byteOffset, v.byteOffset + v.byteLength) : v);
83+ const row = prepared("SELECT value FROM _local_kv WHERE key = ?").get(key) as { value: Uint8Array } | undefined;
88+ "INSERT INTO _local_kv (key, value) VALUES (?, ?) ON CONFLICT (key) DO UPDATE SET value = excluded.value",
91+ (prepared("DELETE FROM _local_kv WHERE key = ?").run(key) as { changes: number | bigint }).changes > 0;
97+ const rows = statement.columns().length > 0 ? statement.all(...args) : (statement.run(...args), []);
140+ rows.filter((r) => r.key.startsWith(options.prefix ?? "")).map((r) => [r.key, deserialize(r.value)]),
143+ // The alarm is kept, but nothing in a local project needs it: it pushes out to Artifacts, which is off here.
145+ const row = prepared("SELECT at FROM _local_alarm WHERE id = 0").get() as { at: number | null } | undefined;
149+ prepared("INSERT INTO _local_alarm (id, at) VALUES (0, ?) ON CONFLICT (id) DO UPDATE SET at = excluded.at").run(
159+
185+
186+// --- Loading the server's code ------------------------------------------------------------------------------------
187+
194+
195+/** Node's SQLite says it's experimental on every start; that line would land in every local command's output. */
207+
208+export const NODE_TOO_OLD = `local projects need Node 22.13 or later, for its built-in SQLite; this is Node ${process.versions.node}`;
209+
220+ // Run as .ts files, the server's `import { DurableObject } from "cloudflare:workers"` needs a stand-in. A built
221+ // copy has it already: the build points the import at the same file (scripts/build-client.mjs).
245+
248+
249+// --- One store, as a fetch -----------------------------------------------------------------------------------------
250+
255+ /** PRAGMA data_version when this process last used the project: it changes when another process writes. */
258+
261+
271+
275+
277+ * The fetch a local folder's calls go through: each call is answered by the open server's router, in this process,
280+export function localFetch(dir: string): (input: string, init?: RequestInit) => Promise<Response> {
292+ db.exec("PRAGMA journal_mode = WAL; PRAGMA busy_timeout = 120000; PRAGMA synchronous = NORMAL");
313+ // Issues, asks and news aren't in local projects yet: a start note's issue hooks find nothing to call.
323+ if (!NAME.test(name)) return json(400, { error: "project names use letters, digits, '.', '_' and '-'" });
332+ const version = (p.db.prepare("PRAGMA data_version").get() as { data_version: number }).data_version;
341+ // The answer is read whole before the write is kept, so a body that fails to arrive keeps nothing either.
359+
360+const issuesNone = async () => json(404, { error: "issues, asks and news aren't in local projects yet" });
- MCP
- compare on this site's /mcp
- CLI
- abso diff 286 287 client/src/local-store.ts --json
- JSON
- /christopher/abso-core/compare/286..287?file=client%2Fsrc%2Flocal-store.ts&format=json