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.
- package/Assessment.html +350 -0
- package/Assessment.md +507 -51
- package/CHANGELOG.md +55 -0
- package/CONTRIBUTING.md +129 -17
- package/README.md +373 -71
- package/SECURITY.md +60 -18
- package/SUPPORT.md +65 -0
- package/__tests__/DBC/DEFINED.test.ts +53 -0
- package/__tests__/DBC/Decorators.test.ts +365 -0
- package/__tests__/DBC/GREATER.test.ts +8 -6
- package/__tests__/DBC/HasAttribute.test.ts +56 -0
- package/__tests__/DBC/IF.test.ts +52 -0
- package/__tests__/DBC/JSON.Parse.test.ts +1 -1
- package/__tests__/DBC/OR.test.ts +1 -1
- package/__tests__/DBC/REGEX.test.ts +1 -1
- package/__tests__/DBC/TYPE.test.ts +1 -1
- package/__tests__/DBC/UNDEFINED.test.ts +45 -0
- package/__tests__/DBC/ZOD.test.ts +54 -0
- package/jest.config.js +21 -0
- package/package.json +4 -5
- package/src/DBC/AE.ts +10 -6
- package/src/DBC/COMPARISON/GREATER.ts +11 -7
- package/src/DBC/COMPARISON/GREATER_OR_EQUAL.ts +14 -10
- package/src/DBC/COMPARISON/LESS.ts +14 -10
- package/src/DBC/COMPARISON/LESS_OR_EQUAL.ts +14 -10
- package/src/DBC/COMPARISON.ts +20 -43
- package/src/DBC/DEFINED.ts +4 -23
- package/src/DBC/EQ/DIFFERENT.ts +21 -56
- package/src/DBC/EQ.ts +7 -26
- package/src/DBC/HasAttribute.ts +9 -26
- package/src/DBC/IF.ts +8 -27
- package/src/DBC/INSTANCE.ts +5 -22
- package/src/DBC/JSON.OP.ts +4 -34
- package/src/DBC/JSON.Parse.ts +5 -25
- package/src/DBC/OR.ts +5 -14
- package/src/DBC/REGEX.ts +41 -40
- package/src/DBC/TYPE.ts +6 -25
- package/src/DBC/UNDEFINED.ts +3 -22
- package/src/DBC/ZOD.ts +10 -27
- package/src/DBC.ts +223 -55
- package/tsconfig.json +7 -4
- package/tsconfig.test.json +12 -0
- package/.parcel-cache/bf96c58b6061a62a-BundleGraph +0 -0
- package/.parcel-cache/d7c812d65aeeac59-AssetGraph +0 -0
- package/.parcel-cache/data.mdb +0 -0
- package/.parcel-cache/e81759c1f106a17f-RequestGraph +0 -0
- package/.parcel-cache/fe0db3c4eb428be2-AssetGraph +0 -0
- package/.parcel-cache/lock.mdb +0 -0
- package/.parcel-cache/snapshot-e81759c1f106a17f.txt +0 -4609
- package/dist/DBC/AE.js +0 -173
- package/dist/DBC/COMPARISON/GREATER.js +0 -21
- package/dist/DBC/COMPARISON/GREATER_OR_EQUAL.js +0 -21
- package/dist/DBC/COMPARISON/LESS.js +0 -21
- package/dist/DBC/COMPARISON/LESS_OR_EQUAL.js +0 -21
- package/dist/DBC/COMPARISON.js +0 -99
- package/dist/DBC/DEFINED.js +0 -99
- package/dist/DBC/EQ/DIFFERENT.js +0 -21
- package/dist/DBC/EQ.js +0 -100
- package/dist/DBC/GREATER.js +0 -99
- package/dist/DBC/HasAttribute.js +0 -108
- package/dist/DBC/IF.js +0 -99
- package/dist/DBC/INSTANCE.js +0 -93
- package/dist/DBC/JSON.OP.js +0 -133
- package/dist/DBC/JSON.Parse.js +0 -114
- package/dist/DBC/OR.js +0 -113
- package/dist/DBC/REGEX.js +0 -110
- package/dist/DBC/TYPE.js +0 -87
- package/dist/DBC/ZOD.js +0 -114
- package/dist/DBC.js +0 -336
- package/dist/Demo.js +0 -290
- package/dist/Test.html +0 -18
- package/dist/bundle.js +0 -2064
- package/dist/index.html +0 -18
- package/jest.config.ts +0 -20
- package/xpackage-lock.json +0 -122
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IF } from "../../src/DBC/IF";
|
|
2
|
+
import { EQ } from "../../src/DBC/EQ";
|
|
3
|
+
import { TYPE } from "../../src/DBC/TYPE";
|
|
4
|
+
|
|
5
|
+
describe("IF", () => {
|
|
6
|
+
const isString = new TYPE("string");
|
|
7
|
+
const eqHello = new EQ("hello");
|
|
8
|
+
|
|
9
|
+
const ifContract = new IF(isString, eqHello);
|
|
10
|
+
|
|
11
|
+
test("Should not report infringement when condition matches and inCase is fulfilled", () => {
|
|
12
|
+
expect(ifContract.check("hello")).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("Should report infringement when condition matches but inCase is not fulfilled", () => {
|
|
16
|
+
expect(typeof ifContract.check("world")).toBe("string");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("Should not report infringement when condition does not match", () => {
|
|
20
|
+
expect(ifContract.check(42)).toBe(true);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("invert", () => {
|
|
24
|
+
const invertedContract = new IF(isString, eqHello, true);
|
|
25
|
+
|
|
26
|
+
test("Should not report infringement when condition does not match and inCase is fulfilled", () => {
|
|
27
|
+
expect(invertedContract.check("hello")).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("Should report infringement when condition does not match and inCase is not fulfilled", () => {
|
|
31
|
+
expect(typeof invertedContract.check(42)).toBe("string");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("Should not report infringement when condition matches", () => {
|
|
35
|
+
expect(invertedContract.check("world")).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe("checkAlgorithm", () => {
|
|
40
|
+
test("Should return true when condition not met", () => {
|
|
41
|
+
expect(IF.checkAlgorithm(123, isString, eqHello)).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("Should return string when condition met but inCase fails", () => {
|
|
45
|
+
expect(typeof IF.checkAlgorithm("notHello", isString, eqHello)).toBe("string");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("Should return true when both condition and inCase pass", () => {
|
|
49
|
+
expect(IF.checkAlgorithm("hello", isString, eqHello)).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
package/__tests__/DBC/OR.test.ts
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { UNDEFINED } from "../../src/DBC/UNDEFINED";
|
|
2
|
+
|
|
3
|
+
describe("UNDEFINED", () => {
|
|
4
|
+
const undef = new UNDEFINED();
|
|
5
|
+
|
|
6
|
+
test("Should not report infringement with undefined", () => {
|
|
7
|
+
expect(undef.check(undefined)).toBe(true);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("Should report infringement with null", () => {
|
|
11
|
+
expect(typeof undef.check(null)).toBe("string");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("Should report infringement with a string value", () => {
|
|
15
|
+
expect(typeof undef.check("hello")).toBe("string");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("Should report infringement with a number value", () => {
|
|
19
|
+
expect(typeof undef.check(42)).toBe("string");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("Should report infringement with zero", () => {
|
|
23
|
+
expect(typeof undef.check(0)).toBe("string");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("Should report infringement with false", () => {
|
|
27
|
+
expect(typeof undef.check(false)).toBe("string");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("Should report infringement with an empty string", () => {
|
|
31
|
+
expect(typeof undef.check("")).toBe("string");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("checkAlgorithm", () => {
|
|
35
|
+
test("Should return true for undefined", () => {
|
|
36
|
+
expect(UNDEFINED.checkAlgorithm(undefined)).toBe(true);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("Should return string for defined values", () => {
|
|
40
|
+
expect(typeof UNDEFINED.checkAlgorithm("test")).toBe("string");
|
|
41
|
+
expect(typeof UNDEFINED.checkAlgorithm(0)).toBe("string");
|
|
42
|
+
expect(typeof UNDEFINED.checkAlgorithm(null)).toBe("string");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ZOD } from "../../src/DBC/ZOD";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
describe("ZOD", () => {
|
|
5
|
+
describe("string schema", () => {
|
|
6
|
+
const zodString = new ZOD(z.string());
|
|
7
|
+
|
|
8
|
+
test("Should not report infringement with a string value", () => {
|
|
9
|
+
expect(zodString.check("hello")).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test("Should report infringement with a number value", () => {
|
|
13
|
+
expect(typeof zodString.check(42)).toBe("string");
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe("number schema", () => {
|
|
18
|
+
const zodNumber = new ZOD(z.number());
|
|
19
|
+
|
|
20
|
+
test("Should not report infringement with a number value", () => {
|
|
21
|
+
expect(zodNumber.check(42)).toBe(true);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("Should report infringement with a string value", () => {
|
|
25
|
+
expect(typeof zodNumber.check("hello")).toBe("string");
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("object schema", () => {
|
|
30
|
+
const zodObject = new ZOD(z.object({ name: z.string(), age: z.number() }));
|
|
31
|
+
|
|
32
|
+
test("Should not report infringement with a valid object", () => {
|
|
33
|
+
expect(zodObject.check({ name: "Alice", age: 30 })).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("Should report infringement with an invalid object", () => {
|
|
37
|
+
expect(typeof zodObject.check({ name: 123 })).toBe("string");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("Should report infringement with a non-object value", () => {
|
|
41
|
+
expect(typeof zodObject.check("not an object")).toBe("string");
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("checkAlgorithm", () => {
|
|
46
|
+
test("Should return true for valid value", () => {
|
|
47
|
+
expect(ZOD.checkAlgorithm("test", z.string())).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("Should return string for invalid value", () => {
|
|
51
|
+
expect(typeof ZOD.checkAlgorithm(42, z.string())).toBe("string");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
silent: true,
|
|
4
|
+
testPathIgnorePatterns: ["<rootDir>/dist/"],
|
|
5
|
+
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"],
|
|
6
|
+
preset: "ts-jest",
|
|
7
|
+
testEnvironment: "jsdom",
|
|
8
|
+
extensionsToTreatAsEsm: [".ts", ".tsx", ".jsx"],
|
|
9
|
+
moduleNameMapper: {
|
|
10
|
+
"^(\\.{1,2}/.*)\\.ts$": "$1",
|
|
11
|
+
},
|
|
12
|
+
transform: {
|
|
13
|
+
"^.+\\.(ts|tsx)?$": [
|
|
14
|
+
"ts-jest",
|
|
15
|
+
{
|
|
16
|
+
allowImportingTsExtensions: true,
|
|
17
|
+
tsconfig: "tsconfig.test.json",
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
};
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.
|
|
2
|
+
"version": "1.0.209",
|
|
3
3
|
"name": "xdbc",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"docs": "typedoc",
|
|
@@ -13,12 +13,11 @@
|
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@babel/core": "^7.27.1",
|
|
15
15
|
"@babel/preset-env": "^7.27.2",
|
|
16
|
-
"@types/express": "^5.0.1",
|
|
17
16
|
"@types/jest": "^29.5.14",
|
|
18
17
|
"@types/node": "^22.15.17",
|
|
19
18
|
"babel-jest": "^29.7.0",
|
|
20
19
|
"jest": "^29.7.0",
|
|
21
|
-
"jest-environment-jsdom": "^
|
|
20
|
+
"jest-environment-jsdom": "^30.3.0",
|
|
22
21
|
"ts-jest": "^29.3.2",
|
|
23
22
|
"ts-loader": "^9.5.2",
|
|
24
23
|
"ts-node": "^10.9.2",
|
|
@@ -30,8 +29,8 @@
|
|
|
30
29
|
},
|
|
31
30
|
"dependencies": {
|
|
32
31
|
"@types/reflect-metadata": "^0.1.0",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
32
|
+
"reflect-metadata": "^0.2.2",
|
|
33
|
+
"zod": "^3.25.0"
|
|
35
34
|
},
|
|
36
35
|
"description": "A Typescript Design by Contract Framework",
|
|
37
36
|
"repository": {
|
package/src/DBC/AE.ts
CHANGED
|
@@ -105,9 +105,10 @@ export class AE extends DBC {
|
|
|
105
105
|
) => void {
|
|
106
106
|
return DBC.decPrecondition(
|
|
107
107
|
(
|
|
108
|
-
|
|
108
|
+
// biome-ignore lint/suspicious/noExplicitAny: Must match DBC.decPrecondition signature
|
|
109
|
+
value: any,
|
|
109
110
|
target: object,
|
|
110
|
-
methodName: string,
|
|
111
|
+
methodName: string | symbol,
|
|
111
112
|
parameterIndex: number,
|
|
112
113
|
) => {
|
|
113
114
|
if (Array.isArray(realConditions)) {
|
|
@@ -222,7 +223,7 @@ export class AE extends DBC {
|
|
|
222
223
|
hint: string | undefined = undefined,
|
|
223
224
|
dbc: string | undefined = undefined,
|
|
224
225
|
) {
|
|
225
|
-
return DBC.
|
|
226
|
+
return DBC.createINVARIANT(AE, [realConditions, index, idxEnd], dbc, path, hint);
|
|
226
227
|
}
|
|
227
228
|
// #endregion Condition checking.
|
|
228
229
|
// #region Referenced Condition checking.
|
|
@@ -236,7 +237,8 @@ export class AE extends DBC {
|
|
|
236
237
|
* @param toCheck See {@link AE.checkAlgorithm }.
|
|
237
238
|
*
|
|
238
239
|
* @returns See {@link EQ.checkAlgorithm}. */
|
|
239
|
-
|
|
240
|
+
// biome-ignore lint/suspicious/noExplicitAny: Must match DBC factory signature
|
|
241
|
+
public check(toCheck: any) {
|
|
240
242
|
if (Array.isArray(this.conditions)) {
|
|
241
243
|
for (const currentCondition of this.conditions) {
|
|
242
244
|
const result = AE.checkAlgorithm(
|
|
@@ -266,10 +268,12 @@ export class AE extends DBC {
|
|
|
266
268
|
* @param equivalent See {@link EQ.check }. */
|
|
267
269
|
public constructor(
|
|
268
270
|
protected conditions:
|
|
271
|
+
// biome-ignore lint/suspicious/noExplicitAny: Must match DBC factory signature
|
|
269
272
|
| Array<{
|
|
270
|
-
check: (toCheck:
|
|
273
|
+
check: (toCheck: any) => boolean | string;
|
|
271
274
|
}>
|
|
272
|
-
|
|
275
|
+
// biome-ignore lint/suspicious/noExplicitAny: Must match DBC factory signature
|
|
276
|
+
| { check: (toCheck: any) => boolean | string },
|
|
273
277
|
protected index: number | undefined = undefined,
|
|
274
278
|
protected idxEnd: number | undefined = undefined,
|
|
275
279
|
) {
|
|
@@ -3,11 +3,12 @@ import { COMPARISON } from "../COMPARISON";
|
|
|
3
3
|
export class GREATER extends COMPARISON {
|
|
4
4
|
/** See {@link COMPARISON.PRE }. */
|
|
5
5
|
public static override PRE(
|
|
6
|
-
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
7
|
+
equivalent: any,
|
|
7
8
|
equalityPermitted = false,
|
|
8
9
|
invert = false,
|
|
9
10
|
|
|
10
|
-
path: string = undefined,
|
|
11
|
+
path: string | undefined = undefined,
|
|
11
12
|
hint: string | undefined = undefined,
|
|
12
13
|
dbc: string | undefined = undefined,
|
|
13
14
|
) {
|
|
@@ -15,10 +16,11 @@ export class GREATER extends COMPARISON {
|
|
|
15
16
|
}
|
|
16
17
|
/** See {@link COMPARISON.POST }. */
|
|
17
18
|
public static override POST(
|
|
18
|
-
|
|
19
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
20
|
+
equivalent: any,
|
|
19
21
|
equalityPermitted = false,
|
|
20
22
|
invert = false,
|
|
21
|
-
path: string = undefined,
|
|
23
|
+
path: string | undefined = undefined,
|
|
22
24
|
hint: string | undefined = undefined,
|
|
23
25
|
dbc: string | undefined = undefined
|
|
24
26
|
) {
|
|
@@ -26,17 +28,19 @@ export class GREATER extends COMPARISON {
|
|
|
26
28
|
}
|
|
27
29
|
/** See {@link COMPARISON.INVARIANT }. */
|
|
28
30
|
public static override INVARIANT(
|
|
29
|
-
|
|
31
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
32
|
+
equivalent: any,
|
|
30
33
|
equalityPermitted = false,
|
|
31
34
|
invert = false,
|
|
32
|
-
path: string = undefined,
|
|
35
|
+
path: string | undefined = undefined,
|
|
33
36
|
hint: string | undefined = undefined,
|
|
34
37
|
dbc: string | undefined = undefined
|
|
35
38
|
) {
|
|
36
39
|
return COMPARISON.INVARIANT(equivalent, false, false, path, hint, dbc);
|
|
37
40
|
}
|
|
38
41
|
/** See {@link COMPARISON.constructor }. */
|
|
39
|
-
|
|
42
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
43
|
+
constructor(public override equivalent: any) {
|
|
40
44
|
super(equivalent, false, false);
|
|
41
45
|
}
|
|
42
46
|
}
|
|
@@ -3,39 +3,43 @@ import { COMPARISON } from "../COMPARISON";
|
|
|
3
3
|
export class GREATER_OR_EQUAL extends COMPARISON {
|
|
4
4
|
/** See {@link COMPARISON.PRE }. */
|
|
5
5
|
public static override PRE(
|
|
6
|
-
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
7
|
+
equivalent: any,
|
|
7
8
|
equalityPermitted = false,
|
|
8
9
|
invert = false,
|
|
9
|
-
path: string = undefined,
|
|
10
|
+
path: string | undefined = undefined,
|
|
10
11
|
hint: string | undefined = undefined,
|
|
11
12
|
dbc: string | undefined = undefined,
|
|
12
13
|
) {
|
|
13
|
-
return COMPARISON.PRE(equivalent, true, false, path,
|
|
14
|
+
return COMPARISON.PRE(equivalent, true, false, path, hint, dbc);
|
|
14
15
|
}
|
|
15
16
|
/** See {@link COMPARISON.POST }. */
|
|
16
17
|
public static override POST(
|
|
17
|
-
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
19
|
+
equivalent: any,
|
|
18
20
|
equalityPermitted = false,
|
|
19
21
|
invert = false,
|
|
20
|
-
path: string = undefined,
|
|
22
|
+
path: string | undefined = undefined,
|
|
21
23
|
hint: string | undefined = undefined,
|
|
22
24
|
dbc: string | undefined = undefined,
|
|
23
25
|
) {
|
|
24
|
-
return COMPARISON.POST(equivalent, true, false, path,
|
|
26
|
+
return COMPARISON.POST(equivalent, true, false, path, hint, dbc);
|
|
25
27
|
}
|
|
26
28
|
/** See {@link COMPARISON.INVARIANT }. */
|
|
27
29
|
public static INVARIANT(
|
|
28
|
-
|
|
30
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
31
|
+
equivalent: any,
|
|
29
32
|
equalityPermitted = false,
|
|
30
33
|
invert = false,
|
|
31
|
-
path: string = undefined,
|
|
34
|
+
path: string | undefined = undefined,
|
|
32
35
|
hint: string | undefined = undefined,
|
|
33
36
|
dbc: string | undefined = undefined,
|
|
34
37
|
) {
|
|
35
|
-
return COMPARISON.INVARIANT(equivalent, true, false, path,
|
|
38
|
+
return COMPARISON.INVARIANT(equivalent, true, false, path, hint, dbc);
|
|
36
39
|
}
|
|
37
40
|
/** See {@link COMPARISON.constructor }. */
|
|
38
|
-
|
|
41
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
42
|
+
constructor(public equivalent: any) {
|
|
39
43
|
super(equivalent, true, false);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -3,39 +3,43 @@ import { COMPARISON } from "../COMPARISON";
|
|
|
3
3
|
export class LESS extends COMPARISON {
|
|
4
4
|
/** See {@link COMPARISON.PRE }. */
|
|
5
5
|
public static override PRE(
|
|
6
|
-
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
7
|
+
equivalent: any,
|
|
7
8
|
equalityPermitted = false,
|
|
8
9
|
invert = false,
|
|
9
|
-
path: string = undefined,
|
|
10
|
+
path: string | undefined = undefined,
|
|
10
11
|
hint: string | undefined = undefined,
|
|
11
12
|
dbc: string | undefined = undefined,
|
|
12
13
|
) {
|
|
13
|
-
return COMPARISON.PRE(equivalent, false, true, path,
|
|
14
|
+
return COMPARISON.PRE(equivalent, false, true, path, hint, dbc);
|
|
14
15
|
}
|
|
15
16
|
/** See {@link COMPARISON.POST }. */
|
|
16
17
|
public static override POST(
|
|
17
|
-
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
19
|
+
equivalent: any,
|
|
18
20
|
equalityPermitted = false,
|
|
19
21
|
invert = false,
|
|
20
|
-
path: string = undefined,
|
|
22
|
+
path: string | undefined = undefined,
|
|
21
23
|
hint: string | undefined = undefined,
|
|
22
24
|
dbc: string | undefined = undefined,
|
|
23
25
|
) {
|
|
24
|
-
return COMPARISON.POST(equivalent, false, true, path,
|
|
26
|
+
return COMPARISON.POST(equivalent, false, true, path, hint, dbc);
|
|
25
27
|
}
|
|
26
28
|
/** See {@link COMPARISON.INVARIANT }. */
|
|
27
29
|
public static INVARIANT(
|
|
28
|
-
|
|
30
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
31
|
+
equivalent: any,
|
|
29
32
|
equalityPermitted = false,
|
|
30
33
|
invert = false,
|
|
31
|
-
path: string = undefined,
|
|
34
|
+
path: string | undefined = undefined,
|
|
32
35
|
hint: string | undefined = undefined,
|
|
33
36
|
dbc: string | undefined = undefined,
|
|
34
37
|
) {
|
|
35
|
-
return COMPARISON.INVARIANT(equivalent, false, true, path,
|
|
38
|
+
return COMPARISON.INVARIANT(equivalent, false, true, path, hint, dbc);
|
|
36
39
|
}
|
|
37
40
|
/** See {@link COMPARISON.constructor }. */
|
|
38
|
-
|
|
41
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
42
|
+
constructor(public equivalent: any) {
|
|
39
43
|
super(equivalent, false, true);
|
|
40
44
|
}
|
|
41
45
|
}
|
|
@@ -3,39 +3,43 @@ import { COMPARISON } from "../COMPARISON";
|
|
|
3
3
|
export class LESS_OR_EQUAL extends COMPARISON {
|
|
4
4
|
/** See {@link COMPARISON.PRE }. */
|
|
5
5
|
public static override PRE(
|
|
6
|
-
|
|
6
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
7
|
+
equivalent: any,
|
|
7
8
|
equalityPermitted = false,
|
|
8
9
|
invert = false,
|
|
9
|
-
path: string = undefined,
|
|
10
|
+
path: string | undefined = undefined,
|
|
10
11
|
hint: string | undefined = undefined,
|
|
11
12
|
dbc: string | undefined = undefined,
|
|
12
13
|
) {
|
|
13
|
-
return COMPARISON.PRE(equivalent, true, true, path,
|
|
14
|
+
return COMPARISON.PRE(equivalent, true, true, path, hint, dbc);
|
|
14
15
|
}
|
|
15
16
|
/** See {@link COMPARISON.POST }. */
|
|
16
17
|
public static override POST(
|
|
17
|
-
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
19
|
+
equivalent: any,
|
|
18
20
|
equalityPermitted = false,
|
|
19
21
|
invert = false,
|
|
20
|
-
path: string = undefined,
|
|
22
|
+
path: string | undefined = undefined,
|
|
21
23
|
hint: string | undefined = undefined,
|
|
22
24
|
dbc: string | undefined = undefined,
|
|
23
25
|
) {
|
|
24
|
-
return COMPARISON.POST(equivalent, true, true, path,
|
|
26
|
+
return COMPARISON.POST(equivalent, true, true, path, hint, dbc);
|
|
25
27
|
}
|
|
26
28
|
/** See {@link COMPARISON.INVARIANT }. */
|
|
27
29
|
public static INVARIANT(
|
|
28
|
-
|
|
30
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
31
|
+
equivalent: any,
|
|
29
32
|
equalityPermitted = false,
|
|
30
33
|
invert = false,
|
|
31
|
-
path: string = undefined,
|
|
34
|
+
path: string | undefined = undefined,
|
|
32
35
|
hint: string | undefined = undefined,
|
|
33
36
|
dbc: string | undefined = undefined,
|
|
34
37
|
) {
|
|
35
|
-
return COMPARISON.INVARIANT(equivalent, true, true, path,
|
|
38
|
+
return COMPARISON.INVARIANT(equivalent, true, true, path, hint, dbc);
|
|
36
39
|
}
|
|
37
40
|
/** See {@link COMPARISON.constructor }. */
|
|
38
|
-
|
|
41
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
42
|
+
constructor(public equivalent: any) {
|
|
39
43
|
super(equivalent, true, true);
|
|
40
44
|
}
|
|
41
45
|
}
|
package/src/DBC/COMPARISON.ts
CHANGED
|
@@ -14,9 +14,10 @@ export class COMPARISON extends DBC {
|
|
|
14
14
|
* fulfilled.
|
|
15
15
|
*
|
|
16
16
|
* @returns TRUE if the value **toCheck** and the **equivalent** are equal to each other, otherwise FALSE. */
|
|
17
|
-
|
|
17
|
+
// biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic comparison
|
|
18
|
+
static checkAlgorithm(toCheck: any, equivalent: any, equalityPermitted: boolean, invert: boolean) {
|
|
18
19
|
if (equalityPermitted && !invert && toCheck < equivalent) {
|
|
19
|
-
return `Value has to
|
|
20
|
+
return `Value has to be greater than or equal to "${equivalent}"`;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
if (equalityPermitted && invert && toCheck > equivalent) {
|
|
@@ -24,7 +25,7 @@ export class COMPARISON extends DBC {
|
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
if (!equalityPermitted && !invert && toCheck <= equivalent) {
|
|
27
|
-
return `Value has to
|
|
28
|
+
return `Value has to be greater than "${equivalent}"`;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
if (!equalityPermitted && invert && toCheck >= equivalent) {
|
|
@@ -45,26 +46,15 @@ export class COMPARISON extends DBC {
|
|
|
45
46
|
*
|
|
46
47
|
* @returns See {@link DBC.decPrecondition }. */
|
|
47
48
|
static PRE(
|
|
48
|
-
|
|
49
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
50
|
+
equivalent: any,
|
|
49
51
|
equalityPermitted = false,
|
|
50
52
|
invert = false,
|
|
51
|
-
path: string = undefined,
|
|
53
|
+
path: string | undefined = undefined,
|
|
52
54
|
hint: string | undefined = undefined,
|
|
53
55
|
dbc: string | undefined = undefined,
|
|
54
56
|
) {
|
|
55
|
-
return DBC.
|
|
56
|
-
(value, target, methodName, parameterIndex) => {
|
|
57
|
-
return COMPARISON.checkAlgorithm(
|
|
58
|
-
value,
|
|
59
|
-
equivalent,
|
|
60
|
-
equalityPermitted,
|
|
61
|
-
invert,
|
|
62
|
-
);
|
|
63
|
-
},
|
|
64
|
-
dbc,
|
|
65
|
-
path,
|
|
66
|
-
hint
|
|
67
|
-
);
|
|
57
|
+
return DBC.createPRE(COMPARISON.checkAlgorithm, [equivalent, equalityPermitted, invert], dbc, path, hint);
|
|
68
58
|
}
|
|
69
59
|
/**
|
|
70
60
|
* A method-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -78,26 +68,15 @@ export class COMPARISON extends DBC {
|
|
|
78
68
|
*
|
|
79
69
|
* @returns See {@link DBC.decPostcondition }. */
|
|
80
70
|
static POST(
|
|
81
|
-
|
|
71
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
72
|
+
equivalent: any,
|
|
82
73
|
equalityPermitted = false,
|
|
83
74
|
invert = false,
|
|
84
|
-
path: string = undefined,
|
|
75
|
+
path: string | undefined = undefined,
|
|
85
76
|
hint: string | undefined = undefined,
|
|
86
77
|
dbc: string | undefined = undefined,
|
|
87
78
|
) {
|
|
88
|
-
return DBC.
|
|
89
|
-
(value, target, propertyKey) => {
|
|
90
|
-
return COMPARISON.checkAlgorithm(
|
|
91
|
-
value,
|
|
92
|
-
equalityPermitted,
|
|
93
|
-
equivalent,
|
|
94
|
-
invert,
|
|
95
|
-
);
|
|
96
|
-
},
|
|
97
|
-
dbc,
|
|
98
|
-
path,
|
|
99
|
-
hint
|
|
100
|
-
);
|
|
79
|
+
return DBC.createPOST(COMPARISON.checkAlgorithm, [equivalent, equalityPermitted, invert], dbc, path, hint);
|
|
101
80
|
}
|
|
102
81
|
/**
|
|
103
82
|
* A field-decorator factory using the {@link COMPARISON.checkAlgorithm } to determine whether this {@link DBC } is fulfilled
|
|
@@ -111,19 +90,15 @@ export class COMPARISON extends DBC {
|
|
|
111
90
|
*
|
|
112
91
|
* @returns See {@link DBC.decInvariant }. */
|
|
113
92
|
static INVARIANT(
|
|
114
|
-
|
|
93
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
94
|
+
equivalent: any,
|
|
115
95
|
equalityPermitted = false,
|
|
116
96
|
invert = false,
|
|
117
|
-
path: string = undefined,
|
|
97
|
+
path: string | undefined = undefined,
|
|
118
98
|
hint: string | undefined = undefined,
|
|
119
99
|
dbc: string | undefined = undefined,
|
|
120
100
|
) {
|
|
121
|
-
return DBC.
|
|
122
|
-
[new COMPARISON(equivalent, equalityPermitted, invert)],
|
|
123
|
-
dbc,
|
|
124
|
-
path,
|
|
125
|
-
hint
|
|
126
|
-
);
|
|
101
|
+
return DBC.createINVARIANT(COMPARISON, [equivalent, equalityPermitted, invert], dbc, path, hint);
|
|
127
102
|
}
|
|
128
103
|
// #endregion Condition checking.
|
|
129
104
|
// #region Referenced Condition checking.
|
|
@@ -134,7 +109,8 @@ export class COMPARISON extends DBC {
|
|
|
134
109
|
* @param toCheck See {@link COMPARISON.checkAlgorithm }.
|
|
135
110
|
*
|
|
136
111
|
* @returns See {@link COMPARISON.checkAlgorithm}. */
|
|
137
|
-
|
|
112
|
+
// biome-ignore lint/suspicious/noExplicitAny: Necessary for dynamic comparison
|
|
113
|
+
public check(toCheck: any) {
|
|
138
114
|
return COMPARISON.checkAlgorithm(
|
|
139
115
|
toCheck,
|
|
140
116
|
this.equivalent,
|
|
@@ -149,7 +125,8 @@ export class COMPARISON extends DBC {
|
|
|
149
125
|
* @param equalityPermitted See {@link COMPARISON.check }.
|
|
150
126
|
* @param invert See {@link COMPARISON.check }. */
|
|
151
127
|
constructor(
|
|
152
|
-
|
|
128
|
+
// biome-ignore lint/suspicious/noExplicitAny: Comparison target can be any numeric value
|
|
129
|
+
public equivalent: any,
|
|
153
130
|
public equalityPermitted = false,
|
|
154
131
|
public invert = false,
|
|
155
132
|
) {
|