/** * @summary A validation decorator that ensures a property contains a valid file object. * @description * Validates that the decorated property represents a file-like object with valid properties: * - Size must be a non-negative number * - Type must be a non-empty string * - Name must be a non-empty string * Supports both browser File objects and server-side file representations (e.g., Multer files with mimetype/originalname). * * @example * ```typescript * class UploadForm { * @IsFile() * document: File; * } * * const form = new UploadForm(); * form.document = new File(['content'], 'test.txt'); // ✓ Valid * form.document = { name: 'test.txt', size: 1024, type: 'text/plain' }; // ✓ Valid * form.document = { name: '', size: 1024, type: 'text/plain' }; // ✗ Invalid (empty name) * form.document = 'not a file'; // ✗ Invalid * ``` * * @returns A property decorator function for file validation. * * @public */ export declare const IsFile: () => PropertyDecorator; /** * @summary A validation decorator that ensures a file's size does not exceed a maximum limit. * @description * Validates that the decorated file property has a size (in bytes) that is less than or equal * to the specified maximum size. Useful for preventing uploads that are too large. * * @param maxSize - The maximum allowed file size in bytes. * * @example * ```typescript * class UploadForm { * @MaxFileSize(5242880) // 5MB in bytes * document: File; * } * * const form = new UploadForm(); * form.document = new File(['small content'], 'small.txt'); // ✓ Valid (assuming < 5MB) * form.document = new File(['large content'.repeat(100000)], 'large.txt'); // ✗ Invalid (> 5MB) * ``` * * @returns A property decorator function for maximum file size validation. * * @public */ export declare const MaxFileSize: (size: number) => PropertyDecorator; /** * @summary A validation decorator that ensures a file has an allowed MIME type. * @description * Validates that the decorated file property has a MIME type that matches one of the * specified allowed types. Supports exact matches and wildcard patterns (e.g., 'image/*'). * * @param allowedTypes - Array of allowed MIME types (e.g., ['image/jpeg', 'image/png']). * * @example * ```typescript * class ImageUpload { * @IsFileType('image/jpeg', 'image/png', 'image/gif') * image: File; * } * * const upload = new ImageUpload(); * upload.image = new File(['content'], 'photo.jpg', { type: 'image/jpeg' }); // ✓ Valid * upload.image = new File(['content'], 'doc.pdf', { type: 'application/pdf' }); // ✗ Invalid * ``` * * @returns A property decorator function for file type validation. * * @public */ export declare const IsFileType: (...ruleParameters: string[]) => PropertyDecorator; /** * @summary A validation decorator that ensures a file is an image. * @description * Validates that the decorated file property has a MIME type that corresponds to a common * image format (JPEG, PNG, GIF, WebP, SVG, BMP). Useful for image upload validation. * * @example * ```typescript * class ProfilePicture { * @IsImage() * avatar: File; * } * * const profile = new ProfilePicture(); * profile.avatar = new File(['content'], 'photo.jpg', { type: 'image/jpeg' }); // ✓ Valid * profile.avatar = new File(['content'], 'doc.pdf', { type: 'application/pdf' }); // ✗ Invalid * ``` * * @returns A property decorator function for image file validation. * * @public */ export declare const IsImage: () => PropertyDecorator; /** * @summary A validation decorator that ensures a file has an allowed extension. * @description * Validates that the decorated file property has a filename with an extension that matches * one of the specified allowed extensions. Extensions are compared case-insensitively and * automatically handle leading dots. * * @param allowedExtensions - Array of allowed file extensions without dots (e.g., ['pdf', 'doc']). * * @example * ```typescript * class DocumentUpload { * @IsFileExtension('pdf', 'doc', 'docx') * document: File; * } * * const upload = new DocumentUpload(); * upload.document = new File(['content'], 'document.pdf'); // ✓ Valid * upload.document = new File(['content'], 'script.js'); // ✗ Invalid * ``` * * @returns A property decorator function for file extension validation. * * @public */ export declare const IsFileExtension: (...ruleParameters: string[]) => PropertyDecorator; /** * @summary A validation decorator that ensures a file meets a minimum size requirement. * @description * Validates that the decorated file property has a size (in bytes) that is greater than or equal * to the specified minimum size. Useful for preventing empty or suspiciously small files. * * @param minSize - The minimum required file size in bytes. * * @example * ```typescript * class UploadForm { * @MinFileSize(1024) // 1KB minimum * document: File; * } * * const form = new UploadForm(); * form.document = new File(['sufficient content'], 'file.txt'); // ✓ Valid (>= 1KB) * form.document = new File(['tiny'], 'empty.txt'); // ✗ Invalid (< 1KB) * ``` * * @returns A property decorator function for minimum file size validation. * * @public */ export declare const MinFileSize: (minSize: number) => PropertyDecorator; declare module '../types' { interface ValidatorRuleParamTypes { /** * @summary Validates that the field contains a valid file object. * @description * Ensures the input represents a file-like object with valid properties: * - Size must be a non-negative number * - Type must be a non-empty string * - Name must be a non-empty string * Accepts both browser File objects and server-side file representations (e.g., Multer files with mimetype/originalname). * * @example * ```typescript * // Valid file objects * await Validator.validate({ * value: { name: 'test.txt', size: 1024, type: 'text/plain' }, * rules: ['File'] * }); // ✓ Valid * * await Validator.validate({ * value: new File(['content'], 'test.txt'), * rules: ['File'] * }); // ✓ Valid * * // Invalid inputs * await Validator.validate({ * value: { name: '', size: 1024, type: 'text/plain' }, * rules: ['File'] * }); // ✗ Invalid (empty name) * * await Validator.validate({ * value: 'not a file', * rules: ['File'] * }); // ✗ Invalid * * await Validator.validate({ * value: null, * rules: ['File'] * }); // ✗ Invalid * ``` * * @public */ File: ValidatorRuleParams<[]>; /** * @summary Validates that the file size does not exceed a maximum limit. * @description * Checks that the file's size in bytes is less than or equal to the specified maximum size. * Useful for preventing uploads that exceed storage or bandwidth limits. * * @param size - The maximum allowed file size in bytes. * * @example * ```typescript * // Valid examples (file size <= limit) * await Validator.validate({ * value: { name: 'small.txt', size: 1024, type: 'text/plain' }, * rules: [{MaxFileSize:[2048]}] * }); // ✓ Valid (1KB <= 2KB) * * // Invalid examples (file size > limit) * await Validator.validate({ * value: { name: 'large.txt', size: 5242880, type: 'text/plain' }, * rules: [{MaxFileSize:[2048]}] * }); // ✗ Invalid (5MB > 2KB) * * await Validator.validate({ * value: 'not a file', * rules: [{MaxFileSize:[2048]}] * }); // ✗ Invalid (not a file) * ``` * * @public */ MaxFileSize: ValidatorRuleParams<[size: number]>; /** * @summary Validates that the file has an allowed MIME type. * @description * Checks that the file's MIME type matches one of the specified allowed types. * Supports exact matches and wildcard patterns for broader type categories. * * @param allowedTypes - Array of allowed MIME types (e.g., ['image/jpeg', 'application/pdf']). * * @example * ```typescript * // Valid examples (matching MIME types) * await Validator.validate({ * value: { name: 'photo.jpg', size: 1024, type: 'image/jpeg' }, * rules: [{'FileType:["image/jpeg","image/png"]}] * }); // ✓ Valid * * await Validator.validate({ * value: { name: 'doc.pdf', size: 1024, type: 'application/pdf' }, * rules: [{FileType:['application/pdf']}] * }); // ✓ Valid * * // Invalid examples (non-matching types) * await Validator.validate({ * value: { name: 'script.js', size: 1024, type: 'application/javascript' }, * rules: [{FileType:["image/jpeg","image/png"]}] * }); // ✗ Invalid * ``` * * @public */ FileType: ValidatorRuleParams; /** * @summary Validates that the file is an image based on MIME type. * @description * Checks that the file's MIME type corresponds to a supported image format. * Supports common image types including JPEG, PNG, GIF, WebP, SVG, and BMP. * * @example * ```typescript * // Valid examples (image MIME types) * await Validator.validate({ * value: { name: 'photo.jpg', size: 1024, type: 'image/jpeg' }, * rules: ['Image'] * }); // ✓ Valid * * await Validator.validate({ * value: { name: 'pic.png', size: 1024, type: 'image/png' }, * rules: ['Image'] * }); // ✓ Valid * * // Invalid examples (non-image types) * await Validator.validate({ * value: { name: 'doc.pdf', size: 1024, type: 'application/pdf' }, * rules: ['Image'] * }); // ✗ Invalid * * await Validator.validate({ * value: 'not a file', * rules: ['Image'] * }); // ✗ Invalid * ``` * * @public */ Image: ValidatorRuleParams<[]>; /** * @summary Validates that the file has an allowed extension. * @description * Checks that the file's name ends with one of the specified extensions. * Extensions are compared case-insensitively and leading dots are handled automatically. * * @param allowedExtensions - Array of allowed file extensions without dots (e.g., ['pdf', 'jpg']). * * @example * ```typescript * // Valid examples (matching extensions) * await Validator.validate({ * value: { name: 'document.pdf', size: 1024, type: 'application/pdf' }, * rules: [{FileExtension:["pdf","doc","docx"]}] * }); // ✓ Valid * * await Validator.validate({ * value: { name: 'script.JS', size: 1024, type: 'application/javascript' }, * rules: ['FileExtension[js,ts]'] * }); // ✓ Valid (case-insensitive) * * // Invalid examples (non-matching extensions) * await Validator.validate({ * value: { name: 'image.exe', size: 1024, type: 'application/octet-stream' }, * rules: [{FileExtension:["pdf","doc","docx"]}] * }); // ✗ Invalid * ``` * * @public */ FileExtension: ValidatorRuleParams; /** * @summary Validates that the file size meets a minimum requirement. * @description * Checks that the file's size in bytes is greater than or equal to the specified minimum size. * Useful for ensuring files are not empty or suspiciously small. * * @param minSize - The minimum required file size in bytes. * * @example * ```typescript * // Valid examples (file size >= minimum) * await Validator.validate({ * value: { name: 'file.txt', size: 2048, type: 'text/plain' }, * rules: [{MinFileSize:[1024]}] * }); // ✓ Valid (2KB >= 1KB) * * // Invalid examples (file size < minimum) * await Validator.validate({ * value: { name: 'small.txt', size: 512, type: 'text/plain' }, * rules: [{MinFileSize:[1024]}] * }); // ✗ Invalid (512B < 1KB) * * await Validator.validate({ * value: 'not a file', * rules: [{MinFileSize:[1024]}] * }); // ✗ Invalid (not a file) * ``` * * @public */ MinFileSize: ValidatorRuleParams<[minSize: number]>; } }