prisma-zod-generator
Version:
Prisma 2+ generator to emit Zod schemas from your Prisma schema
115 lines (114 loc) • 3.01 kB
TypeScript
/**
* 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
*/
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[];
}