xdbc 1.0.119 → 1.0.121
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/dist/DBC/INSTANCE.js +5 -5
- package/dist/DBC/ZOD.js +112 -0
- package/package.json +1 -1
- package/src/DBC/ZOD.ts +2 -1
package/dist/DBC/INSTANCE.js
CHANGED
|
@@ -6,13 +6,13 @@ import { DBC } from "../DBC";
|
|
|
6
6
|
* Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
|
|
7
7
|
export class INSTANCE extends DBC {
|
|
8
8
|
/**
|
|
9
|
-
* Checks if the value **toCheck** is
|
|
9
|
+
* Checks if the value **toCheck** is an instance of the specified **reference**.
|
|
10
10
|
*
|
|
11
|
-
* @param toCheck The value that has
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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
14
|
*
|
|
15
|
-
* @returns TRUE if the value **toCheck** is of the
|
|
15
|
+
* @returns TRUE if the value **toCheck** is is an instance of the *reference**, otherwise FALSE. */
|
|
16
16
|
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
17
17
|
static checkAlgorithm(toCheck, reference) {
|
|
18
18
|
if (!(toCheck instanceof reference)) {
|
package/dist/DBC/ZOD.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
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 ZOD.schema }.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
|
|
7
|
+
export class ZOD extends DBC {
|
|
8
|
+
/**
|
|
9
|
+
* Checks if the value **toCheck** complies to the specified {@link z.ZodType }.
|
|
10
|
+
*
|
|
11
|
+
* @param toCheck The value that has to comply to the specified **schema** in order for this {@link DBC }
|
|
12
|
+
* @param schema The {@link z.ZodType } the {@link object } **toCheck** has comply to in order for this {@link DBC } to be
|
|
13
|
+
* fulfilled.
|
|
14
|
+
*
|
|
15
|
+
* @returns TRUE if the value **toCheck** complies to the specified **schema**, otherwise FALSE. */
|
|
16
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
17
|
+
static checkAlgorithm(toCheck, schema) {
|
|
18
|
+
if (!schema.safeParse(toCheck).success) {
|
|
19
|
+
return `Value has to correspond to "${JSON.stringify(schema.def)}" but is of type "${typeof toCheck}"`;
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A parameter-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
25
|
+
* by the tagged parameter.
|
|
26
|
+
*
|
|
27
|
+
* @param schema See {@link ZOD.checkAlgorithm }.
|
|
28
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
29
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
30
|
+
*
|
|
31
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
32
|
+
static PRE(
|
|
33
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
34
|
+
schema, path = undefined, dbc = "WaXCode.DBC") {
|
|
35
|
+
return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
|
|
36
|
+
return ZOD.checkAlgorithm(value, schema);
|
|
37
|
+
}, dbc, path);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A method-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
41
|
+
* by the tagged method's returnvalue.
|
|
42
|
+
*
|
|
43
|
+
* @param schema See {@link ZOD.checkAlgorithm }.
|
|
44
|
+
* @param path See {@link DBC.Postcondition }.
|
|
45
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
46
|
+
*
|
|
47
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
48
|
+
static POST(
|
|
49
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
50
|
+
schema, path = undefined, dbc = "WaXCode.DBC") {
|
|
51
|
+
return DBC.decPostcondition((value, target, propertyKey) => {
|
|
52
|
+
return ZOD.checkAlgorithm(value, schema);
|
|
53
|
+
}, dbc, path);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A field-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
57
|
+
* by the tagged method's returnvalue.
|
|
58
|
+
*
|
|
59
|
+
* @param schema See {@link ZOD.checkAlgorithm }.
|
|
60
|
+
* @param path See {@link DBC.decInvariant }.
|
|
61
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
62
|
+
*
|
|
63
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
64
|
+
static INVARIANT(
|
|
65
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
66
|
+
schema, path = undefined, dbc = "WaXCode.DBC") {
|
|
67
|
+
return DBC.decInvariant([new ZOD(schema)], path, dbc);
|
|
68
|
+
}
|
|
69
|
+
// #endregion Condition checking.
|
|
70
|
+
// #region Referenced Condition checking.
|
|
71
|
+
//
|
|
72
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
73
|
+
//
|
|
74
|
+
/**
|
|
75
|
+
* Invokes the {@link ZOD.checkAlgorithm } passing the value **toCheck** and the {@link ZOD.schema } .
|
|
76
|
+
*
|
|
77
|
+
* @param toCheck See {@link ZOD.checkAlgorithm }.
|
|
78
|
+
*
|
|
79
|
+
* @returns See {@link ZOD.checkAlgorithm}. */
|
|
80
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
81
|
+
check(toCheck) {
|
|
82
|
+
return ZOD.checkAlgorithm(toCheck, this.schema);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Invokes the {@link ZOD.checkAlgorithm } passing the value **toCheck** and the {@link ZOD.schema } .
|
|
86
|
+
*
|
|
87
|
+
* @param toCheck See {@link ZOD.checkAlgorithm }.
|
|
88
|
+
* @param schema See {@link ZOD.checkAlgorithm }.
|
|
89
|
+
* @param id A {@link string } identifying this {@link ZOD } via the {@link DBC.Infringement }-Message.
|
|
90
|
+
*
|
|
91
|
+
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link ZOD }.
|
|
92
|
+
*
|
|
93
|
+
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
|
|
94
|
+
static tsCheck(toCheck, schema, id = undefined) {
|
|
95
|
+
const result = ZOD.checkAlgorithm(toCheck, schema);
|
|
96
|
+
if (result === true) {
|
|
97
|
+
return toCheck;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
throw new DBC.Infringement(`${id ? `(${id}) ` : ""}${result}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates this {@link ZOD } by setting the protected property {@link ZOD.schema } used by {@link ZOD.check }.
|
|
105
|
+
*
|
|
106
|
+
* @param schema See {@link ZOD.check }. */
|
|
107
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
108
|
+
constructor(schema) {
|
|
109
|
+
super();
|
|
110
|
+
this.schema = schema;
|
|
111
|
+
}
|
|
112
|
+
}
|
package/package.json
CHANGED
package/src/DBC/ZOD.ts
CHANGED
|
@@ -17,7 +17,8 @@ export class ZOD extends DBC {
|
|
|
17
17
|
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
18
18
|
public static checkAlgorithm(toCheck: any, schema: z.ZodType): boolean | string {
|
|
19
19
|
if (!schema.safeParse(toCheck).success) {
|
|
20
|
-
|
|
20
|
+
console.log(schema)
|
|
21
|
+
return `Value has to correspond to "${JSON.stringify(schema.def)}" but is of type "${typeof toCheck}"`;
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
return true;
|