@openforis/arena-core 2.3.42 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/dist/esm/record/_records/recordCompletion.js +3 -3
  2. package/dist/esm/record/_records/recordCompletion.js.map +1 -1
  3. package/dist/esm/record/_records/recordGetters.js +221 -143
  4. package/dist/esm/record/_records/recordGetters.js.map +1 -1
  5. package/dist/esm/record/_records/recordPagesValidation.js +5 -5
  6. package/dist/esm/record/_records/recordPagesValidation.js.map +1 -1
  7. package/dist/esm/record/_records/recordUtils.js +3 -7
  8. package/dist/esm/record/_records/recordUtils.js.map +1 -1
  9. package/dist/esm/record/nodePointers.js +1 -1
  10. package/dist/esm/record/nodePointers.js.map +1 -1
  11. package/dist/esm/record/recordCloner.js +1 -1
  12. package/dist/esm/record/recordCloner.js.map +1 -1
  13. package/dist/esm/record/recordExpressionEvaluator/functions.js +4 -5
  14. package/dist/esm/record/recordExpressionEvaluator/functions.js.map +1 -1
  15. package/dist/esm/record/recordExpressionEvaluator/node/identifier/identifier.js +1 -1
  16. package/dist/esm/record/recordExpressionEvaluator/node/identifier/identifier.js.map +1 -1
  17. package/dist/esm/record/recordExpressionEvaluator/node/identifier/nodesFinder.js +2 -2
  18. package/dist/esm/record/recordExpressionEvaluator/node/identifier/nodesFinder.js.map +1 -1
  19. package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js +1 -1
  20. package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
  21. package/dist/esm/record/recordFixer.js +5 -5
  22. package/dist/esm/record/recordFixer.js.map +1 -1
  23. package/dist/esm/record/recordNodesUpdater/recordExpressionValueConverter.js +2 -8
  24. package/dist/esm/record/recordNodesUpdater/recordExpressionValueConverter.js.map +1 -1
  25. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +6 -6
  26. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
  27. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +1 -1
  28. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
  29. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +1 -6
  30. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
  31. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +3 -4
  32. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
  33. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsEnumeratedEntitiesUpdater.js +3 -3
  34. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsEnumeratedEntitiesUpdater.js.map +1 -1
  35. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsEnumeratingItemsUpdater.js +4 -9
  36. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsEnumeratingItemsUpdater.js.map +1 -1
  37. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +2 -3
  38. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
  39. package/dist/esm/record/recordNodesUpdater/recordNodesDeleter.js +1 -5
  40. package/dist/esm/record/recordNodesUpdater/recordNodesDeleter.js.map +1 -1
  41. package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +2 -9
  42. package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
  43. package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js +1 -1
  44. package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  45. package/dist/esm/record/recordPrettyPrinter.js +14 -12
  46. package/dist/esm/record/recordPrettyPrinter.js.map +1 -1
  47. package/dist/esm/record/recordUpdater.js +2 -2
  48. package/dist/esm/record/recordUpdater.js.map +1 -1
  49. package/dist/esm/record/recordValidator/attributeKeyValidator.js +4 -4
  50. package/dist/esm/record/recordValidator/attributeKeyValidator.js.map +1 -1
  51. package/dist/esm/record/recordValidator/attributeUniqueValidator.js +1 -1
  52. package/dist/esm/record/recordValidator/attributeUniqueValidator.js.map +1 -1
  53. package/dist/esm/record/recordValidator/attributeValidator.js +8 -10
  54. package/dist/esm/record/recordValidator/attributeValidator.js.map +1 -1
  55. package/dist/esm/record/recordValidator/countVaildator.js +2 -2
  56. package/dist/esm/record/recordValidator/countVaildator.js.map +1 -1
  57. package/dist/esm/record/recordValidator/recordValidator.js +1 -2
  58. package/dist/esm/record/recordValidator/recordValidator.js.map +1 -1
  59. package/dist/record/_records/recordCompletion.js +3 -3
  60. package/dist/record/_records/recordCompletion.js.map +1 -1
  61. package/dist/record/_records/recordGetters.d.ts +104 -51
  62. package/dist/record/_records/recordGetters.js +221 -170
  63. package/dist/record/_records/recordGetters.js.map +1 -1
  64. package/dist/record/_records/recordPagesValidation.js +5 -5
  65. package/dist/record/_records/recordPagesValidation.js.map +1 -1
  66. package/dist/record/_records/recordUtils.js +3 -7
  67. package/dist/record/_records/recordUtils.js.map +1 -1
  68. package/dist/record/nodePointers.js +1 -1
  69. package/dist/record/nodePointers.js.map +1 -1
  70. package/dist/record/recordCloner.js +1 -1
  71. package/dist/record/recordCloner.js.map +1 -1
  72. package/dist/record/recordExpressionEvaluator/functions.js +4 -5
  73. package/dist/record/recordExpressionEvaluator/functions.js.map +1 -1
  74. package/dist/record/recordExpressionEvaluator/node/identifier/identifier.js +1 -1
  75. package/dist/record/recordExpressionEvaluator/node/identifier/identifier.js.map +1 -1
  76. package/dist/record/recordExpressionEvaluator/node/identifier/nodesFinder.js +2 -2
  77. package/dist/record/recordExpressionEvaluator/node/identifier/nodesFinder.js.map +1 -1
  78. package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js +1 -1
  79. package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
  80. package/dist/record/recordFixer.js +5 -5
  81. package/dist/record/recordFixer.js.map +1 -1
  82. package/dist/record/recordNodesUpdater/recordExpressionValueConverter.js +2 -8
  83. package/dist/record/recordNodesUpdater/recordExpressionValueConverter.js.map +1 -1
  84. package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +6 -6
  85. package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
  86. package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +1 -1
  87. package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
  88. package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +1 -6
  89. package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
  90. package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +3 -4
  91. package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
  92. package/dist/record/recordNodesUpdater/recordNodeDependentsEnumeratedEntitiesUpdater.js +3 -3
  93. package/dist/record/recordNodesUpdater/recordNodeDependentsEnumeratedEntitiesUpdater.js.map +1 -1
  94. package/dist/record/recordNodesUpdater/recordNodeDependentsEnumeratingItemsUpdater.js +4 -9
  95. package/dist/record/recordNodesUpdater/recordNodeDependentsEnumeratingItemsUpdater.js.map +1 -1
  96. package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +2 -3
  97. package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
  98. package/dist/record/recordNodesUpdater/recordNodesDeleter.js +1 -5
  99. package/dist/record/recordNodesUpdater/recordNodesDeleter.js.map +1 -1
  100. package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +2 -9
  101. package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
  102. package/dist/record/recordNodesUpdater/recordNodesUpdater.js +1 -1
  103. package/dist/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  104. package/dist/record/recordPrettyPrinter.js +14 -12
  105. package/dist/record/recordPrettyPrinter.js.map +1 -1
  106. package/dist/record/recordUpdater.js +2 -2
  107. package/dist/record/recordUpdater.js.map +1 -1
  108. package/dist/record/recordValidator/attributeKeyValidator.js +4 -4
  109. package/dist/record/recordValidator/attributeKeyValidator.js.map +1 -1
  110. package/dist/record/recordValidator/attributeUniqueValidator.js +1 -1
  111. package/dist/record/recordValidator/attributeUniqueValidator.js.map +1 -1
  112. package/dist/record/recordValidator/attributeValidator.js +8 -10
  113. package/dist/record/recordValidator/attributeValidator.js.map +1 -1
  114. package/dist/record/recordValidator/countVaildator.js +2 -2
  115. package/dist/record/recordValidator/countVaildator.js.map +1 -1
  116. package/dist/record/recordValidator/recordValidator.js +1 -2
  117. package/dist/record/recordValidator/recordValidator.js.map +1 -1
  118. package/dist/record/records.d.ts +140 -34
  119. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"recordPrettyPrinter.js","sourceRoot":"","sources":["../../src/record/recordPrettyPrinter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAsD;AACtD,kCAAoE;AACpE,wCAAqC;AACrC,sCAA2C;AAC3C,oCAAkC;AAElC,MAAY,aAAa,qDAAgC;AASzD,MAAM,mBAAmB,GAAiB;IACxC,iBAAiB,EAAE,KAAK;IACxB,iBAAiB,EAAE,KAAK;IACxB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,KAAK;CACtB,CAAA;AAED,MAAM,KAAK,GAAG,CAAC,MAAuE,EAAU,EAAE;IAChG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,mBAAmB,EAAE,GAAG,MAAM,CAAA;IAChE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,cAAc,EAAE,GAAG,OAAO,CAAA;IAEzF,MAAM,KAAK,GAAG,aAAa,CAAC,QAAQ,CAAC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AAI,CAAC,CAAA;IACrB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IACV,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,MAIxB,EAAY,EAAE;IACb,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAA,mBAAmB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACxG,CAAC,CAAA;AAEY,QAAA,mBAAmB,GAAG;IACjC,KAAK;IACL,aAAa;IACb,eAAe;CAChB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../common'\nimport { ArenaRecordNode, NodeValueFormatter, Nodes } from '../node'\nimport { NodeDefs } from '../nodeDef'\nimport { Survey, Surveys } from '../survey'\nimport { Strings } from '../utils'\nimport { ArenaRecord } from './record'\nimport * as RecordGetters from './_records/recordGetters'\n\ntype PrintOptions = {\n includeEmptyNodes?: boolean\n showNotApplicable?: boolean\n showNotEditable?: boolean\n showNotVisible?: boolean\n}\n\nconst DefaultPrintOptions: PrintOptions = {\n includeEmptyNodes: false,\n showNotApplicable: false,\n showNotEditable: false,\n showNotVisible: false,\n}\n\nconst print = (params: { survey: Survey; record: ArenaRecord; options?: PrintOptions }): string => {\n const { survey, record, options = DefaultPrintOptions } = params\n const { includeEmptyNodes, showNotApplicable, showNotEditable, showNotVisible } = options\n\n const cycle = RecordGetters.getCycle(record)\n const rootNode = RecordGetters.getRoot(record)\n if (!rootNode) {\n return ''\n }\n\n const getInfoParts = (params: { parentNode?: ArenaRecordNode | null; childDefUuid: string }): string[] => {\n const { parentNode, childDefUuid } = params\n if (!parentNode) {\n return []\n }\n const infoParts: string[] = []\n if (showNotApplicable && !Nodes.isChildApplicable(parentNode, childDefUuid)) {\n infoParts.push('not applicable')\n }\n if (showNotEditable && !Nodes.isChildEditable(parentNode, childDefUuid)) {\n infoParts.push('not editable')\n }\n if (showNotVisible && !Nodes.isChildVisible(parentNode, childDefUuid)) {\n infoParts.push('not visible')\n }\n return infoParts\n }\n\n const toPart = (params: { depth: number; name: string; value: string; infoParts?: string[] }): string => {\n const { depth, name, value, infoParts = [] } = params\n const indentation = Strings.repeat(' ', depth)\n let part = `${indentation}${name}: ${value}`\n if (infoParts.length > 0) {\n part += ` (${infoParts.join(', ')})`\n }\n return part\n }\n\n const parts: string[] = []\n\n if (includeEmptyNodes) {\n const printNodeAndChildren = (params: { node: ArenaRecordNode; parentNode: ArenaRecordNode | null }): void => {\n const { node, parentNode } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const value = NodeValueFormatter.format({ survey, cycle, nodeDef, node, value: node.value })\n const depth = Nodes.getHierarchy(node).length\n const infoParts = getInfoParts({ parentNode, childDefUuid: node.nodeDefUuid })\n parts.push(toPart({ depth, name: NodeDefs.getName(nodeDef), value, infoParts }))\n\n const childDefs = Surveys.getNodeDefChildrenSorted({ survey, nodeDef, cycle })\n childDefs.forEach((childDef) => {\n const children = RecordGetters.getChildren(node, childDef.uuid)(record)\n if (children.length === 0) {\n const childInfoParts = getInfoParts({ parentNode: node, childDefUuid: childDef.uuid })\n parts.push(\n toPart({\n depth: depth + 1,\n name: NodeDefs.getName(childDef),\n value: '<empty>',\n infoParts: childInfoParts,\n })\n )\n return\n }\n children.forEach((child) => printNodeAndChildren({ node: child, parentNode: node }))\n })\n }\n\n printNodeAndChildren({ node: rootNode, parentNode: null })\n return parts.join('\\n')\n }\n\n RecordGetters.visitDescendantsAndSelf({\n record,\n node: rootNode,\n visitor: (node) => {\n const { nodeDefUuid } = node\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const value = NodeValueFormatter.format({ survey, cycle, nodeDef, node, value: node.value })\n const depth = Nodes.getHierarchy(node).length\n const parentNode = NodeDefs.isRoot(nodeDef) ? null : RecordGetters.getParent(node)(record)\n const infoParts = getInfoParts({ parentNode, childDefUuid: nodeDefUuid })\n parts.push(toPart({ depth, name: NodeDefs.getName(nodeDef), value, infoParts }))\n return false\n },\n traverseMethod: TraverseMethod.dfs,\n })\n return parts.join('\\n')\n}\n\nconst printNodePath = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }): string => {\n const { survey, record, node } = params\n const parts: string[] = []\n RecordGetters.visitAncestorsAndSelf(node, (visitedNode) => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: visitedNode.nodeDefUuid })\n let part = NodeDefs.getName(nodeDef)\n if (NodeDefs.isMultiple(nodeDef)) {\n const index = RecordGetters.getNodeIndex({ record, node: visitedNode })\n part = `${part}[${index}]`\n }\n parts.unshift(part)\n })(record)\n return parts.join('.')\n}\n\nconst printNodesPaths = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: Dictionary<ArenaRecordNode>\n}): string[] => {\n const { survey, record, nodes } = params\n return Object.values(nodes).map((node) => RecordPrettyPrinter.printNodePath({ survey, record, node }))\n}\n\nexport const RecordPrettyPrinter = {\n print,\n printNodePath,\n printNodesPaths,\n}\n"]}
1
+ {"version":3,"file":"recordPrettyPrinter.js","sourceRoot":"","sources":["../../src/record/recordPrettyPrinter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sCAAsD;AACtD,kCAAoE;AACpE,wCAAqC;AACrC,sCAA2C;AAC3C,oCAAkC;AAElC,MAAY,aAAa,qDAAgC;AASzD,MAAM,mBAAmB,GAAiB;IACxC,iBAAiB,EAAE,KAAK;IACxB,iBAAiB,EAAE,KAAK;IACxB,eAAe,EAAE,KAAK;IACtB,cAAc,EAAE,KAAK;CACtB,CAAA;AAED,MAAM,KAAK,GAAG,CAAC,MAAuE,EAAU,EAAE;IAChG,MAAM,EAA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C,OAAO,CAAC,CAAA;YACpC,IAAI,kBAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;gBACjC,MAAM,KAAK,GAAG,aAAa,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;gBACvE,IAAI,GAAG,GAAG,IAAI,IAAI,KAAK,GAAG,CAAA;YAC5B,CAAC;YACD,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACrB,CAAC;KACF,CAAC,CAAC,MAAM,CAAC,CAAA;IACV,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,MAIxB,EAAY,EAAE;IACb,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAA,mBAAmB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AACxG,CAAC,CAAA;AAEY,QAAA,mBAAmB,GAAG;IACjC,KAAK;IACL,aAAa;IACb,eAAe;CAChB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../common'\nimport { ArenaRecordNode, NodeValueFormatter, Nodes } from '../node'\nimport { NodeDefs } from '../nodeDef'\nimport { Survey, Surveys } from '../survey'\nimport { Strings } from '../utils'\nimport { ArenaRecord } from './record'\nimport * as RecordGetters from './_records/recordGetters'\n\ntype PrintOptions = {\n includeEmptyNodes?: boolean\n showNotApplicable?: boolean\n showNotEditable?: boolean\n showNotVisible?: boolean\n}\n\nconst DefaultPrintOptions: PrintOptions = {\n includeEmptyNodes: false,\n showNotApplicable: false,\n showNotEditable: false,\n showNotVisible: false,\n}\n\nconst print = (params: { survey: Survey; record: ArenaRecord; options?: PrintOptions }): string => {\n const { survey, record, options = DefaultPrintOptions } = params\n const { includeEmptyNodes, showNotApplicable, showNotEditable, showNotVisible } = options\n\n const cycle = RecordGetters.getCycle(record)\n const rootNode = RecordGetters.getRoot(record)\n if (!rootNode) {\n return ''\n }\n\n const getInfoParts = (params: { parentNode?: ArenaRecordNode | null; childDefUuid: string }): string[] => {\n const { parentNode, childDefUuid } = params\n if (!parentNode) {\n return []\n }\n const infoParts: string[] = []\n if (showNotApplicable && !Nodes.isChildApplicable(parentNode, childDefUuid)) {\n infoParts.push('not applicable')\n }\n if (showNotEditable && !Nodes.isChildEditable(parentNode, childDefUuid)) {\n infoParts.push('not editable')\n }\n if (showNotVisible && !Nodes.isChildVisible(parentNode, childDefUuid)) {\n infoParts.push('not visible')\n }\n return infoParts\n }\n\n const toPart = (params: { depth: number; name: string; value: string; infoParts?: string[] }): string => {\n const { depth, name, value, infoParts = [] } = params\n const indentation = Strings.repeat(' ', depth)\n let part = `${indentation}${name}: ${value}`\n if (infoParts.length > 0) {\n part += ` (${infoParts.join(', ')})`\n }\n return part\n }\n\n const parts: string[] = []\n\n if (includeEmptyNodes) {\n const printNodeAndChildren = (params: { node: ArenaRecordNode; parentNode: ArenaRecordNode | null }): void => {\n const { node, parentNode } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const value = NodeValueFormatter.format({ survey, cycle, nodeDef, node, value: node.value })\n const depth = Nodes.getHierarchy(node).length\n const infoParts = getInfoParts({ parentNode, childDefUuid: node.nodeDefUuid })\n parts.push(toPart({ depth, name: NodeDefs.getName(nodeDef), value, infoParts }))\n\n const childDefs = Surveys.getNodeDefChildrenSorted({ survey, nodeDef, cycle })\n childDefs.forEach((childDef) => {\n const children = RecordGetters.getChildren({ parentNode: node, childDefUuid: childDef.uuid })(record)\n if (children.length === 0) {\n const childInfoParts = getInfoParts({ parentNode: node, childDefUuid: childDef.uuid })\n parts.push(\n toPart({\n depth: depth + 1,\n name: NodeDefs.getName(childDef),\n value: '<empty>',\n infoParts: childInfoParts,\n })\n )\n return\n }\n children.forEach((child) => printNodeAndChildren({ node: child, parentNode: node }))\n })\n }\n\n printNodeAndChildren({ node: rootNode, parentNode: null })\n return parts.join('\\n')\n }\n\n RecordGetters.visitDescendantsAndSelf({\n node: rootNode,\n visitor: (node) => {\n const { nodeDefUuid } = node\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const value = NodeValueFormatter.format({ survey, cycle, nodeDef, node, value: node.value })\n const depth = Nodes.getHierarchy(node).length\n const parentNode = NodeDefs.isRoot(nodeDef) ? null : RecordGetters.getParent({ node })(record)\n const infoParts = getInfoParts({ parentNode, childDefUuid: nodeDefUuid })\n parts.push(toPart({ depth, name: NodeDefs.getName(nodeDef), value, infoParts }))\n return false\n },\n traverseMethod: TraverseMethod.dfs,\n })(record)\n return parts.join('\\n')\n}\n\nconst printNodePath = (params: { survey: Survey; record: ArenaRecord; node: ArenaRecordNode }): string => {\n const { survey, record, node } = params\n const parts: string[] = []\n RecordGetters.visitAncestorsAndSelf({\n node,\n visitor: (visitedNode) => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: visitedNode.nodeDefUuid })\n let part = NodeDefs.getName(nodeDef)\n if (NodeDefs.isMultiple(nodeDef)) {\n const index = RecordGetters.getNodeIndex({ node: visitedNode })(record)\n part = `${part}[${index}]`\n }\n parts.unshift(part)\n },\n })(record)\n return parts.join('.')\n}\n\nconst printNodesPaths = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: Dictionary<ArenaRecordNode>\n}): string[] => {\n const { survey, record, nodes } = params\n return Object.values(nodes).map((node) => RecordPrettyPrinter.printNodePath({ survey, record, node }))\n}\n\nexport const RecordPrettyPrinter = {\n print,\n printNodePath,\n printNodesPaths,\n}\n"]}
@@ -28,7 +28,7 @@ const getDependentValidationNodePointers = (params) => {
28
28
  const uniquePointersByKey = new Map();
29
29
  for (const node of Object.values(nodes)) {
30
30
  for (const dependencyType of validationDependencyTypes) {
31
- const nodePointers = records_1.Records.getDependentNodePointers({ survey, record, node, dependencyType });
31
+ const nodePointers = records_1.Records.getDependentNodePointers({ survey, node, dependencyType })(record);
32
32
  for (const pointer of nodePointers) {
33
33
  const nodeCtxUuid = pointer.nodeCtx.uuid;
34
34
  const nodeDefUuid = pointer.nodeDef.uuid;
@@ -82,7 +82,7 @@ const createRootEntity = (params) => __awaiter(void 0, void 0, void 0, function*
82
82
  });
83
83
  const updateAttributeValue = (params) => __awaiter(void 0, void 0, void 0, function* () {
84
84
  const { attributeUuid, record, value, dateModified = utils_1.Dates.nowFormattedForStorage(), sideEffect = false } = params;
85
- const attribute = records_1.Records.getNodeByUuid(attributeUuid)(record);
85
+ const attribute = records_1.Records.getNodeByUuid({ uuid: attributeUuid })(record);
86
86
  if (!attribute)
87
87
  throw new error_1.SystemError('record.nodeNotFound');
88
88
  let attributeUpdated = sideEffect ? attribute : Object.assign({}, attribute);
@@ -1 +1 @@
1
- {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAsC;AAEtC,sCAAiE;AACjE,oCAAyC;AACzC,2DAAuD;AACvD,iDAA6C;AAE7C,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,6BAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC1D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,cAAc,IAAI,yBAAyB,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,MAAM,KAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;AAC1F,CAAC,CAAA,CAAA;AAED,MAAM,WAAW,GAAG,CAClB,MAEC,EAC4B,EAAE;IAC/B,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEjE,MAAM,YAAY,GAAG,iBAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;IAC7F,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, record, node, dependencyType })\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid(attributeUuid)(record)\n if (!attribute) throw new SystemError('record.nodeNotFound')\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
1
+ {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAsC;AAEtC,sCAAiE;AACjE,oCAAyC;AACzC,2DAAuD;AACvD,iDAA6C;AAE7C,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,6BAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC1D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,cAAc,IAAI,yBAAyB,EAAE,CAAC;YACvD,MAAM,YAAY,GAAG,iBAAO,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;YAC/F,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;gBACnC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;gBACxC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;gBACxC,MAA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AAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAAM,MAAM,KAAE,MAAM,EAAE,KAAK,EAAE,YAAY,IAAG,CAAA;IAC7F,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,iBAAiB;IACjB,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers({ survey, node, dependencyType })(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst _createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.createNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> =>\n _createNodeAndDescendants(params)\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return _createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid({ uuid: attributeUuid })(record)\n if (!attribute) throw new SystemError('record.nodeNotFound')\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.deleteNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n createDescendants,\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n deleteNode,\n deleteNodes,\n}\n"]}
@@ -25,7 +25,7 @@ const _getKeyValuesByDefUuid = (params) => {
25
25
  const { survey, record, entity, keyDefs, cache } = params;
26
26
  let keyValues = cache === null || cache === void 0 ? void 0 : cache.keyValuesByEntityUuid.get(entity.uuid);
27
27
  if (!keyValues) {
28
- keyValues = records_1.Records.getEntityKeyValuesByDefUuid({ survey, record, entity, keyDefs });
28
+ keyValues = records_1.Records.getEntityKeyValuesByDefUuid({ survey, entity, keyDefs })(record);
29
29
  cache === null || cache === void 0 ? void 0 : cache.keyValuesByEntityUuid.set(entity.uuid, keyValues);
30
30
  }
31
31
  return keyValues;
@@ -33,10 +33,10 @@ const _getKeyValuesByDefUuid = (params) => {
33
33
  const _isEntityDuplicate = (params) => {
34
34
  const { survey, entity, record, entityKeysCache: cache } = params;
35
35
  // 1. get sibling entities
36
- const nodeParent = records_1.Records.getParent(entity)(record);
36
+ const nodeParent = records_1.Records.getParent({ node: entity })(record);
37
37
  if (!nodeParent)
38
38
  return false;
39
- const siblingEntities = records_1.Records.getChildren(nodeParent, entity.nodeDefUuid)(record).filter((node) => !node_1.Nodes.areEqual(entity, node));
39
+ const siblingEntities = records_1.Records.getChildren({ parentNode: nodeParent, childDefUuid: entity.nodeDefUuid })(record).filter((node) => !node_1.Nodes.areEqual(entity, node));
40
40
  // 2. get key values
41
41
  const entityDef = survey_1.Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid });
42
42
  const keyDefs = _getKeyDefs({ survey, entityDef, cache });
@@ -76,7 +76,7 @@ const isNodeDefToBeValidated = (params) => {
76
76
  const validateAttributeKey = (params) => (_propName, node) => {
77
77
  const { survey, nodeDef, record, entityKeysCache } = params;
78
78
  if (isNodeDefToBeValidated({ survey, nodeDef })) {
79
- const entity = records_1.Records.getParent(node)(record);
79
+ const entity = records_1.Records.getParent({ node })(record);
80
80
  if (entity && _isEntityDuplicate({ survey, record, entity, entityKeysCache })) {
81
81
  return Promise.resolve(validation_1.ValidationResultFactory.createInstance({
82
82
  valid: false,
@@ -1 +1 @@
1
- {"version":3,"file":"attributeKeyValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeKeyValidator.ts"],"names":[],"mappings":";;;AACA,wCAAoC;AACpC,2CAA4E;AAC5E,qCAA+D;AAC/D,iDAAgG;AAChG,yCAA8C;AAG9C,uCAAqC;AAW9B,MAAM,qBAAqB,GAAG,GAAoB,EAAE,CAAC,CAAC;IAC3D,sBAAsB,EAAE,IAAI,GAAG,EAAE;IACjC,qBAAqB,EAAE,IAAI,GAAG,EAAE;CACjC,CAAC,CAAA;AAHW,QAAA,qBAAqB,GAArB,qBAAqB,CAGhC;AAEF,MAAM,WAAW,GAAG,CAAC,MAIpB,EAAwC,EAAE;IACzC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IAC3C,IAAI,OAAO,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAC/D,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,GAAG,gBAAO,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;QAChE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,sBAAsB,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC5D,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,sBAAsB,GAAG,CAAC,MAM/B,EAAmB,EAAE;IACpB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACzD,IAAI,SAAS,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,qBAAqB,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC7D,IAAI,CAAC,SAAS,EAAE,CAA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M,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,CAAA;IAE3D,IAAI,sBAAsB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;QAChD,MAAM,MAAM,GAAG,iBAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;QAC9C,IAAI,MAAM,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;YAC9E,OAAO,OAAO,CAAC,OAAO,CACpB,oCAAuB,CAAC,cAAc,CAAC;gBACrC,KAAK,EAAE,KAAK;gBACZ,QAAQ,EAAE,+BAAkB,CAAC,KAAK;gBAClC,GAAG,EAAE,4BAA4B;aAClC,CAAC,CACH,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,oCAAuB,CAAC,cAAc,EAAE,CAAC,CAAA;AAClE,CAAC,CAAA;AAEU,QAAA,qBAAqB,GAAG;IACnC,oBAAoB;CACrB,CAAA","sourcesContent":["import { ArenaRecord } from '../record'\nimport { Records } from '../records'\nimport { NodeDef, NodeDefs, NodeDefProps, NodeDefType } from '../../nodeDef'\nimport { ArenaRecordNode, Nodes, NodeValues } from '../../node'\nimport { ValidationResult, ValidationResultFactory, ValidationSeverity } from '../../validation'\nimport { Survey, Surveys } from '../../survey'\n\nimport { Dictionary } from '../../common'\nimport { Objects } from '../../utils'\n\n/**\n * Cache of entity key values (and key defs by entity def) used during a single validation run (the record doesn't change):\n * without it, validating the keys of S sibling entities would compute the key values of every sibling S times.\n */\nexport type EntityKeysCache = {\n keyDefsByEntityDefUuid: Map<string, NodeDef<NodeDefType, NodeDefProps>[]>\n keyValuesByEntityUuid: Map<string, Dictionary<any>>\n}\n\nexport const createEntityKeysCache = (): EntityKeysCache => ({\n keyDefsByEntityDefUuid: new Map(),\n keyValuesByEntityUuid: new Map(),\n})\n\nconst _getKeyDefs = (params: {\n survey: Survey\n entityDef: NodeDef<NodeDefType, NodeDefProps>\n cache?: EntityKeysCache\n}): NodeDef<NodeDefType, NodeDefProps>[] => {\n const { survey, entityDef, cache } = params\n let keyDefs = cache?.keyDefsByEntityDefUuid.get(entityDef.uuid)\n if (!keyDefs) {\n keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: entityDef })\n cache?.keyDefsByEntityDefUuid.set(entityDef.uuid, keyDefs)\n }\n return keyDefs\n}\n\nconst _getKeyValuesByDefUuid = (params: {\n survey: Survey\n record: ArenaRecord\n entity: ArenaRecordNode\n keyDefs: NodeDef<NodeDefType, NodeDefProps>[]\n cache?: EntityKeysCache\n}): Dictionary<any> => {\n const { survey, record, entity, keyDefs, cache } = params\n let keyValues = cache?.keyValuesByEntityUuid.get(entity.uuid)\n if (!keyValues) {\n keyValues = Records.getEntityKeyValuesByDefUuid({ survey, record, entity, keyDefs })\n cache?.keyValuesByEntityUuid.set(entity.uuid, keyValues)\n }\n return keyValues\n}\n\nconst _isEntityDuplicate = (params: {\n survey: Survey\n record: ArenaRecord\n entity: ArenaRecordNode\n entityKeysCache?: EntityKeysCache\n}): boolean => {\n const { survey, entity, record, entityKeysCache: cache } = params\n // 1. get sibling entities\n const nodeParent = Records.getParent(entity)(record)\n if (!nodeParent) return false\n\n const siblingEntities = Records.getChildren(\n nodeParent,\n entity.nodeDefUuid\n )(record).filter((node) => !Nodes.areEqual(entity, node))\n\n // 2. get key values\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const keyDefs = _getKeyDefs({ survey, entityDef, cache })\n\n if (Objects.isEmpty(siblingEntities) || Objects.isEmpty(keyDefs)) {\n return false\n }\n const keyValuesByDefUuid = _getKeyValuesByDefUuid({ survey, record, entity, keyDefs, cache })\n return (\n !Objects.isEmpty(keyValuesByDefUuid) &&\n siblingEntities.some((sibilingEntity) => {\n const siblingKeyValuesByDefUuid = _getKeyValuesByDefUuid({\n survey,\n record,\n entity: sibilingEntity,\n keyDefs,\n cache,\n })\n return keyDefs.every((keyDef) => {\n const keyValue = keyValuesByDefUuid[keyDef.uuid]\n const siblingKeyValue = siblingKeyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: siblingKeyValue,\n })\n })\n })\n )\n}\n\nconst isNodeDefToBeValidated = (params: { survey: Survey; nodeDef: NodeDef<NodeDefType, NodeDefProps> }): boolean => {\n const { survey, nodeDef } = params\n if (!NodeDefs.isKey(nodeDef)) return false\n\n const nodeDefParent = Surveys.getNodeDefParent({ survey, nodeDef })\n // root entity key attributes will be validated by another validator\n return !!nodeDefParent && !NodeDefs.isRoot(nodeDefParent)\n}\n\nconst validateAttributeKey =\n (params: {\n survey: Survey\n record: ArenaRecord\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n entityKeysCache?: EntityKeysCache\n }) =>\n (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { survey, nodeDef, record, entityKeysCache } = params\n\n if (isNodeDefToBeValidated({ survey, nodeDef })) {\n const entity = Records.getParent(node)(record)\n if (entity && _isEntityDuplicate({ survey, record, entity, entityKeysCache })) {\n return Promise.resolve(\n ValidationResultFactory.createInstance({\n valid: false,\n severity: ValidationSeverity.error,\n key: 'record.entity.keyDuplicate',\n })\n )\n }\n }\n\n return Promise.resolve(ValidationResultFactory.createInstance())\n }\n\nexport const AttributeKeyValidator = {\n validateAttributeKey,\n}\n"]}
1
+ {"version":3,"file":"attributeKeyValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeKeyValidator.ts"],"names":[],"mappings":";;;AACA,wCAAoC;AACpC,2CAA4E;AAC5E,qCAA+D;AAC/D,iDAAgG;AAChG,yCAA8C;AAG9C,uCAAqC;AAW9B,MAAM,qBAAqB,GAAG,GAAoB,EAAE,CAAC,CAAC;IAC3D,sBAAsB,EAAE,IAAI,GAAG,EAAE;IACjC,qBAAqB,EAAE,IAA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MAAM,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC,EAAE,CAAC;YAC9E,OAAO,OAAO,CAAC,OAAO,CACpB,oCAAuB,CAAC,cAAc,CAAC;gBACrC,KAAK,EAAE,KAAK;gBACZ,QAAQ,EAAE,+BAAkB,CAAC,KAAK;gBAClC,GAAG,EAAE,4BAA4B;aAClC,CAAC,CACH,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,oCAAuB,CAAC,cAAc,EAAE,CAAC,CAAA;AAClE,CAAC,CAAA;AAEU,QAAA,qBAAqB,GAAG;IACnC,oBAAoB;CACrB,CAAA","sourcesContent":["import { ArenaRecord } from '../record'\nimport { Records } from '../records'\nimport { NodeDef, NodeDefs, NodeDefProps, NodeDefType } from '../../nodeDef'\nimport { ArenaRecordNode, Nodes, NodeValues } from '../../node'\nimport { ValidationResult, ValidationResultFactory, ValidationSeverity } from '../../validation'\nimport { Survey, Surveys } from '../../survey'\n\nimport { Dictionary } from '../../common'\nimport { Objects } from '../../utils'\n\n/**\n * Cache of entity key values (and key defs by entity def) used during a single validation run (the record doesn't change):\n * without it, validating the keys of S sibling entities would compute the key values of every sibling S times.\n */\nexport type EntityKeysCache = {\n keyDefsByEntityDefUuid: Map<string, NodeDef<NodeDefType, NodeDefProps>[]>\n keyValuesByEntityUuid: Map<string, Dictionary<any>>\n}\n\nexport const createEntityKeysCache = (): EntityKeysCache => ({\n keyDefsByEntityDefUuid: new Map(),\n keyValuesByEntityUuid: new Map(),\n})\n\nconst _getKeyDefs = (params: {\n survey: Survey\n entityDef: NodeDef<NodeDefType, NodeDefProps>\n cache?: EntityKeysCache\n}): NodeDef<NodeDefType, NodeDefProps>[] => {\n const { survey, entityDef, cache } = params\n let keyDefs = cache?.keyDefsByEntityDefUuid.get(entityDef.uuid)\n if (!keyDefs) {\n keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: entityDef })\n cache?.keyDefsByEntityDefUuid.set(entityDef.uuid, keyDefs)\n }\n return keyDefs\n}\n\nconst _getKeyValuesByDefUuid = (params: {\n survey: Survey\n record: ArenaRecord\n entity: ArenaRecordNode\n keyDefs: NodeDef<NodeDefType, NodeDefProps>[]\n cache?: EntityKeysCache\n}): Dictionary<any> => {\n const { survey, record, entity, keyDefs, cache } = params\n let keyValues = cache?.keyValuesByEntityUuid.get(entity.uuid)\n if (!keyValues) {\n keyValues = Records.getEntityKeyValuesByDefUuid({ survey, entity, keyDefs })(record)\n cache?.keyValuesByEntityUuid.set(entity.uuid, keyValues)\n }\n return keyValues\n}\n\nconst _isEntityDuplicate = (params: {\n survey: Survey\n record: ArenaRecord\n entity: ArenaRecordNode\n entityKeysCache?: EntityKeysCache\n}): boolean => {\n const { survey, entity, record, entityKeysCache: cache } = params\n // 1. get sibling entities\n const nodeParent = Records.getParent({ node: entity })(record)\n if (!nodeParent) return false\n\n const siblingEntities = Records.getChildren({ parentNode: nodeParent, childDefUuid: entity.nodeDefUuid })(\n record\n ).filter((node) => !Nodes.areEqual(entity, node))\n\n // 2. get key values\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const keyDefs = _getKeyDefs({ survey, entityDef, cache })\n\n if (Objects.isEmpty(siblingEntities) || Objects.isEmpty(keyDefs)) {\n return false\n }\n const keyValuesByDefUuid = _getKeyValuesByDefUuid({ survey, record, entity, keyDefs, cache })\n return (\n !Objects.isEmpty(keyValuesByDefUuid) &&\n siblingEntities.some((sibilingEntity) => {\n const siblingKeyValuesByDefUuid = _getKeyValuesByDefUuid({\n survey,\n record,\n entity: sibilingEntity,\n keyDefs,\n cache,\n })\n return keyDefs.every((keyDef) => {\n const keyValue = keyValuesByDefUuid[keyDef.uuid]\n const siblingKeyValue = siblingKeyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: siblingKeyValue,\n })\n })\n })\n )\n}\n\nconst isNodeDefToBeValidated = (params: { survey: Survey; nodeDef: NodeDef<NodeDefType, NodeDefProps> }): boolean => {\n const { survey, nodeDef } = params\n if (!NodeDefs.isKey(nodeDef)) return false\n\n const nodeDefParent = Surveys.getNodeDefParent({ survey, nodeDef })\n // root entity key attributes will be validated by another validator\n return !!nodeDefParent && !NodeDefs.isRoot(nodeDefParent)\n}\n\nconst validateAttributeKey =\n (params: {\n survey: Survey\n record: ArenaRecord\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n entityKeysCache?: EntityKeysCache\n }) =>\n (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { survey, nodeDef, record, entityKeysCache } = params\n\n if (isNodeDefToBeValidated({ survey, nodeDef })) {\n const entity = Records.getParent({ node })(record)\n if (entity && _isEntityDuplicate({ survey, record, entity, entityKeysCache })) {\n return Promise.resolve(\n ValidationResultFactory.createInstance({\n valid: false,\n severity: ValidationSeverity.error,\n key: 'record.entity.keyDuplicate',\n })\n )\n }\n }\n\n return Promise.resolve(ValidationResultFactory.createInstance())\n }\n\nexport const AttributeKeyValidator = {\n validateAttributeKey,\n}\n"]}
@@ -11,7 +11,7 @@ const _isAttributeDuplicate = (params) => {
11
11
  // blank values are never considered duplicates
12
12
  if (node_1.Nodes.isValueBlank(attribute))
13
13
  return false;
14
- const nodeSiblings = records_1.Records.getAttributeSiblings({ record, node: attribute, nodeDef });
14
+ const nodeSiblings = records_1.Records.getAttributeSiblings({ node: attribute, nodeDef })(record);
15
15
  return nodeSiblings.some((sibling) => node_1.NodeValues.isValueEqual({ survey, nodeDef, value: sibling.value, valueSearch: attribute.value }));
16
16
  };
17
17
  const isNodeDefToBeValidated = (params) => {
@@ -1 +1 @@
1
- {"version":3,"file":"attributeUniqueValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeUniqueValidator.ts"],"names":[],"mappings":";;;AAAA,qCAA+D;AAC/D,2CAA4E;AAC5E,yCAA8C;AAC9C,iDAAgG;AAE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ACtE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAE1C,IACE,sBAAsB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QAC3C,qBAAqB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EACnE,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CACpB,oCAAuB,CAAC,cAAc,CAAC;YACrC,KAAK,EAAE,KAAK;YACZ,QAAQ,EAAE,+BAAkB,CAAC,KAAK;YAClC,GAAG,EAAE,kCAAkC;SACxC,CAAC,CACH,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAC,OAAO,CAAC,oCAAuB,CAAC,cAAc,EAAE,CAAC,CAAA;AAClE,CAAC,CAAA;AAnBU,QAAA,uBAAuB,GAAvB,uBAAuB,CAmBjC;AAEU,QAAA,wBAAwB,GAAG;IACtC,uBAAuB,EAAvB,QAAA,uBAAuB;CACxB,CAAA","sourcesContent":["import { ArenaRecordNode, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { Survey, Surveys } from '../../survey'\nimport { ValidationResult, ValidationResultFactory, ValidationSeverity } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\nconst _isAttributeDuplicate = (params: {\n survey: Survey\n record: ArenaRecord\n attribute: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n}): boolean => {\n const { survey, attribute, record, nodeDef } = params\n // blank values are never considered duplicates\n if (Nodes.isValueBlank(attribute)) return false\n const nodeSiblings = Records.getAttributeSiblings({ record, node: attribute, nodeDef })\n return nodeSiblings.some((sibling) =>\n NodeValues.isValueEqual({ survey, nodeDef, value: sibling.value, valueSearch: attribute.value })\n )\n}\n\nconst isNodeDefToBeValidated = (params: { survey: Survey; nodeDef: NodeDef<NodeDefType, NodeDefProps> }): boolean => {\n const { survey, nodeDef } = params\n const nodeDefValidations = NodeDefs.getValidations(nodeDef)\n if (!nodeDefValidations?.unique) return false\n\n const nodeDefParent = Surveys.getNodeDefParent({ survey, nodeDef })\n if (!nodeDefParent || NodeDefs.isRoot(nodeDefParent)) {\n // uniqueness at record level evaluated elsewhere\n return false\n }\n return true\n}\n\nexport const validateAttributeUnique =\n (params: { survey: Survey; record: ArenaRecord; nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { survey, record, nodeDef } = params\n\n if (\n isNodeDefToBeValidated({ survey, nodeDef }) &&\n _isAttributeDuplicate({ survey, record, attribute: node, nodeDef })\n ) {\n return Promise.resolve(\n ValidationResultFactory.createInstance({\n valid: false,\n severity: ValidationSeverity.error,\n key: 'record.attribute.uniqueDuplicate',\n })\n )\n }\n\n return Promise.resolve(ValidationResultFactory.createInstance())\n }\n\nexport const AttributeUniqueValidator = {\n validateAttributeUnique,\n}\n"]}
1
+ {"version":3,"file":"attributeUniqueValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeUniqueValidator.ts"],"names":[],"mappings":";;;AAAA,qCAA+D;AAC/D,2CAA4E;AAC5E,yCAA8C;AAC9C,iDAAgG;AAEhG,wCAAoC;AAEpC,MAAM,qBAAqB,GAAG,CAAC,MAK9B,EAAW,EAAE;IACZ,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IACrD,+CAA+C;IAC/C,IAAI,YAAK,CAAC,YAAY,CAAC,SAAS,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/C,MAAM,YAAY,GAAG,iBAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAA;IACvF,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CACnC,iBAAU,CAAC,YAAY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,CAAC,OAAO,CAAC,oCAAuB,CAAC,cAAc,EAAE,CAAC,CAAA;AAClE,CAAC,CAAA;AAnBU,QAAA,uBAAuB,GAAvB,uBAAuB,CAmBjC;AAEU,QAAA,wBAAwB,GAAG;IACtC,uBAAuB,EAAvB,QAAA,uBAAuB;CACxB,CAAA","sourcesContent":["import { ArenaRecordNode, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { Survey, Surveys } from '../../survey'\nimport { ValidationResult, ValidationResultFactory, ValidationSeverity } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\nconst _isAttributeDuplicate = (params: {\n survey: Survey\n record: ArenaRecord\n attribute: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n}): boolean => {\n const { survey, attribute, record, nodeDef } = params\n // blank values are never considered duplicates\n if (Nodes.isValueBlank(attribute)) return false\n const nodeSiblings = Records.getAttributeSiblings({ node: attribute, nodeDef })(record)\n return nodeSiblings.some((sibling) =>\n NodeValues.isValueEqual({ survey, nodeDef, value: sibling.value, valueSearch: attribute.value })\n )\n}\n\nconst isNodeDefToBeValidated = (params: { survey: Survey; nodeDef: NodeDef<NodeDefType, NodeDefProps> }): boolean => {\n const { survey, nodeDef } = params\n const nodeDefValidations = NodeDefs.getValidations(nodeDef)\n if (!nodeDefValidations?.unique) return false\n\n const nodeDefParent = Surveys.getNodeDefParent({ survey, nodeDef })\n if (!nodeDefParent || NodeDefs.isRoot(nodeDefParent)) {\n // uniqueness at record level evaluated elsewhere\n return false\n }\n return true\n}\n\nexport const validateAttributeUnique =\n (params: { survey: Survey; record: ArenaRecord; nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { survey, record, nodeDef } = params\n\n if (\n isNodeDefToBeValidated({ survey, nodeDef }) &&\n _isAttributeDuplicate({ survey, record, attribute: node, nodeDef })\n ) {\n return Promise.resolve(\n ValidationResultFactory.createInstance({\n valid: false,\n severity: ValidationSeverity.error,\n key: 'record.attribute.uniqueDuplicate',\n })\n )\n }\n\n return Promise.resolve(ValidationResultFactory.createInstance())\n }\n\nexport const AttributeUniqueValidator = {\n validateAttributeUnique,\n}\n"]}
@@ -32,23 +32,22 @@ const _getSiblingNodeKeys = (params) => {
32
32
  return [];
33
33
  }
34
34
  const ancestorMultipleEntity = records_1.Records.getAncestor({
35
- record,
36
35
  node: attribute,
37
36
  ancestorDefUuid: ancestorMultipleEntityDef.uuid,
38
- });
37
+ })(record);
39
38
  if (!ancestorMultipleEntity)
40
39
  return [];
41
- const ancestorMultipleEntityParent = records_1.Records.getParent(ancestorMultipleEntity)(record);
40
+ const ancestorMultipleEntityParent = records_1.Records.getParent({ node: ancestorMultipleEntity })(record);
42
41
  if (!ancestorMultipleEntityParent)
43
42
  return [];
44
43
  const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`;
45
44
  let items = siblingKeyNodesCache === null || siblingKeyNodesCache === void 0 ? void 0 : siblingKeyNodesCache.get(cacheKey);
46
45
  if (!items) {
47
46
  const keyDefs = survey_1.Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef });
48
- const entities = records_1.Records.getEntitySiblings({ record, entity: ancestorMultipleEntity, includeSelf: true });
47
+ const entities = records_1.Records.getEntitySiblings({ entity: ancestorMultipleEntity, includeSelf: true })(record);
49
48
  items = [];
50
49
  for (const entity of entities) {
51
- const keyNodes = records_1.Records.getEntityKeyNodes({ survey, record, entity, keyDefs });
50
+ const keyNodes = records_1.Records.getEntityKeyNodes({ survey, entity, keyDefs })(record);
52
51
  for (const keyNode of keyNodes) {
53
52
  if (!keyNode)
54
53
  continue;
@@ -124,7 +123,7 @@ const _validateNodeValidations = (params) => (_propName, node) => __awaiter(void
124
123
  });
125
124
  const validateAttribute = (params) => __awaiter(void 0, void 0, void 0, function* () {
126
125
  const { survey, record, attribute } = params;
127
- if (records_1.Records.isNodeApplicable({ record, node: attribute })) {
126
+ if (records_1.Records.isNodeApplicable({ node: attribute })(record)) {
128
127
  const nodeDef = survey_1.Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid });
129
128
  const validatorParams = Object.assign(Object.assign({}, params), { nodeDef });
130
129
  return new validation_1.Validator().validate(attribute, {
@@ -176,15 +175,14 @@ const findSortedNodesToValidate = (params) => {
176
175
  // Get dependents and attribute itself
177
176
  const nodePointersAttributeAndDependents = records_1.Records.getDependentNodePointers({
178
177
  survey,
179
- record,
180
178
  node,
181
179
  dependencyType: survey_2.SurveyDependencyType.validations,
182
180
  includeSelf: true,
183
- });
184
- const nodeParent = records_1.Records.getParent(node)(record);
181
+ })(record);
182
+ const nodeParent = records_1.Records.getParent({ node })(record);
185
183
  result.push(...nodePointers_1.NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }), ...findSiblingKeyNodesToValidate(Object.assign(Object.assign({}, params), { nodeDef, nodeParent, attribute: node, siblingKeyNodesCache })));
186
184
  if ((_a = nodeDef_1.NodeDefs.getValidations(nodeDef)) === null || _a === void 0 ? void 0 : _a.unique) {
187
- result.push(...records_1.Records.getAttributeSiblings({ record, node, nodeDef }));
185
+ result.push(...records_1.Records.getAttributeSiblings({ node, nodeDef })(record));
188
186
  }
189
187
  }
190
188
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAyE;AACzE,2CAA+F;AAG/F,yCAA8C;AAC9C,gDAA0D;AAC1D,uCAAqC;AACrC,iDAMyB;AAEzB,kDAA8C;AAE9C,4EAAwE;AACxE,wCAAoC;AACpC,4DAAwD;AACxD,mEAAuG;AACvG,qEAAiE;AACjE,yEAAqE;AAErE,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AA6B3D,MAAM,mBAAmB,GA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E,SAAS,EAAE,IAAI,EAAE,oBAAoB,IAAG,CAC5G,CAAA;QAED,IAAI,MAAA,kBAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,0CAAE,MAAM,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,GAAG,iBAAO,CAAC,oBAAoB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,wCAAwC,GAAG,CAC/C,MAAuC,EACZ,EAAE;IAC7B,MAAM,eAAe,GAAsB,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAC5E,MAAM,qBAAqB,GAAqB,EAAE,CAAA;IAClD,6EAA6E;IAC7E,MAAM,eAAe,GAAG,IAAA,6CAAqB,GAAE,CAAA;IAE/C,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAEY,QAAA,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodeItem[]>\n\nconst _getSiblingNodeKeys = (\n params: AttributeValidatorParams & { siblingKeyNodesCache?: SiblingKeyNodesCache }\n): SiblingKeyNodeItem[] => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) {\n return []\n }\n const ancestorMultipleEntity = Records.getAncestor({\n record,\n node: attribute,\n ancestorDefUuid: ancestorMultipleEntityDef.uuid,\n })\n if (!ancestorMultipleEntity) return []\n\n const ancestorMultipleEntityParent = Records.getParent(ancestorMultipleEntity)(record)\n if (!ancestorMultipleEntityParent) return []\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let items = siblingKeyNodesCache?.get(cacheKey)\n if (!items) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings({ record, entity: ancestorMultipleEntity, includeSelf: true })\n items = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes({ survey, record, entity, keyDefs })\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n siblingKeyNodesCache?.set(cacheKey, items)\n }\n return items.filter((item) => item.entityUuid !== ancestorMultipleEntity.uuid)\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _validateRequired =\n (params: { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n (_field: string, node: any): Promise<ValidationResult> => {\n const { nodeDef } = params\n const valid = (!NodeDefs.isKey(nodeDef) && !NodeDefs.isRequired(nodeDef)) || !Nodes.isValueBlank(node)\n return Promise.resolve(\n valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n )\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: { user: User; survey: Survey; record: ArenaRecord; nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable({ record, node: attribute })) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired({ nodeDef }),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache?: SiblingKeyNodesCache\n }\n) => {\n const { survey, nodeDef, nodeParent: parentNode, attribute } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeys = _getSiblingNodeKeys(params)\n const siblingNodeKeysWithSameValue: ArenaRecordNode[] = []\n const siblingNodeKeysWithErrors: ArenaRecordNode[] = []\n siblingNodeKeys.forEach(({ keyNode, hasErrors }) => {\n if (NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })) {\n siblingNodeKeysWithSameValue.push(keyNode)\n }\n if (hasErrors) {\n siblingNodeKeysWithErrors.push(keyNode)\n }\n })\n return [...siblingNodeKeysWithSameValue, ...siblingNodeKeysWithErrors]\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result = []\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = Records.getDependentNodePointers({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.validations,\n includeSelf: true,\n })\n\n const nodeParent = Records.getParent(node)(record)\n\n result.push(\n ...NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }),\n ...findSiblingKeyNodesToValidate({ ...params, nodeDef, nodeParent, attribute: node, siblingKeyNodesCache })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n result.push(...Records.getAttributeSiblings({ record, node, nodeDef }))\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
1
+ {"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAyE;AACzE,2CAA+F;AAG/F,yCAA8C;AAC9C,gDAA0D;AAC1D,uCAAqC;AACrC,iDAMyB;AAEzB,kDAA8C;AAE9C,4EAAwE;AACxE,wCAAoC;AACpC,4DAAwD;AACxD,mEAAuG;AACvG,qEAAiE;AACjE,yEAAqE;AAErE,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AA6B3D,MAAM,mBAAmB,GAAG,CAC1B,MAAkF,EAC5D,EAAE;IACxB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAA;IAElE,MAAM,YAAY,GAAG,gBAAO,CAAC,gBAAgB,CAAC,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AO,CAAC,0CAAE,MAAM,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,GAAG,iBAAO,CAAC,oBAAoB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QACzE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,wCAAwC,GAAG,CAC/C,MAAuC,EACZ,EAAE;IAC7B,MAAM,eAAe,GAAsB,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAC5E,MAAM,qBAAqB,GAAqB,EAAE,CAAA;IAClD,6EAA6E;IAC7E,MAAM,eAAe,GAAG,IAAA,6CAAqB,GAAE,CAAA;IAE/C,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAEY,QAAA,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodeItem[]>\n\nconst _getSiblingNodeKeys = (\n params: AttributeValidatorParams & { siblingKeyNodesCache?: SiblingKeyNodesCache }\n): SiblingKeyNodeItem[] => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) {\n return []\n }\n const ancestorMultipleEntity = Records.getAncestor({\n node: attribute,\n ancestorDefUuid: ancestorMultipleEntityDef.uuid,\n })(record)\n if (!ancestorMultipleEntity) return []\n\n const ancestorMultipleEntityParent = Records.getParent({ node: ancestorMultipleEntity })(record)\n if (!ancestorMultipleEntityParent) return []\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let items = siblingKeyNodesCache?.get(cacheKey)\n if (!items) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings({ entity: ancestorMultipleEntity, includeSelf: true })(record)\n items = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes({ survey, entity, keyDefs })(record)\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n siblingKeyNodesCache?.set(cacheKey, items)\n }\n return items.filter((item) => item.entityUuid !== ancestorMultipleEntity.uuid)\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _validateRequired =\n (params: { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n (_field: string, node: any): Promise<ValidationResult> => {\n const { nodeDef } = params\n const valid = (!NodeDefs.isKey(nodeDef) && !NodeDefs.isRequired(nodeDef)) || !Nodes.isValueBlank(node)\n return Promise.resolve(\n valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n )\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: { user: User; survey: Survey; record: ArenaRecord; nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable({ node: attribute })(record)) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired({ nodeDef }),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache?: SiblingKeyNodesCache\n }\n) => {\n const { survey, nodeDef, nodeParent: parentNode, attribute } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeys = _getSiblingNodeKeys(params)\n const siblingNodeKeysWithSameValue: ArenaRecordNode[] = []\n const siblingNodeKeysWithErrors: ArenaRecordNode[] = []\n siblingNodeKeys.forEach(({ keyNode, hasErrors }) => {\n if (NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })) {\n siblingNodeKeysWithSameValue.push(keyNode)\n }\n if (hasErrors) {\n siblingNodeKeysWithErrors.push(keyNode)\n }\n })\n return [...siblingNodeKeysWithSameValue, ...siblingNodeKeysWithErrors]\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result = []\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = Records.getDependentNodePointers({\n survey,\n node,\n dependencyType: SurveyDependencyType.validations,\n includeSelf: true,\n })(record)\n\n const nodeParent = Records.getParent({ node })(record)\n\n result.push(\n ...NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }),\n ...findSiblingKeyNodesToValidate({ ...params, nodeDef, nodeParent, attribute: node, siblingKeyNodesCache })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n result.push(...Records.getAttributeSiblings({ node, nodeDef })(record))\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
@@ -49,7 +49,7 @@ const validateChildrenCount = (params) => {
49
49
  };
50
50
  const _countChildren = (params) => {
51
51
  const { record, parentNode, childDef } = params;
52
- const children = records_1.Records.getChildren(parentNode, childDef.uuid)(record);
52
+ const children = records_1.Records.getChildren({ parentNode, childDefUuid: childDef.uuid })(record);
53
53
  const nonEmptyChildren = nodeDef_1.NodeDefs.isAttribute(childDef)
54
54
  ? children.filter((child) => !node_1.Nodes.isValueBlank(child))
55
55
  : children;
@@ -69,7 +69,7 @@ const getNodePointersToValidate = (params) => {
69
69
  const { survey, record, node } = params;
70
70
  const nodePointersToValidate = [];
71
71
  const nodeDef = survey_1.Surveys.getNodeDefByUuid({ uuid: node.nodeDefUuid, survey });
72
- const nodeParent = records_1.Records.getParent(node)(record);
72
+ const nodeParent = records_1.Records.getParent({ node })(record);
73
73
  if (nodeParent) {
74
74
  // always validate the node itself
75
75
  const nodePointer = { nodeCtx: nodeParent, nodeDef };
@@ -1 +1 @@
1
- {"version":3,"file":"countVaildator.js","source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AAO,cAAc,CAAA;AACvB,CAAC,CAAA;AAED,MAAM,0BAA0B,GAAG,CAAC,MAInC,EAAoB,EAAE,CAAC,+BAA+B,iCAAM,MAAM,KAAE,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAG,CAAA;AAElG,QAAA,cAAc,GAAG;IAC5B,qBAAqB;IACrB,+BAA+B;IAC/B,0BAA0B;CAC3B,CAAA","sourcesContent":["import { ArenaRecordNode, NodePointer, Nodes } from '../../node'\nimport { NodeDef, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { Records } from '../records'\nimport { Validation, ValidationFactory, ValidationResultFactory, ValidationSeverity } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { Survey, Surveys } from '../../survey'\nimport { RecordValidations } from '../recordValidations'\nimport { ValidationFields } from '../../validation/validation'\n\nconst createValidationResult = (params: {\n nodeDefUuid: string\n isMinCountValidation: boolean\n minCount: number\n maxCount: number\n}): Validation => {\n const { nodeDefUuid, isMinCountValidation, minCount, maxCount } = params\n\n if (minCount === maxCount) {\n return ValidationFactory.createInstance({\n valid: false,\n errors: [\n ValidationResultFactory.createInstance({\n key: 'record.nodes.count.invalid',\n params: { nodeDefUuid, count: minCount },\n severity: ValidationSeverity.error,\n }),\n ],\n })\n }\n return ValidationFactory.createInstance({\n valid: false,\n errors: [\n ValidationResultFactory.createInstance({\n key: isMinCountValidation ? 'record.nodes.count.minNotReached' : 'record.nodes.count.maxExceeded',\n params: { nodeDefUuid, ...(isMinCountValidation ? { minCount } : { maxCount }) },\n severity: ValidationSeverity.error,\n }),\n ],\n })\n}\n\nconst validateChildrenCount = (params: {\n parentNode: ArenaRecordNode\n nodeDefChild: NodeDef<NodeDefType, NodeDefProps>\n count: number\n}): Validation => {\n const { parentNode, nodeDefChild, count } = params\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef: nodeDefChild })\n const maxCount = Nodes.getChildrenMaxCount({ parentNode, nodeDef: nodeDefChild })\n\n const minCountValid = Number.isNaN(minCount) || count >= minCount\n const maxCountValid = Number.isNaN(maxCount) || count <= maxCount\n\n return minCountValid && maxCountValid\n ? ValidationFactory.createInstance()\n : createValidationResult({\n nodeDefUuid: nodeDefChild.uuid,\n isMinCountValidation: !minCountValid,\n minCount,\n maxCount,\n })\n}\n\nconst _countChildren = (params: {\n record: ArenaRecord\n parentNode: ArenaRecordNode\n childDef: NodeDef<NodeDefType, NodeDefProps>\n}) => {\n const { record, parentNode, childDef } = params\n const children = Records.getChildren(parentNode, childDef.uuid)(record)\n const nonEmptyChildren = NodeDefs.isAttribute(childDef)\n ? children.filter((child) => !Nodes.isValueBlank(child))\n : children\n return nonEmptyChildren.length\n}\n\nconst isNodePointerToBeValidated = (nodePointer: NodePointer) => NodeDefs.hasMinOrMaxCount(nodePointer.nodeDef)\n\nconst validateNodePointer = (params: {\n record: ArenaRecord\n nodeCtx: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n}) => {\n const { record, nodeCtx, nodeDef } = params\n // Check children count only for applicable nodes\n if (Nodes.isChildApplicable(nodeCtx, nodeDef.uuid)) {\n const count = _countChildren({ record, parentNode: nodeCtx, childDef: nodeDef })\n return validateChildrenCount({ parentNode: nodeCtx, nodeDefChild: nodeDef, count })\n }\n return ValidationFactory.createInstance()\n}\n\nconst getNodePointersToValidate = (params: {\n survey: Survey\n record: ArenaRecord\n node: ArenaRecordNode\n}): NodePointer[] => {\n const { survey, record, node } = params\n const nodePointersToValidate: NodePointer[] = []\n\n const nodeDef = Surveys.getNodeDefByUuid({ uuid: node.nodeDefUuid, survey })\n\n const nodeParent = Records.getParent(node)(record)\n if (nodeParent) {\n // always validate the node itself\n const nodePointer = { nodeCtx: nodeParent, nodeDef }\n if (isNodePointerToBeValidated(nodePointer)) {\n nodePointersToValidate.push(nodePointer)\n }\n }\n if (NodeDefs.isEntity(nodeDef) && !node.deleted) {\n // validate the count of every node def children\n const childDefs = Surveys.getNodeDefChildren({ survey, nodeDef })\n for (const childDef of childDefs) {\n const nodePointer = { nodeCtx: node, nodeDef: childDef }\n if (isNodePointerToBeValidated(nodePointer)) {\n nodePointersToValidate.push(nodePointer)\n }\n }\n }\n return nodePointersToValidate\n}\n\nconst validateChildrenCountNodesArray = (params: {\n survey: Survey\n record: ArenaRecord\n nodesArray: ArenaRecordNode[]\n}): ValidationFields => {\n const { survey, record, nodesArray } = params\n const validationsAcc: ValidationFields = {}\n for (const node of nodesArray) {\n const nodePointersToValidate = getNodePointersToValidate({ survey, record, node })\n\n for (const nodePointer of nodePointersToValidate) {\n const { nodeCtx, nodeDef } = nodePointer\n // check if validated already\n const validationChildrenCountKey = RecordValidations.getValidationChildrenCountKey({\n nodeParentUuid: nodeCtx.uuid,\n nodeDefChildUuid: nodeDef.uuid,\n })\n if (!(validationChildrenCountKey in validationsAcc)) {\n // validate the children count of this node pointer\n const validationNodePointer = validateNodePointer({ record, nodeCtx, nodeDef })\n validationsAcc[validationChildrenCountKey] = validationNodePointer\n }\n }\n }\n return validationsAcc\n}\n\nconst validateChildrenCountNodes = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: { [key: string]: ArenaRecordNode }\n}): ValidationFields => validateChildrenCountNodesArray({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const CountValidator = {\n validateChildrenCount,\n validateChildrenCountNodesArray,\n validateChildrenCountNodes,\n}\n"]}
1
+ {"version":3,"file":"countVaildator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/countVaildator.ts"],"names":[],"mappings":";;;AAAA,qCAAgE;AAChE,2CAA4E;AAC5E,wCAAoC;AACpC,iDAA6G;AAE7G,yCAA8C;AAC9C,4DAAwD;AAGxD,MAAM,sBAAsB,GAAG,CAAC,MAK/B,EAAc,EAAE;IACf,MAAM,EAAE,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAExE,IAAI,QAAQ,KAAK,QAAQ,EAAE,CAAC;QAC1B,O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er, Nodes } from '../../node'\nimport { NodeDef, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { Records } from '../records'\nimport { Validation, ValidationFactory, ValidationResultFactory, ValidationSeverity } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { Survey, Surveys } from '../../survey'\nimport { RecordValidations } from '../recordValidations'\nimport { ValidationFields } from '../../validation/validation'\n\nconst createValidationResult = (params: {\n nodeDefUuid: string\n isMinCountValidation: boolean\n minCount: number\n maxCount: number\n}): Validation => {\n const { nodeDefUuid, isMinCountValidation, minCount, maxCount } = params\n\n if (minCount === maxCount) {\n return ValidationFactory.createInstance({\n valid: false,\n errors: [\n ValidationResultFactory.createInstance({\n key: 'record.nodes.count.invalid',\n params: { nodeDefUuid, count: minCount },\n severity: ValidationSeverity.error,\n }),\n ],\n })\n }\n return ValidationFactory.createInstance({\n valid: false,\n errors: [\n ValidationResultFactory.createInstance({\n key: isMinCountValidation ? 'record.nodes.count.minNotReached' : 'record.nodes.count.maxExceeded',\n params: { nodeDefUuid, ...(isMinCountValidation ? { minCount } : { maxCount }) },\n severity: ValidationSeverity.error,\n }),\n ],\n })\n}\n\nconst validateChildrenCount = (params: {\n parentNode: ArenaRecordNode\n nodeDefChild: NodeDef<NodeDefType, NodeDefProps>\n count: number\n}): Validation => {\n const { parentNode, nodeDefChild, count } = params\n\n const minCount = Nodes.getChildrenMinCount({ parentNode, nodeDef: nodeDefChild })\n const maxCount = Nodes.getChildrenMaxCount({ parentNode, nodeDef: nodeDefChild })\n\n const minCountValid = Number.isNaN(minCount) || count >= minCount\n const maxCountValid = Number.isNaN(maxCount) || count <= maxCount\n\n return minCountValid && maxCountValid\n ? ValidationFactory.createInstance()\n : createValidationResult({\n nodeDefUuid: nodeDefChild.uuid,\n isMinCountValidation: !minCountValid,\n minCount,\n maxCount,\n })\n}\n\nconst _countChildren = (params: {\n record: ArenaRecord\n parentNode: ArenaRecordNode\n childDef: NodeDef<NodeDefType, NodeDefProps>\n}) => {\n const { record, parentNode, childDef } = params\n const children = Records.getChildren({ parentNode, childDefUuid: childDef.uuid })(record)\n const nonEmptyChildren = NodeDefs.isAttribute(childDef)\n ? children.filter((child) => !Nodes.isValueBlank(child))\n : children\n return nonEmptyChildren.length\n}\n\nconst isNodePointerToBeValidated = (nodePointer: NodePointer) => NodeDefs.hasMinOrMaxCount(nodePointer.nodeDef)\n\nconst validateNodePointer = (params: {\n record: ArenaRecord\n nodeCtx: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n}) => {\n const { record, nodeCtx, nodeDef } = params\n // Check children count only for applicable nodes\n if (Nodes.isChildApplicable(nodeCtx, nodeDef.uuid)) {\n const count = _countChildren({ record, parentNode: nodeCtx, childDef: nodeDef })\n return validateChildrenCount({ parentNode: nodeCtx, nodeDefChild: nodeDef, count })\n }\n return ValidationFactory.createInstance()\n}\n\nconst getNodePointersToValidate = (params: {\n survey: Survey\n record: ArenaRecord\n node: ArenaRecordNode\n}): NodePointer[] => {\n const { survey, record, node } = params\n const nodePointersToValidate: NodePointer[] = []\n\n const nodeDef = Surveys.getNodeDefByUuid({ uuid: node.nodeDefUuid, survey })\n\n const nodeParent = Records.getParent({ node })(record)\n if (nodeParent) {\n // always validate the node itself\n const nodePointer = { nodeCtx: nodeParent, nodeDef }\n if (isNodePointerToBeValidated(nodePointer)) {\n nodePointersToValidate.push(nodePointer)\n }\n }\n if (NodeDefs.isEntity(nodeDef) && !node.deleted) {\n // validate the count of every node def children\n const childDefs = Surveys.getNodeDefChildren({ survey, nodeDef })\n for (const childDef of childDefs) {\n const nodePointer = { nodeCtx: node, nodeDef: childDef }\n if (isNodePointerToBeValidated(nodePointer)) {\n nodePointersToValidate.push(nodePointer)\n }\n }\n }\n return nodePointersToValidate\n}\n\nconst validateChildrenCountNodesArray = (params: {\n survey: Survey\n record: ArenaRecord\n nodesArray: ArenaRecordNode[]\n}): ValidationFields => {\n const { survey, record, nodesArray } = params\n const validationsAcc: ValidationFields = {}\n for (const node of nodesArray) {\n const nodePointersToValidate = getNodePointersToValidate({ survey, record, node })\n\n for (const nodePointer of nodePointersToValidate) {\n const { nodeCtx, nodeDef } = nodePointer\n // check if validated already\n const validationChildrenCountKey = RecordValidations.getValidationChildrenCountKey({\n nodeParentUuid: nodeCtx.uuid,\n nodeDefChildUuid: nodeDef.uuid,\n })\n if (!(validationChildrenCountKey in validationsAcc)) {\n // validate the children count of this node pointer\n const validationNodePointer = validateNodePointer({ record, nodeCtx, nodeDef })\n validationsAcc[validationChildrenCountKey] = validationNodePointer\n }\n }\n }\n return validationsAcc\n}\n\nconst validateChildrenCountNodes = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: { [key: string]: ArenaRecordNode }\n}): ValidationFields => validateChildrenCountNodesArray({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const CountValidator = {\n validateChildrenCount,\n validateChildrenCountNodesArray,\n validateChildrenCountNodes,\n}\n"]}
@@ -35,13 +35,12 @@ const validateRecord = (params) => __awaiter(void 0, void 0, void 0, function* (
35
35
  const nodesArray = [];
36
36
  const nodes = {};
37
37
  records_1.Records.visitDescendantsAndSelf({
38
- record,
39
38
  node: records_1.Records.getRoot(record),
40
39
  visitor: (node) => {
41
40
  nodesArray.push(node);
42
41
  nodes[node.uuid] = node;
43
42
  },
44
- });
43
+ })(record);
45
44
  return (0, exports.validateSortedNodes)(Object.assign(Object.assign({}, params), { nodesArray }));
46
45
  });
47
46
  exports.validateRecord = validateRecord;
@@ -1 +1 @@
1
- {"version":3,"file":"recordValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/recordValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iDAAgE;AAChE,8DAA0D;AAC1D,wCAAoC;AACpC,6DAK6B;AAC7B,qDAAiD;AAE1C,MAAM,mBAAmB,GAAG,CAAO,MAAuC,EAAuB,EAAE;IACxG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAE7C,yBAAyB;IACz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AAA,CAAA;AAdY,QAAA,cAAc,GAAd,cAAc,CAc1B","sourcesContent":["import { ArenaRecordNode, NodesMap } from '../../node'\nimport { Validation, ValidationFactory } from '../../validation'\nimport { Validations } from '../../validation/validations'\nimport { Records } from '../records'\nimport {\n AttributesValidatorParams,\n AttributeValidator,\n RecordValidatorParams,\n SortedAttributesValidatorParams,\n} from './attributeValidator'\nimport { CountValidator } from './countVaildator'\n\nexport const validateSortedNodes = async (params: SortedAttributesValidatorParams): Promise<Validation> => {\n const { survey, record, nodesArray } = params\n\n // 1. validate attributes\n const attributeValidations = await AttributeValidator.validateSelfAndDependentSortedAttributes({\n ...params,\n nodesArray,\n })\n\n // 2. validate min/max count\n const nodeCountValidations = CountValidator.validateChildrenCountNodesArray({ survey, record, nodesArray })\n\n // 3. merge validations\n return Validations.recalculateValidity(\n ValidationFactory.createInstance({\n valid: true,\n fields: {\n ...attributeValidations,\n ...nodeCountValidations,\n },\n })\n )\n}\n\nexport const validateNodes = async (params: AttributesValidatorParams): Promise<Validation> =>\n validateSortedNodes({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const validateRecord = async (params: RecordValidatorParams): Promise<Validation> => {\n const { record } = params\n const nodesArray: ArenaRecordNode[] = []\n const nodes: NodesMap = {}\n Records.visitDescendantsAndSelf({\n record,\n node: Records.getRoot(record)!,\n visitor: (node) => {\n nodesArray.push(node)\n nodes[node.uuid] = node\n },\n })\n\n return validateSortedNodes({ ...params, nodesArray })\n}\n"]}
1
+ {"version":3,"file":"recordValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/recordValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iDAAgE;AAChE,8DAA0D;AAC1D,wCAAoC;AACpC,6DAK6B;AAC7B,qDAAiD;AAE1C,MAAM,mBAAmB,GAAG,CAAO,MAAuC,EAAuB,EAAE;IACxG,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAE7C,yBAAyB;IACzB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AAC,CAAA,CAAA;AAbY,QAAA,cAAc,GAAd,cAAc,CAa1B","sourcesContent":["import { ArenaRecordNode, NodesMap } from '../../node'\nimport { Validation, ValidationFactory } from '../../validation'\nimport { Validations } from '../../validation/validations'\nimport { Records } from '../records'\nimport {\n AttributesValidatorParams,\n AttributeValidator,\n RecordValidatorParams,\n SortedAttributesValidatorParams,\n} from './attributeValidator'\nimport { CountValidator } from './countVaildator'\n\nexport const validateSortedNodes = async (params: SortedAttributesValidatorParams): Promise<Validation> => {\n const { survey, record, nodesArray } = params\n\n // 1. validate attributes\n const attributeValidations = await AttributeValidator.validateSelfAndDependentSortedAttributes({\n ...params,\n nodesArray,\n })\n\n // 2. validate min/max count\n const nodeCountValidations = CountValidator.validateChildrenCountNodesArray({ survey, record, nodesArray })\n\n // 3. merge validations\n return Validations.recalculateValidity(\n ValidationFactory.createInstance({\n valid: true,\n fields: {\n ...attributeValidations,\n ...nodeCountValidations,\n },\n })\n )\n}\n\nexport const validateNodes = async (params: AttributesValidatorParams): Promise<Validation> =>\n validateSortedNodes({ ...params, nodesArray: Object.values(params.nodes) })\n\nexport const validateRecord = async (params: RecordValidatorParams): Promise<Validation> => {\n const { record } = params\n const nodesArray: ArenaRecordNode[] = []\n const nodes: NodesMap = {}\n Records.visitDescendantsAndSelf({\n node: Records.getRoot(record)!,\n visitor: (node) => {\n nodesArray.push(node)\n nodes[node.uuid] = node\n },\n })(record)\n\n return validateSortedNodes({ ...params, nodesArray })\n}\n"]}