UNPKG

@resk/core

Version:

An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla

216 lines (215 loc) 6.25 kB
import { IValidatorValidateOptions, IValidatorResult } from "../../types"; /** * ### Greater Than Rule * * Validates that the field under validation is greater than another field's value * or a specific numeric value. * * #### Parameters * - `field` - Name of another field to compare against, OR * - `value` - Specific numeric value to compare against * * @example * ```typescript * // Compare with another field * const data = { * startDate: '2024-01-01', * endDate: '2024-12-31', * minPrice: 10, * maxPrice: 100 * }; * * await Validator.validate({ * value: data.maxPrice, * rules: ['gt:minPrice'], * context: { data } * }); // ✓ Valid (100 > 10) * * // Compare with specific value * await Validator.validate({ * value: 25, * rules: ['gt:18'] * }); // ✓ Valid (25 > 18) * * // Invalid examples * await Validator.validate({ * value: 15, * rules: ['gt:20'] * }); // ✗ Invalid (15 not > 20) * * // Class validation * class PriceRange { * @Numeric * @Min([0]) * minPrice: number; * * @Numeric * @Gt(['minPrice']) * maxPrice: number; // Must be greater than minPrice * } * ``` * * @param options - Validation options with rule parameters and context * @param options.ruleParams - Array containing field name or value to compare * @param options.context - Validation context containing other field values * @returns Promise resolving to true if valid, rejecting with error message if invalid * * @since 1.22.0 * @see {@link https://laravel.com/docs/11.x/validation#rule-gt | Laravel gt Rule} * @public */ export declare function Gt({ value, ruleParams, context, fieldName, translatedPropertyName, ...rest }: IValidatorValidateOptions<string[]>): IValidatorResult; /** * ### Greater Than or Equal Rule * * Validates that the field under validation is greater than or equal to another * field's value or a specific numeric value. * * #### Parameters * - `field` - Name of another field to compare against, OR * - `value` - Specific numeric value to compare against * * @example * ```typescript * // Compare with another field * const data = { * quantity: 10, * minQuantity: 5 * }; * * await Validator.validate({ * value: data.quantity, * rules: ['gte:minQuantity'], * context: { data } * }); // ✓ Valid (10 >= 5) * * // Compare with specific value * await Validator.validate({ * value: 18, * rules: ['gte:18'] * }); // ✓ Valid (18 >= 18) * * // Class validation * class Order { * @Numeric * @Min([1]) * minQuantity: number; * * @Numeric * @Gte(['minQuantity']) * orderQuantity: number; * } * ``` * * @param options - Validation options with rule parameters and context * @param options.ruleParams - Array containing field name or value to compare * @param options.context - Validation context containing other field values * @returns Promise resolving to true if valid, rejecting with error message if invalid * * @since 1.22.0 * @see {@link https://laravel.com/docs/11.x/validation#rule-gte | Laravel gte Rule} * @public */ export declare function Gte({ value, ruleParams, context, fieldName, translatedPropertyName, ...rest }: IValidatorValidateOptions<string[]>): IValidatorResult; /** * ### Less Than Rule * * Validates that the field under validation is less than another field's value * or a specific numeric value. * * #### Parameters * - `field` - Name of another field to compare against, OR * - `value` - Specific numeric value to compare against * * @example * ```typescript * // Compare with another field * const data = { * currentPrice: 50, * originalPrice: 100 * }; * * await Validator.validate({ * value: data.currentPrice, * rules: ['lt:originalPrice'], * context: { data } * }); // ✓ Valid (50 < 100) * * // Compare with specific value * await Validator.validate({ * value: 15, * rules: ['lt:100'] * }); // ✓ Valid (15 < 100) * * // Class validation * class Discount { * @Numeric * originalPrice: number; * * @Numeric * @Lt(['originalPrice']) * salePrice: number; // Must be less than original price * } * ``` * * @param options - Validation options with rule parameters and context * @param options.ruleParams - Array containing field name or value to compare * @param options.context - Validation context containing other field values * @returns Promise resolving to true if valid, rejecting with error message if invalid * * @since 1.22.0 * @see {@link https://laravel.com/docs/11.x/validation#rule-lt | Laravel lt Rule} * @public */ export declare function Lt({ value, ruleParams, context, fieldName, translatedPropertyName, ...rest }: IValidatorValidateOptions<string[]>): IValidatorResult; /** * ### Less Than or Equal Rule * * Validates that the field under validation is less than or equal to another * field's value or a specific numeric value. * * #### Parameters * - `field` - Name of another field to compare against, OR * - `value` - Specific numeric value to compare against * * @example * ```typescript * // Compare with another field * const data = { * quantity: 100, * maxQuantity: 100 * }; * * await Validator.validate({ * value: data.quantity, * rules: ['lte:maxQuantity'], * context: { data } * }); // ✓ Valid (100 <= 100) * * // Compare with specific value * await Validator.validate({ * value: 50, * rules: ['lte:100'] * }); // ✓ Valid (50 <= 100) * * // Class validation * class Capacity { * @Numeric * maxCapacity: number; * * @Numeric * @Lte(['maxCapacity']) * currentLoad: number; * } * ``` * * @param options - Validation options with rule parameters and context * @param options.ruleParams - Array containing field name or value to compare * @param options.context - Validation context containing other field values * @returns Promise resolving to true if valid, rejecting with error message if invalid * * @since 1.22.0 * @see {@link https://laravel.com/docs/11.x/validation#rule-lte | Laravel lte Rule} * @public */ export declare function Lte({ value, ruleParams, context, fieldName, translatedPropertyName, ...rest }: IValidatorValidateOptions<string[]>): IValidatorResult;