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,62 @@
1
+ /**
2
+ * Base Introspector — shared helpers for all database engines
3
+ *
4
+ * Provides:
5
+ * - URI / naming helpers
6
+ * - testConnection() implementation
7
+ * - Generic Node/Edge factories with deterministic IDs
8
+ */
9
+ import { IntrospectResult, DbEngine, DbConnectionConfig, Node, NodeKind, Edge, EdgeKind } from '../types';
10
+ /**
11
+ * Introspector Interface
12
+ */
13
+ export interface Introspector {
14
+ /** Extract all schema objects into nodes/edges */
15
+ extractAll(): Promise<IntrospectResult>;
16
+ /** Test connectivity (open + close) */
17
+ testConnection(): Promise<boolean>;
18
+ /** Human-readable connection URI (no credentials) */
19
+ getDisplayUri(): string;
20
+ /** Database name from config */
21
+ getDatabase(): string;
22
+ /** Engine type (e.g. 'postgresql') */
23
+ getEngine(): DbEngine;
24
+ }
25
+ /**
26
+ * Abstract base class providing:
27
+ * - URI / naming helpers
28
+ * - testConnection() implementation
29
+ * - Generic Node/Edge factories
30
+ *
31
+ * Subclass responsibilities:
32
+ * - implement extractAll() with engine-specific information_schema queries
33
+ * - call the protected factories to produce Node[] + Edge[]
34
+ */
35
+ export declare abstract class BaseIntrospector implements Introspector {
36
+ protected config: DbConnectionConfig;
37
+ constructor(config: DbConnectionConfig);
38
+ abstract extractAll(): Promise<IntrospectResult>;
39
+ getEngine(): DbEngine;
40
+ getDatabase(): string;
41
+ getDisplayUri(): string;
42
+ testConnection(): Promise<boolean>;
43
+ /** Build a filePath URI for objects in a given schema: `db://@alias/schema` */
44
+ protected schemaFilePath(schema: string): string;
45
+ /** Dot-separated qualified name: `@alias.schema.table.column` */
46
+ protected qn(...parts: string[]): string;
47
+ /** Map from (schema, table) to a stable lookup key */
48
+ protected tableKey(schema: string, table: string): string;
49
+ /** Map from (schema, table, column) to a stable lookup key */
50
+ protected columnKey(schema: string, table: string, column: string): string;
51
+ /**
52
+ * Create a Node with a deterministic ID derived from its qualified name.
53
+ */
54
+ protected makeNode(kind: NodeKind, name: string, qualifiedName: string, filePath: string, extra?: Partial<Node>): Node;
55
+ /**
56
+ * Create an Edge with deterministic provenance = 'introspect'.
57
+ */
58
+ protected makeEdge(source: string, target: string, kind: EdgeKind, metadata?: Record<string, unknown>): Edge;
59
+ /** Shorthand: contains edge (parent → child) */
60
+ protected containEdge(parentId: string, childId: string): Edge;
61
+ }
62
+ //# sourceMappingURL=base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/introspect/base.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,E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,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,GACpB,IAAI;IAeP;;OAEG;IACH,SAAS,CAAC,QAAQ,CAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,EACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,IAAI;IAUP,gDAAgD;IAChD,SAAS,CAAC,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;CAG/D"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ /**
3
+ * Base Introspector — shared helpers for all database engines
4
+ *
5
+ * Provides:
6
+ * - URI / naming helpers
7
+ * - testConnection() implementation
8
+ * - Generic Node/Edge factories with deterministic IDs
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.BaseIntrospector = void 0;
12
+ const connection_1 = require("./connection");
13
+ const utils_1 = require("../utils");
14
+ /**
15
+ * Abstract base class providing:
16
+ * - URI / naming helpers
17
+ * - testConnection() implementation
18
+ * - Generic Node/Edge factories
19
+ *
20
+ * Subclass responsibilities:
21
+ * - implement extractAll() with engine-specific information_schema queries
22
+ * - call the protected factories to produce Node[] + Edge[]
23
+ */
24
+ class BaseIntrospector {
25
+ config;
26
+ constructor(config) {
27
+ this.config = config;
28
+ }
29
+ getEngine() {
30
+ return this.config.engine;
31
+ }
32
+ getDatabase() {
33
+ return this.config.database;
34
+ }
35
+ getDisplayUri() {
36
+ if (this.config.path) {
37
+ return `${this.config.engine}:${this.config.path}`;
38
+ }
39
+ const h = this.config.host || 'localhost';
40
+ const defaultPort = this.config.engine === 'postgresql' ? 5432 : 3306;
41
+ const p = this.config.port || defaultPort;
42
+ return `${this.config.engine}://${h}:${p}/${this.config.database}`;
43
+ }
44
+ async testConnection() {
45
+ try {
46
+ const conn = await (0, connection_1.createConnection)(this.config);
47
+ await conn.close();
48
+ return true;
49
+ }
50
+ catch {
51
+ return false;
52
+ }
53
+ }
54
+ // ---- URI / naming helpers ----
55
+ /** Build a filePath URI for objects in a given schema: `db://@alias/schema` */
56
+ schemaFilePath(schema) {
57
+ return `db://@${this.config.alias}/${schema}`;
58
+ }
59
+ /** Dot-separated qualified name: `@alias.schema.table.column` */
60
+ qn(...parts) {
61
+ return `${this.config.alias}.${parts.join('.')}`;
62
+ }
63
+ /** Map from (schema, table) to a stable lookup key */
64
+ tableKey(schema, table) {
65
+ return `${schema}.${table}`;
66
+ }
67
+ /** Map from (schema, table, column) to a stable lookup key */
68
+ columnKey(schema, table, column) {
69
+ return `${schema}.${table}.${column}`;
70
+ }
71
+ // ---- Generic Node / Edge factories ----
72
+ /**
73
+ * Create a Node with a deterministic ID derived from its qualified name.
74
+ */
75
+ makeNode(kind, name, qualifiedName, filePath, extra) {
76
+ return {
77
+ id: (0, utils_1.hashString)(qualifiedName),
78
+ kind,
79
+ name,
80
+ qualifiedName,
81
+ filePath,
82
+ language: this.config.engine,
83
+ startLine: 0,
84
+ endLine: 0,
85
+ updatedAt: Date.now(),
86
+ ...extra,
87
+ };
88
+ }
89
+ /**
90
+ * Create an Edge with deterministic provenance = 'introspect'.
91
+ */
92
+ makeEdge(source, target, kind, metadata) {
93
+ return {
94
+ source,
95
+ target,
96
+ kind,
97
+ metadata,
98
+ provenance: 'introspect',
99
+ };
100
+ }
101
+ /** Shorthand: contains edge (parent → child) */
102
+ containEdge(parentId, childId) {
103
+ return this.makeEdge(parentId, childId, 'contains');
104
+ }
105
+ }
106
+ exports.BaseIntrospector = BaseIntrospector;
107
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/introspect/base.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAWH,6CAAgD;AAChD,oCAAsC;AAsBtC;;;;;;;;;GASG;AACH,MAAsB,gBAAgB;IACd;IAAtB,YAAsB,MAA0B;QAA1B,WAA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C,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACnD,CAAC;IAED,sDAAsD;IAC5C,QAAQ,CAAC,MAAc,EAAE,KAAa;QAC9C,OAAO,GAAG,MAAM,IAAI,KAAK,EAAE,CAAC;IAC9B,CAAC;IAED,8DAA8D;IACpD,SAAS,CAAC,MAAc,EAAE,KAAa,EAAE,MAAc;QAC/D,OAAO,GAAG,MAAM,IAAI,KAAK,IAAI,MAAM,EAAE,CAAC;IACxC,CAAC;IAED,0CAA0C;IAE1C;;OAEG;IACO,QAAQ,CAChB,IAAc,EACd,IAAY,EACZ,aAAqB,EACrB,QAAgB,EAChB,KAAqB;QAErB,OAAO;YACL,EAAE,EAAE,IAAA,kBAAU,EAAC,aAAa,CAAC;YAC7B,IAAI;YACJ,IAAI;YACJ,aAAa;YACb,QAAQ;YACR,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;YAC5B,SAAS,EAAE,CAAC;YACZ,OAAO,EAAE,CAAC;YACV,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,GAAG,KAAK;SACT,CAAC;IACJ,CAAC;IAED;;OAEG;IACO,QAAQ,CAChB,MAAc,EACd,MAAc,EACd,IAAc,EACd,QAAkC;QAElC,OAAO;YACL,MAAM;YACN,MAAM;YACN,IAAI;YACJ,QAAQ;YACR,UAAU,EAAE,YAAY;SACzB,CAAC;IACJ,CAAC;IAED,gDAAgD;IACtC,WAAW,CAAC,QAAgB,EAAE,OAAe;QACrD,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;IACtD,CAAC;CACF;AAzGD,4CAyGC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * DB Connection Management
3
+ *
4
+ * Adapter pattern over pg, mysql2, and node:sqlite drivers.
5
+ * Driver packages are lazy-imported with try/catch so missing
6
+ * deps fail at connect() time, not at module load time.
7
+ */
8
+ import { DbConnectionConfig } from '../types';
9
+ export interface DBConnection {
10
+ /** Execute a SQL query and return all result rows */
11
+ query(sql: string, params?: any[]): Promise<any[]>;
12
+ /** Close the connection / release pool resources */
13
+ close(): Promise<void>;
14
+ }
15
+ /**
16
+ * Create a DBConnection for the given config.
17
+ *
18
+ * Supported engines:
19
+ * - `postgresql` — via the `pg` package
20
+ * - `mysql` / `mariadb` — via the `mysql2` package
21
+ * - `sqlite` — via built-in `node:sqlite` (Node >= 22.5)
22
+ *
23
+ * @throws ConnectionError if the driver is unavailable or the connection fails.
24
+ */
25
+ export declare function createConnection(config: DbConnectionConfig): Promise<DBConnection>;
26
+ /**
27
+ * Quick connectivity check — returns true if a full connection cycle succeeds.
28
+ */
29
+ export declare function tryConnect(config: DbConnectionConfig): Promise<boolean>;
30
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/introspect/connection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAO9C,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IACnD,oDAAoD;IACpD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AA+OD;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,YAAY,CAAC,CAexF;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAQ7E"}
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ /**
3
+ * DB Connection Management
4
+ *
5
+ * Adapter pattern over pg, mysql2, and node:sqlite drivers.
6
+ * Driver packages are lazy-imported with try/catch so missing
7
+ * deps fail at connect() time, not at module load time.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.createConnection = createConnection;
11
+ exports.tryConnect = tryConnect;
12
+ const errors_1 = require("../errors");
13
+ // =============================================================================
14
+ // Helpers
15
+ // =============================================================================
16
+ function parseAuth(auth) {
17
+ if (!auth || auth.length === 0)
18
+ return {};
19
+ const idx = auth.indexOf(':');
20
+ if (idx === -1)
21
+ return { user: auth };
22
+ return { user: auth.substring(0, idx), password: auth.substring(idx + 1) };
23
+ }
24
+ // =============================================================================
25
+ // PostgreSQL Connection (pg)
26
+ // =============================================================================
27
+ let pgModule;
28
+ try {
29
+ pgModule = require('pg');
30
+ }
31
+ catch {
32
+ /* handled at connect() time */
33
+ }
34
+ class PgConnection {
35
+ client;
36
+ constructor(client) {
37
+ this.client = client;
38
+ }
39
+ static async create(config) {
40
+ if (!pgModule) {
41
+ throw new errors_1.ConnectionError(`pg package is not installed.\n` +
42
+ `Connect to ${config.alias} (${config.engine}) by running: npm install pg`, config.alias);
43
+ }
44
+ const auth = parseAuth(config.auth);
45
+ const client = new pgModule.Client({
46
+ host: config.host || 'localhost',
47
+ port: config.port || 5432,
48
+ database: config.database,
49
+ user: auth.user,
50
+ password: auth.password,
51
+ ssl: config.ssl || false,
52
+ connectionTimeoutMillis: 10_000,
53
+ });
54
+ try {
55
+ await client.connect();
56
+ }
57
+ catch (err) {
58
+ throw new errors_1.ConnectionError(`Failed to connect to PostgreSQL at ${config.host || 'localhost'}:${config.port || 5432}/${config.database}: ${err.message}`, config.alias, err);
59
+ }
60
+ return new PgConnection(client);
61
+ }
62
+ async query(sql, params) {
63
+ try {
64
+ const result = await this.client.query(sql, params);
65
+ return result.rows;
66
+ }
67
+ catch (err) {
68
+ throw new errors_1.ConnectionError(`Query failed: ${err.message}\nSQL: ${sql.substring(0, 200)}`, 'query', err);
69
+ }
70
+ }
71
+ async close() {
72
+ try {
73
+ await this.client.end();
74
+ }
75
+ catch {
76
+ /* closing a closed connection is harmless */
77
+ }
78
+ }
79
+ }
80
+ // =============================================================================
81
+ // MySQL / MariaDB Connection (mysql2)
82
+ // =============================================================================
83
+ let mysqlModule;
84
+ try {
85
+ mysqlModule = require('mysql2/promise');
86
+ }
87
+ catch {
88
+ /* handled at connect() time */
89
+ }
90
+ class MySQLConnection {
91
+ pool;
92
+ constructor(pool) {
93
+ this.pool = pool;
94
+ }
95
+ static async create(config) {
96
+ if (!mysqlModule) {
97
+ throw new errors_1.ConnectionError(`mysql2 package is not installed.\n` +
98
+ `Connect to ${config.alias} (${config.engine}) by running: npm install mysql2`, config.alias);
99
+ }
100
+ const auth = parseAuth(config.auth);
101
+ const pool = mysqlModule.createPool({
102
+ host: config.host || 'localhost',
103
+ port: config.port || 3306,
104
+ database: config.database,
105
+ user: auth.user,
106
+ password: auth.password,
107
+ ssl: config.ssl || undefined,
108
+ waitForConnections: true,
109
+ connectionLimit: 5,
110
+ queueLimit: 0,
111
+ });
112
+ // Verify the connection works before returning
113
+ try {
114
+ const conn = await pool.getConnection();
115
+ conn.release();
116
+ }
117
+ catch (err) {
118
+ await pool.end().catch(() => { });
119
+ throw new errors_1.ConnectionError(`Failed to connect to MySQL at ${config.host || 'localhost'}:${config.port || 3306}/${config.database}: ${err.message}`, config.alias, err);
120
+ }
121
+ return new MySQLConnection(pool);
122
+ }
123
+ async query(sql, params) {
124
+ try {
125
+ const [rows] = await this.pool.query(sql, params);
126
+ return rows;
127
+ }
128
+ catch (err) {
129
+ throw new errors_1.ConnectionError(`Query failed: ${err.message}\nSQL: ${sql.substring(0, 200)}`, 'query', err);
130
+ }
131
+ }
132
+ async close() {
133
+ try {
134
+ await this.pool.end();
135
+ }
136
+ catch {
137
+ /* harmless */
138
+ }
139
+ }
140
+ }
141
+ // =============================================================================
142
+ // SQLite Connection (node:sqlite — built-in Node 22.5+)
143
+ // =============================================================================
144
+ let sqliteModule;
145
+ try {
146
+ sqliteModule = require('node:sqlite');
147
+ }
148
+ catch {
149
+ /* handled at connect() time */
150
+ }
151
+ class SQLiteConnection {
152
+ db;
153
+ constructor(db) {
154
+ this.db = db;
155
+ }
156
+ static create(config) {
157
+ if (!sqliteModule) {
158
+ throw new errors_1.ConnectionError(`node:sqlite is not available. DBGraph requires Node.js 22.5+`, config.alias);
159
+ }
160
+ if (!config.path) {
161
+ throw new errors_1.ConnectionError(`SQLite connection requires a path to the database file in config.\n` +
162
+ `Example: { engine: 'sqlite', alias: 'myapp', path: '/data/mydb.sqlite' }`, config.alias);
163
+ }
164
+ try {
165
+ const db = new sqliteModule.DatabaseSync(config.path);
166
+ // Use WAL mode for read performance during introspection
167
+ db.exec('PRAGMA journal_mode = WAL');
168
+ db.exec('PRAGMA foreign_keys = ON');
169
+ return new SQLiteConnection(db);
170
+ }
171
+ catch (err) {
172
+ throw new errors_1.ConnectionError(`Failed to open SQLite database at ${config.path}: ${err.message}`, config.alias, err);
173
+ }
174
+ }
175
+ async query(sql, params) {
176
+ try {
177
+ const stmt = this.db.prepare(sql);
178
+ return params ? stmt.all(...params) : stmt.all();
179
+ }
180
+ catch (err) {
181
+ throw new errors_1.ConnectionError(`Query failed: ${err.message}\nSQL: ${sql.substring(0, 200)}`, 'query', err);
182
+ }
183
+ }
184
+ async close() {
185
+ try {
186
+ this.db.close();
187
+ }
188
+ catch {
189
+ /* harmless */
190
+ }
191
+ }
192
+ }
193
+ // =============================================================================
194
+ // Factory
195
+ // =============================================================================
196
+ /**
197
+ * Create a DBConnection for the given config.
198
+ *
199
+ * Supported engines:
200
+ * - `postgresql` — via the `pg` package
201
+ * - `mysql` / `mariadb` — via the `mysql2` package
202
+ * - `sqlite` — via built-in `node:sqlite` (Node >= 22.5)
203
+ *
204
+ * @throws ConnectionError if the driver is unavailable or the connection fails.
205
+ */
206
+ async function createConnection(config) {
207
+ switch (config.engine) {
208
+ case 'postgresql':
209
+ return await PgConnection.create(config);
210
+ case 'mysql':
211
+ case 'mariadb':
212
+ return await MySQLConnection.create(config);
213
+ case 'sqlite':
214
+ return SQLiteConnection.create(config);
215
+ default:
216
+ throw new errors_1.ConnectionError(`Unsupported engine: "${config.engine}". Supported engines: postgresql, mysql, mariadb, sqlite`, config.alias);
217
+ }
218
+ }
219
+ /**
220
+ * Quick connectivity check — returns true if a full connection cycle succeeds.
221
+ */
222
+ async function tryConnect(config) {
223
+ try {
224
+ const conn = await createConnection(config);
225
+ await conn.close();
226
+ return true;
227
+ }
228
+ catch {
229
+ return false;
230
+ }
231
+ }
232
+ //# sourceMappingURL=connection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/introspect/connection.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;AAuQH,4CAeC;AAKD,gCAQC;AAhSD,sCAA4C;AAa5C,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF,SAAS,SAAS,CAAC,IAAa;IAC9B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAC1C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,GAAG,KAAK,CAAC,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACtC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC;AAC7E,CAAC;AAED,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEhF,IAAI,QAAa,CAAC;AAClB,IAAI,CAAC;IACH,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC;AAAC,MAAM,CAAC;IACP,+BAA+B;AACjC,CAAC;AAED,MAAM,YAAY;IACR,MAAM,CAAM;IAEpB,YAAoB,MAAW;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IAC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,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Introspector Interface & Factory
3
+ *
4
+ * An Introspector connects to a live database and extracts its schema as
5
+ * a knowledge graph of Node[] + Edge[] (the same format used by DBGraph's
6
+ * query engine and MCP tools).
7
+ *
8
+ * Concrete implementations:
9
+ * - PostgresIntrospector (postgres.ts)
10
+ * - MySQLIntrospector (mysql.ts)
11
+ * - SQLiteIntrospector (sqlite.ts)
12
+ */
13
+ import { DbConnectionConfig } from '../types';
14
+ import { Introspector } from './base';
15
+ export { Introspector, BaseIntrospector } from './base';
16
+ /**
17
+ * Create the appropriate Introspector for the given config.
18
+ *
19
+ * Throws if the engine is not supported.
20
+ * Does _not_ open a connection — call .extractAll() or .testConnection().
21
+ */
22
+ export declare function createIntrospector(config: DbConnectionConfig): Introspector;
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/introspect/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAI9C,OAAO,EAAE,YAAY,EAAoB,MAAM,QAAQ,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAMxD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,GAAG,YAAY,CAe3E"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Introspector Interface & Factory
4
+ *
5
+ * An Introspector connects to a live database and extracts its schema as
6
+ * a knowledge graph of Node[] + Edge[] (the same format used by DBGraph's
7
+ * query engine and MCP tools).
8
+ *
9
+ * Concrete implementations:
10
+ * - PostgresIntrospector (postgres.ts)
11
+ * - MySQLIntrospector (mysql.ts)
12
+ * - SQLiteIntrospector (sqlite.ts)
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BaseIntrospector = void 0;
16
+ exports.createIntrospector = createIntrospector;
17
+ const postgres_1 = require("./postgres");
18
+ const mysql_1 = require("./mysql");
19
+ const sqlite_1 = require("./sqlite");
20
+ // Re-export base types
21
+ var base_1 = require("./base");
22
+ Object.defineProperty(exports, "BaseIntrospector", { enumerable: true, get: function () { return base_1.BaseIntrospector; } });
23
+ // =============================================================================
24
+ // Factory
25
+ // =============================================================================
26
+ /**
27
+ * Create the appropriate Introspector for the given config.
28
+ *
29
+ * Throws if the engine is not supported.
30
+ * Does _not_ open a connection — call .extractAll() or .testConnection().
31
+ */
32
+ function createIntrospector(config) {
33
+ switch (config.engine) {
34
+ case 'postgresql':
35
+ return new postgres_1.PostgresIntrospector(config);
36
+ case 'mysql':
37
+ case 'mariadb':
38
+ return new mysql_1.MySQLIntrospector(config);
39
+ case 'sqlite':
40
+ return new sqlite_1.SQLiteIntrospector(config);
41
+ default:
42
+ throw new Error(`Unsupported database engine: "${config.engine}". ` +
43
+ `Supported engines: postgresql, mysql, mariadb, sqlite`);
44
+ }
45
+ }
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/introspect/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AAqBH,gDAeC;AAjCD,yCAAkD;AAClD,mCAA4C;AAC5C,qCAA8C;AAG9C,uBAAuB;AACvB,+BAAwD;AAAjC,wGAAA,gBAAgB,OAAA;AAEvC,gFAAgF;AAChF,UAAU;AACV,gFAAgF;AAEhF;;;;;GAKG;AACH,SAAgB,kBAAkB,CAAC,MAA0B;IAC3D,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,YAAY;YACf,OAAO,IAAI,+BAAoB,CAAC,MAAM,CAAC,CAAC;QAC1C,KAAK,OAAO,CAAC;QACb,KAAK,SAAS;YACZ,OAAO,IAAI,yBAAiB,CAAC,MAAM,CAAC,CAAC;QACvC,KAAK,QAAQ;YACX,OAAO,IAAI,2BAAkB,CAAC,MAAM,CAAC,CAAC;QACxC;YACE,MAAM,IAAI,KAAK,CACb,iCAAiC,MAAM,CAAC,MAAM,KAAK;gBACnD,uDAAuD,CACxD,CAAC;IACN,CAAC;AACH,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * MySQL / MariaDB Introspector
3
+ *
4
+ * Extracts schemas (databases), tables, columns, primary keys,
5
+ * foreign keys, indexes, and views from a MySQL or MariaDB
6
+ * database using `information_schema` queries.
7
+ *
8
+ * Connection: uses `connection.ts` which wraps the `mysql2` package.
9
+ * The driver import is guarded so a missing `mysql2` is reported at
10
+ * connect() time, not at module load time.
11
+ *
12
+ * MySQL-specific metadata extracted:
13
+ * - ENGINE (InnoDB, MyISAM, …)
14
+ * - AUTO_INCREMENT value
15
+ * - CHARACTER_SET_NAME / COLLATION_NAME
16
+ * - COLUMN_TYPE (full type string, e.g. "varchar(255)")
17
+ */
18
+ import { IntrospectResult, DbConnectionConfig } from '../types';
19
+ import { BaseIntrospector } from './base';
20
+ export declare class MySQLIntrospector extends BaseIntrospector {
21
+ /** The database/schema name to introspect */
22
+ private dbName;
23
+ constructor(config: DbConnectionConfig);
24
+ /**
25
+ * Full schema introspection pipeline.
26
+ *
27
+ * 1. Connect to the MySQL database
28
+ * 2. Query all structural metadata
29
+ * 3. Build Node[] + Edge[]
30
+ * 4. Close connection and return the result
31
+ */
32
+ extractAll(): Promise<IntrospectResult>;
33
+ /**
34
+ * Query: tables and views in the current database.
35
+ */
36
+ private queryTables;
37
+ /**
38
+ * Query: columns with MySQL-specific type info.
39
+ */
40
+ private queryColumns;
41
+ /**
42
+ * Query: primary key columns.
43
+ */
44
+ private queryPrimaryKeys;
45
+ /**
46
+ * Query: foreign key columns with referential actions.
47
+ *
48
+ * MySQL's KEY_COLUMN_USAGE table directly exposes the referenced
49
+ * schema/table/column columns, making it simpler than Postgres.
50
+ */
51
+ private queryForeignKeys;
52
+ /**
53
+ * Query: index columns from STATISTICS table.
54
+ *
55
+ * STATISTICS has one row per (index, column), so we group by
56
+ * index_name + seq_in_index to build the column list later.
57
+ */
58
+ private queryIndexes;
59
+ /**
60
+ * Query: view definitions.
61
+ */
62
+ private queryViews;
63
+ }
64
+ //# sourceMappingURL=mysql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/introspect/mysql.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAKnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,QAAQ,CAAC;AAqE1C,qBAAa,iBAAkB,SAAQ,gBAAgB;IACrD,6CAA6C;IAC7C,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,kBAAkB;IAKtC;;;;;;;OAOG;IACG,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IA8N7C;;OAEG;YACW,WAAW;IAiBzB;;OAEG;YACW,YAAY;IAwB1B;;OAEG;YACW,gBAAgB;IAoB9B;;;;;OAKG;YACW,gBAAgB;IA6B9B;;;;;OAKG;YACW,YAAY;IAgB1B;;OAEG;YACW,UAAU;CAWzB"}