drizzle-docs-generator 0.3.0 → 0.4.1
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/README.ja.md +27 -39
- package/README.md +27 -39
- package/dist/cli/index.js +24 -33
- package/dist/cli/index.js.map +1 -1
- package/dist/formatter/markdown.d.ts +8 -1
- package/dist/formatter/markdown.d.ts.map +1 -1
- package/dist/formatter/markdown.js +10 -1
- package/dist/formatter/markdown.js.map +1 -1
- package/dist/generator/common.d.ts +14 -5
- package/dist/generator/common.d.ts.map +1 -1
- package/dist/generator/common.js +22 -12
- package/dist/generator/common.js.map +1 -1
- package/dist/index.d.ts +14 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -25
- package/dist/index.js.map +1 -1
- package/dist/parser/comments.js +55 -50
- package/dist/parser/comments.js.map +1 -1
- package/dist/test-utils/cli-runner.d.ts +0 -1
- package/dist/test-utils/cli-runner.d.ts.map +1 -1
- package/dist/test-utils/dbml-validator.d.ts +0 -8
- package/dist/test-utils/dbml-validator.d.ts.map +1 -1
- package/dist/types.d.ts +0 -20
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/adapter/index.d.ts +0 -10
- package/dist/adapter/index.d.ts.map +0 -1
- package/dist/formatter/index.d.ts +0 -7
- package/dist/formatter/index.d.ts.map +0 -1
- package/dist/generator/index.d.ts +0 -16
- package/dist/generator/index.d.ts.map +0 -1
- package/dist/parser/index.d.ts +0 -5
- package/dist/parser/index.d.ts.map +0 -1
- package/dist/test-utils/index.d.ts +0 -7
- package/dist/test-utils/index.d.ts.map +0 -1
package/dist/parser/comments.js
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import { readFileSync as
|
|
3
|
-
import { join as
|
|
1
|
+
import * as o from "typescript";
|
|
2
|
+
import { readFileSync as x, statSync as h, readdirSync as b } from "node:fs";
|
|
3
|
+
import { join as C } from "node:path";
|
|
4
4
|
function p(t) {
|
|
5
|
-
const n =
|
|
5
|
+
const n = h(t);
|
|
6
6
|
if (n.isFile())
|
|
7
7
|
return t.endsWith(".ts") ? [t] : [];
|
|
8
8
|
if (n.isDirectory()) {
|
|
9
|
-
const
|
|
10
|
-
for (const e of
|
|
11
|
-
const
|
|
12
|
-
e.isDirectory() ?
|
|
9
|
+
const s = [], i = b(t, { withFileTypes: !0 });
|
|
10
|
+
for (const e of i) {
|
|
11
|
+
const r = C(t, e.name);
|
|
12
|
+
e.isDirectory() ? s.push(...p(r)) : e.isFile() && e.name.endsWith(".ts") && !e.name.endsWith(".test.ts") && s.push(r);
|
|
13
13
|
}
|
|
14
|
-
return
|
|
14
|
+
return s;
|
|
15
15
|
}
|
|
16
16
|
return [];
|
|
17
17
|
}
|
|
18
18
|
function L(t) {
|
|
19
|
-
const n = { tables: {} },
|
|
20
|
-
for (const
|
|
21
|
-
const e =
|
|
22
|
-
d(
|
|
19
|
+
const n = { tables: {} }, s = p(t);
|
|
20
|
+
for (const i of s) {
|
|
21
|
+
const e = x(i, "utf-8"), r = o.createSourceFile(i, e, o.ScriptTarget.Latest, !0);
|
|
22
|
+
d(r, r, n);
|
|
23
23
|
}
|
|
24
24
|
return n;
|
|
25
25
|
}
|
|
26
|
-
function d(t, n,
|
|
27
|
-
if (
|
|
28
|
-
const
|
|
26
|
+
function d(t, n, s) {
|
|
27
|
+
if (o.isVariableStatement(t)) {
|
|
28
|
+
const i = g(t, n);
|
|
29
29
|
for (const e of t.declarationList.declarations)
|
|
30
|
-
if (
|
|
31
|
-
const
|
|
30
|
+
if (o.isIdentifier(e.name) && e.initializer && o.isCallExpression(e.initializer)) {
|
|
31
|
+
const r = y(
|
|
32
32
|
e.name.text,
|
|
33
33
|
e.initializer,
|
|
34
34
|
n,
|
|
35
|
-
|
|
35
|
+
i
|
|
36
36
|
);
|
|
37
|
-
|
|
37
|
+
r && (s.tables[r.tableName] = r.tableComment);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
40
|
+
o.forEachChild(t, (i) => d(i, n, s));
|
|
41
41
|
}
|
|
42
|
-
function
|
|
42
|
+
function y(t, n, s, i) {
|
|
43
43
|
const e = T(n);
|
|
44
44
|
if (!S(e))
|
|
45
45
|
return;
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
46
|
+
const r = n.arguments[0];
|
|
47
|
+
if (!r || !o.isStringLiteral(r))
|
|
48
48
|
return;
|
|
49
|
-
const c =
|
|
50
|
-
if (
|
|
51
|
-
for (const a of
|
|
52
|
-
if (
|
|
53
|
-
const
|
|
54
|
-
|
|
49
|
+
const c = r.text, l = n.arguments[1], m = {};
|
|
50
|
+
if (l && o.isObjectLiteralExpression(l)) {
|
|
51
|
+
for (const a of l.properties)
|
|
52
|
+
if (o.isPropertyAssignment(a) && o.isIdentifier(a.name)) {
|
|
53
|
+
const f = v(a.initializer), u = g(a, s);
|
|
54
|
+
f && u && (m[f] = { comment: u });
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
return {
|
|
58
58
|
tableName: c,
|
|
59
59
|
tableComment: {
|
|
60
|
-
comment:
|
|
61
|
-
columns:
|
|
60
|
+
comment: i,
|
|
61
|
+
columns: m
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
65
|
function T(t) {
|
|
66
|
-
if (
|
|
66
|
+
if (o.isIdentifier(t.expression))
|
|
67
67
|
return t.expression.text;
|
|
68
|
-
if (
|
|
68
|
+
if (o.isPropertyAccessExpression(t.expression))
|
|
69
69
|
return t.expression.name.text;
|
|
70
70
|
}
|
|
71
71
|
function S(t) {
|
|
@@ -73,39 +73,44 @@ function S(t) {
|
|
|
73
73
|
}
|
|
74
74
|
function v(t) {
|
|
75
75
|
let n = t;
|
|
76
|
-
for (;
|
|
77
|
-
if (
|
|
76
|
+
for (; o.isCallExpression(n); )
|
|
77
|
+
if (o.isPropertyAccessExpression(n.expression))
|
|
78
78
|
n = n.expression.expression;
|
|
79
|
-
else if (
|
|
80
|
-
const
|
|
81
|
-
return
|
|
79
|
+
else if (o.isIdentifier(n.expression)) {
|
|
80
|
+
const s = n.arguments[0];
|
|
81
|
+
return s && o.isStringLiteral(s) ? s.text : void 0;
|
|
82
82
|
} else
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
function
|
|
86
|
-
const
|
|
85
|
+
function g(t, n) {
|
|
86
|
+
const s = n.getFullText(), i = t.getFullStart(), e = o.getLeadingCommentRanges(s, i);
|
|
87
87
|
if (!(!e || e.length === 0)) {
|
|
88
|
-
for (const
|
|
89
|
-
const c =
|
|
88
|
+
for (const r of e) {
|
|
89
|
+
const c = s.slice(r.pos, r.end);
|
|
90
90
|
if (c.startsWith("/**"))
|
|
91
91
|
return D(c);
|
|
92
92
|
}
|
|
93
|
-
for (const
|
|
94
|
-
const c =
|
|
93
|
+
for (const r of e) {
|
|
94
|
+
const c = s.slice(r.pos, r.end);
|
|
95
95
|
if (c.startsWith("//"))
|
|
96
96
|
return c.slice(2).trim();
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
function D(t) {
|
|
101
|
-
const
|
|
102
|
-
`).map((e) => e.replace(/^\s*\*\s?/, "").trim()),
|
|
103
|
-
for (const e of
|
|
101
|
+
const s = t.slice(3, -2).split(`
|
|
102
|
+
`).map((e) => e.replace(/^\s*\*\s?/, "").trim()), i = [];
|
|
103
|
+
for (const e of s) {
|
|
104
104
|
if (e.startsWith("@"))
|
|
105
105
|
break;
|
|
106
|
-
|
|
106
|
+
i.push(e);
|
|
107
107
|
}
|
|
108
|
-
|
|
108
|
+
for (; i.length > 0 && i[i.length - 1] === ""; )
|
|
109
|
+
i.pop();
|
|
110
|
+
for (; i.length > 0 && i[0] === ""; )
|
|
111
|
+
i.shift();
|
|
112
|
+
return i.join(`
|
|
113
|
+
`).trim();
|
|
109
114
|
}
|
|
110
115
|
export {
|
|
111
116
|
L as extractComments
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comments.js","sources":["../../src/parser/comments.ts"],"sourcesContent":["import * as ts from \"typescript\";\nimport { readFileSync, statSync, readdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n/**\n * Comments for a single column\n */\nexport interface ColumnComment {\n comment: string;\n}\n\n/**\n * Comments for a single table\n */\nexport interface TableComment {\n comment?: string;\n columns: Record<string, ColumnComment>;\n}\n\n/**\n * All extracted comments from a schema file\n */\nexport interface SchemaComments {\n tables: Record<string, TableComment>;\n}\n\n/**\n * Get all TypeScript files from a path (file or directory)\n */\nfunction getTypeScriptFiles(sourcePath: string): string[] {\n const stat = statSync(sourcePath);\n\n if (stat.isFile()) {\n return sourcePath.endsWith(\".ts\") ? [sourcePath] : [];\n }\n\n if (stat.isDirectory()) {\n const files: string[] = [];\n const entries = readdirSync(sourcePath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(sourcePath, entry.name);\n if (entry.isDirectory()) {\n files.push(...getTypeScriptFiles(fullPath));\n } else if (entry.isFile() && entry.name.endsWith(\".ts\") && !entry.name.endsWith(\".test.ts\")) {\n files.push(fullPath);\n }\n }\n\n return files;\n }\n\n return [];\n}\n\n/**\n * Extract JSDoc comments from a Drizzle schema source file or directory\n *\n * Parses TypeScript source files and extracts:\n * - JSDoc comments on table definitions (e.g., pgTable, mysqlTable, sqliteTable)\n * - JSDoc comments on column definitions within tables\n *\n * @param sourcePath - Path to the TypeScript schema file or directory\n * @returns Extracted comments organized by table and column\n */\nexport function extractComments(sourcePath: string): SchemaComments {\n const comments: SchemaComments = { tables: {} };\n const files = getTypeScriptFiles(sourcePath);\n\n for (const filePath of files) {\n const sourceCode = readFileSync(filePath, \"utf-8\");\n const sourceFile = ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true);\n\n // Visit all nodes in the source file\n visitNode(sourceFile, sourceFile, comments);\n }\n\n return comments;\n}\n\n/**\n * Recursively visit AST nodes to find table and column definitions\n */\nfunction visitNode(node: ts.Node, sourceFile: ts.SourceFile, comments: SchemaComments): void {\n // Look for variable declarations that define tables\n if (ts.isVariableStatement(node)) {\n const jsDocComment = getJsDocComment(node, sourceFile);\n\n for (const declaration of node.declarationList.declarations) {\n if (\n ts.isIdentifier(declaration.name) &&\n declaration.initializer &&\n ts.isCallExpression(declaration.initializer)\n ) {\n const tableInfo = parseTableDefinition(\n declaration.name.text,\n declaration.initializer,\n sourceFile,\n jsDocComment,\n );\n if (tableInfo) {\n comments.tables[tableInfo.tableName] = tableInfo.tableComment;\n }\n }\n }\n }\n\n ts.forEachChild(node, (child) => visitNode(child, sourceFile, comments));\n}\n\n/**\n * Parse a table definition call expression (e.g., pgTable(\"users\", { ... }))\n */\nfunction parseTableDefinition(\n _variableName: string,\n callExpr: ts.CallExpression,\n sourceFile: ts.SourceFile,\n tableJsDoc: string | undefined,\n): { tableName: string; tableComment: TableComment } | undefined {\n const funcName = getCallExpressionName(callExpr);\n\n // Check if this is a table definition function\n if (!isTableDefinitionFunction(funcName)) {\n return undefined;\n }\n\n // Get table name from first argument\n const tableNameArg = callExpr.arguments[0];\n if (!tableNameArg || !ts.isStringLiteral(tableNameArg)) {\n return undefined;\n }\n const tableName = tableNameArg.text;\n\n // Get column definitions from second argument\n const columnsArg = callExpr.arguments[1];\n const columnComments: Record<string, ColumnComment> = {};\n\n if (columnsArg && ts.isObjectLiteralExpression(columnsArg)) {\n for (const property of columnsArg.properties) {\n if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name)) {\n const columnName = extractColumnName(property.initializer);\n const columnJsDoc = getJsDocComment(property, sourceFile);\n\n if (columnName && columnJsDoc) {\n columnComments[columnName] = { comment: columnJsDoc };\n }\n }\n }\n }\n\n return {\n tableName,\n tableComment: {\n comment: tableJsDoc,\n columns: columnComments,\n },\n };\n}\n\n/**\n * Get the function name from a call expression\n */\nfunction getCallExpressionName(callExpr: ts.CallExpression): string | undefined {\n if (ts.isIdentifier(callExpr.expression)) {\n return callExpr.expression.text;\n }\n if (ts.isPropertyAccessExpression(callExpr.expression)) {\n return callExpr.expression.name.text;\n }\n return undefined;\n}\n\n/**\n * Check if a function name is a table definition function\n */\nfunction isTableDefinitionFunction(funcName: string | undefined): boolean {\n if (!funcName) return false;\n return [\"pgTable\", \"mysqlTable\", \"sqliteTable\"].includes(funcName);\n}\n\n/**\n * Extract the actual column name from a column definition\n * e.g., serial(\"id\") -> \"id\", text(\"name\") -> \"name\"\n */\nfunction extractColumnName(expr: ts.Expression): string | undefined {\n // Handle chained calls like serial(\"id\").primaryKey()\n let current = expr;\n\n while (ts.isCallExpression(current)) {\n if (ts.isPropertyAccessExpression(current.expression)) {\n // This is a method call like .primaryKey(), go deeper\n current = current.expression.expression;\n } else if (ts.isIdentifier(current.expression)) {\n // This is the base call like serial(\"id\")\n const firstArg = current.arguments[0];\n if (firstArg && ts.isStringLiteral(firstArg)) {\n return firstArg.text;\n }\n return undefined;\n } else {\n return undefined;\n }\n }\n\n return undefined;\n}\n\n/**\n * Get JSDoc comment from a node\n */\nfunction getJsDocComment(node: ts.Node, sourceFile: ts.SourceFile): string | undefined {\n const fullText = sourceFile.getFullText();\n const nodeStart = node.getFullStart();\n const leadingComments = ts.getLeadingCommentRanges(fullText, nodeStart);\n\n if (!leadingComments || leadingComments.length === 0) {\n return undefined;\n }\n\n // Find JSDoc comment (starts with /**)\n for (const comment of leadingComments) {\n const commentText = fullText.slice(comment.pos, comment.end);\n if (commentText.startsWith(\"/**\")) {\n return parseJsDocComment(commentText);\n }\n }\n\n // Fall back to single-line comments\n for (const comment of leadingComments) {\n const commentText = fullText.slice(comment.pos, comment.end);\n if (commentText.startsWith(\"//\")) {\n return commentText.slice(2).trim();\n }\n }\n\n return undefined;\n}\n\n/**\n * Parse JSDoc comment text to extract the description\n */\nfunction parseJsDocComment(commentText: string): string {\n // Remove /** and */\n let text = commentText.slice(3, -2);\n\n // Split into lines and process\n const lines = text.split(\"\\n\").map((line) => {\n // Remove leading * and whitespace\n return line.replace(/^\\s*\\*\\s?/, \"\").trim();\n });\n\n // Filter out @tags and empty lines at start/end\n const contentLines: string[] = [];\n for (const line of lines) {\n // Stop at first @tag\n if (line.startsWith(\"@\")) {\n break;\n }\n contentLines.push(line);\n }\n\n // Join and trim\n return contentLines.join(\" \").trim();\n}\n"],"names":["getTypeScriptFiles","sourcePath","stat","statSync","files","entries","readdirSync","entry","fullPath","join","extractComments","comments","filePath","sourceCode","readFileSync","sourceFile","ts","visitNode","node","jsDocComment","getJsDocComment","declaration","tableInfo","parseTableDefinition","child","_variableName","callExpr","tableJsDoc","funcName","getCallExpressionName","isTableDefinitionFunction","tableNameArg","tableName","columnsArg","columnComments","property","columnName","extractColumnName","columnJsDoc","expr","current","firstArg","fullText","nodeStart","leadingComments","comment","commentText","parseJsDocComment","lines","line","contentLines"],"mappings":";;;AA6BA,SAASA,EAAmBC,GAA8B;AACxD,QAAMC,IAAOC,EAASF,CAAU;AAEhC,MAAIC,EAAK;AACP,WAAOD,EAAW,SAAS,KAAK,IAAI,CAACA,CAAU,IAAI,CAAA;AAGrD,MAAIC,EAAK,eAAe;AACtB,UAAME,IAAkB,CAAA,GAClBC,IAAUC,EAAYL,GAAY,EAAE,eAAe,IAAM;AAE/D,eAAWM,KAASF,GAAS;AAC3B,YAAMG,IAAWC,EAAKR,GAAYM,EAAM,IAAI;AAC5C,MAAIA,EAAM,gBACRH,EAAM,KAAK,GAAGJ,EAAmBQ,CAAQ,CAAC,IACjCD,EAAM,OAAA,KAAYA,EAAM,KAAK,SAAS,KAAK,KAAK,CAACA,EAAM,KAAK,SAAS,UAAU,KACxFH,EAAM,KAAKI,CAAQ;AAAA,IAEvB;AAEA,WAAOJ;AAAA,EACT;AAEA,SAAO,CAAA;AACT;AAYO,SAASM,EAAgBT,GAAoC;AAClE,QAAMU,IAA2B,EAAE,QAAQ,GAAC,GACtCP,IAAQJ,EAAmBC,CAAU;AAE3C,aAAWW,KAAYR,GAAO;AAC5B,UAAMS,IAAaC,EAAaF,GAAU,OAAO,GAC3CG,IAAaC,EAAG,iBAAiBJ,GAAU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eAAOA,EAAY,MAAM,CAAC,EAAE,KAAA;AAAA,IAEhC;AAAA;AAGF;AAKA,SAASC,EAAkBD,GAA6B;AAKtD,QAAME,IAHKF,EAAY,MAAM,GAAG,EAAE,EAGf,MAAM;AAAA,CAAI,EAAE,IAAI,CAACG,MAE3BA,EAAK,QAAQ,aAAa,EAAE,EAAE,KAAA,CACtC,GAGKC,IAAyB,CAAA;AAC/B,aAAWD,KAAQD,GAAO;AAExB,QAAIC,EAAK,WAAW,GAAG;AACrB;AAEF,IAAAC,EAAa,KAAKD,CAAI;AAAA,EACxB;AAGA,SAAOC,EAAa,KAAK,GAAG,EAAE,KAAA;AAChC;"}
|
|
1
|
+
{"version":3,"file":"comments.js","sources":["../../src/parser/comments.ts"],"sourcesContent":["import * as ts from \"typescript\";\nimport { readFileSync, statSync, readdirSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n/**\n * Comments for a single column\n */\nexport interface ColumnComment {\n comment: string;\n}\n\n/**\n * Comments for a single table\n */\nexport interface TableComment {\n comment?: string;\n columns: Record<string, ColumnComment>;\n}\n\n/**\n * All extracted comments from a schema file\n */\nexport interface SchemaComments {\n tables: Record<string, TableComment>;\n}\n\n/**\n * Get all TypeScript files from a path (file or directory)\n */\nfunction getTypeScriptFiles(sourcePath: string): string[] {\n const stat = statSync(sourcePath);\n\n if (stat.isFile()) {\n return sourcePath.endsWith(\".ts\") ? [sourcePath] : [];\n }\n\n if (stat.isDirectory()) {\n const files: string[] = [];\n const entries = readdirSync(sourcePath, { withFileTypes: true });\n\n for (const entry of entries) {\n const fullPath = join(sourcePath, entry.name);\n if (entry.isDirectory()) {\n files.push(...getTypeScriptFiles(fullPath));\n } else if (entry.isFile() && entry.name.endsWith(\".ts\") && !entry.name.endsWith(\".test.ts\")) {\n files.push(fullPath);\n }\n }\n\n return files;\n }\n\n return [];\n}\n\n/**\n * Extract JSDoc comments from a Drizzle schema source file or directory\n *\n * Parses TypeScript source files and extracts:\n * - JSDoc comments on table definitions (e.g., pgTable, mysqlTable, sqliteTable)\n * - JSDoc comments on column definitions within tables\n *\n * @param sourcePath - Path to the TypeScript schema file or directory\n * @returns Extracted comments organized by table and column\n */\nexport function extractComments(sourcePath: string): SchemaComments {\n const comments: SchemaComments = { tables: {} };\n const files = getTypeScriptFiles(sourcePath);\n\n for (const filePath of files) {\n const sourceCode = readFileSync(filePath, \"utf-8\");\n const sourceFile = ts.createSourceFile(filePath, sourceCode, ts.ScriptTarget.Latest, true);\n\n // Visit all nodes in the source file\n visitNode(sourceFile, sourceFile, comments);\n }\n\n return comments;\n}\n\n/**\n * Recursively visit AST nodes to find table and column definitions\n */\nfunction visitNode(node: ts.Node, sourceFile: ts.SourceFile, comments: SchemaComments): void {\n // Look for variable declarations that define tables\n if (ts.isVariableStatement(node)) {\n const jsDocComment = getJsDocComment(node, sourceFile);\n\n for (const declaration of node.declarationList.declarations) {\n if (\n ts.isIdentifier(declaration.name) &&\n declaration.initializer &&\n ts.isCallExpression(declaration.initializer)\n ) {\n const tableInfo = parseTableDefinition(\n declaration.name.text,\n declaration.initializer,\n sourceFile,\n jsDocComment,\n );\n if (tableInfo) {\n comments.tables[tableInfo.tableName] = tableInfo.tableComment;\n }\n }\n }\n }\n\n ts.forEachChild(node, (child) => visitNode(child, sourceFile, comments));\n}\n\n/**\n * Parse a table definition call expression (e.g., pgTable(\"users\", { ... }))\n */\nfunction parseTableDefinition(\n _variableName: string,\n callExpr: ts.CallExpression,\n sourceFile: ts.SourceFile,\n tableJsDoc: string | undefined,\n): { tableName: string; tableComment: TableComment } | undefined {\n const funcName = getCallExpressionName(callExpr);\n\n // Check if this is a table definition function\n if (!isTableDefinitionFunction(funcName)) {\n return undefined;\n }\n\n // Get table name from first argument\n const tableNameArg = callExpr.arguments[0];\n if (!tableNameArg || !ts.isStringLiteral(tableNameArg)) {\n return undefined;\n }\n const tableName = tableNameArg.text;\n\n // Get column definitions from second argument\n const columnsArg = callExpr.arguments[1];\n const columnComments: Record<string, ColumnComment> = {};\n\n if (columnsArg && ts.isObjectLiteralExpression(columnsArg)) {\n for (const property of columnsArg.properties) {\n if (ts.isPropertyAssignment(property) && ts.isIdentifier(property.name)) {\n const columnName = extractColumnName(property.initializer);\n const columnJsDoc = getJsDocComment(property, sourceFile);\n\n if (columnName && columnJsDoc) {\n columnComments[columnName] = { comment: columnJsDoc };\n }\n }\n }\n }\n\n return {\n tableName,\n tableComment: {\n comment: tableJsDoc,\n columns: columnComments,\n },\n };\n}\n\n/**\n * Get the function name from a call expression\n */\nfunction getCallExpressionName(callExpr: ts.CallExpression): string | undefined {\n if (ts.isIdentifier(callExpr.expression)) {\n return callExpr.expression.text;\n }\n if (ts.isPropertyAccessExpression(callExpr.expression)) {\n return callExpr.expression.name.text;\n }\n return undefined;\n}\n\n/**\n * Check if a function name is a table definition function\n */\nfunction isTableDefinitionFunction(funcName: string | undefined): boolean {\n if (!funcName) return false;\n return [\"pgTable\", \"mysqlTable\", \"sqliteTable\"].includes(funcName);\n}\n\n/**\n * Extract the actual column name from a column definition\n * e.g., serial(\"id\") -> \"id\", text(\"name\") -> \"name\"\n */\nfunction extractColumnName(expr: ts.Expression): string | undefined {\n // Handle chained calls like serial(\"id\").primaryKey()\n let current = expr;\n\n while (ts.isCallExpression(current)) {\n if (ts.isPropertyAccessExpression(current.expression)) {\n // This is a method call like .primaryKey(), go deeper\n current = current.expression.expression;\n } else if (ts.isIdentifier(current.expression)) {\n // This is the base call like serial(\"id\")\n const firstArg = current.arguments[0];\n if (firstArg && ts.isStringLiteral(firstArg)) {\n return firstArg.text;\n }\n return undefined;\n } else {\n return undefined;\n }\n }\n\n return undefined;\n}\n\n/**\n * Get JSDoc comment from a node\n */\nfunction getJsDocComment(node: ts.Node, sourceFile: ts.SourceFile): string | undefined {\n const fullText = sourceFile.getFullText();\n const nodeStart = node.getFullStart();\n const leadingComments = ts.getLeadingCommentRanges(fullText, nodeStart);\n\n if (!leadingComments || leadingComments.length === 0) {\n return undefined;\n }\n\n // Find JSDoc comment (starts with /**)\n for (const comment of leadingComments) {\n const commentText = fullText.slice(comment.pos, comment.end);\n if (commentText.startsWith(\"/**\")) {\n return parseJsDocComment(commentText);\n }\n }\n\n // Fall back to single-line comments\n for (const comment of leadingComments) {\n const commentText = fullText.slice(comment.pos, comment.end);\n if (commentText.startsWith(\"//\")) {\n return commentText.slice(2).trim();\n }\n }\n\n return undefined;\n}\n\n/**\n * Parse JSDoc comment text to extract the description\n *\n * Preserves newlines in the output for proper formatting in DBML and Markdown.\n */\nfunction parseJsDocComment(commentText: string): string {\n // Remove /** and */\n let text = commentText.slice(3, -2);\n\n // Split into lines and process\n const lines = text.split(\"\\n\").map((line) => {\n // Remove leading * and whitespace\n return line.replace(/^\\s*\\*\\s?/, \"\").trim();\n });\n\n // Filter out @tags and empty lines at start/end\n const contentLines: string[] = [];\n for (const line of lines) {\n // Stop at first @tag\n if (line.startsWith(\"@\")) {\n break;\n }\n contentLines.push(line);\n }\n\n // Remove trailing empty lines\n while (contentLines.length > 0 && contentLines[contentLines.length - 1] === \"\") {\n contentLines.pop();\n }\n\n // Remove leading empty lines\n while (contentLines.length > 0 && contentLines[0] === \"\") {\n contentLines.shift();\n }\n\n // Join with newlines to preserve formatting\n return contentLines.join(\"\\n\").trim();\n}\n"],"names":["getTypeScriptFiles","sourcePath","stat","statSync","files","entries","readdirSync","entry","fullPath","join","extractComments","comments","filePath","sourceCode","readFileSync","sourceFile","ts","visitNode","node","jsDocComment","getJsDocComment","declaration","tableInfo","parseTableDefinition","child","_variableName","callExpr","tableJsDoc","funcName","getCallExpressionName","isTableDefinitionFunction","tableNameArg","tableName","columnsArg","columnComments","property","columnName","extractColumnName","columnJsDoc","expr","current","firstArg","fullText","nodeStart","leadingComments","comment","commentText","parseJsDocComment","lines","line","contentLines"],"mappings":";;;AA6BA,SAASA,EAAmBC,GAA8B;AACxD,QAAMC,IAAOC,EAASF,CAAU;AAEhC,MAAIC,EAAK;AACP,WAAOD,EAAW,SAAS,KAAK,IAAI,CAACA,CAA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7 +29,6 @@ export declare function runCli(args: string[], options?: {
|
|
|
29
29
|
*/
|
|
30
30
|
export declare function runGenerate(schemaPath: string, dialect: "postgresql" | "mysql" | "sqlite", options?: {
|
|
31
31
|
output?: string;
|
|
32
|
-
relational?: boolean;
|
|
33
32
|
format?: "dbml" | "markdown";
|
|
34
33
|
singleFile?: boolean;
|
|
35
34
|
noErDiagram?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-runner.d.ts","sourceRoot":"","sources":["../../src/test-utils/cli-runner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC1B,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/C,OAAO,CAAC,SAAS,CAAC,CA0CpB;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,GAAG,OAAO,GAAG,QAAQ,EAC1C,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,
|
|
1
|
+
{"version":3,"file":"cli-runner.d.ts","sourceRoot":"","sources":["../../src/test-utils/cli-runner.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH,MAAM,WAAW,SAAS;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;GAMG;AACH,wBAAsB,MAAM,CAC1B,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAO,GAC/C,OAAO,CAAC,SAAS,CAAC,CA0CpB;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAC/B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,YAAY,GAAG,OAAO,GAAG,QAAQ,EAC1C,OAAO,GAAE;IACP,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACT,GACL,OAAO,CAAC,SAAS,CAAC,CAwBpB"}
|
|
@@ -67,14 +67,6 @@ export declare function countTables(dbml: string): number;
|
|
|
67
67
|
* @returns Number of references
|
|
68
68
|
*/
|
|
69
69
|
export declare function countRefs(dbml: string): number;
|
|
70
|
-
/**
|
|
71
|
-
* Check if Markdown output contains a table heading
|
|
72
|
-
*
|
|
73
|
-
* @param markdown - Markdown output string
|
|
74
|
-
* @param tableName - Table name to check
|
|
75
|
-
* @returns true if the table heading exists
|
|
76
|
-
*/
|
|
77
|
-
export declare function hasMarkdownTable(markdown: string, tableName: string): boolean;
|
|
78
70
|
/**
|
|
79
71
|
* Check if Markdown output contains all expected table headings
|
|
80
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dbml-validator.d.ts","sourceRoot":"","sources":["../../src/test-utils/dbml-validator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAAE,EACpB,SAAS,GAAE,GAAG,GAAG,GAAS,GACzB,OAAO,CAET;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,WAAW,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,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,GAAG,GAAG,GAAS,GACzB,OAAO,CAOT;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,GAAE,GAAG,GAAG,GAAS,GAAG,OAAO,CAqB/F;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,GAAG,GAAG,GAAS,GACzB,OAAO,CAqBT;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGhD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG9C;AAiBD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,OAAO,CAEpF;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE3D"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { AnyColumn, Table } from 'drizzle-orm';
|
|
2
1
|
import { SchemaComments } from './parser/comments';
|
|
3
|
-
export type { AnyColumn, Table };
|
|
4
2
|
/**
|
|
5
3
|
* Options for DBML generation
|
|
6
4
|
*/
|
|
@@ -9,8 +7,6 @@ export interface GenerateOptions<TSchema extends Record<string, unknown>> {
|
|
|
9
7
|
schema: TSchema;
|
|
10
8
|
/** Output file path. If provided, DBML will be written to this file */
|
|
11
9
|
out?: string;
|
|
12
|
-
/** If true, uses relations() definitions instead of foreign keys for references */
|
|
13
|
-
relational?: boolean;
|
|
14
10
|
/**
|
|
15
11
|
* Path to the source schema file or directory for extracting JSDoc comments and relations.
|
|
16
12
|
* If a directory is provided, all .ts files will be processed recursively.
|
|
@@ -23,10 +19,6 @@ export interface GenerateOptions<TSchema extends Record<string, unknown>> {
|
|
|
23
19
|
*/
|
|
24
20
|
comments?: SchemaComments;
|
|
25
21
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Supported relation types in DBML
|
|
28
|
-
*/
|
|
29
|
-
export type RelationType = "one-to-one" | "one-to-many" | "many-to-one";
|
|
30
22
|
/**
|
|
31
23
|
* Internal representation of a reference/relationship
|
|
32
24
|
*/
|
|
@@ -39,17 +31,6 @@ export interface GeneratedRef {
|
|
|
39
31
|
onDelete?: string;
|
|
40
32
|
onUpdate?: string;
|
|
41
33
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Column constraint attributes for DBML output
|
|
44
|
-
*/
|
|
45
|
-
export interface ColumnAttributes {
|
|
46
|
-
primaryKey?: boolean;
|
|
47
|
-
notNull?: boolean;
|
|
48
|
-
unique?: boolean;
|
|
49
|
-
increment?: boolean;
|
|
50
|
-
default?: string;
|
|
51
|
-
note?: string;
|
|
52
|
-
}
|
|
53
34
|
/**
|
|
54
35
|
* Supported database types
|
|
55
36
|
*
|
|
@@ -131,7 +112,6 @@ export interface TableDefinition {
|
|
|
131
112
|
}
|
|
132
113
|
/**
|
|
133
114
|
* Relation types for intermediate schema
|
|
134
|
-
* Note: This is more detailed than RelationType used for DBML output
|
|
135
115
|
*/
|
|
136
116
|
export type IntermediateRelationType = "one-to-one" | "one-to-many" | "many-to-one" | "many-to-many";
|
|
137
117
|
/**
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACtE,2EAA2E;IAC3E,MAAM,EAAE,OAAO,CAAC;IAChB,uEAAuE;IACvE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAQD;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,mEAAmE;IACnE,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,QAAQ,EAAE,OAAO,CAAC;IAClB,2DAA2D;IAC3D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,UAAU,EAAE,OAAO,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,OAAO,CAAC;IAChB,0CA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H,MAAM,WAAW,kBAAkB;IACjC,6BAA6B;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,2BAA2B;IAC3B,IAAI,EAAE,wBAAwB,CAAC;IAC/B,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qBAAqB;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kBAAkB;IAClB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,wDAAwD;IACxD,YAAY,EAAE,YAAY,CAAC;IAC3B,wBAAwB;IACxB,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,qCAAqC;IACrC,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,6CAA6C;IAC7C,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB"}
|
package/package.json
CHANGED
package/dist/adapter/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Relation adapters for unifying v0 and v1 relation APIs
|
|
3
|
-
*
|
|
4
|
-
* This module provides adapters that convert both legacy relations() (v0)
|
|
5
|
-
* and modern defineRelations() (v1) to a unified format.
|
|
6
|
-
*/
|
|
7
|
-
export type { RelationAdapter, UnifiedRelation } from './types';
|
|
8
|
-
export { V0RelationAdapter } from './v0-adapter';
|
|
9
|
-
export { V1RelationAdapter } from './v1-adapter';
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapter/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export type { OutputFormatter, FormatterOptions } from './types';
|
|
2
|
-
export type { MermaidFormatterOptions } from './mermaid';
|
|
3
|
-
export type { MarkdownFormatterOptions } from './markdown';
|
|
4
|
-
export { DbmlFormatter } from './dbml';
|
|
5
|
-
export { MarkdownFormatter } from './markdown';
|
|
6
|
-
export { MermaidErDiagramFormatter } from './mermaid';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/formatter/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACjE,YAAY,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AACzD,YAAY,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAG3D,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DBML Generator Module
|
|
3
|
-
*
|
|
4
|
-
* Provides functions to generate DBML from Drizzle ORM schema definitions.
|
|
5
|
-
* Supports PostgreSQL, MySQL, and SQLite dialects.
|
|
6
|
-
*
|
|
7
|
-
* JSDoc comments can be extracted from source files and included as DBML Note clauses.
|
|
8
|
-
* Use the `source` option to specify the schema source file or directory, or pass pre-extracted
|
|
9
|
-
* comments via the `comments` option.
|
|
10
|
-
*/
|
|
11
|
-
export { pgGenerate, PgGenerator } from './pg';
|
|
12
|
-
export { mysqlGenerate, MySqlGenerator } from './mysql';
|
|
13
|
-
export { sqliteGenerate, SqliteGenerator } from './sqlite';
|
|
14
|
-
export { BaseGenerator, writeDbmlFile } from './common';
|
|
15
|
-
export { DbmlBuilder } from '../formatter/dbml-builder';
|
|
16
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/parser/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export { extractComments } from './comments';
|
|
2
|
-
export type { SchemaComments, TableComment, ColumnComment } from './comments';
|
|
3
|
-
export { extractRelations } from './relations';
|
|
4
|
-
export type { ParsedRelation, SchemaRelations } from './relations';
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/parser/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test utilities for integration testing
|
|
3
|
-
*/
|
|
4
|
-
export { runCli, runGenerate } from './cli-runner.js';
|
|
5
|
-
export type { CliResult } from './cli-runner.js';
|
|
6
|
-
export { hasAllTables, hasAllColumns, hasReference, hasIndexes, hasTableNote, countTables, countRefs, } from './dbml-validator.js';
|
|
7
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test-utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EACL,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,WAAW,EACX,SAAS,GACV,MAAM,qBAAqB,CAAC"}
|