@kkvcrobatz107/codegraph 0.9.6-pkm.3 → 0.9.6-pkm.4
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.
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* SQLite Adapter
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* CodeGraph ships with a bundled Node runtime, so `node:sqlite` (real SQLite,
|
|
9
|
-
* with WAL + FTS5) is always available — there is no native build step and no
|
|
10
|
-
* wasm fallback. When run from source instead, it requires Node >= 22.5.
|
|
4
|
+
* Uses better-sqlite3 (native, always compiled with FTS5, WAL, mmap).
|
|
5
|
+
* better-sqlite3 ships prebuilt binaries for Node 22 Windows x64 — no
|
|
6
|
+
* compile step needed for the supported platform.
|
|
11
7
|
*/
|
|
12
8
|
export interface SqliteStatement {
|
|
13
9
|
run(...params: any[]): {
|
|
@@ -27,18 +23,7 @@ export interface SqliteDatabase {
|
|
|
27
23
|
close(): void;
|
|
28
24
|
readonly open: boolean;
|
|
29
25
|
}
|
|
30
|
-
|
|
31
|
-
* The active SQLite backend. Only one now (`node:sqlite`); kept as a named type
|
|
32
|
-
* so `codegraph status` and the per-instance reporting have a stable shape.
|
|
33
|
-
*/
|
|
34
|
-
export type SqliteBackend = 'node-sqlite';
|
|
35
|
-
/**
|
|
36
|
-
* Create a database connection backed by `node:sqlite`.
|
|
37
|
-
*
|
|
38
|
-
* Returns the active backend alongside the db so each `DatabaseConnection` can
|
|
39
|
-
* report it per-instance — MCP can open multiple project DBs in one process, so
|
|
40
|
-
* a process-global would race.
|
|
41
|
-
*/
|
|
26
|
+
export type SqliteBackend = 'better-sqlite3';
|
|
42
27
|
export declare function createDatabase(dbPath: string): {
|
|
43
28
|
db: SqliteDatabase;
|
|
44
29
|
backend: SqliteBackend;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/db/sqlite-adapter.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/db/sqlite-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,WAAW,eAAe;IAC9B,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC7E,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC;IAC3B,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IACtC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,GAAG,CAAC;IACzD,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC;IACjE,KAAK,IAAI,IAAI,CAAC;IACd,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAE7C,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,aAAa,CAAA;CAAE,CAG7F"}
|
|
@@ -2,113 +2,19 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* SQLite Adapter
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* CodeGraph ships with a bundled Node runtime, so `node:sqlite` (real SQLite,
|
|
10
|
-
* with WAL + FTS5) is always available — there is no native build step and no
|
|
11
|
-
* wasm fallback. When run from source instead, it requires Node >= 22.5.
|
|
5
|
+
* Uses better-sqlite3 (native, always compiled with FTS5, WAL, mmap).
|
|
6
|
+
* better-sqlite3 ships prebuilt binaries for Node 22 Windows x64 — no
|
|
7
|
+
* compile step needed for the supported platform.
|
|
12
8
|
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
13
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
13
|
exports.createDatabase = createDatabase;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* better-sqlite3 interface the rest of the code expects.
|
|
18
|
-
*
|
|
19
|
-
* node:sqlite is real SQLite compiled into Node, so it supports WAL, FTS5,
|
|
20
|
-
* mmap, and `@named` params natively — the only shims needed are the
|
|
21
|
-
* better-sqlite3 conveniences node:sqlite omits: a `.pragma()` helper, a
|
|
22
|
-
* `.transaction()` helper, and `open` (node:sqlite exposes `isOpen`).
|
|
23
|
-
*/
|
|
24
|
-
class NodeSqliteAdapter {
|
|
25
|
-
_db;
|
|
26
|
-
constructor(dbPath) {
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
28
|
-
const { DatabaseSync } = require('node:sqlite');
|
|
29
|
-
this._db = new DatabaseSync(dbPath);
|
|
30
|
-
}
|
|
31
|
-
get open() {
|
|
32
|
-
return this._db.isOpen;
|
|
33
|
-
}
|
|
34
|
-
prepare(sql) {
|
|
35
|
-
// node:sqlite matches better-sqlite3's calling convention (variadic
|
|
36
|
-
// positional args, or a single object for @named params), so params forward
|
|
37
|
-
// through unchanged.
|
|
38
|
-
const stmt = this._db.prepare(sql);
|
|
39
|
-
return {
|
|
40
|
-
run(...params) {
|
|
41
|
-
const r = stmt.run(...params);
|
|
42
|
-
return {
|
|
43
|
-
changes: Number(r?.changes ?? 0),
|
|
44
|
-
lastInsertRowid: r?.lastInsertRowid ?? 0,
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
get(...params) {
|
|
48
|
-
return stmt.get(...params);
|
|
49
|
-
},
|
|
50
|
-
all(...params) {
|
|
51
|
-
return stmt.all(...params);
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
exec(sql) {
|
|
56
|
-
this._db.exec(sql);
|
|
57
|
-
}
|
|
58
|
-
pragma(str, options) {
|
|
59
|
-
const trimmed = str.trim();
|
|
60
|
-
// Write pragma ("key = value"): node:sqlite is real SQLite, so every pragma
|
|
61
|
-
// (WAL, mmap, synchronous, …) applies as-is.
|
|
62
|
-
if (trimmed.includes('=')) {
|
|
63
|
-
this._db.exec(`PRAGMA ${trimmed}`);
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
// Read pragma. Default: the row object (e.g. { journal_mode: 'wal' }).
|
|
67
|
-
// `{ simple: true }` returns just the single column value, like better-sqlite3.
|
|
68
|
-
const row = this._db.prepare(`PRAGMA ${trimmed}`).get();
|
|
69
|
-
if (options?.simple) {
|
|
70
|
-
return row && typeof row === 'object' ? Object.values(row)[0] : row;
|
|
71
|
-
}
|
|
72
|
-
return row;
|
|
73
|
-
}
|
|
74
|
-
transaction(fn) {
|
|
75
|
-
return (...args) => {
|
|
76
|
-
this._db.exec('BEGIN');
|
|
77
|
-
try {
|
|
78
|
-
const result = fn(...args);
|
|
79
|
-
this._db.exec('COMMIT');
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
this._db.exec('ROLLBACK');
|
|
84
|
-
throw error;
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
close() {
|
|
89
|
-
// node:sqlite's DatabaseSync.close() throws if already closed; make it
|
|
90
|
-
// idempotent to match better-sqlite3 (callers may close more than once).
|
|
91
|
-
if (this._db.isOpen)
|
|
92
|
-
this._db.close();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Create a database connection backed by `node:sqlite`.
|
|
97
|
-
*
|
|
98
|
-
* Returns the active backend alongside the db so each `DatabaseConnection` can
|
|
99
|
-
* report it per-instance — MCP can open multiple project DBs in one process, so
|
|
100
|
-
* a process-global would race.
|
|
101
|
-
*/
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
15
|
+
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
102
16
|
function createDatabase(dbPath) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
const msg = error instanceof Error ? error.message : String(error);
|
|
108
|
-
throw new Error('Failed to open SQLite via the built-in node:sqlite module.\n' +
|
|
109
|
-
'CodeGraph requires node:sqlite (Node.js 22.5+). Install the self-contained\n' +
|
|
110
|
-
'CodeGraph release (it bundles a compatible Node), or run on Node 22.5+.\n' +
|
|
111
|
-
`Underlying error: ${msg}`);
|
|
112
|
-
}
|
|
17
|
+
const db = new better_sqlite3_1.default(dbPath);
|
|
18
|
+
return { db: db, backend: 'better-sqlite3' };
|
|
113
19
|
}
|
|
114
20
|
//# sourceMappingURL=sqlite-adapter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sqlite-adapter.js","sourceRoot":"","sources":["../../src/db/sqlite-adapter.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"sqlite-adapter.js","sourceRoot":"","sources":["../../src/db/sqlite-adapter.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAsBH,wCAGC;AAvBD,iEAAiE;AACjE,oEAAsC;AAmBtC,SAAgB,cAAc,CAAC,MAAc;IAC3C,MAAM,EAAE,GAAG,IAAI,wBAAQ,CAAC,MAAM,CAAQ,CAAC;IACvC,OAAO,EAAE,EAAE,EAAE,EAAoB,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;AACjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kkvcrobatz107/codegraph",
|
|
3
|
-
"version": "0.9.6-pkm.
|
|
3
|
+
"version": "0.9.6-pkm.4",
|
|
4
4
|
"description": "AgentPKM fork of @colbymchenry/codegraph — output path patched to knowledge/codegraph/ (upstream: https://github.com/colbymchenry/codegraph, MIT).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|