xdbc 1.0.99 → 1.0.100

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.
@@ -0,0 +1,81 @@
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining that an {@link object }s must be defined thus it's value may not be **null** or **undefined**.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
7
+ export class DEFINED extends DBC {
8
+ /**
9
+ * Checks if the value **toCheck** is null or undefined.
10
+ *
11
+ * @param toCheck The {@link Object } to check.
12
+ *
13
+ * @returns TRUE if the value **toCheck** is of the specified **type**, otherwise FALSE. */
14
+ // biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic type checking of also UNDEFINED.
15
+ static checkAlgorithm(toCheck) {
16
+ // biome-ignore lint/suspicious/useValidTypeof: Necessary
17
+ if (toCheck === undefined || toCheck === null) {
18
+ return `Value may not be UNDEFINED or NULL`;
19
+ }
20
+ return true;
21
+ }
22
+ /**
23
+ * A parameter-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
24
+ * by the tagged parameter.
25
+ *
26
+ * @param type See {@link DEFINED.checkAlgorithm }.
27
+ * @param path See {@link DBC.decPrecondition }.
28
+ * @param dbc See {@link DBC.decPrecondition }.
29
+ *
30
+ * @returns See {@link DBC.decPrecondition }. */
31
+ static PRE(path = undefined, dbc = "WaXCode.DBC") {
32
+ return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
33
+ return DEFINED.checkAlgorithm(value);
34
+ }, dbc, path);
35
+ }
36
+ /**
37
+ * A method-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
38
+ * by the tagged method's returnvalue.
39
+ *
40
+ * @param type See {@link DEFINED.checkAlgorithm }.
41
+ * @param path See {@link DBC.Postcondition }.
42
+ * @param dbc See {@link DBC.decPostcondition }.
43
+ *
44
+ * @returns See {@link DBC.decPostcondition }. */
45
+ static POST(type, path = undefined, dbc = "WaXCode.DBC") {
46
+ return DBC.decPostcondition((value, target, propertyKey) => {
47
+ return DEFINED.checkAlgorithm(value);
48
+ }, dbc, path);
49
+ }
50
+ /**
51
+ * A field-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
52
+ * by the tagged field.
53
+ *
54
+ * @param type See {@link DEFINED.checkAlgorithm }.
55
+ * @param path See {@link DBC.decInvariant }.
56
+ * @param dbc See {@link DBC.decInvariant }.
57
+ *
58
+ * @returns See {@link DBC.decInvariant }. */
59
+ static INVARIANT(type, path = undefined, dbc = "WaXCode.DBC") {
60
+ return DBC.decInvariant([new DEFINED()], path, dbc);
61
+ }
62
+ // #endregion Condition checking.
63
+ // #region Referenced Condition checking.
64
+ //
65
+ // For usage in dynamic scenarios (like with AE-DBC).
66
+ //
67
+ /**
68
+ * Invokes the {@link DEFINED.checkAlgorithm } passing the value **toCheck** and the {@link DEFINED.type } .
69
+ *
70
+ * @param toCheck See {@link DEFINED.checkAlgorithm }.
71
+ *
72
+ * @returns See {@link DEFINED.checkAlgorithm}. */
73
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
74
+ check(toCheck) {
75
+ return DEFINED.checkAlgorithm(toCheck);
76
+ }
77
+ /** Creates this {@link DEFINED }. */
78
+ constructor() {
79
+ super();
80
+ }
81
+ }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.99",
2
+ "version": "1.0.100",
3
3
  "name": "xdbc",
4
4
  "scripts": {
5
5
  "docs": "typedoc",
@@ -0,0 +1,114 @@
1
+ import { DBC } from "../DBC";
2
+ /**
3
+ * A {@link DBC } defining that an {@link object }s must be defined thus it's value may not be **null** or **undefined**.
4
+ *
5
+ * @remarks
6
+ * Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
7
+ export class DEFINED extends DBC {
8
+ /**
9
+ * Checks if the value **toCheck** is null or undefined.
10
+ *
11
+ * @param toCheck The {@link Object } to check.
12
+ *
13
+ * @returns TRUE if the value **toCheck** is of the specified **type**, otherwise FALSE. */
14
+ // biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic type checking of also UNDEFINED.
15
+ public static checkAlgorithm(toCheck: any ): boolean | string {
16
+ // biome-ignore lint/suspicious/useValidTypeof: Necessary
17
+ if ( toCheck === undefined || toCheck === null ) {
18
+ return `Value may not be UNDEFINED or NULL`;
19
+ }
20
+
21
+ return true;
22
+ }
23
+ /**
24
+ * A parameter-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
25
+ * by the tagged parameter.
26
+ *
27
+ * @param type See {@link DEFINED.checkAlgorithm }.
28
+ * @param path See {@link DBC.decPrecondition }.
29
+ * @param dbc See {@link DBC.decPrecondition }.
30
+ *
31
+ * @returns See {@link DBC.decPrecondition }. */
32
+ public static PRE(
33
+ path: string | undefined = undefined,
34
+ dbc = "WaXCode.DBC",
35
+ ): (
36
+ target: object,
37
+ methodName: string | symbol,
38
+ parameterIndex: number,
39
+ ) => void {
40
+ return DBC.decPrecondition(
41
+ (
42
+ value: object,
43
+ target: object,
44
+ methodName: string,
45
+ parameterIndex: number,
46
+ ) => {
47
+ return DEFINED.checkAlgorithm(value);
48
+ },
49
+ dbc,
50
+ path,
51
+ );
52
+ }
53
+ /**
54
+ * A method-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
55
+ * by the tagged method's returnvalue.
56
+ *
57
+ * @param type See {@link DEFINED.checkAlgorithm }.
58
+ * @param path See {@link DBC.Postcondition }.
59
+ * @param dbc See {@link DBC.decPostcondition }.
60
+ *
61
+ * @returns See {@link DBC.decPostcondition }. */
62
+ public static POST(
63
+ type: string,
64
+ path: string | undefined = undefined,
65
+ dbc = "WaXCode.DBC",
66
+ ): (
67
+ target: object,
68
+ propertyKey: string,
69
+ descriptor: PropertyDescriptor,
70
+ ) => PropertyDescriptor {
71
+ return DBC.decPostcondition(
72
+ (value: object, target: object, propertyKey: string) => {
73
+ return DEFINED.checkAlgorithm(value);
74
+ },
75
+ dbc,
76
+ path,
77
+ );
78
+ }
79
+ /**
80
+ * A field-decorator factory using the {@link DEFINED.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
81
+ * by the tagged field.
82
+ *
83
+ * @param type See {@link DEFINED.checkAlgorithm }.
84
+ * @param path See {@link DBC.decInvariant }.
85
+ * @param dbc See {@link DBC.decInvariant }.
86
+ *
87
+ * @returns See {@link DBC.decInvariant }. */
88
+ public static INVARIANT(
89
+ type: string,
90
+ path: string | undefined = undefined,
91
+ dbc = "WaXCode.DBC",
92
+ ) {
93
+ return DBC.decInvariant([new DEFINED()], path, dbc);
94
+ }
95
+ // #endregion Condition checking.
96
+ // #region Referenced Condition checking.
97
+ //
98
+ // For usage in dynamic scenarios (like with AE-DBC).
99
+ //
100
+ /**
101
+ * Invokes the {@link DEFINED.checkAlgorithm } passing the value **toCheck** and the {@link DEFINED.type } .
102
+ *
103
+ * @param toCheck See {@link DEFINED.checkAlgorithm }.
104
+ *
105
+ * @returns See {@link DEFINED.checkAlgorithm}. */
106
+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
107
+ public check(toCheck: any) {
108
+ return DEFINED.checkAlgorithm(toCheck);
109
+ }
110
+ /** Creates this {@link DEFINED }. */
111
+ public constructor() {
112
+ super();
113
+ }
114
+ }