xdbc 1.0.217 → 1.0.218

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 (89) hide show
  1. package/.gitattributes +8 -0
  2. package/.vscode/settings.json +3 -3
  3. package/.vscode/tasks.json +23 -23
  4. package/ASSESSMENT.md +249 -0
  5. package/README.md +131 -1
  6. package/__tests__/DBC/AE.test.ts +62 -62
  7. package/__tests__/DBC/ARRAY.test.ts +91 -91
  8. package/__tests__/DBC/DEFINED.test.ts +53 -53
  9. package/__tests__/DBC/DOM.test.ts +481 -0
  10. package/__tests__/DBC/Decorators.test.ts +367 -367
  11. package/__tests__/DBC/EQ.test.ts +13 -13
  12. package/__tests__/DBC/GREATER.test.ts +31 -31
  13. package/__tests__/DBC/HasAttribute.test.ts +60 -60
  14. package/__tests__/DBC/IF.test.ts +62 -62
  15. package/__tests__/DBC/INSTANCE.test.ts +13 -13
  16. package/__tests__/DBC/JSON.OP.test.ts +47 -47
  17. package/__tests__/DBC/JSON.Parse.test.ts +17 -17
  18. package/__tests__/DBC/OR.test.ts +14 -14
  19. package/__tests__/DBC/PLAIN_OBJECT.test.ts +109 -109
  20. package/__tests__/DBC/REGEX.test.ts +17 -17
  21. package/__tests__/DBC/TYPE.test.ts +13 -13
  22. package/__tests__/DBC/UNDEFINED.test.ts +45 -45
  23. package/__tests__/DBC/ZOD.test.ts +54 -54
  24. package/__tests__/DBC/onInfringement.test.ts +262 -0
  25. package/biome.json +40 -40
  26. package/dist/DBC/AE.js +172 -0
  27. package/dist/DBC/ARR/PLAIN_OBJECT.d.ts +0 -3
  28. package/dist/DBC/ARR/PLAIN_OBJECT.js +95 -0
  29. package/dist/DBC/ARRAY.d.ts +0 -3
  30. package/dist/DBC/ARRAY.js +90 -0
  31. package/dist/DBC/COMPARISON/GREATER.js +21 -0
  32. package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +21 -0
  33. package/dist/DBC/COMPARISON/LESS.js +21 -0
  34. package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +21 -0
  35. package/dist/DBC/COMPARISON.js +98 -0
  36. package/dist/DBC/DEFINED.js +87 -0
  37. package/dist/DBC/DOM.d.ts +87 -0
  38. package/dist/DBC/DOM.js +223 -0
  39. package/dist/DBC/EQ/DIFFERENT.js +34 -0
  40. package/dist/DBC/EQ.js +101 -0
  41. package/dist/DBC/HasAttribute.js +101 -0
  42. package/dist/DBC/IF.js +96 -0
  43. package/dist/DBC/INSTANCE.js +122 -0
  44. package/dist/DBC/JSON.OP.js +120 -0
  45. package/dist/DBC/JSON.Parse.js +104 -0
  46. package/dist/DBC/OR.js +125 -0
  47. package/dist/DBC/REGEX.js +136 -0
  48. package/dist/DBC/TYPE.js +112 -0
  49. package/dist/DBC/UNDEFINED.js +87 -0
  50. package/dist/DBC/ZOD.js +99 -0
  51. package/dist/DBC.d.ts +18 -4
  52. package/dist/DBC.js +645 -0
  53. package/dist/Demo.d.ts +10 -0
  54. package/dist/Demo.js +713 -0
  55. package/dist/bundle.js +6140 -405
  56. package/dist/index.d.ts +22 -0
  57. package/dist/index.js +22 -0
  58. package/jest.config.js +32 -32
  59. package/package.json +71 -55
  60. package/src/DBC/AE.ts +269 -288
  61. package/src/DBC/ARR/PLAIN_OBJECT.ts +122 -133
  62. package/src/DBC/ARRAY.ts +117 -127
  63. package/src/DBC/COMPARISON/GREATER.ts +41 -46
  64. package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +41 -45
  65. package/src/DBC/COMPARISON/LESS.ts +41 -45
  66. package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +41 -45
  67. package/src/DBC/COMPARISON.ts +149 -159
  68. package/src/DBC/DEFINED.ts +117 -122
  69. package/src/DBC/DOM.ts +291 -0
  70. package/src/DBC/EQ/DIFFERENT.ts +51 -57
  71. package/src/DBC/EQ.ts +154 -163
  72. package/src/DBC/HasAttribute.ts +149 -154
  73. package/src/DBC/IF.ts +173 -179
  74. package/src/DBC/INSTANCE.ts +168 -171
  75. package/src/DBC/JSON.OP.ts +178 -186
  76. package/src/DBC/JSON.Parse.ts +150 -157
  77. package/src/DBC/OR.ts +183 -187
  78. package/src/DBC/REGEX.ts +195 -196
  79. package/src/DBC/TYPE.ts +142 -149
  80. package/src/DBC/UNDEFINED.ts +115 -117
  81. package/src/DBC/ZOD.ts +130 -135
  82. package/src/DBC.ts +902 -904
  83. package/src/Demo.ts +537 -404
  84. package/src/index.ts +22 -0
  85. package/tsconfig.json +18 -18
  86. package/tsconfig.test.json +7 -7
  87. package/typedoc.json +16 -16
  88. package/webpack.config.js +27 -27
  89. package/Assessment.md +0 -507
package/src/DBC/ZOD.ts CHANGED
@@ -1,135 +1,130 @@
1
- import type { z } from "zod";
2
- import { DBC } from "../DBC";
3
- /**
4
- * A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link ZOD.schema }.
5
- *
6
- * @remarks
7
- * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
8
- export class ZOD extends DBC {
9
- /**
10
- * Checks if the value **toCheck** complies to the specified {@link z.ZodType }.
11
- *
12
- * @param toCheck The value that has to comply to the specified **schema** in order for this {@link DBC }
13
- * @param schema The {@link z.ZodType } the {@link object } **toCheck** has comply to in order for this {@link DBC } to be
14
- * fulfilled.
15
- *
16
- * @returns TRUE if the value **toCheck** complies to the specified **schema**, otherwise FALSE. */
17
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
18
- public static checkAlgorithm(
19
- toCheck: any,
20
- schema: z.ZodType,
21
- ): boolean | string {
22
- const result = schema.safeParse(toCheck);
23
- if (!result.success) {
24
- return `Value does not comply to the specified schema. Received: "${JSON.stringify(toCheck)}". Errors: ${result.error.message}`;
25
- }
26
-
27
- return true;
28
- }
29
- /**
30
- * A parameter-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
31
- * by the tagged parameter.
32
- *
33
- * @param schema See {@link ZOD.checkAlgorithm }.
34
- * @param path See {@link DBC.decPrecondition }.
35
- * @param dbc See {@link DBC.decPrecondition }.
36
- *
37
- * @returns See {@link DBC.decPrecondition }. */
38
- public static PRE(
39
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
40
- schema: z.ZodType,
41
- path: string | undefined = undefined,
42
- dbc = "WaXCode.DBC",
43
- ): (
44
- target: object,
45
- methodName: string | symbol | undefined,
46
- parameterIndex: number,
47
- ) => void {
48
- return DBC.createPRE(ZOD.checkAlgorithm, [schema], dbc, path);
49
- }
50
- /**
51
- * A method-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
52
- * by the tagged method's returnvalue.
53
- *
54
- * @param schema See {@link ZOD.checkAlgorithm }.
55
- * @param path See {@link DBC.Postcondition }.
56
- * @param dbc See {@link DBC.decPostcondition }.
57
- *
58
- * @returns See {@link DBC.decPostcondition }. */
59
- public static POST(
60
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
61
- schema: z.ZodType,
62
- path: string | undefined = undefined,
63
- dbc = "WaXCode.DBC",
64
- ): (
65
- target: object,
66
- propertyKey: string,
67
- descriptor: PropertyDescriptor,
68
- ) => PropertyDescriptor {
69
- return DBC.createPOST(ZOD.checkAlgorithm, [schema], dbc, path);
70
- }
71
- /**
72
- * A field-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
73
- * by the tagged method's returnvalue.
74
- *
75
- * @param schema See {@link ZOD.checkAlgorithm }.
76
- * @param path See {@link DBC.decInvariant }.
77
- * @param dbc See {@link DBC.decInvariant }.
78
- *
79
- * @returns See {@link DBC.decInvariant }. */
80
- public static INVARIANT(
81
- // biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
82
- schema: z.ZodType,
83
- path: string | undefined = undefined,
84
- dbc = "WaXCode.DBC",
85
- ) {
86
- return DBC.createINVARIANT(ZOD, [schema], dbc, path);
87
- }
88
- // #endregion Condition checking.
89
- // #region Referenced Condition checking.
90
- //
91
- // For usage in dynamic scenarios (like with AE-DBC).
92
- //
93
- /**
94
- * Invokes the {@link ZOD.checkAlgorithm } passing the value **toCheck** and the {@link ZOD.schema } .
95
- *
96
- * @param toCheck See {@link ZOD.checkAlgorithm }.
97
- *
98
- * @returns See {@link ZOD.checkAlgorithm}. */
99
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
100
- public check(toCheck: any) {
101
- return ZOD.checkAlgorithm(toCheck, this.schema);
102
- }
103
- /**
104
- * Invokes the {@link ZOD.checkAlgorithm } passing the value **toCheck** and the {@link ZOD.schema } .
105
- *
106
- * @param toCheck See {@link ZOD.checkAlgorithm }.
107
- * @param schema See {@link ZOD.checkAlgorithm }.
108
- * @param id A {@link string } identifying this {@link ZOD } via the {@link DBC.Infringement }-Message.
109
- *
110
- * @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link ZOD }.
111
- *
112
- * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
113
- public static tsCheck<CANDIDATE = unknown>(
114
- toCheck: any,
115
- schema: z.ZodType,
116
- id: string | undefined = undefined,
117
- dbc: string | undefined = undefined,
118
- ): CANDIDATE {
119
- const result = ZOD.checkAlgorithm(toCheck, schema);
120
-
121
- if (result === true) {
122
- return toCheck;
123
- }
124
- DBC.reportTsCheckInfringement(`${id ? `(${id}) ` : ""}${result as string}`, dbc);
125
- return toCheck as CANDIDATE;
126
- }
127
- /**
128
- * Creates this {@link ZOD } by setting the protected property {@link ZOD.schema } used by {@link ZOD.check }.
129
- *
130
- * @param schema See {@link ZOD.check }. */
131
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
132
- public constructor(protected schema: z.ZodType) {
133
- super();
134
- }
135
- }
1
+ import type { z } from "zod";
2
+ import { DBC } from "../DBC";
3
+ /**
4
+ * A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link ZOD.schema }.
5
+ *
6
+ * @remarks
7
+ * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
8
+ export class ZOD extends DBC {
9
+ /**
10
+ * Checks if the value **toCheck** complies to the specified {@link z.ZodType }.
11
+ *
12
+ * @param toCheck The value that has to comply to the specified **schema** in order for this {@link DBC }
13
+ * @param schema The {@link z.ZodType } the {@link object } **toCheck** has comply to in order for this {@link DBC } to be
14
+ * fulfilled.
15
+ *
16
+ * @returns TRUE if the value **toCheck** complies to the specified **schema**, otherwise FALSE. */
17
+ public static checkAlgorithm(
18
+ toCheck: any,
19
+ schema: z.ZodType,
20
+ ): boolean | string {
21
+ const result = schema.safeParse(toCheck);
22
+ if (!result.success) {
23
+ return `Value does not comply to the specified schema. Received: "${JSON.stringify(toCheck)}". Errors: ${result.error.message}`;
24
+ }
25
+ return true;
26
+ }
27
+ /**
28
+ * A parameter-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
29
+ * by the tagged parameter.
30
+ *
31
+ * @param schema See {@link ZOD.checkAlgorithm }.
32
+ * @param path See {@link DBC.decPrecondition }.
33
+ * @param dbc See {@link DBC.decPrecondition }.
34
+ *
35
+ * @returns See {@link DBC.decPrecondition }. */
36
+ public static PRE(
37
+ schema: z.ZodType,
38
+ path: string | undefined = undefined,
39
+ dbc = "WaXCode.DBC",
40
+ ): (
41
+ target: object,
42
+ methodName: string | symbol | undefined,
43
+ parameterIndex: number,
44
+ ) => void {
45
+ return DBC.createPRE(ZOD.checkAlgorithm, [schema], dbc, path);
46
+ }
47
+ /**
48
+ * A method-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
49
+ * by the tagged method's returnvalue.
50
+ *
51
+ * @param schema See {@link ZOD.checkAlgorithm }.
52
+ * @param path See {@link DBC.Postcondition }.
53
+ * @param dbc See {@link DBC.decPostcondition }.
54
+ *
55
+ * @returns See {@link DBC.decPostcondition }. */
56
+ public static POST(
57
+ schema: z.ZodType,
58
+ path: string | undefined = undefined,
59
+ dbc = "WaXCode.DBC",
60
+ ): (
61
+ target: object,
62
+ propertyKey: string,
63
+ descriptor: PropertyDescriptor,
64
+ ) => PropertyDescriptor {
65
+ return DBC.createPOST(ZOD.checkAlgorithm, [schema], dbc, path);
66
+ }
67
+ /**
68
+ * A field-decorator factory using the {@link ZOD.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
69
+ * by the tagged method's returnvalue.
70
+ *
71
+ * @param schema See {@link ZOD.checkAlgorithm }.
72
+ * @param path See {@link DBC.decInvariant }.
73
+ * @param dbc See {@link DBC.decInvariant }.
74
+ *
75
+ * @returns See {@link DBC.decInvariant }. */
76
+ public static INVARIANT(
77
+ schema: z.ZodType,
78
+ path: string | undefined = undefined,
79
+ dbc = "WaXCode.DBC",
80
+ ) {
81
+ return DBC.createINVARIANT(ZOD, [schema], dbc, path);
82
+ }
83
+ // #endregion Condition checking.
84
+ // #region Referenced Condition checking.
85
+ //
86
+ // For usage in dynamic scenarios (like with AE-DBC).
87
+ //
88
+ /**
89
+ * Invokes the {@link ZOD.checkAlgorithm } passing the value **toCheck** and the {@link ZOD.schema } .
90
+ *
91
+ * @param toCheck See {@link ZOD.checkAlgorithm }.
92
+ *
93
+ * @returns See {@link ZOD.checkAlgorithm}. */
94
+ public check(toCheck: any) {
95
+ return ZOD.checkAlgorithm(toCheck, this.schema);
96
+ }
97
+ /**
98
+ * Invokes the {@link ZOD.checkAlgorithm } passing the value **toCheck** and the {@link ZOD.schema } .
99
+ *
100
+ * @param toCheck See {@link ZOD.checkAlgorithm }.
101
+ * @param schema See {@link ZOD.checkAlgorithm }.
102
+ * @param id A {@link string } identifying this {@link ZOD } via the {@link DBC.Infringement }-Message.
103
+ *
104
+ * @returns The **CANDIDATE** **toCheck** doesn't fulfill this {@link ZOD }.
105
+ *
106
+ * @throws A {@link DBC.Infringement } if the **CANDIDATE** **toCheck** does not fulfill this {@link DEFINED }. */
107
+ public static tsCheck<CANDIDATE = unknown>(
108
+ toCheck: any,
109
+ schema: z.ZodType,
110
+ id: string | undefined = undefined,
111
+ dbc: string | undefined = undefined,
112
+ ): CANDIDATE {
113
+ const result = ZOD.checkAlgorithm(toCheck, schema);
114
+ if (result === true) {
115
+ return toCheck;
116
+ }
117
+ DBC.reportTsCheckInfringement(
118
+ `${id ? `(${id}) ` : ""}${result as string}`,
119
+ dbc,
120
+ );
121
+ return toCheck as CANDIDATE;
122
+ }
123
+ /**
124
+ * Creates this {@link ZOD } by setting the protected property {@link ZOD.schema } used by {@link ZOD.check }.
125
+ *
126
+ * @param schema See {@link ZOD.check }. */
127
+ public constructor(protected schema: z.ZodType) {
128
+ super();
129
+ }
130
+ }