@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
497 lines (496 loc) • 15 kB
TypeScript
/**
* ### Date Rule
*
* Validates that the field under validation is a valid date.
*
* @example
* ```typescript
* // Class validation
* class Event {
* @IsRequired
* @IsDate
* eventDate: Date;
* }
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsDate: PropertyDecorator;
/**
* ### DateAfter Rule
*
* Validates that the date is after the specified date.
*
* #### Parameters
* - Date to compare against (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Class validation
* class Event {
* @IsDateAfter(new Date('2024-01-01'))
* eventDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing the date to compare against
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsDateAfter: (ruleParameters: [date: string | Date]) => PropertyDecorator;
/**
* ### DateBefore Rule
*
* Validates that the date is before the specified date.
*
* #### Parameters
* - Date to compare against (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Class validation
* class Deadline {
* @IsDateBefore(new Date('2024-12-31'))
* submissionDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing the date to compare against
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsDateBefore: (ruleParameters: [date: string | Date]) => PropertyDecorator;
/**
* ### DateBetween Rule
*
* Validates that the date is between the specified start and end dates (inclusive).
*
* #### Parameters
* - Start date (Date object, ISO string, or timestamp)
* - End date (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Class validation
* class Vacation {
* @IsDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
* vacationDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing start date and end date
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsDateBetween: (ruleParameters: [minDate: string | Date, maxDate: string | Date]) => PropertyDecorator;
/**
* ### SameDate Rule
*
* Validates that the date equals the specified date (compares date part only, ignores time).
*
* #### Parameters
* - Date to compare against (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Class validation
* class Birthday {
* @IsSameDate(new Date('1990-01-01'))
* birthDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing the date to compare against
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsSameDate: (ruleParameters: [string | Date]) => PropertyDecorator;
/**
* ### IsFutureDate Rule
*
* Validates that the date is in the future.
*
* @example
* ```typescript
* // Class validation
* class Appointment {
* @IsFutureDate
* appointmentDate: Date;
* }
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsFutureDate: PropertyDecorator;
/**
* ### PastDate Rule
*
* Validates that the date is in the past.
*
* @example
* ```typescript
* // Class validation
* class HistoricalEvent {
* @IsPastDate
* eventDate: Date;
* }
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
export declare const IsPastDate: PropertyDecorator;
declare module "../types" {
interface IValidatorRulesMap<Context = unknown> {
/**
* ### Date Rule
*
* Validates that the field under validation is a valid date.
*
* @example
* ```typescript
* // Valid dates
* await Validator.validate({
* value: new Date(),
* rules: ['Date']
* }); // ✓ Valid
*
* await Validator.validate({
* value: '2024-01-01',
* rules: ['Date']
* }); // ✓ Valid
*
* await Validator.validate({
* value: 1640995200000,
* rules: ['Date']
* }); // ✓ Valid
*
* // Invalid examples
* await Validator.validate({
* value: 'invalid-date',
* rules: ['Date']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: null,
* rules: ['Date']
* }); // ✗ Invalid
*
* // Class validation
* class Event {
* @Required
* @IsDate
* eventDate: Date;
* }
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
Date: IValidatorRuleParams<[], Context>;
/**
* ### DateAfter Rule
*
* Validates that the date is after the specified date.
*
* #### Parameters
* - Date to compare against (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Valid examples
* await Validator.validate({
* value: new Date('2024-01-02'),
* rules: ['DateAfter[2024-01-01]']
* }); // ✓ Valid
*
* await Validator.validate({
* value: '2024-06-15',
* rules: ['DateAfter[2024-01-01]']
* }); // ✓ Valid
*
* // Invalid examples
* await Validator.validate({
* value: new Date('2023-12-31'),
* rules: ['DateAfter[2024-01-01]']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: '2024-01-01',
* rules: ['DateAfter[2024-01-01]']
* }); // ✗ Invalid (not strictly after)
*
* // Class validation
* class Event {
* @IsDateAfter(new Date('2024-01-01'))
* eventDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing the date to compare against
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
DateAfter: IValidatorRuleParams<[date: string | Date], Context>;
/**
* ### DateBefore Rule
*
* Validates that the date is before the specified date.
*
* #### Parameters
* - Date to compare against (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Valid examples
* await Validator.validate({
* value: new Date('2023-12-31'),
* rules: ['DateBefore[2024-01-01]']
* }); // ✓ Valid
*
* await Validator.validate({
* value: '2023-06-15',
* rules: ['DateBefore[2024-01-01]']
* }); // ✓ Valid
*
* // Invalid examples
* await Validator.validate({
* value: new Date('2024-01-02'),
* rules: ['DateBefore[2024-01-01]']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: '2024-01-01',
* rules: ['DateBefore[2024-01-01]']
* }); // ✗ Invalid (not strictly before)
*
* // Class validation
* class Deadline {
* @IsDateBefore(new Date('2024-12-31'))
* submissionDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing the date to compare against
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
DateBefore: IValidatorRuleParams<[date: string | Date], Context>;
/**
* ### DateBetween Rule
*
* Validates that the date is between the specified start and end dates (inclusive).
*
* #### Parameters
* - Start date (Date object, ISO string, or timestamp)
* - End date (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Valid examples
* await Validator.validate({
* value: new Date('2024-06-15'),
* rules: ['DateBetween[2024-01-01,2024-12-31]']
* }); // ✓ Valid
*
* await Validator.validate({
* value: '2024-01-01',
* rules: ['DateBetween[2024-01-01,2024-12-31]']
* }); // ✓ Valid (inclusive)
*
* // Invalid examples
* await Validator.validate({
* value: new Date('2023-12-31'),
* rules: ['DateBetween[2024-01-01,2024-12-31]']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: '2025-01-01',
* rules: ['DateBetween[2024-01-01,2024-12-31]']
* }); // ✗ Invalid
*
* // Class validation
* class Vacation {
* @IsDateBetween(new Date('2024-01-01'), new Date('2024-12-31'))
* vacationDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing start date and end date
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
DateBetween: IValidatorRuleParams<[
minDate: string | Date,
maxDate: string | Date
], Context>;
/**
* ### SameDate Rule
*
* Validates that the date equals the specified date (compares date part only, ignores time).
*
* #### Parameters
* - Date to compare against (Date object, ISO string, or timestamp)
*
* @example
* ```typescript
* // Valid examples
* await Validator.validate({
* value: new Date('2024-01-01T10:30:00'),
* rules: ['SameDate[2024-01-01]']
* }); // ✓ Valid (time ignored)
*
* await Validator.validate({
* value: '2024-01-01',
* rules: ['SameDate[2024-01-01]']
* }); // ✓ Valid
*
* // Invalid examples
* await Validator.validate({
* value: new Date('2024-01-02'),
* rules: ['SameDate[2024-01-01]']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: '2024-01-01T10:30:00',
* rules: ['SameDate[2024-01-02]']
* }); // ✗ Invalid
*
* // Class validation
* class Birthday {
* @IsSameDate(new Date('1990-01-01'))
* birthDate: Date;
* }
* ```
*
* @param options - Validation options with rule parameters
* @param options.ruleParams - Array containing the date to compare against
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
SameDate: IValidatorRuleParams<[date: string | Date], Context>;
/**
* ### FutureDate Rule
*
* Validates that the date is in the future.
*
* @example
* ```typescript
* // Valid examples
* await Validator.validate({
* value: new Date(Date.now() + 86400000), // Tomorrow
* rules: ['FutureDate']
* }); // ✓ Valid
*
* await Validator.validate({
* value: '2025-01-01',
* rules: ['FutureDate']
* }); // ✓ Valid
*
* // Invalid examples
* await Validator.validate({
* value: new Date(Date.now() - 86400000), // Yesterday
* rules: ['FutureDate']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: new Date(), // Now
* rules: ['FutureDate']
* }); // ✗ Invalid
*
* // Class validation
* class Appointment {
* @IsFutureDate
* appointmentDate: Date;
* }
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
FutureDate: IValidatorRuleParams<[], Context>;
/**
* ### PastDate Rule
*
* Validates that the date is in the past.
*
* @example
* ```typescript
* // Valid examples
* await Validator.validate({
* value: new Date(Date.now() - 86400000), // Yesterday
* rules: ['PastDate']
* }); // ✓ Valid
*
* await Validator.validate({
* value: '2020-01-01',
* rules: ['PastDate']
* }); // ✓ Valid
*
* // Invalid examples
* await Validator.validate({
* value: new Date(Date.now() + 86400000), // Tomorrow
* rules: ['PastDate']
* }); // ✗ Invalid
*
* await Validator.validate({
* value: new Date(), // Now
* rules: ['PastDate']
* }); // ✗ Invalid
*
* // Class validation
* class HistoricalEvent {
* @IsPastDate
* eventDate: Date;
* }
* ```
*
* @param options - Validation options containing value and context
* @returns Promise resolving to true if valid, rejecting with error message if invalid
*
* @since 1.22.0
* @public
*/
PastDate: IValidatorRuleParams<[], Context>;
}
}