UNPKG

prisma-zod-generator

Version:

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

126 lines (125 loc) 3.64 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 all relationships for a model */ getModelRelationships(model: DMMF.Model): ModelRelationship[]; /** * Get relation information by name */ private getRelationInfo; /** * Determine the type of relationship */ private getRelationType; /** * Get field constraints from DMMF */ getFieldConstraints(field: DMMF.Field): FieldConstraints; /** * Parse database constraints from field documentation */ private parseDbConstraints; /** * Get enum values for an enum field */ getEnumValues(enumName: string): string[]; /** * Get primary key fields for a model */ getPrimaryKeyFields(model: DMMF.Model): DMMF.Field[]; /** * Get unique constraints for a model */ getUniqueConstraints(model: DMMF.Model): UniqueConstraint[]; /** * Get index information for a model */ getModelIndexes(model: DMMF.Model): ModelIndex[]; /** * 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; /** * Check if a model has soft delete (createdAt/updatedAt pattern) */ hasSoftDelete(model: DMMF.Model): boolean; /** * Check if a model has timestamp fields */ hasTimestamps(model: DMMF.Model): boolean; /** * Get model hierarchy information (for inheritance patterns) */ getModelHierarchy(model: DMMF.Model): ModelHierarchy; } 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[]; }