-
Notifications
You must be signed in to change notification settings - Fork 451
/
constraint.type.ts
145 lines (142 loc) · 4.36 KB
/
constraint.type.ts
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
143
144
145
/**
* This file is part of OpenMediaVault.
*
* @license http://www.gnu.org/licenses/gpl.html GPL Version 3
* @author Volker Theile <volker.theile@openmediavault.org>
* @copyright Copyright (c) 2009-2024 Volker Theile
*
* OpenMediaVault is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* OpenMediaVault is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
/**
* .------------------------------------------------------------------.
* | operator | arg0 | arg1 |
* |---------------|--------------------|-----------------------------|
* | && || and | constraint | constraint |
* | || || or | constraint | constraint |
* | ! || not | constraint | |
* | if | constraint | constraint |
* | === || eq | constraint || prop | constraint || prop || value |
* | !== || ne | constraint || prop | constraint || prop || value |
* | == | constraint || prop | constraint || prop || value |
* | != | constraint || prop | constraint || prop || value |
* | < || lt | constraint || prop | constraint || prop || value |
* | <= || le | constraint || prop | constraint || prop || value |
* | > || gt | constraint || prop | constraint || prop || value |
* | >= || ge | constraint || prop | constraint || prop || value |
* | empty || z | constraint || prop | |
* | notEmpty || n | constraint || prop | |
* | in | constraint || prop | prop || array || value |
* | startsWith | constraint || prop | value |
* | endsWith | constraint || prop | value |
* | regex | constraint || prop | value |
* | length | prop || value | |
* | UUID | prop || value | |
* | truthy | prop || value | |
* | falsy | prop || value | |
* | has | prop | |
* '------------------------------------------------------------------'
*
* The 'if' operator evaluates the 'arg1' constraint only if 'arg0'
* succeeds: If 'arg0' is falsy, the whole constraint will succeed.
*
* The 'length' operator will return the length of an array or string.
* Make sure to use this operator only for those types.
*
* The 'has' operator checks whether the specified prop exists.
*
* Example 1:
* {
* operator: 'eq',
* arg0: {
* prop: 'password'
* },
* arg1: {
* prop: 'passwordconf'
* }
* }
* Example 2:
* {
* operator: 'ne',
* arg0: {
* prop: 'password'
* },
* arg1: '123456789'
* }
* Example 3:
* {
* operator: 'in',
* arg0: {
* prop: 'language'
* },
* arg1: ['de', 'en', 'fr']
* }
* Example 4:
* {
* operator: 'if',
* arg0: { operator: 'has', arg0: { prop: '_used' } },
* arg1: { operator: 'falsy', arg0: { prop: '_used' } }
* }
*/
export type Constraint = {
operator:
| '&&'
| 'and'
| '||'
| 'or'
| '!'
| 'not'
| 'if'
| '==='
| 'eq'
| '!=='
| 'ne'
| '<>'
| '=='
| '!='
| '<'
| 'lt'
| '<='
| 'le'
| '>'
| 'gt'
| '>='
| 'ge'
| 'empty'
| 'z'
| 'notEmpty'
| 'n'
| 'in'
| 'startsWith'
| 'endsWith'
| 'regex'
| 'length'
| 'UUID'
| 'truthy'
| 'falsy'
| 'has';
arg0: Constraint | ConstraintProperty | ConstraintValue;
arg1?:
| boolean
| number
| string
| Array<number | string>
| Constraint
| ConstraintProperty
| ConstraintValue;
};
export type ConstraintProperty = {
// The path of the property, e.g. 'x' or 'x.y.z'.
prop: string;
};
export type ConstraintValue = {
value: boolean | number | string | Array<number | string>;
};
export type ConstraintRecord = Record<any, any>;