@openforis/arena-core 2.3.36 → 2.3.39

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 (383) hide show
  1. package/dist/auth/authGroup.js.map +1 -1
  2. package/dist/auth/authGroups.d.ts +21 -11
  3. package/dist/auth/authGroups.js.map +1 -1
  4. package/dist/auth/authorizer.d.ts +64 -38
  5. package/dist/auth/authorizer.js.map +1 -1
  6. package/dist/auth/permission.js.map +1 -1
  7. package/dist/auth/user.js.map +1 -1
  8. package/dist/auth/users.d.ts +19 -9
  9. package/dist/auth/users.js +3 -2
  10. package/dist/auth/users.js.map +1 -1
  11. package/dist/category/categories.d.ts +7 -3
  12. package/dist/category/categories.js.map +1 -1
  13. package/dist/category/categoryImportSummary.js.map +1 -1
  14. package/dist/category/categoryItemGenerator.d.ts +6 -4
  15. package/dist/category/categoryItems.d.ts +9 -4
  16. package/dist/category/categoryItems.js +2 -1
  17. package/dist/category/categoryItems.js.map +1 -1
  18. package/dist/category/factory.js.map +1 -1
  19. package/dist/chain/chain.js.map +1 -1
  20. package/dist/common/index.js.map +1 -1
  21. package/dist/dataExport/FlatDataExportModel.js.map +1 -1
  22. package/dist/dataExport/FlatDataExportOptions.js.map +1 -1
  23. package/dist/dataExport/FlatDataFiles.d.ts +7 -5
  24. package/dist/dataExport/UniqueFileNamesGenerator.js.map +1 -1
  25. package/dist/dataQuery/dataQuery.js.map +1 -1
  26. package/dist/dataQuery/dataQuerySummaries.d.ts +28 -15
  27. package/dist/dataQuery/dataQuerySummaries.js +3 -3
  28. package/dist/dataQuery/dataQuerySummaries.js.map +1 -1
  29. package/dist/error/SystemError.js.map +1 -1
  30. package/dist/esm/auth/authGroups.js.map +1 -1
  31. package/dist/esm/auth/users.js +3 -2
  32. package/dist/esm/auth/users.js.map +1 -1
  33. package/dist/esm/category/categories.js.map +1 -1
  34. package/dist/esm/category/categoryItems.js +2 -1
  35. package/dist/esm/category/categoryItems.js.map +1 -1
  36. package/dist/esm/dataExport/FlatDataExportModel.js.map +1 -1
  37. package/dist/esm/dataQuery/dataQuerySummaries.js +3 -3
  38. package/dist/esm/dataQuery/dataQuerySummaries.js.map +1 -1
  39. package/dist/esm/expression/javascript/evaluator.js.map +1 -1
  40. package/dist/esm/extraProp/extraProps.js.map +1 -1
  41. package/dist/esm/geo/pointFactory.js.map +1 -1
  42. package/dist/esm/geo/points/bearing.js +1 -1
  43. package/dist/esm/geo/points/bearing.js.map +1 -1
  44. package/dist/esm/geo/points/distance.js +1 -1
  45. package/dist/esm/geo/points/distance.js.map +1 -1
  46. package/dist/esm/geo/points/isValid.js.map +1 -1
  47. package/dist/esm/geo/points/transform.js.map +1 -1
  48. package/dist/esm/job/JobBase.js +4 -3
  49. package/dist/esm/job/JobBase.js.map +1 -1
  50. package/dist/esm/message/messages.js +9 -8
  51. package/dist/esm/message/messages.js.map +1 -1
  52. package/dist/esm/node/factory.js +2 -1
  53. package/dist/esm/node/factory.js.map +1 -1
  54. package/dist/esm/node/nodeValueFormatter.js +2 -1
  55. package/dist/esm/node/nodeValueFormatter.js.map +1 -1
  56. package/dist/esm/node/nodeValues.js +3 -2
  57. package/dist/esm/node/nodeValues.js.map +1 -1
  58. package/dist/esm/node/nodes.js +4 -4
  59. package/dist/esm/node/nodes.js.map +1 -1
  60. package/dist/esm/nodeDef/nodeDefs.js +10 -10
  61. package/dist/esm/nodeDef/nodeDefs.js.map +1 -1
  62. package/dist/esm/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
  63. package/dist/esm/nodeDefExpressionEvaluator/functions.js.map +1 -1
  64. package/dist/esm/nodeDefExpressionEvaluator/node/identifier.js +3 -2
  65. package/dist/esm/nodeDefExpressionEvaluator/node/identifier.js.map +1 -1
  66. package/dist/esm/nodeDefExpressionEvaluator/node/member.js.map +1 -1
  67. package/dist/esm/nodeDefExpressionEvaluator/validator.js.map +1 -1
  68. package/dist/esm/record/_records/nodeDefSelfReferences.js.map +1 -1
  69. package/dist/esm/record/_records/recordGetters.js.map +1 -1
  70. package/dist/esm/record/_records/recordNodesIndexReader.js +6 -4
  71. package/dist/esm/record/_records/recordNodesIndexReader.js.map +1 -1
  72. package/dist/esm/record/_records/recordNodesIndexUpdater.js +10 -7
  73. package/dist/esm/record/_records/recordNodesIndexUpdater.js.map +1 -1
  74. package/dist/esm/record/_records/recordPagesValidation.js.map +1 -1
  75. package/dist/esm/record/_records/recordUpdater.js.map +1 -1
  76. package/dist/esm/record/factory.js +2 -1
  77. package/dist/esm/record/factory.js.map +1 -1
  78. package/dist/esm/record/recordCloner.js +2 -1
  79. package/dist/esm/record/recordCloner.js.map +1 -1
  80. package/dist/esm/record/recordExpressionEvaluator/functions.js.map +1 -1
  81. package/dist/esm/record/recordExpressionEvaluator/node/identifier/identifier.js +3 -2
  82. package/dist/esm/record/recordExpressionEvaluator/node/identifier/identifier.js.map +1 -1
  83. package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js +4 -7
  84. package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
  85. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
  86. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
  87. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
  88. package/dist/esm/record/recordNodesUpdater/recordNodesDeleter.js.map +1 -1
  89. package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  90. package/dist/esm/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
  91. package/dist/esm/record/recordUpdater.js.map +1 -1
  92. package/dist/esm/record/recordValidator/attributeTypeValidator.js +2 -2
  93. package/dist/esm/record/recordValidator/attributeTypeValidator.js.map +1 -1
  94. package/dist/esm/record/recordValidator/attributeUniqueValidator.js.map +1 -1
  95. package/dist/esm/record/recordValidator/attributeValidator.js.map +1 -1
  96. package/dist/esm/record/recordValidator/recordValidator.js.map +1 -1
  97. package/dist/esm/survey/nodeDefsFixer.js.map +1 -1
  98. package/dist/esm/survey/refData/factory.js +3 -2
  99. package/dist/esm/survey/refData/factory.js.map +1 -1
  100. package/dist/esm/survey/surveyDocImageFactory.js.map +1 -1
  101. package/dist/esm/survey/surveyDocImages.js.map +1 -1
  102. package/dist/esm/survey/surveyFileFactory.js.map +1 -1
  103. package/dist/esm/survey/surveys/_nodeDefs/nodeDefsIndex.js.map +1 -1
  104. package/dist/esm/survey/surveys/_nodeDefs/nodeDefsReader.js.map +1 -1
  105. package/dist/esm/survey/surveys/dependencies.js +2 -1
  106. package/dist/esm/survey/surveys/dependencies.js.map +1 -1
  107. package/dist/esm/survey/surveys/nodeDefs.js +4 -2
  108. package/dist/esm/survey/surveys/nodeDefs.js.map +1 -1
  109. package/dist/esm/survey/surveys/refsData.js +2 -1
  110. package/dist/esm/survey/surveys/refsData.js.map +1 -1
  111. package/dist/esm/survey/surveys/surveyGettersSecurity.js +1 -4
  112. package/dist/esm/survey/surveys/surveyGettersSecurity.js.map +1 -1
  113. package/dist/esm/survey/surveys/surveysGetters.js +5 -7
  114. package/dist/esm/survey/surveys/surveysGetters.js.map +1 -1
  115. package/dist/esm/taxonomy/taxa.js.map +1 -1
  116. package/dist/esm/taxonomy/taxonomies.js.map +1 -1
  117. package/dist/esm/tests/builder/recordBuilder/attributeBuilder.js.map +1 -1
  118. package/dist/esm/tests/builder/recordBuilder/index.js.map +1 -1
  119. package/dist/esm/tests/builder/recordBuilder/nodeBuilder.js.map +1 -1
  120. package/dist/esm/tests/builder/surveyBuilder/categoryItemBuilder.js.map +1 -1
  121. package/dist/esm/tests/builder/surveyBuilder/nodeDefAttributeBuilder.js.map +1 -1
  122. package/dist/esm/tests/builder/surveyBuilder/nodeDefBuilder.js.map +1 -1
  123. package/dist/esm/utils/_objects/camelize.js.map +1 -1
  124. package/dist/esm/utils/arrays.js.map +1 -1
  125. package/dist/esm/utils/dates.js.map +1 -1
  126. package/dist/esm/utils/fileNames.js.map +1 -1
  127. package/dist/esm/utils/fileProcessor.js +2 -1
  128. package/dist/esm/utils/fileProcessor.js.map +1 -1
  129. package/dist/esm/utils/numbers.js.map +1 -1
  130. package/dist/esm/utils/queue.js.map +1 -1
  131. package/dist/esm/utils/versions.js.map +1 -1
  132. package/dist/esm/validation/factory.js.map +1 -1
  133. package/dist/esm/validation/fieldValidators/numeric.js.map +1 -1
  134. package/dist/esm/validation/fieldValidators/numericPositive.js.map +1 -1
  135. package/dist/esm/validation/validationResults.js +1 -1
  136. package/dist/esm/validation/validationResults.js.map +1 -1
  137. package/dist/esm/validation/validations.js +2 -2
  138. package/dist/esm/validation/validations.js.map +1 -1
  139. package/dist/esm/validation/validator.js.map +1 -1
  140. package/dist/expression/javascript/evaluator.js.map +1 -1
  141. package/dist/expression/javascript/global.js.map +1 -1
  142. package/dist/expression/javascript/node/array.js.map +1 -1
  143. package/dist/expression/javascript/node/binary.js.map +1 -1
  144. package/dist/expression/javascript/node/call.js.map +1 -1
  145. package/dist/expression/javascript/node/compound.js.map +1 -1
  146. package/dist/expression/javascript/node/conditional.js.map +1 -1
  147. package/dist/expression/javascript/node/identifier.js.map +1 -1
  148. package/dist/expression/javascript/node/literal.js.map +1 -1
  149. package/dist/expression/javascript/node/member.js.map +1 -1
  150. package/dist/expression/javascript/node/sequence.js.map +1 -1
  151. package/dist/expression/javascript/node/this.js.map +1 -1
  152. package/dist/expression/javascript/node/unary.js.map +1 -1
  153. package/dist/expression/javascript/parser/jsep.js.map +1 -1
  154. package/dist/expression/javascript/parser/parser.js.map +1 -1
  155. package/dist/expression/node.js.map +1 -1
  156. package/dist/expression/variable.js.map +1 -1
  157. package/dist/extraProp/extraProp.js.map +1 -1
  158. package/dist/extraProp/extraProps.d.ts +9 -6
  159. package/dist/extraProp/extraProps.js.map +1 -1
  160. package/dist/extraProp/extraPropsDataGenerator.d.ts +7 -5
  161. package/dist/geo/pointFactory.js.map +1 -1
  162. package/dist/geo/points/bearing.js +5 -2
  163. package/dist/geo/points/bearing.js.map +1 -1
  164. package/dist/geo/points/distance.js +5 -2
  165. package/dist/geo/points/distance.js.map +1 -1
  166. package/dist/geo/points/equals.js.map +1 -1
  167. package/dist/geo/points/getSrs.js.map +1 -1
  168. package/dist/geo/points/index.d.ts +18 -14
  169. package/dist/geo/points/isFilled.js.map +1 -1
  170. package/dist/geo/points/isValid.js.map +1 -1
  171. package/dist/geo/points/parse.js.map +1 -1
  172. package/dist/geo/points/pointAtDistance.js.map +1 -1
  173. package/dist/geo/points/toLatLong.js.map +1 -1
  174. package/dist/geo/points/toString.js.map +1 -1
  175. package/dist/geo/points/transform.js.map +1 -1
  176. package/dist/job/JobBase.js +4 -3
  177. package/dist/job/JobBase.js.map +1 -1
  178. package/dist/job/jobEvent.js.map +1 -1
  179. package/dist/job/status.js.map +1 -1
  180. package/dist/language/languageCode.js.map +1 -1
  181. package/dist/language/languages.js.map +1 -1
  182. package/dist/message/message.js.map +1 -1
  183. package/dist/message/messages.d.ts +54 -28
  184. package/dist/message/messages.js +9 -8
  185. package/dist/message/messages.js.map +1 -1
  186. package/dist/node/factory.js +2 -1
  187. package/dist/node/factory.js.map +1 -1
  188. package/dist/node/node.js.map +1 -1
  189. package/dist/node/nodeValueFormatter.d.ts +2 -1
  190. package/dist/node/nodeValueFormatter.js +2 -1
  191. package/dist/node/nodeValueFormatter.js.map +1 -1
  192. package/dist/node/nodeValueProps.js.map +1 -1
  193. package/dist/node/nodeValues.d.ts +62 -41
  194. package/dist/node/nodeValues.js +3 -2
  195. package/dist/node/nodeValues.js.map +1 -1
  196. package/dist/node/nodes.d.ts +112 -86
  197. package/dist/node/nodes.js +4 -4
  198. package/dist/node/nodes.js.map +1 -1
  199. package/dist/nodeDef/nodeDef.js.map +1 -1
  200. package/dist/nodeDef/nodeDefs.d.ts +173 -86
  201. package/dist/nodeDef/nodeDefs.js +10 -10
  202. package/dist/nodeDef/nodeDefs.js.map +1 -1
  203. package/dist/nodeDef/types/entity.js.map +1 -1
  204. package/dist/nodeDef/types/file.js.map +1 -1
  205. package/dist/nodeDef/types/formHeader.js.map +1 -1
  206. package/dist/nodeDef/types/text.js.map +1 -1
  207. package/dist/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
  208. package/dist/nodeDefExpressionEvaluator/functions.js.map +1 -1
  209. package/dist/nodeDefExpressionEvaluator/node/identifier.js +3 -2
  210. package/dist/nodeDefExpressionEvaluator/node/identifier.js.map +1 -1
  211. package/dist/nodeDefExpressionEvaluator/node/member.js.map +1 -1
  212. package/dist/nodeDefExpressionEvaluator/node/nodeDefExpressionNativeProperties.d.ts +11 -8
  213. package/dist/nodeDefExpressionEvaluator/node/thisEvaluator.d.ts +1 -1
  214. package/dist/nodeDefExpressionEvaluator/node/thisEvaluator.js.map +1 -1
  215. package/dist/nodeDefExpressionEvaluator/validator.js.map +1 -1
  216. package/dist/record/_records/nodeDefSelfReferences.d.ts +12 -4
  217. package/dist/record/_records/nodeDefSelfReferences.js.map +1 -1
  218. package/dist/record/_records/recordCompletion.js.map +1 -1
  219. package/dist/record/_records/recordGetters.js.map +1 -1
  220. package/dist/record/_records/recordNodesIndexReader.d.ts +14 -8
  221. package/dist/record/_records/recordNodesIndexReader.js +6 -4
  222. package/dist/record/_records/recordNodesIndexReader.js.map +1 -1
  223. package/dist/record/_records/recordNodesIndexUpdater.d.ts +22 -12
  224. package/dist/record/_records/recordNodesIndexUpdater.js +10 -7
  225. package/dist/record/_records/recordNodesIndexUpdater.js.map +1 -1
  226. package/dist/record/_records/recordPagesValidation.js.map +1 -1
  227. package/dist/record/_records/recordUpdater.js.map +1 -1
  228. package/dist/record/_records/recordUtils.js.map +1 -1
  229. package/dist/record/factory.js +2 -1
  230. package/dist/record/factory.js.map +1 -1
  231. package/dist/record/nodePointers.d.ts +13 -10
  232. package/dist/record/recordCloner.d.ts +11 -10
  233. package/dist/record/recordCloner.js +2 -1
  234. package/dist/record/recordCloner.js.map +1 -1
  235. package/dist/record/recordExpressionEvaluator/functions.js.map +1 -1
  236. package/dist/record/recordExpressionEvaluator/node/identifier/identifier.js +3 -2
  237. package/dist/record/recordExpressionEvaluator/node/identifier/identifier.js.map +1 -1
  238. package/dist/record/recordExpressionEvaluator/node/identifier/nodesFinder.d.ts +8 -6
  239. package/dist/record/recordExpressionEvaluator/node/thisEvaluator.js.map +1 -1
  240. package/dist/record/recordExpressionEvaluator/nodeValueExtractor.d.ts +7 -5
  241. package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js +4 -7
  242. package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
  243. package/dist/record/recordFixer.d.ts +19 -10
  244. package/dist/record/recordNodesUpdater/index.d.ts +8 -7
  245. package/dist/record/recordNodesUpdater/recordEnumeratingItemsExpressionEvaluator.js.map +1 -1
  246. package/dist/record/recordNodesUpdater/recordExpressionValueConverter.d.ts +2 -1
  247. package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
  248. package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
  249. package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
  250. package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
  251. package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
  252. package/dist/record/recordNodesUpdater/recordNodeDependentsEditableUpdater.js.map +1 -1
  253. package/dist/record/recordNodesUpdater/recordNodeDependentsEnumeratedEntitiesUpdater.js.map +1 -1
  254. package/dist/record/recordNodesUpdater/recordNodeDependentsEnumeratingItemsUpdater.js.map +1 -1
  255. package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
  256. package/dist/record/recordNodesUpdater/recordNodeDependentsVisibleUpdater.js.map +1 -1
  257. package/dist/record/recordNodesUpdater/recordNodesCreator.js.map +1 -1
  258. package/dist/record/recordNodesUpdater/recordNodesDeleter.js.map +1 -1
  259. package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
  260. package/dist/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  261. package/dist/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
  262. package/dist/record/recordPrettyPrinter.d.ts +18 -15
  263. package/dist/record/recordPrettyPrinter.js.map +1 -1
  264. package/dist/record/recordStep.d.ts +5 -2
  265. package/dist/record/recordStep.js.map +1 -1
  266. package/dist/record/recordUpdater.d.ts +22 -15
  267. package/dist/record/recordUpdater.js.map +1 -1
  268. package/dist/record/recordValidations.d.ts +21 -14
  269. package/dist/record/recordValidator/attributeKeyValidator.d.ts +8 -6
  270. package/dist/record/recordValidator/attributeKeyValidator.js.map +1 -1
  271. package/dist/record/recordValidator/attributeTypeValidator.d.ts +2 -1
  272. package/dist/record/recordValidator/attributeTypeValidator.js +2 -2
  273. package/dist/record/recordValidator/attributeTypeValidator.js.map +1 -1
  274. package/dist/record/recordValidator/attributeUniqueValidator.d.ts +1 -5
  275. package/dist/record/recordValidator/attributeUniqueValidator.js.map +1 -1
  276. package/dist/record/recordValidator/attributeValidator.d.ts +3 -1
  277. package/dist/record/recordValidator/attributeValidator.js.map +1 -1
  278. package/dist/record/recordValidator/countVaildator.d.ts +21 -17
  279. package/dist/record/recordValidator/index.d.ts +4 -3
  280. package/dist/record/recordValidator/recordValidator.js.map +1 -1
  281. package/dist/record/records.d.ts +62 -220
  282. package/dist/registry/serviceRegistry.js.map +1 -1
  283. package/dist/registry/serviceType.js.map +1 -1
  284. package/dist/srs/srs.js.map +1 -1
  285. package/dist/survey/nodeDefsFixer.d.ts +5 -4
  286. package/dist/survey/nodeDefsFixer.js.map +1 -1
  287. package/dist/survey/refData/factory.js +3 -2
  288. package/dist/survey/refData/factory.js.map +1 -1
  289. package/dist/survey/survey.d.ts +2 -2
  290. package/dist/survey/survey.js.map +1 -1
  291. package/dist/survey/surveyDocImageFactory.js.map +1 -1
  292. package/dist/survey/surveyDocImages.d.ts +11 -5
  293. package/dist/survey/surveyDocImages.js.map +1 -1
  294. package/dist/survey/surveyFileFactory.js.map +1 -1
  295. package/dist/survey/surveys/_nodeDefs/nodeDefsIndex.js.map +1 -1
  296. package/dist/survey/surveys/_nodeDefs/nodeDefsReader.js.map +1 -1
  297. package/dist/survey/surveys/dependencies.js +2 -1
  298. package/dist/survey/surveys/dependencies.js.map +1 -1
  299. package/dist/survey/surveys/index.d.ts +82 -255
  300. package/dist/survey/surveys/nodeDefs.d.ts +4 -6
  301. package/dist/survey/surveys/nodeDefs.js +4 -2
  302. package/dist/survey/surveys/nodeDefs.js.map +1 -1
  303. package/dist/survey/surveys/refsData.js +2 -1
  304. package/dist/survey/surveys/refsData.js.map +1 -1
  305. package/dist/survey/surveys/surveyGettersSecurity.js +1 -4
  306. package/dist/survey/surveys/surveyGettersSecurity.js.map +1 -1
  307. package/dist/survey/surveys/surveysGetters.js +5 -7
  308. package/dist/survey/surveys/surveysGetters.js.map +1 -1
  309. package/dist/survey/surveys/surveysUtils.js.map +1 -1
  310. package/dist/taxonomy/taxa.d.ts +17 -11
  311. package/dist/taxonomy/taxa.js.map +1 -1
  312. package/dist/taxonomy/taxonGenerator.d.ts +6 -4
  313. package/dist/taxonomy/taxonomies.d.ts +7 -3
  314. package/dist/taxonomy/taxonomies.js.map +1 -1
  315. package/dist/tests/builder/recordBuilder/attributeBuilder.js.map +1 -1
  316. package/dist/tests/builder/recordBuilder/entityBuilder.js.map +1 -1
  317. package/dist/tests/builder/recordBuilder/index.d.ts +4 -2
  318. package/dist/tests/builder/recordBuilder/index.js.map +1 -1
  319. package/dist/tests/builder/recordBuilder/nodeBuilder.js.map +1 -1
  320. package/dist/tests/builder/recordBuilder/recordBuilder.js.map +1 -1
  321. package/dist/tests/builder/surveyBuilder/categoryBuilder.js.map +1 -1
  322. package/dist/tests/builder/surveyBuilder/categoryItemBuilder.js.map +1 -1
  323. package/dist/tests/builder/surveyBuilder/index.d.ts +30 -15
  324. package/dist/tests/builder/surveyBuilder/nodeDefAttributeBuilder.js.map +1 -1
  325. package/dist/tests/builder/surveyBuilder/nodeDefBuilder.js.map +1 -1
  326. package/dist/tests/builder/surveyBuilder/nodeDefCodeBuilder.js.map +1 -1
  327. package/dist/tests/builder/surveyBuilder/nodeDefEntityBuilder.js.map +1 -1
  328. package/dist/tests/builder/surveyBuilder/nodeDefTaxonBuilder.js.map +1 -1
  329. package/dist/tests/builder/surveyBuilder/surveyBuilder.js.map +1 -1
  330. package/dist/tests/builder/surveyBuilder/taxonBuilder.js.map +1 -1
  331. package/dist/tests/builder/surveyBuilder/taxonomyBuilder.js.map +1 -1
  332. package/dist/utils/_objects/assoc.js.map +1 -1
  333. package/dist/utils/_objects/assocPath.js.map +1 -1
  334. package/dist/utils/_objects/camelize.js.map +1 -1
  335. package/dist/utils/_objects/deepMerge.js.map +1 -1
  336. package/dist/utils/_objects/deleteEmptyProps.js.map +1 -1
  337. package/dist/utils/_objects/difference.js.map +1 -1
  338. package/dist/utils/_objects/dissoc.js.map +1 -1
  339. package/dist/utils/_objects/dissocPath.js.map +1 -1
  340. package/dist/utils/_objects/dissocPathIfEmpty.js.map +1 -1
  341. package/dist/utils/_objects/index.d.ts +34 -48
  342. package/dist/utils/_objects/isEmpty.js.map +1 -1
  343. package/dist/utils/_objects/isNil.js.map +1 -1
  344. package/dist/utils/_objects/isNotEmpty.js.map +1 -1
  345. package/dist/utils/_objects/parse.js.map +1 -1
  346. package/dist/utils/_objects/path.js.map +1 -1
  347. package/dist/utils/_objects/propertyOf.js.map +1 -1
  348. package/dist/utils/_objects/setInPath.js.map +1 -1
  349. package/dist/utils/_objects/stringify.js.map +1 -1
  350. package/dist/utils/arrays.d.ts +25 -15
  351. package/dist/utils/arrays.js.map +1 -1
  352. package/dist/utils/dates.d.ts +101 -48
  353. package/dist/utils/dates.js.map +1 -1
  354. package/dist/utils/fileNames.d.ts +7 -3
  355. package/dist/utils/fileNames.js.map +1 -1
  356. package/dist/utils/fileProcessor.js +2 -1
  357. package/dist/utils/fileProcessor.js.map +1 -1
  358. package/dist/utils/numbers.d.ts +42 -13
  359. package/dist/utils/numbers.js.map +1 -1
  360. package/dist/utils/promises.d.ts +12 -1
  361. package/dist/utils/queue.js.map +1 -1
  362. package/dist/utils/retryProcessor.js.map +1 -1
  363. package/dist/utils/strings.d.ts +22 -11
  364. package/dist/utils/uuids.d.ts +3 -1
  365. package/dist/utils/versions.d.ts +19 -7
  366. package/dist/utils/versions.js.map +1 -1
  367. package/dist/validation/factory.js.map +1 -1
  368. package/dist/validation/fieldValidators/email.js.map +1 -1
  369. package/dist/validation/fieldValidators/index.d.ts +12 -6
  370. package/dist/validation/fieldValidators/name.js.map +1 -1
  371. package/dist/validation/fieldValidators/notKeyword.js.map +1 -1
  372. package/dist/validation/fieldValidators/numeric.js.map +1 -1
  373. package/dist/validation/fieldValidators/numericPositive.js.map +1 -1
  374. package/dist/validation/fieldValidators/required.js.map +1 -1
  375. package/dist/validation/validation.js.map +1 -1
  376. package/dist/validation/validationResults.d.ts +17 -9
  377. package/dist/validation/validationResults.js +1 -1
  378. package/dist/validation/validationResults.js.map +1 -1
  379. package/dist/validation/validations.d.ts +71 -35
  380. package/dist/validation/validations.js +2 -2
  381. package/dist/validation/validations.js.map +1 -1
  382. package/dist/validation/validator.js.map +1 -1
  383. package/package.json +11 -4
@@ -1 +1 @@
1
- {"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,EAAqB,KAAK,EAAY,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAwD,QAAQ,EAAe,MAAM,eAAe,CAAA;AAC3G,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,MAA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EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../../common'\nimport { SystemError } from '../../error'\nimport { Node, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { Record, RECORD_STEP_DEFAULT } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: Record): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: Record): Dictionary<Node> => record.nodes ?? {}\n\nexport const getNodesArray = (record: Record): Node[] => Object.values(getNodes(record))\n\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: Record): Node | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: Record): Node[] =>\n uuids.map((uuid: string) => getNodeByUuid(uuid)(record)) as Node[]\n\nexport const getRoot = (record: Record): Node | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: Node, childDefUuid?: string) =>\n (record: Record): Node[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\nexport const getChild =\n (parentNode: Node, childDefUuid: string) =>\n (record: Record): Node => {\n const children = getChildren(parentNode, childDefUuid)(record)\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n if (children.length === 1) {\n return children[0]\n }\n if (children.length > 1) {\n throw new SystemError('systemError.record.multipleNodesFound', errorParams)\n }\n throw new SystemError('systemError.record.childNotFound', errorParams)\n }\n\nexport const getParent =\n (node: Node) =>\n (record: Record): Node | undefined =>\n node.parentUuid ? getNodeByUuid(node.parentUuid)(record) : undefined\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: Record): Node[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: Node, nodeDefUuid: string) => boolean) =>\n (params: { record: Record; node: Node }): boolean => {\n const { record, node } = params\n const ancestorsAndSelf = getAncestorsAndSelf({ record, node })\n for (let i = 0; i < ancestorsAndSelf.length - 1; i++) {\n const child = ancestorsAndSelf[i]\n const parent = ancestorsAndSelf[i + 1]\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\nexport const getDependentCodeAttributes =\n (node: Node) =>\n (record: Record): Node[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError('record.nodesIndexNotInitialized')\n }\n\nexport const getParentCodeAttribute =\n (params: { parentNode: Node; nodeDef: NodeDefCode }) =>\n (record: Record): Node | undefined => {\n const { parentNode, nodeDef } = params\n\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf({ record, node: parentNode })\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\nexport const visitAncestorsAndSelf =\n (node: Node, visitor: (node: Node) => void, stopIfFn?: () => boolean) =>\n (record: Record): void => {\n let currentNode: Node | undefined = node\n while (currentNode) {\n visitor(currentNode)\n if (stopIfFn?.()) break\n currentNode = getParent(currentNode)(record)\n }\n }\n\nexport const findAncestor =\n (node: Node, predicate: (node: Node) => boolean) =>\n (record: Record): Node | undefined => {\n let result: Node | undefined = undefined\n visitAncestorsAndSelf(\n node,\n (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n }\n },\n () => !!result\n )(record)\n return result\n }\n\nexport const getAncestor = (params: { record: Record; node: Node; ancestorDefUuid: string }): Node | undefined => {\n const { record, node, ancestorDefUuid } = params\n if (node.nodeDefUuid === ancestorDefUuid) return node\n\n let ancestor = getParent(node)(record)\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParent(ancestor)(record)\n }\n return ancestor\n}\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf = (params: { record: Record; node: Node }): Array<Node> => {\n const { record, node } = params\n const ancestors: Array<Node> = []\n visitAncestorsAndSelf(node, (currentNode) => {\n ancestors.push(currentNode)\n })(record)\n return ancestors\n}\n\n// descendants\n\nexport const getDescendantsOrSelf = (params: {\n record: Record\n node: Node\n nodeDefDescendant: NodeDef<any>\n}): Node[] => {\n const { record, node, nodeDefDescendant } = params\n\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: Node[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n}\n\nexport const getDescendant = (params: { record: Record; node: Node; nodeDefDescendant: NodeDef<any> }): Node => {\n const { record, node, nodeDefDescendant } = params\n\n return getDescendantsOrSelf({ record, node, nodeDefDescendant })[0]\n}\n\nexport const isDescendantOf = (params: { node: Node; ancestor: Node }): boolean => {\n const { node, ancestor } = params\n return Nodes.getHierarchy(node).includes(ancestor.uuid)\n}\n\nexport const visitDescendantsAndSelf = (params: {\n record: Record\n node: Node\n visitor: (node: Node) => boolean | void\n traverseMethod?: TraverseMethod\n}): void => {\n const { record, node, visitor, traverseMethod = TraverseMethod.bfs } = params\n\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as Node\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n}\n\nexport const findDescendantOrSelf =\n (node: Node, predicate: (node: Node) => boolean) =>\n (record: Record): Node | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf({\n record,\n node,\n visitor: (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n },\n })\n return found\n }\n\nconst getClosestAncestorNode = (params: {\n record: Record\n node: Node\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n dependentDef: NodeDef<NodeDefType, NodeDefProps>\n dependencyType: SurveyDependencyType\n}): Node | undefined => {\n const { record, node, nodeDef, dependentDef, dependencyType } = params\n\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor({ record, node, ancestorDefUuid: commonAncestorDefUuid })\n}\n\ntype EntityKeyNodesGetterParams = {\n survey: Survey\n cycle?: string\n record: Record\n entity: Node\n keyDefs?: NodeDef<NodeDefType, NodeDefProps>[]\n}\n\nexport const getEntityKeyNodesByDefUuid = (params: EntityKeyNodesGetterParams): NodesMap => {\n const { survey, cycle, record, entity, keyDefs } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant({ record, node: entity, nodeDefDescendant: nodeDefKey })\n acc[nodeDefKey.uuid] = nodeKey\n return acc\n }, {})\n}\n\nexport const getEntityKeyNodes = (params: EntityKeyNodesGetterParams): Node[] =>\n Object.values(getEntityKeyNodesByDefUuid(params))\n\nexport const getEntityKeyValuesByDefUuid = (params: EntityKeyNodesGetterParams): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(params)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n}\n\nexport const getEntityKeyValues = (params: EntityKeyNodesGetterParams): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(params))\n\nexport const getEntitySiblings = (params: { record: Record; entity: Node; includeSelf?: boolean }) => {\n const { record, entity, includeSelf = false } = params\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n}\n\nexport const getAttributeSiblings = (params: {\n record: Record\n node: Node\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n}) => {\n const { record, node, nodeDef } = params\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings({ record, entity: parentEntity })\n return siblingParentEntities.reduce((siblingsAcc: Node[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n}\n\nexport const getNodeIndex = (params: { record: Record; node: Node }) => {\n const { record, node } = params\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n return siblings.indexOf(node)\n}\n\nexport const findEntityByKeyValues = (params: {\n survey: Survey\n cycle: string\n record: Record\n parentEntity: Node\n entityDefUuid: string\n keyValuesByDefUuid: Dictionary<any>\n}): Node | undefined => {\n const { survey, cycle, record, parentEntity, entityDefUuid, keyValuesByDefUuid } = params\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid({\n survey,\n record,\n entity: siblingEntity,\n keyDefs,\n })\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n}\n\nexport const findEntityWithSameKeysInAnotherRecord = (params: {\n survey: Survey\n cycle: string\n entityUuid: string\n record: Record\n recordOther: Record\n}): Node | undefined => {\n const { survey, cycle, entityUuid, record, recordOther } = params\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf({\n record,\n node: entity,\n })\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid({\n survey,\n record,\n entity: ancestor,\n }),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues({\n survey,\n cycle,\n record: recordOther,\n parentEntity: otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid,\n })\n }\n return otherRecordCurrentParentEntity\n}\n\nexport const getDependentNodePointers = (params: {\n survey: Survey\n record: Record\n node: Node\n dependencyType: SurveyDependencyType\n includeSelf?: boolean\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { survey, record, node, dependencyType, includeSelf = false, filterFn = null } = params\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode({ record, node, nodeDef, dependentDef, dependencyType })\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError('record.nodes.dependents.dependencyOnRootFound')\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf({\n record,\n node: commonAncestorNode,\n nodeDefDescendant: nodeDefDependentParent,\n })\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n}\n\nexport const getAncestorCodePath = (params: {\n survey: Survey\n record: Record\n parentNode: Node\n nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>\n}): string[] => {\n const { record, parentNode, nodeDef, survey } = params\n\n const getCodeAttributeItemCode = (codeAttribute: Node | undefined): string => {\n const codeItemUuid = codeAttribute ? NodeValues.getItemUuid(codeAttribute) : undefined\n if (!codeItemUuid) return ''\n const item = Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n }\n\n const codePaths = []\n let currentParentCodeAttribute = getParentCodeAttribute({ parentNode, nodeDef })(record)\n\n while (currentParentCodeAttribute) {\n const ancestorItemCode = getCodeAttributeItemCode(currentParentCodeAttribute)\n codePaths.unshift(ancestorItemCode)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute({ parentNode, nodeDef: ancestorCodeDef })(record)\n }\n return codePaths\n}\n\nexport const getCategoryItemUuid = (params: {\n survey: Survey\n nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>\n record: Record\n parentNode: Node\n code: string\n}): string | undefined => {\n const { survey, nodeDef, record, parentNode, code } = params\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath({ survey, record, parentNode, nodeDef }), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n}\n\nexport const isNodeFilledByUser =\n (node: Node) =>\n (record: Record): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: Node) =>\n (record: Record): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: Record): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: Record): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: Record): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
1
+ {"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE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,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAc,EAAU,EAAE,wBAAC,MAAM,CAAC,IAAI,mCAAI,mBAAmB,GAAA,CAAA;AAErF,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAW,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../../common'\nimport { SystemError } from '../../error'\nimport { Node, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { Record, RECORD_STEP_DEFAULT } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: Record): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: Record): Dictionary<Node> => record.nodes ?? {}\n\nexport const getNodesArray = (record: Record): Node[] => Object.values(getNodes(record))\n\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: Record): Node | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: Record): Node[] =>\n uuids.map((uuid: string) => getNodeByUuid(uuid)(record)) as Node[]\n\nexport const getRoot = (record: Record): Node | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: Node, childDefUuid?: string) =>\n (record: Record): Node[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\nexport const getChild =\n (parentNode: Node, childDefUuid: string) =>\n (record: Record): Node => {\n const children = getChildren(parentNode, childDefUuid)(record)\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n if (children.length === 1) {\n return children[0]\n }\n if (children.length > 1) {\n throw new SystemError('systemError.record.multipleNodesFound', errorParams)\n }\n throw new SystemError('systemError.record.childNotFound', errorParams)\n }\n\nexport const getParent =\n (node: Node) =>\n (record: Record): Node | undefined =>\n node.parentUuid ? getNodeByUuid(node.parentUuid)(record) : undefined\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: Record): Node[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: Node, nodeDefUuid: string) => boolean) =>\n (params: { record: Record; node: Node }): boolean => {\n const { record, node } = params\n const ancestorsAndSelf = getAncestorsAndSelf({ record, node })\n for (let i = 0; i < ancestorsAndSelf.length - 1; i++) {\n const child = ancestorsAndSelf[i]\n const parent = ancestorsAndSelf[i + 1]\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\nexport const getDependentCodeAttributes =\n (node: Node) =>\n (record: Record): Node[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError('record.nodesIndexNotInitialized')\n }\n\nexport const getParentCodeAttribute =\n (params: { parentNode: Node; nodeDef: NodeDefCode }) =>\n (record: Record): Node | undefined => {\n const { parentNode, nodeDef } = params\n\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf({ record, node: parentNode })\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\nexport const visitAncestorsAndSelf =\n (node: Node, visitor: (node: Node) => void, stopIfFn?: () => boolean) =>\n (record: Record): void => {\n let currentNode: Node | undefined = node\n while (currentNode) {\n visitor(currentNode)\n if (stopIfFn?.()) break\n currentNode = getParent(currentNode)(record)\n }\n }\n\nexport const findAncestor =\n (node: Node, predicate: (node: Node) => boolean) =>\n (record: Record): Node | undefined => {\n let result: Node | undefined = undefined\n visitAncestorsAndSelf(\n node,\n (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n }\n },\n () => !!result\n )(record)\n return result\n }\n\nexport const getAncestor = (params: { record: Record; node: Node; ancestorDefUuid: string }): Node | undefined => {\n const { record, node, ancestorDefUuid } = params\n if (node.nodeDefUuid === ancestorDefUuid) return node\n\n let ancestor = getParent(node)(record)\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParent(ancestor)(record)\n }\n return ancestor\n}\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf = (params: { record: Record; node: Node }): Array<Node> => {\n const { record, node } = params\n const ancestors: Array<Node> = []\n visitAncestorsAndSelf(node, (currentNode) => {\n ancestors.push(currentNode)\n })(record)\n return ancestors\n}\n\n// descendants\n\nexport const getDescendantsOrSelf = (params: {\n record: Record\n node: Node\n nodeDefDescendant: NodeDef<any>\n}): Node[] => {\n const { record, node, nodeDefDescendant } = params\n\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: Node[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n}\n\nexport const getDescendant = (params: { record: Record; node: Node; nodeDefDescendant: NodeDef<any> }): Node => {\n const { record, node, nodeDefDescendant } = params\n\n return getDescendantsOrSelf({ record, node, nodeDefDescendant })[0]\n}\n\nexport const isDescendantOf = (params: { node: Node; ancestor: Node }): boolean => {\n const { node, ancestor } = params\n return Nodes.getHierarchy(node).includes(ancestor.uuid)\n}\n\nexport const visitDescendantsAndSelf = (params: {\n record: Record\n node: Node\n visitor: (node: Node) => boolean | void\n traverseMethod?: TraverseMethod\n}): void => {\n const { record, node, visitor, traverseMethod = TraverseMethod.bfs } = params\n\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as Node\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n}\n\nexport const findDescendantOrSelf =\n (node: Node, predicate: (node: Node) => boolean) =>\n (record: Record): Node | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf({\n record,\n node,\n visitor: (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n },\n })\n return found\n }\n\nconst getClosestAncestorNode = (params: {\n record: Record\n node: Node\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n dependentDef: NodeDef<NodeDefType, NodeDefProps>\n dependencyType: SurveyDependencyType\n}): Node | undefined => {\n const { record, node, nodeDef, dependentDef, dependencyType } = params\n\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor({ record, node, ancestorDefUuid: commonAncestorDefUuid })\n}\n\ntype EntityKeyNodesGetterParams = {\n survey: Survey\n cycle?: string\n record: Record\n entity: Node\n keyDefs?: NodeDef<NodeDefType, NodeDefProps>[]\n}\n\nexport const getEntityKeyNodesByDefUuid = (params: EntityKeyNodesGetterParams): NodesMap => {\n const { survey, cycle, record, entity, keyDefs } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant({ record, node: entity, nodeDefDescendant: nodeDefKey })\n acc[nodeDefKey.uuid] = nodeKey\n return acc\n }, {})\n}\n\nexport const getEntityKeyNodes = (params: EntityKeyNodesGetterParams): Node[] =>\n Object.values(getEntityKeyNodesByDefUuid(params))\n\nexport const getEntityKeyValuesByDefUuid = (params: EntityKeyNodesGetterParams): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(params)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n}\n\nexport const getEntityKeyValues = (params: EntityKeyNodesGetterParams): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(params))\n\nexport const getEntitySiblings = (params: { record: Record; entity: Node; includeSelf?: boolean }) => {\n const { record, entity, includeSelf = false } = params\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n}\n\nexport const getAttributeSiblings = (params: {\n record: Record\n node: Node\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n}) => {\n const { record, node, nodeDef } = params\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings({ record, entity: parentEntity })\n return siblingParentEntities.reduce((siblingsAcc: Node[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n}\n\nexport const getNodeIndex = (params: { record: Record; node: Node }) => {\n const { record, node } = params\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n return siblings.indexOf(node)\n}\n\nexport const findEntityByKeyValues = (params: {\n survey: Survey\n cycle: string\n record: Record\n parentEntity: Node\n entityDefUuid: string\n keyValuesByDefUuid: Dictionary<any>\n}): Node | undefined => {\n const { survey, cycle, record, parentEntity, entityDefUuid, keyValuesByDefUuid } = params\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid({\n survey,\n record,\n entity: siblingEntity,\n keyDefs,\n })\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n}\n\nexport const findEntityWithSameKeysInAnotherRecord = (params: {\n survey: Survey\n cycle: string\n entityUuid: string\n record: Record\n recordOther: Record\n}): Node | undefined => {\n const { survey, cycle, entityUuid, record, recordOther } = params\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf({\n record,\n node: entity,\n })\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid({\n survey,\n record,\n entity: ancestor,\n }),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues({\n survey,\n cycle,\n record: recordOther,\n parentEntity: otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid,\n })\n }\n return otherRecordCurrentParentEntity\n}\n\nexport const getDependentNodePointers = (params: {\n survey: Survey\n record: Record\n node: Node\n dependencyType: SurveyDependencyType\n includeSelf?: boolean\n filterFn?: (nodePointer: NodePointer) => boolean\n}) => {\n const { survey, record, node, dependencyType, includeSelf = false, filterFn = null } = params\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode({ record, node, nodeDef, dependentDef, dependencyType })\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError('record.nodes.dependents.dependencyOnRootFound')\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf({\n record,\n node: commonAncestorNode,\n nodeDefDescendant: nodeDefDependentParent,\n })\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n}\n\nexport const getAncestorCodePath = (params: {\n survey: Survey\n record: Record\n parentNode: Node\n nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>\n}): string[] => {\n const { record, parentNode, nodeDef, survey } = params\n\n const getCodeAttributeItemCode = (codeAttribute: Node | undefined): string => {\n const codeItemUuid = codeAttribute ? NodeValues.getItemUuid(codeAttribute) : undefined\n if (!codeItemUuid) return ''\n const item = Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n }\n\n const codePaths = []\n let currentParentCodeAttribute = getParentCodeAttribute({ parentNode, nodeDef })(record)\n\n while (currentParentCodeAttribute) {\n const ancestorItemCode = getCodeAttributeItemCode(currentParentCodeAttribute)\n codePaths.unshift(ancestorItemCode)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute({ parentNode, nodeDef: ancestorCodeDef })(record)\n }\n return codePaths\n}\n\nexport const getCategoryItemUuid = (params: {\n survey: Survey\n nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>\n record: Record\n parentNode: Node\n code: string\n}): string | undefined => {\n const { survey, nodeDef, record, parentNode, code } = params\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath({ survey, record, parentNode, nodeDef }), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n}\n\nexport const isNodeFilledByUser =\n (node: Node) =>\n (record: Record): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: Node) =>\n (record: Record): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: Record): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: Record): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: Record): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
@@ -1,16 +1,18 @@
1
1
  const getNodeRootUuid = (index) => index.nodeRootUuid;
2
- const getNodeUuidsByDef = (nodeDefUuid) => (index) => { var _a, _b; return Object.keys((_b = (_a = index.nodesByDef) === null || _a === void 0 ? void 0 : _a[nodeDefUuid]) !== null && _b !== void 0 ? _b : {}); };
2
+ const getNodeUuidsByDef = (nodeDefUuid) => (index) => { var _a; var _b; return Object.keys((_b = (_a = index.nodesByDef) === null || _a === void 0 ? void 0 : _a[nodeDefUuid]) !== null && _b !== void 0 ? _b : {}); };
3
3
  const getNodeUuidsByParentAndChildDef = (params) => (index) => {
4
- var _a, _b, _c;
4
+ var _a, _b;
5
+ var _c;
5
6
  const { parentNodeUuid, childDefUuid } = params;
6
7
  return Object.keys((_c = (_b = (_a = index.nodesByParentAndChildDef) === null || _a === void 0 ? void 0 : _a[parentNodeUuid]) === null || _b === void 0 ? void 0 : _b[childDefUuid]) !== null && _c !== void 0 ? _c : {});
7
8
  };
8
9
  const getNodeUuidsByParent = (parentNodeUuid) => (index) => {
9
- var _a, _b;
10
+ var _a;
11
+ var _b;
10
12
  const nodesPresenceByChildDefUuid = (_b = (_a = index.nodesByParentAndChildDef) === null || _a === void 0 ? void 0 : _a[parentNodeUuid]) !== null && _b !== void 0 ? _b : {};
11
13
  return Object.values(nodesPresenceByChildDefUuid).flatMap((nodesPresence) => Object.keys(nodesPresence));
12
14
  };
13
- const getNodeCodeDependentUuids = (nodeUuid) => (index) => { var _a, _b; return Object.keys((_b = (_a = index.nodeCodeDependents) === null || _a === void 0 ? void 0 : _a[nodeUuid]) !== null && _b !== void 0 ? _b : {}); };
15
+ const getNodeCodeDependentUuids = (nodeUuid) => (index) => { var _a; var _b; return Object.keys((_b = (_a = index.nodeCodeDependents) === null || _a === void 0 ? void 0 : _a[nodeUuid]) !== null && _b !== void 0 ? _b : {}); };
14
16
  export const RecordNodesIndexReader = {
15
17
  getNodeRootUuid,
16
18
  getNodeUuidsByDef,
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodesIndexReader.js","sourceRoot":"","sources":["../../../../src/record/_records/recordNodesIndexReader.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAsB,EAAE,CAAC,KAAK,CAAC,YAAY,CAAA;AAE3F,MAAM,iBAAiB,GACrB,CAAC,WAAmB,EAAE,EAAE,CACxB,CAAC,KAAuB,EAAY,EAAE,eACpC,OAAA,MAAM,CAAC,IAAI,CAAC,MAAA,MAAA,KAAK,CAAC,UAAU,0CAAG,WAAW,CAAC,mCAAI,EAAE,CAAC,CAAA,EAAA,CAAA;AAEtD,MAAM,+BAA+B,GACnC,CAAC,MAAwD,EAAE,EAAE,CAC7D,CAAC,KAAuB,EAAY,EAAE;;IACpC,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IAC/C,OAAO,MAAM,CAAC,IAAI,CAAC,MAAA,MAAA,MAAA,KAAK,CAAC,wBAAwB,0CAAG,cAAc,CAAC,0CAAG,YAAY,CAAC,mCAAI,EAAE,CAAC,CAAA;AAC5F,CAAC,CAAA;AAEH,MAAM,oBAAoB,GACxB,CAAC,cAAsB,EAAE,EAAE,CAC3B,CAAC,KAAuB,EAAY,EAAE;;IACpC,MAAM,2BAA2B,GAAG,MAAA,MAAA,KAAK,CAAC,wBAAwB,0CAAG,cAAc,CAAC,mCAAI,EAAE,CAAA;IAC1F,OAAO,MAAM,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAA;AAC1G,CAAC,CAAA;AAEH,MAAM,yBAAyB,GAC7B,CAAC,QAAgB,EAAE,EAAE,CACrB,CAAC,KAAuB,EAAY,EAAE,eACpC,OAAA,MAAM,CAAC,IAAI,CAAC,MAAA,MAAA,KAAK,CAAC,kBAAkB,0CAAG,QAAQ,CAAC,mCAAI,EAAE,CAAC,CAAA,EAAA,CAAA;AAE3D,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,eAAe;IACf,iBAAiB;IACjB,+BAA+B;IAC/B,oBAAoB;IACpB,yBAAyB;CAC1B,CAAA","sourcesContent":["import { RecordNodesIndex } from '../record'\n\nconst getNodeRootUuid = (index: RecordNodesIndex): string | undefined => index.nodeRootUuid\n\nconst getNodeUuidsByDef =\n (nodeDefUuid: string) =>\n (index: RecordNodesIndex): string[] =>\n Object.keys(index.nodesByDef?.[nodeDefUuid] ?? {})\n\nconst getNodeUuidsByParentAndChildDef =\n (params: { parentNodeUuid: string; childDefUuid: string }) =>\n (index: RecordNodesIndex): string[] => {\n const { parentNodeUuid, childDefUuid } = params\n return Object.keys(index.nodesByParentAndChildDef?.[parentNodeUuid]?.[childDefUuid] ?? {})\n }\n\nconst getNodeUuidsByParent =\n (parentNodeUuid: string) =>\n (index: RecordNodesIndex): string[] => {\n const nodesPresenceByChildDefUuid = index.nodesByParentAndChildDef?.[parentNodeUuid] ?? {}\n return Object.values(nodesPresenceByChildDefUuid).flatMap((nodesPresence) => Object.keys(nodesPresence))\n }\n\nconst getNodeCodeDependentUuids =\n (nodeUuid: string) =>\n (index: RecordNodesIndex): string[] =>\n Object.keys(index.nodeCodeDependents?.[nodeUuid] ?? {})\n\nexport const RecordNodesIndexReader = {\n getNodeRootUuid,\n getNodeUuidsByDef,\n getNodeUuidsByParentAndChildDef,\n getNodeUuidsByParent,\n getNodeCodeDependentUuids,\n}\n"]}
1
+ {"version":3,"file":"recordNodesIndexReader.js","sourceRoot":"","sources":["../../../../src/record/_records/recordNodesIndexReader.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG,CAAC,KAAuB,EAAsB,EAAE,CAAC,KAAK,CAAC,YAAY,CAAA;AAE3F,MAAM,iBAAiB,GACrB,CAAC,WAAmB,EAAE,EAAE,CACxB,CAAC,KAAuB,EAAY,EAAE,0BACpC,MAAM,CAAC,IAAI,OAAC,MAAA,KAAK,CAAC,UAAU,0CAAG,WAAW,CAAC,mCAAI,EAAE,CAAC,GAAA,CAAA;AAEtD,MAAM,+BAA+B,GACnC,CAAC,MAAwD,EAAE,EAAE,CAC7D,CAAC,KAAuB,EAAY,EAAE;;;IACpC,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IAC/C,OAAO,MAAM,CAAC,IAAI,OAAC,MAAA,MAAA,KAAK,CAAC,wBAAwB,0CAAG,cAAc,CAAC,0CAAG,YAAY,CAAC,mCAAI,EAAE,CAAC,CAAA;AAC5F,CAAC,CAAA;AAEH,MAAM,oBAAoB,GACxB,CAAC,cAAsB,EAAE,EAAE,CAC3B,CAAC,KAAuB,EAAY,EAAE;;;IACpC,MAAM,2BAA2B,SAAG,MAAA,KAAK,CAAC,wBAAwB,0CAAG,cAAc,CAAC,mCAAI,EAAE,CAAA;IAC1F,OAAO,MAAM,CAAC,MAAM,CAAC,2BAA2B,CAAC,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAA;AAC1G,CAAC,CAAA;AAEH,MAAM,yBAAyB,GAC7B,CAAC,QAAgB,EAAE,EAAE,CACrB,CAAC,KAAuB,EAAY,EAAE,0BACpC,MAAM,CAAC,IAAI,OAAC,MAAA,KAAK,CAAC,kBAAkB,0CAAG,QAAQ,CAAC,mCAAI,EAAE,CAAC,GAAA,CAAA;AAE3D,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,eAAe;IACf,iBAAiB;IACjB,+BAA+B;IAC/B,oBAAoB;IACpB,yBAAyB;CAC1B,CAAA","sourcesContent":["import { RecordNodesIndex } from '../record'\n\nconst getNodeRootUuid = (index: RecordNodesIndex): string | undefined => index.nodeRootUuid\n\nconst getNodeUuidsByDef =\n (nodeDefUuid: string) =>\n (index: RecordNodesIndex): string[] =>\n Object.keys(index.nodesByDef?.[nodeDefUuid] ?? {})\n\nconst getNodeUuidsByParentAndChildDef =\n (params: { parentNodeUuid: string; childDefUuid: string }) =>\n (index: RecordNodesIndex): string[] => {\n const { parentNodeUuid, childDefUuid } = params\n return Object.keys(index.nodesByParentAndChildDef?.[parentNodeUuid]?.[childDefUuid] ?? {})\n }\n\nconst getNodeUuidsByParent =\n (parentNodeUuid: string) =>\n (index: RecordNodesIndex): string[] => {\n const nodesPresenceByChildDefUuid = index.nodesByParentAndChildDef?.[parentNodeUuid] ?? {}\n return Object.values(nodesPresenceByChildDefUuid).flatMap((nodesPresence) => Object.keys(nodesPresence))\n }\n\nconst getNodeCodeDependentUuids =\n (nodeUuid: string) =>\n (index: RecordNodesIndex): string[] =>\n Object.keys(index.nodeCodeDependents?.[nodeUuid] ?? {})\n\nexport const RecordNodesIndexReader = {\n getNodeRootUuid,\n getNodeUuidsByDef,\n getNodeUuidsByParentAndChildDef,\n getNodeUuidsByParent,\n getNodeCodeDependentUuids,\n}\n"]}
@@ -7,14 +7,15 @@ const keys = {
7
7
  nodeCodeDependents: 'nodeCodeDependents',
8
8
  };
9
9
  const sortNodesByIdOrCreationDate = (nodeA, nodeB) => {
10
- var _a, _b, _c, _d, _e, _f;
10
+ var _a, _b, _c, _d;
11
+ var _e, _f;
11
12
  if (!nodeA.parentUuid)
12
13
  return -1;
13
14
  if (!nodeB.parentUuid)
14
15
  return 1;
15
16
  // read the hierarchy length directly: Nodes.getHierarchy copies the array on every comparison
16
- const hierarchyDepthA = (_c = (_b = (_a = nodeA.meta) === null || _a === void 0 ? void 0 : _a.h) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
17
- const hierarchyDepthB = (_f = (_e = (_d = nodeB.meta) === null || _d === void 0 ? void 0 : _d.h) === null || _e === void 0 ? void 0 : _e.length) !== null && _f !== void 0 ? _f : 0;
17
+ const hierarchyDepthA = (_e = (_b = (_a = nodeA.meta) === null || _a === void 0 ? void 0 : _a.h) === null || _b === void 0 ? void 0 : _b.length) !== null && _e !== void 0 ? _e : 0;
18
+ const hierarchyDepthB = (_f = (_d = (_c = nodeB.meta) === null || _c === void 0 ? void 0 : _c.h) === null || _d === void 0 ? void 0 : _d.length) !== null && _f !== void 0 ? _f : 0;
18
19
  const depthDiff = hierarchyDepthA - hierarchyDepthB;
19
20
  if (depthDiff !== 0)
20
21
  return depthDiff;
@@ -81,7 +82,8 @@ class NodesIndexDraft {
81
82
  }
82
83
  }
83
84
  addNode(node) {
84
- var _a, _b;
85
+ var _a;
86
+ var _b;
85
87
  const { uuid: nodeUuid, nodeDefUuid, parentUuid } = node;
86
88
  if (parentUuid) {
87
89
  // nodes by parent and child def uuid
@@ -136,9 +138,10 @@ const removeNodes = (nodes, sideEffect = false) => (index) => {
136
138
  };
137
139
  const removeNode = (node, sideEffect = false) => (index) => removeNodes([node], sideEffect)(index);
138
140
  const _isSameHierarchyCode = (nodeA, nodeB) => {
139
- var _a, _b, _c, _d;
140
- const hCodeA = (_b = (_a = nodeA.meta) === null || _a === void 0 ? void 0 : _a.hCode) !== null && _b !== void 0 ? _b : [];
141
- const hCodeB = (_d = (_c = nodeB.meta) === null || _c === void 0 ? void 0 : _c.hCode) !== null && _d !== void 0 ? _d : [];
141
+ var _a, _b;
142
+ var _c, _d;
143
+ const hCodeA = (_c = (_a = nodeA.meta) === null || _a === void 0 ? void 0 : _a.hCode) !== null && _c !== void 0 ? _c : [];
144
+ const hCodeB = (_d = (_b = nodeB.meta) === null || _b === void 0 ? void 0 : _b.hCode) !== null && _d !== void 0 ? _d : [];
142
145
  return hCodeA.length === hCodeB.length && hCodeA.every((uuid, index) => uuid === hCodeB[index]);
143
146
  };
144
147
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodesIndexUpdater.js","sourceRoot":"","sources":["../../../../src/record/_records/recordNodesIndexUpdater.ts"],"names":[],"mappings":"AAAA,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,CAAC,wBAAwB,0CAAG,UAAU,CAAC,0CAAG,WAAW,CAAC,0CAAG,IAAI,CAAC,CAAA;QACvE,CAAC,CAAC,KAAK,CAAC,YAAY,KAAK,IAAI,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,OAAO;IACP,QAAQ;IACR,eAAe;IACf,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Node, Nodes } from '../../node'\nimport { Objects } from '../../utils'\nimport { Record, RecordNodesIndex } from '../record'\n\nconst keys = {\n nodeRootUuid: 'nodeRootUuid',\n nodesByParentAndChildDef: 'nodesByParentAndChildDef',\n nodesByDef: 'nodesByDef',\n nodeCodeDependents: 'nodeCodeDependents',\n}\n\nconst sortNodesByIdOrCreationDate = (nodeA: Node, nodeB: Node): number => {\n if (!nodeA.parentUuid) return -1\n if (!nodeB.parentUuid) return 1\n // read the hierarchy length directly: Nodes.getHierarchy copies the array on every comparison\n const hierarchyDepthA = nodeA.meta?.h?.length ?? 0\n const hierarchyDepthB = nodeB.meta?.h?.length ?? 0\n const depthDiff = hierarchyDepthA - hierarchyDepthB\n if (depthDiff !== 0) return depthDiff\n if (nodeA.id && nodeB.id) return nodeA.id - nodeB.id\n if (nodeA.dateCreated && nodeB.dateCreated) return nodeA.dateCreated.localeCompare(nodeB.dateCreated)\n return 0\n}\n\n/**\n * Mutable copy of a nodes index, used to apply many changes to it at once.\n * When sideEffect is false, every object along a modified path is copied only the first time it is modified\n * (copy on write): applying N changes costs one copy of each touched object instead of N copies.\n */\nclass NodesIndexDraft {\n readonly index: RecordNodesIndex\n private readonly sideEffect: boolean\n private readonly copiedObjects = new Set<object>()\n\n constructor(index: RecordNodesIndex, sideEffect: boolean) {\n this.sideEffect = sideEffect\n this.index = sideEffect ? index : this.markCopied({ ...index })\n }\n\n private markCopied<T extends object>(obj: T): T {\n this.copiedObjects.add(obj)\n return obj\n }\n\n private getWritableChild(parent: any, key: string, createIfMissing: boolean): any {\n const child = parent[key]\n if (child === undefined || child === null) {\n if (!createIfMissing) return undefined\n const childCreated = this.markCopied({})\n parent[key] = childCreated\n return childCreated\n }\n if (this.sideEffect || this.copiedObjects.has(child)) return child\n const childCopy = this.markCopied({ ...child })\n parent[key] = childCopy\n return childCopy\n }\n\n set(path: string[], value: any): void {\n let current: any = this.index\n for (let i = 0; i < path.length - 1; i++) {\n current = this.getWritableChild(current, path[i], true)\n }\n current[path.at(-1)!] = value\n }\n\n /**\n * Deletes the value at the specified path, then removes the objects along the path left empty.\n */\n delete(path: string[]): void {\n const containers: any[] = [this.index]\n let current: any = this.index\n for (let i = 0; i < path.length - 1; i++) {\n if (current[path[i]] === undefined) return\n current = this.getWritableChild(current, path[i], false)\n containers.push(current)\n }\n delete current[path.at(-1)!]\n for (let i = path.length - 2; i >= 0; i--) {\n if (!Objects.isEmpty(containers[i + 1])) break\n delete containers[i][path[i]]\n }\n }\n\n addNode(node: Node): void {\n const { uuid: nodeUuid, nodeDefUuid, parentUuid } = node\n if (parentUuid) {\n // nodes by parent and child def uuid\n this.set([keys.nodesByParentAndChildDef, parentUuid, nodeDefUuid, nodeUuid], true)\n } else {\n // root entity index\n this.index.nodeRootUuid = nodeUuid\n }\n // nodes by def uuid\n this.set([keys.nodesByDef, nodeDefUuid, nodeUuid], true)\n // code dependents\n for (const ancestorCodeAttributeUuid of node.meta?.hCode ?? []) {\n this.set([keys.nodeCodeDependents, ancestorCodeAttributeUuid, nodeUuid], true)\n }\n }\n\n removeNode(node: Node): void {\n const { uuid: nodeUuid, parentUuid, nodeDefUuid } = node\n if (parentUuid) {\n this.delete([keys.nodesByParentAndChildDef, parentUuid, nodeDefUuid, nodeUuid])\n } else {\n delete this.index.nodeRootUuid\n }\n this.delete([keys.nodesByDef, nodeDefUuid, nodeUuid])\n // code dependents\n for (const ancestorCodeAttributeUuid of Nodes.getHierarchyCode(node)) {\n this.delete([keys.nodeCodeDependents, ancestorCodeAttributeUuid, nodeUuid])\n }\n this.delete([keys.nodeCodeDependents, nodeUuid])\n }\n}\n\nconst addNodes =\n (nodes: { [key: string]: Node }, sideEffect = false, sortNodes = false) =>\n (index: RecordNodesIndex): RecordNodesIndex => {\n const draft = new NodesIndexDraft(index, sideEffect)\n const nodesArray = Object.values(nodes)\n if (sortNodes) {\n nodesArray.sort(sortNodesByIdOrCreationDate)\n }\n for (const node of nodesArray) {\n draft.addNode(node)\n }\n return draft.index\n }\n\nconst addNode =\n (node: Node) =>\n (index: RecordNodesIndex): RecordNodesIndex =>\n addNodes({ [node.uuid]: node })(index)\n\nconst initializeIndex = (record: Record): RecordNodesIndex => addNodes(record.nodes ?? {}, true, true)({})\n\nconst removeNodes =\n (nodes: Node[], sideEffect = false) =>\n (index: RecordNodesIndex): RecordNodesIndex => {\n const draft = new NodesIndexDraft(index, sideEffect)\n for (const node of nodes) {\n draft.removeNode(node)\n }\n return draft.index\n }\n\nconst removeNode =\n (node: Node, sideEffect = false) =>\n (index: RecordNodesIndex): RecordNodesIndex =>\n removeNodes([node], sideEffect)(index)\n\nconst _isSameHierarchyCode = (nodeA: Node, nodeB: Node): boolean => {\n const hCodeA = nodeA.meta?.hCode ?? []\n const hCodeB = nodeB.meta?.hCode ?? []\n return hCodeA.length === hCodeB.length && hCodeA.every((uuid, index) => uuid === hCodeB[index])\n}\n\n/**\n * Returns true if the index entries of the specified node would not change when the node replaces the previous version of it.\n */\nconst isNodeIndexUnchanged = (params: { index: RecordNodesIndex; node: Node; nodePrev?: Node }): boolean => {\n const { index, node, nodePrev } = params\n if (!nodePrev) return false\n const { uuid, parentUuid, nodeDefUuid } = node\n if (parentUuid !== nodePrev.parentUuid || nodeDefUuid !== nodePrev.nodeDefUuid) return false\n if (!_isSameHierarchyCode(node, nodePrev)) return false\n if (!index.nodesByDef?.[nodeDefUuid]?.[uuid]) return false\n return parentUuid\n ? !!index.nodesByParentAndChildDef?.[parentUuid]?.[nodeDefUuid]?.[uuid]\n : index.nodeRootUuid === uuid\n}\n\nexport const RecordNodesIndexUpdater = {\n addNode,\n addNodes,\n initializeIndex,\n isNodeIndexUnchanged,\n removeNode,\n removeNodes,\n}\n"]}
1
+ {"version":3,"file":"recordNodesIndexUpdater.js","sourceRoot":"","sources":["../../../../src/record/_records/recordNodesIndexUpdater.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAGrC,MAAM,IAAI,GAAG;IACX,YAAY,EAAE,cAAc;IAC5B,wBAAwB,EAAE,0BAA0B;IACpD,UAAU,EAAE,YAAY;IACxB,kBAAkB,EAAE,oBAAoB;CACzC,CAAA;AAED,MAAM,2BAA2B,GAAG,CAAC,KAAW,EAAE,KAAW,EAAU,EAAE;;;IACvE,IAAI,CAAC,KAAK,CAAC,UAAU;QAAE,OAAO,CAAC,CAAC,CAAA;IAChC,IAAI,CAAC,KAAK,CAAC,UAAU;QAAE,OAAO,CAAC,CAAA;IAC/B,8FAA8F;IAC9F,MAAM,eAAe,SAAG,MAAA,MAAA,KAAK,CAAC,IAAI,0CAAE,CAAC,0CAAE,MAAM,mCAAI,CAAC,CAAA;IAClD,MAAM,eAAe,SAAG,MAAA,MAAA,KAAK,CAAC,IAAI,0CAAE,CAAC,0CAAE,MAAM,mCAAI,CAAC,CAAA;IAClD,MAAM,SAAS,GAAG,eAAe,GAAG,eAAe,CAAA;IACnD,IAAI,SAAS,KAAK,CAAC;QAAE,OAAO,SAAS,CAAA;IACrC,IAAI,KAAK,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE;QAAE,OAAO,KAAK,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAA;IACpD,IAAI,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW;QAAE,OAAO,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;IACrG,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;A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AAU,0CAAG,WAAW,CAAC,0CAAG,IAAI,CAAC,CAAA;QAAE,OAAO,KAAK,CAAA;IAC1D,OAAO,UAAU;QACf,CAAC,CAAC,CAAC,EAAC,MAAA,MAAA,MAAA,KAAK,CAAC,wBAAwB,0CAAG,UAAU,CAAC,0CAAG,WAAW,CAAC,0CAAG,IAAI,CAAC,CAAA;QACvE,CAAC,CAAC,KAAK,CAAC,YAAY,KAAK,IAAI,CAAA;AACjC,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,OAAO;IACP,QAAQ;IACR,eAAe;IACf,oBAAoB;IACpB,UAAU;IACV,WAAW;CACZ,CAAA","sourcesContent":["import { Node, Nodes } from '../../node'\nimport { Objects } from '../../utils'\nimport { Record, RecordNodesIndex } from '../record'\n\nconst keys = {\n nodeRootUuid: 'nodeRootUuid',\n nodesByParentAndChildDef: 'nodesByParentAndChildDef',\n nodesByDef: 'nodesByDef',\n nodeCodeDependents: 'nodeCodeDependents',\n}\n\nconst sortNodesByIdOrCreationDate = (nodeA: Node, nodeB: Node): number => {\n if (!nodeA.parentUuid) return -1\n if (!nodeB.parentUuid) return 1\n // read the hierarchy length directly: Nodes.getHierarchy copies the array on every comparison\n const hierarchyDepthA = nodeA.meta?.h?.length ?? 0\n const hierarchyDepthB = nodeB.meta?.h?.length ?? 0\n const depthDiff = hierarchyDepthA - hierarchyDepthB\n if (depthDiff !== 0) return depthDiff\n if (nodeA.id && nodeB.id) return nodeA.id - nodeB.id\n if (nodeA.dateCreated && nodeB.dateCreated) return nodeA.dateCreated.localeCompare(nodeB.dateCreated)\n return 0\n}\n\n/**\n * Mutable copy of a nodes index, used to apply many changes to it at once.\n * When sideEffect is false, every object along a modified path is copied only the first time it is modified\n * (copy on write): applying N changes costs one copy of each touched object instead of N copies.\n */\nclass NodesIndexDraft {\n readonly index: RecordNodesIndex\n private readonly sideEffect: boolean\n private readonly copiedObjects = new Set<object>()\n\n constructor(index: RecordNodesIndex, sideEffect: boolean) {\n this.sideEffect = sideEffect\n this.index = sideEffect ? index : this.markCopied({ ...index })\n }\n\n private markCopied<T extends object>(obj: T): T {\n this.copiedObjects.add(obj)\n return obj\n }\n\n private getWritableChild(parent: any, key: string, createIfMissing: boolean): any {\n const child = parent[key]\n if (child === undefined || child === null) {\n if (!createIfMissing) return undefined\n const childCreated = this.markCopied({})\n parent[key] = childCreated\n return childCreated\n }\n if (this.sideEffect || this.copiedObjects.has(child)) return child\n const childCopy = this.markCopied({ ...child })\n parent[key] = childCopy\n return childCopy\n }\n\n set(path: string[], value: any): void {\n let current: any = this.index\n for (let i = 0; i < path.length - 1; i++) {\n current = this.getWritableChild(current, path[i], true)\n }\n current[path.at(-1)!] = value\n }\n\n /**\n * Deletes the value at the specified path, then removes the objects along the path left empty.\n */\n delete(path: string[]): void {\n const containers: any[] = [this.index]\n let current: any = this.index\n for (let i = 0; i < path.length - 1; i++) {\n if (current[path[i]] === undefined) return\n current = this.getWritableChild(current, path[i], false)\n containers.push(current)\n }\n delete current[path.at(-1)!]\n for (let i = path.length - 2; i >= 0; i--) {\n if (!Objects.isEmpty(containers[i + 1])) break\n delete containers[i][path[i]]\n }\n }\n\n addNode(node: Node): void {\n const { uuid: nodeUuid, nodeDefUuid, parentUuid } = node\n if (parentUuid) {\n // nodes by parent and child def uuid\n this.set([keys.nodesByParentAndChildDef, parentUuid, nodeDefUuid, nodeUuid], true)\n } else {\n // root entity index\n this.index.nodeRootUuid = nodeUuid\n }\n // nodes by def uuid\n this.set([keys.nodesByDef, nodeDefUuid, nodeUuid], true)\n // code dependents\n for (const ancestorCodeAttributeUuid of node.meta?.hCode ?? []) {\n this.set([keys.nodeCodeDependents, ancestorCodeAttributeUuid, nodeUuid], true)\n }\n }\n\n removeNode(node: Node): void {\n const { uuid: nodeUuid, parentUuid, nodeDefUuid } = node\n if (parentUuid) {\n this.delete([keys.nodesByParentAndChildDef, parentUuid, nodeDefUuid, nodeUuid])\n } else {\n delete this.index.nodeRootUuid\n }\n this.delete([keys.nodesByDef, nodeDefUuid, nodeUuid])\n // code dependents\n for (const ancestorCodeAttributeUuid of Nodes.getHierarchyCode(node)) {\n this.delete([keys.nodeCodeDependents, ancestorCodeAttributeUuid, nodeUuid])\n }\n this.delete([keys.nodeCodeDependents, nodeUuid])\n }\n}\n\nconst addNodes =\n (nodes: { [key: string]: Node }, sideEffect = false, sortNodes = false) =>\n (index: RecordNodesIndex): RecordNodesIndex => {\n const draft = new NodesIndexDraft(index, sideEffect)\n const nodesArray = Object.values(nodes)\n if (sortNodes) {\n nodesArray.sort(sortNodesByIdOrCreationDate)\n }\n for (const node of nodesArray) {\n draft.addNode(node)\n }\n return draft.index\n }\n\nconst addNode =\n (node: Node) =>\n (index: RecordNodesIndex): RecordNodesIndex =>\n addNodes({ [node.uuid]: node })(index)\n\nconst initializeIndex = (record: Record): RecordNodesIndex => addNodes(record.nodes ?? {}, true, true)({})\n\nconst removeNodes =\n (nodes: Node[], sideEffect = false) =>\n (index: RecordNodesIndex): RecordNodesIndex => {\n const draft = new NodesIndexDraft(index, sideEffect)\n for (const node of nodes) {\n draft.removeNode(node)\n }\n return draft.index\n }\n\nconst removeNode =\n (node: Node, sideEffect = false) =>\n (index: RecordNodesIndex): RecordNodesIndex =>\n removeNodes([node], sideEffect)(index)\n\nconst _isSameHierarchyCode = (nodeA: Node, nodeB: Node): boolean => {\n const hCodeA = nodeA.meta?.hCode ?? []\n const hCodeB = nodeB.meta?.hCode ?? []\n return hCodeA.length === hCodeB.length && hCodeA.every((uuid, index) => uuid === hCodeB[index])\n}\n\n/**\n * Returns true if the index entries of the specified node would not change when the node replaces the previous version of it.\n */\nconst isNodeIndexUnchanged = (params: { index: RecordNodesIndex; node: Node; nodePrev?: Node }): boolean => {\n const { index, node, nodePrev } = params\n if (!nodePrev) return false\n const { uuid, parentUuid, nodeDefUuid } = node\n if (parentUuid !== nodePrev.parentUuid || nodeDefUuid !== nodePrev.nodeDefUuid) return false\n if (!_isSameHierarchyCode(node, nodePrev)) return false\n if (!index.nodesByDef?.[nodeDefUuid]?.[uuid]) return false\n return parentUuid\n ? !!index.nodesByParentAndChildDef?.[parentUuid]?.[nodeDefUuid]?.[uuid]\n : index.nodeRootUuid === uuid\n}\n\nexport const RecordNodesIndexUpdater = {\n addNode,\n addNodes,\n initializeIndex,\n isNodeIndexUnchanged,\n removeNode,\n removeNodes,\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"recordPagesValidation.js","sourceRoot":"","sources":["../../../../src/record/_records/recordPagesValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAU,OAAO,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAmBrF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAA+D,EAAW,EAAE;IAC5G,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;IAChD,IAAI,IAAI,CAAC,WAAW,KAAK,eAAe;QAAE,OAAO,IAAI,CAAA;IACrD,OAAO,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;QACpD,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAA;QACpD,OAAO,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,WAAW,MAAK,eAAe,CAAA;IAClD,CAAC,CAAC,CAAA;AACJ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CAAC,CAAA;IAC3D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA;AAC5C,CAAC,CAAA","sourcesContent":["import { Node, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Survey, Surveys } from '../../survey'\nimport { Validations } from '../../validation'\nimport { Record } from '../record'\nimport { RecordValidations } from '../recordValidations'\nimport { getEntityCompletionStats } from './recordCompletion'\nimport { getCycle, getNodeByUuid, getNodesByDefUuid, getRoot } from './recordGetters'\n\nexport type PageValidationStatus = {\n hasErrors: boolean\n hasWarnings: boolean\n}\n\nexport type EntitySubtreeStatus = {\n hasErrors: boolean\n hasWarnings: boolean\n isComplete: boolean\n}\n\nexport type PagesValidationProgress = {\n percent: number\n validCount: number\n totalCount: number\n}\n\n/**\n * Whether a node belongs under a page entity (itself or any descendant of that page).\n */\nexport const nodeBelongsToPage = (params: { node: Node; pageNodeDefUuid: string; record: Record }): boolean => {\n const { node, pageNodeDefUuid, record } = params\n if (node.nodeDefUuid === pageNodeDefUuid) return true\n return Nodes.getHierarchy(node).some((ancestorUuid) => {\n const ancestor = getNodeByUuid(ancestorUuid)(record)\n return ancestor?.nodeDefUuid === pageNodeDefUuid\n })\n}\n\n/**\n * Whether a node belongs to this page only — not to a nested descendant page entity.\n * When descendantPageUuids is empty, all nodes under the page hierarchy are included.\n */\nexport const nodeBelongsToOwnPage = (params: {\n node: Node\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n record: Record\n}): boolean => {\n const { node, pageNodeDefUuid, descendantPageUuids, record } = params\n if (!nodeBelongsToPage({ node, pageNodeDefUuid, record })) return false\n if (descendantPageUuids.includes(node.nodeDefUuid)) return false\n return !descendantPageUuids.some((descendantUuid) =>\n nodeBelongsToPage({ node, pageNodeDefUuid: descendantUuid, record })\n )\n}\n\n/**\n * Child page-entity defs displayed in their own page under the given entity.\n */\nexport const getNodeDefChildrenInOwnPage = (params: {\n survey: Survey\n nodeDef: NodeDefEntity\n cycle: string\n}): NodeDefEntity[] => {\n const { survey, nodeDef, cycle } = params\n return Surveys.getNodeDefChildren({ survey, nodeDef, includeAnalysis: true }).filter(\n (child): child is NodeDefEntity => {\n if (!NodeDefs.isEntity(child)) return false\n return NodeDefs.isDisplayInOwnPage(cycle)(child as NodeDefEntity)\n }\n )\n}\n\n/**\n * Collects all page-entity node defs in the survey cycle (root + nested own-pages).\n */\nexport const getPageNodeDefs = (params: { survey: Survey; cycle: string }): NodeDefEntity[] => {\n const { survey, cycle } = params\n const root = Surveys.getNodeDefRoot({ survey }) as NodeDefEntity | undefined\n if (!root) return []\n\n const pages: NodeDefEntity[] = []\n const stack: NodeDefEntity[] = [root]\n while (stack.length > 0) {\n const current = stack.pop()\n if (!current) continue\n pages.push(current)\n stack.push(...getNodeDefChildrenInOwnPage({ survey, nodeDef: current, cycle }))\n }\n return pages\n}\n\n/**\n * Collects descendant page node def UUIDs under a page (not including the page itself).\n */\nexport const getDescendantPageNodeDefUuids = (params: {\n survey: Survey\n cycle: string\n pageNodeDef: NodeDefEntity\n}): string[] => {\n const { survey, cycle, pageNodeDef } = params\n const uuids: string[] = []\n const visit = (nodeDef: NodeDefEntity) => {\n const children = getNodeDefChildrenInOwnPage({ survey, nodeDef, cycle })\n for (const child of children) {\n uuids.push(child.uuid)\n visit(child)\n }\n }\n visit(pageNodeDef)\n return uuids\n}\n\nconst nodeIsUnderEntity = (params: { node: Node; entityUuid: string }): boolean => {\n const { node, entityUuid } = params\n if (node.uuid === entityUuid) return true\n return Nodes.getHierarchy(node).includes(entityUuid)\n}\n\nconst getOwnPageFieldValidationFlags = (params: {\n nodeUuid: string\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n scopeEntityUuid?: string\n record: Record\n recordValidation: ReturnType<typeof Validations.getValidation>\n}): PageValidationStatus | null => {\n const { nodeUuid, pageNodeDefUuid, descendantPageUuids, scopeEntityUuid, record, recordValidation } = params\n\n if (RecordValidations.isValidationChildrenCountKey(nodeUuid)) {\n return getOwnPageChildrenCountValidationFlags({\n childrenCountKey: nodeUuid,\n pageNodeDefUuid,\n descendantPageUuids,\n scopeEntityUuid,\n record,\n recordValidation,\n })\n }\n\n const node = getNodeByUuid(nodeUuid)(record)\n if (!node || !nodeBelongsToOwnPage({ node, pageNodeDefUuid, descendantPageUuids, record })) return null\n if (scopeEntityUuid && !nodeIsUnderEntity({ node, entityUuid: scopeEntityUuid })) return null\n\n const nodeValidation = RecordValidations.getValidationNode({ nodeUuid })(recordValidation)\n if (!nodeValidation) return null\n\n return {\n hasErrors: Validations.hasErrors(nodeValidation),\n hasWarnings: Validations.hasWarnings(nodeValidation),\n }\n}\n\n/**\n * Children-count validations (file min count, inline multiple min/max, etc.) are keyed as\n * `childrenCount_{parentUuid}_{childDefUuid}`, not as node UUIDs.\n * Include them when the parent is on this page, but skip counts that refer to descendant\n * page entities (missing sub-page instances should not paint the parent page red).\n */\nconst getOwnPageChildrenCountValidationFlags = (params: {\n childrenCountKey: string\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n scopeEntityUuid?: string\n record: Record\n recordValidation: ReturnType<typeof Validations.getValidation>\n}): PageValidationStatus | null => {\n const { childrenCountKey, pageNodeDefUuid, descendantPageUuids, scopeEntityUuid, record, recordValidation } = params\n const parentUuid = RecordValidations.extractValidationChildrenCountKeyParentUuid(childrenCountKey)\n const childDefUuid = RecordValidations.extractValidationChildrenCountKeyNodeDefUuid(childrenCountKey)\n if (!parentUuid || !childDefUuid) return null\n\n // Sub-page entity min/max counts belong to navigation of nested pages, not this page's fields.\n if (descendantPageUuids.includes(childDefUuid)) return null\n\n const parentNode = getNodeByUuid(parentUuid)(record)\n if (!parentNode || !nodeBelongsToOwnPage({ node: parentNode, pageNodeDefUuid, descendantPageUuids, record })) {\n return null\n }\n if (scopeEntityUuid && !nodeIsUnderEntity({ node: parentNode, entityUuid: scopeEntityUuid })) return null\n\n const fieldValidation = Validations.getFieldValidation(childrenCountKey)(recordValidation)\n if (!fieldValidation) return null\n\n return {\n hasErrors: Validations.hasErrors(fieldValidation),\n hasWarnings: Validations.hasWarnings(fieldValidation),\n }\n}\n\n/**\n * Aggregates error/warning flags for a page.\n * When descendantPageUuids is non-empty, nested page entities are excluded (own-page scope).\n * When scopeEntityUuid is set, only validations for nodes under that entity instance are included.\n */\nexport const getPageValidationStatus = (params: {\n pageNodeDefUuid: string\n descendantPageUuids?: string[]\n record: Record\n scopeEntityUuid?: string\n}): PageValidationStatus => {\n const { pageNodeDefUuid, descendantPageUuids = [], record, scopeEntityUuid } = params\n const recordValidation = Validations.getValidation(record)\n const fields = Validations.getFieldValidations(recordValidation)\n let hasErrors = false\n let hasWarnings = false\n\n for (const nodeUuid of Object.keys(fields)) {\n const flags = getOwnPageFieldValidationFlags({\n nodeUuid,\n pageNodeDefUuid,\n descendantPageUuids,\n scopeEntityUuid,\n record,\n recordValidation,\n })\n if (!flags) continue\n if (flags.hasErrors) hasErrors = true\n if (flags.hasWarnings) hasWarnings = true\n if (hasErrors && hasWarnings) break\n }\n\n return { hasErrors, hasWarnings }\n}\n\nconst aggregatePageValidationStatuses = (statuses: PageValidationStatus[]): PageValidationStatus => ({\n hasErrors: statuses.some((status) => status.hasErrors),\n hasWarnings: statuses.some((status) => status.hasWarnings),\n})\n\n/**\n * Validation and completion status for one entity instance and its descendant pages.\n * Returns null when the node is missing or is not an entity.\n */\nexport const getEntitySubtreeStatus = (params: {\n survey: Survey\n record: Record\n entityUuid: string\n cycle?: string\n}): EntitySubtreeStatus | null => {\n const { survey, record, entityUuid } = params\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return null\n\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n if (!NodeDefs.isEntity(entityDef)) return null\n\n const cycle = params.cycle ?? getCycle(record)\n const entityPageDef = entityDef as NodeDefEntity\n const descendantPageUuids = getDescendantPageNodeDefUuids({ survey, cycle, pageNodeDef: entityPageDef })\n const pageUuidsToCheck = [entity.nodeDefUuid, ...descendantPageUuids]\n\n const validationStatuses = pageUuidsToCheck.map((pageNodeDefUuid) => {\n const pageNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: pageNodeDefUuid }) as NodeDefEntity\n const pageDescendantUuids = getDescendantPageNodeDefUuids({ survey, cycle, pageNodeDef })\n return getPageValidationStatus({\n pageNodeDefUuid,\n descendantPageUuids: pageDescendantUuids,\n record,\n scopeEntityUuid: entityUuid,\n })\n })\n\n const { hasErrors, hasWarnings } = aggregatePageValidationStatuses(validationStatuses)\n const { total, filled } = getEntityCompletionStats({ survey, record, entity })\n const isComplete = total > 0 && filled === total && !hasErrors && !hasWarnings\n\n return { hasErrors, hasWarnings, isComplete }\n}\n\n/**\n * Aggregates subtree status across instances of a multiple page entity.\n * When `scopeEntityUuid` is set, only instances under that ancestor entity are included\n * (needed for nested multiples, e.g. Tree under the currently selected Plot).\n * Empty instance lists return a non-complete status with no validation flags.\n */\nexport const getMultiplePageEntitiesStatus = (params: {\n survey: Survey\n record: Record\n pageNodeDefUuid: string\n cycle?: string\n /** When set, only instances under this ancestor entity are aggregated. */\n scopeEntityUuid?: string\n}): EntitySubtreeStatus => {\n const { survey, record, pageNodeDefUuid, scopeEntityUuid } = params\n const instances = getNodesByDefUuid(pageNodeDefUuid)(record).filter((instance) =>\n scopeEntityUuid ? nodeIsUnderEntity({ node: instance, entityUuid: scopeEntityUuid }) : true\n )\n\n if (instances.length === 0) {\n return { hasErrors: false, hasWarnings: false, isComplete: false }\n }\n\n const instanceStatuses = instances\n .map((instance) => getEntitySubtreeStatus({ survey, record, entityUuid: instance.uuid, cycle: params.cycle }))\n .filter((status): status is EntitySubtreeStatus => status !== null)\n\n return {\n hasErrors: instanceStatuses.some((status) => status.hasErrors),\n hasWarnings: instanceStatuses.some((status) => status.hasWarnings),\n isComplete: instanceStatuses.length > 0 && instanceStatuses.every((status) => status.isComplete),\n }\n}\n\n/**\n * Whether the page has validation errors on its own fields (excluding nested page entities).\n */\nexport const pageHasOwnErrors = (params: {\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n record: Record\n}): boolean => getPageValidationStatus(params).hasErrors\n\n/**\n * Progress of pages without own-field validation errors over all survey pages.\n * Warnings do not reduce the score (matches Arena sidebar red-icon signal).\n */\nexport const getRecordPagesValidationProgress = (params: {\n survey: Survey\n record: Record\n cycle?: string\n}): PagesValidationProgress | null => {\n const { survey, record } = params\n if (!getRoot(record)) return null\n\n const cycle = params.cycle ?? getCycle(record)\n const pageNodeDefs = getPageNodeDefs({ survey, cycle })\n const totalCount = pageNodeDefs.length\n if (totalCount === 0) return null\n\n let validCount = 0\n for (const pageNodeDef of pageNodeDefs) {\n const pageNodeDefUuid = pageNodeDef.uuid\n const descendantPageUuids = getDescendantPageNodeDefUuids({ survey, cycle, pageNodeDef })\n if (!pageHasOwnErrors({ pageNodeDefUuid, descendantPageUuids, record })) {\n validCount += 1\n }\n }\n\n const percent = Math.round((validCount / totalCount) * 100)\n return { percent, validCount, totalCount }\n}\n"]}
1
+ {"version":3,"file":"recordPagesValidation.js","sourceRoot":"","sources":["../../../../src/record/_records/recordPagesValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAiB,QAAQ,EAAE,MAAM,eAAe,CAAA;AACvD,OAAO,EAAU,OAAO,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAC7D,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AAmBrF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAA+D,EAAW,EAAE;IAC5G,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;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C,MAAM,mBAAmB,GAAG,6BAA6B,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC,CAAA;QACzF,IAAI,CAAC,gBAAgB,CAAC,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;YACxE,UAAU,IAAI,CAAC,CAAA;QACjB,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,UAAU,GAAG,UAAU,CAAC,GAAG,GAAG,CAAC,CAAA;IAC3D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,CAAA;AAC5C,CAAC,CAAA","sourcesContent":["import { Node, Nodes } from '../../node'\nimport { NodeDefEntity, NodeDefs } from '../../nodeDef'\nimport { Survey, Surveys } from '../../survey'\nimport { Validations } from '../../validation'\nimport { Record } from '../record'\nimport { RecordValidations } from '../recordValidations'\nimport { getEntityCompletionStats } from './recordCompletion'\nimport { getCycle, getNodeByUuid, getNodesByDefUuid, getRoot } from './recordGetters'\n\nexport type PageValidationStatus = {\n hasErrors: boolean\n hasWarnings: boolean\n}\n\nexport type EntitySubtreeStatus = {\n hasErrors: boolean\n hasWarnings: boolean\n isComplete: boolean\n}\n\nexport type PagesValidationProgress = {\n percent: number\n validCount: number\n totalCount: number\n}\n\n/**\n * Whether a node belongs under a page entity (itself or any descendant of that page).\n */\nexport const nodeBelongsToPage = (params: { node: Node; pageNodeDefUuid: string; record: Record }): boolean => {\n const { node, pageNodeDefUuid, record } = params\n if (node.nodeDefUuid === pageNodeDefUuid) return true\n return Nodes.getHierarchy(node).some((ancestorUuid) => {\n const ancestor = getNodeByUuid(ancestorUuid)(record)\n return ancestor?.nodeDefUuid === pageNodeDefUuid\n })\n}\n\n/**\n * Whether a node belongs to this page only — not to a nested descendant page entity.\n * When descendantPageUuids is empty, all nodes under the page hierarchy are included.\n */\nexport const nodeBelongsToOwnPage = (params: {\n node: Node\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n record: Record\n}): boolean => {\n const { node, pageNodeDefUuid, descendantPageUuids, record } = params\n if (!nodeBelongsToPage({ node, pageNodeDefUuid, record })) return false\n if (descendantPageUuids.includes(node.nodeDefUuid)) return false\n return !descendantPageUuids.some((descendantUuid) =>\n nodeBelongsToPage({ node, pageNodeDefUuid: descendantUuid, record })\n )\n}\n\n/**\n * Child page-entity defs displayed in their own page under the given entity.\n */\nexport const getNodeDefChildrenInOwnPage = (params: {\n survey: Survey\n nodeDef: NodeDefEntity\n cycle: string\n}): NodeDefEntity[] => {\n const { survey, nodeDef, cycle } = params\n return Surveys.getNodeDefChildren({ survey, nodeDef, includeAnalysis: true }).filter(\n (child): child is NodeDefEntity => {\n if (!NodeDefs.isEntity(child)) return false\n return NodeDefs.isDisplayInOwnPage(cycle)(child as NodeDefEntity)\n }\n )\n}\n\n/**\n * Collects all page-entity node defs in the survey cycle (root + nested own-pages).\n */\nexport const getPageNodeDefs = (params: { survey: Survey; cycle: string }): NodeDefEntity[] => {\n const { survey, cycle } = params\n const root = Surveys.getNodeDefRoot({ survey }) as NodeDefEntity | undefined\n if (!root) return []\n\n const pages: NodeDefEntity[] = []\n const stack: NodeDefEntity[] = [root]\n while (stack.length > 0) {\n const current = stack.pop()\n if (!current) continue\n pages.push(current)\n stack.push(...getNodeDefChildrenInOwnPage({ survey, nodeDef: current, cycle }))\n }\n return pages\n}\n\n/**\n * Collects descendant page node def UUIDs under a page (not including the page itself).\n */\nexport const getDescendantPageNodeDefUuids = (params: {\n survey: Survey\n cycle: string\n pageNodeDef: NodeDefEntity\n}): string[] => {\n const { survey, cycle, pageNodeDef } = params\n const uuids: string[] = []\n const visit = (nodeDef: NodeDefEntity) => {\n const children = getNodeDefChildrenInOwnPage({ survey, nodeDef, cycle })\n for (const child of children) {\n uuids.push(child.uuid)\n visit(child)\n }\n }\n visit(pageNodeDef)\n return uuids\n}\n\nconst nodeIsUnderEntity = (params: { node: Node; entityUuid: string }): boolean => {\n const { node, entityUuid } = params\n if (node.uuid === entityUuid) return true\n return Nodes.getHierarchy(node).includes(entityUuid)\n}\n\nconst getOwnPageFieldValidationFlags = (params: {\n nodeUuid: string\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n scopeEntityUuid?: string\n record: Record\n recordValidation: ReturnType<typeof Validations.getValidation>\n}): PageValidationStatus | null => {\n const { nodeUuid, pageNodeDefUuid, descendantPageUuids, scopeEntityUuid, record, recordValidation } = params\n\n if (RecordValidations.isValidationChildrenCountKey(nodeUuid)) {\n return getOwnPageChildrenCountValidationFlags({\n childrenCountKey: nodeUuid,\n pageNodeDefUuid,\n descendantPageUuids,\n scopeEntityUuid,\n record,\n recordValidation,\n })\n }\n\n const node = getNodeByUuid(nodeUuid)(record)\n if (!node || !nodeBelongsToOwnPage({ node, pageNodeDefUuid, descendantPageUuids, record })) return null\n if (scopeEntityUuid && !nodeIsUnderEntity({ node, entityUuid: scopeEntityUuid })) return null\n\n const nodeValidation = RecordValidations.getValidationNode({ nodeUuid })(recordValidation)\n if (!nodeValidation) return null\n\n return {\n hasErrors: Validations.hasErrors(nodeValidation),\n hasWarnings: Validations.hasWarnings(nodeValidation),\n }\n}\n\n/**\n * Children-count validations (file min count, inline multiple min/max, etc.) are keyed as\n * `childrenCount_{parentUuid}_{childDefUuid}`, not as node UUIDs.\n * Include them when the parent is on this page, but skip counts that refer to descendant\n * page entities (missing sub-page instances should not paint the parent page red).\n */\nconst getOwnPageChildrenCountValidationFlags = (params: {\n childrenCountKey: string\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n scopeEntityUuid?: string\n record: Record\n recordValidation: ReturnType<typeof Validations.getValidation>\n}): PageValidationStatus | null => {\n const { childrenCountKey, pageNodeDefUuid, descendantPageUuids, scopeEntityUuid, record, recordValidation } = params\n const parentUuid = RecordValidations.extractValidationChildrenCountKeyParentUuid(childrenCountKey)\n const childDefUuid = RecordValidations.extractValidationChildrenCountKeyNodeDefUuid(childrenCountKey)\n if (!parentUuid || !childDefUuid) return null\n\n // Sub-page entity min/max counts belong to navigation of nested pages, not this page's fields.\n if (descendantPageUuids.includes(childDefUuid)) return null\n\n const parentNode = getNodeByUuid(parentUuid)(record)\n if (!parentNode || !nodeBelongsToOwnPage({ node: parentNode, pageNodeDefUuid, descendantPageUuids, record })) {\n return null\n }\n if (scopeEntityUuid && !nodeIsUnderEntity({ node: parentNode, entityUuid: scopeEntityUuid })) return null\n\n const fieldValidation = Validations.getFieldValidation(childrenCountKey)(recordValidation)\n if (!fieldValidation) return null\n\n return {\n hasErrors: Validations.hasErrors(fieldValidation),\n hasWarnings: Validations.hasWarnings(fieldValidation),\n }\n}\n\n/**\n * Aggregates error/warning flags for a page.\n * When descendantPageUuids is non-empty, nested page entities are excluded (own-page scope).\n * When scopeEntityUuid is set, only validations for nodes under that entity instance are included.\n */\nexport const getPageValidationStatus = (params: {\n pageNodeDefUuid: string\n descendantPageUuids?: string[]\n record: Record\n scopeEntityUuid?: string\n}): PageValidationStatus => {\n const { pageNodeDefUuid, descendantPageUuids = [], record, scopeEntityUuid } = params\n const recordValidation = Validations.getValidation(record)\n const fields = Validations.getFieldValidations(recordValidation)\n let hasErrors = false\n let hasWarnings = false\n\n for (const nodeUuid of Object.keys(fields)) {\n const flags = getOwnPageFieldValidationFlags({\n nodeUuid,\n pageNodeDefUuid,\n descendantPageUuids,\n scopeEntityUuid,\n record,\n recordValidation,\n })\n if (!flags) continue\n if (flags.hasErrors) hasErrors = true\n if (flags.hasWarnings) hasWarnings = true\n if (hasErrors && hasWarnings) break\n }\n\n return { hasErrors, hasWarnings }\n}\n\nconst aggregatePageValidationStatuses = (statuses: PageValidationStatus[]): PageValidationStatus => ({\n hasErrors: statuses.some((status) => status.hasErrors),\n hasWarnings: statuses.some((status) => status.hasWarnings),\n})\n\n/**\n * Validation and completion status for one entity instance and its descendant pages.\n * Returns null when the node is missing or is not an entity.\n */\nexport const getEntitySubtreeStatus = (params: {\n survey: Survey\n record: Record\n entityUuid: string\n cycle?: string\n}): EntitySubtreeStatus | null => {\n const { survey, record, entityUuid } = params\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return null\n\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n if (!NodeDefs.isEntity(entityDef)) return null\n\n const cycle = params.cycle ?? getCycle(record)\n const entityPageDef = entityDef as NodeDefEntity\n const descendantPageUuids = getDescendantPageNodeDefUuids({ survey, cycle, pageNodeDef: entityPageDef })\n const pageUuidsToCheck = [entity.nodeDefUuid, ...descendantPageUuids]\n\n const validationStatuses = pageUuidsToCheck.map((pageNodeDefUuid) => {\n const pageNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: pageNodeDefUuid }) as NodeDefEntity\n const pageDescendantUuids = getDescendantPageNodeDefUuids({ survey, cycle, pageNodeDef })\n return getPageValidationStatus({\n pageNodeDefUuid,\n descendantPageUuids: pageDescendantUuids,\n record,\n scopeEntityUuid: entityUuid,\n })\n })\n\n const { hasErrors, hasWarnings } = aggregatePageValidationStatuses(validationStatuses)\n const { total, filled } = getEntityCompletionStats({ survey, record, entity })\n const isComplete = total > 0 && filled === total && !hasErrors && !hasWarnings\n\n return { hasErrors, hasWarnings, isComplete }\n}\n\n/**\n * Aggregates subtree status across instances of a multiple page entity.\n * When `scopeEntityUuid` is set, only instances under that ancestor entity are included\n * (needed for nested multiples, e.g. Tree under the currently selected Plot).\n * Empty instance lists return a non-complete status with no validation flags.\n */\nexport const getMultiplePageEntitiesStatus = (params: {\n survey: Survey\n record: Record\n pageNodeDefUuid: string\n cycle?: string\n /** When set, only instances under this ancestor entity are aggregated. */\n scopeEntityUuid?: string\n}): EntitySubtreeStatus => {\n const { survey, record, pageNodeDefUuid, scopeEntityUuid } = params\n const instances = getNodesByDefUuid(pageNodeDefUuid)(record).filter((instance) =>\n scopeEntityUuid ? nodeIsUnderEntity({ node: instance, entityUuid: scopeEntityUuid }) : true\n )\n\n if (instances.length === 0) {\n return { hasErrors: false, hasWarnings: false, isComplete: false }\n }\n\n const instanceStatuses = instances\n .map((instance) => getEntitySubtreeStatus({ survey, record, entityUuid: instance.uuid, cycle: params.cycle }))\n .filter((status): status is EntitySubtreeStatus => status !== null)\n\n return {\n hasErrors: instanceStatuses.some((status) => status.hasErrors),\n hasWarnings: instanceStatuses.some((status) => status.hasWarnings),\n isComplete: instanceStatuses.length > 0 && instanceStatuses.every((status) => status.isComplete),\n }\n}\n\n/**\n * Whether the page has validation errors on its own fields (excluding nested page entities).\n */\nexport const pageHasOwnErrors = (params: {\n pageNodeDefUuid: string\n descendantPageUuids: string[]\n record: Record\n}): boolean => getPageValidationStatus(params).hasErrors\n\n/**\n * Progress of pages without own-field validation errors over all survey pages.\n * Warnings do not reduce the score (matches Arena sidebar red-icon signal).\n */\nexport const getRecordPagesValidationProgress = (params: {\n survey: Survey\n record: Record\n cycle?: string\n}): PagesValidationProgress | null => {\n const { survey, record } = params\n if (!getRoot(record)) return null\n\n const cycle = params.cycle ?? getCycle(record)\n const pageNodeDefs = getPageNodeDefs({ survey, cycle })\n const totalCount = pageNodeDefs.length\n if (totalCount === 0) return null\n\n let validCount = 0\n for (const pageNodeDef of pageNodeDefs) {\n const pageNodeDefUuid = pageNodeDef.uuid\n const descendantPageUuids = getDescendantPageNodeDefUuids({ survey, cycle, pageNodeDef })\n if (!pageHasOwnErrors({ pageNodeDefUuid, descendantPageUuids, record })) {\n validCount += 1\n }\n }\n\n const percent = Math.round((validCount / totalCount) * 100)\n return { percent, validCount, totalCount }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../../src/record/_records/recordUpdater.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAuB,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAExF,MAAM,CAAC,MAAM,QAAQ,GACnB,CAAC,KAA8B,EAAE,UAA+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AAC,CAAC,KAAK,CAAC,CAAA;IAC1G,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAClB,CAAC,IAAU,EAAE,UAA+B,2BAA2B,EAAE,EAAE,CAC3E,CAAC,MAAc,EAAE,EAAE,CACjB,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA","sourcesContent":["import { Node } from '../../node'\nimport { Record } from '../record'\nimport * as RecordGetters from './recordGetters'\nimport { RecordNodesIndexUpdater } from './recordNodesIndexUpdater'\nimport { RecordUpdateOptions, RecordUpdateOptionsDefaults } from './recordUpdateOptions'\n\nexport const addNodes =\n (nodes: { [key: string]: Node }, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: Record): Record => {\n const { sideEffect, updateNodesIndex, sortNodes } = { ...RecordUpdateOptionsDefaults, ...options }\n\n const recordUpdated = sideEffect ? record : { ...record }\n const recordNodes = RecordGetters.getNodes(recordUpdated)\n const index = recordUpdated._nodesIndex ?? {}\n\n // index only the nodes not already indexed with the same parent, node def and hierarchy code\n // (e.g. nodes with only an updated value don't need any index change)\n const nodesToIndex: { [key: string]: Node } = {}\n if (updateNodesIndex) {\n for (const [nodeUuid, node] of Object.entries(nodes)) {\n const nodePrev = recordNodes[nodeUuid]\n if (!RecordNodesIndexUpdater.isNodeIndexUnchanged({ index, node, nodePrev })) {\n nodesToIndex[nodeUuid] = node\n }\n }\n }\n\n if (sideEffect) {\n recordUpdated.nodes = Object.assign(recordNodes, nodes)\n } else {\n recordUpdated.nodes = { ...recordNodes, ...nodes }\n }\n if (updateNodesIndex && Object.keys(nodesToIndex).length > 0) {\n recordUpdated._nodesIndex = RecordNodesIndexUpdater.addNodes(nodesToIndex, sideEffect, sortNodes)(index)\n }\n return recordUpdated\n }\n\nexport const addNode =\n (node: Node, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: Record) =>\n addNodes({ [node.uuid]: node }, options)(record)\n"]}
1
+ {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../../../src/record/_records/recordUpdater.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,aAAa,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAA;AACnE,OAAO,EAAuB,2BAA2B,EAAE,MAAM,uBAAuB,CAAA;AAExF,MAAM,CAAC,MAAM,QAAQ,GACnB,CAAC,KAA8B,EAAE,OAAO,GAAwB,2BAA2B,EAAE,EAAE,CAC/F,CAAC,MAAc,EAAU,EAAE;;IACzB,MAAM,EAAE,UAAU,EAAE,gBAAgB,EAAE,SAAS,EAAE,mCAAQ,2BAA2B,GAAK,OAAO,CAAE,CAAA;IAElG,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,mBAAM,MAAM,CAAE,CAAA;IACzD,MAAM,WAAW,GAAG,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAA;IACzD,MAAM,KAAK,SAAG,aAAa,CAAC,WAAW,mCAAI,EAAE,CAAA;IAE7C,6FAA6F;IAC7F,sEAAsE;IACtE,MAAM,YAAY,GAA4B,EAAE,CAAA;IAChD,IAAI,gBAAgB,EAAE,CAAC;QACrB,KAAK,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACrD,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAA;YACtC,IAAI,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC;gBAC7E,YAAY,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAA;YAC/B,CAAC;QACH,CAAC;IACH,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,aAAa,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAA;IACzD,CAAC;SAAM,CAAC;QACN,aAAa,CAAC,KAAK,mCAAQ,WAAW,GAAK,KAAK,CAAE,CAAA;IACpD,CAAC;IACD,IAAI,gBAAgB,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7D,aAAa,CAAC,WAAW,GAAG,uBAAuB,CAAC,QAAQ,CAAC,YAAY,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC,KAAK,CAAC,CAAA;IAC1G,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,OAAO,GAClB,CAAC,IAAU,EAAE,OAAO,GAAwB,2BAA2B,EAAE,EAAE,CAC3E,CAAC,MAAc,EAAE,EAAE,CACjB,QAAQ,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAA","sourcesContent":["import { Node } from '../../node'\nimport { Record } from '../record'\nimport * as RecordGetters from './recordGetters'\nimport { RecordNodesIndexUpdater } from './recordNodesIndexUpdater'\nimport { RecordUpdateOptions, RecordUpdateOptionsDefaults } from './recordUpdateOptions'\n\nexport const addNodes =\n (nodes: { [key: string]: Node }, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: Record): Record => {\n const { sideEffect, updateNodesIndex, sortNodes } = { ...RecordUpdateOptionsDefaults, ...options }\n\n const recordUpdated = sideEffect ? record : { ...record }\n const recordNodes = RecordGetters.getNodes(recordUpdated)\n const index = recordUpdated._nodesIndex ?? {}\n\n // index only the nodes not already indexed with the same parent, node def and hierarchy code\n // (e.g. nodes with only an updated value don't need any index change)\n const nodesToIndex: { [key: string]: Node } = {}\n if (updateNodesIndex) {\n for (const [nodeUuid, node] of Object.entries(nodes)) {\n const nodePrev = recordNodes[nodeUuid]\n if (!RecordNodesIndexUpdater.isNodeIndexUnchanged({ index, node, nodePrev })) {\n nodesToIndex[nodeUuid] = node\n }\n }\n }\n\n if (sideEffect) {\n recordUpdated.nodes = Object.assign(recordNodes, nodes)\n } else {\n recordUpdated.nodes = { ...recordNodes, ...nodes }\n }\n if (updateNodesIndex && Object.keys(nodesToIndex).length > 0) {\n recordUpdated._nodesIndex = RecordNodesIndexUpdater.addNodes(nodesToIndex, sideEffect, sortNodes)(index)\n }\n return recordUpdated\n }\n\nexport const addNode =\n (node: Node, options: RecordUpdateOptions = RecordUpdateOptionsDefaults) =>\n (record: Record) =>\n addNodes({ [node.uuid]: node }, options)(record)\n"]}
@@ -3,7 +3,8 @@ import { RECORD_STEP_DEFAULT } from './record';
3
3
  import { UUIDs } from '../utils';
4
4
  export const RecordFactory = {
5
5
  createInstance: (params) => {
6
- var _a, _b;
6
+ var _a;
7
+ var _b;
7
8
  const defaultProps = {
8
9
  preview: false,
9
10
  step: RECORD_STEP_DEFAULT,
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/record/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAQ,KAAK,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,EAAU,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAahC,MAAM,CAAC,MAAM,aAAa,GAAyC;IACjE,cAAc,EAAE,CAAC,MAA2B,EAAU,EAAE;;QACtD,MAAM,YAAY,GAAG;YACnB,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,mBAAmB;SAC1B,CAAA;QAED,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,mCACjE,YAAY,GACZ,MAAM,CACV,CAAA;QAED,MAAM,WAAW,GAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAA;QACrF,MAAM,SAAS,GAAG,MAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,IAAI,mCAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QAE1G,uBACE,KAAK;YACL,WAAW,EACX,UAAU,EAAE,IAAI,CAAC,KAAK,EACtB,SAAS,EAAE,IAAI,CAAC,IAAI,EACpB,SAAS,EACT,SAAS,EAAE,IAAI,CAAC,IAAI,EACpB,OAAO;YACP,IAAI;YACJ,UAAU,EACV,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,IACb,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACvD;IACH,CAAC;CACF,CAAA","sourcesContent":["import { Factory } from '../common'\nimport { AuthGroupName, User, Users } from '../auth'\nimport { Record, RECORD_STEP_DEFAULT } from './record'\nimport { UUIDs } from '../utils'\nimport { AppInfo } from '../app'\n\nexport type RecordFactoryParams = {\n cycle?: string\n dateCreated?: string\n preview?: boolean\n surveyUuid: string\n step?: string\n user: User\n appInfo?: AppInfo\n}\n\nexport const RecordFactory: Factory<Record, RecordFactoryParams> = {\n createInstance: (params: RecordFactoryParams): Record => {\n const defaultProps = {\n preview: false,\n step: RECORD_STEP_DEFAULT,\n }\n\n const { appInfo, cycle, dateCreated, preview, step, surveyUuid, user } = {\n ...defaultProps,\n ...params,\n }\n\n const surveyGroup = user.authGroups?.find((group) => group.surveyUuid === surveyUuid)\n const ownerRole = surveyGroup?.name ?? (Users.isSystemAdmin(user) ? AuthGroupName.systemAdmin : undefined)\n\n return {\n cycle,\n dateCreated,\n ownerEmail: user.email,\n ownerName: user.name,\n ownerRole,\n ownerUuid: user.uuid,\n preview,\n step,\n surveyUuid,\n uuid: UUIDs.v4(),\n ...(appInfo ? { info: { createdWith: appInfo } } : {}),\n }\n },\n}\n"]}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/record/factory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAQ,KAAK,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,EAAU,mBAAmB,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAahC,MAAM,CAAC,MAAM,aAAa,GAAyC;IACjE,cAAc,EAAE,CAAC,MAA2B,EAAU,EAAE;;;QACtD,MAAM,YAAY,GAAG;YACnB,OAAO,EAAE,KAAK;YACd,IAAI,EAAE,mBAAmB;SAC1B,CAAA;QAED,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,mCACjE,YAAY,GACZ,MAAM,CACV,CAAA;QAED,MAAM,WAAW,GAAG,MAAA,IAAI,CAAC,UAAU,0CAAE,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC,CAAA;QACrF,MAAM,SAAS,SAAG,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,IAAI,mCAAI,CAAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QAE1G,uBACE,KAAK;YACL,WAAW,EACX,UAAU,EAAE,IAAI,CAAC,KAAK,EACtB,SAAS,EAAE,IAAI,CAAC,IAAI,EACpB,SAAS,EACT,SAAS,EAAE,IAAI,CAAC,IAAI,EACpB,OAAO;YACP,IAAI;YACJ,UAAU,EACV,IAAI,EAAE,KAAK,CAAC,EAAE,EAAE,IACb,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACvD;IACH,CAAC;CACF,CAAA","sourcesContent":["import { Factory } from '../common'\nimport { AuthGroupName, User, Users } from '../auth'\nimport { Record, RECORD_STEP_DEFAULT } from './record'\nimport { UUIDs } from '../utils'\nimport { AppInfo } from '../app'\n\nexport type RecordFactoryParams = {\n cycle?: string\n dateCreated?: string\n preview?: boolean\n surveyUuid: string\n step?: string\n user: User\n appInfo?: AppInfo\n}\n\nexport const RecordFactory: Factory<Record, RecordFactoryParams> = {\n createInstance: (params: RecordFactoryParams): Record => {\n const defaultProps = {\n preview: false,\n step: RECORD_STEP_DEFAULT,\n }\n\n const { appInfo, cycle, dateCreated, preview, step, surveyUuid, user } = {\n ...defaultProps,\n ...params,\n }\n\n const surveyGroup = user.authGroups?.find((group) => group.surveyUuid === surveyUuid)\n const ownerRole = surveyGroup?.name ?? (Users.isSystemAdmin(user) ? AuthGroupName.systemAdmin : undefined)\n\n return {\n cycle,\n dateCreated,\n ownerEmail: user.email,\n ownerName: user.name,\n ownerRole,\n ownerUuid: user.uuid,\n preview,\n step,\n surveyUuid,\n uuid: UUIDs.v4(),\n ...(appInfo ? { info: { createdWith: appInfo } } : {}),\n }\n },\n}\n"]}
@@ -20,7 +20,8 @@ const assignNewUuidsToNodes = (params) => {
20
20
  const nodesUpdated = sideEffect ? nodes : Object.assign({}, nodes);
21
21
  // update nodes recordUuid and properties (it does side effect on nodes)
22
22
  nodesArray.forEach((node) => {
23
- var _a, _b;
23
+ var _a;
24
+ var _b;
24
25
  let nodeUpdated = sideEffect ? node : Object.assign({}, node);
25
26
  nodeUpdated.recordUuid = record.uuid;
26
27
  nodeUpdated.dateCreated = nodeUpdated.dateModified = Dates.nowFormattedForStorage();
@@ -1 +1 @@
1
- {"version":3,"file":"recordCloner.js","sourceRoot":"","sources":["../../../src/record/recordCloner.ts"],"names":[],"mappings":"AAAA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EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;IAC5F,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;IAE7G,mFAAmF;IACnF,MAAM,EACJ,qBAAqB,EACrB,qBAAqB,EACrB,MAAM,EAAE,kBAAkB,GAC3B,GAAG,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IAE/D,YAAY,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAA;IAE1E,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,CAAA;AACtF,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW;CACZ,CAAA","sourcesContent":["import { Node, NodeValues, Nodes } from '../node'\nimport { NodeKeys, NodeMetaKeys } from '../node/node'\nimport { NodeDefCode, NodeDefType, NodeDefs } from '../nodeDef'\nimport { Survey, Surveys } from '../survey'\nimport { Dates, Objects, UUIDs } from '../utils'\nimport { Validation } from '../validation'\nimport { Record } from './record'\nimport { RecordFixer } from './recordFixer'\nimport { RecordUpdateResult } from './recordNodesUpdater'\nimport { RecordValidations } from './recordValidations'\nimport { Records } from './records'\n\ntype OldUuidToNewUuidMap = {\n [key: string]: string\n}\n\nconst assignNewUuidsToNodes = (params: {\n record: Record\n sideEffect: boolean\n}): { newNodeUuidsByOldUuid: OldUuidToNewUuidMap; newFileUuidsByOldUuid: OldUuidToNewUuidMap; record: Record } => {\n const { record, sideEffect } = params\n\n // generate a new uuid for each node\n const newNodeUuidsByOldUuid: OldUuidToNewUuidMap = {}\n const newFileUuidsByOldUuid: OldUuidToNewUuidMap = {}\n\n // sort nodes before removing the id, to preserve their hierarchy (faster than comparing each meta.h property)\n const nodesArray = Records.getNodesArray(record).sort(\n (nodeA: Node, nodeB: Node): number => Nodes.getHierarchy(nodeA).length - Nodes.getHierarchy(nodeB).length\n )\n\n const recordUpdated = sideEffect ? record : { ...record }\n\n const nodes = recordUpdated.nodes ?? {}\n const nodesUpdated = sideEffect ? nodes : { ...nodes }\n\n // update nodes recordUuid and properties (it does side effect on nodes)\n nodesArray.forEach((node) => {\n let nodeUpdated = sideEffect ? node : { ...node }\n nodeUpdated.recordUuid = record.uuid\n nodeUpdated.dateCreated = nodeUpdated.dateModified = Dates.nowFormattedForStorage()\n\n const oldUuid = node.uuid\n const newUuid = UUIDs.v4()\n newNodeUuidsByOldUuid[oldUuid] = newUuid\n\n nodeUpdated.uuid = newUuid\n // consider every node as just created node\n delete nodeUpdated.id\n nodeUpdated.created = true // this flag will be used by the RDB generator)\n\n // update internal node uuids, meta hierarchy, file uuid (if any)\n const parentUuid = node.parentUuid\n if (parentUuid) {\n nodeUpdated.parentUuid = newNodeUuidsByOldUuid[parentUuid]\n }\n const hierarchy = node.meta?.h ?? []\n if (hierarchy.length > 0) {\n const hierarchyUpdated = hierarchy.map((ancestorUuid) => newNodeUuidsByOldUuid[ancestorUuid])\n nodeUpdated = Objects.assocPath({\n obj: nodeUpdated,\n path: [NodeKeys.meta, NodeMetaKeys.h],\n value: hierarchyUpdated,\n sideEffect,\n })\n }\n // assign new file uuid (file should be cloned elsewhere)\n const fileUuid = NodeValues.getFileUuid(node)\n if (fileUuid) {\n const newFileUuid = UUIDs.v4()\n nodeUpdated = Objects.assocPath({\n obj: nodeUpdated,\n path: [NodeKeys.value, NodeValues.ValuePropsFile.fileUuid],\n value: newFileUuid,\n })\n newFileUuidsByOldUuid[fileUuid] = newFileUuid\n }\n\n delete nodesUpdated[oldUuid]\n nodesUpdated[newUuid] = nodeUpdated\n })\n\n recordUpdated.nodes = nodesUpdated\n\n return { newNodeUuidsByOldUuid, newFileUuidsByOldUuid, record: recordUpdated }\n}\n\nconst assignNewUuidsToValidation = (params: {\n validation: Validation\n newNodeUuidsByOldUuid: OldUuidToNewUuidMap\n sideEffect: boolean\n}): Validation => {\n const { validation, newNodeUuidsByOldUuid, sideEffect } = params\n\n const validationFields = validation?.fields\n if (!validationFields) return validation\n\n const validationFieldsUpdated = sideEffect ? validationFields : { ...validationFields }\n\n Object.entries(validationFields).forEach(([oldFieldKey, validationField]) => {\n let newFieldKey\n if (oldFieldKey.startsWith(RecordValidations.prefixValidationFieldChildrenCount)) {\n const oldParentUuid = oldFieldKey.substring(\n RecordValidations.prefixValidationFieldChildrenCount.length,\n oldFieldKey.lastIndexOf('_')\n )\n const newParentUuid = newNodeUuidsByOldUuid[oldParentUuid]\n newFieldKey = oldFieldKey.replace(oldParentUuid, newParentUuid)\n } else {\n newFieldKey = newNodeUuidsByOldUuid[oldFieldKey]\n }\n if (newFieldKey) {\n validationFieldsUpdated[newFieldKey] = validationField\n }\n delete validationFieldsUpdated[oldFieldKey]\n })\n return Objects.assoc({\n obj: validation,\n prop: 'fields',\n value: validationFieldsUpdated,\n sideEffect,\n })\n}\n\nconst assignNewUuids = (params: {\n record: Record\n sideEffect: boolean\n}): { newNodeUuidsByOldUuid: OldUuidToNewUuidMap; newFileUuidsByOldUuid: OldUuidToNewUuidMap; record: Record } => {\n const { record, sideEffect } = params\n let recordUpdated = sideEffect ? record : { ...record }\n recordUpdated.uuid = UUIDs.v4()\n\n const {\n newNodeUuidsByOldUuid,\n newFileUuidsByOldUuid,\n record: recordUpdatedUuids,\n } = assignNewUuidsToNodes({ record: recordUpdated, sideEffect })\n\n recordUpdated = recordUpdatedUuids\n\n const { validation } = recordUpdated\n if (validation) {\n const validationUpdated = assignNewUuidsToValidation({\n validation,\n newNodeUuidsByOldUuid,\n sideEffect,\n })\n recordUpdated = Objects.assoc({ obj: recordUpdated, prop: 'validation', value: validationUpdated, sideEffect })\n }\n // re-build nodes index\n const nodes = recordUpdated.nodes!\n delete recordUpdated._nodesIndex\n delete recordUpdated.nodes\n recordUpdated = Records.addNodes(nodes, { sideEffect, sortNodes: true })(recordUpdated)\n\n return { newNodeUuidsByOldUuid, newFileUuidsByOldUuid, record: recordUpdated }\n}\n\nconst removeExcludedNodes = (params: { survey: Survey; record: Record; sideEffect: boolean }): RecordUpdateResult => {\n const { survey, record, sideEffect } = params\n const cycle = record.cycle!\n const result = new RecordUpdateResult({ record })\n Surveys.visitDescendantsAndSelfNodeDef({\n survey,\n cycle,\n nodeDef: Surveys.getNodeDefRoot({ survey }),\n visitor: (nodeDef) => {\n const hasAncestorCodeDefExcludedInClone =\n nodeDef.type === NodeDefType.code &&\n Surveys.getNodeDefAncestorCodes({ survey, nodeDef: nodeDef as NodeDefCode }).some(NodeDefs.isExcludedInClone)\n\n if (\n !NodeDefs.isInCycle(cycle)(nodeDef) ||\n NodeDefs.isExcludedInClone(nodeDef) ||\n hasAncestorCodeDefExcludedInClone\n ) {\n const nodesToDelete = Records.getNodesByDefUuid(nodeDef.uuid)(result.record)\n if (nodesToDelete.length > 0) {\n const partialUpdateResult = Records.deleteNodes(\n nodesToDelete.map((node) => node.uuid),\n { sideEffect }\n )(result.record)\n result.merge(partialUpdateResult)\n }\n }\n },\n })\n return result\n}\n\nconst cloneRecord = (params: { survey: Survey; record: Record; cycleTo: string; sideEffect?: boolean }) => {\n const { survey, record, cycleTo, sideEffect = false } = params\n\n const recordUpdated = sideEffect ? record : { ...record }\n recordUpdated.cycle = cycleTo\n recordUpdated.dateCreated = recordUpdated.dateModified = Dates.nowFormattedForStorage()\n delete recordUpdated.id\n\n // delete nodes not included in clone\n const updateResult = new RecordUpdateResult({ record: recordUpdated })\n updateResult.merge(removeExcludedNodes({ survey, record: updateResult.record, sideEffect }))\n updateResult.merge(RecordFixer.insertMissingSingleNodes({ survey, record: updateResult.record, sideEffect }))\n\n // assign new UUIDs with side effect on record and nodes, faster when record is big\n const {\n newNodeUuidsByOldUuid,\n newFileUuidsByOldUuid,\n record: recordUpdatedUuids,\n } = assignNewUuids({ record: updateResult.record, sideEffect })\n\n updateResult.merge(new RecordUpdateResult({ record: recordUpdatedUuids }))\n\n return { record: updateResult.record, newNodeUuidsByOldUuid, newFileUuidsByOldUuid }\n}\n\nexport const RecordCloner = {\n cloneRecord,\n}\n"]}
1
+ {"version":3,"file":"recordCloner.js","sourceRoot":"","sources":["../../../src/record/recordCloner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AACjD,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,EAAe,WAAW,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAU,OAAO,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAGhD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAMnC,MAAM,qBAAqB,GAAG,CAAC,MAG9B,EAA8G,EAAE;;IAC/G,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;IAErC,oCAAoC;IACpC,MAAM,qBAAqB,GAAwB,EAAE,CAAA;IACrD,MAAM,qBAAqB,GAAwB,EAAE,CAAA;IAErD,8GAA8G;IAC9G,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CACnD,CAAC,KAAW,EAAE,KAAW,EAAU,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,MAAM,CAC1G,CAAA;IAED,MAAM,aAAa,GA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A;IACvF,OAAO,aAAa,CAAC,EAAE,CAAA;IAEvB,qCAAqC;IACrC,MAAM,YAAY,GAAG,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAA;IACtE,YAAY,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;IAC5F,YAAY,CAAC,KAAK,CAAC,WAAW,CAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,CAAA;IAE7G,mFAAmF;IACnF,MAAM,EACJ,qBAAqB,EACrB,qBAAqB,EACrB,MAAM,EAAE,kBAAkB,GAC3B,GAAG,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IAE/D,YAAY,CAAC,KAAK,CAAC,IAAI,kBAAkB,CAAC,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAA;IAE1E,OAAO,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,CAAA;AACtF,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,WAAW;CACZ,CAAA","sourcesContent":["import { Node, NodeValues, Nodes } from '../node'\nimport { NodeKeys, NodeMetaKeys } from '../node/node'\nimport { NodeDefCode, NodeDefType, NodeDefs } from '../nodeDef'\nimport { Survey, Surveys } from '../survey'\nimport { Dates, Objects, UUIDs } from '../utils'\nimport { Validation } from '../validation'\nimport { Record } from './record'\nimport { RecordFixer } from './recordFixer'\nimport { RecordUpdateResult } from './recordNodesUpdater'\nimport { RecordValidations } from './recordValidations'\nimport { Records } from './records'\n\ntype OldUuidToNewUuidMap = {\n [key: string]: string\n}\n\nconst assignNewUuidsToNodes = (params: {\n record: Record\n sideEffect: boolean\n}): { newNodeUuidsByOldUuid: OldUuidToNewUuidMap; newFileUuidsByOldUuid: OldUuidToNewUuidMap; record: Record } => {\n const { record, sideEffect } = params\n\n // generate a new uuid for each node\n const newNodeUuidsByOldUuid: OldUuidToNewUuidMap = {}\n const newFileUuidsByOldUuid: OldUuidToNewUuidMap = {}\n\n // sort nodes before removing the id, to preserve their hierarchy (faster than comparing each meta.h property)\n const nodesArray = Records.getNodesArray(record).sort(\n (nodeA: Node, nodeB: Node): number => Nodes.getHierarchy(nodeA).length - Nodes.getHierarchy(nodeB).length\n )\n\n const recordUpdated = sideEffect ? record : { ...record }\n\n const nodes = recordUpdated.nodes ?? {}\n const nodesUpdated = sideEffect ? nodes : { ...nodes }\n\n // update nodes recordUuid and properties (it does side effect on nodes)\n nodesArray.forEach((node) => {\n let nodeUpdated = sideEffect ? node : { ...node }\n nodeUpdated.recordUuid = record.uuid\n nodeUpdated.dateCreated = nodeUpdated.dateModified = Dates.nowFormattedForStorage()\n\n const oldUuid = node.uuid\n const newUuid = UUIDs.v4()\n newNodeUuidsByOldUuid[oldUuid] = newUuid\n\n nodeUpdated.uuid = newUuid\n // consider every node as just created node\n delete nodeUpdated.id\n nodeUpdated.created = true // this flag will be used by the RDB generator)\n\n // update internal node uuids, meta hierarchy, file uuid (if any)\n const parentUuid = node.parentUuid\n if (parentUuid) {\n nodeUpdated.parentUuid = newNodeUuidsByOldUuid[parentUuid]\n }\n const hierarchy = node.meta?.h ?? []\n if (hierarchy.length > 0) {\n const hierarchyUpdated = hierarchy.map((ancestorUuid) => newNodeUuidsByOldUuid[ancestorUuid])\n nodeUpdated = Objects.assocPath({\n obj: nodeUpdated,\n path: [NodeKeys.meta, NodeMetaKeys.h],\n value: hierarchyUpdated,\n sideEffect,\n })\n }\n // assign new file uuid (file should be cloned elsewhere)\n const fileUuid = NodeValues.getFileUuid(node)\n if (fileUuid) {\n const newFileUuid = UUIDs.v4()\n nodeUpdated = Objects.assocPath({\n obj: nodeUpdated,\n path: [NodeKeys.value, NodeValues.ValuePropsFile.fileUuid],\n value: newFileUuid,\n })\n newFileUuidsByOldUuid[fileUuid] = newFileUuid\n }\n\n delete nodesUpdated[oldUuid]\n nodesUpdated[newUuid] = nodeUpdated\n })\n\n recordUpdated.nodes = nodesUpdated\n\n return { newNodeUuidsByOldUuid, newFileUuidsByOldUuid, record: recordUpdated }\n}\n\nconst assignNewUuidsToValidation = (params: {\n validation: Validation\n newNodeUuidsByOldUuid: OldUuidToNewUuidMap\n sideEffect: boolean\n}): Validation => {\n const { validation, newNodeUuidsByOldUuid, sideEffect } = params\n\n const validationFields = validation?.fields\n if (!validationFields) return validation\n\n const validationFieldsUpdated = sideEffect ? validationFields : { ...validationFields }\n\n Object.entries(validationFields).forEach(([oldFieldKey, validationField]) => {\n let newFieldKey\n if (oldFieldKey.startsWith(RecordValidations.prefixValidationFieldChildrenCount)) {\n const oldParentUuid = oldFieldKey.substring(\n RecordValidations.prefixValidationFieldChildrenCount.length,\n oldFieldKey.lastIndexOf('_')\n )\n const newParentUuid = newNodeUuidsByOldUuid[oldParentUuid]\n newFieldKey = oldFieldKey.replace(oldParentUuid, newParentUuid)\n } else {\n newFieldKey = newNodeUuidsByOldUuid[oldFieldKey]\n }\n if (newFieldKey) {\n validationFieldsUpdated[newFieldKey] = validationField\n }\n delete validationFieldsUpdated[oldFieldKey]\n })\n return Objects.assoc({\n obj: validation,\n prop: 'fields',\n value: validationFieldsUpdated,\n sideEffect,\n })\n}\n\nconst assignNewUuids = (params: {\n record: Record\n sideEffect: boolean\n}): { newNodeUuidsByOldUuid: OldUuidToNewUuidMap; newFileUuidsByOldUuid: OldUuidToNewUuidMap; record: Record } => {\n const { record, sideEffect } = params\n let recordUpdated = sideEffect ? record : { ...record }\n recordUpdated.uuid = UUIDs.v4()\n\n const {\n newNodeUuidsByOldUuid,\n newFileUuidsByOldUuid,\n record: recordUpdatedUuids,\n } = assignNewUuidsToNodes({ record: recordUpdated, sideEffect })\n\n recordUpdated = recordUpdatedUuids\n\n const { validation } = recordUpdated\n if (validation) {\n const validationUpdated = assignNewUuidsToValidation({\n validation,\n newNodeUuidsByOldUuid,\n sideEffect,\n })\n recordUpdated = Objects.assoc({ obj: recordUpdated, prop: 'validation', value: validationUpdated, sideEffect })\n }\n // re-build nodes index\n const nodes = recordUpdated.nodes!\n delete recordUpdated._nodesIndex\n delete recordUpdated.nodes\n recordUpdated = Records.addNodes(nodes, { sideEffect, sortNodes: true })(recordUpdated)\n\n return { newNodeUuidsByOldUuid, newFileUuidsByOldUuid, record: recordUpdated }\n}\n\nconst removeExcludedNodes = (params: { survey: Survey; record: Record; sideEffect: boolean }): RecordUpdateResult => {\n const { survey, record, sideEffect } = params\n const cycle = record.cycle!\n const result = new RecordUpdateResult({ record })\n Surveys.visitDescendantsAndSelfNodeDef({\n survey,\n cycle,\n nodeDef: Surveys.getNodeDefRoot({ survey }),\n visitor: (nodeDef) => {\n const hasAncestorCodeDefExcludedInClone =\n nodeDef.type === NodeDefType.code &&\n Surveys.getNodeDefAncestorCodes({ survey, nodeDef: nodeDef as NodeDefCode }).some(NodeDefs.isExcludedInClone)\n\n if (\n !NodeDefs.isInCycle(cycle)(nodeDef) ||\n NodeDefs.isExcludedInClone(nodeDef) ||\n hasAncestorCodeDefExcludedInClone\n ) {\n const nodesToDelete = Records.getNodesByDefUuid(nodeDef.uuid)(result.record)\n if (nodesToDelete.length > 0) {\n const partialUpdateResult = Records.deleteNodes(\n nodesToDelete.map((node) => node.uuid),\n { sideEffect }\n )(result.record)\n result.merge(partialUpdateResult)\n }\n }\n },\n })\n return result\n}\n\nconst cloneRecord = (params: { survey: Survey; record: Record; cycleTo: string; sideEffect?: boolean }) => {\n const { survey, record, cycleTo, sideEffect = false } = params\n\n const recordUpdated = sideEffect ? record : { ...record }\n recordUpdated.cycle = cycleTo\n recordUpdated.dateCreated = recordUpdated.dateModified = Dates.nowFormattedForStorage()\n delete recordUpdated.id\n\n // delete nodes not included in clone\n const updateResult = new RecordUpdateResult({ record: recordUpdated })\n updateResult.merge(removeExcludedNodes({ survey, record: updateResult.record, sideEffect }))\n updateResult.merge(RecordFixer.insertMissingSingleNodes({ survey, record: updateResult.record, sideEffect }))\n\n // assign new UUIDs with side effect on record and nodes, faster when record is big\n const {\n newNodeUuidsByOldUuid,\n newFileUuidsByOldUuid,\n record: recordUpdatedUuids,\n } = assignNewUuids({ record: updateResult.record, sideEffect })\n\n updateResult.merge(new RecordUpdateResult({ record: recordUpdatedUuids }))\n\n return { record: updateResult.record, newNodeUuidsByOldUuid, newFileUuidsByOldUuid }\n}\n\nexport const RecordCloner = {\n cloneRecord,\n}\n"]}