@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
|
@@ -21,6 +21,7 @@ const recordExpressionEvaluator_1 = require("../recordExpressionEvaluator");
|
|
|
21
21
|
const records_1 = require("../records");
|
|
22
22
|
const recordExpressionValueConverter_1 = require("./recordExpressionValueConverter");
|
|
23
23
|
const recordNodesDependentsUpdaterCommons_1 = require("./recordNodesDependentsUpdaterCommons");
|
|
24
|
+
const expressionNodesFinder_1 = require("../../expression/javascript/parser/expressionNodesFinder");
|
|
24
25
|
const recordUpdateResult_1 = require("./recordUpdateResult");
|
|
25
26
|
const expressionEvaluator = new recordExpressionEvaluator_1.RecordExpressionEvaluator();
|
|
26
27
|
/**
|
|
@@ -41,13 +42,14 @@ const canApplyDefaultValue = (params) => {
|
|
|
41
42
|
(node_1.RecordNodes.isDefaultValueApplied(node) || nodeDef_1.NodeDefs.isReadOnly(nodeDef)))));
|
|
42
43
|
};
|
|
43
44
|
const updateDefaultValueInNode = (params) => {
|
|
44
|
-
const { survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect } = params;
|
|
45
|
+
const { survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect, dateModified: dateModifiedParam } = params;
|
|
46
|
+
const dateModified = dateModifiedParam !== null && dateModifiedParam !== void 0 ? dateModifiedParam : utils_1.Dates.nowFormattedForStorage();
|
|
45
47
|
if (shouldResetDefaultValue({ survey, record: updateResult.record, node: nodeToUpdate })) {
|
|
46
48
|
const nodeUpdated = node_1.RecordNodes.mergeNodes(nodeToUpdate, {
|
|
47
49
|
value: null,
|
|
48
50
|
meta: { defaultValueApplied: false },
|
|
49
51
|
updated: true,
|
|
50
|
-
dateModified
|
|
52
|
+
dateModified,
|
|
51
53
|
});
|
|
52
54
|
updateResult.addNode(nodeUpdated, { sideEffect });
|
|
53
55
|
return;
|
|
@@ -65,20 +67,32 @@ const updateDefaultValueInNode = (params) => {
|
|
|
65
67
|
const nodeUpdated = Object.assign(Object.assign({}, node_1.RecordNodes.mergeNodes(nodeToUpdate, {
|
|
66
68
|
meta: { defaultValueApplied },
|
|
67
69
|
updated: true,
|
|
68
|
-
dateModified
|
|
70
|
+
dateModified,
|
|
69
71
|
})), { value: exprValue });
|
|
70
72
|
updateResult.addNode(nodeUpdated, { sideEffect });
|
|
71
73
|
};
|
|
72
74
|
const updateDefaultValuesInNodes = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
75
|
+
var _a;
|
|
73
76
|
const { survey, nodePointer, updateResult, timezoneOffset, categoryItemProvider, sideEffect = false } = params;
|
|
74
77
|
const { nodeCtx, nodeDef } = nodePointer;
|
|
75
|
-
if (nodeCtx.deleted)
|
|
78
|
+
if (nodeCtx.deleted || (0, recordNodesDependentsUpdaterCommons_1.isAppInfoMissing)({ survey, appInfo: params.appInfo, nodeDef }))
|
|
76
79
|
return;
|
|
77
80
|
const { record } = updateResult;
|
|
78
|
-
let nodesToUpdate = [];
|
|
79
81
|
const dependentNodes = nodePointers_1.RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] });
|
|
80
|
-
let exprValue = null;
|
|
81
82
|
const expressionsToEvaluate = nodeDef_1.NodeDefs.getDefaultValues(nodeDef);
|
|
83
|
+
const updateNodes = (nodesToUpdate, exprValue) => {
|
|
84
|
+
for (const nodeToUpdate of nodesToUpdate) {
|
|
85
|
+
updateDefaultValueInNode({
|
|
86
|
+
survey,
|
|
87
|
+
updateResult,
|
|
88
|
+
nodeToUpdate,
|
|
89
|
+
nodeDef,
|
|
90
|
+
exprValue,
|
|
91
|
+
sideEffect,
|
|
92
|
+
dateModified: params.dateModified,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
82
96
|
if (expressionsToEvaluate.length === 0) {
|
|
83
97
|
if (survey_1.Surveys.isNodeDefEnumerator({ survey, nodeDef })) {
|
|
84
98
|
// if node def is enumerator, its default value is generated using the category items, not with default value expressions
|
|
@@ -86,21 +100,21 @@ const updateDefaultValuesInNodes = (params) => __awaiter(void 0, void 0, void 0,
|
|
|
86
100
|
return;
|
|
87
101
|
}
|
|
88
102
|
// no default expressions to evaluate; check if there are dependent nodes with default value applied, as their default value should be removed
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
103
|
+
// (if there are none, no update is needed)
|
|
104
|
+
updateNodes(dependentNodes.filter(node_1.RecordNodes.isDefaultValueApplied), null);
|
|
105
|
+
return;
|
|
94
106
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
// if there are default value expressions, all dependent nodes should be evaluated, as their default value could change
|
|
108
|
+
if (dependentNodes.length === 0)
|
|
109
|
+
return;
|
|
110
|
+
const evaluateDefaultValue = (nodeCurrent) => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
111
|
try {
|
|
99
|
-
//
|
|
112
|
+
// evaluate applicable default value expression
|
|
100
113
|
const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record,
|
|
101
|
-
nodeCtx,
|
|
114
|
+
nodeCtx,
|
|
115
|
+
nodeCurrent, expressions: expressionsToEvaluate }));
|
|
102
116
|
const exprEvalValue = exprEval === null || exprEval === void 0 ? void 0 : exprEval.value;
|
|
103
|
-
|
|
117
|
+
return utils_1.Objects.isEmpty(exprEvalValue)
|
|
104
118
|
? null
|
|
105
119
|
: yield recordExpressionValueConverter_1.RecordExpressionValueConverter.toNodeValue({
|
|
106
120
|
survey,
|
|
@@ -113,7 +127,7 @@ const updateDefaultValuesInNodes = (params) => __awaiter(void 0, void 0, void 0,
|
|
|
113
127
|
});
|
|
114
128
|
}
|
|
115
129
|
catch (error) {
|
|
116
|
-
(0, recordNodesDependentsUpdaterCommons_1.throwError)({
|
|
130
|
+
return (0, recordNodesDependentsUpdaterCommons_1.throwError)({
|
|
117
131
|
error,
|
|
118
132
|
errorKey: error_1.SystemErrorKeys.record.updateSelfAndDependentsDefaultValues,
|
|
119
133
|
expressionType: survey_2.SurveyDependencyType.defaultValues,
|
|
@@ -122,9 +136,20 @@ const updateDefaultValuesInNodes = (params) => __awaiter(void 0, void 0, void 0,
|
|
|
122
136
|
expressionsToEvaluate,
|
|
123
137
|
});
|
|
124
138
|
}
|
|
139
|
+
});
|
|
140
|
+
const usesThis = expressionsToEvaluate.some((expression) => (0, expressionNodesFinder_1.expressionUsesThis)(expression.expression) || (0, expressionNodesFinder_1.expressionUsesThis)(expression.applyIf));
|
|
141
|
+
if (nodeDef_1.NodeDefs.isMultiple(nodeDef) && usesThis) {
|
|
142
|
+
// "this" refers to each node: evaluate the expressions for every node
|
|
143
|
+
for (const dependentNode of dependentNodes) {
|
|
144
|
+
// sequential: each iteration updates the record
|
|
145
|
+
const exprValue = yield evaluateDefaultValue(dependentNode); // NOSONAR
|
|
146
|
+
updateNodes([dependentNode], exprValue);
|
|
147
|
+
}
|
|
125
148
|
}
|
|
126
|
-
|
|
127
|
-
|
|
149
|
+
else {
|
|
150
|
+
// the same value applies to all the nodes ("this" is the node itself, if the node def is single)
|
|
151
|
+
const exprValue = yield evaluateDefaultValue(nodeDef_1.NodeDefs.isMultiple(nodeDef) ? null : ((_a = dependentNodes[0]) !== null && _a !== void 0 ? _a : null));
|
|
152
|
+
updateNodes(dependentNodes, exprValue);
|
|
128
153
|
}
|
|
129
154
|
});
|
|
130
155
|
const updateSelfAndDependentsDefaultValues = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodeDependentsDefaultValuesUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA6C;AAC7C,qCAAiF;AACjF,2CAAsD;AACtD,yCAAsC;AACtC,gDAAuE;AACvE,uCAA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YAC3B,YAAY,EAAE,CAAC,WAAW,CAAC;SAC5B,CAAC,CAAA;QACF,OAAO,eAAe,CAAC,IAAI,CACzB,CAAC,cAAc,EAAE,EAAE,CACjB,uBAAuB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;YACtF,oBAAoB,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CACvF,CAAA;IACH,CAAC,CAAA;IAED,MAAM,oBAAoB,GAAG,iBAAO,CAAC,wBAAwB,CAC3D,MAAM,EACN,IAAI,EACJ,6BAAoB,CAAC,aAAa,EAClC,IAAI,EACJ,oBAAoB,CACrB,CAAC,MAAM,CAAC,CAAA;IAET,6CAA6C;IAC7C,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,gDAAgD;QAChD,MAAM,0BAA0B,iCAAM,MAAM,KAAE,WAAW,EAAE,YAAY,EAAE,UAAU,IAAG,CAAA,CAAC,UAAU;IACnG,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAxCY,QAAA,oCAAoC,GAApC,oCAAoC,CAwChD","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, RecordNodes } from '../../node'\nimport { ArenaNodeDef, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { ArenaSurvey, SurveyDependencyType } from '../../survey/survey'\nimport { Dates, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordExpressionValueConverter } from './recordExpressionValueConverter'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { throwError } from './recordNodesDependentsUpdaterCommons'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Default value should be reset when a node becomes not applicable, but only if the default value was applied or if the node def is read only (therefore the value can only be set by default value expression)\n */\nconst shouldResetDefaultValue = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): boolean => {\n const { survey, record, node } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n return (\n !Records.isNodeApplicable(node)(record) &&\n !RecordNodes.isValueBlank(node) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))\n )\n}\n\nconst canApplyDefaultValue = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n}): boolean => {\n const { record, node, nodeDef } = params\n return (\n Records.isNodeApplicable(node)(record) &&\n (RecordNodes.isValueBlank(node) ||\n (!NodeDefs.isDefaultValueEvaluatedOneTime(nodeDef) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))))\n )\n}\n\nconst updateDefaultValueInNode = (params: {\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n nodeToUpdate: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n exprValue: any\n sideEffect: boolean\n}): void => {\n const { survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect } = params\n if (shouldResetDefaultValue({ survey, record: updateResult.record, node: nodeToUpdate })) {\n const nodeUpdated = RecordNodes.mergeNodes(nodeToUpdate, {\n value: null,\n meta: { defaultValueApplied: false },\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n return\n }\n if (!canApplyDefaultValue({ record: updateResult.record, nodeDef, node: nodeToUpdate })) {\n return\n }\n\n // 2. if node value is not changed, do nothing\n if (Objects.isEqual(nodeToUpdate.value, exprValue)) {\n return\n }\n\n // 3. update node value and meta\n const defaultValueApplied = !Objects.isEmpty(exprValue)\n\n // the value is replaced, not merged: props of the previous value (e.g. vernacularNameUuid) must not be kept\n const nodeUpdated: ArenaRecordNode = {\n ...RecordNodes.mergeNodes(nodeToUpdate, {\n meta: { defaultValueApplied },\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }),\n value: exprValue,\n }\n updateResult.addNode(nodeUpdated, { sideEffect })\n}\n\nconst updateDefaultValuesInNodes = async (\n params: RecordNodeDependentsUpdateParams & {\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n }\n): Promise<void> => {\n const { survey, nodePointer, updateResult, timezoneOffset, categoryItemProvider, sideEffect = false } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted) return\n\n const { record } = updateResult\n\n let nodesToUpdate: ArenaRecordNode[] = []\n const dependentNodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n let exprValue: any = null\n const expressionsToEvaluate = NodeDefs.getDefaultValues(nodeDef)\n if (expressionsToEvaluate.length === 0) {\n if (Surveys.isNodeDefEnumerator({ survey, nodeDef })) {\n // if node def is enumerator, its default value is generated using the category items, not with default value expressions\n // so the default value should not be reset or updated using default value expressions\n return\n }\n // no default expressions to evaluate; check if there are dependent nodes with default value applied, as their default value should be removed\n nodesToUpdate = dependentNodes.filter(RecordNodes.isDefaultValueApplied)\n if (nodesToUpdate.length === 0) {\n // no default expressions to evaluate and no nodes with default value applied, therefore no update needed\n return\n }\n } else {\n // if there are default value expressions, all dependent nodes should be evaluated, as their default value could change\n nodesToUpdate = dependentNodes\n try {\n // 1. evaluate applicable default value expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n\n const exprEvalValue = exprEval?.value\n exprValue = Objects.isEmpty(exprEvalValue)\n ? null\n : await RecordExpressionValueConverter.toNodeValue({\n survey,\n record,\n nodeDef,\n nodeParent: nodeCtx,\n valueExpr: exprEvalValue,\n timezoneOffset,\n categoryItemProvider,\n })\n } catch (error) {\n throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsDefaultValues,\n expressionType: SurveyDependencyType.defaultValues,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n }\n for (const nodeToUpdate of nodesToUpdate) {\n updateDefaultValueInNode({ survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect })\n }\n}\n\nexport const updateSelfAndDependentsDefaultValues = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n // filter nodes to update including itself and (attributes with empty values or with default values applied)\n // therefore attributes with user defined values are excluded\n const nodePointersFilterFn = (nodePointer: ArenaRecordNodePointer): boolean => {\n const { nodeDef } = nodePointer\n if (!NodeDefs.isAttribute(nodeDef)) return false\n\n const referencedNodes = RecordNodePointers.getNodesFromNodePointers({\n record: updateResult.record,\n nodePointers: [nodePointer],\n })\n return referencedNodes.some(\n (referencedNode) =>\n shouldResetDefaultValue({ survey, record: updateResult.record, node: referencedNode }) ||\n canApplyDefaultValue({ record: updateResult.record, node: referencedNode, nodeDef })\n )\n }\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.defaultValues,\n true,\n nodePointersFilterFn\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateDefaultValuesInNodes({ ...params, nodePointer, updateResult, sideEffect }) // NOSONAR\n }\n return updateResult\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recordNodeDependentsDefaultValuesUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA6C;AAC7C,qCAAiF;AACjF,2CAAsD;AACtD,yCAAsC;AACtC,gDAAuE;AACvE,uCAA4C;AAC5C,kDAA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AAE,CAAC;YACtF,oBAAoB,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CACvF,CAAA;IACH,CAAC,CAAA;IAED,MAAM,oBAAoB,GAAG,iBAAO,CAAC,wBAAwB,CAC3D,MAAM,EACN,IAAI,EACJ,6BAAoB,CAAC,aAAa,EAClC,IAAI,EACJ,oBAAoB,CACrB,CAAC,MAAM,CAAC,CAAA;IAET,6CAA6C;IAC7C,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,gDAAgD;QAChD,MAAM,0BAA0B,iCAAM,MAAM,KAAE,WAAW,EAAE,YAAY,EAAE,UAAU,IAAG,CAAA,CAAC,UAAU;IACnG,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAxCY,QAAA,oCAAoC,GAApC,oCAAoC,CAwChD","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, RecordNodes } from '../../node'\nimport { ArenaNodeDef, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { ArenaSurvey, SurveyDependencyType } from '../../survey/survey'\nimport { Dates, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordExpressionValueConverter } from './recordExpressionValueConverter'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { isAppInfoMissing, throwError } from './recordNodesDependentsUpdaterCommons'\nimport { expressionUsesThis } from '../../expression/javascript/parser/expressionNodesFinder'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Default value should be reset when a node becomes not applicable, but only if the default value was applied or if the node def is read only (therefore the value can only be set by default value expression)\n */\nconst shouldResetDefaultValue = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): boolean => {\n const { survey, record, node } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n return (\n !Records.isNodeApplicable(node)(record) &&\n !RecordNodes.isValueBlank(node) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))\n )\n}\n\nconst canApplyDefaultValue = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n}): boolean => {\n const { record, node, nodeDef } = params\n return (\n Records.isNodeApplicable(node)(record) &&\n (RecordNodes.isValueBlank(node) ||\n (!NodeDefs.isDefaultValueEvaluatedOneTime(nodeDef) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))))\n )\n}\n\nconst updateDefaultValueInNode = (params: {\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n nodeToUpdate: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n exprValue: any\n sideEffect: boolean\n dateModified?: string\n}): void => {\n const { survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect, dateModified: dateModifiedParam } = params\n const dateModified = dateModifiedParam ?? Dates.nowFormattedForStorage()\n if (shouldResetDefaultValue({ survey, record: updateResult.record, node: nodeToUpdate })) {\n const nodeUpdated = RecordNodes.mergeNodes(nodeToUpdate, {\n value: null,\n meta: { defaultValueApplied: false },\n updated: true,\n dateModified,\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n return\n }\n if (!canApplyDefaultValue({ record: updateResult.record, nodeDef, node: nodeToUpdate })) {\n return\n }\n\n // 2. if node value is not changed, do nothing\n if (Objects.isEqual(nodeToUpdate.value, exprValue)) {\n return\n }\n\n // 3. update node value and meta\n const defaultValueApplied = !Objects.isEmpty(exprValue)\n\n // the value is replaced, not merged: props of the previous value (e.g. vernacularNameUuid) must not be kept\n const nodeUpdated: ArenaRecordNode = {\n ...RecordNodes.mergeNodes(nodeToUpdate, {\n meta: { defaultValueApplied },\n updated: true,\n dateModified,\n }),\n value: exprValue,\n }\n updateResult.addNode(nodeUpdated, { sideEffect })\n}\n\nconst updateDefaultValuesInNodes = async (\n params: RecordNodeDependentsUpdateParams & {\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n }\n): Promise<void> => {\n const { survey, nodePointer, updateResult, timezoneOffset, categoryItemProvider, sideEffect = false } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted || isAppInfoMissing({ survey, appInfo: params.appInfo, nodeDef })) return\n\n const { record } = updateResult\n\n const dependentNodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n const expressionsToEvaluate = NodeDefs.getDefaultValues(nodeDef)\n\n const updateNodes = (nodesToUpdate: ArenaRecordNode[], exprValue: any): void => {\n for (const nodeToUpdate of nodesToUpdate) {\n updateDefaultValueInNode({\n survey,\n updateResult,\n nodeToUpdate,\n nodeDef,\n exprValue,\n sideEffect,\n dateModified: params.dateModified,\n })\n }\n }\n\n if (expressionsToEvaluate.length === 0) {\n if (Surveys.isNodeDefEnumerator({ survey, nodeDef })) {\n // if node def is enumerator, its default value is generated using the category items, not with default value expressions\n // so the default value should not be reset or updated using default value expressions\n return\n }\n // no default expressions to evaluate; check if there are dependent nodes with default value applied, as their default value should be removed\n // (if there are none, no update is needed)\n updateNodes(dependentNodes.filter(RecordNodes.isDefaultValueApplied), null)\n return\n }\n\n // if there are default value expressions, all dependent nodes should be evaluated, as their default value could change\n if (dependentNodes.length === 0) return\n\n const evaluateDefaultValue = async (nodeCurrent: ArenaRecordNode | null): Promise<any> => {\n try {\n // evaluate applicable default value expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record,\n nodeCtx,\n nodeCurrent,\n expressions: expressionsToEvaluate,\n })\n const exprEvalValue = exprEval?.value\n return Objects.isEmpty(exprEvalValue)\n ? null\n : await RecordExpressionValueConverter.toNodeValue({\n survey,\n record,\n nodeDef,\n nodeParent: nodeCtx,\n valueExpr: exprEvalValue,\n timezoneOffset,\n categoryItemProvider,\n })\n } catch (error) {\n return throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsDefaultValues,\n expressionType: SurveyDependencyType.defaultValues,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n }\n\n const usesThis = expressionsToEvaluate.some(\n (expression) => expressionUsesThis(expression.expression) || expressionUsesThis(expression.applyIf)\n )\n if (NodeDefs.isMultiple(nodeDef) && usesThis) {\n // \"this\" refers to each node: evaluate the expressions for every node\n for (const dependentNode of dependentNodes) {\n // sequential: each iteration updates the record\n const exprValue = await evaluateDefaultValue(dependentNode) // NOSONAR\n updateNodes([dependentNode], exprValue)\n }\n } else {\n // the same value applies to all the nodes (\"this\" is the node itself, if the node def is single)\n const exprValue = await evaluateDefaultValue(NodeDefs.isMultiple(nodeDef) ? null : (dependentNodes[0] ?? null))\n updateNodes(dependentNodes, exprValue)\n }\n}\n\nexport const updateSelfAndDependentsDefaultValues = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n // filter nodes to update including itself and (attributes with empty values or with default values applied)\n // therefore attributes with user defined values are excluded\n const nodePointersFilterFn = (nodePointer: ArenaRecordNodePointer): boolean => {\n const { nodeDef } = nodePointer\n if (!NodeDefs.isAttribute(nodeDef)) return false\n\n const referencedNodes = RecordNodePointers.getNodesFromNodePointers({\n record: updateResult.record,\n nodePointers: [nodePointer],\n })\n return referencedNodes.some(\n (referencedNode) =>\n shouldResetDefaultValue({ survey, record: updateResult.record, node: referencedNode }) ||\n canApplyDefaultValue({ record: updateResult.record, node: referencedNode, nodeDef })\n )\n }\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.defaultValues,\n true,\n nodePointersFilterFn\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateDefaultValuesInNodes({ ...params, nodePointer, updateResult, sideEffect }) // NOSONAR\n }\n return updateResult\n}\n"]}
|
|
@@ -58,7 +58,7 @@ const calculateFileName = (params) => __awaiter(void 0, void 0, void 0, function
|
|
|
58
58
|
return fileNameCalculated;
|
|
59
59
|
});
|
|
60
60
|
const updateFileNamesInNodes = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
-
const { user, survey, nodePointer, updateResult, sideEffect = false } = params;
|
|
61
|
+
const { user, survey, nodePointer, updateResult, sideEffect = false, dateModified } = params;
|
|
62
62
|
const { nodeCtx, nodeDef } = nodePointer;
|
|
63
63
|
if (nodeCtx.deleted)
|
|
64
64
|
return;
|
|
@@ -70,25 +70,33 @@ const updateFileNamesInNodes = (params) => __awaiter(void 0, void 0, void 0, fun
|
|
|
70
70
|
for (const node of nodes) {
|
|
71
71
|
if (!node_1.RecordNodes.isValueBlank(node)) {
|
|
72
72
|
// sequential: each iteration updates the record
|
|
73
|
-
yield updateFileNameInNode({
|
|
73
|
+
yield updateFileNameInNode({
|
|
74
|
+
user,
|
|
75
|
+
survey,
|
|
76
|
+
updateResult,
|
|
77
|
+
sideEffect,
|
|
78
|
+
nodeDef: nodeDef,
|
|
79
|
+
node,
|
|
80
|
+
dateModified,
|
|
81
|
+
}); // NOSONAR
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
});
|
|
77
85
|
const updateSelfAndDependentsFileNames = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
-
const { user, survey, record, node, sideEffect = false } = params;
|
|
86
|
+
const { user, survey, record, node, sideEffect = false, dateModified } = params;
|
|
79
87
|
const updateResult = new recordUpdateResult_1.RecordUpdateResult({ record });
|
|
80
88
|
// 1. get dependent node pointers
|
|
81
89
|
const nodePointersToUpdate = records_1.Records.getDependentNodePointers(survey, node, survey_2.SurveyDependencyType.fileName, true)(record);
|
|
82
90
|
// 2. update expr to node and dependent nodes
|
|
83
91
|
for (const nodePointer of nodePointersToUpdate) {
|
|
84
92
|
// sequential: each iteration updates the record
|
|
85
|
-
yield updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect }); // NOSONAR
|
|
93
|
+
yield updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect, dateModified }); // NOSONAR
|
|
86
94
|
}
|
|
87
95
|
return updateResult;
|
|
88
96
|
});
|
|
89
97
|
exports.updateSelfAndDependentsFileNames = updateSelfAndDependentsFileNames;
|
|
90
98
|
const updateFileNameInNode = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
-
const { user, survey, updateResult, sideEffect, node, nodeDef } = params;
|
|
99
|
+
const { user, survey, updateResult, sideEffect, node, nodeDef, dateModified } = params;
|
|
92
100
|
const expressionToEvaluate = nodeDef_1.NodeDefs.getFileNameExpression(nodeDef);
|
|
93
101
|
try {
|
|
94
102
|
const fileNameCalculated = yield calculateFileName({ user, survey, record: updateResult.record, node });
|
|
@@ -97,7 +105,7 @@ const updateFileNameInNode = (params) => __awaiter(void 0, void 0, void 0, funct
|
|
|
97
105
|
const nodeUpdated = node_1.RecordNodes.mergeNodes(node, {
|
|
98
106
|
value: { [node_1.RecordNodeValues.ValuePropsFile.fileNameCalculated]: fileNameCalculated },
|
|
99
107
|
updated: true,
|
|
100
|
-
dateModified: utils_1.Dates.nowFormattedForStorage(),
|
|
108
|
+
dateModified: dateModified !== null && dateModified !== void 0 ? dateModified : utils_1.Dates.nowFormattedForStorage(),
|
|
101
109
|
});
|
|
102
110
|
updateResult.addNode(nodeUpdated, { sideEffect });
|
|
103
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodeDependentsFileNamesEvaluator.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA6C;AAE7C,qCAMmB;AACnB,2CAA0D;AA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,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QACvG,MAAM,qBAAqB,GAAG,uBAAgB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;QAC1E,IAAI,kBAAkB,KAAK,qBAAqB,EAAE,CAAC;YACjD,MAAM,WAAW,GAAG,kBAAW,CAAC,UAAU,CAAC,IAAI,EAAE;gBAC/C,KAAK,EAAE,EAAE,CAAC,uBAAgB,CAAC,cAAc,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,EAAE;gBACnF,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,aAAK,CAAC,sBAAsB,EAAE;aAC7C,CAAC,CAAA;YACF,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,qBAAqB,GAAG,CAAC,kCAAwB,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,oBAAqB,EAAE,CAAC,CAAC,CAAA;QAC9G,IAAA,gDAAU,EAAC;YACT,KAAK;YACL,QAAQ,EAAE,uBAAe,CAAC,MAAM,CAAC,gCAAgC;YACjE,cAAc,EAAE,6BAAoB,CAAC,QAAQ;YAC7C,MAAM;YACN,OAAO;YACP,qBAAqB;SACtB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaUser } from '../../auth'\nimport {\n ArenaRecordNode,\n ArenaRecordNodePointer,\n RecordNodes,\n ArenaRecordNodeValueFile,\n RecordNodeValues,\n} from '../../node'\nimport { ArenaNodeDefFile, NodeDefs } from '../../nodeDef'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\nimport { ArenaSurvey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Dates, FileNames, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { throwError } from './recordNodesDependentsUpdaterCommons'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst fileNameWithPositionSuffixRegExp = /^.+\\s\\[\\d+\\]$/ // file name like \"name [1].test\"\n\nconst addPositionSuffix = (params: { fileName: string; position: number }) => {\n const { fileName, position } = params\n return `${fileName} [${position}]`\n}\n\nconst calculateFileName = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): Promise<string | undefined> => {\n const { user, survey, record, node } = params\n\n const nodeDef: ArenaNodeDefFile = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) as ArenaNodeDefFile\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef)\n if (!fileNameExpression) return undefined\n\n const { value } = node\n\n let fileNameCalculated = await expressionEvaluator.evalExpression({\n user,\n survey,\n record,\n node,\n query: fileNameExpression,\n })\n if (!fileNameCalculated) return undefined\n\n fileNameCalculated = String(fileNameCalculated)\n if (NodeDefs.isMultiple(nodeDef) && !fileNameWithPositionSuffixRegExp.test(fileNameCalculated)) {\n const index = Records.getNodeIndex(node)(record)\n fileNameCalculated = addPositionSuffix({ fileName: fileNameCalculated, position: index + 1 })\n }\n\n // add extension from original file name\n const originalFilaName = value ? (value as ArenaRecordNodeValueFile).fileName : undefined\n if (Objects.isNotEmpty(originalFilaName)) {\n const originalExtension = FileNames.getExtension(originalFilaName)\n fileNameCalculated = FileNames.addExtensionIfMissing(fileNameCalculated, originalExtension)\n }\n return fileNameCalculated\n}\n\nconst updateFileNamesInNodes = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n sideEffect?: boolean\n}): Promise<void> => {\n const { user, survey, nodePointer, updateResult, sideEffect = false } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted) return\n\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (!expressionToEvaluate) return\n\n const { record } = updateResult\n\n const nodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n\n for (const node of nodes) {\n if (!RecordNodes.isValueBlank(node)) {\n // sequential: each iteration updates the record\n await updateFileNameInNode({ user, survey, updateResult, sideEffect, nodeDef: nodeDef as ArenaNodeDefFile, node }) // NOSONAR\n }\n }\n}\n\nexport const updateSelfAndDependentsFileNames = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { user, survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.fileName,\n true\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect }) // NOSONAR\n }\n return updateResult\n}\n\nconst updateFileNameInNode = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n sideEffect: boolean\n nodeDef: ArenaNodeDefFile\n node: ArenaRecordNode\n}): Promise<void> => {\n const { user, survey, updateResult, sideEffect, node, nodeDef } = params\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef)\n try {\n const fileNameCalculated = await calculateFileName({ user, survey, record: updateResult.record, node })\n const oldFileNameCalculated = RecordNodeValues.getFileNameCalculated(node)\n if (fileNameCalculated !== oldFileNameCalculated) {\n const nodeUpdated = RecordNodes.mergeNodes(node, {\n value: { [RecordNodeValues.ValuePropsFile.fileNameCalculated]: fileNameCalculated },\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n }\n } catch (error) {\n const expressionsToEvaluate = [NodeDefExpressionFactory.createInstance({ expression: expressionToEvaluate! })]\n throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsFileNames,\n expressionType: SurveyDependencyType.fileName,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recordNodeDependentsFileNamesEvaluator.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA6C;AAE7C,qCAMmB;AACnB,2CAA0D;AAC1D,mDAAgE;AAChE,yCAAmD;AACnD,gDAA0D;AAC1D,uCAAuD;AACvD,kDAAoD;AAEpD,4EAAwE;AACxE,wCAAoC;AAEpC,+FAAkE;AAClE,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAE3D,MAAM,gCAAgC,GAAG,eAAe,CAAA,CAAC,iCAAiC;AAE1F,MAAM,iBAAiB,GAAG,CAAC,MAA8C,EAAE,EAAE;IAC3E,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IACrC,OAAO,GAAG,QAAQ,KAAK,QAAQ,GAAG,CAAA;AACpC,CAAC,CAAA;AAED,MAAM,iBAAiB,GAAG,CAAO,MAKhC,EAA+B,EAAE;IAChC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAE7C,MAAM,OAAO,GAAqB,gBAAO,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,CAAqB,CAAA;IAClH,MAAM,kBAAkB,GAAG,kBAAQ,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;IAClE,IAAI,CAAC,kBAAkB;QA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AAC,CAAA;QAC9G,IAAA,gDAAU,EAAC;YACT,KAAK;YACL,QAAQ,EAAE,uBAAe,CAAC,MAAM,CAAC,gCAAgC;YACjE,cAAc,EAAE,6BAAoB,CAAC,QAAQ;YAC7C,MAAM;YACN,OAAO;YACP,qBAAqB;SACtB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaUser } from '../../auth'\nimport {\n ArenaRecordNode,\n ArenaRecordNodePointer,\n RecordNodes,\n ArenaRecordNodeValueFile,\n RecordNodeValues,\n} from '../../node'\nimport { ArenaNodeDefFile, NodeDefs } from '../../nodeDef'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\nimport { ArenaSurvey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Dates, FileNames, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { throwError } from './recordNodesDependentsUpdaterCommons'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst fileNameWithPositionSuffixRegExp = /^.+\\s\\[\\d+\\]$/ // file name like \"name [1].test\"\n\nconst addPositionSuffix = (params: { fileName: string; position: number }) => {\n const { fileName, position } = params\n return `${fileName} [${position}]`\n}\n\nconst calculateFileName = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): Promise<string | undefined> => {\n const { user, survey, record, node } = params\n\n const nodeDef: ArenaNodeDefFile = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) as ArenaNodeDefFile\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef)\n if (!fileNameExpression) return undefined\n\n const { value } = node\n\n let fileNameCalculated = await expressionEvaluator.evalExpression({\n user,\n survey,\n record,\n node,\n query: fileNameExpression,\n })\n if (!fileNameCalculated) return undefined\n\n fileNameCalculated = String(fileNameCalculated)\n if (NodeDefs.isMultiple(nodeDef) && !fileNameWithPositionSuffixRegExp.test(fileNameCalculated)) {\n const index = Records.getNodeIndex(node)(record)\n fileNameCalculated = addPositionSuffix({ fileName: fileNameCalculated, position: index + 1 })\n }\n\n // add extension from original file name\n const originalFilaName = value ? (value as ArenaRecordNodeValueFile).fileName : undefined\n if (Objects.isNotEmpty(originalFilaName)) {\n const originalExtension = FileNames.getExtension(originalFilaName)\n fileNameCalculated = FileNames.addExtensionIfMissing(fileNameCalculated, originalExtension)\n }\n return fileNameCalculated\n}\n\nconst updateFileNamesInNodes = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n sideEffect?: boolean\n dateModified?: string\n}): Promise<void> => {\n const { user, survey, nodePointer, updateResult, sideEffect = false, dateModified } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted) return\n\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (!expressionToEvaluate) return\n\n const { record } = updateResult\n\n const nodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n\n for (const node of nodes) {\n if (!RecordNodes.isValueBlank(node)) {\n // sequential: each iteration updates the record\n await updateFileNameInNode({\n user,\n survey,\n updateResult,\n sideEffect,\n nodeDef: nodeDef as ArenaNodeDefFile,\n node,\n dateModified,\n }) // NOSONAR\n }\n }\n}\n\nexport const updateSelfAndDependentsFileNames = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { user, survey, record, node, sideEffect = false, dateModified } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.fileName,\n true\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect, dateModified }) // NOSONAR\n }\n return updateResult\n}\n\nconst updateFileNameInNode = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n sideEffect: boolean\n nodeDef: ArenaNodeDefFile\n node: ArenaRecordNode\n dateModified?: string\n}): Promise<void> => {\n const { user, survey, updateResult, sideEffect, node, nodeDef, dateModified } = params\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef)\n try {\n const fileNameCalculated = await calculateFileName({ user, survey, record: updateResult.record, node })\n const oldFileNameCalculated = RecordNodeValues.getFileNameCalculated(node)\n if (fileNameCalculated !== oldFileNameCalculated) {\n const nodeUpdated = RecordNodes.mergeNodes(node, {\n value: { [RecordNodeValues.ValuePropsFile.fileNameCalculated]: fileNameCalculated },\n updated: true,\n dateModified: dateModified ?? Dates.nowFormattedForStorage(),\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n }\n } catch (error) {\n const expressionsToEvaluate = [NodeDefExpressionFactory.createInstance({ expression: expressionToEvaluate! })]\n throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsFileNames,\n expressionType: SurveyDependencyType.fileName,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n}\n"]}
|
|
@@ -23,8 +23,8 @@ const expressionEvaluator = new recordExpressionEvaluator_1.RecordExpressionEval
|
|
|
23
23
|
* Evaluates the "required if" condition of the specified child def in the context of the specified parent entity.
|
|
24
24
|
*/
|
|
25
25
|
const evaluateRequiredIf = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
const { nodeCtx, nodeDef } = params;
|
|
27
|
-
const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { nodeCtx, expressions: nodeDef_1.NodeDefs.getRequiredIf(nodeDef) }));
|
|
26
|
+
const { record, nodeCtx, nodeDef } = params;
|
|
27
|
+
const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { nodeCtx, nodeCurrent: (0, recordNodesDependentsUpdaterCommons_1.getNodeCurrent)({ record, nodeCtx, nodeDef }), expressions: nodeDef_1.NodeDefs.getRequiredIf(nodeDef) }));
|
|
28
28
|
return !!(exprEval === null || exprEval === void 0 ? void 0 : exprEval.value);
|
|
29
29
|
});
|
|
30
30
|
exports.evaluateRequiredIf = evaluateRequiredIf;
|
|
@@ -33,7 +33,7 @@ exports.evaluateRequiredIf = evaluateRequiredIf;
|
|
|
33
33
|
*/
|
|
34
34
|
const updateSelfAndDependentsRequired = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
var _a;
|
|
36
|
-
const { survey, record, node, sideEffect = false } = params;
|
|
36
|
+
const { survey, record, node, sideEffect = false, dateModified } = params;
|
|
37
37
|
const updateResult = new recordUpdateResult_1.RecordUpdateResult({ record });
|
|
38
38
|
const nodePointersToUpdate = (0, recordNodesDependentsUpdaterCommons_1.getDependentNodePointersByType)({
|
|
39
39
|
survey,
|
|
@@ -51,7 +51,7 @@ const updateSelfAndDependentsRequired = (params) => __awaiter(void 0, void 0, vo
|
|
|
51
51
|
const value = yield (0, exports.evaluateRequiredIf)(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, nodeDef })); // NOSONAR
|
|
52
52
|
if (valuePrev === value)
|
|
53
53
|
continue;
|
|
54
|
-
const nodeCtxUpdated = node_1.RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect });
|
|
54
|
+
const nodeCtxUpdated = node_1.RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect, dateModified });
|
|
55
55
|
updateResult.addNode(nodeCtxUpdated, { sideEffect });
|
|
56
56
|
}
|
|
57
57
|
return updateResult;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodeDependentsRequiredUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAyD;AACzD,2CAAyD;AACzD,yCAAsC;AACtC,gDAA0D;AAC1D,6DAA6D;AAC7D,4EAAwE;AAExE,+
|
|
1
|
+
{"version":3,"file":"recordNodeDependentsRequiredUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAyD;AACzD,2CAAyD;AACzD,yCAAsC;AACtC,gDAA0D;AAC1D,6DAA6D;AAC7D,4EAAwE;AAExE,+FAAsG;AAEtG,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAE3D;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAChC,MAGC,EACiB,EAAE;IACpB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC3C,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,wBAAwB,iCAC9D,MAAM,KACT,OAAO,EACP,WAAW,EAAE,IAAA,oDAAc,EAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,EACzD,WAAW,EAAE,kBAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,IAC5C,CAAA;IACF,OAAO,CAAC,EAAC,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,KAAK,CAAA,CAAA;AAC1B,CAAC,CAAA,CAAA;AAdY,QAAA,kBAAkB,GAAlB,kBAAkB,CAc9B;AAED;;GAEG;AACI,MAAM,+BAA+B,GAAG,CAC7C,MAAwC,EACX,EAAE;;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IACzE,MAAM,YAAY,GAAG,IAAI,uCAA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B,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;QACxE,IAAI,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA;YAAE,SAAQ;QAClC,mFAAmF;QACnF,MAAM,0BAA0B,iCAAM,MAAM,KAAE,OAAO,EAAE,YAAY,IAAG,CAAA,CAAC,UAAU;IACnF,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAbY,QAAA,mBAAmB,GAAnB,mBAAmB,CAa/B","sourcesContent":["import { ArenaRecordNode, RecordNodes } from '../../node'\nimport { ArenaAnyNodeDef, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { ArenaRecordExpressionEvaluationContext } from './recordExpressionEvaluationContext'\nimport { getDependentNodePointersByType, getNodeCurrent } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Evaluates the \"required if\" condition of the specified child def in the context of the specified parent entity.\n */\nexport const evaluateRequiredIf = async (\n params: ArenaRecordExpressionEvaluationContext & {\n nodeCtx: ArenaRecordNode\n nodeDef: ArenaAnyNodeDef\n }\n): Promise<boolean> => {\n const { record, nodeCtx, nodeDef } = params\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n nodeCtx,\n nodeCurrent: getNodeCurrent({ record, nodeCtx, nodeDef }),\n expressions: NodeDefs.getRequiredIf(nodeDef),\n })\n return !!exprEval?.value\n}\n\n/**\n * Updates the \"required if\" flags (parent node meta `cReq`) of the node itself (if attribute) and of its dependents.\n */\nexport const updateSelfAndDependentsRequired = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false, dateModified } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.required,\n includeSelfWhenSourceIsAttribute: true,\n filterFn: (nodePointer) => NodeDefs.isRequiredIfDefined(nodePointer.nodeDef),\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const { nodeCtx: nodeCtxNodePointer, nodeDef } of nodePointersToUpdate) {\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxNodePointer.uuid) ?? nodeCtxNodePointer\n const valuePrev = RecordNodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // NOSONAR: sequential evaluation needed (see note above)\n const value = await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef }) // NOSONAR\n if (valuePrev === value) continue\n\n const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect, dateModified })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n return updateResult\n}\n\nconst updateNodeDefRequiredFlags = async (\n params: ArenaRecordExpressionEvaluationContext & {\n nodeDef: ArenaAnyNodeDef\n updateResult: RecordUpdateResult\n }\n): Promise<void> => {\n const { nodeDef, updateResult, sideEffect = false } = params\n const requiredIfDefined = NodeDefs.isRequiredIfDefined(nodeDef)\n const parentNodes = getNodesByDefUuid(nodeDef.parentUuid!)(updateResult.record)\n\n for (const parentNode of parentNodes) {\n const nodeCtx = updateResult.getNodeByUuid(parentNode.uuid) ?? parentNode\n const valuePrev = RecordNodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // sequential evaluation: the same parent node can be updated for different child defs\n const value =\n requiredIfDefined && (await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef })) // NOSONAR\n if (value !== valuePrev) {\n const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n }\n}\n\n/**\n * Recomputes the \"required if\" flags (parent node meta `cReq`) of the specified node defs in the whole record,\n * e.g. after their \"required if\" condition has been added, changed or removed. Validation is not updated.\n */\nexport const updateRequiredFlags = async (\n params: ArenaRecordExpressionEvaluationContext & { nodeDefUuids: string[] }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodeDefUuids } = params\n const updateResult = new RecordUpdateResult({ record })\n\n for (const nodeDefUuid of nodeDefUuids) {\n const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: nodeDefUuid })\n if (!nodeDef?.parentUuid) continue\n // sequential: each node def update works on the record updated by the previous one\n await updateNodeDefRequiredFlags({ ...params, nodeDef, updateResult }) // NOSONAR\n }\n return updateResult\n}\n"]}
|
|
@@ -2,6 +2,25 @@ import { ArenaRecordNode, ArenaRecordNodePointer } from '../../node';
|
|
|
2
2
|
import { ArenaAnyNodeDef, ArenaNodeDefExpression } from '../../nodeDef';
|
|
3
3
|
import { ArenaSurvey, SurveyDependencyType } from '../../survey';
|
|
4
4
|
import { ArenaRecord } from '../record';
|
|
5
|
+
/**
|
|
6
|
+
* Returns the node referenced by "this" when evaluating the expressions of a node def in the context of its parent entity:
|
|
7
|
+
* the node of the node def, if single; null if the node def is multiple (the node is not determined) or the node doesn't exist.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getNodeCurrent: (params: {
|
|
10
|
+
record: ArenaRecord;
|
|
11
|
+
nodeCtx: ArenaRecordNode;
|
|
12
|
+
nodeDef: ArenaAnyNodeDef;
|
|
13
|
+
}) => ArenaRecordNode | null;
|
|
14
|
+
/**
|
|
15
|
+
* Returns true if the expressions of the node def use the app info functions (appId, appIdLabel, appPlatform, appVersion)
|
|
16
|
+
* but the app info is not available (e.g. update done by a server job): they must not be evaluated
|
|
17
|
+
* (they would return null), the current values are kept.
|
|
18
|
+
*/
|
|
19
|
+
export declare const isAppInfoMissing: (params: {
|
|
20
|
+
survey: ArenaSurvey;
|
|
21
|
+
appInfo?: unknown;
|
|
22
|
+
nodeDef: ArenaAnyNodeDef;
|
|
23
|
+
}) => boolean;
|
|
5
24
|
export declare const throwError: (params: {
|
|
6
25
|
error: any;
|
|
7
26
|
errorKey: string;
|
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDependentNodePointersByType = exports.throwError = void 0;
|
|
3
|
+
exports.getDependentNodePointersByType = exports.throwError = exports.isAppInfoMissing = exports.getNodeCurrent = void 0;
|
|
4
4
|
const error_1 = require("../../error");
|
|
5
5
|
const nodeDef_1 = require("../../nodeDef");
|
|
6
6
|
const survey_1 = require("../../survey");
|
|
7
7
|
const records_1 = require("../records");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the node referenced by "this" when evaluating the expressions of a node def in the context of its parent entity:
|
|
10
|
+
* the node of the node def, if single; null if the node def is multiple (the node is not determined) or the node doesn't exist.
|
|
11
|
+
*/
|
|
12
|
+
const getNodeCurrent = (params) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const { record, nodeCtx, nodeDef } = params;
|
|
15
|
+
if (nodeDef_1.NodeDefs.isMultiple(nodeDef))
|
|
16
|
+
return null;
|
|
17
|
+
return (_a = records_1.Records.getChildren(nodeCtx, nodeDef.uuid)(record)[0]) !== null && _a !== void 0 ? _a : null;
|
|
18
|
+
};
|
|
19
|
+
exports.getNodeCurrent = getNodeCurrent;
|
|
20
|
+
/**
|
|
21
|
+
* Returns true if the expressions of the node def use the app info functions (appId, appIdLabel, appPlatform, appVersion)
|
|
22
|
+
* but the app info is not available (e.g. update done by a server job): they must not be evaluated
|
|
23
|
+
* (they would return null), the current values are kept.
|
|
24
|
+
*/
|
|
25
|
+
const isAppInfoMissing = (params) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const { survey, appInfo, nodeDef } = params;
|
|
28
|
+
return !appInfo && !!((_b = (_a = survey.dependencyGraph) === null || _a === void 0 ? void 0 : _a[survey_1.SurveyDependencyType.appInfo]) === null || _b === void 0 ? void 0 : _b[nodeDef.uuid]);
|
|
29
|
+
};
|
|
30
|
+
exports.isAppInfoMissing = isAppInfoMissing;
|
|
8
31
|
const throwError = (params) => {
|
|
9
32
|
const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params;
|
|
10
33
|
const nodeDefName = nodeDef.props.name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAEzC,2CAAiF;AACjF,yCAAyE;AAEzE,wCAAoC;
|
|
1
|
+
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAEzC,2CAAiF;AACjF,yCAAyE;AAEzE,wCAAoC;AAEpC;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,MAI9B,EAA0B,EAAE;;IAC3B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC3C,IAAI,kBAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAA;IAC7C,aAAO,iBAAO,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAA;AACtE,CAAC,CAAA;AARY,QAAA,cAAc,GAAd,cAAc,CAQ1B;AAED;;;;GAIG;AACI,MAAM,gBAAgB,GAAG,CAAC,MAIhC,EAAW,EAAE;;IACZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC3C,OAAO,CAAC,OAAO,IAAI,CAAC,EAAC,MAAA,MAA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,CAAC,WAAW,EAAE,CAAC,CAAA;IAClF,MAAM,WAAW,GAAG,gCAAgC,IAAI,CAAC,kBAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IAEzF,MAAM,YAAY,GAAG,iBAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAA;IAElH,IAAI,CAAC,kBAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,0EAA0E;IAC1E,IAAI,oBAAoB,EAAE,CAAC;QACzB,uBAAuB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1F,CAAC;IAED,uGAAuG;IACvG,IAAI,6BAA6B,EAAE,CAAC;QAClC,iCAAiC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAzCY,QAAA,8BAA8B,GAA9B,8BAA8B,CAyC1C","sourcesContent":["import { SystemError } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer } from '../../node'\nimport { ArenaAnyNodeDef, ArenaNodeDefExpression, NodeDefs } from '../../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../../survey'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\n/**\n * Returns the node referenced by \"this\" when evaluating the expressions of a node def in the context of its parent entity:\n * the node of the node def, if single; null if the node def is multiple (the node is not determined) or the node doesn't exist.\n */\nexport const getNodeCurrent = (params: {\n record: ArenaRecord\n nodeCtx: ArenaRecordNode\n nodeDef: ArenaAnyNodeDef\n}): ArenaRecordNode | null => {\n const { record, nodeCtx, nodeDef } = params\n if (NodeDefs.isMultiple(nodeDef)) return null\n return Records.getChildren(nodeCtx, nodeDef.uuid)(record)[0] ?? null\n}\n\n/**\n * Returns true if the expressions of the node def use the app info functions (appId, appIdLabel, appPlatform, appVersion)\n * but the app info is not available (e.g. update done by a server job): they must not be evaluated\n * (they would return null), the current values are kept.\n */\nexport const isAppInfoMissing = (params: {\n survey: ArenaSurvey\n appInfo?: unknown\n nodeDef: ArenaAnyNodeDef\n}): boolean => {\n const { survey, appInfo, nodeDef } = params\n return !appInfo && !!survey.dependencyGraph?.[SurveyDependencyType.appInfo]?.[nodeDef.uuid]\n}\n\nexport const throwError = (params: {\n error: any\n errorKey: string\n expressionType: SurveyDependencyType\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n expressionsToEvaluate: ArenaNodeDefExpression[]\n}) => {\n const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params\n const nodeDefName = nodeDef.props.name\n const expressionsString = JSON.stringify(expressionsToEvaluate)\n\n throw new SystemError(\n errorKey,\n {\n surveyName: survey.props.name,\n nodeDefName,\n expressionType,\n expressionsString,\n error: error.toString(),\n errorJson: error instanceof SystemError ? error.toJSON() : null,\n },\n { cause: error }\n )\n}\n\nconst addPointerIfAccepted = (params: {\n nodePointers: ArenaRecordNodePointer[]\n pointer: ArenaRecordNodePointer\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, pointer, filterFn } = params\n if (!filterFn || filterFn(pointer)) {\n nodePointers.push(pointer)\n }\n}\n\nconst addNewEntitySelfPointer = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, record, node, sourceNodeDef, filterFn } = params\n if (!node.parentUuid) {\n return\n }\n const parentNode = Records.getNodeByUuid(node.parentUuid)(record)\n if (!parentNode) {\n return\n }\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: parentNode, nodeDef: sourceNodeDef },\n filterFn,\n })\n}\n\nconst addNewEntityChildMultiplePointers = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, survey, node, sourceNodeDef, filterFn } = params\n const multipleNodeDefs = Surveys.getNodeDefChildren({ survey, nodeDef: sourceNodeDef }).filter(NodeDefs.isMultiple)\n\n for (const childDef of multipleNodeDefs) {\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: node, nodeDef: childDef },\n filterFn,\n })\n }\n}\n\nexport const getDependentNodePointersByType = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n dependencyType: SurveyDependencyType\n includeSelfWhenSourceIsAttribute?: boolean\n includeNewEntitySelf?: boolean\n includeNewEntityChildPointers?: boolean\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}): ArenaRecordNodePointer[] => {\n const {\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute = false,\n includeNewEntitySelf = false,\n includeNewEntityChildPointers = false,\n filterFn,\n } = params\n\n const sourceNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const includeSelf = includeSelfWhenSourceIsAttribute && !NodeDefs.isEntity(sourceNodeDef)\n\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType, includeSelf, filterFn)(record)\n\n if (!NodeDefs.isEntity(sourceNodeDef) || !node.created) {\n return nodePointers\n }\n\n // For newly created entities, include a self-pointer for the source node.\n if (includeNewEntitySelf) {\n addNewEntitySelfPointer({ nodePointers, survey, record, node, sourceNodeDef, filterFn })\n }\n\n // For new entities, include child multiple nodes so their dependency metadata/status gets updated too.\n if (includeNewEntityChildPointers) {\n addNewEntityChildMultiplePointers({ nodePointers, survey, node, sourceNodeDef, filterFn })\n }\n\n return nodePointers\n}\n"]}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { ArenaDictionary } from '../../common';
|
|
2
|
-
import { ArenaRecordNode } from '../../node';
|
|
2
|
+
import { ArenaRecordNode, ArenaRecordNodesMap } from '../../node';
|
|
3
3
|
import { ArenaRecordNodesUpdateParams } from './recordNodesCreator';
|
|
4
4
|
import { RecordUpdateResult } from './recordUpdateResult';
|
|
5
|
+
/**
|
|
6
|
+
* Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).
|
|
7
|
+
* The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).
|
|
8
|
+
* @param params.nodes - Nodes created, updated or deleted.
|
|
9
|
+
* @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).
|
|
10
|
+
*/
|
|
5
11
|
export declare const updateNodesDependents: (params: ArenaRecordNodesUpdateParams & {
|
|
6
12
|
nodes: ArenaDictionary<ArenaRecordNode>;
|
|
13
|
+
nodesToEvaluate?: ArenaRecordNodesMap;
|
|
7
14
|
}) => Promise<RecordUpdateResult>;
|