UNPKG

@charliethomson/better-session

Version:

### Adds specific and useful typing, and security through obscurity to the browser storage

1 lines 149 kB
(function(ke,ee){typeof exports=="object"&&typeof module<"u"?ee(exports):typeof define=="function"&&define.amd?define(["exports"],ee):(ke=typeof globalThis<"u"?globalThis:ke||self,ee(ke["better-session"]={}))})(this,function(ke){"use strict";var ni=Object.defineProperty;var ai=(ke,ee,Me)=>ee in ke?ni(ke,ee,{enumerable:!0,configurable:!0,writable:!0,value:Me}):ke[ee]=Me;var mr=(ke,ee,Me)=>(ai(ke,typeof ee!="symbol"?ee+"":ee,Me),Me);var ee;(function(n){n.assertEqual=s=>s;function e(s){}n.assertIs=e;function t(s){throw new Error}n.assertNever=t,n.arrayToEnum=s=>{const i={};for(const l of s)i[l]=l;return i},n.getValidEnumValues=s=>{const i=n.objectKeys(s).filter(c=>typeof s[s[c]]!="number"),l={};for(const c of i)l[c]=s[c];return n.objectValues(l)},n.objectValues=s=>n.objectKeys(s).map(function(i){return s[i]}),n.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const l in s)Object.prototype.hasOwnProperty.call(s,l)&&i.push(l);return i},n.find=(s,i)=>{for(const l of s)if(i(l))return l},n.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(l=>typeof l=="string"?`'${l}'`:l).join(i)}n.joinValues=r,n.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(ee||(ee={}));var Me;(function(n){n.mergeShapes=(e,t)=>({...e,...t})})(Me||(Me={}));const M=ee.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ke=n=>{switch(typeof n){case"undefined":return M.undefined;case"string":return M.string;case"number":return isNaN(n)?M.nan:M.number;case"boolean":return M.boolean;case"function":return M.function;case"bigint":return M.bigint;case"symbol":return M.symbol;case"object":return Array.isArray(n)?M.array:n===null?M.null:n.then&&typeof n.then=="function"&&n.catch&&typeof n.catch=="function"?M.promise:typeof Map<"u"&&n instanceof Map?M.map:typeof Set<"u"&&n instanceof Set?M.set:typeof Date<"u"&&n instanceof Date?M.date:M.object;default:return M.unknown}},Z=ee.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]),Wn=n=>JSON.stringify(n,null,2).replace(/"([^"]+)":/g,"$1:");class Oe extends Error{constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const t=e||function(i){return i.message},r={_errors:[]},s=i=>{for(const l of i.issues)if(l.code==="invalid_union")l.unionErrors.map(s);else if(l.code==="invalid_return_type")s(l.returnTypeError);else if(l.code==="invalid_arguments")s(l.argumentsError);else if(l.path.length===0)r._errors.push(t(l));else{let c=r,x=0;for(;x<l.path.length;){const o=l.path[x];x===l.path.length-1?(c[o]=c[o]||{_errors:[]},c[o]._errors.push(t(l))):c[o]=c[o]||{_errors:[]},c=c[o],x++}}};return s(this),r}toString(){return this.message}get message(){return JSON.stringify(this.issues,ee.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=t=>t.message){const t={},r=[];for(const s of this.issues)s.path.length>0?(t[s.path[0]]=t[s.path[0]]||[],t[s.path[0]].push(e(s))):r.push(e(s));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}Oe.create=n=>new Oe(n);const Rt=(n,e)=>{let t;switch(n.code){case Z.invalid_type:n.received===M.undefined?t="Required":t=`Expected ${n.expected}, received ${n.received}`;break;case Z.invalid_literal:t=`Invalid literal value, expected ${JSON.stringify(n.expected,ee.jsonStringifyReplacer)}`;break;case Z.unrecognized_keys:t=`Unrecognized key(s) in object: ${ee.joinValues(n.keys,", ")}`;break;case Z.invalid_union:t="Invalid input";break;case Z.invalid_union_discriminator:t=`Invalid discriminator value. Expected ${ee.joinValues(n.options)}`;break;case Z.invalid_enum_value:t=`Invalid enum value. Expected ${ee.joinValues(n.options)}, received '${n.received}'`;break;case Z.invalid_arguments:t="Invalid function arguments";break;case Z.invalid_return_type:t="Invalid function return type";break;case Z.invalid_date:t="Invalid date";break;case Z.invalid_string:typeof n.validation=="object"?"includes"in n.validation?(t=`Invalid input: must include "${n.validation.includes}"`,typeof n.validation.position=="number"&&(t=`${t} at one or more positions greater than or equal to ${n.validation.position}`)):"startsWith"in n.validation?t=`Invalid input: must start with "${n.validation.startsWith}"`:"endsWith"in n.validation?t=`Invalid input: must end with "${n.validation.endsWith}"`:ee.assertNever(n.validation):n.validation!=="regex"?t=`Invalid ${n.validation}`:t="Invalid";break;case Z.too_small:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at least":"more than"} ${n.minimum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at least":"over"} ${n.minimum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${n.minimum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly equal to ":n.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(n.minimum))}`:t="Invalid input";break;case Z.too_big:n.type==="array"?t=`Array must contain ${n.exact?"exactly":n.inclusive?"at most":"less than"} ${n.maximum} element(s)`:n.type==="string"?t=`String must contain ${n.exact?"exactly":n.inclusive?"at most":"under"} ${n.maximum} character(s)`:n.type==="number"?t=`Number must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="bigint"?t=`BigInt must be ${n.exact?"exactly":n.inclusive?"less than or equal to":"less than"} ${n.maximum}`:n.type==="date"?t=`Date must be ${n.exact?"exactly":n.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(n.maximum))}`:t="Invalid input";break;case Z.custom:t="Invalid input";break;case Z.invalid_intersection_types:t="Intersection results could not be merged";break;case Z.not_multiple_of:t=`Number must be a multiple of ${n.multipleOf}`;break;case Z.not_finite:t="Number must be finite";break;default:t=e.defaultError,ee.assertNever(n)}return{message:t}};let w0=Rt;function Fn(n){w0=n}function Mt(){return w0}const qt=n=>{const{data:e,path:t,errorMaps:r,issueData:s}=n,i=[...t,...s.path||[]],l={...s,path:i};let c="";const x=r.filter(o=>!!o).slice().reverse();for(const o of x)c=o(l,{data:e,defaultError:c}).message;return{...s,path:i,message:s.message||c}},Un=[];function q(n,e){const t=qt({issueData:e,data:n.data,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,Mt(),Rt].filter(r=>!!r)});n.common.issues.push(t)}class we{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,t){const r=[];for(const s of t){if(s.status==="aborted")return te;s.status==="dirty"&&e.dirty(),r.push(s.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){const r=[];for(const s of t)r.push({key:await s.key,value:await s.value});return we.mergeObjectSync(e,r)}static mergeObjectSync(e,t){const r={};for(const s of t){const{key:i,value:l}=s;if(i.status==="aborted"||l.status==="aborted")return te;i.status==="dirty"&&e.dirty(),l.status==="dirty"&&e.dirty(),(typeof l.value<"u"||s.alwaysSet)&&(r[i.value]=l.value)}return{status:e.value,value:r}}}const te=Object.freeze({status:"aborted"}),C0=n=>({status:"dirty",value:n}),Ee=n=>({status:"valid",value:n}),_r=n=>n.status==="aborted",gr=n=>n.status==="dirty",Wt=n=>n.status==="valid",Ft=n=>typeof Promise<"u"&&n instanceof Promise;var Y;(function(n){n.errToObj=e=>typeof e=="string"?{message:e}:e||{},n.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(Y||(Y={}));class je{constructor(e,t,r,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=s}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const S0=(n,e)=>{if(Wt(e))return{success:!0,data:e.value};if(!n.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const t=new Oe(n.common.issues);return this._error=t,this._error}}};function ne(n){if(!n)return{};const{errorMap:e,invalid_type_error:t,required_error:r,description:s}=n;if(e&&(t||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:s}:{errorMap:(l,c)=>l.code!=="invalid_type"?{message:c.defaultError}:typeof c.data>"u"?{message:r??c.defaultError}:{message:t??c.defaultError},description:s}}class ae{constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this)}get description(){return this._def.description}_getType(e){return Ke(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:Ke(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new we,ctx:{common:e.parent.common,data:e.data,parsedType:Ke(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Ft(t))throw new Error("Synchronous parse encountered promise.");return t}_parseAsync(e){const t=this._parse(e);return Promise.resolve(t)}parse(e,t){const r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){var r;const s={common:{issues:[],async:(r=t==null?void 0:t.async)!==null&&r!==void 0?r:!1,contextualErrorMap:t==null?void 0:t.errorMap},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ke(e)},i=this._parseSync({data:e,path:s.path,parent:s});return S0(s,i)}async parseAsync(e,t){const r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){const r={common:{issues:[],contextualErrorMap:t==null?void 0:t.errorMap,async:!0},path:(t==null?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ke(e)},s=this._parse({data:e,path:r.path,parent:r}),i=await(Ft(s)?s:Promise.resolve(s));return S0(r,i)}refine(e,t){const r=s=>typeof t=="string"||typeof t>"u"?{message:t}:typeof t=="function"?t(s):t;return this._refinement((s,i)=>{const l=e(s),c=()=>i.addIssue({code:Z.custom,...r(s)});return typeof Promise<"u"&&l instanceof Promise?l.then(x=>x?!0:(c(),!1)):l?!0:(c(),!1)})}refinement(e,t){return this._refinement((r,s)=>e(r)?!0:(s.addIssue(typeof t=="function"?t(r,s):t),!1))}_refinement(e){return new Ne({schema:this,typeName:X.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return We.create(this,this._def)}nullable(){return st.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Ie.create(this,this._def)}promise(){return vt.create(this,this._def)}or(e){return Ot.create([this,e],this._def)}and(e){return Pt.create(this,e,this._def)}transform(e){return new Ne({...ne(this._def),schema:this,typeName:X.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t=typeof e=="function"?e:()=>e;return new zt({...ne(this._def),innerType:this,defaultValue:t,typeName:X.ZodDefault})}brand(){return new R0({typeName:X.ZodBranded,type:this,...ne(this._def)})}catch(e){const t=typeof e=="function"?e:()=>e;return new Xt({...ne(this._def),innerType:this,catchValue:t,typeName:X.ZodCatch})}describe(e){const t=this.constructor;return new t({...this._def,description:e})}pipe(e){return Ht.create(this,e)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const Vn=/^c[^\s-]{8,}$/i,Yn=/^[a-z][a-z0-9]*$/,Kn=/[0-9A-HJKMNP-TV-Z]{26}/,Gn=/^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i,Xn=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/,Qn=/^(\p{Extended_Pictographic}|\p{Emoji_Component})+$/u,Jn=/^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/,ea=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,ta=n=>n.precision?n.offset?new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${n.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`):new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${n.precision}}Z$`):n.precision===0?n.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"):n.offset?new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$"):new RegExp("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$");function ra(n,e){return!!((e==="v4"||!e)&&Jn.test(n)||(e==="v6"||!e)&&ea.test(n))}class Pe extends ae{constructor(){super(...arguments),this._regex=(e,t,r)=>this.refinement(s=>e.test(s),{validation:t,code:Z.invalid_string,...Y.errToObj(r)}),this.nonempty=e=>this.min(1,Y.errToObj(e)),this.trim=()=>new Pe({...this._def,checks:[...this._def.checks,{kind:"trim"}]}),this.toLowerCase=()=>new Pe({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]}),this.toUpperCase=()=>new Pe({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==M.string){const i=this._getOrReturnCtx(e);return q(i,{code:Z.invalid_type,expected:M.string,received:i.parsedType}),te}const r=new we;let s;for(const i of this._def.checks)if(i.kind==="min")e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),q(s,{code:Z.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),q(s,{code:Z.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){const l=e.data.length>i.value,c=e.data.length<i.value;(l||c)&&(s=this._getOrReturnCtx(e,s),l?q(s,{code:Z.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):c&&q(s,{code:Z.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")Xn.test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"email",code:Z.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")Qn.test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"emoji",code:Z.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")Gn.test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"uuid",code:Z.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")Vn.test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"cuid",code:Z.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")Yn.test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"cuid2",code:Z.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")Kn.test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"ulid",code:Z.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(e.data)}catch{s=this._getOrReturnCtx(e,s),q(s,{validation:"url",code:Z.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"regex",code:Z.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?e.data=e.data.trim():i.kind==="includes"?e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),q(s,{code:Z.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?e.data=e.data.toLowerCase():i.kind==="toUpperCase"?e.data=e.data.toUpperCase():i.kind==="startsWith"?e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),q(s,{code:Z.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),q(s,{code:Z.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?ta(i).test(e.data)||(s=this._getOrReturnCtx(e,s),q(s,{code:Z.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="ip"?ra(e.data,i.version)||(s=this._getOrReturnCtx(e,s),q(s,{validation:"ip",code:Z.invalid_string,message:i.message}),r.dirty()):ee.assertNever(i);return{status:r.value,value:e.data}}_addCheck(e){return new Pe({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...Y.errToObj(e)})}url(e){return this._addCheck({kind:"url",...Y.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...Y.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...Y.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...Y.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...Y.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...Y.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...Y.errToObj(e)})}datetime(e){var t;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(t=e==null?void 0:e.offset)!==null&&t!==void 0?t:!1,...Y.errToObj(e==null?void 0:e.message)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...Y.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t==null?void 0:t.position,...Y.errToObj(t==null?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...Y.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...Y.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...Y.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...Y.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...Y.errToObj(t)})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get minLength(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Pe.create=n=>{var e;return new Pe({checks:[],typeName:X.ZodString,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...ne(n)})};function na(n,e){const t=(n.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,s=t>r?t:r,i=parseInt(n.toFixed(s).replace(".","")),l=parseInt(e.toFixed(s).replace(".",""));return i%l/Math.pow(10,s)}class Ge extends ae{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==M.number){const i=this._getOrReturnCtx(e);return q(i,{code:Z.invalid_type,expected:M.number,received:i.parsedType}),te}let r;const s=new we;for(const i of this._def.checks)i.kind==="int"?ee.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),q(r,{code:Z.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),q(r,{code:Z.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),q(r,{code:Z.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?na(e.data,i.value)!==0&&(r=this._getOrReturnCtx(e,r),q(r,{code:Z.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),q(r,{code:Z.not_finite,message:i.message}),s.dirty()):ee.assertNever(i);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,Y.toString(t))}gt(e,t){return this.setLimit("min",e,!1,Y.toString(t))}lte(e,t){return this.setLimit("max",e,!0,Y.toString(t))}lt(e,t){return this.setLimit("max",e,!1,Y.toString(t))}setLimit(e,t,r,s){return new Ge({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:Y.toString(s)}]})}_addCheck(e){return new Ge({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:Y.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:Y.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:Y.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:Y.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:Y.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:Y.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:Y.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:Y.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:Y.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&ee.isInteger(e.value))}get isFinite(){let e=null,t=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(t===null||r.value>t)&&(t=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(t)&&Number.isFinite(e)}}Ge.create=n=>new Ge({checks:[],typeName:X.ZodNumber,coerce:(n==null?void 0:n.coerce)||!1,...ne(n)});class Xe extends ae{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==M.bigint){const i=this._getOrReturnCtx(e);return q(i,{code:Z.invalid_type,expected:M.bigint,received:i.parsedType}),te}let r;const s=new we;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?e.data<i.value:e.data<=i.value)&&(r=this._getOrReturnCtx(e,r),q(r,{code:Z.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?e.data>i.value:e.data>=i.value)&&(r=this._getOrReturnCtx(e,r),q(r,{code:Z.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?e.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),q(r,{code:Z.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):ee.assertNever(i);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,Y.toString(t))}gt(e,t){return this.setLimit("min",e,!1,Y.toString(t))}lte(e,t){return this.setLimit("max",e,!0,Y.toString(t))}lt(e,t){return this.setLimit("max",e,!1,Y.toString(t))}setLimit(e,t,r,s){return new Xe({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:Y.toString(s)}]})}_addCheck(e){return new Xe({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:Y.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:Y.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:Y.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:Y.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:Y.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e}}Xe.create=n=>{var e;return new Xe({checks:[],typeName:X.ZodBigInt,coerce:(e=n==null?void 0:n.coerce)!==null&&e!==void 0?e:!1,...ne(n)})};class Tt extends ae{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==M.boolean){const r=this._getOrReturnCtx(e);return q(r,{code:Z.invalid_type,expected:M.boolean,received:r.parsedType}),te}return Ee(e.data)}}Tt.create=n=>new Tt({typeName:X.ZodBoolean,coerce:(n==null?void 0:n.coerce)||!1,...ne(n)});class rt extends ae{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==M.date){const i=this._getOrReturnCtx(e);return q(i,{code:Z.invalid_type,expected:M.date,received:i.parsedType}),te}if(isNaN(e.data.getTime())){const i=this._getOrReturnCtx(e);return q(i,{code:Z.invalid_date}),te}const r=new we;let s;for(const i of this._def.checks)i.kind==="min"?e.data.getTime()<i.value&&(s=this._getOrReturnCtx(e,s),q(s,{code:Z.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?e.data.getTime()>i.value&&(s=this._getOrReturnCtx(e,s),q(s,{code:Z.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):ee.assertNever(i);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new rt({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:Y.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:Y.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)t.kind==="min"&&(e===null||t.value>e)&&(e=t.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)t.kind==="max"&&(e===null||t.value<e)&&(e=t.value);return e!=null?new Date(e):null}}rt.create=n=>new rt({checks:[],coerce:(n==null?void 0:n.coerce)||!1,typeName:X.ZodDate,...ne(n)});class Ut extends ae{_parse(e){if(this._getType(e)!==M.symbol){const r=this._getOrReturnCtx(e);return q(r,{code:Z.invalid_type,expected:M.symbol,received:r.parsedType}),te}return Ee(e.data)}}Ut.create=n=>new Ut({typeName:X.ZodSymbol,...ne(n)});class Bt extends ae{_parse(e){if(this._getType(e)!==M.undefined){const r=this._getOrReturnCtx(e);return q(r,{code:Z.invalid_type,expected:M.undefined,received:r.parsedType}),te}return Ee(e.data)}}Bt.create=n=>new Bt({typeName:X.ZodUndefined,...ne(n)});class At extends ae{_parse(e){if(this._getType(e)!==M.null){const r=this._getOrReturnCtx(e);return q(r,{code:Z.invalid_type,expected:M.null,received:r.parsedType}),te}return Ee(e.data)}}At.create=n=>new At({typeName:X.ZodNull,...ne(n)});class dt extends ae{constructor(){super(...arguments),this._any=!0}_parse(e){return Ee(e.data)}}dt.create=n=>new dt({typeName:X.ZodAny,...ne(n)});class nt extends ae{constructor(){super(...arguments),this._unknown=!0}_parse(e){return Ee(e.data)}}nt.create=n=>new nt({typeName:X.ZodUnknown,...ne(n)});class qe extends ae{_parse(e){const t=this._getOrReturnCtx(e);return q(t,{code:Z.invalid_type,expected:M.never,received:t.parsedType}),te}}qe.create=n=>new qe({typeName:X.ZodNever,...ne(n)});class Vt extends ae{_parse(e){if(this._getType(e)!==M.undefined){const r=this._getOrReturnCtx(e);return q(r,{code:Z.invalid_type,expected:M.void,received:r.parsedType}),te}return Ee(e.data)}}Vt.create=n=>new Vt({typeName:X.ZodVoid,...ne(n)});class Ie extends ae{_parse(e){const{ctx:t,status:r}=this._processInputParams(e),s=this._def;if(t.parsedType!==M.array)return q(t,{code:Z.invalid_type,expected:M.array,received:t.parsedType}),te;if(s.exactLength!==null){const l=t.data.length>s.exactLength.value,c=t.data.length<s.exactLength.value;(l||c)&&(q(t,{code:l?Z.too_big:Z.too_small,minimum:c?s.exactLength.value:void 0,maximum:l?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&t.data.length<s.minLength.value&&(q(t,{code:Z.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&t.data.length>s.maxLength.value&&(q(t,{code:Z.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),t.common.async)return Promise.all([...t.data].map((l,c)=>s.type._parseAsync(new je(t,l,t.path,c)))).then(l=>we.mergeArray(r,l));const i=[...t.data].map((l,c)=>s.type._parseSync(new je(t,l,t.path,c)));return we.mergeArray(r,i)}get element(){return this._def.type}min(e,t){return new Ie({...this._def,minLength:{value:e,message:Y.toString(t)}})}max(e,t){return new Ie({...this._def,maxLength:{value:e,message:Y.toString(t)}})}length(e,t){return new Ie({...this._def,exactLength:{value:e,message:Y.toString(t)}})}nonempty(e){return this.min(1,e)}}Ie.create=(n,e)=>new Ie({type:n,minLength:null,maxLength:null,exactLength:null,typeName:X.ZodArray,...ne(e)});function xt(n){if(n instanceof ve){const e={};for(const t in n.shape){const r=n.shape[t];e[t]=We.create(xt(r))}return new ve({...n._def,shape:()=>e})}else return n instanceof Ie?new Ie({...n._def,type:xt(n.element)}):n instanceof We?We.create(xt(n.unwrap())):n instanceof st?st.create(xt(n.unwrap())):n instanceof ze?ze.create(n.items.map(e=>xt(e))):n}class ve extends ae{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),t=ee.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==M.object){const o=this._getOrReturnCtx(e);return q(o,{code:Z.invalid_type,expected:M.object,received:o.parsedType}),te}const{status:r,ctx:s}=this._processInputParams(e),{shape:i,keys:l}=this._getCached(),c=[];if(!(this._def.catchall instanceof qe&&this._def.unknownKeys==="strip"))for(const o in s.data)l.includes(o)||c.push(o);const x=[];for(const o of l){const u=i[o],w=s.data[o];x.push({key:{status:"valid",value:o},value:u._parse(new je(s,w,s.path,o)),alwaysSet:o in s.data})}if(this._def.catchall instanceof qe){const o=this._def.unknownKeys;if(o==="passthrough")for(const u of c)x.push({key:{status:"valid",value:u},value:{status:"valid",value:s.data[u]}});else if(o==="strict")c.length>0&&(q(s,{code:Z.unrecognized_keys,keys:c}),r.dirty());else if(o!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const o=this._def.catchall;for(const u of c){const w=s.data[u];x.push({key:{status:"valid",value:u},value:o._parse(new je(s,w,s.path,u)),alwaysSet:u in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const o=[];for(const u of x){const w=await u.key;o.push({key:w,value:await u.value,alwaysSet:u.alwaysSet})}return o}).then(o=>we.mergeObjectSync(r,o)):we.mergeObjectSync(r,x)}get shape(){return this._def.shape()}strict(e){return Y.errToObj,new ve({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{var s,i,l,c;const x=(l=(i=(s=this._def).errorMap)===null||i===void 0?void 0:i.call(s,t,r).message)!==null&&l!==void 0?l:r.defaultError;return t.code==="unrecognized_keys"?{message:(c=Y.errToObj(e).message)!==null&&c!==void 0?c:x}:{message:x}}}:{}})}strip(){return new ve({...this._def,unknownKeys:"strip"})}passthrough(){return new ve({...this._def,unknownKeys:"passthrough"})}extend(e){return new ve({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new ve({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:X.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new ve({...this._def,catchall:e})}pick(e){const t={};return ee.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(t[r]=this.shape[r])}),new ve({...this._def,shape:()=>t})}omit(e){const t={};return ee.objectKeys(this.shape).forEach(r=>{e[r]||(t[r]=this.shape[r])}),new ve({...this._def,shape:()=>t})}deepPartial(){return xt(this)}partial(e){const t={};return ee.objectKeys(this.shape).forEach(r=>{const s=this.shape[r];e&&!e[r]?t[r]=s:t[r]=s.optional()}),new ve({...this._def,shape:()=>t})}required(e){const t={};return ee.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])t[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof We;)i=i._def.innerType;t[r]=i}}),new ve({...this._def,shape:()=>t})}keyof(){return E0(ee.objectKeys(this.shape))}}ve.create=(n,e)=>new ve({shape:()=>n,unknownKeys:"strip",catchall:qe.create(),typeName:X.ZodObject,...ne(e)}),ve.strictCreate=(n,e)=>new ve({shape:()=>n,unknownKeys:"strict",catchall:qe.create(),typeName:X.ZodObject,...ne(e)}),ve.lazycreate=(n,e)=>new ve({shape:n,unknownKeys:"strip",catchall:qe.create(),typeName:X.ZodObject,...ne(e)});class Ot extends ae{_parse(e){const{ctx:t}=this._processInputParams(e),r=this._def.options;function s(i){for(const c of i)if(c.result.status==="valid")return c.result;for(const c of i)if(c.result.status==="dirty")return t.common.issues.push(...c.ctx.common.issues),c.result;const l=i.map(c=>new Oe(c.ctx.common.issues));return q(t,{code:Z.invalid_union,unionErrors:l}),te}if(t.common.async)return Promise.all(r.map(async i=>{const l={...t,common:{...t.common,issues:[]},parent:null};return{result:await i._parseAsync({data:t.data,path:t.path,parent:l}),ctx:l}})).then(s);{let i;const l=[];for(const x of r){const o={...t,common:{...t.common,issues:[]},parent:null},u=x._parseSync({data:t.data,path:t.path,parent:o});if(u.status==="valid")return u;u.status==="dirty"&&!i&&(i={result:u,ctx:o}),o.common.issues.length&&l.push(o.common.issues)}if(i)return t.common.issues.push(...i.ctx.common.issues),i.result;const c=l.map(x=>new Oe(x));return q(t,{code:Z.invalid_union,unionErrors:c}),te}}get options(){return this._def.options}}Ot.create=(n,e)=>new Ot({options:n,typeName:X.ZodUnion,...ne(e)});const Yt=n=>n instanceof Nt?Yt(n.schema):n instanceof Ne?Yt(n.innerType()):n instanceof Dt?[n.value]:n instanceof Qe?n.options:n instanceof jt?Object.keys(n.enum):n instanceof zt?Yt(n._def.innerType):n instanceof Bt?[void 0]:n instanceof At?[null]:null;class Kt extends ae{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==M.object)return q(t,{code:Z.invalid_type,expected:M.object,received:t.parsedType}),te;const r=this.discriminator,s=t.data[r],i=this.optionsMap.get(s);return i?t.common.async?i._parseAsync({data:t.data,path:t.path,parent:t}):i._parseSync({data:t.data,path:t.path,parent:t}):(q(t,{code:Z.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),te)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){const s=new Map;for(const i of t){const l=Yt(i.shape[e]);if(!l)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const c of l){if(s.has(c))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(c)}`);s.set(c,i)}}return new Kt({typeName:X.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:s,...ne(r)})}}function br(n,e){const t=Ke(n),r=Ke(e);if(n===e)return{valid:!0,data:n};if(t===M.object&&r===M.object){const s=ee.objectKeys(e),i=ee.objectKeys(n).filter(c=>s.indexOf(c)!==-1),l={...n,...e};for(const c of i){const x=br(n[c],e[c]);if(!x.valid)return{valid:!1};l[c]=x.data}return{valid:!0,data:l}}else if(t===M.array&&r===M.array){if(n.length!==e.length)return{valid:!1};const s=[];for(let i=0;i<n.length;i++){const l=n[i],c=e[i],x=br(l,c);if(!x.valid)return{valid:!1};s.push(x.data)}return{valid:!0,data:s}}else return t===M.date&&r===M.date&&+n==+e?{valid:!0,data:n}:{valid:!1}}class Pt extends ae{_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=(i,l)=>{if(_r(i)||_r(l))return te;const c=br(i.value,l.value);return c.valid?((gr(i)||gr(l))&&t.dirty(),{status:t.value,value:c.data}):(q(r,{code:Z.invalid_intersection_types}),te)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([i,l])=>s(i,l)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Pt.create=(n,e,t)=>new Pt({left:n,right:e,typeName:X.ZodIntersection,...ne(t)});class ze extends ae{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.array)return q(r,{code:Z.invalid_type,expected:M.array,received:r.parsedType}),te;if(r.data.length<this._def.items.length)return q(r,{code:Z.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),te;!this._def.rest&&r.data.length>this._def.items.length&&(q(r,{code:Z.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const i=[...r.data].map((l,c)=>{const x=this._def.items[c]||this._def.rest;return x?x._parse(new je(r,l,r.path,c)):null}).filter(l=>!!l);return r.common.async?Promise.all(i).then(l=>we.mergeArray(t,l)):we.mergeArray(t,i)}get items(){return this._def.items}rest(e){return new ze({...this._def,rest:e})}}ze.create=(n,e)=>{if(!Array.isArray(n))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ze({items:n,typeName:X.ZodTuple,rest:null,...ne(e)})};class It extends ae{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.object)return q(r,{code:Z.invalid_type,expected:M.object,received:r.parsedType}),te;const s=[],i=this._def.keyType,l=this._def.valueType;for(const c in r.data)s.push({key:i._parse(new je(r,c,r.path,c)),value:l._parse(new je(r,r.data[c],r.path,c))});return r.common.async?we.mergeObjectAsync(t,s):we.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(e,t,r){return t instanceof ae?new It({keyType:e,valueType:t,typeName:X.ZodRecord,...ne(r)}):new It({keyType:Pe.create(),valueType:e,typeName:X.ZodRecord,...ne(t)})}}class Gt extends ae{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.map)return q(r,{code:Z.invalid_type,expected:M.map,received:r.parsedType}),te;const s=this._def.keyType,i=this._def.valueType,l=[...r.data.entries()].map(([c,x],o)=>({key:s._parse(new je(r,c,r.path,[o,"key"])),value:i._parse(new je(r,x,r.path,[o,"value"]))}));if(r.common.async){const c=new Map;return Promise.resolve().then(async()=>{for(const x of l){const o=await x.key,u=await x.value;if(o.status==="aborted"||u.status==="aborted")return te;(o.status==="dirty"||u.status==="dirty")&&t.dirty(),c.set(o.value,u.value)}return{status:t.value,value:c}})}else{const c=new Map;for(const x of l){const o=x.key,u=x.value;if(o.status==="aborted"||u.status==="aborted")return te;(o.status==="dirty"||u.status==="dirty")&&t.dirty(),c.set(o.value,u.value)}return{status:t.value,value:c}}}}Gt.create=(n,e,t)=>new Gt({valueType:e,keyType:n,typeName:X.ZodMap,...ne(t)});class at extends ae{_parse(e){const{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.set)return q(r,{code:Z.invalid_type,expected:M.set,received:r.parsedType}),te;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(q(r,{code:Z.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(q(r,{code:Z.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const i=this._def.valueType;function l(x){const o=new Set;for(const u of x){if(u.status==="aborted")return te;u.status==="dirty"&&t.dirty(),o.add(u.value)}return{status:t.value,value:o}}const c=[...r.data.values()].map((x,o)=>i._parse(new je(r,x,r.path,o)));return r.common.async?Promise.all(c).then(x=>l(x)):l(c)}min(e,t){return new at({...this._def,minSize:{value:e,message:Y.toString(t)}})}max(e,t){return new at({...this._def,maxSize:{value:e,message:Y.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}at.create=(n,e)=>new at({valueType:n,minSize:null,maxSize:null,typeName:X.ZodSet,...ne(e)});class ht extends ae{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==M.function)return q(t,{code:Z.invalid_type,expected:M.function,received:t.parsedType}),te;function r(c,x){return qt({data:c,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Mt(),Rt].filter(o=>!!o),issueData:{code:Z.invalid_arguments,argumentsError:x}})}function s(c,x){return qt({data:c,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Mt(),Rt].filter(o=>!!o),issueData:{code:Z.invalid_return_type,returnTypeError:x}})}const i={errorMap:t.common.contextualErrorMap},l=t.data;return this._def.returns instanceof vt?Ee(async(...c)=>{const x=new Oe([]),o=await this._def.args.parseAsync(c,i).catch(f=>{throw x.addIssue(r(c,f)),x}),u=await l(...o);return await this._def.returns._def.type.parseAsync(u,i).catch(f=>{throw x.addIssue(s(u,f)),x})}):Ee((...c)=>{const x=this._def.args.safeParse(c,i);if(!x.success)throw new Oe([r(c,x.error)]);const o=l(...x.data),u=this._def.returns.safeParse(o,i);if(!u.success)throw new Oe([s(o,u.error)]);return u.data})}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new ht({...this._def,args:ze.create(e).rest(nt.create())})}returns(e){return new ht({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new ht({args:e||ze.create([]).rest(nt.create()),returns:t||nt.create(),typeName:X.ZodFunction,...ne(r)})}}class Nt extends ae{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Nt.create=(n,e)=>new Nt({getter:n,typeName:X.ZodLazy,...ne(e)});class Dt extends ae{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return q(t,{received:t.data,code:Z.invalid_literal,expected:this._def.value}),te}return{status:"valid",value:e.data}}get value(){return this._def.value}}Dt.create=(n,e)=>new Dt({value:n,typeName:X.ZodLiteral,...ne(e)});function E0(n,e){return new Qe({values:n,typeName:X.ZodEnum,...ne(e)})}class Qe extends ae{_parse(e){if(typeof e.data!="string"){const t=this._getOrReturnCtx(e),r=this._def.values;return q(t,{expected:ee.joinValues(r),received:t.parsedType,code:Z.invalid_type}),te}if(this._def.values.indexOf(e.data)===-1){const t=this._getOrReturnCtx(e),r=this._def.values;return q(t,{received:t.data,code:Z.invalid_enum_value,options:r}),te}return Ee(e.data)}get options(){return this._def.values}get enum(){const e={};for(const t of this._def.values)e[t]=t;return e}get Values(){const e={};for(const t of this._def.values)e[t]=t;return e}get Enum(){const e={};for(const t of this._def.values)e[t]=t;return e}extract(e){return Qe.create(e)}exclude(e){return Qe.create(this.options.filter(t=>!e.includes(t)))}}Qe.create=E0;class jt extends ae{_parse(e){const t=ee.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==M.string&&r.parsedType!==M.number){const s=ee.objectValues(t);return q(r,{expected:ee.joinValues(s),received:r.parsedType,code:Z.invalid_type}),te}if(t.indexOf(e.data)===-1){const s=ee.objectValues(t);return q(r,{received:r.data,code:Z.invalid_enum_value,options:s}),te}return Ee(e.data)}get enum(){return this._def.values}}jt.create=(n,e)=>new jt({values:n,typeName:X.ZodNativeEnum,...ne(e)});class vt extends ae{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==M.promise&&t.common.async===!1)return q(t,{code:Z.invalid_type,expected:M.promise,received:t.parsedType}),te;const r=t.parsedType===M.promise?t.data:Promise.resolve(t.data);return Ee(r.then(s=>this._def.type.parseAsync(s,{path:t.path,errorMap:t.common.contextualErrorMap})))}}vt.create=(n,e)=>new vt({type:n,typeName:X.ZodPromise,...ne(e)});class Ne extends ae{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===X.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:r}=this._processInputParams(e),s=this._def.effect||null;if(s.type==="preprocess"){const l=s.transform(r.data);return r.common.async?Promise.resolve(l).then(c=>this._def.schema._parseAsync({data:c,path:r.path,parent:r})):this._def.schema._parseSync({data:l,path:r.path,parent:r})}const i={addIssue:l=>{q(r,l),l.fatal?t.abort():t.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="refinement"){const l=c=>{const x=s.refinement(c,i);if(r.common.async)return Promise.resolve(x);if(x instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return c};if(r.common.async===!1){const c=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return c.status==="aborted"?te:(c.status==="dirty"&&t.dirty(),l(c.value),{status:t.value,value:c.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(c=>c.status==="aborted"?te:(c.status==="dirty"&&t.dirty(),l(c.value).then(()=>({status:t.value,value:c.value}))))}if(s.type==="transform")if(r.common.async===!1){const l=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Wt(l))return l;const c=s.transform(l.value,i);if(c instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:c}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(l=>Wt(l)?Promise.resolve(s.transform(l.value,i)).then(c=>({status:t.value,value:c})):l);ee.assertNever(s)}}Ne.create=(n,e,t)=>new Ne({schema:n,typeName:X.ZodEffects,effect:e,...ne(t)}),Ne.createWithPreprocess=(n,e,t)=>new Ne({schema:e,effect:{type:"preprocess",transform:n},typeName:X.ZodEffects,...ne(t)});class We extends ae{_parse(e){return this._getType(e)===M.undefined?Ee(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}We.create=(n,e)=>new We({innerType:n,typeName:X.ZodOptional,...ne(e)});class st extends ae{_parse(e){return this._getType(e)===M.null?Ee(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}st.create=(n,e)=>new st({innerType:n,typeName:X.ZodNullable,...ne(e)});class zt extends ae{_parse(e){const{ctx:t}=this._processInputParams(e);let r=t.data;return t.parsedType===M.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}zt.create=(n,e)=>new zt({innerType:n,typeName:X.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...ne(e)});class Xt extends ae{_parse(e){const{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Ft(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new Oe(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new Oe(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Xt.create=(n,e)=>new Xt({innerType:n,typeName:X.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...ne(e)});class Qt extends ae{_parse(e){if(this._getType(e)!==M.nan){const r=this._getOrReturnCtx(e);return q(r,{code:Z.invali