xdbc 1.0.217 → 1.0.219
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +16 -8
- package/.vscode/settings.json +3 -3
- package/.vscode/tasks.json +23 -23
- package/ASSESSMENT.md +249 -0
- package/README.md +538 -408
- package/__tests__/DBC/AE.test.ts +62 -62
- package/__tests__/DBC/ARRAY.test.ts +91 -91
- package/__tests__/DBC/DEFINED.test.ts +53 -53
- package/__tests__/DBC/DOM.test.ts +786 -0
- package/__tests__/DBC/Decorators.test.ts +367 -367
- package/__tests__/DBC/EQ.test.ts +13 -13
- package/__tests__/DBC/GREATER.test.ts +31 -31
- package/__tests__/DBC/HasAttribute.test.ts +60 -60
- package/__tests__/DBC/IF.test.ts +62 -62
- package/__tests__/DBC/INSTANCE.test.ts +13 -13
- package/__tests__/DBC/JSON.OP.test.ts +47 -47
- package/__tests__/DBC/JSON.Parse.test.ts +17 -17
- package/__tests__/DBC/OR.test.ts +14 -14
- package/__tests__/DBC/PLAIN_OBJECT.test.ts +109 -109
- package/__tests__/DBC/REGEX.test.ts +17 -17
- package/__tests__/DBC/TYPE.test.ts +13 -13
- package/__tests__/DBC/UNDEFINED.test.ts +45 -45
- package/__tests__/DBC/ZOD.test.ts +54 -54
- package/__tests__/DBC/onInfringement.test.ts +262 -0
- package/biome.json +45 -40
- package/dist/DBC/AE.js +172 -0
- package/dist/DBC/ARR/PLAIN_OBJECT.d.ts +0 -3
- package/dist/DBC/ARR/PLAIN_OBJECT.js +95 -0
- package/dist/DBC/ARRAY.d.ts +0 -3
- package/dist/DBC/ARRAY.js +90 -0
- package/dist/DBC/COMPARISON/GREATER.js +21 -0
- package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +21 -0
- package/dist/DBC/COMPARISON/LESS.js +21 -0
- package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +21 -0
- package/dist/DBC/COMPARISON.js +98 -0
- package/dist/DBC/DEFINED.js +87 -0
- package/dist/DBC/DOM.d.ts +123 -0
- package/dist/DBC/DOM.js +362 -0
- package/dist/DBC/EQ/DIFFERENT.js +34 -0
- package/dist/DBC/EQ.js +101 -0
- package/dist/DBC/GREATER.js +99 -0
- package/dist/DBC/HasAttribute.js +101 -0
- package/dist/DBC/IF.js +96 -0
- package/dist/DBC/INSTANCE.js +122 -0
- package/dist/DBC/JSON.OP.js +120 -0
- package/dist/DBC/JSON.Parse.js +104 -0
- package/dist/DBC/OR.js +125 -0
- package/dist/DBC/REGEX.js +136 -0
- package/dist/DBC/TYPE.js +112 -0
- package/dist/DBC/UNDEFINED.js +87 -0
- package/dist/DBC/ZOD.js +99 -0
- package/dist/DBC.d.ts +18 -4
- package/dist/DBC.js +645 -0
- package/dist/Demo.d.ts +10 -0
- package/dist/Demo.js +713 -0
- package/dist/Test.html +18 -0
- package/dist/bundle.js +6140 -405
- package/dist/index.d.ts +22 -0
- package/dist/index.html +18 -0
- package/dist/index.js +22 -0
- package/docs/assets/highlight.css +22 -22
- package/docs/assets/icons.js +17 -17
- package/docs/assets/main.js +60 -60
- package/docs/assets/style.css +1640 -1640
- package/docs/classes/DBC.DBC.html +98 -98
- package/docs/classes/DBC_AE.AE.html +160 -160
- package/docs/classes/DBC_EQ.EQ.html +131 -131
- package/docs/classes/DBC_GREATER.GREATER.html +139 -139
- package/docs/classes/DBC_INSTANCE.INSTANCE.html +130 -130
- package/docs/classes/DBC_JSON.OP.JSON_OP.html +138 -138
- package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +129 -129
- package/docs/classes/DBC_OR.OR.html +137 -137
- package/docs/classes/DBC_REGEX.REGEX.html +136 -136
- package/docs/classes/DBC_TYPE.TYPE.html +130 -130
- package/docs/classes/Demo.Demo.html +14 -14
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +1 -1
- package/docs/modules/DBC.html +1 -1
- package/docs/modules/DBC_AE.html +1 -1
- package/docs/modules/DBC_EQ.html +1 -1
- package/docs/modules/DBC_GREATER.html +1 -1
- package/docs/modules/DBC_INSTANCE.html +1 -1
- package/docs/modules/DBC_JSON.OP.html +1 -1
- package/docs/modules/DBC_JSON.Parse.html +1 -1
- package/docs/modules/DBC_OR.html +1 -1
- package/docs/modules/DBC_REGEX.html +1 -1
- package/docs/modules/DBC_TYPE.html +1 -1
- package/docs/modules/Demo.html +1 -1
- package/jest.config.js +32 -32
- package/package.json +71 -55
- package/src/DBC/AE.ts +269 -288
- package/src/DBC/ARR/PLAIN_OBJECT.ts +122 -133
- package/src/DBC/ARRAY.ts +117 -127
- package/src/DBC/COMPARISON/GREATER.ts +41 -46
- package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +41 -45
- package/src/DBC/COMPARISON/LESS.ts +41 -45
- package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +41 -45
- package/src/DBC/COMPARISON.ts +149 -159
- package/src/DBC/DEFINED.ts +117 -122
- package/src/DBC/DOM.ts +453 -0
- package/src/DBC/EQ/DIFFERENT.ts +51 -57
- package/src/DBC/EQ.ts +154 -163
- package/src/DBC/HasAttribute.ts +149 -154
- package/src/DBC/IF.ts +173 -179
- package/src/DBC/INSTANCE.ts +168 -171
- package/src/DBC/JSON.OP.ts +178 -186
- package/src/DBC/JSON.Parse.ts +150 -157
- package/src/DBC/OR.ts +183 -187
- package/src/DBC/REGEX.ts +195 -196
- package/src/DBC/TYPE.ts +142 -149
- package/src/DBC/UNDEFINED.ts +115 -117
- package/src/DBC/ZOD.ts +130 -135
- package/src/DBC.ts +902 -904
- package/src/Demo.ts +537 -404
- package/src/index.ts +22 -0
- package/tsconfig.json +18 -18
- package/tsconfig.test.json +7 -7
- package/typedoc.json +16 -16
- package/webpack.config.js +27 -27
- package/Assessment.md +0 -507
package/src/DBC/AE.ts
CHANGED
|
@@ -1,288 +1,269 @@
|
|
|
1
|
-
import { DBC } from "../DBC";
|
|
2
|
-
/**
|
|
3
|
-
* A {@link DBC } defining that all elements of an {@link object }s have to fulfill
|
|
4
|
-
* a given {@link object }'s check-method (**( toCheck : any ) => boolean | string**).
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
8
|
-
export class AE extends DBC {
|
|
9
|
-
// #region Condition checking.
|
|
10
|
-
/**
|
|
11
|
-
* Checks each element of the **value**-{@link Array < any >} against the given **condition**, if it is one. If it is not
|
|
12
|
-
* the **value** itself will be checked.
|
|
13
|
-
*
|
|
14
|
-
* @param condition The { check: (toCheck: any) => boolean | string } to check the **value** against.
|
|
15
|
-
* @param value Either **value**-{@link Array < any >}, which's elements will be checked, or the value to be
|
|
16
|
-
* checked itself.
|
|
17
|
-
* @param index If specified with **idxEnd** being undefined, this {@link Number } will be seen as the index of
|
|
18
|
-
* the value-{@link Array }'s element to check. If value isn't an {@link Array } this parameter
|
|
19
|
-
* will not have any effect.
|
|
20
|
-
* With **idxEnd** not undefined this parameter indicates the beginning of the span of elements to
|
|
21
|
-
* check within the value-{@link Array }.
|
|
22
|
-
* @param idxEnd Indicates the last element's index (including) of the span of value-{@link Array } elements to check.
|
|
23
|
-
* Setting this parameter to -1 specifies that all value-{@link Array }'s elements beginning from the
|
|
24
|
-
* specified **index** shall be checked.
|
|
25
|
-
*
|
|
26
|
-
* @returns As soon as the **condition** returns a {@link string }, instead of TRUE, the returned string. TRUE if the
|
|
27
|
-
* **condition** never returns a {@link string}. */
|
|
28
|
-
public static checkAlgorithm(
|
|
29
|
-
condition: {
|
|
30
|
-
check: (toCheck: unknown | null | undefined) => boolean | string;
|
|
31
|
-
},
|
|
32
|
-
value: object,
|
|
33
|
-
index: number | undefined,
|
|
34
|
-
idxEnd: number | undefined,
|
|
35
|
-
): boolean | string {
|
|
36
|
-
if (Array.isArray(value)) {
|
|
37
|
-
if (index !== undefined && idxEnd === undefined) {
|
|
38
|
-
if (index > -1 && index < value.length) {
|
|
39
|
-
const result = condition.check(value[index]);
|
|
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
|
-
* @param
|
|
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
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Creates this {@link AE } by setting the protected property {@link AE.conditions }, {@link AE.index } and {@link AE.idxEnd } used by {@link AE.check }.
|
|
273
|
-
*
|
|
274
|
-
* @param equivalent See {@link EQ.check }. */
|
|
275
|
-
public constructor(
|
|
276
|
-
protected conditions: // biome-ignore lint/suspicious/noExplicitAny: Must match DBC factory signature
|
|
277
|
-
| Array<{
|
|
278
|
-
check: (toCheck: any) => boolean | string;
|
|
279
|
-
}>
|
|
280
|
-
// biome-ignore lint/suspicious/noExplicitAny: Must match DBC factory signature
|
|
281
|
-
| { check: (toCheck: any) => boolean | string },
|
|
282
|
-
protected index: number | undefined = undefined,
|
|
283
|
-
protected idxEnd: number | undefined = undefined,
|
|
284
|
-
) {
|
|
285
|
-
super();
|
|
286
|
-
}
|
|
287
|
-
// #endregion Referenced Condition checking.
|
|
288
|
-
}
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that all elements of an {@link object }s have to fulfill
|
|
4
|
+
* a given {@link object }'s check-method (**( toCheck : any ) => boolean | string**).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
8
|
+
export class AE extends DBC {
|
|
9
|
+
// #region Condition checking.
|
|
10
|
+
/**
|
|
11
|
+
* Checks each element of the **value**-{@link Array < any >} against the given **condition**, if it is one. If it is not
|
|
12
|
+
* the **value** itself will be checked.
|
|
13
|
+
*
|
|
14
|
+
* @param condition The { check: (toCheck: any) => boolean | string } to check the **value** against.
|
|
15
|
+
* @param value Either **value**-{@link Array < any >}, which's elements will be checked, or the value to be
|
|
16
|
+
* checked itself.
|
|
17
|
+
* @param index If specified with **idxEnd** being undefined, this {@link Number } will be seen as the index of
|
|
18
|
+
* the value-{@link Array }'s element to check. If value isn't an {@link Array } this parameter
|
|
19
|
+
* will not have any effect.
|
|
20
|
+
* With **idxEnd** not undefined this parameter indicates the beginning of the span of elements to
|
|
21
|
+
* check within the value-{@link Array }.
|
|
22
|
+
* @param idxEnd Indicates the last element's index (including) of the span of value-{@link Array } elements to check.
|
|
23
|
+
* Setting this parameter to -1 specifies that all value-{@link Array }'s elements beginning from the
|
|
24
|
+
* specified **index** shall be checked.
|
|
25
|
+
*
|
|
26
|
+
* @returns As soon as the **condition** returns a {@link string }, instead of TRUE, the returned string. TRUE if the
|
|
27
|
+
* **condition** never returns a {@link string}. */
|
|
28
|
+
public static checkAlgorithm(
|
|
29
|
+
condition: {
|
|
30
|
+
check: (toCheck: unknown | null | undefined) => boolean | string;
|
|
31
|
+
},
|
|
32
|
+
value: object,
|
|
33
|
+
index: number | undefined,
|
|
34
|
+
idxEnd: number | undefined,
|
|
35
|
+
): boolean | string {
|
|
36
|
+
if (Array.isArray(value)) {
|
|
37
|
+
if (index !== undefined && idxEnd === undefined) {
|
|
38
|
+
if (index > -1 && index < value.length) {
|
|
39
|
+
const result = condition.check(value[index]);
|
|
40
|
+
if (typeof result === "string") {
|
|
41
|
+
return `Violating-Arrayelement at index "${index}" with value "${value[index]}". ${result}`;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return true; // In order for optional parameter to not cause an error if they are omitted.
|
|
45
|
+
}
|
|
46
|
+
const ending =
|
|
47
|
+
idxEnd !== undefined
|
|
48
|
+
? idxEnd !== -1
|
|
49
|
+
? idxEnd + 1
|
|
50
|
+
: (value as []).length
|
|
51
|
+
: (value as []).length;
|
|
52
|
+
for (let i = index ? index : 0; i < ending; i++) {
|
|
53
|
+
const result = condition.check(value[i]);
|
|
54
|
+
if (result !== true) {
|
|
55
|
+
return `Violating-Arrayelement at index ${i}. ${result}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
return condition.check(value);
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A parameter-decorator factory using the {@link AE.checkAlgorithm } with either multiple or a single one
|
|
65
|
+
* of the **realConditions** to check the tagged parameter-value against with.
|
|
66
|
+
* When specifying an **index** and the tagged parameter's **value** is an {@link Array }, the **realConditions** apply to the
|
|
67
|
+
* element at the specified **index**.
|
|
68
|
+
* If the {@link Array } is too short the currently processed { check: (toCheck: any) => boolean | string } of
|
|
69
|
+
* **realConditions** will be verified to TRUE automatically, considering optional parameters.
|
|
70
|
+
* If an **index** is specified but the tagged parameter's value isn't an array, the **index** is treated as being undefined.
|
|
71
|
+
* If **index** is undefined and the tagged parameter's value is an {@link Array } each element of it will be checked
|
|
72
|
+
* against the **realConditions**.
|
|
73
|
+
*
|
|
74
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
75
|
+
* against with.
|
|
76
|
+
* @param index See the {@link AE.checkAlgorithm }.
|
|
77
|
+
* @param idxEnd See the {@link AE.checkAlgorithm }.
|
|
78
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
79
|
+
* @param hint See {@link DBC.decPrecondition }.
|
|
80
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
81
|
+
*
|
|
82
|
+
* @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of **realConditions** returns one.
|
|
83
|
+
* Otherwise TRUE. */
|
|
84
|
+
public static PRE(
|
|
85
|
+
realConditions:
|
|
86
|
+
| Array<{
|
|
87
|
+
check: (toCheck: unknown | undefined | null) => boolean | string;
|
|
88
|
+
}>
|
|
89
|
+
| { check: (toCheck: unknown | undefined | null) => boolean | string },
|
|
90
|
+
index: number | undefined = undefined,
|
|
91
|
+
idxEnd: number | undefined = undefined,
|
|
92
|
+
path: string | undefined = undefined,
|
|
93
|
+
hint: string | undefined = undefined,
|
|
94
|
+
dbc: string | undefined = undefined,
|
|
95
|
+
): (
|
|
96
|
+
target: object,
|
|
97
|
+
methodName: string | symbol | undefined,
|
|
98
|
+
parameterIndex: number,
|
|
99
|
+
) => void {
|
|
100
|
+
return DBC.decPrecondition(
|
|
101
|
+
(
|
|
102
|
+
value: any,
|
|
103
|
+
target: object,
|
|
104
|
+
methodName: string | symbol | undefined,
|
|
105
|
+
parameterIndex: number,
|
|
106
|
+
) => {
|
|
107
|
+
if (Array.isArray(realConditions)) {
|
|
108
|
+
for (const currentCondition of realConditions) {
|
|
109
|
+
const result = AE.checkAlgorithm(
|
|
110
|
+
currentCondition,
|
|
111
|
+
value,
|
|
112
|
+
index,
|
|
113
|
+
idxEnd,
|
|
114
|
+
);
|
|
115
|
+
if (typeof result !== "boolean") return result;
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
return AE.checkAlgorithm(
|
|
119
|
+
realConditions as {
|
|
120
|
+
check: (toCheck: unknown | undefined | null) => boolean | string;
|
|
121
|
+
},
|
|
122
|
+
value,
|
|
123
|
+
index,
|
|
124
|
+
idxEnd,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
return true;
|
|
128
|
+
},
|
|
129
|
+
dbc,
|
|
130
|
+
path,
|
|
131
|
+
hint,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* A method-decorator factory using the {@link AE.checkAlgorithm } with either multiple or a single one
|
|
136
|
+
* of the **realConditions** to check the tagged method's return-value against with.
|
|
137
|
+
*
|
|
138
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
139
|
+
* against with.
|
|
140
|
+
* @param index See the {@link AE.checkAlgorithm }.
|
|
141
|
+
* @param idxEnd See the {@link AE.checkAlgorithm }.
|
|
142
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
143
|
+
* @param hint See {@link DBC.decPrecondition }.
|
|
144
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
145
|
+
*
|
|
146
|
+
* @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of **realConditions** return one.
|
|
147
|
+
* Otherwise TRUE. */
|
|
148
|
+
public static POST(
|
|
149
|
+
realConditions:
|
|
150
|
+
| Array<{ check: (toCheck: any) => boolean | string }>
|
|
151
|
+
| { check: (toCheck: any) => boolean | string },
|
|
152
|
+
index: number | undefined = undefined,
|
|
153
|
+
idxEnd: number | undefined = undefined,
|
|
154
|
+
path: string | undefined = undefined,
|
|
155
|
+
hint: string | undefined = undefined,
|
|
156
|
+
dbc: string | undefined = undefined,
|
|
157
|
+
): (
|
|
158
|
+
target: object,
|
|
159
|
+
propertyKey: string,
|
|
160
|
+
descriptor: PropertyDescriptor,
|
|
161
|
+
) => PropertyDescriptor {
|
|
162
|
+
return DBC.decPostcondition(
|
|
163
|
+
(value: object, target: object, propertyKey: string) => {
|
|
164
|
+
if (Array.isArray(realConditions)) {
|
|
165
|
+
for (const currentCondition of realConditions) {
|
|
166
|
+
const result = AE.checkAlgorithm(
|
|
167
|
+
currentCondition,
|
|
168
|
+
value,
|
|
169
|
+
index,
|
|
170
|
+
idxEnd,
|
|
171
|
+
);
|
|
172
|
+
if (typeof result !== "boolean") return result;
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
return AE.checkAlgorithm(
|
|
176
|
+
realConditions as { check: (toCheck: any) => boolean | string },
|
|
177
|
+
value,
|
|
178
|
+
index,
|
|
179
|
+
idxEnd,
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
},
|
|
184
|
+
dbc,
|
|
185
|
+
path,
|
|
186
|
+
hint,
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* A field-decorator factory using the {@link AE.checkAlgorithm } with either multiple or a single one
|
|
191
|
+
* of the **realConditions** to check the tagged field.
|
|
192
|
+
*
|
|
193
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
194
|
+
* against with.
|
|
195
|
+
* @param index See the {@link AE.checkAlgorithm }.
|
|
196
|
+
* @param idxEnd See the {@link AE.checkAlgorithm }.
|
|
197
|
+
* @param path See {@link DBC.decInvariant }.
|
|
198
|
+
* @param hint See {@link DBC.decInvariant }.
|
|
199
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
200
|
+
*
|
|
201
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
202
|
+
public static INVARIANT(
|
|
203
|
+
realConditions:
|
|
204
|
+
| Array<{ check: (toCheck: any) => boolean | string }>
|
|
205
|
+
| { check: (toCheck: any) => boolean | string },
|
|
206
|
+
index: number | undefined = undefined,
|
|
207
|
+
idxEnd: number | undefined = undefined,
|
|
208
|
+
path: string | undefined = undefined,
|
|
209
|
+
hint: string | undefined = undefined,
|
|
210
|
+
dbc: string | undefined = undefined,
|
|
211
|
+
) {
|
|
212
|
+
return DBC.createINVARIANT(
|
|
213
|
+
AE,
|
|
214
|
+
[realConditions, index, idxEnd],
|
|
215
|
+
dbc,
|
|
216
|
+
path,
|
|
217
|
+
hint,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
// #endregion Condition checking.
|
|
221
|
+
// #region Referenced Condition checking.
|
|
222
|
+
//
|
|
223
|
+
// For usage in dynamic scenarios (like global functions).
|
|
224
|
+
//
|
|
225
|
+
/**
|
|
226
|
+
* Invokes the {@link AE.checkAlgorithm } with all {@link AE.conditions } and the {@link object } {@link toCheck },
|
|
227
|
+
* {@link AE.index } & {@link AE.idxEnd }.
|
|
228
|
+
*
|
|
229
|
+
* @param toCheck See {@link AE.checkAlgorithm }.
|
|
230
|
+
*
|
|
231
|
+
* @returns See {@link EQ.checkAlgorithm}. */
|
|
232
|
+
public check(toCheck: any) {
|
|
233
|
+
if (Array.isArray(this.conditions)) {
|
|
234
|
+
for (const currentCondition of this.conditions) {
|
|
235
|
+
const result = AE.checkAlgorithm(
|
|
236
|
+
currentCondition,
|
|
237
|
+
toCheck,
|
|
238
|
+
this.index,
|
|
239
|
+
this.idxEnd,
|
|
240
|
+
);
|
|
241
|
+
if (typeof result !== "boolean") return result;
|
|
242
|
+
}
|
|
243
|
+
} else {
|
|
244
|
+
return AE.checkAlgorithm(
|
|
245
|
+
this.conditions as { check: (toCheck: any) => boolean | string },
|
|
246
|
+
toCheck,
|
|
247
|
+
this.index,
|
|
248
|
+
this.idxEnd,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Creates this {@link AE } by setting the protected property {@link AE.conditions }, {@link AE.index } and {@link AE.idxEnd } used by {@link AE.check }.
|
|
255
|
+
*
|
|
256
|
+
* @param equivalent See {@link EQ.check }. */
|
|
257
|
+
public constructor(
|
|
258
|
+
protected conditions:
|
|
259
|
+
| Array<{
|
|
260
|
+
check: (toCheck: any) => boolean | string;
|
|
261
|
+
}>
|
|
262
|
+
| { check: (toCheck: any) => boolean | string },
|
|
263
|
+
protected index: number | undefined = undefined,
|
|
264
|
+
protected idxEnd: number | undefined = undefined,
|
|
265
|
+
) {
|
|
266
|
+
super();
|
|
267
|
+
}
|
|
268
|
+
// #endregion Referenced Condition checking.
|
|
269
|
+
}
|