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
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that a {@link HTMLElement } gotta have a certain attribute set.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class HasAttribute extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the {@link HTMLElement } **toCheck** has the attribute **toCheckFor**.
|
|
11
|
+
*
|
|
12
|
+
* @param toCheckFor name of the attribute to check for whether it is set or not.
|
|
13
|
+
*
|
|
14
|
+
* @returns TRUE if the {@link HTMLElement } **toCheck** has set the attribute **toCheckFor**,
|
|
15
|
+
* otherwise a proper errormessage. */
|
|
16
|
+
static checkAlgorithm(toCheck, toCheckFor, invert) {
|
|
17
|
+
if (!(toCheck instanceof HTMLElement)) {
|
|
18
|
+
return `The object to check for whether it has the attribute "${toCheckFor}" is not a HTMLElement. It is of type "${typeof toCheck}".`;
|
|
19
|
+
}
|
|
20
|
+
if (!invert && !toCheck.hasAttribute(toCheckFor)) {
|
|
21
|
+
return `Required Attribute "${toCheckFor}" is not set.`;
|
|
22
|
+
}
|
|
23
|
+
if (invert && toCheck.hasAttribute(toCheckFor)) {
|
|
24
|
+
return `Forbidden Attribute "${toCheckFor}" is set.`;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A parameter-decorator factory using the {@link HasAttribute.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
30
|
+
* by the tagged parameter.
|
|
31
|
+
*
|
|
32
|
+
* @param toCheckFor See {@link HasAttribute.checkAlgorithm }.
|
|
33
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
34
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
35
|
+
*
|
|
36
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
37
|
+
static PRE(toCheckFor, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
38
|
+
return DBC.createPRE(HasAttribute.checkAlgorithm, [toCheckFor, invert], dbc, path);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A method-decorator factory using the {@link HasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
|
|
42
|
+
* fulfilled by the tagged method's returnvalue.
|
|
43
|
+
*
|
|
44
|
+
* @param toCheckFor See {@link HasAttribute.checkAlgorithm }.
|
|
45
|
+
* @param path See {@link DBC.Postcondition }.
|
|
46
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
47
|
+
*
|
|
48
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
49
|
+
static POST(toCheckFor, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
50
|
+
return DBC.createPOST(HasAttribute.checkAlgorithm, [toCheckFor, invert], dbc, path);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A field-decorator factory using the {@link hasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
|
|
54
|
+
* fulfilled by the tagged field.
|
|
55
|
+
*
|
|
56
|
+
* @param toCheckFor See {@link hasAttribute.checkAlgorithm }.
|
|
57
|
+
* @param path See {@link DBC.decInvariant }.
|
|
58
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
59
|
+
*
|
|
60
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
61
|
+
static INVARIANT(toCheckFor, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
62
|
+
return DBC.createINVARIANT(HasAttribute, [toCheckFor, invert], dbc, path);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A field-decorator factory using the {@link hasAttribute.checkAlgorithm } to determine whether this {@link DBC } is
|
|
66
|
+
* fulfilled by the tagged field's class instance.
|
|
67
|
+
*
|
|
68
|
+
* @param toCheckFor See {@link hasAttribute.checkAlgorithm }.
|
|
69
|
+
* @param path See {@link DBC.decInvariant }.
|
|
70
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
71
|
+
*
|
|
72
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
73
|
+
static cINVARIANT(toCheckFor, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
74
|
+
return DBC.decClassInvariant([new HasAttribute(toCheckFor, invert)], path, dbc);
|
|
75
|
+
}
|
|
76
|
+
// #endregion Condition checking.
|
|
77
|
+
// #region Referenced Condition checking.
|
|
78
|
+
//
|
|
79
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
80
|
+
//
|
|
81
|
+
/**
|
|
82
|
+
* Invokes the {@link hasAttribute.checkAlgorithm } passing the value **toCheck**, {@link hasAttribute.equivalent } and
|
|
83
|
+
* {@link hasAttribute.invert }.
|
|
84
|
+
*
|
|
85
|
+
* @param toCheck See {@link EQ.checkAlgorithm }.
|
|
86
|
+
*
|
|
87
|
+
* @returns See {@link EQ.checkAlgorithm}. */
|
|
88
|
+
check(toCheck) {
|
|
89
|
+
return HasAttribute.checkAlgorithm(toCheck, this.toCheckFor, this.invert);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Creates this {@link DBC } by setting the protected property {@link hasAttribute.equivalent } used by
|
|
93
|
+
* {@link hasAttribute.check }.
|
|
94
|
+
*
|
|
95
|
+
* @param toCheckFor See {@link hasAttribute.check }. */
|
|
96
|
+
constructor(toCheckFor, invert = false) {
|
|
97
|
+
super();
|
|
98
|
+
this.toCheckFor = toCheckFor;
|
|
99
|
+
this.invert = invert;
|
|
100
|
+
}
|
|
101
|
+
}
|
package/dist/DBC/IF.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that an {@link object } has also to comply to a certain {@link DBC } if it complies to
|
|
4
|
+
* another specified one.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
8
|
+
export class IF extends DBC {
|
|
9
|
+
// #region Condition checking.
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the value **toCheck** complies to the specified **condition** and if so does also comply to the one **inCase**.
|
|
12
|
+
*
|
|
13
|
+
* @param toCheck The value that has to be equal to it's possible **equivalent** for this {@link DBC } to be fulfilled.
|
|
14
|
+
* @param condition The contract **toCheck** has to comply to in order to also have to comply to the one **inCase**.
|
|
15
|
+
* @param inCase The contract **toCheck** has to also comply to if it complies to **condition**.
|
|
16
|
+
*
|
|
17
|
+
* @returns TRUE if the value **toCheck** and the **equivalent** are equal to each other, otherwise FALSE. */
|
|
18
|
+
static checkAlgorithm(toCheck, condition, inCase, invert = false) {
|
|
19
|
+
if (toCheck === undefined || toCheck === null)
|
|
20
|
+
return true;
|
|
21
|
+
if (invert &&
|
|
22
|
+
condition.check(toCheck) !== true &&
|
|
23
|
+
inCase.check(toCheck) !== true) {
|
|
24
|
+
return "In case that the value does not comply to the condition, it also has to comply to the required contract";
|
|
25
|
+
}
|
|
26
|
+
if (!invert &&
|
|
27
|
+
condition.check(toCheck) === true &&
|
|
28
|
+
inCase.check(toCheck) !== true) {
|
|
29
|
+
return "In case that the value complies to the condition, it has to comply to the required contract";
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A parameter-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
35
|
+
* by the tagged parameter.
|
|
36
|
+
*
|
|
37
|
+
* @param condition See {@link IF.checkAlgorithm }.
|
|
38
|
+
* @param inCase See {@link IF.checkAlgorithm }.
|
|
39
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
40
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
41
|
+
*
|
|
42
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
43
|
+
static PRE(condition, inCase, path = undefined, invert = false, hint = undefined, dbc = undefined) {
|
|
44
|
+
return DBC.createPRE(IF.checkAlgorithm, [condition, inCase, invert], dbc, path, hint);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A method-decorator factory using the {@link IF.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
48
|
+
* by the tagged method's returnvalue.
|
|
49
|
+
*
|
|
50
|
+
* @param condition See {@link IF.checkAlgorithm }.
|
|
51
|
+
* @param inCase See {@link IF.checkAlgorithm }.
|
|
52
|
+
* @param path See {@link DBC.Postcondition }.
|
|
53
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
54
|
+
*
|
|
55
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
56
|
+
static POST(condition, inCase, path = undefined, invert = false, hint = undefined, dbc = undefined) {
|
|
57
|
+
return DBC.createPOST(IF.checkAlgorithm, [condition, inCase, invert], dbc, path, hint);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A field-decorator factory using the {@link IF.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
61
|
+
* by the tagged field.
|
|
62
|
+
*
|
|
63
|
+
* @param condition See {@link IF.checkAlgorithm }.
|
|
64
|
+
* @param inCase See {@link IF.checkAlgorithm }.
|
|
65
|
+
* @param path See {@link DBC.decInvariant }.
|
|
66
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
67
|
+
*
|
|
68
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
69
|
+
static INVARIANT(condition, inCase, path = undefined, invert = false, hint = undefined, dbc = undefined) {
|
|
70
|
+
return DBC.createINVARIANT(IF, [condition, inCase, invert], dbc, path, hint);
|
|
71
|
+
}
|
|
72
|
+
// #endregion Condition checking.
|
|
73
|
+
// #region Referenced Condition checking.
|
|
74
|
+
//
|
|
75
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
76
|
+
//
|
|
77
|
+
/**
|
|
78
|
+
* Invokes the {@link IF.checkAlgorithm } passing the value **toCheck**, {@link IF.equivalent } and {@link IF.invert }.
|
|
79
|
+
*
|
|
80
|
+
* @param toCheck See {@link IF.checkAlgorithm }.
|
|
81
|
+
*
|
|
82
|
+
* @returns See {@link IF.checkAlgorithm}. */
|
|
83
|
+
check(toCheck) {
|
|
84
|
+
return IF.checkAlgorithm(toCheck, this.condition, this.inCase, this.invert);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates this {@link IF } by setting the protected property {@link IF.equivalent } used by {@link IF.check }.
|
|
88
|
+
*
|
|
89
|
+
* @param equivalent See {@link IF.check }. */
|
|
90
|
+
constructor(condition, inCase, invert = false) {
|
|
91
|
+
super();
|
|
92
|
+
this.condition = condition;
|
|
93
|
+
this.inCase = inCase;
|
|
94
|
+
this.invert = invert;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link INSTANCE.reference }.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
|
|
7
|
+
export class INSTANCE extends DBC {
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the value **toCheck** is an instance of the specified **reference**.
|
|
10
|
+
*
|
|
11
|
+
* @param toCheck The value that has to be an instance of the **reference** in order for this {@link DBC }
|
|
12
|
+
* to be fulfilled.
|
|
13
|
+
* @param reference The {@link object } the one **toCheck** has to be an instance of.
|
|
14
|
+
*
|
|
15
|
+
* @returns TRUE if the value **toCheck** is is an instance of the *reference**, **undefined** or **null**, otherwise FALSE. */
|
|
16
|
+
static checkAlgorithm(toCheck, ...references) {
|
|
17
|
+
if (toCheck === null || toCheck === undefined) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
for (const ref of references) {
|
|
21
|
+
if (toCheck instanceof ref) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return `Value has to be an instance of "${references.map((ref) => ref.name || ref).join(", ")}" but is of type "${typeof toCheck}"`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A parameter-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
29
|
+
* by the tagged parameter.
|
|
30
|
+
*
|
|
31
|
+
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
32
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
33
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
34
|
+
*
|
|
35
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
36
|
+
static PRE(reference, path = undefined, hint = undefined, dbc = undefined) {
|
|
37
|
+
const refs = Array.isArray(reference) ? reference : [reference];
|
|
38
|
+
return DBC.createPRE(INSTANCE.checkAlgorithm, refs, dbc, path, hint);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A method-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
42
|
+
* by the tagged method's returnvalue.
|
|
43
|
+
*
|
|
44
|
+
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
45
|
+
* @param path See {@link DBC.Postcondition }.
|
|
46
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
47
|
+
*
|
|
48
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
49
|
+
static POST(reference, path = undefined, hint = undefined, dbc = undefined) {
|
|
50
|
+
const refs = Array.isArray(reference) ? reference : [reference];
|
|
51
|
+
return DBC.createPOST(INSTANCE.checkAlgorithm, refs, dbc, path, hint);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A field-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
55
|
+
* by the tagged method's returnvalue.
|
|
56
|
+
*
|
|
57
|
+
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
58
|
+
* @param path See {@link DBC.decInvariant }.
|
|
59
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
60
|
+
*
|
|
61
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
62
|
+
static INVARIANT(reference, path = undefined, hint = undefined, dbc = undefined) {
|
|
63
|
+
return DBC.createINVARIANT(INSTANCE, [reference], dbc, path, hint);
|
|
64
|
+
}
|
|
65
|
+
// #endregion Condition checking.
|
|
66
|
+
// #region Referenced Condition checking.
|
|
67
|
+
//
|
|
68
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
69
|
+
//
|
|
70
|
+
/**
|
|
71
|
+
* Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
|
|
72
|
+
*
|
|
73
|
+
* @param toCheck See {@link INSTANCE.checkAlgorithm }.
|
|
74
|
+
*
|
|
75
|
+
* @returns See {@link INSTANCE.checkAlgorithm}. */
|
|
76
|
+
check(toCheck) {
|
|
77
|
+
return Array.isArray(this.reference)
|
|
78
|
+
? INSTANCE.checkAlgorithm(toCheck, ...this.reference)
|
|
79
|
+
: INSTANCE.checkAlgorithm(toCheck, this.reference);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Type-safe check that validates if a value is an instance of a specified reference.
|
|
83
|
+
*
|
|
84
|
+
* @param toCheck The value to check for instance validity.
|
|
85
|
+
* @param reference The {@link object } the one **toCheck** has to be an instance of.
|
|
86
|
+
* @param hint An optional {@link string } providing extra information in case of an infringement.
|
|
87
|
+
* @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
|
|
88
|
+
*
|
|
89
|
+
* @returns The **CANDIDATE** **toCheck** if it fulfills this {@link INSTANCE }.
|
|
90
|
+
*
|
|
91
|
+
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link INSTANCE }. */
|
|
92
|
+
static tsCheck(toCheck, reference, hint = undefined, id = undefined, dbc = undefined) {
|
|
93
|
+
return INSTANCE.tsCheckMulti(toCheck, [reference], hint, id, dbc);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
|
|
97
|
+
*
|
|
98
|
+
* @param toCheck See {@link INSTANCE.checkAlgorithm }.
|
|
99
|
+
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
100
|
+
* @param hint An optional {@link string } providing extra information in case of an infringement.
|
|
101
|
+
* @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
|
|
102
|
+
*
|
|
103
|
+
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link INSTANCE }.
|
|
104
|
+
*
|
|
105
|
+
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
|
|
106
|
+
static tsCheckMulti(toCheck, references, hint = undefined, id = undefined, dbc = undefined) {
|
|
107
|
+
const result = INSTANCE.checkAlgorithm(toCheck, ...references);
|
|
108
|
+
if (result === true) {
|
|
109
|
+
return toCheck;
|
|
110
|
+
}
|
|
111
|
+
DBC.reportTsCheckInfringement(`${id ? `(${id}) ` : ""}${result} ${hint ? `✨ ${hint} ✨` : ""}`, dbc);
|
|
112
|
+
return toCheck;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Creates this {@link INSTANCE } by setting the protected property {@link INSTANCE.reference } used by {@link INSTANCE.check }.
|
|
116
|
+
*
|
|
117
|
+
* @param reference See {@link INSTANCE.check }. */
|
|
118
|
+
constructor(reference) {
|
|
119
|
+
super();
|
|
120
|
+
this.reference = reference;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } demanding that an {@link object } has specific properties of specific types.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class JSON_OP extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the object **toCheck** has the **necessaryProperties** of necessary type.
|
|
11
|
+
*
|
|
12
|
+
* @param toCheck The {@link object } to check for the necessary properties.
|
|
13
|
+
* @param necessaryProperties The **{ name : string, type : string }**s defining the properties and type the {@link object } to
|
|
14
|
+
* check needs to have.
|
|
15
|
+
* @param checkElements Indicates if **toCheck** is an iterable object of which all elements have to be checked.
|
|
16
|
+
* Elements will only be checked if **toCheck** is iterable, otherwise **toCheck** itself
|
|
17
|
+
* will be checked.
|
|
18
|
+
*
|
|
19
|
+
* @returns TRUE if the value **toCheck** or it's elements, if **checkElements** is TRUE, has all **necessaryProperties**, otherwise a {@link string } to report the infringement. */
|
|
20
|
+
static checkAlgorithm(toCheck, necessaryProperties, checkElements) {
|
|
21
|
+
if (toCheck === undefined || toCheck === null) {
|
|
22
|
+
return `[ UNDEFINED or NULL received instead of object with following properties: ${JSON.stringify(necessaryProperties)} ]`;
|
|
23
|
+
}
|
|
24
|
+
for (const property of necessaryProperties)
|
|
25
|
+
if (checkElements && typeof toCheck[Symbol.iterator] === "function") {
|
|
26
|
+
for (const element of toCheck) {
|
|
27
|
+
if (
|
|
28
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation>
|
|
29
|
+
!element.hasOwnProperty(property.name) ||
|
|
30
|
+
typeof element[property.name] !== property.type) {
|
|
31
|
+
return `[ Object "${JSON.stringify(element)}" in Array "${JSON.stringify(toCheck)}" does not contain the necessary property "${property.name}" of type "${property.type}"]`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
if (
|
|
37
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation>
|
|
38
|
+
!toCheck.hasOwnProperty(property.name) ||
|
|
39
|
+
typeof toCheck[property.name] !== property.type) {
|
|
40
|
+
return `[ Object does not contain the necessary property "${property.name}" of type "${property.type}"]`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A parameter-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
47
|
+
* by the tagged parameter.
|
|
48
|
+
*
|
|
49
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
50
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
51
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
52
|
+
*
|
|
53
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
54
|
+
static PRE(necessaryProperties, checkElements = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
55
|
+
return DBC.createPRE(JSON_OP.checkAlgorithm, [necessaryProperties, checkElements], dbc, path);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A method-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
59
|
+
* by the tagged method's returnvalue.
|
|
60
|
+
*
|
|
61
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
62
|
+
* @param path See {@link DBC.Postcondition }.
|
|
63
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
64
|
+
*
|
|
65
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
66
|
+
static POST(necessaryProperties, checkElements = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
67
|
+
return DBC.createPOST(JSON_OP.checkAlgorithm, [necessaryProperties, checkElements], dbc, path);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* A field-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
71
|
+
* by the tagged field.
|
|
72
|
+
*
|
|
73
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
74
|
+
* @param path See {@link DBC.decInvariant }.
|
|
75
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
76
|
+
*
|
|
77
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
78
|
+
static INVARIANT(necessaryProperties, checkElements = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
79
|
+
return DBC.createINVARIANT(JSON_OP, [necessaryProperties, checkElements], dbc, path);
|
|
80
|
+
}
|
|
81
|
+
// #endregion Condition checking.
|
|
82
|
+
// #region Referenced Condition checking.
|
|
83
|
+
//
|
|
84
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
85
|
+
//
|
|
86
|
+
/**
|
|
87
|
+
* Invokes the {@link JSON_OP.checkAlgorithm } passing the value **toCheck**, {@link JSON_OP.necessaryProperties } and {@link JSON_OP.checkElements }.
|
|
88
|
+
*
|
|
89
|
+
* @param toCheck See {@link JSON_OP.checkAlgorithm }.
|
|
90
|
+
*
|
|
91
|
+
* @returns See {@link JSON_OP.checkAlgorithm}. */
|
|
92
|
+
check(toCheck) {
|
|
93
|
+
return JSON_OP.checkAlgorithm(toCheck, this.necessaryProperties, this.checkElements);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Creates this {@link JSON_OP } by setting the protected property {@link JSON_OP.necessaryProperties } and {@link checkElements } used by {@link JSON_OP.check }.
|
|
97
|
+
*
|
|
98
|
+
* @param necessaryProperties See {@link JSON_OP.check }.
|
|
99
|
+
* @param checkElements See {@link JSON_OP.check }. */
|
|
100
|
+
constructor(necessaryProperties, checkElements = false) {
|
|
101
|
+
super();
|
|
102
|
+
this.necessaryProperties = necessaryProperties;
|
|
103
|
+
this.checkElements = checkElements;
|
|
104
|
+
}
|
|
105
|
+
// #endregion Referenced Condition checking.
|
|
106
|
+
// #region In-Method checking.
|
|
107
|
+
/**
|
|
108
|
+
* Invokes the {@link JSON_OP.checkAlgorithm } passing the value **toCheck**, {@link JSON_OP.necessaryProperties } and {@link JSON_OP.checkElements }.
|
|
109
|
+
*
|
|
110
|
+
* @param toCheck See {@link JSON_OP.checkAlgorithm} }.
|
|
111
|
+
* @param necessaryProperties See {@link JSON_OP.checkAlgorithm} }.
|
|
112
|
+
* @param checkElements See {@link JSON_OP.checkAlgorithm} }.
|
|
113
|
+
*/
|
|
114
|
+
static check(toCheck, necessaryProperties, checkElements = false, dbc = undefined) {
|
|
115
|
+
const checkResult = JSON_OP.checkAlgorithm(toCheck, necessaryProperties, checkElements);
|
|
116
|
+
if (typeof checkResult === "string") {
|
|
117
|
+
DBC.reportTsCheckInfringement(checkResult, dbc);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } demanding that a {@link string } is {@link JSON.parse}able.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class JSON_Parse extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Tries to {@link JSON.parse } the {@link string } **toCheck** invoking the **receptor** with the result, if so.
|
|
11
|
+
*
|
|
12
|
+
* @param toCheck The {@link string } to be {@link JSON.parse }d.
|
|
13
|
+
* @param receptor The **( json : object ) => void** to receive the {@link JSON.parse }d {@link string } **toCheck**.
|
|
14
|
+
* check needs to have.
|
|
15
|
+
*
|
|
16
|
+
* @returns TRUE if the value **toCheck** is a valid JSON, otherwise a {@link string } to report the infringement. */
|
|
17
|
+
static checkAlgorithm(toCheck, receptor) {
|
|
18
|
+
let parsed;
|
|
19
|
+
try {
|
|
20
|
+
parsed = JSON.parse(toCheck);
|
|
21
|
+
}
|
|
22
|
+
catch (X) {
|
|
23
|
+
return `[ Following string is not a valid JSON: ${toCheck}]`;
|
|
24
|
+
}
|
|
25
|
+
if (receptor) {
|
|
26
|
+
receptor(parsed);
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A parameter-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
32
|
+
* by the tagged parameter.
|
|
33
|
+
*
|
|
34
|
+
* @param receptor See {@link JSON.checkAlgorithm }.
|
|
35
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
36
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
37
|
+
*
|
|
38
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
39
|
+
static PRE(receptor, path = undefined, hint = undefined, dbc = undefined) {
|
|
40
|
+
return DBC.createPRE(JSON_Parse.checkAlgorithm, [receptor], dbc, path, hint);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A method-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
44
|
+
* by the tagged method's returnvalue.
|
|
45
|
+
*
|
|
46
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
47
|
+
* @param path See {@link DBC.Postcondition }.
|
|
48
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
49
|
+
*
|
|
50
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
51
|
+
static POST(receptor, path = undefined, hint = undefined, dbc = undefined) {
|
|
52
|
+
return DBC.createPOST(JSON_Parse.checkAlgorithm, [receptor], dbc, path, hint);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A field-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
56
|
+
* by the tagged field.
|
|
57
|
+
*
|
|
58
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
59
|
+
* @param path See {@link DBC.decInvariant }.
|
|
60
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
61
|
+
*
|
|
62
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
63
|
+
static INVARIANT(receptor, path = undefined, hint = undefined, dbc = undefined) {
|
|
64
|
+
return DBC.createINVARIANT(JSON_Parse, [receptor], dbc, path, hint);
|
|
65
|
+
}
|
|
66
|
+
// #endregion Condition checking.
|
|
67
|
+
// #region Referenced Condition checking.
|
|
68
|
+
//
|
|
69
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
70
|
+
//
|
|
71
|
+
/**
|
|
72
|
+
* Invokes the {@link JSON_Parse.checkAlgorithm } passing the value **toCheck** and {@link JSON_Parse.receptor }.
|
|
73
|
+
*
|
|
74
|
+
* @param toCheck See {@link JSON_Parse.checkAlgorithm }.
|
|
75
|
+
*
|
|
76
|
+
* @returns See {@link JSON_Parse.checkAlgorithm}. */
|
|
77
|
+
check(toCheck) {
|
|
78
|
+
return JSON_Parse.checkAlgorithm(toCheck, this.receptor);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Creates this {@link JSON_Parse } by setting the protected property {@link JSON_Parse.necessaryProperties } and {@link checkElements } used by {@link JSON_Parse.check }.
|
|
82
|
+
*
|
|
83
|
+
* @param necessaryProperties See {@link JSON_Parse.check }.
|
|
84
|
+
* @param checkElements See {@link JSON_Parse.check }. */
|
|
85
|
+
constructor(receptor = undefined) {
|
|
86
|
+
super();
|
|
87
|
+
this.receptor = receptor;
|
|
88
|
+
}
|
|
89
|
+
// #endregion Referenced Condition checking.
|
|
90
|
+
// #region In-Method checking.
|
|
91
|
+
/**
|
|
92
|
+
* Invokes the {@link JSON_Parse.checkAlgorithm } passing the value **toCheck**, {@link JSON_Parse.necessaryProperties } and {@link JSON_Parse.checkElements }.
|
|
93
|
+
*
|
|
94
|
+
* @param toCheck See {@link JSON_Parse.checkAlgorithm} }.
|
|
95
|
+
* @param necessaryProperties See {@link JSON_Parse.checkAlgorithm} }.
|
|
96
|
+
* @param checkElements See {@link JSON_Parse.checkAlgorithm} }.
|
|
97
|
+
*/
|
|
98
|
+
static check(toCheck, receptor, dbc = undefined) {
|
|
99
|
+
const checkResult = JSON_Parse.checkAlgorithm(toCheck, receptor);
|
|
100
|
+
if (typeof checkResult === "string") {
|
|
101
|
+
DBC.reportTsCheckInfringement(checkResult, dbc);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
package/dist/DBC/OR.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that all elements of an {@link object }s have to fulfill
|
|
4
|
+
* one of the given {@link object }s check-methods (**( toCheck : any ) => boolean | string** ).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
8
|
+
export class OR extends DBC {
|
|
9
|
+
// #region Condition checking.
|
|
10
|
+
/**
|
|
11
|
+
* Checks the **value** against the given **conditions**
|
|
12
|
+
*
|
|
13
|
+
* @param conditions The **{ check: (toCheck: any) => boolean | string }**-{@link object }s to check the **value** against.
|
|
14
|
+
* @param value Either **value**-{@link Array < any >}, which's elements will be checked, or the value to be
|
|
15
|
+
* checked itself.
|
|
16
|
+
* @param index If specified with "idxEnd" being undefined, this {@link Number } will be seen as the index of
|
|
17
|
+
* the value-{@link Array }'s element to check. If value isn't an {@link Array } this parameter
|
|
18
|
+
* will not have any effect.
|
|
19
|
+
* With "idxEnd" not undefined this parameter indicates the beginning of the span of elements to
|
|
20
|
+
* check within the value-{@link Array }.
|
|
21
|
+
* @param idxEnd Indicates the last element's index (including) of the span of value-{@link Array } elements to check.
|
|
22
|
+
* Setting this parameter to -1 specifies that all value-{@link Array }'s elements beginning from the
|
|
23
|
+
* specified **index** shall be checked.
|
|
24
|
+
*
|
|
25
|
+
* @returns TRUE if at least one of the provided **conditions** is fulfilled, otherwise a {@link string } containing all **conditions** returned {@link string }s separated by " || ". */
|
|
26
|
+
static checkAlgorithm(conditions, value) {
|
|
27
|
+
let result = "";
|
|
28
|
+
for (let i = 0; i < conditions.length; i++) {
|
|
29
|
+
const conditionResult = conditions[i].check(value);
|
|
30
|
+
if (typeof conditionResult === "string") {
|
|
31
|
+
result += `${conditionResult}${i === conditions.length - 1 ? "" : " or "}`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A parameter-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
|
|
41
|
+
* of the **realConditions** to check the tagged parameter-value against with.
|
|
42
|
+
* When specifying an **index** and the tagged parameter's **value** is an {@link Array }, the **realConditions** apply to the
|
|
43
|
+
* element at the specified **index**.
|
|
44
|
+
* If the {@link Array } is too short the currently processed { check: (toCheck: any) => boolean | string } of
|
|
45
|
+
* **realConditions** will be verified to TRUE automatically, considering optional parameters.
|
|
46
|
+
* If an **index** is specified but the tagged parameter's value isn't an array, the **index** is treated as being undefined.
|
|
47
|
+
* If **index** is undefined and the tagged parameter's value is an {@link Array } each element of it will be checked
|
|
48
|
+
* against the **realConditions**.
|
|
49
|
+
*
|
|
50
|
+
* @param realConditions Either one or more **{ check: (toCheck: any) => boolean | string }** to check the tagged parameter-value
|
|
51
|
+
* against with.
|
|
52
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
53
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
54
|
+
*
|
|
55
|
+
* @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of **realConditions** returns one.
|
|
56
|
+
* Otherwise TRUE. */
|
|
57
|
+
static PRE(conditions, path = undefined, hint = undefined, dbc = undefined) {
|
|
58
|
+
return DBC.decPrecondition((value) => OR.checkAlgorithm(conditions, value), dbc, path, hint);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* A method-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
|
|
62
|
+
* of the **realConditions** to check the tagged method's return-value against with.
|
|
63
|
+
*
|
|
64
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
65
|
+
* against with.
|
|
66
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
67
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
68
|
+
*
|
|
69
|
+
* @returns A {@link string } as soon as one **{ check: (toCheck: any) => boolean | string }** of **realConditions** return one.
|
|
70
|
+
* Otherwise TRUE. */
|
|
71
|
+
static POST(conditions, path = undefined, hint = undefined, dbc = undefined) {
|
|
72
|
+
return DBC.decPostcondition((value) => OR.checkAlgorithm(conditions, value), dbc, path, hint);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A field-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
|
|
76
|
+
* of the **realConditions** to check the tagged field.
|
|
77
|
+
*
|
|
78
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
79
|
+
* against with.
|
|
80
|
+
* @param path See {@link DBC.decInvariant }.
|
|
81
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
82
|
+
*
|
|
83
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
84
|
+
static INVARIANT(conditions, path = undefined, hint = undefined, dbc = undefined) {
|
|
85
|
+
return DBC.createINVARIANT(OR, [conditions], dbc, path, hint);
|
|
86
|
+
}
|
|
87
|
+
// #endregion Condition checking.
|
|
88
|
+
// #region Referenced Condition checking.
|
|
89
|
+
//
|
|
90
|
+
// For usage in dynamic scenarios (like global functions).
|
|
91
|
+
//
|
|
92
|
+
/**
|
|
93
|
+
* Invokes the {@link OR.checkAlgorithm } passing the value **toCheck** and {@link OR.conditions }.
|
|
94
|
+
*
|
|
95
|
+
* @param toCheck See {@link OR.checkAlgorithm }.
|
|
96
|
+
*
|
|
97
|
+
* @returns See {@link OR.checkAlgorithm}. */
|
|
98
|
+
check(toCheck) {
|
|
99
|
+
return OR.checkAlgorithm(this.conditions, toCheck);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Invokes the {@link OR.checkAlgorithm } passing the value **toCheck** and the {@link OR.type } .
|
|
103
|
+
*
|
|
104
|
+
* @param toCheck See {@link OR.checkAlgorithm }.
|
|
105
|
+
*
|
|
106
|
+
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link OR }.
|
|
107
|
+
*
|
|
108
|
+
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link OR }.*/
|
|
109
|
+
static tsCheck(toCheck, conditions, hint = undefined, id = undefined, dbc = undefined) {
|
|
110
|
+
const result = OR.checkAlgorithm(conditions, toCheck);
|
|
111
|
+
if (result === true) {
|
|
112
|
+
return toCheck;
|
|
113
|
+
}
|
|
114
|
+
DBC.reportTsCheckInfringement(`${id ? `(${id}) ` : ""}${result}${hint ? ` ✨ ${hint} ✨` : ""}`, dbc);
|
|
115
|
+
return toCheck;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Creates this {@link OR } by setting the protected property {@link OR.conditions } used by {@link OR.check }.
|
|
119
|
+
*
|
|
120
|
+
* @param conditions See {@link OR.check }. */
|
|
121
|
+
constructor(conditions) {
|
|
122
|
+
super();
|
|
123
|
+
this.conditions = conditions;
|
|
124
|
+
}
|
|
125
|
+
}
|