xdbc 1.0.207 → 1.0.209
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/Assessment.html +350 -0
- package/Assessment.md +507 -51
- package/CHANGELOG.md +55 -0
- package/CONTRIBUTING.md +129 -17
- package/README.md +373 -71
- package/SECURITY.md +60 -18
- package/SUPPORT.md +65 -0
- package/__tests__/DBC/DEFINED.test.ts +53 -0
- package/__tests__/DBC/Decorators.test.ts +365 -0
- package/__tests__/DBC/GREATER.test.ts +8 -6
- package/__tests__/DBC/HasAttribute.test.ts +56 -0
- package/__tests__/DBC/IF.test.ts +52 -0
- package/__tests__/DBC/JSON.Parse.test.ts +1 -1
- package/__tests__/DBC/OR.test.ts +1 -1
- package/__tests__/DBC/REGEX.test.ts +1 -1
- package/__tests__/DBC/TYPE.test.ts +1 -1
- package/__tests__/DBC/UNDEFINED.test.ts +45 -0
- package/__tests__/DBC/ZOD.test.ts +54 -0
- package/jest.config.js +21 -0
- package/package.json +4 -5
- package/src/DBC/AE.ts +10 -6
- package/src/DBC/COMPARISON/GREATER.ts +11 -7
- package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +14 -10
- package/src/DBC/COMPARISON/LESS.ts +14 -10
- package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +14 -10
- package/src/DBC/COMPARISON.ts +20 -43
- package/src/DBC/DEFINED.ts +4 -23
- package/src/DBC/EQ/DIFFERENT.ts +21 -56
- package/src/DBC/EQ.ts +7 -26
- package/src/DBC/HasAttribute.ts +9 -26
- package/src/DBC/IF.ts +8 -27
- package/src/DBC/INSTANCE.ts +5 -22
- package/src/DBC/JSON.OP.ts +4 -34
- package/src/DBC/JSON.Parse.ts +5 -25
- package/src/DBC/OR.ts +5 -14
- package/src/DBC/REGEX.ts +41 -40
- package/src/DBC/TYPE.ts +6 -25
- package/src/DBC/UNDEFINED.ts +3 -22
- package/src/DBC/ZOD.ts +10 -27
- package/src/DBC.ts +223 -55
- package/tsconfig.json +7 -4
- package/tsconfig.test.json +12 -0
- package/.parcel-cache/bf96c58b6061a62a-BundleGraph +0 -0
- package/.parcel-cache/d7c812d65aeeac59-AssetGraph +0 -0
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/e81759c1f106a17f-RequestGraph +0 -0
- package/.parcel-cache/fe0db3c4eb428be2-AssetGraph +0 -0
- package/.parcel-cache/lock.mdb +0 -0
- package/.parcel-cache/snapshot-e81759c1f106a17f.txt +0 -4609
- package/dist/DBC/AE.js +0 -173
- package/dist/DBC/COMPARISON/GREATER.js +0 -21
- package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +0 -21
- package/dist/DBC/COMPARISON/LESS.js +0 -21
- package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +0 -21
- package/dist/DBC/COMPARISON.js +0 -99
- package/dist/DBC/DEFINED.js +0 -99
- package/dist/DBC/EQ/DIFFERENT.js +0 -21
- package/dist/DBC/EQ.js +0 -100
- package/dist/DBC/GREATER.js +0 -99
- package/dist/DBC/HasAttribute.js +0 -108
- package/dist/DBC/IF.js +0 -99
- package/dist/DBC/INSTANCE.js +0 -93
- package/dist/DBC/JSON.OP.js +0 -133
- package/dist/DBC/JSON.Parse.js +0 -114
- package/dist/DBC/OR.js +0 -113
- package/dist/DBC/REGEX.js +0 -110
- package/dist/DBC/TYPE.js +0 -87
- package/dist/DBC/ZOD.js +0 -114
- package/dist/DBC.js +0 -336
- package/dist/Demo.js +0 -290
- package/dist/Test.html +0 -18
- package/dist/bundle.js +0 -2064
- package/dist/index.html +0 -18
- package/jest.config.ts +0 -20
- package/xpackage-lock.json +0 -122
package/src/DBC/REGEX.ts
CHANGED
|
@@ -5,23 +5,43 @@ import { DBC } from "../DBC";
|
|
|
5
5
|
* @remarks
|
|
6
6
|
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
7
|
export class REGEX extends DBC {
|
|
8
|
-
/** Stores often used {@link RegExp }s. */
|
|
9
|
-
|
|
10
|
-
htmlAttributeName:
|
|
11
|
-
eMail:
|
|
12
|
-
property:
|
|
13
|
-
url:
|
|
14
|
-
keyPath:
|
|
15
|
-
date:
|
|
16
|
-
dateFormat:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
8
|
+
/** Stores often used {@link RegExp }s. Patterns are compiled lazily on first access. */
|
|
9
|
+
private static _stdExp: {
|
|
10
|
+
htmlAttributeName: RegExp;
|
|
11
|
+
eMail: RegExp;
|
|
12
|
+
property: RegExp;
|
|
13
|
+
url: RegExp;
|
|
14
|
+
keyPath: RegExp;
|
|
15
|
+
date: RegExp;
|
|
16
|
+
dateFormat: RegExp;
|
|
17
|
+
cssSelector: RegExp;
|
|
18
|
+
boolean: RegExp;
|
|
19
|
+
colorCodeHEX: RegExp;
|
|
20
|
+
simpleHotkey: RegExp;
|
|
21
|
+
bcp47: RegExp;
|
|
22
|
+
} | undefined;
|
|
23
|
+
|
|
24
|
+
public static get stdExp() {
|
|
25
|
+
if (!REGEX._stdExp) {
|
|
26
|
+
REGEX._stdExp = {
|
|
27
|
+
htmlAttributeName: /^[a-zA-Z_:][a-zA-Z0-9_.:-]*$/,
|
|
28
|
+
eMail: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i,
|
|
29
|
+
property: /^[$_A-Za-z][$_A-Za-z0-9]*$/,
|
|
30
|
+
url: /^(?:https?|ftp):\/\/[^\s/$.?#].[^\s]*$/i,
|
|
31
|
+
keyPath: /^([a-zA-Z_$][a-zA-Z0-9_$]*\.)*[a-zA-Z_$][a-zA-Z0-9_$]*$/,
|
|
32
|
+
date: /^\d{1,4}[.\/-]\d{1,2}[.\/-]\d{1,4}$/i,
|
|
33
|
+
dateFormat:
|
|
34
|
+
/^((D{1,2}[./-]M{1,2}[./-]Y{1,4})|(M{1,2}[./-]D{1,2}[./-]Y{1,4})|Y{1,4}[./-]D{1,2}[./-]M{1,2}|(Y{1,4}[./-]M{1,2}[./-]D{1,2}))$/i,
|
|
35
|
+
cssSelector:
|
|
36
|
+
/^(?:\*|#[\w-]+|\.[\w-]+|(?:[\w-]+|\*)(?::(?:[\w-]+(?:\([\w-]+\))?)+)?(?:\[(?:[\w-]+(?:(?:=|~=|\|=|\*=|\$=|\^=)\s*(?:"[^"]*"|'[^']*'|[\w-]+)\s*)?)?\])+|\[\s*[\w-]+\s*=\s*(?:"[^"]*"|'[^']*'|[\w-]+)\s*\])(?:,\s*(?:\*|#[\w-]+|\.[\w-]+|(?:[\w-]+|\*)(?::(?:[\w-]+(?:\([\w-]+\))?)+)?(?:\[(?:[\w-]+(?:(?:=|~=|\|=|\*=|\$=|\^=)\s*(?:"[^"]*"|'[^']*'|[\w-]+)\s*)?)?\])+|\[\s*[\w-]+\s*=\s*(?:"[^"]*"|'[^']*'|[\w-]+)\s*\]))*$/,
|
|
37
|
+
boolean: /^(TRUE|FALSE)$/i,
|
|
38
|
+
colorCodeHEX: /^#([A-Fa-f\d]{3,4}|[A-Fa-f\d]{6}|[A-Fa-f\d]{8})$/i,
|
|
39
|
+
simpleHotkey: /^((Alt|Ctrl|Shift|Meta)\+)+[a-z\d]$/i,
|
|
40
|
+
bcp47: /^(?:[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
|
+
};
|
|
42
|
+
}
|
|
43
|
+
return REGEX._stdExp;
|
|
44
|
+
}
|
|
25
45
|
// #region Condition checking.
|
|
26
46
|
/**
|
|
27
47
|
* Checks if the value **toCheck** is complies to the {@link RegExp } **expression**.
|
|
@@ -62,19 +82,7 @@ export class REGEX extends DBC {
|
|
|
62
82
|
methodName: string | symbol,
|
|
63
83
|
parameterIndex: number,
|
|
64
84
|
) => void {
|
|
65
|
-
return DBC.
|
|
66
|
-
(
|
|
67
|
-
value: string,
|
|
68
|
-
target: object,
|
|
69
|
-
methodName: string,
|
|
70
|
-
parameterIndex: number,
|
|
71
|
-
) => {
|
|
72
|
-
return REGEX.checkAlgorithm(value, expression);
|
|
73
|
-
},
|
|
74
|
-
dbc,
|
|
75
|
-
path,
|
|
76
|
-
hint
|
|
77
|
-
);
|
|
85
|
+
return DBC.createPRE(REGEX.checkAlgorithm, [expression], dbc, path, hint);
|
|
78
86
|
}
|
|
79
87
|
/**
|
|
80
88
|
* A method-decorator factory using the {@link REGEX.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -96,14 +104,7 @@ export class REGEX extends DBC {
|
|
|
96
104
|
propertyKey: string,
|
|
97
105
|
descriptor: PropertyDescriptor,
|
|
98
106
|
) => PropertyDescriptor {
|
|
99
|
-
return DBC.
|
|
100
|
-
(value: string, target: object, propertyKey: string) => {
|
|
101
|
-
return REGEX.checkAlgorithm(value, expression);
|
|
102
|
-
},
|
|
103
|
-
dbc,
|
|
104
|
-
path,
|
|
105
|
-
hint
|
|
106
|
-
);
|
|
107
|
+
return DBC.createPOST(REGEX.checkAlgorithm, [expression], dbc, path, hint);
|
|
107
108
|
}
|
|
108
109
|
/**
|
|
109
110
|
* A field-decorator factory using the {@link REGEX.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -120,7 +121,7 @@ export class REGEX extends DBC {
|
|
|
120
121
|
hint: string | undefined = undefined,
|
|
121
122
|
dbc: string | undefined = undefined,
|
|
122
123
|
) {
|
|
123
|
-
return DBC.
|
|
124
|
+
return DBC.createINVARIANT(REGEX, [expression], dbc, path, hint);
|
|
124
125
|
}
|
|
125
126
|
// #endregion Condition checking.
|
|
126
127
|
// #region Referenced Condition checking.
|
|
@@ -147,7 +148,7 @@ export class REGEX extends DBC {
|
|
|
147
148
|
* @returns The validated value cast to the CANDIDATE type.
|
|
148
149
|
*
|
|
149
150
|
* @throws {@link DBC.Infringement} if the value does not match the regular expression. */
|
|
150
|
-
public static tsCheck<CANDIDATE = unknown>(toCheck: any, expression: RegExp, hint: string = undefined, id: string | undefined = undefined): CANDIDATE {
|
|
151
|
+
public static tsCheck<CANDIDATE = unknown>(toCheck: any, expression: RegExp, hint: string | undefined = undefined, id: string | undefined = undefined): CANDIDATE {
|
|
151
152
|
const result = REGEX.checkAlgorithm(toCheck, expression);
|
|
152
153
|
|
|
153
154
|
if (result) {
|
package/src/DBC/TYPE.ts
CHANGED
|
@@ -26,9 +26,9 @@ export class TYPE extends DBC {
|
|
|
26
26
|
|
|
27
27
|
if (!isValid) {
|
|
28
28
|
if (types.length === 1) {
|
|
29
|
-
return `Value has to
|
|
29
|
+
return `Value has to be of type "${type}" but is of type "${actualType}"`;
|
|
30
30
|
}
|
|
31
|
-
return `Value has to
|
|
31
|
+
return `Value has to be of type "${types.join(" | ")}" but is of type "${actualType}"`;
|
|
32
32
|
}
|
|
33
33
|
// #endregion Check if the actual type matches at least one of the specified types
|
|
34
34
|
return true;
|
|
@@ -53,19 +53,7 @@ export class TYPE extends DBC {
|
|
|
53
53
|
methodName: string | symbol,
|
|
54
54
|
parameterIndex: number,
|
|
55
55
|
) => void {
|
|
56
|
-
return DBC.
|
|
57
|
-
(
|
|
58
|
-
value: object,
|
|
59
|
-
target: object,
|
|
60
|
-
methodName: string,
|
|
61
|
-
parameterIndex: number,
|
|
62
|
-
) => {
|
|
63
|
-
return TYPE.checkAlgorithm(value, type);
|
|
64
|
-
},
|
|
65
|
-
dbc,
|
|
66
|
-
path,
|
|
67
|
-
hint
|
|
68
|
-
);
|
|
56
|
+
return DBC.createPRE(TYPE.checkAlgorithm, [type], dbc, path, hint);
|
|
69
57
|
}
|
|
70
58
|
/**
|
|
71
59
|
* A method-decorator factory using the {@link TYPE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -88,14 +76,7 @@ export class TYPE extends DBC {
|
|
|
88
76
|
propertyKey: string,
|
|
89
77
|
descriptor: PropertyDescriptor,
|
|
90
78
|
) => PropertyDescriptor {
|
|
91
|
-
return DBC.
|
|
92
|
-
(value: object, target: object, propertyKey: string) => {
|
|
93
|
-
return TYPE.checkAlgorithm(value, type);
|
|
94
|
-
},
|
|
95
|
-
dbc,
|
|
96
|
-
path,
|
|
97
|
-
hint
|
|
98
|
-
);
|
|
79
|
+
return DBC.createPOST(TYPE.checkAlgorithm, [type], dbc, path, hint);
|
|
99
80
|
}
|
|
100
81
|
/**
|
|
101
82
|
* A field-decorator factory using the {@link TYPE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -113,7 +94,7 @@ export class TYPE extends DBC {
|
|
|
113
94
|
hint: string | undefined = undefined,
|
|
114
95
|
dbc: string | undefined = undefined,
|
|
115
96
|
) {
|
|
116
|
-
return DBC.
|
|
97
|
+
return DBC.createINVARIANT(TYPE, [type], dbc, path, hint);
|
|
117
98
|
}
|
|
118
99
|
// #endregion Condition checking.
|
|
119
100
|
// #region Referenced Condition checking.
|
|
@@ -141,7 +122,7 @@ export class TYPE extends DBC {
|
|
|
141
122
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link TYPE }.
|
|
142
123
|
*
|
|
143
124
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
|
|
144
|
-
public static tsCheck<CANDIDATE = unknown>(toCheck: any, type: string, hint: string = undefined, id: string | undefined = undefined): CANDIDATE {
|
|
125
|
+
public static tsCheck<CANDIDATE = unknown>(toCheck: any, type: string, hint: string | undefined = undefined, id: string | undefined = undefined): CANDIDATE {
|
|
145
126
|
const result = TYPE.checkAlgorithm(toCheck, type);
|
|
146
127
|
|
|
147
128
|
if (result === true) {
|
package/src/DBC/UNDEFINED.ts
CHANGED
|
@@ -38,19 +38,7 @@ export class UNDEFINED extends DBC {
|
|
|
38
38
|
methodName: string | symbol,
|
|
39
39
|
parameterIndex: number,
|
|
40
40
|
) => void {
|
|
41
|
-
return DBC.
|
|
42
|
-
(
|
|
43
|
-
value: object,
|
|
44
|
-
target: object,
|
|
45
|
-
methodName: string,
|
|
46
|
-
parameterIndex: number,
|
|
47
|
-
) => {
|
|
48
|
-
return UNDEFINED.checkAlgorithm(value);
|
|
49
|
-
},
|
|
50
|
-
dbc,
|
|
51
|
-
path,
|
|
52
|
-
hint
|
|
53
|
-
);
|
|
41
|
+
return DBC.createPRE(UNDEFINED.checkAlgorithm, [], dbc, path, hint);
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
44
|
* A method-decorator factory using the {@link UNDEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -70,14 +58,7 @@ export class UNDEFINED extends DBC {
|
|
|
70
58
|
propertyKey: string,
|
|
71
59
|
descriptor: PropertyDescriptor,
|
|
72
60
|
) => PropertyDescriptor {
|
|
73
|
-
return DBC.
|
|
74
|
-
(value: object, target: object, propertyKey: string) => {
|
|
75
|
-
return UNDEFINED.checkAlgorithm(value);
|
|
76
|
-
},
|
|
77
|
-
dbc,
|
|
78
|
-
path,
|
|
79
|
-
hint
|
|
80
|
-
);
|
|
61
|
+
return DBC.createPOST(UNDEFINED.checkAlgorithm, [], dbc, path, hint);
|
|
81
62
|
}
|
|
82
63
|
/**
|
|
83
64
|
* A field-decorator factory using the {@link UNDEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -94,7 +75,7 @@ export class UNDEFINED extends DBC {
|
|
|
94
75
|
hint: string | undefined = undefined,
|
|
95
76
|
dbc: string | undefined = undefined,
|
|
96
77
|
) {
|
|
97
|
-
return DBC.
|
|
78
|
+
return DBC.createINVARIANT(UNDEFINED, [], dbc, path, hint);
|
|
98
79
|
}
|
|
99
80
|
// #endregion Condition checking.
|
|
100
81
|
// #region Referenced Condition checking.
|
package/src/DBC/ZOD.ts
CHANGED
|
@@ -16,9 +16,9 @@ export class ZOD extends DBC {
|
|
|
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
18
|
public static checkAlgorithm(toCheck: any, schema: z.ZodType): boolean | string {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return `Value
|
|
19
|
+
const result = schema.safeParse(toCheck);
|
|
20
|
+
if (!result.success) {
|
|
21
|
+
return `Value does not comply to the specified schema. Received: "${JSON.stringify(toCheck)}". Errors: ${result.error.message}`;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
return true;
|
|
@@ -42,18 +42,7 @@ export class ZOD extends DBC {
|
|
|
42
42
|
methodName: string | symbol,
|
|
43
43
|
parameterIndex: number,
|
|
44
44
|
) => void {
|
|
45
|
-
return DBC.
|
|
46
|
-
(
|
|
47
|
-
value: object,
|
|
48
|
-
target: object,
|
|
49
|
-
methodName: string,
|
|
50
|
-
parameterIndex: number,
|
|
51
|
-
) => {
|
|
52
|
-
return ZOD.checkAlgorithm(value, schema);
|
|
53
|
-
},
|
|
54
|
-
dbc,
|
|
55
|
-
path,
|
|
56
|
-
);
|
|
45
|
+
return DBC.createPRE(ZOD.checkAlgorithm, [schema], dbc, path);
|
|
57
46
|
}
|
|
58
47
|
/**
|
|
59
48
|
* A method-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -74,13 +63,7 @@ export class ZOD extends DBC {
|
|
|
74
63
|
propertyKey: string,
|
|
75
64
|
descriptor: PropertyDescriptor,
|
|
76
65
|
) => PropertyDescriptor {
|
|
77
|
-
return DBC.
|
|
78
|
-
(value: object, target: object, propertyKey: string) => {
|
|
79
|
-
return ZOD.checkAlgorithm(value, schema);
|
|
80
|
-
},
|
|
81
|
-
dbc,
|
|
82
|
-
path,
|
|
83
|
-
);
|
|
66
|
+
return DBC.createPOST(ZOD.checkAlgorithm, [schema], dbc, path);
|
|
84
67
|
}
|
|
85
68
|
/**
|
|
86
69
|
* A field-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -97,7 +80,7 @@ export class ZOD extends DBC {
|
|
|
97
80
|
path: string | undefined = undefined,
|
|
98
81
|
dbc = "WaXCode.DBC",
|
|
99
82
|
) {
|
|
100
|
-
return DBC.
|
|
83
|
+
return DBC.createINVARIANT(ZOD, [schema], dbc, path);
|
|
101
84
|
}
|
|
102
85
|
// #endregion Condition checking.
|
|
103
86
|
// #region Referenced Condition checking.
|
|
@@ -124,14 +107,14 @@ export class ZOD extends DBC {
|
|
|
124
107
|
* @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link ZOD }.
|
|
125
108
|
*
|
|
126
109
|
* @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
|
|
127
|
-
public static tsCheck
|
|
110
|
+
public static tsCheck<CANDIDATE = unknown>(toCheck: any, schema: z.ZodType, id: string | undefined = undefined): CANDIDATE {
|
|
128
111
|
const result = ZOD.checkAlgorithm(toCheck, schema);
|
|
129
112
|
|
|
130
|
-
if(
|
|
131
|
-
return toCheck
|
|
113
|
+
if (result === true) {
|
|
114
|
+
return toCheck;
|
|
132
115
|
}
|
|
133
116
|
else {
|
|
134
|
-
throw new DBC.Infringement(
|
|
117
|
+
throw new DBC.Infringement(`${id ? `(${id}) ` : ""}${result as string}`);
|
|
135
118
|
}
|
|
136
119
|
}
|
|
137
120
|
/**
|