xdbc 1.0.95 → 1.0.96
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 +1 -1
- package/README.md +10 -3
- package/dist/DBC/COMPARISON/GREATER.js +6 -7
- package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +21 -0
- package/dist/DBC/COMPARISON/LESS.js +21 -0
- package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +21 -0
- package/dist/DBC/COMPARISON.js +18 -18
- package/dist/Demo.js +24 -1
- package/dist/bundle.js +511 -25
- package/package.json +8 -3
- package/src/DBC/COMPARISON.ts +2 -2
- package/src/DBC/EQ/DIFFERENT.ts +35 -0
- package/src/DBC/HasAttribute.ts +140 -0
- package/src/DBC.ts +44 -1
- package/src/Demo.ts +163 -20
- package/webpack.config.js +1 -0
- package/src/DBC/GREATER.ts +0 -150
package/.vscode/settings.json
CHANGED
package/README.md
CHANGED
|
@@ -46,17 +46,22 @@ npm install --save xdbc
|
|
|
46
46
|
|
|
47
47
|
## Usage
|
|
48
48
|
|
|
49
|
-
As by now there're
|
|
49
|
+
As by now there're 14 contracts that can be used:
|
|
50
50
|
|
|
51
51
|
- AE (*Each element of the value-array has to fulfill a certain set of contracts*)
|
|
52
52
|
- EQ (*Value has to be equal to a supplied reference value*)
|
|
53
|
-
-
|
|
53
|
+
- COMPARISON (*Value has to be greater, less, greater/equal, equal or less/equal than a supplied reference value*)
|
|
54
54
|
- INSTANCE (*Value has to be an instance of a supplied type*)
|
|
55
55
|
- JSON.OP (*Value has to contain certain properties of certain type*)
|
|
56
56
|
- JSON.Parse (*String-value has to be a parsable JSON*)
|
|
57
57
|
- OR (*At least one of a set of contracts has to be fulfilled*)
|
|
58
58
|
- REGEX (*Value has to be validated by a supplied regular expression*)
|
|
59
59
|
- TYPE (*Value has to be of a certain type*)
|
|
60
|
+
- GREATER (*Derived from COMPARISON*)
|
|
61
|
+
- GREATER_OR_EQUAL (*Derived from COMPARISON*)
|
|
62
|
+
- LESS (*Derived from COMPARISON*)
|
|
63
|
+
- LESS_OR_EQUAL (*Derived from COMPARISON*)
|
|
64
|
+
- DIFFERENT (*Derived from EQ*)
|
|
60
65
|
|
|
61
66
|
All of which expose a method **PRE**, **POST** and **INVARIANT** (*precondition, postcondition and invariant*).<br>
|
|
62
67
|
Import the classes to use from **xdbc**. If parameters shall be decorated with contracts import class **DBC** also. <br><br>
|
|
@@ -85,10 +90,12 @@ With **PRE**, **POST** and **INVARIANT** decorators an optional **path** paramet
|
|
|
85
90
|
|
|
86
91
|
Multiple instances of the class **DBC** with varying settings for e.g. reporting infringements may be instantiated. Which of these instances is used to report can be defined when either using **PRE**, **POST** or **INVARIANT** by defining their **dbc** parameter: **@DBC.INVARIANT([new EQ(1)],"length","MyVendor.MyDBCInstance")**, for example. The standard path (*WaXCode.DBC*) leads to an automatically created instance, that is generated when the Framework is imported.
|
|
87
92
|
|
|
88
|
-
Many contracts got further features like the **AE**-Contract that can check specific ranges within the tagged array or the **EQ
|
|
93
|
+
Many contracts got further features like the **AE**-Contract that can check specific ranges within the tagged array or the **EQ**--Contract that can be inverted turning it into **not EQual**-Contract. Check out the [API](https://callaris.github.io/XDBC/) for details.
|
|
89
94
|
|
|
90
95
|
A **DBC**'s **warningSettings** & **infringementSettings** determine what happens on warnings and errors, whereas warnings are not implemented yet.
|
|
91
96
|
|
|
97
|
+
**DBC** can be turned off for **PRE**-, **POST**-Conditions and **INVARIANT**S separately by setting the proper **executionSettings** of the **DBC**-Class.
|
|
98
|
+
|
|
92
99
|
## Contribution
|
|
93
100
|
Participation is highly valued and warmly welcomed. The ultimate goal is to create a tool that proves genuinely useful and empowers a wide range of developers to build more robust and reliable applications.
|
|
94
101
|
|
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { COMPARISON } from "../COMPARISON";
|
|
2
|
+
/** See {@link COMPARISON }. */
|
|
2
3
|
export class GREATER extends COMPARISON {
|
|
3
|
-
/** See {@link
|
|
4
|
+
/** See {@link COMPARISON.PRE }. */
|
|
4
5
|
static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
5
6
|
return COMPARISON.PRE(equivalent, false, false, path, dbc);
|
|
6
7
|
}
|
|
7
|
-
/** See {@link
|
|
8
|
+
/** See {@link COMPARISON.POST }. */
|
|
8
9
|
static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
9
10
|
return COMPARISON.POST(equivalent, false, false, path, dbc);
|
|
10
11
|
}
|
|
11
|
-
/** See {@link
|
|
12
|
+
/** See {@link COMPARISON.INVARIANT }. */
|
|
12
13
|
static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
13
14
|
return COMPARISON.INVARIANT(equivalent, false, false, path, dbc);
|
|
14
15
|
}
|
|
15
|
-
/** See {@link
|
|
16
|
-
constructor(equivalent
|
|
16
|
+
/** See {@link COMPARISON.constructor }. */
|
|
17
|
+
constructor(equivalent) {
|
|
17
18
|
super(equivalent, false, false);
|
|
18
19
|
this.equivalent = equivalent;
|
|
19
|
-
this.equalityPermitted = equalityPermitted;
|
|
20
|
-
this.invert = invert;
|
|
21
20
|
}
|
|
22
21
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { COMPARISON } from "../COMPARISON";
|
|
2
|
+
/** See {@link COMPARISON }. */
|
|
3
|
+
export class GREATER_OR_EQUAL extends COMPARISON {
|
|
4
|
+
/** See {@link COMPARISON.PRE }. */
|
|
5
|
+
static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
6
|
+
return COMPARISON.PRE(equivalent, true, false, path, dbc);
|
|
7
|
+
}
|
|
8
|
+
/** See {@link COMPARISON.POST }. */
|
|
9
|
+
static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
10
|
+
return COMPARISON.POST(equivalent, true, false, path, dbc);
|
|
11
|
+
}
|
|
12
|
+
/** See {@link COMPARISON.INVARIANT }. */
|
|
13
|
+
static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
14
|
+
return COMPARISON.INVARIANT(equivalent, true, false, path, dbc);
|
|
15
|
+
}
|
|
16
|
+
/** See {@link COMPARISON.constructor }. */
|
|
17
|
+
constructor(equivalent) {
|
|
18
|
+
super(equivalent, true, false);
|
|
19
|
+
this.equivalent = equivalent;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { COMPARISON } from "../COMPARISON";
|
|
2
|
+
/** See {@link COMPARISON }. */
|
|
3
|
+
export class LESS extends COMPARISON {
|
|
4
|
+
/** See {@link COMPARISON.PRE }. */
|
|
5
|
+
static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
6
|
+
return COMPARISON.PRE(equivalent, false, true, path, dbc);
|
|
7
|
+
}
|
|
8
|
+
/** See {@link COMPARISON.POST }. */
|
|
9
|
+
static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
10
|
+
return COMPARISON.POST(equivalent, false, true, path, dbc);
|
|
11
|
+
}
|
|
12
|
+
/** See {@link COMPARISON.INVARIANT }. */
|
|
13
|
+
static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
14
|
+
return COMPARISON.INVARIANT(equivalent, false, true, path, dbc);
|
|
15
|
+
}
|
|
16
|
+
/** See {@link COMPARISON.constructor }. */
|
|
17
|
+
constructor(equivalent) {
|
|
18
|
+
super(equivalent, false, true);
|
|
19
|
+
this.equivalent = equivalent;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { COMPARISON } from "../COMPARISON";
|
|
2
|
+
/** See {@link COMPARISON }. */
|
|
3
|
+
export class LESS_OR_EQUAL extends COMPARISON {
|
|
4
|
+
/** See {@link COMPARISON.PRE }. */
|
|
5
|
+
static PRE(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
6
|
+
return COMPARISON.PRE(equivalent, true, true, path, dbc);
|
|
7
|
+
}
|
|
8
|
+
/** See {@link COMPARISON.POST }. */
|
|
9
|
+
static POST(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
10
|
+
return COMPARISON.POST(equivalent, true, true, path, dbc);
|
|
11
|
+
}
|
|
12
|
+
/** See {@link COMPARISON.INVARIANT }. */
|
|
13
|
+
static INVARIANT(equivalent, equalityPermitted = false, invert = false, path = undefined, dbc = "WaXCode.DBC") {
|
|
14
|
+
return COMPARISON.INVARIANT(equivalent, true, true, path, dbc);
|
|
15
|
+
}
|
|
16
|
+
/** See {@link COMPARISON.constructor }. */
|
|
17
|
+
constructor(equivalent) {
|
|
18
|
+
super(equivalent, true, true);
|
|
19
|
+
this.equivalent = equivalent;
|
|
20
|
+
}
|
|
21
|
+
}
|
package/dist/DBC/COMPARISON.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DBC } from "../DBC";
|
|
2
2
|
/**
|
|
3
|
-
* A {@link DBC } defining
|
|
3
|
+
* A {@link DBC } defining a comparison between two {@link object }s.
|
|
4
4
|
*
|
|
5
5
|
* @remarks
|
|
6
6
|
* Maintainer: Callari, Salvatore (XDBC@WaXCode.net) */
|
|
7
7
|
export class COMPARISON extends DBC {
|
|
8
8
|
// #region Condition checking.
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Does a comparison between the {@link object } **toCheck** and the **equivalent**.
|
|
11
11
|
*
|
|
12
12
|
* @param toCheck The value that has to be equal to it's possible **equivalent** for this {@link DBC } to be fulfilled.
|
|
13
13
|
* @param equivalent The {@link object } the one **toCheck** has to be equal to in order for this {@link DBC } to be
|
|
@@ -30,11 +30,11 @@ export class COMPARISON extends DBC {
|
|
|
30
30
|
return true;
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
|
-
* A parameter-decorator factory using the {@link
|
|
33
|
+
* A parameter-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
34
34
|
* by the tagged parameter.
|
|
35
35
|
*
|
|
36
|
-
* @param equivalent See {@link
|
|
37
|
-
* @param equalityPermitted See {@link
|
|
36
|
+
* @param equivalent See {@link COMPARISON.checkAlgorithm }.
|
|
37
|
+
* @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
|
|
38
38
|
* @param path See {@link DBC.decPrecondition }.
|
|
39
39
|
* @param dbc See {@link DBC.decPrecondition }.
|
|
40
40
|
*
|
|
@@ -45,11 +45,11 @@ export class COMPARISON extends DBC {
|
|
|
45
45
|
}, dbc, path);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* A method-decorator factory using the {@link
|
|
48
|
+
* A method-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
49
49
|
* by the tagged method's returnvalue.
|
|
50
50
|
*
|
|
51
|
-
* @param equivalent See {@link
|
|
52
|
-
* @param equalityPermitted See {@link
|
|
51
|
+
* @param equivalent See {@link COMPARISON.checkAlgorithm }.
|
|
52
|
+
* @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
|
|
53
53
|
* @param path See {@link DBC.Postcondition }.
|
|
54
54
|
* @param dbc See {@link DBC.decPostcondition }.
|
|
55
55
|
*
|
|
@@ -60,11 +60,11 @@ export class COMPARISON extends DBC {
|
|
|
60
60
|
}, dbc, path);
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* A field-decorator factory using the {@link
|
|
63
|
+
* A field-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
64
64
|
* by the tagged field.
|
|
65
65
|
*
|
|
66
|
-
* @param equivalent See {@link
|
|
67
|
-
* @param equalityPermitted See {@link
|
|
66
|
+
* @param equivalent See {@link COMPARISON.checkAlgorithm }.
|
|
67
|
+
* @param equalityPermitted See {@link COMPARISON.checkAlgorithm }.
|
|
68
68
|
* @param path See {@link DBC.decInvariant }.
|
|
69
69
|
* @param dbc See {@link DBC.decInvariant }.
|
|
70
70
|
*
|
|
@@ -76,20 +76,20 @@ export class COMPARISON extends DBC {
|
|
|
76
76
|
// #region Referenced Condition checking.
|
|
77
77
|
// #region Dynamic usage.
|
|
78
78
|
/**
|
|
79
|
-
* Invokes the {@link
|
|
79
|
+
* Invokes the {@link COMPARISON.checkAlgorithm } passing the value **toCheck**, {@link COMPARISON.equivalent } and {@link COMPARISON.invert }.
|
|
80
80
|
*
|
|
81
|
-
* @param toCheck See {@link
|
|
81
|
+
* @param toCheck See {@link COMPARISON.checkAlgorithm }.
|
|
82
82
|
*
|
|
83
|
-
* @returns See {@link
|
|
83
|
+
* @returns See {@link COMPARISON.checkAlgorithm}. */
|
|
84
84
|
check(toCheck) {
|
|
85
85
|
return COMPARISON.checkAlgorithm(toCheck, this.equivalent, this.equalityPermitted, this.invert);
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
|
-
* Creates this {@link
|
|
88
|
+
* Creates this {@link COMPARISON } by setting the protected property {@link COMPARISON.equivalent }, {@link COMPARISON.equalityPermitted } and {@link COMPARISON.invert } used by {@link COMPARISON.check }.
|
|
89
89
|
*
|
|
90
|
-
* @param equivalent See {@link
|
|
91
|
-
* @param equalityPermitted See {@link
|
|
92
|
-
* @param invert See {@link
|
|
90
|
+
* @param equivalent See {@link COMPARISON.check }.
|
|
91
|
+
* @param equalityPermitted See {@link COMPARISON.check }.
|
|
92
|
+
* @param invert See {@link COMPARISON.check }. */
|
|
93
93
|
constructor(equivalent, equalityPermitted = false, invert = false) {
|
|
94
94
|
super();
|
|
95
95
|
this.equivalent = equivalent;
|
package/dist/Demo.js
CHANGED
|
@@ -16,12 +16,13 @@ import { EQ } from "./DBC/EQ";
|
|
|
16
16
|
import { TYPE } from "./DBC/TYPE";
|
|
17
17
|
import { AE } from "./DBC/AE";
|
|
18
18
|
import { INSTANCE } from "./DBC/INSTANCE";
|
|
19
|
+
import { GREATER } from "./DBC/COMPARISON/GREATER";
|
|
19
20
|
/** Demonstrative use of **D**esign **B**y **C**ontract Decorators */
|
|
20
21
|
export class Demo {
|
|
21
22
|
constructor() {
|
|
22
23
|
// #region Check Property Decorator
|
|
23
24
|
this.testProperty = "a";
|
|
24
|
-
// #endregion Check
|
|
25
|
+
// #endregion Check Comparison
|
|
25
26
|
}
|
|
26
27
|
// #endregion Check Property Decorator
|
|
27
28
|
// #region Check Parameter. & Returnvalue Decorator
|
|
@@ -57,6 +58,9 @@ export class Demo {
|
|
|
57
58
|
// #endregion Check AE Range
|
|
58
59
|
// #region Check AE Index
|
|
59
60
|
testAEIndex(x) { }
|
|
61
|
+
// #endregion Check AE Index
|
|
62
|
+
// #region Check Comparison
|
|
63
|
+
testGREATER(input) { }
|
|
60
64
|
}
|
|
61
65
|
__decorate([
|
|
62
66
|
REGEX.INVARIANT(/^a$/),
|
|
@@ -134,6 +138,12 @@ __decorate([
|
|
|
134
138
|
__metadata("design:paramtypes", [Array]),
|
|
135
139
|
__metadata("design:returntype", void 0)
|
|
136
140
|
], Demo.prototype, "testAEIndex", null);
|
|
141
|
+
__decorate([
|
|
142
|
+
__param(0, GREATER.PRE(2)),
|
|
143
|
+
__metadata("design:type", Function),
|
|
144
|
+
__metadata("design:paramtypes", [Number]),
|
|
145
|
+
__metadata("design:returntype", void 0)
|
|
146
|
+
], Demo.prototype, "testGREATER", null);
|
|
137
147
|
const demo = new Demo();
|
|
138
148
|
try {
|
|
139
149
|
demo.testProperty = "abd";
|
|
@@ -265,3 +275,16 @@ catch (X) {
|
|
|
265
275
|
console.log(X);
|
|
266
276
|
console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
|
|
267
277
|
}
|
|
278
|
+
demo.testGREATER(11);
|
|
279
|
+
console.log("⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄");
|
|
280
|
+
console.log("GREATER OK");
|
|
281
|
+
console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
|
|
282
|
+
try {
|
|
283
|
+
demo.testGREATER(2);
|
|
284
|
+
}
|
|
285
|
+
catch (X) {
|
|
286
|
+
console.log("⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄");
|
|
287
|
+
console.log("GREATER OK");
|
|
288
|
+
console.log(X);
|
|
289
|
+
console.log("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
|
|
290
|
+
}
|