import Ajv from "ajv/dist/2020.js"; import { injectable } from "@codemation/core"; import type { JsonValue } from "@codemation/core"; const ajv = new Ajv({ strict: false }); @injectable() export class DecisionSchemaValidator { validate(args: { schemaJson: string; value: JsonValue }): { valid: true } | { valid: false; message: string } { const schema = JSON.parse(args.schemaJson) as object; const fn = ajv.compile(schema); if (fn(args.value)) { return { valid: true }; } return { valid: false, message: ajv.errorsText(fn.errors) }; } }