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
77 lines (76 loc) • 2.08 kB
TypeScript
import { GeneratedZodSchema } from './zod-schema-generator';
export interface SchemaOutputOptions {
outputDir?: string;
writeToFile?: boolean;
preserveStructure?: boolean;
}
export interface SchemaFileInfo {
schemas: GeneratedZodSchema[];
outputPath: string;
sourceFiles: string[];
}
/**
* SchemaFileWriter - Handles writing Zod schemas to disk
*/
export declare class SchemaFileWriter {
/**
* Write schemas to disk based on output options
*/
static writeSchemas(schemas: GeneratedZodSchema[], options?: SchemaOutputOptions, inputDir?: string): Promise<string[]>;
/**
* Write all schemas to a single schemas.zod.ts file
*/
private static writeSingleSchemaFile;
/**
* Write schemas preserving directory structure
*/
private static writeStructuredSchemas;
/**
* Group schemas by their source file
*/
private static groupSchemasBySourceFile;
/**
* Get the output path for a structured file
*/
private static getStructuredOutputPath;
/**
* Generate content for a single consolidated file
*/
private static generateSingleFileContent;
/**
* Generate content for a single file
*/
private static generateFileContent;
/**
* Generate the export statement for a schema
*/
private static generateSchemaExport;
/**
* Convert a Zod schema to its string representation
*/
private static zodSchemaToString;
/**
* Serialize a Zod schema to string representation
*/
private static serializeZodSchema;
/**
* Serialize a ZodObject
*/
private static serializeZodObject;
/**
* Serialize a ZodString with constraints
*/
private static serializeZodString;
/**
* Serialize a ZodNumber with constraints
*/
private static serializeZodNumber;
/**
* Serialize a ZodArray
*/
private static serializeZodArray;
/**
* Ensure a directory exists, creating it if necessary
*/
private static ensureDirectoryExists;
}