UNPKG

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

56 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TypeResolverFactory = void 0; const type_resolver_1 = require("./type-resolver"); const source_loader_1 = require("./source-loader"); const utils_1 = require("./utils"); class TypeResolverFactory { /** * Create a TypeResolver with full import support */ static async create(input, options = {}) { const { compilerOptions, ...fileOptions } = options; // Check if input is source code first if ((0, utils_1.isSourceCode)(input)) { // For source code, use original constructor for backward compatibility return new type_resolver_1.TypeResolver(input, compilerOptions); } // For files/directories, use the project-based approach const { project, sourceFiles } = await source_loader_1.SourceLoader.createProject(input, { ...fileOptions, compilerOptions, }); // Use new factory method for multiple files or real file system return type_resolver_1.TypeResolver.fromProject(project, sourceFiles); } /** * Create TypeResolver with explicit file discovery options */ static async createFromFiles(input, fileOptions, compilerOptions) { return this.create(input, { ...fileOptions, compilerOptions }); } /** * Create TypeResolver from directory with glob patterns */ static async createFromDirectory(dirPath, glob, exclude, compilerOptions) { return this.create(dirPath, { glob, exclude, compilerOptions, }); } /** * Create TypeResolver from a single file */ static async createFromFile(filePath, compilerOptions) { return this.create(filePath, { compilerOptions }); } /** * Create TypeResolver from source code (same as original constructor) */ static createFromSource(sourceCode, compilerOptions) { return new type_resolver_1.TypeResolver(sourceCode, compilerOptions); } } exports.TypeResolverFactory = TypeResolverFactory; //# sourceMappingURL=type-resolver-factory.js.map