@openforis/arena-core 2.19.1 → 2.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
- package/dist/esm/record/recordValidator/attributeValidator.js +3 -1
- package/dist/esm/record/recordValidator/attributeValidator.js.map +1 -1
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.d.ts +4 -0
- package/dist/record/recordExpressionEvaluator/recordExpressionEvaluator.js.map +1 -1
- package/dist/record/recordValidator/attributeValidator.js +3 -1
- package/dist/record/recordValidator/attributeValidator.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordExpressionEvaluator.js","sourceRoot":"","sources":["../../../../src/record/recordExpressionEvaluator/recordExpressionEvaluator.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AAGpF,OAAO,EAAqB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAU,OAAO,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"recordExpressionEvaluator.js","sourceRoot":"","sources":["../../../../src/record/recordExpressionEvaluator/recordExpressionEvaluator.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAA;AAGpF,OAAO,EAAqB,QAAQ,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAU,OAAO,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAKpC,O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C,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,CAAA;gBAEtC,IACE,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC;oBAC5B,CAAC,MAAM,IAAI,CAAC,cAAc,iCAAM,MAAM,KAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,EAAE,IAAG,CAAC,EACnF,CAAC;oBACD,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;oBAEtC,IAAI,gBAAgB,EAAE,CAAC;wBACrB,MAAK;oBACP,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,qBAAqB,CAAA;QAC9B,CAAC;KAAA;IAEK,yBAAyB,CAC7B,MAIC;;YAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;YAC1B,MAAM,qBAAqB,GAAG,MAAM,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;YAE1E,OAAO,OAAO,CAAC,GAAG,CAChB,qBAAqB,CAAC,GAAG,CAAC,CAAO,UAAU,EAAE,EAAE,+DAAC,CAAC;gBAC/C,UAAU;gBACV,KAAK,EAAE,MAAM,IAAI,CAAC,cAAc,iCAAM,MAAM,KAAE,IAAI,EAAE,OAAO,EAAE,KAAK,QAAE,UAAU,CAAC,UAAU,mCAAI,EAAE,IAAG;aACnG,CAAC,IAAA,CAAC,CACJ,CAAA;QACH,CAAC;KAAA;IAEK,wBAAwB,CAC5B,MAGC;;;YAED,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,yBAAyB,iCAAM,MAAM,KAAE,gBAAgB,EAAE,IAAI,IAAG,CAAA;YACxG,aAAO,oBAAoB,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAA;QACxC,CAAC;KAAA;CACF","sourcesContent":["import type { ArenaRecord } from '../record'\nimport { User } from '../../auth'\nimport { CategoryItem } from '../../category'\nimport { ExpressionNodeType, JavascriptExpressionEvaluator } from '../../expression'\nimport { LanguageCode } from '../../language'\nimport { ArenaRecordNode } from '../../node'\nimport { NodeDefExpression, NodeDefs } from '../../nodeDef'\nimport { Survey, Surveys } from '../../survey'\nimport { Taxon } from '../../taxonomy'\nimport { Objects } from '../../utils'\nimport { Records } from '../records'\nimport { AreaOfInterestProvider } from '../../nodeDefExpressionEvaluator/areaOfInterestProvider'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { RecordExpressionContext } from './context'\nimport { recordExpressionFunctions } from './functions'\nimport { RecordIdentifierEvaluator } from './node/identifier'\nimport { RecordThisEvaluator } from './node/thisEvaluator'\n\ntype ExpressionEvaluateParams = {\n user: User\n survey: Survey\n record: ArenaRecord\n prevCycleRecord?: ArenaRecord\n timezoneOffset?: number\n lang?: LanguageCode\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n}\n\nexport class RecordExpressionEvaluator extends JavascriptExpressionEvaluator<RecordExpressionContext> {\n constructor() {\n super(recordExpressionFunctions, {\n [ExpressionNodeType.Identifier]: RecordIdentifierEvaluator,\n [ExpressionNodeType.This]: RecordThisEvaluator,\n })\n }\n\n async evalExpression(\n params: ExpressionEvaluateParams & {\n node: ArenaRecordNode\n query: string\n item?: CategoryItem | Taxon\n }\n ): Promise<any> {\n const { survey, record, node, query, item } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const nodeContext = NodeDefs.isEntity(nodeDef) ? node : Records.getParent(node)(record)\n if (!nodeContext) return null\n const context: RecordExpressionContext = { ...params, nodeContext, nodeCurrent: node, object: nodeContext, item }\n return this.evaluate(query, context)\n }\n\n private async _getApplicableExpressions(\n params: ExpressionEvaluateParams & {\n nodeCtx: ArenaRecordNode\n expressions: NodeDefExpression[]\n stopAtFirstFound?: boolean\n }\n ): Promise<NodeDefExpression[]> {\n const { nodeCtx, expressions, stopAtFirstFound = false } = params\n const applicableExpressions: NodeDefExpression[] = []\n\n for (const expression of expressions) {\n const applyIfExpr = expression.applyIf\n\n if (\n Objects.isEmpty(applyIfExpr) ||\n (await this.evalExpression({ ...params, node: nodeCtx, query: applyIfExpr ?? '' }))\n ) {\n applicableExpressions.push(expression)\n\n if (stopAtFirstFound) {\n break\n }\n }\n }\n return applicableExpressions\n }\n\n async evalApplicableExpressions(\n params: ExpressionEvaluateParams & {\n nodeCtx: ArenaRecordNode\n expressions: NodeDefExpression[]\n stopAtFirstFound?: boolean\n }\n ): Promise<{ expression: NodeDefExpression; value: any }[]> {\n const { nodeCtx } = params\n const applicableExpressions = await this._getApplicableExpressions(params)\n\n return Promise.all(\n applicableExpressions.map(async (expression) => ({\n expression,\n value: await this.evalExpression({ ...params, node: nodeCtx, query: expression.expression ?? '' }),\n }))\n )\n }\n\n async evalApplicableExpression(\n params: ExpressionEvaluateParams & {\n nodeCtx: ArenaRecordNode\n expressions: NodeDefExpression[]\n }\n ): Promise<{ expression: NodeDefExpression; value: any } | null> {\n const expressionsEvaluated = await this.evalApplicableExpressions({ ...params, stopAtFirstFound: true })\n return expressionsEvaluated[0] ?? null\n }\n}\n"]}
|
|
@@ -95,7 +95,7 @@ const _validateRequired = (params) => (_field, node) => __awaiter(void 0, void 0
|
|
|
95
95
|
*/
|
|
96
96
|
const _validateNodeValidations = (params) => (_propName, node) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
97
|
var _a;
|
|
98
|
-
const { user, survey, record, nodeDef, areaOfInterestProvider } = params;
|
|
98
|
+
const { user, survey, record, nodeDef, categoryItemProvider, taxonProvider, areaOfInterestProvider } = params;
|
|
99
99
|
if (Nodes.isValueBlank(node))
|
|
100
100
|
return ValidationResultFactory.createInstance();
|
|
101
101
|
const validations = NodeDefs.getValidations(nodeDef);
|
|
@@ -105,6 +105,8 @@ const _validateNodeValidations = (params) => (_propName, node) => __awaiter(void
|
|
|
105
105
|
user,
|
|
106
106
|
survey,
|
|
107
107
|
record,
|
|
108
|
+
categoryItemProvider,
|
|
109
|
+
taxonProvider,
|
|
108
110
|
areaOfInterestProvider,
|
|
109
111
|
nodeCtx: node,
|
|
110
112
|
expressions: validations.expressions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAmB,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EAA4C,QAAQ,EAAe,MAAM,eAAe,CAAA;AAI/F,OAAO,EAAU,OAAO,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EACL,iBAAiB,EAEjB,uBAAuB,EACvB,kBAAkB,EAClB,SAAS,GACV,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,CAAA;AAC9F,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAmB,MAAM,yBAAyB,CAAA;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAwC3D,MAAM,wBAAwB,GAAG,CAC/B,MAAiF,EAChB,EAAE;IACnE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,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C;QAC7C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { AreaOfInterestProvider } from '../../nodeDefExpressionEvaluator/areaOfInterestProvider'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { evaluateRequiredIf } from '../recordNodesUpdater/recordNodeDependentsRequiredUpdater'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\ntype SiblingKeyNodesGroup = {\n items: SiblingKeyNodeItem[]\n // items whose key node is not validated anyway (not in the nodes to validate): only these are compared by value\n itemsToCompare?: SiblingKeyNodeItem[]\n // entity of the first key attribute validated in this group: its key nodes with errors are not added\n // until a key attribute of another entity is validated\n firstEntityUuid?: string\n allItemsWithErrorsAdded?: boolean\n}\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodesGroup>\n\nconst _getSiblingNodeKeysGroup = (\n params: AttributeValidatorParams & { siblingKeyNodesCache: SiblingKeyNodesCache }\n): { entityUuid: string; group: SiblingKeyNodesGroup } | undefined => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) return undefined\n\n const ancestorMultipleEntity = Records.getAncestor(attribute, ancestorMultipleEntityDef.uuid)(record)\n if (!ancestorMultipleEntity) return undefined\n\n const ancestorMultipleEntityParent = Records.getParent(ancestorMultipleEntity)(record)\n if (!ancestorMultipleEntityParent) return undefined\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let group = siblingKeyNodesCache.get(cacheKey)\n if (!group) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings(ancestorMultipleEntity, true)(record)\n const items: SiblingKeyNodeItem[] = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes(survey, entity, undefined, keyDefs)(record)\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n group = { items }\n siblingKeyNodesCache.set(cacheKey, group)\n }\n return { entityUuid: ancestorMultipleEntity.uuid, group }\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _isValueRequired = async (\n params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }\n): Promise<boolean> => {\n const { record, attribute, nodeDef } = params\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parentNode = Records.getParent(attribute)(record)\n if (!parentNode) return false\n // evaluated here (not read from the parent node meta flag) so validation doesn't depend on up to date node meta\n // (e.g. records created before the \"required if\" condition was defined)\n return evaluateRequiredIf({ ...params, nodeCtx: parentNode, nodeDef })\n}\n\nconst _validateRequired =\n (params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_field: string, node: any): Promise<ValidationResult> => {\n const valid = !Nodes.isValueBlank(node) || !(await _isValueRequired(params))\n return valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: {\n user: User\n survey: Survey\n record: ArenaRecord\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n areaOfInterestProvider?: AreaOfInterestProvider\n }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef, areaOfInterestProvider } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n areaOfInterestProvider,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable(attribute)(record)) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired(validatorParams),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache: SiblingKeyNodesCache\n nodeUuidsToValidate: Set<string>\n }\n): ArenaRecordNode[] => {\n const { survey, nodeDef, nodeParent: parentNode, attribute, nodeUuidsToValidate } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeysGroup = _getSiblingNodeKeysGroup(params)\n if (!siblingNodeKeysGroup) return []\n\n const { entityUuid, group } = siblingNodeKeysGroup\n // key nodes in the nodes to validate are validated anyway: no need to compare their value\n group.itemsToCompare ??= group.items.filter((item) => !nodeUuidsToValidate.has(item.keyNode.uuid))\n\n const result: ArenaRecordNode[] = []\n for (const { entityUuid: itemEntityUuid, keyNode } of group.itemsToCompare) {\n if (\n itemEntityUuid !== entityUuid &&\n NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })\n ) {\n result.push(keyNode)\n }\n }\n return result.concat(_findSiblingKeyNodesWithErrorsNotAdded({ group, entityUuid }))\n}\n\n// key nodes with errors (in entities other than the attribute's one) are added only once per group\nconst _findSiblingKeyNodesWithErrorsNotAdded = (params: {\n group: SiblingKeyNodesGroup\n entityUuid: string\n}): ArenaRecordNode[] => {\n const { group, entityUuid } = params\n if (group.firstEntityUuid === undefined) {\n group.firstEntityUuid = entityUuid\n return group.items.filter((item) => item.hasErrors && item.entityUuid !== entityUuid).map((item) => item.keyNode)\n }\n if (group.allItemsWithErrorsAdded || group.firstEntityUuid === entityUuid) return []\n group.allItemsWithErrorsAdded = true\n const { firstEntityUuid } = group\n return group.items.filter((item) => item.hasErrors && item.entityUuid === firstEntityUuid).map((item) => item.keyNode)\n}\n\n// attribute siblings (same attribute def in the sibling entities) added to the nodes to validate,\n// by parent entity def and parent of the parent entity\ntype AttributeSiblingsAddedCache = Map<string, { firstParentEntity: ArenaRecordNode; allSiblingsAdded?: boolean }>\n\nconst findUniqueAttributeSiblingsToValidate = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n attributeSiblingsAddedCache: AttributeSiblingsAddedCache\n}): ArenaRecordNode[] => {\n const { record, node, nodeDef, nodeParent, attributeSiblingsAddedCache } = params\n if (!nodeParent) return []\n const nodeParentParent = Records.getParent(nodeParent)(record)\n if (!nodeParentParent) return []\n // the siblings of the attribute are the attributes in the other parent entities:\n // after visiting attributes in 2 different parent entities, all the attributes of the group have been added\n const cacheKey = `${nodeParentParent.uuid}_${nodeParent.nodeDefUuid}_${nodeDef.uuid}`\n const cached = attributeSiblingsAddedCache.get(cacheKey)\n if (!cached) {\n attributeSiblingsAddedCache.set(cacheKey, { firstParentEntity: nodeParent })\n return Records.getAttributeSiblings(node, nodeDef)(record)\n }\n if (cached.allSiblingsAdded || cached.firstParentEntity.uuid === nodeParent.uuid) return []\n cached.allSiblingsAdded = true\n return Records.getChildren(cached.firstParentEntity, nodeDef.uuid)(record)\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result: ArenaRecordNode[] = []\n const resultUuids = new Set<string>()\n const addToResult = (nodes: ArenaRecordNode[]) => {\n for (const node of nodes) {\n if (!resultUuids.has(node.uuid)) {\n resultUuids.add(node.uuid)\n result.push(node)\n }\n }\n }\n // every attribute in nodesArray is validated (it's included in its own dependents)\n const nodeUuidsToValidate = new Set(nodesArray.map((node) => node.uuid))\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n const attributeSiblingsAddedCache: AttributeSiblingsAddedCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = [\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.validations, true)(record),\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.required)(record),\n ]\n\n const nodeParent = Records.getParent(node)(record)\n\n addToResult(NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }))\n addToResult(\n findSiblingKeyNodesToValidate({\n ...params,\n nodeDef,\n nodeParent,\n attribute: node,\n siblingKeyNodesCache,\n nodeUuidsToValidate,\n })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n addToResult(\n findUniqueAttributeSiblingsToValidate({ record, node, nodeDef, nodeParent, attributeSiblingsAddedCache })\n )\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;AAGA,OAAO,EAAmB,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACzE,OAAO,EAA4C,QAAQ,EAAe,MAAM,eAAe,CAAA;AAI/F,OAAO,EAAU,OAAO,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AACrC,OAAO,EACL,iBAAiB,EAEjB,uBAAuB,EACvB,kBAAkB,EAClB,SAAS,GACV,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAE9C,OAAO,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAA;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2DAA2D,CAAA;AAC9F,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAmB,MAAM,yBAAyB,CAAA;AACvG,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,MAAM,mBAAmB,GAAG,IAAI,yBAAyB,EAAE,CAAA;AAwC3D,MAAM,wBAAwB,GAAG,CAC/B,MAAiF,EAChB,EAAE;IACnE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAA;IAElE,MAAM,YAAY,GAAG,OAAO,CAAC,gB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MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { AreaOfInterestProvider } from '../../nodeDefExpressionEvaluator/areaOfInterestProvider'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { evaluateRequiredIf } from '../recordNodesUpdater/recordNodeDependentsRequiredUpdater'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\ntype SiblingKeyNodesGroup = {\n items: SiblingKeyNodeItem[]\n // items whose key node is not validated anyway (not in the nodes to validate): only these are compared by value\n itemsToCompare?: SiblingKeyNodeItem[]\n // entity of the first key attribute validated in this group: its key nodes with errors are not added\n // until a key attribute of another entity is validated\n firstEntityUuid?: string\n allItemsWithErrorsAdded?: boolean\n}\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodesGroup>\n\nconst _getSiblingNodeKeysGroup = (\n params: AttributeValidatorParams & { siblingKeyNodesCache: SiblingKeyNodesCache }\n): { entityUuid: string; group: SiblingKeyNodesGroup } | undefined => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) return undefined\n\n const ancestorMultipleEntity = Records.getAncestor(attribute, ancestorMultipleEntityDef.uuid)(record)\n if (!ancestorMultipleEntity) return undefined\n\n const ancestorMultipleEntityParent = Records.getParent(ancestorMultipleEntity)(record)\n if (!ancestorMultipleEntityParent) return undefined\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let group = siblingKeyNodesCache.get(cacheKey)\n if (!group) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings(ancestorMultipleEntity, true)(record)\n const items: SiblingKeyNodeItem[] = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes(survey, entity, undefined, keyDefs)(record)\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n group = { items }\n siblingKeyNodesCache.set(cacheKey, group)\n }\n return { entityUuid: ancestorMultipleEntity.uuid, group }\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _isValueRequired = async (\n params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }\n): Promise<boolean> => {\n const { record, attribute, nodeDef } = params\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parentNode = Records.getParent(attribute)(record)\n if (!parentNode) return false\n // evaluated here (not read from the parent node meta flag) so validation doesn't depend on up to date node meta\n // (e.g. records created before the \"required if\" condition was defined)\n return evaluateRequiredIf({ ...params, nodeCtx: parentNode, nodeDef })\n}\n\nconst _validateRequired =\n (params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_field: string, node: any): Promise<ValidationResult> => {\n const valid = !Nodes.isValueBlank(node) || !(await _isValueRequired(params))\n return valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: {\n user: User\n survey: Survey\n record: ArenaRecord\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef, categoryItemProvider, taxonProvider, areaOfInterestProvider } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable(attribute)(record)) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired(validatorParams),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache: SiblingKeyNodesCache\n nodeUuidsToValidate: Set<string>\n }\n): ArenaRecordNode[] => {\n const { survey, nodeDef, nodeParent: parentNode, attribute, nodeUuidsToValidate } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeysGroup = _getSiblingNodeKeysGroup(params)\n if (!siblingNodeKeysGroup) return []\n\n const { entityUuid, group } = siblingNodeKeysGroup\n // key nodes in the nodes to validate are validated anyway: no need to compare their value\n group.itemsToCompare ??= group.items.filter((item) => !nodeUuidsToValidate.has(item.keyNode.uuid))\n\n const result: ArenaRecordNode[] = []\n for (const { entityUuid: itemEntityUuid, keyNode } of group.itemsToCompare) {\n if (\n itemEntityUuid !== entityUuid &&\n NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })\n ) {\n result.push(keyNode)\n }\n }\n return result.concat(_findSiblingKeyNodesWithErrorsNotAdded({ group, entityUuid }))\n}\n\n// key nodes with errors (in entities other than the attribute's one) are added only once per group\nconst _findSiblingKeyNodesWithErrorsNotAdded = (params: {\n group: SiblingKeyNodesGroup\n entityUuid: string\n}): ArenaRecordNode[] => {\n const { group, entityUuid } = params\n if (group.firstEntityUuid === undefined) {\n group.firstEntityUuid = entityUuid\n return group.items.filter((item) => item.hasErrors && item.entityUuid !== entityUuid).map((item) => item.keyNode)\n }\n if (group.allItemsWithErrorsAdded || group.firstEntityUuid === entityUuid) return []\n group.allItemsWithErrorsAdded = true\n const { firstEntityUuid } = group\n return group.items.filter((item) => item.hasErrors && item.entityUuid === firstEntityUuid).map((item) => item.keyNode)\n}\n\n// attribute siblings (same attribute def in the sibling entities) added to the nodes to validate,\n// by parent entity def and parent of the parent entity\ntype AttributeSiblingsAddedCache = Map<string, { firstParentEntity: ArenaRecordNode; allSiblingsAdded?: boolean }>\n\nconst findUniqueAttributeSiblingsToValidate = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n attributeSiblingsAddedCache: AttributeSiblingsAddedCache\n}): ArenaRecordNode[] => {\n const { record, node, nodeDef, nodeParent, attributeSiblingsAddedCache } = params\n if (!nodeParent) return []\n const nodeParentParent = Records.getParent(nodeParent)(record)\n if (!nodeParentParent) return []\n // the siblings of the attribute are the attributes in the other parent entities:\n // after visiting attributes in 2 different parent entities, all the attributes of the group have been added\n const cacheKey = `${nodeParentParent.uuid}_${nodeParent.nodeDefUuid}_${nodeDef.uuid}`\n const cached = attributeSiblingsAddedCache.get(cacheKey)\n if (!cached) {\n attributeSiblingsAddedCache.set(cacheKey, { firstParentEntity: nodeParent })\n return Records.getAttributeSiblings(node, nodeDef)(record)\n }\n if (cached.allSiblingsAdded || cached.firstParentEntity.uuid === nodeParent.uuid) return []\n cached.allSiblingsAdded = true\n return Records.getChildren(cached.firstParentEntity, nodeDef.uuid)(record)\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result: ArenaRecordNode[] = []\n const resultUuids = new Set<string>()\n const addToResult = (nodes: ArenaRecordNode[]) => {\n for (const node of nodes) {\n if (!resultUuids.has(node.uuid)) {\n resultUuids.add(node.uuid)\n result.push(node)\n }\n }\n }\n // every attribute in nodesArray is validated (it's included in its own dependents)\n const nodeUuidsToValidate = new Set(nodesArray.map((node) => node.uuid))\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n const attributeSiblingsAddedCache: AttributeSiblingsAddedCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = [\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.validations, true)(record),\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.required)(record),\n ]\n\n const nodeParent = Records.getParent(node)(record)\n\n addToResult(NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }))\n addToResult(\n findSiblingKeyNodesToValidate({\n ...params,\n nodeDef,\n nodeParent,\n attribute: node,\n siblingKeyNodesCache,\n nodeUuidsToValidate,\n })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n addToResult(\n findUniqueAttributeSiblingsToValidate({ record, node, nodeDef, nodeParent, attributeSiblingsAddedCache })\n )\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
|
|
@@ -8,6 +8,8 @@ import { NodeDefExpression } from '../../nodeDef';
|
|
|
8
8
|
import { Survey } from '../../survey';
|
|
9
9
|
import { Taxon } from '../../taxonomy';
|
|
10
10
|
import { AreaOfInterestProvider } from '../../nodeDefExpressionEvaluator/areaOfInterestProvider';
|
|
11
|
+
import { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider';
|
|
12
|
+
import { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider';
|
|
11
13
|
import { RecordExpressionContext } from './context';
|
|
12
14
|
type ExpressionEvaluateParams = {
|
|
13
15
|
user: User;
|
|
@@ -16,6 +18,8 @@ type ExpressionEvaluateParams = {
|
|
|
16
18
|
prevCycleRecord?: ArenaRecord;
|
|
17
19
|
timezoneOffset?: number;
|
|
18
20
|
lang?: LanguageCode;
|
|
21
|
+
categoryItemProvider?: CategoryItemProvider;
|
|
22
|
+
taxonProvider?: TaxonProvider;
|
|
19
23
|
areaOfInterestProvider?: AreaOfInterestProvider;
|
|
20
24
|
};
|
|
21
25
|
export declare class RecordExpressionEvaluator extends JavascriptExpressionEvaluator<RecordExpressionContext> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recordExpressionEvaluator.js","sourceRoot":"","sources":["../../../src/record/recordExpressionEvaluator/recordExpressionEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,iDAAoF;AAGpF,2CAA2D;AAC3D,yCAA8C;AAE9C,uCAAqC;AACrC,wCAAoC;
|
|
1
|
+
{"version":3,"file":"recordExpressionEvaluator.js","sourceRoot":"","sources":["../../../src/record/recordExpressionEvaluator/recordExpressionEvaluator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,i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gBAEtC,IACE,eAAO,CAAC,OAAO,CAAC,WAAW,CAAC;oBAC5B,CAAC,MAAM,IAAI,CAAC,cAAc,iCAAM,MAAM,KAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,EAAE,IAAG,CAAC,EACnF,CAAC;oBACD,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;oBAEtC,IAAI,gBAAgB,EAAE,CAAC;wBACrB,MAAK;oBACP,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,qBAAqB,CAAA;QAC9B,CAAC;KAAA;IAEK,yBAAyB,CAC7B,MAIC;;YAED,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAA;YAC1B,MAAM,qBAAqB,GAAG,MAAM,IAAI,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAA;YAE1E,OAAO,OAAO,CAAC,GAAG,CAChB,qBAAqB,CAAC,GAAG,CAAC,CAAO,UAAU,EAAE,EAAE,+DAAC,CAAC;gBAC/C,UAAU;gBACV,KAAK,EAAE,MAAM,IAAI,CAAC,cAAc,iCAAM,MAAM,KAAE,IAAI,EAAE,OAAO,EAAE,KAAK,QAAE,UAAU,CAAC,UAAU,mCAAI,EAAE,IAAG;aACnG,CAAC,IAAA,CAAC,CACJ,CAAA;QACH,CAAC;KAAA;IAEK,wBAAwB,CAC5B,MAGC;;;YAED,MAAM,oBAAoB,GAAG,MAAM,IAAI,CAAC,yBAAyB,iCAAM,MAAM,KAAE,gBAAgB,EAAE,IAAI,IAAG,CAAA;YACxG,aAAO,oBAAoB,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAA;QACxC,CAAC;KAAA;CACF","sourcesContent":["import type { ArenaRecord } from '../record'\nimport { User } from '../../auth'\nimport { CategoryItem } from '../../category'\nimport { ExpressionNodeType, JavascriptExpressionEvaluator } from '../../expression'\nimport { LanguageCode } from '../../language'\nimport { ArenaRecordNode } from '../../node'\nimport { NodeDefExpression, NodeDefs } from '../../nodeDef'\nimport { Survey, Surveys } from '../../survey'\nimport { Taxon } from '../../taxonomy'\nimport { Objects } from '../../utils'\nimport { Records } from '../records'\nimport { AreaOfInterestProvider } from '../../nodeDefExpressionEvaluator/areaOfInterestProvider'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { RecordExpressionContext } from './context'\nimport { recordExpressionFunctions } from './functions'\nimport { RecordIdentifierEvaluator } from './node/identifier'\nimport { RecordThisEvaluator } from './node/thisEvaluator'\n\ntype ExpressionEvaluateParams = {\n user: User\n survey: Survey\n record: ArenaRecord\n prevCycleRecord?: ArenaRecord\n timezoneOffset?: number\n lang?: LanguageCode\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n}\n\nexport class RecordExpressionEvaluator extends JavascriptExpressionEvaluator<RecordExpressionContext> {\n constructor() {\n super(recordExpressionFunctions, {\n [ExpressionNodeType.Identifier]: RecordIdentifierEvaluator,\n [ExpressionNodeType.This]: RecordThisEvaluator,\n })\n }\n\n async evalExpression(\n params: ExpressionEvaluateParams & {\n node: ArenaRecordNode\n query: string\n item?: CategoryItem | Taxon\n }\n ): Promise<any> {\n const { survey, record, node, query, item } = params\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n const nodeContext = NodeDefs.isEntity(nodeDef) ? node : Records.getParent(node)(record)\n if (!nodeContext) return null\n const context: RecordExpressionContext = { ...params, nodeContext, nodeCurrent: node, object: nodeContext, item }\n return this.evaluate(query, context)\n }\n\n private async _getApplicableExpressions(\n params: ExpressionEvaluateParams & {\n nodeCtx: ArenaRecordNode\n expressions: NodeDefExpression[]\n stopAtFirstFound?: boolean\n }\n ): Promise<NodeDefExpression[]> {\n const { nodeCtx, expressions, stopAtFirstFound = false } = params\n const applicableExpressions: NodeDefExpression[] = []\n\n for (const expression of expressions) {\n const applyIfExpr = expression.applyIf\n\n if (\n Objects.isEmpty(applyIfExpr) ||\n (await this.evalExpression({ ...params, node: nodeCtx, query: applyIfExpr ?? '' }))\n ) {\n applicableExpressions.push(expression)\n\n if (stopAtFirstFound) {\n break\n }\n }\n }\n return applicableExpressions\n }\n\n async evalApplicableExpressions(\n params: ExpressionEvaluateParams & {\n nodeCtx: ArenaRecordNode\n expressions: NodeDefExpression[]\n stopAtFirstFound?: boolean\n }\n ): Promise<{ expression: NodeDefExpression; value: any }[]> {\n const { nodeCtx } = params\n const applicableExpressions = await this._getApplicableExpressions(params)\n\n return Promise.all(\n applicableExpressions.map(async (expression) => ({\n expression,\n value: await this.evalExpression({ ...params, node: nodeCtx, query: expression.expression ?? '' }),\n }))\n )\n }\n\n async evalApplicableExpression(\n params: ExpressionEvaluateParams & {\n nodeCtx: ArenaRecordNode\n expressions: NodeDefExpression[]\n }\n ): Promise<{ expression: NodeDefExpression; value: any } | null> {\n const expressionsEvaluated = await this.evalApplicableExpressions({ ...params, stopAtFirstFound: true })\n return expressionsEvaluated[0] ?? null\n }\n}\n"]}
|
|
@@ -98,7 +98,7 @@ const _validateRequired = (params) => (_field, node) => __awaiter(void 0, void 0
|
|
|
98
98
|
*/
|
|
99
99
|
const _validateNodeValidations = (params) => (_propName, node) => __awaiter(void 0, void 0, void 0, function* () {
|
|
100
100
|
var _a;
|
|
101
|
-
const { user, survey, record, nodeDef, areaOfInterestProvider } = params;
|
|
101
|
+
const { user, survey, record, nodeDef, categoryItemProvider, taxonProvider, areaOfInterestProvider } = params;
|
|
102
102
|
if (node_1.Nodes.isValueBlank(node))
|
|
103
103
|
return validation_1.ValidationResultFactory.createInstance();
|
|
104
104
|
const validations = nodeDef_1.NodeDefs.getValidations(nodeDef);
|
|
@@ -108,6 +108,8 @@ const _validateNodeValidations = (params) => (_propName, node) => __awaiter(void
|
|
|
108
108
|
user,
|
|
109
109
|
survey,
|
|
110
110
|
record,
|
|
111
|
+
categoryItemProvider,
|
|
112
|
+
taxonProvider,
|
|
111
113
|
areaOfInterestProvider,
|
|
112
114
|
nodeCtx: node,
|
|
113
115
|
expressions: validations.expressions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAyE;AACzE,2CAA+F;AAI/F,yCAA8C;AAC9C,gDAA0D;AAC1D,uCAAqC;AACrC,iDAMyB;AAEzB,kDAA8C;AAE9C,4EAAwE;AACxE,mHAA8F;AAC9F,wCAAoC;AACpC,4DAAwD;AACxD,mEAAuG;AACvG,qEAAiE;AACjE,yEAAqE;AAErE,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAwC3D,MAAM,wBAAwB,GAAG,CAC/B,MAAiF,EAChB,EAAE;IACnE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,GAAG,MAAM,CAAA;IAElE,MAAM,YAAY,GAAG,gBAAO,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,CAAC,CAAA;IACtF,MAAM,yBAAyB,GAAG,gBAAO,CAAC,gCAAgC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAA;IAC7G,IAAI,CAAC,yBAAyB;QAAE,OAAO,SAAS,CAAA;IAEhD,MAAM,sBAAsB,GAAG,iBAAO,CAAC,WAAW,CAAC,SAAS,EAAE,yBAAyB,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;IACrG,IAAI,CAAC,sBAAsB;QAAE,OAAO,SAAS,CAAA;IAE7C,MAAM,4BAA4B,GAAG,iBAAO,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;IACtF,IAAI,CAAC,4BAA4B;QAAE,OAAO,SAAS,CAAA;IAEnD,M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CAAA;QAChH,WAAW,CACT,6BAA6B,iCACxB,MAAM,KACT,OAAO;YACP,UAAU,EACV,SAAS,EAAE,IAAI,EACf,oBAAoB;YACpB,mBAAmB,IACnB,CACH,CAAA;QAED,IAAI,MAAA,kBAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,0CAAE,MAAM,EAAE,CAAC;YAC7C,WAAW,CACT,qCAAqC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC,CAC1G,CAAA;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED,MAAM,wCAAwC,GAAG,CAC/C,MAAuC,EACZ,EAAE;IAC7B,MAAM,eAAe,GAAsB,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAC5E,MAAM,qBAAqB,GAAqB,EAAE,CAAA;IAClD,6EAA6E;IAC7E,MAAM,eAAe,GAAG,IAAA,6CAAqB,GAAE,CAAA;IAE/C,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAEY,QAAA,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { AreaOfInterestProvider } from '../../nodeDefExpressionEvaluator/areaOfInterestProvider'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { evaluateRequiredIf } from '../recordNodesUpdater/recordNodeDependentsRequiredUpdater'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\ntype SiblingKeyNodesGroup = {\n items: SiblingKeyNodeItem[]\n // items whose key node is not validated anyway (not in the nodes to validate): only these are compared by value\n itemsToCompare?: SiblingKeyNodeItem[]\n // entity of the first key attribute validated in this group: its key nodes with errors are not added\n // until a key attribute of another entity is validated\n firstEntityUuid?: string\n allItemsWithErrorsAdded?: boolean\n}\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodesGroup>\n\nconst _getSiblingNodeKeysGroup = (\n params: AttributeValidatorParams & { siblingKeyNodesCache: SiblingKeyNodesCache }\n): { entityUuid: string; group: SiblingKeyNodesGroup } | undefined => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) return undefined\n\n const ancestorMultipleEntity = Records.getAncestor(attribute, ancestorMultipleEntityDef.uuid)(record)\n if (!ancestorMultipleEntity) return undefined\n\n const ancestorMultipleEntityParent = Records.getParent(ancestorMultipleEntity)(record)\n if (!ancestorMultipleEntityParent) return undefined\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let group = siblingKeyNodesCache.get(cacheKey)\n if (!group) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings(ancestorMultipleEntity, true)(record)\n const items: SiblingKeyNodeItem[] = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes(survey, entity, undefined, keyDefs)(record)\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n group = { items }\n siblingKeyNodesCache.set(cacheKey, group)\n }\n return { entityUuid: ancestorMultipleEntity.uuid, group }\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _isValueRequired = async (\n params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }\n): Promise<boolean> => {\n const { record, attribute, nodeDef } = params\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parentNode = Records.getParent(attribute)(record)\n if (!parentNode) return false\n // evaluated here (not read from the parent node meta flag) so validation doesn't depend on up to date node meta\n // (e.g. records created before the \"required if\" condition was defined)\n return evaluateRequiredIf({ ...params, nodeCtx: parentNode, nodeDef })\n}\n\nconst _validateRequired =\n (params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_field: string, node: any): Promise<ValidationResult> => {\n const valid = !Nodes.isValueBlank(node) || !(await _isValueRequired(params))\n return valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: {\n user: User\n survey: Survey\n record: ArenaRecord\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n areaOfInterestProvider?: AreaOfInterestProvider\n }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef, areaOfInterestProvider } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n areaOfInterestProvider,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable(attribute)(record)) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired(validatorParams),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache: SiblingKeyNodesCache\n nodeUuidsToValidate: Set<string>\n }\n): ArenaRecordNode[] => {\n const { survey, nodeDef, nodeParent: parentNode, attribute, nodeUuidsToValidate } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeysGroup = _getSiblingNodeKeysGroup(params)\n if (!siblingNodeKeysGroup) return []\n\n const { entityUuid, group } = siblingNodeKeysGroup\n // key nodes in the nodes to validate are validated anyway: no need to compare their value\n group.itemsToCompare ??= group.items.filter((item) => !nodeUuidsToValidate.has(item.keyNode.uuid))\n\n const result: ArenaRecordNode[] = []\n for (const { entityUuid: itemEntityUuid, keyNode } of group.itemsToCompare) {\n if (\n itemEntityUuid !== entityUuid &&\n NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })\n ) {\n result.push(keyNode)\n }\n }\n return result.concat(_findSiblingKeyNodesWithErrorsNotAdded({ group, entityUuid }))\n}\n\n// key nodes with errors (in entities other than the attribute's one) are added only once per group\nconst _findSiblingKeyNodesWithErrorsNotAdded = (params: {\n group: SiblingKeyNodesGroup\n entityUuid: string\n}): ArenaRecordNode[] => {\n const { group, entityUuid } = params\n if (group.firstEntityUuid === undefined) {\n group.firstEntityUuid = entityUuid\n return group.items.filter((item) => item.hasErrors && item.entityUuid !== entityUuid).map((item) => item.keyNode)\n }\n if (group.allItemsWithErrorsAdded || group.firstEntityUuid === entityUuid) return []\n group.allItemsWithErrorsAdded = true\n const { firstEntityUuid } = group\n return group.items.filter((item) => item.hasErrors && item.entityUuid === firstEntityUuid).map((item) => item.keyNode)\n}\n\n// attribute siblings (same attribute def in the sibling entities) added to the nodes to validate,\n// by parent entity def and parent of the parent entity\ntype AttributeSiblingsAddedCache = Map<string, { firstParentEntity: ArenaRecordNode; allSiblingsAdded?: boolean }>\n\nconst findUniqueAttributeSiblingsToValidate = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n attributeSiblingsAddedCache: AttributeSiblingsAddedCache\n}): ArenaRecordNode[] => {\n const { record, node, nodeDef, nodeParent, attributeSiblingsAddedCache } = params\n if (!nodeParent) return []\n const nodeParentParent = Records.getParent(nodeParent)(record)\n if (!nodeParentParent) return []\n // the siblings of the attribute are the attributes in the other parent entities:\n // after visiting attributes in 2 different parent entities, all the attributes of the group have been added\n const cacheKey = `${nodeParentParent.uuid}_${nodeParent.nodeDefUuid}_${nodeDef.uuid}`\n const cached = attributeSiblingsAddedCache.get(cacheKey)\n if (!cached) {\n attributeSiblingsAddedCache.set(cacheKey, { firstParentEntity: nodeParent })\n return Records.getAttributeSiblings(node, nodeDef)(record)\n }\n if (cached.allSiblingsAdded || cached.firstParentEntity.uuid === nodeParent.uuid) return []\n cached.allSiblingsAdded = true\n return Records.getChildren(cached.firstParentEntity, nodeDef.uuid)(record)\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result: ArenaRecordNode[] = []\n const resultUuids = new Set<string>()\n const addToResult = (nodes: ArenaRecordNode[]) => {\n for (const node of nodes) {\n if (!resultUuids.has(node.uuid)) {\n resultUuids.add(node.uuid)\n result.push(node)\n }\n }\n }\n // every attribute in nodesArray is validated (it's included in its own dependents)\n const nodeUuidsToValidate = new Set(nodesArray.map((node) => node.uuid))\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n const attributeSiblingsAddedCache: AttributeSiblingsAddedCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = [\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.validations, true)(record),\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.required)(record),\n ]\n\n const nodeParent = Records.getParent(node)(record)\n\n addToResult(NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }))\n addToResult(\n findSiblingKeyNodesToValidate({\n ...params,\n nodeDef,\n nodeParent,\n attribute: node,\n siblingKeyNodesCache,\n nodeUuidsToValidate,\n })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n addToResult(\n findUniqueAttributeSiblingsToValidate({ record, node, nodeDef, nodeParent, attributeSiblingsAddedCache })\n )\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
|
|
1
|
+
{"version":3,"file":"attributeValidator.js","sourceRoot":"","sources":["../../../src/record/recordValidator/attributeValidator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAGA,qCAAyE;AACzE,2CAA+F;AAI/F,yCAA8C;AAC9C,gDAA0D;AAC1D,uCAAqC;AACrC,iDAMyB;AAEzB,kDAA8C;AAE9C,4EAAwE;AACxE,mHAA8F;AAC9F,wCAAoC;AACpC,4DAAwD;AACxD,mEAAuG;AACvG,qEAAiE;AACjE,yEAAqE;AAErE,MAAM,mBAAmB,GAAG,IAAI,qDAAyB,EAAE,CAAA;AAwC3D,MAAM,wBAAwB,GAAG,CAC/B,MAAiF,EAChB,EAAE;IACnE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,oBAAoB,EAAE,G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,MAAM,eAAe,GAAG,IAAA,6CAAqB,GAAE,CAAA;IAE/C,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;QAC7C,MAAM,QAAQ,GAAG,cAAc,CAAC,IAAI,CAAA;QACpC,iEAAiE;QACjE,IAAI,CAAC,cAAc,CAAC,OAAO,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAChE,qEAAqE;YACrE,MAAM,wBAAwB,mCAAQ,MAAM,KAAE,SAAS,EAAE,cAAc,EAAE,eAAe,GAAE,CAAA;YAC1F,qBAAqB,CAAC,QAAQ,CAAC,GAAG,MAAM,iBAAiB,CAAC,wBAAwB,CAAC,CAAA,CAAC,UAAU;QAChG,CAAC;IACH,CAAC;IACD,OAAO,qBAAqB,CAAA;AAC9B,CAAC,CAAA,CAAA;AAEY,QAAA,kBAAkB,GAAG;IAChC,wCAAwC;CACzC,CAAA","sourcesContent":["import { User } from '../../auth'\nimport { Dictionary } from '../../common'\nimport { Labels } from '../../language'\nimport { ArenaRecordNode, NodeKeys, Nodes, NodeValues } from '../../node'\nimport { NodeDef, NodeDefExpression, NodeDefProps, NodeDefs, NodeDefType } from '../../nodeDef'\nimport { AreaOfInterestProvider } from '../../nodeDefExpressionEvaluator/areaOfInterestProvider'\nimport { CategoryItemProvider } from '../../nodeDefExpressionEvaluator/categoryItemProvider'\nimport { TaxonProvider } from '../../nodeDefExpressionEvaluator/taxonProvider'\nimport { Survey, Surveys } from '../../survey'\nimport { SurveyDependencyType } from '../../survey/survey'\nimport { Objects } from '../../utils'\nimport {\n ValidationFactory,\n ValidationResult,\n ValidationResultFactory,\n ValidationSeverity,\n Validator,\n} from '../../validation'\nimport { ValidationFields } from '../../validation/validation'\nimport { NodePointers } from '../nodePointers'\nimport { ArenaRecord } from '../record'\nimport { RecordExpressionEvaluator } from '../recordExpressionEvaluator'\nimport { evaluateRequiredIf } from '../recordNodesUpdater/recordNodeDependentsRequiredUpdater'\nimport { Records } from '../records'\nimport { RecordValidations } from '../recordValidations'\nimport { AttributeKeyValidator, createEntityKeysCache, EntityKeysCache } from './attributeKeyValidator'\nimport { AttributeTypeValidator } from './attributeTypeValidator'\nimport { AttributeUniqueValidator } from './attributeUniqueValidator'\n\nconst expressionEvaluator = new RecordExpressionEvaluator()\n\nexport interface RecordValidatorParams {\n user: User\n survey: Survey\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n record: ArenaRecord\n}\n\nexport interface AttributeValidatorParams extends RecordValidatorParams {\n attribute: ArenaRecordNode\n}\n\nexport interface AttributesValidatorParams extends RecordValidatorParams {\n nodes: Dictionary<ArenaRecordNode>\n}\n\nexport interface SortedAttributesValidatorParams extends RecordValidatorParams {\n nodesArray: ArenaRecordNode[]\n}\n\ntype SiblingKeyNodeItem = { entityUuid: string; keyNode: ArenaRecordNode; hasErrors: boolean }\n\ntype SiblingKeyNodesGroup = {\n items: SiblingKeyNodeItem[]\n // items whose key node is not validated anyway (not in the nodes to validate): only these are compared by value\n itemsToCompare?: SiblingKeyNodeItem[]\n // entity of the first key attribute validated in this group: its key nodes with errors are not added\n // until a key attribute of another entity is validated\n firstEntityUuid?: string\n allItemsWithErrorsAdded?: boolean\n}\n\n// sibling key nodes are cached by ancestor multiple entity parent and def uuid during the same validation call:\n// when many entities are added to the same parent entity (e.g. data import), computing them for every updated\n// key attribute would take a time that grows quadratically with the number of entities\ntype SiblingKeyNodesCache = Map<string, SiblingKeyNodesGroup>\n\nconst _getSiblingNodeKeysGroup = (\n params: AttributeValidatorParams & { siblingKeyNodesCache: SiblingKeyNodesCache }\n): { entityUuid: string; group: SiblingKeyNodesGroup } | undefined => {\n const { survey, record, attribute, siblingKeyNodesCache } = params\n\n const attributeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const ancestorMultipleEntityDef = Surveys.getNodeDefAncestorMultipleEntity({ survey, nodeDef: attributeDef })\n if (!ancestorMultipleEntityDef) return undefined\n\n const ancestorMultipleEntity = Records.getAncestor(attribute, ancestorMultipleEntityDef.uuid)(record)\n if (!ancestorMultipleEntity) return undefined\n\n const ancestorMultipleEntityParent = Records.getParent(ancestorMultipleEntity)(record)\n if (!ancestorMultipleEntityParent) return undefined\n\n const cacheKey = `${ancestorMultipleEntityParent.uuid}_${ancestorMultipleEntityDef.uuid}`\n let group = siblingKeyNodesCache.get(cacheKey)\n if (!group) {\n const keyDefs = Surveys.getNodeDefKeys({ survey, nodeDef: ancestorMultipleEntityDef })\n const entities = Records.getEntitySiblings(ancestorMultipleEntity, true)(record)\n const items: SiblingKeyNodeItem[] = []\n for (const entity of entities) {\n const keyNodes = Records.getEntityKeyNodes(survey, entity, undefined, keyDefs)(record)\n for (const keyNode of keyNodes) {\n if (!keyNode) continue\n const nodeValidation =\n record.validation && RecordValidations.getValidationNode({ nodeUuid: keyNode.uuid })(record.validation)\n items.push({ entityUuid: entity.uuid, keyNode, hasErrors: !!nodeValidation && !nodeValidation.valid })\n }\n }\n group = { items }\n siblingKeyNodesCache.set(cacheKey, group)\n }\n return { entityUuid: ancestorMultipleEntity.uuid, group }\n}\n\nconst _getValidationMessagesWithDefault = (params: {\n survey: Survey\n expression: NodeDefExpression\n defaultMessage?: string\n}): Labels => {\n const { survey, expression, defaultMessage } = params\n const messages: Labels = { ...expression.messages }\n\n const languages = Surveys.getLanguages(survey)\n const defaultMessageDefined = Objects.isNotEmpty(defaultMessage)\n\n for (const lang of languages) {\n const customMessage = messages[lang]\n if (Objects.isEmpty(customMessage) && defaultMessageDefined) {\n messages[lang] = defaultMessage\n }\n }\n\n return messages\n}\n\nconst _isValueRequired = async (\n params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }\n): Promise<boolean> => {\n const { record, attribute, nodeDef } = params\n if (NodeDefs.isKey(nodeDef) || NodeDefs.isRequired(nodeDef)) return true\n if (!NodeDefs.isRequiredIfDefined(nodeDef)) return false\n const parentNode = Records.getParent(attribute)(record)\n if (!parentNode) return false\n // evaluated here (not read from the parent node meta flag) so validation doesn't depend on up to date node meta\n // (e.g. records created before the \"required if\" condition was defined)\n return evaluateRequiredIf({ ...params, nodeCtx: parentNode, nodeDef })\n}\n\nconst _validateRequired =\n (params: AttributeValidatorParams & { nodeDef: NodeDef<NodeDefType, NodeDefProps> }) =>\n async (_field: string, node: any): Promise<ValidationResult> => {\n const valid = !Nodes.isValueBlank(node) || !(await _isValueRequired(params))\n return valid\n ? ValidationResultFactory.createInstance()\n : ValidationResultFactory.createInstance({\n key: 'record.attribute.valueRequired',\n severity: ValidationSeverity.error,\n valid,\n })\n }\n\n/**\n * Evaluates the validation expressions.\n */\nconst _validateNodeValidations =\n (params: {\n user: User\n survey: Survey\n record: ArenaRecord\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n categoryItemProvider?: CategoryItemProvider\n taxonProvider?: TaxonProvider\n areaOfInterestProvider?: AreaOfInterestProvider\n }) =>\n async (_propName: string, node: ArenaRecordNode): Promise<ValidationResult> => {\n const { user, survey, record, nodeDef, categoryItemProvider, taxonProvider, areaOfInterestProvider } = params\n if (Nodes.isValueBlank(node)) return ValidationResultFactory.createInstance()\n\n const validations = NodeDefs.getValidations(nodeDef)\n if (!validations?.expressions?.length) return ValidationResultFactory.createInstance()\n\n const applicableExpressionsEval = await expressionEvaluator.evalApplicableExpressions({\n user,\n survey,\n record,\n categoryItemProvider,\n taxonProvider,\n areaOfInterestProvider,\n nodeCtx: node,\n expressions: validations.expressions,\n stopAtFirstFound: false,\n })\n\n let validationResult = ValidationResultFactory.createInstance()\n\n for (const { expression, value: valid } of applicableExpressionsEval) {\n if (!valid) {\n const messages = _getValidationMessagesWithDefault({\n survey,\n expression,\n defaultMessage: expression.expression,\n })\n\n validationResult = ValidationResultFactory.createInstance({\n valid: false,\n key: 'record.attribute.customValidation',\n severity: expression.severity,\n messages,\n })\n break\n }\n }\n\n return validationResult\n }\n\nconst validateAttribute = async (params: AttributeValidatorParams & { entityKeysCache?: EntityKeysCache }) => {\n const { survey, record, attribute } = params\n if (Records.isNodeApplicable(attribute)(record)) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: attribute.nodeDefUuid })\n const validatorParams = { ...params, nodeDef }\n return new Validator().validate(attribute, {\n [NodeKeys.value]: [\n _validateRequired(validatorParams),\n AttributeTypeValidator.validateValueType(validatorParams),\n _validateNodeValidations(validatorParams),\n AttributeKeyValidator.validateAttributeKey(validatorParams),\n AttributeUniqueValidator.validateAttributeUnique(validatorParams),\n ],\n })\n }\n return ValidationFactory.createInstance()\n}\n\nconst findSiblingKeyNodesToValidate = (\n params: AttributeValidatorParams & {\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n siblingKeyNodesCache: SiblingKeyNodesCache\n nodeUuidsToValidate: Set<string>\n }\n): ArenaRecordNode[] => {\n const { survey, nodeDef, nodeParent: parentNode, attribute, nodeUuidsToValidate } = params\n if (\n !NodeDefs.isKey(nodeDef) ||\n !parentNode ||\n (NodeDefs.isAutoIncrementalKey(nodeDef) && attribute.created && Nodes.isDefaultValueApplied(attribute))\n ) {\n // when a new node is created and the key is autoincremental, its value will be unique\n // and the validation of sibling key attributes is not necessary\n return []\n }\n // when a key attribute is updated, a sibling key attribute with the same value\n // or a sibling attribute with a validation error (duplicate key) should be re-validated\n const siblingNodeKeysGroup = _getSiblingNodeKeysGroup(params)\n if (!siblingNodeKeysGroup) return []\n\n const { entityUuid, group } = siblingNodeKeysGroup\n // key nodes in the nodes to validate are validated anyway: no need to compare their value\n group.itemsToCompare ??= group.items.filter((item) => !nodeUuidsToValidate.has(item.keyNode.uuid))\n\n const result: ArenaRecordNode[] = []\n for (const { entityUuid: itemEntityUuid, keyNode } of group.itemsToCompare) {\n if (\n itemEntityUuid !== entityUuid &&\n NodeValues.isValueEqual({ survey, nodeDef, parentNode, value: keyNode.value, valueSearch: attribute.value })\n ) {\n result.push(keyNode)\n }\n }\n return result.concat(_findSiblingKeyNodesWithErrorsNotAdded({ group, entityUuid }))\n}\n\n// key nodes with errors (in entities other than the attribute's one) are added only once per group\nconst _findSiblingKeyNodesWithErrorsNotAdded = (params: {\n group: SiblingKeyNodesGroup\n entityUuid: string\n}): ArenaRecordNode[] => {\n const { group, entityUuid } = params\n if (group.firstEntityUuid === undefined) {\n group.firstEntityUuid = entityUuid\n return group.items.filter((item) => item.hasErrors && item.entityUuid !== entityUuid).map((item) => item.keyNode)\n }\n if (group.allItemsWithErrorsAdded || group.firstEntityUuid === entityUuid) return []\n group.allItemsWithErrorsAdded = true\n const { firstEntityUuid } = group\n return group.items.filter((item) => item.hasErrors && item.entityUuid === firstEntityUuid).map((item) => item.keyNode)\n}\n\n// attribute siblings (same attribute def in the sibling entities) added to the nodes to validate,\n// by parent entity def and parent of the parent entity\ntype AttributeSiblingsAddedCache = Map<string, { firstParentEntity: ArenaRecordNode; allSiblingsAdded?: boolean }>\n\nconst findUniqueAttributeSiblingsToValidate = (params: {\n record: ArenaRecord\n node: ArenaRecordNode\n nodeDef: NodeDef<NodeDefType, NodeDefProps>\n nodeParent?: ArenaRecordNode\n attributeSiblingsAddedCache: AttributeSiblingsAddedCache\n}): ArenaRecordNode[] => {\n const { record, node, nodeDef, nodeParent, attributeSiblingsAddedCache } = params\n if (!nodeParent) return []\n const nodeParentParent = Records.getParent(nodeParent)(record)\n if (!nodeParentParent) return []\n // the siblings of the attribute are the attributes in the other parent entities:\n // after visiting attributes in 2 different parent entities, all the attributes of the group have been added\n const cacheKey = `${nodeParentParent.uuid}_${nodeParent.nodeDefUuid}_${nodeDef.uuid}`\n const cached = attributeSiblingsAddedCache.get(cacheKey)\n if (!cached) {\n attributeSiblingsAddedCache.set(cacheKey, { firstParentEntity: nodeParent })\n return Records.getAttributeSiblings(node, nodeDef)(record)\n }\n if (cached.allSiblingsAdded || cached.firstParentEntity.uuid === nodeParent.uuid) return []\n cached.allSiblingsAdded = true\n return Records.getChildren(cached.firstParentEntity, nodeDef.uuid)(record)\n}\n\nconst findSortedNodesToValidate = (params: SortedAttributesValidatorParams): ArenaRecordNode[] => {\n const { survey, record, nodesArray } = params\n\n const result: ArenaRecordNode[] = []\n const resultUuids = new Set<string>()\n const addToResult = (nodes: ArenaRecordNode[]) => {\n for (const node of nodes) {\n if (!resultUuids.has(node.uuid)) {\n resultUuids.add(node.uuid)\n result.push(node)\n }\n }\n }\n // every attribute in nodesArray is validated (it's included in its own dependents)\n const nodeUuidsToValidate = new Set(nodesArray.map((node) => node.uuid))\n const siblingKeyNodesCache: SiblingKeyNodesCache = new Map()\n const attributeSiblingsAddedCache: AttributeSiblingsAddedCache = new Map()\n for (const node of nodesArray) {\n const nodeDef = Surveys.getNodeDefByUuid({ survey, uuid: node.nodeDefUuid })\n if (!NodeDefs.isAttribute(nodeDef)) {\n continue\n }\n // Get dependents and attribute itself\n const nodePointersAttributeAndDependents = [\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.validations, true)(record),\n ...Records.getDependentNodePointers(survey, node, SurveyDependencyType.required)(record),\n ]\n\n const nodeParent = Records.getParent(node)(record)\n\n addToResult(NodePointers.getNodesFromNodePointers({ record, nodePointers: nodePointersAttributeAndDependents }))\n addToResult(\n findSiblingKeyNodesToValidate({\n ...params,\n nodeDef,\n nodeParent,\n attribute: node,\n siblingKeyNodesCache,\n nodeUuidsToValidate,\n })\n )\n\n if (NodeDefs.getValidations(nodeDef)?.unique) {\n addToResult(\n findUniqueAttributeSiblingsToValidate({ record, node, nodeDef, nodeParent, attributeSiblingsAddedCache })\n )\n }\n }\n\n return result\n}\n\nconst validateSelfAndDependentSortedAttributes = async (\n params: SortedAttributesValidatorParams\n): Promise<ValidationFields> => {\n const nodesToValidate: ArenaRecordNode[] = findSortedNodesToValidate(params)\n const validationsByNodeUuid: ValidationFields = {}\n // the record doesn't change during the validation: entity keys can be cached\n const entityKeysCache = createEntityKeysCache()\n\n for (const nodeToValidate of nodesToValidate) {\n const nodeUuid = nodeToValidate.uuid\n // Validate only attributes not deleted and not validated already\n if (!nodeToValidate.deleted && !validationsByNodeUuid[nodeUuid]) {\n // sequential: avoid concurrent item/taxon lookups on large node sets\n const attributeValidatorParams = { ...params, attribute: nodeToValidate, entityKeysCache }\n validationsByNodeUuid[nodeUuid] = await validateAttribute(attributeValidatorParams) // NOSONAR\n }\n }\n return validationsByNodeUuid\n}\n\nexport const AttributeValidator = {\n validateSelfAndDependentSortedAttributes,\n}\n"]}
|