@openforis/arena-core 3.2.2 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/appInfo.d.ts +5 -1
- package/dist/app/appInfo.js.map +1 -1
- package/dist/app/appInfos.d.ts +19 -0
- package/dist/app/appInfos.js +27 -0
- package/dist/app/appInfos.js.map +1 -0
- package/dist/app/index.d.ts +2 -1
- package/dist/app/index.js +3 -0
- package/dist/app/index.js.map +1 -1
- package/dist/esm/app/appInfo.js.map +1 -1
- package/dist/esm/app/appInfos.js +24 -0
- package/dist/esm/app/appInfos.js.map +1 -0
- package/dist/esm/app/index.js +1 -1
- package/dist/esm/app/index.js.map +1 -1
- package/dist/esm/expression/context.js.map +1 -1
- package/dist/esm/expression/javascript/evaluator.js +3 -16
- package/dist/esm/expression/javascript/evaluator.js.map +1 -1
- package/dist/esm/expression/javascript/parser/expressionNodesFinder.js +68 -0
- package/dist/esm/expression/javascript/parser/expressionNodesFinder.js.map +1 -0
- package/dist/esm/geo/points/transform.js +3 -10
- package/dist/esm/geo/points/transform.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node/index.js.map +1 -1
- package/dist/esm/node/nodes.js +14 -12
- package/dist/esm/node/nodes.js.map +1 -1
- package/dist/esm/nodeDefExpressionEvaluator/context.js.map +1 -1
- package/dist/esm/nodeDefExpressionEvaluator/evaluator.js +19 -1
- package/dist/esm/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
- package/dist/esm/nodeDefExpressionEvaluator/functions.js +53 -0
- package/dist/esm/nodeDefExpressionEvaluator/functions.js.map +1 -1
- package/dist/esm/record/_records/recordGetters.js +18 -0
- package/dist/esm/record/_records/recordGetters.js.map +1 -1
- package/dist/esm/record/record.js.map +1 -1
- package/dist/esm/record/recordExpressionEvaluator/functions.js +14 -0
- package/dist/esm/record/recordExpressionEvaluator/functions.js.map +1 -1
- package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js +9 -1
- package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordExpressionEvaluationContext.js +1 -0
- package/dist/esm/record/recordNodesUpdater/recordExpressionEvaluationContext.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +5 -3
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +6 -4
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +2 -2
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +11 -3
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +46 -21
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +14 -6
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +5 -5
- package/dist/esm/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +22 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js +111 -8
- package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordUpdateResult.js +10 -0
- package/dist/esm/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
- package/dist/esm/record/recordUpdater.js +62 -9
- package/dist/esm/record/recordUpdater.js.map +1 -1
- package/dist/esm/record/records.js +3 -1
- package/dist/esm/record/records.js.map +1 -1
- package/dist/esm/survey/survey.js +2 -0
- package/dist/esm/survey/survey.js.map +1 -1
- package/dist/esm/survey/surveys/dependencies.js +67 -32
- package/dist/esm/survey/surveys/dependencies.js.map +1 -1
- package/dist/esm/survey/surveys/index.js +2 -1
- package/dist/esm/survey/surveys/index.js.map +1 -1
- package/dist/esm/utils/_objects/isEqual.js +2 -0
- package/dist/esm/utils/_objects/isEqual.js.map +1 -1
- package/dist/esm/utils/lruCache.js +50 -0
- package/dist/esm/utils/lruCache.js.map +1 -0
- package/dist/expression/context.d.ts +5 -0
- package/dist/expression/context.js.map +1 -1
- package/dist/expression/javascript/evaluator.js +3 -16
- package/dist/expression/javascript/evaluator.js.map +1 -1
- package/dist/expression/javascript/parser/expressionNodesFinder.d.ts +13 -0
- package/dist/expression/javascript/parser/expressionNodesFinder.js +73 -0
- package/dist/expression/javascript/parser/expressionNodesFinder.js.map +1 -0
- package/dist/geo/points/transform.js +3 -10
- package/dist/geo/points/transform.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js.map +1 -1
- package/dist/node/nodes.d.ts +18 -5
- package/dist/node/nodes.js +14 -12
- package/dist/node/nodes.js.map +1 -1
- package/dist/nodeDefExpressionEvaluator/context.d.ts +4 -0
- package/dist/nodeDefExpressionEvaluator/context.js.map +1 -1
- package/dist/nodeDefExpressionEvaluator/evaluator.d.ts +9 -1
- package/dist/nodeDefExpressionEvaluator/evaluator.js +19 -1
- package/dist/nodeDefExpressionEvaluator/evaluator.js.map +1 -1
- package/dist/nodeDefExpressionEvaluator/functions.js +53 -0
- package/dist/nodeDefExpressionEvaluator/functions.js.map +1 -1
- package/dist/record/_records/recordGetters.d.ts +10 -0
- package/dist/record/_records/recordGetters.js +21 -1
- package/dist/record/_records/recordGetters.js.map +1 -1
- package/dist/record/record.d.ts +1 -1
- package/dist/record/record.js.map +1 -1
- package/dist/record/recordExpressionEvaluator/functions.js +14 -0
- package/dist/record/recordExpressionEvaluator/functions.js.map +1 -1
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.d.ts +8 -0
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js +9 -1
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.d.ts +6 -0
- package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.js +1 -0
- package/dist/record/recordNodesUpdater/recordExpressionEvaluationContext.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js +5 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsApplicableUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.d.ts +2 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js +5 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsBooleanUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js +2 -2
- package/dist/record/recordNodesUpdater/recordNodeDependentsCodeAttributesUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js +11 -3
- package/dist/record/recordNodesUpdater/recordNodeDependentsCountUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js +45 -20
- package/dist/record/recordNodesUpdater/recordNodeDependentsDefaultValuesUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js +14 -6
- package/dist/record/recordNodesUpdater/recordNodeDependentsFileNamesEvaluator.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js +4 -4
- package/dist/record/recordNodesUpdater/recordNodeDependentsRequiredUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.d.ts +19 -0
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js +24 -1
- package/dist/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodesUpdater.d.ts +8 -1
- package/dist/record/recordNodesUpdater/recordNodesUpdater.js +107 -4
- package/dist/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordUpdateResult.d.ts +5 -0
- package/dist/record/recordNodesUpdater/recordUpdateResult.js +10 -0
- package/dist/record/recordNodesUpdater/recordUpdateResult.js.map +1 -1
- package/dist/record/recordUpdater.d.ts +10 -2
- package/dist/record/recordUpdater.js +61 -8
- package/dist/record/recordUpdater.js.map +1 -1
- package/dist/record/records.d.ts +3 -1
- package/dist/record/records.js +2 -0
- package/dist/record/records.js.map +1 -1
- package/dist/survey/survey.d.ts +3 -1
- package/dist/survey/survey.js +2 -0
- package/dist/survey/survey.js.map +1 -1
- package/dist/survey/surveys/dependencies.d.ts +10 -0
- package/dist/survey/surveys/dependencies.js +69 -33
- package/dist/survey/surveys/dependencies.js.map +1 -1
- package/dist/survey/surveys/index.d.ts +2 -1
- package/dist/survey/surveys/index.js +1 -0
- package/dist/survey/surveys/index.js.map +1 -1
- package/dist/utils/_objects/isEqual.d.ts +3 -1
- package/dist/utils/_objects/isEqual.js +2 -0
- package/dist/utils/_objects/isEqual.js.map +1 -1
- package/dist/utils/lruCache.d.ts +18 -0
- package/dist/utils/lruCache.js +54 -0
- package/dist/utils/lruCache.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDependentNodePointersByType = exports.throwError = void 0;
|
|
3
|
+
exports.getDependentNodePointersByType = exports.throwError = exports.isAppInfoMissing = exports.getNodeCurrent = void 0;
|
|
4
4
|
const error_1 = require("../../error");
|
|
5
5
|
const nodeDef_1 = require("../../nodeDef");
|
|
6
6
|
const survey_1 = require("../../survey");
|
|
7
7
|
const records_1 = require("../records");
|
|
8
|
+
/**
|
|
9
|
+
* Returns the node referenced by "this" when evaluating the expressions of a node def in the context of its parent entity:
|
|
10
|
+
* the node of the node def, if single; null if the node def is multiple (the node is not determined) or the node doesn't exist.
|
|
11
|
+
*/
|
|
12
|
+
const getNodeCurrent = (params) => {
|
|
13
|
+
var _a;
|
|
14
|
+
const { record, nodeCtx, nodeDef } = params;
|
|
15
|
+
if (nodeDef_1.NodeDefs.isMultiple(nodeDef))
|
|
16
|
+
return null;
|
|
17
|
+
return (_a = records_1.Records.getChildren(nodeCtx, nodeDef.uuid)(record)[0]) !== null && _a !== void 0 ? _a : null;
|
|
18
|
+
};
|
|
19
|
+
exports.getNodeCurrent = getNodeCurrent;
|
|
20
|
+
/**
|
|
21
|
+
* Returns true if the expressions of the node def use the app info functions (appId, appIdLabel, appPlatform, appVersion)
|
|
22
|
+
* but the app info is not available (e.g. update done by a server job): they must not be evaluated
|
|
23
|
+
* (they would return null), the current values are kept.
|
|
24
|
+
*/
|
|
25
|
+
const isAppInfoMissing = (params) => {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const { survey, appInfo, nodeDef } = params;
|
|
28
|
+
return !appInfo && !!((_b = (_a = survey.dependencyGraph) === null || _a === void 0 ? void 0 : _a[survey_1.SurveyDependencyType.appInfo]) === null || _b === void 0 ? void 0 : _b[nodeDef.uuid]);
|
|
29
|
+
};
|
|
30
|
+
exports.isAppInfoMissing = isAppInfoMissing;
|
|
8
31
|
const throwError = (params) => {
|
|
9
32
|
const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params;
|
|
10
33
|
const nodeDefName = nodeDef.props.name;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAEzC,2CAAiF;AACjF,yCAAyE;AAEzE,wCAAoC;
|
|
1
|
+
{"version":3,"file":"recordNodesDependentsUpdaterCommons.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordNodesDependentsUpdaterCommons.ts"],"names":[],"mappings":";;;AAAA,uCAAyC;AAEzC,2CAAiF;AACjF,yCAAyE;AAEzE,wCAAoC;AAEpC;;;GAGG;AACI,MAAM,cAAc,GAAG,CAAC,MAI9B,EAA0B,EAAE;;IAC3B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC3C,IAAI,kBAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAA;IAC7C,aAAO,iBAAO,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAA;AACtE,CAAC,CAAA;AARY,QAAA,cAAc,GAAd,cAAc,CAQ1B;AAED;;;;GAIG;AACI,MAAM,gBAAgB,GAAG,CAAC,MAIhC,EAAW,EAAE;;IACZ,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAC3C,OAAO,CAAC,OAAO,IAAI,CAAC,EAAC,MAAA,MAAA,MAAM,CAAC,eAAe,0CAAG,6BAAoB,CAAC,OAAO,CAAC,0CAAG,OAAO,CAAC,IAAI,CAAC,CAAA,CAAA;AAC7F,CAAC,CAAA;AAPY,QAAA,gBAAgB,GAAhB,gBAAgB,CAO5B;AAEM,MAAM,UAAU,GAAG,CAAC,MAO1B,EAAE,EAAE;IACH,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,cA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CAAA;IAElH,IAAI,CAAC,kBAAQ,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACvD,OAAO,YAAY,CAAA;IACrB,CAAC;IAED,0EAA0E;IAC1E,IAAI,oBAAoB,EAAE,CAAC;QACzB,uBAAuB,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC1F,CAAC;IAED,uGAAuG;IACvG,IAAI,6BAA6B,EAAE,CAAC;QAClC,iCAAiC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;IAC5F,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAzCY,QAAA,8BAA8B,GAA9B,8BAA8B,CAyC1C","sourcesContent":["import { SystemError } from '../../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer } from '../../node'\nimport { ArenaAnyNodeDef, ArenaNodeDefExpression, NodeDefs } from '../../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../../survey'\nimport { ArenaRecord } from '../record'\nimport { Records } from '../records'\n\n/**\n * Returns the node referenced by \"this\" when evaluating the expressions of a node def in the context of its parent entity:\n * the node of the node def, if single; null if the node def is multiple (the node is not determined) or the node doesn't exist.\n */\nexport const getNodeCurrent = (params: {\n record: ArenaRecord\n nodeCtx: ArenaRecordNode\n nodeDef: ArenaAnyNodeDef\n}): ArenaRecordNode | null => {\n const { record, nodeCtx, nodeDef } = params\n if (NodeDefs.isMultiple(nodeDef)) return null\n return Records.getChildren(nodeCtx, nodeDef.uuid)(record)[0] ?? null\n}\n\n/**\n * Returns true if the expressions of the node def use the app info functions (appId, appIdLabel, appPlatform, appVersion)\n * but the app info is not available (e.g. update done by a server job): they must not be evaluated\n * (they would return null), the current values are kept.\n */\nexport const isAppInfoMissing = (params: {\n survey: ArenaSurvey\n appInfo?: unknown\n nodeDef: ArenaAnyNodeDef\n}): boolean => {\n const { survey, appInfo, nodeDef } = params\n return !appInfo && !!survey.dependencyGraph?.[SurveyDependencyType.appInfo]?.[nodeDef.uuid]\n}\n\nexport const throwError = (params: {\n error: any\n errorKey: string\n expressionType: SurveyDependencyType\n survey: ArenaSurvey\n nodeDef: ArenaAnyNodeDef\n expressionsToEvaluate: ArenaNodeDefExpression[]\n}) => {\n const { error, errorKey, expressionType, survey, nodeDef, expressionsToEvaluate } = params\n const nodeDefName = nodeDef.props.name\n const expressionsString = JSON.stringify(expressionsToEvaluate)\n\n throw new SystemError(\n errorKey,\n {\n surveyName: survey.props.name,\n nodeDefName,\n expressionType,\n expressionsString,\n error: error.toString(),\n errorJson: error instanceof SystemError ? error.toJSON() : null,\n },\n { cause: error }\n )\n}\n\nconst addPointerIfAccepted = (params: {\n nodePointers: ArenaRecordNodePointer[]\n pointer: ArenaRecordNodePointer\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, pointer, filterFn } = params\n if (!filterFn || filterFn(pointer)) {\n nodePointers.push(pointer)\n }\n}\n\nconst addNewEntitySelfPointer = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, record, node, sourceNodeDef, filterFn } = params\n if (!node.parentUuid) {\n return\n }\n const parentNode = Records.getNodeByUuid(node.parentUuid)(record)\n if (!parentNode) {\n return\n }\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: parentNode, nodeDef: sourceNodeDef },\n filterFn,\n })\n}\n\nconst addNewEntityChildMultiplePointers = (params: {\n nodePointers: ArenaRecordNodePointer[]\n survey: ArenaSurvey\n node: ArenaRecordNode\n sourceNodeDef: ArenaAnyNodeDef\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}) => {\n const { nodePointers, survey, node, sourceNodeDef, filterFn } = params\n const multipleNodeDefs = Surveys.getNodeDefChildren({ survey, nodeDef: sourceNodeDef }).filter(NodeDefs.isMultiple)\n\n for (const childDef of multipleNodeDefs) {\n addPointerIfAccepted({\n nodePointers,\n pointer: { nodeCtx: node, nodeDef: childDef },\n filterFn,\n })\n }\n}\n\nexport const getDependentNodePointersByType = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n node: ArenaRecordNode\n dependencyType: SurveyDependencyType\n includeSelfWhenSourceIsAttribute?: boolean\n includeNewEntitySelf?: boolean\n includeNewEntityChildPointers?: boolean\n filterFn?: (nodePointer: ArenaRecordNodePointer) => boolean\n}): ArenaRecordNodePointer[] => {\n const {\n survey,\n record,\n node,\n dependencyType,\n includeSelfWhenSourceIsAttribute = false,\n includeNewEntitySelf = false,\n includeNewEntityChildPointers = false,\n filterFn,\n } = params\n\n const sourceNodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const includeSelf = includeSelfWhenSourceIsAttribute && !NodeDefs.isEntity(sourceNodeDef)\n\n const nodePointers = Records.getDependentNodePointers(survey, node, dependencyType, includeSelf, filterFn)(record)\n\n if (!NodeDefs.isEntity(sourceNodeDef) || !node.created) {\n return nodePointers\n }\n\n // For newly created entities, include a self-pointer for the source node.\n if (includeNewEntitySelf) {\n addNewEntitySelfPointer({ nodePointers, survey, record, node, sourceNodeDef, filterFn })\n }\n\n // For new entities, include child multiple nodes so their dependency metadata/status gets updated too.\n if (includeNewEntityChildPointers) {\n addNewEntityChildMultiplePointers({ nodePointers, survey, node, sourceNodeDef, filterFn })\n }\n\n return nodePointers\n}\n"]}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { ArenaDictionary } from '../../common';
|
|
2
|
-
import { ArenaRecordNode } from '../../node';
|
|
2
|
+
import { ArenaRecordNode, ArenaRecordNodesMap } from '../../node';
|
|
3
3
|
import { ArenaRecordNodesUpdateParams } from './recordNodesCreator';
|
|
4
4
|
import { RecordUpdateResult } from './recordUpdateResult';
|
|
5
|
+
/**
|
|
6
|
+
* Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).
|
|
7
|
+
* The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).
|
|
8
|
+
* @param params.nodes - Nodes created, updated or deleted.
|
|
9
|
+
* @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).
|
|
10
|
+
*/
|
|
5
11
|
export declare const updateNodesDependents: (params: ArenaRecordNodesUpdateParams & {
|
|
6
12
|
nodes: ArenaDictionary<ArenaRecordNode>;
|
|
13
|
+
nodesToEvaluate?: ArenaRecordNodesMap;
|
|
7
14
|
}) => Promise<RecordUpdateResult>;
|
|
@@ -11,9 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.updateNodesDependents = void 0;
|
|
13
13
|
const utils_1 = require("../../utils");
|
|
14
|
+
const node_1 = require("../../node");
|
|
14
15
|
const nodeDef_1 = require("../../nodeDef");
|
|
15
16
|
const survey_1 = require("../../survey");
|
|
16
17
|
const recordGetters_1 = require("../_records/recordGetters");
|
|
18
|
+
const nodePointers_1 = require("../nodePointers");
|
|
17
19
|
const recordNodeDependentsApplicableUpdater_1 = require("./recordNodeDependentsApplicableUpdater");
|
|
18
20
|
const recordNodeDependentsCodeAttributesUpdater_1 = require("./recordNodeDependentsCodeAttributesUpdater");
|
|
19
21
|
const recordNodeDependentsCountUpdater_1 = require("./recordNodeDependentsCountUpdater");
|
|
@@ -47,11 +49,81 @@ const dependentsUpdaters = [
|
|
|
47
49
|
recordNodeDependentsEnumeratingItemsUpdater_1.updateDependentEnumeratingItemsEntities,
|
|
48
50
|
recordNodeDependentsFileNamesEvaluator_1.updateSelfAndDependentsFileNames,
|
|
49
51
|
];
|
|
52
|
+
/**
|
|
53
|
+
* True if the node modification changes the date modified of its ancestors:
|
|
54
|
+
* nodes created or deleted, and attributes (whose value changed); entities updated only in their meta
|
|
55
|
+
* (e.g. children applicability) are excluded.
|
|
56
|
+
*/
|
|
57
|
+
const isModificationPropagatedToAncestors = (survey, node) => {
|
|
58
|
+
if (node.created || node.deleted)
|
|
59
|
+
return true;
|
|
60
|
+
const nodeDef = survey_1.Surveys.findNodeDefByUuid({ survey, uuid: node.nodeDefUuid });
|
|
61
|
+
return !!nodeDef && !nodeDef_1.NodeDefs.isEntity(nodeDef);
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Sets the date modified of the ancestors of the specified node (if not set already).
|
|
65
|
+
* @returns The ancestors updated.
|
|
66
|
+
*/
|
|
67
|
+
const updateAncestorsDateModified = (params) => {
|
|
68
|
+
var _a;
|
|
69
|
+
const { node, updateResult, dateModified, sideEffect } = params;
|
|
70
|
+
const ancestorsUpdated = [];
|
|
71
|
+
for (const ancestorUuid of node_1.RecordNodes.getHierarchy(node)) {
|
|
72
|
+
const ancestor = (_a = updateResult.getNodeByUuid(ancestorUuid)) !== null && _a !== void 0 ? _a : (0, recordGetters_1.getNodeByUuid)(ancestorUuid)(updateResult.record);
|
|
73
|
+
if (!ancestor || ancestor.deleted || ancestor.dateModified === dateModified)
|
|
74
|
+
continue;
|
|
75
|
+
const ancestorAlreadyUpdated = !!updateResult.getNodeByUuid(ancestorUuid);
|
|
76
|
+
const ancestorUpdated = sideEffect ? ancestor : Object.assign({}, ancestor);
|
|
77
|
+
ancestorUpdated.dateModified = dateModified;
|
|
78
|
+
ancestorUpdated.updated = true;
|
|
79
|
+
updateResult.addNode(ancestorUpdated, { sideEffect });
|
|
80
|
+
if (!ancestorAlreadyUpdated) {
|
|
81
|
+
updateResult.dateModifiedOnlyNodeUuids.add(ancestorUuid);
|
|
82
|
+
}
|
|
83
|
+
ancestorsUpdated.push(ancestorUpdated);
|
|
84
|
+
}
|
|
85
|
+
return ancestorsUpdated;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Returns the nodes whose expressions use the dates of the specified entity (nodeDateCreated, nodeDateModified),
|
|
89
|
+
* e.g. the attributes in the entity with the expression "nodeDateModified(parent(this))".
|
|
90
|
+
*/
|
|
91
|
+
const getNodeDatesDependentNodes = (params) => {
|
|
92
|
+
const { survey, record, entity } = params;
|
|
93
|
+
const dependentDefs = survey_1.Surveys.getNodeDefDependents({
|
|
94
|
+
survey,
|
|
95
|
+
nodeDefUuid: entity.nodeDefUuid,
|
|
96
|
+
dependencyType: survey_1.SurveyDependencyType.nodeDates,
|
|
97
|
+
});
|
|
98
|
+
if (dependentDefs.length === 0)
|
|
99
|
+
return [];
|
|
100
|
+
const result = [];
|
|
101
|
+
for (const dependentDef of dependentDefs) {
|
|
102
|
+
if (dependentDef.meta.h.includes(entity.nodeDefUuid)) {
|
|
103
|
+
// dependent def is a descendant of the entity def: only the dependent nodes in the entity are affected
|
|
104
|
+
result.push(...(0, recordGetters_1.getDescendantsOrSelf)(entity, dependentDef)(record));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const nodePointers = (0, recordGetters_1.getDependentNodePointers)(survey, entity, survey_1.SurveyDependencyType.nodeDates, false, (nodePointer) => nodePointer.nodeDef.uuid === dependentDef.uuid)(record);
|
|
108
|
+
result.push(...nodePointers_1.RecordNodePointers.getNodesFromNodePointers({ record, nodePointers }));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).
|
|
115
|
+
* The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).
|
|
116
|
+
* @param params.nodes - Nodes created, updated or deleted.
|
|
117
|
+
* @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).
|
|
118
|
+
*/
|
|
50
119
|
const updateNodesDependents = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
120
|
var _a;
|
|
52
|
-
|
|
121
|
+
var _b, _c, _d;
|
|
122
|
+
const { survey, record, nodes, nodesToEvaluate, sideEffect = false } = params;
|
|
123
|
+
// the same date modified is used for all the nodes modified (it lets the propagation to the ancestors end)
|
|
124
|
+
const dateModified = (_b = params.dateModified) !== null && _b !== void 0 ? _b : utils_1.Dates.nowFormattedForStorage();
|
|
53
125
|
// always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited
|
|
54
|
-
const initialNodesToVisit = Object.assign({}, nodes);
|
|
126
|
+
const initialNodesToVisit = Object.assign(Object.assign({}, nodesToEvaluate), nodes);
|
|
55
127
|
// include onUpdate dependents (always included in every record update)
|
|
56
128
|
const onUpdateDependentDefs = survey_1.Surveys.getOnUpdateDependents({ survey });
|
|
57
129
|
if (onUpdateDependentDefs.length > 0) {
|
|
@@ -63,14 +135,44 @@ const updateNodesDependents = (params) => __awaiter(void 0, void 0, void 0, func
|
|
|
63
135
|
}
|
|
64
136
|
}
|
|
65
137
|
const updateResult = new recordUpdateResult_1.RecordUpdateResult({ record, nodes: initialNodesToVisit });
|
|
66
|
-
const createNodeUpdateParams = (node) => (Object.assign(Object.assign({}, params), { record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)
|
|
138
|
+
const createNodeUpdateParams = (node) => (Object.assign(Object.assign({}, params), { dateModified, record: updateResult.record, // updateResult.record changes at every step (when sideEffect=false)
|
|
67
139
|
node }));
|
|
68
140
|
const nodeUuidsToVisit = new utils_1.Queue(Object.keys(initialNodesToVisit));
|
|
141
|
+
const hasNodeDatesDependencies = Object.keys((_c = (_a = survey.dependencyGraph) === null || _a === void 0 ? void 0 : _a[survey_1.SurveyDependencyType.nodeDates]) !== null && _c !== void 0 ? _c : {}).length > 0;
|
|
142
|
+
// the dependents of the entities whose date modified changed (e.g. "nodeDateModified(parent(this))") are visited
|
|
143
|
+
// as sources ("self" evaluation): the entities themselves are not visited, they are not modified in their content
|
|
144
|
+
const visitNodeDatesDependents = (entities) => {
|
|
145
|
+
var _a;
|
|
146
|
+
var _b, _c;
|
|
147
|
+
if (!hasNodeDatesDependencies)
|
|
148
|
+
return;
|
|
149
|
+
for (const entity of entities) {
|
|
150
|
+
for (const dependentNode of getNodeDatesDependentNodes({ survey, record: updateResult.record, entity })) {
|
|
151
|
+
// included in the result (like the onUpdate dependents) so their validation is updated too
|
|
152
|
+
(_a = (_b = updateResult.nodes)[_c = dependentNode.uuid]) !== null && _a !== void 0 ? _a : (_b[_c] = dependentNode);
|
|
153
|
+
nodeUuidsToVisit.enqueue(dependentNode.uuid);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const updateAncestorsOfModifiedNodes = (modifiedNodes) => {
|
|
158
|
+
const entitiesUpdated = [];
|
|
159
|
+
for (const modifiedNode of modifiedNodes) {
|
|
160
|
+
if (isModificationPropagatedToAncestors(survey, modifiedNode)) {
|
|
161
|
+
entitiesUpdated.push(...updateAncestorsDateModified({ node: modifiedNode, updateResult, dateModified, sideEffect }));
|
|
162
|
+
}
|
|
163
|
+
else if (!modifiedNode.deleted) {
|
|
164
|
+
// entity updated in its meta (e.g. children applicability): its date modified changed
|
|
165
|
+
entitiesUpdated.push(modifiedNode);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
visitNodeDatesDependents(entitiesUpdated);
|
|
169
|
+
};
|
|
170
|
+
updateAncestorsOfModifiedNodes(Object.values(nodes));
|
|
69
171
|
// Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)
|
|
70
172
|
const visitedCountByUuid = {};
|
|
71
173
|
while (!nodeUuidsToVisit.isEmpty()) {
|
|
72
174
|
const nodeUuid = nodeUuidsToVisit.dequeue();
|
|
73
|
-
const visitedCount = (
|
|
175
|
+
const visitedCount = (_d = visitedCountByUuid[nodeUuid]) !== null && _d !== void 0 ? _d : 0;
|
|
74
176
|
if (visitedCount < MAX_DEPENDENTS_VISITING_TIMES) {
|
|
75
177
|
const nodesUpdatedCurrent = {};
|
|
76
178
|
for (const dependentsUpdater of dependentsUpdaters) {
|
|
@@ -82,6 +184,7 @@ const updateNodesDependents = (params) => __awaiter(void 0, void 0, void 0, func
|
|
|
82
184
|
}
|
|
83
185
|
// Mark updated nodes to visit
|
|
84
186
|
nodeUuidsToVisit.enqueueItems(Object.keys(nodesUpdatedCurrent));
|
|
187
|
+
updateAncestorsOfModifiedNodes(Object.values(nodesUpdatedCurrent));
|
|
85
188
|
// Mark node as visited
|
|
86
189
|
visitedCountByUuid[nodeUuid] = visitedCount + 1;
|
|
87
190
|
}
|
|
@@ -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,+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,kCAAM,MAAM,KAAE,SAAS,EAAE,0BAAgB,CAAC,GAAG,IAAG;IACjF,yEAAiC;IACjC,+EAAoC;IACpC,qEAA+B;IAC/B,qEAA+B;IAC/B,mEAA8B;IAC9B,yEAA6B;IAC7B,iFAAiC;IACjC,qFAAuC;IACvC,yEAAgC;CACjC,CAAA;AAEM,MAAM,qBAAqB,GAAG,CACnC,MAAkF,EACrD,EAAE;;IAC/B,MAAM,EAAE,MAAM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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;AAvDY,QAAA,qBAAqB,GAArB,qBAAqB,CAuDjC","sourcesContent":["import { Queue } from '../../utils'\n\nimport { ArenaDictionary } 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 { ArenaRecordNodesUpdateParams } 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: ArenaRecordNodesUpdateParams & { nodes: ArenaDictionary<ArenaRecordNode> }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes } = params\n // always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited\n const initialNodesToVisit = { ...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: ArenaDictionary<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: ArenaDictionary<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,uCAA0C;AAG1C,qCAA8E;AAC9E,2CAA0D;AAC1D,yCAAyE;AACzE,6DAKkC;AAClC,kDAAoD;AAEpD,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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CAAC,CAAC,CAAA;YAC/D,8BAA8B,CAAC,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAA;YAElE,uBAAuB;YACvB,kBAAkB,CAAC,QAAQ,CAAC,GAAG,YAAY,GAAG,CAAC,CAAA;QACjD,CAAC;IACH,CAAC;IAED,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA,CAAA;AA9FY,QAAA,qBAAqB,GAArB,qBAAqB,CA8FjC","sourcesContent":["import { Dates, Queue } from '../../utils'\n\nimport { ArenaDictionary } from '../../common'\nimport { ArenaRecordNode, ArenaRecordNodesMap, RecordNodes } from '../../node'\nimport { NodeDefCountType, NodeDefs } from '../../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../../survey'\nimport {\n getDependentNodePointers,\n getDescendantsOrSelf,\n getNodeByUuid,\n getNodesByDefUuid,\n} from '../_records/recordGetters'\nimport { RecordNodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\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 { ArenaRecordNodesUpdateParams } 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\n/**\n * True if the node modification changes the date modified of its ancestors:\n * nodes created or deleted, and attributes (whose value changed); entities updated only in their meta\n * (e.g. children applicability) are excluded.\n */\nconst isModificationPropagatedToAncestors = (survey: ArenaSurvey, node: ArenaRecordNode): boolean => {\n if (node.created || node.deleted) return true\n const nodeDef = Surveys.findNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n return !!nodeDef && !NodeDefs.isEntity(nodeDef)\n}\n\n/**\n * Sets the date modified of the ancestors of the specified node (if not set already).\n * @returns The ancestors updated.\n */\nconst updateAncestorsDateModified = (params: {\n node: ArenaRecordNode\n updateResult: RecordUpdateResult\n dateModified: string\n sideEffect: boolean\n}): ArenaRecordNode[] => {\n const { node, updateResult, dateModified, sideEffect } = params\n const ancestorsUpdated: ArenaRecordNode[] = []\n for (const ancestorUuid of RecordNodes.getHierarchy(node)) {\n const ancestor = updateResult.getNodeByUuid(ancestorUuid) ?? getNodeByUuid(ancestorUuid)(updateResult.record)\n if (!ancestor || ancestor.deleted || ancestor.dateModified === dateModified) continue\n\n const ancestorAlreadyUpdated = !!updateResult.getNodeByUuid(ancestorUuid)\n const ancestorUpdated = sideEffect ? ancestor : { ...ancestor }\n ancestorUpdated.dateModified = dateModified\n ancestorUpdated.updated = true\n updateResult.addNode(ancestorUpdated, { sideEffect })\n if (!ancestorAlreadyUpdated) {\n updateResult.dateModifiedOnlyNodeUuids.add(ancestorUuid)\n }\n ancestorsUpdated.push(ancestorUpdated)\n }\n return ancestorsUpdated\n}\n\n/**\n * Returns the nodes whose expressions use the dates of the specified entity (nodeDateCreated, nodeDateModified),\n * e.g. the attributes in the entity with the expression \"nodeDateModified(parent(this))\".\n */\nconst getNodeDatesDependentNodes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n entity: ArenaRecordNode\n}): ArenaRecordNode[] => {\n const { survey, record, entity } = params\n const dependentDefs = Surveys.getNodeDefDependents({\n survey,\n nodeDefUuid: entity.nodeDefUuid,\n dependencyType: SurveyDependencyType.nodeDates,\n })\n if (dependentDefs.length === 0) return []\n\n const result: ArenaRecordNode[] = []\n for (const dependentDef of dependentDefs) {\n if (dependentDef.meta.h.includes(entity.nodeDefUuid)) {\n // dependent def is a descendant of the entity def: only the dependent nodes in the entity are affected\n result.push(...getDescendantsOrSelf(entity, dependentDef)(record))\n } else {\n const nodePointers = getDependentNodePointers(\n survey,\n entity,\n SurveyDependencyType.nodeDates,\n false,\n (nodePointer) => nodePointer.nodeDef.uuid === dependentDef.uuid\n )(record)\n result.push(...RecordNodePointers.getNodesFromNodePointers({ record, nodePointers }))\n }\n }\n return result\n}\n\n/**\n * Updates the dependents of the specified nodes (applicability, default values, calculations, etc.).\n * The date modified of the ancestors of the modified nodes is updated too (see isModificationPropagatedToAncestors).\n * @param params.nodes - Nodes created, updated or deleted.\n * @param params.nodesToEvaluate - Nodes not modified whose dependents must be updated (e.g. the app info dependents).\n */\nexport const updateNodesDependents = async (\n params: ArenaRecordNodesUpdateParams & {\n nodes: ArenaDictionary<ArenaRecordNode>\n nodesToEvaluate?: ArenaRecordNodesMap\n }\n): Promise<RecordUpdateResult> => {\n const { survey, record, nodes, nodesToEvaluate, sideEffect = false } = params\n // the same date modified is used for all the nodes modified (it lets the propagation to the ancestors end)\n const dateModified = params.dateModified ?? Dates.nowFormattedForStorage()\n // always copy: the nodes passed (e.g. the deleted nodes) must not collect the dependent nodes visited\n const initialNodesToVisit = { ...nodesToEvaluate, ...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 dateModified,\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 const hasNodeDatesDependencies =\n Object.keys(survey.dependencyGraph?.[SurveyDependencyType.nodeDates] ?? {}).length > 0\n\n // the dependents of the entities whose date modified changed (e.g. \"nodeDateModified(parent(this))\") are visited\n // as sources (\"self\" evaluation): the entities themselves are not visited, they are not modified in their content\n const visitNodeDatesDependents = (entities: ArenaRecordNode[]): void => {\n if (!hasNodeDatesDependencies) return\n for (const entity of entities) {\n for (const dependentNode of getNodeDatesDependentNodes({ survey, record: updateResult.record, entity })) {\n // included in the result (like the onUpdate dependents) so their validation is updated too\n updateResult.nodes[dependentNode.uuid] ??= dependentNode\n nodeUuidsToVisit.enqueue(dependentNode.uuid)\n }\n }\n }\n\n const updateAncestorsOfModifiedNodes = (modifiedNodes: ArenaRecordNode[]): void => {\n const entitiesUpdated: ArenaRecordNode[] = []\n for (const modifiedNode of modifiedNodes) {\n if (isModificationPropagatedToAncestors(survey, modifiedNode)) {\n entitiesUpdated.push(\n ...updateAncestorsDateModified({ node: modifiedNode, updateResult, dateModified, sideEffect })\n )\n } else if (!modifiedNode.deleted) {\n // entity updated in its meta (e.g. children applicability): its date modified changed\n entitiesUpdated.push(modifiedNode)\n }\n }\n visitNodeDatesDependents(entitiesUpdated)\n }\n updateAncestorsOfModifiedNodes(Object.values(nodes))\n\n // Avoid loops: visit the same node maximum 2 times (the second time the applicability could have been changed)\n const visitedCountByUuid: ArenaDictionary<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: ArenaDictionary<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 updateAncestorsOfModifiedNodes(Object.values(nodesUpdatedCurrent))\n\n // Mark node as visited\n visitedCountByUuid[nodeUuid] = visitedCount + 1\n }\n }\n\n return updateResult\n}\n"]}
|
|
@@ -7,6 +7,11 @@ export declare class RecordUpdateResult {
|
|
|
7
7
|
nodes: ArenaRecordNodesMap;
|
|
8
8
|
nodesDeleted: ArenaRecordNodesMap;
|
|
9
9
|
clearedDefUuids: Set<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Uuids of the nodes (ancestor entities) updated only in their date modified (because a descendant has been modified):
|
|
12
|
+
* to be persisted, but not to be validated again.
|
|
13
|
+
*/
|
|
14
|
+
dateModifiedOnlyNodeUuids: Set<string>;
|
|
10
15
|
validation?: ArenaValidation;
|
|
11
16
|
constructor(params: {
|
|
12
17
|
record: ArenaRecord;
|
|
@@ -9,6 +9,7 @@ class RecordUpdateResult {
|
|
|
9
9
|
this.nodes = (_a = params.nodes) !== null && _a !== void 0 ? _a : {};
|
|
10
10
|
this.nodesDeleted = (_b = params.nodesDeleted) !== null && _b !== void 0 ? _b : {};
|
|
11
11
|
this.clearedDefUuids = (_c = params.clearedDefUuids) !== null && _c !== void 0 ? _c : new Set();
|
|
12
|
+
this.dateModifiedOnlyNodeUuids = new Set();
|
|
12
13
|
this.validation = params.validation;
|
|
13
14
|
}
|
|
14
15
|
getNodeByUuid(uuid) {
|
|
@@ -40,6 +41,15 @@ class RecordUpdateResult {
|
|
|
40
41
|
for (const nodeDefUuid of recordUpdateResult.clearedDefUuids) {
|
|
41
42
|
this.addClearedDefUuid(nodeDefUuid);
|
|
42
43
|
}
|
|
44
|
+
for (const nodeUuid of Object.keys(recordUpdateResult.nodes)) {
|
|
45
|
+
// node updated in the merged result: not only in its date modified anymore
|
|
46
|
+
if (!recordUpdateResult.dateModifiedOnlyNodeUuids.has(nodeUuid)) {
|
|
47
|
+
this.dateModifiedOnlyNodeUuids.delete(nodeUuid);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const nodeUuid of recordUpdateResult.dateModifiedOnlyNodeUuids) {
|
|
51
|
+
this.dateModifiedOnlyNodeUuids.add(nodeUuid);
|
|
52
|
+
}
|
|
43
53
|
return this;
|
|
44
54
|
}
|
|
45
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordUpdateResult.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordUpdateResult.ts"],"names":[],"mappings":";;;AAGA,6DAA6D;AAG7D;
|
|
1
|
+
{"version":3,"file":"recordUpdateResult.js","sourceRoot":"","sources":["../../../src/record/recordNodesUpdater/recordUpdateResult.ts"],"names":[],"mappings":";;;AAGA,6DAA6D;AAG7D;IAYE,YAAY,MAMX;;QACC,IA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D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAA;QACjE,KAAK,MAAM,WAAW,IAAI,kBAAkB,CAAC,eAAe,EAAE,CAAC;YAC7D,IAAI,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAA;QACrC,CAAC;QACD,KAAK,MAAM,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7D,2EAA2E;YAC3E,IAAI,CAAC,kBAAkB,CAAC,yBAAyB,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAChE,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QACD,KAAK,MAAM,QAAQ,IAAI,kBAAkB,CAAC,yBAAyB,EAAE,CAAC;YACpE,IAAI,CAAC,yBAAyB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC9C,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import { ArenaRecordNode, ArenaRecordNodesMap } from '../../node'\nimport { ArenaValidation } from '../../validation'\nimport { ArenaRecord } from '../record'\nimport { addNode, addNodes } from '../_records/recordUpdater'\nimport { ArenaRecordUpdateOptions } from '../records'\n\nexport class RecordUpdateResult {\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n nodesDeleted: ArenaRecordNodesMap\n clearedDefUuids: Set<string>\n /**\n * Uuids of the nodes (ancestor entities) updated only in their date modified (because a descendant has been modified):\n * to be persisted, but not to be validated again.\n */\n dateModifiedOnlyNodeUuids: Set<string>\n validation?: ArenaValidation\n\n constructor(params: {\n record: ArenaRecord\n nodes?: ArenaRecordNodesMap\n nodesDeleted?: ArenaRecordNodesMap\n clearedDefUuids?: Set<string>\n validation?: ArenaValidation\n }) {\n this.record = params.record\n this.nodes = params.nodes ?? {}\n this.nodesDeleted = params.nodesDeleted ?? {}\n this.clearedDefUuids = params.clearedDefUuids ?? new Set<string>()\n this.dateModifiedOnlyNodeUuids = new Set<string>()\n this.validation = params.validation\n }\n\n getNodeByUuid(uuid: string) {\n return this.nodes[uuid]\n }\n\n addNode(node: ArenaRecordNode, options?: ArenaRecordUpdateOptions) {\n this.nodes[node.uuid] = node\n this.record = addNode(node, options)(this.record)\n }\n\n addNodes(nodes: ArenaRecordNodesMap, options?: ArenaRecordUpdateOptions) {\n Object.assign(this.nodes, nodes)\n this.record = addNodes(nodes, options)(this.record)\n }\n\n addClearedDefUuid(nodeDefUuid: string) {\n this.clearedDefUuids.add(nodeDefUuid)\n }\n\n /**\n * Merges this record update result with the specified one.\n * The record of this record update result will be the one of the specified record update result\n * and the nodes of the specified one will be added to the nodes of this one.\n *\n * @param {!RecordUpdateResult} recordUpdateResult - The record update result to merge with.\n * @returns {RecordUpdateResult} - The updated object.\n */\n merge(recordUpdateResult: RecordUpdateResult): this {\n this.record = recordUpdateResult.record\n Object.assign(this.nodes, recordUpdateResult.nodes)\n Object.assign(this.nodesDeleted, recordUpdateResult.nodesDeleted)\n for (const nodeDefUuid of recordUpdateResult.clearedDefUuids) {\n this.addClearedDefUuid(nodeDefUuid)\n }\n for (const nodeUuid of Object.keys(recordUpdateResult.nodes)) {\n // node updated in the merged result: not only in its date modified anymore\n if (!recordUpdateResult.dateModifiedOnlyNodeUuids.has(nodeUuid)) {\n this.dateModifiedOnlyNodeUuids.delete(nodeUuid)\n }\n }\n for (const nodeUuid of recordUpdateResult.dateModifiedOnlyNodeUuids) {\n this.dateModifiedOnlyNodeUuids.add(nodeUuid)\n }\n return this\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RecordUpdateResult } from './recordNodesUpdater';
|
|
2
2
|
import { ArenaRecordNodeCreateParams, ArenaRecordNodesUpdateParams } from './recordNodesUpdater/recordNodesCreator';
|
|
3
|
-
declare const createDescendants: (
|
|
4
|
-
declare const createNodeAndDescendants: (
|
|
3
|
+
declare const createDescendants: (paramsIn: ArenaRecordNodeCreateParams) => Promise<RecordUpdateResult>;
|
|
4
|
+
declare const createNodeAndDescendants: (paramsIn: ArenaRecordNodeCreateParams) => Promise<RecordUpdateResult>;
|
|
5
5
|
declare const createRootEntity: (params: ArenaRecordNodesUpdateParams & {
|
|
6
6
|
createMultipleEntities?: boolean;
|
|
7
7
|
}) => Promise<RecordUpdateResult>;
|
|
@@ -15,6 +15,13 @@ declare const deleteNodes: (params: ArenaRecordNodesUpdateParams & {
|
|
|
15
15
|
declare const deleteNode: (params: ArenaRecordNodesUpdateParams & {
|
|
16
16
|
nodeUuid: string;
|
|
17
17
|
}) => Promise<RecordUpdateResult>;
|
|
18
|
+
/**
|
|
19
|
+
* Evaluates again the expressions using the app info functions (appId, appIdLabel, appPlatform, appVersion)
|
|
20
|
+
* if the record is being edited with an app different from the one that updated it last
|
|
21
|
+
* (different app id, platform or version, see Records.isAppInfoChanged); does nothing otherwise.
|
|
22
|
+
* To be called when the record is opened for editing (the same check is done in every record update).
|
|
23
|
+
*/
|
|
24
|
+
declare const updateAppInfoDependents: (params: ArenaRecordNodesUpdateParams) => Promise<RecordUpdateResult>;
|
|
18
25
|
export declare const RecordUpdater: {
|
|
19
26
|
/** Creates the descendants of a node and updates dependents (applicability, default values, calculations...) and validation */
|
|
20
27
|
createDescendants: typeof createDescendants;
|
|
@@ -26,5 +33,6 @@ export declare const RecordUpdater: {
|
|
|
26
33
|
deleteNode: typeof deleteNode;
|
|
27
34
|
/** Deletes the nodes and their descendants and updates dependents (applicability, default values, calculations...) and validation */
|
|
28
35
|
deleteNodes: typeof deleteNodes;
|
|
36
|
+
updateAppInfoDependents: typeof updateAppInfoDependents;
|
|
29
37
|
};
|
|
30
38
|
export {};
|
|
@@ -43,10 +43,42 @@ const getDependentValidationNodePointers = (params) => {
|
|
|
43
43
|
}
|
|
44
44
|
return Array.from(uniquePointersByKey.values());
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
/**
|
|
47
|
+
* If the record is being updated with an app different from the one that updated it last (see Records.isAppInfoChanged),
|
|
48
|
+
* stores the app info in the record (info.modifiedWith) and returns the nodes whose expressions use the app info functions,
|
|
49
|
+
* so they will be evaluated again.
|
|
50
|
+
*/
|
|
51
|
+
const _updateAppInfo = (params) => {
|
|
52
|
+
const { survey, record, appInfo, sideEffect = false } = params;
|
|
53
|
+
if (!appInfo || !records_1.Records.isAppInfoChanged(appInfo)(record)) {
|
|
54
|
+
return { record, appInfoDependentNodes: {} };
|
|
55
|
+
}
|
|
56
|
+
const recordUpdated = sideEffect ? record : Object.assign({}, record);
|
|
57
|
+
recordUpdated.info = Object.assign(Object.assign({}, recordUpdated.info), { modifiedWith: appInfo });
|
|
58
|
+
const appInfoDependentNodes = {};
|
|
59
|
+
for (const nodeDef of survey_1.Surveys.getAppInfoDependents({ survey })) {
|
|
60
|
+
for (const node of records_1.Records.getNodesByDefUuid(nodeDef.uuid)(recordUpdated)) {
|
|
61
|
+
appInfoDependentNodes[node.uuid] = node;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return { record: recordUpdated, appInfoDependentNodes };
|
|
65
|
+
};
|
|
66
|
+
const _onRecordNodesCreateOrUpdate = (paramsIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
+
var _a;
|
|
68
|
+
const { record: recordWithAppInfo, appInfoDependentNodes } = _updateAppInfo(paramsIn);
|
|
69
|
+
const params = Object.assign(Object.assign({}, paramsIn), {
|
|
70
|
+
// the same date modified is used for all the nodes modified in this update
|
|
71
|
+
dateModified: (_a = paramsIn.dateModified) !== null && _a !== void 0 ? _a : utils_1.Dates.nowFormattedForStorage(), record: recordWithAppInfo });
|
|
72
|
+
const { user, survey, categoryItemProvider, taxonProvider, areaOfInterestProvider, additionalNodesToValidate, dateModified, } = params;
|
|
73
|
+
const updateResult = yield recordNodesUpdater_1.RecordNodesUpdater.updateNodesDependents(Object.assign(Object.assign({}, params), { nodesToEvaluate: appInfoDependentNodes }));
|
|
74
|
+
const { record: updatedRecord, dateModifiedOnlyNodeUuids } = updateResult;
|
|
75
|
+
// nodes updated only in their date modified (ancestors of the modified nodes) are not validated again
|
|
76
|
+
const updatedNodes = {};
|
|
77
|
+
for (const [nodeUuid, node] of Object.entries(updateResult.nodes)) {
|
|
78
|
+
if (!dateModifiedOnlyNodeUuids.has(nodeUuid)) {
|
|
79
|
+
updatedNodes[nodeUuid] = node;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
50
82
|
const dependentValidationNodePointers = getDependentValidationNodePointers({
|
|
51
83
|
survey,
|
|
52
84
|
record: updatedRecord,
|
|
@@ -72,11 +104,18 @@ const _onRecordNodesCreateOrUpdate = (params) => __awaiter(void 0, void 0, void
|
|
|
72
104
|
updateResult.validation = validation;
|
|
73
105
|
return updateResult;
|
|
74
106
|
});
|
|
75
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Returns the params with the date modified set (now, if not specified): the same date modified is used
|
|
109
|
+
* for all the nodes modified in a record update.
|
|
110
|
+
*/
|
|
111
|
+
const withDateModified = (params) => params.dateModified ? params : Object.assign(Object.assign({}, params), { dateModified: utils_1.Dates.nowFormattedForStorage() });
|
|
112
|
+
const createDescendants = (paramsIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
const params = withDateModified(paramsIn);
|
|
76
114
|
const { record: updatedRecord, nodes: createdNodes } = yield recordNodesUpdater_1.RecordNodesUpdater.addDescendants(params);
|
|
77
115
|
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
|
|
78
116
|
});
|
|
79
|
-
const createNodeAndDescendants = (
|
|
117
|
+
const createNodeAndDescendants = (paramsIn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
const params = withDateModified(paramsIn);
|
|
80
119
|
const { record: updatedRecord, nodes: createdNodes } = yield recordNodesUpdater_1.RecordNodesUpdater.addNodeAndDescendants(params);
|
|
81
120
|
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: updatedRecord, nodes: createdNodes }));
|
|
82
121
|
});
|
|
@@ -96,7 +135,7 @@ const updateAttributeValue = (params) => __awaiter(void 0, void 0, void 0, funct
|
|
|
96
135
|
attributeUpdated = utils_1.Objects.dissocPath({ obj: attributeUpdated, path: ['meta', 'defaultValueApplied'], sideEffect });
|
|
97
136
|
const nodesUpdated = { [attributeUuid]: attributeUpdated };
|
|
98
137
|
const _record = records_1.Records.addNode(attributeUpdated, { sideEffect })(record);
|
|
99
|
-
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record: _record, nodes: nodesUpdated }));
|
|
138
|
+
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { dateModified, record: _record, nodes: nodesUpdated }));
|
|
100
139
|
});
|
|
101
140
|
/**
|
|
102
141
|
* Returns the key and unique attributes of the siblings of the specified entities:
|
|
@@ -140,7 +179,7 @@ const deleteNodes = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
140
179
|
const siblingKeyOrUniqueAttributes = getSiblingKeyOrUniqueAttributes({ survey, record: _record, nodeUuids });
|
|
141
180
|
const updateResult = records_1.Records.removeNodes(nodeUuids, { sideEffect })(_record);
|
|
142
181
|
const { record, nodesDeleted } = updateResult;
|
|
143
|
-
const result = yield _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, params), { record, nodes: nodesDeleted, additionalNodesToValidate: siblingKeyOrUniqueAttributes }));
|
|
182
|
+
const result = yield _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, withDateModified(params)), { record, nodes: nodesDeleted, additionalNodesToValidate: siblingKeyOrUniqueAttributes }));
|
|
144
183
|
result.nodesDeleted = nodesDeleted;
|
|
145
184
|
return result;
|
|
146
185
|
});
|
|
@@ -148,6 +187,19 @@ const deleteNode = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
148
187
|
const { nodeUuid } = params;
|
|
149
188
|
return deleteNodes(Object.assign(Object.assign({}, params), { nodeUuids: [nodeUuid] }));
|
|
150
189
|
});
|
|
190
|
+
/**
|
|
191
|
+
* Evaluates again the expressions using the app info functions (appId, appIdLabel, appPlatform, appVersion)
|
|
192
|
+
* if the record is being edited with an app different from the one that updated it last
|
|
193
|
+
* (different app id, platform or version, see Records.isAppInfoChanged); does nothing otherwise.
|
|
194
|
+
* To be called when the record is opened for editing (the same check is done in every record update).
|
|
195
|
+
*/
|
|
196
|
+
const updateAppInfoDependents = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
197
|
+
const { record, appInfo } = params;
|
|
198
|
+
if (!records_1.Records.isAppInfoChanged(appInfo)(record)) {
|
|
199
|
+
return new recordNodesUpdater_1.RecordUpdateResult({ record });
|
|
200
|
+
}
|
|
201
|
+
return _onRecordNodesCreateOrUpdate(Object.assign(Object.assign({}, withDateModified(params)), { nodes: {} }));
|
|
202
|
+
});
|
|
151
203
|
exports.RecordUpdater = {
|
|
152
204
|
/** Creates the descendants of a node and updates dependents (applicability, default values, calculations...) and validation */
|
|
153
205
|
createDescendants,
|
|
@@ -159,5 +211,6 @@ exports.RecordUpdater = {
|
|
|
159
211
|
deleteNode,
|
|
160
212
|
/** Deletes the nodes and their descendants and updates dependents (applicability, default values, calculations...) and validation */
|
|
161
213
|
deleteNodes,
|
|
214
|
+
updateAppInfoDependents,
|
|
162
215
|
};
|
|
163
216
|
//# sourceMappingURL=recordUpdater.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordUpdater.js","sourceRoot":"","sources":["../../src/record/recordUpdater.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oCAAuD;AAEvD,wCAAmD;AACnD,sCAAsE;AACtE,oCAAyC;AACzC,2DAAuD;AACvD,iDAAmD;AAEnD,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,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;AAED,MAAM,WAAW,GAAG,CAClB,MAEC,EAC4B,EAAE;IAC/B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,KAAK,EAAE,GAAG,MAAM,CAAA;IAEzE,4GAA4G;IAC5G,MAAM,4BAA4B,GAAG,+BAA+B,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAA;IAE5G,MAAM,YAAY,GAAG,iBAAO,CAAC,WAAW,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC,OAAO,CAAC,CAAA;IAC5E,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAAA;IAE7C,MAAM,MAAM,GAAG,MAAM,4BAA4B,iCAC5C,MAAM,KACT,MAAM,EACN,KAAK,EAAE,YAAY,EACnB,yBAAyB,EAAE,4BAA4B,IACvD,CAAA;IACF,MAAM,CAAC,YAAY,GAAG,YAAY,CAAA;IAClC,OAAO,MAAM,CAAA;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAA2D,EAA+B,EAAE;IACpH,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 { ArenaDictionary } from '../common'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, ArenaRecordNodesMap } from '../node'\nimport { ArenaNodeDef, NodeDefs } from '../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { RecordNodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { ArenaRecordNodeCreateParams, ArenaRecordNodesUpdateParams } 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: ArenaSurvey\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n}): ArenaRecordNodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, ArenaRecordNodePointer>()\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: ArenaRecordNodesUpdateParams & {\n nodes: ArenaDictionary<ArenaRecordNode>\n additionalNodesToValidate?: ArenaRecordNodesMap\n }\n): Promise<RecordUpdateResult> => {\n const {\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n additionalNodesToValidate,\n dateModified = Dates.nowFormattedForStorage(),\n } = 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 = RecordNodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes, ...additionalNodesToValidate }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\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: ArenaRecordNodeCreateParams): 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: ArenaRecordNodeCreateParams): 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: ArenaRecordNodesUpdateParams & {\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: ArenaRecordNodesUpdateParams & {\n attributeUuid: string\n // its shape depends on the attribute type (see ArenaRecordNodeValue)\n value: unknown\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\n/**\n * Returns the key and unique attributes of the siblings of the specified entities:\n * they could have been duplicates of the ones being deleted, so they must be validated again.\n */\nconst getEntityKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n entity: ArenaRecordNode\n uniqueAttributeDefs: ArenaNodeDef<any>[]\n}): ArenaRecordNode[] => {\n const { survey, record, entity, uniqueAttributeDefs } = params\n return [\n ...Records.getEntityKeyNodes(survey, entity)(record),\n ...uniqueAttributeDefs.flatMap((uniqueDef) => Records.getChildren(entity, uniqueDef.uuid)(record)),\n ].filter(Boolean)\n}\n\nconst getSiblingKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n nodeUuids: string[]\n}): ArenaRecordNodesMap => {\n const { survey, record, nodeUuids } = params\n const nodeUuidsSet = new Set(nodeUuids)\n const result: ArenaRecordNodesMap = {}\n for (const nodeUuid of nodeUuids) {\n const node = Records.getNodeByUuid(nodeUuid)(record)\n const parentNode = node ? Records.getParent(node)(record) : undefined\n const nodeDef = node ? Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) : undefined\n if (!parentNode || !nodeDef || !NodeDefs.isEntity(nodeDef)) continue\n\n const uniqueAttributeDefs = Surveys.getNodeDefChildren({ survey, nodeDef }).filter(\n (childDef) => NodeDefs.getValidations(childDef)?.unique\n )\n const siblings = Records.getChildren(parentNode, nodeDef.uuid)(record).filter((s) => !nodeUuidsSet.has(s.uuid))\n for (const sibling of siblings) {\n for (const attribute of getEntityKeyOrUniqueAttributes({\n survey,\n record,\n entity: sibling,\n uniqueAttributeDefs,\n })) {\n result[attribute.uuid] = attribute\n }\n }\n }\n return result\n}\n\nconst deleteNodes = async (\n params: ArenaRecordNodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { survey, nodeUuids, record: _record, sideEffect = false } = params\n\n // found before removing the nodes: the deleted nodes are no longer reachable from their siblings afterwards\n const siblingKeyOrUniqueAttributes = getSiblingKeyOrUniqueAttributes({ survey, record: _record, nodeUuids })\n\n const updateResult = Records.removeNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({\n ...params,\n record,\n nodes: nodesDeleted,\n additionalNodesToValidate: siblingKeyOrUniqueAttributes,\n })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: ArenaRecordNodesUpdateParams & { 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,oCAAuD;AAEvD,wCAAmD;AACnD,sCAAsE;AACtE,oCAAyC;AACzC,2DAAuD;AACvD,iDAAmD;AAEnD,6DAA6E;AAE7E,uCAAmC;AACnC,uDAAmD;AAEnD,MAAM,yBAAyB,GAAG;IAChC,6BAAoB,CAAC,WAAW;IAChC,6BAAoB,CAAC,QAAQ;IAC7B,6BAA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A;AACf,CAAC,CAAA,CAAA;AAED,MAAM,UAAU,GAAG,CAAO,MAA2D,EAA+B,EAAE;IACpH,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IAC3B,OAAO,WAAW,iCAAM,MAAM,KAAE,SAAS,EAAE,CAAC,QAAQ,CAAC,IAAG,CAAA;AAC1D,CAAC,CAAA,CAAA;AAED;;;;;GAKG;AACH,MAAM,uBAAuB,GAAG,CAAO,MAAoC,EAA+B,EAAE;IAC1G,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;IAClC,IAAI,CAAC,iBAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/C,OAAO,IAAI,uCAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAA;IAC3C,CAAC;IACD,OAAO,4BAA4B,iCAAM,gBAAgB,CAAC,MAAM,CAAC,KAAE,KAAK,EAAE,EAAE,IAAG,CAAA;AACjF,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;IACX,uBAAuB;CACxB,CAAA","sourcesContent":["import { ArenaDictionary } from '../common'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaRecordNode, ArenaRecordNodePointer, ArenaRecordNodesMap } from '../node'\nimport { ArenaNodeDef, NodeDefs } from '../nodeDef'\nimport { ArenaSurvey, SurveyDependencyType, Surveys } from '../survey'\nimport { Dates, Objects } from '../utils'\nimport { Validations } from '../validation/validations'\nimport { RecordNodePointers } from './nodePointers'\nimport { ArenaRecord } from './record'\nimport { RecordNodesUpdater, RecordUpdateResult } from './recordNodesUpdater'\nimport { ArenaRecordNodeCreateParams, ArenaRecordNodesUpdateParams } 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: ArenaSurvey\n record: ArenaRecord\n nodes: ArenaRecordNodesMap\n}): ArenaRecordNodePointer[] => {\n const { survey, record, nodes } = params\n const uniquePointersByKey = new Map<string, ArenaRecordNodePointer>()\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\n/**\n * If the record is being updated with an app different from the one that updated it last (see Records.isAppInfoChanged),\n * stores the app info in the record (info.modifiedWith) and returns the nodes whose expressions use the app info functions,\n * so they will be evaluated again.\n */\nconst _updateAppInfo = (\n params: ArenaRecordNodesUpdateParams\n): { record: ArenaRecord; appInfoDependentNodes: ArenaRecordNodesMap } => {\n const { survey, record, appInfo, sideEffect = false } = params\n if (!appInfo || !Records.isAppInfoChanged(appInfo)(record)) {\n return { record, appInfoDependentNodes: {} }\n }\n const recordUpdated = sideEffect ? record : { ...record }\n recordUpdated.info = { ...recordUpdated.info, modifiedWith: appInfo }\n\n const appInfoDependentNodes: ArenaRecordNodesMap = {}\n for (const nodeDef of Surveys.getAppInfoDependents({ survey })) {\n for (const node of Records.getNodesByDefUuid(nodeDef.uuid)(recordUpdated)) {\n appInfoDependentNodes[node.uuid] = node\n }\n }\n return { record: recordUpdated, appInfoDependentNodes }\n}\n\nconst _onRecordNodesCreateOrUpdate = async (\n paramsIn: ArenaRecordNodesUpdateParams & {\n nodes: ArenaDictionary<ArenaRecordNode>\n additionalNodesToValidate?: ArenaRecordNodesMap\n }\n): Promise<RecordUpdateResult> => {\n const { record: recordWithAppInfo, appInfoDependentNodes } = _updateAppInfo(paramsIn)\n const params = {\n ...paramsIn,\n // the same date modified is used for all the nodes modified in this update\n dateModified: paramsIn.dateModified ?? Dates.nowFormattedForStorage(),\n record: recordWithAppInfo,\n }\n\n const {\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n additionalNodesToValidate,\n dateModified,\n } = params\n\n const updateResult = await RecordNodesUpdater.updateNodesDependents({\n ...params,\n nodesToEvaluate: appInfoDependentNodes,\n })\n const { record: updatedRecord, dateModifiedOnlyNodeUuids } = updateResult\n // nodes updated only in their date modified (ancestors of the modified nodes) are not validated again\n const updatedNodes: ArenaRecordNodesMap = {}\n for (const [nodeUuid, node] of Object.entries(updateResult.nodes)) {\n if (!dateModifiedOnlyNodeUuids.has(nodeUuid)) {\n updatedNodes[nodeUuid] = node\n }\n }\n\n const dependentValidationNodePointers = getDependentValidationNodePointers({\n survey,\n record: updatedRecord,\n nodes: updatedNodes,\n })\n\n const dependentValidationNodes = RecordNodePointers.getNodesMapFromNodePointers({\n record: updatedRecord,\n nodePointers: dependentValidationNodePointers,\n })\n\n const nodesToValidate = { ...updatedNodes, ...dependentValidationNodes, ...additionalNodesToValidate }\n\n const validationUpdatedNodes = await RecordValidator.validateNodes({\n user,\n survey,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\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\n/**\n * Returns the params with the date modified set (now, if not specified): the same date modified is used\n * for all the nodes modified in a record update.\n */\nconst withDateModified = <P extends { dateModified?: string }>(params: P): P =>\n params.dateModified ? params : { ...params, dateModified: Dates.nowFormattedForStorage() }\n\nconst createDescendants = async (paramsIn: ArenaRecordNodeCreateParams): Promise<RecordUpdateResult> => {\n const params = withDateModified(paramsIn)\n const { record: updatedRecord, nodes: createdNodes } = await RecordNodesUpdater.addDescendants(params)\n\n return _onRecordNodesCreateOrUpdate({ ...params, record: updatedRecord, nodes: createdNodes })\n}\n\nconst createNodeAndDescendants = async (paramsIn: ArenaRecordNodeCreateParams): Promise<RecordUpdateResult> => {\n const params = withDateModified(paramsIn)\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: ArenaRecordNodesUpdateParams & {\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: ArenaRecordNodesUpdateParams & {\n attributeUuid: string\n // its shape depends on the attribute type (see ArenaRecordNodeValue)\n value: unknown\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, dateModified, record: _record, nodes: nodesUpdated })\n}\n\n/**\n * Returns the key and unique attributes of the siblings of the specified entities:\n * they could have been duplicates of the ones being deleted, so they must be validated again.\n */\nconst getEntityKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n entity: ArenaRecordNode\n uniqueAttributeDefs: ArenaNodeDef<any>[]\n}): ArenaRecordNode[] => {\n const { survey, record, entity, uniqueAttributeDefs } = params\n return [\n ...Records.getEntityKeyNodes(survey, entity)(record),\n ...uniqueAttributeDefs.flatMap((uniqueDef) => Records.getChildren(entity, uniqueDef.uuid)(record)),\n ].filter(Boolean)\n}\n\nconst getSiblingKeyOrUniqueAttributes = (params: {\n survey: ArenaSurvey\n record: ArenaRecord\n nodeUuids: string[]\n}): ArenaRecordNodesMap => {\n const { survey, record, nodeUuids } = params\n const nodeUuidsSet = new Set(nodeUuids)\n const result: ArenaRecordNodesMap = {}\n for (const nodeUuid of nodeUuids) {\n const node = Records.getNodeByUuid(nodeUuid)(record)\n const parentNode = node ? Records.getParent(node)(record) : undefined\n const nodeDef = node ? Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid }) : undefined\n if (!parentNode || !nodeDef || !NodeDefs.isEntity(nodeDef)) continue\n\n const uniqueAttributeDefs = Surveys.getNodeDefChildren({ survey, nodeDef }).filter(\n (childDef) => NodeDefs.getValidations(childDef)?.unique\n )\n const siblings = Records.getChildren(parentNode, nodeDef.uuid)(record).filter((s) => !nodeUuidsSet.has(s.uuid))\n for (const sibling of siblings) {\n for (const attribute of getEntityKeyOrUniqueAttributes({\n survey,\n record,\n entity: sibling,\n uniqueAttributeDefs,\n })) {\n result[attribute.uuid] = attribute\n }\n }\n }\n return result\n}\n\nconst deleteNodes = async (\n params: ArenaRecordNodesUpdateParams & {\n nodeUuids: string[]\n }\n): Promise<RecordUpdateResult> => {\n const { survey, nodeUuids, record: _record, sideEffect = false } = params\n\n // found before removing the nodes: the deleted nodes are no longer reachable from their siblings afterwards\n const siblingKeyOrUniqueAttributes = getSiblingKeyOrUniqueAttributes({ survey, record: _record, nodeUuids })\n\n const updateResult = Records.removeNodes(nodeUuids, { sideEffect })(_record)\n const { record, nodesDeleted } = updateResult\n\n const result = await _onRecordNodesCreateOrUpdate({\n ...withDateModified(params),\n record,\n nodes: nodesDeleted,\n additionalNodesToValidate: siblingKeyOrUniqueAttributes,\n })\n result.nodesDeleted = nodesDeleted\n return result\n}\n\nconst deleteNode = async (params: ArenaRecordNodesUpdateParams & { nodeUuid: string }): Promise<RecordUpdateResult> => {\n const { nodeUuid } = params\n return deleteNodes({ ...params, nodeUuids: [nodeUuid] })\n}\n\n/**\n * Evaluates again the expressions using the app info functions (appId, appIdLabel, appPlatform, appVersion)\n * if the record is being edited with an app different from the one that updated it last\n * (different app id, platform or version, see Records.isAppInfoChanged); does nothing otherwise.\n * To be called when the record is opened for editing (the same check is done in every record update).\n */\nconst updateAppInfoDependents = async (params: ArenaRecordNodesUpdateParams): Promise<RecordUpdateResult> => {\n const { record, appInfo } = params\n if (!Records.isAppInfoChanged(appInfo)(record)) {\n return new RecordUpdateResult({ record })\n }\n return _onRecordNodesCreateOrUpdate({ ...withDateModified(params), nodes: {} })\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 updateAppInfoDependents,\n}\n"]}
|
package/dist/record/records.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { getCycle, getRoot, getNodes, getNodesArray, getNodeByUuid, getNodesByUuids, getNodesByDefUuid, getChild, getChildren, getParent, getParentCodeAttribute, getAncestorCodeAttributes, 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';
|
|
1
|
+
import { getAppInfoLast, isAppInfoChanged, getCycle, getRoot, getNodes, getNodesArray, getNodeByUuid, getNodesByUuids, getNodesByDefUuid, getChild, getChildren, getParent, getParentCodeAttribute, getAncestorCodeAttributes, 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';
|
|
5
5
|
import { getDescendantPageNodeDefUuids, getEntitySubtreeStatus, getMultiplePageEntitiesStatus, getNodeDefChildrenInOwnPage, getPageNodeDefs, getPageValidationStatus, getRecordPagesValidationProgress, nodeBelongsToOwnPage, nodeBelongsToPage, pageHasOwnErrors } from './_records/recordPagesValidation';
|
|
6
6
|
import { removeNode, removeNodes } from './recordNodesUpdater/recordNodesDeleter';
|
|
7
7
|
export declare const Records: {
|
|
8
|
+
getAppInfoLast: typeof getAppInfoLast;
|
|
9
|
+
isAppInfoChanged: typeof isAppInfoChanged;
|
|
8
10
|
getCycle: typeof getCycle;
|
|
9
11
|
getRoot: typeof getRoot;
|
|
10
12
|
getNodes: typeof getNodes;
|