xdbc 1.0.73
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/.vscode/settings.json +3 -0
- package/Test.html +18 -0
- package/biome.json +33 -0
- package/dist/DBC/AE.js +163 -0
- package/dist/DBC/EQ.js +86 -0
- package/dist/DBC/INSTANCE.js +80 -0
- package/dist/DBC/JSON.OP.js +121 -0
- package/dist/DBC/JSON.Parse.js +102 -0
- package/dist/DBC/REGEX.js +103 -0
- package/dist/DBC/TYPE.js +75 -0
- package/dist/DBC.js +240 -0
- package/dist/DBC.min.js +2 -0
- package/dist/test.js +110 -0
- package/package.json +28 -0
- package/src/DBC/AE.ts +247 -0
- package/src/DBC/EQ.ts +121 -0
- package/src/DBC/INSTANCE.ts +107 -0
- package/src/DBC/JSON.OP.ts +179 -0
- package/src/DBC/JSON.Parse.ts +138 -0
- package/src/DBC/REGEX.ts +139 -0
- package/src/DBC/TYPE.ts +104 -0
- package/src/DBC.ts +355 -0
- package/src/test.ts +61 -0
- package/test.js +14 -0
- package/test.ts +11 -0
- package/tsconfig.json +15 -0
package/Test.html
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Load test.js</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<h1>Loading test.js Script</h1>
|
|
10
|
+
|
|
11
|
+
<script src="dist/test.js" type="module"></script>
|
|
12
|
+
<script>
|
|
13
|
+
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<p>Check the browser's developer console (usually opened with F12) for output.</p>
|
|
17
|
+
</body>
|
|
18
|
+
</html>
|
package/biome.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": false,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": false
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": false,
|
|
10
|
+
"ignore": []
|
|
11
|
+
},
|
|
12
|
+
"formatter": {
|
|
13
|
+
"enabled": true,
|
|
14
|
+
"indentStyle": "tab"
|
|
15
|
+
},
|
|
16
|
+
"organizeImports": {
|
|
17
|
+
"enabled": true
|
|
18
|
+
},
|
|
19
|
+
"linter": {
|
|
20
|
+
"enabled": true,
|
|
21
|
+
"rules": {
|
|
22
|
+
"recommended": true
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"javascript": {
|
|
26
|
+
"parser": {
|
|
27
|
+
"unsafeParameterDecoratorsEnabled": true
|
|
28
|
+
},
|
|
29
|
+
"formatter": {
|
|
30
|
+
"quoteStyle": "double"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
package/dist/DBC/AE.js
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { DBC } from "../DBC.js";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that all elements of an {@link object }s have to fulfill
|
|
4
|
+
* a given {@link object }'s check-method (( toCheck : any ) => boolean | string ).
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
8
|
+
export class AE extends DBC {
|
|
9
|
+
// #region Condition checking.
|
|
10
|
+
/**
|
|
11
|
+
* Checks each element of the "value"-{@link Array < any >} against the given "condition", if it is one. If it is not
|
|
12
|
+
* the "value" itself will be checked.
|
|
13
|
+
*
|
|
14
|
+
* @param condition The { check: (toCheck: any) => boolean | string } to check the "value" against.
|
|
15
|
+
* @param value Either "value"-{@link Array < any >}, which's elements will be checked, or the value to be
|
|
16
|
+
* checked itself.
|
|
17
|
+
* @param index If specified with "idxEnd" being undefined, this {@link Number } will be seen as the index of
|
|
18
|
+
* the value-{@link Array }'s element to check. If value isn't an {@link Array } this parameter
|
|
19
|
+
* will not have any effect.
|
|
20
|
+
* With "idxEnd" not undefined this parameter indicates the beginning of the span of elements to
|
|
21
|
+
* check within the value-{@link Array }.
|
|
22
|
+
* @param idxEnd Indicates the last element's index (including) of the span of value-{@link Array } elements to check.
|
|
23
|
+
* Setting this parameter to -1 specifies that all value-{@link Array }'s elements beginning from the
|
|
24
|
+
* specified "index" shall be checked.
|
|
25
|
+
*
|
|
26
|
+
* @returns As soon as the "condition" returns a {@link string }, instead of TRUE, the returned string. TRUE if the
|
|
27
|
+
* "condition" never returns a {@link string}. */
|
|
28
|
+
static checkAlgorithm(
|
|
29
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
30
|
+
condition, value, index, idxEnd) {
|
|
31
|
+
if (Array.isArray(value)) {
|
|
32
|
+
if (index !== undefined && idxEnd === undefined) {
|
|
33
|
+
if (index > -1 && index < value.length) {
|
|
34
|
+
const result = condition.check(value[index]);
|
|
35
|
+
if (typeof result === "string") {
|
|
36
|
+
return `Violating-Arrayelement at index "${index}" with value "${value[index]}". ${result}`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true; // In order for optional parameter to not cause an error if they are omitted.
|
|
40
|
+
}
|
|
41
|
+
for (let i = index; i <
|
|
42
|
+
(idxEnd !== undefined
|
|
43
|
+
? idxEnd !== -1
|
|
44
|
+
? idxEnd + 1
|
|
45
|
+
: value.length
|
|
46
|
+
: value.length); i++) {
|
|
47
|
+
const result = condition.check(value[i]);
|
|
48
|
+
if (result !== true) {
|
|
49
|
+
return `Violating-Arrayelement at index ${i}. ${result}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return condition.check(value);
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A parameter-decorator factory using the {@link AE.checkAlgorithm } with either multiple or a single one
|
|
60
|
+
* of the "realConditions" to check the tagged parameter-value against with.
|
|
61
|
+
* When specifying an "index" and the tagged parameter's "value" is an {@link Array }, the "realConditions" apply to the
|
|
62
|
+
* element at the specified "index".
|
|
63
|
+
* If the {@link Array } is too short the currently processed { check: (toCheck: any) => boolean | string } of
|
|
64
|
+
* "realConditions" will be verified to TRUE automatically, considering optional parameters.
|
|
65
|
+
* If an "index" is specified but the tagged parameter's value isn't an array, the "index" is treated as being undefined.
|
|
66
|
+
* If "index" is undefined and the tagged parameter's value is an {@link Array } each element of it will be checked
|
|
67
|
+
* against the "realConditions".
|
|
68
|
+
*
|
|
69
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
70
|
+
* against with.
|
|
71
|
+
* @param index See the {@link AE.checkAlgorithm }.
|
|
72
|
+
* @param idxEnd See the {@link AE.checkAlgorithm }.
|
|
73
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
74
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
75
|
+
*
|
|
76
|
+
* @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of "realConditions" returns one.
|
|
77
|
+
* Otherwise TRUE. */
|
|
78
|
+
static PRE(realConditions, index = undefined, idxEnd = undefined, path = undefined, dbc = "WaXCode.DBC") {
|
|
79
|
+
return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
|
|
80
|
+
if (Array.isArray(realConditions)) {
|
|
81
|
+
for (const currentCondition of realConditions) {
|
|
82
|
+
const result = AE.checkAlgorithm(currentCondition, value, index, idxEnd);
|
|
83
|
+
if (typeof result !== "boolean")
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
return AE.checkAlgorithm(
|
|
89
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
90
|
+
realConditions, value, index, idxEnd);
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}, dbc, path);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A method-decorator factory using the {@link AE.checkAlgorithm } with either multiple or a single one
|
|
97
|
+
* of the "realConditions" to check the tagged method's return-value against with.
|
|
98
|
+
*
|
|
99
|
+
* @param realConditions Either one or more { check: (toCheck: any) => boolean | string } to check the tagged parameter-value
|
|
100
|
+
* against with.
|
|
101
|
+
* @param index See the {@link AE.checkAlgorithm }.
|
|
102
|
+
* @param idxEnd See the {@link AE.checkAlgorithm }.
|
|
103
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
104
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
105
|
+
*
|
|
106
|
+
* @returns A {@link string } as soon as one { check: (toCheck: any) => boolean | string } of "realConditions" return one.
|
|
107
|
+
* Otherwise TRUE. */
|
|
108
|
+
static POST(realConditions, index = undefined, idxEnd = undefined, path = undefined, dbc = "WaXCode.DBC") {
|
|
109
|
+
return DBC.decPostcondition((value, target, propertyKey) => {
|
|
110
|
+
if (Array.isArray(realConditions)) {
|
|
111
|
+
for (const currentCondition of realConditions) {
|
|
112
|
+
const result = AE.checkAlgorithm(currentCondition, value, index, idxEnd);
|
|
113
|
+
if (typeof result !== "boolean")
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return AE.checkAlgorithm(
|
|
119
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
120
|
+
realConditions, value, index, idxEnd);
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
}, dbc, path);
|
|
124
|
+
}
|
|
125
|
+
// #endregion Condition checking.
|
|
126
|
+
// #region Referenced Condition checking.
|
|
127
|
+
//
|
|
128
|
+
// For usage in dynamic scenarios (like global functions).
|
|
129
|
+
//
|
|
130
|
+
/**
|
|
131
|
+
* Invokes the {@link AE.checkAlgorithm } passing the value "toCheck", {@link AE.equivalent } and {@link EQ.invert }.
|
|
132
|
+
*
|
|
133
|
+
* @param toCheck See {@link EQ.checkAlgorithm }.
|
|
134
|
+
*
|
|
135
|
+
* @returns See {@link EQ.checkAlgorithm}. */
|
|
136
|
+
check(
|
|
137
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
138
|
+
toCheck) {
|
|
139
|
+
if (Array.isArray(this.conditions)) {
|
|
140
|
+
for (const currentCondition of this.conditions) {
|
|
141
|
+
const result = AE.checkAlgorithm(currentCondition, toCheck, this.index, this.idxEnd);
|
|
142
|
+
if (typeof result !== "boolean")
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
return AE.checkAlgorithm(
|
|
148
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
149
|
+
this.conditions, toCheck, this.index, this.idxEnd);
|
|
150
|
+
}
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Creates this {@link AE } by setting the protected property {@link AE.conditions }, {@link AE.index } and {@link AE.idxEnd } used by {@link AE.check }.
|
|
155
|
+
*
|
|
156
|
+
* @param equivalent See {@link EQ.check }. */
|
|
157
|
+
constructor(conditions, index = undefined, idxEnd = undefined) {
|
|
158
|
+
super();
|
|
159
|
+
this.conditions = conditions;
|
|
160
|
+
this.index = index;
|
|
161
|
+
this.idxEnd = idxEnd;
|
|
162
|
+
}
|
|
163
|
+
}
|
package/dist/DBC/EQ.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { DBC } from "../DBC.js";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that two {@link object }s gotta be equal.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class EQ extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the value "toCheck" is equal to the specified "equivalent".
|
|
11
|
+
*
|
|
12
|
+
* @param toCheck The value that has to be equal to it's possible "equivalent" for this {@link DBC } to be fulfilled.
|
|
13
|
+
* @param equivalent The {@link object } the one "toCheck" has to be equal to in order for this {@link DBC } to be
|
|
14
|
+
* fulfilled.
|
|
15
|
+
*
|
|
16
|
+
* @returns TRUE if the value "toCheck" and the "equivalent" are equal to each other, otherwise FALSE. */
|
|
17
|
+
static checkAlgorithm(
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
19
|
+
toCheck, equivalent, invert) {
|
|
20
|
+
if (!invert && equivalent !== toCheck) {
|
|
21
|
+
return `Value has to to be equal to "${equivalent}"`;
|
|
22
|
+
}
|
|
23
|
+
if (invert && equivalent === toCheck) {
|
|
24
|
+
return `Value must not to be equal to "${equivalent}"`;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A parameter-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
30
|
+
* by the tagged parameter.
|
|
31
|
+
*
|
|
32
|
+
* @param equivalent See {@link EQ.checkAlgorithm }.
|
|
33
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
34
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
35
|
+
*
|
|
36
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
37
|
+
static PRE(
|
|
38
|
+
// biome-ignore lint/suspicious/noExplicitAny: To check for UNDEFINED and NULL.
|
|
39
|
+
equivalent, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
40
|
+
return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
|
|
41
|
+
return EQ.checkAlgorithm(value, equivalent, invert);
|
|
42
|
+
}, dbc, path);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A method-decorator factory using the {@link EQ.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
46
|
+
* by the tagged method's returnvalue.
|
|
47
|
+
*
|
|
48
|
+
* @param equivalent See {@link EQ.checkAlgorithm }.
|
|
49
|
+
* @param path See {@link DBC.Postcondition }.
|
|
50
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
51
|
+
*
|
|
52
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
53
|
+
static POST(
|
|
54
|
+
// biome-ignore lint/suspicious/noExplicitAny: To check for UNDEFINED and NULL.
|
|
55
|
+
equivalent, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
56
|
+
return DBC.decPostcondition((value, target, propertyKey) => {
|
|
57
|
+
return EQ.checkAlgorithm(value, equivalent, invert);
|
|
58
|
+
}, dbc, path);
|
|
59
|
+
}
|
|
60
|
+
// #endregion Condition checking.
|
|
61
|
+
// #region Referenced Condition checking.
|
|
62
|
+
//
|
|
63
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
64
|
+
//
|
|
65
|
+
/**
|
|
66
|
+
* Invokes the {@link EQ.checkAlgorithm } passing the value "toCheck", {@link EQ.equivalent } and {@link EQ.invert }.
|
|
67
|
+
*
|
|
68
|
+
* @param toCheck See {@link EQ.checkAlgorithm }.
|
|
69
|
+
*
|
|
70
|
+
* @returns See {@link EQ.checkAlgorithm}. */
|
|
71
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
72
|
+
check(toCheck) {
|
|
73
|
+
return EQ.checkAlgorithm(toCheck, this.equivalent, this.invert);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Creates this {@link EQ } by setting the protected property {@link EQ.equivalent } used by {@link EQ.check }.
|
|
77
|
+
*
|
|
78
|
+
* @param equivalent See {@link EQ.check }. */
|
|
79
|
+
constructor(
|
|
80
|
+
// biome-ignore lint/suspicious/noExplicitAny: To be able to match UNDEFINED and NULL.
|
|
81
|
+
equivalent, invert = false) {
|
|
82
|
+
super();
|
|
83
|
+
this.equivalent = equivalent;
|
|
84
|
+
this.invert = invert;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { DBC } from "../DBC.js";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } defining that the an {@link object }s gotta be an instance of a certain {@link INSTANCE.reference }.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Author: Salvatore Callari (Callari@WaXCode.net) / 2025
|
|
7
|
+
* Maintainer: Salvatore Callari (XDBC@WaXCode.net) */
|
|
8
|
+
export class INSTANCE extends DBC {
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the value "toCheck" is complies to the {@link RegExp } "expression".
|
|
11
|
+
*
|
|
12
|
+
* @param toCheck The value that has comply to the {@link RegExp } "expression" for this {@link DBC } to be fulfilled.
|
|
13
|
+
* @param reference The {@link RegExp } the one "toCheck" has comply to in order for this {@link DBC } to be
|
|
14
|
+
* fulfilled.
|
|
15
|
+
*
|
|
16
|
+
* @returns TRUE if the value "toCheck" is of the specified "type", otherwise FALSE. */
|
|
17
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
18
|
+
static checkAlgorithm(toCheck, reference) {
|
|
19
|
+
if (!(toCheck instanceof reference)) {
|
|
20
|
+
return `Value has to be an instance of "${reference}" but is of type "${typeof toCheck}"`;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* A parameter-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
26
|
+
* by the tagged parameter.
|
|
27
|
+
*
|
|
28
|
+
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
29
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
30
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
31
|
+
*
|
|
32
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
33
|
+
static PRE(
|
|
34
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
35
|
+
reference, path = undefined, dbc = "WaXCode.DBC") {
|
|
36
|
+
return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
|
|
37
|
+
return INSTANCE.checkAlgorithm(value, reference);
|
|
38
|
+
}, dbc, path);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A method-decorator factory using the {@link INSTANCE.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
42
|
+
* by the tagged method's returnvalue.
|
|
43
|
+
*
|
|
44
|
+
* @param reference See {@link INSTANCE.checkAlgorithm }.
|
|
45
|
+
* @param path See {@link DBC.Postcondition }.
|
|
46
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
47
|
+
*
|
|
48
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
49
|
+
static POST(
|
|
50
|
+
// biome-ignore lint/suspicious/noExplicitAny: In order to perform an "instanceof" check.
|
|
51
|
+
reference, path = undefined, dbc = "WaXCode.DBC") {
|
|
52
|
+
return DBC.decPostcondition((value, target, propertyKey) => {
|
|
53
|
+
return INSTANCE.checkAlgorithm(value, reference);
|
|
54
|
+
}, dbc, path);
|
|
55
|
+
}
|
|
56
|
+
// #endregion Condition checking.
|
|
57
|
+
// #region Referenced Condition checking.
|
|
58
|
+
//
|
|
59
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
60
|
+
//
|
|
61
|
+
/**
|
|
62
|
+
* Invokes the {@link INSTANCE.checkAlgorithm } passing the value "toCheck" and the {@link INSTANCE.reference } .
|
|
63
|
+
*
|
|
64
|
+
* @param toCheck See {@link INSTANCE.checkAlgorithm }.
|
|
65
|
+
*
|
|
66
|
+
* @returns See {@link INSTANCE.checkAlgorithm}. */
|
|
67
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
68
|
+
check(toCheck) {
|
|
69
|
+
return INSTANCE.checkAlgorithm(toCheck, this.reference);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Creates this {@link INSTANCE } by setting the protected property {@link INSTANCE.reference } used by {@link INSTANCE.check }.
|
|
73
|
+
*
|
|
74
|
+
* @param reference See {@link INSTANCE.check }. */
|
|
75
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
76
|
+
constructor(reference) {
|
|
77
|
+
super();
|
|
78
|
+
this.reference = reference;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } demanding that an {@link object } has specific properties of specific types.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class JSON_OP extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the object "toCheck" has the "necessaryProperties" of necessary type.
|
|
11
|
+
*
|
|
12
|
+
* @param toCheck The {@link object } to check for the necessary properties.
|
|
13
|
+
* @param necessaryProperties The { name : string, type : string }s defining the properties and type the {@link object } to
|
|
14
|
+
* check needs to have.
|
|
15
|
+
* @param checkElements Indicates if "toCheck" is an iterable object of which all elements have to be checked.
|
|
16
|
+
* Elements will only be checked if "toCheck" is iterable, otherwise "toCheck" itself
|
|
17
|
+
* will be checked.
|
|
18
|
+
*
|
|
19
|
+
* @returns TRUE if the value "toCheck" or it's elements, if "checkElements is TRUE, has all "necessaryProperties", otherwise a {@link string } to report the infringement. */
|
|
20
|
+
static checkAlgorithm(
|
|
21
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
22
|
+
toCheck, necessaryProperties, checkElements) {
|
|
23
|
+
if (toCheck === undefined || null) {
|
|
24
|
+
return `[ UNDEFINED or NULL received instead of object with following properties: ${JSON.stringify(necessaryProperties)} ]`;
|
|
25
|
+
}
|
|
26
|
+
for (const property of necessaryProperties)
|
|
27
|
+
if (checkElements && typeof toCheck[Symbol.iterator] === "function") {
|
|
28
|
+
for (const element of toCheck) {
|
|
29
|
+
if (
|
|
30
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation>
|
|
31
|
+
!element.hasOwnProperty(property.name) ||
|
|
32
|
+
// biome-ignore lint/suspicious/useValidTypeof: <explanation>
|
|
33
|
+
typeof element[property.name] !== property.type) {
|
|
34
|
+
return `[ Object "${JSON.stringify(element)}" in Array "${JSON.stringify(toCheck)}" does not contain the necessary property "${property.name}" of type "${property.type}"]`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (
|
|
40
|
+
// biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation>
|
|
41
|
+
!toCheck.hasOwnProperty(property.name) ||
|
|
42
|
+
// biome-ignore lint/suspicious/useValidTypeof: <explanation>
|
|
43
|
+
typeof toCheck[property.name] !== property.type) {
|
|
44
|
+
return `[ Object does not contain the necessary property "${property.name}" of type "${property.type}"]`;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* A parameter-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
51
|
+
* by the tagged parameter.
|
|
52
|
+
*
|
|
53
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
54
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
55
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
56
|
+
*
|
|
57
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
58
|
+
static PRE(necessaryProperties, checkElements = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
59
|
+
return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
|
|
60
|
+
return JSON_OP.checkAlgorithm(value, necessaryProperties, checkElements);
|
|
61
|
+
}, dbc, path);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A method-decorator factory using the {@link JSON_OP.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
65
|
+
* by the tagged method's returnvalue.
|
|
66
|
+
*
|
|
67
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
68
|
+
* @param path See {@link DBC.Postcondition }.
|
|
69
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
70
|
+
*
|
|
71
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
72
|
+
static POST(necessaryProperties, checkElements = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
73
|
+
return DBC.decPostcondition(
|
|
74
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
75
|
+
(value, target, propertyKey) => {
|
|
76
|
+
return JSON_OP.checkAlgorithm(value, necessaryProperties, checkElements);
|
|
77
|
+
}, dbc, path);
|
|
78
|
+
}
|
|
79
|
+
// #endregion Condition checking.
|
|
80
|
+
// #region Referenced Condition checking.
|
|
81
|
+
//
|
|
82
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
83
|
+
//
|
|
84
|
+
/**
|
|
85
|
+
* Invokes the {@link JSON_OP.checkAlgorithm } passing the value "toCheck", {@link JSON_OP.necessaryProperties } and {@link JSON_OP.checkElements }.
|
|
86
|
+
*
|
|
87
|
+
* @param toCheck See {@link JSON_OP.checkAlgorithm }.
|
|
88
|
+
*
|
|
89
|
+
* @returns See {@link JSON_OP.checkAlgorithm}. */
|
|
90
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
91
|
+
check(toCheck) {
|
|
92
|
+
return JSON_OP.checkAlgorithm(toCheck, this.necessaryProperties, this.checkElements);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Creates this {@link JSON_OP } by setting the protected property {@link JSON_OP.necessaryProperties } and {@link checkElements } used by {@link JSON_OP.check }.
|
|
96
|
+
*
|
|
97
|
+
* @param necessaryProperties See {@link JSON_OP.check }.
|
|
98
|
+
* @param checkElements See {@link JSON_OP.check }. */
|
|
99
|
+
constructor(necessaryProperties, checkElements = false) {
|
|
100
|
+
super();
|
|
101
|
+
this.necessaryProperties = necessaryProperties;
|
|
102
|
+
this.checkElements = checkElements;
|
|
103
|
+
}
|
|
104
|
+
// #endregion Referenced Condition checking.
|
|
105
|
+
// #region In-Method checking.
|
|
106
|
+
/**
|
|
107
|
+
* Invokes the {@link JSON_OP.checkAlgorithm } passing the value "toCheck", {@link JSON_OP.necessaryProperties } and {@link JSON_OP.checkElements }.
|
|
108
|
+
*
|
|
109
|
+
* @param toCheck See {@link JSON_OP.checkAlgorithm} }.
|
|
110
|
+
* @param necessaryProperties See {@link JSON_OP.checkAlgorithm} }.
|
|
111
|
+
* @param checkElements See {@link JSON_OP.checkAlgorithm} }.
|
|
112
|
+
*/
|
|
113
|
+
static check(
|
|
114
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
115
|
+
toCheck, necessaryProperties, checkElements = false) {
|
|
116
|
+
const checkResult = JSON_OP.checkAlgorithm(toCheck, necessaryProperties, checkElements);
|
|
117
|
+
if (typeof checkResult === "string") {
|
|
118
|
+
throw new DBC.Infringement(checkResult);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { DBC } from "../DBC";
|
|
2
|
+
/**
|
|
3
|
+
* A {@link DBC } demanding that a {@link string } is {@link JSON.parse}able.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
|
+
export class JSON_Parse extends DBC {
|
|
8
|
+
// #region Condition checking.
|
|
9
|
+
/**
|
|
10
|
+
* Tries to {@link JSON.parse } the {@link string } "toCheck" invoking the "receptor" with the result, if so.
|
|
11
|
+
*
|
|
12
|
+
* @param toCheck The {@link string } to be {@link JSON.parse }d.
|
|
13
|
+
* @param receptor The ( json : object ) => void to receive the {@link JSON.parse }d {@link string } "toCheck".
|
|
14
|
+
* check needs to have.
|
|
15
|
+
*
|
|
16
|
+
* @returns TRUE if the value "toCheck" is a valid JSON, otherwise a {@link string } to report the infringement. */
|
|
17
|
+
static checkAlgorithm(toCheck, receptor) {
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: JSON.parse returns any.
|
|
19
|
+
let parsed;
|
|
20
|
+
try {
|
|
21
|
+
parsed = JSON.parse(toCheck);
|
|
22
|
+
}
|
|
23
|
+
catch (X) {
|
|
24
|
+
return `[ Following string is not a valid JSON: ${toCheck}]`;
|
|
25
|
+
}
|
|
26
|
+
if (receptor) {
|
|
27
|
+
receptor(parsed);
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A parameter-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
33
|
+
* by the tagged parameter.
|
|
34
|
+
*
|
|
35
|
+
* @param receptor See {@link JSON.checkAlgorithm }.
|
|
36
|
+
* @param path See {@link DBC.decPrecondition }.
|
|
37
|
+
* @param dbc See {@link DBC.decPrecondition }.
|
|
38
|
+
*
|
|
39
|
+
* @returns See {@link DBC.decPrecondition }. */
|
|
40
|
+
static PRE(receptor, path = undefined, dbc = "WaXCode.DBC") {
|
|
41
|
+
return DBC.decPrecondition((value, target, methodName, parameterIndex) => {
|
|
42
|
+
return JSON_Parse.checkAlgorithm(value, receptor);
|
|
43
|
+
}, dbc, path);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A method-decorator factory using the {@link JSON_Parse.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
47
|
+
* by the tagged method's returnvalue.
|
|
48
|
+
*
|
|
49
|
+
* @param expression See {@link JSON.checkAlgorithm }.
|
|
50
|
+
* @param path See {@link DBC.Postcondition }.
|
|
51
|
+
* @param dbc See {@link DBC.decPostcondition }.
|
|
52
|
+
*
|
|
53
|
+
* @returns See {@link DBC.decPostcondition }. */
|
|
54
|
+
static POST(receptor, path = undefined, dbc = "WaXCode.DBC") {
|
|
55
|
+
return DBC.decPostcondition(
|
|
56
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
57
|
+
(value, target, propertyKey) => {
|
|
58
|
+
return JSON_Parse.checkAlgorithm(value, receptor);
|
|
59
|
+
}, dbc, path);
|
|
60
|
+
}
|
|
61
|
+
// #endregion Condition checking.
|
|
62
|
+
// #region Referenced Condition checking.
|
|
63
|
+
//
|
|
64
|
+
// For usage in dynamic scenarios (like with AE-DBC).
|
|
65
|
+
//
|
|
66
|
+
/**
|
|
67
|
+
* Invokes the {@link JSON_Parse.checkAlgorithm } passing the value "toCheck" and {@link JSON_Parse.receptor }.
|
|
68
|
+
*
|
|
69
|
+
* @param toCheck See {@link JSON_Parse.checkAlgorithm }.
|
|
70
|
+
*
|
|
71
|
+
* @returns See {@link JSON_Parse.checkAlgorithm}. */
|
|
72
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
73
|
+
check(toCheck) {
|
|
74
|
+
return JSON_Parse.checkAlgorithm(toCheck, this.receptor);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates this {@link JSON_Parse } by setting the protected property {@link JSON_Parse.necessaryProperties } and {@link checkElements } used by {@link JSON_Parse.check }.
|
|
78
|
+
*
|
|
79
|
+
* @param necessaryProperties See {@link JSON_Parse.check }.
|
|
80
|
+
* @param checkElements See {@link JSON_Parse.check }. */
|
|
81
|
+
constructor(receptor) {
|
|
82
|
+
super();
|
|
83
|
+
this.receptor = receptor;
|
|
84
|
+
}
|
|
85
|
+
// #endregion Referenced Condition checking.
|
|
86
|
+
// #region In-Method checking.
|
|
87
|
+
/**
|
|
88
|
+
* Invokes the {@link JSON_Parse.checkAlgorithm } passing the value "toCheck", {@link JSON_Parse.necessaryProperties } and {@link JSON_Parse.checkElements }.
|
|
89
|
+
*
|
|
90
|
+
* @param toCheck See {@link JSON_Parse.checkAlgorithm} }.
|
|
91
|
+
* @param necessaryProperties See {@link JSON_Parse.checkAlgorithm} }.
|
|
92
|
+
* @param checkElements See {@link JSON_Parse.checkAlgorithm} }.
|
|
93
|
+
*/
|
|
94
|
+
static check(
|
|
95
|
+
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
|
|
96
|
+
toCheck, receptor) {
|
|
97
|
+
const checkResult = JSON_Parse.checkAlgorithm(toCheck, receptor);
|
|
98
|
+
if (typeof checkResult === "string") {
|
|
99
|
+
throw new DBC.Infringement(checkResult);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|