xdbc 1.0.94 → 1.0.96

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.
Files changed (49) hide show
  1. package/.vscode/settings.json +1 -1
  2. package/README.md +12 -5
  3. package/dist/DBC/AE.js +16 -1
  4. package/dist/DBC/COMPARISON/GREATER.js +21 -0
  5. package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +21 -0
  6. package/dist/DBC/COMPARISON/LESS.js +21 -0
  7. package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +21 -0
  8. package/dist/DBC/COMPARISON.js +99 -0
  9. package/dist/DBC/EQ.js +15 -1
  10. package/dist/DBC/GREATER.js +15 -2
  11. package/dist/DBC/INSTANCE.js +15 -1
  12. package/dist/DBC/JSON.OP.js +13 -1
  13. package/dist/DBC/JSON.Parse.js +13 -1
  14. package/dist/DBC/OR.js +14 -1
  15. package/dist/DBC/REGEX.js +13 -1
  16. package/dist/DBC/TYPE.js +13 -1
  17. package/dist/DBC.js +59 -11
  18. package/dist/Demo.js +217 -55
  19. package/dist/bundle.js +511 -25
  20. package/docs/assets/hierarchy.js +1 -1
  21. package/docs/assets/navigation.js +1 -1
  22. package/docs/assets/search.js +1 -1
  23. package/docs/classes/DBC.DBC.html +40 -23
  24. package/docs/classes/DBC_AE.AE.html +53 -26
  25. package/docs/classes/DBC_EQ.EQ.html +51 -27
  26. package/docs/classes/DBC_GREATER.GREATER.html +54 -29
  27. package/docs/classes/DBC_INSTANCE.INSTANCE.html +51 -27
  28. package/docs/classes/DBC_JSON.OP.JSON_OP.html +52 -29
  29. package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +50 -27
  30. package/docs/classes/DBC_OR.OR.html +50 -27
  31. package/docs/classes/DBC_REGEX.REGEX.html +53 -29
  32. package/docs/classes/DBC_TYPE.TYPE.html +51 -27
  33. package/docs/classes/Demo.Demo.html +14 -0
  34. package/docs/hierarchy.html +1 -1
  35. package/docs/index.html +1 -1
  36. package/docs/modules/Demo.html +1 -0
  37. package/package.json +8 -3
  38. package/src/DBC/COMPARISON/GREATER.ts +38 -0
  39. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +38 -0
  40. package/src/DBC/COMPARISON/LESS.ts +38 -0
  41. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +38 -0
  42. package/src/DBC/{GREATER.ts → COMPARISON.ts} +25 -25
  43. package/src/DBC/EQ/DIFFERENT.ts +35 -0
  44. package/src/DBC/HasAttribute.ts +140 -0
  45. package/src/DBC.ts +44 -1
  46. package/src/Demo.ts +163 -20
  47. package/webpack.config.js +1 -0
  48. package/docs/classes/x.Calculator.html +0 -12
  49. package/docs/modules/x.html +0 -1
@@ -1,3 +1,3 @@
1
1
  {
2
- "cSpell.words": ["alia", "esign", "ontract", "Paramvalue"]
2
+ "cSpell.words": ["alia", "esign", "ontract", "Paramvalue", "Postconditions"]
3
3
  }
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](www.google.de)'s documentation.
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
 
@@ -46,17 +46,22 @@ npm install --save xdbc
46
46
 
47
47
  ## Usage
48
48
 
49
- As by now there're nine contracts that can be used:
49
+ As by now there're 14 contracts that can be used:
50
50
 
51
51
  - AE (*Each element of the value-array has to fulfill a certain set of contracts*)
52
52
  - EQ (*Value has to be equal to a supplied reference value*)
53
- - GREATER (*Value has to be greater than a supplied reference value*)
53
+ - COMPARISON (*Value has to be greater, less, greater/equal, equal or less/equal than a supplied reference value*)
54
54
  - INSTANCE (*Value has to be an instance of a supplied type*)
55
55
  - JSON.OP (*Value has to contain certain properties of certain type*)
56
56
  - JSON.Parse (*String-value has to be a parsable JSON*)
57
57
  - OR (*At least one of a set of contracts has to be fulfilled*)
58
58
  - REGEX (*Value has to be validated by a supplied regular expression*)
59
59
  - TYPE (*Value has to be of a certain type*)
60
+ - GREATER (*Derived from COMPARISON*)
61
+ - GREATER_OR_EQUAL (*Derived from COMPARISON*)
62
+ - LESS (*Derived from COMPARISON*)
63
+ - LESS_OR_EQUAL (*Derived from COMPARISON*)
64
+ - DIFFERENT (*Derived from EQ*)
60
65
 
61
66
  All of which expose a method **PRE**, **POST** and **INVARIANT** (*precondition, postcondition and invariant*).<br>
62
67
  Import the classes to use from **xdbc**. If parameters shall be decorated with contracts import class **DBC** also. <br><br>
@@ -85,10 +90,12 @@ With **PRE**, **POST** and **INVARIANT** decorators an optional **path** paramet
85
90
 
86
91
  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
92
 
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](www.google.de) for details.
93
+ Many contracts got further features like the **AE**-Contract that can check specific ranges within the tagged array or the **EQ**--Contract that can be inverted turning it into **not EQual**-Contract. Check out the [API](https://callaris.github.io/XDBC/) for details.
89
94
 
90
95
  A **DBC**'s **warningSettings** & **infringementSettings** determine what happens on warnings and errors, whereas warnings are not implemented yet.
91
96
 
97
+ **DBC** can be turned off for **PRE**-, **POST**-Conditions and **INVARIANT**S separately by setting the proper **executionSettings** of the **DBC**-Class.
98
+
92
99
  ## Contribution
93
100
  Participation is highly valued and warmly welcomed. The ultimate goal is to create a tool that proves genuinely useful and empowers a wide range of developers to build more robust and reliable applications.
94
101
 
package/dist/DBC/AE.js CHANGED
@@ -1,4 +1,4 @@
1
- import { DBC } from "../DBC.js";
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,21 @@
1
+ import { COMPARISON } from "../COMPARISON";
2
+ /** See {@link COMPARISON }. */
3
+ export class GREATER extends COMPARISON {
4
+ /** See {@link COMPARISON.PRE }. */
5
+ static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
6
+ return COMPARISON.PRE(equivalent, false, false, path, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
10
+ return COMPARISON.POST(equivalent, false, false, path, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
14
+ return COMPARISON.INVARIANT(equivalent, false, false, path, dbc);
15
+ }
16
+ /** See {@link COMPARISON.constructor }. */
17
+ constructor(equivalent) {
18
+ super(equivalent, false, false);
19
+ this.equivalent = equivalent;
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import { COMPARISON } from "../COMPARISON";
2
+ /** See {@link COMPARISON }. */
3
+ export class GREATER_OR_EQUAL extends COMPARISON {
4
+ /** See {@link COMPARISON.PRE }. */
5
+ static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
6
+ return COMPARISON.PRE(equivalent, true, false, path, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
10
+ return COMPARISON.POST(equivalent, true, false, path, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
14
+ return COMPARISON.INVARIANT(equivalent, true, false, path, dbc);
15
+ }
16
+ /** See {@link COMPARISON.constructor }. */
17
+ constructor(equivalent) {
18
+ super(equivalent, true, false);
19
+ this.equivalent = equivalent;
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import { COMPARISON } from "../COMPARISON";
2
+ /** See {@link COMPARISON }. */
3
+ export class LESS extends COMPARISON {
4
+ /** See {@link COMPARISON.PRE }. */
5
+ static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
6
+ return COMPARISON.PRE(equivalent, false, true, path, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
10
+ return COMPARISON.POST(equivalent, false, true, path, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
14
+ return COMPARISON.INVARIANT(equivalent, false, true, path, dbc);
15
+ }
16
+ /** See {@link COMPARISON.constructor }. */
17
+ constructor(equivalent) {
18
+ super(equivalent, false, true);
19
+ this.equivalent = equivalent;
20
+ }
21
+ }
@@ -0,0 +1,21 @@
1
+ import { COMPARISON } from "../COMPARISON";
2
+ /** See {@link COMPARISON }. */
3
+ export class LESS_OR_EQUAL extends COMPARISON {
4
+ /** See {@link COMPARISON.PRE }. */
5
+ static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
6
+ return COMPARISON.PRE(equivalent, true, true, path, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
10
+ return COMPARISON.POST(equivalent, true, true, path, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
14
+ return COMPARISON.INVARIANT(equivalent, true, true, path, dbc);
15
+ }
16
+ /** See {@link COMPARISON.constructor }. */
17
+ constructor(equivalent) {
18
+ super(equivalent, true, true);
19
+ this.equivalent = equivalent;
20
+ }
21
+ }
@@ -0,0 +1,99 @@
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
+ 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 COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
34
+ * by the tagged parameter.
35
+ *
36
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
37
+ * @param equalityPermitted See {@link COMPARISON.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 COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
49
+ * by the tagged method's returnvalue.
50
+ *
51
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
52
+ * @param equalityPermitted See {@link COMPARISON.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 COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
64
+ * by the tagged field.
65
+ *
66
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
67
+ * @param equalityPermitted See {@link COMPARISON.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 COMPARISON.checkAlgorithm } passing the value **toCheck**, {@link COMPARISON.equivalent } and {@link COMPARISON.invert }.
80
+ *
81
+ * @param toCheck See {@link COMPARISON.checkAlgorithm }.
82
+ *
83
+ * @returns See {@link COMPARISON.checkAlgorithm}. */
84
+ check(toCheck) {
85
+ return COMPARISON.checkAlgorithm(toCheck, this.equivalent, this.equalityPermitted, this.invert);
86
+ }
87
+ /**
88
+ * Creates this {@link COMPARISON } by setting the protected property {@link COMPARISON.equivalent }, {@link COMPARISON.equalityPermitted } and {@link COMPARISON.invert } used by {@link COMPARISON.check }.
89
+ *
90
+ * @param equivalent See {@link COMPARISON.check }.
91
+ * @param equalityPermitted See {@link COMPARISON.check }.
92
+ * @param invert See {@link COMPARISON.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.js";
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
  //
@@ -1,4 +1,4 @@
1
- import { DBC } from "../DBC.js";
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 nb equal to the specified **equivalent**.
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.
@@ -1,4 +1,4 @@
1
- import { DBC } from "../DBC.js";
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
  //
@@ -1,4 +1,4 @@
1
- import { DBC } from "../DBC.js";
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
  //
@@ -1,4 +1,4 @@
1
- import { DBC } from "../DBC.js";
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.js";
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.js";
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.js";
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 INVARIANT(contracts) {
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(newValue);
117
+ const result = contract.check(realValue);
117
118
  if (typeof result === "string") {
118
- throw new DBC.Infringement(`[ Property "${propertyKey}"'s value "${newValue}" violates ${contract.constructor.name} cause: ${result} ]`);
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 Parameter
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 Parameter
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 }. */