drizzle-docs-generator 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.
- package/LICENSE +21 -0
- package/README.ja.md +89 -0
- package/README.md +89 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +69 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/generator/common.d.ts +393 -0
- package/dist/generator/common.d.ts.map +1 -0
- package/dist/generator/common.js +699 -0
- package/dist/generator/common.js.map +1 -0
- package/dist/generator/index.d.ts +15 -0
- package/dist/generator/index.d.ts.map +1 -0
- package/dist/generator/mysql.d.ts +36 -0
- package/dist/generator/mysql.d.ts.map +1 -0
- package/dist/generator/mysql.js +16 -0
- package/dist/generator/mysql.js.map +1 -0
- package/dist/generator/pg.d.ts +48 -0
- package/dist/generator/pg.d.ts.map +1 -0
- package/dist/generator/pg.js +52 -0
- package/dist/generator/pg.js.map +1 -0
- package/dist/generator/sqlite.d.ts +36 -0
- package/dist/generator/sqlite.d.ts.map +1 -0
- package/dist/generator/sqlite.js +16 -0
- package/dist/generator/sqlite.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/comments.d.ts +31 -0
- package/dist/parser/comments.d.ts.map +1 -0
- package/dist/parser/comments.js +113 -0
- package/dist/parser/comments.js.map +1 -0
- package/dist/parser/index.d.ts +5 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/relations.d.ts +34 -0
- package/dist/parser/relations.d.ts.map +1 -0
- package/dist/parser/relations.js +111 -0
- package/dist/parser/relations.js.map +1 -0
- package/dist/test-utils/cli-runner.d.ts +35 -0
- package/dist/test-utils/cli-runner.d.ts.map +1 -0
- package/dist/test-utils/dbml-validator.d.ts +70 -0
- package/dist/test-utils/dbml-validator.d.ts.map +1 -0
- package/dist/test-utils/index.d.ts +7 -0
- package/dist/test-utils/index.d.ts.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sources":["../../src/generator/common.ts"],"sourcesContent":["import {\n type AnyColumn,\n type Table,\n getTableColumns,\n getTableName,\n is,\n Relation,\n One,\n} from \"drizzle-orm\";\nimport type { AnyRelation, TableRelationalConfig } from \"drizzle-orm/relations\";\nimport { PgTable, getTableConfig as getPgTableConfig } from \"drizzle-orm/pg-core\";\n\n/**\n * Legacy v0 Relations type (for backward compatibility with relations())\n * This is a simplified type - the actual structure is more complex\n */\ntype LegacyRelations = {\n table: Table;\n config: Record<string, unknown>;\n};\nimport { MySqlTable, getTableConfig as getMySqlTableConfig } from \"drizzle-orm/mysql-core\";\nimport { SQLiteTable, getTableConfig as getSqliteTableConfig } from \"drizzle-orm/sqlite-core\";\nimport { writeFileSync, mkdirSync } from \"node:fs\";\nimport { dirname, resolve } from \"node:path\";\nimport type { GeneratedRef, GenerateOptions } from \"../types\";\nimport { extractComments, type SchemaComments } from \"../parser/comments\";\nimport { extractRelations, type SchemaRelations } from \"../parser/relations\";\n\n/**\n * Simple DBML string builder\n */\nexport class DbmlBuilder {\n private lines: string[] = [];\n private indentLevel = 0;\n\n /**\n * Increase the indentation level by one\n * @returns This instance for method chaining\n */\n indent(): this {\n this.indentLevel++;\n return this;\n }\n\n /**\n * Decrease the indentation level by one (minimum 0)\n * @returns This instance for method chaining\n */\n dedent(): this {\n this.indentLevel = Math.max(0, this.indentLevel - 1);\n return this;\n }\n\n /**\n * Add a line with the current indentation level\n * @param content - The content to add (empty string adds a blank line)\n * @returns This instance for method chaining\n */\n line(content: string = \"\"): this {\n const indent = \" \".repeat(this.indentLevel);\n this.lines.push(content ? `${indent}${content}` : \"\");\n return this;\n }\n\n /**\n * Build the final DBML string from all added lines\n * @returns The complete DBML content as a string\n */\n build(): string {\n return this.lines.join(\"\\n\");\n }\n}\n\n/**\n * Configuration for different database dialects\n */\nexport interface DialectConfig {\n escapeName: (name: string) => string;\n isIncrement: (column: AnyColumn) => boolean;\n}\n\n/**\n * Table configuration extracted from Drizzle tables\n * Using 'any' types for dialect-agnostic handling\n */\nexport interface TableConfig {\n indexes: unknown[];\n primaryKeys: unknown[];\n uniqueConstraints: unknown[];\n foreignKeys: unknown[];\n}\n\n// Use official v1 types from drizzle-orm/relations:\n// - TableRelationalConfig: { table, name, relations: Record<string, AnyRelation> }\n// - AnyRelation: Relation with sourceColumns, targetColumns, relationType, etc.\n\n/**\n * Base generator class for DBML generation\n */\nexport abstract class BaseGenerator<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n> {\n protected schema: TSchema;\n protected relational: boolean;\n protected generatedRefs: GeneratedRef[] = [];\n protected comments: SchemaComments | undefined;\n protected parsedRelations: SchemaRelations | undefined;\n protected source: string | undefined;\n protected abstract dialectConfig: DialectConfig;\n\n /**\n * Create a new generator instance\n * @param options - Configuration options including schema, relational mode, source code, and comments\n */\n constructor(options: GenerateOptions<TSchema>) {\n this.schema = options.schema;\n this.relational = options.relational ?? false;\n this.source = options.source;\n\n // Initialize comments from options\n if (options.comments) {\n this.comments = options.comments;\n } else if (this.source) {\n this.comments = extractComments(this.source);\n }\n\n // Extract relations from source if relational mode is enabled\n if (this.relational && this.source) {\n this.parsedRelations = extractRelations(this.source);\n }\n }\n\n /**\n * Generate complete DBML output from the schema\n *\n * Creates DBML representation including:\n * - Table definitions with columns, indexes, and constraints\n * - Foreign key references (from table config or relations)\n * - Comments for tables and columns\n *\n * @returns The complete DBML string\n */\n generate(): string {\n const dbml = new DbmlBuilder();\n const tables = this.getTables();\n const v0Relations = this.getV0Relations();\n const v1Entries = this.getV1RelationEntries();\n\n // Generate tables\n for (const table of tables) {\n this.generateTable(dbml, table);\n dbml.line();\n }\n\n // Generate references from relations\n if (this.relational) {\n // Try v1 defineRelations() first - runtime object parsing with official types\n if (v1Entries.length > 0) {\n this.generateRelationalRefsFromV1(v1Entries);\n }\n // Fall back to v0 relations() with AST parsing\n else if (v0Relations.length > 0 || this.parsedRelations) {\n this.generateRelationalRefsFromV0();\n }\n }\n\n // Add collected refs\n for (const ref of this.generatedRefs) {\n this.generateRef(dbml, ref);\n }\n\n return dbml.build().trim();\n }\n\n /**\n * Get all tables from schema\n *\n * Extracts all Drizzle table objects from the schema by checking each value\n * with isTable() method.\n *\n * @returns Array of table objects\n */\n protected getTables(): Table[] {\n const tables: Table[] = [];\n for (const value of Object.values(this.schema)) {\n if (this.isTable(value)) {\n tables.push(value as Table);\n }\n }\n return tables;\n }\n\n /**\n * Check if a value is a Drizzle table\n *\n * Validates whether a value is a table instance from any supported dialect\n * (PostgreSQL, MySQL, or SQLite).\n *\n * @param value - The value to check\n * @returns True if value is a Drizzle table\n */\n protected isTable(value: unknown): boolean {\n return is(value, PgTable) || is(value, MySqlTable) || is(value, SQLiteTable);\n }\n\n /**\n * Get all v0 relations from schema (legacy relations() API)\n *\n * Extracts legacy relations defined using the old relations() API.\n * These are identified by having 'table' and 'config' properties.\n *\n * @returns Array of legacy relation objects\n */\n protected getV0Relations(): LegacyRelations[] {\n const relations: LegacyRelations[] = [];\n for (const value of Object.values(this.schema)) {\n if (this.isV0Relations(value)) {\n relations.push(value as LegacyRelations);\n }\n }\n return relations;\n }\n\n /**\n * Check if a value is a Drizzle v0 relations object (from relations())\n *\n * Validates the legacy relations() format by checking for 'table' and 'config' properties.\n *\n * @param value - The value to check\n * @returns True if value is a legacy relations object\n */\n protected isV0Relations(value: unknown): boolean {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n // v0 Relations objects have 'table' and 'config' properties\n return (\n \"table\" in value &&\n \"config\" in value &&\n typeof (value as Record<string, unknown>).config === \"object\"\n );\n }\n\n /**\n * Check if a value is a v1 relation entry (from defineRelations())\n *\n * Uses official Drizzle v1 types: TableRelationalConfig with Relation instances.\n * Validates the structure has 'table', 'name', and 'relations' properties with valid types.\n *\n * @param value - The value to check\n * @returns True if value is a v1 relation entry\n */\n protected isV1RelationEntry(value: unknown): value is TableRelationalConfig {\n if (typeof value !== \"object\" || value === null) {\n return false;\n }\n const obj = value as Record<string, unknown>;\n if (\n !(\"table\" in obj) ||\n !(\"name\" in obj) ||\n typeof obj.name !== \"string\" ||\n !(\"relations\" in obj) ||\n typeof obj.relations !== \"object\" ||\n obj.relations === null\n ) {\n return false;\n }\n // Check that 'relations' contains Relation instances (using drizzle-orm is())\n const relations = obj.relations as Record<string, unknown>;\n const relationValues = Object.values(relations);\n // Empty relations object is valid, but if there are entries, they must be Relations\n if (relationValues.length > 0) {\n return relationValues.some((rel) => is(rel, Relation));\n }\n // If no relations defined, also check table is valid\n return this.isTable(obj.table);\n }\n\n /**\n * Get all v1 relation entries from schema (defineRelations() API)\n *\n * Handles both individual entries and the full defineRelations() result object.\n * Extracts relation configurations that use the modern v1 API with official types.\n *\n * @returns Array of v1 relation entries\n */\n protected getV1RelationEntries(): TableRelationalConfig[] {\n const entries: TableRelationalConfig[] = [];\n for (const value of Object.values(this.schema)) {\n // Check if it's an individual relation entry\n if (this.isV1RelationEntry(value)) {\n entries.push(value);\n }\n // Check if it's the full defineRelations() result object\n // (an object where each value is a relation entry)\n else if (this.isV1DefineRelationsResult(value)) {\n for (const entry of Object.values(value as Record<string, unknown>)) {\n if (this.isV1RelationEntry(entry)) {\n entries.push(entry);\n }\n }\n }\n }\n return entries;\n }\n\n /**\n * Check if a value is a full v1 defineRelations() result object\n *\n * This is an object where all values are TableRelationalConfig objects.\n * Used to detect the full result of calling defineRelations() in v1.\n *\n * @param value - The value to check\n * @returns True if value is a full defineRelations() result\n */\n protected isV1DefineRelationsResult(value: unknown): boolean {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n return false;\n }\n const obj = value as Record<string, unknown>;\n const values = Object.values(obj);\n // Must have at least one entry and all must be relation entries\n return values.length > 0 && values.every((v) => this.isV1RelationEntry(v));\n }\n\n /**\n * Generate a table definition in DBML format\n *\n * Creates the complete table definition including columns, indexes, constraints,\n * and table-level comments. Also collects foreign keys if not in relational mode.\n *\n * @param dbml - The DBML builder to add the table to\n * @param table - The Drizzle table to generate\n */\n protected generateTable(dbml: DbmlBuilder, table: Table): void {\n const tableName = getTableName(table);\n const columns = getTableColumns(table);\n const escapedName = this.dialectConfig.escapeName(tableName);\n\n dbml.line(`Table ${escapedName} {`);\n dbml.indent();\n\n // Generate columns\n for (const column of Object.values(columns)) {\n this.generateColumn(dbml, column, tableName);\n }\n\n // Get table configuration (indexes, constraints, etc.)\n const tableConfig = this.getTableConfig(table);\n\n // Generate indexes block if any\n if (tableConfig) {\n this.generateIndexesBlock(dbml, tableConfig);\n }\n\n // Add table-level Note if comment exists\n const tableComment = this.comments?.tables[tableName]?.comment;\n if (tableComment) {\n dbml.line();\n dbml.line(`Note: '${escapeDbmlString(tableComment)}'`);\n }\n\n dbml.dedent();\n dbml.line(\"}\");\n\n // Collect foreign keys if not using relational mode\n if (!this.relational && tableConfig && tableConfig.foreignKeys.length > 0) {\n this.collectForeignKeysFromConfig(tableName, tableConfig.foreignKeys);\n }\n }\n\n /**\n * Get table configuration from a Drizzle table\n *\n * Extracts indexes, primary keys, unique constraints, and foreign keys\n * from the table using the appropriate dialect-specific config getter.\n *\n * @param table - The Drizzle table to get configuration from\n * @returns Table configuration or undefined if dialect is not supported\n */\n protected getTableConfig(table: Table): TableConfig | undefined {\n // Detect dialect and use appropriate config getter\n if (is(table, PgTable)) {\n const config = getPgTableConfig(table);\n return {\n indexes: config.indexes || [],\n primaryKeys: config.primaryKeys || [],\n uniqueConstraints: config.uniqueConstraints || [],\n foreignKeys: config.foreignKeys || [],\n };\n }\n if (is(table, MySqlTable)) {\n const config = getMySqlTableConfig(table);\n return {\n indexes: config.indexes || [],\n primaryKeys: config.primaryKeys || [],\n uniqueConstraints: config.uniqueConstraints || [],\n foreignKeys: config.foreignKeys || [],\n };\n }\n if (is(table, SQLiteTable)) {\n const config = getSqliteTableConfig(table);\n return {\n indexes: config.indexes || [],\n primaryKeys: config.primaryKeys || [],\n uniqueConstraints: config.uniqueConstraints || [],\n foreignKeys: config.foreignKeys || [],\n };\n }\n return undefined;\n }\n\n /**\n * Generate a column definition in DBML format\n *\n * Creates a column line with type and attributes (primary key, not null, unique, etc.)\n * and includes column-level comments if available.\n *\n * @param dbml - The DBML builder to add the column to\n * @param column - The Drizzle column to generate\n * @param tableName - Optional table name for looking up comments\n */\n protected generateColumn(dbml: DbmlBuilder, column: AnyColumn, tableName?: string): void {\n const name = this.dialectConfig.escapeName(column.name);\n const type = this.getColumnType(column);\n const attrs = this.getColumnAttributes(column, tableName);\n const attrStr = this.formatAttributes(attrs);\n\n if (attrStr) {\n dbml.line(`${name} ${type} [${attrStr}]`);\n } else {\n dbml.line(`${name} ${type}`);\n }\n }\n\n /**\n * Get the SQL type for a column\n *\n * @param column - The column to get the SQL type from\n * @returns The SQL type string (e.g., \"varchar\", \"integer\")\n */\n protected getColumnType(column: AnyColumn): string {\n return column.getSQLType();\n }\n\n /**\n * Get column attributes for DBML\n *\n * Extracts attributes like primary key, not null, unique, increment, default value,\n * and note from the column. Uses column metadata and comments if available.\n *\n * @param column - The column to get attributes from\n * @param tableName - Optional table name for looking up comments\n * @returns Array of attribute strings for DBML format\n */\n protected getColumnAttributes(column: AnyColumn, tableName?: string): string[] {\n const attrs: string[] = [];\n\n if (column.primary) {\n attrs.push(\"primary key\");\n }\n if (column.notNull) {\n attrs.push(\"not null\");\n }\n if (column.isUnique) {\n attrs.push(\"unique\");\n }\n if (this.dialectConfig.isIncrement(column)) {\n attrs.push(\"increment\");\n }\n\n const defaultValue = this.getDefaultValue(column);\n if (defaultValue !== undefined) {\n attrs.push(`default: ${defaultValue}`);\n }\n\n // Add note attribute if column comment exists\n if (tableName) {\n const columnComment = this.comments?.tables[tableName]?.columns[column.name]?.comment;\n if (columnComment) {\n attrs.push(`note: '${escapeDbmlString(columnComment)}'`);\n }\n }\n\n return attrs;\n }\n\n /**\n * Format attributes into a string\n *\n * @param attrs - Array of attribute strings\n * @returns Comma-separated attribute string\n */\n protected formatAttributes(attrs: string[]): string {\n return attrs.join(\", \");\n }\n\n /**\n * Get the default value for a column\n *\n * Extracts and formats the default value from a column, handling SQL expressions,\n * objects, and primitive values. Returns undefined if no default value exists.\n *\n * @param column - The column to get the default value from\n * @returns Formatted default value string or undefined\n */\n protected getDefaultValue(column: AnyColumn): string | undefined {\n if (!column.hasDefault) {\n return undefined;\n }\n\n const defaultValue = column.default;\n\n if (defaultValue === null) {\n return \"null\";\n }\n\n if (defaultValue === undefined) {\n return undefined;\n }\n\n // Handle SQL expressions\n if (typeof defaultValue === \"object\" && defaultValue !== null) {\n if (\"queryChunks\" in defaultValue) {\n // It's a SQL template\n const chunks = (defaultValue as { queryChunks: unknown[] }).queryChunks;\n const sqlParts: string[] = [];\n for (const chunk of chunks) {\n if (typeof chunk === \"string\") {\n sqlParts.push(chunk);\n } else if (typeof chunk === \"object\" && chunk !== null && \"value\" in chunk) {\n sqlParts.push(String((chunk as { value: unknown }).value));\n }\n }\n return `\\`${sqlParts.join(\"\")}\\``;\n }\n if (\"sql\" in defaultValue) {\n return `\\`${(defaultValue as { sql: string }).sql}\\``;\n }\n // JSON object\n return `'${JSON.stringify(defaultValue)}'`;\n }\n\n // Handle primitives\n if (typeof defaultValue === \"string\") {\n return `'${defaultValue.replace(/'/g, \"\\\\'\")}'`;\n }\n if (typeof defaultValue === \"number\" || typeof defaultValue === \"boolean\") {\n return String(defaultValue);\n }\n\n return undefined;\n }\n\n /**\n * Generate indexes block from table configuration\n *\n * Creates the indexes block containing primary keys, unique constraints,\n * and regular indexes with their respective attributes.\n *\n * @param dbml - The DBML builder to add the indexes block to\n * @param tableConfig - The table configuration containing index information\n */\n protected generateIndexesBlock(dbml: DbmlBuilder, tableConfig: TableConfig): void {\n const { indexes, primaryKeys, uniqueConstraints } = tableConfig;\n\n if (indexes.length === 0 && primaryKeys.length === 0 && uniqueConstraints.length === 0) {\n return;\n }\n\n dbml.line();\n dbml.line(\"indexes {\");\n dbml.indent();\n\n // Primary keys\n for (const pk of primaryKeys) {\n const columns = this.getPrimaryKeyColumns(pk);\n if (columns.length > 0) {\n const colStr = columns.map((c) => this.dialectConfig.escapeName(c)).join(\", \");\n dbml.line(`(${colStr}) [pk]`);\n }\n }\n\n // Unique constraints\n for (const uc of uniqueConstraints) {\n const columns = this.getUniqueConstraintColumns(uc);\n if (columns.length > 0) {\n const colStr = columns.map((c) => this.dialectConfig.escapeName(c)).join(\", \");\n dbml.line(`(${colStr}) [unique]`);\n }\n }\n\n // Regular indexes\n for (const idx of indexes) {\n const columns = this.getIndexColumns(idx);\n if (columns.length > 0) {\n const colStr = columns.map((c) => this.dialectConfig.escapeName(c)).join(\", \");\n const attrs: string[] = [];\n if (this.isUniqueIndex(idx)) {\n attrs.push(\"unique\");\n }\n const attrStr = attrs.length > 0 ? ` [${attrs.join(\", \")}]` : \"\";\n dbml.line(`(${colStr})${attrStr}`);\n }\n }\n\n dbml.dedent();\n dbml.line(\"}\");\n }\n\n /**\n * Collect foreign keys from table configuration\n *\n * Parses all foreign key definitions from the table config and adds them\n * to the generatedRefs collection for later output.\n *\n * @param tableName - The name of the source table\n * @param foreignKeys - Array of foreign key definitions from table config\n */\n protected collectForeignKeysFromConfig(tableName: string, foreignKeys: unknown[]): void {\n for (const fk of foreignKeys) {\n const ref = this.parseForeignKey(tableName, fk);\n if (ref) {\n this.generatedRefs.push(ref);\n }\n }\n }\n\n /**\n * Parse a foreign key into a GeneratedRef\n *\n * Extracts foreign key information (source/target tables and columns, actions)\n * and converts it to a GeneratedRef object for DBML output.\n *\n * @param tableName - The name of the source table\n * @param fk - The foreign key definition to parse\n * @returns GeneratedRef object or undefined if parsing fails\n */\n protected parseForeignKey(tableName: string, fk: unknown): GeneratedRef | undefined {\n try {\n const fkObj = fk as {\n reference: () => {\n columns: Array<{ name: string }>;\n foreignColumns: Array<{ name: string }>;\n foreignTable: Table;\n };\n onDelete?: string;\n onUpdate?: string;\n };\n const reference = fkObj.reference();\n const fromColumns = reference.columns.map((c) => c.name);\n const toColumns = reference.foreignColumns.map((c) => c.name);\n const toTable = getTableName(reference.foreignTable);\n\n return {\n fromTable: tableName,\n fromColumns,\n toTable,\n toColumns,\n type: \">\",\n onDelete: fkObj.onDelete,\n onUpdate: fkObj.onUpdate,\n };\n } catch {\n return undefined;\n }\n }\n\n /**\n * Get a mapping from variable names to table names in the schema\n *\n * Creates a map from TypeScript variable names (e.g., \"usersTable\") to\n * actual database table names (e.g., \"users\").\n *\n * @returns Map of variable names to table names\n */\n protected getTableNameMapping(): Map<string, string> {\n const mapping = new Map<string, string>();\n for (const [varName, value] of Object.entries(this.schema)) {\n if (this.isTable(value)) {\n const tableName = getTableName(value as Table);\n mapping.set(varName, tableName);\n }\n }\n return mapping;\n }\n\n /**\n * Get a mapping from TypeScript property names to database column names for a table\n *\n * Creates a map from TypeScript property names (e.g., \"authorId\") to\n * actual database column names (e.g., \"author_id\").\n *\n * @param tableVarName - The variable name of the table in the schema\n * @returns Map of property names to column names\n */\n protected getColumnNameMapping(tableVarName: string): Map<string, string> {\n const mapping = new Map<string, string>();\n const table = this.schema[tableVarName];\n if (table && this.isTable(table)) {\n const columns = getTableColumns(table as Table);\n for (const [propName, column] of Object.entries(columns)) {\n mapping.set(propName, column.name);\n }\n }\n return mapping;\n }\n\n /**\n * Check if there's a reverse one() relation (B->A when we have A->B)\n *\n * Used to detect one-to-one relationships by checking if both tables\n * have one() relations pointing to each other.\n *\n * @param sourceTable - The source table variable name\n * @param targetTable - The target table variable name\n * @param sourceFields - The source table's field names\n * @param targetReferences - The target table's reference column names\n * @returns True if a reverse one() relation exists\n */\n protected hasReverseOneRelation(\n sourceTable: string,\n targetTable: string,\n sourceFields: string[],\n targetReferences: string[],\n ): boolean {\n if (!this.parsedRelations) return false;\n\n // Look for a one() relation from targetTable to sourceTable\n for (const relation of this.parsedRelations.relations) {\n if (\n relation.type === \"one\" &&\n relation.sourceTable === targetTable &&\n relation.targetTable === sourceTable &&\n relation.fields.length > 0 &&\n relation.references.length > 0\n ) {\n // Check if the fields/references are the reverse of each other\n // A->B: fields=[A.col], references=[B.col]\n // B->A: fields=[B.col], references=[A.col]\n const reverseFields = relation.fields;\n const reverseReferences = relation.references;\n\n // The reverse relation's fields should match our references\n // and the reverse relation's references should match our fields\n if (\n this.arraysEqual(reverseFields, targetReferences) &&\n this.arraysEqual(reverseReferences, sourceFields)\n ) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * Helper to check if two arrays are equal\n *\n * @param a - First array\n * @param b - Second array\n * @returns True if arrays have same length and same elements in order\n */\n private arraysEqual(a: string[], b: string[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((val, i) => val === b[i]);\n }\n\n /**\n * Generate references from v0 relations() API\n *\n * Uses TypeScript Compiler API to parse relations() definitions from source file\n * and extract fields/references to generate DBML Ref lines.\n *\n * Detects one-to-one relationships when bidirectional one() relations exist.\n */\n protected generateRelationalRefsFromV0(): void {\n if (!this.parsedRelations || this.parsedRelations.relations.length === 0) {\n return;\n }\n\n const tableNameMapping = this.getTableNameMapping();\n const processedRefs = new Set<string>();\n\n for (const parsedRelation of this.parsedRelations.relations) {\n // Only process one() relations with fields and references\n // many() relations are typically the inverse and don't have field info\n if (parsedRelation.type !== \"one\") {\n continue;\n }\n\n if (parsedRelation.fields.length === 0 || parsedRelation.references.length === 0) {\n continue;\n }\n\n // Map variable names to actual table names\n const fromTableName = tableNameMapping.get(parsedRelation.sourceTable);\n const toTableName = tableNameMapping.get(parsedRelation.targetTable);\n\n if (!fromTableName || !toTableName) {\n continue;\n }\n\n // Get column name mappings (TypeScript property names -> database column names)\n const fromColumnMapping = this.getColumnNameMapping(parsedRelation.sourceTable);\n const toColumnMapping = this.getColumnNameMapping(parsedRelation.targetTable);\n\n // Map TypeScript field names to database column names\n const fromColumns = parsedRelation.fields.map(\n (field) => fromColumnMapping.get(field) || field,\n );\n const toColumns = parsedRelation.references.map((ref) => toColumnMapping.get(ref) || ref);\n\n // Create a unique key to avoid duplicate refs (bidirectional)\n const refKey = `${fromTableName}.${fromColumns.join(\",\")}-${toTableName}.${toColumns.join(\",\")}`;\n const reverseRefKey = `${toTableName}.${toColumns.join(\",\")}-${fromTableName}.${fromColumns.join(\",\")}`;\n\n if (processedRefs.has(refKey) || processedRefs.has(reverseRefKey)) {\n continue;\n }\n processedRefs.add(refKey);\n\n // Check if this is a one-to-one relationship (bidirectional one())\n const isOneToOne = this.hasReverseOneRelation(\n parsedRelation.sourceTable,\n parsedRelation.targetTable,\n parsedRelation.fields,\n parsedRelation.references,\n );\n\n // Create GeneratedRef\n // one-to-one: \"-\", many-to-one: \">\"\n const ref: GeneratedRef = {\n fromTable: fromTableName,\n fromColumns,\n toTable: toTableName,\n toColumns,\n type: isOneToOne ? \"-\" : \">\",\n };\n\n this.generatedRefs.push(ref);\n }\n }\n\n /**\n * Generate references from v1 defineRelations() entries\n *\n * Uses official Drizzle v1 types (TableRelationalConfig, Relation, One).\n * Processes One relations to extract foreign key information and generates\n * DBML Ref lines. Detects one-to-one relationships with bidirectional checks.\n *\n * @param entries - Array of v1 relation entries from defineRelations()\n */\n protected generateRelationalRefsFromV1(entries: TableRelationalConfig[]): void {\n const processedRefs = new Set<string>();\n\n for (const entry of entries) {\n const sourceTableName = getTableName(entry.table as Table);\n\n for (const relation of Object.values(entry.relations)) {\n // Only process One relations as they define the FK direction\n // Many relations are the inverse and don't add new information\n if (!is(relation, One)) {\n continue;\n }\n\n // Skip reversed relations (they are auto-generated inverse relations)\n if ((relation as AnyRelation).isReversed) {\n continue;\n }\n\n // Get source and target column names (using official Relation properties)\n const rel = relation as AnyRelation;\n const sourceColumns = rel.sourceColumns.map((col) => col.name);\n const targetColumns = rel.targetColumns.map((col) => col.name);\n\n if (sourceColumns.length === 0 || targetColumns.length === 0) {\n continue;\n }\n\n const targetTableName = getTableName(rel.targetTable as Table);\n\n // Create a unique key to avoid duplicate refs\n const refKey = `${sourceTableName}.${sourceColumns.join(\",\")}->${targetTableName}.${targetColumns.join(\",\")}`;\n const reverseRefKey = `${targetTableName}.${targetColumns.join(\",\")}->${sourceTableName}.${sourceColumns.join(\",\")}`;\n\n if (processedRefs.has(refKey) || processedRefs.has(reverseRefKey)) {\n continue;\n }\n processedRefs.add(refKey);\n\n // Check if there's a reverse one() relation (indicating one-to-one)\n const isOneToOne = this.hasV1ReverseOneRelation(\n entries,\n targetTableName,\n sourceTableName,\n targetColumns,\n sourceColumns,\n );\n\n const ref: GeneratedRef = {\n fromTable: sourceTableName,\n fromColumns: sourceColumns,\n toTable: targetTableName,\n toColumns: targetColumns,\n type: isOneToOne ? \"-\" : \">\",\n };\n\n this.generatedRefs.push(ref);\n }\n }\n }\n\n /**\n * Check if there's a reverse One relation in v1 entries\n *\n * Detects one-to-one relationships by checking if the target table\n * has a matching One relation pointing back to the source table.\n *\n * @param entries - All v1 relation entries\n * @param fromTableName - The table to search for reverse relation\n * @param toTableName - The expected target table of the reverse relation\n * @param fromColumns - The expected source columns of the reverse relation\n * @param toColumns - The expected target columns of the reverse relation\n * @returns True if a matching reverse One relation exists\n */\n protected hasV1ReverseOneRelation(\n entries: TableRelationalConfig[],\n fromTableName: string,\n toTableName: string,\n fromColumns: string[],\n toColumns: string[],\n ): boolean {\n const fromEntry = entries.find((e) => getTableName(e.table as Table) === fromTableName);\n if (!fromEntry) {\n return false;\n }\n\n for (const relation of Object.values(fromEntry.relations)) {\n if (!is(relation, One)) {\n continue;\n }\n\n const rel = relation as AnyRelation;\n const relTargetName = getTableName(rel.targetTable as Table);\n if (relTargetName !== toTableName) {\n continue;\n }\n\n const relSourceCols = rel.sourceColumns.map((col) => col.name);\n const relTargetCols = rel.targetColumns.map((col) => col.name);\n\n // Check if columns match in reverse\n if (\n relSourceCols.length === fromColumns.length &&\n relTargetCols.length === toColumns.length &&\n relSourceCols.every((col, i) => col === fromColumns[i]) &&\n relTargetCols.every((col, i) => col === toColumns[i])\n ) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Get unique key for a relation to avoid duplicates\n *\n * Creates a consistent key by sorting table names alphabetically.\n *\n * @param tableName - The source table name\n * @param relation - The relation object\n * @returns A unique key string for the relation\n */\n protected getRelationKey(tableName: string, relation: unknown): string {\n const rel = relation as { referencedTable?: Table };\n const referencedTable = rel.referencedTable ? getTableName(rel.referencedTable) : \"unknown\";\n const tables = [tableName, referencedTable].sort();\n return `${tables[0]}-${tables[1]}`;\n }\n\n /**\n * Parse a relation into a GeneratedRef\n *\n * Extracts relation information from a legacy relation object and converts\n * it to a GeneratedRef for DBML output.\n *\n * @param tableName - The source table name\n * @param relation - The relation object to parse\n * @returns GeneratedRef object or undefined if parsing fails\n */\n protected parseRelation(tableName: string, relation: unknown): GeneratedRef | undefined {\n try {\n const rel = relation as {\n referencedTable?: Table;\n sourceColumns?: AnyColumn[];\n referencedColumns?: AnyColumn[];\n relationType?: string;\n };\n\n if (!rel.referencedTable) {\n return undefined;\n }\n\n const referencedTable = getTableName(rel.referencedTable);\n\n // Try to get field info from the relation\n const fields = rel.sourceColumns || [];\n const references = rel.referencedColumns || [];\n\n if (fields.length === 0 || references.length === 0) {\n // Cannot generate ref without column info\n return undefined;\n }\n\n const fromColumns = fields.map((c: AnyColumn) => c.name);\n const toColumns = references.map((c: AnyColumn) => c.name);\n\n // Determine relation type\n let type: \"<\" | \">\" | \"-\" = \">\";\n if (rel.relationType === \"one\") {\n type = \"-\";\n }\n\n return {\n fromTable: tableName,\n fromColumns,\n toTable: referencedTable,\n toColumns,\n type,\n };\n } catch {\n return undefined;\n }\n }\n\n /**\n * Generate a reference line in DBML format\n *\n * Creates a Ref line showing the relationship between tables with optional\n * onDelete and onUpdate actions.\n *\n * @param dbml - The DBML builder to add the reference to\n * @param ref - The reference definition to generate\n */\n protected generateRef(dbml: DbmlBuilder, ref: GeneratedRef): void {\n const from = `${this.dialectConfig.escapeName(ref.fromTable)}.${ref.fromColumns.map((c) => this.dialectConfig.escapeName(c)).join(\", \")}`;\n const to = `${this.dialectConfig.escapeName(ref.toTable)}.${ref.toColumns.map((c) => this.dialectConfig.escapeName(c)).join(\", \")}`;\n\n let refLine = `Ref: ${from} ${ref.type} ${to}`;\n\n const attrs: string[] = [];\n if (ref.onDelete && ref.onDelete !== \"no action\") {\n attrs.push(`delete: ${ref.onDelete}`);\n }\n if (ref.onUpdate && ref.onUpdate !== \"no action\") {\n attrs.push(`update: ${ref.onUpdate}`);\n }\n\n if (attrs.length > 0) {\n refLine += ` [${attrs.join(\", \")}]`;\n }\n\n dbml.line(refLine);\n }\n\n // Helper methods for extracting column information from constraints\n\n /**\n * Get column names from an index definition\n *\n * @param idx - The index definition to extract columns from\n * @returns Array of column names in the index\n */\n protected getIndexColumns(idx: unknown): string[] {\n try {\n const config = (idx as { config: { columns: Array<{ name?: string }> } }).config;\n return config.columns\n .map((c) => {\n if (typeof c === \"object\" && c !== null && \"name\" in c) {\n return c.name as string;\n }\n return \"\";\n })\n .filter(Boolean);\n } catch {\n return [];\n }\n }\n\n /**\n * Check if an index is unique\n *\n * @param idx - The index definition to check\n * @returns True if the index has the unique flag\n */\n protected isUniqueIndex(idx: unknown): boolean {\n try {\n const config = (idx as { config: { unique?: boolean } }).config;\n return config.unique === true;\n } catch {\n return false;\n }\n }\n\n /**\n * Get column names from a primary key constraint\n *\n * @param pk - The primary key definition to extract columns from\n * @returns Array of column names in the primary key\n */\n protected getPrimaryKeyColumns(pk: unknown): string[] {\n try {\n const columns = (pk as { columns: Array<{ name: string }> }).columns;\n return columns.map((c) => c.name);\n } catch {\n return [];\n }\n }\n\n /**\n * Get column names from a unique constraint\n *\n * @param uc - The unique constraint definition to extract columns from\n * @returns Array of column names in the unique constraint\n */\n protected getUniqueConstraintColumns(uc: unknown): string[] {\n try {\n const columns = (uc as { columns: Array<{ name: string }> }).columns;\n return columns.map((c) => c.name);\n } catch {\n return [];\n }\n }\n}\n\n/**\n * Write DBML content to a file\n *\n * Creates the directory if it doesn't exist and writes the DBML content\n * to the specified file path.\n *\n * @param filePath - The path to write the DBML file to\n * @param content - The DBML content to write\n */\nexport function writeDbmlFile(filePath: string, content: string): void {\n const resolvedPath = resolve(filePath);\n const dir = dirname(resolvedPath);\n mkdirSync(dir, { recursive: true });\n writeFileSync(resolvedPath, content, \"utf-8\");\n}\n\n/**\n * Escape a string for use in DBML single-quoted strings\n *\n * Escapes backslashes, single quotes, and newlines for proper DBML formatting.\n *\n * @param str - The string to escape\n * @returns The escaped string safe for DBML\n */\nfunction escapeDbmlString(str: string): string {\n return str.replace(/\\\\/g, \"\\\\\\\\\").replace(/'/g, \"\\\\'\").replace(/\\n/g, \"\\\\n\");\n}\n"],"names":["DbmlBuilder","content","indent","BaseGenerator","options","extractComments","extractRelations","dbml","tables","v0Relations","v1Entries","table","ref","value","is","PgTable","MySqlTable","SQLiteTable","relations","obj","relationValues","rel","Relation","entries","entry","values","v","tableName","getTableName","columns","getTableColumns","escapedName","column","tableConfig","tableComment","escapeDbmlString","config","getPgTableConfig","getMySqlTableConfig","getSqliteTableConfig","name","type","attrs","attrStr","defaultValue","columnComment","chunks","sqlParts","chunk","indexes","primaryKeys","uniqueConstraints","pk","colStr","c","uc","idx","foreignKeys","fk","fkObj","reference","fromColumns","toColumns","toTable","mapping","varName","tableVarName","propName","sourceTable","targetTable","sourceFields","targetReferences","relation","reverseFields","reverseReferences","a","b","val","i","tableNameMapping","processedRefs","parsedRelation","fromTableName","toTableName","fromColumnMapping","toColumnMapping","field","refKey","reverseRefKey","isOneToOne","sourceTableName","One","sourceColumns","col","targetColumns","targetTableName","fromEntry","e","relSourceCols","relTargetCols","referencedTable","fields","references","from","to","refLine","writeDbmlFile","filePath","resolvedPath","resolve","dir","dirname","mkdirSync","writeFileSync","str"],"mappings":";;;;;;;;AA+BO,MAAMA,EAAY;AAAA,EACf,QAAkB,CAAA;AAAA,EAClB,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtB,SAAe;AACb,gBAAK,eACE;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AA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,IAAI,CAACE,MAAMA,EAAE,IAAI;AAAA,IAClC,QAAQ;AACN,aAAO,CAAA;AAAA,IACT;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQU,2BAA2BC,GAAuB;AAC1D,QAAI;AAEF,aADiBA,EAA4C,QAC9C,IAAI,CAACD,MAAMA,EAAE,IAAI;AAAA,IAClC,QAAQ;AACN,aAAO,CAAA;AAAA,IACT;AAAA,EACF;AACF;AAWO,SAASoD,EAAcC,GAAkB1G,GAAuB;AACrE,QAAM2G,IAAeC,EAAQF,CAAQ,GAC/BG,IAAMC,EAAQH,CAAY;AAChC,EAAAI,EAAUF,GAAK,EAAE,WAAW,GAAA,CAAM,GAClCG,EAAcL,GAAc3G,GAAS,OAAO;AAC9C;AAUA,SAASkC,EAAiB+E,GAAqB;AAC7C,SAAOA,EAAI,QAAQ,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAK,EAAE,QAAQ,OAAO,KAAK;AAC7E;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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, DbmlBuilder, writeDbmlFile } from './common';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseGenerator, DialectConfig } from './common';
|
|
2
|
+
import { GenerateOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* MySQL-specific DBML generator
|
|
5
|
+
*
|
|
6
|
+
* Supports JSDoc comment extraction via `sourceFile` or `comments` options.
|
|
7
|
+
* Comments are included as DBML Note clauses for tables and columns.
|
|
8
|
+
*/
|
|
9
|
+
export declare class MySqlGenerator<TSchema extends Record<string, unknown> = Record<string, unknown>> extends BaseGenerator<TSchema> {
|
|
10
|
+
protected dialectConfig: DialectConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generate DBML from a MySQL Drizzle schema
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { mysqlTable, serial, text, varchar } from "drizzle-orm/mysql-core";
|
|
18
|
+
* import { mysqlGenerate } from "drizzle-docs-generator";
|
|
19
|
+
*
|
|
20
|
+
* const users = mysqlTable("users", {
|
|
21
|
+
* id: serial("id").primaryKey(),
|
|
22
|
+
* name: text("name").notNull(),
|
|
23
|
+
* email: varchar("email", { length: 255 }).unique(),
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const dbml = mysqlGenerate({ schema: { users } });
|
|
27
|
+
* console.log(dbml);
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* To include JSDoc comments as DBML Note clauses, use the `source` option:
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const dbml = mysqlGenerate({ schema: { users }, source: "./schema.ts" });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function mysqlGenerate<TSchema extends Record<string, unknown>>(options: GenerateOptions<TSchema>): string;
|
|
36
|
+
//# sourceMappingURL=mysql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/generator/mysql.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;GAKG;AACH,qBAAa,cAAc,CACzB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjE,SAAQ,aAAa,CAAC,OAAO,CAAC;IAC9B,SAAS,CAAC,aAAa,EAAE,aAAa,CAMpC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnE,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,GAChC,MAAM,CASR"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { writeDbmlFile as n, BaseGenerator as a } from "./common.js";
|
|
2
|
+
class o extends a {
|
|
3
|
+
dialectConfig = {
|
|
4
|
+
escapeName: (r) => `\`${r}\``,
|
|
5
|
+
isIncrement: (r) => r.autoIncrement === !0
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function m(e) {
|
|
9
|
+
const t = new o(e).generate();
|
|
10
|
+
return e.out && n(e.out, t), t;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
o as MySqlGenerator,
|
|
14
|
+
m as mysqlGenerate
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=mysql.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mysql.js","sources":["../../src/generator/mysql.ts"],"sourcesContent":["import type { AnyColumn } from \"drizzle-orm\";\nimport { BaseGenerator, writeDbmlFile, type DialectConfig } from \"./common\";\nimport type { GenerateOptions } from \"../types\";\n\n/**\n * MySQL-specific DBML generator\n *\n * Supports JSDoc comment extraction via `sourceFile` or `comments` options.\n * Comments are included as DBML Note clauses for tables and columns.\n */\nexport class MySqlGenerator<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n> extends BaseGenerator<TSchema> {\n protected dialectConfig: DialectConfig = {\n escapeName: (name: string) => `\\`${name}\\``,\n isIncrement: (column: AnyColumn) => {\n // MySQL uses autoincrement property\n return (column as unknown as { autoIncrement?: boolean }).autoIncrement === true;\n },\n };\n}\n\n/**\n * Generate DBML from a MySQL Drizzle schema\n *\n * @example\n * ```ts\n * import { mysqlTable, serial, text, varchar } from \"drizzle-orm/mysql-core\";\n * import { mysqlGenerate } from \"drizzle-docs-generator\";\n *\n * const users = mysqlTable(\"users\", {\n * id: serial(\"id\").primaryKey(),\n * name: text(\"name\").notNull(),\n * email: varchar(\"email\", { length: 255 }).unique(),\n * });\n *\n * const dbml = mysqlGenerate({ schema: { users } });\n * console.log(dbml);\n * ```\n *\n * To include JSDoc comments as DBML Note clauses, use the `source` option:\n * ```typescript\n * const dbml = mysqlGenerate({ schema: { users }, source: \"./schema.ts\" });\n * ```\n */\nexport function mysqlGenerate<TSchema extends Record<string, unknown>>(\n options: GenerateOptions<TSchema>,\n): string {\n const generator = new MySqlGenerator(options);\n const dbml = generator.generate();\n\n if (options.out) {\n writeDbmlFile(options.out, dbml);\n }\n\n return dbml;\n}\n"],"names":["MySqlGenerator","BaseGenerator","name","column","mysqlGenerate","options","dbml","writeDbmlFile"],"mappings":";AAUO,MAAMA,UAEHC,EAAuB;AAAA,EACrB,gBAA+B;AAAA,IACvC,YAAY,CAACC,MAAiB,KAAKA,CAAI;AAAA,IACvC,aAAa,CAACC,MAEJA,EAAkD,kBAAkB;AAAA,EAC9E;AAEJ;AAyBO,SAASC,EACdC,GACQ;AAER,QAAMC,IADY,IAAIN,EAAeK,CAAO,EACrB,SAAA;AAEvB,SAAIA,EAAQ,OACVE,EAAcF,EAAQ,KAAKC,CAAI,GAG1BA;AACT;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { BaseGenerator, DialectConfig } from './common';
|
|
2
|
+
import { GenerateOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* PostgreSQL-specific DBML generator
|
|
5
|
+
*
|
|
6
|
+
* Supports JSDoc comment extraction via `sourceFile` or `comments` options.
|
|
7
|
+
* Comments are included as DBML Note clauses for tables and columns.
|
|
8
|
+
*/
|
|
9
|
+
export declare class PgGenerator<TSchema extends Record<string, unknown> = Record<string, unknown>> extends BaseGenerator<TSchema> {
|
|
10
|
+
protected dialectConfig: DialectConfig;
|
|
11
|
+
/**
|
|
12
|
+
* Generate DBML including PostgreSQL-specific constructs like enums
|
|
13
|
+
*/
|
|
14
|
+
generate(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Collect all enum types from the schema
|
|
17
|
+
*/
|
|
18
|
+
private collectEnums;
|
|
19
|
+
/**
|
|
20
|
+
* Generate a PostgreSQL enum definition
|
|
21
|
+
*/
|
|
22
|
+
private generateEnum;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate DBML from a PostgreSQL Drizzle schema
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
|
|
30
|
+
* import { pgGenerate } from "drizzle-docs-generator";
|
|
31
|
+
*
|
|
32
|
+
* const users = pgTable("users", {
|
|
33
|
+
* id: serial("id").primaryKey(),
|
|
34
|
+
* name: text("name").notNull(),
|
|
35
|
+
* email: varchar("email", { length: 255 }).unique(),
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const dbml = pgGenerate({ schema: { users } });
|
|
39
|
+
* console.log(dbml);
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* To include JSDoc comments as DBML Note clauses, use the `source` option:
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const dbml = pgGenerate({ schema: { users }, source: "./schema.ts" });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function pgGenerate<TSchema extends Record<string, unknown>>(options: GenerateOptions<TSchema>): string;
|
|
48
|
+
//# sourceMappingURL=pg.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.d.ts","sourceRoot":"","sources":["../../src/generator/pg.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAA8B,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AACzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;GAKG;AACH,qBAAa,WAAW,CACtB,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjE,SAAQ,aAAa,CAAC,OAAO,CAAC;IAC9B,SAAS,CAAC,aAAa,EAAE,aAAa,CAMpC;IAEF;;OAEG;IACM,QAAQ,IAAI,MAAM;IAmB3B;;OAEG;IACH,OAAO,CAAC,YAAY;IAsBpB;;OAEG;IACH,OAAO,CAAC,YAAY;CASrB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,GAChC,MAAM,CASR"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getTableColumns as u } from "drizzle-orm";
|
|
2
|
+
import { PgEnumColumn as l } from "drizzle-orm/pg-core";
|
|
3
|
+
import { writeDbmlFile as c, BaseGenerator as m, DbmlBuilder as i } from "./common.js";
|
|
4
|
+
class f extends m {
|
|
5
|
+
dialectConfig = {
|
|
6
|
+
escapeName: (e) => `"${e}"`,
|
|
7
|
+
isIncrement: (e) => e.getSQLType().toLowerCase().includes("serial")
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Generate DBML including PostgreSQL-specific constructs like enums
|
|
11
|
+
*/
|
|
12
|
+
generate() {
|
|
13
|
+
const e = new i(), n = this.collectEnums();
|
|
14
|
+
for (const [s, r] of n)
|
|
15
|
+
this.generateEnum(e, s, r), e.line();
|
|
16
|
+
const t = super.generate();
|
|
17
|
+
return t && e.line(t), e.build().trim();
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Collect all enum types from the schema
|
|
21
|
+
*/
|
|
22
|
+
collectEnums() {
|
|
23
|
+
const e = /* @__PURE__ */ new Map(), n = this.getTables();
|
|
24
|
+
for (const t of n) {
|
|
25
|
+
const s = u(t);
|
|
26
|
+
for (const r of Object.values(s))
|
|
27
|
+
if (r instanceof l) {
|
|
28
|
+
const a = r.enum;
|
|
29
|
+
a && !e.has(a.enumName) && e.set(a.enumName, a.enumValues);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return e;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generate a PostgreSQL enum definition
|
|
36
|
+
*/
|
|
37
|
+
generateEnum(e, n, t) {
|
|
38
|
+
e.line(`enum ${this.dialectConfig.escapeName(n)} {`), e.indent();
|
|
39
|
+
for (const s of t)
|
|
40
|
+
e.line(s);
|
|
41
|
+
e.dedent(), e.line("}");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function d(o) {
|
|
45
|
+
const n = new f(o).generate();
|
|
46
|
+
return o.out && c(o.out, n), n;
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
f as PgGenerator,
|
|
50
|
+
d as pgGenerate
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=pg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pg.js","sources":["../../src/generator/pg.ts"],"sourcesContent":["import { type AnyColumn, getTableColumns } from \"drizzle-orm\";\nimport { PgEnumColumn } from \"drizzle-orm/pg-core\";\nimport { BaseGenerator, DbmlBuilder, writeDbmlFile, type DialectConfig } from \"./common\";\nimport type { GenerateOptions } from \"../types\";\n\n/**\n * PostgreSQL-specific DBML generator\n *\n * Supports JSDoc comment extraction via `sourceFile` or `comments` options.\n * Comments are included as DBML Note clauses for tables and columns.\n */\nexport class PgGenerator<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n> extends BaseGenerator<TSchema> {\n protected dialectConfig: DialectConfig = {\n escapeName: (name: string) => `\"${name}\"`,\n isIncrement: (column: AnyColumn) => {\n const sqlType = column.getSQLType().toLowerCase();\n return sqlType.includes(\"serial\");\n },\n };\n\n /**\n * Generate DBML including PostgreSQL-specific constructs like enums\n */\n override generate(): string {\n const dbml = new DbmlBuilder();\n\n // Generate enums first\n const enums = this.collectEnums();\n for (const [name, values] of enums) {\n this.generateEnum(dbml, name, values);\n dbml.line();\n }\n\n // Then generate tables and refs\n const baseOutput = super.generate();\n if (baseOutput) {\n dbml.line(baseOutput);\n }\n\n return dbml.build().trim();\n }\n\n /**\n * Collect all enum types from the schema\n */\n private collectEnums(): Map<string, string[]> {\n const enums = new Map<string, string[]>();\n const tables = this.getTables();\n\n for (const table of tables) {\n const columns = getTableColumns(table);\n\n for (const column of Object.values(columns)) {\n if (column instanceof PgEnumColumn) {\n const enumObj = (\n column as unknown as { enum: { enumName: string; enumValues: string[] } }\n ).enum;\n if (enumObj && !enums.has(enumObj.enumName)) {\n enums.set(enumObj.enumName, enumObj.enumValues);\n }\n }\n }\n }\n\n return enums;\n }\n\n /**\n * Generate a PostgreSQL enum definition\n */\n private generateEnum(dbml: DbmlBuilder, name: string, values: string[]): void {\n dbml.line(`enum ${this.dialectConfig.escapeName(name)} {`);\n dbml.indent();\n for (const value of values) {\n dbml.line(value);\n }\n dbml.dedent();\n dbml.line(\"}\");\n }\n}\n\n/**\n * Generate DBML from a PostgreSQL Drizzle schema\n *\n * @example\n * ```ts\n * import { pgTable, serial, text, varchar } from \"drizzle-orm/pg-core\";\n * import { pgGenerate } from \"drizzle-docs-generator\";\n *\n * const users = pgTable(\"users\", {\n * id: serial(\"id\").primaryKey(),\n * name: text(\"name\").notNull(),\n * email: varchar(\"email\", { length: 255 }).unique(),\n * });\n *\n * const dbml = pgGenerate({ schema: { users } });\n * console.log(dbml);\n * ```\n *\n * To include JSDoc comments as DBML Note clauses, use the `source` option:\n * ```typescript\n * const dbml = pgGenerate({ schema: { users }, source: \"./schema.ts\" });\n * ```\n */\nexport function pgGenerate<TSchema extends Record<string, unknown>>(\n options: GenerateOptions<TSchema>,\n): string {\n const generator = new PgGenerator(options);\n const dbml = generator.generate();\n\n if (options.out) {\n writeDbmlFile(options.out, dbml);\n }\n\n return dbml;\n}\n"],"names":["PgGenerator","BaseGenerator","name","column","dbml","DbmlBuilder","enums","values","baseOutput","tables","table","columns","getTableColumns","PgEnumColumn","enumObj","value","pgGenerate","options","writeDbmlFile"],"mappings":";;;AAWO,MAAMA,UAEHC,EAAuB;AAAA,EACrB,gBAA+B;AAAA,IACvC,YAAY,CAACC,MAAiB,IAAIA,CAAI;AAAA,IACtC,aAAa,CAACC,MACIA,EAAO,WAAA,EAAa,YAAA,EACrB,SAAS,QAAQ;AAAA,EAClC;AAAA;AAAA;AAAA;AAAA,EAMO,WAAmB;AAC1B,UAAMC,IAAO,IAAIC,EAAA,GAGXC,IAAQ,KAAK,aAAA;AACnB,eAAW,CAACJ,GAAMK,CAAM,KAAKD;AAC3B,WAAK,aAAaF,GAAMF,GAAMK,CAAM,GACpCH,EAAK,KAAA;AAIP,UAAMI,IAAa,MAAM,SAAA;AACzB,WAAIA,KACFJ,EAAK,KAAKI,CAAU,GAGfJ,EAAK,MAAA,EAAQ,KAAA;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA,EAKQ,eAAsC;AAC5C,UAAME,wBAAY,IAAA,GACZG,IAAS,KAAK,UAAA;AAEpB,eAAWC,KAASD,GAAQ;AAC1B,YAAME,IAAUC,EAAgBF,CAAK;AAErC,iBAAWP,KAAU,OAAO,OAAOQ,CAAO;AACxC,YAAIR,aAAkBU,GAAc;AAClC,gBAAMC,IACJX,EACA;AACF,UAAIW,KAAW,CAACR,EAAM,IAAIQ,EAAQ,QAAQ,KACxCR,EAAM,IAAIQ,EAAQ,UAAUA,EAAQ,UAAU;AAAA,QAElD;AAAA,IAEJ;AAEA,WAAOR;AAAA,EACT;AAAA;AAAA;AAAA;AAAA,EAKQ,aAAaF,GAAmBF,GAAcK,GAAwB;AAC5E,IAAAH,EAAK,KAAK,QAAQ,KAAK,cAAc,WAAWF,CAAI,CAAC,IAAI,GACzDE,EAAK,OAAA;AACL,eAAWW,KAASR;AAClB,MAAAH,EAAK,KAAKW,CAAK;AAEjB,IAAAX,EAAK,OAAA,GACLA,EAAK,KAAK,GAAG;AAAA,EACf;AACF;AAyBO,SAASY,EACdC,GACQ;AAER,QAAMb,IADY,IAAIJ,EAAYiB,CAAO,EAClB,SAAA;AAEvB,SAAIA,EAAQ,OACVC,EAAcD,EAAQ,KAAKb,CAAI,GAG1BA;AACT;"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { BaseGenerator, DialectConfig } from './common';
|
|
2
|
+
import { GenerateOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* SQLite-specific DBML generator
|
|
5
|
+
*
|
|
6
|
+
* Supports JSDoc comment extraction via `sourceFile` or `comments` options.
|
|
7
|
+
* Comments are included as DBML Note clauses for tables and columns.
|
|
8
|
+
*/
|
|
9
|
+
export declare class SqliteGenerator<TSchema extends Record<string, unknown> = Record<string, unknown>> extends BaseGenerator<TSchema> {
|
|
10
|
+
protected dialectConfig: DialectConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Generate DBML from a SQLite Drizzle schema
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { sqliteTable, integer, text } from "drizzle-orm/sqlite-core";
|
|
18
|
+
* import { sqliteGenerate } from "drizzle-docs-generator";
|
|
19
|
+
*
|
|
20
|
+
* const users = sqliteTable("users", {
|
|
21
|
+
* id: integer("id").primaryKey(),
|
|
22
|
+
* name: text("name").notNull(),
|
|
23
|
+
* email: text("email").unique(),
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const dbml = sqliteGenerate({ schema: { users } });
|
|
27
|
+
* console.log(dbml);
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* To include JSDoc comments as DBML Note clauses, use the `source` option:
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const dbml = sqliteGenerate({ schema: { users }, source: "./schema.ts" });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function sqliteGenerate<TSchema extends Record<string, unknown>>(options: GenerateOptions<TSchema>): string;
|
|
36
|
+
//# sourceMappingURL=sqlite.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/generator/sqlite.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAiB,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD;;;;;GAKG;AACH,qBAAa,eAAe,CAC1B,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CACjE,SAAQ,aAAa,CAAC,OAAO,CAAC;IAC9B,SAAS,CAAC,aAAa,EAAE,aAAa,CAOpC;CACH;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,cAAc,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpE,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC,GAChC,MAAM,CASR"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { writeDbmlFile as n, BaseGenerator as a } from "./common.js";
|
|
2
|
+
class o extends a {
|
|
3
|
+
dialectConfig = {
|
|
4
|
+
escapeName: (e) => `"${e}"`,
|
|
5
|
+
isIncrement: (e) => e.getSQLType().toLowerCase() === "integer" && e.primary
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function i(r) {
|
|
9
|
+
const t = new o(r).generate();
|
|
10
|
+
return r.out && n(r.out, t), t;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
o as SqliteGenerator,
|
|
14
|
+
i as sqliteGenerate
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=sqlite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sqlite.js","sources":["../../src/generator/sqlite.ts"],"sourcesContent":["import type { AnyColumn } from \"drizzle-orm\";\nimport { BaseGenerator, writeDbmlFile, type DialectConfig } from \"./common\";\nimport type { GenerateOptions } from \"../types\";\n\n/**\n * SQLite-specific DBML generator\n *\n * Supports JSDoc comment extraction via `sourceFile` or `comments` options.\n * Comments are included as DBML Note clauses for tables and columns.\n */\nexport class SqliteGenerator<\n TSchema extends Record<string, unknown> = Record<string, unknown>,\n> extends BaseGenerator<TSchema> {\n protected dialectConfig: DialectConfig = {\n escapeName: (name: string) => `\"${name}\"`,\n isIncrement: (column: AnyColumn) => {\n // SQLite uses INTEGER PRIMARY KEY for autoincrement\n const sqlType = column.getSQLType().toLowerCase();\n return sqlType === \"integer\" && column.primary;\n },\n };\n}\n\n/**\n * Generate DBML from a SQLite Drizzle schema\n *\n * @example\n * ```ts\n * import { sqliteTable, integer, text } from \"drizzle-orm/sqlite-core\";\n * import { sqliteGenerate } from \"drizzle-docs-generator\";\n *\n * const users = sqliteTable(\"users\", {\n * id: integer(\"id\").primaryKey(),\n * name: text(\"name\").notNull(),\n * email: text(\"email\").unique(),\n * });\n *\n * const dbml = sqliteGenerate({ schema: { users } });\n * console.log(dbml);\n * ```\n *\n * To include JSDoc comments as DBML Note clauses, use the `source` option:\n * ```typescript\n * const dbml = sqliteGenerate({ schema: { users }, source: \"./schema.ts\" });\n * ```\n */\nexport function sqliteGenerate<TSchema extends Record<string, unknown>>(\n options: GenerateOptions<TSchema>,\n): string {\n const generator = new SqliteGenerator(options);\n const dbml = generator.generate();\n\n if (options.out) {\n writeDbmlFile(options.out, dbml);\n }\n\n return dbml;\n}\n"],"names":["SqliteGenerator","BaseGenerator","name","column","sqliteGenerate","options","dbml","writeDbmlFile"],"mappings":";AAUO,MAAMA,UAEHC,EAAuB;AAAA,EACrB,gBAA+B;AAAA,IACvC,YAAY,CAACC,MAAiB,IAAIA,CAAI;AAAA,IACtC,aAAa,CAACC,MAEIA,EAAO,WAAA,EAAa,YAAA,MACjB,aAAaA,EAAO;AAAA,EACzC;AAEJ;AAyBO,SAASC,EACdC,GACQ;AAER,QAAMC,IADY,IAAIN,EAAgBK,CAAO,EACtB,SAAA;AAEvB,SAAIA,EAAQ,OACVE,EAAcF,EAAQ,KAAKC,CAAI,GAG1BA;AACT;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* drizzle-docs-generator
|
|
3
|
+
*
|
|
4
|
+
* A CLI tool that generates DBML files from Drizzle ORM schema definitions.
|
|
5
|
+
*
|
|
6
|
+
* Supports extracting JSDoc comments from source files and including them
|
|
7
|
+
* as DBML Note clauses using the TypeScript Compiler API.
|
|
8
|
+
*/
|
|
9
|
+
export { extractComments } from './parser/index';
|
|
10
|
+
export type { SchemaComments, TableComment, ColumnComment } from './parser/index';
|
|
11
|
+
export { pgGenerate, PgGenerator, mysqlGenerate, MySqlGenerator, sqliteGenerate, SqliteGenerator, BaseGenerator, DbmlBuilder, writeDbmlFile, } from './generator/index';
|
|
12
|
+
export type { GenerateOptions, GeneratedRef, ColumnAttributes, RelationType } from './types';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGlF,OAAO,EACL,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACb,WAAW,EACX,aAAa,GACd,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAAE,eAAe,EAAE,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { extractComments as a } from "./parser/comments.js";
|
|
2
|
+
import "typescript";
|
|
3
|
+
import "node:fs";
|
|
4
|
+
import "node:path";
|
|
5
|
+
import { PgGenerator as i, pgGenerate as l } from "./generator/pg.js";
|
|
6
|
+
import { MySqlGenerator as G, mysqlGenerate as x } from "./generator/mysql.js";
|
|
7
|
+
import { SqliteGenerator as q, sqliteGenerate as s } from "./generator/sqlite.js";
|
|
8
|
+
import { BaseGenerator as g, DbmlBuilder as y, writeDbmlFile as B } from "./generator/common.js";
|
|
9
|
+
export {
|
|
10
|
+
g as BaseGenerator,
|
|
11
|
+
y as DbmlBuilder,
|
|
12
|
+
G as MySqlGenerator,
|
|
13
|
+
i as PgGenerator,
|
|
14
|
+
q as SqliteGenerator,
|
|
15
|
+
a as extractComments,
|
|
16
|
+
x as mysqlGenerate,
|
|
17
|
+
l as pgGenerate,
|
|
18
|
+
s as sqliteGenerate,
|
|
19
|
+
B as writeDbmlFile
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comments for a single column
|
|
3
|
+
*/
|
|
4
|
+
export interface ColumnComment {
|
|
5
|
+
comment: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Comments for a single table
|
|
9
|
+
*/
|
|
10
|
+
export interface TableComment {
|
|
11
|
+
comment?: string;
|
|
12
|
+
columns: Record<string, ColumnComment>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* All extracted comments from a schema file
|
|
16
|
+
*/
|
|
17
|
+
export interface SchemaComments {
|
|
18
|
+
tables: Record<string, TableComment>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Extract JSDoc comments from a Drizzle schema source file or directory
|
|
22
|
+
*
|
|
23
|
+
* Parses TypeScript source files and extracts:
|
|
24
|
+
* - JSDoc comments on table definitions (e.g., pgTable, mysqlTable, sqliteTable)
|
|
25
|
+
* - JSDoc comments on column definitions within tables
|
|
26
|
+
*
|
|
27
|
+
* @param sourcePath - Path to the TypeScript schema file or directory
|
|
28
|
+
* @returns Extracted comments organized by table and column
|
|
29
|
+
*/
|
|
30
|
+
export declare function extractComments(sourcePath: string): SchemaComments;
|
|
31
|
+
//# sourceMappingURL=comments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comments.d.ts","sourceRoot":"","sources":["../../src/parser/comments.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CACtC;AA+BD;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAalE"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import * as r from "typescript";
|
|
2
|
+
import { readFileSync as g, statSync as b, readdirSync as C } from "node:fs";
|
|
3
|
+
import { join as y } from "node:path";
|
|
4
|
+
function p(t) {
|
|
5
|
+
const n = b(t);
|
|
6
|
+
if (n.isFile())
|
|
7
|
+
return t.endsWith(".ts") ? [t] : [];
|
|
8
|
+
if (n.isDirectory()) {
|
|
9
|
+
const i = [], o = C(t, { withFileTypes: !0 });
|
|
10
|
+
for (const e of o) {
|
|
11
|
+
const s = y(t, e.name);
|
|
12
|
+
e.isDirectory() ? i.push(...p(s)) : e.isFile() && e.name.endsWith(".ts") && !e.name.endsWith(".test.ts") && i.push(s);
|
|
13
|
+
}
|
|
14
|
+
return i;
|
|
15
|
+
}
|
|
16
|
+
return [];
|
|
17
|
+
}
|
|
18
|
+
function L(t) {
|
|
19
|
+
const n = { tables: {} }, i = p(t);
|
|
20
|
+
for (const o of i) {
|
|
21
|
+
const e = g(o, "utf-8"), s = r.createSourceFile(o, e, r.ScriptTarget.Latest, !0);
|
|
22
|
+
d(s, s, n);
|
|
23
|
+
}
|
|
24
|
+
return n;
|
|
25
|
+
}
|
|
26
|
+
function d(t, n, i) {
|
|
27
|
+
if (r.isVariableStatement(t)) {
|
|
28
|
+
const o = x(t, n);
|
|
29
|
+
for (const e of t.declarationList.declarations)
|
|
30
|
+
if (r.isIdentifier(e.name) && e.initializer && r.isCallExpression(e.initializer)) {
|
|
31
|
+
const s = h(
|
|
32
|
+
e.name.text,
|
|
33
|
+
e.initializer,
|
|
34
|
+
n,
|
|
35
|
+
o
|
|
36
|
+
);
|
|
37
|
+
s && (i.tables[s.tableName] = s.tableComment);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
r.forEachChild(t, (o) => d(o, n, i));
|
|
41
|
+
}
|
|
42
|
+
function h(t, n, i, o) {
|
|
43
|
+
const e = T(n);
|
|
44
|
+
if (!S(e))
|
|
45
|
+
return;
|
|
46
|
+
const s = n.arguments[0];
|
|
47
|
+
if (!s || !r.isStringLiteral(s))
|
|
48
|
+
return;
|
|
49
|
+
const c = s.text, m = n.arguments[1], f = {};
|
|
50
|
+
if (m && r.isObjectLiteralExpression(m)) {
|
|
51
|
+
for (const a of m.properties)
|
|
52
|
+
if (r.isPropertyAssignment(a) && r.isIdentifier(a.name)) {
|
|
53
|
+
const l = v(a.initializer), u = x(a, i);
|
|
54
|
+
l && u && (f[l] = { comment: u });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
tableName: c,
|
|
59
|
+
tableComment: {
|
|
60
|
+
comment: o,
|
|
61
|
+
columns: f
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function T(t) {
|
|
66
|
+
if (r.isIdentifier(t.expression))
|
|
67
|
+
return t.expression.text;
|
|
68
|
+
if (r.isPropertyAccessExpression(t.expression))
|
|
69
|
+
return t.expression.name.text;
|
|
70
|
+
}
|
|
71
|
+
function S(t) {
|
|
72
|
+
return t ? ["pgTable", "mysqlTable", "sqliteTable"].includes(t) : !1;
|
|
73
|
+
}
|
|
74
|
+
function v(t) {
|
|
75
|
+
let n = t;
|
|
76
|
+
for (; r.isCallExpression(n); )
|
|
77
|
+
if (r.isPropertyAccessExpression(n.expression))
|
|
78
|
+
n = n.expression.expression;
|
|
79
|
+
else if (r.isIdentifier(n.expression)) {
|
|
80
|
+
const i = n.arguments[0];
|
|
81
|
+
return i && r.isStringLiteral(i) ? i.text : void 0;
|
|
82
|
+
} else
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
function x(t, n) {
|
|
86
|
+
const i = n.getFullText(), o = t.getFullStart(), e = r.getLeadingCommentRanges(i, o);
|
|
87
|
+
if (!(!e || e.length === 0)) {
|
|
88
|
+
for (const s of e) {
|
|
89
|
+
const c = i.slice(s.pos, s.end);
|
|
90
|
+
if (c.startsWith("/**"))
|
|
91
|
+
return D(c);
|
|
92
|
+
}
|
|
93
|
+
for (const s of e) {
|
|
94
|
+
const c = i.slice(s.pos, s.end);
|
|
95
|
+
if (c.startsWith("//"))
|
|
96
|
+
return c.slice(2).trim();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function D(t) {
|
|
101
|
+
const i = t.slice(3, -2).split(`
|
|
102
|
+
`).map((e) => e.replace(/^\s*\*\s?/, "").trim()), o = [];
|
|
103
|
+
for (const e of i) {
|
|
104
|
+
if (e.startsWith("@"))
|
|
105
|
+
break;
|
|
106
|
+
o.push(e);
|
|
107
|
+
}
|
|
108
|
+
return o.join(" ").trim();
|
|
109
|
+
}
|
|
110
|
+
export {
|
|
111
|
+
L as extractComments
|
|
112
|
+
};
|
|
113
|
+
//# sourceMappingURL=comments.js.map
|
|
@@ -0,0 +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,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