{"draft":null,"from":148,"to":149,"files":[{"path":"src/engine/graph.ts","added":14,"removed":1,"diff":"--- a/src/engine/graph.ts\n+++ b/src/engine/graph.ts\n@@ -277,6 +277,8 @@\n \t#textCache = new Map<number, readonly string[]>();\n \t#textCached = 0;\n \n+\treadonly #indexAcceptedAtom?: (atom: Atom, files: readonly string[], storage: GraphStateStorage) => void;\n+\n \t/**\n \t * `texts`, when given, says where each atom's lines' text can be read back\n \t * (#46): the graph then keeps no text, only each line's place, and reads an\n@@ -287,8 +289,13 @@\n \t\t\ttexts?: (seq: number) => readonly (readonly string[])[];\n \t\t\tlists?: (seq: number) => AtomLists;\n \t\t\tstorage?: GraphStateStorage;\n+\t\t\t/** Optional derived indexing inside persistent atom acceptance; must be synchronous. */\n+\t\t\tindexAcceptedAtom?: (atom: Atom, files: readonly string[], storage: GraphStateStorage) => void;\n \t\t} = {},\n \t) {\n+\t\tif (options.indexAcceptedAtom && !options.storage)\n+\t\t\tthrow Error(\"accepted atom indexing requires persistent storage\");\n+\t\tthis.#indexAcceptedAtom = options.indexAcceptedAtom;\n \t\tif (options.texts) {\n \t\t\tthis.#texts = options.texts;\n \t\t\tthis.#lineText = undefined;\n@@ -994,7 +1001,13 @@\n \t * The atom is frozen. Adding to the graph does not add it to any set.\n \t */\n \tadd(atom: Atom): void {\n-\t\tif (this.#storage) this.#storage.transaction(() => this.#add(atom));\n+\t\tif (this.#storage)\n+\t\t\tthis.#storage.transaction(() => {\n+\t\t\t\tthis.#add(atom);\n+\t\t\t\tconst result: unknown = this.#indexAcceptedAtom?.(atom, this.filesOf(atom.id), this.#storage!);\n+\t\t\t\tif (result && typeof result === \"object\" && \"then\" in result)\n+\t\t\t\t\tthrow Error(\"accepted atom indexing must be synchronous\");\n+\t\t\t});\n \t\telse this.#add(atom);\n \t}\n "}],"unmatched":[]}