@media-quest/builder 0.0.2 → 0.0.4
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/dist/public-api.d.mts +35 -11
- package/dist/public-api.d.ts +35 -11
- package/dist/public-api.js +455 -47
- package/dist/public-api.mjs +427 -37
- package/package.json +3 -4
- package/src/Builder-option.ts +51 -52
- package/src/Builder-schema.ts +1 -0
- package/src/public-api.ts +3 -0
- package/src/rulebuilder/Builder-rule.spec.ts +266 -182
- package/src/rulebuilder/Builder-rule.ts +106 -67
- package/src/rulebuilder/Rule2.ts +87 -0
- package/src/rulebuilder/RuleBuilder-test-utils.ts +250 -239
- package/src/rulebuilder/RuleVariable.ts +13 -9
- package/src/rulebuilder/SingleSelectItem.ts +118 -118
- package/src/rulebuilder/{Builder-condition-group.ts → condition/Builder-condition-group.ts} +42 -33
- package/src/rulebuilder/condition/Builder-condition.spec.ts +185 -0
- package/src/rulebuilder/condition/Builder-condition.ts +208 -0
- package/src/rulebuilder/index.ts +11 -11
- package/src/rulebuilder/jump-to-action-manager.ts +26 -26
- package/src/rulebuilder/page-action-manager.ts +23 -13
- package/src/rulebuilder/tag-action-manager.ts +23 -13
- package/src/theme/default-theme-compiler.ts +26 -1
- package/src/rulebuilder/Builder-condition.spec.ts +0 -169
- package/src/rulebuilder/Builder-condition.ts +0 -186
- /package/src/rulebuilder/{Builder-condition-group.spec.ts → condition/Builder-condition-group.spec.ts} +0 -0
- /package/src/rulebuilder/{Builder-operator.spec.ts → condition/Builder-operator.spec.ts} +0 -0
- /package/src/rulebuilder/{Builder-operator.ts → condition/Builder-operator.ts} +0 -0
|
@@ -1,254 +1,265 @@
|
|
|
1
1
|
import { BuilderOption } from "../Builder-option";
|
|
2
2
|
import { type BuilderVariable, QuestionVariable } from "./RuleVariable";
|
|
3
3
|
import type { BuilderRuleDto } from "./Builder-rule";
|
|
4
|
-
import type { BuilderConditionGroupDto } from "./Builder-condition-group";
|
|
5
|
-
import type { BuilderConditionDto } from "./Builder-condition";
|
|
6
|
-
import type { BuilderOperator } from "./Builder-operator";
|
|
7
|
-
import type { ExcludeByPageAction, ExcludeByTagAction } from "./RuleAction";
|
|
4
|
+
import type { BuilderConditionGroupDto } from "./condition/Builder-condition-group";
|
|
5
|
+
import type { BuilderConditionDto } from "./condition/Builder-condition";
|
|
6
|
+
import type { BuilderOperator } from "./condition/Builder-operator";
|
|
7
|
+
import type { ExcludeByPageAction, ExcludeByTagAction, JumpToPageAction } from "./RuleAction";
|
|
8
8
|
import { ExcludeByPageIdSelectItem, ExcludeByTagSelectItem } from "./multi-select-item";
|
|
9
9
|
|
|
10
10
|
export namespace RuleBuilderTestUtils {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
return action;
|
|
11
|
+
export const createOptions = () => [
|
|
12
|
+
BuilderOption.create(0, "Nei"),
|
|
13
|
+
BuilderOption.create(1, "Ja"),
|
|
14
|
+
BuilderOption.create(9, "Vet ikke"),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
export const excludeByTagAction = (tag: string) => {
|
|
18
|
+
const pageCount = Math.floor(Math.random() * 10);
|
|
19
|
+
const action: ExcludeByTagAction = {
|
|
20
|
+
kind: "exclude-by-tag",
|
|
21
|
+
tag,
|
|
22
|
+
description: "Description for tag: " + tag,
|
|
23
|
+
pageCount,
|
|
26
24
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
return action;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const excludeByPageIdAction = (pageId: string, pageNumber: number) => {
|
|
29
|
+
const action: ExcludeByPageAction = {
|
|
30
|
+
kind: "exclude-by-pageId",
|
|
31
|
+
mainText: "",
|
|
32
|
+
pageId,
|
|
33
|
+
pageNumber,
|
|
35
34
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
excludeByTagAction("tag7"),
|
|
45
|
-
excludeByTagAction("tag8"),
|
|
46
|
-
excludeByTagAction("tag9"),
|
|
47
|
-
excludeByTagAction("tag10"),
|
|
48
|
-
] as const;
|
|
49
|
-
return list;
|
|
35
|
+
return action;
|
|
36
|
+
};
|
|
37
|
+
export const jumpToPageAction = (pageId: string, pageNumber: number) => {
|
|
38
|
+
const action: JumpToPageAction = {
|
|
39
|
+
kind: "jump-to-page",
|
|
40
|
+
mainText: "TEXT: " + pageId,
|
|
41
|
+
pageId,
|
|
42
|
+
pageNumber,
|
|
50
43
|
};
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
44
|
+
return action;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const excludeByTagActionList = () => {
|
|
48
|
+
const list = [
|
|
49
|
+
excludeByTagAction("tag1"),
|
|
50
|
+
excludeByTagAction("tag2"),
|
|
51
|
+
excludeByTagAction("tag3"),
|
|
52
|
+
excludeByTagAction("tag4"),
|
|
53
|
+
excludeByTagAction("tag5"),
|
|
54
|
+
excludeByTagAction("tag6"),
|
|
55
|
+
excludeByTagAction("tag7"),
|
|
56
|
+
excludeByTagAction("tag8"),
|
|
57
|
+
excludeByTagAction("tag9"),
|
|
58
|
+
excludeByTagAction("tag10"),
|
|
59
|
+
] as const;
|
|
60
|
+
return list;
|
|
61
|
+
};
|
|
62
|
+
export const createRuleVariable = (id: string, pageNumber: number): QuestionVariable =>
|
|
63
|
+
new QuestionVariable(id, "Har du " + id + "?", createOptions(), pageNumber);
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
*/
|
|
68
|
+
export const createBuilderVariables_A_H = (): ReadonlyArray<QuestionVariable> => [
|
|
69
|
+
createRuleVariable("a", 3),
|
|
70
|
+
createRuleVariable("b", 4),
|
|
71
|
+
createRuleVariable("c", 5),
|
|
72
|
+
createRuleVariable("d", 6),
|
|
73
|
+
createRuleVariable("e", 7),
|
|
74
|
+
createRuleVariable("f", 8),
|
|
75
|
+
createRuleVariable("g", 9),
|
|
76
|
+
createRuleVariable("h", 10),
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
export const createConditionDto = (variable: BuilderVariable): BuilderConditionDto => {
|
|
80
|
+
const operator: BuilderOperator = Math.random() > 0 ? "equal" : "notEqual";
|
|
81
|
+
const opt = variable.options[0];
|
|
82
|
+
return {
|
|
83
|
+
kind: "condition",
|
|
84
|
+
name: "condition 1",
|
|
85
|
+
variableId: variable.varId,
|
|
86
|
+
operator,
|
|
87
|
+
value: opt.value,
|
|
78
88
|
};
|
|
89
|
+
};
|
|
79
90
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
};
|
|
91
|
+
export const createConditionGroupDto = (conditions: BuilderConditionDto[]): BuilderConditionGroupDto => {
|
|
92
|
+
return {
|
|
93
|
+
kind: "condition-group",
|
|
94
|
+
conditions,
|
|
95
|
+
type: "all",
|
|
96
|
+
name: "random-group-name",
|
|
87
97
|
};
|
|
98
|
+
};
|
|
88
99
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
};
|
|
105
|
-
return [];
|
|
100
|
+
export const createBuilderRuleDto = (): ReadonlyArray<BuilderRuleDto> => {
|
|
101
|
+
const variables = createBuilderVariables_A_H();
|
|
102
|
+
const condition0 = createConditionDto(variables[0]);
|
|
103
|
+
const condition1 = createConditionDto(variables[1]);
|
|
104
|
+
const condition3 = createConditionDto(variables[3]);
|
|
105
|
+
const condition5 = createConditionDto(variables[5]);
|
|
106
|
+
const group = createConditionGroupDto([condition0, condition3]);
|
|
107
|
+
// const action1: Exc
|
|
108
|
+
const rule: BuilderRuleDto = {
|
|
109
|
+
name: "rule-name",
|
|
110
|
+
conditions: [condition1, group, condition5],
|
|
111
|
+
excludeTags: [],
|
|
112
|
+
excludePages: [],
|
|
113
|
+
jumpToPage: false,
|
|
114
|
+
type: "all",
|
|
106
115
|
};
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
116
|
+
return [];
|
|
117
|
+
};
|
|
118
|
+
export const createExcludeByPageIdList = (): ReadonlyArray<ExcludeByPageIdSelectItem> => [
|
|
119
|
+
ExcludeByPageIdSelectItem.create(
|
|
120
|
+
{
|
|
121
|
+
kind: "exclude-by-pageId",
|
|
122
|
+
pageId: "page_a",
|
|
123
|
+
pageNumber: 5,
|
|
124
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
125
|
+
},
|
|
126
|
+
false,
|
|
127
|
+
),
|
|
128
|
+
|
|
129
|
+
ExcludeByPageIdSelectItem.create(
|
|
130
|
+
{
|
|
131
|
+
kind: "exclude-by-pageId",
|
|
132
|
+
pageId: "page_b",
|
|
133
|
+
pageNumber: 5,
|
|
134
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
135
|
+
},
|
|
136
|
+
true,
|
|
137
|
+
),
|
|
138
|
+
|
|
139
|
+
ExcludeByPageIdSelectItem.create(
|
|
140
|
+
{
|
|
141
|
+
kind: "exclude-by-pageId",
|
|
142
|
+
pageId: "page_c",
|
|
143
|
+
pageNumber: 5,
|
|
144
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
145
|
+
},
|
|
146
|
+
false,
|
|
147
|
+
),
|
|
148
|
+
|
|
149
|
+
ExcludeByPageIdSelectItem.create(
|
|
150
|
+
{
|
|
151
|
+
kind: "exclude-by-pageId",
|
|
152
|
+
pageId: "page_d",
|
|
153
|
+
pageNumber: 5,
|
|
154
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
155
|
+
},
|
|
156
|
+
false,
|
|
157
|
+
),
|
|
158
|
+
|
|
159
|
+
ExcludeByPageIdSelectItem.create(
|
|
160
|
+
{
|
|
161
|
+
kind: "exclude-by-pageId",
|
|
162
|
+
pageId: "page_e",
|
|
163
|
+
pageNumber: 5,
|
|
164
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
165
|
+
},
|
|
166
|
+
true,
|
|
167
|
+
),
|
|
168
|
+
ExcludeByPageIdSelectItem.create(
|
|
169
|
+
{
|
|
170
|
+
kind: "exclude-by-pageId",
|
|
171
|
+
pageId: "page_f",
|
|
172
|
+
pageNumber: 5,
|
|
173
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
174
|
+
},
|
|
175
|
+
false,
|
|
176
|
+
),
|
|
177
|
+
|
|
178
|
+
ExcludeByPageIdSelectItem.create(
|
|
179
|
+
{
|
|
180
|
+
kind: "exclude-by-pageId",
|
|
181
|
+
pageId: "page_g",
|
|
182
|
+
pageNumber: 5,
|
|
183
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
184
|
+
},
|
|
185
|
+
true,
|
|
186
|
+
),
|
|
187
|
+
|
|
188
|
+
ExcludeByPageIdSelectItem.create(
|
|
189
|
+
{
|
|
190
|
+
kind: "exclude-by-pageId",
|
|
191
|
+
pageId: "page_h",
|
|
192
|
+
pageNumber: 5,
|
|
193
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
194
|
+
},
|
|
195
|
+
false,
|
|
196
|
+
),
|
|
197
|
+
|
|
198
|
+
ExcludeByPageIdSelectItem.create(
|
|
199
|
+
{
|
|
200
|
+
kind: "exclude-by-pageId",
|
|
201
|
+
pageId: "page_i",
|
|
202
|
+
pageNumber: 5,
|
|
203
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
204
|
+
},
|
|
205
|
+
false,
|
|
206
|
+
),
|
|
207
|
+
|
|
208
|
+
ExcludeByPageIdSelectItem.create(
|
|
209
|
+
{
|
|
210
|
+
kind: "exclude-by-pageId",
|
|
211
|
+
pageId: "page_j",
|
|
212
|
+
pageNumber: 5,
|
|
213
|
+
mainText: "Har du noen gang vært deprimeri?? ",
|
|
214
|
+
},
|
|
215
|
+
true,
|
|
216
|
+
),
|
|
217
|
+
];
|
|
218
|
+
export const createExcludeByTagList = () => [
|
|
219
|
+
ExcludeByTagSelectItem.create(
|
|
220
|
+
{
|
|
221
|
+
kind: "exclude-by-tag",
|
|
222
|
+
tag: "Can_read",
|
|
223
|
+
pageCount: 5,
|
|
224
|
+
description: "",
|
|
225
|
+
},
|
|
226
|
+
false,
|
|
227
|
+
),
|
|
228
|
+
ExcludeByTagSelectItem.create(
|
|
229
|
+
{
|
|
230
|
+
kind: "exclude-by-tag",
|
|
231
|
+
tag: "Is grownup",
|
|
232
|
+
pageCount: 1,
|
|
233
|
+
description: "",
|
|
234
|
+
},
|
|
235
|
+
true,
|
|
236
|
+
),
|
|
237
|
+
ExcludeByTagSelectItem.create(
|
|
238
|
+
{
|
|
239
|
+
kind: "exclude-by-tag",
|
|
240
|
+
tag: "speaks english",
|
|
241
|
+
pageCount: 3,
|
|
242
|
+
description: "",
|
|
243
|
+
},
|
|
244
|
+
false,
|
|
245
|
+
),
|
|
246
|
+
ExcludeByTagSelectItem.create(
|
|
247
|
+
{
|
|
248
|
+
kind: "exclude-by-tag",
|
|
249
|
+
tag: "has work",
|
|
250
|
+
pageCount: 7,
|
|
251
|
+
description: "",
|
|
252
|
+
},
|
|
253
|
+
false,
|
|
254
|
+
),
|
|
255
|
+
ExcludeByTagSelectItem.create(
|
|
256
|
+
{
|
|
257
|
+
kind: "exclude-by-tag",
|
|
258
|
+
tag: "is-depressed",
|
|
259
|
+
pageCount: 2,
|
|
260
|
+
description: "",
|
|
261
|
+
},
|
|
262
|
+
false,
|
|
263
|
+
),
|
|
264
|
+
];
|
|
254
265
|
}
|
|
@@ -1,38 +1,42 @@
|
|
|
1
1
|
const BuilderVariableType = {
|
|
2
2
|
numericWithOptions: true,
|
|
3
|
+
numeric: true,
|
|
3
4
|
numericRange: true,
|
|
4
5
|
text: true,
|
|
5
6
|
date: true,
|
|
6
7
|
dateRange: true,
|
|
7
8
|
time: true,
|
|
8
9
|
duration: true,
|
|
9
|
-
boolean: true
|
|
10
|
+
boolean: true,
|
|
10
11
|
} as const;
|
|
11
12
|
|
|
12
|
-
type BuilderVariableType = keyof typeof BuilderVariableType;
|
|
13
|
+
export type BuilderVariableType = keyof typeof BuilderVariableType;
|
|
13
14
|
|
|
14
15
|
export class BuilderVariableOption {
|
|
15
|
-
constructor(
|
|
16
|
+
constructor(
|
|
17
|
+
readonly label: string,
|
|
18
|
+
readonly value: number,
|
|
19
|
+
) {}
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
export class QuestionVariable {
|
|
19
|
-
readonly kind:
|
|
20
|
-
readonly dataType: BuilderVariableType =
|
|
23
|
+
readonly kind: "question-variable" = "question-variable";
|
|
24
|
+
readonly dataType: BuilderVariableType = "numericWithOptions";
|
|
21
25
|
constructor(
|
|
22
26
|
readonly varId: string,
|
|
23
27
|
readonly label: string,
|
|
24
28
|
readonly options: ReadonlyArray<BuilderVariableOption>,
|
|
25
|
-
readonly pageNumber: number
|
|
29
|
+
readonly pageNumber: number,
|
|
26
30
|
) {}
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
export class CustomVariable {
|
|
30
|
-
readonly kind:
|
|
31
|
-
readonly dataType: BuilderVariableType =
|
|
34
|
+
readonly kind: "configuration-variable" = "configuration-variable";
|
|
35
|
+
readonly dataType: BuilderVariableType = "numericWithOptions";
|
|
32
36
|
constructor(
|
|
33
37
|
readonly varId: string,
|
|
34
38
|
readonly label: string,
|
|
35
|
-
readonly options: ReadonlyArray<BuilderVariableOption
|
|
39
|
+
readonly options: ReadonlyArray<BuilderVariableOption>,
|
|
36
40
|
) {}
|
|
37
41
|
}
|
|
38
42
|
|