{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAM1E,MAAM,WAAW,uBAAuB;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,wBAAwB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,uBAAuB,EAAE,CAAA;CAAE,CAAC;AAE7G,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,wBAAwB,CAOhG;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAO1E","sourcesContent":["import { Compile, type Validator } from \"typebox/compile\";\nimport { ASM_CONTRACT_SCHEMAS, type AsmContractName } from \"./schemas.js\";\n\nconst validators = Object.fromEntries(\n\tObject.entries(ASM_CONTRACT_SCHEMAS).map(([name, schema]) => [name, Compile(schema)]),\n) as Record<AsmContractName, Validator>;\n\nexport interface ContractValidationError {\n\tpath: string;\n\tmessage: string;\n}\n\nexport type ContractValidationResult = { valid: true } | { valid: false; errors: ContractValidationError[] };\n\nexport function validateContract(name: AsmContractName, value: unknown): ContractValidationResult {\n\tconst validator = validators[name];\n\tif (validator.Check(value)) return { valid: true };\n\treturn {\n\t\tvalid: false,\n\t\terrors: [...validator.Errors(value)].map((error) => ({ path: error.instancePath, message: error.message })),\n\t};\n}\n\nexport function assertContract(name: AsmContractName, value: unknown): void {\n\tconst result = validateContract(name, value);\n\tif (!result.valid) {\n\t\tthrow new Error(\n\t\t\t`Invalid ${name} contract: ${result.errors.map((error) => `${error.path || \"/\"} ${error.message}`).join(\"; \")}`,\n\t\t);\n\t}\n}\n"]}