@monoes/monograph 1.5.2 → 1.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoes/monograph",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "type": "module",
5
5
  "description": "Native TypeScript code intelligence engine for monomind",
6
6
  "main": "dist/src/index.js",
@@ -132,6 +132,17 @@ async function buildAsyncLocked(
132
132
 
133
133
  const db = openDb(dbPath);
134
134
 
135
+ // The whole build is one SQL transaction: a phase throwing (e.g. issue
136
+ // #40's FK violation) used to leave whatever earlier phases had already
137
+ // autocommitted sitting in the DB, silently corrupting the index into a
138
+ // stale partial state that a later build wouldn't repair (cache hits skip
139
+ // re-scanning the files that would restore the missing rows). BEGIN/COMMIT/
140
+ // ROLLBACK are issued directly via db.exec() rather than better-sqlite3's
141
+ // `.transaction()` helper, which requires a synchronous callback — the
142
+ // phases below are async. This is still safe: every phase writes through
143
+ // this same single connection, so SQLite serializes them regardless of how
144
+ // the JS event loop interleaves the awaits between phases.
145
+ db.exec('BEGIN');
135
146
  try {
136
147
  const graph = new Graph({ multi: true, type: 'directed' });
137
148
  const ctx: PipelineContext = {
@@ -229,6 +240,13 @@ async function buildAsyncLocked(
229
240
  }
230
241
  }
231
242
  db.prepare("INSERT OR REPLACE INTO index_meta VALUES ('indexed_at', ?)").run(new Date().toISOString());
243
+ db.exec('COMMIT');
244
+ } catch (err) {
245
+ // Best-effort: if the connection is already broken (e.g. the failure was
246
+ // itself a corrupt-database error), rolling back can throw too — the
247
+ // original error is what matters and must not be masked by this one.
248
+ try { db.exec('ROLLBACK'); } catch { /* ignore */ }
249
+ throw err;
232
250
  } finally {
233
251
  closeDb(db);
234
252
  }