dbgraph 0.1.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.
Files changed (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +347 -0
  3. package/dist/bin/dbgraph.d.ts +8 -0
  4. package/dist/bin/dbgraph.d.ts.map +1 -0
  5. package/dist/bin/dbgraph.js +382 -0
  6. package/dist/bin/dbgraph.js.map +1 -0
  7. package/dist/config.d.ts +25 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +158 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/context/formatter.d.ts +94 -0
  12. package/dist/context/formatter.d.ts.map +1 -0
  13. package/dist/context/formatter.js +288 -0
  14. package/dist/context/formatter.js.map +1 -0
  15. package/dist/context/index.d.ts +77 -0
  16. package/dist/context/index.d.ts.map +1 -0
  17. package/dist/context/index.js +458 -0
  18. package/dist/context/index.js.map +1 -0
  19. package/dist/db/index.d.ts +26 -0
  20. package/dist/db/index.d.ts.map +1 -0
  21. package/dist/db/index.js +127 -0
  22. package/dist/db/index.js.map +1 -0
  23. package/dist/db/migrations.d.ts +8 -0
  24. package/dist/db/migrations.d.ts.map +1 -0
  25. package/dist/db/migrations.js +39 -0
  26. package/dist/db/migrations.js.map +1 -0
  27. package/dist/db/queries.d.ts +46 -0
  28. package/dist/db/queries.d.ts.map +1 -0
  29. package/dist/db/queries.js +436 -0
  30. package/dist/db/queries.js.map +1 -0
  31. package/dist/db/schema.sql +113 -0
  32. package/dist/db/sqlite-adapter.d.ts +30 -0
  33. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  34. package/dist/db/sqlite-adapter.js +78 -0
  35. package/dist/db/sqlite-adapter.js.map +1 -0
  36. package/dist/directory.d.ts +37 -0
  37. package/dist/directory.d.ts.map +1 -0
  38. package/dist/directory.js +160 -0
  39. package/dist/directory.js.map +1 -0
  40. package/dist/errors.d.ts +46 -0
  41. package/dist/errors.d.ts.map +1 -0
  42. package/dist/errors.js +90 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/graph/traversal.d.ts +157 -0
  45. package/dist/graph/traversal.d.ts.map +1 -0
  46. package/dist/graph/traversal.js +531 -0
  47. package/dist/graph/traversal.js.map +1 -0
  48. package/dist/index.d.ts +183 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +435 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/introspect/base.d.ts +62 -0
  53. package/dist/introspect/base.d.ts.map +1 -0
  54. package/dist/introspect/base.js +107 -0
  55. package/dist/introspect/base.js.map +1 -0
  56. package/dist/introspect/connection.d.ts +30 -0
  57. package/dist/introspect/connection.d.ts.map +1 -0
  58. package/dist/introspect/connection.js +232 -0
  59. package/dist/introspect/connection.js.map +1 -0
  60. package/dist/introspect/index.d.ts +23 -0
  61. package/dist/introspect/index.d.ts.map +1 -0
  62. package/dist/introspect/index.js +46 -0
  63. package/dist/introspect/index.js.map +1 -0
  64. package/dist/introspect/mysql.d.ts +64 -0
  65. package/dist/introspect/mysql.d.ts.map +1 -0
  66. package/dist/introspect/mysql.js +360 -0
  67. package/dist/introspect/mysql.js.map +1 -0
  68. package/dist/introspect/postgres.d.ts +55 -0
  69. package/dist/introspect/postgres.d.ts.map +1 -0
  70. package/dist/introspect/postgres.js +372 -0
  71. package/dist/introspect/postgres.js.map +1 -0
  72. package/dist/introspect/sqlite.d.ts +33 -0
  73. package/dist/introspect/sqlite.d.ts.map +1 -0
  74. package/dist/introspect/sqlite.js +207 -0
  75. package/dist/introspect/sqlite.js.map +1 -0
  76. package/dist/mcp/engine.d.ts +92 -0
  77. package/dist/mcp/engine.d.ts.map +1 -0
  78. package/dist/mcp/engine.js +261 -0
  79. package/dist/mcp/engine.js.map +1 -0
  80. package/dist/mcp/index.d.ts +33 -0
  81. package/dist/mcp/index.d.ts.map +1 -0
  82. package/dist/mcp/index.js +119 -0
  83. package/dist/mcp/index.js.map +1 -0
  84. package/dist/mcp/server-instructions.d.ts +9 -0
  85. package/dist/mcp/server-instructions.d.ts.map +1 -0
  86. package/dist/mcp/server-instructions.js +71 -0
  87. package/dist/mcp/server-instructions.js.map +1 -0
  88. package/dist/mcp/session.d.ts +35 -0
  89. package/dist/mcp/session.d.ts.map +1 -0
  90. package/dist/mcp/session.js +140 -0
  91. package/dist/mcp/session.js.map +1 -0
  92. package/dist/mcp/tools.d.ts +99 -0
  93. package/dist/mcp/tools.d.ts.map +1 -0
  94. package/dist/mcp/tools.js +499 -0
  95. package/dist/mcp/tools.js.map +1 -0
  96. package/dist/mcp/transport.d.ts +78 -0
  97. package/dist/mcp/transport.d.ts.map +1 -0
  98. package/dist/mcp/transport.js +182 -0
  99. package/dist/mcp/transport.js.map +1 -0
  100. package/dist/search/query-parser.d.ts +66 -0
  101. package/dist/search/query-parser.d.ts.map +1 -0
  102. package/dist/search/query-parser.js +163 -0
  103. package/dist/search/query-parser.js.map +1 -0
  104. package/dist/search/query-utils.d.ts +78 -0
  105. package/dist/search/query-utils.d.ts.map +1 -0
  106. package/dist/search/query-utils.js +203 -0
  107. package/dist/search/query-utils.js.map +1 -0
  108. package/dist/types.d.ts +279 -0
  109. package/dist/types.d.ts.map +1 -0
  110. package/dist/types.js +47 -0
  111. package/dist/types.js.map +1 -0
  112. package/dist/utils.d.ts +40 -0
  113. package/dist/utils.d.ts.map +1 -0
  114. package/dist/utils.js +190 -0
  115. package/dist/utils.js.map +1 -0
  116. package/package.json +54 -0
@@ -0,0 +1,30 @@
1
+ /**
2
+ * SQLite Adapter
3
+ *
4
+ * Thin wrapper over Node's built-in `node:sqlite` (`DatabaseSync`).
5
+ * Requires Node >= 22.5.
6
+ */
7
+ export interface SqliteStatement {
8
+ run(...params: any[]): {
9
+ changes: number;
10
+ lastInsertRowid: number | bigint;
11
+ };
12
+ get(...params: any[]): any;
13
+ all(...params: any[]): any[];
14
+ }
15
+ export interface SqliteDatabase {
16
+ prepare(sql: string): SqliteStatement;
17
+ exec(sql: string): void;
18
+ pragma(str: string, options?: {
19
+ simple?: boolean;
20
+ }): any;
21
+ transaction<T>(fn: (...args: any[]) => T): (...args: any[]) => T;
22
+ close(): void;
23
+ readonly open: boolean;
24
+ }
25
+ export type SqliteBackend = 'node-sqlite';
26
+ export declare function createDatabase(dbPath: string): {
27
+ db: SqliteDatabase;
28
+ backend: SqliteBackend;
29
+ };
30
+ //# sourceMappingURL=sqlite-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-adapter.d.ts","sourceRoot":"","sources":["../../src/db/sqlite-adapter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,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,aAAa,CAAC;AAiE1C,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,EAAE,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,aAAa,CAAA;CAAE,CAW7F"}
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * SQLite Adapter
4
+ *
5
+ * Thin wrapper over Node's built-in `node:sqlite` (`DatabaseSync`).
6
+ * Requires Node >= 22.5.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.createDatabase = createDatabase;
10
+ class NodeSqliteAdapter {
11
+ _db;
12
+ constructor(dbPath) {
13
+ const { DatabaseSync } = require('node:sqlite');
14
+ this._db = new DatabaseSync(dbPath);
15
+ }
16
+ get open() {
17
+ return this._db.isOpen;
18
+ }
19
+ prepare(sql) {
20
+ const stmt = this._db.prepare(sql);
21
+ return {
22
+ run(...params) {
23
+ const r = stmt.run(...params);
24
+ return {
25
+ changes: Number(r?.changes ?? 0),
26
+ lastInsertRowid: r?.lastInsertRowid ?? 0,
27
+ };
28
+ },
29
+ get(...params) { return stmt.get(...params); },
30
+ all(...params) { return stmt.all(...params); },
31
+ };
32
+ }
33
+ exec(sql) {
34
+ this._db.exec(sql);
35
+ }
36
+ pragma(str, options) {
37
+ const trimmed = str.trim();
38
+ if (trimmed.includes('=')) {
39
+ this._db.exec(`PRAGMA ${trimmed}`);
40
+ return;
41
+ }
42
+ const row = this._db.prepare(`PRAGMA ${trimmed}`).get();
43
+ if (options?.simple) {
44
+ return row && typeof row === 'object' ? Object.values(row)[0] : row;
45
+ }
46
+ return row;
47
+ }
48
+ transaction(fn) {
49
+ return (...args) => {
50
+ this._db.exec('BEGIN');
51
+ try {
52
+ const result = fn(...args);
53
+ this._db.exec('COMMIT');
54
+ return result;
55
+ }
56
+ catch (error) {
57
+ this._db.exec('ROLLBACK');
58
+ throw error;
59
+ }
60
+ };
61
+ }
62
+ close() {
63
+ if (this._db.isOpen)
64
+ this._db.close();
65
+ }
66
+ }
67
+ function createDatabase(dbPath) {
68
+ try {
69
+ return { db: new NodeSqliteAdapter(dbPath), backend: 'node-sqlite' };
70
+ }
71
+ catch (error) {
72
+ const msg = error instanceof Error ? error.message : String(error);
73
+ throw new Error('Failed to open SQLite via node:sqlite module.\n' +
74
+ 'DBGraph requires Node.js 22.5+.\n' +
75
+ `Error: ${msg}`);
76
+ }
77
+ }
78
+ //# sourceMappingURL=sqlite-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite-adapter.js","sourceRoot":"","sources":["../../src/db/sqlite-adapter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAkFH,wCAWC;AA1ED,MAAM,iBAAiB;IACb,GAAG,CAAM;IAEjB,YAAY,MAAc;QACxB,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;QAChD,IAAI,CAAC,GAAG,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,GAAW;QACjB,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,OAAO;YACL,GAAG,CAAC,GAAG,MAAa;gBAClB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;gBAC9B,OAAO;oBACL,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC;oBAChC,eAAe,EAAE,CAAC,EAAE,eAAe,IAAI,CAAC;iBACzC,CAAC;YACJ,CAAC;YACD,GAAG,CAAC,GAAG,MAAa,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YACrD,GAAG,CAAC,GAAG,MAAa,IAAI,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;SACtD,CAAC;IACJ,C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CAAC,KAAK,EAAE,CAAC;IACxC,CAAC;CACF;AAED,SAAgB,cAAc,CAAC,MAAc;IAC3C,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,EAAE,IAAI,iBAAiB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;IACvE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,GAAG,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACnE,MAAM,IAAI,KAAK,CACb,iDAAiD;YACjD,mCAAmC;YACnC,UAAU,GAAG,EAAE,CAChB,CAAC;IACJ,CAAC;AACH,CAAC"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Directory Management
3
+ *
4
+ * Manages the .dbgraph/ directory structure for DBGraph data.
5
+ */
6
+ /**
7
+ * DBGraph directory name
8
+ */
9
+ export declare const DBGRAPH_DIR = ".dbgraph";
10
+ /**
11
+ * Get the .dbgraph directory path for a project
12
+ */
13
+ export declare function getDBGraphDir(projectRoot: string): string;
14
+ /**
15
+ * Check if a project has been initialized with DBGraph
16
+ */
17
+ export declare function isInitialized(projectRoot: string): boolean;
18
+ /**
19
+ * Find the nearest parent directory containing .dbgraph/
20
+ */
21
+ export declare function findNearestDBGraphRoot(startPath: string): string | null;
22
+ /**
23
+ * Create the .dbgraph directory structure
24
+ */
25
+ export declare function createDirectory(projectRoot: string): void;
26
+ /**
27
+ * Remove the .dbgraph directory
28
+ */
29
+ export declare function removeDirectory(projectRoot: string): void;
30
+ /**
31
+ * Validate the .dbgraph directory structure
32
+ */
33
+ export declare function validateDirectory(projectRoot: string): {
34
+ valid: boolean;
35
+ errors: string[];
36
+ };
37
+ //# sourceMappingURL=directory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.d.ts","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;GAEG;AACH,eAAO,MAAM,WAAW,aAAa,CAAC;AAEtC;;GAEG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEzD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAO1D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAkBvE;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CA8BzD;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAkBzD;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG;IACtD,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB,CAkBA"}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ /**
3
+ * Directory Management
4
+ *
5
+ * Manages the .dbgraph/ directory structure for DBGraph data.
6
+ */
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.DBGRAPH_DIR = void 0;
42
+ exports.getDBGraphDir = getDBGraphDir;
43
+ exports.isInitialized = isInitialized;
44
+ exports.findNearestDBGraphRoot = findNearestDBGraphRoot;
45
+ exports.createDirectory = createDirectory;
46
+ exports.removeDirectory = removeDirectory;
47
+ exports.validateDirectory = validateDirectory;
48
+ const fs = __importStar(require("fs"));
49
+ const path = __importStar(require("path"));
50
+ /**
51
+ * DBGraph directory name
52
+ */
53
+ exports.DBGRAPH_DIR = '.dbgraph';
54
+ /**
55
+ * Get the .dbgraph directory path for a project
56
+ */
57
+ function getDBGraphDir(projectRoot) {
58
+ return path.join(projectRoot, exports.DBGRAPH_DIR);
59
+ }
60
+ /**
61
+ * Check if a project has been initialized with DBGraph
62
+ */
63
+ function isInitialized(projectRoot) {
64
+ const dbgraphDir = getDBGraphDir(projectRoot);
65
+ if (!fs.existsSync(dbgraphDir) || !fs.statSync(dbgraphDir).isDirectory()) {
66
+ return false;
67
+ }
68
+ const dbPath = path.join(dbgraphDir, 'dbgraph.db');
69
+ return fs.existsSync(dbPath);
70
+ }
71
+ /**
72
+ * Find the nearest parent directory containing .dbgraph/
73
+ */
74
+ function findNearestDBGraphRoot(startPath) {
75
+ let current = path.resolve(startPath);
76
+ const root = path.parse(current).root;
77
+ while (current !== root) {
78
+ if (isInitialized(current)) {
79
+ return current;
80
+ }
81
+ const parent = path.dirname(current);
82
+ if (parent === current)
83
+ break;
84
+ current = parent;
85
+ }
86
+ if (isInitialized(current)) {
87
+ return current;
88
+ }
89
+ return null;
90
+ }
91
+ /**
92
+ * Create the .dbgraph directory structure
93
+ */
94
+ function createDirectory(projectRoot) {
95
+ const dbgraphDir = getDBGraphDir(projectRoot);
96
+ const dbPath = path.join(dbgraphDir, 'dbgraph.db');
97
+ if (fs.existsSync(dbPath)) {
98
+ throw new Error(`DBGraph already initialized in ${projectRoot}`);
99
+ }
100
+ fs.mkdirSync(dbgraphDir, { recursive: true });
101
+ // Create .gitignore inside .dbgraph
102
+ const gitignorePath = path.join(dbgraphDir, '.gitignore');
103
+ if (!fs.existsSync(gitignorePath)) {
104
+ const gitignoreContent = [
105
+ '# DBGraph data files',
106
+ '# These are local to each machine and should not be committed',
107
+ '',
108
+ '# Database',
109
+ '*.db',
110
+ '*.db-wal',
111
+ '*.db-shm',
112
+ '',
113
+ '# Cache',
114
+ 'cache/',
115
+ '',
116
+ '# Logs',
117
+ '*.log',
118
+ ].join('\n');
119
+ fs.writeFileSync(gitignorePath, gitignoreContent, 'utf-8');
120
+ }
121
+ }
122
+ /**
123
+ * Remove the .dbgraph directory
124
+ */
125
+ function removeDirectory(projectRoot) {
126
+ const dbgraphDir = getDBGraphDir(projectRoot);
127
+ if (!fs.existsSync(dbgraphDir)) {
128
+ return;
129
+ }
130
+ const lstat = fs.lstatSync(dbgraphDir);
131
+ if (lstat.isSymbolicLink()) {
132
+ fs.unlinkSync(dbgraphDir);
133
+ return;
134
+ }
135
+ if (!lstat.isDirectory()) {
136
+ fs.unlinkSync(dbgraphDir);
137
+ return;
138
+ }
139
+ fs.rmSync(dbgraphDir, { recursive: true, force: true });
140
+ }
141
+ /**
142
+ * Validate the .dbgraph directory structure
143
+ */
144
+ function validateDirectory(projectRoot) {
145
+ const errors = [];
146
+ const dbgraphDir = getDBGraphDir(projectRoot);
147
+ if (!fs.existsSync(dbgraphDir)) {
148
+ errors.push('DBGraph directory does not exist');
149
+ return { valid: false, errors };
150
+ }
151
+ if (!fs.statSync(dbgraphDir).isDirectory()) {
152
+ errors.push('.dbgraph exists but is not a directory');
153
+ return { valid: false, errors };
154
+ }
155
+ return {
156
+ valid: errors.length === 0,
157
+ errors,
158
+ };
159
+ }
160
+ //# sourceMappingURL=directory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directory.js","sourceRoot":"","sources":["../src/directory.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAaH,sCAEC;AAKD,sCAOC;AAKD,wDAkBC;AAKD,0CA8BC;AAKD,0CAkBC;AAKD,8CAqBC;AApID,uCAAyB;AACzB,2CAA6B;AAE7B;;GAEG;AACU,QAAA,WAAW,GAAG,UAAU,CAAC;AAEtC;;GAEG;AACH,SAAgB,aAAa,CAAC,WAAmB;IAC/C,OAAO,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,mBAAW,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,WAAmB;IAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAC9C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC;QACzE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACnD,OAAO,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AAC/B,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,SAAiB;IACtD,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC;IAEtC,OAAO,OAAO,KAAK,IAAI,EAAE,CAAC;QACxB,IAAI,aAAa,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}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * DBGraph Error Classes
3
+ */
4
+ /**
5
+ * Base error class for all DBGraph errors
6
+ */
7
+ export declare class DBGraphError extends Error {
8
+ readonly code: string;
9
+ readonly context?: Record<string, unknown>;
10
+ constructor(message: string, code: string, context?: Record<string, unknown>);
11
+ }
12
+ /**
13
+ * Error with database introspection
14
+ */
15
+ export declare class IntrospectError extends DBGraphError {
16
+ readonly source: string;
17
+ constructor(message: string, source: string, cause?: Error);
18
+ }
19
+ /**
20
+ * Error with database operations
21
+ */
22
+ export declare class DatabaseError extends DBGraphError {
23
+ readonly operation: string;
24
+ constructor(message: string, operation: string, cause?: Error);
25
+ }
26
+ /**
27
+ * Error with search operations
28
+ */
29
+ export declare class SearchError extends DBGraphError {
30
+ readonly query: string;
31
+ constructor(message: string, query: string, cause?: Error);
32
+ }
33
+ /**
34
+ * Error with configuration
35
+ */
36
+ export declare class ConfigError extends DBGraphError {
37
+ constructor(message: string, details?: Record<string, unknown>);
38
+ }
39
+ /**
40
+ * Error with database connection
41
+ */
42
+ export declare class ConnectionError extends DBGraphError {
43
+ readonly source: string;
44
+ constructor(message: string, source: string, cause?: Error);
45
+ }
46
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAE/B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAS7E;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM3D;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,YAAY;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM9D;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;gBAEX,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM1D;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY;gBAC/B,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IAC/C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAM3D"}
package/dist/errors.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ /**
3
+ * DBGraph Error Classes
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ConnectionError = exports.ConfigError = exports.SearchError = exports.DatabaseError = exports.IntrospectError = exports.DBGraphError = void 0;
7
+ /**
8
+ * Base error class for all DBGraph errors
9
+ */
10
+ class DBGraphError extends Error {
11
+ code;
12
+ context;
13
+ constructor(message, code, context) {
14
+ super(message);
15
+ this.name = 'DBGraphError';
16
+ this.code = code;
17
+ this.context = context;
18
+ if (Error.captureStackTrace) {
19
+ Error.captureStackTrace(this, this.constructor);
20
+ }
21
+ }
22
+ }
23
+ exports.DBGraphError = DBGraphError;
24
+ /**
25
+ * Error with database introspection
26
+ */
27
+ class IntrospectError extends DBGraphError {
28
+ source;
29
+ constructor(message, source, cause) {
30
+ super(message, 'INTROSPECT_ERROR', { source, cause: cause?.message });
31
+ this.name = 'IntrospectError';
32
+ this.source = source;
33
+ if (cause)
34
+ this.cause = cause;
35
+ }
36
+ }
37
+ exports.IntrospectError = IntrospectError;
38
+ /**
39
+ * Error with database operations
40
+ */
41
+ class DatabaseError extends DBGraphError {
42
+ operation;
43
+ constructor(message, operation, cause) {
44
+ super(message, 'DATABASE_ERROR', { operation, cause: cause?.message });
45
+ this.name = 'DatabaseError';
46
+ this.operation = operation;
47
+ if (cause)
48
+ this.cause = cause;
49
+ }
50
+ }
51
+ exports.DatabaseError = DatabaseError;
52
+ /**
53
+ * Error with search operations
54
+ */
55
+ class SearchError extends DBGraphError {
56
+ query;
57
+ constructor(message, query, cause) {
58
+ super(message, 'SEARCH_ERROR', { query, cause: cause?.message });
59
+ this.name = 'SearchError';
60
+ this.query = query;
61
+ if (cause)
62
+ this.cause = cause;
63
+ }
64
+ }
65
+ exports.SearchError = SearchError;
66
+ /**
67
+ * Error with configuration
68
+ */
69
+ class ConfigError extends DBGraphError {
70
+ constructor(message, details) {
71
+ super(message, 'CONFIG_ERROR', details);
72
+ this.name = 'ConfigError';
73
+ }
74
+ }
75
+ exports.ConfigError = ConfigError;
76
+ /**
77
+ * Error with database connection
78
+ */
79
+ class ConnectionError extends DBGraphError {
80
+ source;
81
+ constructor(message, source, cause) {
82
+ super(message, 'CONNECTION_ERROR', { source, cause: cause?.message });
83
+ this.name = 'ConnectionError';
84
+ this.source = source;
85
+ if (cause)
86
+ this.cause = cause;
87
+ }
88
+ }
89
+ exports.ConnectionError = ConnectionError;
90
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IAC5B,IAAI,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S;IAEvB,YAAY,OAAe,EAAE,KAAa,EAAE,KAAa;QACvD,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QACjE,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAChC,CAAC;CACF;AATD,kCASC;AAED;;GAEG;AACH,MAAa,WAAY,SAAQ,YAAY;IAC3C,YAAY,OAAe,EAAE,OAAiC;QAC5D,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AALD,kCAKC;AAED;;GAEG;AACH,MAAa,eAAgB,SAAQ,YAAY;IACtC,MAAM,CAAS;IAExB,YAAY,OAAe,EAAE,MAAc,EAAE,KAAa;QACxD,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,KAAK;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAChC,CAAC;CACF;AATD,0CASC"}
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Graph Traversal Algorithms
3
+ *
4
+ * BFS and DFS traversal for the database schema knowledge graph.
5
+ * Operates on nodes/edges stored in SQLite via QueryBuilder.
6
+ *
7
+ * All traversal methods use batch node lookups (getNodesByIds) to avoid
8
+ * N+1 query patterns and maintain performance on large schemas.
9
+ */
10
+ import { Node, Edge, Subgraph, TraversalOptions, EdgeKind } from '../types';
11
+ import { QueryBuilder } from '../db/queries';
12
+ /**
13
+ * Graph traverser for BFS and DFS traversal of the database schema graph.
14
+ *
15
+ * Provides methods to navigate the graph structure — containment hierarchies,
16
+ * foreign-key references, and impact analysis — all with batched queries.
17
+ */
18
+ export declare class GraphTraverser {
19
+ private queries;
20
+ constructor(queries: QueryBuilder);
21
+ /**
22
+ * Traverse the graph using breadth-first search.
23
+ *
24
+ * Structural edges (`contains`) are visited before reference edges so that
25
+ * BFS discovers internal structure first before fanning out.
26
+ *
27
+ * @param startId - Starting node ID
28
+ * @param options - Traversal options
29
+ * @returns Subgraph containing traversed nodes and edges
30
+ */
31
+ traverseBFS(startId: string, options?: TraversalOptions): Subgraph;
32
+ /**
33
+ * Traverse the graph using depth-first search.
34
+ *
35
+ * @param startId - Starting node ID
36
+ * @param options - Traversal options
37
+ * @returns Subgraph containing traversed nodes and edges
38
+ */
39
+ traverseDFS(startId: string, options?: TraversalOptions): Subgraph;
40
+ /**
41
+ * Recursive DFS helper with batch neighbor fetching.
42
+ */
43
+ private dfsRecursive;
44
+ /**
45
+ * Get adjacent edges based on direction.
46
+ */
47
+ private getAdjacentEdges;
48
+ /**
49
+ * Find all nodes that reference a given node (e.g., tables with foreign keys
50
+ * pointing to this table, or views referencing this table).
51
+ *
52
+ * Follows `references` edges incoming to the target.
53
+ *
54
+ * @param nodeId - ID of the node being referenced
55
+ * @param maxDepth - Maximum depth to traverse (default: 1)
56
+ * @returns Array of { caller node, edge } pairs
57
+ */
58
+ getCallers(nodeId: string, maxDepth?: number): Array<{
59
+ node: Node;
60
+ edge: Edge;
61
+ }>;
62
+ private getCallersRecursive;
63
+ /**
64
+ * Find all nodes referenced by a given node (e.g., tables this foreign key
65
+ * points to, tables this view depends on).
66
+ *
67
+ * Follows `references` edges outgoing from the source.
68
+ *
69
+ * @param nodeId - ID of the source node
70
+ * @param maxDepth - Maximum depth to traverse (default: 1)
71
+ * @returns Array of { callee node, edge } pairs
72
+ */
73
+ getCallees(nodeId: string, maxDepth?: number): Array<{
74
+ node: Node;
75
+ edge: Edge;
76
+ }>;
77
+ private getCalleesRecursive;
78
+ /**
79
+ * Find all usages of a node — all incoming edges regardless of kind.
80
+ *
81
+ * This returns every node that has any edge pointing to the given node,
82
+ * including foreign key references, dependencies, and structural containment.
83
+ *
84
+ * @param nodeId - ID of the node being examined
85
+ * @returns Array of { using node, edge } pairs
86
+ */
87
+ findUsages(nodeId: string): Array<{
88
+ node: Node;
89
+ edge: Edge;
90
+ }>;
91
+ /**
92
+ * Compute the impact radius of a node — all nodes that could be affected
93
+ * if this schema object changes.
94
+ *
95
+ * Traverses incoming edges (dependents), including following `contains`
96
+ * edges into container children (e.g., a column change impacts the table's
97
+ * foreign-key dependents).
98
+ *
99
+ * @param nodeId - ID of the node being changed
100
+ * @param maxDepth - Maximum depth to traverse (default: 3)
101
+ * @returns Subgraph containing potentially impacted nodes
102
+ */
103
+ getImpactRadius(nodeId: string, maxDepth?: number): Subgraph;
104
+ /**
105
+ * Recursive impact traversal — follows incoming edges and also descends
106
+ * into container children (e.g., table → columns → FK references).
107
+ */
108
+ private getImpactRecursive;
109
+ /**
110
+ * Find the shortest path between two nodes using bidirectional BFS.
111
+ *
112
+ * Each step follows outgoing edges from the direction being expanded.
113
+ * Returns the path as an ordered array of { node, edge } steps, where
114
+ * the first entry's `edge` is null (the start node has no incoming edge).
115
+ *
116
+ * @param fromId - Starting node ID
117
+ * @param toId - Target node ID
118
+ * @param edgeKinds - Edge types to consider (all if empty array)
119
+ * @returns Ordered path, or null if no path exists
120
+ */
121
+ findPath(fromId: string, toId: string, edgeKinds?: EdgeKind[]): Array<{
122
+ node: Node;
123
+ edge: Edge | null;
124
+ }> | null;
125
+ /**
126
+ * Expand one frontier of the bidirectional BFS by one layer.
127
+ *
128
+ * Returns the meeting node ID if frontiers intersect, or null otherwise.
129
+ */
130
+ private expandPathFrontier;
131
+ /**
132
+ * Merge forward and backward path fragments at the meeting node.
133
+ */
134
+ private mergePaths;
135
+ /**
136
+ * Walk up the containment hierarchy from a node to its ancestors.
137
+ *
138
+ * Follows `contains` edges in reverse (incoming edges of kind `contains`),
139
+ * which represent "parent → child" — so the incoming edge on this node
140
+ * points to its parent.
141
+ *
142
+ * @param nodeId - ID of the node to start from
143
+ * @returns Array of ancestor nodes from immediate parent to root
144
+ */
145
+ getAncestors(nodeId: string): Node[];
146
+ /**
147
+ * Get immediate children of a node via `contains` outgoing edges.
148
+ *
149
+ * For a table, these would be its columns, indexes, constraints, etc.
150
+ * For a schema, these would be its tables and views.
151
+ *
152
+ * @param nodeId - ID of the parent node
153
+ * @returns Array of child nodes
154
+ */
155
+ getChildren(nodeId: string): Node[];
156
+ }
157
+ //# sourceMappingURL=traversal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traversal.d.ts","sourceRoot":"","sources":["../../src/graph/traversal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,IAAI,EAAY,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAuB7C;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAe;gBAElB,OAAO,EAAE,YAAY;IAQjC;;;;;;;;;OASG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,QAAQ;IAwEtE;;;;;;OAMG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,QAAQ;IAyBtE;;OAEG;IACH,OAAO,CAAC,YAAY;IA0CpB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAsBxB;;;;;;;;;OASG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,KAAK,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,IAAI,EAAE,IAAI,CAAA;KAAE,CAAC;IASnF,OAAO,CAAC,mBAAmB;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