@media-quest/engine 0.0.22 → 0.0.24
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/package.json +1 -1
- package/src/Delement/DElement.dto.ts +5 -5
- package/src/Delement/DElement.ts +88 -88
- package/src/Delement/DImg.ts +39 -39
- package/src/Delement/DStyle-utils.ts +616 -616
- package/src/Delement/DStyle.ts +165 -165
- package/src/Delement/DText.ts +13 -13
- package/src/Delement/Ddiv.ts +25 -25
- package/src/Delement/button-click-action.ts +35 -35
- package/src/Delement/css.spec.ts +36 -36
- package/src/Delement/css.ts +46 -46
- package/src/Delement/element-factory.ts +40 -40
- package/src/common/DMaybe.ts +46 -46
- package/src/common/DTimestamp.ts +20 -20
- package/src/common/DTmestamp.spec.ts +11 -11
- package/src/common/result.ts +41 -41
- package/src/engine/SchemaDto.ts +24 -24
- package/src/engine/SchemaEngine.ts +150 -150
- package/src/engine/SchemaResult.ts +10 -10
- package/src/engine/dplayer.spec.ts +91 -91
- package/src/engine/dplayer.ts +104 -104
- package/src/engine/history-que.spec.ts +67 -67
- package/src/engine/history-que.ts +17 -17
- package/src/engine/next-que.spec.ts +121 -121
- package/src/engine/next-que.ts +101 -101
- package/src/engine/page-que-ruleengine-action.ts +6 -6
- package/src/engine/scale.spec.ts +38 -38
- package/src/engine/scale.ts +70 -70
- package/src/events/mq-events.ts +63 -63
- package/src/page/Page.ts +182 -182
- package/src/page/media-player.ts +117 -117
- package/src/page/page-component.ts +113 -113
- package/src/page/page-result.ts +11 -11
- package/src/page/task-manager.ts +240 -240
- package/src/page/task-state.ts +55 -55
- package/src/page/task.ts +90 -90
- package/src/public-api.ts +26 -26
- package/src/rules/__test__/complex-condition.spec.ts +15 -15
- package/src/rules/__test__/conditon.spec.ts +124 -124
- package/src/rules/__test__/numeric-condition.spec.ts +84 -84
- package/src/rules/__test__/rule-engine.spec.ts +348 -348
- package/src/rules/__test__/rule-evaluation.spec.ts +140 -140
- package/src/rules/__test__/string-condition.spec.ts +41 -41
- package/src/rules/condition.ts +191 -191
- package/src/rules/fact.ts +18 -18
- package/src/rules/rule-engine.ts +45 -45
- package/src/rules/rule.ts +40 -40
- package/src/utils/DUtil.ts +116 -116
- package/src/utils/ID.spec.ts +39 -39
- package/src/utils/ID.ts +73 -73
- package/tsconfig.json +19 -19
|
@@ -1,140 +1,140 @@
|
|
|
1
|
-
import { Rule } from "../rule";
|
|
2
|
-
import { Fact } from "../fact";
|
|
3
|
-
import { Condition } from "../condition";
|
|
4
|
-
|
|
5
|
-
const xIs = (value: number): Fact.Numeric => ({
|
|
6
|
-
referenceId: "x",
|
|
7
|
-
referenceLabel: "x-label",
|
|
8
|
-
label: "label for x",
|
|
9
|
-
value,
|
|
10
|
-
kind: "numeric-fact",
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const yIs = (value: number): Fact.Numeric => ({
|
|
14
|
-
kind: "numeric-fact",
|
|
15
|
-
referenceId: "y",
|
|
16
|
-
referenceLabel: "y-label",
|
|
17
|
-
label: "value-label-y",
|
|
18
|
-
// valueLabel: 'value-label-y',
|
|
19
|
-
value,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
const conditionFactory =
|
|
23
|
-
(factId: string) =>
|
|
24
|
-
(op: Condition.NumericOperator) =>
|
|
25
|
-
(value: number): Condition.Numeric => ({
|
|
26
|
-
kind: "numeric-condition",
|
|
27
|
-
referenceId: factId,
|
|
28
|
-
operator: op,
|
|
29
|
-
value,
|
|
30
|
-
referenceLabel: "fact-label",
|
|
31
|
-
valueLabel: "value-label",
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Conditon helpers
|
|
35
|
-
const xConditionFactory = conditionFactory("x");
|
|
36
|
-
const xEq = xConditionFactory("eq");
|
|
37
|
-
const xLessThan = xConditionFactory("less-then");
|
|
38
|
-
const xGreaterThan = xConditionFactory("greater-then");
|
|
39
|
-
|
|
40
|
-
const yConditionFactory = conditionFactory("y");
|
|
41
|
-
const yEq = yConditionFactory("eq");
|
|
42
|
-
const yLessThan = yConditionFactory("less-then");
|
|
43
|
-
const yGreaterThan = yConditionFactory("greater-then");
|
|
44
|
-
|
|
45
|
-
const con = {
|
|
46
|
-
xEq,
|
|
47
|
-
xLessThan,
|
|
48
|
-
xGreaterThan,
|
|
49
|
-
yEq,
|
|
50
|
-
yLessThan,
|
|
51
|
-
yGreaterThan,
|
|
52
|
-
} as const;
|
|
53
|
-
|
|
54
|
-
const complex = (all: ReadonlyArray<Condition.Simple>, some: ReadonlyArray<Condition.Simple>): Condition.Complex => ({
|
|
55
|
-
name: "test-name",
|
|
56
|
-
kind: "complex-condition",
|
|
57
|
-
all,
|
|
58
|
-
some,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const createRule = (all: ReadonlyArray<Condition>, some: ReadonlyArray<Condition>): Rule<any, any> => {
|
|
62
|
-
const rule: Rule<any, any> = {
|
|
63
|
-
id: "xyz",
|
|
64
|
-
description: "",
|
|
65
|
-
some,
|
|
66
|
-
all,
|
|
67
|
-
onSuccess: [],
|
|
68
|
-
onFailure: [],
|
|
69
|
-
};
|
|
70
|
-
return rule;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
describe("Rule-evaluation works", () => {
|
|
74
|
-
it("A empty rule is not valid, and will always return false", () => {
|
|
75
|
-
expect(Rule.solve(createRule([], []), [])).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it("One all condition is true => true", () => {
|
|
79
|
-
const all: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
80
|
-
const some: ReadonlyArray<Condition> = [];
|
|
81
|
-
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
82
|
-
const rule = createRule(all, some);
|
|
83
|
-
expect(Rule.solve(rule, facts)).toEqual(true);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("one some condition is true => true", () => {
|
|
87
|
-
const all: ReadonlyArray<Condition> = [];
|
|
88
|
-
const some: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
89
|
-
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
90
|
-
const rule = createRule(all, some);
|
|
91
|
-
expect(Rule.solve(rule, facts)).toEqual(true);
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("one some condition is true, but all condition is false => false", () => {
|
|
95
|
-
const all: ReadonlyArray<Condition> = [con.xEq(6)];
|
|
96
|
-
const some: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
97
|
-
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
98
|
-
const rule = createRule(all, some);
|
|
99
|
-
expect(Rule.solve(rule, facts)).toEqual(false);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("some is empty, and all is not all true => false", () => {
|
|
103
|
-
const all: ReadonlyArray<Condition> = [con.xEq(6), con.xEq(0)];
|
|
104
|
-
const some: ReadonlyArray<Condition> = [];
|
|
105
|
-
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
106
|
-
const rule = createRule(all, some);
|
|
107
|
-
expect(Rule.solve(rule, facts)).toEqual(false);
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("some is false, and all is not all true => false", () => {
|
|
111
|
-
const all: ReadonlyArray<Condition> = [con.xEq(6), con.xEq(0)];
|
|
112
|
-
const some: ReadonlyArray<Condition> = [con.xLessThan(-2)];
|
|
113
|
-
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
114
|
-
const rule = createRule(all, some);
|
|
115
|
-
expect(Rule.solve(rule, facts)).toEqual(false);
|
|
116
|
-
});
|
|
117
|
-
it("If one all-condition is true -> true", () => {
|
|
118
|
-
const all: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
119
|
-
const some: ReadonlyArray<Condition> = [];
|
|
120
|
-
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
121
|
-
const rule = createRule(all, some);
|
|
122
|
-
expect(Rule.solve(rule, facts)).toBe(true);
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it("All all-condition is true, and some is empty -> true", () => {
|
|
126
|
-
const all: ReadonlyArray<Condition> = [con.xEq(0), con.xLessThan(8), con.xGreaterThan(-1)];
|
|
127
|
-
const some: ReadonlyArray<Condition> = [];
|
|
128
|
-
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
129
|
-
const rule = createRule(all, some);
|
|
130
|
-
expect(Rule.solve(rule, facts)).toBe(true);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("All all-condition is true, and none in some is true -> false", () => {
|
|
134
|
-
const all: ReadonlyArray<Condition> = [con.xEq(0), con.xLessThan(8), con.xGreaterThan(-1), con.yEq(9)];
|
|
135
|
-
const some: ReadonlyArray<Condition> = [con.yLessThan(9)];
|
|
136
|
-
const facts: ReadonlyArray<Fact> = [xIs(0), yIs(9)];
|
|
137
|
-
const rule = createRule(all, some);
|
|
138
|
-
expect(Rule.solve(rule, facts)).toBe(false);
|
|
139
|
-
});
|
|
140
|
-
});
|
|
1
|
+
import { Rule } from "../rule";
|
|
2
|
+
import { Fact } from "../fact";
|
|
3
|
+
import { Condition } from "../condition";
|
|
4
|
+
|
|
5
|
+
const xIs = (value: number): Fact.Numeric => ({
|
|
6
|
+
referenceId: "x",
|
|
7
|
+
referenceLabel: "x-label",
|
|
8
|
+
label: "label for x",
|
|
9
|
+
value,
|
|
10
|
+
kind: "numeric-fact",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const yIs = (value: number): Fact.Numeric => ({
|
|
14
|
+
kind: "numeric-fact",
|
|
15
|
+
referenceId: "y",
|
|
16
|
+
referenceLabel: "y-label",
|
|
17
|
+
label: "value-label-y",
|
|
18
|
+
// valueLabel: 'value-label-y',
|
|
19
|
+
value,
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const conditionFactory =
|
|
23
|
+
(factId: string) =>
|
|
24
|
+
(op: Condition.NumericOperator) =>
|
|
25
|
+
(value: number): Condition.Numeric => ({
|
|
26
|
+
kind: "numeric-condition",
|
|
27
|
+
referenceId: factId,
|
|
28
|
+
operator: op,
|
|
29
|
+
value,
|
|
30
|
+
referenceLabel: "fact-label",
|
|
31
|
+
valueLabel: "value-label",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Conditon helpers
|
|
35
|
+
const xConditionFactory = conditionFactory("x");
|
|
36
|
+
const xEq = xConditionFactory("eq");
|
|
37
|
+
const xLessThan = xConditionFactory("less-then");
|
|
38
|
+
const xGreaterThan = xConditionFactory("greater-then");
|
|
39
|
+
|
|
40
|
+
const yConditionFactory = conditionFactory("y");
|
|
41
|
+
const yEq = yConditionFactory("eq");
|
|
42
|
+
const yLessThan = yConditionFactory("less-then");
|
|
43
|
+
const yGreaterThan = yConditionFactory("greater-then");
|
|
44
|
+
|
|
45
|
+
const con = {
|
|
46
|
+
xEq,
|
|
47
|
+
xLessThan,
|
|
48
|
+
xGreaterThan,
|
|
49
|
+
yEq,
|
|
50
|
+
yLessThan,
|
|
51
|
+
yGreaterThan,
|
|
52
|
+
} as const;
|
|
53
|
+
|
|
54
|
+
const complex = (all: ReadonlyArray<Condition.Simple>, some: ReadonlyArray<Condition.Simple>): Condition.Complex => ({
|
|
55
|
+
name: "test-name",
|
|
56
|
+
kind: "complex-condition",
|
|
57
|
+
all,
|
|
58
|
+
some,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const createRule = (all: ReadonlyArray<Condition>, some: ReadonlyArray<Condition>): Rule<any, any> => {
|
|
62
|
+
const rule: Rule<any, any> = {
|
|
63
|
+
id: "xyz",
|
|
64
|
+
description: "",
|
|
65
|
+
some,
|
|
66
|
+
all,
|
|
67
|
+
onSuccess: [],
|
|
68
|
+
onFailure: [],
|
|
69
|
+
};
|
|
70
|
+
return rule;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
describe("Rule-evaluation works", () => {
|
|
74
|
+
it("A empty rule is not valid, and will always return false", () => {
|
|
75
|
+
expect(Rule.solve(createRule([], []), [])).toBe(false);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("One all condition is true => true", () => {
|
|
79
|
+
const all: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
80
|
+
const some: ReadonlyArray<Condition> = [];
|
|
81
|
+
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
82
|
+
const rule = createRule(all, some);
|
|
83
|
+
expect(Rule.solve(rule, facts)).toEqual(true);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("one some condition is true => true", () => {
|
|
87
|
+
const all: ReadonlyArray<Condition> = [];
|
|
88
|
+
const some: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
89
|
+
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
90
|
+
const rule = createRule(all, some);
|
|
91
|
+
expect(Rule.solve(rule, facts)).toEqual(true);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("one some condition is true, but all condition is false => false", () => {
|
|
95
|
+
const all: ReadonlyArray<Condition> = [con.xEq(6)];
|
|
96
|
+
const some: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
97
|
+
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
98
|
+
const rule = createRule(all, some);
|
|
99
|
+
expect(Rule.solve(rule, facts)).toEqual(false);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("some is empty, and all is not all true => false", () => {
|
|
103
|
+
const all: ReadonlyArray<Condition> = [con.xEq(6), con.xEq(0)];
|
|
104
|
+
const some: ReadonlyArray<Condition> = [];
|
|
105
|
+
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
106
|
+
const rule = createRule(all, some);
|
|
107
|
+
expect(Rule.solve(rule, facts)).toEqual(false);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("some is false, and all is not all true => false", () => {
|
|
111
|
+
const all: ReadonlyArray<Condition> = [con.xEq(6), con.xEq(0)];
|
|
112
|
+
const some: ReadonlyArray<Condition> = [con.xLessThan(-2)];
|
|
113
|
+
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
114
|
+
const rule = createRule(all, some);
|
|
115
|
+
expect(Rule.solve(rule, facts)).toEqual(false);
|
|
116
|
+
});
|
|
117
|
+
it("If one all-condition is true -> true", () => {
|
|
118
|
+
const all: ReadonlyArray<Condition> = [con.xEq(0)];
|
|
119
|
+
const some: ReadonlyArray<Condition> = [];
|
|
120
|
+
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
121
|
+
const rule = createRule(all, some);
|
|
122
|
+
expect(Rule.solve(rule, facts)).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("All all-condition is true, and some is empty -> true", () => {
|
|
126
|
+
const all: ReadonlyArray<Condition> = [con.xEq(0), con.xLessThan(8), con.xGreaterThan(-1)];
|
|
127
|
+
const some: ReadonlyArray<Condition> = [];
|
|
128
|
+
const facts: ReadonlyArray<Fact> = [xIs(0)];
|
|
129
|
+
const rule = createRule(all, some);
|
|
130
|
+
expect(Rule.solve(rule, facts)).toBe(true);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("All all-condition is true, and none in some is true -> false", () => {
|
|
134
|
+
const all: ReadonlyArray<Condition> = [con.xEq(0), con.xLessThan(8), con.xGreaterThan(-1), con.yEq(9)];
|
|
135
|
+
const some: ReadonlyArray<Condition> = [con.yLessThan(9)];
|
|
136
|
+
const facts: ReadonlyArray<Fact> = [xIs(0), yIs(9)];
|
|
137
|
+
const rule = createRule(all, some);
|
|
138
|
+
expect(Rule.solve(rule, facts)).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { Condition } from "../condition";
|
|
2
|
-
import { Fact } from "../fact";
|
|
3
|
-
|
|
4
|
-
const helloWorldString = "hello-world";
|
|
5
|
-
const eqHelloWorld: Condition.String = {
|
|
6
|
-
operator: "eq",
|
|
7
|
-
referenceId: "not-important",
|
|
8
|
-
value: helloWorldString,
|
|
9
|
-
kind: "string-condition",
|
|
10
|
-
referenceLabel: "fact-label",
|
|
11
|
-
valueLabel: "value-label",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const strFact = (str: string): [Fact.String] => [
|
|
15
|
-
{
|
|
16
|
-
kind: "string-fact",
|
|
17
|
-
value: str,
|
|
18
|
-
label: "asdf",
|
|
19
|
-
referenceId: "not-important",
|
|
20
|
-
referenceLabel: "not-important-label",
|
|
21
|
-
},
|
|
22
|
-
// Fact.string('not-important', 'var-label-' + str, str, 'value-label-' + str),
|
|
23
|
-
];
|
|
24
|
-
const notEqHelloWorld: Condition.String = {
|
|
25
|
-
...eqHelloWorld,
|
|
26
|
-
operator: "not-eq",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
describe("string-conditions test-suite", () => {
|
|
30
|
-
// beforeEach(() => {});
|
|
31
|
-
|
|
32
|
-
it("string eq works", () => {
|
|
33
|
-
expect(Condition.evaluate(eqHelloWorld, strFact(helloWorldString))).toBe(true);
|
|
34
|
-
expect(Condition.evaluate(eqHelloWorld, strFact("not-hello-world"))).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it("string not-eq works", () => {
|
|
38
|
-
expect(Condition.evaluate(eqHelloWorld, strFact("not-hello-world"))).toBe(false);
|
|
39
|
-
expect(Condition.evaluate(eqHelloWorld, strFact(helloWorldString))).toBe(true);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
1
|
+
import { Condition } from "../condition";
|
|
2
|
+
import { Fact } from "../fact";
|
|
3
|
+
|
|
4
|
+
const helloWorldString = "hello-world";
|
|
5
|
+
const eqHelloWorld: Condition.String = {
|
|
6
|
+
operator: "eq",
|
|
7
|
+
referenceId: "not-important",
|
|
8
|
+
value: helloWorldString,
|
|
9
|
+
kind: "string-condition",
|
|
10
|
+
referenceLabel: "fact-label",
|
|
11
|
+
valueLabel: "value-label",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const strFact = (str: string): [Fact.String] => [
|
|
15
|
+
{
|
|
16
|
+
kind: "string-fact",
|
|
17
|
+
value: str,
|
|
18
|
+
label: "asdf",
|
|
19
|
+
referenceId: "not-important",
|
|
20
|
+
referenceLabel: "not-important-label",
|
|
21
|
+
},
|
|
22
|
+
// Fact.string('not-important', 'var-label-' + str, str, 'value-label-' + str),
|
|
23
|
+
];
|
|
24
|
+
const notEqHelloWorld: Condition.String = {
|
|
25
|
+
...eqHelloWorld,
|
|
26
|
+
operator: "not-eq",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe("string-conditions test-suite", () => {
|
|
30
|
+
// beforeEach(() => {});
|
|
31
|
+
|
|
32
|
+
it("string eq works", () => {
|
|
33
|
+
expect(Condition.evaluate(eqHelloWorld, strFact(helloWorldString))).toBe(true);
|
|
34
|
+
expect(Condition.evaluate(eqHelloWorld, strFact("not-hello-world"))).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("string not-eq works", () => {
|
|
38
|
+
expect(Condition.evaluate(eqHelloWorld, strFact("not-hello-world"))).toBe(false);
|
|
39
|
+
expect(Condition.evaluate(eqHelloWorld, strFact(helloWorldString))).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
});
|