import type { IConstraint, PathLike, ValidatorConstraintOptions } from "../types"; import type { ValidationArguments } from 'class-validator'; /** * @file Decorator Constraints - IsPathConstraint * @module grease/constraints/IsPath */ /** * Custom validator for the `IsPath` decorator. * * @implements {IConstraint} */ export default class IsPathConstraint implements IConstraint { /** * @static * @readonly * @property {ValidatorConstraintOptions} options - Custom constraint options */ static readonly options: ValidatorConstraintOptions; /** * Returns the default error message if validation fails. * * @param {ValidationArguments} args - Message builder arguments * @param {any[]} args.constraints - Validator constraints * @param {IsPathOptions} args.constraints.0 - Validation options * @param {ValidationMessage} [args.constraints.0.message] - Error message * @return {string} Default error message */ defaultMessage(args: ValidationArguments): string; /** * Returns `true` if `value` is `string | Buffer | String | URL`. * * @param {any} value - Value to test against constraint * @return {boolean} Boolean indicating value is `PathLike` */ isPathLike(value: any): value is PathLike; /** * Checks if `value` is a valid file system path where the type is `string | * Buffer | String | URL`, aka `PathLike`. * * If `args.constraints[0].exists` is `true` (the default), the function will * return `false` if the path does not exist within the file system. * * If validation fails, the arguments context `args.constraints[0].context`, * will be modified. * * @param {any} value - Value to test against constraint * @param {ValidationArguments} args - Message builder arguments * @param {any[]} args.constraints - Validator constraints * @param {IsPathOptions} args.constraints.0 - Validation options * @param {boolean} [args.constraints.0.cwd] - Prepend `process.cwd()` * @param {boolean} [args.constraints.0.exists] - Check if path exists * @param {boolean} [args.constraints.0.gh] - Treat as GitHub release asset * path and ignore possible display label (e.g: `'/asset.zip#My label'`) * @return {boolean} Boolean indicating if value is `PathLike` and may exist */ validate(value: any, args: ValidationArguments): value is PathLike; }