@openforis/arena-core 3.2.2 → 3.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/dist/app/appInfo.d.ts +5 -1
  2. package/dist/app/appInfo.js.map +1 -1
  3. package/dist/app/appInfos.d.ts +19 -0
  4. package/dist/app/appInfos.js +27 -0
  5. package/dist/app/appInfos.js.map +1 -0
  6. package/dist/app/index.d.ts +2 -1
  7. package/dist/app/index.js +3 -0
  8. package/dist/app/index.js.map +1 -1
  9. package/dist/esm/app/appInfo.js.map +1 -1
  10. package/dist/esm/app/appInfos.js +24 -0
  11. package/dist/esm/app/appInfos.js.map +1 -0
  12. package/dist/esm/app/index.js +1 -1
  13. package/dist/esm/app/index.js.map +1 -1
  14. package/dist/esm/expression/context.js.map +1 -1
  15. package/dist/esm/expression/javascript/evaluator.js +3 -16
  16. package/dist/esm/expression/javascript/evaluator.js.map +1 -1
  17. package/dist/esm/expression/javascript/parser/expressionNodesFinder.js +68 -0
  18. package/dist/esm/expression/javascript/parser/expressionNodesFinder.js.map +1 -0
  19. package/dist/esm/geo/points/transform.js +3 -10
  20. package/dist/esm/geo/points/transform.js.map +1 -1
  21. package/dist/esm/index.js +1 -0
  22. package/dist/esm/index.js.map +1 -1
  23. package/dist/esm/node/index.js.map +1 -1
  24. package/dist/esm/node/nodes.js +14 -12
  25. package/dist/esm/node/nodes.js.map +1 -1
  26. package/dist/esm/nodeDefExpressionEvaluator/context.js.map +1 -1
  27. package/dist/esm/nodeDefExpressionEvaluator/evaluator.js +19 -1
  28. package/dist/esm/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
  29. package/dist/esm/nodeDefExpressionEvaluator/functions.js +53 -0
  30. package/dist/esm/nodeDefExpressionEvaluator/functions.js.map +1 -1
  31. package/dist/esm/record/_records/recordGetters.js +19 -0
  32. package/dist/esm/record/_records/recordGetters.js.map +1 -1
  33. package/dist/esm/record/record.js.map +1 -1
  34. package/dist/esm/record/recordExpressionEvaluator/functions.js +14 -0
  35. package/dist/esm/record/recordExpressionEvaluator/functions.js.map +1 -1
  36. package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js +9 -1
  37. package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
  38. package/dist/esm/record/recordNodesUpdater/recordExpressionEvaluationContext.js +1 -0
  39. package/dist/esm/record/recordNodesUpdater/recordExpressionEvaluationContext.js.map +1 -1
  40. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +5 -3
  41. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
  42. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +6 -4
  43. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
  44. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +2 -2
  45. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
  46. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +11 -3
  47. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
  48. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +46 -21
  49. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
  50. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +15 -6
  51. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
  52. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +5 -5
  53. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -1
  54. package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +22 -1
  55. package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
  56. package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js +111 -8
  57. package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  58. package/dist/esm/record/recordNodesUpdater/recordUpdateResult.js +10 -0
  59. package/dist/esm/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
  60. package/dist/esm/record/recordUpdater.js +62 -9
  61. package/dist/esm/record/recordUpdater.js.map +1 -1
  62. package/dist/esm/record/records.js +3 -1
  63. package/dist/esm/record/records.js.map +1 -1
  64. package/dist/esm/survey/survey.js +2 -0
  65. package/dist/esm/survey/survey.js.map +1 -1
  66. package/dist/esm/survey/surveys/dependencies.js +67 -32
  67. package/dist/esm/survey/surveys/dependencies.js.map +1 -1
  68. package/dist/esm/survey/surveys/index.js +2 -1
  69. package/dist/esm/survey/surveys/index.js.map +1 -1
  70. package/dist/esm/utils/_objects/isEqual.js +2 -0
  71. package/dist/esm/utils/_objects/isEqual.js.map +1 -1
  72. package/dist/esm/utils/lruCache.js +50 -0
  73. package/dist/esm/utils/lruCache.js.map +1 -0
  74. package/dist/expression/context.d.ts +5 -0
  75. package/dist/expression/context.js.map +1 -1
  76. package/dist/expression/javascript/evaluator.js +3 -16
  77. package/dist/expression/javascript/evaluator.js.map +1 -1
  78. package/dist/expression/javascript/parser/expressionNodesFinder.d.ts +13 -0
  79. package/dist/expression/javascript/parser/expressionNodesFinder.js +73 -0
  80. package/dist/expression/javascript/parser/expressionNodesFinder.js.map +1 -0
  81. package/dist/geo/points/transform.js +3 -10
  82. package/dist/geo/points/transform.js.map +1 -1
  83. package/dist/index.d.ts +3 -2
  84. package/dist/index.js +5 -3
  85. package/dist/index.js.map +1 -1
  86. package/dist/node/index.d.ts +1 -0
  87. package/dist/node/index.js.map +1 -1
  88. package/dist/node/nodes.d.ts +18 -5
  89. package/dist/node/nodes.js +14 -12
  90. package/dist/node/nodes.js.map +1 -1
  91. package/dist/nodeDefExpressionEvaluator/context.d.ts +4 -0
  92. package/dist/nodeDefExpressionEvaluator/context.js.map +1 -1
  93. package/dist/nodeDefExpressionEvaluator/evaluator.d.ts +9 -1
  94. package/dist/nodeDefExpressionEvaluator/evaluator.js +19 -1
  95. package/dist/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
  96. package/dist/nodeDefExpressionEvaluator/functions.js +53 -0
  97. package/dist/nodeDefExpressionEvaluator/functions.js.map +1 -1
  98. package/dist/record/_records/recordGetters.d.ts +10 -0
  99. package/dist/record/_records/recordGetters.js +22 -1
  100. package/dist/record/_records/recordGetters.js.map +1 -1
  101. package/dist/record/record.d.ts +1 -1
  102. package/dist/record/record.js.map +1 -1
  103. package/dist/record/recordExpressionEvaluator/functions.js +14 -0
  104. package/dist/record/recordExpressionEvaluator/functions.js.map +1 -1
  105. package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.d.ts +8 -0
  106. package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js +9 -1
  107. package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
  108. package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.d.ts +6 -0
  109. package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.js +1 -0
  110. package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.js.map +1 -1
  111. package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +5 -3
  112. package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
  113. package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.d.ts +2 -3
  114. package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +5 -3
  115. package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
  116. package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +2 -2
  117. package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
  118. package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +11 -3
  119. package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
  120. package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +45 -20
  121. package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
  122. package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +15 -6
  123. package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
  124. package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +4 -4
  125. package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -1
  126. package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.d.ts +19 -0
  127. package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +24 -1
  128. package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
  129. package/dist/record/recordNodesUpdater/recordNodesUpdater.d.ts +8 -1
  130. package/dist/record/recordNodesUpdater/recordNodesUpdater.js +107 -4
  131. package/dist/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  132. package/dist/record/recordNodesUpdater/recordUpdateResult.d.ts +5 -0
  133. package/dist/record/recordNodesUpdater/recordUpdateResult.js +10 -0
  134. package/dist/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
  135. package/dist/record/recordUpdater.d.ts +10 -2
  136. package/dist/record/recordUpdater.js +61 -8
  137. package/dist/record/recordUpdater.js.map +1 -1
  138. package/dist/record/records.d.ts +3 -1
  139. package/dist/record/records.js +2 -0
  140. package/dist/record/records.js.map +1 -1
  141. package/dist/survey/survey.d.ts +3 -1
  142. package/dist/survey/survey.js +2 -0
  143. package/dist/survey/survey.js.map +1 -1
  144. package/dist/survey/surveys/dependencies.d.ts +10 -0
  145. package/dist/survey/surveys/dependencies.js +69 -33
  146. package/dist/survey/surveys/dependencies.js.map +1 -1
  147. package/dist/survey/surveys/index.d.ts +2 -1
  148. package/dist/survey/surveys/index.js +1 -0
  149. package/dist/survey/surveys/index.js.map +1 -1
  150. package/dist/utils/_objects/isEqual.d.ts +3 -1
  151. package/dist/utils/_objects/isEqual.js +2 -0
  152. package/dist/utils/_objects/isEqual.js.map +1 -1
  153. package/dist/utils/lruCache.d.ts +18 -0
  154. package/dist/utils/lruCache.js +54 -0
  155. package/dist/utils/lruCache.js.map +1 -0
  156. package/package.json +1 -1
@@ -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
- const _onRecordNodesCreateOrUpdate = (params) => __awaiter(void 0, void 0, void 0, function* () {
44
- const { user, survey, categoryItemProvider, taxonProvider, areaOfInterestProvider, additionalNodesToValidate, dateModified = Dates.nowFormattedForStorage(), } = params;
45
- const updateResult = yield RecordNodesUpdater.updateNodesDependents(params);
46
- const { nodes: updatedNodes, record: updatedRecord } = updateResult;
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
- const createDescendants = (params) => __awaiter(void 0, void 0, void 0, function* () {
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 = (params) => __awaiter(void 0, void 0, void 0, function* () {
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,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AS,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 // 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, 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,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,mBAAmB,GAAG,IAAI,GAAG,EAAkC,CAAA;IACrE,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,cAAc,IAAI,yBAAyB,EAAE,CAAC;YACvD,MAAM,YAAY,GAAG,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,EAA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I,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,EAC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AC1B,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,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,cAAc;IACd,gBAAgB;IAChB,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 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,oBAcX;AAdD,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;AACvB,CAAC,EAdW,oBAAoB,KAApB,oBAAoB,QAc/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}\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"]}
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"]}
@@ -10,11 +10,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import * as SurveyNodeDefs from './nodeDefs';
11
11
  import { NodeDefs, NodeDefType, } from '../../nodeDef';
12
12
  import { NodeDefExpressionEvaluator } from '../../nodeDefExpressionEvaluator';
13
+ import { findFunctionCallNames } from '../../expression/javascript/parser/expressionNodesFinder';
13
14
  import { SurveyDependencyType } from '../survey';
14
15
  import { Arrays, Objects } from '../../utils';
15
16
  import { NodeDefExpressionFactory } from '../../nodeDef/nodeDef';
16
- const functionsRequiringOnUpdateDependency = ['recordDateLastModified'];
17
+ // dependency types stored as dictionary of booleans (node def uuid => true), not as dependents of a node def
18
+ const booleanDependencyTypes = new Set([
19
+ SurveyDependencyType.onUpdate,
20
+ SurveyDependencyType.appInfo,
21
+ ]);
22
+ const functionNamesByBooleanDependencyType = {
23
+ [SurveyDependencyType.onUpdate]: ['recordDateLastModified'],
24
+ [SurveyDependencyType.appInfo]: ['appId', 'appIdLabel', 'appPlatform', 'appVersion'],
25
+ };
17
26
  const isContextParentByDependencyType = {
27
+ [SurveyDependencyType.appInfo]: true,
18
28
  [SurveyDependencyType.applicable]: true,
19
29
  [SurveyDependencyType.defaultValues]: true,
20
30
  [SurveyDependencyType.editable]: true,
@@ -23,6 +33,7 @@ const isContextParentByDependencyType = {
23
33
  [SurveyDependencyType.formula]: false,
24
34
  [SurveyDependencyType.maxCount]: true,
25
35
  [SurveyDependencyType.minCount]: true,
36
+ [SurveyDependencyType.nodeDates]: true,
26
37
  [SurveyDependencyType.onUpdate]: true,
27
38
  [SurveyDependencyType.parentCode]: false,
28
39
  [SurveyDependencyType.required]: true,
@@ -30,6 +41,7 @@ const isContextParentByDependencyType = {
30
41
  [SurveyDependencyType.visible]: true,
31
42
  };
32
43
  const selfReferenceAllowedByDependencyType = {
44
+ [SurveyDependencyType.appInfo]: false,
33
45
  [SurveyDependencyType.applicable]: false,
34
46
  [SurveyDependencyType.defaultValues]: false,
35
47
  [SurveyDependencyType.editable]: false,
@@ -38,6 +50,7 @@ const selfReferenceAllowedByDependencyType = {
38
50
  [SurveyDependencyType.formula]: false,
39
51
  [SurveyDependencyType.maxCount]: false,
40
52
  [SurveyDependencyType.minCount]: false,
53
+ [SurveyDependencyType.nodeDates]: false,
41
54
  [SurveyDependencyType.onUpdate]: false,
42
55
  [SurveyDependencyType.parentCode]: false,
43
56
  [SurveyDependencyType.required]: false,
@@ -45,6 +58,7 @@ const selfReferenceAllowedByDependencyType = {
45
58
  [SurveyDependencyType.visible]: false,
46
59
  };
47
60
  const newDependencyGraph = () => ({
61
+ [SurveyDependencyType.appInfo]: {},
48
62
  [SurveyDependencyType.applicable]: {},
49
63
  [SurveyDependencyType.defaultValues]: {},
50
64
  [SurveyDependencyType.editable]: {},
@@ -53,6 +67,7 @@ const newDependencyGraph = () => ({
53
67
  [SurveyDependencyType.formula]: {},
54
68
  [SurveyDependencyType.maxCount]: {},
55
69
  [SurveyDependencyType.minCount]: {},
70
+ [SurveyDependencyType.nodeDates]: {},
56
71
  [SurveyDependencyType.onUpdate]: {},
57
72
  [SurveyDependencyType.parentCode]: {},
58
73
  [SurveyDependencyType.required]: {},
@@ -64,7 +79,7 @@ const getDependencies = (params) => {
64
79
  var _a;
65
80
  var _b;
66
81
  const { graphs, type, nodeDefUuid } = params;
67
- return type === SurveyDependencyType.onUpdate ? [] : ((_b = (_a = graphs === null || graphs === void 0 ? void 0 : graphs[type]) === null || _a === void 0 ? void 0 : _a[nodeDefUuid]) !== null && _b !== void 0 ? _b : []);
82
+ return booleanDependencyTypes.has(type) ? [] : ((_b = (_a = graphs === null || graphs === void 0 ? void 0 : graphs[type]) === null || _a === void 0 ? void 0 : _a[nodeDefUuid]) !== null && _b !== void 0 ? _b : []);
68
83
  };
69
84
  export const getNodeDefDependents = (params) => {
70
85
  const { survey, nodeDefUuid, dependencyType } = params;
@@ -81,13 +96,22 @@ export const getNodeDefDependents = (params) => {
81
96
  }
82
97
  return dependentUuids.size > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: [...dependentUuids] }) : [];
83
98
  };
84
- export const getOnUpdateDependents = (params) => {
99
+ const getBooleanDependencyTypeDependents = (params) => {
85
100
  var _a;
86
- const { survey } = params;
101
+ const { survey, dependencyType } = params;
87
102
  const dependencyGraph = getDependencyGraph(survey);
88
- const sourceDefUuids = Object.keys((_a = dependencyGraph[SurveyDependencyType.onUpdate]) !== null && _a !== void 0 ? _a : {});
103
+ const sourceDefUuids = Object.keys((_a = dependencyGraph[dependencyType]) !== null && _a !== void 0 ? _a : {});
89
104
  return sourceDefUuids.length > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: sourceDefUuids }) : [];
90
105
  };
106
+ /**
107
+ * Returns the node defs to be evaluated again on every record update (their expressions use e.g. recordDateLastModified).
108
+ */
109
+ export const getOnUpdateDependents = (params) => getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.onUpdate });
110
+ /**
111
+ * Returns the node defs to be evaluated again when a record is updated with a different app
112
+ * (their expressions use the app info functions: appId, appIdLabel, appPlatform, appVersion).
113
+ */
114
+ export const getAppInfoDependents = (params) => getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.appInfo });
91
115
  // UPDATE
92
116
  const addDependency = (params) => {
93
117
  const { graphs, type, nodeDefUuid, nodeDefDepUuid, sideEffect = false } = params;
@@ -105,36 +129,41 @@ const addDependencies = (params) => __awaiter(void 0, void 0, void 0, function*
105
129
  let graphsUpdated = sideEffect ? graphsParam : Object.assign({}, graphsParam);
106
130
  const isContextParent = isContextParentByDependencyType[type];
107
131
  const selfReferenceAllowed = selfReferenceAllowedByDependencyType[type];
132
+ const referencedNodeDefUuids = new Set();
133
+ const nodeDateReferencedNodeDefUuids = new Set();
108
134
  const findReferencedNodeDefs = (expression) => __awaiter(void 0, void 0, void 0, function* () {
109
135
  if (!expression)
110
- return {};
111
- const referencedNodeDefUuids = yield new NodeDefExpressionEvaluator().findReferencedNodeDefUuids({
136
+ return;
137
+ const result = yield new NodeDefExpressionEvaluator().findReferencedNodeDefUuidsWithNodeDates({
112
138
  expression,
113
139
  survey,
114
140
  nodeDef,
115
141
  isContextParent,
116
142
  selfReferenceAllowed,
117
143
  });
118
- const referencedNodeDefsByUuid = {};
119
- for (const uuid of referencedNodeDefUuids) {
120
- referencedNodeDefsByUuid[uuid] = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid });
121
- }
122
- return referencedNodeDefsByUuid;
144
+ result.referencedNodeDefUuids.forEach((uuid) => referencedNodeDefUuids.add(uuid));
145
+ result.nodeDateReferencedNodeDefUuids.forEach((uuid) => nodeDateReferencedNodeDefUuids.add(uuid));
123
146
  });
124
- const referencedNodeDefsArray = yield Promise.all(expressions.flatMap((nodeDefExpr) => [
147
+ yield Promise.all(expressions.flatMap((nodeDefExpr) => [
125
148
  findReferencedNodeDefs(nodeDefExpr.expression),
126
149
  findReferencedNodeDefs(nodeDefExpr.applyIf),
127
150
  ]));
128
- const referencedNodeDefs = Object.assign({}, ...referencedNodeDefsArray);
129
- for (const nodeDefRef of Object.values(referencedNodeDefs)) {
130
- graphsUpdated = addDependency({
131
- graphs: graphsUpdated,
132
- type,
133
- nodeDefUuid: nodeDefRef.uuid,
134
- nodeDefDepUuid: nodeDef.uuid,
135
- sideEffect,
136
- });
137
- }
151
+ const addGraphDependencies = (dependencyType, sourceDefUuids) => {
152
+ for (const sourceDefUuid of sourceDefUuids) {
153
+ // the referenced node def must exist
154
+ const sourceDef = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid: sourceDefUuid });
155
+ graphsUpdated = addDependency({
156
+ graphs: graphsUpdated,
157
+ type: dependencyType,
158
+ nodeDefUuid: sourceDef.uuid,
159
+ nodeDefDepUuid: nodeDef.uuid,
160
+ sideEffect,
161
+ });
162
+ }
163
+ };
164
+ addGraphDependencies(type, referencedNodeDefUuids);
165
+ // entities whose nodes dates are used in the expressions (nodeDateCreated, nodeDateModified)
166
+ addGraphDependencies(SurveyDependencyType.nodeDates, nodeDateReferencedNodeDefUuids);
138
167
  return graphsUpdated;
139
168
  });
140
169
  export const addNodeDefDependencies = (params) => __awaiter(void 0, void 0, void 0, function* () {
@@ -150,14 +179,20 @@ export const addNodeDefDependencies = (params) => __awaiter(void 0, void 0, void
150
179
  graphs: graphsUpdated,
151
180
  sideEffect,
152
181
  });
153
- // add onUpdate dependencies
154
- if (expressions.some((expression) => functionsRequiringOnUpdateDependency.some((functionName) => { var _a, _b; return ((_a = expression.applyIf) === null || _a === void 0 ? void 0 : _a.includes(functionName)) || ((_b = expression.expression) === null || _b === void 0 ? void 0 : _b.includes(functionName)); }))) {
155
- _graphUpdated = Objects.assocPath({
156
- obj: _graphUpdated,
157
- path: [SurveyDependencyType.onUpdate, nodeDef.uuid],
158
- value: true,
159
- sideEffect,
160
- });
182
+ // add boolean (onUpdate, appInfo) dependencies
183
+ const calledFunctionNames = new Set(expressions.flatMap((expression) => [
184
+ ...findFunctionCallNames(expression.expression),
185
+ ...findFunctionCallNames(expression.applyIf),
186
+ ]));
187
+ for (const [booleanDependencyType, functionNames] of Object.entries(functionNamesByBooleanDependencyType)) {
188
+ if (functionNames.some((functionName) => calledFunctionNames.has(functionName))) {
189
+ _graphUpdated = Objects.assocPath({
190
+ obj: _graphUpdated,
191
+ path: [booleanDependencyType, nodeDef.uuid],
192
+ value: true,
193
+ sideEffect,
194
+ });
195
+ }
161
196
  }
162
197
  return _graphUpdated;
163
198
  });
@@ -218,7 +253,7 @@ const _removeNodeDefDependenciesOfType = (params) => {
218
253
  let graphUpdated = Object.assign({}, graphsUpdated[dependencyType]);
219
254
  // dissoc nodeDefUuid dependency as dependent
220
255
  graphUpdated = Objects.dissoc({ obj: graphUpdated, prop: nodeDefUuid });
221
- if (dependencyType !== SurveyDependencyType.onUpdate) {
256
+ if (!booleanDependencyTypes.has(dependencyType)) {
222
257
  // dissoc nodeDefUuid dependency from sources (if any)
223
258
  for (const [key, dependentUuids] of Object.entries(graphUpdated)) {
224
259
  graphUpdated[key] = Arrays.removeItem(nodeDefUuid)(dependentUuids);
@@ -1 +1 @@
1
- {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../../../src/survey/surveys/dependencies.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,cAAc,MAAM,YAAY,CAAA;AAC5C,OAAO,EAOL,QAAQ,EACR,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAA;AAE7E,OAAO,EAA2C,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAGhE,MAAM,oCAAoC,GAAG,CAAC,wBAAwB,CAAC,CAAA;AAEvE,MAAM,+BAA+B,GAAG;IACtC,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,IAAI;IACvC,CAAC,oBAAoB,CAAC,aAAa,CAAC,EAAE,IAAI;IAC1C,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,IAAI;IACrC,CAAC,oBAAoB,CAAC,gBAAgB,CAAC,EAAE,IAAI;IAC7C,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,IAAI;IACrC,CAAC,oBAAoB,CAAC,OAAO,CAAC,EAAE,KAAK;IACrC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,IAAI;IACrC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,IAAI;IACrC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,IAAI;IACrC,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,KAAK;IACxC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,EAAE,IAAI;IACrC,CAAC,oBAAoB,CAAC,WAAW,CAAC,EAAE,IA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Defs,\n NodeDefType,\n} from '../../nodeDef'\nimport { NodeDefExpressionEvaluator } from '../../nodeDefExpressionEvaluator'\n\nimport { ArenaSurvey, ArenaSurveyDependencyGraph, SurveyDependencyType } from '../survey'\nimport { Arrays, Objects } from '../../utils'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\nimport { ArenaDictionary } from '../../common'\n\nconst functionsRequiringOnUpdateDependency = ['recordDateLastModified']\n\nconst isContextParentByDependencyType = {\n [SurveyDependencyType.applicable]: true,\n [SurveyDependencyType.defaultValues]: true,\n [SurveyDependencyType.editable]: true,\n [SurveyDependencyType.enumeratingItems]: true,\n [SurveyDependencyType.fileName]: true,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: true,\n [SurveyDependencyType.minCount]: true,\n [SurveyDependencyType.onUpdate]: true,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: true,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: true,\n}\n\nconst selfReferenceAllowedByDependencyType = {\n [SurveyDependencyType.applicable]: false,\n [SurveyDependencyType.defaultValues]: false,\n [SurveyDependencyType.editable]: false,\n [SurveyDependencyType.enumeratingItems]: false,\n [SurveyDependencyType.fileName]: false,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: false,\n [SurveyDependencyType.minCount]: false,\n [SurveyDependencyType.onUpdate]: false,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: false,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: false,\n}\n\nconst newDependencyGraph = () => ({\n [SurveyDependencyType.applicable]: {},\n [SurveyDependencyType.defaultValues]: {},\n [SurveyDependencyType.editable]: {},\n [SurveyDependencyType.enumeratingItems]: {},\n [SurveyDependencyType.fileName]: {},\n [SurveyDependencyType.formula]: {},\n [SurveyDependencyType.maxCount]: {},\n [SurveyDependencyType.minCount]: {},\n [SurveyDependencyType.onUpdate]: {},\n [SurveyDependencyType.parentCode]: {},\n [SurveyDependencyType.required]: {},\n [SurveyDependencyType.validations]: {},\n [SurveyDependencyType.visible]: {},\n})\n\nconst getDependencyGraph = (survey: ArenaSurvey): ArenaSurveyDependencyGraph =>\n survey.dependencyGraph ?? newDependencyGraph()\n\nconst getDependencies = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n}): Array<string> => {\n const { graphs, type, nodeDefUuid } = params\n return type === SurveyDependencyType.onUpdate ? [] : ((graphs?.[type]?.[nodeDefUuid] ?? []) as string[])\n}\n\nexport const getNodeDefDependents = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaAnyNodeDef[] => {\n const { survey, nodeDefUuid, dependencyType } = params\n const dependencyGraph = getDependencyGraph(survey)\n\n const dependentUuids = new Set<string>()\n\n const dependencyTypes: SurveyDependencyType[] = dependencyType\n ? [dependencyType]\n : Object.values(SurveyDependencyType)\n\n for (const depType of dependencyTypes) {\n const dependentUuidsTemp = getDependencies({ graphs: dependencyGraph, type: depType, nodeDefUuid })\n for (const dependentUuid of dependentUuidsTemp) {\n dependentUuids.add(dependentUuid)\n }\n }\n return dependentUuids.size > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: [...dependentUuids] }) : []\n}\n\nexport const getOnUpdateDependents = (params: { survey: ArenaSurvey }) => {\n const { survey } = params\n const dependencyGraph = getDependencyGraph(survey)\n const sourceDefUuids = Object.keys(dependencyGraph[SurveyDependencyType.onUpdate] ?? {})\n return sourceDefUuids.length > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: sourceDefUuids }) : []\n}\n\n// UPDATE\n\nconst addDependency = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n nodeDefDepUuid: string\n sideEffect: boolean\n}): ArenaSurveyDependencyGraph => {\n const { graphs, type, nodeDefUuid, nodeDefDepUuid, sideEffect = false } = params\n const deps = getDependencies({ graphs, type, nodeDefUuid })\n // dependencies of a node def can be added again (e.g. when it is updated): keep each dependent only once\n if (deps.includes(nodeDefDepUuid)) return graphs\n const depsUpdated = Arrays.addItem(nodeDefDepUuid, { sideEffect })(deps)\n return Objects.assocPath({ obj: graphs, path: [type, nodeDefUuid], value: depsUpdated, sideEffect })\n}\n\nconst addDependencies = async (params: {\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n type: SurveyDependencyType\n graphs: ArenaSurveyDependencyGraph\n expressions: ArenaNodeDefExpression[]\n sideEffect?: boolean\n}): Promise<ArenaSurveyDependencyGraph> => {\n const { survey, nodeDef, type, expressions, graphs: graphsParam, sideEffect = false } = params\n\n if (!expressions || expressions.length === 0) return graphsParam\n\n let graphsUpdated = sideEffect ? graphsParam : { ...graphsParam }\n\n const isContextParent = isContextParentByDependencyType[type]\n const selfReferenceAllowed = selfReferenceAllowedByDependencyType[type]\n\n const findReferencedNodeDefs = async (\n expression: string | undefined\n ): Promise<{ [key: string]: ArenaAnyNodeDef }> => {\n if (!expression) return {}\n\n const referencedNodeDefUuids = await new NodeDefExpressionEvaluator().findReferencedNodeDefUuids({\n expression,\n survey,\n nodeDef,\n isContextParent,\n selfReferenceAllowed,\n })\n const referencedNodeDefsByUuid: ArenaDictionary<ArenaNodeDef<any>> = {}\n for (const uuid of referencedNodeDefUuids) {\n referencedNodeDefsByUuid[uuid] = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid })\n }\n return referencedNodeDefsByUuid\n }\n\n const referencedNodeDefsArray = await Promise.all(\n expressions.flatMap((nodeDefExpr) => [\n findReferencedNodeDefs(nodeDefExpr.expression),\n findReferencedNodeDefs(nodeDefExpr.applyIf),\n ])\n )\n const referencedNodeDefs: ArenaDictionary<ArenaNodeDef<any>> = Object.assign({}, ...referencedNodeDefsArray)\n\n for (const nodeDefRef of Object.values(referencedNodeDefs)) {\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type,\n nodeDefUuid: nodeDefRef.uuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n\n return graphsUpdated\n}\n\nexport const addNodeDefDependencies = async (params: {\n nodeDef: ArenaAnyNodeDef\n survey: ArenaSurvey\n sideEffect?: boolean\n}): Promise<ArenaSurvey> => {\n const { nodeDef, survey, sideEffect = false } = params\n const graphs = getDependencyGraph(survey)\n let graphsUpdated = sideEffect ? graphs : { ...graphs }\n\n const _addDependencies = async (type: SurveyDependencyType, expressions: ArenaNodeDefExpression[]) => {\n let _graphUpdated = await addDependencies({\n survey,\n nodeDef,\n type,\n expressions,\n graphs: graphsUpdated,\n sideEffect,\n })\n // add onUpdate dependencies\n if (\n expressions.some((expression) =>\n functionsRequiringOnUpdateDependency.some(\n (functionName) => expression.applyIf?.includes(functionName) || expression.expression?.includes(functionName)\n )\n )\n ) {\n _graphUpdated = Objects.assocPath({\n obj: _graphUpdated,\n path: [SurveyDependencyType.onUpdate, nodeDef.uuid],\n value: true,\n sideEffect,\n })\n }\n return _graphUpdated\n }\n graphsUpdated = await _addDependencies(SurveyDependencyType.applicable, NodeDefs.getApplicable(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.defaultValues, NodeDefs.getDefaultValues(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.editable, NodeDefs.getEditableIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.required, NodeDefs.getRequiredIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.validations, NodeDefs.getValidationsExpressions(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.visible, NodeDefs.getVisibleIf(nodeDef))\n const maxCount = NodeDefs.getMaxCount(nodeDef)\n if (Array.isArray(maxCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.maxCount, maxCount)\n }\n const minCount = NodeDefs.getMinCount(nodeDef)\n if (Array.isArray(minCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.minCount, minCount)\n }\n // file name expression\n if (NodeDefs.getType(nodeDef) === NodeDefType.file) {\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (fileNameExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.fileName, [\n NodeDefExpressionFactory.createInstance({ expression: fileNameExpression }),\n ])\n }\n }\n if (NodeDefs.isEntity(nodeDef)) {\n const enumeratingItemsExpression = NodeDefs.getEnumeratingItemsExpression(nodeDef as ArenaNodeDefEntity)\n if (enumeratingItemsExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.enumeratingItems, [\n NodeDefExpressionFactory.createInstance({ expression: enumeratingItemsExpression }),\n ])\n }\n }\n // parent code\n if (NodeDefs.getType(nodeDef) === NodeDefType.code) {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef as ArenaNodeDefCode)\n if (parentCodeDefUuid) {\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type: SurveyDependencyType.parentCode,\n nodeDefUuid: parentCodeDefUuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n }\n if (sideEffect) {\n survey.dependencyGraph = graphsUpdated\n return survey\n }\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n// DELETE\n\nconst _removeNodeDefDependenciesOfType = (params: {\n graphs: ArenaSurveyDependencyGraph\n dependencyType: SurveyDependencyType\n nodeDefUuid: string\n}): ArenaSurveyDependencyGraph => {\n const { graphs, nodeDefUuid, dependencyType } = params\n\n const graphsUpdated = { ...graphs }\n let graphUpdated = { ...graphsUpdated[dependencyType] }\n // dissoc nodeDefUuid dependency as dependent\n graphUpdated = Objects.dissoc({ obj: graphUpdated, prop: nodeDefUuid })\n\n if (dependencyType !== SurveyDependencyType.onUpdate) {\n // dissoc nodeDefUuid dependency from sources (if any)\n for (const [key, dependentUuids] of Object.entries(graphUpdated)) {\n graphUpdated[key] = Arrays.removeItem(nodeDefUuid)(dependentUuids as string[])\n }\n }\n\n graphsUpdated[dependencyType] = graphUpdated\n return graphsUpdated\n}\n\nexport const removeNodeDefDependencies = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaSurvey => {\n const { survey, nodeDefUuid, dependencyType = null } = params\n const graphs = getDependencyGraph(survey)\n const dependencyTypes = dependencyType ? [dependencyType] : (Object.keys(graphs) as SurveyDependencyType[])\n const graphsUpdated = dependencyTypes.reduce(\n (dependencyGraphAcc, type) =>\n _removeNodeDefDependenciesOfType({ graphs: dependencyGraphAcc, dependencyType: type, nodeDefUuid }),\n graphs\n )\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n/**\n * Builds the dependency graph of the survey.\n *\n * @param survey - The survey.\n * @returns A copy of the survey with the dependency graph (the survey passed in is not modified).\n */\nexport const buildAndAssocDependencyGraph = async (survey: ArenaSurvey): Promise<ArenaSurvey> => {\n // the new graph is built from scratch with side effect (to avoid re-creating objects): it belongs only to the copy of the survey\n const sideEffect = true\n\n // add dependencies for every node def\n let surveyUpdated: ArenaSurvey = { ...survey, dependencyGraph: newDependencyGraph() }\n for (const nodeDef of SurveyNodeDefs.getNodeDefsArray(survey)) {\n // sequential: each iteration updates the survey\n surveyUpdated = await addNodeDefDependencies({ nodeDef, survey: surveyUpdated, sideEffect }) // NOSONAR\n }\n return surveyUpdated\n}\n"]}
1
+ {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../../../src/survey/surveys/dependencies.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,cAAc,MAAM,YAAY,CAAA;AAC5C,OAAO,EAML,QAAQ,EACR,WAAW,GACZ,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAA;AAEhG,OAAO,EAA2C,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACzF,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,wBAA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AAC,IAAI,CAAC,MAAM,CAA4B,CAAA;IAC3G,MAAM,aAAa,GAAG,eAAe,CAAC,MAAM,CAC1C,CAAC,kBAAkB,EAAE,IAAI,EAAE,EAAE,CAC3B,gCAAgC,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,EACrG,MAAM,CACP,CAAA;IACD,uCAAY,MAAM,KAAE,eAAe,EAAE,aAAa,IAAE;AACtD,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAO,MAAmB,EAAwB,EAAE;IAC9F,iIAAiI;IACjI,MAAM,UAAU,GAAG,IAAI,CAAA;IAEvB,sCAAsC;IACtC,IAAI,aAAa,mCAAqB,MAAM,KAAE,eAAe,EAAE,kBAAkB,EAAE,GAAE,CAAA;IACrF,KAAK,MAAM,OAAO,IAAI,cAAc,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9D,gDAAgD;QAChD,aAAa,GAAG,MAAM,sBAAsB,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAA,CAAC,UAAU;IACzG,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA,CAAA","sourcesContent":["import * as SurveyNodeDefs from './nodeDefs'\nimport {\n ArenaAnyNodeDef,\n ArenaNodeDefCode,\n ArenaNodeDefEntity,\n ArenaNodeDefExpression,\n ArenaNodeDefFile,\n NodeDefs,\n NodeDefType,\n} from '../../nodeDef'\nimport { NodeDefExpressionEvaluator } from '../../nodeDefExpressionEvaluator'\nimport { findFunctionCallNames } from '../../expression/javascript/parser/expressionNodesFinder'\n\nimport { ArenaSurvey, ArenaSurveyDependencyGraph, SurveyDependencyType } from '../survey'\nimport { Arrays, Objects } from '../../utils'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\n\n// dependency types stored as dictionary of booleans (node def uuid => true), not as dependents of a node def\nconst booleanDependencyTypes = new Set<SurveyDependencyType>([\n SurveyDependencyType.onUpdate,\n SurveyDependencyType.appInfo,\n])\n\nconst functionNamesByBooleanDependencyType: { [key: string]: string[] } = {\n [SurveyDependencyType.onUpdate]: ['recordDateLastModified'],\n [SurveyDependencyType.appInfo]: ['appId', 'appIdLabel', 'appPlatform', 'appVersion'],\n}\n\nconst isContextParentByDependencyType = {\n [SurveyDependencyType.appInfo]: true,\n [SurveyDependencyType.applicable]: true,\n [SurveyDependencyType.defaultValues]: true,\n [SurveyDependencyType.editable]: true,\n [SurveyDependencyType.enumeratingItems]: true,\n [SurveyDependencyType.fileName]: true,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: true,\n [SurveyDependencyType.minCount]: true,\n [SurveyDependencyType.nodeDates]: true,\n [SurveyDependencyType.onUpdate]: true,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: true,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: true,\n}\n\nconst selfReferenceAllowedByDependencyType = {\n [SurveyDependencyType.appInfo]: false,\n [SurveyDependencyType.applicable]: false,\n [SurveyDependencyType.defaultValues]: false,\n [SurveyDependencyType.editable]: false,\n [SurveyDependencyType.enumeratingItems]: false,\n [SurveyDependencyType.fileName]: false,\n [SurveyDependencyType.formula]: false,\n [SurveyDependencyType.maxCount]: false,\n [SurveyDependencyType.minCount]: false,\n [SurveyDependencyType.nodeDates]: false,\n [SurveyDependencyType.onUpdate]: false,\n [SurveyDependencyType.parentCode]: false,\n [SurveyDependencyType.required]: false,\n [SurveyDependencyType.validations]: true,\n [SurveyDependencyType.visible]: false,\n}\n\nconst newDependencyGraph = () => ({\n [SurveyDependencyType.appInfo]: {},\n [SurveyDependencyType.applicable]: {},\n [SurveyDependencyType.defaultValues]: {},\n [SurveyDependencyType.editable]: {},\n [SurveyDependencyType.enumeratingItems]: {},\n [SurveyDependencyType.fileName]: {},\n [SurveyDependencyType.formula]: {},\n [SurveyDependencyType.maxCount]: {},\n [SurveyDependencyType.minCount]: {},\n [SurveyDependencyType.nodeDates]: {},\n [SurveyDependencyType.onUpdate]: {},\n [SurveyDependencyType.parentCode]: {},\n [SurveyDependencyType.required]: {},\n [SurveyDependencyType.validations]: {},\n [SurveyDependencyType.visible]: {},\n})\n\nconst getDependencyGraph = (survey: ArenaSurvey): ArenaSurveyDependencyGraph =>\n survey.dependencyGraph ?? newDependencyGraph()\n\nconst getDependencies = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n}): Array<string> => {\n const { graphs, type, nodeDefUuid } = params\n return booleanDependencyTypes.has(type) ? [] : ((graphs?.[type]?.[nodeDefUuid] ?? []) as string[])\n}\n\nexport const getNodeDefDependents = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaAnyNodeDef[] => {\n const { survey, nodeDefUuid, dependencyType } = params\n const dependencyGraph = getDependencyGraph(survey)\n\n const dependentUuids = new Set<string>()\n\n const dependencyTypes: SurveyDependencyType[] = dependencyType\n ? [dependencyType]\n : Object.values(SurveyDependencyType)\n\n for (const depType of dependencyTypes) {\n const dependentUuidsTemp = getDependencies({ graphs: dependencyGraph, type: depType, nodeDefUuid })\n for (const dependentUuid of dependentUuidsTemp) {\n dependentUuids.add(dependentUuid)\n }\n }\n return dependentUuids.size > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: [...dependentUuids] }) : []\n}\n\nconst getBooleanDependencyTypeDependents = (params: {\n survey: ArenaSurvey\n dependencyType: SurveyDependencyType\n}): ArenaAnyNodeDef[] => {\n const { survey, dependencyType } = params\n const dependencyGraph = getDependencyGraph(survey)\n const sourceDefUuids = Object.keys(dependencyGraph[dependencyType] ?? {})\n return sourceDefUuids.length > 0 ? SurveyNodeDefs.findNodeDefsByUuids({ survey, uuids: sourceDefUuids }) : []\n}\n\n/**\n * Returns the node defs to be evaluated again on every record update (their expressions use e.g. recordDateLastModified).\n */\nexport const getOnUpdateDependents = (params: { survey: ArenaSurvey }): ArenaAnyNodeDef[] =>\n getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.onUpdate })\n\n/**\n * Returns the node defs to be evaluated again when a record is updated with a different app\n * (their expressions use the app info functions: appId, appIdLabel, appPlatform, appVersion).\n */\nexport const getAppInfoDependents = (params: { survey: ArenaSurvey }): ArenaAnyNodeDef[] =>\n getBooleanDependencyTypeDependents({ survey: params.survey, dependencyType: SurveyDependencyType.appInfo })\n\n// UPDATE\n\nconst addDependency = (params: {\n graphs: ArenaSurveyDependencyGraph\n type: SurveyDependencyType\n nodeDefUuid: string\n nodeDefDepUuid: string\n sideEffect: boolean\n}): ArenaSurveyDependencyGraph => {\n const { graphs, type, nodeDefUuid, nodeDefDepUuid, sideEffect = false } = params\n const deps = getDependencies({ graphs, type, nodeDefUuid })\n // dependencies of a node def can be added again (e.g. when it is updated): keep each dependent only once\n if (deps.includes(nodeDefDepUuid)) return graphs\n const depsUpdated = Arrays.addItem(nodeDefDepUuid, { sideEffect })(deps)\n return Objects.assocPath({ obj: graphs, path: [type, nodeDefUuid], value: depsUpdated, sideEffect })\n}\n\nconst addDependencies = async (params: {\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n type: SurveyDependencyType\n graphs: ArenaSurveyDependencyGraph\n expressions: ArenaNodeDefExpression[]\n sideEffect?: boolean\n}): Promise<ArenaSurveyDependencyGraph> => {\n const { survey, nodeDef, type, expressions, graphs: graphsParam, sideEffect = false } = params\n\n if (!expressions || expressions.length === 0) return graphsParam\n\n let graphsUpdated = sideEffect ? graphsParam : { ...graphsParam }\n\n const isContextParent = isContextParentByDependencyType[type]\n const selfReferenceAllowed = selfReferenceAllowedByDependencyType[type]\n\n const referencedNodeDefUuids = new Set<string>()\n const nodeDateReferencedNodeDefUuids = new Set<string>()\n\n const findReferencedNodeDefs = async (expression: string | undefined): Promise<void> => {\n if (!expression) return\n\n const result = await new NodeDefExpressionEvaluator().findReferencedNodeDefUuidsWithNodeDates({\n expression,\n survey,\n nodeDef,\n isContextParent,\n selfReferenceAllowed,\n })\n result.referencedNodeDefUuids.forEach((uuid) => referencedNodeDefUuids.add(uuid))\n result.nodeDateReferencedNodeDefUuids.forEach((uuid) => nodeDateReferencedNodeDefUuids.add(uuid))\n }\n\n await Promise.all(\n expressions.flatMap((nodeDefExpr) => [\n findReferencedNodeDefs(nodeDefExpr.expression),\n findReferencedNodeDefs(nodeDefExpr.applyIf),\n ])\n )\n\n const addGraphDependencies = (dependencyType: SurveyDependencyType, sourceDefUuids: Set<string>): void => {\n for (const sourceDefUuid of sourceDefUuids) {\n // the referenced node def must exist\n const sourceDef = SurveyNodeDefs.getNodeDefByUuid({ survey, uuid: sourceDefUuid })\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type: dependencyType,\n nodeDefUuid: sourceDef.uuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n }\n addGraphDependencies(type, referencedNodeDefUuids)\n // entities whose nodes dates are used in the expressions (nodeDateCreated, nodeDateModified)\n addGraphDependencies(SurveyDependencyType.nodeDates, nodeDateReferencedNodeDefUuids)\n\n return graphsUpdated\n}\n\nexport const addNodeDefDependencies = async (params: {\n nodeDef: ArenaAnyNodeDef\n survey: ArenaSurvey\n sideEffect?: boolean\n}): Promise<ArenaSurvey> => {\n const { nodeDef, survey, sideEffect = false } = params\n const graphs = getDependencyGraph(survey)\n let graphsUpdated = sideEffect ? graphs : { ...graphs }\n\n const _addDependencies = async (type: SurveyDependencyType, expressions: ArenaNodeDefExpression[]) => {\n let _graphUpdated = await addDependencies({\n survey,\n nodeDef,\n type,\n expressions,\n graphs: graphsUpdated,\n sideEffect,\n })\n // add boolean (onUpdate, appInfo) dependencies\n const calledFunctionNames = new Set(\n expressions.flatMap((expression) => [\n ...findFunctionCallNames(expression.expression),\n ...findFunctionCallNames(expression.applyIf),\n ])\n )\n for (const [booleanDependencyType, functionNames] of Object.entries(functionNamesByBooleanDependencyType)) {\n if (functionNames.some((functionName) => calledFunctionNames.has(functionName))) {\n _graphUpdated = Objects.assocPath({\n obj: _graphUpdated,\n path: [booleanDependencyType, nodeDef.uuid],\n value: true,\n sideEffect,\n })\n }\n }\n return _graphUpdated\n }\n graphsUpdated = await _addDependencies(SurveyDependencyType.applicable, NodeDefs.getApplicable(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.defaultValues, NodeDefs.getDefaultValues(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.editable, NodeDefs.getEditableIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.required, NodeDefs.getRequiredIf(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.validations, NodeDefs.getValidationsExpressions(nodeDef))\n graphsUpdated = await _addDependencies(SurveyDependencyType.visible, NodeDefs.getVisibleIf(nodeDef))\n const maxCount = NodeDefs.getMaxCount(nodeDef)\n if (Array.isArray(maxCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.maxCount, maxCount)\n }\n const minCount = NodeDefs.getMinCount(nodeDef)\n if (Array.isArray(minCount)) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.minCount, minCount)\n }\n // file name expression\n if (NodeDefs.getType(nodeDef) === NodeDefType.file) {\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (fileNameExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.fileName, [\n NodeDefExpressionFactory.createInstance({ expression: fileNameExpression }),\n ])\n }\n }\n if (NodeDefs.isEntity(nodeDef)) {\n const enumeratingItemsExpression = NodeDefs.getEnumeratingItemsExpression(nodeDef as ArenaNodeDefEntity)\n if (enumeratingItemsExpression) {\n graphsUpdated = await _addDependencies(SurveyDependencyType.enumeratingItems, [\n NodeDefExpressionFactory.createInstance({ expression: enumeratingItemsExpression }),\n ])\n }\n }\n // parent code\n if (NodeDefs.getType(nodeDef) === NodeDefType.code) {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef as ArenaNodeDefCode)\n if (parentCodeDefUuid) {\n graphsUpdated = addDependency({\n graphs: graphsUpdated,\n type: SurveyDependencyType.parentCode,\n nodeDefUuid: parentCodeDefUuid,\n nodeDefDepUuid: nodeDef.uuid,\n sideEffect,\n })\n }\n }\n if (sideEffect) {\n survey.dependencyGraph = graphsUpdated\n return survey\n }\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n// DELETE\n\nconst _removeNodeDefDependenciesOfType = (params: {\n graphs: ArenaSurveyDependencyGraph\n dependencyType: SurveyDependencyType\n nodeDefUuid: string\n}): ArenaSurveyDependencyGraph => {\n const { graphs, nodeDefUuid, dependencyType } = params\n\n const graphsUpdated = { ...graphs }\n let graphUpdated = { ...graphsUpdated[dependencyType] }\n // dissoc nodeDefUuid dependency as dependent\n graphUpdated = Objects.dissoc({ obj: graphUpdated, prop: nodeDefUuid })\n\n if (!booleanDependencyTypes.has(dependencyType)) {\n // dissoc nodeDefUuid dependency from sources (if any)\n for (const [key, dependentUuids] of Object.entries(graphUpdated)) {\n graphUpdated[key] = Arrays.removeItem(nodeDefUuid)(dependentUuids as string[])\n }\n }\n\n graphsUpdated[dependencyType] = graphUpdated\n return graphsUpdated\n}\n\nexport const removeNodeDefDependencies = (params: {\n survey: ArenaSurvey\n nodeDefUuid: string\n dependencyType?: SurveyDependencyType\n}): ArenaSurvey => {\n const { survey, nodeDefUuid, dependencyType = null } = params\n const graphs = getDependencyGraph(survey)\n const dependencyTypes = dependencyType ? [dependencyType] : (Object.keys(graphs) as SurveyDependencyType[])\n const graphsUpdated = dependencyTypes.reduce(\n (dependencyGraphAcc, type) =>\n _removeNodeDefDependenciesOfType({ graphs: dependencyGraphAcc, dependencyType: type, nodeDefUuid }),\n graphs\n )\n return { ...survey, dependencyGraph: graphsUpdated }\n}\n\n/**\n * Builds the dependency graph of the survey.\n *\n * @param survey - The survey.\n * @returns A copy of the survey with the dependency graph (the survey passed in is not modified).\n */\nexport const buildAndAssocDependencyGraph = async (survey: ArenaSurvey): Promise<ArenaSurvey> => {\n // the new graph is built from scratch with side effect (to avoid re-creating objects): it belongs only to the copy of the survey\n const sideEffect = true\n\n // add dependencies for every node def\n let surveyUpdated: ArenaSurvey = { ...survey, dependencyGraph: newDependencyGraph() }\n for (const nodeDef of SurveyNodeDefs.getNodeDefsArray(survey)) {\n // sequential: each iteration updates the survey\n surveyUpdated = await addNodeDefDependencies({ nodeDef, survey: surveyUpdated, sideEffect }) // NOSONAR\n }\n return surveyUpdated\n}\n"]}