zaileys 0.29.17-beta → 0.29.18-beta
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.cjs +1 -0
- package/dist/{types/classes/client.d.ts → index.d.mts} +83 -22
- package/dist/index.mjs +1 -0
- package/package.json +10 -6
- package/dist/classes/Client.d.ts +0 -17
- package/dist/classes/Event.d.ts +0 -12
- package/dist/classes/Parser.d.ts +0 -3
- package/dist/database/handler.d.ts +0 -12
- package/dist/database/schema.d.ts +0 -63
- package/dist/helpers/adapter.d.ts +0 -57
- package/dist/helpers/error.d.ts +0 -8
- package/dist/index.esm.js +0 -2
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +0 -1
- package/dist/types/adapter/general.d.ts +0 -156
- package/dist/types/classes/event.d.ts +0 -65
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=require("baileys"),t=require("node-cache"),a=require("pino"),s=require("better-sqlite3"),n=require("fs"),r=require("kysely"),i=require("mysql2"),o=require("path"),d=require("pg"),c=require("url"),u=require("crypto"),l=require("libsignal");function h(e){return e&&e.__esModule?e:{default:e}}var p,m,f,y=h(e),v=h(t),g=h(a),_=h(s),x=h(i),b=h(o),k=l.curve,w=()=>{const{pubKey:e,privKey:t}=k.generateKeyPair();return{private:Buffer.from(t),public:Buffer.from(e.slice(1))}},Z=(e,t)=>{const a=w(),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,k.calculateSignature(n,r)),keyId:t}},T=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},C=(e,t)=>"Buffer"===t?.type&&Array.isArray(t?.data)?{type:"Buffer",data:Buffer.from(t?.data).toString("base64")}:t,N=(e,t)=>"Buffer"===t?.type?Buffer.from(t?.data,"base64"):t,O=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,N)},r=async(n,r)=>{const i=JSON.stringify(r,C);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=w();return{noiseKey:w(),pairingEphemeralKeyPair:w(),signedIdentityKey:e,signedPreKey:Z(e,1),registrationId:16383&Uint16Array.from(u.randomBytes(2))[0],advSecretKey:u.randomBytes(32).toString("base64"),processedHistoryMessages:[],nextPreKeyId:1,firstUnuploadedPreKeyId:1,accountSyncCounter:0,accountSettings:{unarchiveChats:!1},deviceId:Buffer.from(u.randomUUID().replace(/-/g,""),"hex").toString("base64url"),phoneId:u.randomUUID(),identityId:u.randomBytes(20),backupToken:u.randomBytes(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=T(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()))})()}}};(m=p||(p={})).assertEqual=e=>e,m.assertIs=function(e){},m.assertNever=function(e){throw new Error},m.arrayToEnum=e=>{const t={};for(const a of e)t[a]=a;return t},m.getValidEnumValues=e=>{const t=m.objectKeys(e).filter((t=>"number"!=typeof e[e[t]])),a={};for(const s of t)a[s]=e[s];return m.objectValues(a)},m.objectValues=e=>m.objectKeys(e).map((function(t){return e[t]})),m.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},m.find=(e,t)=>{for(const a of e)if(t(a))return a},m.isInteger="function"==typeof Number.isInteger?e=>Number.isInteger(e):e=>"number"==typeof e&&isFinite(e)&&Math.floor(e)===e,m.joinValues=function(e,t=" | "){return e.map((e=>"string"==typeof e?`'${e}'`:e)).join(t)},m.jsonStringifyReplacer=(e,t)=>"bigint"==typeof t?t.toString():t,(f||(f={})).mergeShapes=(e,t)=>({...e,...t});var S=p.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),I=e=>{switch(typeof e){case"undefined":return S.undefined;case"string":return S.string;case"number":return isNaN(e)?S.nan:S.number;case"boolean":return S.boolean;case"function":return S.function;case"bigint":return S.bigint;case"symbol":return S.symbol;case"object":return Array.isArray(e)?S.array:null===e?S.null:e.then&&"function"==typeof e.then&&e.catch&&"function"==typeof e.catch?S.promise:"undefined"!=typeof Map&&e instanceof Map?S.map:"undefined"!=typeof Set&&e instanceof Set?S.set:"undefined"!=typeof Date&&e instanceof Date?S.date:S.object;default:return S.unknown}},A=p.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"]),E=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,p.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()}};E.create=e=>new E(e);var j=(e,t)=>{let a;switch(e.code){case A.invalid_type:a=e.received===S.undefined?"Required":`Expected ${e.expected}, received ${e.received}`;break;case A.invalid_literal:a=`Invalid literal value, expected ${JSON.stringify(e.expected,p.jsonStringifyReplacer)}`;break;case A.unrecognized_keys:a=`Unrecognized key(s) in object: ${p.joinValues(e.keys,", ")}`;break;case A.invalid_union:a="Invalid input";break;case A.invalid_union_discriminator:a=`Invalid discriminator value. Expected ${p.joinValues(e.options)}`;break;case A.invalid_enum_value:a=`Invalid enum value. Expected ${p.joinValues(e.options)}, received '${e.received}'`;break;case A.invalid_arguments:a="Invalid function arguments";break;case A.invalid_return_type:a="Invalid function return type";break;case A.invalid_date:a="Invalid date";break;case A.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}"`:p.assertNever(e.validation):a="regex"!==e.validation?`Invalid ${e.validation}`:"Invalid";break;case A.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 A.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 A.custom:a="Invalid input";break;case A.invalid_intersection_types:a="Intersection results could not be merged";break;case A.not_multiple_of:a=`Number must be a multiple of ${e.multipleOf}`;break;case A.not_finite:a="Number must be finite";break;default:a=t.defaultError,p.assertNever(e)}return{message:a}},P=j;function R(){return P}var $=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 M(e,t){const a=R(),s=$({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,a,a===j?void 0:j].filter((e=>!!e))});e.common.issues.push(s)}var F,D,U,L,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 z;"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 z;if("aborted"===n.status)return z;"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}}},z=Object.freeze({status:"aborted"}),K=e=>({status:"dirty",value:e}),B=e=>({status:"valid",value:e}),V=e=>"aborted"===e.status,J=e=>"dirty"===e.status,W=e=>"valid"===e.status,H=e=>"undefined"!=typeof Promise&&e instanceof Promise;function Y(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 G(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}(D=F||(F={})).errToObj=e=>"string"==typeof e?{message:e}:e||{},D.toString=e=>"string"==typeof e?e:null==e?void 0:e.message;var Q=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}},X=(e,t)=>{if(W(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 E(e.common.issues);return this._error=t,this._error}}};function ee(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 te,ae=class{get description(){return this._def.description}_getType(e){return I(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:I(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:I(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const t=this._parse(e);if(H(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:I(e)},n=this._parseSync({data:e,path:s.path,parent:s});return X(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:I(e)};if(!this["~standard"].async)try{const t=this._parseSync({data:e,path:[],parent:s});return W(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=>W(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:I(e)},s=this._parse({data:e,path:a.path,parent:a}),n=await(H(s)?s:Promise.resolve(s));return X(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:A.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 tt({schema:this,typeName:pt.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 at.create(this,this._def)}nullable(){return st.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return $e.create(this)}promise(){return et.create(this,this._def)}or(e){return De.create([this,e],this._def)}and(e){return ze.create(this,e,this._def)}transform(e){return new tt({...ee(this._def),schema:this,typeName:pt.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const t="function"==typeof e?e:()=>e;return new nt({...ee(this._def),innerType:this,defaultValue:t,typeName:pt.ZodDefault})}brand(){return new dt({typeName:pt.ZodBranded,type:this,...ee(this._def)})}catch(e){const t="function"==typeof e?e:()=>e;return new rt({...ee(this._def),innerType:this,catchValue:t,typeName:pt.ZodCatch})}describe(e){return new(0,this.constructor)({...this._def,description:e})}pipe(e){return ct.create(this,e)}readonly(){return ut.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}},se=/^c[^\s-]{8,}$/i,ne=/^[0-9a-z]+$/,re=/^[0-9A-HJKMNP-TV-Z]{26}$/i,ie=/^[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,oe=/^[a-z0-9_-]{21}$/i,de=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,ce=/^[-+]?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)?)??$/,ue=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,le=/^(?:(?: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])$/,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])\/(3[0-2]|[12]?[0-9])$/,pe=/^(([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]))$/,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]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,fe=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ye=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,ve="((\\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])))",ge=new RegExp(`^${ve}$`);function _e(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 xe(e){let t=`${ve}T${_e(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 be(e,t){if(!de.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 ke(e,t){return!("v4"!==t&&t||!he.test(e))||!("v6"!==t&&t||!me.test(e))}var we=class e extends ae{_parse(e){this._def.coerce&&(e.data=String(e.data));if(this._getType(e)!==S.string){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.string,received:t.parsedType}),z}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),M(a,{code:A.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),M(a,{code:A.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?M(a,{code:A.too_big,maximum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}):n&&M(a,{code:A.too_small,minimum:r.value,type:"string",inclusive:!0,exact:!0,message:r.message}),t.dirty())}else if("email"===r.kind)ue.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"email",code:A.invalid_string,message:r.message}),t.dirty());else if("emoji"===r.kind)te||(te=new RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$","u")),te.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"emoji",code:A.invalid_string,message:r.message}),t.dirty());else if("uuid"===r.kind)ie.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"uuid",code:A.invalid_string,message:r.message}),t.dirty());else if("nanoid"===r.kind)oe.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"nanoid",code:A.invalid_string,message:r.message}),t.dirty());else if("cuid"===r.kind)se.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"cuid",code:A.invalid_string,message:r.message}),t.dirty());else if("cuid2"===r.kind)ne.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"cuid2",code:A.invalid_string,message:r.message}),t.dirty());else if("ulid"===r.kind)re.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"ulid",code:A.invalid_string,message:r.message}),t.dirty());else if("url"===r.kind)try{new URL(e.data)}catch(s){a=this._getOrReturnCtx(e,a),M(a,{validation:"url",code:A.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),M(a,{validation:"regex",code:A.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),M(a,{code:A.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),M(a,{code:A.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),M(a,{code:A.invalid_string,validation:{endsWith:r.value},message:r.message}),t.dirty());else if("datetime"===r.kind){xe(r).test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{code:A.invalid_string,validation:"datetime",message:r.message}),t.dirty())}else if("date"===r.kind){ge.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{code:A.invalid_string,validation:"date",message:r.message}),t.dirty())}else if("time"===r.kind){new RegExp(`^${_e(r)}$`).test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{code:A.invalid_string,validation:"time",message:r.message}),t.dirty())}else"duration"===r.kind?ce.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"duration",code:A.invalid_string,message:r.message}),t.dirty()):"ip"===r.kind?(s=e.data,("v4"!==(n=r.version)&&n||!le.test(s))&&("v6"!==n&&n||!pe.test(s))&&(a=this._getOrReturnCtx(e,a),M(a,{validation:"ip",code:A.invalid_string,message:r.message}),t.dirty())):"jwt"===r.kind?be(e.data,r.alg)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"jwt",code:A.invalid_string,message:r.message}),t.dirty()):"cidr"===r.kind?ke(e.data,r.version)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"cidr",code:A.invalid_string,message:r.message}),t.dirty()):"base64"===r.kind?fe.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"base64",code:A.invalid_string,message:r.message}),t.dirty()):"base64url"===r.kind?ye.test(e.data)||(a=this._getOrReturnCtx(e,a),M(a,{validation:"base64url",code:A.invalid_string,message:r.message}),t.dirty()):p.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:A.invalid_string,...F.errToObj(a)})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}email(e){return this._addCheck({kind:"email",...F.errToObj(e)})}url(e){return this._addCheck({kind:"url",...F.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...F.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...F.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...F.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...F.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...F.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...F.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...F.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...F.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...F.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...F.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...F.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,...F.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,...F.errToObj(null==e?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...F.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...F.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:null==t?void 0:t.position,...F.errToObj(null==t?void 0:t.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...F.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...F.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...F.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...F.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...F.errToObj(t)})}nonempty(e){return this.min(1,F.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 Ze(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)}we.create=e=>{var t;return new we({checks:[],typeName:pt.ZodString,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...ee(e)})};var Te=class e extends ae{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)!==S.number){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.number,received:t.parsedType}),z}let t;const a=new q;for(const s of this._def.checks)if("int"===s.kind)p.isInteger(e.data)||(t=this._getOrReturnCtx(e,t),M(t,{code:A.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),M(t,{code:A.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),M(t,{code:A.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty())}else"multipleOf"===s.kind?0!==Ze(e.data,s.value)&&(t=this._getOrReturnCtx(e,t),M(t,{code:A.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):"finite"===s.kind?Number.isFinite(e.data)||(t=this._getOrReturnCtx(e,t),M(t,{code:A.not_finite,message:s.message}),a.dirty()):p.assertNever(s);return{status:a.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,F.toString(t))}gt(e,t){return this.setLimit("min",e,!1,F.toString(t))}lte(e,t){return this.setLimit("max",e,!0,F.toString(t))}lt(e,t){return this.setLimit("max",e,!1,F.toString(t))}setLimit(t,a,s,n){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:a,inclusive:s,message:F.toString(n)}]})}_addCheck(t){return new e({...this._def,checks:[...this._def.checks,t]})}int(e){return this._addCheck({kind:"int",message:F.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:F.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:F.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:F.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:F.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:F.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:F.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:F.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:F.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&&p.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)}};Te.create=e=>new Te({checks:[],typeName:pt.ZodNumber,coerce:(null==e?void 0:e.coerce)||!1,...ee(e)});var Ce=class e extends ae{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)!==S.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),M(t,{code:A.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),M(t,{code:A.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),M(t,{code:A.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):p.assertNever(s);return{status:a.value,value:e.data}}_getInvalidInput(e){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.bigint,received:t.parsedType}),z}gte(e,t){return this.setLimit("min",e,!0,F.toString(t))}gt(e,t){return this.setLimit("min",e,!1,F.toString(t))}lte(e,t){return this.setLimit("max",e,!0,F.toString(t))}lt(e,t){return this.setLimit("max",e,!1,F.toString(t))}setLimit(t,a,s,n){return new e({...this._def,checks:[...this._def.checks,{kind:t,value:a,inclusive:s,message:F.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:F.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:F.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:F.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:F.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:F.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}};Ce.create=e=>{var t;return new Ce({checks:[],typeName:pt.ZodBigInt,coerce:null!==(t=null==e?void 0:e.coerce)&&void 0!==t&&t,...ee(e)})};var Ne=class extends ae{_parse(e){this._def.coerce&&(e.data=Boolean(e.data));if(this._getType(e)!==S.boolean){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.boolean,received:t.parsedType}),z}return B(e.data)}};Ne.create=e=>new Ne({typeName:pt.ZodBoolean,coerce:(null==e?void 0:e.coerce)||!1,...ee(e)});var Oe=class e extends ae{_parse(e){this._def.coerce&&(e.data=new Date(e.data));if(this._getType(e)!==S.date){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.date,received:t.parsedType}),z}if(isNaN(e.data.getTime())){return M(this._getOrReturnCtx(e),{code:A.invalid_date}),z}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),M(a,{code:A.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),M(a,{code:A.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),t.dirty()):p.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:F.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:F.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}};Oe.create=e=>new Oe({checks:[],coerce:(null==e?void 0:e.coerce)||!1,typeName:pt.ZodDate,...ee(e)});var Se=class extends ae{_parse(e){if(this._getType(e)!==S.symbol){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.symbol,received:t.parsedType}),z}return B(e.data)}};Se.create=e=>new Se({typeName:pt.ZodSymbol,...ee(e)});var Ie=class extends ae{_parse(e){if(this._getType(e)!==S.undefined){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.undefined,received:t.parsedType}),z}return B(e.data)}};Ie.create=e=>new Ie({typeName:pt.ZodUndefined,...ee(e)});var Ae=class extends ae{_parse(e){if(this._getType(e)!==S.null){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.null,received:t.parsedType}),z}return B(e.data)}};Ae.create=e=>new Ae({typeName:pt.ZodNull,...ee(e)});var Ee=class extends ae{constructor(){super(...arguments),this._any=!0}_parse(e){return B(e.data)}};Ee.create=e=>new Ee({typeName:pt.ZodAny,...ee(e)});var je=class extends ae{constructor(){super(...arguments),this._unknown=!0}_parse(e){return B(e.data)}};je.create=e=>new je({typeName:pt.ZodUnknown,...ee(e)});var Pe=class extends ae{_parse(e){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.never,received:t.parsedType}),z}};Pe.create=e=>new Pe({typeName:pt.ZodNever,...ee(e)});var Re=class extends ae{_parse(e){if(this._getType(e)!==S.undefined){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.void,received:t.parsedType}),z}return B(e.data)}};Re.create=e=>new Re({typeName:pt.ZodVoid,...ee(e)});var $e=class e extends ae{_parse(e){const{ctx:t,status:a}=this._processInputParams(e),s=this._def;if(t.parsedType!==S.array)return M(t,{code:A.invalid_type,expected:S.array,received:t.parsedType}),z;if(null!==s.exactLength){const e=t.data.length>s.exactLength.value,n=t.data.length<s.exactLength.value;(e||n)&&(M(t,{code:e?A.too_big:A.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&&(M(t,{code:A.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&&(M(t,{code:A.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 Q(t,e,t.path,a))))).then((e=>q.mergeArray(a,e)));const n=[...t.data].map(((e,a)=>s.type._parseSync(new Q(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:F.toString(a)}})}max(t,a){return new e({...this._def,maxLength:{value:t,message:F.toString(a)}})}length(t,a){return new e({...this._def,exactLength:{value:t,message:F.toString(a)}})}nonempty(e){return this.min(1,e)}};function Me(e){if(e instanceof Fe){const t={};for(const a in e.shape){const s=e.shape[a];t[a]=at.create(Me(s))}return new Fe({...e._def,shape:()=>t})}return e instanceof $e?new $e({...e._def,type:Me(e.element)}):e instanceof at?at.create(Me(e.unwrap())):e instanceof st?st.create(Me(e.unwrap())):e instanceof Ke?Ke.create(e.items.map((e=>Me(e)))):e}$e.create=(e,t)=>new $e({type:e,minLength:null,maxLength:null,exactLength:null,typeName:pt.ZodArray,...ee(t)});var Fe=class e extends ae{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=p.objectKeys(e);return this._cached={shape:e,keys:t}}_parse(e){if(this._getType(e)!==S.object){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.object,received:t.parsedType}),z}const{status:t,ctx:a}=this._processInputParams(e),{shape:s,keys:n}=this._getCached(),r=[];if(!(this._def.catchall instanceof Pe&&"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 Q(a,n,a.path,e)),alwaysSet:e in a.data})}if(this._def.catchall instanceof Pe){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&&(M(a,{code:A.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 Q(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 F.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=F.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:pt.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(t){return new e({...this._def,catchall:t})}pick(t){const a={};return p.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 p.objectKeys(this.shape).forEach((e=>{t[e]||(a[e]=this.shape[e])})),new e({...this._def,shape:()=>a})}deepPartial(){return Me(this)}partial(t){const a={};return p.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 p.objectKeys(this.shape).forEach((e=>{if(t&&!t[e])a[e]=this.shape[e];else{let t=this.shape[e];for(;t instanceof at;)t=t._def.innerType;a[e]=t}})),new e({...this._def,shape:()=>a})}keyof(){return Ge(p.objectKeys(this.shape))}};Fe.create=(e,t)=>new Fe({shape:()=>e,unknownKeys:"strip",catchall:Pe.create(),typeName:pt.ZodObject,...ee(t)}),Fe.strictCreate=(e,t)=>new Fe({shape:()=>e,unknownKeys:"strict",catchall:Pe.create(),typeName:pt.ZodObject,...ee(t)}),Fe.lazycreate=(e,t)=>new Fe({shape:e,unknownKeys:"strip",catchall:Pe.create(),typeName:pt.ZodObject,...ee(t)});var De=class extends ae{_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 E(e.ctx.common.issues)));return M(t,{code:A.invalid_union,unionErrors:a}),z}));{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 E(e)));return M(t,{code:A.invalid_union,unionErrors:n}),z}}get options(){return this._def.options}};De.create=(e,t)=>new De({options:e,typeName:pt.ZodUnion,...ee(t)});var Ue=e=>e instanceof He?Ue(e.schema):e instanceof tt?Ue(e.innerType()):e instanceof Ye?[e.value]:e instanceof Qe?e.options:e instanceof Xe?p.objectValues(e.enum):e instanceof nt?Ue(e._def.innerType):e instanceof Ie?[void 0]:e instanceof Ae?[null]:e instanceof at?[void 0,...Ue(e.unwrap())]:e instanceof st?[null,...Ue(e.unwrap())]:e instanceof dt||e instanceof ut?Ue(e.unwrap()):e instanceof rt?Ue(e._def.innerType):[],Le=class e extends ae{_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==S.object)return M(t,{code:A.invalid_type,expected:S.object,received:t.parsedType}),z;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}):(M(t,{code:A.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[a]}),z)}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=Ue(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:pt.ZodDiscriminatedUnion,discriminator:t,options:a,optionsMap:n,...ee(s)})}};function qe(e,t){const a=I(e),s=I(t);if(e===t)return{valid:!0,data:e};if(a===S.object&&s===S.object){const a=p.objectKeys(t),s=p.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===S.array&&s===S.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===S.date&&s===S.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}var ze=class extends ae{_parse(e){const{status:t,ctx:a}=this._processInputParams(e),s=(e,s)=>{if(V(e)||V(s))return z;const n=qe(e.value,s.value);return n.valid?((J(e)||J(s))&&t.dirty(),{status:t.value,value:n.data}):(M(a,{code:A.invalid_intersection_types}),z)};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}))}};ze.create=(e,t,a)=>new ze({left:e,right:t,typeName:pt.ZodIntersection,...ee(a)});var Ke=class e extends ae{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==S.array)return M(a,{code:A.invalid_type,expected:S.array,received:a.parsedType}),z;if(a.data.length<this._def.items.length)return M(a,{code:A.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),z;!this._def.rest&&a.data.length>this._def.items.length&&(M(a,{code:A.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 Q(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:pt.ZodTuple,rest:null,...ee(t)})};var Be=class e extends ae{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!==S.object)return M(a,{code:A.invalid_type,expected:S.object,received:a.parsedType}),z;const s=[],n=this._def.keyType,r=this._def.valueType;for(const e in a.data)s.push({key:n._parse(new Q(a,e,a.path,e)),value:r._parse(new Q(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 ae?{keyType:t,valueType:a,typeName:pt.ZodRecord,...ee(s)}:{keyType:we.create(),valueType:t,typeName:pt.ZodRecord,...ee(a)})}},Ve=class extends ae{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!==S.map)return M(a,{code:A.invalid_type,expected:S.map,received:a.parsedType}),z;const s=this._def.keyType,n=this._def.valueType,r=[...a.data.entries()].map((([e,t],r)=>({key:s._parse(new Q(a,e,a.path,[r,"key"])),value:n._parse(new Q(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 z;"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 z;"dirty"!==s.status&&"dirty"!==n.status||t.dirty(),e.set(s.value,n.value)}return{status:t.value,value:e}}}};Ve.create=(e,t,a)=>new Ve({valueType:t,keyType:e,typeName:pt.ZodMap,...ee(a)});var Je=class e extends ae{_parse(e){const{status:t,ctx:a}=this._processInputParams(e);if(a.parsedType!==S.set)return M(a,{code:A.invalid_type,expected:S.set,received:a.parsedType}),z;const s=this._def;null!==s.minSize&&a.data.size<s.minSize.value&&(M(a,{code:A.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&&(M(a,{code:A.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 z;"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 Q(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:F.toString(a)}})}max(t,a){return new e({...this._def,maxSize:{value:t,message:F.toString(a)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}};Je.create=(e,t)=>new Je({valueType:e,minSize:null,maxSize:null,typeName:pt.ZodSet,...ee(t)});var We=class e extends ae{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==S.function)return M(t,{code:A.invalid_type,expected:S.function,received:t.parsedType}),z;function a(e,a){return $({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,R(),j].filter((e=>!!e)),issueData:{code:A.invalid_arguments,argumentsError:a}})}function s(e,a){return $({data:e,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,R(),j].filter((e=>!!e)),issueData:{code:A.invalid_return_type,returnTypeError:a}})}const n={errorMap:t.common.contextualErrorMap},r=t.data;if(this._def.returns instanceof et){const e=this;return B((async function(...t){const i=new E([]),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 E([a(t,i.error)]);const o=Reflect.apply(r,this,i.data),d=e._def.returns.safeParse(o,n);if(!d.success)throw new E([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(je.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(je.create()),returns:a||je.create(),typeName:pt.ZodFunction,...ee(s)})}},He=class extends ae{get schema(){return this._def.getter()}_parse(e){const{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}};He.create=(e,t)=>new He({getter:e,typeName:pt.ZodLazy,...ee(t)});var Ye=class extends ae{_parse(e){if(e.data!==this._def.value){const t=this._getOrReturnCtx(e);return M(t,{received:t.data,code:A.invalid_literal,expected:this._def.value}),z}return{status:"valid",value:e.data}}get value(){return this._def.value}};function Ge(e,t){return new Qe({values:e,typeName:pt.ZodEnum,...ee(t)})}Ye.create=(e,t)=>new Ye({value:e,typeName:pt.ZodLiteral,...ee(t)});var Qe=class e extends ae{constructor(){super(...arguments),U.set(this,void 0)}_parse(e){if("string"!=typeof e.data){const t=this._getOrReturnCtx(e),a=this._def.values;return M(t,{expected:p.joinValues(a),received:t.parsedType,code:A.invalid_type}),z}if(Y(this,U)||G(this,U,new Set(this._def.values)),!Y(this,U).has(e.data)){const t=this._getOrReturnCtx(e),a=this._def.values;return M(t,{received:t.data,code:A.invalid_enum_value,options:a}),z}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})}};U=new WeakMap,Qe.create=Ge;var Xe=class extends ae{constructor(){super(...arguments),L.set(this,void 0)}_parse(e){const t=p.getValidEnumValues(this._def.values),a=this._getOrReturnCtx(e);if(a.parsedType!==S.string&&a.parsedType!==S.number){const e=p.objectValues(t);return M(a,{expected:p.joinValues(e),received:a.parsedType,code:A.invalid_type}),z}if(Y(this,L)||G(this,L,new Set(p.getValidEnumValues(this._def.values))),!Y(this,L).has(e.data)){const e=p.objectValues(t);return M(a,{received:a.data,code:A.invalid_enum_value,options:e}),z}return B(e.data)}get enum(){return this._def.values}};L=new WeakMap,Xe.create=(e,t)=>new Xe({values:e,typeName:pt.ZodNativeEnum,...ee(t)});var et=class extends ae{unwrap(){return this._def.type}_parse(e){const{ctx:t}=this._processInputParams(e);if(t.parsedType!==S.promise&&!1===t.common.async)return M(t,{code:A.invalid_type,expected:S.promise,received:t.parsedType}),z;const a=t.parsedType===S.promise?t.data:Promise.resolve(t.data);return B(a.then((e=>this._def.type.parseAsync(e,{path:t.path,errorMap:t.common.contextualErrorMap}))))}};et.create=(e,t)=>new et({type:e,typeName:pt.ZodPromise,...ee(t)});var tt=class extends ae{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===pt.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=>{M(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 z;const s=await this._def.schema._parseAsync({data:e,path:a.path,parent:a});return"aborted"===s.status?z:"dirty"===s.status||"dirty"===t.value?K(s.value):s}));{if("aborted"===t.value)return z;const s=this._def.schema._parseSync({data:e,path:a.path,parent:a});return"aborted"===s.status?z:"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?z:("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?z:("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(!W(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=>W(e)?Promise.resolve(s.transform(e.value,n)).then((e=>({status:t.value,value:e}))):e))}p.assertNever(s)}};tt.create=(e,t,a)=>new tt({schema:e,typeName:pt.ZodEffects,effect:t,...ee(a)}),tt.createWithPreprocess=(e,t,a)=>new tt({schema:t,effect:{type:"preprocess",transform:e},typeName:pt.ZodEffects,...ee(a)});var at=class extends ae{_parse(e){return this._getType(e)===S.undefined?B(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};at.create=(e,t)=>new at({innerType:e,typeName:pt.ZodOptional,...ee(t)});var st=class extends ae{_parse(e){return this._getType(e)===S.null?B(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}};st.create=(e,t)=>new st({innerType:e,typeName:pt.ZodNullable,...ee(t)});var nt=class extends ae{_parse(e){const{ctx:t}=this._processInputParams(e);let a=t.data;return t.parsedType===S.undefined&&(a=this._def.defaultValue()),this._def.innerType._parse({data:a,path:t.path,parent:t})}removeDefault(){return this._def.innerType}};nt.create=(e,t)=>new nt({innerType:e,typeName:pt.ZodDefault,defaultValue:"function"==typeof t.default?t.default:()=>t.default,...ee(t)});var rt=class extends ae{_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 H(s)?s.then((e=>({status:"valid",value:"valid"===e.status?e.value:this._def.catchValue({get error(){return new E(a.common.issues)},input:a.data})}))):{status:"valid",value:"valid"===s.status?s.value:this._def.catchValue({get error(){return new E(a.common.issues)},input:a.data})}}removeCatch(){return this._def.innerType}};rt.create=(e,t)=>new rt({innerType:e,typeName:pt.ZodCatch,catchValue:"function"==typeof t.catch?t.catch:()=>t.catch,...ee(t)});var it=class extends ae{_parse(e){if(this._getType(e)!==S.nan){const t=this._getOrReturnCtx(e);return M(t,{code:A.invalid_type,expected:S.nan,received:t.parsedType}),z}return{status:"valid",value:e.data}}};it.create=e=>new it({typeName:pt.ZodNaN,...ee(e)});var ot=Symbol("zod_brand"),dt=class extends ae{_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}},ct=class e extends ae{_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?z:"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?z:"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:pt.ZodPipeline})}},ut=class extends ae{_parse(e){const t=this._def.innerType._parse(e),a=e=>(W(e)&&(e.value=Object.freeze(e.value)),e);return H(t)?t.then((e=>a(e))):a(t)}unwrap(){return this._def.innerType}};function lt(e,t){const a="function"==typeof e?e(t):"string"==typeof e?{message:e}:e;return"string"==typeof a?{message:a}:a}function ht(e,t={},a){return e?Ee.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=lt(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=lt(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})}})):Ee.create()}ut.create=(e,t)=>new ut({innerType:e,typeName:pt.ZodReadonly,...ee(t)});var pt,mt,ft={object:Fe.lazycreate};(mt=pt||(pt={})).ZodString="ZodString",mt.ZodNumber="ZodNumber",mt.ZodNaN="ZodNaN",mt.ZodBigInt="ZodBigInt",mt.ZodBoolean="ZodBoolean",mt.ZodDate="ZodDate",mt.ZodSymbol="ZodSymbol",mt.ZodUndefined="ZodUndefined",mt.ZodNull="ZodNull",mt.ZodAny="ZodAny",mt.ZodUnknown="ZodUnknown",mt.ZodNever="ZodNever",mt.ZodVoid="ZodVoid",mt.ZodArray="ZodArray",mt.ZodObject="ZodObject",mt.ZodUnion="ZodUnion",mt.ZodDiscriminatedUnion="ZodDiscriminatedUnion",mt.ZodIntersection="ZodIntersection",mt.ZodTuple="ZodTuple",mt.ZodRecord="ZodRecord",mt.ZodMap="ZodMap",mt.ZodSet="ZodSet",mt.ZodFunction="ZodFunction",mt.ZodLazy="ZodLazy",mt.ZodLiteral="ZodLiteral",mt.ZodEnum="ZodEnum",mt.ZodEffects="ZodEffects",mt.ZodNativeEnum="ZodNativeEnum",mt.ZodOptional="ZodOptional",mt.ZodNullable="ZodNullable",mt.ZodDefault="ZodDefault",mt.ZodCatch="ZodCatch",mt.ZodPromise="ZodPromise",mt.ZodBranded="ZodBranded",mt.ZodPipeline="ZodPipeline",mt.ZodReadonly="ZodReadonly";var yt=we.create,vt=Te.create,gt=it.create,_t=Ce.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=Fe.create,At=Fe.strictCreate,Et=De.create,jt=Le.create,Pt=ze.create,Rt=Ke.create,$t=Be.create,Mt=Ve.create,Ft=Je.create,Dt=We.create,Ut=He.create,Lt=Ye.create,qt=Qe.create,zt=Xe.create,Kt=et.create,Bt=tt.create,Vt=at.create,Jt=st.create,Wt=tt.createWithPreprocess,Ht=ct.create,Yt={string:e=>we.create({...e,coerce:!0}),number:e=>Te.create({...e,coerce:!0}),boolean:e=>Ne.create({...e,coerce:!0}),bigint:e=>Ce.create({...e,coerce:!0}),date:e=>Oe.create({...e,coerce:!0})},Gt=z,Qt=Object.freeze({__proto__:null,defaultErrorMap:j,setErrorMap:function(e){P=e},getErrorMap:R,makeIssue:$,EMPTY_PATH:[],addIssueToContext:M,ParseStatus:q,INVALID:z,DIRTY:K,OK:B,isAborted:V,isDirty:J,isValid:W,isAsync:H,get util(){return p},get objectUtil(){return f},ZodParsedType:S,getParsedType:I,ZodType:ae,datetimeRegex:xe,ZodString:we,ZodNumber:Te,ZodBigInt:Ce,ZodBoolean:Ne,ZodDate:Oe,ZodSymbol:Se,ZodUndefined:Ie,ZodNull:Ae,ZodAny:Ee,ZodUnknown:je,ZodNever:Pe,ZodVoid:Re,ZodArray:$e,ZodObject:Fe,ZodUnion:De,ZodDiscriminatedUnion:Le,ZodIntersection:ze,ZodTuple:Ke,ZodRecord:Be,ZodMap:Ve,ZodSet:Je,ZodFunction:We,ZodLazy:He,ZodLiteral:Ye,ZodEnum:Qe,ZodNativeEnum:Xe,ZodPromise:et,ZodEffects:tt,ZodTransformer:tt,ZodOptional:at,ZodNullable:st,ZodDefault:nt,ZodCatch:rt,ZodNaN:it,BRAND:ot,ZodBranded:dt,ZodPipeline:ct,ZodReadonly:ut,custom:ht,Schema:ae,ZodSchema:ae,late:ft,get ZodFirstPartyTypeKind(){return pt},coerce:Yt,any:Tt,array:St,bigint:_t,boolean:xt,date:bt,discriminatedUnion:jt,effect:Bt,enum:qt,function:Dt,instanceof:(e,t={message:`Input not instance of ${e.name}`})=>ht((t=>t instanceof e),t),intersection:Pt,lazy:Ut,literal:Lt,map:Mt,nan:gt,nativeEnum:zt,never:Nt,null:Zt,nullable:Jt,number:vt,object:It,oboolean:()=>xt().optional(),onumber:()=>vt().optional(),optional:Vt,ostring:()=>yt().optional(),pipeline:Ht,preprocess:Wt,promise:Kt,record:$t,set:Ft,strictObject:At,string:yt,symbol:kt,transformer:Bt,tuple:Rt,undefined:wt,union:Et,unknown:Ct,void:Ot,NEVER:Gt,ZodIssueCode:A,quotelessJson:e=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:"),ZodError:E}),Xt=Qt.object({type:Qt.enum(["sqlite","postgresql","mysql"]).default("sqlite"),connection:Qt.object({url:Qt.string().default("./db/zaileys.db")}).optional().default({})}).optional().default({}),ea={prefix:Qt.string().optional(),ignoreMe:Qt.boolean().optional().default(!0),showLogs:Qt.boolean().optional().default(!0),autoMentions:Qt.boolean().optional().default(!0),autoOnline:Qt.boolean().optional().default(!0),autoRead:Qt.boolean().optional().default(!0),autoRejectCall:Qt.boolean().optional().default(!0),database:Xt,citation:Qt.record(Qt.function().returns(Qt.union([Qt.number().array(),Qt.promise(Qt.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}))},ta=Qt.object({authType:Qt.literal("pairing"),phoneNumber:Qt.number(),...ea}),aa=Qt.object({authType:Qt.literal("qr"),phoneNumber:Qt.undefined().optional(),...ea}),sa=Qt.discriminatedUnion("authType",[ta,aa]),na=class{constructor(e){this.client=e}events=new Map;setup(t){t.ev.on("connection.update",(async t=>{const{connection:a,lastDisconnect:s,qr:n}=t;if(this.emit("connection",{status:a||"connecting"}),"qr"==this.client.options?.authType&&n&&console.log("Scan qrcode with your whatsapp: "),"close"===a){const t=s?.error?.output?.statusCode,a=t!==e.DisconnectReason.loggedOut;if(console.log(s?.error?.message),401==t||405==t||500==t)return;a&&await this.client.initialize()}else"open"===a&&this.emit("connection",{status:"open"})})),t.ev.on("messages.upsert",(({messages:e})=>{this.emit("messages",e)})),t.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)))}},ra=class{constructor(e){this.props=e,this.initialize(),this.event=new na(this)}options;chatId="zaileys-chats";logger=g.default({level:"silent",enabled:!1});event;db;socket;groupCache=new v.default({stdTTL:300,useClones:!1});async initialize(){this.options=await sa.parseAsync(this.props),this.db=((e,t)=>{if("sqlite"===e){const e=t||"./db/zaileys.db",a=b.default.resolve(e);return n.mkdirSync(b.default.dirname(a),{recursive:!0}),n.writeFileSync(a,"",{flag:"a"}),new r.Kysely({dialect:new r.SqliteDialect({database:new _.default(a)})})}const a=new c.URL(t),s=a.protocol.replace(":","");if("mysql"===e)return new r.Kysely({dialect:new r.MysqlDialect({pool:x.default.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 r.Kysely({dialect:new r.PostgresDialect({pool:new d.Pool({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:t,saveCreds:a,removeCreds:s}=await O(this.db,this.chatId),i=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=y.default({logger:this.logger,markOnlineOnConnect:this.options.autoOnline,syncFullHistory:!1,defaultQueryTimeoutMs:void 0,msgRetryCounterCache:new v.default,cachedGroupMetadata:async e=>this.groupCache.get(e),printQRInTerminal:"qr"==this.options.authType,browser:e.Browsers.ubuntu("qr"==this.options.authType?"Zaileys Library":"Firefox"),auth:{creds:t.creds,keys:e.makeCacheableSignalKeyStore(t.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",a),i.bind(this.socket?.ev),this.event.setup(this.socket)}on(e,t){this.event.on(e,t)}};module.exports=ra;
|
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
connection: z.ZodDefault<z.ZodOptional<z.ZodObject<{
|
|
5
|
-
url: z.ZodDefault<z.ZodString>;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
url: string;
|
|
8
|
-
}, {
|
|
9
|
-
url?: string | undefined;
|
|
10
|
-
}>>>;
|
|
11
|
-
}, "strip", z.ZodTypeAny, {
|
|
12
|
-
type: "sqlite" | "postgresql" | "mysql";
|
|
13
|
-
connection: {
|
|
14
|
-
url: string;
|
|
15
|
-
};
|
|
16
|
-
}, {
|
|
17
|
-
type?: "sqlite" | "postgresql" | "mysql" | undefined;
|
|
18
|
-
connection?: {
|
|
19
|
-
url?: string | undefined;
|
|
20
|
-
} | undefined;
|
|
21
|
-
}>>>;
|
|
22
|
-
export declare const ClientClassesType: z.ZodDiscriminatedUnion<"authType", [z.ZodObject<{
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
declare const ClientClassesType: z.ZodDiscriminatedUnion<"authType", [z.ZodObject<{
|
|
23
4
|
prefix: z.ZodOptional<z.ZodString>;
|
|
24
5
|
ignoreMe: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
25
6
|
showLogs: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
@@ -150,3 +131,83 @@ export declare const ClientClassesType: z.ZodDiscriminatedUnion<"authType", [z.Z
|
|
|
150
131
|
} | undefined;
|
|
151
132
|
citation?: Record<string, (...args: unknown[]) => number[] | Promise<number[]>> | undefined;
|
|
152
133
|
}>]>;
|
|
134
|
+
|
|
135
|
+
declare const EventConnectionType: z.ZodObject<{
|
|
136
|
+
status: z.ZodEnum<["connecting", "open", "close"]>;
|
|
137
|
+
}, "strip", z.ZodTypeAny, {
|
|
138
|
+
status: "connecting" | "open" | "close";
|
|
139
|
+
}, {
|
|
140
|
+
status: "connecting" | "open" | "close";
|
|
141
|
+
}>;
|
|
142
|
+
declare const EventMessagesType: z.ZodObject<{
|
|
143
|
+
messages: z.ZodObject<{
|
|
144
|
+
remoteJid: z.ZodString;
|
|
145
|
+
id: z.ZodString;
|
|
146
|
+
}, "strip", z.ZodTypeAny, {
|
|
147
|
+
id: string;
|
|
148
|
+
remoteJid: string;
|
|
149
|
+
}, {
|
|
150
|
+
id: string;
|
|
151
|
+
remoteJid: string;
|
|
152
|
+
}>;
|
|
153
|
+
}, "strip", z.ZodTypeAny, {
|
|
154
|
+
messages: {
|
|
155
|
+
id: string;
|
|
156
|
+
remoteJid: string;
|
|
157
|
+
};
|
|
158
|
+
}, {
|
|
159
|
+
messages: {
|
|
160
|
+
id: string;
|
|
161
|
+
remoteJid: string;
|
|
162
|
+
};
|
|
163
|
+
}>;
|
|
164
|
+
declare const EventCallType: z.ZodObject<{
|
|
165
|
+
call: z.ZodObject<{
|
|
166
|
+
id: z.ZodString;
|
|
167
|
+
from: z.ZodString;
|
|
168
|
+
timestamp: z.ZodNumber;
|
|
169
|
+
}, "strip", z.ZodTypeAny, {
|
|
170
|
+
id: string;
|
|
171
|
+
timestamp: number;
|
|
172
|
+
from: string;
|
|
173
|
+
}, {
|
|
174
|
+
id: string;
|
|
175
|
+
timestamp: number;
|
|
176
|
+
from: string;
|
|
177
|
+
}>;
|
|
178
|
+
}, "strip", z.ZodTypeAny, {
|
|
179
|
+
call: {
|
|
180
|
+
id: string;
|
|
181
|
+
timestamp: number;
|
|
182
|
+
from: string;
|
|
183
|
+
};
|
|
184
|
+
}, {
|
|
185
|
+
call: {
|
|
186
|
+
id: string;
|
|
187
|
+
timestamp: number;
|
|
188
|
+
from: string;
|
|
189
|
+
};
|
|
190
|
+
}>;
|
|
191
|
+
declare const EventEnumType: z.ZodEnum<["connection", "messages", "call"]>;
|
|
192
|
+
type EventEnumType = z.infer<typeof EventEnumType>;
|
|
193
|
+
type EventCallbackType = {
|
|
194
|
+
connection: (data: z.infer<typeof EventConnectionType>) => void;
|
|
195
|
+
messages: (data: z.infer<typeof EventMessagesType>) => void;
|
|
196
|
+
call: (data: z.infer<typeof EventCallType>) => void;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
declare class Client {
|
|
200
|
+
private props;
|
|
201
|
+
options: z.infer<typeof ClientClassesType> | undefined;
|
|
202
|
+
private chatId;
|
|
203
|
+
private logger;
|
|
204
|
+
private event;
|
|
205
|
+
private db;
|
|
206
|
+
private socket;
|
|
207
|
+
private groupCache;
|
|
208
|
+
constructor(props: z.input<typeof ClientClassesType>);
|
|
209
|
+
initialize(): Promise<void>;
|
|
210
|
+
on<T extends EventEnumType>(event: T, handler: EventCallbackType[T]): void;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export { Client as default };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +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};
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zaileys",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.18-beta",
|
|
4
4
|
"description": "Zaileys - Simplify Typescript/Javascript WhatsApp NodeJS API",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"
|
|
11
|
-
"dev": "concurrently \"npm:dev:test\"",
|
|
9
|
+
"build": "tsup",
|
|
10
|
+
"dev": " npm run dev:test",
|
|
12
11
|
"dev:test": "npx tsx watch test/example.ts",
|
|
13
12
|
"clean": "rimraf dist"
|
|
14
13
|
},
|
|
@@ -50,14 +49,16 @@
|
|
|
50
49
|
"@rollup/plugin-typescript": "^12.0.0",
|
|
51
50
|
"@types/better-sqlite3": "^7.6.13",
|
|
52
51
|
"@types/pg": "^8.15.1",
|
|
53
|
-
"
|
|
52
|
+
"@types/qrcode-terminal": "^0.12.2",
|
|
54
53
|
"rimraf": "^5.0.0",
|
|
55
54
|
"rollup": "^3.0.0",
|
|
56
55
|
"rollup-plugin-dts": "^5.0.0",
|
|
57
56
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
57
|
+
"rollup-plugin-gzip": "^4.0.1",
|
|
58
58
|
"rollup-plugin-multi-input": "^1.5.0",
|
|
59
59
|
"rollup-plugin-strip": "^1.2.2",
|
|
60
60
|
"rollup-plugin-terser": "^7.0.0",
|
|
61
|
+
"tsup": "^8.4.0",
|
|
61
62
|
"tsx": "^4.19.4",
|
|
62
63
|
"typescript": "^5.0.0",
|
|
63
64
|
"zod": "^3.24.4"
|
|
@@ -65,11 +66,14 @@
|
|
|
65
66
|
"dependencies": {
|
|
66
67
|
"baileys": "^6.7.16",
|
|
67
68
|
"better-sqlite3": "^11.10.0",
|
|
69
|
+
"jimp": "^1.6.0",
|
|
68
70
|
"kysely": "^0.28.2",
|
|
69
71
|
"libsignal": "^2.0.1",
|
|
70
72
|
"mysql2": "^3.14.1",
|
|
71
73
|
"node-cache": "^5.1.2",
|
|
72
74
|
"pg": "^8.15.6",
|
|
73
|
-
"pino": "^9.6.0"
|
|
75
|
+
"pino": "^9.6.0",
|
|
76
|
+
"qrcode-terminal": "^0.12.0",
|
|
77
|
+
"sharp": "^0.34.1"
|
|
74
78
|
}
|
|
75
79
|
}
|
package/dist/classes/Client.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { ClientClassesType } from "../types/classes/client";
|
|
3
|
-
import { EventCallbackType, EventEnumType } from "../types/classes/event";
|
|
4
|
-
declare class Client {
|
|
5
|
-
private props;
|
|
6
|
-
options: z.infer<typeof ClientClassesType> | undefined;
|
|
7
|
-
private chatId;
|
|
8
|
-
private logger;
|
|
9
|
-
private event;
|
|
10
|
-
private db;
|
|
11
|
-
private socket;
|
|
12
|
-
private groupCache;
|
|
13
|
-
constructor(props: z.input<typeof ClientClassesType>);
|
|
14
|
-
initialize(): Promise<void>;
|
|
15
|
-
on<T extends EventEnumType>(event: T, handler: EventCallbackType[T]): void;
|
|
16
|
-
}
|
|
17
|
-
export default Client;
|
package/dist/classes/Event.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { WASocket } from "baileys";
|
|
2
|
-
import { EventCallbackType, EventEnumType } from "../types/classes/event";
|
|
3
|
-
import Client from "./Client";
|
|
4
|
-
declare class Event {
|
|
5
|
-
private client;
|
|
6
|
-
private events;
|
|
7
|
-
constructor(client: Client);
|
|
8
|
-
setup(sock: WASocket): void;
|
|
9
|
-
on<T extends EventEnumType>(event: T, handler: EventCallbackType[T]): void;
|
|
10
|
-
private emit;
|
|
11
|
-
}
|
|
12
|
-
export default Event;
|
package/dist/classes/Parser.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Kysely } from "kysely";
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
import { AuthAdapterHandlerType } from "../types/adapter/general";
|
|
4
|
-
import { AdapterDatabaseType } from "../types/classes/client";
|
|
5
|
-
import type { DB } from "./schema";
|
|
6
|
-
import { BaileysEventEmitter } from "baileys";
|
|
7
|
-
export declare const ConnectDB: (type: z.infer<typeof AdapterDatabaseType>["type"], url: string) => Kysely<DB>;
|
|
8
|
-
export declare const MigrateDB: (db: Kysely<DB>) => Promise<void>;
|
|
9
|
-
export declare const AuthAdapterHandler: (db: Kysely<DB>, session: string) => AuthAdapterHandlerType;
|
|
10
|
-
export declare const StoreAdapterHandler: (db: Kysely<DB>, session: string) => Promise<{
|
|
11
|
-
bind: (event: BaileysEventEmitter) => void;
|
|
12
|
-
}>;
|