@openforis/arena-core 2.17.0 → 2.18.1
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/error/systemErrorKeys.d.ts +2 -0
- package/dist/error/systemErrorKeys.js +2 -0
- package/dist/error/systemErrorKeys.js.map +1 -1
- package/dist/esm/error/systemErrorKeys.js +2 -0
- package/dist/esm/error/systemErrorKeys.js.map +1 -1
- 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 +34 -0
- 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/expression/javascript/node/literal.js +7 -1
- package/dist/esm/expression/javascript/node/literal.js.map +1 -1
- package/dist/esm/expression/javascript/regExpSafety.js +82 -0
- package/dist/esm/expression/javascript/regExpSafety.js.map +1 -0
- package/dist/esm/nodeDefExpressionEvaluator/functions.js +10 -8
- package/dist/esm/nodeDefExpressionEvaluator/functions.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 +34 -0
- 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/expression/javascript/node/literal.js +7 -1
- package/dist/expression/javascript/node/literal.js.map +1 -1
- package/dist/expression/javascript/regExpSafety.d.ts +12 -0
- package/dist/expression/javascript/regExpSafety.js +86 -0
- package/dist/expression/javascript/regExpSafety.js.map +1 -0
- package/dist/nodeDefExpressionEvaluator/functions.js +10 -8
- package/dist/nodeDefExpressionEvaluator/functions.js.map +1 -1
- package/package.json +1 -1
|
@@ -19,7 +19,9 @@ export declare const SystemErrorKeys: {
|
|
|
19
19
|
readonly multipleNodesFoundForNodeDef: 'expression.multipleNodesFoundForNodeDef';
|
|
20
20
|
readonly nodeNotFoundForNodeDef: 'expression.nodeNotFoundForNodeDef';
|
|
21
21
|
readonly notSupported: 'expression.notSupported';
|
|
22
|
+
readonly regularExpressionInputTooLong: 'expression.regularExpressionInputTooLong';
|
|
22
23
|
readonly unaryOperatorNotSupported: 'expression.unaryOperatorNotSupported';
|
|
24
|
+
readonly unsafeRegularExpression: 'expression.unsafeRegularExpression';
|
|
23
25
|
readonly undefinedFunction: 'expression.undefinedFunction';
|
|
24
26
|
readonly unsupportedFunctionType: 'expression.unsupportedFunctionType';
|
|
25
27
|
};
|
|
@@ -22,7 +22,9 @@ exports.SystemErrorKeys = {
|
|
|
22
22
|
multipleNodesFoundForNodeDef: 'expression.multipleNodesFoundForNodeDef',
|
|
23
23
|
nodeNotFoundForNodeDef: 'expression.nodeNotFoundForNodeDef',
|
|
24
24
|
notSupported: 'expression.notSupported',
|
|
25
|
+
regularExpressionInputTooLong: 'expression.regularExpressionInputTooLong',
|
|
25
26
|
unaryOperatorNotSupported: 'expression.unaryOperatorNotSupported',
|
|
27
|
+
unsafeRegularExpression: 'expression.unsafeRegularExpression',
|
|
26
28
|
undefinedFunction: 'expression.undefinedFunction',
|
|
27
29
|
unsupportedFunctionType: 'expression.unsupportedFunctionType',
|
|
28
30
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemErrorKeys.js","sourceRoot":"","sources":["../../src/error/systemErrorKeys.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,eAAe,GAAG;IAC7B,UAAU,EAAE;QACV,sBAAsB,EAAE,mCAAmC;QAC3D,2BAA2B,EAAE,wCAAwC;QACrE,0BAA0B,EAAE,uCAAuC;QACnE,2BAA2B,EAAE,wCAAwC;QACrE,kBAAkB,EAAE,+BAA+B;QACnD,iCAAiC,EAAE,8CAA8C;QACjF,iBAAiB,EAAE,8BAA8B;QACjD,wBAAwB,EAAE,qCAAqC;QAC/D,mBAAmB,EAAE,gCAAgC;QACrD,sCAAsC,EAAE,mDAAmD;QAC3F,wBAAwB,EAAE,qCAAqC;QAC/D,mBAAmB,EAAE,gCAAgC;QACrD,yBAAyB,EAAE,sCAAsC;QACjE,4BAA4B,EAAE,yCAAyC;QACvE,sBAAsB,EAAE,mCAAmC;QAC3D,YAAY,EAAE,yBAAyB;QACvC,yBAAyB,EAAE,sCAAsC;QACjE,iBAAiB,EAAE,8BAA8B;QACjD,uBAAuB,EAAE,oCAAoC;KAC9D;IACD,GAAG,EAAE;QACH,cAAc,EAAE,oBAAoB;QACpC,WAAW,EAAE,iBAAiB;QAC9B,eAAe,EAAE,qBAAqB;KACvC;IACD,GAAG,EAAE;QACH,qBAAqB,EAAE,0BAA0B;KAClD;IACD,OAAO,EAAE;QACP,2BAA2B,EAAE,qCAAqC;QAClE,cAAc,EAAE,wBAAwB;KACzC;IACD,MAAM,EAAE;QACN,qBAAqB,EAAE,+CAA+C;QACtE,sBAAsB,EAAE,+BAA+B;QACvD,kBAAkB,EAAE,uCAAuC;QAC3D,YAAY,EAAE,qBAAqB;QACnC,wBAAwB,EAAE,iCAAiC;QAC3D,oCAAoC,EAAE,6CAA6C;QACnF,gCAAgC,EAAE,yCAAyC;KAC5E;IACD,MAAM,EAAE;QACN,aAAa,EAAE,sBAAsB;QACrC,mBAAmB,EAAE,4BAA4B;QACjD,mBAAmB,EAAE,4BAA4B;QACjD,eAAe,EAAE,wBAAwB;KAC1C;CACO,CAAA","sourcesContent":["/**\n * Keys of the errors thrown by arena-core as SystemError (translatable, see SystemError.key).\n */\nexport const SystemErrorKeys = {\n expression: {\n areaOfInterestNotFound: 'expression.areaOfInterestNotFound',\n booleanOperatorNotSupported: 'expression.booleanOperatorNotSupported',\n functionHasTooFewArguments: 'expression.functionHasTooFewArguments',\n functionHasTooManyArguments: 'expression.functionHasTooManyArguments',\n identifierNotFound: 'expression.identifierNotFound',\n invalidAttributeValuePropertyName: 'expression.invalidAttributeValuePropertyName',\n invalidCalleeType: 'expression.invalidCalleeType',\n invalidCategoryExtraProp: 'expression.invalidCategoryExtraProp',\n invalidCategoryName: 'expression.invalidCategoryName',\n invalidTaxonVernacularNameLanguageCode: 'expression.invalidTaxonVernacularNameLanguageCode',\n invalidTaxonomyExtraProp: 'expression.invalidTaxonomyExtraProp',\n invalidTaxonomyName: 'expression.invalidTaxonomyName',\n missingFunctionParameters: 'expression.missingFunctionParameters',\n multipleNodesFoundForNodeDef: 'expression.multipleNodesFoundForNodeDef',\n nodeNotFoundForNodeDef: 'expression.nodeNotFoundForNodeDef',\n notSupported: 'expression.notSupported',\n unaryOperatorNotSupported: 'expression.unaryOperatorNotSupported',\n undefinedFunction: 'expression.undefinedFunction',\n unsupportedFunctionType: 'expression.unsupportedFunctionType',\n },\n geo: {\n pointNotFilled: 'geo.pointNotFilled',\n srsNotFound: 'geo.srsNotFound',\n transformFailed: 'geo.transformFailed',\n },\n job: {\n canceledOrErrorsFound: 'jobCanceledOrErrorsFound',\n },\n nodeDef: {\n hierarchyCircularDependency: 'nodeDef.hierarchyCircularDependency',\n parentNotFound: 'nodeDef.parentNotFound',\n },\n record: {\n dependencyOnRootFound: 'record.nodes.dependents.dependencyOnRootFound',\n enumeratorNodeNotFound: 'record.enumeratorNodeNotFound',\n multipleNodesFound: 'systemError.record.multipleNodesFound',\n nodeNotFound: 'record.nodeNotFound',\n nodesIndexNotInitialized: 'record.nodesIndexNotInitialized',\n updateSelfAndDependentsDefaultValues: 'record.updateSelfAndDependentsDefaultValues',\n updateSelfAndDependentsFileNames: 'record.updateSelfAndDependentsFileNames',\n },\n survey: {\n emptyNodeDefs: 'survey.emptyNodeDefs',\n nodeDefNameNotFound: 'survey.nodeDefNameNotFound',\n nodeDefUuidNotFound: 'survey.nodeDefUuidNotFound',\n rootDefNotFound: 'survey.rootDefNotFound',\n },\n} as const\n"]}
|
|
1
|
+
{"version":3,"file":"systemErrorKeys.js","sourceRoot":"","sources":["../../src/error/systemErrorKeys.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EAAE,4BAA4B;QACjD,eAAe,EAAE,wBAAwB;KAC1C;CACO,CAAA","sourcesContent":["/**\n * Keys of the errors thrown by arena-core as SystemError (translatable, see SystemError.key).\n */\nexport const SystemErrorKeys = {\n expression: {\n areaOfInterestNotFound: 'expression.areaOfInterestNotFound',\n booleanOperatorNotSupported: 'expression.booleanOperatorNotSupported',\n functionHasTooFewArguments: 'expression.functionHasTooFewArguments',\n functionHasTooManyArguments: 'expression.functionHasTooManyArguments',\n identifierNotFound: 'expression.identifierNotFound',\n invalidAttributeValuePropertyName: 'expression.invalidAttributeValuePropertyName',\n invalidCalleeType: 'expression.invalidCalleeType',\n invalidCategoryExtraProp: 'expression.invalidCategoryExtraProp',\n invalidCategoryName: 'expression.invalidCategoryName',\n invalidTaxonVernacularNameLanguageCode: 'expression.invalidTaxonVernacularNameLanguageCode',\n invalidTaxonomyExtraProp: 'expression.invalidTaxonomyExtraProp',\n invalidTaxonomyName: 'expression.invalidTaxonomyName',\n missingFunctionParameters: 'expression.missingFunctionParameters',\n multipleNodesFoundForNodeDef: 'expression.multipleNodesFoundForNodeDef',\n nodeNotFoundForNodeDef: 'expression.nodeNotFoundForNodeDef',\n notSupported: 'expression.notSupported',\n regularExpressionInputTooLong: 'expression.regularExpressionInputTooLong',\n unaryOperatorNotSupported: 'expression.unaryOperatorNotSupported',\n unsafeRegularExpression: 'expression.unsafeRegularExpression',\n undefinedFunction: 'expression.undefinedFunction',\n unsupportedFunctionType: 'expression.unsupportedFunctionType',\n },\n geo: {\n pointNotFilled: 'geo.pointNotFilled',\n srsNotFound: 'geo.srsNotFound',\n transformFailed: 'geo.transformFailed',\n },\n job: {\n canceledOrErrorsFound: 'jobCanceledOrErrorsFound',\n },\n nodeDef: {\n hierarchyCircularDependency: 'nodeDef.hierarchyCircularDependency',\n parentNotFound: 'nodeDef.parentNotFound',\n },\n record: {\n dependencyOnRootFound: 'record.nodes.dependents.dependencyOnRootFound',\n enumeratorNodeNotFound: 'record.enumeratorNodeNotFound',\n multipleNodesFound: 'systemError.record.multipleNodesFound',\n nodeNotFound: 'record.nodeNotFound',\n nodesIndexNotInitialized: 'record.nodesIndexNotInitialized',\n updateSelfAndDependentsDefaultValues: 'record.updateSelfAndDependentsDefaultValues',\n updateSelfAndDependentsFileNames: 'record.updateSelfAndDependentsFileNames',\n },\n survey: {\n emptyNodeDefs: 'survey.emptyNodeDefs',\n nodeDefNameNotFound: 'survey.nodeDefNameNotFound',\n nodeDefUuidNotFound: 'survey.nodeDefUuidNotFound',\n rootDefNotFound: 'survey.rootDefNotFound',\n },\n} as const\n"]}
|
|
@@ -19,7 +19,9 @@ export const SystemErrorKeys = {
|
|
|
19
19
|
multipleNodesFoundForNodeDef: 'expression.multipleNodesFoundForNodeDef',
|
|
20
20
|
nodeNotFoundForNodeDef: 'expression.nodeNotFoundForNodeDef',
|
|
21
21
|
notSupported: 'expression.notSupported',
|
|
22
|
+
regularExpressionInputTooLong: 'expression.regularExpressionInputTooLong',
|
|
22
23
|
unaryOperatorNotSupported: 'expression.unaryOperatorNotSupported',
|
|
24
|
+
unsafeRegularExpression: 'expression.unsafeRegularExpression',
|
|
23
25
|
undefinedFunction: 'expression.undefinedFunction',
|
|
24
26
|
unsupportedFunctionType: 'expression.unsupportedFunctionType',
|
|
25
27
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemErrorKeys.js","sourceRoot":"","sources":["../../../src/error/systemErrorKeys.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,UAAU,EAAE;QACV,sBAAsB,EAAE,mCAAmC;QAC3D,2BAA2B,EAAE,wCAAwC;QACrE,0BAA0B,EAAE,uCAAuC;QACnE,2BAA2B,EAAE,wCAAwC;QACrE,kBAAkB,EAAE,+BAA+B;QACnD,iCAAiC,EAAE,8CAA8C;QACjF,iBAAiB,EAAE,8BAA8B;QACjD,wBAAwB,EAAE,qCAAqC;QAC/D,mBAAmB,EAAE,gCAAgC;QACrD,sCAAsC,EAAE,mDAAmD;QAC3F,wBAAwB,EAAE,qCAAqC;QAC/D,mBAAmB,EAAE,gCAAgC;QACrD,yBAAyB,EAAE,sCAAsC;QACjE,4BAA4B,EAAE,yCAAyC;QACvE,sBAAsB,EAAE,mCAAmC;QAC3D,YAAY,EAAE,yBAAyB;QACvC,yBAAyB,EAAE,sCAAsC;QACjE,iBAAiB,EAAE,8BAA8B;QACjD,uBAAuB,EAAE,oCAAoC;KAC9D;IACD,GAAG,EAAE;QACH,cAAc,EAAE,oBAAoB;QACpC,WAAW,EAAE,iBAAiB;QAC9B,eAAe,EAAE,qBAAqB;KACvC;IACD,GAAG,EAAE;QACH,qBAAqB,EAAE,0BAA0B;KAClD;IACD,OAAO,EAAE;QACP,2BAA2B,EAAE,qCAAqC;QAClE,cAAc,EAAE,wBAAwB;KACzC;IACD,MAAM,EAAE;QACN,qBAAqB,EAAE,+CAA+C;QACtE,sBAAsB,EAAE,+BAA+B;QACvD,kBAAkB,EAAE,uCAAuC;QAC3D,YAAY,EAAE,qBAAqB;QACnC,wBAAwB,EAAE,iCAAiC;QAC3D,oCAAoC,EAAE,6CAA6C;QACnF,gCAAgC,EAAE,yCAAyC;KAC5E;IACD,MAAM,EAAE;QACN,aAAa,EAAE,sBAAsB;QACrC,mBAAmB,EAAE,4BAA4B;QACjD,mBAAmB,EAAE,4BAA4B;QACjD,eAAe,EAAE,wBAAwB;KAC1C;CACO,CAAA","sourcesContent":["/**\n * Keys of the errors thrown by arena-core as SystemError (translatable, see SystemError.key).\n */\nexport const SystemErrorKeys = {\n expression: {\n areaOfInterestNotFound: 'expression.areaOfInterestNotFound',\n booleanOperatorNotSupported: 'expression.booleanOperatorNotSupported',\n functionHasTooFewArguments: 'expression.functionHasTooFewArguments',\n functionHasTooManyArguments: 'expression.functionHasTooManyArguments',\n identifierNotFound: 'expression.identifierNotFound',\n invalidAttributeValuePropertyName: 'expression.invalidAttributeValuePropertyName',\n invalidCalleeType: 'expression.invalidCalleeType',\n invalidCategoryExtraProp: 'expression.invalidCategoryExtraProp',\n invalidCategoryName: 'expression.invalidCategoryName',\n invalidTaxonVernacularNameLanguageCode: 'expression.invalidTaxonVernacularNameLanguageCode',\n invalidTaxonomyExtraProp: 'expression.invalidTaxonomyExtraProp',\n invalidTaxonomyName: 'expression.invalidTaxonomyName',\n missingFunctionParameters: 'expression.missingFunctionParameters',\n multipleNodesFoundForNodeDef: 'expression.multipleNodesFoundForNodeDef',\n nodeNotFoundForNodeDef: 'expression.nodeNotFoundForNodeDef',\n notSupported: 'expression.notSupported',\n unaryOperatorNotSupported: 'expression.unaryOperatorNotSupported',\n undefinedFunction: 'expression.undefinedFunction',\n unsupportedFunctionType: 'expression.unsupportedFunctionType',\n },\n geo: {\n pointNotFilled: 'geo.pointNotFilled',\n srsNotFound: 'geo.srsNotFound',\n transformFailed: 'geo.transformFailed',\n },\n job: {\n canceledOrErrorsFound: 'jobCanceledOrErrorsFound',\n },\n nodeDef: {\n hierarchyCircularDependency: 'nodeDef.hierarchyCircularDependency',\n parentNotFound: 'nodeDef.parentNotFound',\n },\n record: {\n dependencyOnRootFound: 'record.nodes.dependents.dependencyOnRootFound',\n enumeratorNodeNotFound: 'record.enumeratorNodeNotFound',\n multipleNodesFound: 'systemError.record.multipleNodesFound',\n nodeNotFound: 'record.nodeNotFound',\n nodesIndexNotInitialized: 'record.nodesIndexNotInitialized',\n updateSelfAndDependentsDefaultValues: 'record.updateSelfAndDependentsDefaultValues',\n updateSelfAndDependentsFileNames: 'record.updateSelfAndDependentsFileNames',\n },\n survey: {\n emptyNodeDefs: 'survey.emptyNodeDefs',\n nodeDefNameNotFound: 'survey.nodeDefNameNotFound',\n nodeDefUuidNotFound: 'survey.nodeDefUuidNotFound',\n rootDefNotFound: 'survey.rootDefNotFound',\n },\n} as const\n"]}
|
|
1
|
+
{"version":3,"file":"systemErrorKeys.js","sourceRoot":"","sources":["../../../src/error/systemErrorKeys.ts"],"names":[],"mappings":"AAAA;;G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ACjD,eAAe,EAAE,wBAAwB;KAC1C;CACO,CAAA","sourcesContent":["/**\n * Keys of the errors thrown by arena-core as SystemError (translatable, see SystemError.key).\n */\nexport const SystemErrorKeys = {\n expression: {\n areaOfInterestNotFound: 'expression.areaOfInterestNotFound',\n booleanOperatorNotSupported: 'expression.booleanOperatorNotSupported',\n functionHasTooFewArguments: 'expression.functionHasTooFewArguments',\n functionHasTooManyArguments: 'expression.functionHasTooManyArguments',\n identifierNotFound: 'expression.identifierNotFound',\n invalidAttributeValuePropertyName: 'expression.invalidAttributeValuePropertyName',\n invalidCalleeType: 'expression.invalidCalleeType',\n invalidCategoryExtraProp: 'expression.invalidCategoryExtraProp',\n invalidCategoryName: 'expression.invalidCategoryName',\n invalidTaxonVernacularNameLanguageCode: 'expression.invalidTaxonVernacularNameLanguageCode',\n invalidTaxonomyExtraProp: 'expression.invalidTaxonomyExtraProp',\n invalidTaxonomyName: 'expression.invalidTaxonomyName',\n missingFunctionParameters: 'expression.missingFunctionParameters',\n multipleNodesFoundForNodeDef: 'expression.multipleNodesFoundForNodeDef',\n nodeNotFoundForNodeDef: 'expression.nodeNotFoundForNodeDef',\n notSupported: 'expression.notSupported',\n regularExpressionInputTooLong: 'expression.regularExpressionInputTooLong',\n unaryOperatorNotSupported: 'expression.unaryOperatorNotSupported',\n unsafeRegularExpression: 'expression.unsafeRegularExpression',\n undefinedFunction: 'expression.undefinedFunction',\n unsupportedFunctionType: 'expression.unsupportedFunctionType',\n },\n geo: {\n pointNotFilled: 'geo.pointNotFilled',\n srsNotFound: 'geo.srsNotFound',\n transformFailed: 'geo.transformFailed',\n },\n job: {\n canceledOrErrorsFound: 'jobCanceledOrErrorsFound',\n },\n nodeDef: {\n hierarchyCircularDependency: 'nodeDef.hierarchyCircularDependency',\n parentNotFound: 'nodeDef.parentNotFound',\n },\n record: {\n dependencyOnRootFound: 'record.nodes.dependents.dependencyOnRootFound',\n enumeratorNodeNotFound: 'record.enumeratorNodeNotFound',\n multipleNodesFound: 'systemError.record.multipleNodesFound',\n nodeNotFound: 'record.nodeNotFound',\n nodesIndexNotInitialized: 'record.nodesIndexNotInitialized',\n updateSelfAndDependentsDefaultValues: 'record.updateSelfAndDependentsDefaultValues',\n updateSelfAndDependentsFileNames: 'record.updateSelfAndDependentsFileNames',\n },\n survey: {\n emptyNodeDefs: 'survey.emptyNodeDefs',\n nodeDefNameNotFound: 'survey.nodeDefNameNotFound',\n nodeDefUuidNotFound: 'survey.nodeDefUuidNotFound',\n rootDefNotFound: 'survey.rootDefNotFound',\n },\n} as const\n"]}
|
|
@@ -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":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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,6 +10,35 @@ 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 { 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
|
+
};
|
|
29
|
+
// e.g. /.../.test(text) or text.match(/.../): the time taken by a regular expression grows with the input length
|
|
30
|
+
const checkRegExpInputLength = (fnObject, args, regExpStringPattern) => {
|
|
31
|
+
const values = [fnObject, ...args];
|
|
32
|
+
if (!regExpStringPattern && !values.some((value) => value instanceof RegExp))
|
|
33
|
+
return;
|
|
34
|
+
const inputTooLong = values.find((value) => typeof value === 'string' && value.length > REG_EXP_INPUT_MAX_LENGTH);
|
|
35
|
+
if (inputTooLong !== undefined) {
|
|
36
|
+
throw new SystemError(SystemErrorKeys.expression.regularExpressionInputTooLong, {
|
|
37
|
+
maxLength: REG_EXP_INPUT_MAX_LENGTH,
|
|
38
|
+
length: inputTooLong.length,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
13
42
|
export class CallEvaluator extends ExpressionNodeEvaluator {
|
|
14
43
|
evaluate(expressionNode) {
|
|
15
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -35,6 +64,11 @@ export class CallEvaluator extends ExpressionNodeEvaluator {
|
|
|
35
64
|
const fnObject = yield this.evaluator.evaluateNode(calleeObj, this.context);
|
|
36
65
|
const argsEvaluated = yield Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, this.context)));
|
|
37
66
|
const args = argsEvaluated.flat();
|
|
67
|
+
const regExpStringPattern = isRegExpStringPatternCall(callee, args);
|
|
68
|
+
if (regExpStringPattern) {
|
|
69
|
+
checkRegExpStringPattern(args[0]);
|
|
70
|
+
}
|
|
71
|
+
checkRegExpInputLength(fnObject, args, regExpStringPattern);
|
|
38
72
|
return fn.call(fnObject, ...args);
|
|
39
73
|
}
|
|
40
74
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../../../../src/expression/javascript/node/call.ts"],"names":[],"mappings":";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E,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'\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 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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C,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,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE9F,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,MAAW,EAAE,EAAE;IACtD,IAAI,uBAAuB,CAAC,IAAI,CAAC,IAAI,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;QAC9D,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,IAAI,CAAC,CAAA;IAC3B,IAAI,IAAI,KAAK,SAAS,IAAI,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC;QACjD,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,OAAO,OAAO,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC9D,CAAC,CAAA;AAED,MAAM,OAAO,mBAAiD,SAAQ,uBAAgD;IACpH;;;;;;OAMG;IACO,0BAA0B,CAAC,cAAoC;QACvE,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAA;QAC/B,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,OAAO,CAAA;QAE9C,MAAM,UAAU,GAAG,uBAAuB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;QAC/D,IAAI,UAAU,KAAK,IAAI,EAAE,CAAC;YACxB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAA;QAC9B,CAAC;QACD,MAAM,cAAc,GAAG,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;QAC7D,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,CAAA;QAClC,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;IAED,QAAQ,CAAC,cAAoC;QAC3C,MAAM,QAAQ,GAAG,IAAI,CAAC,0BAA0B,CAAC,cAAc,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"]}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
+
import { SystemError, SystemErrorKeys } from '../../../error';
|
|
1
2
|
import { ExpressionNodeEvaluator } from '../../node';
|
|
3
|
+
import { hasNestedQuantifiers } from '../regExpSafety';
|
|
2
4
|
export class LiteralEvaluator extends ExpressionNodeEvaluator {
|
|
3
5
|
evaluate(expressionNode) {
|
|
4
|
-
|
|
6
|
+
const { value } = expressionNode;
|
|
7
|
+
if (value instanceof RegExp && hasNestedQuantifiers(value.source)) {
|
|
8
|
+
return Promise.reject(new SystemError(SystemErrorKeys.expression.unsafeRegularExpression, { pattern: value.source }));
|
|
9
|
+
}
|
|
10
|
+
return Promise.resolve(value);
|
|
5
11
|
}
|
|
6
12
|
}
|
|
7
13
|
//# sourceMappingURL=literal.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../../../src/expression/javascript/node/literal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../../../src/expression/javascript/node/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAE7D,OAAO,EAAE,uBAAuB,EAAqB,MAAM,YAAY,CAAA;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AAEtD,MAAM,OAAO,gBAA8C,SAAQ,uBAA6C;IAC9G,QAAQ,CAAC,cAAiC;QACxC,MAAM,EAAE,KAAK,EAAE,GAAG,cAAc,CAAA;QAChC,IAAI,KAAK,YAAY,MAAM,IAAI,oBAAoB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAClE,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,WAAW,CAAC,eAAe,CAAC,UAAU,CAAC,uBAAuB,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAC/F,CAAA;QACH,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;CACF","sourcesContent":["import { SystemError, SystemErrorKeys } from '../../../error'\nimport { ExpressionContext } from '../../context'\nimport { ExpressionNodeEvaluator, LiteralExpression } from '../../node'\nimport { hasNestedQuantifiers } from '../regExpSafety'\n\nexport class LiteralEvaluator<C extends ExpressionContext> extends ExpressionNodeEvaluator<C, LiteralExpression> {\n evaluate(expressionNode: LiteralExpression): Promise<any> {\n const { value } = expressionNode\n if (value instanceof RegExp && hasNestedQuantifiers(value.source)) {\n return Promise.reject(\n new SystemError(SystemErrorKeys.expression.unsafeRegularExpression, { pattern: value.source })\n )\n }\n return Promise.resolve(value)\n }\n}\n"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protection against regular expressions that can take exponential time (ReDoS): JavaScript cannot interrupt a
|
|
3
|
+
* running regular expression, so a single evaluation could freeze the server or the browser.
|
|
4
|
+
*/
|
|
5
|
+
// maximum length of the strings that regular expressions are applied to in expressions
|
|
6
|
+
export const REG_EXP_INPUT_MAX_LENGTH = 1000;
|
|
7
|
+
// unbounded quantifier at the given position: *, + or {n,} (quantifiers like {n} or {n,m} are bounded)
|
|
8
|
+
const unboundedQuantifierRegExp = /^(\*|\+|\{\d+,\})/;
|
|
9
|
+
const isQuantifierAt = (source, index) => {
|
|
10
|
+
const char = source[index];
|
|
11
|
+
if (char === '*' || char === '+')
|
|
12
|
+
return true;
|
|
13
|
+
// {n,m} or {n,} (exact {n} repetitions don't multiply the ways a string can be matched)
|
|
14
|
+
return char === '{' && /^\{\d+,\d*\}/.test(source.substring(index));
|
|
15
|
+
};
|
|
16
|
+
const skipEscape = (index) => index + 2;
|
|
17
|
+
const skipCharacterClass = (source, index) => {
|
|
18
|
+
let i = index + 1;
|
|
19
|
+
while (i < source.length && source[i] !== ']') {
|
|
20
|
+
i = source[i] === '\\' ? skipEscape(i) : i + 1;
|
|
21
|
+
}
|
|
22
|
+
return i + 1;
|
|
23
|
+
};
|
|
24
|
+
// marks the innermost open group (if any) as containing a quantifier
|
|
25
|
+
const markInnermostGroupQuantified = (groupsStack) => {
|
|
26
|
+
if (groupsStack.length > 0) {
|
|
27
|
+
groupsStack[groupsStack.length - 1] = true;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Closes the group ending at the specified index (position of the ")").
|
|
32
|
+
* Returns true if the group contains a quantifier and it's repeated by an unbounded quantifier.
|
|
33
|
+
*/
|
|
34
|
+
const closeGroup = (source, index, groupsStack) => {
|
|
35
|
+
var _a;
|
|
36
|
+
const groupContainsQuantifier = (_a = groupsStack.pop()) !== null && _a !== void 0 ? _a : false;
|
|
37
|
+
if (groupContainsQuantifier && unboundedQuantifierRegExp.test(source.substring(index + 1))) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (groupContainsQuantifier || isQuantifierAt(source, index + 1)) {
|
|
41
|
+
markInnermostGroupQuantified(groupsStack);
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Returns true if the specified regular expression source contains a group repeated by an unbounded quantifier
|
|
47
|
+
* that contains a quantifier itself (star height > 1), e.g. (a+)+, (\w*)* or (x{1,3})+:
|
|
48
|
+
* these patterns can take exponential time on non-matching strings.
|
|
49
|
+
* Overlapping alternations like (a|aa)+ are not detected.
|
|
50
|
+
*/
|
|
51
|
+
export const hasNestedQuantifiers = (source) => {
|
|
52
|
+
// for each open group: true if it contains a quantifier
|
|
53
|
+
const groupsStack = [];
|
|
54
|
+
let i = 0;
|
|
55
|
+
while (i < source.length) {
|
|
56
|
+
switch (source[i]) {
|
|
57
|
+
case '\\':
|
|
58
|
+
i = skipEscape(i);
|
|
59
|
+
break;
|
|
60
|
+
case '[':
|
|
61
|
+
i = skipCharacterClass(source, i);
|
|
62
|
+
break;
|
|
63
|
+
case '(':
|
|
64
|
+
groupsStack.push(false);
|
|
65
|
+
// a "?" right after "(" introduces a group modifier (e.g. "(?:"), it's not a quantifier
|
|
66
|
+
i += source[i + 1] === '?' ? 2 : 1;
|
|
67
|
+
break;
|
|
68
|
+
case ')':
|
|
69
|
+
if (closeGroup(source, i, groupsStack))
|
|
70
|
+
return true;
|
|
71
|
+
i += 1;
|
|
72
|
+
break;
|
|
73
|
+
default:
|
|
74
|
+
if (isQuantifierAt(source, i)) {
|
|
75
|
+
markInnermostGroupQuantified(groupsStack);
|
|
76
|
+
}
|
|
77
|
+
i += 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=regExpSafety.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regExpSafety.js","sourceRoot":"","sources":["../../../../src/expression/javascript/regExpSafety.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uFAAuF;AACvF,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAA;AAE5C,uGAAuG;AACvG,MAAM,yBAAyB,GAAG,mBAAmB,CAAA;AAErD,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,KAAa,EAAW,EAAE;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC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/**\n * Protection against regular expressions that can take exponential time (ReDoS): JavaScript cannot interrupt a\n * running regular expression, so a single evaluation could freeze the server or the browser.\n */\n\n// maximum length of the strings that regular expressions are applied to in expressions\nexport const REG_EXP_INPUT_MAX_LENGTH = 1000\n\n// unbounded quantifier at the given position: *, + or {n,} (quantifiers like {n} or {n,m} are bounded)\nconst unboundedQuantifierRegExp = /^(\\*|\\+|\\{\\d+,\\})/\n\nconst isQuantifierAt = (source: string, index: number): boolean => {\n const char = source[index]\n if (char === '*' || char === '+') return true\n // {n,m} or {n,} (exact {n} repetitions don't multiply the ways a string can be matched)\n return char === '{' && /^\\{\\d+,\\d*\\}/.test(source.substring(index))\n}\n\nconst skipEscape = (index: number): number => index + 2\n\nconst skipCharacterClass = (source: string, index: number): number => {\n let i = index + 1\n while (i < source.length && source[i] !== ']') {\n i = source[i] === '\\\\' ? skipEscape(i) : i + 1\n }\n return i + 1\n}\n\n// marks the innermost open group (if any) as containing a quantifier\nconst markInnermostGroupQuantified = (groupsStack: boolean[]): void => {\n if (groupsStack.length > 0) {\n groupsStack[groupsStack.length - 1] = true\n }\n}\n\n/**\n * Closes the group ending at the specified index (position of the \")\").\n * Returns true if the group contains a quantifier and it's repeated by an unbounded quantifier.\n */\nconst closeGroup = (source: string, index: number, groupsStack: boolean[]): boolean => {\n const groupContainsQuantifier = groupsStack.pop() ?? false\n if (groupContainsQuantifier && unboundedQuantifierRegExp.test(source.substring(index + 1))) {\n return true\n }\n if (groupContainsQuantifier || isQuantifierAt(source, index + 1)) {\n markInnermostGroupQuantified(groupsStack)\n }\n return false\n}\n\n/**\n * Returns true if the specified regular expression source contains a group repeated by an unbounded quantifier\n * that contains a quantifier itself (star height > 1), e.g. (a+)+, (\\w*)* or (x{1,3})+:\n * these patterns can take exponential time on non-matching strings.\n * Overlapping alternations like (a|aa)+ are not detected.\n */\nexport const hasNestedQuantifiers = (source: string): boolean => {\n // for each open group: true if it contains a quantifier\n const groupsStack: boolean[] = []\n let i = 0\n while (i < source.length) {\n switch (source[i]) {\n case '\\\\':\n i = skipEscape(i)\n break\n case '[':\n i = skipCharacterClass(source, i)\n break\n case '(':\n groupsStack.push(false)\n // a \"?\" right after \"(\" introduces a group modifier (e.g. \"(?:\"), it's not a quantifier\n i += source[i + 1] === '?' ? 2 : 1\n break\n case ')':\n if (closeGroup(source, i, groupsStack)) return true\n i += 1\n break\n default:\n if (isQuantifierAt(source, i)) {\n markInnermostGroupQuantified(groupsStack)\n }\n i += 1\n }\n }\n return false\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,QAA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AAM,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,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QACrC,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 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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AAQ,EAAE;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC,OAAiC,EAAE,EAAE,CAAC,GAAG,EAAE,kBAAC,MAAA,OAAO,CAAC,IAAI,0CAAE,IAAI,GAAA;KAC1E;IACD,QAAQ,EAAE;QACR,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC;QACX,QAAQ,EAAE,CAAC,OAAiC,EAAE,EAAE,CAAC,CAAC,QAAgB,EAAE,EAAE;YACpE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;YAChC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI;gBAAE,OAAO,SAAS,CAAA;YACtC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;YACnC,MAAM,kBAAkB,GAAG,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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGlobalObjectProperty = exports.isForbiddenPropertyName = void 0;
|
|
3
|
+
exports.getGlobalObjectProperty = exports.isForbiddenValue = exports.isForbiddenPropertyName = void 0;
|
|
4
4
|
const error_1 = require("../../error");
|
|
5
5
|
const globalObjectsDictionary = {
|
|
6
6
|
Array,
|
|
@@ -14,6 +14,9 @@ const globalObjectsArray = Object.values(globalObjectsDictionary);
|
|
|
14
14
|
// properties leading to Object, Function or the prototypes would let an expression run arbitrary code
|
|
15
15
|
const isForbiddenPropertyName = (name) => name === 'constructor' || name === 'prototype' || name.startsWith('__');
|
|
16
16
|
exports.isForbiddenPropertyName = isForbiddenPropertyName;
|
|
17
|
+
// Object and Function (e.g. returned by a function or found as a property value) give access to the same capabilities
|
|
18
|
+
const isForbiddenValue = (value) => value === Object || value === Function;
|
|
19
|
+
exports.isForbiddenValue = isForbiddenValue;
|
|
17
20
|
const getGlobalObjectProperty = (name, object) => {
|
|
18
21
|
const globalObject = globalObjectsDictionary[name];
|
|
19
22
|
if (globalObject) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/expression/javascript/global.ts"],"names":[],"mappings":";;;AACA,uCAA0D;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;AAC/F,MAAM,uBAAuB,GAAG,CAAC,IAAY,EAAW,EAAE,CAC/D,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,WAAW,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;AAD5D,QAAA,uBAAuB,GAAvB,uBAAuB,CACqC;
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/expression/javascript/global.ts"],"names":[],"mappings":";;;AACA,uCAA0D;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{ 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"]}
|
|
@@ -13,6 +13,35 @@ exports.CallEvaluator = void 0;
|
|
|
13
13
|
const error_1 = require("../../../error");
|
|
14
14
|
const node_1 = require("../../node");
|
|
15
15
|
const global_1 = require("../global");
|
|
16
|
+
const regExpSafety_1 = require("../regExpSafety");
|
|
17
|
+
// String functions converting a string argument into a regular expression (replace, replaceAll and split don't)
|
|
18
|
+
const stringFunctionsWithRegExpArgument = new Set(['match', 'matchAll', 'search']);
|
|
19
|
+
// e.g. text.match('(a+)+$'): the string pattern is checked like a regular expression literal
|
|
20
|
+
const isRegExpStringPatternCall = (callee, args) => {
|
|
21
|
+
const { computed, property } = callee;
|
|
22
|
+
return (!computed &&
|
|
23
|
+
property.type === node_1.ExpressionNodeType.Identifier &&
|
|
24
|
+
stringFunctionsWithRegExpArgument.has(property.name) &&
|
|
25
|
+
typeof args[0] === 'string');
|
|
26
|
+
};
|
|
27
|
+
const checkRegExpStringPattern = (pattern) => {
|
|
28
|
+
if ((0, regExpSafety_1.hasNestedQuantifiers)(pattern)) {
|
|
29
|
+
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.unsafeRegularExpression, { pattern });
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// e.g. /.../.test(text) or text.match(/.../): the time taken by a regular expression grows with the input length
|
|
33
|
+
const checkRegExpInputLength = (fnObject, args, regExpStringPattern) => {
|
|
34
|
+
const values = [fnObject, ...args];
|
|
35
|
+
if (!regExpStringPattern && !values.some((value) => value instanceof RegExp))
|
|
36
|
+
return;
|
|
37
|
+
const inputTooLong = values.find((value) => typeof value === 'string' && value.length > regExpSafety_1.REG_EXP_INPUT_MAX_LENGTH);
|
|
38
|
+
if (inputTooLong !== undefined) {
|
|
39
|
+
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.regularExpressionInputTooLong, {
|
|
40
|
+
maxLength: regExpSafety_1.REG_EXP_INPUT_MAX_LENGTH,
|
|
41
|
+
length: inputTooLong.length,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
16
45
|
class CallEvaluator extends node_1.ExpressionNodeEvaluator {
|
|
17
46
|
evaluate(expressionNode) {
|
|
18
47
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -38,6 +67,11 @@ class CallEvaluator extends node_1.ExpressionNodeEvaluator {
|
|
|
38
67
|
const fnObject = yield this.evaluator.evaluateNode(calleeObj, this.context);
|
|
39
68
|
const argsEvaluated = yield Promise.all(exprArgs.map((arg) => this.evaluator.evaluateNode(arg, this.context)));
|
|
40
69
|
const args = argsEvaluated.flat();
|
|
70
|
+
const regExpStringPattern = isRegExpStringPatternCall(callee, args);
|
|
71
|
+
if (regExpStringPattern) {
|
|
72
|
+
checkRegExpStringPattern(args[0]);
|
|
73
|
+
}
|
|
74
|
+
checkRegExpInputLength(fnObject, args, regExpStringPattern);
|
|
41
75
|
return fn.call(fnObject, ...args);
|
|
42
76
|
}
|
|
43
77
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"call.js","sourceRoot":"","sources":["../../../../src/expression/javascript/node/call.ts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","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'\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 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,0CAA6D;AAG7D,qCAMmB;AACnB,sCAAmD;AACnD,kDAAgF;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,yBAAkB,CAAC,UAAU;QAC/C,iCAAiC,CAAC,GAAG,CAAE,QAAiC,CAAC,IA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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"]}
|
|
@@ -5,11 +5,11 @@ const error_1 = require("../../../error");
|
|
|
5
5
|
const node_1 = require("../../node");
|
|
6
6
|
const global_1 = require("../global");
|
|
7
7
|
const getNativeProperty = (name, object) => {
|
|
8
|
-
if ((0, global_1.isForbiddenPropertyName)(name)) {
|
|
8
|
+
if ((0, global_1.isForbiddenPropertyName)(name) || (0, global_1.isForbiddenValue)(object)) {
|
|
9
9
|
return undefined;
|
|
10
10
|
}
|
|
11
11
|
const prop = object === null || object === void 0 ? void 0 : object[name];
|
|
12
|
-
if (prop === undefined) {
|
|
12
|
+
if (prop === undefined || (0, global_1.isForbiddenValue)(prop)) {
|
|
13
13
|
return undefined;
|
|
14
14
|
}
|
|
15
15
|
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,0CAA6D;AAE7D,qCAA0E;AAC1E,
|
|
1
|
+
{"version":3,"file":"identifier.js","sourceRoot":"","sources":["../../../../src/expression/javascript/node/identifier.ts"],"names":[],"mappings":";;;AAAA,0CAA6D;AAE7D,qCAA0E;AAC1E,sCAA8F;AAE9F,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,MAAW,EAAE,EAAE;IACtD,IAAI,IAAA,gCAAuB,EAAC,IAAI,CAAC,IAAI,IAAA,yBAAgB,EAAC,MAAM,CA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e,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"]}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiteralEvaluator = void 0;
|
|
4
|
+
const error_1 = require("../../../error");
|
|
4
5
|
const node_1 = require("../../node");
|
|
6
|
+
const regExpSafety_1 = require("../regExpSafety");
|
|
5
7
|
class LiteralEvaluator extends node_1.ExpressionNodeEvaluator {
|
|
6
8
|
evaluate(expressionNode) {
|
|
7
|
-
|
|
9
|
+
const { value } = expressionNode;
|
|
10
|
+
if (value instanceof RegExp && (0, regExpSafety_1.hasNestedQuantifiers)(value.source)) {
|
|
11
|
+
return Promise.reject(new error_1.SystemError(error_1.SystemErrorKeys.expression.unsafeRegularExpression, { pattern: value.source }));
|
|
12
|
+
}
|
|
13
|
+
return Promise.resolve(value);
|
|
8
14
|
}
|
|
9
15
|
}
|
|
10
16
|
exports.LiteralEvaluator = LiteralEvaluator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../../src/expression/javascript/node/literal.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"literal.js","sourceRoot":"","sources":["../../../../src/expression/javascript/node/literal.ts"],"names":[],"mappings":";;;AAAA,0CAA6D;AAE7D,qCAAuE;AACvE,kDAAsD;AAEtD,sBAA2D,SAAQ,8BAA6C;IAC9G,QAAQ,CAAC,cAAiC;QACxC,MAAM,EAAE,KAAK,EAAE,GAAG,cAAc,CAAA;QAChC,IAAI,KAAK,YAAY,MAAM,IAAI,IAAA,mCAAoB,EAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;YAClE,OAAO,OAAO,CAAC,MAAM,CACnB,IAAI,mBAAW,CAAC,uBAAe,CAAC,UAAU,CAAC,uBAAuB,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAC/F,CAAA;QACH,CAAC;QACD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;CACF","sourcesContent":["import { SystemError, SystemErrorKeys } from '../../../error'\nimport { ExpressionContext } from '../../context'\nimport { ExpressionNodeEvaluator, LiteralExpression } from '../../node'\nimport { hasNestedQuantifiers } from '../regExpSafety'\n\nexport class LiteralEvaluator<C extends ExpressionContext> extends ExpressionNodeEvaluator<C, LiteralExpression> {\n evaluate(expressionNode: LiteralExpression): Promise<any> {\n const { value } = expressionNode\n if (value instanceof RegExp && hasNestedQuantifiers(value.source)) {\n return Promise.reject(\n new SystemError(SystemErrorKeys.expression.unsafeRegularExpression, { pattern: value.source })\n )\n }\n return Promise.resolve(value)\n }\n}\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protection against regular expressions that can take exponential time (ReDoS): JavaScript cannot interrupt a
|
|
3
|
+
* running regular expression, so a single evaluation could freeze the server or the browser.
|
|
4
|
+
*/
|
|
5
|
+
export declare const REG_EXP_INPUT_MAX_LENGTH = 1000;
|
|
6
|
+
/**
|
|
7
|
+
* Returns true if the specified regular expression source contains a group repeated by an unbounded quantifier
|
|
8
|
+
* that contains a quantifier itself (star height > 1), e.g. (a+)+, (\w*)* or (x{1,3})+:
|
|
9
|
+
* these patterns can take exponential time on non-matching strings.
|
|
10
|
+
* Overlapping alternations like (a|aa)+ are not detected.
|
|
11
|
+
*/
|
|
12
|
+
export declare const hasNestedQuantifiers: (source: string) => boolean;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Protection against regular expressions that can take exponential time (ReDoS): JavaScript cannot interrupt a
|
|
4
|
+
* running regular expression, so a single evaluation could freeze the server or the browser.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.hasNestedQuantifiers = exports.REG_EXP_INPUT_MAX_LENGTH = void 0;
|
|
8
|
+
// maximum length of the strings that regular expressions are applied to in expressions
|
|
9
|
+
exports.REG_EXP_INPUT_MAX_LENGTH = 1000;
|
|
10
|
+
// unbounded quantifier at the given position: *, + or {n,} (quantifiers like {n} or {n,m} are bounded)
|
|
11
|
+
const unboundedQuantifierRegExp = /^(\*|\+|\{\d+,\})/;
|
|
12
|
+
const isQuantifierAt = (source, index) => {
|
|
13
|
+
const char = source[index];
|
|
14
|
+
if (char === '*' || char === '+')
|
|
15
|
+
return true;
|
|
16
|
+
// {n,m} or {n,} (exact {n} repetitions don't multiply the ways a string can be matched)
|
|
17
|
+
return char === '{' && /^\{\d+,\d*\}/.test(source.substring(index));
|
|
18
|
+
};
|
|
19
|
+
const skipEscape = (index) => index + 2;
|
|
20
|
+
const skipCharacterClass = (source, index) => {
|
|
21
|
+
let i = index + 1;
|
|
22
|
+
while (i < source.length && source[i] !== ']') {
|
|
23
|
+
i = source[i] === '\\' ? skipEscape(i) : i + 1;
|
|
24
|
+
}
|
|
25
|
+
return i + 1;
|
|
26
|
+
};
|
|
27
|
+
// marks the innermost open group (if any) as containing a quantifier
|
|
28
|
+
const markInnermostGroupQuantified = (groupsStack) => {
|
|
29
|
+
if (groupsStack.length > 0) {
|
|
30
|
+
groupsStack[groupsStack.length - 1] = true;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Closes the group ending at the specified index (position of the ")").
|
|
35
|
+
* Returns true if the group contains a quantifier and it's repeated by an unbounded quantifier.
|
|
36
|
+
*/
|
|
37
|
+
const closeGroup = (source, index, groupsStack) => {
|
|
38
|
+
var _a;
|
|
39
|
+
const groupContainsQuantifier = (_a = groupsStack.pop()) !== null && _a !== void 0 ? _a : false;
|
|
40
|
+
if (groupContainsQuantifier && unboundedQuantifierRegExp.test(source.substring(index + 1))) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (groupContainsQuantifier || isQuantifierAt(source, index + 1)) {
|
|
44
|
+
markInnermostGroupQuantified(groupsStack);
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Returns true if the specified regular expression source contains a group repeated by an unbounded quantifier
|
|
50
|
+
* that contains a quantifier itself (star height > 1), e.g. (a+)+, (\w*)* or (x{1,3})+:
|
|
51
|
+
* these patterns can take exponential time on non-matching strings.
|
|
52
|
+
* Overlapping alternations like (a|aa)+ are not detected.
|
|
53
|
+
*/
|
|
54
|
+
const hasNestedQuantifiers = (source) => {
|
|
55
|
+
// for each open group: true if it contains a quantifier
|
|
56
|
+
const groupsStack = [];
|
|
57
|
+
let i = 0;
|
|
58
|
+
while (i < source.length) {
|
|
59
|
+
switch (source[i]) {
|
|
60
|
+
case '\\':
|
|
61
|
+
i = skipEscape(i);
|
|
62
|
+
break;
|
|
63
|
+
case '[':
|
|
64
|
+
i = skipCharacterClass(source, i);
|
|
65
|
+
break;
|
|
66
|
+
case '(':
|
|
67
|
+
groupsStack.push(false);
|
|
68
|
+
// a "?" right after "(" introduces a group modifier (e.g. "(?:"), it's not a quantifier
|
|
69
|
+
i += source[i + 1] === '?' ? 2 : 1;
|
|
70
|
+
break;
|
|
71
|
+
case ')':
|
|
72
|
+
if (closeGroup(source, i, groupsStack))
|
|
73
|
+
return true;
|
|
74
|
+
i += 1;
|
|
75
|
+
break;
|
|
76
|
+
default:
|
|
77
|
+
if (isQuantifierAt(source, i)) {
|
|
78
|
+
markInnermostGroupQuantified(groupsStack);
|
|
79
|
+
}
|
|
80
|
+
i += 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
};
|
|
85
|
+
exports.hasNestedQuantifiers = hasNestedQuantifiers;
|
|
86
|
+
//# sourceMappingURL=regExpSafety.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"regExpSafety.js","sourceRoot":"","sources":["../../../src/expression/javascript/regExpSafety.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uFAAuF;AAC1E,QAAA,wBAAwB,GAAG,IAAI,CAAA;AAE5C,uGAAuG;AACvG,MAAM,yBAAyB,GAAG,mBAAmB,CAAA;AAErD,MAAM,cAAc,GAAG,CAAC,MAAc,EAAE,KAAa,EAAW,EAAE;IAChE,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;IAC1B,IA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ent":["/**\n * Protection against regular expressions that can take exponential time (ReDoS): JavaScript cannot interrupt a\n * running regular expression, so a single evaluation could freeze the server or the browser.\n */\n\n// maximum length of the strings that regular expressions are applied to in expressions\nexport const REG_EXP_INPUT_MAX_LENGTH = 1000\n\n// unbounded quantifier at the given position: *, + or {n,} (quantifiers like {n} or {n,m} are bounded)\nconst unboundedQuantifierRegExp = /^(\\*|\\+|\\{\\d+,\\})/\n\nconst isQuantifierAt = (source: string, index: number): boolean => {\n const char = source[index]\n if (char === '*' || char === '+') return true\n // {n,m} or {n,} (exact {n} repetitions don't multiply the ways a string can be matched)\n return char === '{' && /^\\{\\d+,\\d*\\}/.test(source.substring(index))\n}\n\nconst skipEscape = (index: number): number => index + 2\n\nconst skipCharacterClass = (source: string, index: number): number => {\n let i = index + 1\n while (i < source.length && source[i] !== ']') {\n i = source[i] === '\\\\' ? skipEscape(i) : i + 1\n }\n return i + 1\n}\n\n// marks the innermost open group (if any) as containing a quantifier\nconst markInnermostGroupQuantified = (groupsStack: boolean[]): void => {\n if (groupsStack.length > 0) {\n groupsStack[groupsStack.length - 1] = true\n }\n}\n\n/**\n * Closes the group ending at the specified index (position of the \")\").\n * Returns true if the group contains a quantifier and it's repeated by an unbounded quantifier.\n */\nconst closeGroup = (source: string, index: number, groupsStack: boolean[]): boolean => {\n const groupContainsQuantifier = groupsStack.pop() ?? false\n if (groupContainsQuantifier && unboundedQuantifierRegExp.test(source.substring(index + 1))) {\n return true\n }\n if (groupContainsQuantifier || isQuantifierAt(source, index + 1)) {\n markInnermostGroupQuantified(groupsStack)\n }\n return false\n}\n\n/**\n * Returns true if the specified regular expression source contains a group repeated by an unbounded quantifier\n * that contains a quantifier itself (star height > 1), e.g. (a+)+, (\\w*)* or (x{1,3})+:\n * these patterns can take exponential time on non-matching strings.\n * Overlapping alternations like (a|aa)+ are not detected.\n */\nexport const hasNestedQuantifiers = (source: string): boolean => {\n // for each open group: true if it contains a quantifier\n const groupsStack: boolean[] = []\n let i = 0\n while (i < source.length) {\n switch (source[i]) {\n case '\\\\':\n i = skipEscape(i)\n break\n case '[':\n i = skipCharacterClass(source, i)\n break\n case '(':\n groupsStack.push(false)\n // a \"?\" right after \"(\" introduces a group modifier (e.g. \"(?:\"), it's not a quantifier\n i += source[i + 1] === '?' ? 2 : 1\n break\n case ')':\n if (closeGroup(source, i, groupsStack)) return true\n i += 1\n break\n default:\n if (isQuantifierAt(source, i)) {\n markInnermostGroupQuantified(groupsStack)\n }\n i += 1\n }\n }\n return false\n}\n"]}
|
|
@@ -101,21 +101,22 @@ exports.nodeDefExpressionFunctions = {
|
|
|
101
101
|
categoryItemProp: {
|
|
102
102
|
minArity: 3,
|
|
103
103
|
executor: (context) => (categoryName, itemPropName, ...codePaths) => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
-
var _a
|
|
104
|
+
var _a;
|
|
105
105
|
const { survey } = context;
|
|
106
106
|
if (utils_1.Objects.isEmpty(categoryName) || utils_1.Objects.isEmpty(itemPropName) || utils_1.Objects.isEmpty(codePaths))
|
|
107
107
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.missingFunctionParameters);
|
|
108
108
|
const category = (0, surveysGetters_1.getCategoryByName)({ survey, categoryName });
|
|
109
109
|
if (!category)
|
|
110
110
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.invalidCategoryName, { name: categoryName });
|
|
111
|
-
const
|
|
111
|
+
const { itemExtraDef } = category.props;
|
|
112
|
+
const extraPropDef = itemExtraDef && Object.hasOwn(itemExtraDef, itemPropName) ? itemExtraDef[itemPropName] : undefined;
|
|
112
113
|
if (!extraPropDef)
|
|
113
114
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.invalidCategoryExtraProp, { propName: itemPropName });
|
|
114
115
|
const { uuid: categoryUuid } = category;
|
|
115
116
|
const categoryItem = yield getOrFetchCategoryItem({ context, categoryUuid, codePaths });
|
|
116
117
|
if (!categoryItem)
|
|
117
118
|
return null;
|
|
118
|
-
const value = (
|
|
119
|
+
const value = (_a = categoryItem.props.extra) === null || _a === void 0 ? void 0 : _a[itemPropName];
|
|
119
120
|
return extraProps_1.ExtraProps.convertValue({ survey, extraPropDef, value });
|
|
120
121
|
}),
|
|
121
122
|
},
|
|
@@ -298,7 +299,7 @@ exports.nodeDefExpressionFunctions = {
|
|
|
298
299
|
minArity: 3,
|
|
299
300
|
maxArity: 3,
|
|
300
301
|
executor: (context) => (taxonomyName, propName, taxonCode) => __awaiter(void 0, void 0, void 0, function* () {
|
|
301
|
-
var _a
|
|
302
|
+
var _a;
|
|
302
303
|
if (utils_1.Objects.isEmpty(taxonomyName) || utils_1.Objects.isEmpty(propName))
|
|
303
304
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.missingFunctionParameters);
|
|
304
305
|
if (utils_1.Objects.isEmpty(taxonCode))
|
|
@@ -307,13 +308,14 @@ exports.nodeDefExpressionFunctions = {
|
|
|
307
308
|
const taxonomy = (0, surveysGetters_1.getTaxonomyByName)({ survey, taxonomyName });
|
|
308
309
|
if (!taxonomy)
|
|
309
310
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName });
|
|
310
|
-
const
|
|
311
|
+
const { extraPropsDefs } = taxonomy.props;
|
|
312
|
+
const extraPropDef = extraPropsDefs && Object.hasOwn(extraPropsDefs, propName) ? extraPropsDefs[propName] : undefined;
|
|
311
313
|
if (!extraPropDef)
|
|
312
314
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.invalidTaxonomyExtraProp, { propName });
|
|
313
315
|
const taxon = yield getOrFetchTaxon({ context, taxonomyUuid: taxonomy.uuid, taxonCode });
|
|
314
316
|
if (!taxon)
|
|
315
317
|
return null;
|
|
316
|
-
const value = (
|
|
318
|
+
const value = (_a = taxon.props.extra) === null || _a === void 0 ? void 0 : _a[propName];
|
|
317
319
|
return extraProps_1.ExtraProps.convertValue({ survey, extraPropDef, value });
|
|
318
320
|
}),
|
|
319
321
|
},
|
|
@@ -330,7 +332,7 @@ exports.nodeDefExpressionFunctions = {
|
|
|
330
332
|
const taxonomy = (0, surveysGetters_1.getTaxonomyByName)({ survey, taxonomyName });
|
|
331
333
|
if (!taxonomy)
|
|
332
334
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.invalidTaxonomyName, { name: taxonomyName });
|
|
333
|
-
if (!language_1.LanguagesISO639part2
|
|
335
|
+
if (!Object.hasOwn(language_1.LanguagesISO639part2, vernacularLangCode)) {
|
|
334
336
|
throw new error_1.SystemError(error_1.SystemErrorKeys.expression.invalidTaxonVernacularNameLanguageCode, {
|
|
335
337
|
vernacularLangCode,
|
|
336
338
|
});
|
|
@@ -374,7 +376,7 @@ exports.nodeDefExpressionFunctions = {
|
|
|
374
376
|
return undefined;
|
|
375
377
|
const { uuid: surveyUuid } = survey;
|
|
376
378
|
const combinedExtraProps = auth_1.Users.getCombinedExtraProps(surveyUuid)(user);
|
|
377
|
-
return combinedExtraProps[propName];
|
|
379
|
+
return Object.hasOwn(combinedExtraProps, propName) ? combinedExtraProps[propName] : undefined;
|
|
378
380
|
},
|
|
379
381
|
},
|
|
380
382
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../../src/nodeDefExpressionEvaluator/functions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kCAA+B;AAE/B,oCAAuD;AAEvD,wDAAoD;AACpD,gCAAsD;AACtD,0CAAkD;AAElD,yDAA6D;AAC7D,yDAAuF;AACvF,qEAMyC;AAEzC,oCAAkD;AAGlD,MAAM,oBAAoB,GAAG;IAC3B,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE;QACR,IAAI,EAAE,SAAS;QACf,WAAW,EAAE;YACX;gBACE,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,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M,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;YACnC,MAAM,kBAAkB,GAAG,YAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAA;YACxE,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QACrC,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 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,kCAA+B;AAE/B,oCAAuD;AAEvD,wDAAoD;AACpD,gCAAsD;AACtD,0CAAkD;AAElD,yDAA6D;AAC7D,yDAAuF;AACvF,qEAMyC;AAEzC,oCAAkD;AAGlD,MAAM,oBAAoB,GAAG;IAC3B,IAAI,EAAE,SAAS;IACf,QAAQ,EAAE;QACR,IAAI,EAAE,SAAS;QACf,WAAW,EAAE;YACX;gBACE,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;gBACZ,CAAC,KAAK,EAAE,GAAG,CAAC;aACb;SACF;KACF;CACF,CAAA;AAED,MAAM,gBAAgB,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,eAAO,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAA;AAExG,MAAM,aAAa,GAAG,CAAC,QAAkC,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAA;AAExE,MAAM,iBAAiB,GAAG,CAAC,O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AE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAA;YACnC,MAAM,kBAAkB,GAAG,YAAK,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAA;YACxE,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QAC/F,CAAC;KACF;CACF,CAAA","sourcesContent":["import { Users } from '../auth'\nimport { 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"]}
|