@media-quest/builder 0.0.24 → 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.
- package/package.json +15 -15
- package/src/Builder-option.ts +6 -8
- package/src/Builder-page.spec.ts +162 -320
- package/src/Builder-page.ts +182 -257
- package/src/Builder-question.spec.ts +57 -57
- package/src/Builder-question.ts +83 -82
- package/src/Builder-schema.spec.ts +96 -124
- package/src/Builder-schema.ts +25 -15
- package/src/Builder-text.spec.ts +11 -11
- package/src/Builder-text.ts +13 -13
- package/src/BuilderObject.ts +2 -33
- package/src/BuilderTag.ts +19 -20
- package/src/builder-compiler.ts +1 -1
- package/src/code-book/codebook-variable.ts +29 -0
- package/src/{codebook.ts → code-book/codebook.ts} +16 -16
- package/src/primitives/ID.spec.ts +39 -0
- package/src/primitives/ID.ts +138 -0
- package/src/primitives/page-prefix.ts +4 -3
- package/src/primitives/varID.ts +1 -0
- package/src/public-api.ts +28 -24
- package/src/rulebuilder/Builder-rule.spec.ts +3 -2
- package/src/rulebuilder/Builder-rule.ts +2 -1
- package/src/rulebuilder/RuleBuilder-test-utils.ts +12 -8
- package/src/rulebuilder/RuleInput.ts +30 -30
- package/src/rulebuilder/RuleVariable.ts +11 -26
- package/src/rulebuilder/SingleSelectItem.ts +9 -8
- package/src/rulebuilder/condition/Builder-condition-group.ts +14 -6
- package/src/rulebuilder/condition/Builder-condition.spec.ts +12 -12
- package/src/rulebuilder/condition/Builder-condition.ts +17 -13
- package/src/rulebuilder/index.ts +16 -3
- package/src/rulebuilder/page-action-manager.ts +4 -2
- package/src/rulebuilder/rule2/Rule2.ts +8 -8
- package/src/schema-config.ts +2 -2
- package/src/sum-score/sum-score-answer.ts +6 -0
- package/src/sum-score/sum-score-manager.spec.ts +189 -0
- package/src/sum-score/sum-score-manager.ts +154 -0
- package/src/sum-score/sum-score-membership.ts +45 -0
- package/src/sum-score/sum-score-variable.spec.ts +151 -0
- package/src/sum-score/sum-score-variable.ts +36 -0
- package/src/{variable → sum-score}/sum-score.ts +122 -138
- package/tsconfig.tsbuildinfo +1 -1
- package/src/variable/mq-variable.spec.ts +0 -146
- package/src/variable/mq-variable.ts +0 -68
package/src/public-api.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
export { type BuilderOptionDto, BuilderOption } from "./Builder-option";
|
|
2
|
-
export { type BuilderPageDto, type BuilderPageType, BuilderPage } from "./Builder-page";
|
|
3
|
-
export {
|
|
4
|
-
type BuilderQuestionDto,
|
|
5
|
-
BuilderQuestion,
|
|
6
|
-
type BuilderQuestionType,
|
|
7
|
-
} from "./Builder-question";
|
|
8
|
-
export { BuilderSchema, type BuilderSchemaDto } from "./Builder-schema";
|
|
9
|
-
export { BuilderText, type BuilderTextDto } from "./Builder-text";
|
|
10
|
-
export { type BuilderMainImageDto } from "./BuilderMainImageDto";
|
|
11
|
-
export { BuilderMainText, type BuilderMainTextDto } from "./BuilderMainText";
|
|
12
|
-
export { type BuilderMainVideoDto } from "./BuilderMainVideoDto";
|
|
13
|
-
export { type BuilderTagDto, BuilderTag, TagCollection } from "./BuilderTag";
|
|
14
|
-
export { type AudioFile, type ImageFile, type VideoFile } from "./media-files";
|
|
15
|
-
// Public Api of rule-builder
|
|
16
|
-
export * from "./rulebuilder";
|
|
17
|
-
export { PagePrefix, PagePrefixValue } from "./primitives/page-prefix";
|
|
18
|
-
export { SchemaPrefix, SchemaPrefixValue } from "./primitives/schema-prefix";
|
|
19
|
-
export * from "./schema-config";
|
|
20
|
-
export * from "./codebook";
|
|
21
|
-
export { VarID } from "./primitives/varID";
|
|
22
|
-
export * from "./
|
|
23
|
-
export * from "./
|
|
24
|
-
export * from "./
|
|
1
|
+
export { type BuilderOptionDto, BuilderOption } from "./Builder-option";
|
|
2
|
+
export { type BuilderPageDto, type BuilderPageType, BuilderPage } from "./Builder-page";
|
|
3
|
+
export {
|
|
4
|
+
type BuilderQuestionDto,
|
|
5
|
+
BuilderQuestion,
|
|
6
|
+
type BuilderQuestionType,
|
|
7
|
+
} from "./Builder-question";
|
|
8
|
+
export { BuilderSchema, type BuilderSchemaDto } from "./Builder-schema";
|
|
9
|
+
export { BuilderText, type BuilderTextDto } from "./Builder-text";
|
|
10
|
+
export { type BuilderMainImageDto } from "./BuilderMainImageDto";
|
|
11
|
+
export { BuilderMainText, type BuilderMainTextDto } from "./BuilderMainText";
|
|
12
|
+
export { type BuilderMainVideoDto } from "./BuilderMainVideoDto";
|
|
13
|
+
export { type BuilderTagDto, BuilderTag, TagCollection } from "./BuilderTag";
|
|
14
|
+
export { type AudioFile, type ImageFile, type VideoFile } from "./media-files";
|
|
15
|
+
// Public Api of rule-builder
|
|
16
|
+
export * from "./rulebuilder";
|
|
17
|
+
export { PagePrefix, PagePrefixValue } from "./primitives/page-prefix";
|
|
18
|
+
export { SchemaPrefix, SchemaPrefixValue } from "./primitives/schema-prefix";
|
|
19
|
+
export * from "./schema-config";
|
|
20
|
+
export * from "./code-book/codebook";
|
|
21
|
+
export { VarID } from "./primitives/varID";
|
|
22
|
+
export * from "./primitives/ID";
|
|
23
|
+
export * from "./code-book/codebook-variable";
|
|
24
|
+
export * from "./builder-compiler";
|
|
25
|
+
export * from "./sum-score/sum-score";
|
|
26
|
+
export { SumScoreVariableDto } from "./sum-score/sum-score-variable";
|
|
27
|
+
export { SumScoreAnswer } from "./sum-score/sum-score-answer";
|
|
28
|
+
export { SumScoreManager } from "./sum-score/sum-score-manager";
|
|
@@ -3,10 +3,11 @@ import { RuleBuilderTestUtils as U } from "./RuleBuilder-test-utils";
|
|
|
3
3
|
import { RuleInput } from "./RuleInput";
|
|
4
4
|
import type { BuilderConditionGroupDto } from "./condition/Builder-condition-group";
|
|
5
5
|
import { BuilderConditionDto } from "./condition/Builder-condition";
|
|
6
|
-
import { Condition
|
|
6
|
+
import { Condition } from "@media-quest/engine";
|
|
7
7
|
import { PagePrefix } from "../primitives/page-prefix";
|
|
8
8
|
import { VarID } from "../primitives/varID";
|
|
9
9
|
import { SchemaPrefix } from "../primitives/schema-prefix";
|
|
10
|
+
import { PageID } from "../primitives/ID";
|
|
10
11
|
|
|
11
12
|
const { createPagesAndVars_A_H } = U;
|
|
12
13
|
|
|
@@ -155,7 +156,7 @@ describe("Builder Rule", () => {
|
|
|
155
156
|
expect(rule.conditionCount).toBe(2);
|
|
156
157
|
});
|
|
157
158
|
|
|
158
|
-
test("Conditions have no operators available before
|
|
159
|
+
test("Conditions have no operators available before sum-score is set.", () => {
|
|
159
160
|
const c1 = rule.addCondition();
|
|
160
161
|
expect(c1.operatorsSelectItems.length).toBe(0);
|
|
161
162
|
|
|
@@ -9,7 +9,8 @@ import { BuilderObject } from "../BuilderObject";
|
|
|
9
9
|
import { TagActionManager } from "./tag-action-manager";
|
|
10
10
|
import { PageActionManager } from "./page-action-manager";
|
|
11
11
|
import { JumpToActionManager } from "./jump-to-action-manager";
|
|
12
|
-
import { Condition,
|
|
12
|
+
import { Condition, RuleActionPageQue, PageQueRules } from "@media-quest/engine";
|
|
13
|
+
import { PageID } from "../primitives/ID";
|
|
13
14
|
|
|
14
15
|
export interface BuilderRuleDto {
|
|
15
16
|
readonly type: ConditionGroupType;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { BuilderOption } from "../Builder-option";
|
|
2
|
-
import { type
|
|
2
|
+
import { type RuleVariable, RuleQuestionVariable } from "./RuleVariable";
|
|
3
3
|
import type { BuilderRuleDto } from "./Builder-rule";
|
|
4
4
|
import type { BuilderConditionGroupDto } from "./condition/Builder-condition-group";
|
|
5
5
|
import type { BuilderConditionDto } from "./condition/Builder-condition";
|
|
6
6
|
import type { BuilderOperator } from "./condition/Builder-operator";
|
|
7
7
|
import type { ExcludeByPageAction, ExcludeByTagAction, JumpToPageAction } from "./RuleAction";
|
|
8
8
|
import { ExcludeByPageIdSelectItem, ExcludeByTagSelectItem } from "./multi-select-item";
|
|
9
|
-
import {
|
|
10
|
-
import { PagePrefix, PagePrefixValue } from "../primitives/page-prefix";
|
|
9
|
+
import { PagePrefix } from "../primitives/page-prefix";
|
|
11
10
|
import { VarID } from "../primitives/varID";
|
|
12
11
|
import { SchemaPrefix } from "../primitives/schema-prefix";
|
|
12
|
+
import { PageID } from "../primitives/ID";
|
|
13
13
|
|
|
14
14
|
const idPxx = () => {
|
|
15
15
|
const id = PageID.create();
|
|
@@ -72,8 +72,8 @@ export namespace RuleBuilderTestUtils {
|
|
|
72
72
|
] as const;
|
|
73
73
|
return list;
|
|
74
74
|
};
|
|
75
|
-
export const createRuleVariable = (varId: VarID, pageNumber: number):
|
|
76
|
-
new
|
|
75
|
+
export const createRuleVariable = (varId: VarID, pageNumber: number): RuleQuestionVariable =>
|
|
76
|
+
new RuleQuestionVariable(varId, "Har du " + varId + "?", createOptions(), pageNumber);
|
|
77
77
|
|
|
78
78
|
/**
|
|
79
79
|
*
|
|
@@ -117,7 +117,7 @@ export namespace RuleBuilderTestUtils {
|
|
|
117
117
|
return { list, items, pageIds, pageIdList };
|
|
118
118
|
};
|
|
119
119
|
|
|
120
|
-
export const createConditionDto = (variable:
|
|
120
|
+
export const createConditionDto = (variable: RuleVariable): BuilderConditionDto => {
|
|
121
121
|
const operator: BuilderOperator = Math.random() > 0 ? "equal" : "notEqual";
|
|
122
122
|
const opt = variable.options[0];
|
|
123
123
|
return {
|
|
@@ -129,7 +129,9 @@ export namespace RuleBuilderTestUtils {
|
|
|
129
129
|
};
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
export const createConditionGroupDto = (
|
|
132
|
+
export const createConditionGroupDto = (
|
|
133
|
+
conditions: BuilderConditionDto[],
|
|
134
|
+
): BuilderConditionGroupDto => {
|
|
133
135
|
return {
|
|
134
136
|
kind: "condition-group",
|
|
135
137
|
conditions,
|
|
@@ -138,7 +140,9 @@ export namespace RuleBuilderTestUtils {
|
|
|
138
140
|
};
|
|
139
141
|
};
|
|
140
142
|
|
|
141
|
-
export const createBuilderRuleDto = (
|
|
143
|
+
export const createBuilderRuleDto = (
|
|
144
|
+
schemaPrefix: SchemaPrefix,
|
|
145
|
+
): ReadonlyArray<BuilderRuleDto> => {
|
|
142
146
|
const v = createPagesAndVars_A_H(schemaPrefix);
|
|
143
147
|
const condition0 = createConditionDto(v.items.a);
|
|
144
148
|
const condition1 = createConditionDto(v.items.b);
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RuleQuestionVariable, RuleCustomVariable, RuleVariable } from "./RuleVariable";
|
|
2
2
|
import type { ExcludeByPageAction, ExcludeByTagAction, JumpToPageAction } from "./RuleAction";
|
|
3
3
|
import { JumpToPageSelectItem } from "./SingleSelectItem";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* TODO Crate filters for "cardinality" or "order" of a
|
|
6
|
+
* TODO Crate filters for "cardinality" or "order" of a sum-score;
|
|
7
7
|
* Return legal lists of variables.
|
|
8
8
|
*/
|
|
9
9
|
export class RuleInput {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly _questionVariables: ReadonlyArray<RuleQuestionVariable>,
|
|
12
|
+
private readonly _customVariables: ReadonlyArray<RuleCustomVariable>,
|
|
13
|
+
private readonly _pageIdActions: ReadonlyArray<ExcludeByPageAction>,
|
|
14
|
+
private readonly _tagActions: ReadonlyArray<ExcludeByTagAction>,
|
|
15
|
+
private readonly _jumpActions: ReadonlyArray<JumpToPageAction>,
|
|
16
|
+
) {}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
get questionVars(): ReadonlyArray<RuleVariable> {
|
|
19
|
+
return this._questionVariables;
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
getConditionInput(): ReadonlyArray<RuleVariable> {
|
|
23
|
+
return [...this.questionVars, ...this.customVars];
|
|
24
|
+
}
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
getJumpToPageOptions(): ReadonlyArray<JumpToPageSelectItem> {
|
|
27
|
+
return this._jumpActions.map(JumpToPageSelectItem.create);
|
|
28
|
+
}
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
get customVars(): ReadonlyArray<RuleCustomVariable> {
|
|
31
|
+
return this._customVariables;
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
get excludeByPageIdActions() {
|
|
35
|
+
return this._pageIdActions;
|
|
36
|
+
}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
get excludeByTagActions() {
|
|
39
|
+
return this._tagActions;
|
|
40
|
+
}
|
|
41
|
+
get jumpToPageActions() {
|
|
42
|
+
return this._jumpActions;
|
|
43
|
+
}
|
|
44
44
|
}
|
|
@@ -1,49 +1,34 @@
|
|
|
1
|
-
import { PagePrefix } from "../primitives/page-prefix";
|
|
2
1
|
import { VarID } from "../primitives/varID";
|
|
3
|
-
import { SchemaPrefix } from "../primitives/schema-prefix";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
numericRange: true,
|
|
9
|
-
text: true,
|
|
10
|
-
date: true,
|
|
11
|
-
dateRange: true,
|
|
12
|
-
time: true,
|
|
13
|
-
duration: true,
|
|
14
|
-
boolean: true,
|
|
15
|
-
} as const;
|
|
3
|
+
/*******************************************
|
|
4
|
+
** ONLY USE THESE TYPES IN RULE-BUILDER **
|
|
5
|
+
******************************************/
|
|
16
6
|
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
export class BuilderVariableOption {
|
|
7
|
+
export class RuleVariableOption {
|
|
20
8
|
constructor(
|
|
21
9
|
readonly label: string,
|
|
22
10
|
readonly value: number,
|
|
23
11
|
) {}
|
|
24
12
|
}
|
|
25
13
|
|
|
26
|
-
export class
|
|
14
|
+
export class RuleQuestionVariable {
|
|
27
15
|
readonly kind: "question-variable" = "question-variable";
|
|
28
|
-
readonly dataType: BuilderVariableType = "numericWithOptions";
|
|
29
16
|
constructor(
|
|
30
|
-
// private schemaPrefix: SchemaPrefix,
|
|
31
|
-
// private pagePrefix: PagePrefix,
|
|
32
17
|
readonly varId: VarID,
|
|
33
18
|
readonly label: string,
|
|
34
|
-
readonly options: ReadonlyArray<
|
|
19
|
+
readonly options: ReadonlyArray<RuleVariableOption>,
|
|
35
20
|
readonly pageNumber: number,
|
|
36
21
|
) {}
|
|
37
22
|
}
|
|
38
23
|
|
|
39
|
-
export class
|
|
24
|
+
export class RuleCustomVariable {
|
|
40
25
|
readonly kind: "configuration-variable" = "configuration-variable";
|
|
41
|
-
readonly dataType: BuilderVariableType = "numericWithOptions";
|
|
42
26
|
constructor(
|
|
43
|
-
readonly varId:
|
|
27
|
+
readonly varId: string,
|
|
44
28
|
readonly label: string,
|
|
45
|
-
readonly options: ReadonlyArray<
|
|
29
|
+
readonly options: ReadonlyArray<RuleVariableOption>,
|
|
46
30
|
) {}
|
|
47
31
|
}
|
|
48
32
|
|
|
49
|
-
export
|
|
33
|
+
// export class RuleVariable {}
|
|
34
|
+
export type RuleVariable = RuleQuestionVariable | RuleCustomVariable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuleVariable, RuleVariableOption } from "./RuleVariable";
|
|
2
2
|
import { BuilderOperator } from "./condition/Builder-operator";
|
|
3
3
|
import { JumpToPageAction } from "./RuleAction";
|
|
4
4
|
|
|
@@ -27,12 +27,12 @@ export abstract class SingleSelectItem<T> {
|
|
|
27
27
|
protected abstract getSearchString(): string;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export class RuleVariableSelectItem extends SingleSelectItem<
|
|
31
|
-
public static create = (data:
|
|
30
|
+
export class RuleVariableSelectItem extends SingleSelectItem<RuleVariable> {
|
|
31
|
+
public static create = (data: RuleVariable) => {
|
|
32
32
|
return new RuleVariableSelectItem(data);
|
|
33
33
|
};
|
|
34
34
|
readonly options: ReadonlyArray<RuleOptionSelectItem>;
|
|
35
|
-
constructor(readonly data:
|
|
35
|
+
constructor(readonly data: RuleVariable) {
|
|
36
36
|
super(data);
|
|
37
37
|
this.options = data.options.map(RuleOptionSelectItem.create);
|
|
38
38
|
}
|
|
@@ -50,11 +50,11 @@ export class RuleVariableSelectItem extends SingleSelectItem<BuilderVariable> {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export class RuleOptionSelectItem extends SingleSelectItem<
|
|
54
|
-
public static create = (option:
|
|
53
|
+
export class RuleOptionSelectItem extends SingleSelectItem<RuleVariableOption> {
|
|
54
|
+
public static create = (option: RuleVariableOption) => {
|
|
55
55
|
return new RuleOptionSelectItem(option);
|
|
56
56
|
};
|
|
57
|
-
private constructor(option:
|
|
57
|
+
private constructor(option: RuleVariableOption) {
|
|
58
58
|
super(option);
|
|
59
59
|
}
|
|
60
60
|
protected getSearchString(): string {
|
|
@@ -116,7 +116,8 @@ export class OperatorSelectItem extends SingleSelectItem<BuilderOperator | ""> {
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
export class JumpToPageSelectItem extends SingleSelectItem<JumpToPageAction> {
|
|
119
|
-
public static readonly create = (pageData: JumpToPageAction) =>
|
|
119
|
+
public static readonly create = (pageData: JumpToPageAction) =>
|
|
120
|
+
new JumpToPageSelectItem(pageData);
|
|
120
121
|
protected constructor(pageData: JumpToPageAction) {
|
|
121
122
|
super(pageData);
|
|
122
123
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BuilderCondition, type BuilderConditionDto } from "./Builder-condition";
|
|
2
2
|
import { BuilderObject } from "../../BuilderObject";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RuleVariable } from "../RuleVariable";
|
|
4
4
|
import { Condition } from "@media-quest/engine";
|
|
5
5
|
|
|
6
6
|
const ConditionGroupType = {
|
|
@@ -18,7 +18,10 @@ export interface BuilderConditionGroupDto {
|
|
|
18
18
|
readonly conditions: ReadonlyArray<BuilderConditionDto>;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export class BuilderConditionGroup extends BuilderObject<
|
|
21
|
+
export class BuilderConditionGroup extends BuilderObject<
|
|
22
|
+
"builder-condition-group",
|
|
23
|
+
BuilderConditionGroupDto
|
|
24
|
+
> {
|
|
22
25
|
static readonly isConditionGroupType = (value: string | symbol): value is ConditionGroupType => {
|
|
23
26
|
if (typeof value !== "string") {
|
|
24
27
|
return false;
|
|
@@ -31,12 +34,15 @@ export class BuilderConditionGroup extends BuilderObject<"builder-condition-grou
|
|
|
31
34
|
private _type: ConditionGroupType;
|
|
32
35
|
name = "";
|
|
33
36
|
private readonly _conditions: Array<BuilderCondition>;
|
|
34
|
-
private readonly _variableList: ReadonlyArray<
|
|
37
|
+
private readonly _variableList: ReadonlyArray<RuleVariable>;
|
|
35
38
|
|
|
36
|
-
public static readonly fromDto = (
|
|
39
|
+
public static readonly fromDto = (
|
|
40
|
+
dto: BuilderConditionGroupDto,
|
|
41
|
+
variableList: ReadonlyArray<RuleVariable>,
|
|
42
|
+
) => {
|
|
37
43
|
return new BuilderConditionGroup(dto, variableList);
|
|
38
44
|
};
|
|
39
|
-
protected constructor(dto: BuilderConditionGroupDto, variableList: ReadonlyArray<
|
|
45
|
+
protected constructor(dto: BuilderConditionGroupDto, variableList: ReadonlyArray<RuleVariable>) {
|
|
40
46
|
super(dto);
|
|
41
47
|
this.name = dto.name;
|
|
42
48
|
this._type = dto.type;
|
|
@@ -73,7 +79,9 @@ export class BuilderConditionGroup extends BuilderObject<"builder-condition-grou
|
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
toJson(): BuilderConditionGroupDto {
|
|
76
|
-
const conditions: ReadonlyArray<BuilderConditionDto> = [
|
|
82
|
+
const conditions: ReadonlyArray<BuilderConditionDto> = [
|
|
83
|
+
...this._conditions.map((c) => c.toJson()),
|
|
84
|
+
];
|
|
77
85
|
return {
|
|
78
86
|
name: this.name,
|
|
79
87
|
conditions,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BuilderCondition, type BuilderConditionDto } from "./Builder-condition";
|
|
2
2
|
import { RuleBuilderTestUtils } from "../RuleBuilder-test-utils";
|
|
3
|
-
import type
|
|
4
|
-
import { QuestionVariable } from "../RuleVariable";
|
|
3
|
+
import { type RuleVariable, RuleVariableOption, RuleQuestionVariable } from "../RuleVariable";
|
|
4
|
+
// import { QuestionVariable } from "../RuleVariable";
|
|
5
5
|
|
|
6
6
|
import { SchemaPrefix } from "../../primitives/schema-prefix";
|
|
7
7
|
|
|
@@ -77,9 +77,9 @@ describe("Builder Operator", () => {
|
|
|
77
77
|
value: 0,
|
|
78
78
|
};
|
|
79
79
|
const c = BuilderCondition.fromDto(dto, vs.list);
|
|
80
|
-
expect(c.variable).toBeInstanceOf(
|
|
80
|
+
expect(c.variable).toBeInstanceOf(RuleQuestionVariable);
|
|
81
81
|
expect(c.operator === "equal").toBe(true);
|
|
82
|
-
const value = c.value as
|
|
82
|
+
const value = c.value as RuleVariableOption;
|
|
83
83
|
expect(value.value).toBe(0);
|
|
84
84
|
expect(value.label).toBe("Nei");
|
|
85
85
|
expect(c.variable).toBe(a);
|
|
@@ -96,9 +96,9 @@ describe("Builder Operator", () => {
|
|
|
96
96
|
value: 0,
|
|
97
97
|
};
|
|
98
98
|
const c = BuilderCondition.fromDto(dto, vs.list);
|
|
99
|
-
expect(c.variable).toBeInstanceOf(
|
|
99
|
+
expect(c.variable).toBeInstanceOf(RuleQuestionVariable);
|
|
100
100
|
expect(c.operator === "equal").toBe(true);
|
|
101
|
-
const value = c.value as
|
|
101
|
+
const value = c.value as RuleVariableOption;
|
|
102
102
|
expect(value.value).toBe(0);
|
|
103
103
|
expect(value.label).toBe("Nei");
|
|
104
104
|
expect(c.validate().isValid).toBe(true);
|
|
@@ -114,7 +114,7 @@ describe("Builder Operator", () => {
|
|
|
114
114
|
const c = BuilderCondition.fromDto(dto, []);
|
|
115
115
|
expect(c.validate().isValid).toBe(false);
|
|
116
116
|
});
|
|
117
|
-
test("Condition is invalid, when
|
|
117
|
+
test("Condition is invalid, when sum-score dont exist in universe.", () => {
|
|
118
118
|
const variables = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
|
|
119
119
|
const dto: BuilderConditionDto = {
|
|
120
120
|
kind: "condition",
|
|
@@ -127,7 +127,7 @@ describe("Builder Operator", () => {
|
|
|
127
127
|
expect(c.variable).toBe(false);
|
|
128
128
|
expect(c.validate().isValid).toBe(false);
|
|
129
129
|
});
|
|
130
|
-
test("Condition is invalid if not all set, when
|
|
130
|
+
test("Condition is invalid if not all set, when sum-score dont exist in variables.", () => {
|
|
131
131
|
const variables = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
|
|
132
132
|
const dto: BuilderConditionDto = {
|
|
133
133
|
kind: "condition",
|
|
@@ -153,11 +153,11 @@ describe("Builder Operator", () => {
|
|
|
153
153
|
};
|
|
154
154
|
expect(a.varId).toBe("as_a");
|
|
155
155
|
const c = BuilderCondition.fromDto(dto, variables.list);
|
|
156
|
-
expect(c.variable).toBeInstanceOf(
|
|
156
|
+
expect(c.variable).toBeInstanceOf(RuleQuestionVariable);
|
|
157
157
|
expect(c.validate().isValid).toBe(false);
|
|
158
158
|
expect(c.value).toBe(false);
|
|
159
159
|
});
|
|
160
|
-
test("Condition is invalid if value (from dto) is not found in
|
|
160
|
+
test("Condition is invalid if value (from dto) is not found in sum-score", () => {
|
|
161
161
|
const { list, items } = RuleBuilderTestUtils.createPagesAndVars_A_H(as);
|
|
162
162
|
expect(items.a.varId).toBe("as_a");
|
|
163
163
|
const dto: BuilderConditionDto = {
|
|
@@ -169,7 +169,7 @@ describe("Builder Operator", () => {
|
|
|
169
169
|
};
|
|
170
170
|
const c = BuilderCondition.fromDto(dto, list);
|
|
171
171
|
expect(c).toBeInstanceOf(BuilderCondition);
|
|
172
|
-
expect(c.variable).toBeInstanceOf(
|
|
172
|
+
expect(c.variable).toBeInstanceOf(RuleQuestionVariable);
|
|
173
173
|
expect(c.operator).toBe("equal");
|
|
174
174
|
expect(c.operatorsSelectItems.length).toBe(BuilderCondition.NUMBER_OPERATORS.length);
|
|
175
175
|
expect(c.value).toBe(false);
|
|
@@ -186,7 +186,7 @@ describe("Builder Operator", () => {
|
|
|
186
186
|
value: 7,
|
|
187
187
|
};
|
|
188
188
|
const c = BuilderCondition.fromDto(dto, variables.list);
|
|
189
|
-
expect(c.variable).toBeInstanceOf(
|
|
189
|
+
expect(c.variable).toBeInstanceOf(RuleQuestionVariable);
|
|
190
190
|
expect(c.operator).toBe("equal");
|
|
191
191
|
expect(c.operatorsSelectItems.length).toBe(BuilderCondition.NUMBER_OPERATORS.length);
|
|
192
192
|
expect(c.value).toBe(false);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { BuilderObject } from "../../BuilderObject";
|
|
2
2
|
import { BuilderOperator } from "./Builder-operator";
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
3
|
+
import type { RuleVariable, RuleVariableOption } from "../RuleVariable";
|
|
4
|
+
import {
|
|
5
|
+
OperatorSelectItem,
|
|
6
|
+
RuleOptionSelectItem,
|
|
7
|
+
RuleVariableSelectItem,
|
|
8
|
+
} from "../SingleSelectItem";
|
|
5
9
|
import { Condition } from "@media-quest/engine";
|
|
6
10
|
export interface BuilderConditionDto {
|
|
7
11
|
readonly kind: "condition";
|
|
@@ -21,7 +25,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
21
25
|
private initialDto: BuilderConditionDto;
|
|
22
26
|
name = "";
|
|
23
27
|
|
|
24
|
-
public static create = (variableList: ReadonlyArray<
|
|
28
|
+
public static create = (variableList: ReadonlyArray<RuleVariable>) => {
|
|
25
29
|
const condition = new BuilderCondition(
|
|
26
30
|
{
|
|
27
31
|
kind: "condition",
|
|
@@ -35,7 +39,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
35
39
|
return condition;
|
|
36
40
|
};
|
|
37
41
|
|
|
38
|
-
public static fromDto = (dto: BuilderConditionDto, variables: ReadonlyArray<
|
|
42
|
+
public static fromDto = (dto: BuilderConditionDto, variables: ReadonlyArray<RuleVariable>) => {
|
|
39
43
|
const _dto: BuilderConditionDto = {
|
|
40
44
|
kind: "condition",
|
|
41
45
|
name: dto.name ?? "",
|
|
@@ -46,16 +50,16 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
46
50
|
const instance = new BuilderCondition(_dto, variables);
|
|
47
51
|
return instance;
|
|
48
52
|
};
|
|
49
|
-
private _variable:
|
|
53
|
+
private _variable: RuleVariable | false = false;
|
|
50
54
|
private _operator: BuilderOperator | "" = "";
|
|
51
|
-
private _value:
|
|
52
|
-
private _variableList: ReadonlyArray<
|
|
55
|
+
private _value: RuleVariableOption | false = false;
|
|
56
|
+
private _variableList: ReadonlyArray<RuleVariable> = [];
|
|
53
57
|
|
|
54
58
|
/**
|
|
55
59
|
* Can only set variables that exist in variableList.
|
|
56
60
|
* @param variable
|
|
57
61
|
*/
|
|
58
|
-
set variable(variable:
|
|
62
|
+
set variable(variable: RuleVariable | false) {
|
|
59
63
|
if (variable === this._variable) {
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
@@ -68,7 +72,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
68
72
|
return this._variable;
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
set value(variableValue:
|
|
75
|
+
set value(variableValue: RuleVariableOption | false) {
|
|
72
76
|
this._value = variableValue;
|
|
73
77
|
}
|
|
74
78
|
get value() {
|
|
@@ -96,7 +100,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
96
100
|
if (!this._value) {
|
|
97
101
|
return {
|
|
98
102
|
isValid: false,
|
|
99
|
-
message: "Value (
|
|
103
|
+
message: "Value (RuleVariableOption) is not initialized",
|
|
100
104
|
};
|
|
101
105
|
}
|
|
102
106
|
|
|
@@ -124,7 +128,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
124
128
|
return false;
|
|
125
129
|
}
|
|
126
130
|
|
|
127
|
-
private findVariableInUniverse(variableId: string):
|
|
131
|
+
private findVariableInUniverse(variableId: string): RuleVariable | false {
|
|
128
132
|
const v = this._variableList.find((v) => v.varId === variableId);
|
|
129
133
|
return v ?? false;
|
|
130
134
|
}
|
|
@@ -141,7 +145,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
141
145
|
return this._operator;
|
|
142
146
|
}
|
|
143
147
|
|
|
144
|
-
private constructor(dto: BuilderConditionDto, variables: ReadonlyArray<
|
|
148
|
+
private constructor(dto: BuilderConditionDto, variables: ReadonlyArray<RuleVariable>) {
|
|
145
149
|
super(dto);
|
|
146
150
|
this.initialDto = dto;
|
|
147
151
|
this.name = dto.name;
|
|
@@ -168,7 +172,7 @@ export class BuilderCondition extends BuilderObject<"builder-condition", Builder
|
|
|
168
172
|
return this.toJson();
|
|
169
173
|
}
|
|
170
174
|
|
|
171
|
-
private _setVariableList(variables: ReadonlyArray<
|
|
175
|
+
private _setVariableList(variables: ReadonlyArray<RuleVariable>): boolean {
|
|
172
176
|
this._variableList = variables;
|
|
173
177
|
const v = this._variableList.find((v) => v.varId === this.originalDto.variableId);
|
|
174
178
|
if (!v) {
|
package/src/rulebuilder/index.ts
CHANGED
|
@@ -7,11 +7,24 @@ export {
|
|
|
7
7
|
export { BuilderOperator } from "./condition/Builder-operator";
|
|
8
8
|
export { BuilderRule, type BuilderRuleDto } from "./Builder-rule";
|
|
9
9
|
export { JumpToActionManager } from "./jump-to-action-manager";
|
|
10
|
-
export {
|
|
10
|
+
export {
|
|
11
|
+
MultiSelectItem,
|
|
12
|
+
ExcludeByPageIdSelectItem,
|
|
13
|
+
ExcludeByTagSelectItem,
|
|
14
|
+
} from "./multi-select-item";
|
|
11
15
|
export { PageActionManager } from "./page-action-manager";
|
|
12
|
-
export {
|
|
16
|
+
export {
|
|
17
|
+
type ExcludeByPageAction,
|
|
18
|
+
type ExcludeByTagAction,
|
|
19
|
+
type JumpToPageAction,
|
|
20
|
+
} from "./RuleAction";
|
|
13
21
|
export { RuleInput } from "./RuleInput";
|
|
14
|
-
export {
|
|
22
|
+
export {
|
|
23
|
+
RuleCustomVariable,
|
|
24
|
+
RuleVariableOption,
|
|
25
|
+
type RuleVariable,
|
|
26
|
+
RuleQuestionVariable,
|
|
27
|
+
} from "./RuleVariable";
|
|
15
28
|
export {
|
|
16
29
|
SingleSelectItem,
|
|
17
30
|
OperatorSelectItem,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { RuleInput } from "./RuleInput";
|
|
2
2
|
import { ExcludeByPageIdSelectItem } from "./multi-select-item";
|
|
3
3
|
import { ExcludeByPageAction } from "./RuleAction";
|
|
4
|
-
import { PageID } from "
|
|
4
|
+
import { PageID } from "../primitives/ID";
|
|
5
5
|
|
|
6
6
|
export class PageActionManager {
|
|
7
7
|
private readonly _initialSelection: Set<string>;
|
|
@@ -19,7 +19,9 @@ export class PageActionManager {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
getCurrentSelection(): ReadonlyArray<PageID> {
|
|
22
|
-
const selected = this.selectItems
|
|
22
|
+
const selected = this.selectItems
|
|
23
|
+
.filter((item) => item.isSelected)
|
|
24
|
+
.map((itm) => itm.data.pageId);
|
|
23
25
|
return selected;
|
|
24
26
|
}
|
|
25
27
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BuilderOperator } from "../condition/Builder-operator";
|
|
2
2
|
import { BuilderConditionDto } from "../condition/Builder-condition";
|
|
3
|
-
import { BuilderConditionGroupDto
|
|
3
|
+
import { BuilderConditionGroupDto } from "../condition/Builder-condition-group";
|
|
4
4
|
import { BuilderRuleDto } from "../Builder-rule";
|
|
5
5
|
|
|
6
6
|
type SolveErrorReason =
|
|
@@ -13,12 +13,16 @@ type SolveErrorReason =
|
|
|
13
13
|
|
|
14
14
|
type TrueResult = { readonly type: "IS_TRUE" };
|
|
15
15
|
type FalseResult = { readonly type: "IS_FALSE" };
|
|
16
|
-
type MissingFactsResult = {
|
|
16
|
+
type MissingFactsResult = {
|
|
17
|
+
readonly type: "MISSING_FACTS";
|
|
18
|
+
readonly missingVariables: ReadonlyArray<string>;
|
|
19
|
+
};
|
|
17
20
|
type ErrorResult = {
|
|
18
21
|
readonly type: "HAS_ERROR";
|
|
19
22
|
readonly reason: SolveErrorReason;
|
|
20
23
|
readonly data: Record<string, string>;
|
|
21
24
|
};
|
|
25
|
+
|
|
22
26
|
export type EvalResult = FalseResult | TrueResult | MissingFactsResult | ErrorResult;
|
|
23
27
|
|
|
24
28
|
export interface Fact2 {
|
|
@@ -47,7 +51,7 @@ export class FactCollection {
|
|
|
47
51
|
if (typeof fact.valueLabel !== "string") {
|
|
48
52
|
return false;
|
|
49
53
|
}
|
|
50
|
-
// NB: This is a temporary check until we have more
|
|
54
|
+
// NB: This is a temporary check until we have more sum-score types.
|
|
51
55
|
if (typeof fact.variableType !== "string" || fact.variableType !== "numeric") {
|
|
52
56
|
return false;
|
|
53
57
|
}
|
|
@@ -164,11 +168,7 @@ export class ConditionGroup implements FactEvaluator, IsValid {
|
|
|
164
168
|
}
|
|
165
169
|
|
|
166
170
|
const minLimit = this.dto.count;
|
|
167
|
-
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return false;
|
|
171
|
+
return type === "count" && typeof minLimit === "number" && trueCount >= minLimit;
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
isValid(): boolean {
|