UNPKG

kist

Version:

Package Pipeline Processor

73 lines (72 loc) 2.71 kB
import { AbstractProcess } from "../abstract/AbstractProcess"; /** * AbstractValidator provides a base class for validation. * Extends AbstractProcess for consistent logging and validation utility * methods. * Subclasses should implement the specific `validateProperty` method for * custom validation logic. */ export declare abstract class AbstractValidator<T> extends AbstractProcess { constructor(); /** * Validates an entire object. * @param target - The object to validate. * @throws Error if validation fails for any property. */ validate(target: T): void; /** * Validates a specific property of the object. * Subclasses must implement this method to provide specific validation logic. * * @param key - The key of the property being validated. * @param value - The value of the property being validated. */ protected abstract validateProperty<K extends keyof T>(key: K, value: T[K]): void; /** * Validates a numeric value. * * @param key - The key being validated. * @param value - The numeric value to validate. * @throws Error if the value is not a non-negative number. */ protected validateNumber<K extends keyof T>(key: K, value: T[K]): void; /** * Validates a boolean value. * * @param key - The key being validated. * @param value - The boolean value to validate. * @throws Error if the value is not a boolean. */ protected validateBoolean<K extends keyof T>(key: K, value: T[K]): void; /** * Validates a string value. * * @param key - The key being validated. * @param value - The string value to validate. * @throws Error if the value is not a non-empty string. */ protected validateString<K extends keyof T>(key: K, value: T[K]): void; /** * Validates an object value. * * @param key - The key being validated. * @param value - The object value to validate. * @throws Error if the value is not a valid object. */ protected validateObject<K extends keyof T>(key: K, value: T[K]): void; /** * Logs validation success for a property. * @param key - The property key. * @param value - The value of the property. */ protected logValidationSuccess(key: keyof T, value: T[keyof T]): void; /** * Throws a standardized validation error. * * @param key - The key being validated. * @param value - The invalid value. * @param message - Additional error message. * @throws Error with a formatted message. */ protected throwValidationError<K extends keyof T>(key: K, value: T[K], message: string): void; }