@media-quest/builder 0.0.25 → 0.0.26

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 (44) hide show
  1. package/package.json +15 -15
  2. package/src/Builder-option.ts +64 -64
  3. package/src/Builder-page.spec.ts +2 -160
  4. package/src/Builder-page.ts +6 -83
  5. package/src/Builder-question.spec.ts +68 -68
  6. package/src/Builder-question.ts +102 -102
  7. package/src/Builder-schema.spec.ts +86 -114
  8. package/src/Builder-schema.ts +13 -9
  9. package/src/Builder-text.spec.ts +24 -24
  10. package/src/Builder-text.ts +57 -57
  11. package/src/BuilderObject.ts +30 -29
  12. package/src/BuilderTag.ts +96 -96
  13. package/src/builder-compiler.ts +1 -1
  14. package/src/code-book/codebook-variable.ts +29 -0
  15. package/src/{codebook.ts → code-book/codebook.ts} +72 -72
  16. package/src/primitives/ID.spec.ts +39 -39
  17. package/src/primitives/ID.ts +138 -119
  18. package/src/primitives/page-prefix.ts +59 -59
  19. package/src/primitives/varID.ts +12 -12
  20. package/src/public-api.ts +28 -26
  21. package/src/rulebuilder/Builder-rule.spec.ts +323 -323
  22. package/src/rulebuilder/Builder-rule.ts +191 -191
  23. package/src/rulebuilder/RuleBuilder-test-utils.ts +320 -320
  24. package/src/rulebuilder/RuleInput.ts +30 -30
  25. package/src/rulebuilder/RuleVariable.ts +34 -48
  26. package/src/rulebuilder/SingleSelectItem.ts +9 -8
  27. package/src/rulebuilder/condition/Builder-condition-group.ts +14 -6
  28. package/src/rulebuilder/condition/Builder-condition.spec.ts +12 -12
  29. package/src/rulebuilder/condition/Builder-condition.ts +17 -13
  30. package/src/rulebuilder/index.ts +16 -3
  31. package/src/rulebuilder/page-action-manager.ts +33 -33
  32. package/src/rulebuilder/rule2/Rule2.ts +211 -215
  33. package/src/schema-config.ts +25 -25
  34. package/src/sum-score/sum-score-answer.ts +6 -0
  35. package/src/sum-score/sum-score-manager.spec.ts +189 -0
  36. package/src/sum-score/sum-score-manager.ts +154 -0
  37. package/src/sum-score/sum-score-membership.ts +45 -0
  38. package/src/sum-score/sum-score-variable.spec.ts +151 -0
  39. package/src/sum-score/sum-score-variable.ts +36 -0
  40. package/src/{variable → sum-score}/sum-score.ts +122 -130
  41. package/tsconfig.tsbuildinfo +1 -1
  42. package/src/variable/b-variable.ts +0 -68
  43. package/src/variable/mq-variable.spec.ts +0 -147
  44. package/src/variable/sum-score-variable.ts +0 -50
@@ -1,102 +1,102 @@
1
- import type { BuilderOptionDto } from "./Builder-option";
2
- import { BuilderOption } from "./Builder-option";
3
- import { BuilderObject } from "./BuilderObject";
4
- import { QuestionID } from "./primitives/ID";
5
-
6
- export type BuilderQuestionType =
7
- | "select-one"
8
- | "select-many"
9
- | "text"
10
- | "color"
11
- | "radio"
12
- | "email"
13
- | "time"
14
- | "checkbox"
15
- | "textarea"
16
- | "date"
17
- | "numeric-range"
18
- | "duration";
19
-
20
- export interface BuilderQuestionDto {
21
- readonly id: QuestionID;
22
- _type: BuilderQuestionType;
23
- text: string;
24
- options: ReadonlyArray<BuilderOptionDto>;
25
- prefix: string;
26
- }
27
-
28
- export class BuilderQuestion extends BuilderObject<"builder-question", BuilderQuestionDto> {
29
- readonly objectType = "builder-question";
30
- id: QuestionID;
31
- type: BuilderQuestionType;
32
- questionText = "";
33
- options: BuilderOption[] = [];
34
- prefix = "";
35
-
36
- static create = (type: BuilderQuestionType) => {
37
- const id = QuestionID.create();
38
-
39
- return new BuilderQuestion({
40
- id,
41
- _type: type,
42
- text: "",
43
- options: [],
44
- prefix: "",
45
- });
46
- };
47
-
48
- public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
49
- const question = new BuilderQuestion(dto);
50
- return question;
51
- }
52
-
53
- private constructor(dto: BuilderQuestionDto) {
54
- super(dto);
55
- this.id = QuestionID.validateOrCreate(dto.id);
56
- this.type = dto._type;
57
- this.questionText = dto.text;
58
- this.prefix = dto.prefix;
59
- this.options = dto.options.map((o) => BuilderOption.fromJson(o));
60
- }
61
-
62
- addOption(label: string, value: number, atIndex = -1) {
63
- const option = BuilderOption.create(value, label);
64
- if (atIndex >= 0 && atIndex < this.options.length) {
65
- this.options.splice(atIndex, 0, option);
66
- } else {
67
- this.options.push(option);
68
- }
69
- return option;
70
- }
71
-
72
- deleteOption(option: BuilderOption): boolean {
73
- const filtered = this.options.filter((o) => o.id !== option.id);
74
- const didDelete = filtered.length === this.options.length - 1;
75
- this.options = filtered;
76
- return didDelete;
77
- }
78
-
79
- toJson() {
80
- const optionsJson = this.options.map((o) => o.toJson());
81
- const dto: BuilderQuestionDto = {
82
- id: this.id,
83
- prefix: this.prefix,
84
- _type: this.type,
85
- text: this.questionText,
86
- options: optionsJson,
87
- };
88
- return dto;
89
- }
90
-
91
- clone(): BuilderQuestionDto {
92
- const cloneId = QuestionID.create();
93
- const dto = this.toJson();
94
- const optionsClone = this.options.map((o) => o.clone());
95
- const clonedDto: BuilderQuestionDto = {
96
- ...dto,
97
- id: cloneId,
98
- options: optionsClone,
99
- };
100
- return clonedDto;
101
- }
102
- }
1
+ import type { BuilderOptionDto } from "./Builder-option";
2
+ import { BuilderOption } from "./Builder-option";
3
+ import { BuilderObject } from "./BuilderObject";
4
+ import { QuestionID } from "./primitives/ID";
5
+
6
+ export type BuilderQuestionType =
7
+ | "select-one"
8
+ | "select-many"
9
+ | "text"
10
+ | "color"
11
+ | "radio"
12
+ | "email"
13
+ | "time"
14
+ | "checkbox"
15
+ | "textarea"
16
+ | "date"
17
+ | "numeric-range"
18
+ | "duration";
19
+
20
+ export interface BuilderQuestionDto {
21
+ readonly id: QuestionID;
22
+ _type: BuilderQuestionType;
23
+ text: string;
24
+ options: ReadonlyArray<BuilderOptionDto>;
25
+ prefix: string;
26
+ }
27
+
28
+ export class BuilderQuestion extends BuilderObject<"builder-question", BuilderQuestionDto> {
29
+ readonly objectType = "builder-question";
30
+ id: QuestionID;
31
+ type: BuilderQuestionType;
32
+ questionText = "";
33
+ options: BuilderOption[] = [];
34
+ prefix = "";
35
+
36
+ static create = (type: BuilderQuestionType) => {
37
+ const id = QuestionID.create();
38
+
39
+ return new BuilderQuestion({
40
+ id,
41
+ _type: type,
42
+ text: "",
43
+ options: [],
44
+ prefix: "",
45
+ });
46
+ };
47
+
48
+ public static fromJson(dto: BuilderQuestionDto): BuilderQuestion {
49
+ const question = new BuilderQuestion(dto);
50
+ return question;
51
+ }
52
+
53
+ private constructor(dto: BuilderQuestionDto) {
54
+ super(dto);
55
+ this.id = QuestionID.validateOrCreate(dto.id);
56
+ this.type = dto._type;
57
+ this.questionText = dto.text;
58
+ this.prefix = dto.prefix;
59
+ this.options = dto.options.map((o) => BuilderOption.fromJson(o));
60
+ }
61
+
62
+ addOption(label: string, value: number, atIndex = -1) {
63
+ const option = BuilderOption.create(value, label);
64
+ if (atIndex >= 0 && atIndex < this.options.length) {
65
+ this.options.splice(atIndex, 0, option);
66
+ } else {
67
+ this.options.push(option);
68
+ }
69
+ return option;
70
+ }
71
+
72
+ deleteOption(option: BuilderOption): boolean {
73
+ const filtered = this.options.filter((o) => o.id !== option.id);
74
+ const didDelete = filtered.length === this.options.length - 1;
75
+ this.options = filtered;
76
+ return didDelete;
77
+ }
78
+
79
+ toJson() {
80
+ const optionsJson = this.options.map((o) => o.toJson());
81
+ const dto: BuilderQuestionDto = {
82
+ id: this.id,
83
+ prefix: this.prefix,
84
+ _type: this.type,
85
+ text: this.questionText,
86
+ options: optionsJson,
87
+ };
88
+ return dto;
89
+ }
90
+
91
+ clone(): BuilderQuestionDto {
92
+ const cloneId = QuestionID.create();
93
+ const dto = this.toJson();
94
+ const optionsClone = this.options.map((o) => o.clone());
95
+ const clonedDto: BuilderQuestionDto = {
96
+ ...dto,
97
+ id: cloneId,
98
+ options: optionsClone,
99
+ };
100
+ return clonedDto;
101
+ }
102
+ }
@@ -6,8 +6,8 @@ import { BuilderTag } from "./BuilderTag";
6
6
  import { PagePrefix } from "./primitives/page-prefix";
7
7
  import { SchemaPrefix } from "./primitives/schema-prefix";
8
8
 
9
- import { SumScoreVariableDto } from "./variable/sum-score-variable";
10
- import { OptionID, PageID, QuestionID, SchemaID } from "./primitives/ID";
9
+ import { SumScoreVariableDto } from "./sum-score/sum-score-variable";
10
+ import { OptionID, PageID, QuestionID, SchemaID, SumScoreVariableID } from "./primitives/ID";
11
11
 
12
12
  const tag1: BuilderTagDto = BuilderTag.create("tag1", "This tag is defined in schemaDto1").toJson();
13
13
 
@@ -24,11 +24,10 @@ const schemaDto1: BuilderSchemaDto = {
24
24
  tags: [tag1, tag2, tag3],
25
25
  sumScoreVariables: [
26
26
  {
27
- kind: "numeric-variable",
28
- origin: "sum-score",
29
- label: "label for dummy variable",
30
- initialValue: 0,
31
- varId: "testId",
27
+ id: SumScoreVariableID.dummy.a,
28
+ name: "label for dummy sum-score",
29
+ description: "testId",
30
+ useAvg: false,
32
31
  basedOn: [],
33
32
  },
34
33
  ],
@@ -78,11 +77,10 @@ const schemaDto1: BuilderSchemaDto = {
78
77
  // { tag: 'can_read', description: 'The patient can read' },
79
78
  // { tag: 'is grown up', description: 'Is grownUp.' }
80
79
  ],
81
- questions: [],
82
80
  autoplaySequence: [],
83
81
  },
84
82
  {
85
- id: PageID.validateOrCreate("b".repeat(24)),
83
+ id: PageID.dummy.b,
86
84
  _type: "multi-select",
87
85
  prefix: PagePrefix.fromStringOrThrow("page2-prefix"),
88
86
  tags: [tag3.tag],
@@ -104,31 +102,6 @@ const schemaDto1: BuilderSchemaDto = {
104
102
  text: "q1",
105
103
  options: [],
106
104
  },
107
- questions: [
108
- {
109
- id: QuestionID.create(),
110
- prefix: "one-prefix",
111
- _type: "select-one",
112
- text: "q1-text",
113
- options: [
114
- {
115
- id: "opt-nei" as OptionID,
116
- value: 0,
117
- label: "Nei",
118
- },
119
- {
120
- id: "opt-ja" as OptionID,
121
- value: 1,
122
- label: "Ja",
123
- },
124
- {
125
- id: "opt-vet-ikke" as OptionID,
126
- value: 9,
127
- label: "Vet ikke",
128
- },
129
- ],
130
- },
131
- ],
132
105
  autoplaySequence: [],
133
106
  },
134
107
  ],
@@ -138,41 +111,41 @@ const schemaDto1: BuilderSchemaDto = {
138
111
  };
139
112
 
140
113
  const SCHEMA_ID = SchemaID.create();
141
- const schemaPrefixA = SchemaPrefix.castOrCreateRandom("a").value;
142
- let builderSchema = BuilderSchema.create(SCHEMA_ID, "test", schemaPrefixA);
114
+ const SCHEMA_PREFIX_A = SchemaPrefix.castOrCreateRandom("a").value;
115
+ let s1 = BuilderSchema.create(SCHEMA_ID, "test-name", SCHEMA_PREFIX_A);
143
116
 
144
117
  beforeEach(() => {
145
- builderSchema = BuilderSchema.create(SCHEMA_ID, "test-name", schemaPrefixA);
118
+ s1 = BuilderSchema.create(SCHEMA_ID, "test-name", SCHEMA_PREFIX_A);
146
119
  });
147
120
 
148
121
  describe("Builder schema", () => {
149
122
  test("Can add pages.", () => {
150
- builderSchema.addPage("question");
151
- builderSchema.addPage("info-page");
152
- expect(builderSchema.pages.length).toBe(2);
153
- const dto = builderSchema.compile().schema;
123
+ s1.addPage("question");
124
+ s1.addPage("info-page");
125
+ expect(s1.pages.length).toBe(2);
126
+ const dto = s1.compile().schema;
154
127
  expect(dto.pages.length).toBe(2);
155
- expect(dto.id).toBe(builderSchema.id);
156
- expect(dto.baseHeight).toBe(builderSchema.baseHeight);
157
- expect(dto.baseWidth).toBe(builderSchema.baseWidth);
158
- expect(dto.backgroundColor).toBe(builderSchema.backgroundColor);
128
+ expect(dto.id).toBe(s1.id);
129
+ expect(dto.baseHeight).toBe(s1.baseHeight);
130
+ expect(dto.baseWidth).toBe(s1.baseWidth);
131
+ expect(dto.backgroundColor).toBe(s1.backgroundColor);
159
132
  });
160
133
 
161
134
  test("Can delete page by passing reference", () => {
162
- const p1 = builderSchema.addPage("question");
163
- const p2 = builderSchema.addPage("question");
164
- const p3 = builderSchema.addPage("info-page");
165
- expect(builderSchema.pages.length).toBe(3);
166
- const result = builderSchema.deletePage(p1);
167
- expect(builderSchema.pages.length).toBe(2);
135
+ const p1 = s1.addPage("question");
136
+ const p2 = s1.addPage("question");
137
+ const p3 = s1.addPage("info-page");
138
+ expect(s1.pages.length).toBe(3);
139
+ const result = s1.deletePage(p1);
140
+ expect(s1.pages.length).toBe(2);
168
141
  expect(result).toBe(true);
169
- const result2 = builderSchema.deletePage(p2);
142
+ const result2 = s1.deletePage(p2);
170
143
  expect(result2).toBe(true);
171
- expect(builderSchema.pages.length).toBe(1);
172
- expect(builderSchema.pages[0]).toBe(p3);
173
- const result3 = builderSchema.deletePage(p2);
144
+ expect(s1.pages.length).toBe(1);
145
+ expect(s1.pages[0]).toBe(p3);
146
+ const result3 = s1.deletePage(p2);
174
147
  expect(result3).toBe(false);
175
- const result4 = builderSchema.deletePage(p3);
148
+ const result4 = s1.deletePage(p3);
176
149
  expect(result4).toBe(true);
177
150
  });
178
151
 
@@ -205,73 +178,77 @@ describe("Builder schema", () => {
205
178
  const json = s.toJson();
206
179
  expect(schemaDto1).toStrictEqual(json);
207
180
  });
181
+
208
182
  test("Can add page at concrete index", () => {
209
- const p1 = builderSchema.addPage("form");
183
+ const p1 = s1.addPage("form");
210
184
  expect(p1.pageType).toBe("form");
211
- const p2 = builderSchema.addPage("multi-select", 0);
185
+ const p2 = s1.addPage("multi-select", 0);
212
186
  expect(p2.pageType).toBe("multi-select");
213
- const pages = builderSchema.pages;
187
+ const pages = s1.pages;
214
188
  expect(pages[0].id).toBe(p2.id);
215
- builderSchema.addPage("form");
216
- builderSchema.addPage("form");
217
- const last = builderSchema.addPage("form");
218
- expect(builderSchema.pages[builderSchema.pages.length - 1]).toBe(last);
219
- const p3 = builderSchema.addPage("info-page", 4);
189
+ s1.addPage("form");
190
+ s1.addPage("form");
191
+ const last = s1.addPage("form");
192
+ expect(s1.pages[s1.pages.length - 1]).toBe(last);
193
+ const p3 = s1.addPage("info-page", 4);
220
194
  expect(pages[4].id).toBe(p3.id);
221
195
  });
196
+
222
197
  test("Can move page up and down", () => {
223
- const p1 = builderSchema.addPage("form");
224
- const p2 = builderSchema.addPage("form");
225
- const p3 = builderSchema.addPage("form");
226
- const p4 = builderSchema.addPage("multi-select");
227
- const last = builderSchema.addPage("form");
228
- const pages = builderSchema.pages;
229
- builderSchema.movePage(p2, 0);
198
+ const p1 = s1.addPage("form");
199
+ const p2 = s1.addPage("form");
200
+ const p3 = s1.addPage("form");
201
+ const p4 = s1.addPage("multi-select");
202
+ const last = s1.addPage("form");
203
+ const pages = s1.pages;
204
+ s1.movePage(p2, 0);
230
205
  expect(pages[0]).toBe(p2);
231
206
  expect(pages[1]).toBe(p1);
232
- expect(builderSchema.movePage(p4, 4)).toBeTruthy();
233
- expect(builderSchema.movePage(p4, 5)).toBeFalsy();
234
- expect(builderSchema.movePage(p4, 10)).toBeFalsy();
207
+ expect(s1.movePage(p4, 4)).toBeTruthy();
208
+ expect(s1.movePage(p4, 5)).toBeFalsy();
209
+ expect(s1.movePage(p4, 10)).toBeFalsy();
235
210
 
236
211
  // expect(pages[0].id).toBe(p4.id);
237
212
  });
213
+
238
214
  test("Can clone a page and insert at index", () => {
239
- const p1 = builderSchema.addPage("form");
240
- const p2 = builderSchema.addPage("form");
241
- const p3 = builderSchema.addPage("form");
215
+ const p1 = s1.addPage("form");
216
+ const p2 = s1.addPage("form");
217
+ const p3 = s1.addPage("form");
242
218
  const mainTextContent = "Hello from test";
243
- const p4 = builderSchema.addPage("multi-select");
219
+ const p4 = s1.addPage("multi-select");
244
220
  p3.mainText.text = mainTextContent;
245
221
  const p1Clone = BuilderPage.fromJson(p1.clone());
246
- const beforeLen = builderSchema.pages.length;
247
- builderSchema.insertPage(p1Clone, 2);
248
- const pages = builderSchema.pages;
222
+ const beforeLen = s1.pages.length;
223
+ s1.insertPage(p1Clone, 2);
224
+ const pages = s1.pages;
249
225
  expect(beforeLen + 1).toBe(pages.length);
250
226
  expect(pages[2]).toBe(p1Clone);
251
227
  });
228
+
252
229
  test("Will not insert a page that is already in array.", () => {
253
- const p1 = builderSchema.addPage("form");
254
- const p2 = builderSchema.addPage("form");
255
- const p3 = builderSchema.addPage("form");
256
- const beforeLen = builderSchema.pages.length;
257
- const result = builderSchema.insertPage(p1, 0);
258
- const pages = builderSchema.pages;
230
+ const p1 = s1.addPage("form");
231
+ const p2 = s1.addPage("form");
232
+ const p3 = s1.addPage("form");
233
+ const beforeLen = s1.pages.length;
234
+ const result = s1.insertPage(p1, 0);
235
+ const pages = s1.pages;
259
236
  expect(beforeLen).toBe(pages.length);
260
237
  expect(result).toBe(false);
261
238
  });
262
239
 
263
240
  test("Can generate a info-page", () => {
264
- const p1 = builderSchema.addPage("info-page");
265
- const p2 = builderSchema.addPage("question");
241
+ const p1 = s1.addPage("info-page");
242
+ const p2 = s1.addPage("question");
266
243
  p2.defaultQuestion.addOption("Ja", 1, 0);
267
244
  p2.defaultQuestion.addOption("Nei", 0);
268
245
  p1.nextButton.label = "Neste";
269
- builderSchema.backgroundColor = "red";
270
- builderSchema.baseHeight = 600;
271
- builderSchema.baseWidth = 500;
246
+ s1.backgroundColor = "red";
247
+ s1.baseHeight = 600;
248
+ s1.baseWidth = 500;
272
249
  // builderSchema.prefix = "as";
273
- builderSchema.name = "depressed";
274
- const schema = builderSchema.compile().schema;
250
+ s1.name = "depressed";
251
+ const schema = s1.compile().schema;
275
252
  expect(schema.backgroundColor).toBe("red");
276
253
  expect(schema.baseHeight).toBe(600);
277
254
  expect(schema.baseWidth).toBe(500);
@@ -287,17 +264,17 @@ describe("Builder schema", () => {
287
264
  // expect(schemaP2.elements.length).toBe(options.length + 1);
288
265
  });
289
266
  test("Can get ruleInput!", () => {
290
- const p0 = builderSchema.addPage("info-page");
267
+ const p0 = s1.addPage("info-page");
291
268
  // p0.prefix = "info_page_prefix_";
292
- const p1 = builderSchema.addPage("question");
269
+ const p1 = s1.addPage("question");
293
270
  // p1.prefix = "p1_prefix_";
294
- const p2 = builderSchema.addPage("question");
271
+ const p2 = s1.addPage("question");
295
272
  // p2.prefix = "p2_prefix_";
296
273
  p1.defaultQuestion.addOption("Ja", 1, 0);
297
274
  p1.defaultQuestion.addOption("Nei", 0, 0);
298
275
  p2.defaultQuestion.addOption("Ja", 1, 0);
299
276
  p2.defaultQuestion.addOption("Nei", 0);
300
- const ruleInput = builderSchema.getRuleInput();
277
+ const ruleInput = s1.getRuleInput();
301
278
  expect(ruleInput.questionVars.length).toBe(2);
302
279
  expect(ruleInput.jumpToPageActions.length).toBe(3);
303
280
  // TODO add TAGS!!
@@ -314,31 +291,26 @@ describe("Builder schema", () => {
314
291
  expect(allPageIds.has(v.pageId)).toBe(true);
315
292
  });
316
293
  });
317
- test.skip("Can add sum-variables - and save as json", () => {
294
+
295
+ test("Can add sum-variables, but not twice", () => {
318
296
  // p0.prefix = "info_page_prefix_";
319
- const p1 = builderSchema.addPage("question");
320
- const p2 = builderSchema.addPage("question");
297
+ const p1 = s1.addPage("question");
298
+ const p2 = s1.addPage("question");
321
299
  p1.prefix = PagePrefix.fromStringOrThrow("p1_prefix");
322
300
  p2.prefix = PagePrefix.fromStringOrThrow("p2_prefix");
323
- p1.defaultQuestion.addOption("Ja", 1, 0);
324
- p1.defaultQuestion.addOption("Nei", 0, 0);
325
- p2.defaultQuestion.addOption("Ja", 1, 0);
326
- p2.defaultQuestion.addOption("Nei", 0);
327
301
 
328
- const ruleInput = builderSchema.getRuleInput();
329
302
  const ss1: SumScoreVariableDto = {
330
- label: "ss1",
331
- varId: "ss1_var_id",
332
- initialValue: 0,
333
- kind: "numeric-variable",
334
- origin: "sum-score",
303
+ id: SumScoreVariableID.dummy.a,
304
+ name: "ss1",
305
+ description: "",
306
+ useAvg: false,
335
307
  basedOn: [],
336
308
  };
337
309
 
338
- builderSchema.addSumScoreVariable(ss1);
310
+ s1.addSumScoreVariable(ss1);
311
+ s1.addSumScoreVariable(ss1);
339
312
 
340
- expect(ruleInput.questionVars.length).toBe(2);
341
- expect(ruleInput.jumpToPageActions.length).toBe(3);
313
+ // expect(s1.sumScoreVariables.length).toBe(1);
342
314
 
343
315
  // TODO add TAGS!!
344
316
  // expect(ruleInput.excludeByTagActions.length).toBe(0);
@@ -2,13 +2,13 @@ import type { BuilderPageDto, BuilderPageType } from "./Builder-page";
2
2
  import { BuilderPage } from "./Builder-page";
3
3
  import type {
4
4
  BuilderRuleDto,
5
- CustomVariable,
6
5
  ExcludeByPageAction,
7
6
  ExcludeByTagAction,
8
7
  JumpToPageAction,
8
+ RuleCustomVariable,
9
9
  } from "./rulebuilder";
10
10
  import { BuilderRule, RuleInput } from "./rulebuilder";
11
- import type { QuestionVariable } from "./rulebuilder/RuleVariable";
11
+ import type { RuleQuestionVariable } from "./rulebuilder/RuleVariable";
12
12
  import type { BuilderTagDto } from "./BuilderTag";
13
13
  import { BuilderTag, TagCollection } from "./BuilderTag";
14
14
  import { DefaultThemeCompiler } from "./theme/default-theme-compiler";
@@ -16,13 +16,14 @@ import { ImageFile } from "./media-files";
16
16
  import { DUtil } from "@media-quest/engine";
17
17
  import { PagePrefix } from "./primitives/page-prefix";
18
18
  import { SchemaPrefix, SchemaPrefixValue } from "./primitives/schema-prefix";
19
- import { CodeBook } from "./codebook";
20
- import { PredefinedVariable } from "./variable/b-variable";
19
+ import { CodeBook } from "./code-book/codebook";
20
+ import { CodebookPredefinedVariable } from "./code-book/codebook-variable";
21
21
  import { SchemaConfig } from "./schema-config";
22
22
  import { CompilerOption, CompilerOutput } from "./builder-compiler";
23
23
 
24
- import { SumScoreVariableDto } from "./variable/sum-score-variable";
24
+ import { SumScoreVariableDto } from "./sum-score/sum-score-variable";
25
25
  import { SchemaID } from "./primitives/ID";
26
+ import { SumScoreMembershipDto } from "./sum-score/sum-score-membership";
26
27
 
27
28
  const U = DUtil;
28
29
 
@@ -35,8 +36,9 @@ export interface BuilderSchemaDto {
35
36
  readonly pages: BuilderPageDto[];
36
37
  readonly baseHeight: number;
37
38
  readonly baseWidth: number;
38
- readonly predefinedVariables?: Array<PredefinedVariable>;
39
+ readonly predefinedVariables?: Array<CodebookPredefinedVariable>;
39
40
  readonly sumScoreVariables?: ReadonlyArray<SumScoreVariableDto>;
41
+ readonly sumScoreMemberShips?: ReadonlyArray<SumScoreMembershipDto>;
40
42
  readonly rules: ReadonlyArray<BuilderRuleDto>;
41
43
  readonly tags: ReadonlyArray<BuilderTagDto>;
42
44
  }
@@ -52,7 +54,7 @@ export class BuilderSchema {
52
54
  backgroundColor = "#000000";
53
55
  pages: BuilderPage[] = [];
54
56
  mainImage: ImageFile | false = false;
55
- predefinedVariables: PredefinedVariable[] = [];
57
+ predefinedVariables: CodebookPredefinedVariable[] = [];
56
58
  private _rules: BuilderRule[] = [];
57
59
  private _sumVariables: SumScoreVariableDto[] = [];
58
60
  get rules(): ReadonlyArray<BuilderRule> {
@@ -139,6 +141,8 @@ export class BuilderSchema {
139
141
  addSumScoreVariable(variable: SumScoreVariableDto) {
140
142
  // TODO VALIDATE.
141
143
  this._sumVariables.push({ ...variable });
144
+
145
+ return variable;
142
146
  }
143
147
 
144
148
  insertPage(page: BuilderPage, atIndex: number): boolean {
@@ -210,8 +214,8 @@ export class BuilderSchema {
210
214
  }
211
215
 
212
216
  getRuleInput(): RuleInput {
213
- const qVars: QuestionVariable[] = [];
214
- const cVars: CustomVariable[] = [];
217
+ const qVars: RuleQuestionVariable[] = [];
218
+ const cVars: RuleCustomVariable[] = [];
215
219
  const pageIdActions: ExcludeByPageAction[] = [];
216
220
  const tagActions: ExcludeByTagAction[] = this.tags.map((t) => {
217
221
  const tag = t.tagText;
@@ -1,24 +1,24 @@
1
- import type { BuilderTextDto } from "./Builder-text";
2
- import { BuilderText } from "./Builder-text";
3
- import { TextID } from "./primitives/ID";
4
-
5
- const textDto: BuilderTextDto = {
6
- id: "dto1" as TextID,
7
- name: "dto1-name",
8
- text: "text one",
9
- translationRequired: true,
10
- };
11
-
12
- let text1 = BuilderText.create("text one created");
13
-
14
- beforeEach(() => {
15
- text1 = BuilderText.create("text one created");
16
- });
17
-
18
- describe("Builder Text", () => {
19
- test("Can serialize", () => {
20
- const instance1 = BuilderText.fromJson(textDto);
21
- const json = instance1.toJson();
22
- expect(textDto).toStrictEqual(json);
23
- });
24
- });
1
+ import type { BuilderTextDto } from "./Builder-text";
2
+ import { BuilderText } from "./Builder-text";
3
+ import { TextID } from "./primitives/ID";
4
+
5
+ const textDto: BuilderTextDto = {
6
+ id: "dto1" as TextID,
7
+ name: "dto1-name",
8
+ text: "text one",
9
+ translationRequired: true,
10
+ };
11
+
12
+ let text1 = BuilderText.create("text one created");
13
+
14
+ beforeEach(() => {
15
+ text1 = BuilderText.create("text one created");
16
+ });
17
+
18
+ describe("Builder Text", () => {
19
+ test("Can serialize", () => {
20
+ const instance1 = BuilderText.fromJson(textDto);
21
+ const json = instance1.toJson();
22
+ expect(textDto).toStrictEqual(json);
23
+ });
24
+ });