UNPKG

@cowwoc/requirements

Version:

A fluent API for enforcing design contracts with automatic message generation.

68 lines (67 loc) 2.16 kB
import { type ValidationFailure } from "./internal/internal.mjs"; /** * A collection of validation failures. */ declare class ValidationFailures { /** * A collection that does not contain any failures. */ static readonly EMPTY: ValidationFailures; private readonly failures; /** * Creates a new instance. * * @param failures - the validation failures * @throws TypeError if `failures` is `undefined` or `null` */ constructor(failures: ValidationFailure[]); /** * Checks if any validation has failed. * * @returns `false` if at least one validation has failed */ isEmpty(): boolean; /** * Returns the list of failed validations. * * @returns an unmodifiable list of failed validations */ getFailures(): ValidationFailure[]; /** * Throws an error if a validation failed; otherwise, returns `true`. * * @returns true if the validation passed * @throws RangeError if a method precondition was violated * @throws AssertionError if a class invariant or method postcondition was violated * @throws MultipleFailuresError if more than one validation failed. This error contains a list of the * failures */ throwOnFailure(): boolean; /** * Returns the validation failure messages. * * @returns an empty list if the validation was successful */ getMessages(): string[]; /** * Returns the error for the validation failures, if any. * * <ol> * <li>Returns `null` if no validation has failed.</li> * <li>Returns `MultipleFailuresError` if there were multiple failures.</li> * <li>Returns `Throwable` if there was one failure.</li> * </ol> * * @returns the error or `null` if no validation has failed */ getError(): Error | null; /** * Adds validation failures into this collection. * * @param failures - the failures to add * @returns this * @throws TypeError if `failures` is `undefined` or `null` */ addAll(failures: ValidationFailures): this; } export { ValidationFailures };