import d from"@redocly/ajv";const o=new d({coerceTypes:!0,removeAdditional:!0,discriminator:!0,allErrors:!0});o.addFormat("uri",{type:"string",validate:e=>{try{return new URL(e),!0}catch{return!1}}}),o.addFormat("email",{type:"string",validate:e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)});function f(e,t){const{errorPrefix:n,dataVar:a="data"}=t??{},r=o.compile(e);return function(i){if(!r(i)){const c=r.errors?.length?r.errors.map(s=>{const u=s.instancePath.replaceAll("/",".");return`'${a}${u}' ${s.message}`}).join(", "):"unknown error",l=n?`${n} `:"";throw new Error(`${l}${c}`)}return i}}function h(e,t){const n=o.compile(e),a=n(t);return{success:a,data:a?t:void 0,error:a?void 0:n.errors?.map(r=>`${r.instancePath} ${r.message}`).join(", ")}}export{f as createValidator,h as validateWithResult};
