zaileys 0.29.18-beta → 0.29.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import e,{makeCacheableSignalKeyStore as t,Browsers as a,DisconnectReason as s}from"baileys";import n from"node-cache";import r from"pino";import i from"better-sqlite3";import{mkdirSync as o,writeFileSync as d}from"fs";import{Kysely as c,SqliteDialect as u,MysqlDialect as l,PostgresDialect as h}from"kysely";import p from"mysql2";import m from"path";import{Pool as f}from"pg";import{URL as y}from"url";import{randomBytes as v,randomUUID as g}from"crypto";import{curve as _}from"libsignal";var x,b,k,w=_,Z=()=>{const{pubKey:e,privKey:t}=w.generateKeyPair();return{private:Buffer.from(t),public:Buffer.from(e.slice(1))}},T=(e,t)=>{const a=Z(),s=(e=>33===e.length?e:Buffer.concat([Buffer.from([5]),e]))(a.public);var n,r;return{keyPair:a,signature:(n=e.private,r=s,w.calculateSignature(n,r)),keyId:t}},C=e=>{const t={...e.fingerprint,deviceIndexes:Array.isArray(e.fingerprint.deviceIndexes)?e.fingerprint.deviceIndexes:[]},a={keyData:Array.isArray(e.keyData)?e.keyData:new Uint8Array,fingerprint:{rawId:t.rawId||0,currentIndex:t.rawId||0,deviceIndexes:t.deviceIndexes},timestamp:(s=e.timestamp,"string"==typeof s?parseInt(s,10):s)};var s;return"string"==typeof e.keyData&&(a.keyData=(e=>{let t=e.length;if(!t)return new Uint8Array(1);let a=0;for(;--t%4>1&&"="===e.charAt(t);)++a;return new Uint8Array(Math.ceil(3*e.length)/4-a).fill(0)})(e.keyData)),a},N=(e,t)=>"Buffer"===t?.type&&Array.isArray(t?.data)?{type:"Buffer",data:Buffer.from(t?.data).toString("base64")}:t,O=(e,t)=>"Buffer"===t?.type?Buffer.from(t?.data,"base64"):t,S=async(e,t)=>{const a="auth";await(async e=>{await e.schema.createTable("auth").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("auth_session_id_unique",["session","id"]).execute(),await e.schema.createTable("chats").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("chats_session_id_unique",["session","id"]).execute(),await e.schema.createTable("contacts").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("contacts_session_id_unique",["session","id"]).execute(),await e.schema.createTable("messages").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("messages_session_id_unique",["session","id"]).execute(),await e.schema.createIndex("auth_session_idx").ifNotExists().on("auth").column("session").execute(),await e.schema.createIndex("auth_id_idx").ifNotExists().on("auth").column("id").execute(),await e.schema.createIndex("chats_session_idx").ifNotExists().on("chats").column("session").execute(),await e.schema.createIndex("chats_id_idx").ifNotExists().on("chats").column("id").execute(),await e.schema.createIndex("contacts_session_idx").ifNotExists().on("contacts").column("session").execute(),await e.schema.createIndex("contacts_id_idx").ifNotExists().on("contacts").column("id").execute(),await e.schema.createIndex("messages_session_idx").ifNotExists().on("messages").column("session").execute(),await e.schema.createIndex("messages_id_idx").ifNotExists().on("messages").column("id").execute()})(e);const s=async e=>{for(let t=0;t<10;t++)try{return await e()}catch(e){await new Promise((e=>setTimeout(e,200)))}throw new Error("Max retries reached")},n=async n=>{const r=await s((()=>e.selectFrom(a).select(["value"]).where("id","=",n).where("session","=",t).executeTakeFirst()));if(!r?.value)return null;const i="object"==typeof r.value?JSON.stringify(r.value):r.value;return JSON.parse(i,O)},r=async(n,r)=>{const i=JSON.stringify(r,N);await s((()=>e.insertInto(a).values({session:t,id:n,value:i}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:i}))).execute()))},i=async n=>{await s((()=>e.deleteFrom(a).where("id","=",n).where("session","=",t).execute()))},o=await n("creds")||(()=>{const e=Z();return{noiseKey:Z(),pairingEphemeralKeyPair:Z(),signedIdentityKey:e,signedPreKey:T(e,1),registrationId:16383&Uint16Array.from(v(2))[0],advSecretKey:v(32).toString("base64"),processedHistoryMessages:[],nextPreKeyId:1,firstUnuploadedPreKeyId:1,accountSyncCounter:0,accountSettings:{unarchiveChats:!1},deviceId:Buffer.from(g().replace(/-/g,""),"hex").toString("base64url"),phoneId:g(),identityId:v(20),backupToken:v(20),registered:!1,registration:{},pairingCode:void 0,lastPropHash:void 0,routingInfo:void 0}})();return{state:{creds:o,keys:{get:async(e,t)=>{const a={};for(const s of t){let t=await n(`${e}-${s}`);"app-state-sync-key"===e&&t&&(t=C(t)),a[s]=t}return a},set:async e=>{for(const t in e)for(const a in e[t]){const s=e[t][a],n=`${t}-${a}`;s?await r(n,s):await i(n)}}}},saveCreds:async()=>{await r("creds",o)},clear:async()=>{await(async()=>{await s((()=>e.deleteFrom(a).where("session","=",t).where("id","!=","creds").execute()))})()},removeCreds:async()=>{await(async()=>{await s((()=>e.deleteFrom(a).where("session","=",t).execute()))})()}}};(b=x||(x={})).assertEqual=e=>e,b.assertIs=function(e){},b.assertNever=function(e){throw new Error},b.arrayToEnum=e=>{const t={};for(const a of e)t[a]=a;return t},b.getValidEnumValues=e=>{const t=b.objectKeys(e).filter((t=>"number"!=typeof e[e[t]])),a={};for(const s of t)a[s]=e[s];return b.objectValues(a)},b.objectValues=e=>b.objectKeys(e).map((function(t){return e[t]})),b.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.push(a);return t},b.find=(e,t)=>{for(const a of e)if(t(a))return a},b.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&isFinite(e)&&Math.floor(e)===e,b.joinValues=function(e,t=" | "){return e.map((e=>"string"==typeof e?`'${e}'`:e)).join(t)},b.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t,(k||(k={})).mergeShapes=(e,t)=>({...e,...t});var I=x.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),A=e=>{switch(typeof e){case"undefined":return I.undefined;case"string":return I.string;case"number":return isNaN(e)?I.nan:I.number;case"boolean":return I.boolean;case"function":return I.function;case"bigint":return I.bigint;case"symbol":return I.symbol;case"object":return Array.isArray(e)?I.array:null===e?I.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?I.promise:"undefined"!=typeof Map&&e instanceof Map?I.map:"undefined"!=typeof Set&&e instanceof Set?I.set:"undefined"!=typeof Date&&e instanceof Date?I.date:I.object;default:return I.unknown}},E=x.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"]),j=class e extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},a={_errors:[]},s=e=>{for(const n of e.issues)if("invalid_union"===n.code)n.unionErrors.map(s);else if("invalid_return_type"===n.code)s(n.returnTypeError);else if("invalid_arguments"===n.code)s(n.argumentsError);else if(0===n.path.length)a._errors.push(t(n));else{let e=a,s=0;for(;s<n.path.length;){const a=n.path[s];s===n.path.length-1?(e[a]=e[a]||{_errors:[]},e[a]._errors.push(t(n))):e[a]=e[a]||{_errors:[]},e=e[a],s++}}};return s(this),a}static assert(t){if(!(t instanceof e))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,x.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},a=[];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))):a.push(e(s));return{formErrors:a,fieldErrors:t}}get formErrors(){return this.flatten()}};j.create=e=>new j(e);var P=(e,t)=>{let a;switch(e.code){case E.invalid_type:a=e.received===I.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case E.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(e.expected,x.jsonStringifyReplacer)}`;break;case E.unrecognized_keys:a=`Unrecognized key(s) in object: ${x.joinValues(e.keys,", ")}`;break;case E.invalid_union:a="Invalid input";break;case E.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${x.joinValues(e.options)}`;break;case E.invalid_enum_value:a=`Invalid enum value. Expected ${x.joinValues(e.options)}, received '${e.received}'`;break;case E.invalid_arguments:a="Invalid function arguments";break;case E.invalid_return_type:a="Invalid function return type";break;case E.invalid_date:a="Invalid date";break;case E.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(a=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(a=`${a} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?a=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?a=`Invalid input: must end with "${e.validation.endsWith}"`:x.assertNever(e.validation):a="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case E.too_small:a="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case E.too_big:a="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case E.custom:a="Invalid input";break;case E.invalid_intersection_types:a="Intersection results could not be merged";break;case E.not_multiple_of:a=`Number must be a multiple of ${e.multipleOf}`;break;case E.not_finite:a="Number must be finite";break;default:a=t.defaultError,x.assertNever(e)}return{message:a}},R=P;function $(){return R}var M=e=>{const{data:t,path:a,errorMaps:s,issueData:n}=e,r=[...a,...n.path||[]],i={...n,path:r};if(void 0!==n.message)return{...n,path:r,message:n.message};let o="";const d=s.filter((e=>!!e)).slice().reverse();for(const e of d)o=e(i,{data:t,defaultError:o}).message;return{...n,path:r,message:o}};function F(e,t){const a=$(),s=M({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,a,a===P?void 0:P].filter((e=>!!e))});e.common.issues.push(s)}var D,L,z,U,q=class e{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const a=[];for(const s of t){if("aborted"===s.status)return V;"dirty"===s.status&&e.dirty(),a.push(s.value)}return{status:e.value,value:a}}static async mergeObjectAsync(t,a){const s=[];for(const e of a){const t=await e.key,a=await e.value;s.push({key:t,value:a})}return e.mergeObjectSync(t,s)}static mergeObjectSync(e,t){const a={};for(const s of t){const{key:t,value:n}=s;if("aborted"===t.status)return V;if("aborted"===n.status)return V;"dirty"===t.status&&e.dirty(),"dirty"===n.status&&e.dirty(),"__proto__"===t.value||void 0===n.value&&!s.alwaysSet||(a[t.value]=n.value)}return{status:e.value,value:a}}},V=Object.freeze({status:"aborted"}),K=e=>({status:"dirty",value:e}),B=e=>({status:"valid",value:e}),J=e=>"aborted"===e.status,W=e=>"dirty"===e.status,H=e=>"valid"===e.status,Y=e=>"undefined"!=typeof Promise&&e instanceof Promise;function G(e,t,a,s){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}function Q(e,t,a,s,n){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,a),a}(L=D||(D={})).errToObj=e=>"string"==typeof e?{message:e}:e||{},L.toString=e=>"string"==typeof e?e:null==e?void 0:e.message;var X=class{constructor(e,t,a,s){this._cachedPath=[],this.parent=e,this.data=t,this._path=a,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}},ee=(e,t)=>{if(H(t))return{success:!0,data:t.value};if(!e.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 j(e.common.issues);return this._error=t,this._error}}};function te(e){if(!e)return{};const{errorMap:t,invalid_type_error:a,required_error:s,description:n}=e;if(t&&(a||s))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:n};return{errorMap:(t,n)=>{var r,i;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:n.defaultError}:void 0===n.data?{message:null!==(r=null!=o?o:s)&&void 0!==r?r:n.defaultError}:"invalid_type"!==t.code?{message:n.defaultError}:{message:null!==(i=null!=o?o:a)&&void 0!==i?i:n.defaultError}},description:n}}var ae,se=class{get description(){return this._def.description}_getType(e){return A(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:A(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new q,ctx:{common:e.parent.common,data:e.data,parsedType:A(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(Y(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 a=this.safeParse(e,t);if(a.success)return a.data;throw a.error}safeParse(e,t){var a;const s={common:{issues:[],async:null!==(a=null==t?void 0:t.async)&&void 0!==a&&a,contextualErrorMap:null==t?void 0:t.errorMap},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:A(e)},n=this._parseSync({data:e,path:s.path,parent:s});return ee(s,n)}"~validate"(e){var t,a;const s={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:A(e)};if(!this["~standard"].async)try{const t=this._parseSync({data:e,path:[],parent:s});return H(t)?{value:t.value}:{issues:s.common.issues}}catch(e){(null===(a=null===(t=null==e?void 0:e.message)||void 0===t?void 0:t.toLowerCase())||void 0===a?void 0:a.includes("encountered"))&&(this["~standard"].async=!0),s.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:s}).then((e=>H(e)?{value:e.value}:{issues:s.common.issues}))}async parseAsync(e,t){const a=await this.safeParseAsync(e,t);if(a.success)return a.data;throw a.error}async safeParseAsync(e,t){const a={common:{issues:[],contextualErrorMap:null==t?void 0:t.errorMap,async:!0},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:A(e)},s=this._parse({data:e,path:a.path,parent:a}),n=await(Y(s)?s:Promise.resolve(s));return ee(a,n)}refine(e,t){const a=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement(((t,s)=>{const n=e(t),r=()=>s.addIssue({code:E.custom,...a(t)});return"undefined"!=typeof Promise&&n instanceof Promise?n.then((e=>!!e||(r(),!1))):!!n||(r(),!1)}))}refinement(e,t){return this._refinement(((a,s)=>!!e(a)||(s.addIssue("function"==typeof t?t(a,s):t),!1)))}_refinement(e){return new at({schema:this,typeName:mt.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}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.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return st.create(this,this._def)}nullable(){return nt.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Me.create(this)}promise(){return tt.create(this,this._def)}or(e){return Le.create([this,e],this._def)}and(e){return Ve.create(this,e,this._def)}transform(e){return new at({...te(this._def),schema:this,typeName:mt.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new rt({...te(this._def),innerType:this,defaultValue:t,typeName:mt.ZodDefault})}brand(){return new ct({typeName:mt.ZodBranded,type:this,...te(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new it({...te(this._def),innerType:this,catchValue:t,typeName:mt.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return ut.create(this,e)}readonly(){return lt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},ne=/^c[^\s-]{8,}$/i,re=/^[0-9a-z]+$/,ie=/^[0-9A-HJKMNP-TV-Z]{26}$/i,oe=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,de=/^[a-z0-9_-]{21}$/i,ce=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ue=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,le=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,he=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,pe=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,me=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,fe=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,ye=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ve=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ge="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",_e=new RegExp(`^${ge}$`);function xe(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function be(e){let t=`${ge}T${xe(e)}`;const a=[];return a.push(e.local?"Z?":"Z"),e.offset&&a.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${a.join("|")})`,new RegExp(`^${t}$`)}function ke(e,t){if(!ce.test(e))return!1;try{const[a]=e.split("."),s=a.replace(/-/g,"+").replace(/_/g,"/").padEnd(a.length+(4-a.length%4)%4,"="),n=JSON.parse(atob(s));return"object"==typeof n&&null!==n&&(!(!n.typ||!n.alg)&&(!t||n.alg===t))}catch(e){return!1}}function we(e,t){return!("v4"!==t&&t||!pe.test(e))||!("v6"!==t&&t||!fe.test(e))}var Ze=class e extends se{_parse(e){this._def.coerce&&(e.data=String(e.data));if(this._getType(e)!==I.string){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.string,received:t.parsedType}),V}const t=new q;let a;for(const r of this._def.checks)if("min"===r.kind)e.data.length<r.value&&(a=this._getOrReturnCtx(e,a),F(a,{code:E.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("max"===r.kind)e.data.length>r.value&&(a=this._getOrReturnCtx(e,a),F(a,{code:E.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!1,message:r.message}),t.dirty());else if("length"===r.kind){const s=e.data.length>r.value,n=e.data.length<r.value;(s||n)&&(a=this._getOrReturnCtx(e,a),s?F(a,{code:E.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}):n&&F(a,{code:E.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}),t.dirty())}else if("email"===r.kind)le.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"email",code:E.invalid_string,message:r.message}),t.dirty());else if("emoji"===r.kind)ae||(ae=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),ae.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"emoji",code:E.invalid_string,message:r.message}),t.dirty());else if("uuid"===r.kind)oe.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"uuid",code:E.invalid_string,message:r.message}),t.dirty());else if("nanoid"===r.kind)de.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"nanoid",code:E.invalid_string,message:r.message}),t.dirty());else if("cuid"===r.kind)ne.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"cuid",code:E.invalid_string,message:r.message}),t.dirty());else if("cuid2"===r.kind)re.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"cuid2",code:E.invalid_string,message:r.message}),t.dirty());else if("ulid"===r.kind)ie.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"ulid",code:E.invalid_string,message:r.message}),t.dirty());else if("url"===r.kind)try{new URL(e.data)}catch(s){a=this._getOrReturnCtx(e,a),F(a,{validation:"url",code:E.invalid_string,message:r.message}),t.dirty()}else if("regex"===r.kind){r.regex.lastIndex=0;r.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"regex",code:E.invalid_string,message:r.message}),t.dirty())}else if("trim"===r.kind)e.data=e.data.trim();else if("includes"===r.kind)e.data.includes(r.value,r.position)||(a=this._getOrReturnCtx(e,a),F(a,{code:E.invalid_string,validation:{includes:r.value,position:r.position},message:r.message}),t.dirty());else if("toLowerCase"===r.kind)e.data=e.data.toLowerCase();else if("toUpperCase"===r.kind)e.data=e.data.toUpperCase();else if("startsWith"===r.kind)e.data.startsWith(r.value)||(a=this._getOrReturnCtx(e,a),F(a,{code:E.invalid_string,validation:{startsWith:r.value},message:r.message}),t.dirty());else if("endsWith"===r.kind)e.data.endsWith(r.value)||(a=this._getOrReturnCtx(e,a),F(a,{code:E.invalid_string,validation:{endsWith:r.value},message:r.message}),t.dirty());else if("datetime"===r.kind){be(r).test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{code:E.invalid_string,validation:"datetime",message:r.message}),t.dirty())}else if("date"===r.kind){_e.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{code:E.invalid_string,validation:"date",message:r.message}),t.dirty())}else if("time"===r.kind){new RegExp(`^${xe(r)}$`).test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{code:E.invalid_string,validation:"time",message:r.message}),t.dirty())}else"duration"===r.kind?ue.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"duration",code:E.invalid_string,message:r.message}),t.dirty()):"ip"===r.kind?(s=e.data,("v4"!==(n=r.version)&&n||!he.test(s))&&("v6"!==n&&n||!me.test(s))&&(a=this._getOrReturnCtx(e,a),F(a,{validation:"ip",code:E.invalid_string,message:r.message}),t.dirty())):"jwt"===r.kind?ke(e.data,r.alg)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"jwt",code:E.invalid_string,message:r.message}),t.dirty()):"cidr"===r.kind?we(e.data,r.version)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"cidr",code:E.invalid_string,message:r.message}),t.dirty()):"base64"===r.kind?ye.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"base64",code:E.invalid_string,message:r.message}),t.dirty()):"base64url"===r.kind?ve.test(e.data)||(a=this._getOrReturnCtx(e,a),F(a,{validation:"base64url",code:E.invalid_string,message:r.message}),t.dirty()):x.assertNever(r);var s,n;return{status:t.value,value:e.data}}_regex(e,t,a){return this.refinement((t=>e.test(t)),{validation:t,code:E.invalid_string,...D.errToObj(a)})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}email(e){return this._addCheck({kind:"email",...D.errToObj(e)})}url(e){return this._addCheck({kind:"url",...D.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...D.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...D.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...D.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...D.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...D.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...D.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...D.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...D.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...D.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...D.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...D.errToObj(e)})}datetime(e){var t,a;return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,offset:null!==(t=null==e?void 0:e.offset)&&void 0!==t&&t,local:null!==(a=null==e?void 0:e.local)&&void 0!==a&&a,...D.errToObj(null==e?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,...D.errToObj(null==e?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...D.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...D.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:null==t?void 0:t.position,...D.errToObj(null==t?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...D.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...D.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...D.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...D.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...D.errToObj(t)})}nonempty(e){return this.min(1,D.errToObj(e))}trim(){return new e({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find((e=>"datetime"===e.kind))}get isDate(){return!!this._def.checks.find((e=>"date"===e.kind))}get isTime(){return!!this._def.checks.find((e=>"time"===e.kind))}get isDuration(){return!!this._def.checks.find((e=>"duration"===e.kind))}get isEmail(){return!!this._def.checks.find((e=>"email"===e.kind))}get isURL(){return!!this._def.checks.find((e=>"url"===e.kind))}get isEmoji(){return!!this._def.checks.find((e=>"emoji"===e.kind))}get isUUID(){return!!this._def.checks.find((e=>"uuid"===e.kind))}get isNANOID(){return!!this._def.checks.find((e=>"nanoid"===e.kind))}get isCUID(){return!!this._def.checks.find((e=>"cuid"===e.kind))}get isCUID2(){return!!this._def.checks.find((e=>"cuid2"===e.kind))}get isULID(){return!!this._def.checks.find((e=>"ulid"===e.kind))}get isIP(){return!!this._def.checks.find((e=>"ip"===e.kind))}get isCIDR(){return!!this._def.checks.find((e=>"cidr"===e.kind))}get isBase64(){return!!this._def.checks.find((e=>"base64"===e.kind))}get isBase64url(){return!!this._def.checks.find((e=>"base64url"===e.kind))}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}};function Te(e,t){const a=(e.toString().split(".")[1]||"").length,s=(t.toString().split(".")[1]||"").length,n=a>s?a:s;return parseInt(e.toFixed(n).replace(".",""))%parseInt(t.toFixed(n).replace(".",""))/Math.pow(10,n)}Ze.create=e=>{var t;return new Ze({checks:[],typeName:mt.ZodString,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...te(e)})};var Ce=class e extends se{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){this._def.coerce&&(e.data=Number(e.data));if(this._getType(e)!==I.number){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.number,received:t.parsedType}),V}let t;const a=new q;for(const s of this._def.checks)if("int"===s.kind)x.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),F(t,{code:E.invalid_type,expected:"integer",received:"float",message:s.message}),a.dirty());else if("min"===s.kind){(s.inclusive?e.data<s.value:e.data<=s.value)&&(t=this._getOrReturnCtx(e,t),F(t,{code:E.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty())}else if("max"===s.kind){(s.inclusive?e.data>s.value:e.data>=s.value)&&(t=this._getOrReturnCtx(e,t),F(t,{code:E.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty())}else"multipleOf"===s.kind?0!==Te(e.data,s.value)&&(t=this._getOrReturnCtx(e,t),F(t,{code:E.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):"finite"===s.kind?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),F(t,{code:E.not_finite,message:s.message}),a.dirty()):x.assertNever(s);return{status:a.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,D.toString(t))}gt(e,t){return this.setLimit("min",e,!1,D.toString(t))}lte(e,t){return this.setLimit("max",e,!0,D.toString(t))}lt(e,t){return this.setLimit("max",e,!1,D.toString(t))}setLimit(t,a,s,n){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:a,inclusive:s,message:D.toString(n)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}int(e){return this._addCheck({kind:"int",message:D.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:D.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:D.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:D.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:D.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:D.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:D.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:D.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:D.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find((e=>"int"===e.kind||"multipleOf"===e.kind&&x.isInteger(e.value)))}get isFinite(){let e=null,t=null;for(const a of this._def.checks){if("finite"===a.kind||"int"===a.kind||"multipleOf"===a.kind)return!0;"min"===a.kind?(null===t||a.value>t)&&(t=a.value):"max"===a.kind&&(null===e||a.value<e)&&(e=a.value)}return Number.isFinite(t)&&Number.isFinite(e)}};Ce.create=e=>new Ce({checks:[],typeName:mt.ZodNumber,coerce:(null==e?void 0:e.coerce)||!1,...te(e)});var Ne=class e extends se{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch(t){return this._getInvalidInput(e)}if(this._getType(e)!==I.bigint)return this._getInvalidInput(e);let t;const a=new q;for(const s of this._def.checks)if("min"===s.kind){(s.inclusive?e.data<s.value:e.data<=s.value)&&(t=this._getOrReturnCtx(e,t),F(t,{code:E.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty())}else if("max"===s.kind){(s.inclusive?e.data>s.value:e.data>=s.value)&&(t=this._getOrReturnCtx(e,t),F(t,{code:E.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty())}else"multipleOf"===s.kind?e.data%s.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),F(t,{code:E.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):x.assertNever(s);return{status:a.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.bigint,received:t.parsedType}),V}gte(e,t){return this.setLimit("min",e,!0,D.toString(t))}gt(e,t){return this.setLimit("min",e,!1,D.toString(t))}lte(e,t){return this.setLimit("max",e,!0,D.toString(t))}lt(e,t){return this.setLimit("max",e,!1,D.toString(t))}setLimit(t,a,s,n){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:a,inclusive:s,message:D.toString(n)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:D.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:D.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:D.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:D.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:D.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}};Ne.create=e=>{var t;return new Ne({checks:[],typeName:mt.ZodBigInt,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...te(e)})};var Oe=class extends se{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==I.boolean){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.boolean,received:t.parsedType}),V}return B(e.data)}};Oe.create=e=>new Oe({typeName:mt.ZodBoolean,coerce:(null==e?void 0:e.coerce)||!1,...te(e)});var Se=class e extends se{_parse(e){this._def.coerce&&(e.data=new Date(e.data));if(this._getType(e)!==I.date){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.date,received:t.parsedType}),V}if(isNaN(e.data.getTime())){return F(this._getOrReturnCtx(e),{code:E.invalid_date}),V}const t=new q;let a;for(const s of this._def.checks)"min"===s.kind?e.data.getTime()<s.value&&(a=this._getOrReturnCtx(e,a),F(a,{code:E.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),t.dirty()):"max"===s.kind?e.data.getTime()>s.value&&(a=this._getOrReturnCtx(e,a),F(a,{code:E.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),t.dirty()):x.assertNever(s);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:D.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:D.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}};Se.create=e=>new Se({checks:[],coerce:(null==e?void 0:e.coerce)||!1,typeName:mt.ZodDate,...te(e)});var Ie=class extends se{_parse(e){if(this._getType(e)!==I.symbol){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.symbol,received:t.parsedType}),V}return B(e.data)}};Ie.create=e=>new Ie({typeName:mt.ZodSymbol,...te(e)});var Ae=class extends se{_parse(e){if(this._getType(e)!==I.undefined){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.undefined,received:t.parsedType}),V}return B(e.data)}};Ae.create=e=>new Ae({typeName:mt.ZodUndefined,...te(e)});var Ee=class extends se{_parse(e){if(this._getType(e)!==I.null){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.null,received:t.parsedType}),V}return B(e.data)}};Ee.create=e=>new Ee({typeName:mt.ZodNull,...te(e)});var je=class extends se{constructor(){super(...arguments),this._any=!0}_parse(e){return B(e.data)}};je.create=e=>new je({typeName:mt.ZodAny,...te(e)});var Pe=class extends se{constructor(){super(...arguments),this._unknown=!0}_parse(e){return B(e.data)}};Pe.create=e=>new Pe({typeName:mt.ZodUnknown,...te(e)});var Re=class extends se{_parse(e){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.never,received:t.parsedType}),V}};Re.create=e=>new Re({typeName:mt.ZodNever,...te(e)});var $e=class extends se{_parse(e){if(this._getType(e)!==I.undefined){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.void,received:t.parsedType}),V}return B(e.data)}};$e.create=e=>new $e({typeName:mt.ZodVoid,...te(e)});var Me=class e extends se{_parse(e){const{ctx:t,status:a}=this._processInputParams(e),s=this._def;if(t.parsedType!==I.array)return F(t,{code:E.invalid_type,expected:I.array,received:t.parsedType}),V;if(null!==s.exactLength){const e=t.data.length>s.exactLength.value,n=t.data.length<s.exactLength.value;(e||n)&&(F(t,{code:e?E.too_big:E.too_small,minimum:n?s.exactLength.value:void 0,maximum:e?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),a.dirty())}if(null!==s.minLength&&t.data.length<s.minLength.value&&(F(t,{code:E.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),a.dirty()),null!==s.maxLength&&t.data.length>s.maxLength.value&&(F(t,{code:E.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),a.dirty()),t.common.async)return Promise.all([...t.data].map(((e,a)=>s.type._parseAsync(new X(t,e,t.path,a))))).then((e=>q.mergeArray(a,e)));const n=[...t.data].map(((e,a)=>s.type._parseSync(new X(t,e,t.path,a))));return q.mergeArray(a,n)}get element(){return this._def.type}min(t,a){return new e({...this._def,minLength:{value:t,message:D.toString(a)}})}max(t,a){return new e({...this._def,maxLength:{value:t,message:D.toString(a)}})}length(t,a){return new e({...this._def,exactLength:{value:t,message:D.toString(a)}})}nonempty(e){return this.min(1,e)}};function Fe(e){if(e instanceof De){const t={};for(const a in e.shape){const s=e.shape[a];t[a]=st.create(Fe(s))}return new De({...e._def,shape:()=>t})}return e instanceof Me?new Me({...e._def,type:Fe(e.element)}):e instanceof st?st.create(Fe(e.unwrap())):e instanceof nt?nt.create(Fe(e.unwrap())):e instanceof Ke?Ke.create(e.items.map((e=>Fe(e)))):e}Me.create=(e,t)=>new Me({type:e,minLength:null,maxLength:null,exactLength:null,typeName:mt.ZodArray,...te(t)});var De=class e extends se{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const e=this._def.shape(),t=x.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==I.object){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.object,received:t.parsedType}),V}const{status:t,ctx:a}=this._processInputParams(e),{shape:s,keys:n}=this._getCached(),r=[];if(!(this._def.catchall instanceof Re&&"strip"===this._def.unknownKeys))for(const e in a.data)n.includes(e)||r.push(e);const i=[];for(const e of n){const t=s[e],n=a.data[e];i.push({key:{status:"valid",value:e},value:t._parse(new X(a,n,a.path,e)),alwaysSet:e in a.data})}if(this._def.catchall instanceof Re){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of r)i.push({key:{status:"valid",value:e},value:{status:"valid",value:a.data[e]}});else if("strict"===e)r.length>0&&(F(a,{code:E.unrecognized_keys,keys:r}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of r){const s=a.data[t];i.push({key:{status:"valid",value:t},value:e._parse(new X(a,s,a.path,t)),alwaysSet:t in a.data})}}return a.common.async?Promise.resolve().then((async()=>{const e=[];for(const t of i){const a=await t.key,s=await t.value;e.push({key:a,value:s,alwaysSet:t.alwaysSet})}return e})).then((e=>q.mergeObjectSync(t,e))):q.mergeObjectSync(t,i)}get shape(){return this._def.shape()}strict(t){return D.errToObj,new e({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(e,a)=>{var s,n,r,i;const o=null!==(r=null===(n=(s=this._def).errorMap)||void 0===n?void 0:n.call(s,e,a).message)&&void 0!==r?r:a.defaultError;return"unrecognized_keys"===e.code?{message:null!==(i=D.errToObj(t).message)&&void 0!==i?i:o}:{message:o}}}:{}})}strip(){return new e({...this._def,unknownKeys:"strip"})}passthrough(){return new e({...this._def,unknownKeys:"passthrough"})}extend(t){return new e({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new e({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:mt.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(t){return new e({...this._def,catchall:t})}pick(t){const a={};return x.objectKeys(t).forEach((e=>{t[e]&&this.shape[e]&&(a[e]=this.shape[e])})),new e({...this._def,shape:()=>a})}omit(t){const a={};return x.objectKeys(this.shape).forEach((e=>{t[e]||(a[e]=this.shape[e])})),new e({...this._def,shape:()=>a})}deepPartial(){return Fe(this)}partial(t){const a={};return x.objectKeys(this.shape).forEach((e=>{const s=this.shape[e];t&&!t[e]?a[e]=s:a[e]=s.optional()})),new e({...this._def,shape:()=>a})}required(t){const a={};return x.objectKeys(this.shape).forEach((e=>{if(t&&!t[e])a[e]=this.shape[e];else{let t=this.shape[e];for(;t instanceof st;)t=t._def.innerType;a[e]=t}})),new e({...this._def,shape:()=>a})}keyof(){return Qe(x.objectKeys(this.shape))}};De.create=(e,t)=>new De({shape:()=>e,unknownKeys:"strip",catchall:Re.create(),typeName:mt.ZodObject,...te(t)}),De.strictCreate=(e,t)=>new De({shape:()=>e,unknownKeys:"strict",catchall:Re.create(),typeName:mt.ZodObject,...te(t)}),De.lazycreate=(e,t)=>new De({shape:e,unknownKeys:"strip",catchall:Re.create(),typeName:mt.ZodObject,...te(t)});var Le=class extends se{_parse(e){const{ctx:t}=this._processInputParams(e),a=this._def.options;if(t.common.async)return Promise.all(a.map((async e=>{const a={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:a}),ctx:a}}))).then((function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const a of e)if("dirty"===a.result.status)return t.common.issues.push(...a.ctx.common.issues),a.result;const a=e.map((e=>new j(e.ctx.common.issues)));return F(t,{code:E.invalid_union,unionErrors:a}),V}));{let e;const s=[];for(const n of a){const a={...t,common:{...t.common,issues:[]},parent:null},r=n._parseSync({data:t.data,path:t.path,parent:a});if("valid"===r.status)return r;"dirty"!==r.status||e||(e={result:r,ctx:a}),a.common.issues.length&&s.push(a.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const n=s.map((e=>new j(e)));return F(t,{code:E.invalid_union,unionErrors:n}),V}}get options(){return this._def.options}};Le.create=(e,t)=>new Le({options:e,typeName:mt.ZodUnion,...te(t)});var ze=e=>e instanceof Ye?ze(e.schema):e instanceof at?ze(e.innerType()):e instanceof Ge?[e.value]:e instanceof Xe?e.options:e instanceof et?x.objectValues(e.enum):e instanceof rt?ze(e._def.innerType):e instanceof Ae?[void 0]:e instanceof Ee?[null]:e instanceof st?[void 0,...ze(e.unwrap())]:e instanceof nt?[null,...ze(e.unwrap())]:e instanceof ct||e instanceof lt?ze(e.unwrap()):e instanceof it?ze(e._def.innerType):[],Ue=class e extends se{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.object)return F(t,{code:E.invalid_type,expected:I.object,received:t.parsedType}),V;const a=this.discriminator,s=t.data[a],n=this.optionsMap.get(s);return n?t.common.async?n._parseAsync({data:t.data,path:t.path,parent:t}):n._parseSync({data:t.data,path:t.path,parent:t}):(F(t,{code:E.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),V)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,a,s){const n=new Map;for(const e of a){const a=ze(e.shape[t]);if(!a.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const s of a){if(n.has(s))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(s)}`);n.set(s,e)}}return new e({typeName:mt.ZodDiscriminatedUnion,discriminator:t,options:a,optionsMap:n,...te(s)})}};function qe(e,t){const a=A(e),s=A(t);if(e===t)return{valid:!0,data:e};if(a===I.object&&s===I.object){const a=x.objectKeys(t),s=x.objectKeys(e).filter((e=>-1!==a.indexOf(e))),n={...e,...t};for(const a of s){const s=qe(e[a],t[a]);if(!s.valid)return{valid:!1};n[a]=s.data}return{valid:!0,data:n}}if(a===I.array&&s===I.array){if(e.length!==t.length)return{valid:!1};const a=[];for(let s=0;s<e.length;s++){const n=qe(e[s],t[s]);if(!n.valid)return{valid:!1};a.push(n.data)}return{valid:!0,data:a}}return a===I.date&&s===I.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}var Ve=class extends se{_parse(e){const{status:t,ctx:a}=this._processInputParams(e),s=(e,s)=>{if(J(e)||J(s))return V;const n=qe(e.value,s.value);return n.valid?((W(e)||W(s))&&t.dirty(),{status:t.value,value:n.data}):(F(a,{code:E.invalid_intersection_types}),V)};return a.common.async?Promise.all([this._def.left._parseAsync({data:a.data,path:a.path,parent:a}),this._def.right._parseAsync({data:a.data,path:a.path,parent:a})]).then((([e,t])=>s(e,t))):s(this._def.left._parseSync({data:a.data,path:a.path,parent:a}),this._def.right._parseSync({data:a.data,path:a.path,parent:a}))}};Ve.create=(e,t,a)=>new Ve({left:e,right:t,typeName:mt.ZodIntersection,...te(a)});var Ke=class e extends se{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==I.array)return F(a,{code:E.invalid_type,expected:I.array,received:a.parsedType}),V;if(a.data.length<this._def.items.length)return F(a,{code:E.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),V;!this._def.rest&&a.data.length>this._def.items.length&&(F(a,{code:E.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const s=[...a.data].map(((e,t)=>{const s=this._def.items[t]||this._def.rest;return s?s._parse(new X(a,e,a.path,t)):null})).filter((e=>!!e));return a.common.async?Promise.all(s).then((e=>q.mergeArray(t,e))):q.mergeArray(t,s)}get items(){return this._def.items}rest(t){return new e({...this._def,rest:t})}};Ke.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Ke({items:e,typeName:mt.ZodTuple,rest:null,...te(t)})};var Be=class e extends se{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==I.object)return F(a,{code:E.invalid_type,expected:I.object,received:a.parsedType}),V;const s=[],n=this._def.keyType,r=this._def.valueType;for(const e in a.data)s.push({key:n._parse(new X(a,e,a.path,e)),value:r._parse(new X(a,a.data[e],a.path,e)),alwaysSet:e in a.data});return a.common.async?q.mergeObjectAsync(t,s):q.mergeObjectSync(t,s)}get element(){return this._def.valueType}static create(t,a,s){return new e(a instanceof se?{keyType:t,valueType:a,typeName:mt.ZodRecord,...te(s)}:{keyType:Ze.create(),valueType:t,typeName:mt.ZodRecord,...te(a)})}},Je=class extends se{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==I.map)return F(a,{code:E.invalid_type,expected:I.map,received:a.parsedType}),V;const s=this._def.keyType,n=this._def.valueType,r=[...a.data.entries()].map((([e,t],r)=>({key:s._parse(new X(a,e,a.path,[r,"key"])),value:n._parse(new X(a,t,a.path,[r,"value"]))})));if(a.common.async){const e=new Map;return Promise.resolve().then((async()=>{for(const a of r){const s=await a.key,n=await a.value;if("aborted"===s.status||"aborted"===n.status)return V;"dirty"!==s.status&&"dirty"!==n.status||t.dirty(),e.set(s.value,n.value)}return{status:t.value,value:e}}))}{const e=new Map;for(const a of r){const s=a.key,n=a.value;if("aborted"===s.status||"aborted"===n.status)return V;"dirty"!==s.status&&"dirty"!==n.status||t.dirty(),e.set(s.value,n.value)}return{status:t.value,value:e}}}};Je.create=(e,t,a)=>new Je({valueType:t,keyType:e,typeName:mt.ZodMap,...te(a)});var We=class e extends se{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==I.set)return F(a,{code:E.invalid_type,expected:I.set,received:a.parsedType}),V;const s=this._def;null!==s.minSize&&a.data.size<s.minSize.value&&(F(a,{code:E.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),t.dirty()),null!==s.maxSize&&a.data.size>s.maxSize.value&&(F(a,{code:E.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),t.dirty());const n=this._def.valueType;function r(e){const a=new Set;for(const s of e){if("aborted"===s.status)return V;"dirty"===s.status&&t.dirty(),a.add(s.value)}return{status:t.value,value:a}}const i=[...a.data.values()].map(((e,t)=>n._parse(new X(a,e,a.path,t))));return a.common.async?Promise.all(i).then((e=>r(e))):r(i)}min(t,a){return new e({...this._def,minSize:{value:t,message:D.toString(a)}})}max(t,a){return new e({...this._def,maxSize:{value:t,message:D.toString(a)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}};We.create=(e,t)=>new We({valueType:e,minSize:null,maxSize:null,typeName:mt.ZodSet,...te(t)});var He=class e extends se{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.function)return F(t,{code:E.invalid_type,expected:I.function,received:t.parsedType}),V;function a(e,a){return M({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,$(),P].filter((e=>!!e)),issueData:{code:E.invalid_arguments,argumentsError:a}})}function s(e,a){return M({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,$(),P].filter((e=>!!e)),issueData:{code:E.invalid_return_type,returnTypeError:a}})}const n={errorMap:t.common.contextualErrorMap},r=t.data;if(this._def.returns instanceof tt){const e=this;return B((async function(...t){const i=new j([]),o=await e._def.args.parseAsync(t,n).catch((e=>{throw i.addIssue(a(t,e)),i})),d=await Reflect.apply(r,this,o);return await e._def.returns._def.type.parseAsync(d,n).catch((e=>{throw i.addIssue(s(d,e)),i}))}))}{const e=this;return B((function(...t){const i=e._def.args.safeParse(t,n);if(!i.success)throw new j([a(t,i.error)]);const o=Reflect.apply(r,this,i.data),d=e._def.returns.safeParse(o,n);if(!d.success)throw new j([s(o,d.error)]);return d.data}))}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new e({...this._def,args:Ke.create(t).rest(Pe.create())})}returns(t){return new e({...this._def,returns:t})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(t,a,s){return new e({args:t||Ke.create([]).rest(Pe.create()),returns:a||Pe.create(),typeName:mt.ZodFunction,...te(s)})}},Ye=class extends se{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})}};Ye.create=(e,t)=>new Ye({getter:e,typeName:mt.ZodLazy,...te(t)});var Ge=class extends se{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return F(t,{received:t.data,code:E.invalid_literal,expected:this._def.value}),V}return{status:"valid",value:e.data}}get value(){return this._def.value}};function Qe(e,t){return new Xe({values:e,typeName:mt.ZodEnum,...te(t)})}Ge.create=(e,t)=>new Ge({value:e,typeName:mt.ZodLiteral,...te(t)});var Xe=class e extends se{constructor(){super(...arguments),z.set(this,void 0)}_parse(e){if("string"!=typeof e.data){const t=this._getOrReturnCtx(e),a=this._def.values;return F(t,{expected:x.joinValues(a),received:t.parsedType,code:E.invalid_type}),V}if(G(this,z)||Q(this,z,new Set(this._def.values)),!G(this,z).has(e.data)){const t=this._getOrReturnCtx(e),a=this._def.values;return F(t,{received:t.data,code:E.invalid_enum_value,options:a}),V}return B(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(t,a=this._def){return e.create(t,{...this._def,...a})}exclude(t,a=this._def){return e.create(this.options.filter((e=>!t.includes(e))),{...this._def,...a})}};z=new WeakMap,Xe.create=Qe;var et=class extends se{constructor(){super(...arguments),U.set(this,void 0)}_parse(e){const t=x.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(e);if(a.parsedType!==I.string&&a.parsedType!==I.number){const e=x.objectValues(t);return F(a,{expected:x.joinValues(e),received:a.parsedType,code:E.invalid_type}),V}if(G(this,U)||Q(this,U,new Set(x.getValidEnumValues(this._def.values))),!G(this,U).has(e.data)){const e=x.objectValues(t);return F(a,{received:a.data,code:E.invalid_enum_value,options:e}),V}return B(e.data)}get enum(){return this._def.values}};U=new WeakMap,et.create=(e,t)=>new et({values:e,typeName:mt.ZodNativeEnum,...te(t)});var tt=class extends se{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==I.promise&&!1===t.common.async)return F(t,{code:E.invalid_type,expected:I.promise,received:t.parsedType}),V;const a=t.parsedType===I.promise?t.data:Promise.resolve(t.data);return B(a.then((e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap}))))}};tt.create=(e,t)=>new tt({type:e,typeName:mt.ZodPromise,...te(t)});var at=class extends se{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===mt.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:a}=this._processInputParams(e),s=this._def.effect||null,n={addIssue:e=>{F(a,e),e.fatal?t.abort():t.dirty()},get path(){return a.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===s.type){const e=s.transform(a.data,n);if(a.common.async)return Promise.resolve(e).then((async e=>{if("aborted"===t.value)return V;const s=await this._def.schema._parseAsync({data:e,path:a.path,parent:a});return"aborted"===s.status?V:"dirty"===s.status||"dirty"===t.value?K(s.value):s}));{if("aborted"===t.value)return V;const s=this._def.schema._parseSync({data:e,path:a.path,parent:a});return"aborted"===s.status?V:"dirty"===s.status||"dirty"===t.value?K(s.value):s}}if("refinement"===s.type){const e=e=>{const t=s.refinement(e,n);if(a.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===a.common.async){const s=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===s.status?V:("dirty"===s.status&&t.dirty(),e(s.value),{status:t.value,value:s.value})}return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then((a=>"aborted"===a.status?V:("dirty"===a.status&&t.dirty(),e(a.value).then((()=>({status:t.value,value:a.value}))))))}if("transform"===s.type){if(!1===a.common.async){const e=this._def.schema._parseSync({data:a.data,path:a.path,parent:a});if(!H(e))return e;const r=s.transform(e.value,n);if(r instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:r}}return this._def.schema._parseAsync({data:a.data,path:a.path,parent:a}).then((e=>H(e)?Promise.resolve(s.transform(e.value,n)).then((e=>({status:t.value,value:e}))):e))}x.assertNever(s)}};at.create=(e,t,a)=>new at({schema:e,typeName:mt.ZodEffects,effect:t,...te(a)}),at.createWithPreprocess=(e,t,a)=>new at({schema:t,effect:{type:"preprocess",transform:e},typeName:mt.ZodEffects,...te(a)});var st=class extends se{_parse(e){return this._getType(e)===I.undefined?B(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};st.create=(e,t)=>new st({innerType:e,typeName:mt.ZodOptional,...te(t)});var nt=class extends se{_parse(e){return this._getType(e)===I.null?B(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};nt.create=(e,t)=>new nt({innerType:e,typeName:mt.ZodNullable,...te(t)});var rt=class extends se{_parse(e){const{ctx:t}=this._processInputParams(e);let a=t.data;return t.parsedType===I.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:t.path,parent:t})}removeDefault(){return this._def.innerType}};rt.create=(e,t)=>new rt({innerType:e,typeName:mt.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...te(t)});var it=class extends se{_parse(e){const{ctx:t}=this._processInputParams(e),a={...t,common:{...t.common,issues:[]}},s=this._def.innerType._parse({data:a.data,path:a.path,parent:{...a}});return Y(s)?s.then((e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new j(a.common.issues)},input:a.data})}))):{status:"valid",value:"valid"===s.status?s.value:this._def.catchValue({get error(){return new j(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}};it.create=(e,t)=>new it({innerType:e,typeName:mt.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...te(t)});var ot=class extends se{_parse(e){if(this._getType(e)!==I.nan){const t=this._getOrReturnCtx(e);return F(t,{code:E.invalid_type,expected:I.nan,received:t.parsedType}),V}return{status:"valid",value:e.data}}};ot.create=e=>new ot({typeName:mt.ZodNaN,...te(e)});var dt=Symbol("zod_brand"),ct=class extends se{_parse(e){const{ctx:t}=this._processInputParams(e),a=t.data;return this._def.type._parse({data:a,path:t.path,parent:t})}unwrap(){return this._def.type}},ut=class e extends se{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.common.async){return(async()=>{const e=await this._def.in._parseAsync({data:a.data,path:a.path,parent:a});return"aborted"===e.status?V:"dirty"===e.status?(t.dirty(),K(e.value)):this._def.out._parseAsync({data:e.value,path:a.path,parent:a})})()}{const e=this._def.in._parseSync({data:a.data,path:a.path,parent:a});return"aborted"===e.status?V:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:a.path,parent:a})}}static create(t,a){return new e({in:t,out:a,typeName:mt.ZodPipeline})}},lt=class extends se{_parse(e){const t=this._def.innerType._parse(e),a=e=>(H(e)&&(e.value=Object.freeze(e.value)),e);return Y(t)?t.then((e=>a(e))):a(t)}unwrap(){return this._def.innerType}};function ht(e,t){const a="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof a?{message:a}:a}function pt(e,t={},a){return e?je.create().superRefine(((s,n)=>{var r,i;const o=e(s);if(o instanceof Promise)return o.then((e=>{var r,i;if(!e){const e=ht(t,s),o=null===(i=null!==(r=e.fatal)&&void 0!==r?r:a)||void 0===i||i;n.addIssue({code:"custom",...e,fatal:o})}}));if(!o){const e=ht(t,s),o=null===(i=null!==(r=e.fatal)&&void 0!==r?r:a)||void 0===i||i;n.addIssue({code:"custom",...e,fatal:o})}})):je.create()}lt.create=(e,t)=>new lt({innerType:e,typeName:mt.ZodReadonly,...te(t)});var mt,ft,yt={object:De.lazycreate};(ft=mt||(mt={})).ZodString="ZodString",ft.ZodNumber="ZodNumber",ft.ZodNaN="ZodNaN",ft.ZodBigInt="ZodBigInt",ft.ZodBoolean="ZodBoolean",ft.ZodDate="ZodDate",ft.ZodSymbol="ZodSymbol",ft.ZodUndefined="ZodUndefined",ft.ZodNull="ZodNull",ft.ZodAny="ZodAny",ft.ZodUnknown="ZodUnknown",ft.ZodNever="ZodNever",ft.ZodVoid="ZodVoid",ft.ZodArray="ZodArray",ft.ZodObject="ZodObject",ft.ZodUnion="ZodUnion",ft.ZodDiscriminatedUnion="ZodDiscriminatedUnion",ft.ZodIntersection="ZodIntersection",ft.ZodTuple="ZodTuple",ft.ZodRecord="ZodRecord",ft.ZodMap="ZodMap",ft.ZodSet="ZodSet",ft.ZodFunction="ZodFunction",ft.ZodLazy="ZodLazy",ft.ZodLiteral="ZodLiteral",ft.ZodEnum="ZodEnum",ft.ZodEffects="ZodEffects",ft.ZodNativeEnum="ZodNativeEnum",ft.ZodOptional="ZodOptional",ft.ZodNullable="ZodNullable",ft.ZodDefault="ZodDefault",ft.ZodCatch="ZodCatch",ft.ZodPromise="ZodPromise",ft.ZodBranded="ZodBranded",ft.ZodPipeline="ZodPipeline",ft.ZodReadonly="ZodReadonly";var vt=Ze.create,gt=Ce.create,_t=ot.create,xt=Ne.create,bt=Oe.create,kt=Se.create,wt=Ie.create,Zt=Ae.create,Tt=Ee.create,Ct=je.create,Nt=Pe.create,Ot=Re.create,St=$e.create,It=Me.create,At=De.create,Et=De.strictCreate,jt=Le.create,Pt=Ue.create,Rt=Ve.create,$t=Ke.create,Mt=Be.create,Ft=Je.create,Dt=We.create,Lt=He.create,zt=Ye.create,Ut=Ge.create,qt=Xe.create,Vt=et.create,Kt=tt.create,Bt=at.create,Jt=st.create,Wt=nt.create,Ht=at.createWithPreprocess,Yt=ut.create,Gt={string:e=>Ze.create({...e,coerce:!0}),number:e=>Ce.create({...e,coerce:!0}),boolean:e=>Oe.create({...e,coerce:!0}),bigint:e=>Ne.create({...e,coerce:!0}),date:e=>Se.create({...e,coerce:!0})},Qt=V,Xt=Object.freeze({__proto__:null,defaultErrorMap:P,setErrorMap:function(e){R=e},getErrorMap:$,makeIssue:M,EMPTY_PATH:[],addIssueToContext:F,ParseStatus:q,INVALID:V,DIRTY:K,OK:B,isAborted:J,isDirty:W,isValid:H,isAsync:Y,get util(){return x},get objectUtil(){return k},ZodParsedType:I,getParsedType:A,ZodType:se,datetimeRegex:be,ZodString:Ze,ZodNumber:Ce,ZodBigInt:Ne,ZodBoolean:Oe,ZodDate:Se,ZodSymbol:Ie,ZodUndefined:Ae,ZodNull:Ee,ZodAny:je,ZodUnknown:Pe,ZodNever:Re,ZodVoid:$e,ZodArray:Me,ZodObject:De,ZodUnion:Le,ZodDiscriminatedUnion:Ue,ZodIntersection:Ve,ZodTuple:Ke,ZodRecord:Be,ZodMap:Je,ZodSet:We,ZodFunction:He,ZodLazy:Ye,ZodLiteral:Ge,ZodEnum:Xe,ZodNativeEnum:et,ZodPromise:tt,ZodEffects:at,ZodTransformer:at,ZodOptional:st,ZodNullable:nt,ZodDefault:rt,ZodCatch:it,ZodNaN:ot,BRAND:dt,ZodBranded:ct,ZodPipeline:ut,ZodReadonly:lt,custom:pt,Schema:se,ZodSchema:se,late:yt,get ZodFirstPartyTypeKind(){return mt},coerce:Gt,any:Ct,array:It,bigint:xt,boolean:bt,date:kt,discriminatedUnion:Pt,effect:Bt,enum:qt,function:Lt,instanceof:(e,t={message:`Input not instance of ${e.name}`})=>pt((t=>t instanceof e),t),intersection:Rt,lazy:zt,literal:Ut,map:Ft,nan:_t,nativeEnum:Vt,never:Ot,null:Tt,nullable:Wt,number:gt,object:At,oboolean:()=>bt().optional(),onumber:()=>gt().optional(),optional:Jt,ostring:()=>vt().optional(),pipeline:Yt,preprocess:Ht,promise:Kt,record:Mt,set:Dt,strictObject:Et,string:vt,symbol:wt,transformer:Bt,tuple:$t,undefined:Zt,union:jt,unknown:Nt,void:St,NEVER:Qt,ZodIssueCode:E,quotelessJson:e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ZodError:j}),ea=Xt.object({type:Xt.enum(["sqlite","postgresql","mysql"]).default("sqlite"),connection:Xt.object({url:Xt.string().default("./db/zaileys.db")}).optional().default({})}).optional().default({}),ta={prefix:Xt.string().optional(),ignoreMe:Xt.boolean().optional().default(!0),showLogs:Xt.boolean().optional().default(!0),autoMentions:Xt.boolean().optional().default(!0),autoOnline:Xt.boolean().optional().default(!0),autoRead:Xt.boolean().optional().default(!0),autoRejectCall:Xt.boolean().optional().default(!0),database:ea,citation:Xt.record(Xt.function().returns(Xt.union([Xt.number().array(),Xt.promise(Xt.number().array())]))).optional().transform((async e=>{const t={};if(e)for(const a of Object.keys(e)){const s=`is${a.charAt(0).toUpperCase()+a.slice(1)}`,n=await e[a]();t[s]=n}return t}))},aa=Xt.object({authType:Xt.literal("pairing"),phoneNumber:Xt.number(),...ta}),sa=Xt.object({authType:Xt.literal("qr"),phoneNumber:Xt.undefined().optional(),...ta}),na=Xt.discriminatedUnion("authType",[aa,sa]),ra=class{constructor(e){this.client=e}events=new Map;setup(e){e.ev.on("connection.update",(async e=>{const{connection:t,lastDisconnect:a,qr:n}=e;if(this.emit("connection",{status:t||"connecting"}),"qr"==this.client.options?.authType&&n&&console.log("Scan qrcode with your whatsapp: "),"close"===t){const e=a?.error?.output?.statusCode,t=e!==s.loggedOut;if(console.log(a?.error?.message),401==e||405==e||500==e)return;t&&await this.client.initialize()}else"open"===t&&this.emit("connection",{status:"open"})})),e.ev.on("messages.upsert",(({messages:e})=>{this.emit("messages",e)})),e.ev.on("call",(e=>{this.emit("call",e)}))}on(e,t){this.events.has(e)||this.events.set(e,[]),this.events.get(e).push(t)}emit(e,t){(this.events.get(e)||[]).forEach((e=>e(t)))}},ia=class{constructor(e){this.props=e,this.initialize(),this.event=new ra(this)}options;chatId="zaileys-chats";logger=r({level:"silent",enabled:!1});event;db;socket;groupCache=new n({stdTTL:300,useClones:!1});async initialize(){this.options=await na.parseAsync(this.props),this.db=((e,t)=>{if("sqlite"===e){const e=t||"./db/zaileys.db",a=m.resolve(e);return o(m.dirname(a),{recursive:!0}),d(a,"",{flag:"a"}),new c({dialect:new u({database:new i(a)})})}const a=new y(t),s=a.protocol.replace(":","");if("mysql"===e)return new c({dialect:new l({pool:p.createPool({host:a.hostname,user:a.username,password:a.password,database:a.pathname.replace("/",""),port:parseInt(a.port||"3306",10)})})});if("postgresql"===e)return new c({dialect:new h({pool:new f({host:a.hostname,user:a.username,password:a.password,database:a.pathname.replace("/",""),port:parseInt(a.port||"5432",10)})})});throw new Error(`Unsupported database protocol: ${s}`)})(this.options.database.type,this.options.database.connection.url);const{state:s,saveCreds:r,removeCreds:v}=await S(this.db,this.chatId),g=await(async(e,t)=>({bind:a=>{a.on("messaging-history.set",(async a=>{const{chats:s,contacts:n,messages:r}=a;for(const a of s)await e.insertInto("chats").values({session:t,id:a.id,value:JSON.stringify(a)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(a)}))).execute();for(const a of n)await e.insertInto("contacts").values({session:t,id:a.id,value:JSON.stringify(a)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(a)}))).execute();for(const a of r)await e.insertInto("messages").values({session:t,id:a.key.id,value:JSON.stringify(a)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(a)}))).execute()})),a.on("messages.upsert",(async({messages:a})=>{for(const s of a)await e.insertInto("messages").values({session:t,id:s.key.id,value:JSON.stringify(s)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(s)}))).execute()})),a.on("chats.upsert",(async a=>{for(const s of a)await e.insertInto("chats").values({session:t,id:s.id,value:JSON.stringify(s)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(s)}))).execute()})),a.on("contacts.upsert",(async a=>{for(const s of a)await e.insertInto("contacts").values({session:t,id:s.id,value:JSON.stringify(s)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(s)}))).execute()}))}}))(this.db,this.chatId);this.socket=e({logger:this.logger,markOnlineOnConnect:this.options.autoOnline,syncFullHistory:!1,defaultQueryTimeoutMs:void 0,msgRetryCounterCache:new n,cachedGroupMetadata:async e=>this.groupCache.get(e),printQRInTerminal:"qr"==this.options.authType,browser:a.ubuntu("qr"==this.options.authType?"Zaileys Library":"Firefox"),auth:{creds:s.creds,keys:t(s.keys,this.logger)}}),"pairing"==this.options.authType&&this.options.phoneNumber&&!this.socket?.authState.creds.registered&&setTimeout((async()=>{try{if("pairing"==this.options?.authType){const e=await(this.socket?.requestPairingCode(this.options.phoneNumber.toString()));console.log("🚀 ~ Client.ts:53 ~ Client ~ setTimeout ~ code:",e)}}catch{console.log("Connection failed"),process.exit(1)}}),5e3),this.socket?.ev.on("creds.update",r),g.bind(this.socket?.ev),this.event.setup(this.socket)}on(e,t){this.event.on(e,t)}};export{ia as default};
1
+ import e,{makeCacheableSignalKeyStore as t,Browsers as s,jidNormalizedUser as a,DisconnectReason as n,getContentType as i,getDevice as r,downloadMediaMessage as o}from"baileys";import{EventEmitter as d}from"events";import c from"figlet";import u from"node-cache";import l from"ora";import p from"pino";import h from"better-sqlite3";import{mkdirSync as m,writeFileSync as f}from"fs";import{Kysely as g,SqliteDialect as y,MysqlDialect as v,PostgresDialect as _}from"kysely";import b from"mysql2";import w from"path";import{Pool as k}from"pg";import{URL as x}from"url";import{randomBytes as I,randomUUID as C}from"crypto";import{curve as T}from"libsignal";import{Readable as N}from"stream";var S,O,M,Z=T,A=()=>{const{pubKey:e,privKey:t}=Z.generateKeyPair();return{private:Buffer.from(t),public:Buffer.from(e.slice(1))}},E=(e,t)=>{const s=A(),a=(e=>33===e.length?e:Buffer.concat([Buffer.from([5]),e]))(s.public);var n,i;return{keyPair:s,signature:(n=e.private,i=a,Z.calculateSignature(n,i)),keyId:t}},j=e=>{const t={...e.fingerprint,deviceIndexes:Array.isArray(e.fingerprint.deviceIndexes)?e.fingerprint.deviceIndexes:[]},s={keyData:Array.isArray(e.keyData)?e.keyData:new Uint8Array,fingerprint:{rawId:t.rawId||0,currentIndex:t.rawId||0,deviceIndexes:t.deviceIndexes},timestamp:(a=e.timestamp,"string"==typeof a?parseInt(a,10):a)};var a;return"string"==typeof e.keyData&&(s.keyData=(e=>{let t=e.length;if(!t)return new Uint8Array(1);let s=0;for(;--t%4>1&&"="===e.charAt(t);)++s;return new Uint8Array(Math.ceil(3*e.length)/4-s).fill(0)})(e.keyData)),s},P=(e,t)=>"Buffer"===t?.type&&Array.isArray(t?.data)?{type:"Buffer",data:Buffer.from(t?.data).toString("base64")}:t,R=(e,t)=>"Buffer"===t?.type?Buffer.from(t?.data,"base64"):t,$=async(e,t)=>{const s="auth";await(async e=>{await e.schema.createTable("auth").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("auth_session_id_unique",["session","id"]).execute(),await e.schema.createTable("chats").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("chats_session_id_unique",["session","id"]).execute(),await e.schema.createTable("contacts").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("contacts_session_id_unique",["session","id"]).execute(),await e.schema.createTable("messages").ifNotExists().addColumn("session","varchar(50)",(e=>e.notNull())).addColumn("id","varchar(80)",(e=>e.notNull())).addColumn("value","text",(e=>e.defaultTo(null))).addUniqueConstraint("messages_session_id_unique",["session","id"]).execute(),await e.schema.createIndex("auth_session_idx").ifNotExists().on("auth").column("session").execute(),await e.schema.createIndex("auth_id_idx").ifNotExists().on("auth").column("id").execute(),await e.schema.createIndex("chats_session_idx").ifNotExists().on("chats").column("session").execute(),await e.schema.createIndex("chats_id_idx").ifNotExists().on("chats").column("id").execute(),await e.schema.createIndex("contacts_session_idx").ifNotExists().on("contacts").column("session").execute(),await e.schema.createIndex("contacts_id_idx").ifNotExists().on("contacts").column("id").execute(),await e.schema.createIndex("messages_session_idx").ifNotExists().on("messages").column("session").execute(),await e.schema.createIndex("messages_id_idx").ifNotExists().on("messages").column("id").execute()})(e);const a=async e=>{for(let t=0;t<10;t++)try{return await e()}catch(e){await new Promise((e=>setTimeout(e,200)))}throw new Error("Max retries reached")},n=async n=>{const i=await a((()=>e.selectFrom(s).select(["value"]).where("id","=",n).where("session","=",t).executeTakeFirst()));if(!i?.value)return null;const r="object"==typeof i.value?JSON.stringify(i.value):i.value;return JSON.parse(r,R)},i=async(n,i)=>{const r=JSON.stringify(i,P);await a((()=>e.insertInto(s).values({session:t,id:n,value:r}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:r}))).execute()))},r=async n=>{await a((()=>e.deleteFrom(s).where("id","=",n).where("session","=",t).execute()))},o=await n("creds")||(()=>{const e=A();return{noiseKey:A(),pairingEphemeralKeyPair:A(),signedIdentityKey:e,signedPreKey:E(e,1),registrationId:16383&Uint16Array.from(I(2))[0],advSecretKey:I(32).toString("base64"),processedHistoryMessages:[],nextPreKeyId:1,firstUnuploadedPreKeyId:1,accountSyncCounter:0,accountSettings:{unarchiveChats:!1},deviceId:Buffer.from(C().replace(/-/g,""),"hex").toString("base64url"),phoneId:C(),identityId:I(20),backupToken:I(20),registered:!1,registration:{},pairingCode:void 0,lastPropHash:void 0,routingInfo:void 0}})();return{state:{creds:o,keys:{get:async(e,t)=>{const s={};for(const a of t){let t=await n(`${e}-${a}`);"app-state-sync-key"===e&&t&&(t=j(t)),s[a]=t}return s},set:async e=>{for(const t in e)for(const s in e[t]){const a=e[t][s],n=`${t}-${s}`;a?await i(n,a):await r(n)}}}},saveCreds:async()=>{await i("creds",o)},clear:async()=>{await(async()=>{await a((()=>e.deleteFrom(s).where("session","=",t).where("id","!=","creds").execute()))})()},removeCreds:async()=>{await(async()=>{await a((()=>e.deleteFrom(s).where("session","=",t).execute()))})()}}};(O=S||(S={})).assertEqual=e=>e,O.assertIs=function(e){},O.assertNever=function(e){throw new Error},O.arrayToEnum=e=>{const t={};for(const s of e)t[s]=s;return t},O.getValidEnumValues=e=>{const t=O.objectKeys(e).filter((t=>"number"!=typeof e[e[t]])),s={};for(const a of t)s[a]=e[a];return O.objectValues(s)},O.objectValues=e=>O.objectKeys(e).map((function(t){return e[t]})),O.objectKeys="function"==typeof Object.keys?e=>Object.keys(e):e=>{const t=[];for(const s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.push(s);return t},O.find=(e,t)=>{for(const s of e)if(t(s))return s},O.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&isFinite(e)&&Math.floor(e)===e,O.joinValues=function(e,t=" | "){return e.map((e=>"string"==typeof e?`'${e}'`:e)).join(t)},O.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t,(M||(M={})).mergeShapes=(e,t)=>({...e,...t});var F=S.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),L=e=>{switch(typeof e){case"undefined":return F.undefined;case"string":return F.string;case"number":return isNaN(e)?F.nan:F.number;case"boolean":return F.boolean;case"function":return F.function;case"bigint":return F.bigint;case"symbol":return F.symbol;case"object":return Array.isArray(e)?F.array:null===e?F.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?F.promise:"undefined"!=typeof Map&&e instanceof Map?F.map:"undefined"!=typeof Set&&e instanceof Set?F.set:"undefined"!=typeof Date&&e instanceof Date?F.date:F.object;default:return F.unknown}},U=S.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"]),D=class e extends Error{get errors(){return this.issues}constructor(e){super(),this.issues=[],this.addIssue=e=>{this.issues=[...this.issues,e]},this.addIssues=(e=[])=>{this.issues=[...this.issues,...e]};const t=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,t):this.__proto__=t,this.name="ZodError",this.issues=e}format(e){const t=e||function(e){return e.message},s={_errors:[]},a=e=>{for(const n of e.issues)if("invalid_union"===n.code)n.unionErrors.map(a);else if("invalid_return_type"===n.code)a(n.returnTypeError);else if("invalid_arguments"===n.code)a(n.argumentsError);else if(0===n.path.length)s._errors.push(t(n));else{let e=s,a=0;for(;a<n.path.length;){const s=n.path[a];a===n.path.length-1?(e[s]=e[s]||{_errors:[]},e[s]._errors.push(t(n))):e[s]=e[s]||{_errors:[]},e=e[s],a++}}};return a(this),s}static assert(t){if(!(t instanceof e))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,S.jsonStringifyReplacer,2)}get isEmpty(){return 0===this.issues.length}flatten(e=e=>e.message){const t={},s=[];for(const a of this.issues)a.path.length>0?(t[a.path[0]]=t[a.path[0]]||[],t[a.path[0]].push(e(a))):s.push(e(a));return{formErrors:s,fieldErrors:t}}get formErrors(){return this.flatten()}};D.create=e=>new D(e);var z=(e,t)=>{let s;switch(e.code){case U.invalid_type:s=e.received===F.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case U.invalid_literal:s=`Invalid literal value, expected ${JSON.stringify(e.expected,S.jsonStringifyReplacer)}`;break;case U.unrecognized_keys:s=`Unrecognized key(s) in object: ${S.joinValues(e.keys,", ")}`;break;case U.invalid_union:s="Invalid input";break;case U.invalid_union_discriminator:s=`Invalid discriminator value. Expected ${S.joinValues(e.options)}`;break;case U.invalid_enum_value:s=`Invalid enum value. Expected ${S.joinValues(e.options)}, received '${e.received}'`;break;case U.invalid_arguments:s="Invalid function arguments";break;case U.invalid_return_type:s="Invalid function return type";break;case U.invalid_date:s="Invalid date";break;case U.invalid_string:"object"==typeof e.validation?"includes"in e.validation?(s=`Invalid input: must include "${e.validation.includes}"`,"number"==typeof e.validation.position&&(s=`${s} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?s=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?s=`Invalid input: must end with "${e.validation.endsWith}"`:S.assertNever(e.validation):s="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case U.too_small:s="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:"date"===e.type?`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:"Invalid input";break;case U.too_big:s="array"===e.type?`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:"string"===e.type?`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:"number"===e.type?`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"bigint"===e.type?`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:"date"===e.type?`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:"Invalid input";break;case U.custom:s="Invalid input";break;case U.invalid_intersection_types:s="Intersection results could not be merged";break;case U.not_multiple_of:s=`Number must be a multiple of ${e.multipleOf}`;break;case U.not_finite:s="Number must be finite";break;default:s=t.defaultError,S.assertNever(e)}return{message:s}},V=z;function q(){return V}var K=e=>{const{data:t,path:s,errorMaps:a,issueData:n}=e,i=[...s,...n.path||[]],r={...n,path:i};if(void 0!==n.message)return{...n,path:i,message:n.message};let o="";const d=a.filter((e=>!!e)).slice().reverse();for(const e of d)o=e(r,{data:t,defaultError:o}).message;return{...n,path:i,message:o}};function B(e,t){const s=q(),a=K({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,s,s===z?void 0:z].filter((e=>!!e))});e.common.issues.push(a)}var J,W,Y,G,H=class e{constructor(){this.value="valid"}dirty(){"valid"===this.value&&(this.value="dirty")}abort(){"aborted"!==this.value&&(this.value="aborted")}static mergeArray(e,t){const s=[];for(const a of t){if("aborted"===a.status)return Q;"dirty"===a.status&&e.dirty(),s.push(a.value)}return{status:e.value,value:s}}static async mergeObjectAsync(t,s){const a=[];for(const e of s){const t=await e.key,s=await e.value;a.push({key:t,value:s})}return e.mergeObjectSync(t,a)}static mergeObjectSync(e,t){const s={};for(const a of t){const{key:t,value:n}=a;if("aborted"===t.status)return Q;if("aborted"===n.status)return Q;"dirty"===t.status&&e.dirty(),"dirty"===n.status&&e.dirty(),"__proto__"===t.value||void 0===n.value&&!a.alwaysSet||(s[t.value]=n.value)}return{status:e.value,value:s}}},Q=Object.freeze({status:"aborted"}),X=e=>({status:"dirty",value:e}),ee=e=>({status:"valid",value:e}),te=e=>"aborted"===e.status,se=e=>"dirty"===e.status,ae=e=>"valid"===e.status,ne=e=>"undefined"!=typeof Promise&&e instanceof Promise;function ie(e,t,s,a){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return t.get(e)}function re(e,t,s,a,n){if("function"==typeof t||!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return t.set(e,s),s}(W=J||(J={})).errToObj=e=>"string"==typeof e?{message:e}:e||{},W.toString=e=>"string"==typeof e?e:null==e?void 0:e.message;var oe=class{constructor(e,t,s,a){this._cachedPath=[],this.parent=e,this.data=t,this._path=s,this._key=a}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}},de=(e,t)=>{if(ae(t))return{success:!0,data:t.value};if(!e.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 D(e.common.issues);return this._error=t,this._error}}};function ce(e){if(!e)return{};const{errorMap:t,invalid_type_error:s,required_error:a,description:n}=e;if(t&&(s||a))throw new Error('Can\'t use "invalid_type_error" or "required_error" in conjunction with custom error map.');if(t)return{errorMap:t,description:n};return{errorMap:(t,n)=>{var i,r;const{message:o}=e;return"invalid_enum_value"===t.code?{message:null!=o?o:n.defaultError}:void 0===n.data?{message:null!==(i=null!=o?o:a)&&void 0!==i?i:n.defaultError}:"invalid_type"!==t.code?{message:n.defaultError}:{message:null!==(r=null!=o?o:s)&&void 0!==r?r:n.defaultError}},description:n}}var ue,le=class{get description(){return this._def.description}_getType(e){return L(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:L(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new H,ctx:{common:e.parent.common,data:e.data,parsedType:L(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(ne(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 s=this.safeParse(e,t);if(s.success)return s.data;throw s.error}safeParse(e,t){var s;const a={common:{issues:[],async:null!==(s=null==t?void 0:t.async)&&void 0!==s&&s,contextualErrorMap:null==t?void 0:t.errorMap},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:L(e)},n=this._parseSync({data:e,path:a.path,parent:a});return de(a,n)}"~validate"(e){var t,s;const a={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:L(e)};if(!this["~standard"].async)try{const t=this._parseSync({data:e,path:[],parent:a});return ae(t)?{value:t.value}:{issues:a.common.issues}}catch(e){(null===(s=null===(t=null==e?void 0:e.message)||void 0===t?void 0:t.toLowerCase())||void 0===s?void 0:s.includes("encountered"))&&(this["~standard"].async=!0),a.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:a}).then((e=>ae(e)?{value:e.value}:{issues:a.common.issues}))}async parseAsync(e,t){const s=await this.safeParseAsync(e,t);if(s.success)return s.data;throw s.error}async safeParseAsync(e,t){const s={common:{issues:[],contextualErrorMap:null==t?void 0:t.errorMap,async:!0},path:(null==t?void 0:t.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:L(e)},a=this._parse({data:e,path:s.path,parent:s}),n=await(ne(a)?a:Promise.resolve(a));return de(s,n)}refine(e,t){const s=e=>"string"==typeof t||void 0===t?{message:t}:"function"==typeof t?t(e):t;return this._refinement(((t,a)=>{const n=e(t),i=()=>a.addIssue({code:U.custom,...s(t)});return"undefined"!=typeof Promise&&n instanceof Promise?n.then((e=>!!e||(i(),!1))):!!n||(i(),!1)}))}refinement(e,t){return this._refinement(((s,a)=>!!e(s)||(a.addIssue("function"==typeof t?t(s,a):t),!1)))}_refinement(e){return new ut({schema:this,typeName:kt.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}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.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:e=>this["~validate"](e)}}optional(){return lt.create(this,this._def)}nullable(){return pt.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Ke.create(this)}promise(){return ct.create(this,this._def)}or(e){return We.create([this,e],this._def)}and(e){return Qe.create(this,e,this._def)}transform(e){return new ut({...ce(this._def),schema:this,typeName:kt.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new ht({...ce(this._def),innerType:this,defaultValue:t,typeName:kt.ZodDefault})}brand(){return new yt({typeName:kt.ZodBranded,type:this,...ce(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new mt({...ce(this._def),innerType:this,catchValue:t,typeName:kt.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return vt.create(this,e)}readonly(){return _t.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},pe=/^c[^\s-]{8,}$/i,he=/^[0-9a-z]+$/,me=/^[0-9A-HJKMNP-TV-Z]{26}$/i,fe=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,ge=/^[a-z0-9_-]{21}$/i,ye=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ve=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,_e=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,be=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,we=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,ke=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,xe=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Ie=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ce=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Te="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",Ne=new RegExp(`^${Te}$`);function Se(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:null==e.precision&&(t=`${t}(\\.\\d+)?`);return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${e.precision?"+":"?"}`}function Oe(e){let t=`${Te}T${Se(e)}`;const s=[];return s.push(e.local?"Z?":"Z"),e.offset&&s.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${s.join("|")})`,new RegExp(`^${t}$`)}function Me(e,t){if(!ye.test(e))return!1;try{const[s]=e.split("."),a=s.replace(/-/g,"+").replace(/_/g,"/").padEnd(s.length+(4-s.length%4)%4,"="),n=JSON.parse(atob(a));return"object"==typeof n&&null!==n&&(!(!n.typ||!n.alg)&&(!t||n.alg===t))}catch(e){return!1}}function Ze(e,t){return!("v4"!==t&&t||!we.test(e))||!("v6"!==t&&t||!xe.test(e))}var Ae=class e extends le{_parse(e){this._def.coerce&&(e.data=String(e.data));if(this._getType(e)!==F.string){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.string,received:t.parsedType}),Q}const t=new H;let s;for(const i of this._def.checks)if("min"===i.kind)e.data.length<i.value&&(s=this._getOrReturnCtx(e,s),B(s,{code:U.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),t.dirty());else if("max"===i.kind)e.data.length>i.value&&(s=this._getOrReturnCtx(e,s),B(s,{code:U.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),t.dirty());else if("length"===i.kind){const a=e.data.length>i.value,n=e.data.length<i.value;(a||n)&&(s=this._getOrReturnCtx(e,s),a?B(s,{code:U.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):n&&B(s,{code:U.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),t.dirty())}else if("email"===i.kind)_e.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"email",code:U.invalid_string,message:i.message}),t.dirty());else if("emoji"===i.kind)ue||(ue=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),ue.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"emoji",code:U.invalid_string,message:i.message}),t.dirty());else if("uuid"===i.kind)fe.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"uuid",code:U.invalid_string,message:i.message}),t.dirty());else if("nanoid"===i.kind)ge.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"nanoid",code:U.invalid_string,message:i.message}),t.dirty());else if("cuid"===i.kind)pe.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"cuid",code:U.invalid_string,message:i.message}),t.dirty());else if("cuid2"===i.kind)he.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"cuid2",code:U.invalid_string,message:i.message}),t.dirty());else if("ulid"===i.kind)me.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"ulid",code:U.invalid_string,message:i.message}),t.dirty());else if("url"===i.kind)try{new URL(e.data)}catch(a){s=this._getOrReturnCtx(e,s),B(s,{validation:"url",code:U.invalid_string,message:i.message}),t.dirty()}else if("regex"===i.kind){i.regex.lastIndex=0;i.regex.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"regex",code:U.invalid_string,message:i.message}),t.dirty())}else if("trim"===i.kind)e.data=e.data.trim();else if("includes"===i.kind)e.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(e,s),B(s,{code:U.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),t.dirty());else if("toLowerCase"===i.kind)e.data=e.data.toLowerCase();else if("toUpperCase"===i.kind)e.data=e.data.toUpperCase();else if("startsWith"===i.kind)e.data.startsWith(i.value)||(s=this._getOrReturnCtx(e,s),B(s,{code:U.invalid_string,validation:{startsWith:i.value},message:i.message}),t.dirty());else if("endsWith"===i.kind)e.data.endsWith(i.value)||(s=this._getOrReturnCtx(e,s),B(s,{code:U.invalid_string,validation:{endsWith:i.value},message:i.message}),t.dirty());else if("datetime"===i.kind){Oe(i).test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{code:U.invalid_string,validation:"datetime",message:i.message}),t.dirty())}else if("date"===i.kind){Ne.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{code:U.invalid_string,validation:"date",message:i.message}),t.dirty())}else if("time"===i.kind){new RegExp(`^${Se(i)}$`).test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{code:U.invalid_string,validation:"time",message:i.message}),t.dirty())}else"duration"===i.kind?ve.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"duration",code:U.invalid_string,message:i.message}),t.dirty()):"ip"===i.kind?(a=e.data,("v4"!==(n=i.version)&&n||!be.test(a))&&("v6"!==n&&n||!ke.test(a))&&(s=this._getOrReturnCtx(e,s),B(s,{validation:"ip",code:U.invalid_string,message:i.message}),t.dirty())):"jwt"===i.kind?Me(e.data,i.alg)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"jwt",code:U.invalid_string,message:i.message}),t.dirty()):"cidr"===i.kind?Ze(e.data,i.version)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"cidr",code:U.invalid_string,message:i.message}),t.dirty()):"base64"===i.kind?Ie.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"base64",code:U.invalid_string,message:i.message}),t.dirty()):"base64url"===i.kind?Ce.test(e.data)||(s=this._getOrReturnCtx(e,s),B(s,{validation:"base64url",code:U.invalid_string,message:i.message}),t.dirty()):S.assertNever(i);var a,n;return{status:t.value,value:e.data}}_regex(e,t,s){return this.refinement((t=>e.test(t)),{validation:t,code:U.invalid_string,...J.errToObj(s)})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}email(e){return this._addCheck({kind:"email",...J.errToObj(e)})}url(e){return this._addCheck({kind:"url",...J.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...J.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...J.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...J.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...J.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...J.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...J.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...J.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...J.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...J.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...J.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...J.errToObj(e)})}datetime(e){var t,s;return"string"==typeof e?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,offset:null!==(t=null==e?void 0:e.offset)&&void 0!==t&&t,local:null!==(s=null==e?void 0:e.local)&&void 0!==s&&s,...J.errToObj(null==e?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return"string"==typeof e?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:void 0===(null==e?void 0:e.precision)?null:null==e?void 0:e.precision,...J.errToObj(null==e?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...J.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...J.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:null==t?void 0:t.position,...J.errToObj(null==t?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...J.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...J.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...J.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...J.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...J.errToObj(t)})}nonempty(e){return this.min(1,J.errToObj(e))}trim(){return new e({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new e({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find((e=>"datetime"===e.kind))}get isDate(){return!!this._def.checks.find((e=>"date"===e.kind))}get isTime(){return!!this._def.checks.find((e=>"time"===e.kind))}get isDuration(){return!!this._def.checks.find((e=>"duration"===e.kind))}get isEmail(){return!!this._def.checks.find((e=>"email"===e.kind))}get isURL(){return!!this._def.checks.find((e=>"url"===e.kind))}get isEmoji(){return!!this._def.checks.find((e=>"emoji"===e.kind))}get isUUID(){return!!this._def.checks.find((e=>"uuid"===e.kind))}get isNANOID(){return!!this._def.checks.find((e=>"nanoid"===e.kind))}get isCUID(){return!!this._def.checks.find((e=>"cuid"===e.kind))}get isCUID2(){return!!this._def.checks.find((e=>"cuid2"===e.kind))}get isULID(){return!!this._def.checks.find((e=>"ulid"===e.kind))}get isIP(){return!!this._def.checks.find((e=>"ip"===e.kind))}get isCIDR(){return!!this._def.checks.find((e=>"cidr"===e.kind))}get isBase64(){return!!this._def.checks.find((e=>"base64"===e.kind))}get isBase64url(){return!!this._def.checks.find((e=>"base64url"===e.kind))}get minLength(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxLength(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}};function Ee(e,t){const s=(e.toString().split(".")[1]||"").length,a=(t.toString().split(".")[1]||"").length,n=s>a?s:a;return parseInt(e.toFixed(n).replace(".",""))%parseInt(t.toFixed(n).replace(".",""))/Math.pow(10,n)}Ae.create=e=>{var t;return new Ae({checks:[],typeName:kt.ZodString,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...ce(e)})};var je=class e extends le{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){this._def.coerce&&(e.data=Number(e.data));if(this._getType(e)!==F.number){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.number,received:t.parsedType}),Q}let t;const s=new H;for(const a of this._def.checks)if("int"===a.kind)S.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),B(t,{code:U.invalid_type,expected:"integer",received:"float",message:a.message}),s.dirty());else if("min"===a.kind){(a.inclusive?e.data<a.value:e.data<=a.value)&&(t=this._getOrReturnCtx(e,t),B(t,{code:U.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty())}else if("max"===a.kind){(a.inclusive?e.data>a.value:e.data>=a.value)&&(t=this._getOrReturnCtx(e,t),B(t,{code:U.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),s.dirty())}else"multipleOf"===a.kind?0!==Ee(e.data,a.value)&&(t=this._getOrReturnCtx(e,t),B(t,{code:U.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):"finite"===a.kind?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),B(t,{code:U.not_finite,message:a.message}),s.dirty()):S.assertNever(a);return{status:s.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,J.toString(t))}gt(e,t){return this.setLimit("min",e,!1,J.toString(t))}lte(e,t){return this.setLimit("max",e,!0,J.toString(t))}lt(e,t){return this.setLimit("max",e,!1,J.toString(t))}setLimit(t,s,a,n){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:s,inclusive:a,message:J.toString(n)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}int(e){return this._addCheck({kind:"int",message:J.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:J.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:J.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:J.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:J.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:J.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:J.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:J.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:J.toString(e)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}get isInt(){return!!this._def.checks.find((e=>"int"===e.kind||"multipleOf"===e.kind&&S.isInteger(e.value)))}get isFinite(){let e=null,t=null;for(const s of this._def.checks){if("finite"===s.kind||"int"===s.kind||"multipleOf"===s.kind)return!0;"min"===s.kind?(null===t||s.value>t)&&(t=s.value):"max"===s.kind&&(null===e||s.value<e)&&(e=s.value)}return Number.isFinite(t)&&Number.isFinite(e)}};je.create=e=>new je({checks:[],typeName:kt.ZodNumber,coerce:(null==e?void 0:e.coerce)||!1,...ce(e)});var Pe=class e extends le{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch(t){return this._getInvalidInput(e)}if(this._getType(e)!==F.bigint)return this._getInvalidInput(e);let t;const s=new H;for(const a of this._def.checks)if("min"===a.kind){(a.inclusive?e.data<a.value:e.data<=a.value)&&(t=this._getOrReturnCtx(e,t),B(t,{code:U.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty())}else if("max"===a.kind){(a.inclusive?e.data>a.value:e.data>=a.value)&&(t=this._getOrReturnCtx(e,t),B(t,{code:U.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),s.dirty())}else"multipleOf"===a.kind?e.data%a.value!==BigInt(0)&&(t=this._getOrReturnCtx(e,t),B(t,{code:U.not_multiple_of,multipleOf:a.value,message:a.message}),s.dirty()):S.assertNever(a);return{status:s.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.bigint,received:t.parsedType}),Q}gte(e,t){return this.setLimit("min",e,!0,J.toString(t))}gt(e,t){return this.setLimit("min",e,!1,J.toString(t))}lte(e,t){return this.setLimit("max",e,!0,J.toString(t))}lt(e,t){return this.setLimit("max",e,!1,J.toString(t))}setLimit(t,s,a,n){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:s,inclusive:a,message:J.toString(n)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:J.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:J.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:J.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:J.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:J.toString(t)})}get minValue(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return e}get maxValue(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return e}};Pe.create=e=>{var t;return new Pe({checks:[],typeName:kt.ZodBigInt,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...ce(e)})};var Re=class extends le{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==F.boolean){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.boolean,received:t.parsedType}),Q}return ee(e.data)}};Re.create=e=>new Re({typeName:kt.ZodBoolean,coerce:(null==e?void 0:e.coerce)||!1,...ce(e)});var $e=class e extends le{_parse(e){this._def.coerce&&(e.data=new Date(e.data));if(this._getType(e)!==F.date){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.date,received:t.parsedType}),Q}if(isNaN(e.data.getTime())){return B(this._getOrReturnCtx(e),{code:U.invalid_date}),Q}const t=new H;let s;for(const a of this._def.checks)"min"===a.kind?e.data.getTime()<a.value&&(s=this._getOrReturnCtx(e,s),B(s,{code:U.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),t.dirty()):"max"===a.kind?e.data.getTime()>a.value&&(s=this._getOrReturnCtx(e,s),B(s,{code:U.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),t.dirty()):S.assertNever(a);return{status:t.value,value:new Date(e.data.getTime())}}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:J.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:J.toString(t)})}get minDate(){let e=null;for(const t of this._def.checks)"min"===t.kind&&(null===e||t.value>e)&&(e=t.value);return null!=e?new Date(e):null}get maxDate(){let e=null;for(const t of this._def.checks)"max"===t.kind&&(null===e||t.value<e)&&(e=t.value);return null!=e?new Date(e):null}};$e.create=e=>new $e({checks:[],coerce:(null==e?void 0:e.coerce)||!1,typeName:kt.ZodDate,...ce(e)});var Fe=class extends le{_parse(e){if(this._getType(e)!==F.symbol){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.symbol,received:t.parsedType}),Q}return ee(e.data)}};Fe.create=e=>new Fe({typeName:kt.ZodSymbol,...ce(e)});var Le=class extends le{_parse(e){if(this._getType(e)!==F.undefined){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.undefined,received:t.parsedType}),Q}return ee(e.data)}};Le.create=e=>new Le({typeName:kt.ZodUndefined,...ce(e)});var Ue=class extends le{_parse(e){if(this._getType(e)!==F.null){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.null,received:t.parsedType}),Q}return ee(e.data)}};Ue.create=e=>new Ue({typeName:kt.ZodNull,...ce(e)});var De=class extends le{constructor(){super(...arguments),this._any=!0}_parse(e){return ee(e.data)}};De.create=e=>new De({typeName:kt.ZodAny,...ce(e)});var ze=class extends le{constructor(){super(...arguments),this._unknown=!0}_parse(e){return ee(e.data)}};ze.create=e=>new ze({typeName:kt.ZodUnknown,...ce(e)});var Ve=class extends le{_parse(e){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.never,received:t.parsedType}),Q}};Ve.create=e=>new Ve({typeName:kt.ZodNever,...ce(e)});var qe=class extends le{_parse(e){if(this._getType(e)!==F.undefined){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.void,received:t.parsedType}),Q}return ee(e.data)}};qe.create=e=>new qe({typeName:kt.ZodVoid,...ce(e)});var Ke=class e extends le{_parse(e){const{ctx:t,status:s}=this._processInputParams(e),a=this._def;if(t.parsedType!==F.array)return B(t,{code:U.invalid_type,expected:F.array,received:t.parsedType}),Q;if(null!==a.exactLength){const e=t.data.length>a.exactLength.value,n=t.data.length<a.exactLength.value;(e||n)&&(B(t,{code:e?U.too_big:U.too_small,minimum:n?a.exactLength.value:void 0,maximum:e?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),s.dirty())}if(null!==a.minLength&&t.data.length<a.minLength.value&&(B(t,{code:U.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),s.dirty()),null!==a.maxLength&&t.data.length>a.maxLength.value&&(B(t,{code:U.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),s.dirty()),t.common.async)return Promise.all([...t.data].map(((e,s)=>a.type._parseAsync(new oe(t,e,t.path,s))))).then((e=>H.mergeArray(s,e)));const n=[...t.data].map(((e,s)=>a.type._parseSync(new oe(t,e,t.path,s))));return H.mergeArray(s,n)}get element(){return this._def.type}min(t,s){return new e({...this._def,minLength:{value:t,message:J.toString(s)}})}max(t,s){return new e({...this._def,maxLength:{value:t,message:J.toString(s)}})}length(t,s){return new e({...this._def,exactLength:{value:t,message:J.toString(s)}})}nonempty(e){return this.min(1,e)}};function Be(e){if(e instanceof Je){const t={};for(const s in e.shape){const a=e.shape[s];t[s]=lt.create(Be(a))}return new Je({...e._def,shape:()=>t})}return e instanceof Ke?new Ke({...e._def,type:Be(e.element)}):e instanceof lt?lt.create(Be(e.unwrap())):e instanceof pt?pt.create(Be(e.unwrap())):e instanceof Xe?Xe.create(e.items.map((e=>Be(e)))):e}Ke.create=(e,t)=>new Ke({type:e,minLength:null,maxLength:null,exactLength:null,typeName:kt.ZodArray,...ce(t)});var Je=class e extends le{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(null!==this._cached)return this._cached;const e=this._def.shape(),t=S.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==F.object){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.object,received:t.parsedType}),Q}const{status:t,ctx:s}=this._processInputParams(e),{shape:a,keys:n}=this._getCached(),i=[];if(!(this._def.catchall instanceof Ve&&"strip"===this._def.unknownKeys))for(const e in s.data)n.includes(e)||i.push(e);const r=[];for(const e of n){const t=a[e],n=s.data[e];r.push({key:{status:"valid",value:e},value:t._parse(new oe(s,n,s.path,e)),alwaysSet:e in s.data})}if(this._def.catchall instanceof Ve){const e=this._def.unknownKeys;if("passthrough"===e)for(const e of i)r.push({key:{status:"valid",value:e},value:{status:"valid",value:s.data[e]}});else if("strict"===e)i.length>0&&(B(s,{code:U.unrecognized_keys,keys:i}),t.dirty());else if("strip"!==e)throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const e=this._def.catchall;for(const t of i){const a=s.data[t];r.push({key:{status:"valid",value:t},value:e._parse(new oe(s,a,s.path,t)),alwaysSet:t in s.data})}}return s.common.async?Promise.resolve().then((async()=>{const e=[];for(const t of r){const s=await t.key,a=await t.value;e.push({key:s,value:a,alwaysSet:t.alwaysSet})}return e})).then((e=>H.mergeObjectSync(t,e))):H.mergeObjectSync(t,r)}get shape(){return this._def.shape()}strict(t){return J.errToObj,new e({...this._def,unknownKeys:"strict",...void 0!==t?{errorMap:(e,s)=>{var a,n,i,r;const o=null!==(i=null===(n=(a=this._def).errorMap)||void 0===n?void 0:n.call(a,e,s).message)&&void 0!==i?i:s.defaultError;return"unrecognized_keys"===e.code?{message:null!==(r=J.errToObj(t).message)&&void 0!==r?r:o}:{message:o}}}:{}})}strip(){return new e({...this._def,unknownKeys:"strip"})}passthrough(){return new e({...this._def,unknownKeys:"passthrough"})}extend(t){return new e({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new e({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:kt.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(t){return new e({...this._def,catchall:t})}pick(t){const s={};return S.objectKeys(t).forEach((e=>{t[e]&&this.shape[e]&&(s[e]=this.shape[e])})),new e({...this._def,shape:()=>s})}omit(t){const s={};return S.objectKeys(this.shape).forEach((e=>{t[e]||(s[e]=this.shape[e])})),new e({...this._def,shape:()=>s})}deepPartial(){return Be(this)}partial(t){const s={};return S.objectKeys(this.shape).forEach((e=>{const a=this.shape[e];t&&!t[e]?s[e]=a:s[e]=a.optional()})),new e({...this._def,shape:()=>s})}required(t){const s={};return S.objectKeys(this.shape).forEach((e=>{if(t&&!t[e])s[e]=this.shape[e];else{let t=this.shape[e];for(;t instanceof lt;)t=t._def.innerType;s[e]=t}})),new e({...this._def,shape:()=>s})}keyof(){return rt(S.objectKeys(this.shape))}};Je.create=(e,t)=>new Je({shape:()=>e,unknownKeys:"strip",catchall:Ve.create(),typeName:kt.ZodObject,...ce(t)}),Je.strictCreate=(e,t)=>new Je({shape:()=>e,unknownKeys:"strict",catchall:Ve.create(),typeName:kt.ZodObject,...ce(t)}),Je.lazycreate=(e,t)=>new Je({shape:e,unknownKeys:"strip",catchall:Ve.create(),typeName:kt.ZodObject,...ce(t)});var We=class extends le{_parse(e){const{ctx:t}=this._processInputParams(e),s=this._def.options;if(t.common.async)return Promise.all(s.map((async e=>{const s={...t,common:{...t.common,issues:[]},parent:null};return{result:await e._parseAsync({data:t.data,path:t.path,parent:s}),ctx:s}}))).then((function(e){for(const t of e)if("valid"===t.result.status)return t.result;for(const s of e)if("dirty"===s.result.status)return t.common.issues.push(...s.ctx.common.issues),s.result;const s=e.map((e=>new D(e.ctx.common.issues)));return B(t,{code:U.invalid_union,unionErrors:s}),Q}));{let e;const a=[];for(const n of s){const s={...t,common:{...t.common,issues:[]},parent:null},i=n._parseSync({data:t.data,path:t.path,parent:s});if("valid"===i.status)return i;"dirty"!==i.status||e||(e={result:i,ctx:s}),s.common.issues.length&&a.push(s.common.issues)}if(e)return t.common.issues.push(...e.ctx.common.issues),e.result;const n=a.map((e=>new D(e)));return B(t,{code:U.invalid_union,unionErrors:n}),Q}}get options(){return this._def.options}};We.create=(e,t)=>new We({options:e,typeName:kt.ZodUnion,...ce(t)});var Ye=e=>e instanceof nt?Ye(e.schema):e instanceof ut?Ye(e.innerType()):e instanceof it?[e.value]:e instanceof ot?e.options:e instanceof dt?S.objectValues(e.enum):e instanceof ht?Ye(e._def.innerType):e instanceof Le?[void 0]:e instanceof Ue?[null]:e instanceof lt?[void 0,...Ye(e.unwrap())]:e instanceof pt?[null,...Ye(e.unwrap())]:e instanceof yt||e instanceof _t?Ye(e.unwrap()):e instanceof mt?Ye(e._def.innerType):[],Ge=class e extends le{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==F.object)return B(t,{code:U.invalid_type,expected:F.object,received:t.parsedType}),Q;const s=this.discriminator,a=t.data[s],n=this.optionsMap.get(a);return n?t.common.async?n._parseAsync({data:t.data,path:t.path,parent:t}):n._parseSync({data:t.data,path:t.path,parent:t}):(B(t,{code:U.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[s]}),Q)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,s,a){const n=new Map;for(const e of s){const s=Ye(e.shape[t]);if(!s.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const a of s){if(n.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);n.set(a,e)}}return new e({typeName:kt.ZodDiscriminatedUnion,discriminator:t,options:s,optionsMap:n,...ce(a)})}};function He(e,t){const s=L(e),a=L(t);if(e===t)return{valid:!0,data:e};if(s===F.object&&a===F.object){const s=S.objectKeys(t),a=S.objectKeys(e).filter((e=>-1!==s.indexOf(e))),n={...e,...t};for(const s of a){const a=He(e[s],t[s]);if(!a.valid)return{valid:!1};n[s]=a.data}return{valid:!0,data:n}}if(s===F.array&&a===F.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let a=0;a<e.length;a++){const n=He(e[a],t[a]);if(!n.valid)return{valid:!1};s.push(n.data)}return{valid:!0,data:s}}return s===F.date&&a===F.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}var Qe=class extends le{_parse(e){const{status:t,ctx:s}=this._processInputParams(e),a=(e,a)=>{if(te(e)||te(a))return Q;const n=He(e.value,a.value);return n.valid?((se(e)||se(a))&&t.dirty(),{status:t.value,value:n.data}):(B(s,{code:U.invalid_intersection_types}),Q)};return s.common.async?Promise.all([this._def.left._parseAsync({data:s.data,path:s.path,parent:s}),this._def.right._parseAsync({data:s.data,path:s.path,parent:s})]).then((([e,t])=>a(e,t))):a(this._def.left._parseSync({data:s.data,path:s.path,parent:s}),this._def.right._parseSync({data:s.data,path:s.path,parent:s}))}};Qe.create=(e,t,s)=>new Qe({left:e,right:t,typeName:kt.ZodIntersection,...ce(s)});var Xe=class e extends le{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==F.array)return B(s,{code:U.invalid_type,expected:F.array,received:s.parsedType}),Q;if(s.data.length<this._def.items.length)return B(s,{code:U.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Q;!this._def.rest&&s.data.length>this._def.items.length&&(B(s,{code:U.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty());const a=[...s.data].map(((e,t)=>{const a=this._def.items[t]||this._def.rest;return a?a._parse(new oe(s,e,s.path,t)):null})).filter((e=>!!e));return s.common.async?Promise.all(a).then((e=>H.mergeArray(t,e))):H.mergeArray(t,a)}get items(){return this._def.items}rest(t){return new e({...this._def,rest:t})}};Xe.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Xe({items:e,typeName:kt.ZodTuple,rest:null,...ce(t)})};var et=class e extends le{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==F.object)return B(s,{code:U.invalid_type,expected:F.object,received:s.parsedType}),Q;const a=[],n=this._def.keyType,i=this._def.valueType;for(const e in s.data)a.push({key:n._parse(new oe(s,e,s.path,e)),value:i._parse(new oe(s,s.data[e],s.path,e)),alwaysSet:e in s.data});return s.common.async?H.mergeObjectAsync(t,a):H.mergeObjectSync(t,a)}get element(){return this._def.valueType}static create(t,s,a){return new e(s instanceof le?{keyType:t,valueType:s,typeName:kt.ZodRecord,...ce(a)}:{keyType:Ae.create(),valueType:t,typeName:kt.ZodRecord,...ce(s)})}},tt=class extends le{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==F.map)return B(s,{code:U.invalid_type,expected:F.map,received:s.parsedType}),Q;const a=this._def.keyType,n=this._def.valueType,i=[...s.data.entries()].map((([e,t],i)=>({key:a._parse(new oe(s,e,s.path,[i,"key"])),value:n._parse(new oe(s,t,s.path,[i,"value"]))})));if(s.common.async){const e=new Map;return Promise.resolve().then((async()=>{for(const s of i){const a=await s.key,n=await s.value;if("aborted"===a.status||"aborted"===n.status)return Q;"dirty"!==a.status&&"dirty"!==n.status||t.dirty(),e.set(a.value,n.value)}return{status:t.value,value:e}}))}{const e=new Map;for(const s of i){const a=s.key,n=s.value;if("aborted"===a.status||"aborted"===n.status)return Q;"dirty"!==a.status&&"dirty"!==n.status||t.dirty(),e.set(a.value,n.value)}return{status:t.value,value:e}}}};tt.create=(e,t,s)=>new tt({valueType:t,keyType:e,typeName:kt.ZodMap,...ce(s)});var st=class e extends le{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.parsedType!==F.set)return B(s,{code:U.invalid_type,expected:F.set,received:s.parsedType}),Q;const a=this._def;null!==a.minSize&&s.data.size<a.minSize.value&&(B(s,{code:U.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),t.dirty()),null!==a.maxSize&&s.data.size>a.maxSize.value&&(B(s,{code:U.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),t.dirty());const n=this._def.valueType;function i(e){const s=new Set;for(const a of e){if("aborted"===a.status)return Q;"dirty"===a.status&&t.dirty(),s.add(a.value)}return{status:t.value,value:s}}const r=[...s.data.values()].map(((e,t)=>n._parse(new oe(s,e,s.path,t))));return s.common.async?Promise.all(r).then((e=>i(e))):i(r)}min(t,s){return new e({...this._def,minSize:{value:t,message:J.toString(s)}})}max(t,s){return new e({...this._def,maxSize:{value:t,message:J.toString(s)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}};st.create=(e,t)=>new st({valueType:e,minSize:null,maxSize:null,typeName:kt.ZodSet,...ce(t)});var at=class e extends le{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==F.function)return B(t,{code:U.invalid_type,expected:F.function,received:t.parsedType}),Q;function s(e,s){return K({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,q(),z].filter((e=>!!e)),issueData:{code:U.invalid_arguments,argumentsError:s}})}function a(e,s){return K({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,q(),z].filter((e=>!!e)),issueData:{code:U.invalid_return_type,returnTypeError:s}})}const n={errorMap:t.common.contextualErrorMap},i=t.data;if(this._def.returns instanceof ct){const e=this;return ee((async function(...t){const r=new D([]),o=await e._def.args.parseAsync(t,n).catch((e=>{throw r.addIssue(s(t,e)),r})),d=await Reflect.apply(i,this,o);return await e._def.returns._def.type.parseAsync(d,n).catch((e=>{throw r.addIssue(a(d,e)),r}))}))}{const e=this;return ee((function(...t){const r=e._def.args.safeParse(t,n);if(!r.success)throw new D([s(t,r.error)]);const o=Reflect.apply(i,this,r.data),d=e._def.returns.safeParse(o,n);if(!d.success)throw new D([a(o,d.error)]);return d.data}))}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...t){return new e({...this._def,args:Xe.create(t).rest(ze.create())})}returns(t){return new e({...this._def,returns:t})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(t,s,a){return new e({args:t||Xe.create([]).rest(ze.create()),returns:s||ze.create(),typeName:kt.ZodFunction,...ce(a)})}},nt=class extends le{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=(e,t)=>new nt({getter:e,typeName:kt.ZodLazy,...ce(t)});var it=class extends le{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return B(t,{received:t.data,code:U.invalid_literal,expected:this._def.value}),Q}return{status:"valid",value:e.data}}get value(){return this._def.value}};function rt(e,t){return new ot({values:e,typeName:kt.ZodEnum,...ce(t)})}it.create=(e,t)=>new it({value:e,typeName:kt.ZodLiteral,...ce(t)});var ot=class e extends le{constructor(){super(...arguments),Y.set(this,void 0)}_parse(e){if("string"!=typeof e.data){const t=this._getOrReturnCtx(e),s=this._def.values;return B(t,{expected:S.joinValues(s),received:t.parsedType,code:U.invalid_type}),Q}if(ie(this,Y)||re(this,Y,new Set(this._def.values)),!ie(this,Y).has(e.data)){const t=this._getOrReturnCtx(e),s=this._def.values;return B(t,{received:t.data,code:U.invalid_enum_value,options:s}),Q}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(t,s=this._def){return e.create(t,{...this._def,...s})}exclude(t,s=this._def){return e.create(this.options.filter((e=>!t.includes(e))),{...this._def,...s})}};Y=new WeakMap,ot.create=rt;var dt=class extends le{constructor(){super(...arguments),G.set(this,void 0)}_parse(e){const t=S.getValidEnumValues(this._def.values),s=this._getOrReturnCtx(e);if(s.parsedType!==F.string&&s.parsedType!==F.number){const e=S.objectValues(t);return B(s,{expected:S.joinValues(e),received:s.parsedType,code:U.invalid_type}),Q}if(ie(this,G)||re(this,G,new Set(S.getValidEnumValues(this._def.values))),!ie(this,G).has(e.data)){const e=S.objectValues(t);return B(s,{received:s.data,code:U.invalid_enum_value,options:e}),Q}return ee(e.data)}get enum(){return this._def.values}};G=new WeakMap,dt.create=(e,t)=>new dt({values:e,typeName:kt.ZodNativeEnum,...ce(t)});var ct=class extends le{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==F.promise&&!1===t.common.async)return B(t,{code:U.invalid_type,expected:F.promise,received:t.parsedType}),Q;const s=t.parsedType===F.promise?t.data:Promise.resolve(t.data);return ee(s.then((e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap}))))}};ct.create=(e,t)=>new ct({type:e,typeName:kt.ZodPromise,...ce(t)});var ut=class extends le{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===kt.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:t,ctx:s}=this._processInputParams(e),a=this._def.effect||null,n={addIssue:e=>{B(s,e),e.fatal?t.abort():t.dirty()},get path(){return s.path}};if(n.addIssue=n.addIssue.bind(n),"preprocess"===a.type){const e=a.transform(s.data,n);if(s.common.async)return Promise.resolve(e).then((async e=>{if("aborted"===t.value)return Q;const a=await this._def.schema._parseAsync({data:e,path:s.path,parent:s});return"aborted"===a.status?Q:"dirty"===a.status||"dirty"===t.value?X(a.value):a}));{if("aborted"===t.value)return Q;const a=this._def.schema._parseSync({data:e,path:s.path,parent:s});return"aborted"===a.status?Q:"dirty"===a.status||"dirty"===t.value?X(a.value):a}}if("refinement"===a.type){const e=e=>{const t=a.refinement(e,n);if(s.common.async)return Promise.resolve(t);if(t instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return e};if(!1===s.common.async){const a=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});return"aborted"===a.status?Q:("dirty"===a.status&&t.dirty(),e(a.value),{status:t.value,value:a.value})}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((s=>"aborted"===s.status?Q:("dirty"===s.status&&t.dirty(),e(s.value).then((()=>({status:t.value,value:s.value}))))))}if("transform"===a.type){if(!1===s.common.async){const e=this._def.schema._parseSync({data:s.data,path:s.path,parent:s});if(!ae(e))return e;const i=a.transform(e.value,n);if(i instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:i}}return this._def.schema._parseAsync({data:s.data,path:s.path,parent:s}).then((e=>ae(e)?Promise.resolve(a.transform(e.value,n)).then((e=>({status:t.value,value:e}))):e))}S.assertNever(a)}};ut.create=(e,t,s)=>new ut({schema:e,typeName:kt.ZodEffects,effect:t,...ce(s)}),ut.createWithPreprocess=(e,t,s)=>new ut({schema:t,effect:{type:"preprocess",transform:e},typeName:kt.ZodEffects,...ce(s)});var lt=class extends le{_parse(e){return this._getType(e)===F.undefined?ee(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};lt.create=(e,t)=>new lt({innerType:e,typeName:kt.ZodOptional,...ce(t)});var pt=class extends le{_parse(e){return this._getType(e)===F.null?ee(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};pt.create=(e,t)=>new pt({innerType:e,typeName:kt.ZodNullable,...ce(t)});var ht=class extends le{_parse(e){const{ctx:t}=this._processInputParams(e);let s=t.data;return t.parsedType===F.undefined&&(s=this._def.defaultValue()),this._def.innerType._parse({data:s,path:t.path,parent:t})}removeDefault(){return this._def.innerType}};ht.create=(e,t)=>new ht({innerType:e,typeName:kt.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...ce(t)});var mt=class extends le{_parse(e){const{ctx:t}=this._processInputParams(e),s={...t,common:{...t.common,issues:[]}},a=this._def.innerType._parse({data:s.data,path:s.path,parent:{...s}});return ne(a)?a.then((e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new D(s.common.issues)},input:s.data})}))):{status:"valid",value:"valid"===a.status?a.value:this._def.catchValue({get error(){return new D(s.common.issues)},input:s.data})}}removeCatch(){return this._def.innerType}};mt.create=(e,t)=>new mt({innerType:e,typeName:kt.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...ce(t)});var ft=class extends le{_parse(e){if(this._getType(e)!==F.nan){const t=this._getOrReturnCtx(e);return B(t,{code:U.invalid_type,expected:F.nan,received:t.parsedType}),Q}return{status:"valid",value:e.data}}};ft.create=e=>new ft({typeName:kt.ZodNaN,...ce(e)});var gt=Symbol("zod_brand"),yt=class extends le{_parse(e){const{ctx:t}=this._processInputParams(e),s=t.data;return this._def.type._parse({data:s,path:t.path,parent:t})}unwrap(){return this._def.type}},vt=class e extends le{_parse(e){const{status:t,ctx:s}=this._processInputParams(e);if(s.common.async){return(async()=>{const e=await this._def.in._parseAsync({data:s.data,path:s.path,parent:s});return"aborted"===e.status?Q:"dirty"===e.status?(t.dirty(),X(e.value)):this._def.out._parseAsync({data:e.value,path:s.path,parent:s})})()}{const e=this._def.in._parseSync({data:s.data,path:s.path,parent:s});return"aborted"===e.status?Q:"dirty"===e.status?(t.dirty(),{status:"dirty",value:e.value}):this._def.out._parseSync({data:e.value,path:s.path,parent:s})}}static create(t,s){return new e({in:t,out:s,typeName:kt.ZodPipeline})}},_t=class extends le{_parse(e){const t=this._def.innerType._parse(e),s=e=>(ae(e)&&(e.value=Object.freeze(e.value)),e);return ne(t)?t.then((e=>s(e))):s(t)}unwrap(){return this._def.innerType}};function bt(e,t){const s="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof s?{message:s}:s}function wt(e,t={},s){return e?De.create().superRefine(((a,n)=>{var i,r;const o=e(a);if(o instanceof Promise)return o.then((e=>{var i,r;if(!e){const e=bt(t,a),o=null===(r=null!==(i=e.fatal)&&void 0!==i?i:s)||void 0===r||r;n.addIssue({code:"custom",...e,fatal:o})}}));if(!o){const e=bt(t,a),o=null===(r=null!==(i=e.fatal)&&void 0!==i?i:s)||void 0===r||r;n.addIssue({code:"custom",...e,fatal:o})}})):De.create()}_t.create=(e,t)=>new _t({innerType:e,typeName:kt.ZodReadonly,...ce(t)});var kt,xt,It={object:Je.lazycreate};(xt=kt||(kt={})).ZodString="ZodString",xt.ZodNumber="ZodNumber",xt.ZodNaN="ZodNaN",xt.ZodBigInt="ZodBigInt",xt.ZodBoolean="ZodBoolean",xt.ZodDate="ZodDate",xt.ZodSymbol="ZodSymbol",xt.ZodUndefined="ZodUndefined",xt.ZodNull="ZodNull",xt.ZodAny="ZodAny",xt.ZodUnknown="ZodUnknown",xt.ZodNever="ZodNever",xt.ZodVoid="ZodVoid",xt.ZodArray="ZodArray",xt.ZodObject="ZodObject",xt.ZodUnion="ZodUnion",xt.ZodDiscriminatedUnion="ZodDiscriminatedUnion",xt.ZodIntersection="ZodIntersection",xt.ZodTuple="ZodTuple",xt.ZodRecord="ZodRecord",xt.ZodMap="ZodMap",xt.ZodSet="ZodSet",xt.ZodFunction="ZodFunction",xt.ZodLazy="ZodLazy",xt.ZodLiteral="ZodLiteral",xt.ZodEnum="ZodEnum",xt.ZodEffects="ZodEffects",xt.ZodNativeEnum="ZodNativeEnum",xt.ZodOptional="ZodOptional",xt.ZodNullable="ZodNullable",xt.ZodDefault="ZodDefault",xt.ZodCatch="ZodCatch",xt.ZodPromise="ZodPromise",xt.ZodBranded="ZodBranded",xt.ZodPipeline="ZodPipeline",xt.ZodReadonly="ZodReadonly";var Ct=Ae.create,Tt=je.create,Nt=ft.create,St=Pe.create,Ot=Re.create,Mt=$e.create,Zt=Fe.create,At=Le.create,Et=Ue.create,jt=De.create,Pt=ze.create,Rt=Ve.create,$t=qe.create,Ft=Ke.create,Lt=Je.create,Ut=Je.strictCreate,Dt=We.create,zt=Ge.create,Vt=Qe.create,qt=Xe.create,Kt=et.create,Bt=tt.create,Jt=st.create,Wt=at.create,Yt=nt.create,Gt=it.create,Ht=ot.create,Qt=dt.create,Xt=ct.create,es=ut.create,ts=lt.create,ss=pt.create,as=ut.createWithPreprocess,ns=vt.create,is={string:e=>Ae.create({...e,coerce:!0}),number:e=>je.create({...e,coerce:!0}),boolean:e=>Re.create({...e,coerce:!0}),bigint:e=>Pe.create({...e,coerce:!0}),date:e=>$e.create({...e,coerce:!0})},rs=Q,os=Object.freeze({__proto__:null,defaultErrorMap:z,setErrorMap:function(e){V=e},getErrorMap:q,makeIssue:K,EMPTY_PATH:[],addIssueToContext:B,ParseStatus:H,INVALID:Q,DIRTY:X,OK:ee,isAborted:te,isDirty:se,isValid:ae,isAsync:ne,get util(){return S},get objectUtil(){return M},ZodParsedType:F,getParsedType:L,ZodType:le,datetimeRegex:Oe,ZodString:Ae,ZodNumber:je,ZodBigInt:Pe,ZodBoolean:Re,ZodDate:$e,ZodSymbol:Fe,ZodUndefined:Le,ZodNull:Ue,ZodAny:De,ZodUnknown:ze,ZodNever:Ve,ZodVoid:qe,ZodArray:Ke,ZodObject:Je,ZodUnion:We,ZodDiscriminatedUnion:Ge,ZodIntersection:Qe,ZodTuple:Xe,ZodRecord:et,ZodMap:tt,ZodSet:st,ZodFunction:at,ZodLazy:nt,ZodLiteral:it,ZodEnum:ot,ZodNativeEnum:dt,ZodPromise:ct,ZodEffects:ut,ZodTransformer:ut,ZodOptional:lt,ZodNullable:pt,ZodDefault:ht,ZodCatch:mt,ZodNaN:ft,BRAND:gt,ZodBranded:yt,ZodPipeline:vt,ZodReadonly:_t,custom:wt,Schema:le,ZodSchema:le,late:It,get ZodFirstPartyTypeKind(){return kt},coerce:is,any:jt,array:Ft,bigint:St,boolean:Ot,date:Mt,discriminatedUnion:zt,effect:es,enum:Ht,function:Wt,instanceof:(e,t={message:`Input not instance of ${e.name}`})=>wt((t=>t instanceof e),t),intersection:Vt,lazy:Yt,literal:Gt,map:Bt,nan:Nt,nativeEnum:Qt,never:Rt,null:Et,nullable:ss,number:Tt,object:Lt,oboolean:()=>Ot().optional(),onumber:()=>Tt().optional(),optional:ts,ostring:()=>Ct().optional(),pipeline:ns,preprocess:as,promise:Xt,record:Kt,set:Jt,strictObject:Ut,string:Ct,symbol:Zt,transformer:es,tuple:qt,undefined:At,union:Dt,unknown:Pt,void:$t,NEVER:rs,ZodIssueCode:U,quotelessJson:e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ZodError:D}),ds=os.object({type:os.enum(["sqlite","postgresql","mysql"]).default("sqlite"),connection:os.object({url:os.string().default("./session/zaileys.db")}).optional().default({})}).optional().default({}),cs=os.record(os.function().returns(os.union([os.number().array(),os.promise(os.number().array())]))).optional().transform((async e=>{if(!e)return{};const t={};for(const[s,a]of Object.entries(e)){t[`is${s.charAt(0).toUpperCase()}${s.slice(1)}`]=await a()}return t})),us=os.object({prefix:os.string().optional(),ignoreMe:os.boolean().optional().default(!0),showLogs:os.boolean().optional().default(!0),autoMentions:os.boolean().optional().default(!0),autoOnline:os.boolean().optional().default(!0),autoRead:os.boolean().optional().default(!0),autoPresence:os.boolean().optional().default(!0),autoRejectCall:os.boolean().optional().default(!0),database:ds,citation:cs}),ls=os.object({authType:os.literal("pairing"),phoneNumber:os.number()}).extend(us.shape),ps=os.object({authType:os.literal("qr"),phoneNumber:os.undefined().optional()}).extend(us.shape),hs=os.discriminatedUnion("authType",[ls,ps]),ms=(e="")=>{try{return JSON.parse(e)}catch{return JSON.parse(JSON.stringify(e))}},fs=(e={})=>{try{return JSON.stringify(e)}catch{return JSON.stringify(JSON.parse(JSON.stringify(e)))}},gs=(e="",t="")=>e?e.toLowerCase().includes(t.toLowerCase()):null,ys=(e,t)=>e&&"object"==typeof e?Array.isArray(e)?e.map((e=>ys(e,t))):Object.fromEntries(Object.entries(e).filter((([e])=>!t.includes(e))).map((([e,s])=>[e,"object"==typeof s?ys(s,t):s]))):e,vs={text:"text",conversation:"text",imageMessage:"image",contactMessage:"contact",locationMessage:"location",documentMessage:"document",audioMessage:"audio",videoMessage:"video",protocolMessage:"protocol",contactsArrayMessage:"contactsArray",highlyStructuredMessage:"highlyStructured",sendPaymentMessage:"sendPayment",liveLocationMessage:"liveLocation",requestPaymentMessage:"requestPayment",declinePaymentRequestMessage:"declinePaymentRequest",cancelPaymentRequestMessage:"cancelPaymentRequest",templateMessage:"template",stickerMessage:"sticker",groupInviteMessage:"groupInvite",templateButtonReplyMessage:"templateButtonReply",productMessage:"product",deviceSentMessage:"deviceSent",listMessage:"list",viewOnceMessage:"viewOnce",orderMessage:"order",listResponseMessage:"listResponse",ephemeralMessage:"ephemeral",invoiceMessage:"invoice",buttonsMessage:"buttons",buttonsResponseMessage:"buttonsResponse",paymentInviteMessage:"paymentInvite",interactiveMessage:"interactive",reactionMessage:"reaction",stickerSyncRmrMessage:"sticker",interactiveResponseMessage:"interactiveResponse",pollCreationMessage:"pollCreation",pollUpdateMessage:"pollUpdate",keepInChatMessage:"keepInChat",documentWithCaptionMessage:"document",requestPhoneNumberMessage:"requestPhoneNumber",viewOnceMessageV2:"viewOnce",encReactionMessage:"reaction",editedMessage:"text",viewOnceMessageV2Extension:"viewOnce",pollCreationMessageV2:"pollCreation",scheduledCallCreationMessage:"scheduledCallCreation",groupMentionedMessage:"groupMentioned",pinInChatMessage:"pinInChat",pollCreationMessageV3:"pollCreation",scheduledCallEditMessage:"scheduledCallEdit",ptvMessage:"ptv",botInvokeMessage:"botInvoke",callLogMesssage:"callLog",encCommentMessage:"encComment",bcallMessage:"bcall",lottieStickerMessage:"lottieSticker",eventMessage:"event",commentMessage:"comment",newsletterAdminInviteMessage:"text",extendedTextMessageWithParentKey:"text",extendedTextMessage:"text",placeholderMessage:"placeholder",encEventUpdateMessage:"encEventUpdate"},_s={whatsapp:"0@s.whatsapp.net",meta:"13135550002@s.whatsapp.net",chatgpt:"18002428478@s.whatsapp.net",copilot:"18772241042@s.whatsapp.net",instagram:"447723442971@s.whatsapp.net",tiktok:"6285574670498@s.whatsapp.net"},bs=os.enum(["text","text","image","contact","location","document","audio","video","protocol","contactsArray","highlyStructured","sendPayment","liveLocation","requestPayment","declinePaymentRequest","cancelPaymentRequest","template","sticker","groupInvite","templateButtonReply","product","deviceSent","list","viewOnce","order","listResponse","ephemeral","invoice","buttons","buttonsResponse","paymentInvite","interactive","reaction","sticker","interactiveResponse","pollCreation","pollUpdate","keepInChat","document","requestPhoneNumber","viewOnce","reaction","text","viewOnce","pollCreation","scheduledCallCreation","groupMentioned","pinInChat","pollCreation","scheduledCallEdit","ptv","botInvoke","callLog","encComment","bcall","lottieSticker","event","comment","text","text","placeholder","encEventUpdate"]),ws=os.enum(["unknown","android","ios","desktop","web"]),ks=os.object({chatId:os.string(),channelId:os.string(),receiverId:os.string(),receiverName:os.string(),roomId:os.string(),roomName:os.string(),senderId:os.string(),senderName:os.string(),senderDevice:ws,chatType:bs,timestamp:os.number(),mentions:os.string().array(),text:os.string().nullable(),links:os.string().array(),isPrefix:os.boolean(),isFromMe:os.boolean(),isTagMe:os.boolean(),isGroup:os.boolean(),isStory:os.boolean(),isViewOnce:os.boolean(),isEdited:os.boolean(),isDeleted:os.boolean(),isPinned:os.boolean(),isUnPinned:os.boolean(),isChannel:os.boolean(),isBroadcast:os.boolean(),isEphemeral:os.boolean(),isForwarded:os.boolean(),citation:os.record(os.string(),os.boolean()).nullable(),media:os.object({buffer:os.function().returns(os.unknown()),stream:os.function().returns(os.unknown())}).passthrough().nullable(),message:os.function().returns(os.record(os.string(),os.any()))});ks.extend({replied:ks.nullable()});var xs=class{constructor(e,t,s){this.socket=e,this.client=t,this.db=s}maxReplies=0;async connection(e){const{connection:t,lastDisconnect:s,qr:a}=e;if(this.client.startSpinner("connection","Connecting to WhatsApp..."),this.client.emit("connection",{status:"connecting"}),"qr"===this.client.options?.authType&&a)return this.client.stopSpinner("connection",!1),this.client.startSpinner("qr","Waiting for QR code scan..."),void this.socket?.ev.on("connection.update",(()=>this.client.stopSpinner("qr",!1)));if("close"===t){this.client.failSpinner("connection","Connection closed");const e=s?.error?.output?.statusCode,t=e!==n.loggedOut;if(console.log(s?.error?.message),401===e||405===e||500===e)return;t&&this.client.options&&await this.client.initialize()}else"open"===t&&(this.client.stopSpinner("connection",!0,"Connected to WhatsApp\n"),this.client.emit("connection",{status:"open"}))}async messages(e,t){if(e?.messageStubType||e?.messageStubParameters?.length||e?.message?.protocolMessage?.peerDataOperationRequestResponseMessage||e?.message?.botInvokeMessage||!e?.key?.id||!e?.message)return null;if(this.client.options?.ignoreMe&&e?.key?.fromMe&&"status@broadcast"!=e?.key?.remoteJid&&!e?.participant)return null;this.client.options?.autoRead&&await this.socket.readMessages([e?.key]);const s=e,n=e?.message?.pinInChatMessage?.key?.id,d=1==e?.message?.pinInChatMessage?.type,c=2==e?.message?.pinInChatMessage?.type;if(n){const t=await this.db.selectFrom("messages").select("value").where("id","=",n).executeTakeFirst(),s=ms(t?.value);e=s}const u=!e?.message?.protocolMessage?.editedMessage&&e?.message?.protocolMessage?.key?.id,l=!!u;if(u){const t=await this.db.selectFrom("messages").select("value").where("id","=",u).executeTakeFirst(),s=ms(t?.value);e=s}const p={},h=i(e?.message?.protocolMessage?.editedMessage||e?.message);p.chatId=e?.message?.protocolMessage?.key?.id||e?.key?.id,p.channelId="",p.receiverId=a(this.socket.user?.id),p.receiverName=this.socket.user?.name||this.socket.user?.verifiedName,p.roomId=a(e?.key?.remoteJid);const m=await this.db.selectFrom("chats").select("value").where("id","=",p.roomId).executeTakeFirst();p.roomName=ms(m?.value)?.name,p.senderId=a(e?.participant||e?.key?.participant||e?.key?.remoteJid);const f=await this.db.selectFrom("chats").select("value").where("id","=",p.senderId).executeTakeFirst();p.senderName=e?.pushName||e?.verifiedBizName||ms(f?.value)?.name||p.receiverName,p.roomName=p.roomName||p.senderName,p.senderDevice=r(p.chatId),p.chatType=vs[h],p.timestamp=e?.messageTimestamp?.low||e?.messageTimestamp||0,p.mentions=[],p.text=null,p.links=[],p.isPrefix=!1,p.isFromMe=e?.key?.fromMe,p.isTagMe=!1,p.isGroup=p.roomId.includes("@g.us"),p.isStory=p.roomId.includes("@broadcast"),p.isViewOnce=!1,p.isEdited=!1,p.isDeleted=l,p.isPinned=d,p.isUnPinned=c,p.isChannel=p.roomId.includes("@newsletter"),p.isBroadcast=!!e?.broadcast,p.isEphemeral=!1,p.isForwarded=!1,p.citation=null,p.media=null,p.replied=null,p.channelId=p.roomId.split("@")[0]+"-"+p.senderId.split("@")[0];const g=this.client.options?.citation;if(Object.keys(g).length){p.citation={};for(const e of Object.keys(g))p.citation[e]=g[e].includes(Number(p.senderId.split("@")[0]))||g[e].includes(Number(p.roomId.split("@")[0]))}const y=(e?.message?.protocolMessage?.editedMessage?.[h]||e?.message[h])?.message?.documentMessage||e?.message[h];"text"!=p.chatType&&(p.media={...ys(y,["url","contextInfo","fileSha256","fileEncSha256","mediaKey","directPath","waveform","thumbnail","jpegThumbnail","thumbnailEncSha256","thumbnailSha256","thumbnailDirectPath","firstFrameSidecar","streamingSidecar","scansSidecar","callKey","midQualityFileSha256"]),buffer:async()=>await o(e,"buffer",{}),stream:async()=>await o(e,"stream",{})});const v=e?.message?.[h]?.contextInfo?.stanzaId;if(v&&this.maxReplies<1){this.maxReplies++;const t=await this.db.selectFrom("messages").select("value").where("id","=",v).executeTakeFirst(),s=ms(t?.value);if(s)p.replied=await this.messages(s,!0);else{const t=e,s=i(t.message?.extendedTextMessage?.contextInfo.quotedMessage);t.key.id=t.message?.extendedTextMessage?.contextInfo.stanzaId,t.message[s]=t.message?.extendedTextMessage?.contextInfo.quotedMessage[s],delete t.message?.extendedTextMessage,p.replied=await this.messages(t,!0)}}const _="string"==typeof y?y:y?.text||y?.caption||y?.name||y?.displayName||"";p.text=((e="")=>e?e.replace(/\u202E([\s\S]*?)\u202C/g,((e,t)=>Array.from(t).reverse().join(""))).replace(/[\u202A-\u202E\u202C]/g,""):null)(_)||null,p.mentions=((e="")=>{if(!e)return[];const t=new Set;for(const s of e.matchAll(/@(\d+)/g))t.add(s[1]);return[...t]})(p.text),p.links=((e="")=>e&&e.match(/(?:https?:\/\/)?[^\s<>"']+\.[^\s<>"']+/g)||[])(p.text);const b=e?.message?.[h];return p.isPrefix=!!this.client.options?.prefix&&!!p.text?.startsWith(this.client.options?.prefix),p.isTagMe=p.mentions.includes(p.receiverId.split("@")[0]),p.isEdited=gs(fs(e),"editedMessage"),p.isEphemeral=gs(fs(b?.contextInfo),"ephemeralSettingTimestamp"),p.isForwarded=gs(fs(b?.contextInfo),"forwardingScore"),p.isViewOnce=!!b?.viewOnce,p.message=()=>s,t||this.client.emit("messages",p),p}async calls(e){this.client.options?.autoRejectCall&&await this.socket.rejectCall(e.id,e.from);const t={};t.callId=e.id,t.roomId=e.chatId,t.callerId=e.from,t.date=e.date,t.offline=e.offline,t.status=e.status,t.isVideo=!!e.isVideo,t.isGroup=!!e.isGroup,this.client.emit("calls",t)}},Is=os.union([os.string().url(),os.instanceof(Buffer).or(os.instanceof(N))]),Cs=os.union([os.string(),os.object({image:Is,text:os.string().optional()}),os.object({video:Is,text:os.string().optional()}),os.object({videoNote:Is}),os.object({gif:Is,text:os.string().optional()}),os.object({audio:Is}),os.object({audioNote:Is}),os.object({sticker:Is})]),Ts=os.object({roomId:os.string(),asForwarded:os.boolean().optional(),asViewOnce:os.boolean().optional(),verifiedReply:os.enum(["whatsapp","meta","chatgpt","copilot","instagram","tiktok"]).optional(),quoted:os.function().returns(os.record(os.string(),os.any())).optional()}),Ns=Ts,Ss=os.object({latitude:os.number(),longitude:os.number(),title:os.string().optional(),footer:os.string().optional()}),Os=Ts,Ms=os.object({fullname:os.string(),nickname:os.string().optional(),organization:os.string().optional(),role:os.string().optional(),email:os.string().email().optional(),whatsAppNumber:os.number(),callNumber:os.number().optional(),voiceNumber:os.number().optional(),website:os.string().url().optional(),homeAddress:os.string().optional(),workAddress:os.string().optional(),avatar:os.string().url().optional()}),Zs=Ts.pick({roomId:!0}).merge(os.object({message:os.function().returns(os.record(os.string(),os.any()))})),As=os.string(),Es=Ts.pick({roomId:!0}).merge(os.object({message:os.function().returns(os.record(os.string(),os.any()))})),js=os.object({action:os.enum(["pin","unpin"]),expired:os.enum(["24h","7d","30d"])}),Ps=Ts.pick({roomId:!0}),Rs=os.object({name:os.string(),answers:os.string().array(),multipleAnswers:os.boolean().optional()}),$s=Ts.pick({roomId:!0}).merge(os.object({message:os.function().returns(os.record(os.string(),os.any()))})),Fs=os.string(),Ls=Ts.pick({roomId:!0}),Us=os.object({message:os.function().returns(os.record(os.string(),os.any()))}),Ds=os.object({callId:os.string(),callerId:os.string()}),zs=Ts.pick({roomId:!0}),Vs=os.object({expired:os.enum(["remove","8h","7d"])}),qs=os.string();os.object({type:os.enum(["group","user"]),id:os.string(),name:os.string(),bio:os.string(),avatar:os.string().url(),ephemeralDuration:os.number().optional(),isRestrict:os.boolean().optional(),isAnnounce:os.boolean().optional(),isCommunity:os.boolean().optional(),isCommunityAnnounce:os.boolean().optional(),isJoinApprovalMode:os.boolean().optional(),isMemberAddMode:os.boolean().optional(),owner:os.object({type:os.literal("user"),id:os.string()}).nullable(),roomCreatedAt:os.number().optional(),nameUpdatedAt:os.number().optional(),bioUpdatedAt:os.number().optional(),membersLength:os.number().optional(),members:os.object({type:os.enum(["user","admin","superadmin"]),id:os.string()}).array().optional()});var Ks=Ts.pick({roomId:!0}),Bs=os.enum(["typing","recording","online","offline","paused"]),Js=class{constructor(e){this.wa=e}async sendMessage(e,t,s){let a=[];this.wa.client.options?.autoMentions&&(a=((e="")=>{if(!e)return[];const t=new Set;for(const s of e.matchAll(/@(\d+)/g))t.add(s[1]);return[...t].flatMap((e=>[`${e}@s.whatsapp.net`,`${e}@g.us`]))})(t?.text||t?.caption)),this.wa.client.options?.autoPresence&&this.wa.socket?.sendPresenceUpdate("composing",e),this.wa.client.options?.autoPresence&&t?.audio&&this.wa.socket?.sendPresenceUpdate("recording",e);const n=t,i={contextInfo:{isForwarded:!!n?.asForwarded}};if("function"==typeof n?.quoted){let t=n?.quoted();t.key.participant=_s[n?.verifiedReply]||t.key.participant;const r=await(this.wa.socket?.sendMessage(e,{...n,mentions:a,...i},{quoted:t,...s}));return await new xs(this.wa.socket,this.wa.client,this.wa.db).messages(r)}{const t=await(this.wa.socket?.sendMessage(e,{...n,mentions:a,...i},s));return await new xs(this.wa.socket,this.wa.client,this.wa.db).messages(t)}}async text(e,t){if(e=Cs.parse(e),t=Ts.parse(t),"string"==typeof e)return await this.sendMessage(t.roomId,{text:e,...t});if("object"==typeof e){const s=Object.keys(e),a=e;if(s.includes("image")){const e="string"==typeof a.image?{url:a.image}:a.image;return await this.sendMessage(t.roomId,{caption:a?.text,image:e,viewOnce:!!t.asViewOnce,...t})}if(s.includes("video")){const e="string"==typeof a.video?{url:a.video}:a.video;return await this.sendMessage(t.roomId,{caption:a?.text,video:e,ptv:!1,viewOnce:!!t.asViewOnce,...t})}if(s.includes("videoNote")){const e="string"==typeof a.videoNote?{url:a.videoNote}:a.videoNote;return await this.sendMessage(t.roomId,{caption:a?.text,video:e,ptv:!0,...t})}if(s.includes("gif")){const e="string"==typeof a.gif?{url:a.gif}:a.gif;return await this.sendMessage(t.roomId,{caption:a?.text,video:e,gifPlayback:!0,viewOnce:!!t.asViewOnce,...t})}if(s.includes("audio")){const e="string"==typeof a.audio?{url:a.audio}:a.audio;return await this.sendMessage(t.roomId,{caption:a?.text,audio:e,viewOnce:!!t.asViewOnce,...t})}if(s.includes("audioNote")){const e="string"==typeof a.audioNote?{url:a.audioNote}:a.audioNote;return await this.sendMessage(t.roomId,{caption:a?.text,audio:e,ptt:!0,viewOnce:!!t.asViewOnce,...t})}if(s.includes("sticker")){const e="string"==typeof a.sticker?{url:a.sticker}:a.sticker;return await this.sendMessage(t.roomId,{caption:a?.text,sticker:e,...t})}}}async location(e,t){return e=Ss.parse(e),t=Ns.parse(t),await this.sendMessage(t.roomId,{location:{degreesLatitude:e.latitude,degreesLongitude:e.longitude,url:e.title,address:e.footer,name:e.title},...t})}async contact(e,t){e=Ms.parse(e),t=Os.parse(t);const s=["BEGIN:VCARD","VERSION:3.0",`N:;${e.fullname};;;`,`FN:${e.fullname}`,e.nickname?`NICKNAME:${e.nickname}`:"",e.organization||e.role?`ORG:${e.organization??""};`:"",e.role?`TITLE:${e.role}`:"",`TEL;TYPE=CELL,VOICE;waid=${e.whatsAppNumber}:+${e.whatsAppNumber}`,e.callNumber?`TEL;TYPE=WORK,VOICE:+${e.callNumber}`:"",e.voiceNumber?`TEL;TYPE=VOICE:+${e.voiceNumber}`:"",e.email?`EMAIL;TYPE=INTERNET:${e.email}`:"",e.website?`URL;TYPE=WORK:${e.website}`:"",e.homeAddress?`ADR;TYPE=HOME:;;${e.homeAddress};;;;`:"",e.workAddress?`ADR;TYPE=WORK:;;${e.workAddress};;;;`:"",e.avatar?`PHOTO;VALUE=URI;TYPE=JPEG:${e.avatar}`:"","END:VCARD"].join("\n");return await this.sendMessage(t.roomId,{contacts:{displayName:e.fullname,contacts:[{vcard:s}]},...t})}async reaction(e,t){return e=As.parse(e),t=Zs.parse(t),await this.sendMessage(t.roomId,{react:{text:e,key:t.message()?.key},...t})}async pin(e,t){e=js.parse(e),t=Es.parse(t);return await this.sendMessage(t.roomId,{pin:{type:"pin"==e.action?1:0,time:{"24h":86400,"7d":604800,"30d":2592e3}[e.expired],key:t.message()?.key},...t})}async poll(e,t){return e=Rs.parse(e),t=Ps.parse(t),await this.sendMessage(t.roomId,{poll:{name:e.name,values:e.answers,selectableCount:e.multipleAnswers?1:0,toAnnouncementGroup:!0},...t})}async edit(e,t){return e=Fs.parse(e),t=$s.parse(t),await this.sendMessage(t.roomId,{text:e,edit:t.message()?.key,...t})}async delete(e,t){return e=Us.parse(e),t=Ls.parse(t),await this.sendMessage(t.roomId,{delete:e.message()?.key,...t})}async rejectCall(e){return e=Ds.parse(e),await(this.wa.socket?.rejectCall(e.callId,e.callerId))}async mute(e,t){e=Vs.parse(e),t=zs.parse(t);return await(this.wa.socket?.chatModify({mute:{remove:null,"8h":864e5,"7d":6048e5}[e.expired]},t.roomId))}async profile(e){const t=(e=qs.parse(e)).includes("@g.us"),s={};s.id=e;if(a(this.wa.socket?.user?.id)==e)s.name=this.wa.socket?.user?.name||this.wa.socket?.user?.verifiedName;else if(t){const t=await(this.wa.socket?.groupMetadata(e));s.type="group",s.name=t?.subject,s.bio=t?.desc,s.avatar=await(this.wa.socket?.profilePictureUrl(e)),s.ephemeralDuration=t?.ephemeralDuration,s.isRestrict=t?.restrict,s.isAnnounce=t?.announce,s.isCommunity=t?.isCommunity,s.isCommunityAnnounce=t?.isCommunityAnnounce,s.isJoinApprovalMode=t?.joinApprovalMode,s.isMemberAddMode=t?.memberAddMode,s.owner={type:"user",id:t?.owner},s.roomCreatedAt=t?.creation,s.nameUpdatedAt=t?.subjectTime,s.membersLength=t?.size,s.members=t?.participants.map((e=>({id:e.id,type:"admin"==e.admin||"superadmin"==e.admin?e.admin:"user"})))}else{const t=await(this.wa.db?.selectFrom("chats").select("value").where("id","=",e).executeTakeFirst()),a=ms(t?.value),n=(await(this.wa?.socket?.fetchStatus(e)))[0]?.status;s.type="user",s.name=a?.name,s.bio=n?.status,s.avatar=await(this.wa?.socket?.profilePictureUrl(e)),s.bioUpdatedAt=new Date(n?.setAt).getTime()}return s}async presence(e,t){e=Bs.parse(e),t=Ks.parse(t);return await(this.wa.socket?.sendPresenceUpdate({typing:"composing",recording:"recording",online:"available",offline:"unavailable",paused:"paused"}[e],t.roomId))}},Ws=class{constructor(e){return this.props=e,this.initialize(),this.worker,new Proxy(this,{get:(e,t)=>t in e?e[t]:e.worker[t]})}options;chatId="zaileys-chats";logger=p({level:"silent",enabled:!1});db;socket;groupCache=new u({stdTTL:300,useClones:!1});events=new d;spinners=new Map;worker;async initialize(){console.clear(),await((e="ZAILEYS")=>new Promise((t=>{c(e,((e,s)=>{if(e)return t("");console.log(s),t(s||"")}))})))(),this.options=await hs.parseAsync(this.props),this.startSpinner("db","Initializing database..."),this.db=((e,t)=>{if("sqlite"===e){const e=t||"./db/zaileys.db",s=w.resolve(e);return m(w.dirname(s),{recursive:!0}),f(s,"",{flag:"a"}),new g({dialect:new y({database:new h(s)})})}const s=new x(t),a=s.protocol.replace(":","");if("mysql"===e)return new g({dialect:new v({pool:b.createPool({host:s.hostname,user:s.username,password:s.password,database:s.pathname.replace("/",""),port:parseInt(s.port||"3306",10)})})});if("postgresql"===e)return new g({dialect:new _({pool:new k({host:s.hostname,user:s.username,password:s.password,database:s.pathname.replace("/",""),port:parseInt(s.port||"5432",10)})})});throw new Error(`Unsupported database protocol: ${a}`)})(this.options.database.type,this.options.database.connection.url),this.stopSpinner("db",!0,"Database initialized"),this.startSpinner("auth","Setting up auth adapter...");const{state:a,saveCreds:n}=await $(this.db,this.chatId);this.stopSpinner("auth",!0,"Auth adapter ready"),this.startSpinner("store","Setting up store adapter...");const i=await(async(e,t)=>({bind:s=>{s.on("messaging-history.set",(async s=>{const{chats:a,contacts:n,messages:i}=s;for(const s of a)await e.insertInto("chats").values({session:t,id:s.id,value:JSON.stringify(s)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(s)}))).execute();for(const s of n)await e.insertInto("contacts").values({session:t,id:s.id,value:JSON.stringify(s)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(s)}))).execute();for(const s of i){if(!s.message)return;if(s.message?.protocolMessage)return;await e.insertInto("messages").values({session:t,id:s.key.id,value:JSON.stringify(s)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(s)}))).execute()}})),s.on("messages.upsert",(async({messages:s})=>{for(const a of s){if(!a.message)return;if(a.message?.protocolMessage)return;await e.insertInto("messages").values({session:t,id:a.key.id,value:JSON.stringify(a)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(a)}))).execute()}})),s.on("chats.upsert",(async s=>{for(const a of s)await e.insertInto("chats").values({session:t,id:a.id,value:JSON.stringify(a)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(a)}))).execute()})),s.on("contacts.upsert",(async s=>{for(const a of s)await e.insertInto("contacts").values({session:t,id:a.id,value:JSON.stringify(a)}).onConflict((e=>e.columns(["session","id"]).doUpdateSet({value:JSON.stringify(a)}))).execute()}))}}))(this.db,this.chatId);if(this.stopSpinner("store",!0,"Store adapter ready"),this.socket=e({logger:this.logger,markOnlineOnConnect:this.options.autoOnline,syncFullHistory:!1,defaultQueryTimeoutMs:void 0,msgRetryCounterCache:new u,cachedGroupMetadata:async e=>this.groupCache.get(e),printQRInTerminal:"qr"===this.options.authType,browser:s.ubuntu("qr"===this.options.authType?"Zaileys Library":"Firefox"),auth:{creds:a.creds,keys:t(a.keys,this.logger)}}),"pairing"===this.options.authType&&this.options.phoneNumber&&!this.socket?.authState.creds.registered){this.startSpinner("pairing","Generating pairing code...");(await this.socket.onWhatsApp(this.options.phoneNumber.toString()+"@s.whatsapp.net"))[0].exists||(this.failSpinner("pairing","Phone is not registered in WhatsApp"),process.exit(1)),setTimeout((async()=>{try{if("pairing"===this.options?.authType){const e=await(this.socket?.requestPairingCode(this.options.phoneNumber.toString()));this.stopSpinner("pairing",!0,`Pairing code: ${e}`)}}catch{this.failSpinner("pairing","Connection failed"),process.exit(1)}}),5e3)}this.socket?.ev.on("creds.update",n),i.bind(this.socket?.ev),this.worker=new Js({client:this,db:this.db,socket:this.socket}),this.socket.ev.on("connection.update",(async e=>{await new xs(this.socket,this,this.db).connection(e)})),this.socket.ev.on("messages.upsert",(async({messages:e})=>{for(const t of e)await new xs(this.socket,this,this.db).messages(t)})),this.socket.ev.on("call",(async e=>{for(const t of e)await new xs(this.socket,this,this.db).calls(t)}))}startSpinner(e,t){let s=this.spinners.get(e);return s||(s=l(t).start(),this.spinners.set(e,s)),s}stopSpinner(e,t,s){const a=this.spinners.get(e);a&&(t?a.succeed(s):a.stop(),this.spinners.delete(e))}failSpinner(e,t){const s=this.spinners.get(e);s&&(s.fail(t),this.spinners.delete(e))}on(e,t){this.events.on(e,t)}emit(e,...t){this.events.emit(e,...t)}};export{Ws as default};
package/package.json CHANGED
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "name": "zaileys",
3
- "version": "0.29.18-beta",
3
+ "version": "0.29.20",
4
4
  "description": "Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API",
5
- "main": "dist/index.js",
6
- "module": "dist/index.esm.js",
5
+ "main": "dist/index.cjs",
6
+ "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "scripts": {
9
9
  "build": "tsup",
10
- "dev": " npm run dev:test",
11
- "dev:test": "npx tsx watch test/example.ts",
12
- "clean": "rimraf dist"
10
+ "dev": "npx tsx watch test/example.ts",
11
+ "clean": "rm -rf dist session"
13
12
  },
14
13
  "keywords": [
15
14
  "zaileys",
@@ -43,21 +42,7 @@
43
42
  },
44
43
  "license": "MIT",
45
44
  "devDependencies": {
46
- "@rollup/plugin-commonjs": "^24.0.0",
47
- "@rollup/plugin-json": "^6.1.0",
48
- "@rollup/plugin-node-resolve": "^15.0.0",
49
- "@rollup/plugin-typescript": "^12.0.0",
50
- "@types/better-sqlite3": "^7.6.13",
51
- "@types/pg": "^8.15.1",
52
- "@types/qrcode-terminal": "^0.12.2",
53
- "rimraf": "^5.0.0",
54
- "rollup": "^3.0.0",
55
- "rollup-plugin-dts": "^5.0.0",
56
- "rollup-plugin-esbuild": "^6.2.1",
57
- "rollup-plugin-gzip": "^4.0.1",
58
- "rollup-plugin-multi-input": "^1.5.0",
59
- "rollup-plugin-strip": "^1.2.2",
60
- "rollup-plugin-terser": "^7.0.0",
45
+ "@types/figlet": "^1.7.0",
61
46
  "tsup": "^8.4.0",
62
47
  "tsx": "^4.19.4",
63
48
  "typescript": "^5.0.0",
@@ -66,14 +51,16 @@
66
51
  "dependencies": {
67
52
  "baileys": "^6.7.16",
68
53
  "better-sqlite3": "^11.10.0",
54
+ "events": "^3.3.0",
55
+ "figlet": "^1.8.1",
69
56
  "jimp": "^1.6.0",
70
57
  "kysely": "^0.28.2",
71
58
  "libsignal": "^2.0.1",
72
59
  "mysql2": "^3.14.1",
73
60
  "node-cache": "^5.1.2",
61
+ "ora": "^8.2.0",
74
62
  "pg": "^8.15.6",
75
63
  "pino": "^9.6.0",
76
- "qrcode-terminal": "^0.12.0",
77
- "sharp": "^0.34.1"
64
+ "qrcode-terminal": "^0.12.0"
78
65
  }
79
66
  }