xdbc 1.0.93 → 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.
Files changed (97) hide show
  1. package/.parcel-cache/bf96c58b6061a62a-BundleGraph +0 -0
  2. package/.parcel-cache/d7c812d65aeeac59-AssetGraph +0 -0
  3. package/.parcel-cache/data.mdb +0 -0
  4. package/.parcel-cache/e81759c1f106a17f-RequestGraph +0 -0
  5. package/.parcel-cache/fe0db3c4eb428be2-AssetGraph +0 -0
  6. package/.parcel-cache/lock.mdb +0 -0
  7. package/.parcel-cache/snapshot-e81759c1f106a17f.txt +4609 -0
  8. package/CODE_OF_CONDUCT.md +128 -0
  9. package/CONTRIBUTING.md +40 -0
  10. package/FUNDING.yml +3 -0
  11. package/LICENSE +21 -0
  12. package/README.md +96 -0
  13. package/SECURITY.md +36 -0
  14. package/Test.html +1 -1
  15. package/__tests__/DBC/AE.test.ts +62 -0
  16. package/__tests__/DBC/EQ.test.ts +13 -0
  17. package/__tests__/DBC/GREATER.test.ts +29 -0
  18. package/__tests__/DBC/INSTANCE.test.ts +13 -0
  19. package/__tests__/DBC/JSON.OP.test.ts +47 -0
  20. package/__tests__/DBC/JSON.Parse.test.ts +17 -0
  21. package/__tests__/DBC/OR.test.ts +14 -0
  22. package/__tests__/DBC/REGEX.test.ts +13 -0
  23. package/__tests__/DBC/TYPE.test.ts +13 -0
  24. package/babel.rc +12 -0
  25. package/dist/DBC/AE.js +39 -23
  26. package/dist/DBC/COMPARISON/GREATER.js +22 -0
  27. package/dist/DBC/COMPARISON.js +99 -0
  28. package/dist/DBC/EQ.js +21 -7
  29. package/dist/DBC/GREATER.js +19 -6
  30. package/dist/DBC/INSTANCE.js +22 -9
  31. package/dist/DBC/JSON.OP.js +19 -7
  32. package/dist/DBC/JSON.Parse.js +19 -7
  33. package/dist/DBC/OR.js +35 -23
  34. package/dist/DBC/REGEX.js +21 -9
  35. package/dist/DBC/TYPE.js +19 -7
  36. package/dist/DBC.js +112 -39
  37. package/dist/Demo.js +267 -0
  38. package/dist/bundle.js +1329 -0
  39. package/docs/.nojekyll +1 -0
  40. package/docs/assets/hierarchy.js +1 -0
  41. package/docs/assets/highlight.css +22 -0
  42. package/docs/assets/icons.js +18 -0
  43. package/docs/assets/icons.svg +1 -0
  44. package/docs/assets/main.js +60 -0
  45. package/docs/assets/navigation.js +1 -0
  46. package/docs/assets/search.js +1 -0
  47. package/docs/assets/style.css +1640 -0
  48. package/docs/classes/DBC.DBC.html +98 -0
  49. package/docs/classes/DBC_AE.AE.html +160 -0
  50. package/docs/classes/DBC_EQ.EQ.html +131 -0
  51. package/docs/classes/DBC_GREATER.GREATER.html +139 -0
  52. package/docs/classes/DBC_INSTANCE.INSTANCE.html +130 -0
  53. package/docs/classes/DBC_JSON.OP.JSON_OP.html +138 -0
  54. package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +129 -0
  55. package/docs/classes/DBC_OR.OR.html +137 -0
  56. package/docs/classes/DBC_REGEX.REGEX.html +136 -0
  57. package/docs/classes/DBC_TYPE.TYPE.html +130 -0
  58. package/docs/classes/Demo.Demo.html +14 -0
  59. package/docs/hierarchy.html +1 -0
  60. package/docs/index.html +1 -0
  61. package/docs/modules/DBC.html +1 -0
  62. package/docs/modules/DBC_AE.html +1 -0
  63. package/docs/modules/DBC_EQ.html +1 -0
  64. package/docs/modules/DBC_GREATER.html +1 -0
  65. package/docs/modules/DBC_INSTANCE.html +1 -0
  66. package/docs/modules/DBC_JSON.OP.html +1 -0
  67. package/docs/modules/DBC_JSON.Parse.html +1 -0
  68. package/docs/modules/DBC_OR.html +1 -0
  69. package/docs/modules/DBC_REGEX.html +1 -0
  70. package/docs/modules/DBC_TYPE.html +1 -0
  71. package/docs/modules/Demo.html +1 -0
  72. package/jest.config.ts +20 -0
  73. package/package.json +23 -5
  74. package/src/DBC/AE.ts +49 -24
  75. package/src/DBC/COMPARISON/GREATER.ts +38 -0
  76. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +38 -0
  77. package/src/DBC/COMPARISON/LESS.ts +38 -0
  78. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +38 -0
  79. package/src/DBC/COMPARISON.ts +150 -0
  80. package/src/DBC/EQ.ts +26 -8
  81. package/src/DBC/GREATER.ts +30 -7
  82. package/src/DBC/INSTANCE.ts +26 -10
  83. package/src/DBC/JSON.OP.ts +29 -8
  84. package/src/DBC/JSON.Parse.ts +24 -8
  85. package/src/DBC/OR.ts +42 -24
  86. package/src/DBC/REGEX.ts +26 -10
  87. package/src/DBC/TYPE.ts +24 -8
  88. package/src/DBC.ts +138 -46
  89. package/src/Demo.ts +211 -0
  90. package/tsconfig.json +3 -1
  91. package/typedoc.json +16 -0
  92. package/webpack.config.js +26 -0
  93. package/dist/DBC.min.js +0 -2
  94. package/dist/test.js +0 -110
  95. package/src/test.ts +0 -61
  96. package/test.js +0 -14
  97. package/test.ts +0 -11
package/dist/DBC/OR.js CHANGED
@@ -1,18 +1,17 @@
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
- * one of the given {@link object }s check-methods (( toCheck : any ) => boolean | string ).
4
+ * one of the given {@link object }s check-methods (**( toCheck : any ) => boolean | string** ).
5
5
  *
6
6
  * @remarks
7
7
  * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
8
8
  export class OR extends DBC {
9
9
  // #region Condition checking.
10
10
  /**
11
- * Checks each element of the "value"-{@link Array < any >} against the given "condition", if it is one. If it is not
12
- * the "value" itself will be checked.
11
+ * Checks the **value** against the given **conditions**
13
12
  *
14
- * @param conditions The { check: (toCheck: any) => boolean | string }-{@link object }s to check the "value" against.
15
- * @param value Either "value"-{@link Array < any >}, which's elements will be checked, or the value to be
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
16
15
  * checked itself.
17
16
  * @param index If specified with "idxEnd" being undefined, this {@link Number } will be seen as the index of
18
17
  * the value-{@link Array }'s element to check. If value isn't an {@link Array } this parameter
@@ -21,39 +20,39 @@ export class OR extends DBC {
21
20
  * check within the value-{@link Array }.
22
21
  * @param idxEnd Indicates the last element's index (including) of the span of value-{@link Array } elements to check.
23
22
  * Setting this parameter to -1 specifies that all value-{@link Array }'s elements beginning from the
24
- * specified "index" shall be checked.
23
+ * specified **index** shall be checked.
25
24
  *
26
- * @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 " || ". */
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 " || ". */
27
26
  static checkAlgorithm(conditions, value) {
28
27
  let result = "";
29
28
  for (let i = 0; i < conditions.length; i++) {
30
29
  const conditionResult = conditions[i].check(value);
31
- if (typeof conditionResult !== "boolean") {
32
- result += `${conditionResult}${i === conditions.length - 1 ? "" : " || "}`;
30
+ if (typeof conditionResult === "string") {
31
+ result += `${conditionResult}${i === conditions.length - 1 ? "" : " or "}`;
33
32
  }
34
33
  else {
35
34
  return true;
36
35
  }
37
36
  }
38
- return true;
37
+ return result;
39
38
  }
40
39
  /**
41
40
  * A parameter-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
42
- * of the "realConditions" to check the tagged parameter-value against with.
43
- * When specifying an "index" and the tagged parameter's "value" is an {@link Array }, the "realConditions" apply to the
44
- * element at the specified "index".
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**.
45
44
  * If the {@link Array } is too short the currently processed { check: (toCheck: any) => boolean | string } of
46
- * "realConditions" will be verified to TRUE automatically, considering optional parameters.
47
- * If an "index" is specified but the tagged parameter's value isn't an array, the "index" is treated as being undefined.
48
- * If "index" is undefined and the tagged parameter's value is an {@link Array } each element of it will be checked
49
- * against the "realConditions".
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**.
50
49
  *
51
- * @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
50
+ * @param realConditions Either one or more **{ check: (toCheck: any) => boolean | string }** to check the tagged parameter-value
52
51
  * against with.
53
52
  * @param path See {@link DBC.decPrecondition }.
54
53
  * @param dbc See {@link DBC.decPrecondition }.
55
54
  *
56
- * @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of "realConditions" returns one.
55
+ * @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of **realConditions** returns one.
57
56
  * Otherwise TRUE. */
58
57
  static PRE(conditions, path = undefined, dbc = "WaXCode.DBC") {
59
58
  return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
@@ -62,27 +61,40 @@ export class OR extends DBC {
62
61
  }
63
62
  /**
64
63
  * A method-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
65
- * of the "realConditions" to check the tagged method's return-value against with.
64
+ * of the **realConditions** to check the tagged method's return-value against with.
66
65
  *
67
66
  * @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
68
67
  * against with.
69
68
  * @param path See {@link DBC.decPrecondition }.
70
69
  * @param dbc See {@link DBC.decPrecondition }.
71
70
  *
72
- * @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of "realConditions" return one.
71
+ * @returns A {@link string } as soon as one **{ check: (toCheck: any) => boolean | string }** of **realConditions** return one.
73
72
  * Otherwise TRUE. */
74
73
  static POST(conditions, path = undefined, dbc = "WaXCode.DBC") {
75
74
  return DBC.decPostcondition((value, target, propertyKey) => {
76
75
  return OR.checkAlgorithm(conditions, value);
77
76
  }, dbc, path);
78
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
+ }
79
91
  // #endregion Condition checking.
80
92
  // #region Referenced Condition checking.
81
93
  //
82
94
  // For usage in dynamic scenarios (like global functions).
83
95
  //
84
96
  /**
85
- * Invokes the {@link OR.checkAlgorithm } passing the value "toCheck" and {@link OR.conditions }.
97
+ * Invokes the {@link OR.checkAlgorithm } passing the value **toCheck** and {@link OR.conditions }.
86
98
  *
87
99
  * @param toCheck See {@link OR.checkAlgorithm }.
88
100
  *
package/dist/DBC/REGEX.js CHANGED
@@ -7,13 +7,13 @@ import { DBC } from "../DBC";
7
7
  export class REGEX extends DBC {
8
8
  // #region Condition checking.
9
9
  /**
10
- * Checks if the value "toCheck" is complies to the {@link RegExp } "expression".
10
+ * Checks if the value **toCheck** is complies to the {@link RegExp } **expression**.
11
11
  *
12
- * @param toCheck The value that has comply to the {@link RegExp } "expression" for this {@link DBC } to be fulfilled.
13
- * @param expression The {@link RegExp } the one "toCheck" has comply to in order for this {@link DBC } to be
12
+ * @param toCheck The value that has comply to the {@link RegExp } **expression** for this {@link DBC } to be fulfilled.
13
+ * @param expression The {@link RegExp } the one **toCheck** has comply to in order for this {@link DBC } to be
14
14
  * fulfilled.
15
15
  *
16
- * @returns TRUE if the value "toCheck" complies with the {@link RegExp } "expression", otherwise FALSE. */
16
+ * @returns TRUE if the value **toCheck** complies with the {@link RegExp } **expression**, otherwise FALSE. */
17
17
  static checkAlgorithm(toCheck, expression) {
18
18
  if (!expression.test(toCheck)) {
19
19
  return `Value has to comply to regular expression "${expression}"`;
@@ -48,15 +48,27 @@ 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
  //
54
66
  // For usage in dynamic scenarios (like with AE-DBC).
55
67
  //
56
68
  /**
57
- * Invokes the {@link EQ.checkAlgorithm } passing the value "toCheck" and {@link EQ.equivalent }.
69
+ * Invokes the {@link REGEX.checkAlgorithm } passing the value **toCheck** and {@link REGEX.equivalent }.
58
70
  *
59
- * @param toCheck See {@link EQ.checkAlgorithm }.
71
+ * @param toCheck See {@link REGEX.checkAlgorithm }.
60
72
  *
61
73
  * @returns See {@link EQ.checkAlgorithm}. */
62
74
  check(toCheck) {
@@ -73,10 +85,10 @@ export class REGEX extends DBC {
73
85
  // #endregion Referenced Condition checking.
74
86
  // #region In-Method checking.
75
87
  /**
76
- * Invokes the {@link JSON_OP.checkAlgorithm } passing the value "toCheck" and {@link JSON_OP.expression }.
88
+ * Invokes the {@link REGEX.checkAlgorithm } passing the value **toCheck** and {@link REGEX.expression }.
77
89
  *
78
- * @param toCheck See {@link JSON_OP.checkAlgorithm} }.
79
- * @param expression See {@link JSON_OP.checkAlgorithm} }.
90
+ * @param toCheck See {@link REGEX.checkAlgorithm}.
91
+ * @param expression See {@link REGEX.checkAlgorithm}.
80
92
  */
81
93
  static check(toCheck, expression) {
82
94
  const checkResult = REGEX.checkAlgorithm(toCheck, expression);
package/dist/DBC/TYPE.js CHANGED
@@ -1,18 +1,18 @@
1
- import { DBC } from "../DBC.js";
1
+ import { DBC } from "../DBC";
2
2
  /**
3
- * A {@link DBC } defining that the an {@link object }s gotta be of certain {@link TYPE.type }.
3
+ * A {@link DBC } defining that an {@link object }s gotta be of certain {@link TYPE.type }.
4
4
  *
5
5
  * @remarks
6
6
  * Author: Salvatore Callari (Callari@WaXCode.net) / 2025
7
7
  * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
8
8
  export class TYPE extends DBC {
9
9
  /**
10
- * Checks if the value "toCheck" is of the "type" specified.
10
+ * Checks if the value **toCheck** is of the **type** specified.
11
11
  *
12
- * @param toCheck The {@link Object } which'S "type" to check.
13
- * @param type The type the {@link object} "toCheck" has to be of.
12
+ * @param toCheck The {@link Object } which's **type** to check.
13
+ * @param type The type the {@link object} **toCheck** has to be of.
14
14
  *
15
- * @returns TRUE if the value "toCheck" is of the specified "type", otherwise FALSE. */
15
+ * @returns TRUE if the value **toCheck** is of the specified **type**, otherwise FALSE. */
16
16
  // biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic type checking of also UNDEFINED.
17
17
  static checkAlgorithm(toCheck, type) {
18
18
  // biome-ignore lint/suspicious/useValidTypeof: Necessary
@@ -49,13 +49,25 @@ 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
  //
55
67
  // For usage in dynamic scenarios (like with AE-DBC).
56
68
  //
57
69
  /**
58
- * Invokes the {@link TYPE.checkAlgorithm } passing the value "toCheck" and the {@link TYPE.type } .
70
+ * Invokes the {@link TYPE.checkAlgorithm } passing the value **toCheck** and the {@link TYPE.type } .
59
71
  *
60
72
  * @param toCheck See {@link TYPE.checkAlgorithm }.
61
73
  *
package/dist/DBC.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Provides a [D]esign [B]y [C]ontract Framework using decorators.
2
+ * Provides a **D**esign **B**y **C**ontract Framework using decorators.
3
3
  *
4
4
  * @remarks
5
5
  * Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
@@ -54,7 +54,8 @@ export class DBC {
54
54
  return undefined;
55
55
  }
56
56
  /**
57
- * A method-decorator factory checking the {@link paramValueRequests } for value-requests of the method's parameter.
57
+ * A method-decorator factory checking the {@link paramValueRequests } for value-requests of the method's parameter thus
58
+ * also usable on setters.
58
59
  * When found it will invoke the "receptor" registered there, inter alia by {@link requestParamValue }, with the
59
60
  * parameter's value.
60
61
  *
@@ -87,7 +88,7 @@ export class DBC {
87
88
  }
88
89
  // #endregion Check if a value of one of the method's parameter has been requested and pass it to the
89
90
  // receptor, if so.
90
- // biome-ignore lint/complexity/noThisInStatic: <explanation>
91
+ // biome-ignore lint/complexity/noThisInStatic: Necessary.
91
92
  return originalMethod.apply(this, args);
92
93
  };
93
94
  return descriptor;
@@ -95,47 +96,60 @@ export class DBC {
95
96
  // #endregion Parameter-value requests.
96
97
  // #region Invariant
97
98
  /**
99
+ * A property-decorator factory serving as a **D**esign **B**y **C**ontract Invariant.
100
+ * Since the value must be initialized or set according to the specified **contracts** the value will only be checked
101
+ * when assigning it.
98
102
  *
99
- * @param toCheck
100
- * @returns
101
- */
102
- check(toCheck) {
103
- return false;
104
- }
105
- /**
103
+ * @param contracts The {@link DBC }-Contracts the value shall uphold.
106
104
  *
107
- * @param conditions
108
- * @param property
109
- * @returns
110
- */
111
- static decInvariant(conditions, property) {
112
- return (toCheck) => {
113
- for (const condition of conditions) {
114
- condition.check(new toCheck(...[])[property]);
115
- }
105
+ * @throws A {@link DBC.Infringement } whenever the property is tried to be set to a value that does not comply to the
106
+ * specified **contracts**, by the returned method.*/
107
+ static decInvariant(contracts, path = undefined, dbc = "WaXCode.DBC") {
108
+ return (target, propertyKey) => {
109
+ // biome-ignore lint/suspicious/noExplicitAny: Necessary to intercept UNDEFINED and NULL.
110
+ let value;
111
+ // #region Replace original property.
112
+ Object.defineProperty(target, propertyKey, {
113
+ set(newValue) {
114
+ const realValue = path ? DBC.resolve(newValue, path) : newValue;
115
+ // #region Check if all "contracts" are fulfilled.
116
+ for (const contract of contracts) {
117
+ const result = contract.check(realValue);
118
+ if (typeof result === "string") {
119
+ DBC.resolveDBCPath(window, dbc).reportFieldInfringement(result, target, path, propertyKey, realValue);
120
+ }
121
+ }
122
+ // #endregion Check if all "contracts" are fulfilled.
123
+ value = newValue;
124
+ },
125
+ enumerable: true,
126
+ configurable: true,
127
+ });
128
+ // #endregion Replace original property.
116
129
  };
117
130
  }
118
131
  // #endregion Invariant
119
132
  // #region Postcondition
120
133
  /**
134
+ * A method decorator factory checking the result of a method whenever it is invoked thus also usable on getters.
121
135
  *
122
- * @param check
123
- * @param dbc
124
- * @param path
125
- * @returns
136
+ * @param check The **(toCheck: any, object, string) => boolean | string** to use for checking.
137
+ * @param dbc See {@link DBC.resolveDBCPath }.
138
+ * @param path The dotted path referring to the actual value to check, starting form the specified one.
139
+ *
140
+ * @returns The **( target : object, propertyKey : string, descriptor : PropertyDescriptor ) : PropertyDescriptor**
141
+ * invoked by Typescript.
126
142
  */
127
143
  static decPostcondition(
128
- // biome-ignore lint/suspicious/noExplicitAny: Gotta be any since parameter-values may be undefined.
144
+ // biome-ignore lint/suspicious/noExplicitAny: Necessary to intercept UNDEFINED and NULL.
129
145
  check, dbc, path = undefined) {
130
146
  return (target, propertyKey, descriptor) => {
131
147
  const originalMethod = descriptor.value;
132
- // biome-ignore lint/suspicious/noExplicitAny: Gotta be any since parameter-values may be undefined.
148
+ // biome-ignore lint/suspicious/noExplicitAny: Necessary to intercept UNDEFINED and NULL.
133
149
  descriptor.value = (...args) => {
134
150
  // biome-ignore lint/complexity/noThisInStatic: <explanation>
135
151
  const result = originalMethod.apply(this, args);
136
- const realValue = path
137
- ? path === null || path === void 0 ? void 0 : path.split(".").reduce((accumulator, current) => accumulator[current], result)
138
- : result;
152
+ const realValue = path ? DBC.resolve(result, path) : result;
139
153
  const checkResult = check(realValue, target, propertyKey);
140
154
  if (typeof checkResult === "string") {
141
155
  DBC.resolveDBCPath(window, dbc).reportReturnvalueInfringement(checkResult, target, path, propertyKey, realValue);
@@ -147,23 +161,21 @@ export class DBC {
147
161
  }
148
162
  // #endregion Postcondition
149
163
  // #region Decorator
150
- // #region Parameter
164
+ // #region Precondition
151
165
  /**
152
166
  * A parameter-decorator factory that requests the tagged parameter's value passing it to the provided
153
167
  * "check"-method when the value becomes available.
154
168
  *
155
169
  * @param check The "( unknown ) => void" to be invoked along with the tagged parameter's value as soon
156
170
  * as it becomes available.
157
- * @param path The dotted path referring to the actual value to check, starting form the specified one.
158
171
  * @param dbc See {@link DBC.resolveDBCPath }.
172
+ * @param path The dotted path referring to the actual value to check, starting form the specified one.
159
173
  *
160
- * @returns The { (target: object, methodName: string | symbol, parameterIndex: number ) => void } invoked by Typescript- */
174
+ * @returns The **(target: object, methodName: string | symbol, parameterIndex: number ) => void** invoked by Typescript- */
161
175
  static decPrecondition(check, dbc, path = undefined) {
162
176
  return (target, methodName, parameterIndex) => {
163
177
  DBC.requestParamValue(target, methodName, parameterIndex, (value) => {
164
- const realValue = path
165
- ? path === null || path === void 0 ? void 0 : path.split(".").reduce((accumulator, current) => accumulator[current], value)
166
- : value;
178
+ const realValue = path ? DBC.resolve(value, path) : value;
167
179
  const result = check(realValue, target, methodName, parameterIndex);
168
180
  if (typeof result === "string") {
169
181
  DBC.resolveDBCPath(window, dbc).reportParameterInfringement(result, target, path, methodName, parameterIndex, realValue);
@@ -196,7 +208,7 @@ export class DBC {
196
208
  }
197
209
  }
198
210
  /**
199
- * Reports a parameter-infringement according via {@link reportInfringement } also generating a proper {@link string }-wrapper
211
+ * Reports a parameter-infringement via {@link reportInfringement } also generating a proper {@link string }-wrapper
200
212
  * for the given "message","method", parameter-"index" & value.
201
213
  *
202
214
  * @param message The {@link string } describing the infringement and it's provenience.
@@ -207,6 +219,18 @@ export class DBC {
207
219
  const properIndex = index + 1;
208
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);
209
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
+ }
210
234
  /**
211
235
  * Reports a returnvalue-infringement according via {@link reportInfringement } also generating a proper {@link string }-wrapper
212
236
  * for the given "message","method" & value.
@@ -220,18 +244,19 @@ export class DBC {
220
244
  this.reportInfringement(`[ Return-value "${value}" did not fulfill one of it's contracts: ${message}]`, method, target, path);
221
245
  }
222
246
  /**
247
+ * Constructs this {@link DBC } by setting the {@link DBC.infringementSettings }, define the **WaXCode** namespace in
248
+ * **window** if not yet available and setting the property **DBC** in there to the instance of this {@link DBC }.
223
249
  *
224
- * @param infringementSettings
225
- */
250
+ * @param infringementSettings See {@link DBC.infringementSettings }. */
226
251
  constructor(infringementSettings = { throwException: true, logToConsole: false }) {
227
- // #endregion Parameter
252
+ // #endregion Precondition
228
253
  // #endregion Decorator
229
254
  // #region Warning handling.
230
255
  /** Stores settings concerning warnings. */
231
256
  this.warningSettings = { logToConsole: true };
232
257
  // #endregion Warning handling.
233
258
  // #region infringement handling.
234
- /** Stores the setting concerning infringements */
259
+ /** Stores the settings concerning infringements */
235
260
  this.infringementSettings = { throwException: true, logToConsole: false };
236
261
  this.infringementSettings = infringementSettings;
237
262
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
@@ -240,6 +265,45 @@ export class DBC {
240
265
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
241
266
  window.WaXCode.DBC = this;
242
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
+ }
243
307
  }
244
308
  // #region Parameter-value requests.
245
309
  /** Stores all request for parameter values registered by {@link decPrecondition }. */
@@ -259,5 +323,14 @@ DBC.Infringement = class extends Error {
259
323
  // #endregion Errors
260
324
  // #endregion Classes
261
325
  // #endregion infringement handling.
326
+ /**
327
+ * Resolves the specified dotted {@link string }-path to a {@link DBC }.
328
+ *
329
+ * @param obj The {@link object } to start resolving from.
330
+ * @param path The dotted {@link string }-path leading to the {@link DBC }.
331
+ *
332
+ * @returns The requested {@link DBC }.
333
+ */
262
334
  DBC.resolveDBCPath = (obj, path) => path === null || path === void 0 ? void 0 : path.split(".").reduce((accumulator, current) => accumulator[current], obj);
335
+ // Set the main instance with standard **DBC.infringementSettings**.
263
336
  new DBC();