@gjermundgaraba/clankerauth-dev 0.7.2 → 0.9.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.
@@ -1,53 +0,0 @@
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),Un=S(2,(e,t)=>w(e,`_tag`)&&e._tag===t);function Wn(e){return e instanceof Error}function Gn(e){return w(e,Symbol.iterator)||Mn(e)}var Kn=`~effect/Hash`,T=e=>{switch(typeof e){case`number`:return Zn(e);case`bigint`:return Qn(e.toString(10));case`string`:return Qn(e);case`undefined`:return Qn(`undefined`);case`function`:case`object`:if(e===null)return Qn(`null`);if(e instanceof Date)return Number.isNaN(e.getTime())?Qn(`Invalid Date`):Qn(e.toISOString());if(e instanceof RegExp)return Qn(e.toString());{if(jn.has(e))return qn(e);if(or.has(e))return or.get(e);let t=cr(e,()=>Xn(e)?e[Kn]():typeof e==`function`?qn(e):e instanceof DataView?nr(new Uint8Array(e.buffer,e.byteOffset,e.byteLength)):Array.isArray(e)||ArrayBuffer.isView(e)?nr(e):e instanceof Map?rr(e):e instanceof Set?ir(e):er(e));return or.set(e,t),t}default:return Qn(String(e))}},qn=e=>(ar.has(e)||ar.set(e,Zn(Math.floor(Math.random()*(2**53-1)))),ar.get(e)),Jn=S(2,(e,t)=>e*53^t),Yn=e=>e&3221225471|e>>>1&1073741824,Xn=e=>w(e,Kn),Zn=e=>{if(e!==e||e===1/0||e===-1/0)return Qn(String(e));let t=e|0;for(t!==e&&(t^=e*4294967295);e>4294967295;)t^=e/=4294967295;return Yn(t)},Qn=e=>{let t=5381,n=e.length;for(;n;)t=t*33^e.charCodeAt(--n);return Yn(t)},$n=(e,t)=>{let n=12289;for(let r of t)n^=Jn(T(r),T(e[r]));return Yn(n)},er=e=>$n(e,An(e)),tr=(e,t)=>n=>{let r=e;for(let e of n)r^=t(e);return Yn(r)},nr=tr(6151,T),rr=tr(Qn(`Map`),([e,t])=>Jn(T(e),T(t))),ir=tr(Qn(`Set`),T),ar=new WeakMap,or=new WeakMap,sr=new WeakSet;function cr(e,t){if(sr.has(e))return Qn(`[Circular]`);sr.add(e);let n=t();return sr.delete(e),n}var lr=`~effect/Equal`;function ur(){return arguments.length===1?e=>dr(e,arguments[0]):dr(arguments[0],arguments[1])}function dr(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:gr(e,t,hr):!1}function fr(e,t,n){let r=pr.has(e),i=mr.has(t);if(r&&i)return!0;if(r||i)return!1;pr.add(e),mr.add(t);let a=n();return pr.delete(e),mr.delete(t),a}var pr=new WeakSet,mr=new WeakSet;function hr(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=Tr(e),r=Tr(t);if(n!==r)return!1;let i=n&&r;return typeof e==`function`&&!i?!1:fr(e,t,()=>{if(i)return e[lr](t);if(Array.isArray(e))return!Array.isArray(t)||e.length!==t.length?!1:vr(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 yr(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),new Uint8Array(n.buffer,n.byteOffset,n.byteLength))}return yr(e,t)}return e instanceof Map?!(t instanceof Map)||e.size!==t.size?!1:Sr(e,t):e instanceof Set?!(t instanceof Set)||e.size!==t.size?!1:wr(e,t):br(e,t)})}function gr(e,t,n){let r=_r.get(e);if(!r)r=new WeakMap,_r.set(e,r);else if(r.has(t))return r.get(t);let i=n(e,t);r.set(t,i);let a=_r.get(t);return a||(a=new WeakMap,_r.set(t,a)),a.set(e,i),i}var _r=new WeakMap;function vr(e,t){for(let n=0;n<e.length;n++)if(!dr(e[n],t[n]))return!1;return!0}function yr(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 br(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)||!dr(e[i],t[i]))return!1;return!0}function xr(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 Sr=xr(dr,dr);function Cr(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 wr=Cr(dr),Tr=e=>w(e,lr),Er=e=>(t,n)=>t===n||e(t,n),Dr=(e,t)=>e===t,Or=()=>Dr;function kr(e){return Er((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 Ar(e){return Er((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 jr=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 Mr(e,t){for(let n of Reflect.ownKeys(t))Object.prototype.propertyIsEnumerable.call(t,n)&&E(e,n,t[n])}var Nr=Symbol.for(`~effect/Redactable`),Pr=e=>w(e,Nr);function Fr(e){return Pr(e)?Ir(e):e}function Ir(e){return e[Nr](globalThis[`~effect/Fiber/currentFiber`]?.context??zr)}var Lr=`~effect/Fiber/currentFiber`,Rr=new Map,zr={"~effect/Context":{},base:Rr,depth:0,mapUnsafe:Rr,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 Br;r.add(e);let l;if(Nr in e)l=c(Ir(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=Ur(e);else if(!t?.ignoreToString&&w(e,`toString`)&&typeof e.toString==`function`&&e.toString!==Object.prototype.toString&&e.toString!==Array.prototype.toString){let t=Wr(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=>`${Vr(t)}:${c(Gr(e,t),n)}`).join(`,`)}}`;l=o(e,r)}else{let r=`{\n${t.map(t=>`${a(n+1)}${Vr(t)}: ${c(Gr(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 Br=`[Circular]`;function Vr(e){return typeof e==`string`?JSON.stringify(e):String(e)}function Hr(e){return e.map(e=>`[${Vr(e)}]`).join(``)}function Ur(e){try{return e.toISOString()}catch{return`Invalid Date`}}function Wr(e){try{let t=e.toString();return typeof t==`string`?t:String(t)}catch{return`[toString threw]`}}function Gr(e,t){try{return e[t]}catch{return`[property access threw]`}}function Kr(e,t){let n=[];return JSON.stringify(e,function(e,t){let r=Object.getOwnPropertyDescriptor(this,e)?.value,i=w(r,Nr)?Fr(r):Fr(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 qr=Symbol.for(`nodejs.util.inspect.custom`),Jr=e=>{try{return e=Fr(e),w(e,`toJSON`)&&Ln(e.toJSON)&&e.toJSON.length===0?e.toJSON():Array.isArray(e)?e.map(Jr):e}catch{return`[toJSON threw]`}},Yr={toJSON(){return Jr(this)},[qr](){return this.toJSON()},toString(){return D(this.toJSON())}},Xr=class{[qr](){return this.toJSON()}toString(){return D(this.toJSON())}},Zr=(()=>{let e=Object.getOwnPropertyDescriptor(Error,`stackTraceLimit`);return e===void 0?Object.isExtensible(Error):Object.hasOwn(e,`writable`)?e.writable===!0:e.set!==void 0})(),Qr=()=>Error.stackTraceLimit,$r=e=>{Zr&&(Error.stackTraceLimit=e)},ei=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)}},ti=(()=>{let e=`~effect/Utils/internal`,t={[e]:e=>e()},n={[e]:e=>{try{return e()}finally{}}};return Qr()!==0&&t[e](()=>Error().stack)?.includes(e)===!0?t[e]:n[e]})(),ni=`~effect/Effect`,ri=`~effect/Exit`,ii={_A:C,_E:C,_R:C},ai=`${ni}/identifier`,O=`${ni}/args`,k=`${ni}/evaluate`,oi=`${ni}/successCont`,si=`${ni}/failureCont`,ci=`${ni}/ensureCont`,li=Symbol.for(`effect/Effect/Yield`),ui={pipe(){return x(this,arguments)},toJSON(){return{...this}},toString(){return D(this.toJSON(),{ignoreToString:!0,space:2})},[qr](){return this.toJSON()}},di={[ni]:ii,...ui,[Symbol.iterator](){return new ei(this)},toJSON(){return{_id:`Effect`,op:this[ai],...O in this?{args:this[O]}:void 0}}},fi=e=>w(e,ni),pi=e=>w(e,ri),mi=`~effect/Cause`,hi=`~effect/Cause/Reason`,gi=e=>w(e,mi),_i=e=>w(e,hi),vi=class{constructor(e){this[mi]=mi,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)})`}[qr](){return this.toJSON()}[lr](e){return gi(e)&&this.reasons.length===e.reasons.length&&this.reasons.every((t,n)=>ur(t,e.reasons[n]))}[Kn](){return nr(this.reasons)}},yi=new WeakMap,bi=class{[hi];annotations;_tag;constructor(e,t,n){if(this[hi]=hi,this._tag=e,t!==xi&&typeof n==`object`&&n&&t.size>0){let e=yi.get(n);e&&(t=new Map([...e,...t])),yi.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)}[qr](){return this.toString()}},xi=new Map,Si=class extends bi{constructor(e,t=xi){super(`Fail`,t,e),this.error=e}toString(){return`Fail(${D(this.error)})`}toJSON(){return{_tag:`Fail`,error:this.error}}[lr](e){return Oi(e)&&ur(this.error,e.error)&&ur(this.annotations,e.annotations)}[Kn](){return Jn(Qn(this._tag))(Jn(T(this.error))(T(this.annotations)))}},Ci=e=>new vi(e),wi=e=>new vi([new Si(e)]),Ti=class extends bi{constructor(e,t=xi){super(`Die`,t,e),this.defect=e}toString(){return`Die(${D(this.defect)})`}toJSON(){return{_tag:`Die`,defect:this.defect}}[lr](e){return ki(e)&&ur(this.defect,e.defect)&&ur(this.annotations,e.annotations)}[Kn](){return Jn(Qn(this._tag))(Jn(T(this.defect))(T(this.annotations)))}},Ei=e=>new vi([new Ti(e)]),Di=S(e=>gi(e[0]),(e,t,n)=>t.mapUnsafe.size===0?e:new vi(e.reasons.map(e=>e.annotate(t,n)))),Oi=e=>e._tag===`Fail`,ki=e=>e._tag===`Die`,Ai=e=>e._tag===`Interrupt`;function ji(e){return zi(`Effect.evaluate: Not implemented`)}var Mi=e=>({...di,[ai]:e.op,[k]:e[k]??ji,[oi]:e[oi],[si]:e[si],[ci]:e[ci]}),Ni=e=>{let t=Mi(e),n=function(e){this[O]=e};return n.prototype=t,function(e){return new n(e)}},Pi=e=>{let t={[ri]:ri,_tag:e.op,get[e.prop](){return this[O]},...Mi(e),toString(){return`${e.op}(${D(this[O])})`},toJSON(){return{_id:`Exit`,_tag:e.op,[e.prop]:this[O]}},[lr](e){return pi(e)&&e._tag===this._tag&&ur(this[O],e[O])},[Kn](){return Jn(Qn(e.op),T(this[O]))}},n=function(e){this[O]=e};return n.prototype=t,function(e){return new n(e)}},A=Pi({op:`Success`,prop:`value`,[k](e){let t=e.getCont(oi);return t?t[oi](this[O],e,this):e.yieldWith(this)}}),Fi={key:`effect/Cause/StackTrace`},Ii={key:`effect/Cause/InterruptorStackTrace`},Li=Pi({op:`Failure`,prop:`cause`,[k](e){let t=this[O],n=!1;e.cache.stackFrame&&(t=Di(t,{mapUnsafe:new Map([[Fi.key,e.cache.stackFrame]])}),n=!0);let r=e.getCont(si);for(;e.interruptible&&e._interruptedCause&&r;)r=e.getCont(si);return r?r[si](t,e,n?void 0:this):e.yieldWith(n?Li(t):this)}}),Ri=e=>Li(wi(e)),zi=e=>Li(Ei(e)),j=Ni({op:`WithFiber`,[k](e){return this[O](e)}}),Bi=function(){class e extends globalThis.Error{}let t=Mi({op:`YieldableError`,[k](){return Ri(this)}});return delete t.toString,Object.assign(e.prototype,t),e}(),Vi=function(){let e=Symbol.for(`effect/Data/Error/plainArgs`);return class extends Bi{constructor(t){super(t?.message,t?.cause?{cause:t.cause}:void 0),t&&(Mr(this,t),Object.defineProperty(this,e,{value:t,enumerable:!1}))}toJSON(){return{...this[e],...this}}}}(),Hi=e=>{class t extends Vi{_tag=e}return t.prototype.name=e,t},Ui=`~effect/Cause/Done`,Wi=e=>w(e,Ui),Gi={[Ui]:Ui,_tag:`Done`,value:void 0},Ki=e=>e===void 0?Gi:{[Ui]:Ui,_tag:`Done`,value:e},qi=Ri(Gi),Ji=e=>e===void 0?qi:Ri(Ki(e)),Yi=`~effect/Option`,Xi={[Yi]:{_A:e=>e},...ui,[Symbol.iterator](){return new ei(this)}},Zi=Object.defineProperty(Object.assign(Object.create(Xi),{_tag:`Some`,_op:`Some`,[lr](e){return ea(e)&&na(e)&&ur(this.value,e.value)},[Kn](){return Jn(T(this._tag))(T(this.value))},toString(){return`some(${D(this.value)})`},toJSON(){return{_id:`Option`,_tag:this._tag,value:Jr(this.value)}}}),"valueOrUndefined",{get(){return this.value}}),Qi=T(`None`),$i=Object.assign(Object.create(Xi),{_tag:`None`,_op:`None`,valueOrUndefined:void 0,[lr](e){return ea(e)&&ta(e)},[Kn](){return Qi},toString(){return`none()`},toJSON(){return{_id:`Option`,_tag:this._tag}}}),ea=e=>w(e,Yi),ta=e=>e._tag===`None`,na=e=>e._tag===`Some`,ra=Object.create($i),ia=function(e){this.value=e};ia.prototype=Zi;var aa=e=>new ia(e),oa=`~effect/Result`,sa={[oa]:{_A:e=>e,_E:e=>e},...ui,[Symbol.iterator](){return new ei(this)}},ca=Object.assign(Object.create(sa),{_tag:`Success`,_op:`Success`,[lr](e){return ua(e)&&fa(e)&&ur(this.success,e.success)},[Kn](){return Jn(T(this._tag))(T(this.success))},toString(){return`success(${D(this.success)})`},toJSON(){return{_id:`Result`,_tag:this._tag,value:Jr(this.success)}}}),la=Object.assign(Object.create(sa),{_tag:`Failure`,_op:`Failure`,[lr](e){return ua(e)&&da(e)&&ur(this.failure,e.failure)},[Kn](){return Jn(T(this._tag))(T(this.failure))},toString(){return`failure(${D(this.failure)})`},toJSON(){return{_id:`Result`,_tag:this._tag,failure:Jr(this.failure)}}}),ua=e=>w(e,oa),da=e=>e._tag===`Failure`,fa=e=>e._tag===`Success`,pa=function(e){this.failure=e};pa.prototype=la;var ma=e=>new pa(e),ha=function(e){this.success=e};ha.prototype=ca;var ga=e=>new ha(e);function _a(e){return(t,n)=>t===n?0:e(t,n)}var va=_a((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),ya=S(2,(e,t)=>_a((n,r)=>e(t(n),t(r)))),ba=e=>S(2,(t,n)=>e(t,n)===-1),xa=e=>S(2,(t,n)=>e(t,n)===1),Sa=e=>S(2,(t,n)=>e(t,n)!==1),Ca=e=>S(2,(t,n)=>e(t,n)!==-1),wa=()=>ra,Ta=aa,Ea=ta,Da=na,Oa=S(2,(e,{onNone:t,onSome:n})=>Ea(e)?t():n(e.value)),ka=S(2,(e,t)=>Ea(e)?t():e.value),Aa=e=>e==null?wa():Ta(e),ja=ka(En),Ma=e=>(...t)=>{try{return Ta(e(...t))}catch{return wa()}},Na=S(2,(e,t)=>Ea(e)?wa():Ta(t(e.value))),Pa=ga,Fa=ma,Ia=e=>{if(Ln(e))try{return Pa(e())}catch(e){return Fa(e)}try{return Pa(e.try())}catch(t){return Fa(e.catch(t))}},La=da,Ra=fa,za=S(2,(e,t)=>Ra(e)?Pa(t(e.success)):e),Ba=S(2,(e,{onFailure:t,onSuccess:n})=>La(e)?t(e.failure):n(e.success)),Va=S(2,(e,t)=>La(e)?t(e.failure):e.success)(En),Ha=kr,Ua=S(2,(e,t)=>Object.hasOwn(e,t)),Wa=S(2,(e,t)=>{let n={...e};for(let r of Ga(e))E(n,r,t(e[r],r));return n}),Ga=e=>Object.keys(e),Ka=e=>S(2,(t,n)=>{for(let r of Ga(t))if(!Ua(n,r)||!e(t[r],n[r]))return!1;return!0}),qa=e=>{let t=Ka(e);return(e,n)=>t(e,n)&&t(n,e)},Ja=globalThis.Array,Ya=e=>Ja.isArray(e)?e:Ja.from(e),Xa=e=>Ja.isArray(e)?e:[e],Za=S(2,(e,t)=>[...e,t]),Qa=S(2,(e,t)=>Ya(e).concat(Ya(t)));Ja.isArray;var $a=jr,eo=jr,to=()=>[],no=e=>[e],ro=S(2,(e,t)=>e.map(t)),io=Ar,ao=`~effect/BigDecimal`,oo={[ao]:ao,[Kn](){let e=ho(this);return Jn(T(e.value),Zn(e.scale))},[lr](e){return so(e)&&wo(this,e)},toString(){return`BigDecimal(${To(this)})`},toJSON(){return{_id:`BigDecimal`,value:String(this.value),scale:this.scale}},[qr](){return this.toJSON()},pipe(){return x(this,arguments)}},so=e=>w(e,ao),co=(e,t)=>{if(!Number.isSafeInteger(t))throw RangeError(`Scale must be a safe integer, got ${t}`);let n=Object.create(oo);return n.value=e,n.scale=t,n},lo=(e,t)=>{if(e!==uo&&e%po===uo)throw RangeError(`Value must be normalized`);let n=co(e,t);return n.normalized=n,n},uo=BigInt(0),fo=BigInt(1),po=BigInt(10),mo=lo(uo,0),ho=e=>{if(e.normalized===void 0){if(e.value===uo)e.normalized=mo;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=lo(BigInt(t.substring(0,t.length-n)),e.scale-n)}}return e.normalized},go=100,_o=[fo],vo=(e,t)=>e===t?0:e<t?-1:1,yo=(e,t)=>{let n=`${e.value<uo?-e.value:e.value}`,r=`${t.value<uo?-t.value:t.value}`,i=BigInt(n.length-r.length)-BigInt(e.scale)+BigInt(t.scale);if(i!==uo)return i<uo?-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},bo=(e,t)=>{if(e.scale===t.scale)return vo(e.value,t.value);let n=xo(e),r=xo(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>go)return n===-1?yo(t,e):yo(e,t);let o=_o[a]??=po**BigInt(a);return i>0?vo(e.value,t.value*o):vo(e.value*o,t.value)},xo=e=>e.value===uo?0:e.value<uo?-1:1,So=e=>e.value<uo?co(-e.value,e.scale):e,Co=Er((e,t)=>bo(e,t)===0),wo=S(2,(e,t)=>Co(e,t)),To=e=>{let t=ho(e);if(Math.abs(t.scale)>=16)return Eo(t);let n=t.value<uo,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},Eo=e=>{if(Do(e))return`0e+0`;let t=ho(e),n=`${So(t).value}`,r=n.slice(0,1),i=n.slice(1),a=`${Oo(t)?`-`:``}${r}`;i!==``&&(a+=`.${i}`);let o=i.length-t.scale;return`${a}e${o>=0?`+`:``}${o}`},Do=e=>e.value===uo,Oo=e=>e.value<uo,ko=e=>Mi({op:e.label,[k]:e.evaluate}),Ao=`~effect/Context/Service`,M=function(){function e(){}let t=e;Object.setPrototypeOf(t,jo);let n=(e,n)=>(t.key=e,n?.defaultValue&&(t[No]=No,t.defaultValue=n.defaultValue),n?.make&&(t.make=n.make),n?.fiberCached&&Mo.add(e),t);return arguments.length>0?n(arguments[0],arguments[1]):n},jo={[Ao]:Ao,...ko({label:`Service`,evaluate(e){return A(rs(e.context,this))}}),toJSON(){return{_id:`Service`,key:this.key}},of(e){return e},context(e){return Xo(this,e)},use(e){return j(t=>e(rs(t.context,this)))},useSync(e){return j(t=>A(e(rs(t.context,this))))}},Mo=new Set,No=`~effect/Context/Reference`,Po=`~effect/Context`,Fo=8,Io=8,Lo=(e,t,n,r)=>{let i=Object.create(Wo);return i.cacheRoot=e??i,i.base=t,i.overlay=n,i.depth=r,i._flat=void 0,i.baseHits=0,i},Ro=(e,t)=>{t&&(Ro(e,t.parent),e.set(t.key,t.value))},zo=e=>{if(e._flat)return e._flat;if(!e.overlay)return e._flat=e.base;let t=new Map(e.base);return Ro(t,e.overlay),e._flat=t},Bo=(e,t)=>{let n=new Map(e.mapUnsafe);return t(n),Uo(n)},Vo=Symbol(),Ho=(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)?Vo:(n.overlay&&++n.baseHits>=Io&&(n.base=zo(n),n.overlay=void 0,n.depth=0),r)},Uo=e=>Lo(void 0,e,void 0,0),Wo={get mapUnsafe(){return zo(this)},...ui,[Po]:{_Services:e=>e},toJSON(){return{_id:`Context`,services:Array.from(this.mapUnsafe).map(([e,t])=>({key:e,value:t}))}},[lr](e){if(!Ko(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)||!ur(r,n.get(e)))return!1;return!0},[Kn](){return Zn(this.mapUnsafe.size)}},Go=(e,t)=>e.cacheRoot===t.cacheRoot,Ko=e=>w(e,Po),qo=e=>!!e[No],Jo=()=>Yo,Yo=Uo(new Map),Xo=(e,t)=>Uo(new Map([[e.key,t]])),Zo=S(3,(e,t,n)=>Qo(e,t.key,n)),Qo=(e,t,n)=>{let r=e,i=Mo.has(t)?void 0:r.cacheRoot;if(r.depth>=Fo){let e=new Map(r.mapUnsafe);return e.set(t,n),Lo(i,e,void 0,0)}return Lo(i,r.base,{key:t,value:n,parent:r.overlay},r.depth+1)},$o=S(3,(e,t,n)=>{let r=Ho(e,t.key);return r===Vo?qo(t)?as(t):n():r}),es=S(2,(e,t)=>ts(e,t.key)),ts=(e,t)=>{let n=Ho(e,t);return n===Vo?void 0:n},ns=S(2,(e,t)=>{let n=Ho(e,t.key);if(n===Vo){if(qo(t))return as(t);throw os(t)}return n}),rs=ns,is=`~effect/Context/defaultValue`,as=e=>is in e?e[is]:e[is]=e.defaultValue(),os=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},ss=S(2,(e,t)=>{let n=Ho(e,t.key);return n===Vo?qo(t)?Ta(as(t)):wa():Ta(n)}),cs=S(2,(e,t)=>e.mapUnsafe.size===0?t:t.mapUnsafe.size===0?e:Bo(e,e=>t.mapUnsafe.forEach((t,n)=>e.set(n,t)))),ls=(...e)=>{let t=new Map;for(let n=0;n<e.length;n++)e[n].mapUnsafe.forEach((e,n)=>{t.set(n,e)});return Uo(t)},us=(...e)=>t=>Bo(t,t=>{for(let n=0;n<e.length;n++)t.delete(e[n].key)}),N=M,ds=`~effect/Duration`,fs=BigInt(0),ps=BigInt(1),ms=BigInt(2),hs=BigInt(10),gs=BigInt(1e3),_s=e=>BigInt(e<0?Math.ceil(e-.5):Math.floor(e+.5)),vs=e=>_s(e*1e6),ys=(e,t)=>{let n=e.indexOf(`.`);if(n===-1)return BigInt(e)*t;let r=e[0]===`-`,i=e.slice(n+1),a=hs**BigInt(i.length),o=(BigInt(e.slice(+!!r,n))*a+BigInt(i))*t,s=o/a+(o%a*ms>=a?ps:fs);return r?-s:s},bs=/^(-?\d+(?:\.\d+)?)\s+(nanos?|micros?|millis?|seconds?|minutes?|hours?|days?|weeks?)$/,xs=e=>{switch(typeof e){case`number`:return Ns(e);case`bigint`:return Ms(e);case`string`:{if(e===`Infinity`)return As;if(e===`-Infinity`)return js;let t=bs.exec(e);if(!t)break;let[n,r,i]=t;if(i===`nano`||i===`nanos`)return Ms(ys(r,ps));if(i===`micro`||i===`micros`)return Ms(ys(r,gs));let a=Number(r);switch(i){case`milli`:case`millis`:return Ns(a);case`second`:case`seconds`:return Ps(a);case`minute`:case`minutes`:return Fs(a);case`hour`:case`hours`:return Is(a);case`day`:case`days`:return Ls(a);case`week`:case`weeks`:return Rs(a)}break}case`object`:{if(e===null)break;if(ds in e)return e;if(Array.isArray(e))return e.length!==2||!e.every(Nn)?Ss(e):Number.isNaN(e[0])||Number.isNaN(e[1])?ks:e[0]===-1/0||e[1]===-1/0?js:e[0]===1/0||e[1]===1/0?As:Ds(_s(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?Ds(n):Ds(_s(n*1e6+(t.microseconds??0)*1e3+(t.nanoseconds??0)))}}return Ss(e)},Ss=e=>{throw Error(`Invalid Input: ${e}`)},Cs={_tag:`Millis`,millis:0},ws={_tag:`Infinity`},Ts={_tag:`NegativeInfinity`},Es={[ds]:ds,[Kn](){switch(this.value._tag){case`Millis`:{let e=this.value.millis*1e6;return Number.isFinite(e)?T(_s(e)):Zn(this.value.millis)}case`Nanos`:return T(this.value.nanos);default:return er(this.value)}},[lr](e){return Os(e)&&Ws(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`}}},[qr](){return this.toJSON()},pipe(){return x(this,arguments)}},Ds=e=>{let t=Object.create(Es);return t.value=typeof e==`number`?isNaN(e)||e===0||Object.is(e,-0)?Cs:Number.isFinite(e)?Number.isInteger(e)?{_tag:`Millis`,millis:e}:{_tag:`Nanos`,nanos:vs(e)}:e>0?ws:Ts:e===fs?Cs:{_tag:`Nanos`,nanos:e},t},Os=e=>w(e,ds),ks=Ds(0),As=Ds(1/0),js=Ds(-1/0),Ms=e=>Ds(e),Ns=e=>Ds(e),Ps=e=>Ds(e*1e3),Fs=e=>Ds(e*6e4),Is=e=>Ds(e*36e5),Ls=e=>Ds(e*864e5),Rs=e=>Ds(e*6048e5),zs=e=>Vs(xs(e),{onMillis:C,onNanos:e=>Number(e)/1e6,onInfinity:()=>1/0,onNegativeInfinity:()=>-1/0}),Bs=e=>{let t=xs(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 vs(t.value.millis)}},Vs=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)()}}),Hs=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(Bs(e),t.value.nanos):n.onNanos(e.value.nanos,Bs(t))),Us=(e,t)=>Hs(e,t,{onMillis:(e,t)=>e===t,onNanos:(e,t)=>e===t,onInfinity:(e,t)=>e.value._tag===t.value._tag}),Ws=S(2,(e,t)=>Us(e,t)),Gs=N(`effect/Scheduler`,{fiberCached:!0,defaultValue:()=>new Xs}),Ks=e=>{let t=!1;return Promise.resolve().then(()=>{t||e()}),()=>{t=!0}},qs=`setImmediate`in globalThis?e=>{let t=globalThis.setImmediate(e);return()=>globalThis.clearImmediate(t)}:e=>{let t=setTimeout(e,0);return()=>clearTimeout(t)},Js=e=>{try{return qs(e)}catch{return Ks(e)}},Ys=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}},Xs=class{executionMode;setImmediate;constructor(e=`async`,t){this.executionMode=e,this.setImmediate=t??(e===`sync`?Ks:Js)}shouldYield(e){return e.currentOpCount>=e.cache.maxOpsBeforeYield}makeDispatcher(){return new Zs(this.setImmediate)}},Zs=class{tasks=new Ys;running=void 0;setImmediate;constructor(e=Js){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()}},Qs=N(`effect/Scheduler/MaxOpsBeforeYield`,{fiberCached:!0,defaultValue:()=>2048}),$s=N(`effect/Scheduler/PreventSchedulerYield`,{fiberCached:!0,defaultValue:()=>!1}),ec=class extends Sn{constructor(e){super(),e&&Mr(this,e)}},tc=e=>class extends ec{_tag=e},nc=Hi,rc=`~effect/Encoding/EncodingError`,ic=class extends nc(`EncodingError`){[rc]=rc},ac=e=>gc(typeof e==`string`?pc.encode(e):e),oc=e=>{let t=hc(e),n=t.length;if(n%4!=0)return Fa(new ic({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 Fa(new ic({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=_c(t.charCodeAt(e))<<18|_c(t.charCodeAt(e+1))<<12|_c(t.charCodeAt(e+2))<<6|_c(t.charCodeAt(e+3));r[i]=n>>16,r[i+1]=n>>8&255,r[i+2]=n&255}return Pa(r)}catch(e){return Fa(new ic({kind:`Decode`,module:`Base64`,input:t,message:e instanceof Error?e.message:`Invalid input`}))}},sc=e=>za(oc(e),e=>mc.decode(e)),cc=e=>{switch(e){case 16:return dc();case 32:return fc();default:{let t=``;for(let n=e>>>3;n>0;n--)t+=uc();return t}}},P=Uint8Array.from(`0123456789abcdef`,e=>e.charCodeAt(0)),lc=()=>Math.random()*4294967296>>>0,uc=()=>{let e=lc();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])},dc=()=>{let e=lc(),t=lc();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])},fc=()=>{let e=lc(),t=lc(),n=lc(),r=lc();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])},pc=new TextEncoder,mc=new TextDecoder,hc=e=>e.replace(/[\n\r]/g,``),gc=e=>{let t=e.length,n=``,r=2;for(;r<t;r+=3)n+=vc[e[r-2]>>2],n+=vc[(e[r-2]&3)<<4|e[r-1]>>4],n+=vc[(e[r-1]&15)<<2|e[r]>>6],n+=vc[e[r]&63];return r===t+1&&(n+=vc[e[r-2]>>2],n+=vc[(e[r-2]&3)<<4],n+=`==`),r===t&&(n+=vc[e[r-2]>>2],n+=vc[(e[r-2]&3)<<4|e[r-1]>>4],n+=vc[(e[r-1]&15)<<2],n+=`=`),n};function _c(e){if(e>=yc.length)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);let t=yc[e];if(t===255)throw TypeError(`Invalid character ${String.fromCharCode(e)}`);return t}var vc=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`.split(``),yc=[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],bc=`effect/Tracer/ParentSpan`,xc=class extends M()(bc,{fiberCached:!0}){},Sc=e=>e,Cc=N(`effect/Tracer/DisablePropagation`,{defaultValue:Tn}),wc=N(`effect/Tracer/CurrentTraceLevel`,{defaultValue:()=>`Info`}),Tc=N(`effect/Tracer/MinimumTraceLevel`,{defaultValue:()=>`All`}),Ec=`effect/Tracer`,Dc=N(Ec,{fiberCached:!0,defaultValue:()=>Oc}),Oc=Sc({span:e=>new kc(e)}),kc=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??=ja(this.parent)?.traceId??cc(32)}get spanId(){return this._spanId??=cc(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)}},Ac=`effect/Metric/FiberRuntimeMetrics`,jc=N(`effect/ErrorReporter/CurrentErrorReporters`,{defaultValue:()=>new Set}),Mc=N(`effect/References/CurrentStackFrame`,{fiberCached:!0,defaultValue:En}),Nc=N(`effect/References/TracerEnabled`,{fiberCached:!0,defaultValue:wn}),Pc=N(`effect/References/TracerTimingEnabled`,{defaultValue:wn}),Fc=N(`effect/References/TracerSpanAnnotations`,{defaultValue:()=>({})}),Ic=N(`effect/References/TracerSpanLinks`,{defaultValue:()=>[]}),Lc=N(`effect/References/CurrentLogAnnotations`,{defaultValue:()=>({})}),Rc=N(`effect/References/CurrentLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),zc=N(`effect/References/MinimumLogLevel`,{fiberCached:!0,defaultValue:()=>`Info`}),Bc=e=>{if(e?.captureStackTrace===!1||e?.captureStackTrace!==void 0&&typeof e.captureStackTrace!=`boolean`)return e;let t=Qr();if(t===0&&e?.captureStackTrace!==!0)return{...e,captureStackTrace:!1};$r(3);let n=Error();return $r(t),{...e,captureStackTrace:Vc(()=>n.stack)}},Vc=(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),Hc=class extends bi{constructor(e,t=xi){super(`Interrupt`,t,`Interrupted`),this.fiberId=e}toString(){return`Interrupt(${this.fiberId})`}toJSON(){return{_tag:`Interrupt`,fiberId:this.fiberId}}[lr](e){return Ai(e)&&this.fiberId===e.fiberId&&this.annotations===e.annotations}[Kn](){return Jn(Qn(`${this._tag}:${this.fiberId}`))(qn(this.annotations))}},Uc=e=>new Hc(e),Wc=e=>new vi([new Hc(e)]),Gc=e=>{for(let t=0;t<e.reasons.length;t++){let n=e.reasons[t];if(n._tag===`Fail`)return Pa(n.error)}return Fa(e)},Kc=e=>e.reasons.some(ki),qc=e=>e.reasons.some(Ai),Jc=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?Pa(t):Fa(e)},Yc=(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=>ur(e,i)))continue;else t.push(i);r.push(i)}return r},Xc=S(2,(e,t)=>{if(e.reasons.length===0)return t;if(t.reasons.length===0)return e;let n=new vi(Yc(e.reasons,t.reasons));return ur(e,n)?e:n}),Zc=S(2,(e,t)=>{let n=!1,r=e.reasons.map(e=>Oi(e)?(n=!0,new Si(t(e.error),e.annotations)):e);return n?Ci(r):e}),Qc=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},$c=e=>{let t=Qc(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`)},el=`~effect/Fiber`,tl={_A:C,_E:C},nl={id:0},rl=()=>globalThis[Lr],il=class{constructor(e,t=!0){this[el]=tl,this.setContext(e),this.id=++nl.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)}[el];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 rs(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=Wc(e);this.cache.stackFrame&&(n=Di(n,Xo(Fi,this.cache.stackFrame))),t&&(n=Di(n,t)),this._interruptedCause=this._interruptedCause?Xc(this._interruptedCause,n):n,this.interruptible&&(this._running?this._deferredInterrupt=!0:this.evaluate(hl(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===li)return;let n=sl.interruptChildren&&sl.interruptChildren(this);if(n!==void 0)return this.evaluate(Zl(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=Jo()}runLoop(e){let t=globalThis[Lr];globalThis[Lr]=this;let n=this._running;this._running=!0;let r=!1,i=e;this.currentOpCount=0;try{for(;;){this._deferredInterrupt&&(this._deferredInterrupt=!1,i=hl(this._interruptedCause)),this.currentOpCount++;let e=this.cache;if(!r&&!e.preventYield&&e.scheduler.shouldYield(this)){r=!0;let e=i;i=Zl(vl,()=>e)}if(i=e.tracerContext?e.tracerContext(i,this):i[k](this),i===li){let e=this._yielded;if(ri in e)return this._deferredInterrupt=!1,this._yielded=void 0,e;if(this._deferredInterrupt){this._yielded=void 0,e();continue}return li}}}catch(e){return w(i,k)?this.runLoop(zi(e)):zi(`Fiber.runLoop: Not a valid effect: ${String(i)}`)}finally{this._running=n,globalThis[Lr]=t}}getCont(e){if(this._deferredInterrupt)return this._deferredInterrupt=!1,ol;for(;;){let t=this._stack.pop();if(!t)return;let n=t[ci];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,li}children(){return this._children??=new Set}pipe(){return x(this,arguments)}setContext(e){let t=this.context;if(this.context=e,t!==void 0&&Go(t,e))return;let n=e.cacheRoot,r=n._fiberCache??=al(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}},al=e=>{let t=ts(e,Ec);return{scheduler:rs(e,Gs),tracer:t,tracerContext:t?t.context:void 0,tracerEnabled:rs(e,Nc),span:ts(e,bc),logLevel:rs(e,Rc),minimumLogLevel:rs(e,zc),stackFrame:rs(e,Mc),runtimeMetrics:ts(e,Ac),maxOpsBeforeYield:rs(e,Qs),preventYield:rs(e,$s)}},ol={[oi](e,t){return hl(t._interruptedCause)},[si](e,t){return hl(t._interruptedCause)}},sl={interruptChildren:void 0},cl=e=>{if(!e.cache.stackFrame)return;let t=new Map;return t.set(Ii.key,e.cache.stackFrame),Uo(t)},ll=e=>{let t=e;return t._exit?F(t._exit):kl(n=>t._exit?n(F(t._exit)):I(e.addObserver(e=>n(F(e)))))},ul=e=>kl(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?.())}),dl=e=>{let t=e;return t._exit?t._exit:kl(n=>t._exit?n(t._exit):I(e.addObserver(n)))},fl=e=>j(t=>pl(e,t.id)),pl=S(e=>w(e[0],el),(e,t,n)=>j(r=>{let i=cl(r);return i=i&&n?cs(i,n):i??n,e.interruptUnsafe(t,i),Xl(ll(e))})),ml=e=>j(t=>{let n=cl(t),r=to();for(let i of e)i.interruptUnsafe(t.id,n),r.push(i);return Xl(ul(r))}),F=A,hl=Li,gl=Ri,I=Ni({op:`Sync`,[k](e){let t=this[O](),n=e.getCont(oi);return n?n[oi](t,e):e.yieldWith(A(t))}}),L=Ni({op:`Suspend`,[k](e){return this[O]()}}),_l=Ba({onFailure:gl,onSuccess:F}),vl=Ni({op:`Yield`,[k](e){let t=!1;return e.currentDispatcher.scheduleTask(()=>{t||e.evaluate(su)},this[O]??0),e.yieldWith(()=>{t=!0})}})(0),yl=F(wa()),bl=e=>L(()=>hl(ti(e))),xl=e=>zi(e),Sl=e=>L(()=>gl(ti(e))),R=F(void 0),Cl=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new lf(e,`An error occurred in Effect.try`):e.catch;return L(()=>{try{return F(ti(t))}catch(e){return gl(ti(()=>n(e)))}})},wl=e=>Dl(function(t,n){ti(()=>e(n)).then(e=>t(F(e)),e=>t(xl(e)))},e.length!==0),Tl=e=>{let t=typeof e==`function`?e:e.try,n=typeof e==`function`?e=>new lf(e,`An error occurred in Effect.tryPromise`):e.catch;return Dl(function(e,r){let i=t=>{try{e(gl(ti(()=>n(t))))}catch(t){e(xl(t))}};try{ti(()=>t(r)).then(t=>e(F(t)),i)}catch(e){i(e)}},t.length!==0)},El=e=>j(t=>e(t.id)),Dl=function(){let e=Mi({op:`Async`,[k](e){let t=ti(()=>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(Ol(()=>(n=!0,i?.abort(),a??su))),li):r}}),t=function(e,t){this.register=e,this.withSignal=t};return t.prototype=e,function(e,n){return new t(e,n)}}(),Ol=Ni({op:`AsyncFinalizer`,[ci](e){e.interruptible&&(e.interruptible=!1,e._stack.push(fd))},[si](e,t){return qc(e)?Zl(this[O](),()=>hl(e)):hl(e)}}),kl=e=>Dl(e,e.length>=2),Al=kl(Dn),jl=(...e)=>{if(e.length===1){let t=e[0];return L(()=>Il(t()))}let[t,n]=e;return L(()=>Il(n.call(t.self)))},Ml=(e,...t)=>{let n=t.length===0?function(){return L(()=>Il(e.apply(this,arguments)))}:function(){let n=L(()=>Il(e.apply(this,arguments)));for(let e=0;e<t.length;e++)n=t[e](n,...arguments);return n};return Nl(e.length,n)},Nl=(e,t)=>Object.defineProperty(t,"length",{value:e,configurable:!0}),Pl=(e,...t)=>Nl(e.length,t.length===0?function(){return Fl(()=>e.apply(this,arguments))}:function(){let n=Fl(()=>e.apply(this,arguments));for(let e of t)n=e(n,...arguments);return n}),Fl=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,Zl(r.value,e=>Il(t,e))):L(()=>Il(e())))}}}catch(e){return xl(e)}},Il=function(){let e=Mi({op:`Iterator`,[oi](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[oi](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)}}(),Ll=S(2,(e,t)=>new Vl(e,Hl,F(t))),Rl=function(e){return e._stack.push(this),this[O]},zl=Mi({op:`OnSuccess`,[k]:Rl}),Bl=function(e,t){this[O]=e,this[oi]=t};Bl.prototype=zl;var Vl=function(e,t,n){this[O]=e,this[oi]=t,this.payload=n};Vl.prototype=zl;var Hl=function(){return this.payload},Ul=function(e){let t=this.payload;return F(ti(()=>t(e)))},Wl=function(e){let t=this.payload;return ti(()=>t(e))},Gl=function(e){let t=this.payload;return new Vl(ti(()=>t(e)),Hl,A(e))},Kl=function(e){return new Vl(this.payload,Hl,A(e))},ql=e=>eu(e,Ta),Jl=S(2,(e,t)=>new Vl(e,fi(t)?Hl:Wl,t)),Yl=S(2,(e,t)=>new Vl(e,fi(t)?Kl:Gl,t)),Xl=e=>new Vl(e,Hl,su),Zl=S(2,(e,t)=>new Bl(e,t.length===1?t:e=>t(e))),z=e=>e[ri]!==void 0,Ql=S(2,(e,t)=>z(e)?e._tag===`Success`?t(e.value):e:Zl(e,t)),$l=e=>Zl(e,C),eu=S(2,(e,t)=>new Vl(e,Ul,t)),tu=S(2,(e,t)=>z(e)?cu(e,t):eu(e,t)),nu=S(2,(e,t)=>z(e)?lu(e,t):ku(e,t)),ru=S(2,(e,t)=>z(e)?uu(e,t):Au(e,t)),iu=e=>Li(Wc(e)),au=e=>e._tag===`Success`,ou=e=>e._tag===`Failure`?Pa(e.cause):Fa(e),su=A(void 0),cu=S(2,(e,t)=>e._tag===`Success`?A(t(e.value)):e),lu=S(2,(e,t)=>{if(e._tag===`Success`)return e;let n=Gc(e.cause);return La(n)?e:Ri(t(n.success))}),uu=S(2,(e,t)=>{if(e._tag===`Success`)return A(t.onSuccess(e.value));let n=Gc(e.cause);return La(n)?e:Ri(t.onFailure(n.success))}),du=S(2,(e,t)=>au(e)?t:e),fu=e=>{let t=[];for(let n of e)n._tag===`Failure`&&t.push(...n.cause.reasons);return t.length===0?su:Li(Ci(t))},pu=S(2,(e,t)=>j(n=>{let r=n.context,i=t(r);return r===i?e:(n.setContext(i),rd(e,()=>{n.setContext(r)}))})),mu=S(3,(e,t,n)=>pu(e,e=>{let r=ns(e,t),i=n(r);return r===i?e:Zo(e,t,i)})),hu=()=>gu,gu=j(e=>F(e.context)),_u=e=>j(t=>e(t.context)),vu=S(2,(e,t)=>z(e)?e:pu(e,cs(t))),yu=function(){return arguments.length===1?S(2,(e,t)=>bu(e,arguments[0],t)):S(3,(e,t,n)=>bu(e,t,n)).apply(this,arguments)},bu=(e,t,n)=>pu(e,Zo(t,n)),xu=S(e=>fi(e[0]),(e,t)=>vd({while:wn,body:Cn(t?.disableYield?e:Zl(e,e=>vl)),step:Dn})),Su=S(2,(e,t)=>new wu(e,t.length===1?t:e=>t(e))),Cu=Mi({op:`OnFailure`,[k]:Rl}),wu=function(e,t){this[O]=e,this[si]=t};wu.prototype=Cu;var Tu=S(3,(e,t,n)=>Su(e,e=>{let r=t(e);return La(r)?hl(r.failure):ti(()=>n(r.success,e))})),Eu=S(2,(e,t)=>Tu(e,Gc,e=>t(e))),Du=S(e=>fi(e[0]),(e,t,n,r)=>Su(e,e=>{let i=Gc(e);return La(i)?hl(i.failure):t(i.success)?ti(()=>n(i.success)):r?ti(()=>r(i.success)):hl(e)})),Ou=S(e=>fi(e[0]),(e,t,n,r)=>Du(e,Array.isArray(t)?e=>w(e,`_tag`)&&t.includes(e._tag):Un(t),n,r)),ku=S(2,(e,t)=>Eu(e,e=>Sl(()=>t(e)))),Au=S(2,(e,t)=>Iu(e,{onFailure:e=>Sl(()=>t.onFailure(e)),onSuccess:e=>I(()=>t.onSuccess(e))})),ju=e=>Eu(e,xl),Mu=e=>Ru(e,{onFailure:Fa,onSuccess:Pa}),Nu=S(2,(e,t)=>new Fu(e,t.onSuccess.length===1?t.onSuccess:e=>t.onSuccess(e),t.onFailure.length===1?t.onFailure:e=>t.onFailure(e))),Pu=Mi({op:`OnSuccessAndFailure`,[k]:Rl}),Fu=function(e,t,n){this[O]=e,this[oi]=t,this[si]=n};Fu.prototype=Pu;var Iu=S(2,(e,t)=>Nu(e,{onFailure:e=>{let n=e.reasons.find(Oi);return n?ti(()=>t.onFailure(n.error)):hl(e)},onSuccess:t.onSuccess})),Lu=S(2,(e,t)=>Iu(e,{onFailure:e=>I(()=>t.onFailure(e)),onSuccess:e=>I(()=>t.onSuccess(e))})),Ru=S(2,(e,t)=>{if(z(e)){if(e._tag===`Success`)return A(t.onSuccess(e.value));let n=Gc(e.cause);return La(n)?e:A(t.onFailure(n.success))}return Lu(e,t)}),zu=e=>z(e)?A(e):Bu(e),Bu=Ni({op:`Exit`,[k](e){return e._stack.push(this),this[O]},[oi](e,t,n){return F(n??A(e))},[si](e,t,n){return F(n??Li(e))}}),Vu=`~effect/Scope`,Hu=`~effect/Scope/Closeable`,Uu=M(`effect/Scope`),Wu=(e,t)=>L(()=>Gu(e,t)??R),Gu=(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):qu(e,i,t)},Ku=(e,t)=>au(e)?t:Su(t,t=>hl(Xc(e.cause,t))),qu=Ml(function*(e,t,n){let r=[],i=[],a=Array.from(t.values()),o=rl();for(let t=a.length-1;t>=0;t--){let s=a[t];e.strategy===`sequential`?r.push(yield*zu(s(n))):i.push(Ed(o,s(n),!0,!0,`inherit`))}return i.length>0&&(r=yield*ul(i)),yield*fu(r)}),Ju=(e,t)=>{let n=$u(t);if(e.state._tag===`Closed`)return n.state=e.state,n;let r={};return Zu(e,r,e=>Wu(n,e)),Zu(n,r,t=>I(()=>Qu(e,r))),n},Yu=(e,t)=>L(()=>e.state._tag===`Closed`?t(e.state.exit):(Zu(e,{},t),R)),Xu=(e,t)=>Yu(e,Cn(t)),Zu=(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))}},Qu=(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)}},$u=(e=`sequential`)=>({[Hu]:Hu,[Vu]:Vu,strategy:e,state:ed}),ed={_tag:`Empty`},td=yu(Uu),nd=e=>L(()=>{let t=$u();return id(e(t),e=>L(()=>Gu(t,e)??R))}),rd=function(){let e=Mi({op:`OnExit`,[k](e){return e._stack.push(this),this.effect},[ci](e){e.interruptible&&this.interruptible!==!0&&(e._stack.push(fd),e.interruptible=!1)},[oi](e,t,n){n??=A(e);let r=this.onExit(n);return r?Zl(r,e=>n):n},[si](e,t,n){n??=Li(e);let r=this.onExit(n);return r?Zl(Ku(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)}}(),id=S(2,rd),ad=S(3,(e,t,n)=>id(e,e=>{let r=t(e);return La(r)?R:n(r.success,e)})),od=S(2,(e,t)=>ad(e,ou,t)),sd=S(3,(e,t,n)=>id(e,e=>{if(e._tag!==`Failure`)return R;let r=t(e.cause);return La(r)?R:n(r.success,e.cause)})),cd=S(2,(e,t)=>sd(Jc,t)(e)),ld=e=>I(()=>{let t=zd(!1),n=!1,r,i=Zl(t.await,()=>r);return L(()=>r===void 0?n?i:(n=!0,id(e,e=>I(()=>{r=e,t.openUnsafe()}))):r)}),ud=e=>j(t=>t.interruptible?(t.interruptible=!1,t._stack.push(fd),e):e),dd=Ni({op:`SetInterruptible`,[ci](e){if(e.interruptible=this[O],e._interruptedCause&&e.interruptible)return()=>hl(e._interruptedCause)}}),fd=dd(!0),pd=dd(!1),md=e=>{if(e.interruptible=!0,e._stack.push(pd),e._interruptedCause)return hl(e._interruptedCause)},hd=e=>j(t=>t.interruptible?e:md(t)??e),gd=e=>j(t=>t.interruptible?(t.interruptible=!1,t._stack.push(fd),e(hd)):e(C)),_d=(e,t)=>Gn(e)?t?.mode===`result`?yd(e,Mu,t):yd(e,C,t):t?.discard?t.mode===`result`?yd(Object.values(e),Mu,t):yd(Object.values(e),C,t):L(()=>{let n={};return Ll(yd(Object.entries(e),([e,r])=>eu(t?.mode===`result`?Mu(r):r,t=>{E(n,e,t)}),{discard:!0,concurrency:t?.concurrency}),n)}),vd=Ni({op:`While`,[oi](e,t){return this[O].step(e),this[O].while()?(t._stack.push(this),this[O].body()):su},[k](e){return this[O].while()?(e._stack.push(this),this[O].body()):su}}),yd=S(e=>typeof e[1]==`function`,(e,t,n)=>L(()=>{let r=xd(n?.concurrency);if(r===1)return bd(e,t,n);let i=Ya(e),a=i.length;if(a===0)return n?.discard?R:F([]);let o=n?.discard?void 0:Array(a),s=Td({f:t,out:o},i,{concurrency:r});return s?Ll(s,o):F(o)})),bd=(e,t,n)=>L(()=>{let r=n?.discard?void 0:[],i=e[Symbol.iterator](),a=i.next(),o=0;return Ll(vd({while:()=>!a.done,body:()=>t(a.value,o++),step:e=>{r&&r.push(e),a=i.next()}}),r)}),xd=e=>e===`unbounded`?1/0:Math.max(1,e??1),Sd=()=>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 Zl(zu(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},Cd=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=zi(e);return p=t,c=!0,f=!0,u&&u.size>0?Zl(ud(ml(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=Ed(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=Li(Ci([e]))}else{let t=n(e,o,a,r);t&&(p=t._tag===`Failure`?Li(Ci(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 kl(e=>{l=rl(),u=new Set,m=_,d=e;let t;try{t=g()}catch(t){return e(h(t))}return t?e(t):L(()=>(p=su,f=!0,u?ml(u):R))})}if(c=!0,p){if(u&&u.size>0){let e=cl(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 su}};return g()}},wd=()=>e=>Cd(e),Td=Cd({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)}}),Ed=(e,t,n=!1,r=!1,i=!1)=>{let a=e,o=i===`inherit`?a.interruptible:!i,s=new il(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},Dd=S(e=>fi(e[0]),(e,t,n)=>j(r=>{let i=Ed(r,e,n?.startImmediately,!0,n?.uninterruptible);if(!i._exit){if(t.state._tag!==`Closed`){let e={};Zu(t,e,()=>El(e=>e===i.id?R:fl(i))),i.addObserver(()=>Qu(t,e))}else i.interruptUnsafe(r.id,cl(r))}return F(i)})),Od=e=>(t,n)=>{let r=new il(n?.scheduler?Zo(e,Gs,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},kd=S(2,(e,t)=>{if(e._exit)return e;if(t.state._tag===`Closed`)return e.interruptUnsafe(e.id),e;let n={};return Zu(t,n,()=>fl(e)),e.addObserver(()=>Qu(t,n)),e}),Ad=Od(Jo()),jd=e=>{let t=Od(e);return(e,n)=>{let r=t(e,n);return new Promise(e=>{r.addObserver(t=>e(t))})}},Md=(e=>{let t=jd(e);return(e,n)=>t(e,n).then(e=>{if(e._tag===`Failure`)throw $c(e.cause);return e.value})})(Jo()),Nd=e=>{let t=Od(e);return e=>{if(z(e))return e;let n=new Xs(`sync`),r=t(e,{scheduler:n});return r._dispatcher?.flush(),r._exit??zi(new sf(r))}},Pd=Nd(Jo()),Fd=(e=>{let t=Nd(e);return e=>{let n=t(e);if(n._tag===`Failure`)throw $c(n.cause);return n.value}})(Jo()),Id=F(!0),Ld=F(!1),Rd=class{waiters=[];scheduled=void 0;_isOpen;constructor(e){this._isOpen=e}scheduleUnsafe(e){if(this.waiters.length===0)return Id;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=[],Id}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](su)};flushWaiters(){let e=this.waiters;this.waiters=[],this.flushScheduled();for(let t=0;t<e.length;t++)e[t](su)}open=j(e=>this._isOpen?Ld:(this._isOpen=!0,this.scheduleUnsafe(e)));release=j(e=>this._isOpen?Ld:this.scheduleUnsafe(e));openUnsafe(){return!this._isOpen&&(this._isOpen=!0,this.flushWaiters(),!0)}await=kl(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=>Zl(this.await,()=>e);isOpen(){return this._isOpen}},zd=e=>new Rd(e??!1),Bd=BigInt(0),Vd={_tag:`Span`,spanId:`noop`,traceId:`noop`,sampled:!1,status:{_tag:`Ended`,startTime:Bd,endTime:Bd,exit:su},attributes:new Map,links:[],kind:`internal`,attribute(){},event(){},end(){},addLinks(){}},Hd=e=>Object.assign(Object.create(Vd),e),Ud=e=>e?rs(e.annotations,Cc)?e._tag===`Span`?Ud(ja(e.parent)):wa():Ta(e):wa(),Wd=(e,t,n)=>{let r=!e.getRef(Nc)||n?.annotations&&rs(n.annotations,Cc),i=n?.parent===void 0?n?.root?wa():Ud(e.cache.span):Ta(n.parent),a;if(r)a=Hd({name:t,parent:i,annotations:Zo(n?.annotations??Jo(),Cc,!0)});else{let r=e.getRef(Dc),o=e.getRef(Zd),s=e.getRef(Pc),c=e.getRef(Fc),l=e.getRef(Ic),u=n?.level??e.getRef(wc),d=n?.links===void 0?l.length===0?[]:l.slice():[...l,...n.links];a=r.span({name:t,parent:i,annotations:n?.annotations??Jo(),links:d,startTime:s?o.currentTimeNanosUnsafe():Bd,kind:n?.kind??`internal`,root:n?.root??Ea(i),sampled:n?.sampled??(Da(i)&&i.value.sampled===!1?!1:!uf(e.getRef(Tc),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},Gd=(e,t)=>(t=typeof t==`function`?t:En,mu(Mc,n=>({name:e,stack:t,parent:n}))),Kd=(e,t,n,r)=>I(()=>{e.status._tag!==`Ended`&&e.end(r?n.currentTimeNanosUnsafe():Bd,t)}),qd=(e,...t)=>{let n=t.length===1?void 0:t[0],r=t[t.length-1];return j(t=>{let i=Wd(t,e,n),a=t.getRef(Zd),o=t.getRef(Pc);return id(L(()=>ti(()=>r(i))),e=>Kd(i,e,a,o))})},Jd=yu(xc),Yd=function(){let e=fi(arguments[0]),t=e?arguments[1]:arguments[0],n=e?arguments[2]:arguments[1],r=C;return t._tag===`Span`&&(n=Bc(n),r=Gd(t.name,n?.captureStackTrace)),e?Jd(r(arguments[0]),t):e=>Jd(r(e),t)},Xd=function(){let e=typeof arguments[0]!=`string`,t=e?arguments[1]:arguments[0],n=Bc(arguments[2]);if(e){let e=arguments[0];return qd(t,arguments[2],t=>Yd(e,t,n))}let r=typeof arguments[1]==`function`?arguments[1]:void 0,i=r?void 0:arguments[1];return(e,...a)=>qd(t,r?r(...a):i,t=>Yd(e,t,n))},Zd=N(`effect/Clock`,{defaultValue:()=>new $d}),Qd=2**31-1,$d=class{currentTimeMillisUnsafe(){return Date.now()}currentTimeMillis=I(()=>this.currentTimeMillisUnsafe());currentTimeNanosUnsafe(){return nf()}currentTimeNanos=I(()=>this.currentTimeNanosUnsafe());monotonicTimeNanosUnsafe(){return tf()}monotonicTimeNanos=I(()=>this.monotonicTimeNanosUnsafe());sleep(e){return this.sleepMillis(zs(e))}sleepMillis(e){return e<=0?vl:Number.isFinite(e)?kl(t=>{let n=e>Qd?this.sleepMillis(e-Qd):R,r=setTimeout(()=>t(n),Math.min(e,Qd));return I(()=>clearTimeout(r))}):Al}},ef=BigInt(1e6),tf=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())*ef;return e>t&&(t=e),t}}(),nf=function(){let e=BigInt(1e9),t;return()=>{let n=tf(),r=BigInt(Date.now())*ef;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}}(),rf=`~effect/Cause/IllegalArgumentError`,af=class extends Hi(`IllegalArgumentError`){[rf]=rf;constructor(e){super({message:e})}},of=`~effect/Cause/AsyncFiberError`,sf=class extends Hi(`AsyncFiberError`){[of]=of;constructor(e){super({message:`An asynchronous Effect was executed with Effect.runSync`,fiber:e})}},cf=`~effect/Cause/UnknownError`,lf=class extends Hi(`UnknownError`){[cf]=cf;constructor(e,t){super({message:t,cause:e})}},uf=xa(ya(va,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}})),df={bold:`1`,red:`31`,green:`32`,yellow:`33`,blue:`34`,cyan:`36`,white:`37`,gray:`90`,black:`30`,bgBrightRed:`101`};df.gray,df.blue,df.green,df.yellow,df.red,df.bgBrightRed,df.black;var ff=S(e=>fi(e[0]),(e,t)=>od(e,e=>j(n=>(pf(n,e,t?.defectsOnly),R)))),pf=(e,t,n)=>{let r=e.getRef(jc);if(r.size===0||n&&!Kc(t))return;let i={cause:t,fiber:e,timestamp:e.getRef(Zd).currentTimeNanosUnsafe()};r.forEach(e=>e.report(i))},mf=gi,hf=_i,gf=Oi,_f=Ci,vf=wi,yf=Ei,bf=e=>new Si(e),xf=e=>new Ti(e),Sf=Uc,Cf=Zc,wf=Xc,Tf=$c,Ef=qc,Df=Wi,Of=Ji,kf=af,Af=A,jf=Li,Mf=Ri,Nf=su,Pf=au,Ff={"~effect/Deferred":{_A:C,_E:C},pipe(){return x(this,arguments)}},If=function(){this.resumes=void 0,this.effect=void 0};If.prototype=Ff;var Lf=()=>new If,Rf=e=>kl(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)}))),zf=S(2,(e,t)=>I(()=>Bf(e,t))),Bf=(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},Vf=Lc,Hf=Uu,Uf=$u,Wf=td,Gf=Yu,Kf=Xu,qf=Ju,Jf=Wu,Yf=`~effect/Layer`,Xf=`~effect/Layer/MemoMap`,Zf=(e,t)=>(e.observers++,Jl(Yu(t,t=>e.finalizer(t)),e.effect)),Qf={[Yf]:{_ROut:C,_E:C,_RIn:C},pipe(){return x(this,arguments)}},$f=e=>{let t=Object.create(Qf);return t.build=e,t},ep=e=>$f((t,n)=>{let r=qf(n);return id(e(t,r),e=>e._tag===`Failure`?Jf(r,e):R)}),tp=e=>{let t=ep((n,r)=>n.getOrElseMemoize(t,r,e));return t},np=(e,t,n,r)=>{let i=Uf(),a=Lf(),o={observers:1,effect:Rf(a),finalizer:n=>L(()=>(o.observers--,o.observers===0?(e.map.delete(t),Jf(i,n)):R))};return e.map.set(t,o),Yu(n,o.finalizer).pipe(Zl(()=>r(e,i)),id(e=>(o.effect=e,zf(a,e))))},rp=class{get[Xf](){return Xf}parent;constructor(e){this.parent=e}map=new Map;get(e,t){let n=this.map.get(e);return n?Zf(n,t):this.parent?.get(e,t)}getOrElseMemoize(e,t,n){return L(()=>this.get(e,t)||np(this,e,t,n))}},ip=()=>new rp,ap=e=>new rp(e),op=class e extends M()(`effect/Layer/CurrentMemoMap`){static forkOrCreate(t){let n=es(t,e);return n?ap(n):ip()}},sp=S(3,(e,t,n)=>yu(eu(e.build(t,n),Zo(op,t)),op,t)),cp=S(2,(e,t)=>j(n=>sp(e,op.forkOrCreate(n.context),t))),lp=function(){return arguments.length===1?e=>up(Xo(arguments[0],e)):up(Xo(arguments[0],arguments[1]))},up=e=>$f(Cn(F(e))),dp=up(Jo()),fp=function(){return arguments.length===1?e=>pp(arguments[0],e):pp(arguments[0],arguments[1])},pp=(e,t)=>mp(eu(t,t=>Xo(e,t))),mp=e=>tp((t,n)=>Wf(e,n)),hp=e=>mp(Ll(e,Jo())),gp=M(`effect/Layer/unwrap`),_p=e=>Cp(fp(gp)(e),rs(gp)),vp=(e,t,n)=>{let r=qf(n,`parallel`);return yd(e,e=>e.build(t,qf(r,`sequential`)),{concurrency:e.length}).pipe(eu(e=>ls(...e)))},yp=(...e)=>ep((t,n)=>vp(e,t,n)),bp=(e,t,n)=>ep((r,i)=>Zl(Array.isArray(t)?vp(t,r,i):t.build(r,i),t=>e.build(r,i).pipe(vu(t),eu(e=>n(e,t))))),xp=S(2,(e,t)=>bp(e,t,C)),Sp=S(2,(e,t)=>bp(e,t,(e,t)=>cs(t,e))),Cp=S(2,(e,t)=>ep((n,r)=>Zl(e.build(n,r),e=>t(e).build(n,r)))),wp=`~effect/DateTime`,Tp=`~effect/DateTime/TimeZone`,Ep={[wp]:wp,pipe(){return x(this,arguments)},[qr](){return this.toString()},toJSON(){return Rp(this).toJSON()}},Dp={...Ep,_tag:`Utc`,[Kn](){return Zn(this.epochMilliseconds)},[lr](e){return kp(e)&&e._tag===`Utc`&&this.epochMilliseconds===e.epochMilliseconds},toString(){return`DateTime.Utc(${Rp(this).toJSON()})`}};({...Ep});var Op={[Tp]:Tp,[qr](){return this.toString()}};({...Op}),{...Op};var kp=e=>w(e,wp),Ap=e=>kp(e[0]),jp=e=>e._tag===`Utc`,Mp=e=>{let t=Object.create(Dp);return t.epochMilliseconds=e,Object.defineProperty(t,"partsUtc",{value:void 0,enumerable:!1,writable:!0}),t},Np=e=>{let t=e.getTime();if(Number.isNaN(t))throw new kf(`Invalid date`);return Mp(t)},Pp=e=>{if(kp(e))return e;if(e instanceof Date)return Np(e);if(typeof e==`object`){if(`epochMilliseconds`in e)return Np(new Date(e.epochMilliseconds));let t=new Date(0);return zp(t,e),Np(t)}return typeof e==`string`&&!Fp(e)?Np(new Date(e+`Z`)):Np(new Date(e))},Fp=e=>/Z|GMT|[+-]\d{2}$|[+-]\d{2}:?\d{2}$|\]$/.test(e),Ip=Ma(Pp),Lp=e=>Mp(e.epochMilliseconds),Rp=e=>new Date(e.epochMilliseconds),zp=(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)},Bp=S(Ap,(e,t)=>new Intl.DateTimeFormat(t?.locale,t).format(e.epochMilliseconds)),Vp=e=>Rp(e).toISOString(),Hp=S(2,(e,t)=>Tu(e,Kp,e=>t(e))),Up=e=>e.reasons.some(Wp),Wp=e=>e._tag===`Fail`&&Df(e.error),Gp=e=>{let t,n=!1;for(let r of e.reasons)Wp(r)?t??=r.error:r._tag!==`Interrupt`&&(n=!0);return t===void 0?Fa(e):n?Fa(_f(e.reasons.filter(e=>!Wp(e)))):Pa(t)},Kp=e=>{let t=Gp(e);return La(t)?t:Pa(t.success.value)},qp=e=>{let t=Gp(e);return La(t)?jf(t.failure):Af(t.success.value)},Jp=(e,t,n)=>nd(r=>Zl(n?.local?sp(t,ip(),r):cp(t,r),t=>vu(e,t))),Yp=S(e=>fi(e[0]),(e,t,n)=>Ko(t)?vu(e,t):Jp(e,Array.isArray(t)?yp(...t):t,n)),Xp=fi,Zp=_d,Qp=wl,$p=Tl,B=F,em=L,tm=I,nm=R,rm=jl,V=gl,im=hl,am=bl,om=xl,sm=Cl,cm=j,lm=_l,H=Zl,um=$l,dm=Jl,fm=Yl,pm=Mu,mm=zu,U=eu,hm=Ll,gm=Xl,_m=Eu,vm=Ou,ym=Su,bm=ku,xm=ju,Sm=ff,Cm=Lu,wm=Nu,Tm=hu,Em=_u,Dm=Yp,Om=vu,km=pu,Am=od,jm=id,Mm=ld,Nm=cd,Pm=gd,Fm=xu,Im=qd,Lm=Xd,Rm=Yd,zm=Dd,Bm=Ad,Vm=Od,Hm=Md,Um=Fd,Wm=Pd,Gm=Ml,Km=S(e=>Xp(e[0]),(e,...t)=>mu(e,Vf,e=>{let n=t.length===1?{...e,...t[0]}:{...e};return t.length===1||E(n,t[0],t[1]),n})),qm=tu,Jm=nu,Ym=ru,Xm=Ql,Zm=Pl;function Qm(e){return e.checks?e.checks[e.checks.length-1].annotations:e.annotations}function $m(e){return t=>Qm(t)?.[e]}var eh=`~structural`,th=`~identifier`,nh=`~sentinels`,rh=`~constructor`,ih=[`title`,`description`,`default`,`examples`,`readOnly`,`writeOnly`,`format`,`contentEncoding`,`contentMediaType`,`contentSchema`],ah=$m(`identifier`),oh=$m(th),sh=$m(`description`),ch=On(e=>{let t=Qm(e)?.identifier;return typeof t==`string`?t:e.getExpected(ch)}),lh=new Set([nh,eh,`representation`,`arbitraryConstraint`,`brands`,`toJsonSchema`,`toCode`,`toEquivalence`,`toFormatter`,`toCodec`,`toCodecJson`,`toCodecStringTree`,`toCodecIso`,`toCodecArbitrary`]),W=Symbol(),uh=Af,dh=uh(W),G=uh(W),fh=e=>e===W?wa():Ta(e),ph=e=>e._tag===`None`?dh:uh(e.value),mh=`~effect/SchemaIssue/Issue`;function hh(e){return w(e,mh)&&e[mh]===mh}function gh(e){return Object.hasOwn(e,`input`)}var _h=class{[mh]=mh;constructor(e,t){t?.reportInput===!0&&e!==W&&(this.input=e)}},vh=class extends _h{_tag=`Filter`;filter;issue;constructor(e,t,n,r){super(n,r),this.filter=e,this.issue=t}},yh=class extends _h{_tag=`Encoding`;ast;issue;constructor(e,t,n,r){super(n,r),this.ast=e,this.issue=t}},bh=class extends _h{_tag=`Pointer`;path;issue;constructor(e,t){super(),this.path=e,this.issue=t}},xh=class extends _h{_tag=`MissingKey`;annotations;constructor(e){super(),this.annotations=e}},Sh=class extends _h{_tag=`UnexpectedKey`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Ch=class extends _h{_tag=`Composite`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},wh=class extends _h{_tag=`InvalidType`;ast;constructor(e,t,n){super(t,n),this.ast=e}},Th=class extends _h{_tag=`InvalidValue`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}};function Eh(e,t,n,r,i){return new Ch(e,[new bh([t],n)],r,i)}var Dh=class extends _h{_tag=`Forbidden`;annotations;constructor(e,t,n){super(t,n),this.annotations=e}},Oh=class extends _h{_tag=`AnyOf`;ast;issues;constructor(e,t,n,r){super(n,r),this.ast=e,this.issues=t}},kh=class extends _h{_tag=`OneOf`;ast;successes;constructor(e,t,n,r){super(n,r),this.ast=e,this.successes=t}};function Ah(e,t,n){if(hh(e))return e;if(typeof e==`string`)return new Th({message:e},t,n);let r=typeof e.issue==`string`?new Th({message:e.issue},t,n):e.issue;return new bh(e.path,r)}function jh(e,t,n){if(e!==void 0)return typeof e==`boolean`?e?void 0:new Th(void 0,t,n):Ah(e,t,n)}function Mh(e,t,n,r){return Array.isArray(t)?eo(t)?t.length===1?Ah(t[0],n,r):new Ch(e,ro(t,e=>Ah(e,n,r)),n,r):void 0:jh(t,n,r)}var Nh=e=>{let t=Hh(e);if(t!==void 0)return t;switch(e._tag){case`InvalidType`:return Lh(ch(e.ast),e);case`InvalidValue`:{let t=Ih(e);if(t!==void 0)return Lh(t,e);let n=Fh(e);return n===void 0?`Expected a valid value`:`Invalid data ${n}`}case`MissingKey`:return`Missing key`;case`UnexpectedKey`:{let t=Fh(e);return t===void 0?`Expected no excess property`:`Unexpected key with value ${t}`}case`Forbidden`:return`Forbidden operation`;case`OneOf`:{let t=Fh(e);return t===void 0?`Expected exactly one member to match`:`Expected exactly one member to match the input ${t}`}}},Ph=e=>Hh(e.issue)??Hh(e);function Fh(e){return gh(e)?D(e.input):void 0}function Ih(e){let t=e.annotations?.expected;return typeof t==`string`?t:void 0}function Lh(e,t){let n=Fh(t);return n===void 0?`Expected ${e}`:`Expected ${e}, got ${n}`}function Rh(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=>Rh(e)).join(` & `)}}function zh(){return e=>Vh(e,``)}var Bh=zh();function Vh(e,t){let n;switch(e._tag){case`Filter`:{let r=Ph(e);if(r!==void 0)n=r;else{if(e.issue._tag!==`InvalidValue`)return Vh(e.issue,t);let r=Ih(e.issue);n=r===void 0?Lh(Rh(e.filter),e):Lh(r,e.issue)}break}case`Encoding`:return Vh(e.issue,t);case`Pointer`:return Vh(e.issue,t+Hr(e.path));case`Composite`:case`AnyOf`:if(e._tag===`Composite`||e.issues.length>0)return e.issues.map(e=>Vh(e,t)).join(`
9
- `);n=Hh(e)??Lh(ch(e.ast),e);break;default:n=Nh(e)}return t?`${n}\n at ${t}`:n}function Hh(e){if(e._tag===`Pointer`)return;if(e._tag===`Encoding`)return Hh(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 Uh(e){let t;for(let n of e.reasons){if(!gf(n)||!hh(n.error))return;t??=n.error}return t}function Wh(e,t){let n=Uh(e);if(n===void 0)throw Error(t,{cause:e});return n}var Gh=kp,Kh=jp,qh=Np,Jh=Pp,Yh=Ip,Xh=Lp,Zh=Bp,Qh=Vp,$h=e=>Object.assign(Object.create(xn),e);function eg(e){return sg((t,n)=>V(e(t,n)))}function tg(e){return eg((t,n)=>{let r={message:e(t)};return Da(t)?new Dh(r,t.value,n):new Dh(r)})}var ng=tg(()=>`Encoding is not supported`),rg=$h({_tag:`Passthrough`});function ig(){return rg}function ag(e){return $h({_tag:`Transform`,transform:e})}function og(e){return $h({_tag:`TransformEffect`,transform:e})}function sg(e){return $h({_tag:`TransformOptionalEffect`,transform:e})}function cg(){return ag(globalThis.String)}function lg(){return ag(globalThis.Number)}function ug(e){return og((t,n)=>sm({try:()=>JSON.parse(t,e?.reviver),catch:()=>new Th({expected:`a valid JSON string`},t,n)}))}function dg(e){return og((t,n)=>sm({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 Th({expected:`a JSON-serializable value`},t,n)}))}function fg(){return ag(ac)}function pg(){return og((e,t)=>Jm(lm(oc(e)),()=>new Th({expected:`a valid Base64 string`},e,t)))}var mg=BigInt(0),hg=BigInt(1),gg=BigInt(1e3),_g=BigInt(1024),vg=[{symbol:`B`,factor:hg,names:[`B`,`byte`,`bytes`]},{symbol:`kB`,factor:gg,names:[`kB`,`kilobyte`,`kilobytes`]},{symbol:`MB`,factor:gg**BigInt(2),names:[`MB`,`megabyte`,`megabytes`]},{symbol:`GB`,factor:gg**BigInt(3),names:[`GB`,`gigabyte`,`gigabytes`]},{symbol:`TB`,factor:gg**BigInt(4),names:[`TB`,`terabyte`,`terabytes`]},{symbol:`PB`,factor:gg**BigInt(5),names:[`PB`,`petabyte`,`petabytes`]},{symbol:`EB`,factor:gg**BigInt(6),names:[`EB`,`exabyte`,`exabytes`]},{symbol:`ZB`,factor:gg**BigInt(7),names:[`ZB`,`zettabyte`,`zettabytes`]},{symbol:`YB`,factor:gg**BigInt(8),names:[`YB`,`yottabyte`,`yottabytes`]},{symbol:`RB`,factor:gg**BigInt(9),names:[`RB`,`ronnabyte`,`ronnabytes`]},{symbol:`QB`,factor:gg**BigInt(10),names:[`QB`,`quettabyte`,`quettabytes`]}],yg=[vg[0],{symbol:`KiB`,factor:_g,names:[`KiB`,`kibibyte`,`kibibytes`]},{symbol:`MiB`,factor:_g**BigInt(2),names:[`MiB`,`mebibyte`,`mebibytes`]},{symbol:`GiB`,factor:_g**BigInt(3),names:[`GiB`,`gibibyte`,`gibibytes`]},{symbol:`TiB`,factor:_g**BigInt(4),names:[`TiB`,`tebibyte`,`tebibytes`]},{symbol:`PiB`,factor:_g**BigInt(5),names:[`PiB`,`pebibyte`,`pebibytes`]},{symbol:`EiB`,factor:_g**BigInt(6),names:[`EiB`,`exbibyte`,`exbibytes`]},{symbol:`ZiB`,factor:_g**BigInt(7),names:[`ZiB`,`zebibyte`,`zebibytes`]},{symbol:`YiB`,factor:_g**BigInt(8),names:[`YiB`,`yobibyte`,`yobibytes`]}],bg=[...vg,...yg.slice(1)],xg=new Map(bg.flatMap(e=>e.names.map(t=>[t,e]))),Sg=new Map(bg.map(e=>[e.symbol,e])),Cg=e=>e,wg=e=>{throw Error(`Invalid ByteSize: ${e}`)},Tg=e=>!Number.isSafeInteger(e)||e<0?wg(`expected a non-negative safe integer, received ${e}`):Cg(BigInt(e)),Eg=(e,t)=>{if(typeof e==`bigint`)return e<mg?wg(`expected a non-negative quantity, received ${e}`):Cg(e*t.factor);let n=e*Number(t.factor);return!Number.isSafeInteger(n)||n<0?wg(`expected an exact non-negative safe-integer byte result, received ${e} ${t.symbol}`):Cg(BigInt(n))},Dg=e=>{let t=/^\s*(\d+)(?:\.(\d+))?\s*([A-Za-z]+)\s*$/.exec(e);if(t===null)return wg(`unsupported syntax ${JSON.stringify(e)}`);let n=xg.get(t[3]);if(n===void 0)return wg(`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===mg?Cg(a/i):wg(`${JSON.stringify(e)} does not represent an integral number of bytes`)},Og=e=>{switch(typeof e){case`bigint`:return e<mg?wg(`expected a non-negative bigint, received ${e}`):Cg(e);case`number`:return Tg(e);case`string`:return Dg(e)}return wg(`unsupported input ${e}`)},kg=(e=>t=>Eg(t,Sg.get(e)))(`MiB`),Ag=class extends Sn{_tag=`Middleware`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Ag(this.encode,this.decode)}},jg=`~effect/SchemaTransformation/Transformation`,Mg=class extends Sn{[jg]=jg;_tag=`Transformation`;decode;encode;constructor(e,t){super(),this.decode=e,this.encode=t}flip(){return new Mg(this.encode,this.decode)}};function Ng(e){return w(e,jg)&&e[jg]===jg}var Pg=e=>Ng(e)?e:new Mg(e.decode,e.encode);function Fg(e){return new Mg(og(e.decode),og(e.encode))}function Ig(e){return new Mg(ag(e.decode),ag(e.encode))}var Lg=new Mg(ig(),ig());function Rg(){return Lg}var zg=new Mg(lg(),cg()),Bg=e=>Vn(e)&&typeof e.message==`string`,Vg=e=>{let t=Object.hasOwn(e,`cause`)?Error(e.message,{cause:Gg(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},Hg=e=>{try{let t=Kr(e);return t===void 0?D(e):JSON.parse(t)}catch{return D(e)}},Ug=(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},Wg=e=>{let t=new WeakSet,n=r=>{if(Wn(r)){if(t.has(r))return`[Circular]`;t.add(r);let i=Ug(r,e,n);return t.delete(r),i}return Hg(r)};return n},Gg=e=>Bg(e)?Vg(e):e,Kg=e=>Ig({decode:Gg,encode:Wg(e)}),qg=new Mg(pg(),fg());function Jg(e){return new Mg(ug(e??{}),dg(e))}function Yg(e){return t=>t._tag===e}var Xg=Yg(`Declaration`),Zg=Yg(`Null`),Qg=Yg(`Void`),$g=Yg(`Never`),e_=Yg(`Literal`),t_=Yg(`UniqueSymbol`),n_=Yg(`Arrays`),r_=Yg(`Objects`),i_=Yg(`Union`),a_=Yg(`Suspend`),o_=class{to;transformation;constructor(e,t){this.to=e,this.transformation=t}},s_={},c_=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}},l_=`~effect/Schema`,u_=class{[l_]=l_;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}>`}},d_=class extends u_{_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?dh:(e??=this.run(this.typeParameters))(t,this,n)}_rebuild(e,t,n,r,i){let a=jv(this.typeParameters,e);return a===this.typeParameters&&t===this.checks&&n===this.encodingChecks&&r===this.run&&i===this.encodingRun?this:new d_(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>`}},f_=new class extends u_{_tag=`Null`;getParser(){return Yv(this,null)}getExpected(){return`null`}},p_=class extends u_{_tag=`Undefined`;getParser(){return Yv(this,void 0)}toCodecJson(){return K(this,[m_])}getExpected(){return`undefined`}},m_=new o_(f_,new Mg(ag(()=>void 0),ag(()=>null))),h_=new p_,g_=new class extends u_{_tag=`Void`;getParser(){let e=uh(void 0);return t=>t===W?dh:e}toCodecJson(){return K(this,[m_])}getExpected(){return`void`}},__=new class extends u_{_tag=`Never`;getParser(){return Xv(this,zn)}getExpected(){return`never`}},v_=new class extends u_{_tag=`Unknown`;getParser(){return Xv(this,Bn)}getExpected(){return`unknown`}},y_=class extends u_{_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 Yv(this,this.literal)}matchPart(e,t){return e===globalThis.String(this.literal)?this.literal:void 0}toCodecJson(){return typeof this.literal==`bigint`?b_(this):this}toCodecStringTree(){return typeof this.literal==`string`?this:b_(this)}getExpected(){return typeof this.literal==`string`?JSON.stringify(this.literal):globalThis.String(this.literal)}};function b_(e){let t=globalThis.String(e.literal);return K(e,[new o_(new y_(t),new Mg(ag(()=>e.literal),ag(()=>t)))])}var x_=new class extends u_{_tag=`String`;getParser(){return Xv(this,Mn)}matchPart(e,t){let n=this.checks;return n&&!t.disableChecks&&oy(n,e,void 0,this,t)?void 0:e}getExpected(){return`string`}},S_=class extends u_{_tag=`Number`;getParser(){return Xv(this,Nn)}matchKey(e,t){return this._match(ty,e,t)}matchPart(e,t){return this._match(ey,e,t)}_match(e,t,n){if(!e.test(t))return;let r=globalThis.Number(t);return n.disableChecks||!this.checks?r:oy(this.checks,r,void 0,this,n)?void 0:r}toCodecJson(){return this.checks&&(C_(this.checks,`effect/schema/isFinite`)||C_(this.checks,`effect/schema/isInt`))?this:K(this,[hv])}toCodecStringTree(){return this.toCodecJson()===this?K(this,[iy]):K(this,[ay])}getExpected(){return`number`}};function C_(e,t){return e.some(e=>e.annotations?.representation?.id===t||e._tag===`FilterGroup`&&C_(e.checks,t))}var w_=new S_,T_=new class extends u_{_tag=`Boolean`;getParser(){return Xv(this,Pn)}getExpected(){return`boolean`}},E_=class extends u_{_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(Bv(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(Bv(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 Zm(function*(e,c){if(e===W)return W;if(!Array.isArray(e))return yield*V(new wh(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:xd(c.concurrency),p=f===1?k_(u,e,0,d):A_(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 Sh(n,e[t],c),i=new bh([t],r);if(c.errors===`all`)u.issues?u.issues.push(i):u.issues=[i];else return yield*V(new Ch(n,[i],e,c))}return u.issues?yield*V(new Ch(n,u.issues,e,c)):u.output})}_rebuild(e,t,n){let r=jv(this.elements,e),i=jv(this.rest,e);return r===this.elements&&i===this.rest&&t===this.checks&&n===this.encodingChecks?this:new E_(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 D_(e,t,n,r){if(n._tag===`Failure`)return j_(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(Bv(t.ast))return;let n=new bh([r],new xh(t.ast.context?.annotations));if(e.options.errors===`all`)e.issues?e.issues.push(n):e.issues=[n];else return Mf(new Ch(e.ast,[n],e.input,e.options))}}var O_={onItem(e,t,n){let r=n<e.len?t:W;return e.getParser(e.tailThreshold,n).parser(r,e.options)},step:D_},k_=Sd()(O_),A_=wd()(O_),j_=(e,t,n,r)=>{if(r.cause.reasons.length===0)return r;let i=Uh(r.cause);if(i===void 0)return jf(Cf(r.cause,r=>new Ch(t,[new bh([n],r)],e.input,e.options)));let a=new bh([n],i);if(e.options.errors===`all`)e.issues?e.issues.push(a):e.issues=[a];else return Mf(new Ch(t,[a],e.input,e.options))},M_=`[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?`;function N_(e,t,n=s_){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(Zv(Gv(t)))}var P_=class{name;type;constructor(e,t){this.name=e,this.type=t}};function F_(e){switch(e._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return e.types.every(F_);default:return!1}}function I_(e){let t=xv(e);switch(t._tag){case`String`:case`Number`:case`Symbol`:case`TemplateLiteral`:return!0;case`Union`:return t.types.every(I_);default:return!1}}function L_(e){return F_(e)&&I_(e)}var R_=class{parameter;type;constructor(e,t){if(!L_(e))throw Error(`Invalid index signature parameter ${e._tag}`);if(this.parameter=e,this.type=t,Bv(t)&&!Jv(t))throw Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.")}},z_=class extends u_{_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 Xv(n,Rn);let s,c,l=(e,t,r,a,s)=>{if(s._tag===`Failure`)return j_(e,n,t,s)??Nf;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 Nf;E(e.out,r,c)}return Nf},u=(e,t,r,i)=>{if(!i){let n=r.parserKey(t,e.options);if(!z(n))return H(mm(n),n=>u(e,t,r,n));i=n}if(i._tag===`Failure`)return j_(e,n,t,i)??Nf;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(mm(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(mm(i),n=>l(e,t,t,r,n))},f=a?wd()({onItem:(e,[t,n])=>n.is.parameter===x_?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(Zv(n.parameter)),parserValue:t(n.type)})):void 0),s),m=Zm(function*(e,t){if(e===W)return W;if(typeof e!=`object`||!e||Array.isArray(e))return yield*V(new wh(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:xd(t.concurrency),v=a&&_?n.indexSignatures.map(e=>N_(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 Sh(n,l[o],t),i=new bh([o],r);if(g){h.issues?h.issues.push(i):h.issues=[i];continue}return yield*V(new Ch(n,[i],e,t))}}}if(i){let e=ee===1?H_(h,s):U_(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===x_?d:u,i=v?.[e]??(n.is.parameter===x_?Object.keys(l):N_(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=to();for(let n=0;n<a;n++){let r=c[n],i=v?.[n]??(r.is.parameter===x_?Object.keys(l):N_(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 Ch(n,h.issues,e,t)):m});if(a)return m;let h=(e,t,n)=>{let r=s[t];return H(mm(n),n=>{let i=B_(e,r,n);if(i)return i;let a=()=>uh(e.out),o=H_(e,s.slice(t+1));return o?Xm(o,a):a()})};return(e,t)=>{if(e===W)return dh;if(t.errors===`all`||t.onExcessProperty!==void 0||t.concurrency!==void 0&&xd(t.concurrency)!==1)return m(e,t);if(typeof e!=`object`||!e||Array.isArray(e))return V(new wh(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=ev(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=B_(o,n,u);if(d)return d}}catch(e){return om(e)}return uh(a)}}_rebuild(e,t,n,r){let i=jv(this.propertySignatures,t=>{let n=e(t.type);return n===t.type?t:new P_(t.name,n)}),a=jv(this.indexSignatures,n=>{let r=t(n.parameter),i=e(n.type);return r===n.parameter&&i===n.type?n:new R_(r,i)});return i===this.propertySignatures&&a===this.indexSignatures&&n===this.checks&&r===this.encodingChecks?this:new z_(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 B_(e,t,n){if(n._tag===`Failure`)return j_(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],!Bv(t.type)){let n=new bh([t.name],new xh(t.type.context?.annotations));if(e.options.errors===`all`){e.issues?e.issues.push(n):e.issues=[n];return}return Mf(new Ch(e.ast,[n],e.input,e.options))}}var V_={onItem(e,t){if(!ev(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:B_},H_=Sd()(V_),U_=wd()(V_);function W_(e,t){return e?t?[...e,...t]:e:t}function G_(e,t,n){return new z_(Reflect.ownKeys(e).map(t=>new P_(t,e[t].ast)),[],n,t)}function K_(e){return e.ast}function q_(e,t=void 0){return new E_(!1,e.map(e=>e.ast),[],void 0,t)}function J_(e,t,n){return new iv(e.map(K_),t,void 0,n)}var Y_=kn(e=>{for(;;){if(a_(e))return v_;let t=e.encoding;if(!t)return e.recur?.(Y_,C)??e;if(t.some(e=>e.transformation._tag===`Middleware`&&e.transformation.decode!==C))return v_;e=t[t.length-1].to}});function X_(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(X_)));default:return[`null`,`undefined`,`string`,`number`,`boolean`,`symbol`,`bigint`,`object`,`array`,`function`]}}function Z_(e){switch(e._tag){default:return[];case`Declaration`:{let t=e.annotations?.[nh];return Array.isArray(t)?t:[]}case`Objects`:return e.propertySignatures.flatMap(e=>{let t=e.type;if(!Bv(t)){if(e_(t))return[{key:e.name,literal:t.literal}];if(t_(t))return[{key:e.name,literal:t.symbol}]}return[]});case`Arrays`:return e.elements.flatMap((e,t)=>{if(!Bv(e)){if(e_(e))return[{key:t,literal:e.literal}];if(t_(e))return[{key:t,literal:e.symbol}]}return[]});case`Union`:{if(e.types.length===0)return[];let t=e.types.map(e=>Z_(Y_(e)));return t[0].filter(e=>t.every(t=>t.some(t=>t.key===e.key&&t.literal===e.literal)))}case`Suspend`:return Z_(e.thunk())}}var Q_=new WeakMap,$_=Object.freeze([]),ev=(e,t)=>t===`__proto__`?Object.hasOwn(e,t):t in e;function tv(e){let t=Q_.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=Y_(s);if($g(c))continue;if(o){if(e_(c)||t_(c)){a??=new Map;let e=e_(c)?c.literal:c.symbol,t=a.get(e);t||a.set(e,t=[]),t.push(s)}else o=!1}let l=Z_(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=X_(c);for(let n of e)(i[n]??=[]).push(t)}}if(o&&a)a.forEach(Object.freeze),t=e=>a.get(e)??$_;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=ev(t,r)?t[r]:void 0;if(i!==void 0)return a.get(i)??$_;if(n)return e}return $_}}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]??$_;if(!Hn(t))return o.map(t=>e[t]);let s=new Set(o),c;if(a){let[n,[i]]=a,l=ev(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=ev(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=ev(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]??$_).map(t=>e[t]).filter(nv(t));return Q_.set(e,t),t}function nv(e){return t=>{let n=Y_(t);return n._tag===`Literal`?n.literal===e:n._tag!==`UniqueSymbol`||n.symbol===e}}function rv(e,t,n=!1){return tv(t)(e,n)}var iv=class extends u_{_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 dh;let a=rv(r,n.types,t!==void 0);if(a.length===0)return V(new Oh(n,[],r,i));if(a.length===1){let t=e(a[0])(r,i);return t._tag===`Success`?t:z(t)?av(n,t.cause,r,i):ym(t,e=>av(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=ov(o,a);return s?Xm(s,e=>o.out===G?B(r):o.out?o.out:V(new Oh(n,o.issues??[],r,i))):o.out?o.out:V(new Oh(n,o.issues??[],r,i))}}_rebuild(e,t,n){let r=jv(this.types,e);return r===this.types&&t===this.checks&&n===this.encodingChecks?this:new iv(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=Gv(t);switch(n._tag){case`Arrays`:{let t=n.elements.filter(e_);if(t.length>0)return`${cv(n.isMutable)}[ ${t.map(t=>e(t)+lv(t.context?.isOptional)).join(`, `)}, ... ]`;break}case`Objects`:{let t=n.propertySignatures.filter(e=>e_(e.type));if(t.length>0)return`{ ${t.map(t=>`${cv(t.type.context?.isMutable)}${Vr(t.name)}${lv(t.type.context?.isOptional)}: ${e(t.type)}`).join(`, `)}, ... }`;break}}return e(n)});return Array.from(new Set(n)).join(` | `)}};function av(e,t,n,r){let i=Uh(t);return i?Mf(new Oh(e,[i],n,r)):jf(t)}var ov=Sd()({onItem(e,t){return e.compile(t)(e.input,e.options)},step(e,t,n){if(n._tag===`Failure`){let t=Uh(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),Mf(new kh(e.ast,e.successes,e.input,e.options));if(e.out=n,e.successes)e.successes.push(t);else return Nf}}}),sv=new iv([new y_(`Infinity`),new y_(`-Infinity`),new y_(`NaN`)]);function cv(e){return e?``:`readonly `}function lv(e){return e?`?`:``}var uv=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 uv(this.run,{...this.annotations,...e},this.aborted)}abort(){return new uv(this.run,this.annotations,!0)}and(e,t){return new dv([this,e],t)}},dv=class extends Sn{_tag=`FilterGroup`;checks;annotations;constructor(e,t=void 0){super(),this.checks=e,this.annotations=t}annotate(e){return new dv(this.checks,{...this.annotations,...e})}and(e,t){return new dv([this,e],t)}};function fv(e,t,n=!1){return new uv((t,n,r)=>Mh(n,e(t,n,r),t,r),t,n)}function pv(e){return fv(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 mv=wv(w_,[pv()]),hv=new o_(new iv([mv,sv]),new Mg(lg(),ag(e=>globalThis.Number.isFinite(e)?e:globalThis.String(e))));function gv(e,t){let n=e.source,r=new globalThis.RegExp(n,e.flags);return fv(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 _v(e,t){let n=Object.getOwnPropertyDescriptors(e);return t(n),Object.create(Object.getPrototypeOf(e),n)}var vv=new WeakMap;function yv(e){return vv.get(e)??e}function K(e,t){return e.encoding===t?e:_v(e,e=>{e.encoding.value=t})}function bv(e,t){if(e.context===t)return e;let n=yv(e);if(n.context===t)return n;let r=_v(e,e=>{e.context.value=t});return vv.set(r,n),r}function xv(e){return e.encoding?xv(e.encoding[e.encoding.length-1].to):e}function Sv(e,t){if(e.checks){let n=e.checks[e.checks.length-1];return Cv(e,Za(e.checks.slice(0,-1),n.annotate(t)))}return _v(e,e=>{e.annotations.value={...e.annotations.value,...t}})}function Cv(e,t){if(e._tag===`Suspend`&&t)throw Error(`Cannot add checks to Suspend`);return e.checks===t?e:_v(e,e=>{e.checks.value=t})}function wv(e,t){return Cv(e,W_(e.checks,t))}function Tv(e,t){let n=t(e.to);return n===e.to?e:new o_(n,e.transformation)}function Ev(e,t){let n=e,r=n[n.length-1],i=Tv(r,t);return i===r?e:Za(e.slice(0,e.length-1),i)}function Dv(e){return t=>t.encoding?K(t,Ev(t.encoding,e)):t}function Ov(e,t){return Dv(e=>bv(e,t))(e)}function kv(e,t){function n(r){if(r.encoding){let e=r.encoding[r.encoding.length-1];return t?.stopAt?.(e)?r:K(r,Ev(r.encoding,n))}return e(r)}return kn(n)}function Av(e,t,n){let r=new o_(e,t);return K(n,n.encoding?[...n.encoding,r]:[r])}function jv(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 Mv(e,t){return bv(e,e.context?new c_(e.context.isOptional,e.context.isMutable,e.context.constructorDefault,{...e.context.annotations,...t}):new c_(!1,!1,void 0,t))}var Nv=kn(e=>Pv(bv(e,e.context?e.context.isOptional===!1?new c_(!0,e.context.isMutable,e.context.constructorDefault,e.context.annotations):e.context:new c_(!0,!1)))),Pv=Dv(Nv),Fv=On(e=>Nv(new iv([e,h_])));function Iv(e,t){return bv(e,e.context?new c_(e.context.isOptional,e.context.isMutable,t,e.context.annotations):new c_(!1,!1,t))}function Lv(e,t,n){return Av(e,n,t)}function Rv(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 zv(e,t){let{literals:n,parameters:r}=Rv(e);return new z_(n.map(e=>new P_(e,t)),r.map(e=>new R_(e,t)))}function Bv(e){return e.context?.isOptional??!1}function Vv(e){return e.context?.isMutable??!1}function Hv(e){return e.annotations?.[`~structural`]===!0||e._tag===`FilterGroup`&&e.checks.every(Hv)}function Uv(e){function t(e){return Hv(e)?[e]:e._tag===`FilterGroup`?e.checks.flatMap(t):[]}let n=e.flatMap(t);return $a(n)?n:void 0}var Wv=kn(e=>{if(e.encoding)return Wv(K(e,void 0));let t=e,n=t.recur?.(Wv)??t,r=n.encodingChecks;if(r){let t=n===e?r:n_(n)||r_(n)||Xg(n)&&n.typeParameters.length>0?Uv(r):void 0;return _v(n,e=>{e.encodingChecks.value=void 0,e.checks.value=W_(n.checks,t)})}return n}),Gv=kn(e=>Wv(qv(e)));function Kv(e,t){let n=t,r=n.length,i=n[r-1],a=[new o_(qv(K(e,void 0)),n[0].transformation.flip())];for(let e=1;e<r;e++)a.unshift(new o_(qv(n[e-1].to),n[e].transformation.flip()));let o=qv(i.to);return o.encoding?K(o,[...o.encoding,...a]):K(o,a)}var qv=On(e=>{if(e.encoding)return Kv(e,e.encoding);let t=e;return t.flip?.(qv)??t.recur?.(qv)??t});function Jv(e){switch(e._tag){case`Undefined`:return!0;case`Union`:return e.types.some(Jv);default:return!1}}function Yv(e,t){let n=t===0?G:uh(t);return(r,i)=>r===W?dh:r===t?n:V(new wh(e,r,i))}function Xv(e,t){return(n,r)=>n===W?dh:t(n)?G:V(new wh(e,n,r))}var Zv=kv(e=>{switch(e._tag){default:return e;case`Number`:return e.toCodecStringTree();case`Union`:return e.recur(Zv)}}),Qv=kv(e=>{switch(e._tag){default:return e;case`Symbol`:case`UniqueSymbol`:return e.toCodecStringTree();case`Union`:return e.recur(Qv)}}),$v=`[\\s\\S]*?`,ey=new globalThis.RegExp(`^${M_}$`),ty=new globalThis.RegExp(`^(?:${M_}|Infinity|-Infinity|NaN)$`);function ny(e){return gv(ey,{expected:`a string representing a finite number`,representation:{id:`effect/schema/isStringFinite`,payload:null},toJsonSchema:()=>({pattern:ey.source}),...e})}var ry=wv(x_,[ny()]),iy=new o_(ry,zg),ay=new o_(new iv([ry,sv]),zg);function oy(e,t,n,r,i){for(let a=0;a<e.length;a++){let o=e[a];if(o._tag===`FilterGroup`){if(n=oy(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 vh(o,e,t,i);if(n?n.push(r):n=[r],i.errors!==`all`||o.aborted)return n}}}return n}function sy(e){if(!Xg(e))return;let t=e.annotations?.[rh];return Ln(t)?t(e.typeParameters):void 0}var cy=$m,ly=ah,uy=sh;function dy(e){return e===null||typeof e==`string`||typeof e==`boolean`||typeof e==`number`&&globalThis.Number.isFinite(e)}function fy(e){return e===void 0||typeof e==`string`}function py(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 my(e){return py(e,dy)}var hy=new d_([],()=>(e,t,n)=>my(e)?G:V(new wh(t,e,n)),{representation:{id:`effect/schema/Json`,payload:null},expected:`JSON value`,toCodecJson:()=>void 0,toCodecStringTree:()=>yy}),gy=new o_(hy,Rg()),_y=new o_(new iv([new E_(!1,[],[hy]),new z_([],[new R_(x_,hy)])]),Rg());function vy(e){return py(e,fy)}var yy=new o_(new d_([],()=>(e,t,n)=>vy(e)?G:V(new wh(t,e,n)),{expected:`StringTree`,toCodecStringTree:()=>void 0}),Rg()),by=dl,xy=fl,Sy=rl,Cy=kd,wy=zd,Ty=`~effect/MutableRef`,Ey={[Ty]:Ty,...ui,toJSON(){return{_id:`MutableRef`,current:Jr(this.current)}}},Dy=e=>{let t=Object.create(Ey);return t.current=e,t},Oy=Symbol.for(`effect/MutableList/Empty`),ky=()=>({head:void 0,tail:void 0,length:0}),Ay=()=>({array:[],mutable:!0,offset:0,next:void 0}),jy=(e,t)=>{e.tail?e.tail.mutable||(e.tail.next=Ay(),e.tail=e.tail.next):e.head=e.tail=Ay(),e.tail.array.push(t),e.length++},My=e=>{e.head=e.tail=void 0,e.length=0},Ny=e=>{if(!e.head)return Oy;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:My(e)),t},Py=`~effect/Queue`,Fy=`~effect/Queue/Enqueue`,Iy=`~effect/Queue/Dequeue`,Ly={_A:C,_E:C},Ry={[Py]:Ly,[Fy]:Ly,[Iy]:Ly,...ui,toJSON(){return{_id:`effect/Queue`,state:this.state._tag,size:qy(this)}}},zy=e=>j(t=>{let n=Object.create(Ry);return n.dispatcher=t.currentDispatcher,n.capacity=e?.capacity??1/0,n.strategy=e?.strategy??`suspend`,n.messages=ky(),n.scheduleRunning=!1,n.state={_tag:`Open`,takers:new Set,offers:new Set,awaiters:new Set},F(n)}),By=e=>zy({capacity:e}),Vy=(e,t)=>L(()=>{if(e.state._tag!==`Open`)return Jy;if(e.messages.length>=e.capacity)switch(e.strategy){case`dropping`:return Jy;case`suspend`:return e.capacity<=0&&e.state.takers.size>0?(jy(e.messages,t),Qy(e),Yy):eb(e,t);case`sliding`:return Ny(e.messages),jy(e.messages,t),Yy}return jy(e.messages,t),$y(e),Yy}),Hy=S(2,(e,t)=>I(()=>Uy(e,t))),Uy=(e,t)=>{if(e.state._tag!==`Open`)return!1;let n=du(Li(t),Xy);return e.state.offers.size===0&&e.messages.length===0?(ib(e,n),!0):(e.state={...e.state,_tag:`Closing`,exit:n},!0)},Wy=e=>I(()=>{if(e.state._tag===`Done`)return!0;My(e.messages);let t=e.state.offers;if(ib(e,e.state._tag===`Open`?Zy:e.state.exit),t.size>0){for(let e of t)e._tag===`Single`?e.resume(Jy):e.resume(A(e.remaining.slice(e.offset)));t.clear()}return!0}),Gy=e=>L(()=>Ky(e)??Jl(rb(e),Gy(e))),Ky=e=>{if(e.state._tag===`Done`)return e.state.exit;if(e.messages.length>0){let t=Ny(e.messages);return nb(e),A(t)}if(e.capacity<=0&&e.state.offers.size>0){let t=tb(e.state.offers);return nb(e),A(t)}},qy=e=>e.state._tag===`Done`?0:e.messages.length,Jy=A(!1),Yy=A(!0),Xy=Ri(Ki()),Zy=iu(),Qy=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(su),e.messages.length===0)break}},$y=e=>{e.scheduleRunning||e.state._tag===`Done`||e.state.takers.size===0||(e.scheduleRunning=!0,e.dispatcher.scheduleTask(()=>{e.scheduleRunning=!1,Qy(e)},0))},eb=(e,t)=>kl(n=>{if(e.state._tag!==`Open`)return n(Jy);let r={_tag:`Single`,message:t,resume:n};return e.state.offers.add(r),I(()=>{e.state._tag===`Open`&&e.state.offers.delete(r)})}),tb=e=>{let t=e.values().next().value;if(t._tag===`Single`)return e.delete(t),t.resume(Yy),t.message;let n=t.remaining[t.offset++];return t.offset===t.remaining.length&&(e.delete(t),t.resume(A([]))),n},nb=e=>{if(e.state._tag===`Done`)return Up(e.state.exit.cause);if(e.state.offers.size===0)return e.state._tag===`Closing`&&e.messages.length===0&&(ib(e,e.state.exit),Up(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`)jy(e.messages,t.message),e.state.offers.delete(t),t.resume(Yy);else{for(;t.offset<t.remaining.length;t.offset++){if(n===0)return!1;jy(e.messages,t.remaining[t.offset]),n--}e.state.offers.delete(t),t.resume(A([]))}}return!1},rb=e=>kl(t=>e.state._tag===`Done`?t(e.state.exit):(e.state.takers.add(t),I(()=>{e.state._tag!==`Done`&&e.state.takers.delete(t)}))),ib=(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()},ab=e=>new sb(e),ob=(e,t,n)=>kl(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)})}),sb=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?ob(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=>gd(n=>{let r=L(()=>this.free<e?Zl(n(ob(this,e,R)),()=>r):(this.taken+=e,rd(n(t),()=>{this.releaseUnsafe(rl(),e)},!0)));return r})}withPermit=this.withPermits(1);withPermitsIfAvailable(e){return t=>gd(n=>this.free<e?yl:(this.taken+=e,rd(n(ql(t)),()=>{this.releaseUnsafe(rl(),e)},!0)))}},cb=`~effect/Channel`,lb=e=>w(e,cb),ub={[cb]:{_Env:C,_InErr:C,_InElem:C,_OutErr:C,_OutElem:C},pipe(){return x(this,arguments)}},db=e=>{let t=Object.create(ub);return t.transform=(t,n)=>ym(e(t,n),e=>B(im(e))),t},fb=(e,t)=>db((n,r)=>H(hb(e)(n,r),e=>t(e,r))),pb=e=>db((t,n)=>e),mb=e=>db(Gm(function*(t,n){let r=qf(n),i=e=>Jf(r,qp(e));return Am(yield*Am(e(t,n,r),i),i)})),hb=e=>e.transform,gb=e=>db((t,n)=>em(()=>hb(e())(t,n))),_b=e=>pb(B(V(e))),vb=e=>pb(tm(()=>{let t=!1;return em(()=>t?Of():(t=!0,e))})),yb=e=>db((t,n)=>bb({scope:n,readable:e.evaluate(),onError:e.onError,releaseLockOnEnd:e.releaseLockOnEnd})),bb=e=>{let t=e.readable.getReader(),n=e.exit??Dy(void 0),r=em(()=>n.current?n.current:wm($p({try:()=>t.read(),catch:e.onError}),{onFailure:e=>n.current??im(e),onSuccess:({done:e,value:t})=>n.current?n.current:e?Of():B(no(t))}));return hm(Kf(e.scope,e.releaseLockOnEnd?tm(()=>t.releaseLock()):Qp(()=>t.cancel().catch(Dn))),r)},xb=S(2,(e,t)=>fb(e,e=>tm(()=>{let n=0;return U(e,e=>t(e,n++))}))),Sb=e=>e===void 0||e!==`unbounded`&&e<=1,Cb=S(e=>lb(e[0]),(e,t,n)=>Sb(n?.concurrency)?wb(e,t):Tb(e,t,n)),wb=(e,t)=>db((n,r)=>{let i=0;return U(hb(e)(n,r),H(e=>t(e,i++)))}),Tb=(e,t,n)=>mb(Gm(function*(r,i,a){let o=0,s=yield*hb(e)(r,i),c=n.concurrency===`unbounded`?2**53-1:n.concurrency,l=yield*By(0);yield*Kf(a,Wy(l));let u=Vm(yield*Tm()),d=Cy(a);if(n.unordered){let e=ab(c),n=Cn(e.release(1)),r=wm({onFailure:e=>H(Hy(l,e),n),onSuccess:e=>H(Vy(l,e),n)});yield*e.take(1).pipe(H(()=>s),H(e=>(d(u(r(t(e,o++)))),nm)),Fm({disableYield:!0}),ym(t=>e.withPermits(c-1)(Hy(l,t))),zm(a))}else{let e=yield*By(c-2);yield*Kf(a,Wy(e)),yield*Gy(e).pipe(um,H(e=>Vy(l,e)),Fm({disableYield:!0}),ym(e=>Hy(l,e)),zm(a));let n,r=e=>{e._tag!==`Success`&&(n=e.cause,Uy(l,e.cause))};yield*s.pipe(H(i=>{if(n)return im(n);let a=u(t(i,o++));return d(a),a.addObserver(r),Vy(e,by(a))}),Fm({disableYield:!0}),ym(t=>Vy(e,jf(t)).pipe(dm(Hy(e,t)))),zm(a))}return Gy(l)})),Eb=S(2,(e,t)=>db((n,r)=>{let i=qf(r);return U(hb(e)(n,i),e=>{let a=e.pipe(ym(e=>{if(Up(e))return im(e);let o=i;return i=qf(r),Jf(o,jf(e)).pipe(dm(hb(t(e))(n,i)),H(e=>(a=e,e)))}));return em(()=>a)})})),Db=S(2,(e,t)=>db((n,r)=>H(hb(e)(n,r),e=>hb(t)(e,r)))),Ob=S(2,(e,t)=>mb((n,r,i)=>Gf(i,t).pipe(dm(hb(e)(n,r))))),kb=S(2,(e,t)=>Ob(e,e=>t)),Ab=(e,t,n)=>em(()=>{let r=Uf();return Hp(H(hb(e)(Of(),r),t),n||B).pipe(jm(e=>Jf(r,e)))}),jb=S(2,(e,t)=>db((n,r)=>U(Om(hb(e)(n,r),t),Om(t)))),Mb=S(2,(e,t)=>Ab(e,e=>Fm(H(e,t),{disableYield:!0}))),Nb=(e,t)=>hb(e)(Of(),t),Pb=(e,t,n)=>e===G?n(t):Xm(e,n);function Fb(e){if(e._tag===`Middleware`)return(t,n,r)=>Ib(t===G?e.decode(uh(fh(n)),r):e.decode(qm(t,fh),r));let t=e.decode;switch(t._tag){case`Passthrough`:return(e,t)=>e===G?uh(t):e;case`Transform`:{let e=e=>e===W?dh:uh(t.transform(e));return(t,n)=>Pb(t,n,e)}case`TransformOptional`:{let e=e=>ph(t.transform(fh(e)));return(t,n)=>Pb(t,n,e)}case`TransformEffect`:return(e,n,r)=>Pb(e,n,e=>e===W?dh:t.transform(e,r));case`TransformOptionalEffect`:return(e,n,r)=>Pb(e,n,e=>Ib(t.transform(fh(e),r)))}}var Ib=e=>Xm(e,ph),Lb=(e,t,n,r)=>ym(r,r=>am(()=>Cf(r,r=>new yh(e,r,t,n))));function Rb(e,t){let n=Fb(e.link.transformation),r;return(i,a)=>{if(i===W)return dh;if(e.isConstructed(i))return G;let o=(r??=t(e.link.to))(i,a);return n(o,i,a)}}function zb(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 Xm(Lb(e,r,i,a),e=>{let n=t(e,i);return n===G?uh(e):n})}}function Bb(e,t){let n=t(e);return e.context?.constructorDefault===void 0?n:zb(e,n)}function Vb(e,t,n,r,i){if(e._tag===`Declaration`)for(let n of e.typeParameters)t(n);let a=n?sy(e):void 0,o=a?Rb(a,t):r??e.getParser(t,n),s=e.checks,c=e.encoding,l=c?.map(e=>Fb(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=oy(u,t,void 0,e,n);i&&(r=V(new Ch(e,i,t,n)))}}}else r=H(r,r=>{if(t!==W&&r!==W){let r=oy(u,t,void 0,e,n);if(r)return V(new Ch(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=oy(s,i,void 0,e,n);a&&(r=V(new Ch(e,a,i,n)))}}else r=H(r,t=>{if(t!==W){let r=oy(s,t,void 0,e,n);if(r)return V(new Ch(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=Xm(o,e=>{let n=t(e,r);return n===G?uh(e):n})}if(o._tag===`Success`){let e=o[O],t=p(e,r);return t===G?o:t}return o=Lb(e,n,r,o),Xm(o,e=>{let t=p(e,r);return t===G?uh(e):t})}:p}var Hb=Symbol(),Ub=new WeakMap,Wb=e=>Jb(e).parser,Gb=e=>Jb(e).makeEffect,Kb=e=>Bb(e,Gb),qb=class{ast;constructor(e){this.ast=e}get decodeEffect(){return this.cachedDecodeEffect??=Vb(this.ast,Wb)}get parser(){return this.decodeEffect}get makeEffect(){return this.cachedMakeEffect??=Vb(this.ast,Gb,Kb)}};function Jb(e){let t=Ub.get(e);if(t!==void 0)return t;let n=new qb(e);return Ub.set(e,n),n}function Yb(e){let t=e.ast,n;return(e,r)=>(n??=sx(fx,Wv(t)))(e,r?.disableChecks?r?.parseOptions?{...r.parseOptions,disableChecks:!0}:{disableChecks:!0}:r?.parseOptions)}function Xb(e){let t=Yb(e);return(e,n)=>{let r=Wm(t(e,n));return Pf(r)?Ta(r.value):(Wh(r.cause,`Option adapter can only return none for schema issues`),wa())}}function Zb(e){return ux(Wv(e.ast))}function Qb(e){return ex(e.ast)}function $b(e){{let t=cx(ax(e));return e=>{let n=t(e,s_);return Pf(n)?!0:(Wh(n.cause,`Type guard adapter can only return false for schema issues`),!1)}}}function ex(e){let t=Wv(e),n=e=>(n=$b(t),n(e));return e=>n(e)}function tx(e,t){let n=ax(e.ast);return t===void 0?n:(e,r)=>n(e,rx(t,r))}function nx(e,t){let n=ax(qv(e.ast));return t===void 0?n:(e,r)=>n(e,rx(t,r))}var rx=(e,t)=>t?{...e,...t}:e,ix=e=>e===W?V(new Th):B(e);function ax(e){return sx(dx,e)}function ox(e,t){return e===G?B(t):z(e)?e[O]===W?ix(W):e:Xm(e,ix)}function sx(e,t){let n;return(r,i)=>{let a=(n??=e(t))(r,i??s_);return a===G?B(r):z(a)?a[O]===W?ix(W):a:Xm(a,ix)}}function cx(e){return(t,n)=>Wm(e(t,n))}function lx(e,t){let n=Wm(e);if(Pf(n))return n.value;let r=Wh(n.cause,t);throw Error(`Schema validation failed`,{cause:r})}function ux(e){let t,n;return(r,i)=>{t??=Jb(e);let a=i?.disableChecks?i.parseOptions?{...i.parseOptions,disableChecks:!0}:{disableChecks:!0}:i?.parseOptions??s_,o=t.make;if(o!==void 0&&r!==W){let e;try{e=o(r,a)}catch(e){throw Wh(yf(e),`Constructor adapter can only throw schema issues`),e}if(e!==Hb&&e!==W)return e}return lx(ox((n??=t.makeEffect)(r,a),r),`Constructor adapter can only throw schema issues`)}}var dx=e=>Jb(e).parser,fx=e=>Jb(e).makeEffect,px=`~effect/Schema/Schema`,mx={[px]:px,pipe(){return x(this,arguments)},annotate(e){return this.rebuild(Sv(this.ast,e))},annotateKey(e){return this.rebuild(Mv(this.ast,e))},check(...e){return this.rebuild(wv(this.ast,e))}};function hx(e,t){function n(){}let r=Object.setPrototypeOf(n,mx);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=>hx(e,t),r.makeEffect=Yb(r),r.make=Zb(r),r.makeOption=Xb(r),r}function gx(e){return e.replace(/~/g,`~0`).replace(/\//g,`~1`)}function _x(e){return e.replace(/~1/g,`/`).replace(/~0/g,`~`)}function vx(e){return encodeURI(gx(e)).replace(/#/g,`%23`)}function yx(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 bx(e){let t=yx(e);return t===void 0?void 0:t.length===0?[]:t.slice(1).split(`/`).map(_x)}function xx(e){return e.reduce((e,t)=>`${e}/${vx(t)}`,`#`)}var Sx=[`example`,`discriminator`,`xml`,`externalDocs`];function Cx(e){let t=Object.keys(e.definitions),n=new Map,r=new Set(t.filter(e=>wx.test(e))),i=t.filter(e=>!wx.test(e)).sort().map(e=>[e,Tx(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=Ax(t.$id),a=Vn(t.$defs)?t.$defs:void 0;return Ex(t,(t,o)=>{Nx(t,Sx,`OpenAPI 3.1`,`Draft 2020-12`),Ox(t,(t,s)=>{let c=t.startsWith(`#`)?bx(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))&&Mx(s,`OpenAPI 3.1`,`a schema resource cannot reference the shared definitions pool`),t):o?t:xx([`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 wx=/^[a-zA-Z0-9.\-_]+$/;function Tx(e){return e.length===0?`_`:e.replace(/[^a-zA-Z0-9._-]/gu,`_`)}function Ex(e,t){return n(e,!1,!0);function n(e,r,i=!1){if(!Vn(e))return e;let a=r||!i&&Ax(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=kx(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 Dx(e,t){return Ex(e,e=>{Ox(e,t)})}function Ox(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 kx(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 Ax(e){return typeof e==`string`&&e.length>0&&e[0]!==`#`}var jx=[`$anchor`,`$defs`,`$dynamicAnchor`,`$dynamicRef`,`$vocabulary`,`contentSchema`,`dependentRequired`,`dependentSchemas`,`maxContains`,`minContains`,`prefixItems`,`unevaluatedItems`,`unevaluatedProperties`];[...jx],[...jx];function Mx(e,t,n){throw Error(`Cannot convert JSON Schema keyword "${e}" to ${t}: ${n}`)}function Nx(e,t,n,r){for(let i of t)Object.hasOwn(e,i)&&Mx(i,n,`it is not active in ${r} but would become active in the target`)}function Px(e){return hx(Fx(e.ast),{schema:e})}var Fx=kv(e=>{let t=Bx(e,Fx),n=e.context;return t===e||n===void 0?t:Ov(t,Ix(n))});function Ix(e){return e.constructorDefault===void 0?e:new c_(e.isOptional,e.isMutable,void 0,e.annotations)}function Lx(e){if(e.propertySignatures.some(e=>typeof e.name!=`string`))throw new globalThis.Error(`Objects property names must be strings`,{cause:e})}function Rx(e){return t=>{let n=new Map;for(let e=0;e<t.length;e++)n.set(Gv(t[e]),e);let r=[...t].sort((t,r)=>{t=Gv(t),r=Gv(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 zx=Rx(e=>{switch(e._tag){case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function Bx(e,t){switch(e._tag){case`Declaration`:{let n=e.annotations?.toCodecJson??e.annotations?.toCodec;if(!Ln(n))return K(e,[gy]);let r=n(e.typeParameters.map(e=>hx(Gv(e))));return r===void 0?e:K(e,[Tv(r,t)])}case`Unknown`:return K(e,[gy]);case`ObjectKeyword`:return K(e,[_y]);case`Undefined`:case`Void`:case`Literal`:case`Number`:return e.toCodecJson();case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return Lx(e),e.recur(t,Qv);case`Union`:{let n=zx(e.types);return n===e.types?e.recur(t):new iv(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 Vx(e){return hx(Yx(e.ast),{schema:e})}function Hx(e){return hx(Zx(e.ast))}var Ux=Rx(e=>{switch(e._tag){case`Null`:case`Boolean`:case`Number`:case`BigInt`:case`Symbol`:case`UniqueSymbol`:return 0;default:return 1}});function Wx(e,t,n){switch(e._tag){case`Declaration`:{let r=e.typeParameters.map(e=>hx(t(Gv(e)))),i=e.annotations?.toCodecStringTree;if(Ln(i)){let n=i(r);return n===void 0?e:K(e,[Tv(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,[Tv(c,t)])}case`Null`:return K(e,[Gx]);case`Boolean`:return K(e,[Kx]);case`Unknown`:case`ObjectKeyword`:return K(e,[yy]);case`Enum`:case`Number`:case`Literal`:case`UniqueSymbol`:case`Symbol`:case`BigInt`:return e.toCodecStringTree();case`Objects`:return Lx(e),e.recur(t,Qv);case`Union`:{let n=Ux(e.types);return n===e.types?e.recur(t):new iv(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 Gx=new o_(new y_(`null`),new Mg(ag(()=>null),ag(()=>`null`))),Kx=new o_(new iv([new y_(`true`),new y_(`false`)]),new Mg(ag(e=>e===`true`),cg())),qx=new Mg(ag(e=>typeof e==`string`?[e]:e),ig()),Jx=e=>e.transformation===qx,Yx=kv(e=>{let t=Wx(e,Yx,e=>{throw new globalThis.Error(`Missing structural codec for StringTree`,{cause:e})});return t!==e&&e.context!==void 0?Ov(t,Ix(e.context)):t},{stopAt:Jx}),Xx=e=>Bv(e)?Nv(v_):v_,Zx=kv(e=>{let t=Qx(e);if(n_(t)){let n=Lv(new iv([new E_(t.isMutable,t.elements.map(Xx),t.rest.map(Xx)),x_],{mode:`anyOf`}),t,qx);return Bv(e)?Nv(n):n}return t},{stopAt:Jx});function Qx(e){return e._tag===`Declaration`||e._tag===`Arrays`||e._tag===`Objects`||e._tag===`Union`||e._tag===`Suspend`?e.recur(Zx):e}globalThis.RegExp;var $x=e=>e.replace(/[/\\^$*+?.()|[\]{}]/g,`\\$&`);function eS(e,t){return t.length>0&&(e+=`\n at ${Hr(t)}`),Error(e)}function tS(e){return`#/$defs/${vx(e)}`}var nS=new Set([...lh,th,...ih]);function rS(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;my(o)&&(n.default=o);let s=e.examples;Array.isArray(s)&&my(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(my(p)&&(n.contentSchema=p),t?.includeAnnotationKey!==void 0)for(let[r,i]of Object.entries(e))!nS.has(r)&&t.includeAnnotationKey(r)&&my(i)&&E(n,r,i);return Object.keys(n).length===0?void 0:n}function iS(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=iS(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 aS(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 oS=`|type|format|pattern|multipleOf|minimum|maximum|exclusiveMinimum|exclusiveMaximum|minLength|maxLength|minItems|maxItems|uniqueItems|minProperties|maxProperties|propertyNames|`;function sS(e,t){return Object.keys(e).every(e=>t.includes(`|${e}|`))}function cS(e,t){return typeof e.$ref!=`string`&&t.every(t=>!Object.hasOwn(e,t))}var lS=`|title|description|default|examples|readOnly|writeOnly|`,uS=oS+lS;function dS(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=aS(e);if(i!==void 0||a){let r=iS(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:sS(r.schema,lS)&&cS(o,s)?{...o,...r.schema}:dS(o,r.schema,n)}}if(n&&cS(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 fS(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=ro(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 eS(`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=>ur(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 Dx(e,e=>{let t=yx(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(_x(t.slice(7,n<0?void 0:n)));return typeof r==`string`?e.replace(/^#(?:\/|%2f).*?(?:\/|%2f).*?(?=\/|%2f|$)/i,tS(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[th]: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=rS(i,r),c=s===void 0?o:{...o,...s},l=s===void 0?oS:uS;return e._tag===`Filter`&&sS(c,l)&&(s===void 0||sS(s,lS))?[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=rS(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:tS(u(e.$ref,t))};let n=a.get(e);if(n!==void 0)return n;let i=g(e,t),o=rS(e.annotations,r);o!==void 0&&(i={...i,...o});for(let n=0;n<e.checks.length;n++){let r=typeof i.type==`string`&&pS(i.type)?i.type:void 0,a=m(e.checks[n],r,[...t,`checks`,n]);a!==void 0&&(i=dS(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 eS(`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(hS).join(``)}$`};case`Arrays`:{if(e.rest.length>1)throw eS(`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=rS(e.annotations,r);return o===void 0?a:dS(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 eS(`Invalid schema representation document`,[...t,`propertySignatures`,n,`name`]);let s=o.name,c=h(o.type,[...t,`propertySignatures`,n,`type`]),l=rS(o.annotations,r);E(i,s,l===void 0?c:dS(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`]);ur(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:dS(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=mS(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 eS(`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`&&sS(n,`|type|pattern|title|description|default|examples|readOnly|writeOnly|`)?[n.pattern]:void 0}case`TemplateLiteral`:return e.checks.length===0?[`^${e.parts.map(hS).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 eS(`Invalid schema representation document`,t)}}}function pS(e){return e===`string`||e===`number`||e===`boolean`||e===`array`||e===`object`||e===`null`||e===`integer`}function mS(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 hS(e){switch(e._tag){case`Literal`:return $x(globalThis.String(e.literal));case`String`:return $v;case`Number`:return M_;case`TemplateLiteral`:return e.parts.map(hS).join(``);case`Union`:return`(?:${e.types.map(hS).join(`|`)})`;default:throw eS(`Invalid schema representation document`,[])}}function gS(e,t){return fS(e.representations,e.representations.map((e,t)=>[`representations`,t]),e.references,t)}var _S=({identifier:e})=>e;function vS(e){return e===void 0?void 0:{annotations:e}}function yS(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??_S;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:ro(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:Sv(e,{identifier:n}):oh(e)===r?e:Sv(e,{[th]: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=xv(e),n=yv(t),r=ah(t),i=r===void 0?(t===e?void 0:ah(e))??oh(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(Wv(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,...vS(e.annotations)};case`Literal`:return{_tag:`Literal`,literal:e.literal,checks:t,...vS(e.annotations)};case`UniqueSymbol`:return{_tag:`UniqueSymbol`,symbol:e.symbol,checks:t,...vS(e.annotations)};case`Enum`:return{_tag:`Enum`,enums:e.enums,checks:t,...vS(e.annotations)};case`TemplateLiteral`:return{_tag:`TemplateLiteral`,parts:e.parts.map(e=>m(e)),checks:t,...vS(e.annotations)};case`Arrays`:return{_tag:`Arrays`,elements:e.elements.map(e=>{let t=xv(e),n=t.context?.annotations;return{isOptional:Bv(t),type:m(e),...vS(n)}}),rest:e.rest.map(e=>m(e)),checks:t,...vS(e.annotations)};case`Objects`:return{_tag:`Objects`,propertySignatures:e.propertySignatures.map(e=>{let t=xv(e.type),n=t.context?.annotations;return{name:e.name,type:m(e.type),isOptional:Bv(t),isMutable:Vv(t),...vS(n)}}),indexSignatures:e.indexSignatures.map(e=>({parameter:m(e.parameter),type:m(e.type)})),checks:t,...vS(e.annotations)};case`Union`:return{_tag:`Union`,types:e.types.map(e=>m(e)),...e.options===void 0?{}:{options:e.options},checks:t,...vS(e.annotations)};case`Suspend`:return{_tag:`Suspend`,checks:[],thunk:m(e.thunk()),...vS(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:ro(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(Wv(e)))};return{...r===void 0?void 0:{representation:r},...Object.keys(n).length===0?void 0:{annotations:n}}}}function bS(e,t){let n=t;for(let t of e)n=wS(n,t);return n}function xS(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function SS(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(_x)}function CS(e){if(!/^(0|[1-9]\d*)$/.test(e))throw Error(`Invalid array index: "${e}"`);return Number(e)}function wS(e,t){if(t.path===``){if(t.op===`remove`)throw Error(`Unsupported operation at the root`);return t.value}let n=TS(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:CS(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,ES(a,n)}if(xS(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),ES(a,e)}throw Error(`Cannot ${t.op} at "${t.path}" (parent not found or not a container).`)}function TS(e,t){let n=SS(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=CS(t);if(e>=a.length)return null;i.push({container:a,token:e}),a=a[e];continue}if(xS(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 ES(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 DS=S(2,(e,t)=>({...e,...t})),OS=e=>e,kS=`~effect/Schema/SchemaError`;function AS(e){return w(e,`~effect/Schema/SchemaError`)&&e[`~effect/Schema/SchemaError`]===`~effect/Schema/SchemaError`}var jS=new WeakMap,MS=`~effect/Redacted`,NS=e=>w(e,MS),PS=(e,t)=>{let n=Object.create(FS);return t?.label&&(n.label=t.label),jS.set(n,e),n},FS={[MS]:{_A:e=>e},label:void 0,...ui,toJSON(){return this.toString()},toString(){return`<redacted${Mn(this.label)?`:`+this.label:``}>`},[Kn](){return T(jS.get(this))},[lr](e){return NS(e)&&ur(jS.get(this),jS.get(e))}},IS=`~effect/http/Cookies`,LS=`~effect/http/Cookies/Cookie`,RS={[IS]:IS,...Yr,toJSON(){return{_id:`effect/Cookies`,cookies:Wa(this.cookies,e=>e.toJSON())}},pipe(){return x(this,arguments)}},zS=e=>{let t=Object.create(RS);return t.cookies=e,t},BS=e=>{let t={};for(let n of e)E(t,n.name,n);return zS(t)},VS=e=>{let t=typeof e==`string`?[e]:e,n=[];for(let e of t){let t=HS(e.trim());t&&n.push(t)}return BS(n)};function HS(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(!WS.test(r))return;let i=t[0].slice(n+1),a=KS(i);if(t.length===1)return Object.assign(Object.create(GS),{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=Ps(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(GS),{name:r,value:a,valueEncoded:i,options:Object.keys(o).length>0?o:void 0})}var US=BS([]),WS=/^[!#$%&'*+\-.^_`|~0-9A-Za-z]+$/,GS={[LS]:LS,...Yr,toJSON(){return{_id:`effect/Cookies/Cookie`,name:this.name,value:this.value,options:this.options}}},KS=e=>{try{return decodeURIComponent(e)}catch{return e}},qS=Symbol.for(`~effect/http/Headers`),JS=Object.defineProperties(Object.create(null),{[qS]:{value:qS},[Nr]:{value(e){return iC(this,rs(e,oC))}},toJSON:{value(){return Fr(this)}},[lr]:{value(e){return XS(this,e)}},[Kn]:{value(){return er(this)}},toString:{value:Yr.toString},[qr]:{value:Yr[qr]}}),YS=e=>Object.assign(Object.create(JS),e),XS=qa(Or()),ZS=Object.create(JS),QS=e=>{if(e===void 0)return ZS;if(Symbol.iterator in e){let t=Object.create(JS);for(let[n,r]of e)t[n.toLowerCase()]=r;return t}let t=Object.create(JS);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},$S=e=>Object.setPrototypeOf(e,JS),eC=S(3,(e,t,n)=>{let r=YS(e);return r[t.toLowerCase()]=n,r}),tC=S(2,(e,t)=>YS({...e,...QS(t)})),nC=S(2,(e,t)=>{let n=YS(e);return Object.assign(n,t),n}),rC=S(2,(e,t)=>{let n=YS(e);return delete n[t.toLowerCase()],n}),iC=S(2,(e,t)=>{let n={...e},r=t=>{if(typeof t==`string`){let r=t.toLowerCase();r in e&&(n[r]=PS(e[r]))}else for(let r in e)r.search(t)!==-1&&(n[r]=PS(e[r]))};if(Array.isArray(t))for(let e=0;e<t.length;e++)r(t[e]);else r(t);return n}),aC=(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},oC=N(`effect/Headers/CurrentRedactedNames`,{defaultValue:()=>[`authorization`,`cookie`,`set-cookie`,`x-api-key`]}),sC=`~effect/http/UrlParams`,cC=e=>w(e,sC),lC={...ui,[sC]:sC,[Symbol.iterator](){return this.params[Symbol.iterator]()},toJSON(){return{_id:`UrlParams`,params:Object.fromEntries(this.params)}},[lr](e){return pC(this,e)},[Kn](){return nr(this.params.flat())}},uC=e=>{let t=Object.create(lC);return t.params=e,t},dC=e=>{if(cC(e))return e;let t=fC(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 uC(n)},fC=e=>{let t=typeof e[Symbol.iterator]==`function`?Ya(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=fC(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},pC=Er((e,t)=>mC(e.params,t.params)),mC=io(Ha([Or(),Or()])),hC=uC([]),gC=S(2,(e,t)=>uC(t(e.params))),_C=S(2,(e,t)=>{let n=dC(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 uC(n)}),vC=S(2,(e,t)=>gC(e,Qa(dC(t).params))),yC=e=>new URLSearchParams(dC(e).params).toString(),bC=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},xC=bC,SC=px;function CC(){return(e,t,n)=>q(new d_(e.map(K_),e=>t(e.map(e=>q(e))),n))}function wC(e,t){return CC()([],()=>(t,n,r)=>e(t)?B(t):V(new wh(n,t,r)),t)}var TC=class extends nc(`SchemaError`){[kS]=kS;constructor(e){let t=Qr();$r(0);try{super({issue:e})}finally{$r(t)}}get message(){return Bh(this.issue)}toString(){return`SchemaError(${this.message})`}};function EC(e){return AS(e)}function DC(e){return z(e)?OC(e):ym(e,e=>am(()=>Cf(e,e=>new TC(e))))}function OC(e){return Pf(e)?e:jf(Cf(e.cause,e=>new TC(e)))}function kC(e,t){let n;for(let r of e.reasons){if(!gf(r)||!EC(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 AC(e){let t=Wm(e);if(Pf(t))return t.value;throw kC(t.cause,`Sync adapter can only throw schema errors`)}var jC=Qb;function MC(e,t){let n=tx(e,t);return(e,t)=>DC(n(e,t))}var NC=MC;function PC(e,t){let n=MC(e,t);return(e,t)=>AC(n(e,t))}function FC(e,t){let n=nx(e,t);return(e,t)=>DC(n(e,t))}var q=hx;function IC(e){return w(e,SC)&&e[SC]===SC}var LC=OS(e=>{let t=aw(e);return q(Fv(e.ast),{schema:t})}),RC=OS(e=>q(Wv(e.ast),{schema:e})),zC=OS(e=>q(Gv(e.ast),{schema:e}));function BC(e){let t=q(new y_(e),{literal:e,transform(n){return t.pipe(X(BC(n),{decode:ag(()=>n),encode:ag(()=>e)}))}});return t}var VC=q(__),HC=q(v_),UC=q(f_),WC=q(h_),J=q(x_),GC=q(w_),KC=q(T_),qC=q(g_);function JC(e,t){return q(e,{fields:t,mapFields(e,t){let n=e(this.fields);return JC(G_(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function Y(e){return JC(G_(e,void 0),e)}function YC(e){return OS(t=>t.mapFields(DS(e)))}function XC(e,t){return q(zv(e.ast,t.ast),{key:e,value:t})}function ZC(e,t){return q(e,{elements:t,mapElements(e,t){let n=e(this.elements);return ZC(q_(n,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function QC(e){return ZC(q_(e),e)}var $C=OS(e=>q(new E_(!1,[],[e.ast]),{value:e})),ew=OS(e=>q(new E_(!1,[e.ast],[e.ast]),{value:e}));function tw(e,t){return q(e,{members:t,mapMembers(e,t){let n=e(this.members);return tw(J_(n,this.ast.options,t?.unsafePreserveChecks?this.ast.checks:void 0),n)}})}function nw(e,t){return tw(J_(e,t,void 0),e)}function rw(e){let t=e.map(BC);return q(J_(t,void 0,void 0),{literals:e,members:t,mapMembers(e){return nw(e(this.members))},pick(e){return rw(e)},transform(e){return nw(t.map((t,n)=>t.transform(e[n])))}})}var iw=OS(e=>nw([e,UC])),aw=OS(e=>nw([e,WC]));function X(e,t){return n=>q(Lv(n.ast,e.ast,t?Pg(t):Rg()),{from:n,to:e})}function ow(){return(e,t)=>dw()(e,{decode:t,encode:ng})}function sw(e){return t=>q(Iv(t.ast,e),{schema:t})}function cw(e){return BC(e).pipe(sw(B(e)))}function lw(e,t){return Y({_tag:cw(e),...t})}function uw(e,t){return wC(t=>t instanceof e,t)}function dw(){return(e,t)=>new o_(e.ast,Pg(t))}var fw=fv,pw=q(mv);function mw(e){let t=Ca(e.order),n=xa(e.order),r=Sa(e.order),i=ba(e.order),a=e.formatter??D;return(o,s)=>{let c=o.exclusiveMinimum?n:t,l=o.exclusiveMaximum?i:r;return fw(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 hw(e){if(!globalThis.Number.isFinite(e))throw new globalThis.RangeError(`Expected a finite number, got ${D(e)}`);return e}var gw=mw({order:va,annotate:e=>{let t=e.exclusiveMinimum?!0:void 0,n=e.exclusiveMaximum?!0:void 0;return{representation:{id:`effect/schema/isBetween`,payload:{minimum:hw(e.minimum),maximum:hw(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 _w(e){return fw(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 vw=GC.check(_w()),yw=e=>+(e?.includeStack===!0)|(e?.excludeCause===!0?2:0),bw=e=>{switch(e){case 0:return;case 1:return{includeStack:!0};case 2:return{excludeCause:!0};case 3:return{includeStack:!0,excludeCause:!0}}},xw=[];function Sw(e){let t=yw(e),n=xw[t];if(n!==void 0)return n;let r=Xw.pipe(X(HC,Kg(bw(t))));return xw[t]=r,r}globalThis.RegExp,globalThis.URL;var Cw=J.annotate({expected:`a string that will be decoded as JSON`,contentMediaType:`application/json`});function ww(e,t){return Cw.pipe(X(e,Jg(t)))}var Tw=ww(HC);globalThis.File,globalThis.FormData,globalThis.URLSearchParams;var Ew=J.annotate({expected:`a base64 encoded string that will be decoded as Uint8Array`,format:`byte`,contentEncoding:`base64`}),Dw=uw(globalThis.Uint8Array,{representation:{id:`effect/schema/Uint8Array`,payload:null},toCode:()=>({runtime:`Schema.Uint8Array`,Type:`globalThis.Uint8Array`}),expected:`Uint8Array`,toCodecJson:()=>dw()(Ew,qg)});function Ow(e,t){return q(CC()([e,t],([e,t])=>(n,r,i)=>{if(!hf(n))return V(new wh(r,n,i));switch(n._tag){case`Fail`:return Ym(tx(e)(n.error,i),{onSuccess:bf,onFailure:e=>Eh(r,`error`,e,n,i)});case`Die`:return Ym(tx(t)(n.defect,i),{onSuccess:xf,onFailure:e=>Eh(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])=>dw()(nw([Y({_tag:BC(`Fail`),error:e}),Y({_tag:BC(`Die`),defect:t}),Y({_tag:BC(`Interrupt`),fiberId:aw(pw)})]),Ig({decode:e=>{switch(e._tag){case`Fail`:return bf(e.error);case`Die`:return xf(e.defect);case`Interrupt`:return Sf(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 kw(e,t){return q(CC()([e,t],([e,t])=>{let n=$C(Ow(e,t));return(e,t,r)=>mf(e)?Ym(tx(n)(e.reasons,r),{onSuccess:_f,onFailure:n=>Eh(t,`failures`,n,e,r)}):V(new wh(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])=>dw()($C(Ow(e,t)),Ig({decode:_f,encode:({reasons:e})=>e}))}).ast,{error:e,defect:t})}var Aw=Fg({decode:(e,t)=>Oa(Yh(e),{onNone:()=>V(new Th({expected:`a valid UTC DateTime string`},e,t)),onSome:e=>B(Xh(e))}),encode:e=>B(Qh(e))}),jw=-864e13,Mw=864e13;function Nw(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 Pw(e,t){return vw.check(gw({minimum:e,maximum:t}))}var Fw=wC(e=>Gh(e)&&Kh(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]=Nw(e,jw,Mw);return ow()(Pw(t,n),ag(Jh))},toCodecJson:()=>dw()(J,Aw),toFormatter:()=>e=>e.toString()}),Iw=J.annotate({expected:`a string that will be decoded as a DateTime.Utc`}).pipe(X(Fw,Aw)),Lw=wC(cC,{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:()=>pC,toCodec:()=>dw()($C(QC([J,J])),Ig({decode:uC,encode:e=>e.params}))}).pipe(X(XC(J,nw([J,ew(J)])),Ig({decode:xC,encode:dC}))),Rw=globalThis.Symbol.for(`immer-draftable`),zw={};function Bw(e,t,n,r,i){let a=Uw(n,t,r),o=Hw(t),s=class extends e{constructor(...[e,t]){let r=t?.[`~payload`],i=r?.token===zw?r.value:n.make(e??{},t);super(i,{...t,disableChecks:!0,"~payload":{token:zw,value:i}})}static[SC]=SC;get[o](){return o}static[Rw]=!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 Zb(a(this))(e??{},t)}static makeOption(e,t){return Xb(a(this))(e??{},t)}static makeEffect(e,t){return a(this).makeEffect(e??{},t)}static annotate(e){return this.rebuild(Sv(this.ast,e))}static annotateKey(e){return this.rebuild(Mv(this.ast,e))}static check(...e){return this.rebuild(wv(this.ast,e))}static extend(e){return(t,r)=>{let a=Ww(t)?t:Y(t),o={...n.fields,...a.fields},s=G_(o,n.ast.checks,{identifier:e});return Bw(this,e,JC(wv(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 Vw(e){return new Mg(ag(t=>new e(t,{"~payload":{token:zw,value:t}})),ig())}function Hw(e){return`~effect/Schema/Class/${e}`}function Uw(e,t,n){let r;return i=>{if(r!==void 0)return r;let a=Hw(t),o=e=>e instanceof i||w(e,a),s=Vw(i);return r=X(q(new d_([e.ast],()=>(e,t,n)=>o(e)?B(e):V(new wh(t,e,n)),{identifier:t,[rh]:([e])=>({isConstructed:o,link:new o_(e,s)}),toCodec:([e])=>new o_(e.ast,s),toEquivalence:([e])=>e,toFormatter:([e])=>t=>`${i.identifier}(${e(t)})`,[nh]:Z_(e.ast),...n})),s)(e)}}function Ww(e){return IC(e)}var Gw=e=>(t,n)=>Bw(Vi,e,Ww(t)?t:Y(t),n,e=>({name:e})),Kw=e=>(t,n,r)=>{let i=Ww(n)?n.mapFields(e=>({_tag:cw(t),...e}),{unsafePreserveChecks:!0}):lw(t,n);return Gw(e??t)(i,r)},qw=Px,Jw=Vx,Yw=Hx,Xw=q(Sv(hy,{toCode:()=>({runtime:`Schema.Json`,Type:`Schema.Json`})})),Zw=(e,t)=>()=>{let n=NC(ew(e),t);return db((e,t)=>B(H(e,e=>n(e))))},Qw=`~effect/Stream`,$w={_R:C,_E:C,_A:C},eT=function(e){this.channel=e};eT.prototype={[Qw]:$w,pipe(){return x(this,arguments)}};var tT=e=>new eT(e),nT=`~effect/Stream`,rT=e=>w(e,nT),iT=tT,aT=e=>iT(vb(U(e,no))),oT=(e,t)=>iT(db((n,r)=>H(Nb(e.channel,r),e=>t(e,r)))),sT=e=>iT(gb(()=>e().channel)),cT=e=>iT(_b(e)),lT=e=>iT(yb(e)),uT=S(2,(e,t)=>sT(()=>{let n=0;return iT(xb(e.channel,ro(e=>t(e,n++))))})),dT=S(2,(e,t)=>iT(Cb(e.channel,t))),fT=S(2,(e,t)=>e.channel.pipe(Eb(e=>t(e).channel),iT)),pT=S(2,(e,t)=>iT(Db(e.channel,t))),mT=S(e=>rT(e[0]),(e,t)=>sT(()=>{let n=new TextDecoder(t?.encoding);return uT(e,e=>n.decode(e,{stream:!0}))})),hT=e=>sT(()=>{let t=new TextEncoder;return uT(e,e=>t.encode(e))}),gT=S(2,(e,t)=>iT(kb(e.channel,t))),_T=S(2,(e,t)=>iT(jb(e.channel,t))),vT=S(2,(e,t)=>Mb(e.channel,t)),yT=S(e=>rT(e[0]),(e,t,n)=>{let r,i,a=wy(!1);return new ReadableStream({start(n){i=Bm(Om(vT(e,e=>a.whenOpen(tm(()=>{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(Tf(e.cause)):n.close()})},pull(){return new Promise(e=>{r=e,a.openUnsafe()})},cancel(){if(i)return Hm(gm(xy(i)))}},n?.strategy)}),bT=S(e=>rT(e[0]),(e,t)=>U(Tm(),n=>yT(e,n,t))),xT=`~effect/ErrorReporter/ignore`,ST=S(2,(e,t)=>e===void 0?void 0:t(e)),CT=(e,t)=>[...new Set([...e.errors,...t??[]])],wT=/^[A-Za-z0-9_-]+$/,TT=(e,t)=>{if(!wT.test(t)||t===`then`)throw Error(`Invalid ${e}: ${t}`)},ET=(e,t)=>{let n=new Set;for(let r of t){if(n.has(r))throw Error(`Duplicate ${e}: ${r}`);n.add(r)}},DT=XC(J,VC);function OT(e,t){TT(`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&&TT(`MCP name`,i.name),{name:e,description:t.description,input:t.input??DT,success:t.success,errors:t.errors??[],access:n,http:t.http!==!1,mcp:i}}var kT=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)}},AT=(e,t,n,r)=>{let i=n[t.name];if(i===void 0)throw Error(`Missing handler: ${t.name}`);let a={"action.group":e.name,"action.name":t.name,"action.access":t.access};return n=>{let o=Lm(Km(em(()=>i(n)),a),`${e.name}.${t.name}`,{captureStackTrace:!1,attributes:a});return r===void 0?o:H(r(t),()=>o)}};function jT(e,...t){let{name:n}=e;TT(`action group name`,n);let r=t.map(t=>({...t,errors:[...t.errors,...e.errors??[]]}));ET(`action`,r.map(e=>e.name)),ET(`MCP tool`,r.flatMap(e=>e.mcp===!1?[]:[e.mcp.name]));let i={name:n,actions:r,schemaError:e.schemaError,implement:e=>{let t=Xp(e)?e:B(e);return kT.make(i,t)}};return i}var MT=`~effect/http/HttpBody`,NT=e=>w(e,MT),PT=class{[MT];constructor(){this[MT]=MT}[qr](){return this.toJSON()}toString(){return D(this,{ignoreToString:!0})}},FT=new class extends PT{_tag=`Empty`;toJSON(){return{_id:`effect/HttpBody`,_tag:`Empty`}}},IT=class extends PT{_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??=BT(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}}},LT=(e,t)=>new IT(e,t??`application/octet-stream`,e.length),RT=new TextEncoder,zT=globalThis.Buffer,BT=zT===void 0?e=>RT.encode(e):e=>zT.from(e,`utf8`),VT=(e,t)=>{if(typeof e!=`string`&&(e=e===void 0?``:String(e)),zT!==void 0)return new IT(void 0,t??`text/plain`,zT.byteLength(e,`utf8`),e);let n=RT.encode(e);return new IT(n,t??`text/plain`,n.length,e)},HT=(e,t)=>VT(JSON.stringify(e),t??`application/json`),UT=(e,t)=>VT(yC(dC(e)),t??`application/x-www-form-urlencoded`),WT=class extends PT{_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}}},GT=e=>new WT(e),KT=class extends PT{_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}}},qT=(e,t,n)=>new KT(e,t??`application/octet-stream`,n),JT=`~effect/http/HttpClientError`,YT=class extends nc(`HttpClientError`){constructor(e){`cause`in e.reason?super({...e,cause:e.reason.cause}):super(e)}[JT]=JT;get request(){return this.reason.request}get response(){return`response`in this.reason?this.reason.response:void 0}get message(){return this.reason.message}},XT=e=>e.endsWith(`Error`)?e.slice(0,-5):e,ZT=(e,t,n)=>t?`${e}: ${t} (${n})`:`${e} error (${n})`,QT=class extends nc(`TransportError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return ZT(XT(this._tag),this.description,this.methodAndUrl)}},$T=class extends nc(`InvalidUrlError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){return ZT(XT(this._tag),this.description,this.methodAndUrl)}},eE=class extends nc(`StatusCodeError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return ZT(XT(this._tag),this.description,e)}},tE=class extends nc(`DecodeError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return ZT(XT(this._tag),this.description,e)}},nE=class extends nc(`EmptyBodyError`){get methodAndUrl(){return`${this.request.method} ${this.request.url}`}get message(){let e=`${this.response.status} ${this.methodAndUrl}`;return ZT(XT(this._tag),this.description,e)}},rE=e=>e!==`GET`&&e!==`HEAD`&&e!==`OPTIONS`&&e!==`TRACE`,iE=[[`GET`,`get`],[`POST`,`post`],[`PUT`,`put`],[`DELETE`,`del`],[`PATCH`,`patch`],[`HEAD`,`head`],[`OPTIONS`,`options`],[`TRACE`,`trace`],[`QUERY`,`query`]],aE=(e,t)=>t._tag===`Empty`||t._tag===`FormData`?rC(rC(e,`content-type`),`content-length`):(e=t.contentType===void 0?rC(e,`content-type`):eC(e,`content-type`,t.contentType),t.contentLength===void 0?rC(e,`content-length`):eC(e,`content-length`,t.contentLength.toString())),oE=class extends nc(`UrlError`){},sE=(e,t,n)=>Ia({try:()=>{let r=new URL(e,cE());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 oE({cause:e})}),cE=()=>{if(`location`in globalThis&&globalThis.location!==void 0&&globalThis.location.origin!==void 0&&globalThis.location.pathname!==void 0)return location.origin+location.pathname},lE=`~effect/http/HttpClientRequest`,uE={[lE]:lE,...Yr,toJSON(){return{_id:`HttpClientRequest`,method:this.method,url:this.url,urlParams:this.urlParams,hash:this.hash,headers:Fr(this.headers),body:this.body.toJSON()}},pipe(){return x(this,arguments)}};function dE(e,t,n,r,i,a){let o=Object.create(uE);return o.method=e,o.url=t,o.urlParams=n,o.hash=r,o.headers=i,o.body=a,o}var fE=dE(`GET`,``,hC,wa(),ZS,FT),pE=e=>(t,n)=>mE(fE,{method:e,url:t,...n??void 0}),mE=S(2,(e,t)=>{let n=e;return t.method&&(n=hE(n,t.method)),t.url&&(n=bE(n,t.url)),t.headers&&(n=_E(n,t.headers)),t.urlParams&&(n=CE(n,t.urlParams)),t.hash&&(n=TE(n,t.hash)),t.body&&(n=EE(n,t.body)),t.accept&&(n=vE(n,t.accept)),t.acceptJson&&(n=yE(n)),n}),hE=S(2,(e,t)=>dE(t,e.url,e.urlParams,e.hash,e.headers,e.body)),gE=S(3,(e,t,n)=>dE(e.method,e.url,e.urlParams,e.hash,eC(e.headers,t,n),e.body)),_E=S(2,(e,t)=>dE(e.method,e.url,e.urlParams,e.hash,tC(e.headers,t),e.body)),vE=S(2,(e,t)=>gE(e,`Accept`,t)),yE=vE(`application/json`),bE=S(2,(e,t)=>{if(typeof t==`string`)return dE(e.method,t,e.urlParams,e.hash,e.headers,e.body);let n=new URL(t.toString()),r=dC(n.searchParams),i=Aa(n.hash===``?void 0:n.hash.slice(1));return n.search=``,n.hash=``,dE(e.method,n.toString(),r,i,e.headers,e.body)}),xE=S(2,(e,t)=>t===``?e:dE(e.method,SE(t,e.url),e.urlParams,e.hash,e.headers,e.body)),SE=(e,t)=>{let n=e.endsWith(`/`),r=t.startsWith(`/`);return n&&r?e+t.slice(1):!n&&!r?e+`/`+t:e+t},CE=S(2,(e,t)=>dE(e.method,e.url,_C(e.urlParams,t),e.hash,e.headers,e.body)),wE=S(2,(e,t)=>dE(e.method,e.url,vC(e.urlParams,t),e.hash,e.headers,e.body)),TE=S(2,(e,t)=>dE(e.method,e.url,e.urlParams,Ta(t),e.headers,e.body)),EE=S(2,(e,t)=>dE(e.method,e.url,e.urlParams,e.hash,aE(e.headers,t),t)),DE=S(2,(e,t)=>EE(e,GT(t)));function OE(e){let t=sE(e.url,e.urlParams,ja(e.hash));return Ra(t)?Ta(t.success):wa()}var kE=`~effect/http/HttpIncomingMessage`,AE=N(`effect/http/HttpIncomingMessage/MaxBodySize`,{defaultValue:()=>void 0}),jE=(e,t)=>{let n=e.headers[`content-type`]??``,r;if(n.includes(`application/json`))try{r=Um(e.json)}catch{}else if(n.includes(`text/`)||n.includes(`urlencoded`))try{r=Um(e.text)}catch{}let i={...t,headers:Fr(e.headers),remoteAddress:e.remoteAddress};return r!==void 0&&(i.body=r),i},ME=`~effect/http/HttpClientResponse`,NE=(e,t)=>new PE(e,t),PE=class extends Xr{[kE];[ME];request;source;constructor(e,t){super(),this.request=e,this.source=t,this[kE]=kE,this[ME]=ME}toJSON(){return jE(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=OE(this.request);return Ea(e)?``:(e.value.hash=``,e.value.href)}get headers(){return QS(this.source.headers)}cachedCookies;get cookies(){return this.cachedCookies?this.cachedCookies:this.cachedCookies=VS(this.source.headers.getSetCookie())}get remoteAddress(){return wa()}get stream(){return this.source.body?lT({evaluate:()=>this.source.body,onError:e=>new YT({reason:new tE({request:this.request,response:this,cause:e})})}):cT(new YT({reason:new nE({request:this.request,response:this,description:`can not create stream from empty body`})}))}get json(){return H(this.text,e=>sm({try:()=>e===``?null:JSON.parse(e),catch:e=>new YT({reason:new tE({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=>sm({try:()=>dC(new URLSearchParams(e)),catch:e=>new YT({reason:new tE({request:this.request,response:this,cause:e})})}))}formDataBody;get formData(){return this.formDataBody??=$p({try:()=>this.source.formData(),catch:e=>new YT({reason:new tE({request:this.request,response:this,cause:e})})}).pipe(Mm,Um)}arrayBufferBody;get arrayBuffer(){return this.arrayBufferBody||=$p({try:()=>this.source.arrayBuffer(),catch:e=>new YT({reason:new tE({request:this.request,response:this,cause:e})})}).pipe(Mm,Um),this.arrayBufferBody}pipe(){return x(this,arguments)}},FE=e=>$S({b3:`${e.traceId}-${e.spanId}-${e.sampled?`1`:`0`}${Oa(e.parent,{onNone:()=>``,onSome:e=>`-${e.spanId}`})}`,traceparent:`00-${e.traceId}-${e.spanId}-${e.sampled?`01`:`00`}`}),IE=`~effect/http/HttpClient`,LE=M(`effect/HttpClient`),RE=S(2,(e,t)=>zE(n=>t(e.postprocess(n)),e.preprocess)),zE=(e,t)=>{let n=Object.create(BE);return n.preprocess=t,n.postprocess=e,n.execute=function(n){return e(t(n))},n},BE={[IE]:IE,pipe(){return x(this,arguments)},...Yr,toJSON(){return{_id:`effect/HttpClient`}},...Object.fromEntries(iE.map(([e,t])=>[t,function(t,n){return this.execute(pE(e)(t,n))}]))},VE=e=>zE(t=>H(t,t=>cm(n=>{let r=YE.get(t),i=r??new AbortController,a=sE(t.url,t.urlParams,ja(t.hash));if(La(a))return V(new YT({reason:new $T({request:t,cause:a.failure})}));let o=a.success;if(n.getRef(Cc)||n.getRef(UE)(t)){let a=e(t,o,i.signal,n);return r?a:Pm(e=>wm(e(a),{onSuccess(e){return JE.register(e,i),B(new XE(e,i))},onFailure(e){return Ef(e)&&i.abort(),im(e)}}))}return Im(n.getRef(KE)(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(oC),l=n.getRef(WE);for(let e in t.headers)l(e,`request`)&&a.attribute(`http.request.header.${e}`,aC(e,c)?`<redacted>`:t.headers[e]);return t=n.getRef(GE)?_E(t,FE(a)):t,Pm(s=>s(e(t,o,i.signal,n)).pipe(Rm(a,{captureStackTrace:!1}),wm({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}`,aC(t,c)?`<redacted>`:e.headers[t]);return r?B(e):(JE.register(e,i),B(new XE(e,i)))},onFailure(e){return!r&&Ef(e)&&i.abort(),im(e)}})))})})),B),HE=S(2,(e,t)=>zE(e.postprocess,n=>U(e.preprocess(n),t))),UE=N(`effect/http/HttpClient/TracerDisabledWhen`,{defaultValue:()=>Tn}),WE=N(`effect/http/HttpClient/TracerHeaderFilter`,{defaultValue:()=>wn}),GE=N(`effect/http/HttpClient/TracerPropagationEnabled`,{defaultValue:wn}),KE=N(`effect/http/HttpClient/SpanNameGenerator`,{defaultValue:()=>e=>`http.client ${e.method}`}),qE=e=>fp(LE)(Em(t=>U(e,e=>RE(e,km(e=>cs(t,e)))))),JE=(()=>{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))}}})(),YE=new WeakMap,XE=class{original;controller;constructor(e,t){this.original=e,this.controller=t}[ME]=ME;[kE]=kE;applyInterrupt(e){return em(()=>(JE.unregister(this.original),Nm(e,()=>tm(()=>{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 sT(()=>(JE.unregister(this.original),gT(this.original.stream,tm(()=>{this.controller.abort()}))))}toJSON(){return this.original.toJSON()}[qr](){return this.original[qr]()}pipe(){return x(this,arguments)}},ZE=N(`effect/http/FetchHttpClient/Fetch`,{defaultValue:()=>globalThis.fetch}),QE=class extends M()(`effect/http/FetchHttpClient/RequestInit`){},$E=qE(B(VE((e,t,n,r)=>{let i=r.getRef(ZE),a=es(r.context,QE)??{},o=a.headers?nC(QS(a.headers),e.headers):e.headers;o[`content-length`]&&(o=rC(o,`content-length`));let s=r=>U($p({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 YT({reason:new QT({request:e,cause:t})})}),t=>NE(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(bT(e.body.stream),s)}return s(void 0)}))),eD=Object.getPrototypeOf(ZS),tD=()=>Object.create(eD),nD=`~effect/http/HttpServerResponse`,rD=e=>w(e,nD),iD=e=>mD({status:e?.status??204,statusText:e?.statusText,headers:e?.headers?QS(e.headers):void 0,cookies:e?.cookies}),aD=(e,t)=>{let n=t?.headers?QS(t.headers):ZS;return mD({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies??US,body:LT(e,oD(t,n))})},oD=(e,t)=>{if(e?.contentType)return e.contentType;if(e?.headers)return t[`content-type`]},sD=(e,t)=>{let n=t?.headers?QS(t.headers):ZS;return mD({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies??US,body:VT(e,oD(t,n))})},cD=(e,t)=>{let n=t?.headers?QS(t.headers):ZS;return mD({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies,body:HT(e,oD(t,n))})},lD=(e,t)=>{let n=t?.headers?QS(t.headers):ZS;return mD({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies,body:VT(yC(dC(e)),oD(t,n)??`application/x-www-form-urlencoded`)})},uD=(e,t)=>{let n=t?.headers?QS(t.headers):ZS;return mD({status:t?.status??200,statusText:t?.statusText,headers:n,cookies:t?.cookies,body:qT(e,oD(t,n),t?.contentLength)})},dD=S(3,(e,t,n)=>mD(e,eC(e.headers,t,n))),fD=S(2,(e,t)=>mD(e,tC(e.headers,t))),pD={...ui,[nD]:nD,[xT]:!0,toJSON(){return{_id:`HttpServerResponse`,status:this.status,statusText:this.statusText,headers:Fr(this.headers),cookies:this.cookies.toJSON(),body:this.body.toJSON()}}},mD=(e,t)=>{let n=Object.create(pD);if(n.status=e.status,n.statusText=e.statusText,n.cookies=e.cookies??US,n.body=e.body??FT,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===ZS?tD():$S({...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??ZS;return n},hD=`~effect/http/HttpServerRespondable`,gD=new Uint8Array(256);for(let e of"!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")gD[e.charCodeAt(0)]=1;var _D=new Uint8Array(256);_D[9]=1;for(let e=32;e<=126;e++)_D[e]=1;for(let e=128;e<=255;e++)_D[e]=1;var vD=e=>{let t=new Map;return e.maxParts!==void 0&&t.set(yD.key,e.maxParts),e.maxFieldSize!==void 0&&t.set(bD.key,Og(e.maxFieldSize)),e.maxFileSize!==void 0&&t.set(xD.key,Og(e.maxFileSize)),e.maxTotalSize!==void 0&&t.set(AE.key,Og(e.maxTotalSize)),e.fieldMimeTypes!==void 0&&t.set(SD.key,e.fieldMimeTypes),Uo(t)},yD=N(`effect/http/Multipart/MaxParts`,{defaultValue:()=>void 0}),bD=N(`effect/http/Multipart/MaxFieldSize`,{defaultValue:Cn(kg(10))}),xD=N(`effect/http/Multipart/MaxFileSize`,{defaultValue:()=>void 0}),SD=N(`effect/http/Multipart/FieldMimeTypes`,{defaultValue:Cn([`application/json`])}),CD=M(`effect/http/HttpServerRequest`),wD=class extends M()(`effect/http/ParsedSearchParams`){},TD=(e,t)=>{let n=MC(e);return H(CD,e=>n(e.cookies,t))},ED=(e,t)=>{let n=MC(e);return H(CD,e=>n(e.headers,t))},DD=(e,t)=>{let n=MC(e);return H(wD,e=>n(e,t))},OD=new WeakSet,kD=e=>cm(t=>{let n=ns(t.context,CD);return OD.add(n.source),e}),AD=M(`effect/http/HttpRouter`),jD=class extends M()(`effect/http/HttpRouter/RouteContext`){},MD=e=>hp(H(AD,e)),ND=`~effect/http/HttpRouter/Route`,PD=e=>({...e,uninterruptible:e.uninterruptible??!1,prefix:typeof e.prefix==`string`?Ta(e.prefix):e.prefix??wa(),[ND]:ND}),FD=(e,t,n,r)=>PD({...r,method:e,path:t,handler:rD(n)?B(n):Xp(n)?n:H(CD,n),uninterruptible:r?.uninterruptible??!1}),ID=e=>e.endsWith(`/`)?e.slice(0,-1):e,LD=S(2,(e,t)=>(t=ID(t),e===`*`?`${t}/*`:e===`/`?t:t+e)),RD=`~effect/http/HttpRouter/Middleware`,zD=function(){return arguments.length===0?BD:BD(arguments[0],arguments[1])},BD=(e,t)=>t?.global?hp(rm(function*(){let t=yield*AD,n=Xp(e)?yield*e:e;yield*t.addGlobalMiddleware(n)})):new UD(Xp(e)?mp(U(e,e=>Uo(new Map([[HD,e]])))):up(Uo(new Map([[HD,e]])))),VD=0,HD=`effect/http/HttpRouter/MiddlewareFn`,UD=class e{[RD]={};layerFn;dependencies;constructor(e,t){this.layerFn=e,this.dependencies=t;let n=`effect/http/HttpRouter/Middleware-${++VD}`;this.layer=mp(rm({self:this},function*(){let e=yield*Tm(),t=[ts(e,HD)];if(this.dependencies){let n=yield*op,r=rs(e,Hf),i=yield*sp(this.dependencies,n,r);t.push(...GD(i))}return Uo(new Map([[n,t]]))})).pipe(xp(this.layerFn))}layer;combine(t){return new e(this.layerFn,this.dependencies?Sp(this.dependencies,t.layer):t.layer)}},WD=new WeakMap,GD=e=>{let t=WD.get(e);if(t)return t;let n=to(),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=Ya(e).reverse()}return WD.set(e,t),t};zD(kD).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},qD=e=>KD[e],JD=`~effect/encoding/Sse/SseError`,YD=class extends nc(`EventTooLarge`){get message(){return`Pending SSE event exceeded the maximum size of ${this.maxEventSize}`}},XD=class extends nc(`SseError`){[JD]=JD;get message(){return this.reason.message}},ZD=10485760,QD=e=>db((t,n)=>tm(()=>{let n=[],r,i=eO(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 nm});return em(function e(){if($a(n)){let e=n;return n=[],B(e)}return r?V(r):H(a,e)})})),$D=(e,t,n)=>Db(QD(t),Zw(nO.pipe(X(e,rO)),n)());function eO(e,t){let n=t?.maxEventSize??ZD,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(tO)&&(i=i.slice(tO.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 XD({reason:new YD({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 aO({duration:Ns(parseInt(p,10)),lastEventId:c}))}}var tO=``,nO=Y({_tag:cw(`Event`),id:aw(J),event:J,data:J}),rO=Ig({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})}),iO=`~effect/encoding/Sse/Retry`,aO=class e extends tc(`Retry`){[iO]=iO;static is(e){return w(e,iO)}static filter(t){return e.is(t)?Pa(t):Fa(t)}},oO={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: ${zs(e.duration)}\n\n`}}},sO=`~effect/httpapi/HttpApiSchema/Stream`;function cO(e){let t=typeof e==`string`?qD(e):e;return e=>e.annotate({httpApiStatus:t})}var lO=(e=>qC.pipe(cO(e)))(204),uO=e=>IC(e)&&w(e,sO),dO=e=>uO(e)&&e._tag===`StreamSse`,fO=e=>uO(e)&&e._tag===`StreamUint8Array`,pO=`~effect/httpapi/HttpApiSchema/WithHeaders`,mO=`~effect/httpapi/HttpApiSchema/WithHeadersValue`,hO=e=>w(e,mO),gO=e=>({[mO]:mO,body:e.body,headers:e.headers}),Z=e=>IC(e)&&w(e,`~effect/httpapi/HttpApiSchema/WithHeaders`);function _O(e,t,n){return q(e.ast,{[pO]:pO,schema:t,headers:n})}function vO(e,t){return e.annotate({"~httpApiEncoding":{_tag:t._tag,contentType:t.contentType??yO(t._tag)}})}function yO(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 bO(e){return t=>vO(t,{_tag:`FormUrlEncoded`,...e})}var xO=e=>{if(Qg(e)||Qg(Gv(e)))return!0;let t=e.encoding?.[0].to;return t!==void 0&&Qg(t)},SO=cy(`~httpApiEncoding`),CO=cy(`~httpApiWithHeaders`),wO=cy(`httpApiStatus`),TO={_tag:`Json`,contentType:`application/json`},EO={_tag:`FormUrlEncoded`,contentType:`application/x-www-form-urlencoded`};function DO(e){return SO(e)??TO}function OO(e,t){return SO(e)||(rE(t)?TO:EO)}function kO(e){let t=DO(e);if(t._tag===`Multipart`)throw Error(`Multipart is not supported in response`);return t}function AO(e){return wO(e)??200}function jO(e){return Z(e)?wO(e.ast)??AO(e.schema.ast):AO(e.ast)}function MO(e){return Z(e)&&SO(e.ast)===void 0?kO(e.schema.ast):kO(e.ast)}function NO(e){return wO(e)??500}function PO(e){return Z(e)?wO(e.ast)??NO(e.schema.ast):NO(e.ast)}function FO(e){let t=e.toLowerCase().trim(),n=t.indexOf(`;`);return n===-1?t:t.slice(0,n).trim()}var IO=`~effect/httpapi/HttpApiEndpoint`;function LO(e){let t=[];for(let{schemas:n}of e.payload.values())t.push(...n);return t}function RO(e){let t=Array.from(e.success);return $a(t)?t:[lO]}function zO(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 BO={[IO]:IO,pipe(){return x(this,arguments)},prefix(e){return HO({...VO(this),path:LD(this.path,e)})},middleware(e){return HO({...VO(this),middlewares:new Set([...this.middlewares,e])})},annotate(e,t){return HO({...VO(this),annotations:Zo(this.annotations,e,t)})},annotateMerge(e){return HO({...VO(this),annotations:cs(this.annotations,e)})}},VO=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 HO(e){function t(){}return Object.setPrototypeOf(t,BO),Object.assign(t,e)}var UO=e=>(t,n,r)=>{let i=r?.disableCodecs??!1,a=i?C:Jw;return HO({identifier:t,path:n,method:e,params:WO(r?.params,a),query:WO(r?.query,a),headers:WO(r?.headers,a),payload:GO(r?.payload,e,i),success:qO(r?.success,e,i),error:YO(r?.error,i),annotations:Jo(),middlewares:new Set,disableCodecs:i})};function WO(e,t){if(e!==void 0)return IC(e)?t(e):t(Y(e))}function GO(e,t,n){let r=new Map;if(e===void 0)return r;let i=Array.isArray(e)?e:IC(e)?[e]:[Y(e).pipe(bO())],a=n?C:ak;for(let e of i){let n=OO(e.ast,t),i=FO(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 qO(e,t,n){if(e===void 0)return new Set;let r=Xa(e);return XO(r,t),new Set(n?r:r.map(JO))}var JO=On(e=>uO(e)?e:Z(e)?_O(e,uO(e.schema)?e.schema:ik(e.schema,MO(e)),Jw(e.headers)):rk(e));function YO(e,t){if(e===void 0)return new Set;let n=Xa(e);for(let e of n)if(uO(Z(e)?e.schema:e))throw Error(`Streaming schemas are not supported in error responses`);return QO(n,PO),new Set(t?n:n.map(JO))}function XO(e,t){let n=!1,r=new Map;for(let i of e){let e=Z(i)?i.schema:i,a=jO(i);if(uO(e)){if($O(e,t),n)throw Error(`Multiple streaming success responses are not supported`);n=!0;let i=ZO(r,a);if(i.noContent)throw Error(`Cannot combine no-content and streaming success responses for status: ${a}`);if(i.bufferedContentTypes.has(FO(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=ZO(r,a),n=xO(e.ast);if(t.stream!==void 0){if(n)throw Error(`Cannot combine no-content and streaming success responses for status: ${a}`);let e=MO(i);if(FO(e.contentType)===FO(t.stream.contentType))throw Error(`Cannot combine buffered and streaming success responses for status ${a} and content-type: ${e.contentType}`)}n||t.bufferedContentTypes.add(FO(MO(i).contentType)),t.noContent=t.noContent||n}}QO(e,jO)}function ZO(e,t){let n=e.get(t);return n===void 0&&(n={bufferedContentTypes:new Set,noContent:!1},e.set(t,n)),n}function QO(e,t){let n=new Map;for(let r of e){let e=t(r),i=CO(r.ast),a=Z(r)?r.schema:i?.body??r,o=xO(a.ast)?``:FO(uO(a)?a.contentType:MO(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 $O(e,t){if(t===`HEAD`)throw Error(`HEAD endpoints cannot declare streaming success responses`);if(dO(e)&&ek(e.events.ast))throw Error(`SSE event name is reserved: ${KO}`)}function ek(e){return tk(Gv(e),new Set)}function tk(e,t){if(t.has(e))return!1;if(t.add(e),i_(e))return e.types.some(e=>tk(e,t));if(a_(e))return tk(e.thunk(),t);if(!r_(e))return!1;let n=e.propertySignatures.find(e=>e.name===`event`);return n!==void 0&&nk(n.type,t)}function nk(e,t){if(t.has(e))return!1;t.add(e);let n=Gv(e);return n===e?e_(e)?e.literal===KO:i_(e)?e.types.some(e=>nk(e,t)):a_(e)?nk(e.thunk(),t):!1:nk(n,t)}function rk(e){let t=kO(e.ast),n=CO(e.ast);if(n===void 0)return ik(e,t);let r=zC(n.headers);return Y({body:ik(zC(n.body),t),headers:r}).pipe(X(e)).annotate({"~httpApiWithHeaders":{...n,headersCodec:Jw(r)}})}function ik(e,t){switch(t._tag){case`Json`:return qw(e);case`FormUrlEncoded`:return Jw(e);case`Text`:case`Uint8Array`:return e}}function ak(e,t){switch(OO(e.ast,t)._tag){case`Json`:return qw(e);case`FormUrlEncoded`:return Jw(e);case`Text`:case`Uint8Array`:case`Multipart`:return e}}var ok=UO(`POST`),sk=`~effect/httpapi/HttpApi`,ck={[sk]:sk,pipe(){return x(this,arguments)},add(...e){let t={...this.groups};for(let n of e)E(t,n.identifier,n);return uk({...lk(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(cs(e.annotations,r.annotations)))}return uk({...lk(this),groups:t})},prefix(e){return uk({...lk(this),groups:Wa(this.groups,t=>t.prefix(e))})},middleware(e){return uk({...lk(this),groups:Wa(this.groups,t=>t.middleware(e))})},annotate(e,t){return uk({...lk(this),annotations:Zo(this.annotations,e,t)})},annotateMerge(e){return uk({...lk(this),annotations:cs(this.annotations,e)})}},lk=e=>({identifier:e.identifier,groups:e.groups,annotations:e.annotations}),uk=e=>{function t(){}return Object.setPrototypeOf(t,ck),Object.assign(t,e)},dk=e=>uk({identifier:e,groups:{},annotations:Jo()}),fk=(e,t)=>{let n=Object.values(e.groups);for(let r of n){let n=cs(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:cs(n,e.annotations),successes:pk(RO(e),jO),errors:pk(zO(e),PO)})}},pk=(e,t)=>{let n=new Map;return e.forEach(r),n;function r(e){if(uO(Z(e)?e.schema:e))return;let r=t(e),i=n.get(r);i===void 0?n.set(r,[e]):i.push(e)}},mk=class extends M()(`effect/httpapi/HttpApi/AdditionalSchemas`){},hk=class extends M()(`effect/httpapi/HttpApi/ParseOptions`){},gk=iD({status:400}),_k=`~effect/httpapi/HttpApiError/HttpApiSchemaError`,vk=class e extends tc(`HttpApiSchemaError`){[_k]=_k;static is(e){return w(e,_k)}static wrap(t,n){return Jm(n,n=>new e({kind:t,cause:n}))}name=`HttpApiSchemaError`;message=this.kind;[hD](){return B(gk)}},yk=`~effect/httpapi/HttpApiMiddleware`,bk=`~effect/httpapi/HttpApiMiddleware/Security`,xk=e=>w(e,bk),Sk=()=>(e,t)=>{let n=Qr(),r;n!==0&&($r(2),r=new globalThis.Error,$r(n));class i extends M()(e){}let a=i;if(Object.defineProperty(i,"stack",{get(){return r?.stack}}),a[yk]=yk,a.error=Ck(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[bk]=bk,a.security=t.security}return a};function Ck(e){return e===void 0?new Set:new Set(Array.isArray(e)?e:[e])}var wk=(e,t)=>lp(e,(e,n)=>_m(e,e=>vk.is(e)?t(e,n):V(e))),Tk=new Set;function Ek(e){if(e===void 0)return Tk;let t=xv(e.ast);return r_(t)&&t.indexSignatures.length===0?new Set(t.propertySignatures.map(e=>String(e.name))):void 0}function Dk(e,t){if(t===void 0||!e.includes(`:`))return e;let n=Ek(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 Ok=class extends M()(`effect/httpapi/OpenApi/Identifier`){},kk=class extends M()(`effect/httpapi/OpenApi/Title`){},Ak=class extends M()(`effect/httpapi/OpenApi/Version`){},jk=class extends M()(`effect/httpapi/OpenApi/Description`){},Mk=class extends M()(`effect/httpapi/OpenApi/License`){},Nk=class extends M()(`effect/httpapi/OpenApi/ExternalDocs`){},Pk=class extends M()(`effect/httpapi/OpenApi/Servers`){},Fk=class extends M()(`effect/httpapi/OpenApi/Format`){},Ik=class extends M()(`effect/httpapi/OpenApi/Summary`){},Lk=class extends M()(`effect/httpapi/OpenApi/Deprecated`){},Rk=class extends M()(`effect/httpapi/OpenApi/Override`){},zk=N(`effect/httpapi/OpenApi/Exclude`,{defaultValue:Tn}),Bk=class extends M()(`effect/httpapi/OpenApi/Transform`){},Vk={},Hk=new WeakMap,Uk=e=>{if(Array.isArray(e))return e.map(Uk);if(typeof e==`object`&&e&&!Object.isFrozen(e)){let t={};for(let n of Object.keys(e))E(t,n,Uk(e[n]));return t}return e};function Q(e,t,n){let r=ss(e,t);Da(r)&&n(r.value)}function Wk(e,t){let n=t??Vk,r=Hk.get(n);r===void 0&&(r=new WeakMap,Hk.set(n,r));let i=r.get(e);if(i!==void 0)return Uk(i);let a=Gk(e,n);return r.set(e,Uk(a)),a}function Gk(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,kk,e=>{n.info.title=e}),Q(e.annotations,Ak,e=>{n.info.version=e}),Q(e.annotations,jk,e=>{n.info.description=e}),Q(e.annotations,Mk,e=>{n.info.license=e}),Q(e.annotations,Ik,e=>{n.info.summary=e}),Q(e.annotations,Pk,e=>{n.servers=[...e]}),fk(e,{onGroup({group:e}){if(rs(e.annotations,zk))return;let t={name:$o(e.annotations,kk,()=>e.identifier)};Q(e.annotations,jk,e=>{t.description=e}),Q(e.annotations,Nk,e=>{t.externalDocs=e}),Q(e.annotations,Rk,e=>{for(let[n,r]of Object.entries(e))E(t,n,r)}),Q(e.annotations,Bk,e=>{t=e(t)}),n.tags.push(t)},onEndpoint({endpoint:e,group:t,mergedAnnotations:s,middleware:c}){if(rs(s,zk))return;let l={tags:[$o(t.annotations,kk,()=>t.identifier)],operationId:$o(e.annotations,Ok,()=>t.topLevel?e.identifier:`${t.identifier}.${e.identifier}`),parameters:[],security:[],responses:{}},u=Ek(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=xv(e.ast);if(r_(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:!Bv(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,K_),o=a.length===1?a[0]:new iv(a);r.push({_tag:`schema`,ast:Zk(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??={},dO(e)?(r.push({_tag:`schema`,ast:K_(e.events),path:[...h,`responses`,String(n),`content`,t,`schema`]}),r.push({_tag:`schema`,ast:K_(qw(kw(e.error,Sw()))),path:[...h,`responses`,String(n),`content`,t,`x-effect-stream`,`causeSchema`]}),r.push({_tag:`schema`,ast:K_(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=xv(e.ast);if(r_(n))for(let e of n.propertySignatures)l.parameters.push({name:String(e.name),in:t,schema:{},required:t===`path`||!Bv(e.type)}),r.push({_tag:`parameter`,ast:e.type,path:[...h,`parameters`,String(l.parameters.length-1),`schema`]})}}Q(e.annotations,jk,e=>{l.description=e}),Q(e.annotations,Ik,e=>{l.summary=e}),Q(e.annotations,Lk,e=>{l.deprecated=e}),Q(e.annotations,Nk,e=>{l.externalDocs=e}),c.forEach(e=>{if(xk(e))for(let[t,n]of Object.entries(e.security))ee(t,n),l.security.push({[t]:[]})});function ee(e,t){let r=$k(t);if(!Object.hasOwn(n.components.securitySchemes,e)){E(n.components.securitySchemes,e,r);return}if(!ur(eA(n.components.securitySchemes[e]),eA(r)))throw new globalThis.Error(`Conflicting OpenAPI security scheme: ${e}`)}let v=rE(e.method);if(v){let t=new Map;for(let n of LO(e)){if(xO(n.ast))continue;let r=OO(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(K_),o=t.length===1?t[0]:new iv(t);r.push({_tag:`schema`,ast:Zk(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(qk(e),()=>`Success`),g(Jk(zO(e),PO,Yk),()=>`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,Rk,e=>{for(let[t,r]of Object.entries(e))E(n,t,r)}),Q(e.annotations,Bk,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,mk,e=>{e.forEach(e=>{let t=ly(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(gx).join(`/`)}if($a(r)){let e=Cx(gS(yS(ro(r,e=>Fx(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=bS(i,n)}for(let e of o)e();return Object.keys(n.components.schemas).forEach(e=>{if(!wx.test(e))throw new globalThis.Error(`Invalid component schema key: ${e}`)}),Q(e.annotations,Rk,e=>{for(let[t,r]of Object.entries(e))E(n,t,r)}),Q(e.annotations,Bk,e=>{n=e(n)}),n}var Kk=`effect/httpapi/stream/failure`;function qk(e){return Jk(RO(e),jO,Yk)}function Jk(e,t,n){let r=new Map;return e.forEach(i),r;function i(e){let i=CO(e.ast),c=Z(e)?e.schema:i?.body??e,l=Z(e)?e.headers:i?.headersCodec,u=t(e),d=c.ast;uO(c)?s(c,u):xO(d)?a(u,n(e.ast)??n(d)??`<No Content>`):o(c,u,MO(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 Yk(e){return uy(e)??ly(e)}var Xk=J.annotate({format:`binary`});function Zk(e,t){switch(t){case`Uint8Array`:return Xk.ast;case`Text`:return J.ast;case`FormUrlEncoded`:case`Json`:return e;case`Multipart`:return Qk(e)}}function Qk(e){return Xg(e)&&e.annotations?.representation?.id===`effect/http/PersistedFile`?Xk.ast:typeof e?.recur==`function`?e.recur(Qk):e}var $k=e=>{let t={};switch(Q(e.annotations,jk,e=>{t.description=e}),e._tag){case`Basic`:return{...t,type:`http`,scheme:`basic`};case`Http`:{let n=ss(e.annotations,Fk).pipe(Na(e=>({bearerFormat:e})),ja);return{...t,type:`http`,scheme:e.scheme,...n}}case`ApiKey`:return{...t,type:`apiKey`,name:e.key,in:e.in}}},eA=e=>e.type===`http`?{...e,scheme:e.scheme.toLowerCase()}:e.in===`header`?{...e,name:e.name.toLowerCase()}:e,tA=(e,t)=>MD(Gm(function*(n){let r=yield*Tm(),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*om(`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=>cD(Wk(e)));yield*n.add(`GET`,t.openapiPath,tm(()=>r(e)))}})),nA=(e,t,n)=>mp(rm(function*(){let r=(yield*Tm()).pipe(us(Hf)),i=e.groups[t],a=n(lA(i)),o=Xp(a)?yield*a:a,s=[];for(let t of o.handlers.values())s.push(pA(e,i,t,r));return Uo(new Map([[i.key,{routes:s,handlers:o.handlers}]]))})),rA=`~effect/httpapi/HttpApiBuilder/Handlers`,iA=e=>{switch(e._tag){case`Http`:return U(CD,t=>PS(oA(t.headers.authorization,e.scheme)??``));case`ApiKey`:{let t=e.in===`header`?e.key.toLowerCase():e.key,n=Y({[t]:J});return Cm(e.in===`query`?DD(n):e.in===`cookie`?TD(n):ED(n),{onFailure:()=>PS(``),onSuccess:e=>PS(e[t])})}case`Basic`:{let e={username:``,password:PS(``)};return U(CD,t=>{let n=oA(t.headers.authorization,aA);if(n===void 0)return e;let r=Va(sc(n));if(r===void 0)return e;let i=r.indexOf(`:`);return i===-1?e:{username:r.slice(0,i),password:PS(r.slice(i+1))}})}}},aA=`Basic`;function oA(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 sA=(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},cA={[rA]:rA,pipe(){return x(this,arguments)},handle(e,t,n){return sA(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;sA(this,t,e,!1,r)}return this},handleRaw(e,t,n){return sA(this,e,t,!0,n)}},lA=e=>{let t=Object.create(cA);return t.group=e,t.handlers=new Map,t};function uA(e,t){let n=new Map;return e.forEach(({encoding:e,schemas:r},i)=>{let a=MC(nw(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=>Zg(Gv(e.ast)))})}),n}function dA(e,t,n){let r=rE(t.method),i=r?FO(t.headers[`content-type`]??`application/json`):`application/x-www-form-urlencoded`,a=e.get(i);if(!a)return sD(`Unsupported content-type: ${i}`,{status:415});let{_tag:o,decode:s}=a;switch(o){case`Multipart`:if(a.mode===`buffered`){let e=xm(t.multipart);return a.limits&&(e=Om(e,vD(a.limits))),H(e,s)}return B(a.limits?_T(t.multipartStream,vD(a.limits)):t.multipartStream);case`Json`:return H(xm(t.text),e=>{if(e===``)return s(a.nullOnEmpty?null:void 0);try{return s(JSON.parse(e))}catch{return V(new TC(new Th({message:`Expected a valid JSON body`})))}});case`Text`:return H(xm(t.text),s);case`FormUrlEncoded`:return H(r?U(xm(t.urlParamsBody),bC):B(n),s);case`Uint8Array`:return H(U(xm(t.arrayBuffer),e=>new Uint8Array(e)),s)}}function fA(e,t,n,r,i,a){let o=es(cs(cs(e.annotations,t.annotations),n.annotations),hk),s=e=>MC(e,o),c=FC(NA(n),o),l=FC(PA(n),o),u=ST(n.params,s),d=ST(n.headers,s),f=ST(n.query,e=>s(Yw(e))),p=SA(n,o),m=xA(n,o),h=n.payload.size>0&&!a?uA(n.payload,o):void 0;return mA(t,n,r,rm(function*(){let e=Sy().context,r=ns(e,CD),a=ns(e,jD),o=ns(e,wD),s={request:r,endpoint:n,group:t};if(u&&(s.params=yield*vk.wrap(`Params`,u(a.params))),d&&(s.headers=yield*vk.wrap(`Headers`,d(r.headers))),f&&(s.query=yield*vk.wrap(`Query`,f(o))),h){let e=dA(h,r,o);if(rD(e))return e;e!==void 0&&(s.payload=yield*vk.wrap(`Payload`,e))}let l=yield*i(s);if(rD(l))return l;let g;m!==void 0&&hO(l)&&(g=l.headers,l=l.body);let _=yield*vk.wrap(`Body`,p?.(l,e)??(g===void 0?c(l):m.encodeBody(l)));return m===void 0||g===void 0?_:fD(_,yield*vk.wrap(`ResponseHeaders`,m.encodeHeaders.get(_.status)(g)))})).pipe(Sm,_m(e=>vk.is(e)?om(e):xm(l(e))),Om(r))}function pA(e,t,n,r){let i=n.endpoint;return FD(i.method,Dk(i.path,i.params),fA(e,t,i,r,n.handler,n.isRaw),{uninterruptible:n.uninterruptible})}var mA=(e,t,n,r)=>{let i={group:e,endpoint:t};for(let e of t.middlewares){let t=e,a=ns(n,t);r=(xk(t)?gA(t,a):a)(r,i)}return r},hA=new WeakMap,gA=(e,t)=>{let n=hA.get(t);if(n!==void 0)return n;let r=Object.entries(e.security).map(([e,n])=>({decode:iA(n),middleware:t[e]}));if(r.length===0)return C;let i=Gm(function*(e,t){e=bm(e,e=>new vA(e));let n;for(let i=0;i<r.length;i++){let{decode:a,middleware:o}=r[i],s=yield*pm(H(a,n=>o(e,{credential:n,endpoint:t.endpoint,group:t.group})));if(La(s)){if(yA(s.failure))return yield*V(s.failure.error);n=s;continue}return s.success}return yield*lm(n)});return hA.set(t,i),i},_A=`~effect/httpapi/HttpApiBuilder/HandlerError`,vA=class{[_A]=_A;error;constructor(e){this.error=e}},yA=e=>w(e,_A),bA=wC(rD);function xA(e,t){let n=new Map,r=[];for(let i of e.success)Z(i)&&(n.set(jO(i),FC(i.headers,t)),uO(i.schema)||r.push(AA(i)));return n.size===0?void 0:{encodeBody:FC(r.length===0?VC:r.length===1?r[0]:nw(r),t),encodeHeaders:n}}function SA(e,t){let n=CA(e);if(n===void 0)return;let r=n.body,i=wA(e),a=jO(n.schema),o=r.contentType;if(fO(r))return(e,t)=>rT(e)?B(uD(_T(e,t),{status:a,contentType:o})):i?void 0:new TC(new Th({message:`Expected a streaming response`}));let s=TA(r,t);return(e,t)=>rT(e)?B(uD(_T(EA(e,s),t),{status:a,contentType:o})):i?void 0:new TC(new Th({message:`Expected a streaming response`}))}function CA(e){for(let t of e.success){let e=Z(t)?t.schema:t;if(uO(e))return{schema:t,body:e}}}function wA(e){for(let t of e.success){let e=Z(t)?t.schema:t;if(IC(e)&&!uO(e))return!0}return e.success.size===0}function TA(e,t){let n=qw(kw(e.error,Sw()));return{sseMode:e.sseMode,encodeEvents:FC($C(e.events),t),encodeCause:FC(ww(n),t)}}function EA(e,t){return e.pipe(t.sseMode===`data`?uT(e=>({id:void 0,event:`message`,data:e})):C,dT(e=>xm(t.encodeEvents(e))),fT(e=>aT(DA(e,t))),uT(kA),hT)}function DA(e,t){return t.encodeCause(e).pipe(xm,U(e=>({id:void 0,event:OA,data:e})))}var OA=`effect/httpapi/stream/failure`;function kA(e){return oO.write({_tag:`Event`,event:e.event,id:e.id,data:e.data})}var AA=FA(jO),jA=FA(PO);function MA(e){if(!Z(e))return jA(e);let t=FC(e.schema),n=FC(e.headers),r=RA(PO(e),MO(e),xO(e.schema.ast)),i=LA((e,n)=>t(e,n).pipe(bm(e=>e.issue),H(e=>r(e,n))),n);return bA.pipe(X(e,i))}function NA(e){let t=RO(e).map(AA);return t.length===1?t[0]:nw(t)}function PA(e){let t=zO(e).map(MA);return t.length===0?VC:t.length===1?t[0]:nw(t)}function FA(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=bA.pipe(X(a,IA(e,n)));return t.set(r,o),o}}function IA(e,t){let n=CO(t.ast);if(n!==void 0)return LA(RA(e(n.body),kO(n.body.ast),xO(n.body.ast)),FC(n.headersCodec));let r=Z(t)?t.schema:t;return Fg({decode:(e,t)=>V(new Dh({message:`Encode only schema`},e,t)),encode:RA(e(t),MO(t),xO(r.ast))})}function LA(e,t){return Fg({decode:(e,t)=>V(new Dh({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(bm(e=>e.issue)),t=>fD(e,t)))}})}function RA(e,t,n){switch(t._tag){case`Json`:return(r,i)=>{if(r===void 0||n)return B(iD({status:e}));try{return B(sD(JSON.stringify(r),{status:e,contentType:t.contentType}))}catch{return V(new Th({expected:`a JSON-serializable response body`},r,i))}};case`Text`:return n=>B(sD(n,{status:e,contentType:t.contentType}));case`Uint8Array`:return n=>B(aD(n,{status:e,contentType:t.contentType}));case`FormUrlEncoded`:return n=>B(lD(n,{status:e}).pipe(dD(`content-type`,t.contentType)))}}var zA=(e,t)=>rm(function*(){let n=yield*Tm(),r=t.httpClient.pipe(t?.baseUrl===void 0?C:HE(xE(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)}})}fk(e,{predicate:t?.predicate,onGroup(e){t.onGroup?.(e)},onEndpoint(e){let{group:n,endpoint:r,errors:a,successes:o,mergedAnnotations:s}=e,c=es(s,hk),l=UA(r.path,r.params),u={orElse:cj},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,WA(r,c))}for(let[e,t]of d.entries()){let n=qA(t);u[e]=e=>H(ym(n(e),t=>im(wf(vf(new YT({reason:new eE({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,WA(r,c))}for(let e of QA(r)){let t=ZA(e)?e.schema:e;KA(f,jO(e),t.contentType,$A(e,c))}for(let[e,t]of f.entries())u[e]=qA(t);let p=e=>FC(e,c),m=ST(r.params,p),h=LO(r),g=$a(h)?rE(r.method)?p(uj(h,r.method)):p(nw(h)):void 0,_=ST(r.headers,p),ee=ST(r.query,p),v=Array.from(e.middleware,e=>`${e.key}/Client`),te=Gm(function*(e){let a=pE(r.method)(r.path);if(e!==void 0){if(m!==void 0){let t=yield*m(e.params);a=bE(a,l(t))}if(g!==void 0){if(rE(r.method)){if(e.payload instanceof FormData)a=DE(a,e.payload);else{let t=yield*g(e.payload);a=EE(a,t)}}else{let t=yield*g(e.payload);a=wE(a,t)}}if(_!==void 0){let t=yield*_(e.headers);a=_E(a,t)}if(ee!==void 0){let t=yield*ee(e.query);a=wE(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})}})}),BA=(e,t)=>H(LE,n=>VA(e,{...t,httpClient:t?.transformClient?t.transformClient(n):n})),VA=(e,t)=>{let n={};return zA(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(hm(n))},HA=/(\/?):(\w+)(\?)?/g,UA=(e,t)=>{if(t===void 0||!e.includes(`:`))return t=>e;let n=Ek(t);return t=>e.replace(HA,(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 WA(e,t){let n=e.some(e=>Z(e)||CO(e.ast)!==void 0),r=NC(n?nw(e.map(GA)):oj(e),t);return e=>H(e.arrayBuffer,n?t=>r({body:t,headers:e.headers}):r)}function GA(e){let t=Z(e),n=CO(e.ast);if(n!==void 0)return Y({body:sj(n.body),headers:n.headersCodec}).pipe(X(e));let r=t?e.schema:e;return Y({body:sj(r).pipe(X(r)),headers:t?e.headers:HC}).pipe(X(t?e:RC(e),Ig({decode:e=>t?gO(e):e.body,encode:e=>t?e:{body:e,headers:void 0}})))}function KA(e,t,n,r){let i=FO(n),a=e.get(t);a===void 0?e.set(t,[{contentType:i,decode:r}]):a.push({contentType:i,decode:r})}function qA(e){let t=e[0];return e.length===1&&t!==void 0?t.decode:(t,n)=>{let r=FO(t.headers[`content-type`]??``),i=e.find(e=>e.contentType===r);return i===void 0?YA(t,r,e):i.decode(t,n)}}function JA(e){let t=new Map;for(let n of e){let e=xO((Z(n)?n.schema:n).ast)?``:FO(MO(n).contentType),r=t.get(e);r===void 0?t.set(e,[n]):r.push(n)}return t}function YA(e,t,n){let r=Array.from(new Set(n.map(e=>e.contentType))).join(`, `);return V(new YT({reason:new tE({request:e.request,response:e,description:`Unsupported response content-type for status ${e.status}: ${t||`<missing>`}. Expected one of: ${r}`})}))}var XA=`effect/httpapi/stream/failure`,ZA=e=>Z(e);function QA(e){let t=[];for(let n of e.success)uO(Z(n)?n.schema:n)&&t.push(n);return t}function $A(e,t){let n=ZA(e),r=n?e.schema:e,i=fO(r)?void 0:{declaration:r,decoder:ej(r,t)},a=(e,t)=>U(Tm(),n=>_T(i===void 0?e.stream:tj(e.stream,i.declaration,i.decoder(t)),n));if(!n)return a;let o=MC(e.headers,t);return(e,t)=>H(o(e.headers),n=>U(a(e,t),e=>gO({body:e,headers:n})))}function ej(e,t){let n=nw([Y({id:LC(J),event:BC(XA),data:ww(qw(kw(e.error,Sw())))}),e.events]),r=$D(n,void 0,t);return e=>e===void 0?r:$D(n,e,t)}function tj(e,t,n){let r=oT(e.pipe(mT,pT(n)),e=>tm(()=>{let t;return em(()=>t===void 0?H(e,e=>{for(let n=0;n<e.length;n++){let r=e[n];if(r.event===XA&&mf(r.data)){if(n===0)return im(r.data);t=r.data,e=e.slice(0,n);break}}return B(e)}):im(t))}));return t.sseMode===`data`?uT(r,e=>e.data):r}var nj=uw(globalThis.ArrayBuffer,{expected:`ArrayBuffer`}),rj=nj.pipe(X(Dw,Ig({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)}}))),ij=nj.pipe(X(J,Ig({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)}}))),aj=ij.pipe(X(nw([BC(``).pipe(X(WC,Ig({decode:()=>void 0,encode:()=>``}))),Tw])));function oj(e){return nw(e.map(t));function t(e){return sj(e).pipe(X(e))}}function sj(e){switch(kO(e.ast)._tag){case`Json`:return Zg(Gv(e.ast))?aj.pipe(X(HC,Ig({decode:e=>e===void 0?null:e,encode:e=>e===null?void 0:e}))):aj;case`FormUrlEncoded`:return ij.pipe(X(Lw,Ig({decode:e=>dC(new URLSearchParams(e)),encode:yC})));case`Uint8Array`:return rj;case`Text`:return ij}}var cj=e=>V(new YT({reason:new tE({request:e.request,response:e})})),lj=wC(NT);function uj(e,t){return nw(e.map(e=>fj(e,t)))}var dj=new WeakMap;function fj(e,t){let n=e.ast,r=dj.get(n);if(r!==void 0)return r;let i=OO(n,t),a=lj.pipe(X(e,Fg({decode(e,t){return V(new Dh({message:`Encode only schema`},e,t))},encode(e,t){switch(i._tag){case`Multipart`:return V(new Dh({message:`Payload must be a FormData`},e,t));case`Json`:try{return B(VT(JSON.stringify(e),i.contentType))}catch{return V(new Th({expected:`a JSON-serializable request body`},e,t))}case`Text`:return typeof e==`string`?B(VT(e,i.contentType)):V(new Th({message:`Expected a string`},e,t));case`FormUrlEncoded`:return Vn(e)?B(UT(dC(e),i.contentType)):V(new Th({message:`Expected a record`},e,t));case`Uint8Array`:return e instanceof Uint8Array?B(LT(e,i.contentType)):V(new Th({message:`Expected a Uint8Array`},e,t))}}})));return dj.set(n,a),a}var pj=`~effect/httpapi/HttpApiGroup`,mj={[pj]:pj,add(...e){let t={...this.endpoints};for(let n of e)E(t,n.identifier,n);return gj({...hj(this),endpoints:t})},prefix(e){return gj({...hj(this),endpoints:Wa(this.endpoints,t=>t.prefix(e))})},middleware(e){return gj({...hj(this),endpoints:Wa(this.endpoints,t=>t.middleware(e))})},annotateMerge(e){return gj({...hj(this),annotations:cs(this.annotations,e)})},annotate(e,t){return gj({...hj(this),annotations:Zo(this.annotations,e,t)})},annotateEndpointsMerge(e){return gj({...hj(this),endpoints:Wa(this.endpoints,t=>t.annotateMerge(e))})},annotateEndpoints(e,t){return gj({...hj(this),endpoints:Wa(this.endpoints,n=>n.annotate(e,t))})},pipe(){return x(this,arguments)}},hj=e=>({identifier:e.identifier,topLevel:e.topLevel,endpoints:e.endpoints,annotations:e.annotations}),gj=e=>{function t(){}return Object.setPrototypeOf(t,mj),t.key=`effect/httpapi/HttpApiGroup/${e.identifier}`,Object.assign(t,e)},_j=(e,t)=>gj({identifier:e,topLevel:t?.topLevel??!1,endpoints:{},annotations:Jo()}),vj=e=>e.actions.filter(e=>e.http),yj=(e,t,n)=>ok(n.name,`${e.apiPath}/${t.name}/${n.name}`,{payload:n.input,success:n.success,error:CT(n,e.errors)}).annotate(jk,n.description),bj=(e,t)=>{class n extends Sk()(`effect-actions/http/SchemaErrors/${e}`,{error:t.errors}){}return{SchemaErrors:n,layer:wk(n,e=>V(t.map(e)))}};function xj(e,t){let[n,...r]=vj(t).map(n=>yj(e,t,n));if(n===void 0)return;let i=_j(t.name).add(n,...r);if(t.schemaError===void 0)return{native:i,middleware:dp};let a=bj(t.name,t.schemaError);return{native:i.middleware(a.SchemaErrors),middleware:a.layer}}function Sj(e){let[t,...n]=e,r=dk(`actions`).annotate(hk,{errors:`all`});return t===void 0?r:r.add(t,...n)}var Cj=e=>e,wj=(e,t,n,r)=>{let i=e=>Object.fromEntries(vj(t.group).map(n=>[n.name,i=>AT(t.group,n,e,r)(i.payload)]));return _p(U(t.build,n=>nA(e,t.group.name,e=>e.handleAll(i(Cj(n)))))).pipe(xp(n))};function Tj(e,...t){ET(`action group`,t.map(e=>e.name));let n=new Map(t.flatMap(t=>{let n=xj(e,t);return n===void 0?[]:[[t,n]]})),r=(e,r={})=>{ET(`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=Sj(i.map(({native:e})=>e)),[o,...s]=i.map(({app:e,middleware:t})=>wj(a,e,t,r.before));return o===void 0?tA(a):tA(a).pipe(xp([o,...s]))};return{groups:t,api:Sj([...n.values()].map(({native:e})=>e)),layer:r}}var Ej=class extends Kw()(`BadRequest`,{error:J},{httpApiStatus:400}){},Dj=class extends Kw()(`Unauthorized`,{error:J},{httpApiStatus:401}){},Oj=class extends Kw()(`Forbidden`,{error:J},{httpApiStatus:403}){},kj=class extends Kw()(`NotFound`,{error:J},{httpApiStatus:404}){},Aj=class extends Kw()(`Conflict`,{error:J},{httpApiStatus:409}){},jj=class extends Kw()(`TooManyRequests`,{error:J},{httpApiStatus:429}){},Mj=class extends Kw()(`InternalServerError`,{error:J},{httpApiStatus:500}){cause},Nj=[Ej,Dj,Oj,kj,Aj,jj,Mj,class extends Kw()(`ServiceUnavailable`,{error:J},{httpApiStatus:503}){}],Pj=Y({email:J,password:J}),Fj=rw([`none`,`client_secret_basic`,`client_secret_post`]),Ij=rw([`web`,`native`]),Lj=Y({client_name:J,redirect_uris:$C(J),resources:$C(J),token_endpoint_auth_method:Fj,application_type:Ij}),Rj=Y({client_id:J,client_name:J,redirect_uris:$C(J),application_type:Ij}),zj=Y({client_id:J}),Bj=Y({client_id:J,blocked:KC}),Vj=Y({onboarding:LC(rw([`managed`,`dcr`,`cimd`])),blocked:LC(KC),client_id:J,client_name:LC(J),redirect_uris:$C(J),token_endpoint_auth_method:LC(J),application_type:LC(iw(J)),scope:LC(J),grant_types:LC($C(J))}),Hj=Vj.pipe(YC({client_secret:LC(J),client_secret_expires_at:LC(GC)})),Uj=Y({identifier:J,name:J,scopes:$C(J)}),Wj=Uj.pipe(YC({builtIn:KC})),Gj=Y({identifier:J}),Kj=Y({client_id:J,resource:J}),qj=Y({client_id:J,resources:$C(J)}),Jj=Y({clientAccess:$C(Kj)}),Yj=XC(J,$C(J)),Xj=Iw,Zj=Y({name:J,permissions:Yj,expiresAt:iw(Xj)}),Qj=Y({keyId:J}),$j=Y({keyId:J,name:LC(J),permissions:LC(Yj),enabled:LC(KC)}),eM=Y({keyId:J,name:J,enabled:KC,permissions:Yj,expiresAt:iw(Xj),createdAt:Xj}),tM={errors:[Ej,Mj],map:e=>e.kind===`Body`||e.kind===`ResponseHeaders`?new Mj({error:`Request could not be completed`}):new Ej({error:`Invalid request`})},nM=jT({name:`issuer`,errors:Nj,schemaError:tM},OT(`setupStatus`,{description:`Check whether the issuer needs its first owner account.`,access:`read`,success:Y({required:KC}),mcp:!1}),OT(`setupOwner`,{description:`Create the first owner account.`,access:`write`,input:Pj,success:Y({created:KC}).pipe(cO(201)),mcp:!1}),OT(`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:$C(J),expiresAt:iw(Xj)}),mcp:!1})),rM=Y({clients:$C(Vj),resources:$C(Wj),clientAccess:$C(Kj),email:J,issuer:J}),iM=Tj({apiPath:`/api`},jT({name:`administration`,errors:Nj,schemaError:tM},OT(`listClients`,{description:`List clients, resources and access grants.`,access:`read`,success:rM}),OT(`createClient`,{description:`Register a first-party OAuth client. Returns its secret once when confidential.`,access:`write`,input:Lj,success:Hj.pipe(cO(201))}),OT(`updateClient`,{description:`Rename a first-party client or change its redirect URIs and application type.`,access:`write`,input:Rj,success:Vj}),OT(`deleteClient`,{description:`Delete a first-party OAuth client.`,access:`write`,input:zj,success:Y({deleted:KC})}),OT(`revokeClient`,{description:`Revoke a client’s authorization grants.`,access:`write`,input:zj,success:Y({revoked:KC})}),OT(`blockClient`,{description:`Block or unblock OAuth authorization for a client.`,access:`write`,input:Bj,success:Y({blocked:KC})}),OT(`rotateClientSecret`,{description:`Rotate a confidential client secret. Returns the new secret once.`,access:`write`,input:zj,success:Hj}),OT(`setClientAccess`,{description:`Set the resources a client may request.`,access:`write`,input:qj,success:Jj}),OT(`createResource`,{description:`Create an OAuth resource and its scopes.`,access:`write`,input:Uj,success:Uj.pipe(cO(201))}),OT(`updateResource`,{description:`Update an OAuth resource and its scopes.`,access:`write`,input:Uj,success:Uj}),OT(`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:Gj,success:Y({deleted:KC})}),OT(`listApiKeys`,{description:`List API key metadata without secret values.`,access:`read`,success:Y({keys:$C(eM)})}),OT(`createApiKey`,{description:`Create a scoped API key. Returns its secret once.`,access:`write`,input:Zj,success:eM.pipe(YC({key:J}),cO(201))}),OT(`updateApiKey`,{description:`Update an API key’s name, permissions or enabled state.`,access:`write`,input:$j,success:eM}),OT(`deleteApiKey`,{description:`Delete an API key.`,access:`write`,input:Qj,success:Y({deleted:KC})})),nM);iM.api;var aM=await Hm(BA(iM.api,{baseUrl:location.origin}).pipe(Dm($E))),oM=jC(nw(Nj)),sM=e=>Error(oM(e)?e.error:`Request could not be completed. Please try again.`);function cM(e){return Hm(bm(e,sM))}var lM=dn({plugins:[bn()]}),uM=document.querySelector(`#app`);uM.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 dM=document.querySelector(`#main`),$=e=>e.replace(/[&<>"']/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`})[e]);function fM(e){let t=document.querySelector(`#message`);t.textContent=e,e&&t.hasAttribute(`tabindex`)&&(t.focus(),t.scrollIntoView({behavior:`smooth`,block:`center`}))}var pM=!1;async function mM(e){if(pM)return;pM=!0;let t=Array.from(dM.querySelectorAll(`button`),e=>({button:e,disabled:e.disabled}));t.forEach(({button:e})=>e.disabled=!0),fM(``);try{await e()}catch(e){fM(e instanceof Error?e.message:`Request failed`)}finally{t.forEach(({button:e,disabled:t})=>e.disabled=t),pM=!1}}function hM(e,t){!pM&&confirm(e)&&mM(t)}function gM(){dM.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(),mM(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.`);await cM(aM.issuer.setupOwner({payload:{email:e.querySelector(`[name="email"]`).value,password:t}}).pipe(fm(()=>tm(()=>location.replace(`/`))),vm(`Conflict`,()=>tm(()=>location.replace(`/login`)))))})})}function _M(){dM.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(),mM(async()=>{if((await lM.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 vM(){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 lM.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`);dM.className=`center`,dM.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`;mM(async()=>{if((await lM.oauth2.consent({accept:n})).error)throw Error(`Authorization could not be completed. Restart from your application.`)})})}function yM(e,t){let n=e.get(t);if(n===null||n instanceof File)throw Error(`Missing form field: ${t}`);return n.trim()}function bM(e){return Array.from(e.querySelectorAll(`input[name="resources"]:checked`),e=>e.value)}function xM(e){let t=[...new Set(yM(e,`scopes`).split(/\s+/).filter(Boolean))];return{name:yM(e,`name`),scopes:t}}function SM(e){let t=[...new Set(yM(e,`redirect_uris`).split(/\s+/).filter(Boolean))];if(!t.length)throw Error(`Add at least one redirect URI.`);return t}var CM={none:`Public client (PKCE only)`,client_secret_basic:`Confidential client · HTTP Basic secret`,client_secret_post:`Confidential client · secret in request body`},wM=e=>PC(Fj)(yM(e,`token_endpoint_auth_method`)),TM=e=>PC(Ij)(e.has(`native`)?`native`:`web`);function EM(e){let t={};for(let n of e.querySelectorAll(`input[name="key-scope"]:checked`))(t[n.dataset.resource]??=[]).push(n.value);return t}var DM=new Map,OM=new Map;function kM(){let e=document.querySelector(`#credentials`);if(e.classList.toggle(`hidden`,OM.size===0&&DM.size===0),e.replaceChildren(),!OM.size&&!DM.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 OM.values()){let n=document.createElement(`pre`);n.textContent=JSON.stringify(e,null,2),t.before(n)}for(let e of DM.values()){let n=document.createElement(`pre`);n.textContent=e,t.before(n)}t.addEventListener(`click`,()=>{DM.clear(),OM.clear(),kM()})}function AM(){kM(),document.querySelector(`#credentials`).scrollIntoView({behavior:`smooth`})}async function jM(){try{await KM()}catch{document.querySelector(`#dashboard-mutations`).disabled=!0,fM(`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`,()=>{mM(jM)}),document.querySelector(`#message`).append(` `,e)}}var MM=`Optional. Separate scopes with spaces. offline_access is reserved.`,NM={managed:`Managed registration · first party, no consent screen`,dcr:`Dynamic registration`,cimd:`Client ID Metadata Document`},PM=e=>!e.onboarding||e.onboarding===`managed`,FM=(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>`,IM=(e,t)=>`<div class="empty"><h3>${e}</h3><p>${t}</p></div>`,LM=e=>`<code>${$(e.identifier)}</code><span class="muted">${$(e.scopes.join(` · `))}</span>`,RM=(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)}${LM(e)}</span></label>`).join(``),zM=(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>`,BM=(e,t)=>`<article class="resource"><h3>${$(e.name)}</h3>${LM(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>`,VM=()=>`<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">${MM}</p><button>Add resource +</button></form>`,HM=(e,t)=>`<article class="resource"><h3>${$(e.name)}</h3><p>${e.enabled?`Enabled`:`Disabled`} · ${e.expiresAt?`Expires ${$(Zh(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)}">${zM(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>`,UM=e=>`<h2>Create API key</h2><form id="key-create"><label>Name<input name="name" required maxlength="100" placeholder="Backup script"></label>${zM(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>`,WM=(e,t,n)=>{let r=PM(e),i=$(e.client_id),a=t.flatMap(e=>n.includes(e.identifier)?[`<div class="allowed-resource"><strong>${$(e.name)}</strong>${LM(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>${RM(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">${NM[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>`},GM=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>${RM(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(CM).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 KM(){let[e,t]=await cM(Zp([aM.administration.listClients({payload:{}}),aM.administration.listApiKeys({payload:{}})],{concurrency:`unbounded`})),{resources:n}=e,r=n.filter(e=>!e.builtIn),i=t=>e.clientAccess.filter(e=>e.client_id===t).map(e=>e.resource);dM.className=`dashboard`,dM.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
- ${FM(`Resources`,n.length,`Protected APIs and MCP servers, and the scopes they define.`,n.map(t=>BM(t,e.clients.filter(e=>PM(e)&&i(e.client_id).includes(t.identifier)))).join(``)||IM(`Add your first Resource`,`Define a protected API or MCP server. Compatible MCP clients onboard automatically when you connect.`),VM())}
51
- ${FM(`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=>HM(e,r)).join(``)||IM(`No API keys`,`Create a key for a CLI or automation that needs direct access.`),UM(r))}
52
- ${FM(`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=>WM(e,n,i(e.client_id))).join(``)||IM(`No Clients registered`,`Connect your MCP client to a configured server to onboard automatically, or register a managed Client here.`),GM(n))}
53
- </fieldset>`,kM();let a=e=>document.querySelector(e),o=(e,t)=>e.addEventListener(`submit`,n=>{n.preventDefault(),mM(()=>t(e))}),s=(e,t)=>{for(let n of dM.querySelectorAll(e))n.addEventListener(`click`,()=>t(n))};document.querySelector(`#logout`).addEventListener(`click`,()=>{mM(async()=>{await lM.signOut(),location.assign(`/login`)})}),o(a(`#register`),async e=>{let t=new FormData(e),n=await cM(aM.administration.createClient({payload:{client_name:yM(t,`name`),redirect_uris:SM(t),resources:bM(e),application_type:TM(t),token_endpoint_auth_method:wM(t)}}));e.reset(),OM.set(n.client_id,n),AM(),await jM()}),o(a(`#key-create`),async e=>{let t=new FormData(e),n=yM(t,`expiry`),r=await cM(aM.administration.createApiKey({payload:{name:yM(t,`name`),permissions:EM(e),expiresAt:n?qh(new Date(n)):null}}));DM.set(r.keyId,`${r.name}\n${r.key}`),e.reset(),AM(),await jM()}),o(a(`#resource-create`),async e=>{let t=new FormData(e);await cM(aM.administration.createResource({payload:{identifier:yM(t,`identifier`),...xM(t)}})),e.reset(),await jM()});for(let e of dM.querySelectorAll(`[data-key-rename]`))o(e,async e=>{await cM(aM.administration.updateApiKey({payload:{keyId:e.dataset.keyRename,name:yM(new FormData(e),`name`)}})),await jM()});for(let e of dM.querySelectorAll(`[data-key-grants]`))o(e,async e=>{await cM(aM.administration.updateApiKey({payload:{keyId:e.dataset.keyGrants,permissions:EM(e)}})),await jM()});for(let e of dM.querySelectorAll(`[data-resource-edit]`))o(e,async e=>{let t=n.find(t=>t.identifier===e.dataset.resourceEdit);await cM(aM.administration.updateResource({payload:{identifier:e.dataset.resourceEdit,name:yM(new FormData(e),`name`),scopes:t.builtIn?t.scopes:xM(new FormData(e)).scopes}})),await jM()});for(let e of dM.querySelectorAll(`[data-client-edit]`))o(e,async e=>{let t=new FormData(e);await cM(aM.administration.updateClient({payload:{client_id:e.dataset.clientEdit,client_name:yM(t,`name`),redirect_uris:SM(t),application_type:TM(t)}})),await jM()});for(let e of dM.querySelectorAll(`[data-client-access]`))e.addEventListener(`submit`,t=>{t.preventDefault();let n=e.dataset.clientAccess,r=bM(e),a=i(n).filter(e=>!r.includes(e)),o=async()=>{await cM(aM.administration.setClientAccess({payload:{client_id:n,resources:r}})),await jM()};a.length?hM(`Remove access to ${a.join(`, `)}? Stored consent remains until revoked.`,o):mM(o)});s(`[data-key-toggle]`,e=>{mM(async()=>{await cM(aM.administration.updateApiKey({payload:{keyId:e.dataset.keyToggle,enabled:e.dataset.enabled!==`true`}})),await jM()})}),s(`[data-key-delete]`,e=>{let t=e.dataset.keyDelete;hM(`Delete this API key?`,async()=>{await cM(aM.administration.deleteApiKey({payload:{keyId:t}})),DM.delete(t),kM(),await jM()})}),s(`[data-revoke]`,e=>{let t=e.dataset.revoke;hM(`Revoke this Client’s authorization? It can request consent again.`,async()=>{await cM(aM.administration.revokeClient({payload:{client_id:t}})),await jM()})}),s(`[data-block]`,e=>{let t=e.dataset.block,n=e.dataset.blocked!==`true`;hM(n?`Block this Client and revoke its authorization?`:`Unblock this Client?`,async()=>{await cM(aM.administration.blockClient({payload:{client_id:t,blocked:n}})),await jM()})}),s(`[data-rotate]`,e=>{let t=e.dataset.rotate;hM(`Rotate the secret? The old one stops working immediately.`,async()=>{let e=await cM(aM.administration.rotateClientSecret({payload:{client_id:t}}));OM.set(e.client_id,e),AM()})}),s(`[data-delete]`,e=>{let t=e.dataset.delete;hM(`Delete this Client and its grants?`,async()=>{await cM(aM.administration.deleteClient({payload:{client_id:t}})),OM.delete(t),kM(),await jM()})}),s(`[data-resource-delete]`,e=>{let t=e.dataset.resourceDelete;hM(`Delete Resource ${t}? Stored grants are kept and may become usable again if it is recreated.`,async()=>{await cM(aM.administration.deleteResource({payload:{identifier:t}})),await jM()})})}try{if((await cM(aM.issuer.setupStatus({payload:{}}))).required)location.pathname===`/setup`?gM():location.replace(`/setup`);else if(location.pathname===`/setup`){let e=await lM.getSession();location.replace(e.data?`/`:`/login`)}else location.pathname===`/consent`?await vM():!(await lM.getSession()).data||location.pathname===`/login`?_M():await KM()}catch(e){dM.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>`}