@openforis/arena-core 3.2.1 → 3.2.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.
- package/dist/app/appInfo.d.ts +5 -1
- package/dist/app/appInfo.js.map +1 -1
- package/dist/app/appInfos.d.ts +19 -0
- package/dist/app/appInfos.js +27 -0
- package/dist/app/appInfos.js.map +1 -0
- package/dist/app/index.d.ts +2 -1
- package/dist/app/index.js +3 -0
- package/dist/app/index.js.map +1 -1
- package/dist/esm/app/appInfo.js.map +1 -1
- package/dist/esm/app/appInfos.js +24 -0
- package/dist/esm/app/appInfos.js.map +1 -0
- package/dist/esm/app/index.js +1 -1
- package/dist/esm/app/index.js.map +1 -1
- package/dist/esm/expression/context.js.map +1 -1
- package/dist/esm/expression/javascript/evaluator.js +3 -16
- package/dist/esm/expression/javascript/evaluator.js.map +1 -1
- package/dist/esm/expression/javascript/parser/expressionNodesFinder.js +68 -0
- package/dist/esm/expression/javascript/parser/expressionNodesFinder.js.map +1 -0
- package/dist/esm/geo/points/transform.js +3 -10
- package/dist/esm/geo/points/transform.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node/index.js.map +1 -1
- package/dist/esm/node/nodeValueFormatter.js +1 -0
- package/dist/esm/node/nodeValueFormatter.js.map +1 -1
- package/dist/esm/node/nodes.js +14 -12
- package/dist/esm/node/nodes.js.map +1 -1
- package/dist/esm/nodeDef/types/entity.js.map +1 -1
- package/dist/esm/nodeDefExpressionEvaluator/context.js.map +1 -1
- package/dist/esm/nodeDefExpressionEvaluator/evaluator.js +19 -1
- package/dist/esm/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
- package/dist/esm/nodeDefExpressionEvaluator/functions.js +53 -0
- package/dist/esm/nodeDefExpressionEvaluator/functions.js.map +1 -1
- package/dist/esm/record/_records/recordGetters.js +18 -0
- package/dist/esm/record/_records/recordGetters.js.map +1 -1
- package/dist/esm/record/record.js.map +1 -1
- package/dist/esm/record/recordExpressionEvaluator/functions.js +14 -0
- package/dist/esm/record/recordExpressionEvaluator/functions.js.map +1 -1
- package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js +9 -1
- package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordExpressionEvaluationContext.js +1 -0
- package/dist/esm/record/recordNodesUpdater/recordExpressionEvaluationContext.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +5 -3
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +6 -4
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +2 -2
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +11 -3
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +46 -21
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +14 -6
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +5 -5
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +22 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js +111 -8
- package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordUpdateResult.js +10 -0
- package/dist/esm/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
- package/dist/esm/record/recordUpdater.js +62 -9
- package/dist/esm/record/recordUpdater.js.map +1 -1
- package/dist/esm/record/records.js +3 -1
- package/dist/esm/record/records.js.map +1 -1
- package/dist/esm/survey/survey.js +2 -0
- package/dist/esm/survey/survey.js.map +1 -1
- package/dist/esm/survey/surveys/dependencies.js +67 -32
- package/dist/esm/survey/surveys/dependencies.js.map +1 -1
- package/dist/esm/survey/surveys/index.js +2 -1
- package/dist/esm/survey/surveys/index.js.map +1 -1
- package/dist/esm/utils/_objects/isEqual.js +2 -0
- package/dist/esm/utils/_objects/isEqual.js.map +1 -1
- package/dist/esm/utils/lruCache.js +50 -0
- package/dist/esm/utils/lruCache.js.map +1 -0
- package/dist/expression/context.d.ts +5 -0
- package/dist/expression/context.js.map +1 -1
- package/dist/expression/javascript/evaluator.js +3 -16
- package/dist/expression/javascript/evaluator.js.map +1 -1
- package/dist/expression/javascript/parser/expressionNodesFinder.d.ts +13 -0
- package/dist/expression/javascript/parser/expressionNodesFinder.js +73 -0
- package/dist/expression/javascript/parser/expressionNodesFinder.js.map +1 -0
- package/dist/geo/points/transform.js +3 -10
- package/dist/geo/points/transform.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/nodeValueFormatter.d.ts +1 -1
- package/dist/node/nodeValueFormatter.js +1 -0
- package/dist/node/nodeValueFormatter.js.map +1 -1
- package/dist/node/nodes.d.ts +18 -5
- package/dist/node/nodes.js +14 -12
- package/dist/node/nodes.js.map +1 -1
- package/dist/nodeDef/types/entity.d.ts +1 -1
- package/dist/nodeDef/types/entity.js.map +1 -1
- package/dist/nodeDefExpressionEvaluator/context.d.ts +4 -0
- package/dist/nodeDefExpressionEvaluator/context.js.map +1 -1
- package/dist/nodeDefExpressionEvaluator/evaluator.d.ts +9 -1
- package/dist/nodeDefExpressionEvaluator/evaluator.js +19 -1
- package/dist/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
- package/dist/nodeDefExpressionEvaluator/functions.js +53 -0
- package/dist/nodeDefExpressionEvaluator/functions.js.map +1 -1
- package/dist/record/_records/recordGetters.d.ts +10 -0
- package/dist/record/_records/recordGetters.js +21 -1
- package/dist/record/_records/recordGetters.js.map +1 -1
- package/dist/record/record.d.ts +1 -1
- package/dist/record/record.js.map +1 -1
- package/dist/record/recordExpressionEvaluator/functions.js +14 -0
- package/dist/record/recordExpressionEvaluator/functions.js.map +1 -1
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.d.ts +8 -0
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js +9 -1
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.d.ts +6 -0
- package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.js +1 -0
- package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +5 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.d.ts +2 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +5 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +2 -2
- package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +11 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +45 -20
- package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +14 -6
- package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +4 -4
- package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.d.ts +19 -0
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +24 -1
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodesUpdater.d.ts +8 -1
- package/dist/record/recordNodesUpdater/recordNodesUpdater.js +107 -4
- package/dist/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordUpdateResult.d.ts +5 -0
- package/dist/record/recordNodesUpdater/recordUpdateResult.js +10 -0
- package/dist/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
- package/dist/record/recordUpdater.d.ts +11 -3
- package/dist/record/recordUpdater.js +61 -8
- package/dist/record/recordUpdater.js.map +1 -1
- package/dist/record/records.d.ts +3 -1
- package/dist/record/records.js +2 -0
- package/dist/record/records.js.map +1 -1
- package/dist/survey/survey.d.ts +3 -1
- package/dist/survey/survey.js +2 -0
- package/dist/survey/survey.js.map +1 -1
- package/dist/survey/surveys/dependencies.d.ts +10 -0
- package/dist/survey/surveys/dependencies.js +69 -33
- package/dist/survey/surveys/dependencies.js.map +1 -1
- package/dist/survey/surveys/index.d.ts +2 -1
- package/dist/survey/surveys/index.js +1 -0
- package/dist/survey/surveys/index.js.map +1 -1
- package/dist/utils/_objects/isEqual.d.ts +3 -1
- package/dist/utils/_objects/isEqual.js +2 -0
- package/dist/utils/_objects/isEqual.js.map +1 -1
- package/dist/utils/lruCache.d.ts +18 -0
- package/dist/utils/lruCache.js +54 -0
- package/dist/utils/lruCache.js.map +1 -0
- package/package.json +1 -1
|
@@ -10,11 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import * as SurveyNodeDefs from './nodeDefs';
|
|
11
11
|
import { NodeDefs, NodeDefType, } from '../../nodeDef';
|
|
12
12
|
import { NodeDefExpressionEvaluator } from '../../nodeDefExpressionEvaluator';
|
|
13
|
+
import { findFunctionCallNames } from '../../expression/javascript/parser/expressionNodesFinder';
|
|
13
14
|
import { SurveyDependencyType } from '../survey';
|
|
14
15
|
import { Arrays, Objects } from '../../utils';
|
|
15
16
|
import { NodeDefExpressionFactory } from '../../nodeDef/nodeDef';
|
|
16
|
-
|
|
17
|
+
// dependency types stored as dictionary of booleans (node def uuid => true), not as dependents of a node def
|
|
18
|
+
const booleanDependencyTypes = new Set([
|
|
19
|
+
SurveyDependencyType.onUpdate,
|
|
20
|
+
SurveyDependencyType.appInfo,
|
|
21
|
+
]);
|
|
22
|
+
const functionNamesByBooleanDependencyType = {
|
|
23
|
+
[SurveyDependencyType.onUpdate]: ['recordDateLastModified'],
|
|
24
|
+
[SurveyDependencyType.appInfo]: ['appId', 'appIdLabel', 'appPlatform', 'appVersion'],
|
|
25
|
+
};
|
|
17
26
|
const isContextParentByDependencyType = {
|
|
27
|
+
[SurveyDependencyType.appInfo]: true,
|
|
18
28
|
[SurveyDependencyType.applicable]: true,
|
|
19
29
|
[SurveyDependencyType.defaultValues]: true,
|
|
20
30
|
[SurveyDependencyType.editable]: true,
|
|
@@ -23,6 +33,7 @@ const isContextParentByDependencyType = {
|
|
|
23
33
|
[SurveyDependencyType.formula]: false,
|
|
24
34
|
[SurveyDependencyType.maxCount]: true,
|
|
25
35
|
[SurveyDependencyType.minCount]: true,
|
|
36
|
+
[SurveyDependencyType.nodeDates]: true,
|
|
26
37
|
[SurveyDependencyType.onUpdate]: true,
|
|
27
38
|
[SurveyDependencyType.parentCode]: false,
|
|
28
39
|
[SurveyDependencyType.required]: true,
|
|
@@ -30,6 +41,7 @@ const isContextParentByDependencyType = {
|
|
|
30
41
|
[SurveyDependencyType.visible]: true,
|
|
31
42
|
};
|
|
32
43
|
const selfReferenceAllowedByDependencyType = {
|
|
44
|
+
[SurveyDependencyType.appInfo]: false,
|
|
33
45
|
[SurveyDependencyType.applicable]: false,
|
|
34
46
|
[SurveyDependencyType.defaultValues]: false,
|
|
35
47
|
[SurveyDependencyType.editable]: false,
|
|
@@ -38,6 +50,7 @@ const selfReferenceAllowedByDependencyType = {
|
|
|
38
50
|
[SurveyDependencyType.formula]: false,
|
|
39
51
|
[SurveyDependencyType.maxCount]: false,
|
|
40
52
|
[SurveyDependencyType.minCount]: false,
|
|
53
|
+
[SurveyDependencyType.nodeDates]: false,
|
|
41
54
|
[SurveyDependencyType.onUpdate]: false,
|
|
42
55
|
[SurveyDependencyType.parentCode]: false,
|
|
43
56
|
[SurveyDependencyType.required]: false,
|
|
@@ -45,6 +58,7 @@ const selfReferenceAllowedByDependencyType = {
|
|
|
45
58
|
[SurveyDependencyType.visible]: false,
|
|
46
59
|
};
|
|
47
60
|
const newDependencyGraph = () => ({
|
|
61
|
+
[SurveyDependencyType.appInfo]: {},
|
|
48
62
|
[SurveyDependencyType.applicable]: {},
|
|
49
63
|
[SurveyDependencyType.defaultValues]: {},
|
|
50
64
|
[SurveyDependencyType.editable]: {},
|
|
@@ -53,6 +67,7 @@ const newDependencyGraph = () => ({
|
|
|
53
67
|
[SurveyDependencyType.formula]: {},
|
|
54
68
|
[SurveyDependencyType.maxCount]: {},
|
|
55
69
|
[SurveyDependencyType.minCount]: {},
|
|
70
|
+
[SurveyDependencyType.nodeDates]: {},
|
|
56
71
|
[SurveyDependencyType.onUpdate]: {},
|
|
57
72
|
[SurveyDependencyType.parentCode]: {},
|
|
58
73
|
[SurveyDependencyType.required]: {},
|
|
@@ -64,7 +79,7 @@ const getDependencies = (params) => {
|
|
|
64
79
|
var _a;
|
|
65
80
|
var _b;
|
|
66
81
|
const { graphs, type, nodeDefUuid } = params;
|
|
67
|
-
return type
|
|
82
|
+
return booleanDependencyTypes.has(type) ? [] : ((_b = (_a = graphs === null || graphs === void 0 ? void 0 : graphs[type]) === null || _a === void 0 ? void 0 : _a[nodeDefUuid]) !== null && _b !== void 0 ? _b : []);
|
|
68
83
|
};
|
|
69
84
|
export const getNodeDefDependents = (params) => {
|
|
70
85
|
const { survey, nodeDefUuid, dependencyType } = params;
|
|
@@ -81,13 +96,22 @@ export const getNodeDefDependents = (params) => {
|
|
|
81
96
|
}
|
|
82
97
|
return dependentUuids.size > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: [...dependentUuids] }) : [];
|
|
83
98
|
};
|
|
84
|
-
|
|
99
|
+
const getBooleanDependencyTypeDependents = (params) => {
|
|
85
100
|
var _a;
|
|
86
|
-
const { survey } = params;
|
|
101
|
+
const { survey, dependencyType } = params;
|
|
87
102
|
const dependencyGraph = getDependencyGraph(survey);
|
|
88
|
-
const sourceDefUuids = Object.keys((_a = dependencyGraph[
|
|
103
|
+
const sourceDefUuids = Object.keys((_a = dependencyGraph[dependencyType]) !== null && _a !== void 0 ? _a : {});
|
|
89
104
|
return sourceDefUuids.length > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: sourceDefUuids }) : [];
|
|
90
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Returns the node defs to be evaluated again on every record update (their expressions use e.g. recordDateLastModified).
|
|
108
|
+
*/
|
|
109
|
+
export const getOnUpdateDependents = (params) => getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.onUpdate });
|
|
110
|
+
/**
|
|
111
|
+
* Returns the node defs to be evaluated again when a record is updated with a different app
|
|
112
|
+
* (their expressions use the app info functions: appId, appIdLabel, appPlatform, appVersion).
|
|
113
|
+
*/
|
|
114
|
+
export const getAppInfoDependents = (params) => getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.appInfo });
|
|
91
115
|
// UPDATE
|
|
92
116
|
const addDependency = (params) => {
|
|
93
117
|
const { graphs, type, nodeDefUuid, nodeDefDepUuid, sideEffect = false } = params;
|
|
@@ -105,36 +129,41 @@ const addDependencies = (params) => __awaiter(void 0, void 0, void 0, function*
|
|
|
105
129
|
let graphsUpdated = sideEffect ? graphsParam : Object.assign({}, graphsParam);
|
|
106
130
|
const isContextParent = isContextParentByDependencyType[type];
|
|
107
131
|
const selfReferenceAllowed = selfReferenceAllowedByDependencyType[type];
|
|
132
|
+
const referencedNodeDefUuids = new Set();
|
|
133
|
+
const nodeDateReferencedNodeDefUuids = new Set();
|
|
108
134
|
const findReferencedNodeDefs = (expression) => __awaiter(void 0, void 0, void 0, function* () {
|
|
109
135
|
if (!expression)
|
|
110
|
-
return
|
|
111
|
-
const
|
|
136
|
+
return;
|
|
137
|
+
const result = yield new NodeDefExpressionEvaluator().findReferencedNodeDefUuidsWithNodeDates({
|
|
112
138
|
expression,
|
|
113
139
|
survey,
|
|
114
140
|
nodeDef,
|
|
115
141
|
isContextParent,
|
|
116
142
|
selfReferenceAllowed,
|
|
117
143
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
referencedNodeDefsByUuid[uuid] = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid });
|
|
121
|
-
}
|
|
122
|
-
return referencedNodeDefsByUuid;
|
|
144
|
+
result.referencedNodeDefUuids.forEach((uuid) => referencedNodeDefUuids.add(uuid));
|
|
145
|
+
result.nodeDateReferencedNodeDefUuids.forEach((uuid) => nodeDateReferencedNodeDefUuids.add(uuid));
|
|
123
146
|
});
|
|
124
|
-
|
|
147
|
+
yield Promise.all(expressions.flatMap((nodeDefExpr) => [
|
|
125
148
|
findReferencedNodeDefs(nodeDefExpr.expression),
|
|
126
149
|
findReferencedNodeDefs(nodeDefExpr.applyIf),
|
|
127
150
|
]));
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
151
|
+
const addGraphDependencies = (dependencyType, sourceDefUuids) => {
|
|
152
|
+
for (const sourceDefUuid of sourceDefUuids) {
|
|
153
|
+
// the referenced node def must exist
|
|
154
|
+
const sourceDef = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid: sourceDefUuid });
|
|
155
|
+
graphsUpdated = addDependency({
|
|
156
|
+
graphs: graphsUpdated,
|
|
157
|
+
type: dependencyType,
|
|
158
|
+
nodeDefUuid: sourceDef.uuid,
|
|
159
|
+
nodeDefDepUuid: nodeDef.uuid,
|
|
160
|
+
sideEffect,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
addGraphDependencies(type, referencedNodeDefUuids);
|
|
165
|
+
// entities whose nodes dates are used in the expressions (nodeDateCreated, nodeDateModified)
|
|
166
|
+
addGraphDependencies(SurveyDependencyType.nodeDates, nodeDateReferencedNodeDefUuids);
|
|
138
167
|
return graphsUpdated;
|
|
139
168
|
});
|
|
140
169
|
export const addNodeDefDependencies = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -150,14 +179,20 @@ export const addNodeDefDependencies = (params) => __awaiter(void 0, void 0, void
|
|
|
150
179
|
graphs: graphsUpdated,
|
|
151
180
|
sideEffect,
|
|
152
181
|
});
|
|
153
|
-
// add onUpdate dependencies
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
182
|
+
// add boolean (onUpdate, appInfo) dependencies
|
|
183
|
+
const calledFunctionNames = new Set(expressions.flatMap((expression) => [
|
|
184
|
+
...findFunctionCallNames(expression.expression),
|
|
185
|
+
...findFunctionCallNames(expression.applyIf),
|
|
186
|
+
]));
|
|
187
|
+
for (const [booleanDependencyType, functionNames] of Object.entries(functionNamesByBooleanDependencyType)) {
|
|
188
|
+
if (functionNames.some((functionName) => calledFunctionNames.has(functionName))) {
|
|
189
|
+
_graphUpdated = Objects.assocPath({
|
|
190
|
+
obj: _graphUpdated,
|
|
191
|
+
path: [booleanDependencyType, nodeDef.uuid],
|
|
192
|
+
value: true,
|
|
193
|
+
sideEffect,
|
|
194
|
+
});
|
|
195
|
+
}
|
|
161
196
|
}
|
|
162
197
|
return _graphUpdated;
|
|
163
198
|
});
|
|
@@ -218,7 +253,7 @@ const _removeNodeDefDependenciesOfType = (params) => {
|
|
|
218
253
|
let graphUpdated = Object.assign({}, graphsUpdated[dependencyType]);
|
|
219
254
|
// dissoc nodeDefUuid dependency as dependent
|
|
220
255
|
graphUpdated = Objects.dissoc({ obj: graphUpdated, prop: nodeDefUuid });
|
|
221
|
-
if (dependencyType
|
|
256
|
+
if (!booleanDependencyTypes.has(dependencyType)) {
|
|
222
257
|
// dissoc nodeDefUuid dependency from sources (if any)
|
|
223
258
|
for (const [key, dependentUuids] of Object.entries(graphUpdated)) {
|
|
224
259
|
graphUpdated[key] = Arrays.removeItem(nodeDefUuid)(dependentUuids);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../../../src/survey/surveys/dependencies.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,cAAc,MAAM,YAAY,CAAA;AAC5C,OAAO,EAOL,QAAQ,EACR,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAA;AAE7E,OAAO,EAA2C,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAGhE,MAAM,oCAAoC,GAAG,CAAC,wBAAwB,CAAC,CAAA;AAEvE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GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAO,MAAmB,EAAwB,EAAE;IAC9F,iIAAiI;IACjI,MAAM,UAAU,GAAG,IAAI,CAAA;IAEvB,sCAAsC;IACtC,IAAI,aAAa,mCAAqB,MAAM,KAAE,eAAe,EAAE,kBAAkB,EAAE,GAAE,CAAA;IACrF,KAAK,MAAM,OAAO,IAAI,cAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9D,gDAAgD;QAChD,aAAa,GAAG,MAAM,sBAAsB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAA,CAAC,UAAU;IACzG,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA,CAAA","sourcesContent":["import * as SurveyNodeDefs from './nodeDefs'\nimport {\n ArenaAnyNodeDef,\n ArenaNodeDef,\n ArenaNodeDefCode,\n ArenaNodeDefEntity,\n ArenaNodeDefExpression,\n ArenaNodeDefFile,\n NodeDefs,\n NodeDefType,\n} from '../../nodeDef'\nimport { NodeDefExpressionEvaluator } from '../../nodeDefExpressionEvaluator'\n\nimport { ArenaSurvey, ArenaSurveyDependencyGraph, SurveyDependencyType } from '../survey'\nimport { Arrays, Objects } from '../../utils'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\nimport { ArenaDictionary } from '../../common'\n\nconst functionsRequiringOnUpdateDependency = ['recordDateLastModified']\n\nconst isContextParentByDependencyType = {\n [SurveyDependencyType.applicable]: true,\n [SurveyDependencyType.defaultValues]: true,\n [SurveyDependencyType.editable]: true,\n [SurveyDependencyType.enumeratingItems]: true,\n [SurveyDependencyType.fileName]: true,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: true,\n [SurveyDependencyType.minCount]: true,\n [SurveyDependencyType.onUpdate]: true,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: true,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: true,\n}\n\nconst selfReferenceAllowedByDependencyType = {\n [SurveyDependencyType.applicable]: false,\n [SurveyDependencyType.defaultValues]: false,\n [SurveyDependencyType.editable]: false,\n [SurveyDependencyType.enumeratingItems]: false,\n [SurveyDependencyType.fileName]: false,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: false,\n [SurveyDependencyType.minCount]: false,\n [SurveyDependencyType.onUpdate]: false,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: false,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: false,\n}\n\nconst newDependencyGraph = () => ({\n [SurveyDependencyType.applicable]: {},\n [SurveyDependencyType.defaultValues]: {},\n [SurveyDependencyType.editable]: {},\n [SurveyDependencyType.enumeratingItems]: {},\n [SurveyDependencyType.fileName]: {},\n [SurveyDependencyType.formula]: {},\n [SurveyDependencyType.maxCount]: {},\n [SurveyDependencyType.minCount]: {},\n [SurveyDependencyType.onUpdate]: {},\n [SurveyDependencyType.parentCode]: {},\n [SurveyDependencyType.required]: {},\n [SurveyDependencyType.validations]: {},\n [SurveyDependencyType.visible]: {},\n})\n\nconst getDependencyGraph = (survey: ArenaSurvey): ArenaSurveyDependencyGraph =>\n survey.dependencyGraph ?? newDependencyGraph()\n\nconst getDependencies = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n}): Array<string> => {\n const { graphs, type, nodeDefUuid } = params\n return type === SurveyDependencyType.onUpdate ? [] : ((graphs?.[type]?.[nodeDefUuid] ?? []) as string[])\n}\n\nexport const getNodeDefDependents = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaAnyNodeDef[] => {\n const { survey, nodeDefUuid, dependencyType } = params\n const dependencyGraph = getDependencyGraph(survey)\n\n const dependentUuids = new Set<string>()\n\n const dependencyTypes: SurveyDependencyType[] = dependencyType\n ? [dependencyType]\n : Object.values(SurveyDependencyType)\n\n for (const depType of dependencyTypes) {\n const dependentUuidsTemp = getDependencies({ graphs: dependencyGraph, type: depType, nodeDefUuid })\n for (const dependentUuid of dependentUuidsTemp) {\n dependentUuids.add(dependentUuid)\n }\n }\n return dependentUuids.size > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: [...dependentUuids] }) : []\n}\n\nexport const getOnUpdateDependents = (params: { survey: ArenaSurvey }) => {\n const { survey } = params\n const dependencyGraph = getDependencyGraph(survey)\n const sourceDefUuids = Object.keys(dependencyGraph[SurveyDependencyType.onUpdate] ?? {})\n return sourceDefUuids.length > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: sourceDefUuids }) : []\n}\n\n// UPDATE\n\nconst addDependency = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n nodeDefDepUuid: string\n sideEffect: boolean\n}): ArenaSurveyDependencyGraph => {\n const { graphs, type, nodeDefUuid, nodeDefDepUuid, sideEffect = false } = params\n const deps = getDependencies({ graphs, type, nodeDefUuid })\n // dependencies of a node def can be added again (e.g. when it is updated): keep each dependent only once\n if (deps.includes(nodeDefDepUuid)) return graphs\n const depsUpdated = Arrays.addItem(nodeDefDepUuid, { sideEffect })(deps)\n return Objects.assocPath({ obj: graphs, path: [type, nodeDefUuid], value: depsUpdated, sideEffect })\n}\n\nconst addDependencies = async (params: {\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n type: SurveyDependencyType\n graphs: ArenaSurveyDependencyGraph\n expressions: ArenaNodeDefExpression[]\n sideEffect?: boolean\n}): Promise<ArenaSurveyDependencyGraph> => {\n const { survey, nodeDef, type, expressions, graphs: graphsParam, sideEffect = false } = params\n\n if (!expressions || expressions.length === 0) return graphsParam\n\n let graphsUpdated = sideEffect ? graphsParam : { ...graphsParam }\n\n const isContextParent = isContextParentByDependencyType[type]\n const selfReferenceAllowed = selfReferenceAllowedByDependencyType[type]\n\n const findReferencedNodeDefs = async (\n expression: string | undefined\n ): Promise<{ [key: string]: ArenaAnyNodeDef }> => {\n if (!expression) return {}\n\n const referencedNodeDefUuids = await new NodeDefExpressionEvaluator().findReferencedNodeDefUuids({\n expression,\n survey,\n nodeDef,\n isContextParent,\n selfReferenceAllowed,\n })\n const referencedNodeDefsByUuid: ArenaDictionary<ArenaNodeDef<any>> = {}\n for (const uuid of referencedNodeDefUuids) {\n referencedNodeDefsByUuid[uuid] = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid })\n }\n return referencedNodeDefsByUuid\n }\n\n const referencedNodeDefsArray = await Promise.all(\n expressions.flatMap((nodeDefExpr) => [\n findReferencedNodeDefs(nodeDefExpr.expression),\n findReferencedNodeDefs(nodeDefExpr.applyIf),\n ])\n )\n const referencedNodeDefs: ArenaDictionary<ArenaNodeDef<any>> = Object.assign({}, ...referencedNodeDefsArray)\n\n for (const nodeDefRef of Object.values(referencedNodeDefs)) {\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type,\n nodeDefUuid: nodeDefRef.uuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n\n return graphsUpdated\n}\n\nexport const addNodeDefDependencies = async (params: {\n nodeDef: ArenaAnyNodeDef\n survey: ArenaSurvey\n sideEffect?: boolean\n}): Promise<ArenaSurvey> => {\n const { nodeDef, survey, sideEffect = false } = params\n const graphs = getDependencyGraph(survey)\n let graphsUpdated = sideEffect ? graphs : { ...graphs }\n\n const _addDependencies = async (type: SurveyDependencyType, expressions: ArenaNodeDefExpression[]) => {\n let _graphUpdated = await addDependencies({\n survey,\n nodeDef,\n type,\n expressions,\n graphs: graphsUpdated,\n sideEffect,\n })\n // add onUpdate dependencies\n if (\n expressions.some((expression) =>\n functionsRequiringOnUpdateDependency.some(\n (functionName) => expression.applyIf?.includes(functionName) || expression.expression?.includes(functionName)\n )\n )\n ) {\n _graphUpdated = Objects.assocPath({\n obj: _graphUpdated,\n path: [SurveyDependencyType.onUpdate, nodeDef.uuid],\n value: true,\n sideEffect,\n })\n }\n return _graphUpdated\n }\n graphsUpdated = await _addDependencies(SurveyDependencyType.applicable, NodeDefs.getApplicable(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.defaultValues, NodeDefs.getDefaultValues(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.editable, NodeDefs.getEditableIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.required, NodeDefs.getRequiredIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.validations, NodeDefs.getValidationsExpressions(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.visible, NodeDefs.getVisibleIf(nodeDef))\n const maxCount = NodeDefs.getMaxCount(nodeDef)\n if (Array.isArray(maxCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.maxCount, maxCount)\n }\n const minCount = NodeDefs.getMinCount(nodeDef)\n if (Array.isArray(minCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.minCount, minCount)\n }\n // file name expression\n if (NodeDefs.getType(nodeDef) === NodeDefType.file) {\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (fileNameExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.fileName, [\n NodeDefExpressionFactory.createInstance({ expression: fileNameExpression }),\n ])\n }\n }\n if (NodeDefs.isEntity(nodeDef)) {\n const enumeratingItemsExpression = NodeDefs.getEnumeratingItemsExpression(nodeDef as ArenaNodeDefEntity)\n if (enumeratingItemsExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.enumeratingItems, [\n NodeDefExpressionFactory.createInstance({ expression: enumeratingItemsExpression }),\n ])\n }\n }\n // parent code\n if (NodeDefs.getType(nodeDef) === NodeDefType.code) {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef as ArenaNodeDefCode)\n if (parentCodeDefUuid) {\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type: SurveyDependencyType.parentCode,\n nodeDefUuid: parentCodeDefUuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n }\n if (sideEffect) {\n survey.dependencyGraph = graphsUpdated\n return survey\n }\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n// DELETE\n\nconst _removeNodeDefDependenciesOfType = (params: {\n graphs: ArenaSurveyDependencyGraph\n dependencyType: SurveyDependencyType\n nodeDefUuid: string\n}): ArenaSurveyDependencyGraph => {\n const { graphs, nodeDefUuid, dependencyType } = params\n\n const graphsUpdated = { ...graphs }\n let graphUpdated = { ...graphsUpdated[dependencyType] }\n // dissoc nodeDefUuid dependency as dependent\n graphUpdated = Objects.dissoc({ obj: graphUpdated, prop: nodeDefUuid })\n\n if (dependencyType !== SurveyDependencyType.onUpdate) {\n // dissoc nodeDefUuid dependency from sources (if any)\n for (const [key, dependentUuids] of Object.entries(graphUpdated)) {\n graphUpdated[key] = Arrays.removeItem(nodeDefUuid)(dependentUuids as string[])\n }\n }\n\n graphsUpdated[dependencyType] = graphUpdated\n return graphsUpdated\n}\n\nexport const removeNodeDefDependencies = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaSurvey => {\n const { survey, nodeDefUuid, dependencyType = null } = params\n const graphs = getDependencyGraph(survey)\n const dependencyTypes = dependencyType ? [dependencyType] : (Object.keys(graphs) as SurveyDependencyType[])\n const graphsUpdated = dependencyTypes.reduce(\n (dependencyGraphAcc, type) =>\n _removeNodeDefDependenciesOfType({ graphs: dependencyGraphAcc, dependencyType: type, nodeDefUuid }),\n graphs\n )\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n/**\n * Builds the dependency graph of the survey.\n *\n * @param survey - The survey.\n * @returns A copy of the survey with the dependency graph (the survey passed in is not modified).\n */\nexport const buildAndAssocDependencyGraph = async (survey: ArenaSurvey): Promise<ArenaSurvey> => {\n // the new graph is built from scratch with side effect (to avoid re-creating objects): it belongs only to the copy of the survey\n const sideEffect = true\n\n // add dependencies for every node def\n let surveyUpdated: ArenaSurvey = { ...survey, dependencyGraph: newDependencyGraph() }\n for (const nodeDef of SurveyNodeDefs.getNodeDefsArray(survey)) {\n // sequential: each iteration updates the survey\n surveyUpdated = await addNodeDefDependencies({ nodeDef, survey: surveyUpdated, sideEffect }) // NOSONAR\n }\n return surveyUpdated\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../../../src/survey/surveys/dependencies.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,cAAc,MAAM,YAAY,CAAA;AAC5C,OAAO,EAML,QAAQ,EACR,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAA;AAEhG,OAAO,EAA2C,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAEhE,6GAA6G;AAC7G,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAuB;IAC3D,oBAAoB,CAAC,QAAQ;IAC7B,oBAAoB,CAAC,OAAO;CAC7B,CAAC,CAAA;AAEF,MAAM,oCAAoC,GAAgC;IACxE,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,CAAC,wBAAwB,CAAC;IAC3D,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,CAAC;CACrF,CAAA;AAED,MAAM,+BAA+B,GAAG;IACtC,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,IAAI;IACpC,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,IAAI;IACvC,CAAC,oBAAoB,CAAC,aAAa,CAAC,EAAE,IAAI;IAC1C,CAAC,oBAAoB,CAAC,QAAQ,CA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C,MAAM,CAAC,EAAE,CAAC;QAC9D,gDAAgD;QAChD,aAAa,GAAG,MAAM,sBAAsB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAA,CAAC,UAAU;IACzG,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA,CAAA","sourcesContent":["import * as SurveyNodeDefs from './nodeDefs'\nimport {\n ArenaAnyNodeDef,\n ArenaNodeDefCode,\n ArenaNodeDefEntity,\n ArenaNodeDefExpression,\n ArenaNodeDefFile,\n NodeDefs,\n NodeDefType,\n} from '../../nodeDef'\nimport { NodeDefExpressionEvaluator } from '../../nodeDefExpressionEvaluator'\nimport { findFunctionCallNames } from '../../expression/javascript/parser/expressionNodesFinder'\n\nimport { ArenaSurvey, ArenaSurveyDependencyGraph, SurveyDependencyType } from '../survey'\nimport { Arrays, Objects } from '../../utils'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\n\n// dependency types stored as dictionary of booleans (node def uuid => true), not as dependents of a node def\nconst booleanDependencyTypes = new Set<SurveyDependencyType>([\n SurveyDependencyType.onUpdate,\n SurveyDependencyType.appInfo,\n])\n\nconst functionNamesByBooleanDependencyType: { [key: string]: string[] } = {\n [SurveyDependencyType.onUpdate]: ['recordDateLastModified'],\n [SurveyDependencyType.appInfo]: ['appId', 'appIdLabel', 'appPlatform', 'appVersion'],\n}\n\nconst isContextParentByDependencyType = {\n [SurveyDependencyType.appInfo]: true,\n [SurveyDependencyType.applicable]: true,\n [SurveyDependencyType.defaultValues]: true,\n [SurveyDependencyType.editable]: true,\n [SurveyDependencyType.enumeratingItems]: true,\n [SurveyDependencyType.fileName]: true,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: true,\n [SurveyDependencyType.minCount]: true,\n [SurveyDependencyType.nodeDates]: true,\n [SurveyDependencyType.onUpdate]: true,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: true,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: true,\n}\n\nconst selfReferenceAllowedByDependencyType = {\n [SurveyDependencyType.appInfo]: false,\n [SurveyDependencyType.applicable]: false,\n [SurveyDependencyType.defaultValues]: false,\n [SurveyDependencyType.editable]: false,\n [SurveyDependencyType.enumeratingItems]: false,\n [SurveyDependencyType.fileName]: false,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: false,\n [SurveyDependencyType.minCount]: false,\n [SurveyDependencyType.nodeDates]: false,\n [SurveyDependencyType.onUpdate]: false,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: false,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: false,\n}\n\nconst newDependencyGraph = () => ({\n [SurveyDependencyType.appInfo]: {},\n [SurveyDependencyType.applicable]: {},\n [SurveyDependencyType.defaultValues]: {},\n [SurveyDependencyType.editable]: {},\n [SurveyDependencyType.enumeratingItems]: {},\n [SurveyDependencyType.fileName]: {},\n [SurveyDependencyType.formula]: {},\n [SurveyDependencyType.maxCount]: {},\n [SurveyDependencyType.minCount]: {},\n [SurveyDependencyType.nodeDates]: {},\n [SurveyDependencyType.onUpdate]: {},\n [SurveyDependencyType.parentCode]: {},\n [SurveyDependencyType.required]: {},\n [SurveyDependencyType.validations]: {},\n [SurveyDependencyType.visible]: {},\n})\n\nconst getDependencyGraph = (survey: ArenaSurvey): ArenaSurveyDependencyGraph =>\n survey.dependencyGraph ?? newDependencyGraph()\n\nconst getDependencies = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n}): Array<string> => {\n const { graphs, type, nodeDefUuid } = params\n return booleanDependencyTypes.has(type) ? [] : ((graphs?.[type]?.[nodeDefUuid] ?? []) as string[])\n}\n\nexport const getNodeDefDependents = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaAnyNodeDef[] => {\n const { survey, nodeDefUuid, dependencyType } = params\n const dependencyGraph = getDependencyGraph(survey)\n\n const dependentUuids = new Set<string>()\n\n const dependencyTypes: SurveyDependencyType[] = dependencyType\n ? [dependencyType]\n : Object.values(SurveyDependencyType)\n\n for (const depType of dependencyTypes) {\n const dependentUuidsTemp = getDependencies({ graphs: dependencyGraph, type: depType, nodeDefUuid })\n for (const dependentUuid of dependentUuidsTemp) {\n dependentUuids.add(dependentUuid)\n }\n }\n return dependentUuids.size > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: [...dependentUuids] }) : []\n}\n\nconst getBooleanDependencyTypeDependents = (params: {\n survey: ArenaSurvey\n dependencyType: SurveyDependencyType\n}): ArenaAnyNodeDef[] => {\n const { survey, dependencyType } = params\n const dependencyGraph = getDependencyGraph(survey)\n const sourceDefUuids = Object.keys(dependencyGraph[dependencyType] ?? {})\n return sourceDefUuids.length > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: sourceDefUuids }) : []\n}\n\n/**\n * Returns the node defs to be evaluated again on every record update (their expressions use e.g. recordDateLastModified).\n */\nexport const getOnUpdateDependents = (params: { survey: ArenaSurvey }): ArenaAnyNodeDef[] =>\n getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.onUpdate })\n\n/**\n * Returns the node defs to be evaluated again when a record is updated with a different app\n * (their expressions use the app info functions: appId, appIdLabel, appPlatform, appVersion).\n */\nexport const getAppInfoDependents = (params: { survey: ArenaSurvey }): ArenaAnyNodeDef[] =>\n getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.appInfo })\n\n// UPDATE\n\nconst addDependency = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n nodeDefDepUuid: string\n sideEffect: boolean\n}): ArenaSurveyDependencyGraph => {\n const { graphs, type, nodeDefUuid, nodeDefDepUuid, sideEffect = false } = params\n const deps = getDependencies({ graphs, type, nodeDefUuid })\n // dependencies of a node def can be added again (e.g. when it is updated): keep each dependent only once\n if (deps.includes(nodeDefDepUuid)) return graphs\n const depsUpdated = Arrays.addItem(nodeDefDepUuid, { sideEffect })(deps)\n return Objects.assocPath({ obj: graphs, path: [type, nodeDefUuid], value: depsUpdated, sideEffect })\n}\n\nconst addDependencies = async (params: {\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n type: SurveyDependencyType\n graphs: ArenaSurveyDependencyGraph\n expressions: ArenaNodeDefExpression[]\n sideEffect?: boolean\n}): Promise<ArenaSurveyDependencyGraph> => {\n const { survey, nodeDef, type, expressions, graphs: graphsParam, sideEffect = false } = params\n\n if (!expressions || expressions.length === 0) return graphsParam\n\n let graphsUpdated = sideEffect ? graphsParam : { ...graphsParam }\n\n const isContextParent = isContextParentByDependencyType[type]\n const selfReferenceAllowed = selfReferenceAllowedByDependencyType[type]\n\n const referencedNodeDefUuids = new Set<string>()\n const nodeDateReferencedNodeDefUuids = new Set<string>()\n\n const findReferencedNodeDefs = async (expression: string | undefined): Promise<void> => {\n if (!expression) return\n\n const result = await new NodeDefExpressionEvaluator().findReferencedNodeDefUuidsWithNodeDates({\n expression,\n survey,\n nodeDef,\n isContextParent,\n selfReferenceAllowed,\n })\n result.referencedNodeDefUuids.forEach((uuid) => referencedNodeDefUuids.add(uuid))\n result.nodeDateReferencedNodeDefUuids.forEach((uuid) => nodeDateReferencedNodeDefUuids.add(uuid))\n }\n\n await Promise.all(\n expressions.flatMap((nodeDefExpr) => [\n findReferencedNodeDefs(nodeDefExpr.expression),\n findReferencedNodeDefs(nodeDefExpr.applyIf),\n ])\n )\n\n const addGraphDependencies = (dependencyType: SurveyDependencyType, sourceDefUuids: Set<string>): void => {\n for (const sourceDefUuid of sourceDefUuids) {\n // the referenced node def must exist\n const sourceDef = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid: sourceDefUuid })\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type: dependencyType,\n nodeDefUuid: sourceDef.uuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n }\n addGraphDependencies(type, referencedNodeDefUuids)\n // entities whose nodes dates are used in the expressions (nodeDateCreated, nodeDateModified)\n addGraphDependencies(SurveyDependencyType.nodeDates, nodeDateReferencedNodeDefUuids)\n\n return graphsUpdated\n}\n\nexport const addNodeDefDependencies = async (params: {\n nodeDef: ArenaAnyNodeDef\n survey: ArenaSurvey\n sideEffect?: boolean\n}): Promise<ArenaSurvey> => {\n const { nodeDef, survey, sideEffect = false } = params\n const graphs = getDependencyGraph(survey)\n let graphsUpdated = sideEffect ? graphs : { ...graphs }\n\n const _addDependencies = async (type: SurveyDependencyType, expressions: ArenaNodeDefExpression[]) => {\n let _graphUpdated = await addDependencies({\n survey,\n nodeDef,\n type,\n expressions,\n graphs: graphsUpdated,\n sideEffect,\n })\n // add boolean (onUpdate, appInfo) dependencies\n const calledFunctionNames = new Set(\n expressions.flatMap((expression) => [\n ...findFunctionCallNames(expression.expression),\n ...findFunctionCallNames(expression.applyIf),\n ])\n )\n for (const [booleanDependencyType, functionNames] of Object.entries(functionNamesByBooleanDependencyType)) {\n if (functionNames.some((functionName) => calledFunctionNames.has(functionName))) {\n _graphUpdated = Objects.assocPath({\n obj: _graphUpdated,\n path: [booleanDependencyType, nodeDef.uuid],\n value: true,\n sideEffect,\n })\n }\n }\n return _graphUpdated\n }\n graphsUpdated = await _addDependencies(SurveyDependencyType.applicable, NodeDefs.getApplicable(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.defaultValues, NodeDefs.getDefaultValues(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.editable, NodeDefs.getEditableIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.required, NodeDefs.getRequiredIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.validations, NodeDefs.getValidationsExpressions(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.visible, NodeDefs.getVisibleIf(nodeDef))\n const maxCount = NodeDefs.getMaxCount(nodeDef)\n if (Array.isArray(maxCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.maxCount, maxCount)\n }\n const minCount = NodeDefs.getMinCount(nodeDef)\n if (Array.isArray(minCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.minCount, minCount)\n }\n // file name expression\n if (NodeDefs.getType(nodeDef) === NodeDefType.file) {\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (fileNameExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.fileName, [\n NodeDefExpressionFactory.createInstance({ expression: fileNameExpression }),\n ])\n }\n }\n if (NodeDefs.isEntity(nodeDef)) {\n const enumeratingItemsExpression = NodeDefs.getEnumeratingItemsExpression(nodeDef as ArenaNodeDefEntity)\n if (enumeratingItemsExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.enumeratingItems, [\n NodeDefExpressionFactory.createInstance({ expression: enumeratingItemsExpression }),\n ])\n }\n }\n // parent code\n if (NodeDefs.getType(nodeDef) === NodeDefType.code) {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef as ArenaNodeDefCode)\n if (parentCodeDefUuid) {\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type: SurveyDependencyType.parentCode,\n nodeDefUuid: parentCodeDefUuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n }\n if (sideEffect) {\n survey.dependencyGraph = graphsUpdated\n return survey\n }\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n// DELETE\n\nconst _removeNodeDefDependenciesOfType = (params: {\n graphs: ArenaSurveyDependencyGraph\n dependencyType: SurveyDependencyType\n nodeDefUuid: string\n}): ArenaSurveyDependencyGraph => {\n const { graphs, nodeDefUuid, dependencyType } = params\n\n const graphsUpdated = { ...graphs }\n let graphUpdated = { ...graphsUpdated[dependencyType] }\n // dissoc nodeDefUuid dependency as dependent\n graphUpdated = Objects.dissoc({ obj: graphUpdated, prop: nodeDefUuid })\n\n if (!booleanDependencyTypes.has(dependencyType)) {\n // dissoc nodeDefUuid dependency from sources (if any)\n for (const [key, dependentUuids] of Object.entries(graphUpdated)) {\n graphUpdated[key] = Arrays.removeItem(nodeDefUuid)(dependentUuids as string[])\n }\n }\n\n graphsUpdated[dependencyType] = graphUpdated\n return graphsUpdated\n}\n\nexport const removeNodeDefDependencies = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaSurvey => {\n const { survey, nodeDefUuid, dependencyType = null } = params\n const graphs = getDependencyGraph(survey)\n const dependencyTypes = dependencyType ? [dependencyType] : (Object.keys(graphs) as SurveyDependencyType[])\n const graphsUpdated = dependencyTypes.reduce(\n (dependencyGraphAcc, type) =>\n _removeNodeDefDependenciesOfType({ graphs: dependencyGraphAcc, dependencyType: type, nodeDefUuid }),\n graphs\n )\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n/**\n * Builds the dependency graph of the survey.\n *\n * @param survey - The survey.\n * @returns A copy of the survey with the dependency graph (the survey passed in is not modified).\n */\nexport const buildAndAssocDependencyGraph = async (survey: ArenaSurvey): Promise<ArenaSurvey> => {\n // the new graph is built from scratch with side effect (to avoid re-creating objects): it belongs only to the copy of the survey\n const sideEffect = true\n\n // add dependencies for every node def\n let surveyUpdated: ArenaSurvey = { ...survey, dependencyGraph: newDependencyGraph() }\n for (const nodeDef of SurveyNodeDefs.getNodeDefsArray(survey)) {\n // sequential: each iteration updates the survey\n surveyUpdated = await addNodeDefDependencies({ nodeDef, survey: surveyUpdated, sideEffect }) // NOSONAR\n }\n return surveyUpdated\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { addNodeDefDependencies, buildAndAssocDependencyGraph, getNodeDefDependents, getOnUpdateDependents, removeNodeDefDependencies, } from './dependencies';
|
|
1
|
+
import { addNodeDefDependencies, buildAndAssocDependencyGraph, getNodeDefDependents, getOnUpdateDependents, getAppInfoDependents, removeNodeDefDependencies, } from './dependencies';
|
|
2
2
|
import { addNodeDefToIndex, buildAndAssocNodeDefsIndex, deleteNodeDefIndex, findNodeDefByName, findNodeDefByUuid, findNodeDefsByUuids, getDependentCodeAttributeDefs, getDependentEnumeratedEntityDefs, getDescendantsInSingleEntities, getNodeDefsArray, getNodeDefAncestorCodes, getNodeDefAncestorMultipleEntity, getNodeDefByName, getNodeDefByUuid, getNodeDefCategoryLevelIndex, getNodeDefChildren, getNodeDefChildrenSorted, getNodeDefEnumerator, getNodeDefKeys, getNodeDefParent, getNodeDefParentCode, getNodeDefRoot, getNodeDefSource, getNodeDefsByUuids, getNodeDefsIncludedInMultipleEntitySummary, getQualifierDefs, getRootKeys, isNodeDefAncestor, isNodeDefEnumerator, isNodeDefParentCode, updateNodeDefUuidByNameIndex, visitAncestorsAndSelfNodeDef, visitDescendantsAndSelfNodeDef, visitNodeDefs, } from './nodeDefs';
|
|
3
3
|
import { getCategoryItemByCodePaths, getCategoryItemByUuid, getCategoryItemUuidByCode, getCategoryItems, getCategoryItemsByNodeDef, getCategoryItemsInLevel, getTaxonByCode, getTaxonByUuid, getTaxonVernacularNameUuid, includesTaxonVernacularName, } from './refsData';
|
|
4
4
|
import { getCategoryByName, getCategoryByUuid, getCycleKeys, getDefaultCycleKey, getDefaultLanguage, getDescription, getFieldManualLink, getLabel, getLabelOrName, getLanguages, getLastCycleKey, getName, getSRSByCode, getSRSIndex, getAreasOfInterest, getAreaOfInterestByName, getSRSs, getTaxonomyByName, getTaxonomyByUuid, getAuthGroups, getAuthGroupAdmin, isKeepNonApplicableValues, } from './surveysGetters';
|
|
@@ -74,6 +74,7 @@ export const Surveys = {
|
|
|
74
74
|
addNodeDefDependencies,
|
|
75
75
|
getNodeDefDependents,
|
|
76
76
|
getOnUpdateDependents,
|
|
77
|
+
getAppInfoDependents,
|
|
77
78
|
removeNodeDefDependencies,
|
|
78
79
|
// index
|
|
79
80
|
buildAndAssocNodeDefsIndex,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/survey/surveys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,EACpB,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,6BAA6B,EAC7B,gCAAgC,EAChC,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EACvB,gCAAgC,EAChC,gBAAgB,EAChB,gBAAgB,EAChB,4BAA4B,EAC5B,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,0CAA0C,EAC1C,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,4BAA4B,EAC5B,4BAA4B,EAC5B,8BAA8B,EAC9B,aAAa,GACd,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,yBAAyB,EACzB,gBAAgB,EAChB,yBAAyB,EACzB,uBAAuB,EACvB,cAAc,EACd,cAAc,EACd,0BAA0B,EAC1B,2BAA2B,GAC5B,MAAM,YAAY,CAAA;AAEnB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,eAAe,EACf,OAAO,EACP,YAAY,EACZ,WAAW,EACX,kBAAkB,EAClB,uBAAuB,EACvB,OAAO,EACP,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EACL,WAAW,EACX,uCAAuC,EACvC,sCAA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5B,kBAAkB;IAElB,WAAW;IACX,WAAW;IACX,uCAAuC;IACvC,sCAAsC;IACtC,iBAAiB;IACjB,gCAAgC;IAChC,gCAAgC;IAChC,0CAA0C;IAC1C,iCAAiC;IAEjC,QAAQ;IACR,2BAA2B;IAC3B,2CAA2C;CAC5C,CAAA","sourcesContent":["import {\n addNodeDefDependencies,\n buildAndAssocDependencyGraph,\n getNodeDefDependents,\n getOnUpdateDependents,\n removeNodeDefDependencies,\n} from './dependencies'\n\nimport {\n addNodeDefToIndex,\n buildAndAssocNodeDefsIndex,\n deleteNodeDefIndex,\n findNodeDefByName,\n findNodeDefByUuid,\n findNodeDefsByUuids,\n getDependentCodeAttributeDefs,\n getDependentEnumeratedEntityDefs,\n getDescendantsInSingleEntities,\n getNodeDefsArray,\n getNodeDefAncestorCodes,\n getNodeDefAncestorMultipleEntity,\n getNodeDefByName,\n getNodeDefByUuid,\n getNodeDefCategoryLevelIndex,\n getNodeDefChildren,\n getNodeDefChildrenSorted,\n getNodeDefEnumerator,\n getNodeDefKeys,\n getNodeDefParent,\n getNodeDefParentCode,\n getNodeDefRoot,\n getNodeDefSource,\n getNodeDefsByUuids,\n getNodeDefsIncludedInMultipleEntitySummary,\n getQualifierDefs,\n getRootKeys,\n isNodeDefAncestor,\n isNodeDefEnumerator,\n isNodeDefParentCode,\n updateNodeDefUuidByNameIndex,\n visitAncestorsAndSelfNodeDef,\n visitDescendantsAndSelfNodeDef,\n visitNodeDefs,\n} from './nodeDefs'\n\nimport {\n getCategoryItemByCodePaths,\n getCategoryItemByUuid,\n getCategoryItemUuidByCode,\n getCategoryItems,\n getCategoryItemsByNodeDef,\n getCategoryItemsInLevel,\n getTaxonByCode,\n getTaxonByUuid,\n getTaxonVernacularNameUuid,\n includesTaxonVernacularName,\n} from './refsData'\n\nimport {\n getCategoryByName,\n getCategoryByUuid,\n getCycleKeys,\n getDefaultCycleKey,\n getDefaultLanguage,\n getDescription,\n getFieldManualLink,\n getLabel,\n getLabelOrName,\n getLanguages,\n getLastCycleKey,\n getName,\n getSRSByCode,\n getSRSIndex,\n getAreasOfInterest,\n getAreaOfInterestByName,\n getSRSs,\n getTaxonomyByName,\n getTaxonomyByUuid,\n getAuthGroups,\n getAuthGroupAdmin,\n isKeepNonApplicableValues,\n} from './surveysGetters'\n\nimport {\n getSecurity,\n isDataAnalystViewNotOwnedRecordsAllowed,\n isDataEditorViewNotOwnedRecordsAllowed,\n isRecordsDownloadInMobileAllowed,\n isRecordsMergeWithSameKeysAllowed,\n isRecordsUploadFromMobileAllowed,\n isRecordsWithErrorsUploadFromMobileAllowed,\n isVisibleInMobile,\n} from './surveyGettersSecurity'\n\nimport { findApplicableDependentEnumeratedEntityDefs, getEnumeratingCategoryItems } from './surveysUtils'\n\nexport const Surveys = {\n getName,\n getLanguages,\n getDefaultLanguage,\n getLabel,\n getLabelOrName,\n getDescription,\n getFieldManualLink,\n getCycleKeys,\n getLastCycleKey,\n getDefaultCycleKey,\n getSRSs,\n getSRSByCode,\n getSRSIndex,\n getAreasOfInterest,\n getAreaOfInterestByName,\n getCategoryByName,\n getCategoryByUuid,\n getTaxonomyByName,\n getTaxonomyByUuid,\n getAuthGroups,\n getAuthGroupAdmin,\n isKeepNonApplicableValues,\n\n findNodeDefByName,\n findNodeDefByUuid,\n findNodeDefsByUuids,\n getNodeDefsArray,\n getNodeDefByName,\n getNodeDefsByUuids,\n getNodeDefByUuid,\n getNodeDefChildren,\n getNodeDefChildrenSorted,\n getNodeDefParent,\n getNodeDefAncestorMultipleEntity,\n getNodeDefRoot,\n getNodeDefSource,\n isNodeDefAncestor,\n getNodeDefKeys,\n getRootKeys,\n getNodeDefsIncludedInMultipleEntitySummary,\n getQualifierDefs,\n isNodeDefEnumerator,\n getNodeDefEnumerator,\n visitAncestorsAndSelfNodeDef,\n visitDescendantsAndSelfNodeDef,\n visitNodeDefs,\n getDescendantsInSingleEntities,\n\n // ref data\n getCategoryItemByCodePaths,\n getCategoryItemByUuid,\n getCategoryItemUuidByCode,\n getCategoryItems,\n getCategoryItemsByNodeDef,\n getCategoryItemsInLevel,\n getTaxonByCode,\n getTaxonByUuid,\n getTaxonVernacularNameUuid,\n includesTaxonVernacularName,\n\n // node def code\n getNodeDefParentCode,\n getNodeDefAncestorCodes,\n isNodeDefParentCode,\n getNodeDefCategoryLevelIndex,\n getDependentCodeAttributeDefs,\n getDependentEnumeratedEntityDefs,\n\n // dependencies\n buildAndAssocDependencyGraph,\n addNodeDefDependencies,\n getNodeDefDependents,\n getOnUpdateDependents,\n removeNodeDefDependencies,\n\n // index\n buildAndAssocNodeDefsIndex,\n addNodeDefToIndex,\n updateNodeDefUuidByNameIndex,\n deleteNodeDefIndex,\n\n // security\n getSecurity,\n isDataAnalystViewNotOwnedRecordsAllowed,\n isDataEditorViewNotOwnedRecordsAllowed,\n isVisibleInMobile,\n isRecordsDownloadInMobileAllowed,\n isRecordsUploadFromMobileAllowed,\n isRecordsWithErrorsUploadFromMobileAllowed,\n isRecordsMergeWithSameKeysAllowed,\n\n // utils\n getEnumeratingCategoryItems,\n findApplicableDependentEnumeratedEntityDefs,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/survey/surveys/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,6BAA6B,EAC7B,gCAAgC,EAChC,8BAA8B,EAC9B,gBAAgB,EAChB,uBAAuB,EACvB,gCAAgC,EAChC,gBAAgB,EAChB,gBAAgB,EAChB,4BAA4B,EAC5B,kBAAkB,EAClB,wBAAwB,EACxB,oBAAoB,EACpB,cAAc,EACd,gBAAgB,EAChB,oBAAoB,EACpB,cAAc,EACd,gBAA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BAAiB;IACjB,iBAAiB;IACjB,mBAAmB;IACnB,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,gBAAgB;IAChB,kBAAkB;IAClB,wBAAwB;IACxB,gBAAgB;IAChB,gCAAgC;IAChC,cAAc;IACd,gBAAgB;IAChB,iBAAiB;IACjB,cAAc;IACd,WAAW;IACX,0CAA0C;IAC1C,gBAAgB;IAChB,mBAAmB;IACnB,oBAAoB;IACpB,4BAA4B;IAC5B,8BAA8B;IAC9B,aAAa;IACb,8BAA8B;IAE9B,WAAW;IACX,0BAA0B;IAC1B,qBAAqB;IACrB,yBAAyB;IACzB,gBAAgB;IAChB,yBAAyB;IACzB,uBAAuB;IACvB,cAAc;IACd,cAAc;IACd,0BAA0B;IAC1B,2BAA2B;IAE3B,gBAAgB;IAChB,oBAAoB;IACpB,uBAAuB;IACvB,mBAAmB;IACnB,4BAA4B;IAC5B,6BAA6B;IAC7B,gCAAgC;IAEhC,eAAe;IACf,4BAA4B;IAC5B,sBAAsB;IACtB,oBAAoB;IACpB,qBAAqB;IACrB,oBAAoB;IACpB,yBAAyB;IAEzB,QAAQ;IACR,0BAA0B;IAC1B,iBAAiB;IACjB,4BAA4B;IAC5B,kBAAkB;IAElB,WAAW;IACX,WAAW;IACX,uCAAuC;IACvC,sCAAsC;IACtC,iBAAiB;IACjB,gCAAgC;IAChC,gCAAgC;IAChC,0CAA0C;IAC1C,iCAAiC;IAEjC,QAAQ;IACR,2BAA2B;IAC3B,2CAA2C;CAC5C,CAAA","sourcesContent":["import {\n addNodeDefDependencies,\n buildAndAssocDependencyGraph,\n getNodeDefDependents,\n getOnUpdateDependents,\n getAppInfoDependents,\n removeNodeDefDependencies,\n} from './dependencies'\n\nimport {\n addNodeDefToIndex,\n buildAndAssocNodeDefsIndex,\n deleteNodeDefIndex,\n findNodeDefByName,\n findNodeDefByUuid,\n findNodeDefsByUuids,\n getDependentCodeAttributeDefs,\n getDependentEnumeratedEntityDefs,\n getDescendantsInSingleEntities,\n getNodeDefsArray,\n getNodeDefAncestorCodes,\n getNodeDefAncestorMultipleEntity,\n getNodeDefByName,\n getNodeDefByUuid,\n getNodeDefCategoryLevelIndex,\n getNodeDefChildren,\n getNodeDefChildrenSorted,\n getNodeDefEnumerator,\n getNodeDefKeys,\n getNodeDefParent,\n getNodeDefParentCode,\n getNodeDefRoot,\n getNodeDefSource,\n getNodeDefsByUuids,\n getNodeDefsIncludedInMultipleEntitySummary,\n getQualifierDefs,\n getRootKeys,\n isNodeDefAncestor,\n isNodeDefEnumerator,\n isNodeDefParentCode,\n updateNodeDefUuidByNameIndex,\n visitAncestorsAndSelfNodeDef,\n visitDescendantsAndSelfNodeDef,\n visitNodeDefs,\n} from './nodeDefs'\n\nimport {\n getCategoryItemByCodePaths,\n getCategoryItemByUuid,\n getCategoryItemUuidByCode,\n getCategoryItems,\n getCategoryItemsByNodeDef,\n getCategoryItemsInLevel,\n getTaxonByCode,\n getTaxonByUuid,\n getTaxonVernacularNameUuid,\n includesTaxonVernacularName,\n} from './refsData'\n\nimport {\n getCategoryByName,\n getCategoryByUuid,\n getCycleKeys,\n getDefaultCycleKey,\n getDefaultLanguage,\n getDescription,\n getFieldManualLink,\n getLabel,\n getLabelOrName,\n getLanguages,\n getLastCycleKey,\n getName,\n getSRSByCode,\n getSRSIndex,\n getAreasOfInterest,\n getAreaOfInterestByName,\n getSRSs,\n getTaxonomyByName,\n getTaxonomyByUuid,\n getAuthGroups,\n getAuthGroupAdmin,\n isKeepNonApplicableValues,\n} from './surveysGetters'\n\nimport {\n getSecurity,\n isDataAnalystViewNotOwnedRecordsAllowed,\n isDataEditorViewNotOwnedRecordsAllowed,\n isRecordsDownloadInMobileAllowed,\n isRecordsMergeWithSameKeysAllowed,\n isRecordsUploadFromMobileAllowed,\n isRecordsWithErrorsUploadFromMobileAllowed,\n isVisibleInMobile,\n} from './surveyGettersSecurity'\n\nimport { findApplicableDependentEnumeratedEntityDefs, getEnumeratingCategoryItems } from './surveysUtils'\n\nexport const Surveys = {\n getName,\n getLanguages,\n getDefaultLanguage,\n getLabel,\n getLabelOrName,\n getDescription,\n getFieldManualLink,\n getCycleKeys,\n getLastCycleKey,\n getDefaultCycleKey,\n getSRSs,\n getSRSByCode,\n getSRSIndex,\n getAreasOfInterest,\n getAreaOfInterestByName,\n getCategoryByName,\n getCategoryByUuid,\n getTaxonomyByName,\n getTaxonomyByUuid,\n getAuthGroups,\n getAuthGroupAdmin,\n isKeepNonApplicableValues,\n\n findNodeDefByName,\n findNodeDefByUuid,\n findNodeDefsByUuids,\n getNodeDefsArray,\n getNodeDefByName,\n getNodeDefsByUuids,\n getNodeDefByUuid,\n getNodeDefChildren,\n getNodeDefChildrenSorted,\n getNodeDefParent,\n getNodeDefAncestorMultipleEntity,\n getNodeDefRoot,\n getNodeDefSource,\n isNodeDefAncestor,\n getNodeDefKeys,\n getRootKeys,\n getNodeDefsIncludedInMultipleEntitySummary,\n getQualifierDefs,\n isNodeDefEnumerator,\n getNodeDefEnumerator,\n visitAncestorsAndSelfNodeDef,\n visitDescendantsAndSelfNodeDef,\n visitNodeDefs,\n getDescendantsInSingleEntities,\n\n // ref data\n getCategoryItemByCodePaths,\n getCategoryItemByUuid,\n getCategoryItemUuidByCode,\n getCategoryItems,\n getCategoryItemsByNodeDef,\n getCategoryItemsInLevel,\n getTaxonByCode,\n getTaxonByUuid,\n getTaxonVernacularNameUuid,\n includesTaxonVernacularName,\n\n // node def code\n getNodeDefParentCode,\n getNodeDefAncestorCodes,\n isNodeDefParentCode,\n getNodeDefCategoryLevelIndex,\n getDependentCodeAttributeDefs,\n getDependentEnumeratedEntityDefs,\n\n // dependencies\n buildAndAssocDependencyGraph,\n addNodeDefDependencies,\n getNodeDefDependents,\n getOnUpdateDependents,\n getAppInfoDependents,\n removeNodeDefDependencies,\n\n // index\n buildAndAssocNodeDefsIndex,\n addNodeDefToIndex,\n updateNodeDefUuidByNameIndex,\n deleteNodeDefIndex,\n\n // security\n getSecurity,\n isDataAnalystViewNotOwnedRecordsAllowed,\n isDataEditorViewNotOwnedRecordsAllowed,\n isVisibleInMobile,\n isRecordsDownloadInMobileAllowed,\n isRecordsUploadFromMobileAllowed,\n isRecordsWithErrorsUploadFromMobileAllowed,\n isRecordsMergeWithSameKeysAllowed,\n\n // utils\n getEnumeratingCategoryItems,\n findApplicableDependentEnumeratedEntityDefs,\n}\n"]}
|
|
@@ -2,6 +2,8 @@ import { isEqual as _isEqual } from 'es-toolkit/predicate';
|
|
|
2
2
|
/**
|
|
3
3
|
* Performs a deep comparison between two values to determine if they are equivalent
|
|
4
4
|
* (same semantics as lodash isEqual).
|
|
5
|
+
* Params typed as any: with unknown, when passed as an equality function (e.g. to react-redux useSelector),
|
|
6
|
+
* the compared type would be inferred as unknown.
|
|
5
7
|
*/
|
|
6
8
|
export const isEqual = (value, other) => _isEqual(value, other);
|
|
7
9
|
//# sourceMappingURL=isEqual.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isEqual.js","sourceRoot":"","sources":["../../../../src/utils/_objects/isEqual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE1D
|
|
1
|
+
{"version":3,"file":"isEqual.js","sourceRoot":"","sources":["../../../../src/utils/_objects/isEqual.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE1D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAAU,EAAE,KAAU,EAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA","sourcesContent":["import { isEqual as _isEqual } from 'es-toolkit/predicate'\n\n/**\n * Performs a deep comparison between two values to determine if they are equivalent\n * (same semantics as lodash isEqual).\n * Params typed as any: with unknown, when passed as an equality function (e.g. to react-redux useSelector),\n * the compared type would be inferred as unknown.\n */\nexport const isEqual = (value: any, other: any): boolean => _isEqual(value, other)\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache with a maximum number of entries: when it is full, adding an entry evicts the least recently used one.
|
|
3
|
+
* To be used for module-level caches, which would otherwise grow for the whole life of the process.
|
|
4
|
+
*/
|
|
5
|
+
export class LRUCache {
|
|
6
|
+
constructor(maxSize) {
|
|
7
|
+
this.entries = new Map();
|
|
8
|
+
if (!Number.isInteger(maxSize) || maxSize <= 0)
|
|
9
|
+
throw new Error(`Invalid LRU cache max size: ${maxSize}`);
|
|
10
|
+
this.maxSize = maxSize;
|
|
11
|
+
}
|
|
12
|
+
get size() {
|
|
13
|
+
return this.entries.size;
|
|
14
|
+
}
|
|
15
|
+
has(key) {
|
|
16
|
+
return this.entries.has(key);
|
|
17
|
+
}
|
|
18
|
+
get(key) {
|
|
19
|
+
if (!this.entries.has(key))
|
|
20
|
+
return undefined;
|
|
21
|
+
const value = this.entries.get(key);
|
|
22
|
+
// move the entry to the end (most recently used): Map keeps the insertion order
|
|
23
|
+
this.entries.delete(key);
|
|
24
|
+
this.entries.set(key, value);
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
set(key, value) {
|
|
28
|
+
this.entries.delete(key);
|
|
29
|
+
if (this.entries.size >= this.maxSize) {
|
|
30
|
+
const leastRecentlyUsedKey = this.entries.keys().next().value;
|
|
31
|
+
this.entries.delete(leastRecentlyUsedKey);
|
|
32
|
+
}
|
|
33
|
+
this.entries.set(key, value);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Returns the cached value of the specified key, computing and caching it if missing.
|
|
38
|
+
*/
|
|
39
|
+
getOrCompute(key, compute) {
|
|
40
|
+
if (this.entries.has(key))
|
|
41
|
+
return this.get(key);
|
|
42
|
+
const value = compute(key);
|
|
43
|
+
this.set(key, value);
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
clear() {
|
|
47
|
+
this.entries.clear();
|
|
48
|
+
}
|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I,EAAE,CAAC,IAAI,EAAE,CAAC,KAAU,CAAA;YAClE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;QAC3C,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAC5B,OAAO,IAAI,CAAA;IACb,CAAC;IAED;;OAEG;IACH,YAAY,CAAC,GAAM,EAAE,OAAsB;QACzC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAM,CAAA;QACpD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;QAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QACpB,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;CACF","sourcesContent":["/**\n * Cache with a maximum number of entries: when it is full, adding an entry evicts the least recently used one.\n * To be used for module-level caches, which would otherwise grow for the whole life of the process.\n */\nexport class LRUCache<K, V> {\n private readonly maxSize: number\n private readonly entries = new Map<K, V>()\n\n constructor(maxSize: number) {\n if (!Number.isInteger(maxSize) || maxSize <= 0) throw new Error(`Invalid LRU cache max size: ${maxSize}`)\n this.maxSize = maxSize\n }\n\n get size(): number {\n return this.entries.size\n }\n\n has(key: K): boolean {\n return this.entries.has(key)\n }\n\n get(key: K): V | undefined {\n if (!this.entries.has(key)) return undefined\n const value = this.entries.get(key) as V\n // move the entry to the end (most recently used): Map keeps the insertion order\n this.entries.delete(key)\n this.entries.set(key, value)\n return value\n }\n\n set(key: K, value: V): this {\n this.entries.delete(key)\n if (this.entries.size >= this.maxSize) {\n const leastRecentlyUsedKey = this.entries.keys().next().value as K\n this.entries.delete(leastRecentlyUsedKey)\n }\n this.entries.set(key, value)\n return this\n }\n\n /**\n * Returns the cached value of the specified key, computing and caching it if missing.\n */\n getOrCompute(key: K, compute: (key: K) => V): V {\n if (this.entries.has(key)) return this.get(key) as V\n const value = compute(key)\n this.set(key, value)\n return value\n }\n\n clear(): void {\n this.entries.clear()\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ArenaAppInfo } from '../app';
|
|
1
2
|
import { LanguageCode } from '../language';
|
|
2
3
|
export interface ArenaExpressionContext {
|
|
3
4
|
object?: any;
|
|
@@ -11,4 +12,8 @@ export interface ArenaExpressionContext {
|
|
|
11
12
|
* language selected in the client app, used by language-aware expression functions (e.g. numberToWords)
|
|
12
13
|
*/
|
|
13
14
|
lang?: LanguageCode;
|
|
15
|
+
/**
|
|
16
|
+
* info about the app running the evaluation (used by the appId, appIdLabel, appVersion and appPlatform expression functions)
|
|
17
|
+
*/
|
|
18
|
+
appInfo?: ArenaAppInfo;
|
|
14
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/expression/context.ts"],"names":[],"mappings":"","sourcesContent":["import { LanguageCode } from '../language'\n\nexport interface ArenaExpressionContext {\n object?: any\n evaluateToNode?: boolean\n includeAnalysis?: boolean\n /**\n * client timezone offset in minutes as returned by the Date.getTimezoneOffset function\n */\n timezoneOffset?: number\n /**\n * language selected in the client app, used by language-aware expression functions (e.g. numberToWords)\n */\n lang?: LanguageCode\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/expression/context.ts"],"names":[],"mappings":"","sourcesContent":["import { ArenaAppInfo } from '../app'\nimport { LanguageCode } from '../language'\n\nexport interface ArenaExpressionContext {\n object?: any\n evaluateToNode?: boolean\n includeAnalysis?: boolean\n /**\n * client timezone offset in minutes as returned by the Date.getTimezoneOffset function\n */\n timezoneOffset?: number\n /**\n * language selected in the client app, used by language-aware expression functions (e.g. numberToWords)\n */\n lang?: LanguageCode\n /**\n * info about the app running the evaluation (used by the appId, appIdLabel, appVersion and appPlatform expression functions)\n */\n appInfo?: ArenaAppInfo\n}\n"]}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.JavascriptExpressionEvaluator = exports.parseExpression = void 0;
|
|
13
13
|
const node_1 = require("../node");
|
|
14
14
|
const error_1 = require("../../error");
|
|
15
|
+
const lruCache_1 = require("../../utils/lruCache");
|
|
15
16
|
const functionsDefault_1 = require("./functionsDefault");
|
|
16
17
|
const array_1 = require("./node/array");
|
|
17
18
|
const binary_1 = require("./node/binary");
|
|
@@ -40,23 +41,9 @@ const defaultEvaluators = {
|
|
|
40
41
|
};
|
|
41
42
|
// Parsed expressions cache: the same expressions are evaluated many times (e.g. for every node during a record update).
|
|
42
43
|
// The cached expression nodes are shared, so evaluators must never modify them.
|
|
43
|
-
const
|
|
44
|
-
const parsedExpressionsCache = new Map();
|
|
44
|
+
const parsedExpressionsCache = new lruCache_1.LRUCache(1000);
|
|
45
45
|
const expressionParser = new parser_1.JavascriptExpressionParser();
|
|
46
|
-
const parseExpression = (expression) =>
|
|
47
|
-
let expressionNode = parsedExpressionsCache.get(expression);
|
|
48
|
-
if (!expressionNode) {
|
|
49
|
-
expressionNode = expressionParser.parse(expression);
|
|
50
|
-
if (parsedExpressionsCache.size >= PARSED_EXPRESSIONS_CACHE_MAX_SIZE) {
|
|
51
|
-
// evict the oldest entry (Map keeps insertion order)
|
|
52
|
-
const oldestExpression = parsedExpressionsCache.keys().next().value;
|
|
53
|
-
if (oldestExpression !== undefined)
|
|
54
|
-
parsedExpressionsCache.delete(oldestExpression);
|
|
55
|
-
}
|
|
56
|
-
parsedExpressionsCache.set(expression, expressionNode);
|
|
57
|
-
}
|
|
58
|
-
return expressionNode;
|
|
59
|
-
};
|
|
46
|
+
const parseExpression = (expression) => parsedExpressionsCache.getOrCompute(expression, () => expressionParser.parse(expression));
|
|
60
47
|
exports.parseExpression = parseExpression;
|
|
61
48
|
class JavascriptExpressionEvaluator {
|
|
62
49
|
constructor(functions = {}, evaluators = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../../src/expression/javascript/evaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,kCAA0G;AAC1G,uCAA0D;
|
|
1
|
+
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../../src/expression/javascript/evaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,kCAA0G;AAC1G,uCAA0D;AAC1D,mDAA+C;AAE/C,yDAAqD;AACrD,wCAA6C;AAC7C,0CAA+C;AAC/C,sCAA2C;AAC3C,8CAAmD;AACnD,oDAAyD;AACzD,kDAAuD;AACvD,4CAAiD;AACjD,0CAA+C;AAC/C,8CAAmD;AACnD,sCAA2C;AAC3C,wCAA6C;AAC7C,4CAA4D;AAM5D,MAAM,iBAAiB,GAAG;IACxB,CAAC,yBAAkB,CAAC,KAAK,CAAC,EAAE,sBAAc;IAC1C,CAAC,yBAAkB,CAAC,MAAM,CAAC,EAAE,wBAAe;IAC5C,CAAC,yBAAkB,CAAC,IAAI,CAAC,EAAE,oBAAa;IACxC,CAAC,yBAAkB,CAAC,QAAQ,CAAC,EAAE,4BAAiB;IAChD,CAAC,yBAAkB,CAAC,WAAW,CAAC,EAAE,kCAAoB;IACtD,CAAC,yBAAkB,CAAC,UAAU,CAAC,EAAE,gCAAmB;IACpD,CAAC,yBAAkB,CAAC,OAAO,CAAC,EAAE,0BAAgB;IAC9C,CAAC,yBAAkB,CAAC,MAAM,CAAC,EAAE,wBAAe;IAC5C,CAAC,yBAAkB,CAAC,QAAQ,CAAC,EAAE,4BAAiB;IAChD,CAAC,yBAAkB,CAAC,IAAI,CAAC,EAAE,oBAAa;IACxC,CAAC,yBAAkB,CAAC,KAAK,CAAC,EAAE,sBAAc;CAC3C,CAAA;AAED,wHAAwH;AACxH,gFAAgF;AAChF,MAAM,sBAAsB,GAAG,IAAI,mBAAQ,CAAkD,IAAI,CAAC,CAAA;AAClG,MAAM,gBAAgB,GAAG,IAAI,mCAA0B,EAAE,CAAA;AAElD,MAAM,eAAe,GAAG,CAAC,UAAkB,EAA2C,EAAE,CAC7F,sBAAsB,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;AAD9E,QAAA,eAAe,GAAf,eAAe,CAC+D;AAE3F;IAIE,YAAY,SAAS,GAAgC,EAAE,EAAE,UAAU,GAAkB,EAAE;QACrF,IAAI,CAAC,UAAU,mCAAQ,iBAAiB,GAAK,UAAU,CAAE,CAAA;QACzD,IAAI,CAAC,SAAS,mCAAQ,mCAAgB,GAAK,SAAS,CAAE,CAAA;IACxD,CAAC;IAEK,QAAQ,CAAC,UAAkB,EAAE,OAAW;;YAC5C,OAAO,IAAI,CAAC,YAAY,CAAC,IAAA,QAAA,eAAe,EAAC,UAAU,CAAC,EAAE,OAAO,aAAP,OAAO,cAAP,OAAO,GAAK,EAAQ,CAAC,CAAA;QAC7E,CAAC;KAAA;IAEK,YAAY,CAAC,cAAuD,EAAE,OAAU;;YACpF,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAA;YAE/B,MAAM,aAAa,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;YAC3C,IAAI,CAAC,aAAa,EAAE,CAAC;gBACnB,MAAM,IAAI,mBAAW,CAAC,uBAAe,CAAC,UAAU,CAAC,uBAAuB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;YACrF,CAAC;YACD,OAAO,IAAI,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAA;QAClE,CAAC;KAAA;CACF","sourcesContent":["import { ArenaExpressionContext } from '../context'\nimport { ArenaExpressionEvaluator } from '../evaluator'\nimport { ArenaExpressionFunctions } from '../function'\nimport { ArenaExpressionNode, ArenaExpressionNodeEvaluatorConstructor, ExpressionNodeType } from '../node'\nimport { SystemError, SystemErrorKeys } from '../../error'\nimport { LRUCache } from '../../utils/lruCache'\n\nimport { functionsDefault } from './functionsDefault'\nimport { ArrayEvaluator } from './node/array'\nimport { BinaryEvaluator } from './node/binary'\nimport { CallEvaluator } from './node/call'\nimport { CompoundEvaluator } from './node/compound'\nimport { ConditionalEvaluator } from './node/conditional'\nimport { IdentifierEvaluator } from './node/identifier'\nimport { LiteralEvaluator } from './node/literal'\nimport { MemberEvaluator } from './node/member'\nimport { SequenceEvaluator } from './node/sequence'\nimport { ThisEvaluator } from './node/this'\nimport { UnaryEvaluator } from './node/unary'\nimport { JavascriptExpressionParser } from './parser/parser'\n\ntype Evaluators<C extends ArenaExpressionContext> = {\n [nodeType in ExpressionNodeType]?: ArenaExpressionNodeEvaluatorConstructor<C, ArenaExpressionNode<ExpressionNodeType>>\n}\n\nconst defaultEvaluators = {\n [ExpressionNodeType.Array]: ArrayEvaluator,\n [ExpressionNodeType.Binary]: BinaryEvaluator,\n [ExpressionNodeType.Call]: CallEvaluator,\n [ExpressionNodeType.Compound]: CompoundEvaluator,\n [ExpressionNodeType.Conditional]: ConditionalEvaluator,\n [ExpressionNodeType.Identifier]: IdentifierEvaluator,\n [ExpressionNodeType.Literal]: LiteralEvaluator,\n [ExpressionNodeType.Member]: MemberEvaluator,\n [ExpressionNodeType.Sequence]: SequenceEvaluator,\n [ExpressionNodeType.This]: ThisEvaluator,\n [ExpressionNodeType.Unary]: UnaryEvaluator,\n}\n\n// Parsed expressions cache: the same expressions are evaluated many times (e.g. for every node during a record update).\n// The cached expression nodes are shared, so evaluators must never modify them.\nconst parsedExpressionsCache = new LRUCache<string, ArenaExpressionNode<ExpressionNodeType>>(1000)\nconst expressionParser = new JavascriptExpressionParser()\n\nexport const parseExpression = (expression: string): ArenaExpressionNode<ExpressionNodeType> =>\n parsedExpressionsCache.getOrCompute(expression, () => expressionParser.parse(expression))\n\nexport class JavascriptExpressionEvaluator<C extends ArenaExpressionContext> implements ArenaExpressionEvaluator<C> {\n functions: ArenaExpressionFunctions<C>\n evaluators: Evaluators<C>\n\n constructor(functions: ArenaExpressionFunctions<C> = {}, evaluators: Evaluators<C> = {}) {\n this.evaluators = { ...defaultEvaluators, ...evaluators }\n this.functions = { ...functionsDefault, ...functions }\n }\n\n async evaluate(expression: string, context?: C): Promise<any> {\n return this.evaluateNode(parseExpression(expression), context ?? ({} as C))\n }\n\n async evaluateNode(expressionNode: ArenaExpressionNode<ExpressionNodeType>, context: C): Promise<any> {\n const { type } = expressionNode\n\n const NodeEvaluator = this.evaluators[type]\n if (!NodeEvaluator) {\n throw new SystemError(SystemErrorKeys.expression.unsupportedFunctionType, { type })\n }\n return new NodeEvaluator(this, context).evaluate(expressionNode)\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the names of the functions called in the specified expression (e.g. "now" in "now() > date_attr").
|
|
3
|
+
* Returns an empty set if the expression is empty or cannot be parsed.
|
|
4
|
+
* @param expression - The expression to search in.
|
|
5
|
+
* @returns The names of the called functions.
|
|
6
|
+
*/
|
|
7
|
+
export declare const findFunctionCallNames: (expression: string | undefined | null) => Set<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Returns true if the specified expression uses the "this" keyword (results are cached by expression, up to 1000).
|
|
10
|
+
* @param expression - The expression to search in.
|
|
11
|
+
* @returns True if "this" is used in the expression.
|
|
12
|
+
*/
|
|
13
|
+
export declare const expressionUsesThis: (expression: string | undefined | null) => boolean;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expressionUsesThis = exports.findFunctionCallNames = void 0;
|
|
4
|
+
const node_1 = require("../../node");
|
|
5
|
+
const lruCache_1 = require("../../../utils/lruCache");
|
|
6
|
+
const parser_1 = require("./parser");
|
|
7
|
+
const parser = new parser_1.JavascriptExpressionParser();
|
|
8
|
+
/**
|
|
9
|
+
* Visits the specified expression node and all its descendants (arguments, operands, compound bodies...).
|
|
10
|
+
*/
|
|
11
|
+
const visit = (value, visitor) => {
|
|
12
|
+
if (Array.isArray(value)) {
|
|
13
|
+
for (const item of value)
|
|
14
|
+
visit(item, visitor);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!value || typeof value !== 'object')
|
|
18
|
+
return;
|
|
19
|
+
const expressionNode = value;
|
|
20
|
+
if (expressionNode.type) {
|
|
21
|
+
visitor(expressionNode);
|
|
22
|
+
}
|
|
23
|
+
for (const child of Object.values(expressionNode)) {
|
|
24
|
+
visit(child, visitor);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
const visitExpression = (expression, visitor) => {
|
|
28
|
+
try {
|
|
29
|
+
visit(parser.parse(expression), visitor);
|
|
30
|
+
}
|
|
31
|
+
catch (_a) {
|
|
32
|
+
// invalid expression (reported by the expression validator)
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Finds the names of the functions called in the specified expression (e.g. "now" in "now() > date_attr").
|
|
37
|
+
* Returns an empty set if the expression is empty or cannot be parsed.
|
|
38
|
+
* @param expression - The expression to search in.
|
|
39
|
+
* @returns The names of the called functions.
|
|
40
|
+
*/
|
|
41
|
+
const findFunctionCallNames = (expression) => {
|
|
42
|
+
const names = new Set();
|
|
43
|
+
if (!expression)
|
|
44
|
+
return names;
|
|
45
|
+
visitExpression(expression, (expressionNode) => {
|
|
46
|
+
if (expressionNode.type === node_1.ExpressionNodeType.Call &&
|
|
47
|
+
expressionNode.callee.type === node_1.ExpressionNodeType.Identifier) {
|
|
48
|
+
names.add(expressionNode.callee.name);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
return names;
|
|
52
|
+
};
|
|
53
|
+
exports.findFunctionCallNames = findFunctionCallNames;
|
|
54
|
+
const usesThisCache = new lruCache_1.LRUCache(1000);
|
|
55
|
+
/**
|
|
56
|
+
* Returns true if the specified expression uses the "this" keyword (results are cached by expression, up to 1000).
|
|
57
|
+
* @param expression - The expression to search in.
|
|
58
|
+
* @returns True if "this" is used in the expression.
|
|
59
|
+
*/
|
|
60
|
+
const expressionUsesThis = (expression) => {
|
|
61
|
+
if (!expression)
|
|
62
|
+
return false;
|
|
63
|
+
return usesThisCache.getOrCompute(expression, () => {
|
|
64
|
+
let result = false;
|
|
65
|
+
visitExpression(expression, (expressionNode) => {
|
|
66
|
+
if (expressionNode.type === node_1.ExpressionNodeType.This)
|
|
67
|
+
result = true;
|
|
68
|
+
});
|
|
69
|
+
return result;
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
exports.expressionUsesThis = expressionUsesThis;
|
|
73
|
+
//# sourceMappingURL=expressionNodesFinder.js.map
|