UNPKG

prisma-class-validator

Version:

Automatically generator class-validator schema from Prisma client

195 lines (157 loc) 3.39 kB
/** * @copyright Koj <https://koj.co> * @link https://github.com/koj-co/prisma-class-validator * */ import { format } from "prettier"; import { generateClassValidatorFromPrismaClient } from "./"; test("generate schema", () => { expect( generateClassValidatorFromPrismaClient(` /** * Client **/ import * as runtime from '@prisma/client/runtime'; /** * Model Lead */ export type Lead = { browser: string | null city: string | null countryCode: string | null createdAt: Date email: string id: number name: string operatingSystem: string | null region: string | null responses: Prisma.JsonValue | null timezone: string | null updatedAt: Date } /** * Model User */ export type User = { active: boolean attributes: Prisma.JsonValue | null checkLocationOnLogin: boolean countryCode: string createdAt: Date gender: Gender } /** * Enums */ // Based on // https://github.com/microsoft/TypeScript/issues/3192#issuecomment-261720275 export const Gender: { FEMALE: 'FEMALE', MALE: 'MALE', NONBINARY: 'NONBINARY', UNKNOWN: 'UNKNOWN' }; export type Gender = (typeof Gender)[keyof typeof Gender] `) ).toBe( format( ` /** * DO NOT EDIT THIS FILE MANUALLY * ============================== * * This file is automatically generated by Prisma Class Validator using @prisma/client * Source: https://github.com/koj-co/prisma-class-validator/blob/HEAD/scripts/generate-types.ts */ import { IsOptional, IsString, IsNumber, IsNotEmpty, IsBoolean, IsObject, IsDateString, IsIn, } from "class-validator"; /** * Model Lead */ export class Lead { @IsString() @IsOptional() browser?: string | null; @IsString() @IsOptional() city?: string | null; @IsString() @IsOptional() countryCode?: string | null; @IsDateString() @IsNotEmpty() createdAt!: Date; @IsString() @IsNotEmpty() email!: string; @IsNumber() @IsNotEmpty() id!: number; @IsString() @IsNotEmpty() name!: string; @IsString() @IsOptional() operatingSystem?: string | null; @IsString() @IsOptional() region?: string | null; @IsObject() @IsOptional() responses?: any | null; @IsString() @IsOptional() timezone?: string | null; @IsDateString() @IsNotEmpty() updatedAt!: Date; } /** * Model User */ export class User { @IsBoolean() @IsNotEmpty() active!: boolean; @IsObject() @IsOptional() attributes?: any | null; @IsBoolean() @IsNotEmpty() checkLocationOnLogin!: boolean; @IsString() @IsNotEmpty() countryCode!: string; @IsDateString() @IsNotEmpty() createdAt!: Date; @IsString() @IsIn(["FEMALE", "MALE", "NONBINARY", "UNKNOWN"]) @IsNotEmpty() gender!: Gender; } /** * Enums */ // Based on // https://github.com/microsoft/TypeScript/issues/3192#issuecomment-261720275 export let Gender: { FEMALE: "FEMALE"; MALE: "MALE"; NONBINARY: "NONBINARY"; UNKNOWN: "UNKNOWN"; }; export type Gender = typeof Gender[keyof typeof Gender]; `, { parser: "typescript" } ) ); });