prisma-zod-generator
Version:
Prisma 2+ generator to emit Zod schemas from your Prisma schema
60 lines (59 loc) • 2.05 kB
TypeScript
/**
* PZG Pro - Drift Guard Generator
* DMMF-based implementation for schema change detection
*/
import { DMMF } from '@prisma/generator-helper';
import { ProFeatureBase } from '../../core/ProFeatureBase';
export interface DriftGuardConfig {
baseBranch?: string;
headBranch?: string;
outputFormat?: 'github' | 'json' | 'text';
strictMode?: boolean;
allowedBreaks?: string[];
}
export interface SchemaChange {
type: 'breaking' | 'non-breaking';
category: 'field' | 'enum' | 'model' | 'type' | 'validation';
model: string;
field?: string;
change: string;
description: string;
severity: 'error' | 'warning' | 'info';
}
export declare class DriftGuardGenerator extends ProFeatureBase {
private config;
constructor(context: any, config?: DriftGuardConfig);
protected getFeatureName(): string;
/**
* Drift Guard writes no files.
*
* It compares two schema revisions, which needs both revisions — something
* `prisma generate` does not have. It is driven by the `pzg-pro guard` CLI or by
* `validateDrift()`. This used to log "Analyzed N models for schema drift
* detection" and produce nothing, which reads as a successful generation.
*/
protected generateFeature(): Promise<void>;
/**
* Compare two DMMF documents and detect schema changes
*/
compareSchemas(baseDMMF: DMMF.Document, headDMMF: DMMF.Document): SchemaChange[];
private compareModels;
private compareModelFields;
private compareFieldProperties;
private compareEnums;
private compareEnumValues;
/**
* Format changes for output
*/
formatOutput(changes: SchemaChange[]): string;
private formatGitHubOutput;
private formatJSONOutput;
private formatTextOutput;
/**
* Validate changes and determine if they should fail CI
*/
/** How many of these breaks the caller explicitly allowed. */
private countWhitelisted;
shouldFailCI(changes: SchemaChange[]): boolean;
private buildChangeIdentifier;
}