case-editor-tools 1.0.0-beta.16 → 1.0.0-beta.17

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 (113) hide show
  1. package/constants/key-definitions.d.ts +14 -0
  2. package/constants/key-definitions.js +34 -0
  3. package/constants/key-definitions.js.map +1 -0
  4. package/exporter/index.d.ts +2 -0
  5. package/exporter/index.js +99 -0
  6. package/exporter/index.js.map +1 -0
  7. package/expression-utils/expressionGen.d.ts +2 -0
  8. package/{src/expression-utils/expressionGen.ts → expression-utils/expressionGen.js} +29 -26
  9. package/expression-utils/expressionGen.js.map +1 -0
  10. package/expression-utils/studyEngineExpressions.d.ts +114 -0
  11. package/expression-utils/studyEngineExpressions.js +283 -0
  12. package/expression-utils/studyEngineExpressions.js.map +1 -0
  13. package/{CHANGELOG.md → index.d.ts} +0 -0
  14. package/index.js +3 -0
  15. package/index.js.map +1 -0
  16. package/item-editor-7f825952.js +522 -0
  17. package/item-editor-7f825952.js.map +1 -0
  18. package/{src/logger/index.ts → logger/index.d.ts} +1 -1
  19. package/logger/index.js +10 -0
  20. package/logger/index.js.map +1 -0
  21. package/logger/logger.d.ts +9 -0
  22. package/logger/logger.js +31 -0
  23. package/logger/logger.js.map +1 -0
  24. package/package.json +1 -1
  25. package/{src/surveys/index.ts → surveys/index.d.ts} +3 -3
  26. package/surveys/index.js +26 -0
  27. package/surveys/index.js.map +1 -0
  28. package/surveys/survey-editor/component-editor.d.ts +84 -0
  29. package/surveys/survey-editor/component-editor.js +112 -0
  30. package/surveys/survey-editor/component-editor.js.map +1 -0
  31. package/{src/surveys/survey-editor/data-types.ts → surveys/survey-editor/data-types.d.ts} +13 -18
  32. package/surveys/survey-editor/data-types.js +3 -0
  33. package/surveys/survey-editor/data-types.js.map +1 -0
  34. package/surveys/survey-editor/item-editor.d.ts +65 -0
  35. package/surveys/survey-editor/item-editor.js +13 -0
  36. package/surveys/survey-editor/item-editor.js.map +1 -0
  37. package/surveys/survey-editor/survey-editor.d.ts +43 -0
  38. package/surveys/survey-editor/survey-editor.js +231 -0
  39. package/surveys/survey-editor/survey-editor.js.map +1 -0
  40. package/surveys/survey-engine-expressions.d.ts +120 -0
  41. package/surveys/survey-engine-expressions.js +407 -0
  42. package/surveys/survey-engine-expressions.js.map +1 -0
  43. package/surveys/survey-items.d.ts +133 -0
  44. package/surveys/survey-items.js +1051 -0
  45. package/surveys/survey-items.js.map +1 -0
  46. package/surveys/types/group.d.ts +23 -0
  47. package/surveys/types/group.js +71 -0
  48. package/surveys/types/group.js.map +1 -0
  49. package/{src/surveys/types/index.ts → surveys/types/index.d.ts} +4 -4
  50. package/surveys/types/index.js +20 -0
  51. package/surveys/types/index.js.map +1 -0
  52. package/surveys/types/item-properties.d.ts +189 -0
  53. package/surveys/types/item-properties.js +3 -0
  54. package/surveys/types/item-properties.js.map +1 -0
  55. package/{src/surveys/types/item.ts → surveys/types/item.d.ts} +22 -42
  56. package/surveys/types/item.js +34 -0
  57. package/surveys/types/item.js.map +1 -0
  58. package/surveys/types/survey-definition.d.ts +19 -0
  59. package/surveys/types/survey-definition.js +60 -0
  60. package/surveys/types/survey-definition.js.map +1 -0
  61. package/surveys/utils/componentGenerators.d.ts +24 -0
  62. package/surveys/utils/componentGenerators.js +58 -0
  63. package/surveys/utils/componentGenerators.js.map +1 -0
  64. package/surveys/utils/optionDefGenerators.d.ts +69 -0
  65. package/surveys/utils/optionDefGenerators.js +169 -0
  66. package/surveys/utils/optionDefGenerators.js.map +1 -0
  67. package/surveys/utils/randomKeyGenerator.d.ts +1 -0
  68. package/{src/surveys/utils/randomKeyGenerator.ts → surveys/utils/randomKeyGenerator.js} +14 -9
  69. package/surveys/utils/randomKeyGenerator.js.map +1 -0
  70. package/surveys/utils/simple-generators.d.ts +13 -0
  71. package/surveys/utils/simple-generators.js +102 -0
  72. package/surveys/utils/simple-generators.js.map +1 -0
  73. package/surveys/utils/simple-question-editor.d.ts +14 -0
  74. package/surveys/utils/simple-question-editor.js +45 -0
  75. package/surveys/utils/simple-question-editor.js.map +1 -0
  76. package/types/duration.d.ts +9 -0
  77. package/{src/types/duration.ts → types/duration.js} +27 -30
  78. package/types/duration.js.map +1 -0
  79. package/types/expression.d.ts +4 -0
  80. package/types/expression.js +23 -0
  81. package/types/expression.js.map +1 -0
  82. package/types/study.d.ts +13 -0
  83. package/types/study.js +3 -0
  84. package/types/study.js.map +1 -0
  85. package/types/studyRules.d.ts +8 -0
  86. package/types/studyRules.js +32 -0
  87. package/types/studyRules.js.map +1 -0
  88. package/.editorconfig +0 -13
  89. package/LICENSE +0 -202
  90. package/publish.sh +0 -9
  91. package/readme.md +0 -18
  92. package/rollup.config.js +0 -49
  93. package/src/constants/key-definitions.ts +0 -14
  94. package/src/exporter/index.ts +0 -101
  95. package/src/expression-utils/studyEngineExpressions.ts +0 -359
  96. package/src/index.ts +0 -1
  97. package/src/logger/logger.ts +0 -31
  98. package/src/surveys/survey-editor/component-editor.ts +0 -133
  99. package/src/surveys/survey-editor/item-editor.ts +0 -529
  100. package/src/surveys/survey-editor/survey-editor.ts +0 -261
  101. package/src/surveys/survey-engine-expressions.ts +0 -483
  102. package/src/surveys/survey-items.ts +0 -1490
  103. package/src/surveys/types/group.ts +0 -73
  104. package/src/surveys/types/item-properties.ts +0 -204
  105. package/src/surveys/types/survey-definition.ts +0 -83
  106. package/src/surveys/utils/componentGenerators.ts +0 -76
  107. package/src/surveys/utils/optionDefGenerators.ts +0 -195
  108. package/src/surveys/utils/simple-generators.ts +0 -106
  109. package/src/surveys/utils/simple-question-editor.ts +0 -52
  110. package/src/types/expression.ts +0 -22
  111. package/src/types/study.ts +0 -17
  112. package/src/types/studyRules.ts +0 -39
  113. package/tsconfig.json +0 -100
@@ -0,0 +1,14 @@
1
+ export declare const responseGroupKey = "rg";
2
+ export declare const singleChoiceKey = "scg";
3
+ export declare const likertScaleGroupKey = "lg";
4
+ export declare const responsiveSingleChoiceArrayKey = "rsca";
5
+ export declare const responsiveBipolarLikertArrayKey = "rsbla";
6
+ export declare const likertScaleKey = "likert";
7
+ export declare const multipleChoiceKey = "mcg";
8
+ export declare const dropDownKey = "ddg";
9
+ export declare const sliderCategoricalKey = "scc";
10
+ export declare const inputKey = "ic";
11
+ export declare const numericInputKey = "num";
12
+ export declare const datePickerKey = "date";
13
+ export declare const matrixKey = "mat";
14
+ export declare const clozeKey = "cloze";
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const responseGroupKey = 'rg';
6
+ const singleChoiceKey = 'scg';
7
+ const likertScaleGroupKey = 'lg';
8
+ const responsiveSingleChoiceArrayKey = 'rsca';
9
+ const responsiveBipolarLikertArrayKey = 'rsbla';
10
+ const likertScaleKey = 'likert';
11
+ const multipleChoiceKey = 'mcg';
12
+ const dropDownKey = 'ddg';
13
+ const sliderCategoricalKey = "scc";
14
+ const inputKey = "ic";
15
+ const numericInputKey = "num";
16
+ const datePickerKey = "date";
17
+ const matrixKey = "mat";
18
+ const clozeKey = "cloze";
19
+
20
+ exports.clozeKey = clozeKey;
21
+ exports.datePickerKey = datePickerKey;
22
+ exports.dropDownKey = dropDownKey;
23
+ exports.inputKey = inputKey;
24
+ exports.likertScaleGroupKey = likertScaleGroupKey;
25
+ exports.likertScaleKey = likertScaleKey;
26
+ exports.matrixKey = matrixKey;
27
+ exports.multipleChoiceKey = multipleChoiceKey;
28
+ exports.numericInputKey = numericInputKey;
29
+ exports.responseGroupKey = responseGroupKey;
30
+ exports.responsiveBipolarLikertArrayKey = responsiveBipolarLikertArrayKey;
31
+ exports.responsiveSingleChoiceArrayKey = responsiveSingleChoiceArrayKey;
32
+ exports.singleChoiceKey = singleChoiceKey;
33
+ exports.sliderCategoricalKey = sliderCategoricalKey;
34
+ //# sourceMappingURL=key-definitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-definitions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ import { Study } from "../types/study";
2
+ export declare const generateFilesForStudy: (study: Study, pretty?: boolean | undefined) => void;
@@ -0,0 +1,99 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fs = require('fs');
6
+ var logger_logger = require('../logger/logger.js');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
11
+
12
+ const generateFilesForStudy = (study, pretty) => {
13
+ const outputName = study.outputFolderName ? study.outputFolderName : study.studyKey;
14
+ const outputRoot = `./output/${outputName}`;
15
+ logger_logger.Logger.log(`Start generating files for study ${outputName}.`);
16
+ if (!fs__default["default"].existsSync(outputRoot)) {
17
+ fs__default["default"].mkdirSync(outputRoot, { recursive: true });
18
+ }
19
+ // Surveys:
20
+ generateSurveyFiles(study, outputRoot, pretty);
21
+ // Study rules:
22
+ generateStudyRuleFile(study, outputRoot, pretty);
23
+ // Custom Study rules: (manually triggered rules)
24
+ generateCustomStudyRules(study, outputRoot, pretty);
25
+ };
26
+ const generateSurveyFiles = (study, outputPath, pretty) => {
27
+ if (study.surveys.length > 0) {
28
+ logger_logger.Logger.log(`\tSurveys:`);
29
+ }
30
+ else {
31
+ logger_logger.Logger.log(`\tNo surveys in the study.`);
32
+ }
33
+ const surveyOutPath = `${outputPath}/surveys`;
34
+ if (!fs__default["default"].existsSync(surveyOutPath)) {
35
+ fs__default["default"].mkdirSync(surveyOutPath, { recursive: true });
36
+ }
37
+ study.surveys.forEach(survey => {
38
+ const fileName = `${surveyOutPath}/${survey.key}.json`;
39
+ const outputObject = {
40
+ studyKey: study.studyKey,
41
+ survey: survey.getSurvey()
42
+ };
43
+ try {
44
+ fs__default["default"].writeFileSync(fileName, JSON.stringify(outputObject, undefined, pretty ? 2 : undefined));
45
+ }
46
+ catch (err) {
47
+ logger_logger.Logger.error(err);
48
+ return;
49
+ }
50
+ logger_logger.Logger.success(`\t\t${survey.key} saved`);
51
+ });
52
+ };
53
+ const generateStudyRuleFile = (study, outputPath, pretty) => {
54
+ if (!study.studyRules) {
55
+ logger_logger.Logger.log(`\tNo study rules in the study.`);
56
+ return;
57
+ }
58
+ else {
59
+ logger_logger.Logger.log(`\tStudy rule:`);
60
+ }
61
+ const fileName = `${outputPath}/studyRules.json`;
62
+ const outputObject = study.studyRules.get();
63
+ try {
64
+ fs__default["default"].writeFileSync(fileName, JSON.stringify(outputObject, undefined, pretty ? 2 : undefined));
65
+ }
66
+ catch (err) {
67
+ logger_logger.Logger.error(err);
68
+ return;
69
+ }
70
+ logger_logger.Logger.success(`\t\tStudy rules saved`);
71
+ };
72
+ const generateCustomStudyRules = (study, outputPath, pretty) => {
73
+ if (!study.customStudyRules || study.customStudyRules.length < 0) {
74
+ logger_logger.Logger.log(`\tNo custom study rules in the study.`);
75
+ return;
76
+ }
77
+ else {
78
+ logger_logger.Logger.log(`\tCustom study rules:`);
79
+ }
80
+ const customRulePath = `${outputPath}/customRules`;
81
+ if (!fs__default["default"].existsSync(customRulePath)) {
82
+ fs__default["default"].mkdirSync(customRulePath, { recursive: true });
83
+ }
84
+ study.customStudyRules.forEach(studyRule => {
85
+ const fileName = `${customRulePath}/${studyRule.name}.json`;
86
+ const outputObject = studyRule.rules;
87
+ try {
88
+ fs__default["default"].writeFileSync(fileName, JSON.stringify(outputObject, undefined, pretty ? 2 : undefined));
89
+ }
90
+ catch (err) {
91
+ logger_logger.Logger.error(err);
92
+ return;
93
+ }
94
+ logger_logger.Logger.success(`\t\tRule ${studyRule.name} saved`);
95
+ });
96
+ };
97
+
98
+ exports.generateFilesForStudy = generateFilesForStudy;
99
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ import { Expression, ExpressionName } from "survey-engine/lib/data_types";
2
+ export declare const generateExpression: (name: ExpressionName, returnType?: "string" | "float" | undefined, ...args: any[]) => Expression;
@@ -1,28 +1,31 @@
1
- import { Expression, ExpressionName } from "survey-engine/lib/data_types"
1
+ 'use strict';
2
2
 
3
+ Object.defineProperty(exports, '__esModule', { value: true });
3
4
 
4
- export const generateExpression = (name: ExpressionName,
5
- returnType?: 'string' | 'float',
6
- ...args: any[]): Expression => {
7
- return {
8
- name: name,
9
- returnType: returnType,
10
- data: args.filter(a => a !== undefined).map(arg => {
11
- if (typeof (arg) === 'string') {
12
- return {
13
- dtype: 'str',
14
- str: arg
15
- }
16
- } else if (typeof (arg) === 'number') {
17
- return {
18
- dtype: 'num',
19
- num: arg
20
- }
21
- }
22
- return {
23
- dtype: 'exp',
24
- exp: arg as Expression
25
- }
26
- })
27
- }
28
- }
5
+ const generateExpression = (name, returnType, ...args) => {
6
+ return {
7
+ name: name,
8
+ returnType: returnType,
9
+ data: args.filter(a => a !== undefined).map(arg => {
10
+ if (typeof (arg) === 'string') {
11
+ return {
12
+ dtype: 'str',
13
+ str: arg
14
+ };
15
+ }
16
+ else if (typeof (arg) === 'number') {
17
+ return {
18
+ dtype: 'num',
19
+ num: arg
20
+ };
21
+ }
22
+ return {
23
+ dtype: 'exp',
24
+ exp: arg
25
+ };
26
+ })
27
+ };
28
+ };
29
+
30
+ exports.generateExpression = generateExpression;
31
+ //# sourceMappingURL=expressionGen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expressionGen.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,114 @@
1
+ import { Expression } from "survey-engine/lib/data_types";
2
+ import { Duration } from "../types/duration";
3
+ export declare const NativeStudyEngineExpressions: {
4
+ checkEventType: (equalsType: 'ENTER' | 'SUBMIT' | 'TIMER') => Expression;
5
+ checkSurveyResponseKey: (surveyKey: string) => Expression;
6
+ responseHasKeysAny: (itemKey: string, responseSlotKey: string, ...optionKeys: string[]) => Expression;
7
+ responseHasOnlyKeysOtherThan: (itemKey: string, responseSlotKey: string, ...optionKeys: string[]) => Expression;
8
+ getResponseValueAsNum: (itemKey: string, responseKey: string) => Expression;
9
+ getResponseValueAsStr: (itemKey: string, responseKey: string) => Expression;
10
+ countResponseItems: (itemKey: string, responseKey: string) => Expression;
11
+ checkConditionForOldResponses: (condition: Expression, checkType?: number | "all" | "any" | undefined, surveyKey?: string | undefined, querySince?: number | Expression | undefined, queryUntil?: number | Expression | undefined) => Expression;
12
+ participantState: {
13
+ getStudyEntryTime: () => Expression;
14
+ hasSurveyKeyAssigned: (surveyKey: string) => Expression;
15
+ getSurveyKeyAssignedFrom: (surveyKey: string) => Expression;
16
+ getSurveyKeyAssignedUntil: (surveyKey: string) => Expression;
17
+ hasStudyStatus: (status: string) => Expression;
18
+ hasParticipantFlag: (key: string, value: string) => Expression;
19
+ lastSubmissionDateOlderThan: (reference: number | Expression, surveyKey?: string | undefined) => Expression;
20
+ };
21
+ eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
22
+ lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
23
+ lte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
24
+ gt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
25
+ gte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
26
+ or: (...args: Expression[]) => Expression;
27
+ and: (...args: Expression[]) => Expression;
28
+ not: (arg: Expression) => Expression;
29
+ timestampWithOffset: (delta: Duration, reference?: number | Expression | undefined) => Expression;
30
+ };
31
+ export declare const StudyEngineActions: {
32
+ if: (condition: Expression, actionIfTrue: Expression, actionIfFalse?: Expression | undefined) => Expression;
33
+ do: (...args: Expression[]) => Expression;
34
+ ifThen: (condition: Expression, ...args: Expression[]) => Expression;
35
+ participantActions: {
36
+ updateStudyStatus: (status: string) => Expression;
37
+ updateFlag: (key: string, newValue: string) => Expression;
38
+ removeFlag: (key: string) => Expression;
39
+ assignedSurveys: {
40
+ add: (surveyKey: string, category: 'prio' | 'normal' | 'optional', activeFrom?: number | Expression | undefined, activeUntil?: number | Expression | undefined) => Expression;
41
+ removeAll: () => Expression;
42
+ remove: (surveyKey: string, selector: 'first' | 'last' | 'all') => Expression;
43
+ };
44
+ reports: {
45
+ add: (itemKey: string) => Expression;
46
+ removeAll: () => Expression;
47
+ remove: (surveyKey: string, selector: 'first' | 'last' | 'all') => Expression;
48
+ };
49
+ stopParticipation: () => Expression;
50
+ finishParticipation: () => Expression;
51
+ };
52
+ };
53
+ export declare const StudyEngine: {
54
+ singleChoice: {
55
+ any: (itemKey: string, ...optionKeys: string[]) => Expression;
56
+ none: (itemKey: string, ...optionKeys: string[]) => Expression;
57
+ };
58
+ multipleChoice: {
59
+ any: (itemKey: string, ...optionKeys: string[]) => Expression;
60
+ none: (itemKey: string, ...optionKeys: string[]) => Expression;
61
+ all: (itemKey: string, ...optionKeys: string[]) => Expression;
62
+ };
63
+ survey: {
64
+ isActive: (surveyKey: string) => Expression;
65
+ validFromOlderThan: (surveyKey: string, delta: Duration, reference?: number | Expression | undefined) => Expression;
66
+ validUntilSoonerThan: (surveyKey: string, delta: Duration, reference?: number | Expression | undefined) => Expression;
67
+ };
68
+ if: (condition: Expression, actionIfTrue: Expression, actionIfFalse?: Expression | undefined) => Expression;
69
+ do: (...args: Expression[]) => Expression;
70
+ ifThen: (condition: Expression, ...args: Expression[]) => Expression;
71
+ participantActions: {
72
+ updateStudyStatus: (status: string) => Expression;
73
+ updateFlag: (key: string, newValue: string) => Expression;
74
+ removeFlag: (key: string) => Expression;
75
+ assignedSurveys: {
76
+ add: (surveyKey: string, category: 'prio' | 'normal' | 'optional', activeFrom?: number | Expression | undefined, activeUntil?: number | Expression | undefined) => Expression;
77
+ removeAll: () => Expression;
78
+ remove: (surveyKey: string, selector: 'first' | 'last' | 'all') => Expression;
79
+ };
80
+ reports: {
81
+ add: (itemKey: string) => Expression;
82
+ removeAll: () => Expression;
83
+ remove: (surveyKey: string, selector: 'first' | 'last' | 'all') => Expression;
84
+ };
85
+ stopParticipation: () => Expression;
86
+ finishParticipation: () => Expression;
87
+ };
88
+ checkEventType: (equalsType: 'ENTER' | 'SUBMIT' | 'TIMER') => Expression;
89
+ checkSurveyResponseKey: (surveyKey: string) => Expression;
90
+ responseHasKeysAny: (itemKey: string, responseSlotKey: string, ...optionKeys: string[]) => Expression;
91
+ responseHasOnlyKeysOtherThan: (itemKey: string, responseSlotKey: string, ...optionKeys: string[]) => Expression;
92
+ getResponseValueAsNum: (itemKey: string, responseKey: string) => Expression;
93
+ getResponseValueAsStr: (itemKey: string, responseKey: string) => Expression;
94
+ countResponseItems: (itemKey: string, responseKey: string) => Expression;
95
+ checkConditionForOldResponses: (condition: Expression, checkType?: number | "all" | "any" | undefined, surveyKey?: string | undefined, querySince?: number | Expression | undefined, queryUntil?: number | Expression | undefined) => Expression;
96
+ participantState: {
97
+ getStudyEntryTime: () => Expression;
98
+ hasSurveyKeyAssigned: (surveyKey: string) => Expression;
99
+ getSurveyKeyAssignedFrom: (surveyKey: string) => Expression;
100
+ getSurveyKeyAssignedUntil: (surveyKey: string) => Expression;
101
+ hasStudyStatus: (status: string) => Expression;
102
+ hasParticipantFlag: (key: string, value: string) => Expression;
103
+ lastSubmissionDateOlderThan: (reference: number | Expression, surveyKey?: string | undefined) => Expression;
104
+ };
105
+ eq: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
106
+ lt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
107
+ lte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
108
+ gt: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
109
+ gte: (val1: Expression | string | number, val2: Expression | string | number) => Expression;
110
+ or: (...args: Expression[]) => Expression;
111
+ and: (...args: Expression[]) => Expression;
112
+ not: (arg: Expression) => Expression;
113
+ timestampWithOffset: (delta: Duration, reference?: number | Expression | undefined) => Expression;
114
+ };
@@ -0,0 +1,283 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var constants_keyDefinitions = require('../constants/key-definitions.js');
6
+ var types_duration = require('../types/duration.js');
7
+ var expressionUtils_expressionGen = require('./expressionGen.js');
8
+
9
+ const or = (...args) => expressionUtils_expressionGen.generateExpression('or', undefined, ...args);
10
+ const and = (...args) => expressionUtils_expressionGen.generateExpression('and', undefined, ...args);
11
+ const not = (arg) => expressionUtils_expressionGen.generateExpression('not', undefined, arg);
12
+ /**
13
+ * Check if the current event has the given type
14
+ * @param equalsType string with the possible values: 'ENTER', 'SUBMIT', 'TIMER
15
+ * @returns if event type matches the argument, return true otherwise false
16
+ */
17
+ const checkEventType = (equalsType) => expressionUtils_expressionGen.generateExpression('checkEventType', undefined, equalsType);
18
+ /**
19
+ * Check if the submitted survey has a specific key
20
+ * @param surveyKey string to check for
21
+ * @returns true, if the survey has the key, false otherwise
22
+ */
23
+ const checkSurveyResponseKey = (surveyKey) => expressionUtils_expressionGen.generateExpression('checkSurveyResponseKey', undefined, surveyKey);
24
+ /**
25
+ * Check survey response item, if any of the defined option keys is present in the given response group
26
+ * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
27
+ * @param responseSlotKey full key to the response group, e.g., 'rg.scg'
28
+ * @param optionKeys list of option keys to be checked for.
29
+ * @returns true if any of the option keys are present in the item's response. If item or the response group is not found, return false.
30
+ */
31
+ const responseHasKeysAny = (itemKey, responseSlotKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, responseSlotKey, ...optionKeys);
32
+ /**
33
+ * Check survey response item, if only other keys have been selected
34
+ * @param itemKey full key to the survey item, in the form, e.g., <surveyKey>.<groupKey>.<itemKey>
35
+ * @param responseSlotKey full key to the response group, e.g., 'rg.mcg'
36
+ * @param optionKeys list of option keys to be checked for.
37
+ * @returns true if a response key is present, but is not in the list defined by optionKeys. If item or the response group is not found, returns false.
38
+ */
39
+ const responseHasOnlyKeysOtherThan = (itemKey, responseSlotKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, responseSlotKey, ...optionKeys);
40
+ const getResponseValueAsNum = (itemKey, responseKey) => {
41
+ return expressionUtils_expressionGen.generateExpression('getResponseValueAsNum', 'float', itemKey, responseKey);
42
+ };
43
+ const getResponseValueAsStr = (itemKey, responseKey) => {
44
+ return expressionUtils_expressionGen.generateExpression('getResponseValueAsStr', 'string', itemKey, responseKey);
45
+ };
46
+ const countResponseItems = (itemKey, responseKey) => {
47
+ return expressionUtils_expressionGen.generateExpression('countResponseItems', undefined, itemKey, responseKey);
48
+ };
49
+ /**
50
+ * Method to run a check on previous responses of the participant.
51
+ * @param condition expression that will be evaluated on each retrieved response
52
+ * @param checkType - optional - 'all'/'any'/<number>: determines how to calculate the final value of the check. Default: 'all'. 'all' means, all the retrieved responses need to fulfil the condition, otherwise the methods returns false. 'any' means at least one retrieved response needs to fulfil the condtion. In both cases, if there were no responses retrieved, returns false. If a number is given here, it means, at least this many response need to fulfil the condition.
53
+ * @param surveyKey - optional - filter for responses of this survey.
54
+ * @param querySince - optional - retrieve responses that were submitted later than this timestamp. Expressions need to return a timestamp, or hard coded numbers can be used as well.
55
+ * @param queryUntil - optional - retrieve responses that were submitted before this timestamp. Expressions need to return a timestamp, or hard coded numbers can be used as well.
56
+ * @returns true/false
57
+ */
58
+ const checkConditionForOldResponses = (condition, checkType, surveyKey, querySince, queryUntil) => expressionUtils_expressionGen.generateExpression('checkConditionForOldResponses', undefined, condition, checkType, surveyKey, querySince, queryUntil);
59
+ /**
60
+ * Method to access the timestamp for when the participant entered the study
61
+ * @returns timestamp
62
+ */
63
+ const getStudyEntryTime = () => expressionUtils_expressionGen.generateExpression('getStudyEntryTime');
64
+ /**
65
+ * Determines if a specific survey key is currently assigned to the participant.
66
+ * @param surveyKey - string - key of the survey to check for.
67
+ * @returns true if the participant has a survey with this surveyKey assigned, otherwise false.
68
+ */
69
+ const hasSurveyKeyAssigned = (surveyKey) => expressionUtils_expressionGen.generateExpression('hasSurveyKeyAssigned', undefined, surveyKey);
70
+ /**
71
+ * Method to access the timestamp for a surveyKey is assigned from
72
+ * @param surveyKey - string - key of the survey to check for.
73
+ * @returns timestamp
74
+ */
75
+ const getSurveyKeyAssignedFrom = (surveyKey) => expressionUtils_expressionGen.generateExpression('getSurveyKeyAssignedFrom', undefined, surveyKey);
76
+ /**
77
+ * Method to access the timestamp for a surveyKey is assigned until
78
+ * @param surveyKey - string - key of the survey to check for.
79
+ * @returns timestamp
80
+ */
81
+ const getSurveyKeyAssignedUntil = (surveyKey) => expressionUtils_expressionGen.generateExpression('getSurveyKeyAssignedUntil', undefined, surveyKey);
82
+ /**
83
+ * Check if a participant has a specific study status
84
+ * @param status - string
85
+ * @returns true/false
86
+ */
87
+ const hasStudyStatus = (status) => expressionUtils_expressionGen.generateExpression('getSurveyKeyAssignedUntil', undefined, status);
88
+ /**
89
+ * Check if a participant flag is present
90
+ * @param key look up this flag
91
+ * @param value and for this value
92
+ * @returns return true if key - value pair (with case sensitive matching for both key and value) is present. If any of the two is different, or participant flags is empty, it returns false.
93
+ */
94
+ const hasParticipantFlag = (key, value) => expressionUtils_expressionGen.generateExpression('hasParticipantFlag', undefined, key, value);
95
+ /**
96
+ * Check if the last submission is older than the reference timestamp
97
+ * @param reference look up this flag
98
+ * @param surveyKey - optional - check for this specific survey key. If empty, it would check for all the submissions.
99
+ * @returns boolean
100
+ */
101
+ const lastSubmissionDateOlderThan = (reference, surveyKey) => expressionUtils_expressionGen.generateExpression('lastSubmissionDateOlderThan', undefined, reference, surveyKey);
102
+ const eq = (val1, val2) => expressionUtils_expressionGen.generateExpression('eq', undefined, val1, val2);
103
+ const lt = (val1, val2) => expressionUtils_expressionGen.generateExpression('lt', undefined, val1, val2);
104
+ const lte = (val1, val2) => expressionUtils_expressionGen.generateExpression('lte', undefined, val1, val2);
105
+ const gt = (val1, val2) => expressionUtils_expressionGen.generateExpression('gt', undefined, val1, val2);
106
+ const gte = (val1, val2) => expressionUtils_expressionGen.generateExpression('gte', undefined, val1, val2);
107
+ /**
108
+ * Generate a timestamp value (POSIX timestamp). T = T_ref + delta. If 'reference' is not defined, the current time will be used as a reference.
109
+ * @param delta offset for the timestamp generation
110
+ * @param reference optional - a hard coded number, or an expression that should retrieve a timestamp (e.g., surveys assigned from, or response to a date question)
111
+ * @returns
112
+ */
113
+ const timestampWithOffset = (delta, reference) => expressionUtils_expressionGen.generateExpression('timestampWithOffset', undefined, types_duration.durationObjectToSeconds(delta), reference ? reference : undefined);
114
+ /**
115
+ * Control flow method to use an if-else like structure
116
+ * @param condition expression, return value interpreted as boolean
117
+ * @param actionIfTrue if condition evaluates to true, this action will be performed.
118
+ * @param actionIfFalse optional, if defined and the condition returns false, this action will be performed.
119
+ * @returns
120
+ */
121
+ const IF = (condition, actionIfTrue, actionIfFalse) => expressionUtils_expressionGen.generateExpression('IF', undefined, condition, actionIfTrue, actionIfFalse);
122
+ /**
123
+ * Perform a list of expressions / actions
124
+ * @param args: list of expressions to be evaluated
125
+ * @returns
126
+ */
127
+ const DO = (...args) => expressionUtils_expressionGen.generateExpression('DO', undefined, ...args);
128
+ /**
129
+ * Simple if statement (without else), that checks for the condition and executes the list of actions.
130
+ * @param condition condition to check, return value interpreted as boolean
131
+ * @param args list of actions to be performed if condition evaluates to true, otherwise they are ignored
132
+ * @returns
133
+ */
134
+ const IFTHEN = (condition, ...args) => expressionUtils_expressionGen.generateExpression('IFTHEN', undefined, condition, ...args);
135
+ /**
136
+ * Update the participant's study status
137
+ * @param status new status value
138
+ * @returns
139
+ */
140
+ const UPDATE_STUDY_STATUS = (status) => expressionUtils_expressionGen.generateExpression('UPDATE_STUDY_STATUS', undefined, status);
141
+ /**
142
+ * Add or update a participant flag
143
+ * @param key
144
+ * @param newValue
145
+ * @returns
146
+ */
147
+ const UPDATE_FLAG = (key, newValue) => expressionUtils_expressionGen.generateExpression('UPDATE_FLAG', undefined, key, newValue);
148
+ const REMOVE_FLAG = (key) => expressionUtils_expressionGen.generateExpression('REMOVE_FLAG', undefined, key);
149
+ const ADD_NEW_SURVEY = (surveyKey, category, activeFrom, activeUntil) => expressionUtils_expressionGen.generateExpression('ADD_NEW_SURVEY', undefined, surveyKey, activeFrom !== undefined ? activeFrom : 0, activeUntil !== undefined ? activeUntil : 0, category);
150
+ const REMOVE_ALL_SURVEYS = () => expressionUtils_expressionGen.generateExpression('REMOVE_ALL_SURVEYS');
151
+ /**
152
+ * When submitting the response, item response with the given key would be added to the report array
153
+ * @param itemKey find and add this item to the report array
154
+ * @returns
155
+ */
156
+ const ADD_REPORT = (itemKey) => expressionUtils_expressionGen.generateExpression('ADD_REPORT', undefined, itemKey);
157
+ const REMOVE_SURVEY_BY_KEY = (surveyKey, selector) => {
158
+ if (selector === 'all') {
159
+ return expressionUtils_expressionGen.generateExpression('REMOVE_SURVEYS_BY_KEY', undefined, surveyKey);
160
+ }
161
+ else {
162
+ return expressionUtils_expressionGen.generateExpression('REMOVE_SURVEY_BY_KEY', undefined, surveyKey, selector);
163
+ }
164
+ };
165
+ const REMOVE_ALL_REPORTS = () => expressionUtils_expressionGen.generateExpression('REMOVE_ALL_REPORTS');
166
+ const REMOVE_REPORT_BY_KEY = (surveyKey, selector) => {
167
+ if (selector === 'all') {
168
+ return expressionUtils_expressionGen.generateExpression('REMOVE_REPORTS_BY_KEY', undefined, surveyKey);
169
+ }
170
+ else {
171
+ return expressionUtils_expressionGen.generateExpression('REMOVE_REPORT_BY_KEY', undefined, surveyKey, selector);
172
+ }
173
+ };
174
+ // ##################
175
+ // Extra methods:
176
+ const singleChoiceOptionsSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey].join('.'), ...optionKeys);
177
+ const multipleChoiceOptionsSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
178
+ const multipleChoiceAllOfTheseSelected = (itemKey, ...optionKeys) => and(...optionKeys.map(option => expressionUtils_expressionGen.generateExpression('responseHasKeysAny', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), option)));
179
+ const multipleChoiceOnlyOtherKeysSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.multipleChoiceKey].join('.'), ...optionKeys);
180
+ const singleChoiceOnlyOtherOptionSelected = (itemKey, ...optionKeys) => expressionUtils_expressionGen.generateExpression('responseHasOnlyKeysOtherThan', undefined, itemKey, [constants_keyDefinitions.responseGroupKey, constants_keyDefinitions.singleChoiceKey].join('.'), ...optionKeys);
181
+ const stopParticipation = () => UPDATE_STUDY_STATUS('inactive');
182
+ const finishParticipation = () => UPDATE_STUDY_STATUS('finished');
183
+ /**
184
+ * If a survey is assigned with validFrom <= now and validUnil >= now
185
+ * @param surveyKey which survey it should check for
186
+ * @returns
187
+ */
188
+ const hasSurveyKeyActive = (surveyKey) => {
189
+ return and(lte(getSurveyKeyAssignedFrom(surveyKey), timestampWithOffset({ seconds: 1 })), gte(getSurveyKeyAssignedUntil(surveyKey), timestampWithOffset({ seconds: -1 })));
190
+ };
191
+ /**
192
+ * Results of "T_ref = reference + delta" will be checked against "validFrom" of the assinged survey (if present). True T_ref > T_validFrom.
193
+ * @param surveyKey which survey it should check for
194
+ * @param delta delta time to the reference time (by default current time).
195
+ * @param reference optional reference time. If undefined it will take the current time.
196
+ * @returns
197
+ */
198
+ const hasSurveyKeyValidFromOlderThan = (surveyKey, delta, reference) => {
199
+ return lt(getSurveyKeyAssignedFrom(surveyKey), timestampWithOffset(delta, reference));
200
+ };
201
+ /**
202
+ * Results of "T_ref = reference + delta" will be checked against "validUntil" of the assinged survey (if present). True T_ref < T_validUntil.
203
+ * @param surveyKey which survey it should check for
204
+ * @param delta delta time to the reference time (by default current time).
205
+ * @param reference optional reference time. If undefined it will take the current time.
206
+ * @returns
207
+ */
208
+ const hasSurveyKeyValidUntilSoonerThan = (surveyKey, delta, reference) => {
209
+ return gt(timestampWithOffset(delta, reference), getSurveyKeyAssignedUntil(surveyKey));
210
+ };
211
+ const NativeStudyEngineExpressions = {
212
+ checkEventType,
213
+ // Response checkers
214
+ checkSurveyResponseKey,
215
+ responseHasKeysAny,
216
+ responseHasOnlyKeysOtherThan,
217
+ getResponseValueAsNum,
218
+ getResponseValueAsStr,
219
+ countResponseItems,
220
+ // Old responses
221
+ checkConditionForOldResponses,
222
+ // Participant state:
223
+ participantState: {
224
+ getStudyEntryTime,
225
+ hasSurveyKeyAssigned,
226
+ getSurveyKeyAssignedFrom,
227
+ getSurveyKeyAssignedUntil,
228
+ hasStudyStatus,
229
+ hasParticipantFlag,
230
+ lastSubmissionDateOlderThan,
231
+ },
232
+ // logical and comparision
233
+ eq,
234
+ lt,
235
+ lte,
236
+ gt,
237
+ gte,
238
+ or,
239
+ and,
240
+ not,
241
+ // Other
242
+ timestampWithOffset,
243
+ };
244
+ const StudyEngineActions = {
245
+ if: IF,
246
+ do: DO,
247
+ ifThen: IFTHEN,
248
+ participantActions: {
249
+ updateStudyStatus: UPDATE_STUDY_STATUS,
250
+ updateFlag: UPDATE_FLAG,
251
+ removeFlag: REMOVE_FLAG,
252
+ assignedSurveys: {
253
+ add: ADD_NEW_SURVEY,
254
+ removeAll: REMOVE_ALL_SURVEYS,
255
+ remove: REMOVE_SURVEY_BY_KEY,
256
+ },
257
+ reports: {
258
+ add: ADD_REPORT,
259
+ removeAll: REMOVE_ALL_REPORTS,
260
+ remove: REMOVE_REPORT_BY_KEY,
261
+ },
262
+ // Extra methods:
263
+ stopParticipation,
264
+ finishParticipation,
265
+ }
266
+ };
267
+ const StudyEngine = Object.assign(Object.assign(Object.assign({}, NativeStudyEngineExpressions), StudyEngineActions), { singleChoice: {
268
+ any: singleChoiceOptionsSelected,
269
+ none: singleChoiceOnlyOtherOptionSelected
270
+ }, multipleChoice: {
271
+ any: multipleChoiceOptionsSelected,
272
+ none: multipleChoiceOnlyOtherKeysSelected,
273
+ all: multipleChoiceAllOfTheseSelected,
274
+ }, survey: {
275
+ isActive: hasSurveyKeyActive,
276
+ validFromOlderThan: hasSurveyKeyValidFromOlderThan,
277
+ validUntilSoonerThan: hasSurveyKeyValidUntilSoonerThan,
278
+ } });
279
+
280
+ exports.NativeStudyEngineExpressions = NativeStudyEngineExpressions;
281
+ exports.StudyEngine = StudyEngine;
282
+ exports.StudyEngineActions = StudyEngineActions;
283
+ //# sourceMappingURL=studyEngineExpressions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"studyEngineExpressions.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
File without changes
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ 'use strict';
2
+
3
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}