@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
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsDefaultValuesUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAA2C,WAAW,EAAE,MAAM,YAAY,CAAA;AACjF,OAAO,EAAgB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAe,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AACvE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAA;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAE3D;;GAEG;AACH,MAAM,uBAAuB,GAAG,CAAC,MAIhC,EAAW,EAAE;IACZ,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,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AAE,cAAc,EAAE,OAAO,EAAE,CAAC,CACvF,CAAA;IACH,CAAC,CAAA;IAED,MAAM,oBAAoB,GAAG,OAAO,CAAC,wBAAwB,CAC3D,MAAM,EACN,IAAI,EACJ,oBAAoB,CAAC,aAAa,EAClC,IAAI,EACJ,oBAAoB,CACrB,CAAC,MAAM,CAAC,CAAA;IAET,6CAA6C;IAC7C,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,gDAAgD;QAChD,MAAM,0BAA0B,iCAAM,MAAM,KAAE,WAAW,EAAE,YAAY,EAAE,UAAU,IAAG,CAAA,CAAC,UAAU;IACnG,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, RecordNodes } from '../../node'\nimport { ArenaNodeDef, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { ArenaSurvey, SurveyDependencyType } from '../../survey/survey'\nimport { Dates, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordExpressionValueConverter } from './recordExpressionValueConverter'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { throwError } from './recordNodesDependentsUpdaterCommons'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Default value should be reset when a node becomes not applicable, but only if the default value was applied or if the node def is read only (therefore the value can only be set by default value expression)\n */\nconst shouldResetDefaultValue = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): boolean => {\n const { survey, record, node } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n return (\n !Records.isNodeApplicable(node)(record) &&\n !RecordNodes.isValueBlank(node) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))\n )\n}\n\nconst canApplyDefaultValue = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n}): boolean => {\n const { record, node, nodeDef } = params\n return (\n Records.isNodeApplicable(node)(record) &&\n (RecordNodes.isValueBlank(node) ||\n (!NodeDefs.isDefaultValueEvaluatedOneTime(nodeDef) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))))\n )\n}\n\nconst updateDefaultValueInNode = (params: {\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n nodeToUpdate: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n exprValue: any\n sideEffect: boolean\n}): void => {\n const { survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect } = params\n if (shouldResetDefaultValue({ survey, record: updateResult.record, node: nodeToUpdate })) {\n const nodeUpdated = RecordNodes.mergeNodes(nodeToUpdate, {\n value: null,\n meta: { defaultValueApplied: false },\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n return\n }\n if (!canApplyDefaultValue({ record: updateResult.record, nodeDef, node: nodeToUpdate })) {\n return\n }\n\n // 2. if node value is not changed, do nothing\n if (Objects.isEqual(nodeToUpdate.value, exprValue)) {\n return\n }\n\n // 3. update node value and meta\n const defaultValueApplied = !Objects.isEmpty(exprValue)\n\n // the value is replaced, not merged: props of the previous value (e.g. vernacularNameUuid) must not be kept\n const nodeUpdated: ArenaRecordNode = {\n ...RecordNodes.mergeNodes(nodeToUpdate, {\n meta: { defaultValueApplied },\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }),\n value: exprValue,\n }\n updateResult.addNode(nodeUpdated, { sideEffect })\n}\n\nconst updateDefaultValuesInNodes = async (\n params: RecordNodeDependentsUpdateParams & {\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n }\n): Promise<void> => {\n const { survey, nodePointer, updateResult, timezoneOffset, categoryItemProvider, sideEffect = false } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted) return\n\n const { record } = updateResult\n\n let nodesToUpdate: ArenaRecordNode[] = []\n const dependentNodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n let exprValue: any = null\n const expressionsToEvaluate = NodeDefs.getDefaultValues(nodeDef)\n if (expressionsToEvaluate.length === 0) {\n if (Surveys.isNodeDefEnumerator({ survey, nodeDef })) {\n // if node def is enumerator, its default value is generated using the category items, not with default value expressions\n // so the default value should not be reset or updated using default value expressions\n return\n }\n // no default expressions to evaluate; check if there are dependent nodes with default value applied, as their default value should be removed\n nodesToUpdate = dependentNodes.filter(RecordNodes.isDefaultValueApplied)\n if (nodesToUpdate.length === 0) {\n // no default expressions to evaluate and no nodes with default value applied, therefore no update needed\n return\n }\n } else {\n // if there are default value expressions, all dependent nodes should be evaluated, as their default value could change\n nodesToUpdate = dependentNodes\n try {\n // 1. evaluate applicable default value expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n\n const exprEvalValue = exprEval?.value\n exprValue = Objects.isEmpty(exprEvalValue)\n ? null\n : await RecordExpressionValueConverter.toNodeValue({\n survey,\n record,\n nodeDef,\n nodeParent: nodeCtx,\n valueExpr: exprEvalValue,\n timezoneOffset,\n categoryItemProvider,\n })\n } catch (error) {\n throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsDefaultValues,\n expressionType: SurveyDependencyType.defaultValues,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n }\n for (const nodeToUpdate of nodesToUpdate) {\n updateDefaultValueInNode({ survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect })\n }\n}\n\nexport const updateSelfAndDependentsDefaultValues = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n // filter nodes to update including itself and (attributes with empty values or with default values applied)\n // therefore attributes with user defined values are excluded\n const nodePointersFilterFn = (nodePointer: ArenaRecordNodePointer): boolean => {\n const { nodeDef } = nodePointer\n if (!NodeDefs.isAttribute(nodeDef)) return false\n\n const referencedNodes = RecordNodePointers.getNodesFromNodePointers({\n record: updateResult.record,\n nodePointers: [nodePointer],\n })\n return referencedNodes.some(\n (referencedNode) =>\n shouldResetDefaultValue({ survey, record: updateResult.record, node: referencedNode }) ||\n canApplyDefaultValue({ record: updateResult.record, node: referencedNode, nodeDef })\n )\n }\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.defaultValues,\n true,\n nodePointersFilterFn\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateDefaultValuesInNodes({ ...params, nodePointer, updateResult, sideEffect }) // NOSONAR\n }\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsDefaultValuesUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAA2C,WAAW,EAAE,MAAM,YAAY,CAAA;AACjF,OAAO,EAAgB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAe,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AACvE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,OAAO,E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CAAC,cAAc,EAAE,EAAE,CACjB,uBAAuB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;YACtF,oBAAoB,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC,CACvF,CAAA;IACH,CAAC,CAAA;IAED,MAAM,oBAAoB,GAAG,OAAO,CAAC,wBAAwB,CAC3D,MAAM,EACN,IAAI,EACJ,oBAAoB,CAAC,aAAa,EAClC,IAAI,EACJ,oBAAoB,CACrB,CAAC,MAAM,CAAC,CAAA;IAET,6CAA6C;IAC7C,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,gDAAgD;QAChD,MAAM,0BAA0B,iCAAM,MAAM,KAAE,WAAW,EAAE,YAAY,EAAE,UAAU,IAAG,CAAA,CAAC,UAAU;IACnG,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, RecordNodes } from '../../node'\nimport { ArenaNodeDef, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { ArenaSurvey, SurveyDependencyType } from '../../survey/survey'\nimport { Dates, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordExpressionValueConverter } from './recordExpressionValueConverter'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { isAppInfoMissing, throwError } from './recordNodesDependentsUpdaterCommons'\nimport { expressionUsesThis } from '../../expression/javascript/parser/expressionNodesFinder'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Default value should be reset when a node becomes not applicable, but only if the default value was applied or if the node def is read only (therefore the value can only be set by default value expression)\n */\nconst shouldResetDefaultValue = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): boolean => {\n const { survey, record, node } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n return (\n !Records.isNodeApplicable(node)(record) &&\n !RecordNodes.isValueBlank(node) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))\n )\n}\n\nconst canApplyDefaultValue = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n}): boolean => {\n const { record, node, nodeDef } = params\n return (\n Records.isNodeApplicable(node)(record) &&\n (RecordNodes.isValueBlank(node) ||\n (!NodeDefs.isDefaultValueEvaluatedOneTime(nodeDef) &&\n (RecordNodes.isDefaultValueApplied(node) || NodeDefs.isReadOnly(nodeDef))))\n )\n}\n\nconst updateDefaultValueInNode = (params: {\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n nodeToUpdate: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n exprValue: any\n sideEffect: boolean\n dateModified?: string\n}): void => {\n const { survey, updateResult, nodeToUpdate, nodeDef, exprValue, sideEffect, dateModified: dateModifiedParam } = params\n const dateModified = dateModifiedParam ?? Dates.nowFormattedForStorage()\n if (shouldResetDefaultValue({ survey, record: updateResult.record, node: nodeToUpdate })) {\n const nodeUpdated = RecordNodes.mergeNodes(nodeToUpdate, {\n value: null,\n meta: { defaultValueApplied: false },\n updated: true,\n dateModified,\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n return\n }\n if (!canApplyDefaultValue({ record: updateResult.record, nodeDef, node: nodeToUpdate })) {\n return\n }\n\n // 2. if node value is not changed, do nothing\n if (Objects.isEqual(nodeToUpdate.value, exprValue)) {\n return\n }\n\n // 3. update node value and meta\n const defaultValueApplied = !Objects.isEmpty(exprValue)\n\n // the value is replaced, not merged: props of the previous value (e.g. vernacularNameUuid) must not be kept\n const nodeUpdated: ArenaRecordNode = {\n ...RecordNodes.mergeNodes(nodeToUpdate, {\n meta: { defaultValueApplied },\n updated: true,\n dateModified,\n }),\n value: exprValue,\n }\n updateResult.addNode(nodeUpdated, { sideEffect })\n}\n\nconst updateDefaultValuesInNodes = async (\n params: RecordNodeDependentsUpdateParams & {\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n }\n): Promise<void> => {\n const { survey, nodePointer, updateResult, timezoneOffset, categoryItemProvider, sideEffect = false } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted || isAppInfoMissing({ survey, appInfo: params.appInfo, nodeDef })) return\n\n const { record } = updateResult\n\n const dependentNodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n const expressionsToEvaluate = NodeDefs.getDefaultValues(nodeDef)\n\n const updateNodes = (nodesToUpdate: ArenaRecordNode[], exprValue: any): void => {\n for (const nodeToUpdate of nodesToUpdate) {\n updateDefaultValueInNode({\n survey,\n updateResult,\n nodeToUpdate,\n nodeDef,\n exprValue,\n sideEffect,\n dateModified: params.dateModified,\n })\n }\n }\n\n if (expressionsToEvaluate.length === 0) {\n if (Surveys.isNodeDefEnumerator({ survey, nodeDef })) {\n // if node def is enumerator, its default value is generated using the category items, not with default value expressions\n // so the default value should not be reset or updated using default value expressions\n return\n }\n // no default expressions to evaluate; check if there are dependent nodes with default value applied, as their default value should be removed\n // (if there are none, no update is needed)\n updateNodes(dependentNodes.filter(RecordNodes.isDefaultValueApplied), null)\n return\n }\n\n // if there are default value expressions, all dependent nodes should be evaluated, as their default value could change\n if (dependentNodes.length === 0) return\n\n const evaluateDefaultValue = async (nodeCurrent: ArenaRecordNode | null): Promise<any> => {\n try {\n // evaluate applicable default value expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record,\n nodeCtx,\n nodeCurrent,\n expressions: expressionsToEvaluate,\n })\n const exprEvalValue = exprEval?.value\n return Objects.isEmpty(exprEvalValue)\n ? null\n : await RecordExpressionValueConverter.toNodeValue({\n survey,\n record,\n nodeDef,\n nodeParent: nodeCtx,\n valueExpr: exprEvalValue,\n timezoneOffset,\n categoryItemProvider,\n })\n } catch (error) {\n return throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsDefaultValues,\n expressionType: SurveyDependencyType.defaultValues,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n }\n\n const usesThis = expressionsToEvaluate.some(\n (expression) => expressionUsesThis(expression.expression) || expressionUsesThis(expression.applyIf)\n )\n if (NodeDefs.isMultiple(nodeDef) && usesThis) {\n // \"this\" refers to each node: evaluate the expressions for every node\n for (const dependentNode of dependentNodes) {\n // sequential: each iteration updates the record\n const exprValue = await evaluateDefaultValue(dependentNode) // NOSONAR\n updateNodes([dependentNode], exprValue)\n }\n } else {\n // the same value applies to all the nodes (\"this\" is the node itself, if the node def is single)\n const exprValue = await evaluateDefaultValue(NodeDefs.isMultiple(nodeDef) ? null : (dependentNodes[0] ?? null))\n updateNodes(dependentNodes, exprValue)\n }\n}\n\nexport const updateSelfAndDependentsDefaultValues = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n // filter nodes to update including itself and (attributes with empty values or with default values applied)\n // therefore attributes with user defined values are excluded\n const nodePointersFilterFn = (nodePointer: ArenaRecordNodePointer): boolean => {\n const { nodeDef } = nodePointer\n if (!NodeDefs.isAttribute(nodeDef)) return false\n\n const referencedNodes = RecordNodePointers.getNodesFromNodePointers({\n record: updateResult.record,\n nodePointers: [nodePointer],\n })\n return referencedNodes.some(\n (referencedNode) =>\n shouldResetDefaultValue({ survey, record: updateResult.record, node: referencedNode }) ||\n canApplyDefaultValue({ record: updateResult.record, node: referencedNode, nodeDef })\n )\n }\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.defaultValues,\n true,\n nodePointersFilterFn\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateDefaultValuesInNodes({ ...params, nodePointer, updateResult, sideEffect }) // NOSONAR\n }\n return updateResult\n}\n"]}
@@ -55,7 +55,7 @@ const calculateFileName = (params) => __awaiter(void 0, void 0, void 0, function
55
55
  return fileNameCalculated;
56
56
  });
57
57
  const updateFileNamesInNodes = (params) => __awaiter(void 0, void 0, void 0, function* () {
58
- const { user, survey, nodePointer, updateResult, sideEffect = false } = params;
58
+ const { user, survey, nodePointer, updateResult, sideEffect = false, dateModified } = params;
59
59
  const { nodeCtx, nodeDef } = nodePointer;
60
60
  if (nodeCtx.deleted)
61
61
  return;
@@ -66,25 +66,34 @@ const updateFileNamesInNodes = (params) => __awaiter(void 0, void 0, void 0, fun
66
66
  const nodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] });
67
67
  for (const node of nodes) {
68
68
  if (!RecordNodes.isValueBlank(node)) {
69
+ const updateParams = {
70
+ user,
71
+ survey,
72
+ updateResult,
73
+ sideEffect,
74
+ nodeDef: nodeDef,
75
+ node,
76
+ dateModified,
77
+ };
69
78
  // sequential: each iteration updates the record
70
- yield updateFileNameInNode({ user, survey, updateResult, sideEffect, nodeDef: nodeDef, node }); // NOSONAR
79
+ yield updateFileNameInNode(updateParams); // NOSONAR
71
80
  }
72
81
  }
73
82
  });
74
83
  export const updateSelfAndDependentsFileNames = (params) => __awaiter(void 0, void 0, void 0, function* () {
75
- const { user, survey, record, node, sideEffect = false } = params;
84
+ const { user, survey, record, node, sideEffect = false, dateModified } = params;
76
85
  const updateResult = new RecordUpdateResult({ record });
77
86
  // 1. get dependent node pointers
78
87
  const nodePointersToUpdate = Records.getDependentNodePointers(survey, node, SurveyDependencyType.fileName, true)(record);
79
88
  // 2. update expr to node and dependent nodes
80
89
  for (const nodePointer of nodePointersToUpdate) {
81
90
  // sequential: each iteration updates the record
82
- yield updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect }); // NOSONAR
91
+ yield updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect, dateModified }); // NOSONAR
83
92
  }
84
93
  return updateResult;
85
94
  });
86
95
  const updateFileNameInNode = (params) => __awaiter(void 0, void 0, void 0, function* () {
87
- const { user, survey, updateResult, sideEffect, node, nodeDef } = params;
96
+ const { user, survey, updateResult, sideEffect, node, nodeDef, dateModified } = params;
88
97
  const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef);
89
98
  try {
90
99
  const fileNameCalculated = yield calculateFileName({ user, survey, record: updateResult.record, node });
@@ -93,7 +102,7 @@ const updateFileNameInNode = (params) => __awaiter(void 0, void 0, void 0, funct
93
102
  const nodeUpdated = RecordNodes.mergeNodes(node, {
94
103
  value: { [RecordNodeValues.ValuePropsFile.fileNameCalculated]: fileNameCalculated },
95
104
  updated: true,
96
- dateModified: Dates.nowFormattedForStorage(),
105
+ dateModified: dateModified !== null && dateModified !== void 0 ? dateModified : Dates.nowFormattedForStorage(),
97
106
  });
98
107
  updateResult.addNode(nodeUpdated, { sideEffect });
99
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsFileNamesEvaluator.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAGL,WAAW,EAEX,gBAAgB,GACjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAoB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,EAAe,OAAO,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,KAAK,EAA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E,MAAM,oBAAoB,GAAG,QAAQ,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAA;IACpE,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAG,MAAM,iBAAiB,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;QACvG,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;QAC1E,IAAI,kBAAkB,KAAK,qBAAqB,EAAE,CAAC;YACjD,MAAM,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE;gBAC/C,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,cAAc,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,EAAE;gBACnF,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,KAAK,CAAC,sBAAsB,EAAE;aAC7C,CAAC,CAAA;YACF,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,qBAAqB,GAAG,CAAC,wBAAwB,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,oBAAqB,EAAE,CAAC,CAAC,CAAA;QAC9G,UAAU,CAAC;YACT,KAAK;YACL,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,gCAAgC;YACjE,cAAc,EAAE,oBAAoB,CAAC,QAAQ;YAC7C,MAAM;YACN,OAAO;YACP,qBAAqB;SACtB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaUser } from '../../auth'\nimport {\n ArenaRecordNode,\n ArenaRecordNodePointer,\n RecordNodes,\n ArenaRecordNodeValueFile,\n RecordNodeValues,\n} from '../../node'\nimport { ArenaNodeDefFile, NodeDefs } from '../../nodeDef'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\nimport { ArenaSurvey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Dates, FileNames, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { throwError } from './recordNodesDependentsUpdaterCommons'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst fileNameWithPositionSuffixRegExp = /^.+\\s\\[\\d+\\]$/ // file name like \"name [1].test\"\n\nconst addPositionSuffix = (params: { fileName: string; position: number }) => {\n const { fileName, position } = params\n return `${fileName} [${position}]`\n}\n\nconst calculateFileName = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): Promise<string | undefined> => {\n const { user, survey, record, node } = params\n\n const nodeDef: ArenaNodeDefFile = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) as ArenaNodeDefFile\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef)\n if (!fileNameExpression) return undefined\n\n const { value } = node\n\n let fileNameCalculated = await expressionEvaluator.evalExpression({\n user,\n survey,\n record,\n node,\n query: fileNameExpression,\n })\n if (!fileNameCalculated) return undefined\n\n fileNameCalculated = String(fileNameCalculated)\n if (NodeDefs.isMultiple(nodeDef) && !fileNameWithPositionSuffixRegExp.test(fileNameCalculated)) {\n const index = Records.getNodeIndex(node)(record)\n fileNameCalculated = addPositionSuffix({ fileName: fileNameCalculated, position: index + 1 })\n }\n\n // add extension from original file name\n const originalFilaName = value ? (value as ArenaRecordNodeValueFile).fileName : undefined\n if (Objects.isNotEmpty(originalFilaName)) {\n const originalExtension = FileNames.getExtension(originalFilaName)\n fileNameCalculated = FileNames.addExtensionIfMissing(fileNameCalculated, originalExtension)\n }\n return fileNameCalculated\n}\n\nconst updateFileNamesInNodes = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n sideEffect?: boolean\n}): Promise<void> => {\n const { user, survey, nodePointer, updateResult, sideEffect = false } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted) return\n\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (!expressionToEvaluate) return\n\n const { record } = updateResult\n\n const nodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n\n for (const node of nodes) {\n if (!RecordNodes.isValueBlank(node)) {\n // sequential: each iteration updates the record\n await updateFileNameInNode({ user, survey, updateResult, sideEffect, nodeDef: nodeDef as ArenaNodeDefFile, node }) // NOSONAR\n }\n }\n}\n\nexport const updateSelfAndDependentsFileNames = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { user, survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.fileName,\n true\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect }) // NOSONAR\n }\n return updateResult\n}\n\nconst updateFileNameInNode = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n sideEffect: boolean\n nodeDef: ArenaNodeDefFile\n node: ArenaRecordNode\n}): Promise<void> => {\n const { user, survey, updateResult, sideEffect, node, nodeDef } = params\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef)\n try {\n const fileNameCalculated = await calculateFileName({ user, survey, record: updateResult.record, node })\n const oldFileNameCalculated = RecordNodeValues.getFileNameCalculated(node)\n if (fileNameCalculated !== oldFileNameCalculated) {\n const nodeUpdated = RecordNodes.mergeNodes(node, {\n value: { [RecordNodeValues.ValuePropsFile.fileNameCalculated]: fileNameCalculated },\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n }\n } catch (error) {\n const expressionsToEvaluate = [NodeDefExpressionFactory.createInstance({ expression: expressionToEvaluate! })]\n throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsFileNames,\n expressionType: SurveyDependencyType.fileName,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsFileNamesEvaluator.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE7C,OAAO,EAGL,WAAW,EAEX,gBAAgB,GACjB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAoB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAChE,OAAO,EAAe,OAAO,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,OAAO,EAAE,UAAU,EAAE,MAAM,uCAAuC,CAAA;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAE3D,MAAM,gCAAgC,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I,CAAC,CAAA;QAC1E,IAAI,kBAAkB,KAAK,qBAAqB,EAAE,CAAC;YACjD,MAAM,WAAW,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,EAAE;gBAC/C,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,cAAc,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,EAAE;gBACnF,OAAO,EAAE,IAAI;gBACb,YAAY,EAAE,YAAY,aAAZ,YAAY,cAAZ,YAAY,GAAI,KAAK,CAAC,sBAAsB,EAAE;aAC7D,CAAC,CAAA;YACF,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QACnD,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,qBAAqB,GAAG,CAAC,wBAAwB,CAAC,cAAc,CAAC,EAAE,UAAU,EAAE,oBAAqB,EAAE,CAAC,CAAC,CAAA;QAC9G,UAAU,CAAC;YACT,KAAK;YACL,QAAQ,EAAE,eAAe,CAAC,MAAM,CAAC,gCAAgC;YACjE,cAAc,EAAE,oBAAoB,CAAC,QAAQ;YAC7C,MAAM;YACN,OAAO;YACP,qBAAqB;SACtB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA","sourcesContent":["import { SystemErrorKeys } from '../../error'\nimport { ArenaUser } from '../../auth'\nimport {\n ArenaRecordNode,\n ArenaRecordNodePointer,\n RecordNodes,\n ArenaRecordNodeValueFile,\n RecordNodeValues,\n} from '../../node'\nimport { ArenaNodeDefFile, NodeDefs } from '../../nodeDef'\nimport { NodeDefExpressionFactory } from '../../nodeDef/nodeDef'\nimport { ArenaSurvey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Dates, FileNames, Objects } from '../../utils'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { throwError } from './recordNodesDependentsUpdaterCommons'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst fileNameWithPositionSuffixRegExp = /^.+\\s\\[\\d+\\]$/ // file name like \"name [1].test\"\n\nconst addPositionSuffix = (params: { fileName: string; position: number }) => {\n const { fileName, position } = params\n return `${fileName} [${position}]`\n}\n\nconst calculateFileName = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n}): Promise<string | undefined> => {\n const { user, survey, record, node } = params\n\n const nodeDef: ArenaNodeDefFile = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) as ArenaNodeDefFile\n const fileNameExpression = NodeDefs.getFileNameExpression(nodeDef)\n if (!fileNameExpression) return undefined\n\n const { value } = node\n\n let fileNameCalculated = await expressionEvaluator.evalExpression({\n user,\n survey,\n record,\n node,\n query: fileNameExpression,\n })\n if (!fileNameCalculated) return undefined\n\n fileNameCalculated = String(fileNameCalculated)\n if (NodeDefs.isMultiple(nodeDef) && !fileNameWithPositionSuffixRegExp.test(fileNameCalculated)) {\n const index = Records.getNodeIndex(node)(record)\n fileNameCalculated = addPositionSuffix({ fileName: fileNameCalculated, position: index + 1 })\n }\n\n // add extension from original file name\n const originalFilaName = value ? (value as ArenaRecordNodeValueFile).fileName : undefined\n if (Objects.isNotEmpty(originalFilaName)) {\n const originalExtension = FileNames.getExtension(originalFilaName)\n fileNameCalculated = FileNames.addExtensionIfMissing(fileNameCalculated, originalExtension)\n }\n return fileNameCalculated\n}\n\nconst updateFileNamesInNodes = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n nodePointer: ArenaRecordNodePointer\n updateResult: RecordUpdateResult\n sideEffect?: boolean\n dateModified?: string\n}): Promise<void> => {\n const { user, survey, nodePointer, updateResult, sideEffect = false, dateModified } = params\n\n const { nodeCtx, nodeDef } = nodePointer\n\n if (nodeCtx.deleted) return\n\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef as ArenaNodeDefFile)\n if (!expressionToEvaluate) return\n\n const { record } = updateResult\n\n const nodes = RecordNodePointers.getNodesFromNodePointers({ record, nodePointers: [nodePointer] })\n\n for (const node of nodes) {\n if (!RecordNodes.isValueBlank(node)) {\n const updateParams = {\n user,\n survey,\n updateResult,\n sideEffect,\n nodeDef: nodeDef as ArenaNodeDefFile,\n node,\n dateModified,\n }\n // sequential: each iteration updates the record\n await updateFileNameInNode(updateParams) // NOSONAR\n }\n }\n}\n\nexport const updateSelfAndDependentsFileNames = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { user, survey, record, node, sideEffect = false, dateModified } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n // 1. get dependent node pointers\n\n const nodePointersToUpdate = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.fileName,\n true\n )(record)\n\n // 2. update expr to node and dependent nodes\n for (const nodePointer of nodePointersToUpdate) {\n // sequential: each iteration updates the record\n await updateFileNamesInNodes({ user, survey, nodePointer, updateResult, sideEffect, dateModified }) // NOSONAR\n }\n return updateResult\n}\n\nconst updateFileNameInNode = async (params: {\n user: ArenaUser\n survey: ArenaSurvey\n updateResult: RecordUpdateResult\n sideEffect: boolean\n nodeDef: ArenaNodeDefFile\n node: ArenaRecordNode\n dateModified?: string\n}): Promise<void> => {\n const { user, survey, updateResult, sideEffect, node, nodeDef, dateModified } = params\n const expressionToEvaluate = NodeDefs.getFileNameExpression(nodeDef)\n try {\n const fileNameCalculated = await calculateFileName({ user, survey, record: updateResult.record, node })\n const oldFileNameCalculated = RecordNodeValues.getFileNameCalculated(node)\n if (fileNameCalculated !== oldFileNameCalculated) {\n const nodeUpdated = RecordNodes.mergeNodes(node, {\n value: { [RecordNodeValues.ValuePropsFile.fileNameCalculated]: fileNameCalculated },\n updated: true,\n dateModified: dateModified ?? Dates.nowFormattedForStorage(),\n })\n updateResult.addNode(nodeUpdated, { sideEffect })\n }\n } catch (error) {\n const expressionsToEvaluate = [NodeDefExpressionFactory.createInstance({ expression: expressionToEvaluate! })]\n throwError({\n error,\n errorKey: SystemErrorKeys.record.updateSelfAndDependentsFileNames,\n expressionType: SurveyDependencyType.fileName,\n survey,\n nodeDef,\n expressionsToEvaluate,\n })\n }\n}\n"]}
@@ -13,15 +13,15 @@ import { Surveys } from '../../survey';
13
13
  import { SurveyDependencyType } from '../../survey/survey';
14
14
  import { getNodesByDefUuid } from '../_records/recordGetters';
15
15
  import { RecordExpressionEvaluator } from '../recordExpressionEvaluator';
16
- import { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons';
16
+ import { getDependentNodePointersByType, getNodeCurrent } from './recordNodesDependentsUpdaterCommons';
17
17
  import { RecordUpdateResult } from './recordUpdateResult';
18
18
  const expressionEvaluator = new RecordExpressionEvaluator();
19
19
  /**
20
20
  * Evaluates the "required if" condition of the specified child def in the context of the specified parent entity.
21
21
  */
22
22
  export const evaluateRequiredIf = (params) => __awaiter(void 0, void 0, void 0, function* () {
23
- const { nodeCtx, nodeDef } = params;
24
- const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { nodeCtx, expressions: NodeDefs.getRequiredIf(nodeDef) }));
23
+ const { record, nodeCtx, nodeDef } = params;
24
+ const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { nodeCtx, nodeCurrent: getNodeCurrent({ record, nodeCtx, nodeDef }), expressions: NodeDefs.getRequiredIf(nodeDef) }));
25
25
  return !!(exprEval === null || exprEval === void 0 ? void 0 : exprEval.value);
26
26
  });
27
27
  /**
@@ -29,7 +29,7 @@ export const evaluateRequiredIf = (params) => __awaiter(void 0, void 0, void 0,
29
29
  */
30
30
  export const updateSelfAndDependentsRequired = (params) => __awaiter(void 0, void 0, void 0, function* () {
31
31
  var _a;
32
- const { survey, record, node, sideEffect = false } = params;
32
+ const { survey, record, node, sideEffect = false, dateModified } = params;
33
33
  const updateResult = new RecordUpdateResult({ record });
34
34
  const nodePointersToUpdate = getDependentNodePointersByType({
35
35
  survey,
@@ -47,7 +47,7 @@ export const updateSelfAndDependentsRequired = (params) => __awaiter(void 0, voi
47
47
  const value = yield evaluateRequiredIf(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, nodeDef })); // NOSONAR
48
48
  if (valuePrev === value)
49
49
  continue;
50
- const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect });
50
+ const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect, dateModified });
51
51
  updateResult.addNode(nodeCtxUpdated, { sideEffect });
52
52
  }
53
53
  return updateResult;
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsRequiredUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAmB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AAExE,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,MAGC,EACiB,EAAE;IACpB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IACnC,MAAM,QAAQ,GA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IACH,CAAC;AACH,CAAC,CAAA,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAA2E,EAC9C,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IAC/C,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;QACxE,IAAI,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA;YAAE,SAAQ;QAClC,mFAAmF;QACnF,MAAM,0BAA0B,iCAAM,MAAM,KAAE,OAAO,EAAE,YAAY,IAAG,CAAA,CAAC,UAAU;IACnF,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, RecordNodes } from '../../node'\nimport { ArenaAnyNodeDef, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { ArenaRecordExpressionEvaluationContext } from './recordExpressionEvaluationContext'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Evaluates the \"required if\" condition of the specified child def in the context of the specified parent entity.\n */\nexport const evaluateRequiredIf = async (\n params: ArenaRecordExpressionEvaluationContext & {\n nodeCtx: ArenaRecordNode\n nodeDef: ArenaAnyNodeDef\n }\n): Promise<boolean> => {\n const { nodeCtx, nodeDef } = params\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n nodeCtx,\n expressions: NodeDefs.getRequiredIf(nodeDef),\n })\n return !!exprEval?.value\n}\n\n/**\n * Updates the \"required if\" flags (parent node meta `cReq`) of the node itself (if attribute) and of its dependents.\n */\nexport const updateSelfAndDependentsRequired = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.required,\n includeSelfWhenSourceIsAttribute: true,\n filterFn: (nodePointer) => NodeDefs.isRequiredIfDefined(nodePointer.nodeDef),\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const { nodeCtx: nodeCtxNodePointer, nodeDef } of nodePointersToUpdate) {\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxNodePointer.uuid) ?? nodeCtxNodePointer\n const valuePrev = RecordNodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // NOSONAR: sequential evaluation needed (see note above)\n const value = await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef }) // NOSONAR\n if (valuePrev === value) continue\n\n const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n return updateResult\n}\n\nconst updateNodeDefRequiredFlags = async (\n params: ArenaRecordExpressionEvaluationContext & {\n nodeDef: ArenaAnyNodeDef\n updateResult: RecordUpdateResult\n }\n): Promise<void> => {\n const { nodeDef, updateResult, sideEffect = false } = params\n const requiredIfDefined = NodeDefs.isRequiredIfDefined(nodeDef)\n const parentNodes = getNodesByDefUuid(nodeDef.parentUuid!)(updateResult.record)\n\n for (const parentNode of parentNodes) {\n const nodeCtx = updateResult.getNodeByUuid(parentNode.uuid) ?? parentNode\n const valuePrev = RecordNodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // sequential evaluation: the same parent node can be updated for different child defs\n const value =\n requiredIfDefined && (await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef })) // NOSONAR\n if (value !== valuePrev) {\n const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n }\n}\n\n/**\n * Recomputes the \"required if\" flags (parent node meta `cReq`) of the specified node defs in the whole record,\n * e.g. after their \"required if\" condition has been added, changed or removed. Validation is not updated.\n */\nexport const updateRequiredFlags = async (\n params: ArenaRecordExpressionEvaluationContext & { nodeDefUuids: string[] }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodeDefUuids } = params\n const updateResult = new RecordUpdateResult({ record })\n\n for (const nodeDefUuid of nodeDefUuids) {\n const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: nodeDefUuid })\n if (!nodeDef?.parentUuid) continue\n // sequential: each node def update works on the record updated by the previous one\n await updateNodeDefRequiredFlags({ ...params, nodeDef, updateResult }) // NOSONAR\n }\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsRequiredUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAmB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AAExE,OAAO,EAAE,8BAA8B,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAEtG,OA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M,kBAAkB,iCAAM,MAAM,KAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,IAAG,CAAC,CAAA,CAAC,UAAU;QAC1H,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxB,MAAM,cAAc,GAAG,WAAW,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;YACnG,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;AACH,CAAC,CAAA,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAA2E,EAC9C,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IAC/C,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;QACxE,IAAI,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA;YAAE,SAAQ;QAClC,mFAAmF;QACnF,MAAM,0BAA0B,iCAAM,MAAM,KAAE,OAAO,EAAE,YAAY,IAAG,CAAA,CAAC,UAAU;IACnF,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, RecordNodes } from '../../node'\nimport { ArenaAnyNodeDef, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { ArenaRecordExpressionEvaluationContext } from './recordExpressionEvaluationContext'\nimport { getDependentNodePointersByType, getNodeCurrent } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Evaluates the \"required if\" condition of the specified child def in the context of the specified parent entity.\n */\nexport const evaluateRequiredIf = async (\n params: ArenaRecordExpressionEvaluationContext & {\n nodeCtx: ArenaRecordNode\n nodeDef: ArenaAnyNodeDef\n }\n): Promise<boolean> => {\n const { record, nodeCtx, nodeDef } = params\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n nodeCtx,\n nodeCurrent: getNodeCurrent({ record, nodeCtx, nodeDef }),\n expressions: NodeDefs.getRequiredIf(nodeDef),\n })\n return !!exprEval?.value\n}\n\n/**\n * Updates the \"required if\" flags (parent node meta `cReq`) of the node itself (if attribute) and of its dependents.\n */\nexport const updateSelfAndDependentsRequired = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false, dateModified } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.required,\n includeSelfWhenSourceIsAttribute: true,\n filterFn: (nodePointer) => NodeDefs.isRequiredIfDefined(nodePointer.nodeDef),\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const { nodeCtx: nodeCtxNodePointer, nodeDef } of nodePointersToUpdate) {\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxNodePointer.uuid) ?? nodeCtxNodePointer\n const valuePrev = RecordNodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // NOSONAR: sequential evaluation needed (see note above)\n const value = await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef }) // NOSONAR\n if (valuePrev === value) continue\n\n const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect, dateModified })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n return updateResult\n}\n\nconst updateNodeDefRequiredFlags = async (\n params: ArenaRecordExpressionEvaluationContext & {\n nodeDef: ArenaAnyNodeDef\n updateResult: RecordUpdateResult\n }\n): Promise<void> => {\n const { nodeDef, updateResult, sideEffect = false } = params\n const requiredIfDefined = NodeDefs.isRequiredIfDefined(nodeDef)\n const parentNodes = getNodesByDefUuid(nodeDef.parentUuid!)(updateResult.record)\n\n for (const parentNode of parentNodes) {\n const nodeCtx = updateResult.getNodeByUuid(parentNode.uuid) ?? parentNode\n const valuePrev = RecordNodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // sequential evaluation: the same parent node can be updated for different child defs\n const value =\n requiredIfDefined && (await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef })) // NOSONAR\n if (value !== valuePrev) {\n const nodeCtxUpdated = RecordNodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n }\n}\n\n/**\n * Recomputes the \"required if\" flags (parent node meta `cReq`) of the specified node defs in the whole record,\n * e.g. after their \"required if\" condition has been added, changed or removed. Validation is not updated.\n */\nexport const updateRequiredFlags = async (\n params: ArenaRecordExpressionEvaluationContext & { nodeDefUuids: string[] }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodeDefUuids } = params\n const updateResult = new RecordUpdateResult({ record })\n\n for (const nodeDefUuid of nodeDefUuids) {\n const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: nodeDefUuid })\n if (!nodeDef?.parentUuid) continue\n // sequential: each node def update works on the record updated by the previous one\n await updateNodeDefRequiredFlags({ ...params, nodeDef, updateResult }) // NOSONAR\n }\n return updateResult\n}\n"]}
@@ -1,7 +1,28 @@
1
1
  import { SystemError } from '../../error';
2
2
  import { NodeDefs } from '../../nodeDef';
3
- import { Surveys } from '../../survey';
3
+ import { SurveyDependencyType, Surveys } from '../../survey';
4
4
  import { Records } from '../records';
5
+ /**
6
+ * Returns the node referenced by "this" when evaluating the expressions of a node def in the context of its parent entity:
7
+ * the node of the node def, if single; null if the node def is multiple (the node is not determined) or the node doesn't exist.
8
+ */
9
+ export const getNodeCurrent = (params) => {
10
+ var _a;
11
+ const { record, nodeCtx, nodeDef } = params;
12
+ if (NodeDefs.isMultiple(nodeDef))
13
+ return null;
14
+ return (_a = Records.getChildren(nodeCtx, nodeDef.uuid)(record)[0]) !== null && _a !== void 0 ? _a : null;
15
+ };
16
+ /**
17
+ * Returns true if the expressions of the node def use the app info functions (appId, appIdLabel, appPlatform, appVersion)
18
+ * but the app info is not available (e.g. update done by a server job): they must not be evaluated
19
+ * (they would return null), the current values are kept.
20
+ */
21
+ export const isAppInfoMissing = (params) => {
22
+ var _a, _b;
23
+ const { survey, appInfo, nodeDef } = params;
24
+ return !appInfo && !!((_b = (_a = survey.dependencyGraph) === null || _a === void 0 ? void 0 : _a[SurveyDependencyType.appInfo]) === null || _b === void 0 ? void 0 : _b[nodeDef.uuid]);
25
+ };
5
26
  export const throwError = (params) => {
6
27
  const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params;
7
28
  const nodeDefName = nodeDef.props.name;
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAA2C,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAqC,OAAO,EAAE,MAAM,cAAc,CAAA;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAO1B,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAA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AC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,0EAA0E;IAC1E,IAAI,oBAAoB,EAAE,CAAC;QACzB,uBAAuB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1F,CAAC;IAED,uGAAuG;IACvG,IAAI,6BAA6B,EAAE,CAAC;QAClC,iCAAiC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA","sourcesContent":["import { SystemError } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer } from '../../node'\nimport { ArenaAnyNodeDef, ArenaNodeDefExpression, NodeDefs } from '../../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../../survey'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\nexport const throwError = (params: {\n error: any\n errorKey: string\n expressionType: SurveyDependencyType\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n expressionsToEvaluate: ArenaNodeDefExpression[]\n}) => {\n const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params\n const nodeDefName = nodeDef.props.name\n const expressionsString = JSON.stringify(expressionsToEvaluate)\n\n throw new SystemError(\n errorKey,\n {\n surveyName: survey.props.name,\n nodeDefName,\n expressionType,\n expressionsString,\n error: error.toString(),\n errorJson: error instanceof SystemError ? error.toJSON() : null,\n },\n { cause: error }\n )\n}\n\nconst addPointerIfAccepted = (params: {\n nodePointers: ArenaRecordNodePointer[]\n pointer: ArenaRecordNodePointer\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, pointer, filterFn } = params\n if (!filterFn || filterFn(pointer)) {\n nodePointers.push(pointer)\n }\n}\n\nconst addNewEntitySelfPointer = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, record, node, sourceNodeDef, filterFn } = params\n if (!node.parentUuid) {\n return\n }\n const parentNode = Records.getNodeByUuid(node.parentUuid)(record)\n if (!parentNode) {\n return\n }\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: parentNode, nodeDef: sourceNodeDef },\n filterFn,\n })\n}\n\nconst addNewEntityChildMultiplePointers = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, survey, node, sourceNodeDef, filterFn } = params\n const multipleNodeDefs = Surveys.getNodeDefChildren({ survey, nodeDef: sourceNodeDef }).filter(NodeDefs.isMultiple)\n\n for (const childDef of multipleNodeDefs) {\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: node, nodeDef: childDef },\n filterFn,\n })\n }\n}\n\nexport const getDependentNodePointersByType = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n dependencyType: SurveyDependencyType\n includeSelfWhenSourceIsAttribute?: boolean\n includeNewEntitySelf?: boolean\n includeNewEntityChildPointers?: boolean\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}): ArenaRecordNodePointer[] => {\n const {\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute = false,\n includeNewEntitySelf = false,\n includeNewEntityChildPointers = false,\n filterFn,\n } = params\n\n const sourceNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const includeSelf = includeSelfWhenSourceIsAttribute && !NodeDefs.isEntity(sourceNodeDef)\n\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType, includeSelf, filterFn)(record)\n\n if (!NodeDefs.isEntity(sourceNodeDef) || !node.created) {\n return nodePointers\n }\n\n // For newly created entities, include a self-pointer for the source node.\n if (includeNewEntitySelf) {\n addNewEntitySelfPointer({ nodePointers, survey, record, node, sourceNodeDef, filterFn })\n }\n\n // For new entities, include child multiple nodes so their dependency metadata/status gets updated too.\n if (includeNewEntityChildPointers) {\n addNewEntityChildMultiplePointers({ nodePointers, survey, node, sourceNodeDef, filterFn })\n }\n\n return nodePointers\n}\n"]}
1
+ {"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,EAA2C,QAAQ,EAAE,MAAM,eAAe,CAAA;AACjF,OAAO,EAAe,oBAAoB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,MAI9B,EAA0B,EAAE;;IAC3B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC3C,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAA;IAC7C,aAAO,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAA;AACtE,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAIhC,EAAW,EAAE;;IACZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC3C,OAAO,C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;IAClF,MAAM,WAAW,GAAG,gCAAgC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IAEzF,MAAM,YAAY,GAAG,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAA;IAElH,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,0EAA0E;IAC1E,IAAI,oBAAoB,EAAE,CAAC;QACzB,uBAAuB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1F,CAAC;IAED,uGAAuG;IACvG,IAAI,6BAA6B,EAAE,CAAC;QAClC,iCAAiC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA","sourcesContent":["import { SystemError } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer } from '../../node'\nimport { ArenaAnyNodeDef, ArenaNodeDefExpression, NodeDefs } from '../../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../../survey'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\n/**\n * Returns the node referenced by \"this\" when evaluating the expressions of a node def in the context of its parent entity:\n * the node of the node def, if single; null if the node def is multiple (the node is not determined) or the node doesn't exist.\n */\nexport const getNodeCurrent = (params: {\n record: ArenaRecord\n nodeCtx: ArenaRecordNode\n nodeDef: ArenaAnyNodeDef\n}): ArenaRecordNode | null => {\n const { record, nodeCtx, nodeDef } = params\n if (NodeDefs.isMultiple(nodeDef)) return null\n return Records.getChildren(nodeCtx, nodeDef.uuid)(record)[0] ?? null\n}\n\n/**\n * Returns true if the expressions of the node def use the app info functions (appId, appIdLabel, appPlatform, appVersion)\n * but the app info is not available (e.g. update done by a server job): they must not be evaluated\n * (they would return null), the current values are kept.\n */\nexport const isAppInfoMissing = (params: {\n survey: ArenaSurvey\n appInfo?: unknown\n nodeDef: ArenaAnyNodeDef\n}): boolean => {\n const { survey, appInfo, nodeDef } = params\n return !appInfo && !!survey.dependencyGraph?.[SurveyDependencyType.appInfo]?.[nodeDef.uuid]\n}\n\nexport const throwError = (params: {\n error: any\n errorKey: string\n expressionType: SurveyDependencyType\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n expressionsToEvaluate: ArenaNodeDefExpression[]\n}) => {\n const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params\n const nodeDefName = nodeDef.props.name\n const expressionsString = JSON.stringify(expressionsToEvaluate)\n\n throw new SystemError(\n errorKey,\n {\n surveyName: survey.props.name,\n nodeDefName,\n expressionType,\n expressionsString,\n error: error.toString(),\n errorJson: error instanceof SystemError ? error.toJSON() : null,\n },\n { cause: error }\n )\n}\n\nconst addPointerIfAccepted = (params: {\n nodePointers: ArenaRecordNodePointer[]\n pointer: ArenaRecordNodePointer\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, pointer, filterFn } = params\n if (!filterFn || filterFn(pointer)) {\n nodePointers.push(pointer)\n }\n}\n\nconst addNewEntitySelfPointer = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, record, node, sourceNodeDef, filterFn } = params\n if (!node.parentUuid) {\n return\n }\n const parentNode = Records.getNodeByUuid(node.parentUuid)(record)\n if (!parentNode) {\n return\n }\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: parentNode, nodeDef: sourceNodeDef },\n filterFn,\n })\n}\n\nconst addNewEntityChildMultiplePointers = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, survey, node, sourceNodeDef, filterFn } = params\n const multipleNodeDefs = Surveys.getNodeDefChildren({ survey, nodeDef: sourceNodeDef }).filter(NodeDefs.isMultiple)\n\n for (const childDef of multipleNodeDefs) {\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: node, nodeDef: childDef },\n filterFn,\n })\n }\n}\n\nexport const getDependentNodePointersByType = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n dependencyType: SurveyDependencyType\n includeSelfWhenSourceIsAttribute?: boolean\n includeNewEntitySelf?: boolean\n includeNewEntityChildPointers?: boolean\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}): ArenaRecordNodePointer[] => {\n const {\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute = false,\n includeNewEntitySelf = false,\n includeNewEntityChildPointers = false,\n filterFn,\n } = params\n\n const sourceNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const includeSelf = includeSelfWhenSourceIsAttribute && !NodeDefs.isEntity(sourceNodeDef)\n\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType, includeSelf, filterFn)(record)\n\n if (!NodeDefs.isEntity(sourceNodeDef) || !node.created) {\n return nodePointers\n }\n\n // For newly created entities, include a self-pointer for the source node.\n if (includeNewEntitySelf) {\n addNewEntitySelfPointer({ nodePointers, survey, record, node, sourceNodeDef, filterFn })\n }\n\n // For new entities, include child multiple nodes so their dependency metadata/status gets updated too.\n if (includeNewEntityChildPointers) {\n addNewEntityChildMultiplePointers({ nodePointers, survey, node, sourceNodeDef, filterFn })\n }\n\n return nodePointers\n}\n"]}
@@ -7,10 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { Queue } from '../../utils';
11
- import { NodeDefCountType } from '../../nodeDef';
12
- import { Surveys } from '../../survey';
13
- import { getNodesByDefUuid } from '../_records/recordGetters';
10
+ import { Dates, Queue } from '../../utils';
11
+ import { RecordNodes } from '../../node';
12
+ import { NodeDefCountType, NodeDefs } from '../../nodeDef';
13
+ import { SurveyDependencyType, Surveys } from '../../survey';
14
+ import { getDependentNodePointers, getDescendantsOrSelf, getNodeByUuid, getNodesByDefUuid, } from '../_records/recordGetters';
15
+ import { RecordNodePointers } from '../nodePointers';
14
16
  import { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater';
15
17
  import { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater';
16
18
  import { updateDependentsCount } from './recordNodeDependentsCountUpdater';
@@ -44,11 +46,81 @@ const dependentsUpdaters = [
44
46
  updateDependentEnumeratingItemsEntities,
45
47
  updateSelfAndDependentsFileNames,
46
48
  ];
49
+ /**
50
+ * True if the node modification changes the date modified of its ancestors:
51
+ * nodes created or deleted, and attributes (whose value changed); entities updated only in their meta
52
+ * (e.g. children applicability) are excluded.
53
+ */
54
+ const isModificationPropagatedToAncestors = (survey, node) => {
55
+ if (node.created || node.deleted)
56
+ return true;
57
+ const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: node.nodeDefUuid });
58
+ return !!nodeDef && !NodeDefs.isEntity(nodeDef);
59
+ };
60
+ /**
61
+ * Sets the date modified of the ancestors of the specified node (if not set already).
62
+ * @returns The ancestors updated.
63
+ */
64
+ const updateAncestorsDateModified = (params) => {
65
+ var _a;
66
+ const { node, updateResult, dateModified, sideEffect } = params;
67
+ const ancestorsUpdated = [];
68
+ for (const ancestorUuid of RecordNodes.getHierarchy(node)) {
69
+ const ancestor = (_a = updateResult.getNodeByUuid(ancestorUuid)) !== null && _a !== void 0 ? _a : getNodeByUuid(ancestorUuid)(updateResult.record);
70
+ if (!ancestor || ancestor.deleted || ancestor.dateModified === dateModified)
71
+ continue;
72
+ const ancestorAlreadyUpdated = !!updateResult.getNodeByUuid(ancestorUuid);
73
+ const ancestorUpdated = sideEffect ? ancestor : Object.assign({}, ancestor);
74
+ ancestorUpdated.dateModified = dateModified;
75
+ ancestorUpdated.updated = true;
76
+ updateResult.addNode(ancestorUpdated, { sideEffect });
77
+ if (!ancestorAlreadyUpdated) {
78
+ updateResult.dateModifiedOnlyNodeUuids.add(ancestorUuid);
79
+ }
80
+ ancestorsUpdated.push(ancestorUpdated);
81
+ }
82
+ return ancestorsUpdated;
83
+ };
84
+ /**
85
+ * Returns the nodes whose expressions use the dates of the specified entity (nodeDateCreated, nodeDateModified),
86
+ * e.g. the attributes in the entity with the expression "nodeDateModified(parent(this))".
87
+ */
88
+ const getNodeDatesDependentNodes = (params) => {
89
+ const { survey, record, entity } = params;
90
+ const dependentDefs = Surveys.getNodeDefDependents({
91
+ survey,
92
+ nodeDefUuid: entity.nodeDefUuid,
93
+ dependencyType: SurveyDependencyType.nodeDates,
94
+ });
95
+ if (dependentDefs.length === 0)
96
+ return [];
97
+ const result = [];
98
+ for (const dependentDef of dependentDefs) {
99
+ if (dependentDef.meta.h.includes(entity.nodeDefUuid)) {
100
+ // dependent def is a descendant of the entity def: only the dependent nodes in the entity are affected
101
+ result.push(...getDescendantsOrSelf(entity, dependentDef)(record));
102
+ }
103
+ else {
104
+ const nodePointers = getDependentNodePointers(survey, entity, SurveyDependencyType.nodeDates, false, (nodePointer) => nodePointer.nodeDef.uuid === dependentDef.uuid)(record);
105
+ result.push(...RecordNodePointers.getNodesFromNodePointers({ record, nodePointers }));
106
+ }
107
+ }
108
+ return result;
109
+ };
110
+ /**
111
+ * Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).
112
+ * The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).
113
+ * @param params.nodes - Nodes created, updated or deleted.
114
+ * @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).
115
+ */
47
116
  export const updateNodesDependents = (params) => __awaiter(void 0, void 0, void 0, function* () {
48
117
  var _a;
49
- const { survey, record, nodes } = params;
118
+ var _b, _c, _d;
119
+ const { survey, record, nodes, nodesToEvaluate, sideEffect = false } = params;
120
+ // the same date modified is used for all the nodes modified (it lets the propagation to the ancestors end)
121
+ const dateModified = (_b = params.dateModified) !== null && _b !== void 0 ? _b : Dates.nowFormattedForStorage();
50
122
  // always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited
51
- const initialNodesToVisit = Object.assign({}, nodes);
123
+ const initialNodesToVisit = Object.assign(Object.assign({}, nodesToEvaluate), nodes);
52
124
  // include onUpdate dependents (always included in every record update)
53
125
  const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey });
54
126
  if (onUpdateDependentDefs.length > 0) {
@@ -60,14 +132,44 @@ export const updateNodesDependents = (params) => __awaiter(void 0, void 0, void
60
132
  }
61
133
  }
62
134
  const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit });
63
- const createNodeUpdateParams = (node) => (Object.assign(Object.assign({}, params), { record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)
135
+ const createNodeUpdateParams = (node) => (Object.assign(Object.assign({}, params), { dateModified, record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)
64
136
  node }));
65
137
  const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit));
138
+ const hasNodeDatesDependencies = Object.keys((_c = (_a = survey.dependencyGraph) === null || _a === void 0 ? void 0 : _a[SurveyDependencyType.nodeDates]) !== null && _c !== void 0 ? _c : {}).length > 0;
139
+ // the dependents of the entities whose date modified changed (e.g. "nodeDateModified(parent(this))") are visited
140
+ // as sources ("self" evaluation): the entities themselves are not visited, they are not modified in their content
141
+ const visitNodeDatesDependents = (entities) => {
142
+ var _a;
143
+ var _b, _c;
144
+ if (!hasNodeDatesDependencies)
145
+ return;
146
+ for (const entity of entities) {
147
+ for (const dependentNode of getNodeDatesDependentNodes({ survey, record: updateResult.record, entity })) {
148
+ // included in the result (like the onUpdate dependents) so their validation is updated too
149
+ (_a = (_b = updateResult.nodes)[_c = dependentNode.uuid]) !== null && _a !== void 0 ? _a : (_b[_c] = dependentNode);
150
+ nodeUuidsToVisit.enqueue(dependentNode.uuid);
151
+ }
152
+ }
153
+ };
154
+ const updateAncestorsOfModifiedNodes = (modifiedNodes) => {
155
+ const entitiesUpdated = [];
156
+ for (const modifiedNode of modifiedNodes) {
157
+ if (isModificationPropagatedToAncestors(survey, modifiedNode)) {
158
+ entitiesUpdated.push(...updateAncestorsDateModified({ node: modifiedNode, updateResult, dateModified, sideEffect }));
159
+ }
160
+ else if (!modifiedNode.deleted) {
161
+ // entity updated in its meta (e.g. children applicability): its date modified changed
162
+ entitiesUpdated.push(modifiedNode);
163
+ }
164
+ }
165
+ visitNodeDatesDependents(entitiesUpdated);
166
+ };
167
+ updateAncestorsOfModifiedNodes(Object.values(nodes));
66
168
  // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)
67
169
  const visitedCountByUuid = {};
68
170
  while (!nodeUuidsToVisit.isEmpty()) {
69
171
  const nodeUuid = nodeUuidsToVisit.dequeue();
70
- const visitedCount = (_a = visitedCountByUuid[nodeUuid]) !== null && _a !== void 0 ? _a : 0;
172
+ const visitedCount = (_d = visitedCountByUuid[nodeUuid]) !== null && _d !== void 0 ? _d : 0;
71
173
  if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {
72
174
  const nodesUpdatedCurrent = {};
73
175
  for (const dependentsUpdater of dependentsUpdaters) {
@@ -79,6 +181,7 @@ export const updateNodesDependents = (params) => __awaiter(void 0, void 0, void
79
181
  }
80
182
  // Mark updated nodes to visit
81
183
  nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent));
184
+ updateAncestorsOfModifiedNodes(Object.values(nodesUpdatedCurrent));
82
185
  // Mark node as visited
83
186
  visitedCountByUuid[nodeUuid] = visitedCount + 1;
84
187
  }
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodesUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodesUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAInC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,iCAAiC,EAAE,MAAM,yCAAyC,CAAA;AAC3F,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAA;AAC3F,OAAO,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAC1E,OAAO,EAAE,oCAAoC,EAAE,MAAM,4CAA4C,CAAA;AACjG,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAA;AACvF,OAAO,EAAE,iCAAiC,EAAE,MAAM,iDAAiD,CAAA;AACnG,OAAO,EAAE,uCAAuC,EAAE,MAAM,+CAA+C,CAAA;AACvG,OAAO,EAAE,gCAAgC,EAAE,MAAM,0CAA0C,CAAA;AAE3F,OAAO,EAAE,+BAA+B,EAAE,MAAM,uCAAuC,CAAA;AACvF,OAAO,EAAE,8BAA8B,EAAE,MAAM,sCAAsC,CAAA;AAErF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD;;;;GAIG;AACH,MAAM,6BAA6B,GAAG,CAAC,CAAA;AAIvC;;GAEG;AACH,MAAM,kBAAkB,GAAkC;IACxD,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAqB,iCAAM,MAAM,KAAE,SAAS,EAAE,gBAAgB,CAAC,GAAG,IAAG;IACjF,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAqB,iCAAM,MAAM,KAAE,SAAS,EAAE,gBAAg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C,OAAO,EAAE,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,EAAG,CAAA;QAE5C,MAAM,YAAY,SAAG,kBAAkB,CAAC,QAAQ,CAAC,mCAAI,CAAC,CAAA;QAEtD,IAAI,YAAY,GAAG,6BAA6B,EAAE,CAAC;YACjD,MAAM,mBAAmB,GAAqC,EAAE,CAAA;YAChE,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;gBACnD,uGAAuG;gBACvG,MAAM,IAAI,GAAG,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;gBACjD,MAAM,sBAAsB,GAAG,MAAM,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,UAAU;gBAC/F,YAAY,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;gBAC1C,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;YAClE,CAAC;YAED,8BAA8B;YAC9B,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAE/D,uBAAuB;YACvB,kBAAkB,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { Queue } from '../../utils'\n\nimport { ArenaDictionary } from '../../common'\nimport { ArenaRecordNode } from '../../node'\nimport { NodeDefCountType } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater'\nimport { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater'\nimport { updateDependentsCount } from './recordNodeDependentsCountUpdater'\nimport { updateSelfAndDependentsDefaultValues } from './recordNodeDependentsDefaultValuesUpdater'\nimport { updateSelfAndDependentsEditable } from './recordNodeDependentsEditableUpdater'\nimport { updateDependentEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { updateDependentEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { updateSelfAndDependentsFileNames } from './recordNodeDependentsFileNamesEvaluator'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { updateSelfAndDependentsRequired } from './recordNodeDependentsRequiredUpdater'\nimport { updateSelfAndDependentsVisible } from './recordNodeDependentsVisibleUpdater'\nimport { ArenaRecordNodesUpdateParams } from './recordNodesCreator'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n/**\n * Nodes can be visited maximum 2 times during the update of the dependent nodes, to avoid loops in the evaluation.\n * The first time the applicability can depend on attributes with default values not applied yet.\n * The second time the applicability expression can be evaluated correctly.\n */\nconst MAX_DEPENDENTS_VISITING_TIMES = 2\n\ntype RecordNodeDependentsUpdater = (params: RecordNodeDependentsUpdateParams) => Promise<RecordUpdateResult>\n\n/**\n * Updaters applied (in this order) to every visited node and to its dependents.\n */\nconst dependentsUpdaters: RecordNodeDependentsUpdater[] = [\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.min }),\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.max }),\n updateSelfAndDependentsApplicable,\n updateSelfAndDependentsDefaultValues,\n updateSelfAndDependentsEditable,\n updateSelfAndDependentsRequired,\n updateSelfAndDependentsVisible,\n updateDependentCodeAttributes,\n updateDependentEnumeratedEntities,\n updateDependentEnumeratingItemsEntities,\n updateSelfAndDependentsFileNames,\n]\n\nexport const updateNodesDependents = async (\n params: ArenaRecordNodesUpdateParams & { nodes: ArenaDictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes } = params\n // always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited\n const initialNodesToVisit = { ...nodes }\n\n // include onUpdate dependents (always included in every record update)\n const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey })\n if (onUpdateDependentDefs.length > 0) {\n for (const dependentDef of onUpdateDependentDefs) {\n const dependentNodes = getNodesByDefUuid(dependentDef.uuid)(record)\n for (const node of dependentNodes) {\n initialNodesToVisit[node.uuid] = node\n }\n }\n }\n\n const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit })\n\n const createNodeUpdateParams = (node: ArenaRecordNode): RecordNodeDependentsUpdateParams => ({\n ...params,\n record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)\n node,\n })\n\n const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit))\n\n // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)\n const visitedCountByUuid: ArenaDictionary<number> = {}\n\n while (!nodeUuidsToVisit.isEmpty()) {\n const nodeUuid = nodeUuidsToVisit.dequeue()!\n\n const visitedCount = visitedCountByUuid[nodeUuid] ?? 0\n\n if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {\n const nodesUpdatedCurrent: ArenaDictionary<ArenaRecordNode> = {}\n for (const dependentsUpdater of dependentsUpdaters) {\n // updaters must run sequentially: each one works on the record (and node) updated by the previous ones\n const node = updateResult.getNodeByUuid(nodeUuid)\n const dependentsUpdateResult = await dependentsUpdater(createNodeUpdateParams(node)) // NOSONAR\n updateResult.merge(dependentsUpdateResult)\n Object.assign(nodesUpdatedCurrent, dependentsUpdateResult.nodes)\n }\n\n // Mark updated nodes to visit\n nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent))\n\n // Mark node as visited\n visitedCountByUuid[nodeUuid] = visitedCount + 1\n }\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodesUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodesUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAG1C,OAAO,EAAwC,WAAW,EAAE,MAAM,YAA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AA;IAC3C,CAAC,CAAA;IACD,8BAA8B,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;IAEpD,+GAA+G;IAC/G,MAAM,kBAAkB,GAA4B,EAAE,CAAA;IAEtD,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,EAAG,CAAA;QAE5C,MAAM,YAAY,SAAG,kBAAkB,CAAC,QAAQ,CAAC,mCAAI,CAAC,CAAA;QAEtD,IAAI,YAAY,GAAG,6BAA6B,EAAE,CAAC;YACjD,MAAM,mBAAmB,GAAqC,EAAE,CAAA;YAChE,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;gBACnD,uGAAuG;gBACvG,MAAM,IAAI,GAAG,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;gBACjD,MAAM,sBAAsB,GAAG,MAAM,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,UAAU;gBAC/F,YAAY,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;gBAC1C,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;YAClE,CAAC;YAED,8BAA8B;YAC9B,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAC/D,8BAA8B,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAElE,uBAAuB;YACvB,kBAAkB,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { Dates, Queue } from '../../utils'\n\nimport { ArenaDictionary } from '../../common'\nimport { ArenaRecordNode, ArenaRecordNodesMap, RecordNodes } from '../../node'\nimport { NodeDefCountType, NodeDefs } from '../../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../../survey'\nimport {\n getDependentNodePointers,\n getDescendantsOrSelf,\n getNodeByUuid,\n getNodesByDefUuid,\n} from '../_records/recordGetters'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater'\nimport { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater'\nimport { updateDependentsCount } from './recordNodeDependentsCountUpdater'\nimport { updateSelfAndDependentsDefaultValues } from './recordNodeDependentsDefaultValuesUpdater'\nimport { updateSelfAndDependentsEditable } from './recordNodeDependentsEditableUpdater'\nimport { updateDependentEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { updateDependentEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { updateSelfAndDependentsFileNames } from './recordNodeDependentsFileNamesEvaluator'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { updateSelfAndDependentsRequired } from './recordNodeDependentsRequiredUpdater'\nimport { updateSelfAndDependentsVisible } from './recordNodeDependentsVisibleUpdater'\nimport { ArenaRecordNodesUpdateParams } from './recordNodesCreator'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n/**\n * Nodes can be visited maximum 2 times during the update of the dependent nodes, to avoid loops in the evaluation.\n * The first time the applicability can depend on attributes with default values not applied yet.\n * The second time the applicability expression can be evaluated correctly.\n */\nconst MAX_DEPENDENTS_VISITING_TIMES = 2\n\ntype RecordNodeDependentsUpdater = (params: RecordNodeDependentsUpdateParams) => Promise<RecordUpdateResult>\n\n/**\n * Updaters applied (in this order) to every visited node and to its dependents.\n */\nconst dependentsUpdaters: RecordNodeDependentsUpdater[] = [\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.min }),\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.max }),\n updateSelfAndDependentsApplicable,\n updateSelfAndDependentsDefaultValues,\n updateSelfAndDependentsEditable,\n updateSelfAndDependentsRequired,\n updateSelfAndDependentsVisible,\n updateDependentCodeAttributes,\n updateDependentEnumeratedEntities,\n updateDependentEnumeratingItemsEntities,\n updateSelfAndDependentsFileNames,\n]\n\n/**\n * True if the node modification changes the date modified of its ancestors:\n * nodes created or deleted, and attributes (whose value changed); entities updated only in their meta\n * (e.g. children applicability) are excluded.\n */\nconst isModificationPropagatedToAncestors = (survey: ArenaSurvey, node: ArenaRecordNode): boolean => {\n if (node.created || node.deleted) return true\n const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n return !!nodeDef && !NodeDefs.isEntity(nodeDef)\n}\n\n/**\n * Sets the date modified of the ancestors of the specified node (if not set already).\n * @returns The ancestors updated.\n */\nconst updateAncestorsDateModified = (params: {\n node: ArenaRecordNode\n updateResult: RecordUpdateResult\n dateModified: string\n sideEffect: boolean\n}): ArenaRecordNode[] => {\n const { node, updateResult, dateModified, sideEffect } = params\n const ancestorsUpdated: ArenaRecordNode[] = []\n for (const ancestorUuid of RecordNodes.getHierarchy(node)) {\n const ancestor = updateResult.getNodeByUuid(ancestorUuid) ?? getNodeByUuid(ancestorUuid)(updateResult.record)\n if (!ancestor || ancestor.deleted || ancestor.dateModified === dateModified) continue\n\n const ancestorAlreadyUpdated = !!updateResult.getNodeByUuid(ancestorUuid)\n const ancestorUpdated = sideEffect ? ancestor : { ...ancestor }\n ancestorUpdated.dateModified = dateModified\n ancestorUpdated.updated = true\n updateResult.addNode(ancestorUpdated, { sideEffect })\n if (!ancestorAlreadyUpdated) {\n updateResult.dateModifiedOnlyNodeUuids.add(ancestorUuid)\n }\n ancestorsUpdated.push(ancestorUpdated)\n }\n return ancestorsUpdated\n}\n\n/**\n * Returns the nodes whose expressions use the dates of the specified entity (nodeDateCreated, nodeDateModified),\n * e.g. the attributes in the entity with the expression \"nodeDateModified(parent(this))\".\n */\nconst getNodeDatesDependentNodes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n entity: ArenaRecordNode\n}): ArenaRecordNode[] => {\n const { survey, record, entity } = params\n const dependentDefs = Surveys.getNodeDefDependents({\n survey,\n nodeDefUuid: entity.nodeDefUuid,\n dependencyType: SurveyDependencyType.nodeDates,\n })\n if (dependentDefs.length === 0) return []\n\n const result: ArenaRecordNode[] = []\n for (const dependentDef of dependentDefs) {\n if (dependentDef.meta.h.includes(entity.nodeDefUuid)) {\n // dependent def is a descendant of the entity def: only the dependent nodes in the entity are affected\n result.push(...getDescendantsOrSelf(entity, dependentDef)(record))\n } else {\n const nodePointers = getDependentNodePointers(\n survey,\n entity,\n SurveyDependencyType.nodeDates,\n false,\n (nodePointer) => nodePointer.nodeDef.uuid === dependentDef.uuid\n )(record)\n result.push(...RecordNodePointers.getNodesFromNodePointers({ record, nodePointers }))\n }\n }\n return result\n}\n\n/**\n * Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).\n * The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).\n * @param params.nodes - Nodes created, updated or deleted.\n * @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).\n */\nexport const updateNodesDependents = async (\n params: ArenaRecordNodesUpdateParams & {\n nodes: ArenaDictionary<ArenaRecordNode>\n nodesToEvaluate?: ArenaRecordNodesMap\n }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes, nodesToEvaluate, sideEffect = false } = params\n // the same date modified is used for all the nodes modified (it lets the propagation to the ancestors end)\n const dateModified = params.dateModified ?? Dates.nowFormattedForStorage()\n // always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited\n const initialNodesToVisit = { ...nodesToEvaluate, ...nodes }\n\n // include onUpdate dependents (always included in every record update)\n const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey })\n if (onUpdateDependentDefs.length > 0) {\n for (const dependentDef of onUpdateDependentDefs) {\n const dependentNodes = getNodesByDefUuid(dependentDef.uuid)(record)\n for (const node of dependentNodes) {\n initialNodesToVisit[node.uuid] = node\n }\n }\n }\n\n const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit })\n\n const createNodeUpdateParams = (node: ArenaRecordNode): RecordNodeDependentsUpdateParams => ({\n ...params,\n dateModified,\n record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)\n node,\n })\n\n const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit))\n\n const hasNodeDatesDependencies =\n Object.keys(survey.dependencyGraph?.[SurveyDependencyType.nodeDates] ?? {}).length > 0\n\n // the dependents of the entities whose date modified changed (e.g. \"nodeDateModified(parent(this))\") are visited\n // as sources (\"self\" evaluation): the entities themselves are not visited, they are not modified in their content\n const visitNodeDatesDependents = (entities: ArenaRecordNode[]): void => {\n if (!hasNodeDatesDependencies) return\n for (const entity of entities) {\n for (const dependentNode of getNodeDatesDependentNodes({ survey, record: updateResult.record, entity })) {\n // included in the result (like the onUpdate dependents) so their validation is updated too\n updateResult.nodes[dependentNode.uuid] ??= dependentNode\n nodeUuidsToVisit.enqueue(dependentNode.uuid)\n }\n }\n }\n\n const updateAncestorsOfModifiedNodes = (modifiedNodes: ArenaRecordNode[]): void => {\n const entitiesUpdated: ArenaRecordNode[] = []\n for (const modifiedNode of modifiedNodes) {\n if (isModificationPropagatedToAncestors(survey, modifiedNode)) {\n entitiesUpdated.push(\n ...updateAncestorsDateModified({ node: modifiedNode, updateResult, dateModified, sideEffect })\n )\n } else if (!modifiedNode.deleted) {\n // entity updated in its meta (e.g. children applicability): its date modified changed\n entitiesUpdated.push(modifiedNode)\n }\n }\n visitNodeDatesDependents(entitiesUpdated)\n }\n updateAncestorsOfModifiedNodes(Object.values(nodes))\n\n // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)\n const visitedCountByUuid: ArenaDictionary<number> = {}\n\n while (!nodeUuidsToVisit.isEmpty()) {\n const nodeUuid = nodeUuidsToVisit.dequeue()!\n\n const visitedCount = visitedCountByUuid[nodeUuid] ?? 0\n\n if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {\n const nodesUpdatedCurrent: ArenaDictionary<ArenaRecordNode> = {}\n for (const dependentsUpdater of dependentsUpdaters) {\n // updaters must run sequentially: each one works on the record (and node) updated by the previous ones\n const node = updateResult.getNodeByUuid(nodeUuid)\n const dependentsUpdateResult = await dependentsUpdater(createNodeUpdateParams(node)) // NOSONAR\n updateResult.merge(dependentsUpdateResult)\n Object.assign(nodesUpdatedCurrent, dependentsUpdateResult.nodes)\n }\n\n // Mark updated nodes to visit\n nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent))\n updateAncestorsOfModifiedNodes(Object.values(nodesUpdatedCurrent))\n\n // Mark node as visited\n visitedCountByUuid[nodeUuid] = visitedCount + 1\n }\n }\n\n return updateResult\n}\n"]}
@@ -6,6 +6,7 @@ export class RecordUpdateResult {
6
6
  this.nodes = (_a = params.nodes) !== null && _a !== void 0 ? _a : {};
7
7
  this.nodesDeleted = (_b = params.nodesDeleted) !== null && _b !== void 0 ? _b : {};
8
8
  this.clearedDefUuids = (_c = params.clearedDefUuids) !== null && _c !== void 0 ? _c : new Set();
9
+ this.dateModifiedOnlyNodeUuids = new Set();
9
10
  this.validation = params.validation;
10
11
  }
11
12
  getNodeByUuid(uuid) {
@@ -37,6 +38,15 @@ export class RecordUpdateResult {
37
38
  for (const nodeDefUuid of recordUpdateResult.clearedDefUuids) {
38
39
  this.addClearedDefUuid(nodeDefUuid);
39
40
  }
41
+ for (const nodeUuid of Object.keys(recordUpdateResult.nodes)) {
42
+ // node updated in the merged result: not only in its date modified anymore
43
+ if (!recordUpdateResult.dateModifiedOnlyNodeUuids.has(nodeUuid)) {
44
+ this.dateModifiedOnlyNodeUuids.delete(nodeUuid);
45
+ }
46
+ }
47
+ for (const nodeUuid of recordUpdateResult.dateModifiedOnlyNodeUuids) {
48
+ this.dateModifiedOnlyNodeUuids.add(nodeUuid);
49
+ }
40
50
  return this;
41
51
  }
42
52
  }
@@ -1 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C;QAC1C,IAAI,CAAC,MAAM,GAAG,kBAAkB,CAAC,MAAM,CAAA;QACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAA;QACnD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAA;QACjE,KAAK,MAAM,WAAW,IAAI,kBAAkB,CAAC,eAAe,EAAE,CAAC;YAC7D,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAA;QACrC,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { ArenaRecordNode, ArenaRecordNodesMap } from '../../node'\nimport { ArenaValidation } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { addNode, addNodes } from '../_records/recordUpdater'\nimport { ArenaRecordUpdateOptions } from '../records'\n\nexport class RecordUpdateResult {\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n nodesDeleted: ArenaRecordNodesMap\n clearedDefUuids: Set<string>\n validation?: ArenaValidation\n\n constructor(params: {\n record: ArenaRecord\n nodes?: ArenaRecordNodesMap\n nodesDeleted?: ArenaRecordNodesMap\n clearedDefUuids?: Set<string>\n validation?: ArenaValidation\n }) {\n this.record = params.record\n this.nodes = params.nodes ?? {}\n this.nodesDeleted = params.nodesDeleted ?? {}\n this.clearedDefUuids = params.clearedDefUuids ?? new Set<string>()\n this.validation = params.validation\n }\n\n getNodeByUuid(uuid: string) {\n return this.nodes[uuid]\n }\n\n addNode(node: ArenaRecordNode, options?: ArenaRecordUpdateOptions) {\n this.nodes[node.uuid] = node\n this.record = addNode(node, options)(this.record)\n }\n\n addNodes(nodes: ArenaRecordNodesMap, options?: ArenaRecordUpdateOptions) {\n Object.assign(this.nodes, nodes)\n this.record = addNodes(nodes, options)(this.record)\n }\n\n addClearedDefUuid(nodeDefUuid: string) {\n this.clearedDefUuids.add(nodeDefUuid)\n }\n\n /**\n * Merges this record update result with the specified one.\n * The record of this record update result will be the one of the specified record update result\n * and the nodes of the specified one will be added to the nodes of this one.\n *\n * @param {!RecordUpdateResult} recordUpdateResult - The record update result to merge with.\n * @returns {RecordUpdateResult} - The updated object.\n */\n merge(recordUpdateResult: RecordUpdateResult): this {\n this.record = recordUpdateResult.record\n Object.assign(this.nodes, recordUpdateResult.nodes)\n Object.assign(this.nodesDeleted, recordUpdateResult.nodesDeleted)\n for (const nodeDefUuid of recordUpdateResult.clearedDefUuids) {\n this.addClearedDefUuid(nodeDefUuid)\n }\n return this\n }\n}\n"]}
1
+ {"version":3,"file":"recordUpdateResult.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordUpdateResult.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAA;AAG7D,MAAM,OAAO,kBAAkB;IAY7B,YAAY,MAMX;;QACC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAA;QAC3B,IAAI,CAAC,KAAK,SAAG,MAAM,CAAC,KAAK,mCAAI,EAAE,CAAA;QAC/B,IAAI,CAAC,YAAY,SAAG,MAAM,CAAC,YAAY,mCAAI,EAAE,CAAA;QAC7C,IAAI,CAAC,eAAe,SAAG,MAAM,CAAC,eAAe,mCAAI,IAAI,GAAG,EAAU,CAAA;QAClE,IAAI,CAAC,yBAAyB,GAAG,IAAI,GAAG,EAAU,CAAA;QAClD,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IACrC,CAAC;IAED,aAAa,CAAC,IAAY;QACxB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACzB,CAAC;IAED,OAAO,CAAC,IAAqB,EAAE,OAAkC;QAC/D,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,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cesContent":["import { ArenaRecordNode, ArenaRecordNodesMap } from '../../node'\nimport { ArenaValidation } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { addNode, addNodes } from '../_records/recordUpdater'\nimport { ArenaRecordUpdateOptions } from '../records'\n\nexport class RecordUpdateResult {\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n nodesDeleted: ArenaRecordNodesMap\n clearedDefUuids: Set<string>\n /**\n * Uuids of the nodes (ancestor entities) updated only in their date modified (because a descendant has been modified):\n * to be persisted, but not to be validated again.\n */\n dateModifiedOnlyNodeUuids: Set<string>\n validation?: ArenaValidation\n\n constructor(params: {\n record: ArenaRecord\n nodes?: ArenaRecordNodesMap\n nodesDeleted?: ArenaRecordNodesMap\n clearedDefUuids?: Set<string>\n validation?: ArenaValidation\n }) {\n this.record = params.record\n this.nodes = params.nodes ?? {}\n this.nodesDeleted = params.nodesDeleted ?? {}\n this.clearedDefUuids = params.clearedDefUuids ?? new Set<string>()\n this.dateModifiedOnlyNodeUuids = new Set<string>()\n this.validation = params.validation\n }\n\n getNodeByUuid(uuid: string) {\n return this.nodes[uuid]\n }\n\n addNode(node: ArenaRecordNode, options?: ArenaRecordUpdateOptions) {\n this.nodes[node.uuid] = node\n this.record = addNode(node, options)(this.record)\n }\n\n addNodes(nodes: ArenaRecordNodesMap, options?: ArenaRecordUpdateOptions) {\n Object.assign(this.nodes, nodes)\n this.record = addNodes(nodes, options)(this.record)\n }\n\n addClearedDefUuid(nodeDefUuid: string) {\n this.clearedDefUuids.add(nodeDefUuid)\n }\n\n /**\n * Merges this record update result with the specified one.\n * The record of this record update result will be the one of the specified record update result\n * and the nodes of the specified one will be added to the nodes of this one.\n *\n * @param {!RecordUpdateResult} recordUpdateResult - The record update result to merge with.\n * @returns {RecordUpdateResult} - The updated object.\n */\n merge(recordUpdateResult: RecordUpdateResult): this {\n this.record = recordUpdateResult.record\n Object.assign(this.nodes, recordUpdateResult.nodes)\n Object.assign(this.nodesDeleted, recordUpdateResult.nodesDeleted)\n for (const nodeDefUuid of recordUpdateResult.clearedDefUuids) {\n this.addClearedDefUuid(nodeDefUuid)\n }\n for (const nodeUuid of Object.keys(recordUpdateResult.nodes)) {\n // node updated in the merged result: not only in its date modified anymore\n if (!recordUpdateResult.dateModifiedOnlyNodeUuids.has(nodeUuid)) {\n this.dateModifiedOnlyNodeUuids.delete(nodeUuid)\n }\n }\n for (const nodeUuid of recordUpdateResult.dateModifiedOnlyNodeUuids) {\n this.dateModifiedOnlyNodeUuids.add(nodeUuid)\n }\n return this\n }\n}\n"]}