xdbc 1.0.216 → 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/dist/DBC/ARR/PLAIN_OBJECT.d.ts +1 -1
- package/dist/DBC/ARRAY.d.ts +1 -1
- 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 +4 -1
- package/src/DBC/ARRAY.ts +4 -1
- 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
|
@@ -112,15 +112,18 @@ export class PLAIN_OBJECT extends ARRAY {
|
|
|
112
112
|
toCheck: CANDIDATE | undefined | null,
|
|
113
113
|
hint: string | undefined = undefined,
|
|
114
114
|
id: string | undefined = undefined,
|
|
115
|
+
dbc: string | undefined = undefined,
|
|
115
116
|
): CANDIDATE {
|
|
116
117
|
const result = PLAIN_OBJECT.checkAlgorithm(toCheck);
|
|
117
118
|
|
|
118
119
|
if (result === true) {
|
|
119
120
|
return toCheck as CANDIDATE;
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
+
DBC.reportTsCheckInfringement(
|
|
122
123
|
`${id ? `(${id}) ` : ""}${result as string}${hint ? ` ✨ ${hint} ✨` : ""}`,
|
|
124
|
+
dbc,
|
|
123
125
|
);
|
|
126
|
+
return toCheck as CANDIDATE;
|
|
124
127
|
}
|
|
125
128
|
/**
|
|
126
129
|
* Creates this {@link PLAIN_OBJECT } instance. No parameters needed — the check is always the same. */
|
package/src/DBC/ARRAY.ts
CHANGED
|
@@ -106,15 +106,18 @@ export class ARRAY 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 = ARRAY.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
|
/**
|
|
120
123
|
* Creates this {@link ARRAY } instance. No parameters needed — the check is always {@link Array.isArray }. */
|
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. */
|