/* Vendored via https://github.com/colinhacks/zod/issues/2084 Usage: ``` export type UserModel = { id: string email: string | null name: string firstName: string createdAt: Date } export const UserCreateSchema = toZod>().with({ email: z.string().email().nullable(), name: z.string(), firstName: z.string(), }); export type UserCreatePayload = z.infer ``` */ import * as z from "zod"; type Implements = { [key in keyof Model]-?: undefined extends Model[key] ? null extends Model[key] ? z.ZodNullableType>> : z.ZodOptionalType> : null extends Model[key] ? z.ZodNullableType> : z.ZodType; }; export function toZod() { return { with: < Schema extends & Implements & { [unknownKey in Exclude]: never; }, >( schema: Schema, ) => z.object(schema), }; }