xdbc 1.0.94 → 1.0.95
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/README.md +3 -3
- package/dist/DBC/AE.js +16 -1
- package/dist/DBC/COMPARISON/GREATER.js +22 -0
- package/dist/DBC/COMPARISON.js +99 -0
- package/dist/DBC/EQ.js +15 -1
- package/dist/DBC/GREATER.js +15 -2
- package/dist/DBC/INSTANCE.js +15 -1
- package/dist/DBC/JSON.OP.js +13 -1
- package/dist/DBC/JSON.Parse.js +13 -1
- package/dist/DBC/OR.js +14 -1
- package/dist/DBC/REGEX.js +13 -1
- package/dist/DBC/TYPE.js +13 -1
- package/dist/DBC.js +59 -11
- package/dist/Demo.js +194 -55
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/DBC.DBC.html +40 -23
- package/docs/classes/DBC_AE.AE.html +53 -26
- package/docs/classes/DBC_EQ.EQ.html +51 -27
- package/docs/classes/DBC_GREATER.GREATER.html +54 -29
- package/docs/classes/DBC_INSTANCE.INSTANCE.html +51 -27
- package/docs/classes/DBC_JSON.OP.JSON_OP.html +52 -29
- package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +50 -27
- package/docs/classes/DBC_OR.OR.html +50 -27
- package/docs/classes/DBC_REGEX.REGEX.html +53 -29
- package/docs/classes/DBC_TYPE.TYPE.html +51 -27
- package/docs/classes/Demo.Demo.html +14 -0
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +1 -1
- package/docs/modules/Demo.html +1 -0
- package/package.json +1 -1
- package/src/DBC/COMPARISON/GREATER.ts +38 -0
- package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +38 -0
- package/src/DBC/COMPARISON/LESS.ts +38 -0
- package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +38 -0
- package/src/DBC/COMPARISON.ts +150 -0
- package/src/DBC/GREATER.ts +1 -1
- package/docs/classes/x.Calculator.html +0 -12
- package/docs/modules/x.html +0 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Leverages the explicit nature of metadata to provide a **D**esign **b**y **C**on
|
|
|
4
4
|
|
|
5
5
|
| Do... | Instead Of |
|
|
6
6
|
|-------------------|------------------------------------------------------------|
|
|
7
|
-
| <pre>public method(@AE.PRE([new REGEX(/^\.*XDBC.\*$/i)]) input : Array\<string>) {<br> ... <br>}</pre>|<pre>public method( input : Array\<string>) {<br> input.forEach(( element, index ) => {<br> console.assert(/^.\*XDBC.\*$/i.test(element),"inconsistent error message");<br> });<br><br> ...<br>}</pre>
|
|
7
|
+
| <pre>@DBC.ParamvalueProvider<br>public method(@AE.PRE([new REGEX(/^\.*XDBC.\*$/i)]) input : Array\<string>) {<br> ... <br>}</pre>|<pre>public method( input : Array\<string>) {<br> input.forEach(( element, index ) => {<br> console.assert(/^.\*XDBC.\*$/i.test(element),"inconsistent error message");<br> });<br><br> ...<br>}</pre>
|
|
8
8
|
| <pre>@REGEX.INVARIANT(/^.\*XDBC.\*$/i)<br>public field = "XDBC";</pre>|<pre>get field() : string { return ... }<br>set field( toSet : string ) {<br> console.assert(/^.\*XDBC.\*$/i.test(element),"Inconsistent error message"); <br><br> ...<br>}</pre>
|
|
9
9
|
| <pre>@REGEX.POST(/^XDBC$/i)<br>public method( input : unknown ) : string {<br> ...<br><br> return result ;<br>}</pre>|<pre>public method( input : unknown ) : string {<br> ...<br><br> if(!/^.\*XDBC.\*$/i.test(result) {<br> throw new Error("inconsistent error message");<br> }<br><br> return result ;<br>}</pre>
|
|
10
10
|
<pre>...and get consistent details about errors like: <code style = "background-color : beige ; color : red ;">[ XDBC Infringement [ From "method" in "MyClass": [ Parameter-value "+1d,+5d,-x10y" of the 1st parameter did not fulfill one of it's contracts: Violating-Arrayelement at index 2. Value has to comply to regular expression "/^(?i:(NOW)|([+-]\d+[dmy]))$/i"]]]</code></pre>
|
|
@@ -36,7 +36,7 @@ Leverages the explicit nature of metadata to provide a **D**esign **b**y **C**on
|
|
|
36
36
|
| Production | Contracts can be kept or disabled | Often disabled for performance |
|
|
37
37
|
|
|
38
38
|
## Demo & API Documentation
|
|
39
|
-
Check out the **Demo.ts** to see some examples usages and the [API](
|
|
39
|
+
Check out the **Demo.ts** to see some examples usages and the [API](https://callaris.github.io/XDBC/)'s documentation.
|
|
40
40
|
|
|
41
41
|
## Installation
|
|
42
42
|
|
|
@@ -85,7 +85,7 @@ With **PRE**, **POST** and **INVARIANT** decorators an optional **path** paramet
|
|
|
85
85
|
|
|
86
86
|
Multiple instances of the class **DBC** with varying settings for e.g. reporting infringements may be instantiated. Which of these instances is used to report can be defined when either using **PRE**, **POST** or **INVARIANT** by defining their **dbc** parameter: **@DBC.INVARIANT([new EQ(1)],"length","MyVendor.MyDBCInstance")**, for example. The standard path (*WaXCode.DBC*) leads to an automatically created instance, that is generated when the Framework is imported.
|
|
87
87
|
|
|
88
|
-
Many contracts got further features like the **AE**-Contract that can check specific ranges within the tagged array or the **EQ**- and **GREATER**-Contract that can be inverted turning them into **not EQual**- or **LESS**-Contracts. Check out the [API](
|
|
88
|
+
Many contracts got further features like the **AE**-Contract that can check specific ranges within the tagged array or the **EQ**- and **GREATER**-Contract that can be inverted turning them into **not EQual**- or **LESS**-Contracts. Check out the [API](https://callaris.github.io/XDBC/) for details.
|
|
89
89
|
|
|
90
90
|
A **DBC**'s **warningSettings** & **infringementSettings** determine what happens on warnings and errors, whereas warnings are not implemented yet.
|
|
91
91
|
|
package/dist/DBC/AE.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } defining that all elements of an {@link object }s have to fulfill
|
|
4
4
|
* a given {@link object }'s check-method (**( toCheck : any ) => boolean | string**).
|
|
@@ -118,6 +118,21 @@ export class AE extends DBC {
|
|
|
118
118
|
return true;
|
|
119
119
|
}, dbc, path);
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* A field-decorator factory using the {@link AE.checkAlgorithm } with either multiple or a single one
|
|
123
|
+
* of the **realConditions** to check the tagged field.
|
|
124
|
+
*
|
|
125
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
126
|
+
* against with.
|
|
127
|
+
* @param index See the {@link AE.checkAlgorithm }.
|
|
128
|
+
* @param idxEnd See the {@link AE.checkAlgorithm }.
|
|
129
|
+
* @param path See {@link DBC.decInvariant }.
|
|
130
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
131
|
+
*
|
|
132
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
133
|
+
static INVARIANT(realConditions, index = undefined, idxEnd = undefined, path = undefined, dbc = "WaXCode.DBC") {
|
|
134
|
+
return DBC.decInvariant([new AE(realConditions, index, idxEnd)], path, dbc);
|
|
135
|
+
}
|
|
121
136
|
// #endregion Condition checking.
|
|
122
137
|
// #region Referenced Condition checking.
|
|
123
138
|
//
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { COMPARISON } from "../COMPARISON";
|
|
2
|
+
export class GREATER extends COMPARISON {
|
|
3
|
+
/** See {@link GREATER.PRE }. */
|
|
4
|
+
static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
5
|
+
return COMPARISON.PRE(equivalent, false, false, path, dbc);
|
|
6
|
+
}
|
|
7
|
+
/** See {@link GREATER.POST }. */
|
|
8
|
+
static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
9
|
+
return COMPARISON.POST(equivalent, false, false, path, dbc);
|
|
10
|
+
}
|
|
11
|
+
/** See {@link GREATER.INVARIANT }. */
|
|
12
|
+
static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
13
|
+
return COMPARISON.INVARIANT(equivalent, false, false, path, dbc);
|
|
14
|
+
}
|
|
15
|
+
/** See {@link GREATER.constructor }. */
|
|
16
|
+
constructor(equivalent, equalityPermitted = false, invert = false) {
|
|
17
|
+
super(equivalent, false, false);
|
|
18
|
+
this.equivalent = equivalent;
|
|
19
|
+
this.equalityPermitted = equalityPermitted;
|
|
20
|
+
this.invert = invert;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that two {@link object }s gotta be equal.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class COMPARISON extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the value **toCheck** is nb equal to the specified **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
|
+
static checkAlgorithm(toCheck, equivalent, equalityPermitted, invert) {
|
|
18
|
+
if (equalityPermitted && !invert && toCheck < equivalent) {
|
|
19
|
+
return `Value has to to be greater than or equal to "${equivalent}"`;
|
|
20
|
+
}
|
|
21
|
+
if (equalityPermitted && invert && toCheck > equivalent) {
|
|
22
|
+
return `Value must not to be less than or equal to "${equivalent}"`;
|
|
23
|
+
}
|
|
24
|
+
if (!equalityPermitted && !invert && toCheck <= equivalent) {
|
|
25
|
+
return `Value has to to be greater than "${equivalent}"`;
|
|
26
|
+
}
|
|
27
|
+
if (!equalityPermitted && invert && toCheck >= equivalent) {
|
|
28
|
+
return `Value must not to be less than "${equivalent}"`;
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* A parameter-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
34
|
+
* by the tagged parameter.
|
|
35
|
+
*
|
|
36
|
+
* @param equivalent See {@link GREATER.checkAlgorithm }.
|
|
37
|
+
* @param equalityPermitted See {@link GREATER.checkAlgorithm }.
|
|
38
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
39
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
40
|
+
*
|
|
41
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
42
|
+
static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
43
|
+
return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
|
|
44
|
+
return COMPARISON.checkAlgorithm(value, equivalent, equalityPermitted, invert);
|
|
45
|
+
}, dbc, path);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* A method-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
49
|
+
* by the tagged method's returnvalue.
|
|
50
|
+
*
|
|
51
|
+
* @param equivalent See {@link GREATER.checkAlgorithm }.
|
|
52
|
+
* @param equalityPermitted See {@link GREATER.checkAlgorithm }.
|
|
53
|
+
* @param path See {@link DBC.Postcondition }.
|
|
54
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
55
|
+
*
|
|
56
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
57
|
+
static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
58
|
+
return DBC.decPostcondition((value, target, propertyKey) => {
|
|
59
|
+
return COMPARISON.checkAlgorithm(value, equalityPermitted, equivalent, invert);
|
|
60
|
+
}, dbc, path);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* A field-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
64
|
+
* by the tagged field.
|
|
65
|
+
*
|
|
66
|
+
* @param equivalent See {@link GREATER.checkAlgorithm }.
|
|
67
|
+
* @param equalityPermitted See {@link GREATER.checkAlgorithm }.
|
|
68
|
+
* @param path See {@link DBC.decInvariant }.
|
|
69
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
70
|
+
*
|
|
71
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
72
|
+
static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
73
|
+
return DBC.decInvariant([new COMPARISON(equivalent, equalityPermitted, invert)], path, dbc);
|
|
74
|
+
}
|
|
75
|
+
// #endregion Condition checking.
|
|
76
|
+
// #region Referenced Condition checking.
|
|
77
|
+
// #region Dynamic usage.
|
|
78
|
+
/**
|
|
79
|
+
* Invokes the {@link GREATER.checkAlgorithm } passing the value **toCheck**, {@link GREATER.equivalent } and {@link GREATER.invert }.
|
|
80
|
+
*
|
|
81
|
+
* @param toCheck See {@link GREATER.checkAlgorithm }.
|
|
82
|
+
*
|
|
83
|
+
* @returns See {@link GREATER.checkAlgorithm}. */
|
|
84
|
+
check(toCheck) {
|
|
85
|
+
return COMPARISON.checkAlgorithm(toCheck, this.equivalent, this.equalityPermitted, this.invert);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Creates this {@link GREATER } by setting the protected property {@link GREATER.equivalent }, {@link GREATER.equalityPermitted } and {@link GREATER.invert } used by {@link GREATER.check }.
|
|
89
|
+
*
|
|
90
|
+
* @param equivalent See {@link GREATER.check }.
|
|
91
|
+
* @param equalityPermitted See {@link GREATER.check }.
|
|
92
|
+
* @param invert See {@link GREATER.check }. */
|
|
93
|
+
constructor(equivalent, equalityPermitted = false, invert = false) {
|
|
94
|
+
super();
|
|
95
|
+
this.equivalent = equivalent;
|
|
96
|
+
this.equalityPermitted = equalityPermitted;
|
|
97
|
+
this.invert = invert;
|
|
98
|
+
}
|
|
99
|
+
}
|
package/dist/DBC/EQ.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } defining that two {@link object }s gotta be equal.
|
|
4
4
|
*
|
|
@@ -57,6 +57,20 @@ export class EQ extends DBC {
|
|
|
57
57
|
return EQ.checkAlgorithm(value, equivalent, invert);
|
|
58
58
|
}, dbc, path);
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* A field-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
62
|
+
* by the tagged field.
|
|
63
|
+
*
|
|
64
|
+
* @param equivalent See {@link EQ.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(
|
|
70
|
+
// biome-ignore lint/suspicious/noExplicitAny: To check for UNDEFINED and NULL.
|
|
71
|
+
equivalent, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
72
|
+
return DBC.decInvariant([new EQ(equivalent, invert)], path, dbc);
|
|
73
|
+
}
|
|
60
74
|
// #endregion Condition checking.
|
|
61
75
|
// #region Referenced Condition checking.
|
|
62
76
|
//
|
package/dist/DBC/GREATER.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } defining that two {@link object }s gotta be equal.
|
|
4
4
|
*
|
|
@@ -7,7 +7,7 @@ import { DBC } from "../DBC.js";
|
|
|
7
7
|
export class GREATER extends DBC {
|
|
8
8
|
// #region Condition checking.
|
|
9
9
|
/**
|
|
10
|
-
* Checks if the value **toCheck** is
|
|
10
|
+
* Checks if the value **toCheck** is equal to the specified **equivalent**.
|
|
11
11
|
*
|
|
12
12
|
* @param toCheck The value that has to be equal to it's possible **equivalent** for this {@link DBC } to be fulfilled.
|
|
13
13
|
* @param equivalent The {@link object } the one **toCheck** has to be equal to in order for this {@link DBC } to be
|
|
@@ -59,6 +59,19 @@ export class GREATER extends DBC {
|
|
|
59
59
|
return GREATER.checkAlgorithm(value, equalityPermitted, equivalent, invert);
|
|
60
60
|
}, dbc, path);
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* A field-decorator factory using the {@link GREATER.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
64
|
+
* by the tagged field.
|
|
65
|
+
*
|
|
66
|
+
* @param equivalent See {@link GREATER.checkAlgorithm }.
|
|
67
|
+
* @param equalityPermitted See {@link GREATER.checkAlgorithm }.
|
|
68
|
+
* @param path See {@link DBC.decInvariant }.
|
|
69
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
70
|
+
*
|
|
71
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
72
|
+
static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
73
|
+
return DBC.decInvariant([new GREATER(equivalent, equalityPermitted, invert)], path, dbc);
|
|
74
|
+
}
|
|
62
75
|
// #endregion Condition checking.
|
|
63
76
|
// #region Referenced Condition checking.
|
|
64
77
|
// #region Dynamic usage.
|
package/dist/DBC/INSTANCE.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link INSTANCE.reference }.
|
|
4
4
|
*
|
|
@@ -52,6 +52,20 @@ export class INSTANCE extends DBC {
|
|
|
52
52
|
return INSTANCE.checkAlgorithm(value, reference);
|
|
53
53
|
}, dbc, path);
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* A field-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
57
|
+
* by the tagged method's returnvalue.
|
|
58
|
+
*
|
|
59
|
+
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
60
|
+
* @param path See {@link DBC.decInvariant }.
|
|
61
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
62
|
+
*
|
|
63
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
64
|
+
static INVARIANT(
|
|
65
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
66
|
+
reference, path = undefined, dbc = "WaXCode.DBC") {
|
|
67
|
+
return DBC.decInvariant([new INSTANCE(reference)], path, dbc);
|
|
68
|
+
}
|
|
55
69
|
// #endregion Condition checking.
|
|
56
70
|
// #region Referenced Condition checking.
|
|
57
71
|
//
|
package/dist/DBC/JSON.OP.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } demanding that an {@link object } has specific properties of specific types.
|
|
4
4
|
*
|
|
@@ -76,6 +76,18 @@ export class JSON_OP extends DBC {
|
|
|
76
76
|
return JSON_OP.checkAlgorithm(value, necessaryProperties, checkElements);
|
|
77
77
|
}, dbc, path);
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A field-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
81
|
+
* by the tagged field.
|
|
82
|
+
*
|
|
83
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
84
|
+
* @param path See {@link DBC.decInvariant }.
|
|
85
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
86
|
+
*
|
|
87
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
88
|
+
static INVARIANT(necessaryProperties, checkElements = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
89
|
+
return DBC.decInvariant([new JSON_OP(necessaryProperties, checkElements)], path, dbc);
|
|
90
|
+
}
|
|
79
91
|
// #endregion Condition checking.
|
|
80
92
|
// #region Referenced Condition checking.
|
|
81
93
|
//
|
package/dist/DBC/JSON.Parse.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } demanding that a {@link string } is {@link JSON.parse}able.
|
|
4
4
|
*
|
|
@@ -58,6 +58,18 @@ export class JSON_Parse extends DBC {
|
|
|
58
58
|
return JSON_Parse.checkAlgorithm(value, receptor);
|
|
59
59
|
}, dbc, path);
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* A field-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
63
|
+
* by the tagged field.
|
|
64
|
+
*
|
|
65
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
66
|
+
* @param path See {@link DBC.decInvariant }.
|
|
67
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
68
|
+
*
|
|
69
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
70
|
+
static INVARIANT(receptor, path = undefined, dbc = "WaXCode.DBC") {
|
|
71
|
+
return DBC.decInvariant([new JSON_Parse(receptor)], path, dbc);
|
|
72
|
+
}
|
|
61
73
|
// #endregion Condition checking.
|
|
62
74
|
// #region Referenced Condition checking.
|
|
63
75
|
//
|
package/dist/DBC/OR.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } defining that all elements of an {@link object }s have to fulfill
|
|
4
4
|
* one of the given {@link object }s check-methods (**( toCheck : any ) => boolean | string** ).
|
|
@@ -75,6 +75,19 @@ export class OR extends DBC {
|
|
|
75
75
|
return OR.checkAlgorithm(conditions, value);
|
|
76
76
|
}, dbc, path);
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* A field-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
|
|
80
|
+
* of the **realConditions** to check the tagged field.
|
|
81
|
+
*
|
|
82
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
83
|
+
* against with.
|
|
84
|
+
* @param path See {@link DBC.decInvariant }.
|
|
85
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
86
|
+
*
|
|
87
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
88
|
+
static INVARIANT(conditions, path = undefined, dbc = "WaXCode.DBC") {
|
|
89
|
+
return DBC.decInvariant([new OR(conditions)], path, dbc);
|
|
90
|
+
}
|
|
78
91
|
// #endregion Condition checking.
|
|
79
92
|
// #region Referenced Condition checking.
|
|
80
93
|
//
|
package/dist/DBC/REGEX.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } providing {@link REGEX }-contracts and standard {@link RegExp } for common use cases in {@link REGEX.stdExp }.
|
|
4
4
|
*
|
|
@@ -48,6 +48,18 @@ export class REGEX extends DBC {
|
|
|
48
48
|
return REGEX.checkAlgorithm(value, expression);
|
|
49
49
|
}, dbc, path);
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* A field-decorator factory using the {@link REGEX.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
53
|
+
* by the tagged field.
|
|
54
|
+
*
|
|
55
|
+
* @param expression See {@link REGEX.checkAlgorithm }.
|
|
56
|
+
* @param path See {@link DBC.decInvariant }.
|
|
57
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
58
|
+
*
|
|
59
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
60
|
+
static INVARIANT(expression, path = undefined, dbc = "WaXCode.DBC") {
|
|
61
|
+
return DBC.decInvariant([new REGEX(expression)], path, dbc);
|
|
62
|
+
}
|
|
51
63
|
// #endregion Condition checking.
|
|
52
64
|
// #region Referenced Condition checking.
|
|
53
65
|
//
|
package/dist/DBC/TYPE.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DBC } from "../DBC
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
3
|
* A {@link DBC } defining that an {@link object }s gotta be of certain {@link TYPE.type }.
|
|
4
4
|
*
|
|
@@ -49,6 +49,18 @@ export class TYPE extends DBC {
|
|
|
49
49
|
return TYPE.checkAlgorithm(value, type);
|
|
50
50
|
}, dbc, path);
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* A field-decorator factory using the {@link TYPE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
54
|
+
* by the tagged field.
|
|
55
|
+
*
|
|
56
|
+
* @param type See {@link TYPE.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(type, path = undefined, dbc = "WaXCode.DBC") {
|
|
62
|
+
return DBC.decInvariant([new TYPE(type)], path, dbc);
|
|
63
|
+
}
|
|
52
64
|
// #endregion Condition checking.
|
|
53
65
|
// #region Referenced Condition checking.
|
|
54
66
|
//
|
package/dist/DBC.js
CHANGED
|
@@ -104,18 +104,19 @@ export class DBC {
|
|
|
104
104
|
*
|
|
105
105
|
* @throws A {@link DBC.Infringement } whenever the property is tried to be set to a value that does not comply to the
|
|
106
106
|
* specified **contracts**, by the returned method.*/
|
|
107
|
-
static
|
|
107
|
+
static decInvariant(contracts, path = undefined, dbc = "WaXCode.DBC") {
|
|
108
108
|
return (target, propertyKey) => {
|
|
109
109
|
// biome-ignore lint/suspicious/noExplicitAny: Necessary to intercept UNDEFINED and NULL.
|
|
110
110
|
let value;
|
|
111
111
|
// #region Replace original property.
|
|
112
112
|
Object.defineProperty(target, propertyKey, {
|
|
113
113
|
set(newValue) {
|
|
114
|
+
const realValue = path ? DBC.resolve(newValue, path) : newValue;
|
|
114
115
|
// #region Check if all "contracts" are fulfilled.
|
|
115
116
|
for (const contract of contracts) {
|
|
116
|
-
const result = contract.check(
|
|
117
|
+
const result = contract.check(realValue);
|
|
117
118
|
if (typeof result === "string") {
|
|
118
|
-
|
|
119
|
+
DBC.resolveDBCPath(window, dbc).reportFieldInfringement(result, target, path, propertyKey, realValue);
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
// #endregion Check if all "contracts" are fulfilled.
|
|
@@ -148,9 +149,7 @@ export class DBC {
|
|
|
148
149
|
descriptor.value = (...args) => {
|
|
149
150
|
// biome-ignore lint/complexity/noThisInStatic: <explanation>
|
|
150
151
|
const result = originalMethod.apply(this, args);
|
|
151
|
-
const realValue = path
|
|
152
|
-
? path === null || path === void 0 ? void 0 : path.split(".").reduce((accumulator, current) => accumulator[current], result)
|
|
153
|
-
: result;
|
|
152
|
+
const realValue = path ? DBC.resolve(result, path) : result;
|
|
154
153
|
const checkResult = check(realValue, target, propertyKey);
|
|
155
154
|
if (typeof checkResult === "string") {
|
|
156
155
|
DBC.resolveDBCPath(window, dbc).reportReturnvalueInfringement(checkResult, target, path, propertyKey, realValue);
|
|
@@ -162,7 +161,7 @@ export class DBC {
|
|
|
162
161
|
}
|
|
163
162
|
// #endregion Postcondition
|
|
164
163
|
// #region Decorator
|
|
165
|
-
// #region
|
|
164
|
+
// #region Precondition
|
|
166
165
|
/**
|
|
167
166
|
* A parameter-decorator factory that requests the tagged parameter's value passing it to the provided
|
|
168
167
|
* "check"-method when the value becomes available.
|
|
@@ -176,9 +175,7 @@ export class DBC {
|
|
|
176
175
|
static decPrecondition(check, dbc, path = undefined) {
|
|
177
176
|
return (target, methodName, parameterIndex) => {
|
|
178
177
|
DBC.requestParamValue(target, methodName, parameterIndex, (value) => {
|
|
179
|
-
const realValue = path
|
|
180
|
-
? path === null || path === void 0 ? void 0 : path.split(".").reduce((accumulator, current) => accumulator[current], value)
|
|
181
|
-
: value;
|
|
178
|
+
const realValue = path ? DBC.resolve(value, path) : value;
|
|
182
179
|
const result = check(realValue, target, methodName, parameterIndex);
|
|
183
180
|
if (typeof result === "string") {
|
|
184
181
|
DBC.resolveDBCPath(window, dbc).reportParameterInfringement(result, target, path, methodName, parameterIndex, realValue);
|
|
@@ -222,6 +219,18 @@ export class DBC {
|
|
|
222
219
|
const properIndex = index + 1;
|
|
223
220
|
this.reportInfringement(`[ Parameter-value "${value}" of the ${properIndex}${properIndex === 1 ? "st" : properIndex === 2 ? "nd" : properIndex === 3 ? "rd" : "th"} parameter did not fulfill one of it's contracts: ${message}]`, method, target, path);
|
|
224
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Reports a field-infringement via {@link reportInfringement } also generating a proper {@link string }-wrapper
|
|
224
|
+
* for the given **message** & **name**.
|
|
225
|
+
*
|
|
226
|
+
* @param message A {@link string } describing the infringement and it's provenience.
|
|
227
|
+
* @param key The property key.
|
|
228
|
+
* @param path The dotted-path {@link string } that leads to the value not fulfilling the contract starting from
|
|
229
|
+
* the tagged one.
|
|
230
|
+
* @param value The value not fulfilling a contract. */
|
|
231
|
+
reportFieldInfringement(message, target, path, key, value) {
|
|
232
|
+
this.reportInfringement(`[ New value for "${key}"${path === undefined ? "" : `.${path}`} with value "${value}" did not fulfill one of it's contracts: ${message}]`, key, target, path);
|
|
233
|
+
}
|
|
225
234
|
/**
|
|
226
235
|
* Reports a returnvalue-infringement according via {@link reportInfringement } also generating a proper {@link string }-wrapper
|
|
227
236
|
* for the given "message","method" & value.
|
|
@@ -240,7 +249,7 @@ export class DBC {
|
|
|
240
249
|
*
|
|
241
250
|
* @param infringementSettings See {@link DBC.infringementSettings }. */
|
|
242
251
|
constructor(infringementSettings = { throwException: true, logToConsole: false }) {
|
|
243
|
-
// #endregion
|
|
252
|
+
// #endregion Precondition
|
|
244
253
|
// #endregion Decorator
|
|
245
254
|
// #region Warning handling.
|
|
246
255
|
/** Stores settings concerning warnings. */
|
|
@@ -256,6 +265,45 @@ export class DBC {
|
|
|
256
265
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
257
266
|
window.WaXCode.DBC = this;
|
|
258
267
|
}
|
|
268
|
+
/**
|
|
269
|
+
* Resolves the desired {@link object } out a given one **toResolveFrom** using the specified **path**.
|
|
270
|
+
*
|
|
271
|
+
* @param toResolveFrom The {@link object } starting to resolve from.
|
|
272
|
+
* @param path The dotted path-{@link string }.
|
|
273
|
+
* This string uses ., [...], and () to represent accessing nested properties,
|
|
274
|
+
* array elements/object keys, and calling methods, respectively, mimicking JavaScript syntax to navigate
|
|
275
|
+
* an object's structure. Code, e.g. something like a.b( 1 as number ).c, will not be executed and
|
|
276
|
+
* thus make the retrieval fail.
|
|
277
|
+
*
|
|
278
|
+
* @returns The requested {@link object }, NULL or UNDEFINED. */
|
|
279
|
+
static resolve(toResolveFrom, path) {
|
|
280
|
+
if (!toResolveFrom || typeof path !== "string") {
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
const parts = path.replace(/\[(['"]?)(.*?)\1\]/g, ".$2").split("."); // Handle indexers
|
|
284
|
+
let current = toResolveFrom;
|
|
285
|
+
for (const part of parts) {
|
|
286
|
+
if (current === null || typeof current === "undefined") {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
const methodMatch = part.match(/(\w+)\((.*)\)/);
|
|
290
|
+
if (methodMatch) {
|
|
291
|
+
const methodName = methodMatch[1];
|
|
292
|
+
const argsStr = methodMatch[2];
|
|
293
|
+
const args = argsStr.split(",").map((arg) => arg.trim()); // Simple argument parsing
|
|
294
|
+
if (typeof current[methodName] === "function") {
|
|
295
|
+
current = current[methodName].apply(current, args);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
return undefined; // Method not found or not a function
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
current = current[part];
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return current;
|
|
306
|
+
}
|
|
259
307
|
}
|
|
260
308
|
// #region Parameter-value requests.
|
|
261
309
|
/** Stores all request for parameter values registered by {@link decPrecondition }. */
|