xdbc 1.0.215 → 1.0.217
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/README.md +2 -0
- package/__tests__/DBC/ARRAY.test.ts +91 -0
- package/__tests__/DBC/PLAIN_OBJECT.test.ts +109 -0
- package/dist/DBC/ARR/PLAIN_OBJECT.d.ts +67 -0
- package/dist/DBC/ARRAY.d.ts +66 -0
- package/dist/DBC/DEFINED.d.ts +1 -1
- package/dist/DBC/EQ.d.ts +1 -1
- package/dist/DBC/INSTANCE.d.ts +2 -2
- package/dist/DBC/JSON.OP.d.ts +1 -1
- package/dist/DBC/JSON.Parse.d.ts +1 -1
- package/dist/DBC/OR.d.ts +1 -1
- package/dist/DBC/REGEX.d.ts +2 -2
- package/dist/DBC/TYPE.d.ts +1 -1
- package/dist/DBC/UNDEFINED.d.ts +1 -1
- package/dist/DBC/ZOD.d.ts +1 -1
- package/dist/DBC.d.ts +9 -0
- package/dist/bundle.js +41 -14
- package/package.json +1 -1
- package/src/DBC/ARR/PLAIN_OBJECT.ts +133 -0
- package/src/DBC/ARRAY.ts +127 -0
- package/src/DBC/DEFINED.ts +4 -1
- package/src/DBC/EQ.ts +5 -2
- package/src/DBC/INSTANCE.ts +6 -2
- package/src/DBC/JSON.OP.ts +2 -1
- package/src/DBC/JSON.Parse.ts +2 -1
- package/src/DBC/OR.ts +4 -1
- package/src/DBC/REGEX.ts +6 -3
- package/src/DBC/TYPE.ts +4 -1
- package/src/DBC/UNDEFINED.ts +3 -1
- package/src/DBC/ZOD.ts +3 -1
- package/src/DBC.ts +27 -0
package/package.json
CHANGED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { DBC } from "../../DBC";
|
|
2
|
+
import { ARRAY } from "../ARRAY";
|
|
3
|
+
/**
|
|
4
|
+
* A {@link DBC } defining that a value must be a plain object — i.e. `typeof value === "object"`,
|
|
5
|
+
* not `null`, and not an array.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
|
|
9
|
+
export class PLAIN_OBJECT extends ARRAY {
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the value **toCheck** is a plain object (non-null, non-array object).
|
|
12
|
+
*
|
|
13
|
+
* @param toCheck The value to check.
|
|
14
|
+
*
|
|
15
|
+
* @returns TRUE if the value **toCheck** is a plain object, otherwise a string describing the infringement. */
|
|
16
|
+
// biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic type checking.
|
|
17
|
+
public static checkAlgorithm(toCheck: any): boolean | string {
|
|
18
|
+
if (toCheck === undefined || toCheck === null) return true;
|
|
19
|
+
|
|
20
|
+
if (typeof toCheck !== "object") {
|
|
21
|
+
return `Value has to be a PLAIN_OBJECT but is of type "${typeof toCheck}"`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(toCheck)) {
|
|
25
|
+
return "Value has to be a PLAIN_OBJECT but is an ARRAY";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A parameter-decorator factory using the {@link PLAIN_OBJECT.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
32
|
+
* by the tagged parameter.
|
|
33
|
+
*
|
|
34
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
35
|
+
* @param hint See {@link DBC.decPrecondition }.
|
|
36
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
37
|
+
*
|
|
38
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
39
|
+
public static PRE(
|
|
40
|
+
path: string | undefined = undefined,
|
|
41
|
+
hint: string | undefined = undefined,
|
|
42
|
+
dbc: string | undefined = undefined,
|
|
43
|
+
): (
|
|
44
|
+
target: object,
|
|
45
|
+
methodName: string | symbol | undefined,
|
|
46
|
+
parameterIndex: number,
|
|
47
|
+
) => void {
|
|
48
|
+
return DBC.createPRE(PLAIN_OBJECT.checkAlgorithm, [], dbc, path, hint);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* A method-decorator factory using the {@link PLAIN_OBJECT.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
52
|
+
* by the tagged method's returnvalue.
|
|
53
|
+
*
|
|
54
|
+
* @param path See {@link DBC.decPostcondition }.
|
|
55
|
+
* @param hint See {@link DBC.decPostcondition }.
|
|
56
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
57
|
+
*
|
|
58
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
59
|
+
public static POST(
|
|
60
|
+
path: string | undefined = undefined,
|
|
61
|
+
hint: string | undefined = undefined,
|
|
62
|
+
dbc: string | undefined = undefined,
|
|
63
|
+
): (
|
|
64
|
+
target: object,
|
|
65
|
+
propertyKey: string,
|
|
66
|
+
descriptor: PropertyDescriptor,
|
|
67
|
+
) => PropertyDescriptor {
|
|
68
|
+
return DBC.createPOST(PLAIN_OBJECT.checkAlgorithm, [], dbc, path, hint);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A field-decorator factory using the {@link PLAIN_OBJECT.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
72
|
+
* by the tagged field.
|
|
73
|
+
*
|
|
74
|
+
* @param path See {@link DBC.decInvariant }.
|
|
75
|
+
* @param hint See {@link DBC.decInvariant }.
|
|
76
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
77
|
+
*
|
|
78
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
79
|
+
public static INVARIANT(
|
|
80
|
+
path: string | undefined = undefined,
|
|
81
|
+
hint: string | undefined = undefined,
|
|
82
|
+
dbc: string | undefined = undefined,
|
|
83
|
+
) {
|
|
84
|
+
return DBC.createINVARIANT(PLAIN_OBJECT, [], dbc, path, hint);
|
|
85
|
+
}
|
|
86
|
+
// #endregion Condition checking.
|
|
87
|
+
// #region Referenced Condition checking.
|
|
88
|
+
//
|
|
89
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
90
|
+
//
|
|
91
|
+
/**
|
|
92
|
+
* Invokes the {@link PLAIN_OBJECT.checkAlgorithm } passing the value **toCheck**.
|
|
93
|
+
*
|
|
94
|
+
* @param toCheck See {@link PLAIN_OBJECT.checkAlgorithm }.
|
|
95
|
+
*
|
|
96
|
+
* @returns See {@link PLAIN_OBJECT.checkAlgorithm}. */
|
|
97
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
98
|
+
public check(toCheck: any) {
|
|
99
|
+
return PLAIN_OBJECT.checkAlgorithm(toCheck);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Invokes the {@link PLAIN_OBJECT.checkAlgorithm } passing the value **toCheck**.
|
|
103
|
+
*
|
|
104
|
+
* @param toCheck See {@link PLAIN_OBJECT.checkAlgorithm }.
|
|
105
|
+
* @param hint An optional {@link string } providing extra information in case of an infringement.
|
|
106
|
+
* @param id A {@link string } identifying this {@link PLAIN_OBJECT } via the {@link DBC.Infringement }-Message.
|
|
107
|
+
*
|
|
108
|
+
* @returns The **CANDIDATE** **toCheck** if this {@link PLAIN_OBJECT } is fulfilled.
|
|
109
|
+
*
|
|
110
|
+
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link PLAIN_OBJECT }. */
|
|
111
|
+
public static tsCheck<CANDIDATE extends object = object>(
|
|
112
|
+
toCheck: CANDIDATE | undefined | null,
|
|
113
|
+
hint: string | undefined = undefined,
|
|
114
|
+
id: string | undefined = undefined,
|
|
115
|
+
dbc: string | undefined = undefined,
|
|
116
|
+
): CANDIDATE {
|
|
117
|
+
const result = PLAIN_OBJECT.checkAlgorithm(toCheck);
|
|
118
|
+
|
|
119
|
+
if (result === true) {
|
|
120
|
+
return toCheck as CANDIDATE;
|
|
121
|
+
}
|
|
122
|
+
DBC.reportTsCheckInfringement(
|
|
123
|
+
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
124
|
+
dbc,
|
|
125
|
+
);
|
|
126
|
+
return toCheck as CANDIDATE;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates this {@link PLAIN_OBJECT } instance. No parameters needed — the check is always the same. */
|
|
130
|
+
public constructor() {
|
|
131
|
+
super();
|
|
132
|
+
}
|
|
133
|
+
}
|
package/src/DBC/ARRAY.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
// biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic type checking.
|
|
15
|
+
public static checkAlgorithm(toCheck: any): boolean | string {
|
|
16
|
+
if (toCheck === undefined || toCheck === null) return true;
|
|
17
|
+
|
|
18
|
+
if (!Array.isArray(toCheck)) {
|
|
19
|
+
return `Value has to be an ARRAY but is of type "${typeof toCheck}"`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A parameter-decorator factory using the {@link ARRAY.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
26
|
+
* by the tagged parameter.
|
|
27
|
+
*
|
|
28
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
29
|
+
* @param hint See {@link DBC.decPrecondition }.
|
|
30
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
31
|
+
*
|
|
32
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
33
|
+
public static PRE(
|
|
34
|
+
path: string | undefined = undefined,
|
|
35
|
+
hint: string | undefined = undefined,
|
|
36
|
+
dbc: string | undefined = undefined,
|
|
37
|
+
): (
|
|
38
|
+
target: object,
|
|
39
|
+
methodName: string | symbol | undefined,
|
|
40
|
+
parameterIndex: number,
|
|
41
|
+
) => void {
|
|
42
|
+
return DBC.createPRE(ARRAY.checkAlgorithm, [], dbc, path, hint);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A method-decorator factory using the {@link ARRAY.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
46
|
+
* by the tagged method's returnvalue.
|
|
47
|
+
*
|
|
48
|
+
* @param path See {@link DBC.decPostcondition }.
|
|
49
|
+
* @param hint See {@link DBC.decPostcondition }.
|
|
50
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
51
|
+
*
|
|
52
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
53
|
+
public static POST(
|
|
54
|
+
path: string | undefined = undefined,
|
|
55
|
+
hint: string | undefined = undefined,
|
|
56
|
+
dbc: string | undefined = undefined,
|
|
57
|
+
): (
|
|
58
|
+
target: object,
|
|
59
|
+
propertyKey: string,
|
|
60
|
+
descriptor: PropertyDescriptor,
|
|
61
|
+
) => PropertyDescriptor {
|
|
62
|
+
return DBC.createPOST(ARRAY.checkAlgorithm, [], dbc, path, hint);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A field-decorator factory using the {@link ARRAY.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
66
|
+
* by the tagged field.
|
|
67
|
+
*
|
|
68
|
+
* @param path See {@link DBC.decInvariant }.
|
|
69
|
+
* @param hint See {@link DBC.decInvariant }.
|
|
70
|
+
* @param dbc See {@link DBC.decInvariant }.
|
|
71
|
+
*
|
|
72
|
+
* @returns See {@link DBC.decInvariant }. */
|
|
73
|
+
public static INVARIANT(
|
|
74
|
+
path: string | undefined = undefined,
|
|
75
|
+
hint: string | undefined = undefined,
|
|
76
|
+
dbc: string | undefined = undefined,
|
|
77
|
+
) {
|
|
78
|
+
return DBC.createINVARIANT(ARRAY, [], dbc, path, hint);
|
|
79
|
+
}
|
|
80
|
+
// #endregion Condition checking.
|
|
81
|
+
// #region Referenced Condition checking.
|
|
82
|
+
//
|
|
83
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
84
|
+
//
|
|
85
|
+
/**
|
|
86
|
+
* Invokes the {@link ARRAY.checkAlgorithm } passing the value **toCheck**.
|
|
87
|
+
*
|
|
88
|
+
* @param toCheck See {@link ARRAY.checkAlgorithm }.
|
|
89
|
+
*
|
|
90
|
+
* @returns See {@link ARRAY.checkAlgorithm}. */
|
|
91
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
92
|
+
public check(toCheck: any) {
|
|
93
|
+
return ARRAY.checkAlgorithm(toCheck);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Invokes the {@link ARRAY.checkAlgorithm } passing the value **toCheck**.
|
|
97
|
+
*
|
|
98
|
+
* @param toCheck See {@link ARRAY.checkAlgorithm }.
|
|
99
|
+
* @param hint An optional {@link string } providing extra information in case of an infringement.
|
|
100
|
+
* @param id A {@link string } identifying this {@link ARRAY } via the {@link DBC.Infringement }-Message.
|
|
101
|
+
*
|
|
102
|
+
* @returns The **CANDIDATE** **toCheck** if this {@link ARRAY } is fulfilled.
|
|
103
|
+
*
|
|
104
|
+
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link ARRAY }. */
|
|
105
|
+
public static tsCheck<CANDIDATE extends unknown[] = unknown[]>(
|
|
106
|
+
toCheck: CANDIDATE | undefined | null,
|
|
107
|
+
hint: string | undefined = undefined,
|
|
108
|
+
id: string | undefined = undefined,
|
|
109
|
+
dbc: string | undefined = undefined,
|
|
110
|
+
): CANDIDATE {
|
|
111
|
+
const result = ARRAY.checkAlgorithm(toCheck);
|
|
112
|
+
|
|
113
|
+
if (result === true) {
|
|
114
|
+
return toCheck as CANDIDATE;
|
|
115
|
+
}
|
|
116
|
+
DBC.reportTsCheckInfringement(
|
|
117
|
+
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
118
|
+
dbc,
|
|
119
|
+
);
|
|
120
|
+
return toCheck as CANDIDATE;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Creates this {@link ARRAY } instance. No parameters needed — the check is always {@link Array.isArray }. */
|
|
124
|
+
public constructor() {
|
|
125
|
+
super();
|
|
126
|
+
}
|
|
127
|
+
}
|
package/src/DBC/DEFINED.ts
CHANGED
|
@@ -106,14 +106,17 @@ export class DEFINED extends DBC {
|
|
|
106
106
|
toCheck: CANDIDATE | undefined | null,
|
|
107
107
|
hint: string | undefined = undefined,
|
|
108
108
|
id: string | undefined = undefined,
|
|
109
|
+
dbc: string | undefined = undefined,
|
|
109
110
|
): CANDIDATE {
|
|
110
111
|
const result = DEFINED.checkAlgorithm(toCheck);
|
|
111
112
|
|
|
112
113
|
if (result === true) {
|
|
113
114
|
return toCheck as CANDIDATE;
|
|
114
115
|
}
|
|
115
|
-
|
|
116
|
+
DBC.reportTsCheckInfringement(
|
|
116
117
|
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
118
|
+
dbc,
|
|
117
119
|
);
|
|
120
|
+
return toCheck as CANDIDATE;
|
|
118
121
|
}
|
|
119
122
|
}
|
package/src/DBC/EQ.ts
CHANGED
|
@@ -135,15 +135,18 @@ export class EQ extends DBC {
|
|
|
135
135
|
equivalent: any,
|
|
136
136
|
hint: string | undefined = undefined,
|
|
137
137
|
id: string | undefined = undefined,
|
|
138
|
+
dbc: string | undefined = undefined,
|
|
138
139
|
): CANDIDATE {
|
|
139
140
|
const result = EQ.checkAlgorithm(toCheck, equivalent, false);
|
|
140
141
|
|
|
141
|
-
if (result) {
|
|
142
|
+
if (result === true) {
|
|
142
143
|
return toCheck as CANDIDATE;
|
|
143
144
|
}
|
|
144
|
-
|
|
145
|
+
DBC.reportTsCheckInfringement(
|
|
145
146
|
`${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
|
|
147
|
+
dbc,
|
|
146
148
|
);
|
|
149
|
+
return toCheck as CANDIDATE;
|
|
147
150
|
}
|
|
148
151
|
/**
|
|
149
152
|
* Creates this {@link EQ } by setting the protected property {@link EQ.equivalent } used by {@link EQ.check }.
|
package/src/DBC/INSTANCE.ts
CHANGED
|
@@ -127,8 +127,9 @@ export class INSTANCE extends DBC {
|
|
|
127
127
|
reference: any,
|
|
128
128
|
hint: string = undefined,
|
|
129
129
|
id: string | undefined = undefined,
|
|
130
|
+
dbc: string | undefined = undefined,
|
|
130
131
|
): CANDIDATE {
|
|
131
|
-
return INSTANCE.tsCheckMulti<CANDIDATE>(toCheck, [reference], hint, id);
|
|
132
|
+
return INSTANCE.tsCheckMulti<CANDIDATE>(toCheck, [reference], hint, id, dbc);
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
134
135
|
* Invokes the {@link INSTANCE.checkAlgorithm } passing the value **toCheck** and the {@link INSTANCE.reference } .
|
|
@@ -146,15 +147,18 @@ export class INSTANCE extends DBC {
|
|
|
146
147
|
references: any[],
|
|
147
148
|
hint: string = undefined,
|
|
148
149
|
id: string | undefined = undefined,
|
|
150
|
+
dbc: string | undefined = undefined,
|
|
149
151
|
): CANDIDATE {
|
|
150
152
|
const result = INSTANCE.checkAlgorithm(toCheck, ...references);
|
|
151
153
|
|
|
152
154
|
if (result === true) {
|
|
153
155
|
return toCheck;
|
|
154
156
|
}
|
|
155
|
-
|
|
157
|
+
DBC.reportTsCheckInfringement(
|
|
156
158
|
`${id ? `(${id}) ` : ""}${result as string} ${hint ? `✨ ${hint} ✨` : ""}`,
|
|
159
|
+
dbc,
|
|
157
160
|
);
|
|
161
|
+
return toCheck as CANDIDATE;
|
|
158
162
|
}
|
|
159
163
|
/**
|
|
160
164
|
* Creates this {@link INSTANCE } by setting the protected property {@link INSTANCE.reference } used by {@link INSTANCE.check }.
|
package/src/DBC/JSON.OP.ts
CHANGED
|
@@ -170,6 +170,7 @@ export class JSON_OP extends DBC {
|
|
|
170
170
|
toCheck: any,
|
|
171
171
|
necessaryProperties: Array<{ name: string; type: string }>,
|
|
172
172
|
checkElements = false,
|
|
173
|
+
dbc: string | undefined = undefined,
|
|
173
174
|
) {
|
|
174
175
|
const checkResult = JSON_OP.checkAlgorithm(
|
|
175
176
|
toCheck,
|
|
@@ -178,7 +179,7 @@ export class JSON_OP extends DBC {
|
|
|
178
179
|
);
|
|
179
180
|
|
|
180
181
|
if (typeof checkResult === "string") {
|
|
181
|
-
|
|
182
|
+
DBC.reportTsCheckInfringement(checkResult, dbc);
|
|
182
183
|
}
|
|
183
184
|
}
|
|
184
185
|
// #endregion In-Method checking.
|
package/src/DBC/JSON.Parse.ts
CHANGED
|
@@ -145,11 +145,12 @@ export class JSON_Parse extends DBC {
|
|
|
145
145
|
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
146
146
|
toCheck: any,
|
|
147
147
|
receptor: (json: object) => void,
|
|
148
|
+
dbc: string | undefined = undefined,
|
|
148
149
|
) {
|
|
149
150
|
const checkResult = JSON_Parse.checkAlgorithm(toCheck, receptor);
|
|
150
151
|
|
|
151
152
|
if (typeof checkResult === "string") {
|
|
152
|
-
|
|
153
|
+
DBC.reportTsCheckInfringement(checkResult, dbc);
|
|
153
154
|
}
|
|
154
155
|
}
|
|
155
156
|
// #endregion In-Method checking.
|
package/src/DBC/OR.ts
CHANGED
|
@@ -159,15 +159,18 @@ export class OR extends DBC {
|
|
|
159
159
|
}>,
|
|
160
160
|
hint: string = undefined,
|
|
161
161
|
id: string | undefined = undefined,
|
|
162
|
+
dbc: string | undefined = undefined,
|
|
162
163
|
): CANDIDATE {
|
|
163
164
|
const result = OR.checkAlgorithm(conditions, toCheck);
|
|
164
165
|
|
|
165
166
|
if (result === true) {
|
|
166
167
|
return toCheck as CANDIDATE;
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
+
DBC.reportTsCheckInfringement(
|
|
169
170
|
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
171
|
+
dbc,
|
|
170
172
|
);
|
|
173
|
+
return toCheck as CANDIDATE;
|
|
171
174
|
}
|
|
172
175
|
/**
|
|
173
176
|
* Creates this {@link OR } by setting the protected property {@link OR.conditions } used by {@link OR.check }.
|
package/src/DBC/REGEX.ts
CHANGED
|
@@ -157,15 +157,18 @@ export class REGEX extends DBC {
|
|
|
157
157
|
expression: RegExp,
|
|
158
158
|
hint: string | undefined = undefined,
|
|
159
159
|
id: string | undefined = undefined,
|
|
160
|
+
dbc: string | undefined = undefined,
|
|
160
161
|
): CANDIDATE {
|
|
161
162
|
const result = REGEX.checkAlgorithm(toCheck, expression);
|
|
162
163
|
|
|
163
164
|
if (result === true) {
|
|
164
165
|
return toCheck;
|
|
165
166
|
}
|
|
166
|
-
|
|
167
|
+
DBC.reportTsCheckInfringement(
|
|
167
168
|
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
169
|
+
dbc,
|
|
168
170
|
);
|
|
171
|
+
return toCheck as CANDIDATE;
|
|
169
172
|
}
|
|
170
173
|
/**
|
|
171
174
|
* Creates this {@link REGEX } by setting the protected property {@link REGEX.expression } used by {@link REGEX.check }.
|
|
@@ -182,11 +185,11 @@ export class REGEX extends DBC {
|
|
|
182
185
|
* @param toCheck See {@link REGEX.checkAlgorithm}.
|
|
183
186
|
* @param expression See {@link REGEX.checkAlgorithm}.
|
|
184
187
|
*/
|
|
185
|
-
public static check(toCheck: unknown | null | undefined, expression: RegExp) {
|
|
188
|
+
public static check(toCheck: unknown | null | undefined, expression: RegExp, dbc: string | undefined = undefined) {
|
|
186
189
|
const checkResult = REGEX.checkAlgorithm(toCheck, expression);
|
|
187
190
|
|
|
188
191
|
if (typeof checkResult === "string") {
|
|
189
|
-
|
|
192
|
+
DBC.reportTsCheckInfringement(checkResult, dbc);
|
|
190
193
|
}
|
|
191
194
|
}
|
|
192
195
|
// #endregion In-Method checking.
|
package/src/DBC/TYPE.ts
CHANGED
|
@@ -126,15 +126,18 @@ export class TYPE extends DBC {
|
|
|
126
126
|
type: string,
|
|
127
127
|
hint: string | undefined = undefined,
|
|
128
128
|
id: string | undefined = undefined,
|
|
129
|
+
dbc: string | undefined = undefined,
|
|
129
130
|
): CANDIDATE {
|
|
130
131
|
const result = TYPE.checkAlgorithm(toCheck, type);
|
|
131
132
|
|
|
132
133
|
if (result === true) {
|
|
133
134
|
return toCheck;
|
|
134
135
|
}
|
|
135
|
-
|
|
136
|
+
DBC.reportTsCheckInfringement(
|
|
136
137
|
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
138
|
+
dbc,
|
|
137
139
|
);
|
|
140
|
+
return toCheck as CANDIDATE;
|
|
138
141
|
}
|
|
139
142
|
/**
|
|
140
143
|
* Creates this {@link TYPE } by setting the protected property {@link TYPE.type } used by {@link TYPE.check }.
|
package/src/DBC/UNDEFINED.ts
CHANGED
|
@@ -104,12 +104,14 @@ export class UNDEFINED extends DBC {
|
|
|
104
104
|
public static tsCheck<CANDIDATE = unknown>(
|
|
105
105
|
toCheck: CANDIDATE | undefined | null,
|
|
106
106
|
id: string | undefined = undefined,
|
|
107
|
+
dbc: string | undefined = undefined,
|
|
107
108
|
): CANDIDATE {
|
|
108
109
|
const result = UNDEFINED.checkAlgorithm(toCheck);
|
|
109
110
|
|
|
110
111
|
if (result === true) {
|
|
111
112
|
return toCheck as CANDIDATE;
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
+
DBC.reportTsCheckInfringement(`${id ? `(${id}) ` : ""}${result as string}`, dbc);
|
|
115
|
+
return toCheck as CANDIDATE;
|
|
114
116
|
}
|
|
115
117
|
}
|
package/src/DBC/ZOD.ts
CHANGED
|
@@ -114,13 +114,15 @@ export class ZOD extends DBC {
|
|
|
114
114
|
toCheck: any,
|
|
115
115
|
schema: z.ZodType,
|
|
116
116
|
id: string | undefined = undefined,
|
|
117
|
+
dbc: string | undefined = undefined,
|
|
117
118
|
): CANDIDATE {
|
|
118
119
|
const result = ZOD.checkAlgorithm(toCheck, schema);
|
|
119
120
|
|
|
120
121
|
if (result === true) {
|
|
121
122
|
return toCheck;
|
|
122
123
|
}
|
|
123
|
-
|
|
124
|
+
DBC.reportTsCheckInfringement(`${id ? `(${id}) ` : ""}${result as string}`, dbc);
|
|
125
|
+
return toCheck as CANDIDATE;
|
|
124
126
|
}
|
|
125
127
|
/**
|
|
126
128
|
* Creates this {@link ZOD } by setting the protected property {@link ZOD.schema } used by {@link ZOD.check }.
|
package/src/DBC.ts
CHANGED
|
@@ -697,6 +697,33 @@ export class DBC {
|
|
|
697
697
|
hint,
|
|
698
698
|
);
|
|
699
699
|
}
|
|
700
|
+
/**
|
|
701
|
+
* Routes an imperative infringement (from {@link tsCheck } or static {@link check } calls) through the
|
|
702
|
+
* registered DBC instance's {@link infringementSettings }, respecting whether to throw, log, or both.
|
|
703
|
+
* Falls back to throwing {@link DBC.Infringement } directly if no DBC instance is registered at the
|
|
704
|
+
* specified path, preserving the pre-existing behaviour for code that does not register a DBC instance.
|
|
705
|
+
*
|
|
706
|
+
* @param message The fully formatted infringement message.
|
|
707
|
+
* @param dbc The path to the DBC instance. Defaults to `"WaXCode.DBC"`. */
|
|
708
|
+
public static reportTsCheckInfringement(
|
|
709
|
+
message: string,
|
|
710
|
+
dbc: string | undefined = undefined,
|
|
711
|
+
): void {
|
|
712
|
+
let dbcInstance: DBC | undefined;
|
|
713
|
+
try {
|
|
714
|
+
dbcInstance = DBC.getDBC(dbc);
|
|
715
|
+
} catch {
|
|
716
|
+
throw new DBC.Infringement(message);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (dbcInstance.infringementSettings.throwException) {
|
|
720
|
+
throw new DBC.Infringement(message);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (dbcInstance.infringementSettings.logToConsole) {
|
|
724
|
+
console.log(message);
|
|
725
|
+
}
|
|
726
|
+
}
|
|
700
727
|
// #region Classes
|
|
701
728
|
// #region Errors
|
|
702
729
|
/** An {@link Error } to be thrown whenever an infringement is detected. */
|