@openforis/arena-core 2.6.0 → 2.7.0

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 (67) hide show
  1. package/dist/esm/node/node.js.map +1 -1
  2. package/dist/esm/node/nodes.js +21 -2
  3. package/dist/esm/node/nodes.js.map +1 -1
  4. package/dist/esm/nodeDef/nodeDef.js.map +1 -1
  5. package/dist/esm/nodeDef/nodeDefs.js +9 -0
  6. package/dist/esm/nodeDef/nodeDefs.js.map +1 -1
  7. package/dist/esm/record/_records/recordCompletion.js +4 -1
  8. package/dist/esm/record/_records/recordCompletion.js.map +1 -1
  9. package/dist/esm/record/_records/recordGetters.js +12 -0
  10. package/dist/esm/record/_records/recordGetters.js.map +1 -1
  11. package/dist/esm/record/recordNodesUpdater/index.js +3 -0
  12. package/dist/esm/record/recordNodesUpdater/index.js.map +1 -1
  13. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +87 -0
  14. package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -0
  15. package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js +2 -0
  16. package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  17. package/dist/esm/record/recordUpdater.js +1 -0
  18. package/dist/esm/record/recordUpdater.js.map +1 -1
  19. package/dist/esm/record/recordValidator/attributeValidator.js +24 -8
  20. package/dist/esm/record/recordValidator/attributeValidator.js.map +1 -1
  21. package/dist/esm/record/records.js +2 -1
  22. package/dist/esm/record/records.js.map +1 -1
  23. package/dist/esm/survey/survey.js +1 -0
  24. package/dist/esm/survey/survey.js.map +1 -1
  25. package/dist/esm/survey/surveys/dependencies.js +4 -0
  26. package/dist/esm/survey/surveys/dependencies.js.map +1 -1
  27. package/dist/esm/tests/builder/surveyBuilder/nodeDefBuilder.js +8 -0
  28. package/dist/esm/tests/builder/surveyBuilder/nodeDefBuilder.js.map +1 -1
  29. package/dist/node/node.d.ts +7 -0
  30. package/dist/node/node.js.map +1 -1
  31. package/dist/node/nodes.d.ts +7 -0
  32. package/dist/node/nodes.js +21 -2
  33. package/dist/node/nodes.js.map +1 -1
  34. package/dist/nodeDef/nodeDef.d.ts +4 -0
  35. package/dist/nodeDef/nodeDef.js.map +1 -1
  36. package/dist/nodeDef/nodeDefs.d.ts +9 -0
  37. package/dist/nodeDef/nodeDefs.js +9 -0
  38. package/dist/nodeDef/nodeDefs.js.map +1 -1
  39. package/dist/record/_records/recordCompletion.js +4 -1
  40. package/dist/record/_records/recordCompletion.js.map +1 -1
  41. package/dist/record/_records/recordGetters.d.ts +5 -0
  42. package/dist/record/_records/recordGetters.js +14 -1
  43. package/dist/record/_records/recordGetters.js.map +1 -1
  44. package/dist/record/recordNodesUpdater/index.d.ts +3 -0
  45. package/dist/record/recordNodesUpdater/index.js +3 -0
  46. package/dist/record/recordNodesUpdater/index.js.map +1 -1
  47. package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.d.ts +23 -0
  48. package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +93 -0
  49. package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -0
  50. package/dist/record/recordNodesUpdater/recordNodesUpdater.js +2 -0
  51. package/dist/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
  52. package/dist/record/recordUpdater.js +1 -0
  53. package/dist/record/recordUpdater.js.map +1 -1
  54. package/dist/record/recordValidator/attributeValidator.js +24 -8
  55. package/dist/record/recordValidator/attributeValidator.js.map +1 -1
  56. package/dist/record/records.d.ts +2 -1
  57. package/dist/record/records.js +1 -0
  58. package/dist/record/records.js.map +1 -1
  59. package/dist/survey/survey.d.ts +1 -0
  60. package/dist/survey/survey.js +1 -0
  61. package/dist/survey/survey.js.map +1 -1
  62. package/dist/survey/surveys/dependencies.js +4 -0
  63. package/dist/survey/surveys/dependencies.js.map +1 -1
  64. package/dist/tests/builder/surveyBuilder/nodeDefBuilder.d.ts +1 -0
  65. package/dist/tests/builder/surveyBuilder/nodeDefBuilder.js +8 -0
  66. package/dist/tests/builder/surveyBuilder/nodeDefBuilder.js.map +1 -1
  67. package/package.json +1 -1
@@ -0,0 +1,23 @@
1
+ import { ArenaRecordNode } from '../../node';
2
+ import { NodeDef, NodeDefType } from '../../nodeDef';
3
+ import { RecordExpressionEvaluationContext } from './recordExpressionEvaluationContext';
4
+ import { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams';
5
+ import { RecordUpdateResult } from './recordUpdateResult';
6
+ /**
7
+ * Evaluates the "required if" condition of the specified child def in the context of the specified parent entity.
8
+ */
9
+ export declare const evaluateRequiredIf: (params: RecordExpressionEvaluationContext & {
10
+ nodeCtx: ArenaRecordNode;
11
+ nodeDef: NodeDef<NodeDefType>;
12
+ }) => Promise<boolean>;
13
+ /**
14
+ * Updates the "required if" flags (parent node meta `cReq`) of the node itself (if attribute) and of its dependents.
15
+ */
16
+ export declare const updateSelfAndDependentsRequired: (params: RecordNodeDependentsUpdateParams) => Promise<RecordUpdateResult>;
17
+ /**
18
+ * Recomputes the "required if" flags (parent node meta `cReq`) of the specified node defs in the whole record,
19
+ * e.g. after their "required if" condition has been added, changed or removed. Validation is not updated.
20
+ */
21
+ export declare const updateRequiredFlags: (params: RecordExpressionEvaluationContext & {
22
+ nodeDefUuids: string[];
23
+ }) => Promise<RecordUpdateResult>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.updateRequiredFlags = exports.updateSelfAndDependentsRequired = exports.evaluateRequiredIf = void 0;
13
+ const node_1 = require("../../node");
14
+ const nodeDef_1 = require("../../nodeDef");
15
+ const survey_1 = require("../../survey");
16
+ const survey_2 = require("../../survey/survey");
17
+ const recordGetters_1 = require("../_records/recordGetters");
18
+ const recordExpressionEvaluator_1 = require("../recordExpressionEvaluator");
19
+ const recordNodesDependentsUpdaterCommons_1 = require("./recordNodesDependentsUpdaterCommons");
20
+ const recordUpdateResult_1 = require("./recordUpdateResult");
21
+ const expressionEvaluator = new recordExpressionEvaluator_1.RecordExpressionEvaluator();
22
+ /**
23
+ * Evaluates the "required if" condition of the specified child def in the context of the specified parent entity.
24
+ */
25
+ const evaluateRequiredIf = (params) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const { nodeCtx, nodeDef } = params;
27
+ const exprEval = yield expressionEvaluator.evalApplicableExpression(Object.assign(Object.assign({}, params), { nodeCtx, expressions: nodeDef_1.NodeDefs.getRequiredIf(nodeDef) }));
28
+ return !!(exprEval === null || exprEval === void 0 ? void 0 : exprEval.value);
29
+ });
30
+ exports.evaluateRequiredIf = evaluateRequiredIf;
31
+ /**
32
+ * Updates the "required if" flags (parent node meta `cReq`) of the node itself (if attribute) and of its dependents.
33
+ */
34
+ const updateSelfAndDependentsRequired = (params) => __awaiter(void 0, void 0, void 0, function* () {
35
+ var _a;
36
+ const { survey, record, node, sideEffect = false } = params;
37
+ const updateResult = new recordUpdateResult_1.RecordUpdateResult({ record });
38
+ const nodePointersToUpdate = (0, recordNodesDependentsUpdaterCommons_1.getDependentNodePointersByType)({
39
+ survey,
40
+ record,
41
+ node,
42
+ dependencyType: survey_2.SurveyDependencyType.required,
43
+ includeSelfWhenSourceIsAttribute: true,
44
+ filterFn: (nodePointer) => nodeDef_1.NodeDefs.isRequiredIfDefined(nodePointer.nodeDef),
45
+ });
46
+ // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten
47
+ for (const { nodeCtx: nodeCtxNodePointer, nodeDef } of nodePointersToUpdate) {
48
+ const nodeCtx = (_a = updateResult.getNodeByUuid(nodeCtxNodePointer.uuid)) !== null && _a !== void 0 ? _a : nodeCtxNodePointer;
49
+ const valuePrev = node_1.Nodes.isChildRequired(nodeCtx, nodeDef.uuid);
50
+ // NOSONAR: sequential evaluation needed (see note above)
51
+ const value = yield (0, exports.evaluateRequiredIf)(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, nodeDef })); // NOSONAR
52
+ if (valuePrev === value)
53
+ continue;
54
+ const nodeCtxUpdated = node_1.Nodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect });
55
+ updateResult.addNode(nodeCtxUpdated, { sideEffect });
56
+ }
57
+ return updateResult;
58
+ });
59
+ exports.updateSelfAndDependentsRequired = updateSelfAndDependentsRequired;
60
+ const updateNodeDefRequiredFlags = (params) => __awaiter(void 0, void 0, void 0, function* () {
61
+ var _a;
62
+ const { nodeDef, updateResult, sideEffect = false } = params;
63
+ const requiredIfDefined = nodeDef_1.NodeDefs.isRequiredIfDefined(nodeDef);
64
+ const parentNodes = (0, recordGetters_1.getNodesByDefUuid)(nodeDef.parentUuid)(updateResult.record);
65
+ for (const parentNode of parentNodes) {
66
+ const nodeCtx = (_a = updateResult.getNodeByUuid(parentNode.uuid)) !== null && _a !== void 0 ? _a : parentNode;
67
+ const valuePrev = node_1.Nodes.isChildRequired(nodeCtx, nodeDef.uuid);
68
+ // sequential evaluation: the same parent node can be updated for different child defs
69
+ const value = requiredIfDefined && (yield (0, exports.evaluateRequiredIf)(Object.assign(Object.assign({}, params), { record: updateResult.record, nodeCtx, nodeDef }))); // NOSONAR
70
+ if (value !== valuePrev) {
71
+ const nodeCtxUpdated = node_1.Nodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect });
72
+ updateResult.addNode(nodeCtxUpdated, { sideEffect });
73
+ }
74
+ }
75
+ });
76
+ /**
77
+ * Recomputes the "required if" flags (parent node meta `cReq`) of the specified node defs in the whole record,
78
+ * e.g. after their "required if" condition has been added, changed or removed. Validation is not updated.
79
+ */
80
+ const updateRequiredFlags = (params) => __awaiter(void 0, void 0, void 0, function* () {
81
+ const { survey, record, nodeDefUuids } = params;
82
+ const updateResult = new recordUpdateResult_1.RecordUpdateResult({ record });
83
+ for (const nodeDefUuid of nodeDefUuids) {
84
+ const nodeDef = survey_1.Surveys.findNodeDefByUuid({ survey, uuid: nodeDefUuid });
85
+ if (!(nodeDef === null || nodeDef === void 0 ? void 0 : nodeDef.parentUuid))
86
+ continue;
87
+ // sequential: each node def update works on the record updated by the previous one
88
+ yield updateNodeDefRequiredFlags(Object.assign(Object.assign({}, params), { nodeDef, updateResult })); // NOSONAR
89
+ }
90
+ return updateResult;
91
+ });
92
+ exports.updateRequiredFlags = updateRequiredFlags;
93
+ //# sourceMappingURL=recordNodeDependentsRequiredUpdater.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recordNodeDependentsRequiredUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAmD;AACnD,2CAA8D;AAC9D,yCAAsC;AACtC,gDAA0D;AAC1D,6DAA6D;AAC7D,4EAAwE;AAExE,+FAAsF;AAEtF,6DAAyD;AAEzD,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAE3D;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAChC,MAGC,EACiB,EAAE;IACpB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IACnC,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC,wBAAwB,iCAC9D,MAAM,KACT,OAAO,EACP,WAAW,EAAE,kBAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,IAC5C,CAAA;IACF,OAAO,CAAC,EAAC,QAAQ,aAAR,QAAQ,uBAAR,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AAM,mBAAmB,GAAG,CACjC,MAAsE,EACzC,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,CAAA;IAC/C,MAAM,YAAY,GAAG,IAAI,uCAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAEvD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,gBAAO,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;QACxE,IAAI,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU,CAAA;YAAE,SAAQ;QAClC,mFAAmF;QACnF,MAAM,0BAA0B,iCAAM,MAAM,KAAE,OAAO,EAAE,YAAY,IAAG,CAAA,CAAC,UAAU;IACnF,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAbY,QAAA,mBAAmB,GAAnB,mBAAmB,CAa/B","sourcesContent":["import { ArenaRecordNode, Nodes } from '../../node'\nimport { NodeDef, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { RecordExpressionEvaluationContext } from './recordExpressionEvaluationContext'\nimport { getDependentNodePointersByType } from './recordNodesDependentsUpdaterCommons'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\n/**\n * Evaluates the \"required if\" condition of the specified child def in the context of the specified parent entity.\n */\nexport const evaluateRequiredIf = async (\n params: RecordExpressionEvaluationContext & {\n nodeCtx: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType>\n }\n): Promise<boolean> => {\n const { nodeCtx, nodeDef } = params\n const exprEval = await expressionEvaluator.evalApplicableExpression({\n ...params,\n nodeCtx,\n expressions: NodeDefs.getRequiredIf(nodeDef),\n })\n return !!exprEval?.value\n}\n\n/**\n * Updates the \"required if\" flags (parent node meta `cReq`) of the node itself (if attribute) and of its dependents.\n */\nexport const updateSelfAndDependentsRequired = async (\n params: RecordNodeDependentsUpdateParams\n): Promise<RecordUpdateResult> => {\n const { survey, record, node, sideEffect = false } = params\n const updateResult = new RecordUpdateResult({ record })\n\n const nodePointersToUpdate = getDependentNodePointersByType({\n survey,\n record,\n node,\n dependencyType: SurveyDependencyType.required,\n includeSelfWhenSourceIsAttribute: true,\n filterFn: (nodePointer) => NodeDefs.isRequiredIfDefined(nodePointer.nodeDef),\n })\n\n // NOTE: don't do it in parallel, same nodeCtx metadata could be overwritten\n for (const { nodeCtx: nodeCtxNodePointer, nodeDef } of nodePointersToUpdate) {\n const nodeCtx = updateResult.getNodeByUuid(nodeCtxNodePointer.uuid) ?? nodeCtxNodePointer\n const valuePrev = Nodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // NOSONAR: sequential evaluation needed (see note above)\n const value = await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef }) // NOSONAR\n if (valuePrev === value) continue\n\n const nodeCtxUpdated = Nodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n return updateResult\n}\n\nconst updateNodeDefRequiredFlags = async (\n params: RecordExpressionEvaluationContext & { nodeDef: NodeDef<NodeDefType>; updateResult: RecordUpdateResult }\n): Promise<void> => {\n const { nodeDef, updateResult, sideEffect = false } = params\n const requiredIfDefined = NodeDefs.isRequiredIfDefined(nodeDef)\n const parentNodes = getNodesByDefUuid(nodeDef.parentUuid!)(updateResult.record)\n\n for (const parentNode of parentNodes) {\n const nodeCtx = updateResult.getNodeByUuid(parentNode.uuid) ?? parentNode\n const valuePrev = Nodes.isChildRequired(nodeCtx, nodeDef.uuid)\n // sequential evaluation: the same parent node can be updated for different child defs\n const value =\n requiredIfDefined && (await evaluateRequiredIf({ ...params, record: updateResult.record, nodeCtx, nodeDef })) // NOSONAR\n if (value !== valuePrev) {\n const nodeCtxUpdated = Nodes.assocChildRequired(nodeCtx, nodeDef.uuid, value, { sideEffect })\n updateResult.addNode(nodeCtxUpdated, { sideEffect })\n }\n }\n}\n\n/**\n * Recomputes the \"required if\" flags (parent node meta `cReq`) of the specified node defs in the whole record,\n * e.g. after their \"required if\" condition has been added, changed or removed. Validation is not updated.\n */\nexport const updateRequiredFlags = async (\n params: RecordExpressionEvaluationContext & { nodeDefUuids: string[] }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodeDefUuids } = params\n const updateResult = new RecordUpdateResult({ record })\n\n for (const nodeDefUuid of nodeDefUuids) {\n const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: nodeDefUuid })\n if (!nodeDef?.parentUuid) continue\n // sequential: each node def update works on the record updated by the previous one\n await updateNodeDefRequiredFlags({ ...params, nodeDef, updateResult }) // NOSONAR\n }\n return updateResult\n}\n"]}
@@ -22,6 +22,7 @@ const recordNodeDependentsEditableUpdater_1 = require("./recordNodeDependentsEdi
22
22
  const recordNodeDependentsEnumeratedEntitiesUpdater_1 = require("./recordNodeDependentsEnumeratedEntitiesUpdater");
23
23
  const recordNodeDependentsEnumeratingItemsUpdater_1 = require("./recordNodeDependentsEnumeratingItemsUpdater");
24
24
  const recordNodeDependentsFileNamesEvaluator_1 = require("./recordNodeDependentsFileNamesEvaluator");
25
+ const recordNodeDependentsRequiredUpdater_1 = require("./recordNodeDependentsRequiredUpdater");
25
26
  const recordNodeDependentsVisibleUpdater_1 = require("./recordNodeDependentsVisibleUpdater");
26
27
  const recordUpdateResult_1 = require("./recordUpdateResult");
27
28
  /**
@@ -39,6 +40,7 @@ const dependentsUpdaters = [
39
40
  recordNodeDependentsApplicableUpdater_1.updateSelfAndDependentsApplicable,
40
41
  recordNodeDependentsDefaultValuesUpdater_1.updateSelfAndDependentsDefaultValues,
41
42
  recordNodeDependentsEditableUpdater_1.updateSelfAndDependentsEditable,
43
+ recordNodeDependentsRequiredUpdater_1.updateSelfAndDependentsRequired,
42
44
  recordNodeDependentsVisibleUpdater_1.updateSelfAndDependentsVisible,
43
45
  recordNodeDependentsCodeAttributesUpdater_1.updateDependentCodeAttributes,
44
46
  recordNodeDependentsEnumeratedEntitiesUpdater_1.updateDependentEnumeratedEntities,
@@ -1 +1 @@
1
- {"version":3,"file":"recordNodesUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAmC;AAInC,2CAAgD;AAChD,yCAAsC;AACtC,6DAA6D;AAC7D,mGAA2F;AAC3F,2GAA2F;AAC3F,yFAA0E;AAC1E,yGAAiG;AACjG,+FAAuF;AACvF,mHAAmG;AACnG,+GAAuG;AACvG,qGAA2F;AAE3F,6FAAqF;AAErF,6DAAyD;AAEzD;;;;GAIG;AACH,MAAM,6BAA6B,GAAG,CAAC,CAAA;AAIvC;;GAEG;AACH,MAAM,kBAAkB,GAAkC;IACxD,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,wDAAqB,kCAAM,MAAM,KAAE,SAAS,EAAE,0BAAgB,CAAC,GAAG,IAAG;IACjF,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,wDAAqB,kCAAM,MAAM,KAAE,SAAS,EAAE,0BAAgB,CAAC,GAAG,IAAG;IACjF,yEAAiC;IACjC,+EAAoC;IACpC,qEAA+B;IAC/B,mEAA8B;IAC9B,yEAA6B;IAC7B,iFAAiC;IACjC,qFAAuC;IACvC,yEAAgC;CACjC,CAAA;AAEM,MAAM,qBAAqB,GAAG,CACnC,MAAkE,EACrC,EAAE;;IAC/B,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAC5D,MAAM,mBAAmB,GAAG,UAAU,CAAC,C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uGAAuG;gBACvG,MAAM,IAAI,GAAG,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;gBACjD,MAAM,sBAAsB,GAAG,MAAM,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,UAAU;gBAC/F,YAAY,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;gBAC1C,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;YAClE,CAAC;YAED,8BAA8B;YAC9B,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAE/D,uBAAuB;YACvB,kBAAkB,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAtDY,QAAA,qBAAqB,GAArB,qBAAqB,CAsDjC","sourcesContent":["import { Queue } from '../../utils'\n\nimport { Dictionary } from '../../common'\nimport { ArenaRecordNode } from '../../node'\nimport { NodeDefCountType } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater'\nimport { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater'\nimport { updateDependentsCount } from './recordNodeDependentsCountUpdater'\nimport { updateSelfAndDependentsDefaultValues } from './recordNodeDependentsDefaultValuesUpdater'\nimport { updateSelfAndDependentsEditable } from './recordNodeDependentsEditableUpdater'\nimport { updateDependentEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { updateDependentEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { updateSelfAndDependentsFileNames } from './recordNodeDependentsFileNamesEvaluator'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { updateSelfAndDependentsVisible } from './recordNodeDependentsVisibleUpdater'\nimport { NodesUpdateParams } from './recordNodesCreator'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n/**\n * Nodes can be visited maximum 2 times during the update of the dependent nodes, to avoid loops in the evaluation.\n * The first time the applicability can depend on attributes with default values not applied yet.\n * The second time the applicability expression can be evaluated correctly.\n */\nconst MAX_DEPENDENTS_VISITING_TIMES = 2\n\ntype RecordNodeDependentsUpdater = (params: RecordNodeDependentsUpdateParams) => Promise<RecordUpdateResult>\n\n/**\n * Updaters applied (in this order) to every visited node and to its dependents.\n */\nconst dependentsUpdaters: RecordNodeDependentsUpdater[] = [\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.min }),\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.max }),\n updateSelfAndDependentsApplicable,\n updateSelfAndDependentsDefaultValues,\n updateSelfAndDependentsEditable,\n updateSelfAndDependentsVisible,\n updateDependentCodeAttributes,\n updateDependentEnumeratedEntities,\n updateDependentEnumeratingItemsEntities,\n updateSelfAndDependentsFileNames,\n]\n\nexport const updateNodesDependents = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes, sideEffect = false } = params\n const initialNodesToVisit = sideEffect ? nodes : { ...nodes }\n\n // include onUpdate dependents (always included in every record update)\n const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey })\n if (onUpdateDependentDefs.length > 0) {\n for (const dependentDef of onUpdateDependentDefs) {\n const dependentNodes = getNodesByDefUuid(dependentDef.uuid)(record)\n for (const node of dependentNodes) {\n initialNodesToVisit[node.uuid] = node\n }\n }\n }\n\n const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit })\n\n const createNodeUpdateParams = (node: ArenaRecordNode): RecordNodeDependentsUpdateParams => ({\n ...params,\n record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)\n node,\n })\n\n const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit))\n\n // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)\n const visitedCountByUuid: Dictionary<number> = {}\n\n while (!nodeUuidsToVisit.isEmpty()) {\n const nodeUuid = nodeUuidsToVisit.dequeue()!\n\n const visitedCount = visitedCountByUuid[nodeUuid] ?? 0\n\n if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {\n const nodesUpdatedCurrent: Dictionary<ArenaRecordNode> = {}\n for (const dependentsUpdater of dependentsUpdaters) {\n // updaters must run sequentially: each one works on the record (and node) updated by the previous ones\n const node = updateResult.getNodeByUuid(nodeUuid)\n const dependentsUpdateResult = await dependentsUpdater(createNodeUpdateParams(node)) // NOSONAR\n updateResult.merge(dependentsUpdateResult)\n Object.assign(nodesUpdatedCurrent, dependentsUpdateResult.nodes)\n }\n\n // Mark updated nodes to visit\n nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent))\n\n // Mark node as visited\n visitedCountByUuid[nodeUuid] = visitedCount + 1\n }\n }\n\n return updateResult\n}\n"]}
1
+ {"version":3,"file":"recordNodesUpdater.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAAmC;AAInC,2CAAgD;AAChD,yCAAsC;AACtC,6DAA6D;AAC7D,mGAA2F;AAC3F,2GAA2F;AAC3F,yFAA0E;AAC1E,yGAAiG;AACjG,+FAAuF;AACvF,mHAAmG;AACnG,+GAAuG;AACvG,qGAA2F;AAE3F,+FAAuF;AACvF,6FAAqF;AAErF,6DAAyD;AAEzD;;;;GAIG;AACH,MAAM,6BAA6B,GAAG,CAAC,CAAA;AAIvC;;GAEG;AACH,MAAM,kBAAkB,GAAkC;IACxD,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,wDAAqB,kCAAM,MAAM,KAAE,SAAS,EAAE,0BAAgB,CAAC,GAAG,IAAG;IACjF,CAAC,MAAM,EAAE,EAAE,CAAC,IAAA,wDAAqB,kCAA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IAEpE,+GAA+G;IAC/G,MAAM,kBAAkB,GAAuB,EAAE,CAAA;IAEjD,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE,CAAC;QACnC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,OAAO,EAAG,CAAA;QAE5C,MAAM,YAAY,SAAG,kBAAkB,CAAC,QAAQ,CAAC,mCAAI,CAAC,CAAA;QAEtD,IAAI,YAAY,GAAG,6BAA6B,EAAE,CAAC;YACjD,MAAM,mBAAmB,GAAgC,EAAE,CAAA;YAC3D,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;gBACnD,uGAAuG;gBACvG,MAAM,IAAI,GAAG,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;gBACjD,MAAM,sBAAsB,GAAG,MAAM,iBAAiB,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAA,CAAC,UAAU;gBAC/F,YAAY,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;gBAC1C,MAAM,CAAC,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;YAClE,CAAC;YAED,8BAA8B;YAC9B,gBAAgB,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAE/D,uBAAuB;YACvB,kBAAkB,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AAtDY,QAAA,qBAAqB,GAArB,qBAAqB,CAsDjC","sourcesContent":["import { Queue } from '../../utils'\n\nimport { Dictionary } from '../../common'\nimport { ArenaRecordNode } from '../../node'\nimport { NodeDefCountType } from '../../nodeDef'\nimport { Surveys } from '../../survey'\nimport { getNodesByDefUuid } from '../_records/recordGetters'\nimport { updateSelfAndDependentsApplicable } from './recordNodeDependentsApplicableUpdater'\nimport { updateDependentCodeAttributes } from './recordNodeDependentsCodeAttributesUpdater'\nimport { updateDependentsCount } from './recordNodeDependentsCountUpdater'\nimport { updateSelfAndDependentsDefaultValues } from './recordNodeDependentsDefaultValuesUpdater'\nimport { updateSelfAndDependentsEditable } from './recordNodeDependentsEditableUpdater'\nimport { updateDependentEnumeratedEntities } from './recordNodeDependentsEnumeratedEntitiesUpdater'\nimport { updateDependentEnumeratingItemsEntities } from './recordNodeDependentsEnumeratingItemsUpdater'\nimport { updateSelfAndDependentsFileNames } from './recordNodeDependentsFileNamesEvaluator'\nimport { RecordNodeDependentsUpdateParams } from './recordNodeDependentsUpdateParams'\nimport { updateSelfAndDependentsRequired } from './recordNodeDependentsRequiredUpdater'\nimport { updateSelfAndDependentsVisible } from './recordNodeDependentsVisibleUpdater'\nimport { NodesUpdateParams } from './recordNodesCreator'\nimport { RecordUpdateResult } from './recordUpdateResult'\n\n/**\n * Nodes can be visited maximum 2 times during the update of the dependent nodes, to avoid loops in the evaluation.\n * The first time the applicability can depend on attributes with default values not applied yet.\n * The second time the applicability expression can be evaluated correctly.\n */\nconst MAX_DEPENDENTS_VISITING_TIMES = 2\n\ntype RecordNodeDependentsUpdater = (params: RecordNodeDependentsUpdateParams) => Promise<RecordUpdateResult>\n\n/**\n * Updaters applied (in this order) to every visited node and to its dependents.\n */\nconst dependentsUpdaters: RecordNodeDependentsUpdater[] = [\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.min }),\n (params) => updateDependentsCount({ ...params, countType: NodeDefCountType.max }),\n updateSelfAndDependentsApplicable,\n updateSelfAndDependentsDefaultValues,\n updateSelfAndDependentsEditable,\n updateSelfAndDependentsRequired,\n updateSelfAndDependentsVisible,\n updateDependentCodeAttributes,\n updateDependentEnumeratedEntities,\n updateDependentEnumeratingItemsEntities,\n updateSelfAndDependentsFileNames,\n]\n\nexport const updateNodesDependents = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes, sideEffect = false } = params\n const initialNodesToVisit = sideEffect ? nodes : { ...nodes }\n\n // include onUpdate dependents (always included in every record update)\n const onUpdateDependentDefs = Surveys.getOnUpdateDependents({ survey })\n if (onUpdateDependentDefs.length > 0) {\n for (const dependentDef of onUpdateDependentDefs) {\n const dependentNodes = getNodesByDefUuid(dependentDef.uuid)(record)\n for (const node of dependentNodes) {\n initialNodesToVisit[node.uuid] = node\n }\n }\n }\n\n const updateResult = new RecordUpdateResult({ record, nodes: initialNodesToVisit })\n\n const createNodeUpdateParams = (node: ArenaRecordNode): RecordNodeDependentsUpdateParams => ({\n ...params,\n record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)\n node,\n })\n\n const nodeUuidsToVisit = new Queue(Object.keys(initialNodesToVisit))\n\n // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)\n const visitedCountByUuid: Dictionary<number> = {}\n\n while (!nodeUuidsToVisit.isEmpty()) {\n const nodeUuid = nodeUuidsToVisit.dequeue()!\n\n const visitedCount = visitedCountByUuid[nodeUuid] ?? 0\n\n if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {\n const nodesUpdatedCurrent: Dictionary<ArenaRecordNode> = {}\n for (const dependentsUpdater of dependentsUpdaters) {\n // updaters must run sequentially: each one works on the record (and node) updated by the previous ones\n const node = updateResult.getNodeByUuid(nodeUuid)\n const dependentsUpdateResult = await dependentsUpdater(createNodeUpdateParams(node)) // NOSONAR\n updateResult.merge(dependentsUpdateResult)\n Object.assign(nodesUpdatedCurrent, dependentsUpdateResult.nodes)\n }\n\n // Mark updated nodes to visit\n nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent))\n\n // Mark node as visited\n visitedCountByUuid[nodeUuid] = visitedCount + 1\n }\n }\n\n return updateResult\n}\n"]}
@@ -20,6 +20,7 @@ const records_1 = require("./records");
20
20
  const recordValidator_1 = require("./recordValidator");
21
21
  const validationDependencyTypes = [
22
22
  survey_1.SurveyDependencyType.validations,
23
+ survey_1.SurveyDependencyType.required,
23
24
  survey_1.SurveyDependencyType.minCount,
24
25
  survey_1.SurveyDependencyType.maxCount,
25
26
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAuD;AAEvD,sCAAiE;AACjE,oCAAyC;AACzC,2DAAuD;AACvD,iDAA6C;AAE7C,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,6BAAoB,CAAC,QAAQ;CAC9B,CAAA;AAED,MAAM,kCAAkC,GAAG,CAAC,MAI3C,EAAiB,EAAE;IAClB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAA;IACxC,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAuB,CAAA;IAC1D,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;QACxC,KAAK,MAAM,cAAc,IAAI,yBAAyB,EAAE,CAAC;YACvD,MAAM,YAAY,GAAG,iBAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,IAAI,EAAE,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;YAC3F,KAAK,MAAM,OAAO,IAAI,YAAY,EAAE,CAAC;gBACnC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;gBACxC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAA;gBACxC,MAAM,GAAG,GAAG,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,EAAE,IAAI,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,EAAE,EAAE,CAAA;gBACvD,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBAClC,mBAAmB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CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAAgD,EAA+B,EAAE;IACzG,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,+HAA+H;IAC/H,iBAAiB;IACjB,gIAAgI;IAChI,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,kIAAkI;IAClI,UAAU;IACV,qIAAqI;IACrI,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType)(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid(attributeUuid)(record)\n if (!attribute) throw new SystemError(SystemErrorKeys.record.nodeNotFound, { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.removeNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n /** Creates the descendants of a node and updates dependents (applicability, default values, calculations...) and validation */\n createDescendants,\n /** Creates a node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n /** Deletes the node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNode,\n /** Deletes the nodes and their descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNodes,\n}\n"]}
1
+ {"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAA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AC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAEY,QAAA,aAAa,GAAG;IAC3B,+HAA+H;IAC/H,iBAAiB;IACjB,gIAAgI;IAChI,wBAAwB;IACxB,gBAAgB;IAChB,oBAAoB;IACpB,kIAAkI;IAClI,UAAU;IACV,qIAAqI;IACrI,WAAW;CACZ,CAAA","sourcesContent":["import { Dictionary } from '../common'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaRecordNode, NodePointer, NodesMap } from '../node'\nimport { Survey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { NodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { NodeCreateParams, NodesUpdateParams } from './recordNodesUpdater/recordNodesCreator'\nimport { Records } from './records'\nimport { RecordValidator } from './recordValidator'\n\nconst validationDependencyTypes = [\n SurveyDependencyType.validations,\n SurveyDependencyType.required,\n SurveyDependencyType.minCount,\n SurveyDependencyType.maxCount,\n]\n\nconst getDependentValidationNodePointers = (params: {\n survey: Survey\n record: ArenaRecord\n nodes: NodesMap\n}): NodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, NodePointer>()\n for (const node of Object.values(nodes)) {\n for (const dependencyType of validationDependencyTypes) {\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType)(record)\n for (const pointer of nodePointers) {\n const nodeCtxUuid = pointer.nodeCtx.uuid\n const nodeDefUuid = pointer.nodeDef.uuid\n const key = `${nodeCtxUuid ?? ''}:${nodeDefUuid ?? ''}`\n if (!uniquePointersByKey.has(key)) {\n uniquePointersByKey.set(key, pointer)\n }\n }\n }\n }\n return Array.from(uniquePointersByKey.values())\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n params: NodesUpdateParams & { nodes: Dictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { user, survey, dateModified = Dates.nowFormattedForStorage() } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents(params)\n const { nodes: updatedNodes, record: updatedRecord } = updateResult\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = NodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n record: updatedRecord,\n nodes: nodesToValidate,\n })\n\n const validation = Validations.mergeValidations(validationUpdatedNodes)(Validations.getValidation(updatedRecord))\n updatedRecord.validation = validation\n updatedRecord.dateModified = dateModified\n\n updateResult.validation = validation\n\n return updateResult\n}\n\nconst createDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (params: NodeCreateParams): Promise<RecordUpdateResult> => {\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addNodeAndDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createRootEntity = async (\n params: NodesUpdateParams & {\n createMultipleEntities?: boolean\n }\n): Promise<RecordUpdateResult> => {\n const { survey, createMultipleEntities = true } = params\n\n return createNodeAndDescendants({ ...params, nodeDef: Surveys.getNodeDefRoot({ survey }), createMultipleEntities })\n}\n\nconst updateAttributeValue = async (\n params: NodesUpdateParams & {\n attributeUuid: string\n value: any\n }\n): Promise<RecordUpdateResult> => {\n const { attributeUuid, record, value, dateModified = Dates.nowFormattedForStorage(), sideEffect = false } = params\n const attribute = Records.getNodeByUuid(attributeUuid)(record)\n if (!attribute) throw new SystemError(SystemErrorKeys.record.nodeNotFound, { uuid: attributeUuid })\n\n let attributeUpdated = sideEffect ? attribute : { ...attribute }\n attributeUpdated.value = value\n attributeUpdated.dateModified = dateModified\n // reset defaultValueApplied flag\n attributeUpdated = Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect })\n\n const nodesUpdated = { [attributeUuid]: attributeUpdated }\n\n const _record = Records.addNode(attributeUpdated, { sideEffect })(record)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: _record, nodes: nodesUpdated })\n}\n\nconst deleteNodes = async (\n params: NodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { nodeUuids, record: _record, sideEffect = false } = params\n\n const updateResult = Records.removeNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({ ...params, record, nodes: nodesDeleted })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: NodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\nexport const RecordUpdater = {\n /** Creates the descendants of a node and updates dependents (applicability, default values, calculations...) and validation */\n createDescendants,\n /** Creates a node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n createNodeAndDescendants,\n createRootEntity,\n updateAttributeValue,\n /** Deletes the node and its descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNode,\n /** Deletes the nodes and their descendants and updates dependents (applicability, default values, calculations...) and validation */\n deleteNodes,\n}\n"]}
@@ -18,6 +18,7 @@ const utils_1 = require("../../utils");
18
18
  const validation_1 = require("../../validation");
19
19
  const nodePointers_1 = require("../nodePointers");
20
20
  const recordExpressionEvaluator_1 = require("../recordExpressionEvaluator");
21
+ const recordNodeDependentsRequiredUpdater_1 = require("../recordNodesUpdater/recordNodeDependentsRequiredUpdater");
21
22
  const records_1 = require("../records");
22
23
  const recordValidations_1 = require("../recordValidations");
23
24
  const attributeKeyValidator_1 = require("./attributeKeyValidator");
@@ -69,17 +70,29 @@ const _getValidationMessagesWithDefault = (params) => {
69
70
  }
70
71
  return messages;
71
72
  };
72
- const _validateRequired = (params) => (_field, node) => {
73
- const { nodeDef } = params;
74
- const valid = (!nodeDef_1.NodeDefs.isKey(nodeDef) && !nodeDef_1.NodeDefs.isRequired(nodeDef)) || !node_1.Nodes.isValueBlank(node);
75
- return Promise.resolve(valid
73
+ const _isValueRequired = (params) => __awaiter(void 0, void 0, void 0, function* () {
74
+ const { record, attribute, nodeDef } = params;
75
+ if (nodeDef_1.NodeDefs.isKey(nodeDef) || nodeDef_1.NodeDefs.isRequired(nodeDef))
76
+ return true;
77
+ if (!nodeDef_1.NodeDefs.isRequiredIfDefined(nodeDef))
78
+ return false;
79
+ const parentNode = records_1.Records.getParent(attribute)(record);
80
+ if (!parentNode)
81
+ return false;
82
+ // evaluated here (not read from the parent node meta flag) so validation doesn't depend on up to date node meta
83
+ // (e.g. records created before the "required if" condition was defined)
84
+ return (0, recordNodeDependentsRequiredUpdater_1.evaluateRequiredIf)(Object.assign(Object.assign({}, params), { nodeCtx: parentNode, nodeDef }));
85
+ });
86
+ const _validateRequired = (params) => (_field, node) => __awaiter(void 0, void 0, void 0, function* () {
87
+ const valid = !node_1.Nodes.isValueBlank(node) || !(yield _isValueRequired(params));
88
+ return valid
76
89
  ? validation_1.ValidationResultFactory.createInstance()
77
90
  : validation_1.ValidationResultFactory.createInstance({
78
91
  key: 'record.attribute.valueRequired',
79
92
  severity: validation_1.ValidationSeverity.error,
80
93
  valid,
81
- }));
82
- };
94
+ });
95
+ });
83
96
  /**
84
97
  * Evaluates the validation expressions.
85
98
  */
@@ -125,7 +138,7 @@ const validateAttribute = (params) => __awaiter(void 0, void 0, void 0, function
125
138
  const validatorParams = Object.assign(Object.assign({}, params), { nodeDef });
126
139
  return new validation_1.Validator().validate(attribute, {
127
140
  [node_1.NodeKeys.value]: [
128
- _validateRequired({ nodeDef }),
141
+ _validateRequired(validatorParams),
129
142
  attributeTypeValidator_1.AttributeTypeValidator.validateValueType(validatorParams),
130
143
  _validateNodeValidations(validatorParams),
131
144
  attributeKeyValidator_1.AttributeKeyValidator.validateAttributeKey(validatorParams),
@@ -170,7 +183,10 @@ const findSortedNodesToValidate = (params) => {
170
183
  continue;
171
184
  }
172
185
  // Get dependents and attribute itself
173
- const nodePointersAttributeAndDependents = records_1.Records.getDependentNodePointers(survey, node, survey_2.SurveyDependencyType.validations, true)(record);
186
+ const nodePointersAttributeAndDependents = [
187
+ ...records_1.Records.getDependentNodePointers(survey, node, survey_2.SurveyDependencyType.validations, true)(record),
188
+ ...records_1.Records.getDependentNodePointers(survey, node, survey_2.SurveyDependencyType.required)(record),
189
+ ];
174
190
  const nodeParent = records_1.Records.getParent(node)(record);
175
191
  result.push(...nodePointers_1.NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }), ...findSiblingKeyNodesToValidate(Object.assign(Object.assign({}, params), { nodeDef, nodeParent, attribute: node, siblingKeyNodesCache })));
176
192
  if ((_a = nodeDef_1.NodeDefs.getValidations(nodeDef)) === null || _a === void 0 ? void 0 : _a.unique) {
@@ -1 +1 @@
1
- {"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAyE;AACzE,2CAA+F;AAG/F,yCAA8C;AAC9C,gDAA0D;AAC1D,uCAAqC;AACrC,iDAMyB;AAEzB,kDAA8C;AAE9C,4EAAwE;AACxE,wCAAoC;AACpC,4DAAwD;AACxD,mEAAuG;AACvG,qEAAiE;AACjE,yEAAqE;AAErE,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AA6B3D,MAAM,mBAAmB,GAAG,CAC1B,MAAkF,EAC5D,EAAE;IACxB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,M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,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QACrE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,wCAAwC,GAAG,CAC/C,MAAuC,EACZ,EAAE;IAC7B,MAAM,eAAe,GAAsB,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAC5E,MAAM,qBAAqB,GAAqB,EAAE,CAAA;IAClD,6EAA6E;IAC7E,MAAM,eAAe,GAAG,IAAA,6CAAqB,GAAE,CAAA;IAE/C,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAEY,QAAA,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodeItem[]>\n\nconst _getSiblingNodeKeys = (\n params: AttributeValidatorParams & { siblingKeyNodesCache?: SiblingKeyNodesCache }\n): SiblingKeyNodeItem[] => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) {\n return []\n }\n const ancestorMultipleEntity = Records.getAncestor(attribute, ancestorMultipleEntityDef.uuid)(record)\n if (!ancestorMultipleEntity) return []\n\n const ancestorMultipleEntityParent = Records.getParent(ancestorMultipleEntity)(record)\n if (!ancestorMultipleEntityParent) return []\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let items = siblingKeyNodesCache?.get(cacheKey)\n if (!items) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings(ancestorMultipleEntity, true)(record)\n items = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes(survey, entity, undefined, keyDefs)(record)\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n siblingKeyNodesCache?.set(cacheKey, items)\n }\n return items.filter((item) => item.entityUuid !== ancestorMultipleEntity.uuid)\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _validateRequired =\n (params: { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n (_field: string, node: any): Promise<ValidationResult> => {\n const { nodeDef } = params\n const valid = (!NodeDefs.isKey(nodeDef) && !NodeDefs.isRequired(nodeDef)) || !Nodes.isValueBlank(node)\n return Promise.resolve(\n valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n )\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: { user: User; survey: Survey; record: ArenaRecord; nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable(attribute)(record)) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired({ nodeDef }),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache?: SiblingKeyNodesCache\n }\n) => {\n const { survey, nodeDef, nodeParent: parentNode, attribute } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeys = _getSiblingNodeKeys(params)\n const siblingNodeKeysWithSameValue: ArenaRecordNode[] = []\n const siblingNodeKeysWithErrors: ArenaRecordNode[] = []\n siblingNodeKeys.forEach(({ keyNode, hasErrors }) => {\n if (NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })) {\n siblingNodeKeysWithSameValue.push(keyNode)\n }\n if (hasErrors) {\n siblingNodeKeysWithErrors.push(keyNode)\n }\n })\n return [...siblingNodeKeysWithSameValue, ...siblingNodeKeysWithErrors]\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result = []\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = Records.getDependentNodePointers(\n survey,\n node,\n SurveyDependencyType.validations,\n true\n )(record)\n\n const nodeParent = Records.getParent(node)(record)\n\n result.push(\n ...NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }),\n ...findSiblingKeyNodesToValidate({ ...params, nodeDef, nodeParent, attribute: node, siblingKeyNodesCache })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n result.push(...Records.getAttributeSiblings(node, nodeDef)(record))\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
1
+ {"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAyE;AACzE,2CAA+F;AAG/F,yCAA8C;AAC9C,gDAA0D;AAC1D,uCAAqC;AACrC,iDAMyB;AAEzB,kDAA8C;AAE9C,4EAAwE;AACxE,mHAA8F;AAC9F,wCAAoC;AACpC,4DAAwD;AACxD,mEAAuG;AACvG,qEAAiE;AACjE,yEAAqE;AAErE,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AA6B3D,MAAM,mBAAmB,GAAG,CAC1B,MAAkF,EAC5D,EAAE;IACxB,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAA;IAElE,MAAM,YAAY,GAAG,gBAAO,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,CAAA;IACtF,MAAM,yBAAyB,GAAG,gBAAO,CAAC,gCAAgC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAA;IAC7G,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAC/B,OAAO,EAAE,CAAA;IACX,CAAC;I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AAC,EACtG,GAAG,6BAA6B,iCAAM,MAAM,KAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,oBAAoB,IAAG,CAC5G,CAAA;QAED,IAAI,MAAA,kBAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,0CAAE,MAAM,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,GAAG,iBAAO,CAAC,oBAAoB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAA;QACrE,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,wCAAwC,GAAG,CAC/C,MAAuC,EACZ,EAAE;IAC7B,MAAM,eAAe,GAAsB,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAC5E,MAAM,qBAAqB,GAAqB,EAAE,CAAA;IAClD,6EAA6E;IAC7E,MAAM,eAAe,GAAG,IAAA,6CAAqB,GAAE,CAAA;IAE/C,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAEY,QAAA,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { evaluateRequiredIf } from '../recordNodesUpdater/recordNodeDependentsRequiredUpdater'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodeItem[]>\n\nconst _getSiblingNodeKeys = (\n params: AttributeValidatorParams & { siblingKeyNodesCache?: SiblingKeyNodesCache }\n): SiblingKeyNodeItem[] => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) {\n return []\n }\n const ancestorMultipleEntity = Records.getAncestor(attribute, ancestorMultipleEntityDef.uuid)(record)\n if (!ancestorMultipleEntity) return []\n\n const ancestorMultipleEntityParent = Records.getParent(ancestorMultipleEntity)(record)\n if (!ancestorMultipleEntityParent) return []\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let items = siblingKeyNodesCache?.get(cacheKey)\n if (!items) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings(ancestorMultipleEntity, true)(record)\n items = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes(survey, entity, undefined, keyDefs)(record)\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n siblingKeyNodesCache?.set(cacheKey, items)\n }\n return items.filter((item) => item.entityUuid !== ancestorMultipleEntity.uuid)\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _isValueRequired = async (\n params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }\n): Promise<boolean> => {\n const { record, attribute, nodeDef } = params\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parentNode = Records.getParent(attribute)(record)\n if (!parentNode) return false\n // evaluated here (not read from the parent node meta flag) so validation doesn't depend on up to date node meta\n // (e.g. records created before the \"required if\" condition was defined)\n return evaluateRequiredIf({ ...params, nodeCtx: parentNode, nodeDef })\n}\n\nconst _validateRequired =\n (params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_field: string, node: any): Promise<ValidationResult> => {\n const valid = !Nodes.isValueBlank(node) || !(await _isValueRequired(params))\n return valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: { user: User; survey: Survey; record: ArenaRecord; nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable(attribute)(record)) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired(validatorParams),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache?: SiblingKeyNodesCache\n }\n) => {\n const { survey, nodeDef, nodeParent: parentNode, attribute } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeys = _getSiblingNodeKeys(params)\n const siblingNodeKeysWithSameValue: ArenaRecordNode[] = []\n const siblingNodeKeysWithErrors: ArenaRecordNode[] = []\n siblingNodeKeys.forEach(({ keyNode, hasErrors }) => {\n if (NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })) {\n siblingNodeKeysWithSameValue.push(keyNode)\n }\n if (hasErrors) {\n siblingNodeKeysWithErrors.push(keyNode)\n }\n })\n return [...siblingNodeKeysWithSameValue, ...siblingNodeKeysWithErrors]\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result = []\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = [\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.validations, true)(record),\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.required)(record),\n ]\n\n const nodeParent = Records.getParent(node)(record)\n\n result.push(\n ...NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }),\n ...findSiblingKeyNodesToValidate({ ...params, nodeDef, nodeParent, attribute: node, siblingKeyNodesCache })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n result.push(...Records.getAttributeSiblings(node, nodeDef)(record))\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { getCycle, getRoot, getNodes, getNodesArray, getNodeByUuid, getNodesByUuids, getNodesByDefUuid, getChild, getChildren, getParent, getParentCodeAttribute, getAncestorCodePath, getDependentCodeAttributes, getAncestor, getEntityKeyNodes, getEntityKeyNodesByDefUuid, getEntityKeyValues, getEntityKeyValuesByDefUuid, getEntitySiblings, getAttributeSiblings, getNodeIndex, visitAncestorsAndSelf, getAncestorsAndSelf, getDescendant, getDescendantsOrSelf, isDescendantOf, visitDescendantsAndSelf, getDependentNodePointers, findEntityByKeyValues, findEntityWithSameKeysInAnotherRecord, getCategoryItemUuid, isNodeEmpty, isNodeFilledByUser, isEmpty, getStep, isInAnalysisStep } from './_records/recordGetters';
1
+ import { getCycle, getRoot, getNodes, getNodesArray, getNodeByUuid, getNodesByUuids, getNodesByDefUuid, getChild, getChildren, getParent, getParentCodeAttribute, getAncestorCodePath, getDependentCodeAttributes, getAncestor, getEntityKeyNodes, getEntityKeyNodesByDefUuid, getEntityKeyValues, getEntityKeyValuesByDefUuid, getEntitySiblings, getAttributeSiblings, getNodeIndex, isNodeRequired, visitAncestorsAndSelf, getAncestorsAndSelf, getDescendant, getDescendantsOrSelf, isDescendantOf, visitDescendantsAndSelf, getDependentNodePointers, findEntityByKeyValues, findEntityWithSameKeysInAnotherRecord, getCategoryItemUuid, isNodeEmpty, isNodeFilledByUser, isEmpty, getStep, isInAnalysisStep } from './_records/recordGetters';
2
2
  import { addNode, addNodes } from './_records/recordUpdater';
3
3
  import { getEnumeratingCategoryItems, findDependentEnumeratedEntityDefsNotEmpty } from './_records/recordUtils';
4
4
  import { getEntityCompletionPercent, getEntityCompletionStats, getEntityOwnCompletionPercent, getRecordCompletionPercent } from './_records/recordCompletion';
@@ -29,6 +29,7 @@ export declare const Records: {
29
29
  isNodeApplicable: (node: import("..").ArenaRecordNode) => (record: import("./record").ArenaRecord) => boolean;
30
30
  isNodeEditable: (node: import("..").ArenaRecordNode) => (record: import("./record").ArenaRecord) => boolean;
31
31
  isNodeVisible: (node: import("..").ArenaRecordNode) => (record: import("./record").ArenaRecord) => boolean;
32
+ isNodeRequired: typeof isNodeRequired;
32
33
  visitAncestorsAndSelf: typeof visitAncestorsAndSelf;
33
34
  getAncestorsAndSelf: typeof getAncestorsAndSelf;
34
35
  getDescendant: typeof getDescendant;
@@ -33,6 +33,7 @@ exports.Records = {
33
33
  isNodeApplicable: recordGetters_1.isNodeApplicable,
34
34
  isNodeEditable: recordGetters_1.isNodeEditable,
35
35
  isNodeVisible: recordGetters_1.isNodeVisible,
36
+ isNodeRequired: recordGetters_1.isNodeRequired,
36
37
  visitAncestorsAndSelf: recordGetters_1.visitAncestorsAndSelf,
37
38
  getAncestorsAndSelf: recordGetters_1.getAncestorsAndSelf,
38
39
  getDescendant: recordGetters_1.getDescendant,
@@ -1 +1 @@
1
- {"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/record/records.ts"],"names":[],"mappings":";;;AAAA,4DAwCiC;AACjC,4DAA4D;AAC5D,wDAA+G;AAC/G,kEAKoC;AACpC,4EAWyC;AACzC,gFAAiF;AAEpE,QAAA,OAAO,GAAG;IACrB,OAAO;IACP,QAAQ,EAAR,wBAAQ;IACR,OAAO,EAAP,uBAAO;IACP,QAAQ,EAAR,wBAAQ;IACR,aAAa,EAAb,6BAAa;IACb,aAAa,EAAb,6BAAa;IACb,eAAe,EAAf,+BAAe;IACf,iBAAiB,EAAjB,iCAAiB;IACjB,QAAQ,EAAR,wBAAQ;IACR,WAAW,EAAX,2BAAW;IACX,SAAS,EAAT,yBAAS;IACT,sBAAsB,EAAtB,sCAAsB;IACtB,mBAAmB,EAAnB,mCAAmB;IACnB,0BAA0B,EAA1B,0CAA0B;IAC1B,WAAW,EAAX,2BAAW;IACX,iBAAiB,EAAjB,iCAAiB;IACjB,0BAA0B,EAA1B,0CAA0B;IAC1B,kBAAkB,EAAlB,kCAAkB;IAClB,2BAA2B,EAA3B,2CAA2B;IAC3B,iBAAiB,EAAjB,iCAAiB;IACjB,oBAAoB,EAApB,oCAAoB;IACpB,YAAY,EAAZ,4BAAY;IACZ,gBAAgB,EAAhB,gCAAgB;IAChB,cAAc,EAAd,8BAAc;IACd,aA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\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n} from './_records/recordGetters'\nimport { addNode, addNodes } from './_records/recordUpdater'\nimport { getEnumeratingCategoryItems, findDependentEnumeratedEntityDefsNotEmpty } from './_records/recordUtils'\nimport {\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n} from './_records/recordCompletion'\nimport {\n getDescendantPageNodeDefUuids,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getPageValidationStatus,\n getRecordPagesValidationProgress,\n nodeBelongsToOwnPage,\n nodeBelongsToPage,\n pageHasOwnErrors,\n} from './_records/recordPagesValidation'\nimport { removeNode, removeNodes } from './recordNodesUpdater/recordNodesDeleter'\n\nexport const Records = {\n // READ\n getCycle,\n getRoot,\n getNodes,\n getNodesArray,\n getNodeByUuid,\n getNodesByUuids,\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getDescendantPageNodeDefUuids,\n nodeBelongsToPage,\n nodeBelongsToOwnPage,\n getPageValidationStatus,\n pageHasOwnErrors,\n getRecordPagesValidationProgress,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n // UPDATE\n addNode,\n addNodes,\n /** Low-level: removes the node and its descendants without updating dependents and validation (see RecordUpdater.deleteNode) */\n removeNode,\n /** Low-level: removes the nodes and their descendants without updating dependents and validation (see RecordUpdater.deleteNodes) */\n removeNodes,\n /** @deprecated Use removeNode (or RecordUpdater.deleteNode to update dependents and validation too) */\n deleteNode: removeNode,\n /** @deprecated Use removeNodes (or RecordUpdater.deleteNodes to update dependents and validation too) */\n deleteNodes: removeNodes,\n // Utils\n getEnumeratingCategoryItems,\n findDependentEnumeratedEntityDefsNotEmpty,\n}\n\nexport type { RecordUpdateOptions } from './_records/recordUpdateOptions'\nexport type {\n EntitySubtreeStatus,\n PageValidationStatus,\n PagesValidationProgress,\n} from './_records/recordPagesValidation'\n"]}
1
+ {"version":3,"file":"records.js","sourceRoot":"","sources":["../../src/record/records.ts"],"names":[],"mappings":";;;AAAA,4DAyCiC;AACjC,4DAA4D;AAC5D,wDAA+G;AAC/G,kEAKoC;AACpC,4EAWyC;AACzC,gFAAiF;AAEpE,QAAA,OAAO,GAAG;IACrB,OAAO;IACP,QAAQ,EAAR,wBAAQ;IACR,OAAO,EAAP,uBAAO;IACP,QAAQ,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,qDAA6B;IAC7B,iBAAiB,EAAjB,yCAAiB;IACjB,oBAAoB,EAApB,4CAAoB;IACpB,uBAAuB,EAAvB,+CAAuB;IACvB,gBAAgB,EAAhB,wCAAgB;IAChB,gCAAgC,EAAhC,wDAAgC;IAChC,sBAAsB,EAAtB,8CAAsB;IACtB,6BAA6B,EAA7B,qDAA6B;IAC7B,SAAS;IACT,OAAO,EAAP,uBAAO;IACP,QAAQ,EAAR,wBAAQ;IACR,gIAAgI;IAChI,UAAU,EAAV,+BAAU;IACV,oIAAoI;IACpI,WAAW,EAAX,gCAAW;IACX,uGAAuG;IACvG,UAAU,EAAE,+BAAU;IACtB,yGAAyG;IACzG,WAAW,EAAE,gCAAW;IACxB,QAAQ;IACR,2BAA2B,EAA3B,yCAA2B;IAC3B,yCAAyC,EAAzC,uDAAyC;CAC1C,CAAA","sourcesContent":["import {\n getCycle,\n getRoot,\n getNodes,\n getNodesArray,\n getNodeByUuid,\n getNodesByUuids,\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n isNodeRequired,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n} from './_records/recordGetters'\nimport { addNode, addNodes } from './_records/recordUpdater'\nimport { getEnumeratingCategoryItems, findDependentEnumeratedEntityDefsNotEmpty } from './_records/recordUtils'\nimport {\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n} from './_records/recordCompletion'\nimport {\n getDescendantPageNodeDefUuids,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getPageValidationStatus,\n getRecordPagesValidationProgress,\n nodeBelongsToOwnPage,\n nodeBelongsToPage,\n pageHasOwnErrors,\n} from './_records/recordPagesValidation'\nimport { removeNode, removeNodes } from './recordNodesUpdater/recordNodesDeleter'\n\nexport const Records = {\n // READ\n getCycle,\n getRoot,\n getNodes,\n getNodesArray,\n getNodeByUuid,\n getNodesByUuids,\n getNodesByDefUuid,\n getChild,\n getChildren,\n getParent,\n getParentCodeAttribute,\n getAncestorCodePath,\n getDependentCodeAttributes,\n getAncestor,\n getEntityKeyNodes,\n getEntityKeyNodesByDefUuid,\n getEntityKeyValues,\n getEntityKeyValuesByDefUuid,\n getEntitySiblings,\n getAttributeSiblings,\n getNodeIndex,\n isNodeApplicable,\n isNodeEditable,\n isNodeVisible,\n isNodeRequired,\n visitAncestorsAndSelf,\n getAncestorsAndSelf,\n getDescendant,\n getDescendantsOrSelf,\n isDescendantOf,\n visitDescendantsAndSelf,\n getDependentNodePointers,\n findEntityByKeyValues,\n findEntityWithSameKeysInAnotherRecord,\n getCategoryItemUuid,\n isNodeEmpty,\n isNodeFilledByUser,\n isEmpty,\n getStep,\n isInAnalysisStep,\n getEntityCompletionPercent,\n getEntityCompletionStats,\n getEntityOwnCompletionPercent,\n getRecordCompletionPercent,\n getNodeDefChildrenInOwnPage,\n getPageNodeDefs,\n getDescendantPageNodeDefUuids,\n nodeBelongsToPage,\n nodeBelongsToOwnPage,\n getPageValidationStatus,\n pageHasOwnErrors,\n getRecordPagesValidationProgress,\n getEntitySubtreeStatus,\n getMultiplePageEntitiesStatus,\n // UPDATE\n addNode,\n addNodes,\n /** Low-level: removes the node and its descendants without updating dependents and validation (see RecordUpdater.deleteNode) */\n removeNode,\n /** Low-level: removes the nodes and their descendants without updating dependents and validation (see RecordUpdater.deleteNodes) */\n removeNodes,\n /** @deprecated Use removeNode (or RecordUpdater.deleteNode to update dependents and validation too) */\n deleteNode: removeNode,\n /** @deprecated Use removeNodes (or RecordUpdater.deleteNodes to update dependents and validation too) */\n deleteNodes: removeNodes,\n // Utils\n getEnumeratingCategoryItems,\n findDependentEnumeratedEntityDefsNotEmpty,\n}\n\nexport type { RecordUpdateOptions } from './_records/recordUpdateOptions'\nexport type {\n EntitySubtreeStatus,\n PageValidationStatus,\n PagesValidationProgress,\n} from './_records/recordPagesValidation'\n"]}
@@ -20,6 +20,7 @@ export declare enum SurveyDependencyType {
20
20
  maxCount = "maxCount",
21
21
  minCount = "minCount",
22
22
  parentCode = "parentCode",
23
+ required = "required",
23
24
  validations = "validations",
24
25
  visible = "visible",
25
26
  onUpdate = "onUpdate"
@@ -13,6 +13,7 @@ var SurveyDependencyType;
13
13
  SurveyDependencyType["maxCount"] = "maxCount";
14
14
  SurveyDependencyType["minCount"] = "minCount";
15
15
  SurveyDependencyType["parentCode"] = "parentCode";
16
+ SurveyDependencyType["required"] = "required";
16
17
  SurveyDependencyType["validations"] = "validations";
17
18
  SurveyDependencyType["visible"] = "visible";
18
19
  SurveyDependencyType["onUpdate"] = "onUpdate";
@@ -1 +1 @@
1
- {"version":3,"file":"survey.js","sourceRoot":"","sources":["../../src/survey/survey.ts"],"names":[],"mappings":";;;AAUa,QAAA,YAAY,GAAG,GAAG,CAAA;AAM/B,IAAY,oBAaX;AAbD,WAAY,oBAAoB;IAC9B,iDAAyB,CAAA;IACzB,uDAA+B,CAAA;IAC/B,6CAAqB,CAAA;IACrB,6DAAqC,CAAA;IACrC,6CAAqB,CAAA;IACrB,2CAAmB,CAAA;IACnB,6CAAqB,CAAA;IACrB,6CAAqB,CAAA;IACrB,iDAAyB,CAAA;IACzB,mDAA2B,CAAA;IAC3B,2CAAmB,CAAA;IACnB,6CAAqB,CAAA;AACvB,CAAC,EAbW,oBAAoB,aAApB,oBAAoB,GAApB,oBAAoB,QAa/B;AAWD,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,mGAA6E,CAAA;IAC7E,qGAA+E,CAAA;IAC/E,yDAAmC,CAAA;IACnC,mFAA6D,CAAA;IAC7D,mFAA6D,CAAA;IAC7D,uGAAiF,CAAA;IACjF,qFAA+D,CAAA;AACjE,CAAC,EARW,kBAAkB,aAAlB,kBAAkB,GAAlB,kBAAkB,QAQ7B;AAMY,QAAA,sBAAsB,GAAmB;IACpD,CAAC,kBAAkB,CAAC,oCAAoC,CAAC,EAAE,IAAI;IAC/D,CAAC,kBAAkB,CAAC,qCAAqC,CAAC,EAAE,IAAI;IAChE,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,IAAI;IAC1C,CAAC,kBAAkB,CAAC,4BAA4B,CAAC,EAAE,IAAI;IACvD,CAAC,kBAAkB,CAAC,4BAA4B,CAAC,EAAE,IAAI;IACvD,CAAC,kBAAkB,CAAC,sCAAsC,CAAC,EAAE,IAAI;IACjE,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,EAAE,IAAI;CACzD,CAAA;AAED,IAAY,cAGX;AAHD,WAAY,cAAc;IACxB,mCAAiB,CAAA;IACjB,mCAAiB,CAAA;AACnB,CAAC,EAHW,cAAc,aAAd,cAAc,GAAd,cAAc,QAGzB;AAEY,QAAA,sBAAsB,GAAG;IACpC,aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;CACV,CAAA","sourcesContent":["import { ArenaObject, Dictionary } from '../common'\nimport { AuthGroup } from '../auth'\nimport { Labels, LanguageCode } from '../language'\nimport { SRS } from '../srs'\n\nimport { NodeDef, NodeDefType } from '../nodeDef'\nimport { Category } from '../category'\nimport { Taxonomy } from '../taxonomy'\nimport { SurveyRefData } from './refData/refData'\n\nexport const defaultCycle = '0'\n\nexport interface SurveyDependency {\n [nodeDefUuid: string]: string[] | boolean\n}\n\nexport enum SurveyDependencyType {\n applicable = 'applicable',\n defaultValues = 'defaultValues',\n editable = 'editable',\n enumeratingItems = 'enumeratingItems',\n fileName = 'fileName',\n formula = 'formula',\n maxCount = 'maxCount',\n minCount = 'minCount',\n parentCode = 'parentCode',\n validations = 'validations',\n visible = 'visible',\n onUpdate = 'onUpdate', // dependencies updated on every record update, stored as dictionary of booleans\n}\n\nexport type SurveyDependencyGraph = {\n [key in SurveyDependencyType]: SurveyDependency\n}\n\nexport interface SurveyCycle {\n dateEnd?: string\n dateStart: string\n}\n\nexport enum SurveySecurityProp {\n dataEditorViewNotOwnedRecordsAllowed = 'dataEditorViewNotOwnedRecordsAllowed',\n dataAnalystViewNotOwnedRecordsAllowed = 'dataAnalystViewNotOwnedRecordsAllowed',\n visibleInMobile = 'visibleInMobile',\n allowRecordsDownloadInMobile = 'allowRecordsDownloadInMobile',\n allowRecordsUploadFromMobile = 'allowRecordsUploadFromMobile',\n allowRecordsWithErrorsUploadFromMobile = 'allowRecordsWithErrorsUploadFromMobile',\n allowRecordsMergeWithSameKeys = 'allowRecordsMergeWithSameKeys',\n}\n\nexport type SurveySecurity = {\n [key in SurveySecurityProp]?: boolean\n}\n\nexport const surveySecurityDefaults: SurveySecurity = {\n [SurveySecurityProp.dataEditorViewNotOwnedRecordsAllowed]: true,\n [SurveySecurityProp.dataAnalystViewNotOwnedRecordsAllowed]: true,\n [SurveySecurityProp.visibleInMobile]: true,\n [SurveySecurityProp.allowRecordsDownloadInMobile]: true,\n [SurveySecurityProp.allowRecordsUploadFromMobile]: true,\n [SurveySecurityProp.allowRecordsWithErrorsUploadFromMobile]: true,\n [SurveySecurityProp.allowRecordsMergeWithSameKeys]: true,\n}\n\nexport enum SurveyDocPlace {\n header = 'header',\n footer = 'footer',\n}\n\nexport const surveyDocImagePropKeys = {\n documentPlace: 'documentPlace',\n applyIf: 'applyIf',\n} as const\n\nexport type SurveyDocImageProps = SurveyFileProps & {\n documentPlace?: SurveyDocPlace\n applyIf?: string\n}\n\nexport type SurveyFileProps = {\n deleted?: boolean\n labels?: Labels\n name?: string\n nodeUuid?: string\n recordUuid?: string\n size?: number | null\n temporary?: boolean\n type?: string\n}\n\nexport type SurveyFile = {\n uuid: string\n props: SurveyFileProps\n content?: Buffer | null\n dateCreated: string\n}\n\nexport type SurveyDocImage = SurveyFile & {\n props: SurveyDocImageProps\n}\n\nexport type SurveyDocOptions = {\n headerOnFirstPageOnly?: boolean // default: true\n}\n\nexport interface SurveyProps {\n collectUri?: string\n cycles: {\n [key: string]: SurveyCycle\n }\n defaultCycleKey?: string\n descriptions?: Labels\n fieldManualLinks?: Labels\n // when true, values of attributes becoming non-applicable are kept during data entry (default: cleared)\n keepNonApplicableValues?: boolean\n labels?: Labels\n languages: LanguageCode[]\n name: string\n preloadedMapLayers?: SurveyFile[]\n preloadedMapLayersEnabled?: boolean\n security?: SurveySecurity\n srs: SRS[]\n surveyDocImages?: SurveyDocImage[]\n surveyDocOptions?: SurveyDocOptions\n}\n\nexport interface SurveyNodeDefsIndex {\n rootDefUuid?: string\n childDefUuidPresenceByParentUuid?: { [parentUuid: string]: { [nodeDefUuid: string]: boolean } }\n nodeDefUuidByName?: Dictionary<string>\n qualifierPresenceByUuid?: { [nodeDefUuid: string]: boolean }\n}\n\nexport interface Survey extends ArenaObject<SurveyProps> {\n authGroups: Array<AuthGroup>\n dateCreated?: string\n dateModified?: string\n datePublished?: string\n dependencyGraph?: SurveyDependencyGraph\n draft: boolean\n nodeDefs?: { [nodeDefUuid: string]: NodeDef<NodeDefType> }\n ownerUuid: string\n published: boolean\n readonly id?: number\n template: boolean\n uuid: string\n /**\n * Categories indexed by uuid.\n */\n categories?: { [categoryUuid: string]: Category }\n /**\n * Taxonomies indexed by uuid.\n */\n taxonomies?: { [taxonomyUuid: string]: Taxonomy }\n /**\n * Reference data cache (category items and taxa).\n */\n refData?: SurveyRefData\n\n nodeDefsIndex?: SurveyNodeDefsIndex\n}\n"]}
1
+ {"version":3,"file":"survey.js","sourceRoot":"","sources":["../../src/survey/survey.ts"],"names":[],"mappings":";;;AAU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aAAa,EAAE,eAAe;IAC9B,OAAO,EAAE,SAAS;CACV,CAAA","sourcesContent":["import { ArenaObject, Dictionary } from '../common'\nimport { AuthGroup } from '../auth'\nimport { Labels, LanguageCode } from '../language'\nimport { SRS } from '../srs'\n\nimport { NodeDef, NodeDefType } from '../nodeDef'\nimport { Category } from '../category'\nimport { Taxonomy } from '../taxonomy'\nimport { SurveyRefData } from './refData/refData'\n\nexport const defaultCycle = '0'\n\nexport interface SurveyDependency {\n [nodeDefUuid: string]: string[] | boolean\n}\n\nexport enum SurveyDependencyType {\n applicable = 'applicable',\n defaultValues = 'defaultValues',\n editable = 'editable',\n enumeratingItems = 'enumeratingItems',\n fileName = 'fileName',\n formula = 'formula',\n maxCount = 'maxCount',\n minCount = 'minCount',\n parentCode = 'parentCode',\n required = 'required',\n validations = 'validations',\n visible = 'visible',\n onUpdate = 'onUpdate', // dependencies updated on every record update, stored as dictionary of booleans\n}\n\nexport type SurveyDependencyGraph = {\n [key in SurveyDependencyType]: SurveyDependency\n}\n\nexport interface SurveyCycle {\n dateEnd?: string\n dateStart: string\n}\n\nexport enum SurveySecurityProp {\n dataEditorViewNotOwnedRecordsAllowed = 'dataEditorViewNotOwnedRecordsAllowed',\n dataAnalystViewNotOwnedRecordsAllowed = 'dataAnalystViewNotOwnedRecordsAllowed',\n visibleInMobile = 'visibleInMobile',\n allowRecordsDownloadInMobile = 'allowRecordsDownloadInMobile',\n allowRecordsUploadFromMobile = 'allowRecordsUploadFromMobile',\n allowRecordsWithErrorsUploadFromMobile = 'allowRecordsWithErrorsUploadFromMobile',\n allowRecordsMergeWithSameKeys = 'allowRecordsMergeWithSameKeys',\n}\n\nexport type SurveySecurity = {\n [key in SurveySecurityProp]?: boolean\n}\n\nexport const surveySecurityDefaults: SurveySecurity = {\n [SurveySecurityProp.dataEditorViewNotOwnedRecordsAllowed]: true,\n [SurveySecurityProp.dataAnalystViewNotOwnedRecordsAllowed]: true,\n [SurveySecurityProp.visibleInMobile]: true,\n [SurveySecurityProp.allowRecordsDownloadInMobile]: true,\n [SurveySecurityProp.allowRecordsUploadFromMobile]: true,\n [SurveySecurityProp.allowRecordsWithErrorsUploadFromMobile]: true,\n [SurveySecurityProp.allowRecordsMergeWithSameKeys]: true,\n}\n\nexport enum SurveyDocPlace {\n header = 'header',\n footer = 'footer',\n}\n\nexport const surveyDocImagePropKeys = {\n documentPlace: 'documentPlace',\n applyIf: 'applyIf',\n} as const\n\nexport type SurveyDocImageProps = SurveyFileProps & {\n documentPlace?: SurveyDocPlace\n applyIf?: string\n}\n\nexport type SurveyFileProps = {\n deleted?: boolean\n labels?: Labels\n name?: string\n nodeUuid?: string\n recordUuid?: string\n size?: number | null\n temporary?: boolean\n type?: string\n}\n\nexport type SurveyFile = {\n uuid: string\n props: SurveyFileProps\n content?: Buffer | null\n dateCreated: string\n}\n\nexport type SurveyDocImage = SurveyFile & {\n props: SurveyDocImageProps\n}\n\nexport type SurveyDocOptions = {\n headerOnFirstPageOnly?: boolean // default: true\n}\n\nexport interface SurveyProps {\n collectUri?: string\n cycles: {\n [key: string]: SurveyCycle\n }\n defaultCycleKey?: string\n descriptions?: Labels\n fieldManualLinks?: Labels\n // when true, values of attributes becoming non-applicable are kept during data entry (default: cleared)\n keepNonApplicableValues?: boolean\n labels?: Labels\n languages: LanguageCode[]\n name: string\n preloadedMapLayers?: SurveyFile[]\n preloadedMapLayersEnabled?: boolean\n security?: SurveySecurity\n srs: SRS[]\n surveyDocImages?: SurveyDocImage[]\n surveyDocOptions?: SurveyDocOptions\n}\n\nexport interface SurveyNodeDefsIndex {\n rootDefUuid?: string\n childDefUuidPresenceByParentUuid?: { [parentUuid: string]: { [nodeDefUuid: string]: boolean } }\n nodeDefUuidByName?: Dictionary<string>\n qualifierPresenceByUuid?: { [nodeDefUuid: string]: boolean }\n}\n\nexport interface Survey extends ArenaObject<SurveyProps> {\n authGroups: Array<AuthGroup>\n dateCreated?: string\n dateModified?: string\n datePublished?: string\n dependencyGraph?: SurveyDependencyGraph\n draft: boolean\n nodeDefs?: { [nodeDefUuid: string]: NodeDef<NodeDefType> }\n ownerUuid: string\n published: boolean\n readonly id?: number\n template: boolean\n uuid: string\n /**\n * Categories indexed by uuid.\n */\n categories?: { [categoryUuid: string]: Category }\n /**\n * Taxonomies indexed by uuid.\n */\n taxonomies?: { [taxonomyUuid: string]: Taxonomy }\n /**\n * Reference data cache (category items and taxa).\n */\n refData?: SurveyRefData\n\n nodeDefsIndex?: SurveyNodeDefsIndex\n}\n"]}
@@ -61,6 +61,7 @@ const isContextParentByDependencyType = {
61
61
  [survey_1.SurveyDependencyType.minCount]: true,
62
62
  [survey_1.SurveyDependencyType.onUpdate]: true,
63
63
  [survey_1.SurveyDependencyType.parentCode]: false,
64
+ [survey_1.SurveyDependencyType.required]: true,
64
65
  [survey_1.SurveyDependencyType.validations]: true,
65
66
  [survey_1.SurveyDependencyType.visible]: true,
66
67
  };
@@ -75,6 +76,7 @@ const selfReferenceAllowedByDependencyType = {
75
76
  [survey_1.SurveyDependencyType.minCount]: false,
76
77
  [survey_1.SurveyDependencyType.onUpdate]: false,
77
78
  [survey_1.SurveyDependencyType.parentCode]: false,
79
+ [survey_1.SurveyDependencyType.required]: false,
78
80
  [survey_1.SurveyDependencyType.validations]: true,
79
81
  [survey_1.SurveyDependencyType.visible]: false,
80
82
  };
@@ -89,6 +91,7 @@ const newDependencyGraph = () => ({
89
91
  [survey_1.SurveyDependencyType.minCount]: {},
90
92
  [survey_1.SurveyDependencyType.onUpdate]: {},
91
93
  [survey_1.SurveyDependencyType.parentCode]: {},
94
+ [survey_1.SurveyDependencyType.required]: {},
92
95
  [survey_1.SurveyDependencyType.validations]: {},
93
96
  [survey_1.SurveyDependencyType.visible]: {},
94
97
  });
@@ -196,6 +199,7 @@ const addNodeDefDependencies = (params) => __awaiter(void 0, void 0, void 0, fun
196
199
  graphsUpdated = yield _addDependencies(survey_1.SurveyDependencyType.applicable, nodeDef_1.NodeDefs.getApplicable(nodeDef));
197
200
  graphsUpdated = yield _addDependencies(survey_1.SurveyDependencyType.defaultValues, nodeDef_1.NodeDefs.getDefaultValues(nodeDef));
198
201
  graphsUpdated = yield _addDependencies(survey_1.SurveyDependencyType.editable, nodeDef_1.NodeDefs.getEditableIf(nodeDef));
202
+ graphsUpdated = yield _addDependencies(survey_1.SurveyDependencyType.required, nodeDef_1.NodeDefs.getRequiredIf(nodeDef));
199
203
  graphsUpdated = yield _addDependencies(survey_1.SurveyDependencyType.validations, nodeDef_1.NodeDefs.getValidationsExpressions(nodeDef));
200
204
  graphsUpdated = yield _addDependencies(survey_1.SurveyDependencyType.visible, nodeDef_1.NodeDefs.getVisibleIf(nodeDef));
201
205
  const maxCount = nodeDef_1.NodeDefs.getMaxCount(nodeDef);