From 5cf41ca2da6fa590ec641081903d0c9cbae8c259 Mon Sep 17 00:00:00 2001 From: BNNBetty <76114747+BNNBetty@users.noreply.github.com> Date: Thu, 4 Aug 2022 17:23:45 +0300 Subject: [PATCH] feat: add configuration validation on linked options (#333) * feat: add configuration validation on linked options * chore: moving linked option schema to separate file * chore: fix format Co-authored-by: Bogdan Nenu --- src/validations/prefab/component.ts | 2 +- src/validations/prefab/componentOption.ts | 14 ---------- src/validations/prefab/linkedOption.ts | 31 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 src/validations/prefab/linkedOption.ts diff --git a/src/validations/prefab/component.ts b/src/validations/prefab/component.ts index ac0e89be..0c88bb87 100644 --- a/src/validations/prefab/component.ts +++ b/src/validations/prefab/component.ts @@ -15,8 +15,8 @@ import { findDuplicates } from '../../utils/validation'; import { optionCategorySchema, optionSchema, - linkedOptionSchema, } from './componentOption'; +import { linkedOptionSchema } from './linkedOption'; type StyleValidator = Record; type PrefabTypes = 'partial' | 'page' | undefined; diff --git a/src/validations/prefab/componentOption.ts b/src/validations/prefab/componentOption.ts index 57f55dfc..d956aae6 100644 --- a/src/validations/prefab/componentOption.ts +++ b/src/validations/prefab/componentOption.ts @@ -83,20 +83,6 @@ const optionConfigurationSchema = Joi.when('type', { .default({}); -const linkedOptionValueSchema = Joi.object({ - ref: Joi.object({ - componentId: Joi.string().required(), - optionId: Joi.string().required(), - }), -}); - -export const linkedOptionSchema = Joi.object({ - key: Joi.string().required(), - label: Joi.string().allow(''), - type: Joi.string().valid('LINKED_OPTION').required(), - value: linkedOptionValueSchema, -}); - export const optionSchema = Joi.object({ label: Joi.string().required(), key: Joi.string().required(), diff --git a/src/validations/prefab/linkedOption.ts b/src/validations/prefab/linkedOption.ts new file mode 100644 index 00000000..3f1d056b --- /dev/null +++ b/src/validations/prefab/linkedOption.ts @@ -0,0 +1,31 @@ +import Joi from 'joi'; +import { + COMPARATORS, + CONDITION_TYPE, + CONFIGURATION_AS, +} from '../constants'; + +const linkedOptionValueSchema = Joi.object({ + ref: Joi.object({ + componentId: Joi.string().required(), + optionId: Joi.string().required(), + }), +}); + +export const linkedOptionConfigurationSchema = Joi.object({ + as: Joi.string().valid(...CONFIGURATION_AS), + condition: Joi.object({ + type: Joi.string().valid(...CONDITION_TYPE), + option: Joi.string(), + comparator: Joi.string().valid(...COMPARATORS), + value: Joi.any(), + }), +}); + +export const linkedOptionSchema = Joi.object({ + key: Joi.string().required(), + label: Joi.string().allow(''), + type: Joi.string().valid('LINKED_OPTION').required(), + value: linkedOptionValueSchema, + configuration: linkedOptionConfigurationSchema, +});