Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] @tsed/prisma should create classes for prisma type definitions #2135

Closed
1 task
aksharp12 opened this issue Oct 24, 2022 · 6 comments · Fixed by #2175
Closed
1 task

[FEAT] @tsed/prisma should create classes for prisma type definitions #2135

aksharp12 opened this issue Oct 24, 2022 · 6 comments · Fixed by #2175

Comments

@aksharp12
Copy link

aksharp12 commented Oct 24, 2022

Information

  • Version: 7.2.3
  • Packages:
  • @prisma/client: 4.5.0

prisma schema.prisma files allow the definition of type which can provide type safety for su-objects in a model. When using the @tsed/prisma generator, there is an exception that is thrown stating that there was an exception trying to access a property of name which is undefined.

The exception occurs here and here. The issue is that tsed only checks for models and no other objects that are supported by prisma

Example

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["interactiveTransactions"]
}
datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}
generator tsed {
  provider = "tsed-prisma"
  output   = "../node_modules/prisma"
}
model User {
  /// @TsED.Groups("!creation")
  id        String   @id @default(auto()) @map("_id") @db.ObjectId
  /// @TsED.Email()
  email     String   @unique
  info      Info
  /// @TsED.Groups("!creation")
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
type Info {
  firstName String
  lastName  String
}

Acceptance criteria

  • running prisma generate, while using the @tsed/prisma generator and having types outside of just model in the schema.prisma, should successfully generate the correct classes and models.
@Romakita
Copy link
Collaborator

Hello @aksharp12

Thank you for the PR ;)

I think the Type should be an interface and not a class. right ?

See you
Romain

@aksharp12
Copy link
Author

Not a problem at all, @Romakita!

Yes, I would think that an interface would be enough. There is no need for a repository to be generated either since types are referenced in models for prisma

@Romakita Romakita changed the title [BUG] @tsed/prisma should create classes for prisma type definitions [FEAT] @tsed/prisma should create classes for prisma type definitions Nov 5, 2022
@Romakita Romakita moved this to To do in Global Board Nov 25, 2022
@Romakita Romakita removed the status in Global Board Nov 25, 2022
@Romakita
Copy link
Collaborator

Finally, the generator will generate a class. It's better to have class for the json-mapper and there is no extra code to support it :)

@Romakita Romakita moved this to Review in progress in Global Board Nov 25, 2022
@Romakita Romakita linked a pull request Nov 25, 2022 that will close this issue
@Romakita
Copy link
Collaborator

@aksharp12 PR Ready #2175

Romakita added a commit that referenced this issue Nov 25, 2022
Romakita added a commit that referenced this issue Nov 25, 2022
Repository owner moved this from Review in progress to Done in Global Board Nov 25, 2022
@github-actions
Copy link

🎉 Are you happy?

If you appreciated the support, know that it is free and is carried out on personal time ;)

A support, even a little bit makes a difference for me and continues to bring you answers!

github opencollective

@Romakita
Copy link
Collaborator

🎉 This issue has been resolved in version 7.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants