import { ErrorSchema } from '@rjsf/utils'; import { RulesLogic } from 'json-logic-js'; export type JsonLogicRule = RulesLogic; export type ConditionPredicate = (formData: any) => boolean; export type Condition = ConditionPredicate | JsonLogicRule; export interface Rule { name: string; condition: Condition; effect: T; order?: number; } export interface EngineConfig { applyEffects: (effects: T[], baseConfig: C, formData: any) => C; defaultConfig: () => C; } export type ConditionalEngineHook = (rules: Rule[], baseConfig: C, formData: any) => C; export interface UiEffect { op: 'add' | 'remove' | 'replace'; path: string; value?: any; } export interface JsonPatchSchemaEffect { op: 'add' | 'remove' | 'replace'; path: string; value?: any; } export interface CustomSchemaEffect { op: 'require' | 'optional'; path: string; field: string; } export type SchemaEffect = JsonPatchSchemaEffect | CustomSchemaEffect; export interface ValidationEffect { /** * Name of the validation rule for debugging purposes */ name: string; /** * Determines if this validation should be applied based on current form data */ isActive: Condition; /** * Applies validation logic and adds errors to the ErrorSchema */ validate: (errors: ErrorSchema, formData: any) => void; } export type StepEffect = 'skip'; export interface StepRule extends Omit, 'condition' | 'effect'> { /** * JsonLogic rule determining whether the step should be skipped. * Functions are not supported to keep configurations serializable. */ condition: JsonLogicRule; /** * Currently only `skip` is supported. The field is optional to keep * authoring friction low – when omitted we treat the rule as `skip`. */ effect?: StepEffect; }