diff --git a/README.md b/README.md index ad31f62..aed895d 100755 --- a/README.md +++ b/README.md @@ -260,6 +260,8 @@ export class ProductDto extends IntersectionType( - puts relational fields into different file for each model. This way the class will match the object returned by a Prisma query, default value is **false** - _clientImportPath_ - set prisma client import path manually, default value is **@prisma/client** +- _useClassTransformerExpose_ + - annotate all properties with @Expose - _useNonNullableAssertions_ - Apply a ! after non-optional class fields to avoid strict mode warnings (Property has no initializer and is not definitely assigned in the constructor.) - _preserveDefaultNullable_ diff --git a/prisma/v7.prisma b/prisma/v7.prisma index 2aec5d7..cb48799 100644 --- a/prisma/v7.prisma +++ b/prisma/v7.prisma @@ -9,12 +9,13 @@ generator client { } generator prismaClassGenerator { - provider = "node -r ts-node/register/transpile-only src/index.ts" - output = "../src/_gen/prisma-class" - dryRun = "false" - separateRelationFields = "false" - useClassValidator = "true" - usePrismaJsonValue = "true" + provider = "node -r ts-node/register/transpile-only src/index.ts" + output = "../src/_gen/prisma-class" + dryRun = "false" + separateRelationFields = "false" + useClassValidator = "true" + usePrismaJsonValue = "true" + useClassTransformerExpose = "true" } enum TestEnum { diff --git a/src/convertor.ts b/src/convertor.ts index c7e1950..6d079ea 100755 --- a/src/convertor.ts +++ b/src/convertor.ts @@ -641,6 +641,17 @@ export class PrismaConvertor { return decorators; } + extractClassTransformerDecoratorsFromField = (dmmfField: DMMF.Field) => { + const decorators = []; + + decorators.push(new DecoratorComponent({ + name: 'Expose', + importFrom: 'class-transformer', + })) + + return decorators; + } + convertField = (dmmfField: DMMF.Field, relationField: boolean): FieldComponent => { const field = new FieldComponent({ name: dmmfField.name, @@ -658,6 +669,11 @@ export class PrismaConvertor { field.decorators.push(...decorators) } + if (this.config.useClassTransformerExpose) { + const decorators = this.extractClassTransformerDecoratorsFromField(dmmfField); + field.decorators.push(...decorators) + } + if (this.config.useGraphQL) { const decorator = this.extractTypeGraphQLDecoratorFromField(dmmfField) diff --git a/src/generator.ts b/src/generator.ts index 6e3b261..a3524e4 100755 --- a/src/generator.ts +++ b/src/generator.ts @@ -57,6 +57,10 @@ export const PrismaClassGeneratorOptions = { desc: 'use class validator', defaultValue: false }, + useClassTransformerExpose: { + desc: 'annotate all properties with @Expose', + defaultValue: false + }, usePrismaJsonValue: { desc: 'use Prisma JsonValue type instead of object for Json fields', defaultValue: false,