xdbc 1.0.217 → 1.0.219

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/.gitattributes +16 -8
  2. package/.vscode/settings.json +3 -3
  3. package/.vscode/tasks.json +23 -23
  4. package/ASSESSMENT.md +249 -0
  5. package/README.md +538 -408
  6. package/__tests__/DBC/AE.test.ts +62 -62
  7. package/__tests__/DBC/ARRAY.test.ts +91 -91
  8. package/__tests__/DBC/DEFINED.test.ts +53 -53
  9. package/__tests__/DBC/DOM.test.ts +786 -0
  10. package/__tests__/DBC/Decorators.test.ts +367 -367
  11. package/__tests__/DBC/EQ.test.ts +13 -13
  12. package/__tests__/DBC/GREATER.test.ts +31 -31
  13. package/__tests__/DBC/HasAttribute.test.ts +60 -60
  14. package/__tests__/DBC/IF.test.ts +62 -62
  15. package/__tests__/DBC/INSTANCE.test.ts +13 -13
  16. package/__tests__/DBC/JSON.OP.test.ts +47 -47
  17. package/__tests__/DBC/JSON.Parse.test.ts +17 -17
  18. package/__tests__/DBC/OR.test.ts +14 -14
  19. package/__tests__/DBC/PLAIN_OBJECT.test.ts +109 -109
  20. package/__tests__/DBC/REGEX.test.ts +17 -17
  21. package/__tests__/DBC/TYPE.test.ts +13 -13
  22. package/__tests__/DBC/UNDEFINED.test.ts +45 -45
  23. package/__tests__/DBC/ZOD.test.ts +54 -54
  24. package/__tests__/DBC/onInfringement.test.ts +262 -0
  25. package/biome.json +45 -40
  26. package/dist/DBC/AE.js +172 -0
  27. package/dist/DBC/ARR/PLAIN_OBJECT.d.ts +0 -3
  28. package/dist/DBC/ARR/PLAIN_OBJECT.js +95 -0
  29. package/dist/DBC/ARRAY.d.ts +0 -3
  30. package/dist/DBC/ARRAY.js +90 -0
  31. package/dist/DBC/COMPARISON/GREATER.js +21 -0
  32. package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +21 -0
  33. package/dist/DBC/COMPARISON/LESS.js +21 -0
  34. package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +21 -0
  35. package/dist/DBC/COMPARISON.js +98 -0
  36. package/dist/DBC/DEFINED.js +87 -0
  37. package/dist/DBC/DOM.d.ts +123 -0
  38. package/dist/DBC/DOM.js +362 -0
  39. package/dist/DBC/EQ/DIFFERENT.js +34 -0
  40. package/dist/DBC/EQ.js +101 -0
  41. package/dist/DBC/GREATER.js +99 -0
  42. package/dist/DBC/HasAttribute.js +101 -0
  43. package/dist/DBC/IF.js +96 -0
  44. package/dist/DBC/INSTANCE.js +122 -0
  45. package/dist/DBC/JSON.OP.js +120 -0
  46. package/dist/DBC/JSON.Parse.js +104 -0
  47. package/dist/DBC/OR.js +125 -0
  48. package/dist/DBC/REGEX.js +136 -0
  49. package/dist/DBC/TYPE.js +112 -0
  50. package/dist/DBC/UNDEFINED.js +87 -0
  51. package/dist/DBC/ZOD.js +99 -0
  52. package/dist/DBC.d.ts +18 -4
  53. package/dist/DBC.js +645 -0
  54. package/dist/Demo.d.ts +10 -0
  55. package/dist/Demo.js +713 -0
  56. package/dist/Test.html +18 -0
  57. package/dist/bundle.js +6140 -405
  58. package/dist/index.d.ts +22 -0
  59. package/dist/index.html +18 -0
  60. package/dist/index.js +22 -0
  61. package/docs/assets/highlight.css +22 -22
  62. package/docs/assets/icons.js +17 -17
  63. package/docs/assets/main.js +60 -60
  64. package/docs/assets/style.css +1640 -1640
  65. package/docs/classes/DBC.DBC.html +98 -98
  66. package/docs/classes/DBC_AE.AE.html +160 -160
  67. package/docs/classes/DBC_EQ.EQ.html +131 -131
  68. package/docs/classes/DBC_GREATER.GREATER.html +139 -139
  69. package/docs/classes/DBC_INSTANCE.INSTANCE.html +130 -130
  70. package/docs/classes/DBC_JSON.OP.JSON_OP.html +138 -138
  71. package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +129 -129
  72. package/docs/classes/DBC_OR.OR.html +137 -137
  73. package/docs/classes/DBC_REGEX.REGEX.html +136 -136
  74. package/docs/classes/DBC_TYPE.TYPE.html +130 -130
  75. package/docs/classes/Demo.Demo.html +14 -14
  76. package/docs/hierarchy.html +1 -1
  77. package/docs/index.html +1 -1
  78. package/docs/modules/DBC.html +1 -1
  79. package/docs/modules/DBC_AE.html +1 -1
  80. package/docs/modules/DBC_EQ.html +1 -1
  81. package/docs/modules/DBC_GREATER.html +1 -1
  82. package/docs/modules/DBC_INSTANCE.html +1 -1
  83. package/docs/modules/DBC_JSON.OP.html +1 -1
  84. package/docs/modules/DBC_JSON.Parse.html +1 -1
  85. package/docs/modules/DBC_OR.html +1 -1
  86. package/docs/modules/DBC_REGEX.html +1 -1
  87. package/docs/modules/DBC_TYPE.html +1 -1
  88. package/docs/modules/Demo.html +1 -1
  89. package/jest.config.js +32 -32
  90. package/package.json +71 -55
  91. package/src/DBC/AE.ts +269 -288
  92. package/src/DBC/ARR/PLAIN_OBJECT.ts +122 -133
  93. package/src/DBC/ARRAY.ts +117 -127
  94. package/src/DBC/COMPARISON/GREATER.ts +41 -46
  95. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +41 -45
  96. package/src/DBC/COMPARISON/LESS.ts +41 -45
  97. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +41 -45
  98. package/src/DBC/COMPARISON.ts +149 -159
  99. package/src/DBC/DEFINED.ts +117 -122
  100. package/src/DBC/DOM.ts +453 -0
  101. package/src/DBC/EQ/DIFFERENT.ts +51 -57
  102. package/src/DBC/EQ.ts +154 -163
  103. package/src/DBC/HasAttribute.ts +149 -154
  104. package/src/DBC/IF.ts +173 -179
  105. package/src/DBC/INSTANCE.ts +168 -171
  106. package/src/DBC/JSON.OP.ts +178 -186
  107. package/src/DBC/JSON.Parse.ts +150 -157
  108. package/src/DBC/OR.ts +183 -187
  109. package/src/DBC/REGEX.ts +195 -196
  110. package/src/DBC/TYPE.ts +142 -149
  111. package/src/DBC/UNDEFINED.ts +115 -117
  112. package/src/DBC/ZOD.ts +130 -135
  113. package/src/DBC.ts +902 -904
  114. package/src/Demo.ts +537 -404
  115. package/src/index.ts +22 -0
  116. package/tsconfig.json +18 -18
  117. package/tsconfig.test.json +7 -7
  118. package/typedoc.json +16 -16
  119. package/webpack.config.js +27 -27
  120. package/Assessment.md +0 -507
@@ -0,0 +1,90 @@
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining that a value must be an array.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
7
+ export class ARRAY extends DBC {
8
+ /**
9
+ * Checks if the value **toCheck** is an array.
10
+ *
11
+ * @param toCheck The value to check.
12
+ *
13
+ * @returns TRUE if the value **toCheck** is an array, otherwise a string describing the infringement. */
14
+ static checkAlgorithm(toCheck) {
15
+ if (toCheck === undefined || toCheck === null)
16
+ return true;
17
+ if (!Array.isArray(toCheck)) {
18
+ return `Value has to be an ARRAY but is of type "${typeof toCheck}"`;
19
+ }
20
+ return true;
21
+ }
22
+ /**
23
+ * A parameter-decorator factory using the {@link ARRAY.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
24
+ * by the tagged parameter.
25
+ *
26
+ * @param path See {@link DBC.decPrecondition }.
27
+ * @param hint See {@link DBC.decPrecondition }.
28
+ * @param dbc See {@link DBC.decPrecondition }.
29
+ *
30
+ * @returns See {@link DBC.decPrecondition }. */
31
+ static PRE(path = undefined, hint = undefined, dbc = undefined) {
32
+ return DBC.createPRE(ARRAY.checkAlgorithm, [], dbc, path, hint);
33
+ }
34
+ /**
35
+ * A method-decorator factory using the {@link ARRAY.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
36
+ * by the tagged method's returnvalue.
37
+ *
38
+ * @param path See {@link DBC.decPostcondition }.
39
+ * @param hint See {@link DBC.decPostcondition }.
40
+ * @param dbc See {@link DBC.decPostcondition }.
41
+ *
42
+ * @returns See {@link DBC.decPostcondition }. */
43
+ static POST(path = undefined, hint = undefined, dbc = undefined) {
44
+ return DBC.createPOST(ARRAY.checkAlgorithm, [], dbc, path, hint);
45
+ }
46
+ /**
47
+ * A field-decorator factory using the {@link ARRAY.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
48
+ * by the tagged field.
49
+ *
50
+ * @param path See {@link DBC.decInvariant }.
51
+ * @param hint See {@link DBC.decInvariant }.
52
+ * @param dbc See {@link DBC.decInvariant }.
53
+ *
54
+ * @returns See {@link DBC.decInvariant }. */
55
+ static INVARIANT(path = undefined, hint = undefined, dbc = undefined) {
56
+ return DBC.createINVARIANT(ARRAY, [], dbc, path, hint);
57
+ }
58
+ // #endregion Condition checking.
59
+ // #region Referenced Condition checking.
60
+ //
61
+ // For usage in dynamic scenarios (like with AE-DBC).
62
+ //
63
+ /**
64
+ * Invokes the {@link ARRAY.checkAlgorithm } passing the value **toCheck**.
65
+ *
66
+ * @param toCheck See {@link ARRAY.checkAlgorithm }.
67
+ *
68
+ * @returns See {@link ARRAY.checkAlgorithm}. */
69
+ check(toCheck) {
70
+ return ARRAY.checkAlgorithm(toCheck);
71
+ }
72
+ /**
73
+ * Invokes the {@link ARRAY.checkAlgorithm } passing the value **toCheck**.
74
+ *
75
+ * @param toCheck See {@link ARRAY.checkAlgorithm }.
76
+ * @param hint An optional {@link string } providing extra information in case of an infringement.
77
+ * @param id A {@link string } identifying this {@link ARRAY } via the {@link DBC.Infringement }-Message.
78
+ *
79
+ * @returns The **CANDIDATE** **toCheck** if this {@link ARRAY } is fulfilled.
80
+ *
81
+ * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link ARRAY }. */
82
+ static tsCheck(toCheck, hint = undefined, id = undefined, dbc = undefined) {
83
+ const result = ARRAY.checkAlgorithm(toCheck);
84
+ if (result === true) {
85
+ return toCheck;
86
+ }
87
+ DBC.reportTsCheckInfringement(`${id ? `(${id}) ` : ""}${result}${hint ? ` ✨ ${hint} ✨` : ""}`, dbc);
88
+ return toCheck;
89
+ }
90
+ }
@@ -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, hint = undefined, dbc = undefined) {
6
+ return COMPARISON.PRE(equivalent, false, false, path, hint, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
10
+ return COMPARISON.POST(equivalent, false, false, path, hint, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
14
+ return COMPARISON.INVARIANT(equivalent, false, false, path, hint, 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, hint = undefined, dbc = undefined) {
6
+ return COMPARISON.PRE(equivalent, true, false, path, hint, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
10
+ return COMPARISON.POST(equivalent, true, false, path, hint, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
14
+ return COMPARISON.INVARIANT(equivalent, true, false, path, hint, 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, hint = undefined, dbc = undefined) {
6
+ return COMPARISON.PRE(equivalent, false, true, path, hint, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
10
+ return COMPARISON.POST(equivalent, false, true, path, hint, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
14
+ return COMPARISON.INVARIANT(equivalent, false, true, path, hint, 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, hint = undefined, dbc = undefined) {
6
+ return COMPARISON.PRE(equivalent, true, true, path, hint, dbc);
7
+ }
8
+ /** See {@link COMPARISON.POST }. */
9
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
10
+ return COMPARISON.POST(equivalent, true, true, path, hint, dbc);
11
+ }
12
+ /** See {@link COMPARISON.INVARIANT }. */
13
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
14
+ return COMPARISON.INVARIANT(equivalent, true, true, path, hint, dbc);
15
+ }
16
+ /** See {@link COMPARISON.constructor }. */
17
+ constructor(equivalent) {
18
+ super(equivalent, true, true);
19
+ this.equivalent = equivalent;
20
+ }
21
+ }
@@ -0,0 +1,98 @@
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 be greater than or equal to "${equivalent}"`;
20
+ }
21
+ if (equalityPermitted && invert && toCheck > equivalent) {
22
+ return `Value has to be less than or equal to "${equivalent}"`;
23
+ }
24
+ if (!equalityPermitted && !invert && toCheck <= equivalent) {
25
+ return `Value has to be greater than "${equivalent}"`;
26
+ }
27
+ if (!equalityPermitted && invert && toCheck >= equivalent) {
28
+ return `Value has 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 hint See {@link DBC.decPrecondition }.
40
+ * @param dbc See {@link DBC.decPrecondition }.
41
+ *
42
+ * @returns See {@link DBC.decPrecondition }. */
43
+ static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
44
+ return DBC.createPRE(COMPARISON.checkAlgorithm, [equivalent, equalityPermitted, invert], dbc, path, hint);
45
+ }
46
+ /**
47
+ * A method-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
48
+ * by the tagged method's returnvalue.
49
+ *
50
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
51
+ * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
52
+ * @param path See {@link DBC.Postcondition }.
53
+ * @param hint See {@link DBC.decPostcondition }.
54
+ * @param dbc See {@link DBC.decPostcondition }.
55
+ *
56
+ * @returns See {@link DBC.decPostcondition }. */
57
+ static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
58
+ return DBC.createPOST(COMPARISON.checkAlgorithm, [equivalent, equalityPermitted, invert], dbc, path, hint);
59
+ }
60
+ /**
61
+ * A field-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
62
+ * by the tagged field.
63
+ *
64
+ * @param equivalent See {@link COMPARISON.checkAlgorithm }.
65
+ * @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
66
+ * @param path See {@link DBC.decInvariant }.
67
+ * @param hint See {@link DBC.decInvariant }.
68
+ * @param dbc See {@link DBC.decInvariant }.
69
+ *
70
+ * @returns See {@link DBC.decInvariant }. */
71
+ static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, hint = undefined, dbc = undefined) {
72
+ return DBC.createINVARIANT(COMPARISON, [equivalent, equalityPermitted, invert], dbc, path, hint);
73
+ }
74
+ // #endregion Condition checking.
75
+ // #region Referenced Condition checking.
76
+ // #region Dynamic usage.
77
+ /**
78
+ * Invokes the {@link COMPARISON.checkAlgorithm } passing the value **toCheck**, {@link COMPARISON.equivalent } and {@link COMPARISON.invert }.
79
+ *
80
+ * @param toCheck See {@link COMPARISON.checkAlgorithm }.
81
+ *
82
+ * @returns See {@link COMPARISON.checkAlgorithm}. */
83
+ check(toCheck) {
84
+ return COMPARISON.checkAlgorithm(toCheck, this.equivalent, this.equalityPermitted, this.invert);
85
+ }
86
+ /**
87
+ * Creates this {@link COMPARISON } by setting the protected property {@link COMPARISON.equivalent }, {@link COMPARISON.equalityPermitted } and {@link COMPARISON.invert } used by {@link COMPARISON.check }.
88
+ *
89
+ * @param equivalent See {@link COMPARISON.check }.
90
+ * @param equalityPermitted See {@link COMPARISON.check }.
91
+ * @param invert See {@link COMPARISON.check }. */
92
+ constructor(equivalent, equalityPermitted = false, invert = false) {
93
+ super();
94
+ this.equivalent = equivalent;
95
+ this.equalityPermitted = equalityPermitted;
96
+ this.invert = invert;
97
+ }
98
+ }
@@ -0,0 +1,87 @@
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining that an {@link object }s must be defined thus it's value may not be **null** or **undefined**.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
7
+ export class DEFINED extends DBC {
8
+ /**
9
+ * Checks if the value **toCheck** is null or undefined.
10
+ *
11
+ * @param toCheck The {@link Object } to check.
12
+ *
13
+ * @returns TRUE if the value **toCheck** is of the specified **type**, otherwise FALSE. */
14
+ static checkAlgorithm(toCheck) {
15
+ if (toCheck === undefined || toCheck === null) {
16
+ return `Value may not be UNDEFINED or NULL but it is ${toCheck === undefined ? "UNDEFINED" : "NULL"}`;
17
+ }
18
+ return true;
19
+ }
20
+ /**
21
+ * A parameter-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
22
+ * by the tagged parameter.
23
+ *
24
+ * @param type See {@link DEFINED.checkAlgorithm }.
25
+ * @param path See {@link DBC.decPrecondition }.
26
+ * @param dbc See {@link DBC.decPrecondition }.
27
+ *
28
+ * @returns See {@link DBC.decPrecondition }. */
29
+ static PRE(path = undefined, hint = undefined, dbc = undefined) {
30
+ return DBC.createPRE(DEFINED.checkAlgorithm, [], dbc, path, hint);
31
+ }
32
+ /**
33
+ * A method-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
34
+ * by the tagged method's returnvalue.
35
+ *
36
+ * @param type See {@link DEFINED.checkAlgorithm }.
37
+ * @param path See {@link DBC.Postcondition }.
38
+ * @param dbc See {@link DBC.decPostcondition }.
39
+ *
40
+ * @returns See {@link DBC.decPostcondition }. */
41
+ static POST(type, path = undefined, hint = undefined, dbc = undefined) {
42
+ return DBC.createPOST(DEFINED.checkAlgorithm, [], dbc, path, hint);
43
+ }
44
+ /**
45
+ * A field-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
46
+ * by the tagged field.
47
+ *
48
+ * @param type See {@link DEFINED.checkAlgorithm }.
49
+ * @param path See {@link DBC.decInvariant }.
50
+ * @param dbc See {@link DBC.decInvariant }.
51
+ *
52
+ * @returns See {@link DBC.decInvariant }. */
53
+ static INVARIANT(type, path = undefined, hint = undefined, dbc = undefined) {
54
+ return DBC.createINVARIANT(DEFINED, [], dbc, path, hint);
55
+ }
56
+ // #endregion Condition checking.
57
+ // #region Referenced Condition checking.
58
+ //
59
+ // For usage in dynamic scenarios (like with AE-DBC).
60
+ //
61
+ /**
62
+ * Invokes the {@link DEFINED.checkAlgorithm } passing the value **toCheck** and the {@link DEFINED.type } .
63
+ *
64
+ * @param toCheck See {@link DEFINED.checkAlgorithm }.
65
+ *
66
+ * @returns See {@link DEFINED.checkAlgorithm}. */
67
+ check(toCheck) {
68
+ return DEFINED.checkAlgorithm(toCheck);
69
+ }
70
+ /**
71
+ * Invokes the {@link DEFINED.checkAlgorithm } passing the value **toCheck** and the {@link DEFINED.type } .
72
+ *
73
+ * @param toCheck See {@link DEFINED.checkAlgorithm }.
74
+ * @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
75
+ *
76
+ * @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link DEFINED }.
77
+ *
78
+ * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }.*/
79
+ static tsCheck(toCheck, hint = undefined, id = undefined, dbc = undefined) {
80
+ const result = DEFINED.checkAlgorithm(toCheck);
81
+ if (result === true) {
82
+ return toCheck;
83
+ }
84
+ DBC.reportTsCheckInfringement(`${id ? `(${id}) ` : ""}${result}${hint ? ` ✨ ${hint} ✨` : ""}`, dbc);
85
+ return toCheck;
86
+ }
87
+ }
@@ -0,0 +1,123 @@
1
+ /** A check function that receives the current field value and the raw attribute string. */
2
+ export type DOMContractCheck = (value: string, attrValue: string) => boolean | string;
3
+ /**
4
+ * Registers a check function for a `data-xdbc-<key>` attribute.
5
+ * Call this before {@link scanDOM } to make a contract available declaratively.
6
+ *
7
+ * @param key The attribute suffix (e.g. `"type"` → `data-xdbc-type`).
8
+ * @param checkFn Receives the live field value and the raw attribute string.
9
+ * Return `true` when the value is valid, or a `string` message when it is not.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { registerDOMContract } from "xdbc/DBC/DOM";
14
+ * import { MY_CONTRACT } from "./MY_CONTRACT";
15
+ *
16
+ * registerDOMContract("my-contract", (value, attr) =>
17
+ * MY_CONTRACT.checkAlgorithm(value, attr),
18
+ * );
19
+ * ```
20
+ */
21
+ export declare function registerDOMContract(key: string, checkFn: DOMContractCheck): void;
22
+ /**
23
+ * Scans the given **root** for `<input>` and `<textarea>` elements marked with the
24
+ * `data-xdbc` attribute, and binds XDBC contracts to their DOM events (blur by
25
+ * default; configurable per element via `data-xdbc-validate-on`).
26
+ *
27
+ * ### Supported attributes
28
+ *
29
+ * | Attribute | Example value | Contract |
30
+ * |----------------------------|----------------------------|-----------------|
31
+ * | `data-xdbc` | *(path or empty)* | marker / DBC path |
32
+ * | `data-xdbc-validate-on` | `input` \| `blur` | when to validate default contracts (default: `blur`) |
33
+ * | `data-xdbc-regex` | `^[a-z]+\.[a-z]{2,}$` | {@link REGEX} — validated per `data-xdbc-validate-on` |
34
+ * | `data-xdbc-regex-input` | `^[a-zA-Z0-9.\-]*$` | {@link REGEX} — always on every keystroke |
35
+ * | `data-xdbc-type` | `string\|number` | {@link TYPE} |
36
+ * | `data-xdbc-type-input` | `string\|number` | {@link TYPE} — always on every keystroke |
37
+ * | `data-xdbc-eq` | `hello` | {@link EQ} |
38
+ * | `data-xdbc-eq-input` | `hello` | {@link EQ} — always on every keystroke |
39
+ * | `data-xdbc-different` | `forbidden` | {@link EQ} (inverted) |
40
+ * | `data-xdbc-different-input` | `forbidden` | {@link EQ} (inverted) — always on every keystroke |
41
+ * | `data-xdbc-defined` | *(no value needed)* | {@link DEFINED} |
42
+ * | `data-xdbc-defined-input` | *(no value needed)* | {@link DEFINED} — always on every keystroke |
43
+ * | `data-xdbc-undefined` | *(no value needed)* | {@link UNDEFINED} |
44
+ * | `data-xdbc-undefined-input` | *(no value needed)* | {@link UNDEFINED} — always on every keystroke |
45
+ * | `data-xdbc-greater` | `5` | {@link COMPARISON} |
46
+ * | `data-xdbc-greater-input` | `5` | {@link COMPARISON} — always on every keystroke |
47
+ * | `data-xdbc-greater-or-equal` | `5` | {@link COMPARISON} |
48
+ * | `data-xdbc-greater-or-equal-input` | `5` | {@link COMPARISON} — always on every keystroke |
49
+ * | `data-xdbc-less` | `100` | {@link COMPARISON} |
50
+ * | `data-xdbc-less-input` | `100` | {@link COMPARISON} — always on every keystroke |
51
+ * | `data-xdbc-less-or-equal` | `100` | {@link COMPARISON} |
52
+ * | `data-xdbc-less-or-equal-input` | `100` | {@link COMPARISON} — always on every keystroke |
53
+ * | `data-xdbc-or` | `regex:^\d+$;;type:string` | {@link OR} (fragment syntax) |
54
+ * | `data-xdbc-or-input` | `regex:^\d+$;;eq:N/A` | {@link OR} — always on every keystroke |
55
+ *
56
+ * Use {@link registerDOMContract } to add further contracts at any time.
57
+ *
58
+ * ### OR fragment syntax
59
+ *
60
+ * Fragments are separated by `;;`. Each fragment is `<contract-key>:<value>`, where the
61
+ * split is on the **first** `:` only, so colons inside values (e.g. regex) are safe.
62
+ * The OR passes as long as **at least one** fragment passes.
63
+ *
64
+ * ```html
65
+ * <!-- digits OR exactly "N/A" -->
66
+ * <input data-xdbc data-xdbc-or="regex:^\d+$;;eq:N/A" />
67
+ * ```
68
+ *
69
+ * ### Behaviour on infringement
70
+ *
71
+ * 1. The element's value is **reverted** to the last accepted state (blocking the invalid input).
72
+ * 2. The configured DBC instance's infringement settings are honoured — `logToConsole`,
73
+ * `onInfringement`, and `throwException` all fire in the usual order. Any throw is caught
74
+ * internally so it cannot propagate out of the DOM event handler.
75
+ *
76
+ * ### IME / composition awareness
77
+ *
78
+ * Validation is suspended during IME composition (e.g. CJK input) and runs once after
79
+ * `compositionend`, so partially composed characters are never incorrectly rejected.
80
+ *
81
+ * @param root Element or Document to scan (default: `document`).
82
+ * @returns A cleanup function that removes all bound event listeners.
83
+ *
84
+ * ### Validate-on
85
+ *
86
+ * By default all contracts are validated when focus **leaves** the field (`blur`). This lets
87
+ * users type freely and only enforces the contract on completion. Set
88
+ * `data-xdbc-validate-on="input"` on an element to revert invalid input on every keystroke.
89
+ *
90
+ * ### Progressive + whole-value validation
91
+ *
92
+ * Use `data-xdbc-regex-input` alongside `data-xdbc-regex` to apply two different patterns:
93
+ * one that allows partial input during typing, and one that enforces the full format on blur.
94
+ * `data-xdbc-regex-input` always fires on every `input` event, regardless of
95
+ * `data-xdbc-validate-on`.
96
+ *
97
+ * ```html
98
+ * <!-- Only validate full domain format when leaving the field (default blur behaviour) -->
99
+ * <!-- While typing, only allow characters that could appear in a domain name -->
100
+ * <input type="text" data-xdbc
101
+ * data-xdbc-regex="^[a-zA-Z0-9][a-zA-Z0-9.\-]*\.[a-zA-Z]{2,}$"
102
+ * data-xdbc-regex-input="^[a-zA-Z0-9.\-]*$" />
103
+ *
104
+ * <!-- Block non-digit keystrokes in real time (explicit input-time validation) -->
105
+ * <input type="text" data-xdbc data-xdbc-validate-on="input" data-xdbc-regex="^\d*$" />
106
+ * ```
107
+ *
108
+ * @example
109
+ * ```html
110
+ * <input type="text" data-xdbc data-xdbc-regex="^[a-zA-Z0-9.\-]*\.[a-zA-Z]{2,}$" />
111
+ * <input type="text" data-xdbc="MyApp.DBC" data-xdbc-type="string" data-xdbc-greater="0" />
112
+ * <input type="text" data-xdbc data-xdbc-or="regex:^\d+$;;eq:N/A" />
113
+ * <textarea data-xdbc data-xdbc-regex="^[\w\s]*$"></textarea>
114
+ * ```
115
+ * ```ts
116
+ * import { scanDOM, registerDOMContract } from "xdbc/DBC/DOM";
117
+ *
118
+ * const cleanup = scanDOM();
119
+ * // later:
120
+ * cleanup();
121
+ * ```
122
+ */
123
+ export declare function scanDOM(root?: Element | Document): () => void;