Prisma +2 generator to emit Yup schemas from your Prisma schema

Overview

Prisma Yup Generator

npm version npm HitCount npm

Automatically generate Yup schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have. Updates every time npx prisma generate runs.

Table of Contents

Installation

Using npm:

 npm install prisma-yup-generator

Using yarn:

 yarn add prisma-yup-generator

Usage

1- Star this repo 😉

2- Add the generator to your Prisma schema

generator yup {
  provider = "prisma-yup-generator"
}

3- Running npx prisma generate for the following schema.prisma

model User {
  id    Int     @id @default(autoincrement())
  email String  @unique
  name  String?
  posts Post[]
}

model Post {
  id        Int      @id @default(autoincrement())
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  title     String
  content   String?
  published Boolean  @default(false)
  viewCount Int      @default(0)
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  Int?
}

will generate the following files

Yup Schemas

4- Use generated schemas somewhere in your API logic, like middleware or decorator

import { PostCreateOneSchema } from './prisma/generated/schemas/createOnePost.schema';

app.post('/blog', async (req, res, next) => {
  const { body } = req;
  await PostCreateOneSchema.validate(body);
});

Additional Options

Option  Description Type  Default
output Output directory for the generated yup schemas string ./generated

Use additional options in the schema.prisma

generator yup {
  provider   = "prisma-yup-generator"
  output     = "./generated-yup-schemas"
}
Comments
  • circular deps generated

    circular deps generated

    Bug description

    Hi, the generated output circular references blocking bundlers like webpack. It would be very beneficial to solve this so that we can bundle it for web.

    How to reproduce

    // config.next.js
    /* eslint-disable @typescript-eslint/no-var-requires */
    const CircularDependencyPlugin = require('circular-dependency-plugin')
    
    module.exports = withTM({
      reactStrictMode: true,
      swcMinify: false,
      future: {
        webpack5: true, // by default, if you customize webpack config, they switch back to version 4.
        // Looks like backward compatibility approach.
      },
      webpack(config) {
        const circularDependencyPlugin = new CircularDependencyPlugin({
          // exclude detection of files based on a RegExp
          exclude: /a\.js|node_modules/,
          // include specific files based on a RegExp
          // include: //,
          // add errors to webpack instead of warnings
          failOnError: true,
          // allow import cycles that include an asyncronous import,
          // e.g. via import(/* webpackMode: "weak" */ './file.js')
          allowAsyncCycles: false,
          // set the current working directory for displaying module paths
          cwd: process.cwd(),
          // `onStart` is called before the cycle detection starts
          onStart({ compilation }) {
            console.log('start detecting webpack modules cycles')
          },
          // `onDetected` is called for each module that is cyclical
          onDetected({ module: webpackModuleRecord, paths, compilation }) {
            console.log('new CD error')
            console.log(paths)
            // `paths` will be an Array of the relative module paths that make up the cycle
            // `module` will be the module record generated by webpack that caused the cycle
            compilation.errors.push(new Error(paths.join(' -> ')))
          },
          // `onEnd` is called before the cycle detection ends
          onEnd({ compilation }) {
            console.log('end detecting webpack modules cycles')
          },
        })
        config.plugins.push(circularDependencyPlugin)
        return config
      },
    })
    

    Expected behavior

    No circular references to exist. It should be avoidable by following this paradigm that exports everything from one file: https://medium.com/visual-development/how-to-fix-nasty-circular-dependency-issues-once-and-for-all-in-javascript-typescript-a04c987cf0de

    Prisma information

    // prisma/schema.prisma

    datasource db { provider = "postgresql" url = env("DATABASE_URL") }

    generator client { provider = "prisma-client-js" previewFeatures = ["interactiveTransactions"] }

    generator fieldEncryptionMigrations { provider = "prisma-field-encryption" output = "./migrations" }

    generator typegraphql { provider = "typegraphql-prisma" output = "../node_modules/.cache/type-graphql" }

    generator yup { provider = "prisma-yup-generator" output = "../src/prisma/gen" }

    generator erd { provider = "prisma-erd-generator" output = "../docs/diagrams/entity-relationship-diagram.svg" }

    enum Role { ADMIN USER }

    enum OrgRole { OWNER ADMIN MEMBER }

    enum Tier { FREE PRO ENTERPRISE }

    enum PaymentStatus { PENDING PAID }

    model License { tier Tier price Int description String

    @@unique([tier]) }

    enum InvoicePeriod { MONTHLY YEARLY }

    model Account { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt userId String type String provider String providerAccountId String refresh_token String? @map("refreshToken") @db.Text access_token String? @map("accessToken") @db.Text expires_at Int? @map("expiresAt") token_type String? @map("tokenType") scope String? id_token String? @map("idToken") @db.Text session_state String? @map("sessionState") user User @relation(fields: [userId], references: [id], onDelete: Cascade) tier Tier @default(FREE) // may be upgraded to PRO then ENTERPRISE clusters Cluster[] organisation Organisation? invoice Invoice[]

    @@unique([provider, providerAccountId]) }

    model Session { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt userId String expires DateTime session_token String @unique @map("sessionToken") user User @relation(fields: [userId], references: [id], onDelete: Cascade) }

    model User { id String @id @default(cuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt name String? email String? @unique emailVerified DateTime? image String? phoneNumber String? /// @encrypted address String? /// @encrypted country String? state String? city String? /// @encrypted zipCode String? /// @encrypted avatarUrl String? /// @encrypted company String?

    role Role @default(USER) accounts Account[] sessions Session[] userOrgs UserOrg[] }

    model VerificationToken { identifier String token String @unique expires DateTime

    @@unique([identifier, token]) }

    model UserOrg { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt userId String @map("user_id") organisationId String role OrgRole user User @relation(fields: [userId], references: [id], onDelete: Cascade) organisation Organisation @relation(fields: [organisationId], references: [id])

    @@id([userId, organisationId]) }

    model Invoice { id String @id @default(uuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt accountId String price Int // no fractions, will be exactly as paid in EURO at that moment in time status PaymentStatus period InvoicePeriod startDate DateTime endDate DateTime

    account Account @relation(fields: [accountId], references: [id]) }

    model Organisation { id String @id @default(uuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt accountId String @unique name String @unique image String?

    account Account @relation(fields: [accountId], references: [id]) orgUsers UserOrg[] }

    model Cluster { id String @id @default(uuid()) createdAt DateTime @default(now()) updatedAt DateTime @updatedAt key String @default(cuid()) accountId String name String description String provider String kubecfg String?

    account Account @relation(fields: [accountId], references: [id]) }

    Environment & setup

    • OS: Mac OS
    • Database: PostgreSQL
    • Node.js version: 16.14.2

    Prisma Version

    3.14.0
    
    bug 
    opened by Morriz 9
  • Upcoming rename of `@prisma/sdk` to `@prisma/internals` with Prisma 4

    Upcoming rename of `@prisma/sdk` to `@prisma/internals` with Prisma 4

    Hey,

    Jan from Prisma Engineering here.

    Quick heads up that we will soon rename our @prisma/sdk package to @prisma/internals with Prisma 4, which we plan to release on June 28th (soon!).

    The @prisma/sdk package was meant as an Prisma internal package only, but somehow it leaked out over time and is now used across all kinds of tools - including yours of course 😄

    With the rename of the Npm package we want to make it clearer that we can not give any API guarantees for @prisma/internals, might need to introduce breaking changes to the API from time to time and will not follow semantic versioning (breaking changes only in major upgrade) with it. We think that it is better communicated with internals than with sdk. With Prisma 4, besides the package name nothing should change though.

    Additionally it would be super helpful if you could help us gain an understanding where, how and why you are using @prisma/sdk (soon @prisma/internals, remember 😀) to achieve, what exactly. We want to cleanup that package and your feedback will be valuable to us to define a better API.

    Looking forward to your feedback.

    Best Jan & your friends at Prisma

    PS: Are you using Prisma.dmmf from import { Prisma } from '@prisma/client' in your code somewhere by chance? That will also change soon and not include the Prisma.dmmf.schema sub property. Instead you can use getDmmf from @prisma/internals moving forward.

    opened by janpio 4
  • don't generate redundant code

    don't generate redundant code

    Problem

    Hi, all your objects/*.schema files contain redundant code. The top definition is always copied to be used in the exported Yup.object({....

    Suggested solution

    Just export like this:

    export const UserUpdateInputObject = ...
    ...
    export const UserUpdateInputObjectSchema = Yup.object(UserUpdateInputObject)
    
    enhancement 
    opened by Morriz 4
  • error - ReferenceError: Cannot access 'AccountWhereInputObjectSchema' before initialization

    error - ReferenceError: Cannot access 'AccountWhereInputObjectSchema' before initialization

    Bug description

    I'm getting the following error with v0.1.4:

    error - ReferenceError: Cannot access 'AccountWhereInputObjectSchema' before initialization
    

    How to reproduce

    having the following code in the api:

    await GameCreateSchema.validate({
        ...body,
        userId,
    })
    

    Expected behavior

    No response

    Prisma information

    see #6

    Environment & setup

    see #6

    Prisma Version

    prisma                  : 3.15.1
    @prisma/client          : 3.15.1
    Current platform        : darwin-arm64
    Query Engine (Node-API) : libquery-engine 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
    Migration Engine        : migration-engine-cli 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
    Introspection Engine    : introspection-core 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
    Format Binary           : prisma-fmt 461d6a05159055555eb7dfb337c9fb271cbd4d7e (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
    Default Engines Hash    : 461d6a05159055555eb7dfb337c9fb271cbd4d7e
    Studio                  : 0.462.0
    
    bug 
    opened by felixerdy 3
  • Module not found: Can't resolve './NullableJsonNullValueInput.schema'

    Module not found: Can't resolve './NullableJsonNullValueInput.schema'

    Bug description

    My application can't resolve NullableJsonNullValueInput.schema which is placed in prisma/generated/schemas/enums

    The files that want to require this file are however located in prisma/generated/schemas/objects

    How to reproduce

    QuestCreateManyRoomInput.schema.ts uses

    import { NullableJsonNullValueInputSchemaObject } from './NullableJsonNullValueInput.schema'

    Expected behavior

    but it should use

    import { NullableJsonNullValueInputSchemaObject } from '../enum/NullableJsonNullValueInput.schema'

    Prisma information

    // This is your Prisma schema file,
    // learn more about it in the docs: https://pris.ly/d/prisma-schema
    
    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    model Account {
      id                String  @id @default(cuid())
      userId            String
      type              String
      provider          String
      providerAccountId String
      refresh_token     String? @db.Text
      access_token      String? @db.Text
      expires_at        Int?
      token_type        String?
      scope             String?
      id_token          String? @db.Text
      session_state     String?
    
      user User @relation(fields: [userId], references: [id], onDelete: Cascade)
    
      @@unique([provider, providerAccountId])
    }
    
    model Session {
      id           String   @id @default(cuid())
      sessionToken String   @unique
      userId       String
      expires      DateTime
      user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
    }
    
    model User {
      id            String    @id @default(cuid())
      name          String?
      email         String?   @unique
      emailVerified DateTime?
      image         String?
      accounts      Account[]
      sessions      Session[]
      Games         Game[]
      S3Image       S3Image[]
    }
    
    model VerificationToken {
      identifier String
      token      String   @unique
      expires    DateTime
    
      @@unique([identifier, token])
    }
    
    model Game {
      id          String   @id @default(uuid())
      name        String?
      description String?
      draft       Boolean  @default(true)
      user        User     @relation(fields: [userId], references: [id], onDelete: Cascade)
      userId      String
      rooms       Room[]
      createdAt   DateTime @default(now())
      updatedAt   DateTime @default(now())
    }
    
    model Room {
      id        String   @id @default(uuid())
      game      Game     @relation(fields: [gameId], references: [id], onDelete: Cascade)
      gameId    String
      createdAt DateTime @default(now())
      updatedAt DateTime @default(now())
      image     S3Image?
      quests    Quest[]
    }
    
    model S3Image {
      id        String   @id @default(uuid())
      user      User     @relation(fields: [userId], references: [id])
      userId    String
      url       String
      createdAt DateTime @default(now())
      updatedAt DateTime @default(now())
      room      Room     @relation(fields: [roomId], references: [id], onDelete: Cascade)
      roomId    String   @unique
    }
    
    model Quest {
      id        String     @id @default(uuid())
      createdAt DateTime   @default(now())
      updatedAt DateTime   @default(now())
      room      Room       @relation(fields: [roomId], references: [id], onDelete: Cascade)
      roomId    String
      x         Float
      y         Float
      type      QuestType?
      data      Json?      @default(dbgenerated())
    }
    
    enum QuestType {
      QUEST_CRYPTO
      QUEST_CODING
      QUEST_QR_SCAN
      QUEST_STATISTICS
      MEDIA_TEXT
      MEDIA_IMAGE
      MEDIA_INSTAGRAM
      MEDIA_YOUTUBE
      MEDIA_IFRAME
    }
    
    generator yup {
      provider = "prisma-yup-generator"
    }
    

    Environment & setup

    • OS: macOS 12.2.1
    • Database: PostgreSQL 13
    • Node.js version: v16.14.2

    Prisma Version

    prisma                  : 3.14.0
    @prisma/client          : 3.14.0
    Current platform        : darwin-arm64
    Query Engine (Node-API) : libquery-engine 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
    Migration Engine        : migration-engine-cli 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
    Introspection Engine    : introspection-core 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
    Format Binary           : prisma-fmt 2b0c12756921c891fec4f68d9444e18c7d5d4a6a (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
    Default Engines Hash    : 2b0c12756921c891fec4f68d9444e18c7d5d4a6a
    Studio                  : 0.460.0
    
    bug 
    opened by felixerdy 3
  • create indexes

    create indexes

    Problem

    It is now needed to target a specific filename to get to a schema.:

    import { UserUpdateInputObjectSchema } from '{...}/gen/schemas/objects/UserUpdateInput.schema'
    

    Suggested solution

    It would be really awesome if you could generate indexes so that we can just import like this:

    import { UserUpdateInputObjectSchema } from `{...}/gen/schemas`
    
    enhancement 
    opened by Morriz 3
  • yup__WEBPACK_IMPORTED_MODULE_0__.link is not a function

    yup__WEBPACK_IMPORTED_MODULE_0__.link is not a function

    Bug description

    Follow up of #1: I'm getting the following error during an updateOne validation:

    error - (api)/prisma/generated/schemas/objects/NestedStringFilter.schema.ts (18:4) @ eval
    TypeError: yup__WEBPACK_IMPORTED_MODULE_0__.link is not a function
      16 |   not: Yup.mixed().oneOfSchemas([
      17 |     Yup.string(),
    > 18 |     Yup.link('#NestedStringFilter'),
         |    ^
      19 |   ]),
      20 | }
      21 | 
    

    FYI: I'm using this package in a Next.js Typescript project. Maybe I did something wrong or looked at the wrong places but I did not find any information about the Yup.link function anywhere

    How to reproduce

    running await QuestUpdateOneSchema.validate({ ...body })

    Expected behavior

    No response

    Prisma information

    // This is your Prisma schema file,
    // learn more about it in the docs: https://pris.ly/d/prisma-schema
    
    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    model Account {
      id                String  @id @default(cuid())
      userId            String
      type              String
      provider          String
      providerAccountId String
      refresh_token     String? @db.Text
      access_token      String? @db.Text
      expires_at        Int?
      token_type        String?
      scope             String?
      id_token          String? @db.Text
      session_state     String?
    
      user User @relation(fields: [userId], references: [id], onDelete: Cascade)
    
      @@unique([provider, providerAccountId])
    }
    
    model Session {
      id           String   @id @default(cuid())
      sessionToken String   @unique
      userId       String
      expires      DateTime
      user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
    }
    
    model User {
      id            String    @id @default(cuid())
      name          String?
      email         String?   @unique
      emailVerified DateTime?
      image         String?
      accounts      Account[]
      sessions      Session[]
      Quests        Quest[]
    }
    
    model VerificationToken {
      identifier String
      token      String   @unique
      expires    DateTime
    
      @@unique([identifier, token])
    }
    
    model Quest {
      id          String  @id @default(uuid())
      name        String?
      description String?
      draft       Boolean @default(true)
      user        User    @relation(fields: [userId], references: [id])
      userId      String
    }
    
    generator yup {
      provider = "prisma-yup-generator"
    }
    

    Environment & setup

    OS: macOS 12.2.1 Database: PostgreSQL 13 Node.js version: v16.14.2

    Prisma Version

    ➜ npx prisma -v      
    Environment variables loaded from .env
    prisma                  : 3.13.0
    @prisma/client          : 3.13.0
    Current platform        : darwin-arm64
    Query Engine (Node-API) : libquery-engine efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
    Migration Engine        : migration-engine-cli efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
    Introspection Engine    : introspection-core efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
    Format Binary           : prisma-fmt efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
    Default Engines Hash    : efdf9b1183dddfd4258cd181a72125755215ab7b
    Studio                  : 0.459.0
    
    bug 
    opened by felixerdy 3
  • Option to enable force overwrite

    Option to enable force overwrite

    Problem

    Generator fails with existing files.

    Suggested solution

    Generator should overwrite generated files or have an option to enable force overwrite.

    Alternatives

    none

    Additional context

    Just running generator multiple times.

    P.S. Thanks for excellent work, output is clean, up-to standard!

    opened by mubaidr 2
  • Can't resolve './QueryMode.schema'

    Can't resolve './QueryMode.schema'

    Bug description

    Thank you for this great generator. Unfortunately, I'm getting the following error during an updateOne validation:

    Module not found: Can't resolve './QueryMode.schema'
      2 | import * as Yup from 'yup'
      3 | import '../helpers/oneOfSchemas.helper.ts'
    > 4 | import { QueryModeSchemaObject } from './QueryMode.schema'
      5 | import { NestedStringNullableFilterSchemaObject } from './NestedStringNullableFilter.schema'
      6 | 
      7 | export const StringNullableFilterSchemaObject = {
    
    Import trace for requested module:
    ./prisma/generated/schemas/objects/AccountScalarWhereInput.schema.ts
    ./prisma/generated/schemas/objects/AccountUpdateManyWithoutUserInput.schema.ts
    ./prisma/generated/schemas/objects/UserUpdateWithoutQuestsInput.schema.ts
    ./prisma/generated/schemas/objects/UserUpdateOneRequiredWithoutQuestsInput.schema.ts
    ./prisma/generated/schemas/objects/QuestUpdateInput.schema.ts
    ./prisma/generated/schemas/updateOneQuest.schema.ts
    ./pages/api/quest/[id].ts
    

    While taking a look into StringNullableFilter.schema.ts in prisma/generated/schemas/objects it seems like there is an incorrect import statement:

    import { QueryModeSchemaObject } from './QueryMode.schema'
    

    which should be:

    import { QueryModeSchemaObject } from '../enums/QueryMode.schema'
    

    How to reproduce

    running await QuestUpdateOneSchema.validate({ ...body })

    Expected behavior

    No response

    Prisma information

    // This is your Prisma schema file,
    // learn more about it in the docs: https://pris.ly/d/prisma-schema
    
    generator client {
      provider = "prisma-client-js"
    }
    
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    model Account {
      id                String  @id @default(cuid())
      userId            String
      type              String
      provider          String
      providerAccountId String
      refresh_token     String? @db.Text
      access_token      String? @db.Text
      expires_at        Int?
      token_type        String?
      scope             String?
      id_token          String? @db.Text
      session_state     String?
    
      user User @relation(fields: [userId], references: [id], onDelete: Cascade)
    
      @@unique([provider, providerAccountId])
    }
    
    model Session {
      id           String   @id @default(cuid())
      sessionToken String   @unique
      userId       String
      expires      DateTime
      user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
    }
    
    model User {
      id            String    @id @default(cuid())
      name          String?
      email         String?   @unique
      emailVerified DateTime?
      image         String?
      accounts      Account[]
      sessions      Session[]
      Quests        Quest[]
    }
    
    model VerificationToken {
      identifier String
      token      String   @unique
      expires    DateTime
    
      @@unique([identifier, token])
    }
    
    model Quest {
      id          String  @id @default(uuid())
      name        String?
      description String?
      draft       Boolean @default(true)
      user        User    @relation(fields: [userId], references: [id])
      userId      String
    }
    
    generator yup {
      provider = "prisma-yup-generator"
    }
    

    Environment & setup

    • OS: macOS 12.2.1
    • Database: PostgreSQL 13
    • Node.js version: v16.14.2

    Prisma Version

    ➜ npx prisma version 
    Environment variables loaded from .env
    prisma                  : 3.13.0
    @prisma/client          : 3.13.0
    Current platform        : darwin-arm64
    Query Engine (Node-API) : libquery-engine efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
    Migration Engine        : migration-engine-cli efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/migration-engine-darwin-arm64)
    Introspection Engine    : introspection-core efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/introspection-engine-darwin-arm64)
    Format Binary           : prisma-fmt efdf9b1183dddfd4258cd181a72125755215ab7b (at node_modules/@prisma/engines/prisma-fmt-darwin-arm64)
    Default Engines Hash    : efdf9b1183dddfd4258cd181a72125755215ab7b
    Studio                  : 0.459.0
    
    bug 
    opened by felixerdy 2
  • some schemas are not available at compile time somehow and are registered as undefined

    some schemas are not available at compile time somehow and are registered as undefined

    Bug description

    the culprit is in the oneOfSchemas helper. The test breaks because it was given an array of schemas that were undefined. You can reproduce it with:

    Yup.addMethod(Yup.MixedSchema, 'oneOfSchemas', function (schemas: Yup.AnySchema[]) {
      if (schemas.length && schemas[0] === undefined) debugger
      return this.test('one-of-schemas', 'Not all items in ${path} match one of the allowed schemas', (item) =>
        schemas.some((schema) =>
          // uncommenting the next line will make the test run correctly
          // if (schema === undefined) return true
          schema.isValidSync(item, { strict: true }),
        ),
      )
    })
    

    How to reproduce

    Expected behavior

    No response

    Prisma information

    Environment & setup

    • OS:
    • Database:
    • Node.js version:

    Prisma Version

    
    
    opened by Morriz 2
  • decorator comments to specify validator

    decorator comments to specify validator

    Problem

    Hi, Prisma only has simple validation for database fields, but Yup/Joi etc allow have richer validators such as email/regex etc. How much work would it be to put the desired validator+args in decorator comments and apply them in the generator to the ones already picked up?

    Suggested solution

    Example could be:

    /// @PrismaYupGen email.nullable
    // or 
    /// @PrismaYupGen min(1).max(10)
    

    To keep it simple I removed () from validator without args.

    Hope to inspire :)

    enhancement 
    opened by Morriz 4
Releases(0.2.0)
  • 0.2.0(Jul 12, 2022)

    What's Changed

    • Upgrade-to-prisma-4 by @omar-dulaimi in https://github.com/omar-dulaimi/prisma-yup-generator/pull/11

    Full Changelog: https://github.com/omar-dulaimi/prisma-yup-generator/commits/0.2.0

    Source code(tar.gz)
    Source code(zip)
Owner
Omar Dulaimi
Full Stack Software Engineer
Omar Dulaimi
Prisma 2+ generator to emit Zod schemas from your Prisma schema

Prisma Zod Generator Automatically generate Zod schemas from your Prisma Schema, and use them to validate your API endpoints or any other use you have

Omar Dulaimi 212 Dec 27, 2022
Prisma +2 generator to emit a tRPC shield from your Prisma schema

Prisma tRPC Shield Generator Automatically generate a tRPC Shield from your Prisma Schema. Updates every time npx prisma generate runs. Table of Conte

Omar Dulaimi 27 Dec 24, 2022
Prisma 2+ generator to emit fully implemented tRPC routers

Prisma tRPC Generator Automatically generate fully implemented tRPC routers from your Prisma Schema. This includes routers, app router and of course a

Omar Dulaimi 370 Jan 3, 2023
Prisma 2+ generator to emit a JSON file that can be run with json-server

Prisma JSON Server Generator A Prisma generator that automates creating a JSON file that can be run as a server from your Prisma schema. Explore the o

Omar Dulaimi 14 Jan 7, 2023
A simple CLI to generate a starter schema for keystone-6 from a pre-existing prisma schema.

Prisma2Keystone A tool for converting prisma schema to keystone schema typescript This is a proof of concept. More work is needed Usage npx prisma2key

Brook Mezgebu 17 Dec 17, 2022
Composition API & Yup Powered Form Validation

vue-yup-form Composition API & Yup Powered Form Validation. This tiny library allows Vue and Yup to be a best friend. Requirements The following versi

Masaki Koyanagi 12 Dec 26, 2022
Schemix allows you to programmatically create Prisma schemas using TypeScript ⌨ī¸

Schemix Schemix let's you programmatically generate Prisma schemas. As Prisma schemas are not inherently segmentable, Schemix acts as a library to aid

Rida F'kih 197 Jan 5, 2023
A NestJS module that allows you use Prisma, set up multiple Prisma services, and use multi-tenancy in each Prisma service.

NestJS Prisma Module Installation To use this package, first install it: npm i @sabinthedev/nestjs-prisma Basic Usage In order to use this package, yo

Sabin Adams 39 Dec 2, 2022
Create a C# .NET core EntityFramework ORM from your schema.prisma file

A note of forewarning to the would-be user... This was a failure. I'm making a note here: huge regret. It's hard to overstate my dissatisfaction. ?? S

Ian Ray 9 Dec 24, 2022
GraphQL Hive provides all the tools the get visibility of your GraphQL architecture at all stages, from standalone APIs to composed schemas (Federation, Stitching)

GraphQL Hive GraphQL Hive provides all the tools the get visibility of your GraphQL architecture at all stages, from standalone APIs to composed schem

Kamil Kisiela 184 Dec 21, 2022
Merge multiple Prisma schema files, model inheritance, resolving name conflicts and timings reports, all in a simple tool.

Prisma Util What is Prisma Util? â€ĸ How to use? â€ĸ The configuration file â€ĸ Support What is Prisma Util? Prisma Util is an easy to use tool that merges

David Hancu 21 Dec 28, 2022
Learn GraphQL by building a blogging engine. Create resolvers, write schemas, write queries, design the database, test and also deploy.

GraphQL Blog graphqlblog.com Learn GraphQL by building a blogging engine. Create resolvers, write schemas, write queries, design the database, test an

GraphQLApps 6 Aug 17, 2022
Opinionated collection of TypeScript definitions and utilities for Deno and Deno Deploy. With complete types for Deno/NPM/TS config files, constructed from official JSON schemas.

Schemas Note: You can also import any type from the default module, ./mod.ts deno.json import { type DenoJson } from "https://deno.land/x/[email protected]

deno911 2 Oct 12, 2022
Hadmean is an internal tool generator. It is language agnostic, schema driven, extremely customizable, featured packed, user-friendly and has just one installation step.

Hadmean Report a Bug ¡ Request a Feature ¡ Ask a Question Table of Contents About Quick Demo Motivation Why you should try Hadmean Getting Started Pre

Hadmean 344 Dec 29, 2022
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io)

Alternative Prisma Data Proxy This is a library to alternate and self-host the Prisma Data Proxy (cloud.prisma.io). In order to deploy your project to

AijiUejima 60 Dec 28, 2022
Prisma Generator for Pothos Codegen.

Prisma Generator Pothos Codegen This is a prisma generator that auto generate all input types for Crud Operations to Pothos. Use it as args for crud o

Emanuel 30 Dec 22, 2022
Obsidian text generator Plugin Text generator using GPT-3 (OpenAI)

is a handy plugin for Obsidian that helps you generate text content using the powerful language model GP

null 356 Dec 29, 2022
typescript-to-jsonschema generates JSON Schema files from your Typescript sources.

fast-typescript-to-jsonschema English | įŽ€äŊ“中文 a tool generate json schema from typescript. Feature compile Typescript to get all type information conve

yunfly 21 Nov 28, 2022