@openforis/arena-core 3.2.2 → 3.2.4
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 +19 -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 +15 -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 +22 -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 +15 -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
package/dist/node/nodes.js
CHANGED
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.RecordNodes = void 0;
|
|
15
15
|
const nodeDef_1 = require("../nodeDef");
|
|
16
16
|
const utils_1 = require("../utils");
|
|
17
|
+
const getDateModified = (options) => { var _a; return (_a = options === null || options === void 0 ? void 0 : options.dateModified) !== null && _a !== void 0 ? _a : utils_1.Dates.nowFormattedForStorage(); };
|
|
17
18
|
const isRoot = (node) => !node.parentUuid;
|
|
18
19
|
const areEqual = (nodeA, nodeB) => nodeA.uuid === nodeB.uuid;
|
|
19
20
|
const isChildApplicable = (node, nodeDefUuid) => {
|
|
@@ -58,7 +59,7 @@ const isQualifierValueApplied = (node) => { var _a; var _b; return (_b = (_a = n
|
|
|
58
59
|
const isValueBlank = (node) => utils_1.Objects.isEmpty(node.value);
|
|
59
60
|
const isValueNotBlank = (node) => utils_1.Objects.isNotEmpty(node.value);
|
|
60
61
|
const hasUserInputValue = (node) => node && !isValueBlank(node) && !isDefaultValueApplied(node) && !isQualifierValueApplied(node);
|
|
61
|
-
const assocChildApplicability = (node, nodeDefUuid, applicable) => {
|
|
62
|
+
const assocChildApplicability = (node, nodeDefUuid, applicable, options) => {
|
|
62
63
|
var _a;
|
|
63
64
|
const childApplicability = Object.assign({}, (_a = node.meta) === null || _a === void 0 ? void 0 : _a.childApplicability);
|
|
64
65
|
if (!applicable) {
|
|
@@ -67,7 +68,7 @@ const assocChildApplicability = (node, nodeDefUuid, applicable) => {
|
|
|
67
68
|
else {
|
|
68
69
|
delete childApplicability[nodeDefUuid];
|
|
69
70
|
}
|
|
70
|
-
return Object.assign(Object.assign({}, node), { meta: Object.assign(Object.assign({}, node.meta), { childApplicability }), updated: true, dateModified:
|
|
71
|
+
return Object.assign(Object.assign({}, node), { meta: Object.assign(Object.assign({}, node.meta), { childApplicability }), updated: true, dateModified: getDateModified(options) });
|
|
71
72
|
};
|
|
72
73
|
const dissocChildApplicability = (node, nodeDefUuid) => {
|
|
73
74
|
var _a;
|
|
@@ -75,7 +76,7 @@ const dissocChildApplicability = (node, nodeDefUuid) => {
|
|
|
75
76
|
delete childApplicability[nodeDefUuid];
|
|
76
77
|
return Object.assign(Object.assign({}, node), { meta: Object.assign(Object.assign({}, node.meta), { childApplicability }) });
|
|
77
78
|
};
|
|
78
|
-
const updateMetaDictionary = ({ node, nodeDefUuid, propName, propValue, defaultValue = true, sideEffect, }) => {
|
|
79
|
+
const updateMetaDictionary = ({ node, nodeDefUuid, propName, propValue, defaultValue = true, sideEffect, dateModified, }) => {
|
|
79
80
|
var _a, _b;
|
|
80
81
|
const nodeUpdated = sideEffect ? node : Object.assign({}, node);
|
|
81
82
|
const metaOriginal = (_a = nodeUpdated.meta) !== null && _a !== void 0 ? _a : {};
|
|
@@ -92,15 +93,15 @@ const updateMetaDictionary = ({ node, nodeDefUuid, propName, propValue, defaultV
|
|
|
92
93
|
meta[propName] = dictionary;
|
|
93
94
|
nodeUpdated.meta = meta;
|
|
94
95
|
nodeUpdated.updated = true;
|
|
95
|
-
nodeUpdated.dateModified =
|
|
96
|
+
nodeUpdated.dateModified = getDateModified({ dateModified });
|
|
96
97
|
return nodeUpdated;
|
|
97
98
|
};
|
|
98
99
|
function assocChildEditable(node, nodeDefUuid, editable, options) {
|
|
99
|
-
const { sideEffect = false } = options !== null && options !== void 0 ? options : {};
|
|
100
|
-
return updateMetaDictionary({ node, nodeDefUuid, propName: 'cEdit', propValue: editable, sideEffect });
|
|
100
|
+
const { sideEffect = false, dateModified } = options !== null && options !== void 0 ? options : {};
|
|
101
|
+
return updateMetaDictionary({ node, nodeDefUuid, propName: 'cEdit', propValue: editable, sideEffect, dateModified });
|
|
101
102
|
}
|
|
102
103
|
const assocChildRequired = (node, nodeDefUuid, required, options) => {
|
|
103
|
-
const { sideEffect = false } = options !== null && options !== void 0 ? options : {};
|
|
104
|
+
const { sideEffect = false, dateModified } = options !== null && options !== void 0 ? options : {};
|
|
104
105
|
return updateMetaDictionary({
|
|
105
106
|
node,
|
|
106
107
|
nodeDefUuid,
|
|
@@ -108,15 +109,16 @@ const assocChildRequired = (node, nodeDefUuid, required, options) => {
|
|
|
108
109
|
propValue: required,
|
|
109
110
|
defaultValue: false,
|
|
110
111
|
sideEffect,
|
|
112
|
+
dateModified,
|
|
111
113
|
});
|
|
112
114
|
};
|
|
113
115
|
function assocChildVisible(node, nodeDefUuid, visible, options) {
|
|
114
|
-
const { sideEffect = false } = options !== null && options !== void 0 ? options : {};
|
|
115
|
-
return updateMetaDictionary({ node, nodeDefUuid, propName: 'cVis', propValue: visible, sideEffect });
|
|
116
|
+
const { sideEffect = false, dateModified } = options !== null && options !== void 0 ? options : {};
|
|
117
|
+
return updateMetaDictionary({ node, nodeDefUuid, propName: 'cVis', propValue: visible, sideEffect, dateModified });
|
|
116
118
|
}
|
|
117
119
|
const assocChildrenCount = (params) => {
|
|
118
120
|
var _a, _b;
|
|
119
|
-
const { node, nodeDefUuid, count, countType } = params;
|
|
121
|
+
const { node, nodeDefUuid, count, countType, dateModified } = params;
|
|
120
122
|
const countIndex = Object.assign({}, (countType === nodeDef_1.NodeDefCountType.max ? (_a = node.meta) === null || _a === void 0 ? void 0 : _a.childrenMaxCount : (_b = node.meta) === null || _b === void 0 ? void 0 : _b.childrenMinCount));
|
|
121
123
|
if (Number.isNaN(count)) {
|
|
122
124
|
delete countIndex[nodeDefUuid];
|
|
@@ -131,7 +133,7 @@ const assocChildrenCount = (params) => {
|
|
|
131
133
|
else {
|
|
132
134
|
metaUpdated.childrenMinCount = countIndex;
|
|
133
135
|
}
|
|
134
|
-
return Object.assign(Object.assign({}, node), { meta: metaUpdated, updated: true, dateModified:
|
|
136
|
+
return Object.assign(Object.assign({}, node), { meta: metaUpdated, updated: true, dateModified: getDateModified({ dateModified }) });
|
|
135
137
|
};
|
|
136
138
|
const assocChildrenMaxCount = (params) => assocChildrenCount(Object.assign(Object.assign({}, params), { countType: nodeDef_1.NodeDefCountType.max }));
|
|
137
139
|
const assocChildrenMinCount = (params) => assocChildrenCount(Object.assign(Object.assign({}, params), { countType: nodeDef_1.NodeDefCountType.min }));
|
|
@@ -156,7 +158,7 @@ function assocValue(node, value, options) {
|
|
|
156
158
|
const nodeUpdated = sideEffect ? node : Object.assign({}, node);
|
|
157
159
|
nodeUpdated.value = value;
|
|
158
160
|
nodeUpdated.updated = true;
|
|
159
|
-
nodeUpdated.dateModified =
|
|
161
|
+
nodeUpdated.dateModified = getDateModified(options);
|
|
160
162
|
if (isDefaultValueApplied(nodeUpdated) || isQualifierValueApplied(nodeUpdated)) {
|
|
161
163
|
// reset defaultValueApplied and qualifierValueApplied flags
|
|
162
164
|
const metaOriginal = (_a = nodeUpdated.meta) !== null && _a !== void 0 ? _a : {};
|
package/dist/node/nodes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../src/node/nodes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,wCAAqE;AACrE,oCAAyC;AAIzC,MAAM,MAAM,GAAG,CAAC,IAAqB,EAAW,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAA;AAEnE,MAAM,QAAQ,GAAG,CAAC,KAAsB,EAAE,KAAsB,EAAW,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAA;AAEvG,MAAM,iBAAiB,GAAG,CAAC,IAAqB,EAAE,WAAmB,EAAW,EAAE;;IAChF,sFAAsF;IACtF,OAAO,CAAA,MAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,kBAAkB,0CAAG,WAAW,CAAC,MAAK,KAAK,CAAA;AAC/D,CAAC,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,IAAqB,EAAE,WAAmB,EAAW,EAAE;;IAC9E,kFAAkF;IAClF,OAAO,CAAA,MAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,0CAAG,WAAW,CAAC,MAAK,KAAK,CAAA;AAClD,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,IAAqB,EAAE,WAAmB,EAAW,EAAE;;IAC7E,gFAAgF;IAChF,OAAO,CAAA,MAAA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,CAAA;IAC5C,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,mBAAM,IAAI,CAAE,CAAA;IACnD,WAAW,CAAC,KAAK,GAAG,KAAK,CAAA;IACzB,WAAW,CAAC,OAAO,GAAG,IAAI,CAAA;IAC1B,WAAW,CAAC,YAAY,GAAG,aAAK,CAAC,sBAAsB,EAAE,CAAA;IACzD,IAAI,qBAAqB,CAAC,WAAW,CAAC,IAAI,uBAAuB,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/E,4DAA4D;QAC5D,MAAM,YAAY,SAAG,WAAW,CAAC,IAAI,mCAAI,EAAE,CAAA;QAC3C,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,mBAAM,YAAY,CAAE,CAAA;QAC5D,WAAW,CAAC,IAAI,mCAAQ,IAAI,KAAE,mBAAmB,EAAE,KAAK,EAAE,qBAAqB,EAAE,KAAK,GAAE,CAAA;IAC1F,CAAC;IACD,OAAO,WAAW,CAAA;AACpB,CAAC;AAEY,QAAA,WAAW,GAAG;IACzB,MAAM;IACN,QAAQ;IACR,iBAAiB;IACjB,eAAe;IACf,cAAc;IACd,eAAe;IACf,wBAAwB;IACxB,mBAAmB;IACnB,mBAAmB;IACnB,YAAY;IACZ,gBAAgB;IAChB,qBAAqB;IACrB,uBAAuB;IACvB,YAAY;IACZ,eAAe;IACf,iBAAiB;IACjB,SAAS;IACT,uBAAuB;IACvB,wBAAwB;IACxB,kBAAkB;IAClB,iBAAiB;IACjB,kBAAkB;IAClB,kBAAkB;IAClB,qBAAqB;IACrB,qBAAqB;IACrB,UAAU;IACV,iBAAiB;IACjB,UAAU;CACX,CAAA","sourcesContent":["import { ArenaDictionary } from '../common'\nimport { ArenaNodeDef, NodeDefCountType, NodeDefs } from '../nodeDef'\nimport { Dates, Objects } from '../utils'\nimport { ArenaMutationOptions } from '../utils/mutationOptions'\nimport { ArenaRecordNode } from './node'\n\nconst isRoot = (node: ArenaRecordNode): boolean => !node.parentUuid\n\nconst areEqual = (nodeA: ArenaRecordNode, nodeB: ArenaRecordNode): boolean => nodeA.uuid === nodeB.uuid\n\nconst isChildApplicable = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child applicability is not defined for a node definition, consider it applicable\n return node.meta?.childApplicability?.[nodeDefUuid] !== false\n}\n\nconst isChildEditable = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child editability is not defined for a node definition, consider it editable\n return node.meta?.cEdit?.[nodeDefUuid] !== false\n}\n\nconst isChildVisible = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child visibility is not defined for a node definition, consider it visible\n return node.meta?.cVis?.[nodeDefUuid] !== false\n}\n\nconst isChildRequired = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child \"required if\" condition is not defined or not met for a node definition, consider it not required\n return node.meta?.cReq?.[nodeDefUuid] === true\n}\n\nconst getChildrenMinOrMaxCount = (params: {\n parentNode: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n countType: NodeDefCountType\n}): number => {\n const { parentNode, nodeDef, countType } = params\n const countIndex =\n countType === NodeDefCountType.max ? parentNode.meta?.childrenMaxCount : parentNode.meta?.childrenMinCount\n\n const count = countIndex?.[nodeDef.uuid]\n if (!Objects.isEmpty(count)) return count!\n\n // count can be a constant value, specified in the node def min/max count prop\n const nodeDefCount =\n countType === NodeDefCountType.max ? NodeDefs.getMaxCount(nodeDef) : NodeDefs.getMinCount(nodeDef)\n // count expressions (array) are evaluated into the parent node meta (childrenMinCount/childrenMaxCount)\n return nodeDefCount && !Array.isArray(nodeDefCount) ? Number(nodeDefCount) : Number.NaN\n}\n\nconst getChildrenMaxCount = (params: { parentNode: ArenaRecordNode; nodeDef: ArenaNodeDef<any> }): number =>\n getChildrenMinOrMaxCount({ ...params, countType: NodeDefCountType.max })\n\nconst getChildrenMinCount = (params: { parentNode: ArenaRecordNode; nodeDef: ArenaNodeDef<any> }): number =>\n getChildrenMinOrMaxCount({ ...params, countType: NodeDefCountType.min })\n\nconst getHierarchy = (node: ArenaRecordNode): string[] => [...(node.meta?.h ?? [])]\n\nconst getHierarchyCode = (node: ArenaRecordNode): string[] => [...(node.meta?.hCode ?? [])]\n\nconst mergeNodes = (target: ArenaRecordNode, ...sources: ArenaRecordNode[] | object[]): ArenaRecordNode =>\n Objects.deepMerge(target, ...sources) as unknown as ArenaRecordNode\n\nconst isDefaultValueApplied = (node: ArenaRecordNode): boolean => node?.meta?.defaultValueApplied ?? false\n\nconst isQualifierValueApplied = (node: ArenaRecordNode): boolean => node?.meta?.qualifierValueApplied ?? false\n\nconst isValueBlank = (node: ArenaRecordNode): boolean => Objects.isEmpty(node.value)\n\nconst isValueNotBlank = (node: ArenaRecordNode): boolean => Objects.isNotEmpty(node.value)\n\nconst hasUserInputValue = (node: ArenaRecordNode): boolean =>\n node && !isValueBlank(node) && !isDefaultValueApplied(node) && !isQualifierValueApplied(node)\n\nconst assocChildApplicability = (node: ArenaRecordNode, nodeDefUuid: string, applicable: boolean): ArenaRecordNode => {\n const childApplicability = { ...node.meta?.childApplicability }\n if (!applicable) {\n childApplicability[nodeDefUuid] = applicable\n } else {\n delete childApplicability[nodeDefUuid]\n }\n return {\n ...node,\n meta: { ...node.meta, childApplicability },\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }\n}\n\nconst dissocChildApplicability = (node: ArenaRecordNode, nodeDefUuid: string) => {\n const childApplicability = { ...node.meta?.childApplicability }\n delete childApplicability[nodeDefUuid]\n return {\n ...node,\n meta: { ...node.meta, childApplicability },\n }\n}\n\ntype MetaBooleanDictionaryProp = 'childApplicability' | 'cEdit' | 'cVis' | 'cReq'\n\nconst updateMetaDictionary = ({\n node,\n nodeDefUuid,\n propName,\n propValue,\n defaultValue = true,\n sideEffect,\n}: {\n node: ArenaRecordNode\n nodeDefUuid: string\n propName: MetaBooleanDictionaryProp\n propValue: boolean\n defaultValue?: boolean\n sideEffect: boolean\n}): ArenaRecordNode => {\n const nodeUpdated = sideEffect ? node : { ...node }\n const metaOriginal = nodeUpdated.meta ?? {}\n const meta = sideEffect ? metaOriginal : { ...metaOriginal }\n const existingDictionary: ArenaDictionary<boolean> = meta[propName] ?? {}\n const dictionary = sideEffect ? existingDictionary : { ...existingDictionary }\n if (propValue === defaultValue) {\n // default value: not stored\n delete dictionary[nodeDefUuid]\n } else {\n dictionary[nodeDefUuid] = propValue\n }\n meta[propName] = dictionary\n nodeUpdated.meta = meta\n nodeUpdated.updated = true\n nodeUpdated.dateModified = Dates.nowFormattedForStorage()\n return nodeUpdated\n}\n\nfunction assocChildEditable(\n node: ArenaRecordNode,\n nodeDefUuid: string,\n editable: boolean,\n options?: ArenaMutationOptions\n): ArenaRecordNode {\n const { sideEffect = false } = options ?? {}\n return updateMetaDictionary({ node, nodeDefUuid, propName: 'cEdit', propValue: editable, sideEffect })\n}\n\nconst assocChildRequired = (\n node: ArenaRecordNode,\n nodeDefUuid: string,\n required: boolean,\n options?: ArenaMutationOptions\n): ArenaRecordNode => {\n const { sideEffect = false } = options ?? {}\n return updateMetaDictionary({\n node,\n nodeDefUuid,\n propName: 'cReq',\n propValue: required,\n defaultValue: false,\n sideEffect,\n })\n}\n\nfunction assocChildVisible(\n node: ArenaRecordNode,\n nodeDefUuid: string,\n visible: boolean,\n options?: ArenaMutationOptions\n): ArenaRecordNode {\n const { sideEffect = false } = options ?? {}\n return updateMetaDictionary({ node, nodeDefUuid, propName: 'cVis', propValue: visible, sideEffect })\n}\n\nconst assocChildrenCount = (params: {\n node: ArenaRecordNode\n nodeDefUuid: string\n count: number\n countType: NodeDefCountType\n}): ArenaRecordNode => {\n const { node, nodeDefUuid, count, countType } = params\n const countIndex = {\n ...(countType === NodeDefCountType.max ? node.meta?.childrenMaxCount : node.meta?.childrenMinCount),\n }\n if (Number.isNaN(count)) {\n delete countIndex[nodeDefUuid]\n } else {\n countIndex[nodeDefUuid] = count\n }\n const metaUpdated = { ...node.meta }\n if (countType === NodeDefCountType.max) {\n metaUpdated.childrenMaxCount = countIndex\n } else {\n metaUpdated.childrenMinCount = countIndex\n }\n return {\n ...node,\n meta: metaUpdated,\n updated: true,\n dateModified: Dates.nowFormattedForStorage(),\n }\n}\n\nconst assocChildrenMaxCount = (params: {\n node: ArenaRecordNode\n nodeDefUuid: string\n count: number\n}): ArenaRecordNode => assocChildrenCount({ ...params, countType: NodeDefCountType.max })\n\nconst assocChildrenMinCount = (params: {\n node: ArenaRecordNode\n nodeDefUuid: string\n count: number\n}): ArenaRecordNode => assocChildrenCount({ ...params, countType: NodeDefCountType.min })\n\nconst clearStatusFlagsInPlace = (node: ArenaRecordNode): ArenaRecordNode => {\n // do not use \"delete\": it would switch the node object to the (much bigger) V8 dictionary mode\n if (node.created !== undefined) node.created = undefined\n if (node.deleted !== undefined) node.deleted = undefined\n if (node.updated !== undefined) node.updated = undefined\n return node\n}\n\nconst omitStatusFlags = (node: ArenaRecordNode): ArenaRecordNode => {\n const { created: _created, deleted: _deleted, updated: _updated, ...nodeCleaned } = node\n return nodeCleaned\n}\n\nconst removeStatusFlags = ({\n node,\n sideEffect = false,\n}: {\n node: ArenaRecordNode\n sideEffect?: boolean\n}): ArenaRecordNode => (sideEffect ? clearStatusFlagsInPlace(node) : omitStatusFlags(node))\n\nfunction assocValue(node: ArenaRecordNode, value: any, options?: ArenaMutationOptions): ArenaRecordNode {\n const { sideEffect = false } = options ?? {}\n const nodeUpdated = sideEffect ? node : { ...node }\n nodeUpdated.value = value\n nodeUpdated.updated = true\n nodeUpdated.dateModified = Dates.nowFormattedForStorage()\n if (isDefaultValueApplied(nodeUpdated) || isQualifierValueApplied(nodeUpdated)) {\n // reset defaultValueApplied and qualifierValueApplied flags\n const metaOriginal = nodeUpdated.meta ?? {}\n const meta = sideEffect ? metaOriginal : { ...metaOriginal }\n nodeUpdated.meta = { ...meta, defaultValueApplied: false, qualifierValueApplied: false }\n }\n return nodeUpdated\n}\n\nexport const RecordNodes = {\n isRoot,\n areEqual,\n isChildApplicable,\n isChildEditable,\n isChildVisible,\n isChildRequired,\n getChildrenMinOrMaxCount,\n getChildrenMaxCount,\n getChildrenMinCount,\n getHierarchy,\n getHierarchyCode,\n isDefaultValueApplied,\n isQualifierValueApplied,\n isValueBlank,\n isValueNotBlank,\n hasUserInputValue,\n // update\n assocChildApplicability,\n dissocChildApplicability,\n assocChildEditable,\n assocChildVisible,\n assocChildRequired,\n assocChildrenCount,\n assocChildrenMaxCount,\n assocChildrenMinCount,\n mergeNodes,\n removeStatusFlags,\n assocValue,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nodes.js","sourceRoot":"","sources":["../../src/node/nodes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,wCAAqE;AACrE,oCAAyC;AAezC,MAAM,eAAe,GAAG,CAAC,OAAsC,EAAU,EAAE,wBACzE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,YAAY,mCAAI,aAAK,CAAC,sBAAsB,EAAE,GAAA,CAAA;AAEzD,MAAM,MAAM,GAAG,CAAC,IAAqB,EAAW,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAA;AAEnE,MAAM,QAAQ,GAAG,CAAC,KAAsB,EAAE,KAAsB,EAAW,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,CAAA;AAEvG,MAAM,iBAAiB,GAAG,CAAC,IAAqB,EAAE,WAAmB,EAAW,EAAE;;IAChF,sFAAsF;IACtF,OAAO,CAAA,MAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,kBAAkB,0CAAG,WAAW,CAAC,MAAK,KAAK,CAAA;AAC/D,CAAC,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,IAAqB,EAAE,WAAmB,EAAW,EAAE;;IAC9E,kFAAkF;IAClF,OAAO,CAAA,MAAA,MAAA,IAAI,CAAC,IAAI,0CAAE,KAAK,0CAAG,WAAW,CAAC,MAAK,KAAK,CAAA;AAClD,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,CA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;IACjB,UAAU;CACX,CAAA","sourcesContent":["import { ArenaDictionary } from '../common'\nimport { ArenaNodeDef, NodeDefCountType, NodeDefs } from '../nodeDef'\nimport { Dates, Objects } from '../utils'\nimport { ArenaMutationOptions } from '../utils/mutationOptions'\nimport { ArenaRecordNode } from './node'\n\n/**\n * Options of the node update functions.\n */\nexport interface ArenaRecordNodeUpdateOptions extends ArenaMutationOptions {\n /**\n * Date of the modification (formatted for storage); the same date is used for all the nodes modified in the same record update.\n * @default now\n */\n dateModified?: string\n}\n\nconst getDateModified = (options?: ArenaRecordNodeUpdateOptions): string =>\n options?.dateModified ?? Dates.nowFormattedForStorage()\n\nconst isRoot = (node: ArenaRecordNode): boolean => !node.parentUuid\n\nconst areEqual = (nodeA: ArenaRecordNode, nodeB: ArenaRecordNode): boolean => nodeA.uuid === nodeB.uuid\n\nconst isChildApplicable = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child applicability is not defined for a node definition, consider it applicable\n return node.meta?.childApplicability?.[nodeDefUuid] !== false\n}\n\nconst isChildEditable = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child editability is not defined for a node definition, consider it editable\n return node.meta?.cEdit?.[nodeDefUuid] !== false\n}\n\nconst isChildVisible = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child visibility is not defined for a node definition, consider it visible\n return node.meta?.cVis?.[nodeDefUuid] !== false\n}\n\nconst isChildRequired = (node: ArenaRecordNode, nodeDefUuid: string): boolean => {\n // if child \"required if\" condition is not defined or not met for a node definition, consider it not required\n return node.meta?.cReq?.[nodeDefUuid] === true\n}\n\nconst getChildrenMinOrMaxCount = (params: {\n parentNode: ArenaRecordNode\n nodeDef: ArenaNodeDef<any>\n countType: NodeDefCountType\n}): number => {\n const { parentNode, nodeDef, countType } = params\n const countIndex =\n countType === NodeDefCountType.max ? parentNode.meta?.childrenMaxCount : parentNode.meta?.childrenMinCount\n\n const count = countIndex?.[nodeDef.uuid]\n if (!Objects.isEmpty(count)) return count!\n\n // count can be a constant value, specified in the node def min/max count prop\n const nodeDefCount =\n countType === NodeDefCountType.max ? NodeDefs.getMaxCount(nodeDef) : NodeDefs.getMinCount(nodeDef)\n // count expressions (array) are evaluated into the parent node meta (childrenMinCount/childrenMaxCount)\n return nodeDefCount && !Array.isArray(nodeDefCount) ? Number(nodeDefCount) : Number.NaN\n}\n\nconst getChildrenMaxCount = (params: { parentNode: ArenaRecordNode; nodeDef: ArenaNodeDef<any> }): number =>\n getChildrenMinOrMaxCount({ ...params, countType: NodeDefCountType.max })\n\nconst getChildrenMinCount = (params: { parentNode: ArenaRecordNode; nodeDef: ArenaNodeDef<any> }): number =>\n getChildrenMinOrMaxCount({ ...params, countType: NodeDefCountType.min })\n\nconst getHierarchy = (node: ArenaRecordNode): string[] => [...(node.meta?.h ?? [])]\n\nconst getHierarchyCode = (node: ArenaRecordNode): string[] => [...(node.meta?.hCode ?? [])]\n\nconst mergeNodes = (target: ArenaRecordNode, ...sources: ArenaRecordNode[] | object[]): ArenaRecordNode =>\n Objects.deepMerge(target, ...sources) as unknown as ArenaRecordNode\n\nconst isDefaultValueApplied = (node: ArenaRecordNode): boolean => node?.meta?.defaultValueApplied ?? false\n\nconst isQualifierValueApplied = (node: ArenaRecordNode): boolean => node?.meta?.qualifierValueApplied ?? false\n\nconst isValueBlank = (node: ArenaRecordNode): boolean => Objects.isEmpty(node.value)\n\nconst isValueNotBlank = (node: ArenaRecordNode): boolean => Objects.isNotEmpty(node.value)\n\nconst hasUserInputValue = (node: ArenaRecordNode): boolean =>\n node && !isValueBlank(node) && !isDefaultValueApplied(node) && !isQualifierValueApplied(node)\n\nconst assocChildApplicability = (\n node: ArenaRecordNode,\n nodeDefUuid: string,\n applicable: boolean,\n options?: Omit<ArenaRecordNodeUpdateOptions, 'sideEffect'>\n): ArenaRecordNode => {\n const childApplicability = { ...node.meta?.childApplicability }\n if (!applicable) {\n childApplicability[nodeDefUuid] = applicable\n } else {\n delete childApplicability[nodeDefUuid]\n }\n return {\n ...node,\n meta: { ...node.meta, childApplicability },\n updated: true,\n dateModified: getDateModified(options),\n }\n}\n\nconst dissocChildApplicability = (node: ArenaRecordNode, nodeDefUuid: string) => {\n const childApplicability = { ...node.meta?.childApplicability }\n delete childApplicability[nodeDefUuid]\n return {\n ...node,\n meta: { ...node.meta, childApplicability },\n }\n}\n\ntype MetaBooleanDictionaryProp = 'childApplicability' | 'cEdit' | 'cVis' | 'cReq'\n\nconst updateMetaDictionary = ({\n node,\n nodeDefUuid,\n propName,\n propValue,\n defaultValue = true,\n sideEffect,\n dateModified,\n}: {\n node: ArenaRecordNode\n nodeDefUuid: string\n propName: MetaBooleanDictionaryProp\n propValue: boolean\n defaultValue?: boolean\n sideEffect: boolean\n dateModified?: string\n}): ArenaRecordNode => {\n const nodeUpdated = sideEffect ? node : { ...node }\n const metaOriginal = nodeUpdated.meta ?? {}\n const meta = sideEffect ? metaOriginal : { ...metaOriginal }\n const existingDictionary: ArenaDictionary<boolean> = meta[propName] ?? {}\n const dictionary = sideEffect ? existingDictionary : { ...existingDictionary }\n if (propValue === defaultValue) {\n // default value: not stored\n delete dictionary[nodeDefUuid]\n } else {\n dictionary[nodeDefUuid] = propValue\n }\n meta[propName] = dictionary\n nodeUpdated.meta = meta\n nodeUpdated.updated = true\n nodeUpdated.dateModified = getDateModified({ dateModified })\n return nodeUpdated\n}\n\nfunction assocChildEditable(\n node: ArenaRecordNode,\n nodeDefUuid: string,\n editable: boolean,\n options?: ArenaRecordNodeUpdateOptions\n): ArenaRecordNode {\n const { sideEffect = false, dateModified } = options ?? {}\n return updateMetaDictionary({ node, nodeDefUuid, propName: 'cEdit', propValue: editable, sideEffect, dateModified })\n}\n\nconst assocChildRequired = (\n node: ArenaRecordNode,\n nodeDefUuid: string,\n required: boolean,\n options?: ArenaRecordNodeUpdateOptions\n): ArenaRecordNode => {\n const { sideEffect = false, dateModified } = options ?? {}\n return updateMetaDictionary({\n node,\n nodeDefUuid,\n propName: 'cReq',\n propValue: required,\n defaultValue: false,\n sideEffect,\n dateModified,\n })\n}\n\nfunction assocChildVisible(\n node: ArenaRecordNode,\n nodeDefUuid: string,\n visible: boolean,\n options?: ArenaRecordNodeUpdateOptions\n): ArenaRecordNode {\n const { sideEffect = false, dateModified } = options ?? {}\n return updateMetaDictionary({ node, nodeDefUuid, propName: 'cVis', propValue: visible, sideEffect, dateModified })\n}\n\nconst assocChildrenCount = (params: {\n node: ArenaRecordNode\n nodeDefUuid: string\n count: number\n countType: NodeDefCountType\n dateModified?: string\n}): ArenaRecordNode => {\n const { node, nodeDefUuid, count, countType, dateModified } = params\n const countIndex = {\n ...(countType === NodeDefCountType.max ? node.meta?.childrenMaxCount : node.meta?.childrenMinCount),\n }\n if (Number.isNaN(count)) {\n delete countIndex[nodeDefUuid]\n } else {\n countIndex[nodeDefUuid] = count\n }\n const metaUpdated = { ...node.meta }\n if (countType === NodeDefCountType.max) {\n metaUpdated.childrenMaxCount = countIndex\n } else {\n metaUpdated.childrenMinCount = countIndex\n }\n return {\n ...node,\n meta: metaUpdated,\n updated: true,\n dateModified: getDateModified({ dateModified }),\n }\n}\n\nconst assocChildrenMaxCount = (params: {\n node: ArenaRecordNode\n nodeDefUuid: string\n count: number\n dateModified?: string\n}): ArenaRecordNode => assocChildrenCount({ ...params, countType: NodeDefCountType.max })\n\nconst assocChildrenMinCount = (params: {\n node: ArenaRecordNode\n nodeDefUuid: string\n count: number\n dateModified?: string\n}): ArenaRecordNode => assocChildrenCount({ ...params, countType: NodeDefCountType.min })\n\nconst clearStatusFlagsInPlace = (node: ArenaRecordNode): ArenaRecordNode => {\n // do not use \"delete\": it would switch the node object to the (much bigger) V8 dictionary mode\n if (node.created !== undefined) node.created = undefined\n if (node.deleted !== undefined) node.deleted = undefined\n if (node.updated !== undefined) node.updated = undefined\n return node\n}\n\nconst omitStatusFlags = (node: ArenaRecordNode): ArenaRecordNode => {\n const { created: _created, deleted: _deleted, updated: _updated, ...nodeCleaned } = node\n return nodeCleaned\n}\n\nconst removeStatusFlags = ({\n node,\n sideEffect = false,\n}: {\n node: ArenaRecordNode\n sideEffect?: boolean\n}): ArenaRecordNode => (sideEffect ? clearStatusFlagsInPlace(node) : omitStatusFlags(node))\n\nfunction assocValue(node: ArenaRecordNode, value: any, options?: ArenaRecordNodeUpdateOptions): ArenaRecordNode {\n const { sideEffect = false } = options ?? {}\n const nodeUpdated = sideEffect ? node : { ...node }\n nodeUpdated.value = value\n nodeUpdated.updated = true\n nodeUpdated.dateModified = getDateModified(options)\n if (isDefaultValueApplied(nodeUpdated) || isQualifierValueApplied(nodeUpdated)) {\n // reset defaultValueApplied and qualifierValueApplied flags\n const metaOriginal = nodeUpdated.meta ?? {}\n const meta = sideEffect ? metaOriginal : { ...metaOriginal }\n nodeUpdated.meta = { ...meta, defaultValueApplied: false, qualifierValueApplied: false }\n }\n return nodeUpdated\n}\n\nexport const RecordNodes = {\n isRoot,\n areEqual,\n isChildApplicable,\n isChildEditable,\n isChildVisible,\n isChildRequired,\n getChildrenMinOrMaxCount,\n getChildrenMaxCount,\n getChildrenMinCount,\n getHierarchy,\n getHierarchyCode,\n isDefaultValueApplied,\n isQualifierValueApplied,\n isValueBlank,\n isValueNotBlank,\n hasUserInputValue,\n // update\n assocChildApplicability,\n dissocChildApplicability,\n assocChildEditable,\n assocChildVisible,\n assocChildRequired,\n assocChildrenCount,\n assocChildrenMaxCount,\n assocChildrenMinCount,\n mergeNodes,\n removeStatusFlags,\n assocValue,\n}\n"]}
|
|
@@ -14,6 +14,10 @@ export interface NodeDefExpressionContext extends ArenaExpressionContext {
|
|
|
14
14
|
* Unique UUIDs of node definitions being visited during expression evaluation.
|
|
15
15
|
*/
|
|
16
16
|
referencedNodeDefUuids?: Set<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Unique UUIDs of entity definitions whose nodes dates are used in the expression (nodeDateCreated, nodeDateModified).
|
|
19
|
+
*/
|
|
20
|
+
nodeDateReferencedNodeDefUuids?: Set<string>;
|
|
17
21
|
selfReferenceAllowed?: boolean;
|
|
18
22
|
itemsFilter?: boolean;
|
|
19
23
|
memberProperty?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/nodeDefExpressionEvaluator/context.ts"],"names":[],"mappings":"","sourcesContent":["import { ArenaUser } from '../auth'\nimport { ArenaExpressionContext } from '../expression'\nimport { ArenaAnyNodeDef } from '../nodeDef'\nimport { ArenaSurvey } from '../survey'\nimport { ArenaAreaOfInterestProvider } from './areaOfInterestProvider'\nimport { ArenaCategoryItemProvider } from './categoryItemProvider'\nimport { ArenaTaxonProvider } from './taxonProvider'\n\nexport interface NodeDefExpressionContext extends ArenaExpressionContext {\n survey: ArenaSurvey\n user?: ArenaUser\n nodeDefCurrent: ArenaAnyNodeDef\n nodeDefContext?: ArenaAnyNodeDef\n /**\n * Unique UUIDs of node definitions being visited during expression evaluation.\n */\n referencedNodeDefUuids?: Set<string>\n selfReferenceAllowed?: boolean\n // true when the expression is used to filter code or taxon items\n itemsFilter?: boolean\n // true when evaluating the property of a member expression (e.g. \"length\" in \"text_attr.length\")\n memberProperty?: boolean\n\n categoryItemProvider?: ArenaCategoryItemProvider\n taxonProvider?: ArenaTaxonProvider\n areaOfInterestProvider?: ArenaAreaOfInterestProvider\n}\n"]}
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/nodeDefExpressionEvaluator/context.ts"],"names":[],"mappings":"","sourcesContent":["import { ArenaUser } from '../auth'\nimport { ArenaExpressionContext } from '../expression'\nimport { ArenaAnyNodeDef } from '../nodeDef'\nimport { ArenaSurvey } from '../survey'\nimport { ArenaAreaOfInterestProvider } from './areaOfInterestProvider'\nimport { ArenaCategoryItemProvider } from './categoryItemProvider'\nimport { ArenaTaxonProvider } from './taxonProvider'\n\nexport interface NodeDefExpressionContext extends ArenaExpressionContext {\n survey: ArenaSurvey\n user?: ArenaUser\n nodeDefCurrent: ArenaAnyNodeDef\n nodeDefContext?: ArenaAnyNodeDef\n /**\n * Unique UUIDs of node definitions being visited during expression evaluation.\n */\n referencedNodeDefUuids?: Set<string>\n /**\n * Unique UUIDs of entity definitions whose nodes dates are used in the expression (nodeDateCreated, nodeDateModified).\n */\n nodeDateReferencedNodeDefUuids?: Set<string>\n selfReferenceAllowed?: boolean\n // true when the expression is used to filter code or taxon items\n itemsFilter?: boolean\n // true when evaluating the property of a member expression (e.g. \"length\" in \"text_attr.length\")\n memberProperty?: boolean\n\n categoryItemProvider?: ArenaCategoryItemProvider\n taxonProvider?: ArenaTaxonProvider\n areaOfInterestProvider?: ArenaAreaOfInterestProvider\n}\n"]}
|
|
@@ -14,7 +14,7 @@ export type ExpressionEvaluatorParams = {
|
|
|
14
14
|
};
|
|
15
15
|
export declare class NodeDefExpressionEvaluator extends JavascriptExpressionEvaluator<NodeDefExpressionContext> {
|
|
16
16
|
constructor();
|
|
17
|
-
_eval(params: ExpressionEvaluatorParams, referencedNodeDefUuids?: Set<string>): Promise<{
|
|
17
|
+
_eval(params: ExpressionEvaluatorParams, referencedNodeDefUuids?: Set<string>, nodeDateReferencedNodeDefUuids?: Set<string>): Promise<{
|
|
18
18
|
result: any;
|
|
19
19
|
referencedNodeDefUuids: Set<string>;
|
|
20
20
|
}>;
|
|
@@ -24,5 +24,13 @@ export declare class NodeDefExpressionEvaluator extends JavascriptExpressionEval
|
|
|
24
24
|
* all the dependencies of the expression.
|
|
25
25
|
*/
|
|
26
26
|
findReferencedNodeDefUuids(params: ExpressionEvaluatorParams): Promise<Set<string>>;
|
|
27
|
+
/**
|
|
28
|
+
* Finds the node defs referenced by the expression (see findReferencedNodeDefUuids) and the entity defs
|
|
29
|
+
* whose nodes dates are used in it (nodeDateCreated, nodeDateModified functions).
|
|
30
|
+
*/
|
|
31
|
+
findReferencedNodeDefUuidsWithNodeDates(params: ExpressionEvaluatorParams): Promise<{
|
|
32
|
+
referencedNodeDefUuids: Set<string>;
|
|
33
|
+
nodeDateReferencedNodeDefUuids: Set<string>;
|
|
34
|
+
}>;
|
|
27
35
|
evalExpression(params: ExpressionEvaluatorParams): Promise<any>;
|
|
28
36
|
}
|
|
@@ -25,7 +25,7 @@ class NodeDefExpressionEvaluator extends expression_1.JavascriptExpressionEvalua
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
_eval(params_1) {
|
|
28
|
-
return __awaiter(this, arguments, void 0, function* (params, referencedNodeDefUuids = new Set()) {
|
|
28
|
+
return __awaiter(this, arguments, void 0, function* (params, referencedNodeDefUuids = new Set(), nodeDateReferencedNodeDefUuids = new Set()) {
|
|
29
29
|
const { expression, user, survey, nodeDef, isContextParent = true, selfReferenceAllowed = true, itemsFilter = false, } = params;
|
|
30
30
|
const nodeDefContext = isContextParent ? (0, nodeDefs_1.getNodeDefParent)({ survey, nodeDef }) : nodeDef;
|
|
31
31
|
const context = {
|
|
@@ -36,6 +36,7 @@ class NodeDefExpressionEvaluator extends expression_1.JavascriptExpressionEvalua
|
|
|
36
36
|
object: nodeDef,
|
|
37
37
|
selfReferenceAllowed,
|
|
38
38
|
referencedNodeDefUuids,
|
|
39
|
+
nodeDateReferencedNodeDefUuids,
|
|
39
40
|
itemsFilter,
|
|
40
41
|
};
|
|
41
42
|
const result = yield this.evaluate(expression, context);
|
|
@@ -59,6 +60,23 @@ class NodeDefExpressionEvaluator extends expression_1.JavascriptExpressionEvalua
|
|
|
59
60
|
return referencedNodeDefUuids;
|
|
60
61
|
});
|
|
61
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Finds the node defs referenced by the expression (see findReferencedNodeDefUuids) and the entity defs
|
|
65
|
+
* whose nodes dates are used in it (nodeDateCreated, nodeDateModified functions).
|
|
66
|
+
*/
|
|
67
|
+
findReferencedNodeDefUuidsWithNodeDates(params) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const referencedNodeDefUuids = new Set();
|
|
70
|
+
const nodeDateReferencedNodeDefUuids = new Set();
|
|
71
|
+
try {
|
|
72
|
+
yield this._eval(params, referencedNodeDefUuids, nodeDateReferencedNodeDefUuids);
|
|
73
|
+
}
|
|
74
|
+
catch (_a) {
|
|
75
|
+
// invalid expression (reported by the expression validator): keep the references found so far
|
|
76
|
+
}
|
|
77
|
+
return { referencedNodeDefUuids, nodeDateReferencedNodeDefUuids };
|
|
78
|
+
});
|
|
79
|
+
}
|
|
62
80
|
evalExpression(params) {
|
|
63
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
82
|
const { result } = yield this._eval(params);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../src/nodeDefExpressionEvaluator/evaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAAiF;AACjF,kDAA8D;AAC9D,0CAAsD;AACtD,wDAA2D;AAC3D,2CAAwD;AAIxD,yDAA6D;AAY7D,gCAAwC,SAAQ,0CAAuD;IACrG;QACE,KAAK,CAAC,sCAA0B,EAAE;YAChC,CAAC,+BAAkB,CAAC,UAAU,CAAC,EAAE,uCAA0B;YAC3D,CAAC,+BAAkB,CAAC,MAAM,CAAC,EAAE,+BAAsB;YACnD,CAAC,+BAAkB,CAAC,IAAI,CAAC,EAAE,oCAAoB;SAChD,CAAC,CAAA;IACJ,CAAC;IAEK,KAAK;6DACT,MAAiC,EACjC,sBAAsB,GAAgB,IAAI,GAAG,EAAE
|
|
1
|
+
{"version":3,"file":"evaluator.js","sourceRoot":"","sources":["../../src/nodeDefExpressionEvaluator/evaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,8CAAiF;AACjF,kDAA8D;AAC9D,0CAAsD;AACtD,wDAA2D;AAC3D,2CAAwD;AAIxD,yDAA6D;AAY7D,gCAAwC,SAAQ,0CAAuD;IACrG;QACE,KAAK,CAAC,sCAA0B,EAAE;YAChC,CAAC,+BAAkB,CAAC,UAAU,CAAC,EAAE,uCAA0B;YAC3D,CAAC,+BAAkB,CAAC,MAAM,CAAC,EAAE,+BAAsB;YACnD,CAAC,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YAC7D,IAAI,CAAC;gBACH,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,sBAAsB,EAAE,8BAA8B,CAAC,CAAA;YAClF,CAAC;uBAAO,CAAC;gBACP,8FAA8F;YAChG,CAAC;YACD,OAAO,EAAE,sBAAsB,EAAE,8BAA8B,EAAE,CAAA;QACnE,CAAC;KAAA;IAEK,cAAc,CAAC,MAAiC;;YACpD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAC3C,OAAO,MAAM,CAAA;QACf,CAAC;KAAA;CACF","sourcesContent":["import { ArenaUser } from '../auth'\nimport { ExpressionNodeType, JavascriptExpressionEvaluator } from '../expression'\nimport { NodeDefIdentifierEvaluator } from './node/identifier'\nimport { NodeDefMemberEvaluator } from './node/member'\nimport { NodeDefThisEvaluator } from './node/thisEvaluator'\nimport { nodeDefExpressionFunctions } from './functions'\nimport { NodeDefExpressionContext } from './context'\nimport { ArenaNodeDef } from '../nodeDef/nodeDef'\nimport { ArenaSurvey } from '../survey'\nimport { getNodeDefParent } from '../survey/surveys/nodeDefs'\n\nexport type ExpressionEvaluatorParams = {\n expression: string\n user?: ArenaUser\n survey: ArenaSurvey\n nodeDef: ArenaNodeDef<any>\n isContextParent?: boolean\n selfReferenceAllowed?: boolean\n itemsFilter?: boolean\n}\n\nexport class NodeDefExpressionEvaluator extends JavascriptExpressionEvaluator<NodeDefExpressionContext> {\n constructor() {\n super(nodeDefExpressionFunctions, {\n [ExpressionNodeType.Identifier]: NodeDefIdentifierEvaluator,\n [ExpressionNodeType.Member]: NodeDefMemberEvaluator,\n [ExpressionNodeType.This]: NodeDefThisEvaluator,\n })\n }\n\n async _eval(\n params: ExpressionEvaluatorParams,\n referencedNodeDefUuids: Set<string> = new Set(),\n nodeDateReferencedNodeDefUuids: Set<string> = new Set()\n ): Promise<{ result: any; referencedNodeDefUuids: Set<string> }> {\n const {\n expression,\n user,\n survey,\n nodeDef,\n isContextParent = true,\n selfReferenceAllowed = true,\n itemsFilter = false,\n } = params\n\n const nodeDefContext = isContextParent ? getNodeDefParent({ survey, nodeDef }) : nodeDef\n\n const context: NodeDefExpressionContext = {\n user,\n survey,\n nodeDefCurrent: nodeDef,\n nodeDefContext,\n object: nodeDef,\n selfReferenceAllowed,\n referencedNodeDefUuids,\n nodeDateReferencedNodeDefUuids,\n itemsFilter,\n }\n const result = await this.evaluate(expression, context)\n return { result, referencedNodeDefUuids }\n }\n\n /**\n * Finds the node defs referenced by the expression.\n * If the evaluation fails, the node defs referenced before the error are returned: an empty set would drop\n * all the dependencies of the expression.\n */\n async findReferencedNodeDefUuids(params: ExpressionEvaluatorParams): Promise<Set<string>> {\n const referencedNodeDefUuids: Set<string> = new Set()\n try {\n await this._eval(params, referencedNodeDefUuids)\n } catch {\n // invalid expression (reported by the expression validator): keep the references found so far\n }\n return referencedNodeDefUuids\n }\n\n /**\n * Finds the node defs referenced by the expression (see findReferencedNodeDefUuids) and the entity defs\n * whose nodes dates are used in it (nodeDateCreated, nodeDateModified functions).\n */\n async findReferencedNodeDefUuidsWithNodeDates(\n params: ExpressionEvaluatorParams\n ): Promise<{ referencedNodeDefUuids: Set<string>; nodeDateReferencedNodeDefUuids: Set<string> }> {\n const referencedNodeDefUuids: Set<string> = new Set()\n const nodeDateReferencedNodeDefUuids: Set<string> = new Set()\n try {\n await this._eval(params, referencedNodeDefUuids, nodeDateReferencedNodeDefUuids)\n } catch {\n // invalid expression (reported by the expression validator): keep the references found so far\n }\n return { referencedNodeDefUuids, nodeDateReferencedNodeDefUuids }\n }\n\n async evalExpression(params: ExpressionEvaluatorParams): Promise<any> {\n const { result } = await this._eval(params)\n return result\n }\n}\n"]}
|
|
@@ -10,15 +10,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.nodeDefExpressionFunctions = void 0;
|
|
13
|
+
const appInfos_1 = require("../app/appInfos");
|
|
13
14
|
const auth_1 = require("../auth");
|
|
14
15
|
const error_1 = require("../error");
|
|
15
16
|
const extraProps_1 = require("../extraProp/extraProps");
|
|
16
17
|
const geo_1 = require("../geo");
|
|
17
18
|
const language_1 = require("../language");
|
|
19
|
+
const nodeDef_1 = require("../nodeDef");
|
|
18
20
|
const nodeDefs_1 = require("../survey/surveys/nodeDefs");
|
|
19
21
|
const refsData_1 = require("../survey/surveys/refsData");
|
|
20
22
|
const surveysGetters_1 = require("../survey/surveys/surveysGetters");
|
|
21
23
|
const utils_1 = require("../utils");
|
|
24
|
+
const validatorErrorKeys_1 = require("../validation/validatorErrorKeys");
|
|
22
25
|
const sampleGeoJsonPolygon = {
|
|
23
26
|
type: 'Feature',
|
|
24
27
|
geometry: {
|
|
@@ -90,6 +93,24 @@ const distanceToAreaOfInterestBoundary = (params) => __awaiter(void 0, void 0, v
|
|
|
90
93
|
return null;
|
|
91
94
|
return geo_1.Points.distanceToPolygonBoundary(point, areaOfInterest, (0, surveysGetters_1.getSRSIndex)(context.survey));
|
|
92
95
|
});
|
|
96
|
+
/**
|
|
97
|
+
* Node date functions (nodeDateCreated, nodeDateModified) at node def level:
|
|
98
|
+
* the node def passed as argument is a dependency of the expression.
|
|
99
|
+
* Attributes are referenced like in any other expression (their date modified changes with their value);
|
|
100
|
+
* entities are referenced in the nodeDates dependency graph (their date modified changes when any of their descendants is modified).
|
|
101
|
+
*/
|
|
102
|
+
const nodeDateExecutor = (context) => (nodeDef) => {
|
|
103
|
+
var _a;
|
|
104
|
+
if (!(nodeDef === null || nodeDef === void 0 ? void 0 : nodeDef.uuid))
|
|
105
|
+
return null;
|
|
106
|
+
const { nodeDefCurrent, selfReferenceAllowed, referencedNodeDefUuids, nodeDateReferencedNodeDefUuids } = context;
|
|
107
|
+
if (!selfReferenceAllowed && nodeDef.uuid === (nodeDefCurrent === null || nodeDefCurrent === void 0 ? void 0 : nodeDefCurrent.uuid)) {
|
|
108
|
+
throw new error_1.SystemError(validatorErrorKeys_1.ValidatorErrorKeys.expressions.cannotUseCurrentNode, { name: (_a = nodeDef.props) === null || _a === void 0 ? void 0 : _a.name });
|
|
109
|
+
}
|
|
110
|
+
const uuids = nodeDef_1.NodeDefs.isEntity(nodeDef) ? nodeDateReferencedNodeDefUuids : referencedNodeDefUuids;
|
|
111
|
+
uuids === null || uuids === void 0 ? void 0 : uuids.add(nodeDef.uuid);
|
|
112
|
+
return null;
|
|
113
|
+
};
|
|
93
114
|
const geoDistanceExecutor = (context) => (coordinateFrom, coordinateTo) => {
|
|
94
115
|
const { survey } = context;
|
|
95
116
|
const srsIndex = (0, surveysGetters_1.getSRSIndex)(survey);
|
|
@@ -98,6 +119,26 @@ const geoDistanceExecutor = (context) => (coordinateFrom, coordinateTo) => {
|
|
|
98
119
|
return pointFrom && pointTo ? geo_1.Points.distance(pointFrom, pointTo, srsIndex) : null;
|
|
99
120
|
};
|
|
100
121
|
exports.nodeDefExpressionFunctions = {
|
|
122
|
+
appId: {
|
|
123
|
+
minArity: 0,
|
|
124
|
+
maxArity: 0,
|
|
125
|
+
executor: (context) => () => { var _a; var _b; return (_b = (_a = context.appInfo) === null || _a === void 0 ? void 0 : _a.appId) !== null && _b !== void 0 ? _b : null; },
|
|
126
|
+
},
|
|
127
|
+
appIdLabel: {
|
|
128
|
+
minArity: 0,
|
|
129
|
+
maxArity: 0,
|
|
130
|
+
executor: (context) => () => { var _a; return (_a = appInfos_1.AppInfos.getLabel(context.appInfo)) !== null && _a !== void 0 ? _a : null; },
|
|
131
|
+
},
|
|
132
|
+
appPlatform: {
|
|
133
|
+
minArity: 0,
|
|
134
|
+
maxArity: 0,
|
|
135
|
+
executor: (context) => () => { var _a; var _b; return (_b = (_a = context.appInfo) === null || _a === void 0 ? void 0 : _a.platform) !== null && _b !== void 0 ? _b : null; },
|
|
136
|
+
},
|
|
137
|
+
appVersion: {
|
|
138
|
+
minArity: 0,
|
|
139
|
+
maxArity: 0,
|
|
140
|
+
executor: (context) => () => { var _a; var _b; return (_b = (_a = context.appInfo) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : null; },
|
|
141
|
+
},
|
|
101
142
|
categoryItemProp: {
|
|
102
143
|
minArity: 3,
|
|
103
144
|
executor: (context) => (categoryName, itemPropName, ...codePaths) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -223,6 +264,18 @@ exports.nodeDefExpressionFunctions = {
|
|
|
223
264
|
evaluateArgsToNodes: true,
|
|
224
265
|
executor: emptyExecutor,
|
|
225
266
|
},
|
|
267
|
+
nodeDateCreated: {
|
|
268
|
+
minArity: 1,
|
|
269
|
+
maxArity: 1,
|
|
270
|
+
evaluateArgsToNodes: true,
|
|
271
|
+
executor: nodeDateExecutor,
|
|
272
|
+
},
|
|
273
|
+
nodeDateModified: {
|
|
274
|
+
minArity: 1,
|
|
275
|
+
maxArity: 1,
|
|
276
|
+
evaluateArgsToNodes: true,
|
|
277
|
+
executor: nodeDateExecutor,
|
|
278
|
+
},
|
|
226
279
|
now: {
|
|
227
280
|
minArity: 0,
|
|
228
281
|
maxArity: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/nodeDefExpressionEvaluator/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kCAA+B;AAE/B,oCAAuD;AAEvD,wDAAoD;AACpD,gCAAgE;AAChE,0CAAkD;AAElD,yDAA6D;AAC7D,yDAAuF;AACvF,qEAMyC;AAEzC,oCAAkD;AAGlD,MAAM,oBAAoB,GAAG;IAC3B,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE;QACR,IAAI,EAAE,SAAS;QACf,WAAW,EAAE;YACX;gBACE,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,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E,IAAI,GAAA;KAC1E;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC,OAAiC,EAAE,EAAE,CAAC,CAAC,QAAgB,EAAE,EAAE;YACpE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;YAChC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAA;YACtC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;YACnC,MAAM,kBAAkB,GAAG,YAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAA;YACxE,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAC/F,CAAC;KACF;CACF,CAAA","sourcesContent":["import { Users } from '../auth'\nimport { ArenaCategoryItem } from '../category'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaExpressionFunctions } from '../expression'\nimport { ExtraProps } from '../extraProp/extraProps'\nimport { ArenaAreaOfInterest, ArenaPoint, Points } from '../geo'\nimport { LanguagesISO639part2 } from '../language'\nimport { ArenaRecord } from '../record'\nimport { getNodeDefParent } from '../survey/surveys/nodeDefs'\nimport { getCategoryItemByCodePaths, getTaxonByCode } from '../survey/surveys/refsData'\nimport {\n getAreaOfInterestByName,\n getAreasOfInterest,\n getCategoryByName,\n getSRSIndex,\n getTaxonomyByName,\n} from '../survey/surveys/surveysGetters'\nimport { ArenaTaxon } from '../taxonomy'\nimport { Dates, Numbers, Objects } from '../utils'\nimport { NodeDefExpressionContext } from './context'\n\nconst sampleGeoJsonPolygon = {\n type: 'Feature',\n geometry: {\n type: 'Polygon',\n coordinates: [\n [\n [100.0, 0.0],\n [101.0, 0.0],\n [101.0, 1.0],\n [100.0, 1.0],\n [100.0, 0.0],\n ],\n ],\n },\n}\n\nconst isNotValidString = (value: string): boolean => Objects.isEmpty(value) || typeof value !== 'string'\n\nconst emptyExecutor = (_context: NodeDefExpressionContext) => () => null\n\nconst isUsingDraftProps = (context: NodeDefExpressionContext) => {\n // use draft props when validating expression or previewing record\n const record: ArenaRecord = (context as any).record\n return !record || !!record.preview\n}\n\nconst getOrFetchCategoryItem = async (params: {\n context: NodeDefExpressionContext\n categoryUuid: string\n codePaths: string[]\n}): Promise<ArenaCategoryItem | undefined> => {\n const { context, categoryUuid, codePaths } = params\n // if any code path is empty, return null (no category item can be found)\n if (Objects.isEmpty(codePaths) || codePaths.some(Objects.isEmpty)) {\n return undefined\n }\n const { survey, categoryItemProvider } = context\n const categoryItem = getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n const draft = isUsingDraftProps(context)\n return categoryItem ?? categoryItemProvider?.getItemByCodePaths({ survey, categoryUuid, codePaths, draft })\n}\n\nconst getOrFetchTaxon = async (params: {\n context: NodeDefExpressionContext\n taxonomyUuid: string\n taxonCode: string\n}): Promise<ArenaTaxon | undefined> => {\n const { context, taxonomyUuid, taxonCode } = params\n if (typeof taxonCode !== 'string' && typeof taxonCode !== 'number') {\n return undefined // node def expression validator could call it passing a node def object\n }\n // if taxonCode is empty, return undefined\n if (Objects.isEmpty(taxonCode)) {\n return undefined\n }\n const { survey, taxonProvider } = context\n const taxon = getTaxonByCode({ survey, taxonomyUuid, taxonCode })\n // fetch draft props when validating expression or previewing record\n const record: ArenaRecord = (context as any).record\n const draft = !record || !!record.preview\n return taxon ?? taxonProvider?.getTaxonByCode({ survey, taxonomyUuid, taxonCode, draft })\n}\n\nconst fetchAreaOfInterest = async (params: {\n context: NodeDefExpressionContext\n name: string\n}): Promise<ArenaAreaOfInterest | undefined> => {\n const { context, name } = params\n const { survey, areaOfInterestProvider } = context\n if (!areaOfInterestProvider || !getAreaOfInterestByName({ survey, name })) return undefined\n return areaOfInterestProvider.getAreaOfInterest({ survey, name })\n}\n\n// expression validation (no record): a literal area name must be defined in the survey\nconst validateAreaOfInterestName = (params: { context: NodeDefExpressionContext; name: unknown }): void => {\n const { context, name } = params\n const record: ArenaRecord = (context as any).record\n if (!record && typeof name === 'string' && !getAreaOfInterestByName({ survey: context.survey, name })) {\n throw new SystemError(SystemErrorKeys.expression.areaOfInterestNotFound, { name })\n }\n}\n\nconst distanceToAreaOfInterestBoundary = async (params: {\n context: NodeDefExpressionContext\n point: ArenaPoint\n name: string\n}): Promise<number | null> => {\n const { context, point, name } = params\n const areaOfInterest = await fetchAreaOfInterest({ context, name })\n if (!areaOfInterest) return null\n return Points.distanceToPolygonBoundary(point, areaOfInterest, getSRSIndex(context.survey))\n}\n\nconst geoDistanceExecutor =\n (context: NodeDefExpressionContext) =>\n (coordinateFrom: ArenaPoint | string, coordinateTo: ArenaPoint | string): number | null => {\n const { survey } = context\n const srsIndex = getSRSIndex(survey)\n\n const pointFrom = Points.parse(coordinateFrom)\n const pointTo = Points.parse(coordinateTo)\n\n return pointFrom && pointTo ? Points.distance(pointFrom, pointTo, srsIndex) : null\n }\n\nexport const nodeDefExpressionFunctions: ArenaExpressionFunctions<NodeDefExpressionContext> = {\n categoryItemProp: {\n minArity: 3,\n executor:\n (context: NodeDefExpressionContext) =>\n async (categoryName: string, itemPropName: string, ...codePaths: string[]): Promise<any> => {\n const { survey } = context\n\n if (Objects.isEmpty(categoryName) || Objects.isEmpty(itemPropName) || Objects.isEmpty(codePaths))\n throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters)\n\n const category = getCategoryByName({ survey, categoryName })\n if (!category) throw new SystemError(SystemErrorKeys.expression.invalidCategoryName, { name: categoryName })\n\n const { itemExtraDef } = category.props\n const extraPropDef =\n itemExtraDef && Object.hasOwn(itemExtraDef, itemPropName) ? itemExtraDef[itemPropName] : undefined\n if (!extraPropDef)\n throw new SystemError(SystemErrorKeys.expression.invalidCategoryExtraProp, { propName: itemPropName })\n\n const { uuid: categoryUuid } = category\n const categoryItem = await getOrFetchCategoryItem({ context, categoryUuid, codePaths })\n if (!categoryItem) return null\n\n const value = categoryItem.props.extra?.[itemPropName]\n return ExtraProps.convertValue({ survey, extraPropDef, value })\n },\n },\n count: {\n minArity: 1,\n maxArity: 1,\n executor:\n (_context: NodeDefExpressionContext) =>\n (_nodeSet): number =>\n 1,\n },\n dateTimeDiff: {\n minArity: 4,\n maxArity: 4,\n executor:\n (_context: NodeDefExpressionContext) =>\n (date1: string, time1: string, date2: string, time2: string): number | null => {\n if (isNotValidString(date1) || isNotValidString(time1) || isNotValidString(date2) || isNotValidString(time2))\n return null\n // computed in UTC: in the local time zone of the machine a DST change between the 2 dates would alter the result\n const toUtcMinutes = (date: string, time: string): number => {\n const [year, month, day] = date.split('-').map(Number)\n const [hours, minutes] = time.split(':').map(Number)\n return Date.UTC(year, month - 1, day, hours, minutes) / 60000\n }\n const diff = toUtcMinutes(date1, time1) - toUtcMinutes(date2, time2)\n return Number.isNaN(diff) ? null : diff\n },\n },\n // deprecated, use geoDistance instead\n distance: { minArity: 2, maxArity: 2, executor: geoDistanceExecutor },\n first: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: emptyExecutor,\n },\n geoCoordinateAtDistance: {\n minArity: 3,\n maxArity: 3,\n executor:\n (context: NodeDefExpressionContext) =>\n (coordinate: ArenaPoint | string, distanceMeters: number, bearingDeg: number): ArenaPoint | null => {\n // validate parameters\n const origin = Points.parse(coordinate)\n if (!origin) return null\n\n const distanceMetersNumber = Number(distanceMeters)\n const bearingDegNumber = Number(bearingDeg)\n if (!Number.isFinite(distanceMetersNumber) || distanceMetersNumber < 0 || !Number.isFinite(bearingDegNumber)) {\n return null\n }\n\n const { survey } = context\n const srsIndex = getSRSIndex(survey)\n\n return Points.pointAtDistance({\n origin,\n distanceMeters: distanceMetersNumber,\n bearingDeg: bearingDegNumber,\n srsIndex,\n })\n },\n },\n geoDistance: { minArity: 2, maxArity: 2, executor: geoDistanceExecutor },\n geoAOIContaining: {\n minArity: 1,\n maxArity: 1,\n executor:\n (context: NodeDefExpressionContext) =>\n async (coordinate: ArenaPoint | string): Promise<string | null> => {\n const point = Points.parse(coordinate)\n if (!point || !context.areaOfInterestProvider) return null\n // the survey order is the priority of overlapping areas\n for (const { name } of getAreasOfInterest(context.survey)) {\n const distance = await distanceToAreaOfInterestBoundary({ context, point, name }) // NOSONAR\n if (distance !== null && distance <= 0) return name\n }\n return null\n },\n },\n geoDistanceToAOIBoundary: {\n minArity: 2,\n maxArity: 2,\n executor:\n (context: NodeDefExpressionContext) =>\n async (coordinate: ArenaPoint | string, name: string): Promise<number | null> => {\n validateAreaOfInterestName({ context, name })\n const point = Points.parse(coordinate)\n if (!point || typeof name !== 'string') return null\n return distanceToAreaOfInterestBoundary({ context, point, name })\n },\n },\n geoPolygon: {\n minArity: 1,\n evaluateArgsToNodes: true,\n executor: () => () => sampleGeoJsonPolygon,\n },\n includes: {\n minArity: 2,\n maxArity: 2,\n evaluateArgsToNodes: false,\n executor:\n () =>\n (items: any, value: any): boolean =>\n Array.isArray(items) && items.map(String).includes(String(value)),\n },\n index: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: () => () => -1,\n },\n last: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: emptyExecutor,\n },\n now: {\n minArity: 0,\n maxArity: 0,\n evaluateToNode: false,\n executor: () => () => Dates.nowFormattedForStorage(),\n },\n numberToWords: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor:\n (context: NodeDefExpressionContext) =>\n (value: any): string | null => {\n if (Objects.isEmpty(value)) return null\n return Numbers.toWords(value, context.lang)\n },\n },\n parent: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n evaluateToNode: true,\n executor: (context: NodeDefExpressionContext) => (nodeDef) => {\n const { survey } = context\n return getNodeDefParent({ survey, nodeDef })\n },\n },\n prevCycleValue: {\n minArity: 1,\n maxArity: 1,\n executor: emptyExecutor,\n },\n prevCycleValues: {\n minArity: 1,\n maxArity: 1,\n executor: emptyExecutor,\n },\n recordCycle: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordDateCreated: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordDateLastModified: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordOwnerEmail: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordOwnerName: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordOwnerRole: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n sum: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (_context: NodeDefExpressionContext) => (_nodeSet) => 1,\n },\n taxonProp: {\n minArity: 3,\n maxArity: 3,\n executor:\n (context: NodeDefExpressionContext) => async (taxonomyName: string, propName: string, taxonCode: string) => {\n if (Objects.isEmpty(taxonomyName) || Objects.isEmpty(propName))\n throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters)\n if (Objects.isEmpty(taxonCode)) return null\n\n const { survey } = context\n const taxonomy = getTaxonomyByName({ survey, taxonomyName })\n if (!taxonomy) throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName })\n\n const { extraPropsDefs } = taxonomy.props\n const extraPropDef =\n extraPropsDefs && Object.hasOwn(extraPropsDefs, propName) ? extraPropsDefs[propName] : undefined\n if (!extraPropDef) throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyExtraProp, { propName })\n\n const taxon = await getOrFetchTaxon({ context, taxonomyUuid: taxonomy.uuid, taxonCode })\n if (!taxon) return null\n\n const value = taxon.props.extra?.[propName]\n return ExtraProps.convertValue({ survey, extraPropDef, value })\n },\n },\n taxonVernacularName: {\n minArity: 3,\n maxArity: 3,\n executor:\n (context: NodeDefExpressionContext) =>\n async (taxonomyName: string, vernacularLangCode: string, taxonCode: string) => {\n if (Objects.isEmpty(taxonomyName) || Objects.isEmpty(vernacularLangCode))\n throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters)\n if (Objects.isEmpty(taxonCode)) return null\n\n const { survey } = context\n const taxonomy = getTaxonomyByName({ survey, taxonomyName })\n if (!taxonomy) throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName })\n\n if (!Object.hasOwn(LanguagesISO639part2, vernacularLangCode)) {\n throw new SystemError(SystemErrorKeys.expression.invalidTaxonVernacularNameLanguageCode, {\n vernacularLangCode,\n })\n }\n\n const taxon = await getOrFetchTaxon({ context, taxonomyUuid: taxonomy.uuid, taxonCode })\n if (!taxon) return null\n\n const vernacularNameArray = taxon.vernacularNames?.[vernacularLangCode]\n // consider first vernacular name object only\n const firstVernacularName = vernacularNameArray?.[0]\n return firstVernacularName?.props?.name\n },\n },\n unique: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (_context: NodeDefExpressionContext) => (_nodeSet) => [],\n },\n userEmail: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => context.user?.email,\n },\n userIsRecordOwner: {\n minArity: 0,\n maxArity: 0,\n executor: (_context: NodeDefExpressionContext) => () => false,\n },\n userName: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => context.user?.name,\n },\n userProp: {\n minArity: 1,\n maxArity: 1,\n executor: (context: NodeDefExpressionContext) => (propName: string) => {\n const { user, survey } = context\n if (!survey || !user) return undefined\n const { uuid: surveyUuid } = survey\n const combinedExtraProps = Users.getCombinedExtraProps(surveyUuid)(user)\n return Object.hasOwn(combinedExtraProps, propName) ? combinedExtraProps[propName] : undefined\n },\n },\n}\n"]}
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/nodeDefExpressionEvaluator/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAA0C;AAC1C,kCAA+B;AAE/B,oCAAuD;AAEvD,wDAAoD;AACpD,g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AAA;YAChC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAA;YACtC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;YACnC,MAAM,kBAAkB,GAAG,YAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAA;YACxE,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAC/F,CAAC;KACF;CACF,CAAA","sourcesContent":["import { AppInfos } from '../app/appInfos'\nimport { Users } from '../auth'\nimport { ArenaCategoryItem } from '../category'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ArenaExpressionFunctions } from '../expression'\nimport { ExtraProps } from '../extraProp/extraProps'\nimport { ArenaAreaOfInterest, ArenaPoint, Points } from '../geo'\nimport { LanguagesISO639part2 } from '../language'\nimport { ArenaAnyNodeDef, NodeDefs } from '../nodeDef'\nimport { ArenaRecord } from '../record'\nimport { getNodeDefParent } from '../survey/surveys/nodeDefs'\nimport { getCategoryItemByCodePaths, getTaxonByCode } from '../survey/surveys/refsData'\nimport {\n getAreaOfInterestByName,\n getAreasOfInterest,\n getCategoryByName,\n getSRSIndex,\n getTaxonomyByName,\n} from '../survey/surveys/surveysGetters'\nimport { ArenaTaxon } from '../taxonomy'\nimport { Dates, Numbers, Objects } from '../utils'\nimport { ValidatorErrorKeys } from '../validation/validatorErrorKeys'\nimport { NodeDefExpressionContext } from './context'\n\nconst sampleGeoJsonPolygon = {\n type: 'Feature',\n geometry: {\n type: 'Polygon',\n coordinates: [\n [\n [100.0, 0.0],\n [101.0, 0.0],\n [101.0, 1.0],\n [100.0, 1.0],\n [100.0, 0.0],\n ],\n ],\n },\n}\n\nconst isNotValidString = (value: string): boolean => Objects.isEmpty(value) || typeof value !== 'string'\n\nconst emptyExecutor = (_context: NodeDefExpressionContext) => () => null\n\nconst isUsingDraftProps = (context: NodeDefExpressionContext) => {\n // use draft props when validating expression or previewing record\n const record: ArenaRecord = (context as any).record\n return !record || !!record.preview\n}\n\nconst getOrFetchCategoryItem = async (params: {\n context: NodeDefExpressionContext\n categoryUuid: string\n codePaths: string[]\n}): Promise<ArenaCategoryItem | undefined> => {\n const { context, categoryUuid, codePaths } = params\n // if any code path is empty, return null (no category item can be found)\n if (Objects.isEmpty(codePaths) || codePaths.some(Objects.isEmpty)) {\n return undefined\n }\n const { survey, categoryItemProvider } = context\n const categoryItem = getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n const draft = isUsingDraftProps(context)\n return categoryItem ?? categoryItemProvider?.getItemByCodePaths({ survey, categoryUuid, codePaths, draft })\n}\n\nconst getOrFetchTaxon = async (params: {\n context: NodeDefExpressionContext\n taxonomyUuid: string\n taxonCode: string\n}): Promise<ArenaTaxon | undefined> => {\n const { context, taxonomyUuid, taxonCode } = params\n if (typeof taxonCode !== 'string' && typeof taxonCode !== 'number') {\n return undefined // node def expression validator could call it passing a node def object\n }\n // if taxonCode is empty, return undefined\n if (Objects.isEmpty(taxonCode)) {\n return undefined\n }\n const { survey, taxonProvider } = context\n const taxon = getTaxonByCode({ survey, taxonomyUuid, taxonCode })\n // fetch draft props when validating expression or previewing record\n const record: ArenaRecord = (context as any).record\n const draft = !record || !!record.preview\n return taxon ?? taxonProvider?.getTaxonByCode({ survey, taxonomyUuid, taxonCode, draft })\n}\n\nconst fetchAreaOfInterest = async (params: {\n context: NodeDefExpressionContext\n name: string\n}): Promise<ArenaAreaOfInterest | undefined> => {\n const { context, name } = params\n const { survey, areaOfInterestProvider } = context\n if (!areaOfInterestProvider || !getAreaOfInterestByName({ survey, name })) return undefined\n return areaOfInterestProvider.getAreaOfInterest({ survey, name })\n}\n\n// expression validation (no record): a literal area name must be defined in the survey\nconst validateAreaOfInterestName = (params: { context: NodeDefExpressionContext; name: unknown }): void => {\n const { context, name } = params\n const record: ArenaRecord = (context as any).record\n if (!record && typeof name === 'string' && !getAreaOfInterestByName({ survey: context.survey, name })) {\n throw new SystemError(SystemErrorKeys.expression.areaOfInterestNotFound, { name })\n }\n}\n\nconst distanceToAreaOfInterestBoundary = async (params: {\n context: NodeDefExpressionContext\n point: ArenaPoint\n name: string\n}): Promise<number | null> => {\n const { context, point, name } = params\n const areaOfInterest = await fetchAreaOfInterest({ context, name })\n if (!areaOfInterest) return null\n return Points.distanceToPolygonBoundary(point, areaOfInterest, getSRSIndex(context.survey))\n}\n\n/**\n * Node date functions (nodeDateCreated, nodeDateModified) at node def level:\n * the node def passed as argument is a dependency of the expression.\n * Attributes are referenced like in any other expression (their date modified changes with their value);\n * entities are referenced in the nodeDates dependency graph (their date modified changes when any of their descendants is modified).\n */\nconst nodeDateExecutor =\n (context: NodeDefExpressionContext) =>\n (nodeDef: ArenaAnyNodeDef | null): null => {\n if (!nodeDef?.uuid) return null\n const { nodeDefCurrent, selfReferenceAllowed, referencedNodeDefUuids, nodeDateReferencedNodeDefUuids } = context\n if (!selfReferenceAllowed && nodeDef.uuid === nodeDefCurrent?.uuid) {\n throw new SystemError(ValidatorErrorKeys.expressions.cannotUseCurrentNode, { name: nodeDef.props?.name })\n }\n const uuids = NodeDefs.isEntity(nodeDef) ? nodeDateReferencedNodeDefUuids : referencedNodeDefUuids\n uuids?.add(nodeDef.uuid)\n return null\n }\n\nconst geoDistanceExecutor =\n (context: NodeDefExpressionContext) =>\n (coordinateFrom: ArenaPoint | string, coordinateTo: ArenaPoint | string): number | null => {\n const { survey } = context\n const srsIndex = getSRSIndex(survey)\n\n const pointFrom = Points.parse(coordinateFrom)\n const pointTo = Points.parse(coordinateTo)\n\n return pointFrom && pointTo ? Points.distance(pointFrom, pointTo, srsIndex) : null\n }\n\nexport const nodeDefExpressionFunctions: ArenaExpressionFunctions<NodeDefExpressionContext> = {\n appId: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => context.appInfo?.appId ?? null,\n },\n appIdLabel: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => AppInfos.getLabel(context.appInfo) ?? null,\n },\n appPlatform: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => context.appInfo?.platform ?? null,\n },\n appVersion: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => context.appInfo?.version ?? null,\n },\n categoryItemProp: {\n minArity: 3,\n executor:\n (context: NodeDefExpressionContext) =>\n async (categoryName: string, itemPropName: string, ...codePaths: string[]): Promise<any> => {\n const { survey } = context\n\n if (Objects.isEmpty(categoryName) || Objects.isEmpty(itemPropName) || Objects.isEmpty(codePaths))\n throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters)\n\n const category = getCategoryByName({ survey, categoryName })\n if (!category) throw new SystemError(SystemErrorKeys.expression.invalidCategoryName, { name: categoryName })\n\n const { itemExtraDef } = category.props\n const extraPropDef =\n itemExtraDef && Object.hasOwn(itemExtraDef, itemPropName) ? itemExtraDef[itemPropName] : undefined\n if (!extraPropDef)\n throw new SystemError(SystemErrorKeys.expression.invalidCategoryExtraProp, { propName: itemPropName })\n\n const { uuid: categoryUuid } = category\n const categoryItem = await getOrFetchCategoryItem({ context, categoryUuid, codePaths })\n if (!categoryItem) return null\n\n const value = categoryItem.props.extra?.[itemPropName]\n return ExtraProps.convertValue({ survey, extraPropDef, value })\n },\n },\n count: {\n minArity: 1,\n maxArity: 1,\n executor:\n (_context: NodeDefExpressionContext) =>\n (_nodeSet): number =>\n 1,\n },\n dateTimeDiff: {\n minArity: 4,\n maxArity: 4,\n executor:\n (_context: NodeDefExpressionContext) =>\n (date1: string, time1: string, date2: string, time2: string): number | null => {\n if (isNotValidString(date1) || isNotValidString(time1) || isNotValidString(date2) || isNotValidString(time2))\n return null\n // computed in UTC: in the local time zone of the machine a DST change between the 2 dates would alter the result\n const toUtcMinutes = (date: string, time: string): number => {\n const [year, month, day] = date.split('-').map(Number)\n const [hours, minutes] = time.split(':').map(Number)\n return Date.UTC(year, month - 1, day, hours, minutes) / 60000\n }\n const diff = toUtcMinutes(date1, time1) - toUtcMinutes(date2, time2)\n return Number.isNaN(diff) ? null : diff\n },\n },\n // deprecated, use geoDistance instead\n distance: { minArity: 2, maxArity: 2, executor: geoDistanceExecutor },\n first: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: emptyExecutor,\n },\n geoCoordinateAtDistance: {\n minArity: 3,\n maxArity: 3,\n executor:\n (context: NodeDefExpressionContext) =>\n (coordinate: ArenaPoint | string, distanceMeters: number, bearingDeg: number): ArenaPoint | null => {\n // validate parameters\n const origin = Points.parse(coordinate)\n if (!origin) return null\n\n const distanceMetersNumber = Number(distanceMeters)\n const bearingDegNumber = Number(bearingDeg)\n if (!Number.isFinite(distanceMetersNumber) || distanceMetersNumber < 0 || !Number.isFinite(bearingDegNumber)) {\n return null\n }\n\n const { survey } = context\n const srsIndex = getSRSIndex(survey)\n\n return Points.pointAtDistance({\n origin,\n distanceMeters: distanceMetersNumber,\n bearingDeg: bearingDegNumber,\n srsIndex,\n })\n },\n },\n geoDistance: { minArity: 2, maxArity: 2, executor: geoDistanceExecutor },\n geoAOIContaining: {\n minArity: 1,\n maxArity: 1,\n executor:\n (context: NodeDefExpressionContext) =>\n async (coordinate: ArenaPoint | string): Promise<string | null> => {\n const point = Points.parse(coordinate)\n if (!point || !context.areaOfInterestProvider) return null\n // the survey order is the priority of overlapping areas\n for (const { name } of getAreasOfInterest(context.survey)) {\n const distance = await distanceToAreaOfInterestBoundary({ context, point, name }) // NOSONAR\n if (distance !== null && distance <= 0) return name\n }\n return null\n },\n },\n geoDistanceToAOIBoundary: {\n minArity: 2,\n maxArity: 2,\n executor:\n (context: NodeDefExpressionContext) =>\n async (coordinate: ArenaPoint | string, name: string): Promise<number | null> => {\n validateAreaOfInterestName({ context, name })\n const point = Points.parse(coordinate)\n if (!point || typeof name !== 'string') return null\n return distanceToAreaOfInterestBoundary({ context, point, name })\n },\n },\n geoPolygon: {\n minArity: 1,\n evaluateArgsToNodes: true,\n executor: () => () => sampleGeoJsonPolygon,\n },\n includes: {\n minArity: 2,\n maxArity: 2,\n evaluateArgsToNodes: false,\n executor:\n () =>\n (items: any, value: any): boolean =>\n Array.isArray(items) && items.map(String).includes(String(value)),\n },\n index: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: () => () => -1,\n },\n last: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: emptyExecutor,\n },\n nodeDateCreated: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: nodeDateExecutor,\n },\n nodeDateModified: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: nodeDateExecutor,\n },\n now: {\n minArity: 0,\n maxArity: 0,\n evaluateToNode: false,\n executor: () => () => Dates.nowFormattedForStorage(),\n },\n numberToWords: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: false,\n executor:\n (context: NodeDefExpressionContext) =>\n (value: any): string | null => {\n if (Objects.isEmpty(value)) return null\n return Numbers.toWords(value, context.lang)\n },\n },\n parent: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n evaluateToNode: true,\n executor: (context: NodeDefExpressionContext) => (nodeDef) => {\n const { survey } = context\n return getNodeDefParent({ survey, nodeDef })\n },\n },\n prevCycleValue: {\n minArity: 1,\n maxArity: 1,\n executor: emptyExecutor,\n },\n prevCycleValues: {\n minArity: 1,\n maxArity: 1,\n executor: emptyExecutor,\n },\n recordCycle: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordDateCreated: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordDateLastModified: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordOwnerEmail: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordOwnerName: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n recordOwnerRole: {\n minArity: 0,\n maxArity: 0,\n executor: emptyExecutor,\n },\n sum: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (_context: NodeDefExpressionContext) => (_nodeSet) => 1,\n },\n taxonProp: {\n minArity: 3,\n maxArity: 3,\n executor:\n (context: NodeDefExpressionContext) => async (taxonomyName: string, propName: string, taxonCode: string) => {\n if (Objects.isEmpty(taxonomyName) || Objects.isEmpty(propName))\n throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters)\n if (Objects.isEmpty(taxonCode)) return null\n\n const { survey } = context\n const taxonomy = getTaxonomyByName({ survey, taxonomyName })\n if (!taxonomy) throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName })\n\n const { extraPropsDefs } = taxonomy.props\n const extraPropDef =\n extraPropsDefs && Object.hasOwn(extraPropsDefs, propName) ? extraPropsDefs[propName] : undefined\n if (!extraPropDef) throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyExtraProp, { propName })\n\n const taxon = await getOrFetchTaxon({ context, taxonomyUuid: taxonomy.uuid, taxonCode })\n if (!taxon) return null\n\n const value = taxon.props.extra?.[propName]\n return ExtraProps.convertValue({ survey, extraPropDef, value })\n },\n },\n taxonVernacularName: {\n minArity: 3,\n maxArity: 3,\n executor:\n (context: NodeDefExpressionContext) =>\n async (taxonomyName: string, vernacularLangCode: string, taxonCode: string) => {\n if (Objects.isEmpty(taxonomyName) || Objects.isEmpty(vernacularLangCode))\n throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters)\n if (Objects.isEmpty(taxonCode)) return null\n\n const { survey } = context\n const taxonomy = getTaxonomyByName({ survey, taxonomyName })\n if (!taxonomy) throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName })\n\n if (!Object.hasOwn(LanguagesISO639part2, vernacularLangCode)) {\n throw new SystemError(SystemErrorKeys.expression.invalidTaxonVernacularNameLanguageCode, {\n vernacularLangCode,\n })\n }\n\n const taxon = await getOrFetchTaxon({ context, taxonomyUuid: taxonomy.uuid, taxonCode })\n if (!taxon) return null\n\n const vernacularNameArray = taxon.vernacularNames?.[vernacularLangCode]\n // consider first vernacular name object only\n const firstVernacularName = vernacularNameArray?.[0]\n return firstVernacularName?.props?.name\n },\n },\n unique: {\n minArity: 1,\n maxArity: 1,\n evaluateArgsToNodes: true,\n executor: (_context: NodeDefExpressionContext) => (_nodeSet) => [],\n },\n userEmail: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => context.user?.email,\n },\n userIsRecordOwner: {\n minArity: 0,\n maxArity: 0,\n executor: (_context: NodeDefExpressionContext) => () => false,\n },\n userName: {\n minArity: 0,\n maxArity: 0,\n executor: (context: NodeDefExpressionContext) => () => context.user?.name,\n },\n userProp: {\n minArity: 1,\n maxArity: 1,\n executor: (context: NodeDefExpressionContext) => (propName: string) => {\n const { user, survey } = context\n if (!survey || !user) return undefined\n const { uuid: surveyUuid } = survey\n const combinedExtraProps = Users.getCombinedExtraProps(surveyUuid)(user)\n return Object.hasOwn(combinedExtraProps, propName) ? combinedExtraProps[propName] : undefined\n },\n },\n}\n"]}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
+
import { ArenaAppInfo } from '../../app';
|
|
1
2
|
import { ArenaDictionary, TraverseMethod } from '../../common';
|
|
2
3
|
import { ArenaRecordNode, ArenaRecordNodePointer, ArenaRecordNodesMap } from '../../node';
|
|
3
4
|
import { ArenaAnyNodeDef, ArenaNodeDef, ArenaNodeDefCode, ArenaNodeDefCodeProps, NodeDefType } from '../../nodeDef';
|
|
4
5
|
import { ArenaSurvey, SurveyDependencyType } from '../../survey/survey';
|
|
5
6
|
import { ArenaRecord, RecordNodesIndex } from '../record';
|
|
6
7
|
export declare const getCycle: (record: ArenaRecord) => string;
|
|
8
|
+
/**
|
|
9
|
+
* Returns the info about the app that updated the record last (or the one that created it, if never updated with another app).
|
|
10
|
+
*/
|
|
11
|
+
export declare const getAppInfoLast: (record: ArenaRecord) => ArenaAppInfo | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Returns true if the specified app info (id, platform or version) differs from the one of the app that updated the record last.
|
|
14
|
+
* Returns false if no app info is specified (e.g. update not done in an app).
|
|
15
|
+
*/
|
|
16
|
+
export declare const isAppInfoChanged: (appInfo: ArenaAppInfo | undefined) => (record: ArenaRecord) => boolean;
|
|
7
17
|
export declare const getNodes: (record: ArenaRecord) => ArenaDictionary<ArenaRecordNode>;
|
|
8
18
|
export declare const getNodesArray: (record: ArenaRecord) => ArenaRecordNode[];
|
|
9
19
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isInAnalysisStep = exports.getStep = exports.isEmpty = exports.isNodeEmpty = exports.isNodeFilledByUser = exports.getCategoryItemUuid = exports.getAncestorCodePath = exports.getAncestorCodeAttributes = exports.getDependentNodePointers = exports.findEntityWithSameKeysInAnotherRecord = exports.findEntityByKeyValues = exports.getNodeIndex = exports.getAttributeSiblings = exports.getEntitySiblings = exports.getEntityKeyValues = exports.getEntityKeyValuesByDefUuid = exports.getEntityKeyNodes = exports.getEntityKeyNodesByDefUuid = exports.findDescendantOrSelf = exports.visitDescendantsAndSelf = exports.isDescendantOf = exports.getDescendant = exports.getDescendantsOrSelf = exports.getAncestorsAndSelf = exports.getAncestor = exports.findAncestor = exports.visitAncestorsAndSelf = exports.getParentCodeAttribute = exports.getDependentCodeAttributes = exports.isNodeRequired = exports.isNodeVisible = exports.isNodeEditable = exports.isNodeApplicable = exports.getNodesByDefUuid = exports.getParent = exports.getChild = exports.getChildren = exports.getRoot = exports.getNodesByUuids = exports.getNodeByUuid = exports.getNodesIndexOrBuild = exports.getNodesArray = exports.getNodes = exports.getCycle = void 0;
|
|
3
|
+
exports.isInAnalysisStep = exports.getStep = exports.isEmpty = exports.isNodeEmpty = exports.isNodeFilledByUser = exports.getCategoryItemUuid = exports.getAncestorCodePath = exports.getAncestorCodeAttributes = exports.getDependentNodePointers = exports.findEntityWithSameKeysInAnotherRecord = exports.findEntityByKeyValues = exports.getNodeIndex = exports.getAttributeSiblings = exports.getEntitySiblings = exports.getEntityKeyValues = exports.getEntityKeyValuesByDefUuid = exports.getEntityKeyNodes = exports.getEntityKeyNodesByDefUuid = exports.findDescendantOrSelf = exports.visitDescendantsAndSelf = exports.isDescendantOf = exports.getDescendant = exports.getDescendantsOrSelf = exports.getAncestorsAndSelf = exports.getAncestor = exports.findAncestor = exports.visitAncestorsAndSelf = exports.getParentCodeAttribute = exports.getDependentCodeAttributes = exports.isNodeRequired = exports.isNodeVisible = exports.isNodeEditable = exports.isNodeApplicable = exports.getNodesByDefUuid = exports.getParent = exports.getChild = exports.getChildren = exports.getRoot = exports.getNodesByUuids = exports.getNodeByUuid = exports.getNodesIndexOrBuild = exports.getNodesArray = exports.getNodes = exports.isAppInfoChanged = exports.getAppInfoLast = exports.getCycle = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const error_1 = require("../../error");
|
|
6
6
|
const node_1 = require("../../node");
|
|
@@ -15,6 +15,27 @@ const recordNodesIndexUpdater_1 = require("./recordNodesIndexUpdater");
|
|
|
15
15
|
const nodeDefSelfReferences_1 = require("./nodeDefSelfReferences");
|
|
16
16
|
const getCycle = (record) => { var _a; return (_a = record.cycle) !== null && _a !== void 0 ? _a : survey_1.defaultCycle; };
|
|
17
17
|
exports.getCycle = getCycle;
|
|
18
|
+
/**
|
|
19
|
+
* Returns the info about the app that updated the record last (or the one that created it, if never updated with another app).
|
|
20
|
+
*/
|
|
21
|
+
const getAppInfoLast = (record) => { var _a, _b; var _c; return (_c = (_a = record.info) === null || _a === void 0 ? void 0 : _a.modifiedWith) !== null && _c !== void 0 ? _c : (_b = record.info) === null || _b === void 0 ? void 0 : _b.createdWith; };
|
|
22
|
+
exports.getAppInfoLast = getAppInfoLast;
|
|
23
|
+
/**
|
|
24
|
+
* Returns true if the specified app info (id, platform or version) differs from the one of the app that updated the record last.
|
|
25
|
+
* Returns false if no app info is specified (e.g. update not done in an app).
|
|
26
|
+
*/
|
|
27
|
+
const isAppInfoChanged = (appInfo) => (record) => {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
if (!appInfo)
|
|
30
|
+
return false;
|
|
31
|
+
const appInfoLast = (0, exports.getAppInfoLast)(record);
|
|
32
|
+
if (!appInfoLast)
|
|
33
|
+
return true;
|
|
34
|
+
return (appInfoLast.appId !== appInfo.appId ||
|
|
35
|
+
((_a = appInfoLast.platform) !== null && _a !== void 0 ? _a : null) !== ((_b = appInfo.platform) !== null && _b !== void 0 ? _b : null) ||
|
|
36
|
+
appInfoLast.version !== appInfo.version);
|
|
37
|
+
};
|
|
38
|
+
exports.isAppInfoChanged = isAppInfoChanged;
|
|
18
39
|
const getNodes = (record) => { var _a; return (_a = record.nodes) !== null && _a !== void 0 ? _a : {}; };
|
|
19
40
|
exports.getNodes = getNodes;
|
|
20
41
|
const getNodesArray = (record) => Object.values((0, exports.getNodes)(record));
|