barejs 0.1.54 → 0.1.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,69 +1,118 @@
1
1
  // @bun
2
- var{defineProperty:ks,getOwnPropertyNames:yu,getOwnPropertyDescriptor:gu}=Object,hu=Object.prototype.hasOwnProperty;function xu(e){return this[e]}var Iu=(e)=>{var t=($i??=new WeakMap).get(e),r;if(t)return t;if(t=ks({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of yu(e))if(!hu.call(t,n))ks(t,n,{get:xu.bind(e,n),enumerable:!(r=gu(e,n))||r.enumerable})}return $i.set(e,t),t},$i;var bu=(e)=>e;function Ru(e,t){this[e]=bu.bind(null,t)}var Ps=(e,t)=>{for(var r in t)ks(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Ru.bind(t,r)})};var _u=(e,t,r)=>()=>{if(e)try{t=e(e=0)}catch(n){r=[n]}if(r)throw r[0];return t};var eu={};Ps(eu,{BARE_CONFIG:()=>Xn,initConfig:()=>bs});var yi,Xn,bs=(e={})=>(Xn={...yi,...e,hash:{...yi.hash,...e.hash}},Xn);var Rs=_u(()=>{yi={hash:{algorithm:"argon2id",memoryCost:65536,timeCost:2},port:3000},Xn=yi});var us={};Ps(us,{BRAND:()=>Xl,DIRTY:()=>tn,EMPTY_PATH:()=>Pl,INVALID:()=>L,NEVER:()=>My,OK:()=>tt,ParseStatus:()=>We,Schema:()=>W,ZodAny:()=>nn,ZodArray:()=>qt,ZodBigInt:()=>Mr,ZodBoolean:()=>Nn,ZodBranded:()=>cs,ZodCatch:()=>Dn,ZodDate:()=>rn,ZodDefault:()=>vn,ZodDiscriminatedUnion:()=>as,ZodEffects:()=>zt,ZodEnum:()=>jr,ZodError:()=>mt,ZodFirstPartyTypeKind:()=>K,ZodFunction:()=>Fn,ZodIntersection:()=>Un,ZodIssueCode:()=>R,ZodLazy:()=>Ln,ZodLiteral:()=>Kn,ZodMap:()=>Io,ZodNaN:()=>bo,ZodNativeEnum:()=>Bn,ZodNever:()=>tr,ZodNull:()=>jn,ZodNullable:()=>hr,ZodNumber:()=>Nr,ZodObject:()=>Pe,ZodOptional:()=>Gt,ZodParsedType:()=>C,ZodPipeline:()=>Ro,ZodPromise:()=>sn,ZodReadonly:()=>qn,ZodRecord:()=>xo,ZodSchema:()=>W,ZodSet:()=>on,ZodString:()=>Dt,ZodSymbol:()=>go,ZodTransformer:()=>zt,ZodTuple:()=>rr,ZodType:()=>W,ZodUndefined:()=>Mn,ZodUnion:()=>En,ZodUnknown:()=>Fr,ZodVoid:()=>ho,addIssueToContext:()=>w,any:()=>sy,array:()=>uy,bigint:()=>ey,boolean:()=>rc,coerce:()=>Ny,custom:()=>Za,date:()=>ty,datetimeRegex:()=>Ya,defaultErrorMap:()=>yr,discriminatedUnion:()=>py,effect:()=>$y,enum:()=>_y,function:()=>Iy,getErrorMap:()=>Cn,getParsedType:()=>er,instanceof:()=>Ql,intersection:()=>ly,isAborted:()=>ss,isAsync:()=>An,isDirty:()=>is,isValid:()=>Tr,late:()=>Yl,lazy:()=>by,literal:()=>Ry,makeIssue:()=>yo,map:()=>hy,nan:()=>Zl,nativeEnum:()=>Oy,never:()=>ay,null:()=>oy,nullable:()=>ky,number:()=>tc,object:()=>dy,objectUtil:()=>oi,oboolean:()=>Fy,onumber:()=>Ty,optional:()=>Sy,ostring:()=>Ay,pipeline:()=>Cy,preprocess:()=>Py,promise:()=>wy,quotelessJson:()=>$l,record:()=>gy,set:()=>xy,setErrorMap:()=>kl,strictObject:()=>fy,string:()=>ec,symbol:()=>ry,transformer:()=>$y,tuple:()=>yy,undefined:()=>ny,union:()=>my,unknown:()=>iy,util:()=>Q,void:()=>cy});var li={};Ps(li,{Any:()=>Sr,Argument:()=>dc,Array:()=>ln,AsyncIterator:()=>yn,Awaited:()=>Hn,BigInt:()=>bn,Boolean:()=>Go,Capitalize:()=>kc,Composite:()=>mc,Const:()=>pc,Constructor:()=>gn,ConstructorParameters:()=>lc,Date:()=>ds,Enum:()=>yc,Exclude:()=>zn,Extends:()=>Pn,Extract:()=>Vn,Function:()=>Qt,Index:()=>wr,InstanceType:()=>bc,Instantiate:()=>_c,Integer:()=>Oc,Intersect:()=>Qe,Iterator:()=>Rn,KeyOf:()=>_n,Literal:()=>se,Lowercase:()=>Pc,Mapped:()=>sa,Module:()=>qc,Never:()=>J,Not:()=>Gc,Null:()=>fs,Number:()=>_t,Object:()=>ae,Omit:()=>Er,Optional:()=>Ye,Parameters:()=>Hc,Partial:()=>Jn,Pick:()=>Ur,Promise:()=>Vo,Readonly:()=>ut,ReadonlyOptional:()=>gs,Record:()=>hs,Recursive:()=>zc,Ref:()=>$t,RegExp:()=>Vc,Required:()=>Wn,Rest:()=>Jc,ReturnType:()=>Wc,String:()=>Et,Symbol:()=>ms,TemplateLiteral:()=>zo,Transform:()=>Qc,Tuple:()=>Ot,Uint8Array:()=>ls,Uncapitalize:()=>Cc,Undefined:()=>ps,Union:()=>ie,Unknown:()=>kr,Unsafe:()=>Ni,Uppercase:()=>Ac,Void:()=>Zc});function Co(e){return it(e)&&globalThis.Symbol.asyncIterator in e}function Ao(e){return it(e)&&globalThis.Symbol.iterator in e}function To(e){return e instanceof globalThis.Promise}function fn(e){return e instanceof Date&&globalThis.Number.isFinite(e.getTime())}function mn(e){return e instanceof globalThis.Uint8Array}function Fo(e,t){return t in e}function it(e){return e!==null&&typeof e==="object"}function Ee(e){return globalThis.Array.isArray(e)&&!globalThis.ArrayBuffer.isView(e)}function nt(e){return e===void 0}function Lr(e){return e===null}function Kr(e){return typeof e==="boolean"}function H(e){return typeof e==="number"}function No(e){return globalThis.Number.isInteger(e)}function lt(e){return typeof e==="bigint"}function De(e){return typeof e==="string"}function Mo(e){return typeof e==="function"}function Br(e){return typeof e==="symbol"}function jo(e){return lt(e)||Kr(e)||Lr(e)||H(e)||De(e)||Br(e)||nt(e)}var le;(function(e){e.InstanceMode="default",e.ExactOptionalPropertyTypes=!1,e.AllowArrayObject=!1,e.AllowNaN=!1,e.AllowNullVoid=!1;function t(i,a){return e.ExactOptionalPropertyTypes?a in i:i[a]!==void 0}e.IsExactOptionalProperty=t;function r(i){let a=it(i);return e.AllowArrayObject?a:a&&!Ee(i)}e.IsObjectLike=r;function n(i){return r(i)&&!(i instanceof Date)&&!(i instanceof Uint8Array)}e.IsRecordLike=n;function o(i){return e.AllowNaN?H(i):Number.isFinite(i)}e.IsNumberLike=o;function s(i){let a=nt(i);return e.AllowNullVoid?a||i===null:a}e.IsVoidLike=s})(le||(le={}));var Si=new Map;function Cs(e){return Si.has(e)}function As(e){return Si.get(e)}var ki=new Map;function Qn(e){return ki.has(e)}function Ts(e){return ki.get(e)}function Pi(e){return xe(e)&&!Ue(e)&&!br(e)&&Symbol.asyncIterator in e}function Ue(e){return Array.isArray(e)}function Lo(e){return typeof e==="bigint"}function Ir(e){return typeof e==="boolean"}function pn(e){return e instanceof globalThis.Date}function Ci(e){return typeof e==="function"}function Ai(e){return xe(e)&&!Ue(e)&&!br(e)&&Symbol.iterator in e}function Ti(e){return e===null}function yt(e){return typeof e==="number"}function xe(e){return typeof e==="object"&&e!==null}function Ko(e){return e instanceof globalThis.RegExp}function ye(e){return typeof e==="string"}function Fi(e){return typeof e==="symbol"}function br(e){return e instanceof globalThis.Uint8Array}function ge(e){return e===void 0}function Ou(e){return globalThis.Object.freeze(e).map((t)=>Zn(t))}function wu(e){return e}function $u(e){return e}function Su(e){return e}function ku(e){let t={};for(let r of Object.getOwnPropertyNames(e))t[r]=Zn(e[r]);for(let r of Object.getOwnPropertySymbols(e))t[r]=Zn(e[r]);return globalThis.Object.freeze(t)}function Zn(e){return Ue(e)?Ou(e):pn(e)?wu(e):br(e)?$u(e):Ko(e)?Su(e):xe(e)?ku(e):e}function Pu(e){return e.map((t)=>Bo(t))}function Cu(e){return new Date(e.getTime())}function Au(e){return new Uint8Array(e)}function Tu(e){return new RegExp(e.source,e.flags)}function Fu(e){let t={};for(let r of Object.getOwnPropertyNames(e))t[r]=Bo(e[r]);for(let r of Object.getOwnPropertySymbols(e))t[r]=Bo(e[r]);return t}function Bo(e){return Ue(e)?Pu(e):pn(e)?Cu(e):br(e)?Au(e):Ko(e)?Tu(e):xe(e)?Fu(e):e}function Ie(e){return Bo(e)}function h(e,t){let r=t!==void 0?{...t,...e}:e;switch(le.InstanceMode){case"freeze":return Zn(r);case"clone":return Ie(r);default:return r}}var Re=Symbol.for("TypeBox.Transform"),Xt=Symbol.for("TypeBox.Readonly"),ze=Symbol.for("TypeBox.Optional"),Yt=Symbol.for("TypeBox.Hint"),I=Symbol.for("TypeBox.Kind");function Ni(e={}){return h({[I]:e[I]??"Unsafe"},e)}class oe extends Error{constructor(e){super(e)}}function re(e){return h({[I]:"MappedResult",properties:e})}function Nu(e,t){let{[t]:r,...n}=e;return n}function $e(e,t){return t.reduce((r,n)=>Nu(r,n),e)}function ln(e,t){return h({[I]:"Array",type:"array",items:e},t)}function yn(e,t){return h({[I]:"AsyncIterator",type:"AsyncIterator",items:e},t)}function gn(e,t,r){return h({[I]:"Constructor",type:"Constructor",parameters:e,returns:t},r)}function Qt(e,t,r){return h({[I]:"Function",type:"Function",parameters:e,returns:t},r)}function he(e,t,r){return h({[I]:"Computed",target:e,parameters:t},r)}function J(e){return h({[I]:"Never",not:{}},e)}function hn(e){return xe(e)&&e[Xt]==="Readonly"}function at(e){return xe(e)&&e[ze]==="Optional"}function Fs(e){return Z(e,"Any")}function Ns(e){return Z(e,"Argument")}function At(e){return Z(e,"Array")}function Dr(e){return Z(e,"AsyncIterator")}function qr(e){return Z(e,"BigInt")}function or(e){return Z(e,"Boolean")}function Tt(e){return Z(e,"Computed")}function Ft(e){return Z(e,"Constructor")}function Mu(e){return Z(e,"Date")}function Nt(e){return Z(e,"Function")}function Mt(e){return Z(e,"Integer")}function Se(e){return Z(e,"Intersect")}function Gr(e){return Z(e,"Iterator")}function Z(e,t){return xe(e)&&I in e&&e[I]===t}function vo(e){return Ir(e)||yt(e)||ye(e)}function gt(e){return Z(e,"Literal")}function ht(e){return Z(e,"MappedKey")}function be(e){return Z(e,"MappedResult")}function Rr(e){return Z(e,"Never")}function ju(e){return Z(e,"Not")}function eo(e){return Z(e,"Null")}function jt(e){return Z(e,"Number")}function Ne(e){return Z(e,"Object")}function Hr(e){return Z(e,"Promise")}function zr(e){return Z(e,"Record")}function Fe(e){return Z(e,"Ref")}function Ms(e){return Z(e,"RegExp")}function sr(e){return Z(e,"String")}function to(e){return Z(e,"Symbol")}function xt(e){return Z(e,"TemplateLiteral")}function Eu(e){return Z(e,"This")}function ne(e){return xe(e)&&Re in e}function It(e){return Z(e,"Tuple")}function ir(e){return Z(e,"Undefined")}function te(e){return Z(e,"Union")}function Uu(e){return Z(e,"Uint8Array")}function Lu(e){return Z(e,"Unknown")}function Ku(e){return Z(e,"Unsafe")}function Bu(e){return Z(e,"Void")}function vu(e){return xe(e)&&I in e&&ye(e[I])}function _e(e){return Fs(e)||Ns(e)||At(e)||or(e)||qr(e)||Dr(e)||Tt(e)||Ft(e)||Mu(e)||Nt(e)||Mt(e)||Se(e)||Gr(e)||gt(e)||ht(e)||be(e)||Rr(e)||ju(e)||eo(e)||jt(e)||Ne(e)||Hr(e)||zr(e)||Fe(e)||Ms(e)||sr(e)||to(e)||xt(e)||Eu(e)||It(e)||ir(e)||te(e)||Uu(e)||Lu(e)||Ku(e)||Bu(e)||vu(e)}function Du(e){return h($e(e,[ze]))}function qu(e){return h({...e,[ze]:"Optional"})}function Gu(e,t){return t===!1?Du(e):qu(e)}function Ye(e,t){let r=t??!0;return be(e)?Mi(e,r):Gu(e,r)}function Hu(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=Ye(e[n],t);return r}function zu(e,t){return Hu(e.properties,t)}function Mi(e,t){let r=zu(e,t);return re(r)}function ro(e,t={}){let r=e.every((o)=>Ne(o)),n=_e(t.unevaluatedProperties)?{unevaluatedProperties:t.unevaluatedProperties}:{};return h(t.unevaluatedProperties===!1||_e(t.unevaluatedProperties)||r?{...n,[I]:"Intersect",type:"object",allOf:e}:{...n,[I]:"Intersect",allOf:e},t)}function Vu(e){return e.every((t)=>at(t))}function Ju(e){return $e(e,[ze])}function ji(e){return e.map((t)=>at(t)?Ju(t):t)}function Wu(e,t){return Vu(e)?Ye(ro(ji(e),t)):ro(ji(e),t)}function Do(e,t={}){if(e.length===1)return h(e[0],t);if(e.length===0)return J(t);if(e.some((r)=>ne(r)))throw Error("Cannot intersect transform types");return Wu(e,t)}function Qe(e,t){if(e.length===1)return h(e[0],t);if(e.length===0)return J(t);if(e.some((r)=>ne(r)))throw Error("Cannot intersect transform types");return ro(e,t)}function no(e,t){return h({[I]:"Union",anyOf:e},t)}function Xu(e){return e.some((t)=>at(t))}function Ei(e){return e.map((t)=>at(t)?Yu(t):t)}function Yu(e){return $e(e,[ze])}function Qu(e,t){return Xu(e)?Ye(no(Ei(e),t)):no(Ei(e),t)}function Zt(e,t){return e.length===1?h(e[0],t):e.length===0?J(t):Qu(e,t)}function ie(e,t){return e.length===0?J(t):e.length===1?h(e[0],t):no(e,t)}class js extends oe{}function Zu(e){return e.replace(/\\\$/g,"$").replace(/\\\*/g,"*").replace(/\\\^/g,"^").replace(/\\\|/g,"|").replace(/\\\(/g,"(").replace(/\\\)/g,")")}function Es(e,t,r){return e[t]===r&&e.charCodeAt(t-1)!==92}function cr(e,t){return Es(e,t,"(")}function oo(e,t){return Es(e,t,")")}function Ui(e,t){return Es(e,t,"|")}function ed(e){if(!(cr(e,0)&&oo(e,e.length-1)))return!1;let t=0;for(let r=0;r<e.length;r++){if(cr(e,r))t+=1;if(oo(e,r))t-=1;if(t===0&&r!==e.length-1)return!1}return!0}function td(e){return e.slice(1,e.length-1)}function rd(e){let t=0;for(let r=0;r<e.length;r++){if(cr(e,r))t+=1;if(oo(e,r))t-=1;if(Ui(e,r)&&t===0)return!0}return!1}function nd(e){for(let t=0;t<e.length;t++)if(cr(e,t))return!0;return!1}function od(e){let[t,r]=[0,0],n=[];for(let s=0;s<e.length;s++){if(cr(e,s))t+=1;if(oo(e,s))t-=1;if(Ui(e,s)&&t===0){let i=e.slice(r,s);if(i.length>0)n.push(xn(i));r=s+1}}let o=e.slice(r);if(o.length>0)n.push(xn(o));if(n.length===0)return{type:"const",const:""};if(n.length===1)return n[0];return{type:"or",expr:n}}function sd(e){function t(o,s){if(!cr(o,s))throw new js("TemplateLiteralParser: Index must point to open parens");let i=0;for(let a=s;a<o.length;a++){if(cr(o,a))i+=1;if(oo(o,a))i-=1;if(i===0)return[s,a]}throw new js("TemplateLiteralParser: Unclosed group parens in expression")}function r(o,s){for(let i=s;i<o.length;i++)if(cr(o,i))return[s,i];return[s,o.length]}let n=[];for(let o=0;o<e.length;o++)if(cr(e,o)){let[s,i]=t(e,o),a=e.slice(s,i+1);n.push(xn(a)),o=i}else{let[s,i]=r(e,o),a=e.slice(s,i);if(a.length>0)n.push(xn(a));o=i-1}return n.length===0?{type:"const",const:""}:n.length===1?n[0]:{type:"and",expr:n}}function xn(e){return ed(e)?xn(td(e)):rd(e)?od(e):nd(e)?sd(e):{type:"const",const:Zu(e)}}function In(e){return xn(e.slice(1,e.length-1))}class Li extends oe{}function id(e){return e.type==="or"&&e.expr.length===2&&e.expr[0].type==="const"&&e.expr[0].const==="0"&&e.expr[1].type==="const"&&e.expr[1].const==="[1-9][0-9]*"}function ad(e){return e.type==="or"&&e.expr.length===2&&e.expr[0].type==="const"&&e.expr[0].const==="true"&&e.expr[1].type==="const"&&e.expr[1].const==="false"}function cd(e){return e.type==="const"&&e.const===".*"}function Vr(e){return id(e)||cd(e)?!1:ad(e)?!0:e.type==="and"?e.expr.every((t)=>Vr(t)):e.type==="or"?e.expr.every((t)=>Vr(t)):e.type==="const"?!0:(()=>{throw new Li("Unknown expression type")})()}function Ki(e){let t=In(e.pattern);return Vr(t)}class Bi extends oe{}function*vi(e){if(e.length===1)return yield*e[0];for(let t of e[0])for(let r of vi(e.slice(1)))yield`${t}${r}`}function*ud(e){return yield*vi(e.expr.map((t)=>[...so(t)]))}function*dd(e){for(let t of e.expr)yield*so(t)}function*fd(e){return yield e.const}function*so(e){return e.type==="and"?yield*ud(e):e.type==="or"?yield*dd(e):e.type==="const"?yield*fd(e):(()=>{throw new Bi("Unknown expression")})()}function qo(e){let t=In(e.pattern);return Vr(t)?[...so(t)]:[]}function se(e,t){return h({[I]:"Literal",const:e,type:typeof e},t)}function Go(e){return h({[I]:"Boolean",type:"boolean"},e)}function bn(e){return h({[I]:"BigInt",type:"bigint"},e)}function _t(e){return h({[I]:"Number",type:"number"},e)}function Et(e){return h({[I]:"String",type:"string"},e)}function*md(e){let t=e.trim().replace(/"|'/g,"");return t==="boolean"?yield Go():t==="number"?yield _t():t==="bigint"?yield bn():t==="string"?yield Et():yield(()=>{let r=t.split("|").map((n)=>se(n.trim()));return r.length===0?J():r.length===1?r[0]:Zt(r)})()}function*pd(e){if(e[1]!=="{"){let t=se("$"),r=Us(e.slice(1));return yield*[t,...r]}for(let t=2;t<e.length;t++)if(e[t]==="}"){let r=md(e.slice(2,t)),n=Us(e.slice(t+1));return yield*[...r,...n]}yield se(e)}function*Us(e){for(let t=0;t<e.length;t++)if(e[t]==="$"){let r=se(e.slice(0,t)),n=pd(e.slice(t));return yield*[r,...n]}yield se(e)}function Di(e){return[...Us(e)]}var qi="(true|false)",Ho="(0|[1-9][0-9]*)",Gi="(.*)";var _r="^(0|[1-9][0-9]*)$",Or="^(.*)$",Hi="^(?!.*)$";class zi extends oe{}function ld(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Vi(e,t){return xt(e)?e.pattern.slice(1,e.pattern.length-1):te(e)?`(${e.anyOf.map((r)=>Vi(r,t)).join("|")})`:jt(e)?`${t}${Ho}`:Mt(e)?`${t}${Ho}`:qr(e)?`${t}${Ho}`:sr(e)?`${t}${Gi}`:gt(e)?`${t}${ld(e.const.toString())}`:or(e)?`${t}${qi}`:(()=>{throw new zi(`Unexpected Kind '${e[I]}'`)})()}function Ls(e){return`^${e.map((t)=>Vi(t,"")).join("")}$`}function Jr(e){let r=qo(e).map((n)=>se(n));return Zt(r)}function zo(e,t){let r=ye(e)?Ls(Di(e)):Ls(e);return h({[I]:"TemplateLiteral",type:"string",pattern:r},t)}function yd(e){return qo(e).map((r)=>r.toString())}function gd(e){let t=[];for(let r of e)t.push(...ct(r));return t}function hd(e){return[e.toString()]}function ct(e){return[...new Set(xt(e)?yd(e):te(e)?gd(e.anyOf):gt(e)?hd(e.const):jt(e)?["[number]"]:Mt(e)?["[number]"]:[])]}function xd(e,t,r){let n={};for(let o of Object.getOwnPropertyNames(t))n[o]=wr(e,ct(t[o]),r);return n}function Id(e,t,r){return xd(e,t.properties,r)}function Ji(e,t,r){let n=Id(e,t,r);return re(n)}function Xi(e,t){return e.map((r)=>Yi(r,t))}function bd(e){return e.filter((t)=>!Rr(t))}function Rd(e,t){return Do(bd(Xi(e,t)))}function _d(e){return e.some((t)=>Rr(t))?[]:e}function Od(e,t){return Zt(_d(Xi(e,t)))}function wd(e,t){return t in e?e[t]:t==="[number]"?Zt(e):J()}function $d(e,t){return t==="[number]"?e:J()}function Sd(e,t){return t in e?e[t]:J()}function Yi(e,t){return Se(e)?Rd(e.allOf,t):te(e)?Od(e.anyOf,t):It(e)?wd(e.items??[],t):At(e)?$d(e.items,t):Ne(e)?Sd(e.properties,t):J()}function io(e,t){return t.map((r)=>Yi(e,r))}function Wi(e,t){return Zt(io(e,t))}function wr(e,t,r){if(Fe(e)||Fe(t)){if(!_e(e)||!_e(t))throw new oe("Index types using Ref parameters require both Type and Key to be of TSchema");return he("Index",[e,t])}if(be(t))return Ji(e,t,r);if(ht(t))return Qi(e,t,r);return h(_e(t)?Wi(e,ct(t)):Wi(e,t),r)}function kd(e,t,r){return{[t]:wr(e,[t],Ie(r))}}function Pd(e,t,r){return t.reduce((n,o)=>({...n,...kd(e,o,r)}),{})}function Cd(e,t,r){return Pd(e,t.keys,r)}function Qi(e,t,r){let n=Cd(e,t,r);return re(n)}function Rn(e,t){return h({[I]:"Iterator",type:"Iterator",items:e},t)}function Ad(e){return globalThis.Object.keys(e).filter((t)=>!at(e[t]))}function Td(e,t){let r=Ad(e),n=r.length>0?{[I]:"Object",type:"object",required:r,properties:e}:{[I]:"Object",type:"object",properties:e};return h(n,t)}var ae=Td;function Vo(e,t){return h({[I]:"Promise",type:"Promise",item:e},t)}function Fd(e){return h($e(e,[Xt]))}function Nd(e){return h({...e,[Xt]:"Readonly"})}function Md(e,t){return t===!1?Fd(e):Nd(e)}function ut(e,t){let r=t??!0;return be(e)?Zi(e,r):Md(e,r)}function jd(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=ut(e[n],t);return r}function Ed(e,t){return jd(e.properties,t)}function Zi(e,t){let r=Ed(e,t);return re(r)}function Ot(e,t){return h(e.length>0?{[I]:"Tuple",type:"array",items:e,additionalItems:!1,minItems:e.length,maxItems:e.length}:{[I]:"Tuple",type:"array",minItems:e.length,maxItems:e.length},t)}function ea(e,t){return e.includes(t)}function ta(e){return[...new Set(e)]}function Ud(e,t){return e.filter((r)=>t.includes(r))}function Ld(e,t){return e.reduce((r,n)=>Ud(r,n),t)}function ra(e){return e.length===1?e[0]:e.length>1?Ld(e.slice(1),e[0]):[]}function na(e){let t=[];for(let r of e)t.push(...r);return t}function oa(e,t){return e in t?wt(e,t[e]):re(t)}function Kd(e){return{[e]:se(e)}}function Bd(e){let t={};for(let r of e)t[r]=se(r);return t}function vd(e,t){return ea(t,e)?Kd(e):Bd(t)}function Dd(e,t){let r=vd(e,t);return oa(e,r)}function ao(e,t){return t.map((r)=>wt(e,r))}function qd(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(t))r[n]=wt(e,t[n]);return r}function wt(e,t){let r={...t};return at(t)?Ye(wt(e,$e(t,[ze]))):hn(t)?ut(wt(e,$e(t,[Xt]))):be(t)?oa(e,t.properties):ht(t)?Dd(e,t.keys):Ft(t)?gn(ao(e,t.parameters),wt(e,t.returns),r):Nt(t)?Qt(ao(e,t.parameters),wt(e,t.returns),r):Dr(t)?yn(wt(e,t.items),r):Gr(t)?Rn(wt(e,t.items),r):Se(t)?Qe(ao(e,t.allOf),r):te(t)?ie(ao(e,t.anyOf),r):It(t)?Ot(ao(e,t.items??[]),r):Ne(t)?ae(qd(e,t.properties),r):At(t)?ln(wt(e,t.items),r):Hr(t)?Vo(wt(e,t.item),r):t}function Gd(e,t){let r={};for(let n of e)r[n]=wt(n,t);return r}function sa(e,t,r){let n=_e(e)?ct(e):e,o=t({[I]:"MappedKey",keys:n}),s=Gd(n,o);return ae(s,r)}function $t(...e){let[t,r]=typeof e[0]==="string"?[e[0],e[1]]:[e[0].$id,e[1]];if(typeof t!=="string")throw new oe("Ref: $ref must be a string");return h({[I]:"Ref",$ref:t},r)}function ia(e){let t=[];for(let r of e)t.push(St(r));return t}function Hd(e){let t=ia(e);return na(t)}function zd(e){let t=ia(e);return ra(t)}function Vd(e){return e.map((t,r)=>r.toString())}function Jd(e){return["[number]"]}function Wd(e){return globalThis.Object.getOwnPropertyNames(e)}function Xd(e){if(!Ks)return[];return globalThis.Object.getOwnPropertyNames(e).map((r)=>r[0]==="^"&&r[r.length-1]==="$"?r.slice(1,r.length-1):r)}function St(e){return Se(e)?Hd(e.allOf):te(e)?zd(e.anyOf):It(e)?Vd(e.items??[]):At(e)?Jd(e.items):Ne(e)?Wd(e.properties):zr(e)?Xd(e.patternProperties):[]}var Ks=!1;function ur(e){Ks=!0;let t=St(e);return Ks=!1,`^(${t.map((n)=>`(${n})`).join("|")})$`}function Yd(e,t){return he("KeyOf",[he(e,t)])}function Qd(e){return he("KeyOf",[$t(e)])}function Zd(e,t){let r=St(e),n=ef(r),o=Zt(n);return h(o,t)}function ef(e){return e.map((t)=>t==="[number]"?_t():se(t))}function _n(e,t){return Tt(e)?Yd(e.target,e.parameters):Fe(e)?Qd(e.$ref):be(e)?aa(e,t):Zd(e,t)}function tf(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=_n(e[n],Ie(t));return r}function rf(e,t){return tf(e.properties,t)}function aa(e,t){let r=rf(e,t);return re(r)}function Jo(e){let t=St(e),r=io(e,t);return t.map((n,o)=>[t[o],r[o]])}function nf(e){return e.allOf.every((t)=>dr(t))}function of(e){return e.anyOf.some((t)=>dr(t))}function sf(e){return!dr(e.not)}function dr(e){return e[I]==="Intersect"?nf(e):e[I]==="Union"?of(e):e[I]==="Not"?sf(e):e[I]==="Undefined"?!0:!1}function af(e){switch(e.errorType){case g.ArrayContains:return"Expected array to contain at least one matching value";case g.ArrayMaxContains:return`Expected array to contain no more than ${e.schema.maxContains} matching values`;case g.ArrayMinContains:return`Expected array to contain at least ${e.schema.minContains} matching values`;case g.ArrayMaxItems:return`Expected array length to be less or equal to ${e.schema.maxItems}`;case g.ArrayMinItems:return`Expected array length to be greater or equal to ${e.schema.minItems}`;case g.ArrayUniqueItems:return"Expected array elements to be unique";case g.Array:return"Expected array";case g.AsyncIterator:return"Expected AsyncIterator";case g.BigIntExclusiveMaximum:return`Expected bigint to be less than ${e.schema.exclusiveMaximum}`;case g.BigIntExclusiveMinimum:return`Expected bigint to be greater than ${e.schema.exclusiveMinimum}`;case g.BigIntMaximum:return`Expected bigint to be less or equal to ${e.schema.maximum}`;case g.BigIntMinimum:return`Expected bigint to be greater or equal to ${e.schema.minimum}`;case g.BigIntMultipleOf:return`Expected bigint to be a multiple of ${e.schema.multipleOf}`;case g.BigInt:return"Expected bigint";case g.Boolean:return"Expected boolean";case g.DateExclusiveMinimumTimestamp:return`Expected Date timestamp to be greater than ${e.schema.exclusiveMinimumTimestamp}`;case g.DateExclusiveMaximumTimestamp:return`Expected Date timestamp to be less than ${e.schema.exclusiveMaximumTimestamp}`;case g.DateMinimumTimestamp:return`Expected Date timestamp to be greater or equal to ${e.schema.minimumTimestamp}`;case g.DateMaximumTimestamp:return`Expected Date timestamp to be less or equal to ${e.schema.maximumTimestamp}`;case g.DateMultipleOfTimestamp:return`Expected Date timestamp to be a multiple of ${e.schema.multipleOfTimestamp}`;case g.Date:return"Expected Date";case g.Function:return"Expected function";case g.IntegerExclusiveMaximum:return`Expected integer to be less than ${e.schema.exclusiveMaximum}`;case g.IntegerExclusiveMinimum:return`Expected integer to be greater than ${e.schema.exclusiveMinimum}`;case g.IntegerMaximum:return`Expected integer to be less or equal to ${e.schema.maximum}`;case g.IntegerMinimum:return`Expected integer to be greater or equal to ${e.schema.minimum}`;case g.IntegerMultipleOf:return`Expected integer to be a multiple of ${e.schema.multipleOf}`;case g.Integer:return"Expected integer";case g.IntersectUnevaluatedProperties:return"Unexpected property";case g.Intersect:return"Expected all values to match";case g.Iterator:return"Expected Iterator";case g.Literal:return`Expected ${typeof e.schema.const==="string"?`'${e.schema.const}'`:e.schema.const}`;case g.Never:return"Never";case g.Not:return"Value should not match";case g.Null:return"Expected null";case g.NumberExclusiveMaximum:return`Expected number to be less than ${e.schema.exclusiveMaximum}`;case g.NumberExclusiveMinimum:return`Expected number to be greater than ${e.schema.exclusiveMinimum}`;case g.NumberMaximum:return`Expected number to be less or equal to ${e.schema.maximum}`;case g.NumberMinimum:return`Expected number to be greater or equal to ${e.schema.minimum}`;case g.NumberMultipleOf:return`Expected number to be a multiple of ${e.schema.multipleOf}`;case g.Number:return"Expected number";case g.Object:return"Expected object";case g.ObjectAdditionalProperties:return"Unexpected property";case g.ObjectMaxProperties:return`Expected object to have no more than ${e.schema.maxProperties} properties`;case g.ObjectMinProperties:return`Expected object to have at least ${e.schema.minProperties} properties`;case g.ObjectRequiredProperty:return"Expected required property";case g.Promise:return"Expected Promise";case g.RegExp:return"Expected string to match regular expression";case g.StringFormatUnknown:return`Unknown format '${e.schema.format}'`;case g.StringFormat:return`Expected string to match '${e.schema.format}' format`;case g.StringMaxLength:return`Expected string length less or equal to ${e.schema.maxLength}`;case g.StringMinLength:return`Expected string length greater or equal to ${e.schema.minLength}`;case g.StringPattern:return`Expected string to match '${e.schema.pattern}'`;case g.String:return"Expected string";case g.Symbol:return"Expected symbol";case g.TupleLength:return`Expected tuple to have ${e.schema.maxItems||0} elements`;case g.Tuple:return"Expected tuple";case g.Uint8ArrayMaxByteLength:return`Expected byte length less or equal to ${e.schema.maxByteLength}`;case g.Uint8ArrayMinByteLength:return`Expected byte length greater or equal to ${e.schema.minByteLength}`;case g.Uint8Array:return"Expected Uint8Array";case g.Undefined:return"Expected undefined";case g.Union:return"Expected union value";case g.Void:return"Expected void";case g.Kind:return`Expected kind '${e.schema[I]}'`;default:return"Unknown error type"}}var cf=af;function ca(){return cf}class ua extends oe{constructor(e){super(`Unable to dereference schema with $id '${e.$ref}'`);this.schema=e}}function uf(e,t){let r=t.find((n)=>n.$id===e.$ref);if(r===void 0)throw new ua(e);return qe(r,t)}function $r(e,t){if(!De(e.$id)||t.some((r)=>r.$id===e.$id))return t;return t.push(e),t}function qe(e,t){return e[I]==="This"||e[I]==="Ref"?uf(e,t):e}class da extends oe{constructor(e){super("Unable to hash value");this.value=e}}var bt;(function(e){e[e.Undefined=0]="Undefined",e[e.Null=1]="Null",e[e.Boolean=2]="Boolean",e[e.Number=3]="Number",e[e.String=4]="String",e[e.Object=5]="Object",e[e.Array=6]="Array",e[e.Date=7]="Date",e[e.Uint8Array=8]="Uint8Array",e[e.Symbol=9]="Symbol",e[e.BigInt=10]="BigInt"})(bt||(bt={}));var On=BigInt("14695981039346656037"),[df,ff]=[BigInt("1099511628211"),BigInt("18446744073709551616")],mf=Array.from({length:256}).map((e,t)=>BigInt(t)),fa=new Float64Array(1),ma=new DataView(fa.buffer),pa=new Uint8Array(fa.buffer);function*pf(e){let t=e===0?1:Math.ceil(Math.floor(Math.log2(e)+1)/8);for(let r=0;r<t;r++)yield e>>8*(t-1-r)&255}function lf(e){Ze(bt.Array);for(let t of e)wn(t)}function yf(e){Ze(bt.Boolean),Ze(e?1:0)}function gf(e){Ze(bt.BigInt),ma.setBigInt64(0,e);for(let t of pa)Ze(t)}function hf(e){Ze(bt.Date),wn(e.getTime())}function xf(e){Ze(bt.Null)}function If(e){Ze(bt.Number),ma.setFloat64(0,e);for(let t of pa)Ze(t)}function bf(e){Ze(bt.Object);for(let t of globalThis.Object.getOwnPropertyNames(e).sort())wn(t),wn(e[t])}function Rf(e){Ze(bt.String);for(let t=0;t<e.length;t++)for(let r of pf(e.charCodeAt(t)))Ze(r)}function _f(e){Ze(bt.Symbol),wn(e.description)}function Of(e){Ze(bt.Uint8Array);for(let t=0;t<e.length;t++)Ze(e[t])}function wf(e){return Ze(bt.Undefined)}function wn(e){if(Ee(e))return lf(e);if(Kr(e))return yf(e);if(lt(e))return gf(e);if(fn(e))return hf(e);if(Lr(e))return xf(e);if(H(e))return If(e);if(it(e))return bf(e);if(De(e))return Rf(e);if(Br(e))return _f(e);if(mn(e))return Of(e);if(nt(e))return wf(e);throw new da(e)}function Ze(e){On=On^mf[e],On=On*df%ff}function $n(e){return On=BigInt("14695981039346656037"),wn(e),On}function Sr(e){return h({[I]:"Any"},e)}function kr(e){return h({[I]:"Unknown"},e)}var $f=["Argument","Any","Array","AsyncIterator","BigInt","Boolean","Computed","Constructor","Date","Enum","Function","Integer","Intersect","Iterator","Literal","MappedKey","MappedResult","Not","Null","Number","Object","Promise","Record","Ref","RegExp","String","Symbol","TemplateLiteral","This","Tuple","Undefined","Union","Uint8Array","Unknown","Void"];function la(e){try{return new RegExp(e),!0}catch{return!1}}function Bs(e){if(!ye(e))return!1;for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r>=7&&r<=13||r===27||r===127)return!1}return!0}function ya(e){return vs(e)||Oe(e)}function co(e){return ge(e)||Lo(e)}function fe(e){return ge(e)||yt(e)}function vs(e){return ge(e)||Ir(e)}function ce(e){return ge(e)||ye(e)}function Sf(e){return ge(e)||ye(e)&&Bs(e)&&la(e)}function kf(e){return ge(e)||ye(e)&&Bs(e)}function ga(e){return ge(e)||Oe(e)}function Wo(e){return xe(e)&&e[ze]==="Optional"}function Ut(e){return ee(e,"Any")&&ce(e.$id)}function Pf(e){return ee(e,"Argument")&&yt(e.index)}function Wr(e){return ee(e,"Array")&&e.type==="array"&&ce(e.$id)&&Oe(e.items)&&fe(e.minItems)&&fe(e.maxItems)&&vs(e.uniqueItems)&&ga(e.contains)&&fe(e.minContains)&&fe(e.maxContains)}function Ds(e){return ee(e,"AsyncIterator")&&e.type==="AsyncIterator"&&ce(e.$id)&&Oe(e.items)}function Xo(e){return ee(e,"BigInt")&&e.type==="bigint"&&ce(e.$id)&&co(e.exclusiveMaximum)&&co(e.exclusiveMinimum)&&co(e.maximum)&&co(e.minimum)&&co(e.multipleOf)}function Xr(e){return ee(e,"Boolean")&&e.type==="boolean"&&ce(e.$id)}function Cf(e){return ee(e,"Computed")&&ye(e.target)&&Ue(e.parameters)&&e.parameters.every((t)=>Oe(t))}function Yo(e){return ee(e,"Constructor")&&e.type==="Constructor"&&ce(e.$id)&&Ue(e.parameters)&&e.parameters.every((t)=>Oe(t))&&Oe(e.returns)}function Qo(e){return ee(e,"Date")&&e.type==="Date"&&ce(e.$id)&&fe(e.exclusiveMaximumTimestamp)&&fe(e.exclusiveMinimumTimestamp)&&fe(e.maximumTimestamp)&&fe(e.minimumTimestamp)&&fe(e.multipleOfTimestamp)}function Zo(e){return ee(e,"Function")&&e.type==="Function"&&ce(e.$id)&&Ue(e.parameters)&&e.parameters.every((t)=>Oe(t))&&Oe(e.returns)}function fr(e){return ee(e,"Integer")&&e.type==="integer"&&ce(e.$id)&&fe(e.exclusiveMaximum)&&fe(e.exclusiveMinimum)&&fe(e.maximum)&&fe(e.minimum)&&fe(e.multipleOf)}function ha(e){return xe(e)&&Object.entries(e).every(([t,r])=>Bs(t)&&Oe(r))}function Yr(e){return ee(e,"Intersect")&&(ye(e.type)&&e.type!=="object"?!1:!0)&&Ue(e.allOf)&&e.allOf.every((t)=>Oe(t)&&!jf(t))&&ce(e.type)&&(vs(e.unevaluatedProperties)||ga(e.unevaluatedProperties))&&ce(e.$id)}function qs(e){return ee(e,"Iterator")&&e.type==="Iterator"&&ce(e.$id)&&Oe(e.items)}function ee(e,t){return xe(e)&&I in e&&e[I]===t}function xa(e){return Pr(e)&&ye(e.const)}function Ia(e){return Pr(e)&&yt(e.const)}function ba(e){return Pr(e)&&Ir(e.const)}function Pr(e){return ee(e,"Literal")&&ce(e.$id)&&Af(e.const)}function Af(e){return Ir(e)||yt(e)||ye(e)}function Tf(e){return ee(e,"MappedKey")&&Ue(e.keys)&&e.keys.every((t)=>yt(t)||ye(t))}function Ff(e){return ee(e,"MappedResult")&&ha(e.properties)}function Cr(e){return ee(e,"Never")&&xe(e.not)&&Object.getOwnPropertyNames(e.not).length===0}function Sn(e){return ee(e,"Not")&&Oe(e.not)}function Gs(e){return ee(e,"Null")&&e.type==="null"&&ce(e.$id)}function dt(e){return ee(e,"Number")&&e.type==="number"&&ce(e.$id)&&fe(e.exclusiveMaximum)&&fe(e.exclusiveMinimum)&&fe(e.maximum)&&fe(e.minimum)&&fe(e.multipleOf)}function ke(e){return ee(e,"Object")&&e.type==="object"&&ce(e.$id)&&ha(e.properties)&&ya(e.additionalProperties)&&fe(e.minProperties)&&fe(e.maxProperties)}function Hs(e){return ee(e,"Promise")&&e.type==="Promise"&&ce(e.$id)&&Oe(e.item)}function Ve(e){return ee(e,"Record")&&e.type==="object"&&ce(e.$id)&&ya(e.additionalProperties)&&xe(e.patternProperties)&&((t)=>{let r=Object.getOwnPropertyNames(t.patternProperties);return r.length===1&&la(r[0])&&xe(t.patternProperties)&&Oe(t.patternProperties[r[0]])})(e)}function Nf(e){return ee(e,"Ref")&&ce(e.$id)&&ye(e.$ref)}function uo(e){return ee(e,"RegExp")&&ce(e.$id)&&ye(e.source)&&ye(e.flags)&&fe(e.maxLength)&&fe(e.minLength)}function Lt(e){return ee(e,"String")&&e.type==="string"&&ce(e.$id)&&fe(e.minLength)&&fe(e.maxLength)&&Sf(e.pattern)&&kf(e.format)}function fo(e){return ee(e,"Symbol")&&e.type==="symbol"&&ce(e.$id)}function mo(e){return ee(e,"TemplateLiteral")&&e.type==="string"&&ye(e.pattern)&&e.pattern[0]==="^"&&e.pattern[e.pattern.length-1]==="$"}function Mf(e){return ee(e,"This")&&ce(e.$id)&&ye(e.$ref)}function jf(e){return xe(e)&&Re in e}function es(e){return ee(e,"Tuple")&&e.type==="array"&&ce(e.$id)&&yt(e.minItems)&&yt(e.maxItems)&&e.minItems===e.maxItems&&(ge(e.items)&&ge(e.additionalItems)&&e.minItems===0||Ue(e.items)&&e.items.every((t)=>Oe(t)))}function Qr(e){return ee(e,"Undefined")&&e.type==="undefined"&&ce(e.$id)}function mr(e){return ee(e,"Union")&&ce(e.$id)&&xe(e)&&Ue(e.anyOf)&&e.anyOf.every((t)=>Oe(t))}function po(e){return ee(e,"Uint8Array")&&e.type==="Uint8Array"&&ce(e.$id)&&fe(e.minByteLength)&&fe(e.maxByteLength)}function Kt(e){return ee(e,"Unknown")&&ce(e.$id)}function Ef(e){return ee(e,"Unsafe")}function ts(e){return ee(e,"Void")&&e.type==="void"&&ce(e.$id)}function Uf(e){return xe(e)&&I in e&&ye(e[I])&&!$f.includes(e[I])}function Oe(e){return xe(e)&&(Ut(e)||Pf(e)||Wr(e)||Xr(e)||Xo(e)||Ds(e)||Cf(e)||Yo(e)||Qo(e)||Zo(e)||fr(e)||Yr(e)||qs(e)||Pr(e)||Tf(e)||Ff(e)||Cr(e)||Sn(e)||Gs(e)||dt(e)||ke(e)||Hs(e)||Ve(e)||Nf(e)||uo(e)||Lt(e)||fo(e)||mo(e)||Mf(e)||es(e)||Qr(e)||mr(e)||po(e)||Kt(e)||Ef(e)||ts(e)||Uf(e))}class Sa extends oe{}var x;(function(e){e[e.Union=0]="Union",e[e.True=1]="True",e[e.False=2]="False"})(x||(x={}));function kt(e){return e===x.False?e:x.True}function kn(e){throw new Sa(e)}function Le(e){return Cr(e)||Yr(e)||mr(e)||Kt(e)||Ut(e)}function Ke(e,t){return Cr(t)?Ca(e,t):Yr(t)?rs(e,t):mr(t)?Xs(e,t):Kt(t)?Na(e,t):Ut(t)?Ws(e,t):kn("StructuralRight")}function Ws(e,t){return x.True}function Lf(e,t){return Yr(t)?rs(e,t):mr(t)&&t.anyOf.some((r)=>Ut(r)||Kt(r))?x.True:mr(t)?x.Union:Kt(t)?x.True:Ut(t)?x.True:x.Union}function Kf(e,t){return Kt(e)?x.False:Ut(e)?x.Union:Cr(e)?x.True:x.False}function Bf(e,t){return ke(t)&&ns(t)?x.True:Le(t)?Ke(e,t):!Wr(t)?x.False:kt(ue(e.items,t.items))}function vf(e,t){return Le(t)?Ke(e,t):!Ds(t)?x.False:kt(ue(e.items,t.items))}function Df(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):Xo(t)?x.True:x.False}function ka(e,t){return ba(e)?x.True:Xr(e)?x.True:x.False}function qf(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):Xr(t)?x.True:x.False}function Gf(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):!Yo(t)?x.False:e.parameters.length>t.parameters.length?x.False:!e.parameters.every((r,n)=>kt(ue(t.parameters[n],r))===x.True)?x.False:kt(ue(e.returns,t.returns))}function Hf(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):Qo(t)?x.True:x.False}function zf(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):!Zo(t)?x.False:e.parameters.length>t.parameters.length?x.False:!e.parameters.every((r,n)=>kt(ue(t.parameters[n],r))===x.True)?x.False:kt(ue(e.returns,t.returns))}function Pa(e,t){return Pr(e)&&yt(e.const)?x.True:dt(e)||fr(e)?x.True:x.False}function Vf(e,t){return fr(t)||dt(t)?x.True:Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):x.False}function rs(e,t){return t.allOf.every((r)=>ue(e,r)===x.True)?x.True:x.False}function Jf(e,t){return e.allOf.some((r)=>ue(r,t)===x.True)?x.True:x.False}function Wf(e,t){return Le(t)?Ke(e,t):!qs(t)?x.False:kt(ue(e.items,t.items))}function Xf(e,t){return Pr(t)&&t.const===e.const?x.True:Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):Lt(t)?Fa(e,t):dt(t)?Aa(e,t):fr(t)?Pa(e,t):Xr(t)?ka(e,t):x.False}function Ca(e,t){return x.False}function Yf(e,t){return x.True}function _a(e){let[t,r]=[e,0];while(!0){if(!Sn(t))break;t=t.not,r+=1}return r%2===0?t:kr()}function Qf(e,t){return Sn(e)?ue(_a(e),t):Sn(t)?ue(e,_a(t)):kn("Invalid fallthrough for Not")}function Zf(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):Gs(t)?x.True:x.False}function Aa(e,t){return Ia(e)?x.True:dt(e)||fr(e)?x.True:x.False}function em(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):fr(t)||dt(t)?x.True:x.False}function ft(e,t){return Object.getOwnPropertyNames(e.properties).length===t}function Oa(e){return ns(e)}function wa(e){return ft(e,0)||ft(e,1)&&"description"in e.properties&&mr(e.properties.description)&&e.properties.description.anyOf.length===2&&(Lt(e.properties.description.anyOf[0])&&Qr(e.properties.description.anyOf[1])||Lt(e.properties.description.anyOf[1])&&Qr(e.properties.description.anyOf[0]))}function zs(e){return ft(e,0)}function $a(e){return ft(e,0)}function tm(e){return ft(e,0)}function rm(e){return ft(e,0)}function nm(e){return ns(e)}function om(e){let t=_t();return ft(e,0)||ft(e,1)&&"length"in e.properties&&kt(ue(e.properties.length,t))===x.True}function sm(e){return ft(e,0)}function ns(e){let t=_t();return ft(e,0)||ft(e,1)&&"length"in e.properties&&kt(ue(e.properties.length,t))===x.True}function im(e){let t=Qt([Sr()],Sr());return ft(e,0)||ft(e,1)&&"then"in e.properties&&kt(ue(e.properties.then,t))===x.True}function Ta(e,t){return ue(e,t)===x.False?x.False:Wo(e)&&!Wo(t)?x.False:x.True}function et(e,t){return Kt(e)?x.False:Ut(e)?x.Union:Cr(e)||xa(e)&&Oa(t)||Ia(e)&&zs(t)||ba(e)&&$a(t)||fo(e)&&wa(t)||Xo(e)&&tm(t)||Lt(e)&&Oa(t)||fo(e)&&wa(t)||dt(e)&&zs(t)||fr(e)&&zs(t)||Xr(e)&&$a(t)||po(e)&&nm(t)||Qo(e)&&rm(t)||Yo(e)&&sm(t)||Zo(e)&&om(t)?x.True:Ve(e)&&Lt(Vs(e))?(()=>t[Yt]==="Record"?x.True:x.False)():Ve(e)&&dt(Vs(e))?(()=>ft(t,0)?x.True:x.False)():x.False}function am(e,t){return Le(t)?Ke(e,t):Ve(t)?Pt(e,t):!ke(t)?x.False:(()=>{for(let r of Object.getOwnPropertyNames(t.properties)){if(!(r in e.properties)&&!Wo(t.properties[r]))return x.False;if(Wo(t.properties[r]))return x.True;if(Ta(e.properties[r],t.properties[r])===x.False)return x.False}return x.True})()}function cm(e,t){return Le(t)?Ke(e,t):ke(t)&&im(t)?x.True:!Hs(t)?x.False:kt(ue(e.item,t.item))}function Vs(e){return _r in e.patternProperties?_t():(Or in e.patternProperties)?Et():kn("Unknown record key pattern")}function Js(e){return _r in e.patternProperties?e.patternProperties[_r]:(Or in e.patternProperties)?e.patternProperties[Or]:kn("Unable to get record value schema")}function Pt(e,t){let[r,n]=[Vs(t),Js(t)];return xa(e)&&dt(r)&&kt(ue(e,n))===x.True?x.True:po(e)&&dt(r)?ue(e,n):Lt(e)&&dt(r)?ue(e,n):Wr(e)&&dt(r)?ue(e,n):ke(e)?(()=>{for(let o of Object.getOwnPropertyNames(e.properties))if(Ta(n,e.properties[o])===x.False)return x.False;return x.True})():x.False}function um(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):!Ve(t)?x.False:ue(Js(e),Js(t))}function dm(e,t){let r=uo(e)?Et():e,n=uo(t)?Et():t;return ue(r,n)}function Fa(e,t){return Pr(e)&&ye(e.const)?x.True:Lt(e)?x.True:x.False}function fm(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):Lt(t)?x.True:x.False}function mm(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):fo(t)?x.True:x.False}function pm(e,t){return mo(e)?ue(Jr(e),t):mo(t)?ue(e,Jr(t)):kn("Invalid fallthrough for TemplateLiteral")}function lm(e,t){return Wr(t)&&e.items!==void 0&&e.items.every((r)=>ue(r,t.items)===x.True)}function ym(e,t){return Cr(e)?x.True:Kt(e)?x.False:Ut(e)?x.Union:x.False}function gm(e,t){return Le(t)?Ke(e,t):ke(t)&&ns(t)?x.True:Wr(t)&&lm(e,t)?x.True:!es(t)?x.False:ge(e.items)&&!ge(t.items)||!ge(e.items)&&ge(t.items)?x.False:ge(e.items)&&!ge(t.items)?x.True:e.items.every((r,n)=>ue(r,t.items[n])===x.True)?x.True:x.False}function hm(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):po(t)?x.True:x.False}function xm(e,t){return Le(t)?Ke(e,t):ke(t)?et(e,t):Ve(t)?Pt(e,t):ts(t)?Rm(e,t):Qr(t)?x.True:x.False}function Xs(e,t){return t.anyOf.some((r)=>ue(e,r)===x.True)?x.True:x.False}function Im(e,t){return e.anyOf.every((r)=>ue(r,t)===x.True)?x.True:x.False}function Na(e,t){return x.True}function bm(e,t){return Cr(t)?Ca(e,t):Yr(t)?rs(e,t):mr(t)?Xs(e,t):Ut(t)?Ws(e,t):Lt(t)?Fa(e,t):dt(t)?Aa(e,t):fr(t)?Pa(e,t):Xr(t)?ka(e,t):Wr(t)?Kf(e,t):es(t)?ym(e,t):ke(t)?et(e,t):Kt(t)?x.True:x.False}function Rm(e,t){return Qr(e)?x.True:Qr(e)?x.True:x.False}function _m(e,t){return Yr(t)?rs(e,t):mr(t)?Xs(e,t):Kt(t)?Na(e,t):Ut(t)?Ws(e,t):ke(t)?et(e,t):ts(t)?x.True:x.False}function ue(e,t){return mo(e)||mo(t)?pm(e,t):uo(e)||uo(t)?dm(e,t):Sn(e)||Sn(t)?Qf(e,t):Ut(e)?Lf(e,t):Wr(e)?Bf(e,t):Xo(e)?Df(e,t):Xr(e)?qf(e,t):Ds(e)?vf(e,t):Yo(e)?Gf(e,t):Qo(e)?Hf(e,t):Zo(e)?zf(e,t):fr(e)?Vf(e,t):Yr(e)?Jf(e,t):qs(e)?Wf(e,t):Pr(e)?Xf(e,t):Cr(e)?Yf(e,t):Gs(e)?Zf(e,t):dt(e)?em(e,t):ke(e)?am(e,t):Ve(e)?um(e,t):Lt(e)?fm(e,t):fo(e)?mm(e,t):es(e)?gm(e,t):Hs(e)?cm(e,t):po(e)?hm(e,t):Qr(e)?xm(e,t):mr(e)?Im(e,t):Kt(e)?bm(e,t):ts(e)?_m(e,t):kn(`Unknown left type operand '${e[I]}'`)}function Ar(e,t){return ue(e,t)}function Om(e,t,r,n,o){let s={};for(let i of globalThis.Object.getOwnPropertyNames(e))s[i]=Pn(e[i],t,r,n,Ie(o));return s}function wm(e,t,r,n,o){return Om(e.properties,t,r,n,o)}function Ma(e,t,r,n,o){let s=wm(e,t,r,n,o);return re(s)}function $m(e,t,r,n){let o=Ar(e,t);return o===x.Union?ie([r,n]):o===x.True?r:n}function Pn(e,t,r,n,o){return be(e)?Ma(e,t,r,n,o):ht(e)?h(ja(e,t,r,n,o)):h($m(e,t,r,n),o)}function Sm(e,t,r,n,o){return{[e]:Pn(se(e),t,r,n,Ie(o))}}function km(e,t,r,n,o){return e.reduce((s,i)=>({...s,...Sm(i,t,r,n,o)}),{})}function Pm(e,t,r,n,o){return km(e.keys,t,r,n,o)}function ja(e,t,r,n,o){let s=Pm(e,t,r,n,o);return re(s)}class Ea extends oe{constructor(e){super("Unknown type");this.schema=e}}function Cm(e){return e[I]==="Any"||e[I]==="Unknown"}function X(e){return e!==void 0}function Am(e,t,r){return!0}function Tm(e,t,r){return!0}function Fm(e,t,r){if(!Ee(r))return!1;if(X(e.minItems)&&!(r.length>=e.minItems))return!1;if(X(e.maxItems)&&!(r.length<=e.maxItems))return!1;if(!r.every((s)=>Ge(e.items,t,s)))return!1;if(e.uniqueItems===!0&&!function(){let s=new Set;for(let i of r){let a=$n(i);if(s.has(a))return!1;else s.add(a)}return!0}())return!1;if(!(X(e.contains)||H(e.minContains)||H(e.maxContains)))return!0;let n=X(e.contains)?e.contains:J(),o=r.reduce((s,i)=>Ge(n,t,i)?s+1:s,0);if(o===0)return!1;if(H(e.minContains)&&o<e.minContains)return!1;if(H(e.maxContains)&&o>e.maxContains)return!1;return!0}function Nm(e,t,r){return Co(r)}function Mm(e,t,r){if(!lt(r))return!1;if(X(e.exclusiveMaximum)&&!(r<e.exclusiveMaximum))return!1;if(X(e.exclusiveMinimum)&&!(r>e.exclusiveMinimum))return!1;if(X(e.maximum)&&!(r<=e.maximum))return!1;if(X(e.minimum)&&!(r>=e.minimum))return!1;if(X(e.multipleOf)&&r%e.multipleOf!==BigInt(0))return!1;return!0}function jm(e,t,r){return Kr(r)}function Em(e,t,r){return Ge(e.returns,t,r.prototype)}function Um(e,t,r){if(!fn(r))return!1;if(X(e.exclusiveMaximumTimestamp)&&!(r.getTime()<e.exclusiveMaximumTimestamp))return!1;if(X(e.exclusiveMinimumTimestamp)&&!(r.getTime()>e.exclusiveMinimumTimestamp))return!1;if(X(e.maximumTimestamp)&&!(r.getTime()<=e.maximumTimestamp))return!1;if(X(e.minimumTimestamp)&&!(r.getTime()>=e.minimumTimestamp))return!1;if(X(e.multipleOfTimestamp)&&r.getTime()%e.multipleOfTimestamp!==0)return!1;return!0}function Lm(e,t,r){return Mo(r)}function Km(e,t,r){let n=globalThis.Object.values(e.$defs),o=e.$defs[e.$ref];return Ge(o,[...t,...n],r)}function Bm(e,t,r){if(!No(r))return!1;if(X(e.exclusiveMaximum)&&!(r<e.exclusiveMaximum))return!1;if(X(e.exclusiveMinimum)&&!(r>e.exclusiveMinimum))return!1;if(X(e.maximum)&&!(r<=e.maximum))return!1;if(X(e.minimum)&&!(r>=e.minimum))return!1;if(X(e.multipleOf)&&r%e.multipleOf!==0)return!1;return!0}function vm(e,t,r){let n=e.allOf.every((o)=>Ge(o,t,r));if(e.unevaluatedProperties===!1){let o=new RegExp(ur(e)),s=Object.getOwnPropertyNames(r).every((i)=>o.test(i));return n&&s}else if(_e(e.unevaluatedProperties)){let o=new RegExp(ur(e)),s=Object.getOwnPropertyNames(r).every((i)=>o.test(i)||Ge(e.unevaluatedProperties,t,r[i]));return n&&s}else return n}function Dm(e,t,r){return Ao(r)}function qm(e,t,r){return r===e.const}function Gm(e,t,r){return!1}function Hm(e,t,r){return!Ge(e.not,t,r)}function zm(e,t,r){return Lr(r)}function Vm(e,t,r){if(!le.IsNumberLike(r))return!1;if(X(e.exclusiveMaximum)&&!(r<e.exclusiveMaximum))return!1;if(X(e.exclusiveMinimum)&&!(r>e.exclusiveMinimum))return!1;if(X(e.minimum)&&!(r>=e.minimum))return!1;if(X(e.maximum)&&!(r<=e.maximum))return!1;if(X(e.multipleOf)&&r%e.multipleOf!==0)return!1;return!0}function Jm(e,t,r){if(!le.IsObjectLike(r))return!1;if(X(e.minProperties)&&!(Object.getOwnPropertyNames(r).length>=e.minProperties))return!1;if(X(e.maxProperties)&&!(Object.getOwnPropertyNames(r).length<=e.maxProperties))return!1;let n=Object.getOwnPropertyNames(e.properties);for(let o of n){let s=e.properties[o];if(e.required&&e.required.includes(o)){if(!Ge(s,t,r[o]))return!1;if((dr(s)||Cm(s))&&!(o in r))return!1}else if(le.IsExactOptionalProperty(r,o)&&!Ge(s,t,r[o]))return!1}if(e.additionalProperties===!1){let o=Object.getOwnPropertyNames(r);if(e.required&&e.required.length===n.length&&o.length===n.length)return!0;else return o.every((s)=>n.includes(s))}else if(typeof e.additionalProperties==="object")return Object.getOwnPropertyNames(r).every((s)=>n.includes(s)||Ge(e.additionalProperties,t,r[s]));else return!0}function Wm(e,t,r){return To(r)}function Xm(e,t,r){if(!le.IsRecordLike(r))return!1;if(X(e.minProperties)&&!(Object.getOwnPropertyNames(r).length>=e.minProperties))return!1;if(X(e.maxProperties)&&!(Object.getOwnPropertyNames(r).length<=e.maxProperties))return!1;let[n,o]=Object.entries(e.patternProperties)[0],s=new RegExp(n),i=Object.entries(r).every(([c,d])=>s.test(c)?Ge(o,t,d):!0),a=typeof e.additionalProperties==="object"?Object.entries(r).every(([c,d])=>!s.test(c)?Ge(e.additionalProperties,t,d):!0):!0,u=e.additionalProperties===!1?Object.getOwnPropertyNames(r).every((c)=>s.test(c)):!0;return i&&a&&u}function Ym(e,t,r){return Ge(qe(e,t),t,r)}function Qm(e,t,r){let n=new RegExp(e.source,e.flags);if(X(e.minLength)){if(!(r.length>=e.minLength))return!1}if(X(e.maxLength)){if(!(r.length<=e.maxLength))return!1}return n.test(r)}function Zm(e,t,r){if(!De(r))return!1;if(X(e.minLength)){if(!(r.length>=e.minLength))return!1}if(X(e.maxLength)){if(!(r.length<=e.maxLength))return!1}if(X(e.pattern)){if(!new RegExp(e.pattern).test(r))return!1}if(X(e.format)){if(!Cs(e.format))return!1;return As(e.format)(r)}return!0}function ep(e,t,r){return Br(r)}function tp(e,t,r){return De(r)&&new RegExp(e.pattern).test(r)}function rp(e,t,r){return Ge(qe(e,t),t,r)}function np(e,t,r){if(!Ee(r))return!1;if(e.items===void 0&&r.length!==0)return!1;if(r.length!==e.maxItems)return!1;if(!e.items)return!0;for(let n=0;n<e.items.length;n++)if(!Ge(e.items[n],t,r[n]))return!1;return!0}function op(e,t,r){return nt(r)}function sp(e,t,r){return e.anyOf.some((n)=>Ge(n,t,r))}function ip(e,t,r){if(!mn(r))return!1;if(X(e.maxByteLength)&&!(r.length<=e.maxByteLength))return!1;if(X(e.minByteLength)&&!(r.length>=e.minByteLength))return!1;return!0}function ap(e,t,r){return!0}function cp(e,t,r){return le.IsVoidLike(r)}function up(e,t,r){if(!Qn(e[I]))return!1;return Ts(e[I])(e,r)}function Ge(e,t,r){let n=X(e.$id)?$r(e,t):t,o=e;switch(o[I]){case"Any":return Am(o,n,r);case"Argument":return Tm(o,n,r);case"Array":return Fm(o,n,r);case"AsyncIterator":return Nm(o,n,r);case"BigInt":return Mm(o,n,r);case"Boolean":return jm(o,n,r);case"Constructor":return Em(o,n,r);case"Date":return Um(o,n,r);case"Function":return Lm(o,n,r);case"Import":return Km(o,n,r);case"Integer":return Bm(o,n,r);case"Intersect":return vm(o,n,r);case"Iterator":return Dm(o,n,r);case"Literal":return qm(o,n,r);case"Never":return Gm(o,n,r);case"Not":return Hm(o,n,r);case"Null":return zm(o,n,r);case"Number":return Vm(o,n,r);case"Object":return Jm(o,n,r);case"Promise":return Wm(o,n,r);case"Record":return Xm(o,n,r);case"Ref":return Ym(o,n,r);case"RegExp":return Qm(o,n,r);case"String":return Zm(o,n,r);case"Symbol":return ep(o,n,r);case"TemplateLiteral":return tp(o,n,r);case"This":return rp(o,n,r);case"Tuple":return np(o,n,r);case"Undefined":return op(o,n,r);case"Union":return sp(o,n,r);case"Uint8Array":return ip(o,n,r);case"Unknown":return ap(o,n,r);case"Void":return cp(o,n,r);default:if(!Qn(o[I]))throw new Ea(o);return up(o,n,r)}}function Zr(...e){return e.length===3?Ge(e[0],e[1],e[2]):Ge(e[0],[],e[1])}var g;(function(e){e[e.ArrayContains=0]="ArrayContains",e[e.ArrayMaxContains=1]="ArrayMaxContains",e[e.ArrayMaxItems=2]="ArrayMaxItems",e[e.ArrayMinContains=3]="ArrayMinContains",e[e.ArrayMinItems=4]="ArrayMinItems",e[e.ArrayUniqueItems=5]="ArrayUniqueItems",e[e.Array=6]="Array",e[e.AsyncIterator=7]="AsyncIterator",e[e.BigIntExclusiveMaximum=8]="BigIntExclusiveMaximum",e[e.BigIntExclusiveMinimum=9]="BigIntExclusiveMinimum",e[e.BigIntMaximum=10]="BigIntMaximum",e[e.BigIntMinimum=11]="BigIntMinimum",e[e.BigIntMultipleOf=12]="BigIntMultipleOf",e[e.BigInt=13]="BigInt",e[e.Boolean=14]="Boolean",e[e.DateExclusiveMaximumTimestamp=15]="DateExclusiveMaximumTimestamp",e[e.DateExclusiveMinimumTimestamp=16]="DateExclusiveMinimumTimestamp",e[e.DateMaximumTimestamp=17]="DateMaximumTimestamp",e[e.DateMinimumTimestamp=18]="DateMinimumTimestamp",e[e.DateMultipleOfTimestamp=19]="DateMultipleOfTimestamp",e[e.Date=20]="Date",e[e.Function=21]="Function",e[e.IntegerExclusiveMaximum=22]="IntegerExclusiveMaximum",e[e.IntegerExclusiveMinimum=23]="IntegerExclusiveMinimum",e[e.IntegerMaximum=24]="IntegerMaximum",e[e.IntegerMinimum=25]="IntegerMinimum",e[e.IntegerMultipleOf=26]="IntegerMultipleOf",e[e.Integer=27]="Integer",e[e.IntersectUnevaluatedProperties=28]="IntersectUnevaluatedProperties",e[e.Intersect=29]="Intersect",e[e.Iterator=30]="Iterator",e[e.Kind=31]="Kind",e[e.Literal=32]="Literal",e[e.Never=33]="Never",e[e.Not=34]="Not",e[e.Null=35]="Null",e[e.NumberExclusiveMaximum=36]="NumberExclusiveMaximum",e[e.NumberExclusiveMinimum=37]="NumberExclusiveMinimum",e[e.NumberMaximum=38]="NumberMaximum",e[e.NumberMinimum=39]="NumberMinimum",e[e.NumberMultipleOf=40]="NumberMultipleOf",e[e.Number=41]="Number",e[e.ObjectAdditionalProperties=42]="ObjectAdditionalProperties",e[e.ObjectMaxProperties=43]="ObjectMaxProperties",e[e.ObjectMinProperties=44]="ObjectMinProperties",e[e.ObjectRequiredProperty=45]="ObjectRequiredProperty",e[e.Object=46]="Object",e[e.Promise=47]="Promise",e[e.RegExp=48]="RegExp",e[e.StringFormatUnknown=49]="StringFormatUnknown",e[e.StringFormat=50]="StringFormat",e[e.StringMaxLength=51]="StringMaxLength",e[e.StringMinLength=52]="StringMinLength",e[e.StringPattern=53]="StringPattern",e[e.String=54]="String",e[e.Symbol=55]="Symbol",e[e.TupleLength=56]="TupleLength",e[e.Tuple=57]="Tuple",e[e.Uint8ArrayMaxByteLength=58]="Uint8ArrayMaxByteLength",e[e.Uint8ArrayMinByteLength=59]="Uint8ArrayMinByteLength",e[e.Uint8Array=60]="Uint8Array",e[e.Undefined=61]="Undefined",e[e.Union=62]="Union",e[e.Void=63]="Void"})(g||(g={}));class Ua extends oe{constructor(e){super("Unknown type");this.schema=e}}function pr(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function Y(e){return e!==void 0}class Ys{constructor(e){this.iterator=e}[Symbol.iterator](){return this.iterator}First(){let e=this.iterator.next();return e.done?void 0:e.value}}function S(e,t,r,n,o=[]){return{type:e,schema:t,path:r,value:n,message:ca()({errorType:e,path:r,schema:t,value:n,errors:o}),errors:o}}function*dp(e,t,r,n){}function*fp(e,t,r,n){}function*mp(e,t,r,n){if(!Ee(n))return yield S(g.Array,e,r,n);if(Y(e.minItems)&&!(n.length>=e.minItems))yield S(g.ArrayMinItems,e,r,n);if(Y(e.maxItems)&&!(n.length<=e.maxItems))yield S(g.ArrayMaxItems,e,r,n);for(let i=0;i<n.length;i++)yield*He(e.items,t,`${r}/${i}`,n[i]);if(e.uniqueItems===!0&&!function(){let i=new Set;for(let a of n){let u=$n(a);if(i.has(u))return!1;else i.add(u)}return!0}())yield S(g.ArrayUniqueItems,e,r,n);if(!(Y(e.contains)||Y(e.minContains)||Y(e.maxContains)))return;let o=Y(e.contains)?e.contains:J(),s=n.reduce((i,a,u)=>He(o,t,`${r}${u}`,a).next().done===!0?i+1:i,0);if(s===0)yield S(g.ArrayContains,e,r,n);if(H(e.minContains)&&s<e.minContains)yield S(g.ArrayMinContains,e,r,n);if(H(e.maxContains)&&s>e.maxContains)yield S(g.ArrayMaxContains,e,r,n)}function*pp(e,t,r,n){if(!Co(n))yield S(g.AsyncIterator,e,r,n)}function*lp(e,t,r,n){if(!lt(n))return yield S(g.BigInt,e,r,n);if(Y(e.exclusiveMaximum)&&!(n<e.exclusiveMaximum))yield S(g.BigIntExclusiveMaximum,e,r,n);if(Y(e.exclusiveMinimum)&&!(n>e.exclusiveMinimum))yield S(g.BigIntExclusiveMinimum,e,r,n);if(Y(e.maximum)&&!(n<=e.maximum))yield S(g.BigIntMaximum,e,r,n);if(Y(e.minimum)&&!(n>=e.minimum))yield S(g.BigIntMinimum,e,r,n);if(Y(e.multipleOf)&&n%e.multipleOf!==BigInt(0))yield S(g.BigIntMultipleOf,e,r,n)}function*yp(e,t,r,n){if(!Kr(n))yield S(g.Boolean,e,r,n)}function*gp(e,t,r,n){yield*He(e.returns,t,r,n.prototype)}function*hp(e,t,r,n){if(!fn(n))return yield S(g.Date,e,r,n);if(Y(e.exclusiveMaximumTimestamp)&&!(n.getTime()<e.exclusiveMaximumTimestamp))yield S(g.DateExclusiveMaximumTimestamp,e,r,n);if(Y(e.exclusiveMinimumTimestamp)&&!(n.getTime()>e.exclusiveMinimumTimestamp))yield S(g.DateExclusiveMinimumTimestamp,e,r,n);if(Y(e.maximumTimestamp)&&!(n.getTime()<=e.maximumTimestamp))yield S(g.DateMaximumTimestamp,e,r,n);if(Y(e.minimumTimestamp)&&!(n.getTime()>=e.minimumTimestamp))yield S(g.DateMinimumTimestamp,e,r,n);if(Y(e.multipleOfTimestamp)&&n.getTime()%e.multipleOfTimestamp!==0)yield S(g.DateMultipleOfTimestamp,e,r,n)}function*xp(e,t,r,n){if(!Mo(n))yield S(g.Function,e,r,n)}function*Ip(e,t,r,n){let o=globalThis.Object.values(e.$defs),s=e.$defs[e.$ref];yield*He(s,[...t,...o],r,n)}function*bp(e,t,r,n){if(!No(n))return yield S(g.Integer,e,r,n);if(Y(e.exclusiveMaximum)&&!(n<e.exclusiveMaximum))yield S(g.IntegerExclusiveMaximum,e,r,n);if(Y(e.exclusiveMinimum)&&!(n>e.exclusiveMinimum))yield S(g.IntegerExclusiveMinimum,e,r,n);if(Y(e.maximum)&&!(n<=e.maximum))yield S(g.IntegerMaximum,e,r,n);if(Y(e.minimum)&&!(n>=e.minimum))yield S(g.IntegerMinimum,e,r,n);if(Y(e.multipleOf)&&n%e.multipleOf!==0)yield S(g.IntegerMultipleOf,e,r,n)}function*Rp(e,t,r,n){let o=!1;for(let s of e.allOf)for(let i of He(s,t,r,n))o=!0,yield i;if(o)return yield S(g.Intersect,e,r,n);if(e.unevaluatedProperties===!1){let s=new RegExp(ur(e));for(let i of Object.getOwnPropertyNames(n))if(!s.test(i))yield S(g.IntersectUnevaluatedProperties,e,`${r}/${i}`,n)}if(typeof e.unevaluatedProperties==="object"){let s=new RegExp(ur(e));for(let i of Object.getOwnPropertyNames(n))if(!s.test(i)){let a=He(e.unevaluatedProperties,t,`${r}/${i}`,n[i]).next();if(!a.done)yield a.value}}}function*_p(e,t,r,n){if(!Ao(n))yield S(g.Iterator,e,r,n)}function*Op(e,t,r,n){if(n!==e.const)yield S(g.Literal,e,r,n)}function*wp(e,t,r,n){yield S(g.Never,e,r,n)}function*$p(e,t,r,n){if(He(e.not,t,r,n).next().done===!0)yield S(g.Not,e,r,n)}function*Sp(e,t,r,n){if(!Lr(n))yield S(g.Null,e,r,n)}function*kp(e,t,r,n){if(!le.IsNumberLike(n))return yield S(g.Number,e,r,n);if(Y(e.exclusiveMaximum)&&!(n<e.exclusiveMaximum))yield S(g.NumberExclusiveMaximum,e,r,n);if(Y(e.exclusiveMinimum)&&!(n>e.exclusiveMinimum))yield S(g.NumberExclusiveMinimum,e,r,n);if(Y(e.maximum)&&!(n<=e.maximum))yield S(g.NumberMaximum,e,r,n);if(Y(e.minimum)&&!(n>=e.minimum))yield S(g.NumberMinimum,e,r,n);if(Y(e.multipleOf)&&n%e.multipleOf!==0)yield S(g.NumberMultipleOf,e,r,n)}function*Pp(e,t,r,n){if(!le.IsObjectLike(n))return yield S(g.Object,e,r,n);if(Y(e.minProperties)&&!(Object.getOwnPropertyNames(n).length>=e.minProperties))yield S(g.ObjectMinProperties,e,r,n);if(Y(e.maxProperties)&&!(Object.getOwnPropertyNames(n).length<=e.maxProperties))yield S(g.ObjectMaxProperties,e,r,n);let o=Array.isArray(e.required)?e.required:[],s=Object.getOwnPropertyNames(e.properties),i=Object.getOwnPropertyNames(n);for(let a of o){if(i.includes(a))continue;yield S(g.ObjectRequiredProperty,e.properties[a],`${r}/${pr(a)}`,void 0)}if(e.additionalProperties===!1){for(let a of i)if(!s.includes(a))yield S(g.ObjectAdditionalProperties,e,`${r}/${pr(a)}`,n[a])}if(typeof e.additionalProperties==="object")for(let a of i){if(s.includes(a))continue;yield*He(e.additionalProperties,t,`${r}/${pr(a)}`,n[a])}for(let a of s){let u=e.properties[a];if(e.required&&e.required.includes(a)){if(yield*He(u,t,`${r}/${pr(a)}`,n[a]),dr(e)&&!(a in n))yield S(g.ObjectRequiredProperty,u,`${r}/${pr(a)}`,void 0)}else if(le.IsExactOptionalProperty(n,a))yield*He(u,t,`${r}/${pr(a)}`,n[a])}}function*Cp(e,t,r,n){if(!To(n))yield S(g.Promise,e,r,n)}function*Ap(e,t,r,n){if(!le.IsRecordLike(n))return yield S(g.Object,e,r,n);if(Y(e.minProperties)&&!(Object.getOwnPropertyNames(n).length>=e.minProperties))yield S(g.ObjectMinProperties,e,r,n);if(Y(e.maxProperties)&&!(Object.getOwnPropertyNames(n).length<=e.maxProperties))yield S(g.ObjectMaxProperties,e,r,n);let[o,s]=Object.entries(e.patternProperties)[0],i=new RegExp(o);for(let[a,u]of Object.entries(n))if(i.test(a))yield*He(s,t,`${r}/${pr(a)}`,u);if(typeof e.additionalProperties==="object"){for(let[a,u]of Object.entries(n))if(!i.test(a))yield*He(e.additionalProperties,t,`${r}/${pr(a)}`,u)}if(e.additionalProperties===!1)for(let[a,u]of Object.entries(n)){if(i.test(a))continue;return yield S(g.ObjectAdditionalProperties,e,`${r}/${pr(a)}`,u)}}function*Tp(e,t,r,n){yield*He(qe(e,t),t,r,n)}function*Fp(e,t,r,n){if(!De(n))return yield S(g.String,e,r,n);if(Y(e.minLength)&&!(n.length>=e.minLength))yield S(g.StringMinLength,e,r,n);if(Y(e.maxLength)&&!(n.length<=e.maxLength))yield S(g.StringMaxLength,e,r,n);if(!new RegExp(e.source,e.flags).test(n))return yield S(g.RegExp,e,r,n)}function*Np(e,t,r,n){if(!De(n))return yield S(g.String,e,r,n);if(Y(e.minLength)&&!(n.length>=e.minLength))yield S(g.StringMinLength,e,r,n);if(Y(e.maxLength)&&!(n.length<=e.maxLength))yield S(g.StringMaxLength,e,r,n);if(De(e.pattern)){if(!new RegExp(e.pattern).test(n))yield S(g.StringPattern,e,r,n)}if(De(e.format)){if(!Cs(e.format))yield S(g.StringFormatUnknown,e,r,n);else if(!As(e.format)(n))yield S(g.StringFormat,e,r,n)}}function*Mp(e,t,r,n){if(!Br(n))yield S(g.Symbol,e,r,n)}function*jp(e,t,r,n){if(!De(n))return yield S(g.String,e,r,n);if(!new RegExp(e.pattern).test(n))yield S(g.StringPattern,e,r,n)}function*Ep(e,t,r,n){yield*He(qe(e,t),t,r,n)}function*Up(e,t,r,n){if(!Ee(n))return yield S(g.Tuple,e,r,n);if(e.items===void 0&&n.length!==0)return yield S(g.TupleLength,e,r,n);if(n.length!==e.maxItems)return yield S(g.TupleLength,e,r,n);if(!e.items)return;for(let o=0;o<e.items.length;o++)yield*He(e.items[o],t,`${r}/${o}`,n[o])}function*Lp(e,t,r,n){if(!nt(n))yield S(g.Undefined,e,r,n)}function*Kp(e,t,r,n){if(Zr(e,t,n))return;let o=e.anyOf.map((s)=>new Ys(He(s,t,r,n)));yield S(g.Union,e,r,n,o)}function*Bp(e,t,r,n){if(!mn(n))return yield S(g.Uint8Array,e,r,n);if(Y(e.maxByteLength)&&!(n.length<=e.maxByteLength))yield S(g.Uint8ArrayMaxByteLength,e,r,n);if(Y(e.minByteLength)&&!(n.length>=e.minByteLength))yield S(g.Uint8ArrayMinByteLength,e,r,n)}function*vp(e,t,r,n){}function*Dp(e,t,r,n){if(!le.IsVoidLike(n))yield S(g.Void,e,r,n)}function*qp(e,t,r,n){if(!Ts(e[I])(e,n))yield S(g.Kind,e,r,n)}function*He(e,t,r,n){let o=Y(e.$id)?[...t,e]:t,s=e;switch(s[I]){case"Any":return yield*dp(s,o,r,n);case"Argument":return yield*fp(s,o,r,n);case"Array":return yield*mp(s,o,r,n);case"AsyncIterator":return yield*pp(s,o,r,n);case"BigInt":return yield*lp(s,o,r,n);case"Boolean":return yield*yp(s,o,r,n);case"Constructor":return yield*gp(s,o,r,n);case"Date":return yield*hp(s,o,r,n);case"Function":return yield*xp(s,o,r,n);case"Import":return yield*Ip(s,o,r,n);case"Integer":return yield*bp(s,o,r,n);case"Intersect":return yield*Rp(s,o,r,n);case"Iterator":return yield*_p(s,o,r,n);case"Literal":return yield*Op(s,o,r,n);case"Never":return yield*wp(s,o,r,n);case"Not":return yield*$p(s,o,r,n);case"Null":return yield*Sp(s,o,r,n);case"Number":return yield*kp(s,o,r,n);case"Object":return yield*Pp(s,o,r,n);case"Promise":return yield*Cp(s,o,r,n);case"Record":return yield*Ap(s,o,r,n);case"Ref":return yield*Tp(s,o,r,n);case"RegExp":return yield*Fp(s,o,r,n);case"String":return yield*Np(s,o,r,n);case"Symbol":return yield*Mp(s,o,r,n);case"TemplateLiteral":return yield*jp(s,o,r,n);case"This":return yield*Ep(s,o,r,n);case"Tuple":return yield*Up(s,o,r,n);case"Undefined":return yield*Lp(s,o,r,n);case"Union":return yield*Kp(s,o,r,n);case"Uint8Array":return yield*Bp(s,o,r,n);case"Unknown":return yield*vp(s,o,r,n);case"Void":return yield*Dp(s,o,r,n);default:if(!Qn(s[I]))throw new Ua(e);return yield*qp(s,o,r,n)}}function La(...e){let t=e.length===3?He(e[0],e[1],"",e[2]):He(e[0],[],"",e[1]);return new Ys(t)}class Qs extends oe{constructor(e,t,r){super("Unable to decode value as it does not match the expected schema");this.schema=e,this.value=t,this.error=r}}class Ka extends oe{constructor(e,t,r,n){super(n instanceof Error?n.message:"Unknown error");this.schema=e,this.path=t,this.value=r,this.error=n}}function we(e,t,r){try{return ne(e)?e[Re].Decode(r):r}catch(n){throw new Ka(e,t,r,n)}}function Gp(e,t,r,n){return Ee(n)?we(e,r,n.map((o,s)=>Bt(e.items,t,`${r}/${s}`,o))):we(e,r,n)}function Hp(e,t,r,n){if(!it(n)||jo(n))return we(e,r,n);let o=Jo(e),s=o.map((d)=>d[0]),i={...n};for(let[d,f]of o)if(d in i)i[d]=Bt(f,t,`${r}/${d}`,i[d]);if(!ne(e.unevaluatedProperties))return we(e,r,i);let a=Object.getOwnPropertyNames(i),u=e.unevaluatedProperties,c={...i};for(let d of a)if(!s.includes(d))c[d]=we(u,`${r}/${d}`,c[d]);return we(e,r,c)}function zp(e,t,r,n){let o=globalThis.Object.values(e.$defs),s=e.$defs[e.$ref],i=Bt(s,[...t,...o],r,n);return we(e,r,i)}function Vp(e,t,r,n){return we(e,r,Bt(e.not,t,r,n))}function Jp(e,t,r,n){if(!it(n))return we(e,r,n);let o=St(e),s={...n};for(let c of o){if(!Fo(s,c))continue;if(nt(s[c])&&(!ir(e.properties[c])||le.IsExactOptionalProperty(s,c)))continue;s[c]=Bt(e.properties[c],t,`${r}/${c}`,s[c])}if(!_e(e.additionalProperties))return we(e,r,s);let i=Object.getOwnPropertyNames(s),a=e.additionalProperties,u={...s};for(let c of i)if(!o.includes(c))u[c]=we(a,`${r}/${c}`,u[c]);return we(e,r,u)}function Wp(e,t,r,n){if(!it(n))return we(e,r,n);let o=Object.getOwnPropertyNames(e.patternProperties)[0],s=new RegExp(o),i={...n};for(let d of Object.getOwnPropertyNames(n))if(s.test(d))i[d]=Bt(e.patternProperties[o],t,`${r}/${d}`,i[d]);if(!_e(e.additionalProperties))return we(e,r,i);let a=Object.getOwnPropertyNames(i),u=e.additionalProperties,c={...i};for(let d of a)if(!s.test(d))c[d]=we(u,`${r}/${d}`,c[d]);return we(e,r,c)}function Xp(e,t,r,n){let o=qe(e,t);return we(e,r,Bt(o,t,r,n))}function Yp(e,t,r,n){let o=qe(e,t);return we(e,r,Bt(o,t,r,n))}function Qp(e,t,r,n){return Ee(n)&&Ee(e.items)?we(e,r,e.items.map((o,s)=>Bt(o,t,`${r}/${s}`,n[s]))):we(e,r,n)}function Zp(e,t,r,n){for(let o of e.anyOf){if(!Zr(o,t,n))continue;let s=Bt(o,t,r,n);return we(e,r,s)}return we(e,r,n)}function Bt(e,t,r,n){let o=$r(e,t),s=e;switch(e[I]){case"Array":return Gp(s,o,r,n);case"Import":return zp(s,o,r,n);case"Intersect":return Hp(s,o,r,n);case"Not":return Vp(s,o,r,n);case"Object":return Jp(s,o,r,n);case"Record":return Wp(s,o,r,n);case"Ref":return Xp(s,o,r,n);case"Symbol":return we(s,r,n);case"This":return Yp(s,o,r,n);case"Tuple":return Qp(s,o,r,n);case"Union":return Zp(s,o,r,n);default:return we(s,r,n)}}function Ba(e,t,r){return Bt(e,t,"",r)}class Zs extends oe{constructor(e,t,r){super("The encoded value does not match the expected schema");this.schema=e,this.value=t,this.error=r}}class va extends oe{constructor(e,t,r,n){super(`${n instanceof Error?n.message:"Unknown error"}`);this.schema=e,this.path=t,this.value=r,this.error=n}}function Je(e,t,r){try{return ne(e)?e[Re].Encode(r):r}catch(n){throw new va(e,t,r,n)}}function el(e,t,r,n){let o=Je(e,r,n);return Ee(o)?o.map((s,i)=>vt(e.items,t,`${r}/${i}`,s)):o}function tl(e,t,r,n){let o=globalThis.Object.values(e.$defs),s=e.$defs[e.$ref],i=Je(e,r,n);return vt(s,[...t,...o],r,i)}function rl(e,t,r,n){let o=Je(e,r,n);if(!it(n)||jo(n))return o;let s=Jo(e),i=s.map((f)=>f[0]),a={...o};for(let[f,l]of s)if(f in a)a[f]=vt(l,t,`${r}/${f}`,a[f]);if(!ne(e.unevaluatedProperties))return a;let u=Object.getOwnPropertyNames(a),c=e.unevaluatedProperties,d={...a};for(let f of u)if(!i.includes(f))d[f]=Je(c,`${r}/${f}`,d[f]);return d}function nl(e,t,r,n){return Je(e.not,r,Je(e,r,n))}function ol(e,t,r,n){let o=Je(e,r,n);if(!it(o))return o;let s=St(e),i={...o};for(let d of s){if(!Fo(i,d))continue;if(nt(i[d])&&(!ir(e.properties[d])||le.IsExactOptionalProperty(i,d)))continue;i[d]=vt(e.properties[d],t,`${r}/${d}`,i[d])}if(!_e(e.additionalProperties))return i;let a=Object.getOwnPropertyNames(i),u=e.additionalProperties,c={...i};for(let d of a)if(!s.includes(d))c[d]=Je(u,`${r}/${d}`,c[d]);return c}function sl(e,t,r,n){let o=Je(e,r,n);if(!it(n))return o;let s=Object.getOwnPropertyNames(e.patternProperties)[0],i=new RegExp(s),a={...o};for(let f of Object.getOwnPropertyNames(n))if(i.test(f))a[f]=vt(e.patternProperties[s],t,`${r}/${f}`,a[f]);if(!_e(e.additionalProperties))return a;let u=Object.getOwnPropertyNames(a),c=e.additionalProperties,d={...a};for(let f of u)if(!i.test(f))d[f]=Je(c,`${r}/${f}`,d[f]);return d}function il(e,t,r,n){let o=qe(e,t),s=vt(o,t,r,n);return Je(e,r,s)}function al(e,t,r,n){let o=qe(e,t),s=vt(o,t,r,n);return Je(e,r,s)}function cl(e,t,r,n){let o=Je(e,r,n);return Ee(e.items)?e.items.map((s,i)=>vt(s,t,`${r}/${i}`,o[i])):[]}function ul(e,t,r,n){for(let o of e.anyOf){if(!Zr(o,t,n))continue;let s=vt(o,t,r,n);return Je(e,r,s)}for(let o of e.anyOf){let s=vt(o,t,r,n);if(!Zr(e,t,s))continue;return Je(e,r,s)}return Je(e,r,n)}function vt(e,t,r,n){let o=$r(e,t),s=e;switch(e[I]){case"Array":return el(s,o,r,n);case"Import":return tl(s,o,r,n);case"Intersect":return rl(s,o,r,n);case"Not":return nl(s,o,r,n);case"Object":return ol(s,o,r,n);case"Record":return sl(s,o,r,n);case"Ref":return il(s,o,r,n);case"This":return al(s,o,r,n);case"Tuple":return cl(s,o,r,n);case"Union":return ul(s,o,r,n);default:return Je(s,r,n)}}function Da(e,t,r){return vt(e,t,"",r)}function dl(e,t){return ne(e)||ve(e.items,t)}function fl(e,t){return ne(e)||ve(e.items,t)}function ml(e,t){return ne(e)||ve(e.returns,t)||e.parameters.some((r)=>ve(r,t))}function pl(e,t){return ne(e)||ve(e.returns,t)||e.parameters.some((r)=>ve(r,t))}function ll(e,t){return ne(e)||ne(e.unevaluatedProperties)||e.allOf.some((r)=>ve(r,t))}function yl(e,t){let r=globalThis.Object.getOwnPropertyNames(e.$defs).reduce((o,s)=>[...o,e.$defs[s]],[]),n=e.$defs[e.$ref];return ne(e)||ve(n,[...r,...t])}function gl(e,t){return ne(e)||ve(e.items,t)}function hl(e,t){return ne(e)||ve(e.not,t)}function xl(e,t){return ne(e)||Object.values(e.properties).some((r)=>ve(r,t))||_e(e.additionalProperties)&&ve(e.additionalProperties,t)}function Il(e,t){return ne(e)||ve(e.item,t)}function bl(e,t){let r=Object.getOwnPropertyNames(e.patternProperties)[0],n=e.patternProperties[r];return ne(e)||ve(n,t)||_e(e.additionalProperties)&&ne(e.additionalProperties)}function Rl(e,t){if(ne(e))return!0;return ve(qe(e,t),t)}function _l(e,t){if(ne(e))return!0;return ve(qe(e,t),t)}function Ol(e,t){return ne(e)||!nt(e.items)&&e.items.some((r)=>ve(r,t))}function wl(e,t){return ne(e)||e.anyOf.some((r)=>ve(r,t))}function ve(e,t){let r=$r(e,t),n=e;if(e.$id&&ei.has(e.$id))return!1;if(e.$id)ei.add(e.$id);switch(e[I]){case"Array":return dl(n,r);case"AsyncIterator":return fl(n,r);case"Constructor":return ml(n,r);case"Function":return pl(n,r);case"Import":return yl(n,r);case"Intersect":return ll(n,r);case"Iterator":return gl(n,r);case"Not":return hl(n,r);case"Object":return xl(n,r);case"Promise":return Il(n,r);case"Record":return bl(n,r);case"Ref":return Rl(n,r);case"This":return _l(n,r);case"Tuple":return Ol(n,r);case"Union":return wl(n,r);default:return ne(e)}}var ei=new Set;function qa(e,t){return ei.clear(),ve(e,t)}class Ga{constructor(e,t,r,n){this.schema=e,this.references=t,this.checkFunc=r,this.code=n,this.hasTransform=qa(e,t)}Code(){return this.code}Schema(){return this.schema}References(){return this.references}Errors(e){return La(this.schema,this.references,e)}Check(e){return this.checkFunc(e)}Decode(e){if(!this.checkFunc(e))throw new Qs(this.schema,e,this.Errors(e).First());return this.hasTransform?Ba(this.schema,this.references,e):e}Encode(e){let t=this.hasTransform?Da(this.schema,this.references,e):e;if(!this.checkFunc(t))throw new Zs(this.schema,e,this.Errors(e).First());return t}}var lr;(function(e){function t(s){return s===36}e.DollarSign=t;function r(s){return s===95}e.IsUnderscore=r;function n(s){return s>=65&&s<=90||s>=97&&s<=122}e.IsAlpha=n;function o(s){return s>=48&&s<=57}e.IsNumeric=o})(lr||(lr={}));var os;(function(e){function t(s){if(s.length===0)return!1;return lr.IsNumeric(s.charCodeAt(0))}function r(s){if(t(s))return!1;for(let i=0;i<s.length;i++){let a=s.charCodeAt(i);if(!(lr.IsAlpha(a)||lr.IsNumeric(a)||lr.DollarSign(a)||lr.IsUnderscore(a)))return!1}return!0}function n(s){return s.replace(/'/g,"\\'")}function o(s,i){return r(i)?`${s}.${i}`:`${s}['${n(i)}']`}e.Encode=o})(os||(os={}));var ti;(function(e){function t(r){let n=[];for(let o=0;o<r.length;o++){let s=r.charCodeAt(o);if(lr.IsNumeric(s)||lr.IsAlpha(s))n.push(r.charAt(o));else n.push(`_${s}_`)}return n.join("").replace(/__/g,"_")}e.Encode=t})(ti||(ti={}));var ri;(function(e){function t(r){return r.replace(/'/g,"\\'")}e.Escape=t})(ri||(ri={}));class Ha extends oe{constructor(e){super("Unknown type");this.schema=e}}class ni extends oe{constructor(e){super("Preflight validation check failed to guard for the given schema");this.schema=e}}var en;(function(e){function t(i,a,u){return le.ExactOptionalPropertyTypes?`('${a}' in ${i} ? ${u} : true)`:`(${os.Encode(i,a)} !== undefined ? ${u} : true)`}e.IsExactOptionalProperty=t;function r(i){return!le.AllowArrayObject?`(typeof ${i} === 'object' && ${i} !== null && !Array.isArray(${i}))`:`(typeof ${i} === 'object' && ${i} !== null)`}e.IsObjectLike=r;function n(i){return!le.AllowArrayObject?`(typeof ${i} === 'object' && ${i} !== null && !Array.isArray(${i}) && !(${i} instanceof Date) && !(${i} instanceof Uint8Array))`:`(typeof ${i} === 'object' && ${i} !== null && !(${i} instanceof Date) && !(${i} instanceof Uint8Array))`}e.IsRecordLike=n;function o(i){return le.AllowNaN?`typeof ${i} === 'number'`:`Number.isFinite(${i})`}e.IsNumberLike=o;function s(i){return le.AllowNullVoid?`(${i} === undefined || ${i} === null)`:`${i} === undefined`}e.IsVoidLike=s})(en||(en={}));var lo;(function(e){function t(m){return m[I]==="Any"||m[I]==="Unknown"}function*r(m,P,p){yield"true"}function*n(m,P,p){yield"true"}function*o(m,P,p){yield`Array.isArray(${p})`;let[D,A]=[ko("value","any"),ko("acc","number")];if(H(m.maxItems))yield`${p}.length <= ${m.maxItems}`;if(H(m.minItems))yield`${p}.length >= ${m.minItems}`;let T=pt(m.items,P,"value");if(yield`${p}.every((${D}) => ${T})`,Oe(m.contains)||H(m.minContains)||H(m.maxContains)){let pe=Oe(m.contains)?m.contains:J(),st=pt(pe,P,"value"),nr=H(m.minContains)?[`(count >= ${m.minContains})`]:[],Ct=H(m.maxContains)?[`(count <= ${m.maxContains})`]:[],Wt=`const count = value.reduce((${A}, ${D}) => ${st} ? acc + 1 : acc, 0)`,Po=["(count > 0)",...nr,...Ct].join(" && ");yield`((${D}) => { ${Wt}; return ${Po}})(${p})`}if(m.uniqueItems===!0)yield`((${D}) => { const set = new Set(); for(const element of value) { const hashed = hash(element); if(set.has(hashed)) { return false } else { set.add(hashed) } } return true } )(${p})`}function*s(m,P,p){yield`(typeof value === 'object' && Symbol.asyncIterator in ${p})`}function*i(m,P,p){if(yield`(typeof ${p} === 'bigint')`,lt(m.exclusiveMaximum))yield`${p} < BigInt(${m.exclusiveMaximum})`;if(lt(m.exclusiveMinimum))yield`${p} > BigInt(${m.exclusiveMinimum})`;if(lt(m.maximum))yield`${p} <= BigInt(${m.maximum})`;if(lt(m.minimum))yield`${p} >= BigInt(${m.minimum})`;if(lt(m.multipleOf))yield`(${p} % BigInt(${m.multipleOf})) === 0`}function*a(m,P,p){yield`(typeof ${p} === 'boolean')`}function*u(m,P,p){yield*je(m.returns,P,`${p}.prototype`)}function*c(m,P,p){if(yield`(${p} instanceof Date) && Number.isFinite(${p}.getTime())`,H(m.exclusiveMaximumTimestamp))yield`${p}.getTime() < ${m.exclusiveMaximumTimestamp}`;if(H(m.exclusiveMinimumTimestamp))yield`${p}.getTime() > ${m.exclusiveMinimumTimestamp}`;if(H(m.maximumTimestamp))yield`${p}.getTime() <= ${m.maximumTimestamp}`;if(H(m.minimumTimestamp))yield`${p}.getTime() >= ${m.minimumTimestamp}`;if(H(m.multipleOfTimestamp))yield`(${p}.getTime() % ${m.multipleOfTimestamp}) === 0`}function*d(m,P,p){yield`(typeof ${p} === 'function')`}function*f(m,P,p){let D=globalThis.Object.getOwnPropertyNames(m.$defs).reduce((A,T)=>[...A,m.$defs[T]],[]);yield*je($t(m.$ref),[...P,...D],p)}function*l(m,P,p){if(yield`Number.isInteger(${p})`,H(m.exclusiveMaximum))yield`${p} < ${m.exclusiveMaximum}`;if(H(m.exclusiveMinimum))yield`${p} > ${m.exclusiveMinimum}`;if(H(m.maximum))yield`${p} <= ${m.maximum}`;if(H(m.minimum))yield`${p} >= ${m.minimum}`;if(H(m.multipleOf))yield`(${p} % ${m.multipleOf}) === 0`}function*y(m,P,p){let D=m.allOf.map((A)=>pt(A,P,p)).join(" && ");if(m.unevaluatedProperties===!1){let A=dn(`${new RegExp(ur(m))};`),T=`Object.getOwnPropertyNames(${p}).every(key => ${A}.test(key))`;yield`(${D} && ${T})`}else if(Oe(m.unevaluatedProperties)){let A=dn(`${new RegExp(ur(m))};`),T=`Object.getOwnPropertyNames(${p}).every(key => ${A}.test(key) || ${pt(m.unevaluatedProperties,P,`${p}[key]`)})`;yield`(${D} && ${T})`}else yield`(${D})`}function*b(m,P,p){yield`(typeof value === 'object' && Symbol.iterator in ${p})`}function*O(m,P,p){if(typeof m.const==="number"||typeof m.const==="boolean")yield`(${p} === ${m.const})`;else yield`(${p} === '${ri.Escape(m.const)}')`}function*B(m,P,p){yield"false"}function*q(m,P,p){yield`(!${pt(m.not,P,p)})`}function*Ce(m,P,p){yield`(${p} === null)`}function*rt(m,P,p){if(yield en.IsNumberLike(p),H(m.exclusiveMaximum))yield`${p} < ${m.exclusiveMaximum}`;if(H(m.exclusiveMinimum))yield`${p} > ${m.exclusiveMinimum}`;if(H(m.maximum))yield`${p} <= ${m.maximum}`;if(H(m.minimum))yield`${p} >= ${m.minimum}`;if(H(m.multipleOf))yield`(${p} % ${m.multipleOf}) === 0`}function*Be(m,P,p){if(yield en.IsObjectLike(p),H(m.minProperties))yield`Object.getOwnPropertyNames(${p}).length >= ${m.minProperties}`;if(H(m.maxProperties))yield`Object.getOwnPropertyNames(${p}).length <= ${m.maxProperties}`;let D=Object.getOwnPropertyNames(m.properties);for(let A of D){let T=os.Encode(p,A),pe=m.properties[A];if(m.required&&m.required.includes(A)){if(yield*je(pe,P,T),dr(pe)||t(pe))yield`('${A}' in ${p})`}else{let st=pt(pe,P,T);yield en.IsExactOptionalProperty(p,A,st)}}if(m.additionalProperties===!1)if(m.required&&m.required.length===D.length)yield`Object.getOwnPropertyNames(${p}).length === ${D.length}`;else{let A=`[${D.map((T)=>`'${T}'`).join(", ")}]`;yield`Object.getOwnPropertyNames(${p}).every(key => ${A}.includes(key))`}if(typeof m.additionalProperties==="object"){let A=pt(m.additionalProperties,P,`${p}[key]`),T=`[${D.map((pe)=>`'${pe}'`).join(", ")}]`;yield`(Object.getOwnPropertyNames(${p}).every(key => ${T}.includes(key) || ${A}))`}}function*me(m,P,p){yield`${p} instanceof Promise`}function*Ae(m,P,p){if(yield en.IsRecordLike(p),H(m.minProperties))yield`Object.getOwnPropertyNames(${p}).length >= ${m.minProperties}`;if(H(m.maxProperties))yield`Object.getOwnPropertyNames(${p}).length <= ${m.maxProperties}`;let[D,A]=Object.entries(m.patternProperties)[0],T=dn(`${new RegExp(D)}`),pe=pt(A,P,"value"),st=Oe(m.additionalProperties)?pt(m.additionalProperties,P,p):m.additionalProperties===!1?"false":"true",nr=`(${T}.test(key) ? ${pe} : ${st})`;yield`(Object.entries(${p}).every(([key, value]) => ${nr}))`}function*M(m,P,p){let D=qe(m,P);if(de.functions.has(m.$ref))return yield`${Yn(m.$ref)}(${p})`;yield*je(D,P,p)}function*k(m,P,p){let D=dn(`${new RegExp(m.source,m.flags)};`);if(yield`(typeof ${p} === 'string')`,H(m.maxLength))yield`${p}.length <= ${m.maxLength}`;if(H(m.minLength))yield`${p}.length >= ${m.minLength}`;yield`${D}.test(${p})`}function*_(m,P,p){if(yield`(typeof ${p} === 'string')`,H(m.maxLength))yield`${p}.length <= ${m.maxLength}`;if(H(m.minLength))yield`${p}.length >= ${m.minLength}`;if(m.pattern!==void 0)yield`${dn(`${new RegExp(m.pattern)};`)}.test(${p})`;if(m.format!==void 0)yield`format('${m.format}', ${p})`}function*U(m,P,p){yield`(typeof ${p} === 'symbol')`}function*j(m,P,p){yield`(typeof ${p} === 'string')`,yield`${dn(`${new RegExp(m.pattern)};`)}.test(${p})`}function*N(m,P,p){yield`${Yn(m.$ref)}(${p})`}function*G(m,P,p){if(yield`Array.isArray(${p})`,m.items===void 0)return yield`${p}.length === 0`;yield`(${p}.length === ${m.maxItems})`;for(let D=0;D<m.items.length;D++)yield`${pt(m.items[D],P,`${p}[${D}]`)}`}function*Xe(m,P,p){yield`${p} === undefined`}function*Te(m,P,p){yield`(${m.anyOf.map((A)=>pt(A,P,p)).join(" || ")})`}function*E(m,P,p){if(yield`${p} instanceof Uint8Array`,H(m.maxByteLength))yield`(${p}.length <= ${m.maxByteLength})`;if(H(m.minByteLength))yield`(${p}.length >= ${m.minByteLength})`}function*v(m,P,p){yield"true"}function*z(m,P,p){yield en.IsVoidLike(p)}function*Me(m,P,p){let D=de.instances.size;de.instances.set(D,m),yield`kind('${m[I]}', ${D}, ${p})`}function*je(m,P,p,D=!0){let A=De(m.$id)?[...P,m]:P,T=m;if(D&&De(m.$id)){let pe=Yn(m.$id);if(de.functions.has(pe))return yield`${pe}(${p})`;else{de.functions.set(pe,"<deferred>");let st=_i(pe,m,P,"value",!1);return de.functions.set(pe,st),yield`${pe}(${p})`}}switch(T[I]){case"Any":return yield*r(T,A,p);case"Argument":return yield*n(T,A,p);case"Array":return yield*o(T,A,p);case"AsyncIterator":return yield*s(T,A,p);case"BigInt":return yield*i(T,A,p);case"Boolean":return yield*a(T,A,p);case"Constructor":return yield*u(T,A,p);case"Date":return yield*c(T,A,p);case"Function":return yield*d(T,A,p);case"Import":return yield*f(T,A,p);case"Integer":return yield*l(T,A,p);case"Intersect":return yield*y(T,A,p);case"Iterator":return yield*b(T,A,p);case"Literal":return yield*O(T,A,p);case"Never":return yield*B(T,A,p);case"Not":return yield*q(T,A,p);case"Null":return yield*Ce(T,A,p);case"Number":return yield*rt(T,A,p);case"Object":return yield*Be(T,A,p);case"Promise":return yield*me(T,A,p);case"Record":return yield*Ae(T,A,p);case"Ref":return yield*M(T,A,p);case"RegExp":return yield*k(T,A,p);case"String":return yield*_(T,A,p);case"Symbol":return yield*U(T,A,p);case"TemplateLiteral":return yield*j(T,A,p);case"This":return yield*N(T,A,p);case"Tuple":return yield*G(T,A,p);case"Undefined":return yield*Xe(T,A,p);case"Union":return yield*Te(T,A,p);case"Uint8Array":return yield*E(T,A,p);case"Unknown":return yield*v(T,A,p);case"Void":return yield*z(T,A,p);default:if(!Qn(T[I]))throw new Ha(m);return yield*Me(T,A,p)}}let de={language:"javascript",functions:new Map,variables:new Map,instances:new Map};function pt(m,P,p,D=!0){return`(${[...je(m,P,p,D)].join(" && ")})`}function Yn(m){return`check_${ti.Encode(m)}`}function dn(m){let P=`local_${de.variables.size}`;return de.variables.set(P,`const ${P} = ${m}`),P}function _i(m,P,p,D,A=!0){let[T,pe]=[`
3
- `,(Wt)=>"".padStart(Wt," ")],st=ko("value","any"),nr=Oi("boolean"),Ct=[...je(P,p,D,A)].map((Wt)=>`${pe(4)}${Wt}`).join(` &&${T}`);return`function ${m}(${st})${nr} {${T}${pe(2)}return (${T}${Ct}${T}${pe(2)})
4
- }`}function ko(m,P){let p=de.language==="typescript"?`: ${P}`:"";return`${m}${p}`}function Oi(m){return de.language==="typescript"?`: ${m}`:""}function fu(m,P,p){let D=_i("check",m,P,"value"),A=ko("value","any"),T=Oi("boolean"),pe=[...de.functions.values()],st=[...de.variables.values()],nr=De(m.$id)?`return function check(${A})${T} {
5
- return ${Yn(m.$id)}(value)
6
- }`:`return ${D}`;return[...st,...pe,nr].join(`
7
- `)}function wi(...m){let P={language:"javascript"},[p,D,A]=m.length===2&&Ee(m[1])?[m[0],m[1],P]:m.length===2&&!Ee(m[1])?[m[0],[],m[1]]:m.length===3?[m[0],m[1],m[2]]:m.length===1?[m[0],[],P]:[null,[],P];if(de.language=A.language,de.variables.clear(),de.functions.clear(),de.instances.clear(),!Oe(p))throw new ni(p);for(let T of D)if(!Oe(T))throw new ni(T);return fu(p,D,A)}e.Code=wi;function mu(m,P=[]){let p=wi(m,P,{language:"javascript"}),D=globalThis.Function("kind","format","hash",p),A=new Map(de.instances);function T(Ct,Wt,Po){if(!Qn(Ct)||!A.has(Wt))return!1;let pu=Ts(Ct),lu=A.get(Wt);return pu(lu,Po)}function pe(Ct,Wt){if(!Cs(Ct))return!1;return As(Ct)(Wt)}function st(Ct){return $n(Ct)}let nr=D(T,pe,st);return new Ga(m,P,nr,p)}e.Compile=mu})(lo||(lo={}));var Q;(function(e){e.assertEqual=(o)=>{};function t(o){}e.assertIs=t;function r(o){throw Error()}e.assertNever=r,e.arrayToEnum=(o)=>{let s={};for(let i of o)s[i]=i;return s},e.getValidEnumValues=(o)=>{let s=e.objectKeys(o).filter((a)=>typeof o[o[a]]!=="number"),i={};for(let a of s)i[a]=o[a];return e.objectValues(i)},e.objectValues=(o)=>e.objectKeys(o).map(function(s){return o[s]}),e.objectKeys=typeof Object.keys==="function"?(o)=>Object.keys(o):(o)=>{let s=[];for(let i in o)if(Object.prototype.hasOwnProperty.call(o,i))s.push(i);return s},e.find=(o,s)=>{for(let i of o)if(s(i))return i;return},e.isInteger=typeof Number.isInteger==="function"?(o)=>Number.isInteger(o):(o)=>typeof o==="number"&&Number.isFinite(o)&&Math.floor(o)===o;function n(o,s=" | "){return o.map((i)=>typeof i==="string"?`'${i}'`:i).join(s)}e.joinValues=n,e.jsonStringifyReplacer=(o,s)=>{if(typeof s==="bigint")return s.toString();return s}})(Q||(Q={}));var oi;(function(e){e.mergeShapes=(t,r)=>({...t,...r})})(oi||(oi={}));var C=Q.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),er=(e)=>{switch(typeof e){case"undefined":return C.undefined;case"string":return C.string;case"number":return Number.isNaN(e)?C.nan:C.number;case"boolean":return C.boolean;case"function":return C.function;case"bigint":return C.bigint;case"symbol":return C.symbol;case"object":if(Array.isArray(e))return C.array;if(e===null)return C.null;if(e.then&&typeof e.then==="function"&&e.catch&&typeof e.catch==="function")return C.promise;if(typeof Map<"u"&&e instanceof Map)return C.map;if(typeof Set<"u"&&e instanceof Set)return C.set;if(typeof Date<"u"&&e instanceof Date)return C.date;return C.object;default:return C.unknown}};var R=Q.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"]),$l=(e)=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class mt extends Error{get errors(){return this.issues}constructor(e){super();this.issues=[],this.addIssue=(r)=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};let t=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,t);else this.__proto__=t;this.name="ZodError",this.issues=e}format(e){let t=e||function(o){return o.message},r={_errors:[]},n=(o)=>{for(let s of o.issues)if(s.code==="invalid_union")s.unionErrors.map(n);else if(s.code==="invalid_return_type")n(s.returnTypeError);else if(s.code==="invalid_arguments")n(s.argumentsError);else if(s.path.length===0)r._errors.push(t(s));else{let i=r,a=0;while(a<s.path.length){let u=s.path[a];if(a!==s.path.length-1)i[u]=i[u]||{_errors:[]};else i[u]=i[u]||{_errors:[]},i[u]._errors.push(t(s));i=i[u],a++}}};return n(this),r}static assert(e){if(!(e instanceof mt))throw Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Q.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=(t)=>t.message){let t={},r=[];for(let n of this.issues)if(n.path.length>0){let o=n.path[0];t[o]=t[o]||[],t[o].push(e(n))}else r.push(e(n));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}mt.create=(e)=>new mt(e);var Sl=(e,t)=>{let r;switch(e.code){case R.invalid_type:if(e.received===C.undefined)r="Required";else r=`Expected ${e.expected}, received ${e.received}`;break;case R.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(e.expected,Q.jsonStringifyReplacer)}`;break;case R.unrecognized_keys:r=`Unrecognized key(s) in object: ${Q.joinValues(e.keys,", ")}`;break;case R.invalid_union:r="Invalid input";break;case R.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${Q.joinValues(e.options)}`;break;case R.invalid_enum_value:r=`Invalid enum value. Expected ${Q.joinValues(e.options)}, received '${e.received}'`;break;case R.invalid_arguments:r="Invalid function arguments";break;case R.invalid_return_type:r="Invalid function return type";break;case R.invalid_date:r="Invalid date";break;case R.invalid_string:if(typeof e.validation==="object")if("includes"in e.validation){if(r=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position==="number")r=`${r} at one or more positions greater than or equal to ${e.validation.position}`}else if("startsWith"in e.validation)r=`Invalid input: must start with "${e.validation.startsWith}"`;else if("endsWith"in e.validation)r=`Invalid input: must end with "${e.validation.endsWith}"`;else Q.assertNever(e.validation);else if(e.validation!=="regex")r=`Invalid ${e.validation}`;else r="Invalid";break;case R.too_small:if(e.type==="array")r=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`;else if(e.type==="string")r=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`;else if(e.type==="number")r=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`;else if(e.type==="bigint")r=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`;else if(e.type==="date")r=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`;else r="Invalid input";break;case R.too_big:if(e.type==="array")r=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`;else if(e.type==="string")r=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`;else if(e.type==="number")r=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`;else if(e.type==="bigint")r=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`;else if(e.type==="date")r=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`;else r="Invalid input";break;case R.custom:r="Invalid input";break;case R.invalid_intersection_types:r="Intersection results could not be merged";break;case R.not_multiple_of:r=`Number must be a multiple of ${e.multipleOf}`;break;case R.not_finite:r="Number must be finite";break;default:r=t.defaultError,Q.assertNever(e)}return{message:r}},yr=Sl;var za=yr;function kl(e){za=e}function Cn(){return za}var yo=(e)=>{let{data:t,path:r,errorMaps:n,issueData:o}=e,s=[...r,...o.path||[]],i={...o,path:s};if(o.message!==void 0)return{...o,path:s,message:o.message};let a="",u=n.filter((c)=>!!c).slice().reverse();for(let c of u)a=c(i,{data:t,defaultError:a}).message;return{...o,path:s,message:a}},Pl=[];function w(e,t){let r=Cn(),n=yo({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,r,r===yr?void 0:yr].filter((o)=>!!o)});e.common.issues.push(n)}class We{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray(e,t){let r=[];for(let n of t){if(n.status==="aborted")return L;if(n.status==="dirty")e.dirty();r.push(n.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){let r=[];for(let n of t){let o=await n.key,s=await n.value;r.push({key:o,value:s})}return We.mergeObjectSync(e,r)}static mergeObjectSync(e,t){let r={};for(let n of t){let{key:o,value:s}=n;if(o.status==="aborted")return L;if(s.status==="aborted")return L;if(o.status==="dirty")e.dirty();if(s.status==="dirty")e.dirty();if(o.value!=="__proto__"&&(typeof s.value<"u"||n.alwaysSet))r[o.value]=s.value}return{status:e.value,value:r}}}var L=Object.freeze({status:"aborted"}),tn=(e)=>({status:"dirty",value:e}),tt=(e)=>({status:"valid",value:e}),ss=(e)=>e.status==="aborted",is=(e)=>e.status==="dirty",Tr=(e)=>e.status==="valid",An=(e)=>typeof Promise<"u"&&e instanceof Promise;var F;(function(e){e.errToObj=(t)=>typeof t==="string"?{message:t}:t||{},e.toString=(t)=>typeof t==="string"?t:t?.message})(F||(F={}));class Ht{constructor(e,t,r,n){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=n}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var Va=(e,t)=>{if(Tr(t))return{success:!0,data:t.value};else{if(!e.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new mt(e.common.issues);return this._error=r,this._error}}}};function V(e){if(!e)return{};let{errorMap:t,invalid_type_error:r,required_error:n,description:o}=e;if(t&&(r||n))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(t)return{errorMap:t,description:o};return{errorMap:(i,a)=>{let{message:u}=e;if(i.code==="invalid_enum_value")return{message:u??a.defaultError};if(typeof a.data>"u")return{message:u??n??a.defaultError};if(i.code!=="invalid_type")return{message:a.defaultError};return{message:u??r??a.defaultError}},description:o}}class W{get description(){return this._def.description}_getType(e){return er(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:er(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new We,ctx:{common:e.parent.common,data:e.data,parsedType:er(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let t=this._parse(e);if(An(t))throw Error("Synchronous parse encountered promise.");return t}_parseAsync(e){let t=this._parse(e);return Promise.resolve(t)}parse(e,t){let r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){let r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:er(e)},n=this._parseSync({data:e,path:r.path,parent:r});return Va(r,n)}"~validate"(e){let t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:er(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:t});return Tr(r)?{value:r.value}:{issues:t.common.issues}}catch(r){if(r?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then((r)=>Tr(r)?{value:r.value}:{issues:t.common.issues})}async parseAsync(e,t){let r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){let r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:er(e)},n=this._parse({data:e,path:r.path,parent:r}),o=await(An(n)?n:Promise.resolve(n));return Va(r,o)}refine(e,t){let r=(n)=>{if(typeof t==="string"||typeof t>"u")return{message:t};else if(typeof t==="function")return t(n);else return t};return this._refinement((n,o)=>{let s=e(n),i=()=>o.addIssue({code:R.custom,...r(n)});if(typeof Promise<"u"&&s instanceof Promise)return s.then((a)=>{if(!a)return i(),!1;else return!0});if(!s)return i(),!1;else return!0})}refinement(e,t){return this._refinement((r,n)=>{if(!e(r))return n.addIssue(typeof t==="function"?t(r,n):t),!1;else return!0})}_refinement(e){return new zt({schema:this,typeName:K.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:(t)=>this["~validate"](t)}}optional(){return Gt.create(this,this._def)}nullable(){return hr.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return qt.create(this)}promise(){return sn.create(this,this._def)}or(e){return En.create([this,e],this._def)}and(e){return Un.create(this,e,this._def)}transform(e){return new zt({...V(this._def),schema:this,typeName:K.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let t=typeof e==="function"?e:()=>e;return new vn({...V(this._def),innerType:this,defaultValue:t,typeName:K.ZodDefault})}brand(){return new cs({typeName:K.ZodBranded,type:this,...V(this._def)})}catch(e){let t=typeof e==="function"?e:()=>e;return new Dn({...V(this._def),innerType:this,catchValue:t,typeName:K.ZodCatch})}describe(e){return new this.constructor({...this._def,description:e})}pipe(e){return Ro.create(this,e)}readonly(){return qn.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var Cl=/^c[^\s-]{8,}$/i,Al=/^[0-9a-z]+$/,Tl=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Fl=/^[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,Nl=/^[a-z0-9_-]{21}$/i,Ml=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,jl=/^[-+]?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)?)??$/,El=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Ul="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",si,Ll=/^(?:(?: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])$/,Kl=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Bl=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,vl=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Dl=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,ql=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,Wa="((\\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])))",Gl=new RegExp(`^${Wa}$`);function Xa(e){let t="[0-5]\\d";if(e.precision)t=`${t}\\.\\d{${e.precision}}`;else if(e.precision==null)t=`${t}(\\.\\d+)?`;let r=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${r}`}function Hl(e){return new RegExp(`^${Xa(e)}$`)}function Ya(e){let t=`${Wa}T${Xa(e)}`,r=[];if(r.push(e.local?"Z?":"Z"),e.offset)r.push("([+-]\\d{2}:?\\d{2})");return t=`${t}(${r.join("|")})`,new RegExp(`^${t}$`)}function zl(e,t){if((t==="v4"||!t)&&Ll.test(e))return!0;if((t==="v6"||!t)&&Bl.test(e))return!0;return!1}function Vl(e,t){if(!Ml.test(e))return!1;try{let[r]=e.split(".");if(!r)return!1;let n=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),o=JSON.parse(atob(n));if(typeof o!=="object"||o===null)return!1;if("typ"in o&&o?.typ!=="JWT")return!1;if(!o.alg)return!1;if(t&&o.alg!==t)return!1;return!0}catch{return!1}}function Jl(e,t){if((t==="v4"||!t)&&Kl.test(e))return!0;if((t==="v6"||!t)&&vl.test(e))return!0;return!1}class Dt extends W{_parse(e){if(this._def.coerce)e.data=String(e.data);if(this._getType(e)!==C.string){let o=this._getOrReturnCtx(e);return w(o,{code:R.invalid_type,expected:C.string,received:o.parsedType}),L}let r=new We,n=void 0;for(let o of this._def.checks)if(o.kind==="min"){if(e.data.length<o.value)n=this._getOrReturnCtx(e,n),w(n,{code:R.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty()}else if(o.kind==="max"){if(e.data.length>o.value)n=this._getOrReturnCtx(e,n),w(n,{code:R.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty()}else if(o.kind==="length"){let s=e.data.length>o.value,i=e.data.length<o.value;if(s||i){if(n=this._getOrReturnCtx(e,n),s)w(n,{code:R.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message});else if(i)w(n,{code:R.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message});r.dirty()}}else if(o.kind==="email"){if(!El.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"email",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="emoji"){if(!si)si=new RegExp(Ul,"u");if(!si.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"emoji",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="uuid"){if(!Fl.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"uuid",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="nanoid"){if(!Nl.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"nanoid",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="cuid"){if(!Cl.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"cuid",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="cuid2"){if(!Al.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"cuid2",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="ulid"){if(!Tl.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"ulid",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),w(n,{validation:"url",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="regex"){if(o.regex.lastIndex=0,!o.regex.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"regex",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="trim")e.data=e.data.trim();else if(o.kind==="includes"){if(!e.data.includes(o.value,o.position))n=this._getOrReturnCtx(e,n),w(n,{code:R.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),r.dirty()}else if(o.kind==="toLowerCase")e.data=e.data.toLowerCase();else if(o.kind==="toUpperCase")e.data=e.data.toUpperCase();else if(o.kind==="startsWith"){if(!e.data.startsWith(o.value))n=this._getOrReturnCtx(e,n),w(n,{code:R.invalid_string,validation:{startsWith:o.value},message:o.message}),r.dirty()}else if(o.kind==="endsWith"){if(!e.data.endsWith(o.value))n=this._getOrReturnCtx(e,n),w(n,{code:R.invalid_string,validation:{endsWith:o.value},message:o.message}),r.dirty()}else if(o.kind==="datetime"){if(!Ya(o).test(e.data))n=this._getOrReturnCtx(e,n),w(n,{code:R.invalid_string,validation:"datetime",message:o.message}),r.dirty()}else if(o.kind==="date"){if(!Gl.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{code:R.invalid_string,validation:"date",message:o.message}),r.dirty()}else if(o.kind==="time"){if(!Hl(o).test(e.data))n=this._getOrReturnCtx(e,n),w(n,{code:R.invalid_string,validation:"time",message:o.message}),r.dirty()}else if(o.kind==="duration"){if(!jl.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"duration",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="ip"){if(!zl(e.data,o.version))n=this._getOrReturnCtx(e,n),w(n,{validation:"ip",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="jwt"){if(!Vl(e.data,o.alg))n=this._getOrReturnCtx(e,n),w(n,{validation:"jwt",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="cidr"){if(!Jl(e.data,o.version))n=this._getOrReturnCtx(e,n),w(n,{validation:"cidr",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="base64"){if(!Dl.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"base64",code:R.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="base64url"){if(!ql.test(e.data))n=this._getOrReturnCtx(e,n),w(n,{validation:"base64url",code:R.invalid_string,message:o.message}),r.dirty()}else Q.assertNever(o);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement((n)=>e.test(n),{validation:t,code:R.invalid_string,...F.errToObj(r)})}_addCheck(e){return new Dt({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...F.errToObj(e)})}url(e){return this._addCheck({kind:"url",...F.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...F.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...F.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...F.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...F.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...F.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...F.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...F.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...F.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...F.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...F.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...F.errToObj(e)})}datetime(e){if(typeof e==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e});return this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...F.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){if(typeof e==="string")return this._addCheck({kind:"time",precision:null,message:e});return this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...F.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...F.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...F.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...F.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...F.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...F.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...F.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...F.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...F.errToObj(t)})}nonempty(e){return this.min(1,F.errToObj(e))}trim(){return new Dt({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Dt({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Dt({...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 isCIDR(){return!!this._def.checks.find((e)=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find((e)=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find((e)=>e.kind==="base64url")}get minLength(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e}get maxLength(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e}}Dt.create=(e)=>new Dt({checks:[],typeName:K.ZodString,coerce:e?.coerce??!1,...V(e)});function Wl(e,t){let r=(e.toString().split(".")[1]||"").length,n=(t.toString().split(".")[1]||"").length,o=r>n?r:n,s=Number.parseInt(e.toFixed(o).replace(".","")),i=Number.parseInt(t.toFixed(o).replace(".",""));return s%i/10**o}class Nr extends W{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);if(this._getType(e)!==C.number){let o=this._getOrReturnCtx(e);return w(o,{code:R.invalid_type,expected:C.number,received:o.parsedType}),L}let r=void 0,n=new We;for(let o of this._def.checks)if(o.kind==="int"){if(!Q.isInteger(e.data))r=this._getOrReturnCtx(e,r),w(r,{code:R.invalid_type,expected:"integer",received:"float",message:o.message}),n.dirty()}else if(o.kind==="min"){if(o.inclusive?e.data<o.value:e.data<=o.value)r=this._getOrReturnCtx(e,r),w(r,{code:R.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),n.dirty()}else if(o.kind==="max"){if(o.inclusive?e.data>o.value:e.data>=o.value)r=this._getOrReturnCtx(e,r),w(r,{code:R.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),n.dirty()}else if(o.kind==="multipleOf"){if(Wl(e.data,o.value)!==0)r=this._getOrReturnCtx(e,r),w(r,{code:R.not_multiple_of,multipleOf:o.value,message:o.message}),n.dirty()}else if(o.kind==="finite"){if(!Number.isFinite(e.data))r=this._getOrReturnCtx(e,r),w(r,{code:R.not_finite,message:o.message}),n.dirty()}else Q.assertNever(o);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,F.toString(t))}gt(e,t){return this.setLimit("min",e,!1,F.toString(t))}lte(e,t){return this.setLimit("max",e,!0,F.toString(t))}lt(e,t){return this.setLimit("max",e,!1,F.toString(t))}setLimit(e,t,r,n){return new Nr({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:F.toString(n)}]})}_addCheck(e){return new Nr({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:F.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:F.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:F.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:F.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:F.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:F.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:F.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:F.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:F.toString(e)})}get minValue(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e}get maxValue(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e}get isInt(){return!!this._def.checks.find((e)=>e.kind==="int"||e.kind==="multipleOf"&&Q.isInteger(e.value))}get isFinite(){let e=null,t=null;for(let r of this._def.checks)if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;else if(r.kind==="min"){if(t===null||r.value>t)t=r.value}else if(r.kind==="max"){if(e===null||r.value<e)e=r.value}return Number.isFinite(t)&&Number.isFinite(e)}}Nr.create=(e)=>new Nr({checks:[],typeName:K.ZodNumber,coerce:e?.coerce||!1,...V(e)});class Mr extends W{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==C.bigint)return this._getInvalidInput(e);let r=void 0,n=new We;for(let o of this._def.checks)if(o.kind==="min"){if(o.inclusive?e.data<o.value:e.data<=o.value)r=this._getOrReturnCtx(e,r),w(r,{code:R.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),n.dirty()}else if(o.kind==="max"){if(o.inclusive?e.data>o.value:e.data>=o.value)r=this._getOrReturnCtx(e,r),w(r,{code:R.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),n.dirty()}else if(o.kind==="multipleOf"){if(e.data%o.value!==BigInt(0))r=this._getOrReturnCtx(e,r),w(r,{code:R.not_multiple_of,multipleOf:o.value,message:o.message}),n.dirty()}else Q.assertNever(o);return{status:n.value,value:e.data}}_getInvalidInput(e){let t=this._getOrReturnCtx(e);return w(t,{code:R.invalid_type,expected:C.bigint,received:t.parsedType}),L}gte(e,t){return this.setLimit("min",e,!0,F.toString(t))}gt(e,t){return this.setLimit("min",e,!1,F.toString(t))}lte(e,t){return this.setLimit("max",e,!0,F.toString(t))}lt(e,t){return this.setLimit("max",e,!1,F.toString(t))}setLimit(e,t,r,n){return new Mr({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:F.toString(n)}]})}_addCheck(e){return new Mr({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:F.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:F.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:F.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:F.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:F.toString(t)})}get minValue(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e}get maxValue(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e}}Mr.create=(e)=>new Mr({checks:[],typeName:K.ZodBigInt,coerce:e?.coerce??!1,...V(e)});class Nn extends W{_parse(e){if(this._def.coerce)e.data=Boolean(e.data);if(this._getType(e)!==C.boolean){let r=this._getOrReturnCtx(e);return w(r,{code:R.invalid_type,expected:C.boolean,received:r.parsedType}),L}return tt(e.data)}}Nn.create=(e)=>new Nn({typeName:K.ZodBoolean,coerce:e?.coerce||!1,...V(e)});class rn extends W{_parse(e){if(this._def.coerce)e.data=new Date(e.data);if(this._getType(e)!==C.date){let o=this._getOrReturnCtx(e);return w(o,{code:R.invalid_type,expected:C.date,received:o.parsedType}),L}if(Number.isNaN(e.data.getTime())){let o=this._getOrReturnCtx(e);return w(o,{code:R.invalid_date}),L}let r=new We,n=void 0;for(let o of this._def.checks)if(o.kind==="min"){if(e.data.getTime()<o.value)n=this._getOrReturnCtx(e,n),w(n,{code:R.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),r.dirty()}else if(o.kind==="max"){if(e.data.getTime()>o.value)n=this._getOrReturnCtx(e,n),w(n,{code:R.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()}else Q.assertNever(o);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new rn({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:F.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:F.toString(t)})}get minDate(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e!=null?new Date(e):null}get maxDate(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e!=null?new Date(e):null}}rn.create=(e)=>new rn({checks:[],coerce:e?.coerce||!1,typeName:K.ZodDate,...V(e)});class go extends W{_parse(e){if(this._getType(e)!==C.symbol){let r=this._getOrReturnCtx(e);return w(r,{code:R.invalid_type,expected:C.symbol,received:r.parsedType}),L}return tt(e.data)}}go.create=(e)=>new go({typeName:K.ZodSymbol,...V(e)});class Mn extends W{_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return w(r,{code:R.invalid_type,expected:C.undefined,received:r.parsedType}),L}return tt(e.data)}}Mn.create=(e)=>new Mn({typeName:K.ZodUndefined,...V(e)});class jn extends W{_parse(e){if(this._getType(e)!==C.null){let r=this._getOrReturnCtx(e);return w(r,{code:R.invalid_type,expected:C.null,received:r.parsedType}),L}return tt(e.data)}}jn.create=(e)=>new jn({typeName:K.ZodNull,...V(e)});class nn extends W{constructor(){super(...arguments);this._any=!0}_parse(e){return tt(e.data)}}nn.create=(e)=>new nn({typeName:K.ZodAny,...V(e)});class Fr extends W{constructor(){super(...arguments);this._unknown=!0}_parse(e){return tt(e.data)}}Fr.create=(e)=>new Fr({typeName:K.ZodUnknown,...V(e)});class tr extends W{_parse(e){let t=this._getOrReturnCtx(e);return w(t,{code:R.invalid_type,expected:C.never,received:t.parsedType}),L}}tr.create=(e)=>new tr({typeName:K.ZodNever,...V(e)});class ho extends W{_parse(e){if(this._getType(e)!==C.undefined){let r=this._getOrReturnCtx(e);return w(r,{code:R.invalid_type,expected:C.void,received:r.parsedType}),L}return tt(e.data)}}ho.create=(e)=>new ho({typeName:K.ZodVoid,...V(e)});class qt extends W{_parse(e){let{ctx:t,status:r}=this._processInputParams(e),n=this._def;if(t.parsedType!==C.array)return w(t,{code:R.invalid_type,expected:C.array,received:t.parsedType}),L;if(n.exactLength!==null){let s=t.data.length>n.exactLength.value,i=t.data.length<n.exactLength.value;if(s||i)w(t,{code:s?R.too_big:R.too_small,minimum:i?n.exactLength.value:void 0,maximum:s?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),r.dirty()}if(n.minLength!==null){if(t.data.length<n.minLength.value)w(t,{code:R.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),r.dirty()}if(n.maxLength!==null){if(t.data.length>n.maxLength.value)w(t,{code:R.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),r.dirty()}if(t.common.async)return Promise.all([...t.data].map((s,i)=>n.type._parseAsync(new Ht(t,s,t.path,i)))).then((s)=>We.mergeArray(r,s));let o=[...t.data].map((s,i)=>n.type._parseSync(new Ht(t,s,t.path,i)));return We.mergeArray(r,o)}get element(){return this._def.type}min(e,t){return new qt({...this._def,minLength:{value:e,message:F.toString(t)}})}max(e,t){return new qt({...this._def,maxLength:{value:e,message:F.toString(t)}})}length(e,t){return new qt({...this._def,exactLength:{value:e,message:F.toString(t)}})}nonempty(e){return this.min(1,e)}}qt.create=(e,t)=>new qt({type:e,minLength:null,maxLength:null,exactLength:null,typeName:K.ZodArray,...V(t)});function Tn(e){if(e instanceof Pe){let t={};for(let r in e.shape){let n=e.shape[r];t[r]=Gt.create(Tn(n))}return new Pe({...e._def,shape:()=>t})}else if(e instanceof qt)return new qt({...e._def,type:Tn(e.element)});else if(e instanceof Gt)return Gt.create(Tn(e.unwrap()));else if(e instanceof hr)return hr.create(Tn(e.unwrap()));else if(e instanceof rr)return rr.create(e.items.map((t)=>Tn(t)));else return e}class Pe extends W{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),t=Q.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==C.object){let u=this._getOrReturnCtx(e);return w(u,{code:R.invalid_type,expected:C.object,received:u.parsedType}),L}let{status:r,ctx:n}=this._processInputParams(e),{shape:o,keys:s}=this._getCached(),i=[];if(!(this._def.catchall instanceof tr&&this._def.unknownKeys==="strip")){for(let u in n.data)if(!s.includes(u))i.push(u)}let a=[];for(let u of s){let c=o[u],d=n.data[u];a.push({key:{status:"valid",value:u},value:c._parse(new Ht(n,d,n.path,u)),alwaysSet:u in n.data})}if(this._def.catchall instanceof tr){let u=this._def.unknownKeys;if(u==="passthrough")for(let c of i)a.push({key:{status:"valid",value:c},value:{status:"valid",value:n.data[c]}});else if(u==="strict"){if(i.length>0)w(n,{code:R.unrecognized_keys,keys:i}),r.dirty()}else if(u==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let u=this._def.catchall;for(let c of i){let d=n.data[c];a.push({key:{status:"valid",value:c},value:u._parse(new Ht(n,d,n.path,c)),alwaysSet:c in n.data})}}if(n.common.async)return Promise.resolve().then(async()=>{let u=[];for(let c of a){let d=await c.key,f=await c.value;u.push({key:d,value:f,alwaysSet:c.alwaysSet})}return u}).then((u)=>We.mergeObjectSync(r,u));else return We.mergeObjectSync(r,a)}get shape(){return this._def.shape()}strict(e){return F.errToObj,new Pe({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{let n=this._def.errorMap?.(t,r).message??r.defaultError;if(t.code==="unrecognized_keys")return{message:F.errToObj(e).message??n};return{message:n}}}:{}})}strip(){return new Pe({...this._def,unknownKeys:"strip"})}passthrough(){return new Pe({...this._def,unknownKeys:"passthrough"})}extend(e){return new Pe({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new Pe({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:K.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new Pe({...this._def,catchall:e})}pick(e){let t={};for(let r of Q.objectKeys(e))if(e[r]&&this.shape[r])t[r]=this.shape[r];return new Pe({...this._def,shape:()=>t})}omit(e){let t={};for(let r of Q.objectKeys(this.shape))if(!e[r])t[r]=this.shape[r];return new Pe({...this._def,shape:()=>t})}deepPartial(){return Tn(this)}partial(e){let t={};for(let r of Q.objectKeys(this.shape)){let n=this.shape[r];if(e&&!e[r])t[r]=n;else t[r]=n.optional()}return new Pe({...this._def,shape:()=>t})}required(e){let t={};for(let r of Q.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let o=this.shape[r];while(o instanceof Gt)o=o._def.innerType;t[r]=o}return new Pe({...this._def,shape:()=>t})}keyof(){return Qa(Q.objectKeys(this.shape))}}Pe.create=(e,t)=>new Pe({shape:()=>e,unknownKeys:"strip",catchall:tr.create(),typeName:K.ZodObject,...V(t)});Pe.strictCreate=(e,t)=>new Pe({shape:()=>e,unknownKeys:"strict",catchall:tr.create(),typeName:K.ZodObject,...V(t)});Pe.lazycreate=(e,t)=>new Pe({shape:e,unknownKeys:"strip",catchall:tr.create(),typeName:K.ZodObject,...V(t)});class En extends W{_parse(e){let{ctx:t}=this._processInputParams(e),r=this._def.options;function n(o){for(let i of o)if(i.result.status==="valid")return i.result;for(let i of o)if(i.result.status==="dirty")return t.common.issues.push(...i.ctx.common.issues),i.result;let s=o.map((i)=>new mt(i.ctx.common.issues));return w(t,{code:R.invalid_union,unionErrors:s}),L}if(t.common.async)return Promise.all(r.map(async(o)=>{let s={...t,common:{...t.common,issues:[]},parent:null};return{result:await o._parseAsync({data:t.data,path:t.path,parent:s}),ctx:s}})).then(n);else{let o=void 0,s=[];for(let a of r){let u={...t,common:{...t.common,issues:[]},parent:null},c=a._parseSync({data:t.data,path:t.path,parent:u});if(c.status==="valid")return c;else if(c.status==="dirty"&&!o)o={result:c,ctx:u};if(u.common.issues.length)s.push(u.common.issues)}if(o)return t.common.issues.push(...o.ctx.common.issues),o.result;let i=s.map((a)=>new mt(a));return w(t,{code:R.invalid_union,unionErrors:i}),L}}get options(){return this._def.options}}En.create=(e,t)=>new En({options:e,typeName:K.ZodUnion,...V(t)});var gr=(e)=>{if(e instanceof Ln)return gr(e.schema);else if(e instanceof zt)return gr(e.innerType());else if(e instanceof Kn)return[e.value];else if(e instanceof jr)return e.options;else if(e instanceof Bn)return Q.objectValues(e.enum);else if(e instanceof vn)return gr(e._def.innerType);else if(e instanceof Mn)return[void 0];else if(e instanceof jn)return[null];else if(e instanceof Gt)return[void 0,...gr(e.unwrap())];else if(e instanceof hr)return[null,...gr(e.unwrap())];else if(e instanceof cs)return gr(e.unwrap());else if(e instanceof qn)return gr(e.unwrap());else if(e instanceof Dn)return gr(e._def.innerType);else return[]};class as extends W{_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==C.object)return w(t,{code:R.invalid_type,expected:C.object,received:t.parsedType}),L;let r=this.discriminator,n=t.data[r],o=this.optionsMap.get(n);if(!o)return w(t,{code:R.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),L;if(t.common.async)return o._parseAsync({data:t.data,path:t.path,parent:t});else return o._parseSync({data:t.data,path:t.path,parent:t})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){let n=new Map;for(let o of t){let s=gr(o.shape[e]);if(!s.length)throw Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let i of s){if(n.has(i))throw Error(`Discriminator property ${String(e)} has duplicate value ${String(i)}`);n.set(i,o)}}return new as({typeName:K.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:n,...V(r)})}}function ii(e,t){let r=er(e),n=er(t);if(e===t)return{valid:!0,data:e};else if(r===C.object&&n===C.object){let o=Q.objectKeys(t),s=Q.objectKeys(e).filter((a)=>o.indexOf(a)!==-1),i={...e,...t};for(let a of s){let u=ii(e[a],t[a]);if(!u.valid)return{valid:!1};i[a]=u.data}return{valid:!0,data:i}}else if(r===C.array&&n===C.array){if(e.length!==t.length)return{valid:!1};let o=[];for(let s=0;s<e.length;s++){let i=e[s],a=t[s],u=ii(i,a);if(!u.valid)return{valid:!1};o.push(u.data)}return{valid:!0,data:o}}else if(r===C.date&&n===C.date&&+e===+t)return{valid:!0,data:e};else return{valid:!1}}class Un extends W{_parse(e){let{status:t,ctx:r}=this._processInputParams(e),n=(o,s)=>{if(ss(o)||ss(s))return L;let i=ii(o.value,s.value);if(!i.valid)return w(r,{code:R.invalid_intersection_types}),L;if(is(o)||is(s))t.dirty();return{status:t.value,value:i.data}};if(r.common.async)return 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(([o,s])=>n(o,s));else return n(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Un.create=(e,t,r)=>new Un({left:e,right:t,typeName:K.ZodIntersection,...V(r)});class rr extends W{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.array)return w(r,{code:R.invalid_type,expected:C.array,received:r.parsedType}),L;if(r.data.length<this._def.items.length)return w(r,{code:R.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),L;if(!this._def.rest&&r.data.length>this._def.items.length)w(r,{code:R.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty();let o=[...r.data].map((s,i)=>{let a=this._def.items[i]||this._def.rest;if(!a)return null;return a._parse(new Ht(r,s,r.path,i))}).filter((s)=>!!s);if(r.common.async)return Promise.all(o).then((s)=>We.mergeArray(t,s));else return We.mergeArray(t,o)}get items(){return this._def.items}rest(e){return new rr({...this._def,rest:e})}}rr.create=(e,t)=>{if(!Array.isArray(e))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new rr({items:e,typeName:K.ZodTuple,rest:null,...V(t)})};class xo extends W{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.object)return w(r,{code:R.invalid_type,expected:C.object,received:r.parsedType}),L;let n=[],o=this._def.keyType,s=this._def.valueType;for(let i in r.data)n.push({key:o._parse(new Ht(r,i,r.path,i)),value:s._parse(new Ht(r,r.data[i],r.path,i)),alwaysSet:i in r.data});if(r.common.async)return We.mergeObjectAsync(t,n);else return We.mergeObjectSync(t,n)}get element(){return this._def.valueType}static create(e,t,r){if(t instanceof W)return new xo({keyType:e,valueType:t,typeName:K.ZodRecord,...V(r)});return new xo({keyType:Dt.create(),valueType:e,typeName:K.ZodRecord,...V(t)})}}class Io extends W{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.map)return w(r,{code:R.invalid_type,expected:C.map,received:r.parsedType}),L;let n=this._def.keyType,o=this._def.valueType,s=[...r.data.entries()].map(([i,a],u)=>({key:n._parse(new Ht(r,i,r.path,[u,"key"])),value:o._parse(new Ht(r,a,r.path,[u,"value"]))}));if(r.common.async){let i=new Map;return Promise.resolve().then(async()=>{for(let a of s){let u=await a.key,c=await a.value;if(u.status==="aborted"||c.status==="aborted")return L;if(u.status==="dirty"||c.status==="dirty")t.dirty();i.set(u.value,c.value)}return{status:t.value,value:i}})}else{let i=new Map;for(let a of s){let{key:u,value:c}=a;if(u.status==="aborted"||c.status==="aborted")return L;if(u.status==="dirty"||c.status==="dirty")t.dirty();i.set(u.value,c.value)}return{status:t.value,value:i}}}}Io.create=(e,t,r)=>new Io({valueType:t,keyType:e,typeName:K.ZodMap,...V(r)});class on extends W{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==C.set)return w(r,{code:R.invalid_type,expected:C.set,received:r.parsedType}),L;let n=this._def;if(n.minSize!==null){if(r.data.size<n.minSize.value)w(r,{code:R.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),t.dirty()}if(n.maxSize!==null){if(r.data.size>n.maxSize.value)w(r,{code:R.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),t.dirty()}let o=this._def.valueType;function s(a){let u=new Set;for(let c of a){if(c.status==="aborted")return L;if(c.status==="dirty")t.dirty();u.add(c.value)}return{status:t.value,value:u}}let i=[...r.data.values()].map((a,u)=>o._parse(new Ht(r,a,r.path,u)));if(r.common.async)return Promise.all(i).then((a)=>s(a));else return s(i)}min(e,t){return new on({...this._def,minSize:{value:e,message:F.toString(t)}})}max(e,t){return new on({...this._def,maxSize:{value:e,message:F.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}on.create=(e,t)=>new on({valueType:e,minSize:null,maxSize:null,typeName:K.ZodSet,...V(t)});class Fn extends W{constructor(){super(...arguments);this.validate=this.implement}_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==C.function)return w(t,{code:R.invalid_type,expected:C.function,received:t.parsedType}),L;function r(i,a){return yo({data:i,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Cn(),yr].filter((u)=>!!u),issueData:{code:R.invalid_arguments,argumentsError:a}})}function n(i,a){return yo({data:i,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Cn(),yr].filter((u)=>!!u),issueData:{code:R.invalid_return_type,returnTypeError:a}})}let o={errorMap:t.common.contextualErrorMap},s=t.data;if(this._def.returns instanceof sn){let i=this;return tt(async function(...a){let u=new mt([]),c=await i._def.args.parseAsync(a,o).catch((l)=>{throw u.addIssue(r(a,l)),u}),d=await Reflect.apply(s,this,c);return await i._def.returns._def.type.parseAsync(d,o).catch((l)=>{throw u.addIssue(n(d,l)),u})})}else{let i=this;return tt(function(...a){let u=i._def.args.safeParse(a,o);if(!u.success)throw new mt([r(a,u.error)]);let c=Reflect.apply(s,this,u.data),d=i._def.returns.safeParse(c,o);if(!d.success)throw new mt([n(c,d.error)]);return d.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Fn({...this._def,args:rr.create(e).rest(Fr.create())})}returns(e){return new Fn({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new Fn({args:e?e:rr.create([]).rest(Fr.create()),returns:t||Fr.create(),typeName:K.ZodFunction,...V(r)})}}class Ln extends W{get schema(){return this._def.getter()}_parse(e){let{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Ln.create=(e,t)=>new Ln({getter:e,typeName:K.ZodLazy,...V(t)});class Kn extends W{_parse(e){if(e.data!==this._def.value){let t=this._getOrReturnCtx(e);return w(t,{received:t.data,code:R.invalid_literal,expected:this._def.value}),L}return{status:"valid",value:e.data}}get value(){return this._def.value}}Kn.create=(e,t)=>new Kn({value:e,typeName:K.ZodLiteral,...V(t)});function Qa(e,t){return new jr({values:e,typeName:K.ZodEnum,...V(t)})}class jr extends W{_parse(e){if(typeof e.data!=="string"){let t=this._getOrReturnCtx(e),r=this._def.values;return w(t,{expected:Q.joinValues(r),received:t.parsedType,code:R.invalid_type}),L}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has(e.data)){let t=this._getOrReturnCtx(e),r=this._def.values;return w(t,{received:t.data,code:R.invalid_enum_value,options:r}),L}return tt(e.data)}get options(){return this._def.values}get enum(){let e={};for(let t of this._def.values)e[t]=t;return e}get Values(){let e={};for(let t of this._def.values)e[t]=t;return e}get Enum(){let e={};for(let t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return jr.create(e,{...this._def,...t})}exclude(e,t=this._def){return jr.create(this.options.filter((r)=>!e.includes(r)),{...this._def,...t})}}jr.create=Qa;class Bn extends W{_parse(e){let t=Q.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==C.string&&r.parsedType!==C.number){let n=Q.objectValues(t);return w(r,{expected:Q.joinValues(n),received:r.parsedType,code:R.invalid_type}),L}if(!this._cache)this._cache=new Set(Q.getValidEnumValues(this._def.values));if(!this._cache.has(e.data)){let n=Q.objectValues(t);return w(r,{received:r.data,code:R.invalid_enum_value,options:n}),L}return tt(e.data)}get enum(){return this._def.values}}Bn.create=(e,t)=>new Bn({values:e,typeName:K.ZodNativeEnum,...V(t)});class sn extends W{unwrap(){return this._def.type}_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==C.promise&&t.common.async===!1)return w(t,{code:R.invalid_type,expected:C.promise,received:t.parsedType}),L;let r=t.parsedType===C.promise?t.data:Promise.resolve(t.data);return tt(r.then((n)=>this._def.type.parseAsync(n,{path:t.path,errorMap:t.common.contextualErrorMap})))}}sn.create=(e,t)=>new sn({type:e,typeName:K.ZodPromise,...V(t)});class zt extends W{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===K.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:t,ctx:r}=this._processInputParams(e),n=this._def.effect||null,o={addIssue:(s)=>{if(w(r,s),s.fatal)t.abort();else t.dirty()},get path(){return r.path}};if(o.addIssue=o.addIssue.bind(o),n.type==="preprocess"){let s=n.transform(r.data,o);if(r.common.async)return Promise.resolve(s).then(async(i)=>{if(t.value==="aborted")return L;let a=await this._def.schema._parseAsync({data:i,path:r.path,parent:r});if(a.status==="aborted")return L;if(a.status==="dirty")return tn(a.value);if(t.value==="dirty")return tn(a.value);return a});else{if(t.value==="aborted")return L;let i=this._def.schema._parseSync({data:s,path:r.path,parent:r});if(i.status==="aborted")return L;if(i.status==="dirty")return tn(i.value);if(t.value==="dirty")return tn(i.value);return i}}if(n.type==="refinement"){let s=(i)=>{let a=n.refinement(i,o);if(r.common.async)return Promise.resolve(a);if(a instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return i};if(r.common.async===!1){let i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(i.status==="aborted")return L;if(i.status==="dirty")t.dirty();return s(i.value),{status:t.value,value:i.value}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then((i)=>{if(i.status==="aborted")return L;if(i.status==="dirty")t.dirty();return s(i.value).then(()=>({status:t.value,value:i.value}))})}if(n.type==="transform")if(r.common.async===!1){let s=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Tr(s))return L;let i=n.transform(s.value,o);if(i instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:i}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then((s)=>{if(!Tr(s))return L;return Promise.resolve(n.transform(s.value,o)).then((i)=>({status:t.value,value:i}))});Q.assertNever(n)}}zt.create=(e,t,r)=>new zt({schema:e,typeName:K.ZodEffects,effect:t,...V(r)});zt.createWithPreprocess=(e,t,r)=>new zt({schema:t,effect:{type:"preprocess",transform:e},typeName:K.ZodEffects,...V(r)});class Gt extends W{_parse(e){if(this._getType(e)===C.undefined)return tt(void 0);return this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Gt.create=(e,t)=>new Gt({innerType:e,typeName:K.ZodOptional,...V(t)});class hr extends W{_parse(e){if(this._getType(e)===C.null)return tt(null);return this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}hr.create=(e,t)=>new hr({innerType:e,typeName:K.ZodNullable,...V(t)});class vn extends W{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;if(t.parsedType===C.undefined)r=this._def.defaultValue();return this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}vn.create=(e,t)=>new vn({innerType:e,typeName:K.ZodDefault,defaultValue:typeof t.default==="function"?t.default:()=>t.default,...V(t)});class Dn extends W{_parse(e){let{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},n=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});if(An(n))return n.then((o)=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new mt(r.common.issues)},input:r.data})}));else return{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new mt(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Dn.create=(e,t)=>new Dn({innerType:e,typeName:K.ZodCatch,catchValue:typeof t.catch==="function"?t.catch:()=>t.catch,...V(t)});class bo extends W{_parse(e){if(this._getType(e)!==C.nan){let r=this._getOrReturnCtx(e);return w(r,{code:R.invalid_type,expected:C.nan,received:r.parsedType}),L}return{status:"valid",value:e.data}}}bo.create=(e)=>new bo({typeName:K.ZodNaN,...V(e)});var Xl=Symbol("zod_brand");class cs extends W{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class Ro extends W{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let o=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});if(o.status==="aborted")return L;if(o.status==="dirty")return t.dirty(),tn(o.value);else return this._def.out._parseAsync({data:o.value,path:r.path,parent:r})})();else{let n=this._def.in._parseSync({data:r.data,path:r.path,parent:r});if(n.status==="aborted")return L;if(n.status==="dirty")return t.dirty(),{status:"dirty",value:n.value};else return this._def.out._parseSync({data:n.value,path:r.path,parent:r})}}static create(e,t){return new Ro({in:e,out:t,typeName:K.ZodPipeline})}}class qn extends W{_parse(e){let t=this._def.innerType._parse(e),r=(n)=>{if(Tr(n))n.value=Object.freeze(n.value);return n};return An(t)?t.then((n)=>r(n)):r(t)}unwrap(){return this._def.innerType}}qn.create=(e,t)=>new qn({innerType:e,typeName:K.ZodReadonly,...V(t)});function Ja(e,t){let r=typeof e==="function"?e(t):typeof e==="string"?{message:e}:e;return typeof r==="string"?{message:r}:r}function Za(e,t={},r){if(e)return nn.create().superRefine((n,o)=>{let s=e(n);if(s instanceof Promise)return s.then((i)=>{if(!i){let a=Ja(t,n),u=a.fatal??r??!0;o.addIssue({code:"custom",...a,fatal:u})}});if(!s){let i=Ja(t,n),a=i.fatal??r??!0;o.addIssue({code:"custom",...i,fatal:a})}return});return nn.create()}var Yl={object:Pe.lazycreate},K;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(K||(K={}));var Ql=(e,t={message:`Input not instance of ${e.name}`})=>Za((r)=>r instanceof e,t),ec=Dt.create,tc=Nr.create,Zl=bo.create,ey=Mr.create,rc=Nn.create,ty=rn.create,ry=go.create,ny=Mn.create,oy=jn.create,sy=nn.create,iy=Fr.create,ay=tr.create,cy=ho.create,uy=qt.create,{create:dy,strictCreate:fy}=Pe,my=En.create,py=as.create,ly=Un.create,yy=rr.create,gy=xo.create,hy=Io.create,xy=on.create,Iy=Fn.create,by=Ln.create,Ry=Kn.create,_y=jr.create,Oy=Bn.create,wy=sn.create,$y=zt.create,Sy=Gt.create,ky=hr.create,Py=zt.createWithPreprocess,Cy=Ro.create,Ay=()=>ec().optional(),Ty=()=>tc().optional(),Fy=()=>rc().optional(),Ny={string:(e)=>Dt.create({...e,coerce:!0}),number:(e)=>Nr.create({...e,coerce:!0}),boolean:(e)=>Nn.create({...e,coerce:!0}),bigint:(e)=>Mr.create({...e,coerce:!0}),date:(e)=>rn.create({...e,coerce:!0})};var My=L;var jy=us,ot=(e,t=400)=>Response.json(e,{status:t,headers:{"Content-Type":"application/json"}}),oc=(e)=>{let t=lo.Compile(e),r=async(n,o)=>{try{let s=n instanceof Object&&"req"in n,i=s?await n.jsonBody():await n.json();if(!t.Check(i)){let a=t.Errors(i).First();return ot({status:"error",code:"VALIDATION_FAILED",message:a?.message||"Invalid input",path:a?.path||"body"})}if(s)n.body=i;return o?o():void 0}catch{return ot({status:"error",message:"Malformed JSON payload"})}};return r.__schema=e,r},sc=(e)=>{let t=e.properties||{},r=Object.keys(t),n=r.length,o=Array.isArray(e.required)?new Set(e.required):null,s=async(i,a)=>{try{let u=i instanceof Object&&"req"in i,c=u?await i.jsonBody():await i.json();if(!c||typeof c!=="object"||Array.isArray(c))return ot({status:"error",message:"Invalid JSON object payload"});for(let d=0;d<n;d++){let f=r[d];if(!(Object.hasOwn(c,f)&&c[f]!==void 0)){if(!o||o.has(f))return ot({status:"error",code:"TYPE_MISMATCH",message:`Field '${f}' must be of type ${t[f]?.type}`,field:f});continue}if(typeof c[f]!==t[f]?.type)return ot({status:"error",code:"TYPE_MISMATCH",message:`Field '${f}' must be of type ${t[f]?.type}`,field:f})}if(u)i.body=c;return a?a():void 0}catch{return ot({status:"error",message:"Invalid JSON payload"})}};return s.__schema=e,s},ic=(e)=>{let t=async(r,n)=>{try{let o=r instanceof Object&&"req"in r,s=o?await r.jsonBody():await r.json(),i=await e.safeParseAsync(s);if(!i.success)return ot({status:"error",code:"ZOD_ERROR",errors:i.error.flatten()});if(o)r.body=i.data;return n?n():void 0}catch{return ot({status:"error",message:"Invalid JSON payload"})}};return t.__schema=e,t},Ey=(e)=>{if(e&&"_def"in e)return ic(e);if(e&&(e.kind||e.type||e[Symbol.for("TypeBox.Kind")]))return oc(e);return sc(e)};var _o=(e)=>{if(e&&"_def"in e)return(r)=>{let n=e.safeParse(r);return n.success?{ok:!0,data:n.data}:{ok:!1,error:n.error.flatten()}};let t=lo.Compile(e);return(r)=>{if(t.Check(r))return{ok:!0,data:r};let n=t.Errors(r).First();return{ok:!1,error:{message:n?.message||"Invalid input",path:n?.path}}}},ai=(e,t)=>{let r=e?.properties;if(!r||typeof r!=="object")return null;let n=[];for(let[o,s]of Object.entries(r)){if(o==="__proto__"||o==="constructor"||o==="prototype")continue;let i=JSON.stringify(o),a=`${t}[${i}]`,u=ai(s,a);if(u)n.push(`${i}: (${a} && typeof ${a} === 'object' && !Array.isArray(${a})) ? ${u} : ${a}`);else n.push(`${i}: ${a}`)}return`{ ${n.join(", ")} }`},ac=(e)=>{if(!e||"_def"in e)return null;if(e.type==="array"&&e.items){let r=ai(e.items,"item");if(!r)return null;return Function(`return function(arr) {
2
+ var Ac=Object.defineProperty;var Sc=(e)=>e;function Pc(e,t){this[e]=Sc.bind(null,t)}var Mi=(e,t)=>{for(var r in t)Ac(e,r,{get:t[r],enumerable:!0,configurable:!0,set:Pc.bind(t,r)})};var _s={};Mi(_s,{BRAND:()=>ny,DIRTY:()=>ln,EMPTY_PATH:()=>Mm,INVALID:()=>H,NEVER:()=>vy,OK:()=>ut,ParseStatus:()=>nt,Schema:()=>se,ZodAny:()=>yn,ZodArray:()=>Qt,ZodBigInt:()=>Gr,ZodBoolean:()=>qn,ZodBranded:()=>Is,ZodCatch:()=>Qn,ZodDate:()=>mn,ZodDefault:()=>Xn,ZodDiscriminatedUnion:()=>bs,ZodEffects:()=>tr,ZodEnum:()=>Hr,ZodError:()=>xt,ZodFirstPartyTypeKind:()=>V,ZodFunction:()=>Dn,ZodIntersection:()=>Vn,ZodIssueCode:()=>S,ZodLazy:()=>Jn,ZodLiteral:()=>Wn,ZodMap:()=>Co,ZodNaN:()=>To,ZodNativeEnum:()=>Yn,ZodNever:()=>fr,ZodNull:()=>Hn,ZodNullable:()=>Sr,ZodNumber:()=>qr,ZodObject:()=>ve,ZodOptional:()=>Zt,ZodParsedType:()=>M,ZodPipeline:()=>Fo,ZodPromise:()=>hn,ZodReadonly:()=>Zn,ZodRecord:()=>Po,ZodSchema:()=>se,ZodSet:()=>gn,ZodString:()=>Xt,ZodSymbol:()=>Ao,ZodTransformer:()=>tr,ZodTuple:()=>dr,ZodType:()=>se,ZodUndefined:()=>Gn,ZodUnion:()=>zn,ZodUnknown:()=>Dr,ZodVoid:()=>So,addIssueToContext:()=>F,any:()=>py,array:()=>gy,bigint:()=>ay,boolean:()=>pu,coerce:()=>By,custom:()=>cu,date:()=>uy,datetimeRegex:()=>au,defaultErrorMap:()=>kr,discriminatedUnion:()=>Iy,effect:()=>Fy,enum:()=>Py,function:()=>ky,getErrorMap:()=>Kn,getParsedType:()=>cr,instanceof:()=>sy,intersection:()=>_y,isAborted:()=>hs,isAsync:()=>Bn,isDirty:()=>xs,isValid:()=>vr,late:()=>oy,lazy:()=>Ay,literal:()=>Sy,makeIssue:()=>ko,map:()=>wy,nan:()=>iy,nativeEnum:()=>Cy,never:()=>my,null:()=>dy,nullable:()=>jy,number:()=>du,object:()=>hy,objectUtil:()=>mi,oboolean:()=>Ky,onumber:()=>Uy,optional:()=>Ny,ostring:()=>Ly,pipeline:()=>Ey,preprocess:()=>My,promise:()=>Ty,quotelessJson:()=>Fm,record:()=>Oy,set:()=>$y,setErrorMap:()=>jm,strictObject:()=>xy,string:()=>fu,symbol:()=>cy,transformer:()=>Fy,tuple:()=>Ry,undefined:()=>fy,union:()=>by,unknown:()=>ly,util:()=>fe,void:()=>yy});var ki={};Mi(ki,{Any:()=>Er,Argument:()=>Ou,Array:()=>wn,AsyncIterator:()=>$n,Awaited:()=>ro,BigInt:()=>Cn,Boolean:()=>rs,Capitalize:()=>Bu,Composite:()=>$u,Const:()=>ku,Constructor:()=>kn,ConstructorParameters:()=>Au,Date:()=>ws,Enum:()=>Su,Exclude:()=>no,Extends:()=>Un,Extract:()=>oo,Function:()=>ar,Index:()=>jr,InstanceType:()=>Nu,Instantiate:()=>Mu,Integer:()=>Eu,Intersect:()=>st,Iterator:()=>Tn,KeyOf:()=>Fn,Literal:()=>xe,Lowercase:()=>vu,Mapped:()=>ya,Module:()=>rc,Never:()=>ne,Not:()=>nc,Null:()=>$s,Number:()=>St,Object:()=>Ie,Omit:()=>zr,Optional:()=>ot,Parameters:()=>oc,Partial:()=>so,Pick:()=>Vr,Promise:()=>ss,Readonly:()=>yt,ReadonlyOptional:()=>Cs,Record:()=>Ts,Recursive:()=>sc,Ref:()=>Tt,RegExp:()=>ic,Required:()=>io,Rest:()=>ac,ReturnType:()=>uc,String:()=>Ht,Symbol:()=>ks,TemplateLiteral:()=>os,Transform:()=>dc,Tuple:()=>Pt,Uint8Array:()=>Ss,Uncapitalize:()=>Du,Undefined:()=>As,Union:()=>be,Unknown:()=>Lr,Unsafe:()=>qi,Uppercase:()=>qu,Void:()=>pc});function vo(e){return pt(e)&&globalThis.Symbol.asyncIterator in e}function Do(e){return pt(e)&&globalThis.Symbol.iterator in e}function qo(e){return e instanceof globalThis.Promise}function _n(e){return e instanceof Date&&globalThis.Number.isFinite(e.getTime())}function Rn(e){return e instanceof globalThis.Uint8Array}function Go(e,t){return t in e}function pt(e){return e!==null&&typeof e==="object"}function Ge(e){return globalThis.Array.isArray(e)&&!globalThis.ArrayBuffer.isView(e)}function ft(e){return e===void 0}function Wr(e){return e===null}function Yr(e){return typeof e==="boolean"}function X(e){return typeof e==="number"}function Ho(e){return globalThis.Number.isInteger(e)}function bt(e){return typeof e==="bigint"}function Ye(e){return typeof e==="string"}function zo(e){return typeof e==="function"}function Xr(e){return typeof e==="symbol"}function Vo(e){return bt(e)||Yr(e)||Wr(e)||X(e)||Ye(e)||Xr(e)||ft(e)}var ke;(function(e){e.InstanceMode="default",e.ExactOptionalPropertyTypes=!1,e.AllowArrayObject=!1,e.AllowNaN=!1,e.AllowNullVoid=!1;function t(i,a){return e.ExactOptionalPropertyTypes?a in i:i[a]!==void 0}e.IsExactOptionalProperty=t;function r(i){let a=pt(i);return e.AllowArrayObject?a:a&&!Ge(i)}e.IsObjectLike=r;function n(i){return r(i)&&!(i instanceof Date)&&!(i instanceof Uint8Array)}e.IsRecordLike=n;function o(i){return e.AllowNaN?X(i):Number.isFinite(i)}e.IsNumberLike=o;function s(i){let a=ft(i);return e.AllowNullVoid?a||i===null:a}e.IsVoidLike=s})(ke||(ke={}));var Ei=new Map;function Ks(e){return Ei.has(e)}function Bs(e){return Ei.get(e)}var Li=new Map;function co(e){return Li.has(e)}function vs(e){return Li.get(e)}function Ui(e){return Te(e)&&!He(e)&&!Cr(e)&&Symbol.asyncIterator in e}function He(e){return Array.isArray(e)}function Yo(e){return typeof e==="bigint"}function Pr(e){return typeof e==="boolean"}function On(e){return e instanceof globalThis.Date}function Ki(e){return typeof e==="function"}function Bi(e){return Te(e)&&!He(e)&&!Cr(e)&&Symbol.iterator in e}function vi(e){return e===null}function It(e){return typeof e==="number"}function Te(e){return typeof e==="object"&&e!==null}function Xo(e){return e instanceof globalThis.RegExp}function Ae(e){return typeof e==="string"}function Di(e){return typeof e==="symbol"}function Cr(e){return e instanceof globalThis.Uint8Array}function Se(e){return e===void 0}function Cc(e){return globalThis.Object.freeze(e).map((t)=>fo(t))}function Tc(e){return e}function Fc(e){return e}function Nc(e){return e}function jc(e){let t={};for(let r of Object.getOwnPropertyNames(e))t[r]=fo(e[r]);for(let r of Object.getOwnPropertySymbols(e))t[r]=fo(e[r]);return globalThis.Object.freeze(t)}function fo(e){return He(e)?Cc(e):On(e)?Tc(e):Cr(e)?Fc(e):Xo(e)?Nc(e):Te(e)?jc(e):e}function Mc(e){return e.map((t)=>Qo(t))}function Ec(e){return new Date(e.getTime())}function Lc(e){return new Uint8Array(e)}function Uc(e){return new RegExp(e.source,e.flags)}function Kc(e){let t={};for(let r of Object.getOwnPropertyNames(e))t[r]=Qo(e[r]);for(let r of Object.getOwnPropertySymbols(e))t[r]=Qo(e[r]);return t}function Qo(e){return He(e)?Mc(e):On(e)?Ec(e):Cr(e)?Lc(e):Xo(e)?Uc(e):Te(e)?Kc(e):e}function Fe(e){return Qo(e)}function I(e,t){let r=t!==void 0?{...t,...e}:e;switch(ke.InstanceMode){case"freeze":return fo(r);case"clone":return Fe(r);default:return r}}var je=Symbol.for("TypeBox.Transform"),sr=Symbol.for("TypeBox.Readonly"),et=Symbol.for("TypeBox.Optional"),ir=Symbol.for("TypeBox.Hint"),O=Symbol.for("TypeBox.Kind");function qi(e={}){return I({[O]:e[O]??"Unsafe"},e)}class he extends Error{constructor(e){super(e)}}function me(e){return I({[O]:"MappedResult",properties:e})}function Bc(e,t){let{[t]:r,...n}=e;return n}function Ue(e,t){return t.reduce((r,n)=>Bc(r,n),e)}function wn(e,t){return I({[O]:"Array",type:"array",items:e},t)}function $n(e,t){return I({[O]:"AsyncIterator",type:"AsyncIterator",items:e},t)}function kn(e,t,r){return I({[O]:"Constructor",type:"Constructor",parameters:e,returns:t},r)}function ar(e,t,r){return I({[O]:"Function",type:"Function",parameters:e,returns:t},r)}function Pe(e,t,r){return I({[O]:"Computed",target:e,parameters:t},r)}function ne(e){return I({[O]:"Never",not:{}},e)}function An(e){return Te(e)&&e[sr]==="Readonly"}function lt(e){return Te(e)&&e[et]==="Optional"}function Ds(e){return de(e,"Any")}function qs(e){return de(e,"Argument")}function Kt(e){return de(e,"Array")}function Zr(e){return de(e,"AsyncIterator")}function en(e){return de(e,"BigInt")}function yr(e){return de(e,"Boolean")}function Bt(e){return de(e,"Computed")}function vt(e){return de(e,"Constructor")}function vc(e){return de(e,"Date")}function Dt(e){return de(e,"Function")}function qt(e){return de(e,"Integer")}function Ke(e){return de(e,"Intersect")}function tn(e){return de(e,"Iterator")}function de(e,t){return Te(e)&&O in e&&e[O]===t}function Zo(e){return Pr(e)||It(e)||Ae(e)}function _t(e){return de(e,"Literal")}function Rt(e){return de(e,"MappedKey")}function Ne(e){return de(e,"MappedResult")}function Tr(e){return de(e,"Never")}function Dc(e){return de(e,"Not")}function po(e){return de(e,"Null")}function Gt(e){return de(e,"Number")}function qe(e){return de(e,"Object")}function rn(e){return de(e,"Promise")}function nn(e){return de(e,"Record")}function De(e){return de(e,"Ref")}function Gs(e){return de(e,"RegExp")}function gr(e){return de(e,"String")}function lo(e){return de(e,"Symbol")}function Ot(e){return de(e,"TemplateLiteral")}function qc(e){return de(e,"This")}function ye(e){return Te(e)&&je in e}function wt(e){return de(e,"Tuple")}function hr(e){return de(e,"Undefined")}function le(e){return de(e,"Union")}function Gc(e){return de(e,"Uint8Array")}function Hc(e){return de(e,"Unknown")}function zc(e){return de(e,"Unsafe")}function Vc(e){return de(e,"Void")}function Jc(e){return Te(e)&&O in e&&Ae(e[O])}function Me(e){return Ds(e)||qs(e)||Kt(e)||yr(e)||en(e)||Zr(e)||Bt(e)||vt(e)||vc(e)||Dt(e)||qt(e)||Ke(e)||tn(e)||_t(e)||Rt(e)||Ne(e)||Tr(e)||Dc(e)||po(e)||Gt(e)||qe(e)||rn(e)||nn(e)||De(e)||Gs(e)||gr(e)||lo(e)||Ot(e)||qc(e)||wt(e)||hr(e)||le(e)||Gc(e)||Hc(e)||zc(e)||Vc(e)||Jc(e)}function Wc(e){return I(Ue(e,[et]))}function Yc(e){return I({...e,[et]:"Optional"})}function Xc(e,t){return t===!1?Wc(e):Yc(e)}function ot(e,t){let r=t??!0;return Ne(e)?Gi(e,r):Xc(e,r)}function Qc(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=ot(e[n],t);return r}function Zc(e,t){return Qc(e.properties,t)}function Gi(e,t){let r=Zc(e,t);return me(r)}function mo(e,t={}){let r=e.every((o)=>qe(o)),n=Me(t.unevaluatedProperties)?{unevaluatedProperties:t.unevaluatedProperties}:{};return I(t.unevaluatedProperties===!1||Me(t.unevaluatedProperties)||r?{...n,[O]:"Intersect",type:"object",allOf:e}:{...n,[O]:"Intersect",allOf:e},t)}function ef(e){return e.every((t)=>lt(t))}function tf(e){return Ue(e,[et])}function Hi(e){return e.map((t)=>lt(t)?tf(t):t)}function rf(e,t){return ef(e)?ot(mo(Hi(e),t)):mo(Hi(e),t)}function es(e,t={}){if(e.length===1)return I(e[0],t);if(e.length===0)return ne(t);if(e.some((r)=>ye(r)))throw Error("Cannot intersect transform types");return rf(e,t)}function st(e,t){if(e.length===1)return I(e[0],t);if(e.length===0)return ne(t);if(e.some((r)=>ye(r)))throw Error("Cannot intersect transform types");return mo(e,t)}function yo(e,t){return I({[O]:"Union",anyOf:e},t)}function nf(e){return e.some((t)=>lt(t))}function zi(e){return e.map((t)=>lt(t)?of(t):t)}function of(e){return Ue(e,[et])}function sf(e,t){return nf(e)?ot(yo(zi(e),t)):yo(zi(e),t)}function ur(e,t){return e.length===1?I(e[0],t):e.length===0?ne(t):sf(e,t)}function be(e,t){return e.length===0?ne(t):e.length===1?I(e[0],t):yo(e,t)}class Hs extends he{}function af(e){return e.replace(/\\\$/g,"$").replace(/\\\*/g,"*").replace(/\\\^/g,"^").replace(/\\\|/g,"|").replace(/\\\(/g,"(").replace(/\\\)/g,")")}function zs(e,t,r){return e[t]===r&&e.charCodeAt(t-1)!==92}function br(e,t){return zs(e,t,"(")}function go(e,t){return zs(e,t,")")}function Vi(e,t){return zs(e,t,"|")}function uf(e){if(!(br(e,0)&&go(e,e.length-1)))return!1;let t=0;for(let r=0;r<e.length;r++){if(br(e,r))t+=1;if(go(e,r))t-=1;if(t===0&&r!==e.length-1)return!1}return!0}function cf(e){return e.slice(1,e.length-1)}function ff(e){let t=0;for(let r=0;r<e.length;r++){if(br(e,r))t+=1;if(go(e,r))t-=1;if(Vi(e,r)&&t===0)return!0}return!1}function df(e){for(let t=0;t<e.length;t++)if(br(e,t))return!0;return!1}function pf(e){let[t,r]=[0,0],n=[];for(let s=0;s<e.length;s++){if(br(e,s))t+=1;if(go(e,s))t-=1;if(Vi(e,s)&&t===0){let i=e.slice(r,s);if(i.length>0)n.push(Sn(i));r=s+1}}let o=e.slice(r);if(o.length>0)n.push(Sn(o));if(n.length===0)return{type:"const",const:""};if(n.length===1)return n[0];return{type:"or",expr:n}}function lf(e){function t(o,s){if(!br(o,s))throw new Hs("TemplateLiteralParser: Index must point to open parens");let i=0;for(let a=s;a<o.length;a++){if(br(o,a))i+=1;if(go(o,a))i-=1;if(i===0)return[s,a]}throw new Hs("TemplateLiteralParser: Unclosed group parens in expression")}function r(o,s){for(let i=s;i<o.length;i++)if(br(o,i))return[s,i];return[s,o.length]}let n=[];for(let o=0;o<e.length;o++)if(br(e,o)){let[s,i]=t(e,o),a=e.slice(s,i+1);n.push(Sn(a)),o=i}else{let[s,i]=r(e,o),a=e.slice(s,i);if(a.length>0)n.push(Sn(a));o=i-1}return n.length===0?{type:"const",const:""}:n.length===1?n[0]:{type:"and",expr:n}}function Sn(e){return uf(e)?Sn(cf(e)):ff(e)?pf(e):df(e)?lf(e):{type:"const",const:af(e)}}function Pn(e){return Sn(e.slice(1,e.length-1))}class Ji extends he{}function mf(e){return e.type==="or"&&e.expr.length===2&&e.expr[0].type==="const"&&e.expr[0].const==="0"&&e.expr[1].type==="const"&&e.expr[1].const==="[1-9][0-9]*"}function yf(e){return e.type==="or"&&e.expr.length===2&&e.expr[0].type==="const"&&e.expr[0].const==="true"&&e.expr[1].type==="const"&&e.expr[1].const==="false"}function gf(e){return e.type==="const"&&e.const===".*"}function on(e){return mf(e)||gf(e)?!1:yf(e)?!0:e.type==="and"?e.expr.every((t)=>on(t)):e.type==="or"?e.expr.every((t)=>on(t)):e.type==="const"?!0:(()=>{throw new Ji("Unknown expression type")})()}function Wi(e){let t=Pn(e.pattern);return on(t)}class Yi extends he{}function*Xi(e){if(e.length===1)return yield*e[0];for(let t of e[0])for(let r of Xi(e.slice(1)))yield`${t}${r}`}function*hf(e){return yield*Xi(e.expr.map((t)=>[...ho(t)]))}function*xf(e){for(let t of e.expr)yield*ho(t)}function*bf(e){return yield e.const}function*ho(e){return e.type==="and"?yield*hf(e):e.type==="or"?yield*xf(e):e.type==="const"?yield*bf(e):(()=>{throw new Yi("Unknown expression")})()}function ts(e){let t=Pn(e.pattern);return on(t)?[...ho(t)]:[]}function xe(e,t){return I({[O]:"Literal",const:e,type:typeof e},t)}function rs(e){return I({[O]:"Boolean",type:"boolean"},e)}function Cn(e){return I({[O]:"BigInt",type:"bigint"},e)}function St(e){return I({[O]:"Number",type:"number"},e)}function Ht(e){return I({[O]:"String",type:"string"},e)}function*If(e){let t=e.trim().replace(/"|'/g,"");return t==="boolean"?yield rs():t==="number"?yield St():t==="bigint"?yield Cn():t==="string"?yield Ht():yield(()=>{let r=t.split("|").map((n)=>xe(n.trim()));return r.length===0?ne():r.length===1?r[0]:ur(r)})()}function*_f(e){if(e[1]!=="{"){let t=xe("$"),r=Vs(e.slice(1));return yield*[t,...r]}for(let t=2;t<e.length;t++)if(e[t]==="}"){let r=If(e.slice(2,t)),n=Vs(e.slice(t+1));return yield*[...r,...n]}yield xe(e)}function*Vs(e){for(let t=0;t<e.length;t++)if(e[t]==="$"){let r=xe(e.slice(0,t)),n=_f(e.slice(t));return yield*[r,...n]}yield xe(e)}function Qi(e){return[...Vs(e)]}var Zi="(true|false)",ns="(0|[1-9][0-9]*)",ea="(.*)";var Fr="^(0|[1-9][0-9]*)$",Nr="^(.*)$",ta="^(?!.*)$";class ra extends he{}function Rf(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function na(e,t){return Ot(e)?e.pattern.slice(1,e.pattern.length-1):le(e)?`(${e.anyOf.map((r)=>na(r,t)).join("|")})`:Gt(e)?`${t}${ns}`:qt(e)?`${t}${ns}`:en(e)?`${t}${ns}`:gr(e)?`${t}${ea}`:_t(e)?`${t}${Rf(e.const.toString())}`:yr(e)?`${t}${Zi}`:(()=>{throw new ra(`Unexpected Kind '${e[O]}'`)})()}function Js(e){return`^${e.map((t)=>na(t,"")).join("")}$`}function sn(e){let r=ts(e).map((n)=>xe(n));return ur(r)}function os(e,t){let r=Ae(e)?Js(Qi(e)):Js(e);return I({[O]:"TemplateLiteral",type:"string",pattern:r},t)}function Of(e){return ts(e).map((r)=>r.toString())}function wf(e){let t=[];for(let r of e)t.push(...mt(r));return t}function $f(e){return[e.toString()]}function mt(e){return[...new Set(Ot(e)?Of(e):le(e)?wf(e.anyOf):_t(e)?$f(e.const):Gt(e)?["[number]"]:qt(e)?["[number]"]:[])]}function kf(e,t,r){let n={};for(let o of Object.getOwnPropertyNames(t))n[o]=jr(e,mt(t[o]),r);return n}function Af(e,t,r){return kf(e,t.properties,r)}function oa(e,t,r){let n=Af(e,t,r);return me(n)}function ia(e,t){return e.map((r)=>aa(r,t))}function Sf(e){return e.filter((t)=>!Tr(t))}function Pf(e,t){return es(Sf(ia(e,t)))}function Cf(e){return e.some((t)=>Tr(t))?[]:e}function Tf(e,t){return ur(Cf(ia(e,t)))}function Ff(e,t){return t in e?e[t]:t==="[number]"?ur(e):ne()}function Nf(e,t){return t==="[number]"?e:ne()}function jf(e,t){return t in e?e[t]:ne()}function aa(e,t){return Ke(e)?Pf(e.allOf,t):le(e)?Tf(e.anyOf,t):wt(e)?Ff(e.items??[],t):Kt(e)?Nf(e.items,t):qe(e)?jf(e.properties,t):ne()}function xo(e,t){return t.map((r)=>aa(e,r))}function sa(e,t){return ur(xo(e,t))}function jr(e,t,r){if(De(e)||De(t)){if(!Me(e)||!Me(t))throw new he("Index types using Ref parameters require both Type and Key to be of TSchema");return Pe("Index",[e,t])}if(Ne(t))return oa(e,t,r);if(Rt(t))return ua(e,t,r);return I(Me(t)?sa(e,mt(t)):sa(e,t),r)}function Mf(e,t,r){return{[t]:jr(e,[t],Fe(r))}}function Ef(e,t,r){return t.reduce((n,o)=>({...n,...Mf(e,o,r)}),{})}function Lf(e,t,r){return Ef(e,t.keys,r)}function ua(e,t,r){let n=Lf(e,t,r);return me(n)}function Tn(e,t){return I({[O]:"Iterator",type:"Iterator",items:e},t)}function Uf(e){return globalThis.Object.keys(e).filter((t)=>!lt(e[t]))}function Kf(e,t){let r=Uf(e),n=r.length>0?{[O]:"Object",type:"object",required:r,properties:e}:{[O]:"Object",type:"object",properties:e};return I(n,t)}var Ie=Kf;function ss(e,t){return I({[O]:"Promise",type:"Promise",item:e},t)}function Bf(e){return I(Ue(e,[sr]))}function vf(e){return I({...e,[sr]:"Readonly"})}function Df(e,t){return t===!1?Bf(e):vf(e)}function yt(e,t){let r=t??!0;return Ne(e)?ca(e,r):Df(e,r)}function qf(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=yt(e[n],t);return r}function Gf(e,t){return qf(e.properties,t)}function ca(e,t){let r=Gf(e,t);return me(r)}function Pt(e,t){return I(e.length>0?{[O]:"Tuple",type:"array",items:e,additionalItems:!1,minItems:e.length,maxItems:e.length}:{[O]:"Tuple",type:"array",minItems:e.length,maxItems:e.length},t)}function fa(e,t){return e.includes(t)}function da(e){return[...new Set(e)]}function Hf(e,t){return e.filter((r)=>t.includes(r))}function zf(e,t){return e.reduce((r,n)=>Hf(r,n),t)}function pa(e){return e.length===1?e[0]:e.length>1?zf(e.slice(1),e[0]):[]}function la(e){let t=[];for(let r of e)t.push(...r);return t}function ma(e,t){return e in t?Ct(e,t[e]):me(t)}function Vf(e){return{[e]:xe(e)}}function Jf(e){let t={};for(let r of e)t[r]=xe(r);return t}function Wf(e,t){return fa(t,e)?Vf(e):Jf(t)}function Yf(e,t){let r=Wf(e,t);return ma(e,r)}function bo(e,t){return t.map((r)=>Ct(e,r))}function Xf(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(t))r[n]=Ct(e,t[n]);return r}function Ct(e,t){let r={...t};return lt(t)?ot(Ct(e,Ue(t,[et]))):An(t)?yt(Ct(e,Ue(t,[sr]))):Ne(t)?ma(e,t.properties):Rt(t)?Yf(e,t.keys):vt(t)?kn(bo(e,t.parameters),Ct(e,t.returns),r):Dt(t)?ar(bo(e,t.parameters),Ct(e,t.returns),r):Zr(t)?$n(Ct(e,t.items),r):tn(t)?Tn(Ct(e,t.items),r):Ke(t)?st(bo(e,t.allOf),r):le(t)?be(bo(e,t.anyOf),r):wt(t)?Pt(bo(e,t.items??[]),r):qe(t)?Ie(Xf(e,t.properties),r):Kt(t)?wn(Ct(e,t.items),r):rn(t)?ss(Ct(e,t.item),r):t}function Qf(e,t){let r={};for(let n of e)r[n]=Ct(n,t);return r}function ya(e,t,r){let n=Me(e)?mt(e):e,o=t({[O]:"MappedKey",keys:n}),s=Qf(n,o);return Ie(s,r)}function Tt(...e){let[t,r]=typeof e[0]==="string"?[e[0],e[1]]:[e[0].$id,e[1]];if(typeof t!=="string")throw new he("Ref: $ref must be a string");return I({[O]:"Ref",$ref:t},r)}function ga(e){let t=[];for(let r of e)t.push(Ft(r));return t}function Zf(e){let t=ga(e);return la(t)}function ed(e){let t=ga(e);return pa(t)}function td(e){return e.map((t,r)=>r.toString())}function rd(e){return["[number]"]}function nd(e){return globalThis.Object.getOwnPropertyNames(e)}function od(e){if(!Ws)return[];return globalThis.Object.getOwnPropertyNames(e).map((r)=>r[0]==="^"&&r[r.length-1]==="$"?r.slice(1,r.length-1):r)}function Ft(e){return Ke(e)?Zf(e.allOf):le(e)?ed(e.anyOf):wt(e)?td(e.items??[]):Kt(e)?rd(e.items):qe(e)?nd(e.properties):nn(e)?od(e.patternProperties):[]}var Ws=!1;function Ir(e){Ws=!0;let t=Ft(e);return Ws=!1,`^(${t.map((n)=>`(${n})`).join("|")})$`}function sd(e,t){return Pe("KeyOf",[Pe(e,t)])}function id(e){return Pe("KeyOf",[Tt(e)])}function ad(e,t){let r=Ft(e),n=ud(r),o=ur(n);return I(o,t)}function ud(e){return e.map((t)=>t==="[number]"?St():xe(t))}function Fn(e,t){return Bt(e)?sd(e.target,e.parameters):De(e)?id(e.$ref):Ne(e)?ha(e,t):ad(e,t)}function cd(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=Fn(e[n],Fe(t));return r}function fd(e,t){return cd(e.properties,t)}function ha(e,t){let r=fd(e,t);return me(r)}function is(e){let t=Ft(e),r=xo(e,t);return t.map((n,o)=>[t[o],r[o]])}function dd(e){return e.allOf.every((t)=>_r(t))}function pd(e){return e.anyOf.some((t)=>_r(t))}function ld(e){return!_r(e.not)}function _r(e){return e[O]==="Intersect"?dd(e):e[O]==="Union"?pd(e):e[O]==="Not"?ld(e):e[O]==="Undefined"?!0:!1}function md(e){switch(e.errorType){case b.ArrayContains:return"Expected array to contain at least one matching value";case b.ArrayMaxContains:return`Expected array to contain no more than ${e.schema.maxContains} matching values`;case b.ArrayMinContains:return`Expected array to contain at least ${e.schema.minContains} matching values`;case b.ArrayMaxItems:return`Expected array length to be less or equal to ${e.schema.maxItems}`;case b.ArrayMinItems:return`Expected array length to be greater or equal to ${e.schema.minItems}`;case b.ArrayUniqueItems:return"Expected array elements to be unique";case b.Array:return"Expected array";case b.AsyncIterator:return"Expected AsyncIterator";case b.BigIntExclusiveMaximum:return`Expected bigint to be less than ${e.schema.exclusiveMaximum}`;case b.BigIntExclusiveMinimum:return`Expected bigint to be greater than ${e.schema.exclusiveMinimum}`;case b.BigIntMaximum:return`Expected bigint to be less or equal to ${e.schema.maximum}`;case b.BigIntMinimum:return`Expected bigint to be greater or equal to ${e.schema.minimum}`;case b.BigIntMultipleOf:return`Expected bigint to be a multiple of ${e.schema.multipleOf}`;case b.BigInt:return"Expected bigint";case b.Boolean:return"Expected boolean";case b.DateExclusiveMinimumTimestamp:return`Expected Date timestamp to be greater than ${e.schema.exclusiveMinimumTimestamp}`;case b.DateExclusiveMaximumTimestamp:return`Expected Date timestamp to be less than ${e.schema.exclusiveMaximumTimestamp}`;case b.DateMinimumTimestamp:return`Expected Date timestamp to be greater or equal to ${e.schema.minimumTimestamp}`;case b.DateMaximumTimestamp:return`Expected Date timestamp to be less or equal to ${e.schema.maximumTimestamp}`;case b.DateMultipleOfTimestamp:return`Expected Date timestamp to be a multiple of ${e.schema.multipleOfTimestamp}`;case b.Date:return"Expected Date";case b.Function:return"Expected function";case b.IntegerExclusiveMaximum:return`Expected integer to be less than ${e.schema.exclusiveMaximum}`;case b.IntegerExclusiveMinimum:return`Expected integer to be greater than ${e.schema.exclusiveMinimum}`;case b.IntegerMaximum:return`Expected integer to be less or equal to ${e.schema.maximum}`;case b.IntegerMinimum:return`Expected integer to be greater or equal to ${e.schema.minimum}`;case b.IntegerMultipleOf:return`Expected integer to be a multiple of ${e.schema.multipleOf}`;case b.Integer:return"Expected integer";case b.IntersectUnevaluatedProperties:return"Unexpected property";case b.Intersect:return"Expected all values to match";case b.Iterator:return"Expected Iterator";case b.Literal:return`Expected ${typeof e.schema.const==="string"?`'${e.schema.const}'`:e.schema.const}`;case b.Never:return"Never";case b.Not:return"Value should not match";case b.Null:return"Expected null";case b.NumberExclusiveMaximum:return`Expected number to be less than ${e.schema.exclusiveMaximum}`;case b.NumberExclusiveMinimum:return`Expected number to be greater than ${e.schema.exclusiveMinimum}`;case b.NumberMaximum:return`Expected number to be less or equal to ${e.schema.maximum}`;case b.NumberMinimum:return`Expected number to be greater or equal to ${e.schema.minimum}`;case b.NumberMultipleOf:return`Expected number to be a multiple of ${e.schema.multipleOf}`;case b.Number:return"Expected number";case b.Object:return"Expected object";case b.ObjectAdditionalProperties:return"Unexpected property";case b.ObjectMaxProperties:return`Expected object to have no more than ${e.schema.maxProperties} properties`;case b.ObjectMinProperties:return`Expected object to have at least ${e.schema.minProperties} properties`;case b.ObjectRequiredProperty:return"Expected required property";case b.Promise:return"Expected Promise";case b.RegExp:return"Expected string to match regular expression";case b.StringFormatUnknown:return`Unknown format '${e.schema.format}'`;case b.StringFormat:return`Expected string to match '${e.schema.format}' format`;case b.StringMaxLength:return`Expected string length less or equal to ${e.schema.maxLength}`;case b.StringMinLength:return`Expected string length greater or equal to ${e.schema.minLength}`;case b.StringPattern:return`Expected string to match '${e.schema.pattern}'`;case b.String:return"Expected string";case b.Symbol:return"Expected symbol";case b.TupleLength:return`Expected tuple to have ${e.schema.maxItems||0} elements`;case b.Tuple:return"Expected tuple";case b.Uint8ArrayMaxByteLength:return`Expected byte length less or equal to ${e.schema.maxByteLength}`;case b.Uint8ArrayMinByteLength:return`Expected byte length greater or equal to ${e.schema.minByteLength}`;case b.Uint8Array:return"Expected Uint8Array";case b.Undefined:return"Expected undefined";case b.Union:return"Expected union value";case b.Void:return"Expected void";case b.Kind:return`Expected kind '${e.schema[O]}'`;default:return"Unknown error type"}}var yd=md;function xa(){return yd}class ba extends he{constructor(e){super(`Unable to dereference schema with $id '${e.$ref}'`);this.schema=e}}function gd(e,t){let r=t.find((n)=>n.$id===e.$ref);if(r===void 0)throw new ba(e);return Xe(r,t)}function Mr(e,t){if(!Ye(e.$id)||t.some((r)=>r.$id===e.$id))return t;return t.push(e),t}function Xe(e,t){return e[O]==="This"||e[O]==="Ref"?gd(e,t):e}class Ia extends he{constructor(e){super("Unable to hash value");this.value=e}}var $t;(function(e){e[e.Undefined=0]="Undefined",e[e.Null=1]="Null",e[e.Boolean=2]="Boolean",e[e.Number=3]="Number",e[e.String=4]="String",e[e.Object=5]="Object",e[e.Array=6]="Array",e[e.Date=7]="Date",e[e.Uint8Array=8]="Uint8Array",e[e.Symbol=9]="Symbol",e[e.BigInt=10]="BigInt"})($t||($t={}));var Nn=BigInt("14695981039346656037"),[hd,xd]=[BigInt("1099511628211"),BigInt("18446744073709551616")],bd=Array.from({length:256}).map((e,t)=>BigInt(t)),_a=new Float64Array(1),Ra=new DataView(_a.buffer),Oa=new Uint8Array(_a.buffer);function*Id(e){let t=e===0?1:Math.ceil(Math.floor(Math.log2(e)+1)/8);for(let r=0;r<t;r++)yield e>>8*(t-1-r)&255}function _d(e){it($t.Array);for(let t of e)jn(t)}function Rd(e){it($t.Boolean),it(e?1:0)}function Od(e){it($t.BigInt),Ra.setBigInt64(0,e);for(let t of Oa)it(t)}function wd(e){it($t.Date),jn(e.getTime())}function $d(e){it($t.Null)}function kd(e){it($t.Number),Ra.setFloat64(0,e);for(let t of Oa)it(t)}function Ad(e){it($t.Object);for(let t of globalThis.Object.getOwnPropertyNames(e).sort())jn(t),jn(e[t])}function Sd(e){it($t.String);for(let t=0;t<e.length;t++)for(let r of Id(e.charCodeAt(t)))it(r)}function Pd(e){it($t.Symbol),jn(e.description)}function Cd(e){it($t.Uint8Array);for(let t=0;t<e.length;t++)it(e[t])}function Td(e){return it($t.Undefined)}function jn(e){if(Ge(e))return _d(e);if(Yr(e))return Rd(e);if(bt(e))return Od(e);if(_n(e))return wd(e);if(Wr(e))return $d(e);if(X(e))return kd(e);if(pt(e))return Ad(e);if(Ye(e))return Sd(e);if(Xr(e))return Pd(e);if(Rn(e))return Cd(e);if(ft(e))return Td(e);throw new Ia(e)}function it(e){Nn=Nn^bd[e],Nn=Nn*hd%xd}function Mn(e){return Nn=BigInt("14695981039346656037"),jn(e),Nn}function Er(e){return I({[O]:"Any"},e)}function Lr(e){return I({[O]:"Unknown"},e)}var Fd=["Argument","Any","Array","AsyncIterator","BigInt","Boolean","Computed","Constructor","Date","Enum","Function","Integer","Intersect","Iterator","Literal","MappedKey","MappedResult","Not","Null","Number","Object","Promise","Record","Ref","RegExp","String","Symbol","TemplateLiteral","This","Tuple","Undefined","Union","Uint8Array","Unknown","Void"];function wa(e){try{return new RegExp(e),!0}catch{return!1}}function Ys(e){if(!Ae(e))return!1;for(let t=0;t<e.length;t++){let r=e.charCodeAt(t);if(r>=7&&r<=13||r===27||r===127)return!1}return!0}function $a(e){return Xs(e)||Ee(e)}function Io(e){return Se(e)||Yo(e)}function Oe(e){return Se(e)||It(e)}function Xs(e){return Se(e)||Pr(e)}function _e(e){return Se(e)||Ae(e)}function Nd(e){return Se(e)||Ae(e)&&Ys(e)&&wa(e)}function jd(e){return Se(e)||Ae(e)&&Ys(e)}function ka(e){return Se(e)||Ee(e)}function as(e){return Te(e)&&e[et]==="Optional"}function zt(e){return pe(e,"Any")&&_e(e.$id)}function Md(e){return pe(e,"Argument")&&It(e.index)}function an(e){return pe(e,"Array")&&e.type==="array"&&_e(e.$id)&&Ee(e.items)&&Oe(e.minItems)&&Oe(e.maxItems)&&Xs(e.uniqueItems)&&ka(e.contains)&&Oe(e.minContains)&&Oe(e.maxContains)}function Qs(e){return pe(e,"AsyncIterator")&&e.type==="AsyncIterator"&&_e(e.$id)&&Ee(e.items)}function us(e){return pe(e,"BigInt")&&e.type==="bigint"&&_e(e.$id)&&Io(e.exclusiveMaximum)&&Io(e.exclusiveMinimum)&&Io(e.maximum)&&Io(e.minimum)&&Io(e.multipleOf)}function un(e){return pe(e,"Boolean")&&e.type==="boolean"&&_e(e.$id)}function Ed(e){return pe(e,"Computed")&&Ae(e.target)&&He(e.parameters)&&e.parameters.every((t)=>Ee(t))}function cs(e){return pe(e,"Constructor")&&e.type==="Constructor"&&_e(e.$id)&&He(e.parameters)&&e.parameters.every((t)=>Ee(t))&&Ee(e.returns)}function fs(e){return pe(e,"Date")&&e.type==="Date"&&_e(e.$id)&&Oe(e.exclusiveMaximumTimestamp)&&Oe(e.exclusiveMinimumTimestamp)&&Oe(e.maximumTimestamp)&&Oe(e.minimumTimestamp)&&Oe(e.multipleOfTimestamp)}function ds(e){return pe(e,"Function")&&e.type==="Function"&&_e(e.$id)&&He(e.parameters)&&e.parameters.every((t)=>Ee(t))&&Ee(e.returns)}function Rr(e){return pe(e,"Integer")&&e.type==="integer"&&_e(e.$id)&&Oe(e.exclusiveMaximum)&&Oe(e.exclusiveMinimum)&&Oe(e.maximum)&&Oe(e.minimum)&&Oe(e.multipleOf)}function Aa(e){return Te(e)&&Object.entries(e).every(([t,r])=>Ys(t)&&Ee(r))}function cn(e){return pe(e,"Intersect")&&(Ae(e.type)&&e.type!=="object"?!1:!0)&&He(e.allOf)&&e.allOf.every((t)=>Ee(t)&&!Dd(t))&&_e(e.type)&&(Xs(e.unevaluatedProperties)||ka(e.unevaluatedProperties))&&_e(e.$id)}function Zs(e){return pe(e,"Iterator")&&e.type==="Iterator"&&_e(e.$id)&&Ee(e.items)}function pe(e,t){return Te(e)&&O in e&&e[O]===t}function Sa(e){return Ur(e)&&Ae(e.const)}function Pa(e){return Ur(e)&&It(e.const)}function Ca(e){return Ur(e)&&Pr(e.const)}function Ur(e){return pe(e,"Literal")&&_e(e.$id)&&Ld(e.const)}function Ld(e){return Pr(e)||It(e)||Ae(e)}function Ud(e){return pe(e,"MappedKey")&&He(e.keys)&&e.keys.every((t)=>It(t)||Ae(t))}function Kd(e){return pe(e,"MappedResult")&&Aa(e.properties)}function Kr(e){return pe(e,"Never")&&Te(e.not)&&Object.getOwnPropertyNames(e.not).length===0}function En(e){return pe(e,"Not")&&Ee(e.not)}function ei(e){return pe(e,"Null")&&e.type==="null"&&_e(e.$id)}function gt(e){return pe(e,"Number")&&e.type==="number"&&_e(e.$id)&&Oe(e.exclusiveMaximum)&&Oe(e.exclusiveMinimum)&&Oe(e.maximum)&&Oe(e.minimum)&&Oe(e.multipleOf)}function Be(e){return pe(e,"Object")&&e.type==="object"&&_e(e.$id)&&Aa(e.properties)&&$a(e.additionalProperties)&&Oe(e.minProperties)&&Oe(e.maxProperties)}function ti(e){return pe(e,"Promise")&&e.type==="Promise"&&_e(e.$id)&&Ee(e.item)}function tt(e){return pe(e,"Record")&&e.type==="object"&&_e(e.$id)&&$a(e.additionalProperties)&&Te(e.patternProperties)&&((t)=>{let r=Object.getOwnPropertyNames(t.patternProperties);return r.length===1&&wa(r[0])&&Te(t.patternProperties)&&Ee(t.patternProperties[r[0]])})(e)}function Bd(e){return pe(e,"Ref")&&_e(e.$id)&&Ae(e.$ref)}function _o(e){return pe(e,"RegExp")&&_e(e.$id)&&Ae(e.source)&&Ae(e.flags)&&Oe(e.maxLength)&&Oe(e.minLength)}function Vt(e){return pe(e,"String")&&e.type==="string"&&_e(e.$id)&&Oe(e.minLength)&&Oe(e.maxLength)&&Nd(e.pattern)&&jd(e.format)}function Ro(e){return pe(e,"Symbol")&&e.type==="symbol"&&_e(e.$id)}function Oo(e){return pe(e,"TemplateLiteral")&&e.type==="string"&&Ae(e.pattern)&&e.pattern[0]==="^"&&e.pattern[e.pattern.length-1]==="$"}function vd(e){return pe(e,"This")&&_e(e.$id)&&Ae(e.$ref)}function Dd(e){return Te(e)&&je in e}function ps(e){return pe(e,"Tuple")&&e.type==="array"&&_e(e.$id)&&It(e.minItems)&&It(e.maxItems)&&e.minItems===e.maxItems&&(Se(e.items)&&Se(e.additionalItems)&&e.minItems===0||He(e.items)&&e.items.every((t)=>Ee(t)))}function fn(e){return pe(e,"Undefined")&&e.type==="undefined"&&_e(e.$id)}function Or(e){return pe(e,"Union")&&_e(e.$id)&&Te(e)&&He(e.anyOf)&&e.anyOf.every((t)=>Ee(t))}function wo(e){return pe(e,"Uint8Array")&&e.type==="Uint8Array"&&_e(e.$id)&&Oe(e.minByteLength)&&Oe(e.maxByteLength)}function Jt(e){return pe(e,"Unknown")&&_e(e.$id)}function qd(e){return pe(e,"Unsafe")}function ls(e){return pe(e,"Void")&&e.type==="void"&&_e(e.$id)}function Gd(e){return Te(e)&&O in e&&Ae(e[O])&&!Fd.includes(e[O])}function Ee(e){return Te(e)&&(zt(e)||Md(e)||an(e)||un(e)||us(e)||Qs(e)||Ed(e)||cs(e)||fs(e)||ds(e)||Rr(e)||cn(e)||Zs(e)||Ur(e)||Ud(e)||Kd(e)||Kr(e)||En(e)||ei(e)||gt(e)||Be(e)||ti(e)||tt(e)||Bd(e)||_o(e)||Vt(e)||Ro(e)||Oo(e)||vd(e)||ps(e)||fn(e)||Or(e)||wo(e)||Jt(e)||qd(e)||ls(e)||Gd(e))}class Ea extends he{}var _;(function(e){e[e.Union=0]="Union",e[e.True=1]="True",e[e.False=2]="False"})(_||(_={}));function Nt(e){return e===_.False?e:_.True}function Ln(e){throw new Ea(e)}function ze(e){return Kr(e)||cn(e)||Or(e)||Jt(e)||zt(e)}function Ve(e,t){return Kr(t)?Ka(e,t):cn(t)?ms(e,t):Or(t)?ii(e,t):Jt(t)?qa(e,t):zt(t)?si(e,t):Ln("StructuralRight")}function si(e,t){return _.True}function Hd(e,t){return cn(t)?ms(e,t):Or(t)&&t.anyOf.some((r)=>zt(r)||Jt(r))?_.True:Or(t)?_.Union:Jt(t)?_.True:zt(t)?_.True:_.Union}function zd(e,t){return Jt(e)?_.False:zt(e)?_.Union:Kr(e)?_.True:_.False}function Vd(e,t){return Be(t)&&ys(t)?_.True:ze(t)?Ve(e,t):!an(t)?_.False:Nt(Re(e.items,t.items))}function Jd(e,t){return ze(t)?Ve(e,t):!Qs(t)?_.False:Nt(Re(e.items,t.items))}function Wd(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):us(t)?_.True:_.False}function La(e,t){return Ca(e)?_.True:un(e)?_.True:_.False}function Yd(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):un(t)?_.True:_.False}function Xd(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):!cs(t)?_.False:e.parameters.length>t.parameters.length?_.False:!e.parameters.every((r,n)=>Nt(Re(t.parameters[n],r))===_.True)?_.False:Nt(Re(e.returns,t.returns))}function Qd(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):fs(t)?_.True:_.False}function Zd(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):!ds(t)?_.False:e.parameters.length>t.parameters.length?_.False:!e.parameters.every((r,n)=>Nt(Re(t.parameters[n],r))===_.True)?_.False:Nt(Re(e.returns,t.returns))}function Ua(e,t){return Ur(e)&&It(e.const)?_.True:gt(e)||Rr(e)?_.True:_.False}function ep(e,t){return Rr(t)||gt(t)?_.True:ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):_.False}function ms(e,t){return t.allOf.every((r)=>Re(e,r)===_.True)?_.True:_.False}function tp(e,t){return e.allOf.some((r)=>Re(r,t)===_.True)?_.True:_.False}function rp(e,t){return ze(t)?Ve(e,t):!Zs(t)?_.False:Nt(Re(e.items,t.items))}function np(e,t){return Ur(t)&&t.const===e.const?_.True:ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):Vt(t)?Da(e,t):gt(t)?Ba(e,t):Rr(t)?Ua(e,t):un(t)?La(e,t):_.False}function Ka(e,t){return _.False}function op(e,t){return _.True}function Fa(e){let[t,r]=[e,0];while(!0){if(!En(t))break;t=t.not,r+=1}return r%2===0?t:Lr()}function sp(e,t){return En(e)?Re(Fa(e),t):En(t)?Re(e,Fa(t)):Ln("Invalid fallthrough for Not")}function ip(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):ei(t)?_.True:_.False}function Ba(e,t){return Pa(e)?_.True:gt(e)||Rr(e)?_.True:_.False}function ap(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):Rr(t)||gt(t)?_.True:_.False}function ht(e,t){return Object.getOwnPropertyNames(e.properties).length===t}function Na(e){return ys(e)}function ja(e){return ht(e,0)||ht(e,1)&&"description"in e.properties&&Or(e.properties.description)&&e.properties.description.anyOf.length===2&&(Vt(e.properties.description.anyOf[0])&&fn(e.properties.description.anyOf[1])||Vt(e.properties.description.anyOf[1])&&fn(e.properties.description.anyOf[0]))}function ri(e){return ht(e,0)}function Ma(e){return ht(e,0)}function up(e){return ht(e,0)}function cp(e){return ht(e,0)}function fp(e){return ys(e)}function dp(e){let t=St();return ht(e,0)||ht(e,1)&&"length"in e.properties&&Nt(Re(e.properties.length,t))===_.True}function pp(e){return ht(e,0)}function ys(e){let t=St();return ht(e,0)||ht(e,1)&&"length"in e.properties&&Nt(Re(e.properties.length,t))===_.True}function lp(e){let t=ar([Er()],Er());return ht(e,0)||ht(e,1)&&"then"in e.properties&&Nt(Re(e.properties.then,t))===_.True}function va(e,t){return Re(e,t)===_.False?_.False:as(e)&&!as(t)?_.False:_.True}function at(e,t){return Jt(e)?_.False:zt(e)?_.Union:Kr(e)||Sa(e)&&Na(t)||Pa(e)&&ri(t)||Ca(e)&&Ma(t)||Ro(e)&&ja(t)||us(e)&&up(t)||Vt(e)&&Na(t)||Ro(e)&&ja(t)||gt(e)&&ri(t)||Rr(e)&&ri(t)||un(e)&&Ma(t)||wo(e)&&fp(t)||fs(e)&&cp(t)||cs(e)&&pp(t)||ds(e)&&dp(t)?_.True:tt(e)&&Vt(ni(e))?(()=>t[ir]==="Record"?_.True:_.False)():tt(e)&&gt(ni(e))?(()=>ht(t,0)?_.True:_.False)():_.False}function mp(e,t){return ze(t)?Ve(e,t):tt(t)?jt(e,t):!Be(t)?_.False:(()=>{for(let r of Object.getOwnPropertyNames(t.properties)){if(!(r in e.properties)&&!as(t.properties[r]))return _.False;if(as(t.properties[r]))return _.True;if(va(e.properties[r],t.properties[r])===_.False)return _.False}return _.True})()}function yp(e,t){return ze(t)?Ve(e,t):Be(t)&&lp(t)?_.True:!ti(t)?_.False:Nt(Re(e.item,t.item))}function ni(e){return Fr in e.patternProperties?St():(Nr in e.patternProperties)?Ht():Ln("Unknown record key pattern")}function oi(e){return Fr in e.patternProperties?e.patternProperties[Fr]:(Nr in e.patternProperties)?e.patternProperties[Nr]:Ln("Unable to get record value schema")}function jt(e,t){let[r,n]=[ni(t),oi(t)];return Sa(e)&&gt(r)&&Nt(Re(e,n))===_.True?_.True:wo(e)&&gt(r)?Re(e,n):Vt(e)&&gt(r)?Re(e,n):an(e)&&gt(r)?Re(e,n):Be(e)?(()=>{for(let o of Object.getOwnPropertyNames(e.properties))if(va(n,e.properties[o])===_.False)return _.False;return _.True})():_.False}function gp(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):!tt(t)?_.False:Re(oi(e),oi(t))}function hp(e,t){let r=_o(e)?Ht():e,n=_o(t)?Ht():t;return Re(r,n)}function Da(e,t){return Ur(e)&&Ae(e.const)?_.True:Vt(e)?_.True:_.False}function xp(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):Vt(t)?_.True:_.False}function bp(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):Ro(t)?_.True:_.False}function Ip(e,t){return Oo(e)?Re(sn(e),t):Oo(t)?Re(e,sn(t)):Ln("Invalid fallthrough for TemplateLiteral")}function _p(e,t){return an(t)&&e.items!==void 0&&e.items.every((r)=>Re(r,t.items)===_.True)}function Rp(e,t){return Kr(e)?_.True:Jt(e)?_.False:zt(e)?_.Union:_.False}function Op(e,t){return ze(t)?Ve(e,t):Be(t)&&ys(t)?_.True:an(t)&&_p(e,t)?_.True:!ps(t)?_.False:Se(e.items)&&!Se(t.items)||!Se(e.items)&&Se(t.items)?_.False:Se(e.items)&&!Se(t.items)?_.True:e.items.every((r,n)=>Re(r,t.items[n])===_.True)?_.True:_.False}function wp(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):wo(t)?_.True:_.False}function $p(e,t){return ze(t)?Ve(e,t):Be(t)?at(e,t):tt(t)?jt(e,t):ls(t)?Sp(e,t):fn(t)?_.True:_.False}function ii(e,t){return t.anyOf.some((r)=>Re(e,r)===_.True)?_.True:_.False}function kp(e,t){return e.anyOf.every((r)=>Re(r,t)===_.True)?_.True:_.False}function qa(e,t){return _.True}function Ap(e,t){return Kr(t)?Ka(e,t):cn(t)?ms(e,t):Or(t)?ii(e,t):zt(t)?si(e,t):Vt(t)?Da(e,t):gt(t)?Ba(e,t):Rr(t)?Ua(e,t):un(t)?La(e,t):an(t)?zd(e,t):ps(t)?Rp(e,t):Be(t)?at(e,t):Jt(t)?_.True:_.False}function Sp(e,t){return fn(e)?_.True:fn(e)?_.True:_.False}function Pp(e,t){return cn(t)?ms(e,t):Or(t)?ii(e,t):Jt(t)?qa(e,t):zt(t)?si(e,t):Be(t)?at(e,t):ls(t)?_.True:_.False}function Re(e,t){return Oo(e)||Oo(t)?Ip(e,t):_o(e)||_o(t)?hp(e,t):En(e)||En(t)?sp(e,t):zt(e)?Hd(e,t):an(e)?Vd(e,t):us(e)?Wd(e,t):un(e)?Yd(e,t):Qs(e)?Jd(e,t):cs(e)?Xd(e,t):fs(e)?Qd(e,t):ds(e)?Zd(e,t):Rr(e)?ep(e,t):cn(e)?tp(e,t):Zs(e)?rp(e,t):Ur(e)?np(e,t):Kr(e)?op(e,t):ei(e)?ip(e,t):gt(e)?ap(e,t):Be(e)?mp(e,t):tt(e)?gp(e,t):Vt(e)?xp(e,t):Ro(e)?bp(e,t):ps(e)?Op(e,t):ti(e)?yp(e,t):wo(e)?wp(e,t):fn(e)?$p(e,t):Or(e)?kp(e,t):Jt(e)?Ap(e,t):ls(e)?Pp(e,t):Ln(`Unknown left type operand '${e[O]}'`)}function Br(e,t){return Re(e,t)}function Cp(e,t,r,n,o){let s={};for(let i of globalThis.Object.getOwnPropertyNames(e))s[i]=Un(e[i],t,r,n,Fe(o));return s}function Tp(e,t,r,n,o){return Cp(e.properties,t,r,n,o)}function Ga(e,t,r,n,o){let s=Tp(e,t,r,n,o);return me(s)}function Fp(e,t,r,n){let o=Br(e,t);return o===_.Union?be([r,n]):o===_.True?r:n}function Un(e,t,r,n,o){return Ne(e)?Ga(e,t,r,n,o):Rt(e)?I(Ha(e,t,r,n,o)):I(Fp(e,t,r,n),o)}function Np(e,t,r,n,o){return{[e]:Un(xe(e),t,r,n,Fe(o))}}function jp(e,t,r,n,o){return e.reduce((s,i)=>({...s,...Np(i,t,r,n,o)}),{})}function Mp(e,t,r,n,o){return jp(e.keys,t,r,n,o)}function Ha(e,t,r,n,o){let s=Mp(e,t,r,n,o);return me(s)}class za extends he{constructor(e){super("Unknown type");this.schema=e}}function Ep(e){return e[O]==="Any"||e[O]==="Unknown"}function ue(e){return e!==void 0}function Lp(e,t,r){return!0}function Up(e,t,r){return!0}function Kp(e,t,r){if(!Ge(r))return!1;if(ue(e.minItems)&&!(r.length>=e.minItems))return!1;if(ue(e.maxItems)&&!(r.length<=e.maxItems))return!1;if(!r.every((s)=>Qe(e.items,t,s)))return!1;if(e.uniqueItems===!0&&!function(){let s=new Set;for(let i of r){let a=Mn(i);if(s.has(a))return!1;else s.add(a)}return!0}())return!1;if(!(ue(e.contains)||X(e.minContains)||X(e.maxContains)))return!0;let n=ue(e.contains)?e.contains:ne(),o=r.reduce((s,i)=>Qe(n,t,i)?s+1:s,0);if(o===0)return!1;if(X(e.minContains)&&o<e.minContains)return!1;if(X(e.maxContains)&&o>e.maxContains)return!1;return!0}function Bp(e,t,r){return vo(r)}function vp(e,t,r){if(!bt(r))return!1;if(ue(e.exclusiveMaximum)&&!(r<e.exclusiveMaximum))return!1;if(ue(e.exclusiveMinimum)&&!(r>e.exclusiveMinimum))return!1;if(ue(e.maximum)&&!(r<=e.maximum))return!1;if(ue(e.minimum)&&!(r>=e.minimum))return!1;if(ue(e.multipleOf)&&r%e.multipleOf!==BigInt(0))return!1;return!0}function Dp(e,t,r){return Yr(r)}function qp(e,t,r){return Qe(e.returns,t,r.prototype)}function Gp(e,t,r){if(!_n(r))return!1;if(ue(e.exclusiveMaximumTimestamp)&&!(r.getTime()<e.exclusiveMaximumTimestamp))return!1;if(ue(e.exclusiveMinimumTimestamp)&&!(r.getTime()>e.exclusiveMinimumTimestamp))return!1;if(ue(e.maximumTimestamp)&&!(r.getTime()<=e.maximumTimestamp))return!1;if(ue(e.minimumTimestamp)&&!(r.getTime()>=e.minimumTimestamp))return!1;if(ue(e.multipleOfTimestamp)&&r.getTime()%e.multipleOfTimestamp!==0)return!1;return!0}function Hp(e,t,r){return zo(r)}function zp(e,t,r){let n=globalThis.Object.values(e.$defs),o=e.$defs[e.$ref];return Qe(o,[...t,...n],r)}function Vp(e,t,r){if(!Ho(r))return!1;if(ue(e.exclusiveMaximum)&&!(r<e.exclusiveMaximum))return!1;if(ue(e.exclusiveMinimum)&&!(r>e.exclusiveMinimum))return!1;if(ue(e.maximum)&&!(r<=e.maximum))return!1;if(ue(e.minimum)&&!(r>=e.minimum))return!1;if(ue(e.multipleOf)&&r%e.multipleOf!==0)return!1;return!0}function Jp(e,t,r){let n=e.allOf.every((o)=>Qe(o,t,r));if(e.unevaluatedProperties===!1){let o=new RegExp(Ir(e)),s=Object.getOwnPropertyNames(r).every((i)=>o.test(i));return n&&s}else if(Me(e.unevaluatedProperties)){let o=new RegExp(Ir(e)),s=Object.getOwnPropertyNames(r).every((i)=>o.test(i)||Qe(e.unevaluatedProperties,t,r[i]));return n&&s}else return n}function Wp(e,t,r){return Do(r)}function Yp(e,t,r){return r===e.const}function Xp(e,t,r){return!1}function Qp(e,t,r){return!Qe(e.not,t,r)}function Zp(e,t,r){return Wr(r)}function el(e,t,r){if(!ke.IsNumberLike(r))return!1;if(ue(e.exclusiveMaximum)&&!(r<e.exclusiveMaximum))return!1;if(ue(e.exclusiveMinimum)&&!(r>e.exclusiveMinimum))return!1;if(ue(e.minimum)&&!(r>=e.minimum))return!1;if(ue(e.maximum)&&!(r<=e.maximum))return!1;if(ue(e.multipleOf)&&r%e.multipleOf!==0)return!1;return!0}function tl(e,t,r){if(!ke.IsObjectLike(r))return!1;if(ue(e.minProperties)&&!(Object.getOwnPropertyNames(r).length>=e.minProperties))return!1;if(ue(e.maxProperties)&&!(Object.getOwnPropertyNames(r).length<=e.maxProperties))return!1;let n=Object.getOwnPropertyNames(e.properties);for(let o of n){let s=e.properties[o];if(e.required&&e.required.includes(o)){if(!Qe(s,t,r[o]))return!1;if((_r(s)||Ep(s))&&!(o in r))return!1}else if(ke.IsExactOptionalProperty(r,o)&&!Qe(s,t,r[o]))return!1}if(e.additionalProperties===!1){let o=Object.getOwnPropertyNames(r);if(e.required&&e.required.length===n.length&&o.length===n.length)return!0;else return o.every((s)=>n.includes(s))}else if(typeof e.additionalProperties==="object")return Object.getOwnPropertyNames(r).every((s)=>n.includes(s)||Qe(e.additionalProperties,t,r[s]));else return!0}function rl(e,t,r){return qo(r)}function nl(e,t,r){if(!ke.IsRecordLike(r))return!1;if(ue(e.minProperties)&&!(Object.getOwnPropertyNames(r).length>=e.minProperties))return!1;if(ue(e.maxProperties)&&!(Object.getOwnPropertyNames(r).length<=e.maxProperties))return!1;let[n,o]=Object.entries(e.patternProperties)[0],s=new RegExp(n),i=Object.entries(r).every(([c,f])=>s.test(c)?Qe(o,t,f):!0),a=typeof e.additionalProperties==="object"?Object.entries(r).every(([c,f])=>!s.test(c)?Qe(e.additionalProperties,t,f):!0):!0,u=e.additionalProperties===!1?Object.getOwnPropertyNames(r).every((c)=>s.test(c)):!0;return i&&a&&u}function ol(e,t,r){return Qe(Xe(e,t),t,r)}function sl(e,t,r){let n=new RegExp(e.source,e.flags);if(ue(e.minLength)){if(!(r.length>=e.minLength))return!1}if(ue(e.maxLength)){if(!(r.length<=e.maxLength))return!1}return n.test(r)}function il(e,t,r){if(!Ye(r))return!1;if(ue(e.minLength)){if(!(r.length>=e.minLength))return!1}if(ue(e.maxLength)){if(!(r.length<=e.maxLength))return!1}if(ue(e.pattern)){if(!new RegExp(e.pattern).test(r))return!1}if(ue(e.format)){if(!Ks(e.format))return!1;return Bs(e.format)(r)}return!0}function al(e,t,r){return Xr(r)}function ul(e,t,r){return Ye(r)&&new RegExp(e.pattern).test(r)}function cl(e,t,r){return Qe(Xe(e,t),t,r)}function fl(e,t,r){if(!Ge(r))return!1;if(e.items===void 0&&r.length!==0)return!1;if(r.length!==e.maxItems)return!1;if(!e.items)return!0;for(let n=0;n<e.items.length;n++)if(!Qe(e.items[n],t,r[n]))return!1;return!0}function dl(e,t,r){return ft(r)}function pl(e,t,r){return e.anyOf.some((n)=>Qe(n,t,r))}function ll(e,t,r){if(!Rn(r))return!1;if(ue(e.maxByteLength)&&!(r.length<=e.maxByteLength))return!1;if(ue(e.minByteLength)&&!(r.length>=e.minByteLength))return!1;return!0}function ml(e,t,r){return!0}function yl(e,t,r){return ke.IsVoidLike(r)}function gl(e,t,r){if(!co(e[O]))return!1;return vs(e[O])(e,r)}function Qe(e,t,r){let n=ue(e.$id)?Mr(e,t):t,o=e;switch(o[O]){case"Any":return Lp(o,n,r);case"Argument":return Up(o,n,r);case"Array":return Kp(o,n,r);case"AsyncIterator":return Bp(o,n,r);case"BigInt":return vp(o,n,r);case"Boolean":return Dp(o,n,r);case"Constructor":return qp(o,n,r);case"Date":return Gp(o,n,r);case"Function":return Hp(o,n,r);case"Import":return zp(o,n,r);case"Integer":return Vp(o,n,r);case"Intersect":return Jp(o,n,r);case"Iterator":return Wp(o,n,r);case"Literal":return Yp(o,n,r);case"Never":return Xp(o,n,r);case"Not":return Qp(o,n,r);case"Null":return Zp(o,n,r);case"Number":return el(o,n,r);case"Object":return tl(o,n,r);case"Promise":return rl(o,n,r);case"Record":return nl(o,n,r);case"Ref":return ol(o,n,r);case"RegExp":return sl(o,n,r);case"String":return il(o,n,r);case"Symbol":return al(o,n,r);case"TemplateLiteral":return ul(o,n,r);case"This":return cl(o,n,r);case"Tuple":return fl(o,n,r);case"Undefined":return dl(o,n,r);case"Union":return pl(o,n,r);case"Uint8Array":return ll(o,n,r);case"Unknown":return ml(o,n,r);case"Void":return yl(o,n,r);default:if(!co(o[O]))throw new za(o);return gl(o,n,r)}}function dn(...e){return e.length===3?Qe(e[0],e[1],e[2]):Qe(e[0],[],e[1])}var b;(function(e){e[e.ArrayContains=0]="ArrayContains",e[e.ArrayMaxContains=1]="ArrayMaxContains",e[e.ArrayMaxItems=2]="ArrayMaxItems",e[e.ArrayMinContains=3]="ArrayMinContains",e[e.ArrayMinItems=4]="ArrayMinItems",e[e.ArrayUniqueItems=5]="ArrayUniqueItems",e[e.Array=6]="Array",e[e.AsyncIterator=7]="AsyncIterator",e[e.BigIntExclusiveMaximum=8]="BigIntExclusiveMaximum",e[e.BigIntExclusiveMinimum=9]="BigIntExclusiveMinimum",e[e.BigIntMaximum=10]="BigIntMaximum",e[e.BigIntMinimum=11]="BigIntMinimum",e[e.BigIntMultipleOf=12]="BigIntMultipleOf",e[e.BigInt=13]="BigInt",e[e.Boolean=14]="Boolean",e[e.DateExclusiveMaximumTimestamp=15]="DateExclusiveMaximumTimestamp",e[e.DateExclusiveMinimumTimestamp=16]="DateExclusiveMinimumTimestamp",e[e.DateMaximumTimestamp=17]="DateMaximumTimestamp",e[e.DateMinimumTimestamp=18]="DateMinimumTimestamp",e[e.DateMultipleOfTimestamp=19]="DateMultipleOfTimestamp",e[e.Date=20]="Date",e[e.Function=21]="Function",e[e.IntegerExclusiveMaximum=22]="IntegerExclusiveMaximum",e[e.IntegerExclusiveMinimum=23]="IntegerExclusiveMinimum",e[e.IntegerMaximum=24]="IntegerMaximum",e[e.IntegerMinimum=25]="IntegerMinimum",e[e.IntegerMultipleOf=26]="IntegerMultipleOf",e[e.Integer=27]="Integer",e[e.IntersectUnevaluatedProperties=28]="IntersectUnevaluatedProperties",e[e.Intersect=29]="Intersect",e[e.Iterator=30]="Iterator",e[e.Kind=31]="Kind",e[e.Literal=32]="Literal",e[e.Never=33]="Never",e[e.Not=34]="Not",e[e.Null=35]="Null",e[e.NumberExclusiveMaximum=36]="NumberExclusiveMaximum",e[e.NumberExclusiveMinimum=37]="NumberExclusiveMinimum",e[e.NumberMaximum=38]="NumberMaximum",e[e.NumberMinimum=39]="NumberMinimum",e[e.NumberMultipleOf=40]="NumberMultipleOf",e[e.Number=41]="Number",e[e.ObjectAdditionalProperties=42]="ObjectAdditionalProperties",e[e.ObjectMaxProperties=43]="ObjectMaxProperties",e[e.ObjectMinProperties=44]="ObjectMinProperties",e[e.ObjectRequiredProperty=45]="ObjectRequiredProperty",e[e.Object=46]="Object",e[e.Promise=47]="Promise",e[e.RegExp=48]="RegExp",e[e.StringFormatUnknown=49]="StringFormatUnknown",e[e.StringFormat=50]="StringFormat",e[e.StringMaxLength=51]="StringMaxLength",e[e.StringMinLength=52]="StringMinLength",e[e.StringPattern=53]="StringPattern",e[e.String=54]="String",e[e.Symbol=55]="Symbol",e[e.TupleLength=56]="TupleLength",e[e.Tuple=57]="Tuple",e[e.Uint8ArrayMaxByteLength=58]="Uint8ArrayMaxByteLength",e[e.Uint8ArrayMinByteLength=59]="Uint8ArrayMinByteLength",e[e.Uint8Array=60]="Uint8Array",e[e.Undefined=61]="Undefined",e[e.Union=62]="Union",e[e.Void=63]="Void"})(b||(b={}));class Va extends he{constructor(e){super("Unknown type");this.schema=e}}function wr(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}function ce(e){return e!==void 0}class ai{constructor(e){this.iterator=e}[Symbol.iterator](){return this.iterator}First(){let e=this.iterator.next();return e.done?void 0:e.value}}function N(e,t,r,n,o=[]){return{type:e,schema:t,path:r,value:n,message:xa()({errorType:e,path:r,schema:t,value:n,errors:o}),errors:o}}function*hl(e,t,r,n){}function*xl(e,t,r,n){}function*bl(e,t,r,n){if(!Ge(n))return yield N(b.Array,e,r,n);if(ce(e.minItems)&&!(n.length>=e.minItems))yield N(b.ArrayMinItems,e,r,n);if(ce(e.maxItems)&&!(n.length<=e.maxItems))yield N(b.ArrayMaxItems,e,r,n);for(let i=0;i<n.length;i++)yield*Ze(e.items,t,`${r}/${i}`,n[i]);if(e.uniqueItems===!0&&!function(){let i=new Set;for(let a of n){let u=Mn(a);if(i.has(u))return!1;else i.add(u)}return!0}())yield N(b.ArrayUniqueItems,e,r,n);if(!(ce(e.contains)||ce(e.minContains)||ce(e.maxContains)))return;let o=ce(e.contains)?e.contains:ne(),s=n.reduce((i,a,u)=>Ze(o,t,`${r}${u}`,a).next().done===!0?i+1:i,0);if(s===0)yield N(b.ArrayContains,e,r,n);if(X(e.minContains)&&s<e.minContains)yield N(b.ArrayMinContains,e,r,n);if(X(e.maxContains)&&s>e.maxContains)yield N(b.ArrayMaxContains,e,r,n)}function*Il(e,t,r,n){if(!vo(n))yield N(b.AsyncIterator,e,r,n)}function*_l(e,t,r,n){if(!bt(n))return yield N(b.BigInt,e,r,n);if(ce(e.exclusiveMaximum)&&!(n<e.exclusiveMaximum))yield N(b.BigIntExclusiveMaximum,e,r,n);if(ce(e.exclusiveMinimum)&&!(n>e.exclusiveMinimum))yield N(b.BigIntExclusiveMinimum,e,r,n);if(ce(e.maximum)&&!(n<=e.maximum))yield N(b.BigIntMaximum,e,r,n);if(ce(e.minimum)&&!(n>=e.minimum))yield N(b.BigIntMinimum,e,r,n);if(ce(e.multipleOf)&&n%e.multipleOf!==BigInt(0))yield N(b.BigIntMultipleOf,e,r,n)}function*Rl(e,t,r,n){if(!Yr(n))yield N(b.Boolean,e,r,n)}function*Ol(e,t,r,n){yield*Ze(e.returns,t,r,n.prototype)}function*wl(e,t,r,n){if(!_n(n))return yield N(b.Date,e,r,n);if(ce(e.exclusiveMaximumTimestamp)&&!(n.getTime()<e.exclusiveMaximumTimestamp))yield N(b.DateExclusiveMaximumTimestamp,e,r,n);if(ce(e.exclusiveMinimumTimestamp)&&!(n.getTime()>e.exclusiveMinimumTimestamp))yield N(b.DateExclusiveMinimumTimestamp,e,r,n);if(ce(e.maximumTimestamp)&&!(n.getTime()<=e.maximumTimestamp))yield N(b.DateMaximumTimestamp,e,r,n);if(ce(e.minimumTimestamp)&&!(n.getTime()>=e.minimumTimestamp))yield N(b.DateMinimumTimestamp,e,r,n);if(ce(e.multipleOfTimestamp)&&n.getTime()%e.multipleOfTimestamp!==0)yield N(b.DateMultipleOfTimestamp,e,r,n)}function*$l(e,t,r,n){if(!zo(n))yield N(b.Function,e,r,n)}function*kl(e,t,r,n){let o=globalThis.Object.values(e.$defs),s=e.$defs[e.$ref];yield*Ze(s,[...t,...o],r,n)}function*Al(e,t,r,n){if(!Ho(n))return yield N(b.Integer,e,r,n);if(ce(e.exclusiveMaximum)&&!(n<e.exclusiveMaximum))yield N(b.IntegerExclusiveMaximum,e,r,n);if(ce(e.exclusiveMinimum)&&!(n>e.exclusiveMinimum))yield N(b.IntegerExclusiveMinimum,e,r,n);if(ce(e.maximum)&&!(n<=e.maximum))yield N(b.IntegerMaximum,e,r,n);if(ce(e.minimum)&&!(n>=e.minimum))yield N(b.IntegerMinimum,e,r,n);if(ce(e.multipleOf)&&n%e.multipleOf!==0)yield N(b.IntegerMultipleOf,e,r,n)}function*Sl(e,t,r,n){let o=!1;for(let s of e.allOf)for(let i of Ze(s,t,r,n))o=!0,yield i;if(o)return yield N(b.Intersect,e,r,n);if(e.unevaluatedProperties===!1){let s=new RegExp(Ir(e));for(let i of Object.getOwnPropertyNames(n))if(!s.test(i))yield N(b.IntersectUnevaluatedProperties,e,`${r}/${i}`,n)}if(typeof e.unevaluatedProperties==="object"){let s=new RegExp(Ir(e));for(let i of Object.getOwnPropertyNames(n))if(!s.test(i)){let a=Ze(e.unevaluatedProperties,t,`${r}/${i}`,n[i]).next();if(!a.done)yield a.value}}}function*Pl(e,t,r,n){if(!Do(n))yield N(b.Iterator,e,r,n)}function*Cl(e,t,r,n){if(n!==e.const)yield N(b.Literal,e,r,n)}function*Tl(e,t,r,n){yield N(b.Never,e,r,n)}function*Fl(e,t,r,n){if(Ze(e.not,t,r,n).next().done===!0)yield N(b.Not,e,r,n)}function*Nl(e,t,r,n){if(!Wr(n))yield N(b.Null,e,r,n)}function*jl(e,t,r,n){if(!ke.IsNumberLike(n))return yield N(b.Number,e,r,n);if(ce(e.exclusiveMaximum)&&!(n<e.exclusiveMaximum))yield N(b.NumberExclusiveMaximum,e,r,n);if(ce(e.exclusiveMinimum)&&!(n>e.exclusiveMinimum))yield N(b.NumberExclusiveMinimum,e,r,n);if(ce(e.maximum)&&!(n<=e.maximum))yield N(b.NumberMaximum,e,r,n);if(ce(e.minimum)&&!(n>=e.minimum))yield N(b.NumberMinimum,e,r,n);if(ce(e.multipleOf)&&n%e.multipleOf!==0)yield N(b.NumberMultipleOf,e,r,n)}function*Ml(e,t,r,n){if(!ke.IsObjectLike(n))return yield N(b.Object,e,r,n);if(ce(e.minProperties)&&!(Object.getOwnPropertyNames(n).length>=e.minProperties))yield N(b.ObjectMinProperties,e,r,n);if(ce(e.maxProperties)&&!(Object.getOwnPropertyNames(n).length<=e.maxProperties))yield N(b.ObjectMaxProperties,e,r,n);let o=Array.isArray(e.required)?e.required:[],s=Object.getOwnPropertyNames(e.properties),i=Object.getOwnPropertyNames(n);for(let a of o){if(i.includes(a))continue;yield N(b.ObjectRequiredProperty,e.properties[a],`${r}/${wr(a)}`,void 0)}if(e.additionalProperties===!1){for(let a of i)if(!s.includes(a))yield N(b.ObjectAdditionalProperties,e,`${r}/${wr(a)}`,n[a])}if(typeof e.additionalProperties==="object")for(let a of i){if(s.includes(a))continue;yield*Ze(e.additionalProperties,t,`${r}/${wr(a)}`,n[a])}for(let a of s){let u=e.properties[a];if(e.required&&e.required.includes(a)){if(yield*Ze(u,t,`${r}/${wr(a)}`,n[a]),_r(e)&&!(a in n))yield N(b.ObjectRequiredProperty,u,`${r}/${wr(a)}`,void 0)}else if(ke.IsExactOptionalProperty(n,a))yield*Ze(u,t,`${r}/${wr(a)}`,n[a])}}function*El(e,t,r,n){if(!qo(n))yield N(b.Promise,e,r,n)}function*Ll(e,t,r,n){if(!ke.IsRecordLike(n))return yield N(b.Object,e,r,n);if(ce(e.minProperties)&&!(Object.getOwnPropertyNames(n).length>=e.minProperties))yield N(b.ObjectMinProperties,e,r,n);if(ce(e.maxProperties)&&!(Object.getOwnPropertyNames(n).length<=e.maxProperties))yield N(b.ObjectMaxProperties,e,r,n);let[o,s]=Object.entries(e.patternProperties)[0],i=new RegExp(o);for(let[a,u]of Object.entries(n))if(i.test(a))yield*Ze(s,t,`${r}/${wr(a)}`,u);if(typeof e.additionalProperties==="object"){for(let[a,u]of Object.entries(n))if(!i.test(a))yield*Ze(e.additionalProperties,t,`${r}/${wr(a)}`,u)}if(e.additionalProperties===!1)for(let[a,u]of Object.entries(n)){if(i.test(a))continue;return yield N(b.ObjectAdditionalProperties,e,`${r}/${wr(a)}`,u)}}function*Ul(e,t,r,n){yield*Ze(Xe(e,t),t,r,n)}function*Kl(e,t,r,n){if(!Ye(n))return yield N(b.String,e,r,n);if(ce(e.minLength)&&!(n.length>=e.minLength))yield N(b.StringMinLength,e,r,n);if(ce(e.maxLength)&&!(n.length<=e.maxLength))yield N(b.StringMaxLength,e,r,n);if(!new RegExp(e.source,e.flags).test(n))return yield N(b.RegExp,e,r,n)}function*Bl(e,t,r,n){if(!Ye(n))return yield N(b.String,e,r,n);if(ce(e.minLength)&&!(n.length>=e.minLength))yield N(b.StringMinLength,e,r,n);if(ce(e.maxLength)&&!(n.length<=e.maxLength))yield N(b.StringMaxLength,e,r,n);if(Ye(e.pattern)){if(!new RegExp(e.pattern).test(n))yield N(b.StringPattern,e,r,n)}if(Ye(e.format)){if(!Ks(e.format))yield N(b.StringFormatUnknown,e,r,n);else if(!Bs(e.format)(n))yield N(b.StringFormat,e,r,n)}}function*vl(e,t,r,n){if(!Xr(n))yield N(b.Symbol,e,r,n)}function*Dl(e,t,r,n){if(!Ye(n))return yield N(b.String,e,r,n);if(!new RegExp(e.pattern).test(n))yield N(b.StringPattern,e,r,n)}function*ql(e,t,r,n){yield*Ze(Xe(e,t),t,r,n)}function*Gl(e,t,r,n){if(!Ge(n))return yield N(b.Tuple,e,r,n);if(e.items===void 0&&n.length!==0)return yield N(b.TupleLength,e,r,n);if(n.length!==e.maxItems)return yield N(b.TupleLength,e,r,n);if(!e.items)return;for(let o=0;o<e.items.length;o++)yield*Ze(e.items[o],t,`${r}/${o}`,n[o])}function*Hl(e,t,r,n){if(!ft(n))yield N(b.Undefined,e,r,n)}function*zl(e,t,r,n){if(dn(e,t,n))return;let o=e.anyOf.map((s)=>new ai(Ze(s,t,r,n)));yield N(b.Union,e,r,n,o)}function*Vl(e,t,r,n){if(!Rn(n))return yield N(b.Uint8Array,e,r,n);if(ce(e.maxByteLength)&&!(n.length<=e.maxByteLength))yield N(b.Uint8ArrayMaxByteLength,e,r,n);if(ce(e.minByteLength)&&!(n.length>=e.minByteLength))yield N(b.Uint8ArrayMinByteLength,e,r,n)}function*Jl(e,t,r,n){}function*Wl(e,t,r,n){if(!ke.IsVoidLike(n))yield N(b.Void,e,r,n)}function*Yl(e,t,r,n){if(!vs(e[O])(e,n))yield N(b.Kind,e,r,n)}function*Ze(e,t,r,n){let o=ce(e.$id)?[...t,e]:t,s=e;switch(s[O]){case"Any":return yield*hl(s,o,r,n);case"Argument":return yield*xl(s,o,r,n);case"Array":return yield*bl(s,o,r,n);case"AsyncIterator":return yield*Il(s,o,r,n);case"BigInt":return yield*_l(s,o,r,n);case"Boolean":return yield*Rl(s,o,r,n);case"Constructor":return yield*Ol(s,o,r,n);case"Date":return yield*wl(s,o,r,n);case"Function":return yield*$l(s,o,r,n);case"Import":return yield*kl(s,o,r,n);case"Integer":return yield*Al(s,o,r,n);case"Intersect":return yield*Sl(s,o,r,n);case"Iterator":return yield*Pl(s,o,r,n);case"Literal":return yield*Cl(s,o,r,n);case"Never":return yield*Tl(s,o,r,n);case"Not":return yield*Fl(s,o,r,n);case"Null":return yield*Nl(s,o,r,n);case"Number":return yield*jl(s,o,r,n);case"Object":return yield*Ml(s,o,r,n);case"Promise":return yield*El(s,o,r,n);case"Record":return yield*Ll(s,o,r,n);case"Ref":return yield*Ul(s,o,r,n);case"RegExp":return yield*Kl(s,o,r,n);case"String":return yield*Bl(s,o,r,n);case"Symbol":return yield*vl(s,o,r,n);case"TemplateLiteral":return yield*Dl(s,o,r,n);case"This":return yield*ql(s,o,r,n);case"Tuple":return yield*Gl(s,o,r,n);case"Undefined":return yield*Hl(s,o,r,n);case"Union":return yield*zl(s,o,r,n);case"Uint8Array":return yield*Vl(s,o,r,n);case"Unknown":return yield*Jl(s,o,r,n);case"Void":return yield*Wl(s,o,r,n);default:if(!co(s[O]))throw new Va(e);return yield*Yl(s,o,r,n)}}function Ja(...e){let t=e.length===3?Ze(e[0],e[1],"",e[2]):Ze(e[0],[],"",e[1]);return new ai(t)}class ui extends he{constructor(e,t,r){super("Unable to decode value as it does not match the expected schema");this.schema=e,this.value=t,this.error=r}}class Wa extends he{constructor(e,t,r,n){super(n instanceof Error?n.message:"Unknown error");this.schema=e,this.path=t,this.value=r,this.error=n}}function Le(e,t,r){try{return ye(e)?e[je].Decode(r):r}catch(n){throw new Wa(e,t,r,n)}}function Xl(e,t,r,n){return Ge(n)?Le(e,r,n.map((o,s)=>Wt(e.items,t,`${r}/${s}`,o))):Le(e,r,n)}function Ql(e,t,r,n){if(!pt(n)||Vo(n))return Le(e,r,n);let o=is(e),s=o.map((f)=>f[0]),i={...n};for(let[f,d]of o)if(f in i)i[f]=Wt(d,t,`${r}/${f}`,i[f]);if(!ye(e.unevaluatedProperties))return Le(e,r,i);let a=Object.getOwnPropertyNames(i),u=e.unevaluatedProperties,c={...i};for(let f of a)if(!s.includes(f))c[f]=Le(u,`${r}/${f}`,c[f]);return Le(e,r,c)}function Zl(e,t,r,n){let o=globalThis.Object.values(e.$defs),s=e.$defs[e.$ref],i=Wt(s,[...t,...o],r,n);return Le(e,r,i)}function em(e,t,r,n){return Le(e,r,Wt(e.not,t,r,n))}function tm(e,t,r,n){if(!pt(n))return Le(e,r,n);let o=Ft(e),s={...n};for(let c of o){if(!Go(s,c))continue;if(ft(s[c])&&(!hr(e.properties[c])||ke.IsExactOptionalProperty(s,c)))continue;s[c]=Wt(e.properties[c],t,`${r}/${c}`,s[c])}if(!Me(e.additionalProperties))return Le(e,r,s);let i=Object.getOwnPropertyNames(s),a=e.additionalProperties,u={...s};for(let c of i)if(!o.includes(c))u[c]=Le(a,`${r}/${c}`,u[c]);return Le(e,r,u)}function rm(e,t,r,n){if(!pt(n))return Le(e,r,n);let o=Object.getOwnPropertyNames(e.patternProperties)[0],s=new RegExp(o),i={...n};for(let f of Object.getOwnPropertyNames(n))if(s.test(f))i[f]=Wt(e.patternProperties[o],t,`${r}/${f}`,i[f]);if(!Me(e.additionalProperties))return Le(e,r,i);let a=Object.getOwnPropertyNames(i),u=e.additionalProperties,c={...i};for(let f of a)if(!s.test(f))c[f]=Le(u,`${r}/${f}`,c[f]);return Le(e,r,c)}function nm(e,t,r,n){let o=Xe(e,t);return Le(e,r,Wt(o,t,r,n))}function om(e,t,r,n){let o=Xe(e,t);return Le(e,r,Wt(o,t,r,n))}function sm(e,t,r,n){return Ge(n)&&Ge(e.items)?Le(e,r,e.items.map((o,s)=>Wt(o,t,`${r}/${s}`,n[s]))):Le(e,r,n)}function im(e,t,r,n){for(let o of e.anyOf){if(!dn(o,t,n))continue;let s=Wt(o,t,r,n);return Le(e,r,s)}return Le(e,r,n)}function Wt(e,t,r,n){let o=Mr(e,t),s=e;switch(e[O]){case"Array":return Xl(s,o,r,n);case"Import":return Zl(s,o,r,n);case"Intersect":return Ql(s,o,r,n);case"Not":return em(s,o,r,n);case"Object":return tm(s,o,r,n);case"Record":return rm(s,o,r,n);case"Ref":return nm(s,o,r,n);case"Symbol":return Le(s,r,n);case"This":return om(s,o,r,n);case"Tuple":return sm(s,o,r,n);case"Union":return im(s,o,r,n);default:return Le(s,r,n)}}function Ya(e,t,r){return Wt(e,t,"",r)}class ci extends he{constructor(e,t,r){super("The encoded value does not match the expected schema");this.schema=e,this.value=t,this.error=r}}class Xa extends he{constructor(e,t,r,n){super(`${n instanceof Error?n.message:"Unknown error"}`);this.schema=e,this.path=t,this.value=r,this.error=n}}function rt(e,t,r){try{return ye(e)?e[je].Encode(r):r}catch(n){throw new Xa(e,t,r,n)}}function am(e,t,r,n){let o=rt(e,r,n);return Ge(o)?o.map((s,i)=>Yt(e.items,t,`${r}/${i}`,s)):o}function um(e,t,r,n){let o=globalThis.Object.values(e.$defs),s=e.$defs[e.$ref],i=rt(e,r,n);return Yt(s,[...t,...o],r,i)}function cm(e,t,r,n){let o=rt(e,r,n);if(!pt(n)||Vo(n))return o;let s=is(e),i=s.map((d)=>d[0]),a={...o};for(let[d,m]of s)if(d in a)a[d]=Yt(m,t,`${r}/${d}`,a[d]);if(!ye(e.unevaluatedProperties))return a;let u=Object.getOwnPropertyNames(a),c=e.unevaluatedProperties,f={...a};for(let d of u)if(!i.includes(d))f[d]=rt(c,`${r}/${d}`,f[d]);return f}function fm(e,t,r,n){return rt(e.not,r,rt(e,r,n))}function dm(e,t,r,n){let o=rt(e,r,n);if(!pt(o))return o;let s=Ft(e),i={...o};for(let f of s){if(!Go(i,f))continue;if(ft(i[f])&&(!hr(e.properties[f])||ke.IsExactOptionalProperty(i,f)))continue;i[f]=Yt(e.properties[f],t,`${r}/${f}`,i[f])}if(!Me(e.additionalProperties))return i;let a=Object.getOwnPropertyNames(i),u=e.additionalProperties,c={...i};for(let f of a)if(!s.includes(f))c[f]=rt(u,`${r}/${f}`,c[f]);return c}function pm(e,t,r,n){let o=rt(e,r,n);if(!pt(n))return o;let s=Object.getOwnPropertyNames(e.patternProperties)[0],i=new RegExp(s),a={...o};for(let d of Object.getOwnPropertyNames(n))if(i.test(d))a[d]=Yt(e.patternProperties[s],t,`${r}/${d}`,a[d]);if(!Me(e.additionalProperties))return a;let u=Object.getOwnPropertyNames(a),c=e.additionalProperties,f={...a};for(let d of u)if(!i.test(d))f[d]=rt(c,`${r}/${d}`,f[d]);return f}function lm(e,t,r,n){let o=Xe(e,t),s=Yt(o,t,r,n);return rt(e,r,s)}function mm(e,t,r,n){let o=Xe(e,t),s=Yt(o,t,r,n);return rt(e,r,s)}function ym(e,t,r,n){let o=rt(e,r,n);return Ge(e.items)?e.items.map((s,i)=>Yt(s,t,`${r}/${i}`,o[i])):[]}function gm(e,t,r,n){for(let o of e.anyOf){if(!dn(o,t,n))continue;let s=Yt(o,t,r,n);return rt(e,r,s)}for(let o of e.anyOf){let s=Yt(o,t,r,n);if(!dn(e,t,s))continue;return rt(e,r,s)}return rt(e,r,n)}function Yt(e,t,r,n){let o=Mr(e,t),s=e;switch(e[O]){case"Array":return am(s,o,r,n);case"Import":return um(s,o,r,n);case"Intersect":return cm(s,o,r,n);case"Not":return fm(s,o,r,n);case"Object":return dm(s,o,r,n);case"Record":return pm(s,o,r,n);case"Ref":return lm(s,o,r,n);case"This":return mm(s,o,r,n);case"Tuple":return ym(s,o,r,n);case"Union":return gm(s,o,r,n);default:return rt(s,r,n)}}function Qa(e,t,r){return Yt(e,t,"",r)}function hm(e,t){return ye(e)||Je(e.items,t)}function xm(e,t){return ye(e)||Je(e.items,t)}function bm(e,t){return ye(e)||Je(e.returns,t)||e.parameters.some((r)=>Je(r,t))}function Im(e,t){return ye(e)||Je(e.returns,t)||e.parameters.some((r)=>Je(r,t))}function _m(e,t){return ye(e)||ye(e.unevaluatedProperties)||e.allOf.some((r)=>Je(r,t))}function Rm(e,t){let r=globalThis.Object.getOwnPropertyNames(e.$defs).reduce((o,s)=>[...o,e.$defs[s]],[]),n=e.$defs[e.$ref];return ye(e)||Je(n,[...r,...t])}function Om(e,t){return ye(e)||Je(e.items,t)}function wm(e,t){return ye(e)||Je(e.not,t)}function $m(e,t){return ye(e)||Object.values(e.properties).some((r)=>Je(r,t))||Me(e.additionalProperties)&&Je(e.additionalProperties,t)}function km(e,t){return ye(e)||Je(e.item,t)}function Am(e,t){let r=Object.getOwnPropertyNames(e.patternProperties)[0],n=e.patternProperties[r];return ye(e)||Je(n,t)||Me(e.additionalProperties)&&ye(e.additionalProperties)}function Sm(e,t){if(ye(e))return!0;return Je(Xe(e,t),t)}function Pm(e,t){if(ye(e))return!0;return Je(Xe(e,t),t)}function Cm(e,t){return ye(e)||!ft(e.items)&&e.items.some((r)=>Je(r,t))}function Tm(e,t){return ye(e)||e.anyOf.some((r)=>Je(r,t))}function Je(e,t){let r=Mr(e,t),n=e;if(e.$id&&fi.has(e.$id))return!1;if(e.$id)fi.add(e.$id);switch(e[O]){case"Array":return hm(n,r);case"AsyncIterator":return xm(n,r);case"Constructor":return bm(n,r);case"Function":return Im(n,r);case"Import":return Rm(n,r);case"Intersect":return _m(n,r);case"Iterator":return Om(n,r);case"Not":return wm(n,r);case"Object":return $m(n,r);case"Promise":return km(n,r);case"Record":return Am(n,r);case"Ref":return Sm(n,r);case"This":return Pm(n,r);case"Tuple":return Cm(n,r);case"Union":return Tm(n,r);default:return ye(e)}}var fi=new Set;function Za(e,t){return fi.clear(),Je(e,t)}class eu{constructor(e,t,r,n){this.schema=e,this.references=t,this.checkFunc=r,this.code=n,this.hasTransform=Za(e,t)}Code(){return this.code}Schema(){return this.schema}References(){return this.references}Errors(e){return Ja(this.schema,this.references,e)}Check(e){return this.checkFunc(e)}Decode(e){if(!this.checkFunc(e))throw new ui(this.schema,e,this.Errors(e).First());return this.hasTransform?Ya(this.schema,this.references,e):e}Encode(e){let t=this.hasTransform?Qa(this.schema,this.references,e):e;if(!this.checkFunc(t))throw new ci(this.schema,e,this.Errors(e).First());return t}}var $r;(function(e){function t(s){return s===36}e.DollarSign=t;function r(s){return s===95}e.IsUnderscore=r;function n(s){return s>=65&&s<=90||s>=97&&s<=122}e.IsAlpha=n;function o(s){return s>=48&&s<=57}e.IsNumeric=o})($r||($r={}));var gs;(function(e){function t(s){if(s.length===0)return!1;return $r.IsNumeric(s.charCodeAt(0))}function r(s){if(t(s))return!1;for(let i=0;i<s.length;i++){let a=s.charCodeAt(i);if(!($r.IsAlpha(a)||$r.IsNumeric(a)||$r.DollarSign(a)||$r.IsUnderscore(a)))return!1}return!0}function n(s){return s.replace(/'/g,"\\'")}function o(s,i){return r(i)?`${s}.${i}`:`${s}['${n(i)}']`}e.Encode=o})(gs||(gs={}));var di;(function(e){function t(r){let n=[];for(let o=0;o<r.length;o++){let s=r.charCodeAt(o);if($r.IsNumeric(s)||$r.IsAlpha(s))n.push(r.charAt(o));else n.push(`_${s}_`)}return n.join("").replace(/__/g,"_")}e.Encode=t})(di||(di={}));var pi;(function(e){function t(r){return r.replace(/'/g,"\\'")}e.Escape=t})(pi||(pi={}));class tu extends he{constructor(e){super("Unknown type");this.schema=e}}class li extends he{constructor(e){super("Preflight validation check failed to guard for the given schema");this.schema=e}}var pn;(function(e){function t(i,a,u){return ke.ExactOptionalPropertyTypes?`('${a}' in ${i} ? ${u} : true)`:`(${gs.Encode(i,a)} !== undefined ? ${u} : true)`}e.IsExactOptionalProperty=t;function r(i){return!ke.AllowArrayObject?`(typeof ${i} === 'object' && ${i} !== null && !Array.isArray(${i}))`:`(typeof ${i} === 'object' && ${i} !== null)`}e.IsObjectLike=r;function n(i){return!ke.AllowArrayObject?`(typeof ${i} === 'object' && ${i} !== null && !Array.isArray(${i}) && !(${i} instanceof Date) && !(${i} instanceof Uint8Array))`:`(typeof ${i} === 'object' && ${i} !== null && !(${i} instanceof Date) && !(${i} instanceof Uint8Array))`}e.IsRecordLike=n;function o(i){return ke.AllowNaN?`typeof ${i} === 'number'`:`Number.isFinite(${i})`}e.IsNumberLike=o;function s(i){return ke.AllowNullVoid?`(${i} === undefined || ${i} === null)`:`${i} === undefined`}e.IsVoidLike=s})(pn||(pn={}));var $o;(function(e){function t(l){return l[O]==="Any"||l[O]==="Unknown"}function*r(l,j,g){yield"true"}function*n(l,j,g){yield"true"}function*o(l,j,g){yield`Array.isArray(${g})`;let[Y,E]=[Ce("value","any"),Ce("acc","number")];if(X(l.maxItems))yield`${g}.length <= ${l.maxItems}`;if(X(l.minItems))yield`${g}.length >= ${l.minItems}`;let U=k(l.items,j,"value");if(yield`${g}.every((${Y}) => ${U})`,Ee(l.contains)||X(l.minContains)||X(l.maxContains)){let $e=Ee(l.contains)?l.contains:ne(),dt=k($e,j,"value"),mr=X(l.minContains)?[`(count >= ${l.minContains})`]:[],Ut=X(l.maxContains)?[`(count <= ${l.maxContains})`]:[],or=`const count = value.reduce((${E}, ${Y}) => ${dt} ? acc + 1 : acc, 0)`,Bo=["(count > 0)",...mr,...Ut].join(" && ");yield`((${Y}) => { ${or}; return ${Bo}})(${g})`}if(l.uniqueItems===!0)yield`((${Y}) => { const set = new Set(); for(const element of value) { const hashed = hash(element); if(set.has(hashed)) { return false } else { set.add(hashed) } } return true } )(${g})`}function*s(l,j,g){yield`(typeof value === 'object' && Symbol.asyncIterator in ${g})`}function*i(l,j,g){if(yield`(typeof ${g} === 'bigint')`,bt(l.exclusiveMaximum))yield`${g} < BigInt(${l.exclusiveMaximum})`;if(bt(l.exclusiveMinimum))yield`${g} > BigInt(${l.exclusiveMinimum})`;if(bt(l.maximum))yield`${g} <= BigInt(${l.maximum})`;if(bt(l.minimum))yield`${g} >= BigInt(${l.minimum})`;if(bt(l.multipleOf))yield`(${g} % BigInt(${l.multipleOf})) === 0`}function*a(l,j,g){yield`(typeof ${g} === 'boolean')`}function*u(l,j,g){yield*ae(l.returns,j,`${g}.prototype`)}function*c(l,j,g){if(yield`(${g} instanceof Date) && Number.isFinite(${g}.getTime())`,X(l.exclusiveMaximumTimestamp))yield`${g}.getTime() < ${l.exclusiveMaximumTimestamp}`;if(X(l.exclusiveMinimumTimestamp))yield`${g}.getTime() > ${l.exclusiveMinimumTimestamp}`;if(X(l.maximumTimestamp))yield`${g}.getTime() <= ${l.maximumTimestamp}`;if(X(l.minimumTimestamp))yield`${g}.getTime() >= ${l.minimumTimestamp}`;if(X(l.multipleOfTimestamp))yield`(${g}.getTime() % ${l.multipleOfTimestamp}) === 0`}function*f(l,j,g){yield`(typeof ${g} === 'function')`}function*d(l,j,g){let Y=globalThis.Object.getOwnPropertyNames(l.$defs).reduce((E,U)=>[...E,l.$defs[U]],[]);yield*ae(Tt(l.$ref),[...j,...Y],g)}function*m(l,j,g){if(yield`Number.isInteger(${g})`,X(l.exclusiveMaximum))yield`${g} < ${l.exclusiveMaximum}`;if(X(l.exclusiveMinimum))yield`${g} > ${l.exclusiveMinimum}`;if(X(l.maximum))yield`${g} <= ${l.maximum}`;if(X(l.minimum))yield`${g} >= ${l.minimum}`;if(X(l.multipleOf))yield`(${g} % ${l.multipleOf}) === 0`}function*y(l,j,g){let Y=l.allOf.map((E)=>k(E,j,g)).join(" && ");if(l.unevaluatedProperties===!1){let E=G(`${new RegExp(Ir(l))};`),U=`Object.getOwnPropertyNames(${g}).every(key => ${E}.test(key))`;yield`(${Y} && ${U})`}else if(Ee(l.unevaluatedProperties)){let E=G(`${new RegExp(Ir(l))};`),U=`Object.getOwnPropertyNames(${g}).every(key => ${E}.test(key) || ${k(l.unevaluatedProperties,j,`${g}[key]`)})`;yield`(${Y} && ${U})`}else yield`(${Y})`}function*p(l,j,g){yield`(typeof value === 'object' && Symbol.iterator in ${g})`}function*h(l,j,g){if(typeof l.const==="number"||typeof l.const==="boolean")yield`(${g} === ${l.const})`;else yield`(${g} === '${pi.Escape(l.const)}')`}function*x(l,j,g){yield"false"}function*R(l,j,g){yield`(!${k(l.not,j,g)})`}function*w(l,j,g){yield`(${g} === null)`}function*P(l,j,g){if(yield pn.IsNumberLike(g),X(l.exclusiveMaximum))yield`${g} < ${l.exclusiveMaximum}`;if(X(l.exclusiveMinimum))yield`${g} > ${l.exclusiveMinimum}`;if(X(l.maximum))yield`${g} <= ${l.maximum}`;if(X(l.minimum))yield`${g} >= ${l.minimum}`;if(X(l.multipleOf))yield`(${g} % ${l.multipleOf}) === 0`}function*C(l,j,g){if(yield pn.IsObjectLike(g),X(l.minProperties))yield`Object.getOwnPropertyNames(${g}).length >= ${l.minProperties}`;if(X(l.maxProperties))yield`Object.getOwnPropertyNames(${g}).length <= ${l.maxProperties}`;let Y=Object.getOwnPropertyNames(l.properties);for(let E of Y){let U=gs.Encode(g,E),$e=l.properties[E];if(l.required&&l.required.includes(E)){if(yield*ae($e,j,U),_r($e)||t($e))yield`('${E}' in ${g})`}else{let dt=k($e,j,U);yield pn.IsExactOptionalProperty(g,E,dt)}}if(l.additionalProperties===!1)if(l.required&&l.required.length===Y.length)yield`Object.getOwnPropertyNames(${g}).length === ${Y.length}`;else{let E=`[${Y.map((U)=>`'${U}'`).join(", ")}]`;yield`Object.getOwnPropertyNames(${g}).every(key => ${E}.includes(key))`}if(typeof l.additionalProperties==="object"){let E=k(l.additionalProperties,j,`${g}[key]`),U=`[${Y.map(($e)=>`'${$e}'`).join(", ")}]`;yield`(Object.getOwnPropertyNames(${g}).every(key => ${U}.includes(key) || ${E}))`}}function*J(l,j,g){yield`${g} instanceof Promise`}function*z(l,j,g){if(yield pn.IsRecordLike(g),X(l.minProperties))yield`Object.getOwnPropertyNames(${g}).length >= ${l.minProperties}`;if(X(l.maxProperties))yield`Object.getOwnPropertyNames(${g}).length <= ${l.maxProperties}`;let[Y,E]=Object.entries(l.patternProperties)[0],U=G(`${new RegExp(Y)}`),$e=k(E,j,"value"),dt=Ee(l.additionalProperties)?k(l.additionalProperties,j,g):l.additionalProperties===!1?"false":"true",mr=`(${U}.test(key) ? ${$e} : ${dt})`;yield`(Object.entries(${g}).every(([key, value]) => ${mr}))`}function*L(l,j,g){let Y=Xe(l,j);if(D.functions.has(l.$ref))return yield`${v(l.$ref)}(${g})`;yield*ae(Y,j,g)}function*T(l,j,g){let Y=G(`${new RegExp(l.source,l.flags)};`);if(yield`(typeof ${g} === 'string')`,X(l.maxLength))yield`${g}.length <= ${l.maxLength}`;if(X(l.minLength))yield`${g}.length >= ${l.minLength}`;yield`${Y}.test(${g})`}function*B(l,j,g){if(yield`(typeof ${g} === 'string')`,X(l.maxLength))yield`${g}.length <= ${l.maxLength}`;if(X(l.minLength))yield`${g}.length >= ${l.minLength}`;if(l.pattern!==void 0)yield`${G(`${new RegExp(l.pattern)};`)}.test(${g})`;if(l.format!==void 0)yield`format('${l.format}', ${g})`}function*Z(l,j,g){yield`(typeof ${g} === 'symbol')`}function*W(l,j,g){yield`(typeof ${g} === 'string')`,yield`${G(`${new RegExp(l.pattern)};`)}.test(${g})`}function*q(l,j,g){yield`${v(l.$ref)}(${g})`}function*A(l,j,g){if(yield`Array.isArray(${g})`,l.items===void 0)return yield`${g}.length === 0`;yield`(${g}.length === ${l.maxItems})`;for(let Y=0;Y<l.items.length;Y++)yield`${k(l.items[Y],j,`${g}[${Y}]`)}`}function*oe(l,j,g){yield`${g} === undefined`}function*Q(l,j,g){yield`(${l.anyOf.map((E)=>k(E,j,g)).join(" || ")})`}function*re(l,j,g){if(yield`${g} instanceof Uint8Array`,X(l.maxByteLength))yield`(${g}.length <= ${l.maxByteLength})`;if(X(l.minByteLength))yield`(${g}.length >= ${l.minByteLength})`}function*ie(l,j,g){yield"true"}function*ge(l,j,g){yield pn.IsVoidLike(g)}function*ee(l,j,g){let Y=D.instances.size;D.instances.set(Y,l),yield`kind('${l[O]}', ${Y}, ${g})`}function*ae(l,j,g,Y=!0){let E=Ye(l.$id)?[...j,l]:j,U=l;if(Y&&Ye(l.$id)){let $e=v(l.$id);if(D.functions.has($e))return yield`${$e}(${g})`;else{D.functions.set($e,"<deferred>");let dt=we($e,l,j,"value",!1);return D.functions.set($e,dt),yield`${$e}(${g})`}}switch(U[O]){case"Any":return yield*r(U,E,g);case"Argument":return yield*n(U,E,g);case"Array":return yield*o(U,E,g);case"AsyncIterator":return yield*s(U,E,g);case"BigInt":return yield*i(U,E,g);case"Boolean":return yield*a(U,E,g);case"Constructor":return yield*u(U,E,g);case"Date":return yield*c(U,E,g);case"Function":return yield*f(U,E,g);case"Import":return yield*d(U,E,g);case"Integer":return yield*m(U,E,g);case"Intersect":return yield*y(U,E,g);case"Iterator":return yield*p(U,E,g);case"Literal":return yield*h(U,E,g);case"Never":return yield*x(U,E,g);case"Not":return yield*R(U,E,g);case"Null":return yield*w(U,E,g);case"Number":return yield*P(U,E,g);case"Object":return yield*C(U,E,g);case"Promise":return yield*J(U,E,g);case"Record":return yield*z(U,E,g);case"Ref":return yield*L(U,E,g);case"RegExp":return yield*T(U,E,g);case"String":return yield*B(U,E,g);case"Symbol":return yield*Z(U,E,g);case"TemplateLiteral":return yield*W(U,E,g);case"This":return yield*q(U,E,g);case"Tuple":return yield*A(U,E,g);case"Undefined":return yield*oe(U,E,g);case"Union":return yield*Q(U,E,g);case"Uint8Array":return yield*re(U,E,g);case"Unknown":return yield*ie(U,E,g);case"Void":return yield*ge(U,E,g);default:if(!co(U[O]))throw new tu(l);return yield*ee(U,E,g)}}let D={language:"javascript",functions:new Map,variables:new Map,instances:new Map};function k(l,j,g,Y=!0){return`(${[...ae(l,j,g,Y)].join(" && ")})`}function v(l){return`check_${di.Encode(l)}`}function G(l){let j=`local_${D.variables.size}`;return D.variables.set(j,`const ${j} = ${l}`),j}function we(l,j,g,Y,E=!0){let[U,$e]=[`
3
+ `,(or)=>"".padStart(or," ")],dt=Ce("value","any"),mr=At("boolean"),Ut=[...ae(j,g,Y,E)].map((or)=>`${$e(4)}${or}`).join(` &&${U}`);return`function ${l}(${dt})${mr} {${U}${$e(2)}return (${U}${Ut}${U}${$e(2)})
4
+ }`}function Ce(l,j){let g=D.language==="typescript"?`: ${j}`:"";return`${l}${g}`}function At(l){return D.language==="typescript"?`: ${l}`:""}function Lt(l,j,g){let Y=we("check",l,j,"value"),E=Ce("value","any"),U=At("boolean"),$e=[...D.functions.values()],dt=[...D.variables.values()],mr=Ye(l.$id)?`return function check(${E})${U} {
5
+ return ${v(l.$id)}(value)
6
+ }`:`return ${Y}`;return[...dt,...$e,mr].join(`
7
+ `)}function ct(...l){let j={language:"javascript"},[g,Y,E]=l.length===2&&Ge(l[1])?[l[0],l[1],j]:l.length===2&&!Ge(l[1])?[l[0],[],l[1]]:l.length===3?[l[0],l[1],l[2]]:l.length===1?[l[0],[],j]:[null,[],j];if(D.language=E.language,D.variables.clear(),D.functions.clear(),D.instances.clear(),!Ee(g))throw new li(g);for(let U of Y)if(!Ee(U))throw new li(U);return Lt(g,Y,E)}e.Code=ct;function wc(l,j=[]){let g=ct(l,j,{language:"javascript"}),Y=globalThis.Function("kind","format","hash",g),E=new Map(D.instances);function U(Ut,or,Bo){if(!co(Ut)||!E.has(or))return!1;let $c=vs(Ut),kc=E.get(or);return $c(kc,Bo)}function $e(Ut,or){if(!Ks(Ut))return!1;return Bs(Ut)(or)}function dt(Ut){return Mn(Ut)}let mr=Y(U,$e,dt);return new eu(l,j,mr,g)}e.Compile=wc})($o||($o={}));var fe;(function(e){e.assertEqual=(o)=>{};function t(o){}e.assertIs=t;function r(o){throw Error()}e.assertNever=r,e.arrayToEnum=(o)=>{let s={};for(let i of o)s[i]=i;return s},e.getValidEnumValues=(o)=>{let s=e.objectKeys(o).filter((a)=>typeof o[o[a]]!=="number"),i={};for(let a of s)i[a]=o[a];return e.objectValues(i)},e.objectValues=(o)=>e.objectKeys(o).map(function(s){return o[s]}),e.objectKeys=typeof Object.keys==="function"?(o)=>Object.keys(o):(o)=>{let s=[];for(let i in o)if(Object.prototype.hasOwnProperty.call(o,i))s.push(i);return s},e.find=(o,s)=>{for(let i of o)if(s(i))return i;return},e.isInteger=typeof Number.isInteger==="function"?(o)=>Number.isInteger(o):(o)=>typeof o==="number"&&Number.isFinite(o)&&Math.floor(o)===o;function n(o,s=" | "){return o.map((i)=>typeof i==="string"?`'${i}'`:i).join(s)}e.joinValues=n,e.jsonStringifyReplacer=(o,s)=>{if(typeof s==="bigint")return s.toString();return s}})(fe||(fe={}));var mi;(function(e){e.mergeShapes=(t,r)=>({...t,...r})})(mi||(mi={}));var M=fe.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),cr=(e)=>{switch(typeof e){case"undefined":return M.undefined;case"string":return M.string;case"number":return Number.isNaN(e)?M.nan:M.number;case"boolean":return M.boolean;case"function":return M.function;case"bigint":return M.bigint;case"symbol":return M.symbol;case"object":if(Array.isArray(e))return M.array;if(e===null)return M.null;if(e.then&&typeof e.then==="function"&&e.catch&&typeof e.catch==="function")return M.promise;if(typeof Map<"u"&&e instanceof Map)return M.map;if(typeof Set<"u"&&e instanceof Set)return M.set;if(typeof Date<"u"&&e instanceof Date)return M.date;return M.object;default:return M.unknown}};var S=fe.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"]),Fm=(e)=>JSON.stringify(e,null,2).replace(/"([^"]+)":/g,"$1:");class xt extends Error{get errors(){return this.issues}constructor(e){super();this.issues=[],this.addIssue=(r)=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};let t=new.target.prototype;if(Object.setPrototypeOf)Object.setPrototypeOf(this,t);else this.__proto__=t;this.name="ZodError",this.issues=e}format(e){let t=e||function(o){return o.message},r={_errors:[]},n=(o)=>{for(let s of o.issues)if(s.code==="invalid_union")s.unionErrors.map(n);else if(s.code==="invalid_return_type")n(s.returnTypeError);else if(s.code==="invalid_arguments")n(s.argumentsError);else if(s.path.length===0)r._errors.push(t(s));else{let i=r,a=0;while(a<s.path.length){let u=s.path[a];if(a!==s.path.length-1)i[u]=i[u]||{_errors:[]};else i[u]=i[u]||{_errors:[]},i[u]._errors.push(t(s));i=i[u],a++}}};return n(this),r}static assert(e){if(!(e instanceof xt))throw Error(`Not a ZodError: ${e}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,fe.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(e=(t)=>t.message){let t={},r=[];for(let n of this.issues)if(n.path.length>0){let o=n.path[0];t[o]=t[o]||[],t[o].push(e(n))}else r.push(e(n));return{formErrors:r,fieldErrors:t}}get formErrors(){return this.flatten()}}xt.create=(e)=>new xt(e);var Nm=(e,t)=>{let r;switch(e.code){case S.invalid_type:if(e.received===M.undefined)r="Required";else r=`Expected ${e.expected}, received ${e.received}`;break;case S.invalid_literal:r=`Invalid literal value, expected ${JSON.stringify(e.expected,fe.jsonStringifyReplacer)}`;break;case S.unrecognized_keys:r=`Unrecognized key(s) in object: ${fe.joinValues(e.keys,", ")}`;break;case S.invalid_union:r="Invalid input";break;case S.invalid_union_discriminator:r=`Invalid discriminator value. Expected ${fe.joinValues(e.options)}`;break;case S.invalid_enum_value:r=`Invalid enum value. Expected ${fe.joinValues(e.options)}, received '${e.received}'`;break;case S.invalid_arguments:r="Invalid function arguments";break;case S.invalid_return_type:r="Invalid function return type";break;case S.invalid_date:r="Invalid date";break;case S.invalid_string:if(typeof e.validation==="object")if("includes"in e.validation){if(r=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position==="number")r=`${r} at one or more positions greater than or equal to ${e.validation.position}`}else if("startsWith"in e.validation)r=`Invalid input: must start with "${e.validation.startsWith}"`;else if("endsWith"in e.validation)r=`Invalid input: must end with "${e.validation.endsWith}"`;else fe.assertNever(e.validation);else if(e.validation!=="regex")r=`Invalid ${e.validation}`;else r="Invalid";break;case S.too_small:if(e.type==="array")r=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`;else if(e.type==="string")r=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`;else if(e.type==="number")r=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`;else if(e.type==="bigint")r=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`;else if(e.type==="date")r=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`;else r="Invalid input";break;case S.too_big:if(e.type==="array")r=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`;else if(e.type==="string")r=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`;else if(e.type==="number")r=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`;else if(e.type==="bigint")r=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`;else if(e.type==="date")r=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`;else r="Invalid input";break;case S.custom:r="Invalid input";break;case S.invalid_intersection_types:r="Intersection results could not be merged";break;case S.not_multiple_of:r=`Number must be a multiple of ${e.multipleOf}`;break;case S.not_finite:r="Number must be finite";break;default:r=t.defaultError,fe.assertNever(e)}return{message:r}},kr=Nm;var ru=kr;function jm(e){ru=e}function Kn(){return ru}var ko=(e)=>{let{data:t,path:r,errorMaps:n,issueData:o}=e,s=[...r,...o.path||[]],i={...o,path:s};if(o.message!==void 0)return{...o,path:s,message:o.message};let a="",u=n.filter((c)=>!!c).slice().reverse();for(let c of u)a=c(i,{data:t,defaultError:a}).message;return{...o,path:s,message:a}},Mm=[];function F(e,t){let r=Kn(),n=ko({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,r,r===kr?void 0:kr].filter((o)=>!!o)});e.common.issues.push(n)}class nt{constructor(){this.value="valid"}dirty(){if(this.value==="valid")this.value="dirty"}abort(){if(this.value!=="aborted")this.value="aborted"}static mergeArray(e,t){let r=[];for(let n of t){if(n.status==="aborted")return H;if(n.status==="dirty")e.dirty();r.push(n.value)}return{status:e.value,value:r}}static async mergeObjectAsync(e,t){let r=[];for(let n of t){let o=await n.key,s=await n.value;r.push({key:o,value:s})}return nt.mergeObjectSync(e,r)}static mergeObjectSync(e,t){let r={};for(let n of t){let{key:o,value:s}=n;if(o.status==="aborted")return H;if(s.status==="aborted")return H;if(o.status==="dirty")e.dirty();if(s.status==="dirty")e.dirty();if(o.value!=="__proto__"&&(typeof s.value<"u"||n.alwaysSet))r[o.value]=s.value}return{status:e.value,value:r}}}var H=Object.freeze({status:"aborted"}),ln=(e)=>({status:"dirty",value:e}),ut=(e)=>({status:"valid",value:e}),hs=(e)=>e.status==="aborted",xs=(e)=>e.status==="dirty",vr=(e)=>e.status==="valid",Bn=(e)=>typeof Promise<"u"&&e instanceof Promise;var K;(function(e){e.errToObj=(t)=>typeof t==="string"?{message:t}:t||{},e.toString=(t)=>typeof t==="string"?t:t?.message})(K||(K={}));class er{constructor(e,t,r,n){this._cachedPath=[],this.parent=e,this.data=t,this._path=r,this._key=n}get path(){if(!this._cachedPath.length)if(Array.isArray(this._key))this._cachedPath.push(...this._path,...this._key);else this._cachedPath.push(...this._path,this._key);return this._cachedPath}}var nu=(e,t)=>{if(vr(t))return{success:!0,data:t.value};else{if(!e.common.issues.length)throw Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;let r=new xt(e.common.issues);return this._error=r,this._error}}}};function te(e){if(!e)return{};let{errorMap:t,invalid_type_error:r,required_error:n,description:o}=e;if(t&&(r||n))throw Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);if(t)return{errorMap:t,description:o};return{errorMap:(i,a)=>{let{message:u}=e;if(i.code==="invalid_enum_value")return{message:u??a.defaultError};if(typeof a.data>"u")return{message:u??n??a.defaultError};if(i.code!=="invalid_type")return{message:a.defaultError};return{message:u??r??a.defaultError}},description:o}}class se{get description(){return this._def.description}_getType(e){return cr(e.data)}_getOrReturnCtx(e,t){return t||{common:e.parent.common,data:e.data,parsedType:cr(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}_processInputParams(e){return{status:new nt,ctx:{common:e.parent.common,data:e.data,parsedType:cr(e.data),schemaErrorMap:this._def.errorMap,path:e.path,parent:e.parent}}}_parseSync(e){let t=this._parse(e);if(Bn(t))throw Error("Synchronous parse encountered promise.");return t}_parseAsync(e){let t=this._parse(e);return Promise.resolve(t)}parse(e,t){let r=this.safeParse(e,t);if(r.success)return r.data;throw r.error}safeParse(e,t){let r={common:{issues:[],async:t?.async??!1,contextualErrorMap:t?.errorMap},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:cr(e)},n=this._parseSync({data:e,path:r.path,parent:r});return nu(r,n)}"~validate"(e){let t={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:cr(e)};if(!this["~standard"].async)try{let r=this._parseSync({data:e,path:[],parent:t});return vr(r)?{value:r.value}:{issues:t.common.issues}}catch(r){if(r?.message?.toLowerCase()?.includes("encountered"))this["~standard"].async=!0;t.common={issues:[],async:!0}}return this._parseAsync({data:e,path:[],parent:t}).then((r)=>vr(r)?{value:r.value}:{issues:t.common.issues})}async parseAsync(e,t){let r=await this.safeParseAsync(e,t);if(r.success)return r.data;throw r.error}async safeParseAsync(e,t){let r={common:{issues:[],contextualErrorMap:t?.errorMap,async:!0},path:t?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:e,parsedType:cr(e)},n=this._parse({data:e,path:r.path,parent:r}),o=await(Bn(n)?n:Promise.resolve(n));return nu(r,o)}refine(e,t){let r=(n)=>{if(typeof t==="string"||typeof t>"u")return{message:t};else if(typeof t==="function")return t(n);else return t};return this._refinement((n,o)=>{let s=e(n),i=()=>o.addIssue({code:S.custom,...r(n)});if(typeof Promise<"u"&&s instanceof Promise)return s.then((a)=>{if(!a)return i(),!1;else return!0});if(!s)return i(),!1;else return!0})}refinement(e,t){return this._refinement((r,n)=>{if(!e(r))return n.addIssue(typeof t==="function"?t(r,n):t),!1;else return!0})}_refinement(e){return new tr({schema:this,typeName:V.ZodEffects,effect:{type:"refinement",refinement:e}})}superRefine(e){return this._refinement(e)}constructor(e){this.spa=this.safeParseAsync,this._def=e,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:(t)=>this["~validate"](t)}}optional(){return Zt.create(this,this._def)}nullable(){return Sr.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Qt.create(this)}promise(){return hn.create(this,this._def)}or(e){return zn.create([this,e],this._def)}and(e){return Vn.create(this,e,this._def)}transform(e){return new tr({...te(this._def),schema:this,typeName:V.ZodEffects,effect:{type:"transform",transform:e}})}default(e){let t=typeof e==="function"?e:()=>e;return new Xn({...te(this._def),innerType:this,defaultValue:t,typeName:V.ZodDefault})}brand(){return new Is({typeName:V.ZodBranded,type:this,...te(this._def)})}catch(e){let t=typeof e==="function"?e:()=>e;return new Qn({...te(this._def),innerType:this,catchValue:t,typeName:V.ZodCatch})}describe(e){return new this.constructor({...this._def,description:e})}pipe(e){return Fo.create(this,e)}readonly(){return Zn.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}var Em=/^c[^\s-]{8,}$/i,Lm=/^[0-9a-z]+$/,Um=/^[0-9A-HJKMNP-TV-Z]{26}$/i,Km=/^[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,Bm=/^[a-z0-9_-]{21}$/i,vm=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,Dm=/^[-+]?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)?)??$/,qm=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,Gm="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$",yi,Hm=/^(?:(?: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])$/,zm=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,Vm=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,Jm=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Wm=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,Ym=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,su="((\\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])))",Xm=new RegExp(`^${su}$`);function iu(e){let t="[0-5]\\d";if(e.precision)t=`${t}\\.\\d{${e.precision}}`;else if(e.precision==null)t=`${t}(\\.\\d+)?`;let r=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${r}`}function Qm(e){return new RegExp(`^${iu(e)}$`)}function au(e){let t=`${su}T${iu(e)}`,r=[];if(r.push(e.local?"Z?":"Z"),e.offset)r.push("([+-]\\d{2}:?\\d{2})");return t=`${t}(${r.join("|")})`,new RegExp(`^${t}$`)}function Zm(e,t){if((t==="v4"||!t)&&Hm.test(e))return!0;if((t==="v6"||!t)&&Vm.test(e))return!0;return!1}function ey(e,t){if(!vm.test(e))return!1;try{let[r]=e.split(".");if(!r)return!1;let n=r.replace(/-/g,"+").replace(/_/g,"/").padEnd(r.length+(4-r.length%4)%4,"="),o=JSON.parse(atob(n));if(typeof o!=="object"||o===null)return!1;if("typ"in o&&o?.typ!=="JWT")return!1;if(!o.alg)return!1;if(t&&o.alg!==t)return!1;return!0}catch{return!1}}function ty(e,t){if((t==="v4"||!t)&&zm.test(e))return!0;if((t==="v6"||!t)&&Jm.test(e))return!0;return!1}class Xt extends se{_parse(e){if(this._def.coerce)e.data=String(e.data);if(this._getType(e)!==M.string){let o=this._getOrReturnCtx(e);return F(o,{code:S.invalid_type,expected:M.string,received:o.parsedType}),H}let r=new nt,n=void 0;for(let o of this._def.checks)if(o.kind==="min"){if(e.data.length<o.value)n=this._getOrReturnCtx(e,n),F(n,{code:S.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty()}else if(o.kind==="max"){if(e.data.length>o.value)n=this._getOrReturnCtx(e,n),F(n,{code:S.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!1,message:o.message}),r.dirty()}else if(o.kind==="length"){let s=e.data.length>o.value,i=e.data.length<o.value;if(s||i){if(n=this._getOrReturnCtx(e,n),s)F(n,{code:S.too_big,maximum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message});else if(i)F(n,{code:S.too_small,minimum:o.value,type:"string",inclusive:!0,exact:!0,message:o.message});r.dirty()}}else if(o.kind==="email"){if(!qm.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"email",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="emoji"){if(!yi)yi=new RegExp(Gm,"u");if(!yi.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"emoji",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="uuid"){if(!Km.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"uuid",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="nanoid"){if(!Bm.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"nanoid",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="cuid"){if(!Em.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"cuid",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="cuid2"){if(!Lm.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"cuid2",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="ulid"){if(!Um.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"ulid",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="url")try{new URL(e.data)}catch{n=this._getOrReturnCtx(e,n),F(n,{validation:"url",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="regex"){if(o.regex.lastIndex=0,!o.regex.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"regex",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="trim")e.data=e.data.trim();else if(o.kind==="includes"){if(!e.data.includes(o.value,o.position))n=this._getOrReturnCtx(e,n),F(n,{code:S.invalid_string,validation:{includes:o.value,position:o.position},message:o.message}),r.dirty()}else if(o.kind==="toLowerCase")e.data=e.data.toLowerCase();else if(o.kind==="toUpperCase")e.data=e.data.toUpperCase();else if(o.kind==="startsWith"){if(!e.data.startsWith(o.value))n=this._getOrReturnCtx(e,n),F(n,{code:S.invalid_string,validation:{startsWith:o.value},message:o.message}),r.dirty()}else if(o.kind==="endsWith"){if(!e.data.endsWith(o.value))n=this._getOrReturnCtx(e,n),F(n,{code:S.invalid_string,validation:{endsWith:o.value},message:o.message}),r.dirty()}else if(o.kind==="datetime"){if(!au(o).test(e.data))n=this._getOrReturnCtx(e,n),F(n,{code:S.invalid_string,validation:"datetime",message:o.message}),r.dirty()}else if(o.kind==="date"){if(!Xm.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{code:S.invalid_string,validation:"date",message:o.message}),r.dirty()}else if(o.kind==="time"){if(!Qm(o).test(e.data))n=this._getOrReturnCtx(e,n),F(n,{code:S.invalid_string,validation:"time",message:o.message}),r.dirty()}else if(o.kind==="duration"){if(!Dm.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"duration",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="ip"){if(!Zm(e.data,o.version))n=this._getOrReturnCtx(e,n),F(n,{validation:"ip",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="jwt"){if(!ey(e.data,o.alg))n=this._getOrReturnCtx(e,n),F(n,{validation:"jwt",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="cidr"){if(!ty(e.data,o.version))n=this._getOrReturnCtx(e,n),F(n,{validation:"cidr",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="base64"){if(!Wm.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"base64",code:S.invalid_string,message:o.message}),r.dirty()}else if(o.kind==="base64url"){if(!Ym.test(e.data))n=this._getOrReturnCtx(e,n),F(n,{validation:"base64url",code:S.invalid_string,message:o.message}),r.dirty()}else fe.assertNever(o);return{status:r.value,value:e.data}}_regex(e,t,r){return this.refinement((n)=>e.test(n),{validation:t,code:S.invalid_string,...K.errToObj(r)})}_addCheck(e){return new Xt({...this._def,checks:[...this._def.checks,e]})}email(e){return this._addCheck({kind:"email",...K.errToObj(e)})}url(e){return this._addCheck({kind:"url",...K.errToObj(e)})}emoji(e){return this._addCheck({kind:"emoji",...K.errToObj(e)})}uuid(e){return this._addCheck({kind:"uuid",...K.errToObj(e)})}nanoid(e){return this._addCheck({kind:"nanoid",...K.errToObj(e)})}cuid(e){return this._addCheck({kind:"cuid",...K.errToObj(e)})}cuid2(e){return this._addCheck({kind:"cuid2",...K.errToObj(e)})}ulid(e){return this._addCheck({kind:"ulid",...K.errToObj(e)})}base64(e){return this._addCheck({kind:"base64",...K.errToObj(e)})}base64url(e){return this._addCheck({kind:"base64url",...K.errToObj(e)})}jwt(e){return this._addCheck({kind:"jwt",...K.errToObj(e)})}ip(e){return this._addCheck({kind:"ip",...K.errToObj(e)})}cidr(e){return this._addCheck({kind:"cidr",...K.errToObj(e)})}datetime(e){if(typeof e==="string")return this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:e});return this._addCheck({kind:"datetime",precision:typeof e?.precision>"u"?null:e?.precision,offset:e?.offset??!1,local:e?.local??!1,...K.errToObj(e?.message)})}date(e){return this._addCheck({kind:"date",message:e})}time(e){if(typeof e==="string")return this._addCheck({kind:"time",precision:null,message:e});return this._addCheck({kind:"time",precision:typeof e?.precision>"u"?null:e?.precision,...K.errToObj(e?.message)})}duration(e){return this._addCheck({kind:"duration",...K.errToObj(e)})}regex(e,t){return this._addCheck({kind:"regex",regex:e,...K.errToObj(t)})}includes(e,t){return this._addCheck({kind:"includes",value:e,position:t?.position,...K.errToObj(t?.message)})}startsWith(e,t){return this._addCheck({kind:"startsWith",value:e,...K.errToObj(t)})}endsWith(e,t){return this._addCheck({kind:"endsWith",value:e,...K.errToObj(t)})}min(e,t){return this._addCheck({kind:"min",value:e,...K.errToObj(t)})}max(e,t){return this._addCheck({kind:"max",value:e,...K.errToObj(t)})}length(e,t){return this._addCheck({kind:"length",value:e,...K.errToObj(t)})}nonempty(e){return this.min(1,K.errToObj(e))}trim(){return new Xt({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Xt({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Xt({...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 isCIDR(){return!!this._def.checks.find((e)=>e.kind==="cidr")}get isBase64(){return!!this._def.checks.find((e)=>e.kind==="base64")}get isBase64url(){return!!this._def.checks.find((e)=>e.kind==="base64url")}get minLength(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e}get maxLength(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e}}Xt.create=(e)=>new Xt({checks:[],typeName:V.ZodString,coerce:e?.coerce??!1,...te(e)});function ry(e,t){let r=(e.toString().split(".")[1]||"").length,n=(t.toString().split(".")[1]||"").length,o=r>n?r:n,s=Number.parseInt(e.toFixed(o).replace(".","")),i=Number.parseInt(t.toFixed(o).replace(".",""));return s%i/10**o}class qr extends se{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);if(this._getType(e)!==M.number){let o=this._getOrReturnCtx(e);return F(o,{code:S.invalid_type,expected:M.number,received:o.parsedType}),H}let r=void 0,n=new nt;for(let o of this._def.checks)if(o.kind==="int"){if(!fe.isInteger(e.data))r=this._getOrReturnCtx(e,r),F(r,{code:S.invalid_type,expected:"integer",received:"float",message:o.message}),n.dirty()}else if(o.kind==="min"){if(o.inclusive?e.data<o.value:e.data<=o.value)r=this._getOrReturnCtx(e,r),F(r,{code:S.too_small,minimum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),n.dirty()}else if(o.kind==="max"){if(o.inclusive?e.data>o.value:e.data>=o.value)r=this._getOrReturnCtx(e,r),F(r,{code:S.too_big,maximum:o.value,type:"number",inclusive:o.inclusive,exact:!1,message:o.message}),n.dirty()}else if(o.kind==="multipleOf"){if(ry(e.data,o.value)!==0)r=this._getOrReturnCtx(e,r),F(r,{code:S.not_multiple_of,multipleOf:o.value,message:o.message}),n.dirty()}else if(o.kind==="finite"){if(!Number.isFinite(e.data))r=this._getOrReturnCtx(e,r),F(r,{code:S.not_finite,message:o.message}),n.dirty()}else fe.assertNever(o);return{status:n.value,value:e.data}}gte(e,t){return this.setLimit("min",e,!0,K.toString(t))}gt(e,t){return this.setLimit("min",e,!1,K.toString(t))}lte(e,t){return this.setLimit("max",e,!0,K.toString(t))}lt(e,t){return this.setLimit("max",e,!1,K.toString(t))}setLimit(e,t,r,n){return new qr({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:K.toString(n)}]})}_addCheck(e){return new qr({...this._def,checks:[...this._def.checks,e]})}int(e){return this._addCheck({kind:"int",message:K.toString(e)})}positive(e){return this._addCheck({kind:"min",value:0,inclusive:!1,message:K.toString(e)})}negative(e){return this._addCheck({kind:"max",value:0,inclusive:!1,message:K.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:0,inclusive:!0,message:K.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:0,inclusive:!0,message:K.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:K.toString(t)})}finite(e){return this._addCheck({kind:"finite",message:K.toString(e)})}safe(e){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:K.toString(e)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:K.toString(e)})}get minValue(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e}get maxValue(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e}get isInt(){return!!this._def.checks.find((e)=>e.kind==="int"||e.kind==="multipleOf"&&fe.isInteger(e.value))}get isFinite(){let e=null,t=null;for(let r of this._def.checks)if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;else if(r.kind==="min"){if(t===null||r.value>t)t=r.value}else if(r.kind==="max"){if(e===null||r.value<e)e=r.value}return Number.isFinite(t)&&Number.isFinite(e)}}qr.create=(e)=>new qr({checks:[],typeName:V.ZodNumber,coerce:e?.coerce||!1,...te(e)});class Gr extends se{constructor(){super(...arguments);this.min=this.gte,this.max=this.lte}_parse(e){if(this._def.coerce)try{e.data=BigInt(e.data)}catch{return this._getInvalidInput(e)}if(this._getType(e)!==M.bigint)return this._getInvalidInput(e);let r=void 0,n=new nt;for(let o of this._def.checks)if(o.kind==="min"){if(o.inclusive?e.data<o.value:e.data<=o.value)r=this._getOrReturnCtx(e,r),F(r,{code:S.too_small,type:"bigint",minimum:o.value,inclusive:o.inclusive,message:o.message}),n.dirty()}else if(o.kind==="max"){if(o.inclusive?e.data>o.value:e.data>=o.value)r=this._getOrReturnCtx(e,r),F(r,{code:S.too_big,type:"bigint",maximum:o.value,inclusive:o.inclusive,message:o.message}),n.dirty()}else if(o.kind==="multipleOf"){if(e.data%o.value!==BigInt(0))r=this._getOrReturnCtx(e,r),F(r,{code:S.not_multiple_of,multipleOf:o.value,message:o.message}),n.dirty()}else fe.assertNever(o);return{status:n.value,value:e.data}}_getInvalidInput(e){let t=this._getOrReturnCtx(e);return F(t,{code:S.invalid_type,expected:M.bigint,received:t.parsedType}),H}gte(e,t){return this.setLimit("min",e,!0,K.toString(t))}gt(e,t){return this.setLimit("min",e,!1,K.toString(t))}lte(e,t){return this.setLimit("max",e,!0,K.toString(t))}lt(e,t){return this.setLimit("max",e,!1,K.toString(t))}setLimit(e,t,r,n){return new Gr({...this._def,checks:[...this._def.checks,{kind:e,value:t,inclusive:r,message:K.toString(n)}]})}_addCheck(e){return new Gr({...this._def,checks:[...this._def.checks,e]})}positive(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:K.toString(e)})}negative(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:K.toString(e)})}nonpositive(e){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:K.toString(e)})}nonnegative(e){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:K.toString(e)})}multipleOf(e,t){return this._addCheck({kind:"multipleOf",value:e,message:K.toString(t)})}get minValue(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e}get maxValue(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e}}Gr.create=(e)=>new Gr({checks:[],typeName:V.ZodBigInt,coerce:e?.coerce??!1,...te(e)});class qn extends se{_parse(e){if(this._def.coerce)e.data=Boolean(e.data);if(this._getType(e)!==M.boolean){let r=this._getOrReturnCtx(e);return F(r,{code:S.invalid_type,expected:M.boolean,received:r.parsedType}),H}return ut(e.data)}}qn.create=(e)=>new qn({typeName:V.ZodBoolean,coerce:e?.coerce||!1,...te(e)});class mn extends se{_parse(e){if(this._def.coerce)e.data=new Date(e.data);if(this._getType(e)!==M.date){let o=this._getOrReturnCtx(e);return F(o,{code:S.invalid_type,expected:M.date,received:o.parsedType}),H}if(Number.isNaN(e.data.getTime())){let o=this._getOrReturnCtx(e);return F(o,{code:S.invalid_date}),H}let r=new nt,n=void 0;for(let o of this._def.checks)if(o.kind==="min"){if(e.data.getTime()<o.value)n=this._getOrReturnCtx(e,n),F(n,{code:S.too_small,message:o.message,inclusive:!0,exact:!1,minimum:o.value,type:"date"}),r.dirty()}else if(o.kind==="max"){if(e.data.getTime()>o.value)n=this._getOrReturnCtx(e,n),F(n,{code:S.too_big,message:o.message,inclusive:!0,exact:!1,maximum:o.value,type:"date"}),r.dirty()}else fe.assertNever(o);return{status:r.value,value:new Date(e.data.getTime())}}_addCheck(e){return new mn({...this._def,checks:[...this._def.checks,e]})}min(e,t){return this._addCheck({kind:"min",value:e.getTime(),message:K.toString(t)})}max(e,t){return this._addCheck({kind:"max",value:e.getTime(),message:K.toString(t)})}get minDate(){let e=null;for(let t of this._def.checks)if(t.kind==="min"){if(e===null||t.value>e)e=t.value}return e!=null?new Date(e):null}get maxDate(){let e=null;for(let t of this._def.checks)if(t.kind==="max"){if(e===null||t.value<e)e=t.value}return e!=null?new Date(e):null}}mn.create=(e)=>new mn({checks:[],coerce:e?.coerce||!1,typeName:V.ZodDate,...te(e)});class Ao extends se{_parse(e){if(this._getType(e)!==M.symbol){let r=this._getOrReturnCtx(e);return F(r,{code:S.invalid_type,expected:M.symbol,received:r.parsedType}),H}return ut(e.data)}}Ao.create=(e)=>new Ao({typeName:V.ZodSymbol,...te(e)});class Gn extends se{_parse(e){if(this._getType(e)!==M.undefined){let r=this._getOrReturnCtx(e);return F(r,{code:S.invalid_type,expected:M.undefined,received:r.parsedType}),H}return ut(e.data)}}Gn.create=(e)=>new Gn({typeName:V.ZodUndefined,...te(e)});class Hn extends se{_parse(e){if(this._getType(e)!==M.null){let r=this._getOrReturnCtx(e);return F(r,{code:S.invalid_type,expected:M.null,received:r.parsedType}),H}return ut(e.data)}}Hn.create=(e)=>new Hn({typeName:V.ZodNull,...te(e)});class yn extends se{constructor(){super(...arguments);this._any=!0}_parse(e){return ut(e.data)}}yn.create=(e)=>new yn({typeName:V.ZodAny,...te(e)});class Dr extends se{constructor(){super(...arguments);this._unknown=!0}_parse(e){return ut(e.data)}}Dr.create=(e)=>new Dr({typeName:V.ZodUnknown,...te(e)});class fr extends se{_parse(e){let t=this._getOrReturnCtx(e);return F(t,{code:S.invalid_type,expected:M.never,received:t.parsedType}),H}}fr.create=(e)=>new fr({typeName:V.ZodNever,...te(e)});class So extends se{_parse(e){if(this._getType(e)!==M.undefined){let r=this._getOrReturnCtx(e);return F(r,{code:S.invalid_type,expected:M.void,received:r.parsedType}),H}return ut(e.data)}}So.create=(e)=>new So({typeName:V.ZodVoid,...te(e)});class Qt extends se{_parse(e){let{ctx:t,status:r}=this._processInputParams(e),n=this._def;if(t.parsedType!==M.array)return F(t,{code:S.invalid_type,expected:M.array,received:t.parsedType}),H;if(n.exactLength!==null){let s=t.data.length>n.exactLength.value,i=t.data.length<n.exactLength.value;if(s||i)F(t,{code:s?S.too_big:S.too_small,minimum:i?n.exactLength.value:void 0,maximum:s?n.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:n.exactLength.message}),r.dirty()}if(n.minLength!==null){if(t.data.length<n.minLength.value)F(t,{code:S.too_small,minimum:n.minLength.value,type:"array",inclusive:!0,exact:!1,message:n.minLength.message}),r.dirty()}if(n.maxLength!==null){if(t.data.length>n.maxLength.value)F(t,{code:S.too_big,maximum:n.maxLength.value,type:"array",inclusive:!0,exact:!1,message:n.maxLength.message}),r.dirty()}if(t.common.async)return Promise.all([...t.data].map((s,i)=>n.type._parseAsync(new er(t,s,t.path,i)))).then((s)=>nt.mergeArray(r,s));let o=[...t.data].map((s,i)=>n.type._parseSync(new er(t,s,t.path,i)));return nt.mergeArray(r,o)}get element(){return this._def.type}min(e,t){return new Qt({...this._def,minLength:{value:e,message:K.toString(t)}})}max(e,t){return new Qt({...this._def,maxLength:{value:e,message:K.toString(t)}})}length(e,t){return new Qt({...this._def,exactLength:{value:e,message:K.toString(t)}})}nonempty(e){return this.min(1,e)}}Qt.create=(e,t)=>new Qt({type:e,minLength:null,maxLength:null,exactLength:null,typeName:V.ZodArray,...te(t)});function vn(e){if(e instanceof ve){let t={};for(let r in e.shape){let n=e.shape[r];t[r]=Zt.create(vn(n))}return new ve({...e._def,shape:()=>t})}else if(e instanceof Qt)return new Qt({...e._def,type:vn(e.element)});else if(e instanceof Zt)return Zt.create(vn(e.unwrap()));else if(e instanceof Sr)return Sr.create(vn(e.unwrap()));else if(e instanceof dr)return dr.create(e.items.map((t)=>vn(t)));else return e}class ve extends se{constructor(){super(...arguments);this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;let e=this._def.shape(),t=fe.objectKeys(e);return this._cached={shape:e,keys:t},this._cached}_parse(e){if(this._getType(e)!==M.object){let u=this._getOrReturnCtx(e);return F(u,{code:S.invalid_type,expected:M.object,received:u.parsedType}),H}let{status:r,ctx:n}=this._processInputParams(e),{shape:o,keys:s}=this._getCached(),i=[];if(!(this._def.catchall instanceof fr&&this._def.unknownKeys==="strip")){for(let u in n.data)if(!s.includes(u))i.push(u)}let a=[];for(let u of s){let c=o[u],f=n.data[u];a.push({key:{status:"valid",value:u},value:c._parse(new er(n,f,n.path,u)),alwaysSet:u in n.data})}if(this._def.catchall instanceof fr){let u=this._def.unknownKeys;if(u==="passthrough")for(let c of i)a.push({key:{status:"valid",value:c},value:{status:"valid",value:n.data[c]}});else if(u==="strict"){if(i.length>0)F(n,{code:S.unrecognized_keys,keys:i}),r.dirty()}else if(u==="strip");else throw Error("Internal ZodObject error: invalid unknownKeys value.")}else{let u=this._def.catchall;for(let c of i){let f=n.data[c];a.push({key:{status:"valid",value:c},value:u._parse(new er(n,f,n.path,c)),alwaysSet:c in n.data})}}if(n.common.async)return Promise.resolve().then(async()=>{let u=[];for(let c of a){let f=await c.key,d=await c.value;u.push({key:f,value:d,alwaysSet:c.alwaysSet})}return u}).then((u)=>nt.mergeObjectSync(r,u));else return nt.mergeObjectSync(r,a)}get shape(){return this._def.shape()}strict(e){return K.errToObj,new ve({...this._def,unknownKeys:"strict",...e!==void 0?{errorMap:(t,r)=>{let n=this._def.errorMap?.(t,r).message??r.defaultError;if(t.code==="unrecognized_keys")return{message:K.errToObj(e).message??n};return{message:n}}}:{}})}strip(){return new ve({...this._def,unknownKeys:"strip"})}passthrough(){return new ve({...this._def,unknownKeys:"passthrough"})}extend(e){return new ve({...this._def,shape:()=>({...this._def.shape(),...e})})}merge(e){return new ve({unknownKeys:e._def.unknownKeys,catchall:e._def.catchall,shape:()=>({...this._def.shape(),...e._def.shape()}),typeName:V.ZodObject})}setKey(e,t){return this.augment({[e]:t})}catchall(e){return new ve({...this._def,catchall:e})}pick(e){let t={};for(let r of fe.objectKeys(e))if(e[r]&&this.shape[r])t[r]=this.shape[r];return new ve({...this._def,shape:()=>t})}omit(e){let t={};for(let r of fe.objectKeys(this.shape))if(!e[r])t[r]=this.shape[r];return new ve({...this._def,shape:()=>t})}deepPartial(){return vn(this)}partial(e){let t={};for(let r of fe.objectKeys(this.shape)){let n=this.shape[r];if(e&&!e[r])t[r]=n;else t[r]=n.optional()}return new ve({...this._def,shape:()=>t})}required(e){let t={};for(let r of fe.objectKeys(this.shape))if(e&&!e[r])t[r]=this.shape[r];else{let o=this.shape[r];while(o instanceof Zt)o=o._def.innerType;t[r]=o}return new ve({...this._def,shape:()=>t})}keyof(){return uu(fe.objectKeys(this.shape))}}ve.create=(e,t)=>new ve({shape:()=>e,unknownKeys:"strip",catchall:fr.create(),typeName:V.ZodObject,...te(t)});ve.strictCreate=(e,t)=>new ve({shape:()=>e,unknownKeys:"strict",catchall:fr.create(),typeName:V.ZodObject,...te(t)});ve.lazycreate=(e,t)=>new ve({shape:e,unknownKeys:"strip",catchall:fr.create(),typeName:V.ZodObject,...te(t)});class zn extends se{_parse(e){let{ctx:t}=this._processInputParams(e),r=this._def.options;function n(o){for(let i of o)if(i.result.status==="valid")return i.result;for(let i of o)if(i.result.status==="dirty")return t.common.issues.push(...i.ctx.common.issues),i.result;let s=o.map((i)=>new xt(i.ctx.common.issues));return F(t,{code:S.invalid_union,unionErrors:s}),H}if(t.common.async)return Promise.all(r.map(async(o)=>{let s={...t,common:{...t.common,issues:[]},parent:null};return{result:await o._parseAsync({data:t.data,path:t.path,parent:s}),ctx:s}})).then(n);else{let o=void 0,s=[];for(let a of r){let u={...t,common:{...t.common,issues:[]},parent:null},c=a._parseSync({data:t.data,path:t.path,parent:u});if(c.status==="valid")return c;else if(c.status==="dirty"&&!o)o={result:c,ctx:u};if(u.common.issues.length)s.push(u.common.issues)}if(o)return t.common.issues.push(...o.ctx.common.issues),o.result;let i=s.map((a)=>new xt(a));return F(t,{code:S.invalid_union,unionErrors:i}),H}}get options(){return this._def.options}}zn.create=(e,t)=>new zn({options:e,typeName:V.ZodUnion,...te(t)});var Ar=(e)=>{if(e instanceof Jn)return Ar(e.schema);else if(e instanceof tr)return Ar(e.innerType());else if(e instanceof Wn)return[e.value];else if(e instanceof Hr)return e.options;else if(e instanceof Yn)return fe.objectValues(e.enum);else if(e instanceof Xn)return Ar(e._def.innerType);else if(e instanceof Gn)return[void 0];else if(e instanceof Hn)return[null];else if(e instanceof Zt)return[void 0,...Ar(e.unwrap())];else if(e instanceof Sr)return[null,...Ar(e.unwrap())];else if(e instanceof Is)return Ar(e.unwrap());else if(e instanceof Zn)return Ar(e.unwrap());else if(e instanceof Qn)return Ar(e._def.innerType);else return[]};class bs extends se{_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==M.object)return F(t,{code:S.invalid_type,expected:M.object,received:t.parsedType}),H;let r=this.discriminator,n=t.data[r],o=this.optionsMap.get(n);if(!o)return F(t,{code:S.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),H;if(t.common.async)return o._parseAsync({data:t.data,path:t.path,parent:t});else return o._parseSync({data:t.data,path:t.path,parent:t})}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(e,t,r){let n=new Map;for(let o of t){let s=Ar(o.shape[e]);if(!s.length)throw Error(`A discriminator value for key \`${e}\` could not be extracted from all schema options`);for(let i of s){if(n.has(i))throw Error(`Discriminator property ${String(e)} has duplicate value ${String(i)}`);n.set(i,o)}}return new bs({typeName:V.ZodDiscriminatedUnion,discriminator:e,options:t,optionsMap:n,...te(r)})}}function gi(e,t){let r=cr(e),n=cr(t);if(e===t)return{valid:!0,data:e};else if(r===M.object&&n===M.object){let o=fe.objectKeys(t),s=fe.objectKeys(e).filter((a)=>o.indexOf(a)!==-1),i={...e,...t};for(let a of s){let u=gi(e[a],t[a]);if(!u.valid)return{valid:!1};i[a]=u.data}return{valid:!0,data:i}}else if(r===M.array&&n===M.array){if(e.length!==t.length)return{valid:!1};let o=[];for(let s=0;s<e.length;s++){let i=e[s],a=t[s],u=gi(i,a);if(!u.valid)return{valid:!1};o.push(u.data)}return{valid:!0,data:o}}else if(r===M.date&&n===M.date&&+e===+t)return{valid:!0,data:e};else return{valid:!1}}class Vn extends se{_parse(e){let{status:t,ctx:r}=this._processInputParams(e),n=(o,s)=>{if(hs(o)||hs(s))return H;let i=gi(o.value,s.value);if(!i.valid)return F(r,{code:S.invalid_intersection_types}),H;if(xs(o)||xs(s))t.dirty();return{status:t.value,value:i.data}};if(r.common.async)return 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(([o,s])=>n(o,s));else return n(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Vn.create=(e,t,r)=>new Vn({left:e,right:t,typeName:V.ZodIntersection,...te(r)});class dr extends se{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.array)return F(r,{code:S.invalid_type,expected:M.array,received:r.parsedType}),H;if(r.data.length<this._def.items.length)return F(r,{code:S.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),H;if(!this._def.rest&&r.data.length>this._def.items.length)F(r,{code:S.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),t.dirty();let o=[...r.data].map((s,i)=>{let a=this._def.items[i]||this._def.rest;if(!a)return null;return a._parse(new er(r,s,r.path,i))}).filter((s)=>!!s);if(r.common.async)return Promise.all(o).then((s)=>nt.mergeArray(t,s));else return nt.mergeArray(t,o)}get items(){return this._def.items}rest(e){return new dr({...this._def,rest:e})}}dr.create=(e,t)=>{if(!Array.isArray(e))throw Error("You must pass an array of schemas to z.tuple([ ... ])");return new dr({items:e,typeName:V.ZodTuple,rest:null,...te(t)})};class Po extends se{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.object)return F(r,{code:S.invalid_type,expected:M.object,received:r.parsedType}),H;let n=[],o=this._def.keyType,s=this._def.valueType;for(let i in r.data)n.push({key:o._parse(new er(r,i,r.path,i)),value:s._parse(new er(r,r.data[i],r.path,i)),alwaysSet:i in r.data});if(r.common.async)return nt.mergeObjectAsync(t,n);else return nt.mergeObjectSync(t,n)}get element(){return this._def.valueType}static create(e,t,r){if(t instanceof se)return new Po({keyType:e,valueType:t,typeName:V.ZodRecord,...te(r)});return new Po({keyType:Xt.create(),valueType:e,typeName:V.ZodRecord,...te(t)})}}class Co extends se{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.map)return F(r,{code:S.invalid_type,expected:M.map,received:r.parsedType}),H;let n=this._def.keyType,o=this._def.valueType,s=[...r.data.entries()].map(([i,a],u)=>({key:n._parse(new er(r,i,r.path,[u,"key"])),value:o._parse(new er(r,a,r.path,[u,"value"]))}));if(r.common.async){let i=new Map;return Promise.resolve().then(async()=>{for(let a of s){let u=await a.key,c=await a.value;if(u.status==="aborted"||c.status==="aborted")return H;if(u.status==="dirty"||c.status==="dirty")t.dirty();i.set(u.value,c.value)}return{status:t.value,value:i}})}else{let i=new Map;for(let a of s){let{key:u,value:c}=a;if(u.status==="aborted"||c.status==="aborted")return H;if(u.status==="dirty"||c.status==="dirty")t.dirty();i.set(u.value,c.value)}return{status:t.value,value:i}}}}Co.create=(e,t,r)=>new Co({valueType:t,keyType:e,typeName:V.ZodMap,...te(r)});class gn extends se{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.parsedType!==M.set)return F(r,{code:S.invalid_type,expected:M.set,received:r.parsedType}),H;let n=this._def;if(n.minSize!==null){if(r.data.size<n.minSize.value)F(r,{code:S.too_small,minimum:n.minSize.value,type:"set",inclusive:!0,exact:!1,message:n.minSize.message}),t.dirty()}if(n.maxSize!==null){if(r.data.size>n.maxSize.value)F(r,{code:S.too_big,maximum:n.maxSize.value,type:"set",inclusive:!0,exact:!1,message:n.maxSize.message}),t.dirty()}let o=this._def.valueType;function s(a){let u=new Set;for(let c of a){if(c.status==="aborted")return H;if(c.status==="dirty")t.dirty();u.add(c.value)}return{status:t.value,value:u}}let i=[...r.data.values()].map((a,u)=>o._parse(new er(r,a,r.path,u)));if(r.common.async)return Promise.all(i).then((a)=>s(a));else return s(i)}min(e,t){return new gn({...this._def,minSize:{value:e,message:K.toString(t)}})}max(e,t){return new gn({...this._def,maxSize:{value:e,message:K.toString(t)}})}size(e,t){return this.min(e,t).max(e,t)}nonempty(e){return this.min(1,e)}}gn.create=(e,t)=>new gn({valueType:e,minSize:null,maxSize:null,typeName:V.ZodSet,...te(t)});class Dn extends se{constructor(){super(...arguments);this.validate=this.implement}_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==M.function)return F(t,{code:S.invalid_type,expected:M.function,received:t.parsedType}),H;function r(i,a){return ko({data:i,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Kn(),kr].filter((u)=>!!u),issueData:{code:S.invalid_arguments,argumentsError:a}})}function n(i,a){return ko({data:i,path:t.path,errorMaps:[t.common.contextualErrorMap,t.schemaErrorMap,Kn(),kr].filter((u)=>!!u),issueData:{code:S.invalid_return_type,returnTypeError:a}})}let o={errorMap:t.common.contextualErrorMap},s=t.data;if(this._def.returns instanceof hn){let i=this;return ut(async function(...a){let u=new xt([]),c=await i._def.args.parseAsync(a,o).catch((m)=>{throw u.addIssue(r(a,m)),u}),f=await Reflect.apply(s,this,c);return await i._def.returns._def.type.parseAsync(f,o).catch((m)=>{throw u.addIssue(n(f,m)),u})})}else{let i=this;return ut(function(...a){let u=i._def.args.safeParse(a,o);if(!u.success)throw new xt([r(a,u.error)]);let c=Reflect.apply(s,this,u.data),f=i._def.returns.safeParse(c,o);if(!f.success)throw new xt([n(c,f.error)]);return f.data})}}parameters(){return this._def.args}returnType(){return this._def.returns}args(...e){return new Dn({...this._def,args:dr.create(e).rest(Dr.create())})}returns(e){return new Dn({...this._def,returns:e})}implement(e){return this.parse(e)}strictImplement(e){return this.parse(e)}static create(e,t,r){return new Dn({args:e?e:dr.create([]).rest(Dr.create()),returns:t||Dr.create(),typeName:V.ZodFunction,...te(r)})}}class Jn extends se{get schema(){return this._def.getter()}_parse(e){let{ctx:t}=this._processInputParams(e);return this._def.getter()._parse({data:t.data,path:t.path,parent:t})}}Jn.create=(e,t)=>new Jn({getter:e,typeName:V.ZodLazy,...te(t)});class Wn extends se{_parse(e){if(e.data!==this._def.value){let t=this._getOrReturnCtx(e);return F(t,{received:t.data,code:S.invalid_literal,expected:this._def.value}),H}return{status:"valid",value:e.data}}get value(){return this._def.value}}Wn.create=(e,t)=>new Wn({value:e,typeName:V.ZodLiteral,...te(t)});function uu(e,t){return new Hr({values:e,typeName:V.ZodEnum,...te(t)})}class Hr extends se{_parse(e){if(typeof e.data!=="string"){let t=this._getOrReturnCtx(e),r=this._def.values;return F(t,{expected:fe.joinValues(r),received:t.parsedType,code:S.invalid_type}),H}if(!this._cache)this._cache=new Set(this._def.values);if(!this._cache.has(e.data)){let t=this._getOrReturnCtx(e),r=this._def.values;return F(t,{received:t.data,code:S.invalid_enum_value,options:r}),H}return ut(e.data)}get options(){return this._def.values}get enum(){let e={};for(let t of this._def.values)e[t]=t;return e}get Values(){let e={};for(let t of this._def.values)e[t]=t;return e}get Enum(){let e={};for(let t of this._def.values)e[t]=t;return e}extract(e,t=this._def){return Hr.create(e,{...this._def,...t})}exclude(e,t=this._def){return Hr.create(this.options.filter((r)=>!e.includes(r)),{...this._def,...t})}}Hr.create=uu;class Yn extends se{_parse(e){let t=fe.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(e);if(r.parsedType!==M.string&&r.parsedType!==M.number){let n=fe.objectValues(t);return F(r,{expected:fe.joinValues(n),received:r.parsedType,code:S.invalid_type}),H}if(!this._cache)this._cache=new Set(fe.getValidEnumValues(this._def.values));if(!this._cache.has(e.data)){let n=fe.objectValues(t);return F(r,{received:r.data,code:S.invalid_enum_value,options:n}),H}return ut(e.data)}get enum(){return this._def.values}}Yn.create=(e,t)=>new Yn({values:e,typeName:V.ZodNativeEnum,...te(t)});class hn extends se{unwrap(){return this._def.type}_parse(e){let{ctx:t}=this._processInputParams(e);if(t.parsedType!==M.promise&&t.common.async===!1)return F(t,{code:S.invalid_type,expected:M.promise,received:t.parsedType}),H;let r=t.parsedType===M.promise?t.data:Promise.resolve(t.data);return ut(r.then((n)=>this._def.type.parseAsync(n,{path:t.path,errorMap:t.common.contextualErrorMap})))}}hn.create=(e,t)=>new hn({type:e,typeName:V.ZodPromise,...te(t)});class tr extends se{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===V.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(e){let{status:t,ctx:r}=this._processInputParams(e),n=this._def.effect||null,o={addIssue:(s)=>{if(F(r,s),s.fatal)t.abort();else t.dirty()},get path(){return r.path}};if(o.addIssue=o.addIssue.bind(o),n.type==="preprocess"){let s=n.transform(r.data,o);if(r.common.async)return Promise.resolve(s).then(async(i)=>{if(t.value==="aborted")return H;let a=await this._def.schema._parseAsync({data:i,path:r.path,parent:r});if(a.status==="aborted")return H;if(a.status==="dirty")return ln(a.value);if(t.value==="dirty")return ln(a.value);return a});else{if(t.value==="aborted")return H;let i=this._def.schema._parseSync({data:s,path:r.path,parent:r});if(i.status==="aborted")return H;if(i.status==="dirty")return ln(i.value);if(t.value==="dirty")return ln(i.value);return i}}if(n.type==="refinement"){let s=(i)=>{let a=n.refinement(i,o);if(r.common.async)return Promise.resolve(a);if(a instanceof Promise)throw Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return i};if(r.common.async===!1){let i=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(i.status==="aborted")return H;if(i.status==="dirty")t.dirty();return s(i.value),{status:t.value,value:i.value}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then((i)=>{if(i.status==="aborted")return H;if(i.status==="dirty")t.dirty();return s(i.value).then(()=>({status:t.value,value:i.value}))})}if(n.type==="transform")if(r.common.async===!1){let s=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!vr(s))return H;let i=n.transform(s.value,o);if(i instanceof Promise)throw Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:t.value,value:i}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then((s)=>{if(!vr(s))return H;return Promise.resolve(n.transform(s.value,o)).then((i)=>({status:t.value,value:i}))});fe.assertNever(n)}}tr.create=(e,t,r)=>new tr({schema:e,typeName:V.ZodEffects,effect:t,...te(r)});tr.createWithPreprocess=(e,t,r)=>new tr({schema:t,effect:{type:"preprocess",transform:e},typeName:V.ZodEffects,...te(r)});class Zt extends se{_parse(e){if(this._getType(e)===M.undefined)return ut(void 0);return this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Zt.create=(e,t)=>new Zt({innerType:e,typeName:V.ZodOptional,...te(t)});class Sr extends se{_parse(e){if(this._getType(e)===M.null)return ut(null);return this._def.innerType._parse(e)}unwrap(){return this._def.innerType}}Sr.create=(e,t)=>new Sr({innerType:e,typeName:V.ZodNullable,...te(t)});class Xn extends se{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;if(t.parsedType===M.undefined)r=this._def.defaultValue();return this._def.innerType._parse({data:r,path:t.path,parent:t})}removeDefault(){return this._def.innerType}}Xn.create=(e,t)=>new Xn({innerType:e,typeName:V.ZodDefault,defaultValue:typeof t.default==="function"?t.default:()=>t.default,...te(t)});class Qn extends se{_parse(e){let{ctx:t}=this._processInputParams(e),r={...t,common:{...t.common,issues:[]}},n=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});if(Bn(n))return n.then((o)=>({status:"valid",value:o.status==="valid"?o.value:this._def.catchValue({get error(){return new xt(r.common.issues)},input:r.data})}));else return{status:"valid",value:n.status==="valid"?n.value:this._def.catchValue({get error(){return new xt(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}Qn.create=(e,t)=>new Qn({innerType:e,typeName:V.ZodCatch,catchValue:typeof t.catch==="function"?t.catch:()=>t.catch,...te(t)});class To extends se{_parse(e){if(this._getType(e)!==M.nan){let r=this._getOrReturnCtx(e);return F(r,{code:S.invalid_type,expected:M.nan,received:r.parsedType}),H}return{status:"valid",value:e.data}}}To.create=(e)=>new To({typeName:V.ZodNaN,...te(e)});var ny=Symbol("zod_brand");class Is extends se{_parse(e){let{ctx:t}=this._processInputParams(e),r=t.data;return this._def.type._parse({data:r,path:t.path,parent:t})}unwrap(){return this._def.type}}class Fo extends se{_parse(e){let{status:t,ctx:r}=this._processInputParams(e);if(r.common.async)return(async()=>{let o=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});if(o.status==="aborted")return H;if(o.status==="dirty")return t.dirty(),ln(o.value);else return this._def.out._parseAsync({data:o.value,path:r.path,parent:r})})();else{let n=this._def.in._parseSync({data:r.data,path:r.path,parent:r});if(n.status==="aborted")return H;if(n.status==="dirty")return t.dirty(),{status:"dirty",value:n.value};else return this._def.out._parseSync({data:n.value,path:r.path,parent:r})}}static create(e,t){return new Fo({in:e,out:t,typeName:V.ZodPipeline})}}class Zn extends se{_parse(e){let t=this._def.innerType._parse(e),r=(n)=>{if(vr(n))n.value=Object.freeze(n.value);return n};return Bn(t)?t.then((n)=>r(n)):r(t)}unwrap(){return this._def.innerType}}Zn.create=(e,t)=>new Zn({innerType:e,typeName:V.ZodReadonly,...te(t)});function ou(e,t){let r=typeof e==="function"?e(t):typeof e==="string"?{message:e}:e;return typeof r==="string"?{message:r}:r}function cu(e,t={},r){if(e)return yn.create().superRefine((n,o)=>{let s=e(n);if(s instanceof Promise)return s.then((i)=>{if(!i){let a=ou(t,n),u=a.fatal??r??!0;o.addIssue({code:"custom",...a,fatal:u})}});if(!s){let i=ou(t,n),a=i.fatal??r??!0;o.addIssue({code:"custom",...i,fatal:a})}return});return yn.create()}var oy={object:ve.lazycreate},V;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(V||(V={}));var sy=(e,t={message:`Input not instance of ${e.name}`})=>cu((r)=>r instanceof e,t),fu=Xt.create,du=qr.create,iy=To.create,ay=Gr.create,pu=qn.create,uy=mn.create,cy=Ao.create,fy=Gn.create,dy=Hn.create,py=yn.create,ly=Dr.create,my=fr.create,yy=So.create,gy=Qt.create,{create:hy,strictCreate:xy}=ve,by=zn.create,Iy=bs.create,_y=Vn.create,Ry=dr.create,Oy=Po.create,wy=Co.create,$y=gn.create,ky=Dn.create,Ay=Jn.create,Sy=Wn.create,Py=Hr.create,Cy=Yn.create,Ty=hn.create,Fy=tr.create,Ny=Zt.create,jy=Sr.create,My=tr.createWithPreprocess,Ey=Fo.create,Ly=()=>fu().optional(),Uy=()=>du().optional(),Ky=()=>pu().optional(),By={string:(e)=>Xt.create({...e,coerce:!0}),number:(e)=>qr.create({...e,coerce:!0}),boolean:(e)=>qn.create({...e,coerce:!0}),bigint:(e)=>Gr.create({...e,coerce:!0}),date:(e)=>mn.create({...e,coerce:!0})};var vy=H;var Dy=_s,We=(e,t=400)=>Response.json(e,{status:t,headers:{"Content-Type":"application/json"}}),hi=(e)=>{let t=$o.Compile(e),r=async(n,o)=>{try{let s=n instanceof Object&&"req"in n,i=s?await n.jsonBody():await n.json();if(!t.Check(i)){let a=t.Errors(i).First();return We({status:"error",code:"VALIDATION_FAILED",message:a?.message||"Invalid input",path:a?.path||"body"})}if(s)n.body=i;return o?o():void 0}catch(s){if(s?.status===413)return We({status:"error",code:"PAYLOAD_TOO_LARGE",message:"Payload Too Large"},413);return We({status:"error",message:"Malformed JSON payload"})}};return r.__schema=e,r},xi=(e)=>{let t=gu(e),r=async(n,o)=>{try{let s=n instanceof Object&&"req"in n,i=s?await n.jsonBody():await n.json(),a=t(i);if(!a.ok)return We({status:"error",code:a.error?.code||"TYPE_MISMATCH",message:a.error?.message||"Validation failed",...a.error?.path?{field:a.error.path}:{}});if(s)n.body=a.data;return o?o():void 0}catch(s){if(s?.status===413)return We({status:"error",code:"PAYLOAD_TOO_LARGE",message:"Payload Too Large"},413);return We({status:"error",message:"Invalid JSON payload"})}};return r.__schema=e,r},mu=(e)=>{let t=async(r,n)=>{try{let o=r instanceof Object&&"req"in r,s=o?await r.jsonBody():await r.json(),i=await e.safeParseAsync(s);if(!i.success)return We({status:"error",code:"ZOD_ERROR",errors:i.error.flatten()});if(o)r.body=i.data;return n?n():void 0}catch(o){if(o?.status===413)return We({status:"error",code:"PAYLOAD_TOO_LARGE",message:"Payload Too Large"},413);return We({status:"error",message:"Invalid JSON payload"})}};return t.__schema=e,t},qy=(e)=>{if(e&&"_def"in e)return mu(e);if(e&&(e.kind||e[Symbol.for("TypeBox.Kind")]))return hi(e);if(e&&e.type)try{return hi(e)}catch{return xi(e)}return xi(e)};var yu=(e,t)=>{if(t===void 0)return!0;if(Array.isArray(t))return t.some((r)=>yu(e,r));if(t==="array")return Array.isArray(e);if(t==="integer")return typeof e==="number"&&Number.isInteger(e);if(t==="number")return typeof e==="number"&&Number.isFinite(e);if(t==="object")return e!==null&&typeof e==="object"&&!Array.isArray(e);if(t==="null")return e===null;return typeof e===t},No=(e,t)=>{if(e===t)return!0;if(typeof e!=="object"||typeof t!=="object"||e===null||t===null)return!1;if(Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!No(e[n],t[n]))return!1;return!0}let r=Object.keys(e);if(r.length!==Object.keys(t).length)return!1;for(let n=0;n<r.length;n++){let o=r[n];if(!Object.hasOwn(t,o)||!No(e[o],t[o]))return!1}return!0},pr=(e,t,r,n)=>{if(!t||typeof t!=="object")return{ok:!0};if(Object.hasOwn(t,"const")&&!No(e,t.const))return{ok:!1,error:{message:`Value at '${r||"root"}' must equal ${JSON.stringify(t.const)}`,path:r}};if(Array.isArray(t.enum)&&!t.enum.some((o)=>No(o,e)))return{ok:!1,error:{message:`Value at '${r||"root"}' must be one of enum values`,path:r}};if(t.not&&typeof t.not==="object"&&pr(e,t.not,r,!1).ok)return{ok:!1,error:{message:`Value at '${r||"root"}' must not match the 'not' schema`,path:r}};if(Array.isArray(t.allOf))for(let o=0;o<t.allOf.length;o++){let s=pr(e,t.allOf[o],r,!1);if(!s.ok)return s}if(Array.isArray(t.anyOf)){let o=!1;for(let s=0;s<t.anyOf.length;s++)if(pr(e,t.anyOf[s],r,!1).ok){o=!0;break}if(!o)return{ok:!1,error:{message:`Value at '${r||"root"}' failed anyOf constraint`,path:r}}}if(Array.isArray(t.oneOf)){let o=0;for(let s=0;s<t.oneOf.length;s++)if(pr(e,t.oneOf[s],r,!1).ok)o++;if(o!==1)return{ok:!1,error:{message:`Value at '${r||"root"}' must match exactly one schema in oneOf`,path:r}}}if(!yu(e,t.type))return{ok:!1,error:{message:r?`Field '${r}' must be of type ${t.type}`:`Expected type ${t.type}`,path:r}};if(typeof e==="number"){if(typeof t.minimum==="number"&&e<t.minimum)return{ok:!1,error:{message:`Field '${r}' must be >= ${t.minimum}`,path:r}};if(typeof t.maximum==="number"&&e>t.maximum)return{ok:!1,error:{message:`Field '${r}' must be <= ${t.maximum}`,path:r}};if(typeof t.multipleOf==="number"&&t.multipleOf>0){let o=e/t.multipleOf;if(Math.abs(o-Math.round(o))>0.000000001*Math.max(1,Math.abs(o)))return{ok:!1,error:{message:`Field '${r}' must be a multiple of ${t.multipleOf}`,path:r}}}if(typeof t.exclusiveMinimum==="number"&&e<=t.exclusiveMinimum)return{ok:!1,error:{message:`Field '${r}' must be > ${t.exclusiveMinimum}`,path:r}};if(typeof t.exclusiveMaximum==="number"&&e>=t.exclusiveMaximum)return{ok:!1,error:{message:`Field '${r}' must be < ${t.exclusiveMaximum}`,path:r}}}if(typeof e==="string"){if(typeof t.minLength==="number"&&e.length<t.minLength)return{ok:!1,error:{message:`Field '${r}' length must be >= ${t.minLength}`,path:r}};if(typeof t.maxLength==="number"&&e.length>t.maxLength)return{ok:!1,error:{message:`Field '${r}' length must be <= ${t.maxLength}`,path:r}};if(typeof t.pattern==="string")try{if(!new RegExp(t.pattern).test(e))return{ok:!1,error:{message:`Field '${r}' does not match pattern`,path:r}}}catch{}}if(Array.isArray(e)){if(typeof t.minItems==="number"&&e.length<t.minItems)return{ok:!1,error:{message:`Field '${r}' must have at least ${t.minItems} items`,path:r}};if(typeof t.maxItems==="number"&&e.length>t.maxItems)return{ok:!1,error:{message:`Field '${r}' must have at most ${t.maxItems} items`,path:r}};if(t.uniqueItems===!0){for(let o=1;o<e.length;o++)for(let s=0;s<o;s++)if(No(e[o],e[s]))return{ok:!1,error:{message:`Field '${r}' must have unique items`,path:r}}}if(Array.isArray(t.items)){let o=Math.min(e.length,t.items.length);for(let s=0;s<o;s++){let i=pr(e[s],t.items[s],r?`${r}[${s}]`:`[${s}]`,!1);if(!i.ok)return i}}else if(t.items&&typeof t.items==="object")for(let o=0;o<e.length;o++){let s=pr(e[o],t.items,r?`${r}[${o}]`:`[${o}]`,!1);if(!s.ok)return s}}if(e!==null&&typeof e==="object"&&!Array.isArray(e)){let o=t.properties&&typeof t.properties==="object"?t.properties:null,s=Array.isArray(t.required)?t.required:null,i=s?new Set(s):null;if(typeof t.minProperties==="number"||typeof t.maxProperties==="number"){let u=Object.keys(e).length;if(typeof t.minProperties==="number"&&u<t.minProperties)return{ok:!1,error:{message:`Object at '${r||"root"}' must have at least ${t.minProperties} properties`,path:r}};if(typeof t.maxProperties==="number"&&u>t.maxProperties)return{ok:!1,error:{message:`Object at '${r||"root"}' must have at most ${t.maxProperties} properties`,path:r}}}if(s)for(let u=0;u<s.length;u++){let c=s[u];if(!Object.hasOwn(e,c)||e[c]===void 0){let f=o?.[c]?.type;return{ok:!1,error:{message:f?`Field '${c}' must be of type ${f}`:`Missing required field '${c}'`,path:r?`${r}.${c}`:c}}}}if(o){let u=Object.keys(o);for(let c=0;c<u.length;c++){let f=u[c];if(!(Object.hasOwn(e,f)&&e[f]!==void 0)){if(n&&!i)return{ok:!1,error:{message:`Field '${f}' must be of type ${o[f]?.type}`,path:r?`${r}.${f}`:f}};continue}let m=r?`${r}.${f}`:f,y=pr(e[f],o[f],m,!1);if(!y.ok)return y}}let a=new Set;if(t.patternProperties&&typeof t.patternProperties==="object"){let u=Object.keys(e);for(let[c,f]of Object.entries(t.patternProperties)){let d;try{d=new RegExp(c)}catch{continue}for(let m=0;m<u.length;m++){let y=u[m];if(!d.test(y))continue;a.add(y);let p=pr(e[y],f,r?`${r}.${y}`:y,!1);if(!p.ok)return p}}}if(t.dependentRequired&&typeof t.dependentRequired==="object")for(let[u,c]of Object.entries(t.dependentRequired)){if(!Object.hasOwn(e,u)||!Array.isArray(c))continue;for(let f of c)if(!Object.hasOwn(e,f))return{ok:!1,error:{message:`Field '${f}' is required when '${u}' is present`,path:r?`${r}.${f}`:f}}}if(t.additionalProperties===!1){let u=Object.keys(e);for(let c=0;c<u.length;c++){let f=u[c];if((!o||!Object.hasOwn(o,f))&&!a.has(f))return{ok:!1,error:{code:"ADDITIONAL_PROPERTIES",message:`Unknown field '${f}' is not allowed`,path:r?`${r}.${f}`:f}}}}else if(t.additionalProperties&&typeof t.additionalProperties==="object"){let u=Object.keys(e);for(let c=0;c<u.length;c++){let f=u[c];if((!o||!Object.hasOwn(o,f))&&!a.has(f)){let d=pr(e[f],t.additionalProperties,r?`${r}.${f}`:f,!1);if(!d.ok)return d}}}}return{ok:!0}},gu=(e)=>{let t=Boolean(e?.anyOf||e?.oneOf||e?.allOf),r=!t&&!Array.isArray(e?.required)&&Boolean(e?.properties),n=!e?.type||e.type==="object";return(o)=>{if(!e||typeof e!=="object")return!o||typeof o!=="object"||Array.isArray(o)?{ok:!1,error:{message:"Invalid JSON object payload"}}:{ok:!0,data:o};if(n&&(!o||typeof o!=="object"||Array.isArray(o))&&!t)return{ok:!1,error:{message:"Invalid JSON object payload"}};let s=pr(o,e,"",r);return s.ok?{ok:!0,data:o}:s}},eo=(e)=>{if(e&&"_def"in e)return(t)=>{let r=e.safeParse(t);return r.success?{ok:!0,data:r.data}:{ok:!1,error:r.error.flatten()}};try{let t=$o.Compile(e);return(r)=>{if(t.Check(r))return{ok:!0,data:r};let n=t.Errors(r).First();return{ok:!1,error:{message:n?.message||"Invalid input",path:n?.path}}}}catch{return gu(e)}},hu=(e,t,r,n,o)=>{if(!e)return null;let s=`ar_${n}_${o}`,i=`j_${n}_${o}`,a=`ai_${n}_${o}`;if(e.type==="array"&&e.items){let f=hu(e.items,a,`${s}[${i}] = `,n+1,o+1);if(f===null)return null;return`if (Array.isArray(${t})) {
8
+ const ${s} = new Array(${t}.length);
9
+ for (let ${i} = 0; ${i} < ${t}.length; ${i}++) {
10
+ const ${a} = ${t}[${i}];
11
+ ${f}
12
+ }
13
+ ${r}${s};
14
+ } else {
15
+ ${r}${t};
16
+ }`}let u=`ao_${n}_${o}`,c=Os(e,a,u,n+1);if(c===null)return null;return`if (Array.isArray(${t})) {
17
+ const ${s} = new Array(${t}.length);
18
+ for (let ${i} = 0; ${i} < ${t}.length; ${i}++) {
19
+ const ${a} = ${t}[${i}];
20
+ if (${a} && typeof ${a} === 'object' && !Array.isArray(${a})) {
21
+ const ${u} = {};
22
+ ${c} ${s}[${i}] = ${u};
23
+ } else {
24
+ ${s}[${i}] = ${a};
25
+ }
26
+ }
27
+ ${r}${s};
28
+ } else {
29
+ ${r}${t};
30
+ }`},Os=(e,t,r,n=0)=>{let o=e?.properties;if(!o||typeof o!=="object")return null;let s="",i=0;for(let[a,u]of Object.entries(o)){if(a==="__proto__"||a==="constructor"||a==="prototype")continue;let c=JSON.stringify(a),f=`v_${n}_${i++}`,d=`d_${n}_${i}`;if(s+=`const ${f} = Object.hasOwn(${t}, ${c}) ? ${t}[${c}] : undefined;
31
+ `,u?.type==="array"&&u?.items){let y=hu(u.items,f,`${r}[${c}] = `,n,i);if(y!==null){s+=`if (${f} !== undefined) {
32
+ ${y}
33
+ }
34
+ `;continue}}let m=Os(u,f,d,n+1);if(m!==null)s+=`if (${f} !== undefined) {
35
+ `,s+=` if (${f} && typeof ${f} === 'object' && !Array.isArray(${f})) {
36
+ `,s+=` const ${d} = {};
37
+ ${m} ${r}[${c}] = ${d};
38
+ `,s+=` } else {
39
+ ${r}[${c}] = ${f};
40
+ }
41
+ }
42
+ `;else s+=`if (${f} !== undefined) ${r}[${c}] = ${f};
43
+ `}return s},bi=(e)=>{if(!e||typeof e!=="object")return!1;if(Array.isArray(e.anyOf)||Array.isArray(e.oneOf)||Array.isArray(e.allOf))return!0;if(e.additionalProperties&&typeof e.additionalProperties==="object")return!0;if(e.patternProperties&&typeof e.patternProperties==="object")return!0;if(Array.isArray(e.items))return!0;if(e.type==="array"&&e.items)return bi(e.items);if(e.properties&&typeof e.properties==="object"){for(let t of Object.values(e.properties))if(bi(t))return!0}return!1},xu=(e,t)=>{let r=!1;if(e?.properties&&typeof e.properties==="object")Object.assign(t,e.properties),r=!0;if(Array.isArray(e?.allOf)){for(let n of e.allOf)if(xu(n,t))r=!0}return r},Mt=(e,t)=>{if(!t||typeof t!=="object"||e===null||typeof e!=="object")return e;if(Array.isArray(e)){if(Array.isArray(t.items))return e.map((i,a)=>t.items[a]?Mt(i,t.items[a]):i);if(t.items&&typeof t.items==="object")return e.map((i)=>Mt(i,t.items));return e}let r=t.anyOf||t.oneOf;if(Array.isArray(r)&&r.length>0){let i=null;for(let a of r)if(a&&typeof a==="object"&&eo(a)(e).ok){i=a;break}if(i){if(t.properties&&typeof t.properties==="object"){let a={...t.properties,...i.properties||{}},u={};for(let[c,f]of Object.entries(a)){if(c==="__proto__"||c==="constructor"||c==="prototype")continue;if(Object.hasOwn(e,c)&&e[c]!==void 0)u[c]=Mt(e[c],f)}return u}return Mt(e,i)}if(!t.properties)return e}if(Array.isArray(t.allOf)){let i={};if(xu(t,i)){let a={};for(let[u,c]of Object.entries(i)){if(u==="__proto__"||u==="constructor"||u==="prototype")continue;if(Object.hasOwn(e,u)&&e[u]!==void 0)a[u]=Mt(e[u],c)}return a}}let n=Boolean(t.properties&&typeof t.properties==="object"),o=Boolean(t.patternProperties&&typeof t.patternProperties==="object"),s=Boolean(t.additionalProperties&&typeof t.additionalProperties==="object");if(n||o||s){let i={},a=n?t.properties:null;if(a)for(let[u,c]of Object.entries(a)){if(u==="__proto__"||u==="constructor"||u==="prototype")continue;if(Object.hasOwn(e,u)&&e[u]!==void 0)i[u]=Mt(e[u],c)}if(o||s){let u=o?Object.entries(t.patternProperties).map(([c,f])=>({re:new RegExp(c),sub:f})):[];for(let c of Object.keys(e)){if(c==="__proto__"||c==="constructor"||c==="prototype")continue;if(e[c]===void 0||a&&Object.hasOwn(a,c))continue;let f=!1;for(let d=0;d<u.length;d++)if(u[d].re.test(c)){i[c]=Mt(e[c],u[d].sub),f=!0;break}if(!f&&s)i[c]=Mt(e[c],t.additionalProperties)}}return i}return e},Rs=(e)=>{if(!e||"_def"in e)return null;if(bi(e))return(r)=>Mt(r,e);if(e.type==="array"&&e.items){if(e.items.type==="array")return(n)=>Mt(n,e);let r=Os(e.items,"item","outItem");if(r===null)return(n)=>Mt(n,e);return Function(`return function(arr) {
8
44
  if (!Array.isArray(arr)) return arr;
9
45
  const len = arr.length;
10
46
  const out = new Array(len);
11
47
  for (let i = 0; i < len; i++) {
12
48
  const item = arr[i];
13
- out[i] = (item && typeof item === 'object' && !Array.isArray(item)) ? ${r} : item;
49
+ if (item && typeof item === 'object' && !Array.isArray(item)) {
50
+ const outItem = {};
51
+ ${r}
52
+ out[i] = outItem;
53
+ } else {
54
+ out[i] = item;
55
+ }
14
56
  }
15
57
  return out;
16
- }`)()}let t=ai(e,"o");if(!t)return null;return Function(`return function(o) {
58
+ }`)()}let t=Os(e,"o","out");if(t===null)return(r)=>Mt(r,e);return Function(`return function(o) {
17
59
  if (!o || typeof o !== 'object' || Array.isArray(o)) return o;
18
- return ${t};
19
- }`)()},cc=(e)=>{let t=_o(e),r=ac(e);return(n)=>{if(n instanceof Response)return n;let o=r?r(n):n,s=t(o);if(!s.ok)return ot({status:"error",code:"RESPONSE_VALIDATION_FAILED",error:s.error},500);return s.data}},nc=(e,t)=>{let r=t?.properties||(t?._def?.shape?typeof t._def.shape==="function"?t._def.shape():t._def.shape:null);if(!r)return e;let n={...e};for(let[o,s]of Object.entries(r)){if(!Object.hasOwn(n,o))continue;let i=n[o];if(typeof i!=="string")continue;let a=s?.type||s?._def?.typeName;if(a==="number"||a==="integer"||a==="ZodNumber"){if(i.trim()!==""){let u=Number(i);if(!Number.isNaN(u))n[o]=u}}else if(a==="boolean"||a==="ZodBoolean"){if(i==="true")n[o]=!0;else if(i==="false")n[o]=!1}}return n},ci=(e)=>{let t=e.body?_o(e.body):null,r=e.query?_o(e.query):null,n=e.params?_o(e.params):null,o=e.headers?_o(e.headers):null,s=e.stripUnknown&&e.body?ac(e.body):null,i=e.response?cc(e.response):null,a=e.maxBodySize??1048576,u=Boolean(n||r||o),c=(f)=>{if(n){let l=nc(f.params,e.params),y=n(l);if(!y.ok)return ot({status:"error",code:"PARAMS_INVALID",error:y.error});f.params=y.data}if(r){let l=nc(f.query,e.query),y=r(l);if(!y.ok)return ot({status:"error",code:"QUERY_INVALID",error:y.error});f._query=y.data}if(o){let l={};f.req.headers.forEach((b,O)=>{l[O.toLowerCase()]=b});let y=o(l);if(!y.ok)return ot({status:"error",code:"HEADERS_INVALID",error:y.error})}return};if(!t){let f=(l,y)=>{if(u){let b=c(l);if(b)return b}return y?y():void 0};if(f.__routeSchemas=e,i)f.__responseFilter=i;return f}let d=async(f,l)=>{if(u){let O=c(f);if(O)return O}let y;try{y=await f.jsonBody(a)}catch(O){if(O?.status===413)return ot({status:"error",code:"PAYLOAD_TOO_LARGE",message:"Payload Too Large"},413);return ot({status:"error",message:"Malformed JSON payload"})}let b=t(y);if(!b.ok)return ot({status:"error",code:"VALIDATION_FAILED",error:b.error});return f.body=s?s(b.data):b.data,l?l():void 0};if(d.__schema=e.body,d.__routeSchemas=e,i)d.__responseFilter=i;return d};class an{prefix;groupMiddleware;routes=[];constructor(e="",t=[]){this.prefix=e;this.groupMiddleware=t}_add(e,t,r){let n=(this.prefix+"/"+t).replace(/\/+/g,"/");if(n.endsWith("/"))n=n.slice(0,-1);let o=[];for(let s=0;s<r.length;s++){let i=r[s];if(typeof i==="function")o.push(i);else if(i&&typeof i==="object")o.push(ci(i))}return this.routes.push({method:e.toUpperCase(),path:n||"",handlers:[...this.groupMiddleware,...o]}),this}get=(e,...t)=>this._add("GET",e,t);post=(e,...t)=>this._add("POST",e,t);put=(e,...t)=>this._add("PUT",e,t);patch=(e,...t)=>this._add("PATCH",e,t);delete=(e,...t)=>this._add("DELETE",e,t);options=(e,...t)=>this._add("OPTIONS",e,t);head=(e,...t)=>this._add("HEAD",e,t);all=(e,...t)=>{for(let r of["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"])this._add(r,e,t);return this};group=(e,...t)=>{let r=t.pop(),n=t,o=(this.prefix+"/"+e).replace(/\/+/g,"/"),s=new an(o,[...this.groupMiddleware,...n]);return r(s),this.routes.push(...s.routes),this};_mountRouter(e,t){let r=(this.prefix+"/"+e).replace(/\/+/g,"/").replace(/\/$/,"");for(let n of t.routes){let o=(r+"/"+n.path).replace(/\/+/g,"/");if(o.endsWith("/"))o=o.slice(0,-1);this.routes.push({method:n.method,path:o||"",handlers:[...this.groupMiddleware,...n.handlers]})}}route(e,t){return this._mountRouter(e,t),this}use(e,t){if(typeof e==="string"&&(t instanceof an||t&&t.routes))this._mountRouter(e,t);else if(e instanceof an||e&&e.routes)this._mountRouter("",e);else if(e&&typeof e.install==="function")e.install(this);else this.groupMiddleware.push(e);return this}}class cn{children={};staticKeys=[];paramNode=null;paramName=null;wildcardNode=null;handlers={};insert(e,t,r){let n=this,o=e.split("/").filter(Boolean);for(let s of o)if(s==="*"){if(!n.wildcardNode)n.wildcardNode=new cn;n=n.wildcardNode;break}else if(s.startsWith(":")){if(!n.paramNode)n.paramNode=new cn;n.paramName=s.slice(1),n=n.paramNode}else{if(!n.children[s])n.children[s]=new cn,n.staticKeys.push(s);n=n.children[s]}n.handlers[t]=r}lookup(e,t,r,n){let o=this,s=r===-1?0:r,i=t.length;if(t[s]==="/")s++;for(let a in n.params)delete n.params[a];while(s<i){let a=t.indexOf("/",s);if(a===-1)a=i;let u=a-s,c=!1,d=o.staticKeys,f=d.length;if(f===1){let l=d[0];if(l.length===u){let y=!0;for(let b=0;b<u;b++)if(l[b]!==t[s+b]){y=!1;break}if(y)o=o.children[l],c=!0}}else for(let l=0;l<f;l++){let y=d[l];if(y.length===u){let b=!0;for(let O=0;O<u;O++)if(y[O]!==t[s+O]){b=!1;break}if(b){o=o.children[y],c=!0;break}}}if(!c)if(o.paramNode)n.params[o.paramName]=t.slice(s,a),o=o.paramNode;else if(o.wildcardNode)return n.params["*"]=t.slice(s),o.wildcardNode.handlers[e]||null;else return null;s=a+1}return o.handlers[e]||null}jitCompile(e,t=0,r="url",n="s",o=[]){let s="",i=" ".repeat(t);if(Object.keys(this.handlers).length>0){if(s+=`${i}if (${n} >= urlLen) {
20
- `,o.length>0){let a=o.map((u)=>`${JSON.stringify(u.name)}: ${u.varName}`).join(", ");s+=`${i} ctx.params = { ${a} };
21
- `}s+=`${i} switch(method) {
22
- `;for(let[a,u]of Object.entries(this.handlers)){let c=e(u);s+=`${i} case ${JSON.stringify(a)}: return ${c}(ctx);
23
- `}s+=`${i} }
24
- `,s+=`${i}}
25
- `}if(this.staticKeys.length>0)if(this.staticKeys.length===1){let a=this.staticKeys[0],u=a.length,c=`nextIdxL${t}`;s+=`${i}if (${r}.startsWith(${JSON.stringify(a)}, ${n})) {
26
- `,s+=`${i} const ${c} = ${n} + ${u};
27
- `,s+=`${i} if (${c} === urlLen || ${r}.charCodeAt(${c}) === 47) {
28
- `;let d=this.children[a],f=`newIdxL${t}`;s+=`${i} const ${f} = ${c} === urlLen ? urlLen : (${c} + 1);
29
- `,s+=d.jitCompile(e,t+1,r,f,o),s+=`${i} }
30
- `,s+=`${i}}
31
- `}else if(this.staticKeys.length>4){s+=`${i}let slash${t} = ${r}.indexOf('/', ${n});
32
- `,s+=`${i}if (slash${t} === -1 || slash${t} > urlLen) slash${t} = urlLen;
33
- `,s+=`${i}switch (${r}.slice(${n}, slash${t})) {
34
- `;for(let a of this.staticKeys){s+=`${i} case ${JSON.stringify(a)}: {
35
- `;let u=this.children[a];s+=u.jitCompile(e,t+1,r,`slash${t} + 1`,o),s+=`${i} break;
36
- `,s+=`${i} }
37
- `}s+=`${i}}
38
- `}else{s+=`${i}let slash${t} = ${r}.indexOf('/', ${n});
39
- `,s+=`${i}if (slash${t} === -1 || slash${t} > urlLen) slash${t} = urlLen;
40
- `,s+=`${i}const len${t} = slash${t} - (${n});
41
-
42
- `;let a=new Map;for(let u of this.staticKeys){let c=a.get(u.length);if(!c)c=[],a.set(u.length,c);c.push(u)}s+=`${i}switch(len${t}) {
43
- `;for(let[u,c]of a){s+=`${i} case ${u}:
44
- `;for(let d of c){if(u===1)s+=`${i} if (${r}.charCodeAt(${n}) === ${d.charCodeAt(0)}) {
45
- `;else s+=`${i} if (${r}.startsWith(${JSON.stringify(d)}, ${n})) {
46
- `;let f=this.children[d];s+=f.jitCompile(e,t+1,r,`slash${t} + 1`,o),s+=`${i} }
47
- `}s+=`${i} break;
48
- `}s+=`${i}}
49
- `}if(this.paramNode){let a=this.paramNode;if(this.staticKeys.length<=1)s+=`${i}let slash${t} = ${r}.indexOf('/', ${n});
50
- `,s+=`${i}if (slash${t} === -1 || slash${t} > urlLen) slash${t} = urlLen;
51
- `;let u=`pL${t}`;s+=`${i}if (slash${t} > ${n}) {
52
- `,s+=`${i} const ${u} = ${r}.slice(${n}, slash${t});
53
- `;let c=[...o,{name:this.paramName,varName:u}];s+=a.jitCompile(e,t+1,r,`slash${t} + 1`,c),s+=`${i}}
54
- `}if(this.wildcardNode&&Object.keys(this.wildcardNode.handlers).length>0){let a=`wL${t}`;s+=`${i}const ${a} = ${r}.slice(${n}, urlLen);
55
- `;let c=[...o,{name:"*",varName:a}].map((d)=>`${JSON.stringify(d.name)}: ${d.varName}`).join(", ");s+=`${i}ctx.params = { ${c} };
56
- `,s+=`${i}switch(method) {
57
- `;for(let[d,f]of Object.entries(this.wildcardNode.handlers)){let l=e(f);s+=`${i} case ${JSON.stringify(d)}: return ${l}(ctx);
58
- `}s+=`${i}}
59
- `}return s}id=Math.random().toString(36).slice(2)}import{createHmac as uc,timingSafeEqual as Uy}from"crypto";class Oo{req;params={};_status=200;_headers=void 0;store=new Map;body=void 0;_query=void 0;_cookies=void 0;_setCookies=void 0;_requestId=void 0;_peerIp=void 0;_trustProxy=!0;constructor(e=!0){this._trustProxy=e}get query(){if(this._query!==void 0)return this._query;let e={},t=this.req?.url;if(t){let r=t.indexOf("?");if(r!==-1){let n=r+1,o=t.length,s=t.indexOf("+",n)!==-1,i=t.indexOf("%",n)!==-1;while(n<o){let a=t.indexOf("&",n);if(a===-1)a=o;if(a>n){let u=t.indexOf("=",n),c,d;if(u!==-1&&u<a)c=t.slice(n,u),d=t.slice(u+1,a);else c=t.slice(n,a),d="";if(s){if(c.indexOf("+")!==-1)c=c.replaceAll("+"," ");if(d.indexOf("+")!==-1)d=d.replaceAll("+"," ")}if(i){if(c.indexOf("%")!==-1)try{c=decodeURIComponent(c)}catch{}if(d.indexOf("%")!==-1)try{d=decodeURIComponent(d)}catch{}}if(c!=="__proto__"&&c!=="constructor"&&c!=="prototype")e[c]=d}n=a+1}}}return this._query=e,e}getQuery(e){let t=this.query;return Object.hasOwn(t,e)?t[e]:void 0}get cookies(){if(this._cookies!==void 0)return this._cookies;let e={},t=this.req?.headers?.get("cookie");if(t){let r=0,n=t.length;while(r<n){let o=t.indexOf(";",r);if(o===-1)o=n;let s=t.indexOf("=",r);if(s!==-1&&s<o){let i=t.slice(r,s).trim(),a=t.slice(s+1,o).trim();try{a=decodeURIComponent(a)}catch{}if(i&&i!=="__proto__"&&i!=="constructor"&&i!=="prototype")e[i]=a}r=o+1}}return this._cookies=e,e}setCookie(e,t,r={}){if(!e||/[\r\n;= \t]/.test(e))throw Error("Invalid cookie name");let n=r.path??"/";if(/[\r\n;]/.test(n))throw Error("Invalid cookie path");if(r.domain&&/[\r\n;]/.test(r.domain))throw Error("Invalid cookie domain");let o=t;if(r.secret){let i=uc("sha256",r.secret).update(t).digest("base64url");o=`${t}.${i}`}let s=`${e}=${encodeURIComponent(o)}`;if(s+=`; Path=${n}`,r.domain)s+=`; Domain=${r.domain}`;if(r.maxAge!==void 0)s+=`; Max-Age=${Math.floor(r.maxAge)}`;if(r.expires)s+=`; Expires=${r.expires.toUTCString()}`;if(r.httpOnly!==!1)s+="; HttpOnly";if(r.secure)s+="; Secure";if(s+=`; SameSite=${r.sameSite??"Lax"}`,!this._setCookies)this._setCookies=[];return this._setCookies.push(s),this}getSignedCookie(e,t){let r=this.cookies[e];if(!r)return null;let n=r.lastIndexOf(".");if(n<=0)return null;let o=r.slice(0,n),s=r.slice(n+1),i=uc("sha256",t).update(o).digest(),a=Buffer.from(s,"base64url");if(a.length!==i.length||!Uy(a,i))return null;return o}deleteCookie(e,t={}){return this.setCookie(e,"",{...t,maxAge:0,expires:new Date(0)})}async jsonBody(e=1048576){if(this.body!==void 0)return this.body;let t=this.req.headers.get("content-type");if(t&&t.includes("application/json")){let r=this.req.headers.get("content-length");if(r!==null){let n=r.trim(),o=n.length>0?Number(n):NaN;if(Number.isInteger(o)&&o>=0){if(o>e){let s=Error("Payload Too Large");throw s.status=413,s}try{return this.body=await this.req.json()}catch{return this.body=null}}}try{let n=await this.req.text();if(Buffer.byteLength(n,"utf-8")>e){let o=Error("Payload Too Large");throw o.status=413,o}return this.body=JSON.parse(n)}catch(n){if(n?.status===413)throw n;return this.body=null}}return this.body=null}reset(e){if(this.req=e,this._status=200,this._headers=void 0,this.store.size>0)this.store.clear();return this.params={},this._query=void 0,this._cookies=void 0,this._setCookies=void 0,this.body=void 0,this._peerIp=void 0,this}status(e){return this._status=e,this}_applyCookies(e){if(this._setCookies){for(let t=0;t<this._setCookies.length;t++)e.headers.append("Set-Cookie",this._setCookies[t]);this._setCookies=void 0}return e}json(e){let t=this._status||200,r;if(!this._headers)r=t===200?Response.json(e):Response.json(e,{status:t});else{let n=this._headers;if(n["content-type"]===void 0){if(Object.isFrozen(n))n={...n},this._headers=n;n["content-type"]="application/json"}r=Response.json(e,{status:t,headers:n})}return this._applyCookies(r)}set(e,t){return this.store.set(e,t),this}get(e){return this.store.get(e)}setHeader(e,t){if(!this._headers)this._headers={};else if(Object.isFrozen(this._headers))this._headers={...this._headers};return this._headers[e.toLowerCase()]=t,this}get user(){return this.store.get("user")}send(e,t={}){let r=this._status>=400;return this.json({status:r?"error":"success",msg:e,...t})}html(e,t){let r={"content-type":"text/html; charset=utf-8",...this._headers||{}};return this._applyCookies(new Response(e,{status:t??this._status,headers:r}))}text(e,t){let r={"content-type":"text/plain; charset=utf-8",...this._headers||{}};return this._applyCookies(new Response(e,{status:t??this._status,headers:r}))}redirect(e,t=302){let r={location:e,...this._headers||{}};return this._applyCookies(new Response(null,{status:t,headers:r}))}sse(e){let t=new TextEncoder,r=(s)=>{if(typeof s==="string")return t.encode(`data: ${s}
60
+ const out = {};
61
+ ${t}
62
+ return out;
63
+ }`)()},bu=(e)=>{let t=eo(e),r=Rs(e);return(n)=>{if(n instanceof Response)return n;let o=r?r(n):n,s=t(o);if(!s.ok)return We({status:"error",code:"RESPONSE_VALIDATION_FAILED",error:s.error},500);return s.data}},Gy=(e)=>{let t=e;while(t?._def){let r=t._def.typeName;if(r==="ZodOptional"||r==="ZodDefault"||r==="ZodNullable")t=t._def.innerType;else if(r==="ZodEffects")t=t._def.schema;else break}return t?.type||t?._def?.typeName},Hy=/^\s*[-+]?(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?\s*$/,lu=(e,t)=>{let r=t;while(r?._def?.typeName==="ZodEffects")r=r._def.schema;let n=r?.properties||(r?._def?.shape?typeof r._def.shape==="function"?r._def.shape():r._def.shape:null);if(!n)return e;let o={...e};for(let[s,i]of Object.entries(n)){if(!Object.hasOwn(o,s))continue;let a=o[s];if(typeof a!=="string")continue;let u=Gy(i);if(u==="number"||u==="integer"||u==="ZodNumber"){if(/^\s*[-+]?(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?\s*$/.test(a)){let c=Number(a);if(Number.isFinite(c))o[s]=c}}else if(u==="boolean"||u==="ZodBoolean"){if(a==="true")o[s]=!0;else if(a==="false")o[s]=!1}}return o},Ii=(e)=>{let t=e.body?eo(e.body):null,r=e.query?eo(e.query):null,n=e.params?eo(e.params):null,o=e.headers?eo(e.headers):null,s=e.stripUnknown&&e.body?Rs(e.body):null,i=e.stripUnknown&&e.query?Rs(e.query):null,a=e.stripUnknown&&e.params?Rs(e.params):null,u=e.response?bu(e.response):null,c=e.maxBodySize??1048576,f=[],d=new Set;{let R=e.query;while(R?._def?.schema)R=R._def.schema;let w=R?.properties||(R?._def?.shape?typeof R._def.shape==="function"?R._def.shape():R._def.shape:null),P=(C)=>{let J=C;while(J?._def){let z=J._def.typeName;if(z==="ZodOptional"||z==="ZodDefault"||z==="ZodNullable")J=J._def.innerType;else if(z==="ZodEffects")J=J._def.schema;else break}return J};if(w)for(let[C,J]of Object.entries(w)){let z=P(J);if(!(z?.type==="array"||z?._def?.typeName==="ZodArray"))continue;f.push(C);let T=P(z.items??z._def?.type),B=T?.type??T?._def?.typeName;if(B==="number"||B==="integer"||B==="ZodNumber")d.add(C)}}let m=Boolean(n||r||o),y=(R)=>{if(n){let w=lu(R.params,e.params),P=n(w);if(!P.ok)return We({status:"error",code:"PARAMS_INVALID",error:P.error});R.params=a?a(P.data):P.data}if(r){let w=lu(R.query,e.query);for(let C of f){let J=R.queryAll(C);if(J.length>0)w[C]=J.map((z)=>d.has(C)&&Hy.test(z)?Number(z):z)}let P=r(w);if(!P.ok)return We({status:"error",code:"QUERY_INVALID",error:P.error});R._query=i?i(P.data):P.data}if(o){let w={};R.req.headers.forEach((C,J)=>{let z=J.toLowerCase();if(z!=="__proto__"&&z!=="constructor"&&z!=="prototype")w[z]=C});let P=o(w);if(!P.ok)return We({status:"error",code:"HEADERS_INVALID",error:P.error})}return};if(!t){let R=(w,P)=>{if(m){let C=y(w);if(C)return C}return P?P():void 0};if(R.__routeSchemas=e,u)R.__responseFilter=u;return R}let p=Boolean(e.body&&"_def"in e.body),h=(R,w,P)=>{let C;try{C=t(w)}catch{if(p)return e.body.safeParseAsync(w).then((J)=>{if(!J.success)return We({status:"error",code:"VALIDATION_FAILED",error:J.error.flatten()});return R.body=s?s(J.data):J.data,P?P():void 0});C={ok:!1,error:{message:"Validation failed"}}}if(!C.ok)return We({status:"error",code:"VALIDATION_FAILED",error:C.error});return R.body=s?s(C.data):C.data,P?P():void 0},x=(R,w)=>{if(m){let C=y(R);if(C)return C}let P;try{P=R.jsonBodySyncOrAsync(c)}catch(C){if(C?.status===413)return We({status:"error",code:"PAYLOAD_TOO_LARGE",message:"Payload Too Large"},413);return We({status:"error",message:"Malformed JSON payload"})}if(P&&typeof P.then==="function")return P.then((C)=>h(R,C,w),(C)=>{if(C?.status===413)return We({status:"error",code:"PAYLOAD_TOO_LARGE",message:"Payload Too Large"},413);return We({status:"error",message:"Malformed JSON payload"})});return h(R,P,w)};if(x.__schema=e.body,x.__routeSchemas=e,u)x.__responseFilter=u;return x};class xn{prefix;groupMiddleware;routes=[];constructor(e="",t=[]){this.prefix=e;this.groupMiddleware=t}_add(e,t,r){let n=(this.prefix+"/"+t).replace(/\/+/g,"/");if(n.endsWith("/"))n=n.slice(0,-1);let o=[];for(let s=0;s<r.length;s++){let i=r[s];if(typeof i==="function")o.push(i);else if(i&&typeof i==="object")o.push(Ii(i))}return this.routes.push({method:e.toUpperCase(),path:n||"",handlers:[...this.groupMiddleware,...o]}),this}get=(e,...t)=>this._add("GET",e,t);post=(e,...t)=>this._add("POST",e,t);put=(e,...t)=>this._add("PUT",e,t);patch=(e,...t)=>this._add("PATCH",e,t);delete=(e,...t)=>this._add("DELETE",e,t);options=(e,...t)=>this._add("OPTIONS",e,t);head=(e,...t)=>this._add("HEAD",e,t);all=(e,...t)=>{for(let r of["GET","POST","PUT","PATCH","DELETE","OPTIONS","HEAD"])this._add(r,e,t);return this};group=(e,...t)=>{let r=t.pop(),n=t,o=(this.prefix+"/"+e).replace(/\/+/g,"/"),s=new xn(o,[...this.groupMiddleware,...n]);return r(s),this.routes.push(...s.routes),this};_mountRouter(e,t){let r=(this.prefix+"/"+e).replace(/\/+/g,"/").replace(/\/$/,"");for(let n of t.routes){let o=(r+"/"+n.path).replace(/\/+/g,"/");if(o.endsWith("/"))o=o.slice(0,-1);this.routes.push({method:n.method,path:o||"",handlers:[...this.groupMiddleware,...n.handlers]})}}route(e,t){return this._mountRouter(e,t),this}use(e,...t){if(typeof e==="string"){let n=[],o=[];for(let s=0;s<t.length;s++){let i=t[s];if(i instanceof xn||i&&i.routes)o.push(i);else if(typeof i==="function")n.push(i)}if(o.length===0)throw TypeError(`BareRouter.use("${e}", ...) requires a BareRouter instance`);for(let s=0;s<o.length;s++){let i=this.routes.length;if(this._mountRouter(e,o[s]),n.length>0)for(let a=i;a<this.routes.length;a++)this.routes[a].handlers=[...this.groupMiddleware,...n,...this.routes[a].handlers.slice(this.groupMiddleware.length)]}return this}let r=[e,...t];for(let n=0;n<r.length;n++){let o=r[n];if(o instanceof xn||o&&o.routes)this._mountRouter("",o);else if(o&&typeof o.install==="function")o.install(this);else if(typeof o==="function")this.groupMiddleware.push(o)}return this}}class bn{children=Object.create(null);staticKeys=[];paramNode=null;paramName=null;wildcardNode=null;handlers=Object.create(null);handlerParams=Object.create(null);insert(e,t,r){let n=this,o=e.split("/").filter(Boolean),s=[];for(let i of o)if(i==="*"){if(!n.wildcardNode)n.wildcardNode=new bn;n=n.wildcardNode;break}else if(i.startsWith(":")){if(!n.paramNode)n.paramNode=new bn;let a=i.slice(1);if(!n.paramName)n.paramName=a;s.push(a),n=n.paramNode}else{if(!n.children[i])n.children[i]=new bn,n.staticKeys.push(i);n=n.children[i]}n.handlers[t]=r,n.handlerParams[t]=s}lookup(e,t,r,n){let o=r===-1?0:r,s=t.indexOf("?",o),i=s===-1?t.length:s;if(t[o]==="/")o++;let a=(c,f,d)=>{let y=c.includes("__proto__")?Object.create(null):{};for(let p=0;p<c.length;p++)y[c[p]]=f[p];if(d!==void 0)y["*"]=d;n.params=y},u=(c,f,d)=>{if(f>=i){let R=c.handlers[e];if(R)return a(c.handlerParams[e]||[],d),R;if(c.wildcardNode&&c.wildcardNode.handlers[e])return a(c.wildcardNode.handlerParams[e]||[],d,""),c.wildcardNode.handlers[e];return null}let m=t.indexOf("/",f);if(m===-1||m>i)m=i;let y=m-f,p=c.staticKeys,h=p.length,x=null;if(h===1){let R=p[0];if(R.length===y){let w=!0;for(let P=0;P<y;P++)if(R[P]!==t[f+P]){w=!1;break}if(w)x=c.children[R]}}else for(let R=0;R<h;R++){let w=p[R];if(w.length===y){let P=!0;for(let C=0;C<y;C++)if(w[C]!==t[f+C]){P=!1;break}if(P){x=c.children[w];break}}}if(x){let R=u(x,m+1,d);if(R)return R}if(c.paramNode&&y>0){d.push(t.slice(f,m));let R=u(c.paramNode,m+1,d);if(R)return R;d.pop()}if(c.wildcardNode&&c.wildcardNode.handlers[e])return a(c.wildcardNode.handlerParams[e]||[],d,t.slice(f,i)),c.wildcardNode.handlers[e];return null};return n.params={},u(this,o,[])}emitParamsAssign(e,t,r){if(t.length===0)return"";if(t.includes("__proto__")){let o=`${e}{ const _p = Object.create(null);
64
+ `;for(let s=0;s<t.length;s++)o+=`${e}_p[${JSON.stringify(t[s])}] = ${r[s]};
65
+ `;return o+`${e}ctx.params = _p; }
66
+ `}let n=t.map((o,s)=>`${JSON.stringify(o)}: ${r[s]}`).join(", ");return`${e}ctx.params = { ${n} };
67
+ `}jitCompile(e,t=0,r="url",n="s",o=[],s=(i)=>`return ${i}(ctx);`){let i="",a=" ".repeat(t);if(Object.keys(this.handlers).length>0){i+=`${a}if (${n} >= urlLen) {
68
+ `,i+=`${a} switch(method) {
69
+ `;for(let[c,f]of Object.entries(this.handlers)){let d=e(f),m=this.handlerParams[c]||[],y=m.length>0?this.emitParamsAssign("",m,o).trim()+" ":"";i+=`${a} case ${JSON.stringify(c)}: ${y}${s(d)}
70
+ `}i+=`${a} }
71
+ `,i+=`${a}}
72
+ `}if(this.staticKeys.length>0||this.paramNode!==null){let c=a+" ";if(i+=`${a}if (${n} < urlLen) {
73
+ `,this.staticKeys.length>0)if(this.staticKeys.length===1){let f=this.staticKeys[0],d=this.children[f],m=f.length,y=`${n} + ${m} === urlLen || ${r}.charCodeAt(${n} + ${m}) === 47`;if(m===1)i+=`${c}if (${r}.charCodeAt(${n}) === ${f.charCodeAt(0)} && (${y})) {
74
+ `;else i+=`${c}if (${r}.startsWith(${JSON.stringify(f)}, ${n}) && (${y})) {
75
+ `;i+=d.jitCompile(e,t+1,r,`${n} + ${m+1}`,o,s),i+=`${c}}
76
+ `}else{i+=`${c}let slash${t} = ${r}.indexOf('/', ${n});
77
+ `,i+=`${c}if (slash${t} === -1 || slash${t} > urlLen) slash${t} = urlLen;
78
+ `,i+=`${c}const len${t} = slash${t} - (${n});
79
+ `;let f=new Map;for(let d of this.staticKeys){let m=f.get(d.length);if(!m)m=[],f.set(d.length,m);m.push(d)}if(this.staticKeys.length>8){let d=new Map;for(let m of this.staticKeys){let y=this.children[m],p=0,h=y.jitCompile(()=>`__H${p++}__`,t+1,r,`slash${t} + 1`,o,s),x=d.get(h);if(!x)x=[],d.set(h,x);x.push(m)}i+=`${c}const seg${t} = ${r}.slice(${n}, slash${t});
80
+ `,i+=`${c}switch(seg${t}) {
81
+ `;for(let[m,y]of d)if(y.length===1){let p=y[0],h=this.children[p];i+=`${c} case ${JSON.stringify(p)}:
82
+ `,i+=h.jitCompile(e,t+1,r,`slash${t} + 1`,o,s),i+=`${c} break;
83
+ `}else{let p=[];for(let w of y){let P=this.children[w],C=[];P.jitCompile((J)=>{let z=e(J);return C.push(z),z},t+1,r,`slash${t} + 1`,o,s),p.push(C)}let h=p[0].length,x=Array.from({length:h},(w,P)=>`_rh${t}_${P}`);for(let w=0;w<y.length;w++)i+=`${c} case ${JSON.stringify(y[w])}:
84
+ `;if(i+=`${c} {
85
+ `,h>0){i+=`${c} let ${x.join(", ")};
86
+ `,i+=`${c} switch(seg${t}) {
87
+ `;for(let w=0;w<y.length;w++){let P=x.map((C,J)=>`${C} = ${p[w][J]}`).join("; ");i+=`${c} case ${JSON.stringify(y[w])}: ${P}; break;
88
+ `}i+=`${c} }
89
+ `}let R=m;for(let w=0;w<h;w++)R=R.replaceAll(`__H${w}__`,x[w]);i+=R,i+=`${c} break;
90
+ `,i+=`${c} }
91
+ `}i+=`${c}}
92
+ `}else{i+=`${c}switch(len${t}) {
93
+ `;for(let[d,m]of f){i+=`${c} case ${d}:
94
+ `;for(let y of m){if(d===1)i+=`${c} if (${r}.charCodeAt(${n}) === ${y.charCodeAt(0)}) {
95
+ `;else i+=`${c} if (${r}.startsWith(${JSON.stringify(y)}, ${n})) {
96
+ `;let p=this.children[y];i+=p.jitCompile(e,t+1,r,`slash${t} + 1`,o,s),i+=`${c} }
97
+ `}i+=`${c} break;
98
+ `}i+=`${c}}
99
+ `}}if(this.paramNode){let f=this.paramNode;if(this.staticKeys.length<=1)i+=`${c}let slash${t} = ${r}.indexOf('/', ${n});
100
+ `,i+=`${c}if (slash${t} === -1 || slash${t} > urlLen) slash${t} = urlLen;
101
+ `;let d=`pL${t}`;i+=`${c}if (slash${t} > ${n}) {
102
+ `,i+=`${c} const ${d} = ${r}.slice(${n}, slash${t});
103
+ `;let m=[...o,d];i+=f.jitCompile(e,t+1,r,`slash${t} + 1`,m,s),i+=`${c}}
104
+ `}i+=`${a}}
105
+ `}if(this.wildcardNode&&Object.keys(this.wildcardNode.handlers).length>0){let c=`wL${t}`;i+=`${a}const ${c} = ${r}.slice(${n}, urlLen);
106
+ `,i+=`${a}switch(method) {
107
+ `;for(let[f,d]of Object.entries(this.wildcardNode.handlers)){let m=e(d),y=[...this.wildcardNode.handlerParams[f]||[],"*"],p=[...o,c],h=this.emitParamsAssign("",y,p).trim();i+=`${a} case ${JSON.stringify(f)}: ${h} ${s(m)}
108
+ `}i+=`${a}}
109
+ `}return i}}import{createHmac as Iu,timingSafeEqual as zy}from"crypto";var _u=0,Ru=new WeakSet;if(typeof globalThis.ReadableStream==="function"&&!globalThis.ReadableStream.__bareTracked){let e=globalThis.ReadableStream,t=new Proxy(e,{construct(r,n,o){let s=Reflect.construct(r,n,o);if(n[0]&&typeof n[0].pull==="function")_u++,Ru.add(s);return s}});t.__bareTracked=!0,globalThis.ReadableStream=t}var Vy=new TextDecoder;class jo{req;params={};_status=200;_headers=void 0;store=new Map;body=void 0;_query=void 0;_cookies=void 0;_setCookies=void 0;_requestId=void 0;_peerIp=void 0;_trustProxy=!1;_detached=!1;constructor(e=!1){this._trustProxy=e}get query(){if(this._query!==void 0)return this._query;let e={},t=this.req?.url;if(t){let r=t.indexOf("?");if(r!==-1){let n=r+1,o=t.length,s=t.indexOf("+",n)!==-1,i=t.indexOf("%",n)!==-1;while(n<o){let a=t.indexOf("&",n);if(a===-1)a=o;if(a>n){let u=t.indexOf("=",n),c,f;if(u!==-1&&u<a)c=t.slice(n,u),f=t.slice(u+1,a);else c=t.slice(n,a),f="";if(s){if(c.indexOf("+")!==-1)c=c.replaceAll("+"," ");if(f.indexOf("+")!==-1)f=f.replaceAll("+"," ")}if(i){if(c.indexOf("%")!==-1)try{c=decodeURIComponent(c)}catch{}if(f.indexOf("%")!==-1)try{f=decodeURIComponent(f)}catch{}}if(c!=="__proto__"&&c!=="constructor"&&c!=="prototype")e[c]=f}n=a+1}}}return this._query=e,e}queryAll(e){let t=this.req?.url,r=t?t.indexOf("?"):-1;if(r===-1)return[];let n=[],o=new URLSearchParams(t.slice(r+1));for(let[s,i]of o)if(s===e)n.push(i);return n}getQuery(e){let t=this.query;return Object.hasOwn(t,e)?t[e]:void 0}get cookies(){if(this._cookies!==void 0)return this._cookies;let e=Object.create(null),t=this.req?.headers?.get("cookie");if(t){let r=0,n=t.length;while(r<n){let o=t.indexOf(";",r);if(o===-1)o=n;let s=t.indexOf("=",r);if(s!==-1&&s<o){let i=t.slice(r,s).trim(),a=t.slice(s+1,o).trim();try{a=decodeURIComponent(a)}catch{}if(i&&i!=="__proto__"&&i!=="constructor"&&i!=="prototype")e[i]=a}r=o+1}}return this._cookies=e,e}setCookie(e,t,r={}){if(!e||/[\r\n;= \t]/.test(e))throw Error("Invalid cookie name");let n=r.path??"/";if(/[\r\n;]/.test(n))throw Error("Invalid cookie path");if(r.domain&&/[\r\n;]/.test(r.domain))throw Error("Invalid cookie domain");let o=r.sameSite??"Lax";if(o!=="Strict"&&o!=="Lax"&&o!=="None")throw Error("Invalid cookie sameSite");let s=t;if(r.secret){let a=Iu("sha256",r.secret).update(t).digest("base64url");s=`${t}.${a}`}let i=`${e}=${encodeURIComponent(s)}`;if(i+=`; Path=${n}`,r.domain)i+=`; Domain=${r.domain}`;if(r.maxAge!==void 0&&Number.isFinite(r.maxAge))i+=`; Max-Age=${Math.floor(r.maxAge)}`;if(r.expires&&!Number.isNaN(r.expires.getTime()))i+=`; Expires=${r.expires.toUTCString()}`;if(r.httpOnly!==!1)i+="; HttpOnly";if(r.secure)i+="; Secure";if(i+=`; SameSite=${o}`,!this._setCookies)this._setCookies=[];return this._setCookies.push(i),this}getSignedCookie(e,t){let r=this.cookies;if(!Object.hasOwn(r,e))return null;let n=r[e];if(typeof n!=="string"||!n)return null;let o=n.lastIndexOf(".");if(o<0)return null;let s=n.slice(0,o),i=n.slice(o+1);if(!/^[A-Za-z0-9_-]{43}$/.test(i))return null;let a=Iu("sha256",t).update(s).digest(),u=Buffer.from(i,"base64url");if(u.length!==a.length||!zy(u,a))return null;return s}deleteCookie(e,t={}){return this.setCookie(e,"",{...t,maxAge:0,expires:new Date(0)})}async readBodyWithLimit(e){let t=this.req.body.getReader(),r=[],n=0;while(!0){let{done:i,value:a}=await t.read();if(i)break;if(a){if(n+=a.byteLength,n>e){try{await t.cancel()}catch{}throw Object.assign(Error("Payload Too Large"),{status:413})}r.push(a)}}let o=new Uint8Array(n),s=0;for(let i=0;i<r.length;i++)o.set(r[i],s),s+=r[i].byteLength;return o}_parseAndSanitizeJson(e,t){if(e.length>t||e.length*3>t&&Buffer.byteLength(e,"utf-8")>t){let n=Error("Payload Too Large");throw n.status=413,n}let r=JSON.parse(e);if(e.indexOf("__proto__")!==-1||e.indexOf("constructor")!==-1||e.indexOf("prototype")!==-1||e.indexOf("\\u")!==-1){let n=[r];while(n.length>0){let o=n.pop();if(!o||typeof o!=="object")continue;if(Array.isArray(o))for(let s=0;s<o.length;s++)n.push(o[s]);else{if(Object.hasOwn(o,"__proto__"))delete o.__proto__;if(Object.hasOwn(o,"constructor"))delete o.constructor;if(Object.hasOwn(o,"prototype"))delete o.prototype;let s=Object.keys(o);for(let i=0;i<s.length;i++)n.push(o[s[i]])}}}return this.body=r}jsonBodySyncOrAsync(e=1048576){if(this.body!==void 0)return this.body;let t=this.req.headers,r=t.get("content-type");if(r&&(r==="application/json"||r.startsWith("application/json;")||r.toLowerCase().includes("application/json"))){let n=t.get("content-length");if(n!==null){let i=n.trim(),a=i.length>0?Number(i):NaN;if(Number.isInteger(a)&&a>e){let u=Error("Payload Too Large");throw u.status=413,u}}if(n===null&&t.get("transfer-encoding")!==null||_u>0&&this.req.body&&Ru.has(this.req.body))return this.readBodyWithLimit(e).then((i)=>{try{return this._parseAndSanitizeJson(Vy.decode(i),e)}catch(a){if(a?.status===413)throw a;return this.body=null}},(i)=>{if(i?.status===413)throw i;return this.body=null});let o=this.req.text(),s=Bun.peek(o);if(typeof s==="string")try{return this._parseAndSanitizeJson(s,e)}catch(i){if(i?.status===413)throw i;return this.body=null}return o.then((i)=>{try{return this._parseAndSanitizeJson(i,e)}catch(a){if(a?.status===413)throw a;return this.body=null}},(i)=>{if(i?.status===413)throw i;return this.body=null})}return this.body=null}async jsonBody(e=1048576){return this.jsonBodySyncOrAsync(e)}reset(e){if(this.req=e,this._status=200,this._headers=void 0,this.store.size>0)this.store.clear();return this.params={},this._query=void 0,this._cookies=void 0,this._setCookies=void 0,this.body=void 0,this._requestId=void 0,this._peerIp=void 0,this._detached=!1,this}status(e){return this._status=e,this}_applyCookies(e){if(this._setCookies){for(let t=0;t<this._setCookies.length;t++)e.headers.append("Set-Cookie",this._setCookies[t]);this._setCookies=void 0}return e}json(e){let t=this._status||200,r;if(!this._headers)r=t===200?Response.json(e):Response.json(e,{status:t});else{let n=this._headers["content-type"]===void 0?{...this._headers,"content-type":"application/json"}:this._headers;r=Response.json(e,{status:t,headers:n})}return this._applyCookies(r)}set(e,t){return this.store.set(e,t),this}get(e){return this.store.get(e)}setHeader(e,t){if(!this._headers)this._headers={};else if(Object.isFrozen(this._headers))this._headers={...this._headers};let r=e.toLowerCase();if(r==="vary"&&this._headers.vary){let n=this._headers.vary,o=n.toLowerCase().split(",").map((i)=>i.trim()),s=t.split(",").map((i)=>i.trim()).filter((i)=>i&&!o.includes(i.toLowerCase()));this._headers.vary=s.length>0?`${n}, ${s.join(", ")}`:n}else this._headers[r]=t;return this}get user(){return this.store.get("user")}send(e,t={}){let r=this._status>=400;return this.json({status:r?"error":"success",msg:e,...t})}html(e,t){let r={...this._headers||{},"content-type":"text/html; charset=utf-8"};return this._applyCookies(new Response(e,{status:t??this._status,headers:r}))}text(e,t){let r={...this._headers||{},"content-type":"text/plain; charset=utf-8"};return this._applyCookies(new Response(e,{status:t??this._status,headers:r}))}redirect(e,t=302){if(/[\r\n]/.test(e))throw Error("Invalid redirect URL");let r={...this._headers||{},location:e};return this._applyCookies(new Response(null,{status:t,headers:r}))}sse(e){let t=new TextEncoder,r=(a)=>a.split(/\r\n|\r|\n/).map((u)=>`data: ${u}`).join(`
110
+ `)+`
60
111
 
61
- `);let i="";if(s.id!==void 0)i+=`id: ${s.id}
62
- `;if(s.event!==void 0)i+=`event: ${s.event}
63
- `;if(s.retry!==void 0)i+=`retry: ${s.retry}
64
- `;let a=typeof s.data==="string"?s.data:JSON.stringify(s.data);return i+=`data: ${a}
65
-
66
- `,t.encode(i)},n=new ReadableStream({async start(s){try{if(typeof e==="function"){let i=!1,a=(c,d,f)=>{if(!i)s.enqueue(r({data:c,event:d,id:f}))},u=()=>{if(!i)i=!0,s.close()};await e(a,u),u()}else{for await(let i of e)s.enqueue(r(i));s.close()}}catch(i){s.error(i)}}}),o={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache, no-transform",connection:"keep-alive",...this._headers||{}};return this._applyCookies(new Response(n,{status:this._status||200,headers:o}))}get requestId(){if(this._requestId!==void 0)return this._requestId;let e=this.req?.headers?.get("x-request-id");return this._requestId=e&&e.length>0&&e.length<=128?e:crypto.randomUUID(),this._requestId}get ip(){if(this._trustProxy){let e=this.req?.headers?.get("x-forwarded-for");if(e)return e.split(",")[0].trim();let t=this.req?.headers?.get("x-real-ip")||this.req?.headers?.get("cf-connecting-ip");if(t)return t}return this._peerIp||"127.0.0.1"}async upload(e={}){let t=e.maxFileSize??5242880,r=e.maxFiles??10,n=e.allowedTypes?new Set(e.allowedTypes):null;if(!(this.req?.headers?.get("content-type")||"").includes("multipart/form-data"))throw Object.assign(Error("Expected multipart/form-data"),{status:400});if(Number(this.req?.headers?.get("content-length")||0)>t*r+65536)throw Object.assign(Error("Payload Too Large"),{status:413});let i=await this.req.formData(),a={},u=[];for(let[c,d]of i.entries()){if(typeof d==="string"){if(c!=="__proto__"&&c!=="constructor"&&c!=="prototype")a[c]=d;continue}let f=d;if(u.length>=r)throw Object.assign(Error(`Too many files (max ${r})`),{status:413});if(f.size>t)throw Object.assign(Error(`File exceeds max size of ${t} bytes`),{status:413});let l=(f.type||"").split(";")[0].trim().toLowerCase();if(n&&!n.has(l))throw Object.assign(Error(`Unsupported file type: ${f.type||"unknown"}`),{status:415});let y=f.name||"file",O=(y.split(/[\\/]/).pop()||"file").replace(/[^a-zA-Z0-9._-]/g,"_").replace(/^\.+/,"")||"file";u.push({fieldName:c,filename:y,safeName:O,type:f.type,size:f.size,file:f})}return{fields:a,files:u}}}function Gn(e,t){return t===void 0?Ie(e):Ie({...t,...e})}function dc(e){return h({[I]:"Argument",index:e})}function Ly(e,t){return he("Awaited",[he(e,t)])}function Ky(e){return he("Awaited",[$t(e)])}function By(e){return Qe(fc(e))}function vy(e){return ie(fc(e))}function Dy(e){return Hn(e)}function fc(e){return e.map((t)=>Hn(t))}function Hn(e,t){return h(Tt(e)?Ly(e.target,e.parameters):Se(e)?By(e.allOf):te(e)?vy(e.anyOf):Hr(e)?Dy(e.item):Fe(e)?Ky(e.$ref):e,t)}function qy(e){let t=[];for(let r of e)t.push(...St(r));return ta(t)}function Gy(e){return e.filter((t)=>!Rr(t))}function Hy(e,t){let r=[];for(let n of e)r.push(...io(n,[t]));return Gy(r)}function zy(e,t){let r={};for(let n of t)r[n]=Do(Hy(e,n));return r}function mc(e,t){let r=qy(e),n=zy(e,r);return ae(n,t)}function ds(e){return h({[I]:"Date",type:"Date"},e)}function fs(e){return h({[I]:"Null",type:"null"},e)}function ms(e){return h({[I]:"Symbol",type:"symbol"},e)}function ps(e){return h({[I]:"Undefined",type:"undefined"},e)}function ls(e){return h({[I]:"Uint8Array",type:"Uint8Array"},e)}function Vy(e){return e.map((t)=>ui(t,!1))}function Jy(e){let t={};for(let r of globalThis.Object.getOwnPropertyNames(e))t[r]=ut(ui(e[r],!1));return t}function ys(e,t){return t===!0?e:ut(e)}function ui(e,t){return Pi(e)?ys(Sr(),t):Ai(e)?ys(Sr(),t):Ue(e)?ut(Ot(Vy(e))):br(e)?ls():pn(e)?ds():xe(e)?ys(ae(Jy(e)),t):Ci(e)?ys(Qt([],kr()),t):ge(e)?ps():Ti(e)?fs():Fi(e)?ms():Lo(e)?bn():yt(e)?se(e):Ir(e)?se(e):ye(e)?se(e):ae({})}function pc(e,t){return h(ui(e,!0),t)}function lc(e,t){return Ft(e)?Ot(e.parameters,t):J(t)}function yc(e,t){if(ge(e))throw Error("Enum undefined or empty");let r=globalThis.Object.getOwnPropertyNames(e).filter((s)=>isNaN(s)).map((s)=>e[s]),o=[...new Set(r)].map((s)=>se(s));return ie(o,{...t,[Yt]:"Enum"})}function gc(e,t){return zn(Jr(e),t)}function Wy(e,t){let r=e.filter((n)=>Ar(n,t)===x.False);return r.length===1?r[0]:ie(r)}function zn(e,t,r={}){if(xt(e))return h(gc(e,t),r);if(be(e))return h(hc(e,t),r);return h(te(e)?Wy(e.anyOf,t):Ar(e,t)!==x.False?J():e,r)}function Xy(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=zn(e[n],t);return r}function Yy(e,t){return Xy(e.properties,t)}function hc(e,t){let r=Yy(e,t);return re(r)}function xc(e,t){return Vn(Jr(e),t)}function Qy(e,t){let r=e.filter((n)=>Ar(n,t)!==x.False);return r.length===1?r[0]:ie(r)}function Vn(e,t,r){if(xt(e))return h(xc(e,t),r);if(be(e))return h(Ic(e,t),r);return h(te(e)?Qy(e.anyOf,t):Ar(e,t)!==x.False?e:J(),r)}function Zy(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=Vn(e[n],t);return r}function eg(e,t){return Zy(e.properties,t)}function Ic(e,t){let r=eg(e,t);return re(r)}function bc(e,t){return Ft(e)?h(e.returns,t):J(t)}function gs(e){return ut(Ye(e))}function un(e,t,r){return h({[I]:"Record",type:"object",patternProperties:{[e]:t}},r)}function di(e,t,r){let n={};for(let o of e)n[o]=t;return ae(n,{...r,[Yt]:"Record"})}function tg(e,t,r){return Ki(e)?di(ct(e),t,r):un(e.pattern,t,r)}function rg(e,t,r){return di(ct(ie(e)),t,r)}function ng(e,t,r){return di([e.toString()],t,r)}function og(e,t,r){return un(e.source,t,r)}function sg(e,t,r){let n=ge(e.pattern)?Or:e.pattern;return un(n,t,r)}function ig(e,t,r){return un(Or,t,r)}function ag(e,t,r){return un(Hi,t,r)}function cg(e,t,r){return ae({true:t,false:t},r)}function ug(e,t,r){return un(_r,t,r)}function dg(e,t,r){return un(_r,t,r)}function hs(e,t,r={}){return te(e)?rg(e.anyOf,t,r):xt(e)?tg(e,t,r):gt(e)?ng(e.const,t,r):or(e)?cg(e,t,r):Mt(e)?ug(e,t,r):jt(e)?dg(e,t,r):Ms(e)?og(e,t,r):sr(e)?sg(e,t,r):Fs(e)?ig(e,t,r):Rr(e)?ag(e,t,r):J(r)}function xs(e){return globalThis.Object.getOwnPropertyNames(e.patternProperties)[0]}function Rc(e){let t=xs(e);return t===Or?Et():t===_r?_t():Et({pattern:t})}function Is(e){return e.patternProperties[xs(e)]}function fg(e,t){return t.parameters=wo(e,t.parameters),t.returns=Vt(e,t.returns),t}function mg(e,t){return t.parameters=wo(e,t.parameters),t.returns=Vt(e,t.returns),t}function pg(e,t){return t.allOf=wo(e,t.allOf),t}function lg(e,t){return t.anyOf=wo(e,t.anyOf),t}function yg(e,t){if(ge(t.items))return t;return t.items=wo(e,t.items),t}function gg(e,t){return t.items=Vt(e,t.items),t}function hg(e,t){return t.items=Vt(e,t.items),t}function xg(e,t){return t.items=Vt(e,t.items),t}function Ig(e,t){return t.item=Vt(e,t.item),t}function bg(e,t){let r=wg(e,t.properties);return{...t,...ae(r)}}function Rg(e,t){let r=Vt(e,Rc(t)),n=Vt(e,Is(t)),o=hs(r,n);return{...t,...o}}function _g(e,t){return t.index in e?e[t.index]:kr()}function Og(e,t){let r=hn(t),n=at(t),o=Vt(e,t);return r&&n?gs(o):r&&!n?ut(o):!r&&n?Ye(o):o}function wg(e,t){return globalThis.Object.getOwnPropertyNames(t).reduce((r,n)=>({...r,[n]:Og(e,t[n])}),{})}function wo(e,t){return t.map((r)=>Vt(e,r))}function Vt(e,t){return Ft(t)?fg(e,t):Nt(t)?mg(e,t):Se(t)?pg(e,t):te(t)?lg(e,t):It(t)?yg(e,t):At(t)?gg(e,t):Dr(t)?hg(e,t):Gr(t)?xg(e,t):Hr(t)?Ig(e,t):Ne(t)?bg(e,t):zr(t)?Rg(e,t):Ns(t)?_g(e,t):t}function _c(e,t){return Vt(t,Gn(e))}function Oc(e){return h({[I]:"Integer",type:"integer"},e)}function $g(e,t,r){return{[e]:Jt(se(e),t,Ie(r))}}function Sg(e,t,r){return e.reduce((o,s)=>({...o,...$g(s,t,r)}),{})}function kg(e,t,r){return Sg(e.keys,t,r)}function wc(e,t,r){let n=kg(e,t,r);return re(n)}function Pg(e){let[t,r]=[e.slice(0,1),e.slice(1)];return[t.toLowerCase(),r].join("")}function Cg(e){let[t,r]=[e.slice(0,1),e.slice(1)];return[t.toUpperCase(),r].join("")}function Ag(e){return e.toUpperCase()}function Tg(e){return e.toLowerCase()}function Fg(e,t,r){let n=In(e.pattern);if(!Vr(n))return{...e,pattern:$c(e.pattern,t)};let i=[...so(n)].map((c)=>se(c)),a=Sc(i,t),u=ie(a);return zo([u],r)}function $c(e,t){return typeof e==="string"?t==="Uncapitalize"?Pg(e):t==="Capitalize"?Cg(e):t==="Uppercase"?Ag(e):t==="Lowercase"?Tg(e):e:e.toString()}function Sc(e,t){return e.map((r)=>Jt(r,t))}function Jt(e,t,r={}){return ht(e)?wc(e,t,r):xt(e)?Fg(e,t,r):te(e)?ie(Sc(e.anyOf,t),r):gt(e)?se($c(e.const,t),r):h(e,r)}function kc(e,t={}){return Jt(e,"Capitalize",t)}function Pc(e,t={}){return Jt(e,"Lowercase",t)}function Cc(e,t={}){return Jt(e,"Uncapitalize",t)}function Ac(e,t={}){return Jt(e,"Uppercase",t)}function Ng(e,t,r){let n={};for(let o of globalThis.Object.getOwnPropertyNames(e))n[o]=Er(e[o],t,Ie(r));return n}function Mg(e,t,r){return Ng(e.properties,t,r)}function Tc(e,t,r){let n=Mg(e,t,r);return re(n)}function jg(e,t){return e.map((r)=>fi(r,t))}function Eg(e,t){return e.map((r)=>fi(r,t))}function Ug(e,t){let{[t]:r,...n}=e;return n}function Lg(e,t){return t.reduce((r,n)=>Ug(r,n),e)}function Kg(e,t,r){let n=$e(e,[Re,"$id","required","properties"]),o=Lg(r,t);return ae(o,n)}function Bg(e){let t=e.reduce((r,n)=>vo(n)?[...r,se(n)]:r,[]);return ie(t)}function fi(e,t){return Se(e)?Qe(jg(e.allOf,t)):te(e)?ie(Eg(e.anyOf,t)):Ne(e)?Kg(e,t,e.properties):ae({})}function Er(e,t,r){let n=Ue(t)?Bg(t):t,o=_e(t)?ct(t):t,s=Fe(e),i=Fe(t);return be(e)?Tc(e,o,r):ht(t)?Fc(e,t,r):s&&i?he("Omit",[e,n],r):!s&&i?he("Omit",[e,n],r):s&&!i?he("Omit",[e,n],r):h({...fi(e,o),...r})}function vg(e,t,r){return{[t]:Er(e,[t],Ie(r))}}function Dg(e,t,r){return t.reduce((n,o)=>({...n,...vg(e,o,r)}),{})}function qg(e,t,r){return Dg(e,t.keys,r)}function Fc(e,t,r){let n=qg(e,t,r);return re(n)}function Gg(e,t,r){let n={};for(let o of globalThis.Object.getOwnPropertyNames(e))n[o]=Ur(e[o],t,Ie(r));return n}function Hg(e,t,r){return Gg(e.properties,t,r)}function Nc(e,t,r){let n=Hg(e,t,r);return re(n)}function zg(e,t){return e.map((r)=>mi(r,t))}function Vg(e,t){return e.map((r)=>mi(r,t))}function Jg(e,t){let r={};for(let n of t)if(n in e)r[n]=e[n];return r}function Wg(e,t,r){let n=$e(e,[Re,"$id","required","properties"]),o=Jg(r,t);return ae(o,n)}function Xg(e){let t=e.reduce((r,n)=>vo(n)?[...r,se(n)]:r,[]);return ie(t)}function mi(e,t){return Se(e)?Qe(zg(e.allOf,t)):te(e)?ie(Vg(e.anyOf,t)):Ne(e)?Wg(e,t,e.properties):ae({})}function Ur(e,t,r){let n=Ue(t)?Xg(t):t,o=_e(t)?ct(t):t,s=Fe(e),i=Fe(t);return be(e)?Nc(e,o,r):ht(t)?Mc(e,t,r):s&&i?he("Pick",[e,n],r):!s&&i?he("Pick",[e,n],r):s&&!i?he("Pick",[e,n],r):h({...mi(e,o),...r})}function Yg(e,t,r){return{[t]:Ur(e,[t],Ie(r))}}function Qg(e,t,r){return t.reduce((n,o)=>({...n,...Yg(e,o,r)}),{})}function Zg(e,t,r){return Qg(e,t.keys,r)}function Mc(e,t,r){let n=Zg(e,t,r);return re(n)}function eh(e,t){return he("Partial",[he(e,t)])}function th(e){return he("Partial",[$t(e)])}function rh(e){let t={};for(let r of globalThis.Object.getOwnPropertyNames(e))t[r]=Ye(e[r]);return t}function nh(e,t){let r=$e(e,[Re,"$id","required","properties"]),n=rh(t);return ae(n,r)}function jc(e){return e.map((t)=>Ec(t))}function Ec(e){return Tt(e)?eh(e.target,e.parameters):Fe(e)?th(e.$ref):Se(e)?Qe(jc(e.allOf)):te(e)?ie(jc(e.anyOf)):Ne(e)?nh(e,e.properties):qr(e)?e:or(e)?e:Mt(e)?e:gt(e)?e:eo(e)?e:jt(e)?e:sr(e)?e:to(e)?e:ir(e)?e:ae({})}function Jn(e,t){if(be(e))return Uc(e,t);else return h({...Ec(e),...t})}function oh(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=Jn(e[n],Ie(t));return r}function sh(e,t){return oh(e.properties,t)}function Uc(e,t){let r=sh(e,t);return re(r)}function ih(e,t){return he("Required",[he(e,t)])}function ah(e){return he("Required",[$t(e)])}function ch(e){let t={};for(let r of globalThis.Object.getOwnPropertyNames(e))t[r]=$e(e[r],[ze]);return t}function uh(e,t){let r=$e(e,[Re,"$id","required","properties"]),n=ch(t);return ae(n,r)}function Lc(e){return e.map((t)=>Kc(t))}function Kc(e){return Tt(e)?ih(e.target,e.parameters):Fe(e)?ah(e.$ref):Se(e)?Qe(Lc(e.allOf)):te(e)?ie(Lc(e.anyOf)):Ne(e)?uh(e,e.properties):qr(e)?e:or(e)?e:Mt(e)?e:gt(e)?e:eo(e)?e:jt(e)?e:sr(e)?e:to(e)?e:ir(e)?e:ae({})}function Wn(e,t){if(be(e))return Bc(e,t);else return h({...Kc(e),...t})}function dh(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=Wn(e[n],t);return r}function fh(e,t){return dh(e.properties,t)}function Bc(e,t){let r=fh(e,t);return re(r)}function mh(e,t){return t.map((r)=>Fe(r)?pi(e,r.$ref):Rt(e,r))}function pi(e,t){return t in e?Fe(e[t])?pi(e,e[t].$ref):Rt(e,e[t]):J()}function ph(e){return Hn(e[0])}function lh(e){return wr(e[0],e[1])}function yh(e){return _n(e[0])}function gh(e){return Jn(e[0])}function hh(e){return Er(e[0],e[1])}function xh(e){return Ur(e[0],e[1])}function Ih(e){return Wn(e[0])}function bh(e,t,r){let n=mh(e,r);return t==="Awaited"?ph(n):t==="Index"?lh(n):t==="KeyOf"?yh(n):t==="Partial"?gh(n):t==="Omit"?hh(n):t==="Pick"?xh(n):t==="Required"?Ih(n):J()}function Rh(e,t){return ln(Rt(e,t))}function _h(e,t){return yn(Rt(e,t))}function Oh(e,t,r){return gn($o(e,t),Rt(e,r))}function wh(e,t,r){return Qt($o(e,t),Rt(e,r))}function $h(e,t){return Qe($o(e,t))}function Sh(e,t){return Rn(Rt(e,t))}function kh(e,t){return ae(globalThis.Object.keys(t).reduce((r,n)=>({...r,[n]:Rt(e,t[n])}),{}))}function Ph(e,t){let[r,n]=[Rt(e,Is(t)),xs(t)],o=Gn(t);return o.patternProperties[n]=r,o}function Ch(e,t){return Fe(t)?{...pi(e,t.$ref),[Re]:t[Re]}:t}function Ah(e,t){return Ot($o(e,t))}function Th(e,t){return ie($o(e,t))}function $o(e,t){return t.map((r)=>Rt(e,r))}function Rt(e,t){return at(t)?h(Rt(e,$e(t,[ze])),t):hn(t)?h(Rt(e,$e(t,[Xt])),t):ne(t)?h(Ch(e,t),t):At(t)?h(Rh(e,t.items),t):Dr(t)?h(_h(e,t.items),t):Tt(t)?h(bh(e,t.target,t.parameters)):Ft(t)?h(Oh(e,t.parameters,t.returns),t):Nt(t)?h(wh(e,t.parameters,t.returns),t):Se(t)?h($h(e,t.allOf),t):Gr(t)?h(Sh(e,t.items),t):Ne(t)?h(kh(e,t.properties),t):zr(t)?h(Ph(e,t)):It(t)?h(Ah(e,t.items||[]),t):te(t)?h(Th(e,t.anyOf),t):t}function Fh(e,t){return t in e?Rt(e,e[t]):J()}function vc(e){return globalThis.Object.getOwnPropertyNames(e).reduce((t,r)=>({...t,[r]:Fh(e,r)}),{})}class Dc{constructor(e){let t=vc(e),r=this.WithIdentifiers(t);this.$defs=r}Import(e,t){let r={...this.$defs,[e]:h(this.$defs[e],t)};return h({[I]:"Import",$defs:r,$ref:e})}WithIdentifiers(e){return globalThis.Object.getOwnPropertyNames(e).reduce((t,r)=>({...t,[r]:{...e[r],$id:r}}),{})}}function qc(e){return new Dc(e)}function Gc(e,t){return h({[I]:"Not",not:e},t)}function Hc(e,t){return Nt(e)?Ot(e.parameters,t):J()}var Nh=0;function zc(e,t={}){if(ge(t.$id))t.$id=`T${Nh++}`;let r=Gn(e({[I]:"This",$ref:`${t.$id}`}));return r.$id=t.$id,h({[Yt]:"Recursive",...r},t)}function Vc(e,t){let r=ye(e)?new globalThis.RegExp(e):e;return h({[I]:"RegExp",type:"RegExp",source:r.source,flags:r.flags},t)}function Mh(e){return Se(e)?e.allOf:te(e)?e.anyOf:It(e)?e.items??[]:[]}function Jc(e){return Mh(e)}function Wc(e,t){return Nt(e)?h(e.returns,t):J(t)}class Xc{constructor(e){this.schema=e}Decode(e){return new Yc(this.schema,e)}}class Yc{constructor(e,t){this.schema=e,this.decode=t}EncodeTransform(e,t){let o={Encode:(s)=>t[Re].Encode(e(s)),Decode:(s)=>this.decode(t[Re].Decode(s))};return{...t,[Re]:o}}EncodeSchema(e,t){let r={Decode:this.decode,Encode:e};return{...t,[Re]:r}}Encode(e){return ne(this.schema)?this.EncodeTransform(e,this.schema):this.EncodeSchema(e,this.schema)}}function Qc(e){return new Xc(e)}function Zc(e){return h({[I]:"Void",type:"void"},e)}var jh=li;import{join as Uh}from"path";import{readFileSync as Lh}from"fs";Rs();import{join as Eh}from"path";async function tu(){let e=Eh(process.cwd(),"bare.config.ts");try{let t=await import(e);return bs(t.default)}catch{return bs()}}var _s=(e)=>{if(!e||!e._def)return{type:"object"};let t=e._def,r=t.typeName;if(r==="ZodObject"){let n=typeof t.shape==="function"?t.shape():t.shape,o={},s=[];for(let[i,a]of Object.entries(n||{})){let u=a;if(o[i]=_s(u),u?._def?.typeName!=="ZodOptional"&&u?._def?.typeName!=="ZodDefault")s.push(i)}return{type:"object",properties:o,...s.length?{required:s}:{}}}if(r==="ZodString")return{type:"string"};if(r==="ZodNumber")return{type:"number"};if(r==="ZodBoolean")return{type:"boolean"};if(r==="ZodArray")return{type:"array",items:_s(t.type)};if(r==="ZodOptional"||r==="ZodDefault")return _s(t.innerType);if(r==="ZodEnum")return{type:"string",enum:t.values};return{type:"object"}},So=(e)=>{if(!e)return{type:"object"};if("_def"in e)return _s(e);return JSON.parse(JSON.stringify(e))},gi=(e,t={})=>{let r={};for(let n of e){if(n.path==="/docs"||n.path==="/docs/json")continue;let o=("/"+n.path).replace(/\/+/g,"/").replace(/:([a-zA-Z0-9_]+)/g,"{$1}");if(!r[o])r[o]={};let s=n.method.toLowerCase(),i=[],a=void 0,u=void 0,c=void 0,d=null;for(let l of n.handlers){if(!l)continue;let y=l.__routeSchemas;if(y){if(y.detail)c=y.detail;if(y.params)d=So(y.params);if(y.query){let b=So(y.query),O=new Set(b.required||[]);for(let[B,q]of Object.entries(b.properties||{}))i.push({name:B,in:"query",required:O.has(B),schema:q})}if(y.headers){let b=So(y.headers),O=new Set(b.required||[]);for(let[B,q]of Object.entries(b.properties||{}))i.push({name:B,in:"header",required:O.has(B),schema:q})}if(y.response)u=So(y.response)}if(l.__schema&&!a)a={required:!0,content:{"application/json":{schema:So(l.__schema)}}}}let f=n.path.matchAll(/:([a-zA-Z0-9_]+)/g);for(let l of f){let y=l[1],b=d?.properties?.[y]||{type:"string"};i.unshift({name:y,in:"path",required:!0,schema:b})}r[o][s]={summary:c?.summary||`${n.method} ${o}`,...c?.description?{description:c.description}:{},...c?.tags?{tags:c.tags}:{},...i.length?{parameters:i}:{},...a?{requestBody:a}:{},responses:{"200":{description:"Success",...u?{content:{"application/json":{schema:u}}}:{}}}}}return{openapi:"3.1.0",info:{title:t.title||"BareJS API",version:t.version||"1.0.0",...t.description?{description:t.description}:{}},...t.servers?.length?{servers:t.servers}:{},...t.tags?.length?{tags:t.tags}:{},...t.securitySchemes?{components:{securitySchemes:t.securitySchemes}}:{},...t.security?.length?{security:t.security}:{},paths:r}},hi=(e,t="BareJS API Docs")=>{let r=t.replace(/[<>&"]/g,""),n=JSON.stringify(e);return`<!doctype html>
112
+ `,n=(a)=>{if(typeof a==="string")return t.encode(r(a));let u="";if(a.id!==void 0)u+=`id: ${String(a.id).replace(/[\r\n]/g,"")}
113
+ `;if(a.event!==void 0)u+=`event: ${String(a.event).replace(/[\r\n]/g,"")}
114
+ `;if(a.retry!==void 0&&Number.isFinite(a.retry))u+=`retry: ${Math.max(0,Math.floor(a.retry))}
115
+ `;let c=a.data===void 0?"":typeof a.data==="string"?a.data:JSON.stringify(a.data);return u+=r(c),t.encode(u)},o=!1,s=new ReadableStream({async start(a){let u=()=>{if(!o){o=!0;try{a.close()}catch{}}};try{if(typeof e==="function"){let f=e((d,m,y)=>{if(!o)try{a.enqueue(n({data:d,event:m,id:y}))}catch{o=!0}},u);if(f&&typeof f.then==="function")await f,u()}else{for await(let c of e){if(o)break;try{a.enqueue(n(c))}catch{o=!0;break}}u()}}catch(c){if(!o){o=!0;try{a.error(c)}catch{}}}},cancel(){o=!0}}),i={"content-type":"text/event-stream; charset=utf-8","cache-control":"no-cache, no-transform",connection:"keep-alive",...this._headers||{}};return this._applyCookies(new Response(s,{status:this._status||200,headers:i}))}get requestId(){if(this._requestId!==void 0)return this._requestId;let e=this.req?.headers?.get("x-request-id"),t=e?e.replace(/[\x00-\x1f\x7f]/g,""):"";return this._requestId=t.length>0&&t.length<=128?t:crypto.randomUUID(),this._requestId}get ip(){if(this._trustProxy){let e=this.req?.headers?.get("x-forwarded-for");if(e){let r=e.split(",")[0]?.trim();if(r)return r}let t=this.req?.headers?.get("x-real-ip")?.trim()||this.req?.headers?.get("cf-connecting-ip")?.trim();if(t)return t}return this._peerIp||"127.0.0.1"}async upload(e={}){let t=e.maxFileSize??5242880,r=e.maxFiles??10,n=e.allowedTypes?new Set(e.allowedTypes.map((m)=>m.trim().toLowerCase())):null;if(!(this.req?.headers?.get("content-type")||"").toLowerCase().includes("multipart/form-data"))throw Object.assign(Error("Expected multipart/form-data"),{status:400});let s=t*r,i=s+65536,a=Number(this.req?.headers?.get("content-length")||0);if(Number.isFinite(a)&&a>i)throw Object.assign(Error("Payload Too Large"),{status:413});let u;try{if(this.req.body){let m=await this.readBodyWithLimit(i);u=await new Response(m,{headers:this.req.headers}).formData()}else u=await this.req.formData()}catch(m){if(m?.status===413)throw m;throw Object.assign(Error("Malformed multipart/form-data payload"),{status:400})}let c={},f=[],d=0;for(let[m,y]of u.entries()){if(typeof y==="string"){if(d+=Buffer.byteLength(y,"utf-8"),d>s)throw Object.assign(Error(`Total upload size exceeds ${s} bytes`),{status:413});if(m!=="__proto__"&&m!=="constructor"&&m!=="prototype")c[m]=y;continue}let p=y;if(f.length>=r)throw Object.assign(Error(`Too many files (max ${r})`),{status:413});if(p.size>t)throw Object.assign(Error(`File exceeds max size of ${t} bytes`),{status:413});if(d+=p.size,d>s)throw Object.assign(Error(`Total upload size exceeds ${s} bytes`),{status:413});let h=(p.type||"").split(";")[0].trim().toLowerCase();if(n&&!n.has(h))throw Object.assign(Error(`Unsupported file type: ${p.type||"unknown"}`),{status:415});let x=p.name||"file",w=(x.split(/[\\/]/).pop()||"file").replace(/[^a-zA-Z0-9._-]/g,"_").replace(/^\.+/,"")||"file";f.push({fieldName:m,filename:x,safeName:w,type:p.type,size:p.size,file:p})}return{fields:c,files:f}}}function to(e,t){return t===void 0?Fe(e):Fe({...t,...e})}function Ou(e){return I({[O]:"Argument",index:e})}function Jy(e,t){return Pe("Awaited",[Pe(e,t)])}function Wy(e){return Pe("Awaited",[Tt(e)])}function Yy(e){return st(wu(e))}function Xy(e){return be(wu(e))}function Qy(e){return ro(e)}function wu(e){return e.map((t)=>ro(t))}function ro(e,t){return I(Bt(e)?Jy(e.target,e.parameters):Ke(e)?Yy(e.allOf):le(e)?Xy(e.anyOf):rn(e)?Qy(e.item):De(e)?Wy(e.$ref):e,t)}function Zy(e){let t=[];for(let r of e)t.push(...Ft(r));return da(t)}function eg(e){return e.filter((t)=>!Tr(t))}function tg(e,t){let r=[];for(let n of e)r.push(...xo(n,[t]));return eg(r)}function rg(e,t){let r={};for(let n of t)r[n]=es(tg(e,n));return r}function $u(e,t){let r=Zy(e),n=rg(e,r);return Ie(n,t)}function ws(e){return I({[O]:"Date",type:"Date"},e)}function $s(e){return I({[O]:"Null",type:"null"},e)}function ks(e){return I({[O]:"Symbol",type:"symbol"},e)}function As(e){return I({[O]:"Undefined",type:"undefined"},e)}function Ss(e){return I({[O]:"Uint8Array",type:"Uint8Array"},e)}function ng(e){return e.map((t)=>_i(t,!1))}function og(e){let t={};for(let r of globalThis.Object.getOwnPropertyNames(e))t[r]=yt(_i(e[r],!1));return t}function Ps(e,t){return t===!0?e:yt(e)}function _i(e,t){return Ui(e)?Ps(Er(),t):Bi(e)?Ps(Er(),t):He(e)?yt(Pt(ng(e))):Cr(e)?Ss():On(e)?ws():Te(e)?Ps(Ie(og(e)),t):Ki(e)?Ps(ar([],Lr()),t):Se(e)?As():vi(e)?$s():Di(e)?ks():Yo(e)?Cn():It(e)?xe(e):Pr(e)?xe(e):Ae(e)?xe(e):Ie({})}function ku(e,t){return I(_i(e,!0),t)}function Au(e,t){return vt(e)?Pt(e.parameters,t):ne(t)}function Su(e,t){if(Se(e))throw Error("Enum undefined or empty");let r=globalThis.Object.getOwnPropertyNames(e).filter((s)=>isNaN(s)).map((s)=>e[s]),o=[...new Set(r)].map((s)=>xe(s));return be(o,{...t,[ir]:"Enum"})}function Pu(e,t){return no(sn(e),t)}function sg(e,t){let r=e.filter((n)=>Br(n,t)===_.False);return r.length===1?r[0]:be(r)}function no(e,t,r={}){if(Ot(e))return I(Pu(e,t),r);if(Ne(e))return I(Cu(e,t),r);return I(le(e)?sg(e.anyOf,t):Br(e,t)!==_.False?ne():e,r)}function ig(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=no(e[n],t);return r}function ag(e,t){return ig(e.properties,t)}function Cu(e,t){let r=ag(e,t);return me(r)}function Tu(e,t){return oo(sn(e),t)}function ug(e,t){let r=e.filter((n)=>Br(n,t)!==_.False);return r.length===1?r[0]:be(r)}function oo(e,t,r){if(Ot(e))return I(Tu(e,t),r);if(Ne(e))return I(Fu(e,t),r);return I(le(e)?ug(e.anyOf,t):Br(e,t)!==_.False?e:ne(),r)}function cg(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=oo(e[n],t);return r}function fg(e,t){return cg(e.properties,t)}function Fu(e,t){let r=fg(e,t);return me(r)}function Nu(e,t){return vt(e)?I(e.returns,t):ne(t)}function Cs(e){return yt(ot(e))}function In(e,t,r){return I({[O]:"Record",type:"object",patternProperties:{[e]:t}},r)}function Ri(e,t,r){let n={};for(let o of e)n[o]=t;return Ie(n,{...r,[ir]:"Record"})}function dg(e,t,r){return Wi(e)?Ri(mt(e),t,r):In(e.pattern,t,r)}function pg(e,t,r){return Ri(mt(be(e)),t,r)}function lg(e,t,r){return Ri([e.toString()],t,r)}function mg(e,t,r){return In(e.source,t,r)}function yg(e,t,r){let n=Se(e.pattern)?Nr:e.pattern;return In(n,t,r)}function gg(e,t,r){return In(Nr,t,r)}function hg(e,t,r){return In(ta,t,r)}function xg(e,t,r){return Ie({true:t,false:t},r)}function bg(e,t,r){return In(Fr,t,r)}function Ig(e,t,r){return In(Fr,t,r)}function Ts(e,t,r={}){return le(e)?pg(e.anyOf,t,r):Ot(e)?dg(e,t,r):_t(e)?lg(e.const,t,r):yr(e)?xg(e,t,r):qt(e)?bg(e,t,r):Gt(e)?Ig(e,t,r):Gs(e)?mg(e,t,r):gr(e)?yg(e,t,r):Ds(e)?gg(e,t,r):Tr(e)?hg(e,t,r):ne(r)}function Fs(e){return globalThis.Object.getOwnPropertyNames(e.patternProperties)[0]}function ju(e){let t=Fs(e);return t===Nr?Ht():t===Fr?St():Ht({pattern:t})}function Ns(e){return e.patternProperties[Fs(e)]}function _g(e,t){return t.parameters=Mo(e,t.parameters),t.returns=rr(e,t.returns),t}function Rg(e,t){return t.parameters=Mo(e,t.parameters),t.returns=rr(e,t.returns),t}function Og(e,t){return t.allOf=Mo(e,t.allOf),t}function wg(e,t){return t.anyOf=Mo(e,t.anyOf),t}function $g(e,t){if(Se(t.items))return t;return t.items=Mo(e,t.items),t}function kg(e,t){return t.items=rr(e,t.items),t}function Ag(e,t){return t.items=rr(e,t.items),t}function Sg(e,t){return t.items=rr(e,t.items),t}function Pg(e,t){return t.item=rr(e,t.item),t}function Cg(e,t){let r=jg(e,t.properties);return{...t,...Ie(r)}}function Tg(e,t){let r=rr(e,ju(t)),n=rr(e,Ns(t)),o=Ts(r,n);return{...t,...o}}function Fg(e,t){return t.index in e?e[t.index]:Lr()}function Ng(e,t){let r=An(t),n=lt(t),o=rr(e,t);return r&&n?Cs(o):r&&!n?yt(o):!r&&n?ot(o):o}function jg(e,t){return globalThis.Object.getOwnPropertyNames(t).reduce((r,n)=>({...r,[n]:Ng(e,t[n])}),{})}function Mo(e,t){return t.map((r)=>rr(e,r))}function rr(e,t){return vt(t)?_g(e,t):Dt(t)?Rg(e,t):Ke(t)?Og(e,t):le(t)?wg(e,t):wt(t)?$g(e,t):Kt(t)?kg(e,t):Zr(t)?Ag(e,t):tn(t)?Sg(e,t):rn(t)?Pg(e,t):qe(t)?Cg(e,t):nn(t)?Tg(e,t):qs(t)?Fg(e,t):t}function Mu(e,t){return rr(t,to(e))}function Eu(e){return I({[O]:"Integer",type:"integer"},e)}function Mg(e,t,r){return{[e]:nr(xe(e),t,Fe(r))}}function Eg(e,t,r){return e.reduce((o,s)=>({...o,...Mg(s,t,r)}),{})}function Lg(e,t,r){return Eg(e.keys,t,r)}function Lu(e,t,r){let n=Lg(e,t,r);return me(n)}function Ug(e){let[t,r]=[e.slice(0,1),e.slice(1)];return[t.toLowerCase(),r].join("")}function Kg(e){let[t,r]=[e.slice(0,1),e.slice(1)];return[t.toUpperCase(),r].join("")}function Bg(e){return e.toUpperCase()}function vg(e){return e.toLowerCase()}function Dg(e,t,r){let n=Pn(e.pattern);if(!on(n))return{...e,pattern:Uu(e.pattern,t)};let i=[...ho(n)].map((c)=>xe(c)),a=Ku(i,t),u=be(a);return os([u],r)}function Uu(e,t){return typeof e==="string"?t==="Uncapitalize"?Ug(e):t==="Capitalize"?Kg(e):t==="Uppercase"?Bg(e):t==="Lowercase"?vg(e):e:e.toString()}function Ku(e,t){return e.map((r)=>nr(r,t))}function nr(e,t,r={}){return Rt(e)?Lu(e,t,r):Ot(e)?Dg(e,t,r):le(e)?be(Ku(e.anyOf,t),r):_t(e)?xe(Uu(e.const,t),r):I(e,r)}function Bu(e,t={}){return nr(e,"Capitalize",t)}function vu(e,t={}){return nr(e,"Lowercase",t)}function Du(e,t={}){return nr(e,"Uncapitalize",t)}function qu(e,t={}){return nr(e,"Uppercase",t)}function qg(e,t,r){let n={};for(let o of globalThis.Object.getOwnPropertyNames(e))n[o]=zr(e[o],t,Fe(r));return n}function Gg(e,t,r){return qg(e.properties,t,r)}function Gu(e,t,r){let n=Gg(e,t,r);return me(n)}function Hg(e,t){return e.map((r)=>Oi(r,t))}function zg(e,t){return e.map((r)=>Oi(r,t))}function Vg(e,t){let{[t]:r,...n}=e;return n}function Jg(e,t){return t.reduce((r,n)=>Vg(r,n),e)}function Wg(e,t,r){let n=Ue(e,[je,"$id","required","properties"]),o=Jg(r,t);return Ie(o,n)}function Yg(e){let t=e.reduce((r,n)=>Zo(n)?[...r,xe(n)]:r,[]);return be(t)}function Oi(e,t){return Ke(e)?st(Hg(e.allOf,t)):le(e)?be(zg(e.anyOf,t)):qe(e)?Wg(e,t,e.properties):Ie({})}function zr(e,t,r){let n=He(t)?Yg(t):t,o=Me(t)?mt(t):t,s=De(e),i=De(t);return Ne(e)?Gu(e,o,r):Rt(t)?Hu(e,t,r):s&&i?Pe("Omit",[e,n],r):!s&&i?Pe("Omit",[e,n],r):s&&!i?Pe("Omit",[e,n],r):I({...Oi(e,o),...r})}function Xg(e,t,r){return{[t]:zr(e,[t],Fe(r))}}function Qg(e,t,r){return t.reduce((n,o)=>({...n,...Xg(e,o,r)}),{})}function Zg(e,t,r){return Qg(e,t.keys,r)}function Hu(e,t,r){let n=Zg(e,t,r);return me(n)}function eh(e,t,r){let n={};for(let o of globalThis.Object.getOwnPropertyNames(e))n[o]=Vr(e[o],t,Fe(r));return n}function th(e,t,r){return eh(e.properties,t,r)}function zu(e,t,r){let n=th(e,t,r);return me(n)}function rh(e,t){return e.map((r)=>wi(r,t))}function nh(e,t){return e.map((r)=>wi(r,t))}function oh(e,t){let r={};for(let n of t)if(n in e)r[n]=e[n];return r}function sh(e,t,r){let n=Ue(e,[je,"$id","required","properties"]),o=oh(r,t);return Ie(o,n)}function ih(e){let t=e.reduce((r,n)=>Zo(n)?[...r,xe(n)]:r,[]);return be(t)}function wi(e,t){return Ke(e)?st(rh(e.allOf,t)):le(e)?be(nh(e.anyOf,t)):qe(e)?sh(e,t,e.properties):Ie({})}function Vr(e,t,r){let n=He(t)?ih(t):t,o=Me(t)?mt(t):t,s=De(e),i=De(t);return Ne(e)?zu(e,o,r):Rt(t)?Vu(e,t,r):s&&i?Pe("Pick",[e,n],r):!s&&i?Pe("Pick",[e,n],r):s&&!i?Pe("Pick",[e,n],r):I({...wi(e,o),...r})}function ah(e,t,r){return{[t]:Vr(e,[t],Fe(r))}}function uh(e,t,r){return t.reduce((n,o)=>({...n,...ah(e,o,r)}),{})}function ch(e,t,r){return uh(e,t.keys,r)}function Vu(e,t,r){let n=ch(e,t,r);return me(n)}function fh(e,t){return Pe("Partial",[Pe(e,t)])}function dh(e){return Pe("Partial",[Tt(e)])}function ph(e){let t={};for(let r of globalThis.Object.getOwnPropertyNames(e))t[r]=ot(e[r]);return t}function lh(e,t){let r=Ue(e,[je,"$id","required","properties"]),n=ph(t);return Ie(n,r)}function Ju(e){return e.map((t)=>Wu(t))}function Wu(e){return Bt(e)?fh(e.target,e.parameters):De(e)?dh(e.$ref):Ke(e)?st(Ju(e.allOf)):le(e)?be(Ju(e.anyOf)):qe(e)?lh(e,e.properties):en(e)?e:yr(e)?e:qt(e)?e:_t(e)?e:po(e)?e:Gt(e)?e:gr(e)?e:lo(e)?e:hr(e)?e:Ie({})}function so(e,t){if(Ne(e))return Yu(e,t);else return I({...Wu(e),...t})}function mh(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=so(e[n],Fe(t));return r}function yh(e,t){return mh(e.properties,t)}function Yu(e,t){let r=yh(e,t);return me(r)}function gh(e,t){return Pe("Required",[Pe(e,t)])}function hh(e){return Pe("Required",[Tt(e)])}function xh(e){let t={};for(let r of globalThis.Object.getOwnPropertyNames(e))t[r]=Ue(e[r],[et]);return t}function bh(e,t){let r=Ue(e,[je,"$id","required","properties"]),n=xh(t);return Ie(n,r)}function Xu(e){return e.map((t)=>Qu(t))}function Qu(e){return Bt(e)?gh(e.target,e.parameters):De(e)?hh(e.$ref):Ke(e)?st(Xu(e.allOf)):le(e)?be(Xu(e.anyOf)):qe(e)?bh(e,e.properties):en(e)?e:yr(e)?e:qt(e)?e:_t(e)?e:po(e)?e:Gt(e)?e:gr(e)?e:lo(e)?e:hr(e)?e:Ie({})}function io(e,t){if(Ne(e))return Zu(e,t);else return I({...Qu(e),...t})}function Ih(e,t){let r={};for(let n of globalThis.Object.getOwnPropertyNames(e))r[n]=io(e[n],t);return r}function _h(e,t){return Ih(e.properties,t)}function Zu(e,t){let r=_h(e,t);return me(r)}function Rh(e,t){return t.map((r)=>De(r)?$i(e,r.$ref):kt(e,r))}function $i(e,t){return t in e?De(e[t])?$i(e,e[t].$ref):kt(e,e[t]):ne()}function Oh(e){return ro(e[0])}function wh(e){return jr(e[0],e[1])}function $h(e){return Fn(e[0])}function kh(e){return so(e[0])}function Ah(e){return zr(e[0],e[1])}function Sh(e){return Vr(e[0],e[1])}function Ph(e){return io(e[0])}function Ch(e,t,r){let n=Rh(e,r);return t==="Awaited"?Oh(n):t==="Index"?wh(n):t==="KeyOf"?$h(n):t==="Partial"?kh(n):t==="Omit"?Ah(n):t==="Pick"?Sh(n):t==="Required"?Ph(n):ne()}function Th(e,t){return wn(kt(e,t))}function Fh(e,t){return $n(kt(e,t))}function Nh(e,t,r){return kn(Eo(e,t),kt(e,r))}function jh(e,t,r){return ar(Eo(e,t),kt(e,r))}function Mh(e,t){return st(Eo(e,t))}function Eh(e,t){return Tn(kt(e,t))}function Lh(e,t){return Ie(globalThis.Object.keys(t).reduce((r,n)=>({...r,[n]:kt(e,t[n])}),{}))}function Uh(e,t){let[r,n]=[kt(e,Ns(t)),Fs(t)],o=to(t);return o.patternProperties[n]=r,o}function Kh(e,t){return De(t)?{...$i(e,t.$ref),[je]:t[je]}:t}function Bh(e,t){return Pt(Eo(e,t))}function vh(e,t){return be(Eo(e,t))}function Eo(e,t){return t.map((r)=>kt(e,r))}function kt(e,t){return lt(t)?I(kt(e,Ue(t,[et])),t):An(t)?I(kt(e,Ue(t,[sr])),t):ye(t)?I(Kh(e,t),t):Kt(t)?I(Th(e,t.items),t):Zr(t)?I(Fh(e,t.items),t):Bt(t)?I(Ch(e,t.target,t.parameters)):vt(t)?I(Nh(e,t.parameters,t.returns),t):Dt(t)?I(jh(e,t.parameters,t.returns),t):Ke(t)?I(Mh(e,t.allOf),t):tn(t)?I(Eh(e,t.items),t):qe(t)?I(Lh(e,t.properties),t):nn(t)?I(Uh(e,t)):wt(t)?I(Bh(e,t.items||[]),t):le(t)?I(vh(e,t.anyOf),t):t}function Dh(e,t){return t in e?kt(e,e[t]):ne()}function ec(e){return globalThis.Object.getOwnPropertyNames(e).reduce((t,r)=>({...t,[r]:Dh(e,r)}),{})}class tc{constructor(e){let t=ec(e),r=this.WithIdentifiers(t);this.$defs=r}Import(e,t){let r={...this.$defs,[e]:I(this.$defs[e],t)};return I({[O]:"Import",$defs:r,$ref:e})}WithIdentifiers(e){return globalThis.Object.getOwnPropertyNames(e).reduce((t,r)=>({...t,[r]:{...e[r],$id:r}}),{})}}function rc(e){return new tc(e)}function nc(e,t){return I({[O]:"Not",not:e},t)}function oc(e,t){return Dt(e)?Pt(e.parameters,t):ne()}var qh=0;function sc(e,t={}){if(Se(t.$id))t.$id=`T${qh++}`;let r=to(e({[O]:"This",$ref:`${t.$id}`}));return r.$id=t.$id,I({[ir]:"Recursive",...r},t)}function ic(e,t){let r=Ae(e)?new globalThis.RegExp(e):e;return I({[O]:"RegExp",type:"RegExp",source:r.source,flags:r.flags},t)}function Gh(e){return Ke(e)?e.allOf:le(e)?e.anyOf:wt(e)?e.items??[]:[]}function ac(e){return Gh(e)}function uc(e,t){return Dt(e)?I(e.returns,t):ne(t)}class cc{constructor(e){this.schema=e}Decode(e){return new fc(this.schema,e)}}class fc{constructor(e,t){this.schema=e,this.decode=t}EncodeTransform(e,t){let o={Encode:(s)=>t[je].Encode(e(s)),Decode:(s)=>this.decode(t[je].Decode(s))};return{...t,[je]:o}}EncodeSchema(e,t){let r={Decode:this.decode,Encode:e};return{...t,[je]:r}}Encode(e){return ye(this.schema)?this.EncodeTransform(e,this.schema):this.EncodeSchema(e,this.schema)}}function dc(e){return new cc(e)}function pc(e){return I({[O]:"Void",type:"void"},e)}var Hh=ki;import{join as Yh}from"path";import{readFileSync as Xh}from"fs";import{existsSync as zh}from"fs";import{createRequire as Vh}from"module";import{join as Jh}from"path";var Ai={hash:{algorithm:"argon2id",memoryCost:65536,timeCost:2},port:3000},Et=Ai,js=(e={})=>{let t=e&&typeof e==="object"&&!Array.isArray(e)?e:{};return Et={...Ai,...t,hash:{...Ai.hash,...t.hash&&typeof t.hash==="object"&&!Array.isArray(t.hash)?t.hash:{}}},Et};var Si=Vh(import.meta.url);async function lc(){let e=Jh(process.cwd(),"bare.config.ts");if(!zh(e))return js();try{let t=Si.resolve(e);delete Si.cache[t];let r=Si(t);return js(r?.default??r)}catch(t){return console.warn("[BareJS] Failed to load bare.config.ts:",t?.message||t),js()}}var Jr=(e)=>{if(!e||!e._def)return{type:"object"};let t=e._def,r=t.typeName;if(r==="ZodObject"){let n=typeof t.shape==="function"?t.shape():t.shape,o={},s=[];for(let[i,a]of Object.entries(n||{})){let u=a;if(o[i]=Jr(u),u?._def?.typeName!=="ZodOptional"&&u?._def?.typeName!=="ZodDefault")s.push(i)}return{type:"object",properties:o,...s.length?{required:s}:{}}}if(r==="ZodString"){let n={type:"string"};for(let o of t.checks||[])if(o.kind==="min")n.minLength=o.value;else if(o.kind==="max")n.maxLength=o.value;else if(o.kind==="email")n.format="email";else if(o.kind==="uuid")n.format="uuid";return n}if(r==="ZodNumber"){let n={type:"number"};for(let o of t.checks||[])if(o.kind==="int")n.type="integer";else if(o.kind==="min")n[o.inclusive===!1?"exclusiveMinimum":"minimum"]=o.value;else if(o.kind==="max")n[o.inclusive===!1?"exclusiveMaximum":"maximum"]=o.value;return n}if(r==="ZodNullable")return{anyOf:[Jr(t.innerType),{type:"null"}]};if(r==="ZodBoolean")return{type:"boolean"};if(r==="ZodArray")return{type:"array",items:Jr(t.type)};if(r==="ZodOptional"||r==="ZodDefault")return Jr(t.innerType);if(r==="ZodEffects")return Jr(t.schema);if(r==="ZodLiteral")return{const:t.value};if(r==="ZodDate")return{type:"string",format:"date-time"};if(r==="ZodRecord")return{type:"object",additionalProperties:Jr(t.valueType)};if(r==="ZodUnion"&&Array.isArray(t.options))return{anyOf:t.options.map(Jr)};if(r==="ZodEnum")return{type:"string",enum:t.values};return{type:"object"}},Lo=(e)=>{if(!e)return{type:"object"};if("_def"in e)return Jr(e);return JSON.parse(JSON.stringify(e))},Pi=(e,t={})=>{let r={},n=new Set(["/docs","/docs/json",...t.excludePaths||[]]);for(let o of e){if(n.has(o.path))continue;let s=("/"+o.path).replace(/\/+/g,"/").replace(/:([a-zA-Z0-9_]+)/g,"{$1}").replace(/\/\*$/,"/{wildcard}");if(!r[s])r[s]={};let i=o.method.toLowerCase(),a=[],u=void 0,c=void 0,f=void 0,d=null;for(let h of o.handlers){if(!h)continue;let x=h.__routeSchemas;if(x){if(x.detail)f=x.detail;if(x.params)d=Lo(x.params);if(x.query){let R=Lo(x.query),w=new Set(R.required||[]);for(let[P,C]of Object.entries(R.properties||{}))a.push({name:P,in:"query",required:w.has(P),schema:C})}if(x.headers){let R=Lo(x.headers),w=new Set(R.required||[]);for(let[P,C]of Object.entries(R.properties||{}))a.push({name:P,in:"header",required:w.has(P),schema:C})}if(x.response)c=Lo(x.response)}if(h.__schema&&!u)u={required:!0,content:{"application/json":{schema:Lo(h.__schema)}}}}let m=[],y=o.path.matchAll(/:([a-zA-Z0-9_]+)/g);for(let h of y){let x=h[1],R=d?.properties?.[x]||{type:"string"};m.push({name:x,in:"path",required:!0,schema:R})}if(/\/\*$/.test(o.path))m.push({name:"wildcard",in:"path",required:!0,schema:{type:"string"}});let p=[...m,...a];r[s][i]={summary:f?.summary||`${o.method} ${s}`,...f?.description?{description:f.description}:{},...f?.tags?{tags:f.tags}:{},...p.length?{parameters:p}:{},...u?{requestBody:u}:{},responses:{"200":{description:"Success",...c?{content:{"application/json":{schema:c}}}:{}}}}}return{openapi:"3.1.0",info:{title:t.title||"BareJS API",version:t.version||"1.0.0",...t.description?{description:t.description}:{}},...t.servers?.length?{servers:t.servers}:{},...t.tags?.length?{tags:t.tags}:{},...t.securitySchemes?{components:{securitySchemes:t.securitySchemes}}:{},...t.security?.length?{security:t.security}:{},paths:r}},Wh=(e)=>e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/'/g,"&#39;").replace(/</g,"&lt;").replace(/>/g,"&gt;"),Ci=(e,t="BareJS API Docs")=>{let r=t.replace(/[<>&"]/g,""),n=Wh(e);return`<!doctype html>
67
116
  <html>
68
117
  <head>
69
118
  <title>${r}</title>
@@ -71,29 +120,35 @@ var{defineProperty:ks,getOwnPropertyNames:yu,getOwnPropertyDescriptor:gu}=Object
71
120
  <meta name="viewport" content="width=device-width, initial-scale=1" />
72
121
  </head>
73
122
  <body>
74
- <script id="api-reference" data-url=${n}></script>
123
+ <script id="api-reference" data-url="${n}"></script>
75
124
  <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
76
125
  </body>
77
- </html>`};class ru extends an{tree=new cn;pool=[];hotFetch;compiled=!1;poolMask;_useLog=!1;_trustProxy=!0;errorHandler;wsRoutes=new Map;startHooks=[];stopHooks=[];crons=[];server;shutdownHandler;wsAdapter={open(e){e.data?.open?.(e)},message(e,t){e.data?.message?.(e,t)},close(e,t,r){e.data?.close?.(e,t,r)},drain(e){e.data?.drain?.(e)}};useLog(e=!0){return this._useLog=e,this}onStart(e){return this.startHooks.push(e),this}onStop(e){return this.stopHooks.push(e),this}cron(e,t,r,n={}){let o=!1,s=async()=>{if(o)return;o=!0;try{await r()}catch(a){n.onError?.(a)}finally{o=!1}},i=setInterval(s,t);if(this.crons.push({name:e,timer:i}),n.runOnStart)s();return this}async stop(e=!1){for(let t of this.crons)clearInterval(t.timer);if(this.crons.length=0,this.shutdownHandler)process.off("SIGINT",this.shutdownHandler),process.off("SIGTERM",this.shutdownHandler),this.shutdownHandler=void 0;if(this.server)this.server.stop(e),this.server=void 0;for(let t of this.stopHooks)await t()}constructor(e=1024){super();tu();let t=Math.pow(2,Math.ceil(Math.log2(e)));this.poolMask=t-1;for(let r=0;r<t;r++)this.pool.push(new Oo);try{let r=Uh(process.cwd(),"package.json"),n=JSON.parse(Lh(r,"utf-8"));if(n.name)this.name=n.name.split(/[-_]/).map((o)=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")}catch{this.name="App"}}notFoundHandler=()=>({status:404,message:"Route not found"});setNotFound(e){this.notFoundHandler=e}onError(e){return this.errorHandler=e,this}ws(e,t){let r=("/"+e).replace(/\/+/g,"/").replace(/\/$/,"")||"/";return this.wsRoutes.set(r,t),this}docs(e="/docs",t={}){let r=("/"+e).replace(/\/+/g,"/").replace(/\/$/,"")||"/docs",n=`${r}/json`,o=null,s=hi(n,t.title||`${this.name} API Docs`);return this.get(n,()=>{if(!o)o=JSON.stringify(gi(this.routes,{title:this.name,...t}));return new Response(o,{status:200,headers:{"content-type":"application/json"}})}),this.get(r,()=>new Response(s,{status:200,headers:{"content-type":"text/html; charset=utf-8"}})),this}rpc(e,t){let r=async(n,o)=>{if(!n||n.jsonrpc!=="2.0"||typeof n.method!=="string")return{jsonrpc:"2.0",error:{code:-32600,message:"Invalid Request"},id:n?.id??null};let s=Object.hasOwn(t,n.method)?t[n.method]:void 0;if(!s)return{jsonrpc:"2.0",error:{code:-32601,message:"Method not found"},id:n.id??null};try{let i=await s(n.params,o);if(n.id===void 0)return null;return{jsonrpc:"2.0",result:i,id:n.id}}catch(i){return{jsonrpc:"2.0",error:{code:-32603,message:i?.message||"Internal error"},id:n.id??null}}};return this.post(e,async(n)=>{let o=await n.jsonBody();if(!o)return n.status(400).json({jsonrpc:"2.0",error:{code:-32700,message:"Parse error"},id:null});if(Array.isArray(o)){if(o.length===0)return n.status(400).json({jsonrpc:"2.0",error:{code:-32600,message:"Invalid Request"},id:null});let i=(await Promise.all(o.map((a)=>r(a,n)))).filter(Boolean);return i.length>0?i:new Response(null,{status:204})}let s=await r(o,n);return s===null?new Response(null,{status:204}):s}),this}_hasDerive=!1;derive(e){return this._hasDerive=!0,this.use(async(t,r)=>{let n=await e(t);if(n&&typeof n==="object"){let o=Object.keys(n);if(!t._derivedKeys)t._derivedKeys=[];for(let s=0;s<o.length;s++){let i=o[s];if(i!=="__proto__"&&i!=="constructor"&&i!=="prototype")t[i]=n[i],t._derivedKeys.push(i)}}return r()}),this}compileHandler(e,t){let r=e.find((_)=>_?.__timeout);if(r){let{ms:_,status:U,message:j}=r.__timeout,N=e.filter((Xe)=>!Xe?.__timeout),G=this.compileHandler(N,t);return async(Xe,Te)=>{let E=G(Xe,Te);if(!E||!E.then)return E;let v;try{let z=new Promise((Me)=>{v=setTimeout(()=>{Me(Response.json({status:"error",code:"REQUEST_TIMEOUT",message:j},{status:U}))},_)});return await Promise.race([E,z])}finally{if(v!==void 0)clearTimeout(v)}}}let n=e.find((_)=>_?.__circuitBreaker);if(n){let _=n.__circuitBreaker,U=e.filter((N)=>!N?.__circuitBreaker),j=this.compileHandler(U,t);return(N,G)=>_(()=>j(N,G))}let o=e.find((_)=>_?.__compress);if(o){let _=o.__compress,U=e.filter((N)=>!N?.__compress),j=this.compileHandler(U,t);return async(N,G)=>{let Xe=await j(N,G);return _(N,Xe)}}let s=e.length,a=e.find((_)=>_?.__responseFilter)?.__responseFilter,u=e.find((_)=>_?.__idempotencyCommit),c=u?.__idempotencyCommit,d=u?.__idempotencyRelease,f={status:200,headers:{"content-type":"application/json"}},l={status:200,headers:{"content-type":"text/plain"}},O=`
78
- ${a?"res = rFilter(res);":""}
79
- if (res instanceof Response) {
80
- ${c?"idemCommit(ctx, res, res.status);":""}
81
- if (ctx._headers) {
82
- for (const k in ctx._headers) {
83
- if (!res.headers.has(k)) res.headers.set(k, ctx._headers[k]);
126
+ </html>`};class Ti extends xn{tree=new bn;pool=[];hotFetch;compiled=!1;_useLog=!1;_trustProxyBox={val:!1};errorHandler;wsRoutes=new Map;startHooks=[];stopHooks=[];crons=[];server;shutdownHandler;wsAdapter={open(e){e.data?.open?.(e)},message(e,t){e.data?.message?.(e,t)},close(e,t,r){e.data?.close?.(e,t,r)},drain(e){e.data?.drain?.(e)}};useLog(e=!0){return this._useLog=e,this}onStart(e){return this.startHooks.push(e),this}onStop(e){return this.stopHooks.push(e),this}cron(e,t,r,n={}){if(!Number.isFinite(t)||t<=0)throw RangeError(`cron("${e}") intervalMs must be a positive finite number`);let o=!1,s=async()=>{if(o)return;o=!0;try{await r()}catch(a){n.onError?.(a)}finally{o=!1}},i=setInterval(s,t);if(this.crons.push({name:e,timer:i}),n.runOnStart)s();return this}async stop(e=!1){for(let t of this.crons)clearInterval(t.timer);if(this.crons.length=0,this.shutdownHandler)process.off("SIGINT",this.shutdownHandler),process.off("SIGTERM",this.shutdownHandler),this.shutdownHandler=void 0;if(this.server)this.server.stop(e),this.server=void 0;for(let t of this.stopHooks)try{await t()}catch(r){console.error(`[${this.name}] onStop error:`,r)}}constructor(e=1024){super();lc();let t=Math.pow(2,Math.ceil(Math.log2(e)));for(let r=0;r<t;r++)this.pool.push(new jo);try{let r=Yh(process.cwd(),"package.json"),n=JSON.parse(Xh(r,"utf-8"));if(n.name)this.name=n.name.split(/[-_]/).map((o)=>o.charAt(0).toUpperCase()+o.slice(1)).join(" ")}catch{this.name="App"}}notFoundHandler=()=>({status:404,message:"Route not found"});setNotFound(e){this.notFoundHandler=e}onError(e){return this.errorHandler=e,this}ws(e,t){let r=("/"+e).replace(/\/+/g,"/").replace(/\/$/,"")||"/";return this.wsRoutes.set(r,t),this}docs(e="/docs",t={}){let r=("/"+e).replace(/\/+/g,"/").replace(/\/$/,"")||"/docs",n=`${r}/json`,o=null,s=Ci(n,t.title||`${this.name} API Docs`);return this.get(n,()=>{if(!o)o=JSON.stringify(Pi(this.routes,{title:this.name,excludePaths:[r,n],...t}));return new Response(o,{status:200,headers:{"content-type":"application/json"}})}),this.get(r,()=>new Response(s,{status:200,headers:{"content-type":"text/html; charset=utf-8"}})),this}rpc(e,t,r={}){let n=r.maxBatchSize??100,o=!1,s=async(i,a)=>{if(!i||i.jsonrpc!=="2.0"||typeof i.method!=="string")return{jsonrpc:"2.0",error:{code:-32600,message:"Invalid Request"},id:i?.id??null};let u=Object.hasOwn(t,i.method)?t[i.method]:void 0;if(!u)return{jsonrpc:"2.0",error:{code:-32601,message:"Method not found"},id:i.id??null};try{let c=await u(i.params,a);if(i.id===void 0)return null;return{jsonrpc:"2.0",result:c,id:i.id}}catch(c){return{jsonrpc:"2.0",error:{code:-32603,message:c?.message||"Internal error"},id:i.id??null}}};return this.post(e,async(i)=>{let a=await i.jsonBody();if(!a)return i.status(400).json({jsonrpc:"2.0",error:{code:-32700,message:"Parse error"},id:null});if(Array.isArray(a)){if(a.length===0||a.length>n)return i.status(400).json({jsonrpc:"2.0",error:{code:-32600,message:"Invalid Request"},id:null});let c=(await Promise.all(a.map((f)=>s(f,i)))).filter(Boolean);return c.length>0?c:new Response(null,{status:204})}let u=await s(a,i);return u===null?new Response(null,{status:204}):u}),this}_hasDerive=!1;static DERIVE_RESERVED=new Set(["__proto__","constructor","prototype","req","params","store","body","user","query","cookies","requestId","ip","status","json","html","text","redirect","sse","upload","reset","set","get","setHeader","setCookie","getSignedCookie","deleteCookie","jsonBody","send","getQuery","_status","_headers","_query","_cookies","_setCookies","_requestId","_peerIp","_trustProxy","_detached","_derivedKeys","_idempotencyKey","_idemInFlight"]);derive(e){this._hasDerive=!0;let t=async(r,n)=>{let o=await e(r);if(o&&typeof o==="object"){let s=Object.keys(o);if(!r._derivedKeys)r._derivedKeys=[];for(let i=0;i<s.length;i++){let a=s[i];if(a==="user")r.set("user",o[a]);else if(!Ti.DERIVE_RESERVED.has(a))r[a]=o[a],r._derivedKeys.push(a)}}return n()};return t.__isDerive=!0,this.use(t),this}compileHandler(e,t){if(e.length===0)return()=>{return};let r=(A,oe)=>{if(oe._headers)for(let Q in oe._headers){let re=oe._headers[Q];if(re===void 0)continue;if(!A.headers.has(Q))try{A.headers.set(Q,re)}catch{}else if(Q.toLowerCase()==="vary"){let ie=A.headers.get("vary")||"",ge=ie.toLowerCase().split(",").map((ae)=>ae.trim()),ee=re.split(",").map((ae)=>ae.trim()).filter((ae)=>ae&&!ge.includes(ae.toLowerCase()));if(ee.length>0)try{A.headers.set("vary",ie?`${ie}, ${ee.join(", ")}`:ee.join(", "))}catch{}}}if(oe._setCookies){for(let Q=0;Q<oe._setCookies.length;Q++)try{A.headers.append("Set-Cookie",oe._setCookies[Q])}catch{}oe._setCookies=void 0}return A},n=e.find((A)=>A?.__compress);if(n){let A=n.__compress,oe=e.filter((re)=>!re?.__compress),Q=this.compileHandler(oe,t);return async(re,ie)=>{let ge=await Q(re,ie);return A(re,ge)}}let o=e.findIndex((A)=>A?.__circuitBreaker);if(o!==-1){let oe=e[o].__circuitBreaker,Q=e.slice(0,o),re=[],ie=[];for(let D=0;D<Q.length;D++){let k=Q[D];if(k?.__timeout||k?.__idempotencyCommit||k?.__responseFilter)ie.push(k);else re.push(k)}let ge=[...ie,...e.slice(o+1)],ee=this.compileHandler(ge,t),ae=()=>{};return async(D,k)=>{for(let we=0;we<re.length;we++){let Ce=re[we](D,ae);if(Ce&&typeof Ce.then==="function")Ce=await Ce;if(Ce instanceof Response){if(r(Ce,D),t&&k&&!D._detached)k(Ce.status);return Ce}}let v=!1,G=await oe(()=>(v=!0,ee(D,k)));if(!v&&G instanceof Response){if(r(G,D),t&&k&&!D._detached)k(G.status)}return G}}let s=e.filter((A)=>A?.__timeout);if(s.length>0){let A=s[0].__timeout;for(let ee=1;ee<s.length;ee++)if(s[ee].__timeout.ms<A.ms)A=s[ee].__timeout;let{ms:oe,status:Q,message:re}=A,ie=e.filter((ee)=>!ee?.__timeout),ge=this.compileHandler(ie,t);return async(ee,ae)=>{let D=ge(ee,ae);if(!D||!D.then)return D;let k;try{let v=new Promise((G)=>{k=setTimeout(()=>{if(ee._detached=!0,ee._idempotencyKey&&ee._idemInFlight)ee._idemInFlight.delete(ee._idempotencyKey),ee._idempotencyKey=void 0,ee._idemInFlight=void 0;if(typeof D.catch==="function")D.catch(()=>{});if(t&&ae)ae(Q);G(r(Response.json({status:"error",code:"REQUEST_TIMEOUT",message:re},{status:Q}),ee))},oe)});return await Promise.race([D,v])}finally{if(k!==void 0)clearTimeout(k)}}}let i=e.length,u=e.find((A)=>A?.__responseFilter)?.__responseFilter,c=e.find((A)=>A?.__idempotencyCommit),f=c?.__idempotencyCommit,d=c?.__idempotencyRelease,m={status:200,headers:{"content-type":"application/json"}},y={status:200,headers:{"content-type":"text/plain"}},p=t?"if (!ctx._detached) doLog(res.status);":"",h=t?"if (!ctx._detached) doLog(finalStatus);":"",x=`
127
+ if (ctx._headers) {
128
+ for (const k in ctx._headers) {
129
+ const val = ctx._headers[k];
130
+ if (val === undefined) continue;
131
+ if (!res.headers.has(k)) {
132
+ try { res.headers.set(k, val); } catch {}
133
+ } else if (k.toLowerCase() === 'vary') {
134
+ const existing = res.headers.get('vary') || '';
135
+ const parts = existing.toLowerCase().split(',').map((v) => v.trim());
136
+ const toAdd = val.split(',').map((v) => v.trim()).filter((v) => v && !parts.includes(v.toLowerCase()));
137
+ if (toAdd.length > 0) {
138
+ try { res.headers.set('vary', existing ? \`\${existing}, \${toAdd.join(', ')}\` : toAdd.join(', ')); } catch {}
139
+ }
84
140
  }
85
141
  }
86
- if (ctx._setCookies) {
87
- for (let i = 0; i < ctx._setCookies.length; i++) res.headers.append('Set-Cookie', ctx._setCookies[i]);
142
+ }
143
+ if (ctx._setCookies) {
144
+ for (let i = 0; i < ctx._setCookies.length; i++) {
145
+ try { res.headers.append('Set-Cookie', ctx._setCookies[i]); } catch {}
88
146
  }
89
- ${t?"doLog(res.status);":""}
90
- return res;
91
147
  }
92
-
93
- const finalStatus = ctx._status || 200;
94
- ${c?"idemCommit(ctx, res, finalStatus);":""}
95
- ${t?"doLog(finalStatus);":""}
96
-
148
+ ${p}
149
+ return res;
150
+ `,R=`
151
+ ${h}
97
152
  let outRes;
98
153
  if (typeof res === 'string') {
99
154
  if (finalStatus === 200 && !ctx._headers) {
@@ -119,75 +174,123 @@ var{defineProperty:ks,getOwnPropertyNames:yu,getOwnPropertyDescriptor:gu}=Object
119
174
  }
120
175
 
121
176
  if (ctx._setCookies) {
122
- for (let i = 0; i < ctx._setCookies.length; i++) outRes.headers.append('Set-Cookie', ctx._setCookies[i]);
177
+ for (let i = 0; i < ctx._setCookies.length; i++) {
178
+ try { outRes.headers.append('Set-Cookie', ctx._setCookies[i]); } catch {}
179
+ }
123
180
  }
124
181
  return outRes;
125
- `,B=t?"ctx, doLog":"ctx",q=[...a?["rFilter"]:[],...c?["idemCommit"]:[],...d?["idemRelease"]:[]],Ce=[...a?[a]:[],...c?[c]:[],...d?[d]:[]],rt=(_)=>{if(!d)return _;return(U,j)=>{try{let N=_(U,j);if(N&&typeof N.then==="function")return N.then((G)=>G,(G)=>{throw d(U),G});return N}catch(N){throw d(U),N}}};if(s===1){let _=e[0];if(_.constructor.name==="AsyncFunction")return rt(Function("fn0","json200","text200",...q,`let lastHdrs = null, lastInit200 = null; return async function(${B}) {
126
- const res = await fn0(ctx);
127
- ${O}
128
- }`)(_,f,l,...Ce));return rt(Function("fn0","json200","text200",...q,`let lastHdrs = null, lastInit200 = null; return function(${B}) {
129
- const res = fn0(ctx);
130
- if (res && res.then) return res.then(v => { const res = v; ${O} });
131
- ${O}
132
- }`)(_,f,l,...Ce))}let Be=e.some((_)=>_.constructor.name==="AsyncFunction"),me="",Ae=e.map((_,U)=>`fn${U}`);if(Be){for(let _=0;_<s-1;_++)me+=`let r${_} = fn${_}(ctx, noop);
133
- `,me+=`if (r${_}) {
134
- `,me+=` if (r${_}.then) r${_} = await r${_};
135
- `,me+=` if (r${_} instanceof Response) { ${t?"doLog(r"+_+".status);":""} return r${_}; }
136
- `,me+=`}
137
- `;me+=`
138
- let res = fn${s-1}(ctx);
182
+ `,w=`
183
+ ${u?"res = rFilter(res);":""}
184
+ if (res instanceof Response) {
185
+ ${f?"const ic = idemCommit(ctx, res, res.status); if (ic && ic.then) return ic.then(() => { "+x+" });":""}
186
+ ${x}
187
+ }
188
+
189
+ const finalStatus = ctx._status || 200;
190
+ ${f?"const ic = idemCommit(ctx, res, finalStatus); if (ic && ic.then) return ic.then(() => { "+R+" });":""}
191
+ ${R}
192
+ `,P=t?"ctx, doLog":"ctx",C=()=>{},J=["applyShortCircuit","noop",...u?["rFilter"]:[],...f?["idemCommit"]:[],...d?["idemRelease"]:[]],z=[r,C,...u?[u]:[],...f?[f]:[],...d?[d]:[]],L=(A)=>{if(!d)return A;return(oe,Q)=>{try{let re=A(oe,Q);if(re&&typeof re.then==="function")return re.then((ie)=>ie,(ie)=>{throw d(oe),ie});return re}catch(re){throw d(oe),re}}};if(i===1){let A=e[0];if(A.constructor.name==="AsyncFunction")return L(Function("fn0","json200","text200",...J,`let lastHdrs = null, lastInit200 = null; return async function(${P}) {
193
+ const res = await fn0(ctx, noop);
194
+ ${w}
195
+ }`)(A,m,y,...z));return L(Function("fn0","json200","text200",...J,`let lastHdrs = null, lastInit200 = null; return function(${P}) {
196
+ const res = fn0(ctx, noop);
197
+ if (res && res.then) return res.then(v => { const res = v; ${w} });
198
+ ${w}
199
+ }`)(A,m,y,...z))}let T=e.some((A)=>A.constructor.name==="AsyncFunction"),B="",Z=e.map((A,oe)=>`fn${oe}`),W="";if(T){for(let A=0;A<i-1;A++)B+=`let r${A} = fn${A}(ctx, noop);
200
+ `,B+=`if (r${A}) {
201
+ `,B+=` if (r${A}.then) r${A} = await r${A};
202
+ `,B+=` if (r${A} instanceof Response) { applyShortCircuit(r${A}, ctx); ${t?"if (!ctx._detached) doLog(r"+A+".status);":""} return r${A}; }
203
+ `,B+=`}
204
+ `;B+=`
205
+ let res = fn${i-1}(ctx, noop);
139
206
  if (res && res.then) res = await res;
140
- ${O}
141
- `}else{for(let _=0;_<s-1;_++)me+=`const r${_} = fn${_}(ctx, noop);
142
- `,me+=`if (r${_} && r${_} instanceof Response) { ${t?"doLog(r"+_+".status);":""} return r${_}; }
143
- `;me+=`
144
- let res = fn${s-1}(ctx);
145
- if (res && res.then) return res.then(v => { let res = v; ${O} });
146
- ${O}
147
- `}let M=()=>{},k=Be?`let lastHdrs = null, lastInit200 = null; return async function(${B})`:`let lastHdrs = null, lastInit200 = null; return function(${B})`;return rt(Function(...Ae,"noop","json200","text200",...q,`${k} { ${me} }`)(...e,M,f,l,...Ce))}compile(){let e=this._useLog;this.tree=new cn;for(let E of this.routes)this.tree.insert(E.path,E.method,this.compileHandler(E.handlers,e));let t=this.tree,r=this.pool,n=r.length,o=this.notFoundHandler,s=this.errorHandler,i=(E,v)=>{if(v._headers)for(let z in v._headers){let Me=v._headers[z];if(Me!==void 0&&!E.headers.has(z))try{E.headers.set(z,Me)}catch{}}if(v._setCookies)for(let z=0;z<v._setCookies.length;z++)try{E.headers.append("Set-Cookie",v._setCookies[z])}catch{}return E},a=(E,v)=>{if(E instanceof Response)return i(E,v);let z=v._status>=400?v._status:500;if(typeof E==="string")return i(new Response(E,{status:z}),v);return i(Response.json(E??null,{status:z}),v)},u=(E,v)=>{if(s){let z=s(E,v);if(z&&typeof z.then==="function")return z.then((Me)=>a(Me,v));return a(z,v)}if(E?.status>=400&&E?.status<500)return i(Response.json({status:E.status,message:E.message||"Bad Request"},{status:E.status}),v);return i(Response.json({status:500,message:E?.message||"Internal Server Error",stack:E?.stack},{status:500}),v)},c=[],d=(E)=>{let v=`h${c.length}`;return c.push(E),v},f=t.jitCompile(d),l=Object.freeze({}),y=c.map((E,v)=>`h${v}`),b=this.routes.some((E)=>E.handlers.some((v)=>v?.__idempotencyCommit)),q=`
148
- if (ctx.store.size > 0) ctx.store.clear();
149
- ${this._hasDerive?"if (ctx._derivedKeys) { for (let i = 0; i < ctx._derivedKeys.length; i++) delete ctx[ctx._derivedKeys[i]]; ctx._derivedKeys = undefined; }":""}
150
- ${b?"if (ctx._idempotencyKey) { ctx._idemInFlight.delete(ctx._idempotencyKey); ctx._idempotencyKey = undefined; ctx._idemInFlight = undefined; }":""}
151
- ctx.req = undefined;
152
- ctx._status = 200;
153
- ctx.body = undefined;
154
- ctx._query = undefined;
155
- ctx._cookies = undefined;
156
- ctx._setCookies = undefined;
157
- ctx._headers = undefined;
158
- ctx._requestId = undefined;
159
- ctx._peerIp = undefined;
160
- ctx.params = EMPTY_PARAMS;
161
- if (poolTop < maxPool) pool[poolTop++] = ctx;
162
- `,Ce=`const errRes = hError(e, ctx);
163
- if (errRes && errRes.then) return errRes.then((r) => { ${e?"doLog(r.status || 500);":""} ${q} return r; });
207
+ ${w}
208
+ `}else{W=`
209
+ const fns = [${Z.join(", ")}];
210
+ const continueAsync = async (${t?"idx, pending, ctx, doLog":"idx, pending, ctx"}) => {
211
+ let r = await pending;
212
+ if (r instanceof Response) { applyShortCircuit(r, ctx); ${t?"if (!ctx._detached) doLog(r.status);":""} return r; }
213
+ for (let i = idx + 1; i < fns.length - 1; i++) {
214
+ r = fns[i](ctx, noop);
215
+ if (r) {
216
+ if (typeof r.then === 'function') r = await r;
217
+ if (r instanceof Response) { applyShortCircuit(r, ctx); ${t?"if (!ctx._detached) doLog(r.status);":""} return r; }
218
+ }
219
+ }
220
+ let res = fns[fns.length - 1](ctx, noop);
221
+ if (res && typeof res.then === 'function') res = await res;
222
+ ${w}
223
+ };
224
+ `;for(let A=0;A<i-1;A++)B+=`const r${A} = fn${A}(ctx, noop);
225
+ `,B+=`if (r${A}) {
226
+ `,B+=` if (r${A} instanceof Response) { applyShortCircuit(r${A}, ctx); ${t?"if (!ctx._detached) doLog(r"+A+".status);":""} return r${A}; }
227
+ `,B+=` if (typeof r${A}.then === 'function') return continueAsync(${A}, r${A}, ${P});
228
+ `,B+=`}
229
+ `;B+=`
230
+ let res = fn${i-1}(ctx, noop);
231
+ if (res && res.then) return res.then(v => { let res = v; ${w} });
232
+ ${w}
233
+ `}let q=T?`let lastHdrs = null, lastInit200 = null; return async function(${P})`:`let lastHdrs = null, lastInit200 = null; ${W} return function(${P})`;return L(Function(...Z,"json200","text200",...J,`${q} { ${B} }`)(...e,m,y,...z))}compile(){let e=this._useLog;this.tree=new bn;let t=new Set;for(let k of this.routes){if(k.method==="OPTIONS")t.add(k.path);this.tree.insert(k.path,k.method,this.compileHandler(k.handlers,e))}for(let k of this.routes){if(k.method==="OPTIONS"||t.has(k.path))continue;let v=-1;for(let G=k.handlers.length-1;G>=0;G--)if(k.handlers[G]?.__isCors&&!this.groupMiddleware.includes(k.handlers[G])){v=G;break}if(v!==-1){t.add(k.path);let G=[...k.handlers.slice(0,v+1).filter((we,Ce)=>Ce===v||!we?.__isCors),()=>new Response(null,{status:204})];this.tree.insert(k.path,"OPTIONS",this.compileHandler(G,e))}}let r=this.tree,n=this.pool,o=n.length,s=this.notFoundHandler,i=this.errorHandler,a=(k,v)=>{if(v._headers)for(let G in v._headers){let we=v._headers[G];if(we===void 0)continue;if(!k.headers.has(G))try{k.headers.set(G,we)}catch{}else if(G.toLowerCase()==="vary"){let Ce=k.headers.get("vary")||"",At=Ce.toLowerCase().split(",").map((ct)=>ct.trim()),Lt=we.split(",").map((ct)=>ct.trim()).filter((ct)=>ct&&!At.includes(ct.toLowerCase()));if(Lt.length>0)try{k.headers.set("vary",Ce?`${Ce}, ${Lt.join(", ")}`:Lt.join(", "))}catch{}}}if(v._setCookies)for(let G=0;G<v._setCookies.length;G++)try{k.headers.append("Set-Cookie",v._setCookies[G])}catch{}return k},u=(k,v)=>{if(k instanceof Response)return a(k,v);let G=v._status>=400?v._status:500;if(typeof k==="string")return a(new Response(k,{status:G}),v);return a(Response.json(k??null,{status:G}),v)},c=(k,v)=>{if(k?.status>=400&&k?.status<500)return a(Response.json({status:k.status,message:k.message||"Bad Request"},{status:k.status}),v);return a(Response.json({status:500,message:k?.message||"Internal Server Error",stack:k?.stack},{status:500}),v)},f=(k,v)=>{if(i)try{let G=i(k,v);if(G&&typeof G.then==="function")return G.then((we)=>u(we,v),(we)=>c(we,v));return u(G,v)}catch(G){return c(G,v)}return c(k,v)},d=[],m=(k)=>{let v=`h${d.length}`;return d.push(k),v},y=Object.freeze({}),p=this.routes.some((k)=>k.handlers.some((v)=>v?.__idempotencyCommit))||this.groupMiddleware.some((k)=>k?.__idempotencyCommit),w=`
234
+ if (!ctx._detached) {
235
+ if (ctx.store.size > 0) ctx.store.clear();
236
+ ${this._hasDerive||this.routes.some((k)=>k.handlers.some((v)=>v?.__isDerive))?"if (ctx._derivedKeys) { for (let i = 0; i < ctx._derivedKeys.length; i++) delete ctx[ctx._derivedKeys[i]]; ctx._derivedKeys = undefined; }":""}
237
+ ${p?"if (ctx._idempotencyKey) { if (ctx._idemInFlight) ctx._idemInFlight.delete(ctx._idempotencyKey); ctx._idempotencyKey = undefined; ctx._idemInFlight = undefined; }":""}
238
+ ctx.req = undefined;
239
+ ctx._status = 200;
240
+ ctx.body = undefined;
241
+ ctx._query = undefined;
242
+ ctx._cookies = undefined;
243
+ ctx._setCookies = undefined;
244
+ ctx._headers = undefined;
245
+ ctx._requestId = undefined;
246
+ ctx._peerIp = undefined;
247
+ ctx.params = EMPTY_PARAMS;
248
+ if (poolTop < maxPool) pool[poolTop++] = ctx;
249
+ }
250
+ `,P=`const errRes = hError(e, ctx);
251
+ if (errRes && errRes.then) return errRes.then((r) => { ${e?"doLog(r.status || 500);":""} ${w} return r; });
164
252
  ${e?"doLog(errRes.status || 500);":""}
165
- ${q}
166
- return errRes;`,rt=e?"(ctx, doLog)":"(ctx)",Be=f.replace(/return (h\d+)\(ctx\);/g,`out = $1${rt};
167
- if (out && out.then) return out.then((v) => { ${q} return v; }, (e) => { ${Ce} });
168
- ${q}
169
- return out;`),me=this.groupMiddleware.length>0,Ae=me?this.compileHandler(this.groupMiddleware,e):void 0,M=me?`if (method === 'OPTIONS') {
170
- out = hOptions${rt};
171
- if (out && out.then) return out.then((v) => { ${q} return v; }, (e) => { ${Ce} });
172
- ${q}
173
- return out;
174
- }`:"",k=this.groupMiddleware.some((E)=>E.__isStatic),_=k?async(E)=>{let v=this.groupMiddleware,z=async(Me)=>{if(Me>=v.length)return;let je=await v[Me](E,()=>z(Me+1));if(je instanceof Response)return i(je,E);return};return z(0)}:void 0,U=k?`if (method === 'GET' || method === 'HEAD') {
253
+ ${w}
254
+ return errRes;`,C=e?"(ctx, doLog)":"(ctx)",J=this.routes.length>16,z=r.jitCompile(m,0,"url","s",[],(k)=>J?`out = ${k}${C};
255
+ if (out && out.then) return out.then((v) => { _rel(ctx); return v; }, (e) => _onErr(e, ctx${e?", doLog":""}));
256
+ _rel(ctx);
257
+ return out;`:`out = ${k}${C};
258
+ if (out && out.then) return out.then((v) => { ${w} return v; }, (e) => { ${P} });
259
+ ${w}
260
+ return out;`),L=d.map((k,v)=>`h${v}`),T=this.groupMiddleware.length>0,B=T?async(k)=>{let v=this.groupMiddleware,G=async(we)=>{if(we>=v.length)return;let Ce=!1,At,Lt=await v[we](k,()=>(Ce=!0,G(we+1).then((ct)=>(At=ct,ct))));if(Lt instanceof Response)return a(Lt,k);if(At instanceof Response)return At;if(!Ce)return G(we+1);return};return G(0)}:void 0,Z=T?`if (method === 'OPTIONS') {
261
+ out = runGlobalOptions(ctx);
262
+ if (out && out.then) {
263
+ return out.then((v) => {
264
+ if (v instanceof Response) { ${e?"doLog(v.status);":""} ${w} return v; }
265
+ const errorBody = hNotFound();
266
+ const status = errorBody.status || 404;
267
+ const nfRes = applyCtxHeaders(Response.json(errorBody, { status }), ctx);
268
+ ${e?"doLog(status);":""}
269
+ ${w}
270
+ return nfRes;
271
+ }, (e) => {
272
+ ${P}
273
+ });
274
+ }
275
+ }`:"",W=this.groupMiddleware.some((k)=>k.__isStatic),q=W?async(k)=>{let v=this.groupMiddleware,G=async(we)=>{if(we>=v.length)return;let Ce=!1,At,Lt=await v[we](k,()=>(Ce=!0,G(we+1).then((ct)=>(At=ct,ct))));if(Lt instanceof Response)return a(Lt,k);if(At instanceof Response)return At;if(!Ce)return G(we+1);return};return G(0)}:void 0,A=W?`if (method === 'GET' || method === 'HEAD') {
175
276
  out = runStatic(ctx);
176
277
  if (out && out.then) {
177
278
  return out.then((v) => {
178
- if (v instanceof Response) { ${e?"doLog(v.status);":""} ${q} return v; }
279
+ if (v instanceof Response) { ${e?"doLog(v.status);":""} ${w} return v; }
179
280
  const errorBody = hNotFound();
180
281
  const status = errorBody.status || 404;
181
282
  const nfRes = applyCtxHeaders(Response.json(errorBody, { status }), ctx);
182
283
  ${e?"doLog(status);":""}
183
- ${q}
284
+ ${w}
184
285
  return nfRes;
185
286
  }, (e) => {
186
- ${Ce}
287
+ ${P}
187
288
  });
188
289
  }
189
- }`:"",j=this._trustProxy,N=["pool","maxPool","Context","hNotFound","hError","applyCtxHeaders","EMPTY_PARAMS","trustProxyVal",...me?["hOptions"]:[],...k?["runStatic"]:[],...y],G=[r,n,Oo,o,u,i,l,j,...me?[Ae]:[],...k?[_]:[],...c],Te=`
190
- let poolTop = maxPool;
290
+ }`:"",oe=this.groupMiddleware.filter((k)=>k?.__isCors),Q=oe.length>0?(k,v)=>{for(let G=0;G<oe.length;G++)try{oe[G](v,()=>k)}catch{}return a(k,v)}:void 0,re=this._trustProxyBox,ie=["pool","maxPool","Context","hNotFound","hError","applyCtxHeaders","EMPTY_PARAMS","trustProxyBox",...T?["runGlobalOptions"]:[],...W?["runStatic"]:[],...Q?["apply404Cors"]:[],...L],ge=[n,o,jo,s,f,a,y,re,...T?[B]:[],...W?[q]:[],...Q?[Q]:[],...d],ee=e?"\n const start = performance.now();\n const doLog = (status) => {\n const duration = (performance.now() - start).toFixed(3);\n console.log(\n ` \\x1b[90m${new Date().toLocaleTimeString()}\\x1b[0m ` +\n `\\x1b[1m\\x1b[38;5;117m${method.padEnd(7)}\\x1b[0m ` +\n `\\x1b[38;5;250m${url.substring(url.indexOf('/', 8))}\\x1b[0m ` +\n `${status >= 400 ? '\\x1b[33m' : '\\x1b[32m'}${status}\\x1b[0m ` +\n `\\x1b[90m(${duration}ms)\\x1b[0m`\n );\n };":"",D=`
291
+ let poolTop = maxPool;${J?`
292
+ const _rel = (ctx) => { ${w} };
293
+ const _onErr = (e, ctx${e?", doLog":""}) => { ${P} };`:""}
191
294
  return function(req, peerIp) {
192
295
  const url = req.url;
193
296
  let s = url.indexOf('/', 8);
@@ -197,32 +300,32 @@ var{defineProperty:ks,getOwnPropertyNames:yu,getOwnPropertyDescriptor:gu}=Object
197
300
  else s = urlLen;
198
301
 
199
302
  const method = req.method;
200
- const ctx = poolTop > 0 ? pool[--poolTop] : new Context(trustProxyVal);
303
+ const ctx = poolTop > 0 ? pool[--poolTop] : new Context(trustProxyBox.val);
201
304
  let out;
202
- ${e?"\n const start = performance.now();\n const doLog = (status) => {\n const duration = (performance.now() - start).toFixed(3);\n console.log(\n ` \\x1b[90m${new Date().toLocaleTimeString()}\\x1b[0m ` +\n `\\x1b[1m\\x1b[38;5;117m${method.padEnd(7)}\\x1b[0m ` +\n `\\x1b[38;5;250m${url.substring(url.indexOf('/', 8))}\\x1b[0m ` +\n `${status >= 400 ? '\\x1b[33m' : '\\x1b[32m'}${status}\\x1b[0m ` +\n `\\x1b[90m(${duration}ms)\\x1b[0m`\n );\n };":""}
305
+ ${ee}
203
306
 
204
307
  try {
205
308
  ctx.req = req;
206
309
  ctx._peerIp = peerIp;
207
310
 
208
- ${Be}
311
+ ${z}
209
312
 
210
- ${M}
313
+ ${Z}
211
314
 
212
- ${U}
315
+ ${A}
213
316
 
214
317
  const errorBody = hNotFound();
215
318
  const status = errorBody.status || 404;
216
- const nfRes = applyCtxHeaders(Response.json(errorBody, { status }), ctx);
319
+ const nfRes = ${Q?"apply404Cors(Response.json(errorBody, { status }), ctx)":"applyCtxHeaders(Response.json(errorBody, { status }), ctx)"};
217
320
  ${e?"doLog(status);":""}
218
- ${q}
321
+ ${w}
219
322
  return nfRes;
220
323
 
221
324
  } catch (e) {
222
- ${Ce}
325
+ ${P}
223
326
  }
224
327
  }
225
- `;this.hotFetch=Function(...N,Te)(...G),this.compiled=!0,this.fetch=this.hotFetch}fetch=(e,t)=>{if(!this.compiled)return this.compile(),this.hotFetch(e,t);return this.hotFetch(e,t)};async request(e,t){let r;if(e.startsWith("http://")||e.startsWith("https://"))r=e;else r=`http://localhost${e.startsWith("/")?e:`/${e}`}`;return this.fetch(new Request(r,t))}name="App";trustProxy(e=!0){this._trustProxy=e;for(let t=0;t<this.pool.length;t++)this.pool[t]._trustProxy=e;return this}listen(e,t="0.0.0.0",r=!0,n={}){if(!this.compiled)this.compile();if(n.trustProxy!==void 0)this.trustProxy(n.trustProxy);let o=n.maxRequestBodySize??10485760,{BARE_CONFIG:s}=(Rs(),Iu(eu)),i=e||s.port||3000;if(!0)console.log(`
328
+ `;this.hotFetch=Function(...ie,D)(...ge),this.compiled=!0,this.fetch=this.hotFetch}fetch=(e,t)=>{if(!this.compiled)return this.compile(),this.hotFetch(e,t);return this.hotFetch(e,t)};async request(e,t){let r;if(e.startsWith("http://")||e.startsWith("https://"))r=e;else r=`http://localhost${e.startsWith("/")?e:`/${e}`}`;return this.fetch(new Request(r,t))}name="App";trustProxy(e=!0){this._trustProxyBox.val=e;for(let t=0;t<this.pool.length;t++)this.pool[t]._trustProxy=e;return this}listen(e,t="0.0.0.0",r=!0,n={}){if(n.trustProxy!==void 0)this.trustProxy(n.trustProxy);if(!this.compiled)this.compile();let o=n.maxRequestBodySize??10485760,s=e??Et.port??3000;if(!0)console.log(`
226
329
  \x1B[33m ____ _ _____ \x1B[0m
227
330
  \x1B[33m | __ ) __ _ _ __ ___ | | ____|\x1B[0m
228
331
  \x1B[33m | _ \\ / _\` | '__/ _ \\ _ | | _| \x1B[0m
@@ -230,9 +333,9 @@ var{defineProperty:ks,getOwnPropertyNames:yu,getOwnPropertyDescriptor:gu}=Object
230
333
  \x1B[33m |____/ \\__,_|_| \\___| \\___/|_____|\x1B[0m
231
334
 
232
335
  \x1B[32m\uD83D\uDE80 ${this.name} is running in development mode\x1B[0m
233
- \x1B[90m\u2699\uFE0F Pool Size: ${this.pool.length} | JIT: Enabled | Port: ${i}\x1B[0m
234
- \x1B[36m\uD83D\uDEE1\uFE0F Hash: ${s.hash.algorithm} (${s.hash.memoryCost/1024}MB) | Iterations: ${s.hash.timeCost}\x1B[0m
235
- `);let u=this.wsRoutes,c=this.fetch,f=u.size>0?Bun.serve({port:i,hostname:t,reusePort:r,maxRequestBodySize:o,fetch(y,b){if(y.headers.get("upgrade")?.toLowerCase()==="websocket"){let O=y.url,B=O.indexOf("/",8),q=B===-1?-1:O.indexOf("?",B),Ce=B===-1?"/":q===-1?O.slice(B):O.slice(B,q),rt=Ce.length>1&&Ce.endsWith("/")?Ce.slice(0,-1):Ce,Be=u.get(rt),me;if(!Be){let Ae=rt.split("/").filter(Boolean);for(let[M,k]of u){if(!M.includes(":")&&!M.includes("*"))continue;let _=M.split("/").filter(Boolean),U={},j=!0;for(let N=0;N<_.length;N++){let G=_[N];if(G==="*"){U["*"]=Ae.slice(N).join("/");break}if(N>=Ae.length){j=!1;break}if(G.startsWith(":"))U[G.slice(1)]=Ae[N];else if(G!==Ae[N]){j=!1;break}}if(j&&(_.includes("*")||_.length===Ae.length)){Be=k,me=U;break}}}if(Be&&b.upgrade(y,{data:me?{...Be,params:me}:Be}))return}return c(y,b?.requestIP?.(y)?.address)},websocket:this.wsAdapter}):Bun.serve({port:i,hostname:t,reusePort:r,maxRequestBodySize:o,fetch(y,b){return c(y,b?.requestIP?.(y)?.address)}});this.server=f;for(let y of this.startHooks)Promise.resolve(y()).catch((b)=>console.error(`[${this.name}] onStart error:`,b));let l=async()=>{let b=this.name,O=process.stdout.isTTY;{let B=O?"\uD83D\uDED1":"!",q=O?"\u2705":"v";process.stdout.write(`
236
- \x1B[31m${B} Stopping ${b}...\x1B[0m
237
- `),await this.stop(!1),process.stdout.write(`\x1B[32m${q} ${b} has been stopped.\x1B[0m
238
- `)}process.exit(0)};return this.shutdownHandler=l,process.on("SIGINT",l),process.on("SIGTERM",l),f}}var Kh=(e)=>{let t=e.indexOf("/",8);if(t===-1)return"/";let r=e.indexOf("?",t);return r===-1?e.slice(t):e.slice(t,r)},Bh=(e={})=>{let t=e.format??"pretty",r=e.requestId??!0,{skip:n,onLog:o}=e;return(s,i)=>{let a=Kh(s.req.url);if(n?.(s,a))return i();let u=r?s.requestId:void 0;if(u)s.setHeader("x-request-id",u);let c={timestamp:new Date().toISOString(),method:s.req.method,path:a,...u?{requestId:u}:{},ip:s.ip};if(o)o(c);else if(t==="json")console.log(JSON.stringify(c));else{let d=u?` [${u.slice(0,8)}]`:"";console.log(`[${c.timestamp}] ${c.method} ${c.path}${d}`)}return i()}};var vh=(e={})=>{let t=e.path??"/health",{readyPath:r,checks:n}=e,o=Date.now(),s=async()=>{let i={},a=!0;if(n){let c=Object.entries(n);await Promise.all(c.map(async([d,f])=>{try{let l=await f();if(i[d]=l?"ok":"fail",!l)a=!1}catch{i[d]="fail",a=!1}}))}let u={status:a?"ok":"degraded",uptimeMs:Date.now()-o,timestamp:new Date().toISOString()};if(e.version)u.version=e.version;if(n)u.checks=i;return Response.json(u,{status:a?200:503})};return{install(i){if(i.get(t,s),r&&r!==t)i.get(r,s)}}};var Dh=(e={})=>{let t=e.origin||"*",r=e.methods||"GET,POST,PUT,PATCH,DELETE,OPTIONS",n=Array.isArray(e.allowedHeaders)?e.allowedHeaders.join(", "):e.allowedHeaders||"Content-Type, Authorization",o=Array.isArray(e.exposedHeaders)?e.exposedHeaders.join(", "):e.exposedHeaders,s=e.credentials===!0;if(typeof t==="string"){let c={"Access-Control-Allow-Origin":t,"Access-Control-Allow-Methods":r,"Access-Control-Allow-Headers":n};if(t!=="*")c.Vary="Origin";if(s)c["Access-Control-Allow-Credentials"]="true";let d={status:204,headers:c};return(l,y)=>{if(l.req.method==="OPTIONS")return new Response(null,d);if(l.setHeader("Access-Control-Allow-Origin",t),l.setHeader("Access-Control-Allow-Methods",r),t!=="*")l.setHeader("Vary","Origin");if(s)l.setHeader("Access-Control-Allow-Credentials","true");if(o)l.setHeader("Access-Control-Expose-Headers",o);let b=y?.();if(b&&typeof b.then==="function")return b.then((O)=>{if(O instanceof Response){if(O.headers.set("Access-Control-Allow-Origin",t),O.headers.set("Access-Control-Allow-Methods",r),t!=="*")O.headers.set("Vary","Origin");if(s)O.headers.set("Access-Control-Allow-Credentials","true");if(o)O.headers.set("Access-Control-Expose-Headers",o)}return O});if(b instanceof Response){if(b.headers.set("Access-Control-Allow-Origin",t),b.headers.set("Access-Control-Allow-Methods",r),t!=="*")b.headers.set("Vary","Origin");if(s)b.headers.set("Access-Control-Allow-Credentials","true");if(o)b.headers.set("Access-Control-Expose-Headers",o)}return b}}let i=Array.isArray(t)?new Set(t):null,a=(c)=>{if(!c)return null;if(i)return i.has(c)?c:null;return t(c)?c:null};return(c,d)=>{let f=a(c.req.headers.get("origin"));if(c.req.method==="OPTIONS"){let y={"Access-Control-Allow-Methods":r,"Access-Control-Allow-Headers":n,Vary:"Origin"};if(f)y["Access-Control-Allow-Origin"]=f;if(s&&f)y["Access-Control-Allow-Credentials"]="true";return new Response(null,{status:204,headers:y})}if(c.setHeader("Vary","Origin"),c.setHeader("Access-Control-Allow-Methods",r),f){if(c.setHeader("Access-Control-Allow-Origin",f),s)c.setHeader("Access-Control-Allow-Credentials","true")}if(o)c.setHeader("Access-Control-Expose-Headers",o);let l=d?.();if(l&&typeof l.then==="function")return l.then((y)=>{if(y instanceof Response){if(y.headers.set("Vary","Origin"),y.headers.set("Access-Control-Allow-Methods",r),f){if(y.headers.set("Access-Control-Allow-Origin",f),s)y.headers.set("Access-Control-Allow-Credentials","true")}if(o)y.headers.set("Access-Control-Expose-Headers",o)}return y});if(l instanceof Response){if(l.headers.set("Vary","Origin"),l.headers.set("Access-Control-Allow-Methods",r),f){if(l.headers.set("Access-Control-Allow-Origin",f),s)l.headers.set("Access-Control-Allow-Credentials","true")}if(o)l.headers.set("Access-Control-Expose-Headers",o)}return l}};import{timingSafeEqual as qh}from"crypto";var Gh=new Set(["GET","HEAD","OPTIONS"]),Hh=(e={})=>{let t=e.ignoreMethods?new Set(e.ignoreMethods.map((i)=>i.toUpperCase())):Gh,r=e.allowedOrigins?new Set(e.allowedOrigins):null,n=e.cookieName||"csrf_token",o=(e.headerName||"x-csrf-token").toLowerCase(),s=e.requireToken===!0;return(i,a)=>{let u=i.req.method.toUpperCase();if(t.has(u))return a();let c=i.req.headers.get("sec-fetch-site"),d=i.req.headers.get("origin"),f=i.req.headers.get("referer");if(c==="cross-site"){if(!r||!d||!r.has(d))return Response.json({status:"error",code:"CSRF_FORBIDDEN",message:"Cross-site request blocked"},{status:403})}let l=d;if(!l&&f)try{l=new URL(f).origin}catch{return Response.json({status:"error",code:"CSRF_FORBIDDEN",message:"Invalid Referer header"},{status:403})}if(l){let y;try{y=new URL(i.req.url).origin}catch{y=""}if(!(l===y||r!==null&&r.has(l)))return Response.json({status:"error",code:"CSRF_FORBIDDEN",message:"Origin mismatch"},{status:403})}if(s){let y=i.cookies[n],b=i.req.headers.get(o),O=!1;if(y&&b){let B=Buffer.from(y),q=Buffer.from(b);O=B.length===q.length&&qh(B,q)}if(!O)return Response.json({status:"error",code:"CSRF_TOKEN_INVALID",message:"Invalid or missing CSRF token"},{status:403})}return a()}};var zh=(e=1e4,t={})=>{let r=t.status??408,n=t.message??"Request Timeout",o=async(s,i)=>{let a;try{let u=new Promise((c)=>{a=setTimeout(()=>{c(Response.json({status:"error",code:"REQUEST_TIMEOUT",message:n},{status:r}))},e)});return await Promise.race([Promise.resolve(i()),u])}finally{if(a!==void 0)clearTimeout(a)}};return o.__timeout={ms:e,status:r,message:n},o};var Vh=(e={})=>{let t=e.windowMs??60000,r=e.max??100,n=e.message??"Too many requests, please try again later.",o=e.maxEntries??1e4,s=e.keyGenerator??((c)=>c.ip),i=e.store,a=(c,d,f,l,y)=>{let b=Math.max(0,r-d),O=String(Math.ceil(f/1000));if(c.setHeader("X-RateLimit-Limit",String(r)),c.setHeader("X-RateLimit-Remaining",String(b)),c.setHeader("X-RateLimit-Reset",O),d>r){let B=Math.max(1,Math.ceil((f-l)/1000));return Response.json({status:"error",code:"RATE_LIMITED",message:n},{status:429,headers:{"Retry-After":String(B),"X-RateLimit-Limit":String(r),"X-RateLimit-Remaining":"0","X-RateLimit-Reset":O}})}return y?.()};if(i)return async(c,d)=>{let f=Date.now(),l=s(c),{count:y,resetAt:b}=await i.increment(l,t);return a(c,y,b,f,d)};let u=new Map;return(c,d)=>{let f=Date.now(),l=s(c),y=u.get(l);if(!y||f>=y.resetAt){if(u.size>=o){for(let[b,O]of u){if(f>=O.resetAt)u.delete(b);if(u.size<o)break}if(u.size>=o){let b=u.keys().next().value;if(b!==void 0)u.delete(b)}}y={count:1,resetAt:f+t},u.set(l,y)}else y.count++;return a(c,y.count,y.resetAt,f,d)}};var nu=(e)=>{if(e.rawBody!==void 0)return new Response(e.rawBody,{status:e.status,headers:{"content-type":e.contentType||"application/json","X-Idempotent-Replayed":"true"}});return Response.json(e.body,{status:e.status,headers:{"X-Idempotent-Replayed":"true"}})},ou=(e,t)=>{let r=e.req.headers.get(t);if(!r)return;let n=e.req.url,o=n.indexOf("/",8),s=o===-1?-1:n.indexOf("?",o),i=o===-1?"/":s===-1?n.slice(o):n.slice(o,s);return`${e.req.method}:${i}:${r}`},Jh=(e={})=>{let t=(e.headerName||"idempotency-key").toLowerCase(),r=e.ttlMs??300000,n=e.maxKeys??1e4,o=e.store;if(o){let c={delete:(f)=>{o.release(f)}},d=async(f)=>{let l=ou(f,t);if(!l){f._idempotencyKey=void 0;return}let y=await o.get(l);if(y&&Date.now()<y.expiresAt)return f._idempotencyKey=void 0,nu(y);if(!await o.acquire(l,r))return f._idempotencyKey=void 0,Response.json({status:"error",code:"IDEMPOTENT_IN_FLIGHT",message:"Duplicate request is currently in flight"},{status:409});f._idempotencyKey=l,f._idemInFlight=c;return};return d.__idempotencyCommit=(f,l,y)=>{let b=f._idempotencyKey;if(!b)return;f._idempotencyKey=void 0,f._idemInFlight=void 0;let O=y>=200&&y<300&&l instanceof Response?l.clone():null,B=O?O.headers.get("content-type")||"application/json":void 0;(async()=>{try{if(y>=200&&y<300)if(O){let q=await O.arrayBuffer();await o.set(b,{status:y,rawBody:q,contentType:B,expiresAt:Date.now()+r},r)}else await o.set(b,{status:y,body:l,expiresAt:Date.now()+r},r)}catch{}finally{await o.release(b)}})()},d.__idempotencyRelease=(f)=>{let l=f._idempotencyKey;if(l)f._idempotencyKey=void 0,f._idemInFlight=void 0,o.release(l)},d}let s=new Map,i=new Set,a=()=>{if(s.size>=n){let c=s.keys().next().value;if(c!==void 0)s.delete(c)}},u=(c)=>{let d=ou(c,t);if(!d){c._idempotencyKey=void 0;return}let f=Date.now(),l=s.get(d);if(l){if(f<l.expiresAt)return c._idempotencyKey=void 0,nu(l);s.delete(d)}if(i.has(d))return c._idempotencyKey=void 0,Response.json({status:"error",code:"IDEMPOTENT_IN_FLIGHT",message:"Duplicate request is currently in flight"},{status:409});i.add(d),c._idempotencyKey=d,c._idemInFlight=i;return};return u.__idempotencyCommit=(c,d,f)=>{let l=c._idempotencyKey;if(!l)return;if(c._idempotencyKey=void 0,c._idemInFlight=void 0,i.delete(l),f>=200&&f<300)if(d instanceof Response){let y=d.headers.get("content-type")||"application/json";d.clone().arrayBuffer().then((b)=>{a(),s.set(l,{status:f,rawBody:b,contentType:y,expiresAt:Date.now()+r})}).catch(()=>{})}else a(),s.set(l,{status:f,body:d,expiresAt:Date.now()+r})},u.__idempotencyRelease=(c)=>{let d=c._idempotencyKey;if(d)c._idempotencyKey=void 0,c._idemInFlight=void 0,i.delete(d)},u},Wh=()=>{let e=new Map;return async(t,r)=>{let n=e.get(t);if(n)return{data:await n,shared:!0};let o=r().finally(()=>{e.delete(t)});return e.set(t,o),{data:await o,shared:!1}}};var Xh=(e,t={})=>{let r=t.prefix??"barejs:",n=typeof e.send==="function",o=(c)=>n?e.send("GET",[c]):e.get(c),s=(c)=>n?e.send("DEL",[c]):e.del(c),i=(c)=>n?e.send("INCR",[c]):e.incr(c),a=async(c,d,f)=>{if(n){await e.send("SET",[c,d,"PX",String(f)]);return}try{await e.set(c,d,"PX",f)}catch{if(await e.set(c,d),typeof e.pexpire==="function")await e.pexpire(c,f);else if(typeof e.expire==="function")await e.expire(c,Math.max(1,Math.ceil(f/1000)))}},u=async(c,d)=>{if(n)await e.send("PEXPIRE",[c,String(d)]);else if(typeof e.pexpire==="function")await e.pexpire(c,d);else if(typeof e.expire==="function")await e.expire(c,Math.max(1,Math.ceil(d/1000)))};return{async increment(c,d){let f=`${r}rl:${c}`,l=Number(await i(f));if(l===1)await u(f,d);let y=d,b=null;if(n)b=Number(await e.send("PTTL",[f]));else if(typeof e.pttl==="function")b=Number(await e.pttl(f));else if(typeof e.ttl==="function"){let O=Number(await e.ttl(f));b=O<0?O:O*1000}if(b===-1)await u(f,d);else if(b!==null&&Number.isFinite(b)&&b>0)y=b;return{count:l,resetAt:Date.now()+y}},async get(c){let d=await o(`${r}idem:${c}`);if(!d)return;try{let f=JSON.parse(typeof d==="string"?d:String(d));if(typeof f.rawBodyBase64==="string"){let l=Buffer.from(f.rawBodyBase64,"base64");return{status:f.status,rawBody:l.buffer.slice(l.byteOffset,l.byteOffset+l.byteLength),contentType:f.contentType,expiresAt:f.expiresAt}}return f}catch{return}},async set(c,d,f){let l={status:d.status,expiresAt:d.expiresAt};if(d.rawBody!==void 0)l.rawBodyBase64=Buffer.from(d.rawBody).toString("base64"),l.contentType=d.contentType;else l.body=d.body;await a(`${r}idem:${c}`,JSON.stringify(l),f)},async acquire(c,d=30000){let f=`${r}idem:lock:${c}`;if(n){let y=await e.send("SET",[f,"1","PX",String(d),"NX"]);return y==="OK"||y===!0}let l=await e.set(f,"1","PX",d,"NX");return l==="OK"||l===!0||l===1},async release(c){await s(`${r}idem:lock:${c}`)},async revoke(c,d){await a(`${r}rev:${c}`,"1",d)},async isRevoked(c){let d=await o(`${r}rev:${c}`);return d!==null&&d!==void 0}}};var Yh=(e={})=>{let t=e.failureThreshold??5,r=e.resetTimeoutMs??30000,n=e.isFailure??((f,l)=>Boolean(l)||f instanceof Response&&f.status>=500),o="CLOSED",s=0,i=0,a=!1,u=(f)=>{if(o!==f){let l=o;o=f,e.onStateChange?.(l,f)}},c=async(f)=>{if(o==="OPEN"){let y=Date.now()-i;if(y<r){let b=Math.max(1,Math.ceil((r-y)/1000));return Response.json({status:"error",code:"CIRCUIT_OPEN",message:"Service temporarily unavailable"},{status:503,headers:{"Retry-After":String(b)}})}u("HALF_OPEN")}let l=!1;if(o==="HALF_OPEN"){if(a)return Response.json({status:"error",code:"CIRCUIT_OPEN",message:"Service temporarily unavailable"},{status:503,headers:{"Retry-After":"1"}});a=!0,l=!0}try{let y=await f();if(n(y)){if(s++,l||s>=t)i=Date.now(),u("OPEN")}else if(s=0,l)u("CLOSED");return y}catch(y){if(s++,l||s>=t)i=Date.now(),u("OPEN");throw y}finally{if(l)a=!1}},d=(f,l)=>c(()=>l?l():void 0);return d.__circuitBreaker=c,d};var Qh=(e={})=>{let t=[];if(e.noSniff!==!1)t.push(["X-Content-Type-Options","nosniff"]);if(e.frameOptions!==!1)t.push(["X-Frame-Options",e.frameOptions??"DENY"]);if(e.referrerPolicy!==!1)t.push(["Referrer-Policy",e.referrerPolicy??"strict-origin-when-cross-origin"]);if(e.hsts!==!1)t.push(["Strict-Transport-Security",e.hsts??"max-age=31536000; includeSubDomains"]);if(e.contentSecurityPolicy)t.push(["Content-Security-Policy",e.contentSecurityPolicy]);t.push(["X-XSS-Protection","0"]);let r=t.length,n=Object.freeze((()=>{let o={};for(let s=0;s<r;s++){let i=t[s];o[i[0].toLowerCase()]=i[1]}return o})());return(o,s)=>{if(!o._headers)o._headers=n;else o._headers={...o._headers,...n};let i=s?.();if(i&&typeof i.then==="function")return i.then((a)=>{if(a instanceof Response)for(let u=0;u<r;u++){let c=t[u];if(!a.headers.has(c[0]))a.headers.set(c[0],c[1])}return a});if(i instanceof Response)for(let a=0;a<r;a++){let u=t[a];if(!i.headers.has(u[0]))i.headers.set(u[0],u[1])}return i}};import{resolve as su,sep as Os}from"path";import{stat as Zh,realpath as iu}from"fs/promises";var ex=(e="public",t={})=>{let r=su(process.cwd(),e),n=r.endsWith(Os)?r:r+Os,o=null,s=t.maxAge??3600,i=t.etag!==!1,a=t.cacheMetadata,u=Boolean(a),c=typeof a==="object"?a.maxEntries??1000:1000,d=typeof a==="object"?a.ttlMs??30000:30000,f=u?new Map:null,l=async(y,b)=>{let O=y.req.method;if(O!=="GET"&&O!=="HEAD")return b();let B=y.req.url,q=B.indexOf("/",8),Ce=q===-1?-1:B.indexOf("?",q),rt=q===-1?"":Ce===-1?B.slice(q):B.slice(q,Ce),Be;try{Be=decodeURIComponent(rt)}catch{return y.status(400).send("Bad Request")}if(Be.includes("\x00"))return y.status(400).send("Bad Request");let me=Be.replace(/^\/+/,""),Ae=su(r,me);if(Ae!==r&&!Ae.startsWith(n))return y.status(403).send("Forbidden");let M=Ae,k=0,_=0,U="",j=f?.get(Ae);if(j&&Date.now()<j.expiresAt)f.delete(Ae),f.set(Ae,j),M=j.realFile,k=j.fileSize,_=j.mtimeMs,U=j.etag;else try{let[Te,E]=await Promise.all([o??=iu(r),iu(Ae)]),v=Te.endsWith(Os)?Te:Te+Os;if(E!==Te&&!E.startsWith(v))return y.status(403).send("Forbidden");let z=await Zh(E);if(z.isDirectory())return b();if(M=E,k=z.size,_=Math.floor(z.mtimeMs),U=i?`W/"${k.toString(16)}-${_.toString(16)}"`:"",f){if(f.size>=c){let Me=f.keys().next().value;if(Me!==void 0)f.delete(Me)}f.set(Ae,{realFile:M,fileSize:k,mtimeMs:_,etag:U,expiresAt:Date.now()+d})}}catch{return b()}let N=Bun.file(M),G={"Cache-Control":`public, max-age=${s}`,"Accept-Ranges":"bytes"};if(i){G.ETag=U;let Te=y.req.headers?.get?.("if-none-match");if(Te&&Te===U)return new Response(null,{status:304,headers:G})}let Xe=y.req.headers?.get?.("range");if(Xe&&Xe.startsWith("bytes=")&&k>0){let[Te,E]=Xe.slice(6).split("-"),v=Te?Number(Te):0,z=E?Number(E):k-1;if(!Te&&E)v=Math.max(0,k-Number(E)),z=k-1;if(!Number.isInteger(v)||!Number.isInteger(z)||v<0||z>=k||v>z)return new Response(null,{status:416,headers:{...G,"Content-Range":`bytes */${k}`}});if(G["Content-Range"]=`bytes ${v}-${z}/${k}`,G["Content-Length"]=String(z-v+1),N.type)G["Content-Type"]=N.type;return new Response(O==="HEAD"?null:N.slice(v,z+1),{status:206,headers:G})}if(N.type)G["Content-Type"]=N.type;return G["Content-Length"]=String(k),new Response(O==="HEAD"?null:N,{status:200,headers:G})};return l.__isStatic=!0,l};import{brotliCompressSync as tx,constants as rx}from"zlib";var nx=(e={})=>{let t=e.minSize??1024,r=e.level??6,n=e.encodings??["zstd","br","gzip"],o=typeof Bun.zstdCompressSync==="function",s=(c,d)=>{let f=c.indexOf(d);if(f===-1)return!1;let l=c.indexOf(",",f),y=l===-1?c.slice(f):c.slice(f,l),b=y.indexOf(";q=");if(b!==-1){let O=parseFloat(y.slice(b+3));if(Number.isFinite(O)&&O<=0)return!1}return!0},i=(c)=>{let d=c.toLowerCase();for(let f=0;f<n.length;f++){let l=n[f];if(l==="zstd"&&!o)continue;if(s(d,l))return l}return null},a=async(c,d)=>{if(c.req.method==="HEAD")return d;let f=c.req.headers.get("accept-encoding");if(!f)return d;let l=i(f);if(!l)return d;if(!(d instanceof Response))return d;if(d.status===204||d.status===304)return d;if(d.headers.has("content-encoding"))return d;if((d.headers.get("content-type")||"").includes("text/event-stream"))return d;let b=await d.arrayBuffer();if(b.byteLength<t)return new Response(b,{status:d.status,headers:d.headers});let O=new Uint8Array(b),B;if(l==="zstd")B=Bun.zstdCompressSync(O);else if(l==="br")B=tx(O,{params:{[rx.BROTLI_PARAM_QUALITY]:Math.min(11,Math.max(1,r))}});else B=Bun.gzipSync(O,{level:r});let q=new Headers(d.headers);return q.set("Content-Encoding",l),q.set("Vary","Accept-Encoding"),q.delete("Content-Length"),new Response(B,{status:d.status,headers:q})},u=async(c,d)=>{let f=await(d?d():void 0);return a(c,f)};return u.__compress=a,u};import{createHash as ox,createHmac as au,timingSafeEqual as Ss}from"crypto";var Ri=new TextEncoder,xi=(e)=>Buffer.from(e).toString("base64url"),ws=(e)=>Buffer.from(e,"base64url").toString("utf-8"),Ii=new Map,sx=async(e)=>{if(Ii.has(e))return Ii.get(e);let t=await crypto.subtle.importKey("raw",Ri.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"]);return Ii.set(e,t),t},ix=async(e,t)=>{let r=JSON.stringify({alg:"HS256",typ:"JWT"}),n=JSON.stringify(e),o=xi(r),s=xi(n),i=`${o}.${s}`,a=await sx(t),u=await crypto.subtle.sign("HMAC",a,Ri.encode(i)),c=xi(new Uint8Array(u));return`${i}.${c}`},xr=new Map;function ax(e,t=3600000,r){if(r)return r.revoke(e,t);if(xr.size>=1e4){let n=Date.now();for(let[o,s]of xr)if(n>=s)xr.delete(o);if(xr.size>=1e4){let o=xr.keys().next().value;if(o!==void 0)xr.delete(o)}}xr.set(e,Date.now()+t)}function bi(e,t){if(t)return t.isRevoked(e);let r=xr.get(e);if(r===void 0)return!1;if(Date.now()>=r)return xr.delete(e),!1;return!0}var cu=new Map,uu=(e)=>e==="RS256"?{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"}:{name:"ECDSA",namedCurve:"P-256"},cx=(e)=>e==="RS256"?{name:"RSASSA-PKCS1-v1_5"}:{name:"ECDSA",hash:"SHA-256"},ux=(e)=>{let t=e.replace(/-----BEGIN [A-Z0-9 ]+-----/g,"").replace(/-----END [A-Z0-9 ]+-----/g,"").replace(/\s+/g,""),r=Buffer.from(t,"base64");return r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)},dx=async(e,t)=>{if(typeof e!=="string")return e;let r=`${t}:${e}`,n=cu.get(r);if(n)return n;let o=await crypto.subtle.importKey("spki",ux(e),uu(t),!1,["verify"]);return cu.set(r,o),o},fx=(e)=>{let t=typeof e==="string"?{secret:e}:e,r=t.secret??"",{isRevoked:n,revocationStore:o,publicKey:s,jwksUri:i}=t,a=t.jwksCacheTtlMs??300000,u=t.algorithms??(s||i?["RS256","ES256"]:["HS256"]),c=t.issuer===void 0?null:Array.isArray(t.issuer)?t.issuer:[t.issuer],d=t.audience===void 0?null:Array.isArray(t.audience)?t.audience:[t.audience],f=(M,k,_)=>{if(M.set("user",k),Array.isArray(_)){if(_.length===0)return;let[U,...j]=_;return U(M,j)}if(typeof _==="function")return _();return},l=(M,k,_,U)=>{if(!k||typeof k!=="object"||Array.isArray(k))return M.status(401).send("Invalid token payload");let j=Date.now()*0.001;if(typeof k.exp==="number"&&j>=k.exp)return M.status(401).send("Token expired");if(typeof k.nbf==="number"&&j<k.nbf)return M.status(401).send("Token not active");if(c&&(typeof k.iss!=="string"||!c.includes(k.iss)))return M.status(401).send("Invalid token issuer");if(d){if(!(Array.isArray(k.aud)?k.aud:typeof k.aud==="string"?[k.aud]:[]).some((G)=>typeof G==="string"&&d.includes(G)))return M.status(401).send("Invalid token audience")}if(bi(_)||k?.jti&&bi(String(k.jti)))return M.status(401).send("Token revoked");if(o)return(async()=>{if(await o.isRevoked(_))return M.status(401).send("Token revoked");if(k?.jti&&await o.isRevoked(String(k.jti)))return M.status(401).send("Token revoked");if(n){if(await n(k,_))return M.status(401).send("Token revoked")}return f(M,k,U)})();if(n){let N=n(k,_);if(N&&typeof N.then==="function")return N.then((G)=>G?M.status(401).send("Token revoked"):f(M,k,U));if(N)return M.status(401).send("Token revoked")}return f(M,k,U)};if(!s&&!i&&u.length===1&&u[0]==="HS256"){let M=(k,_)=>{let U=k.req.headers.get("Authorization");if(!U?.startsWith("Bearer "))return k.status(401).send("Bearer token required");let j=U.slice(7),N=j.indexOf("."),G=N===-1?-1:j.indexOf(".",N+1);if(N===-1||G===-1||j.indexOf(".",G+1)!==-1)return k.status(401).send("Malformed JWT token");let Xe=j.slice(0,N),Te=j.slice(N+1,G),E=j.slice(G+1),v=j.slice(0,G);try{let z=au("sha256",r).update(v).digest(),Me=Buffer.from(E,"base64url");if(Me.length!==z.length||!Ss(Me,z))return k.status(401).send("Invalid signature");let je=JSON.parse(ws(Xe));if(!je||je.alg!=="HS256")return k.status(401).send("Unsupported token algorithm");let de=JSON.parse(ws(Te));return l(k,de,j,_)}catch{return k.status(401).send("Token verification failed")}};if(n||o)return async(k,_)=>M(k,_);return M}let b=0,O=0,B=[],q=null,Ce=new Map,rt=15000,Be=async(M=!1)=>{let k=Date.now();if(!M&&B.length>0&&k-b<a)return B;if(M&&k-O<rt&&B.length>0)return B;if(q)return q;if(M)O=k;return q=(async()=>{let _=await fetch(i,{signal:AbortSignal.timeout(5000)});if(!_.ok)throw Error(`JWKS fetch failed: ${_.status}`);let U=await _.json();if(B=Array.isArray(U?.keys)?U.keys:[],b=Date.now(),M)Ce.clear();return B})().finally(()=>{q=null}),q},me=(M,k,_)=>{let U=(j)=>j&&j.use!=="enc"&&(!j.alg||j.alg===_);return k?M.find((j)=>j.kid===k&&U(j)):M.find((j)=>U(j))},Ae=async(M,k)=>{let _=`${k}:${M??"__default__"}`,U=Ce.get(_);if(U&&Date.now()-b<a)return U;let j=await Be(!1),N=me(j,M,k);if(!N&&M)j=await Be(!0),N=me(j,M,k);if(!N)return null;let G=await crypto.subtle.importKey("jwk",N,uu(k),!1,["verify"]);return Ce.set(_,G),G};return async(M,k)=>{let _=M.req.headers.get("Authorization");if(!_?.startsWith("Bearer "))return M.status(401).send("Bearer token required");let U=_.slice(7),j=U.indexOf("."),N=j===-1?-1:U.indexOf(".",j+1);if(j===-1||N===-1||U.indexOf(".",N+1)!==-1)return M.status(401).send("Malformed JWT token");let G=U.slice(0,j),Xe=U.slice(j+1,N),Te=U.slice(N+1),E=U.slice(0,N);try{let v=JSON.parse(ws(G)),z=v?.alg;if(!z||!u.includes(z))return M.status(401).send("Unsupported token algorithm");if(z==="HS256"){if(!r)return M.status(401).send("Unsupported token algorithm");let je=au("sha256",r).update(E).digest(),de=Buffer.from(Te,"base64url");if(de.length!==je.length||!Ss(de,je))return M.status(401).send("Invalid signature")}else{let je=null;if(i)je=await Ae(v?.kid,z);else if(s)je=await dx(s,z);if(!je)return M.status(401).send("Invalid signature");let de=Buffer.from(Te,"base64url"),pt=de.buffer.slice(de.byteOffset,de.byteOffset+de.byteLength);if(!await crypto.subtle.verify(cx(z),je,pt,Ri.encode(E)))return M.status(401).send("Invalid signature")}let Me=JSON.parse(ws(Xe));return l(M,Me,U,k)}catch{return M.status(401).send("Token verification failed")}}},$s=(e)=>ox("sha256").update(e).digest(),mx=(e)=>{let t=$s(e.user),r=$s(e.pass);return async(n,o)=>{let s=n.req.headers.get("Authorization");if(!s?.startsWith("Basic "))return n.status(401).json({status:"error",message:"Basic Auth required"});let i=s.slice(6).trim();if(!i)return n.status(401).json({status:"error",message:"Missing credentials"});let a=Buffer.from(i,"base64").toString("utf-8"),u=a.indexOf(":");if(u===-1)return n.status(401).json({status:"error",message:"Invalid credentials"});let c=a.slice(0,u),d=a.slice(u+1),f=Ss($s(c),t),l=Ss($s(d),r);if(f&&l)return o();return n.status(401).json({status:"error",message:"Invalid credentials"})}},px=(e)=>async(t,r)=>{let n=t.get("user");if(!n||n.role!==e)return t.status(403).json({status:"error",message:`Required role: ${e}`});return r()};Rs();var du={make:(e)=>Bun.password.hash(e,Xn.hash),verify:async(e,t)=>{if(!t||typeof t!=="string")return!1;try{return await Bun.password.verify(e,t)}catch{return!1}},needsRehash:(e)=>{let{algorithm:t,memoryCost:r,timeCost:n}=Xn.hash;if(t==="bcrypt"){if(!/^\$2[aby]\$/.test(e))return!0;let i=e.match(/^\$2[aby]\$(\d+)\$/);return!i||Number(i[1])!==n}if(!e.startsWith(`$${t}$`))return!0;let o=e.match(/(?:^|[,$])m=(\d+)(?:[,$]|$)/),s=e.match(/(?:^|[,$])t=(\d+)(?:[,$]|$)/);return!o||Number(o[1])!==r||!s||Number(s[1])!==n}};var lx=(e,t,r)=>{let n=t;if(r?.params){let a=r.params;n=n.replace(/:([a-zA-Z0-9_]+)(?=\/|$)/g,(u,c)=>Object.hasOwn(a,c)?encodeURIComponent(String(a[c])):u)}let o=e.endsWith("/")?e.slice(0,-1):e,s=n.startsWith("/")?n:`/${n}`,i=`${o}${s}`;if(r?.query){let a=new URLSearchParams;for(let[c,d]of Object.entries(r.query))if(d!==void 0)a.set(c,String(d));let u=a.toString();if(u)i+=`?${u}`}return i},yx=(e,t={})=>{let r=typeof e==="object"&&e!==null&&typeof e.fetch==="function",n=r?"http://localhost":e,o=t.fetch??(r?(a,u)=>e.fetch(new Request(String(a),u)):fetch),s=t.headers??{},i=async(a,u,c)=>{let d=lx(n,u,c),f={...s,...c?.headers??{}},l={method:a,headers:f};if(c?.body!==void 0&&a!=="GET"&&a!=="HEAD"){if(!f["Content-Type"]&&!f["content-type"])f["Content-Type"]="application/json";l.body=typeof c.body==="string"?c.body:JSON.stringify(c.body)}let y=await o(d,l),b=null;if(y.status!==204&&y.status!==205&&y.status!==304)if((y.headers.get("content-type")||"").includes("application/json")){let B=await y.text();b=B?JSON.parse(B):null}else b=await y.text();if(!y.ok){let O=Error(`HTTP ${y.status}`);throw O.status=y.status,O.data=b,O}return b};return{get:(a,u)=>i("GET",a,u),post:(a,u)=>i("POST",a,u),put:(a,u)=>i("PUT",a,u),patch:(a,u)=>i("PATCH",a,u),delete:(a,u)=>i("DELETE",a,u)}};export{ru as BareJS,an as BareRouter,Oo as Context,du as Hash,du as Password,jh as T,jh as Type,jh as TypeBox,jy as Z,jy as Zod,fx as bareAuth,yx as bareClient,mx as basicAuth,Yh as circuitBreaker,nx as compress,Dh as cors,cc as createResponseFilter,Wh as createSingleflight,ix as createToken,Hh as csrf,gi as generateOpenAPISpec,px as hasRole,vh as healthcheck,Jh as idempotency,bi as isTokenRevoked,Bh as logger,sc as n,sc as native,Vh as rateLimit,Xh as redisStore,hi as renderDocsHTML,ax as revokeToken,ci as schemaValidator,Qh as securityHeaders,ex as staticFile,oc as t,zh as timeout,oc as typebox,Ey as v,Ey as validate,ic as z,ic as zod};
336
+ \x1B[90m\u2699\uFE0F Pool Size: ${this.pool.length} | JIT: Enabled | Port: ${s}\x1B[0m
337
+ \x1B[36m\uD83D\uDEE1\uFE0F Hash: ${Et.hash.algorithm} (${Et.hash.memoryCost/1024}MB) | Iterations: ${Et.hash.timeCost}\x1B[0m
338
+ `);let a=this.wsRoutes,u=this.fetch,f=a.size>0?Bun.serve({port:s,hostname:t,reusePort:r,maxRequestBodySize:o,fetch(m,y){if(m.headers.get("upgrade")?.toLowerCase()==="websocket"){let p=m.url,h=p.indexOf("/",8),x=h===-1?-1:p.indexOf("?",h),w=(h===-1?"/":x===-1?p.slice(h):p.slice(h,x)).replace(/\/+/g,"/"),P=w.length>1&&w.endsWith("/")?w.slice(0,-1):w,C=a.get(P),J;if(!C){let z=P.split("/").filter(Boolean);for(let[L,T]of a){if(!L.includes(":")&&!L.includes("*"))continue;let B=L.split("/").filter(Boolean),Z={},W=!0;for(let q=0;q<B.length;q++){let A=B[q];if(A==="*"){Z["*"]=z.slice(q).join("/");break}if(q>=z.length){W=!1;break}if(A.startsWith(":"))Z[A.slice(1)]=z[q];else if(A!==z[q]){W=!1;break}}if(W&&(B.includes("*")||B.length===z.length)){C=T,J=Z;break}}}if(C&&y.upgrade(m,{data:J?{...C,params:J}:C}))return}return u(m,y?.requestIP?.(m)?.address)},websocket:this.wsAdapter}):Bun.serve({port:s,hostname:t,reusePort:r,maxRequestBodySize:o,fetch(m,y){return u(m,y?.requestIP?.(m)?.address)}});this.server=f;for(let m of this.startHooks)Promise.resolve(m()).catch((y)=>console.error(`[${this.name}] onStart error:`,y));let d=async()=>{let y=this.name,p=process.stdout.isTTY;{let h=p?"\uD83D\uDED1":"!",x=p?"\u2705":"v";process.stdout.write(`
339
+ \x1B[31m${h} Stopping ${y}...\x1B[0m
340
+ `),await this.stop(!1),process.stdout.write(`\x1B[32m${x} ${y} has been stopped.\x1B[0m
341
+ `)}process.exit(0)};return this.shutdownHandler=d,process.on("SIGINT",d),process.on("SIGTERM",d),f}}var Qh=(e)=>{let t=e.indexOf("/",8);if(t===-1)return"/";let r=e.indexOf("?",t);return r===-1?e.slice(t):e.slice(t,r)},Zh=(e={})=>{let t=e.format??"pretty",r=e.requestId??!0,{skip:n,onLog:o}=e;return(s,i)=>{let a=Qh(s.req.url);if(n?.(s,a))return i?.();let u=r?s.requestId:void 0;if(u)s.setHeader("x-request-id",u);let c={timestamp:new Date().toISOString(),method:s.req.method,path:a,...u?{requestId:u}:{},ip:s.ip};if(o)o(c);else if(t==="json")console.log(JSON.stringify(c));else{let f=u?` [${u.slice(0,8)}]`:"";console.log(`[${c.timestamp}] ${c.method} ${c.path}${f}`)}return i?.()}};var ex=(e={})=>{let t=e.path??"/health",{readyPath:r,checks:n}=e,o=Date.now(),s=async()=>{let i={},a=!0;if(n){let c=Object.entries(n);await Promise.all(c.map(async([f,d])=>{try{let m=await d();if(i[f]=m?"ok":"fail",!m)a=!1}catch{i[f]="fail",a=!1}}))}let u={status:a?"ok":"degraded",uptimeMs:Date.now()-o,timestamp:new Date().toISOString()};if(e.version)u.version=e.version;if(n)u.checks=i;return Response.json(u,{status:a?200:503})};return{install(i){if(i.get(t,s),r&&r!==t)i.get(r,s)}}};var ao=(e)=>{let t=e.get("Vary");if(!t)e.set("Vary","Origin");else if(!t.toLowerCase().split(",").some((r)=>r.trim()==="origin"))e.set("Vary",`${t}, Origin`)},tx=(e={})=>{let t=e.origin??"*",r=e.methods||"GET,POST,PUT,PATCH,DELETE,OPTIONS",n=Array.isArray(e.allowedHeaders)?e.allowedHeaders.join(", "):e.allowedHeaders||"Content-Type, Authorization",o=Array.isArray(e.exposedHeaders)?e.exposedHeaders.join(", "):e.exposedHeaders,s=e.credentials===!0,i=(f)=>{let d=f._headers?.vary;if(!d)f.setHeader("Vary","Origin");else if(!d.toLowerCase().split(",").map((m)=>m.trim()).includes("origin"))f.setHeader("Vary",`${d}, Origin`)};if(typeof t==="string"){if(t===""){let p=(h,x)=>{if(h.req.method==="OPTIONS")return new Response(null,{status:204,headers:{Vary:"Origin"}});h.setHeader("Vary","Origin");let R=x?.();if(R&&typeof R.then==="function")return R.then((w)=>{if(w instanceof Response)ao(w.headers);else i(h);return w});if(R instanceof Response)ao(R.headers);else i(h);return R};return p.__isCors=!0,p}let f=s&&t!=="*",d={"Access-Control-Allow-Origin":t,"Access-Control-Allow-Methods":r,"Access-Control-Allow-Headers":n};if(t!=="*")d.Vary="Origin";if(f)d["Access-Control-Allow-Credentials"]="true";let m={status:204,headers:d},y=(p,h)=>{if(p.req.method==="OPTIONS")return new Response(null,m);if(p.setHeader("Access-Control-Allow-Origin",t),p.setHeader("Access-Control-Allow-Methods",r),t!=="*")p.setHeader("Vary","Origin");if(f)p.setHeader("Access-Control-Allow-Credentials","true");if(o)p.setHeader("Access-Control-Expose-Headers",o);let x=h?.();if(x&&typeof x.then==="function")return x.then((R)=>{if(R instanceof Response){if(R.headers.set("Access-Control-Allow-Origin",t),R.headers.set("Access-Control-Allow-Methods",r),t!=="*")ao(R.headers);if(f)R.headers.set("Access-Control-Allow-Credentials","true");if(o)R.headers.set("Access-Control-Expose-Headers",o)}else if(t!=="*")i(p);return R});if(x instanceof Response){if(x.headers.set("Access-Control-Allow-Origin",t),x.headers.set("Access-Control-Allow-Methods",r),t!=="*")ao(x.headers);if(f)x.headers.set("Access-Control-Allow-Credentials","true");if(o)x.headers.set("Access-Control-Expose-Headers",o)}else if(t!=="*")i(p);return x};return y.__isCors=!0,y}let a=Array.isArray(t)?new Set(t):null,u=(f)=>{if(!f)return null;if(a)return a.has(f)?f:null;return t(f)?f:null},c=(f,d)=>{let m=u(f.req.headers.get("origin"));if(f.req.method==="OPTIONS"){let p={"Access-Control-Allow-Methods":r,"Access-Control-Allow-Headers":n,Vary:"Origin"};if(m)p["Access-Control-Allow-Origin"]=m;if(s&&m)p["Access-Control-Allow-Credentials"]="true";return new Response(null,{status:204,headers:p})}if(f.setHeader("Vary","Origin"),f.setHeader("Access-Control-Allow-Methods",r),m){if(f.setHeader("Access-Control-Allow-Origin",m),s)f.setHeader("Access-Control-Allow-Credentials","true")}if(o)f.setHeader("Access-Control-Expose-Headers",o);let y=d?.();if(y&&typeof y.then==="function")return y.then((p)=>{if(p instanceof Response){if(ao(p.headers),p.headers.set("Access-Control-Allow-Methods",r),m){if(p.headers.set("Access-Control-Allow-Origin",m),s)p.headers.set("Access-Control-Allow-Credentials","true")}if(o)p.headers.set("Access-Control-Expose-Headers",o)}else i(f);return p});if(y instanceof Response){if(ao(y.headers),y.headers.set("Access-Control-Allow-Methods",r),m){if(y.headers.set("Access-Control-Allow-Origin",m),s)y.headers.set("Access-Control-Allow-Credentials","true")}if(o)y.headers.set("Access-Control-Expose-Headers",o)}else i(f);return y};return c.__isCors=!0,c};import{timingSafeEqual as rx}from"crypto";var nx=new Set(["GET","HEAD","OPTIONS"]),ox=(e)=>{try{let t=new URL(e.req.url),r=e.req.headers.get("host")?.trim();if(e._trustProxy){let n=e.req.headers.get("x-forwarded-host")?.split(",")[0]?.trim(),o=e.req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim(),s=n||r;if(s){let i=o?`${o.replace(/:$/,"")}:`:t.protocol;return new URL(`${i}//${s}`).origin}}if(r)return new URL(`${t.protocol}//${r}`).origin;return t.origin}catch{return""}},sx=(e={})=>{let t=e.ignoreMethods?new Set(e.ignoreMethods.map((a)=>a.toUpperCase())):nx,r=e.allowedOrigins?new Set(e.allowedOrigins):null,n=e.cookieName||"csrf_token",o=(e.headerName||"x-csrf-token").toLowerCase(),s=e.requireToken===!0,i=e.allowMissingOrigin===!0;return(a,u)=>{let c=a.req.method.toUpperCase();if(t.has(c))return u?.();let f=a.req.headers.get("sec-fetch-site"),d=a.req.headers.get("origin"),m=a.req.headers.get("referer");if(f==="cross-site"){if(!r||!d||!r.has(d))return Response.json({status:"error",code:"CSRF_FORBIDDEN",message:"Cross-site request blocked"},{status:403})}let y=d;if(!y&&m)try{y=new URL(m).origin}catch{return Response.json({status:"error",code:"CSRF_FORBIDDEN",message:"Invalid Referer header"},{status:403})}if(y){let p=ox(a);if(!(p!==""&&y===p||r!==null&&r.has(y)))return Response.json({status:"error",code:"CSRF_FORBIDDEN",message:"Origin mismatch"},{status:403})}else if(!i&&f!=="same-origin")return Response.json({status:"error",code:"CSRF_FORBIDDEN",message:"Missing Origin or Referer header"},{status:403});if(s){let p=a.cookies[n],h=a.req.headers.get(o),x=!1;if(p&&h){let R=Buffer.from(p),w=Buffer.from(h);x=R.length===w.length&&rx(R,w)}if(!x)return Response.json({status:"error",code:"CSRF_TOKEN_INVALID",message:"Invalid or missing CSRF token"},{status:403})}return u()}};var ix=(e=1e4,t={})=>{let r=t.status??408,n=t.message??"Request Timeout",o=Number.isFinite(e)?Math.min(Math.max(e,0),2147483647):2147483647,s=async(i,a)=>{let u;try{let c=Promise.resolve(a()),f=new Promise((d)=>{u=setTimeout(()=>{i._detached=!0,c.catch(()=>{}),d(Response.json({status:"error",code:"REQUEST_TIMEOUT",message:n},{status:r}))},o)});return await Promise.race([c,f])}finally{if(u!==void 0)clearTimeout(u)}};return s.__timeout={ms:o,status:r,message:n},s};var ax=(e={})=>{let t=e.windowMs??60000,r=e.max??100,n=e.message??"Too many requests, please try again later.",o=Math.max(1,e.maxEntries??1e4),s=e.keyGenerator??((c)=>c.ip),i=e.store,a=(c,f,d,m,y)=>{let p=Math.max(0,r-f),h=String(Math.ceil(d/1000));if(c.setHeader("X-RateLimit-Limit",String(r)),c.setHeader("X-RateLimit-Remaining",String(p)),c.setHeader("X-RateLimit-Reset",h),f>r){let x=Math.max(1,Math.ceil((d-m)/1000));return Response.json({status:"error",code:"RATE_LIMITED",message:n},{status:429,headers:{"Retry-After":String(x),"X-RateLimit-Limit":String(r),"X-RateLimit-Remaining":"0","X-RateLimit-Reset":h}})}return y?.()};if(i)return async(c,f)=>{let d=Date.now(),m=s(c),{count:y,resetAt:p}=await i.increment(m,t);return a(c,y,p,d,f)};let u=new Map;return(c,f)=>{let d=Date.now(),m=s(c),y=u.get(m);if(!y||d>=y.resetAt){if(u.size>=o)for(let[h,x]of u){if(d>=x.resetAt)u.delete(h);if(u.size<o)break}let p=m;if(u.size>=o&&!u.has(m)){p="\x00__overflow__";let h=u.get(p);if(h&&d<h.resetAt)return h.count++,a(c,h.count,h.resetAt,d,f)}y={count:1,resetAt:d+t},u.delete(p),u.set(p,y)}else y.count++,u.delete(m),u.set(m,y);return a(c,y.count,y.resetAt,d,f)}};import{createHash as ux}from"crypto";var cx=["location","content-location","etag"],mc=(e)=>{let t;for(let r of cx){let n=e.headers.get(r);if(n!==null)(t??={})[r]=n}return t},fx=(e)=>{let t=e.req.headers.get("authorization")||"",r=e.req.headers.get("cookie")||"";if(!t&&!r)return"";return ux("sha256").update(t).update("\x00").update(r).digest("hex")},Fi=(e)=>{if(e.rawBody!==void 0)return new Response(e.rawBody,{status:e.status,headers:{...e.headers||{},"content-type":e.contentType||"application/json","X-Idempotent-Replayed":"true"}});return Response.json(e.body??null,{status:e.status,headers:{"X-Idempotent-Replayed":"true"}})},yc=(e,t,r)=>{let n=e.req.headers.get(t)?.trim();if(!n)return;let o=e.req.url,s=o.indexOf("/",8),i=s===-1?-1:o.indexOf("?",s),a=s===-1?"/":i===-1?o.slice(s):o.slice(s,i);return`${e.req.method}:${a}:${r(e)||""}:${n}`},dx=(e={})=>{let t=(e.headerName||"idempotency-key").toLowerCase(),r=e.ttlMs??300000,n=e.keyScope??fx,o=e.maxKeys??1e4,s=e.store;if(s){let d=typeof s.acquireToken==="function",m={delete:(p)=>{s.release(p)}},y=async(p)=>{let h=yc(p,t,n);if(!h){p._idempotencyKey=void 0;return}let x=await s.get(h);if(x&&Date.now()<x.expiresAt)return p._idempotencyKey=void 0,Fi(x);let R=!1,w;if(d){let C=await s.acquireToken(h,r);if(C)R=!0,w=C}else R=await s.acquire(h,r);if(!R)return p._idempotencyKey=void 0,Response.json({status:"error",code:"IDEMPOTENT_IN_FLIGHT",message:"Duplicate request is currently in flight"},{status:409});if(p._detached){p._idempotencyKey=void 0,await s.release(h,w);return}let P;try{P=await s.get(h)}catch(C){throw p._idempotencyKey=void 0,await s.release(h,w),C}if(p._detached){p._idempotencyKey=void 0,await s.release(h,w);return}if(P&&Date.now()<P.expiresAt)return p._idempotencyKey=void 0,await s.release(h,w),Fi(P);p._idempotencyKey=h,p._idemExtToken=w,p._idemInFlight=d?{delete:(C)=>{let J=p._idemExtToken;p._idemExtToken=void 0,s.release(C,J)}}:m;return};return y.__idempotencyCommit=(p,h,x)=>{let R=p._idempotencyKey;if(!R)return;let w=h instanceof Response,P=w&&(h.headers.get("content-type")||"").includes("text/event-stream"),C=null;if(!P&&x>=200&&x<300&&w)try{C=h.clone()}catch{C=null}let J=C?C.headers.get("content-type")||"application/json":void 0;return(async()=>{try{if(!p._detached&&!P&&x>=200&&x<300)if(w){if(C){let z=await C.arrayBuffer();if(!p._detached)await s.set(R,{status:x,rawBody:z,contentType:J,headers:mc(C),expiresAt:Date.now()+r},r)}}else await s.set(R,{status:x,body:h??null,expiresAt:Date.now()+r},r)}catch{}finally{let z=p._idemExtToken,L=Boolean(p._detached)||!p._idempotencyKey;if(p._idempotencyKey=void 0,p._idemExtToken=void 0,p._idemInFlight=void 0,!L)await s.release(R,z)}})()},y.__idempotencyRelease=(p)=>{let h=p._idempotencyKey;if(h){let x=p._idemExtToken;p._idempotencyKey=void 0,p._idemExtToken=void 0,p._idemInFlight=void 0,s.release(h,x)}},y}let i=new Map,a=new Map,u=()=>{if(i.size>=o){let d=i.keys().next().value;if(d!==void 0)i.delete(d)}},c=(d)=>{let m=yc(d,t,n);if(!m){d._idempotencyKey=void 0;return}let y=Date.now(),p=i.get(m);if(p){if(y<p.expiresAt)return d._idempotencyKey=void 0,Fi(p);i.delete(m)}let h=a.get(m);if(h!==void 0){if(y<h.expiresAt)return d._idempotencyKey=void 0,Response.json({status:"error",code:"IDEMPOTENT_IN_FLIGHT",message:"Duplicate request is currently in flight"},{status:409});a.delete(m)}let x=crypto.randomUUID();a.set(m,{token:x,expiresAt:y+r}),d._idempotencyKey=m,d._idemToken=x,d._idemInFlight={delete:(R)=>{let w=a.get(R);if(w&&w.token===x)a.delete(R)}};return},f=(d,m)=>{let y=d._idemToken;d._idempotencyKey=void 0,d._idemToken=void 0,d._idemInFlight=void 0;let p=a.get(m);if(p&&(!y||p.token===y))a.delete(m)};return c.__idempotencyCommit=(d,m,y)=>{let p=d._idempotencyKey;if(!p)return;let h=m instanceof Response,x=h&&(m.headers.get("content-type")||"").includes("text/event-stream");if(!d._detached&&!x&&y>=200&&y<300){if(h){let R=null;try{R=m.clone()}catch{R=null}if(R){let w=R.headers.get("content-type")||"application/json";return R.arrayBuffer().then((P)=>{if(d._detached)return;u(),i.set(p,{status:y,rawBody:P,contentType:w,headers:mc(R),expiresAt:Date.now()+r})}).catch(()=>{}).finally(()=>{f(d,p)})}f(d,p);return}u(),i.set(p,{status:y,body:m??null,expiresAt:Date.now()+r})}f(d,p)},c.__idempotencyRelease=(d)=>{let m=d._idempotencyKey;if(m)f(d,m)},c},px=()=>{let e=new Map;return async(t,r)=>{let n=e.get(t);if(n)return{data:await n,shared:!0};let o=r().finally(()=>{e.delete(t)});return e.set(t,o),{data:await o,shared:!1}}};var lx=(e,t={})=>{let r=t.prefix??"barejs:",n=typeof e.send==="function",o=(d)=>n?e.send("GET",[d]):e.get(d),s=(d)=>n?e.send("DEL",[d]):e.del(d),i=(d)=>n?e.send("INCR",[d]):e.incr(d),a=async(d,m,y)=>{if(n){await e.send("SET",[d,m,"PX",String(y)]);return}try{await e.set(d,m,"PX",y)}catch{if(await e.set(d,m),typeof e.pexpire==="function")await e.pexpire(d,y);else if(typeof e.expire==="function")await e.expire(d,Math.max(1,Math.ceil(y/1000)))}},u=async(d,m)=>{if(n)await e.send("PEXPIRE",[d,String(m)]);else if(typeof e.pexpire==="function")await e.pexpire(d,m);else if(typeof e.expire==="function")await e.expire(d,Math.max(1,Math.ceil(m/1000)))},c=new Map,f='if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end';return{async increment(d,m){let y=`${r}rl:${d}`,p=Number(await i(y));if(p===1)await u(y,m);let h=m,x=null;if(n)x=Number(await e.send("PTTL",[y]));else if(typeof e.pttl==="function")x=Number(await e.pttl(y));else if(typeof e.ttl==="function"){let R=Number(await e.ttl(y));x=R<0?R:R*1000}if(x===-1)await u(y,m);else if(x!==null&&Number.isFinite(x)&&x>0)h=x;return{count:p,resetAt:Date.now()+h}},async get(d){let m=await o(`${r}idem:${d}`);if(!m)return;try{let y=JSON.parse(typeof m==="string"?m:String(m));if(typeof y.rawBodyBase64==="string"){let p=Buffer.from(y.rawBodyBase64,"base64");return{status:y.status,rawBody:p.buffer.slice(p.byteOffset,p.byteOffset+p.byteLength),contentType:y.contentType,headers:y.headers,expiresAt:y.expiresAt}}return y}catch{return}},async set(d,m,y){let p={status:m.status,expiresAt:m.expiresAt};if(m.rawBody!==void 0){if(p.rawBodyBase64=Buffer.from(m.rawBody).toString("base64"),p.contentType=m.contentType,m.headers)p.headers=m.headers}else p.body=m.body;await a(`${r}idem:${d}`,JSON.stringify(p),y)},async acquireToken(d,m=30000){let y=`${r}idem:lock:${d}`,p=crypto.randomUUID();if(n){let x=await e.send("SET",[y,p,"PX",String(m),"NX"]);return x==="OK"||x===!0?p:null}let h=await e.set(y,p,"PX",m,"NX");return h==="OK"||h===!0||h===1?p:null},async acquire(d,m=30000){let y=await this.acquireToken(d,m);if(!y)return!1;let p=c.get(d);if(!p)p=[],c.set(d,p);return p.push(y),!0},async release(d,m){let y=`${r}idem:lock:${d}`,p=m;if(p===void 0){let x=c.get(d);if(p=x?.pop(),x&&x.length===0)c.delete(d)}if(!p)return;if(n)try{await e.send("EVAL",['if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end',"1",y,p]);return}catch{}else if(typeof e.eval==="function")try{await e.eval('if redis.call("get", KEYS[1]) == ARGV[1] then return redis.call("del", KEYS[1]) else return 0 end',1,y,p);return}catch{}if(await o(y)===p)await s(y)},async revoke(d,m){await a(`${r}rev:${d}`,"1",m)},async isRevoked(d){let m=await o(`${r}rev:${d}`);return m!==null&&m!==void 0}}};var mx=(e={})=>{let t=e.failureThreshold??5,r=e.resetTimeoutMs??30000,n=e.isFailure??((p,h)=>Boolean(h)||p instanceof Response&&(p.status>=500||p.status===408)),o="CLOSED",s=0,i=0,a=!1,u=0,c=0,f=0,d=(p)=>{if(o!==p){let h=o;o=p,u++;try{e.onStateChange?.(h,p)}catch{}}},m=async(p)=>{if(o==="OPEN"){let P=Date.now()-i;if(P<r){let C=Math.max(1,Math.ceil((r-P)/1000));return Response.json({status:"error",code:"CIRCUIT_OPEN",message:"Service temporarily unavailable"},{status:503,headers:{"Retry-After":String(C)}})}d("HALF_OPEN")}let h=!1;if(o==="HALF_OPEN"){if(a)return Response.json({status:"error",code:"CIRCUIT_OPEN",message:"Service temporarily unavailable"},{status:503,headers:{"Retry-After":"1"}});a=!0,h=!0}let x=u,R,w=h?++c:0;if(h)f=w,R=setTimeout(()=>{if(f===w&&x===u)a=!1,f=0,i=Date.now(),d("OPEN")},Math.min(Math.max(r,1),2147483647));try{let P=await p();if(x!==u)return P;if(n(P)){if(s++,h||s>=t)i=Date.now(),d("OPEN")}else if(s=0,h)d("CLOSED");return P}catch(P){if(x===u&&n(void 0,P)){if(s++,h||s>=t)i=Date.now(),d("OPEN")}throw P}finally{if(R!==void 0)clearTimeout(R);if(h&&f===w)a=!1,f=0}},y=(p,h)=>m(()=>h?h():void 0);return y.__circuitBreaker=m,y};var yx=(e={})=>{let t=[];if(e.noSniff!==!1)t.push(["X-Content-Type-Options","nosniff"]);if(e.frameOptions!==!1)t.push(["X-Frame-Options",e.frameOptions??"DENY"]);if(e.referrerPolicy!==!1)t.push(["Referrer-Policy",e.referrerPolicy??"strict-origin-when-cross-origin"]);if(e.hsts!==!1)t.push(["Strict-Transport-Security",e.hsts??"max-age=31536000; includeSubDomains"]);if(e.contentSecurityPolicy)t.push(["Content-Security-Policy",e.contentSecurityPolicy]);t.push(["X-XSS-Protection","0"]);let r=t.length,n=Object.freeze((()=>{let o={};for(let s=0;s<r;s++){let i=t[s];o[i[0].toLowerCase()]=i[1]}return o})());return(o,s)=>{if(!o._headers)o._headers=n;else o._headers={...o._headers,...n};let i=s?.();if(i&&typeof i.then==="function")return i.then((a)=>{if(a instanceof Response)for(let u=0;u<r;u++){let c=t[u];if(!a.headers.has(c[0]))a.headers.set(c[0],c[1])}return a});if(i instanceof Response)for(let a=0;a<r;a++){let u=t[a];if(!i.headers.has(u[0]))i.headers.set(u[0],u[1])}return i}};import{resolve as gc,sep as Ms}from"path";import{stat as gx,realpath as hc}from"fs/promises";var hx=(e="public",t={})=>{let r=gc(process.cwd(),e),n=r.endsWith(Ms)?r:r+Ms,o=null,s=t.maxAge??3600,i=t.etag!==!1,a=t.cacheMetadata,u=Boolean(a),c=typeof a==="object"?a.maxEntries??1000:1000,f=typeof a==="object"?a.ttlMs??30000:30000,d=u?new Map:null,m=async(y,p)=>{let h=y.req.method;if(h!=="GET"&&h!=="HEAD")return p?.();let x=y.req.url,R=x.indexOf("/",8),w=R===-1?-1:x.indexOf("?",R),P=R===-1?"":w===-1?x.slice(R):x.slice(R,w),C;try{C=decodeURIComponent(P)}catch{return y.status(400).send("Bad Request")}if(C.includes("\x00"))return y.status(400).send("Bad Request");let J=C.replace(/^\/+/,""),z=gc(r,J);if(z!==r&&!z.startsWith(n))return y.status(403).send("Forbidden");let L=z,T=0,B=0,Z="",W=d?.get(z);if(W&&Date.now()<W.expiresAt)d.delete(z),d.set(z,W),L=W.realFile,T=W.fileSize,B=W.mtimeMs,Z=W.etag;else try{let[Q,re]=await Promise.all([o??=hc(r),hc(z)]),ie=Q.endsWith(Ms)?Q:Q+Ms;if(re!==Q&&!re.startsWith(ie))return y.status(403).send("Forbidden");let ge=await gx(re);if(ge.isDirectory())return p?.();if(L=re,T=ge.size,B=Math.floor(ge.mtimeMs),Z=i?`W/"${T.toString(16)}-${B.toString(16)}"`:"",d){if(d.size>=c){let ee=d.keys().next().value;if(ee!==void 0)d.delete(ee)}d.set(z,{realFile:L,fileSize:T,mtimeMs:B,etag:Z,expiresAt:Date.now()+f})}}catch{return o=null,p?.()}let q=Bun.file(L),A={"Cache-Control":`public, max-age=${s}`,"Accept-Ranges":"bytes"};if(i){A.ETag=Z;let Q=y.req.headers?.get?.("if-none-match")?.trim();if(Q){if(Q==="*"||Q.split(",").some((ie)=>ie.trim()===Z))return new Response(null,{status:304,headers:A})}}let oe=y.req.headers?.get?.("range");if(oe&&oe.startsWith("bytes=")&&T>0){let re=oe.slice(6).split("-");if(re.length!==2)return new Response(null,{status:416,headers:{...A,"Content-Range":`bytes */${T}`}});let[ie,ge]=re,ee=/^\d+$/;if(!ie&&!ge||ie&&!ee.test(ie)||ge&&!ee.test(ge))return new Response(null,{status:416,headers:{...A,"Content-Range":`bytes */${T}`}});let ae=ie?Number(ie):0,D=ge?Math.min(Number(ge),T-1):T-1;if(!ie&&ge){let k=Number(ge);if(k===0)return new Response(null,{status:416,headers:{...A,"Content-Range":`bytes */${T}`}});ae=Math.max(0,T-k),D=T-1}if(!Number.isInteger(ae)||!Number.isInteger(D)||ae<0||ae>=T||ae>D)return new Response(null,{status:416,headers:{...A,"Content-Range":`bytes */${T}`}});if(A["Content-Range"]=`bytes ${ae}-${D}/${T}`,A["Content-Length"]=String(D-ae+1),q.type)A["Content-Type"]=q.type;return new Response(h==="HEAD"?null:q.slice(ae,D+1),{status:206,headers:A})}if(q.type)A["Content-Type"]=q.type;return A["Content-Length"]=String(T),new Response(h==="HEAD"?null:q,{status:200,headers:A})};return m.__isStatic=!0,m};import{brotliCompressSync as xx,constants as bx}from"zlib";var Ix=(e={})=>{let t=e.minSize??1024,r=e.level??6,n=e.encodings??["zstd","br","gzip"],o=typeof Bun.zstdCompressSync==="function",s=(u)=>{let f=u.toLowerCase().split(","),d=new Map;for(let h=0;h<f.length;h++){let x=f[h].trim();if(!x)continue;let R=x.indexOf(";"),w=(R===-1?x:x.slice(0,R)).trim(),P=1;if(R!==-1){let C=x.slice(R+1).match(/q\s*=\s*([0-9.]+)/);if(C){let J=parseFloat(C[1]);if(Number.isFinite(J))P=J}}d.set(w,P)}let m=d.get("*"),y=null,p=0;for(let h=0;h<n.length;h++){let x=n[h];if(x==="zstd"&&!o)continue;let R=d.has(x)?d.get(x):m??0;if(R>p)p=R,y=x}return y},i=async(u,c)=>{if(u.req.method==="HEAD")return c;let f=u.req.headers.get("accept-encoding");if(!f)return c;let d=s(f);if(!d)return c;if(!(c instanceof Response))return c;if(c.status===204||c.status===206||c.status===304)return c;if(c.headers.has("content-encoding"))return c;if((c.headers.get("content-type")||"").toLowerCase().includes("text/event-stream"))return c;let y=await c.arrayBuffer();if(y.byteLength<t)return new Response(y,{status:c.status,headers:c.headers});let p=new Uint8Array(y),h;if(d==="zstd")h=Bun.zstdCompressSync(p);else if(d==="br")h=xx(p,{params:{[bx.BROTLI_PARAM_QUALITY]:Math.min(11,Math.max(1,r))}});else h=Bun.gzipSync(p,{level:r});let x=new Headers(c.headers);x.set("Content-Encoding",d);let R=x.get("Vary");if(!R)x.set("Vary","Accept-Encoding");else if(!R.toLowerCase().split(",").some((w)=>w.trim()==="accept-encoding"))x.set("Vary",`${R}, Accept-Encoding`);return x.delete("Content-Length"),new Response(h,{status:c.status,headers:x})},a=async(u,c)=>{let f=await(c?c():void 0);return i(u,f)};return a.__compress=i,a};import{createHash as _x,createHmac as xc,timingSafeEqual as Us}from"crypto";var ji=new TextEncoder,Ni=(e)=>Buffer.from(e).toString("base64url"),Ko=(e)=>Buffer.from(e,"base64url").toString("utf-8"),uo=new Map,Rx=async(e)=>{if(uo.has(e))return uo.get(e);let t=await crypto.subtle.importKey("raw",ji.encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign","verify"]);if(uo.size>=1000){let r=uo.keys().next().value;if(r!==void 0)uo.delete(r)}return uo.set(e,t),t},bc=(e)=>{if(!e||typeof e!=="object")return;let t=[e];while(t.length>0){let r=t.pop();if(!r||typeof r!=="object")continue;if(Array.isArray(r)){for(let n=0;n<r.length;n++)if(r[n]&&typeof r[n]==="object")t.push(r[n])}else{if(Object.hasOwn(r,"__proto__"))delete r.__proto__;let n=Object.values(r);for(let o=0;o<n.length;o++)if(n[o]&&typeof n[o]==="object")t.push(n[o])}}},Ox=async(e,t)=>{let r=JSON.stringify({alg:"HS256",typ:"JWT"}),n=JSON.stringify(e),o=Ni(r),s=Ni(n),i=`${o}.${s}`,a=await Rx(t),u=await crypto.subtle.sign("HMAC",a,ji.encode(i)),c=Ni(new Uint8Array(u));return`${i}.${c}`},Ic=0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551n,_c=(e)=>{let t=e.indexOf(".");if(t<=0)return null;let r=e.indexOf(".",t+1);if(r<=t+1)return null;let n=e.slice(r+1);if(!/^[A-Za-z0-9_-]+$/.test(n))return null;let o=Buffer.from(n,"base64url");if(o.length!==64)return null;try{if(JSON.parse(Ko(e.slice(0,t)))?.alg!=="ES256")return null}catch{return null}let s=BigInt("0x"+o.subarray(32,64).toString("hex"));if(s<=0n||s>=Ic)return null;let a=(Ic-s).toString(16).padStart(64,"0"),u=Buffer.allocUnsafe(64);return o.copy(u,0,0,32),Buffer.from(a,"hex").copy(u,32),e.slice(0,r+1)+u.toString("base64url")},lr=new Map;function wx(e,t=3600000,r){let n=_c(e);if(r){if(n)return Promise.all([r.revoke(e,t),r.revoke(n,t)]).then(()=>{});return r.revoke(e,t)}if(lr.size>=1e4){let s=Date.now();for(let[i,a]of lr)if(s>=a)lr.delete(i);if(lr.size>=1e4){let i=lr.keys().next().value;if(i!==void 0)lr.delete(i)}}let o=Date.now()+t;if(lr.set(e,o),n)lr.set(n,o)}function Ls(e,t){if(t)return t.isRevoked(e);let r=lr.get(e);if(r===void 0)return!1;if(Date.now()>=r)return lr.delete(e),!1;return!0}var Uo=new Map,Rc=(e)=>e==="RS256"?{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"}:{name:"ECDSA",namedCurve:"P-256"},$x=(e)=>e==="RS256"?{name:"RSASSA-PKCS1-v1_5"}:{name:"ECDSA",hash:"SHA-256"},kx=(e)=>{let t=e.replace(/-----BEGIN [A-Z0-9 ]+-----/g,"").replace(/-----END [A-Z0-9 ]+-----/g,"").replace(/\s+/g,""),r=Buffer.from(t,"base64");return r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength)},Ax=async(e,t)=>{if(typeof e!=="string")return e;let r=`${t}:${e}`,n=Uo.get(r);if(n)return n;let o=await crypto.subtle.importKey("spki",kx(e),Rc(t),!1,["verify"]);if(Uo.size>=1000){let s=Uo.keys().next().value;if(s!==void 0)Uo.delete(s)}return Uo.set(r,o),o},Sx=(e)=>{let t=typeof e==="string"?{secret:e}:e,r=t.secret??"",{isRevoked:n,revocationStore:o,publicKey:s,jwksUri:i}=t,a=t.jwksCacheTtlMs??300000,u=t.algorithms??(s||i?["RS256","ES256"]:["HS256"]),c=t.issuer===void 0?null:Array.isArray(t.issuer)?t.issuer:[t.issuer],f=t.audience===void 0?null:Array.isArray(t.audience)?t.audience:[t.audience],d=(L,T,B)=>{if(L.set("user",T),Array.isArray(B)){if(B.length===0)return;let[Z,...W]=B;return Z(L,W)}if(typeof B==="function")return B();return},m=(L,T,B,Z)=>{if(!T||typeof T!=="object"||Array.isArray(T))return L.status(401).send("Invalid token payload");let W=Date.now()*0.001;if(typeof T.exp==="number"&&W>=T.exp)return L.status(401).send("Token expired");if(typeof T.nbf==="number"&&W<T.nbf)return L.status(401).send("Token not active");if(c&&(typeof T.iss!=="string"||!c.includes(T.iss)))return L.status(401).send("Invalid token issuer");if(f){if(!(Array.isArray(T.aud)?T.aud:typeof T.aud==="string"?[T.aud]:[]).some((oe)=>typeof oe==="string"&&f.includes(oe)))return L.status(401).send("Invalid token audience")}let q=_c(B);if(Ls(B)||q&&Ls(q)||T?.jti&&Ls(String(T.jti)))return L.status(401).send("Token revoked");if(o)return(async()=>{if(await o.isRevoked(B))return L.status(401).send("Token revoked");if(q&&await o.isRevoked(q))return L.status(401).send("Token revoked");if(T?.jti&&await o.isRevoked(String(T.jti)))return L.status(401).send("Token revoked");if(n){if(await n(T,B))return L.status(401).send("Token revoked")}return d(L,T,Z)})();if(n){let A=n(T,B);if(A&&typeof A.then==="function")return A.then((oe)=>oe?L.status(401).send("Token revoked"):d(L,T,Z));if(A)return L.status(401).send("Token revoked")}return d(L,T,Z)};if(!s&&!i&&u.length===1&&u[0]==="HS256"){let L=(T,B)=>{if(!r)return T.status(401).send("Unsupported token algorithm");let Z=T.req.headers.get("Authorization");if(!Z?.startsWith("Bearer "))return T.status(401).send("Bearer token required");let W=Z.slice(7),q=W.indexOf("."),A=q===-1?-1:W.indexOf(".",q+1);if(q===-1||A===-1||W.indexOf(".",A+1)!==-1)return T.status(401).send("Malformed JWT token");let oe=W.slice(0,q),Q=W.slice(q+1,A),re=W.slice(A+1);if(!/^[A-Za-z0-9_-]+$/.test(re))return T.status(401).send("Invalid signature");let ie=W.slice(0,A),ge;try{let ee=xc("sha256",r).update(ie).digest(),ae=Buffer.from(re,"base64url");if(ae.length!==ee.length||ae.toString("base64url")!==re||!Us(ae,ee))return T.status(401).send("Invalid signature");let D=JSON.parse(Ko(oe));if(!D||D.alg!=="HS256")return T.status(401).send("Unsupported token algorithm");let k=Ko(Q);if(ge=JSON.parse(k),ge&&typeof ge==="object"&&(k.indexOf("__proto__")!==-1||k.indexOf("\\u")!==-1))bc(ge)}catch{return T.status(401).send("Token verification failed")}return m(T,ge,W,B)};if(n||o)return async(T,B)=>L(T,B);return L}let p=0,h=0,x=[],R=null,w=new Map,P=15000,C=async(L=!1)=>{let T=Date.now();if(!L&&x.length>0&&T-p<a)return x;if(L&&T-h<P&&x.length>0)return x;if(R)return R;if(L)h=T;return R=(async()=>{let B=await fetch(i,{signal:AbortSignal.timeout(5000)});if(!B.ok)throw Error(`JWKS fetch failed: ${B.status}`);let Z=await B.json();return x=Array.isArray(Z?.keys)?Z.keys:[],p=Date.now(),w.clear(),x})().finally(()=>{R=null}),R},J=(L,T,B)=>{let Z=B==="RS256"?"RSA":"EC",W=(q)=>q&&q.use!=="enc"&&(!q.kty||q.kty===Z)&&(!q.alg||q.alg===B);return T?L.find((q)=>q.kid===T&&W(q)):L.find((q)=>W(q))},z=async(L,T)=>{let B=`${T}:${L??"__default__"}`,Z=w.get(B);if(Z&&Date.now()-p<a)return Z;let W=await C(!1),q=J(W,L,T);if(!q&&L)W=await C(!0),q=J(W,L,T);if(!q)return null;let A=await crypto.subtle.importKey("jwk",q,Rc(T),!1,["verify"]);return w.set(B,A),A};return async(L,T)=>{let B=L.req.headers.get("Authorization");if(!B?.startsWith("Bearer "))return L.status(401).send("Bearer token required");let Z=B.slice(7),W=Z.indexOf("."),q=W===-1?-1:Z.indexOf(".",W+1);if(W===-1||q===-1||Z.indexOf(".",q+1)!==-1)return L.status(401).send("Malformed JWT token");let A=Z.slice(0,W),oe=Z.slice(W+1,q),Q=Z.slice(q+1);if(!/^[A-Za-z0-9_-]+$/.test(Q))return L.status(401).send("Invalid signature");let re=Z.slice(0,q),ie;try{let ge=JSON.parse(Ko(A)),ee=ge?.alg;if(!ee||!u.includes(ee))return L.status(401).send("Unsupported token algorithm");if(ee==="HS256"){if(!r)return L.status(401).send("Unsupported token algorithm");let D=xc("sha256",r).update(re).digest(),k=Buffer.from(Q,"base64url");if(k.length!==D.length||k.toString("base64url")!==Q||!Us(k,D))return L.status(401).send("Invalid signature")}else{let D=null;if(i)D=await z(ge?.kid,ee);else if(s)D=await Ax(s,ee);if(!D)return L.status(401).send("Invalid signature");let k=Buffer.from(Q,"base64url");if(k.toString("base64url")!==Q)return L.status(401).send("Invalid signature");let v=k.buffer.slice(k.byteOffset,k.byteOffset+k.byteLength);if(!await crypto.subtle.verify($x(ee),D,v,ji.encode(re)))return L.status(401).send("Invalid signature")}let ae=Ko(oe);if(ie=JSON.parse(ae),ie&&typeof ie==="object"&&(ae.indexOf("__proto__")!==-1||ae.indexOf("\\u")!==-1))bc(ie)}catch{return L.status(401).send("Token verification failed")}return m(L,ie,Z,T)}},Es=(e)=>_x("sha256").update(e).digest(),Px=(e)=>{let t=Es(e.user),r=Es(e.pass);return async(n,o)=>{let s=n.req.headers.get("Authorization");if(!s?.startsWith("Basic "))return n.status(401).json({status:"error",message:"Basic Auth required"});let i=s.slice(6).trim();if(!i)return n.status(401).json({status:"error",message:"Missing credentials"});let a=Buffer.from(i,"base64").toString("utf-8"),u=a.indexOf(":");if(u===-1)return n.status(401).json({status:"error",message:"Invalid credentials"});let c=a.slice(0,u),f=a.slice(u+1),d=Us(Es(c),t),m=Us(Es(f),r);if(d&&m)return o?.();return n.status(401).json({status:"error",message:"Invalid credentials"})}},Cx=(e)=>async(t,r)=>{let n=t.get("user");if(!n||n.role!==e)return t.status(403).json({status:"error",message:`Required role: ${e}`});return r?.()};var Oc={make:(e)=>{if(Et.hash.algorithm==="bcrypt"){let t=Math.max(4,Math.min(31,Et.hash.timeCost));return Bun.password.hash(e,{algorithm:"bcrypt",cost:t})}return Bun.password.hash(e,Et.hash)},verify:async(e,t)=>{if(!t||typeof t!=="string")return!1;try{return await Bun.password.verify(e,t)}catch{return!1}},needsRehash:(e)=>{if(!e||typeof e!=="string")return!0;let{algorithm:t,memoryCost:r,timeCost:n}=Et.hash;if(t==="bcrypt"){if(!/^\$2[aby]\$/.test(e))return!0;let i=e.match(/^\$2[aby]\$(\d+)\$/),a=Math.max(4,Math.min(31,n));return!i||Number(i[1])!==a}if(!e.startsWith(`$${t}$`))return!0;let o=e.match(/(?:^|[,$])m=(\d+)(?:[,$]|$)/),s=e.match(/(?:^|[,$])t=(\d+)(?:[,$]|$)/);return!o||Number(o[1])!==r||!s||Number(s[1])!==n}};var Tx=(e,t,r)=>{let n=t;if(r?.params){let a=r.params;n=n.replace(/:([a-zA-Z0-9_]+)(?=\/|\?|$)/g,(u,c)=>Object.hasOwn(a,c)&&a[c]!==void 0?encodeURIComponent(String(a[c])):u)}let o=e.endsWith("/")?e.slice(0,-1):e,s=n.startsWith("/")?n:`/${n}`,i=`${o}${s}`;if(r?.query){let a=new URLSearchParams;for(let[c,f]of Object.entries(r.query))if(f!==void 0)a.set(c,String(f));let u=a.toString();if(u)i+=(i.includes("?")?"&":"?")+u}return i},Fx=(e,t={})=>{let r=typeof e==="object"&&e!==null&&typeof e.fetch==="function",n=r?"http://localhost":e,o=t.fetch??(r?(a,u)=>e.fetch(new Request(String(a),u)):fetch),s=t.headers??{},i=async(a,u,c)=>{let f=Tx(n,u,c),d=new Headers;for(let[h,x]of Object.entries(s))d.set(h,x);if(c?.headers)for(let[h,x]of Object.entries(c.headers))d.set(h,x);let m={method:a,headers:d};if(c?.body!==void 0&&a!=="GET"&&a!=="HEAD"){let h=c.body;if(typeof h==="string"||h instanceof FormData||h instanceof URLSearchParams||h instanceof Blob||h instanceof ArrayBuffer||ArrayBuffer.isView(h)||typeof ReadableStream<"u"&&h instanceof ReadableStream){if(h instanceof FormData)d.delete("content-type");m.body=h}else{if(!d.has("content-type"))d.set("Content-Type","application/json");m.body=JSON.stringify(h)}}let y=await o(f,m),p=null;if(y.status!==204&&y.status!==205&&y.status!==304){let h=(y.headers.get("content-type")||"").toLowerCase();if(h.includes("application/json")||h.includes("+json")){let x=await y.text();if(x)try{p=JSON.parse(x)}catch{p=x}else p=null}else p=await y.text()}if(!y.ok){let h=Error(`HTTP ${y.status}`);throw h.status=y.status,h.data=p,h}return p};return{get:(a,u)=>i("GET",a,u),post:(a,u)=>i("POST",a,u),put:(a,u)=>i("PUT",a,u),patch:(a,u)=>i("PATCH",a,u),delete:(a,u)=>i("DELETE",a,u)}};export{Ti as BareJS,xn as BareRouter,jo as Context,Oc as Hash,Oc as Password,Hh as T,Hh as Type,Hh as TypeBox,Dy as Z,Dy as Zod,Sx as bareAuth,Fx as bareClient,Px as basicAuth,mx as circuitBreaker,Ix as compress,tx as cors,bu as createResponseFilter,px as createSingleflight,Ox as createToken,sx as csrf,Pi as generateOpenAPISpec,Cx as hasRole,ex as healthcheck,dx as idempotency,Ls as isTokenRevoked,Zh as logger,xi as n,xi as native,ax as rateLimit,lx as redisStore,Ci as renderDocsHTML,wx as revokeToken,Ii as schemaValidator,yx as securityHeaders,hx as staticFile,hi as t,ix as timeout,hi as typebox,qy as v,qy as validate,mu as z,mu as zod};