UNPKG

@axarai/axar

Version:

TypeScript-based agent framework for building agentic applications powered by LLMs

208 lines (207 loc) 6.54 kB
import { SchemaOptions, PropertyOptions, SchemaConstructor } from './types'; /** * Decorates a class for automatic schema generation using Zod. * When applied, it generates and stores a Zod schema based on the class properties * and their decorators. * * @param descriptionOrOptions - Either a description string or a SchemaOptions object * @returns A class decorator * * @example * ```typescript * // Using string description * @schema("User profile information") * class UserProfile { * @property("User's full name") * name: string; * } * * // Using SchemaOptions object * @schema({ * description: "User profile information" * }) * class UserProfile { * @property("User's full name") * name: string; * } * ``` */ export declare function schema(descriptionOrOptions?: string | SchemaOptions): ClassDecorator; /** Alias for {@link schema} decorator, use if conflicts with Zod */ export declare const zodify: typeof schema; /** * Adds metadata to a class property. This can include descriptions and examples * that will be included in the generated schema. * * @param descriptionOrOptions - Either a description string or a PropertyOptions object * @returns A property decorator * * @example * ```typescript * class User { * // Using string description * @property("User's full name") * name: string; * * // Using PropertyOptions object * @property({ * description: "User's age in years", * example: 25 * }) * age: number; * } * ``` */ export declare function property(descriptionOrOptions: string | PropertyOptions): PropertyDecorator; /** * Marks a class property as optional in the generated schema. * Optional properties can be undefined or omitted when creating instances. * * @returns A property decorator * * @example * ```typescript * class UserSettings { * @optional() * @description("Preferred theme (defaults to system)") * theme?: 'light' | 'dark'; * * @optional() * @example("en-US") * language?: string; * } * ``` */ export declare function optional(): PropertyDecorator; /** * Decorates a property with enum validation * @param values - Array of valid enum values * * @example * ```typescript * class User { * @enumValues(['admin', 'user', 'guest']) * role: string; * } * ``` */ export declare function enumValues<T extends string | number>(values: readonly T[]): PropertyDecorator; /** * Decorates an array property with item type information * @param itemType - Function returning the item type * * @example * ```typescript * class PostList { * @arrayItems(() => Post) * items: Post[]; * } * ``` */ export declare function arrayItems(itemType: () => SchemaConstructor): PropertyDecorator; /** * Validates that a string property is a valid email address. * @example * ```ts * class User { * @email() * email: string; * } * ``` */ export declare const email: () => PropertyDecorator; /** * Validates that a string property is a valid URL. * @example `@url() website: string;` */ export declare const url: () => PropertyDecorator; /** * Validates that a string property matches the given regular expression pattern. * @param regex - The regular expression to test against * @example `@pattern(/^[A-Z]{2}\d{3}$/) code: string;` */ export declare const pattern: (regex: RegExp) => PropertyDecorator; /** * Validates that a string property is a valid UUID. * @example `@uuid() id: string;` */ export declare const uuid: () => PropertyDecorator; /** * Validates that a string property is a valid CUID. * @example `@cuid() id: string;` */ export declare const cuid: () => PropertyDecorator; /** * Validates that a string property is a valid ISO datetime string. * @example `@datetime() createdAt: string;` */ export declare const datetime: () => PropertyDecorator; /** * Validates that a string property is a valid IP address. * @example `@ip() serverAddress: string;` */ export declare const ip: () => PropertyDecorator; /** * Validates that a string's length is at most the specified value. * @param value - Maximum length allowed * @example `@max(100) description: string;` */ export declare const max: (value: number) => PropertyDecorator; /** * Validates that a string's length is at least the specified value. * @param value - Minimum length required * @example `@min(3) username: string;` */ export declare const min: (value: number) => PropertyDecorator; /** * Validates that a number is greater than or equal to the specified value. * @param value - Minimum value allowed (inclusive) * @example `@minimum(0) price: number;` */ export declare const minimum: (value: number) => PropertyDecorator; /** * Validates that a number is less than or equal to the specified value. * @param value - Maximum value allowed (inclusive) * @example `@maximum(100) percentage: number;` */ export declare const maximum: (value: number) => PropertyDecorator; /** * Validates that a number is a multiple of the specified value. * @param value - The number must be divisible by this value * @example `@multipleOf(5) quantity: number;` */ export declare const multipleOf: (value: number) => PropertyDecorator; /** * Validates that a number is strictly greater than the specified value. * @param value - Minimum value allowed (exclusive) * @example `@exclusiveMinimum(0) positiveNumber: number;` */ export declare const exclusiveMinimum: (value: number) => PropertyDecorator; /** * Validates that a number is strictly less than the specified value. * @param value - Maximum value allowed (exclusive) * @example `@exclusiveMaximum(100) score: number;` */ export declare const exclusiveMaximum: (value: number) => PropertyDecorator; /** * Validates that a number is an integer (no decimal places). * @example `@integer() age: number;` */ export declare const integer: () => PropertyDecorator; /** * Validates that an array has at least the specified number of items. * @param min - Minimum number of items required * @example `@minItems(1) tags: string[];` */ export declare const minItems: (min: number) => PropertyDecorator; /** * Validates that an array has at most the specified number of items. * @param max - Maximum number of items allowed * @example `@maxItems(10) selections: string[];` */ export declare const maxItems: (max: number) => PropertyDecorator; /** * Validates that all items in an array are unique. * @example `@uniqueItems() categories: string[];` */ export declare const uniqueItems: () => PropertyDecorator;