Skip to content

Commit

Permalink
JSONLogic validations should get same context as calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanbond committed Mar 26, 2024
1 parent 26b7aaf commit 60548ac
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/process/validation/rules/validateJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ProcessorInfo } from 'types/process/ProcessorInfo';
import { isObject } from 'lodash';

export const shouldValidate = (context: ValidationContext) => {
const { component, value } = context;
const { component } = context;
if (!component.validate?.json || !isObject(component.validate.json)) {
return false;
}
Expand All @@ -17,18 +17,17 @@ export const validateJson: RuleFn = async (context: ValidationContext) => {
};

export const validateJsonSync: RuleFnSync = (context: ValidationContext) => {
const { component, data, value } = context;
const { component, data, value, evalContext } = context;
if (!shouldValidate(context)) {
return null;
}

const func = component?.validate?.json;
const evalContextValue = evalContext ? evalContext(context) : context;
evalContextValue.value = value || null;
const valid: true | string = jsonLogic.evaluator.evaluate(
func,
{
data,
input: value,
},
evalContextValue,
'valid'
);
if (valid === null) {
Expand Down

0 comments on commit 60548ac

Please sign in to comment.