@openforis/arena-core 2.16.12 → 2.16.13

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.
@@ -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
- return siblings.indexOf(node);
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,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enaRecordNode, 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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W,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 // 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;AACvF,OAAO,EAAE,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G,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,OAAO,IAAI,CAAA;IACb,CA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AAC,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"]}
@@ -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
- if (Nodes.getChildrenMinOrMaxCount({ parentNode: nodeCtx, nodeDef: nodeDefNodePointer, countType }) !== count) {
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/rec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{ 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 if (Nodes.getChildrenMinOrMaxCount({ parentNode: nodeCtx, nodeDef: nodeDefNodePointer, countType }) !== 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"]}
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;AAE3D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,MAEC,EAC4B,EAAE;;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEtE,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,MAAM,mBAAmB,GAAG,EAAE,UAAU,EAAE,CAAA;IAE1C,2BAA2B;IAC3B,MAAM,cAAc,GAClB,SAAS,KAAK,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC,CAAC,oBAAoB,CAAC,QAAQ,CAAA;IAEpG,MAAM,oBAAoB,GAAG,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;IAEnG,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AAM,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
- const exp = Math.pow(10, precision);
73
- return Math.round(num * exp) / exp;
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,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AAC,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 const exp = Math.pow(10, precision)\n return Math.round(num * exp) / exp\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"]}
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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IAC/E,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,MAAM,CAAC,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
- return siblings.indexOf(node);
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) => {
@@ -1 +1 @@
1
- {"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":";;;AAAA,yCAAyD;AACzD,uCAA0D;AAC1D,qCAA0E;AAC1E,sDAAkD;AAClD,2CAA2G;AAC3G,yCAAoD;AAEpD,uCAA2C;AAC3C,sCAA4D;AAC5D,8CAAsD;AACtD,qEAAiE;AACjE,mEAA+D;AAExD,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,KAAK,mCAAI,qBAAY,GAAA,CAAA;AAAxE,QAAA,QAAQ,GAAR,QAAQ,CAAgE;AAE9E,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAA+B,EAAE,wBAAC,MAAM,CAAC,KAAK,mCAAI,EAAE,GAAA,CAAA;AAAnF,QAAA,QAAQ,GAAR,QAAQ,CAA2E;AAEzF,MAAM,aAAa,GAAG,CAAC,MAAmB,EAAqB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAA,QAAA,QAAQ,EAAC,MAAM,CAAC,CAAC,CAAA;AAA3F,QAAA,aAAa,GAAb,aAAa,CAA8E;AAExG;;;GAGG;AACI,MAAM,aAAa,GACxB,CAAC,IAAY,EAAE,EAAE,CACjB,CAAC,MAAmB,EAA+B,EAAE,kBACnD,MAAA,MAAM,CAAC,KAAK,0CAAG,IAAI,CAAC,GAAA,CAAA;AAHX,QAAA,aAAa,GAAb,aAAa,CAGF;AAEjB,MAAM,eAAe,GAC1B,C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AkB,GAC7B,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,CAAC,IAAA,QAAA,oBAAoB,EAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,YAAK,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAHlF,QAAA,kBAAkB,GAAlB,kBAAkB,CAGgE;AAExF,MAAM,WAAW,GACtB,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,IAAA,QAAA,kBAAkB,EAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;AAHxB,QAAA,WAAW,GAAX,WAAW,CAGa;AAE9B,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAW,EAAE;IACtD,MAAM,QAAQ,GAAG,IAAA,QAAA,OAAO,EAAC,MAAM,CAAC,CAAA;IAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAA,QAAA,WAAW,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC,CAAA;AAHY,QAAA,OAAO,GAAP,OAAO,CAGnB;AAEM,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,IAAI,mCAAI,4BAAmB,GAAA,CAAA;AAA7E,QAAA,OAAO,GAAP,OAAO,CAAsE;AAEnF,MAAM,gBAAgB,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,IAAA,QAAA,OAAO,EAAC,MAAM,CAAC,KAAK,mCAAsB,CAAA;AAA/F,QAAA,gBAAgB,GAAhB,gBAAgB,CAA+E","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,yCAAyD;AACzD,uCAA0D;AAC1D,qCAA0E;AAC1E,sDAAkD;AAClD,2CAA2G;AAC3G,yCAAoD;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CAAC,CAAC,MAAM,CAAC,CAAA;AAHxB,QAAA,WAAW,GAAX,WAAW,CAGa;AAE9B,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAW,EAAE;IACtD,MAAM,QAAQ,GAAG,IAAA,QAAA,OAAO,EAAC,MAAM,CAAC,CAAA;IAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,IAAA,QAAA,WAAW,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC,CAAA;AAHY,QAAA,OAAO,GAAP,OAAO,CAGnB;AAEM,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,IAAI,mCAAI,4BAAmB,GAAA,CAAA;AAA7E,QAAA,OAAO,GAAP,OAAO,CAAsE;AAEnF,MAAM,gBAAgB,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,IAAA,QAAA,OAAO,EAAC,MAAM,CAAC,KAAK,mCAAsB,CAAA;AAA/F,QAAA,gBAAgB,GAAhB,gBAAgB,CAA+E","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"]}
@@ -25,6 +25,7 @@ const extractPreviousCycleValues = ({ node, context, }) => {
25
25
  };
26
26
  exports.recordExpressionFunctions = Object.assign(Object.assign({}, functions_1.nodeDefExpressionFunctions), { count: {
27
27
  minArity: 1,
28
+ maxArity: 1,
28
29
  evaluateArgsToNodes: true,
29
30
  executor: (_context) => (nodeSet) => {
30
31
  if (!nodeSet)
@@ -1 +1 @@
1
- {"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/record/recordExpressionEvaluator/functions.ts"],"names":[],"mappings":";;;AACA,mCAAyC;AACzC,qCAA+D;AAC/D,0EAAuF;AACvF,yCAAsC;AACtC,uCAAoC;AACpC,wCAAoC;AAGpC,MAAM,0BAA0B,GAAG,CAAC,EAClC,IAAI,EACJ,OAAO,GAIR,EAAgB,EAAE;IACjB,MAAM,EAA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,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,IACF","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/funct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AC,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,IACF","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"]}
@@ -42,7 +42,9 @@ const updateDependentsCount = (params) => __awaiter(void 0, void 0, void 0, func
42
42
  const count = Number(countResult === null || countResult === void 0 ? void 0 : countResult.value);
43
43
  // 4. persist updated count if changed, and return updated nodes
44
44
  const nodeDefUuid = nodeDefNodePointer.uuid;
45
- if (node_1.Nodes.getChildrenMinOrMaxCount({ parentNode: nodeCtx, nodeDef: nodeDefNodePointer, countType }) !== count) {
45
+ const countPrev = node_1.Nodes.getChildrenMinOrMaxCount({ parentNode: nodeCtx, nodeDef: nodeDefNodePointer, countType });
46
+ // count not defined (NaN) before and after: NaN !== NaN would mark the node as updated every time
47
+ if (countPrev !== count && !(Number.isNaN(countPrev) && Number.isNaN(count))) {
46
48
  // count changed
47
49
  // 5. update node and add it to nodes updated
48
50
  const nodeCtxUpdated = node_1.Nodes.assocChildrenCount({ node: nodeCtx, nodeDefUuid, count, countType });
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodeDependentsCountUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsCountUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAkC;AAClC,2CAA0D;AAC1D,yCAAmD;AACnD,uCAAqC;AACrC,4EAAwE;AACxE,wCAAoC;AAEpC,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAEpD,MAAM,qBAAqB,GAAG,CACnC,MAEC,EAC4B,EAAE;;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEtE,MAAM,YAAY,GAAG,IAAI,uCAAkB,CAAC,EAAE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G,kBAAkB,CAAC,IAAI,CAAA;QAE3C,IAAI,YAAK,CAAC,wBAAwB,CAAC,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC;YAC9G,gBAAgB;YAEhB,6CAA6C;YAC7C,MAAM,cAAc,GAAG,YAAK,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;AA/CY,QAAA,qBAAqB,GAArB,qBAAqB,CA+CjC","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 if (Nodes.getChildrenMinOrMaxCount({ parentNode: nodeCtx, nodeDef: nodeDefNodePointer, countType }) !== 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"]}
1
+ {"version":3,"file":"recordNodeDependentsCountUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsCountUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAkC;AAClC,2CAA0D;AAC1D,yCAAmD;AACnD,uCAAqC;AACrC,4EAAwE;AACxE,wCAAoC;AAEpC,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAEpD,MAAM,qBAAqB,GAAG,CACnC,MAEC,EAC4B,EAAE;;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEtE,MAAM,YAAY,GAAG,IAAI,uCAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,MAAM,mBAAmB,GAAG,EAA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AK,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,YAAK,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;AAjDY,QAAA,qBAAqB,GAArB,qBAAqB,CAiDjC","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"]}
@@ -75,8 +75,8 @@ const roundToPrecision = (value, precision = Number.NaN) => {
75
75
  return Number.NaN;
76
76
  if (Number.isNaN(precision))
77
77
  return num;
78
- const exp = Math.pow(10, precision);
79
- return Math.round(num * exp) / exp;
78
+ // decimal arithmetic (1.005 * 100 is 100.49999... in floating point); halves rounded away from zero, as formatDecimal
79
+ return new bignumber_js_1.default(num).shiftedBy(precision).integerValue(bignumber_js_1.default.ROUND_HALF_UP).shiftedBy(-precision).toNumber();
80
80
  };
81
81
  const toCardinalByLang = {
82
82
  [language_1.LanguageCode.en]: en_1.toCardinal,
@@ -1 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CAAA;IACb,CAAC;AACH,CAAC,CAAA;AAEY,QAAA,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 const exp = Math.pow(10, precision)\n return Math.round(num * exp) / exp\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"]}
1
+ {"version":3,"file":"numbers.js","sourceRoot":"","sources":["../../src/utils/numbers.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAoC;AACpC,mCAAuD;AACvD,mCAAuD;AACvD,mCAAuD;AACvD,mCAAuD;AACvD,yCAA0D;AAC1D,mCAAuD;AAEvD,0CAA0C;AAC1C,yCAAoC;AAEpC,sBAAS,CAAC,MAAM,CAAC;IACf,MAAM,EAA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ardinalEn } 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"]}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "name": "OpenForis",
5
5
  "email": "openforis.arena@gmail.com"
6
6
  },
7
- "version": "2.16.12",
7
+ "version": "2.16.13",
8
8
  "description": "Arena core module",
9
9
  "repository": {
10
10
  "type": "git",