feat: generate JSDoc from column comments

This commit is contained in:
theoludwig committed 2026-10-02 16:51:15 +02:00
1 parent 3849b14615
commit ff16be6787
6 files changed
+74 -3

No files matched your search

+21
View File
@@ -73,6 +73,24 @@ export abstract class KyselyTypegenDialect {
return scalars[dataType] ?? "unknown"
}
protected formatColumnComment(comment: string): string[] {
const trimmedComment = comment.trim()
if (trimmedComment.length === 0) {
return []
}
const lines = trimmedComment.replaceAll("*/", "*\\/").split(/\r?\n/u)
if (lines.length === 1) {
return [` /** ${lines[0]} */`]
}
return [
" /**",
...lines.map((line) => {
return line.length === 0 ? " *" : ` * ${line}`
}),
" */",
]
}
public getTablesTypegen(
tables: TableMetadata[],
enums: EnumMetadata[],
@@ -94,6 +112,9 @@ export abstract class KyselyTypegenDialect {
if (column.hasDefaultValue || column.isAutoIncrementing) {
columnType = `Generated<${columnType}>`
}
if (column.comment != null) {
result.push(...this.formatColumnComment(column.comment))
}
result.push(` ${column.name}: ${columnType}`)
}
result.push("}", "")