From 7dfdb079f38290e797fbe1e78eb8f160bce7f912 Mon Sep 17 00:00:00 2001 From: Thomas Robinson Date: Wed, 2 Jul 2025 18:28:07 +1000 Subject: [PATCH] Add comment generation to typescript interfaces --- package-lock.json | 4 ++-- src/builders/ModelBuilder.ts | 16 ++++++++++------ src/tests/integration/mariadb/queries.ts | 2 +- src/tests/integration/mssql/queries.ts | 6 ++++++ src/tests/integration/mysql/queries.ts | 2 +- src/tests/integration/postgres/queries.ts | 1 + 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index f07d0d6..f1d7ec9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "sequelize-typescript-generator", - "version": "11.0.8", + "version": "12.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "sequelize-typescript-generator", - "version": "11.0.8", + "version": "12.0.1", "license": "ISC", "dependencies": { "@types/eslint": "^8.56.5", diff --git a/src/builders/ModelBuilder.ts b/src/builders/ModelBuilder.ts index ac1e812..6e47e39 100644 --- a/src/builders/ModelBuilder.ts +++ b/src/builders/ModelBuilder.ts @@ -186,13 +186,17 @@ export class ModelBuilder extends Builder { undefined, undefined, [ - ...(Object.values(columns).map(c => ts.factory.createPropertySignature( - undefined, - ts.factory.createIdentifier(c.name), - c.autoIncrement || c.allowNull || c.defaultValue !== undefined ? + ...(Object.values(columns).map(c => { + const property = ts.factory.createPropertySignature( + undefined, + ts.factory.createIdentifier(c.name), + c.autoIncrement || c.allowNull || c.defaultValue !== undefined ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined, - ts.factory.createTypeReferenceNode(dialect.mapDbTypeToJs(c.type) ?? 'any', undefined) - ))) + ts.factory.createTypeReferenceNode(dialect.mapDbTypeToJs(c.type) ?? 'any', undefined) + ) + return c.comment ? ts.addSyntheticLeadingComment(property, ts.SyntaxKind.MultiLineCommentTrivia, `* ${c.comment}`, true) : property + }) + ) ] ); diff --git a/src/tests/integration/mariadb/queries.ts b/src/tests/integration/mariadb/queries.ts index 9642d02..db293ac 100644 --- a/src/tests/integration/mariadb/queries.ts +++ b/src/tests/integration/mariadb/queries.ts @@ -70,7 +70,7 @@ export const AUTHORS_TABLE_CREATES = [ ` CREATE TABLE ${AUTHORS_TABLE_NAME} ( - author_id INT primary key, + author_id INT primary key COMMENT 'This column stores the PK', full_name VARCHAR(80) not null ); `, diff --git a/src/tests/integration/mssql/queries.ts b/src/tests/integration/mssql/queries.ts index 8567d7e..5718d15 100644 --- a/src/tests/integration/mssql/queries.ts +++ b/src/tests/integration/mssql/queries.ts @@ -81,6 +81,12 @@ export const AUTHORS_TABLE_CREATES = [ full_name VARCHAR(80) not null ); `, + `EXEC sp_addextendedproperty + @name = N'MS_Description', + @value = 'This column stores the PK', + @level0type = N'SCHEMA', @level0name = 'dbo', + @level1type = N'TABLE', @level1name = 'authors', + @level2type = N'COLUMN', @level2name = 'author_id';` ]; export const AUTHORS_TABLE_INSERTS = [ `INSERT INTO ${AUTHORS_TABLE_NAME} VALUES (1, 'Isasc Asimov');`, diff --git a/src/tests/integration/mysql/queries.ts b/src/tests/integration/mysql/queries.ts index 54ef85d..2010f42 100644 --- a/src/tests/integration/mysql/queries.ts +++ b/src/tests/integration/mysql/queries.ts @@ -70,7 +70,7 @@ export const AUTHORS_TABLE_CREATES = [ ` CREATE TABLE ${AUTHORS_TABLE_NAME} ( - author_id INT primary key, + author_id INT primary key COMMENT 'This column stores the PK', full_name VARCHAR(80) not null ); `, diff --git a/src/tests/integration/postgres/queries.ts b/src/tests/integration/postgres/queries.ts index 2b1ddaf..03903bb 100644 --- a/src/tests/integration/postgres/queries.ts +++ b/src/tests/integration/postgres/queries.ts @@ -93,6 +93,7 @@ export const AUTHORS_TABLE_CREATES = [ full_name VARCHAR(80) not null ); `, + `COMMENT ON COLUMN public.authors.author_id IS 'This column stores the PK';` ]; export const AUTHORS_TABLE_INSERTS = [ `INSERT INTO ${SCHEMA_NAME}.${AUTHORS_TABLE_NAME} VALUES (1, 'Isasc Asimov');`,