xdbc 1.0.211 → 1.0.213
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 +8 -0
- package/.github/workflows/ci.yml +51 -0
- package/.vscode/tasks.json +23 -23
- package/CODE_OF_CONDUCT.md +1 -1
- package/README.md +1 -0
- package/__tests__/DBC/AE.test.ts +1 -1
- package/__tests__/DBC/DEFINED.test.ts +49 -49
- package/__tests__/DBC/Decorators.test.ts +334 -332
- package/__tests__/DBC/HasAttribute.test.ts +56 -52
- package/__tests__/DBC/IF.test.ts +57 -57
- package/__tests__/DBC/OR.test.ts +1 -1
- package/__tests__/DBC/UNDEFINED.test.ts +41 -41
- package/__tests__/DBC/ZOD.test.ts +50 -50
- package/biome.json +40 -33
- package/dist/DBC/AE.d.ts +117 -0
- package/dist/DBC/COMPARISON/GREATER.d.ts +13 -0
- package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.d.ts +13 -0
- package/dist/DBC/COMPARISON/LESS.d.ts +13 -0
- package/dist/DBC/COMPARISON/LESS_OR_EQUAL.d.ts +13 -0
- package/dist/DBC/COMPARISON.d.ts +70 -0
- package/dist/DBC/DEFINED.d.ts +62 -0
- package/dist/DBC/EQ/DIFFERENT.d.ts +26 -0
- package/dist/DBC/EQ.d.ts +70 -0
- package/dist/DBC/HasAttribute.d.ts +72 -0
- package/dist/DBC/IF.d.ts +90 -0
- package/dist/DBC/INSTANCE.d.ts +84 -0
- package/dist/DBC/JSON.OP.d.ts +94 -0
- package/dist/DBC/JSON.Parse.d.ts +69 -0
- package/dist/DBC/OR.d.ts +104 -0
- package/dist/DBC/REGEX.d.ts +96 -0
- package/dist/DBC/TYPE.d.ts +75 -0
- package/dist/DBC/UNDEFINED.d.ts +62 -0
- package/dist/DBC/ZOD.d.ts +72 -0
- package/dist/DBC.d.ts +244 -0
- package/dist/Demo.d.ts +20 -0
- package/dist/bundle.js +2297 -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 +29 -18
- package/package.json +6 -2
- package/src/DBC/AE.ts +14 -9
- package/src/DBC/COMPARISON/GREATER.ts +2 -2
- package/src/DBC/COMPARISON.ts +159 -136
- package/src/DBC/DEFINED.ts +10 -10
- package/src/DBC/EQ/DIFFERENT.ts +3 -3
- package/src/DBC/EQ.ts +25 -9
- package/src/DBC/HasAttribute.ts +17 -3
- package/src/DBC/IF.ts +63 -19
- package/src/DBC/INSTANCE.ts +29 -14
- package/src/DBC/JSON.OP.ts +18 -3
- package/src/DBC/JSON.Parse.ts +21 -4
- package/src/DBC/OR.ts +12 -7
- package/src/DBC/REGEX.ts +30 -21
- package/src/DBC/TYPE.ts +15 -11
- package/src/DBC/UNDEFINED.ts +7 -10
- package/src/DBC/ZOD.ts +14 -9
- package/src/DBC.ts +165 -69
- package/src/Demo.ts +21 -18
- package/test.drawio +0 -0
- package/tsconfig.json +3 -5
- package/tsconfig.test.json +6 -11
- package/webpack.config.js +1 -1
package/src/DBC/COMPARISON.ts
CHANGED
|
@@ -1,136 +1,159 @@
|
|
|
1
|
-
import { DBC } from "../DBC";
|
|
2
|
-
/**
|
|
3
|
-
* A {@link DBC } defining a comparison between two {@link object }s.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
-
export class COMPARISON extends DBC {
|
|
8
|
-
// #region Condition checking.
|
|
9
|
-
/**
|
|
10
|
-
* Does a comparison between the {@link object } **toCheck** and the **equivalent**.
|
|
11
|
-
*
|
|
12
|
-
* @param toCheck The value that has to be equal to it's possible **equivalent** for this {@link DBC } to be fulfilled.
|
|
13
|
-
* @param equivalent The {@link object } the one **toCheck** has to be equal to in order for this {@link DBC } to be
|
|
14
|
-
* fulfilled.
|
|
15
|
-
*
|
|
16
|
-
* @returns TRUE if the value **toCheck** and the **equivalent** are equal to each other, otherwise FALSE. */
|
|
17
|
-
// biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic comparison
|
|
18
|
-
static checkAlgorithm(
|
|
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
|
-
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining a comparison between two {@link object }s.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class COMPARISON extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Does a comparison between the {@link object } **toCheck** and the **equivalent**.
|
|
11
|
+
*
|
|
12
|
+
* @param toCheck The value that has to be equal to it's possible **equivalent** for this {@link DBC } to be fulfilled.
|
|
13
|
+
* @param equivalent The {@link object } the one **toCheck** has to be equal to in order for this {@link DBC } to be
|
|
14
|
+
* fulfilled.
|
|
15
|
+
*
|
|
16
|
+
* @returns TRUE if the value **toCheck** and the **equivalent** are equal to each other, otherwise FALSE. */
|
|
17
|
+
// biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic comparison
|
|
18
|
+
static checkAlgorithm(
|
|
19
|
+
toCheck: any,
|
|
20
|
+
equivalent: any,
|
|
21
|
+
equalityPermitted: boolean,
|
|
22
|
+
invert: boolean,
|
|
23
|
+
) {
|
|
24
|
+
if (equalityPermitted && !invert && toCheck < equivalent) {
|
|
25
|
+
return `Value has to be greater than or equal to "${equivalent}"`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (equalityPermitted && invert && toCheck > equivalent) {
|
|
29
|
+
return `Value has to be less than or equal to "${equivalent}"`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (!equalityPermitted && !invert && toCheck <= equivalent) {
|
|
33
|
+
return `Value has to be greater than "${equivalent}"`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!equalityPermitted && invert && toCheck >= equivalent) {
|
|
37
|
+
return `Value has to be less than "${equivalent}"`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A parameter-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
44
|
+
* by the tagged parameter.
|
|
45
|
+
*
|
|
46
|
+
* @param equivalent See {@link COMPARISON.checkAlgorithm }.
|
|
47
|
+
* @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
|
|
48
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
49
|
+
* @param hint See {@link DBC.decPrecondition }.
|
|
50
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
51
|
+
*
|
|
52
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
53
|
+
static PRE(
|
|
54
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
55
|
+
equivalent: any,
|
|
56
|
+
equalityPermitted = false,
|
|
57
|
+
invert = false,
|
|
58
|
+
path: string | undefined = undefined,
|
|
59
|
+
hint: string | undefined = undefined,
|
|
60
|
+
dbc: string | undefined = undefined,
|
|
61
|
+
) {
|
|
62
|
+
return DBC.createPRE(
|
|
63
|
+
COMPARISON.checkAlgorithm,
|
|
64
|
+
[equivalent, equalityPermitted, invert],
|
|
65
|
+
dbc,
|
|
66
|
+
path,
|
|
67
|
+
hint,
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A method-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
72
|
+
* by the tagged method's returnvalue.
|
|
73
|
+
*
|
|
74
|
+
* @param equivalent See {@link COMPARISON.checkAlgorithm }.
|
|
75
|
+
* @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
|
|
76
|
+
* @param path See {@link DBC.Postcondition }.
|
|
77
|
+
* @param hint See {@link DBC.decPostcondition }.
|
|
78
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
79
|
+
*
|
|
80
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
81
|
+
static POST(
|
|
82
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
83
|
+
equivalent: any,
|
|
84
|
+
equalityPermitted = false,
|
|
85
|
+
invert = false,
|
|
86
|
+
path: string | undefined = undefined,
|
|
87
|
+
hint: string | undefined = undefined,
|
|
88
|
+
dbc: string | undefined = undefined,
|
|
89
|
+
) {
|
|
90
|
+
return DBC.createPOST(
|
|
91
|
+
COMPARISON.checkAlgorithm,
|
|
92
|
+
[equivalent, equalityPermitted, invert],
|
|
93
|
+
dbc,
|
|
94
|
+
path,
|
|
95
|
+
hint,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* A field-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
100
|
+
* by the tagged field.
|
|
101
|
+
*
|
|
102
|
+
* @param equivalent See {@link COMPARISON.checkAlgorithm }.
|
|
103
|
+
* @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
|
|
104
|
+
* @param path See {@link DBC.decInvariant }.
|
|
105
|
+
* @param hint See {@link DBC.decInvariant }.
|
|
106
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
107
|
+
*
|
|
108
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
109
|
+
static INVARIANT(
|
|
110
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
111
|
+
equivalent: any,
|
|
112
|
+
equalityPermitted = false,
|
|
113
|
+
invert = false,
|
|
114
|
+
path: string | undefined = undefined,
|
|
115
|
+
hint: string | undefined = undefined,
|
|
116
|
+
dbc: string | undefined = undefined,
|
|
117
|
+
) {
|
|
118
|
+
return DBC.createINVARIANT(
|
|
119
|
+
COMPARISON,
|
|
120
|
+
[equivalent, equalityPermitted, invert],
|
|
121
|
+
dbc,
|
|
122
|
+
path,
|
|
123
|
+
hint,
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
// #endregion Condition checking.
|
|
127
|
+
// #region Referenced Condition checking.
|
|
128
|
+
// #region Dynamic usage.
|
|
129
|
+
/**
|
|
130
|
+
* Invokes the {@link COMPARISON.checkAlgorithm } passing the value **toCheck**, {@link COMPARISON.equivalent } and {@link COMPARISON.invert }.
|
|
131
|
+
*
|
|
132
|
+
* @param toCheck See {@link COMPARISON.checkAlgorithm }.
|
|
133
|
+
*
|
|
134
|
+
* @returns See {@link COMPARISON.checkAlgorithm}. */
|
|
135
|
+
// biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic comparison
|
|
136
|
+
public check(toCheck: any) {
|
|
137
|
+
return COMPARISON.checkAlgorithm(
|
|
138
|
+
toCheck,
|
|
139
|
+
this.equivalent,
|
|
140
|
+
this.equalityPermitted,
|
|
141
|
+
this.invert,
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Creates this {@link COMPARISON } by setting the protected property {@link COMPARISON.equivalent }, {@link COMPARISON.equalityPermitted } and {@link COMPARISON.invert } used by {@link COMPARISON.check }.
|
|
146
|
+
*
|
|
147
|
+
* @param equivalent See {@link COMPARISON.check }.
|
|
148
|
+
* @param equalityPermitted See {@link COMPARISON.check }.
|
|
149
|
+
* @param invert See {@link COMPARISON.check }. */
|
|
150
|
+
constructor(
|
|
151
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
152
|
+
public equivalent: any,
|
|
153
|
+
public equalityPermitted = false,
|
|
154
|
+
public invert = false,
|
|
155
|
+
) {
|
|
156
|
+
super();
|
|
157
|
+
}
|
|
158
|
+
// #endregion Dynamic usage.
|
|
159
|
+
}
|
package/src/DBC/DEFINED.ts
CHANGED
|
@@ -98,22 +98,22 @@ export class DEFINED extends DBC {
|
|
|
98
98
|
*
|
|
99
99
|
* @param toCheck See {@link DEFINED.checkAlgorithm }.
|
|
100
100
|
* @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
|
|
101
|
-
*
|
|
101
|
+
*
|
|
102
102
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link DEFINED }.
|
|
103
|
-
*
|
|
103
|
+
*
|
|
104
104
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }.*/
|
|
105
|
-
public static tsCheck<CANDIDATE = unknown>(
|
|
105
|
+
public static tsCheck<CANDIDATE = unknown>(
|
|
106
|
+
toCheck: CANDIDATE | undefined | null,
|
|
107
|
+
hint: string | undefined = undefined,
|
|
108
|
+
id: string | undefined = undefined,
|
|
109
|
+
): CANDIDATE {
|
|
106
110
|
const result = DEFINED.checkAlgorithm(toCheck);
|
|
107
111
|
|
|
108
112
|
if (result === true) {
|
|
109
113
|
return toCheck as CANDIDATE;
|
|
110
114
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
/** Creates this {@link DEFINED }. */
|
|
116
|
-
public constructor() {
|
|
117
|
-
super();
|
|
115
|
+
throw new DBC.Infringement(
|
|
116
|
+
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
117
|
+
);
|
|
118
118
|
}
|
|
119
119
|
}
|
package/src/DBC/EQ/DIFFERENT.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { EQ } from "../EQ";
|
|
2
2
|
/**
|
|
3
3
|
* DIFFERENT class for inequality comparisons.
|
|
4
|
-
*
|
|
4
|
+
*
|
|
5
5
|
* This class extends EQ and provides methods to check if a value is different (not equal)
|
|
6
6
|
* from a specified equivalent value. It inverts the equality check by always passing
|
|
7
7
|
* `true` for the invert parameter to the parent EQ class methods.
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* @remarks
|
|
10
10
|
* The class provides precondition (PRE), postcondition (POST), and invariant (INVARIANT)
|
|
11
11
|
* checks for Design by Contract programming patterns.
|
|
12
|
-
*
|
|
12
|
+
*
|
|
13
13
|
* @see {@link COMPARISON}
|
|
14
14
|
* @see {@link EQ}
|
|
15
15
|
*/
|
package/src/DBC/EQ.ts
CHANGED
|
@@ -45,13 +45,19 @@ export class EQ extends DBC {
|
|
|
45
45
|
invert = false,
|
|
46
46
|
path: string | undefined = undefined,
|
|
47
47
|
hint: string | undefined = undefined,
|
|
48
|
-
dbc: string | undefined = undefined
|
|
48
|
+
dbc: string | undefined = undefined,
|
|
49
49
|
): (
|
|
50
50
|
target: object,
|
|
51
51
|
methodName: string | symbol,
|
|
52
52
|
parameterIndex: number,
|
|
53
53
|
) => void {
|
|
54
|
-
return DBC.createPRE(
|
|
54
|
+
return DBC.createPRE(
|
|
55
|
+
EQ.checkAlgorithm,
|
|
56
|
+
[equivalent, invert],
|
|
57
|
+
dbc,
|
|
58
|
+
path,
|
|
59
|
+
hint,
|
|
60
|
+
);
|
|
55
61
|
}
|
|
56
62
|
/**
|
|
57
63
|
* A method-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -69,13 +75,18 @@ export class EQ extends DBC {
|
|
|
69
75
|
path: string | undefined = undefined,
|
|
70
76
|
hint: string | undefined = undefined,
|
|
71
77
|
dbc: string | undefined = undefined,
|
|
72
|
-
|
|
73
78
|
): (
|
|
74
79
|
target: object,
|
|
75
80
|
propertyKey: string,
|
|
76
81
|
descriptor: PropertyDescriptor,
|
|
77
82
|
) => PropertyDescriptor {
|
|
78
|
-
return DBC.createPOST(
|
|
83
|
+
return DBC.createPOST(
|
|
84
|
+
EQ.checkAlgorithm,
|
|
85
|
+
[equivalent, invert],
|
|
86
|
+
dbc,
|
|
87
|
+
path,
|
|
88
|
+
hint,
|
|
89
|
+
);
|
|
79
90
|
}
|
|
80
91
|
/**
|
|
81
92
|
* A field-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -117,17 +128,22 @@ export class EQ extends DBC {
|
|
|
117
128
|
* @param toCheck See {@link EQ.checkAlgorithm }.
|
|
118
129
|
*
|
|
119
130
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link EQ }.
|
|
120
|
-
*
|
|
131
|
+
*
|
|
121
132
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link EQ }.*/
|
|
122
|
-
public static tsCheck<CANDIDATE>(
|
|
133
|
+
public static tsCheck<CANDIDATE>(
|
|
134
|
+
toCheck: CANDIDATE | undefined | null,
|
|
135
|
+
equivalent: any,
|
|
136
|
+
hint: string | undefined = undefined,
|
|
137
|
+
id: string | undefined = undefined,
|
|
138
|
+
): CANDIDATE {
|
|
123
139
|
const result = EQ.checkAlgorithm(toCheck, equivalent, false);
|
|
124
140
|
|
|
125
141
|
if (result) {
|
|
126
142
|
return toCheck as CANDIDATE;
|
|
127
143
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
144
|
+
throw new DBC.Infringement(
|
|
145
|
+
`${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
|
|
146
|
+
);
|
|
131
147
|
}
|
|
132
148
|
/**
|
|
133
149
|
* Creates this {@link EQ } by setting the protected property {@link EQ.equivalent } used by {@link EQ.check }.
|
package/src/DBC/HasAttribute.ts
CHANGED
|
@@ -52,7 +52,12 @@ export class HasAttribute extends DBC {
|
|
|
52
52
|
methodName: string | symbol,
|
|
53
53
|
parameterIndex: number,
|
|
54
54
|
) => void {
|
|
55
|
-
return DBC.createPRE(
|
|
55
|
+
return DBC.createPRE(
|
|
56
|
+
HasAttribute.checkAlgorithm,
|
|
57
|
+
[toCheckFor, invert],
|
|
58
|
+
dbc,
|
|
59
|
+
path,
|
|
60
|
+
);
|
|
56
61
|
}
|
|
57
62
|
/**
|
|
58
63
|
* A method-decorator factory using the {@link HasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
|
|
@@ -73,7 +78,12 @@ export class HasAttribute extends DBC {
|
|
|
73
78
|
propertyKey: string,
|
|
74
79
|
descriptor: PropertyDescriptor,
|
|
75
80
|
) => PropertyDescriptor {
|
|
76
|
-
return DBC.createPOST(
|
|
81
|
+
return DBC.createPOST(
|
|
82
|
+
HasAttribute.checkAlgorithm,
|
|
83
|
+
[toCheckFor, invert],
|
|
84
|
+
dbc,
|
|
85
|
+
path,
|
|
86
|
+
);
|
|
77
87
|
}
|
|
78
88
|
/**
|
|
79
89
|
* A field-decorator factory using the {@link hasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
|
|
@@ -107,7 +117,11 @@ export class HasAttribute extends DBC {
|
|
|
107
117
|
path: string | undefined = undefined,
|
|
108
118
|
dbc = "WaXCode.DBC",
|
|
109
119
|
) {
|
|
110
|
-
return DBC.decClassInvariant(
|
|
120
|
+
return DBC.decClassInvariant(
|
|
121
|
+
[new HasAttribute(toCheckFor, invert)],
|
|
122
|
+
path,
|
|
123
|
+
dbc,
|
|
124
|
+
);
|
|
111
125
|
}
|
|
112
126
|
// #endregion Condition checking.
|
|
113
127
|
// #region Referenced Condition checking.
|
package/src/DBC/IF.ts
CHANGED
|
@@ -18,20 +18,30 @@ export class IF extends DBC {
|
|
|
18
18
|
public static checkAlgorithm(
|
|
19
19
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
20
20
|
toCheck: any,
|
|
21
|
-
condition: {
|
|
21
|
+
condition: {
|
|
22
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
23
|
+
},
|
|
22
24
|
inCase: {
|
|
23
25
|
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
24
26
|
},
|
|
25
|
-
invert
|
|
27
|
+
invert = false,
|
|
26
28
|
): boolean | string {
|
|
27
29
|
if (toCheck === undefined || toCheck === null) return true;
|
|
28
30
|
|
|
29
|
-
if (
|
|
30
|
-
|
|
31
|
+
if (
|
|
32
|
+
invert &&
|
|
33
|
+
condition.check(toCheck) !== true &&
|
|
34
|
+
inCase.check(toCheck) !== true
|
|
35
|
+
) {
|
|
36
|
+
return "In case that the value does not comply to the condition, it also has to comply to the required contract";
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
if (
|
|
34
|
-
|
|
39
|
+
if (
|
|
40
|
+
!invert &&
|
|
41
|
+
condition.check(toCheck) === true &&
|
|
42
|
+
inCase.check(toCheck) !== true
|
|
43
|
+
) {
|
|
44
|
+
return "In case that the value complies to the condition, it has to comply to the required contract";
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
return true;
|
|
@@ -47,18 +57,28 @@ export class IF extends DBC {
|
|
|
47
57
|
*
|
|
48
58
|
* @returns See {@link DBC.decPrecondition }. */
|
|
49
59
|
public static PRE(
|
|
50
|
-
condition: {
|
|
51
|
-
|
|
60
|
+
condition: {
|
|
61
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
62
|
+
},
|
|
63
|
+
inCase: {
|
|
64
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
65
|
+
},
|
|
52
66
|
path: string | undefined = undefined,
|
|
53
67
|
invert = false,
|
|
54
68
|
hint: string | undefined = undefined,
|
|
55
|
-
dbc: string | undefined = undefined
|
|
69
|
+
dbc: string | undefined = undefined,
|
|
56
70
|
): (
|
|
57
71
|
target: object,
|
|
58
72
|
methodName: string | symbol,
|
|
59
73
|
parameterIndex: number,
|
|
60
74
|
) => void {
|
|
61
|
-
return DBC.createPRE(
|
|
75
|
+
return DBC.createPRE(
|
|
76
|
+
IF.checkAlgorithm,
|
|
77
|
+
[condition, inCase, invert],
|
|
78
|
+
dbc,
|
|
79
|
+
path,
|
|
80
|
+
hint,
|
|
81
|
+
);
|
|
62
82
|
}
|
|
63
83
|
/**
|
|
64
84
|
* A method-decorator factory using the {@link IF.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -71,8 +91,12 @@ export class IF extends DBC {
|
|
|
71
91
|
*
|
|
72
92
|
* @returns See {@link DBC.decPostcondition }. */
|
|
73
93
|
public static POST(
|
|
74
|
-
condition: {
|
|
75
|
-
|
|
94
|
+
condition: {
|
|
95
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
96
|
+
},
|
|
97
|
+
inCase: {
|
|
98
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
99
|
+
},
|
|
76
100
|
path: string | undefined = undefined,
|
|
77
101
|
invert = false,
|
|
78
102
|
hint: string | undefined = undefined,
|
|
@@ -82,7 +106,13 @@ export class IF extends DBC {
|
|
|
82
106
|
propertyKey: string,
|
|
83
107
|
descriptor: PropertyDescriptor,
|
|
84
108
|
) => PropertyDescriptor {
|
|
85
|
-
return DBC.createPOST(
|
|
109
|
+
return DBC.createPOST(
|
|
110
|
+
IF.checkAlgorithm,
|
|
111
|
+
[condition, inCase, invert],
|
|
112
|
+
dbc,
|
|
113
|
+
path,
|
|
114
|
+
hint,
|
|
115
|
+
);
|
|
86
116
|
}
|
|
87
117
|
/**
|
|
88
118
|
* A field-decorator factory using the {@link IF.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -95,14 +125,24 @@ export class IF extends DBC {
|
|
|
95
125
|
*
|
|
96
126
|
* @returns See {@link DBC.decInvariant }. */
|
|
97
127
|
public static INVARIANT(
|
|
98
|
-
condition: {
|
|
99
|
-
|
|
128
|
+
condition: {
|
|
129
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
130
|
+
},
|
|
131
|
+
inCase: {
|
|
132
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
133
|
+
},
|
|
100
134
|
path: string | undefined = undefined,
|
|
101
135
|
invert = false,
|
|
102
136
|
hint: string | undefined = undefined,
|
|
103
137
|
dbc: string | undefined = undefined,
|
|
104
138
|
) {
|
|
105
|
-
return DBC.createINVARIANT(
|
|
139
|
+
return DBC.createINVARIANT(
|
|
140
|
+
IF,
|
|
141
|
+
[condition, inCase, invert],
|
|
142
|
+
dbc,
|
|
143
|
+
path,
|
|
144
|
+
hint,
|
|
145
|
+
);
|
|
106
146
|
}
|
|
107
147
|
// #endregion Condition checking.
|
|
108
148
|
// #region Referenced Condition checking.
|
|
@@ -125,11 +165,15 @@ export class IF extends DBC {
|
|
|
125
165
|
* @param equivalent See {@link IF.check }. */
|
|
126
166
|
public constructor(
|
|
127
167
|
// biome-ignore lint/suspicious/noExplicitAny: To be able to match UNDEFINED and NULL.
|
|
128
|
-
protected condition: {
|
|
129
|
-
|
|
168
|
+
protected condition: {
|
|
169
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
170
|
+
},
|
|
171
|
+
protected inCase: {
|
|
172
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
173
|
+
},
|
|
130
174
|
protected invert = false,
|
|
131
175
|
) {
|
|
132
176
|
super();
|
|
133
177
|
}
|
|
134
178
|
// #endregion Referenced Condition checking.
|
|
135
|
-
}
|
|
179
|
+
}
|