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