prisma-zod-generator
Version:
Prisma 2+ generator to emit Zod schemas from your Prisma schema
120 lines (119 loc) • 4.02 kB
TypeScript
/**
* Pro Feature Base Class
*
* Abstract base class for all Pro features with DMMF access and common functionality
*/
import { DMMF } from '@prisma/generator-helper';
import { ProGeneratorContext, ProContextUtils } from './ProGeneratorContext';
import { DMMFHelpers } from './DMMFHelpers';
export declare abstract class ProFeatureBase {
protected context: ProGeneratorContext;
protected utils: ProContextUtils;
protected dmmfHelpers: DMMFHelpers;
constructor(context: ProGeneratorContext);
/**
* Validate license for this feature before generation
* Override in subclasses to specify feature name
*/
protected abstract getFeatureName(): string;
/**
* Main generation method - implement in subclasses
*/
protected abstract generateFeature(): Promise<void>;
/**
* Public generate method with license validation
*/
generate(): Promise<void>;
/**
* Get models filtered by enabled status (if applicable)
*/
protected getEnabledModels(): DMMF.Model[];
/**
* Check if a model should be included in generation
*/
protected isModelEnabled(modelName: string): boolean;
/**
* Get field documentation/comments from DMMF
*/
protected getFieldDocumentation(model: DMMF.Model, fieldName: string): string | undefined;
/**
* Get model documentation/comments from DMMF
*/
protected getModelDocumentation(model: DMMF.Model): string | undefined;
/**
* Get all fields of a specific kind from a model
*/
protected getFieldsByKind(model: DMMF.Model, kind: DMMF.FieldKind): DMMF.Field[];
/**
* Get all scalar fields from a model
*/
protected getScalarFields(model: DMMF.Model): DMMF.Field[];
/**
* Get all relation fields from a model
*/
protected getRelationFields(model: DMMF.Model): DMMF.Field[];
/**
* Get all enum fields from a model
*/
protected getEnumFields(model: DMMF.Model): DMMF.Field[];
/**
* Check if a field is required (not optional and no default value)
*/
protected isFieldRequired(field: DMMF.Field): boolean;
/**
* Check if a field is unique
*/
protected isFieldUnique(model: DMMF.Model, fieldName: string): boolean;
/**
* Get field type as string for code generation
*/
protected getFieldTypeString(field: DMMF.Field): string;
/**
* Write file safely with proper directory creation
*/
protected writeFile(filePath: string, content: string): Promise<void>;
/**
* Log info message
*/
protected logInfo(message: string): void;
/**
* Log warning message
*/
protected logWarning(message: string): void;
/**
* Log error message
*/
protected logError(message: string): void;
/**
* Extract comments that match a specific pattern
* Useful for parsing special annotations like @policy, @pii, etc.
*/
protected extractAnnotationsFromComment(comment: string | undefined, annotationType: string): string[];
/**
* Parse field-level annotations from documentation
*/
protected parseFieldAnnotations(model: DMMF.Model, fieldName: string, annotationType: string): string[];
/**
* Parse model-level annotations from documentation
*/
protected parseModelAnnotations(model: DMMF.Model, annotationType: string): string[];
/**
* Get all models that have a specific annotation
*/
protected getModelsWithAnnotation(annotationType: string): DMMF.Model[];
/**
* Get all fields from a model that have a specific annotation
*/
protected getFieldsWithAnnotation(model: DMMF.Model, annotationType: string): DMMF.Field[];
/**
* Generate TypeScript import statements
*/
protected generateImports(imports: Array<{
from: string;
imports: string[];
}>): string;
/**
* Generate export statements
*/
protected generateExports(exports: string[]): string;
}