@colbymchenry/codegraph-win32-arm64 1.3.0 → 1.4.0
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/lib/dist/db/index.d.ts +64 -5
- package/lib/dist/db/index.d.ts.map +1 -1
- package/lib/dist/db/index.js +170 -12
- package/lib/dist/db/index.js.map +1 -1
- package/lib/dist/db/queries.d.ts +25 -1
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +39 -0
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/wal-valve.d.ts +106 -0
- package/lib/dist/db/wal-valve.d.ts.map +1 -0
- package/lib/dist/db/wal-valve.js +208 -0
- package/lib/dist/db/wal-valve.js.map +1 -0
- package/lib/dist/extraction/grammars.d.ts +16 -1
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +85 -43
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +1 -1
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +113 -37
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/parse-pool.d.ts +27 -1
- package/lib/dist/extraction/parse-pool.d.ts.map +1 -1
- package/lib/dist/extraction/parse-pool.js +75 -7
- package/lib/dist/extraction/parse-pool.js.map +1 -1
- package/lib/dist/extraction/parse-worker.js +9 -2
- package/lib/dist/extraction/parse-worker.js.map +1 -1
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +70 -4
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +23 -1
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +8 -0
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/query-pool.d.ts +14 -0
- package/lib/dist/mcp/query-pool.d.ts.map +1 -1
- package/lib/dist/mcp/query-pool.js +18 -0
- package/lib/dist/mcp/query-pool.js.map +1 -1
- package/lib/dist/mcp/session.d.ts.map +1 -1
- package/lib/dist/mcp/session.js +6 -0
- package/lib/dist/mcp/session.js.map +1 -1
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +14 -9
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/mcp/transport.d.ts.map +1 -1
- package/lib/dist/mcp/transport.js +18 -0
- package/lib/dist/mcp/transport.js.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts +2 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/c-fnptr-synthesizer.js +170 -146
- package/lib/dist/resolution/c-fnptr-synthesizer.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +381 -101
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/goframe-synthesizer.d.ts +2 -1
- package/lib/dist/resolution/goframe-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/goframe-synthesizer.js +8 -3
- package/lib/dist/resolution/goframe-synthesizer.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +10 -0
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +55 -15
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/types.d.ts +9 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
package/lib/dist/db/index.d.ts
CHANGED
|
@@ -68,13 +68,51 @@ export declare class DatabaseConnection {
|
|
|
68
68
|
* Get database file size in bytes
|
|
69
69
|
*/
|
|
70
70
|
getSize(): number;
|
|
71
|
+
/**
|
|
72
|
+
* Size of the `-wal` sidecar file in bytes. 0 when it doesn't exist (non-WAL
|
|
73
|
+
* journal mode, in-memory DB, or no write since the last checkpoint+reset).
|
|
74
|
+
*/
|
|
75
|
+
getWalSizeBytes(): number;
|
|
76
|
+
/** Current `wal_autocheckpoint` interval in pages (0 = disabled). */
|
|
77
|
+
getWalAutocheckpoint(): number;
|
|
78
|
+
/**
|
|
79
|
+
* Set the connection's `wal_autocheckpoint` interval (pages; 0 disables).
|
|
80
|
+
* Bulk indexing defers checkpoints entirely (#1231): the default 1000-page
|
|
81
|
+
* auto-checkpoint re-writes hot B-tree/FTS pages into the main DB file over
|
|
82
|
+
* and over — measured at ~95% of ALL disk I/O during a bulk index, and the
|
|
83
|
+
* difference between 45s and 19+ minutes on HDD-class storage. During
|
|
84
|
+
* deferral a {@link WalCheckpointValve} bounds WAL growth off-thread.
|
|
85
|
+
*/
|
|
86
|
+
setWalAutocheckpoint(pages: number): void;
|
|
87
|
+
/**
|
|
88
|
+
* `PRAGMA wal_checkpoint(PASSIVE)` on a worker thread with its own
|
|
89
|
+
* connection. PASSIVE never blocks the writer, and running it off-thread
|
|
90
|
+
* means the main thread — and the #850 watchdog heartbeat — keep turning
|
|
91
|
+
* even when the backfill is minutes of I/O on slow storage (a synchronous
|
|
92
|
+
* checkpoint that exceeds the watchdog's 60s window gets a healthy index
|
|
93
|
+
* SIGKILLed — observed in the #1231 repro).
|
|
94
|
+
*
|
|
95
|
+
* Returns SQLite's checkpoint result row — `log === checkpointed` with
|
|
96
|
+
* `busy === 0` means the ENTIRE WAL was backfilled, so the writer's next
|
|
97
|
+
* commit restarts the WAL from the top and the file stops growing. The
|
|
98
|
+
* WAL valve needs that signal because a WAL file's SIZE never shrinks:
|
|
99
|
+
* after the first wrap, raw file size says nothing about the un-backfilled
|
|
100
|
+
* backlog. Best-effort: returns null on any failure (including worker
|
|
101
|
+
* threads being unavailable — a potentially minutes-long checkpoint must
|
|
102
|
+
* never run inline on the main thread).
|
|
103
|
+
*/
|
|
104
|
+
checkpointWalPassive(): Promise<{
|
|
105
|
+
busy: number;
|
|
106
|
+
log: number;
|
|
107
|
+
checkpointed: number;
|
|
108
|
+
} | null>;
|
|
71
109
|
/**
|
|
72
110
|
* Optimize database (vacuum and analyze)
|
|
73
111
|
*/
|
|
74
112
|
optimize(): void;
|
|
75
113
|
/**
|
|
76
|
-
* Lightweight
|
|
77
|
-
*
|
|
114
|
+
* Lightweight maintenance to run after bulk writes (indexAll, sync).
|
|
115
|
+
* Two operations:
|
|
78
116
|
*
|
|
79
117
|
* - `PRAGMA optimize` — incremental ANALYZE; SQLite only re-analyzes
|
|
80
118
|
* tables whose row counts changed materially since the last
|
|
@@ -86,10 +124,31 @@ export declare class DatabaseConnection {
|
|
|
86
124
|
* unboundedly between automatic checkpoints (auto-fires at 1000
|
|
87
125
|
* pages by default; large indexAll runs blow past that).
|
|
88
126
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
127
|
+
* Runs on a WORKER THREAD with its own connection: on a multi-GB index
|
|
128
|
+
* these pragmas are minutes of synchronous IO (a 95k-file kernel index
|
|
129
|
+
* left a 593MB WAL whose checkpoint alone blew the #850 watchdog's 60s
|
|
130
|
+
* window and got a COMPLETED index SIGKILLed at the finish line). WAL
|
|
131
|
+
* checkpointing from a second connection is standard SQLite; `PRAGMA
|
|
132
|
+
* optimize` persists its statistics in sqlite_stat tables, so the main
|
|
133
|
+
* connection benefits the same. The main thread just awaits a message,
|
|
134
|
+
* so the event loop — and the watchdog heartbeat — keep turning.
|
|
135
|
+
*
|
|
136
|
+
* Everything is silently swallowed on failure — best-effort
|
|
137
|
+
* optimization, never load-bearing for correctness. If worker threads
|
|
138
|
+
* are unavailable, falls back to a bounded in-line `PRAGMA optimize`
|
|
139
|
+
* and SKIPS the checkpoint (the final close() checkpoints after the
|
|
140
|
+
* CLI has already disarmed its watchdog).
|
|
141
|
+
*/
|
|
142
|
+
runMaintenance(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Run pragmas on a worker thread against its own connection to this DB
|
|
145
|
+
* (shared machinery for {@link runMaintenance} and
|
|
146
|
+
* {@link checkpointWalPassive}). Each pragma is individually best-effort;
|
|
147
|
+
* the whole call is best-effort. `inlineFallback` (if any) runs on THIS
|
|
148
|
+
* connection only when worker threads are unavailable — keep it to pragmas
|
|
149
|
+
* that are safe to run synchronously on the main thread.
|
|
91
150
|
*/
|
|
92
|
-
|
|
151
|
+
private runPragmasOffThread;
|
|
93
152
|
/**
|
|
94
153
|
* Close the database connection
|
|
95
154
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAE,aAAa,EAAkB,MAAM,kBAAkB,CAAC;AAGjF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AA0BjE;;GAEG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAgB;IAC/B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW,CAAgB;IAEnC,OAAO;IAOP;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB;IA4BrD;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB;IAoB/C;;OAEG;IACH,KAAK,IAAI,cAAc;IAIvB;;;;OAIG;IACH,UAAU,IAAI,aAAa;IAI3B;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;;;;;;;;OASG;IACH,cAAc,IAAI,MAAM;IASxB;;OAEG;IACH,gBAAgB,IAAI,aAAa,GAAG,IAAI;IAcxC;;OAEG;IACH,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAI9B;;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AE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IA2CjG;;OAEG;IACH,QAAQ,IAAI,IAAI;IAKhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAcrC;;;;;;;OAOG;YACW,mBAAmB;IAkCjC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,MAAM,IAAI,OAAO;IAIjB;;;;;;;;;;OAUG;IACH,gBAAgB,IAAI,OAAO;CAK5B;AAmBD;;GAEG;AACH,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAShD;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAWxD"}
|
package/lib/dist/db/index.js
CHANGED
|
@@ -197,6 +197,100 @@ class DatabaseConnection {
|
|
|
197
197
|
const stats = fs.statSync(this.dbPath);
|
|
198
198
|
return stats.size;
|
|
199
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Size of the `-wal` sidecar file in bytes. 0 when it doesn't exist (non-WAL
|
|
202
|
+
* journal mode, in-memory DB, or no write since the last checkpoint+reset).
|
|
203
|
+
*/
|
|
204
|
+
getWalSizeBytes() {
|
|
205
|
+
if (!this.dbPath || this.dbPath === ':memory:')
|
|
206
|
+
return 0;
|
|
207
|
+
try {
|
|
208
|
+
return fs.statSync(`${this.dbPath}-wal`).size;
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
return 0;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/** Current `wal_autocheckpoint` interval in pages (0 = disabled). */
|
|
215
|
+
getWalAutocheckpoint() {
|
|
216
|
+
const v = this.db.pragma('wal_autocheckpoint', { simple: true });
|
|
217
|
+
const n = Number(v);
|
|
218
|
+
return Number.isFinite(n) ? n : 0;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Set the connection's `wal_autocheckpoint` interval (pages; 0 disables).
|
|
222
|
+
* Bulk indexing defers checkpoints entirely (#1231): the default 1000-page
|
|
223
|
+
* auto-checkpoint re-writes hot B-tree/FTS pages into the main DB file over
|
|
224
|
+
* and over — measured at ~95% of ALL disk I/O during a bulk index, and the
|
|
225
|
+
* difference between 45s and 19+ minutes on HDD-class storage. During
|
|
226
|
+
* deferral a {@link WalCheckpointValve} bounds WAL growth off-thread.
|
|
227
|
+
*/
|
|
228
|
+
setWalAutocheckpoint(pages) {
|
|
229
|
+
this.db.pragma(`wal_autocheckpoint = ${Math.max(0, Math.floor(pages))}`);
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* `PRAGMA wal_checkpoint(PASSIVE)` on a worker thread with its own
|
|
233
|
+
* connection. PASSIVE never blocks the writer, and running it off-thread
|
|
234
|
+
* means the main thread — and the #850 watchdog heartbeat — keep turning
|
|
235
|
+
* even when the backfill is minutes of I/O on slow storage (a synchronous
|
|
236
|
+
* checkpoint that exceeds the watchdog's 60s window gets a healthy index
|
|
237
|
+
* SIGKILLed — observed in the #1231 repro).
|
|
238
|
+
*
|
|
239
|
+
* Returns SQLite's checkpoint result row — `log === checkpointed` with
|
|
240
|
+
* `busy === 0` means the ENTIRE WAL was backfilled, so the writer's next
|
|
241
|
+
* commit restarts the WAL from the top and the file stops growing. The
|
|
242
|
+
* WAL valve needs that signal because a WAL file's SIZE never shrinks:
|
|
243
|
+
* after the first wrap, raw file size says nothing about the un-backfilled
|
|
244
|
+
* backlog. Best-effort: returns null on any failure (including worker
|
|
245
|
+
* threads being unavailable — a potentially minutes-long checkpoint must
|
|
246
|
+
* never run inline on the main thread).
|
|
247
|
+
*/
|
|
248
|
+
async checkpointWalPassive() {
|
|
249
|
+
if (!this.dbPath || this.dbPath === ':memory:') {
|
|
250
|
+
try {
|
|
251
|
+
const row = this.db.prepare('PRAGMA wal_checkpoint(PASSIVE)').get();
|
|
252
|
+
return row ? { busy: Number(row.busy), log: Number(row.log), checkpointed: Number(row.checkpointed) } : null;
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
const { Worker } = await Promise.resolve().then(() => __importStar(require('node:worker_threads')));
|
|
260
|
+
const workerSource = `
|
|
261
|
+
const { workerData, parentPort } = require('node:worker_threads');
|
|
262
|
+
let row = null;
|
|
263
|
+
try {
|
|
264
|
+
const { DatabaseSync } = require('node:sqlite');
|
|
265
|
+
const db = new DatabaseSync(workerData.dbPath);
|
|
266
|
+
try { row = db.prepare('PRAGMA wal_checkpoint(PASSIVE)').get(); } catch {}
|
|
267
|
+
try { db.close(); } catch {}
|
|
268
|
+
} catch {}
|
|
269
|
+
parentPort.postMessage({ row });
|
|
270
|
+
`;
|
|
271
|
+
return await new Promise((resolve) => {
|
|
272
|
+
let settled = false;
|
|
273
|
+
const finish = (row) => {
|
|
274
|
+
if (settled)
|
|
275
|
+
return;
|
|
276
|
+
settled = true;
|
|
277
|
+
resolve(row ? { busy: Number(row.busy), log: Number(row.log), checkpointed: Number(row.checkpointed) } : null);
|
|
278
|
+
};
|
|
279
|
+
try {
|
|
280
|
+
const worker = new Worker(workerSource, { eval: true, workerData: { dbPath: this.dbPath } });
|
|
281
|
+
worker.once('message', (m) => { void worker.terminate(); finish(m?.row ?? null); });
|
|
282
|
+
worker.once('error', () => { void worker.terminate(); finish(null); });
|
|
283
|
+
worker.once('exit', () => finish(null));
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
finish(null);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
catch {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
200
294
|
/**
|
|
201
295
|
* Optimize database (vacuum and analyze)
|
|
202
296
|
*/
|
|
@@ -205,8 +299,8 @@ class DatabaseConnection {
|
|
|
205
299
|
this.db.exec('ANALYZE');
|
|
206
300
|
}
|
|
207
301
|
/**
|
|
208
|
-
* Lightweight
|
|
209
|
-
*
|
|
302
|
+
* Lightweight maintenance to run after bulk writes (indexAll, sync).
|
|
303
|
+
* Two operations:
|
|
210
304
|
*
|
|
211
305
|
* - `PRAGMA optimize` — incremental ANALYZE; SQLite only re-analyzes
|
|
212
306
|
* tables whose row counts changed materially since the last
|
|
@@ -218,21 +312,85 @@ class DatabaseConnection {
|
|
|
218
312
|
* unboundedly between automatic checkpoints (auto-fires at 1000
|
|
219
313
|
* pages by default; large indexAll runs blow past that).
|
|
220
314
|
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
315
|
+
* Runs on a WORKER THREAD with its own connection: on a multi-GB index
|
|
316
|
+
* these pragmas are minutes of synchronous IO (a 95k-file kernel index
|
|
317
|
+
* left a 593MB WAL whose checkpoint alone blew the #850 watchdog's 60s
|
|
318
|
+
* window and got a COMPLETED index SIGKILLed at the finish line). WAL
|
|
319
|
+
* checkpointing from a second connection is standard SQLite; `PRAGMA
|
|
320
|
+
* optimize` persists its statistics in sqlite_stat tables, so the main
|
|
321
|
+
* connection benefits the same. The main thread just awaits a message,
|
|
322
|
+
* so the event loop — and the watchdog heartbeat — keep turning.
|
|
323
|
+
*
|
|
324
|
+
* Everything is silently swallowed on failure — best-effort
|
|
325
|
+
* optimization, never load-bearing for correctness. If worker threads
|
|
326
|
+
* are unavailable, falls back to a bounded in-line `PRAGMA optimize`
|
|
327
|
+
* and SKIPS the checkpoint (the final close() checkpoints after the
|
|
328
|
+
* CLI has already disarmed its watchdog).
|
|
223
329
|
*/
|
|
224
|
-
runMaintenance() {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
330
|
+
async runMaintenance() {
|
|
331
|
+
// In-memory / test databases: nothing worth a worker round-trip.
|
|
332
|
+
if (!this.dbPath || this.dbPath === ':memory:') {
|
|
333
|
+
try {
|
|
334
|
+
this.db.exec('PRAGMA optimize');
|
|
335
|
+
}
|
|
336
|
+
catch { /* ignore */ }
|
|
337
|
+
try {
|
|
338
|
+
this.db.exec('PRAGMA wal_checkpoint(PASSIVE)');
|
|
339
|
+
}
|
|
340
|
+
catch { /* ignore */ }
|
|
341
|
+
return;
|
|
230
342
|
}
|
|
343
|
+
await this.runPragmasOffThread(['PRAGMA analysis_limit=1000', 'PRAGMA optimize', 'PRAGMA wal_checkpoint(PASSIVE)'],
|
|
344
|
+
// Worker threads unavailable — bounded in-line fallback, no checkpoint.
|
|
345
|
+
['PRAGMA analysis_limit=1000', 'PRAGMA optimize']);
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Run pragmas on a worker thread against its own connection to this DB
|
|
349
|
+
* (shared machinery for {@link runMaintenance} and
|
|
350
|
+
* {@link checkpointWalPassive}). Each pragma is individually best-effort;
|
|
351
|
+
* the whole call is best-effort. `inlineFallback` (if any) runs on THIS
|
|
352
|
+
* connection only when worker threads are unavailable — keep it to pragmas
|
|
353
|
+
* that are safe to run synchronously on the main thread.
|
|
354
|
+
*/
|
|
355
|
+
async runPragmasOffThread(pragmas, inlineFallback = []) {
|
|
356
|
+
try {
|
|
357
|
+
const { Worker } = await Promise.resolve().then(() => __importStar(require('node:worker_threads')));
|
|
358
|
+
const workerSource = `
|
|
359
|
+
const { workerData, parentPort } = require('node:worker_threads');
|
|
231
360
|
try {
|
|
232
|
-
|
|
361
|
+
const { DatabaseSync } = require('node:sqlite');
|
|
362
|
+
const db = new DatabaseSync(workerData.dbPath);
|
|
363
|
+
for (const p of workerData.pragmas) { try { db.exec(p); } catch {} }
|
|
364
|
+
try { db.close(); } catch {}
|
|
365
|
+
} catch {}
|
|
366
|
+
parentPort.postMessage('done');
|
|
367
|
+
`;
|
|
368
|
+
await new Promise((resolve) => {
|
|
369
|
+
let settled = false;
|
|
370
|
+
const finish = () => {
|
|
371
|
+
if (!settled) {
|
|
372
|
+
settled = true;
|
|
373
|
+
resolve();
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
try {
|
|
377
|
+
const worker = new Worker(workerSource, { eval: true, workerData: { dbPath: this.dbPath, pragmas } });
|
|
378
|
+
worker.once('message', () => { void worker.terminate(); finish(); });
|
|
379
|
+
worker.once('error', () => { void worker.terminate(); finish(); });
|
|
380
|
+
worker.once('exit', finish);
|
|
381
|
+
}
|
|
382
|
+
catch {
|
|
383
|
+
finish();
|
|
384
|
+
}
|
|
385
|
+
});
|
|
233
386
|
}
|
|
234
387
|
catch {
|
|
235
|
-
|
|
388
|
+
for (const p of inlineFallback) {
|
|
389
|
+
try {
|
|
390
|
+
this.db.exec(p);
|
|
391
|
+
}
|
|
392
|
+
catch { /* ignore */ }
|
|
393
|
+
}
|
|
236
394
|
}
|
|
237
395
|
}
|
|
238
396
|
/**
|
package/lib/dist/db/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAobH,0CAEC;AAqBD,kDAWC;AApdD,qDAAiF;AACjF,uCAAyB;AACzB,2CAA6B;AAE7B,6CAAwF;AACxF,4CAA+C;AAI/C;;;;;;;;;;;;;GAaG;AACH,SAAS,mBAAmB,CAAC,EAAkB;IAC7C,EAAE,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC,CAAM,4BAA4B;IACnE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC/B,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAO,6CAA6C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IAAI,EAAE,CAAC,CAAC;QAC9C,CAAC;QAAC,MAAM,CAAC;YACP,wEAAwE;QAC1E,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/lib/dist/db/queries.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Prepared statements for CRUD operations on the knowledge graph.
|
|
5
5
|
*/
|
|
6
6
|
import { SqliteDatabase } from './sqlite-adapter';
|
|
7
|
-
import { Node, Edge, FileRecord, UnresolvedReference, NodeKind, EdgeKind, GraphStats, SearchOptions, SearchResult } from '../types';
|
|
7
|
+
import { Node, Edge, FileRecord, UnresolvedReference, NodeKind, EdgeKind, Language, GraphStats, SearchOptions, SearchResult } from '../types';
|
|
8
8
|
/**
|
|
9
9
|
* Query builder for the knowledge graph database
|
|
10
10
|
*/
|
|
@@ -198,6 +198,23 @@ export declare class QueryBuilder {
|
|
|
198
198
|
* Get all nodes in the database
|
|
199
199
|
*/
|
|
200
200
|
getAllNodes(): Node[];
|
|
201
|
+
/**
|
|
202
|
+
* Stream nodes of one language whose `decorators` JSON array contains
|
|
203
|
+
* `decorator`. The LIKE on the JSON text is a cheap index-free pre-filter
|
|
204
|
+
* (a decorator name can appear as a substring of another), so callers must
|
|
205
|
+
* still exact-check `node.decorators.includes(decorator)`. Exists so the
|
|
206
|
+
* kotlin expect/actual synthesizer never materializes the whole node table
|
|
207
|
+
* the way `getAllNodes().filter(...)` did — that array alone OOM'd Node's
|
|
208
|
+
* default heap on a 2M-node graph (#1212).
|
|
209
|
+
*/
|
|
210
|
+
iterateNodesByLanguageWithDecorator(language: Language, decorator: string): IterableIterator<Node>;
|
|
211
|
+
/**
|
|
212
|
+
* Distinct languages present in the files table. One indexed aggregate —
|
|
213
|
+
* lets the dynamic-edge synthesizers skip passes for languages the project
|
|
214
|
+
* doesn't contain at all (a Kotlin pass has no work on a pure-C repo), so
|
|
215
|
+
* their cost is zero rather than a full-graph scan that finds nothing (#1212).
|
|
216
|
+
*/
|
|
217
|
+
getDistinctFileLanguages(): Set<string>;
|
|
201
218
|
/**
|
|
202
219
|
* Get nodes by exact name match (uses idx_nodes_name index)
|
|
203
220
|
*/
|
|
@@ -395,6 +412,13 @@ export declare class QueryBuilder {
|
|
|
395
412
|
* Get all distinct node names (lightweight — just name strings for pre-filtering)
|
|
396
413
|
*/
|
|
397
414
|
getAllNodeNames(): string[];
|
|
415
|
+
/**
|
|
416
|
+
* Stream the distinct node names one row at a time — the incremental
|
|
417
|
+
* counterpart to {@link getAllNodeNames} for callers that need to yield
|
|
418
|
+
* to the event loop mid-scan (resolver cache warm-up on multi-million-node
|
|
419
|
+
* indexes). Fresh statement per call: the iterator holds an open cursor.
|
|
420
|
+
*/
|
|
421
|
+
iterateNodeNames(): IterableIterator<string>;
|
|
398
422
|
/**
|
|
399
423
|
* Get unresolved references scoped to specific file paths.
|
|
400
424
|
* Uses the idx_unresolved_file_path index for efficient lookup.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/db/queries.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAmB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,mBAAmB,EACnB,QAAQ,EACR,QAAQ,
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/db/queries.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,cAAc,EAAmB,MAAM,kBAAkB,CAAC;AACnE,OAAO,EACL,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,mBAAmB,EACnB,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACb,MAAM,UAAU,CAAC;AA2JlB;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,EAAE,CAAiB;IAM3B,OAAO,CAAC,iBAAiB,CAA0B;IAGnD,OAAO,CAAC,S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AI,UAAU;IAiDtB;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAKvC;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAM7C;;OAEG;IACH,cAAc,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IASxC;;OAEG;IACH,KAAK,IAAI,IAAI;CASd"}
|
package/lib/dist/db/queries.js
CHANGED
|
@@ -708,6 +708,33 @@ class QueryBuilder {
|
|
|
708
708
|
const rows = this.db.prepare('SELECT * FROM nodes').all();
|
|
709
709
|
return rows.map(rowToNode);
|
|
710
710
|
}
|
|
711
|
+
/**
|
|
712
|
+
* Stream nodes of one language whose `decorators` JSON array contains
|
|
713
|
+
* `decorator`. The LIKE on the JSON text is a cheap index-free pre-filter
|
|
714
|
+
* (a decorator name can appear as a substring of another), so callers must
|
|
715
|
+
* still exact-check `node.decorators.includes(decorator)`. Exists so the
|
|
716
|
+
* kotlin expect/actual synthesizer never materializes the whole node table
|
|
717
|
+
* the way `getAllNodes().filter(...)` did — that array alone OOM'd Node's
|
|
718
|
+
* default heap on a 2M-node graph (#1212).
|
|
719
|
+
*/
|
|
720
|
+
*iterateNodesByLanguageWithDecorator(language, decorator) {
|
|
721
|
+
// Fresh statement per call — an iterator holds an open cursor (see
|
|
722
|
+
// iterateNodesByKind).
|
|
723
|
+
const stmt = this.db.prepare("SELECT * FROM nodes WHERE language = ? AND decorators LIKE '%' || ? || '%'");
|
|
724
|
+
for (const row of stmt.iterate(language, `"${decorator}"`)) {
|
|
725
|
+
yield rowToNode(row);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Distinct languages present in the files table. One indexed aggregate —
|
|
730
|
+
* lets the dynamic-edge synthesizers skip passes for languages the project
|
|
731
|
+
* doesn't contain at all (a Kotlin pass has no work on a pure-C repo), so
|
|
732
|
+
* their cost is zero rather than a full-graph scan that finds nothing (#1212).
|
|
733
|
+
*/
|
|
734
|
+
getDistinctFileLanguages() {
|
|
735
|
+
const rows = this.db.prepare('SELECT DISTINCT language FROM files').all();
|
|
736
|
+
return new Set(rows.map((r) => r.language));
|
|
737
|
+
}
|
|
711
738
|
/**
|
|
712
739
|
* Get nodes by exact name match (uses idx_nodes_name index)
|
|
713
740
|
*/
|
|
@@ -1569,6 +1596,18 @@ class QueryBuilder {
|
|
|
1569
1596
|
const rows = this.stmts.getAllNodeNames.all();
|
|
1570
1597
|
return rows.map((r) => r.name);
|
|
1571
1598
|
}
|
|
1599
|
+
/**
|
|
1600
|
+
* Stream the distinct node names one row at a time — the incremental
|
|
1601
|
+
* counterpart to {@link getAllNodeNames} for callers that need to yield
|
|
1602
|
+
* to the event loop mid-scan (resolver cache warm-up on multi-million-node
|
|
1603
|
+
* indexes). Fresh statement per call: the iterator holds an open cursor.
|
|
1604
|
+
*/
|
|
1605
|
+
*iterateNodeNames() {
|
|
1606
|
+
const stmt = this.db.prepare('SELECT DISTINCT name FROM nodes');
|
|
1607
|
+
for (const row of stmt.iterate()) {
|
|
1608
|
+
yield row.name;
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1572
1611
|
/**
|
|
1573
1612
|
* Get unresolved references scoped to specific file paths.
|
|
1574
1613
|
* Uses the idx_unresolved_file_path index for efficient lookup.
|