@vee-validate/zod
Version:
vee-validate integration with zod schema validation
6 lines • 2.3 kB
JavaScript
/**
* vee-validate v4.15.1
* (c) 2025 Abdelrahman Awad
* @license MIT
*/
var VeeValidateZod=function(t,e,r){"use strict";const n=t=>null!==t&&!!t&&"object"==typeof t&&!Array.isArray(t);function o(t){return Number(t)>=0}function i(t){if(!function(t){return"object"==typeof t&&null!==t}(t)||"[object Object]"!==function(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}(t))return!1;if(null===Object.getPrototypeOf(t))return!0;let e=t;for(;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}function u(t,e){return Object.keys(e).forEach((r=>{if(i(e[r])&&i(t[r]))return t[r]||(t[r]={}),void u(t[r],e[r]);t[r]=e[r]})),t}function s(t,e){return{__type:"VVTypedSchema",async parse(r){const n=await t.safeParseAsync(r,e);if(n.success)return{value:n.data,errors:[]};const o={};return c(n.error.issues,o),{errors:Object.values(o)}},cast(e){try{return t.parse(e)}catch(r){const o=a(t);return n(o)&&n(e)?u(o,e):e}},describe(e){try{if(!e)return{required:!t.isOptional(),exists:!0};const n=function(t,e){if(!y(e))return null;if(r.isNotNestedPath(t))return e.shape[r.cleanupNonNestedPath(t)];const n=(t||"").split(/\.|\[(\d+)\]/).filter(Boolean);let i=e;for(let t=0;t<=n.length;t++){const e=n[t];if(!e||!i)return i;y(i)?i=i.shape[e]||null:o(e)&&p(i)&&(i=i._def.type)}return null}(e,t);return n?{required:!n.isOptional(),exists:!0}:{required:!1,exists:!1}}catch(t){return{required:!1,exists:!1}}}}}function c(t,e){t.forEach((t=>{const r=function(t){const e=t.split(".");if(!e.length)return"";let r=String(e[0]);for(let t=1;t<e.length;t++)o(e[t])?r+=`[${e[t]}]`:r+=`.${e[t]}`;return r}(t.path.join("."));("invalid_union"!==t.code||(c(t.unionErrors.flatMap((t=>t.issues)),e),r))&&(e[r]||(e[r]={errors:[],path:r}),e[r].errors.push(t.message))}))}function a(t){if(t instanceof e.ZodObject)return Object.fromEntries(Object.entries(t.shape).map((([t,r])=>r instanceof e.ZodDefault?[t,r._def.defaultValue()]:r instanceof e.ZodObject?[t,a(r)]:[t,void 0])))}const f=s,l=s;function d(t){return t._def.typeName}function p(t){return d(t)===e.ZodFirstPartyTypeKind.ZodArray}function y(t){return d(t)===e.ZodFirstPartyTypeKind.ZodObject}return t.toFieldValidator=f,t.toFormValidator=l,t.toTypedSchema=s,t}({},zod,VeeValidate);