@media-quest/builder 0.0.24 → 0.0.25
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 +2 -2
- package/src/Builder-option.ts +64 -66
- package/src/Builder-page.spec.ts +320 -320
- package/src/Builder-page.ts +259 -257
- package/src/Builder-question.spec.ts +68 -68
- package/src/Builder-question.ts +102 -101
- package/src/Builder-schema.spec.ts +17 -17
- package/src/Builder-schema.ts +14 -8
- package/src/Builder-text.spec.ts +24 -24
- package/src/Builder-text.ts +57 -57
- package/src/BuilderObject.ts +29 -61
- package/src/BuilderTag.ts +96 -97
- package/src/codebook.ts +72 -72
- package/src/primitives/ID.spec.ts +39 -0
- package/src/primitives/ID.ts +119 -0
- package/src/primitives/page-prefix.ts +59 -58
- package/src/primitives/varID.ts +12 -11
- package/src/public-api.ts +3 -1
- package/src/rulebuilder/Builder-rule.spec.ts +323 -322
- package/src/rulebuilder/Builder-rule.ts +191 -190
- package/src/rulebuilder/RuleBuilder-test-utils.ts +320 -316
- package/src/rulebuilder/RuleVariable.ts +48 -49
- package/src/rulebuilder/page-action-manager.ts +33 -31
- package/src/rulebuilder/rule2/Rule2.ts +215 -211
- package/src/schema-config.ts +25 -25
- package/src/variable/{mq-variable.ts → b-variable.ts} +5 -5
- package/src/variable/mq-variable.spec.ts +6 -5
- package/src/variable/sum-score-variable.ts +50 -0
- package/src/variable/sum-score.ts +6 -14
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// private
|
|
31
|
-
|
|
32
|
-
readonly
|
|
33
|
-
readonly
|
|
34
|
-
readonly
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
readonly
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
readonly
|
|
44
|
-
readonly
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
export type BuilderVariable = QuestionVariable | CustomVariable;
|
|
1
|
+
import { VarID } from "../primitives/varID";
|
|
2
|
+
|
|
3
|
+
const BuilderVariableType = {
|
|
4
|
+
numericWithOptions: true,
|
|
5
|
+
numeric: true,
|
|
6
|
+
numericRange: true,
|
|
7
|
+
text: true,
|
|
8
|
+
date: true,
|
|
9
|
+
dateRange: true,
|
|
10
|
+
time: true,
|
|
11
|
+
duration: true,
|
|
12
|
+
boolean: true,
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export type BuilderVariableType = keyof typeof BuilderVariableType;
|
|
16
|
+
|
|
17
|
+
export class BuilderVariableOption {
|
|
18
|
+
constructor(
|
|
19
|
+
readonly label: string,
|
|
20
|
+
readonly value: number,
|
|
21
|
+
) {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class QuestionVariable {
|
|
25
|
+
readonly kind: "question-variable" = "question-variable";
|
|
26
|
+
readonly dataType: BuilderVariableType = "numericWithOptions";
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
// private schemaPrefix: SchemaPrefix,
|
|
30
|
+
// private pagePrefix: PagePrefix,
|
|
31
|
+
readonly varId: VarID,
|
|
32
|
+
readonly label: string,
|
|
33
|
+
readonly options: ReadonlyArray<BuilderVariableOption>,
|
|
34
|
+
readonly pageNumber: number,
|
|
35
|
+
) {}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class CustomVariable {
|
|
39
|
+
readonly kind: "configuration-variable" = "configuration-variable";
|
|
40
|
+
readonly dataType: BuilderVariableType = "numericWithOptions";
|
|
41
|
+
constructor(
|
|
42
|
+
readonly varId: VarID,
|
|
43
|
+
readonly label: string,
|
|
44
|
+
readonly options: ReadonlyArray<BuilderVariableOption>,
|
|
45
|
+
) {}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type BuilderVariable = QuestionVariable | CustomVariable;
|
|
@@ -1,31 +1,33 @@
|
|
|
1
|
-
import type { RuleInput } from "./RuleInput";
|
|
2
|
-
import { ExcludeByPageIdSelectItem } from "./multi-select-item";
|
|
3
|
-
import { ExcludeByPageAction } from "./RuleAction";
|
|
4
|
-
import { PageID } from "
|
|
5
|
-
|
|
6
|
-
export class PageActionManager {
|
|
7
|
-
private readonly _initialSelection: Set<string>;
|
|
8
|
-
readonly selectItems: ReadonlyArray<ExcludeByPageIdSelectItem>;
|
|
9
|
-
|
|
10
|
-
constructor(
|
|
11
|
-
readonly validOptions: RuleInput["_pageIdActions"],
|
|
12
|
-
readonly initialSelection: ReadonlyArray<string>,
|
|
13
|
-
) {
|
|
14
|
-
this._initialSelection = new Set([...initialSelection]);
|
|
15
|
-
this.selectItems = validOptions.map((opt) => {
|
|
16
|
-
const isSelected = this._initialSelection.has(opt.pageId);
|
|
17
|
-
return ExcludeByPageIdSelectItem.create(opt, isSelected);
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
getCurrentSelection(): ReadonlyArray<PageID> {
|
|
22
|
-
const selected = this.selectItems
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import type { RuleInput } from "./RuleInput";
|
|
2
|
+
import { ExcludeByPageIdSelectItem } from "./multi-select-item";
|
|
3
|
+
import { ExcludeByPageAction } from "./RuleAction";
|
|
4
|
+
import { PageID } from "../primitives/ID";
|
|
5
|
+
|
|
6
|
+
export class PageActionManager {
|
|
7
|
+
private readonly _initialSelection: Set<string>;
|
|
8
|
+
readonly selectItems: ReadonlyArray<ExcludeByPageIdSelectItem>;
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
readonly validOptions: RuleInput["_pageIdActions"],
|
|
12
|
+
readonly initialSelection: ReadonlyArray<string>,
|
|
13
|
+
) {
|
|
14
|
+
this._initialSelection = new Set([...initialSelection]);
|
|
15
|
+
this.selectItems = validOptions.map((opt) => {
|
|
16
|
+
const isSelected = this._initialSelection.has(opt.pageId);
|
|
17
|
+
return ExcludeByPageIdSelectItem.create(opt, isSelected);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
getCurrentSelection(): ReadonlyArray<PageID> {
|
|
22
|
+
const selected = this.selectItems
|
|
23
|
+
.filter((item) => item.isSelected)
|
|
24
|
+
.map((itm) => itm.data.pageId);
|
|
25
|
+
return selected;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getEngineAction(): ReadonlyArray<ExcludeByPageAction> {
|
|
29
|
+
const selectItems = this.selectItems.filter((item) => item.isSelected);
|
|
30
|
+
const actions = selectItems.map((item) => item.data);
|
|
31
|
+
return [...actions];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,211 +1,215 @@
|
|
|
1
|
-
import { BuilderOperator } from "../condition/Builder-operator";
|
|
2
|
-
import { BuilderConditionDto } from "../condition/Builder-condition";
|
|
3
|
-
import { BuilderConditionGroupDto
|
|
4
|
-
import { BuilderRuleDto } from "../Builder-rule";
|
|
5
|
-
|
|
6
|
-
type SolveErrorReason =
|
|
7
|
-
| "INVALID_FACT_TYPE"
|
|
8
|
-
| "INVALID_OPERATOR"
|
|
9
|
-
| "INVALID_VALUE"
|
|
10
|
-
| "INVALID_VARIABLE"
|
|
11
|
-
| "UNIMPLEMENTED_VARIABLE_TYPE"
|
|
12
|
-
| "UNIMPLEMENTED_OPERATOR";
|
|
13
|
-
|
|
14
|
-
type TrueResult = { readonly type: "IS_TRUE" };
|
|
15
|
-
type FalseResult = { readonly type: "IS_FALSE" };
|
|
16
|
-
type MissingFactsResult = {
|
|
17
|
-
type
|
|
18
|
-
readonly
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
readonly
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (typeof
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (typeof fact.
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
interface
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (op === "
|
|
119
|
-
return fact.value
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
if (type === "
|
|
163
|
-
return true;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
private
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return
|
|
210
|
-
}
|
|
211
|
-
|
|
1
|
+
import { BuilderOperator } from "../condition/Builder-operator";
|
|
2
|
+
import { BuilderConditionDto } from "../condition/Builder-condition";
|
|
3
|
+
import { BuilderConditionGroupDto } from "../condition/Builder-condition-group";
|
|
4
|
+
import { BuilderRuleDto } from "../Builder-rule";
|
|
5
|
+
|
|
6
|
+
type SolveErrorReason =
|
|
7
|
+
| "INVALID_FACT_TYPE"
|
|
8
|
+
| "INVALID_OPERATOR"
|
|
9
|
+
| "INVALID_VALUE"
|
|
10
|
+
| "INVALID_VARIABLE"
|
|
11
|
+
| "UNIMPLEMENTED_VARIABLE_TYPE"
|
|
12
|
+
| "UNIMPLEMENTED_OPERATOR";
|
|
13
|
+
|
|
14
|
+
type TrueResult = { readonly type: "IS_TRUE" };
|
|
15
|
+
type FalseResult = { readonly type: "IS_FALSE" };
|
|
16
|
+
type MissingFactsResult = {
|
|
17
|
+
readonly type: "MISSING_FACTS";
|
|
18
|
+
readonly missingVariables: ReadonlyArray<string>;
|
|
19
|
+
};
|
|
20
|
+
type ErrorResult = {
|
|
21
|
+
readonly type: "HAS_ERROR";
|
|
22
|
+
readonly reason: SolveErrorReason;
|
|
23
|
+
readonly data: Record<string, string>;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type EvalResult = FalseResult | TrueResult | MissingFactsResult | ErrorResult;
|
|
27
|
+
|
|
28
|
+
export interface Fact2 {
|
|
29
|
+
readonly variableType: "numeric";
|
|
30
|
+
readonly value: number;
|
|
31
|
+
readonly valueLabel: string;
|
|
32
|
+
readonly variableId: string;
|
|
33
|
+
readonly variableLabel: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class FactCollection {
|
|
37
|
+
public static isFact = (value: unknown): value is Fact2 => {
|
|
38
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const fact = value as Partial<Fact2>;
|
|
42
|
+
if (typeof fact.variableId !== "string" || fact.variableId.length === 0) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
if (typeof fact.variableLabel !== "string") {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (typeof fact.value !== "number") {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (typeof fact.valueLabel !== "string") {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
// NB: This is a temporary check until we have more variable types.
|
|
55
|
+
if (typeof fact.variableType !== "string" || fact.variableType !== "numeric") {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
public static create = (facts: ReadonlyArray<Fact2>): FactCollection => {
|
|
62
|
+
return new FactCollection(facts);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
private readonly _facts: ReadonlyArray<Fact2>;
|
|
66
|
+
|
|
67
|
+
private constructor(facts: ReadonlyArray<Fact2>) {
|
|
68
|
+
if (!Array.isArray(facts)) {
|
|
69
|
+
console.log("Invalid facts", facts);
|
|
70
|
+
this._facts = [];
|
|
71
|
+
} else {
|
|
72
|
+
this._facts = [...facts];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
byId(variableId: string): Fact2 | false {
|
|
76
|
+
const result = this._facts.find((fact) => fact.variableId === variableId);
|
|
77
|
+
if (!result) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return { ...result };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
interface FactEvaluator {
|
|
84
|
+
isTrue(facts: FactCollection): boolean;
|
|
85
|
+
evaluate(facts: FactCollection): EvalResult;
|
|
86
|
+
}
|
|
87
|
+
interface IsValid {
|
|
88
|
+
isValid(): boolean;
|
|
89
|
+
}
|
|
90
|
+
export class Condition implements FactEvaluator, IsValid {
|
|
91
|
+
public static create = (dto: BuilderConditionDto): Condition => {
|
|
92
|
+
return new Condition(dto);
|
|
93
|
+
};
|
|
94
|
+
private constructor(private readonly dto: BuilderConditionDto) {}
|
|
95
|
+
isTrue(facts: FactCollection): boolean {
|
|
96
|
+
const dto = this.dto;
|
|
97
|
+
const op = dto.operator;
|
|
98
|
+
const value = dto.value;
|
|
99
|
+
const varId = dto.variableId;
|
|
100
|
+
if (!BuilderOperator.is(op)) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (typeof value !== "number") {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const fact = facts.byId(this.dto.variableId);
|
|
109
|
+
|
|
110
|
+
if (!FactCollection.isFact(fact)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (fact.variableType !== "numeric" && typeof fact.value !== "number") {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (op === "equal") {
|
|
119
|
+
return fact.value === value;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (op === "notEqual") {
|
|
123
|
+
return fact.value !== value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
isValid(): boolean {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
evaluate(facts: FactCollection): EvalResult {
|
|
133
|
+
return { type: "HAS_ERROR", reason: "UNIMPLEMENTED_VARIABLE_TYPE", data: {} }; // TODO
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
export class ConditionGroup implements FactEvaluator, IsValid {
|
|
137
|
+
public static readonly create = (dto: BuilderConditionGroupDto): ConditionGroup => {
|
|
138
|
+
return new ConditionGroup(dto);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
private readonly _conditions: ReadonlyArray<Condition>;
|
|
142
|
+
private constructor(private readonly dto: BuilderConditionGroupDto) {
|
|
143
|
+
this._conditions = dto.conditions.map(Condition.create);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
isTrue(facts: FactCollection): boolean {
|
|
147
|
+
const results = this._conditions.map((condition) => condition.isTrue(facts));
|
|
148
|
+
let trueCount = 0;
|
|
149
|
+
let falseCount = 0;
|
|
150
|
+
results.forEach((results) => {
|
|
151
|
+
if (results) {
|
|
152
|
+
trueCount++;
|
|
153
|
+
} else {
|
|
154
|
+
falseCount++;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
if (trueCount === 0 || falseCount === 0) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const type = this.dto.type;
|
|
161
|
+
|
|
162
|
+
if (type === "all" && trueCount === this._conditions.length) {
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (type === "any" && trueCount > 0) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const minLimit = this.dto.count;
|
|
171
|
+
if (type === "count" && typeof minLimit === "number" && trueCount >= minLimit) {
|
|
172
|
+
return true;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
isValid(): boolean {
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
evaluate(facts: FactCollection): EvalResult {
|
|
183
|
+
return { type: "HAS_ERROR", reason: "UNIMPLEMENTED_VARIABLE_TYPE", data: {} }; // TODO
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
export class Rule2 implements FactEvaluator {
|
|
187
|
+
readonly name: string;
|
|
188
|
+
private readonly _conditions: ReadonlyArray<Condition | ConditionGroup>;
|
|
189
|
+
public static readonly create = (dto: BuilderRuleDto): Rule2 => {
|
|
190
|
+
return new Rule2(dto);
|
|
191
|
+
};
|
|
192
|
+
private _count = -1;
|
|
193
|
+
constructor(private readonly dto: BuilderRuleDto) {
|
|
194
|
+
this.name = dto.name;
|
|
195
|
+
const conditions: Array<Condition | ConditionGroup> = [];
|
|
196
|
+
dto.conditions.forEach((condition) => {
|
|
197
|
+
if (condition.kind === "condition-group") {
|
|
198
|
+
conditions.push(ConditionGroup.create(condition));
|
|
199
|
+
} else if (condition.kind === "condition") {
|
|
200
|
+
conditions.push(Condition.create(condition));
|
|
201
|
+
} else {
|
|
202
|
+
console.log("Unknown condition", condition);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
this._conditions = conditions;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
isTrue(facts: FactCollection): boolean {
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
evaluate(facts: FactCollection): EvalResult {
|
|
213
|
+
return { type: "HAS_ERROR", reason: "UNIMPLEMENTED_VARIABLE_TYPE", data: {} }; // TODO
|
|
214
|
+
}
|
|
215
|
+
}
|
package/src/schema-config.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { PredefinedVariable } from "./variable/
|
|
2
|
-
import { BuilderSchemaDto } from "./Builder-schema";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* This interface is ment to define all information that a schema-admin app
|
|
6
|
-
* needs to generate a dynamic form for setting values for predefined variables.
|
|
7
|
-
*/
|
|
8
|
-
export interface SchemaConfig {
|
|
9
|
-
readonly schemaName: string;
|
|
10
|
-
readonly schemaId: string;
|
|
11
|
-
readonly schemaPrefix: string;
|
|
12
|
-
readonly variables: ReadonlyArray<Readonly<PredefinedVariable>>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const SchemaConfig = {
|
|
16
|
-
fromSchema: (schema: BuilderSchemaDto): SchemaConfig => {
|
|
17
|
-
const variables = schema.predefinedVariables ?? [];
|
|
18
|
-
return {
|
|
19
|
-
schemaId: schema.id,
|
|
20
|
-
schemaName: schema.name,
|
|
21
|
-
schemaPrefix: schema.prefix,
|
|
22
|
-
variables,
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
} as const;
|
|
1
|
+
import { PredefinedVariable } from "./variable/b-variable";
|
|
2
|
+
import { BuilderSchemaDto } from "./Builder-schema";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* This interface is ment to define all information that a schema-admin app
|
|
6
|
+
* needs to generate a dynamic form for setting values for predefined variables.
|
|
7
|
+
*/
|
|
8
|
+
export interface SchemaConfig {
|
|
9
|
+
readonly schemaName: string;
|
|
10
|
+
readonly schemaId: string;
|
|
11
|
+
readonly schemaPrefix: string;
|
|
12
|
+
readonly variables: ReadonlyArray<Readonly<PredefinedVariable>>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const SchemaConfig = {
|
|
16
|
+
fromSchema: (schema: BuilderSchemaDto): SchemaConfig => {
|
|
17
|
+
const variables = schema.predefinedVariables ?? [];
|
|
18
|
+
return {
|
|
19
|
+
schemaId: schema.id,
|
|
20
|
+
schemaName: schema.name,
|
|
21
|
+
schemaPrefix: schema.prefix,
|
|
22
|
+
variables,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
} as const;
|