-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapValidator.mts
91 lines (79 loc) · 2.55 KB
/
MapValidator.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
import type {
ArrayValidator,
ExtensibleObjectValidator,
NumberValidator
} from "./internal/internal.mjs";
/**
* Validates the requirements of a <code>Map</code>.
*
* Verifier and Validator methods are equivalent.
* Validators return validation failures through the
* {@link ExtensibleObjectValidator.getFailures | getFailures()} method, while Verifiers throw them as
* exceptions.
*
* @typeParam K - the type the map's keys
* @typeParam V - the type the map's values
*/
interface MapValidator<K, V> extends ExtensibleObjectValidator<MapValidator<K, V>, Map<K, V>>
{
/**
* Ensures that value does not contain any entries
*
* @returns the updated validator
*/
isEmpty(): MapValidator<K, V>;
/**
* Ensures that value contains at least one entry.
*
* @returns the updated validator
*/
isNotEmpty(): MapValidator<K, V>;
/**
* @returns a validator for the Map's keys
*/
keys(): ArrayValidator<K>;
/**
* @param consumer - a function that accepts an {@link ArrayValidator} for the Map's keys
* @returns the updated validator
* @throws TypeError if <code>consumer</code> is not set
*/
keysConsumer(consumer: (actual: ArrayValidator<K>) => void): MapValidator<K, V>;
/**
* @returns a validator for the Map's values
*/
values(): ArrayValidator<V>;
/**
* @param consumer - a function that accepts an {@link ArrayValidator} for the Map's values
* @returns the updated validator
* @throws TypeError if <code>consumer</code> is not set
*/
valuesConsumer(consumer: (actual: ArrayValidator<V>) => void): MapValidator<K, V>;
/**
* @returns validator for the Map's entries (an array of
* <code>[key, value]</code> for each element in the Map)
*/
entries(): ArrayValidator<[K, V]>;
/**
* @param consumer - a function that accepts an {@link ArrayValidator} for the Map's entries (an
* array of <code>[key, value]</code> for each element in the Map)
* @returns the updated validator
* @throws TypeError if <code>consumer</code> is not set
*/
entriesConsumer(consumer: (actual: ArrayValidator<[K, V]>) => void): MapValidator<K, V>;
/**
* @returns a validator for the number of entries this Map contains
*/
size(): NumberValidator;
/**
* @param consumer - a function that accepts a {@link NumberValidator} for the number of entries
* this Map contains
* @returns the updated validator
* @throws TypeError if <code>consumer</code> is not set
*/
sizeConsumer(consumer: (actual: NumberValidator) => void): MapValidator<K, V>;
/**
* {@inheritDoc}
*/
getActual(): Map<K, V> | undefined;
}
export {type MapValidator};