typescript-runtime-schemas
Version:
A TypeScript schema generation tool that extracts Zod schemas from TypeScript source files with runtime validation support. Generate validation schemas directly from your existing TypeScript types with support for computed types and constraint-based valid
64 lines (63 loc) • 2.01 kB
TypeScript
import { z } from "zod";
import { ExtractedSchema } from "./schema-extractor";
export interface GeneratedZodSchema {
typeName: string;
zodSchema: z.ZodSchema<any>;
sourceInfo?: {
filePath: string;
line: number;
};
}
/**
* ZodSchemaGenerator - Converts parsed constraint schemas to Zod schemas
*/
export declare class ZodSchemaGenerator {
/**
* Generate Zod schemas from extracted constraint schemas
*/
static generateSchemas(extractedSchemas: ExtractedSchema[], includeSourceInfo?: boolean): GeneratedZodSchema[];
/**
* Generate a single Zod schema from an extracted schema
*/
static generateSingle(extractedSchema: ExtractedSchema, includeSourceInfo?: boolean): GeneratedZodSchema;
/**
* Convert a ParsedSchema to a Zod schema
*/
private static convertToZodSchema;
/**
* Convert a PropertySchema to a Zod type
*/
private static convertPropertyToZod;
/**
* Apply constraints to a Zod type
*/
private static applyConstraints;
/**
* Apply a single constraint to a Zod type
*/
private static applyConstraint;
}
/**
* Generate Zod schemas from source code string
*/
export declare function generateZodSchemasFromSource(sourceCode: string, options?: {
includeSourceInfo?: boolean;
}): Promise<GeneratedZodSchema[]>;
/**
* Generate Zod schemas from a file
*/
export declare function generateZodSchemasFromFile(filePath: string, options?: {
includeSourceInfo?: boolean;
}): Promise<GeneratedZodSchema[]>;
/**
* Generate Zod schemas from a directory
*/
export declare function generateZodSchemasFromDirectory(dirPath: string, options?: {
includeSourceInfo?: boolean;
}): Promise<GeneratedZodSchema[]>;
/**
* Generate Zod schemas using glob patterns
*/
export declare function generateZodSchemasFromGlob(dirPath: string, glob: string | string[], exclude?: string | string[], options?: {
includeSourceInfo?: boolean;
}): Promise<GeneratedZodSchema[]>;