@memberjunction/db-auto-doc 4.3.1 → 5.0.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/dist/ai/simple-ai-client.d.ts +70 -0
- package/dist/ai/simple-ai-client.d.ts.map +1 -0
- package/dist/ai/simple-ai-client.js +181 -0
- package/dist/ai/simple-ai-client.js.map +1 -0
- package/dist/analyzers/analyzer.d.ts +23 -0
- package/dist/analyzers/analyzer.d.ts.map +1 -0
- package/dist/analyzers/analyzer.js +127 -0
- package/dist/analyzers/analyzer.js.map +1 -0
- package/dist/cli-old/cli.d.ts +3 -0
- package/dist/cli-old/cli.d.ts.map +1 -0
- package/dist/cli-old/cli.js +388 -0
- package/dist/cli-old/cli.js.map +1 -0
- package/dist/commands/review.d.ts +11 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +82 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/database/connection.d.ts +40 -0
- package/dist/database/connection.d.ts.map +1 -0
- package/dist/database/connection.js +136 -0
- package/dist/database/connection.js.map +1 -0
- package/dist/database/introspection.d.ts +59 -0
- package/dist/database/introspection.d.ts.map +1 -0
- package/dist/database/introspection.js +124 -0
- package/dist/database/introspection.js.map +1 -0
- package/dist/generators/markdown-generator.d.ts +8 -0
- package/dist/generators/markdown-generator.d.ts.map +1 -0
- package/dist/generators/markdown-generator.js +106 -0
- package/dist/generators/markdown-generator.js.map +1 -0
- package/dist/generators/sql-generator.d.ts +20 -0
- package/dist/generators/sql-generator.d.ts.map +1 -0
- package/dist/generators/sql-generator.js +83 -0
- package/dist/generators/sql-generator.js.map +1 -0
- package/dist/state/state-manager.d.ts +95 -0
- package/dist/state/state-manager.d.ts.map +1 -0
- package/dist/state/state-manager.js +236 -0
- package/dist/state/state-manager.js.map +1 -0
- package/dist/types/state-file.d.ts +124 -0
- package/dist/types/state-file.d.ts.map +1 -0
- package/dist/types/state-file.js +79 -0
- package/dist/types/state-file.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.DatabaseConnection = void 0;
|
|
27
|
+
const sql = __importStar(require("mssql"));
|
|
28
|
+
const dotenv = __importStar(require("dotenv"));
|
|
29
|
+
// Load environment variables
|
|
30
|
+
dotenv.config();
|
|
31
|
+
/**
|
|
32
|
+
* Database connection manager - NO MJ DEPENDENCIES
|
|
33
|
+
*/
|
|
34
|
+
class DatabaseConnection {
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.config = {
|
|
37
|
+
server: config.server,
|
|
38
|
+
database: config.database,
|
|
39
|
+
user: config.user,
|
|
40
|
+
password: config.password,
|
|
41
|
+
port: config.port || 1433,
|
|
42
|
+
options: {
|
|
43
|
+
encrypt: config.encrypt !== undefined ? config.encrypt : true,
|
|
44
|
+
trustServerCertificate: config.trustServerCertificate !== undefined ? config.trustServerCertificate : false,
|
|
45
|
+
enableArithAbort: true,
|
|
46
|
+
},
|
|
47
|
+
pool: {
|
|
48
|
+
max: 10,
|
|
49
|
+
min: 2,
|
|
50
|
+
idleTimeoutMillis: 30000,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get connection from environment variables
|
|
56
|
+
*/
|
|
57
|
+
static fromEnv() {
|
|
58
|
+
const config = {
|
|
59
|
+
server: process.env.DB_SERVER || 'localhost',
|
|
60
|
+
database: process.env.DB_DATABASE || 'master',
|
|
61
|
+
user: process.env.DB_USER,
|
|
62
|
+
password: process.env.DB_PASSWORD,
|
|
63
|
+
port: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 1433,
|
|
64
|
+
encrypt: process.env.DB_ENCRYPT === 'true',
|
|
65
|
+
trustServerCertificate: process.env.DB_TRUST_SERVER_CERTIFICATE === 'true',
|
|
66
|
+
};
|
|
67
|
+
return new DatabaseConnection(config);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get connection pool
|
|
71
|
+
*/
|
|
72
|
+
async getConnection() {
|
|
73
|
+
if (this.pool && this.pool.connected) {
|
|
74
|
+
return this.pool;
|
|
75
|
+
}
|
|
76
|
+
this.pool = new sql.ConnectionPool(this.config);
|
|
77
|
+
await this.pool.connect();
|
|
78
|
+
return this.pool;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Execute query with retry logic
|
|
82
|
+
*/
|
|
83
|
+
async query(queryText, params) {
|
|
84
|
+
let lastError;
|
|
85
|
+
const maxRetries = 3;
|
|
86
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
87
|
+
try {
|
|
88
|
+
const pool = await this.getConnection();
|
|
89
|
+
const request = pool.request();
|
|
90
|
+
if (params) {
|
|
91
|
+
for (const [key, value] of Object.entries(params)) {
|
|
92
|
+
request.input(key, value);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const result = await request.query(queryText);
|
|
96
|
+
return result.recordset;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
lastError = error;
|
|
100
|
+
if (lastError.message.includes('Incorrect syntax')) {
|
|
101
|
+
throw lastError;
|
|
102
|
+
}
|
|
103
|
+
if (attempt < maxRetries) {
|
|
104
|
+
await this.sleep(Math.pow(2, attempt) * 100);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
throw lastError || new Error('Query failed after retries');
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Close connection
|
|
112
|
+
*/
|
|
113
|
+
async close() {
|
|
114
|
+
if (this.pool) {
|
|
115
|
+
await this.pool.close();
|
|
116
|
+
this.pool = undefined;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Test connection
|
|
121
|
+
*/
|
|
122
|
+
async test() {
|
|
123
|
+
try {
|
|
124
|
+
await this.query('SELECT 1 as Test');
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
sleep(ms) {
|
|
132
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
exports.DatabaseConnection = DatabaseConnection;
|
|
136
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/database/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAC7B,+CAAiC;AAEjC,6BAA6B;AAC7B,MAAM,CAAC,MA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AAC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBACnD,MAAM,SAAS,CAAC;gBAClB,CAAC;gBAED,IAAI,OAAO,GAAG,UAAU,EAAE,CAAC;oBACzB,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,GAAG,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;QACH,CAAC;QAED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACd,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;YACxB,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC;QACxB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YACrC,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IACzD,CAAC;CACF;AAnHD,gDAmHC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DatabaseConnection } from './connection.js';
|
|
2
|
+
export interface TableInfo {
|
|
3
|
+
schema: string;
|
|
4
|
+
table: string;
|
|
5
|
+
rowCount: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ColumnInfo {
|
|
8
|
+
name: string;
|
|
9
|
+
dataType: string;
|
|
10
|
+
maxLength?: number;
|
|
11
|
+
precision?: number;
|
|
12
|
+
scale?: number;
|
|
13
|
+
isNullable: boolean;
|
|
14
|
+
defaultValue?: string;
|
|
15
|
+
isIdentity: boolean;
|
|
16
|
+
isComputed: boolean;
|
|
17
|
+
isPrimaryKey: boolean;
|
|
18
|
+
isForeignKey: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ForeignKeyInfo {
|
|
21
|
+
name: string;
|
|
22
|
+
column: string;
|
|
23
|
+
referencedSchema: string;
|
|
24
|
+
referencedTable: string;
|
|
25
|
+
referencedColumn: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ExtendedPropertyInfo {
|
|
28
|
+
objectType: 'TABLE' | 'COLUMN';
|
|
29
|
+
objectName: string;
|
|
30
|
+
value: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Database introspection - pure SQL Server, no MJ dependencies
|
|
34
|
+
*/
|
|
35
|
+
export declare class DatabaseIntrospector {
|
|
36
|
+
private connection;
|
|
37
|
+
constructor(connection: DatabaseConnection);
|
|
38
|
+
/**
|
|
39
|
+
* Get all tables in database
|
|
40
|
+
*/
|
|
41
|
+
getTables(schemas?: string[], excludeSchemas?: string[]): Promise<TableInfo[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Get columns for a table
|
|
44
|
+
*/
|
|
45
|
+
getColumns(schema: string, table: string): Promise<ColumnInfo[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Get foreign keys for a table
|
|
48
|
+
*/
|
|
49
|
+
getForeignKeys(schema: string, table: string): Promise<ForeignKeyInfo[]>;
|
|
50
|
+
/**
|
|
51
|
+
* Get extended properties (existing descriptions)
|
|
52
|
+
*/
|
|
53
|
+
getExtendedProperties(schema: string, table: string): Promise<ExtendedPropertyInfo[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Sample data from table
|
|
56
|
+
*/
|
|
57
|
+
sampleData(schema: string, table: string, limit?: number): Promise<Record<string, any>[]>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=introspection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspection.d.ts","sourceRo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CAAC;IAgCtE;;OAEG;IACG,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAuB9E;;OAEG;IACG,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,EAAE,CAAC;IAkB3F;;OAEG;IACG,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;CAIpG"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DatabaseIntrospector = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Database introspection - pure SQL Server, no MJ dependencies
|
|
6
|
+
*/
|
|
7
|
+
class DatabaseIntrospector {
|
|
8
|
+
constructor(connection) {
|
|
9
|
+
this.connection = connection;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get all tables in database
|
|
13
|
+
*/
|
|
14
|
+
async getTables(schemas, excludeSchemas) {
|
|
15
|
+
let where = "WHERE t.type = 'U'";
|
|
16
|
+
if (schemas && schemas.length > 0) {
|
|
17
|
+
const schemaList = schemas.map(s => `'${s.replace(/'/g, "''")}'`).join(',');
|
|
18
|
+
where += ` AND s.name IN (${schemaList})`;
|
|
19
|
+
}
|
|
20
|
+
if (excludeSchemas && excludeSchemas.length > 0) {
|
|
21
|
+
const excludeList = excludeSchemas.map(s => `'${s.replace(/'/g, "''")}'`).join(',');
|
|
22
|
+
where += ` AND s.name NOT IN (${excludeList})`;
|
|
23
|
+
}
|
|
24
|
+
where += ` AND s.name NOT IN ('sys', 'INFORMATION_SCHEMA')`;
|
|
25
|
+
const query = `
|
|
26
|
+
SELECT
|
|
27
|
+
s.name AS [schema],
|
|
28
|
+
t.name AS [table],
|
|
29
|
+
SUM(p.rows) AS rowCount
|
|
30
|
+
FROM sys.tables t
|
|
31
|
+
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
|
|
32
|
+
LEFT JOIN sys.partitions p ON t.object_id = p.object_id AND p.index_id IN (0, 1)
|
|
33
|
+
${where}
|
|
34
|
+
GROUP BY s.name, t.name
|
|
35
|
+
ORDER BY s.name, t.name
|
|
36
|
+
`;
|
|
37
|
+
return await this.connection.query(query);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get columns for a table
|
|
41
|
+
*/
|
|
42
|
+
async getColumns(schema, table) {
|
|
43
|
+
const query = `
|
|
44
|
+
SELECT
|
|
45
|
+
c.name,
|
|
46
|
+
t.name AS dataType,
|
|
47
|
+
c.max_length AS maxLength,
|
|
48
|
+
c.precision,
|
|
49
|
+
c.scale,
|
|
50
|
+
c.is_nullable AS isNullable,
|
|
51
|
+
OBJECT_DEFINITION(c.default_object_id) AS defaultValue,
|
|
52
|
+
c.is_identity AS isIdentity,
|
|
53
|
+
c.is_computed AS isComputed,
|
|
54
|
+
CASE WHEN pk.column_id IS NOT NULL THEN 1 ELSE 0 END AS isPrimaryKey,
|
|
55
|
+
CASE WHEN fk.parent_column_id IS NOT NULL THEN 1 ELSE 0 END AS isForeignKey
|
|
56
|
+
FROM sys.columns c
|
|
57
|
+
INNER JOIN sys.types t ON c.user_type_id = t.user_type_id
|
|
58
|
+
INNER JOIN sys.tables tbl ON c.object_id = tbl.object_id
|
|
59
|
+
INNER JOIN sys.schemas s ON tbl.schema_id = s.schema_id
|
|
60
|
+
LEFT JOIN (
|
|
61
|
+
SELECT ic.object_id, ic.column_id
|
|
62
|
+
FROM sys.index_columns ic
|
|
63
|
+
INNER JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
|
|
64
|
+
WHERE i.is_primary_key = 1
|
|
65
|
+
) pk ON c.object_id = pk.object_id AND c.column_id = pk.column_id
|
|
66
|
+
LEFT JOIN sys.foreign_key_columns fk ON c.object_id = fk.parent_object_id AND c.column_id = fk.parent_column_id
|
|
67
|
+
WHERE s.name = @schema AND tbl.name = @table
|
|
68
|
+
ORDER BY c.column_id
|
|
69
|
+
`;
|
|
70
|
+
return await this.connection.query(query, { schema, table });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get foreign keys for a table
|
|
74
|
+
*/
|
|
75
|
+
async getForeignKeys(schema, table) {
|
|
76
|
+
const query = `
|
|
77
|
+
SELECT
|
|
78
|
+
fk.name,
|
|
79
|
+
c1.name AS [column],
|
|
80
|
+
s2.name AS referencedSchema,
|
|
81
|
+
t2.name AS referencedTable,
|
|
82
|
+
c2.name AS referencedColumn
|
|
83
|
+
FROM sys.foreign_keys fk
|
|
84
|
+
INNER JOIN sys.tables t1 ON fk.parent_object_id = t1.object_id
|
|
85
|
+
INNER JOIN sys.schemas s1 ON t1.schema_id = s1.schema_id
|
|
86
|
+
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
|
|
87
|
+
INNER JOIN sys.columns c1 ON fkc.parent_object_id = c1.object_id AND fkc.parent_column_id = c1.column_id
|
|
88
|
+
INNER JOIN sys.columns c2 ON fkc.referenced_object_id = c2.object_id AND fkc.referenced_column_id = c2.column_id
|
|
89
|
+
INNER JOIN sys.tables t2 ON fkc.referenced_object_id = t2.object_id
|
|
90
|
+
INNER JOIN sys.schemas s2 ON t2.schema_id = s2.schema_id
|
|
91
|
+
WHERE s1.name = @schema AND t1.name = @table
|
|
92
|
+
ORDER BY fk.name
|
|
93
|
+
`;
|
|
94
|
+
return await this.connection.query(query, { schema, table });
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get extended properties (existing descriptions)
|
|
98
|
+
*/
|
|
99
|
+
async getExtendedProperties(schema, table) {
|
|
100
|
+
const query = `
|
|
101
|
+
SELECT
|
|
102
|
+
CASE WHEN ep.minor_id = 0 THEN 'TABLE' ELSE 'COLUMN' END AS objectType,
|
|
103
|
+
COALESCE(c.name, t.name) AS objectName,
|
|
104
|
+
CAST(ep.value AS NVARCHAR(MAX)) AS value
|
|
105
|
+
FROM sys.extended_properties ep
|
|
106
|
+
INNER JOIN sys.tables t ON ep.major_id = t.object_id
|
|
107
|
+
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
|
|
108
|
+
LEFT JOIN sys.columns c ON ep.major_id = c.object_id AND ep.minor_id = c.column_id
|
|
109
|
+
WHERE s.name = @schema
|
|
110
|
+
AND t.name = @table
|
|
111
|
+
AND ep.name = 'MS_Description'
|
|
112
|
+
`;
|
|
113
|
+
return await this.connection.query(query, { schema, table });
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Sample data from table
|
|
117
|
+
*/
|
|
118
|
+
async sampleData(schema, table, limit = 10) {
|
|
119
|
+
const query = `SELECT TOP ${limit} * FROM [${schema}].[${table}]`;
|
|
120
|
+
return await this.connection.query(query);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.DatabaseIntrospector = DatabaseIntrospector;
|
|
124
|
+
//# sourceMappingURL=introspection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"introspection.js","sourceRoot":"","sources":["../../src/database/introspection.ts"],"names":[],"mappings":";;;AAoCA;;GAEG;AACH,MAAa,oBAAoB;IAC/B,YAAoB,UAA8B;QAA9B,eAAU,GAAV,UAAU,CAAoB;IAAG,CAAC;IAEtD;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,OAAkB,EAAE,cAAyB;QAC3D,IAAI,KAAK,GAAG,oBAAoB,CAAC;QAEjC,IAAI,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAClC,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAA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AE,KAAK,EAAE,CAAC,CAAC;IACrF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU,CAAC,MAAc,EAAE,KAAa,EAAE,QAAgB,EAAE;QAChE,MAAM,KAAK,GAAG,cAAc,KAAK,YAAY,MAAM,MAAM,KAAK,GAAG,CAAC;QAClE,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;CACF;AA9HD,oDA8HC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-generator.d.ts","sourceRoot":"","sources":["../../src/generators/markdown-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;CA8HnC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MarkdownGenerator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generate Markdown documentation
|
|
6
|
+
*/
|
|
7
|
+
class MarkdownGenerator {
|
|
8
|
+
generate(state) {
|
|
9
|
+
const lines = [];
|
|
10
|
+
lines.push(`# Database Documentation: ${state.database.database}`);
|
|
11
|
+
lines.push('');
|
|
12
|
+
lines.push(`**Server**: ${state.database.server}`);
|
|
13
|
+
lines.push(`**Generated**: ${new Date().toISOString()}`);
|
|
14
|
+
lines.push('');
|
|
15
|
+
if (state.seedContext) {
|
|
16
|
+
lines.push('## Overview');
|
|
17
|
+
if (state.seedContext.overallPurpose) {
|
|
18
|
+
lines.push(state.seedContext.overallPurpose);
|
|
19
|
+
}
|
|
20
|
+
if (state.seedContext.businessDomains) {
|
|
21
|
+
lines.push('');
|
|
22
|
+
lines.push('**Business Domains**: ' + state.seedContext.businessDomains.join(', '));
|
|
23
|
+
}
|
|
24
|
+
lines.push('');
|
|
25
|
+
}
|
|
26
|
+
lines.push('## Schemas');
|
|
27
|
+
lines.push('');
|
|
28
|
+
for (const [schemaName, schema] of Object.entries(state.schemas)) {
|
|
29
|
+
lines.push(`### ${schemaName}`);
|
|
30
|
+
lines.push('');
|
|
31
|
+
if (schema.description) {
|
|
32
|
+
lines.push(schema.description);
|
|
33
|
+
lines.push('');
|
|
34
|
+
}
|
|
35
|
+
if (schema.businessDomain) {
|
|
36
|
+
lines.push(`**Domain**: ${schema.businessDomain}`);
|
|
37
|
+
lines.push('');
|
|
38
|
+
}
|
|
39
|
+
lines.push('#### Tables');
|
|
40
|
+
lines.push('');
|
|
41
|
+
for (const [tableName, table] of Object.entries(schema.tables)) {
|
|
42
|
+
lines.push(`##### ${tableName}`);
|
|
43
|
+
lines.push('');
|
|
44
|
+
if (table.finalDescription) {
|
|
45
|
+
lines.push(table.finalDescription);
|
|
46
|
+
lines.push('');
|
|
47
|
+
}
|
|
48
|
+
if (table.aiGenerated?.businessDomain) {
|
|
49
|
+
lines.push(`**Domain**: ${table.aiGenerated.businessDomain}`);
|
|
50
|
+
lines.push('');
|
|
51
|
+
}
|
|
52
|
+
if (table.userNotes) {
|
|
53
|
+
lines.push(`**Notes**: ${table.userNotes}`);
|
|
54
|
+
lines.push('');
|
|
55
|
+
}
|
|
56
|
+
// Columns table
|
|
57
|
+
const hasColumns = Object.keys(table.columns).length > 0;
|
|
58
|
+
if (hasColumns) {
|
|
59
|
+
lines.push('**Columns**:');
|
|
60
|
+
lines.push('');
|
|
61
|
+
lines.push('| Column | Description |');
|
|
62
|
+
lines.push('|--------|-------------|');
|
|
63
|
+
for (const [columnName, column] of Object.entries(table.columns)) {
|
|
64
|
+
const desc = column.finalDescription || '';
|
|
65
|
+
lines.push(`| ${columnName} | ${desc} |`);
|
|
66
|
+
}
|
|
67
|
+
lines.push('');
|
|
68
|
+
}
|
|
69
|
+
// Relationships
|
|
70
|
+
if (table.aiGenerated?.relationships && table.aiGenerated.relationships.length > 0) {
|
|
71
|
+
lines.push('**Relationships**:');
|
|
72
|
+
lines.push('');
|
|
73
|
+
for (const rel of table.aiGenerated.relationships) {
|
|
74
|
+
lines.push(`- ${rel.type === 'parent' ? '→' : '←'} ${rel.table}: ${rel.description}`);
|
|
75
|
+
}
|
|
76
|
+
lines.push('');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// Statistics
|
|
81
|
+
lines.push('---');
|
|
82
|
+
lines.push('');
|
|
83
|
+
lines.push('## Statistics');
|
|
84
|
+
lines.push('');
|
|
85
|
+
const totalSchemas = Object.keys(state.schemas).length;
|
|
86
|
+
const totalTables = Object.values(state.schemas).reduce((sum, s) => sum + Object.keys(s.tables).length, 0);
|
|
87
|
+
const totalColumns = Object.values(state.schemas).reduce((sum, s) => sum + Object.values(s.tables).reduce((s2, t) => s2 + Object.keys(t.columns).length, 0), 0);
|
|
88
|
+
lines.push(`- **Schemas**: ${totalSchemas}`);
|
|
89
|
+
lines.push(`- **Tables**: ${totalTables}`);
|
|
90
|
+
lines.push(`- **Columns**: ${totalColumns}`);
|
|
91
|
+
if (state.runHistory.length > 0) {
|
|
92
|
+
const lastRun = state.runHistory[state.runHistory.length - 1];
|
|
93
|
+
lines.push('');
|
|
94
|
+
lines.push(`**Last Run**: ${lastRun.timestamp}`);
|
|
95
|
+
if (lastRun.tokensUsed) {
|
|
96
|
+
lines.push(`**Tokens Used**: ${lastRun.tokensUsed.toLocaleString()}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
lines.push('');
|
|
100
|
+
lines.push('---');
|
|
101
|
+
lines.push('*Generated by SQL Server Documentation Generator*');
|
|
102
|
+
return lines.join('\n');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.MarkdownGenerator = MarkdownGenerator;
|
|
106
|
+
//# sourceMappingURL=markdown-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-generator.js","sourceR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AAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC9D,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACf,KAAK,CAAC,IAAI,CAAC,iBAAiB,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;YACjD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;gBACvB,KAAK,CAAC,IAAI,CAAC,oBAAoB,OAAO,CAAC,UAAU,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,KAAK,CAAC,IAAI,CAAC,mDAAmD,CAAC,CAAC;QAEhE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CACF;AA/HD,8CA+HC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StateFile } from '../types/state-file.js';
|
|
2
|
+
export interface SQLGeneratorOptions {
|
|
3
|
+
approvedOnly?: boolean;
|
|
4
|
+
confidenceThreshold?: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Generate SQL scripts with sp_addextendedproperty statements
|
|
8
|
+
*/
|
|
9
|
+
export declare class SQLGenerator {
|
|
10
|
+
generate(state: StateFile, options?: SQLGeneratorOptions): string;
|
|
11
|
+
/**
|
|
12
|
+
* Generate sp_addextendedproperty for table
|
|
13
|
+
*/
|
|
14
|
+
private generateTableProperty;
|
|
15
|
+
/**
|
|
16
|
+
* Generate sp_addextendedproperty for column
|
|
17
|
+
*/
|
|
18
|
+
private generateColumnProperty;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=sql-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-generator.d.ts","sourceRoot":"","sources":["../../src/generators/sql-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,WAAW,mBAAmB;IAClC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,QAAQ,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,GAAE,mBAAwB,GAAG,MAAM;IA4DrE;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAY7B;;OAEG;IACH,OAAO,CAAC,sBAAsB;CAgB/B"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SQLGenerator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Generate SQL scripts with sp_addextendedproperty statements
|
|
6
|
+
*/
|
|
7
|
+
class SQLGenerator {
|
|
8
|
+
generate(state, options = {}) {
|
|
9
|
+
const lines = [];
|
|
10
|
+
lines.push('-- Generated by SQL Server Documentation Generator');
|
|
11
|
+
lines.push(`-- Database: ${state.database.server}.${state.database.database}`);
|
|
12
|
+
lines.push(`-- Generated: ${new Date().toISOString()}`);
|
|
13
|
+
lines.push('');
|
|
14
|
+
lines.push('BEGIN TRANSACTION;');
|
|
15
|
+
lines.push('');
|
|
16
|
+
let count = 0;
|
|
17
|
+
for (const [schemaName, schema] of Object.entries(state.schemas)) {
|
|
18
|
+
for (const [tableName, table] of Object.entries(schema.tables)) {
|
|
19
|
+
// Skip if not approved (when approvedOnly is true)
|
|
20
|
+
if (options.approvedOnly && !table.userApproved) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
// Skip if confidence too low
|
|
24
|
+
if (options.confidenceThreshold && table.aiGenerated) {
|
|
25
|
+
if (table.aiGenerated.confidence < options.confidenceThreshold) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
// Table description
|
|
30
|
+
if (table.finalDescription) {
|
|
31
|
+
lines.push(this.generateTableProperty(schemaName, tableName, table.finalDescription));
|
|
32
|
+
count++;
|
|
33
|
+
}
|
|
34
|
+
// Column descriptions
|
|
35
|
+
for (const [columnName, column] of Object.entries(table.columns)) {
|
|
36
|
+
// Skip if confidence too low
|
|
37
|
+
if (options.confidenceThreshold && column.aiGenerated) {
|
|
38
|
+
if (column.aiGenerated.confidence < options.confidenceThreshold) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (column.finalDescription) {
|
|
43
|
+
lines.push(this.generateColumnProperty(schemaName, tableName, columnName, column.finalDescription));
|
|
44
|
+
count++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
lines.push('');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
lines.push('COMMIT TRANSACTION;');
|
|
51
|
+
lines.push('');
|
|
52
|
+
lines.push(`-- Total properties: ${count}`);
|
|
53
|
+
return lines.join('\n');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Generate sp_addextendedproperty for table
|
|
57
|
+
*/
|
|
58
|
+
generateTableProperty(schema, table, description) {
|
|
59
|
+
const escapedDesc = description.replace(/'/g, "''");
|
|
60
|
+
return `
|
|
61
|
+
-- ${schema}.${table}
|
|
62
|
+
EXEC sp_addextendedproperty
|
|
63
|
+
@name = N'MS_Description',
|
|
64
|
+
@value = N'${escapedDesc}',
|
|
65
|
+
@level0type = N'SCHEMA', @level0name = N'${schema}',
|
|
66
|
+
@level1type = N'TABLE', @level1name = N'${table}';`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generate sp_addextendedproperty for column
|
|
70
|
+
*/
|
|
71
|
+
generateColumnProperty(schema, table, column, description) {
|
|
72
|
+
const escapedDesc = description.replace(/'/g, "''");
|
|
73
|
+
return `
|
|
74
|
+
EXEC sp_addextendedproperty
|
|
75
|
+
@name = N'MS_Description',
|
|
76
|
+
@value = N'${escapedDesc}',
|
|
77
|
+
@level0type = N'SCHEMA', @level0name = N'${schema}',
|
|
78
|
+
@level1type = N'TABLE', @level1name = N'${table}',
|
|
79
|
+
@level2type = N'COLUMN', @level2name = N'${column}';`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.SQLGenerator = SQLGenerator;
|
|
83
|
+
//# sourceMappingURL=sql-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sql-generator.js","sourceRoot":"","sources":["../../src/generators/sql-generator.ts"],"names":[],"mappings":";;;AAOA;;GAEG;AACH,MAAa,YAAY;IACvB,QAAQ,CAAC,KAAgB,EAAE,UAA+B,EAAE;QAC1D,MAAM,KAAK,GAAa,EAAE,CAAC;QAE3B,KAAK,CAAC,IAAI,CAAC,oDAAoD,CAAC,CAAC;QACjE,KAAK,CAAC,IAAI,CAAC,gBAAgB,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC/E,KAAK,CAAC,IAAI,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;QACxD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACjC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAEf,IAAI,KAAK,GAAG,CAAC,CAAC;QAEd,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACjE,KAAK,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC/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