xdbc 1.0.211 → 1.0.213
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/.github/workflows/ci.yml +51 -0
- package/.vscode/tasks.json +23 -23
- package/CODE_OF_CONDUCT.md +1 -1
- package/README.md +1 -0
- package/__tests__/DBC/AE.test.ts +1 -1
- package/__tests__/DBC/DEFINED.test.ts +49 -49
- package/__tests__/DBC/Decorators.test.ts +334 -332
- package/__tests__/DBC/HasAttribute.test.ts +56 -52
- package/__tests__/DBC/IF.test.ts +57 -57
- package/__tests__/DBC/OR.test.ts +1 -1
- package/__tests__/DBC/UNDEFINED.test.ts +41 -41
- package/__tests__/DBC/ZOD.test.ts +50 -50
- package/biome.json +40 -33
- package/dist/DBC/AE.d.ts +117 -0
- package/dist/DBC/COMPARISON/GREATER.d.ts +13 -0
- package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.d.ts +13 -0
- package/dist/DBC/COMPARISON/LESS.d.ts +13 -0
- package/dist/DBC/COMPARISON/LESS_OR_EQUAL.d.ts +13 -0
- package/dist/DBC/COMPARISON.d.ts +70 -0
- package/dist/DBC/DEFINED.d.ts +62 -0
- package/dist/DBC/EQ/DIFFERENT.d.ts +26 -0
- package/dist/DBC/EQ.d.ts +70 -0
- package/dist/DBC/HasAttribute.d.ts +72 -0
- package/dist/DBC/IF.d.ts +90 -0
- package/dist/DBC/INSTANCE.d.ts +84 -0
- package/dist/DBC/JSON.OP.d.ts +94 -0
- package/dist/DBC/JSON.Parse.d.ts +69 -0
- package/dist/DBC/OR.d.ts +104 -0
- package/dist/DBC/REGEX.d.ts +96 -0
- package/dist/DBC/TYPE.d.ts +75 -0
- package/dist/DBC/UNDEFINED.d.ts +62 -0
- package/dist/DBC/ZOD.d.ts +72 -0
- package/dist/DBC.d.ts +244 -0
- package/dist/Demo.d.ts +20 -0
- package/dist/bundle.js +2297 -0
- package/docs/assets/highlight.css +22 -22
- package/docs/assets/icons.js +17 -17
- package/docs/assets/main.js +60 -60
- package/docs/assets/style.css +1640 -1640
- package/docs/classes/DBC.DBC.html +98 -98
- package/docs/classes/DBC_AE.AE.html +160 -160
- package/docs/classes/DBC_EQ.EQ.html +131 -131
- package/docs/classes/DBC_GREATER.GREATER.html +139 -139
- package/docs/classes/DBC_INSTANCE.INSTANCE.html +130 -130
- package/docs/classes/DBC_JSON.OP.JSON_OP.html +138 -138
- package/docs/classes/DBC_JSON.Parse.JSON_Parse.html +129 -129
- package/docs/classes/DBC_OR.OR.html +137 -137
- package/docs/classes/DBC_REGEX.REGEX.html +136 -136
- package/docs/classes/DBC_TYPE.TYPE.html +130 -130
- package/docs/classes/Demo.Demo.html +14 -14
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +1 -1
- package/docs/modules/DBC.html +1 -1
- package/docs/modules/DBC_AE.html +1 -1
- package/docs/modules/DBC_EQ.html +1 -1
- package/docs/modules/DBC_GREATER.html +1 -1
- package/docs/modules/DBC_INSTANCE.html +1 -1
- package/docs/modules/DBC_JSON.OP.html +1 -1
- package/docs/modules/DBC_JSON.Parse.html +1 -1
- package/docs/modules/DBC_OR.html +1 -1
- package/docs/modules/DBC_REGEX.html +1 -1
- package/docs/modules/DBC_TYPE.html +1 -1
- package/docs/modules/Demo.html +1 -1
- package/jest.config.js +29 -18
- package/package.json +6 -2
- package/src/DBC/AE.ts +14 -9
- package/src/DBC/COMPARISON/GREATER.ts +2 -2
- package/src/DBC/COMPARISON.ts +159 -136
- package/src/DBC/DEFINED.ts +10 -10
- package/src/DBC/EQ/DIFFERENT.ts +3 -3
- package/src/DBC/EQ.ts +25 -9
- package/src/DBC/HasAttribute.ts +17 -3
- package/src/DBC/IF.ts +63 -19
- package/src/DBC/INSTANCE.ts +29 -14
- package/src/DBC/JSON.OP.ts +18 -3
- package/src/DBC/JSON.Parse.ts +21 -4
- package/src/DBC/OR.ts +12 -7
- package/src/DBC/REGEX.ts +30 -21
- package/src/DBC/TYPE.ts +15 -11
- package/src/DBC/UNDEFINED.ts +7 -10
- package/src/DBC/ZOD.ts +14 -9
- package/src/DBC.ts +165 -69
- package/src/Demo.ts +21 -18
- package/test.drawio +0 -0
- package/tsconfig.json +3 -5
- package/tsconfig.test.json +6 -11
- package/webpack.config.js +1 -1
package/src/DBC/INSTANCE.ts
CHANGED
|
@@ -14,7 +14,10 @@ export class INSTANCE extends DBC {
|
|
|
14
14
|
*
|
|
15
15
|
* @returns TRUE if the value **toCheck** is is an instance of the *reference**, **undefined** or **null**, otherwise FALSE. */
|
|
16
16
|
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
17
|
-
public static checkAlgorithm(
|
|
17
|
+
public static checkAlgorithm(
|
|
18
|
+
toCheck: any,
|
|
19
|
+
...references: any[]
|
|
20
|
+
): boolean | string {
|
|
18
21
|
if (toCheck === null || toCheck === undefined) {
|
|
19
22
|
return true;
|
|
20
23
|
}
|
|
@@ -25,7 +28,7 @@ export class INSTANCE extends DBC {
|
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
return `Value has to be an instance of "${references.map(ref => ref.name || ref).join(
|
|
31
|
+
return `Value has to be an instance of "${references.map((ref) => ref.name || ref).join(", ")}" but is of type "${typeof toCheck}"`;
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
34
|
* A parameter-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -104,42 +107,54 @@ export class INSTANCE extends DBC {
|
|
|
104
107
|
* @returns See {@link INSTANCE.checkAlgorithm}. */
|
|
105
108
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
106
109
|
public check(toCheck: any) {
|
|
107
|
-
return Array.isArray(this.reference)
|
|
110
|
+
return Array.isArray(this.reference)
|
|
111
|
+
? INSTANCE.checkAlgorithm(toCheck, ...this.reference)
|
|
112
|
+
: INSTANCE.checkAlgorithm(toCheck, this.reference);
|
|
108
113
|
}
|
|
109
114
|
/**
|
|
110
115
|
* Type-safe check that validates if a value is an instance of a specified reference.
|
|
111
|
-
*
|
|
116
|
+
*
|
|
112
117
|
* @param toCheck The value to check for instance validity.
|
|
113
118
|
* @param reference The {@link object } the one **toCheck** has to be an instance of.
|
|
114
119
|
* @param hint An optional {@link string } providing extra information in case of an infringement.
|
|
115
120
|
* @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
|
|
116
|
-
*
|
|
121
|
+
*
|
|
117
122
|
* @returns The **CANDIDATE** **toCheck** if it fulfills this {@link INSTANCE }.
|
|
118
|
-
*
|
|
123
|
+
*
|
|
119
124
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link INSTANCE }. */
|
|
120
|
-
public static tsCheck<CANDIDATE = unknown>(
|
|
125
|
+
public static tsCheck<CANDIDATE = unknown>(
|
|
126
|
+
toCheck: any,
|
|
127
|
+
reference: any,
|
|
128
|
+
hint: string = undefined,
|
|
129
|
+
id: string | undefined = undefined,
|
|
130
|
+
): CANDIDATE {
|
|
121
131
|
return INSTANCE.tsCheckMulti<CANDIDATE>(toCheck, [reference], hint, id);
|
|
122
132
|
}
|
|
123
133
|
/**
|
|
124
134
|
* Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
|
|
125
|
-
*
|
|
135
|
+
*
|
|
126
136
|
* @param toCheck See {@link INSTANCE.checkAlgorithm }.
|
|
127
137
|
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
128
138
|
* @param hint An optional {@link string } providing extra information in case of an infringement.
|
|
129
139
|
* @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
|
|
130
|
-
*
|
|
140
|
+
*
|
|
131
141
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link INSTANCE }.
|
|
132
|
-
*
|
|
142
|
+
*
|
|
133
143
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
|
|
134
|
-
public static tsCheckMulti<CANDIDATE = unknown>(
|
|
144
|
+
public static tsCheckMulti<CANDIDATE = unknown>(
|
|
145
|
+
toCheck: any,
|
|
146
|
+
references: any[],
|
|
147
|
+
hint: string = undefined,
|
|
148
|
+
id: string | undefined = undefined,
|
|
149
|
+
): CANDIDATE {
|
|
135
150
|
const result = INSTANCE.checkAlgorithm(toCheck, ...references);
|
|
136
151
|
|
|
137
152
|
if (result === true) {
|
|
138
153
|
return toCheck;
|
|
139
154
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
155
|
+
throw new DBC.Infringement(
|
|
156
|
+
`${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
|
|
157
|
+
);
|
|
143
158
|
}
|
|
144
159
|
/**
|
|
145
160
|
* Creates this {@link INSTANCE } by setting the protected property {@link INSTANCE.reference } used by {@link INSTANCE.check }.
|
package/src/DBC/JSON.OP.ts
CHANGED
|
@@ -71,7 +71,12 @@ export class JSON_OP extends DBC {
|
|
|
71
71
|
methodName: string | symbol,
|
|
72
72
|
parameterIndex: number,
|
|
73
73
|
) => void {
|
|
74
|
-
return DBC.createPRE(
|
|
74
|
+
return DBC.createPRE(
|
|
75
|
+
JSON_OP.checkAlgorithm,
|
|
76
|
+
[necessaryProperties, checkElements],
|
|
77
|
+
dbc,
|
|
78
|
+
path,
|
|
79
|
+
);
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
77
82
|
* A method-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -92,7 +97,12 @@ export class JSON_OP extends DBC {
|
|
|
92
97
|
propertyKey: string,
|
|
93
98
|
descriptor: PropertyDescriptor,
|
|
94
99
|
) => PropertyDescriptor {
|
|
95
|
-
return DBC.createPOST(
|
|
100
|
+
return DBC.createPOST(
|
|
101
|
+
JSON_OP.checkAlgorithm,
|
|
102
|
+
[necessaryProperties, checkElements],
|
|
103
|
+
dbc,
|
|
104
|
+
path,
|
|
105
|
+
);
|
|
96
106
|
}
|
|
97
107
|
/**
|
|
98
108
|
* A field-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -109,7 +119,12 @@ export class JSON_OP extends DBC {
|
|
|
109
119
|
path: string | undefined = undefined,
|
|
110
120
|
dbc = "WaXCode.DBC",
|
|
111
121
|
) {
|
|
112
|
-
return DBC.createINVARIANT(
|
|
122
|
+
return DBC.createINVARIANT(
|
|
123
|
+
JSON_OP,
|
|
124
|
+
[necessaryProperties, checkElements],
|
|
125
|
+
dbc,
|
|
126
|
+
path,
|
|
127
|
+
);
|
|
113
128
|
}
|
|
114
129
|
// #endregion Condition checking.
|
|
115
130
|
// #region Referenced Condition checking.
|
package/src/DBC/JSON.Parse.ts
CHANGED
|
@@ -52,7 +52,13 @@ export class JSON_Parse extends DBC {
|
|
|
52
52
|
methodName: string | symbol,
|
|
53
53
|
parameterIndex: number,
|
|
54
54
|
) => void {
|
|
55
|
-
return DBC.createPRE(
|
|
55
|
+
return DBC.createPRE(
|
|
56
|
+
JSON_Parse.checkAlgorithm,
|
|
57
|
+
[receptor],
|
|
58
|
+
dbc,
|
|
59
|
+
path,
|
|
60
|
+
hint,
|
|
61
|
+
);
|
|
56
62
|
}
|
|
57
63
|
/**
|
|
58
64
|
* A method-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -73,7 +79,13 @@ export class JSON_Parse extends DBC {
|
|
|
73
79
|
propertyKey: string,
|
|
74
80
|
descriptor: PropertyDescriptor,
|
|
75
81
|
) => PropertyDescriptor {
|
|
76
|
-
return DBC.createPOST(
|
|
82
|
+
return DBC.createPOST(
|
|
83
|
+
JSON_Parse.checkAlgorithm,
|
|
84
|
+
[receptor],
|
|
85
|
+
dbc,
|
|
86
|
+
path,
|
|
87
|
+
hint,
|
|
88
|
+
);
|
|
77
89
|
}
|
|
78
90
|
/**
|
|
79
91
|
* A field-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -105,14 +117,19 @@ export class JSON_Parse extends DBC {
|
|
|
105
117
|
* @returns See {@link JSON_Parse.checkAlgorithm}. */
|
|
106
118
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
107
119
|
public check(toCheck: any) {
|
|
108
|
-
return JSON_Parse.checkAlgorithm(
|
|
120
|
+
return JSON_Parse.checkAlgorithm(
|
|
121
|
+
toCheck,
|
|
122
|
+
this.receptor as (json: object) => void,
|
|
123
|
+
);
|
|
109
124
|
}
|
|
110
125
|
/**
|
|
111
126
|
* Creates this {@link JSON_Parse } by setting the protected property {@link JSON_Parse.necessaryProperties } and {@link checkElements } used by {@link JSON_Parse.check }.
|
|
112
127
|
*
|
|
113
128
|
* @param necessaryProperties See {@link JSON_Parse.check }.
|
|
114
129
|
* @param checkElements See {@link JSON_Parse.check }. */
|
|
115
|
-
public constructor(
|
|
130
|
+
public constructor(
|
|
131
|
+
public receptor: ((json: object) => void) | undefined = undefined,
|
|
132
|
+
) {
|
|
116
133
|
super();
|
|
117
134
|
}
|
|
118
135
|
// #endregion Referenced Condition checking.
|
package/src/DBC/OR.ts
CHANGED
|
@@ -150,19 +150,24 @@ export class OR extends DBC {
|
|
|
150
150
|
* @param toCheck See {@link OR.checkAlgorithm }.
|
|
151
151
|
*
|
|
152
152
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link OR }.
|
|
153
|
-
*
|
|
153
|
+
*
|
|
154
154
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link OR }.*/
|
|
155
|
-
public static tsCheck<CANDIDATE>(
|
|
156
|
-
|
|
157
|
-
|
|
155
|
+
public static tsCheck<CANDIDATE>(
|
|
156
|
+
toCheck: unknown | undefined | null,
|
|
157
|
+
conditions: Array<{
|
|
158
|
+
check: (toCheck: unknown | undefined | null | object) => boolean | string;
|
|
159
|
+
}>,
|
|
160
|
+
hint: string = undefined,
|
|
161
|
+
id: string | undefined = undefined,
|
|
162
|
+
): CANDIDATE {
|
|
158
163
|
const result = OR.checkAlgorithm(conditions, toCheck);
|
|
159
164
|
|
|
160
165
|
if (result) {
|
|
161
166
|
return toCheck as CANDIDATE;
|
|
162
167
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
throw new DBC.Infringement(
|
|
169
|
+
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
170
|
+
);
|
|
166
171
|
}
|
|
167
172
|
/**
|
|
168
173
|
* Creates this {@link OR } by setting the protected property {@link OR.conditions } used by {@link OR.check }.
|
package/src/DBC/REGEX.ts
CHANGED
|
@@ -6,20 +6,22 @@ import { DBC } from "../DBC";
|
|
|
6
6
|
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
7
|
export class REGEX extends DBC {
|
|
8
8
|
/** Stores often used {@link RegExp }s. Patterns are compiled lazily on first access. */
|
|
9
|
-
private static _stdExp:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
private static _stdExp:
|
|
10
|
+
| {
|
|
11
|
+
htmlAttributeName: RegExp;
|
|
12
|
+
eMail: RegExp;
|
|
13
|
+
property: RegExp;
|
|
14
|
+
url: RegExp;
|
|
15
|
+
keyPath: RegExp;
|
|
16
|
+
date: RegExp;
|
|
17
|
+
dateFormat: RegExp;
|
|
18
|
+
cssSelector: RegExp;
|
|
19
|
+
boolean: RegExp;
|
|
20
|
+
colorCodeHEX: RegExp;
|
|
21
|
+
simpleHotkey: RegExp;
|
|
22
|
+
bcp47: RegExp;
|
|
23
|
+
}
|
|
24
|
+
| undefined;
|
|
23
25
|
|
|
24
26
|
public static get stdExp() {
|
|
25
27
|
if (!REGEX._stdExp) {
|
|
@@ -37,7 +39,8 @@ export class REGEX extends DBC {
|
|
|
37
39
|
boolean: /^(TRUE|FALSE)$/i,
|
|
38
40
|
colorCodeHEX: /^#([A-Fa-f\d]{3,4}|[A-Fa-f\d]{6}|[A-Fa-f\d]{8})$/i,
|
|
39
41
|
simpleHotkey: /^((Alt|Ctrl|Shift|Meta)\+)+[a-z\d]$/i,
|
|
40
|
-
bcp47:
|
|
42
|
+
bcp47:
|
|
43
|
+
/^(?:[a-z]{2,3}(?:-[a-z]{3}){0,3}|[a-z]{4}|[a-z]{5,8})(?:-[a-z]{4})?(?:-[a-z]{2}|-[0-9]{3})?(?:-[a-z0-9]{5,8}|-[0-9][a-z0-9]{3})*(?:-[0-9a-wy-z](?:-[a-z0-9]{2,8})+)*(?:-x(?:-[a-z0-9]{1,8})+)?$|^x(?:-[a-z0-9]{1,8})+$/i,
|
|
41
44
|
};
|
|
42
45
|
}
|
|
43
46
|
return REGEX._stdExp;
|
|
@@ -55,7 +58,8 @@ export class REGEX extends DBC {
|
|
|
55
58
|
toCheck: unknown | null | undefined,
|
|
56
59
|
expression: RegExp,
|
|
57
60
|
): boolean | string {
|
|
58
|
-
if (toCheck === undefined || toCheck === null || toCheck === "")
|
|
61
|
+
if (toCheck === undefined || toCheck === null || toCheck === "")
|
|
62
|
+
return true;
|
|
59
63
|
|
|
60
64
|
if (!expression.test(toCheck as string)) {
|
|
61
65
|
return `Value has to comply to regular expression "${expression}"`;
|
|
@@ -146,17 +150,22 @@ export class REGEX extends DBC {
|
|
|
146
150
|
* @param id Optional identifier to include in the error message.
|
|
147
151
|
*
|
|
148
152
|
* @returns The validated value cast to the CANDIDATE type.
|
|
149
|
-
*
|
|
153
|
+
*
|
|
150
154
|
* @throws {@link DBC.Infringement} if the value does not match the regular expression. */
|
|
151
|
-
public static tsCheck<CANDIDATE = unknown>(
|
|
155
|
+
public static tsCheck<CANDIDATE = unknown>(
|
|
156
|
+
toCheck: any,
|
|
157
|
+
expression: RegExp,
|
|
158
|
+
hint: string | undefined = undefined,
|
|
159
|
+
id: string | undefined = undefined,
|
|
160
|
+
): CANDIDATE {
|
|
152
161
|
const result = REGEX.checkAlgorithm(toCheck, expression);
|
|
153
162
|
|
|
154
163
|
if (result) {
|
|
155
164
|
return toCheck;
|
|
156
165
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
166
|
+
throw new DBC.Infringement(
|
|
167
|
+
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
168
|
+
);
|
|
160
169
|
}
|
|
161
170
|
/**
|
|
162
171
|
* Creates this {@link REGEX } by setting the protected property {@link REGEX.expression } used by {@link REGEX.check }.
|
package/src/DBC/TYPE.ts
CHANGED
|
@@ -17,12 +17,12 @@ export class TYPE extends DBC {
|
|
|
17
17
|
public static checkAlgorithm(toCheck: any, type: string): boolean | string {
|
|
18
18
|
if (toCheck === undefined || toCheck === null) return true;
|
|
19
19
|
|
|
20
|
-
const types = type.split("|").map(t => t.trim());
|
|
20
|
+
const types = type.split("|").map((t) => t.trim());
|
|
21
21
|
const actualType = typeof toCheck;
|
|
22
22
|
|
|
23
23
|
// #region Check if the actual type matches at least one of the specified types
|
|
24
24
|
// biome-ignore lint/suspicious/useValidTypeof: Necessary
|
|
25
|
-
const isValid = types.some(t => actualType === t);
|
|
25
|
+
const isValid = types.some((t) => actualType === t);
|
|
26
26
|
|
|
27
27
|
if (!isValid) {
|
|
28
28
|
if (types.length === 1) {
|
|
@@ -47,7 +47,7 @@ export class TYPE extends DBC {
|
|
|
47
47
|
type: string,
|
|
48
48
|
path: string | undefined = undefined,
|
|
49
49
|
hint: string | undefined = undefined,
|
|
50
|
-
dbc: string | undefined = undefined
|
|
50
|
+
dbc: string | undefined = undefined,
|
|
51
51
|
): (
|
|
52
52
|
target: object,
|
|
53
53
|
methodName: string | symbol,
|
|
@@ -70,7 +70,6 @@ export class TYPE extends DBC {
|
|
|
70
70
|
path: string | undefined = undefined,
|
|
71
71
|
hint: string | undefined = undefined,
|
|
72
72
|
dbc: string | undefined = undefined,
|
|
73
|
-
|
|
74
73
|
): (
|
|
75
74
|
target: object,
|
|
76
75
|
propertyKey: string,
|
|
@@ -113,24 +112,29 @@ export class TYPE extends DBC {
|
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
115
114
|
* Invokes the {@link TYPE.checkAlgorithm } passing the value **toCheck** and the {@link TYPE.type } .
|
|
116
|
-
*
|
|
115
|
+
*
|
|
117
116
|
* @param toCheck See {@link TYPE.checkAlgorithm }.
|
|
118
117
|
* @param type See {@link TYPE.checkAlgorithm }.
|
|
119
118
|
* @param hint An optional {@link string } providing extra information in case of an infringement.
|
|
120
119
|
* @param id A {@link string } identifying this {@link TYPE } via the {@link DBC.Infringement }-Message.
|
|
121
|
-
*
|
|
120
|
+
*
|
|
122
121
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link TYPE }.
|
|
123
|
-
*
|
|
122
|
+
*
|
|
124
123
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
|
|
125
|
-
public static tsCheck<CANDIDATE = unknown>(
|
|
124
|
+
public static tsCheck<CANDIDATE = unknown>(
|
|
125
|
+
toCheck: any,
|
|
126
|
+
type: string,
|
|
127
|
+
hint: string | undefined = undefined,
|
|
128
|
+
id: string | undefined = undefined,
|
|
129
|
+
): CANDIDATE {
|
|
126
130
|
const result = TYPE.checkAlgorithm(toCheck, type);
|
|
127
131
|
|
|
128
132
|
if (result === true) {
|
|
129
133
|
return toCheck;
|
|
130
134
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
throw new DBC.Infringement(
|
|
136
|
+
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
137
|
+
);
|
|
134
138
|
}
|
|
135
139
|
/**
|
|
136
140
|
* Creates this {@link TYPE } by setting the protected property {@link TYPE.type } used by {@link TYPE.check }.
|
package/src/DBC/UNDEFINED.ts
CHANGED
|
@@ -97,22 +97,19 @@ export class UNDEFINED extends DBC {
|
|
|
97
97
|
*
|
|
98
98
|
* @param toCheck See {@link UNDEFINED.checkAlgorithm }.
|
|
99
99
|
* @param id A {@link string } identifying this {@link INSTANCE } via the {@link DBC.Infringement }-Message.
|
|
100
|
-
*
|
|
100
|
+
*
|
|
101
101
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link UNDEFINED }.
|
|
102
|
-
*
|
|
102
|
+
*
|
|
103
103
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link UNDEFINED }.*/
|
|
104
|
-
public static tsCheck<CANDIDATE = unknown>(
|
|
104
|
+
public static tsCheck<CANDIDATE = unknown>(
|
|
105
|
+
toCheck: CANDIDATE | undefined | null,
|
|
106
|
+
id: string | undefined = undefined,
|
|
107
|
+
): CANDIDATE {
|
|
105
108
|
const result = UNDEFINED.checkAlgorithm(toCheck);
|
|
106
109
|
|
|
107
110
|
if (result === true) {
|
|
108
111
|
return toCheck as CANDIDATE;
|
|
109
112
|
}
|
|
110
|
-
|
|
111
|
-
throw new DBC.Infringement(`${id ? `(${id}) ` : ""}${result as string}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/** Creates this {@link UNDEFINED }. */
|
|
115
|
-
public constructor() {
|
|
116
|
-
super();
|
|
113
|
+
throw new DBC.Infringement(`${id ? `(${id}) ` : ""}${result as string}`);
|
|
117
114
|
}
|
|
118
115
|
}
|
package/src/DBC/ZOD.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
1
2
|
import { DBC } from "../DBC";
|
|
2
|
-
import { z } from 'zod';
|
|
3
3
|
/**
|
|
4
4
|
* A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link ZOD.schema }.
|
|
5
5
|
*
|
|
@@ -15,7 +15,10 @@ export class ZOD extends DBC {
|
|
|
15
15
|
*
|
|
16
16
|
* @returns TRUE if the value **toCheck** complies to the specified **schema**, otherwise FALSE. */
|
|
17
17
|
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
18
|
-
public static checkAlgorithm(
|
|
18
|
+
public static checkAlgorithm(
|
|
19
|
+
toCheck: any,
|
|
20
|
+
schema: z.ZodType,
|
|
21
|
+
): boolean | string {
|
|
19
22
|
const result = schema.safeParse(toCheck);
|
|
20
23
|
if (!result.success) {
|
|
21
24
|
return `Value does not comply to the specified schema. Received: "${JSON.stringify(toCheck)}". Errors: ${result.error.message}`;
|
|
@@ -99,23 +102,25 @@ export class ZOD extends DBC {
|
|
|
99
102
|
}
|
|
100
103
|
/**
|
|
101
104
|
* Invokes the {@link ZOD.checkAlgorithm } passing the value **toCheck** and the {@link ZOD.schema } .
|
|
102
|
-
*
|
|
105
|
+
*
|
|
103
106
|
* @param toCheck See {@link ZOD.checkAlgorithm }.
|
|
104
107
|
* @param schema See {@link ZOD.checkAlgorithm }.
|
|
105
108
|
* @param id A {@link string } identifying this {@link ZOD } via the {@link DBC.Infringement }-Message.
|
|
106
|
-
*
|
|
109
|
+
*
|
|
107
110
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link ZOD }.
|
|
108
|
-
*
|
|
111
|
+
*
|
|
109
112
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
|
|
110
|
-
public static tsCheck<CANDIDATE = unknown>(
|
|
113
|
+
public static tsCheck<CANDIDATE = unknown>(
|
|
114
|
+
toCheck: any,
|
|
115
|
+
schema: z.ZodType,
|
|
116
|
+
id: string | undefined = undefined,
|
|
117
|
+
): CANDIDATE {
|
|
111
118
|
const result = ZOD.checkAlgorithm(toCheck, schema);
|
|
112
119
|
|
|
113
120
|
if (result === true) {
|
|
114
121
|
return toCheck;
|
|
115
122
|
}
|
|
116
|
-
|
|
117
|
-
throw new DBC.Infringement(`${id ? `(${id}) ` : ""}${result as string}`);
|
|
118
|
-
}
|
|
123
|
+
throw new DBC.Infringement(`${id ? `(${id}) ` : ""}${result as string}`);
|
|
119
124
|
}
|
|
120
125
|
/**
|
|
121
126
|
* Creates this {@link ZOD } by setting the protected property {@link ZOD.schema } used by {@link ZOD.check }.
|