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

109 lines (108 loc) 2.55 kB
/** * ### IsRequired Decorator * * Validates that a property has a non-null, non-undefined value. This is * one of the most commonly used validation decorators and should be applied * to any property that must have a value. * * @example * ```typescript * class User { * @IsRequired * username: string; * * @IsRequired * @IsEmail * email: string; * * // Optional field - no @IsRequired * bio?: string; * } * * // Valid data * const user = { username: "john_doe", email: "john@example.com" }; * * // Invalid data * const invalid = { email: "john@example.com" }; // Missing username * // Will fail validation with error: "Username is required" * ``` * * @decorator * @since 1.0.0 * @see {@link IsOptional} - For optional fields * @public */ export declare const IsRequired: PropertyDecorator; /** * ### Empty Decorator * * Marks a field as allowing empty strings, meaning validation will be skipped if the value is an empty string (""). * If the value is not an empty string, other validation rules will still be applied. * * @example * ```typescript * class User { * @IsRequired * @IsEmail * email: string; * * @IsEmpty * @IsString // Only skipped if bio is an empty string * bio: string; * } * ``` * * @decorator * @since 1.23.0 * @public */ export declare const IsEmpty: PropertyDecorator; /** * ### Nullable Decorator * * Marks a field as nullable, meaning validation will be skipped if the value is null or undefined. * If the value is not null or undefined, other validation rules will still be applied. * * @example * ```typescript * class User { * @IsRequired * @IsEmail * email: string; * * @IsNullable * @IsString // Only skipped if bio is null or undefined * bio?: string; * } * ``` * * @decorator * @since 1.23.0 * @public */ export declare const IsNullable: PropertyDecorator; /** * ### Optional Decorator * * Marks a field as sometimes validated, meaning validation will be skipped if the value is undefined. * If the field is not present in the data object, validation is also skipped. * This is useful for optional fields that should only be validated when explicitly provided. * * @example * ```typescript * class User { * @IsRequired * @IsEmail * email: string; * * @IsOptional * @IsUrl // Only validated if website is present in data and not undefined * website?: string; * } * ``` * * @decorator * @since 1.23.0 * @public */ export declare const IsOptional: PropertyDecorator;