/** * ThreadTS Universal - Validation Utilities * * Centralized input validation for ThreadTS operations. * Provides reusable validation functions to ensure data integrity * and consistent error messages across the library. * * @module utils/validation * @author ThreadTS Universal Team */ /** * Validation result containing success status and optional error. */ export interface ValidationResult { /** Whether the validation passed */ valid: boolean; /** Error message if validation failed */ error?: string; } /** * Validates that a value is a function. * * @param fn - The value to validate * @param paramName - Name of the parameter for error messages * @throws {ThreadError} If the value is not a function * * @example * ```typescript * validateFunction(myCallback, 'callback'); * validateFunction(() => 42, 'processor'); * ``` */ export declare function validateFunction(fn: unknown, paramName?: string): void; /** * Validates that a value is an array. * * @param arr - The value to validate * @param paramName - Name of the parameter for error messages * @throws {ThreadError} If the value is not an array * * @example * ```typescript * validateArray([1, 2, 3], 'items'); * validateArray(myData, 'data'); * ``` */ export declare function validateArray(arr: unknown, paramName?: string): void; /** * Validates that an array is not empty. * * @param arr - The array to validate * @param paramName - Name of the parameter for error messages * @throws {ThreadError} If the array is empty * * @example * ```typescript * validateNonEmptyArray([1, 2, 3], 'items'); * ``` */ export declare function validateNonEmptyArray(arr: unknown[], paramName?: string): void; /** * Validates that a number is positive. * * @param value - The value to validate * @param paramName - Name of the parameter for error messages * @throws {ThreadError} If the value is not a positive number * * @example * ```typescript * validatePositiveNumber(5, 'timeout'); * validatePositiveNumber(batchSize, 'batchSize'); * ``` */ export declare function validatePositiveNumber(value: unknown, paramName?: string): void; /** * Validates that a number is non-negative (zero or positive). * * @param value - The value to validate * @param paramName - Name of the parameter for error messages * @throws {ThreadError} If the value is negative * * @example * ```typescript * validateNonNegativeNumber(0, 'delay'); * validateNonNegativeNumber(retryCount, 'retries'); * ``` */ export declare function validateNonNegativeNumber(value: unknown, paramName?: string): void; /** * Validates that a value is within a specified range. * * @param value - The value to validate * @param min - Minimum allowed value (inclusive) * @param max - Maximum allowed value (inclusive) * @param paramName - Name of the parameter for error messages * @throws {ThreadError} If the value is outside the range * * @example * ```typescript * validateRange(priority, 1, 3, 'priority'); * validateRange(poolSize, 1, 100, 'poolSize'); * ``` */ export declare function validateRange(value: number, min: number, max: number, paramName?: string): void; /** * Validates that a value is one of the allowed options. * * @param value - The value to validate * @param allowedValues - Array of allowed values * @param paramName - Name of the parameter for error messages * @throws {ThreadError} If the value is not in the allowed list * * @example * ```typescript * validateEnum(priority, ['low', 'normal', 'high'], 'priority'); * validateEnum(strategy, ['round-robin', 'least-busy'], 'strategy'); * ``` */ export declare function validateEnum(value: T, allowedValues: readonly T[], paramName?: string): void; /** * Validates that data is serializable (can be passed to a worker). * * Checks for: * - Functions (not serializable as data) * - Circular references * - Symbols (not serializable) * - BigInt (not directly serializable) * * @param value - The value to validate * @throws {SerializationError} If the data cannot be serialized * * @example * ```typescript * // Single value validation * validateSerializable({ name: 'test', count: 42 }); * * // Batch validation * for (const item of items) { * validateSerializable(item); * } * ``` */ export declare function validateSerializable(value: unknown): void; /** * Validates thread execution options. * * @param options - The options object to validate * @throws {ThreadError} If any option is invalid * * @example * ```typescript * validateThreadOptions({ timeout: 5000, priority: 'high' }); * validateThreadOptions({ maxRetries: 3 }); * ``` */ export declare function validateThreadOptions(options: Record): void; /** * Validates a task definition for batch/parallel execution. * * Accepts any value but validates that it: * 1. Is a non-null object * 2. Has either 'fn' or 'func' property that is a function * * @param task - The task to validate (accepts unknown for flexibility) * @param index - Optional index for error messages in batch operations * @throws {ThreadError} If the task is invalid * * @example * ```typescript * validateTask({ fn: (x) => x * 2, data: 5 }); * validateTask({ fn: myFunction }, 0); * ``` */ export declare function validateTask(task: unknown, index?: number): asserts task is { fn?: (...args: unknown[]) => unknown; func?: (...args: unknown[]) => unknown; }; /** * Validates multiple tasks for batch/parallel execution. * * @param tasks - Array of tasks to validate * @throws {ThreadError} If any task is invalid * * @example * ```typescript * validateTasks([ * { fn: (x) => x * 2, data: 5 }, * { fn: (x) => x + 1, data: 10 } * ]); * ``` */ export declare function validateTasks(tasks: unknown[]): void; /** * Safely coerces a value to a positive integer. * * @param value - The value to coerce * @param defaultValue - Default value if coercion fails * @param minValue - Minimum allowed value (default: 1) * @returns The coerced positive integer * * @example * ```typescript * const batchSize = toPositiveInt(options.batchSize, 10); * const poolSize = toPositiveInt(config.poolSize, 4, 1); * ``` */ export declare function toPositiveInt(value: unknown, defaultValue: number, minValue?: number): number; /** * Safely coerces a value to a non-negative integer. * * @param value - The value to coerce * @param defaultValue - Default value if coercion fails * @returns The coerced non-negative integer * * @example * ```typescript * const retries = toNonNegativeInt(options.maxRetries, 2); * const delay = toNonNegativeInt(config.delay, 0); * ``` */ export declare function toNonNegativeInt(value: unknown, defaultValue: number): number; /** * Validation utilities class for easier access. * Groups all validation functions as static methods. * * @example * ```typescript * ValidationUtils.validateFunction(callback, 'callback'); * ValidationUtils.validateSerializable(data); * ``` */ export declare class ValidationUtils { static validateFunction(fn: unknown, paramName?: string): void; static validateArray(arr: unknown, paramName?: string): void; static validateNonEmptyArray(arr: unknown[], paramName?: string): void; static validatePositiveNumber(value: unknown, paramName?: string): void; static validateNonNegativeNumber(value: unknown, paramName?: string): void; static validateRange(value: number, min: number, max: number, paramName?: string): void; static validateEnum(value: T, allowedValues: readonly T[], paramName?: string): void; static validateSerializable(value: unknown): void; static validateThreadOptions(options: Record): void; static validateTask(task: unknown, index?: number): asserts task is { fn?: (...args: unknown[]) => unknown; func?: (...args: unknown[]) => unknown; }; static validateTasks(tasks: unknown[]): void; static toPositiveInt(value: unknown, defaultValue: number, minValue?: number): number; static toNonNegativeInt(value: unknown, defaultValue: number): number; } //# sourceMappingURL=validation.d.ts.map