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
178 lines (177 loc) • 6.32 kB
TypeScript
import { Project, SourceFile, TypeAliasDeclaration } from "ts-morph";
/**
* TypeScript type resolver that can resolve computed types like Pick, Omit, etc. using ts-morph
*/
export declare class TypeResolver {
private project;
private sourceFiles;
constructor(sourceCode: string, compilerOptions?: any);
/**
* Create TypeResolver from an existing ts-morph project with multiple files
*/
static fromProject(project: Project, sourceFiles: SourceFile[]): TypeResolver;
/**
* Get the primary source file (for backward compatibility)
*/
private get sourceFile();
/**
* Resolve all type aliases in the source code to their computed forms
* @param predicate Optional function to filter which types should be resolved.
* Types for which the predicate returns false will be returned as-is.
*/
resolveTypes(predicate?: (typeName: string, typeAlias: TypeAliasDeclaration) => boolean): string;
/**
* Get a specific resolved type by name (searches all files)
*/
getResolvedType(typeName: string): string;
/**
* Resolve a specific type alias to its computed form
*/
private resolveTypeAlias;
/**
* Resolve an interface declaration to its type literal form
*/
private resolveInterfaceDeclaration;
/**
* Resolve a type node to its string representation
*/
private resolveTypeNode;
/**
* Resolve type references like Pick<User, 'name' | 'email'>
*/
private resolveTypeReference;
/**
* Resolve utility types like Pick and Omit
*/
private resolveUtilityType;
/**
* Resolve Partial or Required utility types
*/
private resolvePartialOrRequired;
/**
* Get properties from a base type (either a type literal or a type alias reference)
*/
private getBaseTypeProperties;
/**
* Extract properties from an interface declaration
*/
private extractPropertiesFromInterface;
/**
* Extract properties from a type literal
*/
private extractPropertiesFromTypeLiteral;
/**
* Extract keys from a union type like 'name' | 'email'
*/
private extractKeys;
/**
* Resolve type literals to their string representation
*/
private resolveTypeLiteral;
/**
* Resolve single-argument utility types like Partial, Required, Readonly, NonNullable
*/
private resolveSingleArgUtilityType;
/**
* Resolve Readonly<T> utility type
*/
private resolveReadonlyType;
/**
* Resolve NonNullable<T> utility type
*/
private resolveNonNullableType;
/**
* Resolve Record<K, V> utility type
*/
private resolveRecordType;
/**
* Resolve Exclude<T, U> and Extract<T, U> utility types
*/
private resolveExcludeExtractType;
/**
* Resolve ReturnType<T> utility type
*/
private resolveReturnType;
/**
* Resolve Parameters<T> utility type
*/
private resolveParametersType;
/**
* Resolve ConstructorParameters<T> utility type
*/
private resolveConstructorParametersType;
/**
* Resolve InstanceType<T> utility type
*/
private resolveInstanceType;
/**
* Resolve ThisParameterType<T> and OmitThisParameter<T> utility types
*/
private resolveThisParameterType;
/**
* Resolve generic type aliases with type arguments
*/
private resolveGenericTypeAlias;
/**
* Resolve intersection types (A & B)
*/
private resolveIntersectionType;
/**
* Resolve union types (A | B)
*/
private resolveUnionType;
/**
* Get properties from intersection types by merging all constituent types
*/
private getPropertiesFromIntersection;
/**
* Try to resolve imported type properties using TypeScript's type checker
*/
private resolveImportedTypeProperties;
/**
* Substitute type parameters in a type node
*/
private substituteTypeParameters;
}
/**
* Convenience function to resolve types from source code
*/
export declare function resolveTypesFromSource(sourceCode: string, predicate?: (typeName: string, typeAlias: TypeAliasDeclaration) => boolean): string;
/**
* Convenience function to get a specific resolved type
*/
export declare function getResolvedType(sourceCode: string, typeName: string): string;
import { TypeResolverFactoryOptions } from "./type-resolver-factory";
import { FileDiscoveryOptions } from "./file-discovery";
/**
* Enhanced convenience function to resolve types from various input types
*/
export declare function resolveTypesFromInput(input: string, predicate?: (typeName: string, typeAlias: TypeAliasDeclaration) => boolean, options?: TypeResolverFactoryOptions): Promise<string>;
/**
* Enhanced convenience function to get a specific resolved type from various input types
*/
export declare function getResolvedTypeFromInput(input: string, typeName: string, options?: TypeResolverFactoryOptions): Promise<string>;
/**
* Convenience function to resolve types from a directory
*/
export declare function resolveTypesFromDirectory(dirPath: string, options?: FileDiscoveryOptions & {
compilerOptions?: any;
}, predicate?: (typeName: string, typeAlias: TypeAliasDeclaration) => boolean): Promise<string>;
/**
* Convenience function to resolve types using glob patterns
*/
export declare function resolveTypesFromGlob(dirPath: string, glob: string | string[], exclude?: string | string[], predicate?: (typeName: string, typeAlias: TypeAliasDeclaration) => boolean, compilerOptions?: any): Promise<string>;
/**
* Convenience function to resolve types from a single file
*/
export declare function resolveTypesFromFile(filePath: string, predicate?: (typeName: string, typeAlias: TypeAliasDeclaration) => boolean, compilerOptions?: any): Promise<string>;
/**
* Convenience function to get a specific type from a file
*/
export declare function getResolvedTypeFromFile(filePath: string, typeName: string, compilerOptions?: any): Promise<string>;
/**
* Convenience function to get a specific type from a directory
*/
export declare function getResolvedTypeFromDirectory(dirPath: string, typeName: string, options?: FileDiscoveryOptions & {
compilerOptions?: any;
}): Promise<string>;