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.
Files changed (75) hide show
  1. package/Assessment.html +350 -0
  2. package/Assessment.md +507 -51
  3. package/CHANGELOG.md +55 -0
  4. package/CONTRIBUTING.md +129 -17
  5. package/README.md +373 -71
  6. package/SECURITY.md +60 -18
  7. package/SUPPORT.md +65 -0
  8. package/__tests__/DBC/DEFINED.test.ts +53 -0
  9. package/__tests__/DBC/Decorators.test.ts +365 -0
  10. package/__tests__/DBC/GREATER.test.ts +8 -6
  11. package/__tests__/DBC/HasAttribute.test.ts +56 -0
  12. package/__tests__/DBC/IF.test.ts +52 -0
  13. package/__tests__/DBC/JSON.Parse.test.ts +1 -1
  14. package/__tests__/DBC/OR.test.ts +1 -1
  15. package/__tests__/DBC/REGEX.test.ts +1 -1
  16. package/__tests__/DBC/TYPE.test.ts +1 -1
  17. package/__tests__/DBC/UNDEFINED.test.ts +45 -0
  18. package/__tests__/DBC/ZOD.test.ts +54 -0
  19. package/jest.config.js +21 -0
  20. package/package.json +4 -5
  21. package/src/DBC/AE.ts +10 -6
  22. package/src/DBC/COMPARISON/GREATER.ts +11 -7
  23. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +14 -10
  24. package/src/DBC/COMPARISON/LESS.ts +14 -10
  25. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +14 -10
  26. package/src/DBC/COMPARISON.ts +20 -43
  27. package/src/DBC/DEFINED.ts +4 -23
  28. package/src/DBC/EQ/DIFFERENT.ts +21 -56
  29. package/src/DBC/EQ.ts +7 -26
  30. package/src/DBC/HasAttribute.ts +9 -26
  31. package/src/DBC/IF.ts +8 -27
  32. package/src/DBC/INSTANCE.ts +5 -22
  33. package/src/DBC/JSON.OP.ts +4 -34
  34. package/src/DBC/JSON.Parse.ts +5 -25
  35. package/src/DBC/OR.ts +5 -14
  36. package/src/DBC/REGEX.ts +41 -40
  37. package/src/DBC/TYPE.ts +6 -25
  38. package/src/DBC/UNDEFINED.ts +3 -22
  39. package/src/DBC/ZOD.ts +10 -27
  40. package/src/DBC.ts +223 -55
  41. package/tsconfig.json +7 -4
  42. package/tsconfig.test.json +12 -0
  43. package/.parcel-cache/bf96c58b6061a62a-BundleGraph +0 -0
  44. package/.parcel-cache/d7c812d65aeeac59-AssetGraph +0 -0
  45. package/.parcel-cache/data.mdb +0 -0
  46. package/.parcel-cache/e81759c1f106a17f-RequestGraph +0 -0
  47. package/.parcel-cache/fe0db3c4eb428be2-AssetGraph +0 -0
  48. package/.parcel-cache/lock.mdb +0 -0
  49. package/.parcel-cache/snapshot-e81759c1f106a17f.txt +0 -4609
  50. package/dist/DBC/AE.js +0 -173
  51. package/dist/DBC/COMPARISON/GREATER.js +0 -21
  52. package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +0 -21
  53. package/dist/DBC/COMPARISON/LESS.js +0 -21
  54. package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +0 -21
  55. package/dist/DBC/COMPARISON.js +0 -99
  56. package/dist/DBC/DEFINED.js +0 -99
  57. package/dist/DBC/EQ/DIFFERENT.js +0 -21
  58. package/dist/DBC/EQ.js +0 -100
  59. package/dist/DBC/GREATER.js +0 -99
  60. package/dist/DBC/HasAttribute.js +0 -108
  61. package/dist/DBC/IF.js +0 -99
  62. package/dist/DBC/INSTANCE.js +0 -93
  63. package/dist/DBC/JSON.OP.js +0 -133
  64. package/dist/DBC/JSON.Parse.js +0 -114
  65. package/dist/DBC/OR.js +0 -113
  66. package/dist/DBC/REGEX.js +0 -110
  67. package/dist/DBC/TYPE.js +0 -87
  68. package/dist/DBC/ZOD.js +0 -114
  69. package/dist/DBC.js +0 -336
  70. package/dist/Demo.js +0 -290
  71. package/dist/Test.html +0 -18
  72. package/dist/bundle.js +0 -2064
  73. package/dist/index.html +0 -18
  74. package/jest.config.ts +0 -20
  75. 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
- public static stdExp = {
10
- htmlAttributeName: /^[a-zA-Z_:][a-zA-Z0-9_.:-]*$/,
11
- eMail: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/i,
12
- property: /^[$_A-Za-z][$_A-Za-z0-9]*$/,
13
- url: /^(?:(?:http:|https?|ftp):\/\/)?(?:\S+(?::\S*)?@)?(?:localhost|(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,})(?::\d{2,5})?(?:\/(?:[\w\-\.]*\/)*[\w\-\.]+(?:\?\S*)?(?:#\S*)?)?$/i,
14
- keyPath: /^([a-zA-Z_$][a-zA-Z0-9_$]*\.)*[a-zA-Z_$][a-zA-Z0-9_$]*$/,
15
- date: /^\d{1,4}[.\/-]\d{1,2}[.\/-]\d{1,4}$/i,
16
- dateFormat:
17
- /^((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,
18
- cssSelector:
19
- /^(?:\*|#[\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*\]))*$/,
20
- boolean: /^(TRUE|FALSE)$/i,
21
- colorCodeHEX: /^#([A-Fa-f\d]{3,4}|[A-Fa-f\d]{6}|[A-Fa-f\d]{8})$/i,
22
- simpleHotkey: /^((Alt|Ctrl|Shift|Meta)\+)+[a-z\d]$/i,
23
- 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
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.decPrecondition(
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.decPostcondition(
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.decInvariant([new REGEX(expression)], path, dbc, hint);
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 to be of type "${type}" but is of type "${actualType}"`;
29
+ return `Value has to be of type "${type}" but is of type "${actualType}"`;
30
30
  }
31
- return `Value has to to be of type "${types.join(" | ")}" but is of type "${actualType}"`;
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.decPrecondition(
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.decPostcondition(
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.decInvariant([new TYPE(type)], path, dbc, hint);
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) {
@@ -38,19 +38,7 @@ export class UNDEFINED extends DBC {
38
38
  methodName: string | symbol,
39
39
  parameterIndex: number,
40
40
  ) => void {
41
- return DBC.decPrecondition(
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.decPostcondition(
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.decInvariant([new UNDEFINED()], path, dbc, hint);
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
- if (!schema.safeParse(toCheck).success) {
20
- console.log(z.toJSONSchema(schema))
21
- return `Value has to correspond to "${JSON.stringify( z.toJSONSchema(schema).properties )}" but is constituted as "${JSON.stringify( toCheck )}"`;
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.decPrecondition(
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.decPostcondition(
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.decInvariant([new ZOD(schema)], path, 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 < CANDIDATE = unknown > ( toCheck : any, schema : z.ZodType, id : string | undefined = undefined ) : CANDIDATE {
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( result === true ) {
131
- return toCheck ;
113
+ if (result === true) {
114
+ return toCheck;
132
115
  }
133
116
  else {
134
- throw new DBC.Infringement( `${id?`(${id}) `:""}${result as string }`);
117
+ throw new DBC.Infringement(`${id ? `(${id}) ` : ""}${result as string}`);
135
118
  }
136
119
  }
137
120
  /**