UNPKG

@elysiajs/eden

Version:

Fully type-safe Elysia client

2 lines (1 loc) 1.08 kB
import{a as u,b as f}from"./chunk-XYW4OUFN.mjs";var j=async t=>{switch(t.headers.get("Content-Type")?.split(";")[0]){case"application/json":return t.json();case"application/octet-stream":return t.arrayBuffer();case"multipart/form-data":{let e=await t.formData(),r={};return e.forEach((o,a)=>{r[a]=o}),r}}return t.text().then(f)},T=async(t,n)=>{let e=await j(t);return t.status>300?{data:null,status:t.status,headers:t.headers,retry:n,error:new u(t.status,e)}:{data:e,error:null,status:t.status,headers:t.headers,retry:n}},x=(t,n)=>(e,{query:r,params:o,body:a,...s}={})=>{o&&Object.entries(o).forEach(([c,i])=>{e=e.replace(`:${c}`,i)});let h=s.headers?.["Content-Type"];if(!h||h==="application/json")try{a=JSON.stringify(a)}catch{}let p=n?.fetcher||globalThis.fetch,y=r?Object.fromEntries(Object.entries(r).filter(([c,i])=>i!=null)):null,d=y?`?${new URLSearchParams(y).toString()}`:"",m=`${t}${e}${d}`,E=a?{"content-type":"application/json",...s.headers}:s.headers,g={...s,method:s.method?.toUpperCase()||"GET",headers:E,body:a},l=()=>p(m,g).then(c=>T(c,l));return l()};export{x as a};