@cowwoc/requirements
Version:
A fluent API for enforcing design contracts with automatic message generation.
85 lines (84 loc) • 3.71 kB
text/typescript
import { type ApplicationScope, Pluralizer, Configuration, type ValidationFailure, AbstractValidator, ValidationTarget, type UnsignedNumberValidator } from "../internal.mjs";
/**
* Validates the state of a collection.
*
* @typeParam T - the type the collection
* @typeParam E - the type of elements in the array
*/
declare abstract class AbstractCollectionValidator<T extends undefined | null | E[] | Set<E>, E> extends AbstractValidator<T> {
protected readonly pluralizer: Pluralizer;
/**
* @param scope - the application configuration
* @param configuration - the validator configuration
* @param name - the name of the value
* @param value - the value
* @param pluralizer - the type of items in the array
* @param context - the contextual information set by a parent validator or the user
* @param failures - the list of validation failures
* @throws TypeError if `name` is `undefined` or `null`
* @throws RangeError if `name` contains whitespace, or is empty
* @throws AssertionError if `scope`, `configuration`, `value`, `context` or `failures` are null
*/
constructor(scope: ApplicationScope, configuration: Configuration, name: string, value: ValidationTarget<T>, pluralizer: Pluralizer, context: Map<string, unknown>, failures: ValidationFailure[]);
isEmpty(): this;
/**
* @param value - the collection
* @returns the length of the collection
*/
protected getLength(value: E[] | Set<E>): number;
/**
* @param value - the value
* @returns the array representation of the value
*/
protected collectionAsArray(value: E[] | Set<E>): E[];
/**
* @param value - the value
* @returns the array representation of the value
*/
protected collectionAsSet(value: E[] | Set<E>): Set<E>;
isNotEmpty(): this;
contains(expected: E): this;
/**
* Indicates if an array contains at least one element of another array.
*
* @param value - a collection
* @param element - an element
* @returns true if `value` contains the element
*/
protected collectionContainsElement(value: E[] | Set<E>, element: E): boolean;
doesNotContain(unwanted: E): this;
containsExactly(expected: E[], name?: string): this;
containsExactly(expected: Set<E>, name?: string): this;
doesNotContainExactly(unwanted: E[], name?: string): this;
doesNotContainExactly(unwanted: Set<E>, name?: string): this;
containsAny(expected: E[], name?: string): this;
containsAny(expected: Set<E>, name?: string): this;
/**
* @param first - a set
* @param second - a second set
* @returns `true` if the sets do not contain any of the same elements
*/
private isDisjoint;
doesNotContainAny(unwanted: E[], name?: string): this;
doesNotContainAny(unwanted: Set<E>, name?: string): this;
containsAll(expected: E[], name?: string): this;
containsAll(expected: Set<E>, name?: string): this;
doesNotContainAll(unwanted: E[], name?: string): this;
doesNotContainAll(unwanted: Set<E>, name?: string): this;
/**
* Indicates if an array contains all elements of another array.
*
* @param value - the value
* @param expected - a collection of expected elements
* @returns true if `value` contains all the `expected` elements
*/
private collectionContainsAll;
doesNotContainDuplicates(): this;
/**
* @param value - the value
* @returns the duplicate elements in the value
*/
protected getDuplicates(value: E[]): Set<E>;
length(): UnsignedNumberValidator;
}
export { AbstractCollectionValidator };