@gjermundgaraba/clankerauth-dev 0.7.0 → 0.7.2

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