@gjermundgaraba/clankerauth-dev 0.7.2 → 0.8.0

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.
@@ -0,0 +1,53 @@
1
+ (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e=Symbol.for(`better-auth:broadcast-channel`),t=()=>Math.floor(Date.now()/1e3),n=class{listeners=new Set;name;constructor(e=`better-auth.message`){this.name=e}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}post(e){if(typeof window<`u`)try{localStorage.setItem(this.name,JSON.stringify({...e,timestamp:t()}))}catch{}}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=e=>{if(e.key!==this.name)return;let t=JSON.parse(e.newValue??`{}`);t?.event===`session`&&t?.data&&this.listeners.forEach(e=>e(t))};return window.addEventListener(`storage`,e),()=>{window.removeEventListener(`storage`,e)}}};function r(t=`better-auth.message`){return globalThis[e]||(globalThis[e]=new n(t)),globalThis[e]}var i=[],a=0,o=null,s=4,c=globalThis.nanostoresGlobal||={epoch:0},l=()=>{let e,t;for(;a<i.length;){t=a,a+=s;try{i[t](i[t+1].value,i[t+2],i[t+3])}catch(t){e=t}}if(i.length=a=0,e)throw e},u=e=>{let t=[],n={eq:Object.is,get(){return n.lc||n.listen(()=>{})(),n.value},init:e,lc:0,listen(e){return n.lc=t.push(e),()=>{for(let t=a;t<i.length;)i[t]===e?i.splice(t,s):t+=s;let r=t.indexOf(e);~r&&(t.splice(r,1),--n.lc||n.off())}},notify(e,r){c.epoch++;let a=!i.length&&!0;for(let a of t)o?.has(a)||(o?.add(a),i.push(a,n,e,r));a&&l()},off(){},set(e){let t=n.value;n.eq(t,e)||(n.value=e,n.notify(t))},subscribe(e){let t=n.listen(e);return e(n.value),t},value:e};return n},d=2,f=5,p=6,m=10,h=(e,t,n,r)=>(e.events=e.events||{},e.events[n+m]||(e.events[n+m]=r(t=>{e.events[n].reduceRight((e,t)=>(t(e),e),{shared:{},...t})})),e.events[n]=e.events[n]||[],e.events[n].push(t),()=>{let r=e.events[n],i=r.indexOf(t);~i&&(r.splice(i,1),r.length||(e.events[n+m](),delete e.events[n+m]))}),g=(e,t)=>h(e,t,d,t=>{let n=e.set,r=e.setKey;return e.setKey&&=(n,i)=>{let a;if(t({abort:()=>{a=!0},changed:n,newValue:{...e.value,[n]:i}}),!a)return r(n,i)},e.set=e=>{let r;if(t({abort:()=>{r=!0},newValue:e}),!r)return n(e)},()=>{e.set=n,e.setKey=r}}),_=1e3,ee=(e,t)=>h(e,n=>{let r=t(n);r&&e.events[p].push(r)},f,t=>{let n=e.listen;e.listen=(...r)=>(!e.lc&&!e.active&&(e.active=!0,t()),n(...r));let r=e.off;return e.events[p]=[],e.off=()=>{r(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let t of e.events[p])t();e.events[p]=[]}},_)},()=>{e.listen=n,e.off=r}});function v(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function te(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!te(e[n],t[n]))return!1;return!0}if(v(e)&&v(t)){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(!(r in t)||!te(e[r],t[r]))return!1;return!0}return!1}function ne(e,t){return g(e,({newValue:n,abort:r})=>{t(e.value,n)&&r()})}var re=Symbol.for(`better-auth:focus-manager`),ie=class{listeners=new Set;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setFocused(e){this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||typeof document>`u`||window.addEventListener===void 0)return()=>{};let e=()=>{document.visibilityState===`visible`&&this.setFocused(!0)};return document.addEventListener(`visibilitychange`,e,!1),()=>{document.removeEventListener(`visibilitychange`,e,!1)}}};function ae(){return globalThis[re]||(globalThis[re]=new ie),globalThis[re]}var oe=Symbol.for(`better-auth:online-manager`),se=class{listeners=new Set;isOnline=typeof navigator<`u`?navigator.onLine:!0;subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}setOnline(e){this.isOnline=e,this.listeners.forEach(t=>t(e))}setup(){if(typeof window>`u`||window.addEventListener===void 0)return()=>{};let e=()=>this.setOnline(!0),t=()=>this.setOnline(!1);return window.addEventListener(`online`,e,!1),window.addEventListener(`offline`,t,!1),()=>{window.removeEventListener(`online`,e,!1),window.removeEventListener(`offline`,t,!1)}}};function ce(){return globalThis[oe]||(globalThis[oe]=new se),globalThis[oe]}var le={proto:/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,constructor:/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,protoShort:/"__proto__"\s*:/,constructorShort:/"constructor"\s*:/},ue=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/,de={true:!0,false:!1,null:null,undefined:void 0,nan:NaN,infinity:1/0,"-infinity":-1/0},fe=/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,7}))?(?:Z|([+-])(\d{2}):(\d{2}))$/;function pe(e){return e instanceof Date&&!isNaN(e.getTime())}function me(e){let t=fe.exec(e);if(!t)return null;let[,n,r,i,a,o,s,c,l,u,d]=t,f=new Date(Date.UTC(parseInt(n,10),parseInt(r,10)-1,parseInt(i,10),parseInt(a,10),parseInt(o,10),parseInt(s,10),c?parseInt(c.padEnd(3,`0`),10):0));if(l){let e=(parseInt(u,10)*60+parseInt(d,10))*(l===`+`?-1:1);f.setUTCMinutes(f.getUTCMinutes()+e)}return pe(f)?f:null}function he(e,t={}){let{strict:n=!1,warnings:r=!1,reviver:i,parseDates:a=!0}=t;if(typeof e!=`string`)return e;let o=e.trim(),s=o.toLowerCase();if(s.length<=9&&s in de)return de[s];if(!ue.test(o)){if(n)throw SyntaxError(`[better-json] Invalid JSON`);return e}if(Object.entries(le).some(([e,t])=>{let n=t.test(o);return n&&r&&console.warn(`[better-json] Detected potential prototype pollution attempt using ${e} pattern`),n})&&n)throw Error(`[better-json] Potential prototype pollution attempt detected`);try{return JSON.parse(o,(e,t)=>{if(e===`__proto__`||e===`constructor`&&t&&typeof t==`object`&&`prototype`in t){r&&console.warn(`[better-json] Dropping "${e}" key to prevent prototype pollution`);return}if(a&&typeof t==`string`){let e=me(t);if(e)return e}return i?i(e,t):t})}catch(t){if(n)throw t;return e}}function ge(e,t={strict:!0}){return he(e,t)}var _e=()=>Math.floor(Date.now()/1e3),ve=5;function ye(e){let{fetchSession:t,shouldPollSession:n=()=>!0,sessionSignal:i,options:a={}}=e,o=a.sessionOptions?.refetchInterval??0,s=a.sessionOptions?.refetchOnWindowFocus??!0,c=a.sessionOptions?.refetchWhenOffline??!1,l={isInitialized:!1,lastSessionRequest:0},u=()=>c||ce().isOnline,d=e=>{if(u()){if(e?.event===`storage`){t();return}if(e?.event===`poll`){l.lastSessionRequest=_e(),t();return}if(e?.event===`visibilitychange`){if(_e()-l.lastSessionRequest<ve)return;l.lastSessionRequest=_e(),t();return}t()}},f=e=>{r().post({event:`session`,data:{trigger:e},clientId:Math.random().toString(36).substring(7)})},p=()=>{o&&o>0&&(l.pollInterval=setInterval(()=>{n()&&d({event:`poll`})},o*1e3))},m=()=>{l.unsubscribeBroadcast=r().subscribe(()=>{d({event:`storage`})})},h=()=>{s&&(l.unsubscribeFocus=ae().subscribe(()=>{d({event:`visibilitychange`})}))},g=()=>{l.unsubscribeOnline=ce().subscribe(e=>{e&&d({event:`visibilitychange`})})},_=()=>{l.unsubscribeSignal=i.listen(()=>{t()})};return{init:()=>{l.isInitialized||(l.isInitialized=!0,p(),m(),h(),g(),_(),l.cleanupBroadcastSetup=r().setup(),l.cleanupFocusSetup=ae().setup(),l.cleanupOnlineSetup=ce().setup())},cleanup:()=>{l.isInitialized&&(l.pollInterval&&=(clearInterval(l.pollInterval),void 0),l.unsubscribeBroadcast&&=(l.unsubscribeBroadcast(),void 0),l.unsubscribeFocus&&=(l.unsubscribeFocus(),void 0),l.unsubscribeOnline&&=(l.unsubscribeOnline(),void 0),l.unsubscribeSignal&&=(l.unsubscribeSignal(),void 0),l.cleanupBroadcastSetup&&=(l.cleanupBroadcastSetup(),void 0),l.cleanupFocusSetup&&=(l.cleanupFocusSetup(),void 0),l.cleanupOnlineSetup&&=(l.cleanupOnlineSetup(),void 0),l.isInitialized=!1,l.lastSessionRequest=0)},triggerRefetch:d,broadcastSessionUpdate:f}}var be=Object.create(null),xe=e=>({}),Se=new Proxy(be,{get(e,t){return xe()[t]??be[t]},has(e,t){return t in xe()||t in be},set(e,t,n){let r=xe(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=xe(!0);return delete n[t],!0},ownKeys(){let e=xe(!0);return Object.keys(e)}});Se.NODE_ENV;function y(e,t){return typeof process<`u`?{}[e]??t:typeof Deno<`u`?Deno.env.get(e)??t:typeof Bun<`u`?Bun.env[e]??t:t}Object.freeze({get BETTER_AUTH_SECRET(){return y(`BETTER_AUTH_SECRET`)},get AUTH_SECRET(){return y(`AUTH_SECRET`)},get BETTER_AUTH_TELEMETRY(){return y(`BETTER_AUTH_TELEMETRY`)},get BETTER_AUTH_TELEMETRY_ID(){return y(`BETTER_AUTH_TELEMETRY_ID`)},get NODE_ENV(){return y(`NODE_ENV`,`development`)},get PACKAGE_VERSION(){return y(`PACKAGE_VERSION`,`0.0.0`)},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return y(`BETTER_AUTH_TELEMETRY_ENDPOINT`,``)}});var Ce=1,we=4,Te=8,Ee=24,De={eterm:we,cons25:we,console:we,cygwin:we,dtterm:we,gnome:we,hurd:we,jfbterm:we,konsole:we,kterm:we,mlterm:we,mosh:Ee,putty:we,st:we,"rxvt-unicode-24bit":Ee,terminator:Ee,"xterm-kitty":Ee},Oe=new Map(Object.entries({APPVEYOR:Te,BUILDKITE:Te,CIRCLECI:Ee,DRONE:Te,GITEA_ACTIONS:Ee,GITHUB_ACTIONS:Ee,GITLAB_CI:Te,TRAVIS:Te})),ke=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function Ae(){if(y(`FORCE_COLOR`)!==void 0)switch(y(`FORCE_COLOR`)){case``:case`1`:case`true`:return we;case`2`:return Te;case`3`:return Ee;default:return Ce}if(y(`NODE_DISABLE_COLORS`)!==void 0&&y(`NODE_DISABLE_COLORS`)!==``||y(`NO_COLOR`)!==void 0&&y(`NO_COLOR`)!==``||y(`TERM`)===`dumb`)return Ce;if(y(`TMUX`))return Ee;if(`TF_BUILD`in Se&&`AGENT_NAME`in Se)return we;if(`CI`in Se){for(let{0:e,1:t}of Oe)if(e in Se)return t;return y(`CI_NAME`)===`codeship`?Te:Ce}if(`TEAMCITY_VERSION`in Se)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(y(`TEAMCITY_VERSION`))===null?Ce:we;switch(y(`TERM_PROGRAM`)){case`iTerm.app`:return!y(`TERM_PROGRAM_VERSION`)||/^[0-2]\./.exec(y(`TERM_PROGRAM_VERSION`))!==null?Te:Ee;case`HyperTerm`:case`MacTerm`:return Ee;case`Apple_Terminal`:return Te}if(y(`COLORTERM`)===`truecolor`||y(`COLORTERM`)===`24bit`)return Ee;if(y(`TERM`)){if(/truecolor/.exec(y(`TERM`))!==null)return Ee;if(/^xterm-256/.exec(y(`TERM`))!==null)return Te;let e=y(`TERM`).toLowerCase();if(De[e])return De[e];if(ke.some(t=>t.exec(e)!==null))return we}return y(`COLORTERM`)?we:Ce}var je=Symbol.for(`better-auth:global`),Me=null,Ne={},Pe=`1.7.5`;function Fe(){return globalThis[je]||(globalThis[je]={version:Pe,epoch:1,context:Ne},Me=globalThis[je]),Me=globalThis[je],Me.version!==Pe&&(Me.version=Pe,Me.epoch++),globalThis[je]}function Ie(){return Fe().context.endpointContextAsyncStorage?.getStore()}var Le={reset:`\x1B[0m`,bright:`\x1B[1m`,dim:`\x1B[2m`,undim:`\x1B[22m`,underscore:`\x1B[4m`,blink:`\x1B[5m`,reverse:`\x1B[7m`,hidden:`\x1B[8m`,fg:{black:`\x1B[30m`,red:`\x1B[31m`,green:`\x1B[32m`,yellow:`\x1B[33m`,blue:`\x1B[34m`,magenta:`\x1B[35m`,cyan:`\x1B[36m`,white:`\x1B[37m`},bg:{black:`\x1B[40m`,red:`\x1B[41m`,green:`\x1B[42m`,yellow:`\x1B[43m`,blue:`\x1B[44m`,magenta:`\x1B[45m`,cyan:`\x1B[46m`,white:`\x1B[47m`}},Re=[`debug`,`info`,`success`,`warn`,`error`];function ze(e,t){return Re.indexOf(t)>=Re.indexOf(e)}var Be={info:Le.fg.blue,success:Le.fg.green,warn:Le.fg.yellow,error:Le.fg.red,debug:Le.fg.magenta},Ve=(e,t,n)=>{let r=new Date().toISOString();return n?`${Le.dim}${r}${Le.reset} ${Be[e]}${e.toUpperCase()}${Le.reset} ${Le.bright}[Better Auth]:${Le.reset} ${t}`:`${r} ${e.toUpperCase()} [Better Auth]: ${t}`},He=(e=>{let t=e?.disabled!==!0,n=e?.level??`warn`,r=e?.disableColors===void 0?Ae()!==1:!e.disableColors,i=(i,a,o=[])=>{if(!t||!ze(n,i))return;let s=Ve(i,a,r);if(!e||typeof e.log!=`function`){i===`error`?console.error(s,...o):i===`warn`?console.warn(s,...o):console.log(s,...o);return}e.log(i===`success`?`info`:i,a,...o)};return{...Object.fromEntries(Re.map(e=>[e,(...[t,...n])=>i(e,t,n)])),get level(){return n}}})(),Ue=()=>{let e=Ie()?.context.logger;return e&&e!==We?e:He},We={debug:(...e)=>Ue().debug(...e),info:(...e)=>Ue().info(...e),success:(...e)=>Ue().success(...e),warn:(...e)=>Ue().warn(...e),error:(...e)=>Ue().error(...e),get level(){return Ue().level}};function Ge(){let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.prototype.hasOwnProperty.call(e,`writable`)?e.writable:e.set!==void 0}function Ke(e){let t=e.split(`
2
+ at `);return t.length<=1?e:(t.splice(1,1),t.join(`
3
+ at `))}function qe(e,t){class n extends e{#e;constructor(...e){if(Ge()){let t=Error.stackTraceLimit;Error.stackTraceLimit=0,super(...e),Error.stackTraceLimit=t}else super(...e);let t=Error().stack;t&&(this.#e=Ke(t.replace(/^Error/,this.name)))}get errorStack(){return this.#e}}return Object.defineProperty(n.prototype,"constructor",{get(){return t},enumerable:!1,configurable:!0}),n}var Je={OK:200,CREATED:201,ACCEPTED:202,NO_CONTENT:204,MULTIPLE_CHOICES:300,MOVED_PERMANENTLY:301,FOUND:302,SEE_OTHER:303,NOT_MODIFIED:304,TEMPORARY_REDIRECT:307,BAD_REQUEST:400,UNAUTHORIZED:401,PAYMENT_REQUIRED:402,FORBIDDEN:403,NOT_FOUND:404,METHOD_NOT_ALLOWED:405,NOT_ACCEPTABLE:406,PROXY_AUTHENTICATION_REQUIRED:407,REQUEST_TIMEOUT:408,CONFLICT:409,GONE:410,LENGTH_REQUIRED:411,PRECONDITION_FAILED:412,PAYLOAD_TOO_LARGE:413,URI_TOO_LONG:414,UNSUPPORTED_MEDIA_TYPE:415,RANGE_NOT_SATISFIABLE:416,EXPECTATION_FAILED:417,"I'M_A_TEAPOT":418,MISDIRECTED_REQUEST:421,UNPROCESSABLE_ENTITY:422,LOCKED:423,FAILED_DEPENDENCY:424,TOO_EARLY:425,UPGRADE_REQUIRED:426,PRECONDITION_REQUIRED:428,TOO_MANY_REQUESTS:429,REQUEST_HEADER_FIELDS_TOO_LARGE:431,UNAVAILABLE_FOR_LEGAL_REASONS:451,INTERNAL_SERVER_ERROR:500,NOT_IMPLEMENTED:501,BAD_GATEWAY:502,SERVICE_UNAVAILABLE:503,GATEWAY_TIMEOUT:504,HTTP_VERSION_NOT_SUPPORTED:505,VARIANT_ALSO_NEGOTIATES:506,INSUFFICIENT_STORAGE:507,LOOP_DETECTED:508,NOT_EXTENDED:510,NETWORK_AUTHENTICATION_REQUIRED:511};qe(class extends Error{status;body;headers;statusCode;constructor(e=`INTERNAL_SERVER_ERROR`,t=void 0,n={},r=typeof e==`number`?e:Je[e]){super(t?.message,t?.cause?{cause:t.cause}:void 0),this.status=e,this.body=t,this.headers=n,this.statusCode=r,this.name=`APIError`,this.status=e,this.headers=n,this.statusCode=r,this.body=t}},Error);var Ye=class extends Error{constructor(e,t){super(e,t),this.name=`BetterAuthError`,this.message=e,this.stack=``}},Xe=47;function Ze(e){let t=e.length;for(;t>0&&e.charCodeAt(t-1)===Xe;)t--;return t===e.length?e:e.slice(0,t)}function Qe(e){try{return(Ze(new URL(e).pathname)||`/`)!==`/`}catch{throw new Ye(`Invalid base URL: ${e}. Please provide a valid base URL.`)}}function $e(e){try{let t=new URL(e);if(t.protocol!==`http:`&&t.protocol!==`https:`)throw new Ye(`Invalid base URL: ${e}. URL must include 'http://' or 'https://'`)}catch(t){throw t instanceof Ye?t:new Ye(`Invalid base URL: ${e}. Please provide a valid base URL.`,{cause:t})}}function et(e,t=`/api/auth`){if($e(e),Qe(e))return e;let n=Ze(e);return!t||t===`/`?n:(t=t.startsWith(`/`)?t:`/${t}`,`${n}${t}`)}function tt(e,t){return!e||e.trim()===``?!1:t===`proto`?e===`http`||e===`https`:t===`host`?[/\.\./,/\0/,/[\s]/,/^[.]/,/[<>'"]/,/javascript:/i,/file:/i,/data:/i].some(t=>t.test(e))?!1:/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*(:[0-9]{1,5})?$/.test(e)||/^(\d{1,3}\.){3}\d{1,3}(:[0-9]{1,5})?$/.test(e)||/^\[[0-9a-fA-F:]+\](:[0-9]{1,5})?$/.test(e)||/^localhost(:[0-9]{1,5})?$/i.test(e):!1}function nt(e,t,n,r,i){if(e)return et(e,t);if(r!==!1){let e=Se.BETTER_AUTH_URL||Se.NEXT_PUBLIC_BETTER_AUTH_URL||Se.PUBLIC_BETTER_AUTH_URL||Se.NUXT_PUBLIC_BETTER_AUTH_URL||Se.NUXT_PUBLIC_AUTH_URL||(Se.BASE_URL===`/`?void 0:Se.BASE_URL);if(e)return et(e,t)}let a=n?.headers.get(`x-forwarded-host`),o=n?.headers.get(`x-forwarded-proto`);if(a&&o&&i&&tt(o,`proto`)&&tt(a,`host`))try{return et(`${o}://${a}`,t)}catch{}if(n){let e=rt(n.url);if(!e)throw new Ye(`Could not get origin from request. Please provide a valid base URL.`);return et(e,t)}if(typeof window<`u`&&window.location)return et(window.location.origin,t)}function rt(e){try{let t=new URL(e);return t.origin===`null`?null:t.origin}catch{return null}}var it=[`javascript:`,`data:`,`vbscript:`];function at(e){let t;try{t=new URL(e)}catch{return!0}return!it.includes(t.protocol)}var ot={id:`redirect`,name:`Redirect`,hooks:{onSuccess(e){if(e.data?.url&&e.data?.redirect&&at(e.data.url)&&typeof window<`u`&&window.location&&window.location)try{window.location.href=e.data.url}catch{}}}},st=()=>typeof window>`u`,ct=_;function lt(e,t){if(typeof window>`u`)return;let n=e.get();n.data===null&&t!==null&&e.set({...n,data:t,error:null,isPending:!1})}function ut(e){return typeof e==`object`&&e&&`data`in e&&`error`in e?e:{data:e,error:null}}function dt(e){return!e||e.session===null&&e.user===null?null:e}function ft(e,t){return te(e.data,t.data)&&e.error===t.error&&e.isPending===t.isPending&&e.isRefetching===t.isRefetching&&e.refetch===t.refetch}function pt(e,t){let n=u(!1),r,i=0,a=0;n.listen(()=>{a++,i=0});let o=e=>d(e),s=u({data:null,error:null,isPending:!0,isRefetching:!1,refetch:o});ne(s,ft);let c=async(t,n)=>{let r=s.value;if(s.set({...r,isPending:r.data===null,isRefetching:!0,error:null,refetch:o}),t.aborted)return`aborted`;try{let r=await e(`/get-session`,{method:`GET`,query:n?.query,signal:t});if(t.aborted)return`aborted`;let{data:i,error:a}=ut(r),c=`fresh`;if(i?.needsRefresh)try{let n=await e(`/get-session`,{method:`POST`,signal:t});if(t.aborted)return`aborted`;({data:i,error:a}=ut(n))}catch{if(t.aborted)return`aborted`;c=`stale`}if(a){let e=s.value,t=a?.status===401;return s.set({data:t?null:e.data,error:a,isPending:!1,isRefetching:!1,refetch:o}),`failed`}let l=dt(i),u=s.value,d=u.data!=null&&l!=null&&te(u.data,l)?u.data:l;return s.set({data:d,error:null,isPending:!1,isRefetching:!1,refetch:o}),c}catch(e){if(t.aborted)return`aborted`;let n=s.value;return s.set({data:n.data,error:e,isPending:!1,isRefetching:!1,refetch:o}),`failed`}},l=()=>{let e=s.value.data?.session?.expiresAt,t=e instanceof Date?e.getTime():1/0;return Math.min(Date.now()+ct,t)},d=e=>{i=0,r?.cancel();let t=new AbortController,n={cancel:()=>t.abort(),promise:Promise.resolve().then(()=>t.signal.aborted?`aborted`:c(t.signal,e)),revision:a};r=n;let o=e=>{r===n&&(r=void 0,e===`fresh`&&n.revision===a&&(i=l()))};return n.promise.then(o,()=>o(`failed`)),n.promise.then(()=>void 0)},f=()=>r?.revision===a?r.promise.then(()=>void 0):Date.now()<i?Promise.resolve():d(),p=()=>{};return ee(s,()=>{let e;st()||(e=setTimeout(()=>{f()},0));let r=ye({fetchSession:d,shouldPollSession:()=>s.value.data!=null,sessionSignal:n,options:t});return r.init(),p=r.broadcastSessionUpdate,()=>{e&&clearTimeout(e),r.cleanup()}}),{session:s,$sessionSignal:n,broadcastSessionUpdate:e=>p(e)}}function mt(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function ht(e,t,n=`.`,r){if(!mt(t))return ht(e,{},n,r);let i={...t};for(let t of Object.keys(e)){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(i[t]=Array.isArray(a)&&Array.isArray(i[t])?[...a,...i[t]]:mt(a)&&mt(i[t])?ht(a,i[t],(n?`${n}.`:``)+t.toString(),r):a))}return i}function gt(e){return(...t)=>t.reduce((t,n)=>ht(t,n,``,e),{})}var _t=gt(),vt=class extends Error{constructor(e,t,n){super(t||e.toString(),{cause:n}),this.status=e,this.statusText=t,this.error=n,Error.captureStackTrace(this,this.constructor)}},yt=async(e,t)=>{let n=t||{},r={onRequest:[t?.onRequest],onResponse:[t?.onResponse],onSuccess:[t?.onSuccess],onError:[t?.onError],onRetry:[t?.onRetry]};if(!t||!t?.plugins)return{url:e,options:n,hooks:r};for(let i of t?.plugins||[]){if(i.init){let t=await i.init?.call(i,e.toString(),n);n=t.options||n,e=t.url}r.onRequest.push(i.hooks?.onRequest),r.onResponse.push(i.hooks?.onResponse),r.onSuccess.push(i.hooks?.onSuccess),r.onError.push(i.hooks?.onError),r.onRetry.push(i.hooks?.onRetry)}return{url:e,options:n,hooks:r}},bt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(){return this.options.delay}},xt=class{constructor(e){this.options=e}shouldAttemptRetry(e,t){return this.options.shouldRetry?Promise.resolve(e<this.options.attempts&&this.options.shouldRetry(t)):Promise.resolve(e<this.options.attempts)}getDelay(e){return Math.min(this.options.maxDelay,this.options.baseDelay*2**e)}};function St(e){if(typeof e==`number`)return new bt({type:`linear`,attempts:e,delay:1e3});switch(e.type){case`linear`:return new bt(e);case`exponential`:return new xt(e);default:throw Error(`Invalid retry strategy`)}}var Ct=[`get`,`post`,`put`,`patch`,`delete`];function wt(e){if(!e.startsWith(`@`))return{method:void 0,path:e};let t=e.indexOf(`/`),n=e.slice(1,t===-1?void 0:t);return Ct.includes(n)?{method:n,path:t===-1?e:e.slice(t+1)}:{method:void 0,path:e}}var Tt=e=>e===`.`||e===`..`,Et=e=>e.split(`:`).map(e=>encodeURIComponent(e)).join(`:`);function Dt(e,t){let n=t.get(e);if(n===void 0)return Et(e);if(Tt(n))throw TypeError(`Path parameters cannot be reserved path segments`);return encodeURIComponent(n)}function Ot(e,t){let{baseURL:n,params:r,query:i}=t||{query:{},params:{},baseURL:``},a=e.startsWith(`http`)?e.split(`/`).slice(0,3).join(`/`):n||``,{path:o}=wt(e);o!==e&&(e=`/${o}`),a.endsWith(`/`)||(a+=`/`);let[s,c]=e.replace(a,``).split(`?`),l=new URLSearchParams(c);for(let[e,t]of Object.entries(i||{})){if(t==null)continue;let n;if(typeof t==`string`)n=t;else if(Array.isArray(t)){for(let n of t)l.append(e,n);continue}else n=JSON.stringify(t);l.set(e,n)}let u=new Map;if(r){if(Array.isArray(r)){let e=s.split(`/`).filter(e=>e.startsWith(`:`));for(let[t,n]of e.entries()){let e=r[t];u.set(n,String(e))}}else for(let[e,t]of Object.entries(r))u.set(`:${e}`,String(t))}s=s.split(`/`).map(e=>Dt(e,u)).join(`/`),s=s.replace(/^\/+/,``);let d=l.toString();return d=d.length>0?`?${d}`.replace(/\+/g,`%20`):``,a.startsWith(`http`)?new URL(`${s}${d}`,a):`${a}${s}${d}`}var kt=async e=>{let t={},n=async e=>typeof e==`function`?await e():e;if(e?.auth){if(e.auth.type===`Bearer`){let r=await n(e.auth.token);if(!r)return t;t.authorization=`Bearer ${r}`}else if(e.auth.type===`Basic`){let[r,i]=await Promise.all([n(e.auth.username),n(e.auth.password)]);if(!r||!i)return t;t.authorization=`Basic ${btoa(`${r}:${i}`)}`}else if(e.auth.type===`Custom`){let[r,i]=await Promise.all([n(e.auth.prefix),n(e.auth.value)]);if(!i)return t;t.authorization=`${r??``} ${i}`}}return t},At=/^application\/(?:[\w!#$%&*.^`~-]*\+)?json(;.+)?$/i;function jt(e){let t=e.headers.get(`content-type`),n=new Set([`image/svg`,`application/xml`,`application/xhtml`,`application/html`]);if(!t)return`json`;let r=t.split(`;`).shift()||``;return At.test(r)?`json`:n.has(r)||r.startsWith(`text/`)?`text`:`blob`}function Mt(e){try{return JSON.parse(e),!0}catch{return!1}}function Nt(e){if(e===void 0)return!1;let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===null?!0:t===`object`?Array.isArray(e)?!0:e.buffer?!1:e.constructor&&e.constructor.name===`Object`||typeof e.toJSON==`function`:!1}function Pt(e){try{return JSON.parse(e)}catch{return e}}function Ft(e){return typeof e==`function`}function It(e){if(e?.customFetchImpl)return e.customFetchImpl;if(typeof globalThis<`u`&&Ft(globalThis.fetch))return globalThis.fetch;if(typeof window<`u`&&Ft(window.fetch))return window.fetch;throw Error(`No fetch implementation found`)}function Lt(...e){let t={};for(let n of e)if(n){if(n instanceof Headers)n.forEach((e,n)=>{t[n]=e});else{let e=Array.isArray(n)?n:Object.entries(n);for(let[n,r]of e)r!=null&&(t[n]=r)}}return t}async function Rt(e){let t=new Headers(Lt(e?.headers,await kt(e)));if(!t.has(`content-type`)){let n=zt(e?.body);n&&t.set(`content-type`,n)}return t}function zt(e){return Nt(e)?`application/json`:null}function Bt(e){let t=e.get(`content-type`);return t?t.split(`;`)[0].trim().toLowerCase():null}function Vt(e,t){let{body:n}=e;return n?!Nt(n)||typeof n==`string`?n:Bt(t)===`application/x-www-form-urlencoded`?new URLSearchParams(n).toString():JSON.stringify(n):null}function Ht(e,t){if(t?.method)return t.method.toUpperCase();let{method:n}=wt(e);return n?n.toUpperCase():t?.body?`POST`:`GET`}function Ut(e,t){let n;return!e?.signal&&e?.timeout&&(n=setTimeout(()=>t?.abort(),e?.timeout)),{abortTimeout:n,clearTimeout:()=>{n&&clearTimeout(n)}}}var Wt=class e extends Error{constructor(t,n){super(n||JSON.stringify(t,null,2)),this.issues=t,Object.setPrototypeOf(this,e.prototype)}};async function Gt(e,t){let n=await e[`~standard`].validate(t);if(n.issues)throw new Wt(n.issues);return n.value}function Kt(e){"@babel/helpers - typeof";return Kt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},Kt(e)}function qt(e,t){if(Kt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(Kt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Jt(e){var t=qt(e,`string`);return Kt(t)==`symbol`?t:t+``}function Yt(e,t,n){return(t=Jt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Xt(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]==null?{}:arguments[t];t%2?Xt(Object(n),!0).forEach(function(t){Yt(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Xt(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var Zt=async(e,t)=>{var n;let{hooks:r,url:i,options:a}=await yt(e,t),o=It(a),s=new AbortController,c=a.signal??s.signal,l=Ot(i,a),u=await Rt(a),d=Vt(a,u),f=Ht(i,a),p=b(b({},a),{},{url:l,headers:u,body:d,method:f,signal:c});for(let e of r.onRequest)if(e){let t=await e(p);typeof t==`object`&&t&&Object.assign(p,t)}(`pipeTo`in p&&typeof p.pipeTo==`function`||typeof(t==null||(n=t.body)==null?void 0:n.pipe)==`function`)&&(`duplex`in p||(p.duplex=`half`));let{clearTimeout:m}=Ut(a,s),h=await o(p.url,p);m();let g={response:h,request:p};for(let e of r.onResponse)if(e){var _;let n=await e(b(b({},g),{},{response:t!=null&&(_=t.hookOptions)!=null&&_.cloneResponse?h.clone():h}));n instanceof Response?h=n:typeof n==`object`&&n&&(h=n.response)}if(h.ok){if(p.method===`HEAD`)return{data:``,error:null};let e=jt(h),n={data:null,response:h,request:p};if(e===`json`||e===`text`){let e=await h.text();n.data=await(p.jsonParser??Pt)(e)}else n.data=await h[e]();p?.output&&p.output&&!p.disableValidation&&(n.data=await Gt(p.output,n.data));for(let e of r.onSuccess)if(e){var ee;await e(b(b({},n),{},{response:t!=null&&(ee=t.hookOptions)!=null&&ee.cloneResponse?h.clone():h}))}return t?.throw?n.data:{data:n.data,error:null}}let v=t?.jsonParser??Pt,te=await h.text(),ne=Mt(te),re=ne?await v(te):null,ie={response:h,responseText:te,request:p,error:b(b({},re),{},{status:h.status,statusText:h.statusText})};for(let e of r.onError)if(e){var ae;await e(b(b({},ie),{},{response:t!=null&&(ae=t.hookOptions)!=null&&ae.cloneResponse?h.clone():h}))}if(t?.retry){let n=St(t.retry),i=t.retryAttempt??0;if(await n.shouldAttemptRetry(i,h)){for(let e of r.onRetry)e&&await e(g);let a=n.getDelay(i);return await new Promise(e=>setTimeout(e,a)),await Zt(e,b(b({},t),{},{retryAttempt:i+1}))}}if(t?.throw)throw new vt(h.status,h.statusText,ne?re:te);return{data:null,error:b(b({},re),{},{status:h.status,statusText:h.statusText})}},Qt=e=>({id:`apply-schema`,name:`Apply Schema`,version:`1.0.0`,async init(t,n){var r;let i=b(b({},n),e.query!==void 0&&{query:b(b({},e.query),n?.query)}),a=((r=e.plugins)==null||(r=r.find(e=>e.schema?.config?t.startsWith(e.schema.config.baseURL||``)||t.startsWith(e.schema.config.prefix||``):!1))==null?void 0:r.schema)||e.schema;if(a){let r=t;a.config?.prefix&&r.startsWith(a.config.prefix)&&(r=r.replace(a.config.prefix,``),a.config.baseURL&&(t=t.replace(a.config.prefix,a.config.baseURL))),a.config?.baseURL&&r.startsWith(a.config.baseURL)&&(r=r.replace(a.config.baseURL,``)),r.startsWith(`/`)&&r.charAt(1)===`@`&&(r=r.substring(1));let o=a.schema[r];if(o){let{method:a,path:s}=wt(r);a&&(t=t.slice(0,t.length-r.length)+s);let c=n?.headers;if(o.headers&&!n?.disableValidation){let e={};if(n?.headers){if(n.headers instanceof Headers)n.headers.forEach((t,n)=>{e[n.toLowerCase()]=t});else if(typeof n.headers==`object`)for(let[t,r]of Object.entries(n.headers))r!=null&&(e[t.toLowerCase()]=r)}let t=await Gt(o.headers,e),r={};for(let[e,n]of Object.entries(t))r[e.toLowerCase()]=n;c=r}let l=o.method??a;if(i=b(b(b(b({},i),l!==void 0&&{method:l}),o.output!==void 0&&{output:o.output}),c!==void 0&&{headers:c}),!n?.disableValidation){if(o.query&&(i.query=await Gt(o.query,n?.query),i.query!==null&&typeof i.query==`object`)){let t=b({},e.query);for(let e of Object.keys(t))n?.query&&Object.prototype.hasOwnProperty.call(n.query,e)&&(t[e]=n.query[e]);i.query=b(b({},t),i.query)}i=b(b({},i),{},{body:o.input?await Gt(o.input,n?.body):n?.body,params:o.params?await Gt(o.params,n?.params):n?.params})}return{url:t,options:i}}}return b({url:t},(n!==void 0||e.query!==void 0)&&{options:i})}}),$t=e=>{async function t(t,n){let r=b(b(b({},e),n),{},{headers:Lt(e?.headers,n?.headers),plugins:[...e?.plugins||[],Qt(e||{}),...n?.plugins||[]]});if(e?.catchAllError)try{return await Zt(t,r)}catch(e){return{data:null,error:{status:500,statusText:`Fetch Error`,message:`Fetch related error. Captured by catchAllError option. See error property for more details.`,error:e}}}return await Zt(t,r)}return t},en=e=>{if(typeof process>`u`)return;let t=e??`/api/auth`;if({}.NEXT_PUBLIC_AUTH_URL)return{}.NEXT_PUBLIC_AUTH_URL;if(typeof window>`u`){if({}.NEXTAUTH_URL)try{return{}.NEXTAUTH_URL}catch{}if({}.VERCEL_URL)try{let e={}.VERCEL_URL.startsWith(`http`)?``:`https://`;return`${new URL(`${e}${{}.VERCEL_URL}`).origin}${t}`}catch{}}},tn=(e,t)=>{let n=`credentials`in Request.prototype,r=nt(e?.baseURL,e?.basePath,void 0,t)??en(e?.basePath)??`/api/auth`,i=e?.plugins?.flatMap(e=>e.fetchPlugins).filter(e=>e!==void 0)||[],a={id:`lifecycle-hooks`,name:`lifecycle-hooks`,hooks:{onSuccess:e?.fetchOptions?.onSuccess,onError:e?.fetchOptions?.onError,onRequest:e?.fetchOptions?.onRequest,onResponse:e?.fetchOptions?.onResponse}},{onSuccess:o,onError:s,onRequest:c,onResponse:l,...u}=e?.fetchOptions||{},d=$t({baseURL:r,...n?{credentials:`include`}:{},method:`GET`,jsonParser(e){return e?ge(e,{strict:!1}):null},customFetchImpl:fetch,...u,plugins:[a,...u.plugins||[],...e?.disableDefaultFetchPlugins?[]:[ot],...i]}),{$sessionSignal:f,session:p,broadcastSessionUpdate:m}=pt(d,e),h=!1,g=e=>{h||e===null||(h=!0,lt(p,e))},_=e?.plugins||[],ee={},v={$sessionSignal:f,session:p},te={"/sign-out":`POST`,"/revoke-sessions":`POST`,"/revoke-other-sessions":`POST`,"/delete-user":`POST`},ne=[{signal:`$sessionSignal`,matcher(e){return e===`/sign-out`||e===`/update-user`||e===`/update-session`||e===`/sign-up/email`||e===`/sign-in/email`||e===`/delete-user`||e===`/verify-email`||e===`/revoke-sessions`||e===`/revoke-session`||e===`/revoke-other-sessions`||e===`/change-email`||e===`/change-password`},callback(e){e===`/sign-out`?m(`signout`):(e===`/update-user`||e===`/update-session`)&&m(`updateUser`)}}];for(let e of _)e.getAtoms&&Object.assign(v,e.getAtoms?.(d)),e.pathMethods&&Object.assign(te,e.pathMethods),e.atomListeners&&ne.push(...e.atomListeners);let re={notify:e=>{v[e].set(!v[e].get())},listen:(e,t)=>{v[e].subscribe(t)},atoms:v};for(let t of _)t.getActions&&(ee=_t(t.getActions?.(d,re,e)??{},ee));return{get baseURL(){return r},pluginsActions:ee,pluginsAtoms:v,pluginPathMethods:te,atomListeners:ne,hydrateSession:g,$sessionSignal:f,$fetch:d,$store:re}};function nn(e){return typeof e==`object`&&!!e&&`get`in e&&typeof e.get==`function`&&`lc`in e&&typeof e.lc==`number`}function rn(e){return e.charAt(0).toUpperCase()+e.slice(1)}var an=/[\p{Ll}\d]+|\p{Lu}+(?!\p{Ll})|\p{Lu}[\p{Ll}\d]+|\p{Lo}+/gu,on=/['\u2019]/g;function sn(e){return e.replace(on,``).match(an)??[]}function cn(e){return sn(e).map(e=>e.toLowerCase()).join(`-`)}function ln(e,t,n){let r=t[e],{fetchOptions:i,query:a,...o}=n||{};return r||(i?.method?i.method:o&&Object.keys(o).length>0?`POST`:`GET`)}function un(e,t,n,r,i){function a(o=[]){return new Proxy(function(){},{get(t,n){if(typeof n!=`string`||n===`then`||n===`catch`||n===`finally`)return;let r=[...o,n],i=e;for(let e of r)if(i&&typeof i==`object`&&e in i)i=i[e];else{i=void 0;break}return typeof i==`function`||nn(i)?i:a(r)},apply:async(e,a,s)=>{let c=`/`+o.map(cn).join(`/`),l=s[0]||{},u=s[1]||{},{query:d,fetchOptions:f,...p}=l,m={...u,...f},h=ln(c,n,l);return await t(c,{...m,body:h===`GET`?void 0:{...p,...m?.body||{}},query:d||m?.query,method:h,async onSuccess(e){if(await m?.onSuccess?.(e),!i||m.disableSignal)return;let t=i.filter(e=>e.matcher(c));if(!t.length)return;let n=new Set;for(let e of t){let t=r[e.signal];if(!t)return;if(n.has(e.signal))continue;n.add(e.signal);let i=t.get();setTimeout(()=>{t.set(!i)},10),e.callback?.(c)}}})}})}return a()}function dn(e){let{pluginPathMethods:t,pluginsActions:n,pluginsAtoms:r,hydrateSession:i,$fetch:a,atomListeners:o,$store:s}=tn(e),c={};for(let[e,t]of Object.entries(r))c[`use${rn(e)}`]=t;return un({...n,...c,hydrateSession:i,$fetch:a,$store:s},a,t,r,o)}var fn=`ba_param`;function pn(e){let t=e.getAll(fn);if(t.length)return new Set(t)}function mn(e){let t=new URLSearchParams(e);if(!t.has(`sig`))return;let n=pn(t);if(!n)return;let r=new URLSearchParams;for(let[e,i]of t.entries())(e===`sig`||e===fn||n.has(e))&&r.append(e,i);return r.toString()}var hn=`1.7.5`,gn=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;function _n(e){if(typeof e==`string`&&gn.test(e)){let t=new Date(e);if(!isNaN(t.getTime()))return t}return e}function vn(e){if(e==null)return e;if(typeof e==`string`)return _n(e);if(e instanceof Date)return e;if(Array.isArray(e))return e.map(vn);if(typeof e==`object`){let t={};for(let n of Object.keys(e))t[n]=vn(e[n]);return t}return e}function yn(e){try{return typeof e==`string`?JSON.parse(e,(e,t)=>_n(t)):e==null?null:vn(e)}catch(e){return We.error(`Error parsing JSON`,{error:e}),null}}var bn=()=>({id:`oauth-provider-client`,version:hn,fetchPlugins:[{id:`oauth-provider-signin`,name:`oauth-provider-signin`,description:`Adds the current page query to oauth requests`,hooks:{async onRequest(e){let t=e.headers,n=typeof e.body==`string`?t.get(`content-type`)===`application/x-www-form-urlencoded`?Object.fromEntries(new URLSearchParams(e.body)):yn(e.body??`{}`):e.body;n?.oauth_query||typeof window<`u`&&window?.location?.search&&e.method!==`GET`&&e.method!==`DELETE`&&(e.body=JSON.stringify({...n,oauth_query:mn(window.location.search)}))}}}],$InferServerPlugin:{}}),x=(e,t)=>{switch(t.length){case 0:return e;case 1:return t[0](e);case 2:return t[1](t[0](e));case 3:return t[2](t[1](t[0](e)));case 4:return t[3](t[2](t[1](t[0](e))));case 5:return t[4](t[3](t[2](t[1](t[0](e)))));case 6:return t[5](t[4](t[3](t[2](t[1](t[0](e))))));case 7:return t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))));case 8:return t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e))))))));case 9:return t[8](t[7](t[6](t[5](t[4](t[3](t[2](t[1](t[0](e)))))))));default:{let n=e;for(let e=0,r=t.length;e<r;e++)n=t[e](n);return n}}},xn={pipe(){return x(this,arguments)}},Sn=function(){function e(){}return e.prototype=xn,e}(),S=function(e,t){if(typeof e==`function`)return function(){return e(arguments)?t.apply(this,arguments):e=>t(e,...arguments)};switch(e){case 0:case 1:throw RangeError(`Invalid arity ${e}`);case 2:return function(e,n){return arguments.length>=2?t(e,n):function(n){return t(n,e)}};case 3:return function(e,n,r){return arguments.length>=3?t(e,n,r):function(r){return t(r,e,n)}};default:return function(){if(arguments.length>=e)return t.apply(this,arguments);let n=arguments;return function(e){return t(e,...n)}}}},C=e=>e,Cn=e=>()=>e,wn=Cn(!0),Tn=Cn(!1),En=Cn(void 0),Dn=En;function On(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),i}}function kn(e){let t=new WeakMap;return n=>{let r=t.get(n);if(r!==void 0)return r;let i=e(n);return t.set(n,i),t.set(i,i),i}}var An=e=>{let t=new Set(Reflect.ownKeys(e));if(e.constructor===Object)return t;e instanceof Error&&t.delete(`stack`);let n=Object.getPrototypeOf(e),r=n;for(;r!==null&&r!==Object.prototype;){let e=Reflect.ownKeys(r);for(let n=0;n<e.length;n++)t.add(e[n]);r=Object.getPrototypeOf(r)}return t.has(`constructor`)&&typeof e.constructor==`function`&&n===e.constructor.prototype&&t.delete(`constructor`),t},jn=new WeakSet;function Mn(e){return typeof e==`string`}function Nn(e){return typeof e==`number`}function Pn(e){return typeof e==`boolean`}function Fn(e){return typeof e==`symbol`}function In(e){return Mn(e)||Nn(e)||Fn(e)}function Ln(e){return typeof e==`function`}function Rn(e){return e!=null}function zn(e){return!1}function Bn(e){return!0}function Vn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Hn(e){return typeof e==`object`&&!!e||Ln(e)}var w=S(2,(e,t)=>Hn(e)&&t in e);function Un(e){return e instanceof Error}var Wn=`~effect/Hash`,T=e=>{switch(typeof e){case`number`:return Yn(e);case`bigint`:return Xn(e.toString(10));case`string`:return Xn(e);case`undefined`:return Xn(`undefined`);case`function`:case`object`:if(e===null)return Xn(`null`);if(e instanceof Date)return Number.isNaN(e.getTime())?Xn(`Invalid Date`):Xn(e.toISOString());if(e instanceof RegExp)return Xn(e.toString());{if(jn.has(e))return Gn(e);if(ir.has(e))return ir.get(e);let t=or(e,()=>Jn(e)?e[Wn]():typeof e==`function`?Gn(e):e instanceof DataView?er(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)):Array.isArray(e)||ArrayBuffer.isView(e)?er(e):e instanceof Map?tr(e):e instanceof Set?nr(e):Qn(e));return ir.set(e,t),t}default:return Xn(String(e))}},Gn=e=>(rr.has(e)||rr.set(e,Yn(Math.floor(Math.random()*(2**53-1)))),rr.get(e)),Kn=S(2,(e,t)=>e*53^t),qn=e=>e&3221225471|e>>>1&1073741824,Jn=e=>w(e,Wn),Yn=e=>{if(e!==e||e===1/0||e===-1/0)return Xn(String(e));let t=e|0;for(t!==e&&(t^=e*4294967295);e>4294967295;)t^=e/=4294967295;return qn(t)},Xn=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return qn(t)},Zn=(e,t)=>{let n=12289;for(let r of t)n^=Kn(T(r),T(e[r]));return qn(n)},Qn=e=>Zn(e,An(e)),$n=(e,t)=>n=>{let r=e;for(let e of n)r^=t(e);return qn(r)},er=$n(6151,T),tr=$n(Xn(`Map`),([e,t])=>Kn(T(e),T(t))),nr=$n(Xn(`Set`),T),rr=new WeakMap,ir=new WeakMap,ar=new WeakSet;function or(e,t){if(ar.has(e))return Xn(`[Circular]`);ar.add(e);let n=t();return ar.delete(e),n}var sr=`~effect/Equal`;function cr(){return arguments.length===1?e=>lr(e,arguments[0]):lr(arguments[0],arguments[1])}function lr(e,t){if(e===t)return!0;if(e==null||t==null)return!1;let n=typeof e;return n===typeof t?n===`number`&&e!==e&&t!==t?!0:n!==`object`&&n!==`function`||jn.has(e)||jn.has(t)?!1:mr(e,t,pr):!1}function ur(e,t,n){let r=dr.has(e),i=fr.has(t);if(r&&i)return!0;if(r||i)return!1;dr.add(e),fr.add(t);let a=n();return dr.delete(e),fr.delete(t),a}var dr=new WeakSet,fr=new WeakSet;function pr(e,t){if(T(e)!==T(t))return!1;if(e instanceof Date){if(!(t instanceof Date))return!1;let n=e.getTime(),r=t.getTime();return n===r||Number.isNaN(n)&&Number.isNaN(r)}if(e instanceof RegExp)return t instanceof RegExp&&e.toString()===t.toString();let n=Cr(e),r=Cr(t);if(n!==r)return!1;let i=n&&r;return typeof e==`function`&&!i?!1:ur(e,t,()=>{if(i)return e[sr](t);if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:gr(e,t);if(ArrayBuffer.isView(e)){let n=e instanceof DataView;if(!ArrayBuffer.isView(t)||e.byteLength!==t.byteLength||n!==t instanceof DataView)return!1;if(n){let n=t;return _r(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(n.buffer,n.byteOffset,n.byteLength))}return _r(e,t)}return e instanceof Map?!(t instanceof Map)||e.size!==t.size?!1:br(e,t):e instanceof Set?!(t instanceof Set)||e.size!==t.size?!1:Sr(e,t):vr(e,t)})}function mr(e,t,n){let r=hr.get(e);if(!r)r=new WeakMap,hr.set(e,r);else if(r.has(t))return r.get(t);let i=n(e,t);r.set(t,i);let a=hr.get(t);return a||(a=new WeakMap,hr.set(t,a)),a.set(e,i),i}var hr=new WeakMap;function gr(e,t){for(let n=0;n<e.length;n++)if(!lr(e[n],t[n]))return!1;return!0}function _r(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function vr(e,t){let n=An(e),r=An(t);if(n.size!==r.size)return!1;for(let i of n)if(!r.has(i)||!lr(e[i],t[i]))return!1;return!0}function yr(e,t){return function(n,r){let i=Array.from(r);for(let[r,a]of n){let n=!1;for(let o=0;o<i.length;o++){let[s,c]=i[o];if(e(r,s)&&t(a,c)){i[o]=i[i.length-1],i.pop(),n=!0;break}}if(!n)return!1}return!0}}var br=yr(lr,lr);function xr(e){return function(t,n){let r=Array.from(n);for(let n of t){let t=!1;for(let i=0;i<r.length;i++){let a=r[i];if(e(n,a)){r[i]=r[r.length-1],r.pop(),t=!0;break}}if(!t)return!1}return!0}}var Sr=xr(lr),Cr=e=>w(e,sr),wr=e=>(t,n)=>t===n||e(t,n),Tr=(e,t)=>e===t,Er=()=>Tr;function Dr(e){return wr((t,n)=>{if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e[r](t[r],n[r]))return!1;return!0})}function Or(e){return wr((t,n)=>{if(t.length!==n.length)return!1;for(let r=0;r<t.length;r++)if(!e(t[r],n[r]))return!1;return!0})}var kr=e=>e.length>0;function E(e,t,n){t===`__proto__`?Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[t]=n}function Ar(e,t){for(let n of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,n)&&E(e,n,t[n])}var jr=Symbol.for(`~effect/Redactable`),Mr=e=>w(e,jr);function Nr(e){return Mr(e)?Pr(e):e}function Pr(e){return e[jr](globalThis[`~effect/Fiber/currentFiber`]?.context??Lr)}var Fr=`~effect/Fiber/currentFiber`,Ir=new Map,Lr={"~effect/Context":{},base:Ir,depth:0,mapUnsafe:Ir,pipe(){return x(this,arguments)}};function D(e,t){let n=t?.space??0,r=new WeakSet,i=n?typeof n==`number`?` `.repeat(n):n:``,a=e=>i.repeat(e),o=(e,t)=>{let n=e?.constructor;return n&&n!==Object.prototype.constructor&&n.name?`${n.name}(${t})`:t},s=e=>{try{return Reflect.ownKeys(e)}catch{return[`[ownKeys threw]`]}};function c(e,t=0){try{return l(e,t)}catch{return(typeof e==`object`&&e||typeof e==`function`)&&r.delete(e),`[inspection threw]`}}function l(e,n=0){if(typeof e==`string`)return JSON.stringify(e);if(typeof e==`number`||e==null||typeof e==`boolean`||typeof e==`symbol`)return String(e);if(typeof e==`bigint`)return String(e)+`n`;if(typeof e==`object`||typeof e==`function`){if(r.has(e))return Rr;r.add(e);let l;if(jr in e)l=c(Pr(e),n);else if(Array.isArray(e))l=!i||e.length<=1?`[${e.map(e=>c(e,n)).join(`,`)}]`:`[\n${a(n+1)}${e.map(e=>c(e,n+1)).join(`,
4
+ `+a(n+1))}\n${a(n)}]`;else if(e instanceof Date)l=Vr(e);else if(!t?.ignoreToString&&w(e,`toString`)&&typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=Hr(e);l=e instanceof Error&&e.cause!==void 0?`${t} (cause: ${c(e.cause,n)})`:t}else if(Symbol.iterator in e)l=`${e.constructor.name}(${c(Array.from(e),n)})`;else{let t=s(e);if(!i||t.length<=1){let r=`{${t.map(t=>`${zr(t)}:${c(Ur(e,t),n)}`).join(`,`)}}`;l=o(e,r)}else{let r=`{\n${t.map(t=>`${a(n+1)}${zr(t)}: ${c(Ur(e,t),n+1)}`).join(`,
5
+ `)}\n${a(n)}}`;l=o(e,r)}}return r.delete(e),l}return String(e)}return c(e,0)}var Rr=`[Circular]`;function zr(e){return typeof e==`string`?JSON.stringify(e):String(e)}function Br(e){return e.map(e=>`[${zr(e)}]`).join(``)}function Vr(e){try{return e.toISOString()}catch{return`Invalid Date`}}function Hr(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function Ur(e,t){try{return e[t]}catch{return`[property access threw]`}}function Wr(e,t){let n=[];return JSON.stringify(e,function(e,t){let r=Object.getOwnPropertyDescriptor(this,e)?.value,i=w(r,jr)?Nr(r):Nr(t);if(typeof i==`bigint`)return D(i);if(typeof i!=`object`||!i)return i;for(;n.length>0&&n[n.length-1]!==this;)n.pop();if(!n.includes(i))return n.push(i),i},t?.space)??`null`}var Gr=Symbol.for(`nodejs.util.inspect.custom`),Kr=e=>{try{return e=Nr(e),w(e,`toJSON`)&&Ln(e.toJSON)&&e.toJSON.length===0?e.toJSON():Array.isArray(e)?e.map(Kr):e}catch{return`[toJSON threw]`}},qr={toJSON(){return Kr(this)},[Gr](){return this.toJSON()},toString(){return D(this.toJSON())}},Jr=class{[Gr](){return this.toJSON()}toString(){return D(this.toJSON())}},Yr=(()=>{let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.hasOwn(e,`writable`)?e.writable===!0:e.set!==void 0})(),Xr=()=>Error.stackTraceLimit,Zr=e=>{Yr&&(Error.stackTraceLimit=e)},Qr=class e{called=!1;self;constructor(e){this.self=e}next(e){return this.called?{value:e,done:!0}:(this.called=!0,{value:this.self,done:!1})}[Symbol.iterator](){return new e(this.self)}},$r=(()=>{let e=`~effect/Utils/internal`,t={[e]:e=>e()},n={[e]:e=>{try{return e()}finally{}}};return Xr()!==0&&t[e](()=>Error().stack)?.includes(e)===!0?t[e]:n[e]})(),ei=`~effect/Effect`,ti=`~effect/Exit`,ni={_A:C,_E:C,_R:C},ri=`${ei}/identifier`,O=`${ei}/args`,k=`${ei}/evaluate`,ii=`${ei}/successCont`,ai=`${ei}/failureCont`,oi=`${ei}/ensureCont`,si=Symbol.for(`effect/Effect/Yield`),ci={pipe(){return x(this,arguments)},toJSON(){return{...this}},toString(){return D(this.toJSON(),{ignoreToString:!0,space:2})},[Gr](){return this.toJSON()}},li={[ei]:ni,...ci,[Symbol.iterator](){return new Qr(this)},toJSON(){return{_id:`Effect`,op:this[ri],...O in this?{args:this[O]}:void 0}}},ui=e=>w(e,ei),di=e=>w(e,ti),fi=`~effect/Cause`,pi=`~effect/Cause/Reason`,mi=e=>w(e,fi),hi=e=>w(e,pi),gi=class{constructor(e){this[fi]=fi,this.reasons=e}pipe(){return x(this,arguments)}toJSON(){return{_id:`Cause`,failures:this.reasons.map(e=>e.toJSON())}}toString(){return`Cause(${D(this.reasons)})`}[Gr](){return this.toJSON()}[sr](e){return mi(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,n)=>cr(t,e.reasons[n]))}[Wn](){return er(this.reasons)}},_i=new WeakMap,vi=class{[pi];annotations;_tag;constructor(e,t,n){if(this[pi]=pi,this._tag=e,t!==yi&&typeof n==`object`&&n&&t.size>0){let e=_i.get(n);e&&(t=new Map([...e,...t])),_i.set(n,t)}this.annotations=t}annotate(e,t){if(e.mapUnsafe.size===0)return this;let n=new Map(this.annotations);e.mapUnsafe.forEach((e,r)=>{t?.overwrite!==!0&&n.has(r)||n.set(r,e)});let r=Object.assign(Object.create(Object.getPrototypeOf(this)),this);return r.annotations=n,r}pipe(){return x(this,arguments)}toString(){return D(this)}[Gr](){return this.toString()}},yi=new Map,bi=class extends vi{constructor(e,t=yi){super(`Fail`,t,e),this.error=e}toString(){return`Fail(${D(this.error)})`}toJSON(){return{_tag:`Fail`,error:this.error}}[sr](e){return Ei(e)&&cr(this.error,e.error)&&cr(this.annotations,e.annotations)}[Wn](){return Kn(Xn(this._tag))(Kn(T(this.error))(T(this.annotations)))}},xi=e=>new gi(e),Si=e=>new gi([new bi(e)]),Ci=class extends vi{constructor(e,t=yi){super(`Die`,t,e),this.defect=e}toString(){return`Die(${D(this.defect)})`}toJSON(){return{_tag:`Die`,defect:this.defect}}[sr](e){return Di(e)&&cr(this.defect,e.defect)&&cr(this.annotations,e.annotations)}[Wn](){return Kn(Xn(this._tag))(Kn(T(this.defect))(T(this.annotations)))}},wi=e=>new gi([new Ci(e)]),Ti=S(e=>mi(e[0]),(e,t,n)=>t.mapUnsafe.size===0?e:new gi(e.reasons.map(e=>e.annotate(t,n)))),Ei=e=>e._tag===`Fail`,Di=e=>e._tag===`Die`,Oi=e=>e._tag===`Interrupt`;function ki(e){return Li(`Effect.evaluate: Not implemented`)}var Ai=e=>({...li,[ri]:e.op,[k]:e[k]??ki,[ii]:e[ii],[ai]:e[ai],[oi]:e[oi]}),ji=e=>{let t=Ai(e),n=function(e){this[O]=e};return n.prototype=t,function(e){return new n(e)}},Mi=e=>{let t={[ti]:ti,_tag:e.op,get[e.prop](){return this[O]},...Ai(e),toString(){return`${e.op}(${D(this[O])})`},toJSON(){return{_id:`Exit`,_tag:e.op,[e.prop]:this[O]}},[sr](e){return di(e)&&e._tag===this._tag&&cr(this[O],e[O])},[Wn](){return Kn(Xn(e.op),T(this[O]))}},n=function(e){this[O]=e};return n.prototype=t,function(e){return new n(e)}},A=Mi({op:`Success`,prop:`value`,[k](e){let t=e.getCont(ii);return t?t[ii](this[O],e,this):e.yieldWith(this)}}),Ni={key:`effect/Cause/StackTrace`},Pi={key:`effect/Cause/InterruptorStackTrace`},Fi=Mi({op:`Failure`,prop:`cause`,[k](e){let t=this[O],n=!1;e.cache.stackFrame&&(t=Ti(t,{mapUnsafe:new Map([[Ni.key,e.cache.stackFrame]])}),n=!0);let r=e.getCont(ai);for(;e.interruptible&&e._interruptedCause&&r;)r=e.getCont(ai);return r?r[ai](t,e,n?void 0:this):e.yieldWith(n?Fi(t):this)}}),Ii=e=>Fi(Si(e)),Li=e=>Fi(wi(e)),j=ji({op:`WithFiber`,[k](e){return this[O](e)}}),Ri=function(){class e extends globalThis.Error{}let t=Ai({op:`YieldableError`,[k](){return Ii(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),zi=function(){let e=Symbol.for(`effect/Data/Error/plainArgs`);return class extends Ri{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(Ar(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}(),Bi=e=>{class t extends zi{_tag=e}return t.prototype.name=e,t},Vi=`~effect/Cause/Done`,Hi=e=>w(e,Vi),Ui={[Vi]:Vi,_tag:`Done`,value:void 0},Wi=e=>e===void 0?Ui:{[Vi]:Vi,_tag:`Done`,value:e},Gi=Ii(Ui),Ki=e=>e===void 0?Gi:Ii(Wi(e)),qi=`~effect/Option`,Ji={[qi]:{_A:e=>e},...ci,[Symbol.iterator](){return new Qr(this)}},Yi=Object.defineProperty(Object.assign(Object.create(Ji),{_tag:`Some`,_op:`Some`,[sr](e){return Qi(e)&&ea(e)&&cr(this.value,e.value)},[Wn](){return Kn(T(this._tag))(T(this.value))},toString(){return`some(${D(this.value)})`},toJSON(){return{_id:`Option`,_tag:this._tag,value:Kr(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),Xi=T(`None`),Zi=Object.assign(Object.create(Ji),{_tag:`None`,_op:`None`,valueOrUndefined:void 0,[sr](e){return Qi(e)&&$i(e)},[Wn](){return Xi},toString(){return`none()`},toJSON(){return{_id:`Option`,_tag:this._tag}}}),Qi=e=>w(e,qi),$i=e=>e._tag===`None`,ea=e=>e._tag===`Some`,ta=Object.create(Zi),na=function(e){this.value=e};na.prototype=Yi;var ra=e=>new na(e),ia=`~effect/Result`,aa={[ia]:{_A:e=>e,_E:e=>e},...ci,[Symbol.iterator](){return new Qr(this)}},oa=Object.assign(Object.create(aa),{_tag:`Success`,_op:`Success`,[sr](e){return ca(e)&&ua(e)&&cr(this.success,e.success)},[Wn](){return Kn(T(this._tag))(T(this.success))},toString(){return`success(${D(this.success)})`},toJSON(){return{_id:`Result`,_tag:this._tag,value:Kr(this.success)}}}),sa=Object.assign(Object.create(aa),{_tag:`Failure`,_op:`Failure`,[sr](e){return ca(e)&&la(e)&&cr(this.failure,e.failure)},[Wn](){return Kn(T(this._tag))(T(this.failure))},toString(){return`failure(${D(this.failure)})`},toJSON(){return{_id:`Result`,_tag:this._tag,failure:Kr(this.failure)}}}),ca=e=>w(e,ia),la=e=>e._tag===`Failure`,ua=e=>e._tag===`Success`,da=function(e){this.failure=e};da.prototype=sa;var fa=e=>new da(e),pa=function(e){this.success=e};pa.prototype=oa;var ma=e=>new pa(e);function ha(e){return(t,n)=>t===n?0:e(t,n)}var ga=ha((e,t)=>globalThis.Number.isNaN(e)&&globalThis.Number.isNaN(t)?0:globalThis.Number.isNaN(e)?-1:globalThis.Number.isNaN(t)?1:e<t?-1:1),_a=S(2,(e,t)=>ha((n,r)=>e(t(n),t(r)))),va=e=>S(2,(t,n)=>e(t,n)===-1),ya=e=>S(2,(t,n)=>e(t,n)===1),ba=e=>S(2,(t,n)=>e(t,n)!==1),xa=e=>S(2,(t,n)=>e(t,n)!==-1),Sa=()=>ta,Ca=ra,wa=$i,Ta=ea,Ea=S(2,(e,{onNone:t,onSome:n})=>wa(e)?t():n(e.value)),Da=S(2,(e,t)=>wa(e)?t():e.value),Oa=e=>e==null?Sa():Ca(e),ka=Da(En),Aa=e=>(...t)=>{try{return Ca(e(...t))}catch{return Sa()}},ja=S(2,(e,t)=>wa(e)?Sa():Ca(t(e.value))),Ma=ma,Na=fa,Pa=e=>{if(Ln(e))try{return Ma(e())}catch(e){return Na(e)}try{return Ma(e.try())}catch(t){return Na(e.catch(t))}},Fa=la,Ia=ua,La=S(2,(e,t)=>Ia(e)?Ma(t(e.success)):e),Ra=S(2,(e,{onFailure:t,onSuccess:n})=>Fa(e)?t(e.failure):n(e.success)),za=S(2,(e,t)=>Fa(e)?t(e.failure):e.success)(En),Ba=Dr,Va=S(2,(e,t)=>Object.hasOwn(e,t)),Ha=S(2,(e,t)=>{let n={...e};for(let r of Ua(e))E(n,r,t(e[r],r));return n}),Ua=e=>Object.keys(e),Wa=e=>S(2,(t,n)=>{for(let r of Ua(t))if(!Va(n,r)||!e(t[r],n[r]))return!1;return!0}),Ga=e=>{let t=Wa(e);return(e,n)=>t(e,n)&&t(n,e)},Ka=globalThis.Array,qa=e=>Ka.isArray(e)?e:Ka.from(e),Ja=e=>Ka.isArray(e)?e:[e],Ya=S(2,(e,t)=>[...e,t]),Xa=S(2,(e,t)=>qa(e).concat(qa(t)));Ka.isArray;var Za=kr,Qa=kr,$a=()=>[],eo=e=>[e],to=S(2,(e,t)=>e.map(t)),no=Or,ro=`~effect/BigDecimal`,io={[ro]:ro,[Wn](){let e=po(this);return Kn(T(e.value),Yn(e.scale))},[sr](e){return ao(e)&&So(this,e)},toString(){return`BigDecimal(${Co(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[Gr](){return this.toJSON()},pipe(){return x(this,arguments)}},ao=e=>w(e,ro),oo=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(io);return n.value=e,n.scale=t,n},so=(e,t)=>{if(e!==co&&e%uo===co)throw RangeError(`Value must be normalized`);let n=oo(e,t);return n.normalized=n,n},co=BigInt(0),lo=BigInt(1),uo=BigInt(10),fo=so(co,0),po=e=>{if(e.normalized===void 0){if(e.value===co)e.normalized=fo;else{let t=`${e.value}`,n=0;for(let e=t.length-1;e>=0&&t[e]===`0`;e--)n++;n===0&&(e.normalized=e),e.normalized=so(BigInt(t.substring(0,t.length-n)),e.scale-n)}}return e.normalized},mo=100,ho=[lo],go=(e,t)=>e===t?0:e<t?-1:1,_o=(e,t)=>{let n=`${e.value<co?-e.value:e.value}`,r=`${t.value<co?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==co)return i<co?-1:1;let a=Math.max(n.length,r.length);for(let e=0;e<a;e++){let t=e<n.length?n.charCodeAt(e):48,i=e<r.length?r.charCodeAt(e):48;if(t!==i)return t<i?-1:1}return 0},vo=(e,t)=>{if(e.scale===t.scale)return go(e.value,t.value);let n=yo(e),r=yo(t);if(n!==r)return n<r?-1:1;if(n===0)return 0;let i=e.scale-t.scale,a=Math.abs(i);if(a>mo)return n===-1?_o(t,e):_o(e,t);let o=ho[a]??=uo**BigInt(a);return i>0?go(e.value,t.value*o):go(e.value*o,t.value)},yo=e=>e.value===co?0:e.value<co?-1:1,bo=e=>e.value<co?oo(-e.value,e.scale):e,xo=wr((e,t)=>vo(e,t)===0),So=S(2,(e,t)=>xo(e,t)),Co=e=>{let t=po(e);if(Math.abs(t.scale)>=16)return wo(t);let n=t.value<co,r=n?`${t.value}`.substring(1):`${t.value}`,i,a;if(t.scale>=r.length)i=`0`,a=`0`.repeat(t.scale-r.length)+r;else{let e=r.length-t.scale;if(e>r.length){let t=e-r.length;i=`${r}${`0`.repeat(t)}`,a=``}else a=r.slice(e),i=r.slice(0,e)}let o=a===``?i:`${i}.${a}`;return n?`-${o}`:o},wo=e=>{if(To(e))return`0e+0`;let t=po(e),n=`${bo(t).value}`,r=n.slice(0,1),i=n.slice(1),a=`${Eo(t)?`-`:``}${r}`;i!==``&&(a+=`.${i}`);let o=i.length-t.scale;return`${a}e${o>=0?`+`:``}${o}`},To=e=>e.value===co,Eo=e=>e.value<co,Do=e=>Ai({op:e.label,[k]:e.evaluate}),Oo=`~effect/Context/Service`,M=function(){function e(){}let t=e;Object.setPrototypeOf(t,ko);let n=(e,n)=>(t.key=e,n?.defaultValue&&(t[jo]=jo,t.defaultValue=n.defaultValue),n?.make&&(t.make=n.make),n?.fiberCached&&Ao.add(e),t);return arguments.length>0?n(arguments[0],arguments[1]):n},ko={[Oo]:Oo,...Do({label:`Service`,evaluate(e){return A(ts(e.context,this))}}),toJSON(){return{_id:`Service`,key:this.key}},of(e){return e},context(e){return Jo(this,e)},use(e){return j(t=>e(ts(t.context,this)))},useSync(e){return j(t=>A(e(ts(t.context,this))))}},Ao=new Set,jo=`~effect/Context/Reference`,Mo=`~effect/Context`,No=8,Po=8,Fo=(e,t,n,r)=>{let i=Object.create(Ho);return i.cacheRoot=e??i,i.base=t,i.overlay=n,i.depth=r,i._flat=void 0,i.baseHits=0,i},Io=(e,t)=>{t&&(Io(e,t.parent),e.set(t.key,t.value))},Lo=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return Io(t,e.overlay),e._flat=t},Ro=(e,t)=>{let n=new Map(e.mapUnsafe);return t(n),Vo(n)},zo=Symbol(),Bo=(e,t)=>{let n=e;for(let e=n.overlay;e;e=e.parent)if(e.key===t)return e.value;let r=n.base.get(t);return r===void 0&&!n.base.has(t)?zo:(n.overlay&&++n.baseHits>=Po&&(n.base=Lo(n),n.overlay=void 0,n.depth=0),r)},Vo=e=>Fo(void 0,e,void 0,0),Ho={get mapUnsafe(){return Lo(this)},...ci,[Mo]:{_Services:e=>e},toJSON(){return{_id:`Context`,services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[sr](e){if(!Wo(e))return!1;let t=this.mapUnsafe,n=e.mapUnsafe;if(t.size!==n.size)return!1;for(let[e,r]of t)if(!n.has(e)||!cr(r,n.get(e)))return!1;return!0},[Wn](){return Yn(this.mapUnsafe.size)}},Uo=(e,t)=>e.cacheRoot===t.cacheRoot,Wo=e=>w(e,Mo),Go=e=>!!e[jo],Ko=()=>qo,qo=Vo(new Map),Jo=(e,t)=>Vo(new Map([[e.key,t]])),Yo=S(3,(e,t,n)=>Xo(e,t.key,n)),Xo=(e,t,n)=>{let r=e,i=Ao.has(t)?void 0:r.cacheRoot;if(r.depth>=No){let e=new Map(r.mapUnsafe);return e.set(t,n),Fo(i,e,void 0,0)}return Fo(i,r.base,{key:t,value:n,parent:r.overlay},r.depth+1)},Zo=S(3,(e,t,n)=>{let r=Bo(e,t.key);return r===zo?Go(t)?rs(t):n():r}),Qo=S(2,(e,t)=>$o(e,t.key)),$o=(e,t)=>{let n=Bo(e,t);return n===zo?void 0:n},es=S(2,(e,t)=>{let n=Bo(e,t.key);if(n===zo){if(Go(t))return rs(t);throw is(t)}return n}),ts=es,ns=`~effect/Context/defaultValue`,rs=e=>ns in e?e[ns]:e[ns]=e.defaultValue(),is=e=>{let t=Error(`Service not found${e.key?`: ${String(e.key)}`:``}`);if(t.stack){let e=t.stack.split(`
6
+ `);e.splice(1,3),t.stack=e.join(`
7
+ `)}return t},as=S(2,(e,t)=>{let n=Bo(e,t.key);return n===zo?Go(t)?Ca(rs(t)):Sa():Ca(n)}),os=S(2,(e,t)=>e.mapUnsafe.size===0?t:t.mapUnsafe.size===0?e:Ro(e,e=>t.mapUnsafe.forEach((t,n)=>e.set(n,t)))),ss=(...e)=>{let t=new Map;for(let n=0;n<e.length;n++)e[n].mapUnsafe.forEach((e,n)=>{t.set(n,e)});return Vo(t)},cs=(...e)=>t=>Ro(t,t=>{for(let n=0;n<e.length;n++)t.delete(e[n].key)}),N=M,ls=`~effect/Duration`,us=BigInt(0),ds=BigInt(1),fs=BigInt(2),ps=BigInt(10),ms=BigInt(1e3),hs=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),gs=e=>hs(e*1e6),_s=(e,t)=>{let n=e.indexOf(`.`);if(n===-1)return BigInt(e)*t;let r=e[0]===`-`,i=e.slice(n+1),a=ps**BigInt(i.length),o=(BigInt(e.slice(+!!r,n))*a+BigInt(i))*t,s=o/a+(o%a*fs>=a?ds:us);return r?-s:s},vs=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,ys=e=>{switch(typeof e){case`number`:return js(e);case`bigint`:return As(e);case`string`:{if(e===`Infinity`)return Os;if(e===`-Infinity`)return ks;let t=vs.exec(e);if(!t)break;let[n,r,i]=t;if(i===`nano`||i===`nanos`)return As(_s(r,ds));if(i===`micro`||i===`micros`)return As(_s(r,ms));let a=Number(r);switch(i){case`milli`:case`millis`:return js(a);case`second`:case`seconds`:return Ms(a);case`minute`:case`minutes`:return Ns(a);case`hour`:case`hours`:return Ps(a);case`day`:case`days`:return Fs(a);case`week`:case`weeks`:return Is(a)}break}case`object`:{if(e===null)break;if(ls in e)return e;if(Array.isArray(e))return e.length!==2||!e.every(Nn)?bs(e):Number.isNaN(e[0])||Number.isNaN(e[1])?Ds:e[0]===-1/0||e[1]===-1/0?ks:e[0]===1/0||e[1]===1/0?Os:Ts(hs(e[0]*1e9+e[1]));let t=e,n=0;return t.weeks&&(n+=t.weeks*6048e5),t.days&&(n+=t.days*864e5),t.hours&&(n+=t.hours*36e5),t.minutes&&(n+=t.minutes*6e4),t.seconds&&(n+=t.seconds*1e3),t.milliseconds&&(n+=t.milliseconds),!t.microseconds&&!t.nanoseconds?Ts(n):Ts(hs(n*1e6+(t.microseconds??0)*1e3+(t.nanoseconds??0)))}}return bs(e)},bs=e=>{throw Error(`Invalid Input: ${e}`)},xs={_tag:`Millis`,millis:0},Ss={_tag:`Infinity`},Cs={_tag:`NegativeInfinity`},ws={[ls]:ls,[Wn](){switch(this.value._tag){case`Millis`:{let e=this.value.millis*1e6;return Number.isFinite(e)?T(hs(e)):Yn(this.value.millis)}case`Nanos`:return T(this.value.nanos);default:return Qn(this.value)}},[sr](e){return Es(e)&&Hs(this,e)},toString(){switch(this.value._tag){case`Infinity`:return`Infinity`;case`NegativeInfinity`:return`-Infinity`;case`Nanos`:return`${this.value.nanos} nanos`;case`Millis`:return`${this.value.millis} millis`}},toJSON(){switch(this.value._tag){case`Millis`:return{_id:`Duration`,_tag:`Millis`,millis:this.value.millis};case`Nanos`:return{_id:`Duration`,_tag:`Nanos`,nanos:String(this.value.nanos)};case`Infinity`:return{_id:`Duration`,_tag:`Infinity`};case`NegativeInfinity`:return{_id:`Duration`,_tag:`NegativeInfinity`}}},[Gr](){return this.toJSON()},pipe(){return x(this,arguments)}},Ts=e=>{let t=Object.create(ws);return t.value=typeof e==`number`?isNaN(e)||e===0||Object.is(e,-0)?xs:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:gs(e)}:e>0?Ss:Cs:e===us?xs:{_tag:`Nanos`,nanos:e},t},Es=e=>w(e,ls),Ds=Ts(0),Os=Ts(1/0),ks=Ts(-1/0),As=e=>Ts(e),js=e=>Ts(e),Ms=e=>Ts(e*1e3),Ns=e=>Ts(e*6e4),Ps=e=>Ts(e*36e5),Fs=e=>Ts(e*864e5),Is=e=>Ts(e*6048e5),Ls=e=>zs(ys(e),{onMillis:C,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),Rs=e=>{let t=ys(e);switch(t.value._tag){case`Infinity`:case`NegativeInfinity`:throw Error(`Cannot convert infinite duration to nanos`);case`Nanos`:return t.value.nanos;case`Millis`:return gs(t.value.millis)}},zs=S(2,(e,t)=>{switch(e.value._tag){case`Millis`:return t.onMillis(e.value.millis);case`Nanos`:return t.onNanos(e.value.nanos);case`Infinity`:return t.onInfinity();case`NegativeInfinity`:return(t.onNegativeInfinity??t.onInfinity)()}}),Bs=S(3,(e,t,n)=>e.value._tag===`Infinity`||e.value._tag===`NegativeInfinity`||t.value._tag===`Infinity`||t.value._tag===`NegativeInfinity`?n.onInfinity(e,t):e.value._tag===`Millis`?t.value._tag===`Millis`?n.onMillis(e.value.millis,t.value.millis):n.onNanos(Rs(e),t.value.nanos):n.onNanos(e.value.nanos,Rs(t))),Vs=(e,t)=>Bs(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag}),Hs=S(2,(e,t)=>Vs(e,t)),Us=N(`effect/Scheduler`,{fiberCached:!0,defaultValue:()=>new Js}),Ws=e=>{let t=!1;return Promise.resolve().then(()=>{t||e()}),()=>{t=!0}},Gs=`setImmediate`in globalThis?e=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:e=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},Ks=e=>{try{return Gs(e)}catch{return Ws(e)}},qs=class{buckets=[];scheduleTask(e,t){let n=this.buckets,r=n.length,i,a=0;for(;a<r&&!(n[a][0]>t);a++)i=n[a];i&&i[0]===t?i[1].push(e):a===r?n.push([t,[e]]):n.splice(a,0,[t,[e]])}drain(){let e=this.buckets;return this.buckets=[],e}},Js=class{executionMode;setImmediate;constructor(e=`async`,t){this.executionMode=e,this.setImmediate=t??(e===`sync`?Ws:Ks)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new Ys(this.setImmediate)}},Ys=class{tasks=new qs;running=void 0;setImmediate;constructor(e=Ks){this.setImmediate=e}scheduleTask(e,t){this.tasks.scheduleTask(e,t),this.running===void 0&&(this.running=this.setImmediate(this.afterScheduled))}afterScheduled=()=>{this.running=void 0,this.runTasks()};runTasks(){let e=this.tasks.drain();for(let t=0;t<e.length;t++){let n=e[t][1];for(let e=0;e<n.length;e++)n[e]()}}flush(){for(;this.tasks.buckets.length>0;)this.running!==void 0&&(this.running(),this.running=void 0),this.runTasks()}},Xs=N(`effect/Scheduler/MaxOpsBeforeYield`,{fiberCached:!0,defaultValue:()=>2048}),Zs=N(`effect/Scheduler/PreventSchedulerYield`,{fiberCached:!0,defaultValue:()=>!1}),Qs=class extends Sn{constructor(e){super(),e&&Ar(this,e)}},$s=e=>class extends Qs{_tag=e},ec=Bi,tc=`~effect/Encoding/EncodingError`,nc=class extends ec(`EncodingError`){[tc]=tc},rc=e=>mc(typeof e==`string`?dc.encode(e):e),ic=e=>{let t=pc(e),n=t.length;if(n%4!=0)return Na(new nc({kind:`Decode`,module:`Base64`,input:t,message:`Length must be a multiple of 4, but is ${n}`}));let r=t.indexOf(`=`);if(r!==-1&&(r<n-2||r===n-2&&t[n-1]!==`=`))return Na(new nc({kind:`Decode`,module:`Base64`,input:t,message:`Found a '=' character, but it is not at the end`}));try{let e=t.endsWith(`==`)?2:+!!t.endsWith(`=`),r=new Uint8Array(n/4*3-e);for(let e=0,i=0;e<n;e+=4,i+=3){let n=hc(t.charCodeAt(e))<<18|hc(t.charCodeAt(e+1))<<12|hc(t.charCodeAt(e+2))<<6|hc(t.charCodeAt(e+3));r[i]=n>>16,r[i+1]=n>>8&255,r[i+2]=n&255}return Ma(r)}catch(e){return Na(new nc({kind:`Decode`,module:`Base64`,input:t,message:e instanceof Error?e.message:`Invalid input`}))}},ac=e=>La(ic(e),e=>fc.decode(e)),oc=e=>{switch(e){case 16:return lc();case 32:return uc();default:{let t=``;for(let n=e>>>3;n>0;n--)t+=cc();return t}}},P=Uint8Array.from(`0123456789abcdef`,e=>e.charCodeAt(0)),sc=()=>Math.random()*4294967296>>>0,cc=()=>{let e=sc();return String.fromCharCode(P[e>>>28],P[e>>>24&15],P[e>>>20&15],P[e>>>16&15],P[e>>>12&15],P[e>>>8&15],P[e>>>4&15],P[e&15])},lc=()=>{let e=sc(),t=sc();return String.fromCharCode(P[e>>>28],P[e>>>24&15],P[e>>>20&15],P[e>>>16&15],P[e>>>12&15],P[e>>>8&15],P[e>>>4&15],P[e&15],P[t>>>28],P[t>>>24&15],P[t>>>20&15],P[t>>>16&15],P[t>>>12&15],P[t>>>8&15],P[t>>>4&15],P[t&15])},uc=()=>{let e=sc(),t=sc(),n=sc(),r=sc();return String.fromCharCode(P[e>>>28],P[e>>>24&15],P[e>>>20&15],P[e>>>16&15],P[e>>>12&15],P[e>>>8&15],P[e>>>4&15],P[e&15],P[t>>>28],P[t>>>24&15],P[t>>>20&15],P[t>>>16&15],P[t>>>12&15],P[t>>>8&15],P[t>>>4&15],P[t&15],P[n>>>28],P[n>>>24&15],P[n>>>20&15],P[n>>>16&15],P[n>>>12&15],P[n>>>8&15],P[n>>>4&15],P[n&15],P[r>>>28],P[r>>>24&15],P[r>>>20&15],P[r>>>16&15],P[r>>>12&15],P[r>>>8&15],P[r>>>4&15],P[r&15])},dc=new TextEncoder,fc=new TextDecoder,pc=e=>e.replace(/[\n\r]/g,``),mc=e=>{let t=e.length,n=``,r=2;for(;r<t;r+=3)n+=gc[e[r-2]>>2],n+=gc[(e[r-2]&3)<<4|e[r-1]>>4],n+=gc[(e[r-1]&15)<<2|e[r]>>6],n+=gc[e[r]&63];return r===t+1&&(n+=gc[e[r-2]>>2],n+=gc[(e[r-2]&3)<<4],n+=`==`),r===t&&(n+=gc[e[r-2]>>2],n+=gc[(e[r-2]&3)<<4|e[r-1]>>4],n+=gc[(e[r-1]&15)<<2],n+=`=`),n};function hc(e){if(e>=_c.length)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);let t=_c[e];if(t===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return t}var gc=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),_c=[255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,62,255,255,255,63,52,53,54,55,56,57,58,59,60,61,255,255,255,0,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,255,255,255,255,255,255,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51],vc=`effect/Tracer/ParentSpan`,yc=class extends M()(vc,{fiberCached:!0}){},bc=e=>e,xc=N(`effect/Tracer/DisablePropagation`,{defaultValue:Tn}),Sc=N(`effect/Tracer/CurrentTraceLevel`,{defaultValue:()=>`Info`}),Cc=N(`effect/Tracer/MinimumTraceLevel`,{defaultValue:()=>`All`}),wc=`effect/Tracer`,Tc=N(wc,{fiberCached:!0,defaultValue:()=>Ec}),Ec=bc({span:e=>new Dc(e)}),Dc=class{_tag=`Span`;sampled;name;parent;annotations;links;startTime;kind;status;_traceId=void 0;_spanId=void 0;_attributes=void 0;_events=void 0;constructor(e){this.name=e.name,this.parent=e.parent,this.annotations=e.annotations,this.links=e.links,this.startTime=e.startTime,this.kind=e.kind,this.sampled=e.sampled,this.status={_tag:`Started`,startTime:e.startTime}}get traceId(){return this._traceId??=ka(this.parent)?.traceId??oc(32)}get spanId(){return this._spanId??=oc(16)}get attributes(){return this._attributes??=new Map}get events(){return this._events??=[]}end(e,t){this.status={_tag:`Ended`,endTime:e,exit:t,startTime:this.status.startTime}}attribute(e,t){this.attributes.set(e,t)}event(e,t,n){this.events.push([e,t,n??{}])}addLinks(e){this.links.push(...e)}},Oc=`effect/Metric/FiberRuntimeMetrics`,kc=N(`effect/ErrorReporter/CurrentErrorReporters`,{defaultValue:()=>new Set}),Ac=N(`effect/References/CurrentStackFrame`,{fiberCached:!0,defaultValue:En}),jc=N(`effect/References/TracerEnabled`,{fiberCached:!0,defaultValue:wn}),Mc=N(`effect/References/TracerTimingEnabled`,{defaultValue:wn}),Nc=N(`effect/References/TracerSpanAnnotations`,{defaultValue:()=>({})}),Pc=N(`effect/References/TracerSpanLinks`,{defaultValue:()=>[]}),Fc=N(`effect/References/CurrentLogAnnotations`,{defaultValue:()=>({})}),Ic=N(`effect/References/CurrentLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Lc=N(`effect/References/MinimumLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Rc=e=>{if(e?.captureStackTrace===!1||e?.captureStackTrace!==void 0&&typeof e.captureStackTrace!=`boolean`)return e;let t=Xr();if(t===0&&e?.captureStackTrace!==!0)return{...e,captureStackTrace:!1};Zr(3);let n=Error();return Zr(t),{...e,captureStackTrace:zc(()=>n.stack)}},zc=(e=>t=>{let n;return()=>{if(n!==void 0)return n;let r=t();if(!r)return;let i=r.split(`
8
+ `);if(i[e]!==void 0)return n=i[e].trim(),n}})(3),Bc=class extends vi{constructor(e,t=yi){super(`Interrupt`,t,`Interrupted`),this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:`Interrupt`,fiberId:this.fiberId}}[sr](e){return Oi(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[Wn](){return Kn(Xn(`${this._tag}:${this.fiberId}`))(Gn(this.annotations))}},Vc=e=>new Bc(e),Hc=e=>new gi([new Bc(e)]),Uc=e=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag===`Fail`)return Ma(n.error)}return Na(e)},Wc=e=>e.reasons.some(Di),Gc=e=>e.reasons.some(Oi),Kc=e=>{let t;for(let n=0;n<e.reasons.length;n++){let r=e.reasons[n];r._tag===`Interrupt`&&(t??=new Set,r.fiberId!==void 0&&t.add(r.fiberId))}return t?Ma(t):Na(e)},qc=(e,t)=>{let n=new Map,r=[];for(let i of e.concat(t)){let e=T(i),t=n.get(e);if(t===void 0)n.set(e,[i]);else if(t.some(e=>cr(e,i)))continue;else t.push(i);r.push(i)}return r},Jc=S(2,(e,t)=>{if(e.reasons.length===0)return t;if(t.reasons.length===0)return e;let n=new gi(qc(e.reasons,t.reasons));return cr(e,n)?e:n}),Yc=S(2,(e,t)=>{let n=!1,r=e.reasons.map(e=>Ei(e)?(n=!0,new bi(t(e.error),e.annotations)):e);return n?xi(r):e}),Xc=e=>{let t={Fail:[],Die:[],Interrupt:[]};for(let n=0;n<e.reasons.length;n++)t[e.reasons[n]._tag].push(e.reasons[n]);return t},Zc=e=>{let t=Xc(e);return t.Fail.length>0?t.Fail[0].error:t.Die.length>0?t.Die[0].defect:t.Interrupt.length>0?new globalThis.Error(`All fibers interrupted without error`):new globalThis.Error(`Empty cause`)},Qc=`~effect/Fiber`,$c={_A:C,_E:C},el={id:0},tl=()=>globalThis[Fr],nl=class{constructor(e,t=!0){this[Qc]=$c,this.setContext(e),this.id=++el.id,this.currentOpCount=0,this.interruptible=t,this._stack=[],this._observers=void 0,this._exit=void 0,this._children=void 0,this._interruptedCause=void 0,this._yielded=void 0,this._running=!1,this._deferredInterrupt=!1,this._parent=void 0,this.cache.runtimeMetrics?.recordFiberStart(this.context)}[Qc];id;interruptible;currentOpCount;_stack;_observers;_exit;_children;_interruptedCause;_yielded;_running;_deferredInterrupt;_parent;context;cache;_dispatcher=void 0;get currentDispatcher(){return this._dispatcher??=this.cache.scheduler.makeDispatcher()}getRef(e){return ts(this.context,e)}addObserver(e){return this._exit?(e(this._exit),Dn):(this._observers===void 0?this._observers=[e]:this._observers.push(e),()=>{if(this._exit||this._observers===void 0)return;let t=this._observers.indexOf(e);t>=0&&this._observers.splice(t,1)})}interruptUnsafe(e,t){if(this._exit)return;let n=Hc(e);this.cache.stackFrame&&(n=Ti(n,Jo(Ni,this.cache.stackFrame))),t&&(n=Ti(n,t)),this._interruptedCause=this._interruptedCause?Jc(this._interruptedCause,n):n,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(pl(this._interruptedCause)))}pollUnsafe(){return this._exit}evaluate(e){if(this._exit)return;if(this._yielded!==void 0){let e=this._yielded;this._yielded=void 0,e()}let t=this.runLoop(e);if(t===si)return;let n=al.interruptChildren&&al.interruptChildren(this);if(n!==void 0)return this.evaluate(Kl(n,()=>t));if(this._exit=t,this.cache.runtimeMetrics?.recordFiberEnd(this.context,this._exit),this._parent&&=(this._parent._children?.delete(this),void 0),this._observers!==void 0){let e=this._observers;this._observers=void 0;for(let n=0;n<e.length;n++)e[n](t)}this._stack.length=0,this._children=void 0,this.context=Ko()}runLoop(e){let t=globalThis[Fr];globalThis[Fr]=this;let n=this._running;this._running=!0;let r=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=pl(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!r&&!e.preventYield&&e.scheduler.shouldYield(this)){r=!0;let e=i;i=Kl(gl,()=>e)}if(i=e.tracerContext?e.tracerContext(i,this):i[k](this),i===si){let e=this._yielded;if(ti in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return si}}}catch(e){return w(i,k)?this.runLoop(Li(e)):Li(`Fiber.runLoop: Not a valid effect: ${String(i)}`)}finally{this._running=n,globalThis[Fr]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,il;for(;;){let t=this._stack.pop();if(!t)return;let n=t[oi];if(n!==void 0){let r=n.call(t,this);if(r)return r[e]=r,r}if(t[e])return t}}yieldWith(e){return this._yielded=e,si}children(){return this._children??=new Set}pipe(){return x(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Uo(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=rl(e);this.cache!==void 0&&this.cache.scheduler!==r.scheduler&&(this._dispatcher=void 0),this.cache=r}get currentSpanLocal(){let e=this.cache.span;return e?._tag===`Span`?e:void 0}},rl=e=>{let t=$o(e,wc);return{scheduler:ts(e,Us),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:ts(e,jc),span:$o(e,vc),logLevel:ts(e,Ic),minimumLogLevel:ts(e,Lc),stackFrame:ts(e,Ac),runtimeMetrics:$o(e,Oc),maxOpsBeforeYield:ts(e,Xs),preventYield:ts(e,Zs)}},il={[ii](e,t){return pl(t._interruptedCause)},[ai](e,t){return pl(t._interruptedCause)}},al={interruptChildren:void 0},ol=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(Pi.key,e.cache.stackFrame),Vo(t)},sl=e=>{let t=e;return t._exit?F(t._exit):Dl(n=>t._exit?n(F(t._exit)):I(e.addObserver(e=>n(F(e)))))},cl=e=>Dl(t=>{let n=e[Symbol.iterator](),r=[],i;function a(){let e=n.next();for(;!e.done;){if(e.value._exit){r.push(e.value._exit),e=n.next();continue}i=e.value.addObserver(e=>{r.push(e),a()});return}t(F(r))}return a(),I(()=>i?.())}),ll=e=>{let t=e;return t._exit?t._exit:Dl(n=>t._exit?n(t._exit):I(e.addObserver(n)))},ul=e=>j(t=>dl(e,t.id)),dl=S(e=>w(e[0],Qc),(e,t,n)=>j(r=>{let i=ol(r);return i=i&&n?os(i,n):i??n,e.interruptUnsafe(t,i),Gl(sl(e))})),fl=e=>j(t=>{let n=ol(t),r=$a();for(let i of e)i.interruptUnsafe(t.id,n),r.push(i);return Gl(cl(r))}),F=A,pl=Fi,ml=Ii,I=ji({op:`Sync`,[k](e){let t=this[O](),n=e.getCont(ii);return n?n[ii](t,e):e.yieldWith(A(t))}}),L=ji({op:`Suspend`,[k](e){return this[O]()}}),hl=Ra({onFailure:ml,onSuccess:F}),gl=ji({op:`Yield`,[k](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(nu)},this[O]??0),e.yieldWith(()=>{t=!0})}})(0),_l=F(Sa()),vl=e=>L(()=>pl($r(e))),yl=e=>Li(e),bl=e=>L(()=>ml($r(e))),R=F(void 0),xl=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new ef(e,`An error occurred in Effect.try`):e.catch;return L(()=>{try{return F($r(t))}catch(e){return ml($r(()=>n(e)))}})},Sl=e=>Tl(function(t,n){$r(()=>e(n)).then(e=>t(F(e)),e=>t(yl(e)))},e.length!==0),Cl=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new ef(e,`An error occurred in Effect.tryPromise`):e.catch;return Tl(function(e,r){let i=t=>{try{e(ml($r(()=>n(t))))}catch(t){e(yl(t))}};try{$r(()=>t(r)).then(t=>e(F(t)),i)}catch(e){i(e)}},t.length!==0)},wl=e=>j(t=>e(t.id)),Tl=function(){let e=Ai({op:`Async`,[k](e){let t=$r(()=>this.register.bind(e.cache.scheduler)),n=!1,r=!1,i=this.withSignal?new AbortController:void 0,a=t(t=>{n||(n=!0,r?e.evaluate(t):r=t)},i?.signal);return r===!1?(r=!0,e._yielded=()=>{n=!0},i===void 0&&a===void 0||e._stack.push(El(()=>(n=!0,i?.abort(),a??nu))),si):r}}),t=function(e,t){this.register=e,this.withSignal=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),El=ji({op:`AsyncFinalizer`,[oi](e){e.interruptible&&(e.interruptible=!1,e._stack.push(ad))},[ai](e,t){return Gc(e)?Kl(this[O](),()=>pl(e)):pl(e)}}),Dl=e=>Tl(e,e.length>=2),Ol=Dl(Dn),kl=(...e)=>{if(e.length===1){let t=e[0];return L(()=>Pl(t()))}let[t,n]=e;return L(()=>Pl(n.call(t.self)))},Al=(e,...t)=>{let n=t.length===0?function(){return L(()=>Pl(e.apply(this,arguments)))}:function(){let n=L(()=>Pl(e.apply(this,arguments)));for(let e=0;e<t.length;e++)n=t[e](n,...arguments);return n};return jl(e.length,n)},jl=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),Ml=(e,...t)=>jl(e.length,t.length===0?function(){return Nl(()=>e.apply(this,arguments))}:function(){let n=Nl(()=>e.apply(this,arguments));for(let e of t)n=e(n,...arguments);return n}),Nl=e=>{try{let t=e(),n;for(;;){let r=t.next(n);if(r.done)return F(r.value);let i=r.value;if(i&&i._tag===`Success`){n=i.value;continue}if(i&&i._tag===`Failure`)return r.value;{let n=!0;return L(()=>n?(n=!1,Kl(r.value,e=>Pl(t,e))):L(()=>Pl(e())))}}}catch(e){return yl(e)}},Pl=function(){let e=Ai({op:`Iterator`,[ii](e,t){let n=this.iterator;for(;;){let r=n.next(e);if(r.done)return F(r.value);if(!z(r.value))return t._stack.push(this),r.value;if(r.value._tag===`Failure`)return r.value;e=r.value.value}},[k](e){return this[ii](this.initial,e)}}),t=function(e,t){this.iterator=e,this.initial=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),Fl=S(2,(e,t)=>new zl(e,Bl,F(t))),Il=function(e){return e._stack.push(this),this[O]},Ll=Ai({op:`OnSuccess`,[k]:Il}),Rl=function(e,t){this[O]=e,this[ii]=t};Rl.prototype=Ll;var zl=function(e,t,n){this[O]=e,this[ii]=t,this.payload=n};zl.prototype=Ll;var Bl=function(){return this.payload},Vl=function(e){let t=this.payload;return F($r(()=>t(e)))},Hl=function(e){let t=this.payload;return $r(()=>t(e))},Ul=e=>Yl(e,Ca),Wl=S(2,(e,t)=>new zl(e,ui(t)?Bl:Hl,t)),Gl=e=>new zl(e,Bl,nu),Kl=S(2,(e,t)=>new Rl(e,t.length===1?t:e=>t(e))),z=e=>e[ti]!==void 0,ql=S(2,(e,t)=>z(e)?e._tag===`Success`?t(e.value):e:Kl(e,t)),Jl=e=>Kl(e,C),Yl=S(2,(e,t)=>new zl(e,Vl,t)),Xl=S(2,(e,t)=>z(e)?ru(e,t):Yl(e,t)),Zl=S(2,(e,t)=>z(e)?iu(e,t):Su(e,t)),Ql=S(2,(e,t)=>z(e)?au(e,t):Cu(e,t)),$l=e=>Fi(Hc(e)),eu=e=>e._tag===`Success`,tu=e=>e._tag===`Failure`?Ma(e.cause):Na(e),nu=A(void 0),ru=S(2,(e,t)=>e._tag===`Success`?A(t(e.value)):e),iu=S(2,(e,t)=>{if(e._tag===`Success`)return e;let n=Uc(e.cause);return Fa(n)?e:Ii(t(n.success))}),au=S(2,(e,t)=>{if(e._tag===`Success`)return A(t.onSuccess(e.value));let n=Uc(e.cause);return Fa(n)?e:Ii(t.onFailure(n.success))}),ou=S(2,(e,t)=>eu(e)?t:e),su=e=>{let t=[];for(let n of e)n._tag===`Failure`&&t.push(...n.cause.reasons);return t.length===0?nu:Fi(xi(t))},cu=S(2,(e,t)=>j(n=>{let r=n.context,i=t(r);return r===i?e:(n.setContext(i),Xu(e,()=>{n.setContext(r)}))})),lu=S(3,(e,t,n)=>cu(e,e=>{let r=es(e,t),i=n(r);return r===i?e:Yo(e,t,i)})),uu=()=>du,du=j(e=>F(e.context)),fu=e=>j(t=>e(t.context)),pu=S(2,(e,t)=>z(e)?e:cu(e,os(t))),mu=function(){return arguments.length===1?S(2,(e,t)=>hu(e,arguments[0],t)):S(3,(e,t,n)=>hu(e,t,n)).apply(this,arguments)},hu=(e,t,n)=>cu(e,Yo(t,n)),gu=S(e=>ui(e[0]),(e,t)=>ud({while:wn,body:Cn(t?.disableYield?e:Kl(e,e=>gl)),step:Dn})),_u=S(2,(e,t)=>new yu(e,t.length===1?t:e=>t(e))),vu=Ai({op:`OnFailure`,[k]:Il}),yu=function(e,t){this[O]=e,this[ai]=t};yu.prototype=vu;var bu=S(3,(e,t,n)=>_u(e,e=>{let r=t(e);return Fa(r)?pl(r.failure):$r(()=>n(r.success,e))})),xu=S(2,(e,t)=>bu(e,Uc,e=>t(e))),Su=S(2,(e,t)=>xu(e,e=>bl(()=>t(e)))),Cu=S(2,(e,t)=>ku(e,{onFailure:e=>bl(()=>t.onFailure(e)),onSuccess:e=>I(()=>t.onSuccess(e))})),wu=e=>xu(e,yl),Tu=e=>ju(e,{onFailure:Na,onSuccess:Ma}),Eu=S(2,(e,t)=>new Ou(e,t.onSuccess.length===1?t.onSuccess:e=>t.onSuccess(e),t.onFailure.length===1?t.onFailure:e=>t.onFailure(e))),Du=Ai({op:`OnSuccessAndFailure`,[k]:Il}),Ou=function(e,t,n){this[O]=e,this[ii]=t,this[ai]=n};Ou.prototype=Du;var ku=S(2,(e,t)=>Eu(e,{onFailure:e=>{let n=e.reasons.find(Ei);return n?$r(()=>t.onFailure(n.error)):pl(e)},onSuccess:t.onSuccess})),Au=S(2,(e,t)=>ku(e,{onFailure:e=>I(()=>t.onFailure(e)),onSuccess:e=>I(()=>t.onSuccess(e))})),ju=S(2,(e,t)=>{if(z(e)){if(e._tag===`Success`)return A(t.onSuccess(e.value));let n=Uc(e.cause);return Fa(n)?e:A(t.onFailure(n.success))}return Au(e,t)}),Mu=e=>z(e)?A(e):Nu(e),Nu=ji({op:`Exit`,[k](e){return e._stack.push(this),this[O]},[ii](e,t,n){return F(n??A(e))},[ai](e,t,n){return F(n??Fi(e))}}),Pu=`~effect/Scope`,Fu=`~effect/Scope/Closeable`,Iu=M(`effect/Scope`),Lu=(e,t)=>L(()=>Ru(e,t)??R),Ru=(e,t)=>{if(e.state._tag===`Closed`)return;let n={_tag:`Closed`,exit:t};if(e.state._tag===`Empty`){e.state=n;return}let r=e.state;if(e.state=n,r.finalizer!==void 0)return r.finalizer(t);let i=r.finalizers;if(i!==void 0&&i.size!==0)return i.size===1?i.values().next().value(t):Bu(e,i,t)},zu=(e,t)=>eu(e)?t:_u(t,t=>pl(Jc(e.cause,t))),Bu=Al(function*(e,t,n){let r=[],i=[],a=Array.from(t.values()),o=tl();for(let t=a.length-1;t>=0;t--){let s=a[t];e.strategy===`sequential`?r.push(yield*Mu(s(n))):i.push(vd(o,s(n),!0,!0,`inherit`))}return i.length>0&&(r=yield*cl(i)),yield*su(r)}),Vu=(e,t)=>{let n=Ku(t);if(e.state._tag===`Closed`)return n.state=e.state,n;let r={};return Wu(e,r,e=>Lu(n,e)),Wu(n,r,t=>I(()=>Gu(e,r))),n},Hu=(e,t)=>L(()=>e.state._tag===`Closed`?t(e.state.exit):(Wu(e,{},t),R)),Uu=(e,t)=>Hu(e,Cn(t)),Wu=(e,t,n)=>{if(e.state._tag===`Empty`)e.state={_tag:`Open`,finalizerKey:t,finalizer:n,finalizers:void 0};else if(e.state._tag===`Open`){let r=e.state;r.finalizer===void 0?r.finalizers===void 0?(r.finalizerKey=t,r.finalizer=n):r.finalizers.set(t,n):(r.finalizers=new Map([[r.finalizerKey,r.finalizer]]),r.finalizerKey=void 0,r.finalizer=void 0,r.finalizers.set(t,n))}},Gu=(e,t)=>{if(e.state._tag===`Open`){let n=e.state;n.finalizerKey===t?(n.finalizerKey=void 0,n.finalizer=void 0):n.finalizers!==void 0&&n.finalizers.delete(t)}},Ku=(e=`sequential`)=>({[Fu]:Fu,[Pu]:Pu,strategy:e,state:qu}),qu={_tag:`Empty`},Ju=mu(Iu),Yu=e=>L(()=>{let t=Ku();return Zu(e(t),e=>L(()=>Ru(t,e)??R))}),Xu=function(){let e=Ai({op:`OnExit`,[k](e){return e._stack.push(this),this.effect},[oi](e){e.interruptible&&this.interruptible!==!0&&(e._stack.push(ad),e.interruptible=!1)},[ii](e,t,n){n??=A(e);let r=this.onExit(n);return r?Kl(r,e=>n):n},[ai](e,t,n){n??=Fi(e);let r=this.onExit(n);return r?Kl(zu(n,r),e=>n):n}}),t=function(e,t,n){this.effect=e,this.onExit=t,this.interruptible=n};return t.prototype=e,function(e,n,r){return new t(e,n,r)}}(),Zu=S(2,Xu),Qu=S(3,(e,t,n)=>Zu(e,e=>{let r=t(e);return Fa(r)?R:n(r.success,e)})),$u=S(2,(e,t)=>Qu(e,tu,t)),ed=S(3,(e,t,n)=>Zu(e,e=>{if(e._tag!==`Failure`)return R;let r=t(e.cause);return Fa(r)?R:n(r.success,e.cause)})),td=S(2,(e,t)=>ed(Kc,t)(e)),nd=e=>I(()=>{let t=jd(!1),n=!1,r,i=Kl(t.await,()=>r);return L(()=>r===void 0?n?i:(n=!0,Zu(e,e=>I(()=>{r=e,t.openUnsafe()}))):r)}),rd=e=>j(t=>t.interruptible?(t.interruptible=!1,t._stack.push(ad),e):e),id=ji({op:`SetInterruptible`,[oi](e){if(e.interruptible=this[O],e._interruptedCause&&e.interruptible)return()=>pl(e._interruptedCause)}}),ad=id(!0),od=id(!1),sd=e=>{if(e.interruptible=!0,e._stack.push(od),e._interruptedCause)return pl(e._interruptedCause)},cd=e=>j(t=>t.interruptible?e:sd(t)??e),ld=e=>j(t=>t.interruptible?(t.interruptible=!1,t._stack.push(ad),e(cd)):e(C)),ud=ji({op:`While`,[ii](e,t){return this[O].step(e),this[O].while()?(t._stack.push(this),this[O].body()):nu},[k](e){return this[O].while()?(e._stack.push(this),this[O].body()):nu}}),dd=S(e=>typeof e[1]==`function`,(e,t,n)=>L(()=>{let r=pd(n?.concurrency);if(r===1)return fd(e,t,n);let i=qa(e),a=i.length;if(a===0)return n?.discard?R:F([]);let o=n?.discard?void 0:Array(a),s=_d({f:t,out:o},i,{concurrency:r});return s?Fl(s,o):F(o)})),fd=(e,t,n)=>L(()=>{let r=n?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),o=0;return Fl(ud({while:()=>!a.done,body:()=>t(a.value,o++),step:e=>{r&&r.push(e),a=i.next()}}),r)}),pd=e=>e===`unbounded`?1/0:Math.max(1,e??1),md=()=>e=>{let t=e.onItem,n=e.step,r=(e,i,a=0,o=i.length)=>{for(;a<o;a++){let s=i[a],c=t(e,s,a);if(!z(c))return Kl(Mu(c),t=>n(e,s,t,a)??r(e,i,a+1,o)??R);let l=n(e,s,c,a);if(l)return l._tag===`Failure`?l:void 0}};return r},hd=e=>{let t=e.onItem,n=e.step;return(e,r,i)=>{let a=0,o=i.end??r.length,s=i.concurrency,c=!1,l,u,d,f=!1,p,m,h=e=>{let t=Li(e);return p=t,c=!0,f=!0,u&&u.size>0?Kl(rd(fl(Array.from(u))),()=>t):t},g=()=>{let i=!1;for(;!p&&a<o;a++){let o=r[a],_=m??t(e,o,a);if(z(_)){if(p=n(e,o,_,a),p)break}else if(l){m=void 0;let t=vd(l,_,!0,!0,`inherit`);if(t._exit){if(p=n(e,o,t._exit,a),p)break;continue}u.add(t);let r=a;if(t.addObserver(a=>{u.delete(t);try{if(p){if(!f&&a._tag===`Failure`)for(let e of a.cause.reasons)if(e._tag===`Interrupt`)continue;else p._tag===`Failure`?p.cause.reasons.push(e):p=Fi(xi([e]))}else{let t=n(e,o,a,r);t&&(p=t._tag===`Failure`?Fi(xi(t.cause.reasons.slice())):t,g())}if(i){let e=g();e&&d(e)}else c&&u.size===0&&d(p??R)}catch(e){d(h(e))}}),u.size<s)continue;i=!0,a++;return}else return Dl(e=>{l=tl(),u=new Set,m=_,d=e;let t;try{t=g()}catch(t){return e(h(t))}return t?e(t):L(()=>(p=nu,f=!0,u?fl(u):R))})}if(c=!0,p){if(u&&u.size>0){let e=ol(l);u.forEach(t=>t.interruptUnsafe(l.id,e));return}if(d||p._tag===`Failure`)return p}else if(d){if(u)u.size===0&&d(R);else return nu}};return g()}},gd=()=>e=>hd(e),_d=hd({onItem(e,t,n){return e.f(t,n)},step(e,t,n,r){if(n._tag===`Failure`)return n;e.out&&(e.out[r]=n.value)}}),vd=(e,t,n=!1,r=!1,i=!1)=>{let a=e,o=i===`inherit`?a.interruptible:!i,s=new nl(a.context,o);return n?s.evaluate(t):a.currentDispatcher.scheduleTask(()=>s.evaluate(t),0),!r&&!s._exit&&(a.children().add(s),s._parent=a),s},yd=S(e=>ui(e[0]),(e,t,n)=>j(r=>{let i=vd(r,e,n?.startImmediately,!0,n?.uninterruptible);if(!i._exit){if(t.state._tag!==`Closed`){let e={};Wu(t,e,()=>wl(e=>e===i.id?R:ul(i))),i.addObserver(()=>Gu(t,e))}else i.interruptUnsafe(r.id,ol(r))}return F(i)})),bd=e=>(t,n)=>{let r=new nl(n?.scheduler?Yo(e,Us,n.scheduler):e,n?.uninterruptible!==!0);if(r.evaluate(t),r._exit)return r;if(n?.signal){if(n.signal.aborted)r.interruptUnsafe();else{let e=()=>r.interruptUnsafe();n.signal.addEventListener(`abort`,e,{once:!0}),r.addObserver(()=>n.signal.removeEventListener(`abort`,e))}}return n?.onFiberStart&&n.onFiberStart(r),r},xd=S(2,(e,t)=>{if(e._exit)return e;if(t.state._tag===`Closed`)return e.interruptUnsafe(e.id),e;let n={};return Wu(t,n,()=>ul(e)),e.addObserver(()=>Gu(t,n)),e}),Sd=bd(Ko()),Cd=e=>{let t=bd(e);return(e,n)=>{let r=t(e,n);return new Promise(e=>{r.addObserver(t=>e(t))})}},wd=(e=>{let t=Cd(e);return(e,n)=>t(e,n).then(e=>{if(e._tag===`Failure`)throw Zc(e.cause);return e.value})})(Ko()),Td=e=>{let t=bd(e);return e=>{if(z(e))return e;let n=new Js(`sync`),r=t(e,{scheduler:n});return r._dispatcher?.flush(),r._exit??Li(new Qd(r))}},Ed=Td(Ko()),Dd=(e=>{let t=Td(e);return e=>{let n=t(e);if(n._tag===`Failure`)throw Zc(n.cause);return n.value}})(Ko()),Od=F(!0),kd=F(!1),Ad=class{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(this.waiters.length===0)return Od;if(this.scheduled===void 0)this.scheduled=this.waiters,e.currentDispatcher.scheduleTask(this.flushScheduled,0);else for(let e=0;e<this.waiters.length;e++)this.scheduled.push(this.waiters[e]);return this.waiters=[],Od}flushScheduled=()=>{if(this.scheduled===void 0)return;let e=this.scheduled;this.scheduled=void 0;for(let t=0;t<e.length;t++)e[t](nu)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](nu)}open=j(e=>this._isOpen?kd:(this._isOpen=!0,this.scheduleUnsafe(e)));release=j(e=>this._isOpen?kd:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=Dl(e=>this._isOpen?e(R):(this.waiters.push(e),I(()=>{let t=this.waiters.indexOf(e);t===-1?this.scheduled!==void 0&&(t=this.scheduled.indexOf(e),t!==-1&&this.scheduled.splice(t,1)):this.waiters.splice(t,1)})));closeUnsafe(){return this._isOpen?(this._isOpen=!1,!0):!1}close=I(()=>this.closeUnsafe());whenOpen=e=>Kl(this.await,()=>e);isOpen(){return this._isOpen}},jd=e=>new Ad(e??!1),Md=BigInt(0),Nd={_tag:`Span`,spanId:`noop`,traceId:`noop`,sampled:!1,status:{_tag:`Ended`,startTime:Md,endTime:Md,exit:nu},attributes:new Map,links:[],kind:`internal`,attribute(){},event(){},end(){},addLinks(){}},Pd=e=>Object.assign(Object.create(Nd),e),Fd=e=>e?ts(e.annotations,xc)?e._tag===`Span`?Fd(ka(e.parent)):Sa():Ca(e):Sa(),Id=(e,t,n)=>{let r=!e.getRef(jc)||n?.annotations&&ts(n.annotations,xc),i=n?.parent===void 0?n?.root?Sa():Fd(e.cache.span):Ca(n.parent),a;if(r)a=Pd({name:t,parent:i,annotations:Yo(n?.annotations??Ko(),xc,!0)});else{let r=e.getRef(Tc),o=e.getRef(Ud),s=e.getRef(Mc),c=e.getRef(Nc),l=e.getRef(Pc),u=n?.level??e.getRef(Sc),d=n?.links===void 0?l.length===0?[]:l.slice():[...l,...n.links];a=r.span({name:t,parent:i,annotations:n?.annotations??Ko(),links:d,startTime:s?o.currentTimeNanosUnsafe():Md,kind:n?.kind??`internal`,root:n?.root??wa(i),sampled:n?.sampled??(Ta(i)&&i.value.sampled===!1?!1:!tf(e.getRef(Cc),u))});for(let e in c)a.attribute(e,c[e]);if(n?.attributes!==void 0)for(let e in n.attributes)a.attribute(e,n.attributes[e])}return a},Ld=(e,t)=>(t=typeof t==`function`?t:En,lu(Ac,n=>({name:e,stack:t,parent:n}))),Rd=(e,t,n,r)=>I(()=>{e.status._tag!==`Ended`&&e.end(r?n.currentTimeNanosUnsafe():Md,t)}),zd=(e,...t)=>{let n=t.length===1?void 0:t[0],r=t[t.length-1];return j(t=>{let i=Id(t,e,n),a=t.getRef(Ud),o=t.getRef(Mc);return Zu(L(()=>$r(()=>r(i))),e=>Rd(i,e,a,o))})},Bd=mu(yc),Vd=function(){let e=ui(arguments[0]),t=e?arguments[1]:arguments[0],n=e?arguments[2]:arguments[1],r=C;return t._tag===`Span`&&(n=Rc(n),r=Ld(t.name,n?.captureStackTrace)),e?Bd(r(arguments[0]),t):e=>Bd(r(e),t)},Hd=function(){let e=typeof arguments[0]!=`string`,t=e?arguments[1]:arguments[0],n=Rc(arguments[2]);if(e){let e=arguments[0];return zd(t,arguments[2],t=>Vd(e,t,n))}let r=typeof arguments[1]==`function`?arguments[1]:void 0,i=r?void 0:arguments[1];return(e,...a)=>zd(t,r?r(...a):i,t=>Vd(e,t,n))},Ud=N(`effect/Clock`,{defaultValue:()=>new Gd}),Wd=2**31-1,Gd=class{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=I(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return Jd()}currentTimeNanos=I(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return qd()}monotonicTimeNanos=I(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(Ls(e))}sleepMillis(e){return e<=0?gl:Number.isFinite(e)?Dl(t=>{let n=e>Wd?this.sleepMillis(e-Wd):R,r=setTimeout(()=>t(n),Math.min(e,Wd));return I(()=>clearTimeout(r))}):Ol}},Kd=BigInt(1e6),qd=function(){let e=globalThis.process?.hrtime;if(typeof e?.bigint==`function`)return()=>e.bigint();if(typeof performance<`u`&&typeof performance.now==`function`)return()=>BigInt(Math.round(performance.now()*1e6));let t=BigInt(0);return()=>{let e=BigInt(Date.now())*Kd;return e>t&&(t=e),t}}(),Jd=function(){let e=BigInt(1e9),t;return()=>{let n=qd(),r=BigInt(Date.now())*Kd;if(t===void 0)t=r-n;else{let i=t+n;(r>i?r-i:i-r)>e&&(t=r-n)}return t+n}}(),Yd=`~effect/Cause/IllegalArgumentError`,Xd=class extends Bi(`IllegalArgumentError`){[Yd]=Yd;constructor(e){super({message:e})}},Zd=`~effect/Cause/AsyncFiberError`,Qd=class extends Bi(`AsyncFiberError`){[Zd]=Zd;constructor(e){super({message:`An asynchronous Effect was executed with Effect.runSync`,fiber:e})}},$d=`~effect/Cause/UnknownError`,ef=class extends Bi(`UnknownError`){[$d]=$d;constructor(e,t){super({message:t,cause:e})}},tf=ya(_a(ga,e=>{switch(e){case`All`:return-(2**53-1);case`Fatal`:return 5e4;case`Error`:return 4e4;case`Warn`:return 3e4;case`Info`:return 2e4;case`Debug`:return 1e4;case`Trace`:return 0;case`None`:return 2**53-1}})),nf={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};nf.gray,nf.blue,nf.green,nf.yellow,nf.red,nf.bgBrightRed,nf.black;var rf=S(e=>ui(e[0]),(e,t)=>$u(e,e=>j(n=>(af(n,e,t?.defectsOnly),R)))),af=(e,t,n)=>{let r=e.getRef(kc);if(r.size===0||n&&!Wc(t))return;let i={cause:t,fiber:e,timestamp:e.getRef(Ud).currentTimeNanosUnsafe()};r.forEach(e=>e.report(i))},of=mi,sf=hi,cf=Ei,lf=xi,uf=Si,df=wi,ff=e=>new bi(e),pf=e=>new Ci(e),mf=Vc,hf=Yc,gf=Jc,_f=Zc,vf=Gc,yf=Hi,bf=Ki,xf=Xd,Sf=A,Cf=Fi,wf=Ii,Tf=nu,Ef=eu,Df={"~effect/Deferred":{_A:C,_E:C},pipe(){return x(this,arguments)}},Of=function(){this.resumes=void 0,this.effect=void 0};Of.prototype=Df;var kf=()=>new Of,Af=e=>Dl(t=>e.effect?t(e.effect):(e.resumes??=[],e.resumes.push(t),I(()=>{let n=e.resumes;if(n===void 0)return;let r=n.indexOf(t);r>=0&&n.splice(r,1)}))),jf=S(2,(e,t)=>I(()=>Mf(e,t))),Mf=(e,t)=>{if(e.effect)return!1;if(e.effect=t,e.resumes){let n=e.resumes;e.resumes=void 0;for(let e=0;e<n.length;e++)n[e](t)}return!0},Nf=Fc,Pf=Iu,Ff=Ku,If=Ju,Lf=Hu,Rf=Uu,zf=Vu,Bf=Lu,Vf=`~effect/Layer`,Hf=`~effect/Layer/MemoMap`,Uf=(e,t)=>(e.observers++,Wl(Hu(t,t=>e.finalizer(t)),e.effect)),Wf={[Vf]:{_ROut:C,_E:C,_RIn:C},pipe(){return x(this,arguments)}},Gf=e=>{let t=Object.create(Wf);return t.build=e,t},Kf=e=>Gf((t,n)=>{let r=zf(n);return Zu(e(t,r),e=>e._tag===`Failure`?Bf(r,e):R)}),qf=e=>{let t=Kf((n,r)=>n.getOrElseMemoize(t,r,e));return t},Jf=(e,t,n,r)=>{let i=Ff(),a=kf(),o={observers:1,effect:Af(a),finalizer:n=>L(()=>(o.observers--,o.observers===0?(e.map.delete(t),Bf(i,n)):R))};return e.map.set(t,o),Hu(n,o.finalizer).pipe(Kl(()=>r(e,i)),Zu(e=>(o.effect=e,jf(a,e))))},Yf=class{get[Hf](){return Hf}parent;constructor(e){this.parent=e}map=new Map;get(e,t){let n=this.map.get(e);return n?Uf(n,t):this.parent?.get(e,t)}getOrElseMemoize(e,t,n){return L(()=>this.get(e,t)||Jf(this,e,t,n))}},Xf=()=>new Yf,Zf=e=>new Yf(e),Qf=class e extends M()(`effect/Layer/CurrentMemoMap`){static forkOrCreate(t){let n=Qo(t,e);return n?Zf(n):Xf()}},$f=S(3,(e,t,n)=>mu(Yl(e.build(t,n),Yo(Qf,t)),Qf,t)),ep=S(2,(e,t)=>j(n=>$f(e,Qf.forkOrCreate(n.context),t))),tp=function(){return arguments.length===1?e=>np(Jo(arguments[0],e)):np(Jo(arguments[0],arguments[1]))},np=e=>Gf(Cn(F(e))),rp=np(Ko()),ip=function(){return arguments.length===1?e=>ap(arguments[0],e):ap(arguments[0],arguments[1])},ap=(e,t)=>op(Yl(t,t=>Jo(e,t))),op=e=>qf((t,n)=>If(e,n)),sp=e=>op(Fl(e,Ko())),cp=M(`effect/Layer/unwrap`),lp=e=>hp(ip(cp)(e),ts(cp)),up=(e,t,n)=>{let r=zf(n,`parallel`);return dd(e,e=>e.build(t,zf(r,`sequential`)),{concurrency:e.length}).pipe(Yl(e=>ss(...e)))},dp=(...e)=>Kf((t,n)=>up(e,t,n)),fp=(e,t,n)=>Kf((r,i)=>Kl(Array.isArray(t)?up(t,r,i):t.build(r,i),t=>e.build(r,i).pipe(pu(t),Yl(e=>n(e,t))))),pp=S(2,(e,t)=>fp(e,t,C)),mp=S(2,(e,t)=>fp(e,t,(e,t)=>os(t,e))),hp=S(2,(e,t)=>Kf((n,r)=>Kl(e.build(n,r),e=>t(e).build(n,r)))),gp=`~effect/DateTime`,_p=`~effect/DateTime/TimeZone`,vp={[gp]:gp,pipe(){return x(this,arguments)},[Gr](){return this.toString()},toJSON(){return Ap(this).toJSON()}},yp={...vp,_tag:`Utc`,[Wn](){return Yn(this.epochMilliseconds)},[sr](e){return xp(e)&&e._tag===`Utc`&&this.epochMilliseconds===e.epochMilliseconds},toString(){return`DateTime.Utc(${Ap(this).toJSON()})`}};({...vp});var bp={[_p]:_p,[Gr](){return this.toString()}};({...bp}),{...bp};var xp=e=>w(e,gp),Sp=e=>xp(e[0]),Cp=e=>e._tag===`Utc`,wp=e=>{let t=Object.create(yp);return t.epochMilliseconds=e,Object.defineProperty(t,"partsUtc",{value:void 0,enumerable:!1,writable:!0}),t},Tp=e=>{let t=e.getTime();if(Number.isNaN(t))throw new xf(`Invalid date`);return wp(t)},Ep=e=>{if(xp(e))return e;if(e instanceof Date)return Tp(e);if(typeof e==`object`){if(`epochMilliseconds`in e)return Tp(new Date(e.epochMilliseconds));let t=new Date(0);return jp(t,e),Tp(t)}return typeof e==`string`&&!Dp(e)?Tp(new Date(e+`Z`)):Tp(new Date(e))},Dp=e=>/Z|GMT|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e),Op=Aa(Ep),kp=e=>wp(e.epochMilliseconds),Ap=e=>new Date(e.epochMilliseconds),jp=(e,t)=>{if((t.year!==void 0||t.month!==void 0||t.day!==void 0)&&e.setUTCFullYear(t.year??e.getUTCFullYear(),t.month===void 0?e.getUTCMonth():t.month-1,t.day??e.getUTCDate()),t.weekDay!==void 0){let n=t.weekDay-e.getUTCDay();e.setUTCDate(e.getUTCDate()+n)}t.hour!==void 0&&e.setUTCHours(t.hour),t.minute!==void 0&&e.setUTCMinutes(t.minute),t.second!==void 0&&e.setUTCSeconds(t.second),t.millisecond!==void 0&&e.setUTCMilliseconds(t.millisecond)},Mp=S(Sp,(e,t)=>new Intl.DateTimeFormat(t?.locale,t).format(e.epochMilliseconds)),Np=e=>Ap(e).toISOString(),Pp=S(2,(e,t)=>bu(e,Rp,e=>t(e))),Fp=e=>e.reasons.some(Ip),Ip=e=>e._tag===`Fail`&&yf(e.error),Lp=e=>{let t,n=!1;for(let r of e.reasons)Ip(r)?t??=r.error:r._tag!==`Interrupt`&&(n=!0);return t===void 0?Na(e):n?Na(lf(e.reasons.filter(e=>!Ip(e)))):Ma(t)},Rp=e=>{let t=Lp(e);return Fa(t)?t:Ma(t.success.value)},zp=e=>{let t=Lp(e);return Fa(t)?Cf(t.failure):Sf(t.success.value)},Bp=(e,t,n)=>Yu(r=>Kl(n?.local?$f(t,Xf(),r):ep(t,r),t=>pu(e,t))),Vp=S(e=>ui(e[0]),(e,t,n)=>Wo(t)?pu(e,t):Bp(e,Array.isArray(t)?dp(...t):t,n)),Hp=ui,Up=Sl,Wp=Cl,B=F,Gp=L,Kp=I,qp=R,Jp=kl,V=ml,Yp=pl,Xp=vl,Zp=yl,Qp=xl,$p=j,em=hl,H=Kl,tm=Jl,nm=Wl,rm=Tu,im=Mu,U=Yl,am=Fl,om=Gl,sm=xu,cm=_u,lm=Su,um=wu,dm=rf,fm=Au,pm=Eu,mm=uu,hm=fu,gm=Vp,_m=pu,vm=cu,ym=mu,bm=$u,xm=Zu,Sm=nd,Cm=td,wm=ld,Tm=gu,Em=zd,Dm=Hd,Om=Vd,km=yd,Am=Sd,jm=bd,Mm=wd,Nm=Dd,Pm=Ed,Fm=Al,Im=S(e=>Hp(e[0]),(e,...t)=>lu(e,Nf,e=>{let n=t.length===1?{...e,...t[0]}:{...e};return t.length===1||E(n,t[0],t[1]),n})),Lm=Xl,Rm=Zl,zm=Ql,Bm=ql,Vm=Ml;function Hm(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function Um(e){return t=>Hm(t)?.[e]}var Wm=`~structural`,Gm=`~identifier`,Km=`~sentinels`,qm=`~constructor`,Jm=[`title`,`description`,`default`,`examples`,`readOnly`,`writeOnly`,`format`,`contentEncoding`,`contentMediaType`,`contentSchema`],Ym=Um(`identifier`),Xm=Um(Gm),Zm=Um(`description`),Qm=On(e=>{let t=Hm(e)?.identifier;return typeof t==`string`?t:e.getExpected(Qm)}),$m=new Set([Km,Wm,`representation`,`arbitraryConstraint`,`brands`,`toJsonSchema`,`toCode`,`toEquivalence`,`toFormatter`,`toCodec`,`toCodecJson`,`toCodecStringTree`,`toCodecIso`,`toCodecArbitrary`]),W=Symbol(),eh=Sf,th=eh(W),G=eh(W),nh=e=>e===W?Sa():Ca(e),rh=e=>e._tag===`None`?th:eh(e.value),ih=`~effect/SchemaIssue/Issue`;function ah(e){return w(e,ih)&&e[ih]===ih}function oh(e){return Object.hasOwn(e,`input`)}var sh=class{[ih]=ih;constructor(e,t){t?.reportInput===!0&&e!==W&&(this.input=e)}},ch=class extends sh{_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},lh=class extends sh{_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},uh=class extends sh{_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},dh=class extends sh{_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},fh=class extends sh{_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},ph=class extends sh{_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},mh=class extends sh{_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},hh=class extends sh{_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}};function gh(e,t,n,r,i){return new ph(e,[new uh([t],n)],r,i)}var _h=class extends sh{_tag=`Forbidden`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},vh=class extends sh{_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},yh=class extends sh{_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function bh(e,t,n){if(ah(e))return e;if(typeof e==`string`)return new hh({message:e},t,n);let r=typeof e.issue==`string`?new hh({message:e.issue},t,n):e.issue;return new uh(e.path,r)}function xh(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new hh(void 0,t,n):bh(e,t,n)}function Sh(e,t,n,r){return Array.isArray(t)?Qa(t)?t.length===1?bh(t[0],n,r):new ph(e,to(t,e=>bh(e,n,r)),n,r):void 0:xh(t,n,r)}var Ch=e=>{let t=Mh(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Dh(Qm(e.ast),e);case`InvalidValue`:{let t=Eh(e);if(t!==void 0)return Dh(t,e);let n=Th(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=Th(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=Th(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},wh=e=>Mh(e.issue)??Mh(e);function Th(e){return oh(e)?D(e.input):void 0}function Eh(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Dh(e,t){let n=Th(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function Oh(e){let t=e.annotations?.expected;if(typeof t==`string`)return t;switch(e._tag){case`Filter`:return`<filter>`;case`FilterGroup`:return e.checks.map(e=>Oh(e)).join(` & `)}}function kh(){return e=>jh(e,``)}var Ah=kh();function jh(e,t){let n;switch(e._tag){case`Filter`:{let r=wh(e);if(r!==void 0)n=r;else{if(e.issue._tag!==`InvalidValue`)return jh(e.issue,t);let r=Eh(e.issue);n=r===void 0?Dh(Oh(e.filter),e):Dh(r,e.issue)}break}case`Encoding`:return jh(e.issue,t);case`Pointer`:return jh(e.issue,t+Br(e.path));case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>jh(e,t)).join(`
9
+ `);n=Mh(e)??Dh(Qm(e.ast),e);break;default:n=Ch(e)}return t?`${n}\n at ${t}`:n}function Mh(e){if(e._tag===`Pointer`)return;if(e._tag===`Encoding`)return Mh(e.issue);let t=(e._tag===`Filter`?e.filter.annotations:`annotations`in e?e.annotations:e.ast.annotations)?.[e._tag===`MissingKey`?`messageMissingKey`:e._tag===`UnexpectedKey`?`messageUnexpectedKey`:`message`];if(typeof t==`string`)return t}function Nh(e){let t;for(let n of e.reasons){if(!cf(n)||!ah(n.error))return;t??=n.error}return t}function Ph(e,t){let n=Nh(e);if(n===void 0)throw Error(t,{cause:e});return n}var Fh=xp,Ih=Cp,Lh=Tp,Rh=Ep,zh=Op,Bh=kp,Vh=Mp,Hh=Np,Uh=e=>Object.assign(Object.create(xn),e);function Wh(e){return Zh((t,n)=>V(e(t,n)))}function Gh(e){return Wh((t,n)=>{let r={message:e(t)};return Ta(t)?new _h(r,t.value,n):new _h(r)})}var Kh=Gh(()=>`Encoding is not supported`),qh=Uh({_tag:`Passthrough`});function Jh(){return qh}function Yh(e){return Uh({_tag:`Transform`,transform:e})}function Xh(e){return Uh({_tag:`TransformEffect`,transform:e})}function Zh(e){return Uh({_tag:`TransformOptionalEffect`,transform:e})}function Qh(){return Yh(globalThis.String)}function $h(){return Yh(globalThis.Number)}function eg(e){return Xh((t,n)=>Qp({try:()=>JSON.parse(t,e?.reviver),catch:()=>new hh({expected:`a valid JSON string`},t,n)}))}function tg(e){return Xh((t,n)=>Qp({try:()=>{let n=JSON.stringify(t,e?.replacer,e?.space);if(n===void 0)throw TypeError(`Value cannot be represented as JSON`);return n},catch:()=>new hh({expected:`a JSON-serializable value`},t,n)}))}function ng(){return Yh(rc)}function rg(){return Xh((e,t)=>Rm(em(ic(e)),()=>new hh({expected:`a valid Base64 string`},e,t)))}var ig=BigInt(0),ag=BigInt(1),og=BigInt(1e3),sg=BigInt(1024),cg=[{symbol:`B`,factor:ag,names:[`B`,`byte`,`bytes`]},{symbol:`kB`,factor:og,names:[`kB`,`kilobyte`,`kilobytes`]},{symbol:`MB`,factor:og**BigInt(2),names:[`MB`,`megabyte`,`megabytes`]},{symbol:`GB`,factor:og**BigInt(3),names:[`GB`,`gigabyte`,`gigabytes`]},{symbol:`TB`,factor:og**BigInt(4),names:[`TB`,`terabyte`,`terabytes`]},{symbol:`PB`,factor:og**BigInt(5),names:[`PB`,`petabyte`,`petabytes`]},{symbol:`EB`,factor:og**BigInt(6),names:[`EB`,`exabyte`,`exabytes`]},{symbol:`ZB`,factor:og**BigInt(7),names:[`ZB`,`zettabyte`,`zettabytes`]},{symbol:`YB`,factor:og**BigInt(8),names:[`YB`,`yottabyte`,`yottabytes`]},{symbol:`RB`,factor:og**BigInt(9),names:[`RB`,`ronnabyte`,`ronnabytes`]},{symbol:`QB`,factor:og**BigInt(10),names:[`QB`,`quettabyte`,`quettabytes`]}],lg=[cg[0],{symbol:`KiB`,factor:sg,names:[`KiB`,`kibibyte`,`kibibytes`]},{symbol:`MiB`,factor:sg**BigInt(2),names:[`MiB`,`mebibyte`,`mebibytes`]},{symbol:`GiB`,factor:sg**BigInt(3),names:[`GiB`,`gibibyte`,`gibibytes`]},{symbol:`TiB`,factor:sg**BigInt(4),names:[`TiB`,`tebibyte`,`tebibytes`]},{symbol:`PiB`,factor:sg**BigInt(5),names:[`PiB`,`pebibyte`,`pebibytes`]},{symbol:`EiB`,factor:sg**BigInt(6),names:[`EiB`,`exbibyte`,`exbibytes`]},{symbol:`ZiB`,factor:sg**BigInt(7),names:[`ZiB`,`zebibyte`,`zebibytes`]},{symbol:`YiB`,factor:sg**BigInt(8),names:[`YiB`,`yobibyte`,`yobibytes`]}],ug=[...cg,...lg.slice(1)],dg=new Map(ug.flatMap(e=>e.names.map(t=>[t,e]))),fg=new Map(ug.map(e=>[e.symbol,e])),pg=e=>e,mg=e=>{throw Error(`Invalid ByteSize: ${e}`)},hg=e=>!Number.isSafeInteger(e)||e<0?mg(`expected a non-negative safe integer, received ${e}`):pg(BigInt(e)),gg=(e,t)=>{if(typeof e==`bigint`)return e<ig?mg(`expected a non-negative quantity, received ${e}`):pg(e*t.factor);let n=e*Number(t.factor);return!Number.isSafeInteger(n)||n<0?mg(`expected an exact non-negative safe-integer byte result, received ${e} ${t.symbol}`):pg(BigInt(n))},_g=e=>{let t=/^\s*(\d+)(?:\.(\d+))?\s*([A-Za-z]+)\s*$/.exec(e);if(t===null)return mg(`unsupported syntax ${JSON.stringify(e)}`);let n=dg.get(t[3]);if(n===void 0)return mg(`unsupported unit ${JSON.stringify(t[3])}`);let r=t[2]??``,i=BigInt(10)**BigInt(r.length),a=BigInt(t[1]+r)*n.factor;return a%i===ig?pg(a/i):mg(`${JSON.stringify(e)} does not represent an integral number of bytes`)},vg=e=>{switch(typeof e){case`bigint`:return e<ig?mg(`expected a non-negative bigint, received ${e}`):pg(e);case`number`:return hg(e);case`string`:return _g(e)}return mg(`unsupported input ${e}`)},yg=(e=>t=>gg(t,fg.get(e)))(`MiB`),bg=class extends Sn{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new bg(this.encode,this.decode)}},xg=`~effect/SchemaTransformation/Transformation`,Sg=class extends Sn{[xg]=xg;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Sg(this.encode,this.decode)}};function Cg(e){return w(e,xg)&&e[xg]===xg}var wg=e=>Cg(e)?e:new Sg(e.decode,e.encode);function Tg(e){return new Sg(Xh(e.decode),Xh(e.encode))}function Eg(e){return new Sg(Yh(e.decode),Yh(e.encode))}var Dg=new Sg(Jh(),Jh());function Og(){return Dg}var kg=new Sg($h(),Qh()),Ag=e=>Vn(e)&&typeof e.message==`string`,jg=e=>{let t=Object.hasOwn(e,`cause`)?Error(e.message,{cause:Fg(e.cause)}):Error(e.message);return typeof e.name==`string`&&e.name!==`Error`&&(t.name=e.name),typeof e.stack==`string`&&(t.stack=e.stack),t},Mg=e=>{try{let t=Wr(e);return t===void 0?D(e):JSON.parse(t)}catch{return D(e)}},Ng=(e,t,n)=>{let r={name:e.name,message:typeof e.message==`string`?e.message:``};return t?.includeStack&&typeof e.stack==`string`&&(r.stack=e.stack),!t?.excludeCause&&e.cause!==void 0&&(r.cause=n(e.cause)),r},Pg=e=>{let t=new WeakSet,n=r=>{if(Un(r)){if(t.has(r))return`[Circular]`;t.add(r);let i=Ng(r,e,n);return t.delete(r),i}return Mg(r)};return n},Fg=e=>Ag(e)?jg(e):e,Ig=e=>Eg({decode:Fg,encode:Pg(e)}),Lg=new Sg(rg(),ng());function Rg(e){return new Sg(eg(e??{}),tg(e))}function zg(e){return t=>t._tag===e}var Bg=zg(`Declaration`),Vg=zg(`Null`),Hg=zg(`Void`),Ug=zg(`Never`),Wg=zg(`Literal`),Gg=zg(`UniqueSymbol`),Kg=zg(`Arrays`),qg=zg(`Objects`),Jg=zg(`Union`),Yg=zg(`Suspend`),Xg=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},Zg={},Qg=class{isOptional;isMutable;constructorDefault;annotations;constructor(e,t,n=void 0,r=void 0){this.isOptional=e,this.isMutable=t,this.constructorDefault=n,this.annotations=r}},$g=`~effect/Schema`,e_=class{[$g]=$g;annotations;checks;encoding;context;constructor(e=void 0,t=void 0,n=void 0,r=void 0){this.annotations=e,this.checks=t,this.encoding=n,this.context=r}toString(){return`<${this._tag}>`}},t_=class extends e_{_tag=`Declaration`;typeParameters;run;encodingChecks;encodingRun;constructor(e,t,n,r,i,a,o,s){super(n,r,i,a),this.typeParameters=e,this.run=t,this.encodingChecks=o,this.encodingRun=s}getParser(){let e;return(t,n)=>t===W?th:(e??=this.run(this.typeParameters))(t,this,n)}_rebuild(e,t,n,r,i){let a=xv(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new t_(a,r,this.annotations,t,void 0,this.context,n,i)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks,this.run,this.encodingRun)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks,this.encodingRun??this.run,this.run)}getExpected(){let e=this.annotations?.expected;return typeof e==`string`?e:`<Declaration>`}},n_=new class extends e_{_tag=`Null`;getParser(){return zv(this,null)}getExpected(){return`null`}},r_=class extends e_{_tag=`Undefined`;getParser(){return zv(this,void 0)}toCodecJson(){return K(this,[i_])}getExpected(){return`undefined`}},i_=new Xg(n_,new Sg(Yh(()=>void 0),Yh(()=>null))),a_=new r_,o_=new class extends e_{_tag=`Void`;getParser(){let e=eh(void 0);return t=>t===W?th:e}toCodecJson(){return K(this,[i_])}getExpected(){return`void`}},s_=new class extends e_{_tag=`Never`;getParser(){return Bv(this,zn)}getExpected(){return`never`}},c_=new class extends e_{_tag=`Unknown`;getParser(){return Bv(this,Bn)}getExpected(){return`unknown`}},l_=class extends e_{_tag=`Literal`;literal;constructor(e,t,n,r,i){if(super(t,n,r,i),typeof e==`number`&&!globalThis.Number.isFinite(e))throw Error(`A numeric literal must be finite, got ${D(e)}`);this.literal=e}getParser(){return zv(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?u_(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:u_(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function u_(e){let t=globalThis.String(e.literal);return K(e,[new Xg(new l_(t),new Sg(Yh(()=>e.literal),Yh(()=>t)))])}var d_=new class extends e_{_tag=`String`;getParser(){return Bv(this,Mn)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&Xv(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},f_=class extends e_{_tag=`Number`;getParser(){return Bv(this,Nn)}matchKey(e,t){return this._match(Gv,e,t)}matchPart(e,t){return this._match(Wv,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:Xv(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(p_(this.checks,`effect/schema/isFinite`)||p_(this.checks,`effect/schema/isInt`))?this:K(this,[av])}toCodecStringTree(){return this.toCodecJson()===this?K(this,[Jv]):K(this,[Yv])}getExpected(){return`number`}};function p_(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&p_(e.checks,t))}var m_=new f_,h_=new class extends e_{_tag=`Boolean`;getParser(){return Bv(this,Pn)}getExpected(){return`boolean`}},g_=class extends e_{_tag=`Arrays`;isMutable;elements;rest;encodingChecks;constructor(e,t,n,r,i,a,o,s){super(r,i,a,o),this.isMutable=e,this.elements=t,this.rest=n,this.encodingChecks=s;let c=!1;for(let e=0;e<t.length;e++)if(Av(t[e]))c=!0;else if(c)throw Error(`A required element cannot follow an optional element. ts(1257)`);if(c&&n.length>1)throw Error(`A required element cannot follow an optional element. ts(1257)`);for(let e=1;e<n.length;e++)if(Av(n[e]))throw Error(`An optional element cannot follow a rest element. ts(1266)`)}getParser(e,t=e){let n=this,r,i,a=n.elements.length,o=Math.max(0,n.rest.length-1);function s(e,t){return t<a?r[t]:t>=e?i[t-e+1]:i[0]}return Vm(function*(e,c){if(e===W)return W;if(!Array.isArray(e))return yield*V(new mh(n,e,c));r||(r=n.elements.map(e=>({ast:e,parser:t(e)})),i=n.rest.map(e=>({ast:e,parser:t(e)})));let l=e.length,u={ast:n,getParser:s,input:e,len:l,tailThreshold:Math.max(a,l-o),output:new globalThis.Array(l),issues:void 0,options:c},d=n.rest.length===0?a:Math.max(l,a+o),f=c.concurrency===void 0?1:pd(c.concurrency),p=f===1?y_(u,e,0,d):b_(u,e,{concurrency:f,end:d});if(p&&(yield*p),n.rest.length===0&&l>a)for(let t=a;t<=l-1;t++){let r=new fh(n,e[t],c),i=new uh([t],r);if(c.errors===`all`)u.issues?u.issues.push(i):u.issues=[i];else return yield*V(new ph(n,[i],e,c))}return u.issues?yield*V(new ph(n,u.issues,e,c)):u.output})}_rebuild(e,t,n){let r=xv(this.elements,e),i=xv(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new g_(this.isMutable,r,i,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}getExpected(){return`array`}};function __(e,t,n,r){if(n._tag===`Failure`)return x_(e,e.ast,r,n);let i=n===G?t:n[O];if(i!==W)e.output[r]=i;else{let t=e.getParser(e.tailThreshold,r);if(Av(t.ast))return;let n=new uh([r],new dh(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return wf(new ph(e.ast,[n],e.input,e.options))}}var v_={onItem(e,t,n){let r=n<e.len?t:W;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:__},y_=md()(v_),b_=gd()(v_),x_=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=Nh(r.cause);if(i===void 0)return Cf(hf(r.cause,r=>new ph(t,[new uh([n],r)],e.input,e.options)));let a=new uh([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return wf(new ph(t,[a],e.input,e.options))},S_=`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`;function C_(e,t,n=Zg){let r,i;function a(t){switch(t._tag){case`String`:case`TemplateLiteral`:return(r??=Object.keys(e)).filter(e=>t.matchPart(e,n)!==void 0);case`Number`:return(r??=Object.keys(e)).filter(e=>t.matchKey(e,n)!==void 0);case`Symbol`:return(i??=Object.getOwnPropertySymbols(e)).filter(e=>t.matchKey(e,n)!==void 0);case`Union`:return[...new Set(t.types.flatMap(a))];default:return[]}}return a(Vv(Fv(t)))}var w_=class{name;type;constructor(e,t){this.name=e,this.type=t}};function T_(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(T_);default:return!1}}function E_(e){let t=dv(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(E_);default:return!1}}function D_(e){return T_(e)&&E_(e)}var O_=class{parameter;type;constructor(e,t){if(!D_(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,Av(t)&&!Rv(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}},k_=class extends e_{_tag=`Objects`;propertySignatures;indexSignatures;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.propertySignatures=e,this.indexSignatures=t,this.encodingChecks=o;let s=new Set,c=[];for(let t of e){let e=t.name;s.has(e)?c.push(e):s.add(e)}if(c.length>0)throw Error(`Duplicate identifiers: ${JSON.stringify(c)}. ts(2300)`)}getParser(e,t=e){let n=this,r=[];for(let e of n.propertySignatures)r.push(typeof e.name==`number`?globalThis.String(e.name):e.name);let i=r.length,a=n.indexSignatures.length,o=i&&a?new Set(r):void 0;if(!i&&!a)return Bv(n,Rn);let s,c,l=(e,t,r,a,s)=>{if(s._tag===`Failure`)return x_(e,n,t,s)??Tf;let c=s===G?a:s[O];if(r!==W&&c!==W){if(i&&(o.has(t)||o.has(typeof r==`number`?globalThis.String(r):r)))return Tf;E(e.out,r,c)}return Tf},u=(e,t,r,i)=>{if(!i){let n=r.parserKey(t,e.options);if(!z(n))return H(im(n),n=>u(e,t,r,n));i=n}if(i._tag===`Failure`)return x_(e,n,t,i)??Tf;let a=i===G?t:i[O],o=e.input[t],s=r.parserValue(o,e.options);return z(s)?l(e,t,a,o,s):H(im(s),n=>l(e,t,a,o,n))},d=(e,t,n)=>{let r=e.input[t],i=n.parserValue(r,e.options);return z(i)?l(e,t,t,r,i):H(im(i),n=>l(e,t,t,r,n))},f=a?gd()({onItem:(e,[t,n])=>n.is.parameter===d_?d(e,t,n):u(e,t,n),step:(e,t,n)=>n._tag===`Failure`?n:void 0}):void 0,p=()=>(s||(s=n.propertySignatures.map(e=>({parser:t(e.type),name:e.name,type:e.type})),c=a?n.indexSignatures.map(n=>({is:n,parserKey:e(Vv(n.parameter)),parserValue:t(n.type)})):void 0),s),m=Vm(function*(e,t){if(e===W)return W;if(typeof e!=`object`||!e||Array.isArray(e))return yield*V(new mh(n,e,t));p();let l=e,m={},h={ast:n,input:l,out:m,issues:void 0,options:t},g=t.errors===`all`,_=t.onExcessProperty===`error`,ee=t.concurrency===void 0?1:pd(t.concurrency),v=a&&_?n.indexSignatures.map(e=>C_(l,e.parameter,t)):void 0;if(_){o??=new Set(r);let i=v?new Set(o):o;if(v)for(let e of v)for(let t of e)i.add(t);let a=Reflect.ownKeys(l);for(let r=0;r<a.length;r++){let o=a[r];if(!i.has(o)){let r=new fh(n,l[o],t),i=new uh([o],r);if(g){h.issues?h.issues.push(i):h.issues=[i];continue}return yield*V(new ph(n,[i],e,t))}}}if(i){let e=ee===1?M_(h,s):N_(h,s,{concurrency:ee});e&&(yield*e)}if(a&&ee===1)for(let e=0;e<a;e++){let n=c[e],r=n.is.parameter===d_?d:u,i=v?.[e]??(n.is.parameter===d_?Object.keys(l):C_(l,n.is.parameter,t));for(let e=0;e<i.length;e++){let t=r(h,i[e],n);if(!z(t))yield*t;else if(t._tag===`Failure`)return yield*t}}else if(f){let e=$a();for(let n=0;n<a;n++){let r=c[n],i=v?.[n]??(r.is.parameter===d_?Object.keys(l):C_(l,r.is.parameter,t));for(let t=0;t<i.length;t++)e.push([i[t],r])}let n=f(h,e,{concurrency:ee});n&&(yield*n)}return h.issues?yield*V(new ph(n,h.issues,e,t)):m});if(a)return m;let h=(e,t,n)=>{let r=s[t];return H(im(n),n=>{let i=A_(e,r,n);if(i)return i;let a=()=>eh(e.out),o=M_(e,s.slice(t+1));return o?Bm(o,a):a()})};return(e,t)=>{if(e===W)return th;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&pd(t.concurrency)!==1)return m(e,t);if(typeof e!=`object`||!e||Array.isArray(e))return V(new mh(n,e,t));let r=p(),i=e,a={},o={ast:n,input:i,out:a,issues:void 0,options:t};try{for(let e=0;e<r.length;e++){let n=r[e],s=n.name,c=W_(i,s),l=c?i[s]:W,u=n.parser(l,t);if(!z(u))return h(o,e,u);if(u===G){c&&E(a,s,l);continue}let d=A_(o,n,u);if(d)return d}}catch(e){return Zp(e)}return eh(a)}}_rebuild(e,t,n,r){let i=xv(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new w_(t.name,n)}),a=xv(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new O_(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new k_(i,a,this.annotations,n,void 0,this.context,r)}flip(e){return this._rebuild(e,e,this.encodingChecks,this.checks)}recur(e,t=e){return this._rebuild(e,t,this.checks,this.encodingChecks)}getExpected(){return this.propertySignatures.length===0&&this.indexSignatures.length===0?`object | array`:`object`}};function A_(e,t,n){if(n._tag===`Failure`)return x_(e,e.ast,t.name,n);if(n===G)return;let r=n[O];if(r!==W){E(e.out,t.name,r);return}if(delete e.out[t.name],!Av(t.type)){let n=new uh([t.name],new dh(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return wf(new ph(e.ast,[n],e.input,e.options))}}var j_={onItem(e,t){if(!W_(e.input,t.name))return t.parser(W,e.options);let n=e.input[t.name];return E(e.out,t.name,n),t.parser(n,e.options)},step:A_},M_=md()(j_),N_=gd()(j_);function P_(e,t){return e?t?[...e,...t]:e:t}function F_(e,t,n){return new k_(Reflect.ownKeys(e).map(t=>new w_(t,e[t].ast)),[],n,t)}function I_(e){return e.ast}function L_(e,t=void 0){return new g_(!1,e.map(e=>e.ast),[],void 0,t)}function R_(e,t,n){return new J_(e.map(I_),t,void 0,n)}var z_=kn(e=>{for(;;){if(Yg(e))return c_;let t=e.encoding;if(!t)return e.recur?.(z_,C)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==C))return c_;e=t[t.length-1].to}});function B_(e){switch(e._tag){case`Null`:return[`null`];case`Undefined`:return[`undefined`];case`String`:case`TemplateLiteral`:return[`string`];case`Number`:return[`number`];case`Boolean`:return[`boolean`];case`Symbol`:case`UniqueSymbol`:return[`symbol`];case`BigInt`:return[`bigint`];case`Arrays`:return[`array`];case`ObjectKeyword`:return[`object`,`array`,`function`];case`Objects`:return e.propertySignatures.length||e.indexSignatures.length?[`object`]:[`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`];case`Enum`:return Array.from(new Set(e.enums.map(([,e])=>typeof e)));case`Literal`:return[typeof e.literal];case`Union`:return Array.from(new Set(e.types.flatMap(B_)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function V_(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[Km];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!Av(t)){if(Wg(t))return[{key:e.name,literal:t.literal}];if(Gg(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!Av(e)){if(Wg(e))return[{key:t,literal:e.literal}];if(Gg(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>V_(z_(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return V_(e.thunk())}}var H_=new WeakMap,U_=Object.freeze([]),W_=(e,t)=>t===`__proto__`?Object.hasOwn(e,t):t in e;function G_(e){let t=H_.get(e);if(t)return t;let n,r=0,i,a,o=!0;for(let t=0;t<e.length;t++){let s=e[t],c=z_(s);if(Ug(c))continue;if(o){if(Wg(c)||Gg(c)){a??=new Map;let e=Wg(c)?c.literal:c.symbol,t=a.get(e);t||a.set(e,t=[]),t.push(s)}else o=!1}let l=V_(c);if(l.length){n??=new Map,r++;for(let{key:e,literal:r}of l){let i=n.get(e);i||n.set(e,i=[new Map,new Set]),i[1].add(t);let a=i[0].get(r);a||i[0].set(r,a=new Set),a.add(t)}}else{i??={};let e=B_(c);for(let n of e)(i[n]??=[]).push(t)}}if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??U_;else if(n?.size===1&&!i){let[r,[i]]=n.entries().next().value,a=i;for(let[t,n]of i)a.set(t,Object.freeze(Array.from(n,t=>e[t])));t=(t,n)=>{if(Hn(t)){let i=W_(t,r)?t[r]:void 0;if(i!==void 0)return a.get(i)??U_;if(n)return e}return U_}}else if(n){let a;for(let e of n)(!a||e[1][0].size>a[1][0].size)&&e[1][1].size===r&&(a=e);t=(t,r)=>{let o=i?.[t===null?`null`:Array.isArray(t)?`array`:typeof t]??U_;if(!Hn(t))return o.map(t=>e[t]);let s=new Set(o),c;if(a){let[n,[i]]=a,l=W_(t,n),u=l?t[n]:void 0;if(l&&(!r||u!==void 0)){let t=i.get(u);if(!t)return o.map(t=>e[t]);for(let e of t)s.add(e);c=n}}if(c===void 0)for(let[e,[i,a]]of n){let n=W_(t,e),o=n?t[e]:void 0;if(n&&(!r||o!==void 0)){let e=i.get(o);if(e)for(let t of e)s.add(t)}else if(r)for(let e of a)s.add(e)}for(let[e,[i,a]]of n){if(e===c)continue;let n=W_(t,e),o=n?t[e]:void 0;if(n&&(!r||o!==void 0)){let e=i.get(o);for(let t of s)a.has(t)&&!e?.has(t)&&s.delete(t)}}return Array.from(s).sort((e,t)=>e-t).map(t=>e[t])}}else t=t=>(i?.[t===null?`null`:Array.isArray(t)?`array`:typeof t]??U_).map(t=>e[t]).filter(K_(t));return H_.set(e,t),t}function K_(e){return t=>{let n=z_(t);return n._tag===`Literal`?n.literal===e:n._tag!==`UniqueSymbol`||n.symbol===e}}function q_(e,t,n=!1){return G_(t)(e,n)}var J_=class extends e_{_tag=`Union`;types;options;encodingChecks;constructor(e,t,n,r,i,a,o){super(n,r,i,a),this.types=e,this.options=t,this.encodingChecks=o}getParser(e,t){let n=this;return(r,i)=>{if(r===W)return th;let a=q_(r,n.types,t!==void 0);if(a.length===0)return V(new vh(n,[],r,i));if(a.length===1){let t=e(a[0])(r,i);return t._tag===`Success`?t:z(t)?Y_(n,t.cause,r,i):cm(t,e=>Y_(n,e,r,i))}let o={ast:n,compile:e,input:r,out:void 0,successes:n.options?.mode===`oneOf`?[]:void 0,issues:void 0,options:i},s=X_(o,a);return s?Bm(s,e=>o.out===G?B(r):o.out?o.out:V(new vh(n,o.issues??[],r,i))):o.out?o.out:V(new vh(n,o.issues??[],r,i))}}_rebuild(e,t,n){let r=xv(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new J_(r,this.options,this.annotations,t,void 0,this.context,n)}recur(e){return this._rebuild(e,this.checks,this.encodingChecks)}flip(e){return this._rebuild(e,this.encodingChecks,this.checks)}matchPart(e,t){for(let n of this.types){let r=n.matchPart(e,t);if(r!==void 0)return r}}getExpected(e){let t=this.annotations?.expected;if(typeof t==`string`)return t;if(this.types.length===0)return`never`;let n=this.types.map(t=>{let n=Fv(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(Wg);if(t.length>0)return`${Q_(n.isMutable)}[ ${t.map(t=>e(t)+$_(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>Wg(e.type));if(t.length>0)return`{ ${t.map(t=>`${Q_(t.type.context?.isMutable)}${zr(t.name)}${$_(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function Y_(e,t,n,r){let i=Nh(t);return i?wf(new vh(e,[i],n,r)):Cf(t)}var X_=md()({onItem(e,t){return e.compile(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=Nh(n.cause);if(t===void 0)return n;e.issues?e.issues.push(t):e.issues=[t]}else{if(e.out&&e.successes)return e.successes.push(t),wf(new yh(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(t);else return Tf}}}),Z_=new J_([new l_(`Infinity`),new l_(`-Infinity`),new l_(`NaN`)]);function Q_(e){return e?``:`readonly `}function $_(e){return e?`?`:``}var ev=class extends Sn{_tag=`Filter`;run;annotations;aborted;constructor(e,t=void 0,n=!1){super(),this.run=e,this.annotations=t,this.aborted=n}annotate(e){return new ev(this.run,{...this.annotations,...e},this.aborted)}abort(){return new ev(this.run,this.annotations,!0)}and(e,t){return new tv([this,e],t)}},tv=class extends Sn{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new tv(this.checks,{...this.annotations,...e})}and(e,t){return new tv([this,e],t)}};function nv(e,t,n=!1){return new ev((t,n,r)=>Sh(n,e(t,n,r),t,r),t,n)}function rv(e){return nv(e=>globalThis.Number.isFinite(e),{expected:`a finite number`,representation:{id:`effect/schema/isFinite`,payload:null},toJsonSchema:()=>({type:`number`}),toCode:()=>({runtime:`Schema.isFinite()`}),arbitraryConstraint:{number:`finite`},...e})}var iv=mv(m_,[rv()]),av=new Xg(new J_([iv,Z_]),new Sg($h(),Yh(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function ov(e,t){let n=e.source,r=new globalThis.RegExp(n,e.flags);return nv(e=>(r.lastIndex=0,r.test(e)),{expected:`a string matching the RegExp ${n}`,representation:{id:`effect/schema/isPattern`,payload:{source:n,flags:e.flags}},toJsonSchema:()=>({pattern:n}),arbitraryConstraint:{patterns:[{source:e.source,flags:e.flags}]},...t})}function sv(e,t){let n=Object.getOwnPropertyDescriptors(e);return t(n),Object.create(Object.getPrototypeOf(e),n)}var cv=new WeakMap;function lv(e){return cv.get(e)??e}function K(e,t){return e.encoding===t?e:sv(e,e=>{e.encoding.value=t})}function uv(e,t){if(e.context===t)return e;let n=lv(e);if(n.context===t)return n;let r=sv(e,e=>{e.context.value=t});return cv.set(r,n),r}function dv(e){return e.encoding?dv(e.encoding[e.encoding.length-1].to):e}function fv(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return pv(e,Ya(e.checks.slice(0,-1),n.annotate(t)))}return sv(e,e=>{e.annotations.value={...e.annotations.value,...t}})}function pv(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:sv(e,e=>{e.checks.value=t})}function mv(e,t){return pv(e,P_(e.checks,t))}function hv(e,t){let n=t(e.to);return n===e.to?e:new Xg(n,e.transformation)}function gv(e,t){let n=e,r=n[n.length-1],i=hv(r,t);return i===r?e:Ya(e.slice(0,e.length-1),i)}function _v(e){return t=>t.encoding?K(t,gv(t.encoding,e)):t}function vv(e,t){return _v(e=>uv(e,t))(e)}function yv(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:K(r,gv(r.encoding,n))}return e(r)}return kn(n)}function bv(e,t,n){let r=new Xg(e,t);return K(n,n.encoding?[...n.encoding,r]:[r])}function xv(e,t){let n=!1,r=Array(e.length);for(let i=0;i<e.length;i++){let a=e[i],o=t(a);o!==a&&(n=!0),r[i]=o}return n?r:e}function Sv(e,t){return uv(e,e.context?new Qg(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new Qg(!1,!1,void 0,t))}var Cv=kn(e=>wv(uv(e,e.context?e.context.isOptional===!1?new Qg(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new Qg(!0,!1)))),wv=_v(Cv),Tv=On(e=>Cv(new J_([e,a_])));function Ev(e,t){return uv(e,e.context?new Qg(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new Qg(!1,!1,t))}function Dv(e,t,n){return bv(e,n,t)}function Ov(e){let t=[],n=[];function r(e){switch(e._tag){case`Literal`:In(e.literal)&&t.push(e.literal);return;case`UniqueSymbol`:t.push(e.symbol);return;case`Never`:return;case`Union`:for(let t=0;t<e.types.length;t++)r(e.types[t]);return;default:n.push(e)}}return r(e),{literals:t,parameters:n}}function kv(e,t){let{literals:n,parameters:r}=Ov(e);return new k_(n.map(e=>new w_(e,t)),r.map(e=>new O_(e,t)))}function Av(e){return e.context?.isOptional??!1}function jv(e){return e.context?.isMutable??!1}function Mv(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(Mv)}function Nv(e){function t(e){return Mv(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return Za(n)?n:void 0}var Pv=kn(e=>{if(e.encoding)return Pv(K(e,void 0));let t=e,n=t.recur?.(Pv)??t,r=n.encodingChecks;if(r){let t=n===e?r:Kg(n)||qg(n)||Bg(n)&&n.typeParameters.length>0?Nv(r):void 0;return sv(n,e=>{e.encodingChecks.value=void 0,e.checks.value=P_(n.checks,t)})}return n}),Fv=kn(e=>Pv(Lv(e)));function Iv(e,t){let n=t,r=n.length,i=n[r-1],a=[new Xg(Lv(K(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new Xg(Lv(n[e-1].to),n[e].transformation.flip()));let o=Lv(i.to);return o.encoding?K(o,[...o.encoding,...a]):K(o,a)}var Lv=On(e=>{if(e.encoding)return Iv(e,e.encoding);let t=e;return t.flip?.(Lv)??t.recur?.(Lv)??t});function Rv(e){switch(e._tag){case`Undefined`:return!0;case`Union`:return e.types.some(Rv);default:return!1}}function zv(e,t){let n=t===0?G:eh(t);return(r,i)=>r===W?th:r===t?n:V(new mh(e,r,i))}function Bv(e,t){return(n,r)=>n===W?th:t(n)?G:V(new mh(e,n,r))}var Vv=yv(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(Vv)}}),Hv=yv(e=>{switch(e._tag){default:return e;case`Symbol`:case`UniqueSymbol`:return e.toCodecStringTree();case`Union`:return e.recur(Hv)}}),Uv=`[\\s\\S]*?`,Wv=new globalThis.RegExp(`^${S_}$`),Gv=new globalThis.RegExp(`^(?:${S_}|Infinity|-Infinity|NaN)$`);function Kv(e){return ov(Wv,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:Wv.source}),...e})}var qv=mv(d_,[Kv()]),Jv=new Xg(qv,kg),Yv=new Xg(new J_([qv,Z_]),kg);function Xv(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=Xv(o.checks,t,n,r,i),n&&(i.errors!==`all`||n[n.length-1].filter.aborted))return n}else{let e=o.run(t,r,i);if(e){let r=new ch(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function Zv(e){if(!Bg(e))return;let t=e.annotations?.[qm];return Ln(t)?t(e.typeParameters):void 0}var Qv=Um,$v=Ym,ey=Zm;function ty(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function ny(e){return e===void 0||typeof e==`string`}function ry(e,t){let n=new WeakMap,r=[];outer:for(;;){if(typeof e!=`object`||!e){if(!t(e))return!1}else{let t=e,i=n.get(t);if(i===!1)return!1;if(i===void 0){let e=Array.isArray(t);if(!e){let e=Object.getPrototypeOf(t);if(e!==null&&e!==Object.prototype&&Object.getPrototypeOf(e)!==null)return!1}n.set(t,!1),r.push({value:t,keys:e?t.length:Object.keys(t),index:0})}}for(;r.length>0;){let t=r[r.length-1],i=t.keys;if(typeof i==`number`){if(t.index<i){e=t.value[t.index++];continue outer}}else if(t.index<i.length){e=t.value[i[t.index++]];continue outer}n.set(t.value,!0),r.pop()}return!0}}function iy(e){return ry(e,ty)}var ay=new t_([],()=>(e,t,n)=>iy(e)?G:V(new mh(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>ly}),oy=new Xg(ay,Og()),sy=new Xg(new J_([new g_(!1,[],[ay]),new k_([],[new O_(d_,ay)])]),Og());function cy(e){return ry(e,ny)}var ly=new Xg(new t_([],()=>(e,t,n)=>cy(e)?G:V(new mh(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),Og()),uy=ll,dy=ul,fy=tl,py=xd,my=jd,hy=`~effect/MutableRef`,gy={[hy]:hy,...ci,toJSON(){return{_id:`MutableRef`,current:Kr(this.current)}}},_y=e=>{let t=Object.create(gy);return t.current=e,t},vy=Symbol.for(`effect/MutableList/Empty`),yy=()=>({head:void 0,tail:void 0,length:0}),by=()=>({array:[],mutable:!0,offset:0,next:void 0}),xy=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=by(),e.tail=e.tail.next):e.head=e.tail=by(),e.tail.array.push(t),e.length++},Sy=e=>{e.head=e.tail=void 0,e.length=0},Cy=e=>{if(!e.head)return vy;let t=e.head.array[e.head.offset];return e.head.mutable&&(e.head.array[e.head.offset]=void 0),e.head.offset++,e.length--,e.head.offset===e.head.array.length&&(e.head.next?e.head=e.head.next:Sy(e)),t},wy=`~effect/Queue`,Ty=`~effect/Queue/Enqueue`,Ey=`~effect/Queue/Dequeue`,Dy={_A:C,_E:C},Oy={[wy]:Dy,[Ty]:Dy,[Ey]:Dy,...ci,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:Ry(this)}}},ky=e=>j(t=>{let n=Object.create(Oy);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=yy(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:new Set,offers:new Set,awaiters:new Set},F(n)}),Ay=e=>ky({capacity:e}),jy=(e,t)=>L(()=>{if(e.state._tag!==`Open`)return zy;if(e.messages.length>=e.capacity)switch(e.strategy){case`dropping`:return zy;case`suspend`:return e.capacity<=0&&e.state.takers.size>0?(xy(e.messages,t),Uy(e),By):Gy(e,t);case`sliding`:return Cy(e.messages),xy(e.messages,t),By}return xy(e.messages,t),Wy(e),By}),My=S(2,(e,t)=>I(()=>Ny(e,t))),Ny=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=ou(Fi(t),Vy);return e.state.offers.size===0&&e.messages.length===0?(Yy(e,n),!0):(e.state={...e.state,_tag:`Closing`,exit:n},!0)},Py=e=>I(()=>Fy(e)),Fy=e=>{if(e.state._tag===`Done`)return!1;Sy(e.messages);let t=e.state.offers;Yy(e,e.state._tag===`Open`?Hy:e.state.exit);for(let e of t)e._tag===`Single`?e.resume(zy):e.resume(A(e.remaining.slice(e.offset)));return!0},Iy=e=>L(()=>Ly(e)??Wl(Jy(e),Iy(e))),Ly=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=Cy(e.messages);return qy(e),A(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=Ky(e.state.offers);return qy(e),A(t)}},Ry=e=>e.state._tag===`Done`?0:e.messages.length,zy=A(!1),By=A(!0),Vy=Ii(Wi()),Hy=$l(),Uy=e=>{if(e.state._tag!==`Done`&&e.state.takers.size!==0){for(let t of e.state.takers)if(e.state.takers.delete(t),t(nu),e.messages.length===0)break}},Wy=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,Uy(e)},0))},Gy=(e,t)=>Dl(n=>{if(e.state._tag!==`Open`)return n(zy);let r={_tag:`Single`,message:t,resume:n};return e.state.offers.add(r),I(()=>{e.state._tag===`Open`&&e.state.offers.delete(r)})}),Ky=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(By),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(A([]))),n},qy=e=>{if(e.state._tag===`Done`)return Fp(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(Yy(e,e.state.exit),Fp(e.state.exit.cause));for(let t of e.state.offers){let n=e.capacity-e.messages.length;if(n<=0)break;if(t._tag===`Single`)xy(e.messages,t.message),e.state.offers.delete(t),t.resume(By);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;xy(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(A([]))}}return!1},Jy=e=>Dl(t=>e.state._tag===`Done`?t(e.state.exit):(e.state.takers.add(t),I(()=>{e.state._tag!==`Done`&&e.state.takers.delete(t)}))),Yy=(e,t)=>{if(e.state._tag===`Done`)return;let n=e.state;e.state={_tag:`Done`,exit:t};for(let e of n.takers)e(t);n.takers.clear();for(let e of n.awaiters)e(t);n.awaiters.clear()},Xy=e=>new Qy(e),Zy=(e,t,n)=>Dl(r=>{if(e.free>=t)return r(n);let i=()=>{e.free<t||(e.waiters.delete(i),r(n))};return e.waiters.add(i),I(()=>{e.waiters.delete(i)})}),Qy=class{waiters=new Set;taken=0;permits;constructor(e){this.permits=e}get free(){return this.permits-this.taken}take(e){let t=L(()=>this.free<e?Zy(this,e,t):(this.taken+=e,F(e)));return t}takeIfAvailable(e){return L(()=>this.free<e?F(!1):(this.taken+=e,F(!0)))}releaseUnsafe(e,t){return this.taken-=t,this.waiters.size>0&&e.currentDispatcher.scheduleTask(()=>{for(let e of this.waiters){if(this.free<=0)break;e()}},0),this.free}resize(e){return j(t=>(this.permits=e,this.free<0||this.releaseUnsafe(t,0),R))}release(e){return j(t=>F(this.releaseUnsafe(t,e)))}get releaseAll(){return j(e=>F(this.releaseUnsafe(e,this.taken)))}withPermits(e){return t=>ld(n=>{let r=L(()=>this.free<e?Kl(n(Zy(this,e,R)),()=>r):(this.taken+=e,Xu(n(t),()=>{this.releaseUnsafe(tl(),e)},!0)));return r})}withPermit=this.withPermits(1);withPermitsIfAvailable(e){return t=>ld(n=>this.free<e?_l:(this.taken+=e,Xu(n(Ul(t)),()=>{this.releaseUnsafe(tl(),e)},!0)))}},$y=`~effect/Channel`,eb=e=>w(e,$y),tb={[$y]:{_Env:C,_InErr:C,_InElem:C,_OutErr:C,_OutElem:C},pipe(){return x(this,arguments)}},nb=e=>{let t=Object.create(tb);return t.transform=(t,n)=>cm(e(t,n),e=>B(Yp(e))),t},rb=(e,t)=>nb((n,r)=>H(ob(e)(n,r),e=>t(e,r))),ib=e=>nb((t,n)=>e),ab=e=>nb(Fm(function*(t,n){let r=zf(n),i=e=>Bf(r,zp(e));return bm(yield*bm(e(t,n,r),i),i)})),ob=e=>e.transform,sb=e=>nb((t,n)=>Gp(()=>ob(e())(t,n))),cb=e=>ib(B(V(e))),lb=e=>ib(Kp(()=>{let t=!1;return Gp(()=>t?bf():(t=!0,e))})),ub=e=>nb((t,n)=>db({scope:n,readable:e.evaluate(),onError:e.onError,releaseLockOnEnd:e.releaseLockOnEnd})),db=e=>{let t=e.readable.getReader(),n=e.exit??_y(void 0),r=Gp(()=>n.current?n.current:pm(Wp({try:()=>t.read(),catch:e.onError}),{onFailure:e=>n.current??Yp(e),onSuccess:({done:e,value:t})=>n.current?n.current:e?bf():B(eo(t))}));return am(Rf(e.scope,e.releaseLockOnEnd?Kp(()=>t.releaseLock()):Up(()=>t.cancel().catch(Dn))),r)},fb=S(2,(e,t)=>rb(e,e=>Kp(()=>{let n=0;return U(e,e=>t(e,n++))}))),pb=e=>e===void 0||e!==`unbounded`&&e<=1,mb=S(e=>eb(e[0]),(e,t,n)=>pb(n?.concurrency)?hb(e,t):gb(e,t,n)),hb=(e,t)=>nb((n,r)=>{let i=0;return U(ob(e)(n,r),H(e=>t(e,i++)))}),gb=(e,t,n)=>ab(Fm(function*(r,i,a){let o=0,s=yield*ob(e)(r,i),c=n.concurrency===`unbounded`?2**53-1:n.concurrency,l=yield*Ay(0);yield*Rf(a,Py(l));let u=jm(yield*mm()),d=py(a);if(n.unordered){let e=Xy(c),n=Cn(e.release(1)),r=pm({onFailure:e=>H(My(l,e),n),onSuccess:e=>H(jy(l,e),n)});yield*e.take(1).pipe(H(()=>s),H(e=>(d(u(r(t(e,o++)))),qp)),Tm({disableYield:!0}),cm(t=>e.withPermits(c-1)(My(l,t))),km(a))}else{let e=yield*Ay(c-2);yield*Rf(a,Py(e)),yield*Iy(e).pipe(tm,H(e=>jy(l,e)),Tm({disableYield:!0}),cm(e=>My(l,e)),km(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,Ny(l,e.cause))};yield*s.pipe(H(i=>{if(n)return Yp(n);let a=u(t(i,o++));return d(a),a.addObserver(r),jy(e,uy(a))}),Tm({disableYield:!0}),cm(t=>jy(e,Cf(t)).pipe(nm(My(e,t)))),km(a))}return Iy(l)})),_b=S(2,(e,t)=>nb((n,r)=>{let i=zf(r);return U(ob(e)(n,i),e=>{let a=e.pipe(cm(e=>{if(Fp(e))return Yp(e);let o=i;return i=zf(r),Bf(o,Cf(e)).pipe(nm(ob(t(e))(n,i)),H(e=>(a=e,e)))}));return Gp(()=>a)})})),vb=S(2,(e,t)=>nb((n,r)=>H(ob(e)(n,r),e=>ob(t)(e,r)))),yb=S(2,(e,t)=>ab((n,r,i)=>Lf(i,t).pipe(nm(ob(e)(n,r))))),bb=S(2,(e,t)=>yb(e,e=>t)),xb=(e,t,n)=>Gp(()=>{let r=Ff();return Pp(H(ob(e)(bf(),r),t),n||B).pipe(xm(e=>Bf(r,e)))}),Sb=S(2,(e,t)=>nb((n,r)=>U(_m(ob(e)(n,r),t),_m(t)))),Cb=S(2,(e,t)=>xb(e,e=>Tm(H(e,t),{disableYield:!0}))),wb=(e,t)=>ob(e)(bf(),t),Tb=(e,t,n)=>e===G?n(t):Bm(e,n);function Eb(e){if(e._tag===`Middleware`)return(t,n,r)=>Db(t===G?e.decode(eh(nh(n)),r):e.decode(Lm(t,nh),r));let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>e===G?eh(t):e;case`Transform`:{let e=e=>e===W?th:eh(t.transform(e));return(t,n)=>Tb(t,n,e)}case`TransformOptional`:{let e=e=>rh(t.transform(nh(e)));return(t,n)=>Tb(t,n,e)}case`TransformEffect`:return(e,n,r)=>Tb(e,n,e=>e===W?th:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>Tb(e,n,e=>Db(t.transform(nh(e),r)))}}var Db=e=>Bm(e,rh),Ob=(e,t,n,r)=>cm(r,r=>Xp(()=>hf(r,r=>new lh(e,r,t,n))));function kb(e,t){let n=Eb(e.link.transformation),r;return(i,a)=>{if(i===W)return th;if(e.isConstructed(i))return G;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function Ab(e,t){let n=e.context.constructorDefault;return(r,i)=>{if(r!==W&&r!==void 0)return t(r,i);let a=n;if(z(a)&&a._tag===`Success`){let e=t(a[O],i);return e===G?a:e}return Bm(Ob(e,r,i,a),e=>{let n=t(e,i);return n===G?eh(e):n})}}function jb(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:Ab(e,n)}function Mb(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?Zv(e):void 0,o=a?kb(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>Eb(e.transformation)),u=e.encodingChecks;if(!c&&!s&&!u)return o;let d,f=(t,n)=>{let r=o(t,n);if(u&&!n.disableChecks){if(z(r)){if(r._tag===`Success`){let i=r===G?t:r[O];if(t!==W&&i!==W){let i=Xv(u,t,void 0,e,n);i&&(r=V(new ph(e,i,t,n)))}}}else r=H(r,r=>{if(t!==W&&r!==W){let r=Xv(u,t,void 0,e,n);if(r)return V(new ph(e,r,t,n))}return B(r)})}if(s&&!n.disableChecks){if(z(r)){if(r._tag===`Success`){let i=r===G?t:r[O];if(i===W)return r;let a=Xv(s,i,void 0,e,n);a&&(r=V(new ph(e,a,i,n)))}}else r=H(r,t=>{if(t!==W){let r=Xv(s,t,void 0,e,n);if(r)return V(new ph(e,r,t,n))}return B(t)})}return r},p=i===void 0?f:i(f);return c?(n,r)=>{let i=d??=c.map(e=>t(e.to)),a=n,o=i[i.length-1](n,r);for(let e=c.length-1;e>=0;e--)if(o=l[e](o,a,r),e!==0){let t=i[e-1];o._tag===`Success`?(a=o[O],o=t(a,r)):o=Bm(o,e=>{let n=t(e,r);return n===G?eh(e):n})}if(o._tag===`Success`){let e=o[O],t=p(e,r);return t===G?o:t}return o=Ob(e,n,r,o),Bm(o,e=>{let t=p(e,r);return t===G?eh(e):t})}:p}var Nb=Symbol(),Pb=new WeakMap,Fb=e=>zb(e).parser,Ib=e=>zb(e).makeEffect,Lb=e=>jb(e,Ib),Rb=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=Mb(this.ast,Fb)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=Mb(this.ast,Ib,Lb)}};function zb(e){let t=Pb.get(e);if(t!==void 0)return t;let n=new Rb(e);return Pb.set(e,n),n}function Bb(e){let t=e.ast,n;return(e,r)=>(n??=Qb(rx,Pv(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function Vb(e){let t=Bb(e);return(e,n)=>{let r=Pm(t(e,n));return Ef(r)?Ca(r.value):(Ph(r.cause,`Option adapter can only return none for schema issues`),Sa())}}function Hb(e){return tx(Pv(e.ast))}function Ub(e){return Gb(e.ast)}function Wb(e){{let t=$b(Xb(e));return e=>{let n=t(e,Zg);return Ef(n)?!0:(Ph(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function Gb(e){let t=Pv(e),n=e=>(n=Wb(t),n(e));return e=>n(e)}function Kb(e,t){let n=Xb(e.ast);return t===void 0?n:(e,r)=>n(e,Jb(t,r))}function qb(e,t){let n=Xb(Lv(e.ast));return t===void 0?n:(e,r)=>n(e,Jb(t,r))}var Jb=(e,t)=>t?{...e,...t}:e,Yb=e=>e===W?V(new hh):B(e);function Xb(e){return Qb(nx,e)}function Zb(e,t){return e===G?B(t):z(e)?e[O]===W?Yb(W):e:Bm(e,Yb)}function Qb(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??Zg);return a===G?B(r):z(a)?a[O]===W?Yb(W):a:Bm(a,Yb)}}function $b(e){return(t,n)=>Pm(e(t,n))}function ex(e,t){let n=Pm(e);if(Ef(n))return n.value;let r=Ph(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}function tx(e){let t,n;return(r,i)=>{t??=zb(e);let a=i?.disableChecks?i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i?.parseOptions??Zg,o=t.make;if(o!==void 0&&r!==W){let e;try{e=o(r,a)}catch(e){throw Ph(df(e),`Constructor adapter can only throw schema issues`),e}if(e!==Nb&&e!==W)return e}return ex(Zb((n??=t.makeEffect)(r,a),r),`Constructor adapter can only throw schema issues`)}}var nx=e=>zb(e).parser,rx=e=>zb(e).makeEffect,ix=`~effect/Schema/Schema`,ax={[ix]:ix,pipe(){return x(this,arguments)},annotate(e){return this.rebuild(fv(this.ast,e))},annotateKey(e){return this.rebuild(Sv(this.ast,e))},check(...e){return this.rebuild(mv(this.ast,e))}};function ox(e,t){function n(){}let r=Object.setPrototypeOf(n,ax);return t&&(Object.hasOwn(t,`name`)||Object.hasOwn(t,`length`)||Object.hasOwn(t,`__proto__`))?Object.defineProperties(r,Object.getOwnPropertyDescriptors({...t})):Object.assign(r,t),r.ast=e,r.rebuild=e=>ox(e,t),r.makeEffect=Bb(r),r.make=Hb(r),r.makeOption=Vb(r),r}function sx(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function cx(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function lx(e){return encodeURI(sx(e)).replace(/#/g,`%23`)}function ux(e){if(e.length===0||e===`#`)return``;if(!e.startsWith(`#`))return;let t=e.slice(1);try{if(encodeURI(t).replace(/%25/g,`%`).replace(/#/g,`%23`)!==t)return;let e=decodeURIComponent(t);return e.startsWith(`/`)&&!/~(?:[^01]|$)/.test(e)?e:void 0}catch{return}}function dx(e){let t=ux(e);return t===void 0?void 0:t.length===0?[]:t.slice(1).split(`/`).map(cx)}function fx(e){return e.reduce((e,t)=>`${e}/${lx(t)}`,`#`)}var px=[`example`,`discriminator`,`xml`,`externalDocs`];function mx(e){let t=Object.keys(e.definitions),n=new Map,r=new Set(t.filter(e=>hx.test(e))),i=t.filter(e=>!hx.test(e)).sort().map(e=>[e,gx(e)]);for(let[e,t]of i)r.has(t)||(r.add(t),n.set(e,t));for(let[e,t]of i){if(n.has(e))continue;let i,a=0;do i=`${t}_${++a}`;while(r.has(i));r.add(i),n.set(e,i)}function a(t,r=!1){let i=xx(t.$id),a=Vn(t.$defs)?t.$defs:void 0;return _x(t,(t,o)=>{wx(t,px,`OpenAPI 3.1`,`Draft 2020-12`),yx(t,(t,s)=>{let c=t.startsWith(`#`)?dx(t):void 0;if(c===void 0||c[0]!==`$defs`||c.length<2)return t;let l=c[1];return i?(r&&!o&&Object.hasOwn(e.definitions,l)&&(a===void 0||!Object.hasOwn(a,l))&&Cx(s,`OpenAPI 3.1`,`a schema resource cannot reference the shared definitions pool`),t):o?t:fx([`components`,`schemas`,n.get(l)??l,...c.slice(2)])})})}let o=e.schemas.map(e=>a(e,!0)),s={};for(let r of t)E(s,n.get(r)??r,a(e.definitions[r]));return{dialect:`openapi-3.1`,schemas:o,definitions:s}}var hx=/^[a-zA-Z0-9.\-_]+$/;function gx(e){return e.length===0?`_`:e.replace(/[^a-zA-Z0-9._-]/gu,`_`)}function _x(e,t){return n(e,!1,!0);function n(e,r,i=!1){if(!Vn(e))return e;let a=r||!i&&xx(e.$id),o={};for(let t of Object.keys(e)){let r=e[t],i=r;switch(t){case`$defs`:case`properties`:case`patternProperties`:case`dependentSchemas`:i=bx(r,e=>n(e,a))??r;break;case`allOf`:case`anyOf`:case`oneOf`:case`prefixItems`:i=Array.isArray(r)?r.map(e=>n(e,a)):r;break;case`not`:case`additionalProperties`:case`propertyNames`:case`unevaluatedProperties`:case`items`:case`contains`:case`unevaluatedItems`:case`if`:case`then`:case`else`:case`contentSchema`:i=n(r,a)}E(o,t,i)}return t(o,a),o}}function vx(e,t){return _x(e,e=>{yx(e,t)})}function yx(e,t){typeof e.$ref==`string`&&E(e,`$ref`,t(e.$ref,`$ref`)),typeof e.$dynamicRef==`string`&&E(e,`$dynamicRef`,t(e.$dynamicRef,`$dynamicRef`))}function bx(e,t){if(!Vn(e))return;let n={};for(let r of Object.keys(e))E(n,r,t(e[r],r));return n}function xx(e){return typeof e==`string`&&e.length>0&&e[0]!==`#`}var Sx=[`$anchor`,`$defs`,`$dynamicAnchor`,`$dynamicRef`,`$vocabulary`,`contentSchema`,`dependentRequired`,`dependentSchemas`,`maxContains`,`minContains`,`prefixItems`,`unevaluatedItems`,`unevaluatedProperties`];[...Sx],[...Sx];function Cx(e,t,n){throw Error(`Cannot convert JSON Schema keyword "${e}" to ${t}: ${n}`)}function wx(e,t,n,r){for(let i of t)Object.hasOwn(e,i)&&Cx(i,n,`it is not active in ${r} but would become active in the target`)}function Tx(e){return ox(Ex(e.ast),{schema:e})}var Ex=yv(e=>{let t=jx(e,Ex),n=e.context;return t===e||n===void 0?t:vv(t,Dx(n))});function Dx(e){return e.constructorDefault===void 0?e:new Qg(e.isOptional,e.isMutable,void 0,e.annotations)}function Ox(e){if(e.propertySignatures.some(e=>typeof e.name!=`string`))throw new globalThis.Error(`Objects property names must be strings`,{cause:e})}function kx(e){return t=>{let n=new Map;for(let e=0;e<t.length;e++)n.set(Fv(t[e]),e);let r=[...t].sort((t,r)=>{t=Fv(t),r=Fv(r);let i=e(t),a=e(r);return i===a?n.get(t)-n.get(r):i-a});return r.some((e,n)=>e!==t[n])?r:t}}var Ax=kx(e=>{switch(e._tag){case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function jx(e,t){switch(e._tag){case`Declaration`:{let n=e.annotations?.toCodecJson??e.annotations?.toCodec;if(!Ln(n))return K(e,[oy]);let r=n(e.typeParameters.map(e=>ox(Fv(e))));return r===void 0?e:K(e,[hv(r,t)])}case`Unknown`:return K(e,[oy]);case`ObjectKeyword`:return K(e,[sy]);case`Undefined`:case`Void`:case`Literal`:case`Number`:return e.toCodecJson();case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return Ox(e),e.recur(t,Hv);case`Union`:{let n=Ax(e.types);return n===e.types?e.recur(t):new J_(n,e.options,e.annotations,e.checks,e.encoding,e.context,e.encodingChecks).recur(t)}case`Arrays`:case`Suspend`:return e.recur(t)}return e}function Mx(e){return ox(Bx(e.ast),{schema:e})}function Nx(e){return ox(Hx(e.ast))}var Px=kx(e=>{switch(e._tag){case`Null`:case`Boolean`:case`Number`:case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function Fx(e,t,n){switch(e._tag){case`Declaration`:{let r=e.typeParameters.map(e=>ox(t(Fv(e)))),i=e.annotations?.toCodecStringTree;if(Ln(i)){let n=i(r);return n===void 0?e:K(e,[hv(n,t)])}let a=e.annotations?.toCodecJson,o=Ln(a)?a(r):void 0,s=o===void 0?e.annotations?.toCodec:void 0,c=o??(Ln(s)?s(r):void 0);return c===void 0?n(e):K(e,[hv(c,t)])}case`Null`:return K(e,[Ix]);case`Boolean`:return K(e,[Lx]);case`Unknown`:case`ObjectKeyword`:return K(e,[ly]);case`Enum`:case`Number`:case`Literal`:case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return Ox(e),e.recur(t,Hv);case`Union`:{let n=Px(e.types);return n===e.types?e.recur(t):new J_(n,e.options,e.annotations,e.checks,e.encoding,e.context,e.encodingChecks).recur(t)}case`Arrays`:case`Suspend`:return e.recur(t)}return e}var Ix=new Xg(new l_(`null`),new Sg(Yh(()=>null),Yh(()=>`null`))),Lx=new Xg(new J_([new l_(`true`),new l_(`false`)]),new Sg(Yh(e=>e===`true`),Qh())),Rx=new Sg(Yh(e=>typeof e==`string`?[e]:e),Jh()),zx=e=>e.transformation===Rx,Bx=yv(e=>{let t=Fx(e,Bx,e=>{throw new globalThis.Error(`Missing structural codec for StringTree`,{cause:e})});return t!==e&&e.context!==void 0?vv(t,Dx(e.context)):t},{stopAt:zx}),Vx=e=>Av(e)?Cv(c_):c_,Hx=yv(e=>{let t=Ux(e);if(Kg(t)){let n=Dv(new J_([new g_(t.isMutable,t.elements.map(Vx),t.rest.map(Vx)),d_],{mode:`anyOf`}),t,Rx);return Av(e)?Cv(n):n}return t},{stopAt:zx});function Ux(e){return e._tag===`Declaration`||e._tag===`Arrays`||e._tag===`Objects`||e._tag===`Union`||e._tag===`Suspend`?e.recur(Hx):e}globalThis.RegExp;var Wx=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`);function Gx(e,t){return t.length>0&&(e+=`\n at ${Br(t)}`),Error(e)}function Kx(e){return`#/$defs/${lx(e)}`}var qx=new Set([...$m,Gm,...Jm]);function Jx(e,t){if(e===void 0)return;let n={},r=e.title;typeof r==`string`&&(n.title=r);let i=e.description,a=e.expected;typeof i==`string`?n.description=i:t?.generateDescriptions===!0&&typeof a==`string`&&(n.description=a);let o=e.default;iy(o)&&(n.default=o);let s=e.examples;Array.isArray(s)&&iy(s)&&(n.examples=s);let c=e.readOnly;typeof c==`boolean`&&(n.readOnly=c);let l=e.writeOnly;typeof l==`boolean`&&(n.writeOnly=l);let u=e.format;typeof u==`string`&&(n.format=u);let d=e.contentEncoding;typeof d==`string`&&(n.contentEncoding=d);let f=e.contentMediaType;typeof f==`string`&&(n.contentMediaType=f);let p=e.contentSchema;if(iy(p)&&(n.contentSchema=p),t?.includeAnnotationKey!==void 0)for(let[r,i]of Object.entries(e))!qx.has(r)&&t.includeAnnotationKey(r)&&iy(i)&&E(n,r,i);return Object.keys(n).length===0?void 0:n}function Yx(e){let t=e.type===`number`||e.type===`integer`?e.type:void 0,n=e;if(t!==void 0&&(n={...e},delete n.type),Array.isArray(n.allOf)){let e=[],r=!1;for(let i of n.allOf){let n=Yx(i);n.type!==void 0&&(r=!0,(t===void 0||n.type===`integer`)&&(t=n.type)),Object.keys(n.schema).length>0&&e.push(n.schema)}if(r){let{allOf:t,...r}=n;n=e.length===0?r:{...r,allOf:e}}}return{type:t,schema:n}}function Xx(e){if(!Array.isArray(e.anyOf)||e.anyOf.length!==2||e.anyOf[0]?.type!==`number`)return!1;let t=e.anyOf[1];return t?.type===`string`&&Array.isArray(t.enum)&&t.enum.length===3&&t.enum.includes(`NaN`)&&t.enum.includes(`Infinity`)&&t.enum.includes(`-Infinity`)}var Zx=`|type|format|pattern|multipleOf|minimum|maximum|exclusiveMinimum|exclusiveMaximum|minLength|maxLength|minItems|maxItems|uniqueItems|minProperties|maxProperties|propertyNames|`;function Qx(e,t){return Object.keys(e).every(e=>t.includes(`|${e}|`))}function $x(e,t){return typeof e.$ref!=`string`&&t.every(t=>!Object.hasOwn(e,t))}var eS=`|title|description|default|examples|readOnly|writeOnly|`,tS=Zx+eS;function nS(e,t,n){if(Object.keys(e).length===0)return t;let r=Object.keys(t);if(r.length===0)return e;let i=e.type===`number`||e.type===`integer`?e.type:void 0,a=Xx(e);if(i!==void 0||a){let r=Yx(t);if(r.type!==void 0){let t=i===`integer`||r.type===`integer`?`integer`:`number`,o={...e,type:t};a&&delete o.anyOf;let s=Object.keys(r.schema);return s.length===0?o:Qx(r.schema,eS)&&$x(o,s)?{...o,...r.schema}:nS(o,r.schema,n)}}if(n&&$x(e,r))return{...e,...t};let o=Array.isArray(t.allOf)&&r.length===1?t.allOf:[t];return Array.isArray(e.allOf)?{...e,allOf:[...e.allOf,...o]}:typeof e.$ref==`string`?{allOf:[e,...o]}:{...e,allOf:o}}function rS(e,t,n,r){let i=new Map,a=new WeakMap,o=new Map,s=Object.keys(n);for(let e of s)u(e,[`references`,e]);let c=to(e,(e,n)=>d(h(e,t[n]))),l={};for(let e of s){let t=i.get(e);typeof t!=`string`&&E(l,e,d(t))}return{dialect:`draft-2020-12`,schemas:c,definitions:l};function u(e,t){let r=i.get(e);if(r!==void 0)return typeof r==`string`?r:e;if(!Object.hasOwn(n,e))throw Gx(`Invalid reference ${e}`,[...t,`$ref`]);i.set(e,null);let a=n[e],s=h(a,[`references`,e]),c=f(a);if(c!==void 0){let t=o.get(c),n=t?.find(e=>cr(i.get(e),s));if(n===void 0)t===void 0?o.set(c,[e]):t.push(e);else return i.set(e,n),n}return i.set(e,s),e}function d(e){return vx(e,e=>{let t=ux(e);if(t===void 0){if(/^#(?:\/|%2f)/i.test(e))throw Error(`Invalid JSON Pointer URI fragment ${JSON.stringify(e)}`);return e}if(!t.startsWith(`/$defs/`))return e;let n=t.indexOf(`/`,7),r=i.get(cx(t.slice(7,n<0?void 0:n)));return typeof r==`string`?e.replace(/^#(?:\/|%2f).*?(?:\/|%2f).*?(?=\/|%2f|$)/i,Kx(r)):e})}function f(e){if(e._tag===`Reference`)return;let t=e.checks.length===0?e.annotations:e.checks[e.checks.length-1].annotations;return typeof t?.identifier!=`string`&&typeof t?.[`~identifier`]==`string`?t[Gm]:void 0}function p(e,t){return e?.schemas?.map((e,n)=>h(e,[...t,`schemas`,n]))??[]}function m(e,t,n){let i=e.annotations,a=i?.toJsonSchema;if(a!==void 0){let o=a({type:t,schemas:p(e.representation,[...n,`representation`])}),s=Jx(i,r),c=s===void 0?o:{...o,...s},l=s===void 0?Zx:tS;return e._tag===`Filter`&&Qx(c,l)&&(s===void 0||Qx(s,eS))?[c,!0]:[c]}if(e._tag===`Filter`)return;let o=e.checks.map((e,r)=>m(e,t,[...n,`checks`,r])).filter(e=>e!==void 0);if(o.length===0)return;let s=Jx(i,r),c=o.map(([e])=>e);return[s===void 0?{allOf:c}:{allOf:c,...s}]}function h(e,t){if(e._tag===`Reference`)return{$ref:Kx(u(e.$ref,t))};let n=a.get(e);if(n!==void 0)return n;let i=g(e,t),o=Jx(e.annotations,r);o!==void 0&&(i={...i,...o});for(let n=0;n<e.checks.length;n++){let r=typeof i.type==`string`&&iS(i.type)?i.type:void 0,a=m(e.checks[n],r,[...t,`checks`,n]);a!==void 0&&(i=nS(i,...a))}return a.set(e,i),i}function g(e,t){switch(e._tag){case`Any`:case`Unknown`:return{};case`ObjectKeyword`:return{anyOf:[{type:`object`},{type:`array`}]};case`Void`:case`Undefined`:case`Null`:return{type:`null`};case`BigInt`:return{type:`string`,allOf:[{pattern:`^-?\\d+$`}]};case`Symbol`:return{type:`string`,allOf:[{pattern:`^Symbol\\(([\\s\\S]*)\\)$`}]};case`UniqueSymbol`:return globalThis.Symbol.keyFor(e.symbol)===void 0?{not:{}}:{type:`string`,enum:[globalThis.String(e.symbol)]};case`Declaration`:return{};case`Suspend`:return h(e.thunk,[...t,`thunk`]);case`Never`:return{not:{}};case`String`:return{type:`string`};case`Number`:return{anyOf:[{type:`number`},{type:`string`,enum:[`NaN`,`Infinity`,`-Infinity`]}]};case`Boolean`:return{type:`boolean`};case`Literal`:{let t=e.literal;return typeof t==`bigint`?{type:`string`,enum:[globalThis.String(t)]}:{type:typeof t,enum:[t]}}case`Enum`:{let n=e.enums.map(([e,n],r)=>{if(typeof n==`number`&&!globalThis.Number.isFinite(n))throw Gx(`Invalid numeric enum value ${globalThis.String(n)}`,[...t,`enums`,r,1]);return{type:typeof n,enum:[n],title:e}});return n.length===0?{not:{}}:{anyOf:n}}case`TemplateLiteral`:return{type:`string`,pattern:`^${e.parts.map(oS).join(``)}$`};case`Arrays`:{if(e.rest.length>1)throw Gx(`Invalid schema representation document`,[...t,`rest`]);let n={type:`array`},i=e.elements.length,a=e.elements.map((e,n)=>{e.isOptional&&i--;let a=h(e.type,[...t,`elements`,n,`type`]),o=Jx(e.annotations,r);return o===void 0?a:nS(a,o)});if(a.length>0?(n.prefixItems=a,n.maxItems=e.elements.length,i>0&&(n.minItems=i)):n.items=!1,e.rest.length===1){delete n.maxItems;let r=h(e.rest[0],[...t,`rest`,0]);Object.keys(r).length>0?n.items=r:delete n.items}return n}case`Objects`:{if(e.propertySignatures.length===0&&e.indexSignatures.length===0)return{not:{type:`null`}};let n={type:`object`},i={},a=[];for(let n=0;n<e.propertySignatures.length;n++){let o=e.propertySignatures[n];if(typeof o.name!=`string`)throw Gx(`Invalid schema representation document`,[...t,`propertySignatures`,n,`name`]);let s=o.name,c=h(o.type,[...t,`propertySignatures`,n,`type`]),l=Jx(o.annotations,r);E(i,s,l===void 0?c:nS(c,l)),o.isOptional||a.push(s)}e.propertySignatures.length>0&&(n.properties=i),a.length>0&&(n.required=a);let o={},s=[],c=[],l=!1;for(let n=0;n<e.indexSignatures.length;n++){let r=e.indexSignatures[n],i=h(r.type,[...t,`indexSignatures`,n,`type`]);cr(i,{not:{}})&&(i=!1),c.push(i);let a=_(r.parameter,[...t,`indexSignatures`,n,`parameter`],new Set);if(a===void 0){l=!0;continue}if(a.length===0)s.push(i);else for(let e of a){let t=o[e];E(o,e,t===void 0?i:t===!1||i===!1?!1:nS(t,i))}}let u=Object.keys(o).length>0;if(u&&(n.patternProperties=o),l&&r?.onExcessProperty===`error`){let r=[];e.propertySignatures.length>0&&r.push({enum:Object.keys(i)});for(let n=0;n<e.indexSignatures.length;n++)r.push(h(e.indexSignatures[n].parameter,[...t,`indexSignatures`,n,`parameter`]));n.propertyNames=r.length===1?r[0]:{anyOf:r},n.additionalProperties=c.length===1?c[0]:{anyOf:c},s.length>0&&(n.allOf=s.map(e=>({type:`object`,additionalProperties:e})))}else s.length===0?n.additionalProperties=l||r?.onExcessProperty!==`error`:s.length===1&&e.propertySignatures.length===0&&!u?n.additionalProperties=s[0]:s.length>0&&(n.allOf=s.map(e=>({type:`object`,additionalProperties:e})));return typeof n.additionalProperties==`object`&&n.additionalProperties!==null&&Object.keys(n.additionalProperties).length===0&&delete n.additionalProperties,n}case`Union`:{let n=e.types.map((e,n)=>h(e,[...t,`types`,n]));if(n.length===0)return{not:{}};let r=e.options?.mode??`anyOf`;if(r===`anyOf`&&n.length>1){let e=aS(n);if(e!==void 0)return e}return r===`anyOf`?{anyOf:n}:{oneOf:n}}}}function _(e,t,r){switch(e._tag){case`Reference`:{if(!Object.hasOwn(n,e.$ref))throw Gx(`Invalid reference ${e.$ref}`,[...t,`$ref`]);if(u(e.$ref,t),r.has(e.$ref))return;let i=new Set(r).add(e.$ref);return _(n[e.$ref],[`references`,e.$ref],i)}case`String`:{if(e.checks.length===0)return[];if(e.checks.length!==1||e.checks[0]._tag!==`Filter`||e.checks[0].annotations?.toJsonSchema===void 0)return;let n=h(e,t);return n.type===`string`&&typeof n.pattern==`string`&&Qx(n,`|type|pattern|title|description|default|examples|readOnly|writeOnly|`)?[n.pattern]:void 0}case`TemplateLiteral`:return e.checks.length===0?[`^${e.parts.map(oS).join(``)}$`]:void 0;case`Union`:{if(e.types.length===0||e.checks.length>0||e.options?.mode===`oneOf`)return;let n=[];for(let i=0;i<e.types.length;i++){let a=_(e.types[i],[...t,`types`,i],r);if(a===void 0)return;if(a.length===0)return[];n.push(...a)}return n}default:throw Gx(`Invalid schema representation document`,t)}}}function iS(e){return e===`string`||e===`number`||e===`boolean`||e===`array`||e===`object`||e===`null`||e===`integer`}function aS(e){let t,n=[];for(let r of e){if(Object.keys(r).length!==2||r.type===void 0||!Array.isArray(r.enum)||r.enum.length===0)return;if(t===void 0)t=r.type;else if(r.type!==t)return;for(let e of r.enum){if(n.includes(e))return;n.push(e)}}return{type:t,enum:n}}function oS(e){switch(e._tag){case`Literal`:return Wx(globalThis.String(e.literal));case`String`:return Uv;case`Number`:return S_;case`TemplateLiteral`:return e.parts.map(oS).join(``);case`Union`:return`(?:${e.types.map(oS).join(`|`)})`;default:throw Gx(`Invalid schema representation document`,[])}}function sS(e,t){return rS(e.representations,e.representations.map((e,t)=>[`representations`,t]),e.references,t)}var cS=({identifier:e})=>e;function lS(e){return e===void 0?void 0:{annotations:e}}function uS(e,t){let n={},r=new Map,i=new Set,a=new Map,o=new Set;for(let t of e)f(t);let s=t?.referencePolicy??cS;for(let e of a.values())for(let t of e.values()){let e=s({ast:t.ast,occurrences:t.occurrences,identifier:t.identifier});e===void 0?t.isRecursive&&(t.reference=c(`${t.ast._tag}_`,t,``)):t.reference=c(e,t,e===t.identifier||!e.endsWith(`_`)?`_`:``)}return{representations:to(e,e=>m(e)),references:n};function c(e,t,n=`_`){let i=e,a=0;for(;r.has(i);){if(r.get(i)===t)return i;i=`${e}${n}${++a}`}return r.set(i,t),i}function l(e,t,n){let r=t.fallback;return r===void 0?n===t.identifier?e:fv(e,{identifier:n}):Xm(e)===r?e:fv(e,{[Gm]:r})}function u(e,t){if(!Object.hasOwn(n,e)&&!i.has(e)){i.add(e);let r=h(t);i.delete(e),E(n,e,r)}return{_tag:`Reference`,$ref:e}}function d(e){let t=dv(e),n=lv(t),r=Ym(t),i=r===void 0?(t===e?void 0:Ym(e))??Xm(t):void 0;i!==void 0&&(r=`${i}Encoded`);let o=a.get(n);o===void 0&&(o=new Map,a.set(n,o));let s=o.get(r);return s===void 0&&(s={ast:n,identifier:r,fallback:i,occurrences:0,isRecursive:!1,reference:void 0},o.set(r,s)),s}function f(e){let t=d(e),n=t.ast;if(t.occurrences++,o.has(t)){t.isRecursive=!0;return}if(!(t.occurrences>1)){switch(o.add(t),p(n.checks),n._tag){case`Declaration`:case`Arrays`:case`Objects`:case`Union`:n.recur(e=>(f(e),e));break;case`TemplateLiteral`:n.parts.forEach(f);break;case`Suspend`:f(n.thunk())}o.delete(t)}}function p(e){e?.forEach(e=>{e.annotations?.representation?.schemas?.forEach(e=>f(Pv(e))),e._tag===`FilterGroup`&&p(e.checks)})}function m(e){let t=d(e),n=t.ast,r=t.reference;return r===void 0?h(n):u(r,t.identifier===void 0?n:l(n,t,r))}function h(e){let t=g(e.checks);switch(e._tag){case`Declaration`:return{_tag:`Declaration`,typeParameters:e.typeParameters.map(e=>m(e)),checks:t,...ee(e.annotations)};case`Null`:case`Undefined`:case`Void`:case`Never`:case`Unknown`:case`Any`:case`String`:case`Boolean`:case`Number`:case`BigInt`:case`Symbol`:case`ObjectKeyword`:return{_tag:e._tag,checks:t,...lS(e.annotations)};case`Literal`:return{_tag:`Literal`,literal:e.literal,checks:t,...lS(e.annotations)};case`UniqueSymbol`:return{_tag:`UniqueSymbol`,symbol:e.symbol,checks:t,...lS(e.annotations)};case`Enum`:return{_tag:`Enum`,enums:e.enums,checks:t,...lS(e.annotations)};case`TemplateLiteral`:return{_tag:`TemplateLiteral`,parts:e.parts.map(e=>m(e)),checks:t,...lS(e.annotations)};case`Arrays`:return{_tag:`Arrays`,elements:e.elements.map(e=>{let t=dv(e),n=t.context?.annotations;return{isOptional:Av(t),type:m(e),...lS(n)}}),rest:e.rest.map(e=>m(e)),checks:t,...lS(e.annotations)};case`Objects`:return{_tag:`Objects`,propertySignatures:e.propertySignatures.map(e=>{let t=dv(e.type),n=t.context?.annotations;return{name:e.name,type:m(e.type),isOptional:Av(t),isMutable:jv(t),...lS(n)}}),indexSignatures:e.indexSignatures.map(e=>({parameter:m(e.parameter),type:m(e.type)})),checks:t,...lS(e.annotations)};case`Union`:return{_tag:`Union`,types:e.types.map(e=>m(e)),...e.options===void 0?{}:{options:e.options},checks:t,...lS(e.annotations)};case`Suspend`:return{_tag:`Suspend`,checks:[],thunk:m(e.thunk()),...lS(e.annotations)}}}function g(e){return e?.map(_)??[]}function _(e){switch(e._tag){case`Filter`:return{_tag:`Filter`,aborted:e.aborted,...v(e.annotations)};case`FilterGroup`:return{_tag:`FilterGroup`,checks:to(e.checks,_),...v(e.annotations)}}}function ee(e){if(e===void 0)return;let{representation:t,...n}=e;return{...t===void 0?void 0:{representation:t},...Object.keys(n).length===0?void 0:{annotations:n}}}function v(e){if(e===void 0)return;let{representation:t,...n}=e,r=t===void 0?void 0:t.schemas===void 0?t:{...t,schemas:t.schemas.map(e=>m(Pv(e)))};return{...r===void 0?void 0:{representation:r},...Object.keys(n).length===0?void 0:{annotations:n}}}}function dS(e,t){let n=t;for(let t of e)n=hS(n,t);return n}function fS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pS(e){if(e===``)return[];if(e.charCodeAt(0)!==47)throw Error(`Invalid JSON Pointer, it must start with "/": ${JSON.stringify(e)}`);return e.split(`/`).slice(1).map(cx)}function mS(e){if(!/^(0|[1-9]\d*)$/.test(e))throw Error(`Invalid array index: "${e}"`);return Number(e)}function hS(e,t){if(t.path===``){if(t.op===`remove`)throw Error(`Unsupported operation at the root`);return t.value}let n=gS(e,t.path);if(n===null)throw Error(`Cannot ${t.op} at "${t.path}" (parent not found or not a container).`);let{lastToken:r,parent:i,stack:a}=n;if(Array.isArray(i)){if(r===`-`&&t.op!==`add`)throw Error(`"-" is not valid for ${t.op} at "${t.path}".`);let e=r===`-`?i.length:mS(r);if(e>(t.op===`add`?i.length:i.length-1))throw Error(`Array index out of bounds at "${t.path}".`);let n=i.slice();return t.op===`add`?n.splice(e,0,t.value):t.op===`remove`?n.splice(e,1):n[e]=t.value,_S(a,n)}if(fS(i)){if(t.op!==`add`&&!Object.hasOwn(i,r))throw Error(`Property "${r}" does not exist at "${t.path}".`);let e={...i};return t.op===`remove`?delete e[r]:E(e,r,t.value),_S(a,e)}throw Error(`Cannot ${t.op} at "${t.path}" (parent not found or not a container).`)}function gS(e,t){let n=pS(t);if(n.length===0)return null;let r=n[n.length-1],i=[],a=e;for(let e=0;e<n.length-1;e++){let t=n[e];if(Array.isArray(a)){let e=mS(t);if(e>=a.length)return null;i.push({container:a,token:e}),a=a[e];continue}if(fS(a)){if(!Object.hasOwn(a,t))return null;i.push({container:a,token:t}),a=a[t];continue}return null}return{stack:i,parent:a,lastToken:r}}function _S(e,t){let n=t;for(let t=e.length-1;t>=0;t--){let{container:r,token:i}=e[t];if(Array.isArray(r)){let e=r.slice();e[i]=n,n=e}else{let e={...r};E(e,i,n),n=e}}return n}var vS=S(2,(e,t)=>({...e,...t})),yS=e=>e,bS=`~effect/Schema/SchemaError`;function xS(e){return w(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}var SS=new WeakMap,CS=`~effect/Redacted`,wS=e=>w(e,CS),TS=(e,t)=>{let n=Object.create(ES);return t?.label&&(n.label=t.label),SS.set(n,e),n},ES={[CS]:{_A:e=>e},label:void 0,...ci,toJSON(){return this.toString()},toString(){return`<redacted${Mn(this.label)?`:`+this.label:``}>`},[Wn](){return T(SS.get(this))},[sr](e){return wS(e)&&cr(SS.get(this),SS.get(e))}},DS=`~effect/http/Cookies`,OS=`~effect/http/Cookies/Cookie`,kS={[DS]:DS,...qr,toJSON(){return{_id:`effect/Cookies`,cookies:Ha(this.cookies,e=>e.toJSON())}},pipe(){return x(this,arguments)}},AS=e=>{let t=Object.create(kS);return t.cookies=e,t},jS=e=>{let t={};for(let n of e)E(t,n.name,n);return AS(t)},MS=e=>{let t=typeof e==`string`?[e]:e,n=[];for(let e of t){let t=NS(e.trim());t&&n.push(t)}return jS(n)};function NS(e){let t=e.split(`;`).map(e=>e.trim()).filter(e=>e!==``);if(t.length===0)return;let n=t[0].indexOf(`=`);if(n===-1)return;let r=t[0].slice(0,n);if(!FS.test(r))return;let i=t[0].slice(n+1),a=LS(i);if(t.length===1)return Object.assign(Object.create(IS),{name:r,value:a,valueEncoded:i});let o={};for(let e=1;e<t.length;e++){let n=t[e],r=n.indexOf(`=`),i=r===-1?n:n.slice(0,r).trim(),a=r===-1?void 0:n.slice(r+1).trim();switch(i.toLowerCase()){case`domain`:{if(a===void 0)break;let e=a.trim().replace(/^\./,``);e&&(o.domain=e);break}case`expires`:{if(a===void 0)break;let e=new Date(a);isNaN(e.getTime())||(o.expires=e);break}case`max-age`:{if(a===void 0)break;let e=parseInt(a,10);isNaN(e)||(o.maxAge=Ms(e));break}case`path`:if(a===void 0)break;a[0]===`/`&&(o.path=a);break;case`priority`:if(a===void 0)break;switch(a.toLowerCase()){case`low`:o.priority=`low`;break;case`medium`:o.priority=`medium`;break;case`high`:o.priority=`high`}break;case`httponly`:o.httpOnly=!0;break;case`secure`:o.secure=!0;break;case`partitioned`:o.partitioned=!0;break;case`samesite`:if(a===void 0)break;switch(a.toLowerCase()){case`lax`:o.sameSite=`lax`;break;case`strict`:o.sameSite=`strict`;break;case`none`:o.sameSite=`none`}}}return Object.assign(Object.create(IS),{name:r,value:a,valueEncoded:i,options:Object.keys(o).length>0?o:void 0})}var PS=jS([]),FS=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,IS={[OS]:OS,...qr,toJSON(){return{_id:`effect/Cookies/Cookie`,name:this.name,value:this.value,options:this.options}}},LS=e=>{try{return decodeURIComponent(e)}catch{return e}},RS=Symbol.for(`~effect/http/Headers`),zS=Object.defineProperties(Object.create(null),{[RS]:{value:RS},[jr]:{value(e){return YS(this,ts(e,ZS))}},toJSON:{value(){return Nr(this)}},[sr]:{value(e){return VS(this,e)}},[Wn]:{value(){return Qn(this)}},toString:{value:qr.toString},[Gr]:{value:qr[Gr]}}),BS=e=>Object.assign(Object.create(zS),e),VS=Ga(Er()),HS=Object.create(zS),US=e=>{if(e===void 0)return HS;if(Symbol.iterator in e){let t=Object.create(zS);for(let[n,r]of e)t[n.toLowerCase()]=r;return t}let t=Object.create(zS);for(let[n,r]of Object.entries(e))Array.isArray(r)?t[n.toLowerCase()]=r.join(`, `):r!==void 0&&(t[n.toLowerCase()]=r);return t},WS=e=>Object.setPrototypeOf(e,zS),GS=S(3,(e,t,n)=>{let r=BS(e);return r[t.toLowerCase()]=n,r}),KS=S(2,(e,t)=>BS({...e,...US(t)})),qS=S(2,(e,t)=>{let n=BS(e);return Object.assign(n,t),n}),JS=S(2,(e,t)=>{let n=BS(e);return delete n[t.toLowerCase()],n}),YS=S(2,(e,t)=>{let n={...e},r=t=>{if(typeof t==`string`){let r=t.toLowerCase();r in e&&(n[r]=TS(e[r]))}else for(let r in e)r.search(t)!==-1&&(n[r]=TS(e[r]))};if(Array.isArray(t))for(let e=0;e<t.length;e++)r(t[e]);else r(t);return n}),XS=(e,t)=>{for(let n=0;n<t.length;n++){let r=t[n];if(typeof r==`string`){if(r.toLowerCase()===e.toLowerCase())return!0}else if(e.search(r)!==-1)return!0}return!1},ZS=N(`effect/Headers/CurrentRedactedNames`,{defaultValue:()=>[`authorization`,`cookie`,`set-cookie`,`x-api-key`]}),QS=`~effect/http/UrlParams`,$S=e=>w(e,QS),eC={...ci,[QS]:QS,[Symbol.iterator](){return this.params[Symbol.iterator]()},toJSON(){return{_id:`UrlParams`,params:Object.fromEntries(this.params)}},[sr](e){return iC(this,e)},[Wn](){return er(this.params.flat())}},tC=e=>{let t=Object.create(eC);return t.params=e,t},nC=e=>{if($S(e))return e;let t=rC(e),n=[];for(let e=0;e<t.length;e++)if(Array.isArray(t[e][0])){let[r,i]=t[e];n.push([`${r[0]}[${r.slice(1).join(`][`)}]`,i])}else n.push(t[e]);return tC(n)},rC=e=>{let t=typeof e[Symbol.iterator]==`function`?qa(e):Object.entries(e),n=[];for(let[e,r]of t)if(Array.isArray(r))for(let t=0;t<r.length;t++)r[t]!==void 0&&n.push([e,String(r[t])]);else if(typeof r==`object`&&r){let t=rC(r);for(let[r,i]of t)n.push([[e,...typeof r==`string`?[r]:r],i])}else r!==void 0&&n.push([e,String(r)]);return n},iC=wr((e,t)=>aC(e.params,t.params)),aC=no(Ba([Er(),Er()])),oC=tC([]),sC=S(2,(e,t)=>tC(t(e.params))),cC=S(2,(e,t)=>{let n=nC(t).params.slice(),r=new Set;for(let e=0;e<n.length;e++)r.add(n[e][0]);for(let t=0;t<e.params.length;t++)r.has(e.params[t][0])||n.push(e.params[t]);return tC(n)}),lC=S(2,(e,t)=>sC(e,Xa(nC(t).params))),uC=e=>new URLSearchParams(nC(e).params).toString(),dC=e=>{let t={};for(let[n,r]of e.params)if(!Object.hasOwn(t,n))E(t,n,r);else{let e=t[n];typeof e==`string`?E(t,n,[e,r]):e.push(r)}return t},fC=dC,pC=ix;function mC(){return(e,t,n)=>q(new t_(e.map(I_),e=>t(e.map(e=>q(e))),n))}function hC(e,t){return mC()([],()=>(t,n,r)=>e(t)?B(t):V(new mh(n,t,r)),t)}var gC=class extends ec(`SchemaError`){[bS]=bS;constructor(e){let t=Xr();Zr(0);try{super({issue:e})}finally{Zr(t)}}get message(){return Ah(this.issue)}toString(){return`SchemaError(${this.message})`}};function _C(e){return xS(e)}function vC(e){return z(e)?yC(e):cm(e,e=>Xp(()=>hf(e,e=>new gC(e))))}function yC(e){return Ef(e)?e:Cf(hf(e.cause,e=>new gC(e)))}function bC(e,t){let n;for(let r of e.reasons){if(!cf(r)||!_C(r.error))throw new globalThis.Error(t,{cause:e});n??=r.error}if(n===void 0)throw new globalThis.Error(t,{cause:e});return n}function xC(e){let t=Pm(e);if(Ef(t))return t.value;throw bC(t.cause,`Sync adapter can only throw schema errors`)}var SC=Ub;function CC(e,t){let n=Kb(e,t);return(e,t)=>vC(n(e,t))}var wC=CC;function TC(e,t){let n=CC(e,t);return(e,t)=>xC(n(e,t))}function EC(e,t){let n=qb(e,t);return(e,t)=>vC(n(e,t))}var q=ox;function DC(e){return w(e,pC)&&e[pC]===pC}var OC=yS(e=>{let t=XC(e);return q(Tv(e.ast),{schema:t})}),kC=yS(e=>q(Pv(e.ast),{schema:e})),AC=yS(e=>q(Fv(e.ast),{schema:e}));function jC(e){let t=q(new l_(e),{literal:e,transform(n){return t.pipe(X(jC(n),{decode:Yh(()=>n),encode:Yh(()=>e)}))}});return t}var MC=q(s_),NC=q(c_),PC=q(n_),FC=q(a_),J=q(d_),IC=q(m_),LC=q(h_),RC=q(o_);function zC(e,t){return q(e,{fields:t,mapFields(e,t){let n=e(this.fields);return zC(F_(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Y(e){return zC(F_(e,void 0),e)}function BC(e){return yS(t=>t.mapFields(vS(e)))}function VC(e,t){return q(kv(e.ast,t.ast),{key:e,value:t})}function HC(e,t){return q(e,{elements:t,mapElements(e,t){let n=e(this.elements);return HC(L_(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function UC(e){return HC(L_(e),e)}var WC=yS(e=>q(new g_(!1,[],[e.ast]),{value:e})),GC=yS(e=>q(new g_(!1,[e.ast],[e.ast]),{value:e}));function KC(e,t){return q(e,{members:t,mapMembers(e,t){let n=e(this.members);return KC(R_(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function qC(e,t){return KC(R_(e,t,void 0),e)}function JC(e){let t=e.map(jC);return q(R_(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return qC(e(this.members))},pick(e){return JC(e)},transform(e){return qC(t.map((t,n)=>t.transform(e[n])))}})}var YC=yS(e=>qC([e,PC])),XC=yS(e=>qC([e,FC]));function X(e,t){return n=>q(Dv(n.ast,e.ast,t?wg(t):Og()),{from:n,to:e})}function ZC(){return(e,t)=>nw()(e,{decode:t,encode:Kh})}function QC(e){return t=>q(Ev(t.ast,e),{schema:t})}function $C(e){return jC(e).pipe(QC(B(e)))}function ew(e,t){return Y({_tag:$C(e),...t})}function tw(e,t){return hC(t=>t instanceof e,t)}function nw(){return(e,t)=>new Xg(e.ast,wg(t))}var rw=nv,iw=q(iv);function aw(e){let t=xa(e.order),n=ya(e.order),r=ba(e.order),i=va(e.order),a=e.formatter??D;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return rw(e=>c(e,o.minimum)&&l(e,o.maximum),{expected:`a value between ${a(o.minimum)}${o.exclusiveMinimum?` (excluded)`:``} and ${a(o.maximum)}${o.exclusiveMaximum?` (excluded)`:``}`,arbitraryConstraint:{order:e.order,minimum:o.minimum,maximum:o.maximum,...o.exclusiveMinimum&&{exclusiveMinimum:!0},...o.exclusiveMaximum&&{exclusiveMaximum:!0}},...e.annotate?.(o),...s})}}function ow(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${D(e)}`);return e}var sw=aw({order:ga,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:ow(e.minimum),maximum:ow(e.maximum),...t&&{exclusiveMinimum:t},...n&&{exclusiveMaximum:n}}},toJsonSchema:()=>({[t?`exclusiveMinimum`:`minimum`]:e.minimum,[n?`exclusiveMaximum`:`maximum`]:e.maximum}),toCode:()=>({runtime:`Schema.isBetween({ minimum: ${D(e.minimum)}, maximum: ${D(e.maximum)}, exclusiveMinimum: ${D(t)}, exclusiveMaximum: ${D(n)} })`})}}});function cw(e){return rw(e=>globalThis.Number.isSafeInteger(e),{expected:`an integer`,representation:{id:`effect/schema/isInt`,payload:null},toJsonSchema:()=>({type:`integer`}),toCode:()=>({runtime:`Schema.isInt()`}),arbitraryConstraint:{number:`integer`},...e})}var lw=IC.check(cw()),uw=e=>+(e?.includeStack===!0)|(e?.excludeCause===!0?2:0),dw=e=>{switch(e){case 0:return;case 1:return{includeStack:!0};case 2:return{excludeCause:!0};case 3:return{includeStack:!0,excludeCause:!0}}},fw=[];function pw(e){let t=uw(e),n=fw[t];if(n!==void 0)return n;let r=Vw.pipe(X(NC,Ig(dw(t))));return fw[t]=r,r}globalThis.RegExp,globalThis.URL;var mw=J.annotate({expected:`a string that will be decoded as JSON`,contentMediaType:`application/json`});function hw(e,t){return mw.pipe(X(e,Rg(t)))}var gw=hw(NC);globalThis.File,globalThis.FormData,globalThis.URLSearchParams;var _w=J.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),vw=tw(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>nw()(_w,Lg)});function yw(e,t){return q(mC()([e,t],([e,t])=>(n,r,i)=>{if(!sf(n))return V(new mh(r,n,i));switch(n._tag){case`Fail`:return zm(Kb(e)(n.error,i),{onSuccess:ff,onFailure:e=>gh(r,`error`,e,n,i)});case`Die`:return zm(Kb(t)(n.defect,i),{onSuccess:pf,onFailure:e=>gh(r,`defect`,e,n,i)});case`Interrupt`:return B(n)}},{representation:{id:`effect/schema/CauseReason`,payload:null},toCode:({typeParameters:e})=>({runtime:`Schema.CauseReason(${e[0].runtime}, ${e[1].runtime})`,Type:`Cause.Failure<${e[0].Type}, ${e[1].Type}>`,importDeclarations:[`import * as Cause from "effect/Cause"`]}),expected:`Cause.Failure`,toCodec:([e,t])=>nw()(qC([Y({_tag:jC(`Fail`),error:e}),Y({_tag:jC(`Die`),defect:t}),Y({_tag:jC(`Interrupt`),fiberId:XC(iw)})]),Eg({decode:e=>{switch(e._tag){case`Fail`:return ff(e.error);case`Die`:return pf(e.defect);case`Interrupt`:return mf(e.fiberId)}},encode:e=>{switch(e._tag){case`Fail`:return{_tag:`Fail`,error:e.error};case`Die`:return{_tag:`Die`,defect:e.defect};case`Interrupt`:return{_tag:`Interrupt`,fiberId:e.fiberId}}}}))}).ast,{error:e,defect:t})}function bw(e,t){return q(mC()([e,t],([e,t])=>{let n=WC(yw(e,t));return(e,t,r)=>of(e)?zm(Kb(n)(e.reasons,r),{onSuccess:lf,onFailure:n=>gh(t,`failures`,n,e,r)}):V(new mh(t,e,r))},{representation:{id:`effect/schema/Cause`,payload:null},toCode:({typeParameters:e})=>({runtime:`Schema.Cause(${e[0].runtime}, ${e[1].runtime})`,Type:`Cause.Cause<${e[0].Type}, ${e[1].Type}>`,importDeclarations:[`import * as Cause from "effect/Cause"`]}),expected:`Cause`,toCodec:([e,t])=>nw()(WC(yw(e,t)),Eg({decode:lf,encode:({reasons:e})=>e}))}).ast,{error:e,defect:t})}var xw=Tg({decode:(e,t)=>Ea(zh(e),{onNone:()=>V(new hh({expected:`a valid UTC DateTime string`},e,t)),onSome:e=>B(Bh(e))}),encode:e=>B(Hh(e))}),Sw=-864e13,Cw=864e13;function ww(e,t,n){let r=Math.max(t,e?.minimum===void 0?t:e.minimum.epochMilliseconds+ +(e.exclusiveMinimum===!0)),i=Math.min(n,e?.maximum===void 0?n:e.maximum.epochMilliseconds-+(e.exclusiveMaximum===!0));return r<=i?[r,i]:[t,n]}function Tw(e,t){return lw.check(sw({minimum:e,maximum:t}))}var Ew=hC(e=>Fh(e)&&Ih(e),{representation:{id:`effect/schema/DateTimeUtc`,payload:null},toCode:()=>({runtime:`Schema.DateTimeUtc`,Type:`DateTime.Utc`,importDeclarations:[`import * as DateTime from "effect/DateTime"`]}),expected:`DateTime.Utc`,toCodecArbitrary:({constraint:e})=>{let[t,n]=ww(e,Sw,Cw);return ZC()(Tw(t,n),Yh(Rh))},toCodecJson:()=>nw()(J,xw),toFormatter:()=>e=>e.toString()}),Dw=J.annotate({expected:`a string that will be decoded as a DateTime.Utc`}).pipe(X(Ew,xw)),Ow=hC($S,{representation:{id:`effect/http/UrlParams`,payload:null},toCode:()=>({runtime:`Schema.UrlParams`,Type:`UrlParams.UrlParams`,importDeclarations:[`import * as UrlParams from "effect/unstable/http/UrlParams"`]}),expected:`UrlParams`,toEquivalence:()=>iC,toCodec:()=>nw()(WC(UC([J,J])),Eg({decode:tC,encode:e=>e.params}))}).pipe(X(VC(J,qC([J,GC(J)])),Eg({decode:fC,encode:nC}))),kw=globalThis.Symbol.for(`immer-draftable`),Aw={};function jw(e,t,n,r,i){let a=Pw(n,t,r),o=Nw(t),s=class extends e{constructor(...[e,t]){let r=t?.[`~payload`],i=r?.token===Aw?r.value:n.make(e??{},t);super(i,{...t,disableChecks:!0,"~payload":{token:Aw,value:i}})}static[pC]=pC;get[o](){return o}static[kw]=!0;static identifier=t;static fields=n.fields;static get ast(){return a(this).ast}static pipe(){return x(this,arguments)}static rebuild(e){return a(this).rebuild(e)}static make(e,t){return Hb(a(this))(e??{},t)}static makeOption(e,t){return Vb(a(this))(e??{},t)}static makeEffect(e,t){return a(this).makeEffect(e??{},t)}static annotate(e){return this.rebuild(fv(this.ast,e))}static annotateKey(e){return this.rebuild(Sv(this.ast,e))}static check(...e){return this.rebuild(mv(this.ast,e))}static extend(e){return(t,r)=>{let a=Fw(t)?t:Y(t),o={...n.fields,...a.fields},s=F_(o,n.ast.checks,{identifier:e});return jw(this,e,zC(mv(s,a.ast.checks),o),r,i)}}static mapFields(e,t){return n.mapFields(e,t)}};return i!==void 0&&Object.assign(s.prototype,i(t)),s}function Mw(e){return new Sg(Yh(t=>new e(t,{"~payload":{token:Aw,value:t}})),Jh())}function Nw(e){return`~effect/Schema/Class/${e}`}function Pw(e,t,n){let r;return i=>{if(r!==void 0)return r;let a=Nw(t),o=e=>e instanceof i||w(e,a),s=Mw(i);return r=X(q(new t_([e.ast],()=>(e,t,n)=>o(e)?B(e):V(new mh(t,e,n)),{identifier:t,[qm]:([e])=>({isConstructed:o,link:new Xg(e,s)}),toCodec:([e])=>new Xg(e.ast,s),toEquivalence:([e])=>e,toFormatter:([e])=>t=>`${i.identifier}(${e(t)})`,[Km]:V_(e.ast),...n})),s)(e)}}function Fw(e){return DC(e)}var Iw=e=>(t,n)=>jw(zi,e,Fw(t)?t:Y(t),n,e=>({name:e})),Lw=e=>(t,n,r)=>{let i=Fw(n)?n.mapFields(e=>({_tag:$C(t),...e}),{unsafePreserveChecks:!0}):ew(t,n);return Iw(e??t)(i,r)},Rw=Tx,zw=Mx,Bw=Nx,Vw=q(fv(ay,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})})),Hw=(e,t)=>()=>{let n=wC(GC(e),t);return nb((e,t)=>B(H(e,e=>n(e))))},Uw=`~effect/Stream`,Ww={_R:C,_E:C,_A:C},Gw=function(e){this.channel=e};Gw.prototype={[Uw]:Ww,pipe(){return x(this,arguments)}};var Kw=e=>new Gw(e),qw=`~effect/Stream`,Jw=e=>w(e,qw),Yw=Kw,Xw=e=>Yw(lb(U(e,eo))),Zw=(e,t)=>Yw(nb((n,r)=>H(wb(e.channel,r),e=>t(e,r)))),Qw=e=>Yw(sb(()=>e().channel)),$w=e=>Yw(cb(e)),eT=e=>Yw(ub(e)),tT=S(2,(e,t)=>Qw(()=>{let n=0;return Yw(fb(e.channel,to(e=>t(e,n++))))})),nT=S(2,(e,t)=>Yw(mb(e.channel,t))),rT=S(2,(e,t)=>e.channel.pipe(_b(e=>t(e).channel),Yw)),iT=S(2,(e,t)=>Yw(vb(e.channel,t))),aT=S(e=>Jw(e[0]),(e,t)=>Qw(()=>{let n=new TextDecoder(t?.encoding);return tT(e,e=>n.decode(e,{stream:!0}))})),oT=e=>Qw(()=>{let t=new TextEncoder;return tT(e,e=>t.encode(e))}),sT=S(2,(e,t)=>Yw(bb(e.channel,t))),cT=S(2,(e,t)=>Yw(Sb(e.channel,t))),lT=S(2,(e,t)=>Cb(e.channel,t)),uT=S(e=>Jw(e[0]),(e,t,n)=>{let r,i,a=my(!1);return new ReadableStream({start(n){i=Am(_m(lT(e,e=>a.whenOpen(Kp(()=>{a.closeUnsafe();for(let t=0;t<e.length;t++)n.enqueue(e[t]);r(),r=void 0}))),t)),i.addObserver(e=>{e._tag===`Failure`?n.error(_f(e.cause)):n.close()})},pull(){return new Promise(e=>{r=e,a.openUnsafe()})},cancel(){if(i)return Mm(om(dy(i)))}},n?.strategy)}),dT=S(e=>Jw(e[0]),(e,t)=>U(mm(),n=>uT(e,n,t))),fT=`~effect/ErrorReporter/ignore`,pT=S(2,(e,t)=>e===void 0?void 0:t(e)),mT=`~effect/http/HttpBody`,hT=e=>w(e,mT),gT=class{[mT];constructor(){this[mT]=mT}[Gr](){return this.toJSON()}toString(){return D(this,{ignoreToString:!0})}},_T=new class extends gT{_tag=`Empty`;toJSON(){return{_id:`effect/HttpBody`,_tag:`Empty`}}},vT=class extends gT{_tag=`Uint8Array`;contentType;contentLength;text;_body;constructor(e,t,n,r){super(),this._body=e,this.text=r,this.contentType=t,this.contentLength=n}get body(){return this._body??=ST(this.text)}toJSON(){return{_id:`effect/HttpBody`,_tag:`Uint8Array`,body:this.contentType.startsWith(`text/`)||this.contentType.endsWith(`json`)?new TextDecoder().decode(this.body):`Uint8Array(${this.body.length})`,contentType:this.contentType,contentLength:this.contentLength}}},yT=(e,t)=>new vT(e,t??`application/octet-stream`,e.length),bT=new TextEncoder,xT=globalThis.Buffer,ST=xT===void 0?e=>bT.encode(e):e=>xT.from(e,`utf8`),CT=(e,t)=>{if(typeof e!=`string`&&(e=e===void 0?``:String(e)),xT!==void 0)return new vT(void 0,t??`text/plain`,xT.byteLength(e,`utf8`),e);let n=bT.encode(e);return new vT(n,t??`text/plain`,n.length,e)},wT=(e,t)=>CT(JSON.stringify(e),t??`application/json`),TT=(e,t)=>CT(uC(nC(e)),t??`application/x-www-form-urlencoded`),ET=class extends gT{_tag=`FormData`;contentType=void 0;contentLength=void 0;formData;constructor(e){super(),this.formData=e}toJSON(){return{_id:`effect/HttpBody`,_tag:`FormData`,formData:this.formData}}},DT=e=>new ET(e),OT=class extends gT{_tag=`Stream`;stream;contentType;contentLength;constructor(e,t,n){super(),this.stream=e,this.contentType=t,this.contentLength=n}toJSON(){return{_id:`effect/HttpBody`,_tag:`Stream`,contentType:this.contentType,contentLength:this.contentLength}}},kT=(e,t,n)=>new OT(e,t??`application/octet-stream`,n),AT=`~effect/http/HttpClientError`,jT=class extends ec(`HttpClientError`){constructor(e){`cause`in e.reason?super({...e,cause:e.reason.cause}):super(e)}[AT]=AT;get request(){return this.reason.request}get response(){return`response`in this.reason?this.reason.response:void 0}get message(){return this.reason.message}},MT=e=>e.endsWith(`Error`)?e.slice(0,-5):e,NT=(e,t,n)=>t?`${e}: ${t} (${n})`:`${e} error (${n})`,PT=class extends ec(`TransportError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return NT(MT(this._tag),this.description,this.methodAndUrl)}},FT=class extends ec(`InvalidUrlError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return NT(MT(this._tag),this.description,this.methodAndUrl)}},IT=class extends ec(`StatusCodeError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return NT(MT(this._tag),this.description,e)}},LT=class extends ec(`DecodeError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return NT(MT(this._tag),this.description,e)}},RT=class extends ec(`EmptyBodyError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return NT(MT(this._tag),this.description,e)}},zT=e=>e!==`GET`&&e!==`HEAD`&&e!==`OPTIONS`&&e!==`TRACE`,BT=[[`GET`,`get`],[`POST`,`post`],[`PUT`,`put`],[`DELETE`,`del`],[`PATCH`,`patch`],[`HEAD`,`head`],[`OPTIONS`,`options`],[`TRACE`,`trace`],[`QUERY`,`query`]],VT=(e,t)=>t._tag===`Empty`||t._tag===`FormData`?JS(JS(e,`content-type`),`content-length`):(e=t.contentType===void 0?JS(e,`content-type`):GS(e,`content-type`,t.contentType),t.contentLength===void 0?JS(e,`content-length`):GS(e,`content-length`,t.contentLength.toString())),HT=class extends ec(`UrlError`){},UT=(e,t,n)=>Pa({try:()=>{let r=new URL(e,WT());for(let e=0;e<t.params.length;e++){let[n,i]=t.params[e];i!==void 0&&r.searchParams.append(n,i)}return n!==void 0&&(r.hash=n),r},catch:e=>new HT({cause:e})}),WT=()=>{if(`location`in globalThis&&globalThis.location!==void 0&&globalThis.location.origin!==void 0&&globalThis.location.pathname!==void 0)return location.origin+location.pathname},GT=`~effect/http/HttpClientRequest`,KT={[GT]:GT,...qr,toJSON(){return{_id:`HttpClientRequest`,method:this.method,url:this.url,urlParams:this.urlParams,hash:this.hash,headers:Nr(this.headers),body:this.body.toJSON()}},pipe(){return x(this,arguments)}};function qT(e,t,n,r,i,a){let o=Object.create(KT);return o.method=e,o.url=t,o.urlParams=n,o.hash=r,o.headers=i,o.body=a,o}var JT=qT(`GET`,``,oC,Sa(),HS,_T),YT=e=>(t,n)=>XT(JT,{method:e,url:t,...n??void 0}),XT=S(2,(e,t)=>{let n=e;return t.method&&(n=ZT(n,t.method)),t.url&&(n=nE(n,t.url)),t.headers&&(n=$T(n,t.headers)),t.urlParams&&(n=aE(n,t.urlParams)),t.hash&&(n=sE(n,t.hash)),t.body&&(n=cE(n,t.body)),t.accept&&(n=eE(n,t.accept)),t.acceptJson&&(n=tE(n)),n}),ZT=S(2,(e,t)=>qT(t,e.url,e.urlParams,e.hash,e.headers,e.body)),QT=S(3,(e,t,n)=>qT(e.method,e.url,e.urlParams,e.hash,GS(e.headers,t,n),e.body)),$T=S(2,(e,t)=>qT(e.method,e.url,e.urlParams,e.hash,KS(e.headers,t),e.body)),eE=S(2,(e,t)=>QT(e,`Accept`,t)),tE=eE(`application/json`),nE=S(2,(e,t)=>{if(typeof t==`string`)return qT(e.method,t,e.urlParams,e.hash,e.headers,e.body);let n=new URL(t.toString()),r=nC(n.searchParams),i=Oa(n.hash===``?void 0:n.hash.slice(1));return n.search=``,n.hash=``,qT(e.method,n.toString(),r,i,e.headers,e.body)}),rE=S(2,(e,t)=>t===``?e:qT(e.method,iE(t,e.url),e.urlParams,e.hash,e.headers,e.body)),iE=(e,t)=>{let n=e.endsWith(`/`),r=t.startsWith(`/`);return n&&r?e+t.slice(1):!n&&!r?e+`/`+t:e+t},aE=S(2,(e,t)=>qT(e.method,e.url,cC(e.urlParams,t),e.hash,e.headers,e.body)),oE=S(2,(e,t)=>qT(e.method,e.url,lC(e.urlParams,t),e.hash,e.headers,e.body)),sE=S(2,(e,t)=>qT(e.method,e.url,e.urlParams,Ca(t),e.headers,e.body)),cE=S(2,(e,t)=>qT(e.method,e.url,e.urlParams,e.hash,VT(e.headers,t),t)),lE=S(2,(e,t)=>cE(e,DT(t)));function uE(e){let t=UT(e.url,e.urlParams,ka(e.hash));return Ia(t)?Ca(t.success):Sa()}var dE=`~effect/http/HttpIncomingMessage`,fE=N(`effect/http/HttpIncomingMessage/MaxBodySize`,{defaultValue:()=>void 0}),pE=(e,t)=>{let n=e.headers[`content-type`]??``,r;if(n.includes(`application/json`))try{r=Nm(e.json)}catch{}else if(n.includes(`text/`)||n.includes(`urlencoded`))try{r=Nm(e.text)}catch{}let i={...t,headers:Nr(e.headers),remoteAddress:e.remoteAddress};return r!==void 0&&(i.body=r),i},mE=`~effect/http/HttpClientResponse`,hE=(e,t)=>new gE(e,t),gE=class extends Jr{[dE];[mE];request;source;constructor(e,t){super(),this.request=e,this.source=t,this[dE]=dE,this[mE]=mE}toJSON(){return pE(this,{_id:`HttpClientResponse`,request:this.request.toJSON(),status:this.status})}get status(){return this.source.status}get url(){if(this.source.url)return this.source.url.split(`#`)[0];let e=uE(this.request);return wa(e)?``:(e.value.hash=``,e.value.href)}get headers(){return US(this.source.headers)}cachedCookies;get cookies(){return this.cachedCookies?this.cachedCookies:this.cachedCookies=MS(this.source.headers.getSetCookie())}get remoteAddress(){return Sa()}get stream(){return this.source.body?eT({evaluate:()=>this.source.body,onError:e=>new jT({reason:new LT({request:this.request,response:this,cause:e})})}):$w(new jT({reason:new RT({request:this.request,response:this,description:`can not create stream from empty body`})}))}get json(){return H(this.text,e=>Qp({try:()=>e===``?null:JSON.parse(e),catch:e=>new jT({reason:new LT({request:this.request,response:this,cause:e})})}))}textBody;get text(){return this.textBody??=U(this.arrayBuffer,e=>new TextDecoder().decode(e))}get urlParamsBody(){return H(this.text,e=>Qp({try:()=>nC(new URLSearchParams(e)),catch:e=>new jT({reason:new LT({request:this.request,response:this,cause:e})})}))}formDataBody;get formData(){return this.formDataBody??=Wp({try:()=>this.source.formData(),catch:e=>new jT({reason:new LT({request:this.request,response:this,cause:e})})}).pipe(Sm,Nm)}arrayBufferBody;get arrayBuffer(){return this.arrayBufferBody||=Wp({try:()=>this.source.arrayBuffer(),catch:e=>new jT({reason:new LT({request:this.request,response:this,cause:e})})}).pipe(Sm,Nm),this.arrayBufferBody}pipe(){return x(this,arguments)}},_E=e=>WS({b3:`${e.traceId}-${e.spanId}-${e.sampled?`1`:`0`}${Ea(e.parent,{onNone:()=>``,onSome:e=>`-${e.spanId}`})}`,traceparent:`00-${e.traceId}-${e.spanId}-${e.sampled?`01`:`00`}`}),vE=`~effect/http/HttpClient`,yE=M(`effect/HttpClient`),bE=S(2,(e,t)=>xE(n=>t(e.postprocess(n)),e.preprocess)),xE=(e,t)=>{let n=Object.create(SE);return n.preprocess=t,n.postprocess=e,n.execute=function(n){return e(t(n))},n},SE={[vE]:vE,pipe(){return x(this,arguments)},...qr,toJSON(){return{_id:`effect/HttpClient`}},...Object.fromEntries(BT.map(([e,t])=>[t,function(t,n){return this.execute(YT(e)(t,n))}]))},CE=e=>xE(t=>H(t,t=>$p(n=>{let r=jE.get(t),i=r??new AbortController,a=UT(t.url,t.urlParams,ka(t.hash));if(Fa(a))return V(new jT({reason:new FT({request:t,cause:a.failure})}));let o=a.success;if(n.getRef(xc)||n.getRef(TE)(t)){let a=e(t,o,i.signal,n);return r?a:wm(e=>pm(e(a),{onSuccess(e){return AE.register(e,i),B(new ME(e,i))},onFailure(e){return vf(e)&&i.abort(),Yp(e)}}))}return Em(n.getRef(OE)(t),{kind:`client`},a=>{a.attribute(`http.request.method`,t.method),a.attribute(`server.address`,o.origin),o.port!==``&&a.attribute(`server.port`,+o.port),a.attribute(`url.full`,o.toString()),a.attribute(`url.path`,o.pathname),a.attribute(`url.scheme`,o.protocol.slice(0,-1));let s=o.search.slice(1);s!==``&&a.attribute(`url.query`,s);let c=n.getRef(ZS),l=n.getRef(EE);for(let e in t.headers)l(e,`request`)&&a.attribute(`http.request.header.${e}`,XS(e,c)?`<redacted>`:t.headers[e]);return t=n.getRef(DE)?$T(t,_E(a)):t,wm(s=>s(e(t,o,i.signal,n)).pipe(Om(a,{captureStackTrace:!1}),pm({onSuccess:e=>{a.attribute(`http.response.status_code`,e.status);for(let t in e.headers)l(t,`response`)&&a.attribute(`http.response.header.${t}`,XS(t,c)?`<redacted>`:e.headers[t]);return r?B(e):(AE.register(e,i),B(new ME(e,i)))},onFailure(e){return!r&&vf(e)&&i.abort(),Yp(e)}})))})})),B),wE=S(2,(e,t)=>xE(e.postprocess,n=>U(e.preprocess(n),t))),TE=N(`effect/http/HttpClient/TracerDisabledWhen`,{defaultValue:()=>Tn}),EE=N(`effect/http/HttpClient/TracerHeaderFilter`,{defaultValue:()=>wn}),DE=N(`effect/http/HttpClient/TracerPropagationEnabled`,{defaultValue:wn}),OE=N(`effect/http/HttpClient/SpanNameGenerator`,{defaultValue:()=>e=>`http.client ${e.method}`}),kE=e=>ip(yE)(hm(t=>U(e,e=>bE(e,vm(e=>os(t,e)))))),AE=(()=>{if(`FinalizationRegistry`in globalThis&&globalThis.FinalizationRegistry){let e=new FinalizationRegistry(e=>{e.abort()});return{register(t,n){e.register(t,n,t)},unregister(t){e.unregister(t)}}}let e=new Map;return{register(t,n){e.set(t,setTimeout(()=>n.abort(),5e3))},unregister(t){let n=e.get(t);n!==void 0&&(clearTimeout(n),e.delete(t))}}})(),jE=new WeakMap,ME=class{original;controller;constructor(e,t){this.original=e,this.controller=t}[mE]=mE;[dE]=dE;applyInterrupt(e){return Gp(()=>(AE.unregister(this.original),Cm(e,()=>Kp(()=>{this.controller.abort()}))))}get request(){return this.original.request}get url(){return this.original.url}get status(){return this.original.status}get headers(){return this.original.headers}get cookies(){return this.original.cookies}get remoteAddress(){return this.original.remoteAddress}get formData(){return this.applyInterrupt(this.original.formData)}get text(){return this.applyInterrupt(this.original.text)}get json(){return this.applyInterrupt(this.original.json)}get urlParamsBody(){return this.applyInterrupt(this.original.urlParamsBody)}get arrayBuffer(){return this.applyInterrupt(this.original.arrayBuffer)}get stream(){return Qw(()=>(AE.unregister(this.original),sT(this.original.stream,Kp(()=>{this.controller.abort()}))))}toJSON(){return this.original.toJSON()}[Gr](){return this.original[Gr]()}pipe(){return x(this,arguments)}},NE=N(`effect/http/FetchHttpClient/Fetch`,{defaultValue:()=>globalThis.fetch}),PE=class extends M()(`effect/http/FetchHttpClient/RequestInit`){},FE=kE(B(CE((e,t,n,r)=>{let i=r.getRef(NE),a=Qo(r.context,PE)??{},o=a.headers?qS(US(a.headers),e.headers):e.headers;o[`content-length`]&&(o=JS(o,`content-length`));let s=r=>U(Wp({try:()=>i(t,{...a,method:e.method,headers:o,body:r,duplex:typeof ReadableStream<`u`&&r instanceof ReadableStream?`half`:void 0,signal:n}),catch:t=>new jT({reason:new PT({request:e,cause:t})})}),t=>hE(e,t));switch(e.body._tag){case`Raw`:case`Uint8Array`:return s(e.body.body);case`FormData`:return s(e.body.formData);case`Stream`:return H(dT(e.body.stream),s)}return s(void 0)}))),IE=Object.getPrototypeOf(HS),LE=()=>Object.create(IE),RE=`~effect/http/HttpServerResponse`,zE=e=>w(e,RE),BE=e=>XE({status:e?.status??204,statusText:e?.statusText,headers:e?.headers?US(e.headers):void 0,cookies:e?.cookies}),VE=(e,t)=>{let n=t?.headers?US(t.headers):HS;return XE({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies??PS,body:yT(e,HE(t,n))})},HE=(e,t)=>{if(e?.contentType)return e.contentType;if(e?.headers)return t[`content-type`]},UE=(e,t)=>{let n=t?.headers?US(t.headers):HS;return XE({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies??PS,body:CT(e,HE(t,n))})},WE=(e,t)=>{let n=t?.headers?US(t.headers):HS;return XE({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies,body:wT(e,HE(t,n))})},GE=(e,t)=>{let n=t?.headers?US(t.headers):HS;return XE({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies,body:CT(uC(nC(e)),HE(t,n)??`application/x-www-form-urlencoded`)})},KE=(e,t)=>{let n=t?.headers?US(t.headers):HS;return XE({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies,body:kT(e,HE(t,n),t?.contentLength)})},qE=S(3,(e,t,n)=>XE(e,GS(e.headers,t,n))),JE=S(2,(e,t)=>XE(e,KS(e.headers,t))),YE={...ci,[RE]:RE,[fT]:!0,toJSON(){return{_id:`HttpServerResponse`,status:this.status,statusText:this.statusText,headers:Nr(this.headers),cookies:this.cookies.toJSON(),body:this.body.toJSON()}}},XE=(e,t)=>{let n=Object.create(YE);if(n.status=e.status,n.statusText=e.statusText,n.cookies=e.cookies??PS,n.body=e.body??_T,n.body._tag!==`Empty`&&(n.body.contentType||n.body.contentLength!==void 0)){let r=t!==void 0,i=r?t:e.headers===void 0||e.headers===HS?LE():WS({...e.headers});n.body.contentType&&(!r||i[`content-type`]===void 0)&&(i[`content-type`]=n.body.contentType),n.body.contentLength!==void 0&&(!r||i[`content-length`]===void 0)&&(i[`content-length`]=n.body.contentLength.toString()),n.headers=i}else n.headers=t??e.headers??HS;return n},ZE=`~effect/http/HttpServerRespondable`,QE=new Uint8Array(256);for(let e of"!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")QE[e.charCodeAt(0)]=1;var $E=new Uint8Array(256);$E[9]=1;for(let e=32;e<=126;e++)$E[e]=1;for(let e=128;e<=255;e++)$E[e]=1;var eD=e=>{let t=new Map;return e.maxParts!==void 0&&t.set(tD.key,e.maxParts),e.maxFieldSize!==void 0&&t.set(nD.key,vg(e.maxFieldSize)),e.maxFileSize!==void 0&&t.set(rD.key,vg(e.maxFileSize)),e.maxTotalSize!==void 0&&t.set(fE.key,vg(e.maxTotalSize)),e.fieldMimeTypes!==void 0&&t.set(iD.key,e.fieldMimeTypes),Vo(t)},tD=N(`effect/http/Multipart/MaxParts`,{defaultValue:()=>void 0}),nD=N(`effect/http/Multipart/MaxFieldSize`,{defaultValue:Cn(yg(10))}),rD=N(`effect/http/Multipart/MaxFileSize`,{defaultValue:()=>void 0}),iD=N(`effect/http/Multipart/FieldMimeTypes`,{defaultValue:Cn([`application/json`])}),aD=M(`effect/http/HttpServerRequest`),oD=class extends M()(`effect/http/ParsedSearchParams`){},sD=(e,t)=>{let n=CC(e);return H(aD,e=>n(e.cookies,t))},cD=(e,t)=>{let n=CC(e);return H(aD,e=>n(e.headers,t))},lD=(e,t)=>{let n=CC(e);return H(oD,e=>n(e,t))},uD=new WeakSet,dD=e=>$p(t=>{let n=es(t.context,aD);return uD.add(n.source),e}),fD=M(`effect/http/HttpRouter`),pD=class extends M()(`effect/http/HttpRouter/RouteContext`){},mD=e=>sp(H(fD,e)),hD=(e,t,n,r)=>mD(i=>i.add(e,t,n,r)),gD=`~effect/http/HttpRouter/Route`,_D=e=>({...e,uninterruptible:e.uninterruptible??!1,prefix:typeof e.prefix==`string`?Ca(e.prefix):e.prefix??Sa(),[gD]:gD}),vD=(e,t,n,r)=>_D({...r,method:e,path:t,handler:zE(n)?B(n):Hp(n)?n:H(aD,n),uninterruptible:r?.uninterruptible??!1}),yD=e=>e.endsWith(`/`)?e.slice(0,-1):e,bD=S(2,(e,t)=>(t=yD(t),e===`*`?`${t}/*`:e===`/`?t:t+e)),xD=`~effect/http/HttpRouter/Middleware`,SD=function(){return arguments.length===0?CD:CD(arguments[0],arguments[1])},CD=(e,t)=>t?.global?sp(Jp(function*(){let t=yield*fD,n=Hp(e)?yield*e:e;yield*t.addGlobalMiddleware(n)})):new ED(Hp(e)?op(U(e,e=>Vo(new Map([[TD,e]])))):np(Vo(new Map([[TD,e]])))),wD=0,TD=`effect/http/HttpRouter/MiddlewareFn`,ED=class e{[xD]={};layerFn;dependencies;constructor(e,t){this.layerFn=e,this.dependencies=t;let n=`effect/http/HttpRouter/Middleware-${++wD}`;this.layer=op(Jp({self:this},function*(){let e=yield*mm(),t=[$o(e,TD)];if(this.dependencies){let n=yield*Qf,r=ts(e,Pf),i=yield*$f(this.dependencies,n,r);t.push(...OD(i))}return Vo(new Map([[n,t]]))})).pipe(pp(this.layerFn))}layer;combine(t){return new e(this.layerFn,this.dependencies?mp(this.dependencies,t.layer):t.layer)}},DD=new WeakMap,OD=e=>{let t=DD.get(e);if(t)return t;let n=$a(),r=0;for(let[t,i]of e.mapUnsafe)t.startsWith(`effect/http/HttpRouter/Middleware-`)&&(n.push(i),i.length>r&&(r=i.length));if(n.length===0)t=[];else{let e=new Set;for(let t=r-1;t>=0;t--)for(let r of n)t<r.length&&e.add(r[t]);t=qa(e).reverse()}return DD.set(e,t),t};SD(dD).layer;var kD={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,OK:200,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511},AD=e=>kD[e],jD=`~effect/encoding/Sse/SseError`,MD=class extends ec(`EventTooLarge`){get message(){return`Pending SSE event exceeded the maximum size of ${this.maxEventSize}`}},ND=class extends ec(`SseError`){[jD]=jD;get message(){return this.reason.message}},PD=10485760,FD=e=>nb((t,n)=>Kp(()=>{let n=[],r,i=LD(e=>{e._tag===`Retry`?r=e:n.push(e)},e),a=H(t,e=>{for(let t=0;t<e.length;t++){let n=i.feed(e[t]);if(n!==void 0)return V(n)}return qp});return Gp(function e(){if(Za(n)){let e=n;return n=[],B(e)}return r?V(r):H(a,e)})})),ID=(e,t,n)=>vb(FD(t),Hw(zD.pipe(X(e,BD)),n)());function LD(e,t){let n=t?.maxEventSize??PD,r,i,a,o,s,c,l,u;return d(),{feed:f,reset:d};function d(){r=!0,i=``,a=0,o=-1,s=!1,c=void 0,l=void 0,u=``}function f(e){i=i?i+e:e,r&&i.startsWith(RD)&&(i=i.slice(RD.length)),r=!1;let t=i.length,c=0;for(;c<t;){s&&=(i[c]===`
10
+ `&&++c,!1);let e=-1,n=o,r;for(let o=c+a;e<0&&o<t;++o)r=i[o],r===`:`&&n<0?n=o-c:r===`\r`?(s=!0,e=o-c):r===`
11
+ `&&(e=o-c);if(e<0){a=t-c,o=n;break}a=0,o=-1,p(i,c,n,e),c+=e+1}if(c===t?i=``:c>0&&(i=i.slice(c)),i.length+u.length>n){let e=new ND({reason:new MD({maxEventSize:n})});return d(),e}}function p(t,n,r,i){if(i===0){u.length>0&&(e({_tag:`Event`,id:c,event:l||`message`,data:u.slice(0,-1)}),u=``),l=void 0;return}let a=r<0,o=t.slice(n,n+(a?i:r)),s=0;s=a?i:t[n+r+1]===` `?r+2:r+1;let d=n+s,f=i-s,p=t.slice(d,d+f).toString();o===`data`?u+=p?`${p}\n`:`
12
+ `:o===`event`?l=p:o===`id`&&!p.includes(`\0`)?c=p:o===`retry`&&/^\d+$/.test(p)&&e(new HD({duration:js(parseInt(p,10)),lastEventId:c}))}}var RD=``,zD=Y({_tag:$C(`Event`),id:XC(J),event:J,data:J}),BD=Eg({decode:e=>e.id===void 0?{event:e.event,data:e.data}:{id:e.id,event:e.event,data:e.data},encode:e=>({_tag:`Event`,id:e.id,event:e.event??`message`,data:e.data})}),VD=`~effect/encoding/Sse/Retry`,HD=class e extends $s(`Retry`){[VD]=VD;static is(e){return w(e,VD)}static filter(t){return e.is(t)?Ma(t):Na(t)}},UD={write(e){switch(e._tag){case`Event`:{let t=``;return e.id!==void 0&&(t+=`id: ${e.id}\n`),e.event!==`message`&&(t+=`event: ${e.event}\n`),t+=`data: ${e.data.replace(/\n/g,`
13
+ data: `)}\n`,t+`
14
+ `}case`Retry`:return`retry: ${Ls(e.duration)}\n\n`}}},WD=`~effect/httpapi/HttpApiSchema/Stream`;function GD(e){let t=typeof e==`string`?AD(e):e;return e=>e.annotate({httpApiStatus:t})}var KD=(e=>RC.pipe(GD(e)))(204),qD=e=>DC(e)&&w(e,WD),JD=e=>qD(e)&&e._tag===`StreamSse`,YD=e=>qD(e)&&e._tag===`StreamUint8Array`,XD=`~effect/httpapi/HttpApiSchema/WithHeaders`,ZD=`~effect/httpapi/HttpApiSchema/WithHeadersValue`,QD=e=>w(e,ZD),$D=e=>({[ZD]:ZD,body:e.body,headers:e.headers}),Z=e=>DC(e)&&w(e,`~effect/httpapi/HttpApiSchema/WithHeaders`);function eO(e,t,n){return q(e.ast,{[XD]:XD,schema:t,headers:n})}function tO(e,t){return e.annotate({"~httpApiEncoding":{_tag:t._tag,contentType:t.contentType??nO(t._tag)}})}function nO(e){switch(e){case`Multipart`:return`multipart/form-data`;case`Json`:return`application/json`;case`FormUrlEncoded`:return`application/x-www-form-urlencoded`;case`Uint8Array`:return`application/octet-stream`;case`Text`:return`text/plain`}}function rO(e){return t=>tO(t,{_tag:`FormUrlEncoded`,...e})}var iO=e=>{if(Hg(e)||Hg(Fv(e)))return!0;let t=e.encoding?.[0].to;return t!==void 0&&Hg(t)},aO=Qv(`~httpApiEncoding`),oO=Qv(`~httpApiWithHeaders`),sO=Qv(`httpApiStatus`),cO={_tag:`Json`,contentType:`application/json`},lO={_tag:`FormUrlEncoded`,contentType:`application/x-www-form-urlencoded`};function uO(e){return aO(e)??cO}function dO(e,t){return aO(e)||(zT(t)?cO:lO)}function fO(e){let t=uO(e);if(t._tag===`Multipart`)throw Error(`Multipart is not supported in response`);return t}function pO(e){return sO(e)??200}function mO(e){return Z(e)?sO(e.ast)??pO(e.schema.ast):pO(e.ast)}function hO(e){return Z(e)&&aO(e.ast)===void 0?fO(e.schema.ast):fO(e.ast)}function gO(e){return sO(e)??500}function _O(e){return Z(e)?sO(e.ast)??gO(e.schema.ast):gO(e.ast)}function vO(e){let t=e.toLowerCase().trim(),n=t.indexOf(`;`);return n===-1?t:t.slice(0,n).trim()}var yO=`~effect/httpapi/HttpApiEndpoint`;function bO(e){let t=[];for(let{schemas:n}of e.payload.values())t.push(...n);return t}function xO(e){let t=Array.from(e.success);return Za(t)?t:[KD]}function SO(e){let t=new Set(e.error),n=e.disableCodecs?C:jO;for(let r of e.middlewares){let e=r;for(let r of e.error)t.add(n(r))}return Array.from(t)}var CO={[yO]:yO,pipe(){return x(this,arguments)},prefix(e){return TO({...wO(this),path:bD(this.path,e)})},middleware(e){return TO({...wO(this),middlewares:new Set([...this.middlewares,e])})},annotate(e,t){return TO({...wO(this),annotations:Yo(this.annotations,e,t)})},annotateMerge(e){return TO({...wO(this),annotations:os(this.annotations,e)})}},wO=e=>({identifier:e.identifier,path:e.path,method:e.method,params:e.params,query:e.query,headers:e.headers,payload:e.payload,success:e.success,error:e.error,annotations:e.annotations,middlewares:e.middlewares,disableCodecs:e.disableCodecs});function TO(e){function t(){}return Object.setPrototypeOf(t,CO),Object.assign(t,e)}var EO=e=>(t,n,r)=>{let i=r?.disableCodecs??!1,a=i?C:zw;return TO({identifier:t,path:n,method:e,params:DO(r?.params,a),query:DO(r?.query,a),headers:DO(r?.headers,a),payload:OO(r?.payload,e,i),success:AO(r?.success,e,i),error:MO(r?.error,i),annotations:Ko(),middlewares:new Set,disableCodecs:i})};function DO(e,t){if(e!==void 0)return DC(e)?t(e):t(Y(e))}function OO(e,t,n){let r=new Map;if(e===void 0)return r;let i=Array.isArray(e)?e:DC(e)?[e]:[Y(e).pipe(rO())],a=n?C:HO;for(let e of i){let n=dO(e.ast,t),i=vO(n.contentType),o=r.get(i);if(o){if(o.encoding._tag!==n._tag)throw Error(`Multiple payload encodings for content-type: ${n.contentType}`);if(o.encoding._tag===`Multipart`)throw Error(`Multiple multipart payloads for content-type: ${n.contentType}`);o.schemas.push(a(e,t))}else r.set(i,{encoding:n,schemas:[a(e,t)]})}return r}var kO=`effect/httpapi/stream/failure`;function AO(e,t,n){if(e===void 0)return new Set;let r=Ja(e);return NO(r,t),new Set(n?r:r.map(jO))}var jO=On(e=>qD(e)?e:Z(e)?eO(e,qD(e.schema)?e.schema:VO(e.schema,hO(e)),zw(e.headers)):BO(e));function MO(e,t){if(e===void 0)return new Set;let n=Ja(e);for(let e of n)if(qD(Z(e)?e.schema:e))throw Error(`Streaming schemas are not supported in error responses`);return FO(n,_O),new Set(t?n:n.map(jO))}function NO(e,t){let n=!1,r=new Map;for(let i of e){let e=Z(i)?i.schema:i,a=mO(i);if(qD(e)){if(IO(e,t),n)throw Error(`Multiple streaming success responses are not supported`);n=!0;let i=PO(r,a);if(i.noContent)throw Error(`Cannot combine no-content and streaming success responses for status: ${a}`);if(i.bufferedContentTypes.has(vO(e.contentType)))throw Error(`Cannot combine buffered and streaming success responses for status ${a} and content-type: ${e.contentType}`);r.set(a,{...i,stream:e})}else{let t=PO(r,a),n=iO(e.ast);if(t.stream!==void 0){if(n)throw Error(`Cannot combine no-content and streaming success responses for status: ${a}`);let e=hO(i);if(vO(e.contentType)===vO(t.stream.contentType))throw Error(`Cannot combine buffered and streaming success responses for status ${a} and content-type: ${e.contentType}`)}n||t.bufferedContentTypes.add(vO(hO(i).contentType)),t.noContent=t.noContent||n}}FO(e,mO)}function PO(e,t){let n=e.get(t);return n===void 0&&(n={bufferedContentTypes:new Set,noContent:!1},e.set(t,n)),n}function FO(e,t){let n=new Map;for(let r of e){let e=t(r),i=oO(r.ast),a=Z(r)?r.schema:i?.body??r,o=iO(a.ast)?``:vO(qD(a)?a.contentType:hO(r).contentType),s=n.get(e);s===void 0&&(s={headerContentType:void 0,plainContentTypes:new Set},n.set(e,s));let c=()=>Error(`Cannot combine a response with headers with another response for status ${e} and content-type: ${o||`<no content>`}`);if(Z(r)||i!==void 0){if(s.headerContentType!==void 0)throw Error(`Cannot declare multiple responses with headers for status ${e}`);if(s.plainContentTypes.has(o))throw c();s.headerContentType=o}else{if(s.headerContentType===o)throw c();s.plainContentTypes.add(o)}}}function IO(e,t){if(t===`HEAD`)throw Error(`HEAD endpoints cannot declare streaming success responses`);if(JD(e)&&LO(e.events.ast))throw Error(`SSE event name is reserved: ${kO}`)}function LO(e){return RO(Fv(e),new Set)}function RO(e,t){if(t.has(e))return!1;if(t.add(e),Jg(e))return e.types.some(e=>RO(e,t));if(Yg(e))return RO(e.thunk(),t);if(!qg(e))return!1;let n=e.propertySignatures.find(e=>e.name===`event`);return n!==void 0&&zO(n.type,t)}function zO(e,t){if(t.has(e))return!1;t.add(e);let n=Fv(e);return n===e?Wg(e)?e.literal===kO:Jg(e)?e.types.some(e=>zO(e,t)):Yg(e)?zO(e.thunk(),t):!1:zO(n,t)}function BO(e){let t=fO(e.ast),n=oO(e.ast);if(n===void 0)return VO(e,t);let r=AC(n.headers);return Y({body:VO(AC(n.body),t),headers:r}).pipe(X(e)).annotate({"~httpApiWithHeaders":{...n,headersCodec:zw(r)}})}function VO(e,t){switch(t._tag){case`Json`:return Rw(e);case`FormUrlEncoded`:return zw(e);case`Text`:case`Uint8Array`:return e}}function HO(e,t){switch(dO(e.ast,t)._tag){case`Json`:return Rw(e);case`FormUrlEncoded`:return zw(e);case`Text`:case`Uint8Array`:case`Multipart`:return e}}var UO=EO(`POST`),WO=`~effect/httpapi/HttpApi`,GO={[WO]:WO,pipe(){return x(this,arguments)},add(...e){let t={...this.groups};for(let n of e)E(t,n.identifier,n);return qO({...KO(this),groups:t})},addHttpApi(e){let t={...this.groups};for(let n of Object.keys(e.groups)){let r=e.groups[n];E(t,n,r.annotateMerge(os(e.annotations,r.annotations)))}return qO({...KO(this),groups:t})},prefix(e){return qO({...KO(this),groups:Ha(this.groups,t=>t.prefix(e))})},middleware(e){return qO({...KO(this),groups:Ha(this.groups,t=>t.middleware(e))})},annotate(e,t){return qO({...KO(this),annotations:Yo(this.annotations,e,t)})},annotateMerge(e){return qO({...KO(this),annotations:os(this.annotations,e)})}},KO=e=>({identifier:e.identifier,groups:e.groups,annotations:e.annotations}),qO=e=>{function t(){}return Object.setPrototypeOf(t,GO),Object.assign(t,e)},JO=e=>qO({identifier:e,groups:{},annotations:Ko()}),YO=(e,t)=>{let n=Object.values(e.groups);for(let r of n){let n=os(e.annotations,r.annotations);t.onGroup({group:r,mergedAnnotations:n});let i=Object.values(r.endpoints);for(let e of i)(!t.predicate||t.predicate({endpoint:e,group:r}))&&t.onEndpoint({group:r,endpoint:e,middleware:e.middlewares,mergedAnnotations:os(n,e.annotations),successes:XO(xO(e),mO),errors:XO(SO(e),_O)})}},XO=(e,t)=>{let n=new Map;return e.forEach(r),n;function r(e){if(qD(Z(e)?e.schema:e))return;let r=t(e),i=n.get(r);i===void 0?n.set(r,[e]):i.push(e)}},ZO=class extends M()(`effect/httpapi/HttpApi/AdditionalSchemas`){},QO=class extends M()(`effect/httpapi/HttpApi/ParseOptions`){},$O=BE({status:400}),ek=`~effect/httpapi/HttpApiError/HttpApiSchemaError`,tk=class e extends $s(`HttpApiSchemaError`){[ek]=ek;static is(e){return w(e,ek)}static wrap(t,n){return Rm(n,n=>new e({kind:t,cause:n}))}name=`HttpApiSchemaError`;message=this.kind;[ZE](){return B($O)}},nk=`~effect/httpapi/HttpApiMiddleware`,rk=`~effect/httpapi/HttpApiMiddleware/Security`,ik=e=>w(e,rk),ak=()=>(e,t)=>{let n=Xr(),r;n!==0&&(Zr(2),r=new globalThis.Error,Zr(n));class i extends M()(e){}let a=i;if(Object.defineProperty(i,"stack",{get(){return r?.stack}}),a[nk]=nk,a.error=ok(t?.error),a.requiredForClient=t?.requiredForClient??!1,t?.security!==void 0){if(Object.keys(t.security).length===0)throw Error(`HttpApiMiddleware.Service: security object must not be empty`);a[rk]=rk,a.security=t.security}return a};function ok(e){return e===void 0?new Set:new Set(Array.isArray(e)?e:[e])}var sk=(e,t)=>tp(e,(e,n)=>sm(e,e=>tk.is(e)?t(e,n):V(e))),ck=new Set;function lk(e){if(e===void 0)return ck;let t=dv(e.ast);return qg(t)&&t.indexSignatures.length===0?new Set(t.propertySignatures.map(e=>String(e.name))):void 0}function uk(e,t){if(t===void 0||!e.includes(`:`))return e;let n=lk(t);if(n===void 0)return e;let r=``,i=0,a=-1;for(let t=0;t<e.length;t++){let o=e[t];if(i>0||t===a){r+=o,o===`\\`?r+=e[++t]??``:o===`(`?i++:o===`)`&&i--;continue}if(o!==`:`){r+=o;continue}if(e[t+1]===`:`){r+=`::`,t++;continue}let s=/^:(\w+)/.exec(e.slice(t));if(s!==null&&n.has(s[1])){r+=s[0],t+=s[0].length-1;let n=e[t+1];n===`(`?a=t+1:n!==void 0&&!`/.-?`.includes(n)&&(r+=`(.*?)`)}else r+=`::`}return r}var dk=class extends M()(`effect/httpapi/OpenApi/Identifier`){},fk=class extends M()(`effect/httpapi/OpenApi/Title`){},pk=class extends M()(`effect/httpapi/OpenApi/Version`){},mk=class extends M()(`effect/httpapi/OpenApi/Description`){},hk=class extends M()(`effect/httpapi/OpenApi/License`){},gk=class extends M()(`effect/httpapi/OpenApi/ExternalDocs`){},_k=class extends M()(`effect/httpapi/OpenApi/Servers`){},vk=class extends M()(`effect/httpapi/OpenApi/Format`){},yk=class extends M()(`effect/httpapi/OpenApi/Summary`){},bk=class extends M()(`effect/httpapi/OpenApi/Deprecated`){},xk=class extends M()(`effect/httpapi/OpenApi/Override`){},Sk=N(`effect/httpapi/OpenApi/Exclude`,{defaultValue:Tn}),Ck=class extends M()(`effect/httpapi/OpenApi/Transform`){},wk={},Tk=new WeakMap,Ek=e=>{if(Array.isArray(e))return e.map(Ek);if(typeof e==`object`&&e&&!Object.isFrozen(e)){let t={};for(let n of Object.keys(e))E(t,n,Ek(e[n]));return t}return e};function Q(e,t,n){let r=as(e,t);Ta(r)&&n(r.value)}function Dk(e,t){let n=t??wk,r=Tk.get(n);r===void 0&&(r=new WeakMap,Tk.set(n,r));let i=r.get(e);if(i!==void 0)return Ek(i);let a=Ok(e,n);return r.set(e,Ek(a)),a}function Ok(e,t){let n={openapi:`3.1.0`,info:{title:`Api`,version:`0.0.1`},paths:{},components:{schemas:{},securitySchemes:{}},security:[],tags:[]},r=[],i=new Set,a=new Set,o=[];Q(e.annotations,fk,e=>{n.info.title=e}),Q(e.annotations,pk,e=>{n.info.version=e}),Q(e.annotations,mk,e=>{n.info.description=e}),Q(e.annotations,hk,e=>{n.info.license=e}),Q(e.annotations,yk,e=>{n.info.summary=e}),Q(e.annotations,_k,e=>{n.servers=[...e]}),YO(e,{onGroup({group:e}){if(ts(e.annotations,Sk))return;let t={name:Zo(e.annotations,fk,()=>e.identifier)};Q(e.annotations,mk,e=>{t.description=e}),Q(e.annotations,gk,e=>{t.externalDocs=e}),Q(e.annotations,xk,e=>{for(let[n,r]of Object.entries(e))E(t,n,r)}),Q(e.annotations,Ck,e=>{t=e(t)}),n.tags.push(t)},onEndpoint({endpoint:e,group:t,mergedAnnotations:s,middleware:c}){if(ts(s,Sk))return;let l={tags:[Zo(t.annotations,fk,()=>t.identifier)],operationId:Zo(e.annotations,dk,()=>t.topLevel?e.identifier:`${t.identifier}.${e.identifier}`),parameters:[],security:[],responses:{}},u=lk(e.params),d=e.path.replace(/:(\w+)\??/g,(e,t)=>u===void 0||u.has(t)?`{${t}}`:e),f=e.method.toLowerCase(),p=f===`query`,m=p?`QUERY`:f,h=p?[`paths`,d,`x-oai-additionalOperations`,m]:[`paths`,d,m];function g(e,t){for(let[n,{content:i,descriptions:a,headers:o,streamContent:s}]of e){let e=a.size>0?Array.from(a).join(` | `):t();E(l.responses,n,{description:e});for(let e of o){let t=dv(e.ast);if(qg(t))for(let e of t.propertySignatures){let t=String(e.name).toLowerCase();t!==`content-type`&&(l.responses[n].headers??={},E(l.responses[n].headers,t,{schema:{},required:!Av(e.type)}),r.push({_tag:`parameter`,ast:e.type,path:[...h,`responses`,String(n),`headers`,t,`schema`]}))}}i!==void 0&&i.forEach((e,t)=>{e.forEach((e,i)=>{let a=Array.from(e,I_),o=a.length===1?a[0]:new J_(a);r.push({_tag:`schema`,ast:Pk(o,t),path:[...h,`responses`,String(n),`content`,i,`schema`]}),l.responses[n].content??={},E(l.responses[n].content,i,{schema:{}})})}),s!==void 0&&s.forEach((e,t)=>{l.responses[n].content??={},JD(e)?(r.push({_tag:`schema`,ast:I_(e.events),path:[...h,`responses`,String(n),`content`,t,`schema`]}),r.push({_tag:`schema`,ast:I_(Rw(bw(e.error,pw()))),path:[...h,`responses`,String(n),`content`,t,`x-effect-stream`,`causeSchema`]}),r.push({_tag:`schema`,ast:I_(e.error),path:[...h,`responses`,String(n),`content`,t,`x-effect-stream`,`errorSchema`]}),E(l.responses[n].content,t,{schema:{},"x-effect-stream":{encoding:`sse`,causeSchema:{},errorSchema:{},failureEvent:kk}})):E(l.responses[n].content,t,{schema:{type:`string`,format:`binary`},"x-effect-stream":{encoding:`uint8array`}})})}}function _(e,t){if(e){let n=dv(e.ast);if(qg(n))for(let e of n.propertySignatures)l.parameters.push({name:String(e.name),in:t,schema:{},required:t===`path`||!Av(e.type)}),r.push({_tag:`parameter`,ast:e.type,path:[...h,`parameters`,String(l.parameters.length-1),`schema`]})}}Q(e.annotations,mk,e=>{l.description=e}),Q(e.annotations,yk,e=>{l.summary=e}),Q(e.annotations,bk,e=>{l.deprecated=e}),Q(e.annotations,gk,e=>{l.externalDocs=e}),c.forEach(e=>{if(ik(e))for(let[t,n]of Object.entries(e.security))ee(t,n),l.security.push({[t]:[]})});function ee(e,t){let r=Ik(t);if(!Object.hasOwn(n.components.securitySchemes,e)){E(n.components.securitySchemes,e,r);return}if(!cr(Lk(n.components.securitySchemes[e]),Lk(r)))throw new globalThis.Error(`Conflicting OpenAPI security scheme: ${e}`)}let v=zT(e.method);if(v){let t=new Map;for(let n of bO(e)){if(iO(n.ast))continue;let r=dO(n.ast,e.method),i=t.get(r.contentType);i===void 0?t.set(r.contentType,{encoding:r,schemas:[n]}):i.schemas.push(n)}if(t.size>0){let e={};for(let[n,{encoding:i,schemas:a}]of t){let t=a.map(I_),o=t.length===1?t[0]:new J_(t);r.push({_tag:`schema`,ast:Pk(o,i._tag),path:[...h,`requestBody`,`content`,n,`schema`]}),E(e,n,{schema:{}})}l.requestBody={content:e,required:!0}}}if(_(e.params,`path`),!v&&e.payload.size===1){let t=e.payload.values().next().value;_(t.schemas[0],`query`)}_(e.headers,`header`),_(e.query,`query`),g(Ak(e),()=>`Success`),g(jk(SO(e),_O,Mk),()=>`Error`);let te=`${f} ${d.replace(/\{[^}]+\}/g,`{}`)}`;if(i.has(te))throw new globalThis.Error(`Duplicate OpenAPI operation for ${e.method} ${d}`);i.add(te),Object.hasOwn(n.paths,d)||E(n.paths,d,{});let ne=()=>{let e=n.paths[d];return p?e[`x-oai-additionalOperations`]??={}:e};ne()[m]=l,o.push(()=>{let t=ne(),n=t[m];Q(e.annotations,xk,e=>{for(let[t,r]of Object.entries(e))E(n,t,r)}),Q(e.annotations,Ck,e=>{n=e(n)});let r=n.operationId;if(r!==void 0){if(a.has(r))throw new globalThis.Error(`Duplicate OpenAPI operationId: ${r}`);a.add(r)}t[m]=n})}}),Q(e.annotations,ZO,e=>{e.forEach(e=>{let t=$v(e.ast);if(t!==void 0){if(Object.hasOwn(n.components.schemas,t))throw new globalThis.Error(`Duplicate component schema identifier: ${t}`);E(n.components.schemas,t,{}),r.push({_tag:`schema`,ast:e.ast,path:[`components`,`schemas`,t]})}})});function s(e){return`/`+e.map(sx).join(`/`)}if(Za(r)){let e=mx(sS(uS(to(r,e=>Ex(e.ast)),t),{onExcessProperty:`error`})),i=r.map((t,n)=>({op:`replace`,path:s(t.path),value:e.schemas[n]}));Object.entries(e.definitions).forEach(([e,t])=>{i.push({op:`add`,path:s([`components`,`schemas`,e]),value:t})}),n=dS(i,n)}for(let e of o)e();return Object.keys(n.components.schemas).forEach(e=>{if(!hx.test(e))throw new globalThis.Error(`Invalid component schema key: ${e}`)}),Q(e.annotations,xk,e=>{for(let[t,r]of Object.entries(e))E(n,t,r)}),Q(e.annotations,Ck,e=>{n=e(n)}),n}var kk=`effect/httpapi/stream/failure`;function Ak(e){return jk(xO(e),mO,Mk)}function jk(e,t,n){let r=new Map;return e.forEach(i),r;function i(e){let i=oO(e.ast),c=Z(e)?e.schema:i?.body??e,l=Z(e)?e.headers:i?.headersCodec,u=t(e),d=c.ast;qD(c)?s(c,u):iO(d)?a(u,n(e.ast)??n(d)??`<No Content>`):o(c,u,hO(e),n(e.ast)??n(d)),l!==void 0&&r.get(u).headers.push(l)}function a(e,t){let n=r.get(e);n===void 0?r.set(e,{descriptions:new Set([t]),content:void 0,headers:[],streamContent:void 0}):t!==void 0&&n.descriptions.add(t)}function o(e,t,n,i){let a=r.get(t),{_tag:o,contentType:s}=n;if(a===void 0)r.set(t,{descriptions:new Set(i===void 0?[]:[i]),content:new Map([[o,new Map([[s,new Set([e])]])]]),headers:[],streamContent:void 0});else if(i!==void 0&&a.descriptions.add(i),a.content===void 0)a.content=new Map([[o,new Map([[s,new Set([e])]])]]);else{let t=a.content.get(o);if(t===void 0)a.content.set(o,new Map([[s,new Set([e])]]));else{let n=t.get(s);n===void 0?t.set(s,new Set([e])):n.add(e)}}}function s(e,t){let n=r.get(t);n===void 0?r.set(t,{descriptions:new Set,content:void 0,headers:[],streamContent:new Map([[e.contentType,e]])}):n.streamContent===void 0?n.streamContent=new Map([[e.contentType,e]]):n.streamContent.set(e.contentType,e)}}function Mk(e){return ey(e)??$v(e)}var Nk=J.annotate({format:`binary`});function Pk(e,t){switch(t){case`Uint8Array`:return Nk.ast;case`Text`:return J.ast;case`FormUrlEncoded`:case`Json`:return e;case`Multipart`:return Fk(e)}}function Fk(e){return Bg(e)&&e.annotations?.representation?.id===`effect/http/PersistedFile`?Nk.ast:typeof e?.recur==`function`?e.recur(Fk):e}var Ik=e=>{let t={};switch(Q(e.annotations,mk,e=>{t.description=e}),e._tag){case`Basic`:return{...t,type:`http`,scheme:`basic`};case`Http`:{let n=as(e.annotations,vk).pipe(ja(e=>({bearerFormat:e})),ka);return{...t,type:`http`,scheme:e.scheme,...n}}case`ApiKey`:return{...t,type:`apiKey`,name:e.key,in:e.in}}},Lk=e=>e.type===`http`?{...e,scheme:e.scheme.toLowerCase()}:e.in===`header`?{...e,name:e.name.toLowerCase()}:e,Rk=(e,t)=>mD(Fm(function*(n){let r=yield*mm(),i=[],a=Array.from(r.mapUnsafe.keys()).filter(e=>e.startsWith(`effect/httpapi/HttpApiGroup/`)),o=Object.values(e.groups);for(let e of o){let t=r.mapUnsafe.get(e.key)?.routes;if(t===void 0){let t=a.length===0?`none`:a.join(`, `);return yield*Zp(`HttpApiGroup "${e.identifier}" not found (key: "${e.key}"). Did you forget to provide HttpApiBuilder.group(api, "${e.identifier}", ...)? Available groups: ${t}`)}i.push(...t)}if(yield*n.addAll(i),t?.openapiPath){let r=On(e=>WE(Dk(e)));yield*n.add(`GET`,t.openapiPath,Kp(()=>r(e)))}})),zk=(e,t,n)=>op(Jp(function*(){let r=(yield*mm()).pipe(cs(Pf)),i=e.groups[t],a=n(Kk(i)),o=Hp(a)?yield*a:a,s=[];for(let t of o.handlers.values())s.push(Xk(e,i,t,r));return Vo(new Map([[i.key,{routes:s,handlers:o.handlers}]]))})),Bk=`~effect/httpapi/HttpApiBuilder/Handlers`,Vk=e=>{switch(e._tag){case`Http`:return U(aD,t=>TS(Uk(t.headers.authorization,e.scheme)??``));case`ApiKey`:{let t=e.in===`header`?e.key.toLowerCase():e.key,n=Y({[t]:J});return fm(e.in===`query`?lD(n):e.in===`cookie`?sD(n):cD(n),{onFailure:()=>TS(``),onSuccess:e=>TS(e[t])})}case`Basic`:{let e={username:``,password:TS(``)};return U(aD,t=>{let n=Uk(t.headers.authorization,Hk);if(n===void 0)return e;let r=za(ac(n));if(r===void 0)return e;let i=r.indexOf(`:`);return i===-1?e:{username:r.slice(0,i),password:TS(r.slice(i+1))}})}}},Hk=`Basic`;function Uk(e,t){let n=t.length;if(e===void 0||e.length<=n||e.charCodeAt(n)!==32||e.slice(0,n).toLowerCase()!==t.toLowerCase())return;let r=n+1;for(;e.charCodeAt(r)===32;)r++;return r===e.length?void 0:e.slice(r)}var Wk=(e,t,n,r,i)=>{if(!Object.hasOwn(e.group.endpoints,t))throw Error(`HttpApiEndpoint "${t}" not found in HttpApiGroup "${e.group.identifier}"`);if(e.handlers.has(t))throw Error(`Handler for HttpApiEndpoint "${t}" is already registered in HttpApiGroup "${e.group.identifier}"`);let a=e.group.endpoints[t];return e.handlers.set(t,{endpoint:a,handler:n,isRaw:r,uninterruptible:i?.uninterruptible??!1}),e},Gk={[Bk]:Bk,pipe(){return x(this,arguments)},handle(e,t,n){return Wk(this,e,t,!1,n)},handleAll(e){for(let[t,n]of Object.entries(e)){let e=typeof n==`function`?n:n.handler,r=typeof n==`function`?void 0:n.options;Wk(this,t,e,!1,r)}return this},handleRaw(e,t,n){return Wk(this,e,t,!0,n)}},Kk=e=>{let t=Object.create(Gk);return t.group=e,t.handlers=new Map,t};function qk(e,t){let n=new Map;return e.forEach(({encoding:e,schemas:r},i)=>{let a=CC(qC(r),t);e._tag===`Multipart`?n.set(i,{_tag:`Multipart`,mode:e.mode,limits:e.limits,decode:a}):n.set(i,{_tag:e._tag,decode:a,nullOnEmpty:r.some(e=>Vg(Fv(e.ast)))})}),n}function Jk(e,t,n){let r=zT(t.method),i=r?vO(t.headers[`content-type`]??`application/json`):`application/x-www-form-urlencoded`,a=e.get(i);if(!a)return UE(`Unsupported content-type: ${i}`,{status:415});let{_tag:o,decode:s}=a;switch(o){case`Multipart`:if(a.mode===`buffered`){let e=um(t.multipart);return a.limits&&(e=_m(e,eD(a.limits))),H(e,s)}return B(a.limits?cT(t.multipartStream,eD(a.limits)):t.multipartStream);case`Json`:return H(um(t.text),e=>{if(e===``)return s(a.nullOnEmpty?null:void 0);try{return s(JSON.parse(e))}catch{return V(new gC(new hh({message:`Expected a valid JSON body`})))}});case`Text`:return H(um(t.text),s);case`FormUrlEncoded`:return H(r?U(um(t.urlParamsBody),dC):B(n),s);case`Uint8Array`:return H(U(um(t.arrayBuffer),e=>new Uint8Array(e)),s)}}function Yk(e,t,n,r,i,a){let o=Qo(os(os(e.annotations,t.annotations),n.annotations),QO),s=e=>CC(e,o),c=EC(gA(n),o),l=EC(_A(n),o),u=pT(n.params,s),d=pT(n.headers,s),f=pT(n.query,e=>s(Bw(e))),p=aA(n,o),m=iA(n,o),h=n.payload.size>0&&!a?qk(n.payload,o):void 0;return Zk(t,n,r,Jp(function*(){let e=fy().context,r=es(e,aD),a=es(e,pD),o=es(e,oD),s={request:r,endpoint:n,group:t};if(u&&(s.params=yield*tk.wrap(`Params`,u(a.params))),d&&(s.headers=yield*tk.wrap(`Headers`,d(r.headers))),f&&(s.query=yield*tk.wrap(`Query`,f(o))),h){let e=Jk(h,r,o);if(zE(e))return e;e!==void 0&&(s.payload=yield*tk.wrap(`Payload`,e))}let l=yield*i(s);if(zE(l))return l;let g;m!==void 0&&QD(l)&&(g=l.headers,l=l.body);let _=yield*tk.wrap(`Body`,p?.(l,e)??(g===void 0?c(l):m.encodeBody(l)));return m===void 0||g===void 0?_:JE(_,yield*tk.wrap(`ResponseHeaders`,m.encodeHeaders.get(_.status)(g)))})).pipe(dm,sm(e=>tk.is(e)?Zp(e):um(l(e))),_m(r))}function Xk(e,t,n,r){let i=n.endpoint;return vD(i.method,uk(i.path,i.params),Yk(e,t,i,r,n.handler,n.isRaw),{uninterruptible:n.uninterruptible})}var Zk=(e,t,n,r)=>{let i={group:e,endpoint:t};for(let e of t.middlewares){let t=e,a=es(n,t);r=(ik(t)?$k(t,a):a)(r,i)}return r},Qk=new WeakMap,$k=(e,t)=>{let n=Qk.get(t);if(n!==void 0)return n;let r=Object.entries(e.security).map(([e,n])=>({decode:Vk(n),middleware:t[e]}));if(r.length===0)return C;let i=Fm(function*(e,t){e=lm(e,e=>new tA(e));let n;for(let i=0;i<r.length;i++){let{decode:a,middleware:o}=r[i],s=yield*rm(H(a,n=>o(e,{credential:n,endpoint:t.endpoint,group:t.group})));if(Fa(s)){if(nA(s.failure))return yield*V(s.failure.error);n=s;continue}return s.success}return yield*em(n)});return Qk.set(t,i),i},eA=`~effect/httpapi/HttpApiBuilder/HandlerError`,tA=class{[eA]=eA;error;constructor(e){this.error=e}},nA=e=>w(e,eA),rA=hC(zE);function iA(e,t){let n=new Map,r=[];for(let i of e.success)Z(i)&&(n.set(mO(i),EC(i.headers,t)),qD(i.schema)||r.push(pA(i)));return n.size===0?void 0:{encodeBody:EC(r.length===0?MC:r.length===1?r[0]:qC(r),t),encodeHeaders:n}}function aA(e,t){let n=oA(e);if(n===void 0)return;let r=n.body,i=sA(e),a=mO(n.schema),o=r.contentType;if(YD(r))return(e,t)=>Jw(e)?B(KE(cT(e,t),{status:a,contentType:o})):i?void 0:new gC(new hh({message:`Expected a streaming response`}));let s=cA(r,t);return(e,t)=>Jw(e)?B(KE(cT(lA(e,s),t),{status:a,contentType:o})):i?void 0:new gC(new hh({message:`Expected a streaming response`}))}function oA(e){for(let t of e.success){let e=Z(t)?t.schema:t;if(qD(e))return{schema:t,body:e}}}function sA(e){for(let t of e.success){let e=Z(t)?t.schema:t;if(DC(e)&&!qD(e))return!0}return e.success.size===0}function cA(e,t){let n=Rw(bw(e.error,pw()));return{sseMode:e.sseMode,encodeEvents:EC(WC(e.events),t),encodeCause:EC(hw(n),t)}}function lA(e,t){return e.pipe(t.sseMode===`data`?tT(e=>({id:void 0,event:`message`,data:e})):C,nT(e=>um(t.encodeEvents(e))),rT(e=>Xw(uA(e,t))),tT(fA),oT)}function uA(e,t){return t.encodeCause(e).pipe(um,U(e=>({id:void 0,event:dA,data:e})))}var dA=`effect/httpapi/stream/failure`;function fA(e){return UD.write({_tag:`Event`,event:e.event,id:e.id,data:e.data})}var pA=vA(mO),mA=vA(_O);function hA(e){if(!Z(e))return mA(e);let t=EC(e.schema),n=EC(e.headers),r=xA(_O(e),hO(e),iO(e.schema.ast)),i=bA((e,n)=>t(e,n).pipe(lm(e=>e.issue),H(e=>r(e,n))),n);return rA.pipe(X(e,i))}function gA(e){let t=xO(e).map(pA);return t.length===1?t[0]:qC(t)}function _A(e){let t=SO(e).map(hA);return t.length===0?MC:t.length===1?t[0]:qC(t)}function vA(e){let t=new WeakMap;return n=>{let r=Z(n)?n:n.ast,i=t.get(r);if(i!==void 0)return i;let a=Z(n)?n.schema:n,o=rA.pipe(X(a,yA(e,n)));return t.set(r,o),o}}function yA(e,t){let n=oO(t.ast);if(n!==void 0)return bA(xA(e(n.body),fO(n.body.ast),iO(n.body.ast)),EC(n.headersCodec));let r=Z(t)?t.schema:t;return Tg({decode:(e,t)=>V(new _h({message:`Encode only schema`},e,t)),encode:xA(e(t),hO(t),iO(r.ast))})}function bA(e,t){return Tg({decode:(e,t)=>V(new _h({message:`Encode only schema`},e,t)),encode:(n,r)=>{let i=n;return H(e(i.body,r),e=>U(t(i.headers,r).pipe(lm(e=>e.issue)),t=>JE(e,t)))}})}function xA(e,t,n){switch(t._tag){case`Json`:return(r,i)=>{if(r===void 0||n)return B(BE({status:e}));try{return B(UE(JSON.stringify(r),{status:e,contentType:t.contentType}))}catch{return V(new hh({expected:`a JSON-serializable response body`},r,i))}};case`Text`:return n=>B(UE(n,{status:e,contentType:t.contentType}));case`Uint8Array`:return n=>B(VE(n,{status:e,contentType:t.contentType}));case`FormUrlEncoded`:return n=>B(GE(n,{status:e}).pipe(qE(`content-type`,t.contentType)))}}var SA=(e,t)=>Jp(function*(){let n=yield*mm(),r=t.httpClient.pipe(t?.baseUrl===void 0?C:wE(rE(t.baseUrl.toString())));function i(e,t,a,o,s){if(s===-1)return r.execute(a);let c=n.mapUnsafe.get(o[s]);return c===void 0?i(e,t,a,o,s-1):c({endpoint:t,group:e,request:a,next(n){return i(e,t,n,o,s-1)}})}YO(e,{predicate:t?.predicate,onGroup(e){t.onGroup?.(e)},onEndpoint(e){let{group:n,endpoint:r,errors:a,successes:o,mergedAnnotations:s}=e,c=Qo(s,QO),l=EA(r.path,r.params),u={orElse:GA},d=new Map;for(let[e,t]of a.entries()){let n=jA(t);for(let[t,r]of n.entries())kA(d,e,t,DA(r,c))}for(let[e,t]of d.entries()){let n=AA(t);u[e]=e=>H(cm(n(e),t=>Yp(gf(uf(new jT({reason:new IT({request:e.request,response:e})})),t))),V)}let f=new Map;for(let[e,t]of o.entries()){let n=jA(t);for(let[t,r]of n.entries())kA(f,e,t,DA(r,c))}for(let e of FA(r)){let t=PA(e)?e.schema:e;kA(f,mO(e),t.contentType,IA(e,c))}for(let[e,t]of f.entries())u[e]=AA(t);let p=e=>EC(e,c),m=pT(r.params,p),h=bO(r),g=Za(h)?zT(r.method)?p(qA(h,r.method)):p(qC(h)):void 0,_=pT(r.headers,p),ee=pT(r.query,p),v=Array.from(e.middleware,e=>`${e.key}/Client`),te=Fm(function*(e){let a=YT(r.method)(r.path);if(e!==void 0){if(m!==void 0){let t=yield*m(e.params);a=nE(a,l(t))}if(g!==void 0){if(zT(r.method)){if(e.payload instanceof FormData)a=lE(a,e.payload);else{let t=yield*g(e.payload);a=cE(a,t)}}else{let t=yield*g(e.payload);a=oE(a,t)}}if(_!==void 0){let t=yield*_(e.headers);a=$T(a,t)}if(ee!==void 0){let t=yield*ee(e.query);a=oE(a,t)}}let o=yield*i(n,r,a,v,v.length-1);if(e?.responseMode===`response-only`)return o;let s=(u[o.status]??u.orElse)(o,e?.sseOptions),c=yield*t.transformResponse===void 0?s:t.transformResponse(s);return e?.responseMode===`decoded-and-response`?[c,o]:c});t.onEndpoint({...e,endpointFn:te})}})}),CA=(e,t)=>H(yE,n=>wA(e,{...t,httpClient:t?.transformClient?t.transformClient(n):n})),wA=(e,t)=>{let n={};return SA(e,{...t,onGroup({group:e}){e.topLevel||E(n,e.identifier,{})},onEndpoint({endpoint:e,endpointFn:t,group:r}){E(r.topLevel?n:n[r.identifier],e.identifier,t)}}).pipe(am(n))},TA=/(\/?):(\w+)(\?)?/g,EA=(e,t)=>{if(t===void 0||!e.includes(`:`))return t=>e;let n=lk(t);return t=>e.replace(TA,(e,r,i,a)=>{if(n!==void 0&&!n.has(i))return e;let o=t[i];if(o===void 0){if(a!==void 0)return``;throw Error(`Missing path parameter: ${i}`)}return`${r}${encodeURIComponent(o)}`})};function DA(e,t){let n=e.some(e=>Z(e)||oO(e.ast)!==void 0),r=wC(n?qC(e.map(OA)):UA(e),t);return e=>H(e.arrayBuffer,n?t=>r({body:t,headers:e.headers}):r)}function OA(e){let t=Z(e),n=oO(e.ast);if(n!==void 0)return Y({body:WA(n.body),headers:n.headersCodec}).pipe(X(e));let r=t?e.schema:e;return Y({body:WA(r).pipe(X(r)),headers:t?e.headers:NC}).pipe(X(t?e:kC(e),Eg({decode:e=>t?$D(e):e.body,encode:e=>t?e:{body:e,headers:void 0}})))}function kA(e,t,n,r){let i=vO(n),a=e.get(t);a===void 0?e.set(t,[{contentType:i,decode:r}]):a.push({contentType:i,decode:r})}function AA(e){let t=e[0];return e.length===1&&t!==void 0?t.decode:(t,n)=>{let r=vO(t.headers[`content-type`]??``),i=e.find(e=>e.contentType===r);return i===void 0?MA(t,r,e):i.decode(t,n)}}function jA(e){let t=new Map;for(let n of e){let e=iO((Z(n)?n.schema:n).ast)?``:vO(hO(n).contentType),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return t}function MA(e,t,n){let r=Array.from(new Set(n.map(e=>e.contentType))).join(`, `);return V(new jT({reason:new LT({request:e.request,response:e,description:`Unsupported response content-type for status ${e.status}: ${t||`<missing>`}. Expected one of: ${r}`})}))}var NA=`effect/httpapi/stream/failure`,PA=e=>Z(e);function FA(e){let t=[];for(let n of e.success)qD(Z(n)?n.schema:n)&&t.push(n);return t}function IA(e,t){let n=PA(e),r=n?e.schema:e,i=YD(r)?void 0:{declaration:r,decoder:LA(r,t)},a=(e,t)=>U(mm(),n=>cT(i===void 0?e.stream:RA(e.stream,i.declaration,i.decoder(t)),n));if(!n)return a;let o=CC(e.headers,t);return(e,t)=>H(o(e.headers),n=>U(a(e,t),e=>$D({body:e,headers:n})))}function LA(e,t){let n=qC([Y({id:OC(J),event:jC(NA),data:hw(Rw(bw(e.error,pw())))}),e.events]),r=ID(n,void 0,t);return e=>e===void 0?r:ID(n,e,t)}function RA(e,t,n){let r=Zw(e.pipe(aT,iT(n)),e=>Kp(()=>{let t;return Gp(()=>t===void 0?H(e,e=>{for(let n=0;n<e.length;n++){let r=e[n];if(r.event===NA&&of(r.data)){if(n===0)return Yp(r.data);t=r.data,e=e.slice(0,n);break}}return B(e)}):Yp(t))}));return t.sseMode===`data`?tT(r,e=>e.data):r}var zA=tw(globalThis.ArrayBuffer,{expected:`ArrayBuffer`}),BA=zA.pipe(X(vw,Eg({decode(e){return new Uint8Array(e)},encode(e){return e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}}))),VA=zA.pipe(X(J,Eg({decode(e){return new TextDecoder().decode(e)},encode(e){let t=new TextEncoder().encode(e);return t.byteLength===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength)}}))),HA=VA.pipe(X(qC([jC(``).pipe(X(FC,Eg({decode:()=>void 0,encode:()=>``}))),gw])));function UA(e){return qC(e.map(t));function t(e){return WA(e).pipe(X(e))}}function WA(e){switch(fO(e.ast)._tag){case`Json`:return Vg(Fv(e.ast))?HA.pipe(X(NC,Eg({decode:e=>e===void 0?null:e,encode:e=>e===null?void 0:e}))):HA;case`FormUrlEncoded`:return VA.pipe(X(Ow,Eg({decode:e=>nC(new URLSearchParams(e)),encode:uC})));case`Uint8Array`:return BA;case`Text`:return VA}}var GA=e=>V(new jT({reason:new LT({request:e.request,response:e})})),KA=hC(hT);function qA(e,t){return qC(e.map(e=>YA(e,t)))}var JA=new WeakMap;function YA(e,t){let n=e.ast,r=JA.get(n);if(r!==void 0)return r;let i=dO(n,t),a=KA.pipe(X(e,Tg({decode(e,t){return V(new _h({message:`Encode only schema`},e,t))},encode(e,t){switch(i._tag){case`Multipart`:return V(new _h({message:`Payload must be a FormData`},e,t));case`Json`:try{return B(CT(JSON.stringify(e),i.contentType))}catch{return V(new hh({expected:`a JSON-serializable request body`},e,t))}case`Text`:return typeof e==`string`?B(CT(e,i.contentType)):V(new hh({message:`Expected a string`},e,t));case`FormUrlEncoded`:return Vn(e)?B(TT(nC(e),i.contentType)):V(new hh({message:`Expected a record`},e,t));case`Uint8Array`:return e instanceof Uint8Array?B(yT(e,i.contentType)):V(new hh({message:`Expected a Uint8Array`},e,t))}}})));return JA.set(n,a),a}var XA=`~effect/httpapi/HttpApiGroup`,ZA={[XA]:XA,add(...e){let t={...this.endpoints};for(let n of e)E(t,n.identifier,n);return $A({...QA(this),endpoints:t})},prefix(e){return $A({...QA(this),endpoints:Ha(this.endpoints,t=>t.prefix(e))})},middleware(e){return $A({...QA(this),endpoints:Ha(this.endpoints,t=>t.middleware(e))})},annotateMerge(e){return $A({...QA(this),annotations:os(this.annotations,e)})},annotate(e,t){return $A({...QA(this),annotations:Yo(this.annotations,e,t)})},annotateEndpointsMerge(e){return $A({...QA(this),endpoints:Ha(this.endpoints,t=>t.annotateMerge(e))})},annotateEndpoints(e,t){return $A({...QA(this),endpoints:Ha(this.endpoints,n=>n.annotate(e,t))})},pipe(){return x(this,arguments)}},QA=e=>({identifier:e.identifier,topLevel:e.topLevel,endpoints:e.endpoints,annotations:e.annotations}),$A=e=>{function t(){}return Object.setPrototypeOf(t,ZA),t.key=`effect/httpapi/HttpApiGroup/${e.identifier}`,Object.assign(t,e)},ej=(e,t)=>$A({identifier:e,topLevel:t?.topLevel??!1,endpoints:{},annotations:Ko()}),tj=(e,t,n)=>CA(e,n).pipe(gm(FE),ym(NE,t));function nj(e,{baseUrl:t,transformClient:n,fetch:r}={}){let i=r??((e,t)=>globalThis.fetch(e,t)),a=Nm(tj(e.api,i,{baseUrl:t,transformClient:n}));return Object.fromEntries(Object.entries(a).map(([e,t])=>[e,Object.fromEntries(Object.entries(t).map(([e,t])=>[e,e=>Mm(t({payload:e??{}}))]))]))}var rj=e=>[...new Set([e.invalid.schema,e.internal.schema])],ij=new Set([`Body`,`ResponseHeaders`]),aj=(e,t)=>ij.has(t.kind)?e.internal.make(t):e.invalid.make(t),oj=(e,t)=>[...new Set([...e.errors,...t??[]])],sj=/^[A-Za-z0-9_-]+$/,cj=(e,t)=>{if(!sj.test(t)||t===`then`)throw Error(`Invalid ${e}: ${t}`)},lj=(e,t)=>{let n=new Set;for(let r of t){if(n.has(r))throw Error(`Duplicate ${e}: ${r}`);n.add(r)}},uj=VC(J,MC);function dj(e,t){cj(`action name`,e);let{access:n}=t;if(n!==`read`&&n!==`write`)throw Error(`Invalid access: ${String(n)}`);let r=t.mcp===!1?!1:t.mcp?.readOnly??n===`read`,i=t.mcp!==!1&&{name:t.mcp?.name??e,readOnly:r,destructive:t.mcp?.destructive??!r,idempotent:t.mcp?.idempotent??!1,openWorld:t.mcp?.openWorld??!0};if(i!==!1&&i.name.length>128)throw Error(`Invalid MCP name: ${i.name}`);return i!==!1&&cj(`MCP name`,i.name),{name:e,description:t.description,input:t.input??uj,success:t.success,errors:t.errors??[],access:n,mcp:i}}var fj=class e{group;#e;constructor(e,t){this.group=e,this.#e=t}get build(){return this.#e}static make(t,n){return new e(t,n)}},pj=(e,t,n,r)=>{let i=Object.hasOwn(n,t.name)?n[t.name]:void 0;if(!Ln(i))throw Error(`No handler for ${e.name}.${t.name}`);let a={"action.group":e.name,"action.name":t.name,"action.access":t.access};return n=>{let o=Dm(Im(Gp(()=>i(n)),a),`${e.name}.${t.name}`,{captureStackTrace:!1,attributes:a});return r===void 0?o:H(r(t),()=>o)}},mj=(e,t)=>{let n=e.actions.filter(e=>!(Object.hasOwn(t,e.name)&&Ln(t[e.name])));if(n.length>0)throw Error(`Missing handlers for group "${e.name}": ${n.map(e=>e.name).join(`, `)}`);return t};function hj(e,...t){let{name:n}=e;cj(`action group name`,n);let r=t.map(t=>({...t,errors:[...t.errors,...e.errors??[]]}));lj(`action`,r.map(e=>e.name)),lj(`MCP tool`,r.flatMap(e=>e.mcp===!1?[]:[e.mcp.name]));let i={name:n,actions:r,schemaError:e.schemaError,implement:e=>{let t=Hp(e)?U(e,e=>mj(i,e)):B(mj(i,e));return fj.make(i,t)}};return i}var gj=(e,t,n)=>UO(n.name,`${e.apiPath}/${t.name}/${n.name}`,{payload:n.input,success:n.success,error:oj(n,e.errors)}).annotate(mk,n.description),_j=(e,t)=>{class n extends ak()(`effect-actions/http/SchemaErrors/${e}`,{error:rj(t)}){}return{SchemaErrors:n,layer:sk(n,e=>V(aj(t,e)))}};function vj(e,t){let[n,...r]=t.actions.map(n=>gj(e,t,n));if(n===void 0)return;let i=ej(t.name).add(n,...r);if(t.schemaError===void 0)return{native:i,middleware:rp};let a=_j(t.name,t.schemaError);return{native:i.middleware(a.SchemaErrors),middleware:a.layer}}function yj(e){let[t,...n]=e,r=JO(`actions`).annotate(QO,{errors:`all`});return t===void 0?r:r.add(t,...n)}var bj=e=>e,xj=(e,t,n,r)=>{let i=e=>Object.fromEntries(t.group.actions.map(n=>{let i=pj(t.group,n,e,r);return[n.name,e=>i(e.payload)]}));return lp(U(t.build,n=>zk(e,t.group.name,e=>e.handleAll(i(bj(n)))))).pipe(pp(n))};function Sj(e,...t){lj(`action group`,t.map(e=>e.name));let n=new Map(t.flatMap(t=>{let n=vj(e,t);return n===void 0?[]:[[t,n]]})),r=(e,r={})=>{lj(`implementation group`,e.map(e=>e.group.name));for(let n of e)if(!t.includes(n.group))throw Error(`Implementation of group "${n.group.name}" is not served by this adapter`);let i=e.flatMap(e=>{let t=n.get(e.group);return t===void 0?[]:[{app:e,...t}]}),a=yj(i.map(({native:e})=>e)),[o,...s]=i.map(({app:e,middleware:t})=>xj(a,e,t,r.before));return o===void 0?Rk(a):Rk(a).pipe(pp([o,...s]))},i=yj([...n.values()].map(({native:e})=>e));return{groups:t,api:i,layer:r,openApi:(t=`${e.apiPath}/openapi.json`)=>hD(`GET`,t,WE(Dk(i)))}}var Cj=class extends Lw()(`BadRequest`,{error:J},{httpApiStatus:400}){},wj=class extends Lw()(`Unauthorized`,{error:J},{httpApiStatus:401}){},Tj=class extends Lw()(`Forbidden`,{error:J},{httpApiStatus:403}){},Ej=class extends Lw()(`NotFound`,{error:J},{httpApiStatus:404}){},Dj=class extends Lw()(`Conflict`,{error:J},{httpApiStatus:409}){},Oj=class extends Lw()(`TooManyRequests`,{error:J},{httpApiStatus:429}){},kj=class extends Lw()(`InternalServerError`,{error:J},{httpApiStatus:500}){cause},Aj=[Cj,wj,Tj,Ej,Dj,Oj,kj,class extends Lw()(`ServiceUnavailable`,{error:J},{httpApiStatus:503}){}],jj=Y({email:J,password:J}),Mj=JC([`none`,`client_secret_basic`,`client_secret_post`]),Nj=JC([`web`,`native`]),Pj=Y({client_name:J,redirect_uris:WC(J),resources:WC(J),token_endpoint_auth_method:Mj,application_type:Nj}),Fj=Y({client_id:J,client_name:J,redirect_uris:WC(J),application_type:Nj}),Ij=Y({client_id:J}),Lj=Y({client_id:J,blocked:LC}),Rj=Y({onboarding:OC(JC([`managed`,`dcr`,`cimd`])),blocked:OC(LC),client_id:J,client_name:OC(J),redirect_uris:WC(J),token_endpoint_auth_method:OC(J),application_type:OC(YC(J)),scope:OC(J),grant_types:OC(WC(J))}),zj=Rj.pipe(BC({client_secret:OC(J),client_secret_expires_at:OC(IC)})),Bj=Y({identifier:J,name:J,scopes:WC(J)}),Vj=Bj.pipe(BC({builtIn:LC})),Hj=Y({identifier:J}),Uj=Y({client_id:J,resource:J}),Wj=Y({client_id:J,resources:WC(J)}),Gj=Y({clientAccess:WC(Uj)}),Kj=VC(J,WC(J)),qj=Dw,Jj=Y({name:J,permissions:Kj,expiresAt:YC(qj)}),Yj=Y({keyId:J}),Xj=Y({keyId:J,name:OC(J),permissions:OC(Kj),enabled:OC(LC)}),Zj=Y({keyId:J,name:J,enabled:LC,permissions:Kj,expiresAt:YC(qj),createdAt:qj}),Qj={invalid:{schema:Cj,make:()=>new Cj({error:`Invalid request`})},internal:{schema:kj,make:()=>new kj({error:`Request could not be completed`})}},$j=hj({name:`issuer`,errors:Aj,schemaError:Qj},dj(`setupStatus`,{description:`Check whether the issuer needs its first owner account.`,access:`read`,success:Y({required:LC}),mcp:!1}),dj(`setupOwner`,{description:`Create the first owner account.`,access:`write`,input:jj,success:Y({created:LC}).pipe(GD(201)),mcp:!1}),dj(`verifyApiKey`,{description:`Verify the bearer API key against one resource and return its granted scopes.`,access:`read`,input:Y({resource:J}),success:Y({keyId:J,ownerId:J,resource:J,scopes:WC(J),expiresAt:YC(qj)}),mcp:!1})),eM=Y({clients:WC(Rj),resources:WC(Vj),clientAccess:WC(Uj),email:J,issuer:J}),tM=Sj({apiPath:`/api`},hj({name:`administration`,errors:Aj,schemaError:Qj},dj(`listClients`,{description:`List clients, resources and access grants.`,access:`read`,success:eM}),dj(`createClient`,{description:`Register a first-party OAuth client. Returns its secret once when confidential.`,access:`write`,input:Pj,success:zj.pipe(GD(201))}),dj(`updateClient`,{description:`Rename a first-party client or change its redirect URIs and application type.`,access:`write`,input:Fj,success:Rj}),dj(`deleteClient`,{description:`Delete a first-party OAuth client.`,access:`write`,input:Ij,success:Y({deleted:LC})}),dj(`revokeClient`,{description:`Revoke a client’s authorization grants.`,access:`write`,input:Ij,success:Y({revoked:LC})}),dj(`blockClient`,{description:`Block or unblock OAuth authorization for a client.`,access:`write`,input:Lj,success:Y({blocked:LC})}),dj(`rotateClientSecret`,{description:`Rotate a confidential client secret. Returns the new secret once.`,access:`write`,input:Ij,success:zj}),dj(`setClientAccess`,{description:`Set the resources a client may request.`,access:`write`,input:Wj,success:Gj}),dj(`createResource`,{description:`Create an OAuth resource and its scopes.`,access:`write`,input:Bj,success:Bj.pipe(GD(201))}),dj(`updateResource`,{description:`Update an OAuth resource and its scopes.`,access:`write`,input:Bj,success:Bj}),dj(`deleteResource`,{description:`Delete a resource and its client-resource links. Stored authorization grants and API-key permissions are retained; recreating the resource can restore access.`,access:`write`,input:Hj,success:Y({deleted:LC})}),dj(`listApiKeys`,{description:`List API key metadata without secret values.`,access:`read`,success:Y({keys:WC(Zj)})}),dj(`createApiKey`,{description:`Create a scoped API key. Returns its secret once.`,access:`write`,input:Jj,success:Zj.pipe(BC({key:J}),GD(201))}),dj(`updateApiKey`,{description:`Update an API key’s name, permissions or enabled state.`,access:`write`,input:Xj,success:Zj}),dj(`deleteApiKey`,{description:`Delete an API key.`,access:`write`,input:Yj,success:Y({deleted:LC})})),$j);tM.api;var nM=nj(tM),rM=SC(qC(Aj)),iM=e=>Error(rM(e)?e.error:`Request could not be completed. Please try again.`);async function aM(e){try{return await e}catch(e){throw iM(e)}}var oM=dn({plugins:[bn()]}),sM=document.querySelector(`#app`);sM.innerHTML=`<header><a href="/" class="brand"><span class="mark">c.</span> clanker<span class="muted">auth</span></a><span class="tag">PRIVATE IDENTITY</span></header><main id="main"></main><footer>Local accounts. Explicit access.<span>Self-hosted authorization server</span></footer>`;var cM=document.querySelector(`#main`),$=e=>e.replace(/[&<>"']/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`})[e]);function lM(e){let t=document.querySelector(`#message`);t.textContent=e,e&&t.hasAttribute(`tabindex`)&&(t.focus(),t.scrollIntoView({behavior:`smooth`,block:`center`}))}var uM=!1;async function dM(e){if(uM)return;uM=!0;let t=Array.from(cM.querySelectorAll(`button`),e=>({button:e,disabled:e.disabled}));t.forEach(({button:e})=>e.disabled=!0),lM(``);try{await e()}catch(e){lM(e instanceof Error?e.message:`Request failed`)}finally{t.forEach(({button:e,disabled:t})=>e.disabled=t),uM=!1}}function fM(e,t){!uM&&confirm(e)&&dM(t)}function pM(){cM.innerHTML=`<section class="intro"><p class="eyebrow">YOUR NETWORK, YOUR IDENTITY</p><h1>Your identity.<br>Starts here.</h1><p>Create the owner account for your private applications.<br>Your account stays on your infrastructure.</p><div class="note"><span class="dot"></span> One owner · Explicit access</div></section>
15
+ <section class="card login"><p class="eyebrow">FIRST-TIME SETUP</p><h2>Create your account</h2><p class="muted">This account manages Clients and Resources and approves access.</p>
16
+ <form id="setup"><label>Email<input name="email" type="email" autocomplete="username" required placeholder="owner@example.internal"></label>
17
+ <label>Password<input name="password" type="password" autocomplete="new-password" required minlength="8" maxlength="128" aria-describedby="password-help"></label><p id="password-help" class="help">Use 8–128 characters. Save your password somewhere safe.</p>
18
+ <label>Confirm password<input name="confirmation" type="password" autocomplete="new-password" required minlength="8" maxlength="128"></label>
19
+ <p id="message" role="alert"></p><button>Create account <span>→</span></button></form></section>`;let e=document.querySelector(`#setup`);e.addEventListener(`submit`,t=>{t.preventDefault(),dM(async()=>{let t=e.querySelector(`[name="password"]`).value,n=e.querySelector(`[name="confirmation"]`).value;if(t.length<8||t.length>128)throw Error(`Use a password between 8 and 128 characters.`);if(t!==n)throw Error(`Passwords do not match.`);try{await nM.issuer.setupOwner({email:e.querySelector(`[name="email"]`).value,password:t})}catch(e){if(e instanceof Dj)return location.replace(`/login`);throw iM(e)}location.replace(`/`)})})}function mM(){cM.innerHTML=`<section class="intro"><p class="eyebrow">YOUR NETWORK, YOUR IDENTITY</p><h1>One identity.<br>Deliberate access.</h1><p>Sign in to authorize your private applications.<br>Your account stays on your infrastructure.</p><div class="note"><span class="dot"></span> Password login · No external identity provider</div></section>
20
+ <section class="card login"><p class="eyebrow">OWNER ACCESS</p><h2>Welcome back</h2><p class="muted">Use your local account to continue.</p>
21
+ <form id="login"><label>Email<input name="email" type="email" autocomplete="username" required placeholder="owner@example.internal"></label>
22
+ <label>Password<input name="password" type="password" autocomplete="current-password" required></label>
23
+ <p id="message" role="alert"></p><button>Sign in <span>→</span></button></form></section>`;let e=document.querySelector(`#login`);e.addEventListener(`submit`,t=>{t.preventDefault(),dM(async()=>{if((await oM.signIn.email({email:e.querySelector(`[name="email"]`).value,password:e.querySelector(`[name="password"]`).value})).error)throw Error(`Sign-in failed. Check your credentials or try again later.`);let t=new URLSearchParams(location.search),n=t.get(`rd`)??`/`;t.has(`sig`)||location.assign(new URL(n,location.origin).origin===location.origin?n:`/`)})})}async function hM(){let e=new URLSearchParams(location.search),t=e.get(`client_id`);if(!t||!e.has(`sig`))throw Error(`Start authorization from your application; this consent link is incomplete.`);let n=await oM.oauth2.publicClient({query:{client_id:t}});if(n.error||!n.data)throw Error(`Sign in through your application to continue authorization.`);let r=(e.get(`scope`)??``).split(` `).filter(Boolean),i=e.getAll(`resource`),a;try{let e=new URL(t);e.protocol===`https:`&&(a=e.hostname)}catch{}let o=e.get(`redirect_uri`);cM.className=`center`,cM.innerHTML=`<section class="card consent"><p class="eyebrow">PERMISSION REQUEST</p><h1>Allow this connection?</h1>
24
+ <p><strong>${$(n.data.client_name??t)}</strong> wants to act on your behalf.</p>
25
+ ${a?`<p>Client metadata host: <strong>${$(a)}</strong></p>`:``}
26
+ <label>Client ID<code>${$(t)}</code></label>
27
+ <label>Callback destination<code>${$(o??`Not supplied in this request`)}</code></label>
28
+ <p class="help">The client supplies its display name. Review the identifier and callback before approving.</p>
29
+ <div class="resource"><span class="eyebrow">ONLY FOR THIS RESOURCE</span>${i.map(e=>`<code>${$(e)}</code>`).join(``)}</div>
30
+ <h3>Requested access</h3><ul class="scopes">${r.map(e=>`<li><span>✓</span><code>${$(e)}</code></li>`).join(``)}</ul>
31
+ ${e.has(`claims`)?`<h3>Additional identity claims</h3><pre>${$(e.get(`claims`))}</pre>`:``}
32
+ <p class="help">Access tokens expire after fifteen minutes. Offline access lets the Client renew them until you revoke its authorization.</p>
33
+ <p id="message" role="alert"></p><form id="consent"><div class="actions"><button type="submit" name="decision" value="deny" class="secondary">Deny</button><button type="submit" name="decision" value="allow">Allow access →</button></div></form></section>`,document.querySelector(`#consent`).addEventListener(`submit`,e=>{e.preventDefault();let t=e.submitter;if(!(t instanceof HTMLButtonElement))throw Error(`Consent must be decided with the Allow or Deny button.`);let n=t.value===`allow`;dM(async()=>{if((await oM.oauth2.consent({accept:n})).error)throw Error(`Authorization could not be completed. Restart from your application.`)})})}function gM(e,t){let n=e.get(t);if(n===null||n instanceof File)throw Error(`Missing form field: ${t}`);return n.trim()}function _M(e){return Array.from(e.querySelectorAll(`input[name="resources"]:checked`),e=>e.value)}function vM(e){let t=[...new Set(gM(e,`scopes`).split(/\s+/).filter(Boolean))];return{name:gM(e,`name`),scopes:t}}function yM(e){let t=[...new Set(gM(e,`redirect_uris`).split(/\s+/).filter(Boolean))];if(!t.length)throw Error(`Add at least one redirect URI.`);return t}var bM={none:`Public client (PKCE only)`,client_secret_basic:`Confidential client · HTTP Basic secret`,client_secret_post:`Confidential client · secret in request body`},xM=e=>TC(Mj)(gM(e,`token_endpoint_auth_method`)),SM=e=>TC(Nj)(e.has(`native`)?`native`:`web`);function CM(e){let t={};for(let n of e.querySelectorAll(`input[name="key-scope"]:checked`))(t[n.dataset.resource]??=[]).push(n.value);return t}var wM=new Map,TM=new Map;function EM(){let e=document.querySelector(`#credentials`);if(e.classList.toggle(`hidden`,TM.size===0&&wM.size===0),e.replaceChildren(),!TM.size&&!wM.size)return;e.innerHTML=`<h2>Save these credentials now</h2><p>API keys and client secrets are shown only once.</p><button class="secondary">Saved — dismiss credentials</button>`;let t=e.querySelector(`button`);for(let e of TM.values()){let n=document.createElement(`pre`);n.textContent=JSON.stringify(e,null,2),t.before(n)}for(let e of wM.values()){let n=document.createElement(`pre`);n.textContent=e,t.before(n)}t.addEventListener(`click`,()=>{wM.clear(),TM.clear(),EM()})}function DM(){EM(),document.querySelector(`#credentials`).scrollIntoView({behavior:`smooth`})}async function OM(){try{await UM()}catch{document.querySelector(`#dashboard-mutations`).disabled=!0,lM(`Saved, but the dashboard could not refresh.`);let e=document.createElement(`button`);e.type=`button`,e.className=`secondary`,e.textContent=`Retry refresh`,e.addEventListener(`click`,()=>{dM(OM)}),document.querySelector(`#message`).append(` `,e)}}var kM=`Optional. Separate scopes with spaces. offline_access is reserved.`,AM={managed:`Managed registration · first party, no consent screen`,dcr:`Dynamic registration`,cimd:`Client ID Metadata Document`},jM=e=>!e.onboarding||e.onboarding===`managed`,MM=(e,t,n,r,i)=>`<div class="columns dashboard-section"><section><h2>${e} <span class="count">${t}</span></h2><p class="muted">${n}</p>${r}</section><section class="card registration">${i}</section></div>`,NM=(e,t)=>`<div class="empty"><h3>${e}</h3><p>${t}</p></div>`,PM=e=>`<code>${$(e.identifier)}</code><span class="muted">${$(e.scopes.join(` · `))}</span>`,FM=(e,t)=>e.map(e=>`<label class="checkbox resource-choice"><input type="checkbox" name="resources" value="${$(e.identifier)}" ${t.includes(e.identifier)?`checked`:``}><span>${$(e.name)}${PM(e)}</span></label>`).join(``),IM=(e,t)=>e.map(e=>`<fieldset><legend>${$(e.name)}</legend><code>${$(e.identifier)}</code>${e.scopes.map(n=>`<label class="checkbox"><input type="checkbox" name="key-scope" data-resource="${$(e.identifier)}" value="${$(n)}" ${t[e.identifier]?.includes(n)?`checked`:``}><code>${$(n)}</code></label>`).join(``)}</fieldset>`).join(``)||`<p class="help">Add a Resource to grant access.</p>`,LM=(e,t)=>`<article class="resource"><h3>${$(e.name)}</h3>${PM(e)}
34
+ <p class="help dependencies">Managed Clients with access: ${t.length?t.map(e=>$(e.client_name??e.client_id)).join(`, `):`None`}</p>
35
+ ${e.builtIn?`<p class="help">Built-in administration resource. OAuth access tokens are required; its scopes and identifier are fixed.</p>`:``}
36
+ <details><summary>Edit resource</summary><form data-resource-edit="${$(e.identifier)}"><label>Name<input name="name" value="${$(e.name)}" required maxlength="100"></label>
37
+ ${e.builtIn?``:`<label>Scopes<input name="scopes" value="${$(e.scopes.join(` `))}"></label><p class="help">Added scopes need new consent. Removed scopes are no longer issued, but stored grants are kept and work again if the scope is restored.</p>`}
38
+ <button>Save resource</button></form></details>
39
+ ${e.builtIn?``:`<button class="danger" data-resource-delete="${$(e.identifier)}">Delete resource</button>`}</article>`,RM=()=>`<h2>Add resource</h2><form id="resource-create"><label>Name<input name="name" required maxlength="100" placeholder="Notes MCP"></label><label>HTTP or HTTPS identifier<input name="identifier" type="url" required placeholder="https://notes.internal/mcp"></label><p class="help">The identifier is the token audience and cannot be changed later. Use the canonical form a client sends back, such as the application\u2019s origin root with its trailing slash.</p><label>Scopes<input name="scopes" placeholder="notes:read notes:write"></label><p class="help">${kM}</p><button>Add resource +</button></form>`,zM=(e,t)=>`<article class="resource"><h3>${$(e.name)}</h3><p>${e.enabled?`Enabled`:`Disabled`} · ${e.expiresAt?`Expires ${$(Vh(e.expiresAt,{dateStyle:`medium`,timeStyle:`short`}))}`:`Valid until revoked`}</p>${Object.entries(e.permissions).map(([e,t])=>`<code>${$(e)}</code><p class="help">${$(t.join(` · `))}</p>`).join(``)}
40
+ <details><summary>Rename key</summary><form data-key-rename="${$(e.keyId)}"><label>Name<input name="name" required maxlength="100" value="${$(e.name)}"></label><button>Save name</button></form></details>
41
+ <details><summary>Edit grants</summary><form data-key-grants="${$(e.keyId)}">${IM(t,e.permissions)}<p class="help">Saving replaces all grants, including any not currently available, with the selected scopes.</p><button>Save grants</button></form></details>
42
+ <div class="actions"><button class="secondary" data-key-toggle="${$(e.keyId)}" data-enabled="${e.enabled}">${e.enabled?`Disable key`:`Enable key`}</button><button class="danger" data-key-delete="${$(e.keyId)}">Delete key</button></div></article>`,BM=e=>`<h2>Create API key</h2><form id="key-create"><label>Name<input name="name" required maxlength="100" placeholder="Backup script"></label>${IM(e,{})}<label>Expiry (optional)<input name="expiry" type="datetime-local"></label><p class="help">Blank means valid until revoked. The key is shown once.</p><button ${e.length?``:`disabled`}>Create API key</button></form>`,VM=(e,t,n)=>{let r=jM(e),i=$(e.client_id),a=t.flatMap(e=>n.includes(e.identifier)?[`<div class="allowed-resource"><strong>${$(e.name)}</strong>${PM(e)}</div>`]:[]).join(``)||`<p class="help">No Resource access configured.</p>`,o=`<details><summary>Manage access</summary><form data-client-access="${i}"><fieldset><legend>Allowed Resources</legend>${FM(t,n)||`<p class="help">Add a Resource above to configure access.</p>`}</fieldset><p class="help">${r?``:`Automatic Clients receive access to new Resources; each still needs your consent. `}Removing access stops new authorization and refresh; use Revoke authorization to clear issued grants.</p><button>Save access</button></form></details>`,s=r?`<details><summary>Edit client</summary><form data-client-edit="${i}"><label>Client name<input name="name" required maxlength="100" value="${$(e.client_name??``)}"></label><label>Redirect URIs (one per line)<textarea name="redirect_uris" required rows="3">${$(e.redirect_uris.join(`
43
+ `))}</textarea></label><label class="checkbox"><input type="checkbox" name="native" ${e.application_type===`native`?`checked`:``}>Native / desktop client (loopback redirect)</label><p class="help">The authentication method is fixed at registration.</p><button>Save client</button></form></details>`:``,c=[`<button class="secondary" data-revoke="${i}">Revoke authorization</button>`,`<button class="secondary" data-block="${i}" data-blocked="${e.blocked?`true`:`false`}">${e.blocked?`Unblock client`:`Block client`}</button>`,r&&e.token_endpoint_auth_method!==`none`?`<button class="secondary" data-rotate="${i}">Rotate secret</button>`:``,r?`<button class="danger" data-delete="${i}">Delete client</button>`:``].join(``);return`<article class="card client"><div class="client-heading"><h3>${$(e.client_name??`Unnamed client`)}</h3><span class="tag">${e.token_endpoint_auth_method===`none`?`PUBLIC · PKCE`:`CONFIDENTIAL · PKCE`}</span></div><p class="help">${AM[e.onboarding??`managed`]}${e.blocked?` · BLOCKED`:``}</p><label>Client ID<code>${i}</code></label><label>Redirect URIs${e.redirect_uris.map(e=>`<code>${$(e)}</code>`).join(``)}</label>
44
+ <h3>${r?`Allowed Resources`:`Resources eligible for consent`}</h3>${a}${o}${s}<div class="actions">${c}</div></article>`},HM=e=>`<p class="eyebrow">MANAGED REGISTRATION</p><h2>Register client</h2><form id="register"><fieldset><label>Client name<input name="name" required maxlength="100" placeholder="My MCP client"></label><label>Redirect URIs (one per line)<textarea name="redirect_uris" required rows="3" placeholder="https://app.internal/callback"></textarea></label><fieldset><legend>Allowed Resources (optional)</legend>${FM(e,[])||`<p class="help">You can configure Resource access after registration.</p>`}</fieldset><label class="checkbox"><input type="checkbox" name="native">Native / desktop client (loopback redirect)</label><label>Client authentication<select name="token_endpoint_auth_method">${Object.entries(bM).map(([e,t])=>`<option value="${e}">${t}</option>`).join(``)}</select></label><button>Register client +</button></fieldset><p class="help">S256 PKCE is always required. Clients you register here are first party and skip the consent screen.</p></form>`;async function UM(){let[e,t]=await aM(Promise.all([nM.administration.listClients(),nM.administration.listApiKeys()])),{resources:n}=e,r=n.filter(e=>!e.builtIn),i=t=>e.clientAccess.filter(e=>e.client_id===t).map(e=>e.resource);cM.className=`dashboard`,cM.innerHTML=`
45
+ <div class="page-title"><div><p class="eyebrow">CONTROL PLANE</p><h1>Clients and Resources</h1><p class="muted">Signed in as ${$(e.email)}</p></div><button id="logout" class="secondary">Sign out</button></div>
46
+ <div class="issuer"><span class="dot"></span><span>Canonical issuer</span><code>${$(e.issuer)}</code></div>
47
+ <p id="message" role="alert" tabindex="-1"></p>
48
+ <section id="credentials" class="card hidden" aria-live="polite"></section>
49
+ <fieldset id="dashboard-mutations" aria-label="Clients and Resources">
50
+ ${MM(`Resources`,n.length,`Protected APIs and MCP servers, and the scopes they define.`,n.map(t=>LM(t,e.clients.filter(e=>jM(e)&&i(e.client_id).includes(t.identifier)))).join(``)||NM(`Add your first Resource`,`Define a protected API or MCP server. Compatible MCP clients onboard automatically when you connect.`),RM())}
51
+ ${MM(`API keys`,t.keys.length,`Direct access for CLIs and automation. Keys carry only the scopes you select, filtered by current Resource policy. Policy changes do not revoke stored grants; restoring policy restores access.`,t.keys.map(e=>zM(e,r)).join(``)||NM(`No API keys`,`Create a key for a CLI or automation that needs direct access.`),BM(r))}
52
+ ${MM(`Clients`,e.clients.length,`Compatible MCP clients register themselves when they connect; registration alone grants no access. Revoking or blocking stops new authorization and refresh at once; already-issued access tokens stay valid until they expire, at most fifteen minutes.`,e.clients.map(e=>VM(e,n,i(e.client_id))).join(``)||NM(`No Clients registered`,`Connect your MCP client to a configured server to onboard automatically, or register a managed Client here.`),HM(n))}
53
+ </fieldset>`,EM();let a=e=>document.querySelector(e),o=(e,t)=>e.addEventListener(`submit`,n=>{n.preventDefault(),dM(()=>t(e))}),s=(e,t)=>{for(let n of cM.querySelectorAll(e))n.addEventListener(`click`,()=>t(n))};document.querySelector(`#logout`).addEventListener(`click`,()=>{dM(async()=>{await oM.signOut(),location.assign(`/login`)})}),o(a(`#register`),async e=>{let t=new FormData(e),n=await aM(nM.administration.createClient({client_name:gM(t,`name`),redirect_uris:yM(t),resources:_M(e),application_type:SM(t),token_endpoint_auth_method:xM(t)}));e.reset(),TM.set(n.client_id,n),DM(),await OM()}),o(a(`#key-create`),async e=>{let t=new FormData(e),n=gM(t,`expiry`),r=await aM(nM.administration.createApiKey({name:gM(t,`name`),permissions:CM(e),expiresAt:n?Lh(new Date(n)):null}));wM.set(r.keyId,`${r.name}\n${r.key}`),e.reset(),DM(),await OM()}),o(a(`#resource-create`),async e=>{let t=new FormData(e);await aM(nM.administration.createResource({identifier:gM(t,`identifier`),...vM(t)})),e.reset(),await OM()});for(let e of cM.querySelectorAll(`[data-key-rename]`))o(e,async e=>{await aM(nM.administration.updateApiKey({keyId:e.dataset.keyRename,name:gM(new FormData(e),`name`)})),await OM()});for(let e of cM.querySelectorAll(`[data-key-grants]`))o(e,async e=>{await aM(nM.administration.updateApiKey({keyId:e.dataset.keyGrants,permissions:CM(e)})),await OM()});for(let e of cM.querySelectorAll(`[data-resource-edit]`))o(e,async e=>{let t=n.find(t=>t.identifier===e.dataset.resourceEdit);await aM(nM.administration.updateResource({identifier:e.dataset.resourceEdit,name:gM(new FormData(e),`name`),scopes:t.builtIn?t.scopes:vM(new FormData(e)).scopes})),await OM()});for(let e of cM.querySelectorAll(`[data-client-edit]`))o(e,async e=>{let t=new FormData(e);await aM(nM.administration.updateClient({client_id:e.dataset.clientEdit,client_name:gM(t,`name`),redirect_uris:yM(t),application_type:SM(t)})),await OM()});for(let e of cM.querySelectorAll(`[data-client-access]`))e.addEventListener(`submit`,t=>{t.preventDefault();let n=e.dataset.clientAccess,r=_M(e),a=i(n).filter(e=>!r.includes(e)),o=async()=>{await aM(nM.administration.setClientAccess({client_id:n,resources:r})),await OM()};a.length?fM(`Remove access to ${a.join(`, `)}? Stored consent remains until revoked.`,o):dM(o)});s(`[data-key-toggle]`,e=>{dM(async()=>{await aM(nM.administration.updateApiKey({keyId:e.dataset.keyToggle,enabled:e.dataset.enabled!==`true`})),await OM()})}),s(`[data-key-delete]`,e=>{let t=e.dataset.keyDelete;fM(`Delete this API key?`,async()=>{await aM(nM.administration.deleteApiKey({keyId:t})),wM.delete(t),EM(),await OM()})}),s(`[data-revoke]`,e=>{let t=e.dataset.revoke;fM(`Revoke this Client’s authorization? It can request consent again.`,async()=>{await aM(nM.administration.revokeClient({client_id:t})),await OM()})}),s(`[data-block]`,e=>{let t=e.dataset.block,n=e.dataset.blocked!==`true`;fM(n?`Block this Client and revoke its authorization?`:`Unblock this Client?`,async()=>{await aM(nM.administration.blockClient({client_id:t,blocked:n})),await OM()})}),s(`[data-rotate]`,e=>{let t=e.dataset.rotate;fM(`Rotate the secret? The old one stops working immediately.`,async()=>{let e=await aM(nM.administration.rotateClientSecret({client_id:t}));TM.set(e.client_id,e),DM()})}),s(`[data-delete]`,e=>{let t=e.dataset.delete;fM(`Delete this Client and its grants?`,async()=>{await aM(nM.administration.deleteClient({client_id:t})),TM.delete(t),EM(),await OM()})}),s(`[data-resource-delete]`,e=>{let t=e.dataset.resourceDelete;fM(`Delete Resource ${t}? Stored grants are kept and may become usable again if it is recreated.`,async()=>{await aM(nM.administration.deleteResource({identifier:t})),await OM()})})}try{if((await aM(nM.issuer.setupStatus())).required)location.pathname===`/setup`?pM():location.replace(`/setup`);else if(location.pathname===`/setup`){let e=await oM.getSession();location.replace(e.data?`/`:`/login`)}else location.pathname===`/consent`?await hM():!(await oM.getSession()).data||location.pathname===`/login`?mM():await UM()}catch(e){cM.innerHTML=`<section class="card"><h1>Unable to continue</h1><p>${$(e instanceof Error?e.message:`Please try again`)}</p><a href="/login">Return to sign in</a></section>`}