@authhero/kysely-adapter 0.19.0 → 0.20.1

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.
@@ -1 +1 @@
1
- "use strict";var Gr=Object.defineProperty;var Kn=t=>{throw TypeError(t)};var Hr=(t,e,n)=>e in t?Gr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var ut=(t,e,n)=>Hr(t,typeof e!="symbol"?e+"":e,n),bn=(t,e,n)=>e.has(t)||Kn("Cannot "+n);var v=(t,e,n)=>(bn(t,e,"read from private field"),n?n.call(t):e.get(t)),re=(t,e,n)=>e.has(t)?Kn("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),ht=(t,e,n,r)=>(bn(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),C=(t,e,n)=>(bn(t,e,"access private method"),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var Cn=class extends Error{constructor(e=500,n){super(n==null?void 0:n.message,{cause:n==null?void 0:n.cause});ut(this,"res");ut(this,"status");this.res=n==null?void 0:n.res,this.status=e}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}};function Yr(t){return async(e,n)=>{const{identities:r,...a}=n,s={...a,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),tenant_id:e,email_verified:n.email_verified?1:0,is_social:n.is_social?1:0,app_metadata:JSON.stringify(n.app_metadata),user_metadata:JSON.stringify(n.user_metadata)};try{await t.insertInto("users").values(s).execute()}catch(o){throw o.code==="SQLITE_CONSTRAINT_UNIQUE"||o.message.includes("AlreadyExists")?new Cn(409,{message:"User already exists"}):(console.log(o.message),new Cn(500,{message:`${o.code}, ${o.message}`}))}return{...s,email:s.email||"",email_verified:s.email_verified===1,is_social:s.is_social===1}}}function M(t){const e={...t};for(const n in e)e[n]===null?delete e[n]:typeof e[n]=="object"&&(Array.isArray(e[n])?e[n]=e[n].map(M):e[n]=M(e[n]));return e}function Xr(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function ea(t,e){var n;return((n=t==null?void 0:t._def)===null||n===void 0?void 0:n.typeName)===e}function pt(t,e){const n=t.ZodType.prototype[e];t.ZodType.prototype[e]=function(...r){const a=n.apply(this,r);return a._def.openapi=this._def.openapi,a}}function ta(t){if(typeof t.ZodType.prototype.openapi<"u")return;t.ZodType.prototype.openapi=function(a,s){var o,d,c,l,u,Z;const R=typeof a=="string"?s:a,J=R??{},{param:_e}=J,We=Xr(J,["param"]),ge=Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o._internal),typeof a=="string"?{refId:a}:void 0),ye=Object.assign(Object.assign(Object.assign({},(d=this._def.openapi)===null||d===void 0?void 0:d.metadata),We),!((l=(c=this._def.openapi)===null||c===void 0?void 0:c.metadata)===null||l===void 0)&&l.param||_e?{param:Object.assign(Object.assign({},(Z=(u=this._def.openapi)===null||u===void 0?void 0:u.metadata)===null||Z===void 0?void 0:Z.param),_e)}:void 0),ve=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(ge).length>0?{_internal:ge}:void 0),Object.keys(ye).length>0?{metadata:ye}:void 0)}));if(ea(this,"ZodObject")){const Je=this.extend;ve.extend=function(...qe){var ee,te,ne,be,$e,Pe;const Ae=Je.apply(this,qe);return Ae._def.openapi={_internal:{extendedFrom:!((te=(ee=this._def.openapi)===null||ee===void 0?void 0:ee._internal)===null||te===void 0)&&te.refId?{refId:(be=(ne=this._def.openapi)===null||ne===void 0?void 0:ne._internal)===null||be===void 0?void 0:be.refId,schema:this}:($e=this._def.openapi)===null||$e===void 0?void 0:$e._internal.extendedFrom},metadata:(Pe=Ae._def.openapi)===null||Pe===void 0?void 0:Pe.metadata},Ae}}return ve},pt(t,"optional"),pt(t,"nullable"),pt(t,"default"),pt(t,"transform"),pt(t,"refine");const e=t.ZodObject.prototype.deepPartial;t.ZodObject.prototype.deepPartial=function(){const a=this._def.shape(),s=e.apply(this),o=s._def.shape();return Object.entries(o).forEach(([d,c])=>{var l,u;c._def.openapi=(u=(l=a[d])===null||l===void 0?void 0:l._def)===null||u===void 0?void 0:u.openapi}),s._def.openapi=void 0,s};const n=t.ZodObject.prototype.pick;t.ZodObject.prototype.pick=function(...a){const s=n.apply(this,a);return s._def.openapi=void 0,s};const r=t.ZodObject.prototype.omit;t.ZodObject.prototype.omit=function(...a){const s=r.apply(this,a);return s._def.openapi=void 0,s}}new Set(".\\+*[^]$()");var E;(function(t){t.assertEqual=a=>a;function e(a){}t.assertIs=e;function n(a){throw new Error}t.assertNever=n,t.arrayToEnum=a=>{const s={};for(const o of a)s[o]=o;return s},t.getValidEnumValues=a=>{const s=t.objectKeys(a).filter(d=>typeof a[a[d]]!="number"),o={};for(const d of s)o[d]=a[d];return t.objectValues(o)},t.objectValues=a=>t.objectKeys(a).map(function(s){return a[s]}),t.objectKeys=typeof Object.keys=="function"?a=>Object.keys(a):a=>{const s=[];for(const o in a)Object.prototype.hasOwnProperty.call(a,o)&&s.push(o);return s},t.find=(a,s)=>{for(const o of a)if(s(o))return o},t.isInteger=typeof Number.isInteger=="function"?a=>Number.isInteger(a):a=>typeof a=="number"&&isFinite(a)&&Math.floor(a)===a;function r(a,s=" | "){return a.map(o=>typeof o=="string"?`'${o}'`:o).join(s)}t.joinValues=r,t.jsonStringifyReplacer=(a,s)=>typeof s=="bigint"?s.toString():s})(E||(E={}));var On;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(On||(On={}));const g=E.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),xe=t=>{switch(typeof t){case"undefined":return g.undefined;case"string":return g.string;case"number":return isNaN(t)?g.nan:g.number;case"boolean":return g.boolean;case"function":return g.function;case"bigint":return g.bigint;case"symbol":return g.symbol;case"object":return Array.isArray(t)?g.array:t===null?g.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?g.promise:typeof Map<"u"&&t instanceof Map?g.map:typeof Set<"u"&&t instanceof Set?g.set:typeof Date<"u"&&t instanceof Date?g.date:g.object;default:return g.unknown}},h=E.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"]),na=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:");class K extends Error{constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const n=e||function(s){return s.message},r={_errors:[]},a=s=>{for(const o of s.issues)if(o.code==="invalid_union")o.unionErrors.map(a);else if(o.code==="invalid_return_type")a(o.returnTypeError);else if(o.code==="invalid_arguments")a(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let d=r,c=0;for(;c<o.path.length;){const l=o.path[c];c===o.path.length-1?(d[l]=d[l]||{_errors:[]},d[l]._errors.push(n(o))):d[l]=d[l]||{_errors:[]},d=d[l],c++}}};return a(this),r}static assert(e){if(!(e instanceof K))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,E.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},r=[];for(const a of this.issues)a.path.length>0?(n[a.path[0]]=n[a.path[0]]||[],n[a.path[0]].push(e(a))):r.push(e(a));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}K.create=t=>new K(t);const st=(t,e)=>{let n;switch(t.code){case h.invalid_type:t.received===g.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case h.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,E.jsonStringifyReplacer)}`;break;case h.unrecognized_keys:n=`Unrecognized key(s) in object: ${E.joinValues(t.keys,", ")}`;break;case h.invalid_union:n="Invalid input";break;case h.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${E.joinValues(t.options)}`;break;case h.invalid_enum_value:n=`Invalid enum value. Expected ${E.joinValues(t.options)}, received '${t.received}'`;break;case h.invalid_arguments:n="Invalid function arguments";break;case h.invalid_return_type:n="Invalid function return type";break;case h.invalid_date:n="Invalid date";break;case h.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:E.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case h.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case h.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case h.custom:n="Invalid input";break;case h.invalid_intersection_types:n="Intersection results could not be merged";break;case h.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case h.not_finite:n="Number must be finite";break;default:n=e.defaultError,E.assertNever(t)}return{message:n}};let er=st;function ra(t){er=t}function tn(){return er}const nn=t=>{const{data:e,path:n,errorMaps:r,issueData:a}=t,s=[...n,...a.path||[]],o={...a,path:s};if(a.message!==void 0)return{...a,path:s,message:a.message};let d="";const c=r.filter(l=>!!l).slice().reverse();for(const l of c)d=l(o,{data:e,defaultError:d}).message;return{...a,path:s,message:d}},aa=[];function f(t,e){const n=tn(),r=nn({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===st?void 0:st].filter(a=>!!a)});t.common.issues.push(r)}class U{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const a of n){if(a.status==="aborted")return T;a.status==="dirty"&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const a of n){const s=await a.key,o=await a.value;r.push({key:s,value:o})}return U.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const a of n){const{key:s,value:o}=a;if(s.status==="aborted"||o.status==="aborted")return T;s.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof o.value<"u"||a.alwaysSet)&&(r[s.value]=o.value)}return{status:e.value,value:r}}}const T=Object.freeze({status:"aborted"}),rn=t=>({status:"dirty",value:t}),V=t=>({status:"valid",value:t}),Sn=t=>t.status==="aborted",jn=t=>t.status==="dirty",wt=t=>t.status==="valid",xt=t=>typeof Promise<"u"&&t instanceof Promise;function an(t,e,n,r){if(typeof e=="function"?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(t)}function tr(t,e,n,r,a){if(typeof e=="function"?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,n),n}var b;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(b||(b={}));var ft,_t;class ie{constructor(e,n,r,a){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=a}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Wn=(t,e)=>{if(wt(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new K(t.common.issues);return this._error=n,this._error}}};function O(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:a}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(s,o)=>{var d,c;const{message:l}=t;return s.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:(d=l??r)!==null&&d!==void 0?d:o.defaultError}:s.code!=="invalid_type"?{message:o.defaultError}:{message:(c=l??n)!==null&&c!==void 0?c:o.defaultError}},description:a}}class j{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)}get description(){return this._def.description}_getType(e){return xe(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:xe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new U,ctx:{common:e.parent.common,data:e.data,parsedType:xe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(xt(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){var r;const a={common:{issues:[],async:(r=n==null?void 0:n.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:xe(e)},s=this._parseSync({data:e,path:a.path,parent:a});return Wn(a,s)}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:xe(e)},a=this._parse({data:e,path:r.path,parent:r}),s=await(xt(a)?a:Promise.resolve(a));return Wn(r,s)}refine(e,n){const r=a=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(a):n;return this._refinement((a,s)=>{const o=e(a),d=()=>s.addIssue({code:h.custom,...r(a)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(d(),!1)):o?!0:(d(),!1)})}refinement(e,n){return this._refinement((r,a)=>e(r)?!0:(a.addIssue(typeof n=="function"?n(r,a):n),!1))}_refinement(e){return new Y({schema:this,typeName:x.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return ae.create(this,this._def)}nullable(){return Oe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return G.create(this,this._def)}promise(){return ot.create(this,this._def)}or(e){return Ct.create([this,e],this._def)}and(e){return Ot.create(this,e,this._def)}transform(e){return new Y({...O(this._def),schema:this,typeName:x.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new Et({...O(this._def),innerType:this,defaultValue:n,typeName:x.ZodDefault})}brand(){return new zn({typeName:x.ZodBranded,type:this,...O(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new $t({...O(this._def),innerType:this,catchValue:n,typeName:x.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Ht.create(this,e)}readonly(){return Pt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const sa=/^c[^\s-]{8,}$/i,ia=/^[0-9a-z]+$/,oa=/^[0-9A-HJKMNP-TV-Z]{26}$/,da=/^[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,ca=/^[a-z0-9_-]{21}$/i,la=/^[-+]?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)?)??$/,ua=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ha="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let wn;const pa=/^(?:(?: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])$/,ma=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,fa=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,nr="((\\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])))",_a=new RegExp(`^${nr}$`);function rr(t){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`),e}function ga(t){return new RegExp(`^${rr(t)}$`)}function ar(t){let e=`${nr}T${rr(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function ya(t,e){return!!((e==="v4"||!e)&&pa.test(t)||(e==="v6"||!e)&&ma.test(t))}class q extends j{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==g.string){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.string,received:a.parsedType}),T}const n=new U;let r;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="max")e.data.length>a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="length"){const s=e.data.length>a.value,o=e.data.length<a.value;(s||o)&&(r=this._getOrReturnCtx(e,r),s?f(r,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&f(r,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),n.dirty())}else if(a.kind==="email")ua.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"email",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="emoji")wn||(wn=new RegExp(ha,"u")),wn.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"emoji",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="uuid")da.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"uuid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="nanoid")ca.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"nanoid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid")sa.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"cuid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid2")ia.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"cuid2",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="ulid")oa.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"ulid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),f(r,{validation:"url",code:h.invalid_string,message:a.message}),n.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"regex",code:h.invalid_string,message:a.message}),n.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),n.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:{startsWith:a.value},message:a.message}),n.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:{endsWith:a.value},message:a.message}),n.dirty()):a.kind==="datetime"?ar(a).test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:"datetime",message:a.message}),n.dirty()):a.kind==="date"?_a.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:"date",message:a.message}),n.dirty()):a.kind==="time"?ga(a).test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:"time",message:a.message}),n.dirty()):a.kind==="duration"?la.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"duration",code:h.invalid_string,message:a.message}),n.dirty()):a.kind==="ip"?ya(e.data,a.version)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"ip",code:h.invalid_string,message:a.message}),n.dirty()):a.kind==="base64"?fa.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"base64",code:h.invalid_string,message:a.message}),n.dirty()):E.assertNever(a);return{status:n.value,value:e.data}}_regex(e,n,r){return this.refinement(a=>e.test(a),{validation:n,code:h.invalid_string,...b.errToObj(r)})}_addCheck(e){return new q({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...b.errToObj(e)})}url(e){return this._addCheck({kind:"url",...b.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...b.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...b.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...b.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...b.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...b.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...b.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...b.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...b.errToObj(e)})}datetime(e){var n,r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(n=e==null?void 0:e.offset)!==null&&n!==void 0?n:!1,local:(r=e==null?void 0:e.local)!==null&&r!==void 0?r:!1,...b.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...b.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...b.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...b.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...b.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...b.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...b.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...b.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...b.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...b.errToObj(n)})}nonempty(e){return this.min(1,b.errToObj(e))}trim(){return new q({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}q.create=t=>{var e;return new q({checks:[],typeName:x.ZodString,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...O(t)})};function va(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,a=n>r?n:r,s=parseInt(t.toFixed(a).replace(".","")),o=parseInt(e.toFixed(a).replace(".",""));return s%o/Math.pow(10,a)}class ke extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==g.number){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.number,received:a.parsedType}),T}let n;const r=new U;for(const a of this._def.checks)a.kind==="int"?E.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),f(n,{code:h.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="multipleOf"?va(e.data,a.value)!==0&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),f(n,{code:h.not_finite,message:a.message}),r.dirty()):E.assertNever(a);return{status:r.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,r,a){return new ke({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:b.toString(a)}]})}_addCheck(e){return new ke({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:b.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:b.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:b.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:b.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&E.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}}ke.create=t=>new ke({checks:[],typeName:x.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...O(t)});class Te extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==g.bigint){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.bigint,received:a.parsedType}),T}let n;const r=new U;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):E.assertNever(a);return{status:r.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,r,a){return new Te({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:b.toString(a)}]})}_addCheck(e){return new Te({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Te.create=t=>{var e;return new Te({checks:[],typeName:x.ZodBigInt,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...O(t)})};class Nt extends j{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==g.boolean){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.boolean,received:n.parsedType}),T}return V(e.data)}}Nt.create=t=>new Nt({typeName:x.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...O(t)});class ze extends j{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==g.date){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.date,received:a.parsedType}),T}if(isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_date}),T}const n=new U;let r;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),n.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),n.dirty()):E.assertNever(a);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new ze({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:b.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:b.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}ze.create=t=>new ze({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:x.ZodDate,...O(t)});class sn extends j{_parse(e){if(this._getType(e)!==g.symbol){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.symbol,received:n.parsedType}),T}return V(e.data)}}sn.create=t=>new sn({typeName:x.ZodSymbol,...O(t)});class kt extends j{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.undefined,received:n.parsedType}),T}return V(e.data)}}kt.create=t=>new kt({typeName:x.ZodUndefined,...O(t)});class Tt extends j{_parse(e){if(this._getType(e)!==g.null){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.null,received:n.parsedType}),T}return V(e.data)}}Tt.create=t=>new Tt({typeName:x.ZodNull,...O(t)});class it extends j{constructor(){super(...arguments),this._any=!0}_parse(e){return V(e.data)}}it.create=t=>new it({typeName:x.ZodAny,...O(t)});class Me extends j{constructor(){super(...arguments),this._unknown=!0}_parse(e){return V(e.data)}}Me.create=t=>new Me({typeName:x.ZodUnknown,...O(t)});class me extends j{_parse(e){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.never,received:n.parsedType}),T}}me.create=t=>new me({typeName:x.ZodNever,...O(t)});class on extends j{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.void,received:n.parsedType}),T}return V(e.data)}}on.create=t=>new on({typeName:x.ZodVoid,...O(t)});class G extends j{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),a=this._def;if(n.parsedType!==g.array)return f(n,{code:h.invalid_type,expected:g.array,received:n.parsedType}),T;if(a.exactLength!==null){const o=n.data.length>a.exactLength.value,d=n.data.length<a.exactLength.value;(o||d)&&(f(n,{code:o?h.too_big:h.too_small,minimum:d?a.exactLength.value:void 0,maximum:o?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(a.minLength!==null&&n.data.length<a.minLength.value&&(f(n,{code:h.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),a.maxLength!==null&&n.data.length>a.maxLength.value&&(f(n,{code:h.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,d)=>a.type._parseAsync(new ie(n,o,n.path,d)))).then(o=>U.mergeArray(r,o));const s=[...n.data].map((o,d)=>a.type._parseSync(new ie(n,o,n.path,d)));return U.mergeArray(r,s)}get element(){return this._def.type}min(e,n){return new G({...this._def,minLength:{value:e,message:b.toString(n)}})}max(e,n){return new G({...this._def,maxLength:{value:e,message:b.toString(n)}})}length(e,n){return new G({...this._def,exactLength:{value:e,message:b.toString(n)}})}nonempty(e){return this.min(1,e)}}G.create=(t,e)=>new G({type:t,minLength:null,maxLength:null,exactLength:null,typeName:x.ZodArray,...O(e)});function Ge(t){if(t instanceof A){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=ae.create(Ge(r))}return new A({...t._def,shape:()=>e})}else return t instanceof G?new G({...t._def,type:Ge(t.element)}):t instanceof ae?ae.create(Ge(t.unwrap())):t instanceof Oe?Oe.create(Ge(t.unwrap())):t instanceof oe?oe.create(t.items.map(e=>Ge(e))):t}class A extends j{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=E.objectKeys(e);return this._cached={shape:e,keys:n}}_parse(e){if(this._getType(e)!==g.object){const c=this._getOrReturnCtx(e);return f(c,{code:h.invalid_type,expected:g.object,received:c.parsedType}),T}const{status:n,ctx:r}=this._processInputParams(e),{shape:a,keys:s}=this._getCached(),o=[];if(!(this._def.catchall instanceof me&&this._def.unknownKeys==="strip"))for(const c in r.data)s.includes(c)||o.push(c);const d=[];for(const c of s){const l=a[c],u=r.data[c];d.push({key:{status:"valid",value:c},value:l._parse(new ie(r,u,r.path,c)),alwaysSet:c in r.data})}if(this._def.catchall instanceof me){const c=this._def.unknownKeys;if(c==="passthrough")for(const l of o)d.push({key:{status:"valid",value:l},value:{status:"valid",value:r.data[l]}});else if(c==="strict")o.length>0&&(f(r,{code:h.unrecognized_keys,keys:o}),n.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const l of o){const u=r.data[l];d.push({key:{status:"valid",value:l},value:c._parse(new ie(r,u,r.path,l)),alwaysSet:l in r.data})}}return r.common.async?Promise.resolve().then(async()=>{const c=[];for(const l of d){const u=await l.key,Z=await l.value;c.push({key:u,value:Z,alwaysSet:l.alwaysSet})}return c}).then(c=>U.mergeObjectSync(n,c)):U.mergeObjectSync(n,d)}get shape(){return this._def.shape()}strict(e){return b.errToObj,new A({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{var a,s,o,d;const c=(o=(s=(a=this._def).errorMap)===null||s===void 0?void 0:s.call(a,n,r).message)!==null&&o!==void 0?o:r.defaultError;return n.code==="unrecognized_keys"?{message:(d=b.errToObj(e).message)!==null&&d!==void 0?d:c}:{message:c}}}:{}})}strip(){return new A({...this._def,unknownKeys:"strip"})}passthrough(){return new A({...this._def,unknownKeys:"passthrough"})}extend(e){return new A({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new A({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:x.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new A({...this._def,catchall:e})}pick(e){const n={};return E.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new A({...this._def,shape:()=>n})}omit(e){const n={};return E.objectKeys(this.shape).forEach(r=>{e[r]||(n[r]=this.shape[r])}),new A({...this._def,shape:()=>n})}deepPartial(){return Ge(this)}partial(e){const n={};return E.objectKeys(this.shape).forEach(r=>{const a=this.shape[r];e&&!e[r]?n[r]=a:n[r]=a.optional()}),new A({...this._def,shape:()=>n})}required(e){const n={};return E.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])n[r]=this.shape[r];else{let a=this.shape[r];for(;a instanceof ae;)a=a._def.innerType;n[r]=a}}),new A({...this._def,shape:()=>n})}keyof(){return sr(E.objectKeys(this.shape))}}A.create=(t,e)=>new A({shape:()=>t,unknownKeys:"strip",catchall:me.create(),typeName:x.ZodObject,...O(e)});A.strictCreate=(t,e)=>new A({shape:()=>t,unknownKeys:"strict",catchall:me.create(),typeName:x.ZodObject,...O(e)});A.lazycreate=(t,e)=>new A({shape:t,unknownKeys:"strip",catchall:me.create(),typeName:x.ZodObject,...O(e)});class Ct extends j{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function a(s){for(const d of s)if(d.result.status==="valid")return d.result;for(const d of s)if(d.result.status==="dirty")return n.common.issues.push(...d.ctx.common.issues),d.result;const o=s.map(d=>new K(d.ctx.common.issues));return f(n,{code:h.invalid_union,unionErrors:o}),T}if(n.common.async)return Promise.all(r.map(async s=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(a);{let s;const o=[];for(const c of r){const l={...n,common:{...n.common,issues:[]},parent:null},u=c._parseSync({data:n.data,path:n.path,parent:l});if(u.status==="valid")return u;u.status==="dirty"&&!s&&(s={result:u,ctx:l}),l.common.issues.length&&o.push(l.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const d=o.map(c=>new K(c));return f(n,{code:h.invalid_union,unionErrors:d}),T}}get options(){return this._def.options}}Ct.create=(t,e)=>new Ct({options:t,typeName:x.ZodUnion,...O(e)});const we=t=>t instanceof jt?we(t.schema):t instanceof Y?we(t.innerType()):t instanceof It?[t.value]:t instanceof Ce?t.options:t instanceof Zt?E.objectValues(t.enum):t instanceof Et?we(t._def.innerType):t instanceof kt?[void 0]:t instanceof Tt?[null]:t instanceof ae?[void 0,...we(t.unwrap())]:t instanceof Oe?[null,...we(t.unwrap())]:t instanceof zn||t instanceof Pt?we(t.unwrap()):t instanceof $t?we(t._def.innerType):[];class yn extends j{_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==g.object)return f(n,{code:h.invalid_type,expected:g.object,received:n.parsedType}),T;const r=this.discriminator,a=n.data[r],s=this.optionsMap.get(a);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(f(n,{code:h.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),T)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){const a=new Map;for(const s of n){const o=we(s.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const d of o){if(a.has(d))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(d)}`);a.set(d,s)}}return new yn({typeName:x.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:a,...O(r)})}}function In(t,e){const n=xe(t),r=xe(e);if(t===e)return{valid:!0,data:t};if(n===g.object&&r===g.object){const a=E.objectKeys(e),s=E.objectKeys(t).filter(d=>a.indexOf(d)!==-1),o={...t,...e};for(const d of s){const c=In(t[d],e[d]);if(!c.valid)return{valid:!1};o[d]=c.data}return{valid:!0,data:o}}else if(n===g.array&&r===g.array){if(t.length!==e.length)return{valid:!1};const a=[];for(let s=0;s<t.length;s++){const o=t[s],d=e[s],c=In(o,d);if(!c.valid)return{valid:!1};a.push(c.data)}return{valid:!0,data:a}}else return n===g.date&&r===g.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class Ot extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=(s,o)=>{if(Sn(s)||Sn(o))return T;const d=In(s.value,o.value);return d.valid?((jn(s)||jn(o))&&n.dirty(),{status:n.value,value:d.data}):(f(r,{code:h.invalid_intersection_types}),T)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,o])=>a(s,o)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Ot.create=(t,e,n)=>new Ot({left:t,right:e,typeName:x.ZodIntersection,...O(n)});class oe extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.array)return f(r,{code:h.invalid_type,expected:g.array,received:r.parsedType}),T;if(r.data.length<this._def.items.length)return f(r,{code:h.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),T;!this._def.rest&&r.data.length>this._def.items.length&&(f(r,{code:h.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const a=[...r.data].map((s,o)=>{const d=this._def.items[o]||this._def.rest;return d?d._parse(new ie(r,s,r.path,o)):null}).filter(s=>!!s);return r.common.async?Promise.all(a).then(s=>U.mergeArray(n,s)):U.mergeArray(n,a)}get items(){return this._def.items}rest(e){return new oe({...this._def,rest:e})}}oe.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new oe({items:t,typeName:x.ZodTuple,rest:null,...O(e)})};class St extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.object)return f(r,{code:h.invalid_type,expected:g.object,received:r.parsedType}),T;const a=[],s=this._def.keyType,o=this._def.valueType;for(const d in r.data)a.push({key:s._parse(new ie(r,d,r.path,d)),value:o._parse(new ie(r,r.data[d],r.path,d)),alwaysSet:d in r.data});return r.common.async?U.mergeObjectAsync(n,a):U.mergeObjectSync(n,a)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof j?new St({keyType:e,valueType:n,typeName:x.ZodRecord,...O(r)}):new St({keyType:q.create(),valueType:e,typeName:x.ZodRecord,...O(n)})}}class dn extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.map)return f(r,{code:h.invalid_type,expected:g.map,received:r.parsedType}),T;const a=this._def.keyType,s=this._def.valueType,o=[...r.data.entries()].map(([d,c],l)=>({key:a._parse(new ie(r,d,r.path,[l,"key"])),value:s._parse(new ie(r,c,r.path,[l,"value"]))}));if(r.common.async){const d=new Map;return Promise.resolve().then(async()=>{for(const c of o){const l=await c.key,u=await c.value;if(l.status==="aborted"||u.status==="aborted")return T;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}})}else{const d=new Map;for(const c of o){const l=c.key,u=c.value;if(l.status==="aborted"||u.status==="aborted")return T;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}}}}dn.create=(t,e,n)=>new dn({valueType:e,keyType:t,typeName:x.ZodMap,...O(n)});class Ue extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.set)return f(r,{code:h.invalid_type,expected:g.set,received:r.parsedType}),T;const a=this._def;a.minSize!==null&&r.data.size<a.minSize.value&&(f(r,{code:h.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),n.dirty()),a.maxSize!==null&&r.data.size>a.maxSize.value&&(f(r,{code:h.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),n.dirty());const s=this._def.valueType;function o(c){const l=new Set;for(const u of c){if(u.status==="aborted")return T;u.status==="dirty"&&n.dirty(),l.add(u.value)}return{status:n.value,value:l}}const d=[...r.data.values()].map((c,l)=>s._parse(new ie(r,c,r.path,l)));return r.common.async?Promise.all(d).then(c=>o(c)):o(d)}min(e,n){return new Ue({...this._def,minSize:{value:e,message:b.toString(n)}})}max(e,n){return new Ue({...this._def,maxSize:{value:e,message:b.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}Ue.create=(t,e)=>new Ue({valueType:t,minSize:null,maxSize:null,typeName:x.ZodSet,...O(e)});class nt extends j{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==g.function)return f(n,{code:h.invalid_type,expected:g.function,received:n.parsedType}),T;function r(d,c){return nn({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,tn(),st].filter(l=>!!l),issueData:{code:h.invalid_arguments,argumentsError:c}})}function a(d,c){return nn({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,tn(),st].filter(l=>!!l),issueData:{code:h.invalid_return_type,returnTypeError:c}})}const s={errorMap:n.common.contextualErrorMap},o=n.data;if(this._def.returns instanceof ot){const d=this;return V(async function(...c){const l=new K([]),u=await d._def.args.parseAsync(c,s).catch(R=>{throw l.addIssue(r(c,R)),l}),Z=await Reflect.apply(o,this,u);return await d._def.returns._def.type.parseAsync(Z,s).catch(R=>{throw l.addIssue(a(Z,R)),l})})}else{const d=this;return V(function(...c){const l=d._def.args.safeParse(c,s);if(!l.success)throw new K([r(c,l.error)]);const u=Reflect.apply(o,this,l.data),Z=d._def.returns.safeParse(u,s);if(!Z.success)throw new K([a(u,Z.error)]);return Z.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new nt({...this._def,args:oe.create(e).rest(Me.create())})}returns(e){return new nt({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new nt({args:e||oe.create([]).rest(Me.create()),returns:n||Me.create(),typeName:x.ZodFunction,...O(r)})}}class jt extends j{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}jt.create=(t,e)=>new jt({getter:t,typeName:x.ZodLazy,...O(e)});class It extends j{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return f(n,{received:n.data,code:h.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:e.data}}get value(){return this._def.value}}It.create=(t,e)=>new It({value:t,typeName:x.ZodLiteral,...O(e)});function sr(t,e){return new Ce({values:t,typeName:x.ZodEnum,...O(e)})}class Ce extends j{constructor(){super(...arguments),ft.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return f(n,{expected:E.joinValues(r),received:n.parsedType,code:h.invalid_type}),T}if(an(this,ft)||tr(this,ft,new Set(this._def.values)),!an(this,ft).has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return f(n,{received:n.data,code:h.invalid_enum_value,options:r}),T}return V(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return Ce.create(e,{...this._def,...n})}exclude(e,n=this._def){return Ce.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}}ft=new WeakMap;Ce.create=sr;class Zt extends j{constructor(){super(...arguments),_t.set(this,void 0)}_parse(e){const n=E.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==g.string&&r.parsedType!==g.number){const a=E.objectValues(n);return f(r,{expected:E.joinValues(a),received:r.parsedType,code:h.invalid_type}),T}if(an(this,_t)||tr(this,_t,new Set(E.getValidEnumValues(this._def.values))),!an(this,_t).has(e.data)){const a=E.objectValues(n);return f(r,{received:r.data,code:h.invalid_enum_value,options:a}),T}return V(e.data)}get enum(){return this._def.values}}_t=new WeakMap;Zt.create=(t,e)=>new Zt({values:t,typeName:x.ZodNativeEnum,...O(e)});class ot extends j{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==g.promise&&n.common.async===!1)return f(n,{code:h.invalid_type,expected:g.promise,received:n.parsedType}),T;const r=n.parsedType===g.promise?n.data:Promise.resolve(n.data);return V(r.then(a=>this._def.type.parseAsync(a,{path:n.path,errorMap:n.common.contextualErrorMap})))}}ot.create=(t,e)=>new ot({type:t,typeName:x.ZodPromise,...O(e)});class Y extends j{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===x.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=this._def.effect||null,s={addIssue:o=>{f(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),a.type==="preprocess"){const o=a.transform(r.data,s);if(r.common.async)return Promise.resolve(o).then(async d=>{if(n.value==="aborted")return T;const c=await this._def.schema._parseAsync({data:d,path:r.path,parent:r});return c.status==="aborted"?T:c.status==="dirty"||n.value==="dirty"?rn(c.value):c});{if(n.value==="aborted")return T;const d=this._def.schema._parseSync({data:o,path:r.path,parent:r});return d.status==="aborted"?T:d.status==="dirty"||n.value==="dirty"?rn(d.value):d}}if(a.type==="refinement"){const o=d=>{const c=a.refinement(d,s);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return d};if(r.common.async===!1){const d=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return d.status==="aborted"?T:(d.status==="dirty"&&n.dirty(),o(d.value),{status:n.value,value:d.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(d=>d.status==="aborted"?T:(d.status==="dirty"&&n.dirty(),o(d.value).then(()=>({status:n.value,value:d.value}))))}if(a.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!wt(o))return o;const d=a.transform(o.value,s);if(d instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:d}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>wt(o)?Promise.resolve(a.transform(o.value,s)).then(d=>({status:n.value,value:d})):o);E.assertNever(a)}}Y.create=(t,e,n)=>new Y({schema:t,typeName:x.ZodEffects,effect:e,...O(n)});Y.createWithPreprocess=(t,e,n)=>new Y({schema:e,effect:{type:"preprocess",transform:t},typeName:x.ZodEffects,...O(n)});class ae extends j{_parse(e){return this._getType(e)===g.undefined?V(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ae.create=(t,e)=>new ae({innerType:t,typeName:x.ZodOptional,...O(e)});class Oe extends j{_parse(e){return this._getType(e)===g.null?V(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Oe.create=(t,e)=>new Oe({innerType:t,typeName:x.ZodNullable,...O(e)});class Et extends j{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===g.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Et.create=(t,e)=>new Et({innerType:t,typeName:x.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...O(e)});class $t extends j{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return xt(a)?a.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new K(r.common.issues)},input:r.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new K(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}$t.create=(t,e)=>new $t({innerType:t,typeName:x.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...O(e)});class cn extends j{_parse(e){if(this._getType(e)!==g.nan){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.nan,received:n.parsedType}),T}return{status:"valid",value:e.data}}}cn.create=t=>new cn({typeName:x.ZodNaN,...O(t)});const ba=Symbol("zod_brand");class zn extends j{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Ht extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?T:a.status==="dirty"?(n.dirty(),rn(a.value)):this._def.out._parseAsync({data:a.value,path:r.path,parent:r})})();{const a=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?T:a.status==="dirty"?(n.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:r.path,parent:r})}}static create(e,n){return new Ht({in:e,out:n,typeName:x.ZodPipeline})}}class Pt extends j{_parse(e){const n=this._def.innerType._parse(e),r=a=>(wt(a)&&(a.value=Object.freeze(a.value)),a);return xt(n)?n.then(a=>r(a)):r(n)}unwrap(){return this._def.innerType}}Pt.create=(t,e)=>new Pt({innerType:t,typeName:x.ZodReadonly,...O(e)});function ir(t,e={},n){return t?it.create().superRefine((r,a)=>{var s,o;if(!t(r)){const d=typeof e=="function"?e(r):typeof e=="string"?{message:e}:e,c=(o=(s=d.fatal)!==null&&s!==void 0?s:n)!==null&&o!==void 0?o:!0,l=typeof d=="string"?{message:d}:d;a.addIssue({code:"custom",...l,fatal:c})}}):it.create()}const wa={object:A.lazycreate};var x;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(x||(x={}));const xa=(t,e={message:`Input not instance of ${t.name}`})=>ir(n=>n instanceof t,e),or=q.create,dr=ke.create,Na=cn.create,ka=Te.create,cr=Nt.create,Ta=ze.create,Ca=sn.create,Oa=kt.create,Sa=Tt.create,ja=it.create,Ia=Me.create,Za=me.create,Ea=on.create,$a=G.create,Pa=A.create,Aa=A.strictCreate,Da=Ct.create,Ra=yn.create,Ma=Ot.create,La=oe.create,za=St.create,Ua=dn.create,Fa=Ue.create,Va=nt.create,Ba=jt.create,Ka=It.create,Wa=Ce.create,Ja=Zt.create,qa=ot.create,Jn=Y.create,Qa=ae.create,Ga=Oe.create,Ha=Y.createWithPreprocess,Ya=Ht.create,Xa=()=>or().optional(),es=()=>dr().optional(),ts=()=>cr().optional(),ns={string:t=>q.create({...t,coerce:!0}),number:t=>ke.create({...t,coerce:!0}),boolean:t=>Nt.create({...t,coerce:!0}),bigint:t=>Te.create({...t,coerce:!0}),date:t=>ze.create({...t,coerce:!0})},rs=T;var i=Object.freeze({__proto__:null,defaultErrorMap:st,setErrorMap:ra,getErrorMap:tn,makeIssue:nn,EMPTY_PATH:aa,addIssueToContext:f,ParseStatus:U,INVALID:T,DIRTY:rn,OK:V,isAborted:Sn,isDirty:jn,isValid:wt,isAsync:xt,get util(){return E},get objectUtil(){return On},ZodParsedType:g,getParsedType:xe,ZodType:j,datetimeRegex:ar,ZodString:q,ZodNumber:ke,ZodBigInt:Te,ZodBoolean:Nt,ZodDate:ze,ZodSymbol:sn,ZodUndefined:kt,ZodNull:Tt,ZodAny:it,ZodUnknown:Me,ZodNever:me,ZodVoid:on,ZodArray:G,ZodObject:A,ZodUnion:Ct,ZodDiscriminatedUnion:yn,ZodIntersection:Ot,ZodTuple:oe,ZodRecord:St,ZodMap:dn,ZodSet:Ue,ZodFunction:nt,ZodLazy:jt,ZodLiteral:It,ZodEnum:Ce,ZodNativeEnum:Zt,ZodPromise:ot,ZodEffects:Y,ZodTransformer:Y,ZodOptional:ae,ZodNullable:Oe,ZodDefault:Et,ZodCatch:$t,ZodNaN:cn,BRAND:ba,ZodBranded:zn,ZodPipeline:Ht,ZodReadonly:Pt,custom:ir,Schema:j,ZodSchema:j,late:wa,get ZodFirstPartyTypeKind(){return x},coerce:ns,any:ja,array:$a,bigint:ka,boolean:cr,date:Ta,discriminatedUnion:Ra,effect:Jn,enum:Wa,function:Va,instanceof:xa,intersection:Ma,lazy:Ba,literal:Ka,map:Ua,nan:Na,nativeEnum:Ja,never:Za,null:Sa,nullable:Ga,number:dr,object:Pa,oboolean:ts,onumber:es,optional:Qa,ostring:Xa,pipeline:Ya,preprocess:Ha,promise:qa,record:za,set:Fa,strictObject:Aa,string:or,symbol:Ca,transformer:Jn,tuple:La,undefined:Oa,union:Da,unknown:Ia,void:Ea,NEVER:rs,ZodIssueCode:h,quotelessJson:na,ZodError:K});ta(i);i.object({start:i.number(),limit:i.number(),length:i.number()});const Un=i.object({created_at:i.string(),updated_at:i.string()}),as=i.object({email:i.string().optional(),email_verified:i.boolean().optional(),name:i.string().optional(),username:i.string().optional(),given_name:i.string().optional(),phone_number:i.string().optional(),phone_verified:i.boolean().optional(),family_name:i.string().optional()}).catchall(i.any()),ss=i.object({connection:i.string(),user_id:i.string(),provider:i.string(),isSocial:i.boolean(),access_token:i.string().optional(),access_token_secret:i.string().optional(),refresh_token:i.string().optional(),profileData:as.optional()}),lr=i.object({email:i.string().optional(),username:i.string().optional(),given_name:i.string().optional(),family_name:i.string().optional(),nickname:i.string().optional(),name:i.string().optional(),picture:i.string().optional(),locale:i.string().optional(),linked_to:i.string().optional(),profileData:i.string().optional(),user_id:i.string().optional(),app_metadata:i.any().default({}).optional(),user_metadata:i.any().default({}).optional()}),is=lr.extend({email_verified:i.boolean().default(!1),verify_email:i.boolean().optional(),last_ip:i.string().optional(),last_login:i.string().optional(),user_id:i.string().optional(),provider:i.string().default("email"),connection:i.string().default("email")});i.object({...is.shape,...Un.shape,user_id:i.string(),email:i.string(),is_social:i.boolean(),login_count:i.number(),identities:i.array(ss).optional()});lr.extend({email:i.string(),login_count:i.number(),multifactor:i.array(i.string()).optional(),last_ip:i.string().optional(),last_login:i.string().optional(),user_id:i.string()}).catchall(i.any());const os="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ds=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=os[n[t]&63];return e};const cs=i.object({audience:i.string().optional(),recipient:i.string().optional(),createUpnClaim:i.boolean().optional(),mapUnknownClaimsAsIs:i.boolean().optional(),passthroughClaimsWithNoMapping:i.boolean().optional(),mapIdentities:i.boolean().optional(),signatureAlgorithm:i.string().optional(),digestAlgorithm:i.string().optional(),issuer:i.string().optional(),destination:i.string().optional(),lifetimeInSeconds:i.number().optional(),signResponse:i.boolean().optional(),nameIdentifierFormat:i.string().optional(),nameIdentifierProbes:i.array(i.string()).optional(),authnContextClassRef:i.string().optional(),mappings:i.record(i.string()).optional()}),ls=i.object({id:i.string(),name:i.string(),callbacks:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of URLs whitelisted to use as a callback to the client after authentication."}),allowed_origins:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level. Query strings and hash information are not taken into account when validating these URLs."}),web_origins:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode."}),allowed_logout_urls:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains."}),allowed_clients:i.array(i.string()).default([]).optional().openapi({description:"Ids of clients that will be allowed to perform delegation requests. Clients that will be allowed to make delegation request. By default, all your clients will be allowed. This field allows you to specify specific clients"}),addons:i.object({samlp:cs.optional()}).default({}).optional().openapi({description:"Addons associated with the client. The key is the addon's package name and the value is an object with the configuration for the addon."}),email_validation:i.enum(["enabled","disabled","enforced"]).default("enforced").optional().openapi({description:"Defines if it possible to sign in with an unverified email and if verification emails will be sent. This is not available in auth0"}),client_secret:i.string().default(()=>ds()).optional(),disable_sign_ups:i.boolean().optional().default(!1).openapi({description:"Prevents users from signing up using the hosted login page. This is not available in auth0"})}),us=i.object({created_at:i.string().transform(t=>t===null?"":t),updated_at:i.string().transform(t=>t===null?"":t),...ls.shape});var ur=(t=>(t.TOKEN="token",t.TOKEN_ID_TOKEN="token id_token",t.CODE="code",t))(ur||{}),hr=(t=>(t.QUERY="query",t.FRAGMENT="fragment",t.FORM_POST="form_post",t.WEB_MESSAGE="web_message",t.SAML_POST="saml_post",t))(hr||{}),pr=(t=>(t.S265="S256",t.plain="plain",t))(pr||{});const hs=i.object({client_id:i.string(),vendor_id:i.string().optional(),act_as:i.string().optional(),response_type:i.nativeEnum(ur).optional(),response_mode:i.nativeEnum(hr).optional(),redirect_uri:i.string().optional(),audience:i.string().optional(),state:i.string().optional(),nonce:i.string().optional(),scope:i.string().optional(),prompt:i.string().optional(),code_challenge_method:i.nativeEnum(pr).optional(),code_challenge:i.string().optional(),username:i.string().optional(),ui_locales:i.string().optional()});i.object({colors:i.object({primary:i.string(),page_background:i.object({type:i.string().optional(),start:i.string().optional(),end:i.string().optional(),angle_deg:i.number().optional()}).optional()}).optional(),logo_url:i.string().optional(),favicon_url:i.string().optional(),font:i.object({url:i.string()}).optional()});const ps=i.object({id:i.string().optional(),name:i.string(),strategy:i.enum(["google-oauth2","facebook","vipps","freja","apple","email","Username-Password-Authentication","oidc","oauth2","custom"]).optional(),options:i.object({kid:i.string().optional(),team_id:i.string().optional(),realms:i.string().optional(),client_id:i.string().optional(),client_secret:i.string().optional(),app_secret:i.string().optional(),scope:i.string().optional(),authorization_endpoint:i.string().default("").optional(),token_endpoint:i.string().default("").optional(),userinfo_endpoint:i.string().default("").optional(),jwks_uri:i.string().default("").optional(),discovery_url:i.string().default("").optional(),issuer:i.string().default("").optional()}).default({}).optional(),enabled_clients:i.array(i.string()).default([]).optional(),response_type:i.custom().optional(),response_mode:i.custom().optional()}),mr=i.object({id:i.string(),created_at:i.string().transform(t=>t===null?"":t),updated_at:i.string().transform(t=>t===null?"":t)}).extend(ps.shape),ms=i.object({name:i.string(),audience:i.string(),sender_email:i.string().email(),sender_name:i.string(),support_url:i.string().url().optional(),logo:i.string().url().optional(),primary_color:i.string().optional(),secondary_color:i.string().optional(),language:i.string().optional()}),fs=i.object({created_at:i.string().transform(t=>t===null?"":t),updated_at:i.string().transform(t=>t===null?"":t),id:i.string(),...ms.shape});i.object({logoUrl:i.string(),loginBackgroundImage:i.string().nullish(),style:i.object({primaryColor:i.string(),buttonTextColor:i.string(),primaryHoverColor:i.string()}),supportEmail:i.string().nullable(),supportUrl:i.string().nullable(),name:i.string(),showGreyishBackground:i.boolean().optional(),termsAndConditionsUrl:i.string().nullable(),companyName:i.string().optional(),checkoutHideSocial:i.boolean().optional(),siteUrl:i.string().nullable(),manageSubscriptionsUrl:i.string().optional()});const _s=i.object({domain:i.string(),dkim_private_key:i.string().optional(),dkim_public_key:i.string().optional(),email_api_key:i.string().optional(),email_service:i.union([i.literal("mailgun"),i.literal("mailchannels")]).optional()});i.object({...us.shape,domains:i.array(_s),tenant:fs,connections:i.array(mr)});const gs=i.enum(["password_reset","email_verification","otp","authorization_code","oauth2_state","ticket"]),ys=i.object({code_id:i.string().openapi({description:"The code that will be used in for instance an email verification flow"}),login_id:i.string().openapi({description:"The id of the login session that the code is connected to"}),connection_id:i.string().optional().openapi({description:"The connection that the code is connected to"}),code_type:gs,expires_at:i.string(),used_at:i.string().optional(),user_id:i.string().optional()}),vs=i.object({...ys.shape,created_at:i.string()}),bs=i.object({domain:i.string(),dkim_private_key:i.string().optional(),dkim_public_key:i.string().optional(),email_api_key:i.string().optional(),email_service:i.enum(["mailgun","mailchannels"])});Un.extend({...bs.shape,id:i.string()});const ws=i.object({trigger_id:i.enum(["pre-user-signup","post-user-registration","post-user-login"]),enabled:i.boolean().default(!1),url:i.string(),hook_id:i.string().optional(),synchronous:i.boolean().default(!1),priority:i.number().optional()});ws.extend({...Un.shape,hook_id:i.string()});const xs=i.object({alg:i.enum(["RS256","RS384","RS512","ES256","ES384","ES512","HS256","HS384","HS512"]),e:i.string(),kid:i.string(),kty:i.enum(["RSA","EC","oct"]),n:i.string(),x5t:i.string().optional(),x5c:i.array(i.string()).optional(),use:i.enum(["sig","enc"]).optional()});i.object({keys:i.array(xs)});i.object({issuer:i.string(),authorization_endpoint:i.string(),token_endpoint:i.string(),device_authorization_endpoint:i.string(),userinfo_endpoint:i.string(),mfa_challenge_endpoint:i.string(),jwks_uri:i.string(),registration_endpoint:i.string(),revocation_endpoint:i.string(),scopes_supported:i.array(i.string()),response_types_supported:i.array(i.string()),code_challenge_methods_supported:i.array(i.string()),response_modes_supported:i.array(i.string()),subject_types_supported:i.array(i.string()),id_token_signing_alg_values_supported:i.array(i.string()),token_endpoint_auth_methods_supported:i.array(i.string()),claims_supported:i.array(i.string()),request_uri_parameter_supported:i.boolean(),request_parameter_supported:i.boolean(),token_endpoint_auth_signing_alg_values_supported:i.array(i.string())});const Ns=i.object({auth0Client:i.string().optional(),authParams:hs,expires_at:i.string(),deleted_at:i.string().optional(),ip:i.string().optional()}).openapi({description:"This represents a login sesion"}),ks=i.object({...Ns.shape,login_id:i.string().openapi({description:"This is is used as the state in the universal login"}),created_at:i.string(),updated_at:i.string()}),Ts=i.enum(["cls","fsa","fs","f","fc","fcoa","fcp","fh","fp","fs","fu","s","sapi","scoa","scp","scpr","scu","seacft","serft","slo","ss","ssa","sv","svr"]),Cs=i.object({name:i.string(),version:i.string(),env:i.object({node:i.string().optional()}).optional()});i.object({type:Ts,date:i.string(),description:i.string().optional(),log_id:i.string().optional(),_id:i.string().optional(),ip:i.string(),user_agent:i.string(),details:i.any().optional(),isMobile:i.boolean(),user_id:i.string().optional(),user_name:i.string().optional(),connection:i.string().optional(),connection_id:i.string().optional(),client_id:i.string().optional(),client_name:i.string().optional(),audience:i.string().optional(),scope:i.array(i.string()).optional(),strategy:i.string().optional(),strategy_type:i.string().optional(),hostname:i.string().optional(),auth0_client:Cs.optional()});const Os=i.object({user_id:i.string(),password:i.string(),algorithm:i.enum(["bcrypt","argon2id"]).default("argon2id")});i.object({...Os.shape,created_at:i.string(),updated_at:i.string()});const Ss=i.object({session_id:i.string(),client_id:i.string(),expires_at:i.string(),used_at:i.string(),deleted_at:i.string().optional(),user_id:i.string()});i.object({created_at:i.string(),...Ss.shape});i.object({kid:i.string().openapi({description:"The key id of the signing key"}),cert:i.string().openapi({description:"The public certificate of the signing key"}),fingerprint:i.string().openapi({description:"The cert fingerprint"}),thumbprint:i.string().openapi({description:"The cert thumbprint"}),pkcs7:i.string().optional().openapi({description:"The private key in pkcs7 format"}),current:i.boolean().optional().openapi({description:"True if the key is the current key"}),next:i.boolean().optional().openapi({description:"True if the key is the next key"}),previous:i.boolean().optional().openapi({description:"True if the key is the previous key"}),current_since:i.string().optional().openapi({description:"The date and time when the key became the current key"}),current_until:i.string().optional().openapi({description:"The date and time when the current key was rotated"}),revoked:i.boolean().optional().openapi({description:"True if the key is revoked"}),revoked_at:i.string().optional().openapi({description:"The date and time when the key was revoked"})});var fr=(t=>(t.RefreshToken="refresh_token",t.AuthorizationCode="authorization_code",t.ClientCredential="client_credentials",t.Passwordless="passwordless",t.Password="password",t))(fr||{});const Fn=i.nativeEnum(fr);i.object({grant_type:Fn.refine(t=>t==="authorization_code"),code:i.string(),client_secret:i.string(),client_id:i.string()});i.object({grant_type:Fn.refine(t=>t==="authorization_code"),code:i.string(),code_verifier:i.string(),client_id:i.string().optional(),redirect_uri:i.string()});i.object({grant_type:Fn.refine(t=>t==="client_credentials"),scope:i.string().optional(),client_secret:i.string(),client_id:i.string(),audience:i.string().optional()});i.object({access_token:i.string(),id_token:i.string().optional(),scope:i.string().optional(),state:i.string().optional(),refresh_token:i.string().optional(),token_type:i.string(),expires_in:i.number()});i.object({code:i.string(),state:i.string().optional()});const js=i.object({button_border_radius:i.number(),button_border_weight:i.number(),buttons_style:i.enum(["pill"]),input_border_radius:i.number(),input_border_weight:i.number(),inputs_style:i.enum(["pill"]),show_widget_shadow:i.boolean(),widget_border_weight:i.number(),widget_corner_radius:i.number()}),Is=i.object({base_focus_color:i.string(),base_hover_color:i.string(),body_text:i.string(),captcha_widget_theme:i.enum(["auto"]),error:i.string(),header:i.string(),icons:i.string(),input_background:i.string(),input_border:i.string(),input_filled_text:i.string(),input_labels_placeholders:i.string(),links_focused_components:i.string(),primary_button:i.string(),primary_button_label:i.string(),secondary_button_border:i.string(),secondary_button_label:i.string(),success:i.string(),widget_background:i.string(),widget_border:i.string()}),Qe=i.object({bold:i.boolean(),size:i.number()}),Zs=i.object({body_text:Qe,buttons_text:Qe,font_url:i.string(),input_labels:Qe,links:Qe,links_style:i.enum(["normal"]),reference_text_size:i.number(),subtitle:Qe,title:Qe}),Es=i.object({background_color:i.string(),background_image_url:i.string(),page_layout:i.enum(["center"])}),$s=i.object({header_text_alignment:i.enum(["center"]),logo_height:i.number(),logo_position:i.enum(["center"]),logo_url:i.string(),social_buttons_layout:i.enum(["bottom"])}),Ps=i.object({borders:js,colors:Is,displayName:i.string(),fonts:Zs,page_background:Es,widget:$s});Ps.extend({themeId:i.string()});const As=i.object({universal_login_experience:i.enum(["new","classic"]).default("new"),identifier_first:i.boolean().default(!0),password_first:i.boolean().default(!1),webauthn_platform_first_factor:i.boolean()});function Vn(t){const[e,n]=t.split("|");if(!e||!n)throw new Error(`Invalid user_id: ${t}`);return{connection:e,id:n}}function _r(t){let e={};try{e=JSON.parse(t.profileData||"{}")}catch(n){console.error("Error parsing profileData",n)}return{connection:t.connection,provider:t.provider,user_id:Vn(t.user_id).id,isSocial:!!t.is_social,profileData:{email:t.email,email_verified:!!t.email_verified,...e}}}function Ds(t){return async(e,n)=>{const[r,a]=await Promise.all([t.selectFrom("users").where("users.tenant_id","=",e).where("users.user_id","=",n).selectAll().executeTakeFirst(),t.selectFrom("users").where("users.tenant_id","=",e).where("users.linked_to","=",n).selectAll().execute()]);if(!r)return null;const{tenant_id:s,...o}=r,d={...o,email:r.email||"",email_verified:r.email_verified===1,is_social:r.is_social===1,app_metadata:JSON.parse(r.app_metadata),user_metadata:JSON.parse(r.user_metadata),identities:[{connection:r.connection,provider:r.provider,user_id:Vn(r.user_id).id,isSocial:!!r.is_social},...a.map(_r)]};return M(d)}}function Be(t,e,n,r){return n.split(/\s+/).map(s=>s.replace(/^([^:]+)=/g,"$1:")).map(s=>{let o=s.startsWith("-"),d,c,l,u;return s.startsWith("-_exists_:")?(d=s.substring(10),l=!0,o=!0):s.startsWith("_exists_:")?(d=s.substring(9),l=!0,o=!1):s.includes(":")?(o=s.startsWith("-"),[d,c]=o?s.substring(1).split(":"):s.split(":"),l=!1,c.startsWith(">=")?(u=">=",c=c.substring(2)):c.startsWith(">")?(u=">",c=c.substring(1)):c.startsWith("<=")?(console.log("value",c),u="<=",c=c.substring(2)):c.startsWith("<")?(u="<",c=c.substring(1)):u="="):(d=null,c=s,l=!1),{key:d,value:c,isNegation:o,isExistsQuery:l,operator:u}}).forEach(({key:s,value:o,isNegation:d,isExistsQuery:c,operator:l})=>{if(s)if(c)d?e=e.where(s,"is",null):e=e.where(s,"is not",null);else if(d)switch(l){case">":e=e.where(s,"<=",o);break;case">=":e=e.where(s,"<",o);break;case"<":e=e.where(s,">=",o);break;case"<=":e=e.where(s,">",o);break;default:e=e.where(s,"!=",o)}else e=e.where(s,l,o);else{const{ref:u}=t.dynamic;e=e.where(Z=>Z.or(r.map(R=>Z(u(R),"like",`%${o}%`))))}}),e}function Ee(t){return typeof t=="string"?parseInt(t,10):typeof t=="bigint"?Number(t):t}function Rs(t){return async(e,n)=>{let r=t.selectFrom("users").where("users.tenant_id","=",e);if(n.q&&(r=Be(t,r,n.q,["email","name"])),n.sort&&n.sort.sort_by){const{ref:u}=t.dynamic;r=r.orderBy(u(n.sort.sort_by),n.sort.sort_order)}const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),o=s.map(u=>u.user_id),d=o.length?await t.selectFrom("users").selectAll().where("users.tenant_id","=",e).where("users.linked_to","in",o).execute():[],c=s.map(u=>{const Z=d.filter(R=>R.linked_to===u.user_id);return M({...u,email_verified:u.email_verified===1,is_social:u.is_social===1,app_metadata:JSON.parse(u.app_metadata),user_metadata:JSON.parse(u.user_metadata),identities:[{connection:u.connection,provider:u.provider,user_id:Vn(u.user_id).id,isSocial:!!u.is_social},...Z.map(_r)]})}),{count:l}=await r.select(u=>u.fn.countAll().as("count")).executeTakeFirstOrThrow();return{users:c,start:n.page*n.per_page,limit:n.per_page,length:Ee(l)}}}function Ms(t){return async(e,n)=>(await t.deleteFrom("users").where("users.tenant_id","=",e).where("users.linked_to","=",n).execute(),(await t.deleteFrom("users").where("users.tenant_id","=",e).where("users.user_id","=",n).execute()).length===1)}function Ls(t){if(t.email_verified!==void 0)return t.email_verified?1:0}function zs(t){return async(e,n,r)=>{const a={...r,email_verified:Ls(r),updated_at:new Date().toISOString()};return r.app_metadata&&(a.app_metadata=JSON.stringify(r.app_metadata)),r.user_metadata&&(a.user_metadata=JSON.stringify(r.user_metadata)),(await t.updateTable("users").set(a).where("users.tenant_id","=",e).where("users.user_id","=",n).execute()).length===1}}function Us(t){return async(e,n,r,a)=>{const s={linked_to:null};return(await t.updateTable("users").set(s).where("users.tenant_id","=",e).where("users.user_id","=",`${r}|${a}`).where("users.linked_to","=",`${n}`).execute()).length===1}}function Fs(t){return{create:Yr(t),remove:Ms(t),get:Ds(t),list:Rs(t),update:zs(t),unlink:Us(t)}}const Vs="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ke=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Vs[n[t]&63];return e};function Bs(t){return async e=>{const n={id:e.id||Ke(),created_at:new Date().toISOString(),updated_at:new Date().toISOString(),...e};return await t.insertInto("tenants").values(n).execute(),n}}function Ks(t){return async e=>{const n=await t.selectFrom("tenants").where("tenants.id","=",e).selectAll().executeTakeFirst();return n?M(n):null}}function Ws(t){return async e=>{let n=t.selectFrom("tenants");if(e.sort&&e.sort.sort_by){const{ref:d}=t.dynamic;n=n.orderBy(d(e.sort.sort_by),e.sort.sort_order)}e.q&&(n=n.where(d=>d.or([d("name","like",`%${e.q}%`)])));const a=await n.offset(e.page*e.per_page).limit(e.per_page).selectAll().execute();if(!e.include_totals)return{tenants:a};const{count:s}=await n.select(d=>d.fn.countAll().as("count")).executeTakeFirstOrThrow(),o=Ee(s);return{tenants:a.map(M),start:(e.page-1)*e.per_page,limit:e.per_page,length:o}}}function Js(t){return async(e,n)=>{const r={...n,id:e,updated_at:new Date().toISOString()};await t.updateTable("tenants").set(r).where("id","=",e).execute()}}function qs(t){return async e=>(await t.deleteFrom("tenants").where("tenants.id","=",e).execute()).length===1}function Qs(t){return{create:Bs(t),get:Ks(t),list:Ws(t),update:Js(t),remove:qs(t)}}function qn(t){return t?JSON.stringify(t):void 0}const Gs=1024;function Hs(t){return async(e,n)=>{var a,s,o;const r={id:Ke(),...n,user_agent:n.user_agent.slice(0,Gs)};return await t.insertInto("logs").values({...r,description:(a=r.description)==null?void 0:a.substring(0,256),isMobile:n.isMobile?1:0,tenant_id:e,scope:(s=n.scope)==null?void 0:s.join(","),auth0_client:qn(n.auth0_client),details:(o=qn(n.details))==null?void 0:o.substring(0,8192)}).execute(),r}}function Qn(t){if(!t)return"";try{return JSON.parse(t)}catch{return t}}function gr(t){return{...t,client_id:t.client_id,client_name:"",auth0_client:Qn(t.auth0_client),details:Qn(t.details),isMobile:!!t.isMobile,scope:t.scope?t.scope.split(","):void 0,log_id:t.id,_id:t.id}}function Ys(t){return async(e,n)=>{let r=t.selectFrom("logs").where("logs.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","ip"]));let a=r;if(n.sort&&n.sort.sort_by){const{ref:d}=t.dynamic;a=a.orderBy(d(n.sort.sort_by),n.sort.sort_order)}a=a.offset(n.page*n.per_page).limit(n.per_page);const s=await a.selectAll().execute(),{count:o}=await r.select(d=>d.fn.countAll().as("count")).executeTakeFirstOrThrow();return{logs:s.map(gr),start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function Xs(t){return async(e,n)=>{const r=await t.selectFrom("logs").where("logs.tenant_id","=",e).where("logs.id","=",n).selectAll().executeTakeFirst();return r?gr(r):null}}function ei(t){return{create:Hs(t),list:Ys(t),get:Xs(t)}}function ti(t){return async(e,n)=>await t.selectFrom("sessions").where("sessions.tenant_id","=",e).where("sessions.session_id","=",n).where("sessions.deleted_at","is",null).selectAll().executeTakeFirst()??null}function ni(t){return async(e,n)=>{const r={...n,created_at:new Date().toISOString(),expires_at:new Date().toISOString()};return await t.insertInto("sessions").values({...r,tenant_id:e}).execute(),{...n,...r}}}function ri(t){return async(e,n)=>!!(await t.updateTable("sessions").set({deleted_at:new Date().toISOString()}).where("tenant_id","=",e).where("sessions.session_id","=",n).where("sessions.deleted_at","is",null).execute()).length}function ai(t){return async(e,n,r)=>!!(await t.updateTable("sessions").set(r).where("tenant_id","=",e).where("sessions.session_id","=",n).where("sessions.deleted_at","is",null).execute()).length}function si(t){return async(e,n)=>{let r=t.selectFrom("sessions").where("sessions.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","session_id"]));let a=r;if(n.sort&&n.sort.sort_by){const{ref:c}=t.dynamic;a=a.orderBy(c(n.sort.sort_by),n.sort.sort_order)}a=a.offset(n.page*n.per_page).limit(n.per_page);const s=await a.selectAll().execute(),{count:o}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow(),d=Ee(o);return{sessions:s,start:n.page*n.per_page,limit:n.per_page,length:d}}}function ii(t){return{create:ni(t),get:ti(t),list:si(t),remove:ri(t),update:ai(t)}}function oi(t){return async(e,n)=>{const r=await t.selectFrom("tickets").where("tickets.tenant_id","=",e).where("tickets.id","=",n).where("tickets.used_at","is",null).selectAll().executeTakeFirst();if(!r)return null;const{nonce:a,state:s,scope:o,response_type:d,response_mode:c,redirect_uri:l,...u}=r;return{...u,authParams:{nonce:a,state:s,scope:o,response_type:d,response_mode:c,redirect_uri:l},created_at:new Date(r.created_at),expires_at:new Date(r.expires_at),used_at:r.used_at?new Date(r.used_at):void 0}}}function di(t){return async e=>{const{authParams:n,...r}=e,a={...r,...n,created_at:e.created_at.toISOString(),expires_at:e.expires_at.toISOString(),used_at:e.used_at?e.used_at.toISOString():void 0};await t.insertInto("tickets").values(a).execute()}}function ci(t){return async(e,n)=>{await t.updateTable("tickets").set({used_at:new Date().toISOString()}).where("tickets.tenant_id","=",e).where("tickets.id","=",n).execute()}}function li(t){return{create:di(t),get:oi(t),remove:ci(t)}}function ui(t){return async(e,n)=>{const r=await t.selectFrom("passwords").where("passwords.tenant_id","=",e).where("passwords.user_id","=",n).selectAll().executeTakeFirstOrThrow(),{tenant_id:a,...s}=r;return s}}function hi(t){return async(e,n)=>{const r={...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("passwords").values({...r,tenant_id:e}).execute(),r}}function pi(t){return async(e,n)=>(await t.updateTable("passwords").set({password:n.password,updated_at:new Date().toISOString()}).where("tenant_id","=",e).where("user_id","=",n.user_id).execute()).length===1}function mi(t){return{create:hi(t),update:pi(t),get:ui(t)}}function fi(t){return async(e,n)=>{let r=t.selectFrom("codes").where("codes.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["code","login_id"]));const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),{count:o}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{codes:s.map(c=>{const{tenant_id:l,...u}=c;return vs.parse(M(u))}),start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function _i(t){return async(e,n)=>{const r={...n,created_at:new Date().toISOString()};return await t.insertInto("codes").values({...r,tenant_id:e}).execute(),r}}function gi(t){return async(e,n)=>(await t.deleteFrom("codes").where("codes.tenant_id","=",e).where("codes.code_id","=",n).executeTakeFirst()).numDeletedRows>0}function yi(t){return async(e,n,r)=>{let a=t.selectFrom("codes").where("codes.code_id","=",n).where("codes.code_type","=",r).where("codes.expires_at",">",new Date().toISOString());e.length&&(a=a.where("codes.tenant_id","=",e));const s=await a.selectAll().executeTakeFirst();return s?M(s):null}}function vi(t){return{create:_i(t),list:fi(t),remove:gi(t),get:yi(t)}}function bi(t){return async(e,n)=>{const r={created_at:new Date().toISOString(),updated_at:new Date().toISOString(),...n},a=JSON.stringify(n.allowed_origins),s=JSON.stringify(n.callbacks),o=JSON.stringify(n.web_origins),d=JSON.stringify(n.allowed_logout_urls),c=JSON.stringify(n.allowed_clients);return await t.insertInto("applications").values({...r,tenant_id:e,disable_sign_ups:n.disable_sign_ups?1:0,addons:n.addons?JSON.stringify(n.addons):"{}",callbacks:s,allowed_origins:a,web_origins:o,allowed_logout_urls:d,allowed_clients:c}).execute(),r}}function wi(t){return async e=>({applications:(await t.selectFrom("applications").where("applications.tenant_id","=",e).selectAll().execute()).map(s=>({...s,disable_sign_ups:!!s.disable_sign_ups,addons:s.addons?JSON.parse(s.addons):{},callbacks:s.callbacks?JSON.parse(s.callbacks):[],allowed_origins:s.allowed_origins?JSON.parse(s.allowed_origins):[],web_origins:s.web_origins?JSON.parse(s.web_origins):[],allowed_logout_urls:s.allowed_logout_urls?JSON.parse(s.allowed_logout_urls):[],allowed_clients:s.allowed_logout_urls?JSON.parse(s.allowed_logout_urls):[]}))})}function xi(t){return async(e,n)=>{const r=await t.selectFrom("applications").where("applications.tenant_id","=",e).where("applications.id","=",n).selectAll().executeTakeFirst();return r?M({...r,disable_sign_ups:!!r.disable_sign_ups,addons:JSON.parse(r.addons),callbacks:JSON.parse(r.callbacks),allowed_origins:JSON.parse(r.allowed_origins),web_origins:JSON.parse(r.web_origins),allowed_logout_urls:JSON.parse(r.allowed_logout_urls)}):null}}function Ni(t){return async(e,n)=>(await t.deleteFrom("applications").where("applications.tenant_id","=",e).where("applications.id","=",n).executeTakeFirst()).numDeletedRows>0}function ki(t){return async(e,n,r)=>{const a={...r,updated_at:new Date().toISOString(),allowed_origins:r.allowed_origins?JSON.stringify(r.allowed_origins):void 0,callbacks:r.callbacks?JSON.stringify(r.callbacks):void 0,web_origins:r.web_origins?JSON.stringify(r.web_origins):void 0,allowed_logout_urls:r.allowed_logout_urls?JSON.stringify(r.allowed_logout_urls):void 0,allowed_clients:r.allowed_clients?JSON.stringify(r.allowed_clients):void 0,addons:r.addons?JSON.stringify(r.addons):"{}",disable_sign_ups:r.disable_sign_ups?1:0};return await t.updateTable("applications").set(a).where("applications.id","=",n).where("applications.tenant_id","=",e).execute(),!0}}function Ti(t){return{create:bi(t),list:wi(t),get:xi(t),remove:Ni(t),update:ki(t)}}function Ci(t){return async(e,n)=>{const r={id:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("connections").values({...r,options:JSON.stringify(r.options||{}),tenant_id:e}).execute(),r}}function Oi(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function Si(t,e){var n;return((n=t==null?void 0:t._def)===null||n===void 0?void 0:n.typeName)===e}function mt(t,e){const n=t.ZodType.prototype[e];t.ZodType.prototype[e]=function(...r){const a=n.apply(this,r);return a._def.openapi=this._def.openapi,a}}function ji(t){if(typeof t.ZodType.prototype.openapi<"u")return;t.ZodType.prototype.openapi=function(a,s){var o,d,c,l,u,Z;const R=typeof a=="string"?s:a,J=R??{},{param:_e}=J,We=Oi(J,["param"]),ge=Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o._internal),typeof a=="string"?{refId:a}:void 0),ye=Object.assign(Object.assign(Object.assign({},(d=this._def.openapi)===null||d===void 0?void 0:d.metadata),We),!((l=(c=this._def.openapi)===null||c===void 0?void 0:c.metadata)===null||l===void 0)&&l.param||_e?{param:Object.assign(Object.assign({},(Z=(u=this._def.openapi)===null||u===void 0?void 0:u.metadata)===null||Z===void 0?void 0:Z.param),_e)}:void 0),ve=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(ge).length>0?{_internal:ge}:void 0),Object.keys(ye).length>0?{metadata:ye}:void 0)}));if(Si(this,"ZodObject")){const Je=this.extend;ve.extend=function(...qe){var ee,te,ne,be,$e,Pe;const Ae=Je.apply(this,qe);return Ae._def.openapi={_internal:{extendedFrom:!((te=(ee=this._def.openapi)===null||ee===void 0?void 0:ee._internal)===null||te===void 0)&&te.refId?{refId:(be=(ne=this._def.openapi)===null||ne===void 0?void 0:ne._internal)===null||be===void 0?void 0:be.refId,schema:this}:($e=this._def.openapi)===null||$e===void 0?void 0:$e._internal.extendedFrom},metadata:(Pe=Ae._def.openapi)===null||Pe===void 0?void 0:Pe.metadata},Ae}}return ve},mt(t,"optional"),mt(t,"nullable"),mt(t,"default"),mt(t,"transform"),mt(t,"refine");const e=t.ZodObject.prototype.deepPartial;t.ZodObject.prototype.deepPartial=function(){const a=this._def.shape(),s=e.apply(this),o=s._def.shape();return Object.entries(o).forEach(([d,c])=>{var l,u;c._def.openapi=(u=(l=a[d])===null||l===void 0?void 0:l._def)===null||u===void 0?void 0:u.openapi}),s._def.openapi=void 0,s};const n=t.ZodObject.prototype.pick;t.ZodObject.prototype.pick=function(...a){const s=n.apply(this,a);return s._def.openapi=void 0,s};const r=t.ZodObject.prototype.omit;t.ZodObject.prototype.omit=function(...a){const s=r.apply(this,a);return s._def.openapi=void 0,s}}new Set(".\\+*[^]$()");var $;(function(t){t.assertEqual=a=>a;function e(a){}t.assertIs=e;function n(a){throw new Error}t.assertNever=n,t.arrayToEnum=a=>{const s={};for(const o of a)s[o]=o;return s},t.getValidEnumValues=a=>{const s=t.objectKeys(a).filter(d=>typeof a[a[d]]!="number"),o={};for(const d of s)o[d]=a[d];return t.objectValues(o)},t.objectValues=a=>t.objectKeys(a).map(function(s){return a[s]}),t.objectKeys=typeof Object.keys=="function"?a=>Object.keys(a):a=>{const s=[];for(const o in a)Object.prototype.hasOwnProperty.call(a,o)&&s.push(o);return s},t.find=(a,s)=>{for(const o of a)if(s(o))return o},t.isInteger=typeof Number.isInteger=="function"?a=>Number.isInteger(a):a=>typeof a=="number"&&isFinite(a)&&Math.floor(a)===a;function r(a,s=" | "){return a.map(o=>typeof o=="string"?`'${o}'`:o).join(s)}t.joinValues=r,t.jsonStringifyReplacer=(a,s)=>typeof s=="bigint"?s.toString():s})($||($={}));var Zn;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Zn||(Zn={}));const y=$.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ne=t=>{switch(typeof t){case"undefined":return y.undefined;case"string":return y.string;case"number":return isNaN(t)?y.nan:y.number;case"boolean":return y.boolean;case"function":return y.function;case"bigint":return y.bigint;case"symbol":return y.symbol;case"object":return Array.isArray(t)?y.array:t===null?y.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?y.promise:typeof Map<"u"&&t instanceof Map?y.map:typeof Set<"u"&&t instanceof Set?y.set:typeof Date<"u"&&t instanceof Date?y.date:y.object;default:return y.unknown}},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"]),Ii=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:");class W extends Error{constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const n=e||function(s){return s.message},r={_errors:[]},a=s=>{for(const o of s.issues)if(o.code==="invalid_union")o.unionErrors.map(a);else if(o.code==="invalid_return_type")a(o.returnTypeError);else if(o.code==="invalid_arguments")a(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let d=r,c=0;for(;c<o.path.length;){const l=o.path[c];c===o.path.length-1?(d[l]=d[l]||{_errors:[]},d[l]._errors.push(n(o))):d[l]=d[l]||{_errors:[]},d=d[l],c++}}};return a(this),r}static assert(e){if(!(e instanceof W))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,$.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},r=[];for(const a of this.issues)a.path.length>0?(n[a.path[0]]=n[a.path[0]]||[],n[a.path[0]].push(e(a))):r.push(e(a));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}W.create=t=>new W(t);const dt=(t,e)=>{let n;switch(t.code){case p.invalid_type:t.received===y.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case p.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,$.jsonStringifyReplacer)}`;break;case p.unrecognized_keys:n=`Unrecognized key(s) in object: ${$.joinValues(t.keys,", ")}`;break;case p.invalid_union:n="Invalid input";break;case p.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${$.joinValues(t.options)}`;break;case p.invalid_enum_value:n=`Invalid enum value. Expected ${$.joinValues(t.options)}, received '${t.received}'`;break;case p.invalid_arguments:n="Invalid function arguments";break;case p.invalid_return_type:n="Invalid function return type";break;case p.invalid_date:n="Invalid date";break;case p.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:$.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case p.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case p.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case p.custom:n="Invalid input";break;case p.invalid_intersection_types:n="Intersection results could not be merged";break;case p.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case p.not_finite:n="Number must be finite";break;default:n=e.defaultError,$.assertNever(t)}return{message:n}};let yr=dt;function Zi(t){yr=t}function ln(){return yr}const un=t=>{const{data:e,path:n,errorMaps:r,issueData:a}=t,s=[...n,...a.path||[]],o={...a,path:s};if(a.message!==void 0)return{...a,path:s,message:a.message};let d="";const c=r.filter(l=>!!l).slice().reverse();for(const l of c)d=l(o,{data:e,defaultError:d}).message;return{...a,path:s,message:d}},Ei=[];function _(t,e){const n=ln(),r=un({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===dt?void 0:dt].filter(a=>!!a)});t.common.issues.push(r)}class F{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const a of n){if(a.status==="aborted")return k;a.status==="dirty"&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const a of n){const s=await a.key,o=await a.value;r.push({key:s,value:o})}return F.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const a of n){const{key:s,value:o}=a;if(s.status==="aborted"||o.status==="aborted")return k;s.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof o.value<"u"||a.alwaysSet)&&(r[s.value]=o.value)}return{status:e.value,value:r}}}const k=Object.freeze({status:"aborted"}),tt=t=>({status:"dirty",value:t}),B=t=>({status:"valid",value:t}),En=t=>t.status==="aborted",$n=t=>t.status==="dirty",At=t=>t.status==="valid",Dt=t=>typeof Promise<"u"&&t instanceof Promise;function hn(t,e,n,r){if(typeof e=="function"?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(t)}function vr(t,e,n,r,a){if(typeof e=="function"?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,n),n}var w;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(w||(w={}));var gt,yt;class de{constructor(e,n,r,a){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=a}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Gn=(t,e)=>{if(At(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new W(t.common.issues);return this._error=n,this._error}}};function S(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:a}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(o,d)=>{var c,l;const{message:u}=t;return o.code==="invalid_enum_value"?{message:u??d.defaultError}:typeof d.data>"u"?{message:(c=u??r)!==null&&c!==void 0?c:d.defaultError}:o.code!=="invalid_type"?{message:d.defaultError}:{message:(l=u??n)!==null&&l!==void 0?l:d.defaultError}},description:a}}class I{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)}get description(){return this._def.description}_getType(e){return Ne(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:Ne(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new F,ctx:{common:e.parent.common,data:e.data,parsedType:Ne(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(Dt(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){var r;const a={common:{issues:[],async:(r=n==null?void 0:n.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ne(e)},s=this._parseSync({data:e,path:a.path,parent:a});return Gn(a,s)}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ne(e)},a=this._parse({data:e,path:r.path,parent:r}),s=await(Dt(a)?a:Promise.resolve(a));return Gn(r,s)}refine(e,n){const r=a=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(a):n;return this._refinement((a,s)=>{const o=e(a),d=()=>s.addIssue({code:p.custom,...r(a)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(d(),!1)):o?!0:(d(),!1)})}refinement(e,n){return this._refinement((r,a)=>e(r)?!0:(a.addIssue(typeof n=="function"?n(r,a):n),!1))}_refinement(e){return new X({schema:this,typeName:N.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return se.create(this,this._def)}nullable(){return Ze.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return H.create(this,this._def)}promise(){return lt.create(this,this._def)}or(e){return zt.create([this,e],this._def)}and(e){return Ut.create(this,e,this._def)}transform(e){return new X({...S(this._def),schema:this,typeName:N.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new Wt({...S(this._def),innerType:this,defaultValue:n,typeName:N.ZodDefault})}brand(){return new Bn({typeName:N.ZodBranded,type:this,...S(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new Jt({...S(this._def),innerType:this,catchValue:n,typeName:N.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Yt.create(this,e)}readonly(){return qt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const $i=/^c[^\s-]{8,}$/i,Pi=/^[0-9a-z]+$/,Ai=/^[0-9A-HJKMNP-TV-Z]{26}$/,Di=/^[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,Ri=/^[a-z0-9_-]{21}$/i,Mi=/^[-+]?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)?)??$/,Li=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,zi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let xn;const Ui=/^(?:(?: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])$/,Fi=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,Vi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,br="((\\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])))",Bi=new RegExp(`^${br}$`);function wr(t){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`),e}function Ki(t){return new RegExp(`^${wr(t)}$`)}function xr(t){let e=`${br}T${wr(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Wi(t,e){return!!((e==="v4"||!e)&&Ui.test(t)||(e==="v6"||!e)&&Fi.test(t))}class Q extends I{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==y.string){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.string,received:s.parsedType}),k}const r=new F;let a;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="max")e.data.length>s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="length"){const o=e.data.length>s.value,d=e.data.length<s.value;(o||d)&&(a=this._getOrReturnCtx(e,a),o?_(a,{code:p.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):d&&_(a,{code:p.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if(s.kind==="email")Li.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"email",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="emoji")xn||(xn=new RegExp(zi,"u")),xn.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"emoji",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="uuid")Di.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"uuid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="nanoid")Ri.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"nanoid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid")$i.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"cuid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid2")Pi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"cuid2",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="ulid")Ai.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"ulid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{a=this._getOrReturnCtx(e,a),_(a,{validation:"url",code:p.invalid_string,message:s.message}),r.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"regex",code:p.invalid_string,message:s.message}),r.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):s.kind==="datetime"?xr(s).test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:"datetime",message:s.message}),r.dirty()):s.kind==="date"?Bi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:"date",message:s.message}),r.dirty()):s.kind==="time"?Ki(s).test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:"time",message:s.message}),r.dirty()):s.kind==="duration"?Mi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"duration",code:p.invalid_string,message:s.message}),r.dirty()):s.kind==="ip"?Wi(e.data,s.version)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"ip",code:p.invalid_string,message:s.message}),r.dirty()):s.kind==="base64"?Vi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"base64",code:p.invalid_string,message:s.message}),r.dirty()):$.assertNever(s);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(a=>e.test(a),{validation:n,code:p.invalid_string,...w.errToObj(r)})}_addCheck(e){return new Q({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...w.errToObj(e)})}url(e){return this._addCheck({kind:"url",...w.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...w.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...w.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...w.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...w.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...w.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...w.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...w.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...w.errToObj(e)})}datetime(e){var n,r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(n=e==null?void 0:e.offset)!==null&&n!==void 0?n:!1,local:(r=e==null?void 0:e.local)!==null&&r!==void 0?r:!1,...w.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...w.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...w.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...w.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...w.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...w.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...w.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...w.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...w.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...w.errToObj(n)})}nonempty(e){return this.min(1,w.errToObj(e))}trim(){return new Q({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Q({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Q({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Q.create=t=>{var e;return new Q({checks:[],typeName:N.ZodString,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...S(t)})};function Ji(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,a=n>r?n:r,s=parseInt(t.toFixed(a).replace(".","")),o=parseInt(e.toFixed(a).replace(".",""));return s%o/Math.pow(10,a)}class Se extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==y.number){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.number,received:s.parsedType}),k}let r;const a=new F;for(const s of this._def.checks)s.kind==="int"?$.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{code:p.invalid_type,expected:"integer",received:"float",message:s.message}),a.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):s.kind==="multipleOf"?Ji(e.data,s.value)!==0&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{code:p.not_finite,message:s.message}),a.dirty()):$.assertNever(s);return{status:a.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,w.toString(n))}gt(e,n){return this.setLimit("min",e,!1,w.toString(n))}lte(e,n){return this.setLimit("max",e,!0,w.toString(n))}lt(e,n){return this.setLimit("max",e,!1,w.toString(n))}setLimit(e,n,r,a){return new Se({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:w.toString(a)}]})}_addCheck(e){return new Se({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:w.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:w.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:w.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:w.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:w.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&$.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}}Se.create=t=>new Se({checks:[],typeName:N.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...S(t)});class je extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==y.bigint){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.bigint,received:s.parsedType}),k}let r;const a=new F;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):$.assertNever(s);return{status:a.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,w.toString(n))}gt(e,n){return this.setLimit("min",e,!1,w.toString(n))}lte(e,n){return this.setLimit("max",e,!0,w.toString(n))}lt(e,n){return this.setLimit("max",e,!1,w.toString(n))}setLimit(e,n,r,a){return new je({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:w.toString(a)}]})}_addCheck(e){return new je({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:w.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}je.create=t=>{var e;return new je({checks:[],typeName:N.ZodBigInt,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...S(t)})};class Rt extends I{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==y.boolean){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.boolean,received:r.parsedType}),k}return B(e.data)}}Rt.create=t=>new Rt({typeName:N.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...S(t)});class Fe extends I{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==y.date){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.date,received:s.parsedType}),k}if(isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_date}),k}const r=new F;let a;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):$.assertNever(s);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Fe({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:w.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:w.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}Fe.create=t=>new Fe({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:N.ZodDate,...S(t)});class pn extends I{_parse(e){if(this._getType(e)!==y.symbol){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.symbol,received:r.parsedType}),k}return B(e.data)}}pn.create=t=>new pn({typeName:N.ZodSymbol,...S(t)});class Mt extends I{_parse(e){if(this._getType(e)!==y.undefined){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.undefined,received:r.parsedType}),k}return B(e.data)}}Mt.create=t=>new Mt({typeName:N.ZodUndefined,...S(t)});class Lt extends I{_parse(e){if(this._getType(e)!==y.null){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.null,received:r.parsedType}),k}return B(e.data)}}Lt.create=t=>new Lt({typeName:N.ZodNull,...S(t)});class ct extends I{constructor(){super(...arguments),this._any=!0}_parse(e){return B(e.data)}}ct.create=t=>new ct({typeName:N.ZodAny,...S(t)});class Le extends I{constructor(){super(...arguments),this._unknown=!0}_parse(e){return B(e.data)}}Le.create=t=>new Le({typeName:N.ZodUnknown,...S(t)});class fe extends I{_parse(e){const n=this._getOrReturnCtx(e);return _(n,{code:p.invalid_type,expected:y.never,received:n.parsedType}),k}}fe.create=t=>new fe({typeName:N.ZodNever,...S(t)});class mn extends I{_parse(e){if(this._getType(e)!==y.undefined){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.void,received:r.parsedType}),k}return B(e.data)}}mn.create=t=>new mn({typeName:N.ZodVoid,...S(t)});class H extends I{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),a=this._def;if(n.parsedType!==y.array)return _(n,{code:p.invalid_type,expected:y.array,received:n.parsedType}),k;if(a.exactLength!==null){const o=n.data.length>a.exactLength.value,d=n.data.length<a.exactLength.value;(o||d)&&(_(n,{code:o?p.too_big:p.too_small,minimum:d?a.exactLength.value:void 0,maximum:o?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(a.minLength!==null&&n.data.length<a.minLength.value&&(_(n,{code:p.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),a.maxLength!==null&&n.data.length>a.maxLength.value&&(_(n,{code:p.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,d)=>a.type._parseAsync(new de(n,o,n.path,d)))).then(o=>F.mergeArray(r,o));const s=[...n.data].map((o,d)=>a.type._parseSync(new de(n,o,n.path,d)));return F.mergeArray(r,s)}get element(){return this._def.type}min(e,n){return new H({...this._def,minLength:{value:e,message:w.toString(n)}})}max(e,n){return new H({...this._def,maxLength:{value:e,message:w.toString(n)}})}length(e,n){return new H({...this._def,exactLength:{value:e,message:w.toString(n)}})}nonempty(e){return this.min(1,e)}}H.create=(t,e)=>new H({type:t,minLength:null,maxLength:null,exactLength:null,typeName:N.ZodArray,...S(e)});function He(t){if(t instanceof D){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=se.create(He(r))}return new D({...t._def,shape:()=>e})}else return t instanceof H?new H({...t._def,type:He(t.element)}):t instanceof se?se.create(He(t.unwrap())):t instanceof Ze?Ze.create(He(t.unwrap())):t instanceof ce?ce.create(t.items.map(e=>He(e))):t}class D extends I{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=$.objectKeys(e);return this._cached={shape:e,keys:n}}_parse(e){if(this._getType(e)!==y.object){const l=this._getOrReturnCtx(e);return _(l,{code:p.invalid_type,expected:y.object,received:l.parsedType}),k}const{status:r,ctx:a}=this._processInputParams(e),{shape:s,keys:o}=this._getCached(),d=[];if(!(this._def.catchall instanceof fe&&this._def.unknownKeys==="strip"))for(const l in a.data)o.includes(l)||d.push(l);const c=[];for(const l of o){const u=s[l],Z=a.data[l];c.push({key:{status:"valid",value:l},value:u._parse(new de(a,Z,a.path,l)),alwaysSet:l in a.data})}if(this._def.catchall instanceof fe){const l=this._def.unknownKeys;if(l==="passthrough")for(const u of d)c.push({key:{status:"valid",value:u},value:{status:"valid",value:a.data[u]}});else if(l==="strict")d.length>0&&(_(a,{code:p.unrecognized_keys,keys:d}),r.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const u of d){const Z=a.data[u];c.push({key:{status:"valid",value:u},value:l._parse(new de(a,Z,a.path,u)),alwaysSet:u in a.data})}}return a.common.async?Promise.resolve().then(async()=>{const l=[];for(const u of c){const Z=await u.key,R=await u.value;l.push({key:Z,value:R,alwaysSet:u.alwaysSet})}return l}).then(l=>F.mergeObjectSync(r,l)):F.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(e){return w.errToObj,new D({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{var a,s,o,d;const c=(o=(s=(a=this._def).errorMap)===null||s===void 0?void 0:s.call(a,n,r).message)!==null&&o!==void 0?o:r.defaultError;return n.code==="unrecognized_keys"?{message:(d=w.errToObj(e).message)!==null&&d!==void 0?d:c}:{message:c}}}:{}})}strip(){return new D({...this._def,unknownKeys:"strip"})}passthrough(){return new D({...this._def,unknownKeys:"passthrough"})}extend(e){return new D({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new D({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:N.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new D({...this._def,catchall:e})}pick(e){const n={};return $.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new D({...this._def,shape:()=>n})}omit(e){const n={};return $.objectKeys(this.shape).forEach(r=>{e[r]||(n[r]=this.shape[r])}),new D({...this._def,shape:()=>n})}deepPartial(){return He(this)}partial(e){const n={};return $.objectKeys(this.shape).forEach(r=>{const a=this.shape[r];e&&!e[r]?n[r]=a:n[r]=a.optional()}),new D({...this._def,shape:()=>n})}required(e){const n={};return $.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])n[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof se;)s=s._def.innerType;n[r]=s}}),new D({...this._def,shape:()=>n})}keyof(){return Nr($.objectKeys(this.shape))}}D.create=(t,e)=>new D({shape:()=>t,unknownKeys:"strip",catchall:fe.create(),typeName:N.ZodObject,...S(e)});D.strictCreate=(t,e)=>new D({shape:()=>t,unknownKeys:"strict",catchall:fe.create(),typeName:N.ZodObject,...S(e)});D.lazycreate=(t,e)=>new D({shape:t,unknownKeys:"strip",catchall:fe.create(),typeName:N.ZodObject,...S(e)});class zt extends I{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function a(s){for(const d of s)if(d.result.status==="valid")return d.result;for(const d of s)if(d.result.status==="dirty")return n.common.issues.push(...d.ctx.common.issues),d.result;const o=s.map(d=>new W(d.ctx.common.issues));return _(n,{code:p.invalid_union,unionErrors:o}),k}if(n.common.async)return Promise.all(r.map(async s=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(a);{let s;const o=[];for(const c of r){const l={...n,common:{...n.common,issues:[]},parent:null},u=c._parseSync({data:n.data,path:n.path,parent:l});if(u.status==="valid")return u;u.status==="dirty"&&!s&&(s={result:u,ctx:l}),l.common.issues.length&&o.push(l.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const d=o.map(c=>new W(c));return _(n,{code:p.invalid_union,unionErrors:d}),k}}get options(){return this._def.options}}zt.create=(t,e)=>new zt({options:t,typeName:N.ZodUnion,...S(e)});const le=t=>t instanceof Vt?le(t.schema):t instanceof X?le(t.innerType()):t instanceof Bt?[t.value]:t instanceof Ie?t.options:t instanceof Kt?$.objectValues(t.enum):t instanceof Wt?le(t._def.innerType):t instanceof Mt?[void 0]:t instanceof Lt?[null]:t instanceof se?[void 0,...le(t.unwrap())]:t instanceof Ze?[null,...le(t.unwrap())]:t instanceof Bn||t instanceof qt?le(t.unwrap()):t instanceof Jt?le(t._def.innerType):[];class vn extends I{_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.object)return _(n,{code:p.invalid_type,expected:y.object,received:n.parsedType}),k;const r=this.discriminator,a=n.data[r],s=this.optionsMap.get(a);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(_(n,{code:p.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),k)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){const a=new Map;for(const s of n){const o=le(s.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const d of o){if(a.has(d))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(d)}`);a.set(d,s)}}return new vn({typeName:N.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:a,...S(r)})}}function Pn(t,e){const n=Ne(t),r=Ne(e);if(t===e)return{valid:!0,data:t};if(n===y.object&&r===y.object){const a=$.objectKeys(e),s=$.objectKeys(t).filter(d=>a.indexOf(d)!==-1),o={...t,...e};for(const d of s){const c=Pn(t[d],e[d]);if(!c.valid)return{valid:!1};o[d]=c.data}return{valid:!0,data:o}}else if(n===y.array&&r===y.array){if(t.length!==e.length)return{valid:!1};const a=[];for(let s=0;s<t.length;s++){const o=t[s],d=e[s],c=Pn(o,d);if(!c.valid)return{valid:!1};a.push(c.data)}return{valid:!0,data:a}}else return n===y.date&&r===y.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class Ut extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=(s,o)=>{if(En(s)||En(o))return k;const d=Pn(s.value,o.value);return d.valid?(($n(s)||$n(o))&&n.dirty(),{status:n.value,value:d.data}):(_(r,{code:p.invalid_intersection_types}),k)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,o])=>a(s,o)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Ut.create=(t,e,n)=>new Ut({left:t,right:e,typeName:N.ZodIntersection,...S(n)});class ce extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.array)return _(r,{code:p.invalid_type,expected:y.array,received:r.parsedType}),k;if(r.data.length<this._def.items.length)return _(r,{code:p.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),k;!this._def.rest&&r.data.length>this._def.items.length&&(_(r,{code:p.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const s=[...r.data].map((o,d)=>{const c=this._def.items[d]||this._def.rest;return c?c._parse(new de(r,o,r.path,d)):null}).filter(o=>!!o);return r.common.async?Promise.all(s).then(o=>F.mergeArray(n,o)):F.mergeArray(n,s)}get items(){return this._def.items}rest(e){return new ce({...this._def,rest:e})}}ce.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ce({items:t,typeName:N.ZodTuple,rest:null,...S(e)})};class Ft extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.object)return _(r,{code:p.invalid_type,expected:y.object,received:r.parsedType}),k;const a=[],s=this._def.keyType,o=this._def.valueType;for(const d in r.data)a.push({key:s._parse(new de(r,d,r.path,d)),value:o._parse(new de(r,r.data[d],r.path,d)),alwaysSet:d in r.data});return r.common.async?F.mergeObjectAsync(n,a):F.mergeObjectSync(n,a)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof I?new Ft({keyType:e,valueType:n,typeName:N.ZodRecord,...S(r)}):new Ft({keyType:Q.create(),valueType:e,typeName:N.ZodRecord,...S(n)})}}class fn extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.map)return _(r,{code:p.invalid_type,expected:y.map,received:r.parsedType}),k;const a=this._def.keyType,s=this._def.valueType,o=[...r.data.entries()].map(([d,c],l)=>({key:a._parse(new de(r,d,r.path,[l,"key"])),value:s._parse(new de(r,c,r.path,[l,"value"]))}));if(r.common.async){const d=new Map;return Promise.resolve().then(async()=>{for(const c of o){const l=await c.key,u=await c.value;if(l.status==="aborted"||u.status==="aborted")return k;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}})}else{const d=new Map;for(const c of o){const l=c.key,u=c.value;if(l.status==="aborted"||u.status==="aborted")return k;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}}}}fn.create=(t,e,n)=>new fn({valueType:e,keyType:t,typeName:N.ZodMap,...S(n)});class Ve extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.set)return _(r,{code:p.invalid_type,expected:y.set,received:r.parsedType}),k;const a=this._def;a.minSize!==null&&r.data.size<a.minSize.value&&(_(r,{code:p.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),n.dirty()),a.maxSize!==null&&r.data.size>a.maxSize.value&&(_(r,{code:p.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),n.dirty());const s=this._def.valueType;function o(c){const l=new Set;for(const u of c){if(u.status==="aborted")return k;u.status==="dirty"&&n.dirty(),l.add(u.value)}return{status:n.value,value:l}}const d=[...r.data.values()].map((c,l)=>s._parse(new de(r,c,r.path,l)));return r.common.async?Promise.all(d).then(c=>o(c)):o(d)}min(e,n){return new Ve({...this._def,minSize:{value:e,message:w.toString(n)}})}max(e,n){return new Ve({...this._def,maxSize:{value:e,message:w.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}Ve.create=(t,e)=>new Ve({valueType:t,minSize:null,maxSize:null,typeName:N.ZodSet,...S(e)});class rt extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.function)return _(n,{code:p.invalid_type,expected:y.function,received:n.parsedType}),k;function r(d,c){return un({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,ln(),dt].filter(l=>!!l),issueData:{code:p.invalid_arguments,argumentsError:c}})}function a(d,c){return un({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,ln(),dt].filter(l=>!!l),issueData:{code:p.invalid_return_type,returnTypeError:c}})}const s={errorMap:n.common.contextualErrorMap},o=n.data;if(this._def.returns instanceof lt){const d=this;return B(async function(...c){const l=new W([]),u=await d._def.args.parseAsync(c,s).catch(J=>{throw l.addIssue(r(c,J)),l}),Z=await Reflect.apply(o,this,u);return await d._def.returns._def.type.parseAsync(Z,s).catch(J=>{throw l.addIssue(a(Z,J)),l})})}else{const d=this;return B(function(...c){const l=d._def.args.safeParse(c,s);if(!l.success)throw new W([r(c,l.error)]);const u=Reflect.apply(o,this,l.data),Z=d._def.returns.safeParse(u,s);if(!Z.success)throw new W([a(u,Z.error)]);return Z.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new rt({...this._def,args:ce.create(e).rest(Le.create())})}returns(e){return new rt({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new rt({args:e||ce.create([]).rest(Le.create()),returns:n||Le.create(),typeName:N.ZodFunction,...S(r)})}}class Vt extends I{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Vt.create=(t,e)=>new Vt({getter:t,typeName:N.ZodLazy,...S(e)});class Bt extends I{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return _(n,{received:n.data,code:p.invalid_literal,expected:this._def.value}),k}return{status:"valid",value:e.data}}get value(){return this._def.value}}Bt.create=(t,e)=>new Bt({value:t,typeName:N.ZodLiteral,...S(e)});function Nr(t,e){return new Ie({values:t,typeName:N.ZodEnum,...S(e)})}class Ie extends I{constructor(){super(...arguments),gt.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return _(n,{expected:$.joinValues(r),received:n.parsedType,code:p.invalid_type}),k}if(hn(this,gt)||vr(this,gt,new Set(this._def.values)),!hn(this,gt).has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return _(n,{received:n.data,code:p.invalid_enum_value,options:r}),k}return B(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return Ie.create(e,{...this._def,...n})}exclude(e,n=this._def){return Ie.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}}gt=new WeakMap;Ie.create=Nr;class Kt extends I{constructor(){super(...arguments),yt.set(this,void 0)}_parse(e){const n=$.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==y.string&&r.parsedType!==y.number){const a=$.objectValues(n);return _(r,{expected:$.joinValues(a),received:r.parsedType,code:p.invalid_type}),k}if(hn(this,yt)||vr(this,yt,new Set($.getValidEnumValues(this._def.values))),!hn(this,yt).has(e.data)){const a=$.objectValues(n);return _(r,{received:r.data,code:p.invalid_enum_value,options:a}),k}return B(e.data)}get enum(){return this._def.values}}yt=new WeakMap;Kt.create=(t,e)=>new Kt({values:t,typeName:N.ZodNativeEnum,...S(e)});class lt extends I{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.promise&&n.common.async===!1)return _(n,{code:p.invalid_type,expected:y.promise,received:n.parsedType}),k;const r=n.parsedType===y.promise?n.data:Promise.resolve(n.data);return B(r.then(a=>this._def.type.parseAsync(a,{path:n.path,errorMap:n.common.contextualErrorMap})))}}lt.create=(t,e)=>new lt({type:t,typeName:N.ZodPromise,...S(e)});class X extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===N.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=this._def.effect||null,s={addIssue:o=>{_(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),a.type==="preprocess"){const o=a.transform(r.data,s);if(r.common.async)return Promise.resolve(o).then(async d=>{if(n.value==="aborted")return k;const c=await this._def.schema._parseAsync({data:d,path:r.path,parent:r});return c.status==="aborted"?k:c.status==="dirty"||n.value==="dirty"?tt(c.value):c});{if(n.value==="aborted")return k;const d=this._def.schema._parseSync({data:o,path:r.path,parent:r});return d.status==="aborted"?k:d.status==="dirty"||n.value==="dirty"?tt(d.value):d}}if(a.type==="refinement"){const o=d=>{const c=a.refinement(d,s);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return d};if(r.common.async===!1){const d=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return d.status==="aborted"?k:(d.status==="dirty"&&n.dirty(),o(d.value),{status:n.value,value:d.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(d=>d.status==="aborted"?k:(d.status==="dirty"&&n.dirty(),o(d.value).then(()=>({status:n.value,value:d.value}))))}if(a.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!At(o))return o;const d=a.transform(o.value,s);if(d instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:d}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>At(o)?Promise.resolve(a.transform(o.value,s)).then(d=>({status:n.value,value:d})):o);$.assertNever(a)}}X.create=(t,e,n)=>new X({schema:t,typeName:N.ZodEffects,effect:e,...S(n)});X.createWithPreprocess=(t,e,n)=>new X({schema:e,effect:{type:"preprocess",transform:t},typeName:N.ZodEffects,...S(n)});class se extends I{_parse(e){return this._getType(e)===y.undefined?B(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}se.create=(t,e)=>new se({innerType:t,typeName:N.ZodOptional,...S(e)});class Ze extends I{_parse(e){return this._getType(e)===y.null?B(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ze.create=(t,e)=>new Ze({innerType:t,typeName:N.ZodNullable,...S(e)});class Wt extends I{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===y.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Wt.create=(t,e)=>new Wt({innerType:t,typeName:N.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...S(e)});class Jt extends I{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Dt(a)?a.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new W(r.common.issues)},input:r.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new W(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Jt.create=(t,e)=>new Jt({innerType:t,typeName:N.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...S(e)});class _n extends I{_parse(e){if(this._getType(e)!==y.nan){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.nan,received:r.parsedType}),k}return{status:"valid",value:e.data}}}_n.create=t=>new _n({typeName:N.ZodNaN,...S(t)});const qi=Symbol("zod_brand");class Bn extends I{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Yt extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?k:s.status==="dirty"?(n.dirty(),tt(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{const a=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?k:a.status==="dirty"?(n.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:r.path,parent:r})}}static create(e,n){return new Yt({in:e,out:n,typeName:N.ZodPipeline})}}class qt extends I{_parse(e){const n=this._def.innerType._parse(e),r=a=>(At(a)&&(a.value=Object.freeze(a.value)),a);return Dt(n)?n.then(a=>r(a)):r(n)}unwrap(){return this._def.innerType}}qt.create=(t,e)=>new qt({innerType:t,typeName:N.ZodReadonly,...S(e)});function kr(t,e={},n){return t?ct.create().superRefine((r,a)=>{var s,o;if(!t(r)){const d=typeof e=="function"?e(r):typeof e=="string"?{message:e}:e,c=(o=(s=d.fatal)!==null&&s!==void 0?s:n)!==null&&o!==void 0?o:!0,l=typeof d=="string"?{message:d}:d;a.addIssue({code:"custom",...l,fatal:c})}}):ct.create()}const Qi={object:D.lazycreate};var N;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(N||(N={}));const Gi=(t,e={message:`Input not instance of ${t.name}`})=>kr(n=>n instanceof t,e),Tr=Q.create,Cr=Se.create,Hi=_n.create,Yi=je.create,Or=Rt.create,Xi=Fe.create,eo=pn.create,to=Mt.create,no=Lt.create,ro=ct.create,ao=Le.create,so=fe.create,io=mn.create,oo=H.create,co=D.create,lo=D.strictCreate,uo=zt.create,ho=vn.create,po=Ut.create,mo=ce.create,fo=Ft.create,_o=fn.create,go=Ve.create,yo=rt.create,vo=Vt.create,bo=Bt.create,wo=Ie.create,xo=Kt.create,No=lt.create,Hn=X.create,ko=se.create,To=Ze.create,Co=X.createWithPreprocess,Oo=Yt.create,So=()=>Tr().optional(),jo=()=>Cr().optional(),Io=()=>Or().optional(),Zo={string:t=>Q.create({...t,coerce:!0}),number:t=>Se.create({...t,coerce:!0}),boolean:t=>Rt.create({...t,coerce:!0}),bigint:t=>je.create({...t,coerce:!0}),date:t=>Fe.create({...t,coerce:!0})},Eo=k;var $o=Object.freeze({__proto__:null,defaultErrorMap:dt,setErrorMap:Zi,getErrorMap:ln,makeIssue:un,EMPTY_PATH:Ei,addIssueToContext:_,ParseStatus:F,INVALID:k,DIRTY:tt,OK:B,isAborted:En,isDirty:$n,isValid:At,isAsync:Dt,get util(){return $},get objectUtil(){return Zn},ZodParsedType:y,getParsedType:Ne,ZodType:I,datetimeRegex:xr,ZodString:Q,ZodNumber:Se,ZodBigInt:je,ZodBoolean:Rt,ZodDate:Fe,ZodSymbol:pn,ZodUndefined:Mt,ZodNull:Lt,ZodAny:ct,ZodUnknown:Le,ZodNever:fe,ZodVoid:mn,ZodArray:H,ZodObject:D,ZodUnion:zt,ZodDiscriminatedUnion:vn,ZodIntersection:Ut,ZodTuple:ce,ZodRecord:Ft,ZodMap:fn,ZodSet:Ve,ZodFunction:rt,ZodLazy:Vt,ZodLiteral:Bt,ZodEnum:Ie,ZodNativeEnum:Kt,ZodPromise:lt,ZodEffects:X,ZodTransformer:X,ZodOptional:se,ZodNullable:Ze,ZodDefault:Wt,ZodCatch:Jt,ZodNaN:_n,BRAND:qi,ZodBranded:Bn,ZodPipeline:Yt,ZodReadonly:qt,custom:kr,Schema:I,ZodSchema:I,late:Qi,get ZodFirstPartyTypeKind(){return N},coerce:Zo,any:ro,array:oo,bigint:Yi,boolean:Or,date:Xi,discriminatedUnion:ho,effect:Hn,enum:wo,function:yo,instanceof:Gi,intersection:po,lazy:vo,literal:bo,map:_o,nan:Hi,nativeEnum:xo,never:so,null:no,nullable:To,number:Cr,object:co,oboolean:Io,onumber:jo,optional:ko,ostring:So,pipeline:Oo,preprocess:Co,promise:No,record:fo,set:go,strictObject:lo,string:Tr,symbol:eo,transformer:Hn,tuple:mo,undefined:to,union:uo,unknown:ao,void:io,NEVER:Eo,ZodIssueCode:p,quotelessJson:Ii,ZodError:W});ji($o);function Xt(t,e="",n={}){for(let r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const a=e?`${e}_${r}`:r;typeof t[r]=="object"&&t[r]!==null&&!Array.isArray(t[r])?Xt(t[r],a,n):n[a]=t[r]}return n}function Sr(t,e){const n={};for(const[r,a]of Object.entries(t)){const s=e.find(o=>r.startsWith(`${o}_`));if(!s)n[r]=a;else{const o=r.slice(s.length+1);n[s]={...n[s],[o]:a}}}return n}function Po(t){return async(e,n)=>{let r=t.selectFrom("connections").where("connections.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","ip"]));const o=(await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute()).map(c=>M(Sr(c,["options"]))),{count:d}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{connections:o,start:n.page*n.per_page,limit:n.per_page,length:Ee(d)}}}function Ao(t){return async(e,n)=>(await t.deleteFrom("connections").where("connections.tenant_id","=",e).where("connections.id","=",n).executeTakeFirst()).numDeletedRows>0}function Do(t){return async(e,n)=>{const r=await t.selectFrom("connections").where("connections.tenant_id","=",e).where("connections.id","=",n).selectAll().executeTakeFirst();return r?M({...r,options:JSON.parse(r.options)}):null}}function Ro(t){return async(e,n,r)=>{const a={...r,updated_at:new Date().toISOString()};return await t.updateTable("connections").set({...a,options:a.options?JSON.stringify(a.options):void 0}).where("connections.id","=",n).where("connections.tenant_id","=",e).execute(),!0}}function Mo(t){return{create:Ci(t),get:Do(t),list:Po(t),remove:Ao(t),update:Ro(t)}}function Lo(t){return{get:async e=>{const n=await t.selectFrom("applications").selectAll().where("id","=",e).executeTakeFirst();if(!n)return null;const r=await t.selectFrom("tenants").selectAll().where("id","=",n.tenant_id).executeTakeFirst();if(!r)throw new Cn(404,{message:"Tenant not found"});const a=await t.selectFrom("connections").where("tenant_id","=",n.tenant_id).selectAll().execute(),s=await t.selectFrom("domains").where("tenant_id","=",n.tenant_id).selectAll().execute();return{...n,connections:a.map(d=>mr.parse(M({...d,options:d.options?JSON.parse(d.options):{}}))),domains:s,addons:n.addons?JSON.parse(n.addons):{},callbacks:n.callbacks?JSON.parse(n.callbacks):[],allowed_origins:n.allowed_origins?JSON.parse(n.allowed_origins):[],web_origins:n.web_origins?JSON.parse(n.web_origins):[],allowed_logout_urls:n.allowed_logout_urls?JSON.parse(n.allowed_logout_urls):[],allowed_clients:n.allowed_clients?JSON.parse(n.allowed_clients):[],tenant:M(r),disable_sign_ups:!!n.disable_sign_ups}}}}function zo(t){return async()=>await t.selectFrom("keys").where(n=>n.or([n("revoked_at",">",new Date().toISOString()),n("revoked_at","is",null)])).selectAll().execute()}function Uo(t){return async e=>{await t.insertInto("keys").values({...e,created_at:new Date().toDateString()}).execute()}}function Fo(t){return async(e,n)=>!!(await t.updateTable("keys").set(n).where("kid","=",e).execute()).length}function Vo(t){return{create:Uo(t),list:zo(t),update:Fo(t)}}function Bo(t){return async(e,n)=>{const r={created_at:new Date().toISOString(),updated_at:new Date().toISOString(),tenant_id:e,id:Ke(),...n};return await t.insertInto("domains").values(r).execute(),r}}function Ko(t){return async(e,n)=>{let r=t.selectFrom("domains").where("domains.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","ip"]));const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),{count:o}=await r.select(d=>d.fn.countAll().as("count")).executeTakeFirstOrThrow();return{domains:s,start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function Wo(t){return{create:Bo(t),list:Ko(t)}}function Jo(t){return async e=>{const[n]=await t.selectFrom("branding").where("branding.tenant_id","=",e).selectAll().execute();if(!n)return null;const{tenant_id:r,colors_primary:a,colors_page_background_type:s,colors_page_background_start:o,colors_page_background_end:d,colors_page_background_angle_dev:c,font_url:l,...u}=n;return M({...u,colors:{primary:a,page_background:{type:s,start:o,end:d,angle_deg:c}},font:l?{url:l}:void 0})}}function qo(t){return async(e,n)=>{var o,d,c,l,u,Z,R,J,_e,We,ge,ye,ve,Je,qe,ee,te,ne;const{colors:r,font:a,...s}=n;try{await t.insertInto("branding").values({...s,colors_primary:r==null?void 0:r.primary,colors_page_background_type:(d=(o=n.colors)==null?void 0:o.page_background)==null?void 0:d.type,colors_page_background_start:(l=(c=n.colors)==null?void 0:c.page_background)==null?void 0:l.start,colors_page_background_end:(Z=(u=n.colors)==null?void 0:u.page_background)==null?void 0:Z.end,colors_page_background_angle_dev:(J=(R=n.colors)==null?void 0:R.page_background)==null?void 0:J.angle_deg,font_url:(_e=n.font)==null?void 0:_e.url,tenant_id:e}).execute()}catch{await t.updateTable("branding").set({...s,colors_primary:r==null?void 0:r.primary,colors_page_background_type:(ge=(We=n.colors)==null?void 0:We.page_background)==null?void 0:ge.type,colors_page_background_start:(ve=(ye=n.colors)==null?void 0:ye.page_background)==null?void 0:ve.start,colors_page_background_end:(qe=(Je=n.colors)==null?void 0:Je.page_background)==null?void 0:qe.end,colors_page_background_angle_dev:(te=(ee=n.colors)==null?void 0:ee.page_background)==null?void 0:te.angle_deg,font_url:(ne=n.font)==null?void 0:ne.url}).where("tenant_id","=",e).execute()}}}function Qo(t){return{get:Jo(t),set:qo(t)}}function Go(t){return async(e,n)=>{let r=t.selectFrom("hooks").where("hooks.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["url"]));const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),{count:o}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{hooks:s.map(c=>{const{tenant_id:l,enabled:u,synchronous:Z,...R}=c;return M({...R,enabled:!!u,synchronous:!!Z})}),start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function Ho(t){return async(e,n)=>{const r=await t.selectFrom("hooks").where("hooks.tenant_id","=",e).where("hooks.hook_id","=",n).selectAll().executeTakeFirst();return r?M({...r,enabled:!!r.enabled,synchronous:!!r.synchronous}):null}}function Yo(t){return async(e,n)=>(await t.deleteFrom("hooks").where("hooks.tenant_id","=",e).where("hooks.hook_id","=",n).executeTakeFirst()).numDeletedRows>0}function Xo(t){return async(e,n)=>{const r={hook_id:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("hooks").values({...r,tenant_id:e,enabled:n.enabled?1:0,synchronous:n.synchronous?1:0}).execute(),r}}function ed(t){return async(e,n,r)=>{const a={...r,updated_at:new Date().toISOString(),enabled:r.enabled!==void 0?r.enabled?1:0:void 0,synchronous:r.enabled!==void 0?r.synchronous?1:0:void 0};return await t.updateTable("hooks").set(a).where("hooks.hook_id","=",n).where("hooks.tenant_id","=",e).execute(),!0}}function td(t){return{create:Xo(t),get:Ho(t),list:Go(t),update:ed(t),remove:Yo(t)}}function nd(t){return async(e,n)=>{const r={themeId:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("themes").values({...Xt(r),tenant_id:e}).execute(),r}}function rd(t){return async(e,n)=>(await t.deleteFrom("themes").where("themes.tenant_id","=",e).where("themes.theme_id","=",n).executeTakeFirst()).numDeletedRows>0}function ad(t){return async(e,n)=>{const r=await t.selectFrom("themes").where("themes.tenant_id","=",e).where("themes.theme_id","=",n).selectAll().executeTakeFirst();return r?M(r):null}}function sd(t){return async(e,n,r)=>{const a=Xt({...r,updated_at:new Date().toISOString()});return await t.updateTable("themes").set(a).where("themes.id","=",n).where("themes.tenant_id","=",e).execute(),!0}}function id(t){return{create:nd(t),get:ad(t),remove:rd(t),update:sd(t)}}function od(t){return async(e,n)=>{const r=new Date().toISOString(),a=await t.selectFrom("logins").where("logins.expires_at",">",r).where("logins.login_id","=",n).selectAll().executeTakeFirst();return a?ks.parse(Sr(M(a),["authParams"])):null}}function dd(t){return async(e,n)=>{const r={login_id:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("logins").values({...Xt(r),tenant_id:e}).execute(),r}}function cd(t){return async(e,n,r)=>(await t.updateTable("logins").set(Xt(r)).where("logins.login_id","=",n).where("logins.tenant_id","=",e).execute()).length===1}function ld(t){return async(e,n)=>(await t.deleteFrom("logins").where("logins.tenant_id","=",e).where("logins.login_id","=",n).execute()).length>0}function ud(t){return{create:dd(t),get:od(t),update:cd(t),remove:ld(t)}}function hd(t){return async e=>{const[n]=await t.selectFrom("prompt_settings").where("prompt_settings.tenant_id","=",e).selectAll().execute();return M({identifier_first:!!(n!=null&&n.identifier_first),password_first:!!(n!=null&&n.password_first),webauthn_platform_first_factor:!!(n!=null&&n.webauthn_platform_first_factor),universal_login_experience:(n==null?void 0:n.universal_login_experience)||"new"})}}function Yn(t){return M({...t,webauthn_platform_first_factor:t.webauthn_platform_first_factor?!!t.webauthn_platform_first_factor:void 0,identifier_first:t.identifier_first?!!t.identifier_first:void 0,password_first:t.password_first?!!t.password_first:void 0,universal_login_experience:t.universal_login_experience})}function pd(t){return async(e,n)=>{try{const r=As.parse(n);await t.insertInto("prompt_settings").values({...Yn(r),tenant_id:e}).execute()}catch{await t.updateTable("prompt_settings").set(Yn(n)).where("tenant_id","=",e).execute()}}}function md(t){return{get:hd(t),set:pd(t)}}function fd(t){return t[t.length-1]}function z(t){return Object.freeze(t)}const en=z({is(t){return t.kind==="IdentifierNode"},create(t){return z({kind:"IdentifierNode",name:t})}}),An=z({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return z({kind:"SchemableIdentifierNode",identifier:en.create(t)})},createWithSchema(t,e){return z({kind:"SchemableIdentifierNode",schema:en.create(t),identifier:en.create(e)})}}),_d=z({is(t){return t.kind==="AliasNode"},create(t,e){return z({kind:"AliasNode",node:t,alias:e})}}),Nn=z({is(t){return t.kind==="TableNode"},create(t){return z({kind:"TableNode",table:An.create(t)})},createWithSchema(t,e){return z({kind:"TableNode",table:An.createWithSchema(t,e)})}});var gn;class gd{constructor(){ut(this,"nodeStack",[]);re(this,gn,z({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this)}))}transformNode(e){if(!e)return e;this.nodeStack.push(e);const n=this.transformNodeImpl(e);return this.nodeStack.pop(),z(n)}transformNodeImpl(e){return v(this,gn)[e.kind](e)}transformNodeList(e){return e&&z(e.map(n=>this.transformNode(n)))}transformSelectQuery(e){return{kind:"SelectQueryNode",from:this.transformNode(e.from),selections:this.transformNodeList(e.selections),distinctOn:this.transformNodeList(e.distinctOn),joins:this.transformNodeList(e.joins),groupBy:this.transformNode(e.groupBy),orderBy:this.transformNode(e.orderBy),where:this.transformNode(e.where),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),limit:this.transformNode(e.limit),offset:this.transformNode(e.offset),with:this.transformNode(e.with),having:this.transformNode(e.having),explain:this.transformNode(e.explain),setOperations:this.transformNodeList(e.setOperations),fetch:this.transformNode(e.fetch),top:this.transformNode(e.top)}}transformSelection(e){return{kind:"SelectionNode",selection:this.transformNode(e.selection)}}transformColumn(e){return{kind:"ColumnNode",column:this.transformNode(e.column)}}transformAlias(e){return{kind:"AliasNode",node:this.transformNode(e.node),alias:this.transformNode(e.alias)}}transformTable(e){return{kind:"TableNode",table:this.transformNode(e.table)}}transformFrom(e){return{kind:"FromNode",froms:this.transformNodeList(e.froms)}}transformReference(e){return{kind:"ReferenceNode",column:this.transformNode(e.column),table:this.transformNode(e.table)}}transformAnd(e){return{kind:"AndNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformOr(e){return{kind:"OrNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformValueList(e){return{kind:"ValueListNode",values:this.transformNodeList(e.values)}}transformParens(e){return{kind:"ParensNode",node:this.transformNode(e.node)}}transformJoin(e){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table),on:this.transformNode(e.on)}}transformRaw(e){return{kind:"RawNode",sqlFragments:z([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters)}}transformWhere(e){return{kind:"WhereNode",where:this.transformNode(e.where)}}transformInsertQuery(e){return{kind:"InsertQueryNode",into:this.transformNode(e.into),columns:this.transformNodeList(e.columns),values:this.transformNode(e.values),returning:this.transformNode(e.returning),onConflict:this.transformNode(e.onConflict),onDuplicateKey:this.transformNode(e.onDuplicateKey),with:this.transformNode(e.with),ignore:e.ignore,replace:e.replace,explain:this.transformNode(e.explain),defaultValues:e.defaultValues,top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformValues(e){return{kind:"ValuesNode",values:this.transformNodeList(e.values)}}transformDeleteQuery(e){return{kind:"DeleteQueryNode",from:this.transformNode(e.from),using:this.transformNode(e.using),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),returning:this.transformNode(e.returning),with:this.transformNode(e.with),orderBy:this.transformNode(e.orderBy),limit:this.transformNode(e.limit),explain:this.transformNode(e.explain),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformReturning(e){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections)}}transformCreateTable(e){return{kind:"CreateTableNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),constraints:this.transformNodeList(e.constraints),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),selectQuery:this.transformNode(e.selectQuery)}}transformColumnDefinition(e){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),references:this.transformNode(e.references),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo),check:this.transformNode(e.check),generated:this.transformNode(e.generated),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e){return{kind:"AddColumnNode",column:this.transformNode(e.column)}}transformDropTable(e){return{kind:"DropTableNode",table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e){return{kind:"OrderByNode",items:this.transformNodeList(e.items)}}transformOrderByItem(e){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy),direction:this.transformNode(e.direction)}}transformGroupBy(e){return{kind:"GroupByNode",items:this.transformNodeList(e.items)}}transformGroupByItem(e){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy)}}transformUpdateQuery(e){return{kind:"UpdateQueryNode",table:this.transformNode(e.table),from:this.transformNode(e.from),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),updates:this.transformNodeList(e.updates),returning:this.transformNode(e.returning),with:this.transformNode(e.with),explain:this.transformNode(e.explain),limit:this.transformNode(e.limit),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformColumnUpdate(e){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column),value:this.transformNode(e.value)}}transformLimit(e){return{kind:"LimitNode",limit:this.transformNode(e.limit)}}transformOffset(e){return{kind:"OffsetNode",offset:this.transformNode(e.offset)}}transformOnConflict(e){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns),constraint:this.transformNode(e.constraint),indexExpression:this.transformNode(e.indexExpression),indexWhere:this.transformNode(e.indexWhere),updates:this.transformNodeList(e.updates),updateWhere:this.transformNode(e.updateWhere),doNothing:e.doNothing}}transformOnDuplicateKey(e){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates)}}transformCreateIndex(e){return{kind:"CreateIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists,where:this.transformNode(e.where),nullsNotDistinct:e.nullsNotDistinct}}transformList(e){return{kind:"ListNode",items:this.transformNodeList(e.items)}}transformDropIndex(e){return{kind:"DropIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name)}}transformUniqueConstraint(e){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name),nullsNotDistinct:e.nullsNotDistinct}}transformForeignKeyConstraint(e){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns),references:this.transformNode(e.references),name:this.transformNode(e.name),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformSetOperation(e){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression),all:e.all}}transformReferences(e){return{kind:"ReferencesNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression),name:this.transformNode(e.name)}}transformWith(e){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions),recursive:e.recursive}}transformCommonTableExpression(e){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name),materialized:e.materialized,expression:this.transformNode(e.expression)}}transformCommonTableExpressionName(e){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns)}}transformHaving(e){return{kind:"HavingNode",having:this.transformNode(e.having)}}transformCreateSchema(e){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema),ifNotExists:e.ifNotExists}}transformDropSchema(e){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e){return{kind:"AlterTableNode",table:this.transformNode(e.table),renameTo:this.transformNode(e.renameTo),setSchema:this.transformNode(e.setSchema),columnAlterations:this.transformNodeList(e.columnAlterations),addConstraint:this.transformNode(e.addConstraint),dropConstraint:this.transformNode(e.dropConstraint),addIndex:this.transformNode(e.addIndex),dropIndex:this.transformNode(e.dropIndex)}}transformDropColumn(e){return{kind:"DropColumnNode",column:this.transformNode(e.column)}}transformRenameColumn(e){return{kind:"RenameColumnNode",column:this.transformNode(e.column),renameTo:this.transformNode(e.renameTo)}}transformAlterColumn(e){return{kind:"AlterColumnNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),dataTypeExpression:this.transformNode(e.dataTypeExpression),setDefault:this.transformNode(e.setDefault),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e){return{kind:"ModifyColumnNode",column:this.transformNode(e.column)}}transformAddConstraint(e){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint)}}transformDropConstraint(e){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName),ifExists:e.ifExists,modifier:e.modifier}}transformCreateView(e){return{kind:"CreateViewNode",name:this.transformNode(e.name),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns),as:this.transformNode(e.as)}}transformDropView(e){return{kind:"DropViewNode",name:this.transformNode(e.name),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression)}}transformDefaultValue(e){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue)}}transformOn(e){return{kind:"OnNode",on:this.transformNode(e.on)}}transformSelectModifier(e){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier),of:this.transformNodeList(e.of)}}transformCreateType(e){return{kind:"CreateTypeNode",name:this.transformNode(e.name),enum:this.transformNode(e.enum)}}transformDropType(e){return{kind:"DropTypeNode",name:this.transformNode(e.name),ifExists:e.ifExists}}transformExplain(e){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options)}}transformSchemableIdentifier(e){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema),identifier:this.transformNode(e.identifier)}}transformAggregateFunction(e){return{kind:"AggregateFunctionNode",aggregated:this.transformNodeList(e.aggregated),distinct:e.distinct,filter:this.transformNode(e.filter),func:e.func,over:this.transformNode(e.over)}}transformOver(e){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy),partitionBy:this.transformNode(e.partitionBy)}}transformPartitionBy(e){return{kind:"PartitionByNode",items:this.transformNodeList(e.items)}}transformPartitionByItem(e){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy)}}transformBinaryOperation(e){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand),operator:this.transformNode(e.operator),rightOperand:this.transformNode(e.rightOperand)}}transformUnaryOperation(e){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator),operand:this.transformNode(e.operand)}}transformUsing(e){return{kind:"UsingNode",tables:this.transformNodeList(e.tables)}}transformFunction(e){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments)}}transformCase(e){return{kind:"CaseNode",value:this.transformNode(e.value),when:this.transformNodeList(e.when),else:this.transformNode(e.else),isStatement:e.isStatement}}transformWhen(e){return{kind:"WhenNode",condition:this.transformNode(e.condition),result:this.transformNode(e.result)}}transformJSONReference(e){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference),traversal:this.transformNode(e.traversal)}}transformJSONPath(e){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator),pathLegs:this.transformNodeList(e.pathLegs)}}transformJSONPathLeg(e){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator),values:this.transformNodeList(e.values)}}transformTuple(e){return{kind:"TupleNode",values:this.transformNodeList(e.values)}}transformMergeQuery(e){return{kind:"MergeQueryNode",into:this.transformNode(e.into),using:this.transformNode(e.using),whens:this.transformNodeList(e.whens),with:this.transformNode(e.with),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformMatched(e){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e){return{kind:"AddIndexNode",name:this.transformNode(e.name),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists}}transformCast(e){return{kind:"CastNode",expression:this.transformNode(e.expression),dataType:this.transformNode(e.dataType)}}transformFetch(e){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount),modifier:e.modifier}}transformTop(e){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e){return{kind:"OutputNode",selections:this.transformNodeList(e.selections)}}transformDataType(e){return e}transformSelectAll(e){return e}transformIdentifier(e){return e}transformValue(e){return e}transformPrimitiveValueList(e){return e}transformOperator(e){return e}transformDefaultInsertValue(e){return e}}gn=new WeakMap;const yd=z({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0});var at,De,Re,L,jr,Ir,Zr,Ye,Dn,Er;class vd extends gd{constructor(n){super();re(this,L);re(this,at);re(this,De,new Set);re(this,Re,new Set);ht(this,at,n)}transformNodeImpl(n){if(!C(this,L,jr).call(this,n))return super.transformNodeImpl(n);const r=C(this,L,Zr).call(this,n);for(const o of r)v(this,Re).add(o);const a=C(this,L,Ir).call(this,n);for(const o of a)v(this,De).add(o);const s=super.transformNodeImpl(n);for(const o of a)v(this,De).delete(o);for(const o of r)v(this,Re).delete(o);return s}transformSchemableIdentifier(n){const r=super.transformSchemableIdentifier(n);return r.schema||!v(this,De).has(n.identifier.name)?r:{...r,schema:en.create(v(this,at))}}transformReferences(n){const r=super.transformReferences(n);return r.table.table.schema?r:{...r,table:Nn.createWithSchema(v(this,at),r.table.table.identifier.name)}}}at=new WeakMap,De=new WeakMap,Re=new WeakMap,L=new WeakSet,jr=function(n){return n.kind in yd},Ir=function(n){const r=new Set;if("name"in n&&n.name&&An.is(n.name)&&C(this,L,Dn).call(this,n.name,r),"from"in n&&n.from)for(const a of n.from.froms)C(this,L,Ye).call(this,a,r);if("into"in n&&n.into&&C(this,L,Ye).call(this,n.into,r),"table"in n&&n.table&&C(this,L,Ye).call(this,n.table,r),"joins"in n&&n.joins)for(const a of n.joins)C(this,L,Ye).call(this,a.table,r);return"using"in n&&n.using&&C(this,L,Ye).call(this,n.using,r),r},Zr=function(n){const r=new Set;return"with"in n&&n.with&&C(this,L,Er).call(this,n.with,r),r},Ye=function(n,r){const a=Nn.is(n)?n:_d.is(n)&&Nn.is(n.node)?n.node:null;a&&C(this,L,Dn).call(this,a.table,r)},Dn=function(n,r){const a=n.identifier.name;!v(this,De).has(a)&&!v(this,Re).has(a)&&r.add(a)},Er=function(n,r){for(const a of n.expressions){const s=a.name.table.table.identifier.name;v(this,Re).has(s)||r.add(s)}};var Qt;class bd{constructor(e){re(this,Qt);ht(this,Qt,new vd(e))}transformQuery(e){return v(this,Qt).transformNode(e.node)}async transformResult(e){return e.result}}Qt=new WeakMap;class wd{transformQuery(e){return e.node}async transformResult(e){return e.result}}const xd="kysely_migration",Xn="kysely_migration_lock",Nd=!1,kn="migration_lock",kd=z({__noMigrations__:!0});var P,m,vt,ue,he,Xe,Pr,pe,Ar,Dr,Rr,Mr,Lr,Rn,et,Mn,zr,Ur,Fr,Ln,Vr,Br,Kr,Wr,Jr,bt;class $r{constructor(e){re(this,m);re(this,P);ht(this,P,z(e))}async getMigrations(){const e=await C(this,m,et).call(this,v(this,m,he))?await v(this,P).db.withPlugin(v(this,m,pe)).selectFrom(v(this,m,he)).select(["name","timestamp"]).execute():[];return(await C(this,m,Ln).call(this)).map(({name:r,...a})=>{const s=e.find(o=>o.name===r);return{name:r,migration:a,executedAt:s?new Date(s.timestamp):void 0}})}async migrateToLatest(){return C(this,m,vt).call(this,()=>({direction:"Up",step:1/0}))}async migrateTo(e){return C(this,m,vt).call(this,({migrations:n,executedMigrations:r,pendingMigrations:a})=>{if(e===kd)return{direction:"Down",step:1/0};if(!n.find(d=>d.name===e))throw new Error(`migration "${e}" doesn't exist`);const s=r.indexOf(e),o=a.findIndex(d=>d.name===e);if(s!==-1)return{direction:"Down",step:r.length-s-1};if(o!==-1)return{direction:"Up",step:o+1};throw new Error(`migration "${e}" isn't executed or pending`)})}async migrateUp(){return C(this,m,vt).call(this,()=>({direction:"Up",step:1}))}async migrateDown(){return C(this,m,vt).call(this,()=>({direction:"Down",step:1}))}}P=new WeakMap,m=new WeakSet,vt=async function(e){try{return await C(this,m,Ar).call(this),await C(this,m,zr).call(this,e)}catch(n){return n instanceof Tn?n.resultSet:{error:n}}},ue=function(){return v(this,P).migrationTableSchema},he=function(){return v(this,P).migrationTableName??xd},Xe=function(){return v(this,P).migrationLockTableName??Xn},Pr=function(){return v(this,P).allowUnorderedMigrations??Nd},pe=function(){return v(this,m,ue)?new bd(v(this,m,ue)):new wd},Ar=async function(){await C(this,m,Dr).call(this),await C(this,m,Rr).call(this),await C(this,m,Mr).call(this),await C(this,m,Lr).call(this)},Dr=async function(){if(v(this,m,ue)&&!await C(this,m,Rn).call(this))try{await C(this,m,bt).call(this,v(this,P).db.schema.createSchema(v(this,m,ue)))}catch(e){if(!await C(this,m,Rn).call(this))throw e}},Rr=async function(){if(!await C(this,m,et).call(this,v(this,m,he)))try{v(this,m,ue)&&await C(this,m,bt).call(this,v(this,P).db.schema.createSchema(v(this,m,ue))),await C(this,m,bt).call(this,v(this,P).db.schema.withPlugin(v(this,m,pe)).createTable(v(this,m,he)).addColumn("name","varchar(255)",e=>e.notNull().primaryKey()).addColumn("timestamp","varchar(255)",e=>e.notNull()))}catch(e){if(!await C(this,m,et).call(this,v(this,m,he)))throw e}},Mr=async function(){if(!await C(this,m,et).call(this,v(this,m,Xe)))try{await C(this,m,bt).call(this,v(this,P).db.schema.withPlugin(v(this,m,pe)).createTable(v(this,m,Xe)).addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("is_locked","integer",e=>e.notNull().defaultTo(0)))}catch(e){if(!await C(this,m,et).call(this,v(this,m,Xe)))throw e}},Lr=async function(){if(!await C(this,m,Mn).call(this))try{await v(this,P).db.withPlugin(v(this,m,pe)).insertInto(v(this,m,Xe)).values({id:kn,is_locked:0}).execute()}catch(e){if(!await C(this,m,Mn).call(this))throw e}},Rn=async function(){return(await v(this,P).db.introspection.getSchemas()).some(n=>n.name===v(this,m,ue))},et=async function(e){const n=v(this,m,ue);return(await v(this,P).db.introspection.getTables({withInternalKyselyTables:!0})).some(a=>a.name===e&&(!n||a.schema===n))},Mn=async function(){return!!await v(this,P).db.withPlugin(v(this,m,pe)).selectFrom(v(this,m,Xe)).where("id","=",kn).select("id").executeTakeFirst()},zr=async function(e){const n=v(this,P).db.getExecutor().adapter,r=z({lockTable:v(this,P).migrationLockTableName??Xn,lockRowId:kn,lockTableSchema:v(this,P).migrationTableSchema}),a=async s=>{try{await n.acquireMigrationLock(s,r);const o=await C(this,m,Ur).call(this,s);if(o.migrations.length===0)return{results:[]};const{direction:d,step:c}=e(o);return c<=0?{results:[]}:d==="Down"?await C(this,m,Wr).call(this,s,o,c):d==="Up"?await C(this,m,Jr).call(this,s,o,c):{results:[]}}finally{await n.releaseMigrationLock(s,r)}};return n.supportsTransactionalDdl?v(this,P).db.transaction().execute(a):v(this,P).db.connection().execute(a)},Ur=async function(e){const n=await C(this,m,Ln).call(this),r=await C(this,m,Vr).call(this,e);C(this,m,Br).call(this,n,r),v(this,m,Pr)||C(this,m,Kr).call(this,n,r);const a=C(this,m,Fr).call(this,n,r);return z({migrations:n,executedMigrations:r,lastMigration:fd(r),pendingMigrations:a})},Fr=function(e,n){return e.filter(r=>!n.includes(r.name))},Ln=async function(){const e=await v(this,P).provider.getMigrations();return Object.keys(e).sort().map(n=>({...e[n],name:n}))},Vr=async function(e){return(await e.withPlugin(v(this,m,pe)).selectFrom(v(this,m,he)).select("name").orderBy(["timestamp","name"]).execute()).map(r=>r.name)},Br=function(e,n){for(const r of n)if(!e.some(a=>a.name===r))throw new Error(`corrupted migrations: previously executed migration ${r} is missing`)},Kr=function(e,n){for(let r=0;r<n.length;++r)if(e[r].name!==n[r])throw new Error(`corrupted migrations: expected previously executed migration ${n[r]} to be at index ${r} but ${e[r].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`)},Wr=async function(e,n,r){const a=n.executedMigrations.slice().reverse().slice(0,r).map(o=>n.migrations.find(d=>d.name===o)),s=a.map(o=>({migrationName:o.name,direction:"Down",status:"NotExecuted"}));for(let o=0;o<s.length;++o){const d=a[o];try{d.down&&(await d.down(e),await e.withPlugin(v(this,m,pe)).deleteFrom(v(this,m,he)).where("name","=",d.name).execute(),s[o]={migrationName:d.name,direction:"Down",status:"Success"})}catch(c){throw s[o]={migrationName:d.name,direction:"Down",status:"Error"},new Tn({error:c,results:s})}}return{results:s}},Jr=async function(e,n,r){const s=n.pendingMigrations.slice(0,r).map(o=>({migrationName:o.name,direction:"Up",status:"NotExecuted"}));for(let o=0;o<s.length;o++){const d=n.pendingMigrations[o];try{await d.up(e),await e.withPlugin(v(this,m,pe)).insertInto(v(this,m,he)).values({name:d.name,timestamp:new Date().toISOString()}).execute(),s[o]={migrationName:d.name,direction:"Up",status:"Success"}}catch(c){throw s[o]={migrationName:d.name,direction:"Up",status:"Error"},new Tn({error:c,results:s})}}return{results:s}},bt=async function(e){v(this,P).db.getExecutor().adapter.supportsCreateIfNotExists&&(e=e.ifNotExists()),await e.execute()};var Gt;class Tn extends Error{constructor(n){super();re(this,Gt);ht(this,Gt,n)}get resultSet(){return v(this,Gt)}}Gt=new WeakMap;class qr{constructor(e){ut(this,"migrations");this.migrations=e}async getMigrations(){return this.migrations}}async function Td(t){await t.schema.createTable("tenants").addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("name","varchar(255)").addColumn("audience","varchar(255)").addColumn("sender_email","varchar(255)").addColumn("sender_name","varchar(255)").addColumn("language","varchar(255)").addColumn("logo","varchar(255)").addColumn("primary_color","varchar(255)").addColumn("secondary_color","varchar(255)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("users").addColumn("user_id","varchar(255)",e=>e.notNull()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("given_name","varchar(255)").addColumn("family_name","varchar(255)").addColumn("nickname","varchar(255)").addColumn("name","varchar(255)").addColumn("picture","varchar(2083)").addColumn("tags","varchar(255)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).addPrimaryKeyConstraint("users_tenants",["user_id","tenant_id"]).addColumn("linked_to","varchar(255)").addForeignKeyConstraint("linked_to_constraint",["linked_to","tenant_id"],"users",["user_id","tenant_id"]).addColumn("last_ip","varchar(255)").addColumn("login_count","integer",e=>e.notNull()).addColumn("last_login","varchar(255)").addColumn("provider","varchar(255)",e=>e.notNull()).addColumn("connection","varchar(255)").addColumn("email_verified","boolean",e=>e.notNull()).addColumn("is_social","boolean",e=>e.notNull()).addColumn("app_metadata","varchar(4096)",e=>e.defaultTo("{}").notNull()).addColumn("user_metadata","varchar(4096)",e=>e.defaultTo("{}").notNull()).addUniqueConstraint("unique_email_provider",["email","provider","tenant_id"]).execute(),await t.schema.createTable("members").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("sub","varchar(255)").addColumn("email","varchar(255)").addColumn("name","varchar(255)").addColumn("status","varchar(255)").addColumn("role","varchar(255)").addColumn("picture","varchar(2083)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("applications").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("name","varchar(255)",e=>e.notNull()).addColumn("client_secret","varchar(255)").addColumn("allowed_logout_urls","varchar(255)").addColumn("authentication_settings","varchar(255)").addColumn("addons","varchar(4096)",e=>e.notNull().defaultTo("{}")).addColumn("callbacks","varchar(1024)",e=>e.notNull().defaultTo("[]")).addColumn("allowed_origins","varchar(1024)",e=>e.notNull().defaultTo("[]")).addColumn("web_origins","varchar(1024)",e=>e.notNull().defaultTo("[]")).addColumn("allowed_clients","varchar(1024)",e=>e.defaultTo("[]").notNull()).addColumn("options_kid","varchar(32)").addColumn("options_team_id","varchar(32)").addColumn("options_client_id","varchar(128)").addColumn("options_client_secret","varchar(255)").addColumn("options_scope","varchar(255)").addColumn("options_realms","varchar(255)").addColumn("options_app_secret","varchar(1024)").addColumn("email_validation","varchar(255)").addColumn("disable_sign_ups","boolean",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("connections").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("name","varchar(255)",e=>e.notNull()).addColumn("response_type","varchar(255)").addColumn("response_mode","varchar(255)").addColumn("strategy","varchar(64)").addColumn("options","varchar(2048)",e=>e.defaultTo("{}").notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("migrations").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("provider","varchar(255)").addColumn("client_id","varchar(255)").addColumn("origin","varchar(255)").addColumn("domain","varchar(255)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("domains").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("domain","varchar(255)",e=>e.notNull()).addColumn("email_service","varchar(255)").addColumn("email_api_key","varchar(255)").addColumn("dkim_private_key","varchar(2048)").addColumn("dkim_public_key","varchar(2048)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute()}async function Cd(t){await t.schema.dropTable("domains").execute(),await t.schema.dropTable("members").execute(),await t.schema.dropTable("users").execute(),await t.schema.dropTable("connections").execute(),await t.schema.dropTable("applications").execute(),await t.schema.dropTable("migrations").execute(),await t.schema.dropTable("tenants").execute()}const Od=Object.freeze(Object.defineProperty({__proto__:null,down:Cd,up:Td},Symbol.toStringTag,{value:"Module"}));async function Sd(t){await t.schema.alterTable("tenants").addColumn("support_url","varchar(255)").execute()}async function jd(t){await t.schema.alterTable("tenants").dropColumn("support_url").execute()}const Id=Object.freeze(Object.defineProperty({__proto__:null,down:jd,up:Sd},Symbol.toStringTag,{value:"Module"}));async function Zd(t){}async function Ed(t){}const $d=Object.freeze(Object.defineProperty({__proto__:null,down:Ed,up:Zd},Symbol.toStringTag,{value:"Module"}));async function Pd(t){await t.schema.createTable("logs").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("category","varchar(255)",e=>e.notNull()).addColumn("tenant_id","varchar(64)").addColumn("user_id","varchar(64)").addForeignKeyConstraint("tenant_id_constraint",["tenant_id"],"tenants",["id"],e=>e.onDelete("cascade")).addColumn("ip","varchar(255)").addColumn("type","varchar(8)",e=>e.notNull()).addColumn("date","varchar(25)",e=>e.notNull()).addColumn("client_id","varchar(255)").addColumn("client_name","varchar(255)").addColumn("user_agent","varchar(255)").addColumn("description","varchar(255)").addColumn("details","varchar(2048)").execute()}async function Ad(t){await t.schema.dropTable("logs").execute()}const Dd=Object.freeze(Object.defineProperty({__proto__:null,down:Ad,up:Pd},Symbol.toStringTag,{value:"Module"}));async function Rd(t){}async function Md(t){}const Ld=Object.freeze(Object.defineProperty({__proto__:null,down:Md,up:Rd},Symbol.toStringTag,{value:"Module"}));async function zd(t){await t.schema.createTable("sessions").addColumn("session_id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("tenant_id","varchar(255)").addColumn("user_id","varchar(255)").addForeignKeyConstraint("user_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").addColumn("deleted_at","varchar(255)").execute(),await t.schema.createTable("tickets").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("nonce","varchar(255)").addColumn("state","varchar(1024)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createTable("otps").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("user_id","varchar(255)").addColumn("send","varchar(255)").addColumn("nonce","varchar(255)").addColumn("state","varchar(1024)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createIndex("otps_email_index").on("otps").column("email").execute(),await t.schema.createIndex("otps_expires_at_index").on("otps").column("expires_at").execute()}async function Ud(t){await t.schema.dropTable("sessions").execute(),await t.schema.dropTable("tickets").execute(),await t.schema.dropTable("otps").execute()}const Fd=Object.freeze(Object.defineProperty({__proto__:null,down:Ud,up:zd},Symbol.toStringTag,{value:"Module"}));async function Vd(t){await t.schema.createTable("passwords").addColumn("tenant_id","varchar(255)").addColumn("user_id","varchar(255)").addForeignKeyConstraint("user_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("created_at","varchar(255)").addColumn("updated_at","varchar(255)").execute(),await t.schema.createTable("codes").addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("user_id","varchar(255)").addColumn("tenant_id","varchar(255)").addForeignKeyConstraint("user_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createIndex("codes_expires_at_index").on("codes").column("expires_at").execute()}async function Bd(t){await t.schema.dropTable("passwords").execute(),await t.schema.dropTable("codes").execute()}const Kd=Object.freeze(Object.defineProperty({__proto__:null,down:Bd,up:Vd},Symbol.toStringTag,{value:"Module"}));async function Wd(t){}async function Jd(t){}const qd=Object.freeze(Object.defineProperty({__proto__:null,down:Jd,up:Wd},Symbol.toStringTag,{value:"Module"}));async function Qd(t){await t.schema.alterTable("passwords").addColumn("password","varchar(255)",e=>e.notNull()).execute()}async function Gd(t){await t.schema.alterTable("passwords").dropColumn("password").execute()}const Hd=Object.freeze(Object.defineProperty({__proto__:null,down:Gd,up:Qd},Symbol.toStringTag,{value:"Module"}));async function Yd(t){}async function Xd(t){}const ec=Object.freeze(Object.defineProperty({__proto__:null,down:Xd,up:Yd},Symbol.toStringTag,{value:"Module"}));async function tc(t){}async function nc(t){}const rc=Object.freeze(Object.defineProperty({__proto__:null,down:nc,up:tc},Symbol.toStringTag,{value:"Module"}));async function ac(t){}async function sc(t){}const ic=Object.freeze(Object.defineProperty({__proto__:null,down:sc,up:ac},Symbol.toStringTag,{value:"Module"}));async function oc(t){await t.schema.createIndex("users_email_index").on("users").column("email").execute()}async function dc(t){await t.schema.dropIndex("users_email_index").execute()}const cc=Object.freeze(Object.defineProperty({__proto__:null,down:dc,up:oc},Symbol.toStringTag,{value:"Module"}));async function lc(t){await t.schema.alterTable("users").addColumn("profileData","varchar(2048)").execute()}async function uc(t){await t.schema.alterTable("users").dropColumn("profileData").execute()}const hc=Object.freeze(Object.defineProperty({__proto__:null,down:uc,up:lc},Symbol.toStringTag,{value:"Module"}));async function pc(t){await t.schema.createIndex("users_linked_to_index").on("users").column("linked_to").execute()}async function mc(t){await t.schema.dropIndex("users_linked_to_index")}const fc=Object.freeze(Object.defineProperty({__proto__:null,down:mc,up:pc},Symbol.toStringTag,{value:"Module"}));async function _c(t){await t.schema.alterTable("users").addColumn("locale","varchar(255)").execute()}async function gc(t){await t.schema.alterTable("users").dropColumn("locale").execute()}const yc=Object.freeze(Object.defineProperty({__proto__:null,down:gc,up:_c},Symbol.toStringTag,{value:"Module"}));async function vc(t){await t.schema.createTable("keys").addColumn("kid","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade")).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("revoked_at","varchar(255)").addColumn("cert","varchar(2048)").addColumn("pkcs7","varchar(2048)").addColumn("fingerprint","varchar(256)").addColumn("thumbprint","varchar(256)").addColumn("current_since","varchar(256)").addColumn("current_until","varchar(256)").execute()}async function bc(t){await t.schema.dropTable("keys").execute()}const wc=Object.freeze(Object.defineProperty({__proto__:null,down:bc,up:vc},Symbol.toStringTag,{value:"Module"}));async function xc(t){}async function Nc(t){}const kc=Object.freeze(Object.defineProperty({__proto__:null,down:Nc,up:xc},Symbol.toStringTag,{value:"Module"}));async function Tc(t){}async function Cc(t){}const Oc=Object.freeze(Object.defineProperty({__proto__:null,down:Cc,up:Tc},Symbol.toStringTag,{value:"Module"}));async function Sc(t){await t.schema.alterTable("otps").addColumn("audience","varchar(255)").execute()}async function jc(t){await t.schema.alterTable("otps").dropColumn("audience").execute()}const Ic=Object.freeze(Object.defineProperty({__proto__:null,down:jc,up:Sc},Symbol.toStringTag,{value:"Module"}));async function Zc(t){}async function Ec(t){}const $c=Object.freeze(Object.defineProperty({__proto__:null,down:Ec,up:Zc},Symbol.toStringTag,{value:"Module"}));async function Pc(t){await t.schema.alterTable("logs").dropColumn("category").execute()}async function Ac(t){await t.schema.alterTable("logs").addColumn("category","varchar(255)",e=>e.notNull()).execute()}const Dc=Object.freeze(Object.defineProperty({__proto__:null,down:Ac,up:Pc},Symbol.toStringTag,{value:"Module"}));async function Rc(t){await t.schema.alterTable("users").dropColumn("tags").execute()}async function Mc(t){await t.schema.alterTable("users").addColumn("tags","varchar(255)").execute()}const Lc=Object.freeze(Object.defineProperty({__proto__:null,down:Mc,up:Rc},Symbol.toStringTag,{value:"Module"}));async function zc(t){await t.schema.createIndex("logs_user_id").on("logs").column("user_id").execute(),await t.schema.createIndex("logs_tenant_id").on("logs").column("tenant_id").execute(),await t.schema.createIndex("logs_date").on("logs").column("date").execute()}async function Uc(t){await t.schema.dropIndex("logs_user_id"),await t.schema.dropIndex("logs_tenant_id"),await t.schema.dropIndex("logs_date")}const Fc=Object.freeze(Object.defineProperty({__proto__:null,down:Uc,up:zc},Symbol.toStringTag,{value:"Module"}));async function Vc(t){await t.schema.alterTable("logs").dropColumn("details").execute(),await t.schema.alterTable("logs").addColumn("details","varchar(8192)").execute()}async function Bc(t){await t.schema.alterTable("logs").dropColumn("details").execute(),await t.schema.alterTable("logs").addColumn("details","varchar(2048)").execute()}const Kc=Object.freeze(Object.defineProperty({__proto__:null,down:Bc,up:Vc},Symbol.toStringTag,{value:"Module"}));async function Wc(t){await t.schema.alterTable("logs").addColumn("user_name","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("auth0_client","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("isMobile","boolean").execute(),await t.schema.alterTable("logs").addColumn("connection","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("connection_id","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("audience","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("scope","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("strategy","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("strategy_type","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("hostname","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("session_connection","varchar(255)").execute()}async function Jc(t){await t.schema.alterTable("logs").dropColumn("user_name").execute(),await t.schema.alterTable("logs").dropColumn("auth0_client").execute(),await t.schema.alterTable("logs").dropColumn("isMobile").execute(),await t.schema.alterTable("logs").dropColumn("connection").execute(),await t.schema.alterTable("logs").dropColumn("connection_id").execute(),await t.schema.alterTable("logs").dropColumn("audience").execute(),await t.schema.alterTable("logs").dropColumn("scope").execute(),await t.schema.alterTable("logs").dropColumn("strategy").execute(),await t.schema.alterTable("logs").dropColumn("strategy_type").execute(),await t.schema.alterTable("logs").dropColumn("hostname").execute(),await t.schema.alterTable("logs").dropColumn("session_connection").execute()}const qc=Object.freeze(Object.defineProperty({__proto__:null,down:Jc,up:Wc},Symbol.toStringTag,{value:"Module"}));async function Qc(t){await t.schema.createIndex("users_name_index").on("users").column("name").execute()}async function Gc(t){await t.schema.dropIndex("users_name_index").execute()}const Hc=Object.freeze(Object.defineProperty({__proto__:null,down:Gc,up:Qc},Symbol.toStringTag,{value:"Module"}));async function Yc(t){}async function Xc(t){await t.schema.alterTable("users").dropConstraint("unique_email_provider").execute()}const el=Object.freeze(Object.defineProperty({__proto__:null,down:Xc,up:Yc},Symbol.toStringTag,{value:"Module"}));async function tl(t){await t.schema.alterTable("otps").dropColumn("state").execute(),await t.schema.alterTable("otps").addColumn("state","varchar(8192)").execute()}async function nl(t){await t.schema.alterTable("otps").dropColumn("state").execute(),await t.schema.alterTable("otps").addColumn("state","varchar(1024)").execute()}const rl=Object.freeze(Object.defineProperty({__proto__:null,down:nl,up:tl},Symbol.toStringTag,{value:"Module"}));async function al(t){await t.schema.alterTable("tickets").dropColumn("state").execute(),await t.schema.alterTable("tickets").addColumn("state","varchar(8192)").execute()}async function sl(t){await t.schema.alterTable("tickets").dropColumn("state").execute(),await t.schema.alterTable("tickets").addColumn("state","varchar(1024)").execute()}const il=Object.freeze(Object.defineProperty({__proto__:null,down:sl,up:al},Symbol.toStringTag,{value:"Module"}));async function ol(t){await t.schema.createTable("branding").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull().primaryKey()).addColumn("logo_url","varchar(512)").addColumn("favicon_url","varchar(512)").addColumn("font_url","varchar(512)").addColumn("colors_primary","varchar(8)").addColumn("colors_page_background_type","varchar(32)").addColumn("colors_page_background_start","varchar(8)").addColumn("colors_page_background_end","varchar(8)").addColumn("colors_page_background_angle_dev","integer").execute()}async function dl(t){await t.schema.dropTable("branding").execute()}const cl=Object.freeze(Object.defineProperty({__proto__:null,down:dl,up:ol},Symbol.toStringTag,{value:"Module"}));async function ll(t){}async function ul(t){}const hl=Object.freeze(Object.defineProperty({__proto__:null,down:ul,up:ll},Symbol.toStringTag,{value:"Module"}));async function pl(t){}async function ml(t){}const fl=Object.freeze(Object.defineProperty({__proto__:null,down:ml,up:pl},Symbol.toStringTag,{value:"Module"}));async function _l(t){}async function gl(t){}const yl=Object.freeze(Object.defineProperty({__proto__:null,down:gl,up:_l},Symbol.toStringTag,{value:"Module"}));async function vl(t){}async function bl(t){}const wl=Object.freeze(Object.defineProperty({__proto__:null,down:bl,up:vl},Symbol.toStringTag,{value:"Module"}));async function xl(t){await t.schema.createTable("authentication_codes").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)",e=>e.notNull()).addColumn("nonce","varchar(255)").addColumn("state","varchar(8192)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}async function Nl(t){await t.schema.dropTable("authentication_codes").execute()}const kl=Object.freeze(Object.defineProperty({__proto__:null,down:Nl,up:xl},Symbol.toStringTag,{value:"Module"}));async function Tl(t){}async function Cl(t){}const Ol=Object.freeze(Object.defineProperty({__proto__:null,down:Cl,up:Tl},Symbol.toStringTag,{value:"Module"}));async function Sl(t){await t.schema.alterTable("otps").addColumn("ip","varchar(64)").execute()}async function jl(t){await t.schema.alterTable("otps").dropColumn("ip").execute()}const Il=Object.freeze(Object.defineProperty({__proto__:null,down:jl,up:Sl},Symbol.toStringTag,{value:"Module"}));async function Zl(t){await t.schema.alterTable("logs").dropColumn("user_agent").execute(),await t.schema.alterTable("logs").addColumn("user_agent","varchar(1024)").execute()}async function El(t){await t.schema.alterTable("logs").dropColumn("user_agent").execute(),await t.schema.alterTable("logs").addColumn("user_agent","varchar(255)").execute()}const $l=Object.freeze(Object.defineProperty({__proto__:null,down:El,up:Zl},Symbol.toStringTag,{value:"Module"}));async function Pl(t){}async function Al(t){}const Dl=Object.freeze(Object.defineProperty({__proto__:null,down:Al,up:Pl},Symbol.toStringTag,{value:"Module"}));async function Rl(t){await t.schema.createTable("hooks").addColumn("hook_id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("url","varchar(512)",e=>e.notNull()).addColumn("trigger_id","varchar(255)",e=>e.notNull()).addColumn("enabled","boolean",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).addColumn("synchronous","boolean",e=>e.defaultTo(!1).notNull()).addColumn("priority","integer").execute()}async function Ml(t){await t.schema.dropTable("hooks").execute()}const Ll=Object.freeze(Object.defineProperty({__proto__:null,down:Ml,up:Rl},Symbol.toStringTag,{value:"Module"}));async function zl(t){}async function Ul(t){}const Fl=Object.freeze(Object.defineProperty({__proto__:null,down:Ul,up:zl},Symbol.toStringTag,{value:"Module"}));async function Vl(t){}async function Bl(t){}const Kl=Object.freeze(Object.defineProperty({__proto__:null,down:Bl,up:Vl},Symbol.toStringTag,{value:"Module"}));async function Wl(t){await t.schema.createTable("logins").addColumn("login_id","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("authParams_client_id","varchar(255)",e=>e.notNull()).addColumn("authParams_vendor_id","varchar(255)").addColumn("authParams_username","varchar(255)").addColumn("authParams_response_type","varchar(255)").addColumn("authParams_response_mode","varchar(255)").addColumn("authParams_audience","varchar(255)").addColumn("authParams_scope","varchar(511)").addColumn("authParams_state","varchar(511)").addColumn("authParams_code_challenge_method","varchar(256)").addColumn("authParams_code_challenge","varchar(256)").addColumn("authParams_redirect_uri","varchar(256)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.alterTable("passwords").addColumn("algorithm","varchar(16)").execute(),await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("code_id","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)").addColumn("login_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("code_type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}async function Jl(t){await t.schema.dropTable("logins").execute(),await t.schema.alterTable("passwords").dropColumn("algorithm").execute(),await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("code","varchar(255)",e=>e.notNull()).addColumn("user_id","varchar(255)").addColumn("tenant_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}const ql=Object.freeze(Object.defineProperty({__proto__:null,down:Jl,up:Wl},Symbol.toStringTag,{value:"Module"}));async function Ql(t){}async function Gl(t){}const Hl=Object.freeze(Object.defineProperty({__proto__:null,down:Gl,up:Ql},Symbol.toStringTag,{value:"Module"}));async function Yl(t){await t.schema.alterTable("logins").addColumn("auth0Client","varchar(256)").execute()}async function Xl(t){await t.schema.alterTable("logins").dropColumn("auth0Client").execute()}const eu=Object.freeze(Object.defineProperty({__proto__:null,down:Xl,up:Yl},Symbol.toStringTag,{value:"Module"}));async function tu(t){await t.schema.alterTable("logins").dropColumn("authParams_state").execute(),await t.schema.alterTable("logins").addColumn("authParams_state","varchar(8192)").execute()}async function nu(t){await t.schema.alterTable("logins").dropColumn("authParams_state").execute(),await t.schema.alterTable("logins").addColumn("authParams_state","varchar(511)").execute()}const ru=Object.freeze(Object.defineProperty({__proto__:null,down:nu,up:tu},Symbol.toStringTag,{value:"Module"}));async function au(t){}async function su(t){}const iu=Object.freeze(Object.defineProperty({__proto__:null,down:su,up:au},Symbol.toStringTag,{value:"Module"}));async function ou(t){}async function du(t){}const cu=Object.freeze(Object.defineProperty({__proto__:null,down:du,up:ou},Symbol.toStringTag,{value:"Module"}));async function lu(t){await t.schema.alterTable("logins").addColumn("authParams_nonce","varchar(255)").execute()}async function uu(t){await t.schema.alterTable("logins").dropColumn("nonce").execute()}const hu=Object.freeze(Object.defineProperty({__proto__:null,down:uu,up:lu},Symbol.toStringTag,{value:"Module"}));async function pu(t){}async function mu(t){}const fu=Object.freeze(Object.defineProperty({__proto__:null,down:mu,up:pu},Symbol.toStringTag,{value:"Module"}));async function _u(t){}async function gu(t){}const yu=Object.freeze(Object.defineProperty({__proto__:null,down:gu,up:_u},Symbol.toStringTag,{value:"Module"}));async function vu(t){await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("code_id","varchar(255)",e=>e.notNull()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)").addColumn("login_id","varchar(255)").addColumn("connection_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("code_type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").addPrimaryKeyConstraint("PK_codes_code_id_code_type",["code_id","code_type"]).execute()}async function bu(t){await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("code_id","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)").addColumn("connection_id","varchar(255)").addColumn("login_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("code_type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}const wu=Object.freeze(Object.defineProperty({__proto__:null,down:bu,up:vu},Symbol.toStringTag,{value:"Module"}));async function xu(t){await t.schema.dropTable("otps").execute(),await t.schema.dropTable("authentication_codes").execute()}async function Nu(t){await t.schema.alterTable("keys").addColumn("private_key","varchar(2048)").addColumn("public_key","varchar(2048)").execute(),await t.schema.createTable("otps").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("user_id","varchar(255)").addColumn("send","varchar(255)").addColumn("nonce","varchar(255)").addColumn("state","varchar(1024)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createTable("authentication_codes").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)",e=>e.notNull()).addColumn("nonce","varchar(255)").addColumn("state","varchar(8192)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}const ku=Object.freeze(Object.defineProperty({__proto__:null,down:Nu,up:xu},Symbol.toStringTag,{value:"Module"}));async function Tu(t){await t.schema.createIndex("IDX_logs_tenant_date_type_user").on("logs").columns(["tenant_id","date","type","user_id"]).execute()}async function Cu(t){await t.schema.dropIndex("IDX_logs_tenant_date_type_user").on("logs").execute()}const Ou=Object.freeze(Object.defineProperty({__proto__:null,down:Cu,up:Tu},Symbol.toStringTag,{value:"Module"}));async function Su(t){}async function ju(t){}const Iu=Object.freeze(Object.defineProperty({__proto__:null,down:ju,up:Su},Symbol.toStringTag,{value:"Module"}));async function Zu(t){await t.schema.createTable("prompt_settings").addColumn("tenant_id","varchar(64)",e=>e.primaryKey()).addColumn("universal_login_experience","varchar(16)",e=>e.defaultTo("new").notNull()).addColumn("identifier_first","boolean",e=>e.defaultTo(!0).notNull()).addColumn("password_first","boolean",e=>e.defaultTo(!1).notNull()).addColumn("webauthn_platform_first_factor","boolean",e=>e.defaultTo(!1).notNull()).execute()}async function Eu(t){await t.schema.dropTable("prompt_settings").execute()}const $u=Object.freeze(Object.defineProperty({__proto__:null,down:Eu,up:Zu},Symbol.toStringTag,{value:"Module"}));async function Pu(t){}async function Au(t){}const Du=Object.freeze(Object.defineProperty({__proto__:null,down:Au,up:Pu},Symbol.toStringTag,{value:"Module"}));async function Ru(t){}async function Mu(t){}const Lu=Object.freeze(Object.defineProperty({__proto__:null,down:Mu,up:Ru},Symbol.toStringTag,{value:"Module"}));async function zu(t){}async function Uu(t){}const Fu=Object.freeze(Object.defineProperty({__proto__:null,down:Uu,up:zu},Symbol.toStringTag,{value:"Module"}));async function Vu(t){await t.schema.alterTable("logins").addColumn("authParams_ui_locales","varchar(32)").execute()}async function Bu(t){await t.schema.alterTable("logins").dropColumn("authParams_ui_locales").execute()}const Ku=Object.freeze(Object.defineProperty({__proto__:null,down:Bu,up:Vu},Symbol.toStringTag,{value:"Module"}));async function Wu(t){await t.schema.alterTable("logins").addColumn("authParams_prompt","varchar(16)").execute()}async function Ju(t){await t.schema.alterTable("logins").dropColumn("authParams_prompt").execute()}const qu=Object.freeze(Object.defineProperty({__proto__:null,down:Ju,up:Wu},Symbol.toStringTag,{value:"Module"}));async function Qu(t){}async function Gu(t){}const Hu=Object.freeze(Object.defineProperty({__proto__:null,down:Gu,up:Qu},Symbol.toStringTag,{value:"Module"}));async function Yu(t){await t.schema.alterTable("logins").addColumn("authParams_act_as","varchar(255)").execute()}async function Xu(t){await t.schema.alterTable("logins").dropColumn("authParam_act_as").execute()}const eh=Object.freeze(Object.defineProperty({__proto__:null,down:Xu,up:Yu},Symbol.toStringTag,{value:"Module"})),Qr={m1_init:Od,m2_magicLink:Id,m3_updateAt:$d,m4_logTable:Dd,m5_userProfile:Ld,m6_sessions:Fd,m7_passwords:Kd,m8_logsTableNewFields:qd,m9_passwordTableNewField:Hd,n01_codesTable:ec,n11_universalLoginSession:rc,n12_userFields:ic,n13_userEmailIndex:cc,n14_profileDataField:hc,n15_userEmailIndex:fc,n16_userLocale:yc,n17_signingKeys:wc,n18_logsFields:kc,n19_connectionsUserinfo:Oc,n20_missingFields:Ic,n21_sessionDeletedAt:$c,n22_dropLogsFields:Dc,n23_dropUsersFields:Lc,n24_logsIndexes:Fc,n25_logDescMaxLength:Kc,n26_logsTableExtraFields:qc,n27_usersTableNameIndex:Hc,n28_usersEmailConstrain:el,n29_increaseOtpStateLength:rl,n30_increaseTicketStateLength:il,n31_branding:cl,n32_indexesAndNotNull:hl,n33_vendorIdInUniversalLoginSession:fl,n34_auth0ClientInUniversalLoginSession:yl,n35_increaseUniversalSessionStateLength:wl,n36_authenticationCodes:kl,n37_disableSignUps:Ol,n38_otpIpAddress:Il,n39_increaseUserAgentLength:$l,n40_userId:Dl,n41_hooks:Ll,n42_userIdIndexes:Fl,n43_userIdIndexes:Kl,n44_codes:ql,n45_hookProperties:Hl,n46_loginAuth0Client:eu,n47_loginAuth0Client:ru,n48_saml:iu,n49_removeFields:cu,n50_authParamsNonce:hu,n51_connectionid:fu,n52_cert:yu,n53_codes_primary_key:wu,n54_cleanup_tables:ku,n55_logs_index:Ou,n56_application_fields:Iu,n57_prompt_settings:$u,n58_connection_client_id:Du,n59_connection_options:Lu,n60_users_metadata:Fu,n61_userLocales:Ku,n62_prompt:qu,n63_connection_cleanup:Hu,n64_act_as:eh};async function th(t,e=!1){e&&console.log("migrating...");const n=new qr(Qr),r=new $r({db:t,provider:n}),{error:a,results:s}=await r.migrateToLatest();if(s==null||s.forEach(o=>{o.status==="Success"?e&&console.log(`migration "${o.migrationName}" was executed successfully`):o.status==="Error"&&console.error(`failed to execute migration "${o.migrationName}"`)}),a)throw console.error("failed to migrate"),console.error(a),a}async function nh(t){console.log("migrating...");const e=new qr(Qr),n=new $r({db:t,provider:e}),{error:r,results:a}=await n.migrateDown();if(a==null||a.forEach(s=>{s.status==="Success"?console.log(`migration "${s.migrationName}" was reverted successfully`):s.status==="Error"&&console.error(`failed to execute migration "${s.migrationName}"`)}),r)throw console.error("failed to migrate"),console.error(r),r}function rh(t){return{applications:Ti(t),branding:Qo(t),clients:Lo(t),codes:vi(t),connections:Mo(t),domains:Wo(t),hooks:td(t),keys:Vo(t),logins:ud(t),logs:ei(t),passwords:mi(t),promptSettings:md(t),users:Fs(t),sessions:ii(t),tenants:Qs(t),themes:id(t),tickets:li(t)}}exports.default=rh;exports.migrateDown=nh;exports.migrateToLatest=th;
1
+ "use strict";var Gr=Object.defineProperty;var Kn=t=>{throw TypeError(t)};var Hr=(t,e,n)=>e in t?Gr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var ut=(t,e,n)=>Hr(t,typeof e!="symbol"?e+"":e,n),bn=(t,e,n)=>e.has(t)||Kn("Cannot "+n);var v=(t,e,n)=>(bn(t,e,"read from private field"),n?n.call(t):e.get(t)),re=(t,e,n)=>e.has(t)?Kn("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),ht=(t,e,n,r)=>(bn(t,e,"write to private field"),r?r.call(t,n):e.set(t,n),n),C=(t,e,n)=>(bn(t,e,"access private method"),n);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});var Cn=class extends Error{constructor(e=500,n){super(n==null?void 0:n.message,{cause:n==null?void 0:n.cause});ut(this,"res");ut(this,"status");this.res=n==null?void 0:n.res,this.status=e}getResponse(){return this.res?new Response(this.res.body,{status:this.status,headers:this.res.headers}):new Response(this.message,{status:this.status})}};function Yr(t){return async(e,n)=>{const{identities:r,...a}=n,s={...a,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),tenant_id:e,email_verified:n.email_verified?1:0,is_social:n.is_social?1:0,app_metadata:JSON.stringify(n.app_metadata),user_metadata:JSON.stringify(n.user_metadata)};try{await t.insertInto("users").values(s).execute()}catch(o){throw o.code==="SQLITE_CONSTRAINT_UNIQUE"||o.message.includes("AlreadyExists")?new Cn(409,{message:"User already exists"}):(console.log(o.message),new Cn(500,{message:`${o.code}, ${o.message}`}))}return{...s,email:s.email||"",email_verified:s.email_verified===1,is_social:s.is_social===1}}}function M(t){const e={...t};for(const n in e)e[n]===null?delete e[n]:typeof e[n]=="object"&&(Array.isArray(e[n])?e[n]=e[n].map(M):e[n]=M(e[n]));return e}function Xr(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function ea(t,e){var n;return((n=t==null?void 0:t._def)===null||n===void 0?void 0:n.typeName)===e}function pt(t,e){const n=t.ZodType.prototype[e];t.ZodType.prototype[e]=function(...r){const a=n.apply(this,r);return a._def.openapi=this._def.openapi,a}}function ta(t){if(typeof t.ZodType.prototype.openapi<"u")return;t.ZodType.prototype.openapi=function(a,s){var o,d,c,l,u,Z;const R=typeof a=="string"?s:a,J=R??{},{param:_e}=J,We=Xr(J,["param"]),ge=Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o._internal),typeof a=="string"?{refId:a}:void 0),ye=Object.assign(Object.assign(Object.assign({},(d=this._def.openapi)===null||d===void 0?void 0:d.metadata),We),!((l=(c=this._def.openapi)===null||c===void 0?void 0:c.metadata)===null||l===void 0)&&l.param||_e?{param:Object.assign(Object.assign({},(Z=(u=this._def.openapi)===null||u===void 0?void 0:u.metadata)===null||Z===void 0?void 0:Z.param),_e)}:void 0),ve=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(ge).length>0?{_internal:ge}:void 0),Object.keys(ye).length>0?{metadata:ye}:void 0)}));if(ea(this,"ZodObject")){const Je=this.extend;ve.extend=function(...qe){var ee,te,ne,be,$e,Pe;const Ae=Je.apply(this,qe);return Ae._def.openapi={_internal:{extendedFrom:!((te=(ee=this._def.openapi)===null||ee===void 0?void 0:ee._internal)===null||te===void 0)&&te.refId?{refId:(be=(ne=this._def.openapi)===null||ne===void 0?void 0:ne._internal)===null||be===void 0?void 0:be.refId,schema:this}:($e=this._def.openapi)===null||$e===void 0?void 0:$e._internal.extendedFrom},metadata:(Pe=Ae._def.openapi)===null||Pe===void 0?void 0:Pe.metadata},Ae}}return ve},pt(t,"optional"),pt(t,"nullable"),pt(t,"default"),pt(t,"transform"),pt(t,"refine");const e=t.ZodObject.prototype.deepPartial;t.ZodObject.prototype.deepPartial=function(){const a=this._def.shape(),s=e.apply(this),o=s._def.shape();return Object.entries(o).forEach(([d,c])=>{var l,u;c._def.openapi=(u=(l=a[d])===null||l===void 0?void 0:l._def)===null||u===void 0?void 0:u.openapi}),s._def.openapi=void 0,s};const n=t.ZodObject.prototype.pick;t.ZodObject.prototype.pick=function(...a){const s=n.apply(this,a);return s._def.openapi=void 0,s};const r=t.ZodObject.prototype.omit;t.ZodObject.prototype.omit=function(...a){const s=r.apply(this,a);return s._def.openapi=void 0,s}}new Set(".\\+*[^]$()");var E;(function(t){t.assertEqual=a=>a;function e(a){}t.assertIs=e;function n(a){throw new Error}t.assertNever=n,t.arrayToEnum=a=>{const s={};for(const o of a)s[o]=o;return s},t.getValidEnumValues=a=>{const s=t.objectKeys(a).filter(d=>typeof a[a[d]]!="number"),o={};for(const d of s)o[d]=a[d];return t.objectValues(o)},t.objectValues=a=>t.objectKeys(a).map(function(s){return a[s]}),t.objectKeys=typeof Object.keys=="function"?a=>Object.keys(a):a=>{const s=[];for(const o in a)Object.prototype.hasOwnProperty.call(a,o)&&s.push(o);return s},t.find=(a,s)=>{for(const o of a)if(s(o))return o},t.isInteger=typeof Number.isInteger=="function"?a=>Number.isInteger(a):a=>typeof a=="number"&&isFinite(a)&&Math.floor(a)===a;function r(a,s=" | "){return a.map(o=>typeof o=="string"?`'${o}'`:o).join(s)}t.joinValues=r,t.jsonStringifyReplacer=(a,s)=>typeof s=="bigint"?s.toString():s})(E||(E={}));var On;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(On||(On={}));const g=E.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),xe=t=>{switch(typeof t){case"undefined":return g.undefined;case"string":return g.string;case"number":return isNaN(t)?g.nan:g.number;case"boolean":return g.boolean;case"function":return g.function;case"bigint":return g.bigint;case"symbol":return g.symbol;case"object":return Array.isArray(t)?g.array:t===null?g.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?g.promise:typeof Map<"u"&&t instanceof Map?g.map:typeof Set<"u"&&t instanceof Set?g.set:typeof Date<"u"&&t instanceof Date?g.date:g.object;default:return g.unknown}},h=E.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"]),na=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:");class K extends Error{constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const n=e||function(s){return s.message},r={_errors:[]},a=s=>{for(const o of s.issues)if(o.code==="invalid_union")o.unionErrors.map(a);else if(o.code==="invalid_return_type")a(o.returnTypeError);else if(o.code==="invalid_arguments")a(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let d=r,c=0;for(;c<o.path.length;){const l=o.path[c];c===o.path.length-1?(d[l]=d[l]||{_errors:[]},d[l]._errors.push(n(o))):d[l]=d[l]||{_errors:[]},d=d[l],c++}}};return a(this),r}static assert(e){if(!(e instanceof K))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,E.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},r=[];for(const a of this.issues)a.path.length>0?(n[a.path[0]]=n[a.path[0]]||[],n[a.path[0]].push(e(a))):r.push(e(a));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}K.create=t=>new K(t);const st=(t,e)=>{let n;switch(t.code){case h.invalid_type:t.received===g.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case h.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,E.jsonStringifyReplacer)}`;break;case h.unrecognized_keys:n=`Unrecognized key(s) in object: ${E.joinValues(t.keys,", ")}`;break;case h.invalid_union:n="Invalid input";break;case h.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${E.joinValues(t.options)}`;break;case h.invalid_enum_value:n=`Invalid enum value. Expected ${E.joinValues(t.options)}, received '${t.received}'`;break;case h.invalid_arguments:n="Invalid function arguments";break;case h.invalid_return_type:n="Invalid function return type";break;case h.invalid_date:n="Invalid date";break;case h.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:E.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case h.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case h.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case h.custom:n="Invalid input";break;case h.invalid_intersection_types:n="Intersection results could not be merged";break;case h.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case h.not_finite:n="Number must be finite";break;default:n=e.defaultError,E.assertNever(t)}return{message:n}};let er=st;function ra(t){er=t}function tn(){return er}const nn=t=>{const{data:e,path:n,errorMaps:r,issueData:a}=t,s=[...n,...a.path||[]],o={...a,path:s};if(a.message!==void 0)return{...a,path:s,message:a.message};let d="";const c=r.filter(l=>!!l).slice().reverse();for(const l of c)d=l(o,{data:e,defaultError:d}).message;return{...a,path:s,message:d}},aa=[];function f(t,e){const n=tn(),r=nn({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===st?void 0:st].filter(a=>!!a)});t.common.issues.push(r)}class U{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const a of n){if(a.status==="aborted")return T;a.status==="dirty"&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const a of n){const s=await a.key,o=await a.value;r.push({key:s,value:o})}return U.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const a of n){const{key:s,value:o}=a;if(s.status==="aborted"||o.status==="aborted")return T;s.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof o.value<"u"||a.alwaysSet)&&(r[s.value]=o.value)}return{status:e.value,value:r}}}const T=Object.freeze({status:"aborted"}),rn=t=>({status:"dirty",value:t}),V=t=>({status:"valid",value:t}),Sn=t=>t.status==="aborted",jn=t=>t.status==="dirty",wt=t=>t.status==="valid",xt=t=>typeof Promise<"u"&&t instanceof Promise;function an(t,e,n,r){if(typeof e=="function"?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(t)}function tr(t,e,n,r,a){if(typeof e=="function"?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,n),n}var b;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(b||(b={}));var ft,_t;class ie{constructor(e,n,r,a){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=a}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Wn=(t,e)=>{if(wt(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new K(t.common.issues);return this._error=n,this._error}}};function O(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:a}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(s,o)=>{var d,c;const{message:l}=t;return s.code==="invalid_enum_value"?{message:l??o.defaultError}:typeof o.data>"u"?{message:(d=l??r)!==null&&d!==void 0?d:o.defaultError}:s.code!=="invalid_type"?{message:o.defaultError}:{message:(c=l??n)!==null&&c!==void 0?c:o.defaultError}},description:a}}class j{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)}get description(){return this._def.description}_getType(e){return xe(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:xe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new U,ctx:{common:e.parent.common,data:e.data,parsedType:xe(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(xt(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){var r;const a={common:{issues:[],async:(r=n==null?void 0:n.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:xe(e)},s=this._parseSync({data:e,path:a.path,parent:a});return Wn(a,s)}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:xe(e)},a=this._parse({data:e,path:r.path,parent:r}),s=await(xt(a)?a:Promise.resolve(a));return Wn(r,s)}refine(e,n){const r=a=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(a):n;return this._refinement((a,s)=>{const o=e(a),d=()=>s.addIssue({code:h.custom,...r(a)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(d(),!1)):o?!0:(d(),!1)})}refinement(e,n){return this._refinement((r,a)=>e(r)?!0:(a.addIssue(typeof n=="function"?n(r,a):n),!1))}_refinement(e){return new Y({schema:this,typeName:x.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return ae.create(this,this._def)}nullable(){return Oe.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return G.create(this,this._def)}promise(){return ot.create(this,this._def)}or(e){return Ct.create([this,e],this._def)}and(e){return Ot.create(this,e,this._def)}transform(e){return new Y({...O(this._def),schema:this,typeName:x.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new Et({...O(this._def),innerType:this,defaultValue:n,typeName:x.ZodDefault})}brand(){return new zn({typeName:x.ZodBranded,type:this,...O(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new $t({...O(this._def),innerType:this,catchValue:n,typeName:x.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Ht.create(this,e)}readonly(){return Pt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const sa=/^c[^\s-]{8,}$/i,ia=/^[0-9a-z]+$/,oa=/^[0-9A-HJKMNP-TV-Z]{26}$/,da=/^[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,ca=/^[a-z0-9_-]{21}$/i,la=/^[-+]?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)?)??$/,ua=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,ha="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let wn;const pa=/^(?:(?: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])$/,ma=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,fa=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,nr="((\\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])))",_a=new RegExp(`^${nr}$`);function rr(t){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`),e}function ga(t){return new RegExp(`^${rr(t)}$`)}function ar(t){let e=`${nr}T${rr(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function ya(t,e){return!!((e==="v4"||!e)&&pa.test(t)||(e==="v6"||!e)&&ma.test(t))}class q extends j{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==g.string){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.string,received:a.parsedType}),T}const n=new U;let r;for(const a of this._def.checks)if(a.kind==="min")e.data.length<a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="max")e.data.length>a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!1,message:a.message}),n.dirty());else if(a.kind==="length"){const s=e.data.length>a.value,o=e.data.length<a.value;(s||o)&&(r=this._getOrReturnCtx(e,r),s?f(r,{code:h.too_big,maximum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}):o&&f(r,{code:h.too_small,minimum:a.value,type:"string",inclusive:!0,exact:!0,message:a.message}),n.dirty())}else if(a.kind==="email")ua.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"email",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="emoji")wn||(wn=new RegExp(ha,"u")),wn.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"emoji",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="uuid")da.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"uuid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="nanoid")ca.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"nanoid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid")sa.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"cuid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="cuid2")ia.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"cuid2",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="ulid")oa.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"ulid",code:h.invalid_string,message:a.message}),n.dirty());else if(a.kind==="url")try{new URL(e.data)}catch{r=this._getOrReturnCtx(e,r),f(r,{validation:"url",code:h.invalid_string,message:a.message}),n.dirty()}else a.kind==="regex"?(a.regex.lastIndex=0,a.regex.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"regex",code:h.invalid_string,message:a.message}),n.dirty())):a.kind==="trim"?e.data=e.data.trim():a.kind==="includes"?e.data.includes(a.value,a.position)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:{includes:a.value,position:a.position},message:a.message}),n.dirty()):a.kind==="toLowerCase"?e.data=e.data.toLowerCase():a.kind==="toUpperCase"?e.data=e.data.toUpperCase():a.kind==="startsWith"?e.data.startsWith(a.value)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:{startsWith:a.value},message:a.message}),n.dirty()):a.kind==="endsWith"?e.data.endsWith(a.value)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:{endsWith:a.value},message:a.message}),n.dirty()):a.kind==="datetime"?ar(a).test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:"datetime",message:a.message}),n.dirty()):a.kind==="date"?_a.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:"date",message:a.message}),n.dirty()):a.kind==="time"?ga(a).test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{code:h.invalid_string,validation:"time",message:a.message}),n.dirty()):a.kind==="duration"?la.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"duration",code:h.invalid_string,message:a.message}),n.dirty()):a.kind==="ip"?ya(e.data,a.version)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"ip",code:h.invalid_string,message:a.message}),n.dirty()):a.kind==="base64"?fa.test(e.data)||(r=this._getOrReturnCtx(e,r),f(r,{validation:"base64",code:h.invalid_string,message:a.message}),n.dirty()):E.assertNever(a);return{status:n.value,value:e.data}}_regex(e,n,r){return this.refinement(a=>e.test(a),{validation:n,code:h.invalid_string,...b.errToObj(r)})}_addCheck(e){return new q({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...b.errToObj(e)})}url(e){return this._addCheck({kind:"url",...b.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...b.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...b.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...b.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...b.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...b.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...b.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...b.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...b.errToObj(e)})}datetime(e){var n,r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(n=e==null?void 0:e.offset)!==null&&n!==void 0?n:!1,local:(r=e==null?void 0:e.local)!==null&&r!==void 0?r:!1,...b.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...b.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...b.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...b.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...b.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...b.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...b.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...b.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...b.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...b.errToObj(n)})}nonempty(e){return this.min(1,b.errToObj(e))}trim(){return new q({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new q({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}q.create=t=>{var e;return new q({checks:[],typeName:x.ZodString,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...O(t)})};function va(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,a=n>r?n:r,s=parseInt(t.toFixed(a).replace(".","")),o=parseInt(e.toFixed(a).replace(".",""));return s%o/Math.pow(10,a)}class ke extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==g.number){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.number,received:a.parsedType}),T}let n;const r=new U;for(const a of this._def.checks)a.kind==="int"?E.isInteger(e.data)||(n=this._getOrReturnCtx(e,n),f(n,{code:h.invalid_type,expected:"integer",received:"float",message:a.message}),r.dirty()):a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_small,minimum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_big,maximum:a.value,type:"number",inclusive:a.inclusive,exact:!1,message:a.message}),r.dirty()):a.kind==="multipleOf"?va(e.data,a.value)!==0&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):a.kind==="finite"?Number.isFinite(e.data)||(n=this._getOrReturnCtx(e,n),f(n,{code:h.not_finite,message:a.message}),r.dirty()):E.assertNever(a);return{status:r.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,r,a){return new ke({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:b.toString(a)}]})}_addCheck(e){return new ke({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:b.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:b.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:b.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:b.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&E.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}}ke.create=t=>new ke({checks:[],typeName:x.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...O(t)});class Te extends j{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==g.bigint){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.bigint,received:a.parsedType}),T}let n;const r=new U;for(const a of this._def.checks)a.kind==="min"?(a.inclusive?e.data<a.value:e.data<=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_small,type:"bigint",minimum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="max"?(a.inclusive?e.data>a.value:e.data>=a.value)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.too_big,type:"bigint",maximum:a.value,inclusive:a.inclusive,message:a.message}),r.dirty()):a.kind==="multipleOf"?e.data%a.value!==BigInt(0)&&(n=this._getOrReturnCtx(e,n),f(n,{code:h.not_multiple_of,multipleOf:a.value,message:a.message}),r.dirty()):E.assertNever(a);return{status:r.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,b.toString(n))}gt(e,n){return this.setLimit("min",e,!1,b.toString(n))}lte(e,n){return this.setLimit("max",e,!0,b.toString(n))}lt(e,n){return this.setLimit("max",e,!1,b.toString(n))}setLimit(e,n,r,a){return new Te({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:b.toString(a)}]})}_addCheck(e){return new Te({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:b.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:b.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:b.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:b.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:b.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Te.create=t=>{var e;return new Te({checks:[],typeName:x.ZodBigInt,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...O(t)})};class Nt extends j{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==g.boolean){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.boolean,received:n.parsedType}),T}return V(e.data)}}Nt.create=t=>new Nt({typeName:x.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...O(t)});class ze extends j{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==g.date){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_type,expected:g.date,received:a.parsedType}),T}if(isNaN(e.data.getTime())){const a=this._getOrReturnCtx(e);return f(a,{code:h.invalid_date}),T}const n=new U;let r;for(const a of this._def.checks)a.kind==="min"?e.data.getTime()<a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_small,message:a.message,inclusive:!0,exact:!1,minimum:a.value,type:"date"}),n.dirty()):a.kind==="max"?e.data.getTime()>a.value&&(r=this._getOrReturnCtx(e,r),f(r,{code:h.too_big,message:a.message,inclusive:!0,exact:!1,maximum:a.value,type:"date"}),n.dirty()):E.assertNever(a);return{status:n.value,value:new Date(e.data.getTime())}}_addCheck(e){return new ze({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:b.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:b.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}ze.create=t=>new ze({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:x.ZodDate,...O(t)});class sn extends j{_parse(e){if(this._getType(e)!==g.symbol){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.symbol,received:n.parsedType}),T}return V(e.data)}}sn.create=t=>new sn({typeName:x.ZodSymbol,...O(t)});class kt extends j{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.undefined,received:n.parsedType}),T}return V(e.data)}}kt.create=t=>new kt({typeName:x.ZodUndefined,...O(t)});class Tt extends j{_parse(e){if(this._getType(e)!==g.null){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.null,received:n.parsedType}),T}return V(e.data)}}Tt.create=t=>new Tt({typeName:x.ZodNull,...O(t)});class it extends j{constructor(){super(...arguments),this._any=!0}_parse(e){return V(e.data)}}it.create=t=>new it({typeName:x.ZodAny,...O(t)});class Me extends j{constructor(){super(...arguments),this._unknown=!0}_parse(e){return V(e.data)}}Me.create=t=>new Me({typeName:x.ZodUnknown,...O(t)});class me extends j{_parse(e){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.never,received:n.parsedType}),T}}me.create=t=>new me({typeName:x.ZodNever,...O(t)});class on extends j{_parse(e){if(this._getType(e)!==g.undefined){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.void,received:n.parsedType}),T}return V(e.data)}}on.create=t=>new on({typeName:x.ZodVoid,...O(t)});class G extends j{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),a=this._def;if(n.parsedType!==g.array)return f(n,{code:h.invalid_type,expected:g.array,received:n.parsedType}),T;if(a.exactLength!==null){const o=n.data.length>a.exactLength.value,d=n.data.length<a.exactLength.value;(o||d)&&(f(n,{code:o?h.too_big:h.too_small,minimum:d?a.exactLength.value:void 0,maximum:o?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(a.minLength!==null&&n.data.length<a.minLength.value&&(f(n,{code:h.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),a.maxLength!==null&&n.data.length>a.maxLength.value&&(f(n,{code:h.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,d)=>a.type._parseAsync(new ie(n,o,n.path,d)))).then(o=>U.mergeArray(r,o));const s=[...n.data].map((o,d)=>a.type._parseSync(new ie(n,o,n.path,d)));return U.mergeArray(r,s)}get element(){return this._def.type}min(e,n){return new G({...this._def,minLength:{value:e,message:b.toString(n)}})}max(e,n){return new G({...this._def,maxLength:{value:e,message:b.toString(n)}})}length(e,n){return new G({...this._def,exactLength:{value:e,message:b.toString(n)}})}nonempty(e){return this.min(1,e)}}G.create=(t,e)=>new G({type:t,minLength:null,maxLength:null,exactLength:null,typeName:x.ZodArray,...O(e)});function Ge(t){if(t instanceof A){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=ae.create(Ge(r))}return new A({...t._def,shape:()=>e})}else return t instanceof G?new G({...t._def,type:Ge(t.element)}):t instanceof ae?ae.create(Ge(t.unwrap())):t instanceof Oe?Oe.create(Ge(t.unwrap())):t instanceof oe?oe.create(t.items.map(e=>Ge(e))):t}class A extends j{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=E.objectKeys(e);return this._cached={shape:e,keys:n}}_parse(e){if(this._getType(e)!==g.object){const c=this._getOrReturnCtx(e);return f(c,{code:h.invalid_type,expected:g.object,received:c.parsedType}),T}const{status:n,ctx:r}=this._processInputParams(e),{shape:a,keys:s}=this._getCached(),o=[];if(!(this._def.catchall instanceof me&&this._def.unknownKeys==="strip"))for(const c in r.data)s.includes(c)||o.push(c);const d=[];for(const c of s){const l=a[c],u=r.data[c];d.push({key:{status:"valid",value:c},value:l._parse(new ie(r,u,r.path,c)),alwaysSet:c in r.data})}if(this._def.catchall instanceof me){const c=this._def.unknownKeys;if(c==="passthrough")for(const l of o)d.push({key:{status:"valid",value:l},value:{status:"valid",value:r.data[l]}});else if(c==="strict")o.length>0&&(f(r,{code:h.unrecognized_keys,keys:o}),n.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const l of o){const u=r.data[l];d.push({key:{status:"valid",value:l},value:c._parse(new ie(r,u,r.path,l)),alwaysSet:l in r.data})}}return r.common.async?Promise.resolve().then(async()=>{const c=[];for(const l of d){const u=await l.key,Z=await l.value;c.push({key:u,value:Z,alwaysSet:l.alwaysSet})}return c}).then(c=>U.mergeObjectSync(n,c)):U.mergeObjectSync(n,d)}get shape(){return this._def.shape()}strict(e){return b.errToObj,new A({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{var a,s,o,d;const c=(o=(s=(a=this._def).errorMap)===null||s===void 0?void 0:s.call(a,n,r).message)!==null&&o!==void 0?o:r.defaultError;return n.code==="unrecognized_keys"?{message:(d=b.errToObj(e).message)!==null&&d!==void 0?d:c}:{message:c}}}:{}})}strip(){return new A({...this._def,unknownKeys:"strip"})}passthrough(){return new A({...this._def,unknownKeys:"passthrough"})}extend(e){return new A({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new A({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:x.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new A({...this._def,catchall:e})}pick(e){const n={};return E.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new A({...this._def,shape:()=>n})}omit(e){const n={};return E.objectKeys(this.shape).forEach(r=>{e[r]||(n[r]=this.shape[r])}),new A({...this._def,shape:()=>n})}deepPartial(){return Ge(this)}partial(e){const n={};return E.objectKeys(this.shape).forEach(r=>{const a=this.shape[r];e&&!e[r]?n[r]=a:n[r]=a.optional()}),new A({...this._def,shape:()=>n})}required(e){const n={};return E.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])n[r]=this.shape[r];else{let a=this.shape[r];for(;a instanceof ae;)a=a._def.innerType;n[r]=a}}),new A({...this._def,shape:()=>n})}keyof(){return sr(E.objectKeys(this.shape))}}A.create=(t,e)=>new A({shape:()=>t,unknownKeys:"strip",catchall:me.create(),typeName:x.ZodObject,...O(e)});A.strictCreate=(t,e)=>new A({shape:()=>t,unknownKeys:"strict",catchall:me.create(),typeName:x.ZodObject,...O(e)});A.lazycreate=(t,e)=>new A({shape:t,unknownKeys:"strip",catchall:me.create(),typeName:x.ZodObject,...O(e)});class Ct extends j{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function a(s){for(const d of s)if(d.result.status==="valid")return d.result;for(const d of s)if(d.result.status==="dirty")return n.common.issues.push(...d.ctx.common.issues),d.result;const o=s.map(d=>new K(d.ctx.common.issues));return f(n,{code:h.invalid_union,unionErrors:o}),T}if(n.common.async)return Promise.all(r.map(async s=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(a);{let s;const o=[];for(const c of r){const l={...n,common:{...n.common,issues:[]},parent:null},u=c._parseSync({data:n.data,path:n.path,parent:l});if(u.status==="valid")return u;u.status==="dirty"&&!s&&(s={result:u,ctx:l}),l.common.issues.length&&o.push(l.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const d=o.map(c=>new K(c));return f(n,{code:h.invalid_union,unionErrors:d}),T}}get options(){return this._def.options}}Ct.create=(t,e)=>new Ct({options:t,typeName:x.ZodUnion,...O(e)});const we=t=>t instanceof jt?we(t.schema):t instanceof Y?we(t.innerType()):t instanceof It?[t.value]:t instanceof Ce?t.options:t instanceof Zt?E.objectValues(t.enum):t instanceof Et?we(t._def.innerType):t instanceof kt?[void 0]:t instanceof Tt?[null]:t instanceof ae?[void 0,...we(t.unwrap())]:t instanceof Oe?[null,...we(t.unwrap())]:t instanceof zn||t instanceof Pt?we(t.unwrap()):t instanceof $t?we(t._def.innerType):[];class yn extends j{_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==g.object)return f(n,{code:h.invalid_type,expected:g.object,received:n.parsedType}),T;const r=this.discriminator,a=n.data[r],s=this.optionsMap.get(a);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(f(n,{code:h.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),T)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){const a=new Map;for(const s of n){const o=we(s.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const d of o){if(a.has(d))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(d)}`);a.set(d,s)}}return new yn({typeName:x.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:a,...O(r)})}}function In(t,e){const n=xe(t),r=xe(e);if(t===e)return{valid:!0,data:t};if(n===g.object&&r===g.object){const a=E.objectKeys(e),s=E.objectKeys(t).filter(d=>a.indexOf(d)!==-1),o={...t,...e};for(const d of s){const c=In(t[d],e[d]);if(!c.valid)return{valid:!1};o[d]=c.data}return{valid:!0,data:o}}else if(n===g.array&&r===g.array){if(t.length!==e.length)return{valid:!1};const a=[];for(let s=0;s<t.length;s++){const o=t[s],d=e[s],c=In(o,d);if(!c.valid)return{valid:!1};a.push(c.data)}return{valid:!0,data:a}}else return n===g.date&&r===g.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class Ot extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=(s,o)=>{if(Sn(s)||Sn(o))return T;const d=In(s.value,o.value);return d.valid?((jn(s)||jn(o))&&n.dirty(),{status:n.value,value:d.data}):(f(r,{code:h.invalid_intersection_types}),T)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,o])=>a(s,o)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Ot.create=(t,e,n)=>new Ot({left:t,right:e,typeName:x.ZodIntersection,...O(n)});class oe extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.array)return f(r,{code:h.invalid_type,expected:g.array,received:r.parsedType}),T;if(r.data.length<this._def.items.length)return f(r,{code:h.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),T;!this._def.rest&&r.data.length>this._def.items.length&&(f(r,{code:h.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const a=[...r.data].map((s,o)=>{const d=this._def.items[o]||this._def.rest;return d?d._parse(new ie(r,s,r.path,o)):null}).filter(s=>!!s);return r.common.async?Promise.all(a).then(s=>U.mergeArray(n,s)):U.mergeArray(n,a)}get items(){return this._def.items}rest(e){return new oe({...this._def,rest:e})}}oe.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new oe({items:t,typeName:x.ZodTuple,rest:null,...O(e)})};class St extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.object)return f(r,{code:h.invalid_type,expected:g.object,received:r.parsedType}),T;const a=[],s=this._def.keyType,o=this._def.valueType;for(const d in r.data)a.push({key:s._parse(new ie(r,d,r.path,d)),value:o._parse(new ie(r,r.data[d],r.path,d)),alwaysSet:d in r.data});return r.common.async?U.mergeObjectAsync(n,a):U.mergeObjectSync(n,a)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof j?new St({keyType:e,valueType:n,typeName:x.ZodRecord,...O(r)}):new St({keyType:q.create(),valueType:e,typeName:x.ZodRecord,...O(n)})}}class dn extends j{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.map)return f(r,{code:h.invalid_type,expected:g.map,received:r.parsedType}),T;const a=this._def.keyType,s=this._def.valueType,o=[...r.data.entries()].map(([d,c],l)=>({key:a._parse(new ie(r,d,r.path,[l,"key"])),value:s._parse(new ie(r,c,r.path,[l,"value"]))}));if(r.common.async){const d=new Map;return Promise.resolve().then(async()=>{for(const c of o){const l=await c.key,u=await c.value;if(l.status==="aborted"||u.status==="aborted")return T;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}})}else{const d=new Map;for(const c of o){const l=c.key,u=c.value;if(l.status==="aborted"||u.status==="aborted")return T;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}}}}dn.create=(t,e,n)=>new dn({valueType:e,keyType:t,typeName:x.ZodMap,...O(n)});class Ue extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==g.set)return f(r,{code:h.invalid_type,expected:g.set,received:r.parsedType}),T;const a=this._def;a.minSize!==null&&r.data.size<a.minSize.value&&(f(r,{code:h.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),n.dirty()),a.maxSize!==null&&r.data.size>a.maxSize.value&&(f(r,{code:h.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),n.dirty());const s=this._def.valueType;function o(c){const l=new Set;for(const u of c){if(u.status==="aborted")return T;u.status==="dirty"&&n.dirty(),l.add(u.value)}return{status:n.value,value:l}}const d=[...r.data.values()].map((c,l)=>s._parse(new ie(r,c,r.path,l)));return r.common.async?Promise.all(d).then(c=>o(c)):o(d)}min(e,n){return new Ue({...this._def,minSize:{value:e,message:b.toString(n)}})}max(e,n){return new Ue({...this._def,maxSize:{value:e,message:b.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}Ue.create=(t,e)=>new Ue({valueType:t,minSize:null,maxSize:null,typeName:x.ZodSet,...O(e)});class nt extends j{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==g.function)return f(n,{code:h.invalid_type,expected:g.function,received:n.parsedType}),T;function r(d,c){return nn({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,tn(),st].filter(l=>!!l),issueData:{code:h.invalid_arguments,argumentsError:c}})}function a(d,c){return nn({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,tn(),st].filter(l=>!!l),issueData:{code:h.invalid_return_type,returnTypeError:c}})}const s={errorMap:n.common.contextualErrorMap},o=n.data;if(this._def.returns instanceof ot){const d=this;return V(async function(...c){const l=new K([]),u=await d._def.args.parseAsync(c,s).catch(R=>{throw l.addIssue(r(c,R)),l}),Z=await Reflect.apply(o,this,u);return await d._def.returns._def.type.parseAsync(Z,s).catch(R=>{throw l.addIssue(a(Z,R)),l})})}else{const d=this;return V(function(...c){const l=d._def.args.safeParse(c,s);if(!l.success)throw new K([r(c,l.error)]);const u=Reflect.apply(o,this,l.data),Z=d._def.returns.safeParse(u,s);if(!Z.success)throw new K([a(u,Z.error)]);return Z.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new nt({...this._def,args:oe.create(e).rest(Me.create())})}returns(e){return new nt({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new nt({args:e||oe.create([]).rest(Me.create()),returns:n||Me.create(),typeName:x.ZodFunction,...O(r)})}}class jt extends j{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}jt.create=(t,e)=>new jt({getter:t,typeName:x.ZodLazy,...O(e)});class It extends j{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return f(n,{received:n.data,code:h.invalid_literal,expected:this._def.value}),T}return{status:"valid",value:e.data}}get value(){return this._def.value}}It.create=(t,e)=>new It({value:t,typeName:x.ZodLiteral,...O(e)});function sr(t,e){return new Ce({values:t,typeName:x.ZodEnum,...O(e)})}class Ce extends j{constructor(){super(...arguments),ft.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return f(n,{expected:E.joinValues(r),received:n.parsedType,code:h.invalid_type}),T}if(an(this,ft)||tr(this,ft,new Set(this._def.values)),!an(this,ft).has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return f(n,{received:n.data,code:h.invalid_enum_value,options:r}),T}return V(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return Ce.create(e,{...this._def,...n})}exclude(e,n=this._def){return Ce.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}}ft=new WeakMap;Ce.create=sr;class Zt extends j{constructor(){super(...arguments),_t.set(this,void 0)}_parse(e){const n=E.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==g.string&&r.parsedType!==g.number){const a=E.objectValues(n);return f(r,{expected:E.joinValues(a),received:r.parsedType,code:h.invalid_type}),T}if(an(this,_t)||tr(this,_t,new Set(E.getValidEnumValues(this._def.values))),!an(this,_t).has(e.data)){const a=E.objectValues(n);return f(r,{received:r.data,code:h.invalid_enum_value,options:a}),T}return V(e.data)}get enum(){return this._def.values}}_t=new WeakMap;Zt.create=(t,e)=>new Zt({values:t,typeName:x.ZodNativeEnum,...O(e)});class ot extends j{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==g.promise&&n.common.async===!1)return f(n,{code:h.invalid_type,expected:g.promise,received:n.parsedType}),T;const r=n.parsedType===g.promise?n.data:Promise.resolve(n.data);return V(r.then(a=>this._def.type.parseAsync(a,{path:n.path,errorMap:n.common.contextualErrorMap})))}}ot.create=(t,e)=>new ot({type:t,typeName:x.ZodPromise,...O(e)});class Y extends j{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===x.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=this._def.effect||null,s={addIssue:o=>{f(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),a.type==="preprocess"){const o=a.transform(r.data,s);if(r.common.async)return Promise.resolve(o).then(async d=>{if(n.value==="aborted")return T;const c=await this._def.schema._parseAsync({data:d,path:r.path,parent:r});return c.status==="aborted"?T:c.status==="dirty"||n.value==="dirty"?rn(c.value):c});{if(n.value==="aborted")return T;const d=this._def.schema._parseSync({data:o,path:r.path,parent:r});return d.status==="aborted"?T:d.status==="dirty"||n.value==="dirty"?rn(d.value):d}}if(a.type==="refinement"){const o=d=>{const c=a.refinement(d,s);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return d};if(r.common.async===!1){const d=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return d.status==="aborted"?T:(d.status==="dirty"&&n.dirty(),o(d.value),{status:n.value,value:d.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(d=>d.status==="aborted"?T:(d.status==="dirty"&&n.dirty(),o(d.value).then(()=>({status:n.value,value:d.value}))))}if(a.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!wt(o))return o;const d=a.transform(o.value,s);if(d instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:d}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>wt(o)?Promise.resolve(a.transform(o.value,s)).then(d=>({status:n.value,value:d})):o);E.assertNever(a)}}Y.create=(t,e,n)=>new Y({schema:t,typeName:x.ZodEffects,effect:e,...O(n)});Y.createWithPreprocess=(t,e,n)=>new Y({schema:e,effect:{type:"preprocess",transform:t},typeName:x.ZodEffects,...O(n)});class ae extends j{_parse(e){return this._getType(e)===g.undefined?V(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}ae.create=(t,e)=>new ae({innerType:t,typeName:x.ZodOptional,...O(e)});class Oe extends j{_parse(e){return this._getType(e)===g.null?V(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Oe.create=(t,e)=>new Oe({innerType:t,typeName:x.ZodNullable,...O(e)});class Et extends j{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===g.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Et.create=(t,e)=>new Et({innerType:t,typeName:x.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...O(e)});class $t extends j{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return xt(a)?a.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new K(r.common.issues)},input:r.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new K(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}$t.create=(t,e)=>new $t({innerType:t,typeName:x.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...O(e)});class cn extends j{_parse(e){if(this._getType(e)!==g.nan){const n=this._getOrReturnCtx(e);return f(n,{code:h.invalid_type,expected:g.nan,received:n.parsedType}),T}return{status:"valid",value:e.data}}}cn.create=t=>new cn({typeName:x.ZodNaN,...O(t)});const ba=Symbol("zod_brand");class zn extends j{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Ht extends j{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const a=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?T:a.status==="dirty"?(n.dirty(),rn(a.value)):this._def.out._parseAsync({data:a.value,path:r.path,parent:r})})();{const a=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?T:a.status==="dirty"?(n.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:r.path,parent:r})}}static create(e,n){return new Ht({in:e,out:n,typeName:x.ZodPipeline})}}class Pt extends j{_parse(e){const n=this._def.innerType._parse(e),r=a=>(wt(a)&&(a.value=Object.freeze(a.value)),a);return xt(n)?n.then(a=>r(a)):r(n)}unwrap(){return this._def.innerType}}Pt.create=(t,e)=>new Pt({innerType:t,typeName:x.ZodReadonly,...O(e)});function ir(t,e={},n){return t?it.create().superRefine((r,a)=>{var s,o;if(!t(r)){const d=typeof e=="function"?e(r):typeof e=="string"?{message:e}:e,c=(o=(s=d.fatal)!==null&&s!==void 0?s:n)!==null&&o!==void 0?o:!0,l=typeof d=="string"?{message:d}:d;a.addIssue({code:"custom",...l,fatal:c})}}):it.create()}const wa={object:A.lazycreate};var x;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(x||(x={}));const xa=(t,e={message:`Input not instance of ${t.name}`})=>ir(n=>n instanceof t,e),or=q.create,dr=ke.create,Na=cn.create,ka=Te.create,cr=Nt.create,Ta=ze.create,Ca=sn.create,Oa=kt.create,Sa=Tt.create,ja=it.create,Ia=Me.create,Za=me.create,Ea=on.create,$a=G.create,Pa=A.create,Aa=A.strictCreate,Da=Ct.create,Ra=yn.create,Ma=Ot.create,La=oe.create,za=St.create,Ua=dn.create,Fa=Ue.create,Va=nt.create,Ba=jt.create,Ka=It.create,Wa=Ce.create,Ja=Zt.create,qa=ot.create,Jn=Y.create,Qa=ae.create,Ga=Oe.create,Ha=Y.createWithPreprocess,Ya=Ht.create,Xa=()=>or().optional(),es=()=>dr().optional(),ts=()=>cr().optional(),ns={string:t=>q.create({...t,coerce:!0}),number:t=>ke.create({...t,coerce:!0}),boolean:t=>Nt.create({...t,coerce:!0}),bigint:t=>Te.create({...t,coerce:!0}),date:t=>ze.create({...t,coerce:!0})},rs=T;var i=Object.freeze({__proto__:null,defaultErrorMap:st,setErrorMap:ra,getErrorMap:tn,makeIssue:nn,EMPTY_PATH:aa,addIssueToContext:f,ParseStatus:U,INVALID:T,DIRTY:rn,OK:V,isAborted:Sn,isDirty:jn,isValid:wt,isAsync:xt,get util(){return E},get objectUtil(){return On},ZodParsedType:g,getParsedType:xe,ZodType:j,datetimeRegex:ar,ZodString:q,ZodNumber:ke,ZodBigInt:Te,ZodBoolean:Nt,ZodDate:ze,ZodSymbol:sn,ZodUndefined:kt,ZodNull:Tt,ZodAny:it,ZodUnknown:Me,ZodNever:me,ZodVoid:on,ZodArray:G,ZodObject:A,ZodUnion:Ct,ZodDiscriminatedUnion:yn,ZodIntersection:Ot,ZodTuple:oe,ZodRecord:St,ZodMap:dn,ZodSet:Ue,ZodFunction:nt,ZodLazy:jt,ZodLiteral:It,ZodEnum:Ce,ZodNativeEnum:Zt,ZodPromise:ot,ZodEffects:Y,ZodTransformer:Y,ZodOptional:ae,ZodNullable:Oe,ZodDefault:Et,ZodCatch:$t,ZodNaN:cn,BRAND:ba,ZodBranded:zn,ZodPipeline:Ht,ZodReadonly:Pt,custom:ir,Schema:j,ZodSchema:j,late:wa,get ZodFirstPartyTypeKind(){return x},coerce:ns,any:ja,array:$a,bigint:ka,boolean:cr,date:Ta,discriminatedUnion:Ra,effect:Jn,enum:Wa,function:Va,instanceof:xa,intersection:Ma,lazy:Ba,literal:Ka,map:Ua,nan:Na,nativeEnum:Ja,never:Za,null:Sa,nullable:Ga,number:dr,object:Pa,oboolean:ts,onumber:es,optional:Qa,ostring:Xa,pipeline:Ya,preprocess:Ha,promise:qa,record:za,set:Fa,strictObject:Aa,string:or,symbol:Ca,transformer:Jn,tuple:La,undefined:Oa,union:Da,unknown:Ia,void:Ea,NEVER:rs,ZodIssueCode:h,quotelessJson:na,ZodError:K});ta(i);i.object({start:i.number(),limit:i.number(),length:i.number()});const Un=i.object({created_at:i.string(),updated_at:i.string()}),as=i.object({email:i.string().optional(),email_verified:i.boolean().optional(),name:i.string().optional(),username:i.string().optional(),given_name:i.string().optional(),phone_number:i.string().optional(),phone_verified:i.boolean().optional(),family_name:i.string().optional()}).catchall(i.any()),ss=i.object({connection:i.string(),user_id:i.string(),provider:i.string(),isSocial:i.boolean(),access_token:i.string().optional(),access_token_secret:i.string().optional(),refresh_token:i.string().optional(),profileData:as.optional()}),lr=i.object({email:i.string().optional(),username:i.string().optional(),given_name:i.string().optional(),family_name:i.string().optional(),nickname:i.string().optional(),name:i.string().optional(),picture:i.string().optional(),locale:i.string().optional(),linked_to:i.string().optional(),profileData:i.string().optional(),user_id:i.string().optional(),app_metadata:i.any().default({}).optional(),user_metadata:i.any().default({}).optional()}),is=lr.extend({email_verified:i.boolean().default(!1),verify_email:i.boolean().optional(),last_ip:i.string().optional(),last_login:i.string().optional(),user_id:i.string().optional(),provider:i.string().default("email"),connection:i.string().default("email")});i.object({...is.shape,...Un.shape,user_id:i.string(),email:i.string(),is_social:i.boolean(),login_count:i.number(),identities:i.array(ss).optional()});lr.extend({email:i.string(),login_count:i.number(),multifactor:i.array(i.string()).optional(),last_ip:i.string().optional(),last_login:i.string().optional(),user_id:i.string()}).catchall(i.any());const os="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let ds=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=os[n[t]&63];return e};const cs=i.object({audience:i.string().optional(),recipient:i.string().optional(),createUpnClaim:i.boolean().optional(),mapUnknownClaimsAsIs:i.boolean().optional(),passthroughClaimsWithNoMapping:i.boolean().optional(),mapIdentities:i.boolean().optional(),signatureAlgorithm:i.string().optional(),digestAlgorithm:i.string().optional(),issuer:i.string().optional(),destination:i.string().optional(),lifetimeInSeconds:i.number().optional(),signResponse:i.boolean().optional(),nameIdentifierFormat:i.string().optional(),nameIdentifierProbes:i.array(i.string()).optional(),authnContextClassRef:i.string().optional(),mappings:i.record(i.string()).optional()}),ls=i.object({id:i.string(),name:i.string(),callbacks:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of URLs whitelisted to use as a callback to the client after authentication."}),allowed_origins:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of URLs allowed to make requests from JavaScript to Auth0 API (typically used with CORS). By default, all your callback URLs will be allowed. This field allows you to enter other origins if necessary. You can also use wildcards at the subdomain level. Query strings and hash information are not taken into account when validating these URLs."}),web_origins:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of allowed origins for use with Cross-Origin Authentication, Device Flow, and web message response mode."}),allowed_logout_urls:i.array(i.string()).default([]).optional().openapi({description:"Comma-separated list of URLs that are valid to redirect to after logout from Auth0. Wildcards are allowed for subdomains."}),allowed_clients:i.array(i.string()).default([]).optional().openapi({description:"Ids of clients that will be allowed to perform delegation requests. Clients that will be allowed to make delegation request. By default, all your clients will be allowed. This field allows you to specify specific clients"}),addons:i.object({samlp:cs.optional()}).default({}).optional().openapi({description:"Addons associated with the client. The key is the addon's package name and the value is an object with the configuration for the addon."}),email_validation:i.enum(["enabled","disabled","enforced"]).default("enforced").optional().openapi({description:"Defines if it possible to sign in with an unverified email and if verification emails will be sent. This is not available in auth0"}),client_secret:i.string().default(()=>ds()).optional(),disable_sign_ups:i.boolean().optional().default(!1).openapi({description:"Prevents users from signing up using the hosted login page. This is not available in auth0"})}),us=i.object({created_at:i.string().transform(t=>t===null?"":t),updated_at:i.string().transform(t=>t===null?"":t),...ls.shape});var ur=(t=>(t.TOKEN="token",t.TOKEN_ID_TOKEN="token id_token",t.CODE="code",t))(ur||{}),hr=(t=>(t.QUERY="query",t.FRAGMENT="fragment",t.FORM_POST="form_post",t.WEB_MESSAGE="web_message",t.SAML_POST="saml_post",t))(hr||{}),pr=(t=>(t.S265="S256",t.plain="plain",t))(pr||{});const hs=i.object({client_id:i.string(),vendor_id:i.string().optional(),act_as:i.string().optional(),response_type:i.nativeEnum(ur).optional(),response_mode:i.nativeEnum(hr).optional(),redirect_uri:i.string().optional(),audience:i.string().optional(),state:i.string().optional(),nonce:i.string().optional(),scope:i.string().optional(),prompt:i.string().optional(),code_challenge_method:i.nativeEnum(pr).optional(),code_challenge:i.string().optional(),username:i.string().optional(),ui_locales:i.string().optional()});i.object({colors:i.object({primary:i.string(),page_background:i.object({type:i.string().optional(),start:i.string().optional(),end:i.string().optional(),angle_deg:i.number().optional()}).optional()}).optional(),logo_url:i.string().optional(),favicon_url:i.string().optional(),font:i.object({url:i.string()}).optional()});const ps=i.object({id:i.string().optional(),name:i.string(),strategy:i.enum(["google-oauth2","facebook","vipps","freja","apple","email","auth0","authhero","Username-Password-Authentication","oidc","oauth2","custom"]),options:i.object({kid:i.string().optional(),team_id:i.string().optional(),realms:i.string().optional(),client_id:i.string().optional(),client_secret:i.string().optional(),app_secret:i.string().optional(),scope:i.string().optional(),authorization_endpoint:i.string().default("").optional(),token_endpoint:i.string().default("").optional(),userinfo_endpoint:i.string().default("").optional(),jwks_uri:i.string().default("").optional(),discovery_url:i.string().default("").optional(),issuer:i.string().default("").optional()}).default({}).optional(),enabled_clients:i.array(i.string()).default([]).optional(),response_type:i.custom().optional(),response_mode:i.custom().optional()}),mr=i.object({id:i.string(),created_at:i.string().transform(t=>t===null?"":t),updated_at:i.string().transform(t=>t===null?"":t)}).extend(ps.shape),ms=i.object({name:i.string(),audience:i.string(),sender_email:i.string().email(),sender_name:i.string(),support_url:i.string().url().optional(),logo:i.string().url().optional(),primary_color:i.string().optional(),secondary_color:i.string().optional(),language:i.string().optional()}),fs=i.object({created_at:i.string().transform(t=>t===null?"":t),updated_at:i.string().transform(t=>t===null?"":t),id:i.string(),...ms.shape});i.object({logoUrl:i.string(),loginBackgroundImage:i.string().nullish(),style:i.object({primaryColor:i.string(),buttonTextColor:i.string(),primaryHoverColor:i.string()}),supportEmail:i.string().nullable(),supportUrl:i.string().nullable(),name:i.string(),showGreyishBackground:i.boolean().optional(),termsAndConditionsUrl:i.string().nullable(),companyName:i.string().optional(),checkoutHideSocial:i.boolean().optional(),siteUrl:i.string().nullable(),manageSubscriptionsUrl:i.string().optional()});const _s=i.object({domain:i.string(),dkim_private_key:i.string().optional(),dkim_public_key:i.string().optional(),email_api_key:i.string().optional(),email_service:i.union([i.literal("mailgun"),i.literal("mailchannels")]).optional()});i.object({...us.shape,domains:i.array(_s),tenant:fs,connections:i.array(mr)});const gs=i.enum(["password_reset","email_verification","otp","authorization_code","oauth2_state","ticket"]),ys=i.object({code_id:i.string().openapi({description:"The code that will be used in for instance an email verification flow"}),login_id:i.string().openapi({description:"The id of the login session that the code is connected to"}),connection_id:i.string().optional().openapi({description:"The connection that the code is connected to"}),code_type:gs,expires_at:i.string(),used_at:i.string().optional(),user_id:i.string().optional()}),vs=i.object({...ys.shape,created_at:i.string()}),bs=i.object({domain:i.string(),dkim_private_key:i.string().optional(),dkim_public_key:i.string().optional(),email_api_key:i.string().optional(),email_service:i.enum(["mailgun","mailchannels"])});Un.extend({...bs.shape,id:i.string()});const ws=i.object({trigger_id:i.enum(["pre-user-signup","post-user-registration","post-user-login"]),enabled:i.boolean().default(!1),url:i.string(),hook_id:i.string().optional(),synchronous:i.boolean().default(!1),priority:i.number().optional()});ws.extend({...Un.shape,hook_id:i.string()});const xs=i.object({alg:i.enum(["RS256","RS384","RS512","ES256","ES384","ES512","HS256","HS384","HS512"]),e:i.string(),kid:i.string(),kty:i.enum(["RSA","EC","oct"]),n:i.string(),x5t:i.string().optional(),x5c:i.array(i.string()).optional(),use:i.enum(["sig","enc"]).optional()});i.object({keys:i.array(xs)});i.object({issuer:i.string(),authorization_endpoint:i.string(),token_endpoint:i.string(),device_authorization_endpoint:i.string(),userinfo_endpoint:i.string(),mfa_challenge_endpoint:i.string(),jwks_uri:i.string(),registration_endpoint:i.string(),revocation_endpoint:i.string(),scopes_supported:i.array(i.string()),response_types_supported:i.array(i.string()),code_challenge_methods_supported:i.array(i.string()),response_modes_supported:i.array(i.string()),subject_types_supported:i.array(i.string()),id_token_signing_alg_values_supported:i.array(i.string()),token_endpoint_auth_methods_supported:i.array(i.string()),claims_supported:i.array(i.string()),request_uri_parameter_supported:i.boolean(),request_parameter_supported:i.boolean(),token_endpoint_auth_signing_alg_values_supported:i.array(i.string())});const Ns=i.object({auth0Client:i.string().optional(),authParams:hs,expires_at:i.string(),deleted_at:i.string().optional(),ip:i.string().optional()}).openapi({description:"This represents a login sesion"}),ks=i.object({...Ns.shape,login_id:i.string().openapi({description:"This is is used as the state in the universal login"}),created_at:i.string(),updated_at:i.string()}),Ts=i.enum(["cls","fsa","fs","f","fc","fcoa","fcp","fh","fp","fs","fu","s","sapi","scoa","scp","scpr","scu","seacft","serft","slo","ss","ssa","sv","svr"]),Cs=i.object({name:i.string(),version:i.string(),env:i.object({node:i.string().optional()}).optional()});i.object({type:Ts,date:i.string(),description:i.string().optional(),log_id:i.string().optional(),_id:i.string().optional(),ip:i.string(),user_agent:i.string(),details:i.any().optional(),isMobile:i.boolean(),user_id:i.string().optional(),user_name:i.string().optional(),connection:i.string().optional(),connection_id:i.string().optional(),client_id:i.string().optional(),client_name:i.string().optional(),audience:i.string().optional(),scope:i.array(i.string()).optional(),strategy:i.string().optional(),strategy_type:i.string().optional(),hostname:i.string().optional(),auth0_client:Cs.optional()});const Os=i.object({user_id:i.string(),password:i.string(),algorithm:i.enum(["bcrypt","argon2id"]).default("argon2id")});i.object({...Os.shape,created_at:i.string(),updated_at:i.string()});const Ss=i.object({session_id:i.string(),client_id:i.string(),expires_at:i.string(),used_at:i.string(),deleted_at:i.string().optional(),user_id:i.string()});i.object({created_at:i.string(),...Ss.shape});i.object({kid:i.string().openapi({description:"The key id of the signing key"}),cert:i.string().openapi({description:"The public certificate of the signing key"}),fingerprint:i.string().openapi({description:"The cert fingerprint"}),thumbprint:i.string().openapi({description:"The cert thumbprint"}),pkcs7:i.string().optional().openapi({description:"The private key in pkcs7 format"}),current:i.boolean().optional().openapi({description:"True if the key is the current key"}),next:i.boolean().optional().openapi({description:"True if the key is the next key"}),previous:i.boolean().optional().openapi({description:"True if the key is the previous key"}),current_since:i.string().optional().openapi({description:"The date and time when the key became the current key"}),current_until:i.string().optional().openapi({description:"The date and time when the current key was rotated"}),revoked:i.boolean().optional().openapi({description:"True if the key is revoked"}),revoked_at:i.string().optional().openapi({description:"The date and time when the key was revoked"})});var fr=(t=>(t.RefreshToken="refresh_token",t.AuthorizationCode="authorization_code",t.ClientCredential="client_credentials",t.Passwordless="passwordless",t.Password="password",t))(fr||{});const Fn=i.nativeEnum(fr);i.object({grant_type:Fn.refine(t=>t==="authorization_code"),code:i.string(),client_secret:i.string(),client_id:i.string()});i.object({grant_type:Fn.refine(t=>t==="authorization_code"),code:i.string(),code_verifier:i.string(),client_id:i.string().optional(),redirect_uri:i.string()});i.object({grant_type:Fn.refine(t=>t==="client_credentials"),scope:i.string().optional(),client_secret:i.string(),client_id:i.string(),audience:i.string().optional()});i.object({access_token:i.string(),id_token:i.string().optional(),scope:i.string().optional(),state:i.string().optional(),refresh_token:i.string().optional(),token_type:i.string(),expires_in:i.number()});i.object({code:i.string(),state:i.string().optional()});const js=i.object({button_border_radius:i.number(),button_border_weight:i.number(),buttons_style:i.enum(["pill"]),input_border_radius:i.number(),input_border_weight:i.number(),inputs_style:i.enum(["pill"]),show_widget_shadow:i.boolean(),widget_border_weight:i.number(),widget_corner_radius:i.number()}),Is=i.object({base_focus_color:i.string(),base_hover_color:i.string(),body_text:i.string(),captcha_widget_theme:i.enum(["auto"]),error:i.string(),header:i.string(),icons:i.string(),input_background:i.string(),input_border:i.string(),input_filled_text:i.string(),input_labels_placeholders:i.string(),links_focused_components:i.string(),primary_button:i.string(),primary_button_label:i.string(),secondary_button_border:i.string(),secondary_button_label:i.string(),success:i.string(),widget_background:i.string(),widget_border:i.string()}),Qe=i.object({bold:i.boolean(),size:i.number()}),Zs=i.object({body_text:Qe,buttons_text:Qe,font_url:i.string(),input_labels:Qe,links:Qe,links_style:i.enum(["normal"]),reference_text_size:i.number(),subtitle:Qe,title:Qe}),Es=i.object({background_color:i.string(),background_image_url:i.string(),page_layout:i.enum(["center"])}),$s=i.object({header_text_alignment:i.enum(["center"]),logo_height:i.number(),logo_position:i.enum(["center"]),logo_url:i.string(),social_buttons_layout:i.enum(["bottom"])}),Ps=i.object({borders:js,colors:Is,displayName:i.string(),fonts:Zs,page_background:Es,widget:$s});Ps.extend({themeId:i.string()});const As=i.object({universal_login_experience:i.enum(["new","classic"]).default("new"),identifier_first:i.boolean().default(!0),password_first:i.boolean().default(!1),webauthn_platform_first_factor:i.boolean()});function Vn(t){const[e,n]=t.split("|");if(!e||!n)throw new Error(`Invalid user_id: ${t}`);return{connection:e,id:n}}function _r(t){let e={};try{e=JSON.parse(t.profileData||"{}")}catch(n){console.error("Error parsing profileData",n)}return{connection:t.connection,provider:t.provider,user_id:Vn(t.user_id).id,isSocial:!!t.is_social,profileData:{email:t.email,email_verified:!!t.email_verified,...e}}}function Ds(t){return async(e,n)=>{const[r,a]=await Promise.all([t.selectFrom("users").where("users.tenant_id","=",e).where("users.user_id","=",n).selectAll().executeTakeFirst(),t.selectFrom("users").where("users.tenant_id","=",e).where("users.linked_to","=",n).selectAll().execute()]);if(!r)return null;const{tenant_id:s,...o}=r,d={...o,email:r.email||"",email_verified:r.email_verified===1,is_social:r.is_social===1,app_metadata:JSON.parse(r.app_metadata),user_metadata:JSON.parse(r.user_metadata),identities:[{connection:r.connection,provider:r.provider,user_id:Vn(r.user_id).id,isSocial:!!r.is_social},...a.map(_r)]};return M(d)}}function Be(t,e,n,r){return n.split(/\s+/).map(s=>s.replace(/^([^:]+)=/g,"$1:")).map(s=>{let o=s.startsWith("-"),d,c,l,u;return s.startsWith("-_exists_:")?(d=s.substring(10),l=!0,o=!0):s.startsWith("_exists_:")?(d=s.substring(9),l=!0,o=!1):s.includes(":")?(o=s.startsWith("-"),[d,c]=o?s.substring(1).split(":"):s.split(":"),l=!1,c.startsWith(">=")?(u=">=",c=c.substring(2)):c.startsWith(">")?(u=">",c=c.substring(1)):c.startsWith("<=")?(console.log("value",c),u="<=",c=c.substring(2)):c.startsWith("<")?(u="<",c=c.substring(1)):u="="):(d=null,c=s,l=!1),{key:d,value:c,isNegation:o,isExistsQuery:l,operator:u}}).forEach(({key:s,value:o,isNegation:d,isExistsQuery:c,operator:l})=>{if(s)if(c)d?e=e.where(s,"is",null):e=e.where(s,"is not",null);else if(d)switch(l){case">":e=e.where(s,"<=",o);break;case">=":e=e.where(s,"<",o);break;case"<":e=e.where(s,">=",o);break;case"<=":e=e.where(s,">",o);break;default:e=e.where(s,"!=",o)}else e=e.where(s,l,o);else{const{ref:u}=t.dynamic;e=e.where(Z=>Z.or(r.map(R=>Z(u(R),"like",`%${o}%`))))}}),e}function Ee(t){return typeof t=="string"?parseInt(t,10):typeof t=="bigint"?Number(t):t}function Rs(t){return async(e,n)=>{let r=t.selectFrom("users").where("users.tenant_id","=",e);if(n.q&&(r=Be(t,r,n.q,["email","name"])),n.sort&&n.sort.sort_by){const{ref:u}=t.dynamic;r=r.orderBy(u(n.sort.sort_by),n.sort.sort_order)}const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),o=s.map(u=>u.user_id),d=o.length?await t.selectFrom("users").selectAll().where("users.tenant_id","=",e).where("users.linked_to","in",o).execute():[],c=s.map(u=>{const Z=d.filter(R=>R.linked_to===u.user_id);return M({...u,email_verified:u.email_verified===1,is_social:u.is_social===1,app_metadata:JSON.parse(u.app_metadata),user_metadata:JSON.parse(u.user_metadata),identities:[{connection:u.connection,provider:u.provider,user_id:Vn(u.user_id).id,isSocial:!!u.is_social},...Z.map(_r)]})}),{count:l}=await r.select(u=>u.fn.countAll().as("count")).executeTakeFirstOrThrow();return{users:c,start:n.page*n.per_page,limit:n.per_page,length:Ee(l)}}}function Ms(t){return async(e,n)=>(await t.deleteFrom("users").where("users.tenant_id","=",e).where("users.linked_to","=",n).execute(),(await t.deleteFrom("users").where("users.tenant_id","=",e).where("users.user_id","=",n).execute()).length===1)}function Ls(t){if(t.email_verified!==void 0)return t.email_verified?1:0}function zs(t){return async(e,n,r)=>{const a={...r,email_verified:Ls(r),updated_at:new Date().toISOString()};return r.app_metadata&&(a.app_metadata=JSON.stringify(r.app_metadata)),r.user_metadata&&(a.user_metadata=JSON.stringify(r.user_metadata)),(await t.updateTable("users").set(a).where("users.tenant_id","=",e).where("users.user_id","=",n).execute()).length===1}}function Us(t){return async(e,n,r,a)=>{const s={linked_to:null};return(await t.updateTable("users").set(s).where("users.tenant_id","=",e).where("users.user_id","=",`${r}|${a}`).where("users.linked_to","=",`${n}`).execute()).length===1}}function Fs(t){return{create:Yr(t),remove:Ms(t),get:Ds(t),list:Rs(t),update:zs(t),unlink:Us(t)}}const Vs="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ke=(t=21)=>{let e="",n=crypto.getRandomValues(new Uint8Array(t));for(;t--;)e+=Vs[n[t]&63];return e};function Bs(t){return async e=>{const n={id:e.id||Ke(),created_at:new Date().toISOString(),updated_at:new Date().toISOString(),...e};return await t.insertInto("tenants").values(n).execute(),n}}function Ks(t){return async e=>{const n=await t.selectFrom("tenants").where("tenants.id","=",e).selectAll().executeTakeFirst();return n?M(n):null}}function Ws(t){return async e=>{let n=t.selectFrom("tenants");if(e.sort&&e.sort.sort_by){const{ref:d}=t.dynamic;n=n.orderBy(d(e.sort.sort_by),e.sort.sort_order)}e.q&&(n=n.where(d=>d.or([d("name","like",`%${e.q}%`)])));const a=await n.offset(e.page*e.per_page).limit(e.per_page).selectAll().execute();if(!e.include_totals)return{tenants:a};const{count:s}=await n.select(d=>d.fn.countAll().as("count")).executeTakeFirstOrThrow(),o=Ee(s);return{tenants:a.map(M),start:(e.page-1)*e.per_page,limit:e.per_page,length:o}}}function Js(t){return async(e,n)=>{const r={...n,id:e,updated_at:new Date().toISOString()};await t.updateTable("tenants").set(r).where("id","=",e).execute()}}function qs(t){return async e=>(await t.deleteFrom("tenants").where("tenants.id","=",e).execute()).length===1}function Qs(t){return{create:Bs(t),get:Ks(t),list:Ws(t),update:Js(t),remove:qs(t)}}function qn(t){return t?JSON.stringify(t):void 0}const Gs=1024;function Hs(t){return async(e,n)=>{var a,s,o;const r={id:Ke(),...n,user_agent:n.user_agent.slice(0,Gs)};return await t.insertInto("logs").values({...r,description:(a=r.description)==null?void 0:a.substring(0,256),isMobile:n.isMobile?1:0,tenant_id:e,scope:(s=n.scope)==null?void 0:s.join(","),auth0_client:qn(n.auth0_client),details:(o=qn(n.details))==null?void 0:o.substring(0,8192)}).execute(),r}}function Qn(t){if(!t)return"";try{return JSON.parse(t)}catch{return t}}function gr(t){return{...t,client_id:t.client_id,client_name:"",auth0_client:Qn(t.auth0_client),details:Qn(t.details),isMobile:!!t.isMobile,scope:t.scope?t.scope.split(","):void 0,log_id:t.id,_id:t.id}}function Ys(t){return async(e,n)=>{let r=t.selectFrom("logs").where("logs.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","ip"]));let a=r;if(n.sort&&n.sort.sort_by){const{ref:d}=t.dynamic;a=a.orderBy(d(n.sort.sort_by),n.sort.sort_order)}a=a.offset(n.page*n.per_page).limit(n.per_page);const s=await a.selectAll().execute(),{count:o}=await r.select(d=>d.fn.countAll().as("count")).executeTakeFirstOrThrow();return{logs:s.map(gr),start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function Xs(t){return async(e,n)=>{const r=await t.selectFrom("logs").where("logs.tenant_id","=",e).where("logs.id","=",n).selectAll().executeTakeFirst();return r?gr(r):null}}function ei(t){return{create:Hs(t),list:Ys(t),get:Xs(t)}}function ti(t){return async(e,n)=>await t.selectFrom("sessions").where("sessions.tenant_id","=",e).where("sessions.session_id","=",n).where("sessions.deleted_at","is",null).selectAll().executeTakeFirst()??null}function ni(t){return async(e,n)=>{const r={...n,created_at:new Date().toISOString(),expires_at:new Date().toISOString()};return await t.insertInto("sessions").values({...r,tenant_id:e}).execute(),{...n,...r}}}function ri(t){return async(e,n)=>!!(await t.updateTable("sessions").set({deleted_at:new Date().toISOString()}).where("tenant_id","=",e).where("sessions.session_id","=",n).where("sessions.deleted_at","is",null).execute()).length}function ai(t){return async(e,n,r)=>!!(await t.updateTable("sessions").set(r).where("tenant_id","=",e).where("sessions.session_id","=",n).where("sessions.deleted_at","is",null).execute()).length}function si(t){return async(e,n)=>{let r=t.selectFrom("sessions").where("sessions.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","session_id"]));let a=r;if(n.sort&&n.sort.sort_by){const{ref:c}=t.dynamic;a=a.orderBy(c(n.sort.sort_by),n.sort.sort_order)}a=a.offset(n.page*n.per_page).limit(n.per_page);const s=await a.selectAll().execute(),{count:o}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow(),d=Ee(o);return{sessions:s,start:n.page*n.per_page,limit:n.per_page,length:d}}}function ii(t){return{create:ni(t),get:ti(t),list:si(t),remove:ri(t),update:ai(t)}}function oi(t){return async(e,n)=>{const r=await t.selectFrom("tickets").where("tickets.tenant_id","=",e).where("tickets.id","=",n).where("tickets.used_at","is",null).selectAll().executeTakeFirst();if(!r)return null;const{nonce:a,state:s,scope:o,response_type:d,response_mode:c,redirect_uri:l,...u}=r;return{...u,authParams:{nonce:a,state:s,scope:o,response_type:d,response_mode:c,redirect_uri:l},created_at:new Date(r.created_at),expires_at:new Date(r.expires_at),used_at:r.used_at?new Date(r.used_at):void 0}}}function di(t){return async e=>{const{authParams:n,...r}=e,a={...r,...n,created_at:e.created_at.toISOString(),expires_at:e.expires_at.toISOString(),used_at:e.used_at?e.used_at.toISOString():void 0};await t.insertInto("tickets").values(a).execute()}}function ci(t){return async(e,n)=>{await t.updateTable("tickets").set({used_at:new Date().toISOString()}).where("tickets.tenant_id","=",e).where("tickets.id","=",n).execute()}}function li(t){return{create:di(t),get:oi(t),remove:ci(t)}}function ui(t){return async(e,n)=>{const r=await t.selectFrom("passwords").where("passwords.tenant_id","=",e).where("passwords.user_id","=",n).selectAll().executeTakeFirstOrThrow(),{tenant_id:a,...s}=r;return s}}function hi(t){return async(e,n)=>{const r={...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("passwords").values({...r,tenant_id:e}).execute(),r}}function pi(t){return async(e,n)=>(await t.updateTable("passwords").set({password:n.password,updated_at:new Date().toISOString()}).where("tenant_id","=",e).where("user_id","=",n.user_id).execute()).length===1}function mi(t){return{create:hi(t),update:pi(t),get:ui(t)}}function fi(t){return async(e,n)=>{let r=t.selectFrom("codes").where("codes.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["code","login_id"]));const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),{count:o}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{codes:s.map(c=>{const{tenant_id:l,...u}=c;return vs.parse(M(u))}),start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function _i(t){return async(e,n)=>{const r={...n,created_at:new Date().toISOString()};return await t.insertInto("codes").values({...r,tenant_id:e}).execute(),r}}function gi(t){return async(e,n)=>(await t.deleteFrom("codes").where("codes.tenant_id","=",e).where("codes.code_id","=",n).executeTakeFirst()).numDeletedRows>0}function yi(t){return async(e,n,r)=>{let a=t.selectFrom("codes").where("codes.code_id","=",n).where("codes.code_type","=",r).where("codes.expires_at",">",new Date().toISOString());e.length&&(a=a.where("codes.tenant_id","=",e));const s=await a.selectAll().executeTakeFirst();return s?M(s):null}}function vi(t){return{create:_i(t),list:fi(t),remove:gi(t),get:yi(t)}}function bi(t){return async(e,n)=>{const r={created_at:new Date().toISOString(),updated_at:new Date().toISOString(),...n},a=JSON.stringify(n.allowed_origins),s=JSON.stringify(n.callbacks),o=JSON.stringify(n.web_origins),d=JSON.stringify(n.allowed_logout_urls),c=JSON.stringify(n.allowed_clients);return await t.insertInto("applications").values({...r,tenant_id:e,disable_sign_ups:n.disable_sign_ups?1:0,addons:n.addons?JSON.stringify(n.addons):"{}",callbacks:s,allowed_origins:a,web_origins:o,allowed_logout_urls:d,allowed_clients:c}).execute(),r}}function wi(t){return async e=>({applications:(await t.selectFrom("applications").where("applications.tenant_id","=",e).selectAll().execute()).map(s=>({...s,disable_sign_ups:!!s.disable_sign_ups,addons:s.addons?JSON.parse(s.addons):{},callbacks:s.callbacks?JSON.parse(s.callbacks):[],allowed_origins:s.allowed_origins?JSON.parse(s.allowed_origins):[],web_origins:s.web_origins?JSON.parse(s.web_origins):[],allowed_logout_urls:s.allowed_logout_urls?JSON.parse(s.allowed_logout_urls):[],allowed_clients:s.allowed_logout_urls?JSON.parse(s.allowed_logout_urls):[]}))})}function xi(t){return async(e,n)=>{const r=await t.selectFrom("applications").where("applications.tenant_id","=",e).where("applications.id","=",n).selectAll().executeTakeFirst();return r?M({...r,disable_sign_ups:!!r.disable_sign_ups,addons:JSON.parse(r.addons),callbacks:JSON.parse(r.callbacks),allowed_origins:JSON.parse(r.allowed_origins),web_origins:JSON.parse(r.web_origins),allowed_logout_urls:JSON.parse(r.allowed_logout_urls)}):null}}function Ni(t){return async(e,n)=>(await t.deleteFrom("applications").where("applications.tenant_id","=",e).where("applications.id","=",n).executeTakeFirst()).numDeletedRows>0}function ki(t){return async(e,n,r)=>{const a={...r,updated_at:new Date().toISOString(),allowed_origins:r.allowed_origins?JSON.stringify(r.allowed_origins):void 0,callbacks:r.callbacks?JSON.stringify(r.callbacks):void 0,web_origins:r.web_origins?JSON.stringify(r.web_origins):void 0,allowed_logout_urls:r.allowed_logout_urls?JSON.stringify(r.allowed_logout_urls):void 0,allowed_clients:r.allowed_clients?JSON.stringify(r.allowed_clients):void 0,addons:r.addons?JSON.stringify(r.addons):"{}",disable_sign_ups:r.disable_sign_ups?1:0};return await t.updateTable("applications").set(a).where("applications.id","=",n).where("applications.tenant_id","=",e).execute(),!0}}function Ti(t){return{create:bi(t),list:wi(t),get:xi(t),remove:Ni(t),update:ki(t)}}function Ci(t){return async(e,n)=>{const r={id:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("connections").values({...r,options:JSON.stringify(r.options||{}),tenant_id:e}).execute(),r}}function Oi(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,r=Object.getOwnPropertySymbols(t);a<r.length;a++)e.indexOf(r[a])<0&&Object.prototype.propertyIsEnumerable.call(t,r[a])&&(n[r[a]]=t[r[a]]);return n}function Si(t,e){var n;return((n=t==null?void 0:t._def)===null||n===void 0?void 0:n.typeName)===e}function mt(t,e){const n=t.ZodType.prototype[e];t.ZodType.prototype[e]=function(...r){const a=n.apply(this,r);return a._def.openapi=this._def.openapi,a}}function ji(t){if(typeof t.ZodType.prototype.openapi<"u")return;t.ZodType.prototype.openapi=function(a,s){var o,d,c,l,u,Z;const R=typeof a=="string"?s:a,J=R??{},{param:_e}=J,We=Oi(J,["param"]),ge=Object.assign(Object.assign({},(o=this._def.openapi)===null||o===void 0?void 0:o._internal),typeof a=="string"?{refId:a}:void 0),ye=Object.assign(Object.assign(Object.assign({},(d=this._def.openapi)===null||d===void 0?void 0:d.metadata),We),!((l=(c=this._def.openapi)===null||c===void 0?void 0:c.metadata)===null||l===void 0)&&l.param||_e?{param:Object.assign(Object.assign({},(Z=(u=this._def.openapi)===null||u===void 0?void 0:u.metadata)===null||Z===void 0?void 0:Z.param),_e)}:void 0),ve=new this.constructor(Object.assign(Object.assign({},this._def),{openapi:Object.assign(Object.assign({},Object.keys(ge).length>0?{_internal:ge}:void 0),Object.keys(ye).length>0?{metadata:ye}:void 0)}));if(Si(this,"ZodObject")){const Je=this.extend;ve.extend=function(...qe){var ee,te,ne,be,$e,Pe;const Ae=Je.apply(this,qe);return Ae._def.openapi={_internal:{extendedFrom:!((te=(ee=this._def.openapi)===null||ee===void 0?void 0:ee._internal)===null||te===void 0)&&te.refId?{refId:(be=(ne=this._def.openapi)===null||ne===void 0?void 0:ne._internal)===null||be===void 0?void 0:be.refId,schema:this}:($e=this._def.openapi)===null||$e===void 0?void 0:$e._internal.extendedFrom},metadata:(Pe=Ae._def.openapi)===null||Pe===void 0?void 0:Pe.metadata},Ae}}return ve},mt(t,"optional"),mt(t,"nullable"),mt(t,"default"),mt(t,"transform"),mt(t,"refine");const e=t.ZodObject.prototype.deepPartial;t.ZodObject.prototype.deepPartial=function(){const a=this._def.shape(),s=e.apply(this),o=s._def.shape();return Object.entries(o).forEach(([d,c])=>{var l,u;c._def.openapi=(u=(l=a[d])===null||l===void 0?void 0:l._def)===null||u===void 0?void 0:u.openapi}),s._def.openapi=void 0,s};const n=t.ZodObject.prototype.pick;t.ZodObject.prototype.pick=function(...a){const s=n.apply(this,a);return s._def.openapi=void 0,s};const r=t.ZodObject.prototype.omit;t.ZodObject.prototype.omit=function(...a){const s=r.apply(this,a);return s._def.openapi=void 0,s}}new Set(".\\+*[^]$()");var $;(function(t){t.assertEqual=a=>a;function e(a){}t.assertIs=e;function n(a){throw new Error}t.assertNever=n,t.arrayToEnum=a=>{const s={};for(const o of a)s[o]=o;return s},t.getValidEnumValues=a=>{const s=t.objectKeys(a).filter(d=>typeof a[a[d]]!="number"),o={};for(const d of s)o[d]=a[d];return t.objectValues(o)},t.objectValues=a=>t.objectKeys(a).map(function(s){return a[s]}),t.objectKeys=typeof Object.keys=="function"?a=>Object.keys(a):a=>{const s=[];for(const o in a)Object.prototype.hasOwnProperty.call(a,o)&&s.push(o);return s},t.find=(a,s)=>{for(const o of a)if(s(o))return o},t.isInteger=typeof Number.isInteger=="function"?a=>Number.isInteger(a):a=>typeof a=="number"&&isFinite(a)&&Math.floor(a)===a;function r(a,s=" | "){return a.map(o=>typeof o=="string"?`'${o}'`:o).join(s)}t.joinValues=r,t.jsonStringifyReplacer=(a,s)=>typeof s=="bigint"?s.toString():s})($||($={}));var Zn;(function(t){t.mergeShapes=(e,n)=>({...e,...n})})(Zn||(Zn={}));const y=$.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),Ne=t=>{switch(typeof t){case"undefined":return y.undefined;case"string":return y.string;case"number":return isNaN(t)?y.nan:y.number;case"boolean":return y.boolean;case"function":return y.function;case"bigint":return y.bigint;case"symbol":return y.symbol;case"object":return Array.isArray(t)?y.array:t===null?y.null:t.then&&typeof t.then=="function"&&t.catch&&typeof t.catch=="function"?y.promise:typeof Map<"u"&&t instanceof Map?y.map:typeof Set<"u"&&t instanceof Set?y.set:typeof Date<"u"&&t instanceof Date?y.date:y.object;default:return y.unknown}},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"]),Ii=t=>JSON.stringify(t,null,2).replace(/"([^"]+)":/g,"$1:");class W extends Error{constructor(e){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=e}get errors(){return this.issues}format(e){const n=e||function(s){return s.message},r={_errors:[]},a=s=>{for(const o of s.issues)if(o.code==="invalid_union")o.unionErrors.map(a);else if(o.code==="invalid_return_type")a(o.returnTypeError);else if(o.code==="invalid_arguments")a(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let d=r,c=0;for(;c<o.path.length;){const l=o.path[c];c===o.path.length-1?(d[l]=d[l]||{_errors:[]},d[l]._errors.push(n(o))):d[l]=d[l]||{_errors:[]},d=d[l],c++}}};return a(this),r}static assert(e){if(!(e instanceof W))throw new Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,$.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=n=>n.message){const n={},r=[];for(const a of this.issues)a.path.length>0?(n[a.path[0]]=n[a.path[0]]||[],n[a.path[0]].push(e(a))):r.push(e(a));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}W.create=t=>new W(t);const dt=(t,e)=>{let n;switch(t.code){case p.invalid_type:t.received===y.undefined?n="Required":n=`Expected ${t.expected}, received ${t.received}`;break;case p.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(t.expected,$.jsonStringifyReplacer)}`;break;case p.unrecognized_keys:n=`Unrecognized key(s) in object: ${$.joinValues(t.keys,", ")}`;break;case p.invalid_union:n="Invalid input";break;case p.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${$.joinValues(t.options)}`;break;case p.invalid_enum_value:n=`Invalid enum value. Expected ${$.joinValues(t.options)}, received '${t.received}'`;break;case p.invalid_arguments:n="Invalid function arguments";break;case p.invalid_return_type:n="Invalid function return type";break;case p.invalid_date:n="Invalid date";break;case p.invalid_string:typeof t.validation=="object"?"includes"in t.validation?(n=`Invalid input: must include "${t.validation.includes}"`,typeof t.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${t.validation.position}`)):"startsWith"in t.validation?n=`Invalid input: must start with "${t.validation.startsWith}"`:"endsWith"in t.validation?n=`Invalid input: must end with "${t.validation.endsWith}"`:$.assertNever(t.validation):t.validation!=="regex"?n=`Invalid ${t.validation}`:n="Invalid";break;case p.too_small:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at least":"more than"} ${t.minimum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at least":"over"} ${t.minimum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${t.minimum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly equal to ":t.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(t.minimum))}`:n="Invalid input";break;case p.too_big:t.type==="array"?n=`Array must contain ${t.exact?"exactly":t.inclusive?"at most":"less than"} ${t.maximum} element(s)`:t.type==="string"?n=`String must contain ${t.exact?"exactly":t.inclusive?"at most":"under"} ${t.maximum} character(s)`:t.type==="number"?n=`Number must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="bigint"?n=`BigInt must be ${t.exact?"exactly":t.inclusive?"less than or equal to":"less than"} ${t.maximum}`:t.type==="date"?n=`Date must be ${t.exact?"exactly":t.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(t.maximum))}`:n="Invalid input";break;case p.custom:n="Invalid input";break;case p.invalid_intersection_types:n="Intersection results could not be merged";break;case p.not_multiple_of:n=`Number must be a multiple of ${t.multipleOf}`;break;case p.not_finite:n="Number must be finite";break;default:n=e.defaultError,$.assertNever(t)}return{message:n}};let yr=dt;function Zi(t){yr=t}function ln(){return yr}const un=t=>{const{data:e,path:n,errorMaps:r,issueData:a}=t,s=[...n,...a.path||[]],o={...a,path:s};if(a.message!==void 0)return{...a,path:s,message:a.message};let d="";const c=r.filter(l=>!!l).slice().reverse();for(const l of c)d=l(o,{data:e,defaultError:d}).message;return{...a,path:s,message:d}},Ei=[];function _(t,e){const n=ln(),r=un({issueData:e,data:t.data,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,n,n===dt?void 0:dt].filter(a=>!!a)});t.common.issues.push(r)}class F{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(e,n){const r=[];for(const a of n){if(a.status==="aborted")return k;a.status==="dirty"&&e.dirty(),r.push(a.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,n){const r=[];for(const a of n){const s=await a.key,o=await a.value;r.push({key:s,value:o})}return F.mergeObjectSync(e,r)}static mergeObjectSync(e,n){const r={};for(const a of n){const{key:s,value:o}=a;if(s.status==="aborted"||o.status==="aborted")return k;s.status==="dirty"&&e.dirty(),o.status==="dirty"&&e.dirty(),s.value!=="__proto__"&&(typeof o.value<"u"||a.alwaysSet)&&(r[s.value]=o.value)}return{status:e.value,value:r}}}const k=Object.freeze({status:"aborted"}),tt=t=>({status:"dirty",value:t}),B=t=>({status:"valid",value:t}),En=t=>t.status==="aborted",$n=t=>t.status==="dirty",At=t=>t.status==="valid",Dt=t=>typeof Promise<"u"&&t instanceof Promise;function hn(t,e,n,r){if(typeof e=="function"?t!==e||!r:!e.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return e.get(t)}function vr(t,e,n,r,a){if(typeof e=="function"?t!==e||!a:!e.has(t))throw new TypeError("Cannot write private member to an object whose class did not declare it");return e.set(t,n),n}var w;(function(t){t.errToObj=e=>typeof e=="string"?{message:e}:e||{},t.toString=e=>typeof e=="string"?e:e==null?void 0:e.message})(w||(w={}));var gt,yt;class de{constructor(e,n,r,a){this._cachedPath=[],this.parent=e,this.data=n,this._path=r,this._key=a}get path(){return this._cachedPath.length||(this._key instanceof Array?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const Gn=(t,e)=>{if(At(e))return{success:!0,data:e.value};if(!t.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new W(t.common.issues);return this._error=n,this._error}}};function S(t){if(!t)return{};const{errorMap:e,invalid_type_error:n,required_error:r,description:a}=t;if(e&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return e?{errorMap:e,description:a}:{errorMap:(o,d)=>{var c,l;const{message:u}=t;return o.code==="invalid_enum_value"?{message:u??d.defaultError}:typeof d.data>"u"?{message:(c=u??r)!==null&&c!==void 0?c:d.defaultError}:o.code!=="invalid_type"?{message:d.defaultError}:{message:(l=u??n)!==null&&l!==void 0?l:d.defaultError}},description:a}}class I{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)}get description(){return this._def.description}_getType(e){return Ne(e.data)}_getOrReturnCtx(e,n){return n||{common:e.parent.common,data:e.data,parsedType:Ne(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new F,ctx:{common:e.parent.common,data:e.data,parsedType:Ne(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){const n=this._parse(e);if(Dt(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(e){const n=this._parse(e);return Promise.resolve(n)}parse(e,n){const r=this.safeParse(e,n);if(r.success)return r.data;throw r.error}safeParse(e,n){var r;const a={common:{issues:[],async:(r=n==null?void 0:n.async)!==null&&r!==void 0?r:!1,contextualErrorMap:n==null?void 0:n.errorMap},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ne(e)},s=this._parseSync({data:e,path:a.path,parent:a});return Gn(a,s)}async parseAsync(e,n){const r=await this.safeParseAsync(e,n);if(r.success)return r.data;throw r.error}async safeParseAsync(e,n){const r={common:{issues:[],contextualErrorMap:n==null?void 0:n.errorMap,async:!0},path:(n==null?void 0:n.path)||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:Ne(e)},a=this._parse({data:e,path:r.path,parent:r}),s=await(Dt(a)?a:Promise.resolve(a));return Gn(r,s)}refine(e,n){const r=a=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(a):n;return this._refinement((a,s)=>{const o=e(a),d=()=>s.addIssue({code:p.custom,...r(a)});return typeof Promise<"u"&&o instanceof Promise?o.then(c=>c?!0:(d(),!1)):o?!0:(d(),!1)})}refinement(e,n){return this._refinement((r,a)=>e(r)?!0:(a.addIssue(typeof n=="function"?n(r,a):n),!1))}_refinement(e){return new X({schema:this,typeName:N.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}optional(){return se.create(this,this._def)}nullable(){return Ze.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return H.create(this,this._def)}promise(){return lt.create(this,this._def)}or(e){return zt.create([this,e],this._def)}and(e){return Ut.create(this,e,this._def)}transform(e){return new X({...S(this._def),schema:this,typeName:N.ZodEffects,effect:{type:"transform",transform:e}})}default(e){const n=typeof e=="function"?e:()=>e;return new Wt({...S(this._def),innerType:this,defaultValue:n,typeName:N.ZodDefault})}brand(){return new Bn({typeName:N.ZodBranded,type:this,...S(this._def)})}catch(e){const n=typeof e=="function"?e:()=>e;return new Jt({...S(this._def),innerType:this,catchValue:n,typeName:N.ZodCatch})}describe(e){const n=this.constructor;return new n({...this._def,description:e})}pipe(e){return Yt.create(this,e)}readonly(){return qt.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const $i=/^c[^\s-]{8,}$/i,Pi=/^[0-9a-z]+$/,Ai=/^[0-9A-HJKMNP-TV-Z]{26}$/,Di=/^[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,Ri=/^[a-z0-9_-]{21}$/i,Mi=/^[-+]?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)?)??$/,Li=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,zi="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let xn;const Ui=/^(?:(?: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])$/,Fi=/^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,Vi=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,br="((\\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])))",Bi=new RegExp(`^${br}$`);function wr(t){let e="([01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d";return t.precision?e=`${e}\\.\\d{${t.precision}}`:t.precision==null&&(e=`${e}(\\.\\d+)?`),e}function Ki(t){return new RegExp(`^${wr(t)}$`)}function xr(t){let e=`${br}T${wr(t)}`;const n=[];return n.push(t.local?"Z?":"Z"),t.offset&&n.push("([+-]\\d{2}:?\\d{2})"),e=`${e}(${n.join("|")})`,new RegExp(`^${e}$`)}function Wi(t,e){return!!((e==="v4"||!e)&&Ui.test(t)||(e==="v6"||!e)&&Fi.test(t))}class Q extends I{_parse(e){if(this._def.coerce&&(e.data=String(e.data)),this._getType(e)!==y.string){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.string,received:s.parsedType}),k}const r=new F;let a;for(const s of this._def.checks)if(s.kind==="min")e.data.length<s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="max")e.data.length>s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!1,message:s.message}),r.dirty());else if(s.kind==="length"){const o=e.data.length>s.value,d=e.data.length<s.value;(o||d)&&(a=this._getOrReturnCtx(e,a),o?_(a,{code:p.too_big,maximum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}):d&&_(a,{code:p.too_small,minimum:s.value,type:"string",inclusive:!0,exact:!0,message:s.message}),r.dirty())}else if(s.kind==="email")Li.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"email",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="emoji")xn||(xn=new RegExp(zi,"u")),xn.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"emoji",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="uuid")Di.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"uuid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="nanoid")Ri.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"nanoid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid")$i.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"cuid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="cuid2")Pi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"cuid2",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="ulid")Ai.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"ulid",code:p.invalid_string,message:s.message}),r.dirty());else if(s.kind==="url")try{new URL(e.data)}catch{a=this._getOrReturnCtx(e,a),_(a,{validation:"url",code:p.invalid_string,message:s.message}),r.dirty()}else s.kind==="regex"?(s.regex.lastIndex=0,s.regex.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"regex",code:p.invalid_string,message:s.message}),r.dirty())):s.kind==="trim"?e.data=e.data.trim():s.kind==="includes"?e.data.includes(s.value,s.position)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:{includes:s.value,position:s.position},message:s.message}),r.dirty()):s.kind==="toLowerCase"?e.data=e.data.toLowerCase():s.kind==="toUpperCase"?e.data=e.data.toUpperCase():s.kind==="startsWith"?e.data.startsWith(s.value)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:{startsWith:s.value},message:s.message}),r.dirty()):s.kind==="endsWith"?e.data.endsWith(s.value)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:{endsWith:s.value},message:s.message}),r.dirty()):s.kind==="datetime"?xr(s).test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:"datetime",message:s.message}),r.dirty()):s.kind==="date"?Bi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:"date",message:s.message}),r.dirty()):s.kind==="time"?Ki(s).test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{code:p.invalid_string,validation:"time",message:s.message}),r.dirty()):s.kind==="duration"?Mi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"duration",code:p.invalid_string,message:s.message}),r.dirty()):s.kind==="ip"?Wi(e.data,s.version)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"ip",code:p.invalid_string,message:s.message}),r.dirty()):s.kind==="base64"?Vi.test(e.data)||(a=this._getOrReturnCtx(e,a),_(a,{validation:"base64",code:p.invalid_string,message:s.message}),r.dirty()):$.assertNever(s);return{status:r.value,value:e.data}}_regex(e,n,r){return this.refinement(a=>e.test(a),{validation:n,code:p.invalid_string,...w.errToObj(r)})}_addCheck(e){return new Q({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...w.errToObj(e)})}url(e){return this._addCheck({kind:"url",...w.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...w.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...w.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...w.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...w.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...w.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...w.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...w.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...w.errToObj(e)})}datetime(e){var n,r;return typeof e=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e}):this._addCheck({kind:"datetime",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,offset:(n=e==null?void 0:e.offset)!==null&&n!==void 0?n:!1,local:(r=e==null?void 0:e.local)!==null&&r!==void 0?r:!1,...w.errToObj(e==null?void 0:e.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){return typeof e=="string"?this._addCheck({kind:"time",precision:null,message:e}):this._addCheck({kind:"time",precision:typeof(e==null?void 0:e.precision)>"u"?null:e==null?void 0:e.precision,...w.errToObj(e==null?void 0:e.message)})}duration(e){return this._addCheck({kind:"duration",...w.errToObj(e)})}regex(e,n){return this._addCheck({kind:"regex",regex:e,...w.errToObj(n)})}includes(e,n){return this._addCheck({kind:"includes",value:e,position:n==null?void 0:n.position,...w.errToObj(n==null?void 0:n.message)})}startsWith(e,n){return this._addCheck({kind:"startsWith",value:e,...w.errToObj(n)})}endsWith(e,n){return this._addCheck({kind:"endsWith",value:e,...w.errToObj(n)})}min(e,n){return this._addCheck({kind:"min",value:e,...w.errToObj(n)})}max(e,n){return this._addCheck({kind:"max",value:e,...w.errToObj(n)})}length(e,n){return this._addCheck({kind:"length",value:e,...w.errToObj(n)})}nonempty(e){return this.min(1,w.errToObj(e))}trim(){return new Q({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Q({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Q({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(e=>e.kind==="datetime")}get isDate(){return!!this._def.checks.find(e=>e.kind==="date")}get isTime(){return!!this._def.checks.find(e=>e.kind==="time")}get isDuration(){return!!this._def.checks.find(e=>e.kind==="duration")}get isEmail(){return!!this._def.checks.find(e=>e.kind==="email")}get isURL(){return!!this._def.checks.find(e=>e.kind==="url")}get isEmoji(){return!!this._def.checks.find(e=>e.kind==="emoji")}get isUUID(){return!!this._def.checks.find(e=>e.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(e=>e.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(e=>e.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(e=>e.kind==="cuid2")}get isULID(){return!!this._def.checks.find(e=>e.kind==="ulid")}get isIP(){return!!this._def.checks.find(e=>e.kind==="ip")}get isBase64(){return!!this._def.checks.find(e=>e.kind==="base64")}get minLength(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxLength(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}Q.create=t=>{var e;return new Q({checks:[],typeName:N.ZodString,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...S(t)})};function Ji(t,e){const n=(t.toString().split(".")[1]||"").length,r=(e.toString().split(".")[1]||"").length,a=n>r?n:r,s=parseInt(t.toFixed(a).replace(".","")),o=parseInt(e.toFixed(a).replace(".",""));return s%o/Math.pow(10,a)}class Se extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(e){if(this._def.coerce&&(e.data=Number(e.data)),this._getType(e)!==y.number){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.number,received:s.parsedType}),k}let r;const a=new F;for(const s of this._def.checks)s.kind==="int"?$.isInteger(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{code:p.invalid_type,expected:"integer",received:"float",message:s.message}),a.dirty()):s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_small,minimum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_big,maximum:s.value,type:"number",inclusive:s.inclusive,exact:!1,message:s.message}),a.dirty()):s.kind==="multipleOf"?Ji(e.data,s.value)!==0&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):s.kind==="finite"?Number.isFinite(e.data)||(r=this._getOrReturnCtx(e,r),_(r,{code:p.not_finite,message:s.message}),a.dirty()):$.assertNever(s);return{status:a.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,w.toString(n))}gt(e,n){return this.setLimit("min",e,!1,w.toString(n))}lte(e,n){return this.setLimit("max",e,!0,w.toString(n))}lt(e,n){return this.setLimit("max",e,!1,w.toString(n))}setLimit(e,n,r,a){return new Se({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:w.toString(a)}]})}_addCheck(e){return new Se({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:w.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:w.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(n)})}finite(e){return this._addCheck({kind:"finite",message:w.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:w.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:w.toString(e)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}get isInt(){return!!this._def.checks.find(e=>e.kind==="int"||e.kind==="multipleOf"&&$.isInteger(e.value))}get isFinite(){let e=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(e===null||r.value<e)&&(e=r.value)}return Number.isFinite(n)&&Number.isFinite(e)}}Se.create=t=>new Se({checks:[],typeName:N.ZodNumber,coerce:(t==null?void 0:t.coerce)||!1,...S(t)});class je extends I{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce&&(e.data=BigInt(e.data)),this._getType(e)!==y.bigint){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.bigint,received:s.parsedType}),k}let r;const a=new F;for(const s of this._def.checks)s.kind==="min"?(s.inclusive?e.data<s.value:e.data<=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_small,type:"bigint",minimum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):s.kind==="max"?(s.inclusive?e.data>s.value:e.data>=s.value)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.too_big,type:"bigint",maximum:s.value,inclusive:s.inclusive,message:s.message}),a.dirty()):s.kind==="multipleOf"?e.data%s.value!==BigInt(0)&&(r=this._getOrReturnCtx(e,r),_(r,{code:p.not_multiple_of,multipleOf:s.value,message:s.message}),a.dirty()):$.assertNever(s);return{status:a.value,value:e.data}}gte(e,n){return this.setLimit("min",e,!0,w.toString(n))}gt(e,n){return this.setLimit("min",e,!1,w.toString(n))}lte(e,n){return this.setLimit("max",e,!0,w.toString(n))}lt(e,n){return this.setLimit("max",e,!1,w.toString(n))}setLimit(e,n,r,a){return new je({...this._def,checks:[...this._def.checks,{kind:e,value:n,inclusive:r,message:w.toString(a)}]})}_addCheck(e){return new je({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:w.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:w.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:w.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:w.toString(e)})}multipleOf(e,n){return this._addCheck({kind:"multipleOf",value:e,message:w.toString(n)})}get minValue(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e}get maxValue(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e}}je.create=t=>{var e;return new je({checks:[],typeName:N.ZodBigInt,coerce:(e=t==null?void 0:t.coerce)!==null&&e!==void 0?e:!1,...S(t)})};class Rt extends I{_parse(e){if(this._def.coerce&&(e.data=!!e.data),this._getType(e)!==y.boolean){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.boolean,received:r.parsedType}),k}return B(e.data)}}Rt.create=t=>new Rt({typeName:N.ZodBoolean,coerce:(t==null?void 0:t.coerce)||!1,...S(t)});class Fe extends I{_parse(e){if(this._def.coerce&&(e.data=new Date(e.data)),this._getType(e)!==y.date){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_type,expected:y.date,received:s.parsedType}),k}if(isNaN(e.data.getTime())){const s=this._getOrReturnCtx(e);return _(s,{code:p.invalid_date}),k}const r=new F;let a;for(const s of this._def.checks)s.kind==="min"?e.data.getTime()<s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_small,message:s.message,inclusive:!0,exact:!1,minimum:s.value,type:"date"}),r.dirty()):s.kind==="max"?e.data.getTime()>s.value&&(a=this._getOrReturnCtx(e,a),_(a,{code:p.too_big,message:s.message,inclusive:!0,exact:!1,maximum:s.value,type:"date"}),r.dirty()):$.assertNever(s);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new Fe({...this._def,checks:[...this._def.checks,e]})}min(e,n){return this._addCheck({kind:"min",value:e.getTime(),message:w.toString(n)})}max(e,n){return this._addCheck({kind:"max",value:e.getTime(),message:w.toString(n)})}get minDate(){let e=null;for(const n of this._def.checks)n.kind==="min"&&(e===null||n.value>e)&&(e=n.value);return e!=null?new Date(e):null}get maxDate(){let e=null;for(const n of this._def.checks)n.kind==="max"&&(e===null||n.value<e)&&(e=n.value);return e!=null?new Date(e):null}}Fe.create=t=>new Fe({checks:[],coerce:(t==null?void 0:t.coerce)||!1,typeName:N.ZodDate,...S(t)});class pn extends I{_parse(e){if(this._getType(e)!==y.symbol){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.symbol,received:r.parsedType}),k}return B(e.data)}}pn.create=t=>new pn({typeName:N.ZodSymbol,...S(t)});class Mt extends I{_parse(e){if(this._getType(e)!==y.undefined){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.undefined,received:r.parsedType}),k}return B(e.data)}}Mt.create=t=>new Mt({typeName:N.ZodUndefined,...S(t)});class Lt extends I{_parse(e){if(this._getType(e)!==y.null){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.null,received:r.parsedType}),k}return B(e.data)}}Lt.create=t=>new Lt({typeName:N.ZodNull,...S(t)});class ct extends I{constructor(){super(...arguments),this._any=!0}_parse(e){return B(e.data)}}ct.create=t=>new ct({typeName:N.ZodAny,...S(t)});class Le extends I{constructor(){super(...arguments),this._unknown=!0}_parse(e){return B(e.data)}}Le.create=t=>new Le({typeName:N.ZodUnknown,...S(t)});class fe extends I{_parse(e){const n=this._getOrReturnCtx(e);return _(n,{code:p.invalid_type,expected:y.never,received:n.parsedType}),k}}fe.create=t=>new fe({typeName:N.ZodNever,...S(t)});class mn extends I{_parse(e){if(this._getType(e)!==y.undefined){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.void,received:r.parsedType}),k}return B(e.data)}}mn.create=t=>new mn({typeName:N.ZodVoid,...S(t)});class H extends I{_parse(e){const{ctx:n,status:r}=this._processInputParams(e),a=this._def;if(n.parsedType!==y.array)return _(n,{code:p.invalid_type,expected:y.array,received:n.parsedType}),k;if(a.exactLength!==null){const o=n.data.length>a.exactLength.value,d=n.data.length<a.exactLength.value;(o||d)&&(_(n,{code:o?p.too_big:p.too_small,minimum:d?a.exactLength.value:void 0,maximum:o?a.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:a.exactLength.message}),r.dirty())}if(a.minLength!==null&&n.data.length<a.minLength.value&&(_(n,{code:p.too_small,minimum:a.minLength.value,type:"array",inclusive:!0,exact:!1,message:a.minLength.message}),r.dirty()),a.maxLength!==null&&n.data.length>a.maxLength.value&&(_(n,{code:p.too_big,maximum:a.maxLength.value,type:"array",inclusive:!0,exact:!1,message:a.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,d)=>a.type._parseAsync(new de(n,o,n.path,d)))).then(o=>F.mergeArray(r,o));const s=[...n.data].map((o,d)=>a.type._parseSync(new de(n,o,n.path,d)));return F.mergeArray(r,s)}get element(){return this._def.type}min(e,n){return new H({...this._def,minLength:{value:e,message:w.toString(n)}})}max(e,n){return new H({...this._def,maxLength:{value:e,message:w.toString(n)}})}length(e,n){return new H({...this._def,exactLength:{value:e,message:w.toString(n)}})}nonempty(e){return this.min(1,e)}}H.create=(t,e)=>new H({type:t,minLength:null,maxLength:null,exactLength:null,typeName:N.ZodArray,...S(e)});function He(t){if(t instanceof D){const e={};for(const n in t.shape){const r=t.shape[n];e[n]=se.create(He(r))}return new D({...t._def,shape:()=>e})}else return t instanceof H?new H({...t._def,type:He(t.element)}):t instanceof se?se.create(He(t.unwrap())):t instanceof Ze?Ze.create(He(t.unwrap())):t instanceof ce?ce.create(t.items.map(e=>He(e))):t}class D extends I{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const e=this._def.shape(),n=$.objectKeys(e);return this._cached={shape:e,keys:n}}_parse(e){if(this._getType(e)!==y.object){const l=this._getOrReturnCtx(e);return _(l,{code:p.invalid_type,expected:y.object,received:l.parsedType}),k}const{status:r,ctx:a}=this._processInputParams(e),{shape:s,keys:o}=this._getCached(),d=[];if(!(this._def.catchall instanceof fe&&this._def.unknownKeys==="strip"))for(const l in a.data)o.includes(l)||d.push(l);const c=[];for(const l of o){const u=s[l],Z=a.data[l];c.push({key:{status:"valid",value:l},value:u._parse(new de(a,Z,a.path,l)),alwaysSet:l in a.data})}if(this._def.catchall instanceof fe){const l=this._def.unknownKeys;if(l==="passthrough")for(const u of d)c.push({key:{status:"valid",value:u},value:{status:"valid",value:a.data[u]}});else if(l==="strict")d.length>0&&(_(a,{code:p.unrecognized_keys,keys:d}),r.dirty());else if(l!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const l=this._def.catchall;for(const u of d){const Z=a.data[u];c.push({key:{status:"valid",value:u},value:l._parse(new de(a,Z,a.path,u)),alwaysSet:u in a.data})}}return a.common.async?Promise.resolve().then(async()=>{const l=[];for(const u of c){const Z=await u.key,R=await u.value;l.push({key:Z,value:R,alwaysSet:u.alwaysSet})}return l}).then(l=>F.mergeObjectSync(r,l)):F.mergeObjectSync(r,c)}get shape(){return this._def.shape()}strict(e){return w.errToObj,new D({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(n,r)=>{var a,s,o,d;const c=(o=(s=(a=this._def).errorMap)===null||s===void 0?void 0:s.call(a,n,r).message)!==null&&o!==void 0?o:r.defaultError;return n.code==="unrecognized_keys"?{message:(d=w.errToObj(e).message)!==null&&d!==void 0?d:c}:{message:c}}}:{}})}strip(){return new D({...this._def,unknownKeys:"strip"})}passthrough(){return new D({...this._def,unknownKeys:"passthrough"})}extend(e){return new D({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new D({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:N.ZodObject})}setKey(e,n){return this.augment({[e]:n})}catchall(e){return new D({...this._def,catchall:e})}pick(e){const n={};return $.objectKeys(e).forEach(r=>{e[r]&&this.shape[r]&&(n[r]=this.shape[r])}),new D({...this._def,shape:()=>n})}omit(e){const n={};return $.objectKeys(this.shape).forEach(r=>{e[r]||(n[r]=this.shape[r])}),new D({...this._def,shape:()=>n})}deepPartial(){return He(this)}partial(e){const n={};return $.objectKeys(this.shape).forEach(r=>{const a=this.shape[r];e&&!e[r]?n[r]=a:n[r]=a.optional()}),new D({...this._def,shape:()=>n})}required(e){const n={};return $.objectKeys(this.shape).forEach(r=>{if(e&&!e[r])n[r]=this.shape[r];else{let s=this.shape[r];for(;s instanceof se;)s=s._def.innerType;n[r]=s}}),new D({...this._def,shape:()=>n})}keyof(){return Nr($.objectKeys(this.shape))}}D.create=(t,e)=>new D({shape:()=>t,unknownKeys:"strip",catchall:fe.create(),typeName:N.ZodObject,...S(e)});D.strictCreate=(t,e)=>new D({shape:()=>t,unknownKeys:"strict",catchall:fe.create(),typeName:N.ZodObject,...S(e)});D.lazycreate=(t,e)=>new D({shape:t,unknownKeys:"strip",catchall:fe.create(),typeName:N.ZodObject,...S(e)});class zt extends I{_parse(e){const{ctx:n}=this._processInputParams(e),r=this._def.options;function a(s){for(const d of s)if(d.result.status==="valid")return d.result;for(const d of s)if(d.result.status==="dirty")return n.common.issues.push(...d.ctx.common.issues),d.result;const o=s.map(d=>new W(d.ctx.common.issues));return _(n,{code:p.invalid_union,unionErrors:o}),k}if(n.common.async)return Promise.all(r.map(async s=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await s._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(a);{let s;const o=[];for(const c of r){const l={...n,common:{...n.common,issues:[]},parent:null},u=c._parseSync({data:n.data,path:n.path,parent:l});if(u.status==="valid")return u;u.status==="dirty"&&!s&&(s={result:u,ctx:l}),l.common.issues.length&&o.push(l.common.issues)}if(s)return n.common.issues.push(...s.ctx.common.issues),s.result;const d=o.map(c=>new W(c));return _(n,{code:p.invalid_union,unionErrors:d}),k}}get options(){return this._def.options}}zt.create=(t,e)=>new zt({options:t,typeName:N.ZodUnion,...S(e)});const le=t=>t instanceof Vt?le(t.schema):t instanceof X?le(t.innerType()):t instanceof Bt?[t.value]:t instanceof Ie?t.options:t instanceof Kt?$.objectValues(t.enum):t instanceof Wt?le(t._def.innerType):t instanceof Mt?[void 0]:t instanceof Lt?[null]:t instanceof se?[void 0,...le(t.unwrap())]:t instanceof Ze?[null,...le(t.unwrap())]:t instanceof Bn||t instanceof qt?le(t.unwrap()):t instanceof Jt?le(t._def.innerType):[];class vn extends I{_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.object)return _(n,{code:p.invalid_type,expected:y.object,received:n.parsedType}),k;const r=this.discriminator,a=n.data[r],s=this.optionsMap.get(a);return s?n.common.async?s._parseAsync({data:n.data,path:n.path,parent:n}):s._parseSync({data:n.data,path:n.path,parent:n}):(_(n,{code:p.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),k)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,n,r){const a=new Map;for(const s of n){const o=le(s.shape[e]);if(!o.length)throw new Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(const d of o){if(a.has(d))throw new Error(`Discriminator property ${String(e)} has duplicate value ${String(d)}`);a.set(d,s)}}return new vn({typeName:N.ZodDiscriminatedUnion,discriminator:e,options:n,optionsMap:a,...S(r)})}}function Pn(t,e){const n=Ne(t),r=Ne(e);if(t===e)return{valid:!0,data:t};if(n===y.object&&r===y.object){const a=$.objectKeys(e),s=$.objectKeys(t).filter(d=>a.indexOf(d)!==-1),o={...t,...e};for(const d of s){const c=Pn(t[d],e[d]);if(!c.valid)return{valid:!1};o[d]=c.data}return{valid:!0,data:o}}else if(n===y.array&&r===y.array){if(t.length!==e.length)return{valid:!1};const a=[];for(let s=0;s<t.length;s++){const o=t[s],d=e[s],c=Pn(o,d);if(!c.valid)return{valid:!1};a.push(c.data)}return{valid:!0,data:a}}else return n===y.date&&r===y.date&&+t==+e?{valid:!0,data:t}:{valid:!1}}class Ut extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=(s,o)=>{if(En(s)||En(o))return k;const d=Pn(s.value,o.value);return d.valid?(($n(s)||$n(o))&&n.dirty(),{status:n.value,value:d.data}):(_(r,{code:p.invalid_intersection_types}),k)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([s,o])=>a(s,o)):a(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Ut.create=(t,e,n)=>new Ut({left:t,right:e,typeName:N.ZodIntersection,...S(n)});class ce extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.array)return _(r,{code:p.invalid_type,expected:y.array,received:r.parsedType}),k;if(r.data.length<this._def.items.length)return _(r,{code:p.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),k;!this._def.rest&&r.data.length>this._def.items.length&&(_(r,{code:p.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const s=[...r.data].map((o,d)=>{const c=this._def.items[d]||this._def.rest;return c?c._parse(new de(r,o,r.path,d)):null}).filter(o=>!!o);return r.common.async?Promise.all(s).then(o=>F.mergeArray(n,o)):F.mergeArray(n,s)}get items(){return this._def.items}rest(e){return new ce({...this._def,rest:e})}}ce.create=(t,e)=>{if(!Array.isArray(t))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new ce({items:t,typeName:N.ZodTuple,rest:null,...S(e)})};class Ft extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.object)return _(r,{code:p.invalid_type,expected:y.object,received:r.parsedType}),k;const a=[],s=this._def.keyType,o=this._def.valueType;for(const d in r.data)a.push({key:s._parse(new de(r,d,r.path,d)),value:o._parse(new de(r,r.data[d],r.path,d)),alwaysSet:d in r.data});return r.common.async?F.mergeObjectAsync(n,a):F.mergeObjectSync(n,a)}get element(){return this._def.valueType}static create(e,n,r){return n instanceof I?new Ft({keyType:e,valueType:n,typeName:N.ZodRecord,...S(r)}):new Ft({keyType:Q.create(),valueType:e,typeName:N.ZodRecord,...S(n)})}}class fn extends I{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.map)return _(r,{code:p.invalid_type,expected:y.map,received:r.parsedType}),k;const a=this._def.keyType,s=this._def.valueType,o=[...r.data.entries()].map(([d,c],l)=>({key:a._parse(new de(r,d,r.path,[l,"key"])),value:s._parse(new de(r,c,r.path,[l,"value"]))}));if(r.common.async){const d=new Map;return Promise.resolve().then(async()=>{for(const c of o){const l=await c.key,u=await c.value;if(l.status==="aborted"||u.status==="aborted")return k;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}})}else{const d=new Map;for(const c of o){const l=c.key,u=c.value;if(l.status==="aborted"||u.status==="aborted")return k;(l.status==="dirty"||u.status==="dirty")&&n.dirty(),d.set(l.value,u.value)}return{status:n.value,value:d}}}}fn.create=(t,e,n)=>new fn({valueType:e,keyType:t,typeName:N.ZodMap,...S(n)});class Ve extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.parsedType!==y.set)return _(r,{code:p.invalid_type,expected:y.set,received:r.parsedType}),k;const a=this._def;a.minSize!==null&&r.data.size<a.minSize.value&&(_(r,{code:p.too_small,minimum:a.minSize.value,type:"set",inclusive:!0,exact:!1,message:a.minSize.message}),n.dirty()),a.maxSize!==null&&r.data.size>a.maxSize.value&&(_(r,{code:p.too_big,maximum:a.maxSize.value,type:"set",inclusive:!0,exact:!1,message:a.maxSize.message}),n.dirty());const s=this._def.valueType;function o(c){const l=new Set;for(const u of c){if(u.status==="aborted")return k;u.status==="dirty"&&n.dirty(),l.add(u.value)}return{status:n.value,value:l}}const d=[...r.data.values()].map((c,l)=>s._parse(new de(r,c,r.path,l)));return r.common.async?Promise.all(d).then(c=>o(c)):o(d)}min(e,n){return new Ve({...this._def,minSize:{value:e,message:w.toString(n)}})}max(e,n){return new Ve({...this._def,maxSize:{value:e,message:w.toString(n)}})}size(e,n){return this.min(e,n).max(e,n)}nonempty(e){return this.min(1,e)}}Ve.create=(t,e)=>new Ve({valueType:t,minSize:null,maxSize:null,typeName:N.ZodSet,...S(e)});class rt extends I{constructor(){super(...arguments),this.validate=this.implement}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.function)return _(n,{code:p.invalid_type,expected:y.function,received:n.parsedType}),k;function r(d,c){return un({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,ln(),dt].filter(l=>!!l),issueData:{code:p.invalid_arguments,argumentsError:c}})}function a(d,c){return un({data:d,path:n.path,errorMaps:[n.common.contextualErrorMap,n.schemaErrorMap,ln(),dt].filter(l=>!!l),issueData:{code:p.invalid_return_type,returnTypeError:c}})}const s={errorMap:n.common.contextualErrorMap},o=n.data;if(this._def.returns instanceof lt){const d=this;return B(async function(...c){const l=new W([]),u=await d._def.args.parseAsync(c,s).catch(J=>{throw l.addIssue(r(c,J)),l}),Z=await Reflect.apply(o,this,u);return await d._def.returns._def.type.parseAsync(Z,s).catch(J=>{throw l.addIssue(a(Z,J)),l})})}else{const d=this;return B(function(...c){const l=d._def.args.safeParse(c,s);if(!l.success)throw new W([r(c,l.error)]);const u=Reflect.apply(o,this,l.data),Z=d._def.returns.safeParse(u,s);if(!Z.success)throw new W([a(u,Z.error)]);return Z.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new rt({...this._def,args:ce.create(e).rest(Le.create())})}returns(e){return new rt({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,n,r){return new rt({args:e||ce.create([]).rest(Le.create()),returns:n||Le.create(),typeName:N.ZodFunction,...S(r)})}}class Vt extends I{get schema(){return this._def.getter()}_parse(e){const{ctx:n}=this._processInputParams(e);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Vt.create=(t,e)=>new Vt({getter:t,typeName:N.ZodLazy,...S(e)});class Bt extends I{_parse(e){if(e.data!==this._def.value){const n=this._getOrReturnCtx(e);return _(n,{received:n.data,code:p.invalid_literal,expected:this._def.value}),k}return{status:"valid",value:e.data}}get value(){return this._def.value}}Bt.create=(t,e)=>new Bt({value:t,typeName:N.ZodLiteral,...S(e)});function Nr(t,e){return new Ie({values:t,typeName:N.ZodEnum,...S(e)})}class Ie extends I{constructor(){super(...arguments),gt.set(this,void 0)}_parse(e){if(typeof e.data!="string"){const n=this._getOrReturnCtx(e),r=this._def.values;return _(n,{expected:$.joinValues(r),received:n.parsedType,code:p.invalid_type}),k}if(hn(this,gt)||vr(this,gt,new Set(this._def.values)),!hn(this,gt).has(e.data)){const n=this._getOrReturnCtx(e),r=this._def.values;return _(n,{received:n.data,code:p.invalid_enum_value,options:r}),k}return B(e.data)}get options(){return this._def.values}get enum(){const e={};for(const n of this._def.values)e[n]=n;return e}get Values(){const e={};for(const n of this._def.values)e[n]=n;return e}get Enum(){const e={};for(const n of this._def.values)e[n]=n;return e}extract(e,n=this._def){return Ie.create(e,{...this._def,...n})}exclude(e,n=this._def){return Ie.create(this.options.filter(r=>!e.includes(r)),{...this._def,...n})}}gt=new WeakMap;Ie.create=Nr;class Kt extends I{constructor(){super(...arguments),yt.set(this,void 0)}_parse(e){const n=$.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==y.string&&r.parsedType!==y.number){const a=$.objectValues(n);return _(r,{expected:$.joinValues(a),received:r.parsedType,code:p.invalid_type}),k}if(hn(this,yt)||vr(this,yt,new Set($.getValidEnumValues(this._def.values))),!hn(this,yt).has(e.data)){const a=$.objectValues(n);return _(r,{received:r.data,code:p.invalid_enum_value,options:a}),k}return B(e.data)}get enum(){return this._def.values}}yt=new WeakMap;Kt.create=(t,e)=>new Kt({values:t,typeName:N.ZodNativeEnum,...S(e)});class lt extends I{unwrap(){return this._def.type}_parse(e){const{ctx:n}=this._processInputParams(e);if(n.parsedType!==y.promise&&n.common.async===!1)return _(n,{code:p.invalid_type,expected:y.promise,received:n.parsedType}),k;const r=n.parsedType===y.promise?n.data:Promise.resolve(n.data);return B(r.then(a=>this._def.type.parseAsync(a,{path:n.path,errorMap:n.common.contextualErrorMap})))}}lt.create=(t,e)=>new lt({type:t,typeName:N.ZodPromise,...S(e)});class X extends I{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===N.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){const{status:n,ctx:r}=this._processInputParams(e),a=this._def.effect||null,s={addIssue:o=>{_(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(s.addIssue=s.addIssue.bind(s),a.type==="preprocess"){const o=a.transform(r.data,s);if(r.common.async)return Promise.resolve(o).then(async d=>{if(n.value==="aborted")return k;const c=await this._def.schema._parseAsync({data:d,path:r.path,parent:r});return c.status==="aborted"?k:c.status==="dirty"||n.value==="dirty"?tt(c.value):c});{if(n.value==="aborted")return k;const d=this._def.schema._parseSync({data:o,path:r.path,parent:r});return d.status==="aborted"?k:d.status==="dirty"||n.value==="dirty"?tt(d.value):d}}if(a.type==="refinement"){const o=d=>{const c=a.refinement(d,s);if(r.common.async)return Promise.resolve(c);if(c instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return d};if(r.common.async===!1){const d=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return d.status==="aborted"?k:(d.status==="dirty"&&n.dirty(),o(d.value),{status:n.value,value:d.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(d=>d.status==="aborted"?k:(d.status==="dirty"&&n.dirty(),o(d.value).then(()=>({status:n.value,value:d.value}))))}if(a.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!At(o))return o;const d=a.transform(o.value,s);if(d instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:d}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>At(o)?Promise.resolve(a.transform(o.value,s)).then(d=>({status:n.value,value:d})):o);$.assertNever(a)}}X.create=(t,e,n)=>new X({schema:t,typeName:N.ZodEffects,effect:e,...S(n)});X.createWithPreprocess=(t,e,n)=>new X({schema:e,effect:{type:"preprocess",transform:t},typeName:N.ZodEffects,...S(n)});class se extends I{_parse(e){return this._getType(e)===y.undefined?B(void 0):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}se.create=(t,e)=>new se({innerType:t,typeName:N.ZodOptional,...S(e)});class Ze extends I{_parse(e){return this._getType(e)===y.null?B(null):this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Ze.create=(t,e)=>new Ze({innerType:t,typeName:N.ZodNullable,...S(e)});class Wt extends I{_parse(e){const{ctx:n}=this._processInputParams(e);let r=n.data;return n.parsedType===y.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}Wt.create=(t,e)=>new Wt({innerType:t,typeName:N.ZodDefault,defaultValue:typeof e.default=="function"?e.default:()=>e.default,...S(e)});class Jt extends I{_parse(e){const{ctx:n}=this._processInputParams(e),r={...n,common:{...n.common,issues:[]}},a=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Dt(a)?a.then(s=>({status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new W(r.common.issues)},input:r.data})})):{status:"valid",value:a.status==="valid"?a.value:this._def.catchValue({get error(){return new W(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Jt.create=(t,e)=>new Jt({innerType:t,typeName:N.ZodCatch,catchValue:typeof e.catch=="function"?e.catch:()=>e.catch,...S(e)});class _n extends I{_parse(e){if(this._getType(e)!==y.nan){const r=this._getOrReturnCtx(e);return _(r,{code:p.invalid_type,expected:y.nan,received:r.parsedType}),k}return{status:"valid",value:e.data}}}_n.create=t=>new _n({typeName:N.ZodNaN,...S(t)});const qi=Symbol("zod_brand");class Bn extends I{_parse(e){const{ctx:n}=this._processInputParams(e),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Yt extends I{_parse(e){const{status:n,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{const s=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?k:s.status==="dirty"?(n.dirty(),tt(s.value)):this._def.out._parseAsync({data:s.value,path:r.path,parent:r})})();{const a=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?k:a.status==="dirty"?(n.dirty(),{status:"dirty",value:a.value}):this._def.out._parseSync({data:a.value,path:r.path,parent:r})}}static create(e,n){return new Yt({in:e,out:n,typeName:N.ZodPipeline})}}class qt extends I{_parse(e){const n=this._def.innerType._parse(e),r=a=>(At(a)&&(a.value=Object.freeze(a.value)),a);return Dt(n)?n.then(a=>r(a)):r(n)}unwrap(){return this._def.innerType}}qt.create=(t,e)=>new qt({innerType:t,typeName:N.ZodReadonly,...S(e)});function kr(t,e={},n){return t?ct.create().superRefine((r,a)=>{var s,o;if(!t(r)){const d=typeof e=="function"?e(r):typeof e=="string"?{message:e}:e,c=(o=(s=d.fatal)!==null&&s!==void 0?s:n)!==null&&o!==void 0?o:!0,l=typeof d=="string"?{message:d}:d;a.addIssue({code:"custom",...l,fatal:c})}}):ct.create()}const Qi={object:D.lazycreate};var N;(function(t){t.ZodString="ZodString",t.ZodNumber="ZodNumber",t.ZodNaN="ZodNaN",t.ZodBigInt="ZodBigInt",t.ZodBoolean="ZodBoolean",t.ZodDate="ZodDate",t.ZodSymbol="ZodSymbol",t.ZodUndefined="ZodUndefined",t.ZodNull="ZodNull",t.ZodAny="ZodAny",t.ZodUnknown="ZodUnknown",t.ZodNever="ZodNever",t.ZodVoid="ZodVoid",t.ZodArray="ZodArray",t.ZodObject="ZodObject",t.ZodUnion="ZodUnion",t.ZodDiscriminatedUnion="ZodDiscriminatedUnion",t.ZodIntersection="ZodIntersection",t.ZodTuple="ZodTuple",t.ZodRecord="ZodRecord",t.ZodMap="ZodMap",t.ZodSet="ZodSet",t.ZodFunction="ZodFunction",t.ZodLazy="ZodLazy",t.ZodLiteral="ZodLiteral",t.ZodEnum="ZodEnum",t.ZodEffects="ZodEffects",t.ZodNativeEnum="ZodNativeEnum",t.ZodOptional="ZodOptional",t.ZodNullable="ZodNullable",t.ZodDefault="ZodDefault",t.ZodCatch="ZodCatch",t.ZodPromise="ZodPromise",t.ZodBranded="ZodBranded",t.ZodPipeline="ZodPipeline",t.ZodReadonly="ZodReadonly"})(N||(N={}));const Gi=(t,e={message:`Input not instance of ${t.name}`})=>kr(n=>n instanceof t,e),Tr=Q.create,Cr=Se.create,Hi=_n.create,Yi=je.create,Or=Rt.create,Xi=Fe.create,eo=pn.create,to=Mt.create,no=Lt.create,ro=ct.create,ao=Le.create,so=fe.create,io=mn.create,oo=H.create,co=D.create,lo=D.strictCreate,uo=zt.create,ho=vn.create,po=Ut.create,mo=ce.create,fo=Ft.create,_o=fn.create,go=Ve.create,yo=rt.create,vo=Vt.create,bo=Bt.create,wo=Ie.create,xo=Kt.create,No=lt.create,Hn=X.create,ko=se.create,To=Ze.create,Co=X.createWithPreprocess,Oo=Yt.create,So=()=>Tr().optional(),jo=()=>Cr().optional(),Io=()=>Or().optional(),Zo={string:t=>Q.create({...t,coerce:!0}),number:t=>Se.create({...t,coerce:!0}),boolean:t=>Rt.create({...t,coerce:!0}),bigint:t=>je.create({...t,coerce:!0}),date:t=>Fe.create({...t,coerce:!0})},Eo=k;var $o=Object.freeze({__proto__:null,defaultErrorMap:dt,setErrorMap:Zi,getErrorMap:ln,makeIssue:un,EMPTY_PATH:Ei,addIssueToContext:_,ParseStatus:F,INVALID:k,DIRTY:tt,OK:B,isAborted:En,isDirty:$n,isValid:At,isAsync:Dt,get util(){return $},get objectUtil(){return Zn},ZodParsedType:y,getParsedType:Ne,ZodType:I,datetimeRegex:xr,ZodString:Q,ZodNumber:Se,ZodBigInt:je,ZodBoolean:Rt,ZodDate:Fe,ZodSymbol:pn,ZodUndefined:Mt,ZodNull:Lt,ZodAny:ct,ZodUnknown:Le,ZodNever:fe,ZodVoid:mn,ZodArray:H,ZodObject:D,ZodUnion:zt,ZodDiscriminatedUnion:vn,ZodIntersection:Ut,ZodTuple:ce,ZodRecord:Ft,ZodMap:fn,ZodSet:Ve,ZodFunction:rt,ZodLazy:Vt,ZodLiteral:Bt,ZodEnum:Ie,ZodNativeEnum:Kt,ZodPromise:lt,ZodEffects:X,ZodTransformer:X,ZodOptional:se,ZodNullable:Ze,ZodDefault:Wt,ZodCatch:Jt,ZodNaN:_n,BRAND:qi,ZodBranded:Bn,ZodPipeline:Yt,ZodReadonly:qt,custom:kr,Schema:I,ZodSchema:I,late:Qi,get ZodFirstPartyTypeKind(){return N},coerce:Zo,any:ro,array:oo,bigint:Yi,boolean:Or,date:Xi,discriminatedUnion:ho,effect:Hn,enum:wo,function:yo,instanceof:Gi,intersection:po,lazy:vo,literal:bo,map:_o,nan:Hi,nativeEnum:xo,never:so,null:no,nullable:To,number:Cr,object:co,oboolean:Io,onumber:jo,optional:ko,ostring:So,pipeline:Oo,preprocess:Co,promise:No,record:fo,set:go,strictObject:lo,string:Tr,symbol:eo,transformer:Hn,tuple:mo,undefined:to,union:uo,unknown:ao,void:io,NEVER:Eo,ZodIssueCode:p,quotelessJson:Ii,ZodError:W});ji($o);function Xt(t,e="",n={}){for(let r in t)if(Object.prototype.hasOwnProperty.call(t,r)){const a=e?`${e}_${r}`:r;typeof t[r]=="object"&&t[r]!==null&&!Array.isArray(t[r])?Xt(t[r],a,n):n[a]=t[r]}return n}function Sr(t,e){const n={};for(const[r,a]of Object.entries(t)){const s=e.find(o=>r.startsWith(`${o}_`));if(!s)n[r]=a;else{const o=r.slice(s.length+1);n[s]={...n[s],[o]:a}}}return n}function Po(t){return async(e,n)=>{let r=t.selectFrom("connections").where("connections.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","ip"]));const o=(await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute()).map(c=>M(Sr(c,["options"]))),{count:d}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{connections:o,start:n.page*n.per_page,limit:n.per_page,length:Ee(d)}}}function Ao(t){return async(e,n)=>(await t.deleteFrom("connections").where("connections.tenant_id","=",e).where("connections.id","=",n).executeTakeFirst()).numDeletedRows>0}function Do(t){return async(e,n)=>{const r=await t.selectFrom("connections").where("connections.tenant_id","=",e).where("connections.id","=",n).selectAll().executeTakeFirst();return r?M({...r,options:JSON.parse(r.options)}):null}}function Ro(t){return async(e,n,r)=>{const a={...r,updated_at:new Date().toISOString()};return await t.updateTable("connections").set({...a,options:a.options?JSON.stringify(a.options):void 0}).where("connections.id","=",n).where("connections.tenant_id","=",e).execute(),!0}}function Mo(t){return{create:Ci(t),get:Do(t),list:Po(t),remove:Ao(t),update:Ro(t)}}function Lo(t){return{get:async e=>{const n=await t.selectFrom("applications").selectAll().where("id","=",e).executeTakeFirst();if(!n)return null;const r=await t.selectFrom("tenants").selectAll().where("id","=",n.tenant_id).executeTakeFirst();if(!r)throw new Cn(404,{message:"Tenant not found"});const a=await t.selectFrom("connections").where("tenant_id","=",n.tenant_id).selectAll().execute(),s=await t.selectFrom("domains").where("tenant_id","=",n.tenant_id).selectAll().execute();return{...n,connections:a.map(d=>mr.parse(M({...d,options:d.options?JSON.parse(d.options):{}}))),domains:s,addons:n.addons?JSON.parse(n.addons):{},callbacks:n.callbacks?JSON.parse(n.callbacks):[],allowed_origins:n.allowed_origins?JSON.parse(n.allowed_origins):[],web_origins:n.web_origins?JSON.parse(n.web_origins):[],allowed_logout_urls:n.allowed_logout_urls?JSON.parse(n.allowed_logout_urls):[],allowed_clients:n.allowed_clients?JSON.parse(n.allowed_clients):[],tenant:M(r),disable_sign_ups:!!n.disable_sign_ups}}}}function zo(t){return async()=>await t.selectFrom("keys").where(n=>n.or([n("revoked_at",">",new Date().toISOString()),n("revoked_at","is",null)])).selectAll().execute()}function Uo(t){return async e=>{await t.insertInto("keys").values({...e,created_at:new Date().toDateString()}).execute()}}function Fo(t){return async(e,n)=>!!(await t.updateTable("keys").set(n).where("kid","=",e).execute()).length}function Vo(t){return{create:Uo(t),list:zo(t),update:Fo(t)}}function Bo(t){return async(e,n)=>{const r={created_at:new Date().toISOString(),updated_at:new Date().toISOString(),tenant_id:e,id:Ke(),...n};return await t.insertInto("domains").values(r).execute(),r}}function Ko(t){return async(e,n)=>{let r=t.selectFrom("domains").where("domains.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["user_id","ip"]));const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),{count:o}=await r.select(d=>d.fn.countAll().as("count")).executeTakeFirstOrThrow();return{domains:s,start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function Wo(t){return{create:Bo(t),list:Ko(t)}}function Jo(t){return async e=>{const[n]=await t.selectFrom("branding").where("branding.tenant_id","=",e).selectAll().execute();if(!n)return null;const{tenant_id:r,colors_primary:a,colors_page_background_type:s,colors_page_background_start:o,colors_page_background_end:d,colors_page_background_angle_dev:c,font_url:l,...u}=n;return M({...u,colors:{primary:a,page_background:{type:s,start:o,end:d,angle_deg:c}},font:l?{url:l}:void 0})}}function qo(t){return async(e,n)=>{var o,d,c,l,u,Z,R,J,_e,We,ge,ye,ve,Je,qe,ee,te,ne;const{colors:r,font:a,...s}=n;try{await t.insertInto("branding").values({...s,colors_primary:r==null?void 0:r.primary,colors_page_background_type:(d=(o=n.colors)==null?void 0:o.page_background)==null?void 0:d.type,colors_page_background_start:(l=(c=n.colors)==null?void 0:c.page_background)==null?void 0:l.start,colors_page_background_end:(Z=(u=n.colors)==null?void 0:u.page_background)==null?void 0:Z.end,colors_page_background_angle_dev:(J=(R=n.colors)==null?void 0:R.page_background)==null?void 0:J.angle_deg,font_url:(_e=n.font)==null?void 0:_e.url,tenant_id:e}).execute()}catch{await t.updateTable("branding").set({...s,colors_primary:r==null?void 0:r.primary,colors_page_background_type:(ge=(We=n.colors)==null?void 0:We.page_background)==null?void 0:ge.type,colors_page_background_start:(ve=(ye=n.colors)==null?void 0:ye.page_background)==null?void 0:ve.start,colors_page_background_end:(qe=(Je=n.colors)==null?void 0:Je.page_background)==null?void 0:qe.end,colors_page_background_angle_dev:(te=(ee=n.colors)==null?void 0:ee.page_background)==null?void 0:te.angle_deg,font_url:(ne=n.font)==null?void 0:ne.url}).where("tenant_id","=",e).execute()}}}function Qo(t){return{get:Jo(t),set:qo(t)}}function Go(t){return async(e,n)=>{let r=t.selectFrom("hooks").where("hooks.tenant_id","=",e);n.q&&(r=Be(t,r,n.q,["url"]));const s=await r.offset(n.page*n.per_page).limit(n.per_page).selectAll().execute(),{count:o}=await r.select(c=>c.fn.countAll().as("count")).executeTakeFirstOrThrow();return{hooks:s.map(c=>{const{tenant_id:l,enabled:u,synchronous:Z,...R}=c;return M({...R,enabled:!!u,synchronous:!!Z})}),start:n.page*n.per_page,limit:n.per_page,length:Ee(o)}}}function Ho(t){return async(e,n)=>{const r=await t.selectFrom("hooks").where("hooks.tenant_id","=",e).where("hooks.hook_id","=",n).selectAll().executeTakeFirst();return r?M({...r,enabled:!!r.enabled,synchronous:!!r.synchronous}):null}}function Yo(t){return async(e,n)=>(await t.deleteFrom("hooks").where("hooks.tenant_id","=",e).where("hooks.hook_id","=",n).executeTakeFirst()).numDeletedRows>0}function Xo(t){return async(e,n)=>{const r={hook_id:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("hooks").values({...r,tenant_id:e,enabled:n.enabled?1:0,synchronous:n.synchronous?1:0}).execute(),r}}function ed(t){return async(e,n,r)=>{const a={...r,updated_at:new Date().toISOString(),enabled:r.enabled!==void 0?r.enabled?1:0:void 0,synchronous:r.enabled!==void 0?r.synchronous?1:0:void 0};return await t.updateTable("hooks").set(a).where("hooks.hook_id","=",n).where("hooks.tenant_id","=",e).execute(),!0}}function td(t){return{create:Xo(t),get:Ho(t),list:Go(t),update:ed(t),remove:Yo(t)}}function nd(t){return async(e,n)=>{const r={themeId:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("themes").values({...Xt(r),tenant_id:e}).execute(),r}}function rd(t){return async(e,n)=>(await t.deleteFrom("themes").where("themes.tenant_id","=",e).where("themes.theme_id","=",n).executeTakeFirst()).numDeletedRows>0}function ad(t){return async(e,n)=>{const r=await t.selectFrom("themes").where("themes.tenant_id","=",e).where("themes.theme_id","=",n).selectAll().executeTakeFirst();return r?M(r):null}}function sd(t){return async(e,n,r)=>{const a=Xt({...r,updated_at:new Date().toISOString()});return await t.updateTable("themes").set(a).where("themes.id","=",n).where("themes.tenant_id","=",e).execute(),!0}}function id(t){return{create:nd(t),get:ad(t),remove:rd(t),update:sd(t)}}function od(t){return async(e,n)=>{const r=new Date().toISOString(),a=await t.selectFrom("logins").where("logins.expires_at",">",r).where("logins.login_id","=",n).selectAll().executeTakeFirst();return a?ks.parse(Sr(M(a),["authParams"])):null}}function dd(t){return async(e,n)=>{const r={login_id:Ke(),...n,created_at:new Date().toISOString(),updated_at:new Date().toISOString()};return await t.insertInto("logins").values({...Xt(r),tenant_id:e}).execute(),r}}function cd(t){return async(e,n,r)=>(await t.updateTable("logins").set(Xt(r)).where("logins.login_id","=",n).where("logins.tenant_id","=",e).execute()).length===1}function ld(t){return async(e,n)=>(await t.deleteFrom("logins").where("logins.tenant_id","=",e).where("logins.login_id","=",n).execute()).length>0}function ud(t){return{create:dd(t),get:od(t),update:cd(t),remove:ld(t)}}function hd(t){return async e=>{const[n]=await t.selectFrom("prompt_settings").where("prompt_settings.tenant_id","=",e).selectAll().execute();return M({identifier_first:!!(n!=null&&n.identifier_first),password_first:!!(n!=null&&n.password_first),webauthn_platform_first_factor:!!(n!=null&&n.webauthn_platform_first_factor),universal_login_experience:(n==null?void 0:n.universal_login_experience)||"new"})}}function Yn(t){return M({...t,webauthn_platform_first_factor:t.webauthn_platform_first_factor?!!t.webauthn_platform_first_factor:void 0,identifier_first:t.identifier_first?!!t.identifier_first:void 0,password_first:t.password_first?!!t.password_first:void 0,universal_login_experience:t.universal_login_experience})}function pd(t){return async(e,n)=>{try{const r=As.parse(n);await t.insertInto("prompt_settings").values({...Yn(r),tenant_id:e}).execute()}catch{await t.updateTable("prompt_settings").set(Yn(n)).where("tenant_id","=",e).execute()}}}function md(t){return{get:hd(t),set:pd(t)}}function fd(t){return t[t.length-1]}function z(t){return Object.freeze(t)}const en=z({is(t){return t.kind==="IdentifierNode"},create(t){return z({kind:"IdentifierNode",name:t})}}),An=z({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return z({kind:"SchemableIdentifierNode",identifier:en.create(t)})},createWithSchema(t,e){return z({kind:"SchemableIdentifierNode",schema:en.create(t),identifier:en.create(e)})}}),_d=z({is(t){return t.kind==="AliasNode"},create(t,e){return z({kind:"AliasNode",node:t,alias:e})}}),Nn=z({is(t){return t.kind==="TableNode"},create(t){return z({kind:"TableNode",table:An.create(t)})},createWithSchema(t,e){return z({kind:"TableNode",table:An.createWithSchema(t,e)})}});var gn;class gd{constructor(){ut(this,"nodeStack",[]);re(this,gn,z({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this)}))}transformNode(e){if(!e)return e;this.nodeStack.push(e);const n=this.transformNodeImpl(e);return this.nodeStack.pop(),z(n)}transformNodeImpl(e){return v(this,gn)[e.kind](e)}transformNodeList(e){return e&&z(e.map(n=>this.transformNode(n)))}transformSelectQuery(e){return{kind:"SelectQueryNode",from:this.transformNode(e.from),selections:this.transformNodeList(e.selections),distinctOn:this.transformNodeList(e.distinctOn),joins:this.transformNodeList(e.joins),groupBy:this.transformNode(e.groupBy),orderBy:this.transformNode(e.orderBy),where:this.transformNode(e.where),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),limit:this.transformNode(e.limit),offset:this.transformNode(e.offset),with:this.transformNode(e.with),having:this.transformNode(e.having),explain:this.transformNode(e.explain),setOperations:this.transformNodeList(e.setOperations),fetch:this.transformNode(e.fetch),top:this.transformNode(e.top)}}transformSelection(e){return{kind:"SelectionNode",selection:this.transformNode(e.selection)}}transformColumn(e){return{kind:"ColumnNode",column:this.transformNode(e.column)}}transformAlias(e){return{kind:"AliasNode",node:this.transformNode(e.node),alias:this.transformNode(e.alias)}}transformTable(e){return{kind:"TableNode",table:this.transformNode(e.table)}}transformFrom(e){return{kind:"FromNode",froms:this.transformNodeList(e.froms)}}transformReference(e){return{kind:"ReferenceNode",column:this.transformNode(e.column),table:this.transformNode(e.table)}}transformAnd(e){return{kind:"AndNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformOr(e){return{kind:"OrNode",left:this.transformNode(e.left),right:this.transformNode(e.right)}}transformValueList(e){return{kind:"ValueListNode",values:this.transformNodeList(e.values)}}transformParens(e){return{kind:"ParensNode",node:this.transformNode(e.node)}}transformJoin(e){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table),on:this.transformNode(e.on)}}transformRaw(e){return{kind:"RawNode",sqlFragments:z([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters)}}transformWhere(e){return{kind:"WhereNode",where:this.transformNode(e.where)}}transformInsertQuery(e){return{kind:"InsertQueryNode",into:this.transformNode(e.into),columns:this.transformNodeList(e.columns),values:this.transformNode(e.values),returning:this.transformNode(e.returning),onConflict:this.transformNode(e.onConflict),onDuplicateKey:this.transformNode(e.onDuplicateKey),with:this.transformNode(e.with),ignore:e.ignore,replace:e.replace,explain:this.transformNode(e.explain),defaultValues:e.defaultValues,top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformValues(e){return{kind:"ValuesNode",values:this.transformNodeList(e.values)}}transformDeleteQuery(e){return{kind:"DeleteQueryNode",from:this.transformNode(e.from),using:this.transformNode(e.using),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),returning:this.transformNode(e.returning),with:this.transformNode(e.with),orderBy:this.transformNode(e.orderBy),limit:this.transformNode(e.limit),explain:this.transformNode(e.explain),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformReturning(e){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections)}}transformCreateTable(e){return{kind:"CreateTableNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),constraints:this.transformNodeList(e.constraints),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),selectQuery:this.transformNode(e.selectQuery)}}transformColumnDefinition(e){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),references:this.transformNode(e.references),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo),check:this.transformNode(e.check),generated:this.transformNode(e.generated),frontModifiers:this.transformNodeList(e.frontModifiers),endModifiers:this.transformNodeList(e.endModifiers),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e){return{kind:"AddColumnNode",column:this.transformNode(e.column)}}transformDropTable(e){return{kind:"DropTableNode",table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e){return{kind:"OrderByNode",items:this.transformNodeList(e.items)}}transformOrderByItem(e){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy),direction:this.transformNode(e.direction)}}transformGroupBy(e){return{kind:"GroupByNode",items:this.transformNodeList(e.items)}}transformGroupByItem(e){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy)}}transformUpdateQuery(e){return{kind:"UpdateQueryNode",table:this.transformNode(e.table),from:this.transformNode(e.from),joins:this.transformNodeList(e.joins),where:this.transformNode(e.where),updates:this.transformNodeList(e.updates),returning:this.transformNode(e.returning),with:this.transformNode(e.with),explain:this.transformNode(e.explain),limit:this.transformNode(e.limit),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformColumnUpdate(e){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column),value:this.transformNode(e.value)}}transformLimit(e){return{kind:"LimitNode",limit:this.transformNode(e.limit)}}transformOffset(e){return{kind:"OffsetNode",offset:this.transformNode(e.offset)}}transformOnConflict(e){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns),constraint:this.transformNode(e.constraint),indexExpression:this.transformNode(e.indexExpression),indexWhere:this.transformNode(e.indexWhere),updates:this.transformNodeList(e.updates),updateWhere:this.transformNode(e.updateWhere),doNothing:e.doNothing}}transformOnDuplicateKey(e){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates)}}transformCreateIndex(e){return{kind:"CreateIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists,where:this.transformNode(e.where),nullsNotDistinct:e.nullsNotDistinct}}transformList(e){return{kind:"ListNode",items:this.transformNodeList(e.items)}}transformDropIndex(e){return{kind:"DropIndexNode",name:this.transformNode(e.name),table:this.transformNode(e.table),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name)}}transformUniqueConstraint(e){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns),name:this.transformNode(e.name),nullsNotDistinct:e.nullsNotDistinct}}transformForeignKeyConstraint(e){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns),references:this.transformNode(e.references),name:this.transformNode(e.name),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformSetOperation(e){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression),all:e.all}}transformReferences(e){return{kind:"ReferencesNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression),name:this.transformNode(e.name)}}transformWith(e){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions),recursive:e.recursive}}transformCommonTableExpression(e){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name),materialized:e.materialized,expression:this.transformNode(e.expression)}}transformCommonTableExpressionName(e){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table),columns:this.transformNodeList(e.columns)}}transformHaving(e){return{kind:"HavingNode",having:this.transformNode(e.having)}}transformCreateSchema(e){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema),ifNotExists:e.ifNotExists}}transformDropSchema(e){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e){return{kind:"AlterTableNode",table:this.transformNode(e.table),renameTo:this.transformNode(e.renameTo),setSchema:this.transformNode(e.setSchema),columnAlterations:this.transformNodeList(e.columnAlterations),addConstraint:this.transformNode(e.addConstraint),dropConstraint:this.transformNode(e.dropConstraint),addIndex:this.transformNode(e.addIndex),dropIndex:this.transformNode(e.dropIndex)}}transformDropColumn(e){return{kind:"DropColumnNode",column:this.transformNode(e.column)}}transformRenameColumn(e){return{kind:"RenameColumnNode",column:this.transformNode(e.column),renameTo:this.transformNode(e.renameTo)}}transformAlterColumn(e){return{kind:"AlterColumnNode",column:this.transformNode(e.column),dataType:this.transformNode(e.dataType),dataTypeExpression:this.transformNode(e.dataTypeExpression),setDefault:this.transformNode(e.setDefault),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e){return{kind:"ModifyColumnNode",column:this.transformNode(e.column)}}transformAddConstraint(e){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint)}}transformDropConstraint(e){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName),ifExists:e.ifExists,modifier:e.modifier}}transformCreateView(e){return{kind:"CreateViewNode",name:this.transformNode(e.name),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns),as:this.transformNode(e.as)}}transformDropView(e){return{kind:"DropViewNode",name:this.transformNode(e.name),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression)}}transformDefaultValue(e){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue)}}transformOn(e){return{kind:"OnNode",on:this.transformNode(e.on)}}transformSelectModifier(e){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier),of:this.transformNodeList(e.of)}}transformCreateType(e){return{kind:"CreateTypeNode",name:this.transformNode(e.name),enum:this.transformNode(e.enum)}}transformDropType(e){return{kind:"DropTypeNode",name:this.transformNode(e.name),ifExists:e.ifExists}}transformExplain(e){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options)}}transformSchemableIdentifier(e){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema),identifier:this.transformNode(e.identifier)}}transformAggregateFunction(e){return{kind:"AggregateFunctionNode",aggregated:this.transformNodeList(e.aggregated),distinct:e.distinct,filter:this.transformNode(e.filter),func:e.func,over:this.transformNode(e.over)}}transformOver(e){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy),partitionBy:this.transformNode(e.partitionBy)}}transformPartitionBy(e){return{kind:"PartitionByNode",items:this.transformNodeList(e.items)}}transformPartitionByItem(e){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy)}}transformBinaryOperation(e){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand),operator:this.transformNode(e.operator),rightOperand:this.transformNode(e.rightOperand)}}transformUnaryOperation(e){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator),operand:this.transformNode(e.operand)}}transformUsing(e){return{kind:"UsingNode",tables:this.transformNodeList(e.tables)}}transformFunction(e){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments)}}transformCase(e){return{kind:"CaseNode",value:this.transformNode(e.value),when:this.transformNodeList(e.when),else:this.transformNode(e.else),isStatement:e.isStatement}}transformWhen(e){return{kind:"WhenNode",condition:this.transformNode(e.condition),result:this.transformNode(e.result)}}transformJSONReference(e){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference),traversal:this.transformNode(e.traversal)}}transformJSONPath(e){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator),pathLegs:this.transformNodeList(e.pathLegs)}}transformJSONPathLeg(e){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator),values:this.transformNodeList(e.values)}}transformTuple(e){return{kind:"TupleNode",values:this.transformNodeList(e.values)}}transformMergeQuery(e){return{kind:"MergeQueryNode",into:this.transformNode(e.into),using:this.transformNode(e.using),whens:this.transformNodeList(e.whens),with:this.transformNode(e.with),top:this.transformNode(e.top),output:this.transformNode(e.output)}}transformMatched(e){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e){return{kind:"AddIndexNode",name:this.transformNode(e.name),columns:this.transformNodeList(e.columns),unique:e.unique,using:this.transformNode(e.using),ifNotExists:e.ifNotExists}}transformCast(e){return{kind:"CastNode",expression:this.transformNode(e.expression),dataType:this.transformNode(e.dataType)}}transformFetch(e){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount),modifier:e.modifier}}transformTop(e){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e){return{kind:"OutputNode",selections:this.transformNodeList(e.selections)}}transformDataType(e){return e}transformSelectAll(e){return e}transformIdentifier(e){return e}transformValue(e){return e}transformPrimitiveValueList(e){return e}transformOperator(e){return e}transformDefaultInsertValue(e){return e}}gn=new WeakMap;const yd=z({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0});var at,De,Re,L,jr,Ir,Zr,Ye,Dn,Er;class vd extends gd{constructor(n){super();re(this,L);re(this,at);re(this,De,new Set);re(this,Re,new Set);ht(this,at,n)}transformNodeImpl(n){if(!C(this,L,jr).call(this,n))return super.transformNodeImpl(n);const r=C(this,L,Zr).call(this,n);for(const o of r)v(this,Re).add(o);const a=C(this,L,Ir).call(this,n);for(const o of a)v(this,De).add(o);const s=super.transformNodeImpl(n);for(const o of a)v(this,De).delete(o);for(const o of r)v(this,Re).delete(o);return s}transformSchemableIdentifier(n){const r=super.transformSchemableIdentifier(n);return r.schema||!v(this,De).has(n.identifier.name)?r:{...r,schema:en.create(v(this,at))}}transformReferences(n){const r=super.transformReferences(n);return r.table.table.schema?r:{...r,table:Nn.createWithSchema(v(this,at),r.table.table.identifier.name)}}}at=new WeakMap,De=new WeakMap,Re=new WeakMap,L=new WeakSet,jr=function(n){return n.kind in yd},Ir=function(n){const r=new Set;if("name"in n&&n.name&&An.is(n.name)&&C(this,L,Dn).call(this,n.name,r),"from"in n&&n.from)for(const a of n.from.froms)C(this,L,Ye).call(this,a,r);if("into"in n&&n.into&&C(this,L,Ye).call(this,n.into,r),"table"in n&&n.table&&C(this,L,Ye).call(this,n.table,r),"joins"in n&&n.joins)for(const a of n.joins)C(this,L,Ye).call(this,a.table,r);return"using"in n&&n.using&&C(this,L,Ye).call(this,n.using,r),r},Zr=function(n){const r=new Set;return"with"in n&&n.with&&C(this,L,Er).call(this,n.with,r),r},Ye=function(n,r){const a=Nn.is(n)?n:_d.is(n)&&Nn.is(n.node)?n.node:null;a&&C(this,L,Dn).call(this,a.table,r)},Dn=function(n,r){const a=n.identifier.name;!v(this,De).has(a)&&!v(this,Re).has(a)&&r.add(a)},Er=function(n,r){for(const a of n.expressions){const s=a.name.table.table.identifier.name;v(this,Re).has(s)||r.add(s)}};var Qt;class bd{constructor(e){re(this,Qt);ht(this,Qt,new vd(e))}transformQuery(e){return v(this,Qt).transformNode(e.node)}async transformResult(e){return e.result}}Qt=new WeakMap;class wd{transformQuery(e){return e.node}async transformResult(e){return e.result}}const xd="kysely_migration",Xn="kysely_migration_lock",Nd=!1,kn="migration_lock",kd=z({__noMigrations__:!0});var P,m,vt,ue,he,Xe,Pr,pe,Ar,Dr,Rr,Mr,Lr,Rn,et,Mn,zr,Ur,Fr,Ln,Vr,Br,Kr,Wr,Jr,bt;class $r{constructor(e){re(this,m);re(this,P);ht(this,P,z(e))}async getMigrations(){const e=await C(this,m,et).call(this,v(this,m,he))?await v(this,P).db.withPlugin(v(this,m,pe)).selectFrom(v(this,m,he)).select(["name","timestamp"]).execute():[];return(await C(this,m,Ln).call(this)).map(({name:r,...a})=>{const s=e.find(o=>o.name===r);return{name:r,migration:a,executedAt:s?new Date(s.timestamp):void 0}})}async migrateToLatest(){return C(this,m,vt).call(this,()=>({direction:"Up",step:1/0}))}async migrateTo(e){return C(this,m,vt).call(this,({migrations:n,executedMigrations:r,pendingMigrations:a})=>{if(e===kd)return{direction:"Down",step:1/0};if(!n.find(d=>d.name===e))throw new Error(`migration "${e}" doesn't exist`);const s=r.indexOf(e),o=a.findIndex(d=>d.name===e);if(s!==-1)return{direction:"Down",step:r.length-s-1};if(o!==-1)return{direction:"Up",step:o+1};throw new Error(`migration "${e}" isn't executed or pending`)})}async migrateUp(){return C(this,m,vt).call(this,()=>({direction:"Up",step:1}))}async migrateDown(){return C(this,m,vt).call(this,()=>({direction:"Down",step:1}))}}P=new WeakMap,m=new WeakSet,vt=async function(e){try{return await C(this,m,Ar).call(this),await C(this,m,zr).call(this,e)}catch(n){return n instanceof Tn?n.resultSet:{error:n}}},ue=function(){return v(this,P).migrationTableSchema},he=function(){return v(this,P).migrationTableName??xd},Xe=function(){return v(this,P).migrationLockTableName??Xn},Pr=function(){return v(this,P).allowUnorderedMigrations??Nd},pe=function(){return v(this,m,ue)?new bd(v(this,m,ue)):new wd},Ar=async function(){await C(this,m,Dr).call(this),await C(this,m,Rr).call(this),await C(this,m,Mr).call(this),await C(this,m,Lr).call(this)},Dr=async function(){if(v(this,m,ue)&&!await C(this,m,Rn).call(this))try{await C(this,m,bt).call(this,v(this,P).db.schema.createSchema(v(this,m,ue)))}catch(e){if(!await C(this,m,Rn).call(this))throw e}},Rr=async function(){if(!await C(this,m,et).call(this,v(this,m,he)))try{v(this,m,ue)&&await C(this,m,bt).call(this,v(this,P).db.schema.createSchema(v(this,m,ue))),await C(this,m,bt).call(this,v(this,P).db.schema.withPlugin(v(this,m,pe)).createTable(v(this,m,he)).addColumn("name","varchar(255)",e=>e.notNull().primaryKey()).addColumn("timestamp","varchar(255)",e=>e.notNull()))}catch(e){if(!await C(this,m,et).call(this,v(this,m,he)))throw e}},Mr=async function(){if(!await C(this,m,et).call(this,v(this,m,Xe)))try{await C(this,m,bt).call(this,v(this,P).db.schema.withPlugin(v(this,m,pe)).createTable(v(this,m,Xe)).addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("is_locked","integer",e=>e.notNull().defaultTo(0)))}catch(e){if(!await C(this,m,et).call(this,v(this,m,Xe)))throw e}},Lr=async function(){if(!await C(this,m,Mn).call(this))try{await v(this,P).db.withPlugin(v(this,m,pe)).insertInto(v(this,m,Xe)).values({id:kn,is_locked:0}).execute()}catch(e){if(!await C(this,m,Mn).call(this))throw e}},Rn=async function(){return(await v(this,P).db.introspection.getSchemas()).some(n=>n.name===v(this,m,ue))},et=async function(e){const n=v(this,m,ue);return(await v(this,P).db.introspection.getTables({withInternalKyselyTables:!0})).some(a=>a.name===e&&(!n||a.schema===n))},Mn=async function(){return!!await v(this,P).db.withPlugin(v(this,m,pe)).selectFrom(v(this,m,Xe)).where("id","=",kn).select("id").executeTakeFirst()},zr=async function(e){const n=v(this,P).db.getExecutor().adapter,r=z({lockTable:v(this,P).migrationLockTableName??Xn,lockRowId:kn,lockTableSchema:v(this,P).migrationTableSchema}),a=async s=>{try{await n.acquireMigrationLock(s,r);const o=await C(this,m,Ur).call(this,s);if(o.migrations.length===0)return{results:[]};const{direction:d,step:c}=e(o);return c<=0?{results:[]}:d==="Down"?await C(this,m,Wr).call(this,s,o,c):d==="Up"?await C(this,m,Jr).call(this,s,o,c):{results:[]}}finally{await n.releaseMigrationLock(s,r)}};return n.supportsTransactionalDdl?v(this,P).db.transaction().execute(a):v(this,P).db.connection().execute(a)},Ur=async function(e){const n=await C(this,m,Ln).call(this),r=await C(this,m,Vr).call(this,e);C(this,m,Br).call(this,n,r),v(this,m,Pr)||C(this,m,Kr).call(this,n,r);const a=C(this,m,Fr).call(this,n,r);return z({migrations:n,executedMigrations:r,lastMigration:fd(r),pendingMigrations:a})},Fr=function(e,n){return e.filter(r=>!n.includes(r.name))},Ln=async function(){const e=await v(this,P).provider.getMigrations();return Object.keys(e).sort().map(n=>({...e[n],name:n}))},Vr=async function(e){return(await e.withPlugin(v(this,m,pe)).selectFrom(v(this,m,he)).select("name").orderBy(["timestamp","name"]).execute()).map(r=>r.name)},Br=function(e,n){for(const r of n)if(!e.some(a=>a.name===r))throw new Error(`corrupted migrations: previously executed migration ${r} is missing`)},Kr=function(e,n){for(let r=0;r<n.length;++r)if(e[r].name!==n[r])throw new Error(`corrupted migrations: expected previously executed migration ${n[r]} to be at index ${r} but ${e[r].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`)},Wr=async function(e,n,r){const a=n.executedMigrations.slice().reverse().slice(0,r).map(o=>n.migrations.find(d=>d.name===o)),s=a.map(o=>({migrationName:o.name,direction:"Down",status:"NotExecuted"}));for(let o=0;o<s.length;++o){const d=a[o];try{d.down&&(await d.down(e),await e.withPlugin(v(this,m,pe)).deleteFrom(v(this,m,he)).where("name","=",d.name).execute(),s[o]={migrationName:d.name,direction:"Down",status:"Success"})}catch(c){throw s[o]={migrationName:d.name,direction:"Down",status:"Error"},new Tn({error:c,results:s})}}return{results:s}},Jr=async function(e,n,r){const s=n.pendingMigrations.slice(0,r).map(o=>({migrationName:o.name,direction:"Up",status:"NotExecuted"}));for(let o=0;o<s.length;o++){const d=n.pendingMigrations[o];try{await d.up(e),await e.withPlugin(v(this,m,pe)).insertInto(v(this,m,he)).values({name:d.name,timestamp:new Date().toISOString()}).execute(),s[o]={migrationName:d.name,direction:"Up",status:"Success"}}catch(c){throw s[o]={migrationName:d.name,direction:"Up",status:"Error"},new Tn({error:c,results:s})}}return{results:s}},bt=async function(e){v(this,P).db.getExecutor().adapter.supportsCreateIfNotExists&&(e=e.ifNotExists()),await e.execute()};var Gt;class Tn extends Error{constructor(n){super();re(this,Gt);ht(this,Gt,n)}get resultSet(){return v(this,Gt)}}Gt=new WeakMap;class qr{constructor(e){ut(this,"migrations");this.migrations=e}async getMigrations(){return this.migrations}}async function Td(t){await t.schema.createTable("tenants").addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("name","varchar(255)").addColumn("audience","varchar(255)").addColumn("sender_email","varchar(255)").addColumn("sender_name","varchar(255)").addColumn("language","varchar(255)").addColumn("logo","varchar(255)").addColumn("primary_color","varchar(255)").addColumn("secondary_color","varchar(255)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("users").addColumn("user_id","varchar(255)",e=>e.notNull()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("given_name","varchar(255)").addColumn("family_name","varchar(255)").addColumn("nickname","varchar(255)").addColumn("name","varchar(255)").addColumn("picture","varchar(2083)").addColumn("tags","varchar(255)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).addPrimaryKeyConstraint("users_tenants",["user_id","tenant_id"]).addColumn("linked_to","varchar(255)").addForeignKeyConstraint("linked_to_constraint",["linked_to","tenant_id"],"users",["user_id","tenant_id"]).addColumn("last_ip","varchar(255)").addColumn("login_count","integer",e=>e.notNull()).addColumn("last_login","varchar(255)").addColumn("provider","varchar(255)",e=>e.notNull()).addColumn("connection","varchar(255)").addColumn("email_verified","boolean",e=>e.notNull()).addColumn("is_social","boolean",e=>e.notNull()).addColumn("app_metadata","varchar(4096)",e=>e.defaultTo("{}").notNull()).addColumn("user_metadata","varchar(4096)",e=>e.defaultTo("{}").notNull()).addUniqueConstraint("unique_email_provider",["email","provider","tenant_id"]).execute(),await t.schema.createTable("members").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("sub","varchar(255)").addColumn("email","varchar(255)").addColumn("name","varchar(255)").addColumn("status","varchar(255)").addColumn("role","varchar(255)").addColumn("picture","varchar(2083)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("applications").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("name","varchar(255)",e=>e.notNull()).addColumn("client_secret","varchar(255)").addColumn("allowed_logout_urls","varchar(255)").addColumn("authentication_settings","varchar(255)").addColumn("addons","varchar(4096)",e=>e.notNull().defaultTo("{}")).addColumn("callbacks","varchar(1024)",e=>e.notNull().defaultTo("[]")).addColumn("allowed_origins","varchar(1024)",e=>e.notNull().defaultTo("[]")).addColumn("web_origins","varchar(1024)",e=>e.notNull().defaultTo("[]")).addColumn("allowed_clients","varchar(1024)",e=>e.defaultTo("[]").notNull()).addColumn("options_kid","varchar(32)").addColumn("options_team_id","varchar(32)").addColumn("options_client_id","varchar(128)").addColumn("options_client_secret","varchar(255)").addColumn("options_scope","varchar(255)").addColumn("options_realms","varchar(255)").addColumn("options_app_secret","varchar(1024)").addColumn("email_validation","varchar(255)").addColumn("disable_sign_ups","boolean",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("connections").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("name","varchar(255)",e=>e.notNull()).addColumn("response_type","varchar(255)").addColumn("response_mode","varchar(255)").addColumn("strategy","varchar(64)").addColumn("options","varchar(2048)",e=>e.defaultTo("{}").notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("migrations").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("provider","varchar(255)").addColumn("client_id","varchar(255)").addColumn("origin","varchar(255)").addColumn("domain","varchar(255)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.createTable("domains").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("domain","varchar(255)",e=>e.notNull()).addColumn("email_service","varchar(255)").addColumn("email_api_key","varchar(255)").addColumn("dkim_private_key","varchar(2048)").addColumn("dkim_public_key","varchar(2048)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).execute()}async function Cd(t){await t.schema.dropTable("domains").execute(),await t.schema.dropTable("members").execute(),await t.schema.dropTable("users").execute(),await t.schema.dropTable("connections").execute(),await t.schema.dropTable("applications").execute(),await t.schema.dropTable("migrations").execute(),await t.schema.dropTable("tenants").execute()}const Od=Object.freeze(Object.defineProperty({__proto__:null,down:Cd,up:Td},Symbol.toStringTag,{value:"Module"}));async function Sd(t){await t.schema.alterTable("tenants").addColumn("support_url","varchar(255)").execute()}async function jd(t){await t.schema.alterTable("tenants").dropColumn("support_url").execute()}const Id=Object.freeze(Object.defineProperty({__proto__:null,down:jd,up:Sd},Symbol.toStringTag,{value:"Module"}));async function Zd(t){}async function Ed(t){}const $d=Object.freeze(Object.defineProperty({__proto__:null,down:Ed,up:Zd},Symbol.toStringTag,{value:"Module"}));async function Pd(t){await t.schema.createTable("logs").addColumn("id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("category","varchar(255)",e=>e.notNull()).addColumn("tenant_id","varchar(64)").addColumn("user_id","varchar(64)").addForeignKeyConstraint("tenant_id_constraint",["tenant_id"],"tenants",["id"],e=>e.onDelete("cascade")).addColumn("ip","varchar(255)").addColumn("type","varchar(8)",e=>e.notNull()).addColumn("date","varchar(25)",e=>e.notNull()).addColumn("client_id","varchar(255)").addColumn("client_name","varchar(255)").addColumn("user_agent","varchar(255)").addColumn("description","varchar(255)").addColumn("details","varchar(2048)").execute()}async function Ad(t){await t.schema.dropTable("logs").execute()}const Dd=Object.freeze(Object.defineProperty({__proto__:null,down:Ad,up:Pd},Symbol.toStringTag,{value:"Module"}));async function Rd(t){}async function Md(t){}const Ld=Object.freeze(Object.defineProperty({__proto__:null,down:Md,up:Rd},Symbol.toStringTag,{value:"Module"}));async function zd(t){await t.schema.createTable("sessions").addColumn("session_id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("tenant_id","varchar(255)").addColumn("user_id","varchar(255)").addForeignKeyConstraint("user_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").addColumn("deleted_at","varchar(255)").execute(),await t.schema.createTable("tickets").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("nonce","varchar(255)").addColumn("state","varchar(1024)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createTable("otps").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("user_id","varchar(255)").addColumn("send","varchar(255)").addColumn("nonce","varchar(255)").addColumn("state","varchar(1024)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createIndex("otps_email_index").on("otps").column("email").execute(),await t.schema.createIndex("otps_expires_at_index").on("otps").column("expires_at").execute()}async function Ud(t){await t.schema.dropTable("sessions").execute(),await t.schema.dropTable("tickets").execute(),await t.schema.dropTable("otps").execute()}const Fd=Object.freeze(Object.defineProperty({__proto__:null,down:Ud,up:zd},Symbol.toStringTag,{value:"Module"}));async function Vd(t){await t.schema.createTable("passwords").addColumn("tenant_id","varchar(255)").addColumn("user_id","varchar(255)").addForeignKeyConstraint("user_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("created_at","varchar(255)").addColumn("updated_at","varchar(255)").execute(),await t.schema.createTable("codes").addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("user_id","varchar(255)").addColumn("tenant_id","varchar(255)").addForeignKeyConstraint("user_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createIndex("codes_expires_at_index").on("codes").column("expires_at").execute()}async function Bd(t){await t.schema.dropTable("passwords").execute(),await t.schema.dropTable("codes").execute()}const Kd=Object.freeze(Object.defineProperty({__proto__:null,down:Bd,up:Vd},Symbol.toStringTag,{value:"Module"}));async function Wd(t){}async function Jd(t){}const qd=Object.freeze(Object.defineProperty({__proto__:null,down:Jd,up:Wd},Symbol.toStringTag,{value:"Module"}));async function Qd(t){await t.schema.alterTable("passwords").addColumn("password","varchar(255)",e=>e.notNull()).execute()}async function Gd(t){await t.schema.alterTable("passwords").dropColumn("password").execute()}const Hd=Object.freeze(Object.defineProperty({__proto__:null,down:Gd,up:Qd},Symbol.toStringTag,{value:"Module"}));async function Yd(t){}async function Xd(t){}const ec=Object.freeze(Object.defineProperty({__proto__:null,down:Xd,up:Yd},Symbol.toStringTag,{value:"Module"}));async function tc(t){}async function nc(t){}const rc=Object.freeze(Object.defineProperty({__proto__:null,down:nc,up:tc},Symbol.toStringTag,{value:"Module"}));async function ac(t){}async function sc(t){}const ic=Object.freeze(Object.defineProperty({__proto__:null,down:sc,up:ac},Symbol.toStringTag,{value:"Module"}));async function oc(t){await t.schema.createIndex("users_email_index").on("users").column("email").execute()}async function dc(t){await t.schema.dropIndex("users_email_index").execute()}const cc=Object.freeze(Object.defineProperty({__proto__:null,down:dc,up:oc},Symbol.toStringTag,{value:"Module"}));async function lc(t){await t.schema.alterTable("users").addColumn("profileData","varchar(2048)").execute()}async function uc(t){await t.schema.alterTable("users").dropColumn("profileData").execute()}const hc=Object.freeze(Object.defineProperty({__proto__:null,down:uc,up:lc},Symbol.toStringTag,{value:"Module"}));async function pc(t){await t.schema.createIndex("users_linked_to_index").on("users").column("linked_to").execute()}async function mc(t){await t.schema.dropIndex("users_linked_to_index")}const fc=Object.freeze(Object.defineProperty({__proto__:null,down:mc,up:pc},Symbol.toStringTag,{value:"Module"}));async function _c(t){await t.schema.alterTable("users").addColumn("locale","varchar(255)").execute()}async function gc(t){await t.schema.alterTable("users").dropColumn("locale").execute()}const yc=Object.freeze(Object.defineProperty({__proto__:null,down:gc,up:_c},Symbol.toStringTag,{value:"Module"}));async function vc(t){await t.schema.createTable("keys").addColumn("kid","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade")).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("revoked_at","varchar(255)").addColumn("cert","varchar(2048)").addColumn("pkcs7","varchar(2048)").addColumn("fingerprint","varchar(256)").addColumn("thumbprint","varchar(256)").addColumn("current_since","varchar(256)").addColumn("current_until","varchar(256)").execute()}async function bc(t){await t.schema.dropTable("keys").execute()}const wc=Object.freeze(Object.defineProperty({__proto__:null,down:bc,up:vc},Symbol.toStringTag,{value:"Module"}));async function xc(t){}async function Nc(t){}const kc=Object.freeze(Object.defineProperty({__proto__:null,down:Nc,up:xc},Symbol.toStringTag,{value:"Module"}));async function Tc(t){}async function Cc(t){}const Oc=Object.freeze(Object.defineProperty({__proto__:null,down:Cc,up:Tc},Symbol.toStringTag,{value:"Module"}));async function Sc(t){await t.schema.alterTable("otps").addColumn("audience","varchar(255)").execute()}async function jc(t){await t.schema.alterTable("otps").dropColumn("audience").execute()}const Ic=Object.freeze(Object.defineProperty({__proto__:null,down:jc,up:Sc},Symbol.toStringTag,{value:"Module"}));async function Zc(t){}async function Ec(t){}const $c=Object.freeze(Object.defineProperty({__proto__:null,down:Ec,up:Zc},Symbol.toStringTag,{value:"Module"}));async function Pc(t){await t.schema.alterTable("logs").dropColumn("category").execute()}async function Ac(t){await t.schema.alterTable("logs").addColumn("category","varchar(255)",e=>e.notNull()).execute()}const Dc=Object.freeze(Object.defineProperty({__proto__:null,down:Ac,up:Pc},Symbol.toStringTag,{value:"Module"}));async function Rc(t){await t.schema.alterTable("users").dropColumn("tags").execute()}async function Mc(t){await t.schema.alterTable("users").addColumn("tags","varchar(255)").execute()}const Lc=Object.freeze(Object.defineProperty({__proto__:null,down:Mc,up:Rc},Symbol.toStringTag,{value:"Module"}));async function zc(t){await t.schema.createIndex("logs_user_id").on("logs").column("user_id").execute(),await t.schema.createIndex("logs_tenant_id").on("logs").column("tenant_id").execute(),await t.schema.createIndex("logs_date").on("logs").column("date").execute()}async function Uc(t){await t.schema.dropIndex("logs_user_id"),await t.schema.dropIndex("logs_tenant_id"),await t.schema.dropIndex("logs_date")}const Fc=Object.freeze(Object.defineProperty({__proto__:null,down:Uc,up:zc},Symbol.toStringTag,{value:"Module"}));async function Vc(t){await t.schema.alterTable("logs").dropColumn("details").execute(),await t.schema.alterTable("logs").addColumn("details","varchar(8192)").execute()}async function Bc(t){await t.schema.alterTable("logs").dropColumn("details").execute(),await t.schema.alterTable("logs").addColumn("details","varchar(2048)").execute()}const Kc=Object.freeze(Object.defineProperty({__proto__:null,down:Bc,up:Vc},Symbol.toStringTag,{value:"Module"}));async function Wc(t){await t.schema.alterTable("logs").addColumn("user_name","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("auth0_client","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("isMobile","boolean").execute(),await t.schema.alterTable("logs").addColumn("connection","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("connection_id","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("audience","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("scope","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("strategy","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("strategy_type","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("hostname","varchar(255)").execute(),await t.schema.alterTable("logs").addColumn("session_connection","varchar(255)").execute()}async function Jc(t){await t.schema.alterTable("logs").dropColumn("user_name").execute(),await t.schema.alterTable("logs").dropColumn("auth0_client").execute(),await t.schema.alterTable("logs").dropColumn("isMobile").execute(),await t.schema.alterTable("logs").dropColumn("connection").execute(),await t.schema.alterTable("logs").dropColumn("connection_id").execute(),await t.schema.alterTable("logs").dropColumn("audience").execute(),await t.schema.alterTable("logs").dropColumn("scope").execute(),await t.schema.alterTable("logs").dropColumn("strategy").execute(),await t.schema.alterTable("logs").dropColumn("strategy_type").execute(),await t.schema.alterTable("logs").dropColumn("hostname").execute(),await t.schema.alterTable("logs").dropColumn("session_connection").execute()}const qc=Object.freeze(Object.defineProperty({__proto__:null,down:Jc,up:Wc},Symbol.toStringTag,{value:"Module"}));async function Qc(t){await t.schema.createIndex("users_name_index").on("users").column("name").execute()}async function Gc(t){await t.schema.dropIndex("users_name_index").execute()}const Hc=Object.freeze(Object.defineProperty({__proto__:null,down:Gc,up:Qc},Symbol.toStringTag,{value:"Module"}));async function Yc(t){}async function Xc(t){await t.schema.alterTable("users").dropConstraint("unique_email_provider").execute()}const el=Object.freeze(Object.defineProperty({__proto__:null,down:Xc,up:Yc},Symbol.toStringTag,{value:"Module"}));async function tl(t){await t.schema.alterTable("otps").dropColumn("state").execute(),await t.schema.alterTable("otps").addColumn("state","varchar(8192)").execute()}async function nl(t){await t.schema.alterTable("otps").dropColumn("state").execute(),await t.schema.alterTable("otps").addColumn("state","varchar(1024)").execute()}const rl=Object.freeze(Object.defineProperty({__proto__:null,down:nl,up:tl},Symbol.toStringTag,{value:"Module"}));async function al(t){await t.schema.alterTable("tickets").dropColumn("state").execute(),await t.schema.alterTable("tickets").addColumn("state","varchar(8192)").execute()}async function sl(t){await t.schema.alterTable("tickets").dropColumn("state").execute(),await t.schema.alterTable("tickets").addColumn("state","varchar(1024)").execute()}const il=Object.freeze(Object.defineProperty({__proto__:null,down:sl,up:al},Symbol.toStringTag,{value:"Module"}));async function ol(t){await t.schema.createTable("branding").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull().primaryKey()).addColumn("logo_url","varchar(512)").addColumn("favicon_url","varchar(512)").addColumn("font_url","varchar(512)").addColumn("colors_primary","varchar(8)").addColumn("colors_page_background_type","varchar(32)").addColumn("colors_page_background_start","varchar(8)").addColumn("colors_page_background_end","varchar(8)").addColumn("colors_page_background_angle_dev","integer").execute()}async function dl(t){await t.schema.dropTable("branding").execute()}const cl=Object.freeze(Object.defineProperty({__proto__:null,down:dl,up:ol},Symbol.toStringTag,{value:"Module"}));async function ll(t){}async function ul(t){}const hl=Object.freeze(Object.defineProperty({__proto__:null,down:ul,up:ll},Symbol.toStringTag,{value:"Module"}));async function pl(t){}async function ml(t){}const fl=Object.freeze(Object.defineProperty({__proto__:null,down:ml,up:pl},Symbol.toStringTag,{value:"Module"}));async function _l(t){}async function gl(t){}const yl=Object.freeze(Object.defineProperty({__proto__:null,down:gl,up:_l},Symbol.toStringTag,{value:"Module"}));async function vl(t){}async function bl(t){}const wl=Object.freeze(Object.defineProperty({__proto__:null,down:bl,up:vl},Symbol.toStringTag,{value:"Module"}));async function xl(t){await t.schema.createTable("authentication_codes").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)",e=>e.notNull()).addColumn("nonce","varchar(255)").addColumn("state","varchar(8192)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}async function Nl(t){await t.schema.dropTable("authentication_codes").execute()}const kl=Object.freeze(Object.defineProperty({__proto__:null,down:Nl,up:xl},Symbol.toStringTag,{value:"Module"}));async function Tl(t){}async function Cl(t){}const Ol=Object.freeze(Object.defineProperty({__proto__:null,down:Cl,up:Tl},Symbol.toStringTag,{value:"Module"}));async function Sl(t){await t.schema.alterTable("otps").addColumn("ip","varchar(64)").execute()}async function jl(t){await t.schema.alterTable("otps").dropColumn("ip").execute()}const Il=Object.freeze(Object.defineProperty({__proto__:null,down:jl,up:Sl},Symbol.toStringTag,{value:"Module"}));async function Zl(t){await t.schema.alterTable("logs").dropColumn("user_agent").execute(),await t.schema.alterTable("logs").addColumn("user_agent","varchar(1024)").execute()}async function El(t){await t.schema.alterTable("logs").dropColumn("user_agent").execute(),await t.schema.alterTable("logs").addColumn("user_agent","varchar(255)").execute()}const $l=Object.freeze(Object.defineProperty({__proto__:null,down:El,up:Zl},Symbol.toStringTag,{value:"Module"}));async function Pl(t){}async function Al(t){}const Dl=Object.freeze(Object.defineProperty({__proto__:null,down:Al,up:Pl},Symbol.toStringTag,{value:"Module"}));async function Rl(t){await t.schema.createTable("hooks").addColumn("hook_id","varchar(255)",e=>e.notNull().primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("url","varchar(512)",e=>e.notNull()).addColumn("trigger_id","varchar(255)",e=>e.notNull()).addColumn("enabled","boolean",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).addColumn("synchronous","boolean",e=>e.defaultTo(!1).notNull()).addColumn("priority","integer").execute()}async function Ml(t){await t.schema.dropTable("hooks").execute()}const Ll=Object.freeze(Object.defineProperty({__proto__:null,down:Ml,up:Rl},Symbol.toStringTag,{value:"Module"}));async function zl(t){}async function Ul(t){}const Fl=Object.freeze(Object.defineProperty({__proto__:null,down:Ul,up:zl},Symbol.toStringTag,{value:"Module"}));async function Vl(t){}async function Bl(t){}const Kl=Object.freeze(Object.defineProperty({__proto__:null,down:Bl,up:Vl},Symbol.toStringTag,{value:"Module"}));async function Wl(t){await t.schema.createTable("logins").addColumn("login_id","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("authParams_client_id","varchar(255)",e=>e.notNull()).addColumn("authParams_vendor_id","varchar(255)").addColumn("authParams_username","varchar(255)").addColumn("authParams_response_type","varchar(255)").addColumn("authParams_response_mode","varchar(255)").addColumn("authParams_audience","varchar(255)").addColumn("authParams_scope","varchar(511)").addColumn("authParams_state","varchar(511)").addColumn("authParams_code_challenge_method","varchar(256)").addColumn("authParams_code_challenge","varchar(256)").addColumn("authParams_redirect_uri","varchar(256)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("updated_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).execute(),await t.schema.alterTable("passwords").addColumn("algorithm","varchar(16)").execute(),await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("code_id","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)").addColumn("login_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("code_type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}async function Jl(t){await t.schema.dropTable("logins").execute(),await t.schema.alterTable("passwords").dropColumn("algorithm").execute(),await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("code","varchar(255)",e=>e.notNull()).addColumn("user_id","varchar(255)").addColumn("tenant_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}const ql=Object.freeze(Object.defineProperty({__proto__:null,down:Jl,up:Wl},Symbol.toStringTag,{value:"Module"}));async function Ql(t){}async function Gl(t){}const Hl=Object.freeze(Object.defineProperty({__proto__:null,down:Gl,up:Ql},Symbol.toStringTag,{value:"Module"}));async function Yl(t){await t.schema.alterTable("logins").addColumn("auth0Client","varchar(256)").execute()}async function Xl(t){await t.schema.alterTable("logins").dropColumn("auth0Client").execute()}const eu=Object.freeze(Object.defineProperty({__proto__:null,down:Xl,up:Yl},Symbol.toStringTag,{value:"Module"}));async function tu(t){await t.schema.alterTable("logins").dropColumn("authParams_state").execute(),await t.schema.alterTable("logins").addColumn("authParams_state","varchar(8192)").execute()}async function nu(t){await t.schema.alterTable("logins").dropColumn("authParams_state").execute(),await t.schema.alterTable("logins").addColumn("authParams_state","varchar(511)").execute()}const ru=Object.freeze(Object.defineProperty({__proto__:null,down:nu,up:tu},Symbol.toStringTag,{value:"Module"}));async function au(t){}async function su(t){}const iu=Object.freeze(Object.defineProperty({__proto__:null,down:su,up:au},Symbol.toStringTag,{value:"Module"}));async function ou(t){}async function du(t){}const cu=Object.freeze(Object.defineProperty({__proto__:null,down:du,up:ou},Symbol.toStringTag,{value:"Module"}));async function lu(t){await t.schema.alterTable("logins").addColumn("authParams_nonce","varchar(255)").execute()}async function uu(t){await t.schema.alterTable("logins").dropColumn("nonce").execute()}const hu=Object.freeze(Object.defineProperty({__proto__:null,down:uu,up:lu},Symbol.toStringTag,{value:"Module"}));async function pu(t){}async function mu(t){}const fu=Object.freeze(Object.defineProperty({__proto__:null,down:mu,up:pu},Symbol.toStringTag,{value:"Module"}));async function _u(t){}async function gu(t){}const yu=Object.freeze(Object.defineProperty({__proto__:null,down:gu,up:_u},Symbol.toStringTag,{value:"Module"}));async function vu(t){await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("code_id","varchar(255)",e=>e.notNull()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)").addColumn("login_id","varchar(255)").addColumn("connection_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("code_type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").addPrimaryKeyConstraint("PK_codes_code_id_code_type",["code_id","code_type"]).execute()}async function bu(t){await t.schema.dropTable("codes").execute(),await t.schema.createTable("codes").addColumn("code_id","varchar(255)",e=>e.primaryKey()).addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)").addColumn("connection_id","varchar(255)").addColumn("login_id","varchar(255)").addForeignKeyConstraint("codes_user_id_tenant_id_constraint",["user_id","tenant_id"],"users",["user_id","tenant_id"],e=>e.onDelete("cascade")).addColumn("code_type","varchar(255)",e=>e.notNull()).addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}const wu=Object.freeze(Object.defineProperty({__proto__:null,down:bu,up:vu},Symbol.toStringTag,{value:"Module"}));async function xu(t){await t.schema.dropTable("otps").execute(),await t.schema.dropTable("authentication_codes").execute()}async function Nu(t){await t.schema.alterTable("keys").addColumn("private_key","varchar(2048)").addColumn("public_key","varchar(2048)").execute(),await t.schema.createTable("otps").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("id","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.notNull()).addColumn("email","varchar(255)",e=>e.notNull()).addColumn("user_id","varchar(255)").addColumn("send","varchar(255)").addColumn("nonce","varchar(255)").addColumn("state","varchar(1024)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute(),await t.schema.createTable("authentication_codes").addColumn("tenant_id","varchar(255)",e=>e.references("tenants.id").onDelete("cascade").notNull()).addColumn("code","varchar(255)",e=>e.primaryKey()).addColumn("client_id","varchar(255)",e=>e.references("applications.id").onDelete("cascade").notNull()).addColumn("user_id","varchar(255)",e=>e.notNull()).addColumn("nonce","varchar(255)").addColumn("state","varchar(8192)").addColumn("scope","varchar(1024)").addColumn("response_type","varchar(256)").addColumn("response_mode","varchar(256)").addColumn("redirect_uri","varchar(1024)").addColumn("created_at","varchar(255)",e=>e.notNull()).addColumn("expires_at","varchar(255)",e=>e.notNull()).addColumn("used_at","varchar(255)").execute()}const ku=Object.freeze(Object.defineProperty({__proto__:null,down:Nu,up:xu},Symbol.toStringTag,{value:"Module"}));async function Tu(t){await t.schema.createIndex("IDX_logs_tenant_date_type_user").on("logs").columns(["tenant_id","date","type","user_id"]).execute()}async function Cu(t){await t.schema.dropIndex("IDX_logs_tenant_date_type_user").on("logs").execute()}const Ou=Object.freeze(Object.defineProperty({__proto__:null,down:Cu,up:Tu},Symbol.toStringTag,{value:"Module"}));async function Su(t){}async function ju(t){}const Iu=Object.freeze(Object.defineProperty({__proto__:null,down:ju,up:Su},Symbol.toStringTag,{value:"Module"}));async function Zu(t){await t.schema.createTable("prompt_settings").addColumn("tenant_id","varchar(64)",e=>e.primaryKey()).addColumn("universal_login_experience","varchar(16)",e=>e.defaultTo("new").notNull()).addColumn("identifier_first","boolean",e=>e.defaultTo(!0).notNull()).addColumn("password_first","boolean",e=>e.defaultTo(!1).notNull()).addColumn("webauthn_platform_first_factor","boolean",e=>e.defaultTo(!1).notNull()).execute()}async function Eu(t){await t.schema.dropTable("prompt_settings").execute()}const $u=Object.freeze(Object.defineProperty({__proto__:null,down:Eu,up:Zu},Symbol.toStringTag,{value:"Module"}));async function Pu(t){}async function Au(t){}const Du=Object.freeze(Object.defineProperty({__proto__:null,down:Au,up:Pu},Symbol.toStringTag,{value:"Module"}));async function Ru(t){}async function Mu(t){}const Lu=Object.freeze(Object.defineProperty({__proto__:null,down:Mu,up:Ru},Symbol.toStringTag,{value:"Module"}));async function zu(t){}async function Uu(t){}const Fu=Object.freeze(Object.defineProperty({__proto__:null,down:Uu,up:zu},Symbol.toStringTag,{value:"Module"}));async function Vu(t){await t.schema.alterTable("logins").addColumn("authParams_ui_locales","varchar(32)").execute()}async function Bu(t){await t.schema.alterTable("logins").dropColumn("authParams_ui_locales").execute()}const Ku=Object.freeze(Object.defineProperty({__proto__:null,down:Bu,up:Vu},Symbol.toStringTag,{value:"Module"}));async function Wu(t){await t.schema.alterTable("logins").addColumn("authParams_prompt","varchar(16)").execute()}async function Ju(t){await t.schema.alterTable("logins").dropColumn("authParams_prompt").execute()}const qu=Object.freeze(Object.defineProperty({__proto__:null,down:Ju,up:Wu},Symbol.toStringTag,{value:"Module"}));async function Qu(t){}async function Gu(t){}const Hu=Object.freeze(Object.defineProperty({__proto__:null,down:Gu,up:Qu},Symbol.toStringTag,{value:"Module"}));async function Yu(t){await t.schema.alterTable("logins").addColumn("authParams_act_as","varchar(255)").execute()}async function Xu(t){await t.schema.alterTable("logins").dropColumn("authParam_act_as").execute()}const eh=Object.freeze(Object.defineProperty({__proto__:null,down:Xu,up:Yu},Symbol.toStringTag,{value:"Module"})),Qr={m1_init:Od,m2_magicLink:Id,m3_updateAt:$d,m4_logTable:Dd,m5_userProfile:Ld,m6_sessions:Fd,m7_passwords:Kd,m8_logsTableNewFields:qd,m9_passwordTableNewField:Hd,n01_codesTable:ec,n11_universalLoginSession:rc,n12_userFields:ic,n13_userEmailIndex:cc,n14_profileDataField:hc,n15_userEmailIndex:fc,n16_userLocale:yc,n17_signingKeys:wc,n18_logsFields:kc,n19_connectionsUserinfo:Oc,n20_missingFields:Ic,n21_sessionDeletedAt:$c,n22_dropLogsFields:Dc,n23_dropUsersFields:Lc,n24_logsIndexes:Fc,n25_logDescMaxLength:Kc,n26_logsTableExtraFields:qc,n27_usersTableNameIndex:Hc,n28_usersEmailConstrain:el,n29_increaseOtpStateLength:rl,n30_increaseTicketStateLength:il,n31_branding:cl,n32_indexesAndNotNull:hl,n33_vendorIdInUniversalLoginSession:fl,n34_auth0ClientInUniversalLoginSession:yl,n35_increaseUniversalSessionStateLength:wl,n36_authenticationCodes:kl,n37_disableSignUps:Ol,n38_otpIpAddress:Il,n39_increaseUserAgentLength:$l,n40_userId:Dl,n41_hooks:Ll,n42_userIdIndexes:Fl,n43_userIdIndexes:Kl,n44_codes:ql,n45_hookProperties:Hl,n46_loginAuth0Client:eu,n47_loginAuth0Client:ru,n48_saml:iu,n49_removeFields:cu,n50_authParamsNonce:hu,n51_connectionid:fu,n52_cert:yu,n53_codes_primary_key:wu,n54_cleanup_tables:ku,n55_logs_index:Ou,n56_application_fields:Iu,n57_prompt_settings:$u,n58_connection_client_id:Du,n59_connection_options:Lu,n60_users_metadata:Fu,n61_userLocales:Ku,n62_prompt:qu,n63_connection_cleanup:Hu,n64_act_as:eh};async function th(t,e=!1){e&&console.log("migrating...");const n=new qr(Qr),r=new $r({db:t,provider:n}),{error:a,results:s}=await r.migrateToLatest();if(s==null||s.forEach(o=>{o.status==="Success"?e&&console.log(`migration "${o.migrationName}" was executed successfully`):o.status==="Error"&&console.error(`failed to execute migration "${o.migrationName}"`)}),a)throw console.error("failed to migrate"),console.error(a),a}async function nh(t){console.log("migrating...");const e=new qr(Qr),n=new $r({db:t,provider:e}),{error:r,results:a}=await n.migrateDown();if(a==null||a.forEach(s=>{s.status==="Success"?console.log(`migration "${s.migrationName}" was reverted successfully`):s.status==="Error"&&console.error(`failed to execute migration "${s.migrationName}"`)}),r)throw console.error("failed to migrate"),console.error(r),r}function rh(t){return{applications:Ti(t),branding:Qo(t),clients:Lo(t),codes:vi(t),connections:Mo(t),domains:Wo(t),hooks:td(t),keys:Vo(t),logins:ud(t),logs:ei(t),passwords:mi(t),promptSettings:md(t),users:Fs(t),sessions:ii(t),tenants:Qs(t),themes:id(t),tickets:li(t)}}exports.default=rh;exports.migrateDown=nh;exports.migrateToLatest=th;