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
@@ -1,171 +1,168 @@
1
- import { DBC } from "../DBC";
2
- /**
3
- * A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link INSTANCE.reference }.
4
- *
5
- * @remarks
6
- * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
7
- export class INSTANCE extends DBC {
8
- /**
9
- * Checks if the value **toCheck** is an instance of the specified **reference**.
10
- *
11
- * @param toCheck The value that has to be an instance of the **reference** in order for this {@link DBC }
12
- * to be fulfilled.
13
- * @param reference The {@link object } the one **toCheck** has to be an instance of.
14
- *
15
- * @returns TRUE if the value **toCheck** is is an instance of the *reference**, **undefined** or **null**, otherwise FALSE. */
16
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
17
- public static checkAlgorithm(
18
- toCheck: any,
19
- ...references: any[]
20
- ): boolean | string {
21
- if (toCheck === null || toCheck === undefined) {
22
- return true;
23
- }
24
-
25
- for (const ref of references) {
26
- if (toCheck instanceof ref) {
27
- return true;
28
- }
29
- }
30
-
31
- return `Value has to be an instance of "${references.map((ref) => ref.name || ref).join(", ")}" but is of type "${typeof toCheck}"`;
32
- }
33
- /**
34
- * A parameter-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
35
- * by the tagged parameter.
36
- *
37
- * @param reference See {@link INSTANCE.checkAlgorithm }.
38
- * @param path See {@link DBC.decPrecondition }.
39
- * @param dbc See {@link DBC.decPrecondition }.
40
- *
41
- * @returns See {@link DBC.decPrecondition }. */
42
- public static PRE(
43
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
44
- reference: any | any[],
45
- path: string | undefined = undefined,
46
- hint: string | undefined = undefined,
47
- dbc: string | undefined = undefined,
48
- ): (
49
- target: object,
50
- methodName: string | symbol | undefined,
51
- parameterIndex: number,
52
- ) => void {
53
- const refs = Array.isArray(reference) ? reference : [reference];
54
- return DBC.createPRE(INSTANCE.checkAlgorithm, refs, dbc, path, hint);
55
- }
56
- /**
57
- * A method-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
58
- * by the tagged method's returnvalue.
59
- *
60
- * @param reference See {@link INSTANCE.checkAlgorithm }.
61
- * @param path See {@link DBC.Postcondition }.
62
- * @param dbc See {@link DBC.decPostcondition }.
63
- *
64
- * @returns See {@link DBC.decPostcondition }. */
65
- public static POST(
66
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
67
- reference: any | any[],
68
- path: string | undefined = undefined,
69
- hint: string | undefined = undefined,
70
- dbc: string | undefined = undefined,
71
- ): (
72
- target: object,
73
- propertyKey: string,
74
- descriptor: PropertyDescriptor,
75
- ) => PropertyDescriptor {
76
- const refs = Array.isArray(reference) ? reference : [reference];
77
- return DBC.createPOST(INSTANCE.checkAlgorithm, refs, dbc, path, hint);
78
- }
79
- /**
80
- * A field-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
81
- * by the tagged method's returnvalue.
82
- *
83
- * @param reference See {@link INSTANCE.checkAlgorithm }.
84
- * @param path See {@link DBC.decInvariant }.
85
- * @param dbc See {@link DBC.decInvariant }.
86
- *
87
- * @returns See {@link DBC.decInvariant }. */
88
- public static INVARIANT(
89
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
90
- reference: any | any[],
91
- path: string | undefined = undefined,
92
- hint: string | undefined = undefined,
93
- dbc: string | undefined = undefined,
94
- ) {
95
- return DBC.createINVARIANT(INSTANCE, [reference], dbc, path, hint);
96
- }
97
- // #endregion Condition checking.
98
- // #region Referenced Condition checking.
99
- //
100
- // For usage in dynamic scenarios (like with AE-DBC).
101
- //
102
- /**
103
- * Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
104
- *
105
- * @param toCheck See {@link INSTANCE.checkAlgorithm }.
106
- *
107
- * @returns See {@link INSTANCE.checkAlgorithm}. */
108
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
109
- public check(toCheck: any) {
110
- return Array.isArray(this.reference)
111
- ? INSTANCE.checkAlgorithm(toCheck, ...this.reference)
112
- : INSTANCE.checkAlgorithm(toCheck, this.reference);
113
- }
114
- /**
115
- * Type-safe check that validates if a value is an instance of a specified reference.
116
- *
117
- * @param toCheck The value to check for instance validity.
118
- * @param reference The {@link object } the one **toCheck** has to be an instance of.
119
- * @param hint An optional {@link string } providing extra information in case of an infringement.
120
- * @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
121
- *
122
- * @returns The **CANDIDATE** **toCheck** if it fulfills this {@link INSTANCE }.
123
- *
124
- * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link INSTANCE }. */
125
- public static tsCheck<CANDIDATE = unknown>(
126
- toCheck: any,
127
- reference: any,
128
- hint: string = undefined,
129
- id: string | undefined = undefined,
130
- dbc: string | undefined = undefined,
131
- ): CANDIDATE {
132
- return INSTANCE.tsCheckMulti<CANDIDATE>(toCheck, [reference], hint, id, dbc);
133
- }
134
- /**
135
- * Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
136
- *
137
- * @param toCheck See {@link INSTANCE.checkAlgorithm }.
138
- * @param reference See {@link INSTANCE.checkAlgorithm }.
139
- * @param hint An optional {@link string } providing extra information in case of an infringement.
140
- * @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
141
- *
142
- * @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link INSTANCE }.
143
- *
144
- * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
145
- public static tsCheckMulti<CANDIDATE = unknown>(
146
- toCheck: any,
147
- references: any[],
148
- hint: string = undefined,
149
- id: string | undefined = undefined,
150
- dbc: string | undefined = undefined,
151
- ): CANDIDATE {
152
- const result = INSTANCE.checkAlgorithm(toCheck, ...references);
153
-
154
- if (result === true) {
155
- return toCheck;
156
- }
157
- DBC.reportTsCheckInfringement(
158
- `${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
159
- dbc,
160
- );
161
- return toCheck as CANDIDATE;
162
- }
163
- /**
164
- * Creates this {@link INSTANCE } by setting the protected property {@link INSTANCE.reference } used by {@link INSTANCE.check }.
165
- *
166
- * @param reference See {@link INSTANCE.check }. */
167
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
168
- public constructor(protected reference: any) {
169
- super();
170
- }
171
- }
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link INSTANCE.reference }.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
7
+ export class INSTANCE extends DBC {
8
+ /**
9
+ * Checks if the value **toCheck** is an instance of the specified **reference**.
10
+ *
11
+ * @param toCheck The value that has to be an instance of the **reference** in order for this {@link DBC }
12
+ * to be fulfilled.
13
+ * @param reference The {@link object } the one **toCheck** has to be an instance of.
14
+ *
15
+ * @returns TRUE if the value **toCheck** is is an instance of the *reference**, **undefined** or **null**, otherwise FALSE. */
16
+ public static checkAlgorithm(
17
+ toCheck: any,
18
+ ...references: any[]
19
+ ): boolean | string {
20
+ if (toCheck === null || toCheck === undefined) {
21
+ return true;
22
+ }
23
+ for (const ref of references) {
24
+ if (toCheck instanceof ref) {
25
+ return true;
26
+ }
27
+ }
28
+ return `Value has to be an instance of "${references.map((ref) => ref.name || ref).join(", ")}" but is of type "${typeof toCheck}"`;
29
+ }
30
+ /**
31
+ * A parameter-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
32
+ * by the tagged parameter.
33
+ *
34
+ * @param reference See {@link INSTANCE.checkAlgorithm }.
35
+ * @param path See {@link DBC.decPrecondition }.
36
+ * @param dbc See {@link DBC.decPrecondition }.
37
+ *
38
+ * @returns See {@link DBC.decPrecondition }. */
39
+ public static PRE(
40
+ reference: any | any[],
41
+ path: string | undefined = undefined,
42
+ hint: string | undefined = undefined,
43
+ dbc: string | undefined = undefined,
44
+ ): (
45
+ target: object,
46
+ methodName: string | symbol | undefined,
47
+ parameterIndex: number,
48
+ ) => void {
49
+ const refs = Array.isArray(reference) ? reference : [reference];
50
+ return DBC.createPRE(INSTANCE.checkAlgorithm, refs, dbc, path, hint);
51
+ }
52
+ /**
53
+ * A method-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
54
+ * by the tagged method's returnvalue.
55
+ *
56
+ * @param reference See {@link INSTANCE.checkAlgorithm }.
57
+ * @param path See {@link DBC.Postcondition }.
58
+ * @param dbc See {@link DBC.decPostcondition }.
59
+ *
60
+ * @returns See {@link DBC.decPostcondition }. */
61
+ public static POST(
62
+ reference: any | any[],
63
+ path: string | undefined = undefined,
64
+ hint: string | undefined = undefined,
65
+ dbc: string | undefined = undefined,
66
+ ): (
67
+ target: object,
68
+ propertyKey: string,
69
+ descriptor: PropertyDescriptor,
70
+ ) => PropertyDescriptor {
71
+ const refs = Array.isArray(reference) ? reference : [reference];
72
+ return DBC.createPOST(INSTANCE.checkAlgorithm, refs, dbc, path, hint);
73
+ }
74
+ /**
75
+ * A field-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
76
+ * by the tagged method's returnvalue.
77
+ *
78
+ * @param reference See {@link INSTANCE.checkAlgorithm }.
79
+ * @param path See {@link DBC.decInvariant }.
80
+ * @param dbc See {@link DBC.decInvariant }.
81
+ *
82
+ * @returns See {@link DBC.decInvariant }. */
83
+ public static INVARIANT(
84
+ reference: any | any[],
85
+ path: string | undefined = undefined,
86
+ hint: string | undefined = undefined,
87
+ dbc: string | undefined = undefined,
88
+ ) {
89
+ return DBC.createINVARIANT(INSTANCE, [reference], dbc, path, hint);
90
+ }
91
+ // #endregion Condition checking.
92
+ // #region Referenced Condition checking.
93
+ //
94
+ // For usage in dynamic scenarios (like with AE-DBC).
95
+ //
96
+ /**
97
+ * Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
98
+ *
99
+ * @param toCheck See {@link INSTANCE.checkAlgorithm }.
100
+ *
101
+ * @returns See {@link INSTANCE.checkAlgorithm}. */
102
+ public check(toCheck: any) {
103
+ return Array.isArray(this.reference)
104
+ ? INSTANCE.checkAlgorithm(toCheck, ...this.reference)
105
+ : INSTANCE.checkAlgorithm(toCheck, this.reference);
106
+ }
107
+ /**
108
+ * Type-safe check that validates if a value is an instance of a specified reference.
109
+ *
110
+ * @param toCheck The value to check for instance validity.
111
+ * @param reference The {@link object } the one **toCheck** has to be an instance of.
112
+ * @param hint An optional {@link string } providing extra information in case of an infringement.
113
+ * @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
114
+ *
115
+ * @returns The **CANDIDATE** **toCheck** if it fulfills this {@link INSTANCE }.
116
+ *
117
+ * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link INSTANCE }. */
118
+ public static tsCheck<CANDIDATE = unknown>(
119
+ toCheck: any,
120
+ reference: any,
121
+ hint: string = undefined,
122
+ id: string | undefined = undefined,
123
+ dbc: string | undefined = undefined,
124
+ ): CANDIDATE {
125
+ return INSTANCE.tsCheckMulti<CANDIDATE>(
126
+ toCheck,
127
+ [reference],
128
+ hint,
129
+ id,
130
+ dbc,
131
+ );
132
+ }
133
+ /**
134
+ * Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
135
+ *
136
+ * @param toCheck See {@link INSTANCE.checkAlgorithm }.
137
+ * @param reference See {@link INSTANCE.checkAlgorithm }.
138
+ * @param hint An optional {@link string } providing extra information in case of an infringement.
139
+ * @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
140
+ *
141
+ * @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link INSTANCE }.
142
+ *
143
+ * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
144
+ public static tsCheckMulti<CANDIDATE = unknown>(
145
+ toCheck: any,
146
+ references: any[],
147
+ hint: string = undefined,
148
+ id: string | undefined = undefined,
149
+ dbc: string | undefined = undefined,
150
+ ): CANDIDATE {
151
+ const result = INSTANCE.checkAlgorithm(toCheck, ...references);
152
+ if (result === true) {
153
+ return toCheck;
154
+ }
155
+ DBC.reportTsCheckInfringement(
156
+ `${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
157
+ dbc,
158
+ );
159
+ return toCheck as CANDIDATE;
160
+ }
161
+ /**
162
+ * Creates this {@link INSTANCE } by setting the protected property {@link INSTANCE.reference } used by {@link INSTANCE.check }.
163
+ *
164
+ * @param reference See {@link INSTANCE.check }. */
165
+ public constructor(protected reference: any) {
166
+ super();
167
+ }
168
+ }