@openforis/arena-core 2.16.13 → 2.16.14

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.
@@ -11,15 +11,14 @@ import { Nodes } from '../../node';
11
11
  import { NodeDefs } from '../../nodeDef';
12
12
  import { Surveys } from '../../survey';
13
13
  import { SurveyDependencyType } from '../../survey/survey';
14
- import { RecordExpressionEvaluator } from '../recordExpressionEvaluator';
15
14
  import { Records } from '../records';
15
+ import { calculateBooleanValueNext } from './recordNodeDependentsBooleanUpdater';
16
16
  import { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater';
17
17
  import { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater';
18
18
  import { addNodeAndDescendants } from './recordNodesCreator';
19
19
  import { removeNodes } from './recordNodesDeleter';
20
20
  import { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons';
21
21
  import { RecordUpdateResult } from './recordUpdateResult';
22
- const expressionEvaluator = new RecordExpressionEvaluator();
23
22
  const extractNodePointersToUpdate = (params) => {
24
23
  const { survey, record, node } = params;
25
24
  const nodePointersToUpdate = getDependentNodePointersByType({
@@ -32,28 +31,7 @@ const extractNodePointersToUpdate = (params) => {
32
31
  });
33
32
  return nodePointersToUpdate;
34
33
  };
35
- const calculateApplicableNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, }) {
36
- const { nodeDef: nodeDefNodePointer } = nodePointer;
37
- const { uuid: nodeDefUuid } = nodeDefNodePointer;
38
- const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid);
39
- const expressionsToEvaluate = NodeDefs.getApplicable(nodeDefNodePointer);
40
- if (expressionsToEvaluate.length === 0) {
41
- if (applicablePrev) {
42
- // skip nodes that were already applicable and have no applicable expression, as they will remain applicable
43
- return undefined;
44
- }
45
- else {
46
- // used during survey publishing: node def could have had applicable expression(s) that were removed,
47
- // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions
48
- return true;
49
- }
50
- }
51
- else {
52
- // 3. evaluate applicable expression
53
- const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
54
- return (exprEval === null || exprEval === void 0 ? void 0 : exprEval.value) || false;
55
- }
56
- });
34
+ const calculateApplicableNext = (params) => calculateBooleanValueNext(Object.assign(Object.assign({}, params), { getExpressions: (nodePointer) => NodeDefs.getApplicable(nodePointer.nodeDef), getValuePrev: Nodes.isChildApplicable }));
57
35
  const updateDescendantsApplicability = ({ updateResult, nodeCtxChild, applicable, params, recordUpdateOptions, }) => {
58
36
  const { survey, sideEffect = false, clearNonApplicableValues = false } = params;
59
37
  // only values entered by the user are reported as cleared (they need a confirmation)
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAgC,KAAK,EAAE,MAAM,YAAY,CAAA;AAChE,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAU,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,OAAO,EAAuB,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAA;AAClG,OAAO,EAAE,4BAA4B,EAAE,MAAM,+CAA+C,CAAA;AAC5F,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAA;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,OAAO,EAAE,k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M,CAAC,MAAM,iCAAiC,GAAG,CAC/C,MAAwC,EACX,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAE3D,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,MAAM,mBAAmB,GAAwB,EAAE,UAAU,EAAE,CAAA;IAE/D,2BAA2B;IAC3B,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAElF,6CAA6C;IAC7C,4EAA4E;IAC5E,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,MAAM,8BAA8B,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAA,CAAC,UAAU;IAC7G,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = NodeDefs.getApplicable(nodeDefNodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (applicablePrev) {\n // skip nodes that were already applicable and have no applicable expression, as they will remain applicable\n return undefined\n } else {\n // used during survey publishing: node def could have had applicable expression(s) that were removed,\n // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions\n return true\n }\n } else {\n // 3. evaluate applicable expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n }\n}\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAgC,KAAK,EAAE,MAAM,YAAY,CAAA;AAChE,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAU,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAElE,OAAO,EAAE,OAAO,EAAuB,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AAChF,OAAO,EAAE,gCAAgC,EAAE,MAAM,iDAAiD,CAAA;AAClG,OAAO,EAAE,4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,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAA,CAAC,UAAU;IAC7G,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { calculateBooleanValueNext } from './recordNodeDependentsBooleanUpdater'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = (params: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> =>\n calculateBooleanValueNext({\n ...params,\n getExpressions: (nodePointer) => NodeDefs.getApplicable(nodePointer.nodeDef),\n getValuePrev: Nodes.isChildApplicable,\n })\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
@@ -11,15 +11,18 @@ import { RecordExpressionEvaluator } from '../recordExpressionEvaluator';
11
11
  import { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons';
12
12
  import { RecordUpdateResult } from './recordUpdateResult';
13
13
  const expressionEvaluator = new RecordExpressionEvaluator();
14
- const calculateBooleanValueNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev, }) {
14
+ export const calculateBooleanValueNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev, }) {
15
15
  const { nodeDef: nodeDefNodePointer } = nodePointer;
16
16
  const { uuid: nodeDefUuid } = nodeDefNodePointer;
17
17
  const valuePrev = getValuePrev(nodeCtx, nodeDefUuid);
18
18
  const expressionsToEvaluate = getExpressions(nodePointer);
19
19
  if (expressionsToEvaluate.length === 0) {
20
20
  if (valuePrev) {
21
+ // skip nodes already having the value true and no expressions, as they will keep it
21
22
  return undefined;
22
23
  }
24
+ // used during survey publishing: node def could have had expression(s) that were removed,
25
+ // and the value could have been false, but now it should be true, as there are no more expressions
23
26
  return true;
24
27
  }
25
28
  const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAgB3D,MAAM,yBAAyB,GAAG,KAcD,EAAE,4CAdM,EACvC,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,cAAc,EACd,YAAY,GAQb;IACC,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,WAAW,CAAA;IACnD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,kBAAkB,CAAA;IAEhD,MAAM,SAAS,GAAG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,GAAG,kBAAkB,CAAC,IAAI,CAAA;QAE3C,MAAM,OAAO,SAAG,YAAY,CAAC,aAAa,CAAC,WAAW,CAAC,mCAAI,kBAAkB,CAAA;QAE7E,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QACpD,MAAM,eAAe,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,CAAA;QACpG,MAAM,KAAK,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAAC,CAAA,CAAC,UAAU;QAEzE,IAAI,KAAK,KAAK,SAAS,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YAC/C,SAAQ;QACV,CAAC;QAED,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QAC9E,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IACtD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDefExpression } from '../../nodeDef'\nimport { MutationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nconst calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n return undefined\n }\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): 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,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAIA,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,8BAA8B,EAAE,MAAM,uCAAuC,CAAA;AAEtF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAgB3D,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAcR,EAAE,4CAda,EAC9C,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,cAAc,EACd,YAAY,GAQb;IACC,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,WAAW,CAAA;IACnD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,kBAAkB,CAAA;IAEhD,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;IACpD,MAAM,qBAAqB,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;IACzD,IAAI,qBAAqB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvC,IAAI,SAAS,EAAE,CAAC;YACd,oFAAoF;YACpF,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,0FAA0F;QAC1F,mGAAmG;QACnG,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,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AAM,KAAK,GAAG,MAAM,yBAAyB,CAAC,eAAe,CAAC,CAAA,CAAC,UAAU;QAEzE,IAAI,KAAK,KAAK,SAAS,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YAC/C,SAAQ;QACV,CAAC;QAED,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QAC9E,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IACtD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDefExpression } from '../../nodeDef'\nimport { MutationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nexport const calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n // skip nodes already having the value true and no expressions, as they will keep it\n return undefined\n }\n // used during survey publishing: node def could have had expression(s) that were removed,\n // and the value could have been false, but now it should be true, as there are no more expressions\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): 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,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\n}\n"]}
@@ -14,15 +14,14 @@ const node_1 = require("../../node");
14
14
  const nodeDef_1 = require("../../nodeDef");
15
15
  const survey_1 = require("../../survey");
16
16
  const survey_2 = require("../../survey/survey");
17
- const recordExpressionEvaluator_1 = require("../recordExpressionEvaluator");
18
17
  const records_1 = require("../records");
18
+ const recordNodeDependentsBooleanUpdater_1 = require("./recordNodeDependentsBooleanUpdater");
19
19
  const recordNodeDependentsEnumeratedEntitiesUpdater_1 = require("./recordNodeDependentsEnumeratedEntitiesUpdater");
20
20
  const recordNodeDependentsEnumeratingItemsUpdater_1 = require("./recordNodeDependentsEnumeratingItemsUpdater");
21
21
  const recordNodesCreator_1 = require("./recordNodesCreator");
22
22
  const recordNodesDeleter_1 = require("./recordNodesDeleter");
23
23
  const recordNodesDependentsUpdaterCommons_1 = require("./recordNodesDependentsUpdaterCommons");
24
24
  const recordUpdateResult_1 = require("./recordUpdateResult");
25
- const expressionEvaluator = new recordExpressionEvaluator_1.RecordExpressionEvaluator();
26
25
  const extractNodePointersToUpdate = (params) => {
27
26
  const { survey, record, node } = params;
28
27
  const nodePointersToUpdate = (0, recordNodesDependentsUpdaterCommons_1.getDependentNodePointersByType)({
@@ -35,28 +34,7 @@ const extractNodePointersToUpdate = (params) => {
35
34
  });
36
35
  return nodePointersToUpdate;
37
36
  };
38
- const calculateApplicableNext = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, updateResult, nodePointer, nodeCtx, }) {
39
- const { nodeDef: nodeDefNodePointer } = nodePointer;
40
- const { uuid: nodeDefUuid } = nodeDefNodePointer;
41
- const applicablePrev = node_1.Nodes.isChildApplicable(nodeCtx, nodeDefUuid);
42
- const expressionsToEvaluate = nodeDef_1.NodeDefs.getApplicable(nodeDefNodePointer);
43
- if (expressionsToEvaluate.length === 0) {
44
- if (applicablePrev) {
45
- // skip nodes that were already applicable and have no applicable expression, as they will remain applicable
46
- return undefined;
47
- }
48
- else {
49
- // used during survey publishing: node def could have had applicable expression(s) that were removed,
50
- // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions
51
- return true;
52
- }
53
- }
54
- else {
55
- // 3. evaluate applicable expression
56
- const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
57
- return (exprEval === null || exprEval === void 0 ? void 0 : exprEval.value) || false;
58
- }
59
- });
37
+ const calculateApplicableNext = (params) => (0, recordNodeDependentsBooleanUpdater_1.calculateBooleanValueNext)(Object.assign(Object.assign({}, params), { getExpressions: (nodePointer) => nodeDef_1.NodeDefs.getApplicable(nodePointer.nodeDef), getValuePrev: node_1.Nodes.isChildApplicable }));
60
38
  const updateDescendantsApplicability = ({ updateResult, nodeCtxChild, applicable, params, recordUpdateOptions, }) => {
61
39
  const { survey, sideEffect = false, clearNonApplicableValues = false } = params;
62
40
  // only values entered by the user are reported as cleared (they need a confirmation)
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAgE;AAChE,2CAAuD;AACvD,yCAAsC;AACtC,gDAAkE;AAElE,4EAAwE;AACxE,wCAAyD;AACzD,mHAAkG;AAClG,+GAA4F;AAC5F,6DAA4D;AAC5D,6DAAkD;AAClD,+FAAsF;AAEtF,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAE3D,MAAM,2BAA2B,GAAG,CAAC,MAAsE,EAAE,EAAE;IAC7G,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAEvC,MAAM,oBAAoB,GAAG,IAAA,oEAA8B,EAAC;QAC1D,MAAM;QACN,MAAM;QACN,IAAI;QACJ,cAAc,EAAE,6BAAoB,CAAC,UAAU;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AC3B,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAElF,6CAA6C;IAC7C,4EAA4E;IAC5E,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,MAAM,8BAA8B,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAA,CAAC,UAAU;IAC7G,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAlBY,QAAA,iCAAiC,GAAjC,iCAAiC,CAkB7C","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = NodeDefs.getApplicable(nodeDefNodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (applicablePrev) {\n // skip nodes that were already applicable and have no applicable expression, as they will remain applicable\n return undefined\n } else {\n // used during survey publishing: node def could have had applicable expression(s) that were removed,\n // and node could have been not applicable, but now it should be applicable, as there are no more applicable expressions\n return true\n }\n } else {\n // 3. evaluate applicable expression\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n }\n}\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsApplicableUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAgE;AAChE,2CAAuD;AACvD,yCAAsC;AACtC,gDAAkE;AAElE,wCAAyD;AACzD,6FAAgF;AAChF,mHAAkG;AAClG,+GAA4F;AAC5F,6DAA4D;AAC5D,6DAAkD;AAClD,+FAAsF;AAEtF,6DAAyD;AAEzD,MAAM,2BAA2B,GAAG,CAAC,MAAsE,EAAE,EAAE;IAC7G,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAEvC,MAAM,oBAAoB,GAAG,IAAA,oEAA8B,EAAC;QAC1D,MAAM;QACN,MAAM;QACN,IAAI;QACJ,cAAc,EAAE,6BAAoB,CAAC,UAAU;QAC/C,gCAAgC,EAAE,IAAI;QACtC,6BAA6B,EAAE,IAAI;KACpC,CAAC,CAAA;IACF,OAAO,oBAAoB,CAAA;AAC7B,CAAC,CAAA;AAED,MAAM,uBAAuB,GAAG,CAAC,MAKhC,EAAgC,EAAE,CACjC,IAAA,8DAAyB,kCACpB,MAA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;YACV,MAAM;YACN,mBAAmB;SACpB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA;AAEM,MAAM,iCAAiC,GAAG,CAC/C,MAAwC,EACX,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAE3D,MAAM,YAAY,GAAG,IAAI,uCAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,MAAM,mBAAmB,GAAwB,EAAE,UAAU,EAAE,CAAA;IAE/D,2BAA2B;IAC3B,MAAM,oBAAoB,GAAG,2BAA2B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;IAElF,6CAA6C;IAC7C,4EAA4E;IAC5E,KAAK,MAAM,WAAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,MAAM,8BAA8B,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,mBAAmB,EAAE,CAAC,CAAA,CAAC,UAAU;IAC7G,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAlBY,QAAA,iCAAiC,GAAjC,iCAAiC,CAkB7C","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { ArenaRecord } from '../record'\nimport { Records, RecordUpdateOptions } from '../records'\nimport { calculateBooleanValueNext } from './recordNodeDependentsBooleanUpdater'\nimport { createOrDeleteEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { syncEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { addNodeAndDescendants } from './recordNodesCreator'\nimport { removeNodes } from './recordNodesDeleter'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst extractNodePointersToUpdate = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }) => {\n const { survey, record, node } = params\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.applicable,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntityChildPointers: true,\n })\n return nodePointersToUpdate\n}\n\nconst calculateApplicableNext = (params: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n}): Promise<boolean | undefined> =>\n calculateBooleanValueNext({\n ...params,\n getExpressions: (nodePointer) => NodeDefs.getApplicable(nodePointer.nodeDef),\n getValuePrev: Nodes.isChildApplicable,\n })\n\nconst updateDescendantsApplicability = ({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n}: {\n updateResult: RecordUpdateResult\n nodeCtxChild: ArenaRecordNode\n applicable: boolean\n params: RecordNodeDependentsUpdateParams\n recordUpdateOptions: RecordUpdateOptions\n}): void => {\n const { survey, sideEffect = false, clearNonApplicableValues = false } = params\n\n // only values entered by the user are reported as cleared (they need a confirmation)\n let userValuesCleared = false\n\n Records.visitDescendantsAndSelf(nodeCtxChild, (nodeDescendant): boolean => {\n const nodeDescendantCleared = clearNonApplicableValues && !applicable && Nodes.isValueNotBlank(nodeDescendant)\n // values set by expressions (default values, read only attributes) are applied again when applicable: not reported\n // (evaluated before clearing the value: with sideEffect the node is modified in place)\n const nodeDescendantDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDescendant.nodeDefUuid })\n const userValueCleared =\n nodeDescendantCleared && !NodeDefs.isReadOnly(nodeDescendantDef) && Nodes.hasUserInputValue(nodeDescendant)\n // Clear value if becoming non-applicable and parameter is enabled\n const nodeDescendantUpdated = nodeDescendantCleared\n ? Nodes.assocValue(nodeDescendant, null, { sideEffect })\n : nodeDescendant\n updateResult.addNode(nodeDescendantUpdated, recordUpdateOptions)\n if (userValueCleared) {\n updateResult.addClearedDefUuid(nodeDescendant.nodeDefUuid)\n userValuesCleared = true\n }\n return false\n })(updateResult.record)\n\n // if a multiple entity became not applicable and it's empty, delete it instead of just marking descendants as not applicable\n if (!applicable && clearNonApplicableValues) {\n const { uuid: nodeCtxChildUuid, nodeDefUuid: nodeCtxChildDefUuid } = nodeCtxChild\n const nodeCtxChildDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeCtxChildDefUuid })\n if (NodeDefs.isMultipleEntity(nodeCtxChildDef) && Records.isNodeEmpty(nodeCtxChild)(updateResult.record)) {\n const deleteResult = removeNodes([nodeCtxChildUuid], recordUpdateOptions)(updateResult.record)\n updateResult.merge(deleteResult)\n if (userValuesCleared) {\n updateResult.addClearedDefUuid(nodeCtxChildDefUuid)\n }\n }\n }\n}\n\nconst createMissingApplicableMultipleEntities = async ({\n params,\n updateResult,\n parentNode,\n nodeDef,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n parentNode: ArenaRecordNode\n nodeDef: NodeDefEntity\n}): Promise<void> => {\n if (!NodeDefs.isAutoCreateMinCountItems(nodeDef)) return\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef })\n if (Number.isNaN(minCount) || minCount <= 0) return\n\n const existingChildren = Records.getChildren(parentNode, nodeDef.uuid)(updateResult.record)\n const missingCount = Math.max(0, minCount - existingChildren.length)\n\n for (let index = 0; index < missingCount; index++) {\n const createParams = { ...params, record: updateResult.record, parentNode, nodeDef }\n // create nodes sequentially: every iteration works on the record updated by the previous one\n const childUpdateResult = await addNodeAndDescendants(createParams) // NOSONAR\n updateResult.merge(childUpdateResult)\n }\n}\n\nconst updateNodePointerApplicability = async ({\n params,\n updateResult,\n nodePointer,\n recordUpdateOptions,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n recordUpdateOptions: RecordUpdateOptions\n}): Promise<void> => {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const applicablePrev = Nodes.isChildApplicable(nodeCtx, nodeDefUuid)\n const applicable = await calculateApplicableNext({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n })\n if (applicable === undefined) {\n return\n }\n\n if (applicable && NodeDefs.isMultipleEntity(nodeDefNodePointer)) {\n await createMissingApplicableMultipleEntities({\n params,\n updateResult,\n parentNode: nodeCtx,\n nodeDef: nodeDefNodePointer as NodeDefEntity,\n })\n }\n\n // 4. persist updated applicability if changed, and return updated nodes\n if (applicablePrev === applicable) {\n return\n }\n // Applicability changed\n\n // update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildApplicability(nodeCtx, nodeDefUuid, applicable)\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n\n let nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n\n if (NodeDefs.isMultipleEntity(nodeDefNodePointer) && NodeDefs.isEnumerate(nodeDefNodePointer as NodeDefEntity)) {\n const entityDef = nodeDefNodePointer as NodeDefEntity\n if (NodeDefs.getEnumeratingItemsExpression(entityDef)) {\n await syncEnumeratingItemsEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n } else {\n await createOrDeleteEnumeratedEntities({\n ...params,\n parentNode: nodeCtxUpdated,\n entityDef,\n updateResult,\n })\n }\n nodeCtxChildren = Records.getChildren(nodeCtx, nodeDefUuid)(updateResult.record)\n }\n for (const nodeCtxChild of nodeCtxChildren) {\n // add nodeCtxChild and its descendants to nodesUpdated\n updateDescendantsApplicability({\n updateResult,\n nodeCtxChild,\n applicable,\n params,\n recordUpdateOptions,\n })\n }\n}\n\nexport const updateSelfAndDependentsApplicable = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions: RecordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const nodePointersToUpdate = extractNodePointersToUpdate({ survey, record, node })\n\n // 2. update expr to node and dependent nodes\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n await updateNodePointerApplicability({ params, updateResult, nodePointer, recordUpdateOptions }) // NOSONAR\n }\n return updateResult\n}\n"]}
@@ -12,5 +12,13 @@ type UpdateSelfAndDependentsBooleanParams = {
12
12
  assocValue: (nodeCtx: ArenaRecordNode, nodeDefUuid: string, value: boolean, options: MutationOptions) => ArenaRecordNode;
13
13
  includeNewEntitySelf?: boolean;
14
14
  };
15
+ export declare const calculateBooleanValueNext: ({ params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev, }: {
16
+ params: RecordNodeDependentsUpdateParams;
17
+ updateResult: RecordUpdateResult;
18
+ nodePointer: NodePointer;
19
+ nodeCtx: ArenaRecordNode;
20
+ getExpressions: (nodePointer: NodePointer) => NodeDefExpression[];
21
+ getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean;
22
+ }) => Promise<boolean | undefined>;
15
23
  export declare const updateSelfAndDependentsBoolean: ({ params, dependencyType, getExpressions, getValuePrev, assocValue, includeNewEntitySelf, }: UpdateSelfAndDependentsBooleanParams) => Promise<RecordUpdateResult>;
16
24
  export {};
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.updateSelfAndDependentsBoolean = void 0;
12
+ exports.updateSelfAndDependentsBoolean = exports.calculateBooleanValueNext = void 0;
13
13
  const recordExpressionEvaluator_1 = require("../recordExpressionEvaluator");
14
14
  const recordNodesDependentsUpdaterCommons_1 = require("./recordNodesDependentsUpdaterCommons");
15
15
  const recordUpdateResult_1 = require("./recordUpdateResult");
@@ -21,13 +21,17 @@ const calculateBooleanValueNext = (_a) => __awaiter(void 0, [_a], void 0, functi
21
21
  const expressionsToEvaluate = getExpressions(nodePointer);
22
22
  if (expressionsToEvaluate.length === 0) {
23
23
  if (valuePrev) {
24
+ // skip nodes already having the value true and no expressions, as they will keep it
24
25
  return undefined;
25
26
  }
27
+ // used during survey publishing: node def could have had expression(s) that were removed,
28
+ // and the value could have been false, but now it should be true, as there are no more expressions
26
29
  return true;
27
30
  }
28
31
  const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }));
29
32
  return (exprEval === null || exprEval === void 0 ? void 0 : exprEval.value) || false;
30
33
  });
34
+ exports.calculateBooleanValueNext = calculateBooleanValueNext;
31
35
  const updateSelfAndDependentsBoolean = (_a) => __awaiter(void 0, [_a], void 0, function* ({ params, dependencyType, getExpressions, getValuePrev, assocValue, includeNewEntitySelf = true, }) {
32
36
  var _b;
33
37
  const { survey, record, node, sideEffect = false } = params;
@@ -49,7 +53,7 @@ const updateSelfAndDependentsBoolean = (_a) => __awaiter(void 0, [_a], void 0, f
49
53
  const nodeCtx = (_b = updateResult.getNodeByUuid(nodeCtxUuid)) !== null && _b !== void 0 ? _b : nodeCtxNodePointer;
50
54
  const valuePrev = getValuePrev(nodeCtx, nodeDefUuid);
51
55
  const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev };
52
- const value = yield calculateBooleanValueNext(calculateParams); // NOSONAR
56
+ const value = yield (0, exports.calculateBooleanValueNext)(calculateParams); // NOSONAR
53
57
  if (value === undefined || valuePrev === value) {
54
58
  continue;
55
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":"","sources":["../../../src/record/rec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'\nimport { MutationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nconst calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n return undefined\n }\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): 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,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodeDependentsBooleanUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,4EAAwE;AACxE,+FAAsF;AAEtF,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAgBpD,MAAM,yBAAyB,GAAG,KAcR,EAAE,4CAda,EAC9C,MAAM,EACN,YAAY,EACZ,WAAW,EACX,OAAO,EACP,cAAc,EACd,YAAY,GAQb;IACC,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,WAAW,CAAA;IACnD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,kBAAkB,CAAA;IAEhD,MAAM,SAAS,G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GAAG,WAAW,CAAA;QAEhF,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAA;QAC3C,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAA;QAE3C,MAAM,OAAO,SAAG,YAAY,CAAC,aAAa,CAAC,WAAW,CAAC,mCAAI,kBAAkB,CAAA;QAE7E,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,EAAE,WAAW,CAAC,CAAA;QACpD,MAAM,eAAe,GAAG,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,CAAA;QACpG,MAAM,KAAK,GAAG,MAAM,IAAA,QAAA,yBAAyB,EAAC,eAAe,CAAC,CAAA,CAAC,UAAU;QAEzE,IAAI,KAAK,KAAK,SAAS,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YAC/C,SAAQ;QACV,CAAC;QAED,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;QAC9E,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;IACtD,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AA3CY,QAAA,8BAA8B,GAA9B,8BAA8B,CA2C1C","sourcesContent":["import { ArenaRecordNode, NodePointer } from '../../node'\nimport { NodeDefExpression } from '../../nodeDef'\nimport { MutationOptions } from '../../utils/mutationOptions'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\ntype UpdateSelfAndDependentsBooleanParams = {\n params: RecordNodeDependentsUpdateParams\n dependencyType: SurveyDependencyType\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n assocValue: (\n nodeCtx: ArenaRecordNode,\n nodeDefUuid: string,\n value: boolean,\n options: MutationOptions\n ) => ArenaRecordNode\n includeNewEntitySelf?: boolean\n}\n\nexport const calculateBooleanValueNext = async ({\n params,\n updateResult,\n nodePointer,\n nodeCtx,\n getExpressions,\n getValuePrev,\n}: {\n params: RecordNodeDependentsUpdateParams\n updateResult: RecordUpdateResult\n nodePointer: NodePointer\n nodeCtx: ArenaRecordNode\n getExpressions: (nodePointer: NodePointer) => NodeDefExpression[]\n getValuePrev: (nodeCtx: ArenaRecordNode, nodeDefUuid: string) => boolean\n}): Promise<boolean | undefined> => {\n const { nodeDef: nodeDefNodePointer } = nodePointer\n const { uuid: nodeDefUuid } = nodeDefNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const expressionsToEvaluate = getExpressions(nodePointer)\n if (expressionsToEvaluate.length === 0) {\n if (valuePrev) {\n // skip nodes already having the value true and no expressions, as they will keep it\n return undefined\n }\n // used during survey publishing: node def could have had expression(s) that were removed,\n // and the value could have been false, but now it should be true, as there are no more expressions\n return true\n }\n\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n record: updateResult.record,\n nodeCtx,\n expressions: expressionsToEvaluate,\n })\n return exprEval?.value || false\n}\n\nexport const updateSelfAndDependentsBoolean = async ({\n params,\n dependencyType,\n getExpressions,\n getValuePrev,\n assocValue,\n includeNewEntitySelf = true,\n}: UpdateSelfAndDependentsBooleanParams): 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,\n includeSelfWhenSourceIsAttribute: true,\n includeNewEntitySelf,\n includeNewEntityChildPointers: true,\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const nodePointer of nodePointersToUpdate) {\n const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const valuePrev = getValuePrev(nodeCtx, nodeDefUuid)\n const calculateParams = { params, updateResult, nodePointer, nodeCtx, getExpressions, getValuePrev }\n const value = await calculateBooleanValueNext(calculateParams) // NOSONAR\n\n if (value === undefined || valuePrev === value) {\n continue\n }\n\n const nodeCtxUpdated = assocValue(nodeCtx, nodeDefUuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n\n return updateResult\n}\n"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "OpenForis",
5
5
  "email": "openforis.arena@gmail.com"
6
6
  },
7
- "version": "2.16.13",
7
+ "version": "2.16.14",
8
8
  "description": "Arena core module",
9
9
  "repository": {
10
10
  "type": "git",