@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
|
@@ -7,10 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { Queue } from '../../utils';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
10
|
+
import { Dates, Queue } from '../../utils';
|
|
11
|
+
import { RecordNodes } from '../../node';
|
|
12
|
+
import { NodeDefCountType, NodeDefs } from '../../nodeDef';
|
|
13
|
+
import { SurveyDependencyType, Surveys } from '../../survey';
|
|
14
|
+
import { getDependentNodePointers, getDescendantsOrSelf, getNodeByUuid, getNodesByDefUuid, } from '../_records/recordGetters';
|
|
15
|
+
import { RecordNodePointers } from '../nodePointers';
|
|
14
16
|
import { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater';
|
|
15
17
|
import { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater';
|
|
16
18
|
import { updateDependentsCount } from './recordNodeDependentsCountUpdater';
|
|
@@ -44,11 +46,81 @@ const dependentsUpdaters = [
|
|
|
44
46
|
updateDependentEnumeratingItemsEntities,
|
|
45
47
|
updateSelfAndDependentsFileNames,
|
|
46
48
|
];
|
|
49
|
+
/**
|
|
50
|
+
* True if the node modification changes the date modified of its ancestors:
|
|
51
|
+
* nodes created or deleted, and attributes (whose value changed); entities updated only in their meta
|
|
52
|
+
* (e.g. children applicability) are excluded.
|
|
53
|
+
*/
|
|
54
|
+
const isModificationPropagatedToAncestors = (survey, node) => {
|
|
55
|
+
if (node.created || node.deleted)
|
|
56
|
+
return true;
|
|
57
|
+
const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: node.nodeDefUuid });
|
|
58
|
+
return !!nodeDef && !NodeDefs.isEntity(nodeDef);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Sets the date modified of the ancestors of the specified node (if not set already).
|
|
62
|
+
* @returns The ancestors updated.
|
|
63
|
+
*/
|
|
64
|
+
const updateAncestorsDateModified = (params) => {
|
|
65
|
+
var _a;
|
|
66
|
+
const { node, updateResult, dateModified, sideEffect } = params;
|
|
67
|
+
const ancestorsUpdated = [];
|
|
68
|
+
for (const ancestorUuid of RecordNodes.getHierarchy(node)) {
|
|
69
|
+
const ancestor = (_a = updateResult.getNodeByUuid(ancestorUuid)) !== null && _a !== void 0 ? _a : getNodeByUuid(ancestorUuid)(updateResult.record);
|
|
70
|
+
if (!ancestor || ancestor.deleted || ancestor.dateModified === dateModified)
|
|
71
|
+
continue;
|
|
72
|
+
const ancestorAlreadyUpdated = !!updateResult.getNodeByUuid(ancestorUuid);
|
|
73
|
+
const ancestorUpdated = sideEffect ? ancestor : Object.assign({}, ancestor);
|
|
74
|
+
ancestorUpdated.dateModified = dateModified;
|
|
75
|
+
ancestorUpdated.updated = true;
|
|
76
|
+
updateResult.addNode(ancestorUpdated, { sideEffect });
|
|
77
|
+
if (!ancestorAlreadyUpdated) {
|
|
78
|
+
updateResult.dateModifiedOnlyNodeUuids.add(ancestorUuid);
|
|
79
|
+
}
|
|
80
|
+
ancestorsUpdated.push(ancestorUpdated);
|
|
81
|
+
}
|
|
82
|
+
return ancestorsUpdated;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Returns the nodes whose expressions use the dates of the specified entity (nodeDateCreated, nodeDateModified),
|
|
86
|
+
* e.g. the attributes in the entity with the expression "nodeDateModified(parent(this))".
|
|
87
|
+
*/
|
|
88
|
+
const getNodeDatesDependentNodes = (params) => {
|
|
89
|
+
const { survey, record, entity } = params;
|
|
90
|
+
const dependentDefs = Surveys.getNodeDefDependents({
|
|
91
|
+
survey,
|
|
92
|
+
nodeDefUuid: entity.nodeDefUuid,
|
|
93
|
+
dependencyType: SurveyDependencyType.nodeDates,
|
|
94
|
+
});
|
|
95
|
+
if (dependentDefs.length === 0)
|
|
96
|
+
return [];
|
|
97
|
+
const result = [];
|
|
98
|
+
for (const dependentDef of dependentDefs) {
|
|
99
|
+
if (dependentDef.meta.h.includes(entity.nodeDefUuid)) {
|
|
100
|
+
// dependent def is a descendant of the entity def: only the dependent nodes in the entity are affected
|
|
101
|
+
result.push(...getDescendantsOrSelf(entity, dependentDef)(record));
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const nodePointers = getDependentNodePointers(survey, entity, SurveyDependencyType.nodeDates, false, (nodePointer) => nodePointer.nodeDef.uuid === dependentDef.uuid)(record);
|
|
105
|
+
result.push(...RecordNodePointers.getNodesFromNodePointers({ record, nodePointers }));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).
|
|
112
|
+
* The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).
|
|
113
|
+
* @param params.nodes - Nodes created, updated or deleted.
|
|
114
|
+
* @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).
|
|
115
|
+
*/
|
|
47
116
|
export const updateNodesDependents = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
117
|
var _a;
|
|
49
|
-
|
|
118
|
+
var _b, _c, _d;
|
|
119
|
+
const { survey, record, nodes, nodesToEvaluate, sideEffect = false } = params;
|
|
120
|
+
// the same date modified is used for all the nodes modified (it lets the propagation to the ancestors end)
|
|
121
|
+
const dateModified = (_b = params.dateModified) !== null && _b !== void 0 ? _b : Dates.nowFormattedForStorage();
|
|
50
122
|
// always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited
|
|
51
|
-
const initialNodesToVisit = Object.assign({}, nodes);
|
|
123
|
+
const initialNodesToVisit = Object.assign(Object.assign({}, nodesToEvaluate), nodes);
|
|
52
124
|
// include onUpdate dependents (always included in every record update)
|
|
53
125
|
const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey });
|
|
54
126
|
if (onUpdateDependentDefs.length > 0) {
|
|
@@ -60,14 +132,44 @@ export const updateNodesDependents = (params) => __awaiter(void 0, void 0, void
|
|
|
60
132
|
}
|
|
61
133
|
}
|
|
62
134
|
const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit });
|
|
63
|
-
const createNodeUpdateParams = (node) => (Object.assign(Object.assign({}, params), { record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)
|
|
135
|
+
const createNodeUpdateParams = (node) => (Object.assign(Object.assign({}, params), { dateModified, record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)
|
|
64
136
|
node }));
|
|
65
137
|
const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit));
|
|
138
|
+
const hasNodeDatesDependencies = Object.keys((_c = (_a = survey.dependencyGraph) === null || _a === void 0 ? void 0 : _a[SurveyDependencyType.nodeDates]) !== null && _c !== void 0 ? _c : {}).length > 0;
|
|
139
|
+
// the dependents of the entities whose date modified changed (e.g. "nodeDateModified(parent(this))") are visited
|
|
140
|
+
// as sources ("self" evaluation): the entities themselves are not visited, they are not modified in their content
|
|
141
|
+
const visitNodeDatesDependents = (entities) => {
|
|
142
|
+
var _a;
|
|
143
|
+
var _b, _c;
|
|
144
|
+
if (!hasNodeDatesDependencies)
|
|
145
|
+
return;
|
|
146
|
+
for (const entity of entities) {
|
|
147
|
+
for (const dependentNode of getNodeDatesDependentNodes({ survey, record: updateResult.record, entity })) {
|
|
148
|
+
// included in the result (like the onUpdate dependents) so their validation is updated too
|
|
149
|
+
(_a = (_b = updateResult.nodes)[_c = dependentNode.uuid]) !== null && _a !== void 0 ? _a : (_b[_c] = dependentNode);
|
|
150
|
+
nodeUuidsToVisit.enqueue(dependentNode.uuid);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
const updateAncestorsOfModifiedNodes = (modifiedNodes) => {
|
|
155
|
+
const entitiesUpdated = [];
|
|
156
|
+
for (const modifiedNode of modifiedNodes) {
|
|
157
|
+
if (isModificationPropagatedToAncestors(survey, modifiedNode)) {
|
|
158
|
+
entitiesUpdated.push(...updateAncestorsDateModified({ node: modifiedNode, updateResult, dateModified, sideEffect }));
|
|
159
|
+
}
|
|
160
|
+
else if (!modifiedNode.deleted) {
|
|
161
|
+
// entity updated in its meta (e.g. children applicability): its date modified changed
|
|
162
|
+
entitiesUpdated.push(modifiedNode);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
visitNodeDatesDependents(entitiesUpdated);
|
|
166
|
+
};
|
|
167
|
+
updateAncestorsOfModifiedNodes(Object.values(nodes));
|
|
66
168
|
// Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)
|
|
67
169
|
const visitedCountByUuid = {};
|
|
68
170
|
while (!nodeUuidsToVisit.isEmpty()) {
|
|
69
171
|
const nodeUuid = nodeUuidsToVisit.dequeue();
|
|
70
|
-
const visitedCount = (
|
|
172
|
+
const visitedCount = (_d = visitedCountByUuid[nodeUuid]) !== null && _d !== void 0 ? _d : 0;
|
|
71
173
|
if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {
|
|
72
174
|
const nodesUpdatedCurrent = {};
|
|
73
175
|
for (const dependentsUpdater of dependentsUpdaters) {
|
|
@@ -79,6 +181,7 @@ export const updateNodesDependents = (params) => __awaiter(void 0, void 0, void
|
|
|
79
181
|
}
|
|
80
182
|
// Mark updated nodes to visit
|
|
81
183
|
nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent));
|
|
184
|
+
updateAncestorsOfModifiedNodes(Object.values(nodesUpdatedCurrent));
|
|
82
185
|
// Mark node as visited
|
|
83
186
|
visitedCountByUuid[nodeUuid] = visitedCount + 1;
|
|
84
187
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodes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AAA;QAE5C,MAAM,YAAY,SAAG,kBAAkB,CAAC,QAAQ,CAAC,mCAAI,CAAC,CAAA;QAEtD,IAAI,YAAY,GAAG,6BAA6B,EAAE,CAAC;YACjD,MAAM,mBAAmB,GAAqC,EAAE,CAAA;YAChE,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;gBACnD,uGAAuG;gBACvG,MAAM,IAAI,GAAG,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;gBACjD,MAAM,sBAAsB,GAAG,MAAM,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,UAAU;gBAC/F,YAAY,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;gBAC1C,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;YAClE,CAAC;YAED,8BAA8B;YAC9B,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAE/D,uBAAuB;YACvB,kBAAkB,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { Queue } from '../../utils'\n\nimport { ArenaDictionary } from '../../common'\nimport { ArenaRecordNode } from '../../node'\nimport { NodeDefCountType } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater'\nimport { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater'\nimport { updateDependentsCount } from './recordNodeDependentsCountUpdater'\nimport { updateSelfAndDependentsDefaultValues } from './recordNodeDependentsDefaultValuesUpdater'\nimport { updateSelfAndDependentsEditable } from './recordNodeDependentsEditableUpdater'\nimport { updateDependentEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { updateDependentEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { updateSelfAndDependentsFileNames } from './recordNodeDependentsFileNamesEvaluator'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { updateSelfAndDependentsRequired } from './recordNodeDependentsRequiredUpdater'\nimport { updateSelfAndDependentsVisible } from './recordNodeDependentsVisibleUpdater'\nimport { ArenaRecordNodesUpdateParams } from './recordNodesCreator'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n/**\n * Nodes can be visited maximum 2 times during the update of the dependent nodes, to avoid loops in the evaluation.\n * The first time the applicability can depend on attributes with default values not applied yet.\n * The second time the applicability expression can be evaluated correctly.\n */\nconst MAX_DEPENDENTS_VISITING_TIMES = 2\n\ntype RecordNodeDependentsUpdater = (params: RecordNodeDependentsUpdateParams) => Promise<RecordUpdateResult>\n\n/**\n * Updaters applied (in this order) to every visited node and to its dependents.\n */\nconst dependentsUpdaters: RecordNodeDependentsUpdater[] = [\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.min }),\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.max }),\n updateSelfAndDependentsApplicable,\n updateSelfAndDependentsDefaultValues,\n updateSelfAndDependentsEditable,\n updateSelfAndDependentsRequired,\n updateSelfAndDependentsVisible,\n updateDependentCodeAttributes,\n updateDependentEnumeratedEntities,\n updateDependentEnumeratingItemsEntities,\n updateSelfAndDependentsFileNames,\n]\n\nexport const updateNodesDependents = async (\n params: ArenaRecordNodesUpdateParams & { nodes: ArenaDictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes } = params\n // always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited\n const initialNodesToVisit = { ...nodes }\n\n // include onUpdate dependents (always included in every record update)\n const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey })\n if (onUpdateDependentDefs.length > 0) {\n for (const dependentDef of onUpdateDependentDefs) {\n const dependentNodes = getNodesByDefUuid(dependentDef.uuid)(record)\n for (const node of dependentNodes) {\n initialNodesToVisit[node.uuid] = node\n }\n }\n }\n\n const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit })\n\n const createNodeUpdateParams = (node: ArenaRecordNode): RecordNodeDependentsUpdateParams => ({\n ...params,\n record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)\n node,\n })\n\n const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit))\n\n // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)\n const visitedCountByUuid: ArenaDictionary<number> = {}\n\n while (!nodeUuidsToVisit.isEmpty()) {\n const nodeUuid = nodeUuidsToVisit.dequeue()!\n\n const visitedCount = visitedCountByUuid[nodeUuid] ?? 0\n\n if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {\n const nodesUpdatedCurrent: ArenaDictionary<ArenaRecordNode> = {}\n for (const dependentsUpdater of dependentsUpdaters) {\n // updaters must run sequentially: each one works on the record (and node) updated by the previous ones\n const node = updateResult.getNodeByUuid(nodeUuid)\n const dependentsUpdateResult = await dependentsUpdater(createNodeUpdateParams(node)) // NOSONAR\n updateResult.merge(dependentsUpdateResult)\n Object.assign(nodesUpdatedCurrent, dependentsUpdateResult.nodes)\n }\n\n // Mark updated nodes to visit\n nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent))\n\n // Mark node as visited\n visitedCountByUuid[nodeUuid] = visitedCount + 1\n }\n }\n\n return updateResult\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recordNodesUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodesUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,EAAwC,WAAW,EAAE,MAAM,YAAY,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA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CAAC,CAAC,CAAA;IAEpD,+GAA+G;IAC/G,MAAM,kBAAkB,GAA4B,EAAE,CAAA;IAEtD,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,EAAG,CAAA;QAE5C,MAAM,YAAY,SAAG,kBAAkB,CAAC,QAAQ,CAAC,mCAAI,CAAC,CAAA;QAEtD,IAAI,YAAY,GAAG,6BAA6B,EAAE,CAAC;YACjD,MAAM,mBAAmB,GAAqC,EAAE,CAAA;YAChE,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;gBACnD,uGAAuG;gBACvG,MAAM,IAAI,GAAG,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;gBACjD,MAAM,sBAAsB,GAAG,MAAM,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,UAAU;gBAC/F,YAAY,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;gBAC1C,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;YAClE,CAAC;YAED,8BAA8B;YAC9B,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAC/D,8BAA8B,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAElE,uBAAuB;YACvB,kBAAkB,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { Dates, Queue } from '../../utils'\n\nimport { ArenaDictionary } from '../../common'\nimport { ArenaRecordNode, ArenaRecordNodesMap, RecordNodes } from '../../node'\nimport { NodeDefCountType, NodeDefs } from '../../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../../survey'\nimport {\n getDependentNodePointers,\n getDescendantsOrSelf,\n getNodeByUuid,\n getNodesByDefUuid,\n} from '../_records/recordGetters'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater'\nimport { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater'\nimport { updateDependentsCount } from './recordNodeDependentsCountUpdater'\nimport { updateSelfAndDependentsDefaultValues } from './recordNodeDependentsDefaultValuesUpdater'\nimport { updateSelfAndDependentsEditable } from './recordNodeDependentsEditableUpdater'\nimport { updateDependentEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { updateDependentEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { updateSelfAndDependentsFileNames } from './recordNodeDependentsFileNamesEvaluator'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { updateSelfAndDependentsRequired } from './recordNodeDependentsRequiredUpdater'\nimport { updateSelfAndDependentsVisible } from './recordNodeDependentsVisibleUpdater'\nimport { ArenaRecordNodesUpdateParams } from './recordNodesCreator'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n/**\n * Nodes can be visited maximum 2 times during the update of the dependent nodes, to avoid loops in the evaluation.\n * The first time the applicability can depend on attributes with default values not applied yet.\n * The second time the applicability expression can be evaluated correctly.\n */\nconst MAX_DEPENDENTS_VISITING_TIMES = 2\n\ntype RecordNodeDependentsUpdater = (params: RecordNodeDependentsUpdateParams) => Promise<RecordUpdateResult>\n\n/**\n * Updaters applied (in this order) to every visited node and to its dependents.\n */\nconst dependentsUpdaters: RecordNodeDependentsUpdater[] = [\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.min }),\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.max }),\n updateSelfAndDependentsApplicable,\n updateSelfAndDependentsDefaultValues,\n updateSelfAndDependentsEditable,\n updateSelfAndDependentsRequired,\n updateSelfAndDependentsVisible,\n updateDependentCodeAttributes,\n updateDependentEnumeratedEntities,\n updateDependentEnumeratingItemsEntities,\n updateSelfAndDependentsFileNames,\n]\n\n/**\n * True if the node modification changes the date modified of its ancestors:\n * nodes created or deleted, and attributes (whose value changed); entities updated only in their meta\n * (e.g. children applicability) are excluded.\n */\nconst isModificationPropagatedToAncestors = (survey: ArenaSurvey, node: ArenaRecordNode): boolean => {\n if (node.created || node.deleted) return true\n const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n return !!nodeDef && !NodeDefs.isEntity(nodeDef)\n}\n\n/**\n * Sets the date modified of the ancestors of the specified node (if not set already).\n * @returns The ancestors updated.\n */\nconst updateAncestorsDateModified = (params: {\n node: ArenaRecordNode\n updateResult: RecordUpdateResult\n dateModified: string\n sideEffect: boolean\n}): ArenaRecordNode[] => {\n const { node, updateResult, dateModified, sideEffect } = params\n const ancestorsUpdated: ArenaRecordNode[] = []\n for (const ancestorUuid of RecordNodes.getHierarchy(node)) {\n const ancestor = updateResult.getNodeByUuid(ancestorUuid) ?? getNodeByUuid(ancestorUuid)(updateResult.record)\n if (!ancestor || ancestor.deleted || ancestor.dateModified === dateModified) continue\n\n const ancestorAlreadyUpdated = !!updateResult.getNodeByUuid(ancestorUuid)\n const ancestorUpdated = sideEffect ? ancestor : { ...ancestor }\n ancestorUpdated.dateModified = dateModified\n ancestorUpdated.updated = true\n updateResult.addNode(ancestorUpdated, { sideEffect })\n if (!ancestorAlreadyUpdated) {\n updateResult.dateModifiedOnlyNodeUuids.add(ancestorUuid)\n }\n ancestorsUpdated.push(ancestorUpdated)\n }\n return ancestorsUpdated\n}\n\n/**\n * Returns the nodes whose expressions use the dates of the specified entity (nodeDateCreated, nodeDateModified),\n * e.g. the attributes in the entity with the expression \"nodeDateModified(parent(this))\".\n */\nconst getNodeDatesDependentNodes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n entity: ArenaRecordNode\n}): ArenaRecordNode[] => {\n const { survey, record, entity } = params\n const dependentDefs = Surveys.getNodeDefDependents({\n survey,\n nodeDefUuid: entity.nodeDefUuid,\n dependencyType: SurveyDependencyType.nodeDates,\n })\n if (dependentDefs.length === 0) return []\n\n const result: ArenaRecordNode[] = []\n for (const dependentDef of dependentDefs) {\n if (dependentDef.meta.h.includes(entity.nodeDefUuid)) {\n // dependent def is a descendant of the entity def: only the dependent nodes in the entity are affected\n result.push(...getDescendantsOrSelf(entity, dependentDef)(record))\n } else {\n const nodePointers = getDependentNodePointers(\n survey,\n entity,\n SurveyDependencyType.nodeDates,\n false,\n (nodePointer) => nodePointer.nodeDef.uuid === dependentDef.uuid\n )(record)\n result.push(...RecordNodePointers.getNodesFromNodePointers({ record, nodePointers }))\n }\n }\n return result\n}\n\n/**\n * Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).\n * The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).\n * @param params.nodes - Nodes created, updated or deleted.\n * @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).\n */\nexport const updateNodesDependents = async (\n params: ArenaRecordNodesUpdateParams & {\n nodes: ArenaDictionary<ArenaRecordNode>\n nodesToEvaluate?: ArenaRecordNodesMap\n }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes, nodesToEvaluate, sideEffect = false } = params\n // the same date modified is used for all the nodes modified (it lets the propagation to the ancestors end)\n const dateModified = params.dateModified ?? Dates.nowFormattedForStorage()\n // always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited\n const initialNodesToVisit = { ...nodesToEvaluate, ...nodes }\n\n // include onUpdate dependents (always included in every record update)\n const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey })\n if (onUpdateDependentDefs.length > 0) {\n for (const dependentDef of onUpdateDependentDefs) {\n const dependentNodes = getNodesByDefUuid(dependentDef.uuid)(record)\n for (const node of dependentNodes) {\n initialNodesToVisit[node.uuid] = node\n }\n }\n }\n\n const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit })\n\n const createNodeUpdateParams = (node: ArenaRecordNode): RecordNodeDependentsUpdateParams => ({\n ...params,\n dateModified,\n record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)\n node,\n })\n\n const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit))\n\n const hasNodeDatesDependencies =\n Object.keys(survey.dependencyGraph?.[SurveyDependencyType.nodeDates] ?? {}).length > 0\n\n // the dependents of the entities whose date modified changed (e.g. \"nodeDateModified(parent(this))\") are visited\n // as sources (\"self\" evaluation): the entities themselves are not visited, they are not modified in their content\n const visitNodeDatesDependents = (entities: ArenaRecordNode[]): void => {\n if (!hasNodeDatesDependencies) return\n for (const entity of entities) {\n for (const dependentNode of getNodeDatesDependentNodes({ survey, record: updateResult.record, entity })) {\n // included in the result (like the onUpdate dependents) so their validation is updated too\n updateResult.nodes[dependentNode.uuid] ??= dependentNode\n nodeUuidsToVisit.enqueue(dependentNode.uuid)\n }\n }\n }\n\n const updateAncestorsOfModifiedNodes = (modifiedNodes: ArenaRecordNode[]): void => {\n const entitiesUpdated: ArenaRecordNode[] = []\n for (const modifiedNode of modifiedNodes) {\n if (isModificationPropagatedToAncestors(survey, modifiedNode)) {\n entitiesUpdated.push(\n ...updateAncestorsDateModified({ node: modifiedNode, updateResult, dateModified, sideEffect })\n )\n } else if (!modifiedNode.deleted) {\n // entity updated in its meta (e.g. children applicability): its date modified changed\n entitiesUpdated.push(modifiedNode)\n }\n }\n visitNodeDatesDependents(entitiesUpdated)\n }\n updateAncestorsOfModifiedNodes(Object.values(nodes))\n\n // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)\n const visitedCountByUuid: ArenaDictionary<number> = {}\n\n while (!nodeUuidsToVisit.isEmpty()) {\n const nodeUuid = nodeUuidsToVisit.dequeue()!\n\n const visitedCount = visitedCountByUuid[nodeUuid] ?? 0\n\n if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {\n const nodesUpdatedCurrent: ArenaDictionary<ArenaRecordNode> = {}\n for (const dependentsUpdater of dependentsUpdaters) {\n // updaters must run sequentially: each one works on the record (and node) updated by the previous ones\n const node = updateResult.getNodeByUuid(nodeUuid)\n const dependentsUpdateResult = await dependentsUpdater(createNodeUpdateParams(node)) // NOSONAR\n updateResult.merge(dependentsUpdateResult)\n Object.assign(nodesUpdatedCurrent, dependentsUpdateResult.nodes)\n }\n\n // Mark updated nodes to visit\n nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent))\n updateAncestorsOfModifiedNodes(Object.values(nodesUpdatedCurrent))\n\n // Mark node as visited\n visitedCountByUuid[nodeUuid] = visitedCount + 1\n }\n }\n\n return updateResult\n}\n"]}
|
|
@@ -6,6 +6,7 @@ export class RecordUpdateResult {
|
|
|
6
6
|
this.nodes = (_a = params.nodes) !== null && _a !== void 0 ? _a : {};
|
|
7
7
|
this.nodesDeleted = (_b = params.nodesDeleted) !== null && _b !== void 0 ? _b : {};
|
|
8
8
|
this.clearedDefUuids = (_c = params.clearedDefUuids) !== null && _c !== void 0 ? _c : new Set();
|
|
9
|
+
this.dateModifiedOnlyNodeUuids = new Set();
|
|
9
10
|
this.validation = params.validation;
|
|
10
11
|
}
|
|
11
12
|
getNodeByUuid(uuid) {
|
|
@@ -37,6 +38,15 @@ export class RecordUpdateResult {
|
|
|
37
38
|
for (const nodeDefUuid of recordUpdateResult.clearedDefUuids) {
|
|
38
39
|
this.addClearedDefUuid(nodeDefUuid);
|
|
39
40
|
}
|
|
41
|
+
for (const nodeUuid of Object.keys(recordUpdateResult.nodes)) {
|
|
42
|
+
// node updated in the merged result: not only in its date modified anymore
|
|
43
|
+
if (!recordUpdateResult.dateModifiedOnlyNodeUuids.has(nodeUuid)) {
|
|
44
|
+
this.dateModifiedOnlyNodeUuids.delete(nodeUuid);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const nodeUuid of recordUpdateResult.dateModifiedOnlyNodeUuids) {
|
|
48
|
+
this.dateModifiedOnlyNodeUuids.add(nodeUuid);
|
|
49
|
+
}
|
|
40
50
|
return this;
|
|
41
51
|
}
|
|
42
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordUpdateResult.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordUpdateResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAG7D,MAAM,OAAO,kBAAkB;
|
|
1
|
+
{"version":3,"file":"recordUpdateResult.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordUpdateResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAG7D,MAAM,OAAO,kBAAkB;IAY7B,YAAY,MAMX;;QACC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC3B,IAAI,CAAC,KAAK,SAAG,MAAM,CAAC,KAAK,mCAAI,EAAE,CAAA;QAC/B,IAAI,CAAC,YAAY,SAAG,MAAM,CAAC,YAAY,mCAAI,EAAE,CAAA;QAC7C,IAAI,CAAC,eAAe,SAAG,MAAM,CAAC,eAAe,mCAAI,IAAI,GAAG,EAAU,CAAA;QAClE,IAAI,CAAC,yBAAyB,GAAG,IAAI,GAAG,EAAU,CAAA;QAClD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IACrC,CAAC;IAED,aAAa,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IAED,OAAO,CAAC,IAAqB,EAAE,OAAkC;QAC/D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACnD,CAAC;IAED,QAAQ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enaValidation } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { addNode, addNodes } from '../_records/recordUpdater'\nimport { ArenaRecordUpdateOptions } from '../records'\n\nexport class RecordUpdateResult {\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n nodesDeleted: ArenaRecordNodesMap\n clearedDefUuids: Set<string>\n /**\n * Uuids of the nodes (ancestor entities) updated only in their date modified (because a descendant has been modified):\n * to be persisted, but not to be validated again.\n */\n dateModifiedOnlyNodeUuids: Set<string>\n validation?: ArenaValidation\n\n constructor(params: {\n record: ArenaRecord\n nodes?: ArenaRecordNodesMap\n nodesDeleted?: ArenaRecordNodesMap\n clearedDefUuids?: Set<string>\n validation?: ArenaValidation\n }) {\n this.record = params.record\n this.nodes = params.nodes ?? {}\n this.nodesDeleted = params.nodesDeleted ?? {}\n this.clearedDefUuids = params.clearedDefUuids ?? new Set<string>()\n this.dateModifiedOnlyNodeUuids = new Set<string>()\n this.validation = params.validation\n }\n\n getNodeByUuid(uuid: string) {\n return this.nodes[uuid]\n }\n\n addNode(node: ArenaRecordNode, options?: ArenaRecordUpdateOptions) {\n this.nodes[node.uuid] = node\n this.record = addNode(node, options)(this.record)\n }\n\n addNodes(nodes: ArenaRecordNodesMap, options?: ArenaRecordUpdateOptions) {\n Object.assign(this.nodes, nodes)\n this.record = addNodes(nodes, options)(this.record)\n }\n\n addClearedDefUuid(nodeDefUuid: string) {\n this.clearedDefUuids.add(nodeDefUuid)\n }\n\n /**\n * Merges this record update result with the specified one.\n * The record of this record update result will be the one of the specified record update result\n * and the nodes of the specified one will be added to the nodes of this one.\n *\n * @param {!RecordUpdateResult} recordUpdateResult - The record update result to merge with.\n * @returns {RecordUpdateResult} - The updated object.\n */\n merge(recordUpdateResult: RecordUpdateResult): this {\n this.record = recordUpdateResult.record\n Object.assign(this.nodes, recordUpdateResult.nodes)\n Object.assign(this.nodesDeleted, recordUpdateResult.nodesDeleted)\n for (const nodeDefUuid of recordUpdateResult.clearedDefUuids) {\n this.addClearedDefUuid(nodeDefUuid)\n }\n for (const nodeUuid of Object.keys(recordUpdateResult.nodes)) {\n // node updated in the merged result: not only in its date modified anymore\n if (!recordUpdateResult.dateModifiedOnlyNodeUuids.has(nodeUuid)) {\n this.dateModifiedOnlyNodeUuids.delete(nodeUuid)\n }\n }\n for (const nodeUuid of recordUpdateResult.dateModifiedOnlyNodeUuids) {\n this.dateModifiedOnlyNodeUuids.add(nodeUuid)\n }\n return this\n }\n}\n"]}
|
|
@@ -13,7 +13,7 @@ import { SurveyDependencyType, Surveys } from '../survey';
|
|
|
13
13
|
import { Dates, Objects } from '../utils';
|
|
14
14
|
import { Validations } from '../validation/validations';
|
|
15
15
|
import { RecordNodePointers } from './nodePointers';
|
|
16
|
-
import { RecordNodesUpdater } from './recordNodesUpdater';
|
|
16
|
+
import { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater';
|
|
17
17
|
import { Records } from './records';
|
|
18
18
|
import { RecordValidator } from './recordValidator';
|
|
19
19
|
const validationDependencyTypes = [
|
|
@@ -40,10 +40,42 @@ const getDependentValidationNodePointers = (params) => {
|
|
|
40
40
|
}
|
|
41
41
|
return Array.from(uniquePointersByKey.values());
|
|
42
42
|
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
/**
|
|
44
|
+
* If the record is being updated with an app different from the one that updated it last (see Records.isAppInfoChanged),
|
|
45
|
+
* stores the app info in the record (info.modifiedWith) and returns the nodes whose expressions use the app info functions,
|
|
46
|
+
* so they will be evaluated again.
|
|
47
|
+
*/
|
|
48
|
+
const _updateAppInfo = (params) => {
|
|
49
|
+
const { survey, record, appInfo, sideEffect = false } = params;
|
|
50
|
+
if (!appInfo || !Records.isAppInfoChanged(appInfo)(record)) {
|
|
51
|
+
return { record, appInfoDependentNodes: {} };
|
|
52
|
+
}
|
|
53
|
+
const recordUpdated = sideEffect ? record : Object.assign({}, record);
|
|
54
|
+
recordUpdated.info = Object.assign(Object.assign({}, recordUpdated.info), { modifiedWith: appInfo });
|
|
55
|
+
const appInfoDependentNodes = {};
|
|
56
|
+
for (const nodeDef of Surveys.getAppInfoDependents({ survey })) {
|
|
57
|
+
for (const node of Records.getNodesByDefUuid(nodeDef.uuid)(recordUpdated)) {
|
|
58
|
+
appInfoDependentNodes[node.uuid] = node;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { record: recordUpdated, appInfoDependentNodes };
|
|
62
|
+
};
|
|
63
|
+
const _onRecordNodesCreateOrUpdate = (paramsIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
64
|
+
var _a;
|
|
65
|
+
const { record: recordWithAppInfo, appInfoDependentNodes } = _updateAppInfo(paramsIn);
|
|
66
|
+
const params = Object.assign(Object.assign({}, paramsIn), {
|
|
67
|
+
// the same date modified is used for all the nodes modified in this update
|
|
68
|
+
dateModified: (_a = paramsIn.dateModified) !== null && _a !== void 0 ? _a : Dates.nowFormattedForStorage(), record: recordWithAppInfo });
|
|
69
|
+
const { user, survey, categoryItemProvider, taxonProvider, areaOfInterestProvider, additionalNodesToValidate, dateModified, } = params;
|
|
70
|
+
const updateResult = yield RecordNodesUpdater.updateNodesDependents(Object.assign(Object.assign({}, params), { nodesToEvaluate: appInfoDependentNodes }));
|
|
71
|
+
const { record: updatedRecord, dateModifiedOnlyNodeUuids } = updateResult;
|
|
72
|
+
// nodes updated only in their date modified (ancestors of the modified nodes) are not validated again
|
|
73
|
+
const updatedNodes = {};
|
|
74
|
+
for (const [nodeUuid, node] of Object.entries(updateResult.nodes)) {
|
|
75
|
+
if (!dateModifiedOnlyNodeUuids.has(nodeUuid)) {
|
|
76
|
+
updatedNodes[nodeUuid] = node;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
47
79
|
const dependentValidationNodePointers = getDependentValidationNodePointers({
|
|
48
80
|
survey,
|
|
49
81
|
record: updatedRecord,
|
|
@@ -69,11 +101,18 @@ const _onRecordNodesCreateOrUpdate = (params) => __awaiter(void 0, void 0, void
|
|
|
69
101
|
updateResult.validation = validation;
|
|
70
102
|
return updateResult;
|
|
71
103
|
});
|
|
72
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Returns the params with the date modified set (now, if not specified): the same date modified is used
|
|
106
|
+
* for all the nodes modified in a record update.
|
|
107
|
+
*/
|
|
108
|
+
const withDateModified = (params) => params.dateModified ? params : Object.assign(Object.assign({}, params), { dateModified: Dates.nowFormattedForStorage() });
|
|
109
|
+
const createDescendants = (paramsIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
+
const params = withDateModified(paramsIn);
|
|
73
111
|
const { record: updatedRecord, nodes: createdNodes } = yield RecordNodesUpdater.addDescendants(params);
|
|
74
112
|
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
|
|
75
113
|
});
|
|
76
|
-
const createNodeAndDescendants = (
|
|
114
|
+
const createNodeAndDescendants = (paramsIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
const params = withDateModified(paramsIn);
|
|
77
116
|
const { record: updatedRecord, nodes: createdNodes } = yield RecordNodesUpdater.addNodeAndDescendants(params);
|
|
78
117
|
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
|
|
79
118
|
});
|
|
@@ -93,7 +132,7 @@ const updateAttributeValue = (params) => __awaiter(void 0, void 0, void 0, funct
|
|
|
93
132
|
attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect });
|
|
94
133
|
const nodesUpdated = { [attributeUuid]: attributeUpdated };
|
|
95
134
|
const _record = Records.addNode(attributeUpdated, { sideEffect })(record);
|
|
96
|
-
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: _record, nodes: nodesUpdated }));
|
|
135
|
+
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { dateModified, record: _record, nodes: nodesUpdated }));
|
|
97
136
|
});
|
|
98
137
|
/**
|
|
99
138
|
* Returns the key and unique attributes of the siblings of the specified entities:
|
|
@@ -137,7 +176,7 @@ const deleteNodes = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
137
176
|
const siblingKeyOrUniqueAttributes = getSiblingKeyOrUniqueAttributes({ survey, record: _record, nodeUuids });
|
|
138
177
|
const updateResult = Records.removeNodes(nodeUuids, { sideEffect })(_record);
|
|
139
178
|
const { record, nodesDeleted } = updateResult;
|
|
140
|
-
const result = yield _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record, nodes: nodesDeleted, additionalNodesToValidate: siblingKeyOrUniqueAttributes }));
|
|
179
|
+
const result = yield _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, withDateModified(params)), { record, nodes: nodesDeleted, additionalNodesToValidate: siblingKeyOrUniqueAttributes }));
|
|
141
180
|
result.nodesDeleted = nodesDeleted;
|
|
142
181
|
return result;
|
|
143
182
|
});
|
|
@@ -145,6 +184,19 @@ const deleteNode = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
145
184
|
const { nodeUuid } = params;
|
|
146
185
|
return deleteNodes(Object.assign(Object.assign({}, params), { nodeUuids: [nodeUuid] }));
|
|
147
186
|
});
|
|
187
|
+
/**
|
|
188
|
+
* Evaluates again the expressions using the app info functions (appId, appIdLabel, appPlatform, appVersion)
|
|
189
|
+
* if the record is being edited with an app different from the one that updated it last
|
|
190
|
+
* (different app id, platform or version, see Records.isAppInfoChanged); does nothing otherwise.
|
|
191
|
+
* To be called when the record is opened for editing (the same check is done in every record update).
|
|
192
|
+
*/
|
|
193
|
+
const updateAppInfoDependents = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
194
|
+
const { record, appInfo } = params;
|
|
195
|
+
if (!Records.isAppInfoChanged(appInfo)(record)) {
|
|
196
|
+
return new RecordUpdateResult({ record });
|
|
197
|
+
}
|
|
198
|
+
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, withDateModified(params)), { nodes: {} }));
|
|
199
|
+
});
|
|
148
200
|
export const RecordUpdater = {
|
|
149
201
|
/** Creates the descendants of a node and updates dependents (applicability, default values, calculations...) and validation */
|
|
150
202
|
createDescendants,
|
|
@@ -156,5 +208,6 @@ export const RecordUpdater = {
|
|
|
156
208
|
deleteNode,
|
|
157
209
|
/** Deletes the nodes and their descendants and updates dependents (applicability, default values, calculations...) and validation */
|
|
158
210
|
deleteNodes,
|
|
211
|
+
updateAppInfoDependents,
|
|
159
212
|
};
|
|
160
213
|
//# sourceMappingURL=recordUpdater.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAgB,QAAQ,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAe,oBAAoB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAsB,MAAM,sBAAsB,CAAA;AAE7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,MAAM,yBAAyB,GAAG;IAChC,oBAAoB,CAAC,WAAW;IAChC,oBAAoB,CAAC,QAAQ;IAC7B,oBAAoB,CAAC,QAAQ;IAC7B,oBAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAA4B,EAAE;IAC7B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBA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M,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;IAE5G,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAC5C,MAAM,KACT,MAAM,EACN,KAAK,EAAE,YAAY,EACnB,yBAAyB,EAAE,4BAA4B,IACvD,CAAA;IACF,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAA2D,EAA+B,EAAE;IACpH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,+HAA+H;IAC/H,iBAAiB;IACjB,gIAAgI;IAChI,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,kIAAkI;IAClI,UAAU;IACV,qIAAqI;IACrI,WAAW;CACZ,CAAA","sourcesContent":["import { ArenaDictionary } from '../common'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, ArenaRecordNodesMap } from '../node'\nimport { ArenaNodeDef, NodeDefs } from '../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { RecordNodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { ArenaRecordNodeCreateParams, ArenaRecordNodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.required,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n}): ArenaRecordNodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, ArenaRecordNodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType)(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: ArenaRecordNodesUpdateParams & {\n nodes: ArenaDictionary<ArenaRecordNode>\n additionalNodesToValidate?: ArenaRecordNodesMap\n }\n): Promise<RecordUpdateResult> => {\n const {\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n additionalNodesToValidate,\n dateModified = Dates.nowFormattedForStorage(),\n } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = RecordNodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes, ...additionalNodesToValidate }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: ArenaRecordNodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: ArenaRecordNodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createRootEntity = async (\n params: ArenaRecordNodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: ArenaRecordNodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid(attributeUuid)(record)\n if (!attribute) throw new SystemError(SystemErrorKeys.record.nodeNotFound, { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\n/**\n * Returns the key and unique attributes of the siblings of the specified entities:\n * they could have been duplicates of the ones being deleted, so they must be validated again.\n */\nconst getEntityKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n entity: ArenaRecordNode\n uniqueAttributeDefs: ArenaNodeDef<any>[]\n}): ArenaRecordNode[] => {\n const { survey, record, entity, uniqueAttributeDefs } = params\n return [\n ...Records.getEntityKeyNodes(survey, entity)(record),\n ...uniqueAttributeDefs.flatMap((uniqueDef) => Records.getChildren(entity, uniqueDef.uuid)(record)),\n ].filter(Boolean)\n}\n\nconst getSiblingKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n nodeUuids: string[]\n}): ArenaRecordNodesMap => {\n const { survey, record, nodeUuids } = params\n const nodeUuidsSet = new Set(nodeUuids)\n const result: ArenaRecordNodesMap = {}\n for (const nodeUuid of nodeUuids) {\n const node = Records.getNodeByUuid(nodeUuid)(record)\n const parentNode = node ? Records.getParent(node)(record) : undefined\n const nodeDef = node ? Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) : undefined\n if (!parentNode || !nodeDef || !NodeDefs.isEntity(nodeDef)) continue\n\n const uniqueAttributeDefs = Surveys.getNodeDefChildren({ survey, nodeDef }).filter(\n (childDef) => NodeDefs.getValidations(childDef)?.unique\n )\n const siblings = Records.getChildren(parentNode, nodeDef.uuid)(record).filter((s) => !nodeUuidsSet.has(s.uuid))\n for (const sibling of siblings) {\n for (const attribute of getEntityKeyOrUniqueAttributes({\n survey,\n record,\n entity: sibling,\n uniqueAttributeDefs,\n })) {\n result[attribute.uuid] = attribute\n }\n }\n }\n return result\n}\n\nconst deleteNodes = async (\n params: ArenaRecordNodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { survey, nodeUuids, record: _record, sideEffect = false } = params\n\n // found before removing the nodes: the deleted nodes are no longer reachable from their siblings afterwards\n const siblingKeyOrUniqueAttributes = getSiblingKeyOrUniqueAttributes({ survey, record: _record, nodeUuids })\n\n const updateResult = Records.removeNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({\n ...params,\n record,\n nodes: nodesDeleted,\n additionalNodesToValidate: siblingKeyOrUniqueAttributes,\n })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: ArenaRecordNodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n /** Creates the descendants of a node and updates dependents (applicability, default values, calculations...) and validation */\n createDescendants,\n /** Creates a node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n /** Deletes the node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNode,\n /** Deletes the nodes and their descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNodes,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAgB,QAAQ,EAAE,MAAM,YAAY,CAAA;AACnD,OAAO,EAAe,oBAAoB,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE7E,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,eAAe,EAA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,EAAE,4BAA4B,IACvD,CAAA;IACF,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAA2D,EAA+B,EAAE;IACpH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAED;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG,CAAO,MAAoC,EAA+B,EAAE;IAC1G,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAClC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3C,CAAC;IACD,OAAO,4BAA4B,iCAAM,gBAAgB,CAAC,MAAM,CAAC,KAAE,KAAK,EAAE,EAAE,IAAG,CAAA;AACjF,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,+HAA+H;IAC/H,iBAAiB;IACjB,gIAAgI;IAChI,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,kIAAkI;IAClI,UAAU;IACV,qIAAqI;IACrI,WAAW;IACX,uBAAuB;CACxB,CAAA","sourcesContent":["import { ArenaDictionary } from '../common'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, ArenaRecordNodesMap } from '../node'\nimport { ArenaNodeDef, NodeDefs } from '../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { RecordNodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { ArenaRecordNodeCreateParams, ArenaRecordNodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.required,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n}): ArenaRecordNodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, ArenaRecordNodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType)(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\n/**\n * If the record is being updated with an app different from the one that updated it last (see Records.isAppInfoChanged),\n * stores the app info in the record (info.modifiedWith) and returns the nodes whose expressions use the app info functions,\n * so they will be evaluated again.\n */\nconst _updateAppInfo = (\n params: ArenaRecordNodesUpdateParams\n): { record: ArenaRecord; appInfoDependentNodes: ArenaRecordNodesMap } => {\n const { survey, record, appInfo, sideEffect = false } = params\n if (!appInfo || !Records.isAppInfoChanged(appInfo)(record)) {\n return { record, appInfoDependentNodes: {} }\n }\n const recordUpdated = sideEffect ? record : { ...record }\n recordUpdated.info = { ...recordUpdated.info, modifiedWith: appInfo }\n\n const appInfoDependentNodes: ArenaRecordNodesMap = {}\n for (const nodeDef of Surveys.getAppInfoDependents({ survey })) {\n for (const node of Records.getNodesByDefUuid(nodeDef.uuid)(recordUpdated)) {\n appInfoDependentNodes[node.uuid] = node\n }\n }\n return { record: recordUpdated, appInfoDependentNodes }\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n paramsIn: ArenaRecordNodesUpdateParams & {\n nodes: ArenaDictionary<ArenaRecordNode>\n additionalNodesToValidate?: ArenaRecordNodesMap\n }\n): Promise<RecordUpdateResult> => {\n const { record: recordWithAppInfo, appInfoDependentNodes } = _updateAppInfo(paramsIn)\n const params = {\n ...paramsIn,\n // the same date modified is used for all the nodes modified in this update\n dateModified: paramsIn.dateModified ?? Dates.nowFormattedForStorage(),\n record: recordWithAppInfo,\n }\n\n const {\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n additionalNodesToValidate,\n dateModified,\n } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents({\n ...params,\n nodesToEvaluate: appInfoDependentNodes,\n })\n const { record: updatedRecord, dateModifiedOnlyNodeUuids } = updateResult\n // nodes updated only in their date modified (ancestors of the modified nodes) are not validated again\n const updatedNodes: ArenaRecordNodesMap = {}\n for (const [nodeUuid, node] of Object.entries(updateResult.nodes)) {\n if (!dateModifiedOnlyNodeUuids.has(nodeUuid)) {\n updatedNodes[nodeUuid] = node\n }\n }\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = RecordNodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes, ...additionalNodesToValidate }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\n/**\n * Returns the params with the date modified set (now, if not specified): the same date modified is used\n * for all the nodes modified in a record update.\n */\nconst withDateModified = <P extends { dateModified?: string }>(params: P): P =>\n params.dateModified ? params : { ...params, dateModified: Dates.nowFormattedForStorage() }\n\nconst createDescendants = async (paramsIn: ArenaRecordNodeCreateParams): Promise<RecordUpdateResult> => {\n const params = withDateModified(paramsIn)\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (paramsIn: ArenaRecordNodeCreateParams): Promise<RecordUpdateResult> => {\n const params = withDateModified(paramsIn)\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createRootEntity = async (\n params: ArenaRecordNodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: ArenaRecordNodesUpdateParams & {\n attributeUuid: string\n // its shape depends on the attribute type (see ArenaRecordNodeValue)\n value: unknown\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid(attributeUuid)(record)\n if (!attribute) throw new SystemError(SystemErrorKeys.record.nodeNotFound, { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, dateModified, record: _record, nodes: nodesUpdated })\n}\n\n/**\n * Returns the key and unique attributes of the siblings of the specified entities:\n * they could have been duplicates of the ones being deleted, so they must be validated again.\n */\nconst getEntityKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n entity: ArenaRecordNode\n uniqueAttributeDefs: ArenaNodeDef<any>[]\n}): ArenaRecordNode[] => {\n const { survey, record, entity, uniqueAttributeDefs } = params\n return [\n ...Records.getEntityKeyNodes(survey, entity)(record),\n ...uniqueAttributeDefs.flatMap((uniqueDef) => Records.getChildren(entity, uniqueDef.uuid)(record)),\n ].filter(Boolean)\n}\n\nconst getSiblingKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n nodeUuids: string[]\n}): ArenaRecordNodesMap => {\n const { survey, record, nodeUuids } = params\n const nodeUuidsSet = new Set(nodeUuids)\n const result: ArenaRecordNodesMap = {}\n for (const nodeUuid of nodeUuids) {\n const node = Records.getNodeByUuid(nodeUuid)(record)\n const parentNode = node ? Records.getParent(node)(record) : undefined\n const nodeDef = node ? Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) : undefined\n if (!parentNode || !nodeDef || !NodeDefs.isEntity(nodeDef)) continue\n\n const uniqueAttributeDefs = Surveys.getNodeDefChildren({ survey, nodeDef }).filter(\n (childDef) => NodeDefs.getValidations(childDef)?.unique\n )\n const siblings = Records.getChildren(parentNode, nodeDef.uuid)(record).filter((s) => !nodeUuidsSet.has(s.uuid))\n for (const sibling of siblings) {\n for (const attribute of getEntityKeyOrUniqueAttributes({\n survey,\n record,\n entity: sibling,\n uniqueAttributeDefs,\n })) {\n result[attribute.uuid] = attribute\n }\n }\n }\n return result\n}\n\nconst deleteNodes = async (\n params: ArenaRecordNodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { survey, nodeUuids, record: _record, sideEffect = false } = params\n\n // found before removing the nodes: the deleted nodes are no longer reachable from their siblings afterwards\n const siblingKeyOrUniqueAttributes = getSiblingKeyOrUniqueAttributes({ survey, record: _record, nodeUuids })\n\n const updateResult = Records.removeNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({\n ...withDateModified(params),\n record,\n nodes: nodesDeleted,\n additionalNodesToValidate: siblingKeyOrUniqueAttributes,\n })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: ArenaRecordNodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\n/**\n * Evaluates again the expressions using the app info functions (appId, appIdLabel, appPlatform, appVersion)\n * if the record is being edited with an app different from the one that updated it last\n * (different app id, platform or version, see Records.isAppInfoChanged); does nothing otherwise.\n * To be called when the record is opened for editing (the same check is done in every record update).\n */\nconst updateAppInfoDependents = async (params: ArenaRecordNodesUpdateParams): Promise<RecordUpdateResult> => {\n const { record, appInfo } = params\n if (!Records.isAppInfoChanged(appInfo)(record)) {\n return new RecordUpdateResult({ record })\n }\n return _onRecordNodesCreateOrUpdate({ ...withDateModified(params), nodes: {} })\n}\n\nexport const RecordUpdater = {\n /** Creates the descendants of a node and updates dependents (applicability, default values, calculations...) and validation */\n createDescendants,\n /** Creates a node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n /** Deletes the node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNode,\n /** Deletes the nodes and their descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNodes,\n updateAppInfoDependents,\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCycle, getRoot, getNodes, getNodesArray, getNodeByUuid, getNodesByUuids, getNodesByDefUuid, getChild, getChildren, getParent, getParentCodeAttribute, getAncestorCodeAttributes, getAncestorCodePath, getDependentCodeAttributes, getAncestor, getEntityKeyNodes, getEntityKeyNodesByDefUuid, getEntityKeyValues, getEntityKeyValuesByDefUuid, getEntitySiblings, getAttributeSiblings, getNodeIndex, isNodeApplicable, isNodeEditable, isNodeVisible, isNodeRequired, visitAncestorsAndSelf, getAncestorsAndSelf, getDescendant, getDescendantsOrSelf, isDescendantOf, visitDescendantsAndSelf, getDependentNodePointers, findEntityByKeyValues, findEntityWithSameKeysInAnotherRecord, getCategoryItemUuid, isNodeEmpty, isNodeFilledByUser, isEmpty, getStep, isInAnalysisStep, } from './_records/recordGetters';
|
|
1
|
+
import { getAppInfoLast, isAppInfoChanged, getCycle, getRoot, getNodes, getNodesArray, getNodeByUuid, getNodesByUuids, getNodesByDefUuid, getChild, getChildren, getParent, getParentCodeAttribute, getAncestorCodeAttributes, getAncestorCodePath, getDependentCodeAttributes, getAncestor, getEntityKeyNodes, getEntityKeyNodesByDefUuid, getEntityKeyValues, getEntityKeyValuesByDefUuid, getEntitySiblings, getAttributeSiblings, getNodeIndex, isNodeApplicable, isNodeEditable, isNodeVisible, isNodeRequired, visitAncestorsAndSelf, getAncestorsAndSelf, getDescendant, getDescendantsOrSelf, isDescendantOf, visitDescendantsAndSelf, getDependentNodePointers, findEntityByKeyValues, findEntityWithSameKeysInAnotherRecord, getCategoryItemUuid, isNodeEmpty, isNodeFilledByUser, isEmpty, getStep, isInAnalysisStep, } from './_records/recordGetters';
|
|
2
2
|
import { addNode, addNodes } from './_records/recordUpdater';
|
|
3
3
|
import { getEnumeratingCategoryItems, findDependentEnumeratedEntityDefsNotEmpty } from './_records/recordUtils';
|
|
4
4
|
import { getEntityCompletionPercent, getEntityCompletionStats, getEntityOwnCompletionPercent, getRecordCompletionPercent, } from './_records/recordCompletion';
|
|
@@ -6,6 +6,8 @@ import { getDescendantPageNodeDefUuids, getEntitySubtreeStatus, getMultiplePageE
|
|
|
6
6
|
import { removeNode, removeNodes } from './recordNodesUpdater/recordNodesDeleter';
|
|
7
7
|
export const Records = {
|
|
8
8
|
// READ
|
|
9
|
+
getAppInfoLast,
|
|
10
|
+
isAppInfoChanged,
|
|
9
11
|
getCycle,
|
|
10
12
|
getRoot,
|
|
11
13
|
getNodes,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../../src/record/records.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,SAAS,EACT,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,EACnB,0BAA0B,EAC1B,WAAW,EACX,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,EAClB,2BAA2B,EAC3B,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,wBAAwB,EACxB,qBAAqB,EACrB,qCAAqC,EACrC,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,OAAO,EACP,gBAAgB,GACjB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,2BAA2B,EAAE,yCAAyC,EAAE,MAAM,wBAAwB,CAAA;AAC/G,OAAO,EACL,0BAA0B,EAC1B,wBAAwB,EACxB,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,6BAA6B,EAC7B,sBAAsB,EACtB,6BAA6B,EAC7B,2BAA2B,EAC3B,eAAe,EACf,uBAAuB,EACvB,gCAAgC,EAChC,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,kCAAkC,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAA;AAEjF,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,OAAO;IACP,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,aAAa;IACb,aAAa;IACb,eAAe;IACf,iBAAiB;IACjB,QAAQ;IACR,WAAW;IACX,SAAS;IACT,sBAAsB;IACtB,yBAAyB;IACzB,mBAAmB;IACnB,0BAA0B;IAC1B,WAAW;IACX,iBAAiB;IACjB,0BAA0B;IAC1B,kBAAkB;IAClB,2BAA2B;IAC3B,iBAAiB;IACjB,oBAAoB;IACpB,YAAY;IACZ,gBAAgB;IAChB,cAAc;IACd,aAAa;IACb,cAAc;IACd,qBAAqB;IACrB,mBAAmB;IACnB,aAAa;IACb,oBAAoB;IACpB,cAAc;IACd,uBAAuB;IACvB,wBAAwB;IACxB,qBAAqB;IACrB,qCAAqC;IACrC,mBAAmB;IACnB,WAAW;IACX,kBAAkB;IAClB,OAAO;IACP,OAAO;IACP,gBAAgB;IAChB,0BAA0B;IAC1B,wBAAwB;IACxB,6BAA6B;IAC7B,0BAA0B;IAC1B,2BAA2B;IAC3B,eAAe;IACf,6BAA6B;IAC7B,iBAAiB;IACjB,oBAAoB;IACpB,uBAAuB;IACvB,gBAAgB;IAChB,gCAAgC;IAChC,sBAAsB;IACtB,6BAA6B;IAC7B,SAAS;IACT,OAAO;IACP,QAAQ;IACR,gIAAgI;IAChI,UAAU;IACV,oIAAoI;IACpI,WAAW;IACX,QAAQ;IACR,2BAA2B;IAC3B,yCAAyC;CAC1C,CAAA","sourcesContent":["import {\n getCycle,\n getRoot,\n getNodes,\n getNodesArray,\n getNodeByUuid,\n getNodesByUuids,\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodeAttributes,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n isNodeRequired,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n} from './_records/recordGetters'\nimport { addNode, addNodes } from './_records/recordUpdater'\nimport { getEnumeratingCategoryItems, findDependentEnumeratedEntityDefsNotEmpty } from './_records/recordUtils'\nimport {\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n} from './_records/recordCompletion'\nimport {\n getDescendantPageNodeDefUuids,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getPageValidationStatus,\n getRecordPagesValidationProgress,\n nodeBelongsToOwnPage,\n nodeBelongsToPage,\n pageHasOwnErrors,\n} from './_records/recordPagesValidation'\nimport { removeNode, removeNodes } from './recordNodesUpdater/recordNodesDeleter'\n\nexport const Records = {\n // READ\n getCycle,\n getRoot,\n getNodes,\n getNodesArray,\n getNodeByUuid,\n getNodesByUuids,\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodeAttributes,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n isNodeRequired,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getDescendantPageNodeDefUuids,\n nodeBelongsToPage,\n nodeBelongsToOwnPage,\n getPageValidationStatus,\n pageHasOwnErrors,\n getRecordPagesValidationProgress,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n // UPDATE\n addNode,\n addNodes,\n /** Low-level: removes the node and its descendants without updating dependents and validation (see RecordUpdater.deleteNode) */\n removeNode,\n /** Low-level: removes the nodes and their descendants without updating dependents and validation (see RecordUpdater.deleteNodes) */\n removeNodes,\n // Utils\n getEnumeratingCategoryItems,\n findDependentEnumeratedEntityDefsNotEmpty,\n}\n\nexport type { ArenaRecordUpdateOptions } from './_records/recordUpdateOptions'\nexport type {\n EntitySubtreeStatus,\n PageValidationStatus,\n PagesValidationProgress,\n} from './_records/recordPagesValidation'\n"]}
|
|
1
|
+
{"version":3,"file":"records.js","sourceRoot":"","sources":["../../../src/record/records.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,OAAO,EACP,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,QAAQ,EACR,WAAW,EACX,SAAS,EACT,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,EACnB,0BAA0B,EAC1B,WAAW,EACX,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,EAClB,2BAA2B,EAC3B,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,wBAA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AC1B,wBAAwB;IACxB,6BAA6B;IAC7B,0BAA0B;IAC1B,2BAA2B;IAC3B,eAAe;IACf,6BAA6B;IAC7B,iBAAiB;IACjB,oBAAoB;IACpB,uBAAuB;IACvB,gBAAgB;IAChB,gCAAgC;IAChC,sBAAsB;IACtB,6BAA6B;IAC7B,SAAS;IACT,OAAO;IACP,QAAQ;IACR,gIAAgI;IAChI,UAAU;IACV,oIAAoI;IACpI,WAAW;IACX,QAAQ;IACR,2BAA2B;IAC3B,yCAAyC;CAC1C,CAAA","sourcesContent":["import {\n getAppInfoLast,\n isAppInfoChanged,\n getCycle,\n getRoot,\n getNodes,\n getNodesArray,\n getNodeByUuid,\n getNodesByUuids,\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodeAttributes,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n isNodeRequired,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n} from './_records/recordGetters'\nimport { addNode, addNodes } from './_records/recordUpdater'\nimport { getEnumeratingCategoryItems, findDependentEnumeratedEntityDefsNotEmpty } from './_records/recordUtils'\nimport {\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n} from './_records/recordCompletion'\nimport {\n getDescendantPageNodeDefUuids,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getPageValidationStatus,\n getRecordPagesValidationProgress,\n nodeBelongsToOwnPage,\n nodeBelongsToPage,\n pageHasOwnErrors,\n} from './_records/recordPagesValidation'\nimport { removeNode, removeNodes } from './recordNodesUpdater/recordNodesDeleter'\n\nexport const Records = {\n // READ\n getAppInfoLast,\n isAppInfoChanged,\n getCycle,\n getRoot,\n getNodes,\n getNodesArray,\n getNodeByUuid,\n getNodesByUuids,\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodeAttributes,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n isNodeRequired,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getDescendantPageNodeDefUuids,\n nodeBelongsToPage,\n nodeBelongsToOwnPage,\n getPageValidationStatus,\n pageHasOwnErrors,\n getRecordPagesValidationProgress,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n // UPDATE\n addNode,\n addNodes,\n /** Low-level: removes the node and its descendants without updating dependents and validation (see RecordUpdater.deleteNode) */\n removeNode,\n /** Low-level: removes the nodes and their descendants without updating dependents and validation (see RecordUpdater.deleteNodes) */\n removeNodes,\n // Utils\n getEnumeratingCategoryItems,\n findDependentEnumeratedEntityDefsNotEmpty,\n}\n\nexport type { ArenaRecordUpdateOptions } from './_records/recordUpdateOptions'\nexport type {\n EntitySubtreeStatus,\n PageValidationStatus,\n PagesValidationProgress,\n} from './_records/recordPagesValidation'\n"]}
|
|
@@ -14,6 +14,8 @@ export var SurveyDependencyType;
|
|
|
14
14
|
SurveyDependencyType["validations"] = "validations";
|
|
15
15
|
SurveyDependencyType["visible"] = "visible";
|
|
16
16
|
SurveyDependencyType["onUpdate"] = "onUpdate";
|
|
17
|
+
SurveyDependencyType["appInfo"] = "appInfo";
|
|
18
|
+
SurveyDependencyType["nodeDates"] = "nodeDates";
|
|
17
19
|
})(SurveyDependencyType || (SurveyDependencyType = {}));
|
|
18
20
|
export var SurveySecurityProp;
|
|
19
21
|
(function (SurveySecurityProp) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"survey.js","sourceRoot":"","sources":["../../../src/survey/survey.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;AAM/B,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"survey.js","sourceRoot":"","sources":["../../../src/survey/survey.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;AAM/B,MAAM,CAAN,IAAY,oBAgBX;AAhBD,WAAY,oBAAoB;IAC9B,iDAAyB,CAAA;IACzB,uDAA+B,CAAA;IAC/B,6CAAqB,CAAA;IACrB,6DAAqC,CAAA;IACrC,6CAAqB,CAAA;IACrB,2CAAmB,CAAA;IACnB,6CAAqB,CAAA;IACrB,6CAAqB,CAAA;IACrB,iDAAyB,CAAA;IACzB,6CAAqB,CAAA;IACrB,mDAA2B,CAAA;IAC3B,2CAAmB,CAAA;IACnB,6CAAqB,CAAA;IACrB,2CAAmB,CAAA;IACnB,+CAAuB,CAAA;AACzB,CAAC,EAhBW,oBAAoB,KAApB,oBAAoB,QAgB/B;AAWD,MAAM,CAAN,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,mGAA6E,CAAA;IAC7E,qGAA+E,CAAA;IAC/E,yDAAmC,CAAA;IACnC,mFAA6D,CAAA;IAC7D,mFAA6D,CAAA;IAC7D,uGAAiF,CAAA;IACjF,qFAA+D,CAAA;AACjE,CAAC,EARW,kBAAkB,KAAlB,kBAAkB,QAQ7B;AAMD,MAAM,CAAC,MAAM,sBAAsB,GAAwB;IACzD,CAAC,kBAAkB,CAAC,oCAAoC,CAAC,EAAE,IAAI;IAC/D,CAAC,kBAAkB,CAAC,qCAAqC,CAAC,EAAE,IAAI;IAChE,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,IAAI;IAC1C,CAAC,kBAAkB,CAAC,4BAA4B,CAAC,EAAE,IAAI;IACvD,CAAC,kBAAkB,CAAC,4BAA4B,CAAC,EAAE,IAAI;IACvD,CAAC,kBAAkB,CAAC,sCAAsC,CAAC,EAAE,IAAI;IACjE,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,EAAE,IAAI;CACzD,CAAA;AAED,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;AACnB,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;CACV,CAAA","sourcesContent":["import { ArenaObject, ArenaDictionary } from '../common'\nimport { ArenaAuthGroup } from '../auth'\nimport { ArenaLabels, LanguageCode } from '../language'\nimport type { ArenaAreaOfInterestDescriptor } from '../geo'\nimport { ArenaSRS } from '../srs'\n\nimport { ArenaAnyNodeDef } from '../nodeDef'\nimport { ArenaCategory } from '../category'\nimport { ArenaTaxonomy } from '../taxonomy'\nimport { ArenaSurveyRefData } from './refData/refData'\n\nexport const defaultCycle = '0'\n\nexport interface ArenaSurveyDependency {\n [nodeDefUuid: string]: string[] | boolean\n}\n\nexport enum SurveyDependencyType {\n applicable = 'applicable',\n defaultValues = 'defaultValues',\n editable = 'editable',\n enumeratingItems = 'enumeratingItems',\n fileName = 'fileName',\n formula = 'formula',\n maxCount = 'maxCount',\n minCount = 'minCount',\n parentCode = 'parentCode',\n required = 'required',\n validations = 'validations',\n visible = 'visible',\n onUpdate = 'onUpdate', // dependencies updated on every record update, stored as dictionary of booleans\n appInfo = 'appInfo', // dependencies updated when the record is updated with a different app, stored as dictionary of booleans\n nodeDates = 'nodeDates', // entity def => node defs whose expressions use its nodes dates (nodeDateCreated, nodeDateModified)\n}\n\nexport type ArenaSurveyDependencyGraph = {\n [key in SurveyDependencyType]: ArenaSurveyDependency\n}\n\nexport interface ArenaSurveyCycle {\n dateEnd?: string\n dateStart: string\n}\n\nexport enum SurveySecurityProp {\n dataEditorViewNotOwnedRecordsAllowed = 'dataEditorViewNotOwnedRecordsAllowed',\n dataAnalystViewNotOwnedRecordsAllowed = 'dataAnalystViewNotOwnedRecordsAllowed',\n visibleInMobile = 'visibleInMobile',\n allowRecordsDownloadInMobile = 'allowRecordsDownloadInMobile',\n allowRecordsUploadFromMobile = 'allowRecordsUploadFromMobile',\n allowRecordsWithErrorsUploadFromMobile = 'allowRecordsWithErrorsUploadFromMobile',\n allowRecordsMergeWithSameKeys = 'allowRecordsMergeWithSameKeys',\n}\n\nexport type ArenaSurveySecurity = {\n [key in SurveySecurityProp]?: boolean\n}\n\nexport const surveySecurityDefaults: ArenaSurveySecurity = {\n [SurveySecurityProp.dataEditorViewNotOwnedRecordsAllowed]: true,\n [SurveySecurityProp.dataAnalystViewNotOwnedRecordsAllowed]: true,\n [SurveySecurityProp.visibleInMobile]: true,\n [SurveySecurityProp.allowRecordsDownloadInMobile]: true,\n [SurveySecurityProp.allowRecordsUploadFromMobile]: true,\n [SurveySecurityProp.allowRecordsWithErrorsUploadFromMobile]: true,\n [SurveySecurityProp.allowRecordsMergeWithSameKeys]: true,\n}\n\nexport enum SurveyDocPlace {\n header = 'header',\n footer = 'footer',\n}\n\nexport const surveyDocImagePropKeys = {\n documentPlace: 'documentPlace',\n applyIf: 'applyIf',\n} as const\n\nexport type ArenaSurveyDocImageProps = ArenaSurveyFileProps & {\n documentPlace?: SurveyDocPlace\n applyIf?: string\n}\n\nexport type ArenaSurveyFileProps = {\n deleted?: boolean\n labels?: ArenaLabels\n name?: string\n nodeUuid?: string\n recordUuid?: string\n size?: number | null\n temporary?: boolean\n type?: string\n}\n\nexport type ArenaSurveyFile = {\n uuid: string\n props: ArenaSurveyFileProps\n content?: Buffer | null\n dateCreated: string\n}\n\nexport type ArenaSurveyDocImage = ArenaSurveyFile & {\n props: ArenaSurveyDocImageProps\n}\n\nexport type SurveyDocOptions = {\n headerOnFirstPageOnly?: boolean // default: true\n}\n\nexport interface ArenaSurveyProps {\n areasOfInterest?: ArenaAreaOfInterestDescriptor[]\n collectUri?: string\n cycles: {\n [key: string]: ArenaSurveyCycle\n }\n defaultCycleKey?: string\n descriptions?: ArenaLabels\n fieldManualLinks?: ArenaLabels\n // when true, values of attributes becoming non-applicable are kept during data entry (default: cleared)\n keepNonApplicableValues?: boolean\n labels?: ArenaLabels\n languages: LanguageCode[]\n name: string\n preloadedMapLayers?: ArenaSurveyFile[]\n preloadedMapLayersEnabled?: boolean\n security?: ArenaSurveySecurity\n srs: ArenaSRS[]\n surveyDocImages?: ArenaSurveyDocImage[]\n surveyDocOptions?: SurveyDocOptions\n}\n\nexport interface ArenaSurveyNodeDefsIndex {\n rootDefUuid?: string\n childDefUuidPresenceByParentUuid?: { [parentUuid: string]: { [nodeDefUuid: string]: boolean } }\n nodeDefUuidByName?: ArenaDictionary<string>\n qualifierPresenceByUuid?: { [nodeDefUuid: string]: boolean }\n}\n\nexport interface ArenaSurvey extends ArenaObject<ArenaSurveyProps> {\n authGroups: Array<ArenaAuthGroup>\n dateCreated?: string\n dateModified?: string\n datePublished?: string\n dependencyGraph?: ArenaSurveyDependencyGraph\n draft: boolean\n nodeDefs?: { [nodeDefUuid: string]: ArenaAnyNodeDef }\n ownerUuid: string\n published: boolean\n readonly id?: number\n template: boolean\n uuid: string\n /**\n * Categories indexed by uuid.\n */\n categories?: { [categoryUuid: string]: ArenaCategory }\n /**\n * Taxonomies indexed by uuid.\n */\n taxonomies?: { [taxonomyUuid: string]: ArenaTaxonomy }\n /**\n * Reference data cache (category items and taxa).\n */\n refData?: ArenaSurveyRefData\n\n nodeDefsIndex?: ArenaSurveyNodeDefsIndex\n}\n"]}
|