prisma-zod-generator
Version:
Prisma 2+ generator to emit Zod schemas from your Prisma schema
75 lines (74 loc) • 2.1 kB
TypeScript
/**
* PZG Pro - Comment Parser
*
* Parses policy and PII annotations from Prisma schema comments
*/
export interface PolicyRule {
type: 'read' | 'write' | 'deny' | 'update' | 'delete' | 'create';
subtype?: 'where' | 'fields' | 'values';
condition: string;
field?: string;
fields?: string[];
modelName?: string;
operator?: 'in' | 'not_in' | 'equals' | 'not_equals' | 'contains' | 'starts_with' | 'ends_with' | '==' | '!=';
contextVariable?: string;
}
export interface PIIRule {
type: 'pii';
dataType: 'email' | 'phone' | 'ssn' | 'credit_card' | 'custom';
redactLogs?: boolean;
maskType?: 'partial' | 'full' | 'hash';
field?: string;
modelName?: string;
}
export interface TenantRule {
type: 'tenant';
field: string;
fields?: string[];
tenantType?: 'string' | 'number' | 'uuid';
tenantTypes?: ('string' | 'number' | 'uuid')[];
required?: boolean;
modelName?: string;
hierarchy?: {
parent?: string;
children?: string[];
depth?: number;
};
sharding?: {
strategy: 'hash' | 'range' | 'directory';
shardCount?: number;
shardField?: string;
};
inheritance?: {
inheritsFrom?: string;
cascadeDelete?: boolean;
inheritanceType: 'single-table' | 'joined-table' | 'table-per-class';
};
validation?: {
format?: 'uuid' | 'slug' | 'domain' | 'custom';
pattern?: string;
length?: {
min?: number;
max?: number;
};
enum?: string[];
};
performance?: {
indexStrategy: 'btree' | 'hash' | 'gin' | 'gist';
partitioning?: 'range' | 'hash' | 'list';
caching?: {
ttl: number;
strategy: 'redis' | 'memory';
};
};
}
export interface ModelPolicies {
modelName: string;
policies: PolicyRule[];
piiRules: PIIRule[];
tenantRules: TenantRule[];
}
/**
* Parse a Prisma schema file and extract all policy/PII rules
*/
export declare function parseSchemaComments(schemaContent: string): ModelPolicies[];