UNPKG

prisma-zod-generator

Version:

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

90 lines (89 loc) 2.63 kB
/** * DMMF Helper Utilities * * Utility functions for working with DMMF data structures */ import { DMMF } from '@prisma/generator-helper'; import { ProGeneratorContext } from './ProGeneratorContext'; export declare class DMMFHelpers { private context; constructor(context: ProGeneratorContext); /** * Get field constraints from DMMF */ getFieldConstraints(field: DMMF.Field): FieldConstraints; /** * Parse database constraints from field documentation */ private parseDbConstraints; /** * Get primary key fields for a model */ getPrimaryKeyFields(model: DMMF.Model): DMMF.Field[]; /** * Generate TypeScript interface from DMMF model */ generateModelInterface(model: DMMF.Model): string; /** * Get TypeScript type string for a field */ private getFieldTypeString; /** * Get TypeScript type for Prisma scalar types */ /** * TypeScript type for a scalar, as it appears **over the wire**. * * The only consumers of these interfaces are standalone HTTP clients (the SDK * pack and the api-docs pack's sdk.ts), which have no Prisma dependency. They * previously named `Decimal`, `JsonValue` and `Buffer` — Prisma runtime types * that were never imported, so every client with one of those columns failed to * compile (TS2304). `Date` and `bigint` were wrong in a subtler way: JSON.parse * hands back a string, so the annotation type-checked while the value at runtime * was something else entirely. */ private getScalarTypeString; } export interface ModelRelationship { field: DMMF.Field; relatedModel?: DMMF.Model; relationInfo: RelationInfo | null; type: RelationType; } export interface RelationInfo { name: string; fields: string[]; references: string[]; onDelete?: string; onUpdate?: string; } export type RelationType = 'one-to-one' | 'one-to-many' | 'many-to-one' | 'many-to-many'; export interface FieldConstraints { required: boolean; unique: boolean; list: boolean; optional: boolean; hasDefault: boolean; defaultValue?: any; maxLength?: number; minLength?: number; type?: string; precision?: number; scale?: number; pattern?: string; } export interface UniqueConstraint { name: string; fields: string[]; } export interface ModelIndex { name: string; fields: string[]; type: 'primary' | 'unique' | 'index'; unique: boolean; } export interface ModelHierarchy { model: DMMF.Model; parents: DMMF.Model[]; children: DMMF.Model[]; }