{"file":"server/src/engine-project.ts","version":161,"total":768,"from":1,"to":768,"lines":[{"n":1,"text":"// The engine's Project (worker/project/project.ts) behind the server's calls, with its append-only log kept in the","atom":"a1445","author":"speed","version":150},{"n":2,"text":"// Durable Object's SQLite. An entry longer than one row allows (init holds every starting file; SQLite rows stop at","atom":"a1445","author":"speed","version":150},{"n":3,"text":"// 2 MB) is split across rows and joined on load. Ported from the platform's worker/src/engine-project.ts; the","atom":"a1445","author":"speed","version":150},{"n":4,"text":"// writer-adoption and R2 version parts are left out.","atom":"a1445","author":"speed","version":150},{"n":5,"text":"","atom":"a1445","author":"speed","version":150},{"n":6,"text":"import { blame, folderBlame, why } from \"../../worker/project/blame.ts\";","atom":"a1445","author":"speed","version":150},{"n":7,"text":"import { feedEvents } from \"../../worker/project/feed.ts\";","atom":"a1445","author":"speed","version":150},{"n":8,"text":"import { type Entry, type ProjectStore as LogStore, MemoryStore, Project } from \"../../worker/project/project.ts\";","atom":"a1483","author":"speed","version":150},{"n":9,"text":"import type { EditBody, ProjectCalls, ProjectHistory } from \"../../worker/project/project-api.ts\";","atom":"a1445","author":"speed","version":150},{"n":10,"text":"import { where } from \"../../worker/project/where.ts\";","atom":"a1445","author":"speed","version":150},{"n":11,"text":"","atom":"a1445","author":"speed","version":150},{"n":12,"text":"/** The parts of a Durable Object's storage the log and blob store use, declared structurally so tests can stand in. */","atom":"a1445","author":"speed","version":150},{"n":13,"text":"export interface SqliteStorage {","atom":"a1445","author":"speed","version":150},{"n":14,"text":"\tsql: { exec(query: string, ...bindings: unknown[]): { toArray(): unknown[] } };","atom":"a1445","author":"speed","version":150},{"n":15,"text":"\ttransactionSync<T>(fn: () => T): T;","atom":"a1445","author":"speed","version":150},{"n":16,"text":"}","atom":"a1445","author":"speed","version":150},{"n":17,"text":"","atom":"a1445","author":"speed","version":150},{"n":18,"text":"// Characters per row. SQLite's 2 MB cap is in bytes, and a character is at","atom":"a1445","author":"speed","version":150},{"n":19,"text":"// most 3 bytes of UTF-8 (an emoji is 2 characters and 4 bytes), so 600,000 stays under it.","atom":"a1445","author":"speed","version":150},{"n":20,"text":"export const LOG_PART_CHARACTERS = 600_000;","atom":"a1589","author":"codex-capacity-chair","version":157},{"n":21,"text":"","atom":"a1445","author":"speed","version":150},{"n":22,"text":"/** An entry's JSON in rows of at most LOG_PART_CHARACTERS characters, never cutting an emoji's two halves apart. */","atom":"a1589","author":"codex-capacity-chair","version":157},{"n":23,"text":"export function logParts(text: string): string[] {","atom":"a1445","author":"speed","version":150},{"n":24,"text":"\tconst parts: string[] = [];","atom":"a1445","author":"speed","version":150},{"n":25,"text":"\tlet at = 0;","atom":"a1445","author":"speed","version":150},{"n":26,"text":"\tdo {","atom":"a1445","author":"speed","version":150},{"n":27,"text":"\t\tlet end = Math.min(at + LOG_PART_CHARACTERS, text.length);","atom":"a1589","author":"codex-capacity-chair","version":157},{"n":28,"text":"\t\tconst c = text.charCodeAt(end - 1);","atom":"a1445","author":"speed","version":150},{"n":29,"text":"\t\tif (end < text.length && c >= 0xd800 && c <= 0xdbff) end--;","atom":"a1445","author":"speed","version":150},{"n":30,"text":"\t\tparts.push(text.slice(at, end));","atom":"a1445","author":"speed","version":150},{"n":31,"text":"\t\tat = end;","atom":"a1445","author":"speed","version":150},{"n":32,"text":"\t} while (at < text.length);","atom":"a1445","author":"speed","version":150},{"n":33,"text":"\treturn parts;","atom":"a1445","author":"speed","version":150},{"n":34,"text":"}","atom":"a1445","author":"speed","version":150},{"n":35,"text":"","atom":"a1445","author":"speed","version":150},{"n":36,"text":"/** The lines an entry's atoms write: what a loaded project's size grows with (#46, #56). */","atom":"a1445","author":"speed","version":150},{"n":37,"text":"function linesIn(entry: Entry): number {","atom":"a1445","author":"speed","version":150},{"n":38,"text":"\tlet n = 0;","atom":"a1445","author":"speed","version":150},{"n":39,"text":"\tfor (const a of [","atom":"a1445","author":"speed","version":150},{"n":40,"text":"\t\t(entry as { atom?: { inserts?: { lines: unknown[] }[] } }).atom,","atom":"a1445","author":"speed","version":150},{"n":41,"text":"\t\t(entry as { tie?: { inserts?: { lines: unknown[] }[] } }).tie,","atom":"a1445","author":"speed","version":150},{"n":42,"text":"\t]) {","atom":"a1445","author":"speed","version":150},{"n":43,"text":"\t\tfor (const r of a?.inserts ?? []) n += r.lines.length;","atom":"a1445","author":"speed","version":150},{"n":44,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":45,"text":"\treturn n;","atom":"a1445","author":"speed","version":150},{"n":46,"text":"}","atom":"a1445","author":"speed","version":150},{"n":47,"text":"","atom":"a1445","author":"speed","version":150},{"n":48,"text":"/** The version of shared an entry makes, or undefined (abso issue 78: the access check reads it without loading). */","atom":"a1445","author":"speed","version":150},{"n":49,"text":"function sharedVersionOf(entry: Entry): number | undefined {","atom":"a1445","author":"speed","version":150},{"n":50,"text":"\tif (entry.type === \"init\") return 0;","atom":"a1445","author":"speed","version":150},{"n":51,"text":"\tif (entry.type === \"land\" || entry.type === \"drop\") return entry.version;","atom":"a1445","author":"speed","version":150},{"n":52,"text":"\tif (entry.type === \"publish\" && (entry.space ?? \"\") === \"\") return entry.version;","atom":"a1445","author":"speed","version":150},{"n":53,"text":"\treturn undefined;","atom":"a1445","author":"speed","version":150},{"n":54,"text":"}","atom":"a1445","author":"speed","version":150},{"n":55,"text":"","atom":"a1445","author":"speed","version":150},{"n":56,"text":"/** Who made that version of shared, and when. Init is not a publish (abso issue 86). */","atom":"a1445","author":"speed","version":150},{"n":57,"text":"function lastPublishOf(entry: Entry): { agent: string; time: number } | undefined {","atom":"a1445","author":"speed","version":150},{"n":58,"text":"\tif (entry.type === \"land\" || entry.type === \"drop\") return { agent: entry.agent, time: entry.time };","atom":"a1445","author":"speed","version":150},{"n":59,"text":"\tif (entry.type === \"publish\" && (entry.space ?? \"\") === \"\") return { agent: entry.agent, time: entry.time };","atom":"a1445","author":"speed","version":150},{"n":60,"text":"\treturn undefined;","atom":"a1445","author":"speed","version":150},{"n":61,"text":"}","atom":"a1445","author":"speed","version":150},{"n":62,"text":"","atom":"a1445","author":"speed","version":150},{"n":63,"text":"/** An entry's claim keys and deletes (#46): with entries and lines, what the load guard estimates memory by. */","atom":"a1445","author":"speed","version":150},{"n":64,"text":"function keysIn(entry: Entry): number {","atom":"a1445","author":"speed","version":150},{"n":65,"text":"\tlet n = 0;","atom":"a1445","author":"speed","version":150},{"n":66,"text":"\tfor (const a of [","atom":"a1445","author":"speed","version":150},{"n":67,"text":"\t\t(entry as { atom?: Partial<Record<\"writes\" | \"reads\" | \"holds\" | \"deletes\", unknown[]>> }).atom,","atom":"a1445","author":"speed","version":150},{"n":68,"text":"\t\t(entry as { tie?: Partial<Record<\"writes\" | \"reads\" | \"holds\" | \"deletes\", unknown[]>> }).tie,","atom":"a1445","author":"speed","version":150},{"n":69,"text":"\t]) {","atom":"a1445","author":"speed","version":150},{"n":70,"text":"\t\tif (a) n += (a.writes?.length ?? 0) + (a.reads?.length ?? 0) + (a.holds?.length ?? 0) + (a.deletes?.length ?? 0);","atom":"a1445","author":"speed","version":150},{"n":71,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":72,"text":"\treturn n;","atom":"a1445","author":"speed","version":150},{"n":73,"text":"}","atom":"a1445","author":"speed","version":150},{"n":74,"text":"","atom":"a1445","author":"speed","version":150},{"n":75,"text":"export class SqliteLog implements LogStore {","atom":"a1445","author":"speed","version":150},{"n":76,"text":"\tprivate storage: SqliteStorage;","atom":"a1445","author":"speed","version":150},{"n":77,"text":"\tprivate next: number;","atom":"a1445","author":"speed","version":150},{"n":78,"text":"","atom":"a1445","author":"speed","version":150},{"n":79,"text":"\tconstructor(storage: SqliteStorage) {","atom":"a1445","author":"speed","version":150},{"n":80,"text":"\t\tthis.storage = storage;","atom":"a1445","author":"speed","version":150},{"n":81,"text":"\t\tstorage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":82,"text":"\t\t\t\"CREATE TABLE IF NOT EXISTS log (seq INTEGER, part INTEGER, text TEXT NOT NULL, PRIMARY KEY (seq, part))\",","atom":"a1445","author":"speed","version":150},{"n":83,"text":"\t\t);","atom":"a1445","author":"speed","version":150},{"n":84,"text":"\t\tstorage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":85,"text":"\t\t\t\"CREATE TABLE IF NOT EXISTS shapes (space TEXT NOT NULL, version INTEGER NOT NULL, value TEXT NOT NULL, PRIMARY KEY (space, version))\",","atom":"a1445","author":"speed","version":150},{"n":86,"text":"\t\t);","atom":"a1445","author":"speed","version":150},{"n":87,"text":"\t\tstorage.sql.exec(\"CREATE TABLE IF NOT EXISTS counts (name TEXT PRIMARY KEY, value INTEGER NOT NULL)\");","atom":"a1445","author":"speed","version":150},{"n":88,"text":"\t\tstorage.sql.exec(\"CREATE TABLE IF NOT EXISTS marks (name TEXT PRIMARY KEY, value TEXT NOT NULL)\");","atom":"a1445","author":"speed","version":150},{"n":89,"text":"\t\tconst rows = storage.sql.exec(\"SELECT COALESCE(MAX(seq), -1) AS last FROM log\").toArray() as { last: number }[];","atom":"a1445","author":"speed","version":150},{"n":90,"text":"\t\tthis.next = (rows[0]?.last ?? -1) + 1;","atom":"a1445","author":"speed","version":150},{"n":91,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":92,"text":"","atom":"a1445","author":"speed","version":150},{"n":93,"text":"\t/** The seq the next entry would take. A copy's next page must start here. */","atom":"a1445","author":"speed","version":150},{"n":94,"text":"\tseq(): number {","atom":"a1445","author":"speed","version":150},{"n":95,"text":"\t\treturn this.next;","atom":"a1445","author":"speed","version":150},{"n":96,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":97,"text":"","atom":"a1446","author":"speed","version":150},{"n":98,"text":"\t/** Reject an oversized canonical frame before loading its text into JavaScript. */","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":99,"text":"\tboundedFrame(seq: number, maxBytes: number): string {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":100,"text":"\t\tif (","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":101,"text":"\t\t\t!Number.isSafeInteger(seq) ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":102,"text":"\t\t\tseq < 0 ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":103,"text":"\t\t\t!Number.isSafeInteger(maxBytes) ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":104,"text":"\t\t\tmaxBytes < 1 ||","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":105,"text":"\t\t\tmaxBytes > 8_000_000","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":106,"text":"\t\t)","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":107,"text":"\t\t\tthrow new Error(\"invalid canonical frame bound\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":108,"text":"\t\tconst size = this.storage.sql","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":109,"text":"\t\t\t.exec(","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":110,"text":"\t\t\t\t\"SELECT COUNT(*) AS parts, COALESCE(SUM(LENGTH(CAST(text AS BLOB))), 0) AS bytes FROM log WHERE seq = ?\",","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":111,"text":"\t\t\t\tseq,","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":112,"text":"\t\t\t)","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":113,"text":"\t\t\t.toArray()[0] as { parts: number; bytes: number };","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":114,"text":"\t\tif (!size || size.parts < 1 || size.parts > 256 || size.bytes > maxBytes)","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":115,"text":"\t\t\tthrow new Error(\"canonical frame exceeds adoption bound or is missing\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":116,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT part, text FROM log WHERE seq = ? ORDER BY part\", seq).toArray() as {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":117,"text":"\t\t\tpart: number;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":118,"text":"\t\t\ttext: string;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":119,"text":"\t\t}[];","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":120,"text":"\t\tif (rows.length !== size.parts || rows.some((row, part) => row.part !== part))","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":121,"text":"\t\t\tthrow new Error(\"canonical frame parts are incomplete\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":122,"text":"\t\treturn rows.map((row) => row.text).join(\"\");","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":123,"text":"\t}","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":124,"text":"","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":125,"text":"\t/** Refreshes the in-memory cursor after an enclosing transaction rolls back. */","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":126,"text":"\trefreshSequence(): void {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":127,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT COALESCE(MAX(seq), -1) AS last FROM log\").toArray() as {","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":128,"text":"\t\t\tlast: number;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":129,"text":"\t\t}[];","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":130,"text":"\t\tthis.next = (rows[0]?.last ?? -1) + 1;","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":131,"text":"\t}","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":132,"text":"","atom":"a1582","author":"codex-capacity-chair","version":157},{"n":133,"text":"\t/** Monotonic cache invalidation epoch for every canonical log mutation. */","atom":"a1445","author":"speed","version":150},{"n":134,"text":"\tgeneration(): number {","atom":"a1445","author":"speed","version":150},{"n":135,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM marks WHERE name = ?\", \"generation\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":136,"text":"\t\t\tvalue: string;","atom":"a1445","author":"speed","version":150},{"n":137,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":138,"text":"\t\tconst generation = Number(rows[0]?.value ?? 0);","atom":"a1445","author":"speed","version":150},{"n":139,"text":"\t\tif (!Number.isSafeInteger(generation) || generation < 0) throw new Error(\"canonical log generation is invalid\");","atom":"a1445","author":"speed","version":150},{"n":140,"text":"\t\treturn generation;","atom":"a1445","author":"speed","version":150},{"n":141,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":142,"text":"","atom":"a1445","author":"speed","version":150},{"n":143,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":144,"text":"\t * Lines ever recorded (#46, #56): what loading the project costs grows with","atom":"a1445","author":"speed","version":150},{"n":145,"text":"\t * this, not with the log's size, so a guard can read it without loading.","atom":"a1445","author":"speed","version":150},{"n":146,"text":"\t * Kept with each append; undefined for a log written before the count,","atom":"a1445","author":"speed","version":150},{"n":147,"text":"\t * until it next loads.","atom":"a1445","author":"speed","version":150},{"n":148,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":149,"text":"\tlineCount(): number | undefined {","atom":"a1445","author":"speed","version":150},{"n":150,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'lines'\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":151,"text":"\t\t\tvalue: number;","atom":"a1445","author":"speed","version":150},{"n":152,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":153,"text":"\t\treturn rows[0]?.value;","atom":"a1445","author":"speed","version":150},{"n":154,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":155,"text":"","atom":"a1445","author":"speed","version":150},{"n":156,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":157,"text":"\t * The newest version of shared, without loading the project (abso issue 78: the website's access check asked","atom":"a1445","author":"speed","version":150},{"n":158,"text":"\t * every project's engine for it). Kept with each append; a log from before the count is read once by streaming.","atom":"a1445","author":"speed","version":150},{"n":159,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":160,"text":"\tsharedVersion(): number {","atom":"a1445","author":"speed","version":150},{"n":161,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'shared'\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":162,"text":"\t\t\tvalue: number;","atom":"a1445","author":"speed","version":150},{"n":163,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":164,"text":"\t\tif (rows[0] !== undefined) return rows[0].value;","atom":"a1445","author":"speed","version":150},{"n":165,"text":"\t\tlet version = -1;","atom":"a1445","author":"speed","version":150},{"n":166,"text":"\t\tfor (const e of this.#entries()) version = sharedVersionOf(e) ?? version;","atom":"a1445","author":"speed","version":150},{"n":167,"text":"\t\tif (version >= 0)","atom":"a1445","author":"speed","version":150},{"n":168,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('shared', ?)\", version);","atom":"a1445","author":"speed","version":150},{"n":169,"text":"\t\treturn version;","atom":"a1445","author":"speed","version":150},{"n":170,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":171,"text":"","atom":"a1445","author":"speed","version":150},{"n":172,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":173,"text":"\t * Who published shared's newest version, and when, without loading the project (abso issue 86).","atom":"a1445","author":"speed","version":150},{"n":174,"text":"\t * Null when shared has no publish yet. A log from before the mark is read once by streaming.","atom":"a1445","author":"speed","version":150},{"n":175,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":176,"text":"\tlastPublish(): { agent: string; time: number } | null {","atom":"a1445","author":"speed","version":150},{"n":177,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM marks WHERE name = ?\", \"last\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":178,"text":"\t\t\tvalue: string;","atom":"a1445","author":"speed","version":150},{"n":179,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":180,"text":"\t\tif (rows[0] !== undefined) return JSON.parse(rows[0].value) as { agent: string; time: number };","atom":"a1445","author":"speed","version":150},{"n":181,"text":"\t\tlet last: { agent: string; time: number } | null = null;","atom":"a1445","author":"speed","version":150},{"n":182,"text":"\t\tfor (const e of this.#entries()) {","atom":"a1445","author":"speed","version":150},{"n":183,"text":"\t\t\tconst found = lastPublishOf(e);","atom":"a1445","author":"speed","version":150},{"n":184,"text":"\t\t\tif (found) last = found;","atom":"a1445","author":"speed","version":150},{"n":185,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":186,"text":"\t\tif (last)","atom":"a1445","author":"speed","version":150},{"n":187,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\", \"last\", JSON.stringify(last));","atom":"a1445","author":"speed","version":150},{"n":188,"text":"\t\treturn last;","atom":"a1445","author":"speed","version":150},{"n":189,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":190,"text":"","atom":"a1445","author":"speed","version":150},{"n":191,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":192,"text":"\t * How big the log is, without loading the project or scanning it twice (ask 160).","atom":"a1445","author":"speed","version":150},{"n":193,"text":"\t * Entries are the next seq. Chars are kept like lines; a log from before the","atom":"a1445","author":"speed","version":150},{"n":194,"text":"\t * count is summed once, then kept. GET /projects' 2-second wait needs this","atom":"a1445","author":"speed","version":150},{"n":195,"text":"\t * to stay a storage read: SUM(LENGTH(text)) over abso's log misses it.","atom":"a1445","author":"speed","version":150},{"n":196,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":197,"text":"\tlogSize(): { chars: number; entries: number } {","atom":"a1445","author":"speed","version":150},{"n":198,"text":"\t\tconst entries = this.next;","atom":"a1445","author":"speed","version":150},{"n":199,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'chars'\").toArray() as {","atom":"a1445","author":"speed","version":150},{"n":200,"text":"\t\t\tvalue: number;","atom":"a1445","author":"speed","version":150},{"n":201,"text":"\t\t}[];","atom":"a1445","author":"speed","version":150},{"n":202,"text":"\t\tif (rows[0] !== undefined) return { chars: rows[0].value, entries };","atom":"a1445","author":"speed","version":150},{"n":203,"text":"\t\tif (entries === 0) return { chars: 0, entries: 0 };","atom":"a1445","author":"speed","version":150},{"n":204,"text":"\t\tconst summed = this.storage.sql.exec(\"SELECT COALESCE(SUM(LENGTH(text)), 0) AS chars FROM log\").toArray()[0] as","atom":"a1445","author":"speed","version":150},{"n":205,"text":"\t\t\t| { chars: number }","atom":"a1445","author":"speed","version":150},{"n":206,"text":"\t\t\t| undefined;","atom":"a1445","author":"speed","version":150},{"n":207,"text":"\t\tconst chars = summed?.chars ?? 0;","atom":"a1445","author":"speed","version":150},{"n":208,"text":"\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('chars', ?)\", chars);","atom":"a1445","author":"speed","version":150},{"n":209,"text":"\t\treturn { chars, entries };","atom":"a1445","author":"speed","version":150},{"n":210,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":211,"text":"","atom":"a1445","author":"speed","version":150},{"n":212,"text":"\t/** Claim keys and deletes ever recorded (#46), kept like the line count; undefined before they were counted. */","atom":"a1445","author":"speed","version":150},{"n":213,"text":"\tkeyCount(): number | undefined {","atom":"a1445","author":"speed","version":150},{"n":214,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT value FROM counts WHERE name = 'keys'\").toArray() as { value: number }[];","atom":"a1445","author":"speed","version":150},{"n":215,"text":"\t\treturn rows[0]?.value;","atom":"a1445","author":"speed","version":150},{"n":216,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":217,"text":"","atom":"a1445","author":"speed","version":150},{"n":218,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":219,"text":"\t * The lines and keys ever recorded, counting a log from before either count without loading the project","atom":"a1445","author":"speed","version":150},{"n":220,"text":"\t * (#46): one entry parsed at a time, so a log the load guard would refuse can still be measured. Kept once counted.","atom":"a1445","author":"speed","version":150},{"n":221,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":222,"text":"\tcountSizes(): { lines: number; keys: number } {","atom":"a1445","author":"speed","version":150},{"n":223,"text":"\t\tconst lines = this.lineCount();","atom":"a1445","author":"speed","version":150},{"n":224,"text":"\t\tconst keys = this.keyCount();","atom":"a1445","author":"speed","version":150},{"n":225,"text":"\t\tif (lines !== undefined && keys !== undefined) return { lines, keys };","atom":"a1445","author":"speed","version":150},{"n":226,"text":"\t\tlet l = 0;","atom":"a1445","author":"speed","version":150},{"n":227,"text":"\t\tlet k = 0;","atom":"a1445","author":"speed","version":150},{"n":228,"text":"\t\tfor (const e of this.#entries()) {","atom":"a1445","author":"speed","version":150},{"n":229,"text":"\t\t\tl += linesIn(e);","atom":"a1445","author":"speed","version":150},{"n":230,"text":"\t\t\tk += keysIn(e);","atom":"a1445","author":"speed","version":150},{"n":231,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":232,"text":"\t\tthis.#keep(lines === undefined ? l : undefined, keys === undefined ? k : undefined);","atom":"a1445","author":"speed","version":150},{"n":233,"text":"\t\treturn { lines: lines ?? l, keys: keys ?? k };","atom":"a1445","author":"speed","version":150},{"n":234,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":235,"text":"","atom":"a1445","author":"speed","version":150},{"n":236,"text":"\t/** Stores the counts given. */","atom":"a1445","author":"speed","version":150},{"n":237,"text":"\t#keep(lines: number | undefined, keys: number | undefined): void {","atom":"a1445","author":"speed","version":150},{"n":238,"text":"\t\tif (lines !== undefined)","atom":"a1445","author":"speed","version":150},{"n":239,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('lines', ?)\", lines);","atom":"a1445","author":"speed","version":150},{"n":240,"text":"\t\tif (keys !== undefined)","atom":"a1445","author":"speed","version":150},{"n":241,"text":"\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('keys', ?)\", keys);","atom":"a1445","author":"speed","version":150},{"n":242,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":243,"text":"","atom":"a1445","author":"speed","version":150},{"n":244,"text":"\t/** Every stored entry, in order. Rows are read one at a time, so loading never holds the whole log's text at once (#43). */","atom":"a1445","author":"speed","version":150},{"n":245,"text":"\t*entries(): Iterable<Entry> {","atom":"a1445","author":"speed","version":150},{"n":246,"text":"\t\t// A log from before the counts: counted as it loads, and kept.","atom":"a1445","author":"speed","version":150},{"n":247,"text":"\t\tconst countLines = this.lineCount() === undefined;","atom":"a1445","author":"speed","version":150},{"n":248,"text":"\t\tconst countKeys = this.keyCount() === undefined;","atom":"a1445","author":"speed","version":150},{"n":249,"text":"\t\tlet lines = 0;","atom":"a1445","author":"speed","version":150},{"n":250,"text":"\t\tlet keys = 0;","atom":"a1445","author":"speed","version":150},{"n":251,"text":"\t\tfor (const e of this.#entries()) {","atom":"a1445","author":"speed","version":150},{"n":252,"text":"\t\t\tif (countLines) lines += linesIn(e);","atom":"a1445","author":"speed","version":150},{"n":253,"text":"\t\t\tif (countKeys) keys += keysIn(e);","atom":"a1445","author":"speed","version":150},{"n":254,"text":"\t\t\tyield e;","atom":"a1445","author":"speed","version":150},{"n":255,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":256,"text":"\t\tthis.#keep(countLines ? lines : undefined, countKeys ? keys : undefined);","atom":"a1445","author":"speed","version":150},{"n":257,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":258,"text":"","atom":"a1445","author":"speed","version":150},{"n":259,"text":"\t*#entries(from = 0): Iterable<Entry> {","atom":"a1445","author":"speed","version":150},{"n":260,"text":"\t\t// A Workers cursor is iterable; a test's stand-in may only have toArray.","atom":"a1445","author":"speed","version":150},{"n":261,"text":"\t\tconst cursor = this.storage.sql.exec(\"SELECT seq, text FROM log WHERE seq >= ? ORDER BY seq, part\", from) as {","atom":"a1445","author":"speed","version":150},{"n":262,"text":"\t\t\ttoArray(): unknown[];","atom":"a1445","author":"speed","version":150},{"n":263,"text":"\t\t} & Partial<Iterable<unknown>>;","atom":"a1445","author":"speed","version":150},{"n":264,"text":"\t\tconst rows = (cursor[Symbol.iterator] ? cursor : cursor.toArray()) as Iterable<{ seq: number; text: string }>;","atom":"a1445","author":"speed","version":150},{"n":265,"text":"\t\tlet seq = -1;","atom":"a1445","author":"speed","version":150},{"n":266,"text":"\t\tlet text = \"\";","atom":"a1445","author":"speed","version":150},{"n":267,"text":"\t\tfor (const r of rows) {","atom":"a1445","author":"speed","version":150},{"n":268,"text":"\t\t\tif (r.seq !== seq && seq >= 0) yield JSON.parse(text) as Entry;","atom":"a1445","author":"speed","version":150},{"n":269,"text":"\t\t\tif (r.seq !== seq) text = \"\";","atom":"a1445","author":"speed","version":150},{"n":270,"text":"\t\t\tseq = r.seq;","atom":"a1445","author":"speed","version":150},{"n":271,"text":"\t\t\ttext += r.text;","atom":"a1445","author":"speed","version":150},{"n":272,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":273,"text":"\t\tif (seq >= 0) yield JSON.parse(text) as Entry;","atom":"a1445","author":"speed","version":150},{"n":274,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":275,"text":"","atom":"a1445","author":"speed","version":150},{"n":276,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":277,"text":"\t * For backups (#29): the entries from seq `from` on as their stored JSON","atom":"a1445","author":"speed","version":150},{"n":278,"text":"\t * text (not parsed, so an export holds the project up as little as it","atom":"a1445","author":"speed","version":150},{"n":279,"text":"\t * can), at most `limit` of them and about 8 MB (always at least one), and","atom":"a1445","author":"speed","version":150},{"n":280,"text":"\t * the seq to ask for next, or null at the end.","atom":"a1445","author":"speed","version":150},{"n":281,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":282,"text":"\tpage(from: number, limit: number): { texts: string[]; next: number | null } {","atom":"a1445","author":"speed","version":150},{"n":283,"text":"\t\tconst rows = this.storage.sql","atom":"a1445","author":"speed","version":150},{"n":284,"text":"\t\t\t.exec(\"SELECT seq, text FROM log WHERE seq >= ? AND seq < ? ORDER BY seq, part\", from, from + limit)","atom":"a1445","author":"speed","version":150},{"n":285,"text":"\t\t\t.toArray() as { seq: number; text: string }[];","atom":"a1445","author":"speed","version":150},{"n":286,"text":"\t\tconst texts: string[] = [];","atom":"a1445","author":"speed","version":150},{"n":287,"text":"\t\tlet seq = -1;","atom":"a1445","author":"speed","version":150},{"n":288,"text":"\t\tlet text = \"\";","atom":"a1445","author":"speed","version":150},{"n":289,"text":"\t\tlet size = 0;","atom":"a1445","author":"speed","version":150},{"n":290,"text":"\t\tlet next: number | null = null;","atom":"a1445","author":"speed","version":150},{"n":291,"text":"\t\tfor (const r of rows) {","atom":"a1445","author":"speed","version":150},{"n":292,"text":"\t\t\tif (r.seq < from || r.seq >= from + limit) continue;","atom":"a1445","author":"speed","version":150},{"n":293,"text":"\t\t\tif (r.seq !== seq && seq >= 0) {","atom":"a1445","author":"speed","version":150},{"n":294,"text":"\t\t\t\ttexts.push(text);","atom":"a1445","author":"speed","version":150},{"n":295,"text":"\t\t\t\tsize += text.length;","atom":"a1445","author":"speed","version":150},{"n":296,"text":"\t\t\t\tif (size > 8_000_000) {","atom":"a1445","author":"speed","version":150},{"n":297,"text":"\t\t\t\t\tnext = r.seq;","atom":"a1445","author":"speed","version":150},{"n":298,"text":"\t\t\t\t\tbreak;","atom":"a1445","author":"speed","version":150},{"n":299,"text":"\t\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":300,"text":"\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":301,"text":"\t\t\tif (r.seq !== seq) text = \"\";","atom":"a1445","author":"speed","version":150},{"n":302,"text":"\t\t\tseq = r.seq;","atom":"a1445","author":"speed","version":150},{"n":303,"text":"\t\t\ttext += r.text;","atom":"a1445","author":"speed","version":150},{"n":304,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":305,"text":"\t\tif (next === null && seq >= 0) texts.push(text);","atom":"a1445","author":"speed","version":150},{"n":306,"text":"\t\tif (next === null && from + limit < this.next) next = from + limit;","atom":"a1445","author":"speed","version":150},{"n":307,"text":"\t\treturn { texts, next };","atom":"a1445","author":"speed","version":150},{"n":308,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":309,"text":"","atom":"a1445","author":"speed","version":150},{"n":310,"text":"\t/** Up to `limit` entries from position `from`, parsed (#41: the feed and replay). */","atom":"a1445","author":"speed","version":150},{"n":311,"text":"\tsince(from: number, limit: number): Entry[] {","atom":"a1445","author":"speed","version":150},{"n":312,"text":"\t\tconst out: Entry[] = [];","atom":"a1445","author":"speed","version":150},{"n":313,"text":"\t\tfor (let at = from; out.length < limit; ) {","atom":"a1445","author":"speed","version":150},{"n":314,"text":"\t\t\tconst { texts, next } = this.page(at, limit - out.length);","atom":"a1445","author":"speed","version":150},{"n":315,"text":"\t\t\tfor (const t of texts) out.push(JSON.parse(t) as Entry);","atom":"a1445","author":"speed","version":150},{"n":316,"text":"\t\t\tif (next === null || texts.length === 0) break;","atom":"a1445","author":"speed","version":150},{"n":317,"text":"\t\t\tat = next;","atom":"a1445","author":"speed","version":150},{"n":318,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":319,"text":"\t\treturn out;","atom":"a1445","author":"speed","version":150},{"n":320,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":321,"text":"","atom":"a1445","author":"speed","version":150},{"n":322,"text":"\t/** Removes every entry: only for a restore whose log didn't load (#29). */","atom":"a1445","author":"speed","version":150},{"n":323,"text":"\tclear(): void {","atom":"a1445","author":"speed","version":150},{"n":324,"text":"\t\tconst generation = this.generation() + 1;","atom":"a1445","author":"speed","version":150},{"n":325,"text":"\t\tthis.storage.transactionSync(() => {","atom":"a1445","author":"speed","version":150},{"n":326,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM log\");","atom":"a1445","author":"speed","version":150},{"n":327,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM shapes\");","atom":"a1445","author":"speed","version":150},{"n":328,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM counts\");","atom":"a1445","author":"speed","version":150},{"n":329,"text":"\t\t\tthis.storage.sql.exec(\"DELETE FROM marks WHERE name != ?\", \"generation\");","atom":"a1445","author":"speed","version":150},{"n":330,"text":"\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":331,"text":"\t\t\t\t\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\",","atom":"a1445","author":"speed","version":150},{"n":332,"text":"\t\t\t\t\"generation\",","atom":"a1445","author":"speed","version":150},{"n":333,"text":"\t\t\t\tString(generation),","atom":"a1445","author":"speed","version":150},{"n":334,"text":"\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":335,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":336,"text":"\t\tthis.next = 0;","atom":"a1445","author":"speed","version":150},{"n":337,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":338,"text":"","atom":"a1445","author":"speed","version":150},{"n":339,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":340,"text":"\t * Each version's changed files, kept between loads (#41, the Files pages):","atom":"a1445","author":"speed","version":150},{"n":341,"text":"\t * worked out from the log, never part of it, so an older Worker ignores","atom":"a1445","author":"speed","version":150},{"n":342,"text":"\t * the table and nothing about the project depends on it.","atom":"a1445","author":"speed","version":150},{"n":343,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":344,"text":"\tshapes(): {","atom":"a1445","author":"speed","version":150},{"n":345,"text":"\t\tget(space: string, version: number): string | undefined;","atom":"a1445","author":"speed","version":150},{"n":346,"text":"\t\tput(space: string, version: number, value: string): void;","atom":"a1445","author":"speed","version":150},{"n":347,"text":"\t} {","atom":"a1445","author":"speed","version":150},{"n":348,"text":"\t\tconst sql = this.storage.sql;","atom":"a1445","author":"speed","version":150},{"n":349,"text":"\t\treturn {","atom":"a1445","author":"speed","version":150},{"n":350,"text":"\t\t\tget: (space, version) =>","atom":"a1445","author":"speed","version":150},{"n":351,"text":"\t\t\t\t(","atom":"a1445","author":"speed","version":150},{"n":352,"text":"\t\t\t\t\tsql.exec(\"SELECT value FROM shapes WHERE space = ? AND version = ?\", space, version).toArray() as {","atom":"a1445","author":"speed","version":150},{"n":353,"text":"\t\t\t\t\t\tvalue: string;","atom":"a1445","author":"speed","version":150},{"n":354,"text":"\t\t\t\t\t}[]","atom":"a1445","author":"speed","version":150},{"n":355,"text":"\t\t\t\t)[0]?.value,","atom":"a1445","author":"speed","version":150},{"n":356,"text":"\t\t\tput: (space, version, value) =>","atom":"a1445","author":"speed","version":150},{"n":357,"text":"\t\t\t\tvoid sql.exec(\"INSERT OR REPLACE INTO shapes (space, version, value) VALUES (?, ?, ?)\", space, version, value),","atom":"a1445","author":"speed","version":150},{"n":358,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":359,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":360,"text":"","atom":"a1445","author":"speed","version":150},{"n":361,"text":"\tappend(entries: readonly Entry[]): void {","atom":"a1445","author":"speed","version":150},{"n":362,"text":"\t\tif (!entries.length) return;","atom":"a1445","author":"speed","version":150},{"n":363,"text":"\t\tlet next = this.next;","atom":"a1445","author":"speed","version":150},{"n":364,"text":"\t\tthis.storage.transactionSync(() => {","atom":"a1445","author":"speed","version":150},{"n":365,"text":"\t\t\tconst lines = entries.reduce((n, e) => n + linesIn(e), 0);","atom":"a1445","author":"speed","version":150},{"n":366,"text":"\t\t\tif (lines > 0)","atom":"a1445","author":"speed","version":150},{"n":367,"text":"\t\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":368,"text":"\t\t\t\t\t\"INSERT INTO counts (name, value) VALUES ('lines', ?) ON CONFLICT(name) DO UPDATE SET value = value + ?\",","atom":"a1445","author":"speed","version":150},{"n":369,"text":"\t\t\t\t\tlines,","atom":"a1445","author":"speed","version":150},{"n":370,"text":"\t\t\t\t\tlines,","atom":"a1445","author":"speed","version":150},{"n":371,"text":"\t\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":372,"text":"\t\t\t// The newest version of shared: appended entries are the newest, so the last one that makes a version wins.","atom":"a1445","author":"speed","version":150},{"n":373,"text":"\t\t\tfor (const e of entries) {","atom":"a1445","author":"speed","version":150},{"n":374,"text":"\t\t\t\tconst v = sharedVersionOf(e);","atom":"a1445","author":"speed","version":150},{"n":375,"text":"\t\t\t\tif (v !== undefined)","atom":"a1445","author":"speed","version":150},{"n":376,"text":"\t\t\t\t\tthis.storage.sql.exec(\"INSERT OR REPLACE INTO counts (name, value) VALUES ('shared', ?)\", v);","atom":"a1445","author":"speed","version":150},{"n":377,"text":"\t\t\t\tconst last = lastPublishOf(e);","atom":"a1445","author":"speed","version":150},{"n":378,"text":"\t\t\t\tif (last)","atom":"a1445","author":"speed","version":150},{"n":379,"text":"\t\t\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":380,"text":"\t\t\t\t\t\t\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\",","atom":"a1445","author":"speed","version":150},{"n":381,"text":"\t\t\t\t\t\t\"last\",","atom":"a1445","author":"speed","version":150},{"n":382,"text":"\t\t\t\t\t\tJSON.stringify(last),","atom":"a1445","author":"speed","version":150},{"n":383,"text":"\t\t\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":384,"text":"\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":385,"text":"\t\t\t// Keys are only added to once counted: a log from before the key count is counted whole first (countSizes).","atom":"a1445","author":"speed","version":150},{"n":386,"text":"\t\t\tconst keys = entries.reduce((n, e) => n + keysIn(e), 0);","atom":"a1445","author":"speed","version":150},{"n":387,"text":"\t\t\tif (keys > 0) this.storage.sql.exec(\"UPDATE counts SET value = value + ? WHERE name = 'keys'\", keys);","atom":"a1445","author":"speed","version":150},{"n":388,"text":"\t\t\tlet chars = 0;","atom":"a1445","author":"speed","version":150},{"n":389,"text":"\t\t\tfor (const entry of entries) {","atom":"a1445","author":"speed","version":150},{"n":390,"text":"\t\t\t\tconst json = JSON.stringify(entry);","atom":"a1445","author":"speed","version":150},{"n":391,"text":"\t\t\t\tlogParts(json).forEach((text, part) => {","atom":"a1445","author":"speed","version":150},{"n":392,"text":"\t\t\t\t\tchars += text.length;","atom":"a1445","author":"speed","version":150},{"n":393,"text":"\t\t\t\t\tthis.storage.sql.exec(\"INSERT INTO log (seq, part, text) VALUES (?, ?, ?)\", next, part, text);","atom":"a1445","author":"speed","version":150},{"n":394,"text":"\t\t\t\t});","atom":"a1445","author":"speed","version":150},{"n":395,"text":"\t\t\t\tnext++;","atom":"a1445","author":"speed","version":150},{"n":396,"text":"\t\t\t}","atom":"a1445","author":"speed","version":150},{"n":397,"text":"\t\t\t// Chars are only added to once counted: a log from before the count is summed whole first (logSize).","atom":"a1445","author":"speed","version":150},{"n":398,"text":"\t\t\tif (chars > 0) this.storage.sql.exec(\"UPDATE counts SET value = value + ? WHERE name = 'chars'\", chars);","atom":"a1445","author":"speed","version":150},{"n":399,"text":"\t\t\tconst generation = this.generation() + 1;","atom":"a1445","author":"speed","version":150},{"n":400,"text":"\t\t\tthis.storage.sql.exec(","atom":"a1445","author":"speed","version":150},{"n":401,"text":"\t\t\t\t\"INSERT OR REPLACE INTO marks (name, value) VALUES (?, ?)\",","atom":"a1445","author":"speed","version":150},{"n":402,"text":"\t\t\t\t\"generation\",","atom":"a1445","author":"speed","version":150},{"n":403,"text":"\t\t\t\tString(generation),","atom":"a1445","author":"speed","version":150},{"n":404,"text":"\t\t\t);","atom":"a1445","author":"speed","version":150},{"n":405,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":406,"text":"\t\tthis.next = next;","atom":"a1445","author":"speed","version":150},{"n":407,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":408,"text":"}","atom":"a1445","author":"speed","version":150},{"n":409,"text":"","atom":"a1445","author":"speed","version":150},{"n":410,"text":"/** The engine's Project as the Worker's ProjectCalls; the clock comes from here. */","atom":"a1445","author":"speed","version":150},{"n":411,"text":"export class EngineProject implements ProjectCalls, ProjectHistory {","atom":"a1445","author":"speed","version":150},{"n":412,"text":"\tblame(file: string, from?: number, to?: number, version?: number, draft?: string, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":413,"text":"\t\treturn blame(this.project, file, from, to, version, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":414,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":415,"text":"\tfolderBlame(folder: string, version?: number, draft?: string, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":416,"text":"\t\treturn folderBlame(this.project, folder, version, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":417,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":418,"text":"\ttree(folder: string, version?: number, draft?: string | null, agent?: string, authors?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":419,"text":"\t\treturn this.project.tree(folder, {","atom":"a1445","author":"speed","version":150},{"n":420,"text":"\t\t\t...(version !== undefined ? { version } : {}),","atom":"a1445","author":"speed","version":150},{"n":421,"text":"\t\t\tdraft: draft ?? null,","atom":"a1445","author":"speed","version":150},{"n":422,"text":"\t\t\t...(agent !== undefined ? { agent } : {}),","atom":"a1445","author":"speed","version":150},{"n":423,"text":"\t\t\t...(authors ? { authors } : {}),","atom":"a1445","author":"speed","version":150},{"n":424,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":425,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":426,"text":"\tpathLife(path: string, version?: number, draft?: string | null) {","atom":"a1445","author":"speed","version":150},{"n":427,"text":"\t\treturn this.project.pathLife(path, { ...(version !== undefined ? { version } : {}), draft: draft ?? null });","atom":"a1445","author":"speed","version":150},{"n":428,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":429,"text":"\tfollow(path: string, version: number, from: number, to: number, at?: number, draft?: string | null) {","atom":"a1445","author":"speed","version":150},{"n":430,"text":"\t\treturn this.project.follow(path, version, from, to, { ...(at !== undefined ? { at } : {}), draft: draft ?? null });","atom":"a1445","author":"speed","version":150},{"n":431,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":432,"text":"\tpathsOf(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":433,"text":"\t\treturn this.project.pathsOf(agent);","atom":"a1445","author":"speed","version":150},{"n":434,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":435,"text":"\tdraftState(name: string) {","atom":"a1445","author":"speed","version":150},{"n":436,"text":"\t\treturn this.project.draftState(name);","atom":"a1445","author":"speed","version":150},{"n":437,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":438,"text":"\tcollisions(file?: string, folder?: string) {","atom":"a1445","author":"speed","version":150},{"n":439,"text":"\t\treturn this.project.collisions({","atom":"a1445","author":"speed","version":150},{"n":440,"text":"\t\t\t...(file !== undefined ? { file } : {}),","atom":"a1445","author":"speed","version":150},{"n":441,"text":"\t\t\t...(folder !== undefined ? { folder } : {}),","atom":"a1445","author":"speed","version":150},{"n":442,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":443,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":444,"text":"\twhy(file: string, line: number, draft?: string, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":445,"text":"\t\treturn why(this.project, file, line, { ...(draft ? { draft } : {}), ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":446,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":447,"text":"\twhere() {","atom":"a1445","author":"speed","version":150},{"n":448,"text":"\t\treturn where(this.project);","atom":"a1445","author":"speed","version":150},{"n":449,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":450,"text":"\trefusals(agent?: string, limit?: number) {","atom":"a1445","author":"speed","version":150},{"n":451,"text":"\t\treturn this.project.refusals({ ...(agent ? { agent } : {}), ...(limit !== undefined ? { limit } : {}) });","atom":"a1445","author":"speed","version":150},{"n":452,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":453,"text":"","atom":"a1445","author":"speed","version":150},{"n":454,"text":"\tlog(draft: string | null, limit?: number, path?: string, agent?: string, before?: number, follow?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":455,"text":"\t\treturn this.project.log({","atom":"a1445","author":"speed","version":150},{"n":456,"text":"\t\t\tdraft,","atom":"a1445","author":"speed","version":150},{"n":457,"text":"\t\t\t...(limit !== undefined ? { limit } : {}),","atom":"a1445","author":"speed","version":150},{"n":458,"text":"\t\t\t...(path !== undefined ? { path } : {}),","atom":"a1445","author":"speed","version":150},{"n":459,"text":"\t\t\t...(agent ? { agent } : {}),","atom":"a1445","author":"speed","version":150},{"n":460,"text":"\t\t\t...(before !== undefined ? { before } : {}),","atom":"a1445","author":"speed","version":150},{"n":461,"text":"\t\t\t...(follow ? { follow } : {}),","atom":"a1445","author":"speed","version":150},{"n":462,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":463,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":464,"text":"\tfileAt(path: string, version: number, draft: string | null, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":465,"text":"\t\treturn this.project.fileAt(path, version, { draft, ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":466,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":467,"text":"\tcompare(from: number, to: number, draft: string | null, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":468,"text":"\t\treturn this.project.compare(from, to, { draft, ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":469,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":470,"text":"\tshow(version: number, draft: string | null, agent?: string) {","atom":"a1445","author":"speed","version":150},{"n":471,"text":"\t\treturn this.project.show(version, { draft, ...(agent ? { agent } : {}) });","atom":"a1445","author":"speed","version":150},{"n":472,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":473,"text":"\tdiff(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":474,"text":"\t\treturn this.project.diff(agent);","atom":"a1445","author":"speed","version":150},{"n":475,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":476,"text":"\tsyncFull(agent: string, label?: string) {","atom":"a1445","author":"speed","version":150},{"n":477,"text":"\t\treturn this.project.sync(agent, { full: true, ...(label !== undefined ? { label } : {}) });","atom":"a1445","author":"speed","version":150},{"n":478,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":479,"text":"\tagentPaths(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":480,"text":"\t\treturn this.project.agentPaths(agent);","atom":"a1445","author":"speed","version":150},{"n":481,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":482,"text":"\tpathsAt(version?: number, draft?: string | null) {","atom":"a1445","author":"speed","version":150},{"n":483,"text":"\t\treturn this.project.pathsAt(version, draft ?? null);","atom":"a1445","author":"speed","version":150},{"n":484,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":485,"text":"\tsyncTo(agent: string, label: string) {","atom":"a1445","author":"speed","version":150},{"n":486,"text":"\t\treturn this.project.sync(agent, { label });","atom":"a1445","author":"speed","version":150},{"n":487,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":488,"text":"\tlabel(agent: string, name: string, version?: number, remove?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":489,"text":"\t\treturn this.project.label(agent, name, version, Date.now(), { remove: remove === true });","atom":"a1445","author":"speed","version":150},{"n":490,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":491,"text":"\tlabels() {","atom":"a1445","author":"speed","version":150},{"n":492,"text":"\t\treturn this.project.labels();","atom":"a1445","author":"speed","version":150},{"n":493,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":494,"text":"\tamend(agent: string, message: string) {","atom":"a1445","author":"speed","version":150},{"n":495,"text":"\t\treturn this.project.amend(agent, message, Date.now());","atom":"a1445","author":"speed","version":150},{"n":496,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":497,"text":"\tpluck(agent: string, draft: string, versions: number[], message: string, withDependencies?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":498,"text":"\t\treturn this.project.pluck(agent, draft, versions, message, Date.now(), {","atom":"a1445","author":"speed","version":150},{"n":499,"text":"\t\t\twithDependencies: withDependencies === true,","atom":"a1445","author":"speed","version":150},{"n":500,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":501,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":502,"text":"\tdrop(agent: string, versions: number[], message: string, withDependents?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":503,"text":"\t\treturn this.project.drop(agent, versions, message, Date.now(), { withDependents: withDependents === true });","atom":"a1445","author":"speed","version":150},{"n":504,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":505,"text":"\tannounce(agent: string, text: string, to?: string[], how?: string) {","atom":"a1445","author":"speed","version":150},{"n":506,"text":"\t\treturn this.project.announce(agent, text, to, Date.now(), how);","atom":"a1445","author":"speed","version":150},{"n":507,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":508,"text":"","atom":"a1445","author":"speed","version":150},{"n":509,"text":"\tannouncePerson(person: { id: string; name: string }, text: string, to?: string[]) {","atom":"a1445","author":"speed","version":150},{"n":510,"text":"\t\treturn this.project.announcePerson(person, text, to, Date.now());","atom":"a1445","author":"speed","version":150},{"n":511,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":512,"text":"\tstarting(agent: string, text: string | null, files?: string[], options: { issue?: unknown; done?: unknown } = {}) {","atom":"a1445","author":"speed","version":150},{"n":513,"text":"\t\treturn this.project.starting(agent, text, files, Date.now(), options);","atom":"a1445","author":"speed","version":150},{"n":514,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":515,"text":"\tnews(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":516,"text":"\t\treturn this.project.news(agent);","atom":"a1445","author":"speed","version":150},{"n":517,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":518,"text":"\trestore(agent: string, files: string[] | null) {","atom":"a1445","author":"speed","version":150},{"n":519,"text":"\t\treturn this.project.restore(agent, files, Date.now());","atom":"a1445","author":"speed","version":150},{"n":520,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":521,"text":"","atom":"a1445","author":"speed","version":150},{"n":522,"text":"\tprivate project: Project;","atom":"a1445","author":"speed","version":150},{"n":523,"text":"","atom":"a1445","author":"speed","version":150},{"n":524,"text":"\t/** Reads stored entries by log position, for the feed and replay (#41); absent, those answer 501. */","atom":"a1445","author":"speed","version":150},{"n":525,"text":"\tprivate readonly read: ((from: number, limit: number) => Entry[]) | undefined;","atom":"a1445","author":"speed","version":150},{"n":526,"text":"\tprivate readonly store: SqliteLog | undefined;","atom":"a1445","author":"speed","version":150},{"n":527,"text":"","atom":"a1445","author":"speed","version":150},{"n":528,"text":"\tconstructor(project: Project, read?: (from: number, limit: number) => Entry[], store?: SqliteLog) {","atom":"a1445","author":"speed","version":150},{"n":529,"text":"\t\tthis.project = project;","atom":"a1445","author":"speed","version":150},{"n":530,"text":"\t\tthis.read = read;","atom":"a1445","author":"speed","version":150},{"n":531,"text":"\t\tthis.store = store;","atom":"a1445","author":"speed","version":150},{"n":532,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":533,"text":"","atom":"a1445","author":"speed","version":150},{"n":534,"text":"\t/** The project's events from log position `from` (#41): reading consumes nothing. */","atom":"a1445","author":"speed","version":150},{"n":535,"text":"\tfeed(from: number, limit = 500) {","atom":"a1445","author":"speed","version":150},{"n":536,"text":"\t\tif (!this.read) throw Object.assign(new Error(\"the feed needs the log\"), { code: \"not-implemented\" });","atom":"a1445","author":"speed","version":150},{"n":537,"text":"\t\tconst end = this.project.logLength;","atom":"a1445","author":"speed","version":150},{"n":538,"text":"\t\tconst start = Math.max(0, Math.min(from, end));","atom":"a1445","author":"speed","version":150},{"n":539,"text":"\t\t// Discard each canonical payload after extracting its event. A feed page must","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":540,"text":"\t\t// not retain every historical file payload in the requested range.","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":541,"text":"\t\tconst events = [];","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":542,"text":"\t\tlet next = start;","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":543,"text":"\t\twhile (next < end && next - start < limit) {","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":544,"text":"\t\t\tconst entries = this.read(next, 1);","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":545,"text":"\t\t\tif (entries.length === 0) break;","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":546,"text":"\t\t\tevents.push(...feedEvents(entries, next));","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":547,"text":"\t\t\tnext += entries.length;","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":548,"text":"\t\t}","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":549,"text":"\t\t// A drop event names the files it took out (#41), so a timeline needs no read per drop.","atom":"a1445","author":"speed","version":150},{"n":550,"text":"\t\tconst enriched = events.map((e) => {","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":551,"text":"\t\t\tif (e.type !== \"drop\" || e.version === undefined) return e;","atom":"a1445","author":"speed","version":150},{"n":552,"text":"\t\t\tconst v = this.project.log({ limit: 1, before: e.version + 1 }).versions[0];","atom":"a1445","author":"speed","version":150},{"n":553,"text":"\t\t\treturn v && v.version === e.version ? { ...e, dropped: v.files } : e;","atom":"a1445","author":"speed","version":150},{"n":554,"text":"\t\t});","atom":"a1445","author":"speed","version":150},{"n":555,"text":"\t\treturn { next, end, events: enriched };","atom":"a1594","author":"codex-capacity-chair","version":158},{"n":556,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":557,"text":"","atom":"a1445","author":"speed","version":150},{"n":558,"text":"\t/** The log position for a time (ms since 1970) or a version of shared (#41). */","atom":"a1445","author":"speed","version":150},{"n":559,"text":"\tposition(q: { time?: number; version?: number }) {","atom":"a1445","author":"speed","version":150},{"n":560,"text":"\t\treturn this.project.position(q);","atom":"a1445","author":"speed","version":150},{"n":561,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":562,"text":"\t/** Whether the Worker runs the queue's check; until it does, \"queue\": true does nothing. */","atom":"a1445","author":"speed","version":150},{"n":563,"text":"\tsetCheckerReady(ready: boolean): void {","atom":"a1445","author":"speed","version":150},{"n":564,"text":"\t\tthis.project.checkerReady = ready;","atom":"a1445","author":"speed","version":150},{"n":565,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":566,"text":"\t/** An agent withdraws what it has queued (#39). */","atom":"a1445","author":"speed","version":150},{"n":567,"text":"\tunqueue(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":568,"text":"\t\treturn this.project.unqueue(agent, Date.now());","atom":"a1445","author":"speed","version":150},{"n":569,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":570,"text":"\t/** The log length now: what a long-poll waits to see grow. */","atom":"a1445","author":"speed","version":150},{"n":571,"text":"\tlogLength() {","atom":"a1445","author":"speed","version":150},{"n":572,"text":"\t\treturn this.project.logLength;","atom":"a1445","author":"speed","version":150},{"n":573,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":574,"text":"\t/** An agent's draft diff for a reader: never creates the agent (#41). */","atom":"a1445","author":"speed","version":150},{"n":575,"text":"\tdiffOf(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":576,"text":"\t\treturn this.project.diffOf(agent);","atom":"a1445","author":"speed","version":150},{"n":577,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":578,"text":"\t/** Every agent with unpublished changes: its files and how many changes (#41). */","atom":"a1445","author":"speed","version":150},{"n":579,"text":"\tchange(id: number) {","atom":"a1445","author":"speed","version":150},{"n":580,"text":"\t\treturn this.project.change(id);","atom":"a1445","author":"speed","version":150},{"n":581,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":582,"text":"","atom":"a1445","author":"speed","version":150},{"n":583,"text":"\tchanges(since: number, limit: number, before?: number, issue?: number) {","atom":"a1445","author":"speed","version":150},{"n":584,"text":"\t\treturn this.project.changes(since, limit, before, issue);","atom":"a1445","author":"speed","version":150},{"n":585,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":586,"text":"","atom":"a1445","author":"speed","version":150},{"n":587,"text":"\tmove(agent: string, from: string, to: string) {","atom":"a1445","author":"speed","version":150},{"n":588,"text":"\t\treturn this.project.move(agent, from, to, Date.now());","atom":"a1445","author":"speed","version":150},{"n":589,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":590,"text":"","atom":"a1445","author":"speed","version":150},{"n":591,"text":"\tnote(agent: string, body: Record<string, unknown>) {","atom":"a1445","author":"speed","version":150},{"n":592,"text":"\t\treturn this.project.note(agent, body, Date.now());","atom":"a1445","author":"speed","version":150},{"n":593,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":594,"text":"","atom":"a1445","author":"speed","version":150},{"n":595,"text":"\tnotePerson(person: { id: string; name: string }, body: Record<string, unknown>) {","atom":"a1445","author":"speed","version":150},{"n":596,"text":"\t\treturn this.project.notePerson(person, body, Date.now());","atom":"a1445","author":"speed","version":150},{"n":597,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":598,"text":"","atom":"a1445","author":"speed","version":150},{"n":599,"text":"\tcloseNotePerson(person: { id: string; name: string }, id: number, how: unknown) {","atom":"a1445","author":"speed","version":150},{"n":600,"text":"\t\treturn this.project.closeNotePerson(person, id, how, Date.now());","atom":"a1445","author":"speed","version":150},{"n":601,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":602,"text":"","atom":"a1445","author":"speed","version":150},{"n":603,"text":"\tcloseNote(agent: string, id: number, how: unknown) {","atom":"a1445","author":"speed","version":150},{"n":604,"text":"\t\treturn this.project.closeNote(agent, id, how, Date.now());","atom":"a1445","author":"speed","version":150},{"n":605,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":606,"text":"","atom":"a1445","author":"speed","version":150},{"n":607,"text":"\tnotes(options: { file?: string; change?: number; open?: boolean }) {","atom":"a1445","author":"speed","version":150},{"n":608,"text":"\t\treturn this.project.notes(options);","atom":"a1445","author":"speed","version":150},{"n":609,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":610,"text":"","atom":"a1445","author":"speed","version":150},{"n":611,"text":"\tribbon() {","atom":"a1445","author":"speed","version":150},{"n":612,"text":"\t\treturn this.project.ribbon();","atom":"a1445","author":"speed","version":150},{"n":613,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":614,"text":"","atom":"a1445","author":"speed","version":150},{"n":615,"text":"\tdrafts() {","atom":"a1445","author":"speed","version":150},{"n":616,"text":"\t\tconst s = this.project.status();","atom":"a1445","author":"speed","version":150},{"n":617,"text":"\t\treturn {","atom":"a1445","author":"speed","version":150},{"n":618,"text":"\t\t\tversion: s.version,","atom":"a1445","author":"speed","version":150},{"n":619,"text":"\t\t\tdrafts: s.agents","atom":"a1445","author":"speed","version":150},{"n":620,"text":"\t\t\t\t.filter((a) => a.draftChanges > 0)","atom":"a1445","author":"speed","version":150},{"n":621,"text":"\t\t\t\t.map((a) => ({ agent: a.agent, draft: a.draft, base: a.base, draftChanges: a.draftChanges, files: a.files })),","atom":"a1445","author":"speed","version":150},{"n":622,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":623,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":624,"text":"\t/** The last copy replay loaded: scrubbing forward from it applies only the entries after it. */","atom":"a1445","author":"speed","version":150},{"n":625,"text":"\tprivate replica: Project | undefined;","atom":"a1445","author":"speed","version":150},{"n":626,"text":"","atom":"a1445","author":"speed","version":150},{"n":627,"text":"\t/** The project as it stood with the first `at` log entries (#41, replay). */","atom":"a1445","author":"speed","version":150},{"n":628,"text":"\tprivate at(at: number): Project {","atom":"a1445","author":"speed","version":150},{"n":629,"text":"\t\tif (!this.read) throw Object.assign(new Error(\"replay needs the log\"), { code: \"not-implemented\" });","atom":"a1445","author":"speed","version":150},{"n":630,"text":"\t\tconst n = Math.max(0, Math.min(at, this.project.logLength));","atom":"a1445","author":"speed","version":150},{"n":631,"text":"\t\tconst r = this.replica;","atom":"a1445","author":"speed","version":150},{"n":632,"text":"\t\tif (r && r.logLength === n) return r;","atom":"a1445","author":"speed","version":150},{"n":633,"text":"\t\tif (r && r.logLength < n) {","atom":"a1445","author":"speed","version":150},{"n":634,"text":"\t\t\tr.catchUp(this.read(r.logLength, n - r.logLength));","atom":"a1445","author":"speed","version":150},{"n":635,"text":"\t\t\treturn r;","atom":"a1445","author":"speed","version":150},{"n":636,"text":"\t\t}","atom":"a1445","author":"speed","version":150},{"n":637,"text":"\t\tthis.replica = Project.load(this.read(0, n), new MemoryStore());","atom":"a1445","author":"speed","version":150},{"n":638,"text":"\t\treturn this.replica;","atom":"a1445","author":"speed","version":150},{"n":639,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":640,"text":"\tstatusAt(at: number) {","atom":"a1445","author":"speed","version":150},{"n":641,"text":"\t\tconst p = this.at(at);","atom":"a1445","author":"speed","version":150},{"n":642,"text":"\t\tconst answer = {","atom":"a1445","author":"speed","version":150},{"n":643,"text":"\t\t\tat: Math.min(at, this.project.logLength),","atom":"a1445","author":"speed","version":150},{"n":644,"text":"\t\t\t...(p.initialized ? p.status() : { version: -1, agents: [] }),","atom":"a1445","author":"speed","version":150},{"n":645,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":646,"text":"\t\tthis.release();","atom":"a1445","author":"speed","version":150},{"n":647,"text":"\t\treturn answer;","atom":"a1445","author":"speed","version":150},{"n":648,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":649,"text":"\twhereAt(at: number) {","atom":"a1445","author":"speed","version":150},{"n":650,"text":"\t\tconst p = this.at(at);","atom":"a1445","author":"speed","version":150},{"n":651,"text":"\t\tconst answer = {","atom":"a1445","author":"speed","version":150},{"n":652,"text":"\t\t\tat: Math.min(at, this.project.logLength),","atom":"a1445","author":"speed","version":150},{"n":653,"text":"\t\t\t...(p.initialized ? where(p) : { version: -1, files: {} }),","atom":"a1445","author":"speed","version":150},{"n":654,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":655,"text":"\t\tthis.release();","atom":"a1445","author":"speed","version":150},{"n":656,"text":"\t\treturn answer;","atom":"a1445","author":"speed","version":150},{"n":657,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":658,"text":"","atom":"a1445","author":"speed","version":150},{"n":659,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":660,"text":"\t * Drop the replay copy after each read (#46): a second copy of a large","atom":"a1445","author":"speed","version":150},{"n":661,"text":"\t * project's history doubles its memory, past a Durable Object's 128 MB.","atom":"a1445","author":"speed","version":150},{"n":662,"text":"\t * Each scrub replays from the start instead (about 0.2 s on game).","atom":"a1445","author":"speed","version":150},{"n":663,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":664,"text":"\tprivate release(): void {","atom":"a1445","author":"speed","version":150},{"n":665,"text":"\t\tthis.replica = undefined;","atom":"a1445","author":"speed","version":150},{"n":666,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":667,"text":"","atom":"a1445","author":"speed","version":150},{"n":668,"text":"\t/** hasBlob says whether the project holds a blob's bytes (#27); without it, every blob is refused. */","atom":"a1445","author":"speed","version":150},{"n":669,"text":"\t/** whole stores and reads files kept whole (#46); without it every text file is tracked by line. */","atom":"a1445","author":"speed","version":150},{"n":670,"text":"\tstatic open(","atom":"a1445","author":"speed","version":150},{"n":671,"text":"\t\tstorage: SqliteStorage,","atom":"a1445","author":"speed","version":150},{"n":672,"text":"\t\thasBlob?: (sha256: string) => boolean,","atom":"a1445","author":"speed","version":150},{"n":673,"text":"\t\twhole?: { keep(text: string): string; read(sha: string): string | null },","atom":"a1445","author":"speed","version":150},{"n":674,"text":"\t): EngineProject {","atom":"a1445","author":"speed","version":150},{"n":675,"text":"\t\tconst log = new SqliteLog(storage);","atom":"a1445","author":"speed","version":150},{"n":676,"text":"\t\treturn new EngineProject(","atom":"a1445","author":"speed","version":150},{"n":677,"text":"\t\t\tProject.load(log.entries(), log, {","atom":"a1445","author":"speed","version":150},{"n":678,"text":"\t\t\t\t...(hasBlob ? { hasBlob } : {}),","atom":"a1445","author":"speed","version":150},{"n":679,"text":"\t\t\t\t...(whole ? { whole } : {}),","atom":"a1445","author":"speed","version":150},{"n":680,"text":"\t\t\t\tnow: () => Date.now(),","atom":"a1445","author":"speed","version":150},{"n":681,"text":"\t\t\t\tshapes: log.shapes(),","atom":"a1445","author":"speed","version":150},{"n":682,"text":"\t\t\t\tentryAt: (at) => log.since(at, 1)[0]!,","atom":"a1445","author":"speed","version":150},{"n":683,"text":"\t\t\t}),","atom":"a1445","author":"speed","version":150},{"n":684,"text":"\t\t\t(from, limit) => log.since(from, limit),","atom":"a1445","author":"speed","version":150},{"n":685,"text":"\t\t\tlog,","atom":"a1445","author":"speed","version":150},{"n":686,"text":"\t\t);","atom":"a1445","author":"speed","version":150},{"n":687,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":688,"text":"","atom":"a1445","author":"speed","version":150},{"n":689,"text":"\texists() {","atom":"a1445","author":"speed","version":150},{"n":690,"text":"\t\treturn this.project.initialized;","atom":"a1445","author":"speed","version":150},{"n":691,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":692,"text":"\t/** Committed log epoch for host-side cache invalidation; it does not dispatch work. */","atom":"a1445","author":"speed","version":150},{"n":693,"text":"\tcommittedGeneration(): number {","atom":"a1445","author":"speed","version":150},{"n":694,"text":"\t\treturn this.store?.generation() ?? 0;","atom":"a1445","author":"speed","version":150},{"n":695,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":696,"text":"\tinit(","atom":"a1445","author":"speed","version":150},{"n":697,"text":"\t\tfiles: Record<string, string>,","atom":"a1445","author":"speed","version":150},{"n":698,"text":"\t\tmodes?: Record<string, { exec?: boolean; link?: string | null }>,","atom":"a1445","author":"speed","version":150},{"n":699,"text":"\t\tblobs?: Record<string, string>,","atom":"a1445","author":"speed","version":150},{"n":700,"text":"\t) {","atom":"a1445","author":"speed","version":150},{"n":701,"text":"\t\treturn this.project.init(files, Date.now(), modes ?? {}, blobs ?? {});","atom":"a1445","author":"speed","version":150},{"n":702,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":703,"text":"\tedit(agent: string, body: EditBody) {","atom":"a1445","author":"speed","version":150},{"n":704,"text":"\t\treturn this.project.edit(agent, body as Parameters<Project[\"edit\"]>[1], Date.now());","atom":"a1445","author":"speed","version":150},{"n":705,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":706,"text":"\trecord(","atom":"a1445","author":"speed","version":150},{"n":707,"text":"\t\tagent: string,","atom":"a1445","author":"speed","version":150},{"n":708,"text":"\t\tfiles: Record<string, string | null>,","atom":"a1445","author":"speed","version":150},{"n":709,"text":"\t\tmodes?: Record<string, { exec?: boolean; link?: string | null }>,","atom":"a1445","author":"speed","version":150},{"n":710,"text":"\t\tblobs?: Record<string, string>,","atom":"a1445","author":"speed","version":150},{"n":711,"text":"\t\tmeta?: { session?: string; subagent?: string; client?: string },","atom":"a1445","author":"speed","version":150},{"n":712,"text":"\t) {","atom":"a1445","author":"speed","version":150},{"n":713,"text":"\t\treturn this.project.record(agent, files, Date.now(), modes ?? {}, blobs ?? {}, meta ?? {});","atom":"a1445","author":"speed","version":150},{"n":714,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":715,"text":"\tpublish(agent: string, message: string, asIs?: boolean) {","atom":"a1445","author":"speed","version":150},{"n":716,"text":"\t\treturn this.project.publish(agent, message, Date.now(), { asIs: asIs === true });","atom":"a1445","author":"speed","version":150},{"n":717,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":718,"text":"\tsync(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":719,"text":"\t\treturn this.project.sync(agent);","atom":"a1445","author":"speed","version":150},{"n":720,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":721,"text":"\tstatus() {","atom":"a1445","author":"speed","version":150},{"n":722,"text":"\t\treturn this.project.status();","atom":"a1445","author":"speed","version":150},{"n":723,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":724,"text":"\tswitchTo(agent: string, name: string | null, carry = false) {","atom":"a1445","author":"speed","version":150},{"n":725,"text":"\t\treturn this.project.switchTo(agent, name, Date.now(), { carry });","atom":"a1445","author":"speed","version":150},{"n":726,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":727,"text":"\tland(agent: string, message: string) {","atom":"a1445","author":"speed","version":150},{"n":728,"text":"\t\treturn this.project.land(agent, message, Date.now());","atom":"a1445","author":"speed","version":150},{"n":729,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":730,"text":"\tingest(input: Parameters<Project[\"ingest\"]>[0], time: number) {","atom":"a1445","author":"speed","version":150},{"n":731,"text":"\t\treturn this.project.ingest(input, time);","atom":"a1445","author":"speed","version":150},{"n":732,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":733,"text":"\tsyncDraft(agent: string) {","atom":"a1445","author":"speed","version":150},{"n":734,"text":"\t\treturn this.project.syncDraft(agent, Date.now());","atom":"a1445","author":"speed","version":150},{"n":735,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":736,"text":"\tfilesAt(version: number) {","atom":"a1445","author":"speed","version":150},{"n":737,"text":"\t\treturn this.project.viewAt(version).files();","atom":"a1445","author":"speed","version":150},{"n":738,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":739,"text":"\tblobsAt(version: number) {","atom":"a1445","author":"speed","version":150},{"n":740,"text":"\t\treturn this.project.viewAt(version).blobs();","atom":"a1445","author":"speed","version":150},{"n":741,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":742,"text":"\t/**","atom":"a1445","author":"speed","version":150},{"n":743,"text":"\t * Shared's newest version. Its files and modes are laid out on first read: every call reads shared().version","atom":"a1445","author":"speed","version":150},{"n":744,"text":"\t * before and after its op, and laying out the files reads each file's text from the log, about 0.5 s on abso","atom":"a1445","author":"speed","version":150},{"n":745,"text":"\t * (abso 299).","atom":"a1445","author":"speed","version":150},{"n":746,"text":"\t */","atom":"a1445","author":"speed","version":150},{"n":747,"text":"\tshared() {","atom":"a1445","author":"speed","version":150},{"n":748,"text":"\t\tconst version = this.project.version;","atom":"a1445","author":"speed","version":150},{"n":749,"text":"\t\tconst by = version > 0 ? this.project.published(version) : undefined;","atom":"a1445","author":"speed","version":150},{"n":750,"text":"\t\tconst blobs = this.project.blobs();","atom":"a1445","author":"speed","version":150},{"n":751,"text":"\t\tconst project = this.project;","atom":"a1445","author":"speed","version":150},{"n":752,"text":"\t\tlet files: Record<string, string> | undefined;","atom":"a1445","author":"speed","version":150},{"n":753,"text":"\t\tlet modes: ReturnType<Project[\"modes\"]> | undefined;","atom":"a1445","author":"speed","version":150},{"n":754,"text":"\t\treturn {","atom":"a1445","author":"speed","version":150},{"n":755,"text":"\t\t\tversion,","atom":"a1445","author":"speed","version":150},{"n":756,"text":"\t\t\tget files() {","atom":"a1445","author":"speed","version":150},{"n":757,"text":"\t\t\t\tfiles ??= project.files();","atom":"a1445","author":"speed","version":150},{"n":758,"text":"\t\t\t\treturn files;","atom":"a1445","author":"speed","version":150},{"n":759,"text":"\t\t\t},","atom":"a1445","author":"speed","version":150},{"n":760,"text":"\t\t\tget modes() {","atom":"a1445","author":"speed","version":150},{"n":761,"text":"\t\t\t\tmodes ??= project.modes();","atom":"a1445","author":"speed","version":150},{"n":762,"text":"\t\t\t\treturn modes;","atom":"a1445","author":"speed","version":150},{"n":763,"text":"\t\t\t},","atom":"a1445","author":"speed","version":150},{"n":764,"text":"\t\t\t...(Object.keys(blobs).length > 0 ? { blobs } : {}),","atom":"a1445","author":"speed","version":150},{"n":765,"text":"\t\t\t...(by ? { last: { agent: by.agent, message: by.message } } : {}),","atom":"a1445","author":"speed","version":150},{"n":766,"text":"\t\t};","atom":"a1445","author":"speed","version":150},{"n":767,"text":"\t}","atom":"a1445","author":"speed","version":150},{"n":768,"text":"}","atom":"a1445","author":"speed","version":150}],"atoms":[{"atom":"a1445","author":"speed","message":"","time":1791906648241,"timeIso":"2026-10-13T15:50:48.241Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}},{"atom":"a1446","author":"speed","message":"","time":1791906648556,"timeIso":"2026-10-13T15:50:48.556Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}},{"atom":"a1483","author":"speed","message":"","time":1791907425388,"timeIso":"2026-10-13T16:03:45.388Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}},{"atom":"a1582","author":"codex-capacity-chair","message":"","time":1791914678514,"timeIso":"2026-10-13T18:04:38.514Z","publish":{"draft":null,"version":157,"agent":"codex-capacity-chair","message":"Share the SQLite writer and projection host with the open server","time":1791915928641,"timeIso":"2026-10-13T18:25:28.641Z"}},{"atom":"a1589","author":"codex-capacity-chair","message":"","time":1791915569981,"timeIso":"2026-10-13T18:19:29.981Z","publish":{"draft":null,"version":157,"agent":"codex-capacity-chair","message":"Share the SQLite writer and projection host with the open server","time":1791915928641,"timeIso":"2026-10-13T18:25:28.641Z"}},{"atom":"a1594","author":"codex-capacity-chair","message":"","time":1791916379418,"timeIso":"2026-10-13T18:32:59.418Z","publish":{"draft":null,"version":158,"agent":"codex-capacity-chair","message":"Integrate opt-in disk-first project runtime with cold-object transactions","time":1791917879117,"timeIso":"2026-10-13T18:57:59.117Z"}}]}