UNPKG

express-image-validator

Version:

Validator of various image parameters in Express.js applications

29 lines (28 loc) 1.69 kB
import type { Request } from 'express'; import type { ValidationError, ValidatorFunctions } from './validators'; import type { ValidationOptions } from '../types/options'; /** * Runs all validator functions for a specific field and collects validation errors. * * Execution flow: * 1. Normalizes the provided schema into `ValidationOptions` (unless `notNormalizeOptions` is `true`). * 2. Runs all field-level validators with the entire array of files. * - If a validator sets `breakValidation`, file-level validation is skipped. * 3. If no break occurred, runs all file-level validators for each individual file. * 4. Collects all errors into a single array, appends them to `req.IMAGE_VALIDATION_RESULTS`, * and returns that array. * * Requirements: * - At least one validator function (field-level or file-level) must be provided, * otherwise an error is thrown. * - `req.files[field]` is normalized into an array internally. * * @param { Request } req Express request object. * @param { string } field Name of the multipart/form-data field to validate. * @param { ValidationOptions } schema Validation options. * @param { ValidatorFunctions } validators Validator functions separated into field-level and file-level. * @param { boolean } [notNormalizeOptions=false] If `true`, skips normalization of `schema` and uses it directly. * @returns { Promise<ValidationError[]> } Collected validation errors. * @throws { Error } If no validator functions are provided. */ export declare function runValidators(req: Request, field: string, schema: ValidationOptions, validators: ValidatorFunctions, notNormalizeOptions?: boolean): Promise<ValidationError[]>;