Skip to content

Commit

Permalink
Fixing evaluator and jsonlogic evaluator exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
travist committed May 22, 2024
1 parent e4ddc85 commit 7018209
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@formio/core",
"version": "2.1.0-dev.tt.11",
"version": "2.1.0-dev.tt.12",
"description": "The core Form.io renderering framework.",
"main": "lib/index.js",
"exports": {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jsonlogic from './jsonlogic';
import { JSONLogicModule } from './jsonlogic';
export default [
jsonlogic
JSONLogicModule
];
8 changes: 4 additions & 4 deletions src/modules/jsonlogic/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseEvaluator, EvaluatorOptions } from 'utils';
import { jsonLogic } from './jsonLogic';
class JSONLogicEvaluator extends BaseEvaluator {
export class JSONLogicEvaluator extends BaseEvaluator {
public static evaluate(
func: any,
args: any = {},
Expand Down Expand Up @@ -72,7 +72,7 @@ export function interpolate(
});
}

export default {
export * from './jsonLogic';
export const JSONLogicModule = {
evaluator: JSONLogicEvaluator,
jsonLogic: jsonLogic
}
};
5 changes: 2 additions & 3 deletions src/process/calculation/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import JSONLogic from 'modules/jsonlogic';
import { JSONLogicEvaluator } from 'modules/jsonlogic';
import { ProcessorFn, ProcessorFnSync, CalculationScope, CalculationContext, ProcessorInfo, FilterScope } from 'types';
import { set } from 'lodash';
const Evaluator = JSONLogic.evaluator;

export const shouldCalculate = (context: CalculationContext): boolean => {
const { component, config } = context;
Expand All @@ -22,7 +21,7 @@ export const calculateProcessSync: ProcessorFnSync<CalculationScope> = (context:
const evalContextValue = evalContext ? evalContext(context) : context;
evalContextValue.value = value || null;
if (!scope.calculated) scope.calculated = [];
let newValue = Evaluator.evaluate(component.calculateValue, evalContextValue, 'value');
let newValue = JSONLogicEvaluator.evaluate(component.calculateValue, evalContextValue, 'value');

// Only set a new value if it is not "null" which would be the case if no calculation occurred.
if (newValue !== null) {
Expand Down
7 changes: 3 additions & 4 deletions src/process/defaultValue/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import JSONLogic from 'modules/jsonlogic';
import { ProcessorFn, ProcessorFnSync, ConditionsScope, ProcessorInfo, DefaultValueContext, FilterScope } from 'types';
import { JSONLogicEvaluator } from 'modules/jsonlogic';
import { ProcessorFn, ProcessorFnSync, ConditionsScope, ProcessorInfo, DefaultValueContext } from 'types';
import { set, has } from 'lodash';
import { getComponentKey } from 'utils/formUtil';
const Evaluator = JSONLogic.evaluator;

export const hasCustomDefaultValue = (context: DefaultValueContext): boolean => {
const { component } = context;
Expand Down Expand Up @@ -41,7 +40,7 @@ export const customDefaultValueProcessSync: ProcessorFnSync<ConditionsScope> = (
if (component.customDefaultValue) {
const evalContextValue = evalContext ? evalContext(context) : context;
evalContextValue.value = null;
defaultValue = Evaluator.evaluate(component.customDefaultValue, evalContextValue, 'value');
defaultValue = JSONLogicEvaluator.evaluate(component.customDefaultValue, evalContextValue, 'value');
if (component.multiple && !Array.isArray(defaultValue)) {
defaultValue = defaultValue ? [defaultValue] : [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/process/validation/rules/validateJson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import jsonLogic from 'modules/jsonlogic';
import { JSONLogicEvaluator } from 'modules/jsonlogic';
import { FieldError } from 'error';
import { RuleFn, RuleFnSync, ValidationContext } from 'types';
import { ProcessorInfo } from 'types/process/ProcessorInfo';
Expand All @@ -25,7 +25,7 @@ export const validateJsonSync: RuleFnSync = (context: ValidationContext) => {
const func = component?.validate?.json;
const evalContextValue = evalContext ? evalContext(context) : context;
evalContextValue.value = value || null;
const valid: true | string = jsonLogic.evaluator.evaluate(
const valid: true | string = JSONLogicEvaluator.evaluate(
func,
{
...evalContextValue,
Expand Down
3 changes: 1 addition & 2 deletions src/utils/conditions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ConditionsContext, JSONConditional, LegacyConditional, SimpleConditional } from "types";
import JSONLogic, { EvaluatorFn, evaluate } from 'modules/jsonlogic';
import { EvaluatorFn, evaluate, JSONLogicEvaluator } from 'modules/jsonlogic';
import { getComponentActualValue } from "./formUtil";
import { has, isObject, map, every, some, find, filter } from 'lodash';
const JSONLogicEvaluator = JSONLogic.evaluator;
import ConditionOperators from './operators';

export const isJSONConditional = (conditional: any): conditional is JSONConditional => {
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { Evaluator, EvaluatorOptions, BaseEvaluator } from './Evaluator';
export { JSONLogicEvaluator } from 'modules/jsonlogic';
export { sanitize } from './sanitize';
export { override } from './override';
export { unwind } from './unwind';
Expand Down

0 comments on commit 7018209

Please sign in to comment.