@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,186 +0,0 @@
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
- }