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

Configuration for type suffixes and prettier config + other breaking changes #13

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

joshmossas
Copy link

Type suffix is now configurable, but omitted by default

This fixes #11 by omitting the typeSuffix in outputted code by default which is a breaking change.

If a type suffix is still desired it can now be configured in the schema.prisma file as follows:

generator typebox {
  provider = "prisma-typebox-generator"
  typeSuffix = "Type"
}

Customize code style of outputted code by specifying a prettier config

This PR adds a configuration option letting you link to a prettier config as follows:

generator typebox {
  provider = "prisma-typebox-generator"
  prettierConfig = "<path-to-config-file>"
}

This allows users to more easily make the generated code match the code style of their codebase. Under the hood this feature uses c12, which allows us to support json, typescript, and javascript configuration files. (The c12 library was created by the nuxtjs and unjs team so I think it's safe to add it as a dependency as it's very likely to remain well maintained.)

Automatically add the $id property to generated models.

Given the following prisma schema

model User {
  id String @id @default(uuid())
  name String
}

The generator will now output

export const User = Type.Object(
  {
    id: Type.String(),
    name: Type.String(),
  }, 
  { $id: 'User' } // note this line
)

I'm on the fence as to whether this should be the default behavior or whether this is something that should be toggleable through the configuration in the schema.prisma. I guess regardless it would be good to have it be configurable somehow. If we do add another configuration field I wonder what we should call it...

Dependency Updates and Other Changes

  • replace yarn with pnpm
  • remove deprecated @prisma/sdk dependency and replace it with @prisma/internals
  • update @prisma/generator-helper to v5.2.0
  • update core-js to v3.32.1
  • update prettier to v3.0.3
  • add c12 as a dependency to support json, ts, and js prettier config files
  • update all dev dependencies

@joshmossas
Copy link
Author

@adeyahya I know there's alot here so lemme know if anything needs to be reverted or changed.

For example I imagine the yarn > pnpm change might break some CI stuff along with potentially the @semantic-release updates

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

Successfully merging this pull request may close these issues.

Naming conflict of exported member. Cannot use the word Type in schema.prisma
1 participant