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

101 lines 3.51 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.loadConfig = loadConfig; exports.findAndLoadConfig = findAndLoadConfig; exports.mergeConfig = mergeConfig; const fs = __importStar(require("fs")); const path = __importStar(require("path")); /** * Load configuration from a file */ async function loadConfig(configPath) { const fullPath = path.resolve(configPath); if (!fs.existsSync(fullPath)) { throw new Error(`Configuration file not found: ${fullPath}`); } const ext = path.extname(fullPath).toLowerCase(); if (ext === '.json') { const content = await fs.promises.readFile(fullPath, 'utf-8'); return JSON.parse(content); } else if (ext === '.js' || ext === '.mjs') { // Dynamic import for JS config files const config = await Promise.resolve(`${fullPath}`).then(s => __importStar(require(s))); return config.default || config; } else { throw new Error(`Unsupported config file format: ${ext}`); } } /** * Find and load default config file */ async function findAndLoadConfig(startDir = process.cwd()) { const configNames = [ 'typescript-runtime-schemas.config.js', 'typescript-runtime-schemas.config.json', 'typescript-runtime-schemas.config.mjs', ]; for (const configName of configNames) { const configPath = path.join(startDir, configName); if (fs.existsSync(configPath)) { try { return await loadConfig(configPath); } catch (error) { console.warn(`Warning: Failed to load config file ${configPath}:`, error); } } } return null; } /** * Merge configuration with command line options */ function mergeConfig(config, options) { if (!config) { return options; } // Command line options take precedence over config file return { ...config, ...options, // Special handling for arrays glob: options.glob || config.glob, exclude: options.exclude || config.exclude, }; } //# sourceMappingURL=config.js.map