@axarai/axar
Version:
TypeScript-based agent framework for building agentic applications powered by LLMs
37 lines (36 loc) • 1.12 kB
TypeScript
import 'reflect-metadata';
import { z } from 'zod';
import { SchemaConstructor } from './types';
/**
* Creates a Zod schema for a given class constructor.
*
* Scans the class for property decorators and applies their validation rules
* to the generated schema.
*
* @param target - The class constructor to generate the schema for
* @returns A cached Zod object schema with all validations applied
*
* @example
* ```ts
* @schema({ description: 'User data' })
* class User {
* @property({ description: 'User email' })
* @validate('email')
* email: string;
*
* @optional()
* @validate('min', 3)
* name?: string;
* }
*
* const userSchema = toZodSchema(User);
* ``` *
* @features
* - Schema-level descriptions via `@schema` decorator
* - Property-level descriptions via `@property` decorator
* - Optional properties via `@optional` decorator
* - Built-in validations (min, max, pattern, etc.)
* - Custom validation rules via `@validate` decorator
* - Automatic schema caching for performance
*/
export declare function toZodSchema<T>(target: SchemaConstructor<T>): z.ZodObject<any>;