prisma-zod-generator
Version:
Prisma 2+ generator to emit Zod schemas from your Prisma schema
42 lines (41 loc) • 1.78 kB
TypeScript
/**
* Helper functions and utilities for Decimal type support
* Matches zod-prisma-types implementation for seamless migration
*/
/**
* Generate helper schemas for Decimal validation
* These helpers enable proper Prisma.Decimal and Decimal.js support
*
* @param hasDecimalJs - Whether decimal.js is installed and should be imported
* @param zodNamespace - The zod namespace to use (e.g., 'z' or 'zod')
* @returns Object containing helper schema code and necessary imports
*/
export declare function generateDecimalHelpers(hasDecimalJs: boolean, zodNamespace?: string, prismaImportPath?: string): {
helperCode: string;
imports: string[];
};
/**
* Generate Decimal field schema for input types (Create, Update, etc.)
* Uses union of multiple formats with refinement validation
*
* @param zodNamespace - The zod namespace to use (e.g., 'z' or 'zod')
* @param hasDecimalJs - Whether decimal.js is installed
* @param fieldName - Name of the field (for error messages)
* @returns Zod schema string
*/
export declare function generateDecimalInputSchema(zodNamespace: string, hasDecimalJs: boolean, fieldName?: string): string;
/**
* Generate Decimal field schema for pure models (output/result types)
* Uses the cross-runtime-copy safe Prisma.Decimal.isDecimal check
*
* @param zodNamespace - The zod namespace to use (e.g., 'z' or 'zod')
* @param fieldName - Name of the field
* @param modelName - Name of the model (for error messages)
* @returns Zod schema string
*/
export declare function generateDecimalModelSchema(zodNamespace: string, fieldName: string, modelName: string): string;
/**
* Check if decimal.js is installed in the project
* @returns true if decimal.js is available
*/
export declare function isDecimalJsAvailable(): boolean;