@media-quest/builder 0.0.1 → 0.0.3

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 (49) hide show
  1. package/dist/public-api.d.mts +652 -0
  2. package/dist/public-api.d.ts +652 -0
  3. package/dist/public-api.js +2187 -0
  4. package/dist/public-api.mjs +2136 -0
  5. package/package.json +11 -3
  6. package/src/Builder-option.ts +67 -0
  7. package/src/Builder-page.spec.ts +313 -0
  8. package/src/Builder-page.ts +249 -0
  9. package/src/Builder-question.spec.ts +68 -0
  10. package/src/Builder-question.ts +101 -0
  11. package/src/Builder-schema.spec.ts +302 -0
  12. package/src/Builder-schema.ts +250 -0
  13. package/src/Builder-text.spec.ts +24 -0
  14. package/src/Builder-text.ts +57 -0
  15. package/src/BuilderMainImageDto.ts +7 -0
  16. package/src/BuilderMainText.ts +81 -0
  17. package/src/BuilderMainVideoDto.ts +10 -0
  18. package/src/BuilderObject.ts +69 -0
  19. package/src/BuilderTag.ts +97 -0
  20. package/src/media-files.ts +28 -0
  21. package/src/public-api.ts +13 -6
  22. package/src/rulebuilder/Builder-rule.spec.ts +207 -0
  23. package/src/rulebuilder/Builder-rule.ts +134 -0
  24. package/src/rulebuilder/RuleAction.ts +20 -0
  25. package/src/rulebuilder/RuleBuilder-test-utils.ts +254 -0
  26. package/src/rulebuilder/RuleInput.ts +44 -0
  27. package/src/rulebuilder/RuleVariable.ts +39 -0
  28. package/src/rulebuilder/SingleSelectItem.ts +135 -0
  29. package/src/rulebuilder/condition/Builder-condition-group.spec.ts +47 -0
  30. package/src/rulebuilder/condition/Builder-condition-group.ts +91 -0
  31. package/src/rulebuilder/condition/Builder-condition.spec.ts +169 -0
  32. package/src/rulebuilder/condition/Builder-condition.ts +186 -0
  33. package/src/rulebuilder/condition/Builder-operator.spec.ts +9 -0
  34. package/src/rulebuilder/condition/Builder-operator.ts +31 -0
  35. package/src/rulebuilder/index.ts +22 -0
  36. package/src/rulebuilder/jump-to-action-manager.ts +33 -0
  37. package/src/rulebuilder/multi-select-item.ts +70 -0
  38. package/src/rulebuilder/page-action-manager.ts +20 -0
  39. package/src/rulebuilder/tag-action-manager.spec.ts +44 -0
  40. package/src/rulebuilder/tag-action-manager.ts +18 -0
  41. package/src/theme/AbstractThemeCompiler.ts +7 -0
  42. package/src/theme/IDefaultTheme.ts +178 -0
  43. package/src/theme/css-theme.ts +7 -0
  44. package/src/theme/default-theme-compiler.ts +395 -0
  45. package/src/theme/icon-urls.ts +29 -0
  46. package/src/theme/standard-props.ts +113 -0
  47. package/src/theme/theme-utils.ts +110 -0
  48. package/src/theme/theme1.spec.ts +52 -0
  49. package/tsconfig.json +0 -2
@@ -0,0 +1,135 @@
1
+ import { BuilderVariable, BuilderVariableOption } from "./RuleVariable";
2
+ import { BuilderOperator } from "./condition/Builder-operator";
3
+ import { JumpToPageAction } from "./RuleAction";
4
+
5
+ export abstract class SingleSelectItem<T> {
6
+ private readonly _selectLabel;
7
+ private readonly _toolTip;
8
+ private readonly _searchString;
9
+ get selectLabel(): string {
10
+ return this._selectLabel;
11
+ }
12
+ get tooltip() {
13
+ return this._toolTip;
14
+ }
15
+
16
+ get searchString() {
17
+ return this._searchString;
18
+ }
19
+
20
+ protected constructor(readonly data: T) {
21
+ this._selectLabel = this.getSelectLabel();
22
+ this._toolTip = this.getTooltip();
23
+ this._searchString = this.getSearchString();
24
+ }
25
+ protected abstract getSelectLabel(): string;
26
+ protected abstract getTooltip(): string;
27
+ protected abstract getSearchString(): string;
28
+ }
29
+
30
+ export class RuleVariableSelectItem extends SingleSelectItem<BuilderVariable> {
31
+ public static create = (data: BuilderVariable) => {
32
+ return new RuleVariableSelectItem(data);
33
+ };
34
+ readonly options: ReadonlyArray<RuleOptionSelectItem>;
35
+ constructor(readonly data: BuilderVariable) {
36
+ super(data);
37
+ this.options = data.options.map(RuleOptionSelectItem.create);
38
+ }
39
+
40
+ protected getSearchString(): string {
41
+ return this.data.varId + this.data.label;
42
+ }
43
+
44
+ getSelectLabel(): string {
45
+ return this.data.varId;
46
+ }
47
+
48
+ getTooltip(): string {
49
+ return this.data.label;
50
+ }
51
+ }
52
+
53
+ export class RuleOptionSelectItem extends SingleSelectItem<BuilderVariableOption> {
54
+ public static create = (option: BuilderVariableOption) => {
55
+ return new RuleOptionSelectItem(option);
56
+ };
57
+ private constructor(option: BuilderVariableOption) {
58
+ super(option);
59
+ }
60
+ protected getSearchString(): string {
61
+ return "";
62
+ }
63
+
64
+ protected getSelectLabel(): string {
65
+ return this.data.label + "(" + this.data.value + ")";
66
+ }
67
+
68
+ protected getTooltip(): string {
69
+ return "";
70
+ }
71
+ }
72
+
73
+ export class OperatorSelectItem extends SingleSelectItem<BuilderOperator | ""> {
74
+ public static readonly EQ = new OperatorSelectItem("equal");
75
+ public static readonly NOT_EQ = new OperatorSelectItem("notEqual");
76
+ public static readonly fromSymbol = (
77
+ symbol: BuilderOperator | Omit<string, BuilderOperator>,
78
+ ): OperatorSelectItem | false => {
79
+ if (symbol === "equal") {
80
+ return OperatorSelectItem.EQ;
81
+ }
82
+ if (symbol === "notEqual") {
83
+ return OperatorSelectItem.NOT_EQ;
84
+ }
85
+ return false;
86
+ };
87
+ private constructor(operator: BuilderOperator) {
88
+ super(operator);
89
+ }
90
+
91
+ protected getSearchString(): string {
92
+ return "";
93
+ }
94
+
95
+ protected getSelectLabel(): string {
96
+ const operator = this.data;
97
+ if (operator === "equal") {
98
+ return "Equals";
99
+ }
100
+ if (operator === "notEqual") {
101
+ return "Not equals";
102
+ }
103
+ return "";
104
+ }
105
+
106
+ protected getTooltip(): string {
107
+ const operator = this.data;
108
+ if (operator === "equal") {
109
+ return "Equals";
110
+ }
111
+ if (operator === "notEqual") {
112
+ return "Not equals";
113
+ }
114
+ return "";
115
+ }
116
+ }
117
+
118
+ export class JumpToPageSelectItem extends SingleSelectItem<JumpToPageAction> {
119
+ public static readonly create = (pageData: JumpToPageAction) => new JumpToPageSelectItem(pageData);
120
+ protected constructor(pageData: JumpToPageAction) {
121
+ super(pageData);
122
+ }
123
+
124
+ protected getSearchString(): string {
125
+ return this.data.pageId + this.data.mainText;
126
+ }
127
+
128
+ protected getSelectLabel(): string {
129
+ return this.data.pageId + " (" + this.data.pageNumber + ")";
130
+ }
131
+
132
+ protected getTooltip(): string {
133
+ return this.data.mainText;
134
+ }
135
+ }
@@ -0,0 +1,47 @@
1
+ import { BuilderConditionGroup } from "./Builder-condition-group";
2
+
3
+ let group = BuilderConditionGroup.fromDto(
4
+ {
5
+ kind: "condition-group",
6
+ name: "g1",
7
+ type: "all",
8
+ conditions: [],
9
+ },
10
+ []
11
+ );
12
+ beforeEach(() => {});
13
+
14
+ describe("Builder Operator", () => {
15
+ test("Can create", () => {
16
+ expect(group).toBeInstanceOf(BuilderConditionGroup);
17
+ group.name = "group1";
18
+ expect(group.name).toBe("group1");
19
+ });
20
+
21
+ test("Can add condition", () => {
22
+ const condition = group.addCondition();
23
+ expect(group.conditions.length).toBe(1);
24
+ const success = group.removeCondition(condition);
25
+ expect(success).toBe(true);
26
+ expect(group.conditions.length).toBe(0);
27
+ });
28
+ test("Can add condition when many", () => {
29
+ const c1 = group.addCondition();
30
+ const c2 = group.addCondition();
31
+ const c3 = group.addCondition();
32
+ const c4 = group.addCondition();
33
+ const c5 = group.addCondition();
34
+ expect(group.conditionCount).toBe(5);
35
+ const success = group.removeCondition(c3);
36
+ expect(success).toBe(true);
37
+ const fail = group.removeCondition(c3);
38
+ expect(fail).toBe(false);
39
+ expect(group.conditions[0]).toBe(c1);
40
+ expect(group.conditions[1]).toBe(c2);
41
+ expect(group.conditions[2]).toBe(c4);
42
+ expect(group.conditions[3]).toBe(c5);
43
+ // expect(group.conditions.length).toBe(0);
44
+ });
45
+
46
+ test("Can create operator from symbol", () => {});
47
+ });
@@ -0,0 +1,91 @@
1
+ import { BuilderCondition, type BuilderConditionDto } from "./Builder-condition";
2
+ import { BuilderObject } from "../../BuilderObject";
3
+ import type { BuilderVariable } from "../RuleVariable";
4
+
5
+ const ConditionGroupType = {
6
+ all: true,
7
+ any: true,
8
+ count: true,
9
+ range: true,
10
+ };
11
+
12
+ export type ConditionGroupType = keyof typeof ConditionGroupType;
13
+ export interface BuilderConditionGroupDto {
14
+ readonly kind: "condition-group";
15
+ readonly name: string;
16
+ readonly type: ConditionGroupType;
17
+ readonly conditions: ReadonlyArray<BuilderConditionDto>;
18
+ }
19
+
20
+ export class BuilderConditionGroup extends BuilderObject<"builder-condition-group", BuilderConditionGroupDto> {
21
+ static readonly isConditionGroupType = (value: string | symbol): value is ConditionGroupType => {
22
+ if (typeof value !== "string") {
23
+ return false;
24
+ }
25
+ const validValues = Object.keys(ConditionGroupType);
26
+ return validValues.includes(value);
27
+ };
28
+
29
+ readonly objectType: "builder-condition-group" = "builder-condition-group";
30
+ private _type: ConditionGroupType;
31
+ name = "";
32
+ private readonly _conditions: Array<BuilderCondition>;
33
+ private readonly _variableList: ReadonlyArray<BuilderVariable>;
34
+
35
+ public static readonly fromDto = (dto: BuilderConditionGroupDto, variableList: ReadonlyArray<BuilderVariable>) => {
36
+ return new BuilderConditionGroup(dto, variableList);
37
+ };
38
+ protected constructor(dto: BuilderConditionGroupDto, variableList: ReadonlyArray<BuilderVariable>) {
39
+ super(dto);
40
+ this.name = dto.name;
41
+ this._type = dto.type;
42
+ const conditionList = Array.isArray(dto.conditions) ? dto.conditions : [];
43
+ this._conditions = conditionList.map((dto) => BuilderCondition.fromDto(dto, variableList));
44
+ this._variableList = variableList;
45
+ }
46
+ get conditions(): ReadonlyArray<BuilderCondition> {
47
+ return this._conditions;
48
+ }
49
+
50
+ get conditionCount() {
51
+ return this._conditions.length;
52
+ }
53
+
54
+ addCondition(): BuilderCondition {
55
+ const newConditions = BuilderCondition.create(this._variableList);
56
+ this._conditions.push(newConditions);
57
+ return newConditions;
58
+ }
59
+
60
+ removeCondition(condition: BuilderCondition): boolean {
61
+ // this._conditions.
62
+ const index = this._conditions.indexOf(condition);
63
+ if (index < 0) {
64
+ return false;
65
+ }
66
+ this._conditions.splice(index, 1);
67
+ return true;
68
+ }
69
+
70
+ clone(): BuilderConditionGroupDto {
71
+ return this.toJson();
72
+ }
73
+
74
+ toJson(): BuilderConditionGroupDto {
75
+ const conditions: ReadonlyArray<BuilderConditionDto> = [...this._conditions.map((c) => c.toJson())];
76
+ return {
77
+ name: this.name,
78
+ conditions,
79
+ type: this._type,
80
+ kind: "condition-group",
81
+ };
82
+ }
83
+ get type(): ConditionGroupType {
84
+ return this._type;
85
+ }
86
+ set type(conditionGroupType: ConditionGroupType) {
87
+ if (BuilderConditionGroup.isConditionGroupType(conditionGroupType)) {
88
+ this._type = conditionGroupType;
89
+ }
90
+ }
91
+ }
@@ -0,0 +1,169 @@
1
+ import { BuilderCondition, type BuilderConditionDto } from "./Builder-condition";
2
+ import { RuleBuilderTestUtils } from "../RuleBuilder-test-utils";
3
+ import type { BuilderVariable, BuilderVariableOption } from "../RuleVariable";
4
+ import { QuestionVariable } from "../RuleVariable";
5
+
6
+ let condition = BuilderCondition.create([]);
7
+
8
+ beforeEach(() => {
9
+ condition = BuilderCondition.create([]);
10
+ });
11
+
12
+ describe("Builder Operator", () => {
13
+ test("Can create", () => {
14
+ expect(condition).toBeInstanceOf(BuilderCondition);
15
+ });
16
+ test("Can resolve dto from Variables in universe.", () => {
17
+ const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
18
+ const a = vs[0];
19
+ const dto: BuilderConditionDto = {
20
+ kind: "condition",
21
+ name: "a",
22
+ variableId: a.varId,
23
+ operator: "equal",
24
+ value: 1,
25
+ };
26
+ const c = BuilderCondition.fromDto(dto, vs);
27
+ // c.setVariableList(vs);
28
+ expect(c.operatorsSelectItems.length).toBe(2);
29
+ expect(c.operator === "equal").toBe(true);
30
+ expect(c.value).toBeTruthy();
31
+ });
32
+ test("Can not resolve value if invalid value", () => {
33
+ const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
34
+ const a = vs[0];
35
+ const dto: BuilderConditionDto = {
36
+ kind: "condition",
37
+ name: "a",
38
+ variableId: a.varId,
39
+ operator: "equal",
40
+ value: 8,
41
+ };
42
+ const c = BuilderCondition.fromDto(dto, vs);
43
+ expect(c.operatorsSelectItems.length).toBe(2);
44
+ expect(c.value).toBe(false);
45
+ // expect(match).toBe(false);
46
+ });
47
+ test("Will nullify dto if not matchedFrom is called", () => {
48
+ const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
49
+ const a = vs[0];
50
+ const dto: BuilderConditionDto = {
51
+ kind: "condition",
52
+ name: "a",
53
+ variableId: a.varId,
54
+ operator: "equal",
55
+ value: 0,
56
+ };
57
+ const c = BuilderCondition.fromDto(dto, []);
58
+ expect(c.operatorsSelectItems.length).toBe(0);
59
+ expect(c.toJson().name).toBe(dto.name);
60
+ expect(c.toJson().value).toBe("");
61
+ expect(c.toJson().operator).toBe("");
62
+ expect(c.toJson().variableId).toBe("");
63
+ // expect(match).toBe(false);
64
+ });
65
+ test("Will not nullify if created with valid universe", () => {
66
+ const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
67
+ const a = vs[0];
68
+ const dto: BuilderConditionDto = {
69
+ kind: "condition",
70
+ name: "a",
71
+ variableId: a.varId,
72
+ operator: "equal",
73
+ value: 0,
74
+ };
75
+ const c = BuilderCondition.fromDto(dto, vs);
76
+ expect(c.variable).toBeInstanceOf(QuestionVariable);
77
+ expect(c.operator === "equal").toBe(true);
78
+ const value = c.value as BuilderVariableOption;
79
+ expect(value.value).toBe(0);
80
+ expect(value.label).toBe("Nei");
81
+ expect(c.variable).toBe(a);
82
+ });
83
+ test("Condition is valid, when in sync with universe.", () => {
84
+ const vs = RuleBuilderTestUtils.createBuilderVariables_A_H();
85
+ const a = vs[0];
86
+ const dto: BuilderConditionDto = {
87
+ kind: "condition",
88
+
89
+ name: "name of a",
90
+ variableId: a.varId,
91
+ operator: "equal",
92
+ value: 0,
93
+ };
94
+ const c = BuilderCondition.fromDto(dto, vs);
95
+ expect(c.variable).toBeInstanceOf(QuestionVariable);
96
+ expect(c.operator === "equal").toBe(true);
97
+ const value = c.value as BuilderVariableOption;
98
+ expect(value.value).toBe(0);
99
+ expect(value.label).toBe("Nei");
100
+ expect(c.validate().isValid).toBe(true);
101
+ });
102
+ test("Condition is invalid, when not matched against universe", () => {
103
+ const dto: BuilderConditionDto = {
104
+ kind: "condition",
105
+ name: "name of a",
106
+ variableId: "a",
107
+ operator: "equal",
108
+ value: 0,
109
+ };
110
+ const c = BuilderCondition.fromDto(dto, []);
111
+ expect(c.validate().isValid).toBe(false);
112
+ });
113
+ test("Condition is invalid, when variable dont exist in universe.", () => {
114
+ const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
115
+ const dto: BuilderConditionDto = {
116
+ kind: "condition",
117
+ name: "invalid variable name in dto",
118
+ variableId: "kkk",
119
+ operator: "equal",
120
+ value: 9,
121
+ };
122
+ const c = BuilderCondition.fromDto(dto, universe);
123
+ expect(c.variable).toBe(false);
124
+ expect(c.validate().isValid).toBe(false);
125
+ });
126
+ test("Condition is invalid if not all set, when variable dont exist in universe.", () => {
127
+ const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
128
+ const dto: BuilderConditionDto = {
129
+ kind: "condition",
130
+ name: "invalid variable name in dto",
131
+ variableId: "kkk",
132
+ operator: "equal",
133
+ value: 9,
134
+ };
135
+ const c = BuilderCondition.fromDto(dto, universe);
136
+ expect(c.variable).toBe(false);
137
+ expect(c.validate().isValid).toBe(false);
138
+ });
139
+ test("Condition is invalid if operator is not set", () => {
140
+ const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
141
+ const dto: BuilderConditionDto = {
142
+ kind: "condition",
143
+ name: "invalid variable name in dto",
144
+ variableId: "a",
145
+ operator: "",
146
+ value: 1,
147
+ };
148
+ const c = BuilderCondition.fromDto(dto, universe);
149
+ expect(c.variable).toBeInstanceOf(QuestionVariable);
150
+ expect(c.validate().isValid).toBe(false);
151
+ expect(c.value).toBe(false);
152
+ });
153
+ test("Condition is invalid if value (from dto) is not found in variable", () => {
154
+ const universe = RuleBuilderTestUtils.createBuilderVariables_A_H();
155
+ const dto: BuilderConditionDto = {
156
+ kind: "condition",
157
+ name: "invalid variable name in dto",
158
+ variableId: "a",
159
+ operator: "equal",
160
+ value: 7,
161
+ };
162
+ const c = BuilderCondition.fromDto(dto, universe);
163
+ expect(c.variable).toBeInstanceOf(QuestionVariable);
164
+ expect(c.operator).toBe("equal");
165
+ expect(c.operatorsSelectItems.length).toBe(BuilderCondition.NUMBER_OPERATORS.length);
166
+ expect(c.value).toBe(false);
167
+ expect(c.validate().isValid).toBe(false);
168
+ });
169
+ });
@@ -0,0 +1,186 @@
1
+ import { BuilderObject } from "../../BuilderObject";
2
+ import { BuilderOperator } from "./Builder-operator";
3
+ import type { BuilderVariable, BuilderVariableOption } from "../RuleVariable";
4
+ import { OperatorSelectItem, RuleOptionSelectItem, RuleVariableSelectItem } from "../SingleSelectItem";
5
+ export interface BuilderConditionDto {
6
+ readonly kind: "condition";
7
+ readonly operator: BuilderOperator | "";
8
+ readonly name: string;
9
+ readonly variableId: string;
10
+ readonly value: number | string | boolean;
11
+ }
12
+
13
+ export class BuilderCondition extends BuilderObject<"builder-condition", BuilderConditionDto> {
14
+ readonly objectType: "builder-condition" = "builder-condition";
15
+ public static readonly NUMBER_OPERATORS: ReadonlyArray<OperatorSelectItem> = [
16
+ OperatorSelectItem.EQ,
17
+ OperatorSelectItem.NOT_EQ,
18
+ ];
19
+
20
+ private initialDto: BuilderConditionDto;
21
+ name = "";
22
+
23
+ public static create = (variableList: ReadonlyArray<BuilderVariable>) => {
24
+ const condition = new BuilderCondition(
25
+ {
26
+ kind: "condition",
27
+ name: "",
28
+ operator: "",
29
+ variableId: "",
30
+ value: "",
31
+ },
32
+ variableList,
33
+ );
34
+ return condition;
35
+ };
36
+
37
+ public static fromDto = (dto: BuilderConditionDto, variables: ReadonlyArray<BuilderVariable>) => {
38
+ const _dto: BuilderConditionDto = {
39
+ kind: "condition",
40
+ name: dto.name ?? "",
41
+ value: dto.value ?? "",
42
+ operator: dto.operator ?? "",
43
+ variableId: dto.variableId ?? "",
44
+ };
45
+ const instance = new BuilderCondition(_dto, variables);
46
+ return instance;
47
+ };
48
+ private _variable: BuilderVariable | false = false;
49
+ private _operator: BuilderOperator | "" = "";
50
+ private _value: BuilderVariableOption | false = false;
51
+ private _variableList: ReadonlyArray<BuilderVariable> = [];
52
+
53
+ /**
54
+ * Can only set variables that exist in variableList.
55
+ * @param variable
56
+ */
57
+ set variable(variable: BuilderVariable | false) {
58
+ if (variable === this._variable) {
59
+ return;
60
+ }
61
+ this._variable = variable;
62
+ this._operator = "";
63
+ this._value = false;
64
+ }
65
+
66
+ get variable() {
67
+ return this._variable;
68
+ }
69
+
70
+ set value(variableValue: BuilderVariableOption | false) {
71
+ this._value = variableValue;
72
+ }
73
+ get value() {
74
+ return this._value;
75
+ }
76
+
77
+ validate(): { isValid: true } | { isValid: false; message: string } {
78
+ if (this._variableList.length === 0) {
79
+ return {
80
+ isValid: false,
81
+ message: "Has no variableList to check dto against.",
82
+ };
83
+ }
84
+ if (!this._variable) {
85
+ return {
86
+ isValid: false,
87
+ message: "Variable has not been initialized from variableList.",
88
+ };
89
+ }
90
+
91
+ if (!this._operator) {
92
+ return { isValid: false, message: "Operator has not been initialized" };
93
+ }
94
+
95
+ if (!this._value) {
96
+ return {
97
+ isValid: false,
98
+ message: "Value (BuilderVariableOption) is not initialized",
99
+ };
100
+ }
101
+
102
+ return { isValid: true };
103
+ }
104
+
105
+ private findVariableInUniverse(variableId: string): BuilderVariable | false {
106
+ const v = this._variableList.find((v) => v.varId === variableId);
107
+ return v ?? false;
108
+ }
109
+
110
+ set operator(operator: BuilderOperator | "") {
111
+ if (BuilderOperator.is(operator)) {
112
+ this._operator = operator;
113
+ } else {
114
+ this._operator = "";
115
+ }
116
+ }
117
+
118
+ get operator() {
119
+ return this._operator;
120
+ }
121
+
122
+ private constructor(dto: BuilderConditionDto, variables: ReadonlyArray<BuilderVariable>) {
123
+ super(dto);
124
+ this.initialDto = dto;
125
+ this.name = dto.name;
126
+ this._setVariableList(variables);
127
+ }
128
+
129
+ get variableSelectItemsInUniverse(): ReadonlyArray<RuleVariableSelectItem> {
130
+ return this._variableList.map(RuleVariableSelectItem.create);
131
+ }
132
+
133
+ get operatorsSelectItems(): ReadonlyArray<OperatorSelectItem> {
134
+ return this._variable ? BuilderCondition.NUMBER_OPERATORS : [];
135
+ }
136
+
137
+ get selectValueItems(): ReadonlyArray<RuleOptionSelectItem> {
138
+ if (!this._variable) {
139
+ return [];
140
+ }
141
+ const opt = this._variable.options.map(RuleOptionSelectItem.create);
142
+ return opt;
143
+ }
144
+
145
+ clone(): BuilderConditionDto {
146
+ return this.toJson();
147
+ }
148
+
149
+ private _setVariableList(variables: ReadonlyArray<BuilderVariable>): boolean {
150
+ this._variableList = variables;
151
+ const v = this._variableList.find((v) => v.varId === this.originalDto.variableId);
152
+ if (!v) {
153
+ this._variable = false;
154
+ this._operator = "";
155
+ this._value = false;
156
+ return false;
157
+ }
158
+ this._variable = v;
159
+ const op = this.originalDto.operator;
160
+
161
+ if (!BuilderOperator.is(op)) {
162
+ return false;
163
+ }
164
+ this._operator = op;
165
+ const maybeOption = v.options.find((op) => op.value === this.originalDto.value);
166
+ if (!maybeOption) {
167
+ return false;
168
+ }
169
+ this._value = maybeOption;
170
+ return true;
171
+ }
172
+
173
+ toJson(): BuilderConditionDto {
174
+ const name = this.name;
175
+ const variableId = this._variable ? this._variable.varId : "";
176
+ const operator = this._operator ? this._operator : "";
177
+ const value = this._value ? this._value.value : "";
178
+ return {
179
+ kind: "condition",
180
+ name,
181
+ operator,
182
+ variableId,
183
+ value,
184
+ };
185
+ }
186
+ }
@@ -0,0 +1,9 @@
1
+ import { BuilderOperator } from "./Builder-operator";
2
+
3
+ describe("Builder Operator", () => {
4
+ test("Can validate symbol", () => {
5
+ let symbol: BuilderOperator = "notBetween";
6
+ expect(BuilderOperator.is("invalid")).toBe(false);
7
+ expect(BuilderOperator.is(symbol)).toBe(true);
8
+ });
9
+ });
@@ -0,0 +1,31 @@
1
+ const BuilderOperatorSymbols = {
2
+ equal: true,
3
+ notEqual: true,
4
+ lessThan: true,
5
+ lessThanOrEqual: true,
6
+ greaterThan: true,
7
+ greaterThanOrEqual: true,
8
+ between: true,
9
+ notBetween: true,
10
+ in: true,
11
+ notIn: true,
12
+ missing: true,
13
+ notMissing: true,
14
+ contains: true,
15
+ notContains: true,
16
+ empty: true,
17
+ notEmpty: true,
18
+ startsWith: true,
19
+ endsWith: true
20
+ } as const;
21
+
22
+ export type BuilderOperator = keyof typeof BuilderOperatorSymbols;
23
+
24
+ export namespace BuilderOperator {
25
+ export const is = (symbol: string): symbol is BuilderOperator => {
26
+ if (typeof symbol !== 'string') {
27
+ return false;
28
+ }
29
+ return Object.keys(BuilderOperatorSymbols).includes(symbol);
30
+ };
31
+ }
@@ -0,0 +1,22 @@
1
+ export { BuilderCondition, type BuilderConditionDto } from "./condition/Builder-condition";
2
+ export {
3
+ BuilderConditionGroup,
4
+ type BuilderConditionGroupDto,
5
+ type ConditionGroupType,
6
+ } from "./condition/Builder-condition-group";
7
+ export { BuilderOperator } from "./condition/Builder-operator";
8
+ export { BuilderRule, type BuilderRuleDto } from "./Builder-rule";
9
+ export { JumpToActionManager } from "./jump-to-action-manager";
10
+ export { MultiSelectItem, ExcludeByPageIdSelectItem, ExcludeByTagSelectItem } from "./multi-select-item";
11
+ export { PageActionManager } from "./page-action-manager";
12
+ export { type ExcludeByPageAction, type ExcludeByTagAction, type JumpToPageAction } from "./RuleAction";
13
+ export { RuleInput } from "./RuleInput";
14
+ export { CustomVariable, BuilderVariableOption, type BuilderVariable, QuestionVariable } from "./RuleVariable";
15
+ export {
16
+ SingleSelectItem,
17
+ OperatorSelectItem,
18
+ RuleOptionSelectItem,
19
+ RuleVariableSelectItem,
20
+ JumpToPageSelectItem,
21
+ } from "./SingleSelectItem";
22
+ export { TagActionManager } from "./tag-action-manager";