-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayValidator.mts
142 lines (127 loc) · 4.41 KB
/
ArrayValidator.mts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import type {
ExtensibleObjectValidator,
NumberValidator,
ObjectValidator
} from "./internal/internal.mjs";
const typedocWorkaround: null | ObjectValidator<void> = null;
// noinspection PointlessBooleanExpressionJS
if (typedocWorkaround !== null)
console.log("WORKAROUND: https://github.com/microsoft/tsdoc/issues/348");
/**
* Validates the requirements of an array.
*
* Verifier and Validator methods are equivalent.
* Validators return validation failures through the
* {@link ExtensibleObjectValidator.getFailures | getFailures()} method, while Verifiers throw them as
* exceptions.
*
* All methods (except those found in {@link ObjectValidator}) assume that the actual value is not null.
*
* @typeParam E - the type the array elements
*/
interface ArrayValidator<E> extends ExtensibleObjectValidator<ArrayValidator<E>, E[]>
{
/**
* Ensures that the actual value is empty.
*
* @returns the updated validator
*/
isEmpty(): ArrayValidator<E>;
/**
* Ensures that the actual value is not empty.
*
* @returns the updated validator
*/
isNotEmpty(): ArrayValidator<E>;
/**
* Ensures that the array contains an element.
*
* @param element - the element that must exist
* @param name - (optional) the name of the element
* @returns the updated validator
* @throws TypeError if <code>name</code> is null
* @throws RangeError if <code>name</code> is empty
*/
contains(element: E, name?: string): ArrayValidator<E>;
/**
* Ensures that the array contains exactly the specified elements; nothing less, nothing more.
*
* @param expected - the elements that must exist
* @param name - (optional) the name of the expected elements
* @returns the updated validator
* @throws TypeError if <code>name</code> is null
* @throws RangeError if <code>name</code> is empty
*/
containsExactly(expected: E[], name?: string): ArrayValidator<E>;
/**
* Ensures that the array contains any of the specified elements.
*
* @param expected - the elements that must exist
* @param name - (optional) the name of the expected elements
* @returns the updated validator
* @throws TypeError if <code>name</code> is null
* @throws RangeError if <code>name</code> is empty
*/
containsAny(expected: E[], name?: string): ArrayValidator<E>;
/**
* Ensures that the array contains all the specified elements.
*
* @param expected - the elements that must exist
* @param name - (optional) the name of the expected elements
* @returns the updated validator
* @throws TypeError if <code>name</code> is null
* @throws RangeError if <code>name</code> is empty
*/
containsAll(expected: E[], name?: string): ArrayValidator<E>;
/**
* Ensures that the array does not contain an element.
*
* @param element - the element that must not exist
* @param name - (optional) the name of the element
* @returns the updated validator
* @throws TypeError if <code>name</code> is null
* @throws RangeError if <code>name</code> is empty
*/
doesNotContain(element: E, name?: string): ArrayValidator<E>;
/**
* Ensures that the array does not contain any of the specified elements.
*
* @param elements - the elements that must not exist
* @param name - (optional) the name of the elements
* @returns the updated validator
* @throws TypeError if <code>name</code> is null
* @throws RangeError if <code>name</code> is empty
*/
doesNotContainAny(elements: E[], name?: string): ArrayValidator<E>;
/**
* Ensures that the array does not contain all the specified elements.
*
* @param elements - the elements that must not exist
* @param name - (optional) the name of the elements
* @returns the updated validator
* @throws TypeError if <code>name</code> is null
* @throws RangeError if <code>name</code> is empty
*/
doesNotContainAll(elements: E[], name?: string): ArrayValidator<E>;
/**
* Ensures that the array does not contain any duplicate elements.
*
* @returns the updated validator
*/
doesNotContainDuplicates(): ArrayValidator<E>;
/**
* @returns a validator for the length of the array
*/
length(): NumberValidator;
/**
* @param consumer - a function that accepts a {@link NumberValidator} for the length of the array
* @returns the updated validator
* @throws TypeError if <code>consumer</code> is not set
*/
lengthConsumer(consumer: (length: NumberValidator) => void): ArrayValidator<E>;
/**
* {@inheritDoc}
*/
getActual(): E[] | undefined;
}
export {type ArrayValidator};