@openforis/arena-core 2.18.0 → 2.18.2
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/esm/expression/javascript/global.js +2 -0
- package/dist/esm/expression/javascript/global.js.map +1 -1
- package/dist/esm/expression/javascript/node/call.js +23 -4
- package/dist/esm/expression/javascript/node/call.js.map +1 -1
- package/dist/esm/expression/javascript/node/identifier.js +3 -3
- package/dist/esm/expression/javascript/node/identifier.js.map +1 -1
- package/dist/esm/nodeDefExpressionEvaluator/functions.js +10 -8
- package/dist/esm/nodeDefExpressionEvaluator/functions.js.map +1 -1
- package/dist/esm/record/_records/recordGetters.js +6 -0
- package/dist/esm/record/_records/recordGetters.js.map +1 -1
- package/dist/esm/record/_records/recordUpdater.js +2 -2
- package/dist/esm/record/_records/recordUpdater.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesDeleter.js +1 -2
- package/dist/esm/record/recordNodesUpdater/recordNodesDeleter.js.map +1 -1
- package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js +3 -2
- package/dist/esm/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
- package/dist/expression/javascript/global.d.ts +1 -0
- package/dist/expression/javascript/global.js +4 -1
- package/dist/expression/javascript/global.js.map +1 -1
- package/dist/expression/javascript/node/call.js +22 -3
- package/dist/expression/javascript/node/call.js.map +1 -1
- package/dist/expression/javascript/node/identifier.js +2 -2
- package/dist/expression/javascript/node/identifier.js.map +1 -1
- package/dist/nodeDefExpressionEvaluator/functions.js +10 -8
- package/dist/nodeDefExpressionEvaluator/functions.js.map +1 -1
- package/dist/record/_records/recordGetters.d.ts +6 -1
- package/dist/record/_records/recordGetters.js +8 -1
- package/dist/record/_records/recordGetters.js.map +1 -1
- package/dist/record/_records/recordUpdater.js +2 -2
- package/dist/record/_records/recordUpdater.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodesDeleter.js +1 -2
- package/dist/record/recordNodesUpdater/recordNodesDeleter.js.map +1 -1
- package/dist/record/recordNodesUpdater/recordNodesUpdater.js +3 -2
- package/dist/record/recordNodesUpdater/recordNodesUpdater.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,6 +10,8 @@ const globalObjectsDictionary = {
|
|
|
10
10
|
const globalObjectsArray = Object.values(globalObjectsDictionary);
|
|
11
11
|
// properties leading to Object, Function or the prototypes would let an expression run arbitrary code
|
|
12
12
|
export const isForbiddenPropertyName = (name) => name === 'constructor' || name === 'prototype' || name.startsWith('__');
|
|
13
|
+
// Object and Function (e.g. returned by a function or found as a property value) give access to the same capabilities
|
|
14
|
+
export const isForbiddenValue = (value) => value === Object || value === Function;
|
|
13
15
|
export const getGlobalObjectProperty = (name, object) => {
|
|
14
16
|
const globalObject = globalObjectsDictionary[name];
|
|
15
17
|
if (globalObject) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../../src/expression/javascript/global.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE1D,MAAM,uBAAuB,GAAoB;IAC/C,KAAK;IACL,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,MAAM;CACP,CAAA;AACD,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAA;AAEjE,sGAAsG;AACtG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAW,EAAE,CAC/D,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAEzE,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAE,MAAW,EAAO,EAAE;IACxE,MAAM,YAAY,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;IAClD,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAA;IACrB,CAAC;IACD,IAAI,MAAM,IAAI,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAEzE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QAC/E,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { Dictionary } from '../../common'\nimport { SystemError, SystemErrorKeys } from '../../error'\n\nconst globalObjectsDictionary: Dictionary<any> = {\n Array,\n Boolean,\n Date,\n Math,\n Number,\n String,\n}\nconst globalObjectsArray = Object.values(globalObjectsDictionary)\n\n// properties leading to Object, Function or the prototypes would let an expression run arbitrary code\nexport const isForbiddenPropertyName = (name: string): boolean =>\n name === 'constructor' || name === 'prototype' || name.startsWith('__')\n\nexport const getGlobalObjectProperty = (name: string, object: any): any => {\n const globalObject = globalObjectsDictionary[name]\n if (globalObject) {\n return globalObject\n }\n if (object && globalObjectsArray.includes(object)) {\n const property = isForbiddenPropertyName(name) ? undefined : object[name]\n\n if (!property) {\n throw new SystemError(SystemErrorKeys.expression.undefinedFunction, { name })\n }\n return property\n }\n return null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../../src/expression/javascript/global.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE1D,MAAM,uBAAuB,GAAoB;IAC/C,KAAK;IACL,OAAO;IACP,IAAI;IACJ,IAAI;IACJ,MAAM;IACN,MAAM;CACP,CAAA;AACD,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,uBAAuB,CAAC,CAAA;AAEjE,sGAAsG;AACtG,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAW,EAAE,CAC/D,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAEzE,sHAAsH;AACtH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAU,EAAW,EAAE,CAAC,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,CAAA;AAE/F,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAE,MAAW,EAAO,EAAE;IACxE,MAAM,YAAY,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAA;IAClD,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,YAAY,CAAA;IACrB,CAAC;IACD,IAAI,MAAM,IAAI,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,MAAM,QAAQ,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAEzE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;QAC/E,CAAC;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { Dictionary } from '../../common'\nimport { SystemError, SystemErrorKeys } from '../../error'\n\nconst globalObjectsDictionary: Dictionary<any> = {\n Array,\n Boolean,\n Date,\n Math,\n Number,\n String,\n}\nconst globalObjectsArray = Object.values(globalObjectsDictionary)\n\n// properties leading to Object, Function or the prototypes would let an expression run arbitrary code\nexport const isForbiddenPropertyName = (name: string): boolean =>\n name === 'constructor' || name === 'prototype' || name.startsWith('__')\n\n// Object and Function (e.g. returned by a function or found as a property value) give access to the same capabilities\nexport const isForbiddenValue = (value: any): boolean => value === Object || value === Function\n\nexport const getGlobalObjectProperty = (name: string, object: any): any => {\n const globalObject = globalObjectsDictionary[name]\n if (globalObject) {\n return globalObject\n }\n if (object && globalObjectsArray.includes(object)) {\n const property = isForbiddenPropertyName(name) ? undefined : object[name]\n\n if (!property) {\n throw new SystemError(SystemErrorKeys.expression.undefinedFunction, { name })\n }\n return property\n }\n return null\n}\n"]}
|
|
@@ -10,11 +10,26 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { SystemError, SystemErrorKeys } from '../../../error';
|
|
11
11
|
import { ExpressionNodeEvaluator, ExpressionNodeType, } from '../../node';
|
|
12
12
|
import { getGlobalObjectProperty } from '../global';
|
|
13
|
-
import { REG_EXP_INPUT_MAX_LENGTH } from '../regExpSafety';
|
|
13
|
+
import { hasNestedQuantifiers, REG_EXP_INPUT_MAX_LENGTH } from '../regExpSafety';
|
|
14
|
+
// String functions converting a string argument into a regular expression (replace, replaceAll and split don't)
|
|
15
|
+
const stringFunctionsWithRegExpArgument = new Set(['match', 'matchAll', 'search']);
|
|
16
|
+
// e.g. text.match('(a+)+$'): the string pattern is checked like a regular expression literal
|
|
17
|
+
const isRegExpStringPatternCall = (callee, args) => {
|
|
18
|
+
const { computed, property } = callee;
|
|
19
|
+
return (!computed &&
|
|
20
|
+
property.type === ExpressionNodeType.Identifier &&
|
|
21
|
+
stringFunctionsWithRegExpArgument.has(property.name) &&
|
|
22
|
+
typeof args[0] === 'string');
|
|
23
|
+
};
|
|
24
|
+
const checkRegExpStringPattern = (pattern) => {
|
|
25
|
+
if (hasNestedQuantifiers(pattern)) {
|
|
26
|
+
throw new SystemError(SystemErrorKeys.expression.unsafeRegularExpression, { pattern });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
14
29
|
// e.g. /.../.test(text) or text.match(/.../): the time taken by a regular expression grows with the input length
|
|
15
|
-
const checkRegExpInputLength = (fnObject, args) => {
|
|
30
|
+
const checkRegExpInputLength = (fnObject, args, regExpStringPattern) => {
|
|
16
31
|
const values = [fnObject, ...args];
|
|
17
|
-
if (!values.some((value) => value instanceof RegExp))
|
|
32
|
+
if (!regExpStringPattern && !values.some((value) => value instanceof RegExp))
|
|
18
33
|
return;
|
|
19
34
|
const inputTooLong = values.find((value) => typeof value === 'string' && value.length > REG_EXP_INPUT_MAX_LENGTH);
|
|
20
35
|
if (inputTooLong !== undefined) {
|
|
@@ -49,7 +64,11 @@ export class CallEvaluator extends ExpressionNodeEvaluator {
|
|
|
49
64
|
const fnObject = yield this.evaluator.evaluateNode(calleeObj, this.context);
|
|
50
65
|
const argsEvaluated = yield Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, this.context)));
|
|
51
66
|
const args = argsEvaluated.flat();
|
|
52
|
-
|
|
67
|
+
const regExpStringPattern = isRegExpStringPatternCall(callee, args);
|
|
68
|
+
if (regExpStringPattern) {
|
|
69
|
+
checkRegExpStringPattern(args[0]);
|
|
70
|
+
}
|
|
71
|
+
checkRegExpInputLength(fnObject, args, regExpStringPattern);
|
|
53
72
|
return fn.call(fnObject, ...args);
|
|
54
73
|
}
|
|
55
74
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../../../../src/expression/javascript/node/call.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAG7D,OAAO,EAEL,uBAAuB,EACvB,kBAAkB,GAGnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,iHAAiH;AACjH,MAAM,sBAAsB,GAAG,CAAC,QAAa,EAAE,IAAW,EAAQ,EAAE;IAClE,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,G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MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAA;YAE9G,qBAAqB;YACrB,MAAM,WAAW,mCAAQ,IAAI,CAAC,OAAO,KAAE,cAAc,EAAE,mBAAmB,GAAE,CAAA;YAC5E,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;YAEpG,uEAAuE;YACvE,wEAAwE;YACxE,sCAAsC;YACtC,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;QACxC,CAAC;KAAA;CACF","sourcesContent":["import { SystemError, SystemErrorKeys } from '../../../error'\nimport { ExpressionContext } from '../../context'\nimport { ExpressionFunction } from '../../function'\nimport {\n CallExpression,\n ExpressionNodeEvaluator,\n ExpressionNodeType,\n IdentifierExpression,\n MemberExpression,\n} from '../../node'\nimport { getGlobalObjectProperty } from '../global'\nimport { REG_EXP_INPUT_MAX_LENGTH } from '../regExpSafety'\n\n// e.g. /.../.test(text) or text.match(/.../): the time taken by a regular expression grows with the input length\nconst checkRegExpInputLength = (fnObject: any, args: any[]): void => {\n const values = [fnObject, ...args]\n if (!values.some((value) => value instanceof RegExp)) return\n const inputTooLong = values.find((value) => typeof value === 'string' && value.length > REG_EXP_INPUT_MAX_LENGTH)\n if (inputTooLong !== undefined) {\n throw new SystemError(SystemErrorKeys.expression.regularExpressionInputTooLong, {\n maxLength: REG_EXP_INPUT_MAX_LENGTH,\n length: inputTooLong.length,\n })\n }\n}\n\nexport class CallEvaluator<C extends ExpressionContext> extends ExpressionNodeEvaluator<C, CallExpression> {\n async evaluate(expressionNode: CallExpression): Promise<any> {\n const { callee } = expressionNode\n\n if (callee.type === ExpressionNodeType.Member) {\n return this.evaluateMember(expressionNode, callee)\n } else if (callee.type === ExpressionNodeType.Identifier) {\n return this.evaluateIdentifier(expressionNode, callee)\n }\n\n // No complex expressions may be put in place of a function body.\n // Only a plain identifier is allowed.\n throw new SystemError(SystemErrorKeys.expression.invalidCalleeType, { type: callee.type })\n }\n\n private async evaluateMember(expressionNode: CallExpression, callee: MemberExpression): Promise<any> {\n const { arguments: exprArgs } = expressionNode\n\n // global function (e.g. Math.round(...))\n const fn = await this.evaluator.evaluateNode(callee, this.context)\n if (fn) {\n const { object: calleeObj } = callee\n const fnObject = await this.evaluator.evaluateNode(calleeObj, this.context)\n const argsEvaluated = await Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, this.context)))\n const args = argsEvaluated.flat()\n checkRegExpInputLength(fnObject, args)\n return fn.call(fnObject, ...args)\n }\n return null\n }\n\n private async evaluateIdentifier(expressionNode: CallExpression, callee: IdentifierExpression): Promise<any> {\n // Arguments is a reserved word in strict mode\n const { arguments: exprArgs } = expressionNode\n const { object: contextObject } = this.context\n\n const { name: fnName } = callee\n\n const functionInfo = this.evaluator.functions[fnName]\n if (functionInfo) {\n // The function is among the custom functions.\n return this.evaluateCustomIdentifier(expressionNode, fnName)\n }\n // identifier is a global object\n const globalFn = getGlobalObjectProperty(fnName, contextObject)\n if (globalFn !== null) {\n // global functions like String, Number, must be invoked passing node value as argument, not the node itself\n const contextArg = { ...this.context, evaluateToNode: false }\n const args = await Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, contextArg)))\n return globalFn(...args)\n }\n\n throw new SystemError(SystemErrorKeys.expression.undefinedFunction, { name: fnName })\n }\n\n private async evaluateCustomIdentifier(expressionNode: CallExpression, fnName: string): Promise<any> {\n // Arguments is a reserved word in strict mode\n const { arguments: exprArgs } = expressionNode\n const numArgs = exprArgs.length\n\n const expressionFunction: ExpressionFunction<C> = this.evaluator.functions[fnName]\n\n const { minArity, maxArity, evaluateArgsToNodes, executor } = expressionFunction\n\n if (numArgs < minArity)\n throw new SystemError(SystemErrorKeys.expression.functionHasTooFewArguments, { fnName, minArity, numArgs })\n if (maxArity !== undefined && maxArity >= 0 && numArgs > maxArity)\n throw new SystemError(SystemErrorKeys.expression.functionHasTooManyArguments, { fnName, maxArity, numArgs })\n\n // evaluate arguments\n const argsContext = { ...this.context, evaluateToNode: evaluateArgsToNodes }\n const args = await Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, argsContext)))\n\n // Currently there are no side effects from function evaluation so it's\n // safe to call the function even when we're just parsing the expression\n // to find all identifiers being used.\n return executor(this.context)(...args)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../../../../src/expression/javascript/node/call.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAG7D,OAAO,EAEL,uBAAuB,EACvB,kBAAkB,GAGnB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;AACnD,OAAO,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAEhF,gHAAgH;AAChH,MAAM,iCAAiC,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAA;AAElF,6FAA6F;AAC7F,MAAM,yBAAyB,GAAG,CAAC,MAAwB,EAAE,IAAW,EAAW,EAAE;IACnF,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAA;IACrC,OAAO,CACL,CAAC,QAAQ;QACT,QAAQ,CAAC,IAAI,KAAK,kBAAkB,CAAC,UAAU;QAC/C,iCAAiC,CAAC,GAAG,CAAE,QAAiC,CAAC,IAAI,CAAC;QAC9E,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAC5B,CAAA;AACH,CAAC,CAAA;AAED,MAAM,wBAAwB,GAAG,CAAC,OAAe,EAAQ,EAAE;IACzD,IAAI,oBAAoB,CAAC,O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AA;YAE/B,MAAM,kBAAkB,GAA0B,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;YAElF,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,mBAAmB,EAAE,QAAQ,EAAE,GAAG,kBAAkB,CAAA;YAEhF,IAAI,OAAO,GAAG,QAAQ;gBACpB,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAA;YAC7G,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,IAAI,CAAC,IAAI,OAAO,GAAG,QAAQ;gBAC/D,MAAM,IAAI,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,2BAA2B,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAA;YAE9G,qBAAqB;YACrB,MAAM,WAAW,mCAAQ,IAAI,CAAC,OAAO,KAAE,cAAc,EAAE,mBAAmB,GAAE,CAAA;YAC5E,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;YAEpG,uEAAuE;YACvE,wEAAwE;YACxE,sCAAsC;YACtC,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAA;QACxC,CAAC;KAAA;CACF","sourcesContent":["import { SystemError, SystemErrorKeys } from '../../../error'\nimport { ExpressionContext } from '../../context'\nimport { ExpressionFunction } from '../../function'\nimport {\n CallExpression,\n ExpressionNodeEvaluator,\n ExpressionNodeType,\n IdentifierExpression,\n MemberExpression,\n} from '../../node'\nimport { getGlobalObjectProperty } from '../global'\nimport { hasNestedQuantifiers, REG_EXP_INPUT_MAX_LENGTH } from '../regExpSafety'\n\n// String functions converting a string argument into a regular expression (replace, replaceAll and split don't)\nconst stringFunctionsWithRegExpArgument = new Set(['match', 'matchAll', 'search'])\n\n// e.g. text.match('(a+)+$'): the string pattern is checked like a regular expression literal\nconst isRegExpStringPatternCall = (callee: MemberExpression, args: any[]): boolean => {\n const { computed, property } = callee\n return (\n !computed &&\n property.type === ExpressionNodeType.Identifier &&\n stringFunctionsWithRegExpArgument.has((property as IdentifierExpression).name) &&\n typeof args[0] === 'string'\n )\n}\n\nconst checkRegExpStringPattern = (pattern: string): void => {\n if (hasNestedQuantifiers(pattern)) {\n throw new SystemError(SystemErrorKeys.expression.unsafeRegularExpression, { pattern })\n }\n}\n\n// e.g. /.../.test(text) or text.match(/.../): the time taken by a regular expression grows with the input length\nconst checkRegExpInputLength = (fnObject: any, args: any[], regExpStringPattern: boolean): void => {\n const values = [fnObject, ...args]\n if (!regExpStringPattern && !values.some((value) => value instanceof RegExp)) return\n const inputTooLong = values.find((value) => typeof value === 'string' && value.length > REG_EXP_INPUT_MAX_LENGTH)\n if (inputTooLong !== undefined) {\n throw new SystemError(SystemErrorKeys.expression.regularExpressionInputTooLong, {\n maxLength: REG_EXP_INPUT_MAX_LENGTH,\n length: inputTooLong.length,\n })\n }\n}\n\nexport class CallEvaluator<C extends ExpressionContext> extends ExpressionNodeEvaluator<C, CallExpression> {\n async evaluate(expressionNode: CallExpression): Promise<any> {\n const { callee } = expressionNode\n\n if (callee.type === ExpressionNodeType.Member) {\n return this.evaluateMember(expressionNode, callee)\n } else if (callee.type === ExpressionNodeType.Identifier) {\n return this.evaluateIdentifier(expressionNode, callee)\n }\n\n // No complex expressions may be put in place of a function body.\n // Only a plain identifier is allowed.\n throw new SystemError(SystemErrorKeys.expression.invalidCalleeType, { type: callee.type })\n }\n\n private async evaluateMember(expressionNode: CallExpression, callee: MemberExpression): Promise<any> {\n const { arguments: exprArgs } = expressionNode\n\n // global function (e.g. Math.round(...))\n const fn = await this.evaluator.evaluateNode(callee, this.context)\n if (fn) {\n const { object: calleeObj } = callee\n const fnObject = await this.evaluator.evaluateNode(calleeObj, this.context)\n const argsEvaluated = await Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, this.context)))\n const args = argsEvaluated.flat()\n const regExpStringPattern = isRegExpStringPatternCall(callee, args)\n if (regExpStringPattern) {\n checkRegExpStringPattern(args[0])\n }\n checkRegExpInputLength(fnObject, args, regExpStringPattern)\n return fn.call(fnObject, ...args)\n }\n return null\n }\n\n private async evaluateIdentifier(expressionNode: CallExpression, callee: IdentifierExpression): Promise<any> {\n // Arguments is a reserved word in strict mode\n const { arguments: exprArgs } = expressionNode\n const { object: contextObject } = this.context\n\n const { name: fnName } = callee\n\n const functionInfo = this.evaluator.functions[fnName]\n if (functionInfo) {\n // The function is among the custom functions.\n return this.evaluateCustomIdentifier(expressionNode, fnName)\n }\n // identifier is a global object\n const globalFn = getGlobalObjectProperty(fnName, contextObject)\n if (globalFn !== null) {\n // global functions like String, Number, must be invoked passing node value as argument, not the node itself\n const contextArg = { ...this.context, evaluateToNode: false }\n const args = await Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, contextArg)))\n return globalFn(...args)\n }\n\n throw new SystemError(SystemErrorKeys.expression.undefinedFunction, { name: fnName })\n }\n\n private async evaluateCustomIdentifier(expressionNode: CallExpression, fnName: string): Promise<any> {\n // Arguments is a reserved word in strict mode\n const { arguments: exprArgs } = expressionNode\n const numArgs = exprArgs.length\n\n const expressionFunction: ExpressionFunction<C> = this.evaluator.functions[fnName]\n\n const { minArity, maxArity, evaluateArgsToNodes, executor } = expressionFunction\n\n if (numArgs < minArity)\n throw new SystemError(SystemErrorKeys.expression.functionHasTooFewArguments, { fnName, minArity, numArgs })\n if (maxArity !== undefined && maxArity >= 0 && numArgs > maxArity)\n throw new SystemError(SystemErrorKeys.expression.functionHasTooManyArguments, { fnName, maxArity, numArgs })\n\n // evaluate arguments\n const argsContext = { ...this.context, evaluateToNode: evaluateArgsToNodes }\n const args = await Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, argsContext)))\n\n // Currently there are no side effects from function evaluation so it's\n // safe to call the function even when we're just parsing the expression\n // to find all identifiers being used.\n return executor(this.context)(...args)\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SystemError, SystemErrorKeys } from '../../../error';
|
|
2
2
|
import { ExpressionNodeEvaluator } from '../../node';
|
|
3
|
-
import { getGlobalObjectProperty, isForbiddenPropertyName } from '../global';
|
|
3
|
+
import { getGlobalObjectProperty, isForbiddenPropertyName, isForbiddenValue } from '../global';
|
|
4
4
|
const getNativeProperty = (name, object) => {
|
|
5
|
-
if (isForbiddenPropertyName(name)) {
|
|
5
|
+
if (isForbiddenPropertyName(name) || isForbiddenValue(object)) {
|
|
6
6
|
return undefined;
|
|
7
7
|
}
|
|
8
8
|
const prop = object === null || object === void 0 ? void 0 : object[name];
|
|
9
|
-
if (prop === undefined) {
|
|
9
|
+
if (prop === undefined || isForbiddenValue(prop)) {
|
|
10
10
|
return undefined;
|
|
11
11
|
}
|
|
12
12
|
return typeof prop === 'function' ? prop.bind(object) : prop;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identifier.js","sourceRoot":"","sources":["../../../../../src/expression/javascript/node/identifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,EAAE,uBAAuB,EAAwB,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"identifier.js","sourceRoot":"","sources":["../../../../../src/expression/javascript/node/identifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,EAAE,uBAAuB,EAAwB,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAE,uBAAuB,EAA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CAAC,CAAA;QAChE,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;QACxC,CAAC;QACD,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,kBAAkB,EAAE,EAAE,IAAI,EAAE,cAAc,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;IACtH,CAAC;CACF","sourcesContent":["import { SystemError, SystemErrorKeys } from '../../../error'\nimport { ExpressionContext } from '../../context'\nimport { ExpressionNodeEvaluator, IdentifierExpression } from '../../node'\nimport { getGlobalObjectProperty, isForbiddenPropertyName, isForbiddenValue } from '../global'\n\nconst getNativeProperty = (name: string, object: any) => {\n if (isForbiddenPropertyName(name) || isForbiddenValue(object)) {\n return undefined\n }\n const prop = object?.[name]\n if (prop === undefined || isForbiddenValue(prop)) {\n return undefined\n }\n return typeof prop === 'function' ? prop.bind(object) : prop\n}\n\nexport class IdentifierEvaluator<C extends ExpressionContext> extends ExpressionNodeEvaluator<C, IdentifierExpression> {\n /**\n * Looks for the identifier among global or native properties, without throwing when it is not found\n * (creating errors captures stack traces, which is expensive when it happens for every evaluated identifier).\n *\n * @param expressionNode - The identifier expression node.\n * @returns The property value wrapped in an object, or null if the identifier has not been found.\n */\n protected findGlobalOrNativeProperty(expressionNode: IdentifierExpression): { value: any } | null {\n const { name } = expressionNode\n const { object: contextObject } = this.context\n\n const globalProp = getGlobalObjectProperty(name, contextObject)\n if (globalProp !== null) {\n return { value: globalProp }\n }\n const nativeProperty = getNativeProperty(name, contextObject)\n if (nativeProperty !== undefined) {\n return { value: nativeProperty }\n }\n return null\n }\n\n evaluate(expressionNode: IdentifierExpression): Promise<any> {\n const property = this.findGlobalOrNativeProperty(expressionNode)\n if (property) {\n return Promise.resolve(property.value)\n }\n return Promise.reject(new SystemError(SystemErrorKeys.expression.identifierNotFound, { name: expressionNode.name }))\n }\n}\n"]}
|
|
@@ -98,21 +98,22 @@ export const nodeDefExpressionFunctions = {
|
|
|
98
98
|
categoryItemProp: {
|
|
99
99
|
minArity: 3,
|
|
100
100
|
executor: (context) => (categoryName, itemPropName, ...codePaths) => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
-
var _a
|
|
101
|
+
var _a;
|
|
102
102
|
const { survey } = context;
|
|
103
103
|
if (Objects.isEmpty(categoryName) || Objects.isEmpty(itemPropName) || Objects.isEmpty(codePaths))
|
|
104
104
|
throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters);
|
|
105
105
|
const category = getCategoryByName({ survey, categoryName });
|
|
106
106
|
if (!category)
|
|
107
107
|
throw new SystemError(SystemErrorKeys.expression.invalidCategoryName, { name: categoryName });
|
|
108
|
-
const
|
|
108
|
+
const { itemExtraDef } = category.props;
|
|
109
|
+
const extraPropDef = itemExtraDef && Object.hasOwn(itemExtraDef, itemPropName) ? itemExtraDef[itemPropName] : undefined;
|
|
109
110
|
if (!extraPropDef)
|
|
110
111
|
throw new SystemError(SystemErrorKeys.expression.invalidCategoryExtraProp, { propName: itemPropName });
|
|
111
112
|
const { uuid: categoryUuid } = category;
|
|
112
113
|
const categoryItem = yield getOrFetchCategoryItem({ context, categoryUuid, codePaths });
|
|
113
114
|
if (!categoryItem)
|
|
114
115
|
return null;
|
|
115
|
-
const value = (
|
|
116
|
+
const value = (_a = categoryItem.props.extra) === null || _a === void 0 ? void 0 : _a[itemPropName];
|
|
116
117
|
return ExtraProps.convertValue({ survey, extraPropDef, value });
|
|
117
118
|
}),
|
|
118
119
|
},
|
|
@@ -295,7 +296,7 @@ export const nodeDefExpressionFunctions = {
|
|
|
295
296
|
minArity: 3,
|
|
296
297
|
maxArity: 3,
|
|
297
298
|
executor: (context) => (taxonomyName, propName, taxonCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
298
|
-
var _a
|
|
299
|
+
var _a;
|
|
299
300
|
if (Objects.isEmpty(taxonomyName) || Objects.isEmpty(propName))
|
|
300
301
|
throw new SystemError(SystemErrorKeys.expression.missingFunctionParameters);
|
|
301
302
|
if (Objects.isEmpty(taxonCode))
|
|
@@ -304,13 +305,14 @@ export const nodeDefExpressionFunctions = {
|
|
|
304
305
|
const taxonomy = getTaxonomyByName({ survey, taxonomyName });
|
|
305
306
|
if (!taxonomy)
|
|
306
307
|
throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName });
|
|
307
|
-
const
|
|
308
|
+
const { extraPropsDefs } = taxonomy.props;
|
|
309
|
+
const extraPropDef = extraPropsDefs && Object.hasOwn(extraPropsDefs, propName) ? extraPropsDefs[propName] : undefined;
|
|
308
310
|
if (!extraPropDef)
|
|
309
311
|
throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyExtraProp, { propName });
|
|
310
312
|
const taxon = yield getOrFetchTaxon({ context, taxonomyUuid: taxonomy.uuid, taxonCode });
|
|
311
313
|
if (!taxon)
|
|
312
314
|
return null;
|
|
313
|
-
const value = (
|
|
315
|
+
const value = (_a = taxon.props.extra) === null || _a === void 0 ? void 0 : _a[propName];
|
|
314
316
|
return ExtraProps.convertValue({ survey, extraPropDef, value });
|
|
315
317
|
}),
|
|
316
318
|
},
|
|
@@ -327,7 +329,7 @@ export const nodeDefExpressionFunctions = {
|
|
|
327
329
|
const taxonomy = getTaxonomyByName({ survey, taxonomyName });
|
|
328
330
|
if (!taxonomy)
|
|
329
331
|
throw new SystemError(SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName });
|
|
330
|
-
if (!LanguagesISO639part2
|
|
332
|
+
if (!Object.hasOwn(LanguagesISO639part2, vernacularLangCode)) {
|
|
331
333
|
throw new SystemError(SystemErrorKeys.expression.invalidTaxonVernacularNameLanguageCode, {
|
|
332
334
|
vernacularLangCode,
|
|
333
335
|
});
|
|
@@ -371,7 +373,7 @@ export const nodeDefExpressionFunctions = {
|
|
|
371
373
|
return undefined;
|
|
372
374
|
const { uuid: surveyUuid } = survey;
|
|
373
375
|
const combinedExtraProps = Users.getCombinedExtraProps(surveyUuid)(user);
|
|
374
|
-
return combinedExtraProps[propName];
|
|
376
|
+
return Object.hasOwn(combinedExtraProps, propName) ? combinedExtraProps[propName] : undefined;
|
|
375
377
|
},
|
|
376
378
|
},
|
|
377
379
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/nodeDefExpressionEvaluator/functions.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAyB,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AACvF,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,GAClB,MAAM,kCAAkC,CAAA;AAEzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;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,CAAC,KAAK,EAAE,GAAG,CAAC;aACb;SACF;KACF;CACF,CAAA;AAED,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,OAAO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C;KACF;CACF,CAAA","sourcesContent":["import { Users } from '../auth'\nimport { CategoryItem } from '../category'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ExpressionFunctions } from '../expression'\nimport { ExtraProps } from '../extraProp/extraProps'\nimport { AreaOfInterest, Point, 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 { Taxon } 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<CategoryItem | 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<Taxon | 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<AreaOfInterest | 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: Point\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: Point | string, coordinateTo: Point | 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: ExpressionFunctions<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 extraPropDef = category.props.itemExtraDef?.[itemPropName]\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: Point | string, distanceMeters: number, bearingDeg: number): Point | 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: Point | 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: Point | 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 extraPropDef = taxonomy.props.extraPropsDefs?.[propName]\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 (!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 combinedExtraProps[propName]\n },\n },\n}\n"]}
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../../src/nodeDefExpressionEvaluator/functions.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AACpD,OAAO,EAAyB,MAAM,EAAE,MAAM,QAAQ,CAAA;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;AAC7D,OAAO,EAAE,0BAA0B,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AACvF,OAAO,EACL,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,iBAAiB,GAClB,MAAM,kCAAkC,CAAA;AAEzC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;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,CAAC,KAAK,EAAE,GAAG,CAAC;aACb;SACF;KACF;CACF,CAAA;AAED,MAAM,gBAAgB,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,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,KAAK,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 { CategoryItem } from '../category'\nimport { SystemError, SystemErrorKeys } from '../error'\nimport { ExpressionFunctions } from '../expression'\nimport { ExtraProps } from '../extraProp/extraProps'\nimport { AreaOfInterest, Point, 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 { Taxon } 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<CategoryItem | 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<Taxon | 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<AreaOfInterest | 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: Point\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: Point | string, coordinateTo: Point | 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: ExpressionFunctions<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: Point | string, distanceMeters: number, bearingDeg: number): Point | 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: Point | 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: Point | 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"]}
|
|
@@ -8,10 +8,16 @@ import { Arrays, Queue } from '../../utils';
|
|
|
8
8
|
import { RECORD_STEP_DEFAULT } from '../record';
|
|
9
9
|
import { RecordStepAnalysisCode } from '../recordStep';
|
|
10
10
|
import { RecordNodesIndexReader } from './recordNodesIndexReader';
|
|
11
|
+
import { RecordNodesIndexUpdater } from './recordNodesIndexUpdater';
|
|
11
12
|
import { NodeDefSelfReferences } from './nodeDefSelfReferences';
|
|
12
13
|
export const getCycle = (record) => { var _a; return (_a = record.cycle) !== null && _a !== void 0 ? _a : defaultCycle; };
|
|
13
14
|
export const getNodes = (record) => { var _a; return (_a = record.nodes) !== null && _a !== void 0 ? _a : {}; };
|
|
14
15
|
export const getNodesArray = (record) => Object.values(getNodes(record));
|
|
16
|
+
/**
|
|
17
|
+
* Returns the nodes index of the record or, if missing, a new index built from all the record nodes (not stored in the record).
|
|
18
|
+
* To be used before updating the index: a partial index would be trusted by the getters.
|
|
19
|
+
*/
|
|
20
|
+
export const getNodesIndexOrBuild = (record) => { var _a; return (_a = record._nodesIndex) !== null && _a !== void 0 ? _a : RecordNodesIndexUpdater.initializeIndex(record); };
|
|
15
21
|
/**
|
|
16
22
|
* Returns the node with the specified uuid, or undefined if not found.
|
|
17
23
|
* Like the other node getters, it does not throw an error when the node is not found.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordGetters.js","sourceRoot":"","sources":["../../../../src/record/_records/recordGetters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,cAAc,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAgC,KAAK,EAAY,MAAM,YAAY,CAAA;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAwD,QAAQ,EAAe,MAAM,eAAe,CAAA;AAC3G,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAEpD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC3C,OAAO,EAAe,mBAAmB,EAAE,MAAM,WAAW,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAE/D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,KAAK,mCAAI,YAAY,GAAA,CAAA;AAErF,MAAM,CAAC,MAAM,QAAQ,GAAG,C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aRecordNode, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { ArenaRecord, RECORD_STEP_DEFAULT } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: ArenaRecord): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: ArenaRecord): Dictionary<ArenaRecordNode> => record.nodes ?? {}\n\nexport const getNodesArray = (record: ArenaRecord): ArenaRecordNode[] => Object.values(getNodes(record))\n\n/**\n * Returns the node with the specified uuid, or undefined if not found.\n * Like the other node getters, it does not throw an error when the node is not found.\n */\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n uuids.map((uuid: string) => record.nodes?.[uuid]) as ArenaRecordNode[]\n\n/**\n * Returns the root node, or undefined if the record has no nodes.\n */\nexport const getRoot = (record: ArenaRecord): ArenaRecordNode | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: ArenaRecordNode, childDefUuid?: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\n/**\n * Returns the only child of the parent node with the specified node def, or undefined if not found.\n * Throws an error if more than one child is found.\n */\nexport const getChild =\n (parentNode: ArenaRecordNode, childDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const children = getChildren(parentNode, childDefUuid)(record)\n if (children.length > 1) {\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n throw new SystemError(SystemErrorKeys.record.multipleNodesFound, errorParams)\n }\n return children[0]\n }\n\n// called for every ancestor in the record update loops: keep it a plain lookup\nconst getParentNode = (record: ArenaRecord, node: ArenaRecordNode): ArenaRecordNode | undefined =>\n node.parentUuid ? record.nodes?.[node.parentUuid] : undefined\n\nexport const getParent =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getParentNode(record, node)\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: ArenaRecordNode, nodeDefUuid: string) => boolean) =>\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n let child = node\n let parent = getParentNode(record, child)\n while (parent) {\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n child = parent\n parent = getParentNode(record, child)\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\n/**\n * Whether a value is required for the node: key or always required attribute, or attribute with a \"required if\"\n * condition met in its parent entity (evaluated condition stored in the parent node meta).\n */\nexport const isNodeRequired =\n (nodeDef: NodeDef<NodeDefType>, node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parent = getParentNode(record, node)\n return !!parent && Nodes.isChildRequired(parent, nodeDef.uuid)\n }\n\nexport const getDependentCodeAttributes =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError(SystemErrorKeys.record.nodesIndexNotInitialized)\n }\n\nexport const getParentCodeAttribute =\n (parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf(parentNode)(record)\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\n\n/**\n * Visits the specified node and its ancestors, from the node up to the root: the visit stops when the visitor returns true.\n */\nexport const visitAncestorsAndSelf =\n (node: ArenaRecordNode, visitor: (node: ArenaRecordNode) => boolean | void) =>\n (record: ArenaRecord): void => {\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n if (visitor(currentNode)) return\n currentNode = getParentNode(record, currentNode)\n }\n }\n\n/**\n * Returns the first node satisfying the predicate among the specified node and its ancestors (from the node up to the root).\n */\nexport const findAncestor =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let result: ArenaRecordNode | undefined = undefined\n visitAncestorsAndSelf(node, (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n return true\n }\n return false\n })(record)\n return result\n }\n\n/**\n * Returns the specified node, if it has the specified node def, or its ancestor with that node def; undefined if not found.\n */\nexport const getAncestor =\n (node: ArenaRecordNode, ancestorDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let ancestor: ArenaRecordNode | undefined = node\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParentNode(record, ancestor)\n }\n return ancestor\n }\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): Array<ArenaRecordNode> => {\n const ancestors: Array<ArenaRecordNode> = []\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n ancestors.push(currentNode)\n currentNode = getParentNode(record, currentNode)\n }\n return ancestors\n }\n\n// descendants\n\nexport const getDescendantsOrSelf =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: ArenaRecordNode[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n }\n\n/**\n * Returns the first descendant (or the node itself) with the specified node def, or undefined if not found.\n */\nexport const getDescendant =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getDescendantsOrSelf(node, nodeDefDescendant)(record)[0]\n\nexport const isDescendantOf = (node: ArenaRecordNode, ancestor: ArenaRecordNode): boolean =>\n Nodes.getHierarchy(node).includes(ancestor.uuid)\n\nexport const visitDescendantsAndSelf =\n (\n node: ArenaRecordNode,\n visitor: (node: ArenaRecordNode) => boolean | void,\n traverseMethod: TraverseMethod = TraverseMethod.bfs\n ) =>\n (record: ArenaRecord): void => {\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue<ArenaRecordNode>()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()!\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as ArenaRecordNode\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n }\n\nexport const findDescendantOrSelf =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf(node, (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n })(record)\n return found\n }\n\nconst getClosestAncestorNode =\n (\n node: ArenaRecordNode,\n nodeDef: NodeDef<NodeDefType, NodeDefProps>,\n dependentDef: NodeDef<NodeDefType, NodeDefProps>,\n dependencyType: SurveyDependencyType\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor(node, commonAncestorDefUuid)(record)\n }\n\ntype KeyDefs = NodeDef<NodeDefType, NodeDefProps>[]\n\n/**\n * Returns the key nodes of the entity, indexed by key def uuid; keyDefs, when specified, are used instead of the\n * entity def keys in the cycle.\n */\nexport const getEntityKeyNodesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): NodesMap => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant(entity, nodeDefKey)(record)\n // missing key nodes are kept as undefined entries\n acc[nodeDefKey.uuid] = nodeKey as ArenaRecordNode\n return acc\n }, {})\n }\n\nexport const getEntityKeyNodes =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n Object.values(getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntityKeyValuesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n }\n\nexport const getEntityKeyValues =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntitySiblings =\n (entity: ArenaRecordNode, includeSelf = false) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n }\n\nexport const getAttributeSiblings =\n (node: ArenaRecordNode, nodeDef: NodeDef<NodeDefType, NodeDefProps>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings(parentEntity)(record)\n return siblingParentEntities.reduce((siblingsAcc: ArenaRecordNode[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n }\n\nexport const getNodeIndex = (node: ArenaRecordNode) => (record: ArenaRecord) => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n // compared by uuid: the specified node can be a copy of the one in the record (e.g. an updated version of it)\n return siblings.findIndex((sibling) => sibling.uuid === node.uuid)\n}\n\nexport const findEntityByKeyValues =\n (\n survey: Survey,\n cycle: string,\n parentEntity: ArenaRecordNode,\n entityDefUuid: string,\n keyValuesByDefUuid: Dictionary<any>\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid(\n survey,\n siblingEntity,\n undefined,\n keyDefs\n )(record)\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n }\n\nexport const findEntityWithSameKeysInAnotherRecord =\n (survey: Survey, cycle: string, entityUuid: string, recordOther: ArenaRecord) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf(entity)(record)\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid(survey, ancestor)(record),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues(\n survey,\n cycle,\n otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid\n )(recordOther)\n }\n return otherRecordCurrentParentEntity\n }\n\nexport const getDependentNodePointers =\n (\n survey: Survey,\n node: ArenaRecordNode,\n dependencyType: SurveyDependencyType,\n includeSelf = false,\n filterFn: ((nodePointer: NodePointer) => boolean) | null = null\n ) =>\n (record: ArenaRecord): NodePointer[] => {\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode(node, nodeDef, dependentDef, dependencyType)(record)\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError(SystemErrorKeys.record.dependencyOnRootFound)\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf(commonAncestorNode, nodeDefDependentParent)(record)\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n }\n\n/**\n * Returns the code attributes the specified code attribute depends on, from the top level one to the parent one.\n */\nexport const getAncestorCodeAttributes =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const ancestorCodeAttributes = []\n let currentParentCodeAttribute = getParentCodeAttribute(parentNode, nodeDef)(record)\n while (currentParentCodeAttribute) {\n ancestorCodeAttributes.unshift(currentParentCodeAttribute)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute(parentNode, ancestorCodeDef)(record)\n }\n return ancestorCodeAttributes\n }\n\nexport const getAncestorCodePath =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>) =>\n (record: ArenaRecord): string[] =>\n getAncestorCodeAttributes(\n survey,\n parentNode,\n nodeDef\n )(record).map((codeAttribute) => {\n const codeItemUuid = NodeValues.getItemUuid(codeAttribute)\n if (!codeItemUuid) return ''\n // items of big categories are not in the survey ref data: they can be in the node ref data\n const item =\n codeAttribute.refData?.categoryItem ?? Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n })\n\nexport const getCategoryItemUuid =\n (survey: Survey, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>, parentNode: ArenaRecordNode, code: string) =>\n (record: ArenaRecord): string | undefined => {\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath(survey, parentNode, nodeDef)(record), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n }\n\nexport const isNodeFilledByUser =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: ArenaRecord): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: ArenaRecord): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: ArenaRecord): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
|
|
1
|
+
{"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A;IAEpF,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,CAAA;AACnB,CAAC,CAAA;AAEH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,CAAC,oBAAoB,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,KAAK,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;AAE/F,MAAM,CAAC,MAAM,WAAW,GACtB,CAAC,IAAqB,EAAE,EAAE,CAC1B,CAAC,MAAmB,EAAW,EAAE,CAC/B,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAW,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAChC,OAAO,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACxD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAmB,EAAU,EAAE,wBAAC,MAAM,CAAC,IAAI,mCAAI,mBAAmB,GAAA,CAAA;AAE1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAmB,EAAW,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,sBAAsB,CAAA","sourcesContent":["import { Dictionary, TraverseMethod } from '../../common'\nimport { SystemError, SystemErrorKeys } from '../../error'\nimport { ArenaRecordNode, NodePointer, Nodes, NodesMap } from '../../node'\nimport { NodeValues } from '../../node/nodeValues'\nimport { NodeDef, NodeDefCode, NodeDefCodeProps, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { defaultCycle, Surveys } from '../../survey'\nimport { Survey, SurveyDependencyType } from '../../survey/survey'\nimport { Arrays, Queue } from '../../utils'\nimport { ArenaRecord, RECORD_STEP_DEFAULT, RecordNodesIndex } from '../record'\nimport { RecordStepAnalysisCode } from '../recordStep'\nimport { RecordNodesIndexReader } from './recordNodesIndexReader'\nimport { RecordNodesIndexUpdater } from './recordNodesIndexUpdater'\nimport { NodeDefSelfReferences } from './nodeDefSelfReferences'\n\nexport const getCycle = (record: ArenaRecord): string => record.cycle ?? defaultCycle\n\nexport const getNodes = (record: ArenaRecord): Dictionary<ArenaRecordNode> => record.nodes ?? {}\n\nexport const getNodesArray = (record: ArenaRecord): ArenaRecordNode[] => Object.values(getNodes(record))\n\n/**\n * Returns the nodes index of the record or, if missing, a new index built from all the record nodes (not stored in the record).\n * To be used before updating the index: a partial index would be trusted by the getters.\n */\nexport const getNodesIndexOrBuild = (record: ArenaRecord): RecordNodesIndex =>\n record._nodesIndex ?? RecordNodesIndexUpdater.initializeIndex(record)\n\n/**\n * Returns the node with the specified uuid, or undefined if not found.\n * Like the other node getters, it does not throw an error when the node is not found.\n */\nexport const getNodeByUuid =\n (uuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n record.nodes?.[uuid]\n\nexport const getNodesByUuids =\n (uuids: string[]) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n uuids.map((uuid: string) => record.nodes?.[uuid]) as ArenaRecordNode[]\n\n/**\n * Returns the root node, or undefined if the record has no nodes.\n */\nexport const getRoot = (record: ArenaRecord): ArenaRecordNode | undefined => {\n const rootUuid = record._nodesIndex ? RecordNodesIndexReader.getNodeRootUuid(record._nodesIndex) : null\n if (rootUuid) {\n return getNodeByUuid(rootUuid)(record)\n }\n return getNodesArray(record).find((node) => !node.parentUuid)\n}\n\nexport const getChildren =\n (parentNode: ArenaRecordNode, childDefUuid?: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const childrenUuids = childDefUuid\n ? RecordNodesIndexReader.getNodeUuidsByParentAndChildDef({\n parentNodeUuid: parentNode.uuid,\n childDefUuid,\n })(record._nodesIndex)\n : RecordNodesIndexReader.getNodeUuidsByParent(parentNode.uuid)(record._nodesIndex)\n return getNodesByUuids(childrenUuids)(record)\n }\n return getNodesArray(record).filter(\n (node) => node.parentUuid === parentNode.uuid && (!childDefUuid || node.nodeDefUuid == childDefUuid)\n )\n }\n\n/**\n * Returns the only child of the parent node with the specified node def, or undefined if not found.\n * Throws an error if more than one child is found.\n */\nexport const getChild =\n (parentNode: ArenaRecordNode, childDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const children = getChildren(parentNode, childDefUuid)(record)\n if (children.length > 1) {\n const errorParams = { childDefUuid, parentNodeUuid: parentNode.uuid, recordUuid: record.uuid }\n throw new SystemError(SystemErrorKeys.record.multipleNodesFound, errorParams)\n }\n return children[0]\n }\n\n// called for every ancestor in the record update loops: keep it a plain lookup\nconst getParentNode = (record: ArenaRecord, node: ArenaRecordNode): ArenaRecordNode | undefined =>\n node.parentUuid ? record.nodes?.[node.parentUuid] : undefined\n\nexport const getParent =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getParentNode(record, node)\n\nexport const getNodesByDefUuid =\n (nodeDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeUuidsByDef(nodeDefUuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n return getNodesArray(record).filter((node) => node.nodeDefUuid === nodeDefUuid)\n }\n\nconst isNodeFlagTrue =\n (isChildFlagTrue: (parent: ArenaRecordNode, nodeDefUuid: string) => boolean) =>\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n let child = node\n let parent = getParentNode(record, child)\n while (parent) {\n if (!isChildFlagTrue(parent, child.nodeDefUuid)) return false\n child = parent\n parent = getParentNode(record, child)\n }\n return true\n }\n\nexport const isNodeApplicable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildApplicable(parent, nodeDefUuid))\nexport const isNodeEditable = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildEditable(parent, nodeDefUuid))\nexport const isNodeVisible = isNodeFlagTrue((parent, nodeDefUuid) => Nodes.isChildVisible(parent, nodeDefUuid))\n\n/**\n * Whether a value is required for the node: key or always required attribute, or attribute with a \"required if\"\n * condition met in its parent entity (evaluated condition stored in the parent node meta).\n */\nexport const isNodeRequired =\n (nodeDef: NodeDef<NodeDefType>, node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean => {\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parent = getParentNode(record, node)\n return !!parent && Nodes.isChildRequired(parent, nodeDef.uuid)\n }\n\nexport const getDependentCodeAttributes =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (record._nodesIndex) {\n const nodeUuids = RecordNodesIndexReader.getNodeCodeDependentUuids(node.uuid)(record._nodesIndex)\n return getNodesByUuids(nodeUuids)(record)\n }\n throw new SystemError(SystemErrorKeys.record.nodesIndexNotInitialized)\n }\n\nexport const getParentCodeAttribute =\n (parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const parentCodeDefUuid = NodeDefs.getParentCodeDefUuid(nodeDef)\n if (!parentCodeDefUuid) return undefined\n\n const ancestors = getAncestorsAndSelf(parentNode)(record)\n for (const ancestor of ancestors) {\n const children = getChildren(ancestor, parentCodeDefUuid)(record)\n if (children.length === 1) {\n return children[0]\n }\n }\n return undefined\n }\n\n// ancestors\n\n/**\n * Visits the specified node and its ancestors, from the node up to the root: the visit stops when the visitor returns true.\n */\nexport const visitAncestorsAndSelf =\n (node: ArenaRecordNode, visitor: (node: ArenaRecordNode) => boolean | void) =>\n (record: ArenaRecord): void => {\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n if (visitor(currentNode)) return\n currentNode = getParentNode(record, currentNode)\n }\n }\n\n/**\n * Returns the first node satisfying the predicate among the specified node and its ancestors (from the node up to the root).\n */\nexport const findAncestor =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let result: ArenaRecordNode | undefined = undefined\n visitAncestorsAndSelf(node, (visitedNode) => {\n if (predicate(visitedNode)) {\n result = visitedNode\n return true\n }\n return false\n })(record)\n return result\n }\n\n/**\n * Returns the specified node, if it has the specified node def, or its ancestor with that node def; undefined if not found.\n */\nexport const getAncestor =\n (node: ArenaRecordNode, ancestorDefUuid: string) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let ancestor: ArenaRecordNode | undefined = node\n while (ancestor && ancestor.nodeDefUuid !== ancestorDefUuid) {\n ancestor = getParentNode(record, ancestor)\n }\n return ancestor\n }\n\n/**\n * Returns the list of ancestors from the given node to the root entity\n */\nexport const getAncestorsAndSelf =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): Array<ArenaRecordNode> => {\n const ancestors: Array<ArenaRecordNode> = []\n let currentNode: ArenaRecordNode | undefined = node\n while (currentNode) {\n ancestors.push(currentNode)\n currentNode = getParentNode(record, currentNode)\n }\n return ancestors\n }\n\n// descendants\n\nexport const getDescendantsOrSelf =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n if (nodeDefDescendant.uuid === node.nodeDefUuid) return [node]\n\n const nodeDefDescendantFullHierarchy = [...nodeDefDescendant.meta.h, nodeDefDescendant.uuid]\n\n // 1. get the descendant node defs uuids starting from node nodeDefUuid (not inclusive) down to the specified nodeDefDescendant uuid\n const descendantNodeDefUuids = nodeDefDescendantFullHierarchy.slice(\n nodeDefDescendantFullHierarchy.indexOf(node.nodeDefUuid) + 1\n )\n // 2. for every level in the hierarchy, find the children having the nodeDefUuid equal to the current one\n let currentAncestors = [node]\n let currentDescendants: ArenaRecordNode[] = []\n for (const currentDescendantDefUuid of descendantNodeDefUuids) {\n for (const currentAncestor of currentAncestors) {\n currentDescendants.push(...getChildren(currentAncestor, currentDescendantDefUuid)(record))\n }\n currentAncestors = currentDescendants\n currentDescendants = []\n }\n return currentAncestors // currentAncestors is equal to the currentDescendants of the last level\n }\n\n/**\n * Returns the first descendant (or the node itself) with the specified node def, or undefined if not found.\n */\nexport const getDescendant =\n (node: ArenaRecordNode, nodeDefDescendant: NodeDef<any>) =>\n (record: ArenaRecord): ArenaRecordNode | undefined =>\n getDescendantsOrSelf(node, nodeDefDescendant)(record)[0]\n\nexport const isDescendantOf = (node: ArenaRecordNode, ancestor: ArenaRecordNode): boolean =>\n Nodes.getHierarchy(node).includes(ancestor.uuid)\n\nexport const visitDescendantsAndSelf =\n (\n node: ArenaRecordNode,\n visitor: (node: ArenaRecordNode) => boolean | void,\n traverseMethod: TraverseMethod = TraverseMethod.bfs\n ) =>\n (record: ArenaRecord): void => {\n if (traverseMethod === TraverseMethod.bfs) {\n const queue = new Queue<ArenaRecordNode>()\n\n queue.enqueue(node)\n\n while (!queue.isEmpty()) {\n const visitedNode = queue.dequeue()!\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n queue.enqueueItems(children)\n }\n } else {\n const stack = []\n\n stack.push(node)\n\n while (stack.length > 0) {\n const visitedNode = stack.pop() as ArenaRecordNode\n\n if (visitor(visitedNode)) {\n // stop if visitor returns true\n return\n }\n\n const children = getChildren(visitedNode)(record)\n\n // add children to stack in reverse order\n for (let index = children.length - 1; index >= 0; index--) {\n const child = children[index]\n stack.push(child)\n }\n }\n }\n }\n\nexport const findDescendantOrSelf =\n (node: ArenaRecordNode, predicate: (node: ArenaRecordNode) => boolean) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n let found = undefined\n\n visitDescendantsAndSelf(node, (currentNode) => {\n if (predicate(currentNode)) {\n found = currentNode\n return true\n }\n return false\n })(record)\n return found\n }\n\nconst getClosestAncestorNode =\n (\n node: ArenaRecordNode,\n nodeDef: NodeDef<NodeDefType, NodeDefProps>,\n dependentDef: NodeDef<NodeDefType, NodeDefProps>,\n dependencyType: SurveyDependencyType\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n // 1a if dependent def is the same as node def, potentially all nodes with\n // nodeDefUuid === dependentDef.uuid in record could be dependent of nodeDef;\n // consider the root node as the closest ancestor node,\n // unless the node def references itself only among the children of its parent entity (e.g. validation \"dbh > 0\")\n if (nodeDef.uuid === dependentDef.uuid) {\n return NodeDefSelfReferences.isSelfReferenceLocal({ nodeDef, dependencyType })\n ? getParent(node)(record)\n : getRoot(record)\n }\n // 1 find common ancestor def\n const commonAncestorDefUuid = Arrays.last(Arrays.intersection(nodeDef.meta.h, dependentDef.meta.h))\n if (!commonAncestorDefUuid) return undefined\n\n // 2 get ancestor node with common parent def\n return getAncestor(node, commonAncestorDefUuid)(record)\n }\n\ntype KeyDefs = NodeDef<NodeDefType, NodeDefProps>[]\n\n/**\n * Returns the key nodes of the entity, indexed by key def uuid; keyDefs, when specified, are used instead of the\n * entity def keys in the cycle.\n */\nexport const getEntityKeyNodesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): NodesMap => {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: entity.nodeDefUuid })\n const nodeDefKeys = keyDefs ?? Surveys.getNodeDefKeys({ survey, cycle, nodeDef })\n return nodeDefKeys.reduce((acc: NodesMap, nodeDefKey) => {\n const nodeKey = getDescendant(entity, nodeDefKey)(record)\n // missing key nodes are kept as undefined entries\n acc[nodeDefKey.uuid] = nodeKey as ArenaRecordNode\n return acc\n }, {})\n }\n\nexport const getEntityKeyNodes =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): ArenaRecordNode[] =>\n Object.values(getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntityKeyValuesByDefUuid =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): Dictionary<any> => {\n const keyNodesByDefUuid = getEntityKeyNodesByDefUuid(survey, entity, cycle, keyDefs)(record)\n return Object.entries(keyNodesByDefUuid).reduce((acc: Dictionary<any>, [uuid, keyNode]) => {\n acc[uuid] = keyNode?.value\n return acc\n }, {})\n }\n\nexport const getEntityKeyValues =\n (survey: Survey, entity: ArenaRecordNode, cycle?: string, keyDefs?: KeyDefs) =>\n (record: ArenaRecord): any[] =>\n Object.values(getEntityKeyValuesByDefUuid(survey, entity, cycle, keyDefs)(record))\n\nexport const getEntitySiblings =\n (entity: ArenaRecordNode, includeSelf = false) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(entity)(record)\n if (!parentEntity) return []\n const siblingEntities = getChildren(parentEntity, entity.nodeDefUuid)(record)\n return includeSelf ? siblingEntities : siblingEntities.filter((sibling) => !Nodes.areEqual(sibling, entity))\n }\n\nexport const getAttributeSiblings =\n (node: ArenaRecordNode, nodeDef: NodeDef<NodeDefType, NodeDefProps>) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return []\n const siblingParentEntities = getEntitySiblings(parentEntity)(record)\n return siblingParentEntities.reduce((siblingsAcc: ArenaRecordNode[], siblingEntity) => {\n siblingsAcc.push(...getChildren(siblingEntity, nodeDef.uuid)(record))\n return siblingsAcc\n }, [])\n }\n\nexport const getNodeIndex = (node: ArenaRecordNode) => (record: ArenaRecord) => {\n const parentEntity = getParent(node)(record)\n if (!parentEntity) return 0 // root entity\n const siblings = getChildren(parentEntity, node.nodeDefUuid)(record)\n // compared by uuid: the specified node can be a copy of the one in the record (e.g. an updated version of it)\n return siblings.findIndex((sibling) => sibling.uuid === node.uuid)\n}\n\nexport const findEntityByKeyValues =\n (\n survey: Survey,\n cycle: string,\n parentEntity: ArenaRecordNode,\n entityDefUuid: string,\n keyValuesByDefUuid: Dictionary<any>\n ) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entityDef = Surveys.getNodeDefByUuid({ survey, uuid: entityDefUuid })\n const siblingEntities = getChildren(parentEntity, entityDefUuid)(record)\n if (NodeDefs.isSingle(entityDef)) {\n return siblingEntities[0]\n }\n const keyDefs = Surveys.getNodeDefKeys({ survey, cycle, nodeDef: entityDef })\n\n return siblingEntities.find((siblingEntity) => {\n const siblingEntityKeyValuesByDefUuid = getEntityKeyValuesByDefUuid(\n survey,\n siblingEntity,\n undefined,\n keyDefs\n )(record)\n return keyDefs.every((keyDef) => {\n const keyValue = siblingEntityKeyValuesByDefUuid[keyDef.uuid]\n const keyValueSearch = keyValuesByDefUuid[keyDef.uuid]\n return NodeValues.isValueEqual({\n survey,\n nodeDef: keyDef,\n value: keyValue,\n valueSearch: keyValueSearch,\n })\n })\n })\n }\n\nexport const findEntityWithSameKeysInAnotherRecord =\n (survey: Survey, cycle: string, entityUuid: string, recordOther: ArenaRecord) =>\n (record: ArenaRecord): ArenaRecordNode | undefined => {\n const entity = getNodeByUuid(entityUuid)(record)\n if (!entity) return undefined\n\n let otherRecordCurrentParentEntity = getRoot(recordOther)\n if (!otherRecordCurrentParentEntity) return undefined\n\n const entityAncestorsAndSelf = getAncestorsAndSelf(entity)(record)\n const ancestorDefUuidsAndKeys = entityAncestorsAndSelf.map((ancestor) => ({\n entityDefUuid: ancestor.nodeDefUuid,\n keyValuesByDefUuid: getEntityKeyValuesByDefUuid(survey, ancestor)(record),\n }))\n\n const ancestorDefUuidsAndKeysToVisit = [...ancestorDefUuidsAndKeys].reverse()\n\n for (let index = 1; otherRecordCurrentParentEntity && index < ancestorDefUuidsAndKeysToVisit.length; index++) {\n const { entityDefUuid, keyValuesByDefUuid } = ancestorDefUuidsAndKeysToVisit[index]\n otherRecordCurrentParentEntity = findEntityByKeyValues(\n survey,\n cycle,\n otherRecordCurrentParentEntity,\n entityDefUuid,\n keyValuesByDefUuid\n )(recordOther)\n }\n return otherRecordCurrentParentEntity\n }\n\nexport const getDependentNodePointers =\n (\n survey: Survey,\n node: ArenaRecordNode,\n dependencyType: SurveyDependencyType,\n includeSelf = false,\n filterFn: ((nodePointer: NodePointer) => boolean) | null = null\n ) =>\n (record: ArenaRecord): NodePointer[] => {\n const nodeDefUuid = node.nodeDefUuid\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: nodeDefUuid })\n const dependentDefs = Surveys.getNodeDefDependents({ survey, nodeDefUuid, dependencyType })\n const nodePointers: Array<NodePointer> = []\n\n const addToNodePointers = (nodePointer: NodePointer): void => {\n if (filterFn === null || filterFn(nodePointer)) {\n nodePointers.push(nodePointer)\n }\n }\n\n for (const dependentDef of dependentDefs) {\n // 1 find common ancestor node\n const commonAncestorNode = getClosestAncestorNode(node, nodeDef, dependentDef, dependencyType)(record)\n if (!commonAncestorNode) continue\n\n const nodeDefDependentParent = Surveys.getNodeDefParent({ survey, nodeDef: dependentDef })\n if (!nodeDefDependentParent) throw new SystemError(SystemErrorKeys.record.dependencyOnRootFound)\n\n // 2 find descendant nodes of common parent node with nodeDefUuid = dependentDef uuid\n const dependentContextNodes = getDescendantsOrSelf(commonAncestorNode, nodeDefDependentParent)(record)\n\n for (const dependentContextNode of dependentContextNodes) {\n addToNodePointers({\n nodeCtx: dependentContextNode,\n nodeDef: dependentDef,\n })\n }\n }\n if (includeSelf) {\n const parentNode = getParent(node)(record)\n if (parentNode) {\n addToNodePointers({\n nodeCtx: parentNode,\n nodeDef,\n })\n }\n }\n\n return nodePointers\n }\n\n/**\n * Returns the code attributes the specified code attribute depends on, from the top level one to the parent one.\n */\nexport const getAncestorCodeAttributes =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDefCode) =>\n (record: ArenaRecord): ArenaRecordNode[] => {\n const ancestorCodeAttributes = []\n let currentParentCodeAttribute = getParentCodeAttribute(parentNode, nodeDef)(record)\n while (currentParentCodeAttribute) {\n ancestorCodeAttributes.unshift(currentParentCodeAttribute)\n const ancestorCodeDef = Surveys.getNodeDefByUuid({\n survey,\n uuid: currentParentCodeAttribute.nodeDefUuid,\n }) as NodeDefCode\n currentParentCodeAttribute = getParentCodeAttribute(parentNode, ancestorCodeDef)(record)\n }\n return ancestorCodeAttributes\n }\n\nexport const getAncestorCodePath =\n (survey: Survey, parentNode: ArenaRecordNode, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>) =>\n (record: ArenaRecord): string[] =>\n getAncestorCodeAttributes(\n survey,\n parentNode,\n nodeDef\n )(record).map((codeAttribute) => {\n const codeItemUuid = NodeValues.getItemUuid(codeAttribute)\n if (!codeItemUuid) return ''\n // items of big categories are not in the survey ref data: they can be in the node ref data\n const item =\n codeAttribute.refData?.categoryItem ?? Surveys.getCategoryItemByUuid({ survey, itemUuid: codeItemUuid })\n return item?.props.code ?? ''\n })\n\nexport const getCategoryItemUuid =\n (survey: Survey, nodeDef: NodeDef<NodeDefType.code, NodeDefCodeProps>, parentNode: ArenaRecordNode, code: string) =>\n (record: ArenaRecord): string | undefined => {\n const categoryUuid = nodeDef.props.categoryUuid\n\n const codePaths = [...getAncestorCodePath(survey, parentNode, nodeDef)(record), code]\n\n const item = Surveys.getCategoryItemByCodePaths({ survey, categoryUuid, codePaths })\n\n return item?.uuid\n }\n\nexport const isNodeFilledByUser =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !!findDescendantOrSelf(node, (visitedNode) => Nodes.hasUserInputValue(visitedNode))(record)\n\nexport const isNodeEmpty =\n (node: ArenaRecordNode) =>\n (record: ArenaRecord): boolean =>\n !isNodeFilledByUser(node)(record)\n\nexport const isEmpty = (record: ArenaRecord): boolean => {\n const rootNode = getRoot(record)\n return rootNode ? isNodeEmpty(rootNode)(record) : true\n}\n\nexport const getStep = (record: ArenaRecord): string => record.step ?? RECORD_STEP_DEFAULT\n\nexport const isInAnalysisStep = (record: ArenaRecord): boolean => getStep(record) === RecordStepAnalysisCode\n"]}
|
|
@@ -2,11 +2,11 @@ import * as RecordGetters from './recordGetters';
|
|
|
2
2
|
import { RecordNodesIndexUpdater } from './recordNodesIndexUpdater';
|
|
3
3
|
import { RecordUpdateOptionsDefaults } from './recordUpdateOptions';
|
|
4
4
|
export const addNodes = (nodes, options = RecordUpdateOptionsDefaults) => (record) => {
|
|
5
|
-
var _a;
|
|
6
5
|
const { sideEffect, updateNodesIndex, sortNodes } = Object.assign(Object.assign({}, RecordUpdateOptionsDefaults), options);
|
|
7
6
|
const recordUpdated = sideEffect ? record : Object.assign({}, record);
|
|
8
7
|
const recordNodes = RecordGetters.getNodes(recordUpdated);
|
|
9
|
-
|
|
8
|
+
// index got before adding the new nodes (a missing index is built from the current record nodes)
|
|
9
|
+
const index = updateNodesIndex ? RecordGetters.getNodesIndexOrBuild(recordUpdated) : {};
|
|
10
10
|
// index only the nodes not already indexed with the same parent, node def and hierarchy code
|
|
11
11
|
// (e.g. nodes with only an updated value don't need any index change)
|
|
12
12
|
const nodesToIndex = {};
|