xdbc 1.0.217 → 1.0.218
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +8 -0
- package/.vscode/settings.json +3 -3
- package/.vscode/tasks.json +23 -23
- package/ASSESSMENT.md +249 -0
- package/README.md +131 -1
- package/__tests__/DBC/AE.test.ts +62 -62
- package/__tests__/DBC/ARRAY.test.ts +91 -91
- package/__tests__/DBC/DEFINED.test.ts +53 -53
- package/__tests__/DBC/DOM.test.ts +481 -0
- package/__tests__/DBC/Decorators.test.ts +367 -367
- package/__tests__/DBC/EQ.test.ts +13 -13
- package/__tests__/DBC/GREATER.test.ts +31 -31
- package/__tests__/DBC/HasAttribute.test.ts +60 -60
- package/__tests__/DBC/IF.test.ts +62 -62
- package/__tests__/DBC/INSTANCE.test.ts +13 -13
- package/__tests__/DBC/JSON.OP.test.ts +47 -47
- package/__tests__/DBC/JSON.Parse.test.ts +17 -17
- package/__tests__/DBC/OR.test.ts +14 -14
- package/__tests__/DBC/PLAIN_OBJECT.test.ts +109 -109
- package/__tests__/DBC/REGEX.test.ts +17 -17
- package/__tests__/DBC/TYPE.test.ts +13 -13
- package/__tests__/DBC/UNDEFINED.test.ts +45 -45
- package/__tests__/DBC/ZOD.test.ts +54 -54
- package/__tests__/DBC/onInfringement.test.ts +262 -0
- package/biome.json +40 -40
- package/dist/DBC/AE.js +172 -0
- package/dist/DBC/ARR/PLAIN_OBJECT.d.ts +0 -3
- package/dist/DBC/ARR/PLAIN_OBJECT.js +95 -0
- package/dist/DBC/ARRAY.d.ts +0 -3
- package/dist/DBC/ARRAY.js +90 -0
- package/dist/DBC/COMPARISON/GREATER.js +21 -0
- package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +21 -0
- package/dist/DBC/COMPARISON/LESS.js +21 -0
- package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +21 -0
- package/dist/DBC/COMPARISON.js +98 -0
- package/dist/DBC/DEFINED.js +87 -0
- package/dist/DBC/DOM.d.ts +87 -0
- package/dist/DBC/DOM.js +223 -0
- package/dist/DBC/EQ/DIFFERENT.js +34 -0
- package/dist/DBC/EQ.js +101 -0
- package/dist/DBC/HasAttribute.js +101 -0
- package/dist/DBC/IF.js +96 -0
- package/dist/DBC/INSTANCE.js +122 -0
- package/dist/DBC/JSON.OP.js +120 -0
- package/dist/DBC/JSON.Parse.js +104 -0
- package/dist/DBC/OR.js +125 -0
- package/dist/DBC/REGEX.js +136 -0
- package/dist/DBC/TYPE.js +112 -0
- package/dist/DBC/UNDEFINED.js +87 -0
- package/dist/DBC/ZOD.js +99 -0
- package/dist/DBC.d.ts +18 -4
- package/dist/DBC.js +645 -0
- package/dist/Demo.d.ts +10 -0
- package/dist/Demo.js +713 -0
- package/dist/bundle.js +6140 -405
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/jest.config.js +32 -32
- package/package.json +71 -55
- package/src/DBC/AE.ts +269 -288
- package/src/DBC/ARR/PLAIN_OBJECT.ts +122 -133
- package/src/DBC/ARRAY.ts +117 -127
- package/src/DBC/COMPARISON/GREATER.ts +41 -46
- package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +41 -45
- package/src/DBC/COMPARISON/LESS.ts +41 -45
- package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +41 -45
- package/src/DBC/COMPARISON.ts +149 -159
- package/src/DBC/DEFINED.ts +117 -122
- package/src/DBC/DOM.ts +291 -0
- package/src/DBC/EQ/DIFFERENT.ts +51 -57
- package/src/DBC/EQ.ts +154 -163
- package/src/DBC/HasAttribute.ts +149 -154
- package/src/DBC/IF.ts +173 -179
- package/src/DBC/INSTANCE.ts +168 -171
- package/src/DBC/JSON.OP.ts +178 -186
- package/src/DBC/JSON.Parse.ts +150 -157
- package/src/DBC/OR.ts +183 -187
- package/src/DBC/REGEX.ts +195 -196
- package/src/DBC/TYPE.ts +142 -149
- package/src/DBC/UNDEFINED.ts +115 -117
- package/src/DBC/ZOD.ts +130 -135
- package/src/DBC.ts +902 -904
- package/src/Demo.ts +537 -404
- package/src/index.ts +22 -0
- package/tsconfig.json +18 -18
- package/tsconfig.test.json +7 -7
- package/typedoc.json +16 -16
- package/webpack.config.js +27 -27
- package/Assessment.md +0 -507
package/src/DBC/OR.ts
CHANGED
|
@@ -1,187 +1,183 @@
|
|
|
1
|
-
import { DBC } from "../DBC";
|
|
2
|
-
/**
|
|
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** ).
|
|
5
|
-
*
|
|
6
|
-
* @remarks
|
|
7
|
-
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
8
|
-
export class OR extends DBC {
|
|
9
|
-
// #region Condition checking.
|
|
10
|
-
/**
|
|
11
|
-
* Checks the **value** against the given **conditions**
|
|
12
|
-
*
|
|
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
|
|
15
|
-
* checked itself.
|
|
16
|
-
* @param index If specified with "idxEnd" being undefined, this {@link Number } will be seen as the index of
|
|
17
|
-
* the value-{@link Array }'s element to check. If value isn't an {@link Array } this parameter
|
|
18
|
-
* will not have any effect.
|
|
19
|
-
* With "idxEnd" not undefined this parameter indicates the beginning of the span of elements to
|
|
20
|
-
* check within the value-{@link Array }.
|
|
21
|
-
* @param idxEnd Indicates the last element's index (including) of the span of value-{@link Array } elements to check.
|
|
22
|
-
* Setting this parameter to -1 specifies that all value-{@link Array }'s elements beginning from the
|
|
23
|
-
* specified **index** shall be checked.
|
|
24
|
-
*
|
|
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 " || ". */
|
|
26
|
-
public static checkAlgorithm(
|
|
27
|
-
conditions: Array<{
|
|
28
|
-
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
29
|
-
}>,
|
|
30
|
-
value: unknown | null | undefined,
|
|
31
|
-
): boolean | string {
|
|
32
|
-
let result = "";
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* If
|
|
52
|
-
* **realConditions
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* @param
|
|
58
|
-
*
|
|
59
|
-
* @
|
|
60
|
-
*
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @param
|
|
88
|
-
*
|
|
89
|
-
* @
|
|
90
|
-
*
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @param
|
|
118
|
-
*
|
|
119
|
-
* @
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
//
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
super();
|
|
185
|
-
}
|
|
186
|
-
// #endregion Referenced Condition checking.
|
|
187
|
-
}
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
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** ).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
8
|
+
export class OR extends DBC {
|
|
9
|
+
// #region Condition checking.
|
|
10
|
+
/**
|
|
11
|
+
* Checks the **value** against the given **conditions**
|
|
12
|
+
*
|
|
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
|
|
15
|
+
* checked itself.
|
|
16
|
+
* @param index If specified with "idxEnd" being undefined, this {@link Number } will be seen as the index of
|
|
17
|
+
* the value-{@link Array }'s element to check. If value isn't an {@link Array } this parameter
|
|
18
|
+
* will not have any effect.
|
|
19
|
+
* With "idxEnd" not undefined this parameter indicates the beginning of the span of elements to
|
|
20
|
+
* check within the value-{@link Array }.
|
|
21
|
+
* @param idxEnd Indicates the last element's index (including) of the span of value-{@link Array } elements to check.
|
|
22
|
+
* Setting this parameter to -1 specifies that all value-{@link Array }'s elements beginning from the
|
|
23
|
+
* specified **index** shall be checked.
|
|
24
|
+
*
|
|
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 " || ". */
|
|
26
|
+
public static checkAlgorithm(
|
|
27
|
+
conditions: Array<{
|
|
28
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
29
|
+
}>,
|
|
30
|
+
value: unknown | null | undefined,
|
|
31
|
+
): boolean | string {
|
|
32
|
+
let result = "";
|
|
33
|
+
for (let i = 0; i < conditions.length; i++) {
|
|
34
|
+
const conditionResult = conditions[i].check(value);
|
|
35
|
+
if (typeof conditionResult === "string") {
|
|
36
|
+
result += `${conditionResult}${i === conditions.length - 1 ? "" : " or "}`;
|
|
37
|
+
} else {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A parameter-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
|
|
45
|
+
* of the **realConditions** to check the tagged parameter-value against with.
|
|
46
|
+
* When specifying an **index** and the tagged parameter's **value** is an {@link Array }, the **realConditions** apply to the
|
|
47
|
+
* element at the specified **index**.
|
|
48
|
+
* If the {@link Array } is too short the currently processed { check: (toCheck: any) => boolean | string } of
|
|
49
|
+
* **realConditions** will be verified to TRUE automatically, considering optional parameters.
|
|
50
|
+
* If an **index** is specified but the tagged parameter's value isn't an array, the **index** is treated as being undefined.
|
|
51
|
+
* If **index** is undefined and the tagged parameter's value is an {@link Array } each element of it will be checked
|
|
52
|
+
* against the **realConditions**.
|
|
53
|
+
*
|
|
54
|
+
* @param realConditions Either one or more **{ check: (toCheck: any) => boolean | string }** to check the tagged parameter-value
|
|
55
|
+
* against with.
|
|
56
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
57
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
58
|
+
*
|
|
59
|
+
* @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of **realConditions** returns one.
|
|
60
|
+
* Otherwise TRUE. */
|
|
61
|
+
public static PRE(
|
|
62
|
+
conditions: Array<{
|
|
63
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
64
|
+
}>,
|
|
65
|
+
path: string | undefined = undefined,
|
|
66
|
+
hint: string | undefined = undefined,
|
|
67
|
+
dbc: string | undefined = undefined,
|
|
68
|
+
): (
|
|
69
|
+
target: object,
|
|
70
|
+
methodName: string | symbol | undefined,
|
|
71
|
+
parameterIndex: number,
|
|
72
|
+
) => void {
|
|
73
|
+
return DBC.decPrecondition(
|
|
74
|
+
(value) => OR.checkAlgorithm(conditions, value),
|
|
75
|
+
dbc,
|
|
76
|
+
path,
|
|
77
|
+
hint,
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* A method-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
|
|
82
|
+
* of the **realConditions** to check the tagged method's return-value against with.
|
|
83
|
+
*
|
|
84
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
85
|
+
* against with.
|
|
86
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
87
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
88
|
+
*
|
|
89
|
+
* @returns A {@link string } as soon as one **{ check: (toCheck: any) => boolean | string }** of **realConditions** return one.
|
|
90
|
+
* Otherwise TRUE. */
|
|
91
|
+
public static POST(
|
|
92
|
+
conditions: Array<{
|
|
93
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
94
|
+
}>,
|
|
95
|
+
path: string | undefined = undefined,
|
|
96
|
+
hint: string | undefined = undefined,
|
|
97
|
+
dbc: string | undefined = undefined,
|
|
98
|
+
): (
|
|
99
|
+
target: object,
|
|
100
|
+
propertyKey: string,
|
|
101
|
+
descriptor: PropertyDescriptor,
|
|
102
|
+
) => PropertyDescriptor {
|
|
103
|
+
return DBC.decPostcondition(
|
|
104
|
+
(value) => OR.checkAlgorithm(conditions, value),
|
|
105
|
+
dbc,
|
|
106
|
+
path,
|
|
107
|
+
hint,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A field-decorator factory using the {@link OR.checkAlgorithm } with either multiple or a single one
|
|
112
|
+
* of the **realConditions** to check the tagged field.
|
|
113
|
+
*
|
|
114
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
115
|
+
* against with.
|
|
116
|
+
* @param path See {@link DBC.decInvariant }.
|
|
117
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
118
|
+
*
|
|
119
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
120
|
+
public static INVARIANT(
|
|
121
|
+
conditions: Array<{
|
|
122
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
123
|
+
}>,
|
|
124
|
+
path: string | undefined = undefined,
|
|
125
|
+
hint: string | undefined = undefined,
|
|
126
|
+
dbc: string | undefined = undefined,
|
|
127
|
+
) {
|
|
128
|
+
return DBC.createINVARIANT(OR, [conditions], dbc, path, hint);
|
|
129
|
+
}
|
|
130
|
+
// #endregion Condition checking.
|
|
131
|
+
// #region Referenced Condition checking.
|
|
132
|
+
//
|
|
133
|
+
// For usage in dynamic scenarios (like global functions).
|
|
134
|
+
//
|
|
135
|
+
/**
|
|
136
|
+
* Invokes the {@link OR.checkAlgorithm } passing the value **toCheck** and {@link OR.conditions }.
|
|
137
|
+
*
|
|
138
|
+
* @param toCheck See {@link OR.checkAlgorithm }.
|
|
139
|
+
*
|
|
140
|
+
* @returns See {@link OR.checkAlgorithm}. */
|
|
141
|
+
public check(toCheck: unknown | null | undefined) {
|
|
142
|
+
return OR.checkAlgorithm(this.conditions, toCheck);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Invokes the {@link OR.checkAlgorithm } passing the value **toCheck** and the {@link OR.type } .
|
|
146
|
+
*
|
|
147
|
+
* @param toCheck See {@link OR.checkAlgorithm }.
|
|
148
|
+
*
|
|
149
|
+
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link OR }.
|
|
150
|
+
*
|
|
151
|
+
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link OR }.*/
|
|
152
|
+
public static tsCheck<CANDIDATE>(
|
|
153
|
+
toCheck: unknown | undefined | null,
|
|
154
|
+
conditions: Array<{
|
|
155
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
156
|
+
}>,
|
|
157
|
+
hint: string = undefined,
|
|
158
|
+
id: string | undefined = undefined,
|
|
159
|
+
dbc: string | undefined = undefined,
|
|
160
|
+
): CANDIDATE {
|
|
161
|
+
const result = OR.checkAlgorithm(conditions, toCheck);
|
|
162
|
+
if (result === true) {
|
|
163
|
+
return toCheck as CANDIDATE;
|
|
164
|
+
}
|
|
165
|
+
DBC.reportTsCheckInfringement(
|
|
166
|
+
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
167
|
+
dbc,
|
|
168
|
+
);
|
|
169
|
+
return toCheck as CANDIDATE;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Creates this {@link OR } by setting the protected property {@link OR.conditions } used by {@link OR.check }.
|
|
173
|
+
*
|
|
174
|
+
* @param conditions See {@link OR.check }. */
|
|
175
|
+
public constructor(
|
|
176
|
+
protected conditions: Array<{
|
|
177
|
+
check: (toCheck: unknown | undefined | null) => boolean | string;
|
|
178
|
+
}>,
|
|
179
|
+
) {
|
|
180
|
+
super();
|
|
181
|
+
}
|
|
182
|
+
// #endregion Referenced Condition checking.
|
|
183
|
+
}
|