@openforis/arena-core 2.16.12 → 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.
- package/dist/esm/record/_records/recordGetters.js +2 -1
- package/dist/esm/record/_records/recordGetters.js.map +1 -1
- package/dist/esm/record/recordExpressionEvaluator/functions.js +1 -0
- package/dist/esm/record/recordExpressionEvaluator/functions.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +2 -24
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +4 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +3 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
- package/dist/esm/utils/numbers.js +2 -2
- package/dist/esm/utils/numbers.js.map +1 -1
- package/dist/record/_records/recordGetters.js +2 -1
- package/dist/record/_records/recordGetters.js.map +1 -1
- package/dist/record/recordExpressionEvaluator/functions.js +1 -0
- package/dist/record/recordExpressionEvaluator/functions.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +2 -24
- package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.d.ts +8 -0
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +6 -2
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +3 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
- package/dist/utils/numbers.js +2 -2
- package/dist/utils/numbers.js.map +1 -1
- package/package.json +1 -1
|
@@ -285,7 +285,8 @@ export const getNodeIndex = (node) => (record) => {
|
|
|
285
285
|
if (!parentEntity)
|
|
286
286
|
return 0; // root entity
|
|
287
287
|
const siblings = getChildren(parentEntity, node.nodeDefUuid)(record);
|
|
288
|
-
|
|
288
|
+
// compared by uuid: the specified node can be a copy of the one in the record (e.g. an updated version of it)
|
|
289
|
+
return siblings.findIndex((sibling) => sibling.uuid === node.uuid);
|
|
289
290
|
};
|
|
290
291
|
export const findEntityByKeyValues = (survey, cycle, parentEntity, entityDefUuid, keyValuesByDefUuid) => (record) => {
|
|
291
292
|
const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAgC,KAAK,EAAY,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAwD,QAAQ,EAAe,MAAM,eAAe,CAAA;AAC3G,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,KAAK,mCAAI,YAAY,GAAA,CAAA;AAErF,MAAM,CAA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AAM,CAAC,EAAE,IAAI,CAAC,CAAA;IAErF,MAAM,IAAI,GAAG,OAAO,CAAC,0BAA0B,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,CAAA;IAEpF,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAA;AACnB,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/F,MAAM,CAAC,MAAM,WAAW,GACtB,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAW,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,IAAI,mCAAI,mBAAmB,GAAA,CAAA;AAE1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../../common'\nimport { SystemError, SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { ArenaRecord, RECORD_STEP_DEFAULT } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: ArenaRecord): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: ArenaRecord): Dictionary<ArenaRecordNode> => record.nodes ?? {}\n\nexport const getNodesArray = (record: ArenaRecord): ArenaRecordNode[] => Object.values(getNodes(record))\n\n/**\n * Returns the node with the specified uuid, or undefined if not found.\n * Like the other node getters, it does not throw an error when the node is not found.\n */\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n uuids.map((uuid: string) => record.nodes?.[uuid]) as ArenaRecordNode[]\n\n/**\n * Returns the root node, or undefined if the record has no nodes.\n */\nexport const getRoot = (record: ArenaRecord): ArenaRecordNode | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: ArenaRecordNode, childDefUuid?: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\n/**\n * Returns the only child of the parent node with the specified node def, or undefined if not found.\n * Throws an error if more than one child is found.\n */\nexport const getChild =\n (parentNode: ArenaRecordNode, childDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const children = getChildren(parentNode, childDefUuid)(record)\n if (children.length > 1) {\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n throw new SystemError(SystemErrorKeys.record.multipleNodesFound, errorParams)\n }\n return children[0]\n }\n\n// called for every ancestor in the record update loops: keep it a plain lookup\nconst getParentNode = (record: ArenaRecord, node: ArenaRecordNode): ArenaRecordNode | undefined =>\n node.parentUuid ? record.nodes?.[node.parentUuid] : undefined\n\nexport const getParent =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getParentNode(record, node)\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: ArenaRecordNode, nodeDefUuid: string) => boolean) =>\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n let child = node\n let parent = getParentNode(record, child)\n while (parent) {\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n child = parent\n parent = getParentNode(record, child)\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\n/**\n * Whether a value is required for the node: key or always required attribute, or attribute with a \"required if\"\n * condition met in its parent entity (evaluated condition stored in the parent node meta).\n */\nexport const isNodeRequired =\n (nodeDef: NodeDef<NodeDefType>, node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parent = getParentNode(record, node)\n return !!parent && Nodes.isChildRequired(parent, nodeDef.uuid)\n }\n\nexport const getDependentCodeAttributes =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError(SystemErrorKeys.record.nodesIndexNotInitialized)\n }\n\nexport const getParentCodeAttribute =\n (parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf(parentNode)(record)\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\n\n/**\n * Visits the specified node and its ancestors, from the node up to the root: the visit stops when the visitor returns true.\n */\nexport const visitAncestorsAndSelf =\n (node: ArenaRecordNode, visitor: (node: ArenaRecordNode) => boolean | void) =>\n (record: ArenaRecord): void => {\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n if (visitor(currentNode)) return\n currentNode = getParentNode(record, currentNode)\n }\n }\n\n/**\n * Returns the first node satisfying the predicate among the specified node and its ancestors (from the node up to the root).\n */\nexport const findAncestor =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let result: ArenaRecordNode | undefined = undefined\n visitAncestorsAndSelf(node, (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n return true\n }\n return false\n })(record)\n return result\n }\n\n/**\n * Returns the specified node, if it has the specified node def, or its ancestor with that node def; undefined if not found.\n */\nexport const getAncestor =\n (node: ArenaRecordNode, ancestorDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let ancestor: ArenaRecordNode | undefined = node\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParentNode(record, ancestor)\n }\n return ancestor\n }\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): Array<ArenaRecordNode> => {\n const ancestors: Array<ArenaRecordNode> = []\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n ancestors.push(currentNode)\n currentNode = getParentNode(record, currentNode)\n }\n return ancestors\n }\n\n// descendants\n\nexport const getDescendantsOrSelf =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: ArenaRecordNode[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n }\n\n/**\n * Returns the first descendant (or the node itself) with the specified node def, or undefined if not found.\n */\nexport const getDescendant =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getDescendantsOrSelf(node, nodeDefDescendant)(record)[0]\n\nexport const isDescendantOf = (node: ArenaRecordNode, ancestor: ArenaRecordNode): boolean =>\n Nodes.getHierarchy(node).includes(ancestor.uuid)\n\nexport const visitDescendantsAndSelf =\n (\n node: ArenaRecordNode,\n visitor: (node: ArenaRecordNode) => boolean | void,\n traverseMethod: TraverseMethod = TraverseMethod.bfs\n ) =>\n (record: ArenaRecord): void => {\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue<ArenaRecordNode>()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()!\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as ArenaRecordNode\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n }\n\nexport const findDescendantOrSelf =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf(node, (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n })(record)\n return found\n }\n\nconst getClosestAncestorNode =\n (\n node: ArenaRecordNode,\n nodeDef: NodeDef<NodeDefType, NodeDefProps>,\n dependentDef: NodeDef<NodeDefType, NodeDefProps>,\n dependencyType: SurveyDependencyType\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor(node, commonAncestorDefUuid)(record)\n }\n\ntype KeyDefs = NodeDef<NodeDefType, NodeDefProps>[]\n\n/**\n * Returns the key nodes of the entity, indexed by key def uuid; keyDefs, when specified, are used instead of the\n * entity def keys in the cycle.\n */\nexport const getEntityKeyNodesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): NodesMap => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant(entity, nodeDefKey)(record)\n // missing key nodes are kept as undefined entries\n acc[nodeDefKey.uuid] = nodeKey as ArenaRecordNode\n return acc\n }, {})\n }\n\nexport const getEntityKeyNodes =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n Object.values(getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntityKeyValuesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n }\n\nexport const getEntityKeyValues =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntitySiblings =\n (entity: ArenaRecordNode, includeSelf = false) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n }\n\nexport const getAttributeSiblings =\n (node: ArenaRecordNode, nodeDef: NodeDef<NodeDefType, NodeDefProps>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings(parentEntity)(record)\n return siblingParentEntities.reduce((siblingsAcc: ArenaRecordNode[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n }\n\nexport const getNodeIndex = (node: ArenaRecordNode) => (record: ArenaRecord) => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n return siblings.indexOf(node)\n}\n\nexport const findEntityByKeyValues =\n (\n survey: Survey,\n cycle: string,\n parentEntity: ArenaRecordNode,\n entityDefUuid: string,\n keyValuesByDefUuid: Dictionary<any>\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid(\n survey,\n siblingEntity,\n undefined,\n keyDefs\n )(record)\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n }\n\nexport const findEntityWithSameKeysInAnotherRecord =\n (survey: Survey, cycle: string, entityUuid: string, recordOther: ArenaRecord) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf(entity)(record)\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid(survey, ancestor)(record),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues(\n survey,\n cycle,\n otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid\n )(recordOther)\n }\n return otherRecordCurrentParentEntity\n }\n\nexport const getDependentNodePointers =\n (\n survey: Survey,\n node: ArenaRecordNode,\n dependencyType: SurveyDependencyType,\n includeSelf = false,\n filterFn: ((nodePointer: NodePointer) => boolean) | null = null\n ) =>\n (record: ArenaRecord): NodePointer[] => {\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode(node, nodeDef, dependentDef, dependencyType)(record)\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError(SystemErrorKeys.record.dependencyOnRootFound)\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf(commonAncestorNode, nodeDefDependentParent)(record)\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n }\n\n/**\n * Returns the code attributes the specified code attribute depends on, from the top level one to the parent one.\n */\nexport const getAncestorCodeAttributes =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const ancestorCodeAttributes = []\n let currentParentCodeAttribute = getParentCodeAttribute(parentNode, nodeDef)(record)\n while (currentParentCodeAttribute) {\n ancestorCodeAttributes.unshift(currentParentCodeAttribute)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute(parentNode, ancestorCodeDef)(record)\n }\n return ancestorCodeAttributes\n }\n\nexport const getAncestorCodePath =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>) =>\n (record: ArenaRecord): string[] =>\n getAncestorCodeAttributes(\n survey,\n parentNode,\n nodeDef\n )(record).map((codeAttribute) => {\n const codeItemUuid = NodeValues.getItemUuid(codeAttribute)\n if (!codeItemUuid) return ''\n // items of big categories are not in the survey ref data: they can be in the node ref data\n const item =\n codeAttribute.refData?.categoryItem ?? Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n })\n\nexport const getCategoryItemUuid =\n (survey: Survey, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>, parentNode: ArenaRecordNode, code: string) =>\n (record: ArenaRecord): string | undefined => {\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath(survey, parentNode, nodeDef)(record), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n }\n\nexport const isNodeFilledByUser =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: ArenaRecord): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: ArenaRecord): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: ArenaRecord): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
|
|
1
|
+
{"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,cAAc,CAAA;A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CAAC,MAAM,WAAW,GACtB,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAW,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,IAAI,mCAAI,mBAAmB,GAAA,CAAA;AAE1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../../common'\nimport { SystemError, SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { ArenaRecord, RECORD_STEP_DEFAULT } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: ArenaRecord): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: ArenaRecord): Dictionary<ArenaRecordNode> => record.nodes ?? {}\n\nexport const getNodesArray = (record: ArenaRecord): ArenaRecordNode[] => Object.values(getNodes(record))\n\n/**\n * Returns the node with the specified uuid, or undefined if not found.\n * Like the other node getters, it does not throw an error when the node is not found.\n */\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n uuids.map((uuid: string) => record.nodes?.[uuid]) as ArenaRecordNode[]\n\n/**\n * Returns the root node, or undefined if the record has no nodes.\n */\nexport const getRoot = (record: ArenaRecord): ArenaRecordNode | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: ArenaRecordNode, childDefUuid?: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\n/**\n * Returns the only child of the parent node with the specified node def, or undefined if not found.\n * Throws an error if more than one child is found.\n */\nexport const getChild =\n (parentNode: ArenaRecordNode, childDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const children = getChildren(parentNode, childDefUuid)(record)\n if (children.length > 1) {\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n throw new SystemError(SystemErrorKeys.record.multipleNodesFound, errorParams)\n }\n return children[0]\n }\n\n// called for every ancestor in the record update loops: keep it a plain lookup\nconst getParentNode = (record: ArenaRecord, node: ArenaRecordNode): ArenaRecordNode | undefined =>\n node.parentUuid ? record.nodes?.[node.parentUuid] : undefined\n\nexport const getParent =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getParentNode(record, node)\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: ArenaRecordNode, nodeDefUuid: string) => boolean) =>\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n let child = node\n let parent = getParentNode(record, child)\n while (parent) {\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n child = parent\n parent = getParentNode(record, child)\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\n/**\n * Whether a value is required for the node: key or always required attribute, or attribute with a \"required if\"\n * condition met in its parent entity (evaluated condition stored in the parent node meta).\n */\nexport const isNodeRequired =\n (nodeDef: NodeDef<NodeDefType>, node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parent = getParentNode(record, node)\n return !!parent && Nodes.isChildRequired(parent, nodeDef.uuid)\n }\n\nexport const getDependentCodeAttributes =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError(SystemErrorKeys.record.nodesIndexNotInitialized)\n }\n\nexport const getParentCodeAttribute =\n (parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf(parentNode)(record)\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\n\n/**\n * Visits the specified node and its ancestors, from the node up to the root: the visit stops when the visitor returns true.\n */\nexport const visitAncestorsAndSelf =\n (node: ArenaRecordNode, visitor: (node: ArenaRecordNode) => boolean | void) =>\n (record: ArenaRecord): void => {\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n if (visitor(currentNode)) return\n currentNode = getParentNode(record, currentNode)\n }\n }\n\n/**\n * Returns the first node satisfying the predicate among the specified node and its ancestors (from the node up to the root).\n */\nexport const findAncestor =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let result: ArenaRecordNode | undefined = undefined\n visitAncestorsAndSelf(node, (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n return true\n }\n return false\n })(record)\n return result\n }\n\n/**\n * Returns the specified node, if it has the specified node def, or its ancestor with that node def; undefined if not found.\n */\nexport const getAncestor =\n (node: ArenaRecordNode, ancestorDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let ancestor: ArenaRecordNode | undefined = node\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParentNode(record, ancestor)\n }\n return ancestor\n }\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): Array<ArenaRecordNode> => {\n const ancestors: Array<ArenaRecordNode> = []\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n ancestors.push(currentNode)\n currentNode = getParentNode(record, currentNode)\n }\n return ancestors\n }\n\n// descendants\n\nexport const getDescendantsOrSelf =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: ArenaRecordNode[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n }\n\n/**\n * Returns the first descendant (or the node itself) with the specified node def, or undefined if not found.\n */\nexport const getDescendant =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getDescendantsOrSelf(node, nodeDefDescendant)(record)[0]\n\nexport const isDescendantOf = (node: ArenaRecordNode, ancestor: ArenaRecordNode): boolean =>\n Nodes.getHierarchy(node).includes(ancestor.uuid)\n\nexport const visitDescendantsAndSelf =\n (\n node: ArenaRecordNode,\n visitor: (node: ArenaRecordNode) => boolean | void,\n traverseMethod: TraverseMethod = TraverseMethod.bfs\n ) =>\n (record: ArenaRecord): void => {\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue<ArenaRecordNode>()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()!\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as ArenaRecordNode\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n }\n\nexport const findDescendantOrSelf =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf(node, (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n })(record)\n return found\n }\n\nconst getClosestAncestorNode =\n (\n node: ArenaRecordNode,\n nodeDef: NodeDef<NodeDefType, NodeDefProps>,\n dependentDef: NodeDef<NodeDefType, NodeDefProps>,\n dependencyType: SurveyDependencyType\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor(node, commonAncestorDefUuid)(record)\n }\n\ntype KeyDefs = NodeDef<NodeDefType, NodeDefProps>[]\n\n/**\n * Returns the key nodes of the entity, indexed by key def uuid; keyDefs, when specified, are used instead of the\n * entity def keys in the cycle.\n */\nexport const getEntityKeyNodesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): NodesMap => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant(entity, nodeDefKey)(record)\n // missing key nodes are kept as undefined entries\n acc[nodeDefKey.uuid] = nodeKey as ArenaRecordNode\n return acc\n }, {})\n }\n\nexport const getEntityKeyNodes =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n Object.values(getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntityKeyValuesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n }\n\nexport const getEntityKeyValues =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntitySiblings =\n (entity: ArenaRecordNode, includeSelf = false) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n }\n\nexport const getAttributeSiblings =\n (node: ArenaRecordNode, nodeDef: NodeDef<NodeDefType, NodeDefProps>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings(parentEntity)(record)\n return siblingParentEntities.reduce((siblingsAcc: ArenaRecordNode[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n }\n\nexport const getNodeIndex = (node: ArenaRecordNode) => (record: ArenaRecord) => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n // compared by uuid: the specified node can be a copy of the one in the record (e.g. an updated version of it)\n return siblings.findIndex((sibling) => sibling.uuid === node.uuid)\n}\n\nexport const findEntityByKeyValues =\n (\n survey: Survey,\n cycle: string,\n parentEntity: ArenaRecordNode,\n entityDefUuid: string,\n keyValuesByDefUuid: Dictionary<any>\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid(\n survey,\n siblingEntity,\n undefined,\n keyDefs\n )(record)\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n }\n\nexport const findEntityWithSameKeysInAnotherRecord =\n (survey: Survey, cycle: string, entityUuid: string, recordOther: ArenaRecord) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf(entity)(record)\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid(survey, ancestor)(record),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues(\n survey,\n cycle,\n otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid\n )(recordOther)\n }\n return otherRecordCurrentParentEntity\n }\n\nexport const getDependentNodePointers =\n (\n survey: Survey,\n node: ArenaRecordNode,\n dependencyType: SurveyDependencyType,\n includeSelf = false,\n filterFn: ((nodePointer: NodePointer) => boolean) | null = null\n ) =>\n (record: ArenaRecord): NodePointer[] => {\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode(node, nodeDef, dependentDef, dependencyType)(record)\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError(SystemErrorKeys.record.dependencyOnRootFound)\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf(commonAncestorNode, nodeDefDependentParent)(record)\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n }\n\n/**\n * Returns the code attributes the specified code attribute depends on, from the top level one to the parent one.\n */\nexport const getAncestorCodeAttributes =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const ancestorCodeAttributes = []\n let currentParentCodeAttribute = getParentCodeAttribute(parentNode, nodeDef)(record)\n while (currentParentCodeAttribute) {\n ancestorCodeAttributes.unshift(currentParentCodeAttribute)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute(parentNode, ancestorCodeDef)(record)\n }\n return ancestorCodeAttributes\n }\n\nexport const getAncestorCodePath =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>) =>\n (record: ArenaRecord): string[] =>\n getAncestorCodeAttributes(\n survey,\n parentNode,\n nodeDef\n )(record).map((codeAttribute) => {\n const codeItemUuid = NodeValues.getItemUuid(codeAttribute)\n if (!codeItemUuid) return ''\n // items of big categories are not in the survey ref data: they can be in the node ref data\n const item =\n codeAttribute.refData?.categoryItem ?? Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n })\n\nexport const getCategoryItemUuid =\n (survey: Survey, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>, parentNode: ArenaRecordNode, code: string) =>\n (record: ArenaRecord): string | undefined => {\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath(survey, parentNode, nodeDef)(record), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n }\n\nexport const isNodeFilledByUser =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: ArenaRecord): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: ArenaRecord): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: ArenaRecord): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
|
|
@@ -22,6 +22,7 @@ const extractPreviousCycleValues = ({ node, context, }) => {
|
|
|
22
22
|
};
|
|
23
23
|
export const recordExpressionFunctions = Object.assign(Object.assign({}, nodeDefExpressionFunctions), { count: {
|
|
24
24
|
minArity: 1,
|
|
25
|
+
maxArity: 1,
|
|
25
26
|
evaluateArgsToNodes: true,
|
|
26
27
|
executor: (_context) => (nodeSet) => {
|
|
27
28
|
if (!nodeSet)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../src/record/recordExpressionEvaluator/functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,MAAM,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAmB,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACv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AAO,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;QACvG,CAAC;KACF,EACD,iBAAiB,EAAE;QACjB,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC,OAAgC,EAAE,EAAE,CAAC,GAAG,EAAE,sBAAC,CAAA,MAAA,OAAO,CAAC,IAAI,0CAAE,IAAI,OAAK,MAAA,OAAO,CAAC,MAAM,0CAAE,SAAS,CAAA,GAAA;KACvG,GACF,CAAA","sourcesContent":["import { ExpressionFunctions } from '../../expression'\nimport { Point, Points } from '../../geo'\nimport { ArenaRecordNode, Nodes, NodeValues } from '../../node'\nimport { nodeDefExpressionFunctions } from '../../nodeDefExpressionEvaluator/functions'\nimport { Surveys } from '../../survey'\nimport { Arrays } from '../../utils'\nimport { Records } from '../records'\nimport { RecordExpressionContext } from './context'\n\nconst extractPreviousCycleValues = ({\n node,\n context,\n}: {\n node: ArenaRecordNode | null\n context: RecordExpressionContext\n}): any[] | null => {\n const { record, prevCycleRecord, survey } = context\n if (!node || !prevCycleRecord) {\n return null\n }\n const currentRecordEntity = Records.getParent(node)(record)\n if (!currentRecordEntity) {\n return null\n }\n const { uuid: entityUuid } = currentRecordEntity\n const prevCycleEntity = Records.findEntityWithSameKeysInAnotherRecord(\n survey,\n Records.getCycle(record),\n entityUuid,\n prevCycleRecord\n )(record)\n if (!prevCycleEntity) {\n return null\n }\n return Records.getChildren(prevCycleEntity, node.nodeDefUuid)(prevCycleRecord).map((prevNode) => prevNode.value)\n}\n\nexport const recordExpressionFunctions: ExpressionFunctions<RecordExpressionContext> = {\n ...nodeDefExpressionFunctions,\n count: {\n minArity: 1,\n evaluateArgsToNodes: true,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (!nodeSet) return 0\n if (Array.isArray(nodeSet)) return nodeSet.length\n return 0\n },\n },\n first: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (nodeSet && Array.isArray(nodeSet) && nodeSet.length > 0) {\n return nodeSet[0]\n }\n return null\n },\n },\n geoPolygon: {\n minArity: 1,\n evaluateArgsToNodes: true,\n executor:\n (context: RecordExpressionContext) =>\n (...nodeSetOrPoints): object | null => {\n if (nodeSetOrPoints.length === 0) return null\n\n const { survey } = context\n const srsIndex = Surveys.getSRSIndex(survey)\n\n const toPoint = (nodeOrPoint: any): Point | null => {\n if (typeof nodeOrPoint === 'string') {\n const point = Points.parse(nodeOrPoint)\n return point && Points.isValid(point, srsIndex) ? point : null\n }\n return Points.isValid(nodeOrPoint, srsIndex)\n ? nodeOrPoint\n : NodeValues.getValueAsPoint({ survey, node: nodeOrPoint })\n }\n\n const pointsLatLon: Point[] = nodeSetOrPoints.reduce((acc, nodeSetOrPoint) => {\n Arrays.toArray(nodeSetOrPoint).forEach((nodeOrPoint) => {\n const point = toPoint(nodeOrPoint)\n const pointLatLon = point ? Points.toLatLong(point, srsIndex) : null\n if (pointLatLon) {\n acc.push(pointLatLon)\n }\n })\n return acc\n }, [])\n\n if (pointsLatLon.length === 0) return null\n\n return {\n type: 'Feature',\n geometry: {\n type: 'Polygon',\n coordinates: [pointsLatLon.map((point) => [point.x, point.y])],\n },\n }\n },\n },\n index: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (context: RecordExpressionContext) => (node) => {\n if (!node) {\n return -1\n }\n if (Nodes.isRoot(node)) {\n return 0\n }\n const { record } = context\n const parentNode = Records.getParent(node)(record)\n if (!parentNode) {\n return -1\n }\n const children = Records.getChildren(parentNode, node.nodeDefUuid)(record)\n return children.findIndex((n) => Nodes.areEqual(n, node))\n },\n },\n last: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (nodeSet && Array.isArray(nodeSet) && nodeSet.length > 0) {\n return nodeSet.at(-1)\n }\n return null\n },\n },\n parent: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n evaluateToNode: true,\n executor: (context: RecordExpressionContext) => (node) => {\n if (!node || Nodes.isRoot(node)) {\n return null\n }\n const { record } = context\n return Records.getParent(node)(record)\n },\n },\n prevCycleValue: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (context: RecordExpressionContext) => (node) => extractPreviousCycleValues({ node, context })?.[0],\n },\n prevCycleValues: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (context: RecordExpressionContext) => (node) => extractPreviousCycleValues({ node, context }),\n },\n recordCycle: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => Number(context.record.cycle ?? 0) + 1,\n },\n recordDateCreated: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.dateCreated,\n },\n recordDateLastModified: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.dateModified,\n },\n recordOwnerEmail: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.ownerEmail,\n },\n recordOwnerName: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.ownerName,\n },\n recordOwnerRole: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.ownerRole,\n },\n sum: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (!nodeSet) return 0\n if (Array.isArray(nodeSet)) return nodeSet.reduce((acc, value) => acc + (Number(value) || 0), 0)\n return 0\n },\n },\n unique: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (!nodeSet || !Array.isArray(nodeSet)) return []\n return [...new Set(nodeSet.filter((value) => value !== null && value !== undefined && value !== ''))]\n },\n },\n userIsRecordOwner: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.user?.uuid === context.record?.ownerUuid,\n },\n}\n"]}
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../../src/record/recordExpressionEvaluator/functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,MAAM,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAmB,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAA;AACvF,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAGpC,MAAM,0BAA0B,GAAG,CAAC,EAClC,IAAI,EACJ,OAAO,GAIR,EAAgB,EAAE;IACjB,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IACnD,IAAI,CAAC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,mBAAmB,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;IAC3D,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,OAAO,IAAI,CAAA;IACb,CAAC;IACD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,mBAAmB,CAAA;IAChD,MAAM,eAAe,GAAG,OAAO,CAAC,qCAAqC,CACnE,MAAM,EACN,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EACxB,UAAU,EACV,eAAe,CAChB,CAAC,MAAM,CAAC,CAAA;IACT,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAA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O,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YAChG,OAAO,CAAC,CAAA;QACV,CAAC;KACF,EACD,MAAM,EAAE;QACN,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,mBAAmB,EAAE,KAAK;QAC1B,QAAQ,EAAE,CAAC,QAAiC,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3D,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;gBAAE,OAAO,EAAE,CAAA;YAClD,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,CAAA;QACvG,CAAC;KACF,EACD,iBAAiB,EAAE;QACjB,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC,OAAgC,EAAE,EAAE,CAAC,GAAG,EAAE,sBAAC,CAAA,MAAA,OAAO,CAAC,IAAI,0CAAE,IAAI,OAAK,MAAA,OAAO,CAAC,MAAM,0CAAE,SAAS,CAAA,GAAA;KACvG,GACF,CAAA","sourcesContent":["import { ExpressionFunctions } from '../../expression'\nimport { Point, Points } from '../../geo'\nimport { ArenaRecordNode, Nodes, NodeValues } from '../../node'\nimport { nodeDefExpressionFunctions } from '../../nodeDefExpressionEvaluator/functions'\nimport { Surveys } from '../../survey'\nimport { Arrays } from '../../utils'\nimport { Records } from '../records'\nimport { RecordExpressionContext } from './context'\n\nconst extractPreviousCycleValues = ({\n node,\n context,\n}: {\n node: ArenaRecordNode | null\n context: RecordExpressionContext\n}): any[] | null => {\n const { record, prevCycleRecord, survey } = context\n if (!node || !prevCycleRecord) {\n return null\n }\n const currentRecordEntity = Records.getParent(node)(record)\n if (!currentRecordEntity) {\n return null\n }\n const { uuid: entityUuid } = currentRecordEntity\n const prevCycleEntity = Records.findEntityWithSameKeysInAnotherRecord(\n survey,\n Records.getCycle(record),\n entityUuid,\n prevCycleRecord\n )(record)\n if (!prevCycleEntity) {\n return null\n }\n return Records.getChildren(prevCycleEntity, node.nodeDefUuid)(prevCycleRecord).map((prevNode) => prevNode.value)\n}\n\nexport const recordExpressionFunctions: ExpressionFunctions<RecordExpressionContext> = {\n ...nodeDefExpressionFunctions,\n count: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (!nodeSet) return 0\n if (Array.isArray(nodeSet)) return nodeSet.length\n return 0\n },\n },\n first: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (nodeSet && Array.isArray(nodeSet) && nodeSet.length > 0) {\n return nodeSet[0]\n }\n return null\n },\n },\n geoPolygon: {\n minArity: 1,\n evaluateArgsToNodes: true,\n executor:\n (context: RecordExpressionContext) =>\n (...nodeSetOrPoints): object | null => {\n if (nodeSetOrPoints.length === 0) return null\n\n const { survey } = context\n const srsIndex = Surveys.getSRSIndex(survey)\n\n const toPoint = (nodeOrPoint: any): Point | null => {\n if (typeof nodeOrPoint === 'string') {\n const point = Points.parse(nodeOrPoint)\n return point && Points.isValid(point, srsIndex) ? point : null\n }\n return Points.isValid(nodeOrPoint, srsIndex)\n ? nodeOrPoint\n : NodeValues.getValueAsPoint({ survey, node: nodeOrPoint })\n }\n\n const pointsLatLon: Point[] = nodeSetOrPoints.reduce((acc, nodeSetOrPoint) => {\n Arrays.toArray(nodeSetOrPoint).forEach((nodeOrPoint) => {\n const point = toPoint(nodeOrPoint)\n const pointLatLon = point ? Points.toLatLong(point, srsIndex) : null\n if (pointLatLon) {\n acc.push(pointLatLon)\n }\n })\n return acc\n }, [])\n\n if (pointsLatLon.length === 0) return null\n\n return {\n type: 'Feature',\n geometry: {\n type: 'Polygon',\n coordinates: [pointsLatLon.map((point) => [point.x, point.y])],\n },\n }\n },\n },\n index: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (context: RecordExpressionContext) => (node) => {\n if (!node) {\n return -1\n }\n if (Nodes.isRoot(node)) {\n return 0\n }\n const { record } = context\n const parentNode = Records.getParent(node)(record)\n if (!parentNode) {\n return -1\n }\n const children = Records.getChildren(parentNode, node.nodeDefUuid)(record)\n return children.findIndex((n) => Nodes.areEqual(n, node))\n },\n },\n last: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (nodeSet && Array.isArray(nodeSet) && nodeSet.length > 0) {\n return nodeSet.at(-1)\n }\n return null\n },\n },\n parent: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n evaluateToNode: true,\n executor: (context: RecordExpressionContext) => (node) => {\n if (!node || Nodes.isRoot(node)) {\n return null\n }\n const { record } = context\n return Records.getParent(node)(record)\n },\n },\n prevCycleValue: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (context: RecordExpressionContext) => (node) => extractPreviousCycleValues({ node, context })?.[0],\n },\n prevCycleValues: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (context: RecordExpressionContext) => (node) => extractPreviousCycleValues({ node, context }),\n },\n recordCycle: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => Number(context.record.cycle ?? 0) + 1,\n },\n recordDateCreated: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.dateCreated,\n },\n recordDateLastModified: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.dateModified,\n },\n recordOwnerEmail: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.ownerEmail,\n },\n recordOwnerName: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.ownerName,\n },\n recordOwnerRole: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.record.ownerRole,\n },\n sum: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (!nodeSet) return 0\n if (Array.isArray(nodeSet)) return nodeSet.reduce((acc, value) => acc + (Number(value) || 0), 0)\n return 0\n },\n },\n unique: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor: (_context: RecordExpressionContext) => (nodeSet) => {\n if (!nodeSet || !Array.isArray(nodeSet)) return []\n return [...new Set(nodeSet.filter((value) => value !== null && value !== undefined && value !== ''))]\n },\n },\n userIsRecordOwner: {\n minArity: 0,\n maxArity: 0,\n executor: (context: RecordExpressionContext) => () => context.user?.uuid === context.record?.ownerUuid,\n },\n}\n"]}
|
|
@@ -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 = (
|
|
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,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,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,8BAA8B,CAAC;QAC1D,MAAM;QACN,MAAM;QACN,IAAI;QACJ,cAAc,EAAE,oBAAoB,CAAC,UAAU;QAC/C,gCAAgC,EAAE,IAAI;QACtC,6BAA6B,EAAE,IAAI;KACpC,CAAC,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F,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,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,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,2BAA2B,GAAG,CAAC,MAAsE,EAAE,EAAE;IAC7G,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,CAAA;IAEvC,MAAM,oB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CAAA;QACJ,CAAC;QACD,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;IAClF,CAAC;IACD,KAAK,MAAM,YAAY,IAAI,eAAe,EAAE,CAAC;QAC3C,uDAAuD;QACvD,8BAA8B,CAAC;YAC7B,YAAY;YACZ,YAAY;YACZ,UAAU;YACV,MAAM;YACN,mBAAmB;SACpB,CAAC,CAAA;IACJ,CAAC;AACH,CAAC,CAAA,CAAA;AAED,MAAM,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 { 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,
|
|
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;I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AAW,IAAI,oBAAoB,EAAE,CAAC;QAC/C,MAAM,EAAE,OAAO,EAAE,kBAAkB,EAAE,OAAO,EAAE,kBAAkB,EAAE,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,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"]}
|
|
@@ -39,7 +39,9 @@ export const updateDependentsCount = (params) => __awaiter(void 0, void 0, void
|
|
|
39
39
|
const count = Number(countResult === null || countResult === void 0 ? void 0 : countResult.value);
|
|
40
40
|
// 4. persist updated count if changed, and return updated nodes
|
|
41
41
|
const nodeDefUuid = nodeDefNodePointer.uuid;
|
|
42
|
-
|
|
42
|
+
const countPrev = Nodes.getChildrenMinOrMaxCount({ parentNode: nodeCtx, nodeDef: nodeDefNodePointer, countType });
|
|
43
|
+
// count not defined (NaN) before and after: NaN !== NaN would mark the node as updated every time
|
|
44
|
+
if (countPrev !== count && !(Number.isNaN(countPrev) && Number.isNaN(count))) {
|
|
43
45
|
// count changed
|
|
44
46
|
// 5. update node and add it to nodes updated
|
|
45
47
|
const nodeCtxUpdated = Nodes.assocChildrenCount({ node: nodeCtx, nodeDefUuid, count, countType });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodeDependentsCountUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsCountUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAA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AE,SAAS,CAAC,CAAA;QAC9E,IAAI,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC;YAAE,SAAQ;QAE7F,oCAAoC;QACpC,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAA;QAC3C,0DAA0D;QAC1D,MAAM,OAAO,SAAG,YAAY,CAAC,aAAa,CAAC,WAAW,CAAC,mCAAI,kBAAkB,CAAA;QAE7E,MAAM,cAAc,mCAAQ,MAAM,KAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,qBAAqB,GAAE,CAAA;QAC9G,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAA,CAAC,UAAU;QAEjG,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,CAAC,CAAA;QAExC,gEAAgE;QAChE,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAA;QAE3C,
|
|
1
|
+
{"version":3,"file":"recordNodeDependentsCountUpdater.js","sourceRoot":"","sources":["../../../../src/record/recordNodesUpdater/recordNodeDependentsCountUpdater.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAEzD,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AA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A;QAC9G,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAA,CAAC,UAAU;QAEjG,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,CAAC,CAAA;QAExC,gEAAgE;QAChE,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAA;QAE3C,MAAM,SAAS,GAAG,KAAK,CAAC,wBAAwB,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,CAAC,CAAA;QACjH,kGAAkG;QAClG,IAAI,SAAS,KAAK,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAC7E,gBAAgB;YAEhB,6CAA6C;YAC7C,MAAM,cAAc,GAAG,KAAK,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAA;YACjG,YAAY,CAAC,OAAO,CAAC,cAAc,EAAE,mBAAmB,CAAC,CAAA;QAC3D,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA","sourcesContent":["import { Nodes } from '../../node'\nimport { NodeDefCountType, NodeDefs } from '../../nodeDef'\nimport { SurveyDependencyType } from '../../survey'\nimport { Objects } from '../../utils'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport const updateDependentsCount = async (\n params: RecordNodeDependentsUpdateParams & {\n countType: NodeDefCountType\n }\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, countType, sideEffect = false } = params\n\n const updateResult = new RecordUpdateResult({ record })\n\n const recordUpdateOptions = { sideEffect }\n\n // 1. fetch dependent nodes\n const dependencyType =\n countType === NodeDefCountType.max ? SurveyDependencyType.maxCount : SurveyDependencyType.minCount\n\n const nodePointersToUpdate = Records.getDependentNodePointers(survey, node, dependencyType)(record)\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 const { nodeCtx: nodeCtxNodePointer, nodeDef: nodeDefNodePointer } = nodePointer\n\n const expressionsToEvaluate = NodeDefs.getCount(nodeDefNodePointer, countType)\n if (Objects.isEmpty(expressionsToEvaluate) || !Array.isArray(expressionsToEvaluate)) continue\n\n // 3. evaluate applicable expression\n const nodeCtxUuid = nodeCtxNodePointer.uuid\n // nodeCtx could have been updated in a previous iteration\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxUuid) ?? nodeCtxNodePointer\n\n const evaluateParams = { ...params, record: updateResult.record, nodeCtx, expressions: expressionsToEvaluate }\n const countResult = await expressionEvaluator.evalApplicableExpression(evaluateParams) // NOSONAR\n\n const count = Number(countResult?.value)\n\n // 4. persist updated count if changed, and return updated nodes\n const nodeDefUuid = nodeDefNodePointer.uuid\n\n const countPrev = Nodes.getChildrenMinOrMaxCount({ parentNode: nodeCtx, nodeDef: nodeDefNodePointer, countType })\n // count not defined (NaN) before and after: NaN !== NaN would mark the node as updated every time\n if (countPrev !== count && !(Number.isNaN(countPrev) && Number.isNaN(count))) {\n // count changed\n\n // 5. update node and add it to nodes updated\n const nodeCtxUpdated = Nodes.assocChildrenCount({ node: nodeCtx, nodeDefUuid, count, countType })\n updateResult.addNode(nodeCtxUpdated, recordUpdateOptions)\n }\n }\n return updateResult\n}\n"]}
|
|
@@ -69,8 +69,8 @@ const roundToPrecision = (value, precision = Number.NaN) => {
|
|
|
69
69
|
return Number.NaN;
|
|
70
70
|
if (Number.isNaN(precision))
|
|
71
71
|
return num;
|
|
72
|
-
|
|
73
|
-
return
|
|
72
|
+
// decimal arithmetic (1.005 * 100 is 100.49999... in floating point); halves rounded away from zero, as formatDecimal
|
|
73
|
+
return new BigNumber(num).shiftedBy(precision).integerValue(BigNumber.ROUND_HALF_UP).shiftedBy(-precision).toNumber();
|
|
74
74
|
};
|
|
75
75
|
const toCardinalByLang = {
|
|
76
76
|
[LanguageCode.en]: toCardinalEn,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../../src/utils/numbers.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACvD,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AAC1D,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,SAAS,CAAC,MAAM,CAAC;IACf,MAAM,EAAE;QACN,gBAAgB,EAAE,GAAG;QACrB,cAAc,EAAE,GAAG;QACnB,SAAS,EAAE,CAAC;KACb;CACF,CAAC,CAAA;AAEF,MAAM,QAAQ,GAAG,CAAC,GAAQ,EAAU,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;AAExF;;;;GAIG;AACH,MAAM,MAAM,GACV,CAAC,OAAe,EAAE,E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CAAA;IAC3B,CAAC;eAAO,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,MAAM;IACN,OAAO;IACP,aAAa;IACb,aAAa;IACb,OAAO;IACP,SAAS;IACT,KAAK;IACL,gBAAgB;IAChB,QAAQ;IACR,OAAO;CACR,CAAA","sourcesContent":["import BigNumber from 'bignumber.js'\nimport { toCardinal as toCardinalEn } from 'n2words/en'\nimport { toCardinal as toCardinalEs } from 'n2words/es'\nimport { toCardinal as toCardinalFr } from 'n2words/fr'\nimport { toCardinal as toCardinalJa } from 'n2words/ja'\nimport { toCardinal as toCardinalPt } from 'n2words/pt-PT'\nimport { toCardinal as toCardinalRu } from 'n2words/ru'\n\nimport { LanguageCode } from '../language'\nimport { Objects } from './_objects'\n\nBigNumber.config({\n FORMAT: {\n decimalSeparator: '.',\n groupSeparator: ',',\n groupSize: 3,\n },\n})\n\nconst toNumber = (num: any): number => (Objects.isEmpty(num) ? Number.NaN : Number(num))\n\n/**\n * Returns the absolute modulus of the specified value. The result will always be a positive number.\n * @param {!number} modulus - The modulus to apply.\n * @returns {number} - The result of the modulus (always positive or 0).\n */\nconst absMod =\n (modulus: number) =>\n (value: number): number =>\n ((value % modulus) + modulus) % modulus\n\nconst between = (value: number, min: number, max: number): boolean => min <= value && max >= value\n\nconst isFloat = (value: any): boolean => {\n const number = toNumber(value)\n return Number.isFinite(number)\n}\n\nconst isInteger = (value: any): boolean => {\n const number = toNumber(value)\n return Number.isInteger(number)\n}\n\n/**\n * Formats the given value to the specified fixed dicimal digits.\n */\nconst formatDecimal = (value: number, decimalDigits = Number.NaN) => {\n if (Number.isNaN(value) || value === null) return null\n const num = new BigNumber(value)\n\n if (decimalDigits > 0) {\n // round to fixed number of decimal digits\n return num.toFormat(decimalDigits)\n }\n if (decimalDigits === 0) {\n // format as integer\n return num.toFormat(0, { groupSeparator: '' })\n }\n return num.toString()\n}\n\n/**\n * Formats the given value to a rounded integer.\n *\n * @param {!number} value - The value to format.\n * @returns {string} - The formatted value or null if the value was null.\n */\nconst formatInteger = (value: number): string | null => formatDecimal(value, 0)\n\nconst limit =\n ({ minValue = Number.NaN, maxValue = Number.NaN }) =>\n (value: number) => {\n let result = Number(value)\n // NOTE: 0 is a valid bound\n if (!Number.isNaN(minValue)) result = Math.max(minValue, result)\n if (!Number.isNaN(maxValue)) result = Math.min(maxValue, result)\n return result\n }\n\nconst roundToPrecision = (value: any, precision = Number.NaN) => {\n const num = toNumber(value)\n if (Number.isNaN(num)) return Number.NaN\n if (Number.isNaN(precision)) return num\n // decimal arithmetic (1.005 * 100 is 100.49999... in floating point); halves rounded away from zero, as formatDecimal\n return new BigNumber(num).shiftedBy(precision).integerValue(BigNumber.ROUND_HALF_UP).shiftedBy(-precision).toNumber()\n}\n\nconst toCardinalByLang: Partial<Record<LanguageCode, (value: number | string | bigint) => string>> = {\n [LanguageCode.en]: toCardinalEn,\n [LanguageCode.es]: toCardinalEs,\n [LanguageCode.fr]: toCardinalFr,\n [LanguageCode.ja]: toCardinalJa,\n [LanguageCode.pt]: toCardinalPt,\n [LanguageCode.ru]: toCardinalRu,\n}\n\n/**\n * Converts the given number to words (cardinal form) in the specified language.\n * Falls back to English if the specified language is not supported.\n *\n * @returns The number in words, or null if the value is not a finite number or cannot be converted (e.g. too large).\n */\nconst toWords = (value: any, lang: LanguageCode = LanguageCode.en): string | null => {\n const number = toNumber(value)\n if (!Number.isFinite(number)) return null\n const toCardinal = toCardinalByLang[lang] ?? toCardinalByLang[LanguageCode.en]!\n try {\n return toCardinal(number)\n } catch {\n return null\n }\n}\n\nexport const Numbers = {\n absMod,\n between,\n formatDecimal,\n formatInteger,\n isFloat,\n isInteger,\n limit,\n roundToPrecision,\n toNumber,\n toWords,\n}\n"]}
|
|
@@ -316,7 +316,8 @@ const getNodeIndex = (node) => (record) => {
|
|
|
316
316
|
if (!parentEntity)
|
|
317
317
|
return 0; // root entity
|
|
318
318
|
const siblings = (0, exports.getChildren)(parentEntity, node.nodeDefUuid)(record);
|
|
319
|
-
|
|
319
|
+
// compared by uuid: the specified node can be a copy of the one in the record (e.g. an updated version of it)
|
|
320
|
+
return siblings.findIndex((sibling) => sibling.uuid === node.uuid);
|
|
320
321
|
};
|
|
321
322
|
exports.getNodeIndex = getNodeIndex;
|
|
322
323
|
const findEntityByKeyValues = (survey, cycle, parentEntity, entityDefUuid, keyValuesByDefUuid) => (record) => {
|